]> git.pld-linux.org Git - packages/dietlibc.git/blame - dietlibc-cvs.patch
- rel 6
[packages/dietlibc.git] / dietlibc-cvs.patch
CommitLineData
5a4e6f54
JR
1diff -urN -x CVS dietlibc-0.31/alpha/strlen.c dietlibc/alpha/strlen.c
2--- dietlibc-0.31/alpha/strlen.c 2001-01-09 18:57:38.000000000 +0100
3+++ dietlibc/alpha/strlen.c 1970-01-01 01:00:00.000000000 +0100
4@@ -1,32 +0,0 @@
5-#include <string.h>
6-
7-static const unsigned long long magic = 0x0101010101010101LL;
8-
9-size_t strlen(const char *s)
10-{
11- const char *t = s;
12- unsigned long long word;
13-
14- if (!s) return 0;
15-
16- /* Byte compare up until 64 bit word boundary */
17- for (; ((unsigned long long) t & 7); t++)
18- if (!*t) return t - s;
19-
20- /* Word compare */
21- do {
22- word = *((unsigned long long *) t); t += 8;
23- word = (word - magic) &~ word;
24- word &= (magic << 7);
25- } while (word == 0);
26-
27- /* word & 0x8080808080808080 == word */
28- word = (word - 1) & (magic << 8);
29- word += (word << 32);
30- word += (word << 16);
31- word += (word << 8);
32- t += word >> 56;
33- return ((const char *) t) - 8 - s;
34-}
35-
36-
37diff -urN -x CVS dietlibc-0.31/alpha/syscalls.h dietlibc/alpha/syscalls.h
38--- dietlibc-0.31/alpha/syscalls.h 2005-09-21 09:33:08.000000000 +0200
39+++ dietlibc/alpha/syscalls.h 2008-02-19 01:28:13.000000000 +0100
40@@ -380,6 +380,38 @@
41 #define __NR_inotify_init 444
42 #define __NR_inotify_add_watch 445
43 #define __NR_inotify_rm_watch 446
44+#define __NR_fdatasync 447
45+#define __NR_kexec_load 448
46+#define __NR_migrate_pages 449
47+#define __NR_openat 450
48+#define __NR_mkdirat 451
49+#define __NR_mknodat 452
50+#define __NR_fchownat 453
51+#define __NR_futimesat 454
52+#define __NR_fstatat64 455
53+#define __NR_unlinkat 456
54+#define __NR_renameat 457
55+#define __NR_linkat 458
56+#define __NR_symlinkat 459
57+#define __NR_readlinkat 460
58+#define __NR_fchmodat 461
59+#define __NR_faccessat 462
60+#define __NR_pselect6 463
61+#define __NR_ppoll 464
62+#define __NR_unshare 465
63+#define __NR_set_robust_list 466
64+#define __NR_get_robust_list 467
65+#define __NR_splice 468
66+#define __NR_sync_file_range 469
67+#define __NR_tee 470
68+#define __NR_vmsplice 471
69+#define __NR_move_pages 472
70+#define __NR_getcpu 473
71+#define __NR_epoll_pwait 474
72+#define __NR_utimensat 475
73+#define __NR_signalfd 476
74+#define __NR_timerfd 477
75+#define __NR_eventfd 478
76
77
78 #define syscall_weak(name,wsym,sym) \
79diff -urN -x CVS dietlibc-0.31/arm/accept.S dietlibc/arm/accept.S
80--- dietlibc-0.31/arm/accept.S 1970-01-01 01:00:00.000000000 +0100
81+++ dietlibc/arm/accept.S 2008-09-05 17:13:29.000000000 +0200
82@@ -0,0 +1,7 @@
83+#ifdef __ARM_EABI__
84+
85+#include "syscalls.h"
86+
87+syscall(accept,accept)
88+
89+#endif
90diff -urN -x CVS dietlibc-0.31/arm/__aeabi_unwind_cpp.S dietlibc/arm/__aeabi_unwind_cpp.S
91--- dietlibc-0.31/arm/__aeabi_unwind_cpp.S 1970-01-01 01:00:00.000000000 +0100
92+++ dietlibc/arm/__aeabi_unwind_cpp.S 2008-04-12 00:51:11.000000000 +0200
93@@ -0,0 +1,21 @@
94+.text
95+.global __aeabi_unwind_cpp_pr0
96+.hidden __aeabi_unwind_cpp_pr0
97+.type __aeabi_unwind_cpp_pr0, %function
98+
99+.global __aeabi_unwind_cpp_pr1
100+.hidden __aeabi_unwind_cpp_pr1
101+.type __aeabi_unwind_cpp_pr1, %function
102+
103+.global __aeabi_unwind_cpp_pr2
104+.hidden __aeabi_unwind_cpp_pr2
105+.type __aeabi_unwind_cpp_pr2, %function
106+
107+__aeabi_unwind_cpp_pr0:
108+__aeabi_unwind_cpp_pr1:
109+__aeabi_unwind_cpp_pr2:
110+ mov pc, lr @ return from subroutine
111+
112+.size __aeabi_unwind_cpp_pr0,.-__aeabi_unwind_cpp_pr0
113+.size __aeabi_unwind_cpp_pr1,.-__aeabi_unwind_cpp_pr1
114+.size __aeabi_unwind_cpp_pr2,.-__aeabi_unwind_cpp_pr2
115diff -urN -x CVS dietlibc-0.31/arm/bind.S dietlibc/arm/bind.S
116--- dietlibc-0.31/arm/bind.S 1970-01-01 01:00:00.000000000 +0100
117+++ dietlibc/arm/bind.S 2008-09-05 17:13:29.000000000 +0200
118@@ -0,0 +1,7 @@
119+#ifdef __ARM_EABI__
120+
121+#include "syscalls.h"
122+
123+syscall(bind,bind)
124+
125+#endif
126diff -urN -x CVS dietlibc-0.31/arm/clone.S dietlibc/arm/clone.S
127--- dietlibc-0.31/arm/clone.S 2002-02-28 17:27:02.000000000 +0100
128+++ dietlibc/arm/clone.S 2008-09-05 17:13:29.000000000 +0200
129@@ -10,6 +10,76 @@
130 @ Some slightly tricky stuff here... edit with care :-)
131 @
132
133+
134+#ifdef __ARM_EABI__
135+
136+#define CLONE_VM 0x00000100
137+#define CLONE_THREAD 0x00010000
138+
139+@ ; don't do this yet
140+@#define RESET_PID
141+
142+
143+clone:
144+__clone:
145+ @ ; start with a sanity check
146+ cmp r0, #0
147+ cmpne r1, #0
148+ mvneq r0, #-EINVAL
149+ beq __unified_syscall @ handle as if error was returned by the syscall
150+
151+ @ ; insert args into stack
152+ str r3, [r1, #-4]!
153+ str r0, [r1, #-4]!
154+
155+ @ ; do the system call
156+ @ ; get the flags
157+ mov r0, r2
158+#ifdef RESET_PID
159+ mov ip, r2
160+#endif
161+ @ ; child sp is already in r1
162+ stmfd sp!, {r4, r7}
163+ @stmdb sp!, {r4, r7}
164+ ldr r2, [sp, #8]
165+ ldr r3, [sp, #12]
166+ ldr r4, [sp, #16]
167+ ldr r7, =__NR_clone
168+ swi 0
169+
170+ cmp r0, #0
171+ beq 1f
172+ ldmfd sp!, {r4, r7}
173+ blt __unified_syscall @ (return code < 0): handle as an error
174+ bx lr
175+1:
176+#ifdef RESET_PID
177+ tst ip, #CLONE_THREAD
178+ bne 3f
179+
180+ mov r0, #0xffff0fff
181+ mov lr, pc
182+ sub pc, r0, #31
183+ mov r1, r0
184+ tst ip, #CLONE_VM
185+ movne r0, #-1
186+ ldr r7, =__NR_getpid
187+ swi 0
188+ str r0, [r1, #PID_OFFSET] @ ; not defined yet ??
189+ str r0, [r1, #TID_OFFSET] @ ; not defined yet ??
190+3:
191+#endif
192+ @ ; pick the function arg and call address off the stack and execute
193+ ldr r0, [sp, #4]
194+ mov lr, pc
195+ ldr pc, [sp], #8
196+
197+ @ ; and we're done, passing return value through r0
198+ b _exit @ branch to _exit (PIC safe)
199+
200+
201+#else
202+
203 clone:
204 __clone:
205 movs r12, r0 @ check function pointer
206@@ -32,3 +102,4 @@
207
208 1: b _exit @ branch to _exit (PIC safe)
209
210+#endif
211diff -urN -x CVS dietlibc-0.31/arm/connect.S dietlibc/arm/connect.S
212--- dietlibc-0.31/arm/connect.S 1970-01-01 01:00:00.000000000 +0100
213+++ dietlibc/arm/connect.S 2008-09-05 17:13:29.000000000 +0200
214@@ -0,0 +1,7 @@
215+#ifdef __ARM_EABI__
216+
217+#include "syscalls.h"
218+
219+syscall(connect,connect)
220+
221+#endif
222diff -urN -x CVS dietlibc-0.31/arm/dyn_syscalls.S dietlibc/arm/dyn_syscalls.S
223--- dietlibc-0.31/arm/dyn_syscalls.S 2005-10-08 23:22:09.000000000 +0200
224+++ dietlibc/arm/dyn_syscalls.S 2008-07-07 14:31:53.000000000 +0200
225@@ -30,6 +30,7 @@
226 /* ok now include all syscalls.s (*.S) and sysdep *.S */
227 #include "mmap.S"
228 #include "waitpid.S"
229+#include "select.S"
230
231 #include "../syscalls.s/__getpagesize.S"
232 #include "../syscalls.s/__pread.S"
233@@ -132,7 +133,6 @@
234 #include "../syscalls.s/sched_setparam.S"
235 #include "../syscalls.s/sched_setscheduler.S"
236 #include "../syscalls.s/sched_yield.S"
237-#include "../syscalls.s/select.S"
238 #include "../syscalls.s/sendfile.S"
239 #include "../syscalls.s/sendfile64.S"
240 #include "../syscalls.s/setdomainname.S"
241@@ -289,3 +289,4 @@
242
243 #include "__longjmp.S"
244 #include "setjmp.S"
245+#include "__guard.S"
246diff -urN -x CVS dietlibc-0.31/arm/getpeername.S dietlibc/arm/getpeername.S
247--- dietlibc-0.31/arm/getpeername.S 1970-01-01 01:00:00.000000000 +0100
248+++ dietlibc/arm/getpeername.S 2008-09-05 17:13:29.000000000 +0200
249@@ -0,0 +1,7 @@
250+#ifdef __ARM_EABI__
251+
252+#include "syscalls.h"
253+
254+syscall(getpeername,getpeername)
255+
256+#endif
257diff -urN -x CVS dietlibc-0.31/arm/getsockname.S dietlibc/arm/getsockname.S
258--- dietlibc-0.31/arm/getsockname.S 1970-01-01 01:00:00.000000000 +0100
259+++ dietlibc/arm/getsockname.S 2008-09-05 17:13:29.000000000 +0200
260@@ -0,0 +1,7 @@
261+#ifdef __ARM_EABI__
262+
263+#include "syscalls.h"
264+
265+syscall(getsockname,getsockname)
266+
267+#endif
268diff -urN -x CVS dietlibc-0.31/arm/listen.S dietlibc/arm/listen.S
269--- dietlibc-0.31/arm/listen.S 1970-01-01 01:00:00.000000000 +0100
270+++ dietlibc/arm/listen.S 2008-09-05 17:13:29.000000000 +0200
271@@ -0,0 +1,7 @@
272+#ifdef __ARM_EABI__
273+
274+#include "syscalls.h"
275+
276+syscall(listen,listen)
277+
278+#endif
279diff -urN -x CVS dietlibc-0.31/arm/Makefile.add dietlibc/arm/Makefile.add
280--- dietlibc-0.31/arm/Makefile.add 2002-05-09 03:05:10.000000000 +0200
281+++ dietlibc/arm/Makefile.add 2008-09-05 17:13:29.000000000 +0200
282@@ -1,5 +1,8 @@
283
284-LIBOBJ+=$(OBJDIR)/md5asm.o
285-CFLAGS+=-Os -fomit-frame-pointer -fstrict-aliasing -mhard-float
286+LIBOBJ+=$(OBJDIR)/md5asm.o $(OBJDIR)/__aeabi_unwind_cpp.o
287+CFLAGS+=-Os -fomit-frame-pointer -fstrict-aliasing
288+#ifdef __ARM_EABI__
289+CFLAGS+=-mabi=aapcs-linux -mfloat-abi=soft -mno-thumb-interwork
290+#endif
291 VPATH:=arm:syscalls.s:$(VPATH)
292 LIBGMON_OBJS+=$(OBJDIR)/mcount.o
293diff -urN -x CVS dietlibc-0.31/arm/md5asm.S dietlibc/arm/md5asm.S
294--- dietlibc-0.31/arm/md5asm.S 2002-03-08 11:56:15.000000000 +0100
295+++ dietlibc/arm/md5asm.S 2008-09-05 17:13:29.000000000 +0200
296@@ -57,8 +57,12 @@
297 .global MD5Update
298
299 .text
300+#ifdef __ARM_EABI__
301+ .align 4
302+#else
303 .align 2
304-
305+#endif
306+
307 @ --
308 @ void MD5Init (MD5_CTX* context);
309 @ --
310diff -urN -x CVS dietlibc-0.31/arm/mmap.S dietlibc/arm/mmap.S
311--- dietlibc-0.31/arm/mmap.S 2002-02-18 20:57:39.000000000 +0100
312+++ dietlibc/arm/mmap.S 2008-12-02 22:50:42.000000000 +0100
313@@ -1,4 +1,3 @@
314-
315 #include <errno.h>
316 #include "syscalls.h"
317
318@@ -15,6 +14,24 @@
319
320 .global mmap
321
322+#ifdef __ARM_EABI__
323+
324+mmap:
325+ str r5, [sp, #-4]!
326+ ldr r5, [sp, #8]
327+ str r4, [sp, #-4]!
328+ ldr r4, [sp, #8]
329+ mov ip, r7
330+ mov r7, #__NR_mmap2
331+ svc 0x00000000
332+ mov r7, ip
333+ ldr r4, [sp], #4
334+ ldr r5, [sp], #4
335+ cmn r0, #4096
336+ mov pc, lr @ return
337+
338+#else
339+
340 mmap:
341 stmdb sp!, {r0, r1, r2, r3}
342 mov r0, sp
343@@ -22,3 +39,4 @@
344 add sp, sp, #16
345 b __unified_syscall
346
347+#endif
348diff -urN -x CVS dietlibc-0.31/arm/recvfrom.S dietlibc/arm/recvfrom.S
349--- dietlibc-0.31/arm/recvfrom.S 1970-01-01 01:00:00.000000000 +0100
350+++ dietlibc/arm/recvfrom.S 2008-09-05 17:13:29.000000000 +0200
351@@ -0,0 +1,7 @@
352+#ifdef __ARM_EABI__
353+
354+#include "syscalls.h"
355+
356+syscall(recvfrom,recvfrom)
357+
358+#endif
359diff -urN -x CVS dietlibc-0.31/arm/recvmsg.S dietlibc/arm/recvmsg.S
360--- dietlibc-0.31/arm/recvmsg.S 1970-01-01 01:00:00.000000000 +0100
361+++ dietlibc/arm/recvmsg.S 2008-09-05 17:13:29.000000000 +0200
362@@ -0,0 +1,7 @@
363+#ifdef __ARM_EABI__
364+
365+#include "syscalls.h"
366+
367+syscall(recvmsg,recvmsg)
368+
369+#endif
370diff -urN -x CVS dietlibc-0.31/arm/recv.S dietlibc/arm/recv.S
371--- dietlibc-0.31/arm/recv.S 1970-01-01 01:00:00.000000000 +0100
372+++ dietlibc/arm/recv.S 2008-09-05 17:13:29.000000000 +0200
373@@ -0,0 +1,7 @@
374+#ifdef __ARM_EABI__
375+
376+#include "syscalls.h"
377+
378+syscall(recv,recv)
379+
380+#endif
381diff -urN -x CVS dietlibc-0.31/arm/sendmsg.S dietlibc/arm/sendmsg.S
382--- dietlibc-0.31/arm/sendmsg.S 1970-01-01 01:00:00.000000000 +0100
383+++ dietlibc/arm/sendmsg.S 2008-09-05 17:13:29.000000000 +0200
384@@ -0,0 +1,7 @@
385+#ifdef __ARM_EABI__
386+
387+#include "syscalls.h"
388+
389+syscall(sendmsg,sendmsg)
390+
391+#endif
392diff -urN -x CVS dietlibc-0.31/arm/send.S dietlibc/arm/send.S
393--- dietlibc-0.31/arm/send.S 1970-01-01 01:00:00.000000000 +0100
394+++ dietlibc/arm/send.S 2008-09-05 17:13:29.000000000 +0200
395@@ -0,0 +1,7 @@
396+#ifdef __ARM_EABI__
397+
398+#include "syscalls.h"
399+
400+syscall(send,send)
401+
402+#endif
403diff -urN -x CVS dietlibc-0.31/arm/sendto.S dietlibc/arm/sendto.S
404--- dietlibc-0.31/arm/sendto.S 1970-01-01 01:00:00.000000000 +0100
405+++ dietlibc/arm/sendto.S 2008-09-05 17:13:29.000000000 +0200
406@@ -0,0 +1,7 @@
407+#ifdef __ARM_EABI__
408+
409+#include "syscalls.h"
410+
411+syscall(sendto,sendto)
412+
413+#endif
414diff -urN -x CVS dietlibc-0.31/arm/setjmp.S dietlibc/arm/setjmp.S
415--- dietlibc-0.31/arm/setjmp.S 2001-07-02 18:06:48.000000000 +0200
416+++ dietlibc/arm/setjmp.S 2008-09-05 17:13:29.000000000 +0200
417@@ -12,6 +12,6 @@
418 sfm f4, 4, [r0], #48
419 #endif
420 stmia r0, {r4-r11, sp, lr}
421- sub r0, r0, #30
422+ sub r0, r0, #48
423 b __sigjmp_save
424
425diff -urN -x CVS dietlibc-0.31/arm/setsockopt.S dietlibc/arm/setsockopt.S
426--- dietlibc-0.31/arm/setsockopt.S 1970-01-01 01:00:00.000000000 +0100
427+++ dietlibc/arm/setsockopt.S 2008-09-05 17:13:29.000000000 +0200
428@@ -0,0 +1,7 @@
429+#ifdef __ARM_EABI__
430+
431+#include "syscalls.h"
432+
433+syscall(setsockopt,setsockopt)
434+
435+#endif
436diff -urN -x CVS dietlibc-0.31/arm/shutdown.S dietlibc/arm/shutdown.S
437--- dietlibc-0.31/arm/shutdown.S 1970-01-01 01:00:00.000000000 +0100
438+++ dietlibc/arm/shutdown.S 2008-09-05 17:13:29.000000000 +0200
439@@ -0,0 +1,7 @@
440+#ifdef __ARM_EABI__
441+
442+#include "syscalls.h"
443+
444+syscall(shutdown,shutdown)
445+
446+#endif
447diff -urN -x CVS dietlibc-0.31/arm/socketpair.S dietlibc/arm/socketpair.S
448--- dietlibc-0.31/arm/socketpair.S 1970-01-01 01:00:00.000000000 +0100
449+++ dietlibc/arm/socketpair.S 2008-09-05 17:13:29.000000000 +0200
450@@ -0,0 +1,7 @@
451+#ifdef __ARM_EABI__
452+
453+#include "syscalls.h"
454+
455+syscall(socketpair,socketpair)
456+
457+#endif
458diff -urN -x CVS dietlibc-0.31/arm/socket.S dietlibc/arm/socket.S
459--- dietlibc-0.31/arm/socket.S 1970-01-01 01:00:00.000000000 +0100
460+++ dietlibc/arm/socket.S 2008-09-05 17:13:29.000000000 +0200
461@@ -0,0 +1,7 @@
462+#ifdef __ARM_EABI__
463+
464+#include "syscalls.h"
465+
466+syscall(socket,socket)
467+
468+#endif
469diff -urN -x CVS dietlibc-0.31/arm/start.S dietlibc/arm/start.S
470--- dietlibc-0.31/arm/start.S 2006-04-04 07:35:14.000000000 +0200
471+++ dietlibc/arm/start.S 2008-09-05 17:13:29.000000000 +0200
472@@ -3,12 +3,48 @@
473 #include "syscalls.h"
474
475 .text
476+#ifdef __ARM_EABI__
477+ .align 4
478+#else
479 .align 2
480-
481+#endif
482+
483 .global _start
484 .weak exit
485 .global _exit
486
487+
488+#ifdef __ARM_EABI__
489+
490+_start:
491+
492+ mov fp, #0 @ clear the frame pointer
493+ ldr a1, [sp], #4 @ argc
494+ mov a2, sp @ argv
495+ ldr ip, .L3
496+ add a3, a2, a1, lsl #2 @ &argv[argc]
497+ add a3, a3, #4 @ envp
498+ str a3, [ip, #0] @ environ = envp
499+ bl main
500+
501+@
502+@ The exit status from main() is already in r0.
503+@ We need to branch to 'exit' in case we have linked with 'atexit'.
504+@
505+ bl exit
506+
507+exit:
508+_exit:
509+
510+ mov r7, #__NR_exit
511+ swi 0 @ never returns.
512+
513+.L3: .word environ
514+
515+
516+#else
517+
518+
519 _start:
520
521 #ifdef WANT_DYNAMIC
522@@ -72,4 +108,4 @@
523 #endif
524
525
526-
527+#endif
528diff -urN -x CVS dietlibc-0.31/arm/syscalls.h dietlibc/arm/syscalls.h
529--- dietlibc-0.31/arm/syscalls.h 2007-08-24 23:19:33.000000000 +0200
530+++ dietlibc/arm/syscalls.h 2008-09-30 23:02:35.000000000 +0200
531@@ -1,5 +1,16 @@
532-#define __NR_SYSCALL_BASE 0x900000
533+#ifndef _ARM_SYSCALL_H
534+#define _ARM_SYSCALL_H 1
535
536+#define __NR_OABI_SYSCALL_BASE 0x900000
537+
538+#if defined(__thumb__) || defined(__ARM_EABI__)
539+#define __NR_SYSCALL_BASE 0
540+#else
541+#define __NR_SYSCALL_BASE __NR_OABI_SYSCALL_BASE
542+#endif
543+
544+
545+#define __NR_restart_syscall (__NR_SYSCALL_BASE+ 0)
546 #define __NR_exit (__NR_SYSCALL_BASE+ 1)
547 #define __NR_fork (__NR_SYSCALL_BASE+ 2)
548 #define __NR_read (__NR_SYSCALL_BASE+ 3)
549@@ -126,10 +137,10 @@
550 #define __NR_adjtimex (__NR_SYSCALL_BASE+124)
551 #define __NR_mprotect (__NR_SYSCALL_BASE+125)
552 #define __NR_sigprocmask (__NR_SYSCALL_BASE+126)
553-#define __NR_create_module (__NR_SYSCALL_BASE+127)
554+ /* 127 was sys_create_module */
555 #define __NR_init_module (__NR_SYSCALL_BASE+128)
556 #define __NR_delete_module (__NR_SYSCALL_BASE+129)
557-#define __NR_get_kernel_syms (__NR_SYSCALL_BASE+130)
558+ /* 130 was sys_get_kernel_syms */
559 #define __NR_quotactl (__NR_SYSCALL_BASE+131)
560 #define __NR_getpgid (__NR_SYSCALL_BASE+132)
561 #define __NR_fchdir (__NR_SYSCALL_BASE+133)
562@@ -166,7 +177,7 @@
563 #define __NR_setresuid (__NR_SYSCALL_BASE+164)
564 #define __NR_getresuid (__NR_SYSCALL_BASE+165)
565 /* 166 was sys_vm86 */
566-#define __NR_query_module (__NR_SYSCALL_BASE+167)
567+ /* 167 was sys_query_module */
568 #define __NR_poll (__NR_SYSCALL_BASE+168)
569 #define __NR_nfsservctl (__NR_SYSCALL_BASE+169)
570 #define __NR_setresgid (__NR_SYSCALL_BASE+170)
571@@ -179,8 +190,8 @@
572 #define __NR_rt_sigtimedwait (__NR_SYSCALL_BASE+177)
573 #define __NR_rt_sigqueueinfo (__NR_SYSCALL_BASE+178)
574 #define __NR_rt_sigsuspend (__NR_SYSCALL_BASE+179)
575-#define __NR_pread (__NR_SYSCALL_BASE+180)
576-#define __NR_pwrite (__NR_SYSCALL_BASE+181)
577+#define __NR_pread64 (__NR_SYSCALL_BASE+180)
578+#define __NR_pwrite64 (__NR_SYSCALL_BASE+181)
579 #define __NR_chown (__NR_SYSCALL_BASE+182)
580 #define __NR_getcwd (__NR_SYSCALL_BASE+183)
581 #define __NR_capget (__NR_SYSCALL_BASE+184)
582@@ -269,7 +280,7 @@
583 #define __NR_fstatfs64 (__NR_SYSCALL_BASE+267)
584 #define __NR_tgkill (__NR_SYSCALL_BASE+268)
585 #define __NR_utimes (__NR_SYSCALL_BASE+269)
586-#define __NR_fadvise64 (__NR_SYSCALL_BASE+270)
587+#define __NR_arm_fadvise64_64 (__NR_SYSCALL_BASE+270)
588 #define __NR_pciconfig_iobase (__NR_SYSCALL_BASE+271)
589 #define __NR_pciconfig_read (__NR_SYSCALL_BASE+272)
590 #define __NR_pciconfig_write (__NR_SYSCALL_BASE+273)
591@@ -280,10 +291,38 @@
592 #define __NR_mq_notify (__NR_SYSCALL_BASE+278)
593 #define __NR_mq_getsetattr (__NR_SYSCALL_BASE+279)
594 #define __NR_waitid (__NR_SYSCALL_BASE+280)
595-
596+#define __NR_socket (__NR_SYSCALL_BASE+281)
597+#define __NR_bind (__NR_SYSCALL_BASE+282)
598+#define __NR_connect (__NR_SYSCALL_BASE+283)
599+#define __NR_listen (__NR_SYSCALL_BASE+284)
600+#define __NR_accept (__NR_SYSCALL_BASE+285)
601+#define __NR_getsockname (__NR_SYSCALL_BASE+286)
602+#define __NR_getpeername (__NR_SYSCALL_BASE+287)
603+#define __NR_socketpair (__NR_SYSCALL_BASE+288)
604+#define __NR_send (__NR_SYSCALL_BASE+289)
605+#define __NR_sendto (__NR_SYSCALL_BASE+290)
606+#define __NR_recv (__NR_SYSCALL_BASE+291)
607+#define __NR_recvfrom (__NR_SYSCALL_BASE+292)
608+#define __NR_shutdown (__NR_SYSCALL_BASE+293)
609+#define __NR_setsockopt (__NR_SYSCALL_BASE+294)
610+#define __NR_getsockopt (__NR_SYSCALL_BASE+295)
611+#define __NR_sendmsg (__NR_SYSCALL_BASE+296)
612+#define __NR_recvmsg (__NR_SYSCALL_BASE+297)
613+#define __NR_semop (__NR_SYSCALL_BASE+298)
614+#define __NR_semget (__NR_SYSCALL_BASE+299)
615+#define __NR_semctl (__NR_SYSCALL_BASE+300)
616+#define __NR_msgsnd (__NR_SYSCALL_BASE+301)
617+#define __NR_msgrcv (__NR_SYSCALL_BASE+302)
618+#define __NR_msgget (__NR_SYSCALL_BASE+303)
619+#define __NR_msgctl (__NR_SYSCALL_BASE+304)
620+#define __NR_shmat (__NR_SYSCALL_BASE+305)
621+#define __NR_shmdt (__NR_SYSCALL_BASE+306)
622+#define __NR_shmget (__NR_SYSCALL_BASE+307)
623+#define __NR_shmctl (__NR_SYSCALL_BASE+308)
624 #define __NR_add_key (__NR_SYSCALL_BASE+309)
625 #define __NR_request_key (__NR_SYSCALL_BASE+310)
626 #define __NR_keyctl (__NR_SYSCALL_BASE+311)
627+#define __NR_semtimedop (__NR_SYSCALL_BASE+312)
628 #define __NR_vserver (__NR_SYSCALL_BASE+313)
629 #define __NR_ioprio_set (__NR_SYSCALL_BASE+314)
630 #define __NR_ioprio_get (__NR_SYSCALL_BASE+315)
631@@ -293,6 +332,39 @@
632 #define __NR_mbind (__NR_SYSCALL_BASE+319)
633 #define __NR_get_mempolicy (__NR_SYSCALL_BASE+320)
634 #define __NR_set_mempolicy (__NR_SYSCALL_BASE+321)
635+#define __NR_openat (__NR_SYSCALL_BASE+322)
636+#define __NR_mkdirat (__NR_SYSCALL_BASE+323)
637+#define __NR_mknodat (__NR_SYSCALL_BASE+324)
638+#define __NR_fchownat (__NR_SYSCALL_BASE+325)
639+#define __NR_futimesat (__NR_SYSCALL_BASE+326)
640+#define __NR_fstatat64 (__NR_SYSCALL_BASE+327)
641+#define __NR_unlinkat (__NR_SYSCALL_BASE+328)
642+#define __NR_renameat (__NR_SYSCALL_BASE+329)
643+#define __NR_linkat (__NR_SYSCALL_BASE+330)
644+#define __NR_symlinkat (__NR_SYSCALL_BASE+331)
645+#define __NR_readlinkat (__NR_SYSCALL_BASE+332)
646+#define __NR_fchmodat (__NR_SYSCALL_BASE+333)
647+#define __NR_faccessat (__NR_SYSCALL_BASE+334)
648+ /* 335 for pselect6 */
649+ /* 336 for ppoll */
650+#define __NR_unshare (__NR_SYSCALL_BASE+337)
651+#define __NR_set_robust_list (__NR_SYSCALL_BASE+338)
652+#define __NR_get_robust_list (__NR_SYSCALL_BASE+339)
653+#define __NR_splice (__NR_SYSCALL_BASE+340)
654+#define __NR_arm_sync_file_range (__NR_SYSCALL_BASE+341)
655+#define __NR_tee (__NR_SYSCALL_BASE+342)
656+#define __NR_vmsplice (__NR_SYSCALL_BASE+343)
657+#define __NR_move_pages (__NR_SYSCALL_BASE+344)
658+#define __NR_getcpu (__NR_SYSCALL_BASE+345)
659+ /* 346 for epoll_pwait */
660+#define __NR_kexec_load (__NR_SYSCALL_BASE+347)
661+#define __NR_utimensat (__NR_SYSCALL_BASE+348)
662+#define __NR_signalfd (__NR_SYSCALL_BASE+349)
663+#define __NR_timerfd (__NR_SYSCALL_BASE+350)
664+#define __NR_eventfd (__NR_SYSCALL_BASE+351)
665+#define __NR_fallocate (__NR_SYSCALL_BASE+352)
666+#define __NR_timerfd_settime (__NR_SYSCALL_BASE+353)
667+#define __NR_timerfd_gettime (__NR_SYSCALL_BASE+354)
668
669 /*
670 * The following SWIs are ARM private.
671@@ -304,6 +376,25 @@
672 #define __ARM_NR_usr32 (__ARM_NR_BASE+4)
673 #define __ARM_NR_set_tls (__ARM_NR_BASE+5)
674
675+/*
676+ * The following syscalls are obsolete and no longer available for EABI.
677+ */
678+#if defined(__ARM_EABI__) && !defined(__KERNEL__)
679+#undef __NR_time
680+#undef __NR_umount
681+#undef __NR_stime
682+#undef __NR_alarm
683+#undef __NR_utime
684+#undef __NR_getrlimit
685+#undef __NR_select
686+#undef __NR_readdir
687+#undef __NR_mmap
688+#undef __NR_socketcall
689+#undef __NR_syscall
690+#undef __NR_ipc
691+#endif
692+
693+
694 /* ok the next few values are for the optimization of the unified syscalls
695 * on arm.
696 * If the syscall has #arguments
697@@ -597,6 +688,35 @@
698 #define __ARGS_mq_getsetattr 0
699 #define __ARGS_waitid 0
700
701+#define __ARGS_socket 0
702+#define __ARGS_bind 0
703+#define __ARGS_connect 0
704+#define __ARGS_listen 0
705+#define __ARGS_accept 0
706+#define __ARGS_getsockname 0
707+#define __ARGS_getpeername 0
708+#define __ARGS_socketpair 0
709+#define __ARGS_send 0
710+#define __ARGS_sendto 0
711+#define __ARGS_recv 0
712+#define __ARGS_recvfrom 0
713+#define __ARGS_shutdown 0
714+#define __ARGS_setsockopt 0
715+#define __ARGS_getsockopt 0
716+#define __ARGS_sendmsg 0
717+#define __ARGS_recvmsg 0
718+#define __ARGS_semop 0
719+#define __ARGS_semget 0
720+#define __ARGS_semctl 0
721+#define __ARGS_msgsnd 0
722+#define __ARGS_msgrcv 0
723+#define __ARGS_msgget 0
724+#define __ARGS_msgctl 0
725+#define __ARGS_shmat 0
726+#define __ARGS_shmdt 0
727+#define __ARGS_shmget 0
728+#define __ARGS_shmctl 0
729+
730 #define __ARGS_add_key 1
731 #define __ARGS_request_key 1
732 #define __ARGS_keyctl 0
733@@ -610,8 +730,80 @@
734 #define __ARGS_get_mempolicy 1
735 #define __ARGS_set_mempolicy 1
736
737+#define __ARGS_openat 0
738+#define __ARGS_mkdirat 0
739+#define __ARGS_mknodat 0
740+#define __ARGS_fchownat 1
741+#define __ARGS_futimesat 0
742+#define __ARGS_fstatat64 0
743+#define __ARGS_unlinkat 0
744+#define __ARGS_renameat 0
745+#define __ARGS_linkat 1
746+#define __ARGS_symlinkat 0
747+#define __ARGS_readlinkat 0
748+#define __ARGS_fchmodat 0
749+#define __ARGS_faccessat 0
750+ /* 335 for pselect6 */
751+ /* 336 for ppoll */
752+#define __ARGS_unshare 0
753+#define __ARGS_set_robust_list 0
754+#define __ARGS_get_robust_list 0
755+#define __ARGS_splice 1
756+#define __ARGS_arm_sync_file_range 0
757+#define __ARGS_sync_file_range2 0
758+#define __ARGS_tee 0
759+#define __ARGS_vmsplice 0
760+#define __ARGS_move_pages 1
761+#define __ARGS_getcpu 0
762+ /* 346 for epoll_pwait */
763+#define __ARGS_kexec_load 0
764+#define __ARGS_utimensat 0
765+#define __ARGS_signalfd 0
766+#define __ARGS_timerfd 0
767+#define __ARGS_eventfd 0
768+#define __ARGS_fallocate 0
769+#define __ARGS_timerfd_settime 0
770+#define __ARGS_timerfd_gettime 0
771+
772
773 #ifdef __ASSEMBLER__
774+
775+#ifdef __ARM_EABI__
776+
777+#define syscall_weak(name,wsym,sym) __syscall_weak __NR_##name, wsym, sym, __ARGS_##name
778+.macro __syscall_weak name wsym sym typ
779+.text
780+.type \wsym,function
781+.weak \wsym
782+\wsym:
783+.type \sym,function
784+.global \sym
785+\sym:
786+ stmfd sp!,{r4,r5,r7,lr}
787+ ldr r4, [sp,#16]
788+ ldr r5, [sp,#20]
789+ ldr r7, =\name
790+ swi 0
791+ b __unified_syscall
792+.endm
793+
794+
795+#define syscall(name,sym) __syscall __NR_##name, sym, __ARGS_##name
796+.macro __syscall name sym typ
797+.text
798+.type \sym,function
799+.global \sym
800+\sym:
801+ stmfd sp!,{r4,r5,r7,lr}
802+ ldr r4, [sp,#16]
803+ ldr r5, [sp,#20]
804+ ldr r7, =\name
805+ swi 0
806+ b __unified_syscall
807+.endm
808+
809+#else
810+
811 #define syscall_weak(name,wsym,sym) __syscall_weak $__NR_##name, wsym, sym, __ARGS_##name
812 .macro __syscall_weak name wsym sym typ
813 .text
814@@ -654,3 +846,6 @@
815 .endm
816
817 #endif
818+#endif
819+
820+#endif
821diff -urN -x CVS dietlibc-0.31/arm/unified.S dietlibc/arm/unified.S
822--- dietlibc-0.31/arm/unified.S 2002-02-28 17:13:20.000000000 +0100
823+++ dietlibc/arm/unified.S 2008-09-05 17:13:29.000000000 +0200
824@@ -2,11 +2,35 @@
825 #include <dietfeatures.h>
826
827 .text
828+#ifdef __ARM_EABI__
829+ .align 4
830+#else
831 .align 2
832-
833+#endif
834 .global __unified_syscall
835 .global __unified_syscall4
836
837+
838+#ifdef __ARM_EABI__
839+
840+__unified_syscall4:
841+__unified_syscall:
842+
843+ cmn r0, #4096
844+ rsbcs r2, r0, #0
845+ ldrcs r3, 1f
846+ mvncs r0, #0
847+ strcs r2, [r3]
848+ ldmfd sp!,{r4,r5,r7,pc}
849+ .balign 4
850+1:
851+ .word errno
852+
853+/* here we go and "reuse" the return for weak-void functions */
854+#include "dietuglyweaks.h"
855+
856+#else
857+
858 __unified_syscall4:
859 ldmia sp!, {r4, r5, r6}
860 __unified_syscall:
861@@ -32,3 +56,5 @@
862 #ifndef WANT_THREAD_SAFE
863 .L0: .long errno
864 #endif
865+
866+#endif
867diff -urN -x CVS dietlibc-0.31/arm/waitpid.S dietlibc/arm/waitpid.S
868--- dietlibc-0.31/arm/waitpid.S 2004-11-30 17:26:20.000000000 +0100
869+++ dietlibc/arm/waitpid.S 2008-09-05 17:13:29.000000000 +0200
870@@ -1,5 +1,9 @@
871 .text
872+#ifdef __ARM_EABI__
873+.align 4
874+#else
875 .align 2
876+#endif
877 .weak waitpid
878 .type waitpid, %function
879 waitpid:
880diff -urN -x CVS dietlibc-0.31/CHANGES dietlibc/CHANGES
881--- dietlibc-0.31/CHANGES 2007-08-03 22:58:33.000000000 +0200
882+++ dietlibc/CHANGES 2009-03-17 00:17:58.000000000 +0100
883@@ -1,3 +1,32 @@
884+0.32:
885+ add mbsinit, mbrlen, mbtowc, wctomb, mbrtowc, wcrtomb, wcwidth
886+ add btowc, wctype, iswctype
887+ add some wide char routines
888+ add statvfs, fstatvfs
889+ add some amd64 asm string routines
890+ add some constants for inotify
891+ several fixes from Enrico Scholz (printf, string routines on big endian)
892+ add some more syscalls
893+ some minor cleanups
894+ shrink some string functions (Kris Katterjohn)
895+ prepare x86_64 for syscall numbers > 255
896+ fix unaligned memcpy if WANT_SMALL_STRING_ROUTINES is not defined
897+ (Enrico Scholz)
898+ fix utmp, add utmpx support (R.L. Horn)
899+ fix the dynamic library for the ARM architecture (Gernot Tenchio)
900+ get ARM port to work with EABI (Tristan Newby)
901+ fix of scanf with negative floats (Andre Oliveira)
902+ use vsyscall to do time(2) on x86-64
903+ implement back references in basic regexes
904+ make regex faster (coalesce n CHAR matches to one STRING match)
905+ stdio speedup
906+ use randomness passed in ELF auxvec instead of /dev/urandom in startup
907+ (strace looks cleaner now)
908+ use ELF auxvec to implement getpagesize
909+ support thread local storage (w00t!!!!)
910+ don't crash in getaddrinfo if hints is NULL (Gernot Tenchio)
911+ add -D_REENTRANT for -pthread in diet
912+
913 0.31:
914 getopt_long and getopt_long_only now refuse ambiguous abbreviations
915 fix printf %u/%x on 64-bit platforms
916diff -urN -x CVS dietlibc-0.31/contrib/debug-realloc.c dietlibc/contrib/debug-realloc.c
917--- dietlibc-0.31/contrib/debug-realloc.c 2002-04-24 00:04:58.000000000 +0200
918+++ dietlibc/contrib/debug-realloc.c 2007-11-18 01:59:08.000000000 +0100
919@@ -1,15 +1,32 @@
920 #include <unistd.h>
921 #include <sys/mman.h>
922+#include <stdlib.h>
923+#ifdef DEBUG
924+#include <stdio.h>
925+#endif
926
927 static struct malloced {
928 unsigned long len,maplen;
929 struct malloced* next;
930+ unsigned long magic;
931 }* root=0;
932
933-void* malloc(size_t size) {
934+static const unsigned long MAGIC=(unsigned long)0xfefec0dedeadbeefull;
935+
936+static void checkmagic() {
937+ struct malloced* x=root;
938+ while (x) {
939+ if (x->magic != MAGIC)
940+ abort();
941+ x=x->next;
942+ }
943+}
944+
945+static void* domalloc(size_t size) {
946 char* n,* m;
947 unsigned long s=size+sizeof(struct malloced);
948- s=(s+4096+4095)&~4095;
949+ checkmagic();
950+ s=(s+4096+4095)&~4095; // add one page, and round up to fill one page
951 n=mmap(0,s,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0);
952 if (n==MAP_FAILED) return 0;
953 m=n-size; while (m<n) m+=4096;
954@@ -18,12 +35,22 @@
955 ((struct malloced*)n)->len=size;
956 ((struct malloced*)n)->maplen=s;
957 ((struct malloced*)n)->next=root;
958+ ((struct malloced*)n)->magic=MAGIC;
959 root=(struct malloced*)n;
960 return m;
961 }
962
963-void free(void* ptr) {
964+void* malloc(size_t size) {
965+ void* m=domalloc(size);;
966+#ifdef DEBUG
967+ printf("malloc(%zu) -> %p\n",size,m);
968+#endif
969+ return m;
970+}
971+
972+static void dofree(void* ptr) {
973 struct malloced** x=&root;
974+ checkmagic();
975 while (*x) {
976 if (((char*)(*x))+sizeof(struct malloced)<(char*)ptr &&
977 ((char*)(*x))+4096>(char*)ptr) {
978@@ -37,22 +64,35 @@
979 abort();
980 }
981
982+void free(void* ptr) {
983+#ifdef DEBUG
984+ printf("free(%p)\n",ptr);
985+#endif
986+ dofree(ptr);
987+}
988+
989 void *realloc(void *ptr, size_t size) {
990 unsigned long oldsize=0;
991- struct malloced** x=&root;
992+ struct malloced* x=root;
993 char* fnord;
994 if (ptr) {
995- while (*x) {
996- if (((char*)(*x))+sizeof(struct malloced)<(char*)ptr &&
997- ((char*)(*x))+4096>(char*)ptr) {
998- oldsize=(*x)->len;
999+ oldsize=-1;
1000+ while (x) {
1001+ if (((char*)x)+sizeof(struct malloced)<(char*)ptr &&
1002+ ((char*)x)+4096>(char*)ptr) {
1003+ oldsize=x->len;
1004 break;
1005 }
1006- x=&(*x)->next;
1007+ x=x->next;
1008 }
1009+ if (oldsize==(unsigned long)-1)
1010+ abort();
1011 }
1012- fnord=malloc(size);
1013+ fnord=domalloc(size);
1014 memcpy(fnord,ptr,size>oldsize?oldsize:size);
1015- if (oldsize) free(ptr);
1016+ if (oldsize) dofree(ptr);
1017+#ifdef DEBUG
1018+ printf("realloc(%p,%zu) -> %p\n",ptr,size,fnord);
1019+#endif
1020 return fnord;
1021 }
1022diff -urN -x CVS dietlibc-0.31/contrib/dnsd.c dietlibc/contrib/dnsd.c
1023--- dietlibc-0.31/contrib/dnsd.c 2007-01-31 22:09:18.000000000 +0100
1024+++ dietlibc/contrib/dnsd.c 2008-09-30 23:02:35.000000000 +0200
1025@@ -6,7 +6,7 @@
1026 #include <unistd.h>
1027 #include <string.h>
1028 #include <errno.h>
1029-#include <sys/poll.h>
1030+#include <poll.h>
1031 #include <stdio.h>
1032 #include <strings.h>
1033 #include <net/if.h>
1034@@ -26,12 +26,82 @@
1035
1036 struct sockaddr_in mysa4;
1037 struct sockaddr_in6 mysa6;
1038+struct msghdr mh;
1039+
1040+static int scan_fromhex(unsigned char c) {
1041+ c-='0';
1042+ if (c<=9) return c;
1043+ c&=~0x20;
1044+ c-='A'-'0';
1045+ if (c<6) return c+10;
1046+ return -1;
1047+/* more readable but creates worse code:
1048+ if (c>='0' && c<='9')
1049+ return c-'0';
1050+ else if (c>='A' && c<='F')
1051+ return c-'A'+10;
1052+ else if (c>='a' && c<='f')
1053+ return c-'a'+10;
1054+ return -1;
1055+*/
1056+}
1057+
1058+static void getip(int interface) {
1059+ int fd;
1060+ struct cmsghdr* x;
1061+ memset(&mysa4,0,sizeof(mysa4));
1062+ memset(&mysa6,0,sizeof(mysa6));
1063+ for (x=CMSG_FIRSTHDR(&mh); x; x=CMSG_NXTHDR(&mh,x))
1064+ if (x->cmsg_level==SOL_IP && x->cmsg_type==IP_PKTINFO)
1065+ mysa4.sin_addr=((struct in_pktinfo*)(CMSG_DATA(x)))->ipi_spec_dst;
1066+
1067+ fd=open("/proc/net/if_inet6",O_RDONLY);
1068+ if (fd!=-1) {
1069+ char buf[1024]; /* increase as necessary */
1070+ int i,j,len;
1071+ len=read(fd,buf,sizeof buf);
1072+ if (len>0) {
1073+ int ok;
1074+ char* c=buf;
1075+ char* max=buf+len;
1076+ ok=0;
1077+ /* "fec000000000000102c09ffffe53fc52 01 40 40 00 eth0" */
1078+ while (c<max) {
1079+ int a,b;
1080+ for (i=0; i<16; ++i) {
1081+ a=scan_fromhex(c[i*2]);
1082+ b=scan_fromhex(c[i*2+1]);
1083+ if (a<0 || b<0) goto kaputt;
1084+ mysa6.sin6_addr.s6_addr[i]=(a<<4)+b;
1085+ }
1086+ ok=1;
1087+ a=scan_fromhex(c[33]);
1088+ b=scan_fromhex(c[34]);
1089+ c+=32;
1090+ if (a<0 || b<0) goto kaputt;
1091+ if ((a<<4)+b == interface) {
1092+ ok=1;
1093+ goto kaputt;
1094+ }
1095+ while (c<max && *c!='\n') ++c;
1096+ ++c;
1097+ }
1098+kaputt:
1099+ if (!ok) memset(&mysa6,0,sizeof(mysa6));
1100+ }
1101+ close(fd);
1102+ }
1103+}
1104
1105 static void handle(int s,char* buf,int len,int interface,int llmnr) {
1106 int q;
1107 char* obuf=buf;
1108 char* after;
1109 int olen=len;
1110+#ifdef DEBUG
1111+ if (interface==0)
1112+ printf("called with interface==0!\n");
1113+#endif
1114 if (len<8*2) return; /* too short */
1115 buf[len]=0;
1116 if ((buf[2]&(llmnr?0xfd:0xf8)) != 0) return; /* not query */
1117@@ -41,6 +111,9 @@
1118 if (buf[8] || buf[9]) return; /* name server count must be 0 */
1119 if (buf[10] || buf[11]) return; /* additional record count must be 0 */
1120 buf+=12; len-=12;
1121+#ifdef DEBUG
1122+ printf("got %s request for \"%.*s\"",llmnr?"LLMNR":"zeroconf mDNS",(int)(unsigned char)buf[0],buf+1);
1123+#endif
1124 if (buf[0]==namelen && !strncasecmp(buf+1,myhostname,namelen)) {
1125 unsigned int type;
1126 int slen;
1127@@ -60,6 +133,7 @@
1128 if (type==1 || type==255) { /* A or ANY, we can do that */
1129 struct ifreq ifr;
1130 static int v4sock=-1;
1131+ getip(interface);
1132 ++obuf[7]; /* one answer */
1133 memcpy(obuf+slen,"\xc0\x0c" /* goofy compression */
1134 "\x00\x01" /* A */
1135@@ -106,69 +180,11 @@
1136 struct sockaddr_in6 sa6;
1137 struct pollfd pfd[4];
1138
1139-struct msghdr mh;
1140 struct iovec iv;
1141 char abuf[100];
1142 #define PKGSIZE 1500
1143 char buf[PKGSIZE+1];
1144
1145-static int scan_fromhex(unsigned char c) {
1146- if (c>='0' && c<='9')
1147- return c-'0';
1148- else if (c>='A' && c<='F')
1149- return c-'A'+10;
1150- else if (c>='a' && c<='f')
1151- return c-'a'+10;
1152- return -1;
1153-}
1154-
1155-static void getip(int interface) {
1156- int fd;
1157- struct cmsghdr* x;
1158- memset(&mysa4,0,sizeof(mysa4));
1159- memset(&mysa6,0,sizeof(mysa6));
1160- for (x=CMSG_FIRSTHDR(&mh); x; x=CMSG_NXTHDR(&mh,x))
1161- if (x->cmsg_level==SOL_IP && x->cmsg_type==IP_PKTINFO)
1162- mysa4.sin_addr=((struct in_pktinfo*)(CMSG_DATA(x)))->ipi_spec_dst;
1163-
1164- fd=open("/proc/net/if_inet6",O_RDONLY);
1165- if (fd!=-1) {
1166- char buf[1024]; /* increase as necessary */
1167- int i,j,len;
1168- len=read(fd,buf,sizeof buf);
1169- if (len>0) {
1170- int ok;
1171- char* c=buf;
1172- char* max=buf+len;
1173- ok=0;
1174- /* "fec000000000000102c09ffffe53fc52 01 40 40 00 eth0" */
1175- while (c<max) {
1176- int a,b;
1177- for (i=0; i<16; ++i) {
1178- a=scan_fromhex(c[i*2]);
1179- b=scan_fromhex(c[i*2+1]);
1180- if (a<0 || b<0) goto kaputt;
1181- mysa6.sin6_addr.s6_addr[i]=(a<<4)+b;
1182- }
1183- ok=1;
1184- a=scan_fromhex(c[33]);
1185- b=scan_fromhex(c[34]);
1186- c+=32;
1187- if (a<0 || b<0) goto kaputt;
1188- if ((a<<4)+b == interface) {
1189- ok=1;
1190- goto kaputt;
1191- }
1192- while (c<max && *c!='\n') ++c;
1193- ++c;
1194- }
1195-kaputt:
1196- if (!ok) memset(&mysa6,0,sizeof(mysa6));
1197- }
1198- close(fd);
1199- }
1200-}
1201-
1202 static int v4if() {
1203 struct cmsghdr* x;
1204 for (x=CMSG_FIRSTHDR(&mh); x; x=CMSG_NXTHDR(&mh,x))
1205@@ -179,7 +195,6 @@
1206
1207 static void recv4(int s) {
1208 int len;
1209- int interface;
1210
1211 mh.msg_name=&sa4;
1212 mh.msg_namelen=sizeof(sa4);
1213@@ -190,17 +205,26 @@
1214 peer=(struct sockaddr*)&sa4;
1215 sl=sizeof(sa4);
1216
1217- interface=v4if();
1218- getip(interface);
1219+#ifdef DEBUG
1220+ printf("v4: ");
1221+#endif
1222
1223- handle(s,buf,len,interface,s==ls4);
1224+ handle(s,buf,len,v4if(),s==ls4);
1225 }
1226
1227 static void recv6(int s) {
1228 int len,interface;
1229+#ifdef DEBUG
1230+ char addrbuf[INET6_ADDRSTRLEN];
1231+ char ifbuf[IFNAMSIZ];
1232+#endif
1233
1234 mh.msg_name=&sa6;
1235 mh.msg_namelen=sizeof(sa6);
1236+
1237+ mh.msg_control=abuf;
1238+ mh.msg_controllen=sizeof(abuf);
1239+
1240 if ((len=recvmsg(s,&mh,0))==-1) {
1241 perror("recvmsg");
1242 exit(3);
1243@@ -208,18 +232,31 @@
1244 peer=(struct sockaddr*)&sa6;
1245 sl=sizeof(sa6);
1246
1247- if (IN6_IS_ADDR_V4MAPPED(sa6.sin6_addr.s6_addr))
1248+ if (IN6_IS_ADDR_V4MAPPED(sa6.sin6_addr.s6_addr)) {
1249 interface=v4if();
1250- else
1251+#ifdef DEBUG
1252+ inet_ntop(AF_INET,(char*)(sa6.sin6_addr.s6_addr)+12,addrbuf,sizeof addrbuf);
1253+ if_indextoname(interface,ifbuf);
1254+ printf("v4: %s: ",ifbuf);
1255+#endif
1256+ } else {
1257 interface=sa6.sin6_scope_id;
1258-
1259- getip(interface);
1260+#ifdef DEBUG
1261+ inet_ntop(AF_INET6,sa6.sin6_addr.s6_addr,addrbuf,sizeof addrbuf);
1262+ if_indextoname(interface,ifbuf);
1263+ printf("v6: %s: ",ifbuf);
1264+#endif
1265+ }
1266
1267 handle(s,buf,len,interface,s==ls6);
1268+#ifdef DEBUG
1269+ printf(" from %s\n",addrbuf);
1270+#endif
1271 }
1272
1273 static void init_sockets(int* sock6,int* sock4,int port,char* v6ip,char* v4ip) {
1274 int s4,s6;
1275+ int one=1;
1276 *sock6=-1; *sock4=-1;
1277 s6=socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP);
1278 s4=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
1279@@ -228,6 +265,7 @@
1280 return;
1281 }
1282 if (s6!=-1) {
1283+ setsockopt(s6,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one));
1284 memset(&sa6,0,sizeof(sa6));
1285 sa6.sin6_family=PF_INET6;
1286 sa6.sin6_port=htons(port);
1287@@ -238,6 +276,7 @@
1288 }
1289 }
1290 if (s4!=-1) {
1291+ setsockopt(s4,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one));
1292 memset(&sa4,0,sizeof(sa4));
1293 sa4.sin_family=PF_INET;
1294 sa4.sin_port=htons(port);
1295diff -urN -x CVS dietlibc-0.31/diet.c dietlibc/diet.c
1296--- dietlibc-0.31/diet.c 2006-08-27 15:49:00.000000000 +0200
1297+++ dietlibc/diet.c 2009-03-17 00:17:58.000000000 +0100
1298@@ -32,7 +32,11 @@
1299 "sparc","-Os","-mcpu=supersparc",0,
1300 "sparc64","-Os","-m64","-mhard-quad-float",0,
1301 "alpha","-Os","-fomit-frame-pointer",0,
1302+#ifdef __ARM_EABI__
1303+ "arm","-Os","-fomit-frame-pointer","-mfloat-abi=soft","-meabi=4",0,
1304+#else
1305 "arm","-Os","-fomit-frame-pointer",0,
1306+#endif
1307 "mips","-Os","-fomit-frame-pointer","-mno-abicalls","-fno-pic","-G","0",0,
1308 "mipsel","-Os","-fomit-frame-pointer","-mno-abicalls","-fno-pic","-G","0",0,
1309 "ppc","-Os","-fomit-frame-pointer","-mpowerpc-gpopt","-mpowerpc-gfxopt",0,
1310@@ -77,6 +81,7 @@
1311 #endif
1312 const char *nostdlib="-nostdlib";
1313 const char *libgcc="-lgcc";
1314+ char *libpthread="-lpthread";
1315 char dashL[1000];
1316 char dashstatic[]="-static";
1317 int i;
1318@@ -225,7 +230,7 @@
1319 pp:
1320 preprocess=compile=1;
1321 }
1322-/* we need to add -nostdlib if we are not compiling*/
1323+/* we need to add -nostdlib if we are not compiling */
1324 _link=!compile;
1325 #ifdef __DYN_LIB
1326 if (_link) {
1327@@ -241,6 +246,7 @@
1328 if (!strcmp(argv[i],"-o"))
1329 if (!compile) _link=1;
1330 #endif
1331+
1332 newargv=alloca(sizeof(char*)*(argc+100));
1333 a=alloca(strlen(diethome)+20);
1334 b=alloca(strlen(platform)+20);
1335@@ -315,6 +321,11 @@
1336 if (_link) { *dest++=d; }
1337 #endif
1338 for (i=2; i<argc; ++i) {
1339+ if (!strcmp(argv[i],"-pthread")) {
1340+ *dest++="-D_REENTRANT";
1341+ if (_link) *dest++="-lpthread";
1342+ continue;
1343+ }
1344 if (mangleopts)
1345 if (argv[i][0]=='-' && (argv[i][1]=='O' || argv[i][1]=='f' ||
1346 (argv[i][1]=='m' && argv[i][2]!='3' && argv[i][2]!='6'))) {
1347diff -urN -x CVS dietlibc-0.31/dietfeatures.h dietlibc/dietfeatures.h
1348--- dietlibc-0.31/dietfeatures.h 2007-08-03 22:58:33.000000000 +0200
1349+++ dietlibc/dietfeatures.h 2009-02-26 21:51:54.000000000 +0100
1350@@ -25,6 +25,9 @@
1351 /* use errno_location instead of errno */
1352 #define WANT_THREAD_SAFE
1353
1354+/* support __thread */
1355+#define WANT_TLS
1356+
1357 /* make the startcode, etc. dynamic aware ({con,de}structors) */
1358 /* #define WANT_DYNAMIC */
1359
1360@@ -32,7 +35,7 @@
1361 #define WANT_LD_SO_GDB_SUPPORT
1362
1363 /* do you want smaller or faster string routines? */
1364-/* #define WANT_FASTER_STRING_ROUTINES */
1365+#define WANT_FASTER_STRING_ROUTINES
1366
1367 /* define this to have strncpy zero-fill and not just zero-terminate the
1368 * string */
1369@@ -111,20 +114,10 @@
1370 /* Include support for ProPolice/SSP, calls guard_setup */
1371 /* ProPolice is part of gcc 4.1 and up, there were patches for earlier
1372 * versions. To make use of this, compile your application with
1373- * -fstack-protector. On i386, enabling this option with
1374- * WANT_SSP_URANDOM and then not using -fstack-protector enlarges a
1375- * binary by 152 bytes. */
1376+ * -fstack-protector. */
1377 #if (__GNUC__>4) || ((__GNUC__==4) && (__GNUC_MINOR__>=1))
1378 #define WANT_SSP
1379 #endif
1380-/* Choose which canary seeder you want you can choose
1381- * both but it will check urandom first and use xor as
1382- * a fallback. xor is lighter but weaker */
1383-#define WANT_SSP_URANDOM
1384-/* The XOR seeder is completely predictable and should not be used
1385- * unless you don't have a /dev/urandom, and even then it's a bad idea. */
1386-/* #define WANT_SSP_XOR */
1387-
1388
1389
1390
1391diff -urN -x CVS dietlibc-0.31/dietstring.h dietlibc/dietstring.h
1392--- dietlibc-0.31/dietstring.h 2003-12-21 13:06:36.000000000 +0100
1393+++ dietlibc/dietstring.h 2008-02-19 01:28:13.000000000 +0100
1394@@ -11,6 +11,16 @@
1395 # define STRALIGN(x) (((unsigned long)x&3)?4-((unsigned long)x&3):0)
1396 #endif
1397
1398+/* GFC(x) - returns first character */
1399+/* INCSTR(x) - moves to next character */
1400+#if __BYTE_ORDER == __LITTLE_ENDIAN
1401+# define GFC(x) ((x)&0xff)
1402+# define INCSTR(x) do { x >>= 8; } while (0)
1403+#else
1404+# define GFC(x) (((x)>>(sizeof(x)*8-8))&0xff)
1405+# define INCSTR(x) do { x <<= 8; } while (0)
1406+#endif
1407+
1408 #define UNALIGNED(x,y) (((unsigned long)x & (sizeof (unsigned long)-1)) ^ ((unsigned long)y & (sizeof (unsigned long)-1)))
1409
1410 #endif /* _DIET_STRING_H_ */
1411diff -urN -x CVS dietlibc-0.31/dyn_start.c dietlibc/dyn_start.c
1412--- dietlibc-0.31/dyn_start.c 2005-09-21 09:33:08.000000000 +0200
1413+++ dietlibc/dyn_start.c 2008-04-12 00:51:11.000000000 +0200
1414@@ -67,8 +67,11 @@
1415 {
1416 int main(int argc, char **argv, char **envp);
1417
1418+#ifndef __arm__
1419+ /* GT: segfaults on arm, don't know why (for now) */
1420 void _dl_aux_init_from_envp(char **envp);
1421 _dl_aux_init_from_envp(envp);
1422+#endif
1423
1424 if (dl_init) atexit(dl_init);
1425 _init();
1426diff -urN -x CVS dietlibc-0.31/FAQ dietlibc/FAQ
1427--- dietlibc-0.31/FAQ 2007-04-02 07:31:53.000000000 +0200
1428+++ dietlibc/FAQ 2008-08-30 15:59:17.000000000 +0200
1429@@ -331,3 +331,14 @@
1430 diet-dyn gcc -Wl,--hash-style=sysv -shared -o libx.so x.c
1431 ^^^^^^^^^^^^^^^^^^^^^
1432
1433+
1434+Q: How do I compile OpenSSL with dietlibc?
1435+A: Here's how I do it:
1436+
1437+ ./config --prefix=/opt/diet no-dso
1438+ make libssl.pc openssl.pc
1439+ for i in libssl.pc openssl.pc Makefile; do (echo ",s/ *-ldl//g"; echo w) | ed $i; done
1440+ make CC="diet -Os gcc -pipe -nostdinc"
1441+
1442+Then the libraries go to /opt/diet/lib, so you still need a symlink to
1443+lib-i386 or whatever your architecture is.
1444diff -urN -x CVS dietlibc-0.31/i386/dyn_syscalls.S dietlibc/i386/dyn_syscalls.S
1445--- dietlibc-0.31/i386/dyn_syscalls.S 2006-10-13 22:11:13.000000000 +0200
1446+++ dietlibc/i386/dyn_syscalls.S 2008-12-27 20:53:16.000000000 +0100
1447@@ -349,6 +349,9 @@
1448 #include "../syscalls.s/lgetxattr.S"
1449 #include "../syscalls.s/fgetxattr.S"
1450
1451+#include "../syscalls.s/timerfd.S"
1452+#include "../syscalls.s/__signalfd.S"
1453+
1454 #undef __PIC__
1455 #undef __socketcall
1456 /* oh what a kludge! */
1457diff -urN -x CVS dietlibc-0.31/i386/syscalls.h dietlibc/i386/syscalls.h
1458--- dietlibc-0.31/i386/syscalls.h 2007-01-10 23:51:09.000000000 +0100
1459+++ dietlibc/i386/syscalls.h 2008-09-30 23:02:35.000000000 +0200
1460@@ -318,6 +318,13 @@
1461 #define __NR_move_pages 317
1462 #define __NR_getcpu 318
1463 #define __NR_epoll_pwait 319
1464+#define __NR_utimensat 320
1465+#define __NR_signalfd 321
1466+#define __NR_timerfd 322
1467+#define __NR_eventfd 323
1468+#define __NR_fallocate 324
1469+#define __NR_timerfd_settime 325
1470+#define __NR_timerfd_gettime 326
1471
1472
1473 #define syscall_weak(name,wsym,sym) \
1474diff -urN -x CVS dietlibc-0.31/ia64/syscalls.h dietlibc/ia64/syscalls.h
1475--- dietlibc-0.31/ia64/syscalls.h 2006-09-19 00:08:39.000000000 +0200
1476+++ dietlibc/ia64/syscalls.h 2008-09-30 23:02:35.000000000 +0200
1477@@ -279,7 +279,16 @@
1478 #define __NR_sync_file_range 1300
1479 #define __NR_tee 1301
1480 #define __NR_vmsplice 1302
1481-
1482+#define __NR_fallocate 1303
1483+#define __NR_getcpu 1304
1484+#define __NR_epoll_pwait 1305
1485+#define __NR_utimensat 1306
1486+#define __NR_signalfd 1307
1487+#define __NR_timerfd 1308
1488+#define __NR_eventfd 1309
1489+#define __NR_timerfd_create 1310
1490+#define __NR_timerfd_settime 1311
1491+#define __NR_timerfd_gettime 1312
1492
1493 #define syscall(name, sym) \
1494 .text; \
1495diff -urN -x CVS dietlibc-0.31/include/elf.h dietlibc/include/elf.h
1496--- dietlibc-0.31/include/elf.h 2006-11-08 16:14:27.000000000 +0100
1497+++ dietlibc/include/elf.h 2008-09-05 17:13:29.000000000 +0200
1498@@ -2078,6 +2078,7 @@
1499 #define EF_ARM_EABI_UNKNOWN 0x00000000
1500 #define EF_ARM_EABI_VER1 0x01000000
1501 #define EF_ARM_EABI_VER2 0x02000000
1502+#define EF_ARM_EABI_VER4 0x04000000
1503
1504 /* Additional symbol types for Thumb */
1505 #define STT_ARM_TFUNC 0xd
1506diff -urN -x CVS dietlibc-0.31/include/fcntl.h dietlibc/include/fcntl.h
1507--- dietlibc-0.31/include/fcntl.h 2005-10-04 19:47:03.000000000 +0200
1508+++ dietlibc/include/fcntl.h 2008-02-19 01:28:13.000000000 +0100
1509@@ -624,9 +624,51 @@
1510 #endif
1511
1512 #if defined(_LINUX_SOURCE) || defined(_GNU_SOURCE)
1513-ssize_t readahead(int fd, off64_t *offset, size_t count);
1514+ssize_t readahead(int fd, off64_t *offset, size_t count) __THROW;
1515 #endif
1516
1517+#ifdef _GNU_SOURCE
1518+#define SPLICE_F_MOVE (0x01) /* move pages instead of copying */
1519+#define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
1520+ /* we may still block on the fd we splice */
1521+ /* from/to, of course */
1522+#define SPLICE_F_MORE (0x04) /* expect more data */
1523+#define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */
1524+
1525+long tee(int fd_in, int fd_out, size_t len, unsigned int flags) __THROW;
1526+
1527+#include <sys/uio.h>
1528+
1529+long vmsplice(int fd, const struct iovec *iov, unsigned long nr_segs, unsigned int flags) __THROW;
1530+long splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags) __THROW;
1531+
1532+int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags) __THROW;
1533+#endif
1534+
1535+#ifdef _ATFILE_SOURCE
1536+#define AT_FDCWD -100 /* Special value used to indicate openat should use the current working directory. */
1537+#define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
1538+#define AT_REMOVEDIR 0x200 /* Remove directory instead of unlinking file. */
1539+#define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
1540+
1541+int openat(int dirfd, const char *pathname, int flags, ...);
1542+int faccessat(int dirfd, const char *pathname, int mode, int flags);
1543+int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
1544+int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags);
1545+int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags);
1546+int futimesat(int dirfd, const char *pathname, const struct timeval times[2]);
1547+int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags);
1548+int mkdirat(int dirfd, const char *pathname, mode_t mode);
1549+int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev);
1550+int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz);
1551+int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
1552+int symlinkat(const char *oldpath, int newdirfd, const char *newpath);
1553+int unlinkat(int dirfd, const char *pathname, int flags);
1554+int mkfifoat(int dirfd, const char *pathname, mode_t mode);
1555+int utimensat(int dirfd, const char *pathname, struct timespec* t);
1556+#endif
1557+
1558+
1559 __END_DECLS
1560
1561 #endif
1562diff -urN -x CVS dietlibc-0.31/include/linux/eventpoll.h dietlibc/include/linux/eventpoll.h
1563--- dietlibc-0.31/include/linux/eventpoll.h 2003-08-19 18:58:18.000000000 +0200
1564+++ dietlibc/include/linux/eventpoll.h 2008-02-20 01:45:11.000000000 +0100
1565@@ -3,7 +3,7 @@
1566
1567 #include <sys/cdefs.h>
1568 #include <sys/ioctl.h>
1569-#include <sys/poll.h>
1570+#include <poll.h>
1571 #include <sys/shm.h>
1572
1573 __BEGIN_DECLS
1574diff -urN -x CVS dietlibc-0.31/include/netinet/in.h dietlibc/include/netinet/in.h
1575--- dietlibc-0.31/include/netinet/in.h 2005-09-21 09:33:08.000000000 +0200
1576+++ dietlibc/include/netinet/in.h 2008-02-19 01:28:13.000000000 +0100
1577@@ -350,6 +350,7 @@
1578 /* fnord */
1579
1580 #define IPPORT_RESERVED 1024
1581+#define INET_ADDRSTRLEN 16
1582 #define INET6_ADDRSTRLEN 46
1583
1584 #undef htonl
1585diff -urN -x CVS dietlibc-0.31/include/paths.h dietlibc/include/paths.h
1586--- dietlibc-0.31/include/paths.h 2005-04-26 19:47:18.000000000 +0200
1587+++ dietlibc/include/paths.h 2008-02-23 01:09:54.000000000 +0100
1588@@ -26,4 +26,14 @@
1589
1590 #define _PATH_TMP "/tmp/"
1591
1592+#define _PATH_UTMP "/var/run/utmp"
1593+#define _PATH_WTMP "/var/log/wtmp"
1594+#ifdef _BSD_SOURCE
1595+/* die, BSD, die!!! */
1596+#define UTMP_FILE _PATH_UTMP
1597+#define WTMP_FILE _PATH_WTMP
1598+#endif
1599+#define _PATH_UTMPX _PATH_UTMP
1600+#define _PATH_WTMPX _PATH_WTMP
1601+
1602 #endif
1603diff -urN -x CVS dietlibc-0.31/include/poll.h dietlibc/include/poll.h
1604--- dietlibc-0.31/include/poll.h 2003-03-14 17:42:28.000000000 +0100
1605+++ dietlibc/include/poll.h 2008-02-20 01:47:08.000000000 +0100
1606@@ -1,3 +1,58 @@
1607-/* ah, the sublime brokenness... susv3 defines poll.h, the Linux man
1608- * page defines sys/poll.h; duh! */
1609-#include <sys/poll.h>
1610+#ifndef _POLL_H
1611+#define _POLL_H
1612+
1613+#include <sys/cdefs.h>
1614+
1615+__BEGIN_DECLS
1616+
1617+enum {
1618+ POLLIN = 0x0001,
1619+#define POLLIN POLLIN
1620+ POLLPRI = 0x0002,
1621+#define POLLPRI POLLPRI
1622+ POLLOUT = 0x0004,
1623+#define POLLOUT POLLOUT
1624+ POLLERR = 0x0008,
1625+#define POLLERR POLLERR
1626+ POLLHUP = 0x0010,
1627+#define POLLHUP POLLHUP
1628+ POLLNVAL = 0x0020,
1629+#define POLLNVAL POLLNVAL
1630+ POLLRDNORM = 0x0040,
1631+#define POLLRDNORM POLLRDNORM
1632+ POLLRDBAND = 0x0080,
1633+#define POLLRDBAND POLLRDBAND
1634+ POLLWRBAND = 0x0200,
1635+#define POLLWRBAND POLLWRBAND
1636+ POLLMSG = 0x0400,
1637+#define POLLMSG POLLMSG
1638+/* POLLREMOVE is for /dev/epoll (/dev/misc/eventpoll),
1639+ * a new event notification mechanism for 2.6 */
1640+ POLLREMOVE = 0x1000,
1641+#define POLLREMOVE POLLREMOVE
1642+};
1643+
1644+#if defined(__sparc__) || defined (__mips__)
1645+#define POLLWRNORM POLLOUT
1646+#else
1647+#define POLLWRNORM 0x0100
1648+#endif
1649+
1650+struct pollfd {
1651+ int fd;
1652+ short events;
1653+ short revents;
1654+};
1655+
1656+typedef unsigned int nfds_t;
1657+
1658+extern int poll(struct pollfd *ufds, nfds_t nfds, int timeout) __THROW;
1659+
1660+#ifdef _GNU_SOURCE
1661+#include <signal.h>
1662+int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *sigmask) __THROW;
1663+#endif
1664+
1665+__END_DECLS
1666+
1667+#endif /* _POLL_H */
1668diff -urN -x CVS dietlibc-0.31/include/resolv.h dietlibc/include/resolv.h
1669--- dietlibc-0.31/include/resolv.h 2006-07-05 08:27:18.000000000 +0200
1670+++ dietlibc/include/resolv.h 2008-09-30 23:02:35.000000000 +0200
1671@@ -119,8 +119,8 @@
1672 int length, unsigned char **dnptrs, unsigned char *exp_dn,
1673 unsigned char **lastdnptr) __THROW;
1674
1675-int dn_expand(unsigned char *msg, unsigned char *eomorig,
1676- unsigned char *comp_dn, unsigned char *exp_dn,
1677+int dn_expand(const unsigned char *msg, const unsigned char *eomorig,
1678+ const unsigned char *comp_dn, unsigned char *exp_dn,
1679 int length) __THROW;
1680
1681 void res_close(void) __THROW __attribute_dontuse__;
1682diff -urN -x CVS dietlibc-0.31/include/sched.h dietlibc/include/sched.h
1683--- dietlibc-0.31/include/sched.h 2003-08-19 18:58:17.000000000 +0200
1684+++ dietlibc/include/sched.h 2008-02-19 01:28:13.000000000 +0100
1685@@ -7,24 +7,6 @@
1686 __BEGIN_DECLS
1687
1688 /*
1689- * cloning flags:
1690- */
1691-#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
1692-#define CLONE_VM 0x00000100 /* set if VM shared between processes */
1693-#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
1694-#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
1695-#define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */
1696-#define CLONE_PID 0x00001000 /* set if pid shared */
1697-#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
1698-#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
1699-#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
1700-#define CLONE_THREAD 0x00010000 /* Same thread group? */
1701-
1702-#define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
1703-
1704-int clone(void*(*fn)(void*),void*stack,int flags,void*arg);
1705-
1706-/*
1707 * Scheduling policies
1708 */
1709 #define SCHED_OTHER 0
1710@@ -67,6 +49,28 @@
1711 int __sched_rr_get_interval(pid_t pid, struct timespec* tp);
1712 int sched_rr_get_interval(pid_t pid, struct timespec* tp);
1713
1714+#ifdef _GNU_SOURCE
1715+/*
1716+ * cloning flags:
1717+ */
1718+#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
1719+#define CLONE_VM 0x00000100 /* set if VM shared between processes */
1720+#define CLONE_FS 0x00000200 /* set if fs info shared between processes */
1721+#define CLONE_FILES 0x00000400 /* set if open files shared between processes */
1722+#define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */
1723+#define CLONE_PID 0x00001000 /* set if pid shared */
1724+#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
1725+#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
1726+#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
1727+#define CLONE_THREAD 0x00010000 /* Same thread group? */
1728+
1729+#define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
1730+
1731+int clone(void*(*fn)(void*),void*stack,int flags,void*arg);
1732+
1733+int unshare(int flags);
1734+#endif
1735+
1736 __END_DECLS
1737
1738 #endif
1739diff -urN -x CVS dietlibc-0.31/include/stdarg.h dietlibc/include/stdarg.h
1740--- dietlibc-0.31/include/stdarg.h 2003-08-19 18:58:17.000000000 +0200
1741+++ dietlibc/include/stdarg.h 2008-11-26 19:43:06.000000000 +0100
1742@@ -9,7 +9,7 @@
1743 #if (__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 96))
1744
1745 typedef __builtin_va_list va_list;
1746-#define va_start(v,l) __builtin_stdarg_start((v),l)
1747+#define va_start(v,l) __builtin_va_start((v),(l))
1748 #define va_end __builtin_va_end
1749 #define va_arg __builtin_va_arg
1750 #define __va_copy(d,s) __builtin_va_copy((d),(s))
1751diff -urN -x CVS dietlibc-0.31/include/stdlib.h dietlibc/include/stdlib.h
1752--- dietlibc-0.31/include/stdlib.h 2006-07-04 05:33:02.000000000 +0200
1753+++ dietlibc/include/stdlib.h 2007-09-20 20:51:18.000000000 +0200
1754@@ -111,6 +111,11 @@
1755 int clearenv(void);
1756 #endif
1757
1758+int mbtowc(wchar_t *pwc, const char *s, size_t n) __THROW;
1759+int wctomb(char *s, wchar_t wc) __THROW;
1760+size_t mbstowcs(wchar_t *dest, const char *src, size_t n) __THROW;
1761+int mblen(const char* s,size_t n) __THROW __pure;
1762+
1763 __END_DECLS
1764
1765 #endif
1766diff -urN -x CVS dietlibc-0.31/include/sys/cdefs.h dietlibc/include/sys/cdefs.h
1767--- dietlibc-0.31/include/sys/cdefs.h 2005-10-04 19:47:03.000000000 +0200
1768+++ dietlibc/include/sys/cdefs.h 2008-05-09 06:36:56.000000000 +0200
1769@@ -31,6 +31,7 @@
1770 #if __GNUC__ < 3
1771 #define __builtin_expect(foo,bar) (foo)
1772 #define __expect(foo,bar) (foo)
1773+#define __malloc__
1774 #else
1775 #define __expect(foo,bar) __builtin_expect((long)(foo),bar)
1776 #define __attribute_malloc__ __attribute__((__malloc__))
1777@@ -74,6 +75,7 @@
1778 # define __attribute_used __attribute__ ((__used__))
1779 #else
1780 # define __attribute_used
1781+# define __warn_unused_result__
1782 #endif
1783
1784 #if (__GNUC__ >= 4)
1785@@ -83,4 +85,10 @@
1786 #define __sentinel__
1787 #endif
1788
1789+#if (__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3))
1790+# define __cold__
1791+# define __hot__
1792+#endif
1793+
1794+
1795 #endif
1796diff -urN -x CVS dietlibc-0.31/include/sys/epoll.h dietlibc/include/sys/epoll.h
1797--- dietlibc-0.31/include/sys/epoll.h 2005-03-15 09:51:22.000000000 +0100
1798+++ dietlibc/include/sys/epoll.h 2008-02-20 01:45:12.000000000 +0100
1799@@ -3,7 +3,8 @@
1800
1801 #include <sys/cdefs.h>
1802 #include <sys/types.h>
1803-#include <sys/poll.h>
1804+#include <poll.h>
1805+#include <signal.h>
1806
1807 __BEGIN_DECLS
1808
1809@@ -65,6 +66,8 @@
1810 int epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) __THROW;
1811 int epoll_wait(int epfd, struct epoll_event *events, int maxevents,
1812 int timeout) __THROW;
1813+int epoll_pwait(int epfd, struct epoll_event *events, int maxevents,
1814+ int timeout, const sigset_t* sigmask) __THROW;
1815
1816 __END_DECLS
1817
1818diff -urN -x CVS dietlibc-0.31/include/sys/inotify.h dietlibc/include/sys/inotify.h
1819--- dietlibc-0.31/include/sys/inotify.h 2005-10-04 19:47:03.000000000 +0200
1820+++ dietlibc/include/sys/inotify.h 2008-02-19 01:28:13.000000000 +0100
1821@@ -2,13 +2,14 @@
1822 #define _SYS_INOTIFY_H
1823
1824 #include <sys/cdefs.h>
1825+#include <inttypes.h>
1826
1827 struct inotify_event {
1828- __s32 wd; /* watch descriptor */
1829- __u32 mask; /* watch mask */
1830- __u32 cookie; /* cookie to synchronize two events */
1831- __u32 len; /* length (including nulls) of name */
1832- char name[0]; /* stub for possible name */
1833+ int32_t wd; /* watch descriptor */
1834+ uint32_t mask, /* watch mask */
1835+ cookie, /* cookie to synchronize two events */
1836+ len; /* length (including nulls) of name */
1837+ char name[0]; /* stub for possible name */
1838 };
1839
1840 /* the following are legal, implemented events that user-space can watch for */
1841@@ -35,6 +36,9 @@
1842 #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */
1843
1844 /* special flags */
1845+#define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */
1846+#define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */
1847+#define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */
1848 #define IN_ISDIR 0x40000000 /* event occurred against dir */
1849 #define IN_ONESHOT 0x80000000 /* only send event once */
1850
1851diff -urN -x CVS dietlibc-0.31/include/sys/mman.h dietlibc/include/sys/mman.h
1852--- dietlibc-0.31/include/sys/mman.h 2005-04-25 09:22:24.000000000 +0200
1853+++ dietlibc/include/sys/mman.h 2007-10-09 01:15:27.000000000 +0200
1854@@ -26,6 +26,7 @@
1855 #define MAP_DENYWRITE 0x2000 /* ETXTBSY */
1856 #define MAP_EXECUTABLE 0x4000 /* mark it as an executable */
1857 #define MAP_LOCKED 0x8000 /* pages are locked */
1858+#define MAP_POPULATE 0x10000
1859 #define MS_ASYNC 0x0001 /* sync memory asynchronously */
1860 #define MS_INVALIDATE 0x0002 /* invalidate mappings & caches */
1861 #define MS_SYNC 0x0004 /* synchronous memory sync */
1862@@ -44,6 +45,7 @@
1863 #define MAP_EXECUTABLE 0x4000 /* mark it as an executable */
1864 #define MAP_LOCKED 0x8000 /* lock the mapping */
1865 #define MAP_NORESERVE 0x10000 /* don't check for reservations */
1866+#define MAP_POPULATE 0x20000
1867 #define MS_ASYNC 1 /* sync memory asynchronously */
1868 #define MS_SYNC 2 /* synchronous memory sync */
1869 #define MS_INVALIDATE 4 /* invalidate the caches */
1870@@ -63,6 +65,7 @@
1871 #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */
1872 #define MAP_LOCKED 0x2000 /* pages are locked */
1873 #define MAP_NORESERVE 0x4000 /* don't check for reservations */
1874+#define MAP_POPULATE 0x8000
1875 #define MS_ASYNC 1 /* sync memory asynchronously */
1876 #define MS_INVALIDATE 2 /* invalidate the caches */
1877 #define MS_SYNC 4 /* synchronous memory sync */
1878@@ -84,6 +87,7 @@
1879 #define MAP_GROWSDOWN 0x0100 /* stack-like segment */
1880 #define MAP_DENYWRITE 0x0800 /* ETXTBSY */
1881 #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */
1882+#define MAP_POPULATE 0x8000
1883 #define MS_ASYNC 1 /* sync memory asynchronously */
1884 #define MS_INVALIDATE 2 /* invalidate the caches */
1885 #define MS_SYNC 4 /* synchronous memory sync */
1886@@ -103,6 +107,7 @@
1887 #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */
1888 #define MAP_LOCKED 0x2000 /* pages are locked */
1889 #define MAP_NORESERVE 0x4000 /* don't check for reservations */
1890+#define MAP_POPULATE 0x8000
1891 #define MS_ASYNC 1 /* sync memory asynchronously */
1892 #define MS_INVALIDATE 2 /* invalidate the caches */
1893 #define MS_SYNC 4 /* synchronous memory sync */
1894@@ -124,6 +129,7 @@
1895 #define MAP_LOCKED 0x2000 /* pages are locked */
1896 #define MAP_NORESERVE 0x4000 /* don't check for reservations */
1897 #define MAP_GROWSDOWN 0x8000 /* stack-like segment */
1898+#define MAP_POPULATE 0x10000
1899
1900 #define MS_SYNC 1 /* synchronous memory sync */
1901 #define MS_ASYNC 2 /* sync memory asynchronously */
1902@@ -160,6 +166,7 @@
1903 #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */
1904 #define MAP_LOCKED 0x2000 /* pages are locked */
1905 #define MAP_NORESERVE 0x4000 /* don't check for reservations */
1906+#define MAP_POPULATE 0x8000
1907 #define MAP_WRITECOMBINED 0x10000 /* write-combine the area */
1908 #define MAP_NONCACHED 0x20000 /* don't cache the memory */
1909
1910diff -urN -x CVS dietlibc-0.31/include/sys/poll.h dietlibc/include/sys/poll.h
1911--- dietlibc-0.31/include/sys/poll.h 2003-08-19 18:58:18.000000000 +0200
1912+++ dietlibc/include/sys/poll.h 2008-02-20 01:45:12.000000000 +0100
1913@@ -1,51 +1,8 @@
1914+/* ah, the sublime brokenness... susv3 defines poll.h, the Linux man
1915+ * page defines sys/poll.h; duh! */
1916 #ifndef _SYS_POLL_H
1917 #define _SYS_POLL_H
1918
1919-#include <sys/cdefs.h>
1920+#include <poll.h>
1921
1922-__BEGIN_DECLS
1923-
1924-enum {
1925- POLLIN = 0x0001,
1926-#define POLLIN POLLIN
1927- POLLPRI = 0x0002,
1928-#define POLLPRI POLLPRI
1929- POLLOUT = 0x0004,
1930-#define POLLOUT POLLOUT
1931- POLLERR = 0x0008,
1932-#define POLLERR POLLERR
1933- POLLHUP = 0x0010,
1934-#define POLLHUP POLLHUP
1935- POLLNVAL = 0x0020,
1936-#define POLLNVAL POLLNVAL
1937- POLLRDNORM = 0x0040,
1938-#define POLLRDNORM POLLRDNORM
1939- POLLRDBAND = 0x0080,
1940-#define POLLRDBAND POLLRDBAND
1941- POLLWRBAND = 0x0200,
1942-#define POLLWRBAND POLLWRBAND
1943- POLLMSG = 0x0400,
1944-#define POLLMSG POLLMSG
1945-/* POLLREMOVE is for /dev/epoll (/dev/misc/eventpoll),
1946- * a new event notification mechanism for 2.6 */
1947- POLLREMOVE = 0x1000,
1948-#define POLLREMOVE POLLREMOVE
1949-};
1950-
1951-#if defined(__sparc__) || defined (__mips__)
1952-#define POLLWRNORM POLLOUT
1953-#else
1954-#define POLLWRNORM 0x0100
1955 #endif
1956-
1957-struct pollfd {
1958- int fd;
1959- short events;
1960- short revents;
1961-};
1962-
1963-extern int poll(struct pollfd *ufds, unsigned int nfds, int timeout) __THROW;
1964-
1965-__END_DECLS
1966-
1967-#endif /* _SYS_POLL_H */
1968diff -urN -x CVS dietlibc-0.31/include/sys/signalfd.h dietlibc/include/sys/signalfd.h
1969--- dietlibc-0.31/include/sys/signalfd.h 1970-01-01 01:00:00.000000000 +0100
1970+++ dietlibc/include/sys/signalfd.h 2008-02-19 01:28:13.000000000 +0100
1971@@ -0,0 +1,33 @@
1972+#ifndef _SYS_SIGNALFD_H
1973+#define _SYS_SIGNALFD_H
1974+
1975+#include <inttypes.h>
1976+
1977+struct signalfd_siginfo {
1978+ uint32_t ssi_signo;
1979+ int32_t ssi_errno;
1980+ int32_t ssi_code;
1981+ uint32_t ssi_pid;
1982+ uint32_t ssi_uid;
1983+ int32_t ssi_fd;
1984+ uint32_t ssi_tid;
1985+ uint32_t ssi_band;
1986+ uint32_t ssi_overrun;
1987+ uint32_t ssi_trapno;
1988+ int32_t ssi_status;
1989+ int32_t ssi_int;
1990+ uint64_t ssi_ptr;
1991+ uint64_t ssi_utime;
1992+ uint64_t ssi_stime;
1993+ uint64_t ssi_addr;
1994+ uint8_t __pad[48];
1995+};
1996+
1997+__BEGIN_DECLS
1998+
1999+extern int signalfd (int __fd, const sigset_t *__mask, int __flags)
2000+ __nonnull ((2)) __THROW;
2001+
2002+__END_DECLS
2003+
2004+#endif
2005diff -urN -x CVS dietlibc-0.31/include/sys/statvfs.h dietlibc/include/sys/statvfs.h
2006--- dietlibc-0.31/include/sys/statvfs.h 1970-01-01 01:00:00.000000000 +0100
2007+++ dietlibc/include/sys/statvfs.h 2008-08-06 02:28:13.000000000 +0200
2008@@ -0,0 +1,61 @@
2009+#ifndef _SYS_STATVFS_H
2010+#define _SYS_STATVFS_H
2011+
2012+#include <sys/cdefs.h>
2013+#include <sys/types.h>
2014+
2015+__BEGIN_DECLS
2016+
2017+struct statvfs {
2018+ unsigned long f_bsize; /* file system block size */
2019+ unsigned long f_frsize; /* fragment size */
2020+ fsblkcnt_t f_blocks; /* size of fs in f_frsize units */
2021+ fsblkcnt_t f_bfree; /* # free blocks */
2022+ fsblkcnt_t f_bavail; /* # free blocks for non-root */
2023+ fsfilcnt_t f_files; /* # inodes */
2024+ fsfilcnt_t f_ffree; /* # free inodes */
2025+ fsfilcnt_t f_favail; /* # free inodes for non-root */
2026+ unsigned long f_fsid; /* file system ID */
2027+ unsigned long f_flag; /* mount flags */
2028+ unsigned long f_namemax; /* maximum filename length */
2029+};
2030+
2031+int statvfs(const char *path, struct statvfs *buf) __THROW;
2032+int fstatvfs(int fd, struct statvfs *buf) __THROW;
2033+
2034+/* Definitions for the flag in `f_flag'. These definitions should be
2035+ kept in sync with the definitions in <sys/mount.h>. */
2036+enum
2037+{
2038+ ST_RDONLY = 1, /* Mount read-only. */
2039+#define ST_RDONLY ST_RDONLY
2040+ ST_NOSUID = 2 /* Ignore suid and sgid bits. */
2041+#define ST_NOSUID ST_NOSUID
2042+#ifdef __USE_GNU
2043+ ,
2044+ ST_NODEV = 4, /* Disallow access to device special files. */
2045+# define ST_NODEV ST_NODEV
2046+ ST_NOEXEC = 8, /* Disallow program execution. */
2047+# define ST_NOEXEC ST_NOEXEC
2048+ ST_SYNCHRONOUS = 16, /* Writes are synced at once. */
2049+# define ST_SYNCHRONOUS ST_SYNCHRONOUS
2050+ ST_MANDLOCK = 64, /* Allow mandatory locks on an FS. */
2051+# define ST_MANDLOCK ST_MANDLOCK
2052+ ST_WRITE = 128, /* Write on file/directory/symlink. */
2053+# define ST_WRITE ST_WRITE
2054+ ST_APPEND = 256, /* Append-only file. */
2055+# define ST_APPEND ST_APPEND
2056+ ST_IMMUTABLE = 512, /* Immutable file. */
2057+# define ST_IMMUTABLE ST_IMMUTABLE
2058+ ST_NOATIME = 1024, /* Do not update access times. */
2059+# define ST_NOATIME ST_NOATIME
2060+ ST_NODIRATIME = 2048, /* Do not update directory access times. */
2061+# define ST_NODIRATIME ST_NODIRATIME
2062+ ST_RELATIME = 4096 /* Update atime relative to mtime/ctime. */
2063+# define ST_RELATIME ST_RELATIME
2064+#endif /* Use GNU. */
2065+};
2066+
2067+__END_DECLS
2068+
2069+#endif
2070diff -urN -x CVS dietlibc-0.31/include/sys/time.h dietlibc/include/sys/time.h
2071--- dietlibc-0.31/include/sys/time.h 2005-09-21 09:33:08.000000000 +0200
2072+++ dietlibc/include/sys/time.h 2008-09-04 11:25:51.000000000 +0200
2073@@ -68,7 +68,6 @@
2074
2075 #ifdef _BSD_SOURCE
2076 /* another wonderful BSD invention... :( */
2077-/* note how subtly broken it is (doesn't work with <= or >=) */
2078 #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))
2079 #define timerclear(x) ((x)->tv_sec=(x)->tv_usec=0)
2080 #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)
2081diff -urN -x CVS dietlibc-0.31/include/sys/timerfd.h dietlibc/include/sys/timerfd.h
2082--- dietlibc-0.31/include/sys/timerfd.h 1970-01-01 01:00:00.000000000 +0100
2083+++ dietlibc/include/sys/timerfd.h 2008-02-19 01:28:13.000000000 +0100
2084@@ -0,0 +1,16 @@
2085+#ifndef _SYS_TIMERFD_H
2086+#define _SYS_TIMERFD_H
2087+
2088+#include <time.h>
2089+
2090+enum { TFD_TIMER_ABSTIME = 1 };
2091+
2092+__BEGIN_DECLS
2093+
2094+int timerfd_create (clockid_t clock_id, int flags) __THROW;
2095+int timerfd_settime (int ufd, int flags, const struct itimerspec *utmr, struct itimerspec *otmr) __THROW;
2096+int timerfd_gettime (int ufd, struct itimerspec *otmr) __THROW;
2097+
2098+__END_DECLS
2099+
2100+#endif
2101diff -urN -x CVS dietlibc-0.31/include/sys/types.h dietlibc/include/sys/types.h
2102--- dietlibc-0.31/include/sys/types.h 2005-09-21 09:33:08.000000000 +0200
2103+++ dietlibc/include/sys/types.h 2007-10-18 23:08:02.000000000 +0200
2104@@ -12,13 +12,10 @@
2105 clock ticks or CLOCKS_PER_SEC
2106 (see <time.h>). */
2107
2108+typedef uint64_t fsblkcnt_t;
2109+typedef uint64_t fsfilcnt_t;
2110+
2111 /* TODO:
2112- clockid_t
2113- Used for clock ID type in the clock and timer functions.
2114- fsblkcnt_t
2115- Used for file system block counts
2116- fsfilcnt_t
2117- Used for file system file counts
2118 pthread_attr_t
2119 Used to identify a thread attribute object.
2120 pthread_cond_t
2121@@ -39,8 +36,6 @@
2122 Used for read-write lock attributes.
2123 pthread_t
2124 Used to identify a thread.
2125- timer_t
2126- Used for timer ID returned by timer_create().
2127 */
2128
2129 #if defined(__alpha__) || defined(__ia64__) || defined(__sparc64__) || defined(__s390x__)
2130diff -urN -x CVS dietlibc-0.31/include/utmp.h dietlibc/include/utmp.h
2131--- dietlibc-0.31/include/utmp.h 2003-08-19 18:58:18.000000000 +0200
2132+++ dietlibc/include/utmp.h 2008-02-23 01:09:54.000000000 +0100
2133@@ -4,6 +4,7 @@
2134 #include <sys/cdefs.h>
2135 #include <sys/types.h>
2136 #include <time.h>
2137+#include <paths.h>
2138
2139 __BEGIN_DECLS
2140
2141@@ -11,14 +12,6 @@
2142 #define UT_NAMESIZE 32
2143 #define UT_HOSTSIZE 256
2144
2145-#define _PATH_UTMP "/var/run/utmp"
2146-#define _PATH_WTMP "/var/log/wtmp"
2147-#ifdef _BSD_SOURCE
2148-/* die, BSD, die!!! */
2149-#define UTMP_FILE _PATH_UTMP
2150-#define WTMP_FILE _PATH_WTMP
2151-#endif
2152-
2153 /* The structure describing an entry in the database of
2154 previous logins. */
2155 struct lastlog
2156@@ -72,6 +65,7 @@
2157 char __unused[20]; /* Reserved for future use. */
2158 };
2159
2160+#ifndef _UTMPX_H /* untmpx.h hasn't already defined these. */
2161 /* Values for the `ut_type' field of a `struct utmp'. */
2162 #define EMPTY 0 /* No valid user accounting information. */
2163
2164@@ -86,6 +80,7 @@
2165 #define DEAD_PROCESS 8 /* Terminated process. */
2166
2167 #define ACCOUNTING 9
2168+#endif
2169
2170 /* Tell the user that we have a modern system with UT_HOST, UT_PID,
2171 UT_TYPE, UT_ID and UT_TV fields. */
2172diff -urN -x CVS dietlibc-0.31/include/utmpx.h dietlibc/include/utmpx.h
2173--- dietlibc-0.31/include/utmpx.h 1970-01-01 01:00:00.000000000 +0100
2174+++ dietlibc/include/utmpx.h 2008-02-23 01:09:54.000000000 +0100
2175@@ -0,0 +1,95 @@
2176+#ifndef _UTMPX_H
2177+#define _UTMPX_H
2178+
2179+#include <sys/cdefs.h>
2180+#include <sys/types.h>
2181+#include <sys/time.h>
2182+#include <paths.h>
2183+
2184+/* For the getutmp{,x} functions we need the `struct utmp'. */
2185+#ifdef _GNU_SOURCE
2186+struct utmp;
2187+#endif
2188+
2189+#define __UT_LINESIZE 32
2190+#define __UT_NAMESIZE 32
2191+#define __UT_HOSTSIZE 256
2192+
2193+__BEGIN_DECLS
2194+
2195+/* The structure describing the status of a terminated process. This
2196+ type is used in `struct utmpx below. */
2197+struct __exit_status
2198+ {
2199+ short int e_termination; /* Process termination status. */
2200+ short int e_exit; /* Process exit status. */
2201+ };
2202+
2203+/* The structure describing an entry in the user accounting database. */
2204+struct utmpx
2205+{
2206+ short int ut_type; /* Type of login. */
2207+ pid_t ut_pid; /* Process ID of login process. */
2208+ char ut_line[__UT_LINESIZE]; /* Devicename. */
2209+ char ut_id[4]; /* Inittab ID. */
2210+ char ut_user[__UT_NAMESIZE]; /* Username. */
2211+ char ut_host[__UT_HOSTSIZE]; /* Hostname for remote login. */
2212+ struct __exit_status ut_exit; /* Exit status of a process marked
2213+ as DEAD_PROCESS. */
2214+/* The ut_session and ut_tv fields must be the same size when compiled
2215+ 32- and 64-bit. This allows data files and shared memory to be
2216+ shared between 32- and 64-bit applications. */
2217+#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
2218+ int32_t ut_session; /* Session ID, used for windowing. */
2219+ struct
2220+ {
2221+ int32_t tv_sec; /* Seconds. */
2222+ int32_t tv_usec; /* Microseconds. */
2223+ } ut_tv; /* Time entry was made. */
2224+#else
2225+ long int ut_session; /* Session ID, used for windowing. */
2226+ struct timeval ut_tv; /* Time entry was made. */
2227+#endif
2228+ int32_t ut_addr_v6[4]; /* Internet address of remote host. */
2229+ char __unused[20]; /* Reserved for future use. */
2230+};
2231+
2232+#ifndef _UTMP_H /* utmp.h hasn't already defined these. */
2233+/* Values for the `ut_type' field of a `struct utmpx'. */
2234+#define EMPTY 0 /* No valid user accounting information. */
2235+
2236+#define RUN_LVL 1 /* The system's runlevel. */
2237+#define BOOT_TIME 2 /* Time of system boot. */
2238+#define NEW_TIME 3 /* Time after system clock changed. */
2239+#define OLD_TIME 4 /* Time when system clock changed. */
2240+
2241+#define INIT_PROCESS 5 /* Process spawned by the init process. */
2242+#define LOGIN_PROCESS 6 /* Session leader of a logged in user. */
2243+#define USER_PROCESS 7 /* Normal process. */
2244+#define DEAD_PROCESS 8 /* Terminated process. */
2245+
2246+#define ACCOUNTING 9
2247+#endif
2248+
2249+/* Apparently, these functions are all considered possible cancellation
2250+ * points, thus no __THROW */
2251+
2252+struct utmpx *getutxent(void);
2253+struct utmpx *getutxid(struct utmpx *ut);
2254+struct utmpx *getutxline(struct utmpx *ut);
2255+
2256+struct utmpx *pututxline(struct utmpx *ut);
2257+
2258+void setutxent(void);
2259+void endutxent(void);
2260+
2261+#ifdef _GNU_SOURCE
2262+void utmpxname (const char *file);
2263+void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx);
2264+void getutmp (const struct utmpx *utmpx, struct utmp *utmp);
2265+void getutmpx (const struct utmp *utmp, struct utmpx *utmpx);
2266+#endif
2267+
2268+__END_DECLS
2269+
2270+#endif
2271diff -urN -x CVS dietlibc-0.31/include/wchar.h dietlibc/include/wchar.h
2272--- dietlibc-0.31/include/wchar.h 2005-09-21 09:33:08.000000000 +0200
2273+++ dietlibc/include/wchar.h 2007-09-09 04:11:18.000000000 +0200
2274@@ -13,7 +13,7 @@
2275 #else
2276 typedef unsigned int wint_t;
2277 #endif
2278-typedef unsigned long int wctype_t;
2279+typedef int (*wctype_t)(wint_t) __THROW __attribute__((__const__));
2280
2281 #ifndef WCHAR_MIN
2282 #define WCHAR_MIN (-2147483647 - 1)
2283@@ -27,7 +27,7 @@
2284
2285 typedef struct {
2286 int count;
2287- unsigned long sofar;
2288+ wchar_t sofar;
2289 } mbstate_t;
2290
2291 wint_t btowc(int);
2292@@ -94,6 +94,10 @@
2293 int wprintf(const wchar_t *__restrict__, ...);
2294 int wscanf(const wchar_t *__restrict__, ...);
2295
2296+#ifdef _XOPEN_SOURCE
2297+int wcwidth(wchar_t c);
2298+#endif
2299+
2300 __END_DECLS
2301
2302 #endif
2303diff -urN -x CVS dietlibc-0.31/lib/btowc.c dietlibc/lib/btowc.c
2304--- dietlibc-0.31/lib/btowc.c 1970-01-01 01:00:00.000000000 +0100
2305+++ dietlibc/lib/btowc.c 2007-09-09 04:11:18.000000000 +0200
2306@@ -0,0 +1,13 @@
2307+#include <wchar.h>
2308+#include "dietlocale.h"
2309+
2310+wint_t btowc(int c) {
2311+ if (c==EOF) return WEOF;
2312+ switch (lc_ctype) {
2313+ case CT_8BIT:
2314+ return c>0xff?WEOF:1;
2315+ case CT_UTF8:
2316+ return c>0x7f?WEOF:1;
2317+ }
2318+ return WEOF;
2319+}
2320diff -urN -x CVS dietlibc-0.31/lib/fstatvfs.c dietlibc/lib/fstatvfs.c
2321--- dietlibc-0.31/lib/fstatvfs.c 1970-01-01 01:00:00.000000000 +0100
2322+++ dietlibc/lib/fstatvfs.c 2007-10-18 23:08:02.000000000 +0200
2323@@ -0,0 +1,12 @@
2324+#define _FILE_OFFSET_BITS 64
2325+#include <sys/statvfs.h>
2326+#include <sys/statfs.h>
2327+
2328+extern void __statvfs_cvt(struct statfs* from,struct statvfs* to);
2329+
2330+int fstatvfs(int fd, struct statvfs *sv) {
2331+ struct statfs ss;
2332+ if (fstatfs(fd,&ss)==-1) return -1;
2333+ __statvfs_cvt(&ss,sv);
2334+ return 0;
2335+}
2336diff -urN -x CVS dietlibc-0.31/lib/mblen.c dietlibc/lib/mblen.c
2337--- dietlibc-0.31/lib/mblen.c 1970-01-01 01:00:00.000000000 +0100
2338+++ dietlibc/lib/mblen.c 2007-09-20 20:51:18.000000000 +0200
2339@@ -0,0 +1,6 @@
2340+#include <stdlib.h>
2341+#include <wchar.h>
2342+
2343+int mblen(const char* s,size_t n) {
2344+ return mbrlen(s,n,NULL);
2345+}
2346diff -urN -x CVS dietlibc-0.31/lib/mbrlen.c dietlibc/lib/mbrlen.c
2347--- dietlibc-0.31/lib/mbrlen.c 1970-01-01 01:00:00.000000000 +0100
2348+++ dietlibc/lib/mbrlen.c 2008-09-30 23:02:35.000000000 +0200
2349@@ -0,0 +1,9 @@
2350+#include <wchar.h>
2351+#include <errno.h>
2352+
2353+static mbstate_t internal;
2354+
2355+size_t mbrlen(const char *s, size_t n, mbstate_t *ps) {
2356+ static mbstate_t internal;
2357+ return mbrtowc (NULL, s, n, ps ?: &internal);
2358+}
2359diff -urN -x CVS dietlibc-0.31/lib/mbrtowc.c dietlibc/lib/mbrtowc.c
2360--- dietlibc-0.31/lib/mbrtowc.c 1970-01-01 01:00:00.000000000 +0100
2361+++ dietlibc/lib/mbrtowc.c 2008-09-30 23:02:35.000000000 +0200
2362@@ -0,0 +1,67 @@
2363+#include "dietlocale.h"
2364+#include <wchar.h>
2365+#include <errno.h>
2366+
2367+static mbstate_t internal;
2368+
2369+size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) {
2370+ size_t i;
2371+ if (!ps) ps=&internal;
2372+ if (!s) {
2373+ if (ps->count) {
2374+ errno=EILSEQ;
2375+ return (size_t)-1;
2376+ } else {
2377+ ps->count=0;
2378+ ps->sofar=0;
2379+ return 0;
2380+ }
2381+ }
2382+ for (i=0; i<n; ++i) {
2383+ unsigned char c=s[i];
2384+ switch (lc_ctype) {
2385+ case CT_8BIT:
2386+ if (pwc) { *pwc=c; ++pwc; }
2387+ return (!!c);
2388+ case CT_UTF8:
2389+ if (ps->count) {
2390+ /* we have an unfinished multibyte sequence */
2391+ if ((c&0xc0)!=0x80) {
2392+ /* expected a continuation, didn't get one */
2393+kaputt:
2394+ errno=EILSEQ;
2395+ ps->count=0;
2396+ return (size_t)-1;
2397+ }
2398+ ps->sofar=(ps->sofar << 6) + (c & 0x3f);
2399+ if (!--ps->count) {
2400+complete:
2401+ if (pwc) { *pwc=ps->sofar; ++pwc; }
2402+ if (ps->sofar) {
2403+ ps->sofar=0;
2404+ return i+1;
2405+ } else {
2406+ ps->count=0; ps->sofar=0;
2407+ return 0;
2408+ }
2409+ }
2410+ } else {
2411+ if (c&0x80) { /* start of multibyte sequence? */
2412+ unsigned char x=c<<1;
2413+ unsigned char cnt=0;
2414+ while (x&0x80) {
2415+ x<<=1;
2416+ ++cnt;
2417+ }
2418+ if (!cnt || cnt>5) goto kaputt;
2419+ ps->sofar=x>>(cnt+1);
2420+ ps->count=cnt;
2421+ } else {
2422+ ps->sofar=c;
2423+ goto complete;
2424+ }
2425+ }
2426+ }
2427+ }
2428+ return n;
2429+}
2430diff -urN -x CVS dietlibc-0.31/lib/mbsinit.c dietlibc/lib/mbsinit.c
2431--- dietlibc-0.31/lib/mbsinit.c 1970-01-01 01:00:00.000000000 +0100
2432+++ dietlibc/lib/mbsinit.c 2007-09-09 03:37:54.000000000 +0200
2433@@ -0,0 +1,5 @@
2434+#include <wchar.h>
2435+
2436+int mbsinit(const mbstate_t* s) {
2437+ return (!s || s->sofar);
2438+}
2439diff -urN -x CVS dietlibc-0.31/lib/mbsrtowcs.c dietlibc/lib/mbsrtowcs.c
2440--- dietlibc-0.31/lib/mbsrtowcs.c 1970-01-01 01:00:00.000000000 +0100
2441+++ dietlibc/lib/mbsrtowcs.c 2008-09-30 23:13:46.000000000 +0200
2442@@ -0,0 +1,14 @@
2443+#include <wchar.h>
2444+
2445+size_t mbsrtowcs(wchar_t *dest, const char **src, size_t len, mbstate_t *ps) {
2446+ const char* orig=*src;
2447+ size_t i;
2448+ if (!dest) len=(size_t)-1;
2449+ for (i=0; i<len; ++i) {
2450+ size_t n=mbrtowc(dest?dest+i:0,*src,len,ps);
2451+ if (n==(size_t)-1) return -1;
2452+ if (!n) break;
2453+ *src+=n;
2454+ }
2455+ return i;
2456+}
2457diff -urN -x CVS dietlibc-0.31/lib/mbstowcs.c dietlibc/lib/mbstowcs.c
2458--- dietlibc-0.31/lib/mbstowcs.c 1970-01-01 01:00:00.000000000 +0100
2459+++ dietlibc/lib/mbstowcs.c 2007-09-09 04:11:18.000000000 +0200
2460@@ -0,0 +1,7 @@
2461+#include <stdlib.h>
2462+#include <wchar.h>
2463+
2464+size_t mbstowcs(wchar_t *dest, const char *src, size_t n) {
2465+ const char** s=&src;
2466+ return mbsrtowcs(dest,s,n,NULL);
2467+}
2468diff -urN -x CVS dietlibc-0.31/lib/mbtowc.c dietlibc/lib/mbtowc.c
2469--- dietlibc-0.31/lib/mbtowc.c 1970-01-01 01:00:00.000000000 +0100
2470+++ dietlibc/lib/mbtowc.c 2007-09-09 03:37:54.000000000 +0200
2471@@ -0,0 +1,6 @@
2472+#include <stdlib.h>
2473+#include <wchar.h>
2474+
2475+int mbtowc(wchar_t *pwc, const char *s, size_t n) {
2476+ return mbrtowc(pwc,s,n,NULL);
2477+}
2478diff -urN -x CVS dietlibc-0.31/lib/memcpy.c dietlibc/lib/memcpy.c
2479--- dietlibc-0.31/lib/memcpy.c 2003-12-21 13:06:36.000000000 +0100
2480+++ dietlibc/lib/memcpy.c 2008-02-23 01:02:19.000000000 +0100
2481@@ -28,6 +28,8 @@
2482 *c1++ = *c2++;
2483 if (n == (size_t) - 1)
2484 return (res);
2485+ dst = c1;
2486+ src = c2;
2487 }
2488
2489 lx1 = (unsigned long *) dst;
2490diff -urN -x CVS dietlibc-0.31/lib/signalfd.c dietlibc/lib/signalfd.c
2491--- dietlibc-0.31/lib/signalfd.c 1970-01-01 01:00:00.000000000 +0100
2492+++ dietlibc/lib/signalfd.c 2008-05-09 06:36:56.000000000 +0200
2493@@ -0,0 +1,13 @@
2494+#include <signal.h>
2495+#include <errno.h>
2496+#include <sys/signalfd.h>
2497+
2498+extern int __signalfd(int fd,const sigset_t* mask,size_t nsig);
2499+
2500+int signalfd(int fd,const sigset_t* mask,int flags) {
2501+ if (flags) { /* bizarre glibc bullshit */
2502+ errno=EINVAL;
2503+ return -1;
2504+ }
2505+ return __signalfd(fd,mask,_NSIG/8);
2506+}
2507diff -urN -x CVS dietlibc-0.31/lib/stackgap.c dietlibc/lib/stackgap.c
2508--- dietlibc-0.31/lib/stackgap.c 2007-08-24 23:19:33.000000000 +0200
2509+++ dietlibc/lib/stackgap.c 2009-03-12 16:36:51.000000000 +0100
2510@@ -3,6 +3,8 @@
2511 #include <alloca.h>
2512 #include <sys/time.h>
2513 #include <sys/tls.h>
2514+#include <endian.h>
2515+#include <elf.h>
2516 #include "dietfeatures.h"
2517
2518 extern int main(int argc,char* argv[],char* envp[]);
2519@@ -11,25 +13,65 @@
2520 extern unsigned long __guard;
2521 #endif
2522
2523-#if defined(WANT_SSP) || defined(WANT_THREAD_SAFE)
2524+#ifdef WANT_TLS
2525+/* __tdatasize is the size of the initialized thread local data section
2526+ * __tmemsize is the size of the complete thread local data section
2527+ * (including uninitialized data)
2528+ * __tdataptr is a pointer to the initialized thread local data section
2529+ * __tmemsize is already rounded up to meet alignment
2530+ * the final memory layout is [tdata] [tbss (zero)] [tcb] */
2531+size_t __tdatasize, __tmemsize;
2532+void* __tdataptr;
2533+
2534+static void findtlsdata(long* auxvec) {
2535+#if (__WORDSIZE == 64)
2536+ Elf64_Phdr* x=0;
2537+#else
2538+ Elf32_Phdr* x=0;
2539+#endif
2540+ size_t i,n;
2541+ while (*auxvec) {
2542+ if (auxvec[0]==3) {
2543+ x=(void*)auxvec[1];
2544+ break;
2545+ }
2546+ auxvec+=2;
2547+ } /* if we don't find the entry, the kernel let us down */
2548+ if (!x) return; /* a kernel this old does not support thread local storage anyway */
2549+ if (x->p_type!=PT_PHDR) return; /* should start with PT_PHDR */
2550+ /* if it doesn't, assume there is no thread local storage */
2551+ n=x->p_memsz/sizeof(*x);
2552+ for (i=1; i<n; ++i)
2553+ if (x[i].p_type==PT_TLS) {
2554+ __tdataptr=(void*)x[i].p_vaddr;
2555+ __tdatasize=x[i].p_filesz;
2556+ __tmemsize=x[i].p_memsz;
2557+ break;
2558+ }
2559+ /* if there is no PT_TLS section, there is no thread-local data, and
2560+ * we just leave the __t* variables zero */
2561+}
2562+#endif
2563+
2564+#if defined(WANT_SSP) || defined(WANT_TLS)
2565 static tcbhead_t mainthread;
2566
2567-static void setup_tls(void) {
2568- mainthread.tcb=&mainthread;
2569- mainthread.self=&mainthread;
2570+static void setup_tls(tcbhead_t* mainthread) {
2571+ mainthread->tcb=&mainthread;
2572+ mainthread->self=&mainthread;
2573 #if defined(WANT_SSP)
2574- mainthread.stack_guard=__guard;
2575+ mainthread->stack_guard=__guard;
2576 #endif
2577
2578 #if defined(__x86_64__)
2579
2580- arch_prctl(ARCH_SET_FS, &mainthread);
2581+ arch_prctl(ARCH_SET_FS, mainthread);
2582
2583 #elif defined(__i386__)
2584
2585 static unsigned int sd[4];
2586 sd[0]=-1;
2587- sd[1]=(unsigned long int)&mainthread;
2588+ sd[1]=(unsigned long int)mainthread;
2589 sd[2]=0xfffff; /* 4 GB limit */
2590 sd[3]=0x51; /* bitfield, see struct user_desc in asm-i386/ldt.h */
2591 if (set_thread_area((struct user_desc*)(void*)&sd)==0) {
2592@@ -37,46 +79,66 @@
2593 }
2594
2595 #elif defined(__alpha__) || defined(__s390__)
2596- __builtin_set_thread_pointer(&mainthread);
2597+ __builtin_set_thread_pointer(mainthread);
2598 #elif defined(__ia64__) || defined(__powerpc__)
2599 register tcbhead_t* __thread_self __asm__("r13");
2600- __thread_self=&mainthread;
2601+ __thread_self=mainthread;
2602 #elif defined(__sparc__)
2603 register tcbhead_t* __thread_self __asm("%g7");
2604- __thread_self=&mainthread;
2605+ __thread_self=mainthread;
2606 #else
2607 #warning "no idea how to enable TLS on this platform, edit lib/stackgap.c"
2608 #endif
2609 }
2610 #endif
2611
2612+static void* find_rand(long* x) {
2613+ while (*x) {
2614+ if (*x==25)
2615+ return (void*)x[1];
2616+ x+=2;
2617+ }
2618+ return NULL;
2619+}
2620+
2621 int stackgap(int argc,char* argv[],char* envp[]);
2622 int stackgap(int argc,char* argv[],char* envp[]) {
2623-#ifdef WANT_SSP_XOR
2624- struct timeval tv;
2625-#endif
2626-#if defined(WANT_STACKGAP) || defined(WANT_SSP_URANDOM)
2627- int fd=open("/dev/urandom",O_RDONLY);
2628+#if defined(WANT_STACKGAP) || defined(WANT_SSP) || defined(WANT_TLS)
2629+ long* auxvec=(long*)envp;
2630+ char* rand;
2631+ char* tlsdata;
2632+ while (*auxvec) ++auxvec; ++auxvec; /* skip envp to get to auxvec */
2633 #ifdef WANT_STACKGAP
2634 unsigned short s;
2635+#endif
2636+#if defined(WANT_STACKGAP) || defined(WANT_SSP)
2637 volatile char* gap;
2638- read(fd,&s,2);
2639+ rand=find_rand(auxvec);
2640+ if (!rand) {
2641+ char myrand[10];
2642+ int fd=open("/dev/urandom",O_RDONLY);
2643+ read(fd,myrand,10);
2644+ close(fd);
2645+ rand=myrand;
2646+ }
2647+#endif
2648+#ifdef WANT_STACKGAP
2649+ s=*(unsigned short*)(rand+8);
2650 #endif
2651 #ifdef WANT_SSP
2652- read(fd,&__guard,sizeof(__guard));
2653+ __guard=*(unsigned long*)rand;
2654 #endif
2655- close(fd);
2656 #ifdef WANT_STACKGAP
2657 gap=alloca(s);
2658 #endif
2659 #endif
2660-#ifdef WANT_SSP_XOR
2661- gettimeofday (&tv, NULL);
2662- __guard ^= tv.tv_usec ^ tv.tv_sec ^ getpid();
2663-#endif
2664
2665-#if defined(WANT_SSP) || defined(WANT_THREAD_SAFE)
2666- setup_tls();
2667+#if defined(WANT_SSP) || defined(WANT_TLS)
2668+ findtlsdata(auxvec);
2669+ tlsdata=alloca(__tmemsize+sizeof(tcbhead_t));
2670+ memcpy(tlsdata,__tdataptr,__tdatasize);
2671+ memset(tlsdata+__tdatasize,0,__tmemsize-__tdatasize);
2672+ setup_tls((tcbhead_t*)(tlsdata+__tmemsize));
2673 #endif
2674 return main(argc,argv,envp);
2675 }
2676diff -urN -x CVS dietlibc-0.31/lib/statvfs.c dietlibc/lib/statvfs.c
2677--- dietlibc-0.31/lib/statvfs.c 1970-01-01 01:00:00.000000000 +0100
2678+++ dietlibc/lib/statvfs.c 2008-05-09 06:36:56.000000000 +0200
2679@@ -0,0 +1,13 @@
2680+#define _FILE_OFFSET_BITS 64
2681+#include <sys/statvfs.h>
2682+#include <sys/statfs.h>
2683+
2684+extern void __statvfs_cvt(struct statfs* from,struct statvfs* to);
2685+
2686+int statvfs(const char *path, struct statvfs *sv) {
2687+ struct statfs ss;
2688+ if (statfs(path,&ss)==-1) return -1;
2689+ __statvfs_cvt(&ss,sv);
2690+ return 0;
2691+}
2692+
2693diff -urN -x CVS dietlibc-0.31/lib/statvfs_cvt.c dietlibc/lib/statvfs_cvt.c
2694--- dietlibc-0.31/lib/statvfs_cvt.c 1970-01-01 01:00:00.000000000 +0100
2695+++ dietlibc/lib/statvfs_cvt.c 2007-10-18 23:08:02.000000000 +0200
2696@@ -0,0 +1,19 @@
2697+#define _FILE_OFFSET_BITS 64
2698+#include <sys/statvfs.h>
2699+#include <sys/statfs.h>
2700+
2701+void __statvfs_cvt(struct statfs* from,struct statvfs* to);
2702+
2703+void __statvfs_cvt(struct statfs* from,struct statvfs* to) {
2704+ to->f_bsize=from->f_bsize;
2705+ to->f_frsize=from->f_frsize;
2706+ to->f_blocks=from->f_blocks;
2707+ to->f_bfree=from->f_bfree;
2708+ to->f_bavail=from->f_bavail;
2709+ to->f_files=from->f_files;
2710+ to->f_ffree=from->f_ffree;
2711+ to->f_favail=from->f_ffree;
2712+ to->f_fsid=from->f_fsid.__val[0];
2713+ to->f_flag=0;
2714+ to->f_namemax=from->f_namelen;
2715+}
2716diff -urN -x CVS dietlibc-0.31/lib/strcmp.c dietlibc/lib/strcmp.c
2717--- dietlibc-0.31/lib/strcmp.c 2003-12-21 13:06:36.000000000 +0100
2718+++ dietlibc/lib/strcmp.c 2008-02-19 01:28:13.000000000 +0100
2719@@ -31,16 +31,16 @@
2720 while (1) {
2721 l1 = *lx1++;
2722 l2 = *lx2++;
2723- if ((((l1 - MKW(0x1)) & ~l1) & MKW(0x80)) ||
2724- ((((l2 - MKW(0x1)) & ~l2) & MKW(0x80))) || l1 != l2) {
2725+ if ((((l1 - MKW(0x1ul)) & ~l1) & MKW(0x80ul)) ||
2726+ ((((l2 - MKW(0x1ul)) & ~l2) & MKW(0x80ul))) || l1 != l2) {
2727 unsigned char c1, c2;
2728 while (1) {
2729- c1 = l1 & 0xff;
2730- c2 = l2 & 0xff;
2731+ c1 = GFC(l1);
2732+ c2 = GFC(l2);
2733 if (!c1 || c1 != c2)
2734 return (c1 - c2);
2735- l1 >>= 8;
2736- l2 >>= 8;
2737+ INCSTR(l1);
2738+ INCSTR(l2);
2739 }
2740 }
2741 }
2742diff -urN -x CVS dietlibc-0.31/lib/strcpy.c dietlibc/lib/strcpy.c
2743--- dietlibc-0.31/lib/strcpy.c 2003-12-21 13:06:36.000000000 +0100
2744+++ dietlibc/lib/strcpy.c 2008-02-19 01:28:13.000000000 +0100
2745@@ -25,9 +25,8 @@
2746
2747 while (1) {
2748 l = *(const unsigned long *) s2;
2749- if (((l - MKW(0x1)) & ~l) & MKW(0x80)) {
2750- unsigned char c;
2751- while ((*s1++ = (l & 0xff))) l>>=8;
2752+ if (((l - MKW(0x1ul)) & ~l) & MKW(0x80ul)) {
2753+ while ((*s1++ = GFC(l))) INCSTR(l);
2754 return (res);
2755 }
2756 *(unsigned long *) s1 = l;
2757diff -urN -x CVS dietlibc-0.31/lib/strcspn.c dietlibc/lib/strcspn.c
2758--- dietlibc-0.31/lib/strcspn.c 2001-01-09 18:57:43.000000000 +0100
2759+++ dietlibc/lib/strcspn.c 2008-02-19 01:28:13.000000000 +0100
2760@@ -4,14 +4,12 @@
2761 size_t strcspn(const char *s, const char *reject)
2762 {
2763 size_t l=0;
2764- int a=1,i,al=strlen(reject);
2765+ int i,al=strlen(reject);
2766
2767- while((a)&&(*s))
2768- {
2769- for(i=0;(a)&&(i<al);i++)
2770- if (*s==reject[i]) a=0;
2771- if (a) l++;
2772- s++;
2773+ for (; *s; ++s) {
2774+ for (i=0; reject[i]; ++i)
2775+ if (*s==reject[i]) return l;
2776+ ++l;
2777 }
2778 return l;
2779 }
2780diff -urN -x CVS dietlibc-0.31/lib/strdup.c dietlibc/lib/strdup.c
2781--- dietlibc-0.31/lib/strdup.c 2001-01-09 18:57:43.000000000 +0100
2782+++ dietlibc/lib/strdup.c 2007-11-17 15:29:53.000000000 +0100
2783@@ -2,8 +2,8 @@
2784 #include <stdlib.h>
2785
2786 char *strdup(const char *s) {
2787- char *tmp=(char *)malloc(strlen(s)+1);
2788+ size_t l=strlen(s)+1;
2789+ char *tmp=(char *)malloc(l);
2790 if (!tmp) return 0;
2791- strcpy(tmp,s);
2792- return tmp;
2793+ return memcpy(tmp,s,l);
2794 }
2795diff -urN -x CVS dietlibc-0.31/lib/strlen.c dietlibc/lib/strlen.c
2796--- dietlibc-0.31/lib/strlen.c 2003-08-19 21:34:18.000000000 +0200
2797+++ dietlibc/lib/strlen.c 2008-02-19 01:28:13.000000000 +0100
2798@@ -1,6 +1,7 @@
2799 #include <endian.h>
2800 #include "dietfeatures.h"
2801 #include <string.h>
2802+#include <stdint.h>
2803
2804 #ifdef WANT_SMALL_STRING_ROUTINES
2805 size_t strlen(const char *s) {
2806@@ -10,38 +11,88 @@
2807 return i;
2808 }
2809 #else
2810-static const unsigned long magic = 0x01010101;
2811+
2812+#if __WORDSIZE == 64
2813+typedef uint64_t word_t;
2814+#elif __WORDSIZE == 32
2815+typedef uint32_t word_t;
2816+#else
2817+#error unsupported __WORDSIZE
2818+#endif
2819+
2820+static word_t const magic = (word_t)(0x0101010101010101ull);
2821
2822 size_t strlen(const char *s)
2823 {
2824 const char *t = s;
2825- unsigned long word;
2826+ word_t word;
2827+ word_t mask;
2828
2829- if (!s) return 0;
2830+ if (__unlikely(!s)) return 0;
2831
2832 /* Byte compare up until word boundary */
2833- for (; ((unsigned long) t & 3); t++)
2834+ for (; ((unsigned long) t & (sizeof(magic)-1)); t++)
2835 if (!*t) return t - s;
2836
2837 /* Word compare */
2838 do {
2839- word = *((unsigned long *) t); t += 4;
2840+ word = *((word_t const *) t); t += sizeof word;
2841 word = (word - magic) &~ word;
2842 word &= (magic << 7);
2843 } while (__likely(word == 0));
2844
2845-#if BYTE_ORDER == LITTLE_ENDIAN
2846- /* word & 0x80808080 == word */
2847- word = (word - 1) & (magic << 10);
2848- word += (word << 8) + (word << 16);
2849- t += word >> 26;
2850+#if __BYTE_ORDER == __LITTLE_ENDIAN
2851+ (void)mask;
2852+ switch (sizeof(word)) {
2853+ case 8:
2854+ /* word & 0x8080808080808080 == word */
2855+ word = (word - 1) & (magic << 8);
2856+ word += (word << 32);
2857+ word += (word << 16);
2858+ word += (word << 8);
2859+ t += word >> 56;
2860+ break;
2861+
2862+ case 4:
2863+ /* word & 0x80808080 == word */
2864+ word = (word - 1) & (magic << 10);
2865+ word += (word << 8) + (word << 16);
2866+ t += word >> 26;
2867+ break;
2868+
2869+ default: { char exc[sizeof(word)==8]; (void)exc; }
2870+ }
2871 #else
2872- if ((word & 0x80800000) == 0) {
2873- word <<= 16;
2874- t += 2;
2875+ mask = (magic << 7);
2876+
2877+ switch (sizeof(word)) {
2878+ case 8:
2879+ mask <<= 4*8;
2880+ if ((word & mask) == 0) {
2881+ t += 4;
2882+ word <<= 4*8;
2883+ }
2884+ /* fallthrough */
2885+
2886+ case 4:
2887+ mask <<= 2*8;
2888+ if ((word & mask) == 0) {
2889+ t += 2;
2890+ word <<= 2*8;
2891+ }
2892+ /* fallthrough */
2893+
2894+ case 2:
2895+ mask <<= 1*8;
2896+ if ((word & mask) == 0) {
2897+ t += 1;
2898+ word <<= 1*8;
2899+ }
2900+ break;
2901+
2902+ default: { char exc[sizeof(word)==8]; (void)exc; }
2903 }
2904- if ((word & 0x80000000) == 0) t += 1;
2905 #endif
2906- return ((const char *) t) - 4 - s;
2907+ return t - sizeof(word) - s;
2908 }
2909 #endif
2910diff -urN -x CVS dietlibc-0.31/lib/strpbrk.c dietlibc/lib/strpbrk.c
2911--- dietlibc-0.31/lib/strpbrk.c 2001-01-09 18:57:43.000000000 +0100
2912+++ dietlibc/lib/strpbrk.c 2008-02-19 01:28:13.000000000 +0100
2913@@ -2,9 +2,9 @@
2914 #include <string.h>
2915
2916 char *strpbrk(const char *s, const char *accept) {
2917- register int i,l=strlen(accept);
2918+ register unsigned int i;
2919 for (; *s; s++)
2920- for (i=0; i<l; i++)
2921+ for (i=0; accept[i]; i++)
2922 if (*s == accept[i])
2923 return (char*)s;
2924 return 0;
2925diff -urN -x CVS dietlibc-0.31/lib/strspn.c dietlibc/lib/strspn.c
2926--- dietlibc-0.31/lib/strspn.c 2001-01-09 18:57:43.000000000 +0100
2927+++ dietlibc/lib/strspn.c 2008-02-19 01:28:13.000000000 +0100
2928@@ -3,15 +3,17 @@
2929
2930 size_t strspn(const char *s, const char *accept)
2931 {
2932- size_t l=0;
2933- int a=1,i,al=strlen(accept);
2934+ size_t l = 0;
2935+ const char *a;
2936
2937- while((a)&&(*s))
2938- {
2939- for(a=i=0;(!a)&&(i<al);i++)
2940- if (*s==accept[i]) a=1;
2941- if (a) l++;
2942- s++;
2943+ for (; *s; s++) {
2944+ for (a = accept; *a && *s != *a; a++);
2945+
2946+ if (!*a)
2947+ break;
2948+ else
2949+ l++;
2950 }
2951+
2952 return l;
2953 }
2954diff -urN -x CVS dietlibc-0.31/lib/strstr.c dietlibc/lib/strstr.c
2955--- dietlibc-0.31/lib/strstr.c 2003-08-19 21:34:18.000000000 +0200
2956+++ dietlibc/lib/strstr.c 2008-02-19 01:28:13.000000000 +0100
2957@@ -4,7 +4,7 @@
2958 char *strstr(const char *haystack, const char *needle) {
2959 size_t nl=strlen(needle);
2960 size_t hl=strlen(haystack);
2961- int i;
2962+ size_t i;
2963 if (!nl) goto found;
2964 if (nl>hl) return 0;
2965 for (i=hl-nl+1; __likely(i); --i) {
2966diff -urN -x CVS dietlibc-0.31/lib/timerfd_create.c dietlibc/lib/timerfd_create.c
2967--- dietlibc-0.31/lib/timerfd_create.c 1970-01-01 01:00:00.000000000 +0100
2968+++ dietlibc/lib/timerfd_create.c 2008-02-19 01:28:13.000000000 +0100
2969@@ -0,0 +1,7 @@
2970+#include <sys/timerfd.h>
2971+
2972+extern int __timerfd(int ufd, int clockid, int flags, const struct itimerspec *utmr);
2973+
2974+int timerfd_create (clockid_t __clock_id, int __flags) {
2975+ return __timerfd(-1,__clock_id,__flags,0);
2976+}
2977diff -urN -x CVS dietlibc-0.31/lib/__v_printf.c dietlibc/lib/__v_printf.c
2978--- dietlibc-0.31/lib/__v_printf.c 2007-05-17 07:00:42.000000000 +0200
2979+++ dietlibc/lib/__v_printf.c 2008-02-19 01:28:13.000000000 +0100
2980@@ -21,7 +21,8 @@
2981 static const char pad_line[2][16]= { " ", "0000000000000000", };
2982 static int write_pad(unsigned int* dlen,struct arg_printf* fn, unsigned int len, int padwith) {
2983 int nr=0;
2984- if ((int)len<0 || *dlen+len<len) return -1;
2985+ if ((int)len<=0) return 0;
2986+ if(*dlen+len<len) return -1;
2987 for (;len>15;len-=16,nr+=16) {
2988 A_WRITE(fn,pad_line[(padwith=='0')?1:0],16);
2989 }
2990@@ -80,8 +81,6 @@
2991 /* FLAGS */
2992 case '#':
2993 flag_hash=-1;
2994- case 'z':
2995- goto inn_printf;
2996
2997 case 'h':
2998 --flag_long;
2999@@ -95,6 +94,7 @@
3000 #if __WORDSIZE == 64
3001 case 'j':
3002 #endif
3003+ case 'z':
3004 case 'l':
3005 ++flag_long;
3006 goto inn_printf;
3007@@ -129,10 +129,18 @@
3008 goto inn_printf;
3009
3010 case '*':
3011- width=va_arg(arg_ptr,int);
3012- if (width>MAX_WIDTH) return -1; /* width is unsiged, so this catches <0, too */
3013- goto inn_printf;
3014-
3015+ {
3016+ /* A negative field width is taken as a '-' flag followed by
3017+ * a positive field width
3018+ **/
3019+ int tmp;
3020+ if ((tmp=va_arg(arg_ptr,int))<0) {
3021+ flag_left=1;
3022+ tmp=-tmp;
3023+ }
3024+ if ((width=(unsigned long)tmp)>MAX_WIDTH) return -1;
3025+ goto inn_printf;
3026+ }
3027 case '.':
3028 flag_dot=1;
3029 if (*format=='*') {
3030@@ -214,7 +222,7 @@
3031
3032 if (flag_dot && width==0) width=preci;
3033 if (!flag_dot) preci=sz;
3034- if (!flag_left) { /* do left-side padding */
3035+ if (!flag_left && padwith==' ') { /* do left-side padding with spaces */
3036 if (write_pad(&len,fn,width-preci,padwith))
3037 return -1;
3038 }
3039@@ -222,6 +230,10 @@
3040 B_WRITE(fn,sign,todo);
3041 len+=todo;
3042 }
3043+ if (!flag_left && padwith!=' ') { /* do left-side padding with '0' */
3044+ if (write_pad(&len,fn,width-preci,padwith))
3045+ return -1;
3046+ }
3047 /* do preci padding */
3048 if (write_pad(&len,fn,preci-sz,precpadwith))
3049 return -1;
3050@@ -377,7 +389,7 @@
3051
3052 sz=strlen(s);
3053 if (width<sz) width=sz;
3054- padwith='0';
3055+ precpadwith='0';
3056 flag_dot=0;
3057 flag_hash=0;
3058 goto print_out;
3059diff -urN -x CVS dietlibc-0.31/lib/__v_scanf.c dietlibc/lib/__v_scanf.c
3060--- dietlibc-0.31/lib/__v_scanf.c 2005-04-10 15:59:32.000000000 +0200
3061+++ dietlibc/lib/__v_scanf.c 2008-07-07 14:52:55.000000000 +0200
3062@@ -280,6 +280,7 @@
3063 }
3064 }
3065 exp_out:
3066+ if (neg) d = -d;
3067 if (!flag_discard) {
3068 if (flag_long) {
3069 pd=(double *)va_arg(arg_ptr,double*);
3070diff -urN -x CVS dietlibc-0.31/lib/wcrtomb.c dietlibc/lib/wcrtomb.c
3071--- dietlibc-0.31/lib/wcrtomb.c 1970-01-01 01:00:00.000000000 +0100
3072+++ dietlibc/lib/wcrtomb.c 2007-09-09 03:37:54.000000000 +0200
3073@@ -0,0 +1,32 @@
3074+#include <wchar.h>
3075+#include "dietlocale.h"
3076+
3077+static mbstate_t internal;
3078+
3079+size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) {
3080+ if (!ps) ps=&internal;
3081+ switch (lc_ctype) {
3082+ case CT_8BIT:
3083+ if (!s) return 0;
3084+ *s=wc;
3085+ return 1;
3086+ case CT_UTF8:
3087+ if (!s) return (wc>=0x80);
3088+ {
3089+ unsigned int bits,j,k;
3090+ if (wc>=0x04000000) { bits=30; *s=0xFC; j=6; } else
3091+ if (wc>=0x00200000) { bits=24; *s=0xF8; j=5; } else
3092+ if (wc>=0x00010000) { bits=18; *s=0xF0; j=4; } else
3093+ if (wc>=0x00000800) { bits=12; *s=0xE0; j=3; } else
3094+ if (wc>=0x00000080) { bits=6; *s=0xC0; j=2; } else
3095+ { *s=wc; return 1; }
3096+ *s |= (unsigned char)(wc>>bits);
3097+ for (k=1; k<j; ++k) {
3098+ bits-=6;
3099+ s[k]=0x80+((wc>>bits)&0x3f);
3100+ }
3101+ return k;
3102+ }
3103+ }
3104+ return 0;
3105+}
3106diff -urN -x CVS dietlibc-0.31/lib/wcsncat.c dietlibc/lib/wcsncat.c
3107--- dietlibc-0.31/lib/wcsncat.c 1970-01-01 01:00:00.000000000 +0100
3108+++ dietlibc/lib/wcsncat.c 2007-10-04 15:58:29.000000000 +0200
3109@@ -0,0 +1,10 @@
3110+#include <wchar.h>
3111+
3112+wchar_t* wcsncat(wchar_t *__restrict__ dest, const wchar_t *__restrict__ src,size_t n) {
3113+ wchar_t* orig=dest;
3114+ size_t i;
3115+ while (*dest) ++dest;
3116+ for (i=0; i<n && src[i]; ++i) dest[i]=src[i];
3117+ dest[i]=0;
3118+ return orig;
3119+}
3120diff -urN -x CVS dietlibc-0.31/lib/wcsncpy.c dietlibc/lib/wcsncpy.c
3121--- dietlibc-0.31/lib/wcsncpy.c 1970-01-01 01:00:00.000000000 +0100
3122+++ dietlibc/lib/wcsncpy.c 2007-10-04 15:58:29.000000000 +0200
3123@@ -0,0 +1,8 @@
3124+#include <wchar.h>
3125+
3126+wchar_t* wcsncpy(wchar_t *__restrict__ dest, const wchar_t *__restrict__ src,size_t n) {
3127+ wchar_t* orig=dest;
3128+ for (; dest<orig+n && (*dest=*src); ++src,++dest) ;
3129+ for (; dest<orig+n; ++dest) *dest=0;
3130+ return orig;
3131+}
3132diff -urN -x CVS dietlibc-0.31/lib/wcsstr.c dietlibc/lib/wcsstr.c
3133--- dietlibc-0.31/lib/wcsstr.c 1970-01-01 01:00:00.000000000 +0100
3134+++ dietlibc/lib/wcsstr.c 2007-10-08 16:23:59.000000000 +0200
3135@@ -0,0 +1,11 @@
3136+#include <wchar.h>
3137+
3138+wchar_t *wcsstr(const wchar_t *haystack, const wchar_t *needle) {
3139+ size_t i,j;
3140+ for (i=0; haystack[i]; ++i) {
3141+ for (j=0; haystack[i+j]==needle[j]; ++j) ;
3142+ if (!needle[j]) return (wchar_t*)haystack+i;
3143+ }
3144+ return 0;
3145+}
3146+
3147diff -urN -x CVS dietlibc-0.31/lib/wctomb.c dietlibc/lib/wctomb.c
3148--- dietlibc-0.31/lib/wctomb.c 1970-01-01 01:00:00.000000000 +0100
3149+++ dietlibc/lib/wctomb.c 2007-09-09 03:37:54.000000000 +0200
3150@@ -0,0 +1,6 @@
3151+#include <stdlib.h>
3152+#include <wchar.h>
3153+
3154+int wctomb(char *pwc, wchar_t s) {
3155+ return wcrtomb(pwc,s,NULL);
3156+}
3157diff -urN -x CVS dietlibc-0.31/lib/wcwidth.c dietlibc/lib/wcwidth.c
3158--- dietlibc-0.31/lib/wcwidth.c 1970-01-01 01:00:00.000000000 +0100
3159+++ dietlibc/lib/wcwidth.c 2007-09-09 04:11:18.000000000 +0200
3160@@ -0,0 +1,8 @@
3161+#define _XOPEN_SOURCE
3162+#include <wchar.h>
3163+
3164+int wcwidth(wchar_t c) {
3165+ if (!c) return 0;
3166+ if (c<' ') return -1;
3167+ return 1;
3168+}
3169diff -urN -x CVS dietlibc-0.31/libcompat/getutmp.c dietlibc/libcompat/getutmp.c
3170--- dietlibc-0.31/libcompat/getutmp.c 1970-01-01 01:00:00.000000000 +0100
3171+++ dietlibc/libcompat/getutmp.c 2008-02-23 01:09:54.000000000 +0100
3172@@ -0,0 +1,25 @@
3173+#include "dietfeatures.h"
3174+#include <string.h>
3175+#include <utmp.h>
3176+#include "dietwarning.h"
3177+
3178+#define _GNU_SOURCE
3179+#include <utmpx.h>
3180+
3181+void
3182+getutmp (const struct utmpx *utmpx, struct utmp *utmp)
3183+{
3184+ memcpy (utmp, utmpx, sizeof(struct utmp));
3185+ return;
3186+}
3187+
3188+void
3189+getutmpx (const struct utmp *utmp, struct utmpx *utmpx)
3190+{
3191+ memcpy (utmpx, utmp, sizeof(struct utmpx));
3192+ return;
3193+}
3194+
3195+link_warning("getutmp","getutmp(): dietlibc utmp and utmpx structures are identical. If you actually require conversion, this it NOT the place to find it!");
3196+
3197+link_warning("getutmpx","getutmpx(): dietlibc utmp and utmpx structures are identical. If you actually require conversion, this it NOT the place to find it!");
3198diff -urN -x CVS dietlibc-0.31/libcompat/utmpxname.c dietlibc/libcompat/utmpxname.c
3199--- dietlibc-0.31/libcompat/utmpxname.c 1970-01-01 01:00:00.000000000 +0100
3200+++ dietlibc/libcompat/utmpxname.c 2008-02-23 01:09:54.000000000 +0100
3201@@ -0,0 +1,10 @@
3202+#define _GNU_SOURCE
3203+#include <utmpx.h>
3204+
3205+void __utmpxname (const char *file);
3206+
3207+void
3208+utmpxname (const char *file) {
3209+ __utmpxname (file);
3210+ return;
3211+}
3212diff -urN -x CVS dietlibc-0.31/libcompat/wtxent.c dietlibc/libcompat/wtxent.c
3213--- dietlibc-0.31/libcompat/wtxent.c 1970-01-01 01:00:00.000000000 +0100
3214+++ dietlibc/libcompat/wtxent.c 2008-02-23 01:09:54.000000000 +0100
3215@@ -0,0 +1,14 @@
3216+#include <unistd.h>
3217+#include <fcntl.h>
3218+#include <string.h>
3219+
3220+#define _GNU_SOURCE
3221+#include <utmpx.h>
3222+
3223+void updwtmpx(const char *wtmpx_file, const struct utmpx *ut) {
3224+ int fd = open(wtmpx_file, O_WRONLY|O_APPEND);
3225+ if (fd<0) return;
3226+ fcntl (fd, F_SETFD, FD_CLOEXEC);
3227+ write(fd, ut, sizeof(struct utmpx));
3228+ close(fd);
3229+}
3230diff -urN -x CVS dietlibc-0.31/libcruft/dn_expand.c dietlibc/libcruft/dn_expand.c
3231--- dietlibc-0.31/libcruft/dn_expand.c 2002-07-11 00:20:34.000000000 +0200
3232+++ dietlibc/libcruft/dn_expand.c 2008-09-30 23:02:35.000000000 +0200
3233@@ -2,10 +2,10 @@
3234 #include <arpa/nameser.h>
3235 #include <resolv.h>
3236
3237-extern int __dns_decodename(unsigned char *packet,unsigned int ofs,unsigned char *dest,
3238- unsigned int maxlen,unsigned char* behindpacket);
3239+extern int __dns_decodename(const unsigned char *packet,unsigned int ofs,unsigned char *dest,
3240+ unsigned int maxlen,const unsigned char* behindpacket);
3241
3242-int dn_expand(unsigned char *msg, unsigned char *eomorig, unsigned char *comp_dn, unsigned char *exp_dn, int length) {
3243+int dn_expand(const unsigned char *msg, const unsigned char *eomorig, const unsigned char *comp_dn, unsigned char *exp_dn, int length) {
3244 return __dns_decodename(msg,comp_dn-msg,exp_dn,length,eomorig)-(comp_dn-msg);
3245 }
3246
3247diff -urN -x CVS dietlibc-0.31/libcruft/dnscruft.c dietlibc/libcruft/dnscruft.c
3248--- dietlibc-0.31/libcruft/dnscruft.c 2006-10-13 20:19:12.000000000 +0200
3249+++ dietlibc/libcruft/dnscruft.c 2008-09-30 23:02:35.000000000 +0200
3250@@ -20,8 +20,8 @@
3251 void __dns_make_fd(void);
3252 void __dns_make_fd6(void);
3253 void __dns_readstartfiles(void);
3254-int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest,
3255- unsigned int maxlen,unsigned char* behindpacket);
3256+int __dns_decodename(const unsigned char *packet,unsigned int offset,unsigned char *dest,
3257+ unsigned int maxlen,const unsigned char* behindpacket);
3258
3259 void __dns_make_fd(void) {
3260 int tmp;
3261@@ -148,11 +148,11 @@
3262 }
3263
3264 /* return length of decoded data or -1 */
3265-int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest,
3266- unsigned int maxlen,unsigned char* behindpacket) {
3267- unsigned char *tmp;
3268- unsigned char *max=dest+maxlen;
3269- unsigned char *after=packet+offset;
3270+int __dns_decodename(const unsigned char *packet,unsigned int offset,unsigned char *dest,
3271+ unsigned int maxlen,const unsigned char* behindpacket) {
3272+ const unsigned char *tmp;
3273+ const unsigned char *max=dest+maxlen;
3274+ const unsigned char *after=packet+offset;
3275 int ok=0;
3276 for (tmp=after; maxlen>0&&*tmp; ) {
3277 if (tmp>=behindpacket) return -1;
3278diff -urN -x CVS dietlibc-0.31/libcruft/getpagesize.c dietlibc/libcruft/getpagesize.c
3279--- dietlibc-0.31/libcruft/getpagesize.c 2002-02-23 23:18:42.000000000 +0100
3280+++ dietlibc/libcruft/getpagesize.c 2009-02-26 21:51:54.000000000 +0100
3281@@ -1,6 +1,8 @@
3282 #include <sys/types.h>
3283 #include <sys/ipc.h>
3284 #include <sys/shm.h>
3285+/* for environ: */
3286+#include <stdlib.h>
3287
3288 #ifndef PAGE_SIZE
3289 #define PAGE_SIZE 4096
3290@@ -8,6 +10,14 @@
3291
3292 size_t __libc_getpagesize(void);
3293 size_t __libc_getpagesize(void) {
3294+ long* x=(long*)environ;
3295+ int fd;
3296+ while (*x) ++x; ++x; /* skip envp to get to auxvec */
3297+ while (*x) {
3298+ if (*x==6)
3299+ return x[1];
3300+ x+=2;
3301+ }
3302 return PAGE_SIZE;
3303 }
3304
3305diff -urN -x CVS dietlibc-0.31/libcruft/res_query.c dietlibc/libcruft/res_query.c
3306--- dietlibc-0.31/libcruft/res_query.c 2006-12-08 17:24:56.000000000 +0100
3307+++ dietlibc/libcruft/res_query.c 2008-02-20 01:45:12.000000000 +0100
3308@@ -6,7 +6,7 @@
3309 #include <netdb.h>
3310 #include <stdlib.h>
3311 #include <arpa/inet.h>
3312-#include <sys/poll.h>
3313+#include <poll.h>
3314 #include <unistd.h>
3315 #include <errno.h>
3316 #include <arpa/nameser.h>
3317diff -urN -x CVS dietlibc-0.31/libcruft/setlocale.c dietlibc/libcruft/setlocale.c
3318--- dietlibc-0.31/libcruft/setlocale.c 2006-04-04 05:10:40.000000000 +0200
3319+++ dietlibc/libcruft/setlocale.c 2007-09-09 03:37:54.000000000 +0200
3320@@ -4,16 +4,17 @@
3321 #include "dietlocale.h"
3322
3323 char *setlocale (int category, const char *locale) {
3324+ lc_ctype=CT_8BIT;
3325 if (locale && (category==LC_ALL || category==LC_CTYPE)) {
3326 if (!*locale) {
3327- char* x;
3328- lc_ctype=CT_8BIT;
3329+ const char* x;
3330 x=getenv("LC_CTYPE");
3331 if (!x) x=getenv("LC_ALL");
3332 if (!x) x="C";
3333- if (strstr(x,".UTF-8") || strstr(x,".UTF8")) lc_ctype=CT_UTF8;
3334+ locale=x;
3335 }
3336 }
3337+ if (strstr(locale,".UTF-8") || strstr(locale,".UTF8")) lc_ctype=CT_UTF8;
3338 if (locale && (locale[0]!='C' || locale[1])) return 0;
3339 return "C";
3340 }
3341diff -urN -x CVS dietlibc-0.31/libdl/_dl_alloc.c dietlibc/libdl/_dl_alloc.c
3342--- dietlibc-0.31/libdl/_dl_alloc.c 2005-10-07 21:33:34.000000000 +0200
3343+++ dietlibc/libdl/_dl_alloc.c 2008-04-12 00:51:11.000000000 +0200
3344@@ -41,7 +41,7 @@
3345 register int i,m;
3346 #ifdef __DIET_LD_SO__
3347 tmp = (struct _dl_handle*)_dl_sys_mmap(0,at_pagesize,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0);
3348- m=at_pagesize/sizeof(struct _dl_handle);
3349+ m=DIV(at_pagesize,sizeof(struct _dl_handle));
3350 #else
3351 int ps=getpagesize();
3352 tmp = (struct _dl_handle*)mmap(0,ps,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0);
3353diff -urN -x CVS dietlibc-0.31/libdl/dlerror.c dietlibc/libdl/dlerror.c
3354--- dietlibc-0.31/libdl/dlerror.c 2005-05-13 14:22:32.000000000 +0200
3355+++ dietlibc/libdl/dlerror.c 2008-04-12 00:51:11.000000000 +0200
3356@@ -35,7 +35,7 @@
3357 buf[len]=0;
3358 --_dl_error;
3359
3360- if (_dl_error>=(sizeof(_dl_error_msg)/sizeof(struct _dl_err_msg)))
3361+ if (_dl_error>=DIV(sizeof(_dl_error_msg),sizeof(struct _dl_err_msg)))
3362 return "HAE ?!?";
3363
3364 if (_dl_error_location) {
3365diff -urN -x CVS dietlibc-0.31/libdl/_dl_main.c dietlibc/libdl/_dl_main.c
3366--- dietlibc-0.31/libdl/_dl_main.c 2006-11-16 11:04:00.000000000 +0100
3367+++ dietlibc/libdl/_dl_main.c 2008-07-07 14:35:43.000000000 +0200
3368@@ -318,6 +318,7 @@
3369 " mov fp, #0 @ start new stack frame \n"
3370 " ldr a1, [sp], #4 @ argc \n"
3371 " mov a2, sp @ argv \n"
3372+" mov sp, r4 @ restore stack pointer \n"
3373 " add a3, a2, a1, lsl #2 @ envp \n"
3374 " add a3, a3, #4 \n"
3375 /* PIC code startup */
3376@@ -332,8 +333,6 @@
3377 " add a4, a4, sl \n"
3378 /* call _dl_main */
3379 " bl _dl_main \n"
3380-/* restore stack pointer */
3381-" mov sp, r4 \n"
3382 /* save program entry point */
3383 " mov lr, a1 \n"
3384 /* abi: agrument 1: global fini entry */
3385@@ -371,20 +370,20 @@
3386 "_dl_sys_mmap: \n"
3387 " stmdb sp!,{r0,r1,r2,r3} \n"
3388 " mov r0, sp \n"
3389-" swi #0x900090 @ mmap \n"
3390+" swi #0x90005a @ mmap \n"
3391 " add sp, sp, #16 \n"
3392 " mov pc, lr \n"
3393 ".type _dl_sys_munmap,function \n"
3394 "_dl_sys_munmap: \n"
3395-" swi #0x900091 @ munmap \n"
3396+" swi #0x90005b @ munmap \n"
3397 " mov pc, lr \n"
3398 ".type _dl_sys_fstat,function \n"
3399 "_dl_sys_fstat: \n"
3400-" swi #0x900108 @ fstat \n"
3401+" swi #0x90006c @ fstat \n"
3402 " mov pc, lr \n"
3403 ".type _dl_sys_mprotect,function \n"
3404 "_dl_sys_mprotect: \n"
3405-" swi #0x900125 @ mprotect \n"
3406+" swi #0x90007d @ mprotect \n"
3407 " mov pc, lr \n"
3408
3409 ".type _dl_jump,function \n"
3410@@ -689,6 +688,15 @@
3411 #endif
3412
3413 /* now reuse some unchanged sources */
3414+#ifdef __arm__
3415+#include "_dl_math.c"
3416+#define MOD(a,b) _dl_mod(a,b)
3417+#define DIV(a,b) _dl_div(a,b,NULL)
3418+#else
3419+#define MOD(a,b) (a % b)
3420+#define DIV(a,b) (a / b)
3421+#endif
3422+
3423 #include "dlerror.c"
3424 #include "_dl_alloc.c"
3425
3426@@ -1092,7 +1100,7 @@
3427 #ifdef DEBUG
3428 pf(__FUNCTION__); pf(": try to relocate some values\n");
3429 #endif
3430- if (_dl_relocate(dh,rel,relsize/relent)) return 0;
3431+ if (_dl_relocate(dh,rel,DIV(relsize,relent))) return 0;
3432 }
3433
3434 /* do PTL / GOT relocation */
3435diff -urN -x CVS dietlibc-0.31/libdl/_dl_math.c dietlibc/libdl/_dl_math.c
3436--- dietlibc-0.31/libdl/_dl_math.c 1970-01-01 01:00:00.000000000 +0100
3437+++ dietlibc/libdl/_dl_math.c 2008-04-12 00:51:11.000000000 +0200
3438@@ -0,0 +1,33 @@
3439+static unsigned long _dl_div(
3440+ unsigned long num,
3441+ unsigned long den,
3442+ unsigned long * rem)
3443+{
3444+ unsigned long quot = 0, qbit = 1;
3445+
3446+ if (den == 0)
3447+ return 0;
3448+ /* Left-justify denominator and count shift */
3449+ while ((int) den >= 0) {
3450+ den <<= 1;
3451+ qbit <<= 1;
3452+ }
3453+ while (qbit) {
3454+ if (den <= num) {
3455+ num -= den;
3456+ quot += qbit;
3457+ }
3458+ den >>= 1;
3459+ qbit >>= 1;
3460+ }
3461+ if (rem)
3462+ *rem = num;
3463+ return quot;
3464+}
3465+
3466+static unsigned long _dl_mod(unsigned long num, unsigned long den)
3467+{
3468+ unsigned long rem;
3469+ _dl_div(num, den, &rem);
3470+ return rem;
3471+}
3472diff -urN -x CVS dietlibc-0.31/libdl/dlsym.c dietlibc/libdl/dlsym.c
3473--- dietlibc-0.31/libdl/dlsym.c 2006-11-16 11:04:00.000000000 +0100
3474+++ dietlibc/libdl/dlsym.c 2008-04-12 00:51:11.000000000 +0200
3475@@ -6,7 +6,7 @@
3476 static void*_dlsym_elfhash(struct _dl_handle*dh,const unsigned char*symbol) {
3477 unsigned long*sym=0;
3478 unsigned int hash =elf_hash(symbol);
3479- unsigned int bhash=hash%HASH_BUCKET_LEN(dh->hash_tab);
3480+ unsigned int bhash=MOD(hash, HASH_BUCKET_LEN(dh->hash_tab));
3481 unsigned int*chain=HASH_CHAIN(dh->hash_tab);
3482 unsigned char*name=(unsigned char*)dh->dyn_str_tab;
3483 unsigned int ind=HASH_BUCKET(dh->hash_tab)[bhash];
3484@@ -38,7 +38,7 @@
3485 unsigned long*sym=0;
3486 unsigned char*name=(unsigned char*)dh->dyn_str_tab;
3487 unsigned int hash =gnu_hash(symbol);
3488- unsigned int bhash=hash%GNU_HASH_BUCKET_LEN(dh->gnu_hash_tab);
3489+ unsigned int bhash=MOD(hash, GNU_HASH_BUCKET_LEN(dh->hash_tab));
3490 unsigned int ind =GNU_HASH_BUCKET(dh->gnu_hash_tab,bhash);
3491 #ifdef DEBUG
3492 //pf(__FUNCTION__); pf(": bucket("); ph(bhash); pf(",\""); pf(symbol); pf("\")\n");
3493diff -urN -x CVS dietlibc-0.31/libpthread/pthread_fputs.c dietlibc/libpthread/pthread_fputs.c
3494--- dietlibc-0.31/libpthread/pthread_fputs.c 1970-01-01 01:00:00.000000000 +0100
3495+++ dietlibc/libpthread/pthread_fputs.c 2008-05-09 06:36:56.000000000 +0200
3496@@ -0,0 +1,5 @@
3497+#include <dietstdio.h>
3498+
3499+int fputs(const char*s,FILE*stream) {
3500+ return fwrite(s,strlen(s),1,stream);
3501+}
3502diff -urN -x CVS dietlibc-0.31/libpthread/pthread_fread.c dietlibc/libpthread/pthread_fread.c
3503--- dietlibc-0.31/libpthread/pthread_fread.c 1970-01-01 01:00:00.000000000 +0100
3504+++ dietlibc/libpthread/pthread_fread.c 2008-05-09 06:36:56.000000000 +0200
3505@@ -0,0 +1,9 @@
3506+#include <dietstdio.h>
3507+
3508+size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) {
3509+ size_t tmp;
3510+ pthread_mutex_lock(&stream->m);
3511+ tmp=fread_unlocked(ptr,size,nmemb,stream);
3512+ pthread_mutex_unlock(&stream->m);
3513+ return tmp;
3514+}
3515diff -urN -x CVS dietlibc-0.31/libpthread/pthread_fwrite.c dietlibc/libpthread/pthread_fwrite.c
3516--- dietlibc-0.31/libpthread/pthread_fwrite.c 1970-01-01 01:00:00.000000000 +0100
3517+++ dietlibc/libpthread/pthread_fwrite.c 2008-05-09 06:36:56.000000000 +0200
3518@@ -0,0 +1,9 @@
3519+#include <dietstdio.h>
3520+
3521+size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) {
3522+ size_t tmp;
3523+ pthread_mutex_lock(&stream->m);
3524+ tmp=fwrite_unlocked(ptr,size,nmemb,stream);
3525+ pthread_mutex_unlock(&stream->m);
3526+ return tmp;
3527+}
3528diff -urN -x CVS dietlibc-0.31/libpthread/pthread_internal.c dietlibc/libpthread/pthread_internal.c
3529--- dietlibc-0.31/libpthread/pthread_internal.c 2006-09-18 16:55:35.000000000 +0200
3530+++ dietlibc/libpthread/pthread_internal.c 2008-02-20 01:45:12.000000000 +0100
3531@@ -1,3 +1,4 @@
3532+#define _GNU_SOURCE
3533 #include <signal.h>
3534 #include <string.h>
3535 #include <sys/wait.h>
3536@@ -5,7 +6,7 @@
3537 #include <errno.h>
3538 #include <sys/mman.h>
3539
3540-#include <sys/poll.h>
3541+#include <poll.h>
3542 #include <sched.h>
3543 #include <sys/resource.h>
3544
3545diff -urN -x CVS dietlibc-0.31/libregex/rx.c dietlibc/libregex/rx.c
3546--- dietlibc-0.31/libregex/rx.c 2005-11-05 00:10:45.000000000 +0100
3547+++ dietlibc/libregex/rx.c 2008-12-26 02:24:33.000000000 +0100
3548@@ -7,6 +7,10 @@
3549 #include <string.h>
3550 #include <assert.h>
3551
3552+#if !defined(__x86_64__)
3553+#undef WANT_REGEX_JIT
3554+#endif
3555+
3556 /* this is ugly.
3557 * the idea is to build a parse tree, then do some poor man's OOP with a
3558 * generic matcher function call that is always that the start of each
3559@@ -40,15 +44,21 @@
3560 struct branch *b;
3561 }; */
3562
3563+struct string {
3564+ char* s;
3565+ size_t len;
3566+};
3567+
3568 struct atom {
3569 matcher m;
3570 void* next;
3571- enum { ILLEGAL, EMPTY, REGEX, BRACKET, ANY, LINESTART, LINEEND, WORDSTART, WORDEND, CHAR, } type;
3572+ enum { ILLEGAL, EMPTY, REGEX, BRACKET, ANY, LINESTART, LINEEND, WORDSTART, WORDEND, CHAR, STRING, BACKREF, } type;
3573 int bnum;
3574 union {
3575 struct regex r;
3576 struct bracketed b;
3577 char c;
3578+ struct string s;
3579 } u;
3580 };
3581
3582@@ -100,6 +110,30 @@
3583
3584 static const char* parseregex(struct regex* r,const char* s,regex_t* rx);
3585
3586+static int matchatom_CHAR(void*__restrict__ x,const unsigned char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
3587+ register struct atom* a=(struct atom*)x;
3588+#ifdef DEBUG
3589+ printf("matching atom CHAR %c against \"%.20s\"\n",a->u.c,s);
3590+#endif
3591+ if (*s!=a->u.c) return -1;
3592+ if (a->next)
3593+ return ((struct atom*)(a->next))->m(a->next,(const char*)s+1,ofs+1,preg,plus+1,eflags);
3594+ else
3595+ return plus+1;
3596+}
3597+
3598+static int matchatom_CHAR_ICASE(void*__restrict__ x,const unsigned char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
3599+ register struct atom* a=(struct atom*)x;
3600+#ifdef DEBUG
3601+ printf("matching atom CHAR_ICASE %c against \"%.20s\"\n",a->u.c,s);
3602+#endif
3603+ if (tolower(*s)!=a->u.c) return -1;
3604+ if (a->next)
3605+ return ((struct atom*)(a->next))->m(a->next,(const char*)s+1,ofs+1,preg,plus+1,eflags);
3606+ else
3607+ return plus+1;
3608+}
3609+
3610 static int matchatom(void*__restrict__ x,const unsigned char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
3611 register struct atom* a=(struct atom*)x;
3612 int matchlen=0;
3613@@ -176,6 +210,30 @@
3614 matchlen=1;
3615 if (((preg->cflags&REG_ICASE)?tolower(*s):*s)==a->u.c) goto match;
3616 break;
3617+ case STRING:
3618+ matchlen=a->u.s.len;
3619+#ifdef DEBUG
3620+ printf("matching atom STRING \"%.*s\" against \"%.20s\"\n",a->u.s.len,a->u.s.s,s);
3621+#endif
3622+ {
3623+ int i;
3624+ if (preg->cflags&REG_ICASE) {
3625+ for (i=0; i<matchlen; ++i)
3626+ if (tolower(s[i]) != a->u.s.s[i]) return -1;
3627+ } else {
3628+ for (i=0; i<matchlen; ++i)
3629+ if (s[i] != a->u.s.s[i]) return -1;
3630+ }
3631+ }
3632+ goto match;
3633+ break;
3634+ case BACKREF:
3635+ matchlen=preg->l[(unsigned char)(a->u.c)].rm_eo-preg->l[(unsigned char)(a->u.c)].rm_so;
3636+#ifdef DEBUG
3637+ printf("matching atom BACKREF %d (\"%.*s\") against \"%.20s\"\n",a->u.c,matchlen,s-ofs+preg->l[a->u.c].rm_so,s);
3638+#endif
3639+ if (memcmp(s-ofs+preg->l[(unsigned char)(a->u.c)].rm_so,s,matchlen)==0) goto match;
3640+ break;
3641 }
3642 return -1;
3643 match:
3644@@ -226,10 +284,36 @@
3645 } else if (*s=='>') {
3646 a->type=WORDEND;
3647 break;
3648+ } else if (*s>='1' && *s<=(rx->brackets+'1') && ((rx->cflags&REG_EXTENDED)==0)) {
3649+ a->type=BACKREF;
3650+ a->u.c=*s-'0';
3651+ break;
3652 }
3653+ /* fall through */
3654 default:
3655 a->type=CHAR;
3656- a->u.c=rx->cflags&REG_ICASE?tolower(*s):*s;
3657+ if (rx->cflags&REG_ICASE) {
3658+ a->u.c=tolower(*s);
3659+ a->m=(matcher)matchatom_CHAR_ICASE;
3660+ } else {
3661+ a->u.c=*s;
3662+ a->m=(matcher)matchatom_CHAR;
3663+ }
3664+ /* optimization: if we have a run of CHAR, make it into a STRING */
3665+ {
3666+ size_t i;
3667+ for (i=1; s[i] && !strchr("(|)[.^$\\*+?{",s[i]); ++i) ;
3668+ if (!strchr("*+?{",s[i])) --i;
3669+ if (i>2) {
3670+ a->m=(matcher)matchatom;
3671+ a->type=STRING;
3672+ a->u.s.len=i;
3673+ if (!(a->u.s.s=malloc(i+1))) return s;
3674+ memcpy(a->u.s.s,s,i);
3675+ a->u.s.s[i]=0;
3676+ return s+i;
3677+ }
3678+ }
3679 break;
3680 }
3681 return s+1;
3682@@ -444,6 +528,7 @@
3683 if (b->m!=matchempty) {
3684 for (i=0; i<b->num-1; ++i) {
3685 if (b->p[i+1].min==1 && b->p[i+1].max==1)
3686+/* shortcut: link directly to next atom if it's a piece with min=max=1 */
3687 piece_putnext(&b->p[i],&b->p[i+1].a);
3688 else
3689 piece_putnext(&b->p[i],&b->p[i+1]);
3690@@ -502,8 +587,10 @@
3691 int j,k;
3692 k=r->b[i].num;
3693 for (j=0; j<k; ++j)
3694- if (r->b[i].p[j].a.type==REGEX)
3695- __regfree(&r->b[i].p[j].a.u.r);
3696+ if (r->b[i].p[j].a.type==REGEX)
3697+ __regfree(&r->b[i].p[j].a.u.r);
3698+ else if (r->b[i].p[j].a.type==STRING)
3699+ free(r->b[i].p[j].a.u.s.s);
3700 free(r->b[i].p);
3701 }
3702 free(r->b);
3703diff -urN -x CVS dietlibc-0.31/libstdio/fflush.c dietlibc/libstdio/fflush.c
3704--- dietlibc-0.31/libstdio/fflush.c 2006-06-01 08:11:34.000000000 +0200
3705+++ dietlibc/libstdio/fflush.c 2009-01-13 18:58:38.000000000 +0100
3706@@ -43,11 +43,11 @@
3707 }
3708
3709 int __fflush4(FILE *stream,int next) {
3710- if (!__stdio_atexit) {
3711+ if (__unlikely(!__stdio_atexit)) {
3712 __stdio_atexit=1;
3713 atexit(__stdio_flushall);
3714 }
3715- if ((stream->flags&BUFINPUT)!=next) {
3716+ if (__unlikely((stream->flags&BUFINPUT)!=next)) {
3717 int res=fflush_unlocked(stream);
3718 stream->flags=(stream->flags&~BUFINPUT)|next;
3719 return res;
3720diff -urN -x CVS dietlibc-0.31/libstdio/fgetc_unlocked.c dietlibc/libstdio/fgetc_unlocked.c
3721--- dietlibc-0.31/libstdio/fgetc_unlocked.c 2005-09-21 09:33:08.000000000 +0200
3722+++ dietlibc/libstdio/fgetc_unlocked.c 2009-02-26 21:51:54.000000000 +0100
3723@@ -3,15 +3,20 @@
3724
3725 int fgetc_unlocked(FILE *stream) {
3726 unsigned char c;
3727- if (!(stream->flags&CANREAD)) goto kaputt;
3728- if (stream->ungotten) {
3729+ if (__unlikely(!(stream->flags&CANREAD))) goto kaputt;
3730+ if (__unlikely(stream->ungotten)) {
3731 stream->ungotten=0;
3732 return stream->ungetbuf;
3733 }
3734- if (feof_unlocked(stream))
3735+
3736+ /* common case first */
3737+ if (__likely(stream->bm<stream->bs))
3738+ return (unsigned char)stream->buf[stream->bm++];
3739+
3740+ if (__unlikely(feof_unlocked(stream)))
3741 return EOF;
3742 if (__fflush4(stream,BUFINPUT)) return EOF;
3743- if (stream->bm>=stream->bs) {
3744+ if (__unlikely(stream->bm>=stream->bs)) {
3745 ssize_t len=__libc_read(stream->fd,stream->buf,stream->buflen);
3746 if (len==0) {
3747 stream->flags|=EOFINDICATOR;
3748diff -urN -x CVS dietlibc-0.31/libstdio/fgets.c dietlibc/libstdio/fgets.c
3749--- dietlibc-0.31/libstdio/fgets.c 2003-11-11 19:39:51.000000000 +0100
3750+++ dietlibc/libstdio/fgets.c 2009-01-13 18:58:38.000000000 +0100
3751@@ -1,20 +1,28 @@
3752 #include "dietstdio.h"
3753
3754 char *fgets_unlocked(char *s, int size, FILE *stream) {
3755- char *orig=s;
3756 int l;
3757- for (l=size; l>1;) {
3758- register int c=fgetc_unlocked(stream);
3759- if (c==EOF) break;
3760- *s=c;
3761- ++s;
3762- --l;
3763- if (c=='\n') break;
3764+ for (l=0; l<size; ) {
3765+ register int c;
3766+ if (l && __likely(stream->bm<stream->bs)) {
3767+ /* try common case first */
3768+ c=(unsigned char)stream->buf[stream->bm++];
3769+ } else {
3770+ c=fgetc_unlocked(stream);
3771+ if (__unlikely(c==EOF)) {
3772+ if (!l) return 0;
3773+ goto fini;
3774+ }
3775+ }
3776+ s[l]=c;
3777+ ++l;
3778+ if (c=='\n') {
3779+fini:
3780+ s[l]=0;
3781+ return s;
3782+ }
3783 }
3784- if (l==size || ferror_unlocked(stream))
3785- return 0;
3786- *s=0;
3787- return orig;
3788+ return 0;
3789 }
3790
3791 char*fgets(char*s,int size,FILE*stream) __attribute__((weak,alias("fgets_unlocked")));
3792diff -urN -x CVS dietlibc-0.31/libstdio/fputc_unlocked.c dietlibc/libstdio/fputc_unlocked.c
3793--- dietlibc-0.31/libstdio/fputc_unlocked.c 2003-11-11 19:27:41.000000000 +0100
3794+++ dietlibc/libstdio/fputc_unlocked.c 2009-01-13 18:58:38.000000000 +0100
3795@@ -3,12 +3,12 @@
3796 #include <endian.h>
3797
3798 int fputc_unlocked(int c, FILE *stream) {
3799- if (!(stream->flags&CANWRITE) || __fflush4(stream,0)) {
3800+ if (!__likely(stream->flags&CANWRITE) || __fflush4(stream,0)) {
3801 kaputt:
3802 stream->flags|=ERRORINDICATOR;
3803 return EOF;
3804 }
3805- if (stream->bm>=stream->buflen-1)
3806+ if (__unlikely(stream->bm>=stream->buflen-1))
3807 if (fflush_unlocked(stream)) goto kaputt;
3808 if (stream->flags&NOBUF) {
3809 #if __BYTE_ORDER == __LITTLE_ENDIAN
3810diff -urN -x CVS dietlibc-0.31/libstdio/fwrite.c dietlibc/libstdio/fwrite.c
3811--- dietlibc-0.31/libstdio/fwrite.c 2005-09-21 09:33:08.000000000 +0200
3812+++ dietlibc/libstdio/fwrite.c 2009-01-13 18:58:38.000000000 +0100
3813@@ -5,22 +5,43 @@
3814
3815 size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb, FILE *stream) {
3816 ssize_t res;
3817- unsigned long len=size*nmemb;
3818- long i;
3819- if (!(stream->flags&CANWRITE)) {
3820+ size_t len=size*nmemb;
3821+ size_t i,done;
3822+ if (!__likely(stream->flags&CANWRITE) || __fflush4(stream,0)) {
3823+kaputt:
3824 stream->flags|=ERRORINDICATOR;
3825 return 0;
3826 }
3827 if (!nmemb || len/nmemb!=size) return 0; /* check for integer overflow */
3828- if (len>stream->buflen || (stream->flags&NOBUF)) {
3829+ if (__unlikely(len>stream->buflen || (stream->flags&NOBUF))) {
3830 if (fflush_unlocked(stream)) return 0;
3831 do {
3832 res=__libc_write(stream->fd,ptr,len);
3833 } while (res==-1 && errno==EINTR);
3834 } else {
3835- register const unsigned char *c=ptr;
3836- for (i=len; i>0; --i,++c)
3837- if (fputc_unlocked(*c,stream)) { res=len-i; goto abort; }
3838+ /* try to make the common case fast */
3839+ size_t todo=stream->buflen-stream->bm;
3840+ if (todo>len) todo=len;
3841+
3842+ if (todo) {
3843+ if (stream->flags&BUFLINEWISE) {
3844+ for (i=0; i<todo; ++i) {
3845+ if ((stream->buf[stream->bm++]=((char*)ptr)[i])=='\n') {
3846+ if (fflush_unlocked(stream)) goto kaputt;
3847+ }
3848+ }
3849+ } else {
3850+ memcpy(stream->buf+stream->bm,ptr,todo);
3851+ stream->bm+=todo;
3852+ }
3853+ done=todo;
3854+ } else
3855+ done=0;
3856+ for (i=done; i<len; ++i)
3857+ if (fputc_unlocked(((char*)ptr)[i],stream)) {
3858+ res=len-i;
3859+ goto abort;
3860+ }
3861 res=len;
3862 }
3863 if (res<0) {
3864diff -urN -x CVS dietlibc-0.31/libstdio/setvbuf.c dietlibc/libstdio/setvbuf.c
3865--- dietlibc-0.31/libstdio/setvbuf.c 2006-06-01 08:11:34.000000000 +0200
3866+++ dietlibc/libstdio/setvbuf.c 2007-10-09 01:15:27.000000000 +0200
3867@@ -27,8 +27,8 @@
3868 if (!(tmp=malloc(size))) return -1;
3869 if (!(stream->flags&STATICBUF)) free(stream->buf);
3870 stream->buf=tmp;
3871- stream->flags &= ~STATICBUF;
3872 }
3873+ stream->flags &= ~STATICBUF;
3874 stream->buflen=size;
3875 stream->bm=stream->bs=0;
3876 return set_flags(stream,flags);
3877diff -urN -x CVS dietlibc-0.31/libugly/getaddrinfo.c dietlibc/libugly/getaddrinfo.c
3878--- dietlibc-0.31/libugly/getaddrinfo.c 2007-03-26 05:06:59.000000000 +0200
3879+++ dietlibc/libugly/getaddrinfo.c 2009-03-11 05:03:16.000000000 +0100
3880@@ -102,11 +102,11 @@
3881 for (foo->ai.ai_socktype=SOCK_STREAM; ; foo->ai.ai_socktype=SOCK_DGRAM) {
3882 char* type,* x;
3883 if (foo->ai.ai_socktype==SOCK_STREAM) { /* TCP */
3884- if (hints->ai_socktype==SOCK_DGRAM) continue;
3885+ if (hints && hints->ai_socktype==SOCK_DGRAM) continue;
3886 foo->ai.ai_protocol=IPPROTO_TCP;
3887 type="tcp";
3888 } else { /* UDP */
3889- if (hints->ai_socktype==SOCK_STREAM) break;
3890+ if (hints && hints->ai_socktype==SOCK_STREAM) break;
3891 foo->ai.ai_protocol=IPPROTO_UDP;
3892 type="udp";
3893 }
3894diff -urN -x CVS dietlibc-0.31/libugly/iswctype.c dietlibc/libugly/iswctype.c
3895--- dietlibc-0.31/libugly/iswctype.c 1970-01-01 01:00:00.000000000 +0100
3896+++ dietlibc/libugly/iswctype.c 2007-09-09 04:11:18.000000000 +0200
3897@@ -0,0 +1,6 @@
3898+#include <wctype.h>
3899+#include <string.h>
3900+
3901+int iswctype(wint_t wc, wctype_t desc) {
3902+ return desc(wc);
3903+}
3904diff -urN -x CVS dietlibc-0.31/libugly/popen.c dietlibc/libugly/popen.c
3905--- dietlibc-0.31/libugly/popen.c 2002-01-29 19:54:03.000000000 +0100
3906+++ dietlibc/libugly/popen.c 2008-02-19 14:08:19.000000000 +0100
3907@@ -13,16 +13,12 @@
3908
3909 if (pipe(pfd)<0) return 0;
3910 fd0=(*type=='r');
3911- if (!(f=fdopen(pfd[!fd0],type))) {
3912+ if ((!(f=fdopen(pfd[!fd0],type))) ||
3913+ ((pid=fork())<0)) {
3914 close(pfd[0]); /* malloc failed */
3915 close(pfd[1]);
3916 return 0;
3917 }
3918- if ((pid=fork())<0) {
3919- close(pfd[0]);
3920- close(pfd[1]);
3921- return 0;
3922- }
3923 if (!pid) { /* child */
3924 const char *argv[]={__sh,"-c",0,0};
3925 close(pfd[!fd0]); close(fd0);
3926diff -urN -x CVS dietlibc-0.31/libugly/strptime.c dietlibc/libugly/strptime.c
3927--- dietlibc-0.31/libugly/strptime.c 2007-08-03 22:58:33.000000000 +0200
3928+++ dietlibc/libugly/strptime.c 2008-11-26 19:43:06.000000000 +0100
3929@@ -134,6 +134,11 @@
3930 if (i==-1) return 0;
3931 tm->tm_year=i-1900;
3932 break;
3933+ case 'Z':
3934+ /* time zone. Not sure what I'm expected to do here. We'll just
3935+ * skip to the next whitespace */
3936+ while (*s!=' ' && *s!='\t') ++s;
3937+ break;
3938 }
3939 ++format;
3940 break;
3941diff -urN -x CVS dietlibc-0.31/libugly/utent.c dietlibc/libugly/utent.c
3942--- dietlibc-0.31/libugly/utent.c 2005-09-21 09:33:08.000000000 +0200
3943+++ dietlibc/libugly/utent.c 2008-02-23 01:09:54.000000000 +0100
3944@@ -5,6 +5,7 @@
3945
3946 static const char *utmp_file_name = _PATH_UTMP;
3947 static int fd = -1;
3948+static off_t utmp_current = 0;
3949
3950 static int lock_record(int type) {
3951 struct flock fl;
3952@@ -37,12 +38,13 @@
3953 if (fd<0) fd = open(utmp_file_name,O_RDWR);
3954 if (fd<0) fd = open(utmp_file_name,O_RDONLY);
3955 fcntl (fd, F_SETFD, FD_CLOEXEC);
3956- lseek(fd,0,SEEK_SET);
3957+ utmp_current = lseek(fd,0,SEEK_SET);
3958 }
3959
3960 void endutent() {
3961 if (fd<0) return;
3962 close(fd); fd=-1;
3963+ utmp_current = 0;
3964 }
3965
3966 struct utmp *getutent(void) {
3967@@ -53,6 +55,7 @@
3968 setutent();
3969 if (fd<0) return 0;
3970 }
3971+ utmp_current = lseek (fd, 0, SEEK_CUR);
3972 if (lock_record(F_RDLCK)) return 0;
3973 ret=read(fd, &getutent_tmp, sizeof(struct utmp));
3974 unlock_record();
3975@@ -88,13 +91,16 @@
3976 void pututline(struct utmp *ut) {
3977 struct utmp *tmp;
3978
3979+ /* Seek to the current record before searching. */
3980+ lseek (fd, utmp_current, SEEK_SET);
3981 if ((tmp = getutid(ut))) {
3982 lseek(fd, - (off_t)sizeof(struct utmp), SEEK_CUR);
3983 if (lock_record(F_WRLCK)) return;
3984 write(fd, ut, sizeof(struct utmp));
3985+ utmp_current += sizeof(struct utmp);
3986 }
3987 else {
3988- lseek(fd, 0, SEEK_END);
3989+ utmp_current = lseek(fd, 0, SEEK_END);
3990 if (lock_record(F_WRLCK)) return;
3991 write(fd, ut, sizeof(struct utmp));
3992 }
3993diff -urN -x CVS dietlibc-0.31/libugly/__utmp_block_signals.c dietlibc/libugly/__utmp_block_signals.c
3994--- dietlibc-0.31/libugly/__utmp_block_signals.c 1970-01-01 01:00:00.000000000 +0100
3995+++ dietlibc/libugly/__utmp_block_signals.c 2008-02-23 01:09:54.000000000 +0100
3996@@ -0,0 +1,45 @@
3997+#include <signal.h>
3998+
3999+/*
4000+ * Block a bunch of signals. Call with a sigset_t pointer into which
4001+ * the old signal set is placed. On error (which should never happen),
4002+ * returns NULL, otherwise returns oldset.
4003+ */
4004+
4005+sigset_t *__utmp_block_signals (sigset_t *oldset);
4006+
4007+sigset_t *
4008+__utmp_block_signals (sigset_t *oldset)
4009+{
4010+ sigset_t blockset;
4011+
4012+ /* There are actually more signals to block than not, so just start
4013+ * with everything */
4014+ sigfillset (&blockset);
4015+
4016+ /* Don't try to block program error signals */
4017+
4018+ /* Unconditionally defined signals */
4019+ sigdelset (&blockset, SIGILL);
4020+ sigdelset (&blockset, SIGTRAP);
4021+ sigdelset (&blockset, SIGABRT);
4022+ sigdelset (&blockset, SIGIOT); /* Yeah, right */
4023+ sigdelset (&blockset, SIGFPE);
4024+ sigdelset (&blockset, SIGSEGV);
4025+
4026+ /* Others. FIXME - This list may need to be expanded. */
4027+#ifdef SIGBUS
4028+ sigdelset (&blockset, SIGBUS);
4029+#endif
4030+#ifdef SIGEMT
4031+ sigdelset (&blockset, SIGEMT);
4032+#endif
4033+#ifdef SIGSYS
4034+ sigdelset (&blockset, SIGSYS);
4035+#endif
4036+
4037+ if (sigprocmask (SIG_BLOCK, &blockset, oldset) < 0)
4038+ oldset = (sigset_t *)0;
4039+
4040+ return oldset;
4041+}
4042diff -urN -x CVS dietlibc-0.31/libugly/__utmp_io.c dietlibc/libugly/__utmp_io.c
4043--- dietlibc-0.31/libugly/__utmp_io.c 1970-01-01 01:00:00.000000000 +0100
4044+++ dietlibc/libugly/__utmp_io.c 2008-02-23 01:09:54.000000000 +0100
4045@@ -0,0 +1,47 @@
4046+#include <unistd.h>
4047+#include <fcntl.h>
4048+#include <errno.h>
4049+
4050+void *__utmp_io(int fd, void *ut, ssize_t len, off_t *offset, int type);
4051+
4052+/* type: F_RDLCK or F_WRLCK */
4053+void *
4054+__utmp_io(int fd, void *ut, ssize_t len, off_t *offset, int type) {
4055+ int e, ret;
4056+ struct flock fl;
4057+ off_t newoffset;
4058+
4059+ fl.l_whence = SEEK_CUR;
4060+ fl.l_start = 0;
4061+ fl.l_len = len;
4062+ fl.l_pid = 0;
4063+ fl.l_type = type;
4064+
4065+ if (fcntl(fd, F_SETLKW, &fl)) return 0;
4066+ if (type == F_WRLCK) {
4067+ ret = write(fd, ut, len);
4068+ e = errno;
4069+ fsync (fd);
4070+ /* FIXME - where exactly should the offset point after a write? */
4071+ newoffset = lseek (fd, 0, SEEK_CUR);
4072+ } else {
4073+ newoffset = lseek (fd, 0, SEEK_CUR);
4074+ ret = read(fd, ut, len);
4075+ e = errno;
4076+ }
4077+
4078+ fl.l_start = -(len);
4079+ fl.l_type = F_UNLCK;
4080+
4081+ fcntl(fd, F_SETLK, &fl);
4082+
4083+ /* Arrrgh! There's no provision in the POSIX utmp spec for detecting errors.
4084+ * Stupidly update the offset. */
4085+ if (offset)
4086+ *offset = newoffset;
4087+
4088+ errno = e;
4089+ if (ret != len)
4090+ return (void *)0;
4091+ return ut;
4092+}
4093diff -urN -x CVS dietlibc-0.31/libugly/utxent.c dietlibc/libugly/utxent.c
4094--- dietlibc-0.31/libugly/utxent.c 1970-01-01 01:00:00.000000000 +0100
4095+++ dietlibc/libugly/utxent.c 2008-02-23 01:09:54.000000000 +0100
4096@@ -0,0 +1,125 @@
4097+#include <unistd.h>
4098+#include <fcntl.h>
4099+#include <string.h>
4100+#include <errno.h>
4101+#include <utmpx.h>
4102+#include <signal.h>
4103+
4104+static const char *utmp_file_name = _PATH_UTMPX;
4105+static int fd = -1;
4106+static off_t utmp_current = 0;
4107+
4108+/* Forward declaration for utmp common functions */
4109+void *__utmp_io(int fd, void *ut, ssize_t len, off_t *offset, int type);
4110+sigset_t *__utmp_block_signals (sigset_t *oldset);
4111+
4112+/* See libcompat for utmpxname() */
4113+void __utmpxname(const char *file); /* keep the compiler happy */
4114+void __utmpxname(const char *file) {
4115+ if (file)
4116+ utmp_file_name = file;
4117+ else
4118+ utmp_file_name = _PATH_UTMPX;
4119+}
4120+
4121+void setutxent() {
4122+ sigset_t oldset, *savedset;
4123+
4124+ savedset = __utmp_block_signals(&oldset);
4125+ if (fd<0) fd = open(utmp_file_name,O_RDWR);
4126+ if (fd<0) fd = open(utmp_file_name,O_RDONLY);
4127+ fcntl (fd, F_SETFD, FD_CLOEXEC);
4128+ utmp_current = lseek(fd,0,SEEK_SET);
4129+ if (savedset)
4130+ sigprocmask (SIG_SETMASK, savedset, 0);
4131+}
4132+
4133+void endutxent() {
4134+ if (fd<0) return;
4135+ close(fd); fd=-1;
4136+ utmp_current = 0;
4137+}
4138+
4139+struct utmpx *getutxent(void) {
4140+ static struct utmpx getutent_tmp, *retval;
4141+ ssize_t ret;
4142+ sigset_t oldset, *savedset;
4143+
4144+ if (fd<0) {
4145+ setutxent();
4146+ if (fd<0) return 0;
4147+ }
4148+ savedset = __utmp_block_signals (&oldset);
4149+
4150+ retval = __utmp_io(fd, &getutent_tmp, sizeof(struct utmpx),
4151+ &utmp_current, F_RDLCK);
4152+
4153+ if (savedset)
4154+ sigprocmask (SIG_SETMASK, savedset, 0);
4155+
4156+ return retval;
4157+}
4158+
4159+struct utmpx *getutxid(struct utmpx *ut) {
4160+ struct utmpx *tmp;
4161+
4162+ while ((tmp = getutxent())) {
4163+ if (ut->ut_type && (ut->ut_type <= OLD_TIME)) {
4164+ if (ut->ut_type == tmp->ut_type) break;
4165+ }
4166+ if ((ut->ut_type >= INIT_PROCESS) && (ut->ut_type <= DEAD_PROCESS)) {
4167+ if (!strncmp(ut->ut_id,tmp->ut_id,4)) break;
4168+ }
4169+ }
4170+ return tmp;
4171+}
4172+
4173+struct utmpx *getutxline(struct utmpx *ut) {
4174+ struct utmpx *tmp;
4175+
4176+ while ((tmp = getutxent())) {
4177+ if ((tmp->ut_type == USER_PROCESS) || (tmp->ut_type == LOGIN_PROCESS)) {
4178+ if (!strncmp(ut->ut_line,tmp->ut_line,__UT_LINESIZE)) break;
4179+ }
4180+ }
4181+ return tmp;
4182+}
4183+
4184+struct utmpx *pututxline(struct utmpx *ut) {
4185+ struct utmpx *tmp, ut_copy, *retval = 0, *result;
4186+ int e;
4187+ ssize_t bytes_written;
4188+ sigset_t oldset, *savedset;
4189+
4190+ /* It's kosher to call this function with a pointer to our own static
4191+ * utmp structure, so work with a copy of "ut" */
4192+
4193+ memcpy (&ut_copy, ut, sizeof (struct utmpx));
4194+
4195+ savedset = __utmp_block_signals (&oldset);
4196+
4197+ /* Seek to the current record before searching. */
4198+ lseek (fd, utmp_current, SEEK_SET);
4199+ if ((tmp = getutxid(&ut_copy))) {
4200+ lseek(fd, - (off_t)sizeof(struct utmpx), SEEK_CUR);
4201+ result = __utmp_io (fd, &ut_copy, sizeof(struct utmpx),
4202+ &utmp_current, F_WRLCK);
4203+ e = errno;
4204+ } else {
4205+ utmp_current = lseek(fd, 0, SEEK_END);
4206+ result = __utmp_io (fd, &ut_copy, sizeof(struct utmpx),
4207+ &utmp_current, F_WRLCK);
4208+ e = errno;
4209+ }
4210+ if (savedset)
4211+ sigprocmask (SIG_SETMASK, savedset, 0);
4212+
4213+ if (result) {
4214+ retval = ut;
4215+ }
4216+
4217+ memcpy (ut, &ut_copy, sizeof (struct utmpx));
4218+ errno = e;
4219+ return retval;
4220+}
4221+
4222diff -urN -x CVS dietlibc-0.31/libugly/wctype.c dietlibc/libugly/wctype.c
4223--- dietlibc-0.31/libugly/wctype.c 1970-01-01 01:00:00.000000000 +0100
4224+++ dietlibc/libugly/wctype.c 2007-09-09 04:11:18.000000000 +0200
4225@@ -0,0 +1,24 @@
4226+#include <wctype.h>
4227+#include <string.h>
4228+
4229+struct { const char* name; wctype_t func; } types[]={
4230+ { "alnum", iswalnum },
4231+ { "alpha", iswalpha },
4232+ { "blank", iswblank },
4233+ { "cntrl", iswcntrl },
4234+ { "digit", iswdigit },
4235+ { "graph", iswgraph },
4236+ { "lower", iswlower },
4237+ { "print", iswprint },
4238+ { "punct", iswpunct },
4239+ { "space", iswspace },
4240+ { "upper", iswupper },
4241+ { "xdigit", iswxdigit },
4242+};
4243+
4244+wctype_t wctype(const char* name) {
4245+ size_t i;
4246+ for (i=0; i<sizeof(types)/sizeof(types[0]); ++i)
4247+ if (!strcmp(name,types[i].name)) return types[i].func;
4248+ return (wctype_t)0;
4249+}
4250diff -urN -x CVS dietlibc-0.31/libugly/wmemcmp.c dietlibc/libugly/wmemcmp.c
4251--- dietlibc-0.31/libugly/wmemcmp.c 1970-01-01 01:00:00.000000000 +0100
4252+++ dietlibc/libugly/wmemcmp.c 2007-10-01 19:22:56.000000000 +0200
4253@@ -0,0 +1,10 @@
4254+#include <wchar.h>
4255+
4256+int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n) {
4257+ size_t i;
4258+ for (i=0; i<n; ++i) {
4259+ wint_t x=s1[i]-s2[i];
4260+ if (x) return x;
4261+ }
4262+ return 0;
4263+}
4264diff -urN -x CVS dietlibc-0.31/libugly/wmemcpy.c dietlibc/libugly/wmemcpy.c
4265--- dietlibc-0.31/libugly/wmemcpy.c 1970-01-01 01:00:00.000000000 +0100
4266+++ dietlibc/libugly/wmemcpy.c 2007-10-01 19:22:56.000000000 +0200
4267@@ -0,0 +1,8 @@
4268+#include <wchar.h>
4269+
4270+wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t n) {
4271+ size_t i;
4272+ for (i=0; i<n; ++i)
4273+ dest[i]=src[i];
4274+ return dest;
4275+}
4276diff -urN -x CVS dietlibc-0.31/libugly/wmemset.c dietlibc/libugly/wmemset.c
4277--- dietlibc-0.31/libugly/wmemset.c 1970-01-01 01:00:00.000000000 +0100
4278+++ dietlibc/libugly/wmemset.c 2007-10-01 19:22:56.000000000 +0200
4279@@ -0,0 +1,7 @@
4280+#include <wchar.h>
4281+
4282+wchar_t *wmemset(wchar_t *wcs, wchar_t wc, size_t n) {
4283+ size_t i;
4284+ for (i=0; i<n; ++i) wcs[i]=wc;
4285+ return wcs;
4286+}
4287diff -urN -x CVS dietlibc-0.31/Makefile dietlibc/Makefile
4288--- dietlibc-0.31/Makefile 2007-02-08 15:40:20.000000000 +0100
4289+++ dietlibc/Makefile 2008-05-09 06:36:56.000000000 +0200
4290@@ -140,7 +140,7 @@
4291 CFLAGS = -g
4292 COMMENT = :
4293 endif
4294-CFLAGS += -Wall -W -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls
4295+CFLAGS += -W -Wall -Wextra -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls
4296
4297 PWD=$(shell pwd)
4298
4299@@ -352,7 +352,7 @@
4300 t1:
4301 $(CROSS)$(CC) -g -o t1 t.c
4302
4303-install: $(OBJDIR)/start.o $(OBJDIR)/dietlibc.a $(OBJDIR)/librpc.a $(OBJDIR)/liblatin1.a $(OBJDIR)/libcompat.a $(OBJDIR)/elftrunc $(OBJDIR)/diet-i
4304+install-bin: $(OBJDIR)/start.o $(OBJDIR)/dietlibc.a $(OBJDIR)/librpc.a $(OBJDIR)/liblatin1.a $(OBJDIR)/libcompat.a $(OBJDIR)/elftrunc $(OBJDIR)/diet-i
4305 $(INSTALL) -d $(DESTDIR)$(ILIBDIR) $(DESTDIR)$(MAN1DIR) $(DESTDIR)$(BINDIR)
4306 $(INSTALL) $(OBJDIR)/start.o $(DESTDIR)$(ILIBDIR)/start.o
4307 $(INSTALL) -m 644 $(OBJDIR)/libm.a $(OBJDIR)/libpthread.a $(OBJDIR)/librpc.a \
4308@@ -363,7 +363,12 @@
4309 -$(INSTALL) $(PICODIR)/diet-dyn-i $(DESTDIR)$(BINDIR)/diet-dyn
4310 endif
4311 $(INSTALL) -m 755 $(OBJDIR)/elftrunc $(OBJDIR)/dnsd $(DESTDIR)$(BINDIR)
4312+ $(INSTALL) -m 644 diet.1 $(DESTDIR)$(MAN1DIR)/diet.1
4313+
4314+install-profiling:
4315 -$(INSTALL) $(OBJDIR)/pstart.o $(OBJDIR)/libgmon.a $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR)
4316+
4317+install-pic:
4318 -$(INSTALL) $(PICODIR)/libc.so $(DESTDIR)$(ILIBDIR)/libc.so
4319 -$(INSTALL) $(PICODIR)/libpthread.so $(DESTDIR)$(ILIBDIR)/libpthread.so
4320 -$(INSTALL) $(PICODIR)/libdl.so $(DESTDIR)$(ILIBDIR)/libdl.so
4321@@ -372,10 +377,14 @@
4322 -$(INSTALL) $(PICODIR)/dyn_start.o $(DESTDIR)$(ILIBDIR)/dyn_dstart.o
4323 -$(INSTALL) $(PICODIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR)/dyn_dstop.o
4324 -$(INSTALL) $(PICODIR)/dstart.o $(PICODIR)/dyn_so_start.o $(DESTDIR)$(ILIBDIR)
4325- $(INSTALL) -m 644 diet.1 $(DESTDIR)$(MAN1DIR)/diet.1
4326 if test -f $(PICODIR)/libc.so -a ! -f $(DESTDIR)/etc/diet.ld.conf; then echo "$(ILIBDIR)" > $(DESTDIR)/etc/diet.ld.conf; fi
4327+
4328+install-headers:
4329 for i in `find include -name \*.h`; do install -m 644 -D $$i $(DESTDIR)$(prefix)/$$i; done
4330
4331+
4332+install: install-bin install-profiling install-pic install-headers
4333+
4334 uninstall:
4335 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
4336 rm -f $(DESTDIR)$(BINDIR)/diet $(DESTDIR)$(BINDIR)/diet-dyn
4337diff -urN -x CVS dietlibc-0.31/mips/syscalls.h dietlibc/mips/syscalls.h
4338--- dietlibc-0.31/mips/syscalls.h 2006-09-19 00:08:39.000000000 +0200
4339+++ dietlibc/mips/syscalls.h 2008-09-30 23:02:35.000000000 +0200
4340@@ -312,6 +312,21 @@
4341 #define __NR_tee (__NR_Linux + 306)
4342 #define __NR_vmsplice (__NR_Linux + 307)
4343 #define __NR_move_pages (__NR_Linux + 308)
4344+#define __NR_set_robust_list (__NR_Linux + 272)
4345+#define __NR_get_robust_list (__NR_Linux + 273)
4346+#define __NR_kexec_load (__NR_Linux + 274)
4347+#define __NR_getcpu (__NR_Linux + 275)
4348+#define __NR_epoll_pwait (__NR_Linux + 276)
4349+#define __NR_ioprio_set (__NR_Linux + 277)
4350+#define __NR_ioprio_get (__NR_Linux + 278)
4351+#define __NR_utimensat (__NR_Linux + 279)
4352+#define __NR_signalfd (__NR_Linux + 280)
4353+#define __NR_timerfd (__NR_Linux + 281)
4354+#define __NR_eventfd (__NR_Linux + 282)
4355+#define __NR_fallocate (__NR_Linux + 283)
4356+#define __NR_timerfd_create (__NR_Linux + 284)
4357+#define __NR_timerfd_gettime (__NR_Linux + 285)
4358+#define __NR_timerfd_settime (__NR_Linux + 286)
4359
4360 #define syscall_weak(name,wsym,sym) \
4361 .text; \
4362diff -urN -x CVS dietlibc-0.31/parisc/mmap2.S dietlibc/parisc/mmap2.S
4363--- dietlibc-0.31/parisc/mmap2.S 1970-01-01 01:00:00.000000000 +0100
4364+++ dietlibc/parisc/mmap2.S 2008-11-03 04:13:35.000000000 +0100
4365@@ -0,0 +1,6 @@
4366+#include "syscalls.h"
4367+
4368+#ifdef __NR_mmap2
4369+syscall6(mmap2,__mmap2)
4370+#endif
4371+
4372diff -urN -x CVS dietlibc-0.31/parisc/syscalls.h dietlibc/parisc/syscalls.h
4373--- dietlibc-0.31/parisc/syscalls.h 2006-04-04 05:10:40.000000000 +0200
4374+++ dietlibc/parisc/syscalls.h 2008-09-30 23:02:35.000000000 +0200
4375@@ -277,8 +277,54 @@
4376 #define __NR_mbind (__NR_Linux + 260)
4377 #define __NR_get_mempolicy (__NR_Linux + 261)
4378 #define __NR_set_mempolicy (__NR_Linux + 262)
4379+#define __NR_vserver (__NR_Linux + 263)
4380+#define __NR_add_key (__NR_Linux + 264)
4381+#define __NR_request_key (__NR_Linux + 265)
4382+#define __NR_keyctl (__NR_Linux + 266)
4383+#define __NR_ioprio_set (__NR_Linux + 267)
4384+#define __NR_ioprio_get (__NR_Linux + 268)
4385+#define __NR_inotify_init (__NR_Linux + 269)
4386+#define __NR_inotify_add_watch (__NR_Linux + 270)
4387+#define __NR_inotify_rm_watch (__NR_Linux + 271)
4388+#define __NR_migrate_pages (__NR_Linux + 272)
4389+#define __NR_pselect6 (__NR_Linux + 273)
4390+#define __NR_ppoll (__NR_Linux + 274)
4391+#define __NR_openat (__NR_Linux + 275)
4392+#define __NR_mkdirat (__NR_Linux + 276)
4393+#define __NR_mknodat (__NR_Linux + 277)
4394+#define __NR_fchownat (__NR_Linux + 278)
4395+#define __NR_futimesat (__NR_Linux + 279)
4396+#define __NR_fstatat64 (__NR_Linux + 280)
4397+#define __NR_unlinkat (__NR_Linux + 281)
4398+#define __NR_renameat (__NR_Linux + 282)
4399+#define __NR_linkat (__NR_Linux + 283)
4400+#define __NR_symlinkat (__NR_Linux + 284)
4401+#define __NR_readlinkat (__NR_Linux + 285)
4402+#define __NR_fchmodat (__NR_Linux + 286)
4403+#define __NR_faccessat (__NR_Linux + 287)
4404+#define __NR_unshare (__NR_Linux + 288)
4405+#define __NR_set_robust_list (__NR_Linux + 289)
4406+#define __NR_get_robust_list (__NR_Linux + 290)
4407+#define __NR_splice (__NR_Linux + 291)
4408+#define __NR_sync_file_range (__NR_Linux + 292)
4409+#define __NR_tee (__NR_Linux + 293)
4410+#define __NR_vmsplice (__NR_Linux + 294)
4411+#define __NR_move_pages (__NR_Linux + 295)
4412+#define __NR_getcpu (__NR_Linux + 296)
4413+#define __NR_epoll_pwait (__NR_Linux + 297)
4414+#define __NR_statfs64 (__NR_Linux + 298)
4415+#define __NR_fstatfs64 (__NR_Linux + 299)
4416+#define __NR_kexec_load (__NR_Linux + 300)
4417+#define __NR_utimensat (__NR_Linux + 301)
4418+#define __NR_signalfd (__NR_Linux + 302)
4419+#define __NR_timerfd (__NR_Linux + 303)
4420+#define __NR_eventfd (__NR_Linux + 304)
4421+#define __NR_fallocate (__NR_Linux + 305)
4422+#define __NR_timerfd_create (__NR_Linux + 306)
4423+#define __NR_timerfd_settime (__NR_Linux + 307)
4424+#define __NR_timerfd_gettime (__NR_Linux + 308)
4425
4426-#define __NR_Linux_syscalls 263
4427+#define __NR_Linux_syscalls (__NR_fallocate + 1)
4428
4429 #define LINUX_GATEWAY_ADDR 0x100
4430
4431diff -urN -x CVS dietlibc-0.31/ppc/syscalls.h dietlibc/ppc/syscalls.h
4432--- dietlibc-0.31/ppc/syscalls.h 2006-09-19 00:08:39.000000000 +0200
4433+++ dietlibc/ppc/syscalls.h 2008-09-30 23:02:35.000000000 +0200
4434@@ -299,6 +299,18 @@
4435 #define __NR_faccessat 298
4436 #define __NR_get_robust_list 299
4437 #define __NR_set_robust_list 300
4438+#define __NR_move_pages 301
4439+#define __NR_getcpu 302
4440+#define __NR_epoll_pwait 303
4441+#define __NR_utimensat 304
4442+#define __NR_signalfd 305
4443+#define __NR_timerfd 306
4444+#define __NR_eventfd 307
4445+#define __NR_sync_file_range2 308
4446+#define __NR_fallocate 309
4447+#define __NR_subpage_prot 310
4448+#define __NR_timerfd_settime 311
4449+#define __NR_timerfd_gettime 312
4450
4451
4452 #define syscall_weak(name,wsym,sym) \
4453diff -urN -x CVS dietlibc-0.31/ppc64/syscalls.h dietlibc/ppc64/syscalls.h
4454--- dietlibc-0.31/ppc64/syscalls.h 2006-09-19 00:08:39.000000000 +0200
4455+++ dietlibc/ppc64/syscalls.h 2008-09-30 23:02:35.000000000 +0200
4456@@ -299,7 +299,18 @@
4457 #define __NR_faccessat 298
4458 #define __NR_get_robust_list 299
4459 #define __NR_set_robust_list 300
4460-
4461+#define __NR_move_pages 301
4462+#define __NR_getcpu 302
4463+#define __NR_epoll_pwait 303
4464+#define __NR_utimensat 304
4465+#define __NR_signalfd 305
4466+#define __NR_timerfd 306
4467+#define __NR_eventfd 307
4468+#define __NR_sync_file_range2 308
4469+#define __NR_fallocate 309
4470+#define __NR_subpage_prot 310
4471+#define __NR_timerfd_settime 311
4472+#define __NR_timerfd_gettime 312
4473
4474
4475 #define __diet_proto_common(sym) \
4476diff -urN -x CVS dietlibc-0.31/s390/syscalls.h dietlibc/s390/syscalls.h
4477--- dietlibc-0.31/s390/syscalls.h 2006-09-19 00:08:39.000000000 +0200
4478+++ dietlibc/s390/syscalls.h 2008-09-30 23:02:35.000000000 +0200
4479@@ -293,6 +293,18 @@
4480 #define __NR_sync_file_range 307
4481 #define __NR_tee 308
4482 #define __NR_vmsplice 309
4483+/* Number 310 is reserved for new sys_move_pages */
4484+#define __NR_getcpu 311
4485+#define __NR_epoll_pwait 312
4486+#define __NR_utimes 313
4487+#define __NR_fallocate 314
4488+#define __NR_utimensat 315
4489+#define __NR_signalfd 316
4490+#define __NR_timerfd 317
4491+#define __NR_eventfd 318
4492+#define __NR_timerfd_create 319
4493+#define __NR_timerfd_settime 320
4494+#define __NR_timerfd_gettime 321
4495
4496
4497 #define syscall_weak(name,wsym,sym) \
4498diff -urN -x CVS dietlibc-0.31/s390x/syscalls.h dietlibc/s390x/syscalls.h
4499--- dietlibc-0.31/s390x/syscalls.h 2006-09-19 00:08:39.000000000 +0200
4500+++ dietlibc/s390x/syscalls.h 2008-09-30 23:02:35.000000000 +0200
4501@@ -293,6 +293,18 @@
4502 #define __NR_sync_file_range 307
4503 #define __NR_tee 308
4504 #define __NR_vmsplice 309
4505+/* Number 310 is reserved for new sys_move_pages */
4506+#define __NR_getcpu 311
4507+#define __NR_epoll_pwait 312
4508+#define __NR_utimes 313
4509+#define __NR_fallocate 314
4510+#define __NR_utimensat 315
4511+#define __NR_signalfd 316
4512+#define __NR_timerfd 317
4513+#define __NR_eventfd 318
4514+#define __NR_timerfd_create 319
4515+#define __NR_timerfd_settime 320
4516+#define __NR_timerfd_gettime 321
4517
4518
4519 /*
4520diff -urN -x CVS dietlibc-0.31/sparc/syscalls.h dietlibc/sparc/syscalls.h
4521--- dietlibc-0.31/sparc/syscalls.h 2006-09-19 00:08:39.000000000 +0200
4522+++ dietlibc/sparc/syscalls.h 2008-09-30 23:02:35.000000000 +0200
4523@@ -300,6 +300,21 @@
4524 #define __NR_unshare 299
4525 #define __NR_set_robust_list 300
4526 #define __NR_get_robust_list 301
4527+#define __NR_migrate_pages 302
4528+#define __NR_mbind 303
4529+#define __NR_get_mempolicy 304
4530+#define __NR_set_mempolicy 305
4531+#define __NR_kexec_load 306
4532+#define __NR_move_pages 307
4533+#define __NR_getcpu 308
4534+#define __NR_epoll_pwait 309
4535+#define __NR_utimensat 310
4536+#define __NR_signalfd 311
4537+#define __NR_timerfd 312
4538+#define __NR_eventfd 313
4539+#define __NR_fallocate 314
4540+#define __NR_timerfd_settime 315
4541+#define __NR_timerfd_gettime 316
4542
4543 #define syscall_weak(name,wsym,sym) \
4544 .text; \
4545diff -urN -x CVS dietlibc-0.31/sparc64/syscalls.h dietlibc/sparc64/syscalls.h
4546--- dietlibc-0.31/sparc64/syscalls.h 2006-09-19 00:08:39.000000000 +0200
4547+++ dietlibc/sparc64/syscalls.h 2008-09-30 23:02:35.000000000 +0200
4548@@ -299,6 +299,21 @@
4549 #define __NR_unshare 299
4550 #define __NR_set_robust_list 300
4551 #define __NR_get_robust_list 301
4552+#define __NR_migrate_pages 302
4553+#define __NR_mbind 303
4554+#define __NR_get_mempolicy 304
4555+#define __NR_set_mempolicy 305
4556+#define __NR_kexec_load 306
4557+#define __NR_move_pages 307
4558+#define __NR_getcpu 308
4559+#define __NR_epoll_pwait 309
4560+#define __NR_utimensat 310
4561+#define __NR_signalfd 311
4562+#define __NR_timerfd 312
4563+#define __NR_eventfd 313
4564+#define __NR_fallocate 314
4565+#define __NR_timerfd_settime 315
4566+#define __NR_timerfd_gettime 316
4567
4568 #define syscall_weak(name,wsym,sym) \
4569 .text; \
4570diff -urN -x CVS dietlibc-0.31/syscalls.s/__signalfd.S dietlibc/syscalls.s/__signalfd.S
4571--- dietlibc-0.31/syscalls.s/__signalfd.S 1970-01-01 01:00:00.000000000 +0100
4572+++ dietlibc/syscalls.s/__signalfd.S 2008-02-19 01:28:13.000000000 +0100
4573@@ -0,0 +1,5 @@
4574+#include "syscalls.h"
4575+
4576+#ifdef __NR_signalfd
4577+syscall(signalfd,__signalfd)
4578+#endif
4579diff -urN -x CVS dietlibc-0.31/syscalls.s/splice.S dietlibc/syscalls.s/splice.S
4580--- dietlibc-0.31/syscalls.s/splice.S 1970-01-01 01:00:00.000000000 +0100
4581+++ dietlibc/syscalls.s/splice.S 2008-02-19 01:28:13.000000000 +0100
4582@@ -0,0 +1,5 @@
4583+#include "syscalls.h"
4584+
4585+#ifdef __NR_splice
4586+syscall(splice,splice)
4587+#endif
4588diff -urN -x CVS dietlibc-0.31/syscalls.s/tee.S dietlibc/syscalls.s/tee.S
4589--- dietlibc-0.31/syscalls.s/tee.S 1970-01-01 01:00:00.000000000 +0100
4590+++ dietlibc/syscalls.s/tee.S 2008-02-19 01:28:13.000000000 +0100
4591@@ -0,0 +1,5 @@
4592+#include "syscalls.h"
4593+
4594+#ifdef __NR_tee
4595+syscall(tee,tee)
4596+#endif
4597diff -urN -x CVS dietlibc-0.31/syscalls.s/timerfd.S dietlibc/syscalls.s/timerfd.S
4598--- dietlibc-0.31/syscalls.s/timerfd.S 1970-01-01 01:00:00.000000000 +0100
4599+++ dietlibc/syscalls.s/timerfd.S 2008-02-19 01:28:13.000000000 +0100
4600@@ -0,0 +1,5 @@
4601+#include "syscalls.h"
4602+
4603+#ifdef __NR_timerfd
4604+syscall(timerfd,__timerfd)
4605+#endif
4606diff -urN -x CVS dietlibc-0.31/syscalls.s/vmsplice.S dietlibc/syscalls.s/vmsplice.S
4607--- dietlibc-0.31/syscalls.s/vmsplice.S 1970-01-01 01:00:00.000000000 +0100
4608+++ dietlibc/syscalls.s/vmsplice.S 2008-02-19 01:28:13.000000000 +0100
4609@@ -0,0 +1,5 @@
4610+#include "syscalls.h"
4611+
4612+#ifdef __NR_vmsplice
4613+syscall(vmsplice,vmsplice)
4614+#endif
4615diff -urN -x CVS dietlibc-0.31/t.c dietlibc/t.c
4616--- dietlibc-0.31/t.c 2005-10-08 23:11:32.000000000 +0200
4617+++ dietlibc/t.c 2009-02-26 21:51:54.000000000 +0100
4618@@ -105,12 +105,22 @@
4619 #define rdtscl(low) \
4620 __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
4621
4622+#define malloc(x) ({typeof(x) y=x; (y<0 || (size_t)(y)!=y ? 0 : malloc(y));})
4623+
4624 int main(int argc,char *argv[]) {
4625+#if 0
4626+ char* a=malloc(-3);
4627+ char* b=malloc(0xffffffffull+1);
4628+ printf("%p %p\n",a,b);
4629+#endif
4630+ printf("%u\n",getpagesize());
4631+#if 0
4632 struct stat s;
4633 time_t t=time(0);
4634 struct tm* T;
4635 stat("/tmp/nyt.html",&s);
4636 T=gmtime(&s.st_mtime);
4637+#endif
4638 #if 0
4639 static struct mq_attr x;
4640 mqd_t a=mq_open("fnord",O_WRONLY|O_CREAT,0600,&x);
4641diff -urN -x CVS dietlibc-0.31/test/Makefile dietlibc/test/Makefile
4642--- dietlibc-0.31/test/Makefile 2003-12-15 14:07:42.000000000 +0100
4643+++ dietlibc/test/Makefile 2008-02-23 01:02:19.000000000 +0100
4644@@ -11,9 +11,9 @@
4645 fputc ftw fwrite getaddrinfo getenv getgrnam gethostbyaddr gethostbyname \
4646 gethostbyname_r getmntent getopt getpass getpwnam getservbyname getservbyport getusershell \
4647 glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness \
4648-memccpy memchr memcmp memcpy memrchr memusage mktime mmap_test pipe printf printftest \
4649+memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest \
4650 protoent prototypes putenv pwent rand48 read1 readdir regex select sendfile servent siglist \
4651-speed spent sprintf sscanf stdarg strcasecmp strcmp strlen strncat strncpy strptime strrchr \
4652+speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr \
4653 strstr strtol sysenter ungetc waitpid
4654
4655 test: $(TESTPROGRAMS)
4656diff -urN -x CVS dietlibc-0.31/test/mbrlen.c dietlibc/test/mbrlen.c
4657--- dietlibc-0.31/test/mbrlen.c 1970-01-01 01:00:00.000000000 +0100
4658+++ dietlibc/test/mbrlen.c 2008-09-30 23:02:35.000000000 +0200
4659@@ -0,0 +1,18 @@
4660+#include <wchar.h>
4661+#include <assert.h>
4662+#include <stdio.h>
4663+#include <locale.h>
4664+
4665+main() {
4666+ static mbstate_t ps;
4667+ setlocale(LC_CTYPE,"de_DE.UTF8");
4668+ /* does it parse a single multibyte sequence OK? */
4669+ assert(mbrlen("\xc2\xa9",2,&ps)==2);
4670+ /* does it whine about an invalid sequence? */
4671+ assert(mbrlen("\xa9",1,&ps)==(size_t)-1);
4672+ /* does it accept a multibyte sequence in two parts? */
4673+ printf("%d\n",mbrlen("\xc2\xa9",1,&ps));
4674+ printf("%d\n",mbrlen("\xa9""fnord",6,&ps));
4675+ /* does it parse non-sequence stuff right? */
4676+ assert(mbrlen("f",1,&ps)==1);
4677+}
4678diff -urN -x CVS dietlibc-0.31/test/mbtowc.c dietlibc/test/mbtowc.c
4679--- dietlibc-0.31/test/mbtowc.c 1970-01-01 01:00:00.000000000 +0100
4680+++ dietlibc/test/mbtowc.c 2007-09-09 03:37:54.000000000 +0200
4681@@ -0,0 +1,28 @@
4682+#include <stdlib.h>
4683+#include <wchar.h>
4684+#include <stdio.h>
4685+#include <locale.h>
4686+#include <string.h>
4687+#include <assert.h>
4688+#include <errno.h>
4689+
4690+int main() {
4691+ wchar_t ws;
4692+ char* c="fn\xc3\xb6rd";
4693+ size_t n=strlen(c);
4694+ setlocale(LC_CTYPE,"de_DE.UTF8");
4695+
4696+ ws=0;
4697+ assert(mbtowc(&ws,c,6)==1 && ws==102);
4698+ assert(mbtowc(&ws,c+1,5)==1 && ws==110);
4699+ assert(mbtowc(&ws,c+2,4)==2 && ws==246);
4700+ assert(mbtowc(&ws,c+4,2)==1 && ws==114);
4701+ assert(mbtowc(&ws,c+5,1)==1 && ws==100);
4702+ assert(mbtowc(&ws,c+6,1)==0);
4703+
4704+ errno=0;
4705