commit dbe076a6ac464a6481caeec6909efcf7e38fcc15
parent 7accffd86d439e57fdcd45de4448534045516103
Author: Kris Maglione <jg@suckless.org>
Date: Tue, 6 Mar 2007 04:09:20 -0500
Fixed some void pointer arithmatic and fixed some signedness issues.
Diffstat:
5 files changed, 23 insertions(+), 30 deletions(-)
diff --git a/ixp.h b/ixp.h
@@ -61,18 +61,6 @@ enum { TVERSION = 100,
RWSTAT,
};
-/* borrowed from libc.h of Plan 9 */
-enum { IXP_DMDIR = 0x80000000, /* mode bit for directories */
- IXP_DMAPPEND = 0x40000000, /* mode bit for append only files */
- IXP_DMEXCL = 0x20000000, /* mode bit for exclusive use files */
- IXP_DMMOUNT = 0x10000000, /* mode bit for mounted channel */
- IXP_DMAUTH = 0x08000000, /* mode bit for authentication file */
- IXP_DMTMP = 0x04000000, /* mode bit for non-backed-up file */
- IXP_DMREAD = 0x4<<6, /* mode bit for read permission */
- IXP_DMWRITE = 0x2<<6, /* mode bit for write permission */
- IXP_DMEXEC = 0x1<<6 /* mode bit for execute permission */
-};
-
/* modes */
enum { IXP_OREAD = 0x00,
IXP_OWRITE = 0x01,
diff --git a/ixpc.c b/ixpc.c
@@ -46,7 +46,7 @@ xcreate(char *file) {
return -1;
}
p++;
- if(ixp_client_create(&c, fid, p, IXP_DMWRITE, IXP_OWRITE) == -1) {
+ if(ixp_client_create(&c, fid, p, P9DMWRITE, P9OWRITE) == -1) {
fprintf(stderr, "ixpc: cannot create file '%s': %s\n", p, c.errstr);
return -1;
}
@@ -75,7 +75,7 @@ xawrite(char *file, uchar mode) {
fprintf(stderr, "ixpc: cannot open file '%s': %s\n", file, c.errstr);
return -1;
}
- if(ixp_client_write(&c, fid, 0, strlen(buffer), buffer) != strlen(buffer))
+ if(ixp_client_write(&c, fid, 0, strlen(buffer), (uchar*)buffer) != strlen(buffer))
fprintf(stderr, "ixpc: cannot write file: %s\n", c.errstr);
return ixp_client_close(&c, fid);
}
@@ -106,7 +106,7 @@ static char *
str_of_mode(uint mode) {
static char buf[16];
- if(mode & IXP_DMDIR)
+ if(mode & P9DMDIR)
buf[0]='d';
else
buf[0]='-';
@@ -135,7 +135,7 @@ print_stat(Stat *s, int details) {
fprintf(stdout, "%s %s %s %5llu %s %s\n", str_of_mode(s->mode),
s->uid, s->gid, s->length, str_of_time(s->mtime), s->name);
else {
- if(s->mode & IXP_DMDIR)
+ if(s->mode & P9DMDIR)
fprintf(stdout, "%s/\n", s->name);
else
fprintf(stdout, "%s\n", s->name);
@@ -184,19 +184,19 @@ xdir(char *file, int details) {
}
buf = c.ofcall.stat;
ixp_unpack_stat(&buf, NULL, s);
- if(!(s->mode & IXP_DMDIR)) {
+ if(!(s->mode & P9DMDIR)) {
print_stat(s, details);
fflush(stdout);
return 0;
}
/* directory */
- if(ixp_client_open(&c, fid, IXP_OREAD) == -1) {
+ if(ixp_client_open(&c, fid, P9OREAD) == -1) {
fprintf(stderr, "ixpc: cannot open directory '%s': %s\n", file, c.errstr);
return -1;
}
while((count = ixp_client_read(&c, fid, offset, result, IXP_MAX_MSG)) > 0) {
data = ixp_erealloc(data, offset + count);
- memcpy(data + offset, result, count);
+ memcpy((uchar*)data + offset, result, count);
offset += count;
}
if(count == -1) {
@@ -215,7 +215,7 @@ xread(char *file) {
static uchar result[IXP_MAX_MSG];
uvlong offset = 0;
- if(ixp_client_walkopen(&c, fid, file, IXP_OREAD) == -1) {
+ if(ixp_client_walkopen(&c, fid, file, P9OREAD) == -1) {
fprintf(stderr, "ixpc: cannot open file '%s': %s\n", file, c.errstr);
return -1;
}
@@ -279,7 +279,7 @@ main(int argc, char *argv[]) {
else if(!strncmp(cmd, "remove", 7))
ret = xremove(file);
else if(!strncmp(cmd, "write", 6))
- ret = xwrite(file, IXP_OWRITE);
+ ret = xwrite(file, P9OWRITE);
else if(!strncmp(cmd, "xwrite", 7)) {
if(i < argc)
ixp_strlcat(buffer, argv[i++], 1023);
@@ -288,7 +288,7 @@ main(int argc, char *argv[]) {
if(ixp_strlcat(buffer, argv[i++], 1024) > 1023)
break;
}
- ret = xawrite(file, IXP_OWRITE);
+ ret = xawrite(file, P9OWRITE);
}else {
Usage:
ixp_eprint("usage: ixpc [-a <address>] {create | read | ls [-l] | remove | write} <file>\n"
diff --git a/message.c b/message.c
@@ -28,10 +28,13 @@ ixp_sizeof_stat(Stat * stat) {
uint
ixp_fcall2msg(void *msg, Fcall *fcall, uint msglen) {
- uint i = sizeof(uchar) +
- sizeof(ushort) + sizeof(uint);
- int msize = msglen - i;
- uchar *p = (uchar*)msg + i;
+ int msize;
+ uint i;
+ uchar *p;
+
+ i = sizeof(uchar) + sizeof(ushort) + sizeof(uint);
+ msize = msglen - i;
+ p = (uchar*)msg + i;
switch (fcall->type) {
case TVERSION:
@@ -134,7 +137,9 @@ ixp_msg2fcall(Fcall *fcall, void *msg, uint msglen) {
int msize;
uint i, tsize;
ushort len;
- uchar *p = msg;
+ uchar *p;
+
+ p = msg;
ixp_unpack_prefix(&p, (uint *)&msize, &fcall->type, &fcall->tag);
tsize = msize;
diff --git a/socket.c b/socket.c
@@ -90,7 +90,7 @@ create_inet_sock(char *host, char **errstr) {
}
*port = 0;
port++;
- if(sscanf(port, "%d", &prt) != 1) {
+ if(sscanf(port, "%u", &prt) != 1) {
*errstr = "invalid port number";
return -1;
}
diff --git a/transport.c b/transport.c
@@ -19,7 +19,7 @@ ixp_send_message(int fd, void *msg, uint msize, char **errstr) {
/* send message */
while(num < msize) {
- r = write(fd, msg + num, msize - num);
+ r = write(fd, (uchar*)msg + num, msize - num);
if(r == -1 && errno == EINTR)
continue;
if(r < 1) {
@@ -38,7 +38,7 @@ ixp_recv_data(int fd, void *msg, uint msize, char **errstr) {
/* receive data */
while(num < msize) {
- r = read(fd, msg + num, msize - num);
+ r = read(fd, (uchar*)msg + num, msize - num);
if(r == -1 && errno == EINTR)
continue;
if(r < 1) {