diff -uNr dietlibc-0.24/CHANGES dietlibc-0.25/CHANGES --- dietlibc-0.24/CHANGES 2003-11-20 23:48:20.000000000 +0100 +++ dietlibc-0.25/CHANGES 2004-03-25 22:11:00.000000000 +0100 @@ -1,3 +1,36 @@ +0.25: + fix sprintf + head -1 -> head -n 1 + handle negative precision and -0 (Jens Låås) + susv3 renamed IFNAMSIZ to IF_NAMESIZE + make diet accept "gcc-3.3.2" and "diet -v -Os gcc" (Yuri Kozlov) + make libcompat syscall position independent (Peter S. Mazinger) + fix missing pthread stdio external (Gernot Tenchio) + Port parts of glibc test suite (Florian Westphal) + Now we need more manpower to fix the bugs it uncovers ;-) + add linux/if_ether.h and net/ethernet.h for sniffers + faster string routines and a small fix for alloc (Thomas Ogrisegg) + remove C++ comments from header files + add ftrylockfile + C99 fixes and a new printf test from Enrico Scholz + epoll_event needs to be packed on x86_64 (pointed out by Indan Zupancic) + work around make dependency problem breaking mipsel by creating kludge + mipsel/syscalls.h (Samium Gromoff) + Fix i386 unified syscall -EMEDIUMTYPE handling (Juergen Sawinski via + Clifford Wolf) + vsnprintf: fix output when output does not fit (Enrico Scholz) + new dirname with test suite entry (Yuri Kozlov) + fnmatch: add [:charclass:], fix negation (Michael J. Pomraning) + make calloc a weak symbol (Martin Pohlack) + make NULL C++ friendly (Martin Pohlack) + new realpath (Thomas Ogrisegg) + fix stupid glibcism in sys/epoll.h + add pause for Alpha (Kurt Garloff) + ptrace fix (Dallachiesa Michele) + ptread.h cleanups (Martin Pohlack) + fix execvp and execlp (Younès) + fix time() for sparc64 + 0.24: work around incompatible Linux select() modifying the timeout in librpc (Patch was sent from Mike Waychison from Sun) @@ -400,7 +433,7 @@ add readdir64 and automatic mapping if _FILE_OFFSET_BITS == 64 make diet not include the linker safeguard stuff when preprocessing Olaf: port to S/390! - me: fix vfork (it was put into dietlibc.a twice) + fix vfork (it was put into dietlibc.a twice) res_query did not initialize last diet (not diet-dyn, of course) now adds -static to the gcc command line fixed fflush on input streams (tic from ncurses exposed this) @@ -485,7 +518,7 @@ a little over 300 bytes on x86. Guillaume Cottenceau just wrote me that strncat should be even more broken than it already is: it should append n bytes AND THEN \0! - I wonder how many programmers have produces off-by-one errors here... + I wonder how many programmers have produced off-by-one errors here... Fix regexec offset return. autoconf now believes that diet libc has POSIX regular expressions. Fix fnmatch (a/b/* matched a/b/c/d even if FNM_PATHNAME was set) diff -uNr dietlibc-0.24/FAQ dietlibc-0.25/FAQ --- dietlibc-0.24/FAQ 2003-06-26 00:45:49.000000000 +0200 +++ dietlibc-0.25/FAQ 2004-01-19 17:47:23.000000000 +0100 @@ -261,3 +261,10 @@ the way. On all platforms supported by the diet libc, numeric zero is also the pointer value for NULL. So not initializing a static pointer yields NULL. + + +Q: My diet libc programs all segfault in User Mode Linux 2.6! +A: This is a shortcoming of User Mode Linux. + Edit dietfeatures.h, remove the WANT_SYSENTER #define, and then + recompile the diet libc and your program. Oh, and bug the user mode + linux people about this, it's their fault! ;) diff -uNr dietlibc-0.24/Makefile dietlibc-0.25/Makefile --- dietlibc-0.24/Makefile 2003-11-04 17:59:17.000000000 +0100 +++ dietlibc-0.25/Makefile 2004-03-26 16:28:44.000000000 +0100 @@ -256,7 +256,7 @@ $(OBJDIR)/elftrunc: $(OBJDIR)/diet contrib/elftrunc.c bin-$(MYARCH)/diet $(CROSS)$(CC) $(CFLAGS) -o $@ contrib/elftrunc.c -VERSION=dietlibc-$(shell head -1 CHANGES|sed 's/://') +VERSION=dietlibc-$(shell head -n 1 CHANGES|sed 's/://') CURNAME=$(notdir $(shell pwd)) $(OBJDIR)/diet: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o @@ -420,6 +420,9 @@ $(OBJDIR)/strncpy.o: dietfeatures.h $(OBJDIR)/strxfrm.o: dietfeatures.h +$(OBJDIR)/stat.o $(OBJDIR)/fstat.o $(OBJDIR)/lstat.o: include/sys/stat.h +$(OBJDIR)/stat64.o $(OBJDIR)/fstat64.o $(OBJDIR)/lstat64.o: include/sys/stat.h + # these depend on dietfeatures.h for WANT_INET_ADDR_DNS $(OBJDIR)/gethostbyname_r.o: dietfeatures.h diff -uNr dietlibc-0.24/THANKS dietlibc-0.25/THANKS --- dietlibc-0.24/THANKS 2003-11-14 15:00:44.000000000 +0100 +++ dietlibc-0.25/THANKS 2003-12-05 15:50:49.000000000 +0100 @@ -36,5 +36,5 @@ Gerrit Pape maintains the Debian port and helped immensely by relaying bug reports and doing testing on platforms I didn't have access to. -Manuel Novoa III reported many bugs although it really works for the +Manuel Novoa III reported many bugs although he really works for the competition, uClibc ;-) diff -uNr dietlibc-0.24/alpha/__pause.c dietlibc-0.25/alpha/__pause.c --- dietlibc-0.24/alpha/__pause.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/alpha/__pause.c 2004-02-27 23:19:51.000000000 +0100 @@ -0,0 +1,11 @@ +#include +#include + +int pause(void) +{ + sigset_t set; + sigemptyset(&set); + sigprocmask(SIG_BLOCK, NULL, &set); + return sigsuspend(&set); +} + diff -uNr dietlibc-0.24/contrib/Makefile dietlibc-0.25/contrib/Makefile --- dietlibc-0.24/contrib/Makefile 2003-09-20 02:06:32.000000000 +0200 +++ dietlibc-0.25/contrib/Makefile 1970-01-01 01:00:00.000000000 +0100 @@ -1,2 +0,0 @@ -pnpdnsd: pnpdnsd.c - diet gcc -g -o $@ $^ diff -uNr dietlibc-0.24/contrib/memchr.c dietlibc-0.25/contrib/memchr.c --- dietlibc-0.24/contrib/memchr.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/contrib/memchr.c 2004-03-27 00:28:13.000000000 +0100 @@ -0,0 +1,51 @@ +/* fast memchr -- Copyright (C) 2003 Thomas M. Ogrisegg */ +#include +#include "dietfeatures.h" +#include "dietstring.h" + +#if __WORDSIZE == 64 +# define MB 0x7efefefefefefeff +#else +# define MB 0x7efefeff +#endif + +void * +memchr (const void *s, int c, size_t n) +{ + const unsigned char *pc = (unsigned char *) s; +#ifdef WANT_SMALLER_STRING_ROUTINES + for (;n--;pc++) if (*pc == c) return ((void *) pc); + return (NULL); +#else + unsigned long l, lb, lt; + int tmp; + + if ((tmp = STRALIGN(s)) || n < sizeof(unsigned long)) { + if (n < sizeof(unsigned long)) tmp = n; + for (; tmp-- && n--; pc++) + if (*pc == c) + return ((char *) pc); + if (n == (size_t) - 1) + return (NULL); + } + + lb = c | c << 8; + lb |= lb << 16; +#if __WORDSIZE == 64 + lb |= lb << 32; +#endif + + while (n >= sizeof(unsigned long)) { + l = *(unsigned long *) pc; + lt = l ^ lb; + if ((((lt + MB) ^ ~lt) & ~MB)) { + while (l && (l & 0xff) != (unsigned long) c) l >>= 8, pc++; + if (l) return ((char *) pc); + } else + pc += sizeof(unsigned long); + n -= sizeof(unsigned long); + } + for (; n--; pc++) if (*pc == c) return ((char *) pc); + return (NULL); +#endif +} diff -uNr dietlibc-0.24/contrib/pnpdnsd.c dietlibc-0.25/contrib/pnpdnsd.c --- dietlibc-0.24/contrib/pnpdnsd.c 2003-09-20 20:03:27.000000000 +0200 +++ dietlibc-0.25/contrib/pnpdnsd.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,117 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc,char* argv[]) { - int pnpfd; - struct sockaddr_in6 pnpsa; - struct pollfd pfd; - struct ipv6_mreq opt; - unsigned int interface=0; - unsigned char inpkg[4095]; - - if (argc<2) { - puts("usage: pnpdnsd eth0"); - return 111; - } - interface=if_nametoindex(argv[1]); - if (interface==0) { - puts("pnpdnsd: network interface not found!"); - return 111; - } - pnpfd=socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP); - - /* bind to port 53 */ - memset(&pnpsa,0,sizeof(struct sockaddr_in6)); - pnpsa.sin6_family=AF_INET6; - pnpsa.sin6_port=htons(53); - pnpsa.sin6_scope_id=interface; - if (bind(pnpfd,(struct sockaddr*)&pnpsa,sizeof(pnpsa))) { - perror("bind"); - return 111; - } - - /* join the multicast group */ - memmove(&opt.ipv6mr_multiaddr,"\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00dnspnp",16); - opt.ipv6mr_interface=interface; - if (setsockopt(pnpfd,IPPROTO_IPV6,IPV6_ADD_MEMBERSHIP,&opt,sizeof opt)==-1) { - perror("setsockopt"); - return 111; - } - - { - socklen_t len=sizeof(pnpsa); - if (getsockname(pnpfd,(struct sockaddr*)&pnpsa,&len)==-1) { - perror("getsockname"); - return 111; - } - } - - for (;;) { - int len; - int fromlen; - int qdcount; - struct sockaddr_in6 peersa; - fromlen=sizeof(peersa); - len=recvfrom(pnpfd,inpkg,sizeof(inpkg),0,(struct sockaddr*)&peersa,&fromlen); - if (len==-1) { - perror("recvfrom"); - return 111; - } - - /* is it a recursive query, as libresolv would issue? */ - if (inpkg[2]!=1) continue; - - qdcount=((unsigned long)(inpkg[4])<<8) + inpkg[5]; - - { - int decofs; - char name[257]; - char myname[257]; - struct utsname u; - decofs=dn_expand(inpkg,inpkg+len,inpkg+12,name,sizeof(name)-1); - puts(name); - uname(&u); - if (strlen(u.nodename)>63) u.nodename[63]=0; - if (!strcasecmp(u.nodename,name)) { - char packet[1500]; - char* c; - packet[0]=inpkg[0]; - packet[1]=inpkg[1]; - packet[2]=inpkg[2] | 0x84; - packet[3]=0; - memset(packet+4,0,8); - packet[7]=1; - packet[12]=strlen(u.nodename); - strcpy(packet+13,u.nodename); - c=packet+14+strlen(u.nodename); - if (((long)c)&1) { *c=0; ++c; } - /* int16 type */ - c[0]=0; c[1]=28; /* AAAA */ - /* int16 class */ - c[2]=0; c[3]=1; /* IN */ - /* int32 ttl */ - c[4]=0; c[5]=0; c[6]=0; c[7]=23; /* 23 seconds TTL */ - /* int16 rdlength */ - c[8]=0; c[9]=16; - /* int16 rdata */ - memmove(c+10,&pnpsa.sin6_addr,16); - - if (sendto(pnpfd,packet,c+26-packet,0,(struct sockaddr*)&peersa,fromlen)==-1) - perror("sendto"); - } - } - } -} diff -uNr dietlibc-0.24/diet.c dietlibc-0.25/diet.c --- dietlibc-0.24/diet.c 2003-10-10 15:17:46.000000000 +0200 +++ dietlibc-0.25/diet.c 2003-12-15 13:32:52.000000000 +0100 @@ -43,6 +43,21 @@ "x86_64","-Os","-fstrict-aliasing","-momit-leaf-frame-pointer","-mfance-math-387",0, 0}; +static void usage(void) { + __write2( +#ifdef __DYN_LIB + "dyn-" +#endif + "diet version " VERSION +#ifndef INSTALLVERSION + " (non-install version in source tree)" +#endif + "\n\n"); + error("usage: diet [-v] [-Os] gcc command line\n" + "e.g. diet -Os gcc -c t.c\n" + "or diet sparc-linux-gcc -o foo foo.c bar.o\n"); +} + int main(int argc,char *argv[]) { int _link=0; int compile=0; @@ -78,37 +93,22 @@ #endif strcpy(dashL,"-L"); - if (argc<2) { -usage: - if (verbose) { - __write2( -#ifdef __DYN_LIB - "dyn-" -#endif - "diet version " VERSION -#ifndef INSTALLVERSION - " (non-install version in source tree)" -#endif - "\n\n"); - } - error("usage: diet [-v] [-Os] gcc command line\n" - "e.g. diet -Os gcc -c t.c\n" - "or diet sparc-linux-gcc -o foo foo.c bar.o\n"); - } - if (!strcmp(argv[1],"-v")) { - ++argv; --argc; - verbose=1; - } - if (argv[1] && !strcmp(argv[1],"-Os")) { - ++argv; --argc; - mangleopts=1; - } - if (!argv[1]) goto usage; + do { + if (!argv[1]) usage(); + if (!strcmp(argv[1],"-v")) { + ++argv; --argc; + verbose=1; + } else if (argv[1] && !strcmp(argv[1],"-Os")) { + ++argv; --argc; + mangleopts=1; + } else break; + } while (1); { - char *tmp=strchr(argv[1],0)-2; - char *tmp2,*tmp3; char *cc=argv[1]; + char *tmp=strchr(cc,0)-2; + char *tmp2,*tmp3; if (tmp + +#if __WORDSIZE == 64 +# define MKW(x) (x|x<<8|x<<16|x<<24|x<<32|x<<40|x<<48|x<<56) +# define STRALIGN(x) (((unsigned long)x&7)?8-((unsigned long)x&7):0) +#else /* __WORDSIZE == 32 */ +# define MKW(x) (x|x<<8|x<<16|x<<24) +# define STRALIGN(x) (((unsigned long)x&3)?4-((unsigned long)x&3):0) +#endif + +#define UNALIGNED(x,y) (((unsigned long)x & (sizeof (unsigned long)-1)) ^ ((unsigned long)y & (sizeof (unsigned long)-1))) + +#endif /* _DIET_STRING_H_ */ diff -uNr dietlibc-0.24/i386/dyn_syscalls.S dietlibc-0.25/i386/dyn_syscalls.S --- dietlibc-0.24/i386/dyn_syscalls.S 2003-10-08 01:44:25.000000000 +0200 +++ dietlibc-0.25/i386/dyn_syscalls.S 2004-01-15 18:35:43.000000000 +0100 @@ -72,6 +72,8 @@ /* OK this is basicaly unified.S */ .text +.type __you_tried_to_link_a_dietlibc_object_against_glibc,@function +.type __nop,@function .type __unified_syscall_256,@function __unified_syscall_256: movzwl %ax, %eax diff -uNr dietlibc-0.24/i386/unified.S dietlibc-0.25/i386/unified.S --- dietlibc-0.24/i386/unified.S 2003-04-17 15:55:39.000000000 +0200 +++ dietlibc-0.25/i386/unified.S 2004-01-15 18:35:43.000000000 +0100 @@ -48,7 +48,7 @@ int $0x80 #endif cmp $-124,%eax - jbe .Lnoerror + jb .Lnoerror neg %eax #ifdef WANT_THREAD_SAFE movl %eax,%ebx diff -uNr dietlibc-0.24/include/asm/types.h dietlibc-0.25/include/asm/types.h --- dietlibc-0.24/include/asm/types.h 2003-08-19 18:39:21.000000000 +0200 +++ dietlibc-0.25/include/asm/types.h 2004-01-07 16:06:48.000000000 +0100 @@ -14,14 +14,14 @@ typedef uint8_t __u8; typedef uint16_t __u16; typedef uint32_t __u32; -#ifndef __STRICT_ANSI__ +#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L typedef uint64_t __u64; #endif typedef int8_t __s8; typedef int16_t __s16; typedef int32_t __s32; -#ifndef __STRICT_ANSI__ +#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L typedef int64_t __s64; #endif diff -uNr dietlibc-0.24/include/dietrefdef.h dietlibc-0.25/include/dietrefdef.h --- dietlibc-0.24/include/dietrefdef.h 2003-11-06 13:56:25.000000000 +0100 +++ dietlibc-0.25/include/dietrefdef.h 2004-01-03 03:11:30.000000000 +0100 @@ -14,6 +14,6 @@ "\t.long 0\n" \ "\t.ascii \"diet\"\n" \ "1:\t" __DIETREFDEF_H__ " " name "\n2:" \ - ".previous"); + ".previous") #endif diff -uNr dietlibc-0.24/include/dirent.h dietlibc-0.25/include/dirent.h --- dietlibc-0.24/include/dirent.h 2003-08-19 18:22:52.000000000 +0200 +++ dietlibc-0.25/include/dirent.h 2004-01-07 16:06:48.000000000 +0100 @@ -14,7 +14,7 @@ char d_name[256]; /* We must not include limits.h! */ }; -#ifndef __STRICT_ANSI__ +#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L struct dirent64 { uint64_t d_ino; int64_t d_off; diff -uNr dietlibc-0.24/include/dlfcn.h dietlibc-0.25/include/dlfcn.h --- dietlibc-0.24/include/dlfcn.h 2003-08-19 18:23:18.000000000 +0200 +++ dietlibc-0.25/include/dlfcn.h 2004-01-30 19:27:32.000000000 +0100 @@ -16,7 +16,7 @@ void *dlopen (const char *filename, int flag); const char *dlerror(void); -void *dlsym(void *handle, char *symbol); +void *dlsym(void *handle, const char *symbol); int dlclose (void *handle); __END_DECLS diff -uNr dietlibc-0.24/include/fcntl.h dietlibc-0.25/include/fcntl.h --- dietlibc-0.24/include/fcntl.h 2003-10-10 15:17:46.000000000 +0200 +++ dietlibc-0.25/include/fcntl.h 2004-01-03 03:10:02.000000000 +0100 @@ -358,11 +358,9 @@ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ -//#if !defined(__powerpc64__) #define F_GETLK64 12 /* using 'struct flock64' */ #define F_SETLK64 13 #define F_SETLKW64 14 -//#endif /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ @@ -399,7 +397,6 @@ pid_t l_pid; }; -//#if !defined(__powerpc64__) struct flock64 { short l_type; short l_whence; @@ -407,7 +404,6 @@ loff_t l_len; pid_t l_pid; }; -//#endif #elif defined (__arm__) diff -uNr dietlibc-0.24/include/iconv.h dietlibc-0.25/include/iconv.h --- dietlibc-0.24/include/iconv.h 2003-08-19 18:26:11.000000000 +0200 +++ dietlibc-0.25/include/iconv.h 2003-12-01 18:42:12.000000000 +0100 @@ -16,7 +16,7 @@ /* Convert at most *INBYTESLEFT bytes from *INBUF according to the code conversion algorithm specified by CD and place up to *OUTBYTESLEFT bytes in buffer at *OUTBUF. */ -extern size_t iconv (iconv_t cd, const char** inbuf, +extern size_t iconv (iconv_t cd, char** inbuf, size_t* inbytesleft, char** outbuf, size_t* outbytesleft) __THROW; diff -uNr dietlibc-0.24/include/inttypes.h dietlibc-0.25/include/inttypes.h --- dietlibc-0.24/include/inttypes.h 2003-08-19 18:26:26.000000000 +0200 +++ dietlibc-0.25/include/inttypes.h 2004-01-07 16:06:48.000000000 +0100 @@ -239,7 +239,7 @@ typedef signed long int intptr_t; typedef unsigned long int uintptr_t; -#ifndef __STRICT_ANSI__ +#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L __extension__ typedef signed long long int64_t; __extension__ typedef unsigned long long uint64_t; __extension__ typedef signed long long int intmax_t; diff -uNr dietlibc-0.24/include/langinfo.h dietlibc-0.25/include/langinfo.h --- dietlibc-0.24/include/langinfo.h 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/include/langinfo.h 2003-12-15 21:43:56.000000000 +0100 @@ -0,0 +1,8 @@ +#ifndef _LANGINFO_H +#define _LANGINFO_H + +#include + +char *nl_langinfo(nl_item); + +#endif diff -uNr dietlibc-0.24/include/linux/if_ether.h dietlibc-0.25/include/linux/if_ether.h --- dietlibc-0.24/include/linux/if_ether.h 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/include/linux/if_ether.h 2003-12-18 16:53:53.000000000 +0100 @@ -0,0 +1,83 @@ +#ifndef _LINUX_IF_ETHER_H +#define _LINUX_IF_ETHER_H + +/* + * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble + * and FCS/CRC (frame check sequence). + */ + +#define ETH_ALEN 6 /* Octets in one ethernet addr */ +#define ETH_HLEN 14 /* Total octets in header. */ +#define ETH_ZLEN 60 /* Min. octets in frame sans FCS */ +#define ETH_DATA_LEN 1500 /* Max. octets in payload */ +#define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */ + +/* + * These are the defined Ethernet Protocol ID's. + */ + +#define ETH_P_LOOP 0x0060 /* Ethernet Loopback packet */ +#define ETH_P_PUP 0x0200 /* Xerox PUP packet */ +#define ETH_P_PUPAT 0x0201 /* Xerox PUP Addr Trans packet */ +#define ETH_P_IP 0x0800 /* Internet Protocol packet */ +#define ETH_P_X25 0x0805 /* CCITT X.25 */ +#define ETH_P_ARP 0x0806 /* Address Resolution packet */ +#define ETH_P_BPQ 0x08FF /* G8BPQ AX.25 Ethernet Packet [ NOT AN OFFICIALLY REGISTERED ID ] */ +#define ETH_P_IEEEPUP 0x0a00 /* Xerox IEEE802.3 PUP packet */ +#define ETH_P_IEEEPUPAT 0x0a01 /* Xerox IEEE802.3 PUP Addr Trans packet */ +#define ETH_P_DEC 0x6000 /* DEC Assigned proto */ +#define ETH_P_DNA_DL 0x6001 /* DEC DNA Dump/Load */ +#define ETH_P_DNA_RC 0x6002 /* DEC DNA Remote Console */ +#define ETH_P_DNA_RT 0x6003 /* DEC DNA Routing */ +#define ETH_P_LAT 0x6004 /* DEC LAT */ +#define ETH_P_DIAG 0x6005 /* DEC Diagnostics */ +#define ETH_P_CUST 0x6006 /* DEC Customer use */ +#define ETH_P_SCA 0x6007 /* DEC Systems Comms Arch */ +#define ETH_P_RARP 0x8035 /* Reverse Addr Res packet */ +#define ETH_P_ATALK 0x809B /* Appletalk DDP */ +#define ETH_P_AARP 0x80F3 /* Appletalk AARP */ +#define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */ +#define ETH_P_IPX 0x8137 /* IPX over DIX */ +#define ETH_P_IPV6 0x86DD /* IPv6 over bluebook */ +#define ETH_P_PPP_DISC 0x8863 /* PPPoE discovery messages */ +#define ETH_P_PPP_SES 0x8864 /* PPPoE session messages */ +#define ETH_P_MPLS_UC 0x8847 /* MPLS Unicast traffic */ +#define ETH_P_MPLS_MC 0x8848 /* MPLS Multicast traffic */ +#define ETH_P_ATMMPOA 0x884c /* MultiProtocol Over ATM */ +#define ETH_P_ATMFATE 0x8884 /* Frame-based ATM Transport + * over Ethernet + */ +#define ETH_P_EDP2 0x88A2 /* Coraid EDP2 */ + +/* + * Non DIX types. Won't clash for 1500 types. + */ + +#define ETH_P_802_3 0x0001 /* Dummy type for 802.3 frames */ +#define ETH_P_AX25 0x0002 /* Dummy protocol id for AX.25 */ +#define ETH_P_ALL 0x0003 /* Every packet (be careful!!!) */ +#define ETH_P_802_2 0x0004 /* 802.2 frames */ +#define ETH_P_SNAP 0x0005 /* Internal only */ +#define ETH_P_DDCMP 0x0006 /* DEC DDCMP: Internal only */ +#define ETH_P_WAN_PPP 0x0007 /* Dummy type for WAN PPP frames*/ +#define ETH_P_PPP_MP 0x0008 /* Dummy type for PPP MP frames */ +#define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type */ +#define ETH_P_PPPTALK 0x0010 /* Dummy type for Atalk over PPP*/ +#define ETH_P_TR_802_2 0x0011 /* 802.2 frames */ +#define ETH_P_MOBITEX 0x0015 /* Mobitex (kaz@cafe.net) */ +#define ETH_P_CONTROL 0x0016 /* Card specific control frames */ +#define ETH_P_IRDA 0x0017 /* Linux-IrDA */ +#define ETH_P_ECONET 0x0018 /* Acorn Econet */ +#define ETH_P_HDLC 0x0019 /* HDLC frames */ + +/* + * This is an Ethernet frame header. + */ + +struct ethhdr { + unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ + unsigned char h_source[ETH_ALEN]; /* source ether addr */ + unsigned short h_proto; /* packet type ID field */ +} __attribute__((packed)); + +#endif diff -uNr dietlibc-0.24/include/net/ethernet.h dietlibc-0.25/include/net/ethernet.h --- dietlibc-0.24/include/net/ethernet.h 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/include/net/ethernet.h 2003-12-18 17:34:42.000000000 +0100 @@ -0,0 +1,55 @@ +#ifndef __NET_ETHERNET_H +#define __NET_ETHERNET_H + +#include +#include +#include /* IEEE 802.3 Ethernet constants */ + +__BEGIN_DECLS + +/* This is a name for the 48 bit ethernet address available on many + systems. */ +struct ether_addr +{ + uint8_t ether_addr_octet[ETH_ALEN]; +} __attribute__ ((__packed__)); + +/* 10Mb/s ethernet header */ +struct ether_header +{ + uint8_t ether_dhost[ETH_ALEN]; /* destination eth addr */ + uint8_t ether_shost[ETH_ALEN]; /* source ether addr */ + uint16_t ether_type; /* packet type ID field */ +} __attribute__ ((__packed__)); + +/* Ethernet protocol ID's */ +#define ETHERTYPE_PUP 0x0200 /* Xerox PUP */ +#define ETHERTYPE_IP 0x0800 /* IP */ +#define ETHERTYPE_ARP 0x0806 /* Address resolution */ +#define ETHERTYPE_REVARP 0x8035 /* Reverse ARP */ + +#define ETHER_ADDR_LEN ETH_ALEN /* size of ethernet addr */ +#define ETHER_TYPE_LEN 2 /* bytes in type field */ +#define ETHER_CRC_LEN 4 /* bytes in CRC field */ +#define ETHER_HDR_LEN ETH_HLEN /* total octets in header */ +#define ETHER_MIN_LEN (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */ +#define ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */ + +/* make sure ethenet length is valid */ +#define ETHER_IS_VALID_LEN(foo) \ + ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) + +/* + * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have + * (type-ETHERTYPE_TRAIL)*512 bytes of data followed + * by an ETHER type (as given above) and then the (variable-length) header. + */ +#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ +#define ETHERTYPE_NTRAILER 16 + +#define ETHERMTU ETH_DATA_LEN +#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) + +__END_DECLS + +#endif diff -uNr dietlibc-0.24/include/net/if.h dietlibc-0.25/include/net/if.h --- dietlibc-0.24/include/net/if.h 2003-08-19 18:42:12.000000000 +0200 +++ dietlibc-0.25/include/net/if.h 2003-12-05 20:32:09.000000000 +0100 @@ -41,10 +41,11 @@ struct ifreq { #define IFHWADDRLEN 6 -#define IFNAMSIZ 16 +#define IF_NAMESIZE 16 +#define IFNAMSIZ IF_NAMESIZE union { - char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + char ifrn_name[IF_NAMESIZE]; /* if name, e.g. "en0" */ } ifr_ifrn; union { struct sockaddr ifru_addr; @@ -56,8 +57,8 @@ int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; - char ifru_slave[IFNAMSIZ]; /* Just fits the size */ - char ifru_newname[IFNAMSIZ]; + char ifru_slave[IF_NAMESIZE]; /* Just fits the size */ + char ifru_newname[IF_NAMESIZE]; char* ifru_data; } ifr_ifru; }; diff -uNr dietlibc-0.24/include/nl_types.h dietlibc-0.25/include/nl_types.h --- dietlibc-0.24/include/nl_types.h 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/include/nl_types.h 2003-12-15 21:43:56.000000000 +0100 @@ -0,0 +1,34 @@ +#ifndef _NL_TYPES_H +#define _NL_TYPES_H + +typedef enum { + CODESET, + D_T_FMT, + D_FMT, + T_FMT, + T_FMT_AMPM, + AM_STR, + PM_STR, + DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7, + ABDAY_1, ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, ABDAY_7, + MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, + MON_7, MON_8, MON_9, MON_10, MON_11, MON_12, + ABMON_1, ABMON_2, ABMON_3, ABMON_4, ABMON_5, ABMON_6, + ABMON_7, ABMON_8, ABMON_9, ABMON_10, ABMON_11, ABMON_12, + ERA, + ERA_D_FMT, + ERA_D_T_FMT, + ERA_T_FMT, + ALT_DIGITS, + RADIXCHAR, + THOUSEP, + YESEXPR, + NOEXPR, + CRNCYSTR +} nl_item; + +typedef void* nl_catd; + +enum { NL_SETD=0, NL_CAT_LOCALE=1 }; + +#endif diff -uNr dietlibc-0.24/include/paths.h dietlibc-0.25/include/paths.h --- dietlibc-0.24/include/paths.h 2003-11-20 12:09:27.000000000 +0100 +++ dietlibc-0.25/include/paths.h 2003-12-19 17:25:07.000000000 +0100 @@ -7,7 +7,6 @@ #define _PATH_DEVNULL "/dev/null" #define _PATH_CONSOLE "/dev/console" -#define _PATH_MOUNTED "/etc/mtab" #define _PATH_PASSWD "/etc/passwd" #define _PATH_GROUP "/etc/group" diff -uNr dietlibc-0.24/include/stddef.h dietlibc-0.25/include/stddef.h --- dietlibc-0.24/include/stddef.h 2003-08-22 14:16:20.000000000 +0200 +++ dietlibc-0.25/include/stddef.h 2004-01-27 18:00:17.000000000 +0100 @@ -19,7 +19,10 @@ typedef int wchar_t; #endif -#ifndef NULL +#undef NULL +#if defined(__cplusplus) +#define NULL 0 +#else #define NULL (void*)0 #endif diff -uNr dietlibc-0.24/include/stdint.h dietlibc-0.25/include/stdint.h --- dietlibc-0.24/include/stdint.h 2003-08-19 18:35:32.000000000 +0200 +++ dietlibc-0.25/include/stdint.h 2004-01-07 16:06:48.000000000 +0100 @@ -12,7 +12,7 @@ typedef uint16_t uint_least16_t; typedef uint32_t uint_least32_t; -#ifndef __STRICT_ANSI__ +#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L typedef int64_t int_least64_t; typedef uint64_t uint_least64_t; #endif diff -uNr dietlibc-0.24/include/stdio.h dietlibc-0.25/include/stdio.h --- dietlibc-0.24/include/stdio.h 2003-11-11 18:35:03.000000000 +0100 +++ dietlibc-0.25/include/stdio.h 2004-01-03 03:17:32.000000000 +0100 @@ -164,6 +164,7 @@ void flockfile(FILE* f) __THROW; void funlockfile(FILE* f) __THROW; +int ftrylockfile (FILE *__stream) __THROW; #ifdef _GNU_SOURCE int vasprintf(char **strp, const char *fmt, va_list ap); diff -uNr dietlibc-0.24/include/stdlib.h dietlibc-0.25/include/stdlib.h --- dietlibc-0.24/include/stdlib.h 2003-08-22 14:16:20.000000000 +0200 +++ dietlibc-0.25/include/stdlib.h 2004-01-07 16:06:48.000000000 +0100 @@ -31,7 +31,7 @@ extern int __ltostr(char *s, unsigned int size, unsigned long i, unsigned int base, int UpCase) __THROW; extern int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2) __THROW; -#ifndef __STRICT_ANSI__ +#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L __extension__ long long int strtoll(const char *nptr, char **endptr, int base) __THROW; __extension__ unsigned long long int strtoull(const char *nptr, char **endptr, int base) __THROW; __extension__ int __lltostr(char *s, unsigned int size, unsigned long long i, unsigned int base, int UpCase) __THROW; @@ -40,6 +40,7 @@ int atoi(const char *nptr) __THROW; long int atol(const char *nptr) __THROW; double atof(const char *nptr) __THROW; +__extension__ long long int atoll(const char *nptr); void exit(int status) __THROW __attribute__((noreturn)); void abort(void) __THROW; diff -uNr dietlibc-0.24/include/sys/cdefs.h dietlibc-0.25/include/sys/cdefs.h --- dietlibc-0.24/include/sys/cdefs.h 2003-10-08 01:44:25.000000000 +0200 +++ dietlibc-0.25/include/sys/cdefs.h 2004-01-07 16:06:48.000000000 +0100 @@ -48,7 +48,7 @@ #define __ptr_t void* -#ifdef __STRICT_ANSI__ +#if defined(__STRICT_ANSI__) && __STDC_VERSION__ + 0 < 199900L #define inline #endif diff -uNr dietlibc-0.24/include/sys/epoll.h dietlibc-0.25/include/sys/epoll.h --- dietlibc-0.24/include/sys/epoll.h 2003-08-19 18:47:02.000000000 +0200 +++ dietlibc-0.25/include/sys/epoll.h 2004-02-24 01:33:18.000000000 +0100 @@ -20,7 +20,7 @@ EPOLLOUT = 0x004, #define EPOLLOUT EPOLLOUT -#ifdef __USE_XOPEN +#ifdef _XOPEN_SOURCE EPOLLRDNORM = 0x040, #define EPOLLRDNORM EPOLLRDNORM EPOLLRDBAND = 0x080, @@ -31,7 +31,7 @@ #define EPOLLWRBAND EPOLLWRBAND #endif /* #ifdef __USE_XOPEN */ -#ifdef __USE_GNU +#ifdef _GNU_SOURCE EPOLLMSG = 0x400, #define EPOLLMSG EPOLLMSG #endif /* #ifdef __USE_GNU */ @@ -55,7 +55,11 @@ struct epoll_event { uint32_t events; epoll_data_t data; -}; +} +#ifdef __x86_64__ +__attribute__((packed)) +#endif +; int epoll_create(int size) __THROW; int epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) __THROW; diff -uNr dietlibc-0.24/include/sys/mtio.h dietlibc-0.25/include/sys/mtio.h --- dietlibc-0.24/include/sys/mtio.h 2003-11-20 14:56:05.000000000 +0100 +++ dietlibc-0.25/include/sys/mtio.h 2003-12-18 17:37:02.000000000 +0100 @@ -2,7 +2,6 @@ #define _SYS_MTIO_H #include -#include /* for daddr_t */ __BEGIN_DECLS @@ -69,8 +68,9 @@ long int mt_gstat; /* generic (device independent) status */ long int mt_erreg; /* error register */ /* The next two fields are not always used */ - daddr_t mt_fileno; /* number of current file on tape */ - daddr_t mt_blkno; /* current block number */ + /* these really are daddr_t, but that is only declared with _BSD_SOURCE */ + long mt_fileno; /* number of current file on tape */ + long mt_blkno; /* current block number */ }; /* diff -uNr dietlibc-0.24/include/sys/resource.h dietlibc-0.25/include/sys/resource.h --- dietlibc-0.24/include/sys/resource.h 2003-08-19 18:50:41.000000000 +0200 +++ dietlibc-0.25/include/sys/resource.h 2003-11-24 21:32:04.000000000 +0100 @@ -46,11 +46,31 @@ #define RLIMIT_DATA 2 /* max data size */ #define RLIMIT_STACK 3 /* max stack size */ #define RLIMIT_CORE 4 /* max core file size */ +#if defined(__alpha__) +#define RLIMIT_RSS 5 /* max resident set size */ +#define RLIMIT_NPROC 8 /* max number of processes */ +#define RLIMIT_NOFILE 6 /* max number of open files */ +#define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */ +#define RLIMIT_AS 7 /* address space limit */ +#elif defined(__mips__) +#define RLIMIT_RSS 7 /* max resident set size */ +#define RLIMIT_NPROC 8 /* max number of processes */ +#define RLIMIT_NOFILE 5 /* max number of open files */ +#define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */ +#define RLIMIT_AS 6 /* address space limit */ +#elif defined(__sparc__) +#define RLIMIT_RSS 5 /* max resident set size */ +#define RLIMIT_NPROC 7 /* max number of processes */ +#define RLIMIT_NOFILE 6 /* max number of open files */ +#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ +#define RLIMIT_AS 9 /* address space limit */ +#else #define RLIMIT_RSS 5 /* max resident set size */ #define RLIMIT_NPROC 6 /* max number of processes */ #define RLIMIT_NOFILE 7 /* max number of open files */ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ +#endif #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIM_NLIMITS 11 diff -uNr dietlibc-0.24/include/sys/stat.h dietlibc-0.25/include/sys/stat.h --- dietlibc-0.24/include/sys/stat.h 2003-10-10 15:17:46.000000000 +0200 +++ dietlibc-0.25/include/sys/stat.h 2004-03-26 16:25:15.000000000 +0100 @@ -64,6 +64,59 @@ __extension__ unsigned long long st_ino; }; +#elif defined(__sparc__) && defined(__arch64__) + +struct stat { + unsigned int st_dev; + unsigned long st_ino; + unsigned int st_mode; + short st_nlink; + unsigned int st_uid; + unsigned int st_gid; + unsigned int st_rdev; + long st_size; + time_t st_atime; + time_t st_mtime; + time_t st_ctime; + long st_blksize; + long st_blocks; + unsigned long __unused4[2]; +}; + +struct stat64 { + unsigned long long st_dev; + + unsigned long long st_ino; + + unsigned int st_mode; + unsigned int st_nlink; + + unsigned int st_uid; + unsigned int st_gid; + + unsigned long long st_rdev; + + unsigned char __pad3[8]; + + long long st_size; + unsigned int st_blksize; + + unsigned char __pad4[8]; + unsigned int st_blocks; + + unsigned int st_atime; + unsigned int st_atime_nsec; + + unsigned int st_mtime; + unsigned int st_mtime_nsec; + + unsigned int st_ctime; + unsigned int st_ctime_nsec; + + unsigned int __unused4; + unsigned int __unused5; +}; + #elif defined(__sparc__) struct stat { unsigned short st_dev; @@ -243,7 +296,6 @@ /* This matches struct stat64 in glibc2.1. */ -//#if !defined(__powerpc64__) struct stat64 { __extension__ unsigned long long st_dev; /* Device. */ __extension__ unsigned long long st_ino; /* File serial number. */ @@ -266,7 +318,6 @@ unsigned long int __unused4; unsigned long int __unused5; }; -//#endif #elif defined(__arm__) struct stat { unsigned short st_dev; diff -uNr dietlibc-0.24/include/sys/types.h dietlibc-0.25/include/sys/types.h --- dietlibc-0.24/include/sys/types.h 2003-11-20 12:06:10.000000000 +0100 +++ dietlibc-0.25/include/sys/types.h 2004-01-07 16:06:48.000000000 +0100 @@ -144,7 +144,7 @@ typedef uint8_t u_int8_t __attribute_dontuse__; typedef uint16_t u_int16_t __attribute_dontuse__; typedef uint32_t u_int32_t __attribute_dontuse__; -#ifndef __STRICT_ANSI__ +#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L typedef uint64_t u_int64_t __attribute_dontuse__; #endif #endif diff -uNr dietlibc-0.24/lib/__dtostr.c dietlibc-0.25/lib/__dtostr.c --- dietlibc-0.24/lib/__dtostr.c 2003-10-15 15:14:41.000000000 +0200 +++ dietlibc-0.25/lib/__dtostr.c 2003-12-05 19:52:26.000000000 +0100 @@ -47,8 +47,10 @@ if (d==0.0) { prec2=prec2==0?1:prec2+2; prec2=prec2>maxlen?8:prec2; - for (i=0; i #define ptrace fnord #include #undef ptrace @@ -10,6 +11,7 @@ int ptrace(int request, pid_t pid, void *addr, void *data); int ptrace(int request, pid_t pid, void *addr, void *data) { + errno=0; switch (request) { case PTRACE_TRACEME: case PTRACE_KILL: case PTRACE_ATTACH: case PTRACE_DETACH: diff -uNr dietlibc-0.24/lib/__stat64_cvt.c dietlibc-0.25/lib/__stat64_cvt.c --- dietlibc-0.24/lib/__stat64_cvt.c 2001-08-14 18:56:49.000000000 +0200 +++ dietlibc-0.25/lib/__stat64_cvt.c 2004-03-10 16:24:50.000000000 +0100 @@ -8,7 +8,8 @@ dest->st_ino=src->st_ino; dest->st_mode=src->st_mode; dest->st_nlink=src->st_nlink; - dest->st_uid=src->st_gid; + dest->st_uid=src->st_uid; + dest->st_gid=src->st_gid; dest->st_rdev=src->st_rdev; dest->st_size=src->st_size; dest->st_blksize=src->st_blksize; diff -uNr dietlibc-0.24/lib/__v_printf.c dietlibc-0.25/lib/__v_printf.c --- dietlibc-0.24/lib/__v_printf.c 2003-10-18 17:48:06.000000000 +0200 +++ dietlibc-0.25/lib/__v_printf.c 2003-12-05 19:52:27.000000000 +0100 @@ -123,7 +123,8 @@ case '.': flag_dot=1; if (*format=='*') { - preci=va_arg(arg_ptr,int); + int tmp=va_arg(arg_ptr,int); + preci=tmp<0?0:tmp; ++format; } else { long int tmp=strtol(format,(char**)&s,10); diff -uNr dietlibc-0.24/lib/alloc.c dietlibc-0.25/lib/alloc.c --- dietlibc-0.24/lib/alloc.c 2003-11-07 18:22:33.000000000 +0100 +++ dietlibc-0.25/lib/alloc.c 2004-01-27 15:24:11.000000000 +0100 @@ -153,10 +153,10 @@ #ifdef WANT_MALLOC_ZERO if (!size) return BLOCK_RET(zeromem); #else - if (!size) goto retzero; + if (!size) goto err_out; #endif size+=sizeof(__alloc_t); - if (size #include +#include "dietfeatures.h" +#include "dietstring.h" void* memchr(const void *s, int c, size_t n) { - register const char* t=s; - int i; - for (i=n; i; --i) { - if (*t==c) - return (char*)t; - ++t; - } + const unsigned char *pc = (unsigned char *) s; + for (;n--;pc++) + if (*pc == c) + return ((void *) pc); return 0; } diff -uNr dietlibc-0.24/lib/memcpy.c dietlibc-0.25/lib/memcpy.c --- dietlibc-0.24/lib/memcpy.c 2003-08-19 19:40:50.000000000 +0200 +++ dietlibc-0.25/lib/memcpy.c 2003-12-21 13:06:36.000000000 +0100 @@ -1,14 +1,49 @@ -#include +/* fast memcpy -- Copyright (C) 2003 Thomas M. Ogrisegg */ -/* gcc is broken and has a non-SUSv2 compliant internal prototype. - * This causes it to warn about a type mismatch here. Ignore it. */ -void* memcpy(void* dst, const void* src, size_t count) { - register char *d=dst; - register const char *s=src; - ++count; /* this actually produces better code than using count-- */ - while (__likely(--count)) { - *d = *s; - ++d; ++s; - } - return dst; +#include +#include "dietfeatures.h" +#include "dietstring.h" + +void * +memcpy (void *dst, const void *src, size_t n) +{ + void *res = dst; + unsigned char *c1, *c2; +#ifdef WANT_SMALL_STRING_ROUTINES + c1 = (unsigned char *) dst; + c2 = (unsigned char *) src; + while (n--) *c1++ = *c2++; + return (res); +#else + int tmp; + unsigned long *lx1 = NULL; + const unsigned long *lx2 = NULL; + + if (!UNALIGNED(dst, src) && n > sizeof(unsigned long)) { + + if ((tmp = STRALIGN(dst))) { + c1 = (unsigned char *) dst; + c2 = (unsigned char *) src; + while (tmp-- && n--) + *c1++ = *c2++; + if (n == (size_t) - 1) + return (res); + } + + lx1 = (unsigned long *) dst; + lx2 = (unsigned long *) src; + + for (; n >= sizeof(unsigned long); n -= sizeof(unsigned long)) + *lx1++ = *lx2++; + } + + if (n) { + c1 = (unsigned char *) (lx1?lx1:dst); + c2 = (unsigned char *) (lx1?lx2:src); + while (n--) + *c1++ = *c2++; + } + + return (res); +#endif } diff -uNr dietlibc-0.24/lib/readdir64.c dietlibc-0.25/lib/readdir64.c --- dietlibc-0.24/lib/readdir64.c 2002-11-10 00:31:08.000000000 +0100 +++ dietlibc-0.25/lib/readdir64.c 2004-03-02 22:27:19.000000000 +0100 @@ -27,8 +27,8 @@ #endif struct dirent* o; static struct dirent64 d64; -again: #ifdef __NR_getdents64 +again: if (!trygetdents64) { #endif if (!d->num || (d->cur += ((struct dirent*)(d->buf+d->cur))->d_reclen)>=d->num) { diff -uNr dietlibc-0.24/lib/strcmp.c dietlibc-0.25/lib/strcmp.c --- dietlibc-0.24/lib/strcmp.c 2003-08-19 23:14:40.000000000 +0200 +++ dietlibc-0.25/lib/strcmp.c 2003-12-21 13:06:36.000000000 +0100 @@ -1,19 +1,50 @@ +/* fast strcmp -- Copyright (C) 2003 Thomas M. Ogrisegg */ +#include #include "dietfeatures.h" -#include +#include "dietstring.h" -int strcmp(register const char *s,register const char *t) { - register char x; +int +strcmp (const char *s1, const char *s2) +{ +#ifdef WANT_SMALL_STRING_ROUTINES + while (*s1 && *s1 == *s2) + s1++, s2++; + return (*s1 - *s2); +#else + const unsigned long *lx1, *lx2; + unsigned long l1, l2; + int tmp; - for (;;) { - x = *s; if (__unlikely(x != *t)) break; if (__unlikely(!x)) break; ++s; ++t; -#ifndef WANT_SMALL_STRING_ROUTINES - x = *s; if (__unlikely(x != *t)) break; if (__unlikely(!x)) break; ++s; ++t; - x = *s; if (__unlikely(x != *t)) break; if (__unlikely(!x)) break; ++s; ++t; - x = *s; if (__unlikely(x != *t)) break; if (__unlikely(!x)) break; ++s; ++t; + if (UNALIGNED(s1, s2)) { + while (*s1 && *s1 == *s2) s1++, s2++; + return (*s1 - *s2); + } + + if ((tmp = STRALIGN(s1))) + for (; tmp--; s1++, s2++) + if (!*s1 || *s1 != *s2) + return (*s1 - *s2); + + lx1 = (unsigned long *) s1; + lx2 = (unsigned long *) s2; + + while (1) { + l1 = *lx1++; + l2 = *lx2++; + if ((((l1 - MKW(0x1)) & ~l1) & MKW(0x80)) || + ((((l2 - MKW(0x1)) & ~l2) & MKW(0x80))) || l1 != l2) { + unsigned char c1, c2; + while (1) { + c1 = l1 & 0xff; + c2 = l2 & 0xff; + if (!c1 || c1 != c2) + return (c1 - c2); + l1 >>= 8; + l2 >>= 8; + } + } + } #endif - } - return ((int)(unsigned int)(unsigned char) x) - - ((int)(unsigned int)(unsigned char) *t); } -int strcoll(const char *s,const char* t) __attribute__((weak,alias("strcmp"))); +int strcoll(const char *s,const char* t) __attribute__((weak,alias("strcmp"))); diff -uNr dietlibc-0.24/lib/strcpy.c dietlibc-0.25/lib/strcpy.c --- dietlibc-0.24/lib/strcpy.c 2003-08-19 19:32:08.000000000 +0200 +++ dietlibc-0.25/lib/strcpy.c 2003-12-21 13:06:36.000000000 +0100 @@ -1,19 +1,38 @@ -#include "dietfeatures.h" +/* fast strcpy -- Copyright (C) 2003 Thomas M. Ogrisegg */ #include +#include "dietfeatures.h" +#include "dietstring.h" -char* strcpy(register char* s,register const char* t) +char * +strcpy (char *s1, const char *s2) { - char *dest=s; -#ifndef WANT_SMALL_STRING_ROUTINES - for (;;) { - if (__unlikely(!(*s = *t))) return dest; ++s; ++t; - if (__unlikely(!(*s = *t))) return dest; ++s; ++t; - if (__unlikely(!(*s = *t))) return dest; ++s; ++t; - if (__unlikely(!(*s = *t))) return dest; ++s; ++t; - } + char *res = s1; +#ifdef WANT_SMALL_STRING_ROUTINES + while ((*s1++ = *s2++)); + return (res); #else - while (__likely(*dest++=*t++)); - return s; + int tmp; + unsigned long l; + + if (UNALIGNED(s1, s2)) { + while ((*s1++ = *s2++)); + return (res); + } + if ((tmp = STRALIGN(s1))) { + while (tmp-- && (*s1++ = *s2++)); + if (tmp != -1) return (res); + } + + while (1) { + l = *(const unsigned long *) s2; + if (((l - MKW(0x1)) & ~l) & MKW(0x80)) { + unsigned char c; + while ((*s1++ = (l & 0xff))) l>>=8; + return (res); + } + *(unsigned long *) s1 = l; + s2 += sizeof(unsigned long); + s1 += sizeof(unsigned long); + } #endif } - diff -uNr dietlibc-0.24/lib/strtoul.c dietlibc-0.25/lib/strtoul.c --- dietlibc-0.24/lib/strtoul.c 2003-11-06 13:00:09.000000000 +0100 +++ dietlibc-0.25/lib/strtoul.c 2004-01-27 15:10:53.000000000 +0100 @@ -43,7 +43,6 @@ ++nptr; } if (__unlikely(nptr==orig)) { /* no conversion done */ -err_conv: nptr=ptr; errno=EINVAL; v=0; diff -uNr dietlibc-0.24/lib/strtoull.c dietlibc-0.25/lib/strtoull.c --- dietlibc-0.24/lib/strtoull.c 2003-11-14 14:25:25.000000000 +0100 +++ dietlibc-0.25/lib/strtoull.c 2004-01-27 15:10:53.000000000 +0100 @@ -43,7 +43,6 @@ ++nptr; } if (__unlikely(nptr==orig)) { /* no conversion done */ -err_conv: nptr=ptr; errno=EINVAL; v=0; diff -uNr dietlibc-0.24/lib/vsnprintf.c dietlibc-0.25/lib/vsnprintf.c --- dietlibc-0.24/lib/vsnprintf.c 2003-11-14 22:33:50.000000000 +0100 +++ dietlibc-0.25/lib/vsnprintf.c 2004-03-26 15:46:48.000000000 +0100 @@ -27,12 +27,11 @@ int vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr) { long n; - struct str_data sd = { str, 0, size }; + struct str_data sd = { str, 0, size?size-1:0 }; struct arg_printf ap = { &sd, (int(*)(void*,size_t,void*)) swrite }; - if (size) --sd.size; n=__v_printf(&ap,format,arg_ptr); - if (str) { - if ((long)n>(long)size) str[size]=0; + if (str && size && n>=0) { + if (size!=(size_t)-1 && ((size_t)n>=size)) str[size-1]=0; else str[n]=0; } return n; diff -uNr dietlibc-0.24/libcompat/syscall.S dietlibc-0.25/libcompat/syscall.S --- dietlibc-0.24/libcompat/syscall.S 2002-07-29 12:00:45.000000000 +0200 +++ dietlibc-0.25/libcompat/syscall.S 2003-12-17 02:08:56.000000000 +0100 @@ -1,5 +1,11 @@ #include "dietfeatures.h" +#if defined(__i386__) && defined(__DYN_LIB) +#include "i386/PIC.h" +#undef WANT_THREADSAFE +#define WANT_THREADSAFE +#endif + .text .globl syscall #ifdef __arm__ @@ -27,9 +33,14 @@ jbe .Lret negl %eax #ifdef WANT_THREADSAFE - movl %eax, %ebx + movl %eax, %edx +#ifdef __DYN_LIB + PIC_INIT + call __errno_location@PLT +#else call __errno_location - movl %ebx, (%eax) +#endif + movl %edx, (%eax) xorl %eax, %eax decl %eax #else diff -uNr dietlibc-0.24/libcruft/inet_ntop.c dietlibc-0.25/libcruft/inet_ntop.c --- dietlibc-0.24/libcruft/inet_ntop.c 2002-02-24 00:08:20.000000000 +0100 +++ dietlibc-0.25/libcruft/inet_ntop.c 2004-01-15 19:44:59.000000000 +0100 @@ -22,9 +22,10 @@ unsigned int i; unsigned int temp; unsigned int compressing; + unsigned int compressed; int j; - len = 0; compressing = 0; + len = 0; compressing = 0; compressed = 0; for (j=0; j<16; j+=2) { if (j==12 && !memcmp(ip,V4mappedprefix,12)) { inet_ntoa_r(*(struct in_addr*)(ip+12),s); @@ -33,7 +34,7 @@ } temp = ((unsigned long) (unsigned char) ip[j] << 8) + (unsigned long) (unsigned char) ip[j+1]; - if (temp == 0) { + if (temp == 0 && !compressed) { if (!compressing) { compressing=1; if (j==0) { @@ -42,7 +43,7 @@ } } else { if (compressing) { - compressing=0; + compressing=0; compressed=1; *s++=':'; ++len; } i = fmt_xlong(s,temp); len += i; s += i; diff -uNr dietlibc-0.24/libcruft/nl_langinfo.c dietlibc-0.25/libcruft/nl_langinfo.c --- dietlibc-0.24/libcruft/nl_langinfo.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/libcruft/nl_langinfo.c 2003-12-15 21:43:56.000000000 +0100 @@ -0,0 +1,52 @@ +#include +#include + +static inline char* get_codeset(void) { + /* this is normally only used to look for "UTF-8" */ + char* s=getenv("LC_CTYPE"); + if (!s) s=getenv("LC_ALL"); + if (!s) s="ANSI_X3.4-1968"; /* it's what glibc does */ + return s; +} + +static const char sweekdays [7] [4] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; + +static const char weekdays [7] [10] = { + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" +}; + +static const char smonths [12] [4] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +static const char* months [12] = { + "January", "February", "March", "April", smonths[5-1], "June", + "July", "August", "September", "October", "November", "December" +}; + +char* nl_langinfo(nl_item x) { + if (x>=DAY_1 && x<=DAY_7) return (char*)weekdays[x-DAY_1]; + if (x>=ABDAY_1 && x<=ABDAY_7) return (char*)sweekdays[x-ABDAY_1]; + if (x>=MON_1 && x<=MON_12) return (char*)months[x-MON_1]; + if (x>=ABMON_1 && x<=ABMON_12) return (char*)smonths[x-ABMON_1]; + switch (x) { + case CODESET: return get_codeset(); + case D_T_FMT: return "%b %a %d %k:%M:%S %Z %Y"; + case D_FMT: return "%b %a %d"; + case T_FMT: return "%H:%M"; + case T_FMT_AMPM: return "%I:%M:%S %p"; + case AM_STR: return "am"; + case PM_STR: return "pm"; + case ERA: return 0; + case ERA_D_FMT: case ERA_D_T_FMT: case ERA_T_FMT: case ALT_DIGITS: return ""; + case RADIXCHAR: return "."; + case THOUSEP: return ""; + case YESEXPR: return "^[yY]"; + case NOEXPR: return "^[nN]"; + case CRNCYSTR: return "$"; + default: return 0; + } +} diff -uNr dietlibc-0.24/libcruft/sysconf_cpus.c dietlibc-0.25/libcruft/sysconf_cpus.c --- dietlibc-0.24/libcruft/sysconf_cpus.c 2002-05-09 03:01:17.000000000 +0200 +++ dietlibc-0.25/libcruft/sysconf_cpus.c 2004-03-26 15:52:46.000000000 +0100 @@ -2,6 +2,7 @@ #include #include #include +#include #include "dietfeatures.h" /* diff -uNr dietlibc-0.24/libdl/dlsym.c dietlibc-0.25/libdl/dlsym.c --- dietlibc-0.24/libdl/dlsym.c 2002-11-15 16:39:17.000000000 +0100 +++ dietlibc-0.25/libdl/dlsym.c 2004-01-30 19:27:32.000000000 +0100 @@ -5,7 +5,7 @@ #ifdef __DIET_LD_SO__ static #endif -void *_dlsym(void*handle,char*symbol) { +void *_dlsym(void* handle,const char* symbol) { unsigned long*sym=0; if (handle) { struct _dl_handle*dh=(struct _dl_handle*)handle; @@ -78,7 +78,7 @@ return sym; } -void*dlsym(void*handle,char*symbol) { +void* dlsym(void* handle,const char* symbol) { void*h; if (handle==RTLD_DEFAULT || !handle /* RTLD_DEFAULT is NULL on glibc */ ) h=_dl_sym_search_str(0,symbol); Files dietlibc-0.24/libpthread/__testandset.o and dietlibc-0.25/libpthread/__testandset.o differ Files dietlibc-0.24/libpthread/libpthread.a and dietlibc-0.25/libpthread/libpthread.a differ Files dietlibc-0.24/libpthread/pthread_atfork.o and dietlibc-0.25/libpthread/pthread_atfork.o differ Files dietlibc-0.24/libpthread/pthread_attr_getdetachstate.o and dietlibc-0.25/libpthread/pthread_attr_getdetachstate.o differ Files dietlibc-0.24/libpthread/pthread_attr_getinheritsched.o and dietlibc-0.25/libpthread/pthread_attr_getinheritsched.o differ Files dietlibc-0.24/libpthread/pthread_attr_getschedparam.o and dietlibc-0.25/libpthread/pthread_attr_getschedparam.o differ Files dietlibc-0.24/libpthread/pthread_attr_getschedpolicy.o and dietlibc-0.25/libpthread/pthread_attr_getschedpolicy.o differ Files dietlibc-0.24/libpthread/pthread_attr_getscope.o and dietlibc-0.25/libpthread/pthread_attr_getscope.o differ Files dietlibc-0.24/libpthread/pthread_attr_getstackaddr.o and dietlibc-0.25/libpthread/pthread_attr_getstackaddr.o differ Files dietlibc-0.24/libpthread/pthread_attr_getstacksize.o and dietlibc-0.25/libpthread/pthread_attr_getstacksize.o differ Files dietlibc-0.24/libpthread/pthread_attr_setdetachstate.o and dietlibc-0.25/libpthread/pthread_attr_setdetachstate.o differ Files dietlibc-0.24/libpthread/pthread_attr_setinheritsched.o and dietlibc-0.25/libpthread/pthread_attr_setinheritsched.o differ Files dietlibc-0.24/libpthread/pthread_attr_setschedparam.o and dietlibc-0.25/libpthread/pthread_attr_setschedparam.o differ Files dietlibc-0.24/libpthread/pthread_attr_setschedpolicy.o and dietlibc-0.25/libpthread/pthread_attr_setschedpolicy.o differ Files dietlibc-0.24/libpthread/pthread_attr_setscope.o and dietlibc-0.25/libpthread/pthread_attr_setscope.o differ Files dietlibc-0.24/libpthread/pthread_attr_setstackaddr.o and dietlibc-0.25/libpthread/pthread_attr_setstackaddr.o differ Files dietlibc-0.24/libpthread/pthread_attr_setstacksize.o and dietlibc-0.25/libpthread/pthread_attr_setstacksize.o differ Files dietlibc-0.24/libpthread/pthread_cleanup.o and dietlibc-0.25/libpthread/pthread_cleanup.o differ Files dietlibc-0.24/libpthread/pthread_cond_broadcast.o and dietlibc-0.25/libpthread/pthread_cond_broadcast.o differ Files dietlibc-0.24/libpthread/pthread_cond_destroy.o and dietlibc-0.25/libpthread/pthread_cond_destroy.o differ Files dietlibc-0.24/libpthread/pthread_cond_init.o and dietlibc-0.25/libpthread/pthread_cond_init.o differ Files dietlibc-0.24/libpthread/pthread_cond_signal.o and dietlibc-0.25/libpthread/pthread_cond_signal.o differ Files dietlibc-0.24/libpthread/pthread_cond_timedwait.o and dietlibc-0.25/libpthread/pthread_cond_timedwait.o differ Files dietlibc-0.24/libpthread/pthread_cond_wait.o and dietlibc-0.25/libpthread/pthread_cond_wait.o differ Files dietlibc-0.24/libpthread/pthread_condattr_getshared.o and dietlibc-0.25/libpthread/pthread_condattr_getshared.o differ Files dietlibc-0.24/libpthread/pthread_condattr_setshared.o and dietlibc-0.25/libpthread/pthread_condattr_setshared.o differ Files dietlibc-0.24/libpthread/pthread_create.o and dietlibc-0.25/libpthread/pthread_create.o differ Files dietlibc-0.24/libpthread/pthread_detach.o and dietlibc-0.25/libpthread/pthread_detach.o differ Files dietlibc-0.24/libpthread/pthread_dns_cruft.o and dietlibc-0.25/libpthread/pthread_dns_cruft.o differ Files dietlibc-0.24/libpthread/pthread_equal.o and dietlibc-0.25/libpthread/pthread_equal.o differ Files dietlibc-0.24/libpthread/pthread_errno.o and dietlibc-0.25/libpthread/pthread_errno.o differ Files dietlibc-0.24/libpthread/pthread_fdglue2.o and dietlibc-0.25/libpthread/pthread_fdglue2.o differ Files dietlibc-0.24/libpthread/pthread_fgetc.o and dietlibc-0.25/libpthread/pthread_fgetc.o differ Files dietlibc-0.24/libpthread/pthread_flockfile.o and dietlibc-0.25/libpthread/pthread_flockfile.o differ Files dietlibc-0.24/libpthread/pthread_fputc.o and dietlibc-0.25/libpthread/pthread_fputc.o differ diff -uNr dietlibc-0.24/libpthread/pthread_ftrylockfile.c dietlibc-0.25/libpthread/pthread_ftrylockfile.c --- dietlibc-0.24/libpthread/pthread_ftrylockfile.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/libpthread/pthread_ftrylockfile.c 2004-01-03 03:17:32.000000000 +0100 @@ -0,0 +1,5 @@ +#include "dietstdio.h" + +int ftrylockfile(FILE* f) { + return pthread_mutex_trylock(&f->m); +} Files dietlibc-0.24/libpthread/pthread_funlockfile.o and dietlibc-0.25/libpthread/pthread_funlockfile.o differ Files dietlibc-0.24/libpthread/pthread_internal.o and dietlibc-0.25/libpthread/pthread_internal.o differ Files dietlibc-0.24/libpthread/pthread_join.o and dietlibc-0.25/libpthread/pthread_join.o differ Files dietlibc-0.24/libpthread/pthread_key.o and dietlibc-0.25/libpthread/pthread_key.o differ Files dietlibc-0.24/libpthread/pthread_kill.o and dietlibc-0.25/libpthread/pthread_kill.o differ Files dietlibc-0.24/libpthread/pthread_mutex_destroy.o and dietlibc-0.25/libpthread/pthread_mutex_destroy.o differ Files dietlibc-0.24/libpthread/pthread_mutex_init.o and dietlibc-0.25/libpthread/pthread_mutex_init.o differ Files dietlibc-0.24/libpthread/pthread_mutex_lock.o and dietlibc-0.25/libpthread/pthread_mutex_lock.o differ Files dietlibc-0.24/libpthread/pthread_mutex_trylock.o and dietlibc-0.25/libpthread/pthread_mutex_trylock.o differ Files dietlibc-0.24/libpthread/pthread_mutex_unlock.o and dietlibc-0.25/libpthread/pthread_mutex_unlock.o differ Files dietlibc-0.24/libpthread/pthread_mutexattr_getkind_np.o and dietlibc-0.25/libpthread/pthread_mutexattr_getkind_np.o differ Files dietlibc-0.24/libpthread/pthread_mutexattr_init.o and dietlibc-0.25/libpthread/pthread_mutexattr_init.o differ Files dietlibc-0.24/libpthread/pthread_mutexattr_setkind_np.o and dietlibc-0.25/libpthread/pthread_mutexattr_setkind_np.o differ Files dietlibc-0.24/libpthread/pthread_self.o and dietlibc-0.25/libpthread/pthread_self.o differ Files dietlibc-0.24/libpthread/pthread_semaphore_destroy.o and dietlibc-0.25/libpthread/pthread_semaphore_destroy.o differ Files dietlibc-0.24/libpthread/pthread_semaphore_getvalue.o and dietlibc-0.25/libpthread/pthread_semaphore_getvalue.o differ Files dietlibc-0.24/libpthread/pthread_semaphore_init.o and dietlibc-0.25/libpthread/pthread_semaphore_init.o differ Files dietlibc-0.24/libpthread/pthread_semaphore_misc.o and dietlibc-0.25/libpthread/pthread_semaphore_misc.o differ Files dietlibc-0.24/libpthread/pthread_semaphore_post.o and dietlibc-0.25/libpthread/pthread_semaphore_post.o differ Files dietlibc-0.24/libpthread/pthread_semaphore_trywait.o and dietlibc-0.25/libpthread/pthread_semaphore_trywait.o differ Files dietlibc-0.24/libpthread/pthread_semaphore_wait.o and dietlibc-0.25/libpthread/pthread_semaphore_wait.o differ Files dietlibc-0.24/libpthread/pthread_setcancelstate.o and dietlibc-0.25/libpthread/pthread_setcancelstate.o differ Files dietlibc-0.24/libpthread/pthread_setschedparam.o and dietlibc-0.25/libpthread/pthread_setschedparam.o differ Files dietlibc-0.24/libpthread/pthread_sigaction.o and dietlibc-0.25/libpthread/pthread_sigaction.o differ Files dietlibc-0.24/libpthread/pthread_sigmask.o and dietlibc-0.25/libpthread/pthread_sigmask.o differ Files dietlibc-0.24/libpthread/pthread_spinlock.o and dietlibc-0.25/libpthread/pthread_spinlock.o differ Files dietlibc-0.24/libpthread/pthread_sys_alloc.o and dietlibc-0.25/libpthread/pthread_sys_alloc.o differ Files dietlibc-0.24/libpthread/pthread_sys_close.o and dietlibc-0.25/libpthread/pthread_sys_close.o differ Files dietlibc-0.24/libpthread/pthread_sys_create.o and dietlibc-0.25/libpthread/pthread_sys_create.o differ Files dietlibc-0.24/libpthread/pthread_sys_fcntl.o and dietlibc-0.25/libpthread/pthread_sys_fcntl.o differ Files dietlibc-0.24/libpthread/pthread_sys_fdatasync.o and dietlibc-0.25/libpthread/pthread_sys_fdatasync.o differ Files dietlibc-0.24/libpthread/pthread_sys_fsync.o and dietlibc-0.25/libpthread/pthread_sys_fsync.o differ Files dietlibc-0.24/libpthread/pthread_sys_logging.o and dietlibc-0.25/libpthread/pthread_sys_logging.o differ Files dietlibc-0.24/libpthread/pthread_sys_msync.o and dietlibc-0.25/libpthread/pthread_sys_msync.o differ Files dietlibc-0.24/libpthread/pthread_sys_nanosleep.o and dietlibc-0.25/libpthread/pthread_sys_nanosleep.o differ Files dietlibc-0.24/libpthread/pthread_sys_open.o and dietlibc-0.25/libpthread/pthread_sys_open.o differ Files dietlibc-0.24/libpthread/pthread_sys_pause.o and dietlibc-0.25/libpthread/pthread_sys_pause.o differ Files dietlibc-0.24/libpthread/pthread_sys_read.o and dietlibc-0.25/libpthread/pthread_sys_read.o differ Files dietlibc-0.24/libpthread/pthread_sys_sigsuspend.o and dietlibc-0.25/libpthread/pthread_sys_sigsuspend.o differ Files dietlibc-0.24/libpthread/pthread_sys_sleep.o and dietlibc-0.25/libpthread/pthread_sys_sleep.o differ Files dietlibc-0.24/libpthread/pthread_sys_tcdrain.o and dietlibc-0.25/libpthread/pthread_sys_tcdrain.o differ Files dietlibc-0.24/libpthread/pthread_sys_waitpid.o and dietlibc-0.25/libpthread/pthread_sys_waitpid.o differ Files dietlibc-0.24/libpthread/pthread_sys_write.o and dietlibc-0.25/libpthread/pthread_sys_write.o differ diff -uNr dietlibc-0.24/libshell/dirname.c dietlibc-0.25/libshell/dirname.c --- dietlibc-0.24/libshell/dirname.c 2001-07-17 19:39:08.000000000 +0200 +++ dietlibc-0.25/libshell/dirname.c 2004-01-27 14:31:05.000000000 +0100 @@ -1,25 +1,34 @@ -#include #include - +#include /* - path dirname basename - "/usr/lib" "/usr" "lib" - "/usr/" "/" "usr" - "usr" "." "usr" - "/" "/" "/" - "." "." "." - ".." "." ".." + path dirname basename + "/usr/lib" "/usr" "lib" + "/usr/" "/" "usr" + "usr" "." "usr" + "/" "/" "/" + "." "." "." + ".." "." ".." + NULL "." "." + "" "." "." */ -char *dirname(char *path) { +static char *dot="."; +#define SLASH '/' +#define EOL (char)0 +char *dirname(char *path) +{ char *c; -again: - if (!(c=strrchr(path,'/'))) return "."; - while (c[1]==0) { /* remove trailing slashes */ - if (c==path) return c; /* unless path=='/' */ - *c=0; - if (*--c!='/') break; + if ( path == NULL ) return dot; + for(;;) { + if ( !(c=strrchr(path,SLASH)) ) return dot; /* no slashes */ + if ( c[1]==EOL && c!=path ) { /* remove trailing slashes */ + while ( *c==SLASH && c!=path ) *c--=EOL; + continue; + } + if ( c!=path ) + while ( *c==SLASH ) *c--=EOL; /* slashes in the middle */ + else + path[1]=EOL; /* slash is first symbol */ + return path; } - if (*c=='/') { if (c!=path) *c=0; return path; } - goto again; } diff -uNr dietlibc-0.24/libshell/fnmatch.c dietlibc-0.25/libshell/fnmatch.c --- dietlibc-0.24/libshell/fnmatch.c 2003-09-05 16:15:50.000000000 +0200 +++ dietlibc-0.25/libshell/fnmatch.c 2004-01-27 22:43:55.000000000 +0100 @@ -4,6 +4,42 @@ #define NOTFIRST 128 +#define STRUCT_CHARCLASS(c) { #c , is##c } + +static struct charclass { + char * class; + int (*istype)(int); +} allclasses[] = { + STRUCT_CHARCLASS(alnum), + STRUCT_CHARCLASS(alpha), + STRUCT_CHARCLASS(blank), + STRUCT_CHARCLASS(cntrl), + STRUCT_CHARCLASS(digit), + STRUCT_CHARCLASS(graph), + STRUCT_CHARCLASS(lower), + STRUCT_CHARCLASS(print), + STRUCT_CHARCLASS(punct), + STRUCT_CHARCLASS(space), + STRUCT_CHARCLASS(upper), + STRUCT_CHARCLASS(xdigit), +}; + +/* look for "class:]" in pattern */ +static struct charclass *charclass_lookup(const char *pattern) { + unsigned int i; + + for (i = 0; i< sizeof(allclasses)/sizeof(*allclasses); i++) { + int len = strlen(allclasses[i].class); + if (!strncmp(pattern, allclasses[i].class, len)) { + pattern += len; + if (strncmp(pattern, ":]", 2)) goto noclass; + return &allclasses[i]; + } + } +noclass: + return NULL; +} + static int match(char c,char d,int flags) { if (flags&FNM_CASEFOLD) return (tolower(c)==tolower(d)); @@ -12,17 +48,16 @@ } int fnmatch(const char *pattern, const char *string, int flags) { - /*printf("fnmatch(\"%s\",\"%s\")\n",pattern,string);*/ if (*string==0) { while (*pattern=='*') ++pattern; return (!!*pattern); } if (*string=='.' && *pattern!='.' && (flags&FNM_PERIOD)) { /* don't match if FNM_PERIOD and this is the first char */ - if ((flags&FNM_PERIOD) && (!(flags&NOTFIRST))) + if (!(flags&NOTFIRST)) return FNM_NOMATCH; - /* don't match if FNM_PERIOD and FNM_FILE_NAME and previous was '/' */ - if ((flags&(FNM_FILE_NAME|FNM_PERIOD)) && string[-1]=='/') + /* don't match if FNM_PERIOD and FNM_PATHNAME and previous was '/' */ + if ((flags&(FNM_PATHNAME)) && string[-1]=='/') return FNM_NOMATCH; } flags|=NOTFIRST; @@ -30,25 +65,48 @@ case '[': { int neg=0; + const char* start; /* first member of character class */ + ++pattern; if (*string=='/' && flags&FNM_PATHNAME) return FNM_NOMATCH; if (*pattern=='!') { neg=1; ++pattern; } - while (*pattern && *pattern!=']') { + start=pattern; + while (*pattern) { int res=0; - if (pattern[1]=='-') { - if (*string>=*pattern && *string<=pattern[2]) res=1; - if (flags&FNM_CASEFOLD) { - if (tolower(*string)>=tolower(*pattern) && tolower(*string)<=tolower(pattern[2])) res=1; + + if (*pattern==']' && pattern!=start) break; + if (*pattern=='[' && pattern[1]==':') { + /* MEMBER - stupid POSIX char classes */ + const struct charclass *cc; + + if (!(cc = charclass_lookup(pattern+2))) goto invalidclass; + pattern += strlen(cc->class) + 4; + if (flags&FNM_CASEFOLD + && (cc->istype == isupper || cc->istype == islower)) { + res = islower(tolower(*string)); + } else { + res = ((*(cc->istype))(*string)); } - pattern+=3; } else { - res=match(*pattern,*string,flags); - ++pattern; +invalidclass: + if (pattern[1]=='-' && pattern[2]!=']') { + /* MEMBER - character range */ + if (*string>=*pattern && *string<=pattern[2]) res=1; + if (flags&FNM_CASEFOLD) { + if (tolower(*string)>=tolower(*pattern) && tolower(*string)<=tolower(pattern[2])) res=1; + } + pattern+=3; + } else { + /* MEMBER - literal character match */ + res=match(*pattern,*string,flags); + ++pattern; + } } - if (res ^ neg) { + if ((res&&!neg) || ((neg&&!res) && *pattern==']')) { while (*pattern && *pattern!=']') ++pattern; - return fnmatch(pattern+1,string+1,flags); - } + return fnmatch(pattern+!!*pattern,string+1,flags); + } else if (res && neg) + return FNM_NOMATCH; } } break; @@ -69,6 +127,9 @@ if (*string==0 || (*string=='/' && (flags&FNM_LEADING_DIR))) return 0; break; + case '?': + if (*string=='/' && flags&FNM_PATHNAME) break; + return fnmatch(pattern+1,string+1,flags); default: if (match(*pattern,*string,flags)) return fnmatch(pattern+1,string+1,flags); diff -uNr dietlibc-0.24/libshell/realpath.c dietlibc-0.25/libshell/realpath.c --- dietlibc-0.24/libshell/realpath.c 2003-10-10 15:37:12.000000000 +0200 +++ dietlibc-0.25/libshell/realpath.c 2004-01-27 22:50:42.000000000 +0100 @@ -1,76 +1,90 @@ -#include +/* realpath - determine the absolute pathname of a file + + Copyright (C) 2003 Thomas M. Ogrisegg + + This realpath has still space for improvements: + e.g., if the initial path does not start with '/' it should + be checked whether the first path component(s) is/are symlinks. + This would save lots of filesystem lookups, but also greatly + increases complexity. +*/ + +#include +#include #include +#include #include -#include +#include #include -#include "dietfeatures.h" -static char *sep(char *path) +#define CD(x) (x=='/'||!x) + +char * +realpath (const char *file, char *dst) { - char *tmp, c; - - tmp = strrchr(path, '/'); - if(tmp) { - c = tmp[1]; - tmp[1] = 0; - if (chdir(path)) { - return NULL; - } - tmp[1] = c; - - return tmp + 1; - } - - return path; + unsigned char buffer[PATH_MAX]; + size_t i, off; -} + if (!file || !dst) { errno = EINVAL; return (NULL); } + if (!*file) { errno = ENOENT; return (NULL); } -char *realpath(const char *_path, char *resolved_path) -{ - int fd = open(".", O_RDONLY), l; - char path[PATH_MAX], lnk[PATH_MAX], *tmp = (char *)""; - - if (fd < 0) { - return NULL; - } - strncpy(path, _path, PATH_MAX); - - if (chdir(path)) { - if (errno == ENOTDIR) { - l = readlink(path, lnk, PATH_MAX); - if (!(tmp = sep(path))) { - resolved_path = NULL; - goto abort; - } - if (l < 0) { - if (errno != EINVAL) { - resolved_path = NULL; - goto abort; - } - } else { - lnk[l] = 0; - if (!(tmp = sep(lnk))) { - resolved_path = NULL; - goto abort; - } - } - } else { - resolved_path = NULL; - goto abort; - } - } - if (!getcwd(resolved_path, PATH_MAX)) { - resolved_path = NULL; - goto abort; - } - - if(strcmp(resolved_path, "/") && *tmp) { - strcat(resolved_path, "/"); - } - - strcat(resolved_path, tmp); - abort: - fchdir(fd); - close(fd); - return resolved_path; + if (*file != '/') { + if (!getcwd (buffer, sizeof (buffer))) return (NULL); + off = strlen (buffer); + while (file[0] == '.' && file[1] == '.' && file[2] == '/') { + if (off) off--; + while (off && buffer[off] != '/') off--; + file += 3; + } + buffer[off++] = '/'; + i = strlen (file); + if (i+off >= PATH_MAX) return (NULL); + memcpy (buffer+off, file, i+1); + file = buffer; + } + + off = i = 0; + + while (file[i]) { + if (file[i] == '.' && file[i-1] == '/' && + ((file[i+1] == '.'&&CD(file[i+2])) || CD(file[i+1]))) { + if (file[i+1] == '/') { i+=2; continue; } + if (file[i+1] == '.') { + if (off > 2) off -= 2; + while (off && dst[off] != '/') off--; + i++; + } + i++; + continue; + } + + if (file[i] == '/' && off < PATH_MAX) { + unsigned char buf[PATH_MAX]; + int ret; + + if (file[i+1] == '/') { i+=2; continue; } + + if (off) { + if (dst[off-1] == '/') { i++; continue; } + +last_test: + dst[off] = 0; + if (-1 != (ret = readlink (dst, buf, sizeof (buf)))) { + struct stat st; + buf[ret] = 0; + if (-1 == stat (buf, &st)) return (NULL); + if (ret+(PATH_MAX-i) > PATH_MAX) return (NULL); + strcpy (buf+ret, file+i); + return (realpath (buf, dst)); + } else + if (errno == EACCES || errno == ENOENT) return (NULL); + + if (!file[i]) return (dst); + } + } + dst[off++] = file[i++]; + } + + if (off > 2 && dst[off-1] == '/') off--; + goto last_test; } diff -uNr dietlibc-0.24/libstdio/fdglue.c dietlibc-0.25/libstdio/fdglue.c --- dietlibc-0.24/libstdio/fdglue.c 2002-02-23 23:18:43.000000000 +0100 +++ dietlibc-0.25/libstdio/fdglue.c 2004-03-02 22:27:19.000000000 +0100 @@ -2,7 +2,9 @@ #include #include #include +#ifdef WANT_THREAD_SAFE #include +#endif #include "dietstdio.h" int __stdio_parse_mode(const char *mode) { diff -uNr dietlibc-0.24/libstdio/fdglue2.c dietlibc-0.25/libstdio/fdglue2.c --- dietlibc-0.24/libstdio/fdglue2.c 2003-11-11 18:35:04.000000000 +0100 +++ dietlibc-0.25/libstdio/fdglue2.c 2004-03-02 22:27:19.000000000 +0100 @@ -4,7 +4,9 @@ #include #include "dietstdio.h" #include +#ifdef WANT_THREAD_SAFE #include +#endif extern int __stdio_atexit; @@ -43,3 +45,5 @@ tmp->ungotten=0; return tmp; } + +FILE* __stdio_init_file_nothreads(int fd,int closeonerror,int mode) __attribute__((alias("__stdio_init_file"))); diff -uNr dietlibc-0.24/libugly/iconv.c dietlibc-0.25/libugly/iconv.c --- dietlibc-0.24/libugly/iconv.c 2002-02-24 00:08:21.000000000 +0100 +++ dietlibc-0.25/libugly/iconv.c 2003-12-01 18:42:12.000000000 +0100 @@ -3,22 +3,38 @@ #include "dieticonv.h" #include -size_t iconv(iconv_t cd, const char* * inbuf, size_t * +size_t iconv(iconv_t cd, char* * inbuf, size_t * inbytesleft, char* * outbuf, size_t * outbytesleft) { - size_t converted=0,i,j,k; + size_t result=0,i,j,k; int bits; + unsigned char* in,* out; + enum charset from=ic_from(cd); + enum charset to=ic_to(cd); if (!inbuf || !*inbuf) return 0; + in=(char*)(*inbuf); + out=(char*)(*outbuf); + k=0; while (*inbytesleft) { - unsigned int v=0; - v=*(unsigned char*)*inbuf; + unsigned int v; + v=*in; i=j=1; - switch (ic_from(cd)) { + switch (from) { case UCS_2: - v=ntohs(*(unsigned short*)*inbuf); + if (*inbytesleft<2) { +starve: + errno=EINVAL; + return (size_t)-1; + } + v=(((unsigned long)in[0])<<8) | + ((unsigned long)in[1]); i=2; break; case UCS_4: - v=ntohs(*(unsigned int*)*inbuf); + if (*inbytesleft<4) goto starve; + v=(((unsigned long)in[0])<<24) | + (((unsigned long)in[1])<<16) | + (((unsigned long)in[2])<<8) | + ((unsigned long)in[3]); i=4; case ISO_8859_1: break; @@ -29,43 +45,131 @@ v&=~i; break; } - for (i=1; ((*inbuf)[i]&0xc0)==0x80; ++i) - v=(v<<6)|((*inbuf)[i]&0x3f); + for (i=1; (in[i]&0xc0)==0x80; ++i) { + if (i>*inbytesleft) goto starve; + v=(v<<6)|(in[i]&0x3f); + } /* printf("got %u in %u bytes, buflen %u\n",v,i,*inbytesleft); */ break; + case UTF_16: + if (*inbytesleft<2) goto starve; + if (v==0xff && in[1]==0xfe) { + from=UTF_16_LE; *inbytesleft-=2; in+=2; goto utf16le; + } else if (v==0xfe && in[1]==0xff) { + from=UTF_16_BE; *inbytesleft-=2; in+=2; goto utf16be; + } +ABEND: + errno=EILSEQ; + return (size_t)-1; + case UTF_16_BE: +utf16be: + if (*inbytesleft<2) goto starve; + v=((unsigned long)in[0]<<8) | in[1]; +joined: + i=2; + if (v>=0xd800 && v<=0xdfff) { + long w; + if (v>0xdbff) goto ABEND; + if (*inbytesleft<4) goto starve; + if (from==UTF_16_BE) + w=((unsigned long)in[2]<<8) | in[3]; + else + w=((unsigned long)in[3]<<8) | in[2]; + if (w<0xdc00 || w>0xdfff) goto ABEND; + v=0x10000+(((v-0xd800) << 10) | (w-0xdc00)); + i=4; + } + break; + case UTF_16_LE: +utf16le: + v=((unsigned long)in[1]<<8) | in[0]; + goto joined; } - switch (ic_to(cd)) { + if (v>=0xd800 && v<=0xd8ff) goto ABEND; /* yuck! in-band signalling! */ + switch (to) { case ISO_8859_1: - **outbuf=(unsigned char)v; + if (*outbytesleft<1) goto bloat; + if (v>0xff) ++result; + *out=(unsigned char)v; + ++j; break; case UCS_2: - *(unsigned short*)*outbuf=htons(v); + if (*outbytesleft<2) goto bloat; + if (v>0xffff) ++result; + out[0]=v>>8; + out[1]=v&0xff; j=2; break; case UCS_4: - *(unsigned int*)*outbuf=htonl(v); + if (*outbytesleft<4) goto bloat; + out[0]=(v>>23)&0xff; + out[1]=(v>>16)&0xff; + out[2]=(v>>8)&0xff; + out[3]=v&0xff; j=4; break; case UTF_8: - if (v>0x04000000) { bits=30; **outbuf=0xFC; j=6; } else - if (v>0x00200000) { bits=24; **outbuf=0xF8; j=5; } else - if (v>0x00010000) { bits=18; **outbuf=0xF0; j=4; } else - if (v>0x00000800) { bits=12; **outbuf=0xE0; j=3; } else - if (v>0x00000080) { bits=6; **outbuf=0xC0; j=2; } else - { bits=0; **outbuf=0; } - **outbuf |= (unsigned char)(v>>bits); + if (v>0x04000000) { bits=30; *out=0xFC; j=6; } else + if (v>0x00200000) { bits=24; *out=0xF8; j=5; } else + if (v>0x00010000) { bits=18; *out=0xF0; j=4; } else + if (v>0x00000800) { bits=12; *out=0xE0; j=3; } else + if (v>0x00000080) { bits=6; *out=0xC0; j=2; } else + { bits=0; *out=0; } + *out|= (unsigned char)(v>>bits); if (*outbytesleft>bits)&0x3F); + out[k]=0x80+((v>>bits)&0x3F); + } + break; + case UTF_16: + if (*outbytesleft<4) goto bloat; + to=UTF_16_LE; + out[0]=0xff; + out[1]=0xfe; + out+=2; *outbytesleft-=2; + case UTF_16_LE: + if (v>0xffff) { + long a,b; + if (*outbytesleft<(j=4)) goto bloat; + v-=0x10000; + if (v>0xfffff) result++; + a=0xd800+(v>>10); b=0xdc00+(v&0x3ff); + out[1]=a>>8; + out[0]=a&0xff; + out[3]=b>>8; + out[2]=b&0xff; + } else { + if (*outbytesleft<(j=2)) goto bloat; + out[1]=(v>>8)&0xff; + out[0]=v&0xff; + } + break; + case UTF_16_BE: + if (v>0xffff) { + long a,b; + if (*outbytesleft<(j=4)) goto bloat; + v-=0x10000; + if (v>0xfffff) result++; + a=0xd800+(v>>10); b=0xdc00+(v&0x3ff); + out[0]=a>>8; + out[1]=a&0xff; + out[2]=b>>8; + out[3]=b&0xff; + } else { + if (*outbytesleft<(j=2)) goto bloat; + out[0]=(v>>8)&0xff; + out[1]=v&0xff; } break; } - *inbuf+=i; *inbytesleft-=i; ++converted; - *outbuf+=j; *outbytesleft-=j; + in+=i; *inbytesleft-=i; + out+=j; *outbytesleft-=j; } - return converted; + *inbuf=in; *outbuf=out; + return result; } diff -uNr dietlibc-0.24/libugly/iconv_open.c dietlibc-0.25/libugly/iconv_open.c --- dietlibc-0.24/libugly/iconv_open.c 2002-10-27 17:51:03.000000000 +0100 +++ dietlibc-0.25/libugly/iconv_open.c 2003-12-01 18:42:12.000000000 +0100 @@ -9,8 +9,11 @@ if (!strcasecmp(s,"UTF-8")) return UTF_8; else if (!strcasecmp(s,"UCS-2") || !strcasecmp(s,"UCS2")) return UCS_2; else if (!strcasecmp(s,"UCS-4") || !strcasecmp(s,"UCS4")) return UCS_4; else - if (!strcasecmp(s,"ISO-8859-1")) return ISO_8859_1; else + if (!strcasecmp(s,"ISO-8859-1") || !strcasecmp(s,"LATIN1")) return ISO_8859_1; else if (!strcasecmp(s,"US-ASCII")) return ISO_8859_1; else + if (!strcasecmp(s,"UTF-16")) return UTF_16; else + if (!strcasecmp(s,"UTF-16BE")) return UTF_16_BE; else + if (!strcasecmp(s,"UTF-16LE")) return UTF_16_LE; else return INVALID; } diff -uNr dietlibc-0.24/libugly/localtime_r.c dietlibc-0.25/libugly/localtime_r.c --- dietlibc-0.24/libugly/localtime_r.c 2002-07-22 16:51:13.000000000 +0200 +++ dietlibc-0.25/libugly/localtime_r.c 2004-03-27 01:47:00.000000000 +0100 @@ -4,7 +4,7 @@ #ifdef WANT_TZFILE_PARSER extern void __maplocaltime(void); -extern time_t __tzfile_map(time_t t, int *isdst); +extern time_t __tzfile_map(time_t t, int *isdst, int forward); #else extern long int timezone; extern int daylight; @@ -14,7 +14,7 @@ time_t tmp; #ifdef WANT_TZFILE_PARSER __maplocaltime(); - tmp=__tzfile_map(*t,&r->tm_isdst); + tmp=__tzfile_map(*t,&r->tm_isdst,1); #else struct timezone tz; gettimeofday(0, &tz); diff -uNr dietlibc-0.24/libugly/mktime.c dietlibc-0.25/libugly/mktime.c --- dietlibc-0.24/libugly/mktime.c 2003-11-20 14:12:27.000000000 +0100 +++ dietlibc-0.25/libugly/mktime.c 2004-03-27 01:47:00.000000000 +0100 @@ -1,58 +1,30 @@ +#define _GNU_SOURCE #include +#include "dietfeatures.h" -extern const short __spm []; - -/* apparently mktime is expected to treat the time as local time. - * I don't understand what that is supposed to mean, though */ - -time_t mktime ( register struct tm* const t ) -{ - register time_t day; - register time_t i; - - if ( t->tm_year < 70 ) - return (time_t) -1; - - day = t->tm_yday = __spm [t->tm_mon] + t->tm_mday-1 + ( __isleap (t->tm_year+1900) & (t->tm_mon > 1) ); - - for ( i = 70; i < t->tm_year; i++ ) - day += 365 + __isleap (i+1900); - - /* day is now the number of days since 'Jan 1 1970' */ - i = 7; - t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */ +#ifdef WANT_TZFILE_PARSER +extern void __maplocaltime(void); +extern time_t __tzfile_map(time_t t, int *isdst, int forward); +#else +extern long int timezone; +extern int daylight; +#endif - i = 24; - day *= i; - i = 60; - return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; +time_t mktime(register struct tm* const t) { + time_t x=timegm(t); +#ifdef WANT_TZFILE_PARSER + int isdst; + time_t y; + __maplocaltime(); + x=__tzfile_map(x,&isdst,0); +#else + struct timezone tz; + gettimeofday(0, &tz); + timezone=tz.tz_minuteswest*60L; + x+=timezone; +#endif + return x; } time_t timelocal(struct tm* const t) __attribute__((alias("mktime"))); -#if 0 - -#include - -main() -{ - int i, j, k; - static char *s[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; - - for (i=70; i<200; i++) - for (j=0; j<12; j++) - for (k=1; k<=31; k++) { - struct tm t; - double x; - t.tm_year = i; - t.tm_mon = j; - t.tm_mday = k; - t.tm_hour = 0; - t.tm_min = 0; - t.tm_sec = 0; - x = mktime (&t); - printf ("%4d.%5.0f %2u.%02u.%04u %s\n", (int)floor(x/86400), x-86400.*(int)floor(x/86400), k, j+1, 1900+i, s[t.tm_wday] ); - } - -} -#endif diff -uNr dietlibc-0.24/libugly/timegm.c dietlibc-0.25/libugly/timegm.c --- dietlibc-0.24/libugly/timegm.c 2003-11-20 14:13:17.000000000 +0100 +++ dietlibc-0.25/libugly/timegm.c 2004-03-27 01:47:00.000000000 +0100 @@ -6,24 +6,50 @@ extern const short __spm []; time_t timegm(struct tm *const t) { - register time_t day; - register time_t i; - - if ( t->tm_year < 70 ) - return (time_t) -1; - - day = t->tm_yday = __spm [t->tm_mon] + t->tm_mday-1 + ( __isleap (t->tm_year+1900) & (t->tm_mon > 1) ); - - for ( i = 70; i < t->tm_year; i++ ) - day += 365 + __isleap (i+1900); - - /* day is now the number of days since 'Jan 1 1970' */ - i = 7; - t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */ - - i = 24; - day *= i; - i = 60; - return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; + register time_t day; + register time_t i; + register time_t years = t->tm_year - 70; + + if (t->tm_sec>60) { t->tm_min += t->tm_sec/60; t->tm_sec%=60; } + if (t->tm_min>60) { t->tm_hour += t->tm_min/60; t->tm_min%=60; } + if (t->tm_hour>60) { t->tm_mday += t->tm_hour/60; t->tm_hour%=60; } + if (t->tm_mon>12) { t->tm_year += t->tm_mon/12; t->tm_mon%=12; } + while (t->tm_mday>__spm[t->tm_mon]) { + if (t->tm_mon==1 && __isleap(t->tm_year+1900)) { + if (t->tm_mon==31+29) break; + --t->tm_mday; + } + t->tm_mday-=__spm[t->tm_mon]; + ++t->tm_mon; + if (t->tm_mon>11) { t->tm_mon=0; ++t->tm_year; } + } + + if (t->tm_year < 70) + return (time_t) -1; + + /* Days since 1970 is 365 * number of years + number of leap years since 1970 */ + day = years * 365 + (years + 1) / 4; + + /* After 2100 we have to substract 3 leap years for every 400 years + This is not intuitive. Most mktime implementations do not support + dates after 2059, anyway, so we might leave this out for it's + bloat. */ + if ((years -= 131) >= 0) { + years /= 100; + day -= (years >> 2) * 3 + 1; + if ((years &= 3) == 3) years--; + day -= years; + } + + day += t->tm_yday = __spm [t->tm_mon] + t->tm_mday-1 + ( __isleap (t->tm_year+1900) & (t->tm_mon > 1) ); + + /* day is now the number of days since 'Jan 1 1970' */ + i = 7; + t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */ + + i = 24; + day *= i; + i = 60; + return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; } diff -uNr dietlibc-0.24/libugly/tzfile.c dietlibc-0.25/libugly/tzfile.c --- dietlibc-0.24/libugly/tzfile.c 2003-06-26 00:45:50.000000000 +0200 +++ dietlibc-0.25/libugly/tzfile.c 2004-03-27 01:47:00.000000000 +0100 @@ -5,7 +5,11 @@ #include #include -/* #include */ +#include + +/* This code appears to be subtly wrong depending on the date. + * However, the documentation I found about the tzfile layout are not + * sufficient to debug this. */ char* tzname[2]={"GMT","GMT"}; @@ -23,7 +27,11 @@ len=lseek(fd,0,SEEK_END); if ((tzfile=mmap(0,len,PROT_READ,MAP_PRIVATE,fd,0))==MAP_FAILED) return; close(fd); - if (ntohl(*(int*)tzfile) != 0x545a6966) return; + if (len<44 || ntohl(*(int*)tzfile) != 0x545a6966) { + munmap(tzfile,len); + tzfile=0; + return; + } tzlen=len; } @@ -34,8 +42,8 @@ ((unsigned long)c[3]); } -time_t __tzfile_map(time_t t, int *isdst); -time_t __tzfile_map(time_t t, int *isdst) { +time_t __tzfile_map(time_t t, int *isdst, int forward); +time_t __tzfile_map(time_t t, int *isdst, int forward) { /* "TZif" plus 16 reserved bytes. */ char *tmp; int i; @@ -76,21 +84,43 @@ tmp=tzfile+20+6*4; daylight=(tzh_timecnt>0); - for (i=0; i= t) { - char* tz=tmp; -/* printf("match at %d\n",i); */ - tmp+=tzh_timecnt*4; - i=tmp[i-1]; -/* printf("using index %d\n",i); */ - tmp+=tzh_timecnt; + if (forward) { + for (i=0; i= t) { + char* tz=tmp; + /* printf("match at %d\n",i); */ + tmp+=tzh_timecnt*4; + i=tmp[i-1]; + /* printf("using index %d\n",i); */ + tmp+=tzh_timecnt; + tz+=tzh_timecnt*5+tzh_leapcnt*4+tzh_typecnt*6; + tmp+=i*6; + /* printf("(%lu,%d,%d)\n",ntohl(*(int*)tmp),tmp[4],tmp[5]); */ + *isdst=tmp[4]; + tzname[0]=tz+tmp[5]; + timezone=__myntohl(tmp); + return t+timezone; + } + } + } else { /* reverse map, for mktime */ + time_t prevtz,nexttz=0,lastval=0; +// printf("tzh_timecnt: %d\n",tzh_timecnt); + for (i=0; i t) { +// printf("FOUND!1!! Offset %d\n",prevtz); + return t-prevtz; + } + lastval=k; } } return t; @@ -99,7 +129,7 @@ void tzset(void) { int isdst; __maplocaltime(); - __tzfile_map(time(0),&isdst); + __tzfile_map(time(0),&isdst,1); } #else diff -uNr dietlibc-0.24/mipsel/Makefile.add dietlibc-0.25/mipsel/Makefile.add --- dietlibc-0.24/mipsel/Makefile.add 2002-02-02 23:50:31.000000000 +0100 +++ dietlibc-0.25/mipsel/Makefile.add 2004-01-09 18:41:05.000000000 +0100 @@ -1,2 +1,3 @@ -include mips/Makefile.add ENDIAN=-EL +CFLAGS+=$(ENDIAN) -Os -G 0 -fstrict-aliasing -fno-pic -mno-abicalls +VPATH:=mips:syscalls.s:$(VPATH) diff -uNr dietlibc-0.24/mipsel/syscalls.h dietlibc-0.25/mipsel/syscalls.h --- dietlibc-0.24/mipsel/syscalls.h 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/mipsel/syscalls.h 2004-01-09 18:41:05.000000000 +0100 @@ -0,0 +1 @@ +#include "../mips/syscalls.h" diff -uNr dietlibc-0.24/sparc64/Makefile.add dietlibc-0.25/sparc64/Makefile.add --- dietlibc-0.24/sparc64/Makefile.add 2002-03-26 14:07:38.000000000 +0100 +++ dietlibc-0.25/sparc64/Makefile.add 2004-03-25 22:11:00.000000000 +0100 @@ -1,2 +1,3 @@ CFLAGS+=-m64 -Os VPATH:=sparc64:syscalls.s:$(VPATH) +LIBOBJ+=$(patsubst %,$(OBJDIR)/%,__time.o) diff -uNr dietlibc-0.24/sparc64/__time.c dietlibc-0.25/sparc64/__time.c --- dietlibc-0.24/sparc64/__time.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/sparc64/__time.c 2004-03-25 22:11:00.000000000 +0100 @@ -0,0 +1 @@ +#include "alpha/__time.c" diff -uNr dietlibc-0.24/sparc64/time.c dietlibc-0.25/sparc64/time.c --- dietlibc-0.24/sparc64/time.c 2002-03-26 14:07:38.000000000 +0100 +++ dietlibc-0.25/sparc64/time.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,14 +0,0 @@ -#include -#include - -time_t time(time_t*t) { - struct timeval tv; - time_t ret; - if (gettimeofday(&tv,0)) { - ret=(time_t)-1; - } else { - ret=(time_t)tv.tv_sec; - } - if (t) *t=ret; - return ret; -} diff -uNr dietlibc-0.24/test/Makefile dietlibc-0.25/test/Makefile --- dietlibc-0.24/test/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/Makefile 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,62 @@ +all: direnttest inet stdiotests stdlibtests stringtests timetests \ +test ffs getdelim stdlib + +DIET=diet +CC=gcc +CFLAGS=-nostdinc -Wall + +LCOMPAT=-lcompat + +TESTPROGRAMS=adjtime argv asprintf atexit bsearch byteswap calloc confstr cycles empty flush fnmatch \ +fputc ftw fwrite getaddrinfo getenv getgrnam gethostbyaddr gethostbyname \ +gethostbyname_r getmntent getopt getpass getpwnam getservbyname getservbyport getusershell \ +glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness \ +memccpy memchr memcmp memcpy memrchr memusage mktime mmap_test pipe printf printftest \ +protoent prototypes putenv pwent rand48 read1 readdir regex select sendfile servent siglist \ +speed spent sprintf sscanf stdarg strcasecmp strcmp strlen strncat strncpy strptime strrchr \ +strstr strtol sysenter ungetc waitpid + +test: $(TESTPROGRAMS) + +ffs: ffs.c + $(DIET) $(CC) $(CFLAGS) $^ $(LCOMPAT) -o $@ + +getdelim: getdelim.c + $(DIET) $(CC) $(CFLAGS) $^ $(LCOMPAT) -o $@ + +syscall: syscall.c + $(DIET) $(CC) $^ -o $@ + +testandset: testandset.c + $(DIET) $(CC) $^ -o $@ + +direnttest: + $(MAKE) -C dirent CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT) + +inettest: + $(MAKE) -C inet CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT) + +stdiotests: + $(MAKE) -C stdio CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT) + +stdlibtests: + $(MAKE) -C stdlib CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT) + +stringtests: + $(MAKE) -C string CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT) + +timetests: + $(MAKE) -C time CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT) + + +%: %.c + $(DIET) $(CC) $(CFLAGS) $^ -o $@ + +clean: + rm -f $(TESTPROGRAMS) getdelim ffs + $(MAKE) -C dirent clean + $(MAKE) -C stdio clean + $(MAKE) -C stdlib clean + $(MAKE) -C string clean + $(MAKE) -C time clean + diff -uNr dietlibc-0.24/test/argv.c dietlibc-0.25/test/argv.c --- dietlibc-0.24/test/argv.c 2003-02-20 16:57:12.000000000 +0100 +++ dietlibc-0.25/test/argv.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,7 +1,9 @@ #include #include -int main(int argc,char* argv[],char* envp[]) { +extern char **environ; + +int main(int argc,char* argv[]) { int i; char** x; for (i=0; i<=argc; ++i) diff -uNr dietlibc-0.24/test/asprintf.c dietlibc-0.25/test/asprintf.c --- dietlibc-0.24/test/asprintf.c 2003-06-03 14:05:40.000000000 +0200 +++ dietlibc-0.25/test/asprintf.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,9 +1,21 @@ #define _GNU_SOURCE #include +#include +#include -int main(void){ -char *path; -asprintf(&path, "/proc" "/%d/stat", 1); -return printf("%s\n",path); -} +int main(int argc, char **argv) { + char *path; + int asprintlen=0; + + if ( argc < 2 ) return 111; + + asprintlen=asprintf(&path, "/proc" "/%s/stat", argv[1]); + assert(strlen(path) == asprintlen); + + printf("%s\n", path); + asprintlen=asprintf(&path, "/proc" "/%d/stat", strlen(argv[1])); + assert(strlen(path) == asprintlen); + printf("%s\n", path); +return 0; +} diff -uNr dietlibc-0.24/test/bsearch.c dietlibc-0.25/test/bsearch.c --- dietlibc-0.24/test/bsearch.c 2003-02-20 16:57:12.000000000 +0100 +++ dietlibc-0.25/test/bsearch.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,7 +1,8 @@ +#include #include #include #include -#include +#include int compint(const void *a, const void *b) { register const int* A=a; @@ -10,7 +11,7 @@ } void die(const char* message) { - __write2(message); + write(2,message,strlen(message)); exit(1); } @@ -18,7 +19,6 @@ #define SIZE 1000 int array[SIZE],array2[SIZE]; int i,j; - long a,b,c; int *k; for (j=10; j #include #include +#include -main() { +int main() { + char buf[100]; printf("%x %x\n",bswap_16(0x1234),bswap_16(0x5678)); + snprintf(buf,100,"%x %x", bswap_16(0x1234), bswap_16(0x5678)); + assert(strcmp(buf, "3412 7856") == 0); + printf("%lx\n",bswap_32(0x12345678)); + snprintf(buf,100,"%lx", bswap_32(0x12345678)); + assert(strcmp(buf, "78563412") == 0); + printf("%qx\n",bswap_64(0x123456789ABCDEFull)); + snprintf(buf,100,"%qx", bswap_64(0x123456789ABCDEFull)); + assert(strcmp(buf, "efcdab8967452301") == 0); + return 0; } diff -uNr dietlibc-0.24/test/cycles.c dietlibc-0.25/test/cycles.c --- dietlibc-0.24/test/cycles.c 2002-11-06 17:43:17.000000000 +0100 +++ dietlibc-0.25/test/cycles.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,6 +1,10 @@ #include #include #include +#include +#include + +extern char **environ; int main(int argc,char* argv[]) { uint64_t a,b; @@ -9,4 +13,6 @@ wait(0); asm volatile("rdtsc":"=A"(b)); printf("%llu cycles\n",b-a); + + return 0; } diff -uNr dietlibc-0.24/test/dirent/Makefile dietlibc-0.25/test/dirent/Makefile --- dietlibc-0.24/test/dirent/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/dirent/Makefile 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,16 @@ +DIET=diet +CC=gcc +CFLAGS=-Wall + +all: dirent + +TESTPROGRAMS=opendir-tst1 tst-seekdir + +dirent: $(TESTPROGRAMS) + +%: %.c + $(DIET) $(CC) $(CFLAGS) $^ -o $@ + +clean: + rm -f $(TESTPROGRAMS) + diff -uNr dietlibc-0.24/test/dirent/opendir-tst1.c dietlibc-0.25/test/dirent/opendir-tst1.c --- dietlibc-0.24/test/dirent/opendir-tst1.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/dirent/opendir-tst1.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,95 @@ +/* Copyright (C) 1998, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1998. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +//#include +#include + + +/* Name of the FIFO. */ +char tmpname[] = "fifoXXXXXX"; + +void do_cleanup (void) +{ + remove (tmpname); +} + + +/* Do the real work. */ +static int +real_test (void) +{ + DIR *dirp; + + /* This should not block for an FIFO. */ + dirp = opendir (tmpname); + + /* Successful. */ + if (dirp != NULL) + { + /* Oh, oh, how can this work? */ + fputs ("`opendir' succeeded on a FIFO???\n", stdout); + closedir (dirp); + return 1; + } + + if (errno != ENOTDIR) + { + fprintf (stdout, "`opendir' return error `%s' instead of `%s'\n", + strerror (errno), strerror (ENOTDIR)); + return 1; + } + + return 0; +} + + +int main (int argc, char *argv[]) +{ + int retval; + atexit(do_cleanup); + + if (mktemp (tmpname) == NULL) + { + perror ("mktemp"); + return 1; + } + + /* Try to generate a FIFO. */ + if (mknod (tmpname, 0600 | S_IFIFO, 0) < 0) + { + perror ("mknod"); + /* We cannot make this an error. */ + return 0; + } + + retval = real_test (); + + return retval; +} + + diff -uNr dietlibc-0.24/test/dirent/runtests.sh dietlibc-0.25/test/dirent/runtests.sh --- dietlibc-0.24/test/dirent/runtests.sh 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/dirent/runtests.sh 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,9 @@ +#!/bin/sh + +TESTPROGRAMS="opendir-tst1 tst-seekdir" + +for p in $TESTPROGRAMS; do +echo "---";echo testing $p;echo "---" + ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 ) +done + diff -uNr dietlibc-0.24/test/dirent/tst-seekdir.c dietlibc-0.25/test/dirent/tst-seekdir.c --- dietlibc-0.24/test/dirent/tst-seekdir.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/dirent/tst-seekdir.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,50 @@ +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + DIR * dirp; + long int save3 = 0; + long int cur; + int i = 0; + int result = 0; + struct dirent *dp; + + dirp = opendir ("."); + for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp)) + { + /* save position 3 (after fourth entry) */ + if (i++ == 3) + save3 = telldir (dirp); + + printf ("%s\n", dp->d_name); + + /* stop at 400 (just to make sure dirp->__offset and dirp->__size are + scrambled */ + if (i == 400) + break; + } + + printf ("going back past 4-th entry...\n"); + + /* go back to saved entry */ + seekdir (dirp, save3); + + /* Check whether telldir equals to save3 now. */ + cur = telldir (dirp); + if (cur != save3) + { + printf ("seekdir (d, %ld); telldir (d) == %ld\n", save3, cur); + result = 1; + } + + /* print remaining files (3-last) */ + for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp)) + printf ("%s\n", dp->d_name); + + + closedir (dirp); + return result; +} diff -uNr dietlibc-0.24/test/dirname.c dietlibc-0.25/test/dirname.c --- dietlibc-0.24/test/dirname.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/dirname.c 2004-01-19 16:31:16.000000000 +0100 @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + char s[80]; + + strncpy(s,"/usr/lib",80); assert(strcmp(dirname(s), "/usr")==0); + strncpy(s,"/usr/",80); assert(strcmp(dirname(s), "/")==0); + strncpy(s,"usr",80); assert(strcmp(dirname(s), ".")==0); + strncpy(s,"usr/test",80); assert(strcmp(dirname(s), "usr")==0); + strncpy(s,"usr/test/test2",80); assert(strcmp(dirname(s), "usr/test")==0); + strncpy(s,"/usr",80); assert(strcmp(dirname(s), "/")==0); + strncpy(s,"/",80); assert(strcmp(dirname(s), "/")==0); + strncpy(s,".",80); assert(strcmp(dirname(s), ".")==0); + strncpy(s,"..",80); assert(strcmp(dirname(s), ".")==0); + strncpy(s,"////",80); assert(strcmp(dirname(s), "/")==0); + strncpy(s,"//",80); assert(strcmp(dirname(s), "/")==0); + assert(strcmp(dirname(NULL),".")==0); + s[0]=0; assert(strcmp(dirname(s), ".")==0); + + puts("OK"); + return 0; +} diff -uNr dietlibc-0.24/test/ffs.c dietlibc-0.25/test/ffs.c --- dietlibc-0.24/test/ffs.c 2003-08-20 02:41:46.000000000 +0200 +++ dietlibc-0.25/test/ffs.c 2003-12-15 14:07:42.000000000 +0100 @@ -3,7 +3,7 @@ #include #include -main() { +int main() { assert(ffs(1)==1); assert(ffs(2)==2); assert(ffs(4)==3); @@ -12,4 +12,6 @@ assert(ffsll(511)==1); assert(ffsll(256)==9); assert(ffsll(0x200000000ll)==34); + + return 0; } diff -uNr dietlibc-0.24/test/fstab dietlibc-0.25/test/fstab --- dietlibc-0.24/test/fstab 2002-05-09 03:09:49.000000000 +0200 +++ dietlibc-0.25/test/fstab 2003-12-15 14:07:42.000000000 +0100 @@ -17,5 +17,6 @@ # none /dev devfs noauto 0 0 # proc /proc proc noauto 0 0 # tmpfs /service tmpfs noauto 0 0 +#sysfs /sys sysfs noauto 0 0 /dev/floppy/0 /mnt/floppy auto defaults,noauto 0 0 diff -uNr dietlibc-0.24/test/ftw.c dietlibc-0.25/test/ftw.c --- dietlibc-0.24/test/ftw.c 2001-11-04 23:41:38.000000000 +0100 +++ dietlibc-0.25/test/ftw.c 2003-12-15 14:07:42.000000000 +0100 @@ -8,4 +8,5 @@ int main() { ftw("/tmp",traverse,10); + return 0; } diff -uNr dietlibc-0.24/test/gethostbyname.c dietlibc-0.25/test/gethostbyname.c --- dietlibc-0.24/test/gethostbyname.c 2003-02-21 03:33:21.000000000 +0100 +++ dietlibc-0.25/test/gethostbyname.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,11 +1,11 @@ #include #include #include +#include + int main() { - struct in_addr bar; struct hostent *foo; -// foo=gethostbyname("zeit.fu-berlin.de"); foo=gethostbyname("zeit.fu-berlin.de"); if (foo) { int i; @@ -13,6 +13,8 @@ for (i=0; foo->h_aliases[i]; ++i) { printf(" also known as %s\n",foo->h_aliases[i]); } - } + } else return 1; /* printf("%g %g\n",1e-10,1e10); */ + +return 0; } diff -uNr dietlibc-0.24/test/gethostbyname_r.c dietlibc-0.25/test/gethostbyname_r.c --- dietlibc-0.24/test/gethostbyname_r.c 2002-05-02 23:57:28.000000000 +0200 +++ dietlibc-0.25/test/gethostbyname_r.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,14 +1,19 @@ +#include #include #include #include +#include +#include int main() { - struct in_addr bar; - struct hostent host,*res; char buf[2048]; int fnord; - if (gethostbyname_r("knuth",&host,buf,2048,&res,&fnord)) + if (gethostbyname_r("localhost",&host,buf,2048,&res,&fnord)) return 2; printf("%s -> %s\n",res->h_name,inet_ntoa(*(struct in_addr*)res->h_addr)); + + assert(strcmp(res->h_name, "localhost") == 0); + assert(strcmp((char *)inet_ntoa(*(struct in_addr*)res->h_addr), "127.0.0.1") == 0); + return 0; } diff -uNr dietlibc-0.24/test/getmntent.c dietlibc-0.25/test/getmntent.c --- dietlibc-0.24/test/getmntent.c 2002-08-05 20:08:24.000000000 +0200 +++ dietlibc-0.25/test/getmntent.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,20 +1,42 @@ +#include #include #include int main() { - FILE* f=fopen("test/fstab","r"); - struct mntent* e; - while ((e=getmntent(f))) { + int entsuccess=0; + FILE* fstab = setmntent("fstab", "r"); + struct mntent* e; + + if (!fstab) { + perror("setmntent()"); + return 1; + } + +while ((e = getmntent(fstab))) { + entsuccess=1; #if 0 - char *mnt_fsname; /* name of mounted file system */ - char *mnt_dir; /* file system path prefix */ - char *mnt_type; /* mount type (see mntent.h) */ - char *mnt_opts; /* mount options (see mntent.h) */ - int mnt_freq; /* dump frequency in days */ - int mnt_passno; /* pass number on parallel fsck */ + char *mnt_fsname; /* name of mounted file system */ + char *mnt_dir; /* file system path prefix */ + char *mnt_type; /* mount type (see mntent.h) */ + char *mnt_opts; /* mount options (see mntent.h) */ + int mnt_freq; /* dump frequency in days */ + int mnt_passno; /* pass number on parallel fsck */ #endif - printf("fsname %s\n dir %s\n type %s\n opts %s\n freq %d\n passno %d\n\n", - e->mnt_fsname,e->mnt_dir,e->mnt_type,e->mnt_opts,e->mnt_freq,e->mnt_passno); - } - return 0; + printf("fsname %s\n dir %s\n type %s\n opts %s\n freq %d\n passno %d\n\n", + e->mnt_fsname,e->mnt_dir,e->mnt_type,e->mnt_opts,e->mnt_freq,e->mnt_passno); + } + + if ( !entsuccess ) { + perror("getmntent()"); + return 2; + } + + printf("closing /etc/fstab\n"); + assert ( 1 == endmntent(fstab)); + printf("closing /etc/fstab again\n"); + assert ( 1 == endmntent(fstab)); /* endmntent must always return 1 */ + printf("entmntent(0)\n"); + assert ( 1 == endmntent(0)); /* causes a segfault with diet libc */ + return 0; } + diff -uNr dietlibc-0.24/test/getpwnam.c dietlibc-0.25/test/getpwnam.c --- dietlibc-0.24/test/getpwnam.c 2001-10-27 01:33:36.000000000 +0200 +++ dietlibc-0.25/test/getpwnam.c 2003-12-15 14:07:42.000000000 +0100 @@ -4,11 +4,18 @@ int main() { struct passwd* pw=getpwnam("fnord"); if (!pw) pw=getpwnam("alias"); + if (!pw) pw=getpwnam("nobody"); + if (!pw) pw=getpwnam("root"); if (!pw) { puts("not found"); return 0; } + printf("name %s\npassword %s\nuid %u\ngid %u\ngecos %s\ndir %s\nshell %s\n", pw->pw_name,pw->pw_passwd,pw->pw_uid,pw->pw_gid,pw->pw_gecos,pw->pw_dir, pw->pw_shell); + + pw=getpwnam("doesNOThopefullnotexistsdar3245235wrafsdsfsdpl"); + if (pw) printf("getpwnam(\"doesNOThopefullnotexistsdar3245235wrafsdsfsdpl\" did not return null\n"); + return 0; } diff -uNr dietlibc-0.24/test/getservbyname.c dietlibc-0.25/test/getservbyname.c --- dietlibc-0.24/test/getservbyname.c 2003-02-20 16:57:12.000000000 +0100 +++ dietlibc-0.25/test/getservbyname.c 2003-12-15 14:07:42.000000000 +0100 @@ -3,7 +3,7 @@ int main(int argc,char *argv[]) { struct servent* se; - if (se=getservbyname("pop","tcp")) { + if ((se=getservbyname("pop","tcp"))) { int i; printf("name %s\tport %d\tproto %s\n",se->s_name,ntohs(se->s_port),se->s_proto); for (i=0; i<16; ++i) { diff -uNr dietlibc-0.24/test/getservbyport.c dietlibc-0.25/test/getservbyport.c --- dietlibc-0.24/test/getservbyport.c 2003-02-20 16:57:12.000000000 +0100 +++ dietlibc-0.25/test/getservbyport.c 2003-12-15 14:07:42.000000000 +0100 @@ -4,7 +4,7 @@ int main(int argc,char *argv[]) { struct servent* se; - if (se=getservbyport(htons(80),"tcp")) { + if ((se=getservbyport(htons(80),"tcp"))) { int i; printf("name %s\tport %d\tproto %s\n",se->s_name,ntohs(se->s_port),se->s_proto); for (i=0; i<16; ++i) { diff -uNr dietlibc-0.24/test/getusershell.c dietlibc-0.25/test/getusershell.c --- dietlibc-0.24/test/getusershell.c 2003-02-20 16:57:12.000000000 +0100 +++ dietlibc-0.25/test/getusershell.c 2003-12-15 14:07:42.000000000 +0100 @@ -4,7 +4,7 @@ int main() { char* c; - while (c=getusershell()) + while ((c=getusershell())) puts(c); return 0; } diff -uNr dietlibc-0.24/test/glob.c dietlibc-0.25/test/glob.c --- dietlibc-0.24/test/glob.c 2003-02-12 14:20:57.000000000 +0100 +++ dietlibc-0.25/test/glob.c 2003-12-15 14:07:42.000000000 +0100 @@ -7,4 +7,5 @@ printf("%d\n",glob("/tmp/*.c",0,0,&g)); for (i=0; i + +#ifdef __dietlibc__ #include +#else +#warning "You are not using dietlibc, using printf instead of __write1" +#include +#define __write1(x) printf("%s", x) +#endif -main() { - __write1("Hello, world!\n"); +#define HELLO "Hello, world!\n" +int main() { + assert (__write1(HELLO) == sizeof HELLO -1 ); + + return 0; } diff -uNr dietlibc-0.24/test/iconv.c dietlibc-0.25/test/iconv.c --- dietlibc-0.24/test/iconv.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/iconv.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,15 @@ +#include +#include +#include +#include + +int main() { + iconv_t i=iconv_open("UTF-16BE","UTF-16"); + char foo[100]="\xFE\xFF\xD8\x08\xDF\x45\x00\x3D\x00\x52\x00\x61"; + char bar[100]; + char *x=foo,*y=bar; + size_t X=12,Y=100; + assert(iconv(i,&x,&X,&y,&Y)==0 && X==0 && Y==90); + assert(memcmp(bar,"\xD8\x08\xDF\x45\x00\x3D\x00\x52\x00\x61",10)==0); +return 0; +} diff -uNr dietlibc-0.24/test/inet/Makefile dietlibc-0.25/test/inet/Makefile --- dietlibc-0.24/test/inet/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/inet/Makefile 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,17 @@ +DIET=diet +CC=gcc +CFLAGS=-Wall + +TESTPROGRAMS=test_ifindex tst-gethnm tst-ntoa +# tst-network does not link w diet libc +all: inet + +inet: $(TESTPROGRAMS) + +%: %.c + $(DIET) $(CC) $(CFLAGS) $^ -o $@ + +clean: + rm -f $(TESTPROGRAMS) + + diff -uNr dietlibc-0.24/test/inet/runtests.sh dietlibc-0.25/test/inet/runtests.sh --- dietlibc-0.24/test/inet/runtests.sh 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/inet/runtests.sh 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,10 @@ +#!/bin/sh + +TESTPROGRAMS="test_ifindex tst-gethnm tst-ntoa" + +for p in $TESTPROGRAMS; do +echo "---";echo testing $p;echo "---" + ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 ) + done + + diff -uNr dietlibc-0.24/test/inet/test_ifindex.c dietlibc-0.25/test/inet/test_ifindex.c --- dietlibc-0.24/test/inet/test_ifindex.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/inet/test_ifindex.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,65 @@ +/* Test interface name <-> index conversions. + Copyright (C) 1997, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Philip Blundell . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + +int +main (void) +{ + int failures = 0; + struct if_nameindex *idx = if_nameindex (), *p; + if (idx == NULL) + { + if (errno != ENOSYS) + { + printf ("Couldn't get any interfaces.\n"); + exit (1); + } + /* The function is simply not implemented. */ + exit (0); + } + + printf ("Idx Name | Idx Name\n"); + + for (p = idx; p->if_index || p->if_name; ++p) + { + char buf[IFNAMSIZ]; + unsigned int ni; + int result; + printf ("%3d %15s | ", p->if_index, p->if_name); + printf ("%3d", ni = if_nametoindex (p->if_name)); + printf ("%15s", if_indextoname (p->if_index, buf)); + result = (ni != p->if_index || (strcmp (buf, p->if_name))); + if (ni == p->if_index) + /* We have to make sure that this is not an alias with the + same interface number. */ + if (p->if_index == if_nametoindex (buf)) + result = 0; + printf ("%10s", result ? "fail" : "okay"); + printf ("\n"); + failures += result; + } + if_freenameindex (idx); + return failures ? 1 : 0; +} diff -uNr dietlibc-0.24/test/inet/tst-gethnm.c dietlibc-0.25/test/inet/tst-gethnm.c --- dietlibc-0.24/test/inet/tst-gethnm.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/inet/tst-gethnm.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,64 @@ +/* Based on a test case by grd@algonet.se. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int +main (void) +{ + struct hostent *ent; + struct in_addr hostaddr; + int result = 0; + + inet_aton ("127.0.0.1", (struct in_addr *) &hostaddr.s_addr); + ent = gethostbyaddr (&hostaddr, sizeof (hostaddr), AF_INET); + if (ent == NULL) + puts ("gethostbyaddr (...) == NULL"); + else + { + puts ("Using gethostbyaddr(..):"); + printf ("h_name: %s\n", ent->h_name); + + if (ent->h_aliases == NULL) + puts ("ent->h_aliases == NULL"); + else + printf ("h_aliases[0]: %s\n", ent->h_aliases[0]); + } + + ent = gethostbyname ("127.0.0.1"); + if (ent == NULL) + { + puts ("gethostbyname (\"127.0.0.1\") == NULL"); + result = 1; + } + else + { + printf ("\nNow using gethostbyname(..):\n"); + printf ("h_name: %s\n", ent->h_name); + if (strcmp (ent->h_name, "127.0.0.1") != 0) + { + puts ("ent->h_name != \"127.0.0.1\""); + result = 1; + } + + if (ent->h_aliases == NULL) + { + puts ("ent->h_aliases == NULL"); + result = 1; + } + else + { + printf ("h_aliases[0]: %s\n", ent->h_aliases[0]); + result |= ent->h_aliases[0] != NULL; + } + } + + return result; +} diff -uNr dietlibc-0.24/test/inet/tst-network.c dietlibc-0.25/test/inet/tst-network.c --- dietlibc-0.24/test/inet/tst-network.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/inet/tst-network.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,73 @@ +/* Test for inet_network. + Copyright (C) 2000, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Jaeger , 2000. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +struct +{ + const char *network; + uint32_t number; +} tests [] = +{ + {"1.0.0.0", 0x1000000}, + {"1.0.0", 0x10000}, + {"1.0", 0x100}, + {"1", 0x1}, + {"192.168.0.0", 0xC0A80000}, + /* Now some invalid addresses. */ + {"141.30.225.2800", INADDR_NONE}, + {"141.76.1.1.1", INADDR_NONE}, + {"141.76.1.11.", INADDR_NONE}, + {"1410", INADDR_NONE}, + {"1.1410", INADDR_NONE}, + {"1.1410.", INADDR_NONE}, + {"1.1410", INADDR_NONE}, + {"141.76.1111", INADDR_NONE}, + {"141.76.1111.", INADDR_NONE} +}; + + +int +main (void) +{ + int errors = 0; + size_t i; + uint32_t res; + + for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i) + { + printf ("Testing: %s\n", tests[i].network); + res = inet_network (tests[i].network); + + if (res != tests[i].number) + { + printf ("Test failed for inet_network (\"%s\"):\n", + tests[i].network); + printf ("Expected return value %u (0x%x) but got %u (0x%x).\n", + tests[i].number, tests[i].number, res, res); + } + + } + + return errors != 0; +} diff -uNr dietlibc-0.24/test/inet/tst-ntoa.c dietlibc-0.25/test/inet/tst-ntoa.c --- dietlibc-0.24/test/inet/tst-ntoa.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/inet/tst-ntoa.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,36 @@ +#include +#include +#include +#include + + +static int +test (unsigned int inaddr, const char *expected) +{ + struct in_addr addr; + char *res; + int fail; + + addr.s_addr = htonl (inaddr); + res = inet_ntoa (addr); + fail = strcmp (res, expected); + + printf ("%#010x -> \"%s\" -> %s%s\n", inaddr, res, + fail ? "fail, expected" : "ok", fail ? expected : ""); + + return fail; +} + + +int +main (void) +{ + int result = 0; + + result |= test (INADDR_LOOPBACK, "127.0.0.1"); + result |= test (INADDR_BROADCAST, "255.255.255.255"); + result |= test (INADDR_ANY, "0.0.0.0"); + result |= test (0xc0060746, "192.6.7.70"); + + return result; +} diff -uNr dietlibc-0.24/test/ltostr.c dietlibc-0.25/test/ltostr.c --- dietlibc-0.24/test/ltostr.c 2003-02-20 16:57:13.000000000 +0100 +++ dietlibc-0.25/test/ltostr.c 2003-12-15 14:07:42.000000000 +0100 @@ -2,6 +2,10 @@ #include #include +#ifndef __dietlibc__ +#warning "You are not using dietlibc, __ltostr test disbled" +int main () { return 0; } +#else int main() { char buf[1024]; assert(__ltostr(buf,10,1723,10,0)==4); assert(!strcmp(buf,"1723")); @@ -10,3 +14,4 @@ assert(__ltostr(buf,3,0xFEFE,16,1)==2); assert(!strcmp(buf,"FE")); return 0; } +#endif diff -uNr dietlibc-0.24/test/md5_testharness.c dietlibc-0.25/test/md5_testharness.c --- dietlibc-0.24/test/md5_testharness.c 2002-03-08 11:56:15.000000000 +0100 +++ dietlibc-0.25/test/md5_testharness.c 2003-12-15 14:07:42.000000000 +0100 @@ -2,6 +2,10 @@ #include #include +#ifndef __dietlibc__ +#warning "You are not using diet libc, md5 test disbled" +int main(void) { return 0; } +#else #include @@ -150,5 +154,5 @@ return (errorcode); } - +#endif diff -uNr dietlibc-0.24/test/memchr.c dietlibc-0.25/test/memchr.c --- dietlibc-0.24/test/memchr.c 2002-04-29 22:18:43.000000000 +0200 +++ dietlibc-0.25/test/memchr.c 2004-03-27 00:28:13.000000000 +0100 @@ -8,5 +8,6 @@ assert(memchr(test,'u',7) == test+2); assert(memchr(test,'b',7)==test); assert(memchr(test+6,'r',1)==test+6); + assert(memchr(test+7,0,100)==test+7); return 0; } diff -uNr dietlibc-0.24/test/mktime.c dietlibc-0.25/test/mktime.c --- dietlibc-0.24/test/mktime.c 2003-02-20 16:57:13.000000000 +0100 +++ dietlibc-0.25/test/mktime.c 2004-03-27 01:47:00.000000000 +0100 @@ -7,13 +7,17 @@ t.tm_min=2; t.tm_hour=3; t.tm_mday=29; - t.tm_mon=1; + t.tm_mon=2; t.tm_year=100; printf("%d\n",mktime(&t)); t.tm_mday=1; t.tm_mon=3; t.tm_year=102; printf("%d\n",mktime(&t)); + t.tm_mday=1; + t.tm_mon=6; + t.tm_year=102; + printf("%d\n",mktime(&t)); return 0; } diff -uNr dietlibc-0.24/test/printf.c dietlibc-0.25/test/printf.c --- dietlibc-0.24/test/printf.c 2002-04-21 23:45:03.000000000 +0200 +++ dietlibc-0.25/test/printf.c 2004-01-07 16:06:48.000000000 +0100 @@ -1,17 +1,123 @@ #include #include +#include +#include +#include +#include -main() { - char buf[100]; - int i; - if (printf("foo")!=3) return 1; - sprintf(buf,"%8.7lx",0xfefe); - if (!strcmp(buf," 000fefe")) return 1; - return 0; +#define ALGN 5 + +// https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=112986 #if 0 - i=printf("foo %d\n",23); - fprintf(stderr,"got %d\n",i); - fprintf(stderr,"got %d\n",printf("foo")); +#undef assert +#define assert(X) if (!(X)) { write(2, #X "\n", sizeof(#X)); *(char *)0 = 0; } +#endif + +#define TEST_INIT(EXP) \ + char buf[sizeof(EXP)+ALGN*3+16]; \ + int rc; \ + memset(buf, cmp[0], sizeof buf) + +#define TEST_CHECK(EXP,SZ) \ + assert(rc==sizeof(EXP)-1); \ + assert(memcmp(buf,cmp,ALGN)==0); \ + if ((SZ)>=0) { \ + assert(memcmp(buf+ALGN,(EXP),(SZ))==0); \ + assert(buf[ALGN+(SZ)]=='\0'); \ + } \ + assert(memcmp(buf+ALGN+(SZ)+1,cmp,ALGN)==0) + + +#define TEST_SPRINTF(EXP,...) \ + { \ + TEST_INIT(EXP); \ + rc=sprintf(buf+ALGN,__VA_ARGS__); \ + TEST_CHECK(EXP,rc); \ + } + +#define TEST_SNPRINTF(EXP,SZ, ...) \ + { \ + volatile char * args[] = { EXP, #SZ }; \ + int test_sz=MIN((SZ),sizeof(EXP))-1; \ + TEST_INIT(EXP); \ + rc=snprintf(buf+ALGN,(SZ),__VA_ARGS__); \ + TEST_CHECK(EXP, test_sz); \ + } + +#define TEST_SNPRINTF_NULL(EXP, ...) \ + { \ + int rc=snprintf(0,0, __VA_ARGS__); \ + assert(rc==sizeof(EXP)-1); \ + } + +#define TEST(EXP, ...) \ + TEST_SPRINTF (EXP, __VA_ARGS__); \ + TEST_SNPRINTF(EXP, sizeof(EXP)+1, __VA_ARGS__); \ + TEST_SNPRINTF(EXP, sizeof(EXP), __VA_ARGS__); \ + TEST_SNPRINTF(EXP, sizeof(EXP)-1, __VA_ARGS__); \ + TEST_SNPRINTF(EXP, 1, __VA_ARGS__); \ + TEST_SNPRINTF(EXP, 0, __VA_ARGS__); \ + TEST_SNPRINTF(EXP, sizeof(EXP)+ALGN, __VA_ARGS__); \ + TEST_SNPRINTF_NULL(EXP, __VA_ARGS__) + + +int main() +{ + char cmp[ALGN]; + memset(cmp, '\376', sizeof cmp); + + TEST("x", "x"); + TEST("xy", "xy"); + + + TEST("23", "%d", 23); + TEST("5", "%d", 5); + TEST("0.05", "%.2f", 0.05); + TEST("0.000009", "%f", 9e-6); + TEST("0.010000", "%f", 1e-2); + TEST(" -1", "%6d", -1); + TEST("012", "%03o", 10); + + TEST("foobar", "%s", "foobar"); + TEST("01.23", "%05.2f", 1.23); + + TEST("42", "%i", 42); + TEST("", "%.0i", 0); + + TEST("52", "%o", 42); + TEST("", "%.0o", 0); + + TEST("42", "%u", 42); + TEST("", "%.0u", 0); + + TEST("2a", "%x", 42); + TEST("", "%.0x", 0); + + TEST("2A", "%X", 42); + TEST("", "%.0x", 0); + + TEST("42.23", "%5.2f", 42.23); + TEST("42.23", "%5.4g", 42.23); + TEST(" 42.2", "%5.3g", 42.23); + + TEST(" 1", "%*i", 4, 1); + TEST(" 1", "%4i", 1); + TEST("1 ", "%-4i", 1); + TEST(" +1", "%+4i", 1); + TEST("+1 ", "%-+4i", 1); + TEST(" 1 ", "%- 4i", 1); + TEST("0001", "%04i", 1); + TEST("+001", "%+04i", 1); + + TEST("0x1", "%#x", 1); + +#ifdef XSI_TESTS + setlocale(LC_ALL, "de_DE"); + + TEST("1.234", "%'u", 1234); + TEST("2 1", "%2$u %1$u", 1, 2); #endif -// fprintf(stderr,"fflush returned %d\n",fflush(stdout)); + + + return EXIT_SUCCESS; } diff -uNr dietlibc-0.24/test/printftest.c dietlibc-0.25/test/printftest.c --- dietlibc-0.24/test/printftest.c 2003-10-17 16:36:38.000000000 +0200 +++ dietlibc-0.25/test/printftest.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,4 +1,5 @@ #include +#include char * format[] = { "%", @@ -61,7 +62,7 @@ (void) printf("\"\n"); } -void main() +int main() { char buf[256]; int i; @@ -146,4 +147,5 @@ printf ("snprintf (\"%%.999999u\", 10) == %d\n", snprintf(buf2, sizeof(buf2), "%.999999u", 10)); } + return 0; } diff -uNr dietlibc-0.24/test/protoent.c dietlibc-0.25/test/protoent.c --- dietlibc-0.24/test/protoent.c 2003-02-20 16:57:13.000000000 +0100 +++ dietlibc-0.25/test/protoent.c 2003-12-15 14:07:42.000000000 +0100 @@ -15,7 +15,7 @@ } #else struct protoent* se; - while (se=getprotoent()) { + while ((se=getprotoent())) { int i; printf("name %s\tproto %d\n",se->p_name,se->p_proto); for (i=0; i<16; ++i) { diff -uNr dietlibc-0.24/test/realpath.c dietlibc-0.25/test/realpath.c --- dietlibc-0.24/test/realpath.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/realpath.c 2004-01-27 22:50:42.000000000 +0100 @@ -0,0 +1,22 @@ +#include +#include +#include + +main() { + char buf[1024]; + + realpath("fnord",buf); + puts(buf); + mkdir("foo",0755); + symlink("foo","bar"); + close(open("foo/blah",O_WRONLY|O_CREAT,0700)); + realpath("bar/blah",buf); + puts(buf); + symlink("..","foo/blub"); + realpath("bar/blub/foo/blub",buf); + puts(buf); + unlink("foo/blub"); + unlink("foo/blah"); + rmdir("foo"); + unlink("bar"); +} diff -uNr dietlibc-0.24/test/runtests.sh dietlibc-0.25/test/runtests.sh --- dietlibc-0.24/test/runtests.sh 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/runtests.sh 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,37 @@ +SUBDIRS="dirent inet stdio string stdlib time" + +TESTPROGRAMS="adjtime argv atexit bsearch byteswap calloc confstr empty flush fputc ffs fnmatch ftw fwrite getaddrinfo getenv getdelim getgrnam gethostbyaddr gethostbyname gethostbyname_r getmntent getopt getpwnam getservbyname getservbyport getusershell glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness memccpy memchr memcmp memcpy memrchr memusage mktime mmap_test pipe printf printftest protoent prototypes putenv pwent rand48 readdir regex select sendfile servent siglist speed spent sprintf sscanf stdarg strcasecmp strcmp strlen strncat strncpy strptime strrchr strstr strtol sysenter ungetc waitpid" + +STDIN="read1" +PASS="getpass" + +CWD=`pwd` + +for d in $SUBDIRS; do + echo Entering directory $d + cd $d && ./runtests.sh + cd "$CWD" || exit 1 +done + + +for p in $TESTPROGRAMS; do +echo "---";echo testing $p;echo "---" + ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 ) +done + +./asprintf foobar || ( echo TESTCASE asprintf exited non-zero 1>&2 ; sleep 5 ) +./cycles strncpy || ( echo TESTCASE cycles exited non-zero 1>&2 ; sleep 5 ) + +for p in $STDIN;do +echo "---";echo testing $p;echo "---" +echo foobar | ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5) +done + +for p in $PASS;do + echo "---";echo testing $p;echo "---" + echo if you are not prompted for input it is broken + sleep 2 + echo foobar | ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5) +done + + diff -uNr dietlibc-0.24/test/sendfile.c dietlibc-0.25/test/sendfile.c --- dietlibc-0.24/test/sendfile.c 2003-05-08 23:21:41.000000000 +0200 +++ dietlibc-0.25/test/sendfile.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,7 +1,15 @@ // #define _FILE_OFFSET_BITS 64 #include +#include -main() { +int main() { off_t o=0; - sendfile(1,0,&o,100); + int ret=sendfile(1,0,&o,100); + + if (ret<0) + perror("sendfile()"); + + printf("sendfile returned %d\n",ret); + +return 0; } diff -uNr dietlibc-0.24/test/servent.c dietlibc-0.25/test/servent.c --- dietlibc-0.24/test/servent.c 2003-02-20 16:57:13.000000000 +0100 +++ dietlibc-0.25/test/servent.c 2003-12-15 14:07:42.000000000 +0100 @@ -16,7 +16,7 @@ } #else struct servent* se; - while (se=getservent()) { + while ((se=getservent())) { int i; printf("name %s\tport %d\tproto %s\n",se->s_name,ntohs(se->s_port),se->s_proto); for (i=0; i<16; ++i) { diff -uNr dietlibc-0.24/test/siglist.c dietlibc-0.25/test/siglist.c --- dietlibc-0.24/test/siglist.c 2003-10-18 17:52:01.000000000 +0200 +++ dietlibc-0.25/test/siglist.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,6 +1,9 @@ +#define _GNU_SOURCE #include +#include #include -main() { +int main() { puts(strsignal(SIGPIPE)); + return 0; } diff -uNr dietlibc-0.24/test/speed.c dietlibc-0.25/test/speed.c --- dietlibc-0.24/test/speed.c 2003-04-12 14:40:24.000000000 +0200 +++ dietlibc-0.25/test/speed.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,10 +1,16 @@ #include #include #include +#include -main() { +int main() { int i; time_t t; + + printf("%d\n", time(0)); for (i=0; i<10000000; ++i) t=time(0); + + printf("%d\n", time(0)); + return 0; } diff -uNr dietlibc-0.24/test/spent.c dietlibc-0.25/test/spent.c --- dietlibc-0.24/test/spent.c 2003-02-20 16:57:13.000000000 +0100 +++ dietlibc-0.25/test/spent.c 2003-12-15 14:07:42.000000000 +0100 @@ -5,7 +5,6 @@ struct spwd sp,*tmp; char buf[1000]; while (getspent_r(&sp,buf,sizeof(buf),&tmp)==0) { - int i; printf("name %s\tpassword %s\n",sp.sp_namp,sp.sp_pwdp); printf(" %ld %d %d %d %d %d %d\n",sp.sp_lstchg, sp.sp_min, sp.sp_max, sp.sp_warn, sp.sp_inact, sp.sp_expire, sp.sp_flag); diff -uNr dietlibc-0.24/test/sprintf.c dietlibc-0.25/test/sprintf.c --- dietlibc-0.24/test/sprintf.c 2003-08-26 19:55:24.000000000 +0200 +++ dietlibc-0.25/test/sprintf.c 2003-12-03 21:51:24.000000000 +0100 @@ -25,5 +25,7 @@ assert(!strcmp(buf,"")); assert(snprintf(buf,0,"x")==1); assert(!strcmp(buf,"")); + assert(sprintf(buf,"%03o",10)==3); + assert(!strcmp(buf,"012")); return 0; } diff -uNr dietlibc-0.24/test/stdio/Makefile dietlibc-0.25/test/stdio/Makefile --- dietlibc-0.24/test/stdio/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/Makefile 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,23 @@ +DIET=diet +CC=gcc +CFLAGS=-Wall -nostdinc +LCOMPAT=-lcompat + +all: stdiotest tstgetln + +TESTPROGRAMS=tst-ferror tstdiomisc tst-fdopen tst-fileno \ +tst-fphex tst-fseek tst-printf tstscanf tst-sprintf tst-sscanf tst-tmpnam \ +tst-unbputc tst-ungetc + +stdiotest: $(TESTPROGRAMS) + +%: %.c + $(DIET) $(CC) $(CFLAGS) $^ -o $@ + +tstgetln: tstgetln.c + $(DIET) $(CC) $(CFLAGS) $^ $(LCOMPAT) -o $@ + +clean: + rm -f $(TESTPROGRAMS) tstgetln + + diff -uNr dietlibc-0.24/test/stdio/runtests.sh dietlibc-0.25/test/stdio/runtests.sh --- dietlibc-0.24/test/stdio/runtests.sh 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/runtests.sh 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,20 @@ +#!/bin/sh + +TESTPROGRAMS="tstdiomisc tst-fdopen tst-fileno tst-fphex tst-fseek tst-printf tst-sprintf tst-sscanf tst-tmpnam tst-unbputc tst-ungetc" + +for f in "tstgetln tst-ferror tstscanf";do +echo " +25 54.32E-1 thompson +56789 0123 56a72 +2 quarts of oil +-12.8degrees Celsius +lots of luck +10.0LBS of fertilizer +100ergs of energy" | ./$f || ( echo TESTCASE $f exited non-zero 1>&2 ; sleep 5 ) +done + +for p in $TESTPROGRAMS; do +echo "---";echo testing $p;echo "---" + ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 ) +done + diff -uNr dietlibc-0.24/test/stdio/tst-fdopen.c dietlibc-0.25/test/stdio/tst-fdopen.c --- dietlibc-0.24/test/stdio/tst-fdopen.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-fdopen.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,50 @@ +/* Test for fdopen bugs. */ + +#include +#include +#include + +#undef assert +#define assert(x) \ + if (!(x)) \ + { \ + fputs ("test failed: " #x "\n", stderr); \ + retval = 1; \ + goto the_end; \ + } + +char buffer[256]; + +int +main (int argc, char *argv[]) +{ + char *name; + FILE *fp = NULL; + int retval = 0; + int fd; + + name = tmpnam (NULL); + fp = fopen (name, "w"); + assert (fp != NULL) + fputs ("foobar and baz", fp); + fclose (fp); + fp = NULL; + + fd = open (name, O_RDONLY); + assert (fd != -1); + assert (lseek (fd, 5, SEEK_SET) == 5); + /* The file position indicator associated with the new stream is set to + the position indicated by the file offset associated with the file + descriptor. */ + fp = fdopen (fd, "r"); + assert (fp != NULL); + assert (getc (fp) == 'r'); + assert (getc (fp) == ' '); + +the_end: + if (fp != NULL) + fclose (fp); + unlink (name); + + return retval; +} diff -uNr dietlibc-0.24/test/stdio/tst-ferror.c dietlibc-0.25/test/stdio/tst-ferror.c --- dietlibc-0.24/test/stdio/tst-ferror.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-ferror.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,41 @@ +#include + +int +main (int argc, char *argv[]) +{ + char buf[100]; + int result = 0; + + if (ferror (stdin) != 0) + { + fputs ("error bit set for stdin at startup\n", stdout); + result = 1; + } + if (fgets (buf, sizeof buf, stdin) != buf) + { + fputs ("fgets with existing input has problem\n", stdout); + result = 1; + } + if (ferror (stdin) != 0) + { + fputs ("error bit set for stdin after setup\n", stdout); + result = 1; + } + if (fputc ('a', stdin) != EOF) + { + fputs ("fputc to stdin does not terminate with an error\n", stdout); + result = 1; + } + if (ferror (stdin) == 0) + { + fputs ("error bit not set for stdin after fputc\n", stdout); + result = 1; + } + clearerr (stdin); + if (ferror (stdin) != 0) + { + fputs ("error bit set for stdin after clearerr\n", stdout); + result = 1; + } + return result; +} diff -uNr dietlibc-0.24/test/stdio/tst-fileno.c dietlibc-0.25/test/stdio/tst-fileno.c --- dietlibc-0.24/test/stdio/tst-fileno.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-fileno.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,38 @@ +/* Copyright (C) 1994, 1997, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +static int +check (const char *name, FILE *stream, int fd) +{ + int sfd = fileno (stream); + printf ("(fileno (%s) = %d) %c= %d\n", name, sfd, + sfd == fd ? '=' : '!', fd); + return sfd != fd; +} + +int +main (void) +{ + return (check ("stdin", stdin, STDIN_FILENO) || + check ("stdout", stdout, STDOUT_FILENO) || + check ("stderr", stderr, STDERR_FILENO)); +} diff -uNr dietlibc-0.24/test/stdio/tst-fphex.c dietlibc-0.25/test/stdio/tst-fphex.c --- dietlibc-0.24/test/stdio/tst-fphex.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-fphex.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,48 @@ +/* Test program for %a printf formats. */ + +#include +#include + +struct testcase +{ + double value; + const char *fmt; + const char *expect; +}; + +static const struct testcase testcases[] = + { + { 0x0.0030p+0, "%a", "0x1.8p-11" }, + { 0x0.0040p+0, "%a", "0x1p-10" }, + { 0x0.0030p+0, "%040a", "0x00000000000000000000000000000001.8p-11" }, + { 0x0.0040p+0, "%040a", "0x0000000000000000000000000000000001p-10" }, + { 0x0.0040p+0, "%40a", " 0x1p-10" }, + { 0x0.0040p+0, "%#40a", " 0x1.p-10" }, + { 0x0.0040p+0, "%-40a", "0x1p-10 " }, + { 0x0.0040p+0, "%#-40a", "0x1.p-10 " }, + { 0x0.0030p+0, "%040e", "00000000000000000000000000007.324219e-04" }, + { 0x0.0040p+0, "%040e", "00000000000000000000000000009.765625e-04" }, + }; + + +int main (int argc, char **argv) { + const struct testcase *t; + int result = 0; + + for (t = testcases; + t < &testcases[sizeof testcases / sizeof testcases[0]]; + ++t) + { + char buf[1024]; + int n = snprintf (buf, sizeof buf, t->fmt, t->value); + if (n != strlen (t->expect) || strcmp (buf, t->expect) != 0) + { + printf ("%s\tExpected \"%s\" (%u)\n\tGot \"%s\" (%d, %u)\n", + t->fmt, t->expect, strlen (t->expect), buf, n, strlen (buf)); + result = 1; + } + } + + return result; +} + diff -uNr dietlibc-0.24/test/stdio/tst-fseek.c dietlibc-0.25/test/stdio/tst-fseek.c --- dietlibc-0.24/test/stdio/tst-fseek.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-fseek.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,484 @@ +/* Tests of fseek and fseeko. + Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 2000. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + + +int +main (void) +{ + const char *tmpdir; + char *fname; + int fd; + FILE *fp; + const char outstr[] = "hello world!\n"; + char strbuf[sizeof outstr]; + char buf[200]; + struct stat64 st1; + struct stat64 st2; + int result = 0; + + tmpdir = getenv ("TMPDIR"); + if (tmpdir == NULL || tmpdir[0] == '\0') + tmpdir = "/tmp"; + + asprintf (&fname, "%s/tst-fseek.XXXXXX", tmpdir); + if (fname == NULL) { + fprintf(stderr, "cannot generate name for temporary file: %s\n",strerror(errno)); + return 1; + } + + /* Create a temporary file. */ + fd = mkstemp (fname); + if (fd == -1) { + fprintf(stderr, "cannot open temporary file: %s\n",strerror(errno)); + return 1; + } + + fp = fdopen (fd, "w+"); + if (fp == NULL) { + fprintf(stderr, "cannot get FILE for temporary file: %s\n",strerror(errno)); + return 1; + } + setbuffer (fp, strbuf, sizeof (outstr) -1); + + if (fwrite (outstr, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: write error\n", __LINE__); + result = 1; + goto out; + } + + /* The EOF flag must be reset. */ + if (fgetc (fp) != EOF) + { + printf ("%d: managed to read at end of file\n", __LINE__); + result = 1; + } + else if (! feof (fp)) + { + printf ("%d: EOF flag not set\n", __LINE__); + result = 1; + } + if (fseek (fp, 0, SEEK_CUR) != 0) + { + printf ("%d: fseek(fp, 0, SEEK_CUR) failed\n", __LINE__); + result = 1; + } + else if (feof (fp)) + { + printf ("%d: fseek() didn't reset EOF flag\n", __LINE__); + result = 1; + } + + /* Do the same for fseeko(). */ + if (fgetc (fp) != EOF) + { + printf ("%d: managed to read at end of file\n", __LINE__); + result = 1; + } + else if (! feof (fp)) + { + printf ("%d: EOF flag not set\n", __LINE__); + result = 1; + } + if (fseeko (fp, 0, SEEK_CUR) != 0) + { + printf ("%d: fseek(fp, 0, SEEK_CUR) failed\n", __LINE__); + result = 1; + } + else if (feof (fp)) + { + printf ("%d: fseek() didn't reset EOF flag\n", __LINE__); + result = 1; + } + + /* Go back to the beginning of the file: absolute. */ + if (fseek (fp, 0, SEEK_SET) != 0) + { + printf ("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush (fp) != 0) + { + printf ("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek (fd, 0, SEEK_CUR) != 0) + { + printf ("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0) + { + printf ("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } + + /* Now with fseeko. */ + if (fseeko (fp, 0, SEEK_SET) != 0) + { + printf ("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush (fp) != 0) + { + printf ("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek (fd, 0, SEEK_CUR) != 0) + { + printf ("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0) + { + printf ("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } + + /* Go back to the beginning of the file: relative. */ + if (fseek (fp, -((int) sizeof (outstr) - 1), SEEK_CUR) != 0) + { + printf ("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush (fp) != 0) + { + printf ("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek (fd, 0, SEEK_CUR) != 0) + { + printf ("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0) + { + printf ("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } + + /* Now with fseeko. */ + if (fseeko (fp, -((int) sizeof (outstr) - 1), SEEK_CUR) != 0) + { + printf ("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush (fp) != 0) + { + printf ("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek (fd, 0, SEEK_CUR) != 0) + { + printf ("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0) + { + printf ("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } + + /* Go back to the beginning of the file: from the end. */ + if (fseek (fp, -((int) sizeof (outstr) - 1), SEEK_END) != 0) + { + printf ("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush (fp) != 0) + { + printf ("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek (fd, 0, SEEK_CUR) != 0) + { + printf ("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0) + { + printf ("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } + + /* Now with fseeko. */ + if (fseeko (fp, -((int) sizeof (outstr) - 1), SEEK_END) != 0) + { + printf ("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__); + result = 1; + } + else if (fflush (fp) != 0) + { + printf ("%d: fflush() failed\n", __LINE__); + result = 1; + } + else if (lseek (fd, 0, SEEK_CUR) != 0) + { + printf ("%d: lseek() returned different position\n", __LINE__); + result = 1; + } + else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: fread() failed\n", __LINE__); + result = 1; + } + else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0) + { + printf ("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__); + result = 1; + } + + if (fwrite (outstr, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: write error 2\n", __LINE__); + result = 1; + goto out; + } + + if (fwrite (outstr, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: write error 3\n", __LINE__); + result = 1; + goto out; + } + + if (fwrite (outstr, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: write error 4\n", __LINE__); + result = 1; + goto out; + } + + if (fwrite (outstr, sizeof (outstr) - 1, 1, fp) != 1) + { + printf ("%d: write error 5\n", __LINE__); + result = 1; + goto out; + } + + if (fputc ('1', fp) == EOF || fputc ('2', fp) == EOF) + { + printf ("%d: cannot add characters at the end\n", __LINE__); + result = 1; + goto out; + } + + /* Check the access time. */ + if (fstat64 (fd, &st1) < 0) + { + printf ("%d: fstat64() before fseeko() failed\n\n", __LINE__); + result = 1; + } + else + { + sleep (1); + + if (fseek (fp, -(2 + 2 * (sizeof (outstr) - 1)), SEEK_CUR) != 0) + { + printf ("%d: fseek() after write characters failed\n", __LINE__); + result = 1; + goto out; + } + else + { + + time_t t; + /* Make sure the timestamp actually can be different. */ + sleep (1); + t = time (NULL); + + if (fstat64 (fd, &st2) < 0) + { + printf ("%d: fstat64() after fseeko() failed\n\n", __LINE__); + result = 1; + } + if (st1.st_ctime >= t) + { + printf ("%d: st_ctime not updated\n", __LINE__); + result = 1; + } + if (st1.st_mtime >= t) + { + printf ("%d: st_mtime not updated\n", __LINE__); + result = 1; + } + if (st1.st_ctime >= st2.st_ctime) + { + printf ("%d: st_ctime not changed\n", __LINE__); + result = 1; + } + if (st1.st_mtime >= st2.st_mtime) + { + printf ("%d: st_mtime not changed\n", __LINE__); + result = 1; + } + } + } + + if (fread (buf, 1, 2 + 2 * (sizeof (outstr) - 1), fp) + != 2 + 2 * (sizeof (outstr) - 1)) + { + printf ("%d: reading 2 records plus bits failed\n", __LINE__); + result = 1; + } + else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0 + || memcmp (&buf[sizeof (outstr) - 1], outstr, + sizeof (outstr) - 1) != 0 + || buf[2 * (sizeof (outstr) - 1)] != '1' + || buf[2 * (sizeof (outstr) - 1) + 1] != '2') + { + printf ("%d: reading records failed\n", __LINE__); + result = 1; + } + else if (ungetc ('9', fp) == EOF) + { + printf ("%d: ungetc() failed\n", __LINE__); + result = 1; + } + else if (fseek (fp, -(2 + 2 * (sizeof (outstr) - 1)), SEEK_END) != 0) + { + printf ("%d: fseek after ungetc failed\n", __LINE__); + result = 1; + } + else if (fread (buf, 1, 2 + 2 * (sizeof (outstr) - 1), fp) + != 2 + 2 * (sizeof (outstr) - 1)) + { + printf ("%d: reading 2 records plus bits failed\n", __LINE__); + result = 1; + } + else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0 + || memcmp (&buf[sizeof (outstr) - 1], outstr, + sizeof (outstr) - 1) != 0 + || buf[2 * (sizeof (outstr) - 1)] != '1') + { + printf ("%d: reading records for the second time failed\n", __LINE__); + result = 1; + } + else if (buf[2 * (sizeof (outstr) - 1) + 1] == '9') + { + printf ("%d: unget character not ignored\n", __LINE__); + result = 1; + } + else if (buf[2 * (sizeof (outstr) - 1) + 1] != '2') + { + printf ("%d: unget somehow changed character\n", __LINE__); + result = 1; + } + + fclose (fp); + + fp = fopen (fname, "r"); + if (fp == NULL) + { + printf ("%d: fopen() failed\n\n", __LINE__); + result = 1; + } + else if (fstat64 (fileno (fp), &st1) < 0) + { + printf ("%d: fstat64() before fseeko() failed\n\n", __LINE__); + result = 1; + } + else if (fseeko (fp, 0, SEEK_END) != 0) + { + printf ("%d: fseeko(fp, 0, SEEK_END) failed\n", __LINE__); + result = 1; + } + else if (ftello (fp) != st1.st_size) + { + printf ("%d: fstat64 st_size %zd ftello %zd\n", __LINE__, + (size_t) st1.st_size, (size_t) ftello (fp)); + result = 1; + } + else + printf ("%d: SEEK_END works\n", __LINE__); + if (fp != NULL) + fclose (fp); + + fp = fopen (fname, "r"); + if (fp == NULL) + { + printf ("%d: fopen() failed\n\n", __LINE__); + result = 1; + } + else if (fstat64 (fileno (fp), &st1) < 0) + { + printf ("%d: fstat64() before fgetc() failed\n\n", __LINE__); + result = 1; + } + else if (fgetc (fp) == EOF) + { + printf ("%d: fgetc() before fseeko() failed\n\n", __LINE__); + result = 1; + } + else if (fseeko (fp, 0, SEEK_END) != 0) + { + printf ("%d: fseeko(fp, 0, SEEK_END) failed\n", __LINE__); + result = 1; + } + else if (ftello (fp) != st1.st_size) + { + printf ("%d: fstat64 st_size %zd ftello %zd\n", __LINE__, + (size_t) st1.st_size, (size_t) ftello (fp)); + result = 1; + } + else + printf ("%d: SEEK_END works\n", __LINE__); + if (fp != NULL) + fclose (fp); + + out: + unlink (fname); + + return result; +} diff -uNr dietlibc-0.24/test/stdio/tst-printf.c dietlibc-0.25/test/stdio/tst-printf.c --- dietlibc-0.24/test/stdio/tst-printf.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-printf.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,376 @@ +/* Copyright (C) 1991,92,93,95,96,97,98,99, 2000, 2002 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include + +#include + +static void rfg1 (void); +static void rfg2 (void); +static void rfg3 (void); + + +static void +fmtchk (const char *fmt) +{ + (void) fputs(fmt, stdout); + (void) printf(":\t`"); + (void) printf(fmt, 0x12); + (void) printf("'\n"); +} + +static void +fmtst1chk (const char *fmt) +{ + (void) fputs(fmt, stdout); + (void) printf(":\t`"); + (void) printf(fmt, 4, 0x12); + (void) printf("'\n"); +} + +static void +fmtst2chk (const char *fmt) +{ + (void) fputs(fmt, stdout); + (void) printf(":\t`"); + (void) printf(fmt, 4, 4, 0x12); + (void) printf("'\n"); +} + +/* This page is covered by the following copyright: */ + +/* (C) Copyright C E Chew + * + * Feel free to copy, use and distribute this software provided: + * + * 1. you do not pretend that you wrote it + * 2. you leave this copyright notice intact. + */ + +/* + * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans. + */ + +#define DEC -123 +#define INT 255 +#define UNS (~0) + +/* Formatted Output Test + * + * This exercises the output formatting code. + */ + +static void +fp_test (void) +{ + int i, j, k, l; + char buf[7]; + char *prefix = buf; + char tp[20]; + + puts("\nFormatted output test"); + printf("prefix 6d 6o 6x 6X 6u\n"); + strcpy(prefix, "%"); + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + for (k = 0; k < 2; k++) { + for (l = 0; l < 2; l++) { + strcpy(prefix, "%"); + if (i == 0) strcat(prefix, "-"); + if (j == 0) strcat(prefix, "+"); + if (k == 0) strcat(prefix, "#"); + if (l == 0) strcat(prefix, "0"); + printf("%5s |", prefix); + strcpy(tp, prefix); + strcat(tp, "6d |"); + printf(tp, DEC); + strcpy(tp, prefix); + strcat(tp, "6o |"); + printf(tp, INT); + strcpy(tp, prefix); + strcat(tp, "6x |"); + printf(tp, INT); + strcpy(tp, prefix); + strcat(tp, "6X |"); + printf(tp, INT); + strcpy(tp, prefix); + strcat(tp, "6u |"); + printf(tp, UNS); + printf("\n"); + } + } + } + } + printf("%10s\n", (char *) NULL); + printf("%-10s\n", (char *) NULL); +} + +int +main (int argc, char *argv[]) +{ + static char shortstr[] = "Hi, Z."; + static char longstr[] = "Good morning, Doctor Chandra. This is Hal. \ +I am ready for my first lesson today."; + int result = 0; + + fmtchk("%.4x"); + fmtchk("%04x"); + fmtchk("%4.4x"); + fmtchk("%04.4x"); + fmtchk("%4.3x"); + fmtchk("%04.3x"); + + fmtst1chk("%.*x"); + fmtst1chk("%0*x"); + fmtst2chk("%*.*x"); + fmtst2chk("%0*.*x"); + + printf("bad format:\t\"%b\"\n"); + printf("nil pointer (padded):\t\"%10p\"\n", (void *) NULL); + + printf("decimal negative:\t\"%d\"\n", -2345); + printf("octal negative:\t\"%o\"\n", -2345); + printf("hex negative:\t\"%x\"\n", -2345); + printf("long decimal number:\t\"%ld\"\n", -123456L); + printf("long octal negative:\t\"%lo\"\n", -2345L); + printf("long unsigned decimal number:\t\"%lu\"\n", -123456L); + printf("zero-padded LDN:\t\"%010ld\"\n", -123456L); + printf("left-adjusted ZLDN:\t\"%-010ld\"\n", -123456L); + printf("space-padded LDN:\t\"%10ld\"\n", -123456L); + printf("left-adjusted SLDN:\t\"%-10ld\"\n", -123456L); + + printf("zero-padded string:\t\"%010s\"\n", shortstr); + printf("left-adjusted Z string:\t\"%-010s\"\n", shortstr); + printf("space-padded string:\t\"%10s\"\n", shortstr); + printf("left-adjusted S string:\t\"%-10s\"\n", shortstr); + printf("null string:\t\"%s\"\n", (char *)NULL); + printf("limited string:\t\"%.22s\"\n", longstr); + + printf("e-style >= 1:\t\"%e\"\n", 12.34); + printf("e-style >= .1:\t\"%e\"\n", 0.1234); + printf("e-style < .1:\t\"%e\"\n", 0.001234); + printf("e-style big:\t\"%.60e\"\n", 1e20); + printf ("e-style == .1:\t\"%e\"\n", 0.1); + printf("f-style >= 1:\t\"%f\"\n", 12.34); + printf("f-style >= .1:\t\"%f\"\n", 0.1234); + printf("f-style < .1:\t\"%f\"\n", 0.001234); + printf("g-style >= 1:\t\"%g\"\n", 12.34); + printf("g-style >= .1:\t\"%g\"\n", 0.1234); + printf("g-style < .1:\t\"%g\"\n", 0.001234); + printf("g-style big:\t\"%.60g\"\n", 1e20); + + printf (" %6.5f\n", .099999999860301614); + printf (" %6.5f\n", .1); + printf ("x%5.4fx\n", .5); + + printf ("%#03x\n", 1); + + printf ("something really insane: %.10000f\n", 1.0); + + { + double d = FLT_MIN; + int niter = 17; + + while (niter-- != 0) + printf ("%.17e\n", d / 2); + fflush (stdout); + } + + printf ("%15.5e\n", 4.9406564584124654e-324); + +#define FORMAT "|%12.4f|%12.4e|%12.4g|\n" + printf (FORMAT, 0.0, 0.0, 0.0); + printf (FORMAT, 1.0, 1.0, 1.0); + printf (FORMAT, -1.0, -1.0, -1.0); + printf (FORMAT, 100.0, 100.0, 100.0); + printf (FORMAT, 1000.0, 1000.0, 1000.0); + printf (FORMAT, 10000.0, 10000.0, 10000.0); + printf (FORMAT, 12345.0, 12345.0, 12345.0); + printf (FORMAT, 100000.0, 100000.0, 100000.0); + printf (FORMAT, 123456.0, 123456.0, 123456.0); +#undef FORMAT + + { + char buf[20]; + char buf2[512]; + printf ("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n", + snprintf (buf, sizeof (buf), "%30s", "foo"), (int) sizeof (buf), + buf); + printf ("snprintf (\"%%.999999u\", 10) == %d\n", + snprintf(buf2, sizeof(buf2), "%.999999u", 10)); + } + + fp_test (); + + printf ("%e should be 1.234568e+06\n", 1234567.8); + printf ("%f should be 1234567.800000\n", 1234567.8); + printf ("%g should be 1.23457e+06\n", 1234567.8); + printf ("%g should be 123.456\n", 123.456); + printf ("%g should be 1e+06\n", 1000000.0); + printf ("%g should be 10\n", 10.0); + printf ("%g should be 0.02\n", 0.02); + +#if 0 + /* This test rather checks the way the compiler handles constant + folding. gcc behavior wrt to this changed in 3.2 so it is not a + portable test. */ + { + double x=1.0; + printf("%.17f\n",(1.0/x/10.0+1.0)*x-x); + } +#endif + + { + char buf[200]; + + sprintf(buf,"%*s%*s%*s",-1,"one",-20,"two",-30,"three"); + + result |= strcmp (buf, + "onetwo three "); + + puts (result != 0 ? "Test failed!" : "Test ok."); + } + + { + char buf[200]; + + sprintf (buf, "%07Lo", 040000000000ll); + printf ("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s", buf); + + if (strcmp (buf, "40000000000") != 0) + { + result = 1; + fputs ("\tFAILED", stdout); + } + puts (""); + } + + printf ("printf (\"%%hhu\", %u) = %hhu\n", UCHAR_MAX + 2, UCHAR_MAX + 2); + printf ("printf (\"%%hu\", %u) = %hu\n", USHRT_MAX + 2, USHRT_MAX + 2); + + puts ("--- Should be no further output. ---"); + rfg1 (); + rfg2 (); + rfg3 (); + + { + char bytes[7]; + char buf[20]; + + memset (bytes, '\xff', sizeof bytes); + sprintf (buf, "foo%hhn\n", &bytes[3]); + if (bytes[0] != '\xff' || bytes[1] != '\xff' || bytes[2] != '\xff' + || bytes[4] != '\xff' || bytes[5] != '\xff' || bytes[6] != '\xff') + { + puts ("%hhn overwrite more bytes"); + result = 1; + } + if (bytes[3] != 3) + { + puts ("%hhn wrote incorrect value"); + result = 1; + } + } + + return result != 0; +} + +static void +rfg1 (void) +{ + char buf[100]; + + sprintf (buf, "%5.s", "xyz"); + if (strcmp (buf, " ") != 0) + printf ("got: '%s', expected: '%s'\n", buf, " "); + sprintf (buf, "%5.f", 33.3); + if (strcmp (buf, " 33") != 0) + printf ("got: '%s', expected: '%s'\n", buf, " 33"); + sprintf (buf, "%8.e", 33.3e7); + if (strcmp (buf, " 3e+08") != 0) + printf ("got: '%s', expected: '%s'\n", buf, " 3e+08"); + sprintf (buf, "%8.E", 33.3e7); + if (strcmp (buf, " 3E+08") != 0) + printf ("got: '%s', expected: '%s'\n", buf, " 3E+08"); + sprintf (buf, "%.g", 33.3); + if (strcmp (buf, "3e+01") != 0) + printf ("got: '%s', expected: '%s'\n", buf, "3e+01"); + sprintf (buf, "%.G", 33.3); + if (strcmp (buf, "3E+01") != 0) + printf ("got: '%s', expected: '%s'\n", buf, "3E+01"); +} + +static void +rfg2 (void) +{ + int prec; + char buf[100]; + + prec = 0; + sprintf (buf, "%.*g", prec, 3.3); + if (strcmp (buf, "3") != 0) + printf ("got: '%s', expected: '%s'\n", buf, "3"); + prec = 0; + sprintf (buf, "%.*G", prec, 3.3); + if (strcmp (buf, "3") != 0) + printf ("got: '%s', expected: '%s'\n", buf, "3"); + prec = 0; + sprintf (buf, "%7.*G", prec, 3.33); + if (strcmp (buf, " 3") != 0) + printf ("got: '%s', expected: '%s'\n", buf, " 3"); + prec = 3; + sprintf (buf, "%04.*o", prec, 33); + if (strcmp (buf, " 041") != 0) + printf ("got: '%s', expected: '%s'\n", buf, " 041"); + prec = 7; + sprintf (buf, "%09.*u", prec, 33); + if (strcmp (buf, " 0000033") != 0) + printf ("got: '%s', expected: '%s'\n", buf, " 0000033"); + prec = 3; + sprintf (buf, "%04.*x", prec, 33); + if (strcmp (buf, " 021") != 0) + printf ("got: '%s', expected: '%s'\n", buf, " 021"); + prec = 3; + sprintf (buf, "%04.*X", prec, 33); + if (strcmp (buf, " 021") != 0) + printf ("got: '%s', expected: '%s'\n", buf, " 021"); +} + +static void +rfg3 (void) +{ + char buf[100]; + double g = 5.0000001; + unsigned long l = 1234567890; + double d = 321.7654321; + const char s[] = "test-string"; + int i = 12345; + int h = 1234; + + sprintf (buf, + "%1$*5$d %2$*6$hi %3$*7$lo %4$*8$f %9$*12$e %10$*13$g %11$*14$s", + i, h, l, d, 8, 5, 14, 14, d, g, s, 14, 3, 14); + if (strcmp (buf, + " 12345 1234 11145401322 321.765432 3.217654e+02 5 test-string") != 0) + printf ("got: '%s', expected: '%s'\n", buf, + " 12345 1234 11145401322 321.765432 3.217654e+02 5 test-string"); +} diff -uNr dietlibc-0.24/test/stdio/tst-printfsz.c dietlibc-0.25/test/stdio/tst-printfsz.c --- dietlibc-0.24/test/stdio/tst-printfsz.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-printfsz.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,67 @@ +/* Based on code by Larry McVoy . */ +#include +#include +#include + +#define V 12345678.12345678 + + +int +main (int argc, char *argv[]) +{ + char buf[1024]; + int result = 0; + + /* Register the printf handlers. */ + register_printf_function ('b', printf_size, printf_size_info); + register_printf_function ('B', printf_size, printf_size_info); + + + sprintf (buf, "%g %b %B %.0b %.0B %.1b %.1B %8.0b %08.0B", + V, 1025., V, V, V, V, V, V, V, V); + fputs (buf, stdout); + if (strcmp (buf, "\ +1.23457e+07 1.001k 12.346M 12m 12M 11.8m 12.3M 12m 0000012M")) + { + result = 1; + fputs (" -> WRONG\n", stdout); + } + else + fputs (" -> OK\n", stdout); + + sprintf (buf, "%b|%B|%-20.2b|%-10.0b|%-10.8b|%-10.2B|", + V, V, V, V, V, V, V, V, V, V, V); + fputs (buf, stdout); + if (strcmp (buf, "\ +11.774m|12.346M|11.77m |12m |11.77375614m|12.35M |")) + { + result = 1; + fputs (" -> WRONG\n", stdout); + } + else + fputs (" -> OK\n", stdout); + + sprintf (buf, "%#.0B %*.0b %10.*b %*.*B %10.2B", + V, 2, V, 2, V, 10, 2, V, V); + fputs (buf, stdout); + if (strcmp (buf, "12.M 12m 11.77m 12.35M 12.35M")) + { + result = 1; + fputs (" -> WRONG\n", stdout); + } + else + fputs (" -> OK\n", stdout); + + sprintf (buf, "%6B %6.1B %b %B %b %B", + V, V, 1000.0, 1000.0, 1024.0, 1024.0); + fputs (buf, stdout); + if (strcmp (buf, "12.346M 12.3M 1000.000 1.000K 1.000k 1.024K")) + { + result = 1; + fputs (" -> WRONG\n", stdout); + } + else + fputs (" -> OK\n", stdout); + + return result; +} diff -uNr dietlibc-0.24/test/stdio/tst-sprintf.c dietlibc-0.25/test/stdio/tst-sprintf.c --- dietlibc-0.24/test/stdio/tst-sprintf.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-sprintf.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,19 @@ +#include +#include + + +int +main (void) +{ + char buf[100]; + int result = 0; + + if (sprintf (buf, "%.0ls", L"foo") != 0 + || strlen (buf) != 0) + { + puts ("sprintf (buf, \"%.0ls\", L\"foo\") produced some output\n"); + result = 1; + } + + return result; +} diff -uNr dietlibc-0.24/test/stdio/tst-sscanf.c dietlibc-0.25/test/stdio/tst-sscanf.c --- dietlibc-0.24/test/stdio/tst-sscanf.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-sscanf.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,123 @@ +/* Copyright (C) 2000, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek , 2000. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +const char *str_double[] = +{ + "-.10000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01", + "0.10000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01", + "-1234567E0198765432E0912345678901987654321091234567890198765432109", + "-0.1000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01" +}; + +const double val_double[] = +{ + -.10000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01, + 0.10000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01, + -1234567E01, 98765432E09, 12345678901.0, 98765432109.0, 12345678901.0, + 98765432109.0, + -0.1000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01 +}; + +const char *str_long[] = +{ + "-12345678987654321123456789987654321123456789987654321", + "-12345678987654321123456789987654321123456789987654321", + "-12,345,678987,654,321123,456,789987,654,321123,456,789987,654,321", + "-12,345,678987,654,321123,456,789987,654,321123,456,789987,654,321" +}; + +const char *fmt_long[] = +{ + "%9ld%9ld%9ld%9ld%9ld%9ld", + "%I9ld%I9ld%I9ld%I9ld%I9ld%I9ld", + "%'11ld%'11ld%'11ld%'11ld%'11ld%'11ld", + "%I'11ld%I'11ld%I'11ld%I'11ld%I'11ld%I'11ld" +}; + +const long int val_long[] = +{ + -12345678, 987654321, 123456789, 987654321, 123456789, 987654321 +}; + +int +main (void) +{ + double d[6]; + long l[6]; + int i, j; + int tst_locale; + int result = 0; + + tst_locale = 1; + if (tst_locale) + if (setlocale (LC_ALL, "en_US.ISO-8859-1") == NULL) + { + puts ("Failed to set en_US locale, skipping locale related tests"); + tst_locale = 0; + } + + for (i = 0; i < 4; ++i) + { + if (sscanf (str_double[i], "%11lf%11lf%11lf%11lf%11lf%11lf", + &d[0], &d[1], &d[2], &d[3], &d[4], &d[5]) != 6) + { + printf ("Double sscanf test %d wrong number of " + "assigned inputs\n", i); + result = 1; + } + else + for (j = 0; j < 6; ++j) + if (d[j] != val_double[6 * i + j]) + { + printf ("Double sscanf test %d failed (%g instead of %g)\n", + i, d[j], val_double[6 * i + j]); + result = 1; + break; + } + } + + for (i = 0; i < 4; ++i) + { + if (sscanf (str_long[i], fmt_long[i], + &l[0], &l[1], &l[2], &l[3], &l[4], &l[5]) != 6) + { + printf ("Integer sscanf test %d wrong number of " + "assigned inputs\n", i); + result = 1; + } + else + for (j = 0; j < 6; ++j) + if (l[j] != val_long[j]) + { + printf ("Integer sscanf test %d failed (%ld instead %ld)\n", + i, l[j], val_long[j]); + result = 1; + break; + } + + if (! tst_locale) + break; + } + + return result; +} diff -uNr dietlibc-0.24/test/stdio/tst-tmpnam.c dietlibc-0.25/test/stdio/tst-tmpnam.c --- dietlibc-0.24/test/stdio/tst-tmpnam.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-tmpnam.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,51 @@ +/* Copyright (C) 1998 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +int +main (void) +{ + const char *name; + int retval = 0; + + /* Set TMPDIR to a value other than the traditional /tmp. */ + setenv ("TMPDIR", "/usr", 1); + + name = tmpnam (NULL); + + printf ("name = %s\n", name); + + /* Make sure the name is not based on the value in TMPDIR. */ + if (strncmp (name, "/usr", 4) == 0) + { + puts ("error: `tmpnam' used TMPDIR value"); + retval = 1; + } + + /* Test that it is in the directory denoted by P_tmpdir. */ + if (strncmp (name, P_tmpdir, sizeof (P_tmpdir) - 1) != 0) + { + puts ("error: `tmpnam' return value not in P_tmpdir directory"); + retval = 1; + } + + return retval; +} diff -uNr dietlibc-0.24/test/stdio/tst-unbputc.c dietlibc-0.25/test/stdio/tst-unbputc.c --- dietlibc-0.24/test/stdio/tst-unbputc.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-unbputc.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,11 @@ +#include + + +int +main (void) +{ + putc ('1', stderr); + putc ('2', stderr); + + return 0; +} diff -uNr dietlibc-0.24/test/stdio/tst-ungetc.c dietlibc-0.25/test/stdio/tst-ungetc.c --- dietlibc-0.24/test/stdio/tst-ungetc.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tst-ungetc.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,63 @@ +/* Test for ungetc bugs. */ + +#include +#include + +#undef assert +#define assert(x) \ + if (!(x)) \ + { \ + fputs ("test failed: " #x "\n", stderr); \ + retval = 1; \ + goto the_end; \ + } + +int +main (int argc, char *argv[]) +{ + char *name; + FILE *fp = NULL; + int retval = 0; + int c; + char buffer[64]; + + name = tmpnam (NULL); + fp = fopen (name, "w"); + assert (fp != NULL) + fputs ("bla", fp); + fclose (fp); + fp = NULL; + + fp = fopen (name, "r"); + assert (fp != NULL); + assert (ungetc ('z', fp) == 'z'); + assert (getc (fp) == 'z'); + assert (getc (fp) == 'b'); + assert (getc (fp) == 'l'); + assert (ungetc ('m', fp) == 'm'); + assert (getc (fp) == 'm'); + assert ((c = getc (fp)) == 'a'); + assert (getc (fp) == EOF); + assert (ungetc (c, fp) == c); + assert (feof (fp) == 0); + assert (getc (fp) == c); + assert (getc (fp) == EOF); + fclose (fp); + fp = NULL; + + fp = fopen (name, "r"); + assert (fp != NULL); + assert (getc (fp) == 'b'); + assert (getc (fp) == 'l'); + assert (ungetc ('b', fp) == 'b'); + assert (fread (buffer, 1, 64, fp) == 2); + assert (buffer[0] == 'b'); + assert (buffer[1] == 'a'); + +the_end: + if (fp != NULL) + fclose (fp); + unlink (name); + + return retval; +} diff -uNr dietlibc-0.24/test/stdio/tstdiomisc.c dietlibc-0.25/test/stdio/tstdiomisc.c --- dietlibc-0.24/test/stdio/tstdiomisc.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tstdiomisc.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,91 @@ +#include +#include +#include +#include + +static int +t1 (void) +{ + int n = -1; + sscanf ("abc ", "abc %n", &n); + printf ("t1: count=%d\n", n); + + return n != 5; +} + +static int +t2 (void) +{ + int result = 0; + int n; + long N; + int retval; +#define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \ + VAR = -1; \ + retval = sscanf (INPUT, FORMAT, &VAR); \ + printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \ + INPUT, FORMAT, retval, (long int) VAR); \ + result |= retval != EXP_RES || VAR != EXP_VAL + + SCAN ("12345", "%ld", N, 1, 12345); + SCAN ("12345", "%llllld", N, 0, -1); + SCAN ("12345", "%LLLLLd", N, 0, -1); + SCAN ("test ", "%*s%n", n, 0, 4); + SCAN ("test ", "%2*s%n", n, 0, -1); + SCAN ("12 ", "%l2d", n, 0, -1); + SCAN ("12 ", "%2ld", N, 1, 12); + + n = -1; + N = -1; + retval = sscanf ("1 1", "%d %Z", &n, &N); + printf ("sscanf (\"1 1\", \"%%d %%Z\", &n, &N) => %d, n = %d, N = %ld\n", \ + retval, n, N); \ + result |= retval != 1 || n != 1 || N != -1; + + return result; +} + +static int +F (void) +{ + char buf[20]; + wchar_t wbuf[10]; + int result; + + snprintf (buf, sizeof buf, "%f %F", DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX, + DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX); + result = strcmp (buf, "nan NAN") != 0; + printf ("expected \"nan NAN\", got \"%s\"\n", buf); + + snprintf (buf, sizeof buf, "%f %F", DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX); + result |= strcmp (buf, "inf INF") != 0; + printf ("expected \"inf INF\", got \"%s\"\n", buf); + + /* swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F", + DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX, + DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX); + result |= wcscmp (wbuf, L"nan NAN") != 0; + printf ("expected L\"nan NAN\", got L\"%S\"\n", wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F", + DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX); + result |= wcscmp (wbuf, L"inf INF") != 0; + printf ("expected L\"inf INF\", got L\"%S\"\n", wbuf); + + */ + return result; +} + +int +main (int argc, char *argv[]) +{ + int result = 0; + + result |= t1 (); + result |= t2 (); + result |= F (); + + result |= fflush (stdout) == EOF; + + return result; +} diff -uNr dietlibc-0.24/test/stdio/tstgetln.c dietlibc-0.25/test/stdio/tstgetln.c --- dietlibc-0.24/test/stdio/tstgetln.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tstgetln.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,46 @@ +/* Copyright (C) 1992, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#define _GNU_SOURCE +#include +#include + +int main (int argc, char *argv[]) +{ + char *buf = NULL; + size_t size = 0; + ssize_t len; + + while ((len = getline (&buf, &size, stdin)) != -1) + { + printf ("bufsize %Zu; read %Zd: ", size, len); + if (fwrite (buf, len, 1, stdout) != 1) + { + perror ("fwrite"); + return 1; + } + } + + if (ferror (stdin)) + { + perror ("getline"); + return 1; + } + + return 0; +} diff -uNr dietlibc-0.24/test/stdio/tstscanf.c dietlibc-0.25/test/stdio/tstscanf.c --- dietlibc-0.24/test/stdio/tstscanf.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdio/tstscanf.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,356 @@ +/* Copyright (C) 1991,92,96,97,98,99,2000,2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifdef BSD +#include +#else +#include +#endif +#include +#include +#include + + +int +main (int argc, char **argv) +{ + char buf[BUFSIZ]; + FILE *in = stdin, *out = stdout; + int x; + int result = 0; + + if (sscanf ("0", "%d", &x) != 1) + { + fputs ("test failed!\n", stdout); + result = 1; + } + + if (sscanf ("08905x", "%9[0-9]", buf) != 1 + || strcmp (buf, "08905") != 0) + { + fputs ("test failed!\n", stdout); + result = 1; + } + + if (sscanf ("", "%10[a-z]", buf) != EOF) + { + fputs ("test failed!\n", stdout); + result = 1; + } + + sscanf ("conversion] Zero flag Ze]ro#\n", "%*[^]] %[^#]\n", buf); + if (strcmp (buf, "] Zero flag Ze]ro") != 0) + { + fputs ("test failed!\n", stdout); + result = 1; + } + + if (argc == 2 && !strcmp (argv[1], "-opipe")) + { + out = popen ("/bin/cat", "w"); + if (out == NULL) + { + perror ("popen: /bin/cat"); + result = 1; + } + } + else if (argc == 3 && !strcmp (argv[1], "-ipipe")) + { + sprintf (buf, "/bin/cat %s", argv[2]); + in = popen (buf, "r"); + if (in == NULL) + { + perror ("popen: /bin/cat"); + result = 1; + } + } + + { + char name[50]; + fprintf (out, + "sscanf (\"thompson\", \"%%s\", name) == %d, name == \"%s\"\n", + sscanf ("thompson", "%s", name), + name); + if (strcmp (name, "thompson") != 0) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + fputs ("Testing scanf (vfscanf)\n", out); + + fputs ("Test 1:\n", out); + { + int n, i; + float x; + char name[50]; + n = fscanf (in, "%d%f%s", &i, &x, name); + fprintf (out, "n = %d, i = %d, x = %f, name = \"%.50s\"\n", + n, i, x, name); + if (n != 3 || i != 25 || x != 5.432F || strcmp (name, "thompson")) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + fprintf (out, "Residual: \"%s\"\n", fgets (buf, sizeof (buf), in)); + if (strcmp (buf, "\n")) + { + fputs ("test failed!\n", stdout); + result = 1; + } + fputs ("Test 2:\n", out); + { + int i; + float x; + char name[50]; + (void) fscanf (in, "%2d%f%*d %[0123456789]", &i, &x, name); + fprintf (out, "i = %d, x = %f, name = \"%.50s\"\n", i, x, name); + if (i != 56 || x != 789.0F || strcmp (name, "56")) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + fprintf (out, "Residual: \"%s\"\n", fgets (buf, sizeof (buf), in)); + if (strcmp (buf, "a72\n")) + { + fputs ("test failed!\n", stdout); + result = 1; + } + fputs ("Test 3:\n", out); + { + static struct { + int count; + float quant; + const char *units; + const char *item; + } ok[] = { + { 3, 2.0F, "quarts", "oil" }, + { 2, -12.8F, "degrees", "" }, + { 0, 0.0F, "", "" }, + { 3, 10.0F, "LBS", "fertilizer" }, + { 3, 100.0F, "rgs", "energy" }, + { -1, 0.0F, "", "" }}; + size_t rounds = 0; + float quant; + char units[21], item[21]; + while (!feof (in) && !ferror (in)) + { + int count; + + if (rounds++ >= sizeof (ok) / sizeof (ok[0])) + { + fputs ("test failed!\n", stdout); + result = 1; + } + + quant = 0.0; + units[0] = item[0] = '\0'; + count = fscanf (in, "%f%20s of %20s", &quant, units, item); + (void) fscanf (in, "%*[^\n]"); + fprintf (out, "count = %d, quant = %f, item = %.21s, units = %.21s\n", + count, quant, item, units); + if (count != ok[rounds-1].count || quant != ok[rounds-1].quant + || strcmp (item, ok[rounds-1].item) + || strcmp (units, ok[rounds-1].units)) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + } + buf[0] = '\0'; + fprintf (out, "Residual: \"%s\"\n", fgets (buf, sizeof (buf), in)); + if (strcmp (buf, "")) + { + fputs ("test failed!\n", stdout); + result = 1; + } + + if (out != stdout) + pclose (out); + + fputs ("Test 4:\n", out); + { + int res, val, n; + + res = sscanf ("-242", "%3o%n", &val, &n); + printf ("res = %d, val = %d, n = %d\n", res, val, n); + if (res != 1 || val != -20 || n != 3) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + fputs ("Test 5:\n", out); + { + double a = 0, b = 0; + int res, n; + + res = sscanf ("1234567", "%3lg%3lg%n", &a, &b, &n); + printf ("res = %d, a = %g, b = %g, n = %d\n", res, a, b, n); + + if (res != 2 || a != 123 || b != 456 || n != 6) + { + fputs ("test failed!\n", stdout); + result = 1; + } + + res = sscanf ("0", "%lg", &a); + printf ("res = %d, a = %g\n", res, a); + + if (res != 1 || a != 0) + { + fputs ("test failed!\n", stdout); + result = 1; + } + + res = sscanf ("1e3", "%lg%n", &a, &n); + printf ("res = %d, a = %g, n = %d\n", res, a, n); + + if (res != 1 || a != 1000 || n != 3) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + fputs ("Test 6:\n", stdout); + { + char *p = (char *) -1; + int res; + + sprintf (buf, "%p", NULL); + res = sscanf (buf, "%p", &p); + printf ("sscanf (\"%s\", \"%%p\", &p) = %d, p == %p\n", buf, res, p); + + if (res != 1 || p != NULL) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + fputs ("Test 7:\n", stdout); + { + short a[2] = { -1, -1 }; + int res; + + res = sscanf ("32767 1234", "%hd %hd", &a[0], &a[1]); + printf ("res = %d, a[0] = %d, a[1] = %d\n", res, a[0], a[1]); + + if (res != 2 || a[0] != 32767 || a[1] != 1234) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + fputs ("Test 8:\n", stdout); + { + double d = 123456.789; + int res; + + res = sscanf ("0x1234", "%lf", &d); + printf ("res = %d, d = %f\n", res, d); + + if (res != 0 || d != 123456.789) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + fputs ("Test 9:\n", stdout); + { + /* From PR libc/1313 reported by Ben Caradoc-Davies . */ + float value; + int res; + + res = sscanf ("0123", "%2f", &value); + if (res != 1 || value != 1.0) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + fputs ("Test 10:\n", stdout); + { + float value; + int res; + + res = sscanf ("--", "%f", &value); + if (res != 0) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + fputs ("Test 11:\n", stdout); + { + char uart[50]; + int res; + + res = sscanf ("uart:16550A tx:0", "uart:%31s tx:%*u", uart); + if (res != 1) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + fputs ("Test 12:\n", stdout); + { + char uart[50]; + int res; + + res = sscanf ("uart:16550A", "uart:%31s tx:%*u", uart); + if (res != 1) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + fputs ("Test 13:\n", stdout); + { + float value; + int res; + + res = sscanf ("-InF", "%f", &value); + if (res != 1 || isinf (value) != -1) + { + fputs ("test failed!\n", stdout); + result = 1; + } + + res = sscanf ("+InfiNiTY", "%f", &value); + if (res != 1 || isinf (value) != 1) + { + fputs ("test failed!\n", stdout); + result = 1; + } + } + + return result; +} diff -uNr dietlibc-0.24/test/stdlib/Makefile dietlibc-0.25/test/stdlib/Makefile --- dietlibc-0.24/test/stdlib/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/Makefile 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,18 @@ +DIET=diet +CC=gcc + +CFLAGS=-Wall -nostdinc + +all: stdlibtest + +TESTPROGRAMS=test-canon testdiv testrand testsort tst-calloc \ +tst-environ tst-limits tst-malloc tst-rand48 tst-strtod tst-strtol \ +tst-strtoll tst-system + +stdlibtest: $(TESTPROGRAMS) +%: %.c + $(DIET) $(CC) $(CFLAGS) $^ -o $@ + +clean: + rm -f $(TESTPROGRAMS) + diff -uNr dietlibc-0.24/test/stdlib/runtests.sh dietlibc-0.25/test/stdlib/runtests.sh --- dietlibc-0.24/test/stdlib/runtests.sh 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/runtests.sh 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,10 @@ +#!/bin/sh + +TESTPROGRAMS="test-canon testrand testsort tst-calloc tst-environ tst-limits tst-malloc tst-rand48 tst-strtod tst-strtol tst-strtoll tst-system" + +for p in $TESTPROGRAMS; do +echo "---";echo testing $p;echo "---" + ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 ) + done + +echo "12 165 12 10000 10 123 546 752 12 87 98 347 3186 482 92 3941 7563 865 85371 547 28" ./testdiv diff -uNr dietlibc-0.24/test/stdlib/test-canon.c dietlibc-0.25/test/stdlib/test-canon.c --- dietlibc-0.24/test/stdlib/test-canon.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/test-canon.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,285 @@ +/* Test program for returning the canonical absolute name of a given file. + Copyright (C) 1996, 1997, 2000, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Mosberger . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This file must be run from within a directory called "stdlib". */ + +#include +#include +#include +#include +#include +#include +#include + +#define myrealpath realpath +static char cwd[PATH_MAX]; +static size_t cwd_len; + +struct { + const char * name; + const char * value; +} symlinks[] = { + {"SYMLINK_LOOP", "SYMLINK_LOOP"}, + {"SYMLINK_1", "."}, + {"SYMLINK_2", "//////./../../etc"}, + {"SYMLINK_3", "SYMLINK_1"}, + {"SYMLINK_4", "SYMLINK_2"}, + {"SYMLINK_5", "doesNotExist"}, +}; + +struct { + const char * in, * out, *resolved; + int error; +} tests[] = { + /* 0 */ + {"/", "/", "", 0}, + {"/////////////////////////////////", "/", "" ,0}, + {"/.././.././.././..///", "/", "",0}, + {"/etc", "/etc", "",0}, + {"/etc/../etc", "/etc", "",0}, + /* 5 */ + {"/doesNotExist/../etc", 0, "/doesNotExist", ENOENT}, + {"./././././././././.", ".", "",0}, + {"/etc/.//doesNotExist", 0, "/etc/doesNotExist", ENOENT}, + {"./doesExist", "./doesExist", "",0}, + {"./doesExist/", "./doesExist", "",0}, + /* 10 */ + {"./doesExist/../doesExist", "./doesExist","",0}, + {"foobar", 0, "./foobar", ENOENT}, + {".", ".","",0}, + {"./foobar", 0, "./foobar", ENOENT}, + {"SYMLINK_LOOP", 0, "./SYMLINK_LOOP", ELOOP}, + /* 15 */ + {"./SYMLINK_LOOP", 0, "./SYMLINK_LOOP", ELOOP}, + {"SYMLINK_1", ".","",0}, + {"SYMLINK_1/foobar", 0, "./foobar", ENOENT}, + {"SYMLINK_2", "/etc","",0}, + {"SYMLINK_3", ".","",0}, + /* 20 */ + {"SYMLINK_4", "/etc","",0}, + {"../stdlib/SYMLINK_1", ".","",0}, + {"../stdlib/SYMLINK_2", "/etc","",0}, + {"../stdlib/SYMLINK_3", ".","",0}, + {"../stdlib/SYMLINK_4", "/etc","",0}, + /* 25 */ + {"./SYMLINK_5", 0, "./doesNotExist", ENOENT}, + {"SYMLINK_5", 0, "./doesNotExist", ENOENT}, + {"SYMLINK_5/foobar", 0, "./doesNotExist", ENOENT}, + {"doesExist/../../stdlib/doesExist", "./doesExist","",0}, + {"doesExist/.././../stdlib/.", ".","",0} +}; + + +static int +check_path (const char * result, const char * expected) +{ + int good; + + if (!result) + return (expected == NULL); + + if (!expected) + return 0; + + if (expected[0] == '.' && (expected[1] == '/' || expected[1] == '\0')) + good = (strncmp (result, cwd, cwd_len) == 0 + && strcmp (result + cwd_len, expected + 1) == 0); + else + good = (strcmp (expected, result) == 0); + + return good; +} + + +int +main (int argc, char ** argv) +{ + char * result; + int fd, i, errors = 0; + char buf[PATH_MAX]; + + getcwd (cwd, sizeof(buf)); + cwd_len = strlen (cwd); + +/* this segfaults with dietlibc +man page documents: + EINVAL Either path or resolved_path is NULL. (In libc5 this would just + cause a segfault.) + errno = 0; + if (myrealpath (NULL, buf) != NULL || errno != EINVAL) + { + printf ("%s: expected return value NULL and errno set to EINVAL" + " for myrealpath(NULL,...)\n", argv[0]); + ++errors; + } +*/ + +/* according to glibc, this test is invalid + errno = 0; + if (myrealpath ("/", NULL) != NULL || errno != EINVAL) + { + printf ("%s: expected return value NULL and errno set to EINVAL" + " for myrealpath(...,NULL)\n", argv[0]); + ++errors; + } +*/ + + errno = 0; + if (myrealpath ("", buf) != NULL || errno != ENOENT) + { + printf ("%s: expected return value NULL and set errno to ENOENT" + " for myrealpath(\"\",...)\n", argv[0]); + ++errors; + } + + for (i = 0; i < (int) (sizeof (symlinks) / sizeof (symlinks[0])); ++i) + symlink (symlinks[i].value, symlinks[i].name); + + fd = open("doesExist", O_CREAT | O_EXCL, 0777); + + for (i = 0; i < (int) (sizeof (tests) / sizeof (tests[0])); ++i) + { + buf[0] = '\0'; + result = myrealpath (tests[i].in, buf); + + if (!check_path (result, tests[i].out)) + { + printf ("%s: flunked test %d (expected `%s', got `%s')\n", + argv[0], i, tests[i].out ? tests[i].out : "NULL", + result ? result : "NULL"); + ++errors; + continue; + } + + if (!check_path (buf, tests[i].out ? tests[i].out : tests[i].resolved)) + { + printf ("%s: flunked test %d (expected resolved `%s', got `%s')\n", + argv[0], i, tests[i].out ? tests[i].out : tests[i].resolved, + buf); + ++errors; + continue; + } + + if (!tests[i].out && errno != tests[i].error) + { + printf ("%s: flunked test %d (expected errno %d, got %d)\n", + argv[0], i, tests[i].error, errno); + ++errors; + continue; + } + } + + getcwd (buf, sizeof(buf)); + if (strcmp (buf, cwd)) + { + printf ("%s: current working directory changed from %s to %s\n", + argv[0], cwd, buf); + ++errors; + } + + if (fd >= 0) + unlink("doesExist"); + + for (i = 0; i < (int) (sizeof (symlinks) / sizeof (symlinks[0])); ++i) + unlink (symlinks[i].name); + + if (errors != 0) + { + printf ("%d errors.\n", errors); + return EXIT_FAILURE; + } + + puts ("No errors."); + return EXIT_SUCCESS; +} + +#if 0 +static char *sep(char *path) +{ + char *tmp, c; + + tmp = strrchr(path, '/'); + if(tmp) { + c = tmp[1]; + tmp[1] = 0; + if (chdir(path)) { + return NULL; + } + tmp[1] = c; + + return tmp + 1; + } + + return path; + +} + +char *myrealpath(const char *_path, char *resolved_path) +{ + int fd = open(".", O_RDONLY), l; + char path[PATH_MAX], lnk[PATH_MAX], *tmp = (char *)""; + + if (fd < 0) { + return NULL; + } + strncpy(path, _path, PATH_MAX); + + if (chdir(path)) { + if (errno == ENOTDIR) { + l = readlink(path, lnk, PATH_MAX); + if (!(tmp = sep(path))) { + resolved_path = NULL; + goto abort; + } + if (l < 0) { + perror("readlink"); + if (errno != EINVAL || errno !=ENOENT) { + resolved_path = NULL; + goto abort; + } + } else { + lnk[l] = 0; + if (!(tmp = sep(lnk))) { + resolved_path = NULL; + goto abort; + } + } + } else { + perror("chdir()"); + resolved_path = NULL; + goto abort; + } + } + if (!getcwd(resolved_path, PATH_MAX)) { + resolved_path = NULL; + goto abort; + } + + if(strcmp(resolved_path, "/") && *tmp) { + strcat(resolved_path, "/"); + } + + strcat(resolved_path, tmp); + abort: + fchdir(fd); + close(fd); + return resolved_path; +} +#endif diff -uNr dietlibc-0.24/test/stdlib/testdiv.c dietlibc-0.25/test/stdlib/testdiv.c --- dietlibc-0.24/test/stdlib/testdiv.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/testdiv.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,40 @@ +/* Copyright (C) 1992, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + +int +main (void) +{ + int err = 0; + int i, j; + while (scanf ("%d %d\n", &i, &j) == 2) + { + div_t d = div (i, j); + printf ("%d / %d = %d + %d/%d", i, j, d.quot, d.rem, j); + if (i == d.quot * j + d.rem) + fputs (" OK\n", stdout); + else + { + fputs (" FAILED\n", stdout); + err = 1; + } + } + return err; +} diff -uNr dietlibc-0.24/test/stdlib/testrand.c dietlibc-0.25/test/stdlib/testrand.c --- dietlibc-0.24/test/stdlib/testrand.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/testrand.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,53 @@ +/* Copyright (C) 1992, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + +int +main (void) +{ + int i1, i2; + int j1, j2; + + /* The C standard says that "If rand is called before any calls to + srand have been made, the same sequence shall be generated as + when srand is first called with a seed value of 1." */ + i1 = rand(); + i2 = rand(); + srand (1); + j1 = rand(); + j2 = rand(); + if (i1 < 0 || i2 < 0 || j1 < 0 || j2 < 0) { + puts ("Test FAILED!"); + } + if (j1 == i1 && j2 == i2) + { + puts ("Test succeeded."); + return 0; + } + else + { + if (j1 != i1) + printf ("%d != %d\n", j1, i1); + if (j2 != i2) + printf ("%d != %d\n", j2, i2); + puts ("Test FAILED!"); + return 1; + } +} diff -uNr dietlibc-0.24/test/stdlib/testsort.c dietlibc-0.25/test/stdlib/testsort.c --- dietlibc-0.24/test/stdlib/testsort.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/testsort.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,36 @@ +#include +#include +#include + +static int +compare (const void *a, const void *b) +{ + return strcmp (*(char **) a, *(char **) b); +} + +int +main (void) +{ + char bufs[500][20]; + char *lines[500]; + size_t lens[500]; + size_t i, j; + + srandom (1); + + for (i = 0; i < 500; ++i) + { + lens[i] = random() % 19; + lines[i] = bufs[i]; + for (j = 0; j < lens[i]; ++j) + lines[i][j] = random() % 26 + 'a'; + lines[i][j] = '\0'; + } + + qsort (lines, 500, sizeof (char *), compare); + + for (i = 0; i < 500 && lines[i] != NULL; ++i) + puts (lines[i]); + + return 0; +} diff -uNr dietlibc-0.24/test/stdlib/tst-calloc.c dietlibc-0.25/test/stdlib/tst-calloc.c --- dietlibc-0.24/test/stdlib/tst-calloc.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/tst-calloc.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,127 @@ +/* Copyright (C) 2000, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include + + +/* Number of samples per size. */ +#define N 50000 + + +static void +fixed_test (int size) +{ + char *ptrs[N]; + int i; + + for (i = 0; i < N; ++i) + { + int j; + + ptrs[i] = (char *) calloc (1, size); + + if (ptrs[i] == NULL) + break; + + for (j = 0; j < size; ++j) + { + if (ptrs[i][j] != '\0') { + fprintf(stderr, "byte not cleared (size %d, element %d, byte %d)", + size, i, j); + exit(1); + } + ptrs[i][j] = '\xff'; + } + } + + while (i-- > 0) + free (ptrs[i]); +} + + +static void +random_test (void) +{ + char *ptrs[N]; + int i; + + for (i = 0; i < N; ++i) + { + int j; + int n = 1 + random () % 10; + int elem = 1 + random () % 100; + int size = n * elem; + + ptrs[i] = (char *) calloc (n, elem); + + if (ptrs[i] == NULL) + break; + + for (j = 0; j < size; ++j) + { + if (ptrs[i][j] != '\0') { + fprintf (stderr, "byte not cleared (size %d, element %d, byte %d)", + size, i, j); + exit(1); + } + ptrs[i][j] = '\xff'; + } + } + + while (i-- > 0) + free (ptrs[i]); +} + + +static void +null_test (void) +{ + /* If the size is 0 the result is implementation defined. Just make + sure the program doesn't crash. */ + calloc (0, 0); + calloc (0, UINT_MAX); + calloc (UINT_MAX, 0); + calloc (0, ~((size_t) 0)); + calloc (~((size_t) 0), 0); +} + + +int +main (void) +{ + /* We are allocating blocks with `calloc' and check whether every + block is completely cleared. We first try this for some fixed + times and then with random size. */ + fixed_test (15); + fixed_test (5); + fixed_test (17); + fixed_test (6); + fixed_test (31); + fixed_test (96); + + random_test (); + + null_test (); + + return 0; +} diff -uNr dietlibc-0.24/test/stdlib/tst-environ.c dietlibc-0.25/test/stdlib/tst-environ.c --- dietlibc-0.24/test/stdlib/tst-environ.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/tst-environ.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,177 @@ +/* Copyright (C) 1999 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + + +#define VAR "FOOBAR" + +char putenv_val[100] = VAR "=some longer value"; + +int +main (void) +{ + int result = 0; + const char *valp; + + /* First test: remove entry FOOBAR, whether it exists or not. */ + unsetenv (VAR); + + /* Now getting the value should fail. */ + if (getenv (VAR) != NULL) + { + printf ("There should be no `%s' value\n", VAR); + result = 1; + } + + /* Now add a value, with the replace flag cleared. */ + if (setenv (VAR, "one", 0) != 0) + { + printf ("setenv #1 failed: %m\n"); + result = 1; + } + + /* Getting this value should now be possible. */ + valp = getenv (VAR); + if (valp == NULL || strcmp (valp, "one") != 0) + { + puts ("getenv #2 failed"); + result = 1; + } + + /* Try to replace without the replace flag set. This should fail. */ + if (setenv (VAR, "two", 0) != 0) + { + printf ("setenv #2 failed: %m\n"); + result = 1; + } + + /* The value shouldn't have changed. */ + valp = getenv (VAR); + if (valp == NULL || strcmp (valp, "one") != 0) + { + puts ("getenv #3 failed"); + result = 1; + } + + /* Now replace the value using putenv. */ + if (putenv (putenv_val) != 0) + { + printf ("putenv #1 failed: %m\n"); + result = 1; + } + + /* The value should have changed now. */ + valp = getenv (VAR); + if (valp == NULL || strcmp (valp, "some longer value") != 0) + { + printf ("getenv #4 failed (is \"%s\")\n", valp); + result = 1; + } + + /* Now one tricky check: changing the variable passed in putenv should + change the environment. */ + strcpy (&putenv_val[sizeof VAR], "a short one"); + + /* The value should have changed again. */ + valp = getenv (VAR); + if (valp == NULL || strcmp (valp, "a short one") != 0) + { + puts ("getenv #5 failed"); + result = 1; + } + + /* It should even be possible to rename the variable. */ + strcpy (putenv_val, "XYZZY=some other value"); + + /* Now a lookup using the old name should fail. */ + if (getenv (VAR) != NULL) + { + puts ("getenv #6 failed"); + result = 1; + } + + /* But using the new name it should work. */ + valp = getenv ("XYZZY"); + if (valp == NULL || strcmp (valp, "some other value") != 0) + { + puts ("getenv #7 failed"); + result = 1; + } + + /* Create a new variable with the old name. */ + if (setenv (VAR, "a new value", 0) != 0) + { + printf ("setenv #3 failed: %m\n"); + result = 1; + } + + /* At this point a getenv call must return the new value. */ + valp = getenv (VAR); + if (valp == NULL || strcmp (valp, "a new value") != 0) + { + puts ("getenv #8 failed"); + result = 1; + } + + /* Black magic: rename the variable we added using putenv back. */ + strcpy (putenv_val, VAR "=old name new value"); + + /* This is interesting. We have two variables with the same name. + Getting a value should return one of them. */ + valp = getenv (VAR); + if (valp == NULL + || (strcmp (valp, "a new value") != 0 + && strcmp (valp, "old name new value") != 0)) + { + puts ("getenv #9 failed"); + result = 1; + } + + /* More fun ahead: we are now removing the variable. This should remove + both values. The cast is ok: this call should never put the string + in the environment and it should never modify it. */ + putenv ((char *) VAR); + + /* Getting the value should now fail. */ + if (getenv (VAR) != NULL) + { + printf ("getenv #10 failed (\"%s\" found)\n", getenv (VAR)); + result = 1; + } + + /* Now a test with an environment variable that's one character long. + This is to test a special case in the getenv implementation. */ + strcpy (putenv_val, "X=one character test"); + if (putenv (putenv_val) != 0) + { + printf ("putenv #2 failed: %m\n"); + result = 1; + } + + valp = getenv ("X"); + if (valp == NULL || strcmp (valp, "one character test") != 0) + { + puts ("getenv #11 failed"); + result = 1; + } + + return result; +} diff -uNr dietlibc-0.24/test/stdlib/tst-limits.c dietlibc-0.25/test/stdlib/tst-limits.c --- dietlibc-0.24/test/stdlib/tst-limits.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/tst-limits.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,73 @@ +/* It is important that this comes first to not hide effects introduced + by other headers. */ +#include + +#include +#include + +static long long int +bitval (int bits) +{ + long long int val = 0; + while (bits-- > 0) + val |= 1ll << bits; + return val; +} + + +int +main (void) +{ + int result = 0; + +#define TEST(name, format, expected) \ + if (expected != name ) \ + fprintf (stderr, "%-12s expected = %-20" format " actual = %" format "\n", \ + #name ":", expected, name); \ + result |= name != expected + + /* The limits from ISO C99. */ + + /* We cannot support anything but 8-bit chars. */ + TEST (CHAR_BIT, "d", 8); + TEST (SCHAR_MIN, "d", -128); + TEST (SCHAR_MAX, "d", 127); + TEST (UCHAR_MAX, "d", 255); + + TEST (SHRT_MIN, "d", -(1 << (sizeof (short int) * CHAR_BIT - 1))); + TEST (SHRT_MAX, "d", (1 << (sizeof (short int) * CHAR_BIT - 1)) - 1); + TEST (USHRT_MAX, "d", (1 << sizeof (short int) * CHAR_BIT) - 1); + + TEST (INT_MIN, "d", (int) -bitval (sizeof (int) * CHAR_BIT - 1) - 1); + TEST (INT_MAX, "d", (int) bitval (sizeof (int) * CHAR_BIT - 1)); + TEST (UINT_MAX, "u", + (unsigned int) bitval (sizeof (unsigned int) * CHAR_BIT)); + + TEST (LONG_MIN, "ld", + (long int) -bitval (sizeof (long int) * CHAR_BIT - 1) - 1); + TEST (LONG_MAX, "ld", (long int) bitval (sizeof (long int) * CHAR_BIT - 1)); + TEST (ULONG_MAX, "lu", + (unsigned long int) bitval (sizeof (unsigned long int) * CHAR_BIT)); +#ifdef __dietlibc__ /* tst-limits.c:54: `LLONG_MIN' undeclared (first use in this function). Great.*/ + TEST (LLONG_MIN, "lld", -bitval (sizeof (long long int) * CHAR_BIT - 1) - 1); + TEST (LLONG_MAX, "lld", bitval (sizeof (long long int) * CHAR_BIT - 1)); + TEST (ULLONG_MAX, "llu", + (unsigned long long int) bitval (sizeof (unsigned long long int) + * CHAR_BIT)); +#endif + + /* Values from POSIX and Unix. */ +#ifdef PAGESIZE + TEST (PAGESIZE, "d", getpagesize ()); +#elif PAGE_SIZE + TEST (PAGE_SIZE, "d", getpagesize ()); +#endif + + +/* not defined in dietlibc + TEST (WORD_BIT, "zd", sizeof (int) * CHAR_BIT); +/ TEST (LONG_BIT, "zd", sizeof (long int) * CHAR_BIT); */ + + if (!result) fprintf(stdout, "OK\n"); + return result; +} diff -uNr dietlibc-0.24/test/stdlib/tst-malloc.c dietlibc-0.25/test/stdlib/tst-malloc.c --- dietlibc-0.24/test/stdlib/tst-malloc.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/tst-malloc.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,68 @@ +/* Copyright (C) 1999 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Jaeger , 1999. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +static int errors = 0; + +static void +merror (const char *msg) +{ + ++errors; + printf ("Error: %s\n", msg); +} + +int +main (void) +{ + void *p; + int save; + + errno = 0; + + p = malloc (-1); + save = errno; + + if (p != NULL) + merror ("malloc (-1) succeeded."); + + if (p == NULL && save != ENOMEM) + merror ("errno is not set correctly"); + + p = malloc (10); + if (p == NULL) + merror ("malloc (10) failed."); + + /* realloc (p, 0) == free (p). */ + p = realloc (p, 0); + if (p != NULL) + merror ("realloc (p, 0) failed."); + + p = malloc (0); + if (p == NULL) + merror ("malloc (0) failed."); + + p = realloc (p, 0); + if (p != NULL) + merror ("realloc (p, 0) failed."); + + return errors != 0; +} diff -uNr dietlibc-0.24/test/stdlib/tst-rand48.c dietlibc-0.25/test/stdlib/tst-rand48.c --- dietlibc-0.24/test/stdlib/tst-rand48.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/tst-rand48.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,390 @@ +#include +#include +#include +#include + +#ifndef DECIMAL_DIG +# define DECIMAL_DIG 21 +#endif + + +int +main (void) +{ + unsigned short int xs[3] = { 0x0001, 0x0012, 0x0123 }; + unsigned short int lxs[7]; + unsigned short int *xsp; + int result = 0; + long int l; + double d; + double e; + + /* Test srand48. */ + srand48 (0x98765432); + /* Get the values of the internal Xi array. */ + xsp = seed48 (xs); + if (xsp[0] != 0x330e || xsp[1] != 0x5432 || xsp[2] != 0x9876) + { + puts ("srand48(0x98765432) didn't set correct value"); + printf (" expected: { %04hx, %04hx, %04hx }\n", 0x330e, 0x5432, 0x9876); + printf (" seen: { %04hx, %04hx, %04hx }\n", xsp[0], xsp[1], xsp[2]); + result = 1; + } + /* Put the values back. */ + memcpy (xs, xsp, sizeof (xs)); + (void) seed48 (xs); + + /* See whether the correct values are installed. */ + l = lrand48 (); + if (l != 0x2fed1413l) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x2fed1413l, l); + result = 1; + } + + l = mrand48 (); + if (l != 0xa28c1003l) + { + printf ("mrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0xa28c1003l, l); + result = 1; + } + + l = lrand48 (); + if (l != 0x585fcfb7l) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x585fcfb7l, l); + result = 1; + } + + l = mrand48 (); + if (l != 0x9e88f474l) + { + printf ("mrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x9e88f474l, l); + result = 1; + } + + /* Test seed48. The previous call should have install the values in + the initialization of `xs' above. */ + xs[0] = 0x1234; + xs[1] = 0x5678; + xs[2] = 0x9012; + xsp = seed48 (xs); + if (xsp[0] != 0x62f2 || xsp[1] != 0xf474 || xsp[2] != 0x9e88) + { + puts ("seed48() did not install the values correctly"); + printf (" expected: { %04hx, %04hx, %04hx }\n", 0x62f2, 0xf474, 0x9e88); + printf (" seen: { %04hx, %04hx, %04hx }\n", xsp[0], xsp[1], xsp[2]); + result = 1; + } + + /* Test lrand48 and mrand48. We continue from the seed established + above. */ + l = lrand48 (); + if (l != 0x017e48b5l) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x017e48b5l, l); + result = 1; + } + + l = mrand48 (); + if (l != 0xeb7a1fa3l) + { + printf ("mrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0xeb7a1fa3l, l); + result = 1; + } + + l = lrand48 (); + if (l != 0x6b6a3f95l) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x6b6a3f95l, l); + result = 1; + } + + l = mrand48 (); + if (l != 0x175c0d6fl) + { + printf ("mrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x175c0d6fl, l); + result = 1; + } + + /* Test lcong48. */ + lxs[0] = 0x4567; + lxs[1] = 0x6789; + lxs[2] = 0x8901; + lxs[3] = 0x0123; + lxs[4] = 0x2345; + lxs[5] = 0x1111; + lxs[6] = 0x2222; + lcong48 (lxs); + + /* See whether the correct values are installed. */ + l = lrand48 (); + if (l != 0x6df63d66l) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x6df63d66l, l); + result = 1; + } + + l = mrand48 (); + if (l != 0x2f92c8e1l) + { + printf ("mrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x2f92c8e1l, l); + result = 1; + } + + l = lrand48 (); + if (l != 0x3b4869ffl) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x3b4869ffl, l); + result = 1; + } + + l = mrand48 (); + if (l != 0x5cd4cc3el) + { + printf ("mrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x5cd4cc3el, l); + result = 1; + } + + /* Check whether srand48() restores the A and C parameters. */ + srand48 (0x98765432); + + /* See whether the correct values are installed. */ + l = lrand48 (); + if (l != 0x2fed1413l) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x2fed1413l, l); + result = 1; + } + + l = mrand48 (); + if (l != 0xa28c1003l) + { + printf ("mrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0xa28c1003l, l); + result = 1; + } + + l = lrand48 (); + if (l != 0x585fcfb7l) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x585fcfb7l, l); + result = 1; + } + + l = mrand48 (); + if (l != 0x9e88f474l) + { + printf ("mrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x9e88f474l, l); + result = 1; + } + + /* And again to see whether seed48() does the same. */ + lcong48 (lxs); + + /* See whether lxs wasn't modified. */ + l = lrand48 (); + if (l != 0x6df63d66l) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x6df63d66l, l); + result = 1; + } + + /* Test seed48. The previous call should have install the values in + the initialization of `xs' above. */ + xs[0] = 0x1234; + xs[1] = 0x5678; + xs[2] = 0x9012; + xsp = seed48 (xs); + if (xsp[0] != 0x0637 || xsp[1] != 0x7acd || xsp[2] != 0xdbec) + { + puts ("seed48() did not install the values correctly"); + printf (" expected: { %04hx, %04hx, %04hx }\n", 0x0637, 0x7acd, 0xdbec); + printf (" seen: { %04hx, %04hx, %04hx }\n", xsp[0], xsp[1], xsp[2]); + result = 1; + } + + /* Test lrand48 and mrand48. We continue from the seed established + above. */ + l = lrand48 (); + if (l != 0x017e48b5l) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x017e48b5l, l); + result = 1; + } + + l = mrand48 (); + if (l != 0xeb7a1fa3l) + { + printf ("mrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0xeb7a1fa3l, l); + result = 1; + } + + l = lrand48 (); + if (l != 0x6b6a3f95l) + { + printf ("lrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x6b6a3f95l, l); + result = 1; + } + + l = mrand48 (); + if (l != 0x175c0d6fl) + { + printf ("mrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x175c0d6fl, l); + result = 1; + } + + /* Test drand48. */ + d = drand48 (); + if (d != 0.0908832261858485424) + { + printf ("drand48() in line %d failed: expected %.*g, seen %.*g\n", + __LINE__ - 4, DECIMAL_DIG, 0.0908832261858485424, + DECIMAL_DIG, d); + result = 1; + } + + d = drand48 (); + if (d != 0.943149381730059133133) + { + printf ("drand48() in line %d failed: expected %.*g, seen %.*g\n", + __LINE__ - 4, DECIMAL_DIG, 0.943149381730059133133, + DECIMAL_DIG, d); + result = 1; + } + + /* Now the functions which get the Xis passed. */ + xs[0] = 0x3849; + xs[1] = 0x5061; + xs[2] = 0x7283; + + l = nrand48 (xs); + if (l != 0x1efe61a1l) + { + printf ("nrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x1efe61a1l, l); + result = 1; + } + + l = jrand48 (xs); + if (l != 0xf568c7a0l) + { + printf ("jrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0xf568c7a0l, l); + result = 1; + } + + l = nrand48 (xs); + if (l != 0x2a5e57fel) + { + printf ("nrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x2a5e57fel, l); + result = 1; + } + + l = jrand48 (xs); + if (l != 0x71a779a8l) + { + printf ("jrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x71a779a8l, l); + result = 1; + } + + /* Test whether the global A and C are used. */ + lcong48 (lxs); + + l = nrand48 (xs); + if (l != 0x32beee9fl) + { + printf ("nrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x32beee9fl, l); + result = 1; + } + + l = jrand48 (xs); + if (l != 0x7bddf3bal) + { + printf ("jrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x7bddf3bal, l); + result = 1; + } + + l = nrand48 (xs); + if (l != 0x85bdf28l) + { + printf ("nrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x85bdf28l, l); + result = 1; + } + + l = jrand48 (xs); + if (l != 0x7b433e47l) + { + printf ("jrand48() in line %d failed: expected %lx, seen %lx\n", + __LINE__ - 4, 0x7b433e47l, l); + result = 1; + } + + /* Test erand48. Also compare with the drand48 results. */ + (void) seed48 (xs); + + d = drand48 (); + e = erand48 (xs); + if (d != e) + { + printf ("\ +drand48() and erand48 in lines %d and %d produce different results\n", + __LINE__ - 6, __LINE__ - 5); + printf (" drand48() = %g, erand48() = %g\n", d, e); + result = 1; + } + else if (e != 0.640650904452755298735) + { + printf ("erand48() in line %d failed: expected %.*g, seen %.*g\n", + __LINE__ - 4, DECIMAL_DIG, 0.640650904452755298735, + DECIMAL_DIG, e); + result = 1; + + } + + d = drand48 (); + e = erand48 (xs); + if (d != e) + { + printf ("\ +drand48() and erand48 in lines %d and %d produce different results\n", + __LINE__ - 6, __LINE__ - 5); + printf (" drand48() = %g, erand48() = %g\n", d, e); + result = 1; + } + else if (e != 0.115372323508150742555) + { + printf ("erand48() in line %d failed: expected %.*g, seen %.*g\n", + __LINE__ - 4, DECIMAL_DIG, 0.0115372323508150742555, + DECIMAL_DIG, e); + result = 1; + + } + + return result; +} diff -uNr dietlibc-0.24/test/stdlib/tst-strtod.c dietlibc-0.25/test/stdlib/tst-strtod.c --- dietlibc-0.24/test/stdlib/tst-strtod.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/tst-strtod.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,261 @@ +/* Copyright (C) 1991,96,97,98,99,2000,2001,2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct ltest + { + const char *str; /* Convert this. */ + double expect; /* To get this. */ + char left; /* With this left over. */ + int err; /* And this in errno. */ + }; +static const struct ltest tests[] = + { + { "12.345", 12.345, '\0', 0 }, + { "12.345e19", 12.345e19, '\0', 0 }, + { "-.1e+9", -.1e+9, '\0', 0 }, + { ".125", .125, '\0', 0 }, + { "1e20", 1e20, '\0', 0 }, + { "0e-19", 0, '\0', 0 }, + { "4\00012", 4.0, '\0', 0 }, + { "5.9e-76", 5.9e-76, '\0', 0 }, + { "0x1.4p+3", 10.0, '\0', 0 }, + { "0xAp0", 10.0, '\0', 0 }, + { "0x0Ap0", 10.0, '\0', 0 }, + { "0x0A", 10.0, '\0', 0 }, + { "0xA0", 160.0, '\0', 0 }, + { "0x0.A0p8", 160.0, '\0', 0 }, + { "0x0.50p9", 160.0, '\0', 0 }, + { "0x0.28p10", 160.0, '\0', 0 }, + { "0x0.14p11", 160.0, '\0', 0 }, + { "0x0.0A0p12", 160.0, '\0', 0 }, + { "0x0.050p13", 160.0, '\0', 0 }, + { "0x0.028p14", 160.0, '\0', 0 }, + { "0x0.014p15", 160.0, '\0', 0 }, + { "0x00.00A0p16", 160.0, '\0', 0 }, + { "0x00.0050p17", 160.0, '\0', 0 }, + { "0x00.0028p18", 160.0, '\0', 0 }, + { "0x00.0014p19", 160.0, '\0', 0 }, + { "0x1p-1023", + 1.11253692925360069154511635866620203210960799023116591527666e-308, + '\0', 0 }, + { "0x0.8p-1022", + 1.11253692925360069154511635866620203210960799023116591527666e-308, + '\0', 0 }, +/*#if __GNUC_PREREQ(2,96) + For older GCC release HUGE_VAL is not a constant. Also fails with diet libc. + { "Inf", HUGE_VAL, '\0', 0 }, + { "-Inf", -HUGE_VAL, '\0', 0 }, + { "+InFiNiTy", HUGE_VAL, '\0', 0 }, +#endif */ + { NULL, 0, '\0', 0 } + }; + +static void expand (char *dst, int c); +static int long_dbl (void); +static int locale_test (void); + +int +main (int argc, char ** argv) +{ + char buf[100]; + register const struct ltest *lt; + char *ep; + int status = 0; + int save_errno; + + for (lt = tests; lt->str != NULL; ++lt) + { + double d; + + errno = 0; + d = strtod(lt->str, &ep); + save_errno = errno; + printf ("strtod (\"%s\") test %u", + lt->str, (unsigned int) (lt - tests)); + if (d == lt->expect && *ep == lt->left && save_errno == lt->err) + puts ("\tOK"); + else + { + puts ("\tBAD"); + if (d != lt->expect) + printf (" returns %.60g, expected %.60g\n", d, lt->expect); + if (lt->left != *ep) + { + char exp1[5], exp2[5]; + expand (exp1, *ep); + expand (exp2, lt->left); + printf (" leaves '%s', expected '%s'\n", exp1, exp2); + } + if (save_errno != lt->err) + printf (" errno %d (%s) instead of %d (%s)\n", + save_errno, strerror (save_errno), + lt->err, strerror (lt->err)); + status = 1; + } + } + + sprintf (buf, "%f", strtod ("-0.0", NULL)); + if (strcmp (buf, "-0.000000") != 0) + { + printf (" strtod (\"-0.0\", NULL) returns \"%s\"\n", buf); + status = 1; + } + + const char input[] = "3752432815e-39"; + + float f1 = strtold (input, NULL); + float f2; + float f3 = strtof (input, NULL); + sscanf (input, "%g", &f2); + + if (f1 != f2) + { + printf ("f1 = %a != f2 = %a\n", f1, f2); + status = 1; + } + if (f1 != f3) + { + printf ("f1 = %a != f3 = %a\n", f1, f3); + status = 1; + } + if (f2 != f3) + { + printf ("f2 = %a != f3 = %a\n", f2, f3); + status = 1; + } + + const char input2[] = "+1.000000000116415321826934814453125"; + if (strtold (input2, NULL) != +1.000000000116415321826934814453125) + { + printf ("input2: %La != %La\n", strtold (input2, NULL), + +1.000000000116415321826934814453125); + status = 1; + } + + status |= long_dbl (); + + status |= locale_test (); + + return status ? EXIT_FAILURE : EXIT_SUCCESS; +} + +static void +expand (dst, c) + char *dst; + register int c; +{ + if (isprint (c)) + { + dst[0] = c; + dst[1] = '\0'; + } + else + (void) sprintf (dst, "%#.3o", (unsigned int) c); +} + +static int +long_dbl (void) +{ + /* Regenerate this string using + + echo '(2^53-1)*2^(1024-53)' | bc | sed 's/\([^\]*\)\\*$/ "\1"/' + + */ + static const char longestdbl[] = + "17976931348623157081452742373170435679807056752584499659891747680315" + "72607800285387605895586327668781715404589535143824642343213268894641" + "82768467546703537516986049910576551282076245490090389328944075868508" + "45513394230458323690322294816580855933212334827479782620414472316873" + "8177180919299881250404026184124858368"; + double d = strtod (longestdbl, NULL); + + printf ("strtod (\"%s\", NULL) = %g\n", longestdbl, d); + + if (d != 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000) + return 1; + + return 0; +} + +/* Perform a few tests in a locale with thousands separators. */ +static int +locale_test (void) +{ + static const struct + { + const char *loc; + const char *str; + double exp; + ptrdiff_t nread; + } tests[] = + { + { "de_DE.UTF-8", "1,5", 1.5, 3 }, + { "de_DE.UTF-8", "1.5", 1.0, 1 }, + { "de_DE.UTF-8", "1.500", 1500.0, 5 }, + { "de_DE.UTF-8", "36.893.488.147.419.103.232", 0x1.0p65, 26 } + }; +#define ntests (sizeof (tests) / sizeof (tests[0])) + size_t n; + int result = 0; + + puts ("\nLocale tests"); + + for (n = 0; n < ntests; ++n) + { + double d; + char *endp; + + if (setlocale (LC_ALL, tests[n].loc) == NULL) + { + printf ("cannot set locale %s\n", tests[n].loc); + result = 1; + continue; + } + + /* This originally called __strtod_interal here "to tests the + handling of grouping." */ + // d = __strtod_internal (tests[n].str, &endp, 1); + d = strtod (tests[n].str, &endp); + if (d != tests[n].exp) + { + printf ("strtod(\"%s\") returns %g and not %g\n", + tests[n].str, d, tests[n].exp); + result = 1; + } + else if (endp - tests[n].str != tests[n].nread) + { + printf ("strtod(\"%s\") read %td bytes and not %td\n", + tests[n].str, endp - tests[n].str, tests[n].nread); + result = 1; + } + } + + if (result == 0) + puts ("all OK"); + + return result; +} diff -uNr dietlibc-0.24/test/stdlib/tst-strtol.c dietlibc-0.25/test/stdlib/tst-strtol.c --- dietlibc-0.24/test/stdlib/tst-strtol.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/tst-strtol.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,187 @@ +/* My bet is this was written by Chris Torek. + I reformatted and ansidecl-ized it, and tweaked it a little. */ + +#include +#include +#include +#include +#include +#include + +struct ltest + { + const char *str; /* Convert this. */ + unsigned long int expect; /* To get this. */ + int base; /* Use this base. */ + char left; /* With this left over. */ + int err; /* And this in errno. */ + }; +static const struct ltest tests[] = + { + /* First, signed numbers: */ + /* simple... */ + {"123", 123, 0, 0, 0}, + {"+123", 123, 0, 0, 0}, + {" 123", 123, 0, 0, 0}, + {" 123 ", 123, 0, ' ', 0}, + {" -17", -17, 0, 0, 0}, + + /* implicit base... */ + {"0123", 0123, 0, 0, 0}, + {"0123a", 0123, 0, 'a', 0}, + {"01239", 0123, 0, '9', 0}, + {"0x123", 0x123, 0, 0, 0}, + {"-0x123", -0x123, 0, 0, 0}, + {"0x0xc", 0, 0, 'x', 0}, + {" +0x123fg", 0x123f, 0, 'g', 0}, + + /* explicit base... */ + {"123", 0x123, 16, 0, 0}, + {"0x123", 0x123, 16, 0, 0}, + {"123", 0123, 8, 0, 0}, + {"0123", 0123, 8, 0, 0}, + {"0123", 123, 10, 0, 0}, + {"0x123", 0, 10, 'x', 0}, + + /* case insensitivity... */ + {"abcd", 0xabcd, 16, 0, 0}, + {"AbCd", 0xabcd, 16, 0, 0}, + {"0xABCD", 0xabcd, 16, 0, 0}, + {"0Xabcd", 0xabcd, 16, 0, 0}, + + /* odd bases... */ + {"0xyz", 33 * 35 + 34, 35, 'z', 0}, + {"yz!", 34 * 36 + 35, 36, '!', 0}, + {"-yz", -(34*36 + 35), 36, 0, 0}, + {"GhI4", ((16*20 + 17)*20 + 18)*20 + 4, 20, 0, 0}, + + /* extremes... */ +#if LONG_MAX == 0x7fffffff + {"2147483647", 2147483647, 0, 0, 0}, + {"2147483648", 2147483647, 0, 0, ERANGE}, + {"214748364888", 2147483647, 0, 0, ERANGE}, + {"2147483650", 2147483647, 0, 0, ERANGE}, + {"-2147483648", 0x80000000, 0, 0, 0}, + {"-2147483649", 0x80000000, 0, 0, ERANGE}, + {"0x1122334455z", 2147483647, 16, 'z', ERANGE}, +#else + {"9223372036854775807", 9223372036854775807, 0, 0, 0}, + {"9223372036854775808", 9223372036854775807, 0, 0, ERANGE}, + {"922337203685477580777", 9223372036854775807, 0, 0, ERANGE}, + {"9223372036854775810", 9223372036854775807, 0, 0, ERANGE}, + {"-2147483648", -2147483648, 0, 0, 0}, + {"-9223372036854775808", 0x8000000000000000, 0, 0, 0}, + {"-9223372036854775809", 0x8000000000000000, 0, 0, ERANGE}, + {"0x112233445566778899z", 9223372036854775807, 16, 'z', ERANGE}, + {"0xFFFFFFFFFFFF00FF" , 9223372036854775807, 0, 0, ERANGE}, +#endif + {NULL, 0, 0, 0, 0}, + + /* Then unsigned. */ + {" 0", 0, 0, 0, 0}, + {"0xffffffffg", 0xffffffff, 0, 'g', 0}, +#if LONG_MAX == 0x7fffffff + {"-0xfedcba98", 0x01234568, 0, 0, 0}, + {"0xf1f2f3f4f5", 0xffffffff, 0, 0, ERANGE}, + {"-0x123456789", 0xffffffff, 0, 0, ERANGE}, +#else + {"0xffffffffffffffffg", 0xffffffffffffffff, 0, 'g', 0}, + {"-0xfedcba987654321", 0xf0123456789abcdf, 0, 0, 0}, + {"0xf1f2f3f4f5f6f7f8f9", 0xffffffffffffffff, 0, 0, ERANGE}, + {"-0x123456789abcdef01", 0xffffffffffffffff, 0, 0, ERANGE}, +#endif + {NULL, 0, 0, 0, 0}, + }; + +/* Prototypes for local functions. */ +static void expand (char *dst, int c); + +int +main (void) +{ + register const struct ltest *lt; + char *ep; + int status = 0; + int save_errno; + + for (lt = tests; lt->str != NULL; ++lt) + { + register long int l; + + errno = 0; + l = strtol (lt->str, &ep, lt->base); + save_errno = errno; + printf ("strtol(\"%s\", , %d) test %u", + lt->str, lt->base, (unsigned int) (lt - tests)); + if (l == (long int) lt->expect && *ep == lt->left + && save_errno == lt->err) + puts("\tOK"); + else + { + puts("\tBAD"); + if (l != (long int) lt->expect) + printf(" returns %ld, expected %ld\n", + l, (long int) lt->expect); + if (lt->left != *ep) + { + char exp1[5], exp2[5]; + expand (exp1, *ep); + expand (exp2, lt->left); + printf (" leaves '%s', expected '%s'\n", exp1, exp2); + } + if (save_errno != lt->err) + printf (" errno %d (%s) instead of %d (%s)\n", + save_errno, strerror (save_errno), + lt->err, strerror (lt->err)); + status = 1; + } + } + + for (++lt; lt->str != NULL; lt++) + { + register unsigned long int ul; + + errno = 0; + ul = strtoul (lt->str, &ep, lt->base); + save_errno = errno; + printf ("strtoul(\"%s\", , %d) test %u", + lt->str, lt->base, (unsigned int) (lt - tests)); + if (ul == lt->expect && *ep == lt->left && save_errno == lt->err) + puts("\tOK"); + else + { + puts ("\tBAD"); + if (ul != lt->expect) + printf (" returns %lu, expected %lu\n", + ul, lt->expect); + if (lt->left != *ep) + { + char exp1[5], exp2[5]; + expand (exp1, *ep); + expand (exp2, lt->left); + printf (" leaves '%s', expected '%s'\n", exp1, exp2); + } + if (save_errno != lt->err) + printf (" errno %d (%s) instead of %d (%s)\n", + save_errno, strerror (save_errno), + lt->err, strerror (lt->err)); + status = 1; + } + } + + return status ? EXIT_FAILURE : EXIT_SUCCESS; +} + +static void +expand (dst, c) + char *dst; + int c; +{ + if (isprint (c)) + { + dst[0] = c; + dst[1] = '\0'; + } + else + (void) sprintf (dst, "%#.3o", (unsigned int) c); +} diff -uNr dietlibc-0.24/test/stdlib/tst-strtoll.c dietlibc-0.25/test/stdlib/tst-strtoll.c --- dietlibc-0.24/test/stdlib/tst-strtoll.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/tst-strtoll.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,175 @@ +/* My bet is this was written by Chris Torek. + I reformatted and ansidecl-ized it, and tweaked it a little. */ + +#include +#include +#include +#include +#include +#include + +struct ltest + { + const char *str; /* Convert this. */ + unsigned long long int expect; /* To get this. */ + int base; /* Use this base. */ + char left; /* With this left over. */ + int err; /* And this in errno. */ + }; +static const struct ltest tests[] = + { + /* First, signed numbers: */ + /* simple... */ + {"123", 123, 0, 0, 0}, + {"+123", 123, 0, 0, 0}, + {" 123", 123, 0, 0, 0}, + {" 123 ", 123, 0, ' ', 0}, + {" -17", -17, 0, 0, 0}, + + /* implicit base... */ + {"0123", 0123, 0, 0, 0}, + {"0123a", 0123, 0, 'a', 0}, + {"01239", 0123, 0, '9', 0}, + {"0x123", 0x123, 0, 0, 0}, + {"-0x123", -0x123, 0, 0, 0}, + {"0x0xc", 0, 0, 'x', 0}, + {" +0x123fg", 0x123f, 0, 'g', 0}, + + /* explicit base... */ + {"123", 0x123, 16, 0, 0}, + {"0x123", 0x123, 16, 0, 0}, + {"123", 0123, 8, 0, 0}, + {"0123", 0123, 8, 0, 0}, + {"0123", 123, 10, 0, 0}, + {"0x123", 0, 10, 'x', 0}, + + /* case insensitivity... */ + {"abcd", 0xabcd, 16, 0, 0}, + {"AbCd", 0xabcd, 16, 0, 0}, + {"0xABCD", 0xabcd, 16, 0, 0}, + {"0Xabcd", 0xabcd, 16, 0, 0}, + + /* odd bases... */ + {"0xyz", 33 * 35 + 34, 35, 'z', 0}, + {"yz!", 34 * 36 + 35, 36, '!', 0}, + {"-yz", -(34*36 + 35), 36, 0, 0}, + {"GhI4", ((16*20 + 17)*20 + 18)*20 + 4, 20, 0, 0}, + + /* special case for the 32-bit version of strtoll, + from a ncftp configure test */ + {"99000000001", 1000000000ll * 99ll + 1ll, 0, 0}, + + /* extremes... */ + {"9223372036854775807", 9223372036854775807ll, 0, 0, 0}, + {"9223372036854775808", 9223372036854775807ll, 0, 0, ERANGE}, + {"922337203685477580777", 9223372036854775807ll, 0, 0, ERANGE}, + {"9223372036854775810", 9223372036854775807ll, 0, 0, ERANGE}, + {"-2147483648", -2147483648ll, 0, 0, 0}, + {"-9223372036854775808", -9223372036854775807ll - 1, 0, 0, 0}, + {"-9223372036854775809", -9223372036854775807ll - 1, 0, 0, ERANGE}, + {"0x112233445566778899z", 9223372036854775807ll, 16, 'z', ERANGE}, + {"0xFFFFFFFFFFFF00FF" , 9223372036854775807ll, 0, 0, ERANGE}, + {NULL, 0, 0, 0, 0}, + + /* Then unsigned. */ + {" 0", 0, 0, 0, 0}, + {"0xffffffffg", 0xffffffff, 0, 'g', 0}, + {"0xffffffffffffffffg", 0xffffffffffffffffull, 0, 'g', 0}, + {"-0xfedcba987654321", 0xf0123456789abcdfull, 0, 0, 0}, + {"0xf1f2f3f4f5f6f7f8f9", 0xffffffffffffffffull, 0, 0, ERANGE}, + {"-0x123456789abcdef01", 0xffffffffffffffffull, 0, 0, ERANGE}, + {NULL, 0, 0, 0, 0}, + }; + +/* Prototypes for local functions. */ +static void expand (char *dst, int c); + +int +main (void) +{ + register const struct ltest *lt; + char *ep; + int status = 0; + int save_errno; + + for (lt = tests; lt->str != NULL; ++lt) + { + register long long int l; + + errno = 0; + l = strtoll (lt->str, &ep, lt->base); + save_errno = errno; + printf ("strtoll(\"%s\", , %d) test %u", + lt->str, lt->base, (unsigned int) (lt - tests)); + if (l == (long long int) lt->expect && *ep == lt->left + && save_errno == lt->err) + puts("\tOK"); + else + { + puts("\tBAD"); + if (l != (long long int) lt->expect) + printf(" returns %lld, expected %lld\n", + l, (long long int) lt->expect); + if (lt->left != *ep) + { + char exp1[5], exp2[5]; + expand (exp1, *ep); + expand (exp2, lt->left); + printf (" leaves '%s', expected '%s'\n", exp1, exp2); + } + if (save_errno != lt->err) + printf (" errno %d (%s) instead of %d (%s)\n", + save_errno, strerror (save_errno), + lt->err, strerror (lt->err)); + status = 1; + } + } + + for (++lt; lt->str != NULL; lt++) + { + register unsigned long long int ul; + + errno = 0; + ul = strtoull (lt->str, &ep, lt->base); + save_errno = errno; + printf ("strtoull(\"%s\", , %d) test %u", + lt->str, lt->base, (unsigned int) (lt - tests)); + if (ul == lt->expect && *ep == lt->left && save_errno == lt->err) + puts("\tOK"); + else + { + puts ("\tBAD"); + if (ul != lt->expect) + printf (" returns %llu, expected %llu\n", + ul, lt->expect); + if (lt->left != *ep) + { + char exp1[5], exp2[5]; + expand (exp1, *ep); + expand (exp2, lt->left); + printf (" leaves '%s', expected '%s'\n", exp1, exp2); + } + if (save_errno != lt->err) + printf (" errno %d (%s) instead of %d (%s)\n", + save_errno, strerror (save_errno), + lt->err, strerror (lt->err)); + status = 1; + } + } + + return status ? EXIT_FAILURE : EXIT_SUCCESS; +} + +static void +expand (dst, c) + char *dst; + int c; +{ + if (isprint (c)) + { + dst[0] = c; + dst[1] = '\0'; + } + else + (void) sprintf (dst, "%#.3o", (unsigned int) c); +} diff -uNr dietlibc-0.24/test/stdlib/tst-system.c dietlibc-0.25/test/stdlib/tst-system.c --- dietlibc-0.24/test/stdlib/tst-system.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/stdlib/tst-system.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,28 @@ +/* Copyright (C) 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 2002. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +int main (void) +{ + return system (":"); +} + + diff -uNr dietlibc-0.24/test/strcasecmp.c dietlibc-0.25/test/strcasecmp.c --- dietlibc-0.24/test/strcasecmp.c 2002-11-03 01:14:35.000000000 +0100 +++ dietlibc-0.25/test/strcasecmp.c 2003-12-15 14:07:42.000000000 +0100 @@ -7,7 +7,7 @@ exit(1); } -main() { +int main() { char buf[100]="fNord"; char buf2[100]="fnOrt"; if (strcasecmp(buf,buf)) die("strcmp sais a != a"); diff -uNr dietlibc-0.24/test/strcmp.c dietlibc-0.25/test/strcmp.c --- dietlibc-0.24/test/strcmp.c 2003-02-20 16:57:13.000000000 +0100 +++ dietlibc-0.25/test/strcmp.c 2003-12-21 13:06:36.000000000 +0100 @@ -13,5 +13,8 @@ if (strcmp(buf,buf)) die("strcmp say a != a"); if (strcmp(buf,buf2)>=0) die("strcmp said fnord > fnort"); if (strcmp(buf2,buf)<=0) die("strcmp said fnort < fnord"); + if (strcmp(buf+1,buf2+1)>=0) die("unaligned strcmp is broken"); + if (strcmp(buf+2,buf2+2)>=0) die("unaligned strcmp is broken"); + if (strcmp(buf+3,buf2+3)>=0) die("unaligned strcmp is broken"); return 0; } diff -uNr dietlibc-0.24/test/string/Makefile dietlibc-0.25/test/string/Makefile --- dietlibc-0.24/test/string/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/Makefile 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,16 @@ +#DIET=diet +CC=gcc +CFLAGS=-Wall + +all: stringtest + +TESTPROGRAMS=memccpy memchr memcmp memcpy memrchr strcasecmp strcmp strlen strncat strncpy strrchr strstr + +stringtest: $(TESTPROGRAMS) + +%: %.c + $(DIET) $(CC) $(CFLAGS) $^ -o $@ + +clean: + rm -f $(TESTPROGRAMS) + diff -uNr dietlibc-0.24/test/string/memccpy.c dietlibc-0.25/test/string/memccpy.c --- dietlibc-0.24/test/string/memccpy.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/memccpy.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,15 @@ +#include +#include + +int +main () +{ + char buf[100]; + memset (buf, 0x1, sizeof (buf)); + assert (memccpy (buf, "Hello World\n", ' ', sizeof (buf))); + assert (buf[6] == 0x1); + assert (!*(char *) (memccpy (buf, "Hello, World", 0, sizeof (buf))-1)); + assert (buf[13] == 0x1); + assert (!memccpy (buf, "Hello, World\n", 0, 5)); + return (0); +} diff -uNr dietlibc-0.24/test/string/memchr.c dietlibc-0.25/test/string/memchr.c --- dietlibc-0.24/test/string/memchr.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/memchr.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,12 @@ +#include +#include + +int main() { + const char* test="blubber"; + assert(memchr("aaaa",'x',4)==0); + assert(memchr(0,'x',0)==0); + assert(memchr(test,'u',7) == test+2); + assert(memchr(test,'b',7)==test); + assert(memchr(test+6,'r',1)==test+6); + return 0; +} diff -uNr dietlibc-0.24/test/string/memcmp.c dietlibc-0.25/test/string/memcmp.c --- dietlibc-0.24/test/string/memcmp.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/memcmp.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,10 @@ +#include +#include + +int main() { + const char* test="blubber"; + assert(memcmp(test,"blubber",8)==0); + assert(memcmp(test,"fnord",5)<0); + assert(memcmp(test,0,0)==0); + return 0; +} diff -uNr dietlibc-0.24/test/string/memcpy.c dietlibc-0.25/test/string/memcpy.c --- dietlibc-0.24/test/string/memcpy.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/memcpy.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,11 @@ +#include +#include + +int main() { + char test[100]="blubber"; + assert(memcpy(test,"blubber",8)==test); + assert(!memcmp(test,"blubber",8)); + assert(memcpy(0,0,0)==0); + assert(memcpy(test,"foobar",3) && test[2]=='o'); + return 0; +} diff -uNr dietlibc-0.24/test/string/memrchr.c dietlibc-0.25/test/string/memrchr.c --- dietlibc-0.24/test/string/memrchr.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/memrchr.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,13 @@ +#define _GNU_SOURCE +#include +#include + +int main() { + const char* test="blubber"; + assert(memrchr("aaaa",'x',4)==0); + assert(memrchr(0,'x',0)==0); + assert(memrchr(test,'u',7) == test+2); + assert(memrchr(test,'b',7)==test+4); + assert(memrchr(test+6,'r',1)==test+6); + return 0; +} diff -uNr dietlibc-0.24/test/string/runtests.sh dietlibc-0.25/test/string/runtests.sh --- dietlibc-0.24/test/string/runtests.sh 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/runtests.sh 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,9 @@ +#!/bin/sh + +TESTPROGRAMS="memccpy memchr memcmp memcpy memrchr strcasecmp strcmp strlen strncat strncpy strrchr strstr" + +for p in $TESTPROGRAMS; do +echo "---";echo testing $p;echo "---" + ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 ) + done + diff -uNr dietlibc-0.24/test/string/strcasecmp.c dietlibc-0.25/test/string/strcasecmp.c --- dietlibc-0.24/test/string/strcasecmp.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/strcasecmp.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,18 @@ +#include +#include +#include + +void die(const char* message) { + puts(message); + exit(1); +} + +int main() { + char buf[100]="fNord"; + char buf2[100]="fnOrt"; + if (strcasecmp(buf,buf)) die("strcmp sais a != a"); + if (strcasecmp(buf,buf2)>=0) die("strcmp said fnord > fnort"); + if (strcasecmp(buf2,buf)<=0) die("strcmp said fnort < fnord"); + if (strcasecmp("Host","hostbasedauthentication")==0) die("strcmp said a == abc"); + return 0; +} diff -uNr dietlibc-0.24/test/string/strcmp.c dietlibc-0.25/test/string/strcmp.c --- dietlibc-0.24/test/string/strcmp.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/strcmp.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,17 @@ +#include +#include +#include + +void die(const char* message) { + puts(message); + exit(1); +} + +int main() { + char buf[100]="fnord"; + char buf2[100]="fnort"; + if (strcmp(buf,buf)) die("strcmp say a != a"); + if (strcmp(buf,buf2)>=0) die("strcmp said fnord > fnort"); + if (strcmp(buf2,buf)<=0) die("strcmp said fnort < fnord"); + return 0; +} diff -uNr dietlibc-0.24/test/string/strlen.c dietlibc-0.25/test/string/strlen.c --- dietlibc-0.24/test/string/strlen.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/strlen.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,10 @@ +#include +#include + +int main() { + const char* x="foo bar baz"; + assert(strlen("")==0); + assert(strlen(x)==11); + assert(strlen(x+5)==6); + return 0; +} diff -uNr dietlibc-0.24/test/string/strncat.c dietlibc-0.25/test/string/strncat.c --- dietlibc-0.24/test/string/strncat.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/strncat.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,17 @@ +#include +#include +#include + +void die(const char* message) { + puts(message); + exit(1); +} + +int main() { + char buf[100]="fnord"; + strncat(buf,"foo",0); + if (strcmp(buf,"fnord")) die("strncat did not work for length 0"); + strncat(buf,"foo",2); + if (strcmp(buf,"fnordfo")) die("strncat did not copy n bytes"); + return 0; +} diff -uNr dietlibc-0.24/test/string/strncpy.c dietlibc-0.25/test/string/strncpy.c --- dietlibc-0.24/test/string/strncpy.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/strncpy.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,14 @@ +#include +#include +#include + +int main() { + char buf[100]; + assert(strncpy(buf,"fnord",6)==buf); + assert(!strcmp(buf,"fnord")); + memset(buf,23,sizeof buf); + assert(strncpy(buf,"fnord",5)==buf); + assert(!memcmp(buf,"fnord",5) && buf[5]==23); + + return 0; +} diff -uNr dietlibc-0.24/test/string/strrchr.c dietlibc-0.25/test/string/strrchr.c --- dietlibc-0.24/test/string/strrchr.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/strrchr.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,10 @@ +#include +#include + +int main() { + const char* x="foo bar baz"; + assert(strrchr(x,'z')==x+10); + assert(strrchr(x,' ')==x+7); + assert(strrchr(x,'x')==0); + return 0; +} diff -uNr dietlibc-0.24/test/string/strstr.c dietlibc-0.25/test/string/strstr.c --- dietlibc-0.24/test/string/strstr.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/string/strstr.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,12 @@ +#include +#include + +int main() { + char buf[]="foo bar baz"; + assert(strstr(buf,"bar")==buf+4); + assert(strstr(buf,"baz")==buf+8); + assert(strstr(buf,"barney")==0); + assert(strstr(buf,"foo")==buf); + assert(strstr(buf,"")==buf); + return 0; +} diff -uNr dietlibc-0.24/test/strptime.c dietlibc-0.25/test/strptime.c --- dietlibc-0.24/test/strptime.c 2003-11-18 13:57:14.000000000 +0100 +++ dietlibc-0.25/test/strptime.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,11 +1,15 @@ #define _XOPEN_SOURCE #include +#include -main() { +int main() { char buf[1024]; struct tm* t; time_t T=time(0); t=localtime(&T); + strftime(buf,sizeof(buf),"%c",t); printf("%s\n",strptime(buf,"%c",t)); + + return 0; } diff -uNr dietlibc-0.24/test/strtol.c dietlibc-0.25/test/strtol.c --- dietlibc-0.24/test/strtol.c 2003-11-06 13:00:09.000000000 +0100 +++ dietlibc-0.25/test/strtol.c 2003-12-15 14:07:42.000000000 +0100 @@ -5,7 +5,7 @@ #include #include -main() { +int main() { char* c, *s; assert(strtol(s="123",&c,0)==123 && c==s+3); diff -uNr dietlibc-0.24/test/sysenter.c dietlibc-0.25/test/sysenter.c --- dietlibc-0.24/test/sysenter.c 2003-04-12 17:52:02.000000000 +0200 +++ dietlibc-0.25/test/sysenter.c 2003-12-15 14:07:42.000000000 +0100 @@ -2,6 +2,8 @@ #include #include +extern char **environ; + int main() { register struct elf_aux { unsigned long type, value; @@ -15,4 +17,5 @@ else if (x->type==AT_SYSINFO) printf("vsyscall %p\n",x->value); } + return 0; } diff -uNr dietlibc-0.24/test/test-newfnmatch.c dietlibc-0.25/test/test-newfnmatch.c --- dietlibc-0.24/test/test-newfnmatch.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/test-newfnmatch.c 2004-01-19 17:09:22.000000000 +0100 @@ -0,0 +1,141 @@ +#include +#include +#include +#include + +/* + * xlat / printflags adapted from strace + * http://www.liacs.nl/~wichert/strace/ + */ + +#define FLAG(f) { f, #f } + +struct xlat { + int val; + char *str; +} fnmatch_flags[] = { + FLAG(FNM_NOESCAPE), + FLAG(FNM_PATHNAME), + FLAG(FNM_PERIOD), + FLAG(FNM_LEADING_DIR), + FLAG(FNM_CASEFOLD), + {0, NULL}, +}; + +static void printflags(const struct xlat *map, int flags) { + char * sep; + + if (! flags) { + printf("0"); + return; + } + + sep = ""; + for (; map->str; map++) { + if (map->val && (flags & map->val) == map->val) { + printf("%s%s", sep, map->str); + sep = "|"; + flags &= ~(map->val); + } + } + if (flags) printf("%sunknown=%#x", sep, flags); +} + +/* + * tests harness adapted from glibc testfnm.c + */ +struct { + const char *pattern; + const char *string; + int flags; + int expected; +} tests[] = { + /* begin dietlibc tests */ + { "*.c", "foo.c", 0, 0 }, + { "*.c", ".c", 0, 0 }, + { "*.a", "foo.c", 0, FNM_NOMATCH }, + { "*.c", ".foo.c", 0, 0 }, + { "*.c", ".foo.c", FNM_PERIOD, FNM_NOMATCH }, + { "*.c", "foo.c", FNM_PERIOD, 0 }, + { "a\\*.c", "a*.c", FNM_NOESCAPE, FNM_NOMATCH }, + { "a\\*.c", "ax.c", 0, FNM_NOMATCH }, + { "a[xy].c", "ax.c", 0, 0 }, + { "a[!y].c", "ax.c", 0, 0 }, + { "a[a/z]*.c", "a/x.c", FNM_PATHNAME, FNM_NOMATCH }, + { "a/*.c", "a/x.c", FNM_PATHNAME, 0 }, + { "a*.c", "a/x.c", FNM_PATHNAME, FNM_NOMATCH }, + { "*/foo", "/foo", FNM_PATHNAME, 0 }, + { "*.c", "foo.C", FNM_CASEFOLD, 0 }, + { "-O[01]", "-O1", 0, 0 }, + { "[[?*\\]", "\\", 0, 0 }, + { "[]?*\\]", "]", 0, 0 }, + /* initial right-bracket tests */ + { "[!]a-]", "b", 0, 0 }, + { "[]-_]", "^", 0, 0 }, /* range: ']', '^', '_' */ + { "[!]-_]", "X", 0, 0 }, + { "??", "-", 0, FNM_NOMATCH }, + /* begin glibc tests */ + { "*LIB*", "lib", FNM_PERIOD, FNM_NOMATCH }, + { "*LIB*", "lib", FNM_CASEFOLD|FNM_PERIOD, 0 }, + { "a[/]b", "a/b", 0, 0 }, + { "a[/]b", "a/b", FNM_PATHNAME, FNM_NOMATCH }, + { "[a-z]/[a-z]", "a/b", 0, 0 }, + { "*", "a/b", FNM_FILE_NAME, FNM_NOMATCH }, + { "*[/]b", "a/b", FNM_FILE_NAME, FNM_NOMATCH }, + { "*[b]", "a/b", FNM_FILE_NAME, FNM_NOMATCH }, + { "[*]/b", "a/b", 0, FNM_NOMATCH }, + { "[*]/b", "*/b", 0, 0 }, + { "[?]/b", "a/b", 0, FNM_NOMATCH }, + { "[?]/b", "?/b", 0, 0 }, + { "[[a]/b", "a/b", 0, 0 }, + { "[[a]/b", "[/b", 0, 0 }, + { "\\*/b", "a/b", 0, FNM_NOMATCH }, + { "\\*/b", "*/b", 0, 0 }, + { "\\?/b", "a/b", 0, FNM_NOMATCH }, + { "\\?/b", "?/b", 0, 0 }, + { "[/b", "[/b", 0, FNM_NOMATCH }, + { "\\[/b", "[/b", 0, 0 }, + { "??/b", "aa/b", 0, 0 }, + { "???b", "aa/b", 0, 0 }, + { "???b", "aa/b", FNM_PATHNAME, FNM_NOMATCH }, + { "?a/b", ".a/b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH }, + { "a/?b", "a/.b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH }, + { "*a/b", ".a/b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH }, + { "a/*b", "a/.b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH }, + { "[.]a/b", ".a/b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH }, + { "a/[.]b", "a/.b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH }, + { "*/?", "a/b", FNM_PATHNAME|FNM_PERIOD, 0 }, + { "?/*", "a/b", FNM_PATHNAME|FNM_PERIOD, 0 }, + { ".*/?", ".a/b", FNM_PATHNAME|FNM_PERIOD, 0 }, + { "*/.?", "a/.b", FNM_PATHNAME|FNM_PERIOD, 0 }, + { "*/*", "a/.b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH }, + { "*?*/*", "a/.b", FNM_PERIOD, 0 }, + { "*[.]/b", "a./b", FNM_PATHNAME|FNM_PERIOD, 0 }, + { "*[[:alpha:]]/*[[:alnum:]]", "a/b", FNM_PATHNAME, 0 }, + { "*[![:digit:]]*/[![:d-d]", "a/b", FNM_PATHNAME, 0 }, + { "*[![:digit:]]*/[[:d-d]", "a/[", FNM_PATHNAME, 0 }, + { "*[![:digit:]]*/[![:d-d]", "a/[", FNM_PATHNAME, FNM_NOMATCH }, + { "a?b", "a.b", FNM_PATHNAME|FNM_PERIOD, 0 }, + { "a*b", "a.b", FNM_PATHNAME|FNM_PERIOD, 0 }, + { "a[.]b", "a.b", FNM_PATHNAME|FNM_PERIOD, 0 }, +}; + +int main(void) { + int i; + unsigned int failed = 0; + + for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) { + int r; + + r = fnmatch(tests[i].pattern, tests[i].string, tests[i].flags); + if (r != tests[i].expected) { + failed++; + printf("fail - fnmatch(\"%s\", \"%s\", ", + tests[i].pattern, tests[i].string); + printflags(fnmatch_flags, tests[i].flags); + printf(") => %d (expected %d)\n", r, tests[i].expected); + } + } + + exit(failed != 0); +} diff -uNr dietlibc-0.24/test/time/Makefile dietlibc-0.25/test/time/Makefile --- dietlibc-0.24/test/time/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/time/Makefile 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,16 @@ +DIET=diet +CC=gcc +CFLAGS=-Wall + +all: timetest + +TESTPROGRAMS=tst-strptime tst-mktime tst-posixtz tst-strftime + +timetest: $(TESTPROGRAMS) + +%: %.c + $(DIET) $(CC) $(CFLAGS) $^ -o $@ + +clean: + rm -f $(TESTPROGRAMS) + diff -uNr dietlibc-0.24/test/time/runtests.sh dietlibc-0.25/test/time/runtests.sh --- dietlibc-0.24/test/time/runtests.sh 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/time/runtests.sh 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,10 @@ +#!/bin/sh + +TESTPROGRAMS="tst-strptime tst-mktime tst-posixtz tst-strftime" + +for p in $TESTPROGRAMS; do +echo "---";echo testing $p;echo "---" + ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 ) +done + + diff -uNr dietlibc-0.24/test/time/tst-mktime.c dietlibc-0.25/test/time/tst-mktime.c --- dietlibc-0.24/test/time/tst-mktime.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/time/tst-mktime.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +int +main (void) +{ + struct tm time_str, *tm; + time_t t; + char daybuf[20]; + int result; + + time_str.tm_year = 2001 - 1900; + time_str.tm_mon = 7 - 1; + time_str.tm_mday = 4; + time_str.tm_hour = 0; + time_str.tm_min = 0; + time_str.tm_sec = 1; + time_str.tm_isdst = -1; + + if (mktime (&time_str) == -1) + { + (void) puts ("-unknown-"); + result = 1; + } + else + { + (void) strftime (daybuf, sizeof (daybuf), "%A", &time_str); + (void) puts (daybuf); + result = strcmp (daybuf, "Wednesday") != 0; + } + + setenv ("TZ", "EST+5", 1); +#define EVENING69 1 * 60 * 60 + 2 * 60 + 29 + t = EVENING69; + tm = localtime (&t); + if (tm == NULL) + { + (void) puts ("localtime returned NULL"); + result = 1; + } + else + { + time_str = *tm; + t = mktime (&time_str); + if (t != EVENING69) + { + printf ("mktime returned %ld, expected %d\n", + (long) t, EVENING69); + result = 1; + } + else + (void) puts ("Dec 31 1969 EST test passed"); + + setenv ("TZ", "CET-1", 1); + t = mktime (&time_str); + if (t != (time_t) -1) + { + printf ("mktime returned %ld, expected -1\n", (long) t); + result = 1; + } + else + (void) puts ("Dec 31 1969 CET test passed"); + } + + return result; +} diff -uNr dietlibc-0.24/test/time/tst-posixtz.c dietlibc-0.25/test/time/tst-posixtz.c --- dietlibc-0.24/test/time/tst-posixtz.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/time/tst-posixtz.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,88 @@ +#include +#include +#include +#include + +struct +{ + time_t when; + const char *tz; + const char *result; +} tests[] = +{ + { 909312849L, "AEST-10AEDST-11,M10.5.0,M3.5.0", + "1998/10/25 21:54:09 dst=1 zone=AEDST" }, + { 924864849L, "AEST-10AEDST-11,M10.5.0,M3.5.0", + "1999/04/23 20:54:09 dst=0 zone=AEST" }, + { 919973892L, "AEST-10AEDST-11,M10.5.0,M3.5.0", + "1999/02/26 07:18:12 dst=1 zone=AEDST" }, + { 909312849L, "EST+5EDT,M4.1.0/2,M10.5.0/2", + "1998/10/25 05:54:09 dst=0 zone=EST" }, + { 924864849L, "EST+5EDT,M4.1.0/2,M10.5.0/2", + "1999/04/23 06:54:09 dst=1 zone=EDT" }, + { 919973892L, "EST+5EDT,M4.1.0/2,M10.5.0/2", + "1999/02/25 15:18:12 dst=0 zone=EST" }, +}; + +int +main (void) +{ + int result = 0; + size_t cnt; + + for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt) + { + char buf[100]; + struct tm *tmp; + + printf ("TZ = \"%s\", time = %ld => ", tests[cnt].tz, tests[cnt].when); + fflush (stdout); + + setenv ("TZ", tests[cnt].tz, 1); + + tmp = localtime (&tests[cnt].when); + + snprintf (buf, sizeof (buf), + "%04d/%02d/%02d %02d:%02d:%02d dst=%d zone=%s", + tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, + tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tmp->tm_isdst, + tzname[tmp->tm_isdst ? 1 : 0]); + + fputs (buf, stdout); + + if (strcmp (buf, tests[cnt].result) == 0) + puts (", OK"); + else + { + result = 1; + puts (", FAIL"); + } + } + + setenv ("TZ", "Universal", 1); + localtime (&tests[0].when); + printf ("TZ = \"Universal\" daylight %d tzname = { \"%s\", \"%s\" }", + daylight, tzname[0], tzname[1]); + if (! daylight) + puts (", OK"); + else + { + result = 1; + puts (", FAIL"); + } + + setenv ("TZ", "AEST-10AEDST-11,M10.5.0,M3.5.0", 1); + tzset (); + printf ("TZ = \"AEST-10AEDST-11,M10.5.0,M3.5.0\" daylight %d" + " tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]); + if (daylight + && strcmp (tzname[0], "AEST") == 0 && strcmp (tzname[1], "AEDST") == 0) + puts (", OK"); + else + { + result = 1; + puts (", FAIL"); + } + + return result; +} diff -uNr dietlibc-0.24/test/time/tst-strftime.c dietlibc-0.25/test/time/tst-strftime.c --- dietlibc-0.24/test/time/tst-strftime.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/time/tst-strftime.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,70 @@ +#include +#include +#include + + +static struct +{ + const char *fmt; + size_t min; + size_t max; +} tests[] = + { + { "%2000Y", 2000, 4000 }, + { "%02000Y", 2000, 4000 }, + { "%_2000Y", 2000, 4000 }, + { "%-2000Y", 2000, 4000 }, + }; +#define ntests (sizeof (tests) / sizeof (tests[0])) + + +int main (void) { + size_t cnt; + int result = 0; + + time_t tnow = time (NULL); + struct tm *now = localtime (&tnow); + + for (cnt = 0; cnt < ntests; ++cnt) + { + size_t size = 0; + int res; + char *buf = NULL; + + do + { + size += 500; + buf = (char *) realloc (buf, size); + if (buf == NULL) + { + puts ("out of memory"); + exit (1); + } + + res = strftime (buf, size, tests[cnt].fmt, now); + if (res != 0) + break; + } + while (size < tests[cnt].max); + + if (res == 0) + { + printf ("%Zu: %s: res == 0 despite size == %Zu\n", + cnt, tests[cnt].fmt, size); + result = 1; + } + else if (size < tests[cnt].min) + { + printf ("%Zu: %s: size == %Zu was enough\n", + cnt, tests[cnt].fmt, size); + result = 1; + } + else + printf ("%Zu: %s: size == %Zu: OK\n", cnt, tests[cnt].fmt, size); + + free (buf); + } + + return result; +} + diff -uNr dietlibc-0.24/test/time/tst-strptime.c dietlibc-0.25/test/time/tst-strptime.c --- dietlibc-0.24/test/time/tst-strptime.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc-0.25/test/time/tst-strptime.c 2003-12-15 14:07:42.000000000 +0100 @@ -0,0 +1,173 @@ +/* Test for strptime. + Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1998. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#define _XOPEN_SOURCE /* glibc2 needs this */ +#include +#include +#include +#include +#include + + +static const struct +{ + const char *locale; + const char *input; + const char *format; + int wday; + int yday; + int mon; + int mday; +} day_tests[] = +{ + { "C", "2000-01-01", "%Y-%m-%d", 6, 0, 0, 1 }, + { "C", "03/03/00", "%D", 5, 62, 2, 3 }, + { "C", "9/9/99", "%x", 4, 251, 8, 9 }, + { "C", "19990502123412", "%Y%m%d%H%M%S", 0, 121, 4, 2 }, + { "C", "2001 20 Mon", "%Y %U %a", 1, 140, 4, 21 }, + { "C", "2001 21 Mon", "%Y %W %a", 1, 140, 4, 21 }, + { "ja_JP.EUC-JP", "2001 20 \xb7\xee", "%Y %U %a", 1, 140, 4, 21 }, + { "ja_JP.EUC-JP", "2001 21 \xb7\xee", "%Y %W %a", 1, 140, 4, 21 }, +}; + + +static const struct +{ + const char *input; + const char *format; + const char *output; + int wday; + int yday; +} tm_tests [] = +{ + {"17410105012000", "%H%M%S%d%m%Y", "2000-01-05 17:41:01", 3, 4} +}; + + + +static int +test_tm (void) +{ + struct tm tm; + size_t i; + int result = 0; + char buf[100]; + + for (i = 0; i < sizeof (tm_tests) / sizeof (tm_tests[0]); ++i) + { + memset (&tm, '\0', sizeof (tm)); + + if (strptime (tm_tests[i].input, tm_tests[i].format, &tm) != '\0') + { + printf ("not all of `%s' read\n", tm_tests[i].input); + result = 1; + } + strftime (buf, sizeof (buf), "%F %T", &tm); + printf ("strptime (\"%s\", \"%s\", ...)\n" + "\tshould be: %s, wday = %d, yday = %3d\n" + "\t is: %s, wday = %d, yday = %3d\n", + tm_tests[i].input, tm_tests[i].format, + tm_tests[i].output, + tm_tests[i].wday, tm_tests[i].yday, + buf, tm.tm_wday, tm.tm_yday); + + if (strcmp (buf, tm_tests[i].output) != 0) + { + printf ("Time and date are not correct.\n"); + result = 1; + } + if (tm.tm_wday != tm_tests[i].wday) + { + printf ("weekday for `%s' incorrect: %d instead of %d\n", + tm_tests[i].input, tm.tm_wday, tm_tests[i].wday); + result = 1; + } + if (tm.tm_yday != tm_tests[i].yday) + { + printf ("yearday for `%s' incorrect: %d instead of %d\n", + tm_tests[i].input, tm.tm_yday, tm_tests[i].yday); + result = 1; + } + } + + return result; +} + + +int main (void) { + struct tm tm; + size_t i; + int result = 0; + + for (i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i) + { + memset (&tm, '\0', sizeof (tm)); + + if (setlocale (LC_ALL, day_tests[i].locale) == NULL) + { + printf ("cannot set locale %s: %m\n", day_tests[i].locale); + } + + if (*strptime (day_tests[i].input, day_tests[i].format, &tm) != '\0') + { + printf ("not all of `%s' read\n", day_tests[i].input); + result = 1; + } + + printf ("strptime (\"%s\", \"%s\", ...)\n" + "\tshould be: wday = %d, yday = %3d, mon = %2d, mday = %2d\n" + "\t is: wday = %d, yday = %3d, mon = %2d, mday = %2d\n", + day_tests[i].input, day_tests[i].format, + day_tests[i].wday, day_tests[i].yday, + day_tests[i].mon, day_tests[i].mday, + tm.tm_wday, tm.tm_yday, tm.tm_mon, tm.tm_mday); + + if (tm.tm_wday != day_tests[i].wday) + { + printf ("weekday for `%s' incorrect: %d instead of %d\n", + day_tests[i].input, tm.tm_wday, day_tests[i].wday); + result = 1; + } + if (tm.tm_yday != day_tests[i].yday) + { + printf ("yearday for `%s' incorrect: %d instead of %d\n", + day_tests[i].input, tm.tm_yday, day_tests[i].yday); + result = 1; + } + if (tm.tm_mon != day_tests[i].mon) + { + printf ("month for `%s' incorrect: %d instead of %d\n", + day_tests[i].input, tm.tm_mon, day_tests[i].mon); + result = 1; + } + if (tm.tm_mday != day_tests[i].mday) + { + printf ("monthday for `%s' incorrect: %d instead of %d\n", + day_tests[i].input, tm.tm_mday, day_tests[i].mday); + result = 1; + } + } + + setlocale (LC_ALL, "C"); + + result |= test_tm (); + + return result; +} diff -uNr dietlibc-0.24/test/ungetc.c dietlibc-0.25/test/ungetc.c --- dietlibc-0.24/test/ungetc.c 2001-11-13 01:25:11.000000000 +0100 +++ dietlibc-0.25/test/ungetc.c 2003-12-15 14:07:42.000000000 +0100 @@ -1,6 +1,6 @@ #include -main() { +int main() { ungetc(23,stdin); if (fgetc(stdin) != 23) return 1; ungetc(230,stdin); diff -uNr dietlibc-0.24/test/waitpid.c dietlibc-0.25/test/waitpid.c --- dietlibc-0.24/test/waitpid.c 2002-11-09 19:04:03.000000000 +0100 +++ dietlibc-0.25/test/waitpid.c 2003-12-15 14:07:42.000000000 +0100 @@ -3,7 +3,7 @@ #include #include -main() { +int main() { pid_t t; int status; switch (t=fork()) { @@ -17,4 +17,5 @@ } printf("waitpid returned %u\n",waitpid(-1,&status,0)); printf("status was: %d\n",WEXITSTATUS(status)); + return 0; }