remove libowfat (will not compile)

This commit is contained in:
Neale Pickett 2012-02-13 17:06:42 -07:00
parent 54032d736a
commit 273f348fa8
37 changed files with 8 additions and 806 deletions

View File

@ -1,58 +1,14 @@
VERSION=$(shell head -n 1 CHANGES | tr -d :) VERSION := $(shell head -n 1 CHANGES | tr -d :)
CFLAGS += -Os -fomit-frame-pointer CFLAGS = -DFNORD='fnord/$(VERSION)'
#CFLAGS=-g
all: fnord fnord-cgi fnord-idx all: fnord fnord-cgi fnord-idx
fnord: httpd fnord-cgi: httpd.c
cp -p $^ $@ fnord-cgi: CFLAGS += -DCGI
-strip -R .note -R .comment $@
httpd: httpd.o libowfat.a fnord-idx: httpd.c
$(CC) -o $@ $^ $(CFLAGS) fnord-idx: CFLAGS += -DDIR_LIST
fnord-cgi: httpd-cgi.o libowfat.a
$(CC) -o $@ $^ $(CFLAGS)
-strip -R .note -R .comment $@
fnord-idx: httpd-idx.o libowfat.a
$(CC) -o $@ $^ $(CFLAGS)
-strip -R .note -R .comment $@
libowfat.a: httpd.o buffer_1.o buffer_puts.o buffer_flush.o buffer_put.o \
buffer_putulong.o buffer_2.o buffer_putspace.o buffer_stubborn.o \
buffer_putflush.o str_copy.o fmt_ulong.o byte_diff.o byte_copy.o \
str_len.o str_diff.o str_chr.o str_diffn.o str_start.o scan_ulong.o
ar cru $@ $^
-ranlib $@
httpd.o: httpd.c
$(CC) -pipe $(CFLAGS) -c $^ -DFNORD=\"fnord/$(VERSION)\"
httpd-cgi.o: httpd.c
$(CC) -pipe $(CFLAGS) -c httpd.c -o $@ -DCGI -DFNORD=\"fnord/$(VERSION)\"
httpd-idx.o: httpd.c
$(CC) -pipe $(CFLAGS) -c httpd.c -o $@ -DDIR_LIST -DFNORD=\"fnord/$(VERSION)\"
%.o: %.c
$(CC) -pipe $(CFLAGS) -c $^
.PHONY: rename clean install server
server: fnord
tcpserver -v -RHl localhost 0 8000 ./fnord
clean: clean:
rm -f *.[oa] httpd fnord fnord-cgi fnord-idx rm -f *.[oa] fnord fnord-cgi fnord-idx
install:
test -d /command || mkdir /command
CURNAME=$(notdir $(shell pwd))
tar: rename
cd .. && tar cvvf fnord-$(VERSION).tar.bz2 --use=bzip2 --exclude CVS --exclude bin-* --exclude .cvsignore --exclude default fnord-$(VERSION)
rename:
if test $(CURNAME) != fnord-$(VERSION); then cd .. && mv $(CURNAME) fnord-$(VERSION); fi

View File

@ -1,20 +0,0 @@
The auth patch was contributed by Nicolas George. Here is the excerpt from his
email describing how to use it. Firstly, #define AUTH or add -DAUTH to CFLAGS.
Then, I have implemented some basic handling of HTTP authentication. The
concept is that if there is a file .http-auth in the root of one site,
then it is an executable (most likely a script) that handles
authorizations. It is called with first argument the virtual host name,
second argument the path to the requested file, and third argument the
value of the Authorization header, if present. If it exists
successfully, access is granted, else 401.
An example of .http-auth that grants the access only to the user Cigaes
with password foober is:
#!/bin/sh
[ x"$3" = x"Basic Q2lnYWVzOmZvb2Jhcg==" ]
The format of the Authorization is not very convenient. The mangled
string is the base64 encoding of "$username:$password".

32
SPEED
View File

