plan9port/src/lib9pclient/create.c

53 lines
775 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
fsfcreate(CFid *fid, char *name, int mode, ulong perm)
{
Fcall tx, rx;
tx.type = Tcreate;
tx.name = name;
tx.fid = fid->fid;
tx.mode = mode;
tx.perm = perm;
tx.extension = nil;
2006-07-23 02:55:34 +00:00
if(_fsrpc(fid->fs, &tx, &rx, 0) < 0)
return -1;
fid->mode = mode;
return 0;
}
2005-01-04 21:22:40 +00:00
CFid*
fscreate(CFsys *fs, char *name, int mode, ulong perm)
{
CFid *fid;
2006-01-27 04:08:41 +00:00
char *p, *dir, *elem;
p = strrchr(name, '/');
if(p == nil){
dir = "";
elem = name;
}else{
dir = name;
*p = 0;
elem = p+1;
}
2005-01-04 21:22:40 +00:00
2006-07-23 02:55:34 +00:00
if((fid = fswalk(fs->root, dir)) == nil){
2006-01-27 04:08:41 +00:00
if(p)
*p = '/';
2005-01-04 21:22:40 +00:00
return nil;
2006-01-27 04:08:41 +00:00
}
2006-07-23 02:55:34 +00:00
if(p)
*p = '/';
if(fsfcreate(fid, elem, mode, perm) < 0){
2005-01-04 21:22:40 +00:00
fsclose(fid);
return nil;
}
return fid;
}