plan9port/src/lib9pclient/open.c

38 lines
563 B
C
Raw Normal View History

2005-01-04 21:22:40 +00:00
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <9pclient.h>
#include "fsimpl.h"
2006-07-23 02:55:34 +00:00
int
fsfopen(CFid *fid, int mode)
{
Fcall tx, rx;
tx.type = Topen;
tx.fid = fid->fid;
tx.mode = mode;
if(_fsrpc(fid->fs, &tx, &rx, 0) < 0)
return -1;
fid->mode = mode;
return 0;
}
2005-01-04 21:22:40 +00:00
CFid*
fsopen(CFsys *fs, char *name, int mode)
{
char e[ERRMAX];
2005-01-04 21:22:40 +00:00
CFid *fid;
2006-07-23 02:55:34 +00:00
if((fid = fswalk(fs->root, name)) == nil)
2005-01-04 21:22:40 +00:00
return nil;
2006-07-23 02:55:34 +00:00
if(fsfopen(fid, mode) < 0){
rerrstr(e, sizeof e);
2005-01-04 21:22:40 +00:00
fsclose(fid);
errstr(e, sizeof e);
2005-01-04 21:22:40 +00:00
return nil;
}
fid->mode = mode;
return fid;
}