--- /386/include/ape/inttypes.h Sat Jan 4 00:00:00 2014 +++ /386/include/ape/inttypes.h Sat Jan 4 00:00:00 2014 @@ -0,0 +1,21 @@ +#ifndef _SUSV2_SOURCE +#error "inttypes.h is SUSV2" +#endif + +#ifndef _INTTYPES_H_ +#define _INTTYPES_H_ 1 + + +typedef char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef long intptr_t; +typedef unsigned long uintptr_t; + +#endif --- /amd64/include/ape/inttypes.h Sat Jan 4 00:00:00 2014 +++ /amd64/include/ape/inttypes.h Sat Jan 4 00:00:00 2014 @@ -0,0 +1,21 @@ +#ifndef _SUSV2_SOURCE +#error "inttypes.h is SUSV2" +#endif + +#ifndef _INTTYPES_H_ +#define _INTTYPES_H_ 1 + + +typedef char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef long long intptr_t; +typedef unsigned long long uintptr_t; + +#endif --- /mips/include/ape/inttypes.h Sat Jan 4 00:00:00 2014 +++ /mips/include/ape/inttypes.h Sat Jan 4 00:00:00 2014 @@ -0,0 +1,21 @@ +#ifndef _SUSV2_SOURCE +#error "inttypes.h is SUSV2" +#endif + +#ifndef _INTTYPES_H_ +#define _INTTYPES_H_ 1 + + +typedef char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef long intptr_t; +typedef unsigned long uintptr_t; + +#endif --- /power/include/ape/inttypes.h Sat Jan 4 00:00:00 2014 +++ /power/include/ape/inttypes.h Sat Jan 4 00:00:00 2014 @@ -0,0 +1,21 @@ +#ifndef _SUSV2_SOURCE +#error "inttypes.h is SUSV2" +#endif + +#ifndef _INTTYPES_H_ +#define _INTTYPES_H_ 1 + + +typedef char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef long intptr_t; +typedef unsigned long uintptr_t; + +#endif --- /sparc/include/ape/inttypes.h Sat Jan 4 00:00:00 2014 +++ /sparc/include/ape/inttypes.h Sat Jan 4 00:00:00 2014 @@ -0,0 +1,21 @@ +#ifndef _SUSV2_SOURCE +#error "inttypes.h is SUSV2" +#endif + +#ifndef _INTTYPES_H_ +#define _INTTYPES_H_ 1 + + +typedef char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef long intptr_t; +typedef unsigned long uintptr_t; + +#endif diff -Nru /n/sources/plan9/sys/include/ape/arpa/inet.h /sys/include/ape/arpa/inet.h --- /n/sources/plan9/sys/include/ape/arpa/inet.h Sat Dec 11 00:00:00 1999 +++ /sys/include/ape/arpa/inet.h Sat Jan 4 00:00:00 2014 @@ -97,6 +97,7 @@ #define INADDR_ANY (unsigned long)0x00000000 #define INADDR_BROADCAST (unsigned long)0xffffffff /* must be masked */ +#define INADDR_NONE (unsigned long)0xffffffff /* -1 return */ #define IN_LOOPBACKNET 127 /* official! */ @@ -110,6 +111,27 @@ char sin_zero[8]; }; +#define INET_ADDRSTRLEN 16 + +struct in6_addr { + unsigned char s6_addr[16]; +}; + +struct sockaddr_in6 { + int sin6_family; + short sin6_port; + unsigned int sin6_flowinfo; /* uint32_t */ + struct in6_addr sin6_addr; + unsigned int sin6_scope_id; /* uint32_t */ +}; + +#define IN6ADDR_ANY_INIT {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } +#define IN6ADDR_LOOPBACK_INIT {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, } +#define INET6_ADDRSTRLEN 46 + +extern const struct in6_addr in6addr_any; +extern const struct in6_addr in6addr_loopback; + /* * Structure used to describe IP options. * Used to store options internally, to pass them to a process, @@ -138,6 +160,10 @@ extern unsigned long inet_addr(char*); extern char* inet_ntoa(struct in_addr); extern unsigned long nptohl(void*); + +/* _SUSV2_SOURCE ? */ +const char* inet_ntop(int, const void*, char*, int); +int inet_pton(int, const char*, void*); #ifdef __cplusplus } diff -Nru /n/sources/plan9/sys/include/ape/auth.h /sys/include/ape/auth.h --- /n/sources/plan9/sys/include/ape/auth.h Thu Jan 1 00:00:00 1970 +++ /sys/include/ape/auth.h Tue May 14 00:00:00 2013 @@ -0,0 +1,151 @@ +#ifndef _PLAN9_SOURCE + This header file is an extension to ANSI/POSIX +#endif + +#ifndef __AUTH_H_ +#define __AUTH_H_ +#pragma src "/sys/src/ape/lib/auth" +#pragma lib "/$M/lib/ape/libauth.a" + +/* + * Interface for typical callers. + */ + +typedef struct AuthInfo AuthInfo; +typedef struct Chalstate Chalstate; +typedef struct Chapreply Chapreply; +typedef struct MSchapreply MSchapreply; +typedef struct UserPasswd UserPasswd; +typedef struct AuthRpc AuthRpc; + +enum +{ + MAXCHLEN= 256, /* max challenge length */ + MAXNAMELEN= 256, /* maximum name length */ + MD5LEN= 16, + + ARok = 0, /* rpc return values */ + ARdone, + ARerror, + ARneedkey, + ARbadkey, + ARwritenext, + ARtoosmall, + ARtoobig, + ARrpcfailure, + ARphase, + + AuthRpcMax = 4096, +}; + +struct AuthRpc +{ + int afd; + char ibuf[AuthRpcMax+1]; + char obuf[AuthRpcMax]; + char *arg; + uint narg; +}; + +struct AuthInfo +{ + char *cuid; /* caller id */ + char *suid; /* server id */ + char *cap; /* capability (only valid on server side) */ + int nsecret; /* length of secret */ + uchar *secret; /* secret */ +}; + +struct Chalstate +{ + char *user; + char chal[MAXCHLEN]; + int nchal; + void *resp; + int nresp; + +/* for implementation only */ + int afd; /* to factotum */ + AuthRpc *rpc; /* to factotum */ + char userbuf[MAXNAMELEN]; /* temp space if needed */ + int userinchal; /* user was sent to obtain challenge */ +}; + +struct Chapreply /* for protocol "chap" */ +{ + uchar id; + char resp[MD5LEN]; +}; + +struct MSchapreply /* for protocol "mschap" */ +{ + char LMresp[24]; /* Lan Manager response */ + char NTresp[24]; /* NT response */ +}; + +struct UserPasswd +{ + char *user; + char *passwd; +}; + +extern int newns(char*, char*); +extern int addns(char*, char*); + +extern int noworld(char*); +extern int amount(int, char*, int, char*); + +/* these two may get generalized away -rsc */ +extern int login(char*, char*, char*); +extern int httpauth(char*, char*); + +typedef struct Attr Attr; +enum { + AttrNameval, /* name=val -- when matching, must have name=val */ + AttrQuery, /* name? -- when matching, must be present */ + AttrDefault, /* name:=val -- when matching, if present must match INTERNAL */ +}; +struct Attr +{ + int type; + Attr *next; + char *name; + char *val; +}; + +typedef int AuthGetkey(char*); + +int _attrfmt(Fmt*); +Attr *_copyattr(Attr*); +Attr *_delattr(Attr*, char*); +Attr *_findattr(Attr*, char*); +void _freeattr(Attr*); +Attr *_mkattr(int, char*, char*, Attr*); +Attr *_parseattr(char*); +char *_strfindattr(Attr*, char*); +#pragma varargck type "A" Attr* + +extern AuthInfo* fauth_proxy(int, AuthRpc *rpc, AuthGetkey *getkey, char *params); +extern AuthInfo* auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...); +extern int auth_getkey(char*); +extern int (*amount_getkey)(char*); +extern void auth_freeAI(AuthInfo *ai); +extern int auth_chuid(AuthInfo *ai, char *ns); +extern Chalstate *auth_challenge(char*, ...); +extern AuthInfo* auth_response(Chalstate*); +extern int auth_respond(void*, uint, char*, uint, void*, uint, AuthGetkey *getkey, char*, ...); +extern void auth_freechal(Chalstate*); +extern AuthInfo* auth_userpasswd(char *user, char *passwd); +extern UserPasswd* auth_getuserpasswd(AuthGetkey *getkey, char*, ...); +extern AuthInfo* auth_getinfo(AuthRpc *rpc); +extern AuthRpc* auth_allocrpc(int afd); +extern Attr* auth_attr(AuthRpc *rpc); +extern void auth_freerpc(AuthRpc *rpc); +extern uint auth_rpc(AuthRpc *rpc, char *verb, void *a, int n); +extern int auth_wep(char*, char*, ...); +#pragma varargck argpos auth_proxy 3 +#pragma varargck argpos auth_challenge 1 +#pragma varargck argpos auth_respond 8 +#pragma varargck argpos auth_getuserpasswd 2 + +#endif diff -Nru /n/sources/plan9/sys/include/ape/bio.h /sys/include/ape/bio.h --- /n/sources/plan9/sys/include/ape/bio.h Thu Jan 1 00:00:00 1970 +++ /sys/include/ape/bio.h Tue May 28 00:00:00 2013 @@ -0,0 +1,82 @@ +#ifndef _PLAN9_SOURCE + This header file is an extension to ANSI/POSIX +#endif + +#ifndef __BIO_H_ +#define __BIO_H_ +#pragma src "/sys/src/libbio" +#pragma lib "/$M/lib/ape/libbio.a" + +typedef struct Biobuf Biobuf; +typedef struct Biobufhdr Biobufhdr; + +enum +{ + Bsize = 8*1024, + Bungetsize = 4, /* space for ungetc */ + Bmagic = 0x314159, + Beof = -1, + Bbad = -2, + + Binactive = 0, /* states */ + Bractive, + Bwactive, + Bracteof, +}; + +struct Biobufhdr +{ + int icount; /* neg num of bytes at eob */ + int ocount; /* num of bytes at bob */ + int rdline; /* num of bytes after rdline */ + int runesize; /* num of bytes of last getrune */ + int state; /* r/w/inactive */ + int fid; /* open file */ + int flag; /* magic if malloc'ed */ + vlong offset; /* offset of buffer in file */ + int bsize; /* size of buffer */ + uchar* bbuf; /* pointer to beginning of buffer */ + uchar* ebuf; /* pointer to end of buffer */ + uchar* gbuf; /* pointer to good data in buf */ +}; + +struct Biobuf +{ + Biobufhdr; + uchar b[Bungetsize+Bsize]; +}; + +/* Dregs, redefined as functions for backwards compatibility */ +#define BGETC(bp) Bgetc(bp) +#define BPUTC(bp,c) Bputc(bp,c) +#define BOFFSET(bp) Boffset(bp) +#define BLINELEN(bp) Blinelen(bp) +#define BFILDES(bp) Bfildes(bp) + +int Bbuffered(Biobufhdr*); +int Bfildes(Biobufhdr*); +int Bflush(Biobufhdr*); +int Bgetc(Biobufhdr*); +//int Bgetd(Biobufhdr*, double*); +long Bgetrune(Biobufhdr*); +int Binit(Biobuf*, int, int); +int Binits(Biobufhdr*, int, int, uchar*, int); +int Blinelen(Biobufhdr*); +vlong Boffset(Biobufhdr*); +Biobuf* Bopen(char*, int); +int Bprint(Biobufhdr*, char*, ...); +int Bvprint(Biobufhdr*, char*, va_list); +int Bputc(Biobufhdr*, int); +int Bputrune(Biobufhdr*, long); +void* Brdline(Biobufhdr*, int); +char* Brdstr(Biobufhdr*, int, int); +long Bread(Biobufhdr*, void*, long); +vlong Bseek(Biobufhdr*, vlong, int); +int Bterm(Biobufhdr*); +int Bungetc(Biobufhdr*); +int Bungetrune(Biobufhdr*); +long Bwrite(Biobufhdr*, void*, long); + +#pragma varargck argpos Bprint 2 + +#endif diff -Nru /n/sources/plan9/sys/include/ape/errno.h /sys/include/ape/errno.h --- /n/sources/plan9/sys/include/ape/errno.h Thu Feb 28 00:00:00 2013 +++ /sys/include/ape/errno.h Sat Jan 4 00:00:00 2014 @@ -81,6 +81,10 @@ /* from research unix */ #define ETXTBSY 63 +/* Added in more recent 1003.x versions */ +#define EALREADY 64 +#define ECONNRESET 65 + #endif /* _POSIX_SOURCE */ #endif /* __ERRNO */ diff -Nru /n/sources/plan9/sys/include/ape/inttypes.h /sys/include/ape/inttypes.h --- /n/sources/plan9/sys/include/ape/inttypes.h Mon Nov 25 00:00:00 2002 +++ /sys/include/ape/inttypes.h Thu Jan 1 00:00:00 1970 @@ -1,23 +0,0 @@ -#ifndef _SUSV2_SOURCE -#error "inttypes.h is SUSV2" -#endif - -#ifndef _INTTYPES_H_ -#define _INTTYPES_H_ 1 - -typedef int _intptr_t; -typedef unsigned int _uintptr_t; - - -typedef char int8_t; -typedef short int16_t; -typedef int int32_t; -typedef long long int64_t; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; -typedef _intptr_t intptr_t; -typedef _uintptr_t uintptr_t; - -#endif diff -Nru /n/sources/plan9/sys/include/ape/lib9.h /sys/include/ape/lib9.h --- /n/sources/plan9/sys/include/ape/lib9.h Sat Mar 15 00:00:00 2008 +++ /sys/include/ape/lib9.h Sat Jan 4 00:00:00 2014 @@ -60,16 +60,17 @@ #define ARGC() _argc extern int errstr(char*, unsigned int); -extern int bind(char*, char*, int); +extern int _BIND(const char*, const char*, int); +#define bind(name, old, flag) _BIND(name, old, flag) extern int mount(int, int, char*, int, char*); extern int unmount(char*, char*); extern int rfork(int); -extern int segattach(int, char*, void*, unsigned long); -extern int segbrk(void*, void*); +extern void* segattach(int, char*, void*, unsigned long); +extern void* segbrk(void*, void*); extern int segdetach(void*); extern int segflush(void*, unsigned long); extern int segfree(void*, unsigned long); -extern unsigned long rendezvous(unsigned long, unsigned long); +extern void* rendezvous(void*, void*); extern unsigned long getfcr(void); extern unsigned long getfsr(void); extern void setfcr(unsigned long); diff -Nru /n/sources/plan9/sys/include/ape/netdb.h /sys/include/ape/netdb.h --- /n/sources/plan9/sys/include/ape/netdb.h Thu Feb 28 00:00:00 2002 +++ /sys/include/ape/netdb.h Sat Jan 4 00:00:00 2014 @@ -114,6 +114,77 @@ #define __HOST_SVC_NOT_AVAIL 99 /* libc internal use only */ +enum { + AI_PASSIVE = 0x01, + AI_CANONNAME = 0x02, + AI_NUMERICHOST = 0x04, /* ignored */ + AI_V4MAPPED = 0x08, + AI_ALL = 0x10, /* ignored */ + AI_ADDRCONFIG = 0x20, /* ignored */ + AI_NUMERICSERV = 0x400, +}; + +#define AI_PASSIVE AI_PASSIVE +#define AI_CANONNAME AI_CANONNAME +#define AI_NUMERICHOST AI_NUMERICHOST +#define AI_V4MAPPED AI_V4MAPPED +#define AI_ALL AI_ALL +#define AI_ADDRCONFIG AI_ADDRCONFIG +#define AI_NUMERICSERV AI_NUMERICSERV + +enum { + EAI_BADFLAGS = -1, + EAI_NONAME = -2, + EAI_AGAIN = -3, + EAI_FAIL = -4, + EAI_FAMILY = -6, + EAI_SOCKTYPE = -7, + EAI_SERVICE = -8, + EAI_MEMORY = -10, + EAI_SYSTEM = -11, + EAI_OVERFLOW = -12, +}; +#define EAI_BADFLAGS EAI_BADFLAGS +#define EAI_NONAME EAI_NONAME +#define EAI_AGAIN EAI_AGAIN +#define EAI_FAIL EAI_FAIL +#define EAI_FAMILY EAI_FAMILY +#define EAI_SOCKTYPE EAI_SOCKTYPE +#define EAI_SERVICE EAI_SERVICE +#define EAI_MEMORY EAI_MEMORY +#define EAI_SYSTEM EAI_SYSTEM +#define EAI_OVERFLOW EAI_OVERFLOW + +enum { + NI_NUMERICHOST = 1<<0, + NI_NUMERICSERV = 1<<1, + NI_NOFQDN = 1<<2, + NI_NAMEREQD = 1<<3, + NI_DGRAM = 1<<4, +}; +#define NI_NUMERICHOST NI_NUMERICHOST +#define NI_NUMERICSERV NI_NUMERICSERV +#define NI_NOFQDN NI_NOFQDN +#define NI_NAMEREQD NI_NAMEREQD +#define NI_DGRAM NI_DGRAM + +struct addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + int ai_addrlen; + struct sockaddr *ai_addr; + char *ai_canonname; + struct addrinfo *ai_next; +}; + +/* _SUSV2_SOURCE? */ +int getaddrinfo(const char*, const char*, const struct addrinfo*, struct addrinfo**); +void freeaddrinfo(struct addrinfo *); +int getnameinfo(const struct sockaddr *, int, char*, long, char*, long, int); +const char* gai_strerror(int); + #ifdef __cplusplus } #endif diff -Nru /n/sources/plan9/sys/include/ape/netinet/in.h /sys/include/ape/netinet/in.h --- /n/sources/plan9/sys/include/ape/netinet/in.h Sat Jul 14 00:00:00 2007 +++ /sys/include/ape/netinet/in.h Sat Jan 4 00:00:00 2014 @@ -111,6 +111,27 @@ char sin_zero[8]; }; +#define INET_ADDRSTRLEN 16 + +struct in6_addr { + unsigned char s6_addr[16]; +}; + +struct sockaddr_in6 { + int sin6_family; + short sin6_port; + unsigned int sin6_flowinfo; /* uint32_t */ + struct in6_addr sin6_addr; + unsigned int sin6_scope_id; /* uint32_t */ +}; + +#define IN6ADDR_ANY_INIT {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } +#define IN6ADDR_LOOPBACK_INIT {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, } +#define INET6_ADDRSTRLEN 46 + +extern const struct in6_addr in6addr_any; +extern const struct in6_addr in6addr_loopback; + /* * Structure used to describe IP options. * Used to store options internally, to pass them to a process, @@ -139,6 +160,10 @@ extern unsigned long inet_addr(char*); extern char* inet_ntoa(struct in_addr); extern unsigned long nptohl(void*); + +/* _SUSV2_SOURCE ? */ +const char* inet_ntop(int, const void*, char*, int); +int inet_pton(int, const char*, void*); #ifdef __cplusplus } diff -Nru /n/sources/plan9/sys/include/ape/regexp.h /sys/include/ape/regexp.h --- /n/sources/plan9/sys/include/ape/regexp.h Wed Apr 25 00:00:00 2001 +++ /sys/include/ape/regexp.h Tue Oct 27 00:00:00 2009 @@ -35,9 +35,16 @@ /* * character class, each pair of rune's defines a range */ +enum{ + NCCRUNE = 256, + NCLASS = 16, + NINST = 5, + +}; + struct Reclass{ wchar_t *end; - wchar_t spans[64]; + wchar_t spans[NCCRUNE]; }; /* @@ -62,8 +69,8 @@ */ struct Reprog{ Reinst *startinst; /* start pc */ - Reclass class[16]; /* .data */ - Reinst firstinst[5]; /* .text */ + Reclass class[NCLASS]; /* .data */ + Reinst firstinst[NINST]; /* .text */ }; extern Reprog *regcomp(char*); diff -Nru /n/sources/plan9/sys/include/ape/signal.h /sys/include/ape/signal.h --- /n/sources/plan9/sys/include/ape/signal.h Sat Dec 11 00:00:00 1999 +++ /sys/include/ape/signal.h Tue May 28 00:00:00 2013 @@ -46,7 +46,7 @@ extern "C" { #endif -extern void (*signal(int, void (*)()))(); +extern void (*signal(int, void (*)(int)))(int); extern int raise(int); #ifdef __cplusplus diff -Nru /n/sources/plan9/sys/include/ape/stddef.h /sys/include/ape/stddef.h --- /n/sources/plan9/sys/include/ape/stddef.h Tue Sep 17 00:00:00 2013 +++ /sys/include/ape/stddef.h Fri Jan 29 00:00:00 2010 @@ -8,9 +8,7 @@ #define NULL ((void*)0) #endif #endif -#ifndef offsetof #define offsetof(ty,mem) ((size_t) &(((ty *)0)->mem)) -#endif typedef long ptrdiff_t; #ifndef _SIZE_T @@ -19,7 +17,7 @@ #endif #ifndef _WCHAR_T #define _WCHAR_T -typedef unsigned short wchar_t; +typedef unsigned int wchar_t; #endif #endif /* __STDDEF_H */ diff -Nru /n/sources/plan9/sys/include/ape/stdlib.h /sys/include/ape/stdlib.h --- /n/sources/plan9/sys/include/ape/stdlib.h Tue Apr 30 00:00:00 2013 +++ /sys/include/ape/stdlib.h Tue May 28 00:00:00 2013 @@ -6,8 +6,9 @@ #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 -#define MB_CUR_MAX 4 +#define MB_CUR_MAX 3 #define RAND_MAX 32767 +#define ATEXIT_MAX 32 typedef struct { int quot, rem; } div_t; typedef struct { long quot, rem; } ldiv_t; diff -Nru /n/sources/plan9/sys/include/ape/sys/limits.h /sys/include/ape/sys/limits.h --- /n/sources/plan9/sys/include/ape/sys/limits.h Mon Dec 3 00:00:00 2012 +++ /sys/include/ape/sys/limits.h Sat Dec 11 00:00:00 1999 @@ -10,10 +10,10 @@ #define OPEN_MAX 96 #undef LINK_MAX #define LINK_MAX 1 +#undef NAME_MAX +#define NAME_MAX 27 #undef PATH_MAX #define PATH_MAX 1023 -#undef NAME_MAX -#define NAME_MAX PATH_MAX #undef NGROUPS_MAX #define NGROUPS_MAX 32 #undef MAX_CANON diff -Nru /n/sources/plan9/sys/include/ape/unistd.h /sys/include/ape/unistd.h --- /n/sources/plan9/sys/include/ape/unistd.h Tue Dec 16 00:00:00 2008 +++ /sys/include/ape/unistd.h Sat Jan 4 00:00:00 2014 @@ -143,6 +143,9 @@ #ifdef __TYPES_H extern int ftruncate(int, off_t); extern off_t lseek(int, off_t, int); + +extern ssize_t pread(int, void*, size_t, off_t); +extern ssize_t pwrite(int, void*, size_t, off_t); #endif /* device- and class-specific functions */ @@ -159,6 +162,8 @@ #ifdef _BSD_EXTENSION #include #endif + +int gethostname(char *, size_t); #ifdef __cplusplus } diff -Nru /n/sources/plan9/sys/include/ape/utf.h /sys/include/ape/utf.h --- /n/sources/plan9/sys/include/ape/utf.h Tue Apr 30 00:00:00 2013 +++ /sys/include/ape/utf.h Sat Jan 4 00:00:00 2014 @@ -55,6 +55,9 @@ extern int istitlerune(Rune); extern int isupperrune(Rune); +extern void rerrstr(char*, unsigned int); /* gross */ +extern int getfields(char*, char**, int, int, char*); /* gross */ + #if defined(__cplusplus) } #endif diff -Nru /n/sources/plan9/sys/src/ape/lib/9/libc.h /sys/src/ape/lib/9/libc.h --- /n/sources/plan9/sys/src/ape/lib/9/libc.h Wed Jan 30 00:00:00 2013 +++ /sys/src/ape/lib/9/libc.h Sat Jan 4 00:00:00 2014 @@ -1,3 +1,6 @@ +#ifndef _LIBC_H_ +#define _LIBC_H_ 1 + #define _LOCK_EXTENSION #define _QLOCK_EXTENSION #define _BSD_EXTENSION @@ -89,10 +92,10 @@ extern long _PWRITE(int, void*, long, long long); extern long _READ(int, void*, long); extern int _REMOVE(const char*); -extern int _RENDEZVOUS(unsigned long, unsigned long); +extern void* _RENDEZVOUS(void*, void*); extern int _RFORK(int); -extern int _SEGATTACH(int, char*, void*, unsigned long); -extern int _SEGBRK(void*, void*); +extern void* _SEGATTACH(int, char*, void*, unsigned long); +extern void* _SEGBRK(void*, void*); extern int _SEGDETACH(void*); extern int _SEGFLUSH(void*, unsigned long); extern int _SEGFREE(void*, unsigned long); @@ -102,39 +105,54 @@ extern Waitmsg* _WAIT(void); extern long _WRITE(int, const void*, long); extern int _WSTAT(const char*, unsigned char*, int); -extern void *_MALLOCZ(int, int); -extern int _WERRSTR(char*, ...); extern long _READN(int, void*, long); extern int _IOUNIT(int); +extern void *_MALLOCZ(int, int); /* not a syscall */ + #define dirstat _dirstat #define dirfstat _dirfstat #define OREAD 0 #define OWRITE 1 #define ORDWR 2 -#define OCEXEC 32 +#define OEXEC 3 /* execute, == read but check execute permission */ +#define OTRUNC 16 /* or'ed in (except for exec), truncate file first */ +#define OCEXEC 32 /* or'ed in, close on exec */ +#define ORCLOSE 64 /* or'ed in, remove on close */ +#define OEXCL 0x1000 /* or'ed in, exclusive use (create only) */ #define AREAD 4 #define AWRITE 2 #define AEXEC 1 #define AEXIST 0 +#ifdef thisisallgoingtoendintears #define open _OPEN #define close _CLOSE #define read _READ #define write _WRITE -#define _exits(s) _exit(s && *(char*)s ? 1 : 0) -#define exits(s) exit(s && *(char*)s ? 1 : 0) #define create _CREATE #define pread _PREAD +#define seek _SEEK +#endif + +/* we don't have fauth(), so let this slide */ +#define seek(fd, off, dir) lseek(fd, off, dir) +#define fauth _FAUTH +/* neither iounit */ +#define iounit _IOUNIT +#define wait _WAIT + +#define create(file, omode, perm) open(file, (omode) |O_CREAT | O_TRUNC, perm) #define readn _READN #define mallocz _MALLOCZ -#define iounit _IOUNIT +#define _exits(s) _exit(s && *(char*)s ? 1 : 0) +#define exits(s) exit(s && *(char*)s ? 1 : 0) /* assume being called as in event.c */ #define postnote(x, pid, msg) kill(pid, SIGTERM) -#define atnotify(x, y) signal(SIGTERM, ekill) +#define atnotify(x, y) signal(SIGTERM, NULL) #define ERRMAX 128 @@ -151,10 +169,14 @@ int enc32(char *, int, uchar *, int); int dec64(uchar *, int, char *, int); int enc64(char *, int, uchar *, int); +int decrypt(void*, void*, int); +int encrypt(void*, void*, int); extern vlong nsec(void); extern void sysfatal(char*, ...); extern ulong truerand(void); /* uses /dev/random */ -extern int getfields(char*, char**, int, int, char*); + +#endif /* _LIBC_H_ */ + diff -Nru /n/sources/plan9/sys/src/ape/lib/9/mkfile /sys/src/ape/lib/9/mkfile --- /n/sources/plan9/sys/src/ape/lib/9/mkfile Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/9/mkfile Sat Jan 4 00:00:00 2014 @@ -4,9 +4,11 @@ LIB=/$objtype/lib/ape/lib9.a OFILES=errstr.$O\ bind.$O\ + crypt.$O\ getcallerpc.$O\ getfcr.$O\ mount.$O\ + nsec.$O\ rendezvous.$O\ rfork.$O\ segattach.$O\ @@ -21,10 +23,11 @@ u32.$O\ u64.$O\ unmount.$O\ + wait.$O\ +#include "libc.h" + +static uvlong border = 0x0001020304050607ull; + +static uvlong +getbe(uchar *t, int w) +{ + uint i; + uvlong r; + + r = 0; + for(i = 0; i < w; i++) + r = r<<8 | t[i]; + return r; +} + +vlong +nsec(void) +{ + uchar b[8]; + int fd; + vlong v; + + fd = _OPEN("/dev/bintime", OREAD); + if(fd != -1 && _PREAD(fd, b, 8, 0) == 8) + v = getbe(b, 8); + else + v = 0; + _CLOSE(fd); + return v; +} diff -Nru /n/sources/plan9/sys/src/ape/lib/9/rendezvous.c /sys/src/ape/lib/9/rendezvous.c --- /n/sources/plan9/sys/src/ape/lib/9/rendezvous.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/9/rendezvous.c Sat Jan 4 00:00:00 2014 @@ -1,9 +1,9 @@ #include -extern unsigned long _RENDEZVOUS(unsigned long, unsigned long); +extern void* _RENDEZVOUS(void*, void*); -unsigned long -rendezvous(unsigned long tag, unsigned long value) +void* +rendezvous(void* tag, void* value) { return _RENDEZVOUS(tag, value); } diff -Nru /n/sources/plan9/sys/src/ape/lib/9/segattach.c /sys/src/ape/lib/9/segattach.c --- /n/sources/plan9/sys/src/ape/lib/9/segattach.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/9/segattach.c Sat Jan 4 00:00:00 2014 @@ -1,8 +1,8 @@ #include -extern int _SEGATTACH(int, char*, void*, unsigned long); +extern void* _SEGATTACH(int, char*, void*, unsigned long); -int +void* segattach(int attr, char *class, void *va, unsigned long len) { return _SEGATTACH(attr, class, va, len); diff -Nru /n/sources/plan9/sys/src/ape/lib/9/segbrk.c /sys/src/ape/lib/9/segbrk.c --- /n/sources/plan9/sys/src/ape/lib/9/segbrk.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/9/segbrk.c Sat Jan 4 00:00:00 2014 @@ -2,7 +2,7 @@ extern int _SEGBRK(void*, void*); -int +void* segbrk(void *saddr, void *addr) { return _SEGBRK(saddr, addr); diff -Nru /n/sources/plan9/sys/src/ape/lib/9/wait.c /sys/src/ape/lib/9/wait.c --- /n/sources/plan9/sys/src/ape/lib/9/wait.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/9/wait.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,31 @@ +#include +#include "libc.h" + +Waitmsg* +wait(void) +{ + int n, l; + char buf[512], *fld[5]; + Waitmsg *w; + + n = _AWAIT(buf, sizeof buf-1); + if(n < 0) + return nil; + buf[n] = '\0'; + if(tokenize(buf, fld, nelem(fld)) != nelem(fld)){ + werrstr("couldn't parse wait message"); + return nil; + } + l = strlen(fld[4])+1; + w = malloc(sizeof(Waitmsg)+l); + if(w == nil) + return nil; + w->pid = atoi(fld[0]); + w->time[0] = atoi(fld[1]); + w->time[1] = atoi(fld[2]); + w->time[2] = atoi(fld[3]); + w->msg = (char*)&w[1]; + memmove(w->msg, fld[4], l); + return w; +} + diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/gen/memchr.c /sys/src/ape/lib/ap/gen/memchr.c --- /n/sources/plan9/sys/src/ape/lib/ap/gen/memchr.c Fri Sep 7 00:00:00 2007 +++ /sys/src/ape/lib/ap/gen/memchr.c Sat Jan 4 00:00:00 2014 @@ -3,13 +3,13 @@ void* memchr(const void *ap, int c, size_t n) { - unsigned char *sp; + const unsigned char *sp; sp = ap; c &= 0xFF; while(n > 0) { if(*sp++ == c) - return sp-1; + return (void*)(sp-1); n--; } return 0; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/gen/memcmp.c /sys/src/ape/lib/ap/gen/memcmp.c --- /n/sources/plan9/sys/src/ape/lib/ap/gen/memcmp.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/gen/memcmp.c Sat Jan 4 00:00:00 2014 @@ -3,7 +3,7 @@ int memcmp(const void *a1, const void *a2, size_t n) { - char *s1, *s2; + const char *s1, *s2; unsigned c1, c2; s1 = a1; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/gen/memmove.c /sys/src/ape/lib/ap/gen/memmove.c --- /n/sources/plan9/sys/src/ape/lib/ap/gen/memmove.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/gen/memmove.c Sat Jan 4 00:00:00 2014 @@ -11,7 +11,7 @@ if(a1 > a2) goto back; s1 = a1; - s2 = a2; + s2 = (char*)a2; while(n > 0) { *s1++ = *s2++; n--; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/gen/qsort.c /sys/src/ape/lib/ap/gen/qsort.c --- /n/sources/plan9/sys/src/ape/lib/ap/gen/qsort.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/gen/qsort.c Sat Jan 4 00:00:00 2014 @@ -1,15 +1,17 @@ /* qsort -- qsort interface implemented by faster quicksort */ +#define _SUSV2_SOURCE #include +#include #define SWAPINIT(a, es) swaptype = \ - (a - (char*) 0) % sizeof(long) || es % sizeof(long) ? 2 : \ + ((uintptr_t)a - 0) % sizeof(long) || es % sizeof(long) ? 2 : \ es == sizeof(long) ? 0 : 1; #define swapcode(TYPE, parmi, parmj, n) { \ long i = (n) / (int) sizeof(TYPE); \ - register TYPE *pi = (TYPE *) (parmi); \ - register TYPE *pj = (TYPE *) (parmj); \ + TYPE *pi = (TYPE *) (parmi); \ + TYPE *pj = (TYPE *) (parmj); \ do { \ - register TYPE t = *pi; \ + TYPE t = *pi; \ *pi++ = *pj; \ *pj++ = t; \ } while (--i > 0); \ diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/gen/rand.c /sys/src/ape/lib/ap/gen/rand.c --- /n/sources/plan9/sys/src/ape/lib/ap/gen/rand.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/gen/rand.c Sat Jan 4 00:00:00 2014 @@ -27,8 +27,8 @@ rng_tap = rng_vec; rng_feed = rng_vec+LEN-TAP; seed = seed%M; - if(0 && seed < 0) /* seed is unsigned */ - seed += M; +// if(seed < 0) +// seed += M; if(seed == 0) seed = 89482311; x = seed; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/gen/strcspn.c /sys/src/ape/lib/ap/gen/strcspn.c --- /n/sources/plan9/sys/src/ape/lib/ap/gen/strcspn.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/gen/strcspn.c Sat Jan 4 00:00:00 2014 @@ -5,7 +5,8 @@ size_t strcspn(const char *s, const char *b) { - char map[N], *os; + char map[N]; + const char *os; memset(map, 0, N); for(;;) { @@ -13,7 +14,7 @@ if(*b++ == 0) break; } - os = (char *)s; + os = s; while(map[*(unsigned char*)s++] == 0) ; return s - os - 1; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/gen/strrchr.c /sys/src/ape/lib/ap/gen/strrchr.c --- /n/sources/plan9/sys/src/ape/lib/ap/gen/strrchr.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/gen/strrchr.c Sat Jan 4 00:00:00 2014 @@ -3,12 +3,12 @@ char* strrchr(const char *s, int c) { - char *r; + const char *r; if(c == 0) return strchr(s, 0); r = 0; while(s = strchr(s, c)) - r = (char *)s++; - return r; + r = s++; + return (char*)r; } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/gen/strspn.c /sys/src/ape/lib/ap/gen/strspn.c --- /n/sources/plan9/sys/src/ape/lib/ap/gen/strspn.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/gen/strspn.c Sat Jan 4 00:00:00 2014 @@ -5,12 +5,13 @@ size_t strspn(const char *s, const char *b) { - char map[N], *os; + char map[N]; + const char *os; memset(map, 0, N); while(*b) map[*(unsigned char *)b++] = 1; - os = (char *)s; + os = s; while(map[*(unsigned char *)s++]) ; return s - os - 1; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/9iounit.c /sys/src/ape/lib/ap/plan9/9iounit.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/9iounit.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/9iounit.c Sat Jan 4 00:00:00 2014 @@ -10,41 +10,6 @@ 3 r M 4 (0000000000457def 11 00) 8192 512 /rc/lib/rcmain */ -static int -getfields(char *str, char **args, int max, int mflag) -{ - char r; - int nr, intok, narg; - - if(max <= 0) - return 0; - - narg = 0; - args[narg] = str; - if(!mflag) - narg++; - intok = 0; - for(;;) { - nr = 1; /* utf bytes in this rune */ - r = *str++; - if(r == 0) - break; - if(r == ' ' || r == '\t'){ - if(narg >= max) - break; - *str = 0; - intok = 0; - args[narg] = str + nr; - if(!mflag) - narg++; - } else { - if(!intok && mflag) - narg++; - intok = 1; - } - } - return narg; -} int _IOUNIT(int fd) { @@ -60,7 +25,7 @@ if(i <= 0) return 0; buf[i] = '\0'; - if(getfields(buf, args, 10, 1) != 10) + if(getfields(buf, args, 10, 1, " \t") != 10) return 0; return atoi(args[7]); } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/_buf.c /sys/src/ape/lib/ap/plan9/_buf.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/_buf.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/_buf.c Sat Jan 4 00:00:00 2014 @@ -11,6 +11,7 @@ #include #include #include +#include #include "sys9.h" typedef struct Muxseg { @@ -23,7 +24,6 @@ Muxbuf bufs[INITBUFS]; /* can grow, via segbrk() */ } Muxseg; -#define MUXADDR ((void*)0x6000000) static Muxseg *mux = 0; /* shared memory segment */ /* _muxsid and _killmuxsid are known in libbsd's listen.c */ @@ -57,8 +57,8 @@ if(mux == 0){ _RFORK(RFREND); - mux = (Muxseg*)_SEGATTACH(0, "shared", MUXADDR, sizeof(Muxseg)); - if((long)mux == -1){ + mux = (Muxseg*)_SEGATTACH(0, "shared", 0, sizeof(Muxseg)); + if(mux == (void*)-1){ _syserrno(); return -1; } @@ -72,7 +72,7 @@ lock(&mux->lock); slot = mux->curfds++; if(mux->curfds > INITBUFS) { - if(_SEGBRK(mux, mux->bufs+mux->curfds) < 0){ + if(_SEGBRK(mux, mux->bufs+mux->curfds) == (void*)-1){ _syserrno(); unlock(&mux->lock); return -1; @@ -99,7 +99,7 @@ for(i=0; ibuf = b; f->flags |= FD_BUFFERED; unlock(&mux->lock); - _muxsid = _RENDEZVOUS(0, 0); + _muxsid = (uintptr_t)_RENDEZVOUS((void*)0x101, 0); /* leave fd open in parent so system doesn't reuse it */ return 0; } @@ -152,7 +152,7 @@ /* sleep until there's room */ b->roomwait = 1; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&b->roomwait, 0); + _RENDEZVOUS(&b->roomwait, 0); } } else unlock(&mux->lock); @@ -174,15 +174,15 @@ if(mux->selwait && FD_ISSET(fd, &mux->ewant)) { mux->selwait = 0; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&mux->selwait, fd); + _RENDEZVOUS(&mux->selwait, (void*)fd); } else if(b->datawait) { b->datawait = 0; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&b->datawait, 0); + _RENDEZVOUS(&b->datawait, 0); } else if(mux->selwait && FD_ISSET(fd, &mux->rwant)) { mux->selwait = 0; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&mux->selwait, fd); + _RENDEZVOUS(&mux->selwait, (void*)fd); } else unlock(&mux->lock); _exit(0); @@ -195,12 +195,12 @@ b->datawait = 0; unlock(&mux->lock); /* wake up _bufreading process */ - _RENDEZVOUS((unsigned long)&b->datawait, 0); + _RENDEZVOUS(&b->datawait, 0); } else if(mux->selwait && FD_ISSET(fd, &mux->rwant)) { mux->selwait = 0; unlock(&mux->lock); /* wake up selecting process */ - _RENDEZVOUS((unsigned long)&mux->selwait, fd); + _RENDEZVOUS(&mux->selwait, (void*)fd); } else unlock(&mux->lock); } else @@ -237,7 +237,7 @@ /* sleep until there's data */ b->datawait = 1; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&b->datawait, 0); + _RENDEZVOUS(&b->datawait, 0); lock(&mux->lock); ngot = b->putnext - b->getnext; } @@ -255,7 +255,7 @@ b->roomwait = 0; unlock(&mux->lock); /* wake up copy process */ - _RENDEZVOUS((unsigned long)&b->roomwait, 0); + _RENDEZVOUS(&b->roomwait, 0); } else unlock(&mux->lock); return ngot; @@ -348,7 +348,7 @@ } mux->selwait = 1; unlock(&mux->lock); - fd = _RENDEZVOUS((unsigned long)&mux->selwait, 0); + fd = (uintptr_t)_RENDEZVOUS(&mux->selwait, 0); if(fd >= 0) { b = _fdinfo[fd].buf; if(FD_ISSET(fd, &mux->rwant)) { @@ -393,8 +393,9 @@ setpgid(getpid(), _muxsid); signal(SIGALRM, alarmed); for(i=0; iwaittime); if(timerreset) { @@ -405,7 +406,7 @@ mux->selwait = 0; mux->waittime = LONGWAIT; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&mux->selwait, -2); + _RENDEZVOUS(&mux->selwait, (void*)-2); } else { mux->waittime = LONGWAIT; unlock(&mux->lock); @@ -415,7 +416,8 @@ } atexit(_killtimerproc); /* parent process continues */ - _RENDEZVOUS(1, 0); + while(_RENDEZVOUS((void*)0x103, 0) == (void*)~0) + ; } static void @@ -454,7 +456,7 @@ } static int -copynotehandler(void *, char *) +copynotehandler(void*, char*) { if(_finishing) _finish(0, 0); diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/_envsetup.c /sys/src/ape/lib/ap/plan9/_envsetup.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/_envsetup.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/_envsetup.c Sat Jan 4 00:00:00 2014 @@ -21,7 +21,6 @@ char **environ; int errno; unsigned long _clock; - static void fdsetup(char *, char *); static void sigsetup(char *, char *); @@ -32,48 +31,45 @@ void _envsetup(void) { - int dfd, fdinited, n, nd, m, i, j, f, nohandle, psize, cnt; - char *ps, *p; + int dfd; + int n, nd, m, i, j, f; + int psize, cnt; + int nohandle; + int fdinited; + char *ps, *p, *name; char **pp; - char name[NAME_MAX+5]; Dir *d9, *d9a; - static char **emptyenvp = 0; - environ = emptyenvp; /* pessimism */ nohandle = 0; fdinited = 0; cnt = 0; - strcpy(name, "#e"); - dfd = _OPEN(name, 0); - if(dfd < 0) + dfd = _OPEN("/env", 0); + if(dfd < 0) { + environ = malloc(sizeof(char**)); + *environ = NULL; return; - name[2] = '/'; + } ps = p = malloc(Envhunk); - if(p == 0) - return; psize = Envhunk; nd = _dirreadall(dfd, &d9a); _CLOSE(dfd); for(j=0; jname); - if(n >= sizeof name - 4) - continue; /* shouldn't be possible */ m = d9->length; i = p - ps; if(i+n+1+m+1 > psize) { psize += (n+m+2 < Envhunk)? Envhunk : n+m+2; ps = realloc(ps, psize); - if (ps == 0) { - free(d9a); - return; - } p = ps + i; } memcpy(p, d9->name, n); p[n] = '='; - strcpy(name+3, d9->name); + name = malloc(n+6); + strcpy(name, "/env/"); + strcpy(name+5, d9->name); f = _OPEN(name, O_RDONLY); + free(name); if(f < 0 || _READ(f, p+n+1, m) != m) m = 0; _CLOSE(f); @@ -96,10 +92,7 @@ free(d9a); if(!fdinited) _fdinit(0, 0); - pp = malloc((1+cnt)*sizeof(char *)); - if (pp == 0) - return; - environ = pp; + environ = pp = malloc((1+cnt)*sizeof(char *)); p = ps; for(i = 0; i < cnt; i++) { *pp++ = p; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/_getpw.c /sys/src/ape/lib/ap/plan9/_getpw.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/_getpw.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/_getpw.c Sat Jan 4 00:00:00 2014 @@ -61,7 +61,7 @@ } matchnum = (*pname == NULL); matched = 0; - mem = nil; + mem = (void*)0; /* try using memo */ for(i = 0; i +#include #include "sys9.h" char end[]; static char *bloc = { end }; -extern int _BRK_(void*); + +enum +{ + Round = 7 +}; char * brk(char *p) { - unsigned long n; + uintptr_t bl; - n = (unsigned long)p; - n += 3; - n &= ~3; - if(_BRK_((void*)n) < 0){ + bl = ((uintptr_t)p + Round) & ~Round; + if(_BRK_((void*)bl) < 0){ errno = ENOMEM; return (char *)-1; } - bloc = (char *)n; + bloc = (char*)bl; return 0; } void * sbrk(unsigned long n) { - n += 3; - n &= ~3; + uintptr_t bl; + + bl = ((uintptr_t)bloc + Round) & ~Round; if(_BRK_((void *)(bloc+n)) < 0){ errno = ENOMEM; return (void *)-1; } - bloc += n; - return (void *)(bloc-n); + bloc = (char*)bl + n; + return (void*)bl; } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/copysign.c /sys/src/ape/lib/ap/plan9/copysign.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/copysign.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/ap/plan9/copysign.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,18 @@ +#include +#include +#define _RESEARCH_SOURCE +#include + +#define SIGN (1<<31) + +double +copysign(double x, double y) +{ + FPdbleword a, b; + + a.x = x; + b.x = y; + a.hi &= ~SIGN; + a.hi |= b.hi & SIGN; + return a.x; +} diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/execve.c /sys/src/ape/lib/ap/plan9/execve.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/execve.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/execve.c Sat Jan 4 00:00:00 2014 @@ -57,7 +57,7 @@ * are ignored, in case the current value of the * variable ignored some. */ - f = _CREATE("#e/_sighdlr", OWRITE, 0666); + f = _CREATE("/env/_sighdlr", OWRITE, 0666); if(f >= 0){ ss = buf; for(i = 0; i <=MAXSIG && ss < &buf[sizeof(buf)]-5; i++) { @@ -70,16 +70,16 @@ _CLOSE(f); } if(envp){ - strcpy(nam, "#e/"); - for(e = (char **)envp; (ss = *e); e++) { + strcpy(nam, "/env/"); + for(e = (char**)envp; (ss = *e); e++) { se = strchr(ss, '='); if(!se || ss==se) continue; /* what is name? value? */ n = se-ss; - if(n >= sizeof(nam)-3) - n = sizeof(nam)-3-1; - memcpy(nam+3, ss, n); - nam[3+n] = 0; + if(n >= sizeof(nam)-5) + n = sizeof(nam)-(5 + 1); + memcpy(nam+5, ss, n); + nam[5+n] = 0; f = _CREATE(nam, OWRITE, 0666); if(f < 0) continue; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/frexp.c /sys/src/ape/lib/ap/plan9/frexp.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/frexp.c Wed Aug 14 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/frexp.c Sat Jan 4 00:00:00 2014 @@ -8,51 +8,36 @@ #define BIAS 1022L #define SIG 52 -typedef union -{ - double d; - struct - { -#ifdef IEEE_8087 - long ls; - long ms; -#else - long ms; - long ls; -#endif - }; -} Cheat; - double frexp(double d, int *ep) { - Cheat x, a; + FPdbleword x, a; *ep = 0; - /* order matters: only isNaN can operate on NaN */ if(isNaN(d) || isInf(d, 0) || d == 0) return d; - x.d = d; - a.d = fabs(d); - if((a.ms >> SHIFT) == 0){ /* normalize subnormal numbers */ - x.d = (double)(1ULL<> SHIFT) == 0){ + /* normalize subnormal numbers */ + x.x = (double)(1ULL<> SHIFT) & MASK) - BIAS; - x.ms &= ~(MASK << SHIFT); - x.ms |= BIAS << SHIFT; - return x.d; + *ep += ((x.hi >> SHIFT) & MASK) - BIAS; + x.hi &= ~(MASK << SHIFT); + x.hi |= BIAS << SHIFT; + return x.x; } double ldexp(double d, int e) { - Cheat x; + FPdbleword x; if(d == 0) return 0; - x.d = d; - e += (x.ms >> SHIFT) & MASK; + x.x = d; + e += (x.hi >> SHIFT) & MASK; if(e <= 0) return 0; if(e >= MASK){ @@ -61,28 +46,18 @@ return -HUGE_VAL; return HUGE_VAL; } - x.ms &= ~(MASK << SHIFT); - x.ms |= (long)e << SHIFT; - return x.d; + x.hi &= ~(MASK << SHIFT); + x.hi |= (long)e << SHIFT; + return x.x; } double modf(double d, double *ip) { double f; - Cheat x; + FPdbleword x; int e; - x.d = d; - e = (x.ms >> SHIFT) & MASK; - if(e == MASK){ - *ip = d; - if(x.ls != 0 || (x.ms & 0xfffffL) != 0) /* NaN */ - return d; - /* ±Inf */ - x.ms &= 0x80000000L; - return x.d; - } if(d < 1) { if(d < 0) { f = modf(-d, ip); @@ -92,13 +67,14 @@ *ip = 0; return d; } - e -= BIAS; + x.x = d; + e = ((x.hi >> SHIFT) & MASK) - BIAS; if(e <= SHIFT+1) { - x.ms &= ~(0x1fffffL >> e); - x.ls = 0; + x.hi &= ~(0x1fffffL >> e); + x.lo = 0; } else if(e <= SHIFT+33) - x.ls &= ~(0x7fffffffL >> (e-SHIFT-2)); - *ip = x.d; - return d - x.d; + x.lo &= ~(0x7fffffffL >> (e-SHIFT-2)); + *ip = x.x; + return d - x.x; } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/fsync.c /sys/src/ape/lib/ap/plan9/fsync.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/fsync.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/fsync.c Sat Jan 4 00:00:00 2014 @@ -3,8 +3,9 @@ #include int -fsync(int) +fsync(int fd) { + USED(fd); errno = EINVAL; return -1; } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/getgroups.c /sys/src/ape/lib/ap/plan9/getgroups.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/getgroups.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/getgroups.c Sat Jan 4 00:00:00 2014 @@ -3,8 +3,9 @@ #include int -getgroups(int, gid_t []) +getgroups(int gidsize, gid_t grouplist[]) { + USED(gidsize, grouplist); errno = EINVAL; return -1; } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/lib.h /sys/src/ape/lib/ap/plan9/lib.h --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/lib.h Wed Dec 31 00:00:00 2003 +++ /sys/src/ape/lib/ap/plan9/lib.h Sat Jan 4 00:00:00 2014 @@ -9,7 +9,7 @@ enum { READMAX = 8192, /* read at most this much with _READ */ PERFDMAX = 2*READMAX, /* stop _READing an fd when it has this much */ - INITBUFS = 4, /* allow enough room for this many PERFDMAX */ + INITBUFS = 90, /* allow enough room for this many PERFDMAX */ }; typedef struct Muxbuf { diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/malloc.c /sys/src/ape/lib/ap/plan9/malloc.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/malloc.c Fri Apr 29 00:00:00 2011 +++ /sys/src/ape/lib/ap/plan9/malloc.c Sat Jan 4 00:00:00 2014 @@ -2,6 +2,8 @@ #include #include +#include + typedef unsigned int uint; enum @@ -25,10 +27,11 @@ struct Arena { Bucket *btab[MAX2SIZE]; + Lock; }; static Arena arena; -#define datoff ((int)((Bucket*)0)->data) +#define datoff ((intptr_t)((Bucket*)0)->data) #define nil ((void*)0) extern void *sbrk(unsigned long); @@ -48,16 +51,19 @@ return nil; good: /* Allocate off this list */ + lock(&arena); bp = arena.btab[pow]; if(bp) { arena.btab[pow] = bp->next; + unlock(&arena); if(bp->magic != 0) abort(); bp->magic = MAGIC; - return bp->data; + return bp->data; } + size = sizeof(Bucket)+(1<next = (Bucket*)next; nbp->size = pow; nbp = nbp->next; @@ -81,9 +89,12 @@ } else { bp = sbrk(size); - if((intptr_t)bp == -1) + if((intptr_t)bp == -1){ + unlock(&arena); return nil; + } } + unlock(&arena); bp->size = pow; bp->magic = MAGIC; @@ -100,15 +111,17 @@ return; /* Find the start of the structure */ - bp = (Bucket*)((uint)ptr - datoff); + bp = (Bucket*)((intptr_t)ptr - datoff); if(bp->magic != MAGIC) abort(); bp->magic = 0; l = &arena.btab[bp->size]; + lock(&arena); bp->next = *l; *l = bp; + unlock(&arena); } void* @@ -122,7 +135,7 @@ return malloc(n); /* Find the start of the structure */ - bp = (Bucket*)((uint)ptr - datoff); + bp = (Bucket*)((intptr_t)ptr - datoff); if(bp->magic != MAGIC) abort(); diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/mkfile /sys/src/ape/lib/ap/plan9/mkfile --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/mkfile Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/mkfile Sat Jan 4 00:00:00 2014 @@ -26,6 +26,7 @@ close.$O\ convM2D.$O\ convD2M.$O\ + copysign.$O\ creat.$O\ ctermid.$O\ ctime.$O\ diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/pause.c /sys/src/ape/lib/ap/plan9/pause.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/pause.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/pause.c Sat Jan 4 00:00:00 2014 @@ -1,11 +1,14 @@ #include "lib.h" #include +#include #include "sys9.h" int pause(void) { for(;;) - if(_SLEEP(1000*1000) < 0) + if(_SLEEP(1000*1000) < 0){ + errno = EINTR; return -1; + } } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/profile.c /sys/src/ape/lib/ap/plan9/profile.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/profile.c Fri Jan 22 00:00:00 2010 +++ /sys/src/ape/lib/ap/plan9/profile.c Sat Jan 4 00:00:00 2014 @@ -18,6 +18,7 @@ typedef long long vlong; typedef unsigned long ulong; typedef unsigned long long uvlong; +typedef unsigned long uint; #include "/sys/include/tos.h" diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/qlock.c /sys/src/ape/lib/ap/plan9/qlock.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/qlock.c Tue Dec 2 00:00:00 2003 +++ /sys/src/ape/lib/ap/plan9/qlock.c Sat Jan 4 00:00:00 2014 @@ -73,7 +73,7 @@ unlock(&q->lock); /* wait */ - while((*_rendezvousp)((ulong)mp, 1) == ~0) + while((*_rendezvousp)(mp, (void*)1) == (void*)~0) ; mp->inuse = 0; } @@ -84,6 +84,8 @@ QLp *p; lock(&q->lock); + if (q->locked == 0) + abort(); p = q->head; if(p != nil){ /* wakeup head waiting process */ @@ -91,7 +93,7 @@ if(q->head == nil) q->tail = nil; unlock(&q->lock); - while((*_rendezvousp)((ulong)p, 0x12345) == ~0) + while((*_rendezvousp)(p, (void*)0x12345) == (void*)~0) ; return; } @@ -140,7 +142,7 @@ unlock(&q->lock); /* wait in kernel */ - while((*_rendezvousp)((ulong)mp, 1) == ~0) + while((*_rendezvousp)(mp, (void*)1) == (void*)~0) ; mp->inuse = 0; } @@ -183,7 +185,7 @@ unlock(&q->lock); /* wakeup waiter */ - while((*_rendezvousp)((ulong)p, 0) == ~0) + while((*_rendezvousp)(p, 0) == (void*)~0) ; } @@ -213,7 +215,7 @@ unlock(&q->lock); /* wait in kernel */ - while((*_rendezvousp)((ulong)mp, 1) == ~0) + while((*_rendezvousp)(mp, (void*)1) == (void*)~0) ; mp->inuse = 0; } @@ -252,7 +254,7 @@ if(q->head == nil) q->tail = nil; unlock(&q->lock); - while((*_rendezvousp)((ulong)p, 0) == ~0) + while((*_rendezvousp)(p, 0) == (void*)~0) ; return; } @@ -265,7 +267,7 @@ p = q->head; q->head = p->next; q->readers++; - while((*_rendezvousp)((ulong)p, 0) == ~0) + while((*_rendezvousp)(p, 0) == (void*)~0) ; } if(q->head == nil) @@ -303,7 +305,7 @@ if(r->l->head == nil) r->l->tail = nil; unlock(&r->l->lock); - while((*_rendezvousp)((ulong)t, 0x12345) == ~0) + while((*_rendezvousp)(t, (void*)0x12345) == (void*)~0) ; }else{ r->l->locked = 0; @@ -311,7 +313,7 @@ } /* wait for a wakeup */ - while((*_rendezvousp)((ulong)me, 1) == ~0) + while((*_rendezvousp)(me, (void*)1) == (void*)~0) ; me->inuse = 0; } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/read.c /sys/src/ape/lib/ap/plan9/read.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/read.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/read.c Sat Jan 4 00:00:00 2014 @@ -1,4 +1,5 @@ #include +#include #include #include #include "lib.h" @@ -7,12 +8,12 @@ #include ssize_t -read(int d, void *buf, size_t nbytes) +pread(int fd, void *buf, size_t nbytes, off_t offset) { int n, noblock, isbuf; Fdinfo *f; - if(d<0 || d>=OPEN_MAX || !(_fdinfo[d].flags&FD_ISOPEN)){ + if(fd<0 || fd>=OPEN_MAX || !((f = &_fdinfo[fd])->flags&FD_ISOPEN)){ errno = EBADF; return -1; } @@ -22,7 +23,6 @@ errno = EFAULT; return -1; } - f = &_fdinfo[d]; noblock = f->oflags&O_NONBLOCK; isbuf = f->flags&(FD_BUFFERED|FD_BUFFEREDX); if(noblock || isbuf){ @@ -31,16 +31,22 @@ return -1; } if(!isbuf) { - if(_startbuf(d) != 0) { + if(_startbuf(fd) != 0) { errno = EIO; return -1; } } - n = _readbuf(d, buf, nbytes, noblock); + n = _readbuf(fd, buf, nbytes, noblock); }else{ - n = _READ(d, buf, nbytes); + n = _PREAD(fd, buf, nbytes, offset); if(n < 0) _syserrno(); } return n; +} + +ssize_t +read(int fd, void *buf, size_t nbytes) +{ + return pread(fd, buf, nbytes, -1ll); } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/rename.c /sys/src/ape/lib/ap/plan9/rename.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/rename.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/rename.c Sat Jan 4 00:00:00 2014 @@ -11,7 +11,7 @@ rename(const char *from, const char *to) { int n; - char *f, *t; + const char *f, *t; Dir *d, nd; if(access(to, 0) >= 0){ @@ -31,13 +31,14 @@ } f = strrchr(from, '/'); t = strrchr(to, '/'); - f = f? f+1 : (char *)from; - t = t? t+1 : (char *)to; + f = f? f+1 : from; + t = t? t+1 : to; n = 0; if(f-from==t-to && strncmp(from, to, f-from)==0){ /* from and to are in same directory (we miss some cases) */ + strlen(t); _nulldir(&nd); - nd.name = t; + nd.name = (char*)t; if(_dirwstat(from, &nd) < 0){ _syserrno(); n = -1; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/setgid.c /sys/src/ape/lib/ap/plan9/setgid.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/setgid.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/setgid.c Sat Jan 4 00:00:00 2014 @@ -7,8 +7,9 @@ */ int -setgid(gid_t) +setgid(gid_t gid) { + USED(gid); errno = EPERM; return -1; } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/setuid.c /sys/src/ape/lib/ap/plan9/setuid.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/setuid.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/setuid.c Sat Jan 4 00:00:00 2014 @@ -7,8 +7,9 @@ */ int -setuid(uid_t) +setuid(uid_t uid) { + USED(uid); errno = EPERM; return -1; } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/signal.c /sys/src/ape/lib/ap/plan9/signal.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/signal.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/plan9/signal.c Sat Jan 4 00:00:00 2014 @@ -37,21 +37,23 @@ void (*_sighdlr[MAXSIG+1])(int, char*, Ureg*); /* 0 initialized: SIG_DFL */ -/* must match signal.h: extern void (*signal(int, void (*)()))(); */ -//void (*signal(int sig, void (*func)(int, char*, Ureg*)))(int, char*, Ureg*) +/* consider moving to */ +typedef void (*sighandler_t)(int); +typedef void (*isighandler_t)(int, char*, Ureg*); + void -(*signal(int sig, void (*func)()))() +(*signal(int sig, void (*func)(int)))(int) { - void(*oldf)(int, char*, Ureg*); + sighandler_t oldf; if(sig <= 0 || sig > MAXSIG){ errno = EINVAL; return SIG_ERR; } - oldf = _sighdlr[sig]; + oldf = (sighandler_t)_sighdlr[sig]; if(sig == SIGKILL) return oldf; /* can't catch or ignore SIGKILL */ - _sighdlr[sig] = func; + _sighdlr[sig] = (isighandler_t)func; return oldf; } @@ -90,12 +92,14 @@ /* this is registered in _envsetup */ int -_notehandler(void *u, char *msg) +_notehandler(void *v, char *msg) { int i; void(*f)(int, char*, Ureg*); + Ureg *u; extern void _doatexits(void); /* in stdio/exit.c */ + u = v; if(_finishing) _finish(0, 0); for(i = 0; iflags&FD_ISOPEN) && (db2=_dirfstat(i)) != nil) { if(db1->qid.path == db2->qid.path && @@ -67,10 +66,8 @@ free(db2); } } - n = 0; - if(fd == -1) - if((n=_REMOVE(path)) < 0) - _syserrno(); + if((n = _REMOVE(path)) < 0) + _syserrno(); free(db1); return n; } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/plan9/write.c /sys/src/ape/lib/ap/plan9/write.c --- /n/sources/plan9/sys/src/ape/lib/ap/plan9/write.c Mon Nov 25 00:00:00 2002 +++ /sys/src/ape/lib/ap/plan9/write.c Sat Jan 4 00:00:00 2014 @@ -1,21 +1,28 @@ #include +#include #include #include "lib.h" #include "sys9.h" ssize_t -write(int d, const void *buf, size_t nbytes) +pwrite(int fd, const void *buf, size_t nbytes, off_t off) { int n; - if(d<0 || d>=OPEN_MAX || !(_fdinfo[d].flags&FD_ISOPEN)){ + if(fd<0 || fd>=OPEN_MAX || !(_fdinfo[fd].flags&FD_ISOPEN)){ errno = EBADF; return -1; } - if(_fdinfo[d].oflags&O_APPEND) - _SEEK(d, 0, 2); - n = _WRITE(d, buf, nbytes); + if(_fdinfo[fd].oflags&O_APPEND) + _SEEK(fd, 0, 2); + n = _PWRITE(fd, buf, nbytes, off); if(n < 0) _syserrno(); return n; +} + +ssize_t +write(int fd, const void *buf, size_t nbytes) +{ + return pwrite(fd, buf, nbytes, -1ll); } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/posix/getgrent.c /sys/src/ape/lib/ap/posix/getgrent.c --- /n/sources/plan9/sys/src/ape/lib/ap/posix/getgrent.c Sat Mar 10 00:00:00 2012 +++ /sys/src/ape/lib/ap/posix/getgrent.c Sat Jan 4 00:00:00 2014 @@ -32,7 +32,7 @@ } static char * -grskip(register char *p, register c) +grskip(char *p, int c) { while( *p && *p != c ) ++p; if( *p ) *p++ = 0; @@ -40,9 +40,9 @@ } struct group * -getgrent() +getgrent(void) { - register char *p, **q; + char *p, **q; if( !grf && !(grf = fopen( GROUP, "r" )) ) return(NULL); diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/posix/getpwent.c /sys/src/ape/lib/ap/posix/getpwent.c --- /n/sources/plan9/sys/src/ape/lib/ap/posix/getpwent.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/posix/getpwent.c Sat Jan 4 00:00:00 2014 @@ -49,14 +49,16 @@ passwd.pw_dir = p; p = pwskip(p); passwd.pw_shell = p; - pwskip(p); + p = pwskip(p); + USED(p); + return(&passwd); } struct passwd * getpwent(void) { - register char *p; + char *p; if (pwf == NULL) { if( (pwf = fopen( PASSWD, "r" )) == NULL ) diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/posix/mkfifo.c /sys/src/ape/lib/ap/posix/mkfifo.c --- /n/sources/plan9/sys/src/ape/lib/ap/posix/mkfifo.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/posix/mkfifo.c Sat Jan 4 00:00:00 2014 @@ -3,8 +3,9 @@ #include int -mkfifo(char *, mode_t) +mkfifo(char *path, mode_t mode) { + USED(path, mode); errno = 0; return -1; } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/posix/pathconf.c /sys/src/ape/lib/ap/posix/pathconf.c --- /n/sources/plan9/sys/src/ape/lib/ap/posix/pathconf.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/posix/pathconf.c Sat Jan 4 00:00:00 2014 @@ -4,8 +4,9 @@ #include long -pathconf(const char *, int name) +pathconf(const char *path, int name) { + USED(path); switch(name) { case _PC_LINK_MAX: @@ -44,8 +45,9 @@ } long -fpathconf(int, int name) +fpathconf(int fd, int name) { + USED(fd); return pathconf(0, name); } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/_IO_getc.c /sys/src/ape/lib/ap/stdio/_IO_getc.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/_IO_getc.c Mon Nov 25 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/_IO_getc.c Sat Jan 4 00:00:00 2014 @@ -2,13 +2,16 @@ * pANS stdio -- _IO_getc */ #include "iolib.h" -int _IO_getc(FILE *f){ +int +_IO_getc(FILE *f) +{ int cnt, n; switch(f->state){ default: /* CLOSED, WR, ERR, EOF */ return EOF; case OPEN: - _IO_setvbuf(f); + if(_IO_setvbuf(f) != 0) + return EOF; case RDWR: case RD: if(f->flags&STRING) return EOF; @@ -17,6 +20,8 @@ else n = f->bufl; cnt=read(f->fd, f->buf, n); + if(f->state == CLOSED) + return EOF; switch(cnt){ case -1: f->state=ERR; return EOF; case 0: f->state=END; return EOF; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/_IO_newfile.c /sys/src/ape/lib/ap/stdio/_IO_newfile.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/_IO_newfile.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/ap/stdio/_IO_newfile.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,27 @@ +/* + * pANS stdio -- fopen + */ +#include "iolib.h" + +#define _PLAN9_SOURCE +#include + +FILE *_IO_newfile(void) +{ + static FILE *fx=0; + static Lock fl; + FILE *f; + int i; + + lock(&fl); + for(i=0; i= &_IO_stream[FOPEN_MAX]) fx=_IO_stream; + if(fx->state==CLOSED) + break; + } + f = fx; + unlock(&fl); + if(f->state!=CLOSED) + return NULL; + return f; +} diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/_IO_putc.c /sys/src/ape/lib/ap/stdio/_IO_putc.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/_IO_putc.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/_IO_putc.c Sat Jan 4 00:00:00 2014 @@ -19,7 +19,8 @@ case CLOSED: return EOF; case OPEN: - _IO_setvbuf(f); + if(_IO_setvbuf(f)!=0) + return EOF; /* fall through */ case RDWR: case END: diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/_fconv.c /sys/src/ape/lib/ap/stdio/_fconv.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/_fconv.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/_fconv.c Sat Jan 4 00:00:00 2014 @@ -103,9 +103,9 @@ } int -_hi0bits(register unsigned long x) +_hi0bits(unsigned long x) { - register int k = 0; + int k = 0; if (!(x & 0xffff0000)) { k = 16; @@ -134,8 +134,8 @@ static int lo0bits(unsigned long *y) { - register int k; - register unsigned long x = *y; + int k; + unsigned long x = *y; if (x & 7) { if (x & 1) diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/atexit.c /sys/src/ape/lib/ap/stdio/atexit.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/atexit.c Fri Feb 1 00:00:00 2013 +++ /sys/src/ape/lib/ap/stdio/atexit.c Sat Jan 4 00:00:00 2014 @@ -1,12 +1,13 @@ #include -#define NONEXIT 34 -extern void (*_atexitfns[NONEXIT])(void); +#include + +extern void (*_atexitfns[ATEXIT_MAX])(void); int atexit(void (*f)(void)) { int i; - for(i=0; i -#define NONEXIT 34 -void (*_atexitfns[NONEXIT])(void); -void _doatexits(void){ +#include + +void (*_atexitfns[ATEXIT_MAX])(void); + +void +_doatexits(void) +{ int i; void (*f)(void); - for(i = NONEXIT-1; i >= 0; i--) + + for(i = ATEXIT_MAX-1; i >= 0; i--) if(_atexitfns[i]){ f = _atexitfns[i]; - _atexitfns[i] = 0; /* self defense against bozos */ + _atexitfns[i] = NULL; /* self defense against bozos */ (*f)(); } } + void exit(int status) { _doatexits(); diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/fclose.c /sys/src/ape/lib/ap/stdio/fclose.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/fclose.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/fclose.c Sat Jan 4 00:00:00 2014 @@ -3,12 +3,28 @@ */ #include "iolib.h" int fclose(FILE *f){ - int error=0; + int d, error=0; + char *p; + if(!f) return EOF; if(f->state==CLOSED) return EOF; if(fflush(f)==EOF) error=EOF; - if(f->flags&BALLOC) free(f->buf); - if(!(f->flags&STRING) && close(f->fd)<0) error=EOF; + if(f->flags&BALLOC){ + if((p = f->buf)!=0){ + f->buf = 0; + f->wp = 0; + f->rp = 0; + f->lp = 0; + free(p); + } + } + if(!(f->flags&STRING)){ + if((d = f->fd)>=0){ + f->fd = -1; + if(close(d) < 0) + error = EOF; + } + } f->state=CLOSED; f->flags=0; return error; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/fdopen.c /sys/src/ape/lib/ap/stdio/fdopen.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/fdopen.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/fdopen.c Sat Jan 4 00:00:00 2014 @@ -14,10 +14,8 @@ */ FILE *fdopen(const int fd, const char *mode){ FILE *f; - for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++) - if(f->state==CLOSED) - break; - if(f==&_IO_stream[FOPEN_MAX]) + + if((f = _IO_newfile()) == NULL) return NULL; f->fd=fd; if(mode[0]=='a') diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/fflush.c /sys/src/ape/lib/ap/stdio/fflush.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/fflush.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/fflush.c Sat Jan 4 00:00:00 2014 @@ -21,7 +21,8 @@ case WR: cnt=(f->flags&LINEBUF?f->lp:f->wp)-f->buf; if(cnt && write(f->fd, f->buf, cnt)!=cnt){ - f->state=ERR; + if(f->state != CLOSED) + f->state = ERR; return EOF; } f->rp=f->wp=f->buf; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/fopen.c /sys/src/ape/lib/ap/stdio/fopen.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/fopen.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/fopen.c Sat Jan 4 00:00:00 2014 @@ -2,10 +2,11 @@ * pANS stdio -- fopen */ #include "iolib.h" + FILE *fopen(const char *name, const char *mode){ FILE *f; - for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++) - if(f->state==CLOSED) - return freopen(name, mode, f); - return NULL; + + if((f = _IO_newfile()) == NULL) + return NULL; + return freopen(name, mode, f); } diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/fread.c /sys/src/ape/lib/ap/stdio/fread.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/fread.c Thu Dec 8 00:00:00 2005 +++ /sys/src/ape/lib/ap/stdio/fread.c Sat Jan 4 00:00:00 2014 @@ -12,7 +12,7 @@ s=(char *)p; n=recl*nrec; - while(n>0){ + while(n>0 && f->state!=CLOSED){ d=f->wp-f->rp; if(d>0){ if(d>n) @@ -20,10 +20,11 @@ memcpy(s, f->rp, d); f->rp+=d; }else{ - if(n >= BIGN && f->state==RD && !(f->flags&STRING) && f->buf!=f->unbuf){ + if(f->buf==f->unbuf || (n >= BIGN && f->state==RD && !(f->flags&STRING))){ d=read(f->fd, s, n); if(d<=0){ - f->state=(d==0)?END:ERR; + if(f->state!=CLOSED) + f->state=(d==0)?END:ERR; goto ret; } }else{ diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/fwrite.c /sys/src/ape/lib/ap/stdio/fwrite.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/fwrite.c Mon Nov 25 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/fwrite.c Sat Jan 4 00:00:00 2014 @@ -12,7 +12,7 @@ s=(char *)p; n=recl*nrec; - while(n>0){ + while(n>0 && f->state!=CLOSED){ d=f->rp-f->wp; if(d>0){ if(d>n) @@ -20,13 +20,14 @@ memcpy(f->wp, s, d); f->wp+=d; }else{ - if(n>=BIGN && f->state==WR && !(f->flags&(STRING|LINEBUF)) && f->buf!=f->unbuf){ + if(f->buf==f->unbuf || (n>=BIGN && f->state==WR && !(f->flags&(STRING|LINEBUF)))){ d=f->wp-f->buf; if(d>0){ if(f->flags&APPEND) lseek(f->fd, 0L, SEEK_END); if(write(f->fd, f->buf, d)!=d){ - f->state=ERR; + if(f->state!=CLOSED) + f->state=ERR; goto ret; } f->wp=f->rp=f->buf; @@ -35,7 +36,8 @@ lseek(f->fd, 0L, SEEK_END); d=write(f->fd, s, n); if(d<=0){ - f->state=ERR; + if(f->state!=CLOSED) + f->state=ERR; goto ret; } }else{ diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/iolib.h /sys/src/ape/lib/ap/stdio/iolib.h --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/iolib.h Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/iolib.h Sat Jan 4 00:00:00 2014 @@ -42,3 +42,4 @@ FILE *_IO_sopenr(const char*); FILE *_IO_sopenw(void); char *_IO_sclose(FILE *); +FILE *_IO_newfile(void); diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/mkfile /sys/src/ape/lib/ap/stdio/mkfile --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/mkfile Thu Jan 31 00:00:00 2013 +++ /sys/src/ape/lib/ap/stdio/mkfile Sat Jan 4 00:00:00 2014 @@ -2,6 +2,7 @@ <$APE/config LIB=/$objtype/lib/ape/libap.a OFILES=\ + _IO_newfile.$O\ _IO_getc.$O\ _IO_putc.$O\ _dtoa.$O\ @@ -66,4 +67,4 @@ state=RD; case RD: @@ -46,6 +47,8 @@ break; } cnt=read(f->fd, f->wp, cnt); + if(f->state==CLOSED) + return NULL; if(cnt==-1){ f->state=ERR; return NULL; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/snprintf.c /sys/src/ape/lib/ap/stdio/snprintf.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/snprintf.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/stdio/snprintf.c Sat Jan 4 00:00:00 2014 @@ -1,6 +1,8 @@ /* * pANS stdio -- sprintf */ +#define _C99_SNPRINTF_EXTENSION + #include "iolib.h" int snprintf(char *buf, size_t nbuf, const char *fmt, ...){ diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/sopenr.c /sys/src/ape/lib/ap/stdio/sopenr.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/sopenr.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/sopenr.c Sat Jan 4 00:00:00 2014 @@ -6,8 +6,9 @@ FILE *_IO_sopenr(const char *s){ FILE *f; - for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++) if(f->state==CLOSED) break; - if(f==&_IO_stream[FOPEN_MAX]) return NULL; + + if((f=_IO_newfile())==NULL) + return NULL; f->buf=f->rp=(char *)s; /* what an annoyance const is */ f->bufl=strlen(s); f->wp=f->buf+f->bufl; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/sopenw.c /sys/src/ape/lib/ap/stdio/sopenw.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/sopenw.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/ap/stdio/sopenw.c Sat Jan 4 00:00:00 2014 @@ -5,8 +5,9 @@ FILE *_IO_sopenw(void){ FILE *f; - for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++) if(f->state==CLOSED) break; - if(f==&_IO_stream[FOPEN_MAX]) return NULL; + + if((f=_IO_newfile())==NULL) + return NULL; f->buf=f->rp=f->wp=0; f->state=OPEN; f->flags=STRING; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/strtod.c /sys/src/ape/lib/ap/stdio/strtod.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/strtod.c Wed Feb 3 00:00:00 2010 +++ /sys/src/ape/lib/ap/stdio/strtod.c Sat Jan 4 00:00:00 2014 @@ -42,7 +42,7 @@ static double ulp(double xarg) { - register long L; + long L; Dul a; Dul x; diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/vfprintf.c /sys/src/ape/lib/ap/stdio/vfprintf.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/vfprintf.c Wed Jun 16 00:00:00 2004 +++ /sys/src/ape/lib/ap/stdio/vfprintf.c Sat Jan 4 00:00:00 2014 @@ -6,6 +6,9 @@ #include #include #include +#define _SUSV2_SOURCE +#include + /* * Leading flags */ @@ -202,13 +205,13 @@ nprint++; } } - return ferror(f)? -1: nprint;; + return ferror(f)? -1: nprint; } static int ocvt_c(FILE *f, va_list *args, int flags, int width, int precision) { -#pragma ref precision + USED(precision); int i; if(!(flags&LEFT)) for(i=1; i #include #include +#define _PLAN9_SOURCE +#include + static int icvt_f(FILE *f, va_list *args, int store, int width, int type); static int icvt_x(FILE *f, va_list *args, int store, int width, int type); static int icvt_sq(FILE *f, va_list *args, int store, int width, int type); @@ -59,12 +62,16 @@ #define wungetc(c, f) (++width, nungetc(c, f)) static int nread, ncvt; static const char *fmtp; +static QLock scanlock; /* lazy solution */ -int vfscanf(FILE *f, const char *s, va_list args){ +static int +vfscanf0(FILE *f, const char *s, va_list args) +{ int c, width, type, store; nread=0; ncvt=0; fmtp=s; + for(;*fmtp;fmtp++) switch(*fmtp){ default: if(isspace(*fmtp)){ @@ -105,9 +112,21 @@ } return ncvt; } + +int +vfscanf(FILE *f, const char *s, va_list args) +{ + int r; + + qlock(&scanlock); + r = vfscanf0(f, s, args); + qunlock(&scanlock); + + return r; +} + static int icvt_n(FILE *f, va_list *args, int store, int width, int type){ -#pragma ref f -#pragma ref width + USED(f, width); if(store){ --ncvt; /* this assignment doesn't count! */ switch(type){ @@ -279,10 +298,12 @@ return 1; } static int icvt_s(FILE *f, va_list *args, int store, int width, int type){ -#pragma ref type int c, nn; - register char *s; + char *s; + + USED(type); if(store) s=va_arg(*args, char *); + else s=NULL; do c=ngetc(f); while(isspace(c)); @@ -307,10 +328,12 @@ return 1; } static int icvt_c(FILE *f, va_list *args, int store, int width, int type){ -#pragma ref type int c; - register char *s; + char *s; + + USED(type); if(store) s=va_arg(*args, char *); + else s=NULL; if(width<0) width=1; for(;;){ wgetc(c, f, Done); @@ -339,15 +362,17 @@ return !ok; } static int icvt_sq(FILE *f, va_list *args, int store, int width, int type){ -#pragma ref type int c, nn; - register char *s; - register const char *pat; + char *s; + const char *pat; + + USED(type); pat=++fmtp; if(*fmtp=='^') fmtp++; if(*fmtp!='\0') fmtp++; while(*fmtp!='\0' && *fmtp!=']') fmtp++; if(store) s=va_arg(*args, char *); + else s=NULL; nn=0; for(;;){ wgetc(c, f, Done); diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/vsnprintf.c /sys/src/ape/lib/ap/stdio/vsnprintf.c --- /n/sources/plan9/sys/src/ape/lib/ap/stdio/vsnprintf.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/ap/stdio/vsnprintf.c Sat Jan 4 00:00:00 2014 @@ -1,6 +1,8 @@ /* * pANS stdio -- vsnprintf */ +#define _C99_SNPRINTF_EXTENSION + #include "iolib.h" int vsnprintf(char *buf, size_t nbuf, const char *fmt, va_list args){ diff -Nru /n/sources/plan9/sys/src/ape/lib/auth/authsrv.h /sys/src/ape/lib/auth/authsrv.h --- /n/sources/plan9/sys/src/ape/lib/auth/authsrv.h Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/auth/authsrv.h Sat Jan 4 00:00:00 2014 @@ -0,0 +1,18 @@ +enum +{ + ANAMELEN= 28, /* name max size in previous proto */ + AERRLEN= 64, /* errstr max size in previous proto */ + DOMLEN= 48, /* authentication domain name length */ + DESKEYLEN= 7, /* encrypt/decrypt des key length */ + CHALLEN= 8, /* plan9 sk1 challenge length */ + NETCHLEN= 16, /* max network challenge length (used in AS protocol) */ + CONFIGLEN= 14, + SECRETLEN= 32, /* secret max size */ + + KEYDBOFF= 8, /* bytes of random data at key file's start */ + OKEYDBLEN= ANAMELEN+DESKEYLEN+4+2, /* old key file entry length */ + KEYDBLEN= OKEYDBLEN+SECRETLEN, /* key file entry length */ + OMD5LEN= 16, +}; + +extern int passtokey(char*, char*); diff -Nru /n/sources/plan9/sys/src/ape/lib/auth/fcall.h /sys/src/ape/lib/auth/fcall.h --- /n/sources/plan9/sys/src/ape/lib/auth/fcall.h Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/auth/fcall.h Sat Jan 4 00:00:00 2014 @@ -0,0 +1,20 @@ +#define VERSION9P "9P2000" +#define MAXWELEM 16 + +#define GBIT8(p) ((p)[0]) +#define GBIT16(p) ((p)[0]|((p)[1]<<8)) +#define GBIT32(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) +#define GBIT64(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\ + ((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32)) + +#define PBIT8(p,v) (p)[0]=(v) +#define PBIT16(p,v) (p)[0]=(v);(p)[1]=(v)>>8 +#define PBIT32(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24 +#define PBIT64(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\ + (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56 + +#define BIT8SZ 1 +#define BIT16SZ 2 +#define BIT32SZ 4 +#define BIT64SZ 8 +#define QIDSZ (BIT8SZ+BIT32SZ+BIT64SZ) diff -Nru /n/sources/plan9/sys/src/ape/lib/auth/mkfile /sys/src/ape/lib/auth/mkfile --- /n/sources/plan9/sys/src/ape/lib/auth/mkfile Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/auth/mkfile Sat Jan 4 00:00:00 2014 @@ -0,0 +1,39 @@ +APE=/sys/src/ape +<$APE/config + +LIB=/$objtype/lib/ape/libauth.a +OFILES=\ + amount.$O\ + amount_getkey.$O\ + attr.$O\ + auth_attr.$O\ + auth_challenge.$O\ + auth_chuid.$O\ + auth_getkey.$O\ + auth_getuserpasswd.$O\ + auth_proxy.$O\ + auth_respond.$O\ + auth_rpc.$O\ + auth_userpasswd.$O\ + auth_wep.$O\ + login.$O\ +# newns.$O\ +# noworld.$O\ + +HFILES=\ + /sys/include/ape/auth.h\ + /sys/src/libauth/authlocal.h\ + ../9/libc.h + +UPDATE=\ + mkfile\ + $HFILES\ + ${OFILES:%.$O=%.c}\ + ${LIB:/$objtype/%=/386/%}\ + +ctl); p = strrchr(name, '/'); strcpy(p+1, a); fd = open(name, O_RDONLY); - if(fd >= 0){ - n = read(fd, name, sizeof(name)-1); - if(n > 0){ - name[n] = 0; - p = strchr(name, '!'); - if(p){ - *p++ = 0; - ip->sin_family = AF_INET; - ip->sin_port = htons(atoi(p)); - ip->sin_addr.s_addr = inet_addr(name); - if(alen) - *alen = sizeof(struct sockaddr_in); - } - } + if(fd < 0) + return; + n = read(fd, name, sizeof(name)-1); + if(n < 0){ close(fd); + return; } + name[n] = 0; + if((p = strchr(name, '!')) != nil){ + *p++ = 0; + /* + * allow a AF_INET listen to accept a AF_INET6 call + * so a machine with ip4 and ip6 addresses can accept either. + */ + if(strchr(p, ':') != nil){ + ip = (struct sockaddr_in*)sa; + ip->sin_family = AF_INET; + ip->sin_port = htons(atoi(p)); + ip->sin_addr.s_addr = inet_addr(name); + if(alen) + *alen = sizeof(struct sockaddr_in); + }else{ + ip6 = (struct sockaddr_in6*)sa; + ip6->sin6_family = AF_INET6; + ip6->sin6_port = htons(atoi(p)); + inet_pton(AF_INET6, name, &ip6->sin6_addr); + if(alen) + *alen = sizeof(struct sockaddr_in6); + } + } + close(fd); } diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/_sock_ipattr.c /sys/src/ape/lib/bsd/_sock_ipattr.c --- /n/sources/plan9/sys/src/ape/lib/bsd/_sock_ipattr.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/bsd/_sock_ipattr.c Sat Jan 4 00:00:00 2014 @@ -1,7 +1,7 @@ /* posix */ #include #include -#include +#include /* bsd extensions */ #include @@ -16,30 +16,11 @@ int _sock_ipattr(char *name) { - char *p; - int dot = 0; - int alpha = 0; + struct in6_addr ia6; - for(p = name; *p; p++){ - if(isdigit(*p)){ - ; - }else if(isalpha(*p) || *p == '-') - alpha = 1; - else if(*p == '.') - dot = 1; - else - return Tsys; - } - - if(alpha){ - if(dot) - return Tdom; - else - return Tsys; - } - - if(dot) + if(inet_pton(AF_INET6, name, &ia6) == 1) return Tip; - else - return Tsys; + if(strchr(name, '.') != nil) + return Tdom; + return Tsys; } diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/_sock_ntop.c /sys/src/ape/lib/bsd/_sock_ntop.c --- /n/sources/plan9/sys/src/ape/lib/bsd/_sock_ntop.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/bsd/_sock_ntop.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,43 @@ +/* posix */ +#include +#include +#include +#include +#include +#include +#include + +/* bsd extensions */ +#include +#include +#include +#include + +#include "priv.h" + +void +_sock_ntop(int af, const void *addr, char *ip, int nip, int *port) +{ + struct sockaddr_in *a; + struct sockaddr_in6 *a6; + + switch(af){ + default: + abort(); + case AF_INET: + a = (struct sockaddr_in*)addr; + if(port != nil) + *port = ntohs(a->sin_port); + if(ip != nil) + inet_ntop(af, &a->sin_addr, ip, nip); + break; + case AF_INET6: + a6 = (struct sockaddr_in6*)addr; + if(port != nil) + *port = ntohs(a6->sin6_port); + if(ip != nil) + inet_ntop(af, &a6->sin6_addr, ip, nip); + break; + } +} + diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/accept.c /sys/src/ape/lib/bsd/accept.c --- /n/sources/plan9/sys/src/ape/lib/bsd/accept.c Tue Sep 17 00:00:00 2013 +++ /sys/src/ape/lib/bsd/accept.c Sat Jan 4 00:00:00 2014 @@ -21,7 +21,6 @@ { int n, nfd, cfd; Rock *r, *nr; - struct sockaddr_in *ip; char name[Ctlsize]; char file[8+Ctlsize+1]; char *net; @@ -34,16 +33,17 @@ switch(r->domain){ case PF_INET: + case PF_INET6: switch(r->stype){ + default: + errno = EPROTONOSUPPORT; + return -1; case SOCK_DGRAM: net = "udp"; break; case SOCK_STREAM: net = "tcp"; break; - default: - net = "gok"; - break; } /* get control file name from listener process */ @@ -72,11 +72,10 @@ } /* get remote address */ - ip = (struct sockaddr_in*)&nr->raddr; - _sock_ingetaddr(nr, ip, &n, "remote"); - if(a){ - memmove(a, ip, sizeof(struct sockaddr_in)); - *alen = sizeof(struct sockaddr_in); + _sock_ingetaddr(nr, &nr->raddr, &n, "remote"); + if(a != nil){ + memmove(a, &nr->raddr, n); + *alen = n; } return nfd; diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/bind.c /sys/src/ape/lib/bsd/bind.c --- /n/sources/plan9/sys/src/ape/lib/bsd/bind.c Tue Sep 2 00:00:00 2008 +++ /sys/src/ape/lib/bsd/bind.c Sat Jan 4 00:00:00 2014 @@ -24,10 +24,9 @@ int bind(int fd, void *a, int alen) { - int n, len, cfd; + int n, len, cfd, port; Rock *r; char msg[128]; - struct sockaddr_in *lip; /* assign the address */ r = _sock_findrock(fd, 0); @@ -42,29 +41,30 @@ memmove(&r->addr, a, alen); /* the rest is IP sepecific */ - if (r->domain != PF_INET) - return 0; - - cfd = open(r->ctl, O_RDWR); - if(cfd < 0){ - errno = EBADF; - return -1; - } - lip = (struct sockaddr_in*)&r->addr; - if(lip->sin_port > 0) - snprintf(msg, sizeof msg, "bind %d", ntohs(lip->sin_port)); - else - strcpy(msg, "bind *"); - n = write(cfd, msg, strlen(msg)); - if(n < 0){ - errno = EOPNOTSUPP; /* Improve error reporting!!! */ + switch(r->domain){ + case PF_INET: + case PF_INET6: + cfd = open(r->ctl, O_RDWR); + if(cfd < 0){ + errno = EBADF; + return -1; + } + _sock_ntop(r->domain, &r->addr, nil, 0, &port); + if(port > 0) + snprintf(msg, sizeof msg, "bind %d", port); + else + strcpy(msg, "bind *"); + n = write(cfd, msg, strlen(msg)); + if(n < 0){ + errno = EOPNOTSUPP; /* Improve error reporting!!! */ + close(cfd); + return -1; + } close(cfd); - return -1; - } - close(cfd); - if(lip->sin_port <= 0) - _sock_ingetaddr(r, lip, &len, "local"); + if(port <= 0) + _sock_ingetaddr(r, &r->addr, &len, "local"); + } return 0; } diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/connect.c /sys/src/ape/lib/bsd/connect.c --- /n/sources/plan9/sys/src/ape/lib/bsd/connect.c Tue Sep 17 00:00:00 2013 +++ /sys/src/ape/lib/bsd/connect.c Sat Jan 4 00:00:00 2014 @@ -6,13 +6,13 @@ #include #include #include +#include /* bsd extensions */ #include #include #include #include -#include #include "priv.h" @@ -20,14 +20,13 @@ connect(int fd, void *a, int alen) { Rock *r; - int n, cfd, nfd; - char msg[8+256+1], file[8+256+1]; - struct sockaddr_in *lip, *rip; + int n, cfd, nfd, lport, rport; + char msg[8+256+1], file[8+256+1], rip[48], *rflag; struct sockaddr_un *runix; static int vers; r = _sock_findrock(fd, 0); - if(r == 0){ + if(r == nil){ errno = ENOTSOCK; return -1; } @@ -39,23 +38,23 @@ switch(r->domain){ case PF_INET: + case PF_INET6: /* set up a tcp or udp connection */ cfd = open(r->ctl, O_RDWR); if(cfd < 0){ _syserrno(); return -1; } - rip = a; - lip = (struct sockaddr_in*)&r->addr; - if(lip->sin_port) + + _sock_ntop(r->domain, &r->raddr, rip, sizeof rip, &rport); + _sock_ntop(r->domain, &r->addr, nil, 0, &lport); + rflag = r->reserved? "!r": ""; + if(lport) snprintf(msg, sizeof msg, "connect %s!%d%s %d", - inet_ntoa(rip->sin_addr), ntohs(rip->sin_port), - r->reserved ? "!r" : "", - ntohs(lip->sin_port)); + rip, rport, rflag, lport); else snprintf(msg, sizeof msg, "connect %s!%d%s", - inet_ntoa(rip->sin_addr), ntohs(rip->sin_port), - r->reserved ? "!r" : ""); + rip, rport, rflag); n = write(cfd, msg, strlen(msg)); if(n < 0){ _syserrno(); diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/gai_strerr.c /sys/src/ape/lib/bsd/gai_strerr.c --- /n/sources/plan9/sys/src/ape/lib/bsd/gai_strerr.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/bsd/gai_strerr.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,31 @@ +#include +#include +#include + +#define nil ((void*)0) +#define nelem(a) (sizeof(a)/sizeof((a)[0])) + +char *gaitab[] = { +[-EAI_BADFLAGS] "bad flags", +[-EAI_NONAME] "authoratitive negative response", +[-EAI_AGAIN] "temporary lookup failure", +[-EAI_FAIL] "name resolution failure", +[-EAI_FAMILY] "family not supported", +[-EAI_SOCKTYPE] "ai_socktype not supported", +[-EAI_SERVICE] "srvname unsupported", +[-EAI_MEMORY] "no memory", +[-EAI_SYSTEM] "see errno", +[-EAI_OVERFLOW] "overflow", +}; + +const char* +gai_strerror(int error) +{ + unsigned int e; + + e = -error; + if(e <= nelem(gaitab) && gaitab[e] != nil) + return gaitab[e]; + return "bogus gai_strerror argument"; +} + diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/getaddrinfo.c /sys/src/ape/lib/bsd/getaddrinfo.c --- /n/sources/plan9/sys/src/ape/lib/bsd/getaddrinfo.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/bsd/getaddrinfo.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,360 @@ +#define _SUSV2_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +static const struct addrinfo defhints = { +.ai_flags = AI_ALL, +.ai_family = PF_UNSPEC, +.ai_socktype = 0, +.ai_protocol = 0, +}; + +#define nil ((void*)0) +#define nelem(a) (sizeof(a)/sizeof((a)[0])) + +static int +chkfamily(int f) +{ + switch(f){ + default: + return -1; + case PF_UNSPEC: + case PF_INET: + case PF_INET6: + return 0; + } +} + +static struct { + char *s; + int proto; + int type; +} sockttab[] = { + "tcp", IPPROTO_TCP, SOCK_STREAM, + "il", IPPROTO_RAW, SOCK_STREAM, + "udp", IPPROTO_UDP, SOCK_DGRAM, + "icmp", IPPROTO_ICMP, SOCK_RAW, + "icmpv6", IPPROTO_ICMP, SOCK_RAW, +}; + +typedef struct Storage Storage; +struct Storage { + struct addrinfo ai; + struct sockaddr sa; + char buf[64]; +}; + +#define Strround(s) ((strlen(s)+1)+7 & ~7) + +static int +copyout(Storage *storage, int ns, int totsz, struct addrinfo *hint, struct addrinfo **res) +{ + char *p; + unsigned char *m; + int i; + Storage *s; + struct addrinfo *ai; + struct sockaddr *sa; + + m = malloc(totsz); + if(m == nil) + return EAI_MEMORY; + memset(m, 0, totsz); + *res = (void*)m; + + for(i = 0; i < ns; i++){ + s = storage + i; + sa = &s->sa; + + ai = (struct addrinfo*)m; + m += sizeof *ai; + ai->ai_addr = (struct sockaddr*)m; + m += s->ai.ai_addrlen; + + ai->ai_addrlen = s->ai.ai_addrlen; + memmove(ai->ai_addr, sa, s->ai.ai_addrlen); + ai->ai_family = s->ai.ai_family; + ai->ai_flags = hint->ai_flags; + ai->ai_socktype = s->ai.ai_socktype; + ai->ai_protocol = s->ai.ai_protocol; + + if(hint->ai_flags & AI_CANONNAME){ + ai->ai_canonname =(char*)m; + p = s->buf; + m += Strround(p); + memcpy(ai->ai_canonname, p, strlen(p)); + } + + if(i+1 < ns) + ai->ai_next = (struct addrinfo*)m; + } + return 0; +} + +static int +canon(int fd, Storage *a, int ns, int *totsz, struct addrinfo *hint) +{ + char buf[128], *f[15], *p; + int i, j, n, best, diff; + Storage *s; + + for(i = 0; i < ns; i++){ + s = a+i; + + lseek(fd, 0, 0); + if(s->buf[0] != 0 && (hint->ai_flags & AI_PASSIVE) == 0) + snprintf(buf, sizeof buf, "!ipinfo ip=%s sys dom", s->buf); + else + snprintf(buf, sizeof buf, "!ipinfo sys dom"); + if(write(fd, buf, strlen(buf)) == -1) + return EAI_FAIL; + lseek(fd, 0, 0); + n = read(fd, buf, sizeof buf-1); + if(n <= 0) + continue; + buf[n] = 0; + + // n = tokenize(buf, f, nelem(f)); + p = buf; + best = -1; + for(j = 0; j < n; j++){ + f[j] = p; + p = strchr(f[j], ' '); + if(p != nil) + *p++ = 0; + + if(strncmp(f[j], "dom=", 4) == 0) + break; + if(best == 0) + if(strncmp(f[j], "sys=", 4) == 0) + best = i; + + if(p == nil) + break; + } + if(j == n && best != -1) + j = best; + while((read(fd, buf, sizeof buf)) > 0) + ; + + if(j != n){ + p = strchr(f[j], '=')+1; + diff = Strround(s->buf) - Strround(p); + memset(s->buf, 0, sizeof s->buf); + memcpy(s->buf, p, strlen(p)); + *totsz -= diff; + } + } + return 0; +} + +static int +docsquery(char *nettype, char *host, char *service, struct addrinfo *hint, struct addrinfo **res) +{ + char buf[128], *p, *q, *r, *net; + int i, fd, rv, n, ns, af, sz, totsz; + struct sockaddr_in *in; + struct sockaddr_in6 *in6; + Storage storage[6]; + + fd = open("/net/cs", O_RDWR); + if(fd < 0) + return EAI_FAIL; + + snprintf(buf, sizeof buf, "%s!%s!%s", nettype, host, service); + if(write(fd, buf, strlen(buf)) == -1){ + close(fd); + return EAI_FAIL; + } + + lseek(fd, 0, 0); + totsz = 0; + for(ns = 0; ns < nelem(storage);){ + n = read(fd, buf, sizeof buf - 1); + if(n < 1) + break; + buf[n] = 0; + if((p = strchr(buf, ' ')) == nil) + continue; + *p++ = 0; + + if(strstr(buf, "!fasttimeout") != nil) + continue; + if((q = strchr(p, '!')) == nil) + q = ""; + else + *q++ = 0; + + if(strcmp(host, "*") == 0){ + q = p; + if(hint->ai_family == AF_INET6) + p = "::"; + else + p = "0.0.0.0"; + } + if(strlen(p) >= sizeof storage[0].buf) + continue; + + /* wrong for passive, except for icmp6 */ + af = AF_INET; + if(strchr(p, ':') != nil) + af = AF_INET6; + + if(hint->ai_family != AF_UNSPEC && af != hint->ai_family) + continue; + + sz = 0; + memset(&storage[ns], 0, sizeof(storage[ns])); + if(hint->ai_flags & AI_CANONNAME){ + memcpy(storage[ns].buf, p, strlen(p)); + sz += Strround(p); + } + + storage[ns].ai.ai_socktype = SOCK_DGRAM; + net = "tcp"; + r = strrchr(buf, '/'); + if(r != nil && strcmp(r, "/clone") == 0){ + *r = 0; + r = strrchr(buf, '/'); + if(r != nil) + net = r+1; + } + for(i = 0; i < nelem(sockttab); i++) + if(strcmp(sockttab[i].s, net) == 0) + if(sockttab[i].proto != IPPROTO_RAW || hint->ai_protocol == IPPROTO_RAW){ + storage[ns].ai.ai_socktype = sockttab[i].type; + storage[ns].ai.ai_protocol = sockttab[i].proto; + break; + } + if(i == nelem(sockttab)) + continue; + + storage[ns].ai.ai_family = af; + switch(af){ + case AF_INET: + in = (struct sockaddr_in*)&storage[ns].sa; + in->sin_family = af; + in->sin_addr.s_addr = inet_addr(p); + in->sin_port = ntohs(atoi(q)); + storage[ns].ai.ai_addrlen = sizeof *in; + sz += sizeof *in; + break; + case AF_INET6: + storage[ns].ai.ai_family = af; + in6 = (struct sockaddr_in6*)&storage[ns].sa; + in6->sin6_family = af; + inet_pton(af, p, &in6->sin6_addr); + in6->sin6_port = ntohs(atoi(q)); + storage[ns].ai.ai_addrlen = sizeof *in6; + sz += sizeof *in6; + break; + } + + totsz += sz + sizeof(struct addrinfo); + ns++; + + /* hacky way to get udp */ + if(strcmp(nettype, "net") == 0 && hint->ai_protocol == 0) + if(ns < nelem(storage)){ + storage[ns] = storage[ns-1]; + storage[ns].ai.ai_protocol = IPPROTO_UDP; + totsz += sz + sizeof(struct addrinfo); + ns++; + } + } + + rv = 0; + if(hint->ai_flags & AI_CANONNAME) + rv = canon(fd, storage, ns, &totsz, hint); + close(fd); + + if(rv != 0) + return rv; + if(ns == 0) + return EAI_NONAME; + return copyout(storage, ns, totsz, hint, res); +} + +int +getaddrinfo(const char *node, const char *service, const struct addrinfo *hint0, struct addrinfo **res) +{ + char *nettype, *p; + int i; + struct addrinfo hint; + + *res = nil; + + if(node == nil && service == nil) + return EAI_BADFLAGS; + if(hint0 == nil) + hint = defhints; + else + hint = *hint0; + + if(hint.ai_flags & AI_NUMERICSERV){ + if(service == nil) + return EAI_BADFLAGS; + strtoul(service, &p, 0); + if(*p != 0) + return EAI_NONAME; + } + + if(chkfamily(hint.ai_family) == -1) + return EAI_FAMILY; + if(node != nil) + hint.ai_flags &= ~AI_PASSIVE; + + /* not passive and no host → loopback */ + if(node == nil && (hint.ai_flags & AI_PASSIVE) == 0){ + switch(hint.ai_family){ + case PF_UNSPEC: + hint.ai_family = AF_INET; + case PF_INET: + node = "127.1"; + break; + case PF_INET6: + node = "::1"; + break; + } + } + else if (node == nil) + node = "*"; + + nettype = "net"; + switch(hint.ai_socktype){ + for(i = 0; i < nelem(sockttab); i++) + if(sockttab[i].type == hint.ai_socktype) + nettype = sockttab[i].s; + } + if(strcmp(nettype, "net") != 0 && hint.ai_protocol != 0) + return EAI_BADFLAGS; + if(hint.ai_protocol != 0){ + for(i = 0; i < nelem(sockttab); i++) + if(sockttab[i].proto == hint.ai_protocol) + nettype = sockttab[i].s; + } + if(hint.ai_family == PF_INET6 && strcmp(nettype, "icmp") == 0) + nettype = "icmpv6"; + + if(node == nil || *node == 0) + node = "*"; + if(service == nil || *service == 0) + service = "0"; + + return docsquery(nettype, node, service, &hint, res); +} + +void +freeaddrinfo(struct addrinfo *ai) +{ + free(ai); +} diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/gethostbyaddr.c /sys/src/ape/lib/bsd/gethostbyaddr.c --- /n/sources/plan9/sys/src/ape/lib/bsd/gethostbyaddr.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/bsd/gethostbyaddr.c Sat Jan 4 00:00:00 2014 @@ -11,19 +11,10 @@ int h_errno; struct hostent* -gethostbyaddr(void *addr, int len, int type) +gethostbyaddr(void *addr, int len, int af) { - unsigned long y; - struct in_addr x; - unsigned char *p = addr; + char name[64]; - if(type != AF_INET || len != 4){ - h_errno = NO_RECOVERY; - return 0; - } - - y = (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3]; - x.s_addr = htonl(y); - - return gethostbyname(inet_ntoa(x)); + USED(len); + return gethostbyname(inet_ntop(af, addr, name, sizeof name)); } diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/gethostbyname.c /sys/src/ape/lib/bsd/gethostbyname.c --- /n/sources/plan9/sys/src/ape/lib/bsd/gethostbyname.c Tue Sep 17 00:00:00 2013 +++ /sys/src/ape/lib/bsd/gethostbyname.c Sat Jan 4 00:00:00 2014 @@ -26,17 +26,17 @@ * for inet addresses only */ struct hostent* -gethostbyname(const char *name) +gethostbyname(char *name) { int i, t, fd, m; char *p, *bp; - int nn, na; - unsigned long x; + int nn, na, na6; static struct hostent h; static char buf[1024]; static char *nptr[Nname+1]; static char *aptr[Nname+1]; - static char addr[Nname][4]; + static char addr4[Nname][4]; + static char addr6[Nname][16]; h.h_name = 0; t = _sock_ipattr(name); @@ -79,7 +79,7 @@ buf[i] = 0; /* parse the reply */ - nn = na = 0; + nn = na = na6 = 0; for(bp = buf;;){ p = strchr(bp, '='); if(p == 0) @@ -94,15 +94,12 @@ if(nn < Nname) nptr[nn++] = p; } else if(strcmp(bp, "ip") == 0){ - x = inet_addr(p); - x = ntohl(x); - if(na < Nname){ - addr[na][0] = x>>24; - addr[na][1] = x>>16; - addr[na][2] = x>>8; - addr[na][3] = x; - aptr[na] = addr[na]; - na++; + if(strchr(p, ':') != nil){ + if(inet_pton(AF_INET6, p, addr6[na6]) == 1) + na6++; + }else{ + if(inet_pton(AF_INET, p, addr4[na]) == 1) + na++; } } while(*p && *p != ' ') @@ -111,17 +108,29 @@ *p++ = 0; bp = p; } - if(nn+na == 0){ + if(nn+na+na6 == 0){ h_errno = HOST_NOT_FOUND; return 0; } nptr[nn] = 0; - aptr[na] = 0; + + if(na == 0){ + for(i = 0; i < na6; i++) + aptr[i] = addr6[i]; + aptr[i] = 0; + h.h_addrtype = AF_INET6; + h.h_length = 16; + }else{ + for(i = 0; i < na; i++) + aptr[i] = addr4[i]; + aptr[i] = 0; + h.h_addrtype = AF_INET; + h.h_length = 4; + } + h.h_aliases = nptr; h.h_addr_list = aptr; - h.h_length = 4; - h.h_addrtype = AF_INET; if(h.h_name == 0) h.h_name = nptr[0]; if(h.h_name == 0) diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/gethostname.c /sys/src/ape/lib/bsd/gethostname.c --- /n/sources/plan9/sys/src/ape/lib/bsd/gethostname.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/bsd/gethostname.c Sat Jan 4 00:00:00 2014 @@ -6,7 +6,7 @@ #include int -gethostname(char *name, int namelen) +gethostname(char *name, size_t namelen) { int n, fd; char buf[128]; diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/getnameinfo.c /sys/src/ape/lib/bsd/getnameinfo.c --- /n/sources/plan9/sys/src/ape/lib/bsd/getnameinfo.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/bsd/getnameinfo.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,165 @@ +#define _SUSV2_SOURCE +#define _C99_SNPRINTF_EXTENSION +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define nil ((void*)0) + +static int +getport(char *trans, int port, char *srv, int srvlen) +{ + char buf[128], match[5], *p, *q; + int fd, r, n; + + r = EAI_FAIL; + fd = open("/net/cs", O_RDWR); + if(fd < 0) + return r; + snprintf(buf, sizeof buf, "!port=%d %s=*", port, trans); + snprintf(match, sizeof match, "%s=", trans); + if(write(fd, buf, strlen(buf)) == -1){ + close(fd); + return r; + } + + lseek(fd, 0, 0); + n = read(fd, buf, sizeof buf - 1); + if(n > 0){ + buf[n] = 0; + for(p = buf; p != nil; p = q){ + q = strchr(buf, ' '); + if(q != nil) + *q++ = 0; + if(strncmp(p, match, 4) == 0){ + r = snprintf(srv, srvlen, "%s", p+4); + break; + } + } + } + close(fd); + return r; +} + +static int +getname(int af, void *addr, char *host, long hostlen, int flags) +{ + char ipbuf[128], buf[128], *p, *q; + int fd, r, n; + + r = EAI_FAIL; + if(inet_ntop(af, addr, ipbuf, sizeof ipbuf) == nil) + return EAI_SYSTEM; + fd = open("/net/cs", O_RDWR); + if(fd < 0) + return r; + snprintf(buf, sizeof buf, "!ip=%s dom=*", ipbuf); + if(write(fd, buf, strlen(buf)) == -1){ + close(fd); + return r; + } + + lseek(fd, 0, 0); + n = read(fd, buf, sizeof buf - 1); + if(n > 0){ + buf[n] = 0; + for(p = buf; p != nil; p = q){ + q = strchr(buf, ' '); + if(q != nil) + *q++ = 0; + if(strncmp(p, "dom=", 4) == 0){ + r = snprintf(ipbuf, sizeof ipbuf, "%s", p+4); + break; + } + } + } + close(fd); + + if(r >= 0){ + if(flags & NI_NOFQDN){ + p = strchr(ipbuf, '.'); + if(p != nil) + *p = 0; + } + r = EAI_OVERFLOW; + if(snprintf(host, hostlen, "%s", ipbuf) >= 0) + r = 0; + } + return r; +} + +static int +afhinfo(int af, void *addr, int port, char *host, long hostlen, char *srv, long srvlen, int flags) +{ + char *trans; + int r; + + trans = "tcp"; + if(flags & NI_DGRAM) + trans = "udp"; + + if(flags & NI_NUMERICSERV || getport(trans, port, srv, srvlen) < 0) + snprintf(srv, srvlen, "%d", port); + + /* require name even if not returning it */ + if(flags & NI_NAMEREQD){ + r = getname(af, addr, host, hostlen, flags); + if(r < 0) + return r; + } + if(flags & NI_NUMERICHOST){ + if(inet_ntop(af, addr, host, hostlen) == nil) + return EAI_SYSTEM; + return 0; + } + if(getname(af, addr, host, hostlen, flags) == 0) + return 0; + return 0; +} + +int +getnameinfo(const struct sockaddr *sa, int len, char *host, long hostlen, char *srv, long srvlen, int flags) +{ + char fakehost[64], fakesrv[16]; + struct sockaddr_in *in; + struct sockaddr_in6 *in6; + + if(host != nil && hostlen != 0) + *host = 0; + else{ + host = fakehost; + hostlen = sizeof fakehost; + } + if(srv != nil && hostlen != 0) + *srv = 0; + else{ + srv = fakesrv; + srvlen = sizeof fakesrv; + } + + switch(sa->sa_family){ + default: + return EAI_SOCKTYPE; + case AF_INET: + if(len < sizeof *in) + return EAI_OVERFLOW; + in = (struct sockaddr_in*)sa; + return afhinfo(AF_INET, &in->sin_addr, ntohs(in->sin_port), + host, hostlen, srv, srvlen, flags); + case AF_INET6: + if(len < sizeof *in6) + return EAI_OVERFLOW; + in6 = (struct sockaddr_in6*)sa; + return afhinfo(AF_INET6, &in6->sin6_addr, ntohs(in6->sin6_port), + host, hostlen, srv, srvlen, flags); + } +} diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/getopt.c /sys/src/ape/lib/bsd/getopt.c --- /n/sources/plan9/sys/src/ape/lib/bsd/getopt.c Thu Jul 21 00:00:00 2005 +++ /sys/src/ape/lib/bsd/getopt.c Sat Jan 4 00:00:00 2014 @@ -11,8 +11,8 @@ getopt (int argc, char **argv, char *opts) { static int sp = 1; - register c; - register char *cp; + int c; + char *cp; if (sp == 1) if (optind >= argc || diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/getpeername.c /sys/src/ape/lib/bsd/getpeername.c --- /n/sources/plan9/sys/src/ape/lib/bsd/getpeername.c Tue Sep 17 00:00:00 2013 +++ /sys/src/ape/lib/bsd/getpeername.c Sat Jan 4 00:00:00 2014 @@ -16,25 +16,35 @@ #include "priv.h" +static int +connected(Rock *r, int len) +{ + static struct sockaddr niladdr; + + return memcmp(&r->raddr, &niladdr, len) != 0; +} + int getpeername(int fd, void *addr, int *alen) { Rock *r; int i; - struct sockaddr_in *rip; struct sockaddr_un *runix; r = _sock_findrock(fd, 0); - if(r == 0){ + if(r == nil){ errno = ENOTSOCK; return -1; } switch(r->domain){ case PF_INET: - rip = (struct sockaddr_in*)&r->raddr; - memmove(addr, rip, sizeof(struct sockaddr_in)); *alen = sizeof(struct sockaddr_in); + memmove(addr, &r->raddr, *alen); + break; + case PF_INET6: + *alen = sizeof(struct sockaddr_in6); + memmove(addr, &r->raddr, *alen); break; case PF_UNIX: runix = (struct sockaddr_un*)&r->raddr; @@ -44,6 +54,12 @@ break; default: errno = EAFNOSUPPORT; + return -1; + } + + if(!connected(r, *alen)){ + errno = ENOTCONN; + memset(&addr, 0, *alen); /* python depends on this */ return -1; } return 0; diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/getprotobyname.c /sys/src/ape/lib/bsd/getprotobyname.c --- /n/sources/plan9/sys/src/ape/lib/bsd/getprotobyname.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/bsd/getprotobyname.c Sat Jan 4 00:00:00 2014 @@ -24,7 +24,8 @@ static struct protoent r; -struct protoent *getprotobyname(const char *name) { +struct protoent* +getprotobyname(const char *name) { int fd, i, m; char *p, *bp; int nn, na; diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/getservbyaddr.c /sys/src/ape/lib/bsd/getservbyaddr.c --- /n/sources/plan9/sys/src/ape/lib/bsd/getservbyaddr.c Tue Sep 2 00:00:00 2008 +++ /sys/src/ape/lib/bsd/getservbyaddr.c Sat Jan 4 00:00:00 2014 @@ -13,6 +13,6 @@ { char buf[32]; - snprintf(buf, sizeof buf, "%d", port); + snprintf(buf, sizeof buf, "%d", ntohs(port)); return getservbyname(buf, proto); } diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/getservbyname.c /sys/src/ape/lib/bsd/getservbyname.c --- /n/sources/plan9/sys/src/ape/lib/bsd/getservbyname.c Tue Sep 2 00:00:00 2008 +++ /sys/src/ape/lib/bsd/getservbyname.c Sat Jan 4 00:00:00 2014 @@ -49,8 +49,10 @@ } /* construct the query, always expect an ip# back */ - if(num) + if(num && proto != nil) snprintf(buf, sizeof buf, "!port=%s %s=*", name, proto); + else if(num) + snprintf(buf, sizeof buf, "!port=%s", name); else snprintf(buf, sizeof buf, "!%s=%s port=*", proto, name); @@ -76,10 +78,13 @@ if(p == 0) break; *p++ = 0; - if(strcmp(bp, proto) == 0){ + if(proto != nil && strcmp(bp, proto) == 0){ if(nn < Nname) nptr[nn++] = p; - } else if(strcmp(bp, "port") == 0){ + } else if(strcmp(bp, "port") != 0){ + if(nn < Nname) + nptr[nn++] = p; + } else{ s.s_port = htons(atoi(p)); } while(*p && *p != ' ') diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/getsockname.c /sys/src/ape/lib/bsd/getsockname.c --- /n/sources/plan9/sys/src/ape/lib/bsd/getsockname.c Tue Sep 17 00:00:00 2013 +++ /sys/src/ape/lib/bsd/getsockname.c Sat Jan 4 00:00:00 2014 @@ -21,7 +21,6 @@ { Rock *r; int i; - struct sockaddr_in *lip; struct sockaddr_un *lunix; r = _sock_findrock(fd, 0); @@ -32,8 +31,8 @@ switch(r->domain){ case PF_INET: - lip = (struct sockaddr_in*)addr; - _sock_ingetaddr(r, lip, alen, "local"); + case PF_INET6: + _sock_ingetaddr(r, addr, alen, "local"); break; case PF_UNIX: lunix = (struct sockaddr_un*)&r->addr; diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/herror.c /sys/src/ape/lib/bsd/herror.c --- /n/sources/plan9/sys/src/ape/lib/bsd/herror.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/bsd/herror.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,46 @@ +/* posix */ +#include +#include +#include +#include +#include +#include + +/* bsd extensions */ +#include +#include +//#include + +#include "priv.h" + +int h_errno; + +static const char *hetab[] = { +[HOST_NOT_FOUND] "authoritative answer host not found", +[TRY_AGAIN] "non-authoritive host not found", +[NO_RECOVERY] "non recoverable error", +[NO_DATA] "valid name, no data record of requested type" +}; + +static const char* +getmsg(unsigned int e) +{ + const char *p; + + if(e > nelem(hetab) || (p = hetab[e]) == nil) + p = "unknown error"; + return p; +} + +void +herror(const char *s) +{ + fprintf(stderr, "%s: %s", s, getmsg(h_errno)); +} + + +const char* +hstrerror(int err) +{ + return getmsg(err); +} diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/inet_ntop.c /sys/src/ape/lib/bsd/inet_ntop.c --- /n/sources/plan9/sys/src/ape/lib/bsd/inet_ntop.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/bsd/inet_ntop.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,92 @@ +#define _SUSV2_SOURCE +#define _C99_SNPRINTF_EXTENSION +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define nil ((void*)0) + +const char* +inet_ntop(int af, const void *src, char *dst, int size) +{ + char map[16/2], buf[32], *c; + int d, j, n, run, srun, maxrun, maxsrun; + uint8_t *u; + uint32_t i; + struct in_addr *ia; + struct in6_addr *ia6; + + switch(af){ + default: + errno = EAFNOSUPPORT; + return nil; + case AF_INET: + ia = (struct in_addr*)src; + i = ia->s_addr; + i = ntohl(i); + n = snprintf(dst, size, "%d.%d.%d.%d", + i>>24, i>>16 & 0xff, i>>8 & 0xff, i & 0xff); + if(n == -1){ + errno = ENOSPC; + return nil; + } + return dst; + case AF_INET6: + ia6 = (struct in6_addr*)src; + u = ia6->s6_addr; + + srun = run = 0; + maxrun = maxsrun = 0; + for(i = 0; i < 16; i += 2){ + if((u[i]|u[i+1]) == 0){ + map[i/2] = 1; + if(run == 0) + srun = i/2; + run++; + }else{ + if(run > 0 && run > maxrun){ + maxrun = run; + maxsrun = srun; + } + srun = run = 0; + } + } + if(run > 0 && run > maxrun){ + maxrun = run; + maxsrun = srun; + } + + /* buf must be bigger than biggest address, else -1 return gets us */ + memset(buf, 0, sizeof buf); + j = 0; + c = ":"; + for(i = 0; i < 8;){ + if(map[i] && i == maxsrun){ + j += snprintf(buf+j, sizeof buf-j, "%s:", c); + c = ""; + i += maxrun; + }else{ + d = u[i*2]<<8 | u[i*2+1]; + c = i<7? ":": ""; + j += snprintf(buf+j, sizeof buf-j, "%x%s", d, c); + c = ""; + i++; + } + } + if(strlen(buf)+1 > size){ + errno = ENOSPC; + return nil; + } + memcpy(dst, buf, strlen(buf)+1); + return dst; + } +} diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/inet_pton.c /sys/src/ape/lib/bsd/inet_pton.c --- /n/sources/plan9/sys/src/ape/lib/bsd/inet_pton.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/bsd/inet_pton.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,128 @@ +#define _SUSV2_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define nil ((void*)0) +typedef unsigned char uchar; + +int classnetbytes[] = {1, 1, 2, 3, }; + +static char* +parseip4(uchar *u, char *s) +{ + char *v; + int i, d, b, n; + + for(i = 0; i < 4; i++){ + v = s; + d = strtoul(s, &s, 0); + if(d > 255) + return nil; + u[i] = d; + if(*s == '.') + s++; + else if(s == v) + break; + } + if(i < 4 && i > (b = classnetbytes[u[0]>>6])){ + n = i - b; + memmove(u+4-n, u+b, n); + memset(u+b, 0, 4-(b+n)); + i = 4; + } + if(i != 4) + return nil; + return s; +} + +static char* +parseip6(uchar *u, char *s) +{ + char *v; + int i, d, cc, is4; + + is4 = 1; + cc = -1; + for(i = 0; i < 16;){ + v = s; + d = strtoul(s, &s, 16); + switch(*s){ + case '.': + if(i + 4 > 16) + return nil; + s = parseip4(u+i, v); + if(s == nil) + return nil; + i += 4; + break; + case ':': + is4 = 0; + s++; + default: + if(d > 0xffff) + return nil; + u[i++] = d>>8; + u[i++] = d; + if(*s == ':'){ + if(cc != -1) + return nil; + cc = i; + s++; + } + if(s == v) + i -= 2; + break; + } + if(s == v) + break; + } + if(is4 && i == 4){ + memmove(u+12, u, 4); + memset(u, 0, 4); + memset(u+10, 0xff, 2); + } + else if(cc != -1 && i < 16){ + memmove(u+cc+(16-i), u+cc, i-cc); + memset(u+cc, 0, 16-i); + } + else if(i != 16) + return nil; + return s; +} + +int +inet_pton(int af, const char *src, void *dst) +{ + uchar u[16]; + struct in_addr *ia; + struct in6_addr *ia6; + + memset(u, 0, sizeof u); + switch(af){ + default: + errno = EAFNOSUPPORT; + return -1; + case AF_INET: + if(parseip4(u, src) == nil) + return 0; + ia = (struct in_addr*)dst; + memmove(&ia->s_addr, u, 4); + return 1; + case AF_INET6: + if(parseip6(u, src) == nil) + return 0; + ia6 = (struct in6_addr*)dst; + memmove(ia6->s6_addr, u, 16); + return 1; + } +} diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/ip6const.c /sys/src/ape/lib/bsd/ip6const.c --- /n/sources/plan9/sys/src/ape/lib/bsd/ip6const.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/bsd/ip6const.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,5 @@ +#include +#include + +const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; +const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/listen.c /sys/src/ape/lib/bsd/listen.c --- /n/sources/plan9/sys/src/ape/lib/bsd/listen.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/bsd/listen.c Sat Jan 4 00:00:00 2014 @@ -8,6 +8,9 @@ #include #include #include +#include +#define _SUSV2_SOURCE +#include /* socket extensions */ #include @@ -39,17 +42,18 @@ char *p; char listen[Ctlsize]; char name[Ctlsize]; + void *v; switch(r->stype){ + default: + errno = EOPNOTSUPP; + return -1; case SOCK_DGRAM: net = "udp"; break; case SOCK_STREAM: net = "tcp"; break; - default: - net = "gok"; - break; } strcpy(listen, r->ctl); @@ -81,11 +85,14 @@ _muxsid = getpgrp(); } else setpgid(getpid(), _muxsid); - _RENDEZVOUS(2, _muxsid); + while(_RENDEZVOUS((void*)2, (void*)_muxsid) == (void*)~0) + ; break; default: atexit(_killmuxsid); - _muxsid = _RENDEZVOUS(2, 0); + while((v = _RENDEZVOUS((void*)2, 0)) == (void*)~0) + ; + _muxsid = (int)(uintptr_t)v; close(pfd[1]); close(nfd); return 0; @@ -116,12 +123,11 @@ } int -listen(int fd, int) +listen(int fd, int /*backlog*/) { Rock *r; - int n, cfd; + int n, cfd, port; char msg[128]; - struct sockaddr_in *lip; struct sockaddr_un *lunix; r = _sock_findrock(fd, 0); @@ -132,20 +138,20 @@ switch(r->domain){ case PF_INET: + case PF_INET6: cfd = open(r->ctl, O_RDWR); if(cfd < 0){ errno = EBADF; return -1; } - lip = (struct sockaddr_in*)&r->addr; - if(1 || lip->sin_port >= 0) { /* sin_port is unsigned */ + _sock_ntop(r->domain, &r->addr, nil, 0, &port); + if(port != 0 && port != 0xffff) { if(write(cfd, "bind 0", 6) < 0) { errno = EGREG; close(cfd); return -1; } - snprintf(msg, sizeof msg, "announce %d", - ntohs(lip->sin_port)); + snprintf(msg, sizeof msg, "announce %d", port); } else strcpy(msg, "announce *"); diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/lstat.c /sys/src/ape/lib/bsd/lstat.c --- /n/sources/plan9/sys/src/ape/lib/bsd/lstat.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/bsd/lstat.c Sat Jan 4 00:00:00 2014 @@ -9,14 +9,14 @@ } int -symlink(char *, char *) +symlink(char*, char*) { errno = EPERM; return -1; } int -readlink(char *, char *, int ) +readlink(char*, char*, int) { errno = EIO; return -1; diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/mkfile /sys/src/ape/lib/bsd/mkfile --- /n/sources/plan9/sys/src/ape/lib/bsd/mkfile Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/bsd/mkfile Sat Jan 4 00:00:00 2014 @@ -9,10 +9,13 @@ connect.$O\ endhostent.$O\ ffs.$O\ + gai_strerr.$O\ + getaddrinfo.$O\ getdtablesize.$O\ - gethostbyname.$O\ gethostbyaddr.$O\ + gethostbyname.$O\ gethostname.$O\ + getnameinfo.$O\ getopt.$O\ getpeername.$O\ getprotobyname.$O\ @@ -20,9 +23,13 @@ getservbyname.$O\ getsockname.$O\ gettimeofday.$O\ + herror.$O\ inet_addr.$O\ inet_ntoa.$O\ + inet_ntop.$O\ + inet_pton.$O\ ioctl.$O\ + ip6const.$O\ listen.$O\ lstat.$O\ mktemp.$O\ @@ -39,6 +46,7 @@ shutdown.$O\ _sock_ingetaddr.$O\ _sock_ipattr.$O\ + _sock_ntop.$O\ _sock_srv.$O\ strcasecmp.$O\ strncasecmp.$O\ diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/priv.h /sys/src/ape/lib/bsd/priv.h --- /n/sources/plan9/sys/src/ape/lib/bsd/priv.h Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/bsd/priv.h Sat Jan 4 00:00:00 2014 @@ -1,5 +1,8 @@ typedef struct Rock Rock; +#define nil ((void*)0) +#define nelem(a) (sizeof(a)/sizeof((a)[0])) + enum { Ctlsize= 128, @@ -41,6 +44,7 @@ extern int _sock_srv(char*, int); extern int _sock_data(int, char*, int, int, int, Rock**); extern int _sock_ipattr(char*); -extern void _sock_ingetaddr(Rock*, struct sockaddr_in*, int*, char*); +extern void _sock_ingetaddr(Rock*, struct sockaddr*, int*, char*); +extern void _sock_ntop(int, const void*, char*, int , int*); extern void _syserrno(void); diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/putenv.c /sys/src/ape/lib/bsd/putenv.c --- /n/sources/plan9/sys/src/ape/lib/bsd/putenv.c Thu Feb 28 00:00:00 2002 +++ /sys/src/ape/lib/bsd/putenv.c Sat Jan 4 00:00:00 2014 @@ -1,8 +1,56 @@ +#include #include #include #include #include +extern char **environ; + +static int +envredo(char *s) +{ + char *x, **p, *q, **v, *mem; + int n, nsz, nenv, esz; + + x = strchr(s, '='); + if(x == NULL) + return -1; + nsz = x - s + 1; /* compare the var=, not just var */ + + nenv = 1; + esz = strlen(s)+1; + for(p = environ; (q = *p) != NULL; p++){ + esz += strlen(q)+1; + nenv++; + } + + /* overestimate in the case we have changed a variable. */ + v = malloc((nenv+1)*sizeof(char**) + esz); + if(v == NULL) + return -1; + mem = (char*)(v + nenv + 1); + + nenv = 0; + for(p = environ; (q = *p) != NULL; p++){ + if(strncmp(q, s, nsz) == 0) + continue; + v[nenv++] = mem; + n = strlen(q)+1; + memcpy(mem, q, n); + mem += n; + } + v[nenv++] = mem; + n = strlen(s)+1; + memcpy(mem, s, n); + + v[nenv] = NULL; + + free(environ); + environ = v; + + return 0; +} + int putenv(char *s) { @@ -26,7 +74,7 @@ if(write(f, value, n) != n) return -1; close(f); - return 0; + return envredo(s); } else return -1; } diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/rcmd.c /sys/src/ape/lib/bsd/rcmd.c --- /n/sources/plan9/sys/src/ape/lib/bsd/rcmd.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/bsd/rcmd.c Sat Jan 4 00:00:00 2014 @@ -6,6 +6,7 @@ #include #include #include +#include /* socket extensions */ #include @@ -23,6 +24,7 @@ { } +/* no ip6 and i don't care */ int rcmd(char **dst, int port, char *luser, char *ruser, char *cmd, int *fd2p) { @@ -92,6 +94,8 @@ if(write(fd, luser, strlen(luser)+1) < 0 || write(fd, ruser, strlen(ruser)+1) < 0 || write(fd, cmd, strlen(cmd)+1) < 0){ + if(fd2p) + close(lfd); fprintf(stderr, pbotch); return -1; } @@ -116,10 +120,8 @@ /* get reply */ if(read(fd, &c, 1) != 1){ - if(fd2p){ + if(fd2p) close(fd2); - *fd2p = -1; - } fprintf(stderr, pbotch); return -1; } diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/sendto.c /sys/src/ape/lib/bsd/sendto.c --- /n/sources/plan9/sys/src/ape/lib/bsd/sendto.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/bsd/sendto.c Sat Jan 4 00:00:00 2014 @@ -11,8 +11,10 @@ #include "priv.h" int -sendto(int fd, void *a, int n, int flags, void *, int) +sendto(int fd, void *a, int n, int flags, + void *to, int tolen) { + USED(to, tolen); /* actually, should do connect if not done already */ return send(fd, a, n, flags); } diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/sethostent.c /sys/src/ape/lib/bsd/sethostent.c --- /n/sources/plan9/sys/src/ape/lib/bsd/sethostent.c Sun Jun 1 00:00:00 2008 +++ /sys/src/ape/lib/bsd/sethostent.c Thu Jan 1 00:00:00 1970 @@ -1,5 +0,0 @@ -int -sethostent(int) -{ - return 0; -} diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/socket.c /sys/src/ape/lib/bsd/socket.c --- /n/sources/plan9/sys/src/ape/lib/bsd/socket.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/bsd/socket.c Sat Jan 4 00:00:00 2014 @@ -42,11 +42,8 @@ r = _sock_findrock(fd, &d); if(r == 0){ r = malloc(sizeof(Rock)); - if(r == 0) - return 0; - r->dev = d.st_dev; - r->inode = d.st_ino; - r->other = -1; + if(r == nil) + return nil; r->next = _sock_rock; _sock_rock = r; } @@ -115,6 +112,7 @@ switch(domain){ case PF_INET: + case PF_INET6: /* get a free network directory */ switch(stype){ case SOCK_DGRAM: diff -Nru /n/sources/plan9/sys/src/ape/lib/bsd/socketpair.c /sys/src/ape/lib/bsd/socketpair.c --- /n/sources/plan9/sys/src/ape/lib/bsd/socketpair.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/bsd/socketpair.c Sat Jan 4 00:00:00 2014 @@ -9,8 +9,9 @@ #include int -socketpair(int domain, int , int , int *sv) +socketpair(int domain, int type, int protocol, int *sv) { + USED(protocol, type); switch(domain){ case PF_UNIX: return pipe(sv); diff -Nru /n/sources/plan9/sys/src/ape/lib/draw/libc.h /sys/src/ape/lib/draw/libc.h --- /n/sources/plan9/sys/src/ape/lib/draw/libc.h Sun Dec 25 00:00:00 2005 +++ /sys/src/ape/lib/draw/libc.h Thu Jan 1 00:00:00 1970 @@ -1,138 +0,0 @@ -#define _LOCK_EXTENSION -#define _QLOCK_EXTENSION -#define _BSD_EXTENSION -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef -struct Qid -{ - uvlong path; - ulong vers; - uchar type; -} Qid; - -typedef -struct Dir { - /* system-modified data */ - ushort type; /* server type */ - uint dev; /* server subtype */ - /* file data */ - Qid qid; /* unique id from server */ - ulong mode; /* permissions */ - ulong atime; /* last read time */ - ulong mtime; /* last write time */ - vlong length; /* file length: see */ - char *name; /* last element of path */ - char *uid; /* owner name */ - char *gid; /* group name */ - char *muid; /* last modifier name */ -} Dir; - -uint _convM2D(uchar*, uint, Dir*, char*); -uint _convD2M(Dir*, uchar*, uint); -Dir *_dirstat(char*); -int _dirwstat(char*, Dir*); -Dir *_dirfstat(int); -int _dirfwstat(int, Dir*); -long _dirread(int, Dir**); -long _dirreadall(int, Dir**); -void _nulldir(Dir*); -uint _sizeD2M(Dir*); - -typedef -struct Waitmsg -{ - int pid; /* of loved one */ - unsigned long time[3]; /* of loved one & descendants */ - char *msg; -} Waitmsg; - - -extern int _AWAIT(char*, int); -extern int _ALARM(unsigned long); -extern int _BIND(const char*, const char*, int); -extern int _CHDIR(const char*); -extern int _CLOSE(int); -extern int _CREATE(char*, int, unsigned long); -extern int _DUP(int, int); -extern int _ERRSTR(char*, unsigned int); -extern int _EXEC(char*, char*[]); -extern void _EXITS(char *); -extern int _FD2PATH(int, char*, int); -extern int _FAUTH(int, char*); -extern int _FSESSION(int, char*, int); -extern int _FSTAT(int, unsigned char*, int); -extern int _FWSTAT(int, unsigned char*, int); -extern int _MOUNT(int, int, const char*, int, const char*); -extern int _NOTED(int); -extern int _NOTIFY(int(*)(void*, char*)); -extern int _OPEN(const char*, int); -extern int _PIPE(int*); -extern long _PREAD(int, void*, long, long long); -extern long _PWRITE(int, void*, long, long long); -extern long _READ(int, void*, long); -extern int _REMOVE(const char*); -extern int _RENDEZVOUS(unsigned long, unsigned long); -extern int _RFORK(int); -extern int _SEGATTACH(int, char*, void*, unsigned long); -extern int _SEGBRK(void*, void*); -extern int _SEGDETACH(void*); -extern int _SEGFLUSH(void*, unsigned long); -extern int _SEGFREE(void*, unsigned long); -extern long long _SEEK(int, long long, int); -extern int _SLEEP(long); -extern int _STAT(const char*, unsigned char*, int); -extern Waitmsg* _WAIT(void); -extern long _WRITE(int, const void*, long); -extern int _WSTAT(const char*, unsigned char*, int); -extern void *_MALLOCZ(int, int); -extern int _WERRSTR(char*, ...); -extern long _READN(int, void*, long); -extern int _IOUNIT(int); - -#define dirstat _dirstat -#define dirfstat _dirfstat - -#define OREAD 0 -#define OWRITE 1 -#define ORDWR 2 -#define OCEXEC 32 - -#define AREAD 4 -#define AWRITE 2 -#define AEXEC 1 -#define AEXIST 0 - -#define open _OPEN -#define close _CLOSE -#define read _READ -#define write _WRITE -#define _exits(s) _exit(s && *(char*)s ? 1 : 0) -#define exits(s) exit(s && *(char*)s ? 1 : 0) -#define create _CREATE -#define pread _PREAD -#define readn _READN -#define mallocz _MALLOCZ -#define iounit _IOUNIT -#define bind _BIND - -/* assume being called as in event.c */ -#define postnote(x, pid, msg) kill(pid, SIGTERM) -#define atnotify(x, y) signal(SIGTERM, ekill) - -#define ERRMAX 128 - -extern void setmalloctag(void*, ulong); -extern ulong getcallerpc(void*); diff -Nru /n/sources/plan9/sys/src/ape/lib/draw/mkfile /sys/src/ape/lib/draw/mkfile --- /n/sources/plan9/sys/src/ape/lib/draw/mkfile Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/draw/mkfile Sat Jan 4 00:00:00 2014 @@ -69,7 +69,7 @@ #include +#define _SUSV2_SOURCE +#include #include "utf.h" #include "fmt.h" #include "fmtdef.h" @@ -329,6 +331,7 @@ char buf[70], *p, *conv; uvlong vu; ulong u; + uintptr_t pu; int neg, base, i, n, fl, w, isv; neg = 0; @@ -348,7 +351,12 @@ break; } if(f->r == 'p'){ - u = (ulong)va_arg(f->args, void*); + pu = va_arg(f->args, uintptr_t); + if(sizeof(uintptr_t) == sizeof(uvlong)){ + vu = pu; + isv = 1; + }else + u = pu; f->r = 'x'; fl |= FmtUnsigned; }else if(fl & FmtVLong){ diff -Nru /n/sources/plan9/sys/src/ape/lib/fmt/fmt.c /sys/src/ape/lib/fmt/fmt.c --- /n/sources/plan9/sys/src/ape/lib/fmt/fmt.c Tue Jul 10 00:00:00 2012 +++ /sys/src/ape/lib/fmt/fmt.c Sat Jan 4 00:00:00 2014 @@ -80,7 +80,7 @@ { Convfmt *p, *ep; - if(c<=0 || c>=65536) + if(c<=0 || c>Runemax) return -1; if(!f) f = __badfmt; diff -Nru /n/sources/plan9/sys/src/ape/lib/fmt/fmtdef.h /sys/src/ape/lib/fmt/fmtdef.h --- /n/sources/plan9/sys/src/ape/lib/fmt/fmtdef.h Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/fmt/fmtdef.h Sat Jan 4 00:00:00 2014 @@ -25,8 +25,6 @@ #define vlong _fmtvlong #define uvlong _fmtuvlong -// #define USED(x) if(x);else - typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; diff -Nru /n/sources/plan9/sys/src/ape/lib/fmt/fmtfdflush.c /sys/src/ape/lib/fmt/fmtfdflush.c --- /n/sources/plan9/sys/src/ape/lib/fmt/fmtfdflush.c Tue Dec 2 00:00:00 2003 +++ /sys/src/ape/lib/fmt/fmtfdflush.c Sat Jan 4 00:00:00 2014 @@ -13,6 +13,8 @@ */ #include #include +#define _SUSV2_SOURCE +#include #include "fmt.h" #include "fmtdef.h" @@ -26,7 +28,7 @@ int n; n = (char*)f->to - (char*)f->start; - if(n && write((int)f->farg, f->start, n) != n) + if(n && write((int)(uintptr_t)f->farg, f->start, n) != n) return 0; f->to = f->start; return 1; diff -Nru /n/sources/plan9/sys/src/ape/lib/fmt/fmtstr.c /sys/src/ape/lib/fmt/fmtstr.c --- /n/sources/plan9/sys/src/ape/lib/fmt/fmtstr.c Tue Dec 2 00:00:00 2003 +++ /sys/src/ape/lib/fmt/fmtstr.c Sat Jan 4 00:00:00 2014 @@ -14,6 +14,8 @@ #include #include #include +#define _SUSV2_SOURCE +#include #include "utf.h" #include "fmt.h" #include "fmtdef.h" @@ -24,7 +26,7 @@ char *s; int n; - n = (int)f->farg; + n = (int)(uintptr_t)f->farg; n += 256; f->farg = (void*)n; s = (char*)f->start; diff -Nru /n/sources/plan9/sys/src/ape/lib/fmt/runefmtstr.c /sys/src/ape/lib/fmt/runefmtstr.c --- /n/sources/plan9/sys/src/ape/lib/fmt/runefmtstr.c Tue Dec 2 00:00:00 2003 +++ /sys/src/ape/lib/fmt/runefmtstr.c Sat Jan 4 00:00:00 2014 @@ -14,6 +14,8 @@ #include #include #include +#define _SUSV2_SOURCE +#include #include "utf.h" #include "fmt.h" #include "fmtdef.h" @@ -24,7 +26,7 @@ Rune *s; int n; - n = (int)f->farg; + n = (int)(uintptr_t)f->farg; n += 256; f->farg = (void*)n; s = (Rune*)f->start; diff -Nru /n/sources/plan9/sys/src/ape/lib/mp/port/libc.h /sys/src/ape/lib/mp/port/libc.h --- /n/sources/plan9/sys/src/ape/lib/mp/port/libc.h Mon Jan 28 00:00:00 2013 +++ /sys/src/ape/lib/mp/port/libc.h Thu Jan 1 00:00:00 1970 @@ -1,26 +0,0 @@ -#include -#include -#include -#include -#include -#include - -typedef unsigned int u32int; -typedef unsigned long long u64int; - -#define nelem(x) (sizeof(x)/sizeof((x)[0])) - -extern ulong getcallerpc(void*); -extern void* mallocz(ulong, int); -extern void setmalloctag(void*, ulong); - -extern int dec16(uchar *, int, char *, int); -extern int enc16(char *, int, uchar *, int); -extern int dec32(uchar *, int, char *, int); -extern int enc32(char *, int, uchar *, int); -extern int dec64(uchar *, int, char *, int); -extern int enc64(char *, int, uchar *, int); - -extern vlong nsec(void); - -extern void sysfatal(char*, ...); diff -Nru /n/sources/plan9/sys/src/ape/lib/mp/port/mkfile /sys/src/ape/lib/mp/port/mkfile --- /n/sources/plan9/sys/src/ape/lib/mp/port/mkfile Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/mp/port/mkfile Sat Jan 4 00:00:00 2014 @@ -53,7 +53,7 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -// #include - -#define nelem(x) (sizeof(x)/sizeof((x)[0])) - -extern int tokenize(char*, char**, int); - -typedef -struct Qid -{ - uvlong path; - ulong vers; - uchar type; -} Qid; - -typedef -struct Dir { - /* system-modified data */ - ushort type; /* server type */ - uint dev; /* server subtype */ - /* file data */ - Qid qid; /* unique id from server */ - ulong mode; /* permissions */ - ulong atime; /* last read time */ - ulong mtime; /* last write time */ - vlong length; /* file length: see */ - char *name; /* last element of path */ - char *uid; /* owner name */ - char *gid; /* group name */ - char *muid; /* last modifier name */ -} Dir; - -uint _convM2D(uchar*, uint, Dir*, char*); -uint _convD2M(Dir*, uchar*, uint); -Dir *_dirstat(char*); -int _dirwstat(char*, Dir*); -Dir *_dirfstat(int); -int _dirfwstat(int, Dir*); -long _dirread(int, Dir**); -long _dirreadall(int, Dir**); -void _nulldir(Dir*); -uint _sizeD2M(Dir*); - -typedef -struct Waitmsg -{ - int pid; /* of loved one */ - unsigned long time[3]; /* of loved one & descendants */ - char *msg; -} Waitmsg; - -/* - * Time-of-day - */ - -typedef -struct Tm -{ - int sec; - int min; - int hour; - int mday; - int mon; - int year; - int wday; - int yday; - char zone[4]; - int tzoff; -} Tm; - -extern Tm* gmtime(long); -extern Tm* localtime(long); -extern char* asctime(Tm*); -extern char* ctime(long); -extern double cputime(void); -extern long times(long*); -extern long tm2sec(Tm*); -extern vlong nsec(void); - -extern void cycles(uvlong*); /* 64-bit value of the cycle counter if there is one, 0 if there isn't */ - -extern long time(long*); - -extern int _AWAIT(char*, int); -extern int _ALARM(unsigned long); -extern int _BIND(const char*, const char*, int); -extern int _CHDIR(const char*); -extern int _CLOSE(int); -extern int _CREATE(char*, int, unsigned long); -extern int _DUP(int, int); -extern int _ERRSTR(char*, unsigned int); -extern int _EXEC(char*, char*[]); -extern void _EXITS(char *); -extern int _FD2PATH(int, char*, int); -extern int _FAUTH(int, char*); -extern int _FSESSION(int, char*, int); -extern int _FSTAT(int, unsigned char*, int); -extern int _FWSTAT(int, unsigned char*, int); -extern int _MOUNT(int, int, const char*, int, const char*); -extern int _NOTED(int); -extern int _NOTIFY(int(*)(void*, char*)); -extern int _OPEN(const char*, int); -extern int _PIPE(int*); -extern long _PREAD(int, void*, long, long long); -extern long _PWRITE(int, void*, long, long long); -extern long _READ(int, void*, long); -extern int _REMOVE(const char*); -extern int _RENDEZVOUS(unsigned long, unsigned long); -extern int _RFORK(int); -extern int _SEGATTACH(int, char*, void*, unsigned long); -extern int _SEGBRK(void*, void*); -extern int _SEGDETACH(void*); -extern int _SEGFLUSH(void*, unsigned long); -extern int _SEGFREE(void*, unsigned long); -extern long long _SEEK(int, long long, int); -extern int _SLEEP(long); -extern int _STAT(const char*, unsigned char*, int); -extern Waitmsg* _WAIT(void); -extern long _WRITE(int, const void*, long); -extern int _WSTAT(const char*, unsigned char*, int); -extern void *_MALLOCZ(int, int); -extern int _WERRSTR(char*, ...); -extern long _READN(int, void*, long); -extern int _IOUNIT(int); - -#define dirstat _dirstat -#define dirfstat _dirfstat - -#define OREAD 0 -#define OWRITE 1 -#define ORDWR 2 -#define OCEXEC 32 - -#define AREAD 4 -#define AWRITE 2 -#define AEXEC 1 -#define AEXIST 0 - -#define open _OPEN -#define close _CLOSE -#define read _READ -#define write _WRITE -#define _exits(s) _exit(s && *(char*)s ? 1 : 0) -#define exits(s) exit(s && *(char*)s ? 1 : 0) -#define create _CREATE -#define pread _PREAD -#define readn _READN -#define mallocz _MALLOCZ -#define iounit _IOUNIT - -/* assume being called as in event.c */ -#define postnote(x, pid, msg) kill(pid, SIGTERM) -#define atnotify(x, y) signal(SIGTERM, ekill) - -#define ERRMAX 128 - -extern void setmalloctag(void*, ulong); -extern ulong getcallerpc(void*); - -/* Used in libsec.h and not picked up in earlier type definitions */ -typedef unsigned int u32int; -typedef unsigned long long u64int; - -int dec16(uchar *, int, char *, int); -int enc16(char *, int, uchar *, int); -int dec32(uchar *, int, char *, int); -int enc32(char *, int, uchar *, int); -int dec64(uchar *, int, char *, int); -int enc64(char *, int, uchar *, int); - -extern vlong nsec(void); - -extern void sysfatal(char*, ...); - -extern ulong truerand(void); /* uses /dev/random */ -extern int getfields(char*, char**, int, int, char*); - -#pragma varargck type "lld" vlong -#pragma varargck type "llo" vlong -#pragma varargck type "llx" vlong -#pragma varargck type "llb" vlong -#pragma varargck type "lld" uvlong -#pragma varargck type "llo" uvlong -#pragma varargck type "llx" uvlong -#pragma varargck type "llb" uvlong -#pragma varargck type "ld" long -#pragma varargck type "lo" long -#pragma varargck type "lx" long -#pragma varargck type "lb" long -#pragma varargck type "ld" ulong -#pragma varargck type "lo" ulong -#pragma varargck type "lx" ulong -#pragma varargck type "lb" ulong -#pragma varargck type "d" int -#pragma varargck type "o" int -#pragma varargck type "x" int -#pragma varargck type "c" int -#pragma varargck type "C" int -#pragma varargck type "b" int -#pragma varargck type "d" uint -#pragma varargck type "x" uint -#pragma varargck type "c" uint -#pragma varargck type "C" uint -#pragma varargck type "b" uint -#pragma varargck type "f" double -#pragma varargck type "e" double -#pragma varargck type "g" double -#pragma varargck type "s" char* -#pragma varargck type "q" char* -#pragma varargck type "S" Rune* -#pragma varargck type "Q" Rune* -#pragma varargck type "r" void -#pragma varargck type "%" void -#pragma varargck type "n" int* -#pragma varargck type "p" ulong /* uintptr */ -#pragma varargck type "p" void* -#pragma varargck flag ',' -#pragma varargck flag ' ' -#pragma varargck flag 'h' -#pragma varargck type "<" void* -#pragma varargck type "[" void* -#pragma varargck type "H" void* -#pragma varargck type "lH" void* diff -Nru /n/sources/plan9/sys/src/ape/lib/sec/port/mkfile /sys/src/ape/lib/sec/port/mkfile --- /n/sources/plan9/sys/src/ape/lib/sec/port/mkfile Thu Sep 19 00:00:00 2013 +++ /sys/src/ape/lib/sec/port/mkfile Sat Jan 4 00:00:00 2014 @@ -8,6 +8,7 @@ aes.c blowfish.c \ hmac.c md5.c md5block.c md4.c sha1.c sha1block.c\ sha2_64.c sha2_128.c sha2block64.c sha2block128.c\ + sha1block.c md5block.c\ sha1pickle.c md5pickle.c\ rc4.c\ genrandom.c prng.c fastrand.c nfastrand.c\ @@ -32,23 +33,27 @@ HFILES=\ /sys/include/ape/libsec.h\ /sys/include/ape/mp.h\ - libc.h\ + ../../9/libc.h\ UPDATE=\ mkfile\ $HFILES\ $CFILES\ +CLEANFILES=\ + x509-ape.c + /tm0->tm_/g' | \ + sed 's/static //g' > x509-ape.c $O.rsatest: rsatest.$O $LD -o $target $prereq diff -Nru /n/sources/plan9/sys/src/ape/lib/sec/port/reduce /sys/src/ape/lib/sec/port/reduce --- /n/sources/plan9/sys/src/ape/lib/sec/port/reduce Mon Jan 28 00:00:00 2013 +++ /sys/src/ape/lib/sec/port/reduce Sat Jan 4 00:00:00 2014 @@ -1,3 +1,4 @@ +#!/bin/rc O=$1 shift objtype=$1 @@ -5,7 +6,7 @@ cwd=`{basename -d `{pwd}} cwd=$cwd/$objtype -bind -ac /sys/src/libsec/$objtype $cwd +bind -ac ../../../../libsec/$objtype $cwd ls -p ../$objtype/*.[cs] >[2]/dev/null | sed 's/..$//' > /tmp/reduce.$pid # diff -Nru /n/sources/plan9/sys/src/ape/lib/sec/power/mkfile /sys/src/ape/lib/sec/power/mkfile --- /n/sources/plan9/sys/src/ape/lib/sec/power/mkfile Mon Jan 28 00:00:00 2013 +++ /sys/src/ape/lib/sec/power/mkfile Sat Jan 4 00:00:00 2014 @@ -10,3 +10,6 @@ UPDATE=mkfile +#include + +int +getfields(char *str, char **args, int max, int mflag, char *set) +{ + Rune r; + int nr, intok, narg; + + if(max <= 0) + return 0; + + narg = 0; + args[narg] = str; + if(!mflag) + narg++; + intok = 0; + for(;; str += nr) { + nr = chartorune(&r, str); + if(r == 0) + break; + if(utfrune(set, r)) { + if(narg >= max) + break; + *str = 0; + intok = 0; + args[narg] = str + nr; + if(!mflag) + narg++; + } else { + if(!intok && mflag) + narg++; + intok = 1; + } + } + return narg; +} diff -Nru /n/sources/plan9/sys/src/ape/lib/utf/gettokens.c /sys/src/ape/lib/utf/gettokens.c --- /n/sources/plan9/sys/src/ape/lib/utf/gettokens.c Thu Jan 1 00:00:00 1970 +++ /sys/src/ape/lib/utf/gettokens.c Sat Jan 4 00:00:00 2014 @@ -0,0 +1,50 @@ +#include +#include + +static char* +etoken(char *t, char *sep) +{ + int quoting; + + /* move to end of next token */ + quoting = 0; + while(*t!='\0' && (quoting || utfrune(sep, *t)==nil)){ + if(*t != '\''){ + t++; + continue; + } + /* *t is a quote */ + if(!quoting){ + quoting = 1; + t++; + continue; + } + /* quoting and we're on a quote */ + if(t[1] != '\''){ + /* end of quoted section; absorb closing quote */ + t++; + quoting = 0; + continue; + } + /* doubled quote; fold one quote into two */ + t += 2; + } + return t; +} + +int +gettokens(char *s, char **args, int maxargs, char *sep) +{ + int nargs; + + for(nargs=0; nargs 0){ - for(i = 0; i < 1000*1000*10; i++) - ; - } + _SLEEP((n*16667)/1000); return 0; } diff -Nru /n/sources/plan9/sys/src/ape/lib/v/plan9/tty.c /sys/src/ape/lib/v/plan9/tty.c --- /n/sources/plan9/sys/src/ape/lib/v/plan9/tty.c Wed May 29 00:00:00 2013 +++ /sys/src/ape/lib/v/plan9/tty.c Sat Jan 4 00:00:00 2014 @@ -14,8 +14,9 @@ /* fd is ignored */ -tty_echooff(int) +tty_echooff(int fd) { + USED(fd); if(ctlfd >= 0) return 0; ctlfd = open("/dev/consctl", O_WRONLY); @@ -25,8 +26,9 @@ return 0; } -tty_echoon(int) +tty_echoon(int fd) { + USED(fd); if(ctlfd >= 0){ write(ctlfd, "rawoff", 6); close(ctlfd);