switch to size_t and ssize_t
This commit is contained in:
parent
0e190f60ab
commit
3004b518ef
1
CHANGES
1
CHANGES
@ -20,6 +20,7 @@
|
||||
remove support for ip6.int (it's no longer delegated)
|
||||
add asm versions of imult64 and umult64 for x86_64
|
||||
(22 cycles -> 12 cycles on my Athlon 64)
|
||||
use size_t and ssize_t instead of unsigned long et al
|
||||
|
||||
0.24:
|
||||
fix scan_to_sa (Tim Lorenz)
|
||||
|
41
buffer.h
41
buffer.h
@ -1,13 +1,18 @@
|
||||
#ifndef BUFFER_H
|
||||
#define BUFFER_H
|
||||
|
||||
/* for size_t: */
|
||||
#include <stddef.h>
|
||||
/* for ssize_t: */
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct buffer {
|
||||
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 */
|
||||
size_t p; /* current position */
|
||||
size_t n; /* current size of string in buffer */
|
||||
size_t a; /* allocated buffer size */
|
||||
int fd; /* passed as first argument to op */
|
||||
int (*op)(); /* use read(2) or write(2) */
|
||||
ssize_t (*op)(); /* use read(2) or write(2) */
|
||||
enum { NOTHING, FREE, MUNMAP } todo;
|
||||
} buffer;
|
||||
|
||||
@ -17,15 +22,15 @@ typedef struct buffer {
|
||||
#define BUFFER_INSIZE 8192
|
||||
#define BUFFER_OUTSIZE 8192
|
||||
|
||||
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);
|
||||
void buffer_init(buffer* b,ssize_t (*op)(),int fd,char* y,size_t ylen);
|
||||
void buffer_init_free(buffer* b,ssize_t (*op)(),int fd,char* y,size_t 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 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_put(buffer* b,const char* x,size_t len);
|
||||
int buffer_putalign(buffer* b,const char* x,size_t len);
|
||||
int buffer_putflush(buffer* b,const char* x,size_t 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);
|
||||
@ -44,27 +49,27 @@ int buffer_putnlflush(buffer* b); /* put \n and flush */
|
||||
: buffer_put((s),&(c),1) \
|
||||
)
|
||||
|
||||
int buffer_get(buffer* b,char* x,unsigned long int len);
|
||||
ssize_t buffer_get(buffer* b,char* x,size_t len);
|
||||
int buffer_feed(buffer* b);
|
||||
int buffer_getc(buffer* b,char* x);
|
||||
int buffer_getn(buffer* b,char* x,unsigned long int len);
|
||||
ssize_t buffer_getn(buffer* b,char* x,size_t 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 long int len,const char* charset,unsigned long int setlen);
|
||||
int buffer_getline(buffer* b,char* x,unsigned long int len);
|
||||
ssize_t buffer_get_token(buffer* b,char* x,size_t len,const char* charset,size_t setlen);
|
||||
ssize_t buffer_getline(buffer* b,char* x,size_t 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 long int len);
|
||||
typedef int (*string_predicate)(const char* x,size_t len);
|
||||
|
||||
/* like buffer_get_token but the token ends when your predicate says so */
|
||||
int buffer_get_token_pred(buffer* b,char* x,unsigned long int len,string_predicate p);
|
||||
ssize_t buffer_get_token_pred(buffer* b,char* x,size_t len,string_predicate p);
|
||||
|
||||
char *buffer_peek(buffer* b);
|
||||
void buffer_seek(buffer* b,unsigned long int len);
|
||||
void buffer_seek(buffer* b,size_t len);
|
||||
|
||||
#define buffer_PEEK(s) ( (s)->x + (s)->p )
|
||||
#define buffer_SEEK(s,len) ( (s)->p += (len) )
|
||||
@ -112,12 +117,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 long int setlen);
|
||||
int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,size_t 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 long int setlen);
|
||||
int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,size_t setlen);
|
||||
/* same as buffer_getline_sa but empty sa first */
|
||||
int buffer_getnewline_sa(buffer* b,stralloc* sa);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <unistd.h>
|
||||
#include "buffer.h"
|
||||
|
||||
static int b0read(int fd,char* buf, unsigned int len) {
|
||||
static ssize_t b0read(int fd,char* buf, size_t len) {
|
||||
if (buffer_flush(buffer_1)<0) return -1;
|
||||
return read(fd,buf,len);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <unistd.h>
|
||||
#include "buffer.h"
|
||||
|
||||
static int b0read(int fd,char* buf, unsigned int len) {
|
||||
static ssize_t b0read(int fd,char* buf, size_t len) {
|
||||
if (buffer_flush(buffer_1small)<0) return -1;
|
||||
return read(fd,buf,len);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "buffer.h"
|
||||
|
||||
extern int buffer_stubborn_read(int (*op)(),int fd,const char* buf, unsigned int len);
|
||||
extern int buffer_stubborn_read(ssize_t (*op)(),int fd,const char* buf, size_t len);
|
||||
|
||||
int buffer_feed(buffer* b) {
|
||||
if (b->p==b->n) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "buffer.h"
|
||||
|
||||
extern int buffer_stubborn(int (*op)(),int fd,const char* buf, unsigned int len);
|
||||
extern int buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t len);
|
||||
|
||||
extern int buffer_flush(buffer* b) {
|
||||
register int p;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "stralloc.h"
|
||||
#include "buffer.h"
|
||||
|
||||
static int dummyreadwrite(int fd,char* buf,unsigned long int len) {
|
||||
static ssize_t dummyreadwrite(int fd,char* buf,size_t len) {
|
||||
(void)fd;
|
||||
(void)buf;
|
||||
(void)len;
|
||||
|
@ -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 long int \fIlen\fR);
|
||||
ssize_t \fBbuffer_get\fP(buffer* \fIb\fR,char* \fIx\fR,size_t \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 long int len) {
|
||||
ssize_t buffer_get(buffer* b,char* x,size_t len) {
|
||||
unsigned long done;
|
||||
int blen;
|
||||
done=0;
|
||||
|
@ -7,7 +7,7 @@ buffer_get_new_token_sa \- read token from buffer
|
||||
.B #include <buffer.h>
|
||||
|
||||
int \fBbuffer_get_new_token_sa\fP(buffer* \fIb\fR,stralloc* \fIsa\fR,
|
||||
const char* \fIcharset\fR,unsigned int \fIsetlen\fR);
|
||||
const char* \fIcharset\fR,size_t \fIsetlen\fR);
|
||||
.SH DESCRIPTION
|
||||
buffer_get_new_token_sa copies data from the \fIb\fR to \fIsa\fR until
|
||||
one of the delimiters in \fIcharset\fR is found, overwriting the
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "stralloc.h"
|
||||
#include "buffer.h"
|
||||
|
||||
int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned long int setlen) {
|
||||
int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,size_t 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 long int \fIlen\fR,
|
||||
const char* \fIcharset\fR,unsigned long int \fIsetlen\fR);
|
||||
ssize_t \fBbuffer_get_token\fP(buffer* \fIb\fR,char* \fIx\fR,size_t \fIlen\fR,
|
||||
const char* \fIcharset\fR,size_t \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,8 +2,8 @@
|
||||
#include "buffer.h"
|
||||
#include "scan.h"
|
||||
|
||||
int buffer_get_token(buffer* b,char* x,unsigned long int len,const char* charset,unsigned long int setlen) {
|
||||
unsigned long int blen;
|
||||
ssize_t buffer_get_token(buffer* b,char* x,size_t len,const char* charset,size_t setlen) {
|
||||
size_t blen;
|
||||
|
||||
for (blen=0;blen<len;++blen) {
|
||||
register int r;
|
||||
|
@ -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 long int \fIlen\fR,
|
||||
int (*\fIpredicate\fR)(const char* \fIs\fR,unsigned long int \fIlen\fR));
|
||||
ssize_t \fBbuffer_get_token_pred\fP(buffer* \fIb\fR,char* \fIx\fR,size_t \fIlen\fR,
|
||||
int (*\fIpredicate\fR)(const char* \fIs\fR,size_t \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,char* x,unsigned long int len,
|
||||
ssize_t buffer_get_token_pred(buffer* b,char* x,size_t len,
|
||||
string_predicate p) {
|
||||
unsigned 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 char* \fIcharset\fR,unsigned long int \fIsetlen\fR);
|
||||
const char* \fIcharset\fR,size_t \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
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
int buffer_get_token_sa(buffer* b,stralloc* sa,
|
||||
const char* charset,
|
||||
unsigned long int setlen) {
|
||||
size_t setlen) {
|
||||
for (;;) {
|
||||
char x;
|
||||
if (!stralloc_readyplus(sa,1)) goto nomem;
|
||||
|
@ -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 long int \fIlen\fR);
|
||||
ssize_t \fBbuffer_getline\fP(buffer* \fIb\fR,char* \fIx\fR,size_t \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,char* x,unsigned long int len) {
|
||||
ssize_t buffer_getline(buffer* b,char* x,size_t 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,char* \fIx\fR,unsigned long int \fIlen\fR);
|
||||
ssize_t \fBbuffer_getn\fP(buffer* \fIb\fR,char* \fIx\fR,size_t \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,11 +1,11 @@
|
||||
#include "byte.h"
|
||||
#include "buffer.h"
|
||||
|
||||
int buffer_getn(buffer* b,char* x,unsigned long int len) {
|
||||
unsigned int blen;
|
||||
ssize_t buffer_getn(buffer* b,char* x,size_t len) {
|
||||
size_t blen;
|
||||
|
||||
for(blen=0;blen<len;++blen) {
|
||||
register int r;
|
||||
register ssize_t r;
|
||||
if ((r=buffer_getc(b,x))<0) return r;
|
||||
if (r==0) break;
|
||||
++x;
|
||||
|
@ -5,8 +5,8 @@ buffer_init \- initialize buffer structure
|
||||
.B #include <buffer.h>
|
||||
|
||||
void \fBbuffer_init\fR(buffer &\fIb\fR,
|
||||
int (*\fIop\fR)(int,char*,unsigned int),
|
||||
int \fIfd\fR, char* \fIy\fR, unsigned long int \fIylen\fR);
|
||||
ssize_t (*\fIop\fR)(int,char*,size_t),
|
||||
int \fIfd\fR, char* \fIy\fR, size_t \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,
|
||||
char* y,unsigned long int ylen) {
|
||||
void buffer_init(buffer* b,ssize_t (*op)(),int fd,
|
||||
char* y,size_t ylen) {
|
||||
b->op=op;
|
||||
b->fd=fd;
|
||||
b->x=y;
|
||||
|
@ -5,8 +5,8 @@ buffer_init_free \- initialize buffer structure
|
||||
.B #include <buffer.h>
|
||||
|
||||
void \fBbuffer_init_free\fR(buffer &\fIb\fR,
|
||||
int (*\fIop\fR)(int,char*,unsigned int),
|
||||
int \fIfd\fR, char* \fIy\fR, unsigned long int \fIylen\fR);
|
||||
ssize_t (*\fIop\fR)(int,char*,size_t),
|
||||
int \fIfd\fR, char* \fIy\fR, size_t \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,
|
||||
char* y,unsigned long int ylen) {
|
||||
void buffer_init_free(buffer* b,ssize_t (*op)(),int fd,
|
||||
char* y,size_t ylen) {
|
||||
buffer_init(b,op,fd,y,ylen);
|
||||
b->todo=FREE;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <buffer.h>
|
||||
#include <mmap.h>
|
||||
|
||||
static int op() {
|
||||
static ssize_t op() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -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 long int \fIlen\fR);
|
||||
int \fBbuffer_put\fP(buffer* \fIb\fR,const char* \fIx\fR,size_t \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 long int len);
|
||||
extern int buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t len);
|
||||
|
||||
int buffer_put(buffer* b,const char* buf,unsigned long int len) {
|
||||
int buffer_put(buffer* b,const char* buf,size_t len) {
|
||||
if (len>b->a-b->p) { /* doesn't fit */
|
||||
if (buffer_flush(b)==-1) return -1;
|
||||
if (len>b->a) {
|
||||
|
@ -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 long int \fIlen\fR);
|
||||
int \fBbuffer_putalign\fP(buffer* \fIb\fR,const char* \fIx\fR,size_t \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 long int len) {
|
||||
int buffer_putalign(buffer* b,const char* buf,size_t len) {
|
||||
unsigned 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 long int \fIlen\fR);
|
||||
const char* \fIx\fR,size_t \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 long int len) {
|
||||
int buffer_putflush(buffer* b,const char* x,size_t len) {
|
||||
if (buffer_put(b,x,len)<0) return -1;
|
||||
if (buffer_flush(b)<0) return -1;
|
||||
return 0;
|
||||
|
@ -4,7 +4,7 @@ buffer_seek \- remove bytes from beginning of string in buffer
|
||||
.SH SYNTAX
|
||||
.B #include <buffer.h>
|
||||
|
||||
void \fBbuffer_seek\fP(buffer* \fIb\fR,unsigned long int \fIr\fR);
|
||||
void \fBbuffer_seek\fP(buffer* \fIb\fR,size_t \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,7 @@
|
||||
#include "buffer.h"
|
||||
|
||||
void buffer_seek(buffer* b,unsigned long int len) {
|
||||
unsigned long int n=b->p+len;
|
||||
void buffer_seek(buffer* b,size_t len) {
|
||||
size_t 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 long int len) {
|
||||
int buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t 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 long int len) {
|
||||
int buffer_stubborn_read(ssize_t (*op)(),int fd,const char* buf, size_t len) {
|
||||
int w;
|
||||
for (;;) {
|
||||
if ((w=op(fd,buf,len))<0)
|
||||
|
17
byte.h
17
byte.h
@ -1,9 +1,8 @@
|
||||
#ifndef BYTE_H
|
||||
#define BYTE_H
|
||||
|
||||
#ifdef __dietlibc__
|
||||
#include <sys/cdefs.h>
|
||||
#endif
|
||||
/* for size_t: */
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef __pure__
|
||||
#define __pure__
|
||||
@ -11,29 +10,29 @@
|
||||
|
||||
/* byte_chr returns the smallest integer i between 0 and len-1
|
||||
* inclusive such that one[i] equals needle, or len if not found. */
|
||||
unsigned long byte_chr(const void* haystack, unsigned long len, char needle) __pure__;
|
||||
size_t byte_chr(const void* haystack, size_t len, char needle) __pure__;
|
||||
|
||||
/* byte_rchr returns the largest integer i between 0 and len-1 inclusive
|
||||
* such that one[i] equals needle, or len if not found. */
|
||||
unsigned long byte_rchr(const void* haystack,unsigned long len,char needle) __pure__;
|
||||
size_t byte_rchr(const void* haystack,size_t len,char needle) __pure__;
|
||||
|
||||
/* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1]
|
||||
* to out[len-1]. */
|
||||
void byte_copy(void* out, unsigned long len, const void* in);
|
||||
void byte_copy(void* out, size_t len, const void* in);
|
||||
|
||||
/* byte_copyr copies in[len-1] to out[len-1], in[len-2] to out[len-2],
|
||||
* ... and in[0] to out[0] */
|
||||
void byte_copyr(void* out, unsigned long len, const void* in);
|
||||
void byte_copyr(void* out, size_t len, const void* in);
|
||||
|
||||
/* byte_diff returns negative, 0, or positive, depending on whether the
|
||||
* string a[0], a[1], ..., a[len-1] is lexicographically smaller
|
||||
* than, equal to, or greater than the string b[0], b[1], ...,
|
||||
* b[len-1]. When the strings are different, byte_diff does not read
|
||||
* bytes past the first difference. */
|
||||
int byte_diff(const void* a, unsigned long len, const void* b) __pure__;
|
||||
int byte_diff(const void* a, size_t len, const void* b) __pure__;
|
||||
|
||||
/* byte_zero sets the bytes out[0], out[1], ..., out[len-1] to 0 */
|
||||
void byte_zero(void* out, unsigned long len);
|
||||
void byte_zero(void* out, size_t len);
|
||||
|
||||
#define byte_equal(s,n,t) (!byte_diff((s),(n),(t)))
|
||||
|
||||
|
@ -4,7 +4,7 @@ byte_chr \- search for a byte in a string
|
||||
.SH SYNTAX
|
||||
.B #include <byte.h>
|
||||
|
||||
long \fBbyte_chr\fP(const char *\fIhaystack\fR,unsigned long \fIlen\fR,char \fIneedle\fR);
|
||||
size_t \fBbyte_chr\fP(const char *\fIhaystack\fR,size_t \fIlen\fR,char \fIneedle\fR);
|
||||
.SH DESCRIPTION
|
||||
\fIbyte_chr\fR returns the smallest integer \fIi\fR between 0 and
|
||||
\fIlen\fR-1 inclusive such that \fIone\fR[\fIi\fR] equals \fIneedle\fR.
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
/* byte_chr returns the smallest integer i between 0 and len-1
|
||||
* inclusive such that one[i] equals needle, or len if not found. */
|
||||
unsigned long byte_chr(const void* haystack, unsigned long len, char needle) {
|
||||
size_t byte_chr(const void* haystack, size_t len, char needle) {
|
||||
register char c=needle;
|
||||
register const char* s=haystack;
|
||||
register const char* t=s+len;
|
||||
|
@ -4,7 +4,7 @@ byte_copy \- copy a string
|
||||
.SH SYNTAX
|
||||
.B #include <byte.h>
|
||||
|
||||
void \fBbyte_copy\fP(char *\fIout\fR,unsigned long \fIlen\fR,const char *\fIin\fR);
|
||||
void \fBbyte_copy\fP(char *\fIout\fR,size_t \fIlen\fR,const char *\fIin\fR);
|
||||
.SH DESCRIPTION
|
||||
\fIbyte_copy\fR copies \fIin\fR[0] to \fIout\fR[0], \fIin\fR[1] to
|
||||
\fIout\fR[1], etc., and finally \fIin\fR[\fIlen\fR-1] to
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
/* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1]
|
||||
* to out[len-1]. */
|
||||
void byte_copy(void* out, unsigned long len, const void* in) {
|
||||
void byte_copy(void* out, size_t len, const void* in) {
|
||||
register char* s=out;
|
||||
register const char* t=in;
|
||||
register const char* u=t+len;
|
||||
|
@ -4,7 +4,7 @@ byte_copyr \- copy a string
|
||||
.SH SYNTAX
|
||||
.B #include <byte.h>
|
||||
|
||||
void \fBbyte_copyr\fP(char *\fIout\fR,unsigned long \fIlen\fR,const char *\fIin\fR);
|
||||
void \fBbyte_copyr\fP(char *\fIout\fR,size_t \fIlen\fR,const char *\fIin\fR);
|
||||
.SH DESCRIPTION
|
||||
\fIbyte_copyr\fR copies \fIin\fR[\fIlen\fR-1] to \fIout\fR[\fIlen\fR-1],
|
||||
\fIin\fR[\fIlen\fR-2] to \fIout\fR[\fIlen\fR-2], etc., and
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
/* byte_copyr copies in[len-1] to out[len-1], in[len-2] to out[len-2],
|
||||
* ... and in[0] to out[0] */
|
||||
void byte_copyr(void* out, unsigned long len, const void* in) {
|
||||
void byte_copyr(void* out, size_t len, const void* in) {
|
||||
register char* s=(char*)out+len;
|
||||
register const char* t=in;
|
||||
register const char* u=t+len;
|
||||
|
@ -4,7 +4,7 @@ byte_diff \- compare two strings
|
||||
.SH SYNTAX
|
||||
.B #include <byte.h>
|
||||
|
||||
int \fBbyte_diff\fP(const char *\fIone\fR,unsigned long \fIlen\fR,const char *\fItwo\fR);
|
||||
int \fBbyte_diff\fP(const char *\fIone\fR,size_t \fIlen\fR,const char *\fItwo\fR);
|
||||
.SH DESCRIPTION
|
||||
\fIbyte_diff\fR returns negative, 0, or positive, depending on whether
|
||||
the string \fIone\fR[0], \fIone\fR[1], ..., \fIone\fR[\fIlen\fR-1] is
|
||||
|
@ -5,7 +5,7 @@
|
||||
* than, equal to, or greater than the string one[0], one[1], ...,
|
||||
* one[len-1]. When the strings are different, byte_diff does not read
|
||||
* bytes past the first difference. */
|
||||
int byte_diff(const void* a, unsigned long len, const void* b) {
|
||||
int byte_diff(const void* a, size_t len, const void* b) {
|
||||
register const unsigned char* s=a;
|
||||
register const unsigned char* t=b;
|
||||
register const unsigned char* u=t+len;
|
||||
|
@ -4,7 +4,7 @@ byte_equal \- compare two strings
|
||||
.SH SYNTAX
|
||||
.B #include <byte.h>
|
||||
|
||||
int \fBbyte_equal\fP(const char *\fIone\fR,unsigned long \fIlen\fR,const char *\fItwo\fR);
|
||||
int \fBbyte_equal\fP(const char *\fIone\fR,size_t \fIlen\fR,const char *\fItwo\fR);
|
||||
.SH DESCRIPTION
|
||||
\fIbyte_equal\fR returns 1 if the strings are equal, 0 otherwise.
|
||||
|
||||
|
@ -4,7 +4,7 @@ byte_rchr \- search for a byte in a string
|
||||
.SH SYNTAX
|
||||
.B #include <byte.h>
|
||||
|
||||
long \fBbyte_rchr\fP(const char *\fIhaystack\fR,unsigned long \fIlen\fR,char \fIneedle\fR);
|
||||
size_t \fBbyte_rchr\fP(const char *\fIhaystack\fR,size_t \fIlen\fR,char \fIneedle\fR);
|
||||
.SH DESCRIPTION
|
||||
\fIbyte_chr\fR returns the largest integer \fIi\fR between 0 and
|
||||
\fIlen\fR-1 inclusive such that \fIone\fR[\fIi\fR] equals \fIneedle\fR.
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
/* byte_rchr returns the largest integer i between 0 and len-1 inclusive
|
||||
* such that one[i] equals needle, or len if not found. */
|
||||
unsigned long byte_rchr(const void* haystack,unsigned long len,char needle) {
|
||||
size_t byte_rchr(const void* haystack,size_t len,char needle) {
|
||||
register char c=needle;
|
||||
register const char* s=haystack;
|
||||
register const char* t=s+len;
|
||||
|
@ -4,7 +4,7 @@ byte_zero \- initialize a string
|
||||
.SH SYNTAX
|
||||
.B #include <byte.h>
|
||||
|
||||
void \fBbyte_zero\fP(char *\fIout\fR,unsigned long \fIlen\fR);
|
||||
void \fBbyte_zero\fP(char *\fIout\fR,size_t \fIlen\fR);
|
||||
.SH DESCRIPTION
|
||||
\fIbyte_zero\fR sets \fIout\fR[0], \fIout\fR[1], ...,
|
||||
\fIout\fR[\fIlen\fR-1] to 0.
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "byte.h"
|
||||
|
||||
/* byte_zero sets the bytes out[0], out[1], ..., out[len-1] to 0 */
|
||||
void byte_zero(void* out, unsigned long len) {
|
||||
void byte_zero(void* out, size_t len) {
|
||||
register char* s=out;
|
||||
register const char* t=s+len;
|
||||
for (;;) {
|
||||
|
6
case.h
6
case.h
@ -1,15 +1,17 @@
|
||||
#ifndef CASE_H
|
||||
#define CASE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* turn upper case letters to lower case letters, ASCIIZ */
|
||||
void case_lowers(char *s);
|
||||
/* turn upper case letters to lower case letters, binary */
|
||||
void case_lowerb(void *buf,unsigned long len);
|
||||
void case_lowerb(void *buf,size_t len);
|
||||
|
||||
/* like str_diff, ignoring case */
|
||||
int case_diffs(const char *,const char *);
|
||||
/* like byte_diff, ignoring case */
|
||||
int case_diffb(const void *,unsigned long,const void *);
|
||||
int case_diffb(const void *,size_t ,const void *);
|
||||
|
||||
/* like str_start, ignoring case */
|
||||
int case_starts(const char *,const char *);
|
||||
|
@ -4,7 +4,7 @@ case_diffb \- compare strings case-insensitively
|
||||
.SH SYNTAX
|
||||
.B #include <case.h>
|
||||
|
||||
int \fBcase_diffb\fP(const void* \fIa\fR,unsigned long \fIlen\fR,const void* \fIb\fR);
|
||||
int \fBcase_diffb\fP(const void* \fIa\fR,size_t \fIlen\fR,const void* \fIb\fR);
|
||||
.SH DESCRIPTION
|
||||
case_diffb is similar to byte_diff. The difference is that for the
|
||||
comparison 'A' == 'a', 'B' == 'b', ..., 'Z' == 'z'.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "case.h"
|
||||
|
||||
int case_diffb(register const void* S,register unsigned long len,register const void* T)
|
||||
int case_diffb(register const void* S,register size_t len,register const void* T)
|
||||
{
|
||||
register unsigned char x;
|
||||
register unsigned char y;
|
||||
|
@ -4,7 +4,7 @@ case_lowerb \- compare strings case-insensitively
|
||||
.SH SYNTAX
|
||||
.B #include <case.h>
|
||||
|
||||
void \fBcase_lowerb\fP(void* \fIs\fR,unsigned long \fIlen\fR);
|
||||
void \fBcase_lowerb\fP(void* \fIs\fR,size_t \fIlen\fR);
|
||||
.SH DESCRIPTION
|
||||
case_lowerb converts each 'A' to 'a', 'B' to 'b', ..., 'Z' to 'z' in
|
||||
\fIs\fR[0], \fIs\fR[1], ..., \fIs\fR[\fIlen\fR].
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "case.h"
|
||||
|
||||
void case_lowerb(void *S,unsigned long len) {
|
||||
void case_lowerb(void *S,size_t len) {
|
||||
char* s=(char*)S;
|
||||
unsigned char x;
|
||||
while (len > 0) {
|
||||
|
12
cdb/cdb.c
12
cdb/cdb.c
@ -110,9 +110,9 @@ int cdb_findnext(struct cdb *c,const unsigned char *key,unsigned long int len) {
|
||||
if (!c->loop) {
|
||||
u = cdb_hash(key,len);
|
||||
if (cdb_read(c,buf,8,(u << 3) & 2047) == -1) return -1;
|
||||
uint32_unpack(buf + 4,&c->hslots);
|
||||
uint32_unpack((char*)buf + 4,&c->hslots);
|
||||
if (!c->hslots) return 0;
|
||||
uint32_unpack(buf,&c->hpos);
|
||||
uint32_unpack((char*)buf,&c->hpos);
|
||||
c->khash = u;
|
||||
u >>= 8;
|
||||
u %= c->hslots;
|
||||
@ -122,21 +122,21 @@ int cdb_findnext(struct cdb *c,const unsigned char *key,unsigned long int len) {
|
||||
|
||||
while (c->loop < c->hslots) {
|
||||
if (cdb_read(c,buf,8,c->kpos) == -1) return -1;
|
||||
uint32_unpack(buf + 4,&pos);
|
||||
uint32_unpack((char*)buf + 4,&pos);
|
||||
if (!pos) return 0;
|
||||
c->loop += 1;
|
||||
c->kpos += 8;
|
||||
if (c->kpos == c->hpos + (c->hslots << 3)) c->kpos = c->hpos;
|
||||
uint32_unpack(buf,&u);
|
||||
uint32_unpack((char*)buf,&u);
|
||||
if (u == c->khash) {
|
||||
if (cdb_read(c,buf,8,pos) == -1) return -1;
|
||||
uint32_unpack(buf,&u);
|
||||
uint32_unpack((char*)buf,&u);
|
||||
if (u == len)
|
||||
switch(match(c,key,len,pos + 8)) {
|
||||
case -1:
|
||||
return -1;
|
||||
case 1:
|
||||
uint32_unpack(buf + 4,&c->dlen);
|
||||
uint32_unpack((char*)buf + 4,&c->dlen);
|
||||
c->dpos = pos + 8 + len;
|
||||
return 1;
|
||||
}
|
||||
|
@ -4,15 +4,15 @@ static int doit(struct cdb *c,uint32 *kpos) {
|
||||
unsigned char buf[8];
|
||||
uint32 eod,klen;
|
||||
if (cdb_read(c,buf,4,0)) return -1;
|
||||
uint32_unpack(buf,&eod);
|
||||
uint32_unpack((char*)buf,&eod);
|
||||
if (eod<8 || eod-8<*kpos) return 0;
|
||||
c->kpos=*kpos+8;
|
||||
if (c->kpos<*kpos) return -1; /* wraparound */
|
||||
cdb_findstart(c);
|
||||
c->hslots=1;
|
||||
if (cdb_read(c,buf,8,*kpos) == -1) return -1;
|
||||
uint32_unpack(buf,&klen);
|
||||
uint32_unpack(buf+4,&c->dlen);
|
||||
uint32_unpack((char*)buf,&klen);
|
||||
uint32_unpack((char*)buf+4,&c->dlen);
|
||||
c->dpos=c->kpos+klen;
|
||||
*kpos+=8+klen+c->dlen;
|
||||
return 1;
|
||||
|
5
errmsg.h
5
errmsg.h
@ -1,11 +1,6 @@
|
||||
#ifndef ERRMSG_H
|
||||
#define ERRMSG_H
|
||||
|
||||
#ifdef __dietlibc__
|
||||
#include <sys/cdefs.h>
|
||||
#else
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
/* for exit(): */
|
||||
#include <stdlib.h>
|
||||
|
||||
|
38
fmt.h
38
fmt.h
@ -1,6 +1,8 @@
|
||||
#ifndef FMT_H
|
||||
#define FMT_H
|
||||
|
||||
/* for size_t: */
|
||||
#include <stddef.h>
|
||||
/* for time_t: */
|
||||
#include <sys/types.h>
|
||||
|
||||
@ -15,23 +17,23 @@
|
||||
|
||||
/* convert signed src integer -23 to ASCII '-','2','3', return length.
|
||||
* If dest is not NULL, write result to dest */
|
||||
unsigned int fmt_long(char *dest,signed long src);
|
||||
size_t fmt_long(char *dest,signed long src);
|
||||
|
||||
/* convert unsigned src integer 23 to ASCII '2','3', return length.
|
||||
* If dest is not NULL, write result to dest */
|
||||
unsigned int fmt_ulong(char *dest,unsigned long src);
|
||||
size_t fmt_ulong(char *dest,unsigned long src);
|
||||
|
||||
/* convert unsigned src integer 0x23 to ASCII '2','3', return length.
|
||||
* If dest is not NULL, write result to dest */
|
||||
unsigned int fmt_xlong(char *dest,unsigned long src);
|
||||
size_t fmt_xlong(char *dest,unsigned long src);
|
||||
|
||||
/* convert unsigned src integer 023 to ASCII '2','3', return length.
|
||||
* If dest is not NULL, write result to dest */
|
||||
unsigned int fmt_8long(char *dest,unsigned long src);
|
||||
size_t fmt_8long(char *dest,unsigned long src);
|
||||
|
||||
unsigned int fmt_longlong(char *dest,signed long long src);
|
||||
unsigned int fmt_ulonglong(char *dest,unsigned long long src);
|
||||
unsigned int fmt_xlonglong(char *dest,unsigned long long src);
|
||||
size_t fmt_longlong(char *dest,signed long long src);
|
||||
size_t fmt_ulonglong(char *dest,unsigned long long src);
|
||||
size_t fmt_xlonglong(char *dest,unsigned long long src);
|
||||
|
||||
#define fmt_uint(dest,src) fmt_ulong(dest,src)
|
||||
#define fmt_int(dest,src) fmt_long(dest,src)
|
||||
@ -40,50 +42,50 @@ unsigned int fmt_xlonglong(char *dest,unsigned long long src);
|
||||
|
||||
/* Like fmt_ulong, but prepend '0' while length is smaller than padto.
|
||||
* Does not truncate! */
|
||||
unsigned int fmt_ulong0(char *,unsigned long src,unsigned int padto);
|
||||
size_t fmt_ulong0(char *,unsigned long src,size_t padto);
|
||||
|
||||
#define fmt_uint0(buf,src,padto) fmt_ulong0(buf,src,padto)
|
||||
|
||||
/* convert src double 1.7 to ASCII '1','.','7', return length.
|
||||
* If dest is not NULL, write result to dest */
|
||||
unsigned int fmt_double(char *dest, double d,int max,int prec);
|
||||
size_t fmt_double(char *dest, double d,int max,int prec);
|
||||
|
||||
/* if src is negative, write '-' and return 1.
|
||||
* if src is positive, write '+' and return 1.
|
||||
* otherwise return 0 */
|
||||
unsigned int fmt_plusminus(char *dest,int src);
|
||||
size_t fmt_plusminus(char *dest,int src);
|
||||
|
||||
/* if src is negative, write '-' and return 1.
|
||||
* otherwise return 0. */
|
||||
unsigned int fmt_minus(char *dest,int src);
|
||||
size_t fmt_minus(char *dest,int src);
|
||||
|
||||
/* copy str to dest until \0 byte, return number of copied bytes. */
|
||||
unsigned long fmt_str(char *dest,const char *src);
|
||||
size_t fmt_str(char *dest,const char *src);
|
||||
|
||||
/* copy str to dest until \0 byte or limit bytes copied.
|
||||
* return number of copied bytes. */
|
||||
unsigned long fmt_strn(char *dest,const char *src,unsigned long limit);
|
||||
size_t fmt_strn(char *dest,const char *src,size_t limit);
|
||||
|
||||
/* "foo" -> " foo"
|
||||
* write padlen-srclen spaces, if that is >= 0. Then copy srclen
|
||||
* characters from src. Truncate only if total length is larger than
|
||||
* maxlen. Return number of characters written. */
|
||||
unsigned long fmt_pad(char* dest,const char* src,unsigned long srclen,unsigned long padlen,unsigned long maxlen);
|
||||
size_t fmt_pad(char* dest,const char* src,size_t srclen,size_t padlen,size_t maxlen);
|
||||
|
||||
/* "foo" -> "foo "
|
||||
* append padlen-srclen spaces after dest, if that is >= 0. Truncate
|
||||
* only if total length is larger than maxlen. Return number of
|
||||
* characters written. */
|
||||
unsigned long fmt_fill(char* dest,unsigned long srclen,unsigned long padlen,unsigned long maxlen);
|
||||
size_t fmt_fill(char* dest,size_t srclen,size_t padlen,size_t maxlen);
|
||||
|
||||
/* 1 -> "1", 4900 -> "4.9k", 2300000 -> "2.3M" */
|
||||
unsigned int fmt_human(char* dest,unsigned long long l);
|
||||
size_t fmt_human(char* dest,unsigned long long l);
|
||||
|
||||
/* 1 -> "1", 4900 -> "4.8k", 2300000 -> "2.2M" */
|
||||
unsigned int fmt_humank(char* dest,unsigned long long l);
|
||||
size_t fmt_humank(char* dest,unsigned long long l);
|
||||
|
||||
/* "Sun, 06 Nov 1994 08:49:37 GMT" */
|
||||
unsigned int fmt_httpdate(char* dest,time_t t);
|
||||
size_t fmt_httpdate(char* dest,time_t t);
|
||||
|
||||
/* internal functions, may be independently useful */
|
||||
char fmt_tohex(char c);
|
||||
|
@ -4,7 +4,7 @@ fmt_8long \- write an octal ASCII representation of an unsigned long integer
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_8long\fP(char *\fIdest\fR,unsigned long \fIsource\fR);
|
||||
size_t \fBfmt_8long\fP(char *\fIdest\fR,size_t \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_8long writes an ASCII representation ('0' to '7', base 8) of
|
||||
\fIsource\fR to \fIdest\fR and returns the number of bytes written.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_8long(char *dest,unsigned long i) {
|
||||
size_t fmt_8long(char *dest,unsigned long i) {
|
||||
register unsigned long len,tmp;
|
||||
/* first count the number of bytes needed */
|
||||
for (len=1, tmp=i; tmp>7; ++len) tmp>>=3;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_8longlong(char *dest,unsigned long long i) {
|
||||
size_t fmt_8longlong(char *dest,unsigned long long i) {
|
||||
register unsigned long len;
|
||||
unsigned long long tmp;
|
||||
/* first count the number of bytes needed */
|
||||
|
@ -4,8 +4,8 @@ fmt_double \- write an ASCII representation of a double
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_double\fP(char *\fIdest\fR,double \fId\fR,int
|
||||
\fImaxlen\fR,int \fIprec\fR);
|
||||
size_t \fBfmt_double\fP(char *\fIdest\fR,double \fId\fR,size_t
|
||||
\fImaxlen\fR,size_t \fIprec\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_double writes an ASCII representation ('0' to '9', base 10) of
|
||||
\fId\fR to \fIdest\fR and returns the number of bytes written. No more
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_double(char *dest, double d,int maxlen,int prec) {
|
||||
size_t fmt_double(char *dest, double d,int maxlen,int prec) {
|
||||
union {
|
||||
double d;
|
||||
unsigned long long x;
|
||||
|
@ -4,9 +4,9 @@ fmt_fill \- append spaces to a string
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned long \fBfmt_fill\fP(char *\fIdest\fR,
|
||||
unsigned long \fIsrclen\fR, unsigned long \fIpadlen\fR,
|
||||
unsigned long \fImaxlen\fR);
|
||||
size_t \fBfmt_fill\fP(char *\fIdest\fR,
|
||||
size_t \fIsrclen\fR, size_t \fIpadlen\fR,
|
||||
size_t \fImaxlen\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_fill appends \fIpadlen\fR-\fIsrclen\fR spaces (if that number is
|
||||
positive) to \fIdest\fR (which holds \fIsrclen\fR bytes). It truncates
|
||||
|
@ -4,7 +4,7 @@
|
||||
* append padlen-srclen spaces after dest, if that is >= 0. Truncate
|
||||
* only if total length is larger than maxlen. Return number of
|
||||
* characters written. */
|
||||
unsigned long fmt_fill(char* dest,unsigned long srclen,unsigned long padlen,unsigned long maxlen) {
|
||||
size_t fmt_fill(char* dest,size_t srclen,size_t padlen,size_t maxlen) {
|
||||
long todo;
|
||||
char* olddest=dest;
|
||||
char* max=dest+maxlen;
|
||||
|
@ -4,7 +4,7 @@ fmt_httpdate \- write a date in ASCII as in the HTTP protocol
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_httpdate\fP(char *\fIdest\fR,time_t \fIsource\fR);
|
||||
size_t \fBfmt_httpdate\fP(char *\fIdest\fR,time_t \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_httpdate writes a date in ASCII representation as the HTTP protocol defines it:
|
||||
"Sun, 06 Nov 1994 08:49:37 GMT".
|
||||
|
@ -8,11 +8,11 @@ static unsigned int fmt_2digits(char* dest,int i) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
unsigned int fmt_httpdate(char* dest,time_t t) {
|
||||
size_t fmt_httpdate(char* dest,time_t t) {
|
||||
static const char days[] = "SunMonTueWedThuFriSat";
|
||||
static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||
struct tm* x=gmtime(&t);
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
if (dest==0) return 29;
|
||||
/* "Sun, 06 Nov 1994 08:49:37 GMT" */
|
||||
|
@ -4,7 +4,7 @@ fmt_human \- write a human readable ASCII representation of a long integer
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_human\fP(char *\fIdest\fR,unsigned long long \fIsource\fR);
|
||||
size_t \fBfmt_human\fP(char *\fIdest\fR,unsigned long long \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_human writes a human readable ASCII representation of \fIsource\fR
|
||||
to \fIdest\fR and returns the number of bytes written. The result
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_human(char* dest,unsigned long long l) {
|
||||
size_t fmt_human(char* dest,unsigned long long l) {
|
||||
char unit;
|
||||
int i;
|
||||
if (l<1000) return fmt_ulong(dest,l);
|
||||
|
@ -4,7 +4,7 @@ fmt_humank \- write a human readable ASCII representation of a long integer
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_humank\fP(char *\fIdest\fR,unsigned long long \fIsource\fR);
|
||||
size_t \fBfmt_humank\fP(char *\fIdest\fR,unsigned long long \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_humank writes a human readable ASCII representation of \fIsource\fR
|
||||
to \fIdest\fR and returns the number of bytes written. The result
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_humank(char* dest,unsigned long long l) {
|
||||
size_t fmt_humank(char* dest,unsigned long long l) {
|
||||
char unit;
|
||||
int i;
|
||||
size_t i;
|
||||
if (l<1000) return fmt_ulong(dest,l);
|
||||
if (l>1024*1024*1024*1024ull) {
|
||||
l=(l+(1024*1024*1024*1024ull/20))/(1024*1024*1024*1024ull/10);
|
||||
|
@ -4,7 +4,7 @@ fmt_long \- write an ASCII representation of a long integer
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_long\fP(char *\fIdest\fR,long \fIsource\fR);
|
||||
size_t \fBfmt_long\fP(char *\fIdest\fR,long \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_long writes an ASCII representation ('-' and '0' to '9', base 10) of
|
||||
\fIsource\fR to \fIdest\fR and returns the number of bytes written.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_long(char *dest,long int i) {
|
||||
size_t fmt_long(char *dest,long int i) {
|
||||
if (i<0) {
|
||||
if (dest) *dest++='-';
|
||||
return fmt_ulong(dest,-i)+1;
|
||||
|
@ -4,7 +4,7 @@ fmt_longlong \- write an ASCII representation of a long long integer
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_longlong\fP(char *\fIdest\fR,long long \fIsource\fR);
|
||||
size_t \fBfmt_longlong\fP(char *\fIdest\fR,long long \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_longlong writes an ASCII representation ('-' and '0' to '9', base 10) of
|
||||
\fIsource\fR to \fIdest\fR and returns the number of bytes written.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_longlong(char *dest,signed long long int i) {
|
||||
size_t fmt_longlong(char *dest,signed long long int i) {
|
||||
if (i<0) {
|
||||
if (dest) *dest++='-';
|
||||
return fmt_ulonglong(dest,-i)+1;
|
||||
|
@ -4,7 +4,7 @@ fmt_minus \- write '-' for negative integers
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_minus\fP(char *\fIdest\fR,signed int \fIsource\fR);
|
||||
size_t \fBfmt_minus\fP(char *\fIdest\fR,signed int \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_minus writes '-' if \fIsource\fR is negative, nothing otherwise. It
|
||||
returns the number of bytes written.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_minus(char *dest,int i) {
|
||||
size_t fmt_minus(char *dest,int i) {
|
||||
if (i<0) {
|
||||
if (dest) *dest='-';
|
||||
return 1;
|
||||
|
@ -4,9 +4,9 @@ fmt_pad \- pad a string with spaces.
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned long \fBfmt_pad\fP(char *\fIdest\fR, const char *\fIsource\fR,
|
||||
unsigned long \fIsrclen\fR, unsigned long \fIpadlen\fR,
|
||||
unsigned long \fImaxlen\fR);
|
||||
size_t \fBfmt_pad\fP(char *\fIdest\fR, const char *\fIsource\fR,
|
||||
size_t \fIsrclen\fR, size_t \fIpadlen\fR,
|
||||
size_t \fImaxlen\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_pad writes \fIpadlen\fR-\fIsrclen\fR spaces (if that number is
|
||||
positive) and then \fIsrclen\fR characters from \fIsource\fR. It
|
||||
|
@ -4,7 +4,7 @@
|
||||
* write padlen-srclen spaces, if that is >= 0. Then copy srclen
|
||||
* characters from src. Truncate only if total length is larger than
|
||||
* maxlen. Return number of characters written. */
|
||||
unsigned long fmt_pad(char* dest,const char* src,unsigned long srclen,unsigned long padlen,unsigned long maxlen) {
|
||||
size_t fmt_pad(char* dest,const char* src,size_t srclen,size_t padlen,size_t maxlen) {
|
||||
long todo;
|
||||
char* olddest=dest;
|
||||
char* max=dest+maxlen;
|
||||
|
@ -4,7 +4,7 @@ fmt_plusminus \- write '+' or '-'
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_plusminus\fP(char *\fIdest\fR,signed int \fIsource\fR);
|
||||
size_t \fBfmt_plusminus\fP(char *\fIdest\fR,signed int \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_plusminus writes '-' to \fIdest\fR if \fIsource\fR is negative, '+'
|
||||
if \fIsource\fR is positive, nothing otherwise. It returns the number
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_plusminus(char *dest,int i) {
|
||||
size_t fmt_plusminus(char *dest,int i) {
|
||||
if (i) {
|
||||
if (dest) *dest=(i>=0?'+':'-');
|
||||
return 1;
|
||||
|
@ -4,7 +4,7 @@ fmt_str \- write an ASCII string
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned long \fBfmt_str\fP(char *\fIdest\fR,const char *\fIsource\fR);
|
||||
size_t \fBfmt_str\fP(char *\fIdest\fR,const char *\fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_str copies all leading nonzero bytes from \fIsource\fR to \fIdest\fR
|
||||
and returns the number of bytes it copied.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned long fmt_str(char *out,const char *in) {
|
||||
size_t fmt_str(char *out,const char *in) {
|
||||
register char* s=out;
|
||||
register const char* t=in;
|
||||
for (;;) {
|
||||
|
@ -4,8 +4,8 @@ fmt_strn \- write an ASCII string
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned long \fBfmt_strn\fP(char *\fIdest\fR,const char *\fIsource\fR,
|
||||
unsigned long maxlen);
|
||||
size_t \fBfmt_strn\fP(char *\fIdest\fR,const char *\fIsource\fR,
|
||||
size_t \fImaxlen\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_str copies at most \fImaxlen\fR leading nonzero bytes from
|
||||
\fIsource\fR to \fIdest\fR and returns the number of bytes it copied.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned long fmt_strn(char *out,const char *in,unsigned long limit) {
|
||||
size_t fmt_strn(char *out,const char *in,size_t limit) {
|
||||
register char* s=out;
|
||||
register const char* t=in;
|
||||
register const char* u=in+limit;
|
||||
|
@ -4,7 +4,7 @@ fmt_uint \- write an ASCII representation of an unsigned integer
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_uint\fP(char *\fIdest\fR,unsigned int \fIsource\fR);
|
||||
size_t \fBfmt_uint\fP(char *\fIdest\fR,unsigned int \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_uint writes an ASCII representation ('0' to '9', base 10) of
|
||||
\fIsource\fR to \fIdest\fR and returns the number of bytes written.
|
||||
|
@ -4,8 +4,8 @@ fmt_uint0 \- write a zero-padded ASCII representation of an unsigned integer
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_uint0\fP(char *\fIdest\fR,unsigned int \fIsource\fR,
|
||||
unsigned int \fIn\fR);
|
||||
size_t \fBfmt_uint0\fP(char *\fIdest\fR,unsigned int \fIsource\fR,
|
||||
size_t \fIn\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_uint0 writes an ASCII representation ('0' to '9', base 10) of
|
||||
\fIsource\fR to \fIdest\fR and returns the number of bytes written.
|
||||
|
@ -4,7 +4,7 @@ fmt_ulong \- write an ASCII representation of an unsigned long integer
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_ulong\fP(char *\fIdest\fR,unsigned long \fIsource\fR);
|
||||
size_t \fBfmt_ulong\fP(char *\fIdest\fR,unsigned long \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_ulong writes an ASCII representation ('0' to '9', base 10) of
|
||||
\fIsource\fR to \fIdest\fR and returns the number of bytes written.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_ulong(char *dest,unsigned long i) {
|
||||
size_t fmt_ulong(char *dest,unsigned long i) {
|
||||
register unsigned long len,tmp,len2;
|
||||
/* first count the number of bytes needed */
|
||||
for (len=1, tmp=i; tmp>9; ++len) tmp/=10;
|
||||
|
@ -4,8 +4,8 @@ fmt_ulong0 \- write a zero-padded ASCII representation of an unsigned long integ
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_ulong0\fP(char *\fIdest\fR, unsigned long \fIsource\fR,
|
||||
unsigned int \fIn\fR);
|
||||
size_t \fBfmt_ulong0\fP(char *\fIdest\fR, unsigned long \fIsource\fR,
|
||||
size_t \fIn\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_ulong0 writes an ASCII representation ('0' to '9', base 10) of
|
||||
\fIsource\fR to \fIdest\fR and returns the number of bytes written.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_ulong0(char *dest,unsigned long i,unsigned int pad) {
|
||||
size_t fmt_ulong0(char *dest,unsigned long i,size_t pad) {
|
||||
register unsigned int len;
|
||||
register unsigned long tmp;
|
||||
/* first count the number of bytes needed */
|
||||
|
@ -4,7 +4,7 @@ fmt_ulonglong \- write an ASCII representation of an unsigned long long integer
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_ulonglong\fP(char *\fIdest\fR,unsigned long long \fIsource\fR);
|
||||
size_t \fBfmt_ulonglong\fP(char *\fIdest\fR,unsigned long long \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_ulonglong writes an ASCII representation ('0' to '9', base 10) of
|
||||
\fIsource\fR to \fIdest\fR and returns the number of bytes written.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_ulonglong(char *dest,unsigned long long int i) {
|
||||
size_t fmt_ulonglong(char *dest,unsigned long long int i) {
|
||||
register unsigned long len;
|
||||
unsigned long long tmp,len2;
|
||||
/* first count the number of bytes needed */
|
||||
|
@ -4,7 +4,7 @@ fmt_xlong \- write a hexadecimal ASCII representation of an unsigned long intege
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_xlong\fP(char *\fIdest\fR,unsigned long \fIsource\fR);
|
||||
size_t \fBfmt_xlong\fP(char *\fIdest\fR,unsigned long \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_xlong writes an ASCII representation ('0' to '9' and 'a' to 'f',
|
||||
base 16) of \fIsource\fR to \fIdest\fR and returns the number of bytes
|
||||
|
@ -5,7 +5,7 @@ static inline char tohex(char c) {
|
||||
return c>=10?c-10+'a':c+'0';
|
||||
}
|
||||
|
||||
unsigned int fmt_xlong(char *dest,unsigned long i) {
|
||||
size_t fmt_xlong(char *dest,unsigned long i) {
|
||||
register unsigned long len,tmp;
|
||||
/* first count the number of bytes needed */
|
||||
for (len=1, tmp=i; tmp>15; ++len) tmp>>=4;
|
||||
|
@ -4,7 +4,7 @@ fmt_xlonglong \- write a hexadecimal ASCII representation of an unsigned long lo
|
||||
.SH SYNTAX
|
||||
.B #include <fmt.h>
|
||||
|
||||
unsigned int \fBfmt_xlonglong\fP(char *\fIdest\fR,unsigned long long \fIsource\fR);
|
||||
size_t \fBfmt_xlonglong\fP(char *\fIdest\fR,unsigned long long \fIsource\fR);
|
||||
.SH DESCRIPTION
|
||||
fmt_xlonglong writes an ASCII representation ('0' to '9' and 'a' to 'f',
|
||||
base 16) of \fIsource\fR to \fIdest\fR and returns the number of bytes
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fmt.h"
|
||||
|
||||
unsigned int fmt_xlonglong(char *dest,unsigned long long i) {
|
||||
size_t fmt_xlonglong(char *dest,unsigned long long i) {
|
||||
int tmp=0;
|
||||
if (i>>32) {
|
||||
tmp=fmt_xlong(dest,i>>32);
|
||||
|
10
mmap.h
10
mmap.h
@ -1,20 +1,22 @@
|
||||
#ifndef MMAP_H
|
||||
#define MMAP_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* open file for reading, mmap whole file, close file, write length of
|
||||
* map in filesize and return pointer to map. */
|
||||
char* mmap_read(const char *filename,unsigned long* filesize);
|
||||
char* mmap_read(const char *filename,size_t* filesize);
|
||||
|
||||
/* open file for writing, mmap whole file privately (copy on write),
|
||||
* close file, write length of map in filesize and return pointer to
|
||||
* map. */
|
||||
char* mmap_private(const char *filename,unsigned long* filesize);
|
||||
char* mmap_private(const char *filename,size_t* filesize);
|
||||
|
||||
/* open file for writing, mmap whole file shared, close file, write
|
||||
* length of map in filesize and return pointer to map. */
|
||||
char* mmap_shared(const char *filename,unsigned long* filesize);
|
||||
char* mmap_shared(const char *filename,size_t* filesize);
|
||||
|
||||
/* unmap a mapped region */
|
||||
int mmap_unmap(char* mapped,unsigned long maplen);
|
||||
int mmap_unmap(char* mapped,size_t maplen);
|
||||
|
||||
#endif
|
||||
|
@ -4,7 +4,7 @@ mmap_private \- memory map a file for reading and writing
|
||||
.SH SYNTAX
|
||||
.B #include <mmap.h>
|
||||
|
||||
extern char* \fBmmap_private\fP(const char* \fIfilename\fR,unsigned long* \fIfilesize\fR);
|
||||
char* \fBmmap_private\fP(const char* \fIfilename\fR,size_t* \fIfilesize\fR);
|
||||
.SH DESCRIPTION
|
||||
mmap_private opens \fIfilename\fR for reading and writing, maps the
|
||||
whole file into memory, closes the file, writes the length of the file
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user