commit 9c3f2c870035faf9c6751d50d1cb82a6f983c0a1
parent a5600f2bcf64b1f4c7d49e2e5bcac26e90a8a9ab
Author: Kris Maglione <jg@suckless.org>
Date: Sun, 1 Jul 2007 16:10:21 -0400
Fix issues. Add ixp_print and ixp_vprint.
Diffstat:
11 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/cmd/Makefile b/cmd/Makefile
@@ -4,6 +4,6 @@ include ${ROOT}/mk/ixp.mk
TARG = ixpc
OBJ = ixpc
-LIB = ${ROOT}/libixp/libixp.a
+LIB = ${ROOT}/lib/libixp.a
include ${ROOT}/mk/one.mk
diff --git a/include/ixp.h b/include/ixp.h
@@ -397,6 +397,7 @@ struct IxpThread {
extern IxpThread *ixp_thread;
extern int (*ixp_vsnprint)(char*, int, char*, va_list);
+extern char* (*ixp_vsmprint)(char*, va_list);
/* thread_*.c */
int ixp_taskinit(void);
@@ -416,6 +417,8 @@ long ixp_write(IxpCFid *f, void *buf, long count);
long ixp_pread(IxpCFid *f, void *buf, long count, vlong offset);
long ixp_pwrite(IxpCFid *f, void *buf, long count, vlong offset);
int ixp_close(IxpCFid *f);
+int ixp_print(IxpCFid *f, char *fmt, ...);
+int ixp_vprint(IxpCFid *f, char *fmt, va_list ap);
/* convert.c */
void ixp_pu8(IxpMsg *msg, uchar *val);
diff --git a/libixp/client.c b/libixp/client.c
@@ -425,7 +425,7 @@ _pwrite(IxpCFid *f, void *buf, long count, vlong offset) {
fcall.type = TWrite;
fcall.fid = f->fid;
fcall.offset = f->offset;
- fcall.data = (uchar*)buf + len;
+ fcall.data = buf + len;
fcall.count = n;
if(dofcall(f->client, &fcall) == 0)
return -1;
@@ -462,3 +462,29 @@ ixp_pwrite(IxpCFid *f, void *buf, long count, vlong offset) {
return n;
}
+int
+ixp_vprint(IxpCFid *f, char *fmt, va_list ap) {
+ char *buf;
+ int n;
+
+ buf = ixp_vsmprint(fmt, ap);
+ if(buf == nil)
+ return -1;
+
+ n = ixp_write(f, buf, strlen(buf));
+ free(buf);
+ return n;
+}
+
+int
+ixp_print(IxpCFid *f, char *fmt, ...) {
+ va_list ap;
+ int n;
+
+ va_start(ap, fmt);
+ n = ixp_vprint(f, fmt, ap);
+ va_end(ap);
+
+ return n;
+}
+
diff --git a/libixp/convert.c b/libixp/convert.c
@@ -133,7 +133,7 @@ ixp_pstrings(IxpMsg *msg, ushort *num, char *strings[]) {
if(msg->mode == MsgUnpack) {
memcpy(s, msg->pos, len);
- strings[i] = s;
+ strings[i] = (char*)s;
s += len;
msg->pos += len;
*s++ = '\0';
diff --git a/libixp/error.c b/libixp/error.c
@@ -1,10 +1,33 @@
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "ixp_local.h"
-int (*ixp_vsnprint)(char*, int, char*, va_list);
+static int
+_vsnprint(char *buf, int n, char *fmt, va_list ap) {
+ return vsnprintf(buf, n, fmt, ap);
+}
+
+static char*
+_vsmprint(char *fmt, va_list ap) {
+ va_list al;
+ char *buf = "";
+ int n;
+
+ va_copy(al, ap);
+ n = snprintf(buf, 0, fmt, al);
+ va_end(al);
+
+ buf = malloc(++n);
+ if(buf)
+ snprintf(buf, n, fmt, ap);
+ return buf;
+}
+
+int (*ixp_vsnprint)(char*, int, char*, va_list) = _vsnprint;
+char* (*ixp_vsmprint)(char*, va_list) = _vsmprint;
/* Approach to errno handling taken from Plan 9 Port. */
enum {
@@ -44,10 +67,7 @@ werrstr(char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
- if(ixp_vsnprint)
- ixp_vsnprint(tmp, sizeof(tmp), fmt, ap);
- else
- vsnprintf(tmp, sizeof(tmp), fmt, ap);
+ ixp_vsnprint(tmp, sizeof(tmp), fmt, ap);
va_end(ap);
strncpy(thread->errbuf(), tmp, IXP_ERRMAX);
errno = EPLAN9;
diff --git a/libixp/message.c b/libixp/message.c
@@ -169,7 +169,7 @@ ixp_pfcall(IxpMsg *msg, Fcall *fcall) {
uint
ixp_fcall2msg(IxpMsg *msg, Fcall *fcall) {
- int size;
+ uint size;
msg->end = msg->data + msg->size;
msg->pos = msg->data + SDWord;
diff --git a/libixp_pthread/thread_pthread.c b/libixp_pthread/thread_pthread.c
@@ -3,7 +3,6 @@
#include <stdlib.h>
#include <unistd.h>
#include "ixp_local.h"
-#include "ixp_pthread.h"
static IxpThread ixp_pthread;
static pthread_key_t errstr_k;
diff --git a/libixp_rubythread/thread_ruby.c b/libixp_rubythread/thread_ruby.c
@@ -3,7 +3,6 @@
#include <unistd.h>
#include <ruby.h>
#include "ixp_local.h"
-#include "ixp_rubythread.h"
static IxpThread ixp_rthread;
static char RWLock[];
diff --git a/libixp_task/thread_task.c b/libixp_task/thread_task.c
@@ -3,7 +3,6 @@
#include <unistd.h>
#include <task.h>
#include "ixp_local.h"
-#include "ixp_task.h"
static IxpThread ixp_task;
diff --git a/mk/lib.mk b/mk/lib.mk
@@ -18,8 +18,8 @@ printinstall:
echo ' Lib: ${LIBDIR}'
${LIB}: ${OFILES}
- @echo AR $$($(ROOT)/util/cleanname $(BASE)/$@)
- @${AR} $@ ${OFILES}
- @${RANLIB} $@
+ echo AR $$($(ROOT)/util/cleanname $(BASE)/$@)
+ mkdir ${ROOT}/lib 2>/dev/null || true
+ ${AR} $@ ${OFILES}
include ${ROOT}/mk/common.mk
diff --git a/util/compile b/util/compile
@@ -12,8 +12,9 @@ $CC -o $outfile $CFLAGS $@ 2>$xtmp
status=$?
base=$(echo $BASE | sed 's/,/\\,/g')
+re='\([^[:space:]/]*\..:[0-9]\)'
-cat $xtmp | sed "s,^[^/][^:]*\.c:,$base&,g" |
+cat $xtmp | sed "s,^$re,$base&,g; s,\([[:space:]]\)$re,\1$base\2,g" |
egrep -v ': error: .Each undeclared identifier|: error: for each function it appears|is dangerous, better use|is almost always misused|: In function |: At top level:|support .long long.|use of C99 long long|ISO C forbids conversion' |
sed 's/ .first use in this function.$//; s/\"\([^\"][^\"]*\)\", line \([0-9][0-9]*\)/\1:\2/g' |
uniq 1>&2