tadd fsseek - plan9port - [fork] Plan 9 from user space
(HTM) git clone git://src.adamsgaard.dk/plan9port
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit daefa1a92f688399290f231c4c738ef99e7b8ab4
(DIR) parent 0fcd970331d664ae6ae2b7a414efb086361ceff7
(HTM) Author: rsc <devnull@localhost>
Date: Tue, 18 Jan 2005 18:11:39 +0000
add fsseek
Diffstat:
M include/9pclient.h | 3 +++
M src/lib9pclient/mkfile | 1 +
A src/lib9pclient/seek.c | 46 +++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/include/9pclient.h b/include/9pclient.h
t@@ -22,6 +22,9 @@ CFid *fsopen(CFsys*, char*, int);
int fsopenfd(CFsys*, char*, int);
long fsread(CFid*, void*, long);
long fsreadn(CFid*, void*, long);
+long fspread(CFid*, void*, long, vlong);
+long fspwrite(CFid*, void*, long, vlong);
+vlong fsseek(CFid*, vlong, int);
long fswrite(CFid*, void*, long);
void fsclose(CFid*);
void fsunmount(CFsys*);
(DIR) diff --git a/src/lib9pclient/mkfile b/src/lib9pclient/mkfile
t@@ -11,6 +11,7 @@ OFILES=\
open.$O\
openfd.$O\
read.$O\
+ seek.$O\
stat.$O\
walk.$O\
write.$O\
(DIR) diff --git a/src/lib9pclient/seek.c b/src/lib9pclient/seek.c
t@@ -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;
+}