libixp

git clone git://oldgit.suckless.org/libixp/
Log | Files | Refs | LICENSE

commit b6240a86f85c19a469d1370449f6b621725f9aba
parent b890908fd040c799794d49f5f0e6e3070cdbdf06
Author: Kris Maglione <jg@suckless.org>
Date:   Mon, 26 Mar 2007 17:20:54 -0400

Fixed some bugs.

Diffstat:
cmd/ixpc.c | 30++++++++++++++++--------------
libixp/client.c | 11++++++-----
libixp/convert.c | 2+-
libixp/request.c | 1+
4 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/cmd/ixpc.c b/cmd/ixpc.c @@ -28,25 +28,27 @@ static IxpClient *client; static void usage() { - ixp_eprint("usage: ixpc [-a <address>] {create | read | ls [-l] | remove | write} <file>\n" - " ixpc [-a <address>] xwrite <file> <data>\n" - " ixpc -v\n"); + fprintf(stderr, + "usage: %1$s [-a <address>] {create | read | ls [-ld] | remove | write} <file>\n" + " %1$s [-a <address>] xwrite <file> <data>\n" + " %1$s -v\n", argv0); + exit(1); } /* Utility Functions */ static void -write_data(IxpCFid *fid) { +write_data(IxpCFid *fid, char *name) { void *buf; uint len; buf = ixp_emalloc(fid->iounit);; while((len = read(0, buf, fid->iounit)) > 0) if(ixp_write(fid, buf, len) != len) - ixp_eprint("ixpc: cannot write file: %s\n", errstr); + ixp_eprint("cannot write file '%s': %s\n", name, errstr); /* do an explicit empty write when no writing has been done yet */ if(fid->offset == 0) if(ixp_write(fid, buf, 0) != 0) - ixp_eprint("ixpc: cannot write file: %s\n", errstr); + ixp_eprint("cannot write file '%s': %s\n", name, errstr); free(buf); } @@ -120,9 +122,9 @@ xwrite(int argc, char *argv[]) { file = EARGF(usage()); fid = ixp_open(client, file, P9_OWRITE); if(fid == nil) - ixp_eprint("ixpc: error: Can't open file '%s': %s\n", file, errstr); + ixp_eprint("Can't open file '%s': %s\n", file, errstr); - write_data(fid); + write_data(fid, file); return 0; } @@ -140,7 +142,7 @@ xawrite(int argc, char *argv[]) { file = EARGF(usage()); fid = ixp_open(client, file, P9_OWRITE); if(fid == nil) - ixp_eprint("ixpc: error: Can't open file '%s': %s\n", file, errstr); + ixp_eprint("Can't open file '%s': %s\n", file, errstr); nbuf = 0; mbuf = 128; @@ -159,7 +161,7 @@ xawrite(int argc, char *argv[]) { } if(ixp_write(fid, buf, nbuf) == -1) - ixp_eprint("ixpc: cannot write file '%s': %s\n", file, errstr); + ixp_eprint("cannot write file '%s': %s\n", file, errstr); return 0; } @@ -174,12 +176,12 @@ xcreate(int argc, char *argv[]) { }ARGEND; file = EARGF(usage()); - fid = ixp_create(client, file, 0777, P9_OREAD); + fid = ixp_create(client, file, 0777, P9_OWRITE); if(fid == nil) ixp_eprint("ixpc: error: Can't create file '%s': %s\n", file, errstr); if((fid->qid.type&P9_DMDIR) == 0) - write_data(fid); + write_data(fid, file); return 0; } @@ -299,7 +301,7 @@ main(int argc, char *argv[]) { ARGBEGIN{ case 'v': - puts("ixpc-" VERSION ", ©2007 Kris Maglione\n"); + printf("%s-" VERSION ", ©2007 Kris Maglione\n", argv0); exit(0); case 'a': address = EARGF(usage()); @@ -315,7 +317,7 @@ main(int argc, char *argv[]) { client = ixp_mount(address); if(client == nil) - ixp_eprint("ixpc: %s\n", errstr); + ixp_eprint("%s: %s\n", argv0, errstr); if(!strcmp(cmd, "create")) ret = xcreate(argc, argv); diff --git a/libixp/client.c b/libixp/client.c @@ -73,16 +73,17 @@ dofcall(IxpClient *c, Fcall *fcall) { errstr = "received bad message"; return 0; } - if(fcall->type != (type^1)) { - ixp_freefcall(fcall); - errstr = "received mismatched fcall"; - } if(fcall->type == RError) { strncpy(errbuf, fcall->ename, sizeof errbuf); ixp_freefcall(fcall); errstr = errbuf; return 0; } + if(fcall->type != (type^1)) { + ixp_freefcall(fcall); + errstr = "received mismatched fcall"; + return 0; + } return 1; } @@ -378,7 +379,7 @@ ixp_write(IxpCFid *f, void *buf, uint count) { len = 0; do { n = min(count-len, f->iounit); - fcall.type = TRead; + fcall.type = TWrite; fcall.tag = IXP_NOTAG; fcall.fid = f->fid; fcall.offset = f->offset; diff --git a/libixp/convert.c b/libixp/convert.c @@ -180,7 +180,7 @@ ixp_pstat(Message *msg, Stat *stat) { ushort size; if(msg->mode == MsgPack) - size = ixp_sizeof_stat(stat); + size = ixp_sizeof_stat(stat) - 2; ixp_pu16(msg, &size); ixp_pu16(msg, &stat->type); diff --git a/libixp/request.c b/libixp/request.c @@ -3,6 +3,7 @@ */ #include <assert.h> #include <stdlib.h> +#include <stdio.h> #include <string.h> #include <sys/socket.h> #include "ixp.h"