[hackers] [libixp] Added u(v?long|int|short|char) typedefs, and fixed some bugs reported by mauke.

From: Kris Maglione <jg_AT_suckless.org>
Date: Tue Mar 06 09:54:47 2007

changeset: 41:67eac5e46b45
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Tue Mar 06 03:50:06 2007 -0500
summary: Added u(v?long|int|short|char) typedefs, and fixed some bugs reported by mauke.

diff -r c9b5bed927bf -r 67eac5e46b45 client.c
--- a/client.c Tue Mar 06 03:29:46 2007 -0500
+++ b/client.c Tue Mar 06 03:50:06 2007 -0500
@@ -11,8 +11,8 @@
 
 int
 ixp_client_do_fcall(IXPClient *c) {
- static unsigned char msg[IXP_MAX_MSG];
- unsigned int msize = ixp_fcall2msg(msg, &c->ifcall, IXP_MAX_MSG);
+ static uchar msg[IXP_MAX_MSG];
+ uint msize = ixp_fcall2msg(msg, &c->ifcall, IXP_MAX_MSG);
 
         c->errstr = 0;
         if(ixp_send_message(c->fd, msg, msize, &c->errstr) != msize)
@@ -31,7 +31,7 @@ ixp_client_do_fcall(IXPClient *c) {
 }
 
 int
-ixp_client_dial(IXPClient *c, char *sockfile, unsigned int rootfid) {
+ixp_client_dial(IXPClient *c, char *sockfile, uint rootfid) {
         if((c->fd = ixp_connect_sock(sockfile)) < 0) {
                 c->errstr = "cannot connect server";
                 return -1;
@@ -69,7 +69,7 @@ ixp_client_dial(IXPClient *c, char *sock
 }
 
 int
-ixp_client_remove(IXPClient *c, unsigned int newfid, char *filepath) {
+ixp_client_remove(IXPClient *c, uint newfid, char *filepath) {
         if(ixp_client_walk(c, newfid, filepath) == -1)
                 return -1;
         c->ifcall.type = TREMOVE;
@@ -79,8 +79,8 @@ ixp_client_remove(IXPClient *c, unsigned
 }
 
 int
-ixp_client_create(IXPClient *c, unsigned int dirfid, char *name,
- unsigned int perm, unsigned char mode)
+ixp_client_create(IXPClient *c, uint dirfid, char *name,
+ uint perm, uchar mode)
 {
         c->ifcall.type = TCREATE;
         c->ifcall.tag = IXP_NOTAG;
@@ -92,8 +92,8 @@ ixp_client_create(IXPClient *c, unsigned
 }
 
 int
-ixp_client_walk(IXPClient *c, unsigned int newfid, char *filepath) {
- unsigned int i;
+ixp_client_walk(IXPClient *c, uint newfid, char *filepath) {
+ uint i;
         char *wname[IXP_MAX_WELEM];
 
         c->ifcall.type = TWALK;
@@ -109,7 +109,7 @@ ixp_client_walk(IXPClient *c, unsigned i
 }
 
 int
-ixp_client_stat(IXPClient *c, unsigned int newfid, char *filepath) {
+ixp_client_stat(IXPClient *c, uint newfid, char *filepath) {
         if(ixp_client_walk(c, newfid, filepath) == -1)
                 return -1;
         c->ifcall.type = TSTAT;
@@ -119,7 +119,7 @@ ixp_client_stat(IXPClient *c, unsigned i
 }
 
 int
-ixp_client_open(IXPClient *c, unsigned int newfid, unsigned char mode) {
+ixp_client_open(IXPClient *c, uint newfid, uchar mode) {
         c->ifcall.type = TOPEN;
         c->ifcall.tag = IXP_NOTAG;
         c->ifcall.fid = newfid;
@@ -128,8 +128,8 @@ ixp_client_open(IXPClient *c, unsigned i
 }
 
 int
-ixp_client_walkopen(IXPClient *c, unsigned int newfid, char *filepath,
- unsigned char mode)
+ixp_client_walkopen(IXPClient *c, uint newfid, char *filepath,
+ uchar mode)
 {
         if(ixp_client_walk(c, newfid, filepath) == -1)
                 return -1;
@@ -137,10 +137,10 @@ ixp_client_walkopen(IXPClient *c, unsign
 }
 
 int
-ixp_client_read(IXPClient *c, unsigned int fid, unsigned long long offset,
- void *result, unsigned int res_len)
+ixp_client_read(IXPClient *c, uint fid, uvlong offset,
+ void *result, uint res_len)
 {
- unsigned int bytes = c->ofcall.iounit;
+ uint bytes = c->ofcall.iounit;
 
         c->ifcall.type = TREAD;
         c->ifcall.tag = IXP_NOTAG;
@@ -155,9 +155,9 @@ ixp_client_read(IXPClient *c, unsigned i
 }
 
 int
-ixp_client_write(IXPClient *c, unsigned int fid,
- unsigned long long offset, unsigned int count,
- unsigned char *data)
+ixp_client_write(IXPClient *c, uint fid,
+ uvlong offset, uint count,
+ uchar *data)
 {
         if(count > c->ofcall.iounit) {
                 c->errstr = "iounit exceeded";
@@ -175,7 +175,7 @@ ixp_client_write(IXPClient *c, unsigned
 }
 
 int
-ixp_client_close(IXPClient *c, unsigned int fid) {
+ixp_client_close(IXPClient *c, uint fid) {
         c->ifcall.type = TCLUNK;
         c->ifcall.tag = IXP_NOTAG;
         c->ifcall.fid = fid;
diff -r c9b5bed927bf -r 67eac5e46b45 convert.c
--- a/convert.c Tue Mar 06 03:29:46 2007 -0500
+++ b/convert.c Tue Mar 06 03:50:06 2007 -0500
@@ -8,19 +8,19 @@
 /* packode/unpackode stuff */
 
 void
-ixp_pack_u8(unsigned char **msg, int *msize, unsigned char val) {
+ixp_pack_u8(uchar **msg, int *msize, uchar val) {
         if(!msize || (*msize -= 1) >= 0)
                 *(*msg)++ = val;
 }
 
 void
-ixp_unpack_u8(unsigned char **msg, int *msize, unsigned char *val) {
+ixp_unpack_u8(uchar **msg, int *msize, uchar *val) {
         if(!msize || (*msize -= 1) >= 0)
                 *val = *(*msg)++;
 }
 
 void
-ixp_pack_u16(unsigned char **msg, int *msize, unsigned short val) {
+ixp_pack_u16(uchar **msg, int *msize, ushort val) {
         if(!msize || (*msize -= 2) >= 0) {
                 *(*msg)++ = val;
                 *(*msg)++ = val >> 8;
@@ -28,7 +28,7 @@ ixp_pack_u16(unsigned char **msg, int *m
 }
 
 void
-ixp_unpack_u16(unsigned char **msg, int *msize, unsigned short *val) {
+ixp_unpack_u16(uchar **msg, int *msize, ushort *val) {
         if(!msize || (*msize -= 2) >= 0) {
                 *val = *(*msg)++;
                 *val |= *(*msg)++ << 8;
@@ -36,7 +36,7 @@ ixp_unpack_u16(unsigned char **msg, int
 }
 
 void
-ixp_pack_u32(unsigned char **msg, int *msize, unsigned int val) {
+ixp_pack_u32(uchar **msg, int *msize, uint val) {
         if(!msize || (*msize -= 4) >= 0) {
                 *(*msg)++ = val;
                 *(*msg)++ = val >> 8;
@@ -46,7 +46,7 @@ ixp_pack_u32(unsigned char **msg, int *m
 }
 
 void
-ixp_unpack_u32(unsigned char **msg, int *msize, unsigned int *val) {
+ixp_unpack_u32(uchar **msg, int *msize, uint *val) {
         if(!msize || (*msize -= 4) >= 0) {
                 *val = *(*msg)++;
                 *val |= *(*msg)++ << 8;
@@ -56,7 +56,7 @@ ixp_unpack_u32(unsigned char **msg, int
 }
 
 void
-ixp_pack_u64(unsigned char **msg, int *msize, unsigned long long val) {
+ixp_pack_u64(uchar **msg, int *msize, uvlong val) {
         if(!msize || (*msize -= 8) >= 0) {
                 *(*msg)++ = val;
                 *(*msg)++ = val >> 8;
@@ -70,32 +70,32 @@ ixp_pack_u64(unsigned char **msg, int *m
 }
 
 void
-ixp_unpack_u64(unsigned char **msg, int *msize, unsigned long long *val) {
+ixp_unpack_u64(uchar **msg, int *msize, uvlong *val) {
         if(!msize || (*msize -= 8) >= 0) {
                 *val |= *(*msg)++;
                 *val |= *(*msg)++ << 8;
                 *val |= *(*msg)++ << 16;
                 *val |= *(*msg)++ << 24;
- *val |= (unsigned long long)*(*msg)++ << 32;
- *val |= (unsigned long long)*(*msg)++ << 40;
- *val |= (unsigned long long)*(*msg)++ << 48;
- *val |= (unsigned long long)*(*msg)++ << 56;
- }
-}
-
-void
-ixp_pack_string(unsigned char **msg, int *msize, const char *s) {
- unsigned short len = s ? strlen(s) : 0;
+ *val |= (uvlong)*(*msg)++ << 32;
+ *val |= (uvlong)*(*msg)++ << 40;
+ *val |= (uvlong)*(*msg)++ << 48;
+ *val |= (uvlong)*(*msg)++ << 56;
+ }
+}
+
+void
+ixp_pack_string(uchar **msg, int *msize, const char *s) {
+ ushort len = s ? strlen(s) : 0;
         ixp_pack_u16(msg, msize, len);
         if(s)
                 ixp_pack_data(msg, msize, (void *)s, len);
 }
 
 void
-ixp_unpack_strings(unsigned char **msg, int *msize, unsigned short n, char **strings) {
- unsigned char *s = *msg;
- unsigned int i, size = 0;
- unsigned short len;
+ixp_unpack_strings(uchar **msg, int *msize, ushort n, char **strings) {
+ uchar *s = *msg;
+ uint i, size = 0;
+ ushort len;
         for(i=0; i<n; i++) {
                 ixp_unpack_u16(&s, msize, &len);
                 s += len;
@@ -120,7 +120,7 @@ ixp_unpack_strings(unsigned char **msg,
 }
 
 void
-ixp_unpack_string(unsigned char **msg, int *msize, char **string, unsigned short *len) {
+ixp_unpack_string(uchar **msg, int *msize, char **string, ushort *len) {
         ixp_unpack_u16(msg, msize, len);
         *string = NULL;
         if (!msize || (*msize -= *len) >= 0) {
@@ -133,7 +133,7 @@ ixp_unpack_string(unsigned char **msg, i
 }
 
 void
-ixp_pack_data(unsigned char **msg, int *msize, unsigned char *data, unsigned int datalen) {
+ixp_pack_data(uchar **msg, int *msize, uchar *data, uint datalen) {
         if(!msize || (*msize -= datalen) >= 0) {
                 memcpy(*msg, data, datalen);
                 *msg += datalen;
@@ -141,7 +141,7 @@ ixp_pack_data(unsigned char **msg, int *
 }
 
 void
-ixp_unpack_data(unsigned char **msg, int *msize, unsigned char **data, unsigned int datalen) {
+ixp_unpack_data(uchar **msg, int *msize, uchar **data, uint datalen) {
         if(!msize || (*msize -= datalen) >= 0) {
                 *data = ixp_emallocz(datalen);
                 memcpy(*data, *msg, datalen);
@@ -150,8 +150,8 @@ ixp_unpack_data(unsigned char **msg, int
 }
 
 void
-ixp_pack_prefix(unsigned char *msg, unsigned int size, unsigned char id,
- unsigned short tag)
+ixp_pack_prefix(uchar *msg, uint size, uchar id,
+ ushort tag)
 {
         ixp_pack_u32(&msg, 0, size);
         ixp_pack_u8(&msg, 0, id);
@@ -159,8 +159,8 @@ ixp_pack_prefix(unsigned char *msg, unsi
 }
 
 void
-ixp_unpack_prefix(unsigned char **msg, unsigned int *size, unsigned char *id,
- unsigned short *tag)
+ixp_unpack_prefix(uchar **msg, uint *size, uchar *id,
+ ushort *tag)
 {
         int msize;
         ixp_unpack_u32(msg, NULL, size);
@@ -170,22 +170,22 @@ ixp_unpack_prefix(unsigned char **msg, u
 }
 
 void
-ixp_pack_qid(unsigned char **msg, int *msize, Qid * qid) {
+ixp_pack_qid(uchar **msg, int *msize, Qid * qid) {
         ixp_pack_u8(msg, msize, qid->type);
         ixp_pack_u32(msg, msize, qid->version);
         ixp_pack_u64(msg, msize, qid->path);
 }
 
 void
-ixp_unpack_qid(unsigned char **msg, int *msize, Qid * qid) {
+ixp_unpack_qid(uchar **msg, int *msize, Qid * qid) {
         ixp_unpack_u8(msg, msize, &qid->type);
         ixp_unpack_u32(msg, msize, &qid->version);
         ixp_unpack_u64(msg, msize, &qid->path);
 }
 
 void
-ixp_pack_stat(unsigned char **msg, int *msize, Stat * stat) {
- ixp_pack_u16(msg, msize, ixp_sizeof_stat(stat) - sizeof(unsigned short));
+ixp_pack_stat(uchar **msg, int *msize, Stat * stat) {
+ ixp_pack_u16(msg, msize, ixp_sizeof_stat(stat) - sizeof(ushort));
         ixp_pack_u16(msg, msize, stat->type);
         ixp_pack_u32(msg, msize, stat->dev);
         ixp_pack_qid(msg, msize, &stat->qid);
@@ -200,10 +200,10 @@ ixp_pack_stat(unsigned char **msg, int *
 }
 
 void
-ixp_unpack_stat(unsigned char **msg, int *msize, Stat * stat) {
- unsigned short dummy;
-
- *msg += sizeof(unsigned short);
+ixp_unpack_stat(uchar **msg, int *msize, Stat * stat) {
+ ushort dummy;
+
+ *msg += sizeof(ushort);
         ixp_unpack_u16(msg, msize, &stat->type);
         ixp_unpack_u32(msg, msize, &stat->dev);
         ixp_unpack_qid(msg, msize, &stat->qid);
diff -r c9b5bed927bf -r 67eac5e46b45 fcall.h
--- a/fcall.h Tue Mar 06 03:29:46 2007 -0500
+++ b/fcall.h Tue Mar 06 03:50:06 2007 -0500
@@ -1,54 +1,54 @@
 /* from fcall(3) in plan9port */
 typedef struct Fcall {
- unsigned char type;
- unsigned short tag;
- unsigned int fid;
+ uchar type;
+ ushort tag;
+ uint fid;
         union {
                 struct { /* Tversion, Rversion */
- unsigned int msize;
+ uint msize;
                         char *version;
                 };
                 struct { /* Tflush */
- unsigned short oldtag;
+ ushort oldtag;
                 };
                 struct { /* Rerror */
                         char *ename;
                 };
                 struct { /* Ropen, Rcreate */
                         Qid qid; /* +Rattach */
- unsigned int iounit;
+ uint iounit;
                 };
                 struct { /* Rauth */
                         Qid aqid;
                 };
                 struct { /* Tauth, Tattach */
- unsigned int afid;
+ uint afid;
                         char *uname;
                         char *aname;
                 };
                 struct { /* Tcreate */
- unsigned int perm;
+ uint perm;
                         char *name;
- unsigned char mode; /* +Topen */
+ uchar mode; /* +Topen */
                 };
                 struct { /* Twalk */
- unsigned int newfid;
- unsigned short nwname;
+ uint newfid;
+ ushort nwname;
                         char *wname[IXP_MAX_WELEM];
                 };
                 struct { /* Rwalk */
- unsigned short nwqid;
+ ushort nwqid;
                         Qid wqid[IXP_MAX_WELEM];
                 };
                 struct { /* Twrite */
- unsigned long long offset; /* +Tread */
+ uvlong offset; /* +Tread */
                         /* +Rread */
- unsigned int count; /* +Tread */
+ uint count; /* +Tread */
                         char *data;
                 };
                 struct { /* Twstat, Rstat */
- unsigned short nstat;
- unsigned char *stat;
+ ushort nstat;
+ uchar *stat;
                 };
         };
 } Fcall;
diff -r c9b5bed927bf -r 67eac5e46b45 intmap.c
--- a/intmap.c Tue Mar 06 03:29:46 2007 -0500
+++ b/intmap.c Tue Mar 06 03:50:06 2007 -0500
@@ -6,14 +6,14 @@
 #define USED(v) if(v){}else{}
 
 struct Intlist {
- unsigned long id;
+ ulong id;
         void* aux;
         Intlist* link;
- unsigned int ref;
+ uint ref;
 };
 
-static unsigned long
-hashid(Intmap *map, unsigned long id) {
+static ulong
+hashid(Intmap *map, ulong id) {
         return id%map->nhash;
 }
 
@@ -23,13 +23,13 @@ nop(void *v) {
 }
 
 void
-initmap(Intmap *m, unsigned long nhash, void *hash) {
+initmap(Intmap *m, ulong nhash, void *hash) {
         m->nhash = nhash;
         m->hash = hash;
 }
 
 static Intlist**
-llookup(Intmap *map, unsigned long id) {
+llookup(Intmap *map, ulong id) {
         Intlist **lf;
 
         for(lf=&map->hash[hashid(map, id)]; *lf; lf=&(*lf)->link)
@@ -67,7 +67,7 @@ execmap(Intmap *map, void (*run)(void*))
 }
 
 void *
-lookupkey(Intmap *map, unsigned long id) {
+lookupkey(Intmap *map, ulong id) {
         Intlist *f;
         void *v;
 
@@ -79,10 +79,10 @@ lookupkey(Intmap *map, unsigned long id)
 }
 
 void *
-insertkey(Intmap *map, unsigned long id, void *v) {
+insertkey(Intmap *map, ulong id, void *v) {
         Intlist *f;
         void *ov;
- unsigned long h;
+ ulong h;
 
         if((f = *llookup(map, id))){
                 /* no decrement for ov because we're returning it */
@@ -101,10 +101,10 @@ insertkey(Intmap *map, unsigned long id,
 }
 
 int
-caninsertkey(Intmap *map, unsigned long id, void *v) {
+caninsertkey(Intmap *map, ulong id, void *v) {
         Intlist *f;
         int rv;
- unsigned long h;
+ ulong h;
 
         if(*llookup(map, id))
                 rv = 0;
@@ -121,7 +121,7 @@ caninsertkey(Intmap *map, unsigned long
 }
 
 void*
-deletekey(Intmap *map, unsigned long id) {
+deletekey(Intmap *map, ulong id) {
         Intlist **lf, *f;
         void *ov;
 
diff -r c9b5bed927bf -r 67eac5e46b45 ixp.h
--- a/ixp.h Tue Mar 06 03:29:46 2007 -0500
+++ b/ixp.h Tue Mar 06 03:50:06 2007 -0500
@@ -5,9 +5,22 @@
 
 #include <sys/types.h>
 
+#define uchar _ixpuchar
+#define ushort _ixpushort
+#define uint _ixpuint
+#define ulong _ixpulong
+#define vlong _ixpvlong
+#define uvlong _ixpuvlong
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef unsigned int uint;
+typedef unsigned long ulong;
+typedef long long vlong;
+typedef unsigned long long uvlong;
+
 #define IXP_VERSION "9P2000"
-#define IXP_NOTAG (unsigned short)~0U /*Dummy tag */
-#define IXP_NOFID (unsigned int)~0 /*No auth */
+#define IXP_NOTAG (ushort)~0U /*Dummy tag */
+#define IXP_NOFID (uint)~0 /*No auth */
 
 enum { IXP_MAX_VERSION = 32,
         IXP_MAX_ERROR = 128,
@@ -132,24 +145,24 @@ enum { P9DMREAD = 0x4, /* mode bit for
 
 typedef struct Qid Qid;
 struct Qid {
- unsigned char type;
- unsigned int version;
- unsigned long long path;
+ uchar type;
+ uint version;
+ uvlong path;
         /* internal use only */
- unsigned char dir_type;
+ uchar dir_type;
 };
 
 #include <ixp_fcall.h>
 
 /* stat structure */
 typedef struct Stat {
- unsigned short type;
- unsigned int dev;
+ ushort type;
+ uint dev;
         Qid qid;
- unsigned int mode;
- unsigned int atime;
- unsigned int mtime;
- unsigned long long length;
+ uint mode;
+ uint atime;
+ uint mtime;
+ uvlong length;
         char *name;
         char *uid;
         char *gid;
@@ -162,7 +175,7 @@ typedef struct Intmap Intmap;
 
 typedef struct Intlist Intlist;
 struct Intmap {
- unsigned long nhash;
+ ulong nhash;
         Intlist **hash;
 };
 
@@ -188,7 +201,7 @@ struct IXPServer {
 
 typedef struct IXPClient {
         int fd;
- unsigned int root_fid;
+ uint root_fid;
         Qid root_qid;
         Fcall ifcall;
         Fcall ofcall;
@@ -201,7 +214,7 @@ typedef struct Fid {
         Intmap *map;
         char *uid;
         void *aux;
- unsigned long fid;
+ ulong fid;
         Qid qid;
         signed char omode;
 } Fid;
@@ -232,76 +245,76 @@ typedef struct P9Srv {
 } P9Srv;
 
 /* client.c */
-extern int ixp_client_dial(IXPClient *c, char *address, unsigned int rootfid);
+extern int ixp_client_dial(IXPClient *c, char *address, uint rootfid);
 extern void ixp_client_hangup(IXPClient *c);
-extern int ixp_client_remove(IXPClient *c, unsigned int newfid, char *filepath);
-extern int ixp_client_create(IXPClient *c, unsigned int dirfid, char *name,
- unsigned int perm, unsigned char mode);
-extern int ixp_client_walk(IXPClient *c, unsigned int newfid, char *filepath);
-extern int ixp_client_stat(IXPClient *c, unsigned int newfid, char *filepath);
-extern int ixp_client_walkopen(IXPClient *c, unsigned int newfid, char *filepath,
- unsigned char mode);
-extern int ixp_client_open(IXPClient *c, unsigned int newfid, unsigned char mode);
-extern int ixp_client_read(IXPClient *c, unsigned int fid,
- unsigned long long offset, void *result,
- unsigned int res_len);
-extern int ixp_client_write(IXPClient *c, unsigned int fid,
- unsigned long long offset,
- unsigned int count, unsigned char *data);
-extern int ixp_client_close(IXPClient *c, unsigned int fid);
+extern int ixp_client_remove(IXPClient *c, uint newfid, char *filepath);
+extern int ixp_client_create(IXPClient *c, uint dirfid, char *name,
+ uint perm, uchar mode);
+extern int ixp_client_walk(IXPClient *c, uint newfid, char *filepath);
+extern int ixp_client_stat(IXPClient *c, uint newfid, char *filepath);
+extern int ixp_client_walkopen(IXPClient *c, uint newfid, char *filepath,
+ uchar mode);
+extern int ixp_client_open(IXPClient *c, uint newfid, uchar mode);
+extern int ixp_client_read(IXPClient *c, uint fid,
+ uvlong offset, void *result,
+ uint res_len);
+extern int ixp_client_write(IXPClient *c, uint fid,
+ uvlong offset,
+ uint count, uchar *data);
+extern int ixp_client_close(IXPClient *c, uint fid);
 extern int ixp_client_do_fcall(IXPClient * c);
 
 /* convert.c */
-extern void ixp_pack_u8(unsigned char **msg, int *msize, unsigned char val);
-extern void ixp_unpack_u8(unsigned char **msg, int *msize, unsigned char *val);
-extern void ixp_pack_u16(unsigned char **msg, int *msize, unsigned short val);
-extern void ixp_unpack_u16(unsigned char **msg, int *msize, unsigned short *val);
-extern void ixp_pack_u32(unsigned char **msg, int *msize, unsigned int val);
-extern void ixp_unpack_u32(unsigned char **msg, int *msize, unsigned int *val);
-extern void ixp_pack_u64(unsigned char **msg, int *msize, unsigned long long val);
-extern void ixp_unpack_u64(unsigned char **msg, int *msize, unsigned long long *val);
-extern void ixp_pack_string(unsigned char **msg, int *msize, const char *s);
-extern void ixp_unpack_strings(unsigned char **msg, int *msize, unsigned short n, char **strings);
-extern void ixp_unpack_string(unsigned char **msg, int *msize, char **string, unsigned short *len);
-extern void ixp_pack_data(unsigned char **msg, int *msize, unsigned char *data,
- unsigned int datalen);
-extern void ixp_unpack_data(unsigned char **msg, int *msize, unsigned char **data,
- unsigned int datalen);
-extern void ixp_pack_prefix(unsigned char *msg, unsigned int size,
- unsigned char id, unsigned short tag);
-extern void ixp_unpack_prefix(unsigned char **msg, unsigned int *size,
- unsigned char *id, unsigned short *tag);
-extern void ixp_pack_qid(unsigned char **msg, int *msize, Qid *qid);
-extern void ixp_unpack_qid(unsigned char **msg, int *msize, Qid *qid);
-extern void ixp_pack_stat(unsigned char **msg, int *msize, Stat *stat);
-extern void ixp_unpack_stat(unsigned char **msg, int *msize, Stat *stat);
+extern void ixp_pack_u8(uchar **msg, int *msize, uchar val);
+extern void ixp_unpack_u8(uchar **msg, int *msize, uchar *val);
+extern void ixp_pack_u16(uchar **msg, int *msize, ushort val);
+extern void ixp_unpack_u16(uchar **msg, int *msize, ushort *val);
+extern void ixp_pack_u32(uchar **msg, int *msize, uint val);
+extern void ixp_unpack_u32(uchar **msg, int *msize, uint *val);
+extern void ixp_pack_u64(uchar **msg, int *msize, uvlong val);
+extern void ixp_unpack_u64(uchar **msg, int *msize, uvlong *val);
+extern void ixp_pack_string(uchar **msg, int *msize, const char *s);
+extern void ixp_unpack_strings(uchar **msg, int *msize, ushort n, char **strings);
+extern void ixp_unpack_string(uchar **msg, int *msize, char **string, ushort *len);
+extern void ixp_pack_data(uchar **msg, int *msize, uchar *data,
+ uint datalen);
+extern void ixp_unpack_data(uchar **msg, int *msize, uchar **data,
+ uint datalen);
+extern void ixp_pack_prefix(uchar *msg, uint size,
+ uchar id, ushort tag);
+extern void ixp_unpack_prefix(uchar **msg, uint *size,
+ uchar *id, ushort *tag);
+extern void ixp_pack_qid(uchar **msg, int *msize, Qid *qid);
+extern void ixp_unpack_qid(uchar **msg, int *msize, Qid *qid);
+extern void ixp_pack_stat(uchar **msg, int *msize, Stat *stat);
+extern void ixp_unpack_stat(uchar **msg, int *msize, Stat *stat);
 
 /* request.c */
 extern void respond(P9Req *r, char *error);
 extern void serve_9pcon(IXPConn *c);
 
 /* intmap.c */
-extern void initmap(Intmap *m, unsigned long nhash, void *hash);
+extern void initmap(Intmap *m, ulong nhash, void *hash);
 extern void incref_map(Intmap *m);
 extern void decref_map(Intmap *m);
 extern void freemap(Intmap *map, void (*destroy)(void*));
 extern void execmap(Intmap *map, void (*destroy)(void*));
-extern void * lookupkey(Intmap *map, unsigned long id);
-extern void * insertkey(Intmap *map, unsigned long id, void *v);
-extern int caninsertkey(Intmap *map, unsigned long id, void *v);
-extern void * deletekey(Intmap *map, unsigned long id);
+extern void * lookupkey(Intmap *map, ulong id);
+extern void * insertkey(Intmap *map, ulong id, void *v);
+extern int caninsertkey(Intmap *map, ulong id, void *v);
+extern void * deletekey(Intmap *map, ulong id);
 
 /* message.c */
-extern unsigned short ixp_sizeof_stat(Stat *stat);
-extern unsigned int ixp_fcall2msg(void *msg, Fcall *fcall, unsigned int msglen);
-extern unsigned int ixp_msg2fcall(Fcall *call, void *msg, unsigned int msglen);
+extern ushort ixp_sizeof_stat(Stat *stat);
+extern uint ixp_fcall2msg(void *msg, Fcall *fcall, uint msglen);
+extern uint ixp_msg2fcall(Fcall *call, void *msg, uint msglen);
 
 /* server.c */
 extern IXPConn *ixp_server_open_conn(IXPServer *s, int fd, void *aux,
                 void (*read)(IXPConn *c), void (*close)(IXPConn *c));
 extern void ixp_server_close_conn(IXPConn *c);
 extern char *ixp_server_loop(IXPServer *s);
-extern unsigned int ixp_server_receive_fcall(IXPConn *c, Fcall *fcall);
+extern uint ixp_server_receive_fcall(IXPConn *c, Fcall *fcall);
 extern int ixp_server_respond_fcall(IXPConn *c, Fcall *fcall);
 extern int ixp_server_respond_error(IXPConn *c, Fcall *fcall, char *errstr);
 extern void ixp_server_close(IXPServer *s);
@@ -311,14 +324,14 @@ extern int ixp_create_sock(char *address
 extern int ixp_create_sock(char *address, char **errstr);
 
 /* transport.c */
-extern unsigned int ixp_send_message(int fd, void *msg, unsigned int msize, char **errstr);
-extern unsigned int ixp_recv_message(int fd, void *msg, unsigned int msglen, char **errstr);
+extern uint ixp_send_message(int fd, void *msg, uint msize, char **errstr);
+extern uint ixp_recv_message(int fd, void *msg, uint msglen, char **errstr);
 
 /* util.c */
-extern void * ixp_emalloc(unsigned int size);
-extern void * ixp_emallocz(unsigned int size);
+extern void * ixp_emalloc(uint size);
+extern void * ixp_emallocz(uint size);
 extern void ixp_eprint(const char *errstr, ...);
-extern void * ixp_erealloc(void *ptr, unsigned int size);
+extern void * ixp_erealloc(void *ptr, uint size);
 extern char * ixp_estrdup(const char *str);
-extern unsigned int ixp_tokenize(char **result, unsigned int reslen, char *str, char delim);
-extern unsigned int ixp_strlcat(char *dst, const char *src, unsigned int siz);
+extern uint ixp_tokenize(char **result, uint reslen, char *str, char delim);
+extern uint ixp_strlcat(char *dst, const char *src, uint siz);
diff -r c9b5bed927bf -r 67eac5e46b45 ixpc.c
--- a/ixpc.c Tue Mar 06 03:29:46 2007 -0500
+++ b/ixpc.c Tue Mar 06 03:50:06 2007 -0500
@@ -13,10 +13,10 @@ static char buffer[1024] = { 0 };
 static char buffer[1024] = { 0 };
 
 static void
-write_data(unsigned int fid) {
+write_data(uint fid) {
         void *data = ixp_emallocz(c.ofcall.iounit);
- unsigned long long offset = 0;
- unsigned int len = 0;
+ uvlong offset = 0;
+ uint len = 0;
 
         while((len = read(0, data, c.ofcall.iounit)) > 0) {
                 if(ixp_client_write(&c, fid, offset, len, data) != len) {
@@ -33,7 +33,7 @@ write_data(unsigned int fid) {
 
 static int
 xcreate(char *file) {
- unsigned int fid;
+ uint fid;
         char *p = strrchr(file, '/');
 
         if(!p)
@@ -56,9 +56,9 @@ xcreate(char *file) {
 }
 
 static int
-xwrite(char *file, unsigned char mode) {
+xwrite(char *file, uchar mode) {
         /* open */
- unsigned int fid = c.root_fid << 2;
+ uint fid = c.root_fid << 2;
         if(ixp_client_walkopen(&c, fid, file, mode) == -1) {
                 fprintf(stderr, "ixpc: cannot open file '%s': %s\n", file, c.errstr);
                 return -1;
@@ -68,9 +68,9 @@ xwrite(char *file, unsigned char mode) {
 }
 
 static int
-xawrite(char *file, unsigned char mode) {
+xawrite(char *file, uchar mode) {
         /* open */
- unsigned int fid = c.root_fid << 2;
+ uint fid = c.root_fid << 2;
         if(ixp_client_walkopen(&c, fid, file, mode) == -1) {
                 fprintf(stderr, "ixpc: cannot open file '%s': %s\n", file, c.errstr);
                 return -1;
@@ -103,7 +103,7 @@ setrwx(long m, char *s) {
 }
 
 static char *
-str_of_mode(unsigned int mode) {
+str_of_mode(uint mode) {
         static char buf[16];
 
         if(mode & IXP_DMDIR)
@@ -119,7 +119,7 @@ str_of_mode(unsigned int mode) {
 }
 
 static char *
-str_of_time(unsigned int val) {
+str_of_time(uint val) {
         static char buf[32];
         time_t t = (time_t)(int)val;
         char *tstr = ctime(&t);
@@ -143,9 +143,9 @@ print_stat(Stat *s, int details) {
 }
 
 static void
-xls(void *result, unsigned int msize, int details) {
- unsigned int n = 0, i = 0;
- unsigned char *p = result;
+xls(void *result, uint msize, int details) {
+ uint n = 0, i = 0;
+ uchar *p = result;
         Stat *dir;
         static Stat stat;
 
@@ -153,13 +153,13 @@ xls(void *result, unsigned int msize, in
                 ixp_unpack_stat(&p, NULL, &stat);
                 n++;
         }
- while(p - (unsigned char*)result < msize);
+ while(p - (uchar*)result < msize);
         dir = (Stat *)ixp_emallocz(sizeof(Stat) * n);
         p = result;
         do {
                 ixp_unpack_stat(&p, NULL, &dir[i++]);
         }
- while(p - (unsigned char*)result < msize);
+ while(p - (uchar*)result < msize);
         qsort(dir, n, sizeof(Stat), comp_stat);
         for(i = 0; i < n; i++)
                 print_stat(&dir[i], details);
@@ -169,14 +169,14 @@ xls(void *result, unsigned int msize, in
 
 static int
 xdir(char *file, int details) {
- unsigned int fid = c.root_fid << 2;
+ uint fid = c.root_fid << 2;
         /* XXX: buffer overflow */
         Stat *s = ixp_emallocz(sizeof(Stat));
- unsigned char *buf;
+ uchar *buf;
         int count;
- static unsigned char result[IXP_MAX_MSG];
+ static uchar result[IXP_MAX_MSG];
         void *data = NULL;
- unsigned long long offset = 0;
+ uvlong offset = 0;
 
         if(ixp_client_stat(&c, fid, file) == -1) {
                 fprintf(stderr, "ixpc: cannot stat file '%s': %s\n", file, c.errstr);
@@ -210,10 +210,10 @@ xdir(char *file, int details) {
 
 static int
 xread(char *file) {
- unsigned int fid = c.root_fid << 2;
+ uint fid = c.root_fid << 2;
         int count;
- static unsigned char result[IXP_MAX_MSG];
- unsigned long long offset = 0;
+ static uchar result[IXP_MAX_MSG];
+ uvlong offset = 0;
 
         if(ixp_client_walkopen(&c, fid, file, IXP_OREAD) == -1) {
                 fprintf(stderr, "ixpc: cannot open file '%s': %s\n", file, c.errstr);
@@ -232,7 +232,7 @@ xread(char *file) {
 
 static int
 xremove(char *file) {
- unsigned int fid;
+ uint fid;
 
         fid = c.root_fid << 2;
         if(ixp_client_remove(&c, fid, file) == -1) {
diff -r c9b5bed927bf -r 67eac5e46b45 message.c
--- a/message.c Tue Mar 06 03:29:46 2007 -0500
+++ b/message.c Tue Mar 06 03:50:06 2007 -0500
@@ -6,32 +6,32 @@
 #include <stdlib.h>
 #include <string.h>
 
-#define IXP_QIDSZ (sizeof(unsigned char) + sizeof(unsigned int)\
- + sizeof(unsigned long long))
-
-static unsigned short
+#define IXP_QIDSZ (sizeof(uchar) + sizeof(uint)\
+ + sizeof(uvlong))
+
+static ushort
 sizeof_string(const char *s) {
- return sizeof(unsigned short) + strlen(s);
-}
-
-unsigned short
+ return sizeof(ushort) + strlen(s);
+}
+
+ushort
 ixp_sizeof_stat(Stat * stat) {
         return IXP_QIDSZ
- + 2 * sizeof(unsigned short)
- + 4 * sizeof(unsigned int)
- + sizeof(unsigned long long)
+ + 2 * sizeof(ushort)
+ + 4 * sizeof(uint)
+ + sizeof(uvlong)
                 + sizeof_string(stat->name)
                 + sizeof_string(stat->uid)
                 + sizeof_string(stat->gid)
                 + sizeof_string(stat->muid);
 }
 
-unsigned int
-ixp_fcall2msg(void *msg, Fcall *fcall, unsigned int msglen) {
- unsigned int i = sizeof(unsigned char) +
- sizeof(unsigned short) + sizeof(unsigned int);
+uint
+ixp_fcall2msg(void *msg, Fcall *fcall, uint msglen) {
+ uint i = sizeof(uchar) +
+ sizeof(ushort) + sizeof(uint);
         int msize = msglen - i;
- unsigned char *p = msg + i;
+ uchar *p = (uchar*)msg + i;
 
         switch (fcall->type) {
         case TVERSION:
@@ -96,13 +96,13 @@ ixp_fcall2msg(void *msg, Fcall *fcall, u
                 break;
         case RREAD:
                 ixp_pack_u32(&p, &msize, fcall->count);
- ixp_pack_data(&p, &msize, (unsigned char *)fcall->data, fcall->count);
+ ixp_pack_data(&p, &msize, (uchar *)fcall->data, fcall->count);
                 break;
         case TWRITE:
                 ixp_pack_u32(&p, &msize, fcall->fid);
                 ixp_pack_u64(&p, &msize, fcall->offset);
                 ixp_pack_u32(&p, &msize, fcall->count);
- ixp_pack_data(&p, &msize, (unsigned char *)fcall->data, fcall->count);
+ ixp_pack_data(&p, &msize, (uchar *)fcall->data, fcall->count);
                 break;
         case RWRITE:
                 ixp_pack_u32(&p, &msize, fcall->count);
@@ -129,13 +129,13 @@ ixp_fcall2msg(void *msg, Fcall *fcall, u
         return msize;
 }
 
-unsigned int
-ixp_msg2fcall(Fcall *fcall, void *msg, unsigned int msglen) {
+uint
+ixp_msg2fcall(Fcall *fcall, void *msg, uint msglen) {
         int msize;
- unsigned int i, tsize;
- unsigned short len;
- unsigned char *p = msg;
- ixp_unpack_prefix(&p, (unsigned int *)&msize, &fcall->type, &fcall->tag);
+ uint i, tsize;
+ ushort len;
+ uchar *p = msg;
+ ixp_unpack_prefix(&p, (uint *)&msize, &fcall->type, &fcall->tag);
         tsize = msize;
 
         if(msize > msglen) /* bad message */
diff -r c9b5bed927bf -r 67eac5e46b45 request.c
--- a/request.c Tue Mar 06 03:29:46 2007 -0500
+++ b/request.c Tue Mar 06 03:50:06 2007 -0500
@@ -34,9 +34,9 @@ struct P9Conn {
         void *fidhash[FID_BUCKETS];
         P9Srv *srv;
         IXPConn *conn;
- unsigned int msize;
- unsigned char *buf;
- unsigned int ref;
+ uint msize;
+ uchar *buf;
+ uint ref;
 };
 
 static void
@@ -61,7 +61,7 @@ createfid(Intmap *map, int fid, P9Conn *
 }
 
 static int
-destroyfid(P9Conn *pc, unsigned long fid) {
+destroyfid(P9Conn *pc, ulong fid) {
         Fid *f;
         if(!(f = deletekey(&pc->fidmap, fid)))
                 return 0;
@@ -77,7 +77,7 @@ ixp_server_handle_fcall(IXPConn *c) {
         Fcall fcall = {0};
         P9Conn *pc = c->aux;
         P9Req *req;
- unsigned int msize;
+ uint msize;
         char *errstr = NULL;
 
         if(!(msize = ixp_recv_message(c->fd, pc->buf, pc->msize, &errstr)))
@@ -296,7 +296,7 @@ respond(P9Req *r, char *error) {
                         r->fid->qid = r->ofcall.qid;
                 }
                 free(r->ifcall.name);
- r->ofcall.iounit = pc->msize - sizeof(unsigned long);
+ r->ofcall.iounit = pc->msize - sizeof(ulong);
                 break;
         case TWALK:
                 if(error || r->ofcall.nwqid < r->ifcall.nwname) {
diff -r c9b5bed927bf -r 67eac5e46b45 server.c
--- a/server.c Tue Mar 06 03:29:46 2007 -0500
+++ b/server.c Tue Mar 06 03:50:06 2007 -0500
@@ -14,7 +14,7 @@
 #include <sys/un.h>
 #include <unistd.h>
 
-static unsigned char *msg[IXP_MAX_MSG];
+static uchar *msg[IXP_MAX_MSG];
 
 IXPConn *
 ixp_server_open_conn(IXPServer *s, int fd, void *aux,
@@ -86,10 +86,10 @@ ixp_server_loop(IXPServer *s) {
         return NULL;
 }
 
-unsigned int
+uint
 ixp_server_receive_fcall(IXPConn *c, Fcall *fcall)
 {
- unsigned int msize;
+ uint msize;
         char *errstr = 0;
         if(!(msize = ixp_recv_message(c->fd, msg, IXP_MAX_MSG, &errstr))) {
                 ixp_server_close_conn(c);
@@ -101,7 +101,7 @@ int
 int
 ixp_server_respond_fcall(IXPConn *c, Fcall *fcall) {
         char *errstr;
- unsigned int msize = ixp_fcall2msg(msg, fcall, IXP_MAX_MSG);
+ uint msize = ixp_fcall2msg(msg, fcall, IXP_MAX_MSG);
         if(c->closed)
                 return 0;
         if(ixp_send_message(c->fd, msg, msize, &errstr) != msize) {
diff -r c9b5bed927bf -r 67eac5e46b45 socket.c
--- a/socket.c Tue Mar 06 03:29:46 2007 -0500
+++ b/socket.c Tue Mar 06 03:50:06 2007 -0500
@@ -39,13 +39,13 @@ connect_inet_sock(char *host) {
         struct sockaddr_in addr = { 0 };
         struct hostent *hp;
         char *port = strrchr(host, '!');
- unsigned int prt;
+ uint prt;
 
         if(!port)
                 return -1;
         *port = 0;
         port++;
- if(sscanf(port, "%d", &prt) != 1)
+ if(sscanf(port, "%u", &prt) != 1)
                 return -1;
         /* init */
         if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
@@ -82,7 +82,7 @@ create_inet_sock(char *host, char **errs
         struct sockaddr_in addr = { 0 };
         struct hostent *hp;
         char *port = strrchr(host, '!');
- unsigned int prt;
+ uint prt;
 
         if(!port) {
                 *errstr = "no port provided in address";
diff -r c9b5bed927bf -r 67eac5e46b45 transport.c
--- a/transport.c Tue Mar 06 03:29:46 2007 -0500
+++ b/transport.c Tue Mar 06 03:50:06 2007 -0500
@@ -12,9 +12,9 @@
 #include <sys/un.h>
 #include <unistd.h>
 
-unsigned int
-ixp_send_message(int fd, void *msg, unsigned int msize, char **errstr) {
- unsigned int num = 0;
+uint
+ixp_send_message(int fd, void *msg, uint msize, char **errstr) {
+ uint num = 0;
         int r;
 
         /* send message */
@@ -31,9 +31,9 @@ ixp_send_message(int fd, void *msg, unsi
         return num;
 }
 
-static unsigned int
-ixp_recv_data(int fd, void *msg, unsigned int msize, char **errstr) {
- unsigned int num = 0;
+static uint
+ixp_recv_data(int fd, void *msg, uint msize, char **errstr) {
+ uint num = 0;
         int r = 0;
 
         /* receive data */
@@ -50,13 +50,13 @@ ixp_recv_data(int fd, void *msg, unsigne
         return num;
 }
 
-unsigned int
-ixp_recv_message(int fd, void *msg, unsigned int msglen, char **errstr) {
- unsigned int msize;
+uint
+ixp_recv_message(int fd, void *msg, uint msglen, char **errstr) {
+ uint msize;
 
         /* receive header */
- if(ixp_recv_data(fd, msg, sizeof(unsigned int), errstr) !=
- sizeof(unsigned int))
+ if(ixp_recv_data(fd, msg, sizeof(uint), errstr) !=
+ sizeof(uint))
                 return 0;
         ixp_unpack_u32((void *)&msg, NULL, &msize);
         if(msize > msglen) {
@@ -64,8 +64,8 @@ ixp_recv_message(int fd, void *msg, unsi
                 return 0;
         }
         /* receive message */
- if(ixp_recv_data(fd, msg, msize - sizeof(unsigned int), errstr)
- != msize - sizeof(unsigned int))
+ if(ixp_recv_data(fd, msg, msize - sizeof(uint), errstr)
+ != msize - sizeof(uint))
                 return 0;
         return msize;
 }
diff -r c9b5bed927bf -r 67eac5e46b45 util.c
--- a/util.c Tue Mar 06 03:29:46 2007 -0500
+++ b/util.c Tue Mar 06 03:50:06 2007 -0500
@@ -10,7 +10,7 @@
 #include <unistd.h>
 
 void *
-ixp_emalloc(unsigned int size) {
+ixp_emalloc(uint size) {
         void *res = malloc(size);
 
         if(!res)
@@ -19,7 +19,7 @@ ixp_emalloc(unsigned int size) {
 }
 
 void *
-ixp_emallocz(unsigned int size) {
+ixp_emallocz(uint size) {
         void *res = calloc(1, size);
 
         if(!res)
@@ -38,7 +38,7 @@ ixp_eprint(const char *errstr, ...) {
 }
 
 void *
-ixp_erealloc(void *ptr, unsigned int size) {
+ixp_erealloc(void *ptr, uint size) {
         void *res = realloc(ptr, size);
 
         if(!res)
@@ -55,10 +55,10 @@ ixp_estrdup(const char *str) {
         return res;
 }
 
-unsigned int
-ixp_tokenize(char **result, unsigned int reslen, char *str, char delim) {
+uint
+ixp_tokenize(char **result, uint reslen, char *str, char delim) {
         char *p, *n;
- unsigned int i = 0;
+ uint i = 0;
 
         if(!str)
                 return 0;
@@ -114,12 +114,12 @@ ixp_tokenize(char **result, unsigned int
  * Returns strlen(src) + MIN(siz, strlen(initial dst)).
  * If retval >= siz, truncation occurred.
  */
-unsigned int
-ixp_strlcat(char *dst, const char *src, unsigned int siz)
+uint
+ixp_strlcat(char *dst, const char *src, uint siz)
 {
         const char *s;
         char *d;
- unsigned int n, dlen;
+ uint n, dlen;
 
         n = siz;
         s = src;
Received on Tue Mar 06 2007 - 09:54:47 UTC

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