Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <fcall.h>
4 #include <9pclient.h>
5 #include "fsimpl.h"
7 vlong
8 fsseek(CFid *fid, vlong n, int whence)
9 {
10 Dir *d;
12 switch(whence){
13 case 0:
14 qlock(&fid->lk);
15 fid->offset = n;
16 qunlock(&fid->lk);
17 break;
18 case 1:
19 qlock(&fid->lk);
20 n += fid->offset;
21 if(n < 0){
22 qunlock(&fid->lk);
23 werrstr("negative offset");
24 return -1;
25 }
26 fid->offset = n;
27 qunlock(&fid->lk);
28 break;
29 case 2:
30 if((d = fsdirfstat(fid)) == nil)
31 return -1;
32 n += d->length;
33 if(n < 0){
34 werrstr("negative offset");
35 return -1;
36 }
37 qlock(&fid->lk);
38 fid->offset = n;
39 qunlock(&fid->lk);
40 break;
41 default:
42 werrstr("bad whence in fsseek");
43 return -1;
44 }
45 return n;
46 }