gcc 4 cleanups (mostly unsigned char* vs char*)
This commit is contained in:
parent
dd5f8d13c3
commit
c874604f12
1
CHANGES
1
CHANGES
@ -2,6 +2,7 @@
|
||||
also recognize EPFNOSUPPORT as EAFNOSUPPORT (groan)
|
||||
fix a few man pages
|
||||
optimize fmt_base64 (Dan Gundlach)
|
||||
gcc 4 cleanups (mostly unsigned char* vs char*)
|
||||
|
||||
0.22:
|
||||
uh, the scope_id detection #defined the wrong constant. libowfat
|
||||
|
@ -15,9 +15,11 @@ buffer.a mmap.a taia.a tai.a dns.a case.a mult.a array.a io.a textcode.a
|
||||
all: t $(LIBS) libowfat.a libsocket
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-pipe -Wall -O2 -fomit-frame-pointer
|
||||
CFLAGS=-pipe -W -Wall -O2 -fomit-frame-pointer
|
||||
#CFLAGS=-pipe -Os -march=pentiumpro -mcpu=pentiumpro -fomit-frame-pointer -fschedule-insns2 -Wall
|
||||
|
||||
CFLAGS += -fstrict-aliasing -Wstrict-aliasing=2
|
||||
|
||||
# startrip
|
||||
ifneq ($(DEBUG),)
|
||||
CFLAGS=-pipe -Wall -g
|
||||
|
2
Makefile
2
Makefile
@ -16,7 +16,7 @@ buffer.a mmap.a taia.a tai.a dns.a case.a mult.a array.a io.a textcode.a
|
||||
all: t $(LIBS) libowfat.a libsocket
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-pipe -Wall -O2 -fomit-frame-pointer
|
||||
CFLAGS=-pipe -W -Wall -O2 -fomit-frame-pointer
|
||||
#CFLAGS=-pipe -Os -march=pentiumpro -mcpu=pentiumpro -fomit-frame-pointer -fschedule-insns2 -Wall
|
||||
|
||||
array_allocate.o: array/array_allocate.c safemult.h uint16.h \
|
||||
|
36
buffer.h
36
buffer.h
@ -2,7 +2,7 @@
|
||||
#define BUFFER_H
|
||||
|
||||
typedef struct buffer {
|
||||
unsigned char *x; /* actual buffer space */
|
||||
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 */
|
||||
@ -17,18 +17,18 @@ typedef struct buffer {
|
||||
#define BUFFER_INSIZE 8192
|
||||
#define BUFFER_OUTSIZE 8192
|
||||
|
||||
void buffer_init(buffer* b,int (*op)(),int fd,unsigned char* y,unsigned long int ylen);
|
||||
void buffer_init_free(buffer* b,int (*op)(),int fd,unsigned char* y,unsigned long int ylen);
|
||||
void buffer_init(buffer* b,int (*op)(),int fd,char* y,unsigned long int ylen);
|
||||
void buffer_init_free(buffer* b,int (*op)(),int fd,char* y,unsigned long int ylen);
|
||||
int buffer_mmapread(buffer* b,const char* filename);
|
||||
void buffer_close(buffer* b);
|
||||
|
||||
int buffer_flush(buffer* b);
|
||||
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_put(buffer* b,const char* x,unsigned long int len);
|
||||
int buffer_putalign(buffer* b,const char* x,unsigned long int len);
|
||||
int buffer_putflush(buffer* b,const char* x,unsigned long 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_putm_internal(buffer*b,...);
|
||||
int buffer_putm_internal_flush(buffer*b,...);
|
||||
@ -44,24 +44,24 @@ int buffer_putnlflush(buffer* b); /* put \n and flush */
|
||||
: buffer_put((s),&(c),1) \
|
||||
)
|
||||
|
||||
int buffer_get(buffer* b,unsigned char* x,unsigned long int len);
|
||||
int buffer_get(buffer* b,char* x,unsigned long int len);
|
||||
int buffer_feed(buffer* b);
|
||||
int buffer_getc(buffer* b,unsigned char* x);
|
||||
int buffer_getn(buffer* b,unsigned char* x,unsigned long int len);
|
||||
int buffer_getc(buffer* b,char* x);
|
||||
int buffer_getn(buffer* b,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,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);
|
||||
int buffer_get_token(buffer* b,char* x,unsigned long int len,const char* charset,unsigned long int setlen);
|
||||
int buffer_getline(buffer* b,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 unsigned char* x,unsigned long int len);
|
||||
typedef int (*string_predicate)(const 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,unsigned char* x,unsigned long int len,string_predicate p);
|
||||
int buffer_get_token_pred(buffer* b,char* x,unsigned long int len,string_predicate p);
|
||||
|
||||
char *buffer_peek(buffer* b);
|
||||
void buffer_seek(buffer* b,unsigned long int len);
|
||||
@ -112,12 +112,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 unsigned char* charset,unsigned long 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 unsigned char* charset,unsigned long 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);
|
||||
|
||||
|
@ -2,6 +2,9 @@
|
||||
#include "buffer.h"
|
||||
|
||||
static int dummyreadwrite(int fd,char* buf,unsigned long int len) {
|
||||
(void)fd;
|
||||
(void)buf;
|
||||
(void)len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ buffer_get \- read binary data from buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
int \fBbuffer_get\fP(buffer* \fIb\fR,unsigned char* \fIx\fR,unsigned long int \fIlen\fR);
|
||||
int \fBbuffer_get\fP(buffer* \fIb\fR,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,unsigned char* x,unsigned long int len) {
|
||||
int buffer_get(buffer* b,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 unsigned char* charset,unsigned long int setlen) {
|
||||
int buffer_get_new_token_sa(buffer* b,stralloc* sa,const 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,unsigned char* \fIx\fR,unsigned long int \fIlen\fR,
|
||||
const unsigned char* \fIcharset\fR,unsigned long int \fIsetlen\fR);
|
||||
int \fBbuffer_get_token\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned long int \fIlen\fR,
|
||||
const 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,unsigned char* x,unsigned long int len,const unsigned char* charset,unsigned long int setlen) {
|
||||
int buffer_get_token(buffer* b,char* x,unsigned long int len,const 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,unsigned char* \fIx\fR,unsigned long int \fIlen\fR,
|
||||
int (*\fIpredicate\fR)(const unsigned char* \fIs\fR,unsigned long int \fIlen\fR));
|
||||
int \fBbuffer_get_token_pred\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned long int \fIlen\fR,
|
||||
int (*\fIpredicate\fR)(const 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,7 @@
|
||||
#include "buffer.h"
|
||||
#include "scan.h"
|
||||
|
||||
int buffer_get_token_pred(buffer* b,unsigned char* x,unsigned long int len,
|
||||
int buffer_get_token_pred(buffer* b,char* x,unsigned long int len,
|
||||
string_predicate p) {
|
||||
int 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 unsigned char* \fIcharset\fR,unsigned long int \fIsetlen\fR);
|
||||
const 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
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
int buffer_get_token_sa(buffer* b,stralloc* sa,
|
||||
const unsigned char* charset,
|
||||
const char* charset,
|
||||
unsigned long int setlen) {
|
||||
for (;;) {
|
||||
char x;
|
||||
|
@ -4,7 +4,7 @@ buffer_getc \- read one char from buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
int \fBbuffer_getc\fP(buffer* \fIb\fR,unsigned char* \fIx\fR);
|
||||
int \fBbuffer_getc\fP(buffer* \fIb\fR,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,unsigned char* x) {
|
||||
int buffer_getc(buffer* b,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,unsigned char* \fIx\fR,unsigned long int \fIlen\fR);
|
||||
int \fBbuffer_getline\fP(buffer* \fIb\fR,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
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <buffer.h>
|
||||
|
||||
int buffer_getline(buffer* b,unsigned char* x,unsigned long int len) {
|
||||
int buffer_getline(buffer* b,char* x,unsigned long int len) {
|
||||
return buffer_get_token(b,x,len,"\n",1);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ buffer_getn \- read binary data from buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
int \fBbuffer_getn\fP(buffer* \fIb\fR,unsigned char* \fIx\fR,unsigned long int \fIlen\fR);
|
||||
int \fBbuffer_getn\fP(buffer* \fIb\fR,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,unsigned char* x,unsigned long int len) {
|
||||
int buffer_getn(buffer* b,char* x,unsigned long int len) {
|
||||
int blen;
|
||||
|
||||
for(blen=0;blen<len;++blen) {
|
||||
|
@ -6,7 +6,7 @@ buffer_init \- initialize buffer structure
|
||||
|
||||
void \fBbuffer_init\fR(buffer &\fIb\fR,
|
||||
int (*\fIop\fR)(int,char*,unsigned int),
|
||||
int \fIfd\fR, unsigned char* \fIy\fR, unsigned long int \fIylen\fR);
|
||||
int \fIfd\fR, 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,7 +1,7 @@
|
||||
#include "buffer.h"
|
||||
|
||||
void buffer_init(buffer* b,int (*op)(),int fd,
|
||||
unsigned char* y,unsigned long int ylen) {
|
||||
char* y,unsigned long int ylen) {
|
||||
b->op=op;
|
||||
b->fd=fd;
|
||||
b->x=y;
|
||||
|
@ -6,7 +6,7 @@ buffer_init_free \- initialize buffer structure
|
||||
|
||||
void \fBbuffer_init_free\fR(buffer &\fIb\fR,
|
||||
int (*\fIop\fR)(int,char*,unsigned int),
|
||||
int \fIfd\fR, unsigned char* \fIy\fR, unsigned long int \fIylen\fR);
|
||||
int \fIfd\fR, char* \fIy\fR, unsigned long int \fIylen\fR);
|
||||
.SH DESCRIPTION
|
||||
buffer_init_free is like buffer_init except that the memory (\fIy\fR is
|
||||
marked to be freed by buffer_close().
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "buffer.h"
|
||||
|
||||
void buffer_init_free(buffer* b,int (*op)(),int fd,
|
||||
unsigned char* y,unsigned long int ylen) {
|
||||
char* y,unsigned long int ylen) {
|
||||
buffer_init(b,op,fd,y,ylen);
|
||||
b->todo=FREE;
|
||||
}
|
||||
|
@ -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 unsigned char* \fIx\fR,unsigned long int \fIlen\fR);
|
||||
int \fBbuffer_put\fP(buffer* \fIb\fR,const 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 unsigned char* buf, unsigned long int len);
|
||||
extern int buffer_stubborn(int (*op)(),int fd,const char* buf, unsigned long int len);
|
||||
|
||||
int buffer_put(buffer* b,const unsigned char* buf,unsigned long int len) {
|
||||
int buffer_put(buffer* b,const 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) {
|
||||
unsigned char buf[FMT_8LONG];
|
||||
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 unsigned char* \fIx\fR,unsigned long int \fIlen\fR);
|
||||
int \fBbuffer_putalign\fP(buffer* \fIb\fR,const 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 unsigned char* buf,unsigned long int len) {
|
||||
int buffer_putalign(buffer* b,const 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 unsigned char* \fIx\fR,unsigned long int \fIlen\fR);
|
||||
const 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 unsigned char* x,unsigned long int len) {
|
||||
int buffer_putflush(buffer* b,const 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) {
|
||||
unsigned char buf[FMT_LONG];
|
||||
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) {
|
||||
unsigned char buf[FMT_LONG];
|
||||
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 unsigned char*)))
|
||||
while ((s=va_arg(a,const 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 unsigned char*)))
|
||||
while ((s=va_arg(a,const 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 unsigned char* \fIx\fR);
|
||||
int \fBbuffer_puts\fP(buffer* \fIb\fR,const 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 unsigned char* x) {
|
||||
int buffer_puts(buffer* b,const 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 unsigned char* \fIx\fR);
|
||||
int \fBbuffer_putsalign\fP(buffer* \fIb\fR,const 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 unsigned char* x) {
|
||||
int buffer_putsalign(buffer* b,const 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 unsigned char* \fIx\fR);
|
||||
int \fBbuffer_putsflush\fP(buffer* \fIb\fR,const 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 unsigned char* x) {
|
||||
int buffer_putsflush(buffer* b,const 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) {
|
||||
unsigned char buf[FMT_XLONG];
|
||||
char buf[FMT_XLONG];
|
||||
return buffer_put(b,buf,fmt_xlong(buf,l));
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <errno.h>
|
||||
#include "buffer.h"
|
||||
|
||||
int buffer_stubborn(int (*op)(),int fd,const unsigned char* buf, unsigned long int len) {
|
||||
int buffer_stubborn(int (*op)(),int fd,const 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 unsigned char* buf, unsigned long int len) {
|
||||
int buffer_stubborn_read(int (*op)(),int fd,const char* buf, unsigned long int len) {
|
||||
int w;
|
||||
for (;;) {
|
||||
if ((w=op(fd,buf,len))<0)
|
||||
|
@ -22,7 +22,7 @@ union fdmsg {
|
||||
};
|
||||
|
||||
int io_passfd(int64 sock,int64 fd) {
|
||||
struct msghdr msg = {0};
|
||||
struct msghdr msg;
|
||||
struct iovec iov;
|
||||
#ifdef CMSG_LEN
|
||||
struct cmsghdr *cmsg;
|
||||
|
@ -13,7 +13,8 @@
|
||||
int64 iob_send(int64 s,io_batch* b) {
|
||||
iob_entry* e,* last;
|
||||
struct iovec* v;
|
||||
int64 total,sent;
|
||||
uint64 total;
|
||||
int64 sent;
|
||||
long i;
|
||||
long headers;
|
||||
#ifdef HAVE_BSDSENDFILE
|
||||
@ -101,8 +102,8 @@ eagain:
|
||||
if (sent>0)
|
||||
total+=sent;
|
||||
else
|
||||
return total?total:sent;
|
||||
if (sent==b->bytesleft) {
|
||||
return total?total:(uint64)sent;
|
||||
if ((uint64)sent==b->bytesleft) {
|
||||
#ifdef TCP_CORK
|
||||
if (b->bufs && b->files) {
|
||||
static int zero=0;
|
||||
@ -112,7 +113,7 @@ eagain:
|
||||
iob_reset(b);
|
||||
break;
|
||||
} else if (sent>0) {
|
||||
int64 rest=sent;
|
||||
uint64 rest=sent;
|
||||
|
||||
b->bytesleft-=rest;
|
||||
for (i=0; e+i<last; ++i) {
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
int64 iob_write(int64 s,io_batch* b,io_write_callback cb) {
|
||||
iob_entry* e,* last;
|
||||
int64 total,sent;
|
||||
uint64 total;
|
||||
int64 sent;
|
||||
long i;
|
||||
int thatsit;
|
||||
|
||||
@ -18,10 +19,10 @@ int64 iob_write(int64 s,io_batch* b,io_write_callback cb) {
|
||||
sent=io_mmapwritefile(s,e[i].fd,e[i].offset,e[i].n,cb);
|
||||
else
|
||||
sent=cb(s,e[i].buf+e[i].offset,e[i].n);
|
||||
if (sent>0 && sent>e[i].n) sent=e[i].n; /* can't happen */
|
||||
thatsit=(sent != e[i].n);
|
||||
if (sent>0 && (uint64)sent>e[i].n) sent=e[i].n; /* can't happen */
|
||||
thatsit=((uint64)sent != e[i].n);
|
||||
if (sent<=0)
|
||||
return total?total:sent;
|
||||
return total?total:(uint64)sent;
|
||||
e[i].offset+=sent;
|
||||
e[i].n-=sent;
|
||||
total+=sent;
|
||||
|
6
ip6.h
6
ip6.h
@ -25,9 +25,9 @@ unsigned int fmt_ip6_flat(char *dest,const char *);
|
||||
|
||||
#define IP6_FMT 40
|
||||
|
||||
extern const unsigned char V4mappedprefix[12]; /*={0,0,0,0,0,0,0,0,0,0,0xff,0xff}; */
|
||||
extern const unsigned char V6loopback[16]; /*={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; */
|
||||
extern const unsigned char V6any[16]; /*={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; */
|
||||
extern const char V4mappedprefix[12]; /*={0,0,0,0,0,0,0,0,0,0,0xff,0xff}; */
|
||||
extern const char V6loopback[16]; /*={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; */
|
||||
extern const char V6any[16]; /*={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; */
|
||||
|
||||
#define ip6_isv4mapped(ip) (byte_equal(ip,12,V4mappedprefix))
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
* When the strings are different, str_diff does not read bytes past the
|
||||
* first difference. */
|
||||
int str_diff(const char* a, const char* b) {
|
||||
register const char* s=a;
|
||||
register const char* t=b;
|
||||
register const unsigned char* s=(const unsigned char*)a;
|
||||
register const unsigned char* t=(const unsigned char*)b;
|
||||
register int j;
|
||||
j=0;
|
||||
for (;;) {
|
||||
|
@ -6,8 +6,8 @@
|
||||
* When the strings are different, str_diff does not read bytes past the
|
||||
* first difference. */
|
||||
int str_diffn(const char* a, const char* b, unsigned long limit) {
|
||||
register const char* s=a;
|
||||
register const char* t=b;
|
||||
register const unsigned char* s=(const unsigned char*)a;
|
||||
register const unsigned char* t=(const unsigned char*)b;
|
||||
register const char* u=t+limit;
|
||||
register int j;
|
||||
j=0;
|
||||
|
@ -1,3 +1,4 @@
|
||||
#undef __dietlibc__
|
||||
#include "str.h"
|
||||
|
||||
unsigned long str_len(const char* in) {
|
||||
|
14
stralloc.h
14
stralloc.h
@ -42,12 +42,12 @@ 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 unsigned char* buf,unsigned long int len);
|
||||
int stralloc_copyb(stralloc* sa,const 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 unsigned char* buf);
|
||||
int stralloc_copys(stralloc* sa,const 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,10 +58,10 @@ 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 unsigned char* in,unsigned long int len);
|
||||
int stralloc_catb(stralloc* sa,const char* in,unsigned long int len);
|
||||
|
||||
/* stralloc_cats is analogous to stralloc_copys */
|
||||
int stralloc_cats(stralloc* sa,const unsigned char* in);
|
||||
int stralloc_cats(stralloc* sa,const char* in);
|
||||
|
||||
void stralloc_zero(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 unsigned char* in); /* beware: this takes a pointer to 1 char */
|
||||
int stralloc_append(stralloc* sa,const 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 unsigned char* in) __pure__;
|
||||
int stralloc_starts(stralloc* sa,const 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 unsigned char* b) __pure__;
|
||||
int stralloc_diffs(const stralloc* a,const char* b) __pure__;
|
||||
|
||||
#define stralloc_equal(a,b) (!stralloc_diff((a),(b)))
|
||||
#define stralloc_equals(a,b) (!stralloc_diffs((a),(b)))
|
||||
|
@ -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 unsigned char* \fIin\fR);
|
||||
int \fBstralloc_append\fP(stralloc* \fIsa\fR,const 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
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
/* 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) {
|
||||
int stralloc_append(stralloc *sa,const char *in) {
|
||||
if (stralloc_readyplus(sa,1)) {
|
||||
sa->s[sa->len]=*in;
|
||||
++sa->len;
|
||||
|
@ -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 unsigned char* \fIbuf\fR,unsigned long int \fIlen\fR);
|
||||
int \fBstralloc_catb\fP(stralloc* \fIsa\fR,const 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
|
||||
|
@ -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 unsigned char *buf,unsigned long int len) {
|
||||
int stralloc_catb(stralloc *sa,const char *buf,unsigned long int len) {
|
||||
if (stralloc_readyplus(sa,len)) {
|
||||
byte_copy(sa->s+sa->len,len,buf);
|
||||
sa->len+=len;
|
||||
|
@ -4,7 +4,7 @@ stralloc_catm \- append string(s) to a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
int \fBstralloc_catm\fP(stralloc* \fIsa\fR,const unsigned char* \fIs\fR, ...);
|
||||
int \fBstralloc_catm\fP(stralloc* \fIsa\fR,const char* \fIs\fR, ...);
|
||||
.SH DESCRIPTION
|
||||
stralloc_catm appends \\0-terminated strings from \fIs\fR... to the
|
||||
end of the string stored in \fIsa\fR, allocating space if necessary, and
|
||||
|
@ -4,7 +4,7 @@ stralloc_cats \- append data to a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
int \fBstralloc_cats\fP(stralloc* \fIsa\fR,const unsigned char* \fIbuf\fR);
|
||||
int \fBstralloc_cats\fP(stralloc* \fIsa\fR,const 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
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "stralloc.h"
|
||||
#include "str.h"
|
||||
|
||||
extern int stralloc_cats(stralloc *sa,const unsigned char *buf) {
|
||||
extern int stralloc_cats(stralloc *sa,const char *buf) {
|
||||
return stralloc_catb(sa,buf,str_len(buf));
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ stralloc_copyb \- copy data into a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
int \fBstralloc_copyb\fP(stralloc* \fIsa\fR,const unsigned char* \fIbuf\fR,unsigned long int \fIlen\fR);
|
||||
int \fBstralloc_copyb\fP(stralloc* \fIsa\fR,const 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
|
||||
|
@ -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 unsigned char *buf,unsigned long int len) {
|
||||
int stralloc_copyb(stralloc *sa,const char *buf,unsigned long int len) {
|
||||
if (stralloc_ready(sa,len)) {
|
||||
sa->len=len;
|
||||
byte_copy(sa->s,len,buf);
|
||||
|
@ -4,7 +4,7 @@ stralloc_copys \- copy data into a stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
int \fBstralloc_copys\fP(stralloc* \fIsa\fR,const unsigned char* \fIbuf\fR);
|
||||
int \fBstralloc_copys\fP(stralloc* \fIsa\fR,const 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
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "stralloc.h"
|
||||
#include "str.h"
|
||||
|
||||
extern int stralloc_copys(stralloc *sa,const unsigned char *buf) {
|
||||
extern int stralloc_copys(stralloc *sa,const char *buf) {
|
||||
return stralloc_copyb(sa,buf,str_len(buf));
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ extern int stralloc_diff(const stralloc* a,const stralloc* b) {
|
||||
register int j;
|
||||
for (i=0;;++i) {
|
||||
if (i==a->len) return i==b->len?0:-1; if (i==b->len) return 1;
|
||||
if ((j=(a->s[i]-b->s[i]))) return j;
|
||||
if ((j=((unsigned char)(a->s[i])-(unsigned char)(b->s[i])))) return j;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ stralloc_diffs \- check if string is prefix of stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
int \fBstralloc_diffs\fP(stralloc* \fIa\fR,const unsigned char* \fIb\fR);
|
||||
int \fBstralloc_diffs\fP(stralloc* \fIa\fR,const char* \fIb\fR);
|
||||
.SH DESCRIPTION
|
||||
stralloc_diffs returns negative, 0, or positive, depending on whether
|
||||
the \\0-terminated string in \fIa\fR, without
|
||||
|
@ -2,12 +2,12 @@
|
||||
#include "byte.h"
|
||||
#include "str.h"
|
||||
|
||||
extern int stralloc_diffs(const stralloc* a,const unsigned char* b) {
|
||||
extern int stralloc_diffs(const stralloc* a,const 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;
|
||||
if ((j=(a->s[i]-b[i]))) return j;
|
||||
if ((j=((unsigned char)(a->s[i])-(unsigned char)(b[i])))) return j;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ stralloc_starts \- check if string is prefix of stralloc
|
||||
.SH SYNTAX
|
||||
.B #include <stralloc.h>
|
||||
|
||||
int \fBstralloc_starts\fP(stralloc* \fIsa\fR,const unsigned char* \fIin\fR);
|
||||
int \fBstralloc_starts\fP(stralloc* \fIsa\fR,const 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
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "byte.h"
|
||||
#include "str.h"
|
||||
|
||||
extern int stralloc_starts(stralloc *sa,const unsigned char *in) {
|
||||
extern int stralloc_starts(stralloc *sa,const char *in) {
|
||||
register unsigned long int len=str_len(in);
|
||||
return (len<=sa->len && !byte_diff(sa->s,len,in));
|
||||
}
|
||||
|
9
t.c
9
t.c
@ -26,6 +26,9 @@
|
||||
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
|
||||
|
||||
int64 writecb(int64 fd,const void* buf,uint64 n) {
|
||||
(void)fd;
|
||||
(void)buf;
|
||||
(void)n;
|
||||
#if 0
|
||||
int r;
|
||||
int todo=n>=65536?65536:n;
|
||||
@ -37,6 +40,8 @@ int64 writecb(int64 fd,const void* buf,uint64 n) {
|
||||
}
|
||||
|
||||
int main(int argc,char* argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
#if 0
|
||||
io_batch* b=iob_new(1234);
|
||||
int64 fd=open("t.c",0);
|
||||
@ -312,7 +317,7 @@ int main(int argc,char* argv[]) {
|
||||
rdtscl(c);
|
||||
printf("%lu %lu\n",b-a,c-b);
|
||||
#endif
|
||||
#if 1
|
||||
#if 0
|
||||
unsigned long size;
|
||||
char* buf=mmap_read(argv[1],&size);
|
||||
if (buf) {
|
||||
@ -323,6 +328,8 @@ int main(int argc,char* argv[]) {
|
||||
write(1,tmp,x);
|
||||
}
|
||||
#endif
|
||||
printf("%d %d\n",strcmp("foo","bar"),str_diff("foo","bar"));
|
||||
printf("%d %d\n",strcmp("foo","üar"),str_diff("foo","üar"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user