@ -1,32 +0,0 @@
fnord is meant to be used under Linux with the diet libc
(http://www.fefe.de/dietlibc/). These are actual apache bench results,
all on localhost on a 100k JPEG test file, 1000 requests with a
concurrency of 10.
To be fair, I linked thttpd, mini_httpd and fnord against the diet libc.
I did not try this with apache, though. Since apache does not exec
anything, it should not matter much, though.
mini_httpd forks for each request, apparently does not support
keep-alive and compared to fnord does not incur the overhead of execve
for each request.
thttpd is the fastest web server known to me.
Values are time in seconds for the whole transaction (1000 downloads, 10
parallel connections).
server software keep-alive no keep-alive
----------------------------------------------------------------
mini_httpd 1.15c 1.690 0.943
apache 1.3.22 1.236 1.178
thttpd 2.21b 0.896 0.839
fnord 1.008 1.331
fnord w/ sendfile 0.316 0.912
Please note that fnord actually plays in the same league as others even
without keep-alive and sendfile support. That is surprising since fnord
has one fork() _and_ one execve() as overhead for each request! As the
difference between keep-alive and non-keep-alive shows, that difference
is not very large. That is the achievement of the diet libc, which
reduces the normally significant libc overhead to zero.

3
TODO
View File

@ -1,2 +1 @@
investigate CGI keep-alive * Investigate CGI keep-alive

View File

@ -1,70 +0,0 @@
#ifndef BUFFER_H
#define BUFFER_H
typedef struct buffer {
char *x;
unsigned int p;
unsigned int n;
unsigned int a;
int fd;
int (*op)();
} buffer;
#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, 0, (len), (fd), (op) }
#define BUFFER_INIT_READ(op,fd,buf,len) BUFFER_INIT(op,fd,buf,len) /*obsolete*/
#define BUFFER_INSIZE 8192
#define BUFFER_OUTSIZE 8192
extern void buffer_init(buffer* b,int (*op)(),int fd,char* y,unsigned int ylen);
extern int buffer_flush(buffer* b);
extern int buffer_put(buffer* b,const char* x,unsigned int len);
extern int buffer_putalign(buffer* b,const char* x,unsigned int len);
extern int buffer_putflush(buffer* b,const char* x,unsigned int len);
extern int buffer_puts(buffer* b,const char* x);
extern int buffer_putsalign(buffer* b,const char* x);
extern int buffer_putsflush(buffer* b,const char* x);
extern int buffer_putspace(buffer* b);
#define buffer_PUTC(s,c) \
( ((s)->a != (s)->p) \
? ( (s)->x[(s)->p++] = (c), 0 ) \
: buffer_put((s),&(c),1) \
)
extern int buffer_get(buffer* b,char* x,unsigned int len);
extern int buffer_bget(buffer* b,char* x,unsigned int len);
extern int buffer_feed(buffer* b);
extern int buffer_getc(buffer* b,char* x);
extern int buffer_getn(buffer* b,char* x,unsigned int len);
extern int buffer_get_token(buffer* b,char* x,unsigned int len,const char* charset,unsigned int setlen);
#define buffer_getline(b,x,len) buffer_get_token((b),(x),(len),"\n",1)
extern char *buffer_peek(buffer* b);
extern void buffer_seek(buffer* b,unsigned int len);
#define buffer_PEEK(s) ( (s)->x + (s)->p )
#define buffer_SEEK(s,len) ( (s)->p += (len) )
#define buffer_GETC(s,c) \
( ((s)->p < (s>->n) \
? ( *(c) = *buffer_PEEK(s), buffer_SEEK((s),1), 1 ) \
: buffer_get((s),(c),1) \
)
extern int buffer_copy(buffer* out,buffer* in);
extern int buffer_putulong(buffer *b,unsigned long l);
extern int buffer_put8long(buffer *b,unsigned long l);
extern int buffer_putxlong(buffer *b,unsigned long l);
extern int buffer_putlong(buffer *b,unsigned long l);
extern int buffer_putulonglong(buffer *b,unsigned long long l);
extern buffer *buffer_0;
extern buffer *buffer_0small;
extern buffer *buffer_1;
extern buffer *buffer_1small;
extern buffer *buffer_2;
#endif

View File

@ -1,7 +0,0 @@
#include <unistd.h>
#include "buffer.h"
char buffer_1_space[BUFFER_INSIZE];
static buffer it = BUFFER_INIT(write,1,buffer_1_space,sizeof buffer_1_space);
buffer *buffer_1 = &it;

View File

@ -1,7 +0,0 @@
#include <unistd.h>
#include "buffer.h"
char buffer_2_space[BUFFER_INSIZE];
static buffer it = BUFFER_INIT(write,2,buffer_2_space,sizeof buffer_2_space);
buffer *buffer_2 = &it;

View File

@ -1,10 +0,0 @@
#include "buffer.h"
extern int buffer_stubborn(int (*op)(),int fd,const char* buf, unsigned int len);
extern int buffer_flush(buffer* b) {
register int p;
if (!(p=b->p)) return 0; /* buffer already empty */
b->p=0;
return buffer_stubborn(b->op,b->fd,b->x,p);
}

View File

@ -1,17 +0,0 @@
#include "byte.h"
#include "buffer.h"
extern int buffer_stubborn(int (*op)(),int fd,const char* buf, unsigned int len);
int buffer_put(buffer* b,const char* buf,unsigned int len) {
if (len>b->a-b->p) { /* doesn't fit */
if (buffer_flush(b)==-1) return -1;
if (len>b->a) {
if (buffer_stubborn(b->op,b->fd,buf,len)<0) return -1;
return 0;
}
}
byte_copy(b->x+b->p, len, buf);
b->p+=len;
return 0;
}

View File

@ -1,7 +0,0 @@
#include "buffer.h"
int buffer_putflush(buffer* b,const char* x,unsigned int len) {
if (buffer_put(b,x,len)<0) return -1;
if (buffer_flush(b)<0) return -1;
return 0;
}

View File

@ -1,6 +0,0 @@
#include "str.h"
#include "buffer.h"
int buffer_puts(buffer* b,const char* x) {
return buffer_put(b,x,str_len(x));
}

View File

@ -1,7 +0,0 @@
#include "str.h"
#include "buffer.h"
int buffer_putspace(buffer* b) {
static char space=' ';
return buffer_put(b,&space,1);
}

View File

@ -1,8 +0,0 @@
#include "buffer.h"
#include "fmt.h"
int buffer_putulong(buffer *b,unsigned long l) {
char buf[FMT_ULONG];
return buffer_put(b,buf,fmt_ulong(buf,l));
}

View File

@ -1,8 +0,0 @@
#include "buffer.h"
#include "fmt.h"
int buffer_putulonglong(buffer *b,unsigned long long l) {
char buf[FMT_ULONG];
return buffer_put(b,buf,fmt_ulonglong(buf,l));
}

View File

@ -1,15 +0,0 @@
#include <errno.h>
#include "buffer.h"
int buffer_stubborn(int (*op)(),int fd,const char* buf, unsigned int len) {
int w;
while (len) {
if ((w=op(fd,buf,len))<0) {
if (errno == EINTR) continue;
return -1;
};
buf+=w;
len-=w;
}
return 0;
}

38
byte.h
View File

@ -1,38 +0,0 @@
#ifndef BYTE_H
#define BYTE_H
#include <sys/cdefs.h>
#ifndef __pure__
#define __pure__
#endif
/* byte_chr returns the smallest integer i between 0 and len-1
* inclusive such that one[i] equals needle, or len it not found. */
unsigned int byte_chr(const void* haystack, unsigned int 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 int byte_rchr(const void* haystack,unsigned int 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 int 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 int 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 int 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 len);
#define byte_equal(s,n,t) (!byte_diff((s),(n),(t)))
#endif

View File

@ -1,28 +0,0 @@
#include "byte.h"
/* 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 int len, const void* in) {
register char* s=out;
register const char* t=in;
register const char* u=t+len;
if (len>127) {
while ((unsigned long)s&(sizeof(unsigned long)-1)) {
if (t==u) break; *s=*t; ++s; ++t;
}
/* s (destination) is now unsigned long aligned */
#ifndef __i386__
if (!((unsigned long)t&(sizeof(unsigned long)-1)))
#endif
while (t+sizeof(unsigned long)<=u) {
*(unsigned long*)s=*(unsigned long*)t;
s+=sizeof(unsigned long); t+=sizeof(unsigned long);
}
}
for (;;) {
if (t==u) break; *s=*t; ++s; ++t;
if (t==u) break; *s=*t; ++s; ++t;
if (t==u) break; *s=*t; ++s; ++t;
if (t==u) break; *s=*t; ++s; ++t;
}
}

View File

@ -1,21 +0,0 @@
#include "byte.h"
/* byte_diff returns negative, 0, or positive, depending on whether the
* string one[0], one[1], ..., one[len-1] is lexicographically smaller
* 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 int len, const void* b) {
register const char* s=a;
register const char* t=b;
register const char* u=t+len;
register int j;
j=0;
for (;;) {
if (t==u) break; if ((j=(*s-*t))) break; ++s; ++t;
if (t==u) break; if ((j=(*s-*t))) break; ++s; ++t;
if (t==u) break; if ((j=(*s-*t))) break; ++s; ++t;
if (t==u) break; if ((j=(*s-*t))) break; ++s; ++t;
}
return j;
}

View File

@ -1,55 +0,0 @@
#include <stdlib.h>
#include <write12.h>
int main() {
char* method=getenv("REQUEST_METHOD");
if (!method) {
__write1("Content-Type: text/plain\r\n\r\nFatal: $REQUEST_METHOD not set!\n");
return 1;
}
if (!strcmp(method,"GET")) {
char* c=getenv("QUERY_STRING");
__write1("Content-Type: text/plain\r\n\r\n");
if (c)
write(1,c,strlen(c));
else {
__write1("Fatal: $QUERY_STRING not set!\n");
return 1;
}
} else if (!strcmp(method,"POST")) {
char* c=getenv("CONTENT_TYPE");
char* d=getenv("CONTENT_LENGTH");
int l;
if (!c) {
__write1("Content-Type: text/plain\r\n\r\nFatal: $CONTENT_TYPE not set!\n");
return 1;
}
if (!d) {
__write1("Content-Type: text/plain\r\n\r\nFatal: $CONTENT_LENGTH not set!\n");
return 1;
}
{
char* e;
l=strtoul(d,&e,10);
if (e==d || *e) {
__write1("Content-Type: text/plain\r\n\r\nFatal: $CONTENT_LENGTH not a number: ");
__write1(d);
__write1("\n");
return 1;
}
}
__write1("Content-Type: "); __write1(c); __write1("\r\n");
__write1("Content-Length: "); __write1(d); __write1("\r\n\r\n");
while (l>0) {
char buf[2048];
int r;
r=read(0,buf,sizeof(buf));
if (r==-1) return 1;
if (r==0) break;
l-=r;
write(1,buf,r);
}
} else {
puts("Content-Type: text/plain\r\n\r\nFatal: $REQUEST_METHOD is neither GET nor POST!\n");
}
}

Binary file not shown.

View File

@ -1,40 +0,0 @@
#!/usr/bin/perl
use Compress::Zlib;
$PWD=`pwd`;
chomp $PWD;
push @dirs,$PWD;
while ($#dirs>=0) {
my $x=shift @dirs;
opendir DIR,$x || die "can't chdir to $x\n";
foreach $i (readdir DIR) {
next if (substr($i,0,1) eq ".");
if (-d "$x/$i") {
push @dirs,"$x/$i";
} elsif (-f "$x/$i") {
next if ($i =~ m/\.gz$/);
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$x/$i");
my $gzmtime=(stat("$x/$i.gz"))[9];
if (not defined $gzmtime or $gzmtime<$mtime) {
print "gzipping $x/$i...\n";
if ($#ARGV<0) {
open FILE,"$x/$i" || die "can't open $x/$i\n";
my $gz = gzopen("$x/$i.gz","wb")
or die "can't open $x/$i.gz: $gzerrno\n";
while (<FILE>) {
$gz->gzwrite($_)
or die "error writing: $gzerrno\n";
}
$gz->gzclose;
close FILE;
utime $atime, $mtime, "$x/$i.gz" or die "can't utime $x/$i.gz\n";
my $gzsize=(stat("$x/$i.gz"))[7];
unlink "$x/$i.gz" if ($gzsize>=$size);
}
}
}
}
closedir DIR;
}

76
fmt.h
View File

@ -1,76 +0,0 @@
#ifndef FMT_H
#define FMT_H
#include "str.h"
#define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */
#define FMT_8LONG 44 /* enough space to hold 2^128 - 1 in octal, plus \0 */
#define FMT_XLONG 33 /* enough space to hold 2^128 - 1 in hexadecimal, plus \0 */
#define FMT_LEN ((char *) 0) /* convenient abbreviation */
/* The formatting routines do not append \0!
* Use them like this: buf[fmt_ulong(buf,number)]=0; */
/* 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);
/* 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);
/* same for long long */
unsigned int fmt_ulonglong(char *dest,unsigned long 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);
/* 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);
#define fmt_uint(dest,src) fmt_ulong(dest,src)
#define fmt_int(dest,src) fmt_long(dest,src)
#define fmt_xint(dest,src) fmt_xlong(dest,src)
#define fmt_8int(dest,src) fmt_8long(dest,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);
#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);
/* 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);
/* if src is negative, write '-' and return 1.
* otherwise return 0. */
unsigned int fmt_minus(char *dest,int src);
/* copy str to dest until \0 byte, return number of copied bytes. */
unsigned int fmt_str(char *dest,const char *src);
/* copy str to dest until \0 byte or limit bytes copied.
* return number of copied bytes. */
unsigned int fmt_strn(char *dest,const char *src,unsigned int 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 int fmt_pad(char* dest,const char* src,unsigned int srclen,unsigned int padlen,unsigned int 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 int fmt_fill(char* dest,unsigned int srclen,unsigned int padlen,unsigned int maxlen);
#endif

View File

@ -1,11 +0,0 @@
#include "fmt.h"
unsigned int 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;
if (dest)
for (tmp=i, dest+=len, len2=len+1; --len2; tmp/=10)
*--dest = (tmp%10)+'0';
return len;
}

View File

@ -1,12 +0,0 @@
#include "fmt.h"
unsigned int fmt_ulonglong(char *dest,unsigned long long i) {
register unsigned long len,len2;
register unsigned long long tmp;
/* first count the number of bytes needed */
for (len=1, tmp=i; tmp>9; ++len) tmp/=10;
if (dest)
for (tmp=i, dest+=len, len2=len+1; --len2; tmp/=10)
*--dest = (tmp%10)+'0';
return len;
}

View File

@ -1,33 +0,0 @@
#!/bin/sh
set -e
acct=$1
logacct=$2
dir=$3
webroot=$4
myip=$5
if test x$webroot = x; then
echo "fnord-conf: usage: fnord-conf acct logacct /fnord /webroot [ myip ]"
exit 1;
fi
# install stuff
mkdir -p $dir
echo "#!/bin/sh" > $dir/run
echo "cd $webroot" >> $dir/run
echo "exec envuidgid $acct tcpserver -RHl localhost ${myip:-0} 80 fnord 2>&1" >> $dir/run
chmod 755 $dir/run
# tell old daemontools that it should spawn a log process, too
chmod a+t $dir
# install logging stuff
mkdir $dir/log
echo "#!/bin/sh" > $dir/log/run
echo "exec setuidgid $logacct multilog t ./main" >> $dir/log/run
chmod 755 $dir/log/run
mkdir $dir/log/main
chown $logacct $dir/log/main

View File

2
http
View File

@ -1,2 +0,0 @@
#!/bin/sh
tcpserver -RHl localhost 0 80 fnord-idx .

61
scan.h
View File

@ -1,61 +0,0 @@
#ifndef SCAN_H
#define SCAN_H
#include <sys/cdefs.h>
#ifndef __pure__
#define __pure__
#endif
/* interpret src as ASCII decimal number, write number to dest and
* return the number of bytes that were parsed */
extern unsigned int scan_ulong(const char *src,unsigned long *dest);
/* same, for long long */
extern unsigned int scan_ulonglong(const char *src,unsigned long long *dest);
/* interpret src as ASCII hexadecimal number, write number to dest and
* return the number of bytes that were parsed */
extern unsigned int scan_xlong(const char *src,unsigned long *dest);
/* interpret src as ASCII octal number, write number to dest and
* return the number of bytes that were parsed */
extern unsigned int scan_8long(const char *src,unsigned long *dest);
/* interpret src as signed ASCII decimal number, write number to dest
* and return the number of bytes that were parsed */
extern unsigned int scan_long(const char *src,signed long *dest);
extern unsigned int scan_uint(const char *src,unsigned int *dest);
extern unsigned int scan_xint(const char *src,unsigned int *dest);
extern unsigned int scan_8int(const char *src,unsigned int *dest);
extern unsigned int scan_int(const char *src,signed int *dest);
extern unsigned int scan_ushort(const char *src,unsigned short *dest);
extern unsigned int scan_xshort(const char *src,unsigned short *dest);
extern unsigned int scan_8short(const char *src,unsigned short *dest);
extern unsigned int scan_short(const char *src,signed short *dest);
/* interpret src as double precision floating point number,
* write number to dest and return the number of bytes that were parsed */
extern unsigned int scan_double(const char *in, double *dest);
/* if *src=='-', set *dest to -1 and return 1.
* if *src=='+', set *dest to 1 and return 1.
* otherwise set *dest to 1 return 0. */
extern unsigned int scan_plusminus(const char *src,signed int *dest);
/* return the highest integer n<=limit so that isspace(in[i]) for all 0<=i<=n */
extern unsigned int scan_whitenskip(const char *in,unsigned int limit) __pure__;
/* return the highest integer n<=limit so that !isspace(in[i]) for all 0<=i<=n */
extern unsigned int scan_nonwhitenskip(const char *in,unsigned int limit) __pure__;
/* return the highest integer n<=limit so that in[i] is element of
* charset (ASCIIZ string) for all 0<=i<=n */
extern unsigned int scan_charsetnskip(const char *in,const char *charset,unsigned int limit) __pure__;
/* return the highest integer n<=limit so that in[i] is not element of
* charset (ASCIIZ string) for all 0<=i<=n */
extern unsigned int scan_noncharsetnskip(const char *in,const char *charset,unsigned int limit) __pure__;
#endif

View File

@ -1,13 +0,0 @@
#include "scan.h"
unsigned int scan_ulong(const char *src,unsigned long *dest) {
register const char *tmp=src;
register int l=0;
register unsigned char c;
while ((c=*tmp-'0')<10) {
l=l*10+c;
++tmp;
}
*dest=l;
return tmp-src;
}

View File

@ -1,13 +0,0 @@
#include "scan.h"
unsigned int scan_ulonglong(const char *src,unsigned long long *dest) {
register const char *tmp=src;
register unsigned long long int l=0;
register unsigned char c;
while ((c=*tmp-'0')<10) {
l=l*10+c;
++tmp;
}
*dest=l;
return tmp-src;
}

43
str.h
View File

@ -1,43 +0,0 @@
#ifndef STR_H
#define STR_H
#include <sys/cdefs.h>
#ifndef __pure__
#define __pure__
#endif
/* str_copy copies leading bytes from in to out until \0.
* return number of copied bytes. */
extern unsigned int str_copy(char *out,const char *in);
/* str_diff returns negative, 0, or positive, depending on whether the
* string a[0], a[1], ..., a[n]=='\0' is lexicographically smaller than,
* equal to, or greater than the string b[0], b[1], ..., b[m-1]=='\0'.
* If the strings are different, str_diff does not read bytes past the
* first difference. */
extern int str_diff(const char *a,const char *b) __pure__;
/* str_diffn returns negative, 0, or positive, depending on whether the
* string a[0], a[1], ..., a[n]=='\0' is lexicographically smaller than,
* equal to, or greater than the string b[0], b[1], ..., b[m-1]=='\0'.
* If the strings are different, str_diffn does not read bytes past the
* first difference. The strings will be considered equal if the first
* limit characters match. */
extern int str_diffn(const char *a,const char *b,unsigned int limit) __pure__;
/* str_len returns the index of \0 in s */
extern unsigned int str_len(const char *s) __pure__;
/* str_chr returns the index of the first occurance of needle or \0 in haystack */
extern unsigned int str_chr(const char *haystack,char needle) __pure__;
/* str_rchr returns the index of the last occurance of needle or \0 in haystack */
extern unsigned int str_rchr(const char *haystack,char needle) __pure__;
/* str_start returns 1 if the b is a prefix of a, 0 otherwise */
extern int str_start(const char *a,const char *b) __pure__;
/* convenience shortcut to test for string equality */
#define str_equal(s,t) (!str_diff((s),(t)))
#endif

View File

@ -1,13 +0,0 @@
#include "str.h"
unsigned int str_chr(const char *in, char needle) {
register const char* t=in;
register const char c=needle;
for (;;) {
if (!*t || *t==c) break; ++t;
if (!*t || *t==c) break; ++t;
if (!*t || *t==c) break; ++t;
if (!*t || *t==c) break; ++t;
}
return t-in;
}

View File

@ -1,13 +0,0 @@
#include "str.h"
unsigned int str_copy(char *out,const char *in) {
register char* s=out;
register const char* t=in;
for (;;) {
if (!(*s=*t)) break; ++s; ++t;
if (!(*s=*t)) break; ++s; ++t;
if (!(*s=*t)) break; ++s; ++t;
if (!(*s=*t)) break; ++s; ++t;
}
return s-out;
}

View File

@ -1,20 +0,0 @@
#include "byte.h"
/* str_diff returns negative, 0, or positive, depending on whether the
* string a[0], a[1], ..., a[n]=='\0' is lexicographically smaller than,
* equal to, or greater than the string b[0], b[1], ..., b[m-1]=='\0'.
* When the strings are different, str_diff does not read bytes past the
* first difference. */
int str_diff(const char* a, const char* b) {
register const char* s=a;
register const char* t=b;
register int j;
j=0;
for (;;) {
if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t;
if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t;
if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t;
if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t;
}
return j;
}

View File

@ -1,21 +0,0 @@
#include "byte.h"
/* str_diff returns negative, 0, or positive, depending on whether the
* string a[0], a[1], ..., a[n]=='\0' is lexicographically smaller than,
* equal to, or greater than the string b[0], b[1], ..., b[m-1]=='\0'.
* When the strings are different, str_diff does not read bytes past the
* first difference. */
int str_diffn(const char* a, const char* b, unsigned int limit) {
register const char* s=a;
register const char* t=b;
register const char* u=t+limit;
register int j;
j=0;
for (;;) {
if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t;
if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t;
if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t;
if (t>=u) break; if ((j=(*s-*t))) break; if (!*t) break; ++s; ++t;
}
return j;
}

View File

@ -1,12 +0,0 @@
#include "str.h"
unsigned int str_len(const char *in) {
register const char* t=in;
for (;;) {
if (!*t) break; ++t;
if (!*t) break; ++t;
if (!*t) break; ++t;
if (!*t) break; ++t;
}
return t-in;
}

View File

@ -1,14 +0,0 @@
#include "str.h"
int str_start (register const char *s, register const char *t)
{
register char x ;
for (;;)
{
x = *t++; if (!x) return 1; if (x != *s++) return 0;
x = *t++; if (!x) return 1; if (x != *s++) return 0;
x = *t++; if (!x) return 1; if (x != *s++) return 0;
x = *t++; if (!x) return 1; if (x != *s++) return 0;
}
}