
58 changed files with 238 additions and 160 deletions
-
1.cvsignore
-
16buffer.h
-
17buffer/buffer_close.c
-
10buffer/buffer_feed.c
-
9buffer/buffer_flush.c
-
6buffer/buffer_free.c
-
2buffer/buffer_frombuf.c
-
2buffer/buffer_get.3
-
15buffer/buffer_get.c
-
5buffer/buffer_get_token.c
-
2buffer/buffer_get_token_pred.c
-
4buffer/buffer_getc.c
-
3buffer/buffer_getn.c
-
2buffer/buffer_init.c
-
2buffer/buffer_init_free.c
-
2buffer/buffer_mmapread.c
-
15buffer/buffer_munmap.c
-
2buffer/buffer_putalign.c
-
4buffer/buffer_stubborn.c
-
4buffer/buffer_stubborn2.c
-
3buffer/buffer_tosa.c
-
2dns.h
-
2dns/dns_dfd.c
-
10dns/dns_dtda.c
-
2dns/dns_rcrw.c
-
4ip4.h
-
16ip6.h
-
4mmap/mmap_private.c
-
4mmap/mmap_read.c
-
4mmap/mmap_shared.c
-
2open/openreadclose.3
-
8open/readclose.c
-
2open/readclose_append.3
-
7readclose.h
-
2scan/scan_double.c
-
7socket/fmt_ip4.c
-
5socket/fmt_ip6.c
-
11socket/fmt_ip6_flat.c
-
2socket/fmt_ip6c.c
-
4socket/fmt_ip6if.c
-
11socket/scan_ip4.c
-
16socket/scan_ip6.c
-
12socket/scan_ip6_flat.c
-
6socket/scan_ip6if.c
-
2socket/socket_listen.c
-
9stralloc.h
-
8stralloc/stralloc_catlong0.c
-
4t.c
-
16tai/tai_pack.c
-
4taia/taia_add.c
-
2taia/taia_addsec.c
-
4taia/taia_half.c
-
2taia/taia_now.c
-
18taia/taia_pack.c
-
8taia/taia_sub.c
-
2taia/taia_unpack.c
-
48test/marshal.c
-
2unix/iopause.c
@ -1,22 +1,7 @@ |
|||
#include <buffer.h> |
|||
#include <stdlib.h> |
|||
#include <unistd.h> |
|||
#ifdef __MINGW32__ |
|||
#include <windows.h> |
|||
#else |
|||
#include <sys/mman.h> |
|||
#endif |
|||
|
|||
void buffer_close(buffer* b) { |
|||
if (b->fd != -1) close(b->fd); |
|||
switch (b->todo) { |
|||
case FREE: free(b->x); break; |
|||
case MUNMAP: |
|||
#ifdef __MINGW32__ |
|||
UnmapViewOfFile(b->x); |
|||
#else |
|||
munmap(b->x,b->a); break; |
|||
#endif |
|||
default: ; |
|||
} |
|||
if (b->deinit) b->deinit(b); |
|||
} |
@ -1,14 +1,14 @@ |
|||
#include "buffer.h" |
|||
|
|||
extern int buffer_stubborn_read(ssize_t (*op)(),int fd,const char* buf, size_t len,void* cookie); |
|||
extern ssize_t buffer_stubborn_read(ssize_t (*op)(),int fd,const char* buf, size_t len,void* cookie); |
|||
|
|||
int buffer_feed(buffer* b) { |
|||
ssize_t buffer_feed(buffer* b) { |
|||
if (b->p==b->n) { |
|||
int w; |
|||
ssize_t w; |
|||
if ((w=buffer_stubborn_read(b->op,b->fd,b->x,b->a,b))<0) |
|||
return -1; |
|||
b->n=w; |
|||
b->n=(size_t)w; |
|||
b->p=0; |
|||
} |
|||
return (b->n-b->p); |
|||
return (ssize_t)(b->n-b->p); |
|||
} |
@ -1,10 +1,13 @@ |
|||
#include "buffer.h" |
|||
|
|||
extern int buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t len,void* cookie); |
|||
extern ssize_t buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t len,void* cookie); |
|||
|
|||
extern int buffer_flush(buffer* b) { |
|||
register int p; |
|||
register size_t p; |
|||
register ssize_t r; |
|||
if (!(p=b->p)) return 0; /* buffer already empty */ |
|||
b->p=0; |
|||
return buffer_stubborn(b->op,b->fd,b->x,p,b); |
|||
r=buffer_stubborn(b->op,b->fd,b->x,p,b); |
|||
if (r>0) r=0; |
|||
return (int)r; |
|||
} |
@ -0,0 +1,6 @@ |
|||
#include <stdlib.h> |
|||
#include "buffer.h" |
|||
|
|||
void buffer_free(void* buf) { |
|||
free(buf); |
|||
} |
@ -0,0 +1,15 @@ |
|||
#include "buffer.h" |
|||
#ifdef __MINGW32__ |
|||
#include <windows.h> |
|||
#else |
|||
#include <sys/mman.h> |
|||
#endif |
|||
|
|||
void buffer_munmap(void* buf) { |
|||
buffer* b=(buffer*)buf; |
|||
#ifdef __MINGW32__ |
|||
UnmapViewOfFile(b->x); |
|||
#else |
|||
munmap(b->x,b->a); |
|||
#endif |
|||
} |
@ -1,17 +1,14 @@ |
|||
#include "ip6.h" |
|||
#include "haveinline.h" |
|||
#include "fmt.h" |
|||
|
|||
static inline char tohex(char c) { |
|||
return c>=10?c-10+'a':c+'0'; |
|||
} |
|||
|
|||
unsigned int fmt_ip6_flat(char *s,const char ip[16]) |
|||
size_t fmt_ip6_flat(char *s,const char ip[16]) |
|||
{ |
|||
int i; |
|||
if (!s) return 32; |
|||
for (i=0; i<16; i++) { |
|||
*s++=tohex((unsigned char)ip[i] >> 4); |
|||
*s++=tohex((unsigned char)ip[i] & 15); |
|||
*s++=fmt_tohex((char)((unsigned char)ip[i] >> 4)); |
|||
*s++=fmt_tohex((unsigned char)ip[i] & 15); |
|||
} |
|||
return 32; |
|||
} |
@ -1,18 +1,17 @@ |
|||
#include "scan.h" |
|||
#include "ip4.h" |
|||
|
|||
unsigned int scan_ip4(const char *s,char ip[4]) |
|||
size_t scan_ip4(const char *s,char ip[4]) |
|||
{ |
|||
unsigned int len; |
|||
size_t i,len; |
|||
unsigned long u; |
|||
int i; |
|||
|
|||
len = 0; |
|||
for (i=0; i<4; ++i) { |
|||
register unsigned int j; |
|||
register size_t j; |
|||
len+=(j=scan_ulong(s,&u))+1; |
|||
if (!j) return 0; |
|||
ip[i]=u; s+=j; |
|||
if (!j || u>255) return 0; |
|||
ip[i]=(char)u; s+=j; |
|||
if (i<3 && *s!='.') return 0; ++s; |
|||
} |
|||
return len-1; |
|||
|
@ -1,16 +1,16 @@ |
|||
#include "scan.h" |
|||
|
|||
unsigned int scan_ip6_flat(const char *s,char ip[16]) |
|||
size_t scan_ip6_flat(const char *s,char ip[16]) |
|||
{ |
|||
int i; |
|||
size_t i; |
|||
for (i=0; i<16; i++) { |
|||
int tmp; |
|||
tmp=scan_fromhex(*s++); |
|||
tmp=scan_fromhex((unsigned char)*s++); |
|||
if (tmp<0) return 0; |
|||
ip[i]=tmp << 4; |
|||
tmp=scan_fromhex(*s++); |
|||
ip[i]=(char)(tmp << 4); |
|||
tmp=scan_fromhex((unsigned char)*s++); |
|||
if (tmp<0) return 0; |
|||
ip[i]+=tmp; |
|||
ip[i] = ip[i] | (char)tmp; |
|||
} |
|||
return 32; |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue