openfd.c (470B)
1 #include <u.h> 2 #include <libc.h> 3 #include <fcall.h> 4 #include <9pclient.h> 5 #include "fsimpl.h" 6 7 int 8 fsopenfd(CFsys *fs, char *name, int mode) 9 { 10 CFid *fid; 11 Fcall tx, rx; 12 13 if((fid = fswalk(fs->root, name)) == nil) 14 return -1; 15 tx.type = Topenfd; 16 tx.fid = fid->fid; 17 tx.mode = mode&~OCEXEC; 18 if(_fsrpc(fs, &tx, &rx, 0) < 0){ 19 fsclose(fid); 20 return -1; 21 } 22 _fsputfid(fid); 23 if(mode&OCEXEC && rx.unixfd>=0) 24 fcntl(rx.unixfd, F_SETFL, FD_CLOEXEC); 25 return rx.unixfd; 26 }