cleanups in stralloc and buffer:
int -> long for sizes char -> unsigned char for strings
This commit is contained in:
parent
38ef27207a
commit
5eb1cdf888
3
CHANGES
3
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
|
||||
|
58
buffer.h
58
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);
|
||||
|
||||
|
@ -4,7 +4,7 @@ buffer_get \- read binary data from buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ buffer_get_token \- read token from buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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
|
||||
|
@ -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<len;++blen) {
|
||||
|
@ -4,8 +4,8 @@ buffer_get_token_pred \- read token from buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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
|
||||
|
@ -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<len;++blen) {
|
||||
|
@ -7,7 +7,7 @@ buffer_get_token_sa \- read token from buffer
|
||||
.B #include <buffer.h>
|
||||
|
||||
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
|
||||
|
@ -3,7 +3,9 @@
|
||||
#include "buffer.h"
|
||||
#include <errno.h>
|
||||
|
||||
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;
|
||||
|
@ -4,7 +4,7 @@ buffer_getc \- read one char from buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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"
|
||||
|
@ -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;
|
||||
|
@ -4,7 +4,7 @@ buffer_getline \- read line from buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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
|
||||
|
@ -4,7 +4,7 @@ buffer_getn \- read binary data from buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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
|
||||
|
@ -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;blen<len;++blen) {
|
||||
|
@ -6,7 +6,7 @@ buffer_init \- initialize buffer structure
|
||||
|
||||
int \fBbuffer_init\fR(buffer &\fIb\fR,
|
||||
int (*\fIop\fR)(int,char*,unsigned int),
|
||||
int \fIfd\fR, char* \fIy\fR, unsigned int \fIylen\fR);
|
||||
int \fIfd\fR, unsigned char* \fIy\fR, unsigned long int \fIylen\fR);
|
||||
.SH DESCRIPTION
|
||||
buffer_init prepares \fIb\fR to store a string in \fIy\fR[0], \fIy\fR[1], ...,
|
||||
\fIy\fR[\fIylen\fR-1]. Initially the string is empty.
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "buffer.h"
|
||||
|
||||
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) {
|
||||
b->op=op;
|
||||
b->fd=fd;
|
||||
b->x=y;
|
||||
|
@ -4,7 +4,7 @@ buffer_put \- write binary data to buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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.
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ buffer_putalign \- write binary data to buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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.
|
||||
|
||||
|
@ -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);
|
||||
|
@ -5,7 +5,7 @@ buffer_putflush \- write binary data to buffer and flush
|
||||
.B #include <buffer.h>
|
||||
|
||||
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).
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -4,7 +4,7 @@ buffer_puts \- write ASCIIZ string to buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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.
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ buffer_putsalign \- write ASCIIZ string to buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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.
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ buffer_putsflush \- write ASCIIZ string to buffer and flush
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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.
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ buffer_seek \- remove bytes from beginning of string in buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
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.
|
||||
|
@ -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 (n<b->p) n=b->p;
|
||||
if (n>b->n) n=b->n;
|
||||
b->p=n;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <errno.h>
|
||||
#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) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <errno.h>
|
||||
#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)
|
||||
|
32
stralloc.h
32
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);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -4,7 +4,7 @@ stralloc_append \- append a character to a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -4,7 +4,7 @@ stralloc_catb \- append data to a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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.
|
||||
|
@ -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;
|
||||
|
@ -4,12 +4,14 @@ stralloc_catlong0 \- append an integer to a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -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);
|
||||
|
@ -4,14 +4,16 @@ stralloc_catm \- append string(s) to a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -4,12 +4,14 @@ stralloc_cats \- append data to a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,14 @@ stralloc_catulong0 \- append an integer to a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -4,13 +4,15 @@ stralloc_copyb \- copy data into a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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.
|
||||
|
@ -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);
|
||||
|
@ -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 <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -4,15 +4,17 @@ stralloc_copys \- copy data into a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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 a<b, 0 if a==b, >0 if a>b.
|
||||
.SH "SEE ALSO"
|
||||
stralloc_diffs(3), stralloc_starts(3)
|
||||
|
@ -4,11 +4,13 @@ stralloc_diffs \- check if string is prefix of stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -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;
|
||||
|
@ -4,9 +4,11 @@ stralloc_free \- free storage associated with a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -4,12 +4,14 @@ stralloc_init \- initialize a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -4,7 +4,7 @@ stralloc_ready \- provide space in a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -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<len) {
|
||||
register char* tmp;
|
||||
|
@ -4,7 +4,7 @@ stralloc_readyplus \- provide space in a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -4,10 +4,12 @@ stralloc_starts \- check if string is prefix of stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,10 @@ stralloc_zero \- set length of stralloc to 0
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
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)
|
||||
|
5
stralloc/stralloc_zero.c
Normal file
5
stralloc/stralloc_zero.c
Normal file
@ -0,0 +1,5 @@
|
||||
#include <stralloc.h>
|
||||
|
||||
void stralloc_zero(stralloc* sa) {
|
||||
sa->len=0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user