|
|
1.1 root 1: #define FIO_IMP
2: #include "fio.h"
3: #include <libc.h>
4:
5: long
6: Fseek(fd, n, cmd)
7: long n;
8: {
9: register Fbuffer *f;
10: register long dest, k;
11:
12: FIOSET(f, fd);
13: switch(cmd)
14: {
15: case 0:
16: dest = n;
17: break;
18: case 1:
19: /* allow for the fact we are beyond where we think we are */
20: dest = f->offset + n + f->next-f->end;
21: break;
22: case 2:
23: if(f->flags&FIO_WRITING)
24: F_flush(f, fd);
25: dest = SEEK(fd, n, cmd);
26: FIORESET(f);
27: f->offset = dest;
28: break;
29: }
30: if(dest < 0)
31: return(dest);
32: k = f->end - ((f->flags&FIO_WRITING)? f->buf : f->lnext);
33: if((dest >= f->offset) || (dest < f->offset-k)){
34: if(f->flags&FIO_WRITING)
35: F_flush(f, fd);
36: FIORESET(f);
37: f->offset = dest;
38: SEEK(fd, f->offset, 0);
39: } else {
40: f->next = f->lnext + (dest-(f->offset-k));
41: if(f->flags&FIO_WRITING){
42: f->offset -= f->end - f->next;
43: f->end = f->next;
44: }
45: SEEK(fd, f->offset, 0);
46: }
47: return(dest);
48: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.