[hackers] [libixp] Fixed some bugs.

From: Kris Maglione <jg_AT_suckless.org>
Date: Mon Mar 26 23:24:26 2007

changeset: 53:112371e1ac54
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Mon Mar 26 17:20:54 2007 -0400
summary: Fixed some bugs.

diff -r 7c9a3d78a7a5 -r 112371e1ac54 cmd/ixpc.c
--- a/cmd/ixpc.c Mon Mar 26 15:46:04 2007 -0400
+++ b/cmd/ixpc.c Mon Mar 26 17:20:54 2007 -0400
@@ -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);
-
- write_data(fid);
+ ixp_eprint("Can't open file '%s': %s\n", file, errstr);
+
+ 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 -r 7c9a3d78a7a5 -r 112371e1ac54 libixp/client.c
--- a/libixp/client.c Mon Mar 26 15:46:04 2007 -0400
+++ b/libixp/client.c Mon Mar 26 17:20:54 2007 -0400
@@ -73,14 +73,15 @@ 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 co
         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 -r 7c9a3d78a7a5 -r 112371e1ac54 libixp/convert.c
--- a/libixp/convert.c Mon Mar 26 15:46:04 2007 -0400
+++ b/libixp/convert.c Mon Mar 26 17:20:54 2007 -0400
@@ -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 -r 7c9a3d78a7a5 -r 112371e1ac54 libixp/request.c
--- a/libixp/request.c Mon Mar 26 15:46:04 2007 -0400
+++ b/libixp/request.c Mon Mar 26 17:20:54 2007 -0400
@@ -3,6 +3,7 @@
  */
 #include <assert.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/socket.h>
 #include "ixp.h"
Received on Mon Mar 26 2007 - 23:24:26 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:27 UTC