aboutsummaryrefslogtreecommitdiff
path: root/src/lib9pclient
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2006-02-08 21:21:01 +0000
committerrsc <devnull@localhost>2006-02-08 21:21:01 +0000
commit5a1e9de7b160033e85a77ad4c60193186364a2fb (patch)
tree43ab13d3937a9f6de64828e053dbfd5b2b511b6d /src/lib9pclient
parent4ca53ff0e0398171fe9afb1e989b97b30d3d584f (diff)
downloadplan9port-5a1e9de7b160033e85a77ad4c60193186364a2fb.tar.gz
plan9port-5a1e9de7b160033e85a77ad4c60193186364a2fb.tar.bz2
plan9port-5a1e9de7b160033e85a77ad4c60193186364a2fb.zip
add print
Diffstat (limited to 'src/lib9pclient')
-rw-r--r--src/lib9pclient/mkfile1
-rw-r--r--src/lib9pclient/print.c67
2 files changed, 68 insertions, 0 deletions
diff --git a/src/lib9pclient/mkfile b/src/lib9pclient/mkfile
index 55882cae..b86a4828 100644
--- a/src/lib9pclient/mkfile
+++ b/src/lib9pclient/mkfile
@@ -12,6 +12,7 @@ OFILES=\
ns.$O\
open.$O\
openfd.$O\
+ print.$O\
read.$O\
remove.$O\
seek.$O\
diff --git a/src/lib9pclient/print.c b/src/lib9pclient/print.c
new file mode 100644
index 00000000..d02afb40
--- /dev/null
+++ b/src/lib9pclient/print.c
@@ -0,0 +1,67 @@
+#include <u.h>
+#include <libc.h>
+#include <fcall.h>
+#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;
+}
+