diff -urN -x CVS dietlibc-0.31/alpha/strlen.c dietlibc/alpha/strlen.c --- dietlibc-0.31/alpha/strlen.c 2001-01-09 18:57:38.000000000 +0100 +++ dietlibc/alpha/strlen.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,32 +0,0 @@ -#include - -static const unsigned long long magic = 0x0101010101010101LL; - -size_t strlen(const char *s) -{ - const char *t = s; - unsigned long long word; - - if (!s) return 0; - - /* Byte compare up until 64 bit word boundary */ - for (; ((unsigned long long) t & 7); t++) - if (!*t) return t - s; - - /* Word compare */ - do { - word = *((unsigned long long *) t); t += 8; - word = (word - magic) &~ word; - word &= (magic << 7); - } while (word == 0); - - /* word & 0x8080808080808080 == word */ - word = (word - 1) & (magic << 8); - word += (word << 32); - word += (word << 16); - word += (word << 8); - t += word >> 56; - return ((const char *) t) - 8 - s; -} - - diff -urN -x CVS dietlibc-0.31/alpha/syscalls.h dietlibc/alpha/syscalls.h --- dietlibc-0.31/alpha/syscalls.h 2005-09-21 09:33:08.000000000 +0200 +++ dietlibc/alpha/syscalls.h 2008-02-19 01:28:13.000000000 +0100 @@ -380,6 +380,38 @@ #define __NR_inotify_init 444 #define __NR_inotify_add_watch 445 #define __NR_inotify_rm_watch 446 +#define __NR_fdatasync 447 +#define __NR_kexec_load 448 +#define __NR_migrate_pages 449 +#define __NR_openat 450 +#define __NR_mkdirat 451 +#define __NR_mknodat 452 +#define __NR_fchownat 453 +#define __NR_futimesat 454 +#define __NR_fstatat64 455 +#define __NR_unlinkat 456 +#define __NR_renameat 457 +#define __NR_linkat 458 +#define __NR_symlinkat 459 +#define __NR_readlinkat 460 +#define __NR_fchmodat 461 +#define __NR_faccessat 462 +#define __NR_pselect6 463 +#define __NR_ppoll 464 +#define __NR_unshare 465 +#define __NR_set_robust_list 466 +#define __NR_get_robust_list 467 +#define __NR_splice 468 +#define __NR_sync_file_range 469 +#define __NR_tee 470 +#define __NR_vmsplice 471 +#define __NR_move_pages 472 +#define __NR_getcpu 473 +#define __NR_epoll_pwait 474 +#define __NR_utimensat 475 +#define __NR_signalfd 476 +#define __NR_timerfd 477 +#define __NR_eventfd 478 #define syscall_weak(name,wsym,sym) \ diff -urN -x CVS dietlibc-0.31/arm/accept.S dietlibc/arm/accept.S --- dietlibc-0.31/arm/accept.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/accept.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(accept,accept) + +#endif diff -urN -x CVS dietlibc-0.31/arm/__aeabi_unwind_cpp.S dietlibc/arm/__aeabi_unwind_cpp.S --- dietlibc-0.31/arm/__aeabi_unwind_cpp.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/__aeabi_unwind_cpp.S 2008-04-12 00:51:11.000000000 +0200 @@ -0,0 +1,21 @@ +.text +.global __aeabi_unwind_cpp_pr0 +.hidden __aeabi_unwind_cpp_pr0 +.type __aeabi_unwind_cpp_pr0, %function + +.global __aeabi_unwind_cpp_pr1 +.hidden __aeabi_unwind_cpp_pr1 +.type __aeabi_unwind_cpp_pr1, %function + +.global __aeabi_unwind_cpp_pr2 +.hidden __aeabi_unwind_cpp_pr2 +.type __aeabi_unwind_cpp_pr2, %function + +__aeabi_unwind_cpp_pr0: +__aeabi_unwind_cpp_pr1: +__aeabi_unwind_cpp_pr2: + mov pc, lr @ return from subroutine + +.size __aeabi_unwind_cpp_pr0,.-__aeabi_unwind_cpp_pr0 +.size __aeabi_unwind_cpp_pr1,.-__aeabi_unwind_cpp_pr1 +.size __aeabi_unwind_cpp_pr2,.-__aeabi_unwind_cpp_pr2 diff -urN -x CVS dietlibc-0.31/arm/bind.S dietlibc/arm/bind.S --- dietlibc-0.31/arm/bind.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/bind.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(bind,bind) + +#endif diff -urN -x CVS dietlibc-0.31/arm/clone.S dietlibc/arm/clone.S --- dietlibc-0.31/arm/clone.S 2002-02-28 17:27:02.000000000 +0100 +++ dietlibc/arm/clone.S 2008-09-05 17:13:29.000000000 +0200 @@ -10,6 +10,76 @@ @ Some slightly tricky stuff here... edit with care :-) @ + +#ifdef __ARM_EABI__ + +#define CLONE_VM 0x00000100 +#define CLONE_THREAD 0x00010000 + +@ ; don't do this yet +@#define RESET_PID + + +clone: +__clone: + @ ; start with a sanity check + cmp r0, #0 + cmpne r1, #0 + mvneq r0, #-EINVAL + beq __unified_syscall @ handle as if error was returned by the syscall + + @ ; insert args into stack + str r3, [r1, #-4]! + str r0, [r1, #-4]! + + @ ; do the system call + @ ; get the flags + mov r0, r2 +#ifdef RESET_PID + mov ip, r2 +#endif + @ ; child sp is already in r1 + stmfd sp!, {r4, r7} + @stmdb sp!, {r4, r7} + ldr r2, [sp, #8] + ldr r3, [sp, #12] + ldr r4, [sp, #16] + ldr r7, =__NR_clone + swi 0 + + cmp r0, #0 + beq 1f + ldmfd sp!, {r4, r7} + blt __unified_syscall @ (return code < 0): handle as an error + bx lr +1: +#ifdef RESET_PID + tst ip, #CLONE_THREAD + bne 3f + + mov r0, #0xffff0fff + mov lr, pc + sub pc, r0, #31 + mov r1, r0 + tst ip, #CLONE_VM + movne r0, #-1 + ldr r7, =__NR_getpid + swi 0 + str r0, [r1, #PID_OFFSET] @ ; not defined yet ?? + str r0, [r1, #TID_OFFSET] @ ; not defined yet ?? +3: +#endif + @ ; pick the function arg and call address off the stack and execute + ldr r0, [sp, #4] + mov lr, pc + ldr pc, [sp], #8 + + @ ; and we're done, passing return value through r0 + b _exit @ branch to _exit (PIC safe) + + +#else + clone: __clone: movs r12, r0 @ check function pointer @@ -32,3 +102,4 @@ 1: b _exit @ branch to _exit (PIC safe) +#endif diff -urN -x CVS dietlibc-0.31/arm/connect.S dietlibc/arm/connect.S --- dietlibc-0.31/arm/connect.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/connect.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(connect,connect) + +#endif diff -urN -x CVS dietlibc-0.31/arm/dyn_syscalls.S dietlibc/arm/dyn_syscalls.S --- dietlibc-0.31/arm/dyn_syscalls.S 2005-10-08 23:22:09.000000000 +0200 +++ dietlibc/arm/dyn_syscalls.S 2008-07-07 14:31:53.000000000 +0200 @@ -30,6 +30,7 @@ /* ok now include all syscalls.s (*.S) and sysdep *.S */ #include "mmap.S" #include "waitpid.S" +#include "select.S" #include "../syscalls.s/__getpagesize.S" #include "../syscalls.s/__pread.S" @@ -132,7 +133,6 @@ #include "../syscalls.s/sched_setparam.S" #include "../syscalls.s/sched_setscheduler.S" #include "../syscalls.s/sched_yield.S" -#include "../syscalls.s/select.S" #include "../syscalls.s/sendfile.S" #include "../syscalls.s/sendfile64.S" #include "../syscalls.s/setdomainname.S" @@ -289,3 +289,4 @@ #include "__longjmp.S" #include "setjmp.S" +#include "__guard.S" diff -urN -x CVS dietlibc-0.31/arm/getpeername.S dietlibc/arm/getpeername.S --- dietlibc-0.31/arm/getpeername.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/getpeername.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(getpeername,getpeername) + +#endif diff -urN -x CVS dietlibc-0.31/arm/getsockname.S dietlibc/arm/getsockname.S --- dietlibc-0.31/arm/getsockname.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/getsockname.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(getsockname,getsockname) + +#endif diff -urN -x CVS dietlibc-0.31/arm/listen.S dietlibc/arm/listen.S --- dietlibc-0.31/arm/listen.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/listen.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(listen,listen) + +#endif diff -urN -x CVS dietlibc-0.31/arm/Makefile.add dietlibc/arm/Makefile.add --- dietlibc-0.31/arm/Makefile.add 2002-05-09 03:05:10.000000000 +0200 +++ dietlibc/arm/Makefile.add 2008-09-05 17:13:29.000000000 +0200 @@ -1,5 +1,8 @@ -LIBOBJ+=$(OBJDIR)/md5asm.o -CFLAGS+=-Os -fomit-frame-pointer -fstrict-aliasing -mhard-float +LIBOBJ+=$(OBJDIR)/md5asm.o $(OBJDIR)/__aeabi_unwind_cpp.o +CFLAGS+=-Os -fomit-frame-pointer -fstrict-aliasing +#ifdef __ARM_EABI__ +CFLAGS+=-mabi=aapcs-linux -mfloat-abi=soft -mno-thumb-interwork +#endif VPATH:=arm:syscalls.s:$(VPATH) LIBGMON_OBJS+=$(OBJDIR)/mcount.o diff -urN -x CVS dietlibc-0.31/arm/md5asm.S dietlibc/arm/md5asm.S --- dietlibc-0.31/arm/md5asm.S 2002-03-08 11:56:15.000000000 +0100 +++ dietlibc/arm/md5asm.S 2008-09-05 17:13:29.000000000 +0200 @@ -57,8 +57,12 @@ .global MD5Update .text +#ifdef __ARM_EABI__ + .align 4 +#else .align 2 - +#endif + @ -- @ void MD5Init (MD5_CTX* context); @ -- diff -urN -x CVS dietlibc-0.31/arm/mmap.S dietlibc/arm/mmap.S --- dietlibc-0.31/arm/mmap.S 2002-02-18 20:57:39.000000000 +0100 +++ dietlibc/arm/mmap.S 2008-12-02 22:50:42.000000000 +0100 @@ -1,4 +1,3 @@ - #include #include "syscalls.h" @@ -15,6 +14,24 @@ .global mmap +#ifdef __ARM_EABI__ + +mmap: + str r5, [sp, #-4]! + ldr r5, [sp, #8] + str r4, [sp, #-4]! + ldr r4, [sp, #8] + mov ip, r7 + mov r7, #__NR_mmap2 + svc 0x00000000 + mov r7, ip + ldr r4, [sp], #4 + ldr r5, [sp], #4 + cmn r0, #4096 + mov pc, lr @ return + +#else + mmap: stmdb sp!, {r0, r1, r2, r3} mov r0, sp @@ -22,3 +39,4 @@ add sp, sp, #16 b __unified_syscall +#endif diff -urN -x CVS dietlibc-0.31/arm/recvfrom.S dietlibc/arm/recvfrom.S --- dietlibc-0.31/arm/recvfrom.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/recvfrom.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(recvfrom,recvfrom) + +#endif diff -urN -x CVS dietlibc-0.31/arm/recvmsg.S dietlibc/arm/recvmsg.S --- dietlibc-0.31/arm/recvmsg.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/recvmsg.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(recvmsg,recvmsg) + +#endif diff -urN -x CVS dietlibc-0.31/arm/recv.S dietlibc/arm/recv.S --- dietlibc-0.31/arm/recv.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/recv.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(recv,recv) + +#endif diff -urN -x CVS dietlibc-0.31/arm/sendmsg.S dietlibc/arm/sendmsg.S --- dietlibc-0.31/arm/sendmsg.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/sendmsg.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(sendmsg,sendmsg) + +#endif diff -urN -x CVS dietlibc-0.31/arm/send.S dietlibc/arm/send.S --- dietlibc-0.31/arm/send.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/send.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(send,send) + +#endif diff -urN -x CVS dietlibc-0.31/arm/sendto.S dietlibc/arm/sendto.S --- dietlibc-0.31/arm/sendto.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/sendto.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(sendto,sendto) + +#endif diff -urN -x CVS dietlibc-0.31/arm/setjmp.S dietlibc/arm/setjmp.S --- dietlibc-0.31/arm/setjmp.S 2001-07-02 18:06:48.000000000 +0200 +++ dietlibc/arm/setjmp.S 2008-09-05 17:13:29.000000000 +0200 @@ -12,6 +12,6 @@ sfm f4, 4, [r0], #48 #endif stmia r0, {r4-r11, sp, lr} - sub r0, r0, #30 + sub r0, r0, #48 b __sigjmp_save diff -urN -x CVS dietlibc-0.31/arm/setsockopt.S dietlibc/arm/setsockopt.S --- dietlibc-0.31/arm/setsockopt.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/setsockopt.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(setsockopt,setsockopt) + +#endif diff -urN -x CVS dietlibc-0.31/arm/shutdown.S dietlibc/arm/shutdown.S --- dietlibc-0.31/arm/shutdown.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/shutdown.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(shutdown,shutdown) + +#endif diff -urN -x CVS dietlibc-0.31/arm/socketpair.S dietlibc/arm/socketpair.S --- dietlibc-0.31/arm/socketpair.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/socketpair.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(socketpair,socketpair) + +#endif diff -urN -x CVS dietlibc-0.31/arm/socket.S dietlibc/arm/socket.S --- dietlibc-0.31/arm/socket.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/arm/socket.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,7 @@ +#ifdef __ARM_EABI__ + +#include "syscalls.h" + +syscall(socket,socket) + +#endif diff -urN -x CVS dietlibc-0.31/arm/start.S dietlibc/arm/start.S --- dietlibc-0.31/arm/start.S 2006-04-04 07:35:14.000000000 +0200 +++ dietlibc/arm/start.S 2008-09-05 17:13:29.000000000 +0200 @@ -3,12 +3,48 @@ #include "syscalls.h" .text +#ifdef __ARM_EABI__ + .align 4 +#else .align 2 - +#endif + .global _start .weak exit .global _exit + +#ifdef __ARM_EABI__ + +_start: + + mov fp, #0 @ clear the frame pointer + ldr a1, [sp], #4 @ argc + mov a2, sp @ argv + ldr ip, .L3 + add a3, a2, a1, lsl #2 @ &argv[argc] + add a3, a3, #4 @ envp + str a3, [ip, #0] @ environ = envp + bl main + +@ +@ The exit status from main() is already in r0. +@ We need to branch to 'exit' in case we have linked with 'atexit'. +@ + bl exit + +exit: +_exit: + + mov r7, #__NR_exit + swi 0 @ never returns. + +.L3: .word environ + + +#else + + _start: #ifdef WANT_DYNAMIC @@ -72,4 +108,4 @@ #endif - +#endif diff -urN -x CVS dietlibc-0.31/arm/syscalls.h dietlibc/arm/syscalls.h --- dietlibc-0.31/arm/syscalls.h 2007-08-24 23:19:33.000000000 +0200 +++ dietlibc/arm/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -1,5 +1,16 @@ -#define __NR_SYSCALL_BASE 0x900000 +#ifndef _ARM_SYSCALL_H +#define _ARM_SYSCALL_H 1 +#define __NR_OABI_SYSCALL_BASE 0x900000 + +#if defined(__thumb__) || defined(__ARM_EABI__) +#define __NR_SYSCALL_BASE 0 +#else +#define __NR_SYSCALL_BASE __NR_OABI_SYSCALL_BASE +#endif + + +#define __NR_restart_syscall (__NR_SYSCALL_BASE+ 0) #define __NR_exit (__NR_SYSCALL_BASE+ 1) #define __NR_fork (__NR_SYSCALL_BASE+ 2) #define __NR_read (__NR_SYSCALL_BASE+ 3) @@ -126,10 +137,10 @@ #define __NR_adjtimex (__NR_SYSCALL_BASE+124) #define __NR_mprotect (__NR_SYSCALL_BASE+125) #define __NR_sigprocmask (__NR_SYSCALL_BASE+126) -#define __NR_create_module (__NR_SYSCALL_BASE+127) + /* 127 was sys_create_module */ #define __NR_init_module (__NR_SYSCALL_BASE+128) #define __NR_delete_module (__NR_SYSCALL_BASE+129) -#define __NR_get_kernel_syms (__NR_SYSCALL_BASE+130) + /* 130 was sys_get_kernel_syms */ #define __NR_quotactl (__NR_SYSCALL_BASE+131) #define __NR_getpgid (__NR_SYSCALL_BASE+132) #define __NR_fchdir (__NR_SYSCALL_BASE+133) @@ -166,7 +177,7 @@ #define __NR_setresuid (__NR_SYSCALL_BASE+164) #define __NR_getresuid (__NR_SYSCALL_BASE+165) /* 166 was sys_vm86 */ -#define __NR_query_module (__NR_SYSCALL_BASE+167) + /* 167 was sys_query_module */ #define __NR_poll (__NR_SYSCALL_BASE+168) #define __NR_nfsservctl (__NR_SYSCALL_BASE+169) #define __NR_setresgid (__NR_SYSCALL_BASE+170) @@ -179,8 +190,8 @@ #define __NR_rt_sigtimedwait (__NR_SYSCALL_BASE+177) #define __NR_rt_sigqueueinfo (__NR_SYSCALL_BASE+178) #define __NR_rt_sigsuspend (__NR_SYSCALL_BASE+179) -#define __NR_pread (__NR_SYSCALL_BASE+180) -#define __NR_pwrite (__NR_SYSCALL_BASE+181) +#define __NR_pread64 (__NR_SYSCALL_BASE+180) +#define __NR_pwrite64 (__NR_SYSCALL_BASE+181) #define __NR_chown (__NR_SYSCALL_BASE+182) #define __NR_getcwd (__NR_SYSCALL_BASE+183) #define __NR_capget (__NR_SYSCALL_BASE+184) @@ -269,7 +280,7 @@ #define __NR_fstatfs64 (__NR_SYSCALL_BASE+267) #define __NR_tgkill (__NR_SYSCALL_BASE+268) #define __NR_utimes (__NR_SYSCALL_BASE+269) -#define __NR_fadvise64 (__NR_SYSCALL_BASE+270) +#define __NR_arm_fadvise64_64 (__NR_SYSCALL_BASE+270) #define __NR_pciconfig_iobase (__NR_SYSCALL_BASE+271) #define __NR_pciconfig_read (__NR_SYSCALL_BASE+272) #define __NR_pciconfig_write (__NR_SYSCALL_BASE+273) @@ -280,10 +291,38 @@ #define __NR_mq_notify (__NR_SYSCALL_BASE+278) #define __NR_mq_getsetattr (__NR_SYSCALL_BASE+279) #define __NR_waitid (__NR_SYSCALL_BASE+280) - +#define __NR_socket (__NR_SYSCALL_BASE+281) +#define __NR_bind (__NR_SYSCALL_BASE+282) +#define __NR_connect (__NR_SYSCALL_BASE+283) +#define __NR_listen (__NR_SYSCALL_BASE+284) +#define __NR_accept (__NR_SYSCALL_BASE+285) +#define __NR_getsockname (__NR_SYSCALL_BASE+286) +#define __NR_getpeername (__NR_SYSCALL_BASE+287) +#define __NR_socketpair (__NR_SYSCALL_BASE+288) +#define __NR_send (__NR_SYSCALL_BASE+289) +#define __NR_sendto (__NR_SYSCALL_BASE+290) +#define __NR_recv (__NR_SYSCALL_BASE+291) +#define __NR_recvfrom (__NR_SYSCALL_BASE+292) +#define __NR_shutdown (__NR_SYSCALL_BASE+293) +#define __NR_setsockopt (__NR_SYSCALL_BASE+294) +#define __NR_getsockopt (__NR_SYSCALL_BASE+295) +#define __NR_sendmsg (__NR_SYSCALL_BASE+296) +#define __NR_recvmsg (__NR_SYSCALL_BASE+297) +#define __NR_semop (__NR_SYSCALL_BASE+298) +#define __NR_semget (__NR_SYSCALL_BASE+299) +#define __NR_semctl (__NR_SYSCALL_BASE+300) +#define __NR_msgsnd (__NR_SYSCALL_BASE+301) +#define __NR_msgrcv (__NR_SYSCALL_BASE+302) +#define __NR_msgget (__NR_SYSCALL_BASE+303) +#define __NR_msgctl (__NR_SYSCALL_BASE+304) +#define __NR_shmat (__NR_SYSCALL_BASE+305) +#define __NR_shmdt (__NR_SYSCALL_BASE+306) +#define __NR_shmget (__NR_SYSCALL_BASE+307) +#define __NR_shmctl (__NR_SYSCALL_BASE+308) #define __NR_add_key (__NR_SYSCALL_BASE+309) #define __NR_request_key (__NR_SYSCALL_BASE+310) #define __NR_keyctl (__NR_SYSCALL_BASE+311) +#define __NR_semtimedop (__NR_SYSCALL_BASE+312) #define __NR_vserver (__NR_SYSCALL_BASE+313) #define __NR_ioprio_set (__NR_SYSCALL_BASE+314) #define __NR_ioprio_get (__NR_SYSCALL_BASE+315) @@ -293,6 +332,39 @@ #define __NR_mbind (__NR_SYSCALL_BASE+319) #define __NR_get_mempolicy (__NR_SYSCALL_BASE+320) #define __NR_set_mempolicy (__NR_SYSCALL_BASE+321) +#define __NR_openat (__NR_SYSCALL_BASE+322) +#define __NR_mkdirat (__NR_SYSCALL_BASE+323) +#define __NR_mknodat (__NR_SYSCALL_BASE+324) +#define __NR_fchownat (__NR_SYSCALL_BASE+325) +#define __NR_futimesat (__NR_SYSCALL_BASE+326) +#define __NR_fstatat64 (__NR_SYSCALL_BASE+327) +#define __NR_unlinkat (__NR_SYSCALL_BASE+328) +#define __NR_renameat (__NR_SYSCALL_BASE+329) +#define __NR_linkat (__NR_SYSCALL_BASE+330) +#define __NR_symlinkat (__NR_SYSCALL_BASE+331) +#define __NR_readlinkat (__NR_SYSCALL_BASE+332) +#define __NR_fchmodat (__NR_SYSCALL_BASE+333) +#define __NR_faccessat (__NR_SYSCALL_BASE+334) + /* 335 for pselect6 */ + /* 336 for ppoll */ +#define __NR_unshare (__NR_SYSCALL_BASE+337) +#define __NR_set_robust_list (__NR_SYSCALL_BASE+338) +#define __NR_get_robust_list (__NR_SYSCALL_BASE+339) +#define __NR_splice (__NR_SYSCALL_BASE+340) +#define __NR_arm_sync_file_range (__NR_SYSCALL_BASE+341) +#define __NR_tee (__NR_SYSCALL_BASE+342) +#define __NR_vmsplice (__NR_SYSCALL_BASE+343) +#define __NR_move_pages (__NR_SYSCALL_BASE+344) +#define __NR_getcpu (__NR_SYSCALL_BASE+345) + /* 346 for epoll_pwait */ +#define __NR_kexec_load (__NR_SYSCALL_BASE+347) +#define __NR_utimensat (__NR_SYSCALL_BASE+348) +#define __NR_signalfd (__NR_SYSCALL_BASE+349) +#define __NR_timerfd (__NR_SYSCALL_BASE+350) +#define __NR_eventfd (__NR_SYSCALL_BASE+351) +#define __NR_fallocate (__NR_SYSCALL_BASE+352) +#define __NR_timerfd_settime (__NR_SYSCALL_BASE+353) +#define __NR_timerfd_gettime (__NR_SYSCALL_BASE+354) /* * The following SWIs are ARM private. @@ -304,6 +376,25 @@ #define __ARM_NR_usr32 (__ARM_NR_BASE+4) #define __ARM_NR_set_tls (__ARM_NR_BASE+5) +/* + * The following syscalls are obsolete and no longer available for EABI. + */ +#if defined(__ARM_EABI__) && !defined(__KERNEL__) +#undef __NR_time +#undef __NR_umount +#undef __NR_stime +#undef __NR_alarm +#undef __NR_utime +#undef __NR_getrlimit +#undef __NR_select +#undef __NR_readdir +#undef __NR_mmap +#undef __NR_socketcall +#undef __NR_syscall +#undef __NR_ipc +#endif + + /* ok the next few values are for the optimization of the unified syscalls * on arm. * If the syscall has #arguments @@ -597,6 +688,35 @@ #define __ARGS_mq_getsetattr 0 #define __ARGS_waitid 0 +#define __ARGS_socket 0 +#define __ARGS_bind 0 +#define __ARGS_connect 0 +#define __ARGS_listen 0 +#define __ARGS_accept 0 +#define __ARGS_getsockname 0 +#define __ARGS_getpeername 0 +#define __ARGS_socketpair 0 +#define __ARGS_send 0 +#define __ARGS_sendto 0 +#define __ARGS_recv 0 +#define __ARGS_recvfrom 0 +#define __ARGS_shutdown 0 +#define __ARGS_setsockopt 0 +#define __ARGS_getsockopt 0 +#define __ARGS_sendmsg 0 +#define __ARGS_recvmsg 0 +#define __ARGS_semop 0 +#define __ARGS_semget 0 +#define __ARGS_semctl 0 +#define __ARGS_msgsnd 0 +#define __ARGS_msgrcv 0 +#define __ARGS_msgget 0 +#define __ARGS_msgctl 0 +#define __ARGS_shmat 0 +#define __ARGS_shmdt 0 +#define __ARGS_shmget 0 +#define __ARGS_shmctl 0 + #define __ARGS_add_key 1 #define __ARGS_request_key 1 #define __ARGS_keyctl 0 @@ -610,8 +730,80 @@ #define __ARGS_get_mempolicy 1 #define __ARGS_set_mempolicy 1 +#define __ARGS_openat 0 +#define __ARGS_mkdirat 0 +#define __ARGS_mknodat 0 +#define __ARGS_fchownat 1 +#define __ARGS_futimesat 0 +#define __ARGS_fstatat64 0 +#define __ARGS_unlinkat 0 +#define __ARGS_renameat 0 +#define __ARGS_linkat 1 +#define __ARGS_symlinkat 0 +#define __ARGS_readlinkat 0 +#define __ARGS_fchmodat 0 +#define __ARGS_faccessat 0 + /* 335 for pselect6 */ + /* 336 for ppoll */ +#define __ARGS_unshare 0 +#define __ARGS_set_robust_list 0 +#define __ARGS_get_robust_list 0 +#define __ARGS_splice 1 +#define __ARGS_arm_sync_file_range 0 +#define __ARGS_sync_file_range2 0 +#define __ARGS_tee 0 +#define __ARGS_vmsplice 0 +#define __ARGS_move_pages 1 +#define __ARGS_getcpu 0 + /* 346 for epoll_pwait */ +#define __ARGS_kexec_load 0 +#define __ARGS_utimensat 0 +#define __ARGS_signalfd 0 +#define __ARGS_timerfd 0 +#define __ARGS_eventfd 0 +#define __ARGS_fallocate 0 +#define __ARGS_timerfd_settime 0 +#define __ARGS_timerfd_gettime 0 + #ifdef __ASSEMBLER__ + +#ifdef __ARM_EABI__ + +#define syscall_weak(name,wsym,sym) __syscall_weak __NR_##name, wsym, sym, __ARGS_##name +.macro __syscall_weak name wsym sym typ +.text +.type \wsym,function +.weak \wsym +\wsym: +.type \sym,function +.global \sym +\sym: + stmfd sp!,{r4,r5,r7,lr} + ldr r4, [sp,#16] + ldr r5, [sp,#20] + ldr r7, =\name + swi 0 + b __unified_syscall +.endm + + +#define syscall(name,sym) __syscall __NR_##name, sym, __ARGS_##name +.macro __syscall name sym typ +.text +.type \sym,function +.global \sym +\sym: + stmfd sp!,{r4,r5,r7,lr} + ldr r4, [sp,#16] + ldr r5, [sp,#20] + ldr r7, =\name + swi 0 + b __unified_syscall +.endm + +#else + #define syscall_weak(name,wsym,sym) __syscall_weak $__NR_##name, wsym, sym, __ARGS_##name .macro __syscall_weak name wsym sym typ .text @@ -654,3 +846,6 @@ .endm #endif +#endif + +#endif diff -urN -x CVS dietlibc-0.31/arm/unified.S dietlibc/arm/unified.S --- dietlibc-0.31/arm/unified.S 2002-02-28 17:13:20.000000000 +0100 +++ dietlibc/arm/unified.S 2008-09-05 17:13:29.000000000 +0200 @@ -2,11 +2,35 @@ #include .text +#ifdef __ARM_EABI__ + .align 4 +#else .align 2 - +#endif .global __unified_syscall .global __unified_syscall4 + +#ifdef __ARM_EABI__ + +__unified_syscall4: +__unified_syscall: + + cmn r0, #4096 + rsbcs r2, r0, #0 + ldrcs r3, 1f + mvncs r0, #0 + strcs r2, [r3] + ldmfd sp!,{r4,r5,r7,pc} + .balign 4 +1: + .word errno + +/* here we go and "reuse" the return for weak-void functions */ +#include "dietuglyweaks.h" + +#else + __unified_syscall4: ldmia sp!, {r4, r5, r6} __unified_syscall: @@ -32,3 +56,5 @@ #ifndef WANT_THREAD_SAFE .L0: .long errno #endif + +#endif diff -urN -x CVS dietlibc-0.31/arm/waitpid.S dietlibc/arm/waitpid.S --- dietlibc-0.31/arm/waitpid.S 2004-11-30 17:26:20.000000000 +0100 +++ dietlibc/arm/waitpid.S 2008-09-05 17:13:29.000000000 +0200 @@ -1,5 +1,9 @@ .text +#ifdef __ARM_EABI__ +.align 4 +#else .align 2 +#endif .weak waitpid .type waitpid, %function waitpid: diff -urN -x CVS dietlibc-0.31/CHANGES dietlibc/CHANGES --- dietlibc-0.31/CHANGES 2007-08-03 22:58:33.000000000 +0200 +++ dietlibc/CHANGES 2009-03-17 00:17:58.000000000 +0100 @@ -1,3 +1,32 @@ +0.32: + add mbsinit, mbrlen, mbtowc, wctomb, mbrtowc, wcrtomb, wcwidth + add btowc, wctype, iswctype + add some wide char routines + add statvfs, fstatvfs + add some amd64 asm string routines + add some constants for inotify + several fixes from Enrico Scholz (printf, string routines on big endian) + add some more syscalls + some minor cleanups + shrink some string functions (Kris Katterjohn) + prepare x86_64 for syscall numbers > 255 + fix unaligned memcpy if WANT_SMALL_STRING_ROUTINES is not defined + (Enrico Scholz) + fix utmp, add utmpx support (R.L. Horn) + fix the dynamic library for the ARM architecture (Gernot Tenchio) + get ARM port to work with EABI (Tristan Newby) + fix of scanf with negative floats (Andre Oliveira) + use vsyscall to do time(2) on x86-64 + implement back references in basic regexes + make regex faster (coalesce n CHAR matches to one STRING match) + stdio speedup + use randomness passed in ELF auxvec instead of /dev/urandom in startup + (strace looks cleaner now) + use ELF auxvec to implement getpagesize + support thread local storage (w00t!!!!) + don't crash in getaddrinfo if hints is NULL (Gernot Tenchio) + add -D_REENTRANT for -pthread in diet + 0.31: getopt_long and getopt_long_only now refuse ambiguous abbreviations fix printf %u/%x on 64-bit platforms diff -urN -x CVS dietlibc-0.31/contrib/debug-realloc.c dietlibc/contrib/debug-realloc.c --- dietlibc-0.31/contrib/debug-realloc.c 2002-04-24 00:04:58.000000000 +0200 +++ dietlibc/contrib/debug-realloc.c 2007-11-18 01:59:08.000000000 +0100 @@ -1,15 +1,32 @@ #include #include +#include +#ifdef DEBUG +#include +#endif static struct malloced { unsigned long len,maplen; struct malloced* next; + unsigned long magic; }* root=0; -void* malloc(size_t size) { +static const unsigned long MAGIC=(unsigned long)0xfefec0dedeadbeefull; + +static void checkmagic() { + struct malloced* x=root; + while (x) { + if (x->magic != MAGIC) + abort(); + x=x->next; + } +} + +static void* domalloc(size_t size) { char* n,* m; unsigned long s=size+sizeof(struct malloced); - s=(s+4096+4095)&~4095; + checkmagic(); + s=(s+4096+4095)&~4095; // add one page, and round up to fill one page n=mmap(0,s,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); if (n==MAP_FAILED) return 0; m=n-size; while (mlen=size; ((struct malloced*)n)->maplen=s; ((struct malloced*)n)->next=root; + ((struct malloced*)n)->magic=MAGIC; root=(struct malloced*)n; return m; } -void free(void* ptr) { +void* malloc(size_t size) { + void* m=domalloc(size);; +#ifdef DEBUG + printf("malloc(%zu) -> %p\n",size,m); +#endif + return m; +} + +static void dofree(void* ptr) { struct malloced** x=&root; + checkmagic(); while (*x) { if (((char*)(*x))+sizeof(struct malloced)<(char*)ptr && ((char*)(*x))+4096>(char*)ptr) { @@ -37,22 +64,35 @@ abort(); } +void free(void* ptr) { +#ifdef DEBUG + printf("free(%p)\n",ptr); +#endif + dofree(ptr); +} + void *realloc(void *ptr, size_t size) { unsigned long oldsize=0; - struct malloced** x=&root; + struct malloced* x=root; char* fnord; if (ptr) { - while (*x) { - if (((char*)(*x))+sizeof(struct malloced)<(char*)ptr && - ((char*)(*x))+4096>(char*)ptr) { - oldsize=(*x)->len; + oldsize=-1; + while (x) { + if (((char*)x)+sizeof(struct malloced)<(char*)ptr && + ((char*)x)+4096>(char*)ptr) { + oldsize=x->len; break; } - x=&(*x)->next; + x=x->next; } + if (oldsize==(unsigned long)-1) + abort(); } - fnord=malloc(size); + fnord=domalloc(size); memcpy(fnord,ptr,size>oldsize?oldsize:size); - if (oldsize) free(ptr); + if (oldsize) dofree(ptr); +#ifdef DEBUG + printf("realloc(%p,%zu) -> %p\n",ptr,size,fnord); +#endif return fnord; } diff -urN -x CVS dietlibc-0.31/contrib/dnsd.c dietlibc/contrib/dnsd.c --- dietlibc-0.31/contrib/dnsd.c 2007-01-31 22:09:18.000000000 +0100 +++ dietlibc/contrib/dnsd.c 2008-09-30 23:02:35.000000000 +0200 @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -26,12 +26,82 @@ struct sockaddr_in mysa4; struct sockaddr_in6 mysa6; +struct msghdr mh; + +static int scan_fromhex(unsigned char c) { + c-='0'; + if (c<=9) return c; + c&=~0x20; + c-='A'-'0'; + if (c<6) return c+10; + return -1; +/* more readable but creates worse code: + if (c>='0' && c<='9') + return c-'0'; + else if (c>='A' && c<='F') + return c-'A'+10; + else if (c>='a' && c<='f') + return c-'a'+10; + return -1; +*/ +} + +static void getip(int interface) { + int fd; + struct cmsghdr* x; + memset(&mysa4,0,sizeof(mysa4)); + memset(&mysa6,0,sizeof(mysa6)); + for (x=CMSG_FIRSTHDR(&mh); x; x=CMSG_NXTHDR(&mh,x)) + if (x->cmsg_level==SOL_IP && x->cmsg_type==IP_PKTINFO) + mysa4.sin_addr=((struct in_pktinfo*)(CMSG_DATA(x)))->ipi_spec_dst; + + fd=open("/proc/net/if_inet6",O_RDONLY); + if (fd!=-1) { + char buf[1024]; /* increase as necessary */ + int i,j,len; + len=read(fd,buf,sizeof buf); + if (len>0) { + int ok; + char* c=buf; + char* max=buf+len; + ok=0; + /* "fec000000000000102c09ffffe53fc52 01 40 40 00 eth0" */ + while (c='0' && c<='9') - return c-'0'; - else if (c>='A' && c<='F') - return c-'A'+10; - else if (c>='a' && c<='f') - return c-'a'+10; - return -1; -} - -static void getip(int interface) { - int fd; - struct cmsghdr* x; - memset(&mysa4,0,sizeof(mysa4)); - memset(&mysa6,0,sizeof(mysa6)); - for (x=CMSG_FIRSTHDR(&mh); x; x=CMSG_NXTHDR(&mh,x)) - if (x->cmsg_level==SOL_IP && x->cmsg_type==IP_PKTINFO) - mysa4.sin_addr=((struct in_pktinfo*)(CMSG_DATA(x)))->ipi_spec_dst; - - fd=open("/proc/net/if_inet6",O_RDONLY); - if (fd!=-1) { - char buf[1024]; /* increase as necessary */ - int i,j,len; - len=read(fd,buf,sizeof buf); - if (len>0) { - int ok; - char* c=buf; - char* max=buf+len; - ok=0; - /* "fec000000000000102c09ffffe53fc52 01 40 40 00 eth0" */ - while (c4) || ((__GNUC__==4) && (__GNUC_MINOR__>=1)) #define WANT_SSP #endif -/* Choose which canary seeder you want you can choose - * both but it will check urandom first and use xor as - * a fallback. xor is lighter but weaker */ -#define WANT_SSP_URANDOM -/* The XOR seeder is completely predictable and should not be used - * unless you don't have a /dev/urandom, and even then it's a bad idea. */ -/* #define WANT_SSP_XOR */ - diff -urN -x CVS dietlibc-0.31/dietstring.h dietlibc/dietstring.h --- dietlibc-0.31/dietstring.h 2003-12-21 13:06:36.000000000 +0100 +++ dietlibc/dietstring.h 2008-02-19 01:28:13.000000000 +0100 @@ -11,6 +11,16 @@ # define STRALIGN(x) (((unsigned long)x&3)?4-((unsigned long)x&3):0) #endif +/* GFC(x) - returns first character */ +/* INCSTR(x) - moves to next character */ +#if __BYTE_ORDER == __LITTLE_ENDIAN +# define GFC(x) ((x)&0xff) +# define INCSTR(x) do { x >>= 8; } while (0) +#else +# define GFC(x) (((x)>>(sizeof(x)*8-8))&0xff) +# define INCSTR(x) do { x <<= 8; } while (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 -urN -x CVS dietlibc-0.31/dyn_start.c dietlibc/dyn_start.c --- dietlibc-0.31/dyn_start.c 2005-09-21 09:33:08.000000000 +0200 +++ dietlibc/dyn_start.c 2008-04-12 00:51:11.000000000 +0200 @@ -67,8 +67,11 @@ { int main(int argc, char **argv, char **envp); +#ifndef __arm__ + /* GT: segfaults on arm, don't know why (for now) */ void _dl_aux_init_from_envp(char **envp); _dl_aux_init_from_envp(envp); +#endif if (dl_init) atexit(dl_init); _init(); diff -urN -x CVS dietlibc-0.31/FAQ dietlibc/FAQ --- dietlibc-0.31/FAQ 2007-04-02 07:31:53.000000000 +0200 +++ dietlibc/FAQ 2008-08-30 15:59:17.000000000 +0200 @@ -331,3 +331,14 @@ diet-dyn gcc -Wl,--hash-style=sysv -shared -o libx.so x.c ^^^^^^^^^^^^^^^^^^^^^ + +Q: How do I compile OpenSSL with dietlibc? +A: Here's how I do it: + + ./config --prefix=/opt/diet no-dso + make libssl.pc openssl.pc + for i in libssl.pc openssl.pc Makefile; do (echo ",s/ *-ldl//g"; echo w) | ed $i; done + make CC="diet -Os gcc -pipe -nostdinc" + +Then the libraries go to /opt/diet/lib, so you still need a symlink to +lib-i386 or whatever your architecture is. diff -urN -x CVS dietlibc-0.31/i386/dyn_syscalls.S dietlibc/i386/dyn_syscalls.S --- dietlibc-0.31/i386/dyn_syscalls.S 2006-10-13 22:11:13.000000000 +0200 +++ dietlibc/i386/dyn_syscalls.S 2008-12-27 20:53:16.000000000 +0100 @@ -349,6 +349,9 @@ #include "../syscalls.s/lgetxattr.S" #include "../syscalls.s/fgetxattr.S" +#include "../syscalls.s/timerfd.S" +#include "../syscalls.s/__signalfd.S" + #undef __PIC__ #undef __socketcall /* oh what a kludge! */ diff -urN -x CVS dietlibc-0.31/i386/syscalls.h dietlibc/i386/syscalls.h --- dietlibc-0.31/i386/syscalls.h 2007-01-10 23:51:09.000000000 +0100 +++ dietlibc/i386/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -318,6 +318,13 @@ #define __NR_move_pages 317 #define __NR_getcpu 318 #define __NR_epoll_pwait 319 +#define __NR_utimensat 320 +#define __NR_signalfd 321 +#define __NR_timerfd 322 +#define __NR_eventfd 323 +#define __NR_fallocate 324 +#define __NR_timerfd_settime 325 +#define __NR_timerfd_gettime 326 #define syscall_weak(name,wsym,sym) \ diff -urN -x CVS dietlibc-0.31/ia64/syscalls.h dietlibc/ia64/syscalls.h --- dietlibc-0.31/ia64/syscalls.h 2006-09-19 00:08:39.000000000 +0200 +++ dietlibc/ia64/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -279,7 +279,16 @@ #define __NR_sync_file_range 1300 #define __NR_tee 1301 #define __NR_vmsplice 1302 - +#define __NR_fallocate 1303 +#define __NR_getcpu 1304 +#define __NR_epoll_pwait 1305 +#define __NR_utimensat 1306 +#define __NR_signalfd 1307 +#define __NR_timerfd 1308 +#define __NR_eventfd 1309 +#define __NR_timerfd_create 1310 +#define __NR_timerfd_settime 1311 +#define __NR_timerfd_gettime 1312 #define syscall(name, sym) \ .text; \ diff -urN -x CVS dietlibc-0.31/include/elf.h dietlibc/include/elf.h --- dietlibc-0.31/include/elf.h 2006-11-08 16:14:27.000000000 +0100 +++ dietlibc/include/elf.h 2008-09-05 17:13:29.000000000 +0200 @@ -2078,6 +2078,7 @@ #define EF_ARM_EABI_UNKNOWN 0x00000000 #define EF_ARM_EABI_VER1 0x01000000 #define EF_ARM_EABI_VER2 0x02000000 +#define EF_ARM_EABI_VER4 0x04000000 /* Additional symbol types for Thumb */ #define STT_ARM_TFUNC 0xd diff -urN -x CVS dietlibc-0.31/include/fcntl.h dietlibc/include/fcntl.h --- dietlibc-0.31/include/fcntl.h 2005-10-04 19:47:03.000000000 +0200 +++ dietlibc/include/fcntl.h 2008-02-19 01:28:13.000000000 +0100 @@ -624,9 +624,51 @@ #endif #if defined(_LINUX_SOURCE) || defined(_GNU_SOURCE) -ssize_t readahead(int fd, off64_t *offset, size_t count); +ssize_t readahead(int fd, off64_t *offset, size_t count) __THROW; #endif +#ifdef _GNU_SOURCE +#define SPLICE_F_MOVE (0x01) /* move pages instead of copying */ +#define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */ + /* we may still block on the fd we splice */ + /* from/to, of course */ +#define SPLICE_F_MORE (0x04) /* expect more data */ +#define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */ + +long tee(int fd_in, int fd_out, size_t len, unsigned int flags) __THROW; + +#include + +long vmsplice(int fd, const struct iovec *iov, unsigned long nr_segs, unsigned int flags) __THROW; +long splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags) __THROW; + +int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags) __THROW; +#endif + +#ifdef _ATFILE_SOURCE +#define AT_FDCWD -100 /* Special value used to indicate openat should use the current working directory. */ +#define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */ +#define AT_REMOVEDIR 0x200 /* Remove directory instead of unlinking file. */ +#define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */ + +int openat(int dirfd, const char *pathname, int flags, ...); +int faccessat(int dirfd, const char *pathname, int mode, int flags); +int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags); +int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags); +int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags); +int futimesat(int dirfd, const char *pathname, const struct timeval times[2]); +int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags); +int mkdirat(int dirfd, const char *pathname, mode_t mode); +int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev); +int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz); +int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); +int symlinkat(const char *oldpath, int newdirfd, const char *newpath); +int unlinkat(int dirfd, const char *pathname, int flags); +int mkfifoat(int dirfd, const char *pathname, mode_t mode); +int utimensat(int dirfd, const char *pathname, struct timespec* t); +#endif + + __END_DECLS #endif diff -urN -x CVS dietlibc-0.31/include/linux/eventpoll.h dietlibc/include/linux/eventpoll.h --- dietlibc-0.31/include/linux/eventpoll.h 2003-08-19 18:58:18.000000000 +0200 +++ dietlibc/include/linux/eventpoll.h 2008-02-20 01:45:11.000000000 +0100 @@ -3,7 +3,7 @@ #include #include -#include +#include #include __BEGIN_DECLS diff -urN -x CVS dietlibc-0.31/include/netinet/in.h dietlibc/include/netinet/in.h --- dietlibc-0.31/include/netinet/in.h 2005-09-21 09:33:08.000000000 +0200 +++ dietlibc/include/netinet/in.h 2008-02-19 01:28:13.000000000 +0100 @@ -350,6 +350,7 @@ /* fnord */ #define IPPORT_RESERVED 1024 +#define INET_ADDRSTRLEN 16 #define INET6_ADDRSTRLEN 46 #undef htonl diff -urN -x CVS dietlibc-0.31/include/paths.h dietlibc/include/paths.h --- dietlibc-0.31/include/paths.h 2005-04-26 19:47:18.000000000 +0200 +++ dietlibc/include/paths.h 2008-02-23 01:09:54.000000000 +0100 @@ -26,4 +26,14 @@ #define _PATH_TMP "/tmp/" +#define _PATH_UTMP "/var/run/utmp" +#define _PATH_WTMP "/var/log/wtmp" +#ifdef _BSD_SOURCE +/* die, BSD, die!!! */ +#define UTMP_FILE _PATH_UTMP +#define WTMP_FILE _PATH_WTMP +#endif +#define _PATH_UTMPX _PATH_UTMP +#define _PATH_WTMPX _PATH_WTMP + #endif diff -urN -x CVS dietlibc-0.31/include/poll.h dietlibc/include/poll.h --- dietlibc-0.31/include/poll.h 2003-03-14 17:42:28.000000000 +0100 +++ dietlibc/include/poll.h 2008-02-20 01:47:08.000000000 +0100 @@ -1,3 +1,58 @@ -/* ah, the sublime brokenness... susv3 defines poll.h, the Linux man - * page defines sys/poll.h; duh! */ -#include +#ifndef _POLL_H +#define _POLL_H + +#include + +__BEGIN_DECLS + +enum { + POLLIN = 0x0001, +#define POLLIN POLLIN + POLLPRI = 0x0002, +#define POLLPRI POLLPRI + POLLOUT = 0x0004, +#define POLLOUT POLLOUT + POLLERR = 0x0008, +#define POLLERR POLLERR + POLLHUP = 0x0010, +#define POLLHUP POLLHUP + POLLNVAL = 0x0020, +#define POLLNVAL POLLNVAL + POLLRDNORM = 0x0040, +#define POLLRDNORM POLLRDNORM + POLLRDBAND = 0x0080, +#define POLLRDBAND POLLRDBAND + POLLWRBAND = 0x0200, +#define POLLWRBAND POLLWRBAND + POLLMSG = 0x0400, +#define POLLMSG POLLMSG +/* POLLREMOVE is for /dev/epoll (/dev/misc/eventpoll), + * a new event notification mechanism for 2.6 */ + POLLREMOVE = 0x1000, +#define POLLREMOVE POLLREMOVE +}; + +#if defined(__sparc__) || defined (__mips__) +#define POLLWRNORM POLLOUT +#else +#define POLLWRNORM 0x0100 +#endif + +struct pollfd { + int fd; + short events; + short revents; +}; + +typedef unsigned int nfds_t; + +extern int poll(struct pollfd *ufds, nfds_t nfds, int timeout) __THROW; + +#ifdef _GNU_SOURCE +#include +int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *sigmask) __THROW; +#endif + +__END_DECLS + +#endif /* _POLL_H */ diff -urN -x CVS dietlibc-0.31/include/resolv.h dietlibc/include/resolv.h --- dietlibc-0.31/include/resolv.h 2006-07-05 08:27:18.000000000 +0200 +++ dietlibc/include/resolv.h 2008-09-30 23:02:35.000000000 +0200 @@ -119,8 +119,8 @@ int length, unsigned char **dnptrs, unsigned char *exp_dn, unsigned char **lastdnptr) __THROW; -int dn_expand(unsigned char *msg, unsigned char *eomorig, - unsigned char *comp_dn, unsigned char *exp_dn, +int dn_expand(const unsigned char *msg, const unsigned char *eomorig, + const unsigned char *comp_dn, unsigned char *exp_dn, int length) __THROW; void res_close(void) __THROW __attribute_dontuse__; diff -urN -x CVS dietlibc-0.31/include/sched.h dietlibc/include/sched.h --- dietlibc-0.31/include/sched.h 2003-08-19 18:58:17.000000000 +0200 +++ dietlibc/include/sched.h 2008-02-19 01:28:13.000000000 +0100 @@ -7,24 +7,6 @@ __BEGIN_DECLS /* - * cloning flags: - */ -#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */ -#define CLONE_VM 0x00000100 /* set if VM shared between processes */ -#define CLONE_FS 0x00000200 /* set if fs info shared between processes */ -#define CLONE_FILES 0x00000400 /* set if open files shared between processes */ -#define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */ -#define CLONE_PID 0x00001000 /* set if pid shared */ -#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */ -#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */ -#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */ -#define CLONE_THREAD 0x00010000 /* Same thread group? */ - -#define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD) - -int clone(void*(*fn)(void*),void*stack,int flags,void*arg); - -/* * Scheduling policies */ #define SCHED_OTHER 0 @@ -67,6 +49,28 @@ int __sched_rr_get_interval(pid_t pid, struct timespec* tp); int sched_rr_get_interval(pid_t pid, struct timespec* tp); +#ifdef _GNU_SOURCE +/* + * cloning flags: + */ +#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */ +#define CLONE_VM 0x00000100 /* set if VM shared between processes */ +#define CLONE_FS 0x00000200 /* set if fs info shared between processes */ +#define CLONE_FILES 0x00000400 /* set if open files shared between processes */ +#define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */ +#define CLONE_PID 0x00001000 /* set if pid shared */ +#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */ +#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */ +#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */ +#define CLONE_THREAD 0x00010000 /* Same thread group? */ + +#define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD) + +int clone(void*(*fn)(void*),void*stack,int flags,void*arg); + +int unshare(int flags); +#endif + __END_DECLS #endif diff -urN -x CVS dietlibc-0.31/include/stdarg.h dietlibc/include/stdarg.h --- dietlibc-0.31/include/stdarg.h 2003-08-19 18:58:17.000000000 +0200 +++ dietlibc/include/stdarg.h 2008-11-26 19:43:06.000000000 +0100 @@ -9,7 +9,7 @@ #if (__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 96)) typedef __builtin_va_list va_list; -#define va_start(v,l) __builtin_stdarg_start((v),l) +#define va_start(v,l) __builtin_va_start((v),(l)) #define va_end __builtin_va_end #define va_arg __builtin_va_arg #define __va_copy(d,s) __builtin_va_copy((d),(s)) diff -urN -x CVS dietlibc-0.31/include/stdlib.h dietlibc/include/stdlib.h --- dietlibc-0.31/include/stdlib.h 2006-07-04 05:33:02.000000000 +0200 +++ dietlibc/include/stdlib.h 2007-09-20 20:51:18.000000000 +0200 @@ -111,6 +111,11 @@ int clearenv(void); #endif +int mbtowc(wchar_t *pwc, const char *s, size_t n) __THROW; +int wctomb(char *s, wchar_t wc) __THROW; +size_t mbstowcs(wchar_t *dest, const char *src, size_t n) __THROW; +int mblen(const char* s,size_t n) __THROW __pure; + __END_DECLS #endif diff -urN -x CVS dietlibc-0.31/include/sys/cdefs.h dietlibc/include/sys/cdefs.h --- dietlibc-0.31/include/sys/cdefs.h 2005-10-04 19:47:03.000000000 +0200 +++ dietlibc/include/sys/cdefs.h 2008-05-09 06:36:56.000000000 +0200 @@ -31,6 +31,7 @@ #if __GNUC__ < 3 #define __builtin_expect(foo,bar) (foo) #define __expect(foo,bar) (foo) +#define __malloc__ #else #define __expect(foo,bar) __builtin_expect((long)(foo),bar) #define __attribute_malloc__ __attribute__((__malloc__)) @@ -74,6 +75,7 @@ # define __attribute_used __attribute__ ((__used__)) #else # define __attribute_used +# define __warn_unused_result__ #endif #if (__GNUC__ >= 4) @@ -83,4 +85,10 @@ #define __sentinel__ #endif +#if (__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) +# define __cold__ +# define __hot__ +#endif + + #endif diff -urN -x CVS dietlibc-0.31/include/sys/epoll.h dietlibc/include/sys/epoll.h --- dietlibc-0.31/include/sys/epoll.h 2005-03-15 09:51:22.000000000 +0100 +++ dietlibc/include/sys/epoll.h 2008-02-20 01:45:12.000000000 +0100 @@ -3,7 +3,8 @@ #include #include -#include +#include +#include __BEGIN_DECLS @@ -65,6 +66,8 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) __THROW; int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) __THROW; +int epoll_pwait(int epfd, struct epoll_event *events, int maxevents, + int timeout, const sigset_t* sigmask) __THROW; __END_DECLS diff -urN -x CVS dietlibc-0.31/include/sys/inotify.h dietlibc/include/sys/inotify.h --- dietlibc-0.31/include/sys/inotify.h 2005-10-04 19:47:03.000000000 +0200 +++ dietlibc/include/sys/inotify.h 2008-02-19 01:28:13.000000000 +0100 @@ -2,13 +2,14 @@ #define _SYS_INOTIFY_H #include +#include struct inotify_event { - __s32 wd; /* watch descriptor */ - __u32 mask; /* watch mask */ - __u32 cookie; /* cookie to synchronize two events */ - __u32 len; /* length (including nulls) of name */ - char name[0]; /* stub for possible name */ + int32_t wd; /* watch descriptor */ + uint32_t mask, /* watch mask */ + cookie, /* cookie to synchronize two events */ + len; /* length (including nulls) of name */ + char name[0]; /* stub for possible name */ }; /* the following are legal, implemented events that user-space can watch for */ @@ -35,6 +36,9 @@ #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */ /* special flags */ +#define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */ +#define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */ +#define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */ #define IN_ISDIR 0x40000000 /* event occurred against dir */ #define IN_ONESHOT 0x80000000 /* only send event once */ diff -urN -x CVS dietlibc-0.31/include/sys/mman.h dietlibc/include/sys/mman.h --- dietlibc-0.31/include/sys/mman.h 2005-04-25 09:22:24.000000000 +0200 +++ dietlibc/include/sys/mman.h 2007-10-09 01:15:27.000000000 +0200 @@ -26,6 +26,7 @@ #define MAP_DENYWRITE 0x2000 /* ETXTBSY */ #define MAP_EXECUTABLE 0x4000 /* mark it as an executable */ #define MAP_LOCKED 0x8000 /* pages are locked */ +#define MAP_POPULATE 0x10000 #define MS_ASYNC 0x0001 /* sync memory asynchronously */ #define MS_INVALIDATE 0x0002 /* invalidate mappings & caches */ #define MS_SYNC 0x0004 /* synchronous memory sync */ @@ -44,6 +45,7 @@ #define MAP_EXECUTABLE 0x4000 /* mark it as an executable */ #define MAP_LOCKED 0x8000 /* lock the mapping */ #define MAP_NORESERVE 0x10000 /* don't check for reservations */ +#define MAP_POPULATE 0x20000 #define MS_ASYNC 1 /* sync memory asynchronously */ #define MS_SYNC 2 /* synchronous memory sync */ #define MS_INVALIDATE 4 /* invalidate the caches */ @@ -63,6 +65,7 @@ #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */ #define MAP_LOCKED 0x2000 /* pages are locked */ #define MAP_NORESERVE 0x4000 /* don't check for reservations */ +#define MAP_POPULATE 0x8000 #define MS_ASYNC 1 /* sync memory asynchronously */ #define MS_INVALIDATE 2 /* invalidate the caches */ #define MS_SYNC 4 /* synchronous memory sync */ @@ -84,6 +87,7 @@ #define MAP_GROWSDOWN 0x0100 /* stack-like segment */ #define MAP_DENYWRITE 0x0800 /* ETXTBSY */ #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */ +#define MAP_POPULATE 0x8000 #define MS_ASYNC 1 /* sync memory asynchronously */ #define MS_INVALIDATE 2 /* invalidate the caches */ #define MS_SYNC 4 /* synchronous memory sync */ @@ -103,6 +107,7 @@ #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */ #define MAP_LOCKED 0x2000 /* pages are locked */ #define MAP_NORESERVE 0x4000 /* don't check for reservations */ +#define MAP_POPULATE 0x8000 #define MS_ASYNC 1 /* sync memory asynchronously */ #define MS_INVALIDATE 2 /* invalidate the caches */ #define MS_SYNC 4 /* synchronous memory sync */ @@ -124,6 +129,7 @@ #define MAP_LOCKED 0x2000 /* pages are locked */ #define MAP_NORESERVE 0x4000 /* don't check for reservations */ #define MAP_GROWSDOWN 0x8000 /* stack-like segment */ +#define MAP_POPULATE 0x10000 #define MS_SYNC 1 /* synchronous memory sync */ #define MS_ASYNC 2 /* sync memory asynchronously */ @@ -160,6 +166,7 @@ #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */ #define MAP_LOCKED 0x2000 /* pages are locked */ #define MAP_NORESERVE 0x4000 /* don't check for reservations */ +#define MAP_POPULATE 0x8000 #define MAP_WRITECOMBINED 0x10000 /* write-combine the area */ #define MAP_NONCACHED 0x20000 /* don't cache the memory */ diff -urN -x CVS dietlibc-0.31/include/sys/poll.h dietlibc/include/sys/poll.h --- dietlibc-0.31/include/sys/poll.h 2003-08-19 18:58:18.000000000 +0200 +++ dietlibc/include/sys/poll.h 2008-02-20 01:45:12.000000000 +0100 @@ -1,51 +1,8 @@ +/* ah, the sublime brokenness... susv3 defines poll.h, the Linux man + * page defines sys/poll.h; duh! */ #ifndef _SYS_POLL_H #define _SYS_POLL_H -#include +#include -__BEGIN_DECLS - -enum { - POLLIN = 0x0001, -#define POLLIN POLLIN - POLLPRI = 0x0002, -#define POLLPRI POLLPRI - POLLOUT = 0x0004, -#define POLLOUT POLLOUT - POLLERR = 0x0008, -#define POLLERR POLLERR - POLLHUP = 0x0010, -#define POLLHUP POLLHUP - POLLNVAL = 0x0020, -#define POLLNVAL POLLNVAL - POLLRDNORM = 0x0040, -#define POLLRDNORM POLLRDNORM - POLLRDBAND = 0x0080, -#define POLLRDBAND POLLRDBAND - POLLWRBAND = 0x0200, -#define POLLWRBAND POLLWRBAND - POLLMSG = 0x0400, -#define POLLMSG POLLMSG -/* POLLREMOVE is for /dev/epoll (/dev/misc/eventpoll), - * a new event notification mechanism for 2.6 */ - POLLREMOVE = 0x1000, -#define POLLREMOVE POLLREMOVE -}; - -#if defined(__sparc__) || defined (__mips__) -#define POLLWRNORM POLLOUT -#else -#define POLLWRNORM 0x0100 #endif - -struct pollfd { - int fd; - short events; - short revents; -}; - -extern int poll(struct pollfd *ufds, unsigned int nfds, int timeout) __THROW; - -__END_DECLS - -#endif /* _SYS_POLL_H */ diff -urN -x CVS dietlibc-0.31/include/sys/signalfd.h dietlibc/include/sys/signalfd.h --- dietlibc-0.31/include/sys/signalfd.h 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/include/sys/signalfd.h 2008-02-19 01:28:13.000000000 +0100 @@ -0,0 +1,33 @@ +#ifndef _SYS_SIGNALFD_H +#define _SYS_SIGNALFD_H + +#include + +struct signalfd_siginfo { + uint32_t ssi_signo; + int32_t ssi_errno; + int32_t ssi_code; + uint32_t ssi_pid; + uint32_t ssi_uid; + int32_t ssi_fd; + uint32_t ssi_tid; + uint32_t ssi_band; + uint32_t ssi_overrun; + uint32_t ssi_trapno; + int32_t ssi_status; + int32_t ssi_int; + uint64_t ssi_ptr; + uint64_t ssi_utime; + uint64_t ssi_stime; + uint64_t ssi_addr; + uint8_t __pad[48]; +}; + +__BEGIN_DECLS + +extern int signalfd (int __fd, const sigset_t *__mask, int __flags) + __nonnull ((2)) __THROW; + +__END_DECLS + +#endif diff -urN -x CVS dietlibc-0.31/include/sys/statvfs.h dietlibc/include/sys/statvfs.h --- dietlibc-0.31/include/sys/statvfs.h 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/include/sys/statvfs.h 2008-08-06 02:28:13.000000000 +0200 @@ -0,0 +1,61 @@ +#ifndef _SYS_STATVFS_H +#define _SYS_STATVFS_H + +#include +#include + +__BEGIN_DECLS + +struct statvfs { + unsigned long f_bsize; /* file system block size */ + unsigned long f_frsize; /* fragment size */ + fsblkcnt_t f_blocks; /* size of fs in f_frsize units */ + fsblkcnt_t f_bfree; /* # free blocks */ + fsblkcnt_t f_bavail; /* # free blocks for non-root */ + fsfilcnt_t f_files; /* # inodes */ + fsfilcnt_t f_ffree; /* # free inodes */ + fsfilcnt_t f_favail; /* # free inodes for non-root */ + unsigned long f_fsid; /* file system ID */ + unsigned long f_flag; /* mount flags */ + unsigned long f_namemax; /* maximum filename length */ +}; + +int statvfs(const char *path, struct statvfs *buf) __THROW; +int fstatvfs(int fd, struct statvfs *buf) __THROW; + +/* Definitions for the flag in `f_flag'. These definitions should be + kept in sync with the definitions in . */ +enum +{ + ST_RDONLY = 1, /* Mount read-only. */ +#define ST_RDONLY ST_RDONLY + ST_NOSUID = 2 /* Ignore suid and sgid bits. */ +#define ST_NOSUID ST_NOSUID +#ifdef __USE_GNU + , + ST_NODEV = 4, /* Disallow access to device special files. */ +# define ST_NODEV ST_NODEV + ST_NOEXEC = 8, /* Disallow program execution. */ +# define ST_NOEXEC ST_NOEXEC + ST_SYNCHRONOUS = 16, /* Writes are synced at once. */ +# define ST_SYNCHRONOUS ST_SYNCHRONOUS + ST_MANDLOCK = 64, /* Allow mandatory locks on an FS. */ +# define ST_MANDLOCK ST_MANDLOCK + ST_WRITE = 128, /* Write on file/directory/symlink. */ +# define ST_WRITE ST_WRITE + ST_APPEND = 256, /* Append-only file. */ +# define ST_APPEND ST_APPEND + ST_IMMUTABLE = 512, /* Immutable file. */ +# define ST_IMMUTABLE ST_IMMUTABLE + ST_NOATIME = 1024, /* Do not update access times. */ +# define ST_NOATIME ST_NOATIME + ST_NODIRATIME = 2048, /* Do not update directory access times. */ +# define ST_NODIRATIME ST_NODIRATIME + ST_RELATIME = 4096 /* Update atime relative to mtime/ctime. */ +# define ST_RELATIME ST_RELATIME +#endif /* Use GNU. */ +}; + +__END_DECLS + +#endif diff -urN -x CVS dietlibc-0.31/include/sys/time.h dietlibc/include/sys/time.h --- dietlibc-0.31/include/sys/time.h 2005-09-21 09:33:08.000000000 +0200 +++ dietlibc/include/sys/time.h 2008-09-04 11:25:51.000000000 +0200 @@ -68,7 +68,6 @@ #ifdef _BSD_SOURCE /* another wonderful BSD invention... :( */ -/* note how subtly broken it is (doesn't work with <= or >=) */ #define timercmp(a,b,CMP) (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_usec CMP (b)->tv_usec) : ((a)->tv_sec CMP (b)->tv_sec)) #define timerclear(x) ((x)->tv_sec=(x)->tv_usec=0) #define timeradd(a,b,x) do { (x)->tv_sec=(a)->tv_sec+(b)->tv_sec; if (((x)->tv_usec=(a)->tv_usec+(b)->tv_usec)>=1000000) { ++(x)->tv_sec; (x)->tv_usec-=1000000; } } while (0) diff -urN -x CVS dietlibc-0.31/include/sys/timerfd.h dietlibc/include/sys/timerfd.h --- dietlibc-0.31/include/sys/timerfd.h 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/include/sys/timerfd.h 2008-02-19 01:28:13.000000000 +0100 @@ -0,0 +1,16 @@ +#ifndef _SYS_TIMERFD_H +#define _SYS_TIMERFD_H + +#include + +enum { TFD_TIMER_ABSTIME = 1 }; + +__BEGIN_DECLS + +int timerfd_create (clockid_t clock_id, int flags) __THROW; +int timerfd_settime (int ufd, int flags, const struct itimerspec *utmr, struct itimerspec *otmr) __THROW; +int timerfd_gettime (int ufd, struct itimerspec *otmr) __THROW; + +__END_DECLS + +#endif diff -urN -x CVS dietlibc-0.31/include/sys/types.h dietlibc/include/sys/types.h --- dietlibc-0.31/include/sys/types.h 2005-09-21 09:33:08.000000000 +0200 +++ dietlibc/include/sys/types.h 2007-10-18 23:08:02.000000000 +0200 @@ -12,13 +12,10 @@ clock ticks or CLOCKS_PER_SEC (see ). */ +typedef uint64_t fsblkcnt_t; +typedef uint64_t fsfilcnt_t; + /* TODO: - clockid_t - Used for clock ID type in the clock and timer functions. - fsblkcnt_t - Used for file system block counts - fsfilcnt_t - Used for file system file counts pthread_attr_t Used to identify a thread attribute object. pthread_cond_t @@ -39,8 +36,6 @@ Used for read-write lock attributes. pthread_t Used to identify a thread. - timer_t - Used for timer ID returned by timer_create(). */ #if defined(__alpha__) || defined(__ia64__) || defined(__sparc64__) || defined(__s390x__) diff -urN -x CVS dietlibc-0.31/include/utmp.h dietlibc/include/utmp.h --- dietlibc-0.31/include/utmp.h 2003-08-19 18:58:18.000000000 +0200 +++ dietlibc/include/utmp.h 2008-02-23 01:09:54.000000000 +0100 @@ -4,6 +4,7 @@ #include #include #include +#include __BEGIN_DECLS @@ -11,14 +12,6 @@ #define UT_NAMESIZE 32 #define UT_HOSTSIZE 256 -#define _PATH_UTMP "/var/run/utmp" -#define _PATH_WTMP "/var/log/wtmp" -#ifdef _BSD_SOURCE -/* die, BSD, die!!! */ -#define UTMP_FILE _PATH_UTMP -#define WTMP_FILE _PATH_WTMP -#endif - /* The structure describing an entry in the database of previous logins. */ struct lastlog @@ -72,6 +65,7 @@ char __unused[20]; /* Reserved for future use. */ }; +#ifndef _UTMPX_H /* untmpx.h hasn't already defined these. */ /* Values for the `ut_type' field of a `struct utmp'. */ #define EMPTY 0 /* No valid user accounting information. */ @@ -86,6 +80,7 @@ #define DEAD_PROCESS 8 /* Terminated process. */ #define ACCOUNTING 9 +#endif /* Tell the user that we have a modern system with UT_HOST, UT_PID, UT_TYPE, UT_ID and UT_TV fields. */ diff -urN -x CVS dietlibc-0.31/include/utmpx.h dietlibc/include/utmpx.h --- dietlibc-0.31/include/utmpx.h 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/include/utmpx.h 2008-02-23 01:09:54.000000000 +0100 @@ -0,0 +1,95 @@ +#ifndef _UTMPX_H +#define _UTMPX_H + +#include +#include +#include +#include + +/* For the getutmp{,x} functions we need the `struct utmp'. */ +#ifdef _GNU_SOURCE +struct utmp; +#endif + +#define __UT_LINESIZE 32 +#define __UT_NAMESIZE 32 +#define __UT_HOSTSIZE 256 + +__BEGIN_DECLS + +/* The structure describing the status of a terminated process. This + type is used in `struct utmpx below. */ +struct __exit_status + { + short int e_termination; /* Process termination status. */ + short int e_exit; /* Process exit status. */ + }; + +/* The structure describing an entry in the user accounting database. */ +struct utmpx +{ + short int ut_type; /* Type of login. */ + pid_t ut_pid; /* Process ID of login process. */ + char ut_line[__UT_LINESIZE]; /* Devicename. */ + char ut_id[4]; /* Inittab ID. */ + char ut_user[__UT_NAMESIZE]; /* Username. */ + char ut_host[__UT_HOSTSIZE]; /* Hostname for remote login. */ + struct __exit_status ut_exit; /* Exit status of a process marked + as DEAD_PROCESS. */ +/* The ut_session and ut_tv fields must be the same size when compiled + 32- and 64-bit. This allows data files and shared memory to be + shared between 32- and 64-bit applications. */ +#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 + int32_t ut_session; /* Session ID, used for windowing. */ + struct + { + int32_t tv_sec; /* Seconds. */ + int32_t tv_usec; /* Microseconds. */ + } ut_tv; /* Time entry was made. */ +#else + long int ut_session; /* Session ID, used for windowing. */ + struct timeval ut_tv; /* Time entry was made. */ +#endif + int32_t ut_addr_v6[4]; /* Internet address of remote host. */ + char __unused[20]; /* Reserved for future use. */ +}; + +#ifndef _UTMP_H /* utmp.h hasn't already defined these. */ +/* Values for the `ut_type' field of a `struct utmpx'. */ +#define EMPTY 0 /* No valid user accounting information. */ + +#define RUN_LVL 1 /* The system's runlevel. */ +#define BOOT_TIME 2 /* Time of system boot. */ +#define NEW_TIME 3 /* Time after system clock changed. */ +#define OLD_TIME 4 /* Time when system clock changed. */ + +#define INIT_PROCESS 5 /* Process spawned by the init process. */ +#define LOGIN_PROCESS 6 /* Session leader of a logged in user. */ +#define USER_PROCESS 7 /* Normal process. */ +#define DEAD_PROCESS 8 /* Terminated process. */ + +#define ACCOUNTING 9 +#endif + +/* Apparently, these functions are all considered possible cancellation + * points, thus no __THROW */ + +struct utmpx *getutxent(void); +struct utmpx *getutxid(struct utmpx *ut); +struct utmpx *getutxline(struct utmpx *ut); + +struct utmpx *pututxline(struct utmpx *ut); + +void setutxent(void); +void endutxent(void); + +#ifdef _GNU_SOURCE +void utmpxname (const char *file); +void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx); +void getutmp (const struct utmpx *utmpx, struct utmp *utmp); +void getutmpx (const struct utmp *utmp, struct utmpx *utmpx); +#endif + +__END_DECLS + +#endif diff -urN -x CVS dietlibc-0.31/include/wchar.h dietlibc/include/wchar.h --- dietlibc-0.31/include/wchar.h 2005-09-21 09:33:08.000000000 +0200 +++ dietlibc/include/wchar.h 2007-09-09 04:11:18.000000000 +0200 @@ -13,7 +13,7 @@ #else typedef unsigned int wint_t; #endif -typedef unsigned long int wctype_t; +typedef int (*wctype_t)(wint_t) __THROW __attribute__((__const__)); #ifndef WCHAR_MIN #define WCHAR_MIN (-2147483647 - 1) @@ -27,7 +27,7 @@ typedef struct { int count; - unsigned long sofar; + wchar_t sofar; } mbstate_t; wint_t btowc(int); @@ -94,6 +94,10 @@ int wprintf(const wchar_t *__restrict__, ...); int wscanf(const wchar_t *__restrict__, ...); +#ifdef _XOPEN_SOURCE +int wcwidth(wchar_t c); +#endif + __END_DECLS #endif diff -urN -x CVS dietlibc-0.31/lib/btowc.c dietlibc/lib/btowc.c --- dietlibc-0.31/lib/btowc.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/btowc.c 2007-09-09 04:11:18.000000000 +0200 @@ -0,0 +1,13 @@ +#include +#include "dietlocale.h" + +wint_t btowc(int c) { + if (c==EOF) return WEOF; + switch (lc_ctype) { + case CT_8BIT: + return c>0xff?WEOF:1; + case CT_UTF8: + return c>0x7f?WEOF:1; + } + return WEOF; +} diff -urN -x CVS dietlibc-0.31/lib/fstatvfs.c dietlibc/lib/fstatvfs.c --- dietlibc-0.31/lib/fstatvfs.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/fstatvfs.c 2007-10-18 23:08:02.000000000 +0200 @@ -0,0 +1,12 @@ +#define _FILE_OFFSET_BITS 64 +#include +#include + +extern void __statvfs_cvt(struct statfs* from,struct statvfs* to); + +int fstatvfs(int fd, struct statvfs *sv) { + struct statfs ss; + if (fstatfs(fd,&ss)==-1) return -1; + __statvfs_cvt(&ss,sv); + return 0; +} diff -urN -x CVS dietlibc-0.31/lib/mblen.c dietlibc/lib/mblen.c --- dietlibc-0.31/lib/mblen.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/mblen.c 2007-09-20 20:51:18.000000000 +0200 @@ -0,0 +1,6 @@ +#include +#include + +int mblen(const char* s,size_t n) { + return mbrlen(s,n,NULL); +} diff -urN -x CVS dietlibc-0.31/lib/mbrlen.c dietlibc/lib/mbrlen.c --- dietlibc-0.31/lib/mbrlen.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/mbrlen.c 2008-09-30 23:02:35.000000000 +0200 @@ -0,0 +1,9 @@ +#include +#include + +static mbstate_t internal; + +size_t mbrlen(const char *s, size_t n, mbstate_t *ps) { + static mbstate_t internal; + return mbrtowc (NULL, s, n, ps ?: &internal); +} diff -urN -x CVS dietlibc-0.31/lib/mbrtowc.c dietlibc/lib/mbrtowc.c --- dietlibc-0.31/lib/mbrtowc.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/mbrtowc.c 2008-09-30 23:02:35.000000000 +0200 @@ -0,0 +1,67 @@ +#include "dietlocale.h" +#include +#include + +static mbstate_t internal; + +size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) { + size_t i; + if (!ps) ps=&internal; + if (!s) { + if (ps->count) { + errno=EILSEQ; + return (size_t)-1; + } else { + ps->count=0; + ps->sofar=0; + return 0; + } + } + for (i=0; icount) { + /* we have an unfinished multibyte sequence */ + if ((c&0xc0)!=0x80) { + /* expected a continuation, didn't get one */ +kaputt: + errno=EILSEQ; + ps->count=0; + return (size_t)-1; + } + ps->sofar=(ps->sofar << 6) + (c & 0x3f); + if (!--ps->count) { +complete: + if (pwc) { *pwc=ps->sofar; ++pwc; } + if (ps->sofar) { + ps->sofar=0; + return i+1; + } else { + ps->count=0; ps->sofar=0; + return 0; + } + } + } else { + if (c&0x80) { /* start of multibyte sequence? */ + unsigned char x=c<<1; + unsigned char cnt=0; + while (x&0x80) { + x<<=1; + ++cnt; + } + if (!cnt || cnt>5) goto kaputt; + ps->sofar=x>>(cnt+1); + ps->count=cnt; + } else { + ps->sofar=c; + goto complete; + } + } + } + } + return n; +} diff -urN -x CVS dietlibc-0.31/lib/mbsinit.c dietlibc/lib/mbsinit.c --- dietlibc-0.31/lib/mbsinit.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/mbsinit.c 2007-09-09 03:37:54.000000000 +0200 @@ -0,0 +1,5 @@ +#include + +int mbsinit(const mbstate_t* s) { + return (!s || s->sofar); +} diff -urN -x CVS dietlibc-0.31/lib/mbsrtowcs.c dietlibc/lib/mbsrtowcs.c --- dietlibc-0.31/lib/mbsrtowcs.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/mbsrtowcs.c 2008-09-30 23:13:46.000000000 +0200 @@ -0,0 +1,14 @@ +#include + +size_t mbsrtowcs(wchar_t *dest, const char **src, size_t len, mbstate_t *ps) { + const char* orig=*src; + size_t i; + if (!dest) len=(size_t)-1; + for (i=0; i +#include + +size_t mbstowcs(wchar_t *dest, const char *src, size_t n) { + const char** s=&src; + return mbsrtowcs(dest,s,n,NULL); +} diff -urN -x CVS dietlibc-0.31/lib/mbtowc.c dietlibc/lib/mbtowc.c --- dietlibc-0.31/lib/mbtowc.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/mbtowc.c 2007-09-09 03:37:54.000000000 +0200 @@ -0,0 +1,6 @@ +#include +#include + +int mbtowc(wchar_t *pwc, const char *s, size_t n) { + return mbrtowc(pwc,s,n,NULL); +} diff -urN -x CVS dietlibc-0.31/lib/memcpy.c dietlibc/lib/memcpy.c --- dietlibc-0.31/lib/memcpy.c 2003-12-21 13:06:36.000000000 +0100 +++ dietlibc/lib/memcpy.c 2008-02-23 01:02:19.000000000 +0100 @@ -28,6 +28,8 @@ *c1++ = *c2++; if (n == (size_t) - 1) return (res); + dst = c1; + src = c2; } lx1 = (unsigned long *) dst; diff -urN -x CVS dietlibc-0.31/lib/signalfd.c dietlibc/lib/signalfd.c --- dietlibc-0.31/lib/signalfd.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/signalfd.c 2008-05-09 06:36:56.000000000 +0200 @@ -0,0 +1,13 @@ +#include +#include +#include + +extern int __signalfd(int fd,const sigset_t* mask,size_t nsig); + +int signalfd(int fd,const sigset_t* mask,int flags) { + if (flags) { /* bizarre glibc bullshit */ + errno=EINVAL; + return -1; + } + return __signalfd(fd,mask,_NSIG/8); +} diff -urN -x CVS dietlibc-0.31/lib/stackgap.c dietlibc/lib/stackgap.c --- dietlibc-0.31/lib/stackgap.c 2007-08-24 23:19:33.000000000 +0200 +++ dietlibc/lib/stackgap.c 2009-03-12 16:36:51.000000000 +0100 @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "dietfeatures.h" extern int main(int argc,char* argv[],char* envp[]); @@ -11,25 +13,65 @@ extern unsigned long __guard; #endif -#if defined(WANT_SSP) || defined(WANT_THREAD_SAFE) +#ifdef WANT_TLS +/* __tdatasize is the size of the initialized thread local data section + * __tmemsize is the size of the complete thread local data section + * (including uninitialized data) + * __tdataptr is a pointer to the initialized thread local data section + * __tmemsize is already rounded up to meet alignment + * the final memory layout is [tdata] [tbss (zero)] [tcb] */ +size_t __tdatasize, __tmemsize; +void* __tdataptr; + +static void findtlsdata(long* auxvec) { +#if (__WORDSIZE == 64) + Elf64_Phdr* x=0; +#else + Elf32_Phdr* x=0; +#endif + size_t i,n; + while (*auxvec) { + if (auxvec[0]==3) { + x=(void*)auxvec[1]; + break; + } + auxvec+=2; + } /* if we don't find the entry, the kernel let us down */ + if (!x) return; /* a kernel this old does not support thread local storage anyway */ + if (x->p_type!=PT_PHDR) return; /* should start with PT_PHDR */ + /* if it doesn't, assume there is no thread local storage */ + n=x->p_memsz/sizeof(*x); + for (i=1; itcb=&mainthread; + mainthread->self=&mainthread; #if defined(WANT_SSP) - mainthread.stack_guard=__guard; + mainthread->stack_guard=__guard; #endif #if defined(__x86_64__) - arch_prctl(ARCH_SET_FS, &mainthread); + arch_prctl(ARCH_SET_FS, mainthread); #elif defined(__i386__) static unsigned int sd[4]; sd[0]=-1; - sd[1]=(unsigned long int)&mainthread; + sd[1]=(unsigned long int)mainthread; sd[2]=0xfffff; /* 4 GB limit */ sd[3]=0x51; /* bitfield, see struct user_desc in asm-i386/ldt.h */ if (set_thread_area((struct user_desc*)(void*)&sd)==0) { @@ -37,46 +79,66 @@ } #elif defined(__alpha__) || defined(__s390__) - __builtin_set_thread_pointer(&mainthread); + __builtin_set_thread_pointer(mainthread); #elif defined(__ia64__) || defined(__powerpc__) register tcbhead_t* __thread_self __asm__("r13"); - __thread_self=&mainthread; + __thread_self=mainthread; #elif defined(__sparc__) register tcbhead_t* __thread_self __asm("%g7"); - __thread_self=&mainthread; + __thread_self=mainthread; #else #warning "no idea how to enable TLS on this platform, edit lib/stackgap.c" #endif } #endif +static void* find_rand(long* x) { + while (*x) { + if (*x==25) + return (void*)x[1]; + x+=2; + } + return NULL; +} + int stackgap(int argc,char* argv[],char* envp[]); int stackgap(int argc,char* argv[],char* envp[]) { -#ifdef WANT_SSP_XOR - struct timeval tv; -#endif -#if defined(WANT_STACKGAP) || defined(WANT_SSP_URANDOM) - int fd=open("/dev/urandom",O_RDONLY); +#if defined(WANT_STACKGAP) || defined(WANT_SSP) || defined(WANT_TLS) + long* auxvec=(long*)envp; + char* rand; + char* tlsdata; + while (*auxvec) ++auxvec; ++auxvec; /* skip envp to get to auxvec */ #ifdef WANT_STACKGAP unsigned short s; +#endif +#if defined(WANT_STACKGAP) || defined(WANT_SSP) volatile char* gap; - read(fd,&s,2); + rand=find_rand(auxvec); + if (!rand) { + char myrand[10]; + int fd=open("/dev/urandom",O_RDONLY); + read(fd,myrand,10); + close(fd); + rand=myrand; + } +#endif +#ifdef WANT_STACKGAP + s=*(unsigned short*)(rand+8); #endif #ifdef WANT_SSP - read(fd,&__guard,sizeof(__guard)); + __guard=*(unsigned long*)rand; #endif - close(fd); #ifdef WANT_STACKGAP gap=alloca(s); #endif #endif -#ifdef WANT_SSP_XOR - gettimeofday (&tv, NULL); - __guard ^= tv.tv_usec ^ tv.tv_sec ^ getpid(); -#endif -#if defined(WANT_SSP) || defined(WANT_THREAD_SAFE) - setup_tls(); +#if defined(WANT_SSP) || defined(WANT_TLS) + findtlsdata(auxvec); + tlsdata=alloca(__tmemsize+sizeof(tcbhead_t)); + memcpy(tlsdata,__tdataptr,__tdatasize); + memset(tlsdata+__tdatasize,0,__tmemsize-__tdatasize); + setup_tls((tcbhead_t*)(tlsdata+__tmemsize)); #endif return main(argc,argv,envp); } diff -urN -x CVS dietlibc-0.31/lib/statvfs.c dietlibc/lib/statvfs.c --- dietlibc-0.31/lib/statvfs.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/statvfs.c 2008-05-09 06:36:56.000000000 +0200 @@ -0,0 +1,13 @@ +#define _FILE_OFFSET_BITS 64 +#include +#include + +extern void __statvfs_cvt(struct statfs* from,struct statvfs* to); + +int statvfs(const char *path, struct statvfs *sv) { + struct statfs ss; + if (statfs(path,&ss)==-1) return -1; + __statvfs_cvt(&ss,sv); + return 0; +} + diff -urN -x CVS dietlibc-0.31/lib/statvfs_cvt.c dietlibc/lib/statvfs_cvt.c --- dietlibc-0.31/lib/statvfs_cvt.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/statvfs_cvt.c 2007-10-18 23:08:02.000000000 +0200 @@ -0,0 +1,19 @@ +#define _FILE_OFFSET_BITS 64 +#include +#include + +void __statvfs_cvt(struct statfs* from,struct statvfs* to); + +void __statvfs_cvt(struct statfs* from,struct statvfs* to) { + to->f_bsize=from->f_bsize; + to->f_frsize=from->f_frsize; + to->f_blocks=from->f_blocks; + to->f_bfree=from->f_bfree; + to->f_bavail=from->f_bavail; + to->f_files=from->f_files; + to->f_ffree=from->f_ffree; + to->f_favail=from->f_ffree; + to->f_fsid=from->f_fsid.__val[0]; + to->f_flag=0; + to->f_namemax=from->f_namelen; +} diff -urN -x CVS dietlibc-0.31/lib/strcmp.c dietlibc/lib/strcmp.c --- dietlibc-0.31/lib/strcmp.c 2003-12-21 13:06:36.000000000 +0100 +++ dietlibc/lib/strcmp.c 2008-02-19 01:28:13.000000000 +0100 @@ -31,16 +31,16 @@ while (1) { l1 = *lx1++; l2 = *lx2++; - if ((((l1 - MKW(0x1)) & ~l1) & MKW(0x80)) || - ((((l2 - MKW(0x1)) & ~l2) & MKW(0x80))) || l1 != l2) { + if ((((l1 - MKW(0x1ul)) & ~l1) & MKW(0x80ul)) || + ((((l2 - MKW(0x1ul)) & ~l2) & MKW(0x80ul))) || l1 != l2) { unsigned char c1, c2; while (1) { - c1 = l1 & 0xff; - c2 = l2 & 0xff; + c1 = GFC(l1); + c2 = GFC(l2); if (!c1 || c1 != c2) return (c1 - c2); - l1 >>= 8; - l2 >>= 8; + INCSTR(l1); + INCSTR(l2); } } } diff -urN -x CVS dietlibc-0.31/lib/strcpy.c dietlibc/lib/strcpy.c --- dietlibc-0.31/lib/strcpy.c 2003-12-21 13:06:36.000000000 +0100 +++ dietlibc/lib/strcpy.c 2008-02-19 01:28:13.000000000 +0100 @@ -25,9 +25,8 @@ while (1) { l = *(const unsigned long *) s2; - if (((l - MKW(0x1)) & ~l) & MKW(0x80)) { - unsigned char c; - while ((*s1++ = (l & 0xff))) l>>=8; + if (((l - MKW(0x1ul)) & ~l) & MKW(0x80ul)) { + while ((*s1++ = GFC(l))) INCSTR(l); return (res); } *(unsigned long *) s1 = l; diff -urN -x CVS dietlibc-0.31/lib/strcspn.c dietlibc/lib/strcspn.c --- dietlibc-0.31/lib/strcspn.c 2001-01-09 18:57:43.000000000 +0100 +++ dietlibc/lib/strcspn.c 2008-02-19 01:28:13.000000000 +0100 @@ -4,14 +4,12 @@ size_t strcspn(const char *s, const char *reject) { size_t l=0; - int a=1,i,al=strlen(reject); + int i,al=strlen(reject); - while((a)&&(*s)) - { - for(i=0;(a)&&(i char *strdup(const char *s) { - char *tmp=(char *)malloc(strlen(s)+1); + size_t l=strlen(s)+1; + char *tmp=(char *)malloc(l); if (!tmp) return 0; - strcpy(tmp,s); - return tmp; + return memcpy(tmp,s,l); } diff -urN -x CVS dietlibc-0.31/lib/strlen.c dietlibc/lib/strlen.c --- dietlibc-0.31/lib/strlen.c 2003-08-19 21:34:18.000000000 +0200 +++ dietlibc/lib/strlen.c 2008-02-19 01:28:13.000000000 +0100 @@ -1,6 +1,7 @@ #include #include "dietfeatures.h" #include +#include #ifdef WANT_SMALL_STRING_ROUTINES size_t strlen(const char *s) { @@ -10,38 +11,88 @@ return i; } #else -static const unsigned long magic = 0x01010101; + +#if __WORDSIZE == 64 +typedef uint64_t word_t; +#elif __WORDSIZE == 32 +typedef uint32_t word_t; +#else +#error unsupported __WORDSIZE +#endif + +static word_t const magic = (word_t)(0x0101010101010101ull); size_t strlen(const char *s) { const char *t = s; - unsigned long word; + word_t word; + word_t mask; - if (!s) return 0; + if (__unlikely(!s)) return 0; /* Byte compare up until word boundary */ - for (; ((unsigned long) t & 3); t++) + for (; ((unsigned long) t & (sizeof(magic)-1)); t++) if (!*t) return t - s; /* Word compare */ do { - word = *((unsigned long *) t); t += 4; + word = *((word_t const *) t); t += sizeof word; word = (word - magic) &~ word; word &= (magic << 7); } while (__likely(word == 0)); -#if BYTE_ORDER == LITTLE_ENDIAN - /* word & 0x80808080 == word */ - word = (word - 1) & (magic << 10); - word += (word << 8) + (word << 16); - t += word >> 26; +#if __BYTE_ORDER == __LITTLE_ENDIAN + (void)mask; + switch (sizeof(word)) { + case 8: + /* word & 0x8080808080808080 == word */ + word = (word - 1) & (magic << 8); + word += (word << 32); + word += (word << 16); + word += (word << 8); + t += word >> 56; + break; + + case 4: + /* word & 0x80808080 == word */ + word = (word - 1) & (magic << 10); + word += (word << 8) + (word << 16); + t += word >> 26; + break; + + default: { char exc[sizeof(word)==8]; (void)exc; } + } #else - if ((word & 0x80800000) == 0) { - word <<= 16; - t += 2; + mask = (magic << 7); + + switch (sizeof(word)) { + case 8: + mask <<= 4*8; + if ((word & mask) == 0) { + t += 4; + word <<= 4*8; + } + /* fallthrough */ + + case 4: + mask <<= 2*8; + if ((word & mask) == 0) { + t += 2; + word <<= 2*8; + } + /* fallthrough */ + + case 2: + mask <<= 1*8; + if ((word & mask) == 0) { + t += 1; + word <<= 1*8; + } + break; + + default: { char exc[sizeof(word)==8]; (void)exc; } } - if ((word & 0x80000000) == 0) t += 1; #endif - return ((const char *) t) - 4 - s; + return t - sizeof(word) - s; } #endif diff -urN -x CVS dietlibc-0.31/lib/strpbrk.c dietlibc/lib/strpbrk.c --- dietlibc-0.31/lib/strpbrk.c 2001-01-09 18:57:43.000000000 +0100 +++ dietlibc/lib/strpbrk.c 2008-02-19 01:28:13.000000000 +0100 @@ -2,9 +2,9 @@ #include char *strpbrk(const char *s, const char *accept) { - register int i,l=strlen(accept); + register unsigned int i; for (; *s; s++) - for (i=0; ihl) return 0; for (i=hl-nl+1; __likely(i); --i) { diff -urN -x CVS dietlibc-0.31/lib/timerfd_create.c dietlibc/lib/timerfd_create.c --- dietlibc-0.31/lib/timerfd_create.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/timerfd_create.c 2008-02-19 01:28:13.000000000 +0100 @@ -0,0 +1,7 @@ +#include + +extern int __timerfd(int ufd, int clockid, int flags, const struct itimerspec *utmr); + +int timerfd_create (clockid_t __clock_id, int __flags) { + return __timerfd(-1,__clock_id,__flags,0); +} diff -urN -x CVS dietlibc-0.31/lib/__v_printf.c dietlibc/lib/__v_printf.c --- dietlibc-0.31/lib/__v_printf.c 2007-05-17 07:00:42.000000000 +0200 +++ dietlibc/lib/__v_printf.c 2008-02-19 01:28:13.000000000 +0100 @@ -21,7 +21,8 @@ static const char pad_line[2][16]= { " ", "0000000000000000", }; static int write_pad(unsigned int* dlen,struct arg_printf* fn, unsigned int len, int padwith) { int nr=0; - if ((int)len<0 || *dlen+len15;len-=16,nr+=16) { A_WRITE(fn,pad_line[(padwith=='0')?1:0],16); } @@ -80,8 +81,6 @@ /* FLAGS */ case '#': flag_hash=-1; - case 'z': - goto inn_printf; case 'h': --flag_long; @@ -95,6 +94,7 @@ #if __WORDSIZE == 64 case 'j': #endif + case 'z': case 'l': ++flag_long; goto inn_printf; @@ -129,10 +129,18 @@ goto inn_printf; case '*': - width=va_arg(arg_ptr,int); - if (width>MAX_WIDTH) return -1; /* width is unsiged, so this catches <0, too */ - goto inn_printf; - + { + /* A negative field width is taken as a '-' flag followed by + * a positive field width + **/ + int tmp; + if ((tmp=va_arg(arg_ptr,int))<0) { + flag_left=1; + tmp=-tmp; + } + if ((width=(unsigned long)tmp)>MAX_WIDTH) return -1; + goto inn_printf; + } case '.': flag_dot=1; if (*format=='*') { @@ -214,7 +222,7 @@ if (flag_dot && width==0) width=preci; if (!flag_dot) preci=sz; - if (!flag_left) { /* do left-side padding */ + if (!flag_left && padwith==' ') { /* do left-side padding with spaces */ if (write_pad(&len,fn,width-preci,padwith)) return -1; } @@ -222,6 +230,10 @@ B_WRITE(fn,sign,todo); len+=todo; } + if (!flag_left && padwith!=' ') { /* do left-side padding with '0' */ + if (write_pad(&len,fn,width-preci,padwith)) + return -1; + } /* do preci padding */ if (write_pad(&len,fn,preci-sz,precpadwith)) return -1; @@ -377,7 +389,7 @@ sz=strlen(s); if (width +#include "dietlocale.h" + +static mbstate_t internal; + +size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) { + if (!ps) ps=&internal; + switch (lc_ctype) { + case CT_8BIT: + if (!s) return 0; + *s=wc; + return 1; + case CT_UTF8: + if (!s) return (wc>=0x80); + { + unsigned int bits,j,k; + if (wc>=0x04000000) { bits=30; *s=0xFC; j=6; } else + if (wc>=0x00200000) { bits=24; *s=0xF8; j=5; } else + if (wc>=0x00010000) { bits=18; *s=0xF0; j=4; } else + if (wc>=0x00000800) { bits=12; *s=0xE0; j=3; } else + if (wc>=0x00000080) { bits=6; *s=0xC0; j=2; } else + { *s=wc; return 1; } + *s |= (unsigned char)(wc>>bits); + for (k=1; k>bits)&0x3f); + } + return k; + } + } + return 0; +} diff -urN -x CVS dietlibc-0.31/lib/wcsncat.c dietlibc/lib/wcsncat.c --- dietlibc-0.31/lib/wcsncat.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/wcsncat.c 2007-10-04 15:58:29.000000000 +0200 @@ -0,0 +1,10 @@ +#include + +wchar_t* wcsncat(wchar_t *__restrict__ dest, const wchar_t *__restrict__ src,size_t n) { + wchar_t* orig=dest; + size_t i; + while (*dest) ++dest; + for (i=0; i + +wchar_t* wcsncpy(wchar_t *__restrict__ dest, const wchar_t *__restrict__ src,size_t n) { + wchar_t* orig=dest; + for (; dest + +wchar_t *wcsstr(const wchar_t *haystack, const wchar_t *needle) { + size_t i,j; + for (i=0; haystack[i]; ++i) { + for (j=0; haystack[i+j]==needle[j]; ++j) ; + if (!needle[j]) return (wchar_t*)haystack+i; + } + return 0; +} + diff -urN -x CVS dietlibc-0.31/lib/wctomb.c dietlibc/lib/wctomb.c --- dietlibc-0.31/lib/wctomb.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/wctomb.c 2007-09-09 03:37:54.000000000 +0200 @@ -0,0 +1,6 @@ +#include +#include + +int wctomb(char *pwc, wchar_t s) { + return wcrtomb(pwc,s,NULL); +} diff -urN -x CVS dietlibc-0.31/lib/wcwidth.c dietlibc/lib/wcwidth.c --- dietlibc-0.31/lib/wcwidth.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/lib/wcwidth.c 2007-09-09 04:11:18.000000000 +0200 @@ -0,0 +1,8 @@ +#define _XOPEN_SOURCE +#include + +int wcwidth(wchar_t c) { + if (!c) return 0; + if (c<' ') return -1; + return 1; +} diff -urN -x CVS dietlibc-0.31/libcompat/getutmp.c dietlibc/libcompat/getutmp.c --- dietlibc-0.31/libcompat/getutmp.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libcompat/getutmp.c 2008-02-23 01:09:54.000000000 +0100 @@ -0,0 +1,25 @@ +#include "dietfeatures.h" +#include +#include +#include "dietwarning.h" + +#define _GNU_SOURCE +#include + +void +getutmp (const struct utmpx *utmpx, struct utmp *utmp) +{ + memcpy (utmp, utmpx, sizeof(struct utmp)); + return; +} + +void +getutmpx (const struct utmp *utmp, struct utmpx *utmpx) +{ + memcpy (utmpx, utmp, sizeof(struct utmpx)); + return; +} + +link_warning("getutmp","getutmp(): dietlibc utmp and utmpx structures are identical. If you actually require conversion, this it NOT the place to find it!"); + +link_warning("getutmpx","getutmpx(): dietlibc utmp and utmpx structures are identical. If you actually require conversion, this it NOT the place to find it!"); diff -urN -x CVS dietlibc-0.31/libcompat/utmpxname.c dietlibc/libcompat/utmpxname.c --- dietlibc-0.31/libcompat/utmpxname.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libcompat/utmpxname.c 2008-02-23 01:09:54.000000000 +0100 @@ -0,0 +1,10 @@ +#define _GNU_SOURCE +#include + +void __utmpxname (const char *file); + +void +utmpxname (const char *file) { + __utmpxname (file); + return; +} diff -urN -x CVS dietlibc-0.31/libcompat/wtxent.c dietlibc/libcompat/wtxent.c --- dietlibc-0.31/libcompat/wtxent.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libcompat/wtxent.c 2008-02-23 01:09:54.000000000 +0100 @@ -0,0 +1,14 @@ +#include +#include +#include + +#define _GNU_SOURCE +#include + +void updwtmpx(const char *wtmpx_file, const struct utmpx *ut) { + int fd = open(wtmpx_file, O_WRONLY|O_APPEND); + if (fd<0) return; + fcntl (fd, F_SETFD, FD_CLOEXEC); + write(fd, ut, sizeof(struct utmpx)); + close(fd); +} diff -urN -x CVS dietlibc-0.31/libcruft/dn_expand.c dietlibc/libcruft/dn_expand.c --- dietlibc-0.31/libcruft/dn_expand.c 2002-07-11 00:20:34.000000000 +0200 +++ dietlibc/libcruft/dn_expand.c 2008-09-30 23:02:35.000000000 +0200 @@ -2,10 +2,10 @@ #include #include -extern int __dns_decodename(unsigned char *packet,unsigned int ofs,unsigned char *dest, - unsigned int maxlen,unsigned char* behindpacket); +extern int __dns_decodename(const unsigned char *packet,unsigned int ofs,unsigned char *dest, + unsigned int maxlen,const unsigned char* behindpacket); -int dn_expand(unsigned char *msg, unsigned char *eomorig, unsigned char *comp_dn, unsigned char *exp_dn, int length) { +int dn_expand(const unsigned char *msg, const unsigned char *eomorig, const unsigned char *comp_dn, unsigned char *exp_dn, int length) { return __dns_decodename(msg,comp_dn-msg,exp_dn,length,eomorig)-(comp_dn-msg); } diff -urN -x CVS dietlibc-0.31/libcruft/dnscruft.c dietlibc/libcruft/dnscruft.c --- dietlibc-0.31/libcruft/dnscruft.c 2006-10-13 20:19:12.000000000 +0200 +++ dietlibc/libcruft/dnscruft.c 2008-09-30 23:02:35.000000000 +0200 @@ -20,8 +20,8 @@ void __dns_make_fd(void); void __dns_make_fd6(void); void __dns_readstartfiles(void); -int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest, - unsigned int maxlen,unsigned char* behindpacket); +int __dns_decodename(const unsigned char *packet,unsigned int offset,unsigned char *dest, + unsigned int maxlen,const unsigned char* behindpacket); void __dns_make_fd(void) { int tmp; @@ -148,11 +148,11 @@ } /* return length of decoded data or -1 */ -int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest, - unsigned int maxlen,unsigned char* behindpacket) { - unsigned char *tmp; - unsigned char *max=dest+maxlen; - unsigned char *after=packet+offset; +int __dns_decodename(const unsigned char *packet,unsigned int offset,unsigned char *dest, + unsigned int maxlen,const unsigned char* behindpacket) { + const unsigned char *tmp; + const unsigned char *max=dest+maxlen; + const unsigned char *after=packet+offset; int ok=0; for (tmp=after; maxlen>0&&*tmp; ) { if (tmp>=behindpacket) return -1; diff -urN -x CVS dietlibc-0.31/libcruft/getpagesize.c dietlibc/libcruft/getpagesize.c --- dietlibc-0.31/libcruft/getpagesize.c 2002-02-23 23:18:42.000000000 +0100 +++ dietlibc/libcruft/getpagesize.c 2009-02-26 21:51:54.000000000 +0100 @@ -1,6 +1,8 @@ #include #include #include +/* for environ: */ +#include #ifndef PAGE_SIZE #define PAGE_SIZE 4096 @@ -8,6 +10,14 @@ size_t __libc_getpagesize(void); size_t __libc_getpagesize(void) { + long* x=(long*)environ; + int fd; + while (*x) ++x; ++x; /* skip envp to get to auxvec */ + while (*x) { + if (*x==6) + return x[1]; + x+=2; + } return PAGE_SIZE; } diff -urN -x CVS dietlibc-0.31/libcruft/res_query.c dietlibc/libcruft/res_query.c --- dietlibc-0.31/libcruft/res_query.c 2006-12-08 17:24:56.000000000 +0100 +++ dietlibc/libcruft/res_query.c 2008-02-20 01:45:12.000000000 +0100 @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff -urN -x CVS dietlibc-0.31/libcruft/setlocale.c dietlibc/libcruft/setlocale.c --- dietlibc-0.31/libcruft/setlocale.c 2006-04-04 05:10:40.000000000 +0200 +++ dietlibc/libcruft/setlocale.c 2007-09-09 03:37:54.000000000 +0200 @@ -4,16 +4,17 @@ #include "dietlocale.h" char *setlocale (int category, const char *locale) { + lc_ctype=CT_8BIT; if (locale && (category==LC_ALL || category==LC_CTYPE)) { if (!*locale) { - char* x; - lc_ctype=CT_8BIT; + const char* x; x=getenv("LC_CTYPE"); if (!x) x=getenv("LC_ALL"); if (!x) x="C"; - if (strstr(x,".UTF-8") || strstr(x,".UTF8")) lc_ctype=CT_UTF8; + locale=x; } } + if (strstr(locale,".UTF-8") || strstr(locale,".UTF8")) lc_ctype=CT_UTF8; if (locale && (locale[0]!='C' || locale[1])) return 0; return "C"; } diff -urN -x CVS dietlibc-0.31/libdl/_dl_alloc.c dietlibc/libdl/_dl_alloc.c --- dietlibc-0.31/libdl/_dl_alloc.c 2005-10-07 21:33:34.000000000 +0200 +++ dietlibc/libdl/_dl_alloc.c 2008-04-12 00:51:11.000000000 +0200 @@ -41,7 +41,7 @@ register int i,m; #ifdef __DIET_LD_SO__ tmp = (struct _dl_handle*)_dl_sys_mmap(0,at_pagesize,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); - m=at_pagesize/sizeof(struct _dl_handle); + m=DIV(at_pagesize,sizeof(struct _dl_handle)); #else int ps=getpagesize(); tmp = (struct _dl_handle*)mmap(0,ps,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); diff -urN -x CVS dietlibc-0.31/libdl/dlerror.c dietlibc/libdl/dlerror.c --- dietlibc-0.31/libdl/dlerror.c 2005-05-13 14:22:32.000000000 +0200 +++ dietlibc/libdl/dlerror.c 2008-04-12 00:51:11.000000000 +0200 @@ -35,7 +35,7 @@ buf[len]=0; --_dl_error; - if (_dl_error>=(sizeof(_dl_error_msg)/sizeof(struct _dl_err_msg))) + if (_dl_error>=DIV(sizeof(_dl_error_msg),sizeof(struct _dl_err_msg))) return "HAE ?!?"; if (_dl_error_location) { diff -urN -x CVS dietlibc-0.31/libdl/_dl_main.c dietlibc/libdl/_dl_main.c --- dietlibc-0.31/libdl/_dl_main.c 2006-11-16 11:04:00.000000000 +0100 +++ dietlibc/libdl/_dl_main.c 2008-07-07 14:35:43.000000000 +0200 @@ -318,6 +318,7 @@ " mov fp, #0 @ start new stack frame \n" " ldr a1, [sp], #4 @ argc \n" " mov a2, sp @ argv \n" +" mov sp, r4 @ restore stack pointer \n" " add a3, a2, a1, lsl #2 @ envp \n" " add a3, a3, #4 \n" /* PIC code startup */ @@ -332,8 +333,6 @@ " add a4, a4, sl \n" /* call _dl_main */ " bl _dl_main \n" -/* restore stack pointer */ -" mov sp, r4 \n" /* save program entry point */ " mov lr, a1 \n" /* abi: agrument 1: global fini entry */ @@ -371,20 +370,20 @@ "_dl_sys_mmap: \n" " stmdb sp!,{r0,r1,r2,r3} \n" " mov r0, sp \n" -" swi #0x900090 @ mmap \n" +" swi #0x90005a @ mmap \n" " add sp, sp, #16 \n" " mov pc, lr \n" ".type _dl_sys_munmap,function \n" "_dl_sys_munmap: \n" -" swi #0x900091 @ munmap \n" +" swi #0x90005b @ munmap \n" " mov pc, lr \n" ".type _dl_sys_fstat,function \n" "_dl_sys_fstat: \n" -" swi #0x900108 @ fstat \n" +" swi #0x90006c @ fstat \n" " mov pc, lr \n" ".type _dl_sys_mprotect,function \n" "_dl_sys_mprotect: \n" -" swi #0x900125 @ mprotect \n" +" swi #0x90007d @ mprotect \n" " mov pc, lr \n" ".type _dl_jump,function \n" @@ -689,6 +688,15 @@ #endif /* now reuse some unchanged sources */ +#ifdef __arm__ +#include "_dl_math.c" +#define MOD(a,b) _dl_mod(a,b) +#define DIV(a,b) _dl_div(a,b,NULL) +#else +#define MOD(a,b) (a % b) +#define DIV(a,b) (a / b) +#endif + #include "dlerror.c" #include "_dl_alloc.c" @@ -1092,7 +1100,7 @@ #ifdef DEBUG pf(__FUNCTION__); pf(": try to relocate some values\n"); #endif - if (_dl_relocate(dh,rel,relsize/relent)) return 0; + if (_dl_relocate(dh,rel,DIV(relsize,relent))) return 0; } /* do PTL / GOT relocation */ diff -urN -x CVS dietlibc-0.31/libdl/_dl_math.c dietlibc/libdl/_dl_math.c --- dietlibc-0.31/libdl/_dl_math.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libdl/_dl_math.c 2008-04-12 00:51:11.000000000 +0200 @@ -0,0 +1,33 @@ +static unsigned long _dl_div( + unsigned long num, + unsigned long den, + unsigned long * rem) +{ + unsigned long quot = 0, qbit = 1; + + if (den == 0) + return 0; + /* Left-justify denominator and count shift */ + while ((int) den >= 0) { + den <<= 1; + qbit <<= 1; + } + while (qbit) { + if (den <= num) { + num -= den; + quot += qbit; + } + den >>= 1; + qbit >>= 1; + } + if (rem) + *rem = num; + return quot; +} + +static unsigned long _dl_mod(unsigned long num, unsigned long den) +{ + unsigned long rem; + _dl_div(num, den, &rem); + return rem; +} diff -urN -x CVS dietlibc-0.31/libdl/dlsym.c dietlibc/libdl/dlsym.c --- dietlibc-0.31/libdl/dlsym.c 2006-11-16 11:04:00.000000000 +0100 +++ dietlibc/libdl/dlsym.c 2008-04-12 00:51:11.000000000 +0200 @@ -6,7 +6,7 @@ static void*_dlsym_elfhash(struct _dl_handle*dh,const unsigned char*symbol) { unsigned long*sym=0; unsigned int hash =elf_hash(symbol); - unsigned int bhash=hash%HASH_BUCKET_LEN(dh->hash_tab); + unsigned int bhash=MOD(hash, HASH_BUCKET_LEN(dh->hash_tab)); unsigned int*chain=HASH_CHAIN(dh->hash_tab); unsigned char*name=(unsigned char*)dh->dyn_str_tab; unsigned int ind=HASH_BUCKET(dh->hash_tab)[bhash]; @@ -38,7 +38,7 @@ unsigned long*sym=0; unsigned char*name=(unsigned char*)dh->dyn_str_tab; unsigned int hash =gnu_hash(symbol); - unsigned int bhash=hash%GNU_HASH_BUCKET_LEN(dh->gnu_hash_tab); + unsigned int bhash=MOD(hash, GNU_HASH_BUCKET_LEN(dh->hash_tab)); unsigned int ind =GNU_HASH_BUCKET(dh->gnu_hash_tab,bhash); #ifdef DEBUG //pf(__FUNCTION__); pf(": bucket("); ph(bhash); pf(",\""); pf(symbol); pf("\")\n"); diff -urN -x CVS dietlibc-0.31/libpthread/pthread_fputs.c dietlibc/libpthread/pthread_fputs.c --- dietlibc-0.31/libpthread/pthread_fputs.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libpthread/pthread_fputs.c 2008-05-09 06:36:56.000000000 +0200 @@ -0,0 +1,5 @@ +#include + +int fputs(const char*s,FILE*stream) { + return fwrite(s,strlen(s),1,stream); +} diff -urN -x CVS dietlibc-0.31/libpthread/pthread_fread.c dietlibc/libpthread/pthread_fread.c --- dietlibc-0.31/libpthread/pthread_fread.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libpthread/pthread_fread.c 2008-05-09 06:36:56.000000000 +0200 @@ -0,0 +1,9 @@ +#include + +size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { + size_t tmp; + pthread_mutex_lock(&stream->m); + tmp=fread_unlocked(ptr,size,nmemb,stream); + pthread_mutex_unlock(&stream->m); + return tmp; +} diff -urN -x CVS dietlibc-0.31/libpthread/pthread_fwrite.c dietlibc/libpthread/pthread_fwrite.c --- dietlibc-0.31/libpthread/pthread_fwrite.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libpthread/pthread_fwrite.c 2008-05-09 06:36:56.000000000 +0200 @@ -0,0 +1,9 @@ +#include + +size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { + size_t tmp; + pthread_mutex_lock(&stream->m); + tmp=fwrite_unlocked(ptr,size,nmemb,stream); + pthread_mutex_unlock(&stream->m); + return tmp; +} diff -urN -x CVS dietlibc-0.31/libpthread/pthread_internal.c dietlibc/libpthread/pthread_internal.c --- dietlibc-0.31/libpthread/pthread_internal.c 2006-09-18 16:55:35.000000000 +0200 +++ dietlibc/libpthread/pthread_internal.c 2008-02-20 01:45:12.000000000 +0100 @@ -1,3 +1,4 @@ +#define _GNU_SOURCE #include #include #include @@ -5,7 +6,7 @@ #include #include -#include +#include #include #include diff -urN -x CVS dietlibc-0.31/libregex/rx.c dietlibc/libregex/rx.c --- dietlibc-0.31/libregex/rx.c 2005-11-05 00:10:45.000000000 +0100 +++ dietlibc/libregex/rx.c 2008-12-26 02:24:33.000000000 +0100 @@ -7,6 +7,10 @@ #include #include +#if !defined(__x86_64__) +#undef WANT_REGEX_JIT +#endif + /* this is ugly. * the idea is to build a parse tree, then do some poor man's OOP with a * generic matcher function call that is always that the start of each @@ -40,15 +44,21 @@ struct branch *b; }; */ +struct string { + char* s; + size_t len; +}; + struct atom { matcher m; void* next; - enum { ILLEGAL, EMPTY, REGEX, BRACKET, ANY, LINESTART, LINEEND, WORDSTART, WORDEND, CHAR, } type; + enum { ILLEGAL, EMPTY, REGEX, BRACKET, ANY, LINESTART, LINEEND, WORDSTART, WORDEND, CHAR, STRING, BACKREF, } type; int bnum; union { struct regex r; struct bracketed b; char c; + struct string s; } u; }; @@ -100,6 +110,30 @@ static const char* parseregex(struct regex* r,const char* s,regex_t* rx); +static int matchatom_CHAR(void*__restrict__ x,const unsigned char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) { + register struct atom* a=(struct atom*)x; +#ifdef DEBUG + printf("matching atom CHAR %c against \"%.20s\"\n",a->u.c,s); +#endif + if (*s!=a->u.c) return -1; + if (a->next) + return ((struct atom*)(a->next))->m(a->next,(const char*)s+1,ofs+1,preg,plus+1,eflags); + else + return plus+1; +} + +static int matchatom_CHAR_ICASE(void*__restrict__ x,const unsigned char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) { + register struct atom* a=(struct atom*)x; +#ifdef DEBUG + printf("matching atom CHAR_ICASE %c against \"%.20s\"\n",a->u.c,s); +#endif + if (tolower(*s)!=a->u.c) return -1; + if (a->next) + return ((struct atom*)(a->next))->m(a->next,(const char*)s+1,ofs+1,preg,plus+1,eflags); + else + return plus+1; +} + static int matchatom(void*__restrict__ x,const unsigned char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) { register struct atom* a=(struct atom*)x; int matchlen=0; @@ -176,6 +210,30 @@ matchlen=1; if (((preg->cflags®_ICASE)?tolower(*s):*s)==a->u.c) goto match; break; + case STRING: + matchlen=a->u.s.len; +#ifdef DEBUG + printf("matching atom STRING \"%.*s\" against \"%.20s\"\n",a->u.s.len,a->u.s.s,s); +#endif + { + int i; + if (preg->cflags®_ICASE) { + for (i=0; iu.s.s[i]) return -1; + } else { + for (i=0; iu.s.s[i]) return -1; + } + } + goto match; + break; + case BACKREF: + matchlen=preg->l[(unsigned char)(a->u.c)].rm_eo-preg->l[(unsigned char)(a->u.c)].rm_so; +#ifdef DEBUG + printf("matching atom BACKREF %d (\"%.*s\") against \"%.20s\"\n",a->u.c,matchlen,s-ofs+preg->l[a->u.c].rm_so,s); +#endif + if (memcmp(s-ofs+preg->l[(unsigned char)(a->u.c)].rm_so,s,matchlen)==0) goto match; + break; } return -1; match: @@ -226,10 +284,36 @@ } else if (*s=='>') { a->type=WORDEND; break; + } else if (*s>='1' && *s<=(rx->brackets+'1') && ((rx->cflags®_EXTENDED)==0)) { + a->type=BACKREF; + a->u.c=*s-'0'; + break; } + /* fall through */ default: a->type=CHAR; - a->u.c=rx->cflags®_ICASE?tolower(*s):*s; + if (rx->cflags®_ICASE) { + a->u.c=tolower(*s); + a->m=(matcher)matchatom_CHAR_ICASE; + } else { + a->u.c=*s; + a->m=(matcher)matchatom_CHAR; + } + /* optimization: if we have a run of CHAR, make it into a STRING */ + { + size_t i; + for (i=1; s[i] && !strchr("(|)[.^$\\*+?{",s[i]); ++i) ; + if (!strchr("*+?{",s[i])) --i; + if (i>2) { + a->m=(matcher)matchatom; + a->type=STRING; + a->u.s.len=i; + if (!(a->u.s.s=malloc(i+1))) return s; + memcpy(a->u.s.s,s,i); + a->u.s.s[i]=0; + return s+i; + } + } break; } return s+1; @@ -444,6 +528,7 @@ if (b->m!=matchempty) { for (i=0; inum-1; ++i) { if (b->p[i+1].min==1 && b->p[i+1].max==1) +/* shortcut: link directly to next atom if it's a piece with min=max=1 */ piece_putnext(&b->p[i],&b->p[i+1].a); else piece_putnext(&b->p[i],&b->p[i+1]); @@ -502,8 +587,10 @@ int j,k; k=r->b[i].num; for (j=0; jb[i].p[j].a.type==REGEX) - __regfree(&r->b[i].p[j].a.u.r); + if (r->b[i].p[j].a.type==REGEX) + __regfree(&r->b[i].p[j].a.u.r); + else if (r->b[i].p[j].a.type==STRING) + free(r->b[i].p[j].a.u.s.s); free(r->b[i].p); } free(r->b); diff -urN -x CVS dietlibc-0.31/libstdio/fflush.c dietlibc/libstdio/fflush.c --- dietlibc-0.31/libstdio/fflush.c 2006-06-01 08:11:34.000000000 +0200 +++ dietlibc/libstdio/fflush.c 2009-01-13 18:58:38.000000000 +0100 @@ -43,11 +43,11 @@ } int __fflush4(FILE *stream,int next) { - if (!__stdio_atexit) { + if (__unlikely(!__stdio_atexit)) { __stdio_atexit=1; atexit(__stdio_flushall); } - if ((stream->flags&BUFINPUT)!=next) { + if (__unlikely((stream->flags&BUFINPUT)!=next)) { int res=fflush_unlocked(stream); stream->flags=(stream->flags&~BUFINPUT)|next; return res; diff -urN -x CVS dietlibc-0.31/libstdio/fgetc_unlocked.c dietlibc/libstdio/fgetc_unlocked.c --- dietlibc-0.31/libstdio/fgetc_unlocked.c 2005-09-21 09:33:08.000000000 +0200 +++ dietlibc/libstdio/fgetc_unlocked.c 2009-02-26 21:51:54.000000000 +0100 @@ -3,15 +3,20 @@ int fgetc_unlocked(FILE *stream) { unsigned char c; - if (!(stream->flags&CANREAD)) goto kaputt; - if (stream->ungotten) { + if (__unlikely(!(stream->flags&CANREAD))) goto kaputt; + if (__unlikely(stream->ungotten)) { stream->ungotten=0; return stream->ungetbuf; } - if (feof_unlocked(stream)) + + /* common case first */ + if (__likely(stream->bmbs)) + return (unsigned char)stream->buf[stream->bm++]; + + if (__unlikely(feof_unlocked(stream))) return EOF; if (__fflush4(stream,BUFINPUT)) return EOF; - if (stream->bm>=stream->bs) { + if (__unlikely(stream->bm>=stream->bs)) { ssize_t len=__libc_read(stream->fd,stream->buf,stream->buflen); if (len==0) { stream->flags|=EOFINDICATOR; diff -urN -x CVS dietlibc-0.31/libstdio/fgets.c dietlibc/libstdio/fgets.c --- dietlibc-0.31/libstdio/fgets.c 2003-11-11 19:39:51.000000000 +0100 +++ dietlibc/libstdio/fgets.c 2009-01-13 18:58:38.000000000 +0100 @@ -1,20 +1,28 @@ #include "dietstdio.h" char *fgets_unlocked(char *s, int size, FILE *stream) { - char *orig=s; int l; - for (l=size; l>1;) { - register int c=fgetc_unlocked(stream); - if (c==EOF) break; - *s=c; - ++s; - --l; - if (c=='\n') break; + for (l=0; lbmbs)) { + /* try common case first */ + c=(unsigned char)stream->buf[stream->bm++]; + } else { + c=fgetc_unlocked(stream); + if (__unlikely(c==EOF)) { + if (!l) return 0; + goto fini; + } + } + s[l]=c; + ++l; + if (c=='\n') { +fini: + s[l]=0; + return s; + } } - if (l==size || ferror_unlocked(stream)) - return 0; - *s=0; - return orig; + return 0; } char*fgets(char*s,int size,FILE*stream) __attribute__((weak,alias("fgets_unlocked"))); diff -urN -x CVS dietlibc-0.31/libstdio/fputc_unlocked.c dietlibc/libstdio/fputc_unlocked.c --- dietlibc-0.31/libstdio/fputc_unlocked.c 2003-11-11 19:27:41.000000000 +0100 +++ dietlibc/libstdio/fputc_unlocked.c 2009-01-13 18:58:38.000000000 +0100 @@ -3,12 +3,12 @@ #include int fputc_unlocked(int c, FILE *stream) { - if (!(stream->flags&CANWRITE) || __fflush4(stream,0)) { + if (!__likely(stream->flags&CANWRITE) || __fflush4(stream,0)) { kaputt: stream->flags|=ERRORINDICATOR; return EOF; } - if (stream->bm>=stream->buflen-1) + if (__unlikely(stream->bm>=stream->buflen-1)) if (fflush_unlocked(stream)) goto kaputt; if (stream->flags&NOBUF) { #if __BYTE_ORDER == __LITTLE_ENDIAN diff -urN -x CVS dietlibc-0.31/libstdio/fwrite.c dietlibc/libstdio/fwrite.c --- dietlibc-0.31/libstdio/fwrite.c 2005-09-21 09:33:08.000000000 +0200 +++ dietlibc/libstdio/fwrite.c 2009-01-13 18:58:38.000000000 +0100 @@ -5,22 +5,43 @@ size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb, FILE *stream) { ssize_t res; - unsigned long len=size*nmemb; - long i; - if (!(stream->flags&CANWRITE)) { + size_t len=size*nmemb; + size_t i,done; + if (!__likely(stream->flags&CANWRITE) || __fflush4(stream,0)) { +kaputt: stream->flags|=ERRORINDICATOR; return 0; } if (!nmemb || len/nmemb!=size) return 0; /* check for integer overflow */ - if (len>stream->buflen || (stream->flags&NOBUF)) { + if (__unlikely(len>stream->buflen || (stream->flags&NOBUF))) { if (fflush_unlocked(stream)) return 0; do { res=__libc_write(stream->fd,ptr,len); } while (res==-1 && errno==EINTR); } else { - register const unsigned char *c=ptr; - for (i=len; i>0; --i,++c) - if (fputc_unlocked(*c,stream)) { res=len-i; goto abort; } + /* try to make the common case fast */ + size_t todo=stream->buflen-stream->bm; + if (todo>len) todo=len; + + if (todo) { + if (stream->flags&BUFLINEWISE) { + for (i=0; ibuf[stream->bm++]=((char*)ptr)[i])=='\n') { + if (fflush_unlocked(stream)) goto kaputt; + } + } + } else { + memcpy(stream->buf+stream->bm,ptr,todo); + stream->bm+=todo; + } + done=todo; + } else + done=0; + for (i=done; iflags&STATICBUF)) free(stream->buf); stream->buf=tmp; - stream->flags &= ~STATICBUF; } + stream->flags &= ~STATICBUF; stream->buflen=size; stream->bm=stream->bs=0; return set_flags(stream,flags); diff -urN -x CVS dietlibc-0.31/libugly/getaddrinfo.c dietlibc/libugly/getaddrinfo.c --- dietlibc-0.31/libugly/getaddrinfo.c 2007-03-26 05:06:59.000000000 +0200 +++ dietlibc/libugly/getaddrinfo.c 2009-03-11 05:03:16.000000000 +0100 @@ -102,11 +102,11 @@ for (foo->ai.ai_socktype=SOCK_STREAM; ; foo->ai.ai_socktype=SOCK_DGRAM) { char* type,* x; if (foo->ai.ai_socktype==SOCK_STREAM) { /* TCP */ - if (hints->ai_socktype==SOCK_DGRAM) continue; + if (hints && hints->ai_socktype==SOCK_DGRAM) continue; foo->ai.ai_protocol=IPPROTO_TCP; type="tcp"; } else { /* UDP */ - if (hints->ai_socktype==SOCK_STREAM) break; + if (hints && hints->ai_socktype==SOCK_STREAM) break; foo->ai.ai_protocol=IPPROTO_UDP; type="udp"; } diff -urN -x CVS dietlibc-0.31/libugly/iswctype.c dietlibc/libugly/iswctype.c --- dietlibc-0.31/libugly/iswctype.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libugly/iswctype.c 2007-09-09 04:11:18.000000000 +0200 @@ -0,0 +1,6 @@ +#include +#include + +int iswctype(wint_t wc, wctype_t desc) { + return desc(wc); +} diff -urN -x CVS dietlibc-0.31/libugly/popen.c dietlibc/libugly/popen.c --- dietlibc-0.31/libugly/popen.c 2002-01-29 19:54:03.000000000 +0100 +++ dietlibc/libugly/popen.c 2008-02-19 14:08:19.000000000 +0100 @@ -13,16 +13,12 @@ if (pipe(pfd)<0) return 0; fd0=(*type=='r'); - if (!(f=fdopen(pfd[!fd0],type))) { + if ((!(f=fdopen(pfd[!fd0],type))) || + ((pid=fork())<0)) { close(pfd[0]); /* malloc failed */ close(pfd[1]); return 0; } - if ((pid=fork())<0) { - close(pfd[0]); - close(pfd[1]); - return 0; - } if (!pid) { /* child */ const char *argv[]={__sh,"-c",0,0}; close(pfd[!fd0]); close(fd0); diff -urN -x CVS dietlibc-0.31/libugly/strptime.c dietlibc/libugly/strptime.c --- dietlibc-0.31/libugly/strptime.c 2007-08-03 22:58:33.000000000 +0200 +++ dietlibc/libugly/strptime.c 2008-11-26 19:43:06.000000000 +0100 @@ -134,6 +134,11 @@ if (i==-1) return 0; tm->tm_year=i-1900; break; + case 'Z': + /* time zone. Not sure what I'm expected to do here. We'll just + * skip to the next whitespace */ + while (*s!=' ' && *s!='\t') ++s; + break; } ++format; break; diff -urN -x CVS dietlibc-0.31/libugly/utent.c dietlibc/libugly/utent.c --- dietlibc-0.31/libugly/utent.c 2005-09-21 09:33:08.000000000 +0200 +++ dietlibc/libugly/utent.c 2008-02-23 01:09:54.000000000 +0100 @@ -5,6 +5,7 @@ static const char *utmp_file_name = _PATH_UTMP; static int fd = -1; +static off_t utmp_current = 0; static int lock_record(int type) { struct flock fl; @@ -37,12 +38,13 @@ if (fd<0) fd = open(utmp_file_name,O_RDWR); if (fd<0) fd = open(utmp_file_name,O_RDONLY); fcntl (fd, F_SETFD, FD_CLOEXEC); - lseek(fd,0,SEEK_SET); + utmp_current = lseek(fd,0,SEEK_SET); } void endutent() { if (fd<0) return; close(fd); fd=-1; + utmp_current = 0; } struct utmp *getutent(void) { @@ -53,6 +55,7 @@ setutent(); if (fd<0) return 0; } + utmp_current = lseek (fd, 0, SEEK_CUR); if (lock_record(F_RDLCK)) return 0; ret=read(fd, &getutent_tmp, sizeof(struct utmp)); unlock_record(); @@ -88,13 +91,16 @@ void pututline(struct utmp *ut) { struct utmp *tmp; + /* Seek to the current record before searching. */ + lseek (fd, utmp_current, SEEK_SET); if ((tmp = getutid(ut))) { lseek(fd, - (off_t)sizeof(struct utmp), SEEK_CUR); if (lock_record(F_WRLCK)) return; write(fd, ut, sizeof(struct utmp)); + utmp_current += sizeof(struct utmp); } else { - lseek(fd, 0, SEEK_END); + utmp_current = lseek(fd, 0, SEEK_END); if (lock_record(F_WRLCK)) return; write(fd, ut, sizeof(struct utmp)); } diff -urN -x CVS dietlibc-0.31/libugly/__utmp_block_signals.c dietlibc/libugly/__utmp_block_signals.c --- dietlibc-0.31/libugly/__utmp_block_signals.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libugly/__utmp_block_signals.c 2008-02-23 01:09:54.000000000 +0100 @@ -0,0 +1,45 @@ +#include + +/* + * Block a bunch of signals. Call with a sigset_t pointer into which + * the old signal set is placed. On error (which should never happen), + * returns NULL, otherwise returns oldset. + */ + +sigset_t *__utmp_block_signals (sigset_t *oldset); + +sigset_t * +__utmp_block_signals (sigset_t *oldset) +{ + sigset_t blockset; + + /* There are actually more signals to block than not, so just start + * with everything */ + sigfillset (&blockset); + + /* Don't try to block program error signals */ + + /* Unconditionally defined signals */ + sigdelset (&blockset, SIGILL); + sigdelset (&blockset, SIGTRAP); + sigdelset (&blockset, SIGABRT); + sigdelset (&blockset, SIGIOT); /* Yeah, right */ + sigdelset (&blockset, SIGFPE); + sigdelset (&blockset, SIGSEGV); + + /* Others. FIXME - This list may need to be expanded. */ +#ifdef SIGBUS + sigdelset (&blockset, SIGBUS); +#endif +#ifdef SIGEMT + sigdelset (&blockset, SIGEMT); +#endif +#ifdef SIGSYS + sigdelset (&blockset, SIGSYS); +#endif + + if (sigprocmask (SIG_BLOCK, &blockset, oldset) < 0) + oldset = (sigset_t *)0; + + return oldset; +} diff -urN -x CVS dietlibc-0.31/libugly/__utmp_io.c dietlibc/libugly/__utmp_io.c --- dietlibc-0.31/libugly/__utmp_io.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libugly/__utmp_io.c 2008-02-23 01:09:54.000000000 +0100 @@ -0,0 +1,47 @@ +#include +#include +#include + +void *__utmp_io(int fd, void *ut, ssize_t len, off_t *offset, int type); + +/* type: F_RDLCK or F_WRLCK */ +void * +__utmp_io(int fd, void *ut, ssize_t len, off_t *offset, int type) { + int e, ret; + struct flock fl; + off_t newoffset; + + fl.l_whence = SEEK_CUR; + fl.l_start = 0; + fl.l_len = len; + fl.l_pid = 0; + fl.l_type = type; + + if (fcntl(fd, F_SETLKW, &fl)) return 0; + if (type == F_WRLCK) { + ret = write(fd, ut, len); + e = errno; + fsync (fd); + /* FIXME - where exactly should the offset point after a write? */ + newoffset = lseek (fd, 0, SEEK_CUR); + } else { + newoffset = lseek (fd, 0, SEEK_CUR); + ret = read(fd, ut, len); + e = errno; + } + + fl.l_start = -(len); + fl.l_type = F_UNLCK; + + fcntl(fd, F_SETLK, &fl); + + /* Arrrgh! There's no provision in the POSIX utmp spec for detecting errors. + * Stupidly update the offset. */ + if (offset) + *offset = newoffset; + + errno = e; + if (ret != len) + return (void *)0; + return ut; +} diff -urN -x CVS dietlibc-0.31/libugly/utxent.c dietlibc/libugly/utxent.c --- dietlibc-0.31/libugly/utxent.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libugly/utxent.c 2008-02-23 01:09:54.000000000 +0100 @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include + +static const char *utmp_file_name = _PATH_UTMPX; +static int fd = -1; +static off_t utmp_current = 0; + +/* Forward declaration for utmp common functions */ +void *__utmp_io(int fd, void *ut, ssize_t len, off_t *offset, int type); +sigset_t *__utmp_block_signals (sigset_t *oldset); + +/* See libcompat for utmpxname() */ +void __utmpxname(const char *file); /* keep the compiler happy */ +void __utmpxname(const char *file) { + if (file) + utmp_file_name = file; + else + utmp_file_name = _PATH_UTMPX; +} + +void setutxent() { + sigset_t oldset, *savedset; + + savedset = __utmp_block_signals(&oldset); + if (fd<0) fd = open(utmp_file_name,O_RDWR); + if (fd<0) fd = open(utmp_file_name,O_RDONLY); + fcntl (fd, F_SETFD, FD_CLOEXEC); + utmp_current = lseek(fd,0,SEEK_SET); + if (savedset) + sigprocmask (SIG_SETMASK, savedset, 0); +} + +void endutxent() { + if (fd<0) return; + close(fd); fd=-1; + utmp_current = 0; +} + +struct utmpx *getutxent(void) { + static struct utmpx getutent_tmp, *retval; + ssize_t ret; + sigset_t oldset, *savedset; + + if (fd<0) { + setutxent(); + if (fd<0) return 0; + } + savedset = __utmp_block_signals (&oldset); + + retval = __utmp_io(fd, &getutent_tmp, sizeof(struct utmpx), + &utmp_current, F_RDLCK); + + if (savedset) + sigprocmask (SIG_SETMASK, savedset, 0); + + return retval; +} + +struct utmpx *getutxid(struct utmpx *ut) { + struct utmpx *tmp; + + while ((tmp = getutxent())) { + if (ut->ut_type && (ut->ut_type <= OLD_TIME)) { + if (ut->ut_type == tmp->ut_type) break; + } + if ((ut->ut_type >= INIT_PROCESS) && (ut->ut_type <= DEAD_PROCESS)) { + if (!strncmp(ut->ut_id,tmp->ut_id,4)) break; + } + } + return tmp; +} + +struct utmpx *getutxline(struct utmpx *ut) { + struct utmpx *tmp; + + while ((tmp = getutxent())) { + if ((tmp->ut_type == USER_PROCESS) || (tmp->ut_type == LOGIN_PROCESS)) { + if (!strncmp(ut->ut_line,tmp->ut_line,__UT_LINESIZE)) break; + } + } + return tmp; +} + +struct utmpx *pututxline(struct utmpx *ut) { + struct utmpx *tmp, ut_copy, *retval = 0, *result; + int e; + ssize_t bytes_written; + sigset_t oldset, *savedset; + + /* It's kosher to call this function with a pointer to our own static + * utmp structure, so work with a copy of "ut" */ + + memcpy (&ut_copy, ut, sizeof (struct utmpx)); + + savedset = __utmp_block_signals (&oldset); + + /* Seek to the current record before searching. */ + lseek (fd, utmp_current, SEEK_SET); + if ((tmp = getutxid(&ut_copy))) { + lseek(fd, - (off_t)sizeof(struct utmpx), SEEK_CUR); + result = __utmp_io (fd, &ut_copy, sizeof(struct utmpx), + &utmp_current, F_WRLCK); + e = errno; + } else { + utmp_current = lseek(fd, 0, SEEK_END); + result = __utmp_io (fd, &ut_copy, sizeof(struct utmpx), + &utmp_current, F_WRLCK); + e = errno; + } + if (savedset) + sigprocmask (SIG_SETMASK, savedset, 0); + + if (result) { + retval = ut; + } + + memcpy (ut, &ut_copy, sizeof (struct utmpx)); + errno = e; + return retval; +} + diff -urN -x CVS dietlibc-0.31/libugly/wctype.c dietlibc/libugly/wctype.c --- dietlibc-0.31/libugly/wctype.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/libugly/wctype.c 2007-09-09 04:11:18.000000000 +0200 @@ -0,0 +1,24 @@ +#include +#include + +struct { const char* name; wctype_t func; } types[]={ + { "alnum", iswalnum }, + { "alpha", iswalpha }, + { "blank", iswblank }, + { "cntrl", iswcntrl }, + { "digit", iswdigit }, + { "graph", iswgraph }, + { "lower", iswlower }, + { "print", iswprint }, + { "punct", iswpunct }, + { "space", iswspace }, + { "upper", iswupper }, + { "xdigit", iswxdigit }, +}; + +wctype_t wctype(const char* name) { + size_t i; + for (i=0; i + +int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n) { + size_t i; + for (i=0; i + +wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t n) { + size_t i; + for (i=0; i + +wchar_t *wmemset(wchar_t *wcs, wchar_t wc, size_t n) { + size_t i; + for (i=0; i $(DESTDIR)/etc/diet.ld.conf; fi + +install-headers: for i in `find include -name \*.h`; do install -m 644 -D $$i $(DESTDIR)$(prefix)/$$i; done + +install: install-bin install-profiling install-pic install-headers + uninstall: for i in start.o libm.a libpthread.a librpc.a liblatin1.a libcompat.a libcrypt.a libc.a; do rm -f $(DESTDIR)$(ILIBDIR)/$$i; done rm -f $(DESTDIR)$(BINDIR)/diet $(DESTDIR)$(BINDIR)/diet-dyn diff -urN -x CVS dietlibc-0.31/mips/syscalls.h dietlibc/mips/syscalls.h --- dietlibc-0.31/mips/syscalls.h 2006-09-19 00:08:39.000000000 +0200 +++ dietlibc/mips/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -312,6 +312,21 @@ #define __NR_tee (__NR_Linux + 306) #define __NR_vmsplice (__NR_Linux + 307) #define __NR_move_pages (__NR_Linux + 308) +#define __NR_set_robust_list (__NR_Linux + 272) +#define __NR_get_robust_list (__NR_Linux + 273) +#define __NR_kexec_load (__NR_Linux + 274) +#define __NR_getcpu (__NR_Linux + 275) +#define __NR_epoll_pwait (__NR_Linux + 276) +#define __NR_ioprio_set (__NR_Linux + 277) +#define __NR_ioprio_get (__NR_Linux + 278) +#define __NR_utimensat (__NR_Linux + 279) +#define __NR_signalfd (__NR_Linux + 280) +#define __NR_timerfd (__NR_Linux + 281) +#define __NR_eventfd (__NR_Linux + 282) +#define __NR_fallocate (__NR_Linux + 283) +#define __NR_timerfd_create (__NR_Linux + 284) +#define __NR_timerfd_gettime (__NR_Linux + 285) +#define __NR_timerfd_settime (__NR_Linux + 286) #define syscall_weak(name,wsym,sym) \ .text; \ diff -urN -x CVS dietlibc-0.31/parisc/mmap2.S dietlibc/parisc/mmap2.S --- dietlibc-0.31/parisc/mmap2.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/parisc/mmap2.S 2008-11-03 04:13:35.000000000 +0100 @@ -0,0 +1,6 @@ +#include "syscalls.h" + +#ifdef __NR_mmap2 +syscall6(mmap2,__mmap2) +#endif + diff -urN -x CVS dietlibc-0.31/parisc/syscalls.h dietlibc/parisc/syscalls.h --- dietlibc-0.31/parisc/syscalls.h 2006-04-04 05:10:40.000000000 +0200 +++ dietlibc/parisc/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -277,8 +277,54 @@ #define __NR_mbind (__NR_Linux + 260) #define __NR_get_mempolicy (__NR_Linux + 261) #define __NR_set_mempolicy (__NR_Linux + 262) +#define __NR_vserver (__NR_Linux + 263) +#define __NR_add_key (__NR_Linux + 264) +#define __NR_request_key (__NR_Linux + 265) +#define __NR_keyctl (__NR_Linux + 266) +#define __NR_ioprio_set (__NR_Linux + 267) +#define __NR_ioprio_get (__NR_Linux + 268) +#define __NR_inotify_init (__NR_Linux + 269) +#define __NR_inotify_add_watch (__NR_Linux + 270) +#define __NR_inotify_rm_watch (__NR_Linux + 271) +#define __NR_migrate_pages (__NR_Linux + 272) +#define __NR_pselect6 (__NR_Linux + 273) +#define __NR_ppoll (__NR_Linux + 274) +#define __NR_openat (__NR_Linux + 275) +#define __NR_mkdirat (__NR_Linux + 276) +#define __NR_mknodat (__NR_Linux + 277) +#define __NR_fchownat (__NR_Linux + 278) +#define __NR_futimesat (__NR_Linux + 279) +#define __NR_fstatat64 (__NR_Linux + 280) +#define __NR_unlinkat (__NR_Linux + 281) +#define __NR_renameat (__NR_Linux + 282) +#define __NR_linkat (__NR_Linux + 283) +#define __NR_symlinkat (__NR_Linux + 284) +#define __NR_readlinkat (__NR_Linux + 285) +#define __NR_fchmodat (__NR_Linux + 286) +#define __NR_faccessat (__NR_Linux + 287) +#define __NR_unshare (__NR_Linux + 288) +#define __NR_set_robust_list (__NR_Linux + 289) +#define __NR_get_robust_list (__NR_Linux + 290) +#define __NR_splice (__NR_Linux + 291) +#define __NR_sync_file_range (__NR_Linux + 292) +#define __NR_tee (__NR_Linux + 293) +#define __NR_vmsplice (__NR_Linux + 294) +#define __NR_move_pages (__NR_Linux + 295) +#define __NR_getcpu (__NR_Linux + 296) +#define __NR_epoll_pwait (__NR_Linux + 297) +#define __NR_statfs64 (__NR_Linux + 298) +#define __NR_fstatfs64 (__NR_Linux + 299) +#define __NR_kexec_load (__NR_Linux + 300) +#define __NR_utimensat (__NR_Linux + 301) +#define __NR_signalfd (__NR_Linux + 302) +#define __NR_timerfd (__NR_Linux + 303) +#define __NR_eventfd (__NR_Linux + 304) +#define __NR_fallocate (__NR_Linux + 305) +#define __NR_timerfd_create (__NR_Linux + 306) +#define __NR_timerfd_settime (__NR_Linux + 307) +#define __NR_timerfd_gettime (__NR_Linux + 308) -#define __NR_Linux_syscalls 263 +#define __NR_Linux_syscalls (__NR_fallocate + 1) #define LINUX_GATEWAY_ADDR 0x100 diff -urN -x CVS dietlibc-0.31/ppc/syscalls.h dietlibc/ppc/syscalls.h --- dietlibc-0.31/ppc/syscalls.h 2006-09-19 00:08:39.000000000 +0200 +++ dietlibc/ppc/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -299,6 +299,18 @@ #define __NR_faccessat 298 #define __NR_get_robust_list 299 #define __NR_set_robust_list 300 +#define __NR_move_pages 301 +#define __NR_getcpu 302 +#define __NR_epoll_pwait 303 +#define __NR_utimensat 304 +#define __NR_signalfd 305 +#define __NR_timerfd 306 +#define __NR_eventfd 307 +#define __NR_sync_file_range2 308 +#define __NR_fallocate 309 +#define __NR_subpage_prot 310 +#define __NR_timerfd_settime 311 +#define __NR_timerfd_gettime 312 #define syscall_weak(name,wsym,sym) \ diff -urN -x CVS dietlibc-0.31/ppc64/syscalls.h dietlibc/ppc64/syscalls.h --- dietlibc-0.31/ppc64/syscalls.h 2006-09-19 00:08:39.000000000 +0200 +++ dietlibc/ppc64/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -299,7 +299,18 @@ #define __NR_faccessat 298 #define __NR_get_robust_list 299 #define __NR_set_robust_list 300 - +#define __NR_move_pages 301 +#define __NR_getcpu 302 +#define __NR_epoll_pwait 303 +#define __NR_utimensat 304 +#define __NR_signalfd 305 +#define __NR_timerfd 306 +#define __NR_eventfd 307 +#define __NR_sync_file_range2 308 +#define __NR_fallocate 309 +#define __NR_subpage_prot 310 +#define __NR_timerfd_settime 311 +#define __NR_timerfd_gettime 312 #define __diet_proto_common(sym) \ diff -urN -x CVS dietlibc-0.31/s390/syscalls.h dietlibc/s390/syscalls.h --- dietlibc-0.31/s390/syscalls.h 2006-09-19 00:08:39.000000000 +0200 +++ dietlibc/s390/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -293,6 +293,18 @@ #define __NR_sync_file_range 307 #define __NR_tee 308 #define __NR_vmsplice 309 +/* Number 310 is reserved for new sys_move_pages */ +#define __NR_getcpu 311 +#define __NR_epoll_pwait 312 +#define __NR_utimes 313 +#define __NR_fallocate 314 +#define __NR_utimensat 315 +#define __NR_signalfd 316 +#define __NR_timerfd 317 +#define __NR_eventfd 318 +#define __NR_timerfd_create 319 +#define __NR_timerfd_settime 320 +#define __NR_timerfd_gettime 321 #define syscall_weak(name,wsym,sym) \ diff -urN -x CVS dietlibc-0.31/s390x/syscalls.h dietlibc/s390x/syscalls.h --- dietlibc-0.31/s390x/syscalls.h 2006-09-19 00:08:39.000000000 +0200 +++ dietlibc/s390x/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -293,6 +293,18 @@ #define __NR_sync_file_range 307 #define __NR_tee 308 #define __NR_vmsplice 309 +/* Number 310 is reserved for new sys_move_pages */ +#define __NR_getcpu 311 +#define __NR_epoll_pwait 312 +#define __NR_utimes 313 +#define __NR_fallocate 314 +#define __NR_utimensat 315 +#define __NR_signalfd 316 +#define __NR_timerfd 317 +#define __NR_eventfd 318 +#define __NR_timerfd_create 319 +#define __NR_timerfd_settime 320 +#define __NR_timerfd_gettime 321 /* diff -urN -x CVS dietlibc-0.31/sparc/syscalls.h dietlibc/sparc/syscalls.h --- dietlibc-0.31/sparc/syscalls.h 2006-09-19 00:08:39.000000000 +0200 +++ dietlibc/sparc/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -300,6 +300,21 @@ #define __NR_unshare 299 #define __NR_set_robust_list 300 #define __NR_get_robust_list 301 +#define __NR_migrate_pages 302 +#define __NR_mbind 303 +#define __NR_get_mempolicy 304 +#define __NR_set_mempolicy 305 +#define __NR_kexec_load 306 +#define __NR_move_pages 307 +#define __NR_getcpu 308 +#define __NR_epoll_pwait 309 +#define __NR_utimensat 310 +#define __NR_signalfd 311 +#define __NR_timerfd 312 +#define __NR_eventfd 313 +#define __NR_fallocate 314 +#define __NR_timerfd_settime 315 +#define __NR_timerfd_gettime 316 #define syscall_weak(name,wsym,sym) \ .text; \ diff -urN -x CVS dietlibc-0.31/sparc64/syscalls.h dietlibc/sparc64/syscalls.h --- dietlibc-0.31/sparc64/syscalls.h 2006-09-19 00:08:39.000000000 +0200 +++ dietlibc/sparc64/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -299,6 +299,21 @@ #define __NR_unshare 299 #define __NR_set_robust_list 300 #define __NR_get_robust_list 301 +#define __NR_migrate_pages 302 +#define __NR_mbind 303 +#define __NR_get_mempolicy 304 +#define __NR_set_mempolicy 305 +#define __NR_kexec_load 306 +#define __NR_move_pages 307 +#define __NR_getcpu 308 +#define __NR_epoll_pwait 309 +#define __NR_utimensat 310 +#define __NR_signalfd 311 +#define __NR_timerfd 312 +#define __NR_eventfd 313 +#define __NR_fallocate 314 +#define __NR_timerfd_settime 315 +#define __NR_timerfd_gettime 316 #define syscall_weak(name,wsym,sym) \ .text; \ diff -urN -x CVS dietlibc-0.31/syscalls.s/__signalfd.S dietlibc/syscalls.s/__signalfd.S --- dietlibc-0.31/syscalls.s/__signalfd.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/syscalls.s/__signalfd.S 2008-02-19 01:28:13.000000000 +0100 @@ -0,0 +1,5 @@ +#include "syscalls.h" + +#ifdef __NR_signalfd +syscall(signalfd,__signalfd) +#endif diff -urN -x CVS dietlibc-0.31/syscalls.s/splice.S dietlibc/syscalls.s/splice.S --- dietlibc-0.31/syscalls.s/splice.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/syscalls.s/splice.S 2008-02-19 01:28:13.000000000 +0100 @@ -0,0 +1,5 @@ +#include "syscalls.h" + +#ifdef __NR_splice +syscall(splice,splice) +#endif diff -urN -x CVS dietlibc-0.31/syscalls.s/tee.S dietlibc/syscalls.s/tee.S --- dietlibc-0.31/syscalls.s/tee.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/syscalls.s/tee.S 2008-02-19 01:28:13.000000000 +0100 @@ -0,0 +1,5 @@ +#include "syscalls.h" + +#ifdef __NR_tee +syscall(tee,tee) +#endif diff -urN -x CVS dietlibc-0.31/syscalls.s/timerfd.S dietlibc/syscalls.s/timerfd.S --- dietlibc-0.31/syscalls.s/timerfd.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/syscalls.s/timerfd.S 2008-02-19 01:28:13.000000000 +0100 @@ -0,0 +1,5 @@ +#include "syscalls.h" + +#ifdef __NR_timerfd +syscall(timerfd,__timerfd) +#endif diff -urN -x CVS dietlibc-0.31/syscalls.s/vmsplice.S dietlibc/syscalls.s/vmsplice.S --- dietlibc-0.31/syscalls.s/vmsplice.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/syscalls.s/vmsplice.S 2008-02-19 01:28:13.000000000 +0100 @@ -0,0 +1,5 @@ +#include "syscalls.h" + +#ifdef __NR_vmsplice +syscall(vmsplice,vmsplice) +#endif diff -urN -x CVS dietlibc-0.31/t.c dietlibc/t.c --- dietlibc-0.31/t.c 2005-10-08 23:11:32.000000000 +0200 +++ dietlibc/t.c 2009-02-26 21:51:54.000000000 +0100 @@ -105,12 +105,22 @@ #define rdtscl(low) \ __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx") +#define malloc(x) ({typeof(x) y=x; (y<0 || (size_t)(y)!=y ? 0 : malloc(y));}) + int main(int argc,char *argv[]) { +#if 0 + char* a=malloc(-3); + char* b=malloc(0xffffffffull+1); + printf("%p %p\n",a,b); +#endif + printf("%u\n",getpagesize()); +#if 0 struct stat s; time_t t=time(0); struct tm* T; stat("/tmp/nyt.html",&s); T=gmtime(&s.st_mtime); +#endif #if 0 static struct mq_attr x; mqd_t a=mq_open("fnord",O_WRONLY|O_CREAT,0600,&x); diff -urN -x CVS dietlibc-0.31/test/Makefile dietlibc/test/Makefile --- dietlibc-0.31/test/Makefile 2003-12-15 14:07:42.000000000 +0100 +++ dietlibc/test/Makefile 2008-02-23 01:02:19.000000000 +0100 @@ -11,9 +11,9 @@ 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 \ +memccpy memchr memcmp 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 \ +speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr \ strstr strtol sysenter ungetc waitpid test: $(TESTPROGRAMS) diff -urN -x CVS dietlibc-0.31/test/mbrlen.c dietlibc/test/mbrlen.c --- dietlibc-0.31/test/mbrlen.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/test/mbrlen.c 2008-09-30 23:02:35.000000000 +0200 @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +main() { + static mbstate_t ps; + setlocale(LC_CTYPE,"de_DE.UTF8"); + /* does it parse a single multibyte sequence OK? */ + assert(mbrlen("\xc2\xa9",2,&ps)==2); + /* does it whine about an invalid sequence? */ + assert(mbrlen("\xa9",1,&ps)==(size_t)-1); + /* does it accept a multibyte sequence in two parts? */ + printf("%d\n",mbrlen("\xc2\xa9",1,&ps)); + printf("%d\n",mbrlen("\xa9""fnord",6,&ps)); + /* does it parse non-sequence stuff right? */ + assert(mbrlen("f",1,&ps)==1); +} diff -urN -x CVS dietlibc-0.31/test/mbtowc.c dietlibc/test/mbtowc.c --- dietlibc-0.31/test/mbtowc.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/test/mbtowc.c 2007-09-09 03:37:54.000000000 +0200 @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include +#include + +int main() { + wchar_t ws; + char* c="fn\xc3\xb6rd"; + size_t n=strlen(c); + setlocale(LC_CTYPE,"de_DE.UTF8"); + + ws=0; + assert(mbtowc(&ws,c,6)==1 && ws==102); + assert(mbtowc(&ws,c+1,5)==1 && ws==110); + assert(mbtowc(&ws,c+2,4)==2 && ws==246); + assert(mbtowc(&ws,c+4,2)==1 && ws==114); + assert(mbtowc(&ws,c+5,1)==1 && ws==100); + assert(mbtowc(&ws,c+6,1)==0); + + errno=0; + c="fnörd"; + assert(mbtowc(&ws,c,6)==1 && ws==102); + assert(mbtowc(&ws,c+1,5)==1 && ws==110); + assert(mbtowc(&ws,c+2,4)==(size_t)-1 && errno==EILSEQ); +} diff -urN -x CVS dietlibc-0.31/test/memcpy.c dietlibc/test/memcpy.c --- dietlibc-0.31/test/memcpy.c 2003-02-20 16:57:13.000000000 +0100 +++ dietlibc/test/memcpy.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,11 +0,0 @@ -#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 -urN -x CVS dietlibc-0.31/test/popen.c dietlibc/test/popen.c --- dietlibc-0.31/test/popen.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/test/popen.c 2008-02-19 14:08:19.000000000 +0100 @@ -0,0 +1,11 @@ +#include +#include + +int main() { + FILE* f; + char buf[1024]; + assert(f=popen("/bin/echo foo","r")); + assert(fgets(buf,sizeof(buf),f)); + assert(fclose(f)==0); + assert(!strcmp(buf,"foo\n")); +} diff -urN -x CVS dietlibc-0.31/test/printf.c dietlibc/test/printf.c --- dietlibc-0.31/test/printf.c 2004-01-07 16:06:48.000000000 +0100 +++ dietlibc/test/printf.c 2008-02-19 01:28:13.000000000 +0100 @@ -38,7 +38,8 @@ #define TEST_SNPRINTF(EXP,SZ, ...) \ { \ volatile char * args[] = { EXP, #SZ }; \ - int test_sz=MIN((SZ),sizeof(EXP))-1; \ + ssize_t test_sz=MIN((SZ),sizeof(EXP))-1; \ + (void)args; \ TEST_INIT(EXP); \ rc=snprintf(buf+ALGN,(SZ),__VA_ARGS__); \ TEST_CHECK(EXP, test_sz); \ @@ -80,6 +81,7 @@ TEST("foobar", "%s", "foobar"); TEST("01.23", "%05.2f", 1.23); + TEST("001.2", "%05.2g", 1.23); TEST("42", "%i", 42); TEST("", "%.0i", 0); @@ -111,6 +113,24 @@ TEST("0x1", "%#x", 1); + TEST("abcX", "%2sX", "abc"); + TEST("abcX", "%-2sX", "abc"); + + TEST("001234", "%.6u", 1234); + TEST("-001234", "%.6i", -1234); + TEST(" 1234", "%6u", 1234); + TEST(" -1234", "%6i", -1234); + TEST("001234", "%06u", 1234); + TEST("-01234", "%06i", -1234); + TEST("1234 ", "%-6u", 1234); + TEST("-1234 ", "%-6i", -1234); + TEST("1234", "%.6s", "1234"); + TEST(" 1234", "%6s", "1234"); + TEST("1234 ", "%-6s", "1234"); + TEST(" 01234", "%6.5u", 1234); + TEST("-01234", "%6.5i", -1234); + TEST(" 1234", "%6.5s", "1234"); + #ifdef XSI_TESTS setlocale(LC_ALL, "de_DE"); diff -urN -x CVS dietlibc-0.31/test/regex.c dietlibc/test/regex.c --- dietlibc-0.31/test/regex.c 2005-07-23 01:08:15.000000000 +0200 +++ dietlibc/test/regex.c 2008-12-22 01:25:54.000000000 +0100 @@ -101,6 +101,17 @@ assert(regexec(&r,"leitner@home.fefe.de",10,matches,0)==0); regfree(&r); + assert(regcomp(&r,"^chello[0-9]*.chello.[a-z][a-z]$",REG_EXTENDED)==0); + assert(regexec(&r,"chello089078194199.chello.pl",10,matches,0)==0); + regfree(&r); + + assert(regcomp(&r,"(satel.com|kievnet.com|dn|merlin.net|inetcom.com|zdn.gov|terabit.com|od|odessa|elencom.net|uz|syndicate.org|tvcom.net|dn|qt.net|b-net.com).ua",REG_EXTENDED|REG_ICASE|REG_NOSUB)==0); + assert(regexec(&r,"mail.b-net.com.ua",0,NULL,0)==0); + regfree(&r); + + assert(regcomp(&r,"(foo)bar\\1",0)==0); + assert(regexec(&r,"foobarfoo",10,matches,0)==0); + regfree(&r); #if 0 printf("regcomp %d\n",regcomp(&r,"\\.( ? ? ?\\.)*\\.",REG_EXTENDED|REG_NOSUB)); diff -urN -x CVS dietlibc-0.31/test/runtests.sh dietlibc/test/runtests.sh --- dietlibc-0.31/test/runtests.sh 2003-12-15 14:07:42.000000000 +0100 +++ dietlibc/test/runtests.sh 2008-02-23 01:02:19.000000000 +0100 @@ -1,6 +1,6 @@ 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" +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 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 strncat strncpy strptime strrchr strstr strtol sysenter ungetc waitpid" STDIN="read1" PASS="getpass" diff -urN -x CVS dietlibc-0.31/test/stdio/tst-fphex.c dietlibc/test/stdio/tst-fphex.c --- dietlibc-0.31/test/stdio/tst-fphex.c 2003-12-15 14:07:42.000000000 +0100 +++ dietlibc/test/stdio/tst-fphex.c 2008-05-09 06:36:56.000000000 +0200 @@ -37,7 +37,7 @@ 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", + printf ("%s\tExpected \"%s\" (%zu)\n\tGot \"%s\" (%d, %zu)\n", t->fmt, t->expect, strlen (t->expect), buf, n, strlen (buf)); result = 1; } diff -urN -x CVS dietlibc-0.31/test/stdio/tst-fseek.c dietlibc/test/stdio/tst-fseek.c --- dietlibc-0.31/test/stdio/tst-fseek.c 2003-12-15 14:07:42.000000000 +0100 +++ dietlibc/test/stdio/tst-fseek.c 2008-05-09 06:36:56.000000000 +0200 @@ -18,6 +18,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#define _FILE_OFFSET_BITS 64 #define _GNU_SOURCE #include #include @@ -38,8 +39,8 @@ const char outstr[] = "hello world!\n"; char strbuf[sizeof outstr]; char buf[200]; - struct stat64 st1; - struct stat64 st2; + struct stat st1; + struct stat st2; int result = 0; tmpdir = getenv ("TMPDIR"); @@ -315,9 +316,9 @@ } /* Check the access time. */ - if (fstat64 (fd, &st1) < 0) + if (fstat (fd, &st1) < 0) { - printf ("%d: fstat64() before fseeko() failed\n\n", __LINE__); + printf ("%d: fstat() before fseeko() failed\n\n", __LINE__); result = 1; } else @@ -338,9 +339,9 @@ sleep (1); t = time (NULL); - if (fstat64 (fd, &st2) < 0) + if (fstat (fd, &st2) < 0) { - printf ("%d: fstat64() after fseeko() failed\n\n", __LINE__); + printf ("%d: fstat() after fseeko() failed\n\n", __LINE__); result = 1; } if (st1.st_ctime >= t) @@ -424,9 +425,9 @@ printf ("%d: fopen() failed\n\n", __LINE__); result = 1; } - else if (fstat64 (fileno (fp), &st1) < 0) + else if (fstat (fileno (fp), &st1) < 0) { - printf ("%d: fstat64() before fseeko() failed\n\n", __LINE__); + printf ("%d: fstat() before fseeko() failed\n\n", __LINE__); result = 1; } else if (fseeko (fp, 0, SEEK_END) != 0) @@ -436,7 +437,7 @@ } else if (ftello (fp) != st1.st_size) { - printf ("%d: fstat64 st_size %zd ftello %zd\n", __LINE__, + printf ("%d: fstat st_size %zd ftello %zd\n", __LINE__, (size_t) st1.st_size, (size_t) ftello (fp)); result = 1; } @@ -451,9 +452,9 @@ printf ("%d: fopen() failed\n\n", __LINE__); result = 1; } - else if (fstat64 (fileno (fp), &st1) < 0) + else if (fstat (fileno (fp), &st1) < 0) { - printf ("%d: fstat64() before fgetc() failed\n\n", __LINE__); + printf ("%d: fstat() before fgetc() failed\n\n", __LINE__); result = 1; } else if (fgetc (fp) == EOF) @@ -468,7 +469,7 @@ } else if (ftello (fp) != st1.st_size) { - printf ("%d: fstat64 st_size %zd ftello %zd\n", __LINE__, + printf ("%d: fstat st_size %zd ftello %zd\n", __LINE__, (size_t) st1.st_size, (size_t) ftello (fp)); result = 1; } diff -urN -x CVS dietlibc-0.31/test/strchr.c dietlibc/test/strchr.c --- dietlibc-0.31/test/strchr.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/test/strchr.c 2007-12-05 23:41:01.000000000 +0100 @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +int main() { + char* p="/opt/diet/bin:/home/leitner/bin:/usr/local/bin:/opt/cross/bin:/usr/local/sbin:/usr/bin:/sbin:/bin:/usr/sbin:/usr/X11R6/bin:/opt/teTeX/bin:/opt/qt-4.3.2/bin:/opt/kde-3.5/bin:/usr/X11R7/bin:/opt/mono/bin"; + assert(strchr(p,':')==p+13); + assert(strchr(p="fnord",'\0')==p+5); + assert(strchr(p,'r')==p+3); + assert(strchr(p,'x')==0); + return 0; +} diff -urN -x CVS dietlibc-0.31/test/strcmp.c dietlibc/test/strcmp.c --- dietlibc-0.31/test/strcmp.c 2003-12-21 13:06:36.000000000 +0100 +++ dietlibc/test/strcmp.c 2007-12-05 23:41:01.000000000 +0100 @@ -10,11 +10,14 @@ int main() { char buf[100]="fnord"; char buf2[100]="fnort"; - if (strcmp(buf,buf)) die("strcmp say a != a"); + if (strcmp(buf,buf)) die("strcmp said 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"); + if (strcmp(buf+1,buf2+1)>=0) die("unaligned strcmp is broken 1"); + if (strcmp(buf+2,buf2+2)>=0) die("unaligned strcmp is broken 2"); + if (strcmp(buf+3,buf2+3)>=0) die("unaligned strcmp is broken 3"); + if (strcmp("mäh","meh")<0) die("strcmp uses signed arithmetic"); + if (strcmp("foo","foobar")>=0) die("prefix handling broken in strcmp 1"); + if (strcmp("foobar","foo")<=0) die("prefix handling broken in strcmp 2"); return 0; } diff -urN -x CVS dietlibc-0.31/test/strcpy.c dietlibc/test/strcpy.c --- dietlibc-0.31/test/strcpy.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/test/strcpy.c 2007-11-17 15:29:53.000000000 +0100 @@ -0,0 +1,13 @@ +#include +#include + +int main() { + char buf[128]; + size_t i; + for (i=0; i<100; ++i) { + memset(buf,'x',sizeof(buf)); + strcpy(buf+i,"fnord"); + assert(!strcmp(buf+i,"fnord")); + assert(buf[i+6]=='x'); + } +} diff -urN -x CVS dietlibc-0.31/test/string/Makefile dietlibc/test/string/Makefile --- dietlibc-0.31/test/string/Makefile 2003-12-15 14:07:42.000000000 +0100 +++ dietlibc/test/string/Makefile 2008-02-19 01:28:13.000000000 +0100 @@ -1,10 +1,11 @@ #DIET=diet CC=gcc -CFLAGS=-Wall +CFLAGS=-Wall -fno-builtin all: stringtest -TESTPROGRAMS=memccpy memchr memcmp memcpy memrchr strcasecmp strcmp strlen strncat strncpy strrchr strstr +TESTPROGRAMS=memccpy memchr memcmp memcpy memrchr strcasecmp strcmp strlen strncat strncpy strrchr strstr \ +strspn strcspn strpbrk stringtest: $(TESTPROGRAMS) diff -urN -x CVS dietlibc-0.31/test/string/memcpy.c dietlibc/test/string/memcpy.c --- dietlibc-0.31/test/string/memcpy.c 2003-12-15 14:07:42.000000000 +0100 +++ dietlibc/test/string/memcpy.c 2008-02-23 01:02:19.000000000 +0100 @@ -1,11 +1,52 @@ #include #include +#include + +#define WO (__WORDSIZE/8) int main() { + size_t const LENS[] = { + 1, 2, 3, 4, 5, 6, 7, 8, + WO -3, WO -2, WO -1, WO, WO +1, WO +2, WO +3, WO +4, + WO*2-3, WO*2-2, WO*2-1, WO*2, WO*2+1, WO*2+2, WO*2+3, WO*2+4, + WO*3-3, WO*3-2, WO*3-1, WO*3, WO*3+1, WO*3+2, WO*3+3, WO*3+4, + (size_t)(-1) }; + + size_t i,j; + size_t const *len; 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'); + + /* test all possible alignments of src and destination in combination with + * some interesting lengths */ + for (len=LENS+0; *len!=(size_t)(-1); ++len) { + unsigned char src[WO * 5]; + + for (i=0; i<*len + WO; ++i) + src[i] = i; + + for (i=MIN(WO,*len); i>0;) { + --i; + + for (j=MIN(WO,*len); j>0;) { + unsigned char dst[WO * 5]; + size_t k; + --j; + + for (k=0; k<*len; ++k) + dst[j+k]=src[i+k]+1; + + assert(memcpy(dst+j, src+i, *len)==dst+j); + + for (k=0; k<*len; ++k) + assert(dst[j+k]==src[i+k]); + } + } + } + return 0; } diff -urN -x CVS dietlibc-0.31/test/string/runtests.sh dietlibc/test/string/runtests.sh --- dietlibc-0.31/test/string/runtests.sh 2003-12-15 14:07:42.000000000 +0100 +++ dietlibc/test/string/runtests.sh 2008-02-19 01:28:13.000000000 +0100 @@ -1,6 +1,6 @@ #!/bin/sh -TESTPROGRAMS="memccpy memchr memcmp memcpy memrchr strcasecmp strcmp strlen strncat strncpy strrchr strstr" +TESTPROGRAMS="memccpy memchr memcmp memcpy memrchr strcasecmp strcmp strlen strncat strncpy strrchr strstr strspn strcspn strpbrk" for p in $TESTPROGRAMS; do echo "---";echo testing $p;echo "---" diff -urN -x CVS dietlibc-0.31/test/string/strcspn.c dietlibc/test/string/strcspn.c --- dietlibc-0.31/test/string/strcspn.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/test/string/strcspn.c 2008-02-19 01:28:13.000000000 +0100 @@ -0,0 +1,9 @@ +#include +#include +#include + +int main() { + assert(strcspn("foo:bar:",":")==3); + assert(strcspn("foo:bar:","=of")==0); + return 0; +} diff -urN -x CVS dietlibc-0.31/test/string/strlen.c dietlibc/test/string/strlen.c --- dietlibc-0.31/test/string/strlen.c 2003-12-15 14:07:42.000000000 +0100 +++ dietlibc/test/string/strlen.c 2008-02-19 01:28:13.000000000 +0100 @@ -1,10 +1,35 @@ #include #include +#include + +/* make it large enough to test all possible alignments, number of trailing + * bytes and word sizes */ +#define BUFLEN (__WORDSIZE/8 * 4) int main() { - const char* x="foo bar baz"; + /* will hold the string, the trailing zero and a test pattern */ + char buf[BUFLEN + 1 + __WORDSIZE/8]; + size_t len; + assert(strlen("")==0); - assert(strlen(x)==11); - assert(strlen(x+5)==6); + + for (len=0; len +#include +#include + +int main() { + const char* c; + c="fnord:foo:bar:baz"; assert(strpbrk(c,":")==c+5); + c=":/::/:foo/bar:baz"; assert(strpbrk(c,"/:")==c); + return 0; +} diff -urN -x CVS dietlibc-0.31/test/string/strspn.c dietlibc/test/string/strspn.c --- dietlibc-0.31/test/string/strspn.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/test/string/strspn.c 2008-02-19 01:28:13.000000000 +0100 @@ -0,0 +1,9 @@ +#include +#include +#include + +int main() { + assert(strspn("foo:bar:",":=b")==0); + assert(strspn("foo:bar:",":=of")==4); + return 0; +} diff -urN -x CVS dietlibc-0.31/test/strlen.c dietlibc/test/strlen.c --- dietlibc-0.31/test/strlen.c 2003-02-20 16:57:13.000000000 +0100 +++ dietlibc/test/strlen.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,10 +0,0 @@ -#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 -urN -x CVS dietlibc-0.31/test/wctomb.c dietlibc/test/wctomb.c --- dietlibc-0.31/test/wctomb.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/test/wctomb.c 2007-09-09 03:38:16.000000000 +0200 @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include +#include +#include + +int main() { + wchar_t c[100]; + char buf[100]; + size_t n=0; + c[0]='f'; + c[1]='n'; + c[2]=0xd6; + c[3]='r'; + c[4]='d'; + c[5]=0; + setlocale(LC_CTYPE,"de_DE.UTF8"); + + assert(wctomb(buf,c[0])==1); + assert(wctomb(buf+1,c[1])==1); + assert(wctomb(buf+2,c[2])==2); + assert(wctomb(buf+4,c[3])==1); + assert(wctomb(buf+5,c[4])==1); + buf[6]=0; + assert(!strcmp(buf,"fn\xc3\x96rd")); + +} diff -urN -x CVS dietlibc-0.31/test/wctype.c dietlibc/test/wctype.c --- dietlibc-0.31/test/wctype.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/test/wctype.c 2007-09-09 04:11:18.000000000 +0200 @@ -0,0 +1,9 @@ +#include +#include +#include + +int main() { + wctype_t x; + assert(x=wctype("lower")); + assert(iswctype(L'o',x)); +} diff -urN -x CVS dietlibc-0.31/test/wmem.c dietlibc/test/wmem.c --- dietlibc-0.31/test/wmem.c 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/test/wmem.c 2007-10-08 16:23:59.000000000 +0200 @@ -0,0 +1,52 @@ +#include +#include + +int main() { + wchar_t buf[100]; + int i; + + /* does wmemset work? */ + assert(wmemset(buf,0,100)==buf); + for (i=0; i<100; ++i) assert(buf[i]==0); + + /* do wcscpy and wcscat work? */ + assert(wcscpy(buf,L"fnord")==buf); + assert(wcscat(buf,L"blah")==buf); + assert(wcslen(buf)==9); + assert(wcscmp(buf,L"fnordblah")==0); + + /* does wmemcmp work? */ + assert(wmemcmp(buf,L"fnordxxx",5)==0); + assert(wmemcmp(buf,L"fnordxxx",6)<0); + + /* check wmemcpy */ + assert(wmemcpy(buf+5,buf,5)==buf+5); + assert(wmemcmp(buf,L"fnordfnord",10)==0); + + /* does wmemmove handle overlapping properly */ + assert(wmemmove(buf+1,buf,3)==buf+1); + assert(wmemcmp(buf,L"ffnod",5)==0); + assert(wmemmove(buf,buf+1,3)==buf); + assert(wmemcmp(buf,L"fnood",5)==0); + + /* check wcsncpy */ + assert(wcsncpy(buf,L"fnord",8)==buf); + assert(wmemcmp(buf,L"fnord\0\0\0",8)==0); + buf[5]=L'x'; + assert(wcsncpy(buf,L"test_",5)==buf); + assert(wmemcmp(buf,L"test_x\0\0",8)==0); + + /* check wcsncat */ + wmemset(buf,L'x',10); + wcscpy(buf,L"ab"); + assert(wcsncat(buf,L"cd",5)==buf); // normal case + assert(wmemcmp(buf,L"abcd\0xxxxx",10)==0); + assert(wcsncat(buf,L"efgh",2)==buf); // truncation case + assert(wmemcmp(buf,L"abcdef\0xxx",10)==0); + + /* wcsstr */ + wcscpy(buf,L"abracadabra"); + assert(wcsstr(buf,L"abr")==buf); + assert(wcsstr(buf+1,L"abr")==buf+7); + assert(wcsstr(buf+8,L"abr")==0); +} diff -urN -x CVS dietlibc-0.31/TODO dietlibc/TODO --- dietlibc-0.31/TODO 2006-08-03 16:33:58.000000000 +0200 +++ dietlibc/TODO 2008-05-09 06:36:56.000000000 +0200 @@ -15,7 +15,7 @@ - look at mktime: "Falls tm_isdst == -1 gesetzt, so sollte mktime versuchen herauszufinden, ob Sommerzeit eingestellt ist (und laut linux manpage auch tzname setzen), ansonsten die angegebene DST - berücksichtigen." + berücksichtigen." - better rand()? - try to make zebra compile. - printf %e @@ -32,3 +32,4 @@ set_thread_area -> set up TLD, for stack guard lsearch, lfind, hsearch, tsearch + diff -urN -x CVS dietlibc-0.31/x86_64/dyn_syscalls.S dietlibc/x86_64/dyn_syscalls.S --- dietlibc-0.31/x86_64/dyn_syscalls.S 2006-10-13 22:14:30.000000000 +0200 +++ dietlibc/x86_64/dyn_syscalls.S 2008-12-27 20:53:16.000000000 +0100 @@ -288,6 +288,9 @@ #include "../syscalls.s/lgetxattr.S" #include "../syscalls.s/fgetxattr.S" +#include "../syscalls.s/timerfd.S" +#include "../syscalls.s/__signalfd.S" + #define _exit __exit #include "clone.S" #undef _exit diff -urN -x CVS dietlibc-0.31/x86_64/strchr.S dietlibc/x86_64/strchr.S --- dietlibc-0.31/x86_64/strchr.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/x86_64/strchr.S 2007-12-05 23:41:01.000000000 +0100 @@ -0,0 +1,20 @@ +.text +.type strchr,@function +.global strchr +.weak index +.type index,@function + +index: +strchr: + xchg %rsi,%rdi +.Lloop: + lodsb + cmp %al,%dil + jz .Lfound + or %al,%al + jnz .Lloop + xor %eax,%eax + ret +.Lfound: + lea -1(%rsi),%rax + ret diff -urN -x CVS dietlibc-0.31/x86_64/strcmp.S dietlibc/x86_64/strcmp.S --- dietlibc-0.31/x86_64/strcmp.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/x86_64/strcmp.S 2007-12-05 23:41:01.000000000 +0100 @@ -0,0 +1,27 @@ +.text +.global strcmp +.type strcmp,@function +.weak strcoll +.type strcoll,@function + +strcoll: +strcmp: +.Lloop: + mov (%rdi),%al + cmp (%rsi),%al + jnz .Lmismatch + inc %rsi + inc %rdi + or %al,%al + jnz .Lloop + /* end of string reached, return NULL */ + xor %eax,%eax + ret +.Lmismatch: +/* In the C version we return (unsigned char)*b-(unsigned char)*a + but in assembler it is less trouble to return 1 or -1 + depending on whether the carry flag is set. + The standard only wants positive, zero, or negative, so both are OK */ + sbb %eax,%eax + or $1,%eax + ret diff -urN -x CVS dietlibc-0.31/x86_64/strcpy.S dietlibc/x86_64/strcpy.S --- dietlibc-0.31/x86_64/strcpy.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/x86_64/strcpy.S 2008-09-05 17:13:29.000000000 +0200 @@ -0,0 +1,15 @@ +.text +.align 0 +.global strcpy +.type strcpy,@function +strcpy: + mov %rdi,%rdx + +.Lloop: + lodsb + test %al, %al + stosb + jnz .Lloop + + mov %rdx,%rax + ret diff -urN -x CVS dietlibc-0.31/x86_64/syscalls.h dietlibc/x86_64/syscalls.h --- dietlibc-0.31/x86_64/syscalls.h 2006-09-19 00:08:39.000000000 +0200 +++ dietlibc/x86_64/syscalls.h 2008-09-30 23:02:35.000000000 +0200 @@ -325,6 +325,15 @@ #define __NR_sync_file_range 277 #define __NR_vmsplice 278 #define __NR_move_pages 279 +#define __NR_utimensat 280 +#define __IGNORE_getcpu /* implemented as a vsyscall */ +#define __NR_epoll_pwait 281 +#define __NR_signalfd 282 +#define __NR_timerfd 283 +#define __NR_eventfd 284 +#define __NR_fallocate 285 +#define __NR_timerfd_settime 286 +#define __NR_timerfd_gettime 287 #ifdef __PIC__ #define syscall_weak(name,wsym,sym) \ @@ -356,14 +365,24 @@ .type sym,@function; \ .global sym; \ sym: \ +.ifge __NR_##name-256 ; \ + mov $__NR_##name,%ax; \ + jmp __unified_syscall_16bit; \ +.else ; \ mov $__NR_##name,%al; \ - jmp __unified_syscall + jmp __unified_syscall; \ +.endif #define syscall(name,sym) \ .text; \ .type sym,@function; \ .global sym; \ sym: \ +.ifge __NR_##name-256 ; \ + mov $__NR_##name,%ax; \ + jmp __unified_syscall_16bit; \ +.else ; \ mov $__NR_##name,%al; \ - jmp __unified_syscall + jmp __unified_syscall; \ +.endif #endif diff -urN -x CVS dietlibc-0.31/x86_64/time.S dietlibc/x86_64/time.S --- dietlibc-0.31/x86_64/time.S 1970-01-01 01:00:00.000000000 +0100 +++ dietlibc/x86_64/time.S 2008-11-23 18:19:43.000000000 +0100 @@ -0,0 +1,21 @@ +/* implement time(2) via gettimeofday(2) on x86-64 because gettimeofday + is a vsyscall (i.e. no actual switch to kernel mode) */ +.text +.global time +.type time,@function +time: + push %rdi + xor %rsi,%rsi + sub $16,%rsp + mov %rsp,%rdi + call gettimeofday + pop %rax + pop %rdi + pop %rdi + test %rdi,%rdi + jz 1f + mov %rax,(%rdi) +1: + ret +.Lhere: + .size time,.Lhere-time diff -urN -x CVS dietlibc-0.31/x86_64/unified.S dietlibc/x86_64/unified.S --- dietlibc-0.31/x86_64/unified.S 2005-05-08 01:07:33.000000000 +0200 +++ dietlibc/x86_64/unified.S 2008-02-19 14:02:23.000000000 +0100 @@ -3,6 +3,7 @@ #define SYS_exit 0x3c .text + .weak exit exit: .global _exit @@ -10,8 +11,11 @@ mov $SYS_exit,%al .global __unified_syscall +.global __unified_syscall_16bit __unified_syscall: - movzbl %al, %eax + mov $0, %ah +__unified_syscall_16bit: + movzwl %ax, %eax mov %rcx, %r10 syscall cmpq $-128, %rax