commit 5a1e9de7b160033e85a77ad4c60193186364a2fb from: rsc date: Wed Feb 08 21:21:01 2006 UTC add print commit - 4ca53ff0e0398171fe9afb1e989b97b30d3d584f commit + 5a1e9de7b160033e85a77ad4c60193186364a2fb blob - aac7ee1236fe184e5541e2706a4faee775d077ab blob + de9d2691971e5abf8c5aecf40e2a8d4fdae71f36 --- include/9pclient.h +++ include/9pclient.h @@ -44,6 +44,9 @@ CFid *nsopen(char*, char*, char*, int); int fsfremove(CFid*); int fsremove(CFsys*, char*); CFid *fscreate(CFsys*, char*, int, ulong); +int fsaccess(CFsys*, char*, int); +int fsvprint(CFid*, char*, va_list); +int fsprint(CFid*, char*, ...); extern int chatty9pclient; blob - 55882cae070120258044d9785add34ee1778c585 blob + b86a4828674b5dafc89ceff25528c2c7a6735de5 --- src/lib9pclient/mkfile +++ src/lib9pclient/mkfile @@ -12,6 +12,7 @@ OFILES=\ ns.$O\ open.$O\ openfd.$O\ + print.$O\ read.$O\ remove.$O\ seek.$O\ blob - /dev/null blob + d02afb40375c0ffe561a1c7a4894c662f68cb096 (mode 644) --- /dev/null +++ src/lib9pclient/print.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include <9pclient.h> + +/* C99 nonsense */ +#ifdef va_copy +# define VA_COPY(a,b) va_copy(a,b) +# define VA_END(a) va_end(a) +#else +# define VA_COPY(a,b) (a) = (b) +# define VA_END(a) +#endif + +static int +fidflush(Fmt *f) +{ + int n; + + n = (char*)f->to - (char*)f->start; + if(n && fswrite(f->farg, f->start, n) != n) + return 0; + f->to = f->start; + return 1; +} + +static int +fsfmtfidinit(Fmt *f, CFid *fid, char *buf, int size) +{ + f->runes = 0; + f->start = buf; + f->to = buf; + f->stop = buf + size; + f->flush = fidflush; + f->farg = fid; + f->nfmt = 0; + return 0; +} + +int +fsprint(CFid *fd, char *fmt, ...) +{ + int n; + va_list args; + + va_start(args, fmt); + n = fsvprint(fd, fmt, args); + va_end(args); + return n; +} + +int +fsvprint(CFid *fd, char *fmt, va_list args) +{ + Fmt f; + char buf[256]; + int n; + + fsfmtfidinit(&f, fd, buf, sizeof(buf)); + VA_COPY(f.args,args); + n = dofmt(&f, fmt); + VA_END(f.args); + if(n > 0 && fidflush(&f) == 0) + return -1; + return n; +} +