Browse Source

switch to size_t and ssize_t

master
Felix von Leitner 15 years ago
parent
commit
0698149baf
  1. 1
      CHANGES
  2. 41
      buffer.h
  3. 2
      buffer/buffer_0.c
  4. 2
      buffer/buffer_0small.c
  5. 2
      buffer/buffer_feed.c
  6. 2
      buffer/buffer_flush.c
  7. 2
      buffer/buffer_fromsa.c
  8. 2
      buffer/buffer_get.3
  9. 2
      buffer/buffer_get.c
  10. 2
      buffer/buffer_get_new_token_sa.3
  11. 2
      buffer/buffer_get_new_token_sa.c
  12. 4
      buffer/buffer_get_token.3
  13. 4
      buffer/buffer_get_token.c
  14. 4
      buffer/buffer_get_token_pred.3
  15. 2
      buffer/buffer_get_token_pred.c
  16. 2
      buffer/buffer_get_token_sa.3
  17. 2
      buffer/buffer_get_token_sa.c
  18. 2
      buffer/buffer_getline.3
  19. 2
      buffer/buffer_getline.c
  20. 2
      buffer/buffer_getn.3
  21. 6
      buffer/buffer_getn.c
  22. 4
      buffer/buffer_init.3
  23. 4
      buffer/buffer_init.c
  24. 4
      buffer/buffer_init_free.3
  25. 4
      buffer/buffer_init_free.c
  26. 2
      buffer/buffer_mmapread.c
  27. 2
      buffer/buffer_put.3
  28. 4
      buffer/buffer_put.c
  29. 2
      buffer/buffer_putalign.3
  30. 2
      buffer/buffer_putalign.c
  31. 2
      buffer/buffer_putflush.3
  32. 2
      buffer/buffer_putflush.c
  33. 2
      buffer/buffer_seek.3
  34. 4
      buffer/buffer_seek.c
  35. 2
      buffer/buffer_stubborn.c
  36. 2
      buffer/buffer_stubborn2.c
  37. 17
      byte.h
  38. 2
      byte/byte_chr.3
  39. 2
      byte/byte_chr.c
  40. 2
      byte/byte_copy.3
  41. 2
      byte/byte_copy.c
  42. 2
      byte/byte_copyr.3
  43. 2
      byte/byte_copyr.c
  44. 2
      byte/byte_diff.3
  45. 2
      byte/byte_diff.c
  46. 2
      byte/byte_equal.3
  47. 2
      byte/byte_rchr.3
  48. 2
      byte/byte_rchr.c
  49. 2
      byte/byte_zero.3
  50. 2
      byte/byte_zero.c
  51. 6
      case.h
  52. 2
      case/case_diffb.3
  53. 2
      case/case_diffb.c
  54. 2
      case/case_lowerb.3
  55. 2
      case/case_lowerb.c
  56. 12
      cdb/cdb.c
  57. 6
      cdb/cdb_traverse.c
  58. 5
      errmsg.h
  59. 38
      fmt.h
  60. 2
      fmt/fmt_8long.3
  61. 2
      fmt/fmt_8long.c
  62. 2
      fmt/fmt_8longlong.c
  63. 4
      fmt/fmt_double.3
  64. 2
      fmt/fmt_double.c
  65. 6
      fmt/fmt_fill.3
  66. 2
      fmt/fmt_fill.c
  67. 2
      fmt/fmt_httpdate.3
  68. 4
      fmt/fmt_httpdate.c
  69. 2
      fmt/fmt_human.3
  70. 2
      fmt/fmt_human.c
  71. 2
      fmt/fmt_humank.3
  72. 4
      fmt/fmt_humank.c
  73. 2
      fmt/fmt_long.3
  74. 2
      fmt/fmt_long.c
  75. 2
      fmt/fmt_longlong.3
  76. 2
      fmt/fmt_longlong.c
  77. 2
      fmt/fmt_minus.3
  78. 2
      fmt/fmt_minus.c
  79. 6
      fmt/fmt_pad.3
  80. 2
      fmt/fmt_pad.c
  81. 2
      fmt/fmt_plusminus.3
  82. 2
      fmt/fmt_plusminus.c
  83. 2
      fmt/fmt_str.3
  84. 2
      fmt/fmt_str.c
  85. 4
      fmt/fmt_strn.3
  86. 2
      fmt/fmt_strn.c
  87. 2
      fmt/fmt_uint.3
  88. 4
      fmt/fmt_uint0.3
  89. 2
      fmt/fmt_ulong.3
  90. 2
      fmt/fmt_ulong.c
  91. 4
      fmt/fmt_ulong0.3
  92. 2
      fmt/fmt_ulong0.c
  93. 2
      fmt/fmt_ulonglong.3
  94. 2
      fmt/fmt_ulonglong.c
  95. 2
      fmt/fmt_xlong.3
  96. 2
      fmt/fmt_xlong.c
  97. 2
      fmt/fmt_xlonglong.3
  98. 2
      fmt/fmt_xlonglong.c
  99. 10
      mmap.h
  100. 2
      mmap/mmap_private.3

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

@ -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);

2
buffer/buffer_0.c

@ -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);
}

2
buffer/buffer_0small.c

@ -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);
}

2
buffer/buffer_feed.c

@ -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) {

2
buffer/buffer_flush.c

@ -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;

2
buffer/buffer_fromsa.c

@ -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;

2
buffer/buffer_get.3

@ -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

2
buffer/buffer_get.c

@ -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;

2
buffer/buffer_get_new_token_sa.3

@ -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

2
buffer/buffer_get_new_token_sa.c

@ -1,7 +1,7 @@
#include "stralloc.h"
#include "buffer.h"
int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned 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
buffer/buffer_get_token.3

@ -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

4
buffer/buffer_get_token.c

@ -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
buffer/buffer_get_token_pred.3

@ -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
buffer/buffer_get_token_pred.c

@ -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;

2
buffer/buffer_get_token_sa.3

@ -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

2
buffer/buffer_get_token_sa.c

@ -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;

2
buffer/buffer_getline.3

@ -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

2
buffer/buffer_getline.c

@ -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);
}

2
buffer/buffer_getn.3

@ -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

6
buffer/buffer_getn.c

@ -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;

4
buffer/buffer_init.3

@ -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.

4
buffer/buffer_init.c

@ -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;

4
buffer/buffer_init_free.3

@ -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().

4
buffer/buffer_init_free.c

@ -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;
}

2
buffer/buffer_mmapread.c

@ -1,7 +1,7 @@
#include <buffer.h>
#include <mmap.h>
static int op() {
static ssize_t op() {
return 0;
}

2
buffer/buffer_put.3

@ -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.

4
buffer/buffer_put.c

@ -1,9 +1,9 @@
#include "byte.h"
#include "buffer.h"
extern int buffer_stubborn(int (*op)(),int fd,const char* buf, unsigned 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) {

2
buffer/buffer_putalign.3

@ -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.

2
buffer/buffer_putalign.c

@ -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);

2
buffer/buffer_putflush.3

@ -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).

2
buffer/buffer_putflush.c

@ -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;

2
buffer/buffer_seek.3

@ -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.

4
buffer/buffer_seek.c

@ -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;

2
buffer/buffer_stubborn.c

@ -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) {

2
buffer/buffer_stubborn2.c

@ -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

@ -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)))

2
byte/byte_chr.3

@ -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
byte/byte_chr.c

@ -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;

2
byte/byte_copy.3

@ -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
byte/byte_copy.c

@ -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;

2
byte/byte_copyr.3

@ -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
byte/byte_copyr.c

@ -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;

2
byte/byte_diff.3

@ -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

2
byte/byte_diff.c

@ -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;

2
byte/byte_equal.3

@ -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.

2
byte/byte_rchr.3

@ -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
byte/byte_rchr.c

@ -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;

2
byte/byte_zero.3

@ -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.

2
byte/byte_zero.c

@ -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

@ -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 *);

2
case/case_diffb.3

@ -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'.

2
case/case_diffb.c

@ -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;

2
case/case_lowerb.3

@ -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].

2
case/case_lowerb.c

@ -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

@ -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;
}

6
cdb/cdb_traverse.c

@ -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

@ -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

@ -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);

2
fmt/fmt_8long.3

@ -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.

2
fmt/fmt_8long.c

@ -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;

2
fmt/fmt_8longlong.c

@ -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
fmt/fmt_double.3

@ -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

2
fmt/fmt_double.c

@ -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;

6
fmt/fmt_fill.3

@ -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

2
fmt/fmt_fill.c

@ -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;

2
fmt/fmt_httpdate.3

@ -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".

4
fmt/fmt_httpdate.c

@ -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" */

2
fmt/fmt_human.3

@ -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

2
fmt/fmt_human.c

@ -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);

2
fmt/fmt_humank.3

@ -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

4
fmt/fmt_humank.c

@ -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);

2
fmt/fmt_long.3

@ -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.

2
fmt/fmt_long.c

@ -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;

2
fmt/fmt_longlong.3

@ -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.

2
fmt/fmt_longlong.c

@ -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;

2
fmt/fmt_minus.3

@ -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.

2
fmt/fmt_minus.c

@ -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;

6
fmt/fmt_pad.3

@ -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

2
fmt/fmt_pad.c

@ -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;

2
fmt/fmt_plusminus.3

@ -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