From 5eb1cdf88852e1a973fb6b49c1bb180470f4ac02 Mon Sep 17 00:00:00 2001 From: leitner Date: Thu, 25 Nov 2004 21:29:35 +0000 Subject: [PATCH] cleanups in stralloc and buffer: int -> long for sizes char -> unsigned char for strings --- CHANGES | 3 ++ buffer.h | 58 ++++++++++++++--------------- buffer/buffer_get.3 | 2 +- buffer/buffer_get.c | 2 +- buffer/buffer_get_new_token_sa.c | 2 +- buffer/buffer_get_token.3 | 4 +- buffer/buffer_get_token.c | 2 +- buffer/buffer_get_token_pred.3 | 4 +- buffer/buffer_get_token_pred.c | 3 +- buffer/buffer_get_token_sa.3 | 2 +- buffer/buffer_get_token_sa.c | 4 +- buffer/buffer_getc.3 | 2 +- buffer/buffer_getc.c | 2 +- buffer/buffer_getline.3 | 2 +- buffer/buffer_getn.3 | 2 +- buffer/buffer_getn.c | 2 +- buffer/buffer_init.3 | 2 +- buffer/buffer_init.c | 3 +- buffer/buffer_put.3 | 2 +- buffer/buffer_put.c | 4 +- buffer/buffer_put8long.c | 2 +- buffer/buffer_putalign.3 | 2 +- buffer/buffer_putalign.c | 2 +- buffer/buffer_putflush.3 | 2 +- buffer/buffer_putflush.c | 2 +- buffer/buffer_putlong.c | 2 +- buffer/buffer_putlonglong.c | 2 +- buffer/buffer_putm_internal.c | 2 +- buffer/buffer_putm_internal_flush.c | 2 +- buffer/buffer_puts.3 | 2 +- buffer/buffer_puts.c | 2 +- buffer/buffer_putsalign.3 | 2 +- buffer/buffer_putsalign.c | 2 +- buffer/buffer_putsflush.3 | 2 +- buffer/buffer_putsflush.c | 2 +- buffer/buffer_putxlong.c | 2 +- buffer/buffer_seek.3 | 2 +- buffer/buffer_seek.c | 5 ++- buffer/buffer_stubborn.c | 2 +- buffer/buffer_stubborn2.c | 2 +- stralloc.h | 32 ++++++++-------- stralloc/stralloc_0.3 | 2 + stralloc/stralloc_append.3 | 4 +- stralloc/stralloc_append.c | 6 +-- stralloc/stralloc_cat.3 | 2 + stralloc/stralloc_catb.3 | 4 +- stralloc/stralloc_catb.c | 2 +- stralloc/stralloc_catlong0.3 | 4 +- stralloc/stralloc_catlong0.c | 2 +- stralloc/stralloc_catm.3 | 14 ++++--- stralloc/stralloc_cats.3 | 4 +- stralloc/stralloc_cats.c | 2 +- stralloc/stralloc_catulong0.3 | 4 +- stralloc/stralloc_catulong0.c | 2 +- stralloc/stralloc_chomp.3 | 2 + stralloc/stralloc_chop.3 | 2 + stralloc/stralloc_copy.3 | 2 + stralloc/stralloc_copyb.3 | 6 ++- stralloc/stralloc_copyb.c | 2 +- stralloc/stralloc_copym.3 | 8 ++-- stralloc/stralloc_copys.3 | 6 ++- stralloc/stralloc_copys.c | 2 +- stralloc/stralloc_diff.3 | 2 + stralloc/stralloc_diffs.3 | 4 +- stralloc/stralloc_diffs.c | 4 +- stralloc/stralloc_free.3 | 4 +- stralloc/stralloc_init.3 | 6 ++- stralloc/stralloc_ready.3 | 4 +- stralloc/stralloc_ready.c | 2 +- stralloc/stralloc_readyplus.3 | 4 +- stralloc/stralloc_readyplus.c | 7 ++-- stralloc/stralloc_starts.3 | 4 +- stralloc/stralloc_starts.c | 4 +- stralloc/stralloc_zero.3 | 6 +-- stralloc/stralloc_zero.c | 5 +++ 75 files changed, 188 insertions(+), 132 deletions(-) create mode 100644 stralloc/stralloc_zero.c diff --git a/CHANGES b/CHANGES index 4b946f9..672e2c8 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,9 @@ add buffer_putsflush add stralloc_catm and stralloc_copym add buffer_putm and buffer_putmflush + cleanups in stralloc and buffer: + int -> long for sizes + char -> unsigned char for strings 0.20: add errmsg API diff --git a/buffer.h b/buffer.h index a85c84d..2e31cd0 100644 --- a/buffer.h +++ b/buffer.h @@ -2,12 +2,12 @@ #define BUFFER_H typedef struct buffer { - char *x; /* actual buffer space */ - unsigned int p; /* current position */ - unsigned int n; /* current size of string in buffer */ - unsigned int a; /* allocated buffer size */ - int fd; /* passed as first argument to op */ - int (*op)(); /* use read(2) or write(2) */ + unsigned char *x; /* actual buffer space */ + unsigned long int p; /* current position */ + unsigned long int n; /* current size of string in buffer */ + unsigned long int a; /* allocated buffer size */ + int fd; /* passed as first argument to op */ + int (*op)(); /* use read(2) or write(2) */ } buffer; #define BUFFER_INIT(op,fd,buf,len) { (buf), 0, 0, (len), (fd), (op) } @@ -15,15 +15,15 @@ typedef struct buffer { #define BUFFER_INSIZE 8192 #define BUFFER_OUTSIZE 8192 -void buffer_init(buffer* b,int (*op)(),int fd,char* y,unsigned int ylen); +void buffer_init(buffer* b,int (*op)(),int fd,unsigned char* y,unsigned long int ylen); int buffer_flush(buffer* b); -int buffer_put(buffer* b,const char* x,unsigned int len); -int buffer_putalign(buffer* b,const char* x,unsigned int len); -int buffer_putflush(buffer* b,const char* x,unsigned int len); -int buffer_puts(buffer* b,const char* x); -int buffer_putsalign(buffer* b,const char* x); -int buffer_putsflush(buffer* b,const char* x); +int buffer_put(buffer* b,const unsigned char* x,unsigned long int len); +int buffer_putalign(buffer* b,const unsigned char* x,unsigned long int len); +int buffer_putflush(buffer* b,const unsigned char* x,unsigned long int len); +int buffer_puts(buffer* b,const unsigned char* x); +int buffer_putsalign(buffer* b,const unsigned char* x); +int buffer_putsflush(buffer* b,const unsigned char* x); int buffer_putm_internal(buffer*b,...); int buffer_putm_internal_flush(buffer*b,...); @@ -39,27 +39,27 @@ int buffer_putnlflush(buffer* b); /* put \n and flush */ : buffer_put((s),&(c),1) \ ) -int buffer_get(buffer* b,char* x,unsigned int len); +int buffer_get(buffer* b,unsigned char* x,unsigned long int len); int buffer_feed(buffer* b); -int buffer_getc(buffer* b,char* x); -int buffer_getn(buffer* b,char* x,unsigned int len); +int buffer_getc(buffer* b,unsigned char* x); +int buffer_getn(buffer* b,unsigned char* x,unsigned long int len); /* read bytes until the destination buffer is full (len bytes), end of * file is reached or the read char is in charset (setlen bytes). An * empty line when looking for \n will write '\n' to x and return 0. If * EOF is reached, \0 is written to the buffer */ -int buffer_get_token(buffer* b,char* x,unsigned int len,const char* charset,unsigned int setlen); -#define buffer_getline(b,x,len) buffer_get_token((b),(x),(len),"\n",1) +int buffer_get_token(buffer* b,unsigned char* x,unsigned long int len,const unsigned char* charset,unsigned long int setlen); +int buffer_getline(buffer* b,unsigned char* x,unsigned long int len); /* this predicate is given the string as currently read from the buffer * and is supposed to return 1 if the token is complete, 0 if not. */ -typedef int (*string_predicate)(const char* x,unsigned int len); +typedef int (*string_predicate)(const unsigned char* x,unsigned long int len); /* like buffer_get_token but the token ends when your predicate says so */ -int buffer_get_token_pred(buffer* b,char* x,unsigned int len,string_predicate p); +int buffer_get_token_pred(buffer* b,unsigned char* x,unsigned long int len,string_predicate p); char *buffer_peek(buffer* b); -void buffer_seek(buffer* b,unsigned int len); +void buffer_seek(buffer* b,unsigned long int len); #define buffer_PEEK(s) ( (s)->x + (s)->p ) #define buffer_SEEK(s,len) ( (s)->p += (len) ) @@ -72,13 +72,13 @@ void buffer_seek(buffer* b,unsigned int len); int buffer_copy(buffer* out,buffer* in); -int buffer_putulong(buffer *b,unsigned long l); -int buffer_put8long(buffer *b,unsigned long l); -int buffer_putxlong(buffer *b,unsigned long l); -int buffer_putlong(buffer *b,signed long l); +int buffer_putulong(buffer *b,unsigned long int l); +int buffer_put8long(buffer *b,unsigned long int l); +int buffer_putxlong(buffer *b,unsigned long int l); +int buffer_putlong(buffer *b,signed long int l); -int buffer_putlonglong(buffer* b,signed long long l); -int buffer_putulonglong(buffer* b,unsigned long long l); +int buffer_putlonglong(buffer* b,signed long long int l); +int buffer_putulonglong(buffer* b,unsigned long long int l); int buffer_puterror(buffer* b); int buffer_puterror2(buffer* b, int errnum); @@ -107,12 +107,12 @@ int buffer_putsaflush(buffer* b,stralloc* sa); * data is available. */ /* read token from buffer to stralloc */ -int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen); +int buffer_get_token_sa(buffer* b,stralloc* sa,const unsigned char* charset,unsigned long int setlen); /* read line from buffer to stralloc */ int buffer_getline_sa(buffer* b,stralloc* sa); /* same as buffer_get_token_sa but empty sa first */ -int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen); +int buffer_get_new_token_sa(buffer* b,stralloc* sa,const unsigned char* charset,unsigned long int setlen); /* same as buffer_getline_sa but empty sa first */ int buffer_getnewline_sa(buffer* b,stralloc* sa); diff --git a/buffer/buffer_get.3 b/buffer/buffer_get.3 index 35e7ff9..1d1de45 100644 --- a/buffer/buffer_get.3 +++ b/buffer/buffer_get.3 @@ -4,7 +4,7 @@ buffer_get \- read binary data from buffer .SH SYNTAX .B #include -int \fBbuffer_get\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned int \fIlen\fR); +int \fBbuffer_get\fP(buffer* \fIb\fR,unsigned char* \fIx\fR,unsigned long int \fIlen\fR); .SH DESCRIPTION Normally buffer_get copies data to \fIx\fR[0], \fIx\fR[1], ..., \fIx\fR[\fIlen\fR-1] from the beginning of a string stored in diff --git a/buffer/buffer_get.c b/buffer/buffer_get.c index 905bcdf..788f3fd 100644 --- a/buffer/buffer_get.c +++ b/buffer/buffer_get.c @@ -1,7 +1,7 @@ #include "byte.h" #include "buffer.h" -int buffer_get(buffer* b,char* x,unsigned int len) { +int buffer_get(buffer* b,unsigned char* x,unsigned long int len) { int blen; if ((blen=buffer_feed(b))>=len) blen=len; diff --git a/buffer/buffer_get_new_token_sa.c b/buffer/buffer_get_new_token_sa.c index c261799..51cb3f5 100644 --- a/buffer/buffer_get_new_token_sa.c +++ b/buffer/buffer_get_new_token_sa.c @@ -1,7 +1,7 @@ #include "stralloc.h" #include "buffer.h" -int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen) { +int buffer_get_new_token_sa(buffer* b,stralloc* sa,const unsigned char* charset,unsigned long int setlen) { stralloc_zero(sa); return buffer_get_token_sa(b,sa,charset,setlen); } diff --git a/buffer/buffer_get_token.3 b/buffer/buffer_get_token.3 index 7905f82..0755bb0 100644 --- a/buffer/buffer_get_token.3 +++ b/buffer/buffer_get_token.3 @@ -4,8 +4,8 @@ buffer_get_token \- read token from buffer .SH SYNTAX .B #include -int \fBbuffer_get_token\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned int \fIlen\fR, - const char* \fIcharset\fR,unsigned int \fIsetlen\fR); +int \fBbuffer_get_token\fP(buffer* \fIb\fR,unsigned char* \fIx\fR,unsigned long int \fIlen\fR, + const unsigned char* \fIcharset\fR,unsigned long int \fIsetlen\fR); .SH DESCRIPTION buffer_get_token copies data from \fIb\fR to \fIx\fR[0], \fIx\fR[1], ..., \fIx\fR[\fIlen\fR-1] until \fIlen\fR bytes have been copied or one of diff --git a/buffer/buffer_get_token.c b/buffer/buffer_get_token.c index e49ff2e..9d2391b 100644 --- a/buffer/buffer_get_token.c +++ b/buffer/buffer_get_token.c @@ -2,7 +2,7 @@ #include "buffer.h" #include "scan.h" -int buffer_get_token(buffer* b,char* x,unsigned int len,const char* charset,unsigned int setlen) { +int buffer_get_token(buffer* b,unsigned char* x,unsigned long int len,const unsigned char* charset,unsigned long int setlen) { int blen; for (blen=0;blen -int \fBbuffer_get_token_pred\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned int \fIlen\fR, - int (*\fIpredicate\fR)(const char* \fIs\fR,unsigned int \fIlen\fR)); +int \fBbuffer_get_token_pred\fP(buffer* \fIb\fR,unsigned char* \fIx\fR,unsigned long int \fIlen\fR, + int (*\fIpredicate\fR)(const unsigned char* \fIs\fR,unsigned long int \fIlen\fR)); .SH DESCRIPTION buffer_get_token_pred copies data from \fIb\fR to \fIx\fR[0], \fIx\fR[1], ..., \fIx\fR[\fIlen\fR-1] until \fIlen\fR bytes have been diff --git a/buffer/buffer_get_token_pred.c b/buffer/buffer_get_token_pred.c index 88c297d..057100f 100644 --- a/buffer/buffer_get_token_pred.c +++ b/buffer/buffer_get_token_pred.c @@ -2,7 +2,8 @@ #include "buffer.h" #include "scan.h" -int buffer_get_token_pred(buffer* b,char* x,unsigned int len,string_predicate p) { +int buffer_get_token_pred(buffer* b,unsigned char* x,unsigned long int len, + string_predicate p) { int blen; for (blen=0;blen int \fBbuffer_get_token_sa\fP(buffer* \fIb\fR,stralloc* \fIsa\fR, - const char* \fIcharset\fR,unsigned int \fIsetlen\fR); + const unsigned char* \fIcharset\fR,unsigned long int \fIsetlen\fR); .SH DESCRIPTION buffer_get_token_sa appends data from the \fIb\fR to \fIsa\fR until one of the delimiters in \fIcharset\fR is found, NOT overwriting the diff --git a/buffer/buffer_get_token_sa.c b/buffer/buffer_get_token_sa.c index 08cb2ab..19ce938 100644 --- a/buffer/buffer_get_token_sa.c +++ b/buffer/buffer_get_token_sa.c @@ -3,7 +3,9 @@ #include "buffer.h" #include -int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen) { +int buffer_get_token_sa(buffer* b,stralloc* sa, + const unsigned char* charset, + unsigned long int setlen) { for (;;) { char x; if (!stralloc_readyplus(sa,1)) goto nomem; diff --git a/buffer/buffer_getc.3 b/buffer/buffer_getc.3 index 3ebc3b7..b299507 100644 --- a/buffer/buffer_getc.3 +++ b/buffer/buffer_getc.3 @@ -4,7 +4,7 @@ buffer_getc \- read one char from buffer .SH SYNTAX .B #include -int \fBbuffer_getc\fP(buffer* \fIb\fR,char* \fIx\fR); +int \fBbuffer_getc\fP(buffer* \fIb\fR,unsigned char* \fIx\fR); .SH DESCRIPTION buffer_getc(b,x) is similar to buffer_get(b,x,1). .SH "SEE ALSO" diff --git a/buffer/buffer_getc.c b/buffer/buffer_getc.c index b507c2a..85d4413 100644 --- a/buffer/buffer_getc.c +++ b/buffer/buffer_getc.c @@ -1,7 +1,7 @@ #include "byte.h" #include "buffer.h" -int buffer_getc(buffer* b,char* x) { +int buffer_getc(buffer* b,unsigned char* x) { if (b->p==b->n) { register int blen; if ((blen=buffer_feed(b))<=0) return blen; diff --git a/buffer/buffer_getline.3 b/buffer/buffer_getline.3 index cb304ab..995f01e 100644 --- a/buffer/buffer_getline.3 +++ b/buffer/buffer_getline.3 @@ -4,7 +4,7 @@ buffer_getline \- read line from buffer .SH SYNTAX .B #include -int \fBbuffer_getline\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned int \fIlen\fR); +int \fBbuffer_getline\fP(buffer* \fIb\fR,unsigned char* \fIx\fR,unsigned long int \fIlen\fR); .SH DESCRIPTION buffer_getline copies data from \fIb\fR to \fIx\fR[0], \fIx\fR[1], ..., \fIx\fR[\fIlen\fR-1] until \fIlen\fR bytes have been copied or a diff --git a/buffer/buffer_getn.3 b/buffer/buffer_getn.3 index 7217356..3851396 100644 --- a/buffer/buffer_getn.3 +++ b/buffer/buffer_getn.3 @@ -4,7 +4,7 @@ buffer_getn \- read binary data from buffer .SH SYNTAX .B #include -int \fBbuffer_getn\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned int \fIlen\fR); +int \fBbuffer_getn\fP(buffer* \fIb\fR,unsigned char* \fIx\fR,unsigned long int \fIlen\fR); .SH DESCRIPTION buffer_getn copies data to \fIx\fR[0], \fIx\fR[1], ..., \fIx\fR[\fIlen\fR-1] from the buffer, calling buffer_feed as needed, and diff --git a/buffer/buffer_getn.c b/buffer/buffer_getn.c index 4617d13..78affde 100644 --- a/buffer/buffer_getn.c +++ b/buffer/buffer_getn.c @@ -1,7 +1,7 @@ #include "byte.h" #include "buffer.h" -int buffer_getn(buffer* b,char* x,unsigned int len) { +int buffer_getn(buffer* b,unsigned char* x,unsigned long int len) { int blen; for(blen=0;blenop=op; b->fd=fd; b->x=y; diff --git a/buffer/buffer_put.3 b/buffer/buffer_put.3 index 93cbb03..89db53e 100644 --- a/buffer/buffer_put.3 +++ b/buffer/buffer_put.3 @@ -4,7 +4,7 @@ buffer_put \- write binary data to buffer .SH SYNTAX .B #include -int \fBbuffer_put\fP(buffer* \fIb\fR,const char* \fIx\fR,unsigned int \fIlen\fR); +int \fBbuffer_put\fP(buffer* \fIb\fR,const unsigned char* \fIx\fR,unsigned long int \fIlen\fR); .SH DESCRIPTION buffer_put writes \fIlen\fR bytes from \fIx\fR to \fIb\fR. diff --git a/buffer/buffer_put.c b/buffer/buffer_put.c index d53b6cc..953ae5e 100644 --- a/buffer/buffer_put.c +++ b/buffer/buffer_put.c @@ -1,9 +1,9 @@ #include "byte.h" #include "buffer.h" -extern int buffer_stubborn(int (*op)(),int fd,const char* buf, unsigned int len); +extern int buffer_stubborn(int (*op)(),int fd,const unsigned char* buf, unsigned long int len); -int buffer_put(buffer* b,const char* buf,unsigned int len) { +int buffer_put(buffer* b,const unsigned char* buf,unsigned long int len) { if (len>b->a-b->p) { /* doesn't fit */ if (buffer_flush(b)==-1) return -1; if (len>b->a) { diff --git a/buffer/buffer_put8long.c b/buffer/buffer_put8long.c index 8ee0a7b..b987b04 100644 --- a/buffer/buffer_put8long.c +++ b/buffer/buffer_put8long.c @@ -2,7 +2,7 @@ #include "fmt.h" int buffer_put8long(buffer *b,unsigned long l) { - char buf[FMT_8LONG]; + unsigned char buf[FMT_8LONG]; return buffer_put(b,buf,fmt_8long(buf,l)); } diff --git a/buffer/buffer_putalign.3 b/buffer/buffer_putalign.3 index 977cffd..928e637 100644 --- a/buffer/buffer_putalign.3 +++ b/buffer/buffer_putalign.3 @@ -4,7 +4,7 @@ buffer_putalign \- write binary data to buffer .SH SYNTAX .B #include -int \fBbuffer_putalign\fP(buffer* \fIb\fR,const char* \fIx\fR,unsigned int \fIlen\fR); +int \fBbuffer_putalign\fP(buffer* \fIb\fR,const unsigned char* \fIx\fR,unsigned long int \fIlen\fR); .SH DESCRIPTION buffer_putalign is similar to buffer_put. diff --git a/buffer/buffer_putalign.c b/buffer/buffer_putalign.c index 0ff1cd4..ab11b11 100644 --- a/buffer/buffer_putalign.c +++ b/buffer/buffer_putalign.c @@ -1,7 +1,7 @@ #include "byte.h" #include "buffer.h" -int buffer_putalign(buffer* b,const char* buf,unsigned int len) { +int buffer_putalign(buffer* b,const unsigned char* buf,unsigned long int len) { int tmp; while (len>(tmp=b->a-b->p)) { byte_copy(b->x+b->p, tmp, buf); diff --git a/buffer/buffer_putflush.3 b/buffer/buffer_putflush.3 index 3adef3a..9c0673e 100644 --- a/buffer/buffer_putflush.3 +++ b/buffer/buffer_putflush.3 @@ -5,7 +5,7 @@ buffer_putflush \- write binary data to buffer and flush .B #include int \fBbuffer_putflush\fP(buffer* \fIb\fR, - const char* \fIx\fR,unsigned int \fIlen\fR); + const unsigned char* \fIx\fR,unsigned long int \fIlen\fR); .SH DESCRIPTION buffer_putflush is similar to calling buffer_put(\fIb\fR,\fIx\fR,\fIlen\fR) and then buffer_flush(\fIb\fR). diff --git a/buffer/buffer_putflush.c b/buffer/buffer_putflush.c index 9e8e87e..b47742f 100644 --- a/buffer/buffer_putflush.c +++ b/buffer/buffer_putflush.c @@ -1,6 +1,6 @@ #include "buffer.h" -int buffer_putflush(buffer* b,const char* x,unsigned int len) { +int buffer_putflush(buffer* b,const unsigned char* x,unsigned long int len) { if (buffer_put(b,x,len)<0) return -1; if (buffer_flush(b)<0) return -1; return 0; diff --git a/buffer/buffer_putlong.c b/buffer/buffer_putlong.c index c622f34..0806f31 100644 --- a/buffer/buffer_putlong.c +++ b/buffer/buffer_putlong.c @@ -2,7 +2,7 @@ #include "fmt.h" int buffer_putlong(buffer *b,signed long l) { - char buf[FMT_LONG]; + unsigned char buf[FMT_LONG]; return buffer_put(b,buf,fmt_long(buf,l)); } diff --git a/buffer/buffer_putlonglong.c b/buffer/buffer_putlonglong.c index efbcbfe..a4ee4b3 100644 --- a/buffer/buffer_putlonglong.c +++ b/buffer/buffer_putlonglong.c @@ -2,7 +2,7 @@ #include "fmt.h" int buffer_putlonglong(buffer *b,signed long long l) { - char buf[FMT_LONG]; + unsigned char buf[FMT_LONG]; return buffer_put(b,buf,fmt_longlong(buf,l)); } diff --git a/buffer/buffer_putm_internal.c b/buffer/buffer_putm_internal.c index 1370600..6212b4d 100644 --- a/buffer/buffer_putm_internal.c +++ b/buffer/buffer_putm_internal.c @@ -6,7 +6,7 @@ int buffer_putm_internal(buffer* b, ...) { va_list a; const char* s; va_start(a,b); - while ((s=va_arg(a,const char*))) + while ((s=va_arg(a,const unsigned char*))) if (buffer_puts(b,s)==-1) { r=-1; break; diff --git a/buffer/buffer_putm_internal_flush.c b/buffer/buffer_putm_internal_flush.c index a5afbcb..f007c4c 100644 --- a/buffer/buffer_putm_internal_flush.c +++ b/buffer/buffer_putm_internal_flush.c @@ -6,7 +6,7 @@ int buffer_putm_internal_flush(buffer* b, ...) { va_list a; const char* s; va_start(a,b); - while ((s=va_arg(a,const char*))) + while ((s=va_arg(a,const unsigned char*))) if (buffer_puts(b,s)==-1) { r=-1; break; diff --git a/buffer/buffer_puts.3 b/buffer/buffer_puts.3 index 72a16c5..196e673 100644 --- a/buffer/buffer_puts.3 +++ b/buffer/buffer_puts.3 @@ -4,7 +4,7 @@ buffer_puts \- write ASCIIZ string to buffer .SH SYNTAX .B #include -int \fBbuffer_puts\fP(buffer* \fIb\fR,const char* \fIx\fR); +int \fBbuffer_puts\fP(buffer* \fIb\fR,const unsigned char* \fIx\fR); .SH DESCRIPTION buffer_puts is like buffer_put with \fIlen\fR determined as the number of bytes before the first \\0 in \fIx\fR. diff --git a/buffer/buffer_puts.c b/buffer/buffer_puts.c index e53f675..fe13221 100644 --- a/buffer/buffer_puts.c +++ b/buffer/buffer_puts.c @@ -1,6 +1,6 @@ #include "str.h" #include "buffer.h" -int buffer_puts(buffer* b,const char* x) { +int buffer_puts(buffer* b,const unsigned char* x) { return buffer_put(b,x,str_len(x)); } diff --git a/buffer/buffer_putsalign.3 b/buffer/buffer_putsalign.3 index 49912d8..e0d02cd 100644 --- a/buffer/buffer_putsalign.3 +++ b/buffer/buffer_putsalign.3 @@ -4,7 +4,7 @@ buffer_putsalign \- write ASCIIZ string to buffer .SH SYNTAX .B #include -int \fBbuffer_putsalign\fP(buffer* \fIb\fR,const char* \fIx\fR); +int \fBbuffer_putsalign\fP(buffer* \fIb\fR,const unsigned char* \fIx\fR); .SH DESCRIPTION buffer_putsalign is like buffer_putalign with \fIlen\fR determined as the number of bytes before the first \\0 in \fIx\fR. diff --git a/buffer/buffer_putsalign.c b/buffer/buffer_putsalign.c index 2693e5c..2853483 100644 --- a/buffer/buffer_putsalign.c +++ b/buffer/buffer_putsalign.c @@ -1,6 +1,6 @@ #include "str.h" #include "buffer.h" -int buffer_putsalign(buffer* b,const char* x) { +int buffer_putsalign(buffer* b,const unsigned char* x) { return buffer_putalign(b,x,str_len(x)); } diff --git a/buffer/buffer_putsflush.3 b/buffer/buffer_putsflush.3 index ad5199d..3e2b533 100644 --- a/buffer/buffer_putsflush.3 +++ b/buffer/buffer_putsflush.3 @@ -4,7 +4,7 @@ buffer_putsflush \- write ASCIIZ string to buffer and flush .SH SYNTAX .B #include -int \fBbuffer_putsflush\fP(buffer* \fIb\fR,const char* \fIx\fR); +int \fBbuffer_putsflush\fP(buffer* \fIb\fR,const unsigned char* \fIx\fR); .SH DESCRIPTION buffer_putsflush is like buffer_putflush with \fIlen\fR determined as the number of bytes before the first \\0 in \fIx\fR. diff --git a/buffer/buffer_putsflush.c b/buffer/buffer_putsflush.c index e01762d..e0185d3 100644 --- a/buffer/buffer_putsflush.c +++ b/buffer/buffer_putsflush.c @@ -1,6 +1,6 @@ #include "str.h" #include "buffer.h" -int buffer_putsflush(buffer* b,const char* x) { +int buffer_putsflush(buffer* b,const unsigned char* x) { return buffer_putflush(b,x,str_len(x)); } diff --git a/buffer/buffer_putxlong.c b/buffer/buffer_putxlong.c index 7938646..22ee6eb 100644 --- a/buffer/buffer_putxlong.c +++ b/buffer/buffer_putxlong.c @@ -2,7 +2,7 @@ #include "fmt.h" int buffer_putxlong(buffer *b,unsigned long l) { - char buf[FMT_XLONG]; + unsigned char buf[FMT_XLONG]; return buffer_put(b,buf,fmt_xlong(buf,l)); } diff --git a/buffer/buffer_seek.3 b/buffer/buffer_seek.3 index 84f1f75..7cc5140 100644 --- a/buffer/buffer_seek.3 +++ b/buffer/buffer_seek.3 @@ -4,7 +4,7 @@ buffer_seek \- remove bytes from beginning of string in buffer .SH SYNTAX .B #include -int \fBbuffer_seek\fP(buffer* \fIb\fR,unsigned int \fIr\fR); +int \fBbuffer_seek\fP(buffer* \fIb\fR,unsigned long int \fIr\fR); .SH DESCRIPTION buffer_seek removes \fIr\fR bytes from the beginning of the string. \fIr\fR must be at most the current length of the string. diff --git a/buffer/buffer_seek.c b/buffer/buffer_seek.c index 2d053bd..7821ac8 100644 --- a/buffer/buffer_seek.c +++ b/buffer/buffer_seek.c @@ -1,7 +1,8 @@ #include "buffer.h" -void buffer_seek(buffer* b,unsigned int len) { - unsigned int n=b->p+len; +void buffer_seek(buffer* b,unsigned long int len) { + unsigned long int n=b->p+len; + if (np) n=b->p; if (n>b->n) n=b->n; b->p=n; } diff --git a/buffer/buffer_stubborn.c b/buffer/buffer_stubborn.c index c94a1d0..c206608 100644 --- a/buffer/buffer_stubborn.c +++ b/buffer/buffer_stubborn.c @@ -1,7 +1,7 @@ #include #include "buffer.h" -int buffer_stubborn(int (*op)(),int fd,const char* buf, unsigned int len) { +int buffer_stubborn(int (*op)(),int fd,const unsigned char* buf, unsigned long int len) { int w; while (len) { if ((w=op(fd,buf,len))<0) { diff --git a/buffer/buffer_stubborn2.c b/buffer/buffer_stubborn2.c index 37103ed..a54e089 100644 --- a/buffer/buffer_stubborn2.c +++ b/buffer/buffer_stubborn2.c @@ -1,7 +1,7 @@ #include #include "buffer.h" -int buffer_stubborn_read(int (*op)(),int fd,const char* buf, unsigned int len) { +int buffer_stubborn_read(int (*op)(),int fd,const unsigned char* buf, unsigned long int len) { int w; for (;;) { if ((w=op(fd,buf,len))<0) diff --git a/stralloc.h b/stralloc.h index 08c3754..3fe8eff 100644 --- a/stralloc.h +++ b/stralloc.h @@ -16,8 +16,8 @@ typedef struct stralloc { char* s; - unsigned int len; - unsigned int a; + unsigned long int len; + unsigned long int a; } stralloc; /* stralloc_init will initialize a stralloc. @@ -32,22 +32,22 @@ void stralloc_init(stralloc* sa); * bytes of space, copies the old string into the new space, frees the * old space, and returns 1. Note that this changes sa.s. If the * allocation fails, stralloc_ready leaves sa alone and returns 0. */ -int stralloc_ready(stralloc* sa,unsigned int len); +int stralloc_ready(stralloc* sa,unsigned long int len); /* stralloc_readyplus is like stralloc_ready except that, if sa is * already allocated, stralloc_readyplus adds the current length of sa * to len. */ -int stralloc_readyplus(stralloc* sa,unsigned int len); +int stralloc_readyplus(stralloc* sa,unsigned long int len); /* stralloc_copyb copies the string buf[0], buf[1], ..., buf[len-1] into * sa, allocating space if necessary, and returns 1. If it runs out of * memory, stralloc_copyb leaves sa alone and returns 0. */ -int stralloc_copyb(stralloc* sa,const char* buf,unsigned int len); +int stralloc_copyb(stralloc* sa,const unsigned char* buf,unsigned long int len); /* stralloc_copys copies a \0-terminated string from buf into sa, * without the \0. It is the same as * stralloc_copyb(&sa,buf,str_len(buf)). */ -int stralloc_copys(stralloc* sa,const char* buf); +int stralloc_copys(stralloc* sa,const unsigned char* buf); /* stralloc_copy copies the string stored in sa2 into sa. It is the same * as stralloc_copyb(&sa,sa2.s,sa2.len). sa2 must already be allocated. */ @@ -58,12 +58,12 @@ int stralloc_copy(stralloc* sa,const stralloc* sa2); * returns 1. If sa is unallocated, stralloc_catb is the same as * stralloc_copyb. If it runs out of memory, stralloc_catb leaves sa * alone and returns 0. */ -int stralloc_catb(stralloc* sa,const char* in,unsigned int len); +int stralloc_catb(stralloc* sa,const unsigned char* in,unsigned long int len); /* stralloc_cats is analogous to stralloc_copys */ -int stralloc_cats(stralloc* sa,const char* in); +int stralloc_cats(stralloc* sa,const unsigned char* in); -#define stralloc_zero(sa) stralloc_copys(sa,"") +void stralloc_zero(stralloc* sa); /* like stralloc_cats but can cat more than one string at once */ int stralloc_catm_internal(stralloc* sa,...); @@ -76,12 +76,12 @@ int stralloc_cat(stralloc* sa,stralloc* in); /* stralloc_append adds one byte in[0] to the end of the string stored * in sa. It is the same as stralloc_catb(&sa,in,1). */ -int stralloc_append(stralloc* sa,const char* in); /* beware: this takes a pointer to 1 char */ +int stralloc_append(stralloc* sa,const unsigned char* in); /* beware: this takes a pointer to 1 char */ /* stralloc_starts returns 1 if the \0-terminated string in "in", without * the terminating \0, is a prefix of the string stored in sa. Otherwise * it returns 0. sa must already be allocated. */ -int stralloc_starts(stralloc* sa,const char* in) __pure__; +int stralloc_starts(stralloc* sa,const unsigned char* in) __pure__; /* stralloc_diff returns negative, 0, or positive, depending on whether * a is lexicographically smaller than, equal to, or greater than the @@ -91,7 +91,7 @@ int stralloc_diff(const stralloc* a,const stralloc* b) __pure__; /* stralloc_diffs returns negative, 0, or positive, depending on whether * a is lexicographically smaller than, equal to, or greater than the * string b[0], b[1], ..., b[n]=='\0'. */ -int stralloc_diffs(const stralloc* a,const char* b) __pure__; +int stralloc_diffs(const stralloc* a,const unsigned char* b) __pure__; #define stralloc_equal(a,b) (!stralloc_diff((a),(b))) #define stralloc_equals(a,b) (!stralloc_diffs((a),(b))) @@ -100,10 +100,10 @@ int stralloc_diffs(const stralloc* a,const char* b) __pure__; #define stralloc_0(sa) stralloc_append(sa,"") /* stralloc_catulong0 appends a '0' padded ASCII representation of in */ -int stralloc_catulong0(stralloc* sa,unsigned long in,unsigned int n); +int stralloc_catulong0(stralloc* sa,unsigned long int in,unsigned long int n); /* stralloc_catlong0 appends a '0' padded ASCII representation of in */ -int stralloc_catlong0(stralloc* sa,signed long in,unsigned int n); +int stralloc_catlong0(stralloc* sa,signed long int in,unsigned long int n); /* stralloc_free frees the storage associated with sa */ void stralloc_free(stralloc* sa); @@ -137,12 +137,12 @@ int buffer_putsaflush(buffer* b,stralloc* sa); * data is available. */ /* read token from buffer to stralloc */ -int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen); +int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned long int setlen); /* read line from buffer to stralloc */ int buffer_getline_sa(buffer* b,stralloc* sa); /* same as buffer_get_token_sa but empty sa first */ -int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen); +int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned long int setlen); /* same as buffer_getline_sa but empty sa first */ int buffer_getnewline_sa(buffer* b,stralloc* sa); diff --git a/stralloc/stralloc_0.3 b/stralloc/stralloc_0.3 index bcd0b0b..e4dbcb3 100644 --- a/stralloc/stralloc_0.3 +++ b/stralloc/stralloc_0.3 @@ -9,5 +9,7 @@ int \fBstralloc_0\fP(stralloc* \fIsa\fR); stralloc_0 appends \\0 to a stralloc. It is a shortcut for stralloc_append(\fIsa\fR,""). +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" stralloc_append(3) diff --git a/stralloc/stralloc_append.3 b/stralloc/stralloc_append.3 index 5170718..6719fbc 100644 --- a/stralloc/stralloc_append.3 +++ b/stralloc/stralloc_append.3 @@ -4,7 +4,7 @@ stralloc_append \- append a character to a stralloc .SH SYNTAX .B #include -int \fBstralloc_append\fP(stralloc* \fIsa\fR,const char* \fIin\fR); +int \fBstralloc_append\fP(stralloc* \fIsa\fR,const unsigned char* \fIin\fR); .SH DESCRIPTION stralloc_append appends the byte from *\fIbuf\fR to the string stored in \fIsa\fR, allocating space if necessary, and @@ -12,5 +12,7 @@ returns 1. If it runs out of memory, stralloc_append leaves \fIsa\fR alone and returns 0. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" stralloc_copyb(3) diff --git a/stralloc/stralloc_append.c b/stralloc/stralloc_append.c index c90c778..42156ec 100644 --- a/stralloc/stralloc_append.c +++ b/stralloc/stralloc_append.c @@ -1,8 +1,8 @@ #include "stralloc.h" -/* stralloc_append adds one byte in[0] to the end of the string stored - * in sa. It is the same as stralloc_catb(&sa,in,1). */ -int stralloc_append(stralloc *sa,const char *in) { +/* stralloc_append adds one byte in[0] to the end of the string stored + * in sa. It is the same as stralloc_catb(&sa,in,1). */ +int stralloc_append(stralloc *sa,const unsigned char *in) { if (stralloc_readyplus(sa,1)) { sa->s[sa->len]=*in; ++sa->len; diff --git a/stralloc/stralloc_cat.3 b/stralloc/stralloc_cat.3 index 332d94d..f46bed8 100644 --- a/stralloc/stralloc_cat.3 +++ b/stralloc/stralloc_cat.3 @@ -12,5 +12,7 @@ is the same as \fIsafrom\fR must already be allocated. The data that \fIsa\fR previously contained is overwritten and truncated. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" stralloc_catb(3) diff --git a/stralloc/stralloc_catb.3 b/stralloc/stralloc_catb.3 index 8b53f03..351aa52 100644 --- a/stralloc/stralloc_catb.3 +++ b/stralloc/stralloc_catb.3 @@ -4,7 +4,7 @@ stralloc_catb \- append data to a stralloc .SH SYNTAX .B #include -int \fBstralloc_catb\fP(stralloc* \fIsa\fR,const char* \fIbuf\fR,unsigned int \fIlen\fR); +int \fBstralloc_catb\fP(stralloc* \fIsa\fR,const unsigned char* \fIbuf\fR,unsigned long int \fIlen\fR); .SH DESCRIPTION stralloc_catb adds the string \fIbuf\fR[0], \fIbuf\fR[1], ... \fIbuf\fR[\fIlen\fR-1] to the end of the string stored in \fIsa\fR, allocating space if necessary, and @@ -12,3 +12,5 @@ returns 1. If \fIsa\fR is unallocated, stralloc_catb is the same as stralloc_copyb. If it runs out of memory, stralloc_catb leaves \fIsa\fR alone and returns 0. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. diff --git a/stralloc/stralloc_catb.c b/stralloc/stralloc_catb.c index ed28912..a7bda3c 100644 --- a/stralloc/stralloc_catb.c +++ b/stralloc/stralloc_catb.c @@ -6,7 +6,7 @@ * returns 1. If sa is unallocated, stralloc_catb is the same as * stralloc_copyb. If it runs out of memory, stralloc_catb leaves sa * alone and returns 0. */ -int stralloc_catb(stralloc *sa,const char *buf,unsigned int len) { +int stralloc_catb(stralloc *sa,const unsigned char *buf,unsigned long int len) { if (stralloc_readyplus(sa,len)) { byte_copy(sa->s+sa->len,len,buf); sa->len+=len; diff --git a/stralloc/stralloc_catlong0.3 b/stralloc/stralloc_catlong0.3 index 7edd3fc..29b5061 100644 --- a/stralloc/stralloc_catlong0.3 +++ b/stralloc/stralloc_catlong0.3 @@ -4,12 +4,14 @@ stralloc_catlong0 \- append an integer to a stralloc .SH SYNTAX .B #include -int \fBstralloc_catlong0\fP(stralloc* \fIsa\fR, unsigned long \fIin\fR, unsigned int \fIn\fR); +int \fBstralloc_catlong0\fP(stralloc* \fIsa\fR, unsigned long int \fIin\fR, unsigned long int \fIn\fR); .SH DESCRIPTION stralloc_catlong0 converts in to a string using \fBfmt_long0\fR and appends the result to \fIsa\fR, allocating memory as necessary. If there was a memory allocation failure, stralloc_catlong0 returns 0, else 1. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" fmt_long0(3) diff --git a/stralloc/stralloc_catlong0.c b/stralloc/stralloc_catlong0.c index 66c6160..aa50c3e 100644 --- a/stralloc/stralloc_catlong0.c +++ b/stralloc/stralloc_catlong0.c @@ -1,7 +1,7 @@ #include "stralloc.h" #include "fmt.h" -int stralloc_catlong0(stralloc *sa,signed long in,unsigned int n) { +int stralloc_catlong0(stralloc *sa,signed long int in,unsigned long int n) { if (stralloc_readyplus(sa,fmt_minus(0,in)+fmt_ulong0(0,in,n))) { sa->len+=fmt_minus(sa->s+sa->len,in); sa->len+=fmt_ulong0(sa->s+sa->len,in>=0?in:-in,n); diff --git a/stralloc/stralloc_catm.3 b/stralloc/stralloc_catm.3 index 9c7c331..e069e64 100644 --- a/stralloc/stralloc_catm.3 +++ b/stralloc/stralloc_catm.3 @@ -4,14 +4,16 @@ stralloc_catm \- append string(s) to a stralloc .SH SYNTAX .B #include -int \fBstralloc_cats\fP(stralloc* \fIsa\fR,const char* \fIs\fR, ...); +int \fBstralloc_catm\fP(stralloc* \fIsa\fR,const unsigned char* \fIs\fR, ...); .SH DESCRIPTION -stralloc_cats appends \\0-terminated strings from \fIs\fR... to the +stralloc_catm appends \\0-terminated strings from \fIs\fR... to the end of the string stored in \fIsa\fR, allocating space if necessary, and -returns 1. If \fIsa\fR is unallocated, stralloc_cats is the same as -stralloc_copys. +returns 1. If \fIsa\fR is unallocated, stralloc_catm is the same as +stralloc_copym. -If it runs out of memory, stralloc_cats returns 0. At that point, it +If it runs out of memory, stralloc_catm returns 0. At that point, it may already have copied a few of the strings to sa. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" -stralloc_cats(3) +stralloc_copym(3) diff --git a/stralloc/stralloc_cats.3 b/stralloc/stralloc_cats.3 index 20fa628..4d94216 100644 --- a/stralloc/stralloc_cats.3 +++ b/stralloc/stralloc_cats.3 @@ -4,12 +4,14 @@ stralloc_cats \- append data to a stralloc .SH SYNTAX .B #include -int \fBstralloc_cats\fP(stralloc* \fIsa\fR,const char* \fIbuf\fR); +int \fBstralloc_cats\fP(stralloc* \fIsa\fR,const unsigned char* \fIbuf\fR); .SH DESCRIPTION stralloc_cats appends a \\0-terminated string from \fIbuf\fR to the end of the string stored in \fIsa\fR, allocating space if necessary, and returns 1. If \fIsa\fR is unallocated, stralloc_cats is the same as stralloc_copys. If it runs out of memory, stralloc_cats leaves \fIsa\fR alone and returns 0. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" stralloc_copyb(3) diff --git a/stralloc/stralloc_cats.c b/stralloc/stralloc_cats.c index 483f099..01f54a9 100644 --- a/stralloc/stralloc_cats.c +++ b/stralloc/stralloc_cats.c @@ -1,7 +1,7 @@ #include "stralloc.h" #include "str.h" -extern int stralloc_cats(stralloc *sa,const char *buf) { +extern int stralloc_cats(stralloc *sa,const unsigned char *buf) { return stralloc_catb(sa,buf,str_len(buf)); } diff --git a/stralloc/stralloc_catulong0.3 b/stralloc/stralloc_catulong0.3 index f9c89c2..57ce3c0 100644 --- a/stralloc/stralloc_catulong0.3 +++ b/stralloc/stralloc_catulong0.3 @@ -4,12 +4,14 @@ stralloc_catulong0 \- append an integer to a stralloc .SH SYNTAX .B #include -int \fBstralloc_catulong0\fP(stralloc* \fIsa\fR, unsigned long \fIin\fR, unsigned int \fIn\fR); +int \fBstralloc_catulong0\fP(stralloc* \fIsa\fR, unsigned long int \fIin\fR, unsigned long int \fIn\fR); .SH DESCRIPTION stralloc_catulong0 converts in to a string using \fBfmt_ulong0\fR and appends the result to \fIsa\fR, allocating memory as necessary. If there was a memory allocation failure, stralloc_catulong0 returns 0, else 1. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" fmt_ulong0(3) diff --git a/stralloc/stralloc_catulong0.c b/stralloc/stralloc_catulong0.c index f0f8eba..8a35bdf 100644 --- a/stralloc/stralloc_catulong0.c +++ b/stralloc/stralloc_catulong0.c @@ -1,7 +1,7 @@ #include "stralloc.h" #include "fmt.h" -int stralloc_catulong0(stralloc *sa,unsigned long in,unsigned int n) { +int stralloc_catulong0(stralloc *sa,unsigned long int in,unsigned long int n) { if (stralloc_readyplus(sa,fmt_ulong0(0,in,n))) { sa->len+=fmt_ulong0(sa->s+sa->len,in,n); return 1; diff --git a/stralloc/stralloc_chomp.3 b/stralloc/stralloc_chomp.3 index 39508c9..2178933 100644 --- a/stralloc/stralloc_chomp.3 +++ b/stralloc/stralloc_chomp.3 @@ -8,5 +8,7 @@ int \fBstralloc_chomp\fP(stralloc* \fIsa\fR); .SH DESCRIPTION stralloc_chomp removes trailing CRLF, CR or LF from \fIsa\fR and returns the number of removed characters (i.e. 0, 1 or 2). +.SH "RETURN VALUE" +number of removed characters (0, 1, or 2). .SH "SEE ALSO" stralloc_chop(3) diff --git a/stralloc/stralloc_chop.3 b/stralloc/stralloc_chop.3 index 7db01fa..6ac5e72 100644 --- a/stralloc/stralloc_chop.3 +++ b/stralloc/stralloc_chop.3 @@ -9,5 +9,7 @@ int \fBstralloc_chop\fP(stralloc* \fIsa\fR); stralloc_chop removes the last char in the stralloc (if it is empty, stralloc_chop does nothing and returns -1). This character is cast to unsigned char and returned. +.SH "RETURN VALUE" +chopped character, or -1 if string was empty. .SH "SEE ALSO" stralloc_chomp(3) diff --git a/stralloc/stralloc_copy.3 b/stralloc/stralloc_copy.3 index 002345f..67b1d2a 100644 --- a/stralloc/stralloc_copy.3 +++ b/stralloc/stralloc_copy.3 @@ -15,5 +15,7 @@ The data that \fIsa\fR previously contained is overwritten and truncated. If stralloc_copy has trouble allocating memory, it returns 0. Otherwise it returns 1. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" stralloc_copyb(3) diff --git a/stralloc/stralloc_copyb.3 b/stralloc/stralloc_copyb.3 index c84bc75..eea3d5b 100644 --- a/stralloc/stralloc_copyb.3 +++ b/stralloc/stralloc_copyb.3 @@ -4,13 +4,15 @@ stralloc_copyb \- copy data into a stralloc .SH SYNTAX .B #include -int \fBstralloc_copyb\fP(stralloc* \fIsa\fR,const char* \fIbuf\fR,unsigned int \fIlen\fR); +int \fBstralloc_copyb\fP(stralloc* \fIsa\fR,const unsigned char* \fIbuf\fR,unsigned long int \fIlen\fR); .SH DESCRIPTION stralloc_copyb makes sure that \fIsa\fR has enough space allocated to hold \fIlen\fR bytes. Then it copies the first \fIlen\fR bytes from \fIbuf\fR into the stralloc. The data that \fIsa\fR previously contained is overwritten and truncated. -.SH "RETURN VALUE" + If stralloc_copys runs out of memory, stralloc_copys leaves \fIsa\fR alone and return 0, otherwise it returns 1. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. diff --git a/stralloc/stralloc_copyb.c b/stralloc/stralloc_copyb.c index 0729874..ec9267a 100644 --- a/stralloc/stralloc_copyb.c +++ b/stralloc/stralloc_copyb.c @@ -4,7 +4,7 @@ /* stralloc_copyb copies the string buf[0], buf[1], ..., buf[len-1] into * sa, allocating space if necessary, and returns 1. If it runs out of * memory, stralloc_copyb leaves sa alone and returns 0. */ -int stralloc_copyb(stralloc *sa,const char *buf,unsigned int len) { +int stralloc_copyb(stralloc *sa,const unsigned char *buf,unsigned long int len) { if (stralloc_ready(sa,len)) { sa->len=len; byte_copy(sa->s,len,buf); diff --git a/stralloc/stralloc_copym.3 b/stralloc/stralloc_copym.3 index cc19334..bd5ca9b 100644 --- a/stralloc/stralloc_copym.3 +++ b/stralloc/stralloc_copym.3 @@ -1,16 +1,18 @@ -.TH stralloc_catm 3 +.TH stralloc_copym 3 .SH NAME stralloc_copym \- copy string(s) to a stralloc .SH SYNTAX .B #include -int \fBstralloc_copys\fP(stralloc* \fIsa\fR,const char* \fIs\fR, ...); +int \fBstralloc_copym\fP(stralloc* \fIsa\fR,const char* \fIs\fR, ...); .SH DESCRIPTION stralloc_cats copies \\0-terminated strings from \fIs\fR... to \fIsa\fR, allocating space if necessary, and returns 1. If there is data in the \fIsa\fR, it is cleared first. -If it runs out of memory, stralloc_copys returns 0. At that point, it +If it runs out of memory, stralloc_copym returns 0. At that point, it may already have copied a few of the strings to sa. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" stralloc_copys(3) diff --git a/stralloc/stralloc_copys.3 b/stralloc/stralloc_copys.3 index 6570c27..80e8672 100644 --- a/stralloc/stralloc_copys.3 +++ b/stralloc/stralloc_copys.3 @@ -4,15 +4,17 @@ stralloc_copys \- copy data into a stralloc .SH SYNTAX .B #include -int \fBstralloc_copys\fP(stralloc* \fIsa\fR,const char* \fIbuf\fR); +int \fBstralloc_copys\fP(stralloc* \fIsa\fR,const unsigned char* \fIbuf\fR); .SH DESCRIPTION stralloc_copys copies a \\0-terminated string from \fIbuf\fR into \fIsa\fR, without the \\0. It is the same as \fBstralloc_copyb\fR(&\fIsa\fR, \fIbuf\fR, str_len(\fIbuf\fR)). The data that \fIsa\fR previously contained is overwritten and truncated. -.SH "RETURN VALUE" + If stralloc_copys runs out of memory, stralloc_copys leaves \fIsa\fR alone and return 0, otherwise it returns 1. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" stralloc_copyb(3) diff --git a/stralloc/stralloc_copys.c b/stralloc/stralloc_copys.c index 80360ea..d03c3d4 100644 --- a/stralloc/stralloc_copys.c +++ b/stralloc/stralloc_copys.c @@ -1,7 +1,7 @@ #include "stralloc.h" #include "str.h" -extern int stralloc_copys(stralloc *sa,const char *buf) { +extern int stralloc_copys(stralloc *sa,const unsigned char *buf) { return stralloc_copyb(sa,buf,str_len(buf)); } diff --git a/stralloc/stralloc_diff.3 b/stralloc/stralloc_diff.3 index b0bb154..205ee45 100644 --- a/stralloc/stralloc_diff.3 +++ b/stralloc/stralloc_diff.3 @@ -9,5 +9,7 @@ int \fBstralloc_diff\fP(const stralloc* \fIa\fR,const stralloc* \fIb\fR); stralloc_diff returns negative, 0, or positive, depending on whether \fIa\fR is lexicographically smaller than, equal to, or greater than the string \fIb\fR. +.SH "RETURN VALUE" +<0 if a0 if a>b. .SH "SEE ALSO" stralloc_diffs(3), stralloc_starts(3) diff --git a/stralloc/stralloc_diffs.3 b/stralloc/stralloc_diffs.3 index baf03db..1aa81d4 100644 --- a/stralloc/stralloc_diffs.3 +++ b/stralloc/stralloc_diffs.3 @@ -4,11 +4,13 @@ stralloc_diffs \- check if string is prefix of stralloc .SH SYNTAX .B #include -int \fBstralloc_diffs\fP(stralloc* \fIa\fR,const char* \fIb\fR); +int \fBstralloc_diffs\fP(stralloc* \fIa\fR,const unsigned char* \fIb\fR); .SH DESCRIPTION stralloc_diffs returns negative, 0, or positive, depending on whether the \\0-terminated string in \fIa\fR, without the terminating \\0, is lexicographically smaller than, equal to, or greater than the string stored in \fIa\fR. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" stralloc_diff(3), stralloc_starts(3), str_diff(3) diff --git a/stralloc/stralloc_diffs.c b/stralloc/stralloc_diffs.c index 2b51675..e5cac51 100644 --- a/stralloc/stralloc_diffs.c +++ b/stralloc/stralloc_diffs.c @@ -2,8 +2,8 @@ #include "byte.h" #include "str.h" -extern int stralloc_diffs(const stralloc* a,const char* b) { - register unsigned int i; +extern int stralloc_diffs(const stralloc* a,const unsigned char* b) { + register unsigned long int i; register int j; for (i=0;;++i) { if (i==a->len) return (!b[i])?0:-1; if (!b[i]) return 1; diff --git a/stralloc/stralloc_free.3 b/stralloc/stralloc_free.3 index 2ef6e37..57fb0e5 100644 --- a/stralloc/stralloc_free.3 +++ b/stralloc/stralloc_free.3 @@ -4,9 +4,11 @@ stralloc_free \- free storage associated with a stralloc .SH SYNTAX .B #include -int \fBstralloc_free\fP(stralloc* \fIsa\fR); +void \fBstralloc_free\fP(stralloc* \fIsa\fR); .SH DESCRIPTION stralloc_free returns the storage associated with \fIsa\fR to the system. Afterwards, the stralloc is unallocated. +.SH "RETURN VALUE" +none. .SH "SEE ALSO" stralloc_ready(3) diff --git a/stralloc/stralloc_init.3 b/stralloc/stralloc_init.3 index fc4430c..043c08b 100644 --- a/stralloc/stralloc_init.3 +++ b/stralloc/stralloc_init.3 @@ -4,12 +4,14 @@ stralloc_init \- initialize a stralloc .SH SYNTAX .B #include -int \fBstralloc_init\fP(stralloc* \fIsa\fR); +void \fBstralloc_init\fP(stralloc* \fIsa\fR); .SH DESCRIPTION stralloc_init initializes a stralloc to the empty string. It does not free any memory previously associated with a stralloc. Use stralloc_free(3) for that. If you just want to empty a stralloc, use -stralloc_copys(sa,"") instead. +stralloc_zero(sa) instead. +.SH "RETURN VALUE" +none. .SH "SEE ALSO" stralloc_free(3), stralloc_copys(3) diff --git a/stralloc/stralloc_ready.3 b/stralloc/stralloc_ready.3 index eac9a8d..0b8f8cc 100644 --- a/stralloc/stralloc_ready.3 +++ b/stralloc/stralloc_ready.3 @@ -4,7 +4,7 @@ stralloc_ready \- provide space in a stralloc .SH SYNTAX .B #include -int \fBstralloc_ready\fP(stralloc* \fIsa\fR,unsigned int \fIlen\fR); +int \fBstralloc_ready\fP(stralloc* \fIsa\fR,unsigned long int \fIlen\fR); .SH DESCRIPTION stralloc_ready makes sure that \fIsa\fR has enough space allocated to hold \fIlen\fR bytes: If \fIsa\fR is not allocated, stralloc_ready allocates at least @@ -15,5 +15,7 @@ old space, and returns 1. Note that this changes \fIsa\fR.s. If stralloc_ready runs out of memory, it leaves \fIsa\fR alone and returns 0. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" stralloc_readyplus(3) diff --git a/stralloc/stralloc_ready.c b/stralloc/stralloc_ready.c index 6de7018..dc44cb5 100644 --- a/stralloc/stralloc_ready.c +++ b/stralloc/stralloc_ready.c @@ -7,7 +7,7 @@ * not enough to hold len bytes, stralloc_ready allocates at least len * bytes of space, copies the old string into the new space, frees the * old space, and returns 1. Note that this changes sa.s. */ -int stralloc_ready(stralloc *sa,unsigned int len) { +int stralloc_ready(stralloc *sa,unsigned long int len) { register int wanted=len+(len>>3)+30; /* heuristic from djb */ if (!sa->s || sa->a -int \fBstralloc_readyplus\fP(stralloc* \fIsa\fR,unsigned int \fIlen\fR); +int \fBstralloc_readyplus\fP(stralloc* \fIsa\fR,unsigned long int \fIlen\fR); .SH DESCRIPTION stralloc_readyplus makes sure that \fIsa\fR has enough space allocated to hold an additional \fIlen\fR bytes: If \fIsa\fR is not allocated, @@ -17,5 +17,7 @@ new space, frees the old space, and returns 1. Note that this changes If stralloc_readyplus runs out of memory, it leaves \fIsa\fR alone and returns 0. +.SH "RETURN VALUE" +1 for success, 0 on memory allocation failure. .SH "SEE ALSO" stralloc_ready(3) diff --git a/stralloc/stralloc_readyplus.c b/stralloc/stralloc_readyplus.c index 3140164..f8603f0 100644 --- a/stralloc/stralloc_readyplus.c +++ b/stralloc/stralloc_readyplus.c @@ -4,9 +4,10 @@ /* stralloc_readyplus is like stralloc_ready except that, if sa is * already allocated, stralloc_readyplus adds the current length of sa * to len. */ -int stralloc_readyplus(stralloc *sa,unsigned int len) { - if (sa->s) +int stralloc_readyplus(stralloc *sa,unsigned long len) { + if (sa->s) { + if (sa->len + len < len) return 0; /* catch integer overflow */ return stralloc_ready(sa,sa->len+len); - else + } else return stralloc_ready(sa,len); } diff --git a/stralloc/stralloc_starts.3 b/stralloc/stralloc_starts.3 index f673ad8..c2a56e6 100644 --- a/stralloc/stralloc_starts.3 +++ b/stralloc/stralloc_starts.3 @@ -4,10 +4,12 @@ stralloc_starts \- check if string is prefix of stralloc .SH SYNTAX .B #include -int \fBstralloc_starts\fP(stralloc* \fIsa\fR,const char* \fIin\fR); +int \fBstralloc_starts\fP(stralloc* \fIsa\fR,const unsigned char* \fIin\fR); .SH DESCRIPTION stralloc_starts returns 1 if the \\0-terminated string in \fIin\fR, without the terminating \\0, is a prefix of the string stored in \fIsa\fR. Otherwise it returns 0. \fIsa\fR must already be allocated. +.SH "RETURN VALUE" +1 if \fIin\fR is a prefix of \fIsa\fR, otherwise 0. .SH "SEE ALSO" str_starts(3) diff --git a/stralloc/stralloc_starts.c b/stralloc/stralloc_starts.c index ff011a1..5896ac9 100644 --- a/stralloc/stralloc_starts.c +++ b/stralloc/stralloc_starts.c @@ -2,8 +2,8 @@ #include "byte.h" #include "str.h" -extern int stralloc_starts(stralloc *sa,const char *in) { - register int len=str_len(in); +extern int stralloc_starts(stralloc *sa,const unsigned char *in) { + register unsigned long int len=str_len(in); return (len<=sa->len && !byte_diff(sa->s,len,in)); } diff --git a/stralloc/stralloc_zero.3 b/stralloc/stralloc_zero.3 index e7e8dd1..91c218d 100644 --- a/stralloc/stralloc_zero.3 +++ b/stralloc/stralloc_zero.3 @@ -4,10 +4,10 @@ stralloc_zero \- set length of stralloc to 0 .SH SYNTAX .B #include -int \fBstralloc_zero\fP(stralloc* \fIsa\fR); +void \fBstralloc_zero\fP(stralloc* \fIsa\fR); .SH DESCRIPTION stralloc_zero sets the length of the stralloc to 0. - -It is a shortcut for stralloc_copys(\fIsa\fR,""). +.SH "RETURN VALUE" +none. .SH "SEE ALSO" stralloc_copys(3) diff --git a/stralloc/stralloc_zero.c b/stralloc/stralloc_zero.c new file mode 100644 index 0000000..a62352c --- /dev/null +++ b/stralloc/stralloc_zero.c @@ -0,0 +1,5 @@ +#include + +void stralloc_zero(stralloc* sa) { + sa->len=0; +}