aboutsummaryrefslogtreecommitdiff
path: root/src/lib9pclient
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-01-18 18:11:39 +0000
committerrsc <devnull@localhost>2005-01-18 18:11:39 +0000
commitdaefa1a92f688399290f231c4c738ef99e7b8ab4 (patch)
tree753e5b3a4bbbf6033e6eb205c53d29779368ab68 /src/lib9pclient
parent0fcd970331d664ae6ae2b7a414efb086361ceff7 (diff)
downloadplan9port-daefa1a92f688399290f231c4c738ef99e7b8ab4.tar.gz
plan9port-daefa1a92f688399290f231c4c738ef99e7b8ab4.tar.bz2
plan9port-daefa1a92f688399290f231c4c738ef99e7b8ab4.zip
add fsseek
Diffstat (limited to 'src/lib9pclient')
-rw-r--r--src/lib9pclient/mkfile1
-rw-r--r--src/lib9pclient/seek.c46
2 files changed, 47 insertions, 0 deletions
diff --git a/src/lib9pclient/mkfile b/src/lib9pclient/mkfile
index c6bbc7dc..097f20ad 100644
--- a/src/lib9pclient/mkfile
+++ b/src/lib9pclient/mkfile
@@ -11,6 +11,7 @@ OFILES=\
open.$O\
openfd.$O\
read.$O\
+ seek.$O\
stat.$O\
walk.$O\
write.$O\
diff --git a/src/lib9pclient/seek.c b/src/lib9pclient/seek.c
new file mode 100644
index 00000000..0785c4b4
--- /dev/null
+++ b/src/lib9pclient/seek.c
@@ -0,0 +1,46 @@
+#include <u.h>
+#include <libc.h>
+#include <fcall.h>
+#include <9pclient.h>
+#include "fsimpl.h"
+
+vlong
+fsseek(CFid *fid, vlong n, int whence)
+{
+ Dir *d;
+
+ switch(whence){
+ case 0:
+ qlock(&fid->lk);
+ fid->offset = n;
+ qunlock(&fid->lk);
+ break;
+ case 1:
+ qlock(&fid->lk);
+ n += fid->offset;
+ if(n < 0){
+ qunlock(&fid->lk);
+ werrstr("negative offset");
+ return -1;
+ }
+ fid->offset = n;
+ qunlock(&fid->lk);
+ break;
+ case 2:
+ if((d = fsdirfstat(fid)) == nil)
+ return -1;
+ n += d->length;
+ if(n < 0){
+ werrstr("negative offset");
+ return -1;
+ }
+ qlock(&fid->lk);
+ fid->offset = n;
+ qunlock(&fid->lk);
+ break;
+ default:
+ werrstr("bad whence in fsseek");
+ return -1;
+ }
+ return n;
+}