summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--extra/Configs/Config.in14
-rw-r--r--libc/inet/if_nametoindex.c189
-rw-r--r--libc/misc/assert/__assert.c6
-rw-r--r--libc/misc/ctype/Makefile.in4
-rw-r--r--libc/misc/ctype/ctype.c72
-rw-r--r--libc/misc/dirent/Makefile.in7
-rw-r--r--libc/misc/dirent/alphasort64.c4
-rw-r--r--libc/misc/dirent/dirstream.h2
-rw-r--r--libc/misc/dirent/opendir.c4
-rw-r--r--libc/misc/dirent/readdir.c6
-rw-r--r--libc/misc/dirent/readdir64.c8
-rw-r--r--libc/misc/dirent/readdir64_r.c5
-rw-r--r--libc/misc/dirent/rewinddir.c2
-rw-r--r--libc/misc/dirent/scandir.c2
-rw-r--r--libc/misc/dirent/scandir64.c6
-rw-r--r--libc/misc/dirent/seekdir.c2
-rw-r--r--libc/misc/error/err.c8
-rw-r--r--libc/misc/error/error.c10
-rw-r--r--libc/misc/file/lockf.c11
-rw-r--r--libc/misc/file/lockf64.c10
-rw-r--r--libc/misc/fnmatch/Makefile.in16
-rw-r--r--libc/misc/fnmatch/fnmatch.c607
-rw-r--r--libc/misc/fnmatch/fnmatch_loop.c1209
-rw-r--r--libc/misc/fnmatch/fnmatch_old.c224
-rw-r--r--libc/misc/ftw/Makefile.in37
-rw-r--r--libc/misc/ftw/ftw.c1031
-rw-r--r--libc/misc/glob/glob.c54
-rw-r--r--libc/misc/glob/glob64.c14
-rw-r--r--libc/misc/gnu/obstack.c2
-rw-r--r--libc/misc/internals/__uClibc_main.c50
-rw-r--r--libc/misc/internals/errno.c4
-rw-r--r--libc/misc/internals/tempname.c4
-rw-r--r--libc/misc/locale/locale.c22
-rw-r--r--libc/misc/mntent/mntent.c2
-rw-r--r--libc/misc/pthread/Makefile.in21
-rw-r--r--libc/misc/pthread/weaks.c102
-rw-r--r--libc/misc/regex/regcomp.c9
-rw-r--r--libc/misc/regex/regex.c3
-rw-r--r--libc/misc/regex/regex_internal.c4
-rw-r--r--libc/misc/regex/regex_internal.h2
-rw-r--r--libc/misc/regex/regex_old.c40
-rw-r--r--libc/misc/statfs/fstatfs64.c9
-rw-r--r--libc/misc/statfs/fstatvfs.c6
-rw-r--r--libc/misc/statfs/fstatvfs64.c6
-rw-r--r--libc/misc/statfs/internal_statvfs.c10
-rw-r--r--libc/misc/statfs/statfs64.c10
-rw-r--r--libc/misc/statfs/statvfs.c7
-rw-r--r--libc/misc/statfs/statvfs64.c6
-rw-r--r--libc/misc/syslog/syslog.c2
-rw-r--r--libc/misc/sysvipc/ftok.c2
-rw-r--r--libc/misc/time/time.c2
-rw-r--r--libc/misc/ttyent/getttyent.c5
-rw-r--r--libc/misc/utmp/utent.c12
-rw-r--r--libc/misc/utmp/wtent.c4
-rw-r--r--libc/misc/wchar/wchar.c13
-rw-r--r--libc/misc/wchar/wstdio.c3
-rw-r--r--libc/misc/wctype/wctype.c79
-rw-r--r--libc/misc/wordexp/wordexp.c32
-rw-r--r--libc/pwd_grp/lckpwdf.c6
-rw-r--r--libc/pwd_grp/pwd_grp.c7
-rw-r--r--libc/stdio/_READ.c2
-rw-r--r--libc/stdio/_WRITE.c2
-rw-r--r--libc/stdio/_cs_funcs.c8
-rw-r--r--libc/stdio/_fopen.c2
-rw-r--r--libc/stdio/_stdio.c4
-rw-r--r--libc/stdio/_stdio.h1
-rw-r--r--libc/stdio/_trans2w.c2
-rw-r--r--libc/stdio/clearerr.c4
-rw-r--r--libc/stdio/fclose.c2
-rw-r--r--libc/stdio/fdopen.c2
-rw-r--r--libc/stdio/feof.c4
-rw-r--r--libc/stdio/ferror.c4
-rw-r--r--libc/stdio/fflush.c8
-rw-r--r--libc/stdio/fgetc.c8
-rw-r--r--libc/stdio/fgets.c8
-rw-r--r--libc/stdio/fgetwc.c15
-rw-r--r--libc/stdio/fgetws.c4
-rw-r--r--libc/stdio/fileno.c6
-rw-r--r--libc/stdio/fopen.c8
-rw-r--r--libc/stdio/fopen64.c2
-rw-r--r--libc/stdio/fputc.c9
-rw-r--r--libc/stdio/fputs.c8
-rw-r--r--libc/stdio/fputwc.c10
-rw-r--r--libc/stdio/fputws.c10
-rw-r--r--libc/stdio/fseeko.c6
-rw-r--r--libc/stdio/fsetpos.c8
-rw-r--r--libc/stdio/fsetpos64.c2
-rw-r--r--libc/stdio/getchar.c4
-rw-r--r--libc/stdio/getwchar.c8
-rw-r--r--libc/stdio/old_vfprintf.c4
-rw-r--r--libc/stdio/popen.c4
-rw-r--r--libc/stdio/putchar.c4
-rw-r--r--libc/stdio/putwchar.c8
-rw-r--r--libc/stdio/remove.c3
-rw-r--r--libc/stdio/rewind.c2
-rw-r--r--libc/stdio/scanf.c4
-rw-r--r--libc/stdio/tmpfile.c3
-rw-r--r--libc/stdio/vfprintf.c1
-rw-r--r--libc/stdlib/abort.c14
-rw-r--r--libc/stdlib/atexit.c11
-rw-r--r--libc/stdlib/ldiv.c3
-rw-r--r--libc/stdlib/lldiv.c3
-rw-r--r--libc/stdlib/malloc-standard/free.c2
-rw-r--r--libc/stdlib/malloc-standard/mallinfo.c2
-rw-r--r--libc/stdlib/malloc-standard/malloc.h3
-rw-r--r--libc/stdlib/malloc/Makefile.in2
-rw-r--r--libc/stdlib/malloc/free.c1
-rw-r--r--libc/stdlib/malloc/heap_debug.c4
-rw-r--r--libc/stdlib/malloc/malloc.c1
-rw-r--r--libc/stdlib/malloc/malloc.h2
-rw-r--r--libc/stdlib/malloc/malloc_debug.c4
-rw-r--r--libc/stdlib/ptsname.c4
-rw-r--r--libc/stdlib/setenv.c3
-rw-r--r--libc/stdlib/stdlib.c5
-rw-r--r--libc/stdlib/system.c4
-rw-r--r--libc/stdlib/unix_grantpt.c11
-rw-r--r--libc/string/Makefile.in117
-rw-r--r--libc/string/__glibc_strerror_r.c19
-rw-r--r--libc/string/__xpg_basename.c35
-rw-r--r--libc/string/__xpg_strerror_r.c273
-rw-r--r--libc/string/_collate.c686
-rw-r--r--libc/string/_string.h33
-rw-r--r--libc/string/_string_syserrmsgs.c146
-rw-r--r--libc/string/_string_syssigmsgs.c50
-rw-r--r--libc/string/_syserrmsg.h35
-rw-r--r--libc/string/arm/_memcpy.S1
-rw-r--r--libc/string/arm/bcopy.S6
-rw-r--r--libc/string/arm/bzero.S7
-rw-r--r--libc/string/arm/memcmp.S7
-rw-r--r--libc/string/arm/memcpy.S8
-rw-r--r--libc/string/arm/memmove.S8
-rw-r--r--libc/string/arm/memset.S5
-rw-r--r--libc/string/arm/strcmp.S8
-rw-r--r--libc/string/arm/strlen.S5
-rw-r--r--libc/string/arm/strncmp.S6
-rw-r--r--libc/string/basename.c26
-rw-r--r--libc/string/bcopy.c53
-rw-r--r--libc/string/bzero.c31
-rw-r--r--libc/string/dirname.c43
-rw-r--r--libc/string/ffs.c54
-rw-r--r--libc/string/frv/memcpy.S5
-rw-r--r--libc/string/frv/memset.S5
-rw-r--r--libc/string/generic/memchr.c4
-rw-r--r--libc/string/generic/memcmp.c6
-rw-r--r--libc/string/generic/memcpy.c4
-rw-r--r--libc/string/generic/memmem.c4
-rw-r--r--libc/string/generic/memmove.c4
-rw-r--r--libc/string/generic/mempcpy.c2
-rw-r--r--libc/string/generic/memrchr.c4
-rw-r--r--libc/string/generic/memset.c4
-rw-r--r--libc/string/generic/rawmemchr.c4
-rw-r--r--libc/string/generic/strcat.c4
-rw-r--r--libc/string/generic/strchr.c6
-rw-r--r--libc/string/generic/strchrnul.c4
-rw-r--r--libc/string/generic/strcmp.c13
-rw-r--r--libc/string/generic/strcpy.c4
-rw-r--r--libc/string/generic/strcspn.c4
-rw-r--r--libc/string/generic/strlen.c4
-rw-r--r--libc/string/generic/strncat.c4
-rw-r--r--libc/string/generic/strncmp.c4
-rw-r--r--libc/string/generic/strncpy.c4
-rw-r--r--libc/string/generic/strnlen.c4
-rw-r--r--libc/string/generic/strrchr.c6
-rw-r--r--libc/string/generic/strsep.c4
-rw-r--r--libc/string/generic/strspn.c4
-rw-r--r--libc/string/generic/strstr.c4
-rw-r--r--libc/string/generic/strtok_r.c14
-rw-r--r--libc/string/i386/memchr.c3
-rw-r--r--libc/string/i386/memcpy.c3
-rw-r--r--libc/string/i386/memmove.c3
-rw-r--r--libc/string/i386/memset.c3
-rw-r--r--libc/string/i386/strcat.c3
-rw-r--r--libc/string/i386/strchr.c5
-rw-r--r--libc/string/i386/strcmp.c12
-rw-r--r--libc/string/i386/strcpy.c3
-rw-r--r--libc/string/i386/strlen.c3
-rw-r--r--libc/string/i386/strncat.c3
-rw-r--r--libc/string/i386/strncmp.c3
-rw-r--r--libc/string/i386/strncpy.c3
-rw-r--r--libc/string/i386/strnlen.c3
-rw-r--r--libc/string/i386/strrchr.c5
-rw-r--r--libc/string/memccpy.c22
-rw-r--r--libc/string/memchr.c36
-rw-r--r--libc/string/memcmp.c39
-rw-r--r--libc/string/memcpy.c33
-rw-r--r--libc/string/memmem.c40
-rw-r--r--libc/string/memmove.c53
-rw-r--r--libc/string/mempcpy.c33
-rw-r--r--libc/string/memrchr.c33
-rw-r--r--libc/string/memset.c33
-rw-r--r--libc/string/mips/memcpy.S8
-rw-r--r--libc/string/mips/memset.S8
-rw-r--r--libc/string/mips/sysdep.h7
-rw-r--r--libc/string/powerpc/memcpy.c3
-rw-r--r--libc/string/powerpc/memmove.c3
-rw-r--r--libc/string/powerpc/memset.c3
-rw-r--r--libc/string/psignal.c30
-rw-r--r--libc/string/rawmemchr.c19
-rw-r--r--libc/string/sh64/memcpy.S8
-rw-r--r--libc/string/sh64/memset.S9
-rw-r--r--libc/string/sh64/strcpy.S13
-rw-r--r--libc/string/sh64/strlen.S6
-rw-r--r--libc/string/sparc/_glibc_inc.h6
-rw-r--r--libc/string/sparc/sparc32/memchr.S6
-rw-r--r--libc/string/sparc/sparc32/memcpy.S12
-rw-r--r--libc/string/sparc/sparc32/memset.S7
-rw-r--r--libc/string/sparc/sparc32/stpcpy.S5
-rw-r--r--libc/string/sparc/sparc32/strcat.S5
-rw-r--r--libc/string/sparc/sparc32/strchr.S13
-rw-r--r--libc/string/sparc/sparc32/strcmp.S5
-rw-r--r--libc/string/sparc/sparc32/strcpy.S5
-rw-r--r--libc/string/sparc/sparc32/strlen.S5
-rw-r--r--libc/string/sparc/sparc64/memchr.S4
-rw-r--r--libc/string/sparc/sparc64/memcpy.S16
-rw-r--r--libc/string/sparc/sparc64/memset.S7
-rw-r--r--libc/string/sparc/sparc64/sparcv9b/memcpy.S22
-rw-r--r--libc/string/sparc/sparc64/stpcpy.S2
-rw-r--r--libc/string/sparc/sparc64/strcat.S5
-rw-r--r--libc/string/sparc/sparc64/strchr.S13
-rw-r--r--libc/string/sparc/sparc64/strcmp.S5
-rw-r--r--libc/string/sparc/sparc64/strcpy.S5
-rw-r--r--libc/string/sparc/sparc64/strlen.S5
-rw-r--r--libc/string/stpcpy.c27
-rw-r--r--libc/string/stpncpy.c37
-rw-r--r--libc/string/strcasecmp.c75
-rw-r--r--libc/string/strcasecmp_l.c8
-rw-r--r--libc/string/strcasestr.c51
-rw-r--r--libc/string/strcat.c25
-rw-r--r--libc/string/strchr.c29
-rw-r--r--libc/string/strchrnul.c21
-rw-r--r--libc/string/strcmp.c46
-rw-r--r--libc/string/strcpy.c29
-rw-r--r--libc/string/strcspn.c28
-rw-r--r--libc/string/strdup.c33
-rw-r--r--libc/string/strerror.c21
-rw-r--r--libc/string/strlcat.c46
-rw-r--r--libc/string/strlcpy.c55
-rw-r--r--libc/string/strlen.c23
-rw-r--r--libc/string/strncasecmp.c78
-rw-r--r--libc/string/strncasecmp_l.c8
-rw-r--r--libc/string/strncat.c34
-rw-r--r--libc/string/strncmp.c38
-rw-r--r--libc/string/strncpy.c35
-rw-r--r--libc/string/strndup.c25
-rw-r--r--libc/string/strnlen.c33
-rw-r--r--libc/string/strpbrk.c27
-rw-r--r--libc/string/strrchr.c31
-rw-r--r--libc/string/strsep.c31
-rw-r--r--libc/string/strspn.c28
-rw-r--r--libc/string/strstr.c41
-rw-r--r--libc/string/strtok.c22
-rw-r--r--libc/string/strtok_r.c54
-rw-r--r--libc/string/strxfrm.c9
-rw-r--r--libc/string/strxfrm_l.c10
-rw-r--r--libc/string/sys_errlist.c171
-rw-r--r--libc/string/sys_siglist.c57
-rw-r--r--libc/string/wcpcpy.c9
-rw-r--r--libc/string/wcpncpy.c9
-rw-r--r--libc/string/wcscasecmp.c8
-rw-r--r--libc/string/wcscasecmp_l.c9
-rw-r--r--libc/string/wcscat.c9
-rw-r--r--libc/string/wcschr.c9
-rw-r--r--libc/string/wcschrnul.c9
-rw-r--r--libc/string/wcscmp.c14
-rw-r--r--libc/string/wcscpy.c9
-rw-r--r--libc/string/wcscspn.c9
-rw-r--r--libc/string/wcsdup.c14
-rw-r--r--libc/string/wcslcpy.c11
-rw-r--r--libc/string/wcslen.c9
-rw-r--r--libc/string/wcsncasecmp.c8
-rw-r--r--libc/string/wcsncasecmp_l.c9
-rw-r--r--libc/string/wcsncat.c9
-rw-r--r--libc/string/wcsncmp.c9
-rw-r--r--libc/string/wcsncpy.c9
-rw-r--r--libc/string/wcsnlen.c9
-rw-r--r--libc/string/wcspbrk.c9
-rw-r--r--libc/string/wcsrchr.c9
-rw-r--r--libc/string/wcsspn.c9
-rw-r--r--libc/string/wcsstr.c11
-rw-r--r--libc/string/wcstok.c14
-rw-r--r--libc/string/wcsxfrm.c9
-rw-r--r--libc/string/wcsxfrm_l.c10
-rw-r--r--libc/string/wmemchr.c9
-rw-r--r--libc/string/wmemcmp.c9
-rw-r--r--libc/string/wmemcpy.c9
-rw-r--r--libc/string/wmemmove.c9
-rw-r--r--libc/string/wmempcpy.c9
-rw-r--r--libc/string/wmemset.c9
-rw-r--r--libc/string/wstring.c3246
-rw-r--r--libc/string/x86_64/_glibc_inc.h6
-rw-r--r--libc/string/x86_64/bzero.S4
-rw-r--r--libc/string/x86_64/memcpy.S8
-rw-r--r--libc/string/x86_64/mempcpy.S3
-rw-r--r--libc/string/x86_64/memset.S8
-rw-r--r--libc/string/x86_64/stpcpy.S4
-rw-r--r--libc/string/x86_64/strcat.S5
-rw-r--r--libc/string/x86_64/strchr.S6
-rw-r--r--libc/string/x86_64/strcmp.S5
-rw-r--r--libc/string/x86_64/strcpy.S6
-rw-r--r--libc/string/x86_64/strcspn.S10
-rw-r--r--libc/string/x86_64/strlen.S5
-rw-r--r--libc/string/x86_64/strpbrk.S4
-rw-r--r--libc/string/x86_64/strspn.S5
-rw-r--r--libc/sysdeps/linux/alpha/brk.S1
-rw-r--r--libc/sysdeps/linux/alpha/clone.S2
-rw-r--r--libc/sysdeps/linux/arm/brk.c3
-rw-r--r--libc/sysdeps/linux/arm/clone.S6
-rw-r--r--libc/sysdeps/linux/arm/ioperm.c1
-rw-r--r--libc/sysdeps/linux/arm/vfork.S15
-rw-r--r--libc/sysdeps/linux/bfin/Makefile58
-rw-r--r--libc/sysdeps/linux/bfin/Makefile.arch12
-rw-r--r--libc/sysdeps/linux/bfin/bits/syscalls.h134
-rw-r--r--libc/sysdeps/linux/bfin/bits/uClibc_page.h29
-rw-r--r--libc/sysdeps/linux/bfin/brk.c3
-rw-r--r--libc/sysdeps/linux/cris/brk.c3
-rw-r--r--libc/sysdeps/linux/cris/clone.S2
-rw-r--r--libc/sysdeps/linux/cris/fork.c3
-rw-r--r--libc/sysdeps/linux/cris/sbrk.c5
-rw-r--r--libc/sysdeps/linux/frv/__init_brk.c2
-rw-r--r--libc/sysdeps/linux/frv/brk.c5
-rw-r--r--libc/sysdeps/linux/frv/clone.S2
-rw-r--r--libc/sysdeps/linux/frv/sbrk.c7
-rw-r--r--libc/sysdeps/linux/frv/vfork.S12
-rw-r--r--libc/sysdeps/linux/h8300/brk.c3
-rw-r--r--libc/sysdeps/linux/hppa/brk.c5
-rw-r--r--libc/sysdeps/linux/hppa/clone.S2
-rw-r--r--libc/sysdeps/linux/i386/bits/syscalls.h12
-rw-r--r--libc/sysdeps/linux/i386/brk.c4
-rw-r--r--libc/sysdeps/linux/i386/vfork.S9
-rw-r--r--libc/sysdeps/linux/m68k/Makefile.arch2
-rw-r--r--libc/sysdeps/linux/m68k/brk.c3
-rw-r--r--libc/sysdeps/linux/m68k/vfork.S15
-rw-r--r--libc/sysdeps/linux/nios/Makefile59
-rw-r--r--libc/sysdeps/linux/nios/Makefile.arch14
-rw-r--r--libc/sysdeps/linux/nios/brk.c4
-rw-r--r--libc/sysdeps/linux/nios/crt0.c73
-rw-r--r--libc/sysdeps/linux/nios/crt1.S (renamed from libc/sysdeps/linux/nios/crt0.S)18
-rw-r--r--libc/sysdeps/linux/nios2/Makefile74
-rw-r--r--libc/sysdeps/linux/nios2/Makefile.arch14
-rw-r--r--libc/sysdeps/linux/nios2/brk.c3
-rw-r--r--libc/sysdeps/linux/nios2/crt1.S (renamed from libc/sysdeps/linux/nios2/crt0.S)28
-rw-r--r--libc/sysdeps/linux/powerpc/brk.S1
-rw-r--r--libc/sysdeps/linux/powerpc/clone.S6
-rw-r--r--libc/sysdeps/linux/powerpc/crt1.S3
-rw-r--r--libc/sysdeps/linux/powerpc/pread_write.c12
-rw-r--r--libc/sysdeps/linux/powerpc/vfork.S9
-rw-r--r--libc/sysdeps/linux/powerpc/vfork.c4
-rw-r--r--libc/sysdeps/linux/sh/__init_brk.c2
-rw-r--r--libc/sysdeps/linux/sh/bits/kernel_stat.h8
-rw-r--r--libc/sysdeps/linux/sh/brk.c5
-rw-r--r--libc/sysdeps/linux/sh/clone.S2
-rw-r--r--libc/sysdeps/linux/sh/sbrk.c7
-rw-r--r--libc/sysdeps/linux/sh/vfork.S12
-rw-r--r--libc/sysdeps/linux/sh64/__init_brk.c2
-rw-r--r--libc/sysdeps/linux/sh64/brk.c5
-rw-r--r--libc/sysdeps/linux/sh64/sbrk.c7
-rw-r--r--libc/sysdeps/linux/sparc/brk.c3
-rw-r--r--libc/sysdeps/linux/sparc/clone.S2
-rw-r--r--libc/sysdeps/linux/sparc/fork.S15
-rw-r--r--libc/sysdeps/linux/sparc/vfork.S15
-rw-r--r--libc/sysdeps/linux/x86_64/brk.c3
-rw-r--r--libc/sysdeps/linux/x86_64/clone.S2
-rw-r--r--libc/sysdeps/linux/x86_64/vfork.S11
-rw-r--r--libc/termios/ttyname.c5
-rw-r--r--libc/unistd/daemon.c5
-rw-r--r--libc/unistd/fpathconf.c6
-rw-r--r--libc/unistd/getpass.c7
-rw-r--r--libc/unistd/pathconf.c6
-rw-r--r--libc/unistd/usershell.c3
-rw-r--r--libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h2
370 files changed, 6753 insertions, 5746 deletions
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
index 46b3d55c2..151ca35d2 100644
--- a/extra/Configs/Config.in
+++ b/extra/Configs/Config.in
@@ -618,6 +618,20 @@ config UCLIBC_HAS_REENTRANT_RPC
help
Most packages utilize the normal (non-reentrant) RPC functions, but
some (like exportfs from nfs-utils) need these reentrant versions.
+
+ Most people can safely answer N.
+
+config UCLIBC_USE_NETLINK
+ bool "Use netlink to query interfaces"
+ default n
+ help
+ In newer versions of Linux (2.4.17+), support was added for querying
+ network device information via netlink rather than the old style
+ ioctl's. Most of the time, the older ioctl style is sufficient (and
+ it is smaller than netlink), but if you find that not all of your
+ devices are being returned by the if_nameindex() function, you will
+ have to use the netlink implementation.
+
Most people can safely answer N.
endmenu
diff --git a/libc/inet/if_nametoindex.c b/libc/inet/if_nametoindex.c
deleted file mode 100644
index f3803e56b..000000000
--- a/libc/inet/if_nametoindex.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* Copyright (C) 1997,98,99,2000,02 Free Software Foundation, Inc.
- * This file is part of the GNU C Library.
- *
- * The GNU C Library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * The GNU C Library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with the GNU C Library; if not, write to the Free
- * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- * 02111-1307 USA.
- *
- * Reworked Dec 2002 by Erik Andersen <andersen@codepoet.org>
- */
-
-#define __FORCE_GLIBC
-#include <features.h>
-#include <string.h>
-#include <errno.h>
-#include <net/if.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-static int __opensock(void)
-{
- int fd;
-#ifdef __UCLIBC_HAS_IPV6__
- fd=__socket(AF_INET6,SOCK_DGRAM,0);
- if (fd<0)
-#endif /* __UCLIBC_HAS_IPV6__ */
- fd=__socket(AF_INET,SOCK_DGRAM,0);
- return(fd);
-}
-
-unsigned int if_nametoindex(const char* ifname)
-{
-#ifndef SIOCGIFINDEX
- __set_errno (ENOSYS);
- return 0;
-#else
- int fd;
- struct ifreq ifr;
-
- fd = __opensock();
- if (fd < 0)
- return 0;
- __strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
- if (__ioctl(fd,SIOCGIFINDEX,&ifr) < 0) {
- int saved_errno = errno;
- __close(fd);
- if (saved_errno == EINVAL)
- __set_errno(ENOSYS);
- return 0;
- }
- __close(fd);
- return ifr.ifr_ifindex;
-
-#endif /* SIOCGIFINDEX */
-}
-
-void if_freenameindex (struct if_nameindex *ifn)
-{
- struct if_nameindex *ptr = ifn;
- while (ptr->if_name || ptr->if_index) {
- if (ptr->if_name) {
- free (ptr->if_name);
- }
- ++ptr;
- }
- free (ifn);
-}
-
-struct if_nameindex * if_nameindex (void)
-{
-#ifndef SIOCGIFINDEX
- __set_errno (ENOSYS);
- return NULL;
-#else
- int fd;
- struct ifconf ifc;
- unsigned int nifs, i;
- int rq_len;
- struct if_nameindex *idx = NULL;
-# define RQ_IFS 4
-
- fd = __opensock();
- if (fd < 0)
- return 0;
-
- ifc.ifc_buf = NULL;
-
- /* Guess on the correct buffer size... */
- rq_len = RQ_IFS * sizeof (struct ifreq);
-
- /* Read all the interfaces out of the kernel. */
- do {
- ifc.ifc_buf = realloc(ifc.ifc_buf, ifc.ifc_len = rq_len);
- if (ifc.ifc_buf == NULL || __ioctl(fd, SIOCGIFCONF, &ifc) < 0) {
- __close(fd);
- return NULL;
- }
- rq_len *= 2;
- } while (ifc.ifc_len == rq_len);
-
- nifs = ifc.ifc_len / sizeof(struct ifreq);
-
- idx = malloc ((nifs + 1) * sizeof(struct if_nameindex));
- if (idx == NULL) {
- __close(fd);
- __set_errno(ENOBUFS);
- return NULL;
- }
-
- for (i = 0; i < nifs; ++i) {
- struct ifreq *ifr = &ifc.ifc_req[i];
- idx[i].if_name = __strdup (ifr->ifr_name);
- if (idx[i].if_name == NULL || __ioctl(fd,SIOCGIFINDEX,ifr) < 0) {
- int saved_errno = errno;
- unsigned int j;
- for (j = 0; j < i; ++j)
- free (idx[j].if_name);
- free(idx);
- __close(fd);
- if (saved_errno == EINVAL)
- saved_errno = ENOSYS;
- else if (saved_errno == ENOMEM)
- saved_errno = ENOBUFS;
- __set_errno (saved_errno);
- return NULL;
- }
- idx[i].if_index = ifr->ifr_ifindex;
- }
-
- idx[i].if_index = 0;
- idx[i].if_name = NULL;
-
- __close(fd);
- return idx;
-#endif
-}
-
-char * if_indextoname (unsigned int ifindex, char *ifname)
-{
-#ifdef SIOCGIFNAME
- /* Use ioctl to avoid searching the list. */
- struct ifreq ifr;
- int fd, saved_errno;
-
- fd = __opensock ();
-
- if (fd < 0)
- return NULL;
-
- ifr.ifr_ifindex = ifindex;
- if (__ioctl (fd, SIOCGIFNAME, &ifr) < 0) {
- saved_errno = errno;
- __close (fd);
- __set_errno (saved_errno);
- return NULL;
- }
- __close (fd);
-
- return __strncpy (ifname, ifr.ifr_name, IFNAMSIZ);
-#else
- struct if_nameindex *idx;
- struct if_nameindex *p;
- char *result = NULL;
-
- idx = if_nameindex();
- if (idx != NULL) {
- for (p = idx; p->if_index || p->if_name; ++p) {
- if (p->if_index == ifindex) {
- result = __strncpy (ifname, p->if_name, IFNAMSIZ);
- break;
- }
- }
- if_freenameindex (idx);
- }
- return result;
-#endif
-}
-
diff --git a/libc/misc/assert/__assert.c b/libc/misc/assert/__assert.c
index 2949b75f0..c55f0b6ae 100644
--- a/libc/misc/assert/__assert.c
+++ b/libc/misc/assert/__assert.c
@@ -41,10 +41,6 @@
#define ASSERT_SHOW_PROGNAME 1
-#ifdef ASSERT_SHOW_PROGNAME
-extern const char *__progname;
-#endif
-
static int in_assert; /* bss inits to 0. */
void __assert(const char *assertion, const char * filename,
@@ -55,7 +51,7 @@ void __assert(const char *assertion, const char * filename,
fprintf(stderr,
#ifdef ASSERT_SHOW_PROGNAME
- "%s: %s: %d: %s: Assertion `%s' failed.\n", __progname,
+ "%s: %s: %d: %s: Assertion `%s' failed.\n", __uclibc_progname,
#else
"%s: %d: %s: Assertion `%s' failed.\n",
#endif
diff --git a/libc/misc/ctype/Makefile.in b/libc/misc/ctype/Makefile.in
index 0e194cbff..87a3d11b1 100644
--- a/libc/misc/ctype/Makefile.in
+++ b/libc/misc/ctype/Makefile.in
@@ -10,7 +10,7 @@ MSRC:=ctype.c
MOBJ:= isalnum.o isalpha.o isascii.o iscntrl.o isdigit.o \
isgraph.o islower.o isprint.o ispunct.o isspace.o \
isupper.o isxdigit.o toascii.o tolower.o toupper.o \
- isblank.o isxlower.o isxupper.o
+ isblank.o
ifeq ($(UCLIBC_HAS_CTYPE_TABLES),y)
MOBJ+= __C_ctype_b.o __C_ctype_tolower.o __C_ctype_toupper.o \
@@ -21,7 +21,7 @@ endif
MOBJx:= isalnum_l.o isalpha_l.o isascii_l.o iscntrl_l.o isdigit_l.o \
isgraph_l.o islower_l.o isprint_l.o ispunct_l.o isspace_l.o \
isupper_l.o isxdigit_l.o toascii_l.o tolower_l.o toupper_l.o \
- isblank_l.o # isxlower_l.o isxupper_l.o
+ isblank_l.o
MISC_CTYPE_DIR:=$(top_srcdir)libc/misc/ctype
MISC_CTYPE_OUT:=$(top_builddir)libc/misc/ctype
diff --git a/libc/misc/ctype/ctype.c b/libc/misc/ctype/ctype.c
index 65debd842..69b4c1a6d 100644
--- a/libc/misc/ctype/ctype.c
+++ b/libc/misc/ctype/ctype.c
@@ -156,11 +156,9 @@ int CTYPE_NAME(NAME) (int c) \
#ifdef L___ctype_assert
#ifdef __UCLIBC_HAS_CTYPE_ENFORCED__
-extern const char *__progname;
-
void __isctype_assert(int c, int mask)
{
- fprintf(stderr, "%s: __is*{_l}(%d,%#x {locale})\n", __progname, c, mask);
+ fprintf(stderr, "%s: __is*{_l}(%d,%#x {locale})\n", __uclibc_progname, c, mask);
abort();
}
@@ -270,7 +268,7 @@ IS_FUNC_BODY(xdigit);
#ifdef __UCLIBC_HAS_CTYPE_TABLES__
-int tolower(int c)
+int attribute_hidden __tolower(int c)
{
#if defined(__UCLIBC_HAS_CTYPE_ENFORCED__)
assert(CTYPE_DOMAIN_CHECK(c));
@@ -280,12 +278,13 @@ int tolower(int c)
#else /* __UCLIBC_HAS_CTYPE_TABLES__ */
-int tolower(int c)
+int attribute_hidden __tolower(int c)
{
return __C_tolower(c);
}
#endif /* __UCLIBC_HAS_CTYPE_TABLES__ */
+strong_alias(__tolower,tolower)
#endif
/**********************************************************************/
@@ -310,7 +309,7 @@ weak_alias(__tolower_l, tolower_l)
#ifdef __UCLIBC_HAS_CTYPE_TABLES__
-int toupper(int c)
+int attribute_hidden __toupper(int c)
{
#if defined(__UCLIBC_HAS_CTYPE_ENFORCED__)
assert(CTYPE_DOMAIN_CHECK(c));
@@ -320,12 +319,13 @@ int toupper(int c)
#else /* __UCLIBC_HAS_CTYPE_TABLES__ */
-int toupper(int c)
+int attribute_hidden __toupper(int c)
{
return __C_toupper(c);
}
#endif /* __UCLIBC_HAS_CTYPE_TABLES__ */
+strong_alias(__toupper,toupper)
#endif
/**********************************************************************/
@@ -390,64 +390,6 @@ int toascii(int c)
#endif
/**********************************************************************/
-/* old uClibc extensions */
-/**********************************************************************/
-#ifdef L_isxlower
-
-#ifdef __UCLIBC_HAS_CTYPE_TABLES__
-
-int isxlower(int C)
-{
-#if defined(__UCLIBC_HAS_CTYPE_ENFORCED__)
- assert(CTYPE_DOMAIN_CHECK(C));
- return (__isctype(C, (_ISxdigit|_ISupper)) == _ISxdigit);
-#elif defined(__UCLIBC_HAS_CTYPE_CHECKED__)
- return CTYPE_DOMAIN_CHECK(C)
- ? (__isctype(C, (_ISxdigit|_ISupper)) == _ISxdigit)
- : 0;
-#elif defined(__UCLIBC_HAS_CTYPE_UNSAFE__)
- return (__isctype(C, (_ISxdigit|_ISupper)) == _ISxdigit);
-#else /* No checking done. */
-#error Unknown type of ctype checking!
-#endif
-}
-
-#else /* __UCLIBC_HAS_CTYPE_TABLES__ */
-
-IS_FUNC_BODY(xlower);
-
-#endif /* __UCLIBC_HAS_CTYPE_TABLES__ */
-
-#endif
-/**********************************************************************/
-#ifdef L_isxupper
-
-#ifdef __UCLIBC_HAS_CTYPE_TABLES__
-
-int isxupper(int C)
-{
-#if defined(__UCLIBC_HAS_CTYPE_ENFORCED__)
- assert(CTYPE_DOMAIN_CHECK(C));
- return (__isctype(C, (_ISxdigit|_ISlower)) == _ISxdigit);
-#elif defined(__UCLIBC_HAS_CTYPE_CHECKED__)
- return CTYPE_DOMAIN_CHECK(C)
- ? (__isctype(C, (_ISxdigit|_ISlower)) == _ISxdigit)
- : 0;
-#elif defined(__UCLIBC_HAS_CTYPE_UNSAFE__)
- return (__isctype(C, (_ISxdigit|_ISlower)) == _ISxdigit);
-#else /* No checking done. */
-#error Unknown type of ctype checking!
-#endif
-}
-
-#else /* __UCLIBC_HAS_CTYPE_TABLES__ */
-
-IS_FUNC_BODY(xupper);
-
-#endif /* __UCLIBC_HAS_CTYPE_TABLES__ */
-
-#endif
-/**********************************************************************/
/* glibc extensions */
/**********************************************************************/
#ifdef L_isctype
diff --git a/libc/misc/dirent/Makefile.in b/libc/misc/dirent/Makefile.in
index ee0165e38..e1dfa3d94 100644
--- a/libc/misc/dirent/Makefile.in
+++ b/libc/misc/dirent/Makefile.in
@@ -7,8 +7,11 @@
#
CSRC:= alphasort.c closedir.c dirfd.c opendir.c readdir.c rewinddir.c scandir.c \
- seekdir.c telldir.c readdir64.c alphasort64.c scandir64.c readdir_r.c \
- readdir64_r.c
+ seekdir.c telldir.c readdir_r.c
+
+ifeq ($(UCLIBC_HAS_LFS),y)
+CSRC+= readdir64.c alphasort64.c scandir64.c readdir64_r.c
+endif
MISC_DIRENT_DIR:=$(top_srcdir)libc/misc/dirent
MISC_DIRENT_OUT:=$(top_builddir)libc/misc/dirent
diff --git a/libc/misc/dirent/alphasort64.c b/libc/misc/dirent/alphasort64.c
index 5801f4940..c6cfcdacf 100644
--- a/libc/misc/dirent/alphasort64.c
+++ b/libc/misc/dirent/alphasort64.c
@@ -1,5 +1,5 @@
#include <features.h>
-#ifdef __UCLIBC_HAS_LFS__
+
#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64
#undef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
@@ -22,5 +22,3 @@ int alphasort64(const void * a, const void * b)
return __strcmp ((*(const struct dirent64 **) a)->d_name,
(*(const struct dirent64 **) b)->d_name);
}
-#endif /* __UCLIBC_HAS_LFS__ */
-
diff --git a/libc/misc/dirent/dirstream.h b/libc/misc/dirent/dirstream.h
index a90ca6312..15c70858f 100644
--- a/libc/misc/dirent/dirstream.h
+++ b/libc/misc/dirent/dirstream.h
@@ -72,8 +72,10 @@ struct __dirstream {
extern ssize_t __getdents(int fd, char *buf, size_t count) attribute_hidden;
+extern struct dirent *__readdir (DIR *__dirp) __nonnull ((1)) attribute_hidden;
#ifdef __UCLIBC_HAS_LFS__
extern ssize_t __getdents64 (int fd, char *buf, size_t count) attribute_hidden;
+extern struct dirent64 *__readdir64 (DIR *__dirp) __nonnull ((1)) attribute_hidden;
#endif
#endif /* dirent.h */
diff --git a/libc/misc/dirent/opendir.c b/libc/misc/dirent/opendir.c
index 5c9762f85..82e7f364f 100644
--- a/libc/misc/dirent/opendir.c
+++ b/libc/misc/dirent/opendir.c
@@ -18,7 +18,7 @@ DIR attribute_hidden *__opendir(const char *name)
char *buf;
DIR *ptr;
- if (stat(name, &statbuf))
+ if (__stat(name, &statbuf))
return NULL;
if (!S_ISDIR(statbuf.st_mode)) {
__set_errno(ENOTDIR);
@@ -29,7 +29,7 @@ DIR attribute_hidden *__opendir(const char *name)
/* According to POSIX, directory streams should be closed when
* exec. From "Anna Pluzhnikov" <besp@midway.uchicago.edu>.
*/
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+ if (__fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
return NULL;
if (!(ptr = malloc(sizeof(*ptr)))) {
__close(fd);
diff --git a/libc/misc/dirent/readdir.c b/libc/misc/dirent/readdir.c
index 68a465fc8..2d4ad4aeb 100644
--- a/libc/misc/dirent/readdir.c
+++ b/libc/misc/dirent/readdir.c
@@ -1,3 +1,5 @@
+#include <features.h>
+
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -5,8 +7,7 @@
#include <dirent.h>
#include "dirstream.h"
-
-struct dirent *readdir(DIR * dir)
+struct dirent attribute_hidden *__readdir(DIR * dir)
{
ssize_t bytes;
struct dirent *de;
@@ -45,3 +46,4 @@ all_done:
__pthread_mutex_unlock(&(dir->dd_lock));
return de;
}
+strong_alias(__readdir,readdir)
diff --git a/libc/misc/dirent/readdir64.c b/libc/misc/dirent/readdir64.c
index 8d22a314e..177af3fc9 100644
--- a/libc/misc/dirent/readdir64.c
+++ b/libc/misc/dirent/readdir64.c
@@ -1,5 +1,5 @@
#include <features.h>
-#ifdef __UCLIBC_HAS_LFS__
+
#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64
#undef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
@@ -20,8 +20,7 @@
#include <dirent.h>
#include "dirstream.h"
-
-struct dirent64 *readdir64(DIR * dir)
+struct dirent64 attribute_hidden *__readdir64(DIR * dir)
{
ssize_t bytes;
struct dirent64 *de;
@@ -61,5 +60,4 @@ all_done:
return de;
}
-
-#endif /* __UCLIBC_HAS_LFS__ */
+strong_alias(__readdir64,readdir64)
diff --git a/libc/misc/dirent/readdir64_r.c b/libc/misc/dirent/readdir64_r.c
index 7daf890dd..1cbaf3156 100644
--- a/libc/misc/dirent/readdir64_r.c
+++ b/libc/misc/dirent/readdir64_r.c
@@ -1,5 +1,5 @@
#include <features.h>
-#ifdef __UCLIBC_HAS_LFS__
+
#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64
#undef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
@@ -19,7 +19,6 @@
#include <dirent.h>
#include "dirstream.h"
-
int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result)
{
int ret;
@@ -69,5 +68,3 @@ all_done:
__pthread_mutex_unlock(&(dir->dd_lock));
return((de != NULL)? 0 : ret);
}
-#endif /* __UCLIBC_HAS_LFS__ */
-
diff --git a/libc/misc/dirent/rewinddir.c b/libc/misc/dirent/rewinddir.c
index f41ecc389..18d6547a8 100644
--- a/libc/misc/dirent/rewinddir.c
+++ b/libc/misc/dirent/rewinddir.c
@@ -12,7 +12,7 @@ void rewinddir(DIR * dir)
return;
}
__pthread_mutex_lock(&(dir->dd_lock));
- lseek(dir->dd_fd, 0, SEEK_SET);
+ __lseek(dir->dd_fd, 0, SEEK_SET);
dir->dd_nextoff = dir->dd_nextloc = dir->dd_size = 0;
__pthread_mutex_unlock(&(dir->dd_lock));
}
diff --git a/libc/misc/dirent/scandir.c b/libc/misc/dirent/scandir.c
index cc76bed5e..72929fb57 100644
--- a/libc/misc/dirent/scandir.c
+++ b/libc/misc/dirent/scandir.c
@@ -49,7 +49,7 @@ int scandir(const char *dir, struct dirent ***namelist,
__set_errno (0);
pos = 0;
- while ((current = readdir (dp)) != NULL)
+ while ((current = __readdir (dp)) != NULL)
if (selector == NULL || (*selector) (current))
{
struct dirent *vnew;
diff --git a/libc/misc/dirent/scandir64.c b/libc/misc/dirent/scandir64.c
index 377f55fe6..e77b88d3c 100644
--- a/libc/misc/dirent/scandir64.c
+++ b/libc/misc/dirent/scandir64.c
@@ -25,7 +25,7 @@
#define closedir __closedir
#include <features.h>
-#ifdef __UCLIBC_HAS_LFS__
+
#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64
#undef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
@@ -64,7 +64,7 @@ int scandir64(const char *dir, struct dirent64 ***namelist,
__set_errno (0);
pos = 0;
- while ((current = readdir64 (dp)) != NULL)
+ while ((current = __readdir64 (dp)) != NULL)
if (selector == NULL || (*selector) (current))
{
struct dirent64 *vnew;
@@ -114,5 +114,3 @@ int scandir64(const char *dir, struct dirent64 ***namelist,
*namelist = names;
return pos;
}
-#endif /* __UCLIBC_HAS_LFS__ */
-
diff --git a/libc/misc/dirent/seekdir.c b/libc/misc/dirent/seekdir.c
index 507131097..6e841291a 100644
--- a/libc/misc/dirent/seekdir.c
+++ b/libc/misc/dirent/seekdir.c
@@ -10,7 +10,7 @@ void seekdir(DIR * dir, long int offset)
return;
}
__pthread_mutex_lock(&(dir->dd_lock));
- dir->dd_nextoff = lseek(dir->dd_fd, offset, SEEK_SET);
+ dir->dd_nextoff = __lseek(dir->dd_fd, offset, SEEK_SET);
dir->dd_size = dir->dd_nextloc = 0;
__pthread_mutex_unlock(&(dir->dd_lock));
}
diff --git a/libc/misc/error/err.c b/libc/misc/error/err.c
index 922cd8aba..43fe60cc6 100644
--- a/libc/misc/error/err.c
+++ b/libc/misc/error/err.c
@@ -19,10 +19,8 @@
#endif
#ifdef __UCLIBC_MJN3_ONLY__
-#warning REMINDER: Need a centralized __progname prototype.
#warning REMINDER: Deal with wide oriented stderr case.
#endif
-extern const char *__progname;
static void vwarn_work(const char *format, va_list args, int showerr)
{
@@ -41,7 +39,7 @@ static void vwarn_work(const char *format, va_list args, int showerr)
__STDIO_AUTO_THREADLOCK(stderr);
- fprintf(stderr, fmt, __progname);
+ fprintf(stderr, fmt, __uclibc_progname);
if (format) {
vfprintf(stderr, format, args);
f -= 2; /* At 5 (showerr) or 9. */
@@ -84,7 +82,7 @@ void warnx(const char *format, ...)
void attribute_hidden __verr(int status, const char *format, va_list args)
{
__vwarn(format, args);
- exit(status);
+ __exit(status);
}
strong_alias(__verr,verr)
@@ -103,7 +101,7 @@ void attribute_noreturn err(int status, const char *format, ...)
void attribute_hidden __verrx(int status, const char *format, va_list args)
{
__vwarnx(format, args);
- exit(status);
+ __exit(status);
}
strong_alias(__verrx,verrx)
diff --git a/libc/misc/error/error.c b/libc/misc/error/error.c
index 5427e9568..b51177e35 100644
--- a/libc/misc/error/error.c
+++ b/libc/misc/error/error.c
@@ -24,6 +24,7 @@
#define strerror __strerror
#define vfprintf __vfprintf
+#define fflush __fflush
#include <stdio.h>
#include <stdarg.h>
@@ -31,6 +32,7 @@
#include <string.h>
#include "error.h"
+extern int __putc(int c, FILE *stream) attribute_hidden;
/* This variable is incremented each time `error' is called. */
unsigned int error_message_count;
@@ -56,9 +58,9 @@ void __error (int status, int errnum, const char *message, ...)
if (errnum) {
fprintf (stderr, ": %s", strerror (errnum));
}
- putc ('\n', stderr);
+ __putc ('\n', stderr);
if (status)
- exit (status);
+ __exit (status);
}
void __error_at_line (int status, int errnum, const char *file_name,
@@ -92,9 +94,9 @@ void __error_at_line (int status, int errnum, const char *file_name,
if (errnum) {
fprintf (stderr, ": %s", strerror (errnum));
}
- putc ('\n', stderr);
+ __putc ('\n', stderr);
if (status)
- exit (status);
+ __exit (status);
}
/* Use the weaks here in an effort at controlling namespace pollution */
diff --git a/libc/misc/file/lockf.c b/libc/misc/file/lockf.c
index 29c91482a..2ba81de9a 100644
--- a/libc/misc/file/lockf.c
+++ b/libc/misc/file/lockf.c
@@ -16,6 +16,9 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include <features.h>
+#undef __lockf
+
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
@@ -24,7 +27,8 @@
/* lockf is a simplified interface to fcntl's locking facilities. */
-int lockf (int fd, int cmd, off_t len)
+#undef lockf
+int attribute_hidden __lockf (int fd, int cmd, off_t len)
{
struct flock fl;
@@ -41,7 +45,7 @@ int lockf (int fd, int cmd, off_t len)
/* Test the lock: return 0 if FD is unlocked or locked by this process;
return -1, set errno to EACCES, if another process holds the lock. */
fl.l_type = F_RDLCK;
- if (fcntl (fd, F_GETLK, &fl) < 0)
+ if (__fcntl (fd, F_GETLK, &fl) < 0)
return -1;
if (fl.l_type == F_UNLCK || fl.l_pid == __getpid ())
return 0;
@@ -66,5 +70,6 @@ int lockf (int fd, int cmd, off_t len)
return -1;
}
- return fcntl(fd, cmd, &fl);
+ return __fcntl(fd, cmd, &fl);
}
+strong_alias(__lockf,lockf)
diff --git a/libc/misc/file/lockf64.c b/libc/misc/file/lockf64.c
index 63c2ddfbe..1e294d9a6 100644
--- a/libc/misc/file/lockf64.c
+++ b/libc/misc/file/lockf64.c
@@ -17,6 +17,7 @@
Boston, MA 02111-1307, USA. */
#include <features.h>
+#undef __lockf64
#ifdef __UCLIBC_HAS_LFS__
#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64
@@ -41,16 +42,18 @@
#include <sys/syscall.h>
#ifdef __NR_fcntl64
-extern int fcntl64 (int fd, int cmd, ...);
#define flock flock64
-#define fcntl fcntl64
+#define fcntl __fcntl64
#define F_GETLK F_GETLK64
#define F_SETLK F_SETLK64
+#else
+#define fcntl __fcntl
#endif
/* lockf is a simplified interface to fcntl's locking facilities. */
-int lockf64 (int fd, int cmd, off64_t len64)
+#undef lockf64
+int attribute_hidden __lockf64 (int fd, int cmd, off64_t len64)
{
struct flock fl;
off_t len = (off_t) len64;
@@ -103,3 +106,4 @@ int lockf64 (int fd, int cmd, off64_t len64)
return fcntl(fd, cmd, &fl);
}
+strong_alias(__lockf64,lockf64)
diff --git a/libc/misc/fnmatch/Makefile.in b/libc/misc/fnmatch/Makefile.in
index 5476672df..61e125f9f 100644
--- a/libc/misc/fnmatch/Makefile.in
+++ b/libc/misc/fnmatch/Makefile.in
@@ -6,16 +6,22 @@
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
+ifeq ($(UCLIBC_HAS_FNMATCH_OLD),y)
+CSRC:=fnmatch_old.c
+else
+CSRC:=fnmatch.c
+endif
+
MISC_FNMATCH_DIR:=$(top_srcdir)libc/misc/fnmatch
MISC_FNMATCH_OUT:=$(top_builddir)libc/misc/fnmatch
-MISC_FNMATCH_SRC:=$(MISC_FNMATCH_DIR)/fnmatch.c
-MISC_FNMATCH_OBJ:=$(MISC_FNMATCH_OUT)/fnmatch.o
+MISC_FNMATCH_SRC:=$(patsubst %.c,$(MISC_FNMATCH_DIR)/%.c,$(CSRC))
+MISC_FNMATCH_OBJ:=$(patsubst %.c,$(MISC_FNMATCH_OUT)/%.o,$(CSRC))
-libc-a-y+=$(MISC_FNMATCH_OBJ)
-libc-so-y+=$(MISC_FNMATCH_OBJ:.o=.os)
+libc-a-$(UCLIBC_HAS_FNMATCH)+=$(MISC_FNMATCH_OBJ)
+libc-so-$(UCLIBC_HAS_FNMATCH)+=$(MISC_FNMATCH_OBJ:.o=.os)
-libc-multi-y+=$(MISC_FNMATCH_SRC)
+libc-multi-$(UCLIBC_HAS_FNMATCH)+=$(MISC_FNMATCH_SRC)
objclean-y+=misc_fnmatch_objclean
diff --git a/libc/misc/fnmatch/fnmatch.c b/libc/misc/fnmatch/fnmatch.c
index e0d9daa87..2dafebe18 100644
--- a/libc/misc/fnmatch/fnmatch.c
+++ b/libc/misc/fnmatch/fnmatch.c
@@ -1,19 +1,23 @@
-/* Copyright (C) 1991, 1992, 1993, 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
-You should have received a copy of the GNU Library General Public
-License along with this library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define strcmp __strcmp
#if HAVE_CONFIG_H
# include <config.h>
@@ -24,10 +28,93 @@ Cambridge, MA 02139, USA. */
# define _GNU_SOURCE 1
#endif
+#include <features.h>
+#ifdef __UCLIBC__
+# undef _LIBC
+# define HAVE_STRING_H 1
+# define STDC_HEADERS
+# define HAVE___STRCHRNUL 1
+extern void *__mempcpy (void *__restrict __dest,
+ __const void *__restrict __src, size_t __n)
+ __THROW __nonnull ((1, 2)) attribute_hidden;
+extern void *__memchr (__const void *__s, int __c, size_t __n)
+ __THROW __attribute_pure__ __nonnull ((1)) attribute_hidden;
+# ifdef __UCLIBC_HAS_WCHAR__
+# define HAVE_WCHAR_H 1
+# define HAVE_WCTYPE_H 1
+# ifdef __UCLIBC_HAS_LOCALE__
+# define HAVE_MBSTATE_T 1
+# define HAVE_MBSRTOWCS 1
+# endif
+# endif
+#endif
+
+#include <assert.h>
#include <errno.h>
#include <fnmatch.h>
#include <ctype.h>
+#if HAVE_STRING_H || defined _LIBC
+# include <string.h>
+#else
+# include <strings.h>
+#endif
+
+#if defined STDC_HEADERS || defined _LIBC
+# include <stdlib.h>
+#endif
+
+/* For platform which support the ISO C amendement 1 functionality we
+ support user defined character classes. */
+#if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H)
+/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */
+# include <wchar.h>
+# include <wctype.h>
+# ifdef __UCLIBC__
+extern wctype_t __wctype (__const char *__property) __THROW attribute_hidden;
+extern int __iswctype (wint_t __wc, wctype_t __desc) __THROW attribute_hidden;
+extern wint_t __btowc (int __c) __THROW attribute_hidden;
+# ifdef __UCLIBC_HAS_LOCALE__
+extern size_t __mbsrtowcs (wchar_t *__restrict __dst,
+ __const char **__restrict __src, size_t __len,
+ mbstate_t *__restrict __ps) __THROW attribute_hidden;
+extern size_t __wcslen (__const wchar_t *__s) __THROW __attribute_pure__ attribute_hidden;
+extern wchar_t *__wmempcpy (wchar_t *__restrict __s1,
+ __const wchar_t *__restrict __s2, size_t __n)
+ __THROW attribute_hidden;
+extern wchar_t *__wcscat (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src) __THROW attribute_hidden;
+extern size_t __strnlen (__const char *__string, size_t __maxlen)
+ __THROW __attribute_pure__ __nonnull ((1)) attribute_hidden;
+extern wchar_t *__wmemchr (__const wchar_t *__s, wchar_t __c, size_t __n)
+ __THROW __attribute_pure__ attribute_hidden;
+extern wint_t __towlower (wint_t __wc) __THROW attribute_hidden;
+# endif
+# endif
+#endif
+
+/* We need some of the locale data (the collation sequence information)
+ but there is no interface to get this information in general. Therefore
+ we support a correct implementation only in glibc. */
+#if defined _LIBC || defined __UCLIBC__
+# ifndef __UCLIBC__
+# include "../locale/localeinfo.h"
+# include "../locale/elem-hash.h"
+# include "../locale/coll-lookup.h"
+# include <shlib-compat.h>
+# endif
+
+# define CONCAT(a,b) __CONCAT(a,b)
+# if defined _LIBC || defined __UCLIBC_HAS_LOCALE__
+# define mbsrtowcs __mbsrtowcs
+# endif
+# define fnmatch __fnmatch
+extern int fnmatch (const char *pattern, const char *string, int flags) attribute_hidden;
+#endif
+
+/* We often have to test for FNM_FILE_NAME and FNM_PERIOD being both set. */
+#define NO_LEADING_PERIOD(flags) \
+ ((flags & (FNM_FILE_NAME | FNM_PERIOD)) == (FNM_FILE_NAME | FNM_PERIOD))
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
@@ -37,189 +124,351 @@ Cambridge, MA 02139, USA. */
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
-#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
+#if defined _LIBC || !defined __GNU_LIBRARY__
-# if defined (STDC_HEADERS) || !defined (isascii)
+# if defined STDC_HEADERS || !defined isascii
# define ISASCII(c) 1
# else
# define ISASCII(c) isascii(c)
# endif
+# ifdef isblank
+# define ISBLANK(c) (ISASCII (c) && isblank (c))
+# else
+# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
+# endif
+# ifdef isgraph
+# define ISGRAPH(c) (ISASCII (c) && isgraph (c))
+# else
+# define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
+# endif
+
+# define ISPRINT(c) (ISASCII (c) && isprint (c))
+# define ISDIGIT(c) (ISASCII (c) && isdigit (c))
+# define ISALNUM(c) (ISASCII (c) && isalnum (c))
+# define ISALPHA(c) (ISASCII (c) && isalpha (c))
+# define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
+# define ISLOWER(c) (ISASCII (c) && islower (c))
+# define ISPUNCT(c) (ISASCII (c) && ispunct (c))
+# define ISSPACE(c) (ISASCII (c) && isspace (c))
# define ISUPPER(c) (ISASCII (c) && isupper (c))
+# define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
+
+# define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
+
+# if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H)
+/* The GNU C library provides support for user-defined character classes
+ and the functions from ISO C amendement 1. */
+# ifdef CHARCLASS_NAME_MAX
+# define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX
+# else
+/* This shouldn't happen but some implementation might still have this
+ problem. Use a reasonable default value. */
+# define CHAR_CLASS_MAX_LENGTH 256
+# endif
+
+# if defined _LIBC || defined __UCLIBC__
+# define IS_CHAR_CLASS(string) __wctype (string)
+# else
+# define IS_CHAR_CLASS(string) wctype (string)
+# endif
+
+# if defined _LIBC || defined __UCLIBC__
+# define ISWCTYPE(WC, WT) __iswctype (WC, WT)
+# else
+# define ISWCTYPE(WC, WT) iswctype (WC, WT)
+# endif
+
+# if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC
+/* In this case we are implementing the multibyte character handling. */
+# define HANDLE_MULTIBYTE 1
+# endif
+
+# else
+# define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
+
+# define IS_CHAR_CLASS(string) \
+ (STREQ (string, "alpha") || STREQ (string, "upper") \
+ || STREQ (string, "lower") || STREQ (string, "digit") \
+ || STREQ (string, "alnum") || STREQ (string, "xdigit") \
+ || STREQ (string, "space") || STREQ (string, "print") \
+ || STREQ (string, "punct") || STREQ (string, "graph") \
+ || STREQ (string, "cntrl") || STREQ (string, "blank"))
+# endif
+/* Avoid depending on library functions or files
+ whose names are inconsistent. */
+
+# if !defined _LIBC && !defined getenv && !defined __UCLIBC__
+extern char *getenv ();
+# endif
+
+# ifndef errno
+extern int errno;
+# endif
+
+/* Global variable. */
+static int posixly_correct;
+
+/* This function doesn't exist on most systems. */
+
+# if !defined HAVE___STRCHRNUL && !defined _LIBC
+static char *
+__strchrnul (s, c)
+ const char *s;
+ int c;
+{
+ char *result = strchr (s, c);
+ if (result == NULL)
+ result = strchr (s, '\0');
+ return result;
+}
+# endif
-/* Match STRING against the filename pattern PATTERN, returning zero if
- it matches, nonzero if not. */
-int attribute_hidden __fnmatch(const char *pattern, const char *string, int flags)
+# if HANDLE_MULTIBYTE && !defined HAVE___STRCHRNUL && !defined _LIBC
+static wchar_t *
+__wcschrnul (s, c)
+ const wchar_t *s;
+ wint_t c;
{
- register const char *p = pattern, *n = string;
- register char c;
+ wchar_t *result = wcschr (s, c);
+ if (result == NULL)
+ result = wcschr (s, '\0');
+ return result;
+}
+# endif
+
+# ifndef internal_function
+/* Inside GNU libc we mark some function in a special way. In other
+ environments simply ignore the marking. */
+# define internal_function
+# endif
+
+/* Note that this evaluates C many times. */
+# if defined _LIBC || defined __UCLIBC__
+# define FOLD(c) ((flags & FNM_CASEFOLD) ? __tolower (c) : (c))
+# else
+# define FOLD(c) ((flags & FNM_CASEFOLD) && ISUPPER (c) ? tolower (c) : (c))
+# endif
+# define CHAR char
+# define UCHAR unsigned char
+# define INT int
+# define FCT internal_fnmatch
+# define EXT ext_match
+# define END end_pattern
+# define L(CS) CS
+# if defined _LIBC || defined __UCLIBC__
+# define BTOWC(C) __btowc (C)
+# else
+# define BTOWC(C) btowc (C)
+# endif
+# define STRLEN(S) __strlen (S)
+# define STRCAT(D, S) __strcat (D, S)
+# define MEMPCPY(D, S, N) __mempcpy (D, S, N)
+# define MEMCHR(S, C, N) __memchr (S, C, N)
+# define STRCOLL(S1, S2) __strcoll (S1, S2)
+# include "fnmatch_loop.c"
+
+# if HANDLE_MULTIBYTE
/* Note that this evaluates C many times. */
-# define FOLD(c) ((flags & FNM_CASEFOLD) && ISUPPER (c) ? tolower (c) : (c))
-
- while ((c = *p++) != '\0') {
- c = FOLD(c);
-
- switch (c) {
- case '?':
- if (*n == '\0')
- return FNM_NOMATCH;
- else if ((flags & FNM_FILE_NAME) && *n == '/')
- return FNM_NOMATCH;
- else if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string
- || ((flags & FNM_FILE_NAME)
- && n[-1] == '/'))) return FNM_NOMATCH;
- break;
-
- case '\\':
- if (!(flags & FNM_NOESCAPE)) {
- c = *p++;
- if (c == '\0')
- /* Trailing \ loses. */
- return FNM_NOMATCH;
- c = FOLD(c);
- }
- if (FOLD(*n) != c)
- return FNM_NOMATCH;
- break;
-
- case '*':
- if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
- return FNM_NOMATCH;
-
- for (c = *p++; c == '?' || c == '*'; c = *p++) {
- if ((flags & FNM_FILE_NAME) && *n == '/')
- /* A slash does not match a wildcard under FNM_FILE_NAME. */
- return FNM_NOMATCH;
- else if (c == '?') {
- /* A ? needs to match one character. */
- if (*n == '\0')
- /* There isn't another character; no match. */
- return FNM_NOMATCH;
- else
- /* One character of the string is consumed in matching
- this ? wildcard, so *??? won't match if there are
- less than three characters. */
- ++n;
- }
- }
-
- if (c == '\0')
- return 0;
-
- {
- char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
-
- c1 = FOLD(c1);
- for (--p; *n != '\0'; ++n)
- if ((c == '[' || FOLD(*n) == c1) &&
- __fnmatch(p, n, flags & ~FNM_PERIOD) == 0)
- return 0;
- return FNM_NOMATCH;
- }
-
- case '[':
- {
- /* Nonzero if the sense of the character class is inverted. */
- register int not;
-
- if (*n == '\0')
- return FNM_NOMATCH;
-
- if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
- return FNM_NOMATCH;
-
- not = (*p == '!' || *p == '^');
- if (not)
- ++p;
-
- c = *p++;
- for (;;) {
- register char cstart = c, cend = c;
-
- if (!(flags & FNM_NOESCAPE) && c == '\\') {
- if (*p == '\0')
- return FNM_NOMATCH;
- cstart = cend = *p++;
- }
-
- cstart = cend = FOLD(cstart);
-
- if (c == '\0')
- /* [ (unterminated) loses. */
- return FNM_NOMATCH;
-
- c = *p++;
- c = FOLD(c);
-
- if ((flags & FNM_FILE_NAME) && c == '/')
- /* [/] can never match. */
- return FNM_NOMATCH;
-
- if (c == '-' && *p != ']') {
- cend = *p++;
- if (!(flags & FNM_NOESCAPE) && cend == '\\')
- cend = *p++;
- if (cend == '\0')
- return FNM_NOMATCH;
- cend = FOLD(cend);
-
- c = *p++;
- }
-
- if (FOLD(*n) >= cstart && FOLD(*n) <= cend)
- goto matched;
-
- if (c == ']')
- break;
- }
- if (!not)
- return FNM_NOMATCH;
- break;
-
- matched:;
- /* Skip the rest of the [...] that already matched. */
- while (c != ']') {
- if (c == '\0')
- /* [... (unterminated) loses. */
- return FNM_NOMATCH;
-
- c = *p++;
- if (!(flags & FNM_NOESCAPE) && c == '\\') {
- if (*p == '\0')
- return FNM_NOMATCH;
- /* XXX 1003.2d11 is unclear if this is right. */
- ++p;
- }
- }
- if (not)
- return FNM_NOMATCH;
- }
- break;
-
- default:
- if (c != FOLD(*n))
- return FNM_NOMATCH;
- }
-
- ++n;
+# if defined _LIBC || defined __UCLIBC__
+# define FOLD(c) ((flags & FNM_CASEFOLD) ? __towlower (c) : (c))
+# else
+# define FOLD(c) ((flags & FNM_CASEFOLD) && ISUPPER (c) ? towlower (c) : (c))
+# endif
+# define CHAR wchar_t
+# define UCHAR wint_t
+# define INT wint_t
+# define FCT internal_fnwmatch
+# define EXT ext_wmatch
+# define END end_wpattern
+# define L(CS) L##CS
+# define BTOWC(C) (C)
+# define STRLEN(S) __wcslen (S)
+# define STRCAT(D, S) __wcscat (D, S)
+# define MEMPCPY(D, S, N) __wmempcpy (D, S, N)
+# define MEMCHR(S, C, N) __wmemchr (S, C, N)
+# define STRCOLL(S1, S2) __wcscoll (S1, S2)
+# ifndef __UCLIBC__
+# define WIDE_CHAR_VERSION 1
+# endif
+
+# undef IS_CHAR_CLASS
+/* We have to convert the wide character string in a multibyte string. But
+ we know that the character class names consist of alphanumeric characters
+ from the portable character set, and since the wide character encoding
+ for a member of the portable character set is the same code point as
+ its single-byte encoding, we can use a simplified method to convert the
+ string to a multibyte character string. */
+static wctype_t
+is_char_class (const wchar_t *wcs)
+{
+ char s[CHAR_CLASS_MAX_LENGTH + 1];
+ char *cp = s;
+
+ do
+ {
+ /* Test for a printable character from the portable character set. */
+# if defined _LIBC || defined __UCLIBC__
+ if (*wcs < 0x20 || *wcs > 0x7e
+ || *wcs == 0x24 || *wcs == 0x40 || *wcs == 0x60)
+ return (wctype_t) 0;
+# else
+ switch (*wcs)
+ {
+ case L' ': case L'!': case L'"': case L'#': case L'%':
+ case L'&': case L'\'': case L'(': case L')': case L'*':
+ case L'+': case L',': case L'-': case L'.': case L'/':
+ case L'0': case L'1': case L'2': case L'3': case L'4':
+ case L'5': case L'6': case L'7': case L'8': case L'9':
+ case L':': case L';': case L'<': case L'=': case L'>':
+ case L'?':
+ case L'A': case L'B': case L'C': case L'D': case L'E':
+ case L'F': case L'G': case L'H': case L'I': case L'J':
+ case L'K': case L'L': case L'M': case L'N': case L'O':
+ case L'P': case L'Q': case L'R': case L'S': case L'T':
+ case L'U': case L'V': case L'W': case L'X': case L'Y':
+ case L'Z':
+ case L'[': case L'\\': case L']': case L'^': case L'_':
+ case L'a': case L'b': case L'c': case L'd': case L'e':
+ case L'f': case L'g': case L'h': case L'i': case L'j':
+ case L'k': case L'l': case L'm': case L'n': case L'o':
+ case L'p': case L'q': case L'r': case L's': case L't':
+ case L'u': case L'v': case L'w': case L'x': case L'y':
+ case L'z': case L'{': case L'|': case L'}': case L'~':
+ break;
+ default:
+ return (wctype_t) 0;
}
+# endif
+
+ /* Avoid overrunning the buffer. */
+ if (cp == s + CHAR_CLASS_MAX_LENGTH)
+ return (wctype_t) 0;
+
+ *cp++ = (char) *wcs++;
+ }
+ while (*wcs != L'\0');
- if (*n == '\0')
- return 0;
+ *cp = '\0';
- if ((flags & FNM_LEADING_DIR) && *n == '/')
- /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
- return 0;
+# if defined _LIBC || defined __UCLIBC__
+ return __wctype (s);
+# else
+ return wctype (s);
+# endif
+}
+# define IS_CHAR_CLASS(string) is_char_class (string)
+
+# include "fnmatch_loop.c"
+# endif
+
+
+int attribute_hidden
+fnmatch (const char *pattern, const char *string, int flags)
+{
+# if HANDLE_MULTIBYTE
+# ifdef __UCLIBC_HAS_WCHAR__
+# undef MB_CUR_MAX
+# define MB_CUR_MAX (_stdlib_mb_cur_max_internal ())
+extern size_t _stdlib_mb_cur_max_internal (void) __THROW __wur attribute_hidden;
+# endif
+ if (__builtin_expect (MB_CUR_MAX, 1) != 1)
+ {
+ mbstate_t ps;
+ size_t n;
+ const char *p;
+ wchar_t *wpattern = NULL;
+ wchar_t *wstring = NULL;
+
+ /* Convert the strings into wide characters. */
+ __memset (&ps, '\0', sizeof (ps));
+ p = pattern;
+#if defined _LIBC || defined __UCLIBC__
+ n = __strnlen (pattern, 1024);
+#else
+ n = __strlen (pattern);
+#endif
+ if (__builtin_expect (n < 1024, 1))
+ {
+ wpattern = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
+ n = mbsrtowcs (wpattern, &p, n + 1, &ps);
+ if (__builtin_expect (n == (size_t) -1, 0))
+ /* Something wrong.
+ XXX Do we have to set `errno' to something which mbsrtows hasn't
+ already done? */
+ return -1;
+ if (p)
+ __memset (&ps, '\0', sizeof (ps));
+ }
+ if (__builtin_expect (p != NULL, 0))
+ {
+ n = mbsrtowcs (NULL, &pattern, 0, &ps);
+ if (__builtin_expect (n == (size_t) -1, 0))
+ /* Something wrong.
+ XXX Do we have to set `errno' to something which mbsrtows hasn't
+ already done? */
+ return -1;
+ wpattern = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
+ assert (mbsinit (&ps));
+ (void) mbsrtowcs (wpattern, &pattern, n + 1, &ps);
+ }
+
+ assert (mbsinit (&ps));
+#if defined _LIBC || defined __UCLIBC__
+ n = __strnlen (string, 1024);
+#else
+ n = __strlen (string);
+#endif
+ p = string;
+ if (__builtin_expect (n < 1024, 1))
+ {
+ wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
+ n = mbsrtowcs (wstring, &p, n + 1, &ps);
+ if (__builtin_expect (n == (size_t) -1, 0))
+ /* Something wrong.
+ XXX Do we have to set `errno' to something which mbsrtows hasn't
+ already done? */
+ return -1;
+ if (p)
+ __memset (&ps, '\0', sizeof (ps));
+ }
+ if (__builtin_expect (p != NULL, 0))
+ {
+ n = mbsrtowcs (NULL, &string, 0, &ps);
+ if (__builtin_expect (n == (size_t) -1, 0))
+ /* Something wrong.
+ XXX Do we have to set `errno' to something which mbsrtows hasn't
+ already done? */
+ return -1;
+ wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
+ assert (mbsinit (&ps));
+ (void) mbsrtowcs (wstring, &string, n + 1, &ps);
+ }
- return FNM_NOMATCH;
+ return internal_fnwmatch (wpattern, wstring, wstring + n,
+ flags & FNM_PERIOD, flags);
+ }
+# endif /* mbstate_t and mbsrtowcs or _LIBC. */
-# undef FOLD
+ return internal_fnmatch (pattern, string, string + __strlen (string),
+ flags & FNM_PERIOD, flags);
}
+
+# if defined _LIBC || defined __UCLIBC__
+# undef fnmatch
+# ifndef __UCLIBC__
+versioned_symbol (libc, __fnmatch, fnmatch, GLIBC_2_2_3);
+# if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_2_3)
+strong_alias (__fnmatch, __fnmatch_old)
+compat_symbol (libc, __fnmatch_old, fnmatch, GLIBC_2_0);
+# endif
+libc_hidden_ver (__fnmatch, fnmatch)
+# else
strong_alias(__fnmatch,fnmatch)
-#endif /* _LIBC or not __GNU_LIBRARY__. */
+# endif
+# endif
+
+#endif /* _LIBC or not __GNU_LIBRARY__. */
diff --git a/libc/misc/fnmatch/fnmatch_loop.c b/libc/misc/fnmatch/fnmatch_loop.c
new file mode 100644
index 000000000..663af1222
--- /dev/null
+++ b/libc/misc/fnmatch/fnmatch_loop.c
@@ -0,0 +1,1209 @@
+/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2003,2004,2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Match STRING against the filename pattern PATTERN, returning zero if
+ it matches, nonzero if not. */
+static int FCT (const CHAR *pattern, const CHAR *string,
+ const CHAR *string_end, int no_leading_period, int flags)
+ internal_function;
+static int EXT (INT opt, const CHAR *pattern, const CHAR *string,
+ const CHAR *string_end, int no_leading_period, int flags)
+ internal_function;
+static const CHAR *END (const CHAR *patternp) internal_function;
+
+static int
+internal_function
+FCT (pattern, string, string_end, no_leading_period, flags)
+ const CHAR *pattern;
+ const CHAR *string;
+ const CHAR *string_end;
+ int no_leading_period;
+ int flags;
+{
+ register const CHAR *p = pattern, *n = string;
+ register UCHAR c;
+#ifdef _LIBC
+# if WIDE_CHAR_VERSION
+ const char *collseq = (const char *)
+ _NL_CURRENT(LC_COLLATE, _NL_COLLATE_COLLSEQWC);
+# else
+ const UCHAR *collseq = (const UCHAR *)
+ _NL_CURRENT(LC_COLLATE, _NL_COLLATE_COLLSEQMB);
+# endif
+#endif
+
+ while ((c = *p++) != L('\0'))
+ {
+ int new_no_leading_period = 0;
+ c = FOLD (c);
+
+ switch (c)
+ {
+ case L('?'):
+ if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(')
+ {
+ int res;
+
+ res = EXT (c, p, n, string_end, no_leading_period,
+ flags);
+ if (res != -1)
+ return res;
+ }
+
+ if (n == string_end)
+ return FNM_NOMATCH;
+ else if (*n == L('/') && (flags & FNM_FILE_NAME))
+ return FNM_NOMATCH;
+ else if (*n == L('.') && no_leading_period)
+ return FNM_NOMATCH;
+ break;
+
+ case L('\\'):
+ if (!(flags & FNM_NOESCAPE))
+ {
+ c = *p++;
+ if (c == L('\0'))
+ /* Trailing \ loses. */
+ return FNM_NOMATCH;
+ c = FOLD (c);
+ }
+ if (n == string_end || FOLD ((UCHAR) *n) != c)
+ return FNM_NOMATCH;
+ break;
+
+ case L('*'):
+ if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(')
+ {
+ int res;
+
+ res = EXT (c, p, n, string_end, no_leading_period,
+ flags);
+ if (res != -1)
+ return res;
+ }
+
+ if (n != string_end && *n == L('.') && no_leading_period)
+ return FNM_NOMATCH;
+
+ for (c = *p++; c == L('?') || c == L('*'); c = *p++)
+ {
+ if (*p == L('(') && (flags & FNM_EXTMATCH) != 0)
+ {
+ const CHAR *endp = END (p);
+ if (endp != p)
+ {
+ /* This is a pattern. Skip over it. */
+ p = endp;
+ continue;
+ }
+ }
+
+ if (c == L('?'))
+ {
+ /* A ? needs to match one character. */
+ if (n == string_end)
+ /* There isn't another character; no match. */
+ return FNM_NOMATCH;
+ else if (*n == L('/')
+ && __builtin_expect (flags & FNM_FILE_NAME, 0))
+ /* A slash does not match a wildcard under
+ FNM_FILE_NAME. */
+ return FNM_NOMATCH;
+ else
+ /* One character of the string is consumed in matching
+ this ? wildcard, so *??? won't match if there are
+ less than three characters. */
+ ++n;
+ }
+ }
+
+ if (c == L('\0'))
+ /* The wildcard(s) is/are the last element of the pattern.
+ If the name is a file name and contains another slash
+ this means it cannot match, unless the FNM_LEADING_DIR
+ flag is set. */
+ {
+ int result = (flags & FNM_FILE_NAME) == 0 ? 0 : FNM_NOMATCH;
+
+ if (flags & FNM_FILE_NAME)
+ {
+ if (flags & FNM_LEADING_DIR)
+ result = 0;
+ else
+ {
+ if (MEMCHR (n, L('/'), string_end - n) == NULL)
+ result = 0;
+ }
+ }
+
+ return result;
+ }
+ else
+ {
+ const CHAR *endp;
+
+ endp = MEMCHR (n, (flags & FNM_FILE_NAME) ? L('/') : L('\0'),
+ string_end - n);
+ if (endp == NULL)
+ endp = string_end;
+
+ if (c == L('[')
+ || (__builtin_expect (flags & FNM_EXTMATCH, 0) != 0
+ && (c == L('@') || c == L('+') || c == L('!'))
+ && *p == L('(')))
+ {
+ int flags2 = ((flags & FNM_FILE_NAME)
+ ? flags : (flags & ~FNM_PERIOD));
+ int no_leading_period2 = no_leading_period;
+
+ for (--p; n < endp; ++n, no_leading_period2 = 0)
+ if (FCT (p, n, string_end, no_leading_period2, flags2)
+ == 0)
+ return 0;
+ }
+ else if (c == L('/') && (flags & FNM_FILE_NAME))
+ {
+ while (n < string_end && *n != L('/'))
+ ++n;
+ if (n < string_end && *n == L('/')
+ && (FCT (p, n + 1, string_end, flags & FNM_PERIOD, flags)
+ == 0))
+ return 0;
+ }
+ else
+ {
+ int flags2 = ((flags & FNM_FILE_NAME)
+ ? flags : (flags & ~FNM_PERIOD));
+ int no_leading_period2 = no_leading_period;
+
+ if (c == L('\\') && !(flags & FNM_NOESCAPE))
+ c = *p;
+ c = FOLD (c);
+ for (--p; n < endp; ++n, no_leading_period2 = 0)
+ if (FOLD ((UCHAR) *n) == c
+ && (FCT (p, n, string_end, no_leading_period2, flags2)
+ == 0))
+ return 0;
+ }
+ }
+
+ /* If we come here no match is possible with the wildcard. */
+ return FNM_NOMATCH;
+
+ case L('['):
+ {
+ /* Nonzero if the sense of the character class is inverted. */
+ register int not;
+ CHAR cold;
+ UCHAR fn;
+
+ if (posixly_correct == 0)
+ posixly_correct = __getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1;
+
+ if (n == string_end)
+ return FNM_NOMATCH;
+
+ if (*n == L('.') && no_leading_period)
+ return FNM_NOMATCH;
+
+ if (*n == L('/') && (flags & FNM_FILE_NAME))
+ /* `/' cannot be matched. */
+ return FNM_NOMATCH;
+
+ not = (*p == L('!') || (posixly_correct < 0 && *p == L('^')));
+ if (not)
+ ++p;
+
+ fn = FOLD ((UCHAR) *n);
+
+ c = *p++;
+ for (;;)
+ {
+ if (!(flags & FNM_NOESCAPE) && c == L('\\'))
+ {
+ if (*p == L('\0'))
+ return FNM_NOMATCH;
+ c = FOLD ((UCHAR) *p);
+ ++p;
+
+ goto normal_bracket;
+ }
+ else if (c == L('[') && *p == L(':'))
+ {
+ /* Leave room for the null. */
+ CHAR str[CHAR_CLASS_MAX_LENGTH + 1];
+ size_t c1 = 0;
+#if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H)
+ wctype_t wt;
+#endif
+ const CHAR *startp = p;
+
+ for (;;)
+ {
+ if (c1 == CHAR_CLASS_MAX_LENGTH)
+ /* The name is too long and therefore the pattern
+ is ill-formed. */
+ return FNM_NOMATCH;
+
+ c = *++p;
+ if (c == L(':') && p[1] == L(']'))
+ {
+ p += 2;
+ break;
+ }
+ if (c < L('a') || c >= L('z'))
+ {
+ /* This cannot possibly be a character class name.
+ Match it as a normal range. */
+ p = startp;
+ c = L('[');
+ goto normal_bracket;
+ }
+ str[c1++] = c;
+ }
+ str[c1] = L('\0');
+
+#if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H)
+ wt = IS_CHAR_CLASS (str);
+ if (wt == 0)
+ /* Invalid character class name. */
+ return FNM_NOMATCH;
+
+# if defined _LIBC && ! WIDE_CHAR_VERSION
+ /* The following code is glibc specific but does
+ there a good job in speeding up the code since
+ we can avoid the btowc() call. */
+ if (_ISCTYPE ((UCHAR) *n, wt))
+ goto matched;
+# else
+ if (ISWCTYPE (BTOWC ((UCHAR) *n), wt))
+ goto matched;
+# endif
+#else
+ if ((STREQ (str, L("alnum")) && ISALNUM ((UCHAR) *n))
+ || (STREQ (str, L("alpha")) && ISALPHA ((UCHAR) *n))
+ || (STREQ (str, L("blank")) && ISBLANK ((UCHAR) *n))
+ || (STREQ (str, L("cntrl")) && ISCNTRL ((UCHAR) *n))
+ || (STREQ (str, L("digit")) && ISDIGIT ((UCHAR) *n))
+ || (STREQ (str, L("graph")) && ISGRAPH ((UCHAR) *n))
+ || (STREQ (str, L("lower")) && ISLOWER ((UCHAR) *n))
+ || (STREQ (str, L("print")) && ISPRINT ((UCHAR) *n))
+ || (STREQ (str, L("punct")) && ISPUNCT ((UCHAR) *n))
+ || (STREQ (str, L("space")) && ISSPACE ((UCHAR) *n))
+ || (STREQ (str, L("upper")) && ISUPPER ((UCHAR) *n))
+ || (STREQ (str, L("xdigit")) && ISXDIGIT ((UCHAR) *n)))
+ goto matched;
+#endif
+ c = *p++;
+ }
+#ifdef _LIBC
+ else if (c == L('[') && *p == L('='))
+ {
+ UCHAR str[1];
+ uint32_t nrules =
+ _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+ const CHAR *startp = p;
+
+ c = *++p;
+ if (c == L('\0'))
+ {
+ p = startp;
+ c = L('[');
+ goto normal_bracket;
+ }
+ str[0] = c;
+
+ c = *++p;
+ if (c != L('=') || p[1] != L(']'))
+ {
+ p = startp;
+ c = L('[');
+ goto normal_bracket;
+ }
+ p += 2;
+
+ if (nrules == 0)
+ {
+ if ((UCHAR) *n == str[0])
+ goto matched;
+ }
+ else
+ {
+ const int32_t *table;
+# if WIDE_CHAR_VERSION
+ const int32_t *weights;
+ const int32_t *extra;
+# else
+ const unsigned char *weights;
+ const unsigned char *extra;
+# endif
+ const int32_t *indirect;
+ int32_t idx;
+ const UCHAR *cp = (const UCHAR *) str;
+
+ /* This #include defines a local function! */
+# if WIDE_CHAR_VERSION
+# include <locale/weightwc.h>
+# else
+# include <locale/weight.h>
+# endif
+
+# if WIDE_CHAR_VERSION
+ table = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEWC);
+ weights = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTWC);
+ extra = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAWC);
+ indirect = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTWC);
+# else
+ table = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
+ weights = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTMB);
+ extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
+ indirect = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
+# endif
+
+ idx = findidx (&cp);
+ if (idx != 0)
+ {
+ /* We found a table entry. Now see whether the
+ character we are currently at has the same
+ equivalance class value. */
+ int len = weights[idx];
+ int32_t idx2;
+ const UCHAR *np = (const UCHAR *) n;
+
+ idx2 = findidx (&np);
+ if (idx2 != 0 && len == weights[idx2])
+ {
+ int cnt = 0;
+
+ while (cnt < len
+ && (weights[idx + 1 + cnt]
+ == weights[idx2 + 1 + cnt]))
+ ++cnt;
+
+ if (cnt == len)
+ goto matched;
+ }
+ }
+ }
+
+ c = *p++;
+ }
+#endif
+ else if (c == L('\0'))
+ /* [ (unterminated) loses. */
+ return FNM_NOMATCH;
+ else
+ {
+ int is_range = 0;
+
+#ifdef _LIBC
+ int is_seqval = 0;
+
+ if (c == L('[') && *p == L('.'))
+ {
+ uint32_t nrules =
+ _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+ const CHAR *startp = p;
+ size_t c1 = 0;
+
+ while (1)
+ {
+ c = *++p;
+ if (c == L('.') && p[1] == L(']'))
+ {
+ p += 2;
+ break;
+ }
+ if (c == '\0')
+ return FNM_NOMATCH;
+ ++c1;
+ }
+
+ /* We have to handling the symbols differently in
+ ranges since then the collation sequence is
+ important. */
+ is_range = *p == L('-') && p[1] != L('\0');
+
+ if (nrules == 0)
+ {
+ /* There are no names defined in the collation
+ data. Therefore we only accept the trivial
+ names consisting of the character itself. */
+ if (c1 != 1)
+ return FNM_NOMATCH;
+
+ if (!is_range && *n == startp[1])
+ goto matched;
+
+ cold = startp[1];
+ c = *p++;
+ }
+ else
+ {
+ int32_t table_size;
+ const int32_t *symb_table;
+# ifdef WIDE_CHAR_VERSION
+ char str[c1];
+ unsigned int strcnt;
+# else
+# define str (startp + 1)
+# endif
+ const unsigned char *extra;
+ int32_t idx;
+ int32_t elem;
+ int32_t second;
+ int32_t hash;
+
+# ifdef WIDE_CHAR_VERSION
+ /* We have to convert the name to a single-byte
+ string. This is possible since the names
+ consist of ASCII characters and the internal
+ representation is UCS4. */
+ for (strcnt = 0; strcnt < c1; ++strcnt)
+ str[strcnt] = startp[1 + strcnt];
+#endif
+
+ table_size =
+ _NL_CURRENT_WORD (LC_COLLATE,
+ _NL_COLLATE_SYMB_HASH_SIZEMB);
+ symb_table = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_SYMB_TABLEMB);
+ extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_SYMB_EXTRAMB);
+
+ /* Locate the character in the hashing table. */
+ hash = elem_hash (str, c1);
+
+ idx = 0;
+ elem = hash % table_size;
+ if (symb_table[2 * elem] != 0)
+ {
+ second = hash % (table_size - 2) + 1;
+
+ do
+ {
+ /* First compare the hashing value. */
+ if (symb_table[2 * elem] == hash
+ && (c1
+ == extra[symb_table[2 * elem + 1]])
+ && __memcmp (str,
+ &extra[symb_table[2 * elem
+ + 1]
+ + 1], c1) == 0)
+ {
+ /* Yep, this is the entry. */
+ idx = symb_table[2 * elem + 1];
+ idx += 1 + extra[idx];
+ break;
+ }
+
+ /* Next entry. */
+ elem += second;
+ }
+ while (symb_table[2 * elem] != 0);
+ }
+
+ if (symb_table[2 * elem] != 0)
+ {
+ /* Compare the byte sequence but only if
+ this is not part of a range. */
+# ifdef WIDE_CHAR_VERSION
+ int32_t *wextra;
+
+ idx += 1 + extra[idx];
+ /* Adjust for the alignment. */
+ idx = (idx + 3) & ~3;
+
+ wextra = (int32_t *) &extra[idx + 4];
+# endif
+
+ if (! is_range)
+ {
+# ifdef WIDE_CHAR_VERSION
+ for (c1 = 0;
+ (int32_t) c1 < wextra[idx];
+ ++c1)
+ if (n[c1] != wextra[1 + c1])
+ break;
+
+ if ((int32_t) c1 == wextra[idx])
+ goto matched;
+# else
+ for (c1 = 0; c1 < extra[idx]; ++c1)
+ if (n[c1] != extra[1 + c1])
+ break;
+
+ if (c1 == extra[idx])
+ goto matched;
+# endif
+ }
+
+ /* Get the collation sequence value. */
+ is_seqval = 1;
+# ifdef WIDE_CHAR_VERSION
+ cold = wextra[1 + wextra[idx]];
+# else
+ /* Adjust for the alignment. */
+ idx += 1 + extra[idx];
+ idx = (idx + 3) & ~4;
+ cold = *((int32_t *) &extra[idx]);
+# endif
+
+ c = *p++;
+ }
+ else if (c1 == 1)
+ {
+ /* No valid character. Match it as a
+ single byte. */
+ if (!is_range && *n == str[0])
+ goto matched;
+
+ cold = str[0];
+ c = *p++;
+ }
+ else
+ return FNM_NOMATCH;
+ }
+ }
+ else
+# undef str
+#endif
+ {
+ c = FOLD (c);
+ normal_bracket:
+
+ /* We have to handling the symbols differently in
+ ranges since then the collation sequence is
+ important. */
+ is_range = (*p == L('-') && p[1] != L('\0')
+ && p[1] != L(']'));
+
+ if (!is_range && c == fn)
+ goto matched;
+
+ /* This is needed if we goto normal_bracket; from
+ outside of is_seqval's scope. */
+#ifndef __UCLIBC__ /* this should be probably ifdef _LIBC*/
+ is_seqval = 0;
+#endif
+ cold = c;
+ c = *p++;
+ }
+
+ if (c == L('-') && *p != L(']'))
+ {
+#if _LIBC
+ /* We have to find the collation sequence
+ value for C. Collation sequence is nothing
+ we can regularly access. The sequence
+ value is defined by the order in which the
+ definitions of the collation values for the
+ various characters appear in the source
+ file. A strange concept, nowhere
+ documented. */
+ uint32_t fcollseq;
+ uint32_t lcollseq;
+ UCHAR cend = *p++;
+
+# ifdef WIDE_CHAR_VERSION
+ /* Search in the `names' array for the characters. */
+ fcollseq = __collseq_table_lookup (collseq, fn);
+ if (fcollseq == ~((uint32_t) 0))
+ /* XXX We don't know anything about the character
+ we are supposed to match. This means we are
+ failing. */
+ goto range_not_matched;
+
+ if (is_seqval)
+ lcollseq = cold;
+ else
+ lcollseq = __collseq_table_lookup (collseq, cold);
+# else
+ fcollseq = collseq[fn];
+ lcollseq = is_seqval ? cold : collseq[(UCHAR) cold];
+# endif
+
+ is_seqval = 0;
+ if (cend == L('[') && *p == L('.'))
+ {
+ uint32_t nrules =
+ _NL_CURRENT_WORD (LC_COLLATE,
+ _NL_COLLATE_NRULES);
+ const CHAR *startp = p;
+ size_t c1 = 0;
+
+ while (1)
+ {
+ c = *++p;
+ if (c == L('.') && p[1] == L(']'))
+ {
+ p += 2;
+ break;
+ }
+ if (c == '\0')
+ return FNM_NOMATCH;
+ ++c1;
+ }
+
+ if (nrules == 0)
+ {
+ /* There are no names defined in the
+ collation data. Therefore we only
+ accept the trivial names consisting
+ of the character itself. */
+ if (c1 != 1)
+ return FNM_NOMATCH;
+
+ cend = startp[1];
+ }
+ else
+ {
+ int32_t table_size;
+ const int32_t *symb_table;
+# ifdef WIDE_CHAR_VERSION
+ char str[c1];
+ unsigned int strcnt;
+# else
+# define str (startp + 1)
+# endif
+ const unsigned char *extra;
+ int32_t idx;
+ int32_t elem;
+ int32_t second;
+ int32_t hash;
+
+# ifdef WIDE_CHAR_VERSION
+ /* We have to convert the name to a single-byte
+ string. This is possible since the names
+ consist of ASCII characters and the internal
+ representation is UCS4. */
+ for (strcnt = 0; strcnt < c1; ++strcnt)
+ str[strcnt] = startp[1 + strcnt];
+# endif
+
+ table_size =
+ _NL_CURRENT_WORD (LC_COLLATE,
+ _NL_COLLATE_SYMB_HASH_SIZEMB);
+ symb_table = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_SYMB_TABLEMB);
+ extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_SYMB_EXTRAMB);
+
+ /* Locate the character in the hashing
+ table. */
+ hash = elem_hash (str, c1);
+
+ idx = 0;
+ elem = hash % table_size;
+ if (symb_table[2 * elem] != 0)
+ {
+ second = hash % (table_size - 2) + 1;
+
+ do
+ {
+ /* First compare the hashing value. */
+ if (symb_table[2 * elem] == hash
+ && (c1
+ == extra[symb_table[2 * elem + 1]])
+ && __memcmp (str,
+ &extra[symb_table[2 * elem + 1]
+ + 1], c1) == 0)
+ {
+ /* Yep, this is the entry. */
+ idx = symb_table[2 * elem + 1];
+ idx += 1 + extra[idx];
+ break;
+ }
+
+ /* Next entry. */
+ elem += second;
+ }
+ while (symb_table[2 * elem] != 0);
+ }
+
+ if (symb_table[2 * elem] != 0)
+ {
+ /* Compare the byte sequence but only if
+ this is not part of a range. */
+# ifdef WIDE_CHAR_VERSION
+ int32_t *wextra;
+
+ idx += 1 + extra[idx];
+ /* Adjust for the alignment. */
+ idx = (idx + 3) & ~4;
+
+ wextra = (int32_t *) &extra[idx + 4];
+# endif
+ /* Get the collation sequence value. */
+ is_seqval = 1;
+# ifdef WIDE_CHAR_VERSION
+ cend = wextra[1 + wextra[idx]];
+# else
+ /* Adjust for the alignment. */
+ idx += 1 + extra[idx];
+ idx = (idx + 3) & ~4;
+ cend = *((int32_t *) &extra[idx]);
+# endif
+ }
+ else if (symb_table[2 * elem] != 0 && c1 == 1)
+ {
+ cend = str[0];
+ c = *p++;
+ }
+ else
+ return FNM_NOMATCH;
+ }
+# undef str
+ }
+ else
+ {
+ if (!(flags & FNM_NOESCAPE) && cend == L('\\'))
+ cend = *p++;
+ if (cend == L('\0'))
+ return FNM_NOMATCH;
+ cend = FOLD (cend);
+ }
+
+ /* XXX It is not entirely clear to me how to handle
+ characters which are not mentioned in the
+ collation specification. */
+ if (
+# ifdef WIDE_CHAR_VERSION
+ lcollseq == 0xffffffff ||
+# endif
+ lcollseq <= fcollseq)
+ {
+ /* We have to look at the upper bound. */
+ uint32_t hcollseq;
+
+ if (is_seqval)
+ hcollseq = cend;
+ else
+ {
+# ifdef WIDE_CHAR_VERSION
+ hcollseq =
+ __collseq_table_lookup (collseq, cend);
+ if (hcollseq == ~((uint32_t) 0))
+ {
+ /* Hum, no information about the upper
+ bound. The matching succeeds if the
+ lower bound is matched exactly. */
+ if (lcollseq != fcollseq)
+ goto range_not_matched;
+
+ goto matched;
+ }
+# else
+ hcollseq = collseq[cend];
+# endif
+ }
+
+ if (lcollseq <= hcollseq && fcollseq <= hcollseq)
+ goto matched;
+ }
+# ifdef WIDE_CHAR_VERSION
+ range_not_matched:
+# endif
+#else
+ /* We use a boring value comparison of the character
+ values. This is better than comparing using
+ `strcoll' since the latter would have surprising
+ and sometimes fatal consequences. */
+ UCHAR cend = *p++;
+
+ if (!(flags & FNM_NOESCAPE) && cend == L('\\'))
+ cend = *p++;
+ if (cend == L('\0'))
+ return FNM_NOMATCH;
+
+ /* It is a range. */
+ if (cold <= fn && fn <= cend)
+ goto matched;
+#endif
+
+ c = *p++;
+ }
+ }
+
+ if (c == L(']'))
+ break;
+ }
+
+ if (!not)
+ return FNM_NOMATCH;
+ break;
+
+ matched:
+ /* Skip the rest of the [...] that already matched. */
+ do
+ {
+ ignore_next:
+ c = *p++;
+
+ if (c == L('\0'))
+ /* [... (unterminated) loses. */
+ return FNM_NOMATCH;
+
+ if (!(flags & FNM_NOESCAPE) && c == L('\\'))
+ {
+ if (*p == L('\0'))
+ return FNM_NOMATCH;
+ /* XXX 1003.2d11 is unclear if this is right. */
+ ++p;
+ }
+ else if (c == L('[') && *p == L(':'))
+ {
+ int c1 = 0;
+ const CHAR *startp = p;
+
+ while (1)
+ {
+ c = *++p;
+ if (++c1 == CHAR_CLASS_MAX_LENGTH)
+ return FNM_NOMATCH;
+
+ if (*p == L(':') && p[1] == L(']'))
+ break;
+
+ if (c < L('a') || c >= L('z'))
+ {
+ p = startp;
+ goto ignore_next;
+ }
+ }
+ p += 2;
+ c = *p++;
+ }
+ else if (c == L('[') && *p == L('='))
+ {
+ c = *++p;
+ if (c == L('\0'))
+ return FNM_NOMATCH;
+ c = *++p;
+ if (c != L('=') || p[1] != L(']'))
+ return FNM_NOMATCH;
+ p += 2;
+ c = *p++;
+ }
+ else if (c == L('[') && *p == L('.'))
+ {
+ ++p;
+ while (1)
+ {
+ c = *++p;
+ if (c == '\0')
+ return FNM_NOMATCH;
+
+ if (*p == L('.') && p[1] == L(']'))
+ break;
+ }
+ p += 2;
+ c = *p++;
+ }
+ }
+ while (c != L(']'));
+ if (not)
+ return FNM_NOMATCH;
+ }
+ break;
+
+ case L('+'):
+ case L('@'):
+ case L('!'):
+ if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(')
+ {
+ int res;
+
+ res = EXT (c, p, n, string_end, no_leading_period, flags);
+ if (res != -1)
+ return res;
+ }
+ goto normal_match;
+
+ case L('/'):
+ if (NO_LEADING_PERIOD (flags))
+ {
+ if (n == string_end || c != (UCHAR) *n)
+ return FNM_NOMATCH;
+
+ new_no_leading_period = 1;
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ normal_match:
+ if (n == string_end || c != FOLD ((UCHAR) *n))
+ return FNM_NOMATCH;
+ }
+
+ no_leading_period = new_no_leading_period;
+ ++n;
+ }
+
+ if (n == string_end)
+ return 0;
+
+ if ((flags & FNM_LEADING_DIR) && n != string_end && *n == L('/'))
+ /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
+ return 0;
+
+ return FNM_NOMATCH;
+}
+
+
+static const CHAR *
+internal_function
+END (const CHAR *pattern)
+{
+ const CHAR *p = pattern;
+
+ while (1)
+ if (*++p == L('\0'))
+ /* This is an invalid pattern. */
+ return pattern;
+ else if (*p == L('['))
+ {
+ /* Handle brackets special. */
+ if (posixly_correct == 0)
+ posixly_correct = __getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1;
+
+ /* Skip the not sign. We have to recognize it because of a possibly
+ following ']'. */
+ if (*++p == L('!') || (posixly_correct < 0 && *p == L('^')))
+ ++p;
+ /* A leading ']' is recognized as such. */
+ if (*p == L(']'))
+ ++p;
+ /* Skip over all characters of the list. */
+ while (*p != L(']'))
+ if (*p++ == L('\0'))
+ /* This is no valid pattern. */
+ return pattern;
+ }
+ else if ((*p == L('?') || *p == L('*') || *p == L('+') || *p == L('@')
+ || *p == L('!')) && p[1] == L('('))
+ p = END (p + 1);
+ else if (*p == L(')'))
+ break;
+
+ return p + 1;
+}
+
+
+static int
+internal_function
+EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
+ int no_leading_period, int flags)
+{
+ const CHAR *startp;
+ int level;
+ struct patternlist
+ {
+ struct patternlist *next;
+ CHAR str[0];
+ } *list = NULL;
+ struct patternlist **lastp = &list;
+ size_t pattern_len = STRLEN (pattern);
+ const CHAR *p;
+ const CHAR *rs;
+
+ /* Parse the pattern. Store the individual parts in the list. */
+ level = 0;
+ for (startp = p = pattern + 1; level >= 0; ++p)
+ if (*p == L('\0'))
+ /* This is an invalid pattern. */
+ return -1;
+ else if (*p == L('['))
+ {
+ /* Handle brackets special. */
+ if (posixly_correct == 0)
+ posixly_correct = __getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1;
+
+ /* Skip the not sign. We have to recognize it because of a possibly
+ following ']'. */
+ if (*++p == L('!') || (posixly_correct < 0 && *p == L('^')))
+ ++p;
+ /* A leading ']' is recognized as such. */
+ if (*p == L(']'))
+ ++p;
+ /* Skip over all characters of the list. */
+ while (*p != L(']'))
+ if (*p++ == L('\0'))
+ /* This is no valid pattern. */
+ return -1;
+ }
+ else if ((*p == L('?') || *p == L('*') || *p == L('+') || *p == L('@')
+ || *p == L('!')) && p[1] == L('('))
+ /* Remember the nesting level. */
+ ++level;
+ else if (*p == L(')'))
+ {
+ if (level-- == 0)
+ {
+ /* This means we found the end of the pattern. */
+#define NEW_PATTERN \
+ struct patternlist *newp; \
+ \
+ if (opt == L('?') || opt == L('@')) \
+ newp = alloca (sizeof (struct patternlist) \
+ + (pattern_len * sizeof (CHAR))); \
+ else \
+ newp = alloca (sizeof (struct patternlist) \
+ + ((p - startp + 1) * sizeof (CHAR))); \
+ *((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L('\0'); \
+ newp->next = NULL; \
+ *lastp = newp; \
+ lastp = &newp->next
+ NEW_PATTERN;
+ }
+ }
+ else if (*p == L('|'))
+ {
+ if (level == 0)
+ {
+ NEW_PATTERN;
+ startp = p + 1;
+ }
+ }
+ assert (list != NULL);
+ assert (p[-1] == L(')'));
+#undef NEW_PATTERN
+
+ switch (opt)
+ {
+ case L('*'):
+ if (FCT (p, string, string_end, no_leading_period, flags) == 0)
+ return 0;
+ /* FALLTHROUGH */
+
+ case L('+'):
+ do
+ {
+ for (rs = string; rs <= string_end; ++rs)
+ /* First match the prefix with the current pattern with the
+ current pattern. */
+ if (FCT (list->str, string, rs, no_leading_period,
+ flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0
+ /* This was successful. Now match the rest with the rest
+ of the pattern. */
+ && (FCT (p, rs, string_end,
+ rs == string
+ ? no_leading_period
+ : rs[-1] == '/' && NO_LEADING_PERIOD (flags) ? 1 : 0,
+ flags & FNM_FILE_NAME
+ ? flags : flags & ~FNM_PERIOD) == 0
+ /* This didn't work. Try the whole pattern. */
+ || (rs != string
+ && FCT (pattern - 1, rs, string_end,
+ rs == string
+ ? no_leading_period
+ : (rs[-1] == '/' && NO_LEADING_PERIOD (flags)
+ ? 1 : 0),
+ flags & FNM_FILE_NAME
+ ? flags : flags & ~FNM_PERIOD) == 0)))
+ /* It worked. Signal success. */
+ return 0;
+ }
+ while ((list = list->next) != NULL);
+
+ /* None of the patterns lead to a match. */
+ return FNM_NOMATCH;
+
+ case L('?'):
+ if (FCT (p, string, string_end, no_leading_period, flags) == 0)
+ return 0;
+ /* FALLTHROUGH */
+
+ case L('@'):
+ do
+ /* I cannot believe it but `strcat' is actually acceptable
+ here. Match the entire string with the prefix from the
+ pattern list and the rest of the pattern following the
+ pattern list. */
+ if (FCT (STRCAT (list->str, p), string, string_end,
+ no_leading_period,
+ flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0)
+ /* It worked. Signal success. */
+ return 0;
+ while ((list = list->next) != NULL);
+
+ /* None of the patterns lead to a match. */
+ return FNM_NOMATCH;
+
+ case L('!'):
+ for (rs = string; rs <= string_end; ++rs)
+ {
+ struct patternlist *runp;
+
+ for (runp = list; runp != NULL; runp = runp->next)
+ if (FCT (runp->str, string, rs, no_leading_period,
+ flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0)
+ break;
+
+ /* If none of the patterns matched see whether the rest does. */
+ if (runp == NULL
+ && (FCT (p, rs, string_end,
+ rs == string
+ ? no_leading_period
+ : rs[-1] == '/' && NO_LEADING_PERIOD (flags) ? 1 : 0,
+ flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD)
+ == 0))
+ /* This is successful. */
+ return 0;
+ }
+
+ /* None of the patterns together with the rest of the pattern
+ lead to a match. */
+ return FNM_NOMATCH;
+
+ default:
+ assert (! "Invalid extended matching operator");
+ break;
+ }
+
+ return -1;
+}
+
+
+#undef FOLD
+#undef CHAR
+#undef UCHAR
+#undef INT
+#undef FCT
+#undef EXT
+#undef END
+#undef MEMPCPY
+#undef MEMCHR
+#undef STRCOLL
+#undef STRLEN
+#undef STRCAT
+#undef L
+#undef BTOWC
diff --git a/libc/misc/fnmatch/fnmatch_old.c b/libc/misc/fnmatch/fnmatch_old.c
new file mode 100644
index 000000000..384756569
--- /dev/null
+++ b/libc/misc/fnmatch/fnmatch_old.c
@@ -0,0 +1,224 @@
+/* Copyright (C) 1991, 1992, 1993, 1996 Free Software Foundation, Inc.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Enable GNU extensions in fnmatch.h. */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+
+#include <errno.h>
+#include <fnmatch.h>
+#include <ctype.h>
+
+/* Comment out all this code if we are using the GNU C Library, and are not
+ actually compiling the library itself. This code is part of the GNU C
+ Library, but also included in many other GNU distributions. Compiling
+ and linking in this code is a waste when using the GNU C library
+ (especially if it is a shared library). Rather than having every GNU
+ program understand `configure --with-gnu-libc' and omit the object files,
+ it is simpler to just do this in the source for each such file. */
+
+#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
+
+
+# if defined (STDC_HEADERS) || !defined (isascii)
+# define ISASCII(c) 1
+# else
+# define ISASCII(c) isascii(c)
+# endif
+
+# define ISUPPER(c) (ISASCII (c) && isupper (c))
+
+
+/* Match STRING against the filename pattern PATTERN, returning zero if
+ it matches, nonzero if not. */
+int attribute_hidden __fnmatch(const char *pattern, const char *string, int flags)
+{
+ register const char *p = pattern, *n = string;
+ register char c;
+
+/* Note that this evaluates C many times. */
+# define FOLD(c) ((flags & FNM_CASEFOLD) && ISUPPER (c) ? __tolower (c) : (c))
+
+ while ((c = *p++) != '\0') {
+ c = FOLD(c);
+
+ switch (c) {
+ case '?':
+ if (*n == '\0')
+ return FNM_NOMATCH;
+ else if ((flags & FNM_FILE_NAME) && *n == '/')
+ return FNM_NOMATCH;
+ else if ((flags & FNM_PERIOD) && *n == '.' &&
+ (n == string
+ || ((flags & FNM_FILE_NAME)
+ && n[-1] == '/'))) return FNM_NOMATCH;
+ break;
+
+ case '\\':
+ if (!(flags & FNM_NOESCAPE)) {
+ c = *p++;
+ if (c == '\0')
+ /* Trailing \ loses. */
+ return FNM_NOMATCH;
+ c = FOLD(c);
+ }
+ if (FOLD(*n) != c)
+ return FNM_NOMATCH;
+ break;
+
+ case '*':
+ if ((flags & FNM_PERIOD) && *n == '.' &&
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+ return FNM_NOMATCH;
+
+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
+ if ((flags & FNM_FILE_NAME) && *n == '/')
+ /* A slash does not match a wildcard under FNM_FILE_NAME. */
+ return FNM_NOMATCH;
+ else if (c == '?') {
+ /* A ? needs to match one character. */
+ if (*n == '\0')
+ /* There isn't another character; no match. */
+ return FNM_NOMATCH;
+ else
+ /* One character of the string is consumed in matching
+ this ? wildcard, so *??? won't match if there are
+ less than three characters. */
+ ++n;
+ }
+ }
+
+ if (c == '\0')
+ return 0;
+
+ {
+ char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
+
+ c1 = FOLD(c1);
+ for (--p; *n != '\0'; ++n)
+ if ((c == '[' || FOLD(*n) == c1) &&
+ __fnmatch(p, n, flags & ~FNM_PERIOD) == 0)
+ return 0;
+ return FNM_NOMATCH;
+ }
+
+ case '[':
+ {
+ /* Nonzero if the sense of the character class is inverted. */
+ register int not;
+
+ if (*n == '\0')
+ return FNM_NOMATCH;
+
+ if ((flags & FNM_PERIOD) && *n == '.' &&
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
+ return FNM_NOMATCH;
+
+ not = (*p == '!' || *p == '^');
+ if (not)
+ ++p;
+
+ c = *p++;
+ for (;;) {
+ register char cstart = c, cend = c;
+
+ if (!(flags & FNM_NOESCAPE) && c == '\\') {
+ if (*p == '\0')
+ return FNM_NOMATCH;
+ cstart = cend = *p++;
+ }
+
+ cstart = cend = FOLD(cstart);
+
+ if (c == '\0')
+ /* [ (unterminated) loses. */
+ return FNM_NOMATCH;
+
+ c = *p++;
+ c = FOLD(c);
+
+ if ((flags & FNM_FILE_NAME) && c == '/')
+ /* [/] can never match. */
+ return FNM_NOMATCH;
+
+ if (c == '-' && *p != ']') {
+ cend = *p++;
+ if (!(flags & FNM_NOESCAPE) && cend == '\\')
+ cend = *p++;
+ if (cend == '\0')
+ return FNM_NOMATCH;
+ cend = FOLD(cend);
+
+ c = *p++;
+ }
+
+ if (FOLD(*n) >= cstart && FOLD(*n) <= cend)
+ goto matched;
+
+ if (c == ']')
+ break;
+ }
+ if (!not)
+ return FNM_NOMATCH;
+ break;
+
+ matched:;
+ /* Skip the rest of the [...] that already matched. */
+ while (c != ']') {
+ if (c == '\0')
+ /* [... (unterminated) loses. */
+ return FNM_NOMATCH;
+
+ c = *p++;
+ if (!(flags & FNM_NOESCAPE) && c == '\\') {
+ if (*p == '\0')
+ return FNM_NOMATCH;
+ /* XXX 1003.2d11 is unclear if this is right. */
+ ++p;
+ }
+ }
+ if (not)
+ return FNM_NOMATCH;
+ }
+ break;
+
+ default:
+ if (c != FOLD(*n))
+ return FNM_NOMATCH;
+ }
+
+ ++n;
+ }
+
+ if (*n == '\0')
+ return 0;
+
+ if ((flags & FNM_LEADING_DIR) && *n == '/')
+ /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
+ return 0;
+
+ return FNM_NOMATCH;
+
+# undef FOLD
+}
+strong_alias(__fnmatch,fnmatch)
+#endif /* _LIBC or not __GNU_LIBRARY__. */
diff --git a/libc/misc/ftw/Makefile.in b/libc/misc/ftw/Makefile.in
index c2cabfa0e..6c0304bc8 100644
--- a/libc/misc/ftw/Makefile.in
+++ b/libc/misc/ftw/Makefile.in
@@ -5,36 +5,23 @@
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
-MSRC:=ftw.c
-MOBJ:=ftw.o ftw64.o
+SRC := ftw.c
+ifeq ($(UCLIBC_HAS_LFS),y)
+SRC += ftw64.c
+endif
-MISC_FTW_DIR:=$(top_srcdir)libc/misc/ftw
-MISC_FTW_OUT:=$(top_builddir)libc/misc/ftw
+MISC_FTW_DIR := $(top_srcdir)libc/misc/ftw
+MISC_FTW_OUT := $(top_builddir)libc/misc/ftw
-# ftw.c has to be rewritten to allow multi
-MISC_FTW_NO_MULTI:=ftw64.o
+MISC_FTW_SRC := $(patsubst %.c,$(MISC_FTW_DIR)/%.c,$(SRC))
+MISC_FTW_OBJ := $(patsubst %.c,$(MISC_FTW_OUT)/%.o,$(SRC))
-MISC_FTW_MSRC:=$(MISC_FTW_DIR)/$(MSRC)
-MISC_FTW_MOBJ:=$(patsubst %.o,$(MISC_FTW_OUT)/%.o,$(MOBJ))
+libc-a-$(UCLIBC_HAS_FTW) += $(MISC_FTW_OBJ)
+libc-so-$(UCLIBC_HAS_FTW) += $(MISC_FTW_OBJ:.o=.os)
-MISC_FTW_DEF:=$(patsubst %,-DL_%,$(subst .o,,$(filter-out $(MISC_FTW_NO_MULTI),$(notdir $(MISC_FTW_MOBJ)))))
+libc-multi-$(UCLIBC_HAS_FTW) += $(MISC_FTW_SRC)
-MISC_FTW_OBJS:=$(MISC_FTW_MOBJ)
-
-$(MISC_FTW_OBJS): $(MISC_FTW_MSRC)
- $(compile.m)
-
-$(MISC_FTW_OBJS:.o=.os): $(MISC_FTW_MSRC)
- $(compile.m)
-
-libc-a-$(UCLIBC_HAS_FTW)+=$(MISC_FTW_OBJS)
-libc-so-$(UCLIBC_HAS_FTW)+=$(MISC_FTW_OBJS:.o=.os)
-
-CFLAGS-multi-$(UCLIBC_HAS_FTW)+=$(MISC_FTW_DEF)
-libc-multi-$(UCLIBC_HAS_FTW)+=$(MISC_FTW_MSRC)
-libc-nomulti-$(UCLIBC_HAS_FTW)+=$(patsubst %.o,$(MISC_FTW_OUT)/%.o,$(MISC_FTW_NO_MULTI))
-
-objclean-y+=misc_ftw_objclean
+objclean-y += misc_ftw_objclean
misc_ftw_objclean:
$(RM) $(MISC_FTW_OUT)/*.{o,os}
diff --git a/libc/misc/ftw/ftw.c b/libc/misc/ftw/ftw.c
index 30009def9..fdea1c208 100644
--- a/libc/misc/ftw/ftw.c
+++ b/libc/misc/ftw/ftw.c
@@ -1,5 +1,5 @@
/* File tree walker functions.
- Copyright (C) 1996-2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1996-2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -18,65 +18,68 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-/* used by D_EXACT_NAMLEN */
-#define strlen __strlen
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
-#define mempcpy __mempcpy
-#define stpcpy __stpcpy
+#define _GNU_SOURCE
+#define _XOPEN_SOURCE 500
+#include <features.h>
+#ifdef __UCLIBC__
+#undef _LIBC
+#define HAVE_DIRENT_H 1
+#define HAVE_SYS_PARAM_H 1
+#define HAVE_DECL_STPCPY 1
+#define HAVE_MEMPCPY 1
+#define dirfd __dirfd
#define tsearch __tsearch
-#define tdestroy __tdestroy
#define tfind __tfind
-#define fchdir __fchdir
-#define chdir __chdir
-#define dirfd __dirfd
+#define tdestroy __tdestroy
#define getcwd __getcwd
+#define chdir __chdir
+#define fchdir __fchdir
+#define mempcpy __mempcpy
#define opendir __opendir
#define closedir __closedir
-
-#define _GNU_SOURCE
-#include <features.h>
-
-
-#if defined (__UCLIBC_HAS_LFS__) && defined L_ftw64
-#ifndef L_ftw
-#define L_ftw
+#define stpcpy __stpcpy
#endif
-/* If Large file support is enabled, transparently remap
- * things to use the 64-bit interfaces */
-#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64
-#undef _FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS 64
-#endif
-#ifndef __USE_LARGEFILE64
-# define __USE_LARGEFILE64 1
-#endif
-#ifndef __USE_FILE_OFFSET64
-# define __USE_FILE_OFFSET64 1
+#if __GNUC__
+# define alloca __builtin_alloca
+#else
+# if HAVE_ALLOCA_H
+# include <alloca.h>
+# else
+# ifdef _AIX
+ # pragma alloca
+# else
+char *alloca ();
+# endif
+# endif
#endif
-#define FTW_NAME ftw64
-#define NFTW_NAME nftw64
-#define INO_T ino64_t
-#define STAT stat64
-#define LSTAT lstat64
-#define XSTAT stat64
-#define FTW_FUNC_T __ftw64_func_t
-#define NFTW_FUNC_T __nftw64_func_t
+#if defined _LIBC
+# include <dirent.h>
+# define NAMLEN(dirent) _D_EXACT_NAMLEN (dirent)
#else
-#define FTW_NAME ftw
-#define NFTW_NAME nftw
-#define INO_T ino_t
-#define STAT stat
-#define LSTAT lstat
-#define XSTAT stat
-#define FTW_FUNC_T __ftw_func_t
-#define NFTW_FUNC_T __nftw_func_t
+# if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) __strlen ((dirent)->d_name)
+# else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+# include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+# include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+# include <ndir.h>
+# endif
+# endif
#endif
-#ifdef L_ftw
-
-#include <alloca.h>
#include <errno.h>
#include <ftw.h>
#include <limits.h>
@@ -84,10 +87,102 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <sys/param.h>
-#include <sys/stat.h>
+#if HAVE_SYS_PARAM_H || defined _LIBC
+# include <sys/param.h>
+#endif
+#ifdef _LIBC
+# include <include/sys/stat.h>
+#else
+# include <sys/stat.h>
+#endif
+
+#if ! _LIBC && !HAVE_DECL_STPCPY && !defined stpcpy
+char *stpcpy ();
+#endif
+
+#if ! _LIBC && ! defined HAVE_MEMPCPY && ! defined mempcpy
+/* Be CAREFUL that there are no side effects in N. */
+# define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
+#endif
+
+/* #define NDEBUG 1 */
#include <assert.h>
-#include <dirent.h>
+
+#if !defined _LIBC && !defined __UCLIBC__
+# undef __chdir
+# define __chdir chdir
+# undef __closedir
+# define __closedir closedir
+# undef __fchdir
+# define __fchdir fchdir
+# ifndef __UCLIBC__
+# undef __getcwd
+# define __getcwd(P, N) xgetcwd ()
+extern char *xgetcwd (void);
+# endif
+# undef __mempcpy
+# define __mempcpy mempcpy
+# undef __opendir
+# define __opendir opendir
+# undef __readdir64
+# define __readdir64 readdir
+# undef __stpcpy
+# define __stpcpy stpcpy
+# undef __tdestroy
+# define __tdestroy tdestroy
+# undef __tfind
+# define __tfind tfind
+# undef __tsearch
+# define __tsearch tsearch
+# undef internal_function
+# define internal_function /* empty */
+# undef dirent64
+# define dirent64 dirent
+# undef MAX
+# define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
+/* Arrange to make lstat calls go through the wrapper function
+ on systems with an lstat function that does not dereference symlinks
+ that are specified with a trailing slash. */
+#if ! _LIBC && ! LSTAT_FOLLOWS_SLASHED_SYMLINK && !defined __UCLIBC__
+int rpl_lstat (const char *, struct stat *);
+# undef lstat
+# define lstat(Name, Stat_buf) rpl_lstat(Name, Stat_buf)
+#endif
+
+#ifndef __set_errno
+# define __set_errno(Val) errno = (Val)
+#endif
+
+/* Support for the LFS API version. */
+#ifndef FTW_NAME
+# define FTW_NAME ftw
+# define NFTW_NAME nftw
+# define NFTW_OLD_NAME __old_nftw
+# define NFTW_NEW_NAME __new_nftw
+# define INO_T ino_t
+# define STAT stat
+# ifdef _LIBC
+# define LXSTAT __lxstat
+# define XSTAT __xstat
+# else
+# ifdef __UCLIBC__
+# define LXSTAT(V,f,sb) __lstat(f,sb)
+# define XSTAT(V,f,sb) __stat(f,sb)
+# define __readdir64 __readdir
+# define dirent64 dirent
+# else
+# define LXSTAT(V,f,sb) lstat (f,sb)
+# define XSTAT(V,f,sb) stat (f,sb)
+# endif
+# endif
+# define FTW_FUNC_T __ftw_func_t
+# define NFTW_FUNC_T __nftw_func_t
+extern struct dirent *__readdir (DIR *__dirp) __nonnull ((1)) attribute_hidden;
+# else
+extern struct dirent64 *__readdir64 (DIR *__dirp) __nonnull ((1)) attribute_hidden;
+#endif
/* We define PATH_MAX if the system does not provide a definition.
This does not artificially limit any operation. PATH_MAX is simply
@@ -99,48 +194,48 @@
struct dir_data
{
- DIR *stream;
- char *content;
+ DIR *stream;
+ char *content;
};
struct known_object
{
- dev_t dev;
- INO_T ino;
+ dev_t dev;
+ INO_T ino;
};
struct ftw_data
{
- /* Array with pointers to open directory streams. */
- struct dir_data **dirstreams;
- size_t actdir;
- size_t maxdir;
+ /* Array with pointers to open directory streams. */
+ struct dir_data **dirstreams;
+ size_t actdir;
+ size_t maxdir;
- /* Buffer containing name of currently processed object. */
- char *dirbuf;
- size_t dirbufsize;
+ /* Buffer containing name of currently processed object. */
+ char *dirbuf;
+ size_t dirbufsize;
- /* Passed as fourth argument to `nftw' callback. The `base' member
- tracks the content of the `dirbuf'. */
- struct FTW ftw;
+ /* Passed as fourth argument to `nftw' callback. The `base' member
+ tracks the content of the `dirbuf'. */
+ struct FTW ftw;
- /* Flags passed to `nftw' function. 0 for `ftw'. */
- int flags;
+ /* Flags passed to `nftw' function. 0 for `ftw'. */
+ int flags;
- /* Conversion array for flag values. It is the identity mapping for
- `nftw' calls, otherwise it maps the values to those known by
- `ftw'. */
- const int *cvt_arr;
+ /* Conversion array for flag values. It is the identity mapping for
+ `nftw' calls, otherwise it maps the values to those known by
+ `ftw'. */
+ const int *cvt_arr;
- /* Callback function. We always use the `nftw' form. */
- NFTW_FUNC_T func;
+ /* Callback function. We always use the `nftw' form. */
+ NFTW_FUNC_T func;
- /* Device of starting point. Needed for FTW_MOUNT. */
- dev_t dev;
+ /* Device of starting point. Needed for FTW_MOUNT. */
+ dev_t dev;
- /* Data structure for keeping fingerprints of already processed
- object. This is needed when not using FTW_PHYS. */
- void *known_objects;
+ /* Data structure for keeping fingerprints of already processed
+ object. This is needed when not using FTW_PHYS. */
+ void *known_objects;
};
@@ -148,52 +243,54 @@ struct ftw_data
as `ftw', map each flag to the subset of values used by `ftw'. */
static const int nftw_arr[] =
{
- FTW_F, FTW_D, FTW_DNR, FTW_NS, FTW_SL, FTW_DP, FTW_SLN
+ FTW_F, FTW_D, FTW_DNR, FTW_NS, FTW_SL, FTW_DP, FTW_SLN
};
static const int ftw_arr[] =
{
- FTW_F, FTW_D, FTW_DNR, FTW_NS, FTW_F, FTW_D, FTW_NS
+ FTW_F, FTW_D, FTW_DNR, FTW_NS, FTW_F, FTW_D, FTW_NS
};
+
/* Forward declarations of local functions. */
-static int ftw_dir (struct ftw_data *data, struct STAT *st) internal_function;
+static int ftw_dir (struct ftw_data *data, struct STAT *st,
+ struct dir_data *old_dir) internal_function;
static int
object_compare (const void *p1, const void *p2)
{
- /* We don't need a sophisticated and useful comparison. We are only
- interested in equality. However, we must be careful not to
- accidentally compare `holes' in the structure. */
- const struct known_object *kp1 = p1, *kp2 = p2;
- int cmp1;
- cmp1 = (kp1->ino > kp2->ino) - (kp1->ino < kp2->ino);
- if (cmp1 != 0)
- return cmp1;
- return (kp1->dev > kp2->dev) - (kp1->dev < kp2->dev);
+ /* We don't need a sophisticated and useful comparison. We are only
+ interested in equality. However, we must be careful not to
+ accidentally compare `holes' in the structure. */
+ const struct known_object *kp1 = p1, *kp2 = p2;
+ int cmp1;
+ cmp1 = (kp1->ino > kp2->ino) - (kp1->ino < kp2->ino);
+ if (cmp1 != 0)
+ return cmp1;
+ return (kp1->dev > kp2->dev) - (kp1->dev < kp2->dev);
}
static inline int
add_object (struct ftw_data *data, struct STAT *st)
{
- struct known_object *newp = malloc (sizeof (struct known_object));
- if (newp == NULL)
- return -1;
- newp->dev = st->st_dev;
- newp->ino = st->st_ino;
- return tsearch (newp, &data->known_objects, object_compare) ? 0 : -1;
+ struct known_object *newp = malloc (sizeof (struct known_object));
+ if (newp == NULL)
+ return -1;
+ newp->dev = st->st_dev;
+ newp->ino = st->st_ino;
+ return __tsearch (newp, &data->known_objects, object_compare) ? 0 : -1;
}
static inline int
find_object (struct ftw_data *data, struct STAT *st)
{
- struct known_object obj;
- obj.dev = st->st_dev;
- obj.ino = st->st_ino;
- return tfind (&obj, &data->known_objects, object_compare) != NULL;
+ struct known_object obj;
+ obj.dev = st->st_dev;
+ obj.ino = st->st_ino;
+ return __tfind (&obj, &data->known_objects, object_compare) != NULL;
}
@@ -201,465 +298,537 @@ static inline int
__attribute ((always_inline))
open_dir_stream (struct ftw_data *data, struct dir_data *dirp)
{
- int result = 0;
+ int result = 0;
- if (data->dirstreams[data->actdir] != NULL)
+ if (data->dirstreams[data->actdir] != NULL)
{
- /* Oh, oh. We must close this stream. Get all remaining
- entries and store them as a list in the `content' member of
- the `struct dir_data' variable. */
- size_t bufsize = 1024;
- char *buf = malloc (bufsize);
-
- if (buf == NULL)
- result = -1;
- else
+ /* Oh, oh. We must close this stream. Get all remaining
+ entries and store them as a list in the `content' member of
+ the `struct dir_data' variable. */
+ size_t bufsize = 1024;
+ char *buf = malloc (bufsize);
+
+ if (buf == NULL)
+ result = -1;
+ else
{
- DIR *st = data->dirstreams[data->actdir]->stream;
- struct dirent *d;
- size_t actsize = 0;
+ DIR *st = data->dirstreams[data->actdir]->stream;
+ struct dirent64 *d;
+ size_t actsize = 0;
- while ((d = readdir (st)) != NULL)
+ while ((d = __readdir64 (st)) != NULL)
{
- size_t this_len = _D_EXACT_NAMLEN (d);
- if (actsize + this_len + 2 >= bufsize)
+ size_t this_len = NAMLEN (d);
+ if (actsize + this_len + 2 >= bufsize)
{
- char *newp;
- bufsize += MAX (1024, 2 * this_len);
- newp = (char *) realloc (buf, bufsize);
- if (newp == NULL)
+ char *newp;
+ bufsize += MAX (1024, 2 * this_len);
+ newp = (char *) realloc (buf, bufsize);
+ if (newp == NULL)
{
- /* No more memory. */
- int save_err = errno;
- free (buf);
- __set_errno (save_err);
- result = -1;
- break;
+ /* No more memory. */
+ int save_err = errno;
+ free (buf);
+ __set_errno (save_err);
+ result = -1;
+ break;
}
- buf = newp;
+ buf = newp;
}
- *((char *) mempcpy (buf + actsize, d->d_name, this_len))
- = '\0';
- actsize += this_len + 1;
+ *((char *) __mempcpy (buf + actsize, d->d_name, this_len))
+ = '\0';
+ actsize += this_len + 1;
}
- /* Terminate the list with an additional NUL byte. */
- buf[actsize++] = '\0';
+ /* Terminate the list with an additional NUL byte. */
+ buf[actsize++] = '\0';
- /* Shrink the buffer to what we actually need. */
- data->dirstreams[data->actdir]->content = realloc (buf, actsize);
- if (data->dirstreams[data->actdir]->content == NULL)
+ /* Shrink the buffer to what we actually need. */
+ data->dirstreams[data->actdir]->content = realloc (buf, actsize);
+ if (data->dirstreams[data->actdir]->content == NULL)
{
- int save_err = errno;
- free (buf);
- __set_errno (save_err);
- result = -1;
+ int save_err = errno;
+ free (buf);
+ __set_errno (save_err);
+ result = -1;
}
- else
+ else
{
- closedir (st);
- data->dirstreams[data->actdir]->stream = NULL;
- data->dirstreams[data->actdir] = NULL;
+ __closedir (st);
+ data->dirstreams[data->actdir]->stream = NULL;
+ data->dirstreams[data->actdir] = NULL;
}
}
}
- /* Open the new stream. */
- if (result == 0)
+ /* Open the new stream. */
+ if (result == 0)
{
- const char *name = ((data->flags & FTW_CHDIR)
- ? data->dirbuf + data->ftw.base: data->dirbuf);
- assert (data->dirstreams[data->actdir] == NULL);
-
- dirp->stream = opendir (name);
- if (dirp->stream == NULL)
- result = -1;
- else
+ const char *name = ((data->flags & FTW_CHDIR)
+ ? data->dirbuf + data->ftw.base: data->dirbuf);
+ assert (data->dirstreams[data->actdir] == NULL);
+
+ dirp->stream = __opendir (name);
+ if (dirp->stream == NULL)
+ result = -1;
+ else
{
- dirp->content = NULL;
- data->dirstreams[data->actdir] = dirp;
+ dirp->content = NULL;
+ data->dirstreams[data->actdir] = dirp;
- if (++data->actdir == data->maxdir)
- data->actdir = 0;
+ if (++data->actdir == data->maxdir)
+ data->actdir = 0;
}
}
- return result;
+ return result;
}
static int
internal_function
-process_entry (struct ftw_data *data, struct dir_data *dir, const char *name, size_t namlen)
+process_entry (struct ftw_data *data, struct dir_data *dir, const char *name,
+ size_t namlen)
{
- struct STAT st;
- int result = 0;
- int flag = 0;
- size_t new_buflen;
-
- if (name[0] == '.' && (name[1] == '\0'
- || (name[1] == '.' && name[2] == '\0')))
- /* Don't process the "." and ".." entries. */
- return 0;
-
- new_buflen = data->ftw.base + namlen + 2;
- if (data->dirbufsize < new_buflen)
+ struct STAT st;
+ int result = 0;
+ int flag = 0;
+ size_t new_buflen;
+
+ if (name[0] == '.' && (name[1] == '\0'
+ || (name[1] == '.' && name[2] == '\0')))
+ /* Don't process the "." and ".." entries. */
+ return 0;
+
+ new_buflen = data->ftw.base + namlen + 2;
+ if (data->dirbufsize < new_buflen)
{
- /* Enlarge the buffer. */
- char *newp;
-
- data->dirbufsize = 2 * new_buflen;
- newp = (char *) realloc (data->dirbuf, data->dirbufsize);
- if (newp == NULL)
- return -1;
- data->dirbuf = newp;
+ /* Enlarge the buffer. */
+ char *newp;
+
+ data->dirbufsize = 2 * new_buflen;
+ newp = (char *) realloc (data->dirbuf, data->dirbufsize);
+ if (newp == NULL)
+ return -1;
+ data->dirbuf = newp;
}
- *((char *) mempcpy (data->dirbuf + data->ftw.base, name, namlen)) = '\0';
+ *((char *) __mempcpy (data->dirbuf + data->ftw.base, name, namlen)) = '\0';
- if ((data->flags & FTW_CHDIR) == 0)
- name = data->dirbuf;
+ if ((data->flags & FTW_CHDIR) == 0)
+ name = data->dirbuf;
- if (((data->flags & FTW_PHYS)
- ? LSTAT (name, &st)
- : XSTAT (name, &st)) < 0)
+ if (((data->flags & FTW_PHYS)
+ ? LXSTAT (_STAT_VER, name, &st)
+ : XSTAT (_STAT_VER, name, &st)) < 0)
{
- if (errno != EACCES && errno != ENOENT)
- result = -1;
- else if (!(data->flags & FTW_PHYS)
- && LSTAT (name, &st) == 0
- && S_ISLNK (st.st_mode))
- flag = FTW_SLN;
- else
- flag = FTW_NS;
+ if (errno != EACCES && errno != ENOENT)
+ result = -1;
+ else if (!(data->flags & FTW_PHYS)
+ && LXSTAT (_STAT_VER, name, &st) == 0
+ && S_ISLNK (st.st_mode))
+ flag = FTW_SLN;
+ else
+ flag = FTW_NS;
}
- else
+ else
{
- if (S_ISDIR (st.st_mode))
- flag = FTW_D;
- else if (S_ISLNK (st.st_mode))
- flag = FTW_SL;
- else
- flag = FTW_F;
+ if (S_ISDIR (st.st_mode))
+ flag = FTW_D;
+ else if (S_ISLNK (st.st_mode))
+ flag = FTW_SL;
+ else
+ flag = FTW_F;
}
- if (result == 0
- && (flag == FTW_NS
- || !(data->flags & FTW_MOUNT) || st.st_dev == data->dev))
+ if (result == 0
+ && (flag == FTW_NS
+ || !(data->flags & FTW_MOUNT) || st.st_dev == data->dev))
{
- if (flag == FTW_D)
+ if (flag == FTW_D)
{
- if ((data->flags & FTW_PHYS)
- || (!find_object (data, &st)
- /* Remember the object. */
- && (result = add_object (data, &st)) == 0))
- {
- result = ftw_dir (data, &st);
-
- if (result == 0 && (data->flags & FTW_CHDIR))
- {
- /* Change back to the parent directory. */
- int done = 0;
- if (dir->stream != NULL)
- if (fchdir (dirfd (dir->stream)) == 0)
- done = 1;
-
- if (!done)
- {
- if (data->ftw.base == 1)
- {
- if (chdir ("/") < 0)
- result = -1;
- }
- else
- if (chdir ("..") < 0)
- result = -1;
- }
- }
- }
+ if ((data->flags & FTW_PHYS)
+ || (!find_object (data, &st)
+ /* Remember the object. */
+ && (result = add_object (data, &st)) == 0))
+ result = ftw_dir (data, &st, dir);
}
- else
- result = (*data->func) (data->dirbuf, &st, data->cvt_arr[flag],
- &data->ftw);
+ else
+ result = (*data->func) (data->dirbuf, &st, data->cvt_arr[flag],
+ &data->ftw);
}
- return result;
+ if ((data->flags & FTW_ACTIONRETVAL) && result == FTW_SKIP_SUBTREE)
+ result = 0;
+
+ return result;
}
+
static int
+__attribute ((noinline))
internal_function
-ftw_dir (struct ftw_data *data, struct STAT *st)
+ftw_dir (struct ftw_data *data, struct STAT *st, struct dir_data *old_dir)
{
- struct dir_data dir;
- struct dirent *d;
- int previous_base = data->ftw.base;
- int result;
- char *startp;
-
- /* Open the stream for this directory. This might require that
- another stream has to be closed. */
- result = open_dir_stream (data, &dir);
- if (result != 0)
+ struct dir_data dir;
+ struct dirent64 *d;
+ int previous_base = data->ftw.base;
+ int result;
+ char *startp;
+
+ /* Open the stream for this directory. This might require that
+ another stream has to be closed. */
+ result = open_dir_stream (data, &dir);
+ if (result != 0)
{
- if (errno == EACCES)
- /* We cannot read the directory. Signal this with a special flag. */
- result = (*data->func) (data->dirbuf, st, FTW_DNR, &data->ftw);
+ if (errno == EACCES)
+ /* We cannot read the directory. Signal this with a special flag. */
+ result = (*data->func) (data->dirbuf, st, FTW_DNR, &data->ftw);
- return result;
+ return result;
}
- /* First, report the directory (if not depth-first). */
- if (!(data->flags & FTW_DEPTH))
+ /* First, report the directory (if not depth-first). */
+ if (!(data->flags & FTW_DEPTH))
{
- result = (*data->func) (data->dirbuf, st, FTW_D, &data->ftw);
- if (result != 0)
- return result;
+ result = (*data->func) (data->dirbuf, st, FTW_D, &data->ftw);
+ if (result != 0)
+ {
+ int save_err;
+fail:
+ save_err = errno;
+ __closedir (dir.stream);
+ __set_errno (save_err);
+
+ if (data->actdir-- == 0)
+ data->actdir = data->maxdir - 1;
+ data->dirstreams[data->actdir] = NULL;
+ return result;
+ }
}
- /* If necessary, change to this directory. */
- if (data->flags & FTW_CHDIR)
+ /* If necessary, change to this directory. */
+ if (data->flags & FTW_CHDIR)
{
- if (fchdir (dirfd (dir.stream)) < 0)
+ if (__fchdir (dirfd (dir.stream)) < 0)
{
- int save_err = errno;
- closedir (dir.stream);
- __set_errno (save_err);
-
- if (data->actdir-- == 0)
- data->actdir = data->maxdir - 1;
- data->dirstreams[data->actdir] = NULL;
-
- return -1;
+ result = -1;
+ goto fail;
}
}
- /* Next, update the `struct FTW' information. */
- ++data->ftw.level;
- startp = __strchr (data->dirbuf, '\0');
- /* There always must be a directory name. */
- assert (startp != data->dirbuf);
- if (startp[-1] != '/')
- *startp++ = '/';
- data->ftw.base = startp - data->dirbuf;
+ /* Next, update the `struct FTW' information. */
+ ++data->ftw.level;
+ startp = __strchr (data->dirbuf, '\0');
+ /* There always must be a directory name. */
+ assert (startp != data->dirbuf);
+ if (startp[-1] != '/')
+ *startp++ = '/';
+ data->ftw.base = startp - data->dirbuf;
- while (dir.stream != NULL && (d = readdir (dir.stream)) != NULL)
+ while (dir.stream != NULL && (d = __readdir64 (dir.stream)) != NULL)
{
- result = process_entry (data, &dir, d->d_name, _D_EXACT_NAMLEN (d));
- if (result != 0)
- break;
+ result = process_entry (data, &dir, d->d_name, NAMLEN (d));
+ if (result != 0)
+ break;
}
- if (dir.stream != NULL)
+ if (dir.stream != NULL)
{
- /* The stream is still open. I.e., we did not need more
- descriptors. Simply close the stream now. */
- int save_err = errno;
+ /* The stream is still open. I.e., we did not need more
+ descriptors. Simply close the stream now. */
+ int save_err = errno;
- assert (dir.content == NULL);
+ assert (dir.content == NULL);
- closedir (dir.stream);
- __set_errno (save_err);
+ __closedir (dir.stream);
+ __set_errno (save_err);
- if (data->actdir-- == 0)
- data->actdir = data->maxdir - 1;
- data->dirstreams[data->actdir] = NULL;
+ if (data->actdir-- == 0)
+ data->actdir = data->maxdir - 1;
+ data->dirstreams[data->actdir] = NULL;
}
- else
+ else
{
- int save_err;
- char *runp = dir.content;
+ int save_err;
+ char *runp = dir.content;
- while (result == 0 && *runp != '\0')
+ while (result == 0 && *runp != '\0')
{
- char *endp = __strchr (runp, '\0');
+ char *endp = __strchr (runp, '\0');
- result = process_entry (data, &dir, runp, endp - runp);
+ result = process_entry (data, &dir, runp, endp - runp);
- runp = endp + 1;
+ runp = endp + 1;
}
- save_err = errno;
- free (dir.content);
- __set_errno (save_err);
+ save_err = errno;
+ free (dir.content);
+ __set_errno (save_err);
}
- /* Prepare the return, revert the `struct FTW' information. */
- data->dirbuf[data->ftw.base - 1] = '\0';
- --data->ftw.level;
- data->ftw.base = previous_base;
+ if ((data->flags & FTW_ACTIONRETVAL) && result == FTW_SKIP_SIBLINGS)
+ result = 0;
- /* Finally, if we process depth-first report the directory. */
- if (result == 0 && (data->flags & FTW_DEPTH))
- result = (*data->func) (data->dirbuf, st, FTW_DP, &data->ftw);
+ /* Prepare the return, revert the `struct FTW' information. */
+ data->dirbuf[data->ftw.base - 1] = '\0';
+ --data->ftw.level;
+ data->ftw.base = previous_base;
- return result;
+ /* Finally, if we process depth-first report the directory. */
+ if (result == 0 && (data->flags & FTW_DEPTH))
+ result = (*data->func) (data->dirbuf, st, FTW_DP, &data->ftw);
+
+ if (old_dir
+ && (data->flags & FTW_CHDIR)
+ && (result == 0
+ || ((data->flags & FTW_ACTIONRETVAL)
+ && (result != -1 && result != FTW_STOP))))
+ {
+ /* Change back to the parent directory. */
+ int done = 0;
+ if (old_dir->stream != NULL)
+ if (__fchdir (dirfd (old_dir->stream)) == 0)
+ done = 1;
+
+ if (!done)
+ {
+ if (data->ftw.base == 1)
+ {
+ if (__chdir ("/") < 0)
+ result = -1;
+ }
+ else
+ if (__chdir ("..") < 0)
+ result = -1;
+ }
+ }
+
+ return result;
}
static int
+__attribute ((noinline))
internal_function
-ftw_startup (const char *dir, int is_nftw, void *func, int descriptors, int flags)
+ftw_startup (const char *dir, int is_nftw, void *func, int descriptors,
+ int flags)
{
- struct ftw_data data;
- struct STAT st;
- int result = 0;
- int save_err;
- char *cwd = NULL;
- char *cp;
-
- /* First make sure the parameters are reasonable. */
- if (unlikely(dir==NULL || *dir=='\0')) {
- __set_errno (ENOENT);
- return -1;
- }
- if ((__strlen(dir)+1) > NAME_MAX) {
- __set_errno(ENAMETOOLONG);
- return -1;
+ struct ftw_data data;
+ struct STAT st;
+ int result = 0;
+ int save_err;
+ char *cwd = NULL;
+ char *cp;
+
+ /* First make sure the parameters are reasonable. */
+ if (dir[0] == '\0')
+ {
+ __set_errno (ENOENT);
+ return -1;
}
- data.maxdir = descriptors < 1 ? 1 : descriptors;
- data.actdir = 0;
- data.dirstreams = (struct dir_data **) alloca (data.maxdir
- * sizeof (struct dir_data *));
- __memset (data.dirstreams, '\0', data.maxdir * sizeof (struct dir_data *));
-
- /* PATH_MAX is always defined when we get here. */
- data.dirbufsize = MAX (2 * __strlen (dir), PATH_MAX);
- data.dirbuf = (char *) malloc (data.dirbufsize);
- if (data.dirbuf == NULL)
- return -1;
- cp = stpcpy (data.dirbuf, dir);
- /* Strip trailing slashes. */
- while (cp > data.dirbuf + 1 && cp[-1] == '/')
- --cp;
- *cp = '\0';
-
- data.ftw.level = 0;
-
- /* Find basename. */
- while (cp > data.dirbuf && cp[-1] != '/')
- --cp;
- data.ftw.base = cp - data.dirbuf;
-
- data.flags = flags;
-
- /* This assignment might seem to be strange but it is what we want.
- The trick is that the first three arguments to the `ftw' and
- `nftw' callback functions are equal. Therefore we can call in
- every case the callback using the format of the `nftw' version
- and get the correct result since the stack layout for a function
- call in C allows this. */
- data.func = (NFTW_FUNC_T) func;
-
- /* Since we internally use the complete set of FTW_* values we need
- to reduce the value range before calling a `ftw' callback. */
- data.cvt_arr = is_nftw ? nftw_arr : ftw_arr;
-
- /* No object known so far. */
- data.known_objects = NULL;
-
- /* Now go to the directory containing the initial file/directory. */
- if (flags & FTW_CHDIR)
+ data.maxdir = descriptors < 1 ? 1 : descriptors;
+ data.actdir = 0;
+ data.dirstreams = (struct dir_data **) alloca (data.maxdir
+ * sizeof (struct dir_data *));
+ __memset (data.dirstreams, '\0', data.maxdir * sizeof (struct dir_data *));
+
+ /* PATH_MAX is always defined when we get here. */
+ data.dirbufsize = MAX (2 * __strlen (dir), PATH_MAX);
+ data.dirbuf = (char *) malloc (data.dirbufsize);
+ if (data.dirbuf == NULL)
+ return -1;
+ cp = __stpcpy (data.dirbuf, dir);
+ /* Strip trailing slashes. */
+ while (cp > data.dirbuf + 1 && cp[-1] == '/')
+ --cp;
+ *cp = '\0';
+
+ data.ftw.level = 0;
+
+ /* Find basename. */
+ while (cp > data.dirbuf && cp[-1] != '/')
+ --cp;
+ data.ftw.base = cp - data.dirbuf;
+
+ data.flags = flags;
+
+ /* This assignment might seem to be strange but it is what we want.
+ The trick is that the first three arguments to the `ftw' and
+ `nftw' callback functions are equal. Therefore we can call in
+ every case the callback using the format of the `nftw' version
+ and get the correct result since the stack layout for a function
+ call in C allows this. */
+ data.func = (NFTW_FUNC_T) func;
+
+ /* Since we internally use the complete set of FTW_* values we need
+ to reduce the value range before calling a `ftw' callback. */
+ data.cvt_arr = is_nftw ? nftw_arr : ftw_arr;
+
+ /* No object known so far. */
+ data.known_objects = NULL;
+
+ /* Now go to the directory containing the initial file/directory. */
+ if (flags & FTW_CHDIR)
{
- /* GNU extension ahead. */
- cwd = getcwd (NULL, 0);
- if (cwd == NULL)
- result = -1;
- else if (data.ftw.base > 0)
+ /* GNU extension ahead. */
+ cwd = __getcwd (NULL, 0);
+ if (cwd == NULL)
+ result = -1;
+ else if (data.ftw.base > 0)
{
- /* Change to the directory the file is in. In data.dirbuf
- we have a writable copy of the file name. Just NUL
- terminate it for now and change the directory. */
- if (data.ftw.base == 1)
- /* I.e., the file is in the root directory. */
- result = chdir ("/");
- else
+ /* Change to the directory the file is in. In data.dirbuf
+ we have a writable copy of the file name. Just NUL
+ terminate it for now and change the directory. */
+ if (data.ftw.base == 1)
+ /* I.e., the file is in the root directory. */
+ result = __chdir ("/");
+ else
{
- char ch = data.dirbuf[data.ftw.base - 1];
- data.dirbuf[data.ftw.base - 1] = '\0';
- result = chdir (data.dirbuf);
- data.dirbuf[data.ftw.base - 1] = ch;
+ char ch = data.dirbuf[data.ftw.base - 1];
+ data.dirbuf[data.ftw.base - 1] = '\0';
+ result = __chdir (data.dirbuf);
+ data.dirbuf[data.ftw.base - 1] = ch;
}
}
}
- /* Get stat info for start directory. */
- if (result == 0)
+ /* Get stat info for start directory. */
+ if (result == 0)
{
- const char *name = ((data.flags & FTW_CHDIR)
- ? data.dirbuf + data.ftw.base
- : data.dirbuf);
+ const char *name = ((data.flags & FTW_CHDIR)
+ ? data.dirbuf + data.ftw.base
+ : data.dirbuf);
- if (((flags & FTW_PHYS)
- ? LSTAT (name, &st)
- : XSTAT (name, &st)) < 0)
+ if (((flags & FTW_PHYS)
+ ? LXSTAT (_STAT_VER, name, &st)
+ : XSTAT (_STAT_VER, name, &st)) < 0)
{
- if (!(flags & FTW_PHYS)
- && errno == ENOENT
- && LSTAT (name, &st) == 0
- && S_ISLNK (st.st_mode))
- result = (*data.func) (data.dirbuf, &st, data.cvt_arr[FTW_SLN],
- &data.ftw);
- else
- /* No need to call the callback since we cannot say anything
- about the object. */
- result = -1;
+ if (!(flags & FTW_PHYS)
+ && errno == ENOENT
+ && LXSTAT (_STAT_VER, name, &st) == 0
+ && S_ISLNK (st.st_mode))
+ result = (*data.func) (data.dirbuf, &st, data.cvt_arr[FTW_SLN],
+ &data.ftw);
+ else
+ /* No need to call the callback since we cannot say anything
+ about the object. */
+ result = -1;
}
- else
+ else
{
- if (S_ISDIR (st.st_mode))
+ if (S_ISDIR (st.st_mode))
{
- /* Remember the device of the initial directory in case
- FTW_MOUNT is given. */
- data.dev = st.st_dev;
+ /* Remember the device of the initial directory in case
+ FTW_MOUNT is given. */
+ data.dev = st.st_dev;
- /* We know this directory now. */
- if (!(flags & FTW_PHYS))
- result = add_object (&data, &st);
+ /* We know this directory now. */
+ if (!(flags & FTW_PHYS))
+ result = add_object (&data, &st);
- if (result == 0)
- result = ftw_dir (&data, &st);
+ if (result == 0)
+ result = ftw_dir (&data, &st, NULL);
}
- else
+ else
{
- int flag = S_ISLNK (st.st_mode) ? FTW_SL : FTW_F;
+ int flag = S_ISLNK (st.st_mode) ? FTW_SL : FTW_F;
- result = (*data.func) (data.dirbuf, &st, data.cvt_arr[flag],
- &data.ftw);
+ result = (*data.func) (data.dirbuf, &st, data.cvt_arr[flag],
+ &data.ftw);
}
}
+
+ if ((flags & FTW_ACTIONRETVAL)
+ && (result == FTW_SKIP_SUBTREE || result == FTW_SKIP_SIBLINGS))
+ result = 0;
}
- /* Return to the start directory (if necessary). */
- if (cwd != NULL)
+ /* Return to the start directory (if necessary). */
+ if (cwd != NULL)
{
- int save_err = errno;
- chdir (cwd);
- free (cwd);
- __set_errno (save_err);
+ int save_err = errno;
+ __chdir (cwd);
+ free (cwd);
+ __set_errno (save_err);
}
- /* Free all memory. */
- save_err = errno;
- tdestroy (data.known_objects, free);
- free (data.dirbuf);
- __set_errno (save_err);
+ /* Free all memory. */
+ save_err = errno;
+ __tdestroy (data.known_objects, free);
+ free (data.dirbuf);
+ __set_errno (save_err);
- return result;
+ return result;
}
/* Entry points. */
-int FTW_NAME (const char *path, FTW_FUNC_T func, int descriptors)
+int
+FTW_NAME (path, func, descriptors)
+ const char *path;
+ FTW_FUNC_T func;
+ int descriptors;
+{
+ return ftw_startup (path, 0, func, descriptors, 0);
+}
+
+#ifndef _LIBC
+int
+NFTW_NAME (path, func, descriptors, flags)
+ const char *path;
+ NFTW_FUNC_T func;
+ int descriptors;
+ int flags;
+{
+ return ftw_startup (path, 1, func, descriptors, flags);
+}
+#else
+
+#include <shlib-compat.h>
+
+int NFTW_NEW_NAME (const char *, NFTW_FUNC_T, int, int);
+
+int
+NFTW_NEW_NAME (path, func, descriptors, flags)
+ const char *path;
+ NFTW_FUNC_T func;
+ int descriptors;
+ int flags;
{
- return ftw_startup (path, 0, func, descriptors, 0);
+ if (flags
+ & ~(FTW_PHYS | FTW_MOUNT | FTW_CHDIR | FTW_DEPTH | FTW_ACTIONRETVAL))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ return ftw_startup (path, 1, func, descriptors, flags);
}
-int NFTW_NAME (const char *path, NFTW_FUNC_T func, int descriptors, int flags)
+versioned_symbol (libc, NFTW_NEW_NAME, NFTW_NAME, GLIBC_2_3_3);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_3_3)
+
+/* Older nftw* version just ignored all unknown flags. */
+
+int NFTW_OLD_NAME (const char *, NFTW_FUNC_T, int, int);
+
+int
+attribute_compat_text_section
+NFTW_OLD_NAME (path, func, descriptors, flags)
+ const char *path;
+ NFTW_FUNC_T func;
+ int descriptors;
+ int flags;
{
- return ftw_startup (path, 1, func, descriptors, flags);
+ flags &= (FTW_PHYS | FTW_MOUNT | FTW_CHDIR | FTW_DEPTH);
+ return ftw_startup (path, 1, func, descriptors, flags);
}
+
+compat_symbol (libc, NFTW_OLD_NAME, NFTW_NAME, GLIBC_2_1);
+#endif
#endif
diff --git a/libc/misc/glob/glob.c b/libc/misc/glob/glob.c
index d4a0b67ca..ea87d371c 100644
--- a/libc/misc/glob/glob.c
+++ b/libc/misc/glob/glob.c
@@ -50,11 +50,16 @@ static int prefix_array __P ((const char *prefix, char **array, size_t n,
static int collated_compare __P ((const __ptr_t, const __ptr_t));
#ifdef __GLOB64
-extern int glob_pattern_p(const char *pattern, int quote);
+extern int __glob_pattern_p(const char *pattern, int quote) attribute_hidden;
#else
+extern struct dirent *__readdir (DIR *__dirp) __nonnull ((1)) attribute_hidden;
+extern int __glob (__const char *__restrict __pattern, int __flags,
+ int (*__errfunc) (__const char *, int),
+ glob_t *__restrict __pglob) __THROW attribute_hidden;
+extern void __globfree (glob_t *__pglob) __THROW attribute_hidden;
/* Return nonzero if PATTERN contains any metacharacters.
Metacharacters can be quoted with backslashes if QUOTE is nonzero. */
-int glob_pattern_p(const char *pattern, int quote)
+int attribute_hidden __glob_pattern_p(const char *pattern, int quote)
{
const char *p;
int open = 0;
@@ -83,6 +88,7 @@ int glob_pattern_p(const char *pattern, int quote)
return 0;
}
+strong_alias(__glob_pattern_p,glob_pattern_p)
#endif
@@ -94,8 +100,8 @@ int glob_pattern_p(const char *pattern, int quote)
`glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
Otherwise, `glob' returns zero. */
-int
-glob (pattern, flags, errfunc, pglob)
+int attribute_hidden
+__glob (pattern, flags, errfunc, pglob)
const char *pattern;
int flags;
int (*errfunc) __P ((const char *, int));
@@ -140,7 +146,7 @@ glob (pattern, flags, errfunc, pglob)
if (filename[0] == '\0' && dirlen > 1)
/* "pattern/". Expand "pattern", appending slashes. */
{
- int val = glob (dirname, flags | GLOB_MARK, errfunc, pglob);
+ int val = __glob (dirname, flags | GLOB_MARK, errfunc, pglob);
if (val == 0)
pglob->gl_flags = (pglob->gl_flags & ~GLOB_MARK) | (flags & GLOB_MARK);
return val;
@@ -154,7 +160,7 @@ glob (pattern, flags, errfunc, pglob)
oldcount = pglob->gl_pathc;
- if (glob_pattern_p (dirname, !(flags & GLOB_NOESCAPE)))
+ if (__glob_pattern_p (dirname, !(flags & GLOB_NOESCAPE)))
{
/* The directory name contains metacharacters, so we
have to glob for the directory, and then glob for
@@ -162,7 +168,7 @@ glob (pattern, flags, errfunc, pglob)
glob_t dirs;
register int i;
- status = glob (dirname,
+ status = __glob (dirname,
((flags & (GLOB_ERR | GLOB_NOCHECK | GLOB_NOESCAPE)) |
GLOB_NOSORT),
errfunc, &dirs);
@@ -183,8 +189,8 @@ glob (pattern, flags, errfunc, pglob)
if (interrupt_state)
{
- globfree (&dirs);
- globfree (&files);
+ __globfree (&dirs);
+ __globfree (&files);
return GLOB_ABEND;
}
}
@@ -200,8 +206,8 @@ glob (pattern, flags, errfunc, pglob)
if (status != 0)
{
- globfree (&dirs);
- globfree (pglob);
+ __globfree (&dirs);
+ __globfree (pglob);
return status;
}
@@ -211,8 +217,8 @@ glob (pattern, flags, errfunc, pglob)
pglob->gl_pathc - oldcount,
flags & GLOB_MARK))
{
- globfree (&dirs);
- globfree (pglob);
+ __globfree (&dirs);
+ __globfree (pglob);
return GLOB_NOSPACE;
}
}
@@ -271,7 +277,7 @@ glob (pattern, flags, errfunc, pglob)
pglob->gl_pathc - oldcount,
flags & GLOB_MARK))
{
- globfree (pglob);
+ __globfree (pglob);
return GLOB_NOSPACE;
}
}
@@ -284,7 +290,7 @@ glob (pattern, flags, errfunc, pglob)
int i;
struct stat st;
for (i = oldcount; i < pglob->gl_pathc; ++i)
- if (lstat (pglob->gl_pathv[i], &st) == 0 &&
+ if (__lstat (pglob->gl_pathv[i], &st) == 0 &&
S_ISDIR (st.st_mode))
__strcat (pglob->gl_pathv[i], "/");
}
@@ -297,11 +303,16 @@ glob (pattern, flags, errfunc, pglob)
return 0;
}
+#ifdef __GLOB64
+strong_alias(__glob64,glob64)
+#else
+strong_alias(__glob,glob)
+#endif
/* Free storage allocated in PGLOB by a previous `glob' call. */
-void
-globfree (pglob)
+void attribute_hidden
+__globfree (pglob)
register glob_t *pglob;
{
if (pglob->gl_pathv != NULL)
@@ -313,6 +324,11 @@ globfree (pglob)
free ((__ptr_t) pglob->gl_pathv);
}
}
+#ifdef __GLOB64
+strong_alias(__globfree64,globfree64)
+#else
+strong_alias(__globfree,globfree)
+#endif
/* Do a collated comparison of A and B. */
@@ -409,7 +425,7 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
return GLOB_ABORTED;
}
- meta = glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE));
+ meta = __glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE));
if (meta)
flags |= GLOB_MAGCHAR;
@@ -428,7 +444,7 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
}
else
{
- struct dirent *d = readdir ((DIR *) stream);
+ struct dirent *d = __readdir ((DIR *) stream);
if (d == NULL)
break;
if (! (d->d_ino != 0))
diff --git a/libc/misc/glob/glob64.c b/libc/misc/glob/glob64.c
index 5829fec14..f0c65abe0 100644
--- a/libc/misc/glob/glob64.c
+++ b/libc/misc/glob/glob64.c
@@ -18,17 +18,27 @@
#include <glob.h>
#include <sys/stat.h>
+extern struct dirent64 *__readdir64 (DIR *__dirp) __nonnull ((1)) attribute_hidden;
+extern int __glob64 (__const char *__restrict __pattern, int __flags,
+ int (*__errfunc) (__const char *, int),
+ glob64_t *__restrict __pglob) __THROW attribute_hidden;
+extern void __globfree (glob_t *__pglob) __THROW attribute_hidden;
+extern void __globfree64 (glob64_t *__pglob) __THROW attribute_hidden;
+
#define dirent dirent64
-#define readdir(dirp) readdir64 (dirp)
+#define __readdir(dirp) __readdir64(dirp)
#define glob_t glob64_t
+#define __glob(pattern, flags, errfunc, pglob) \
+ __glob64 (pattern, flags, errfunc, pglob)
#define glob(pattern, flags, errfunc, pglob) \
glob64 (pattern, flags, errfunc, pglob)
+#define __globfree(pglob) __globfree64 (pglob)
#define globfree(pglob) globfree64 (pglob)
#undef stat
#define stat stat64
-#define lstat lstat64
+#define __lstat __lstat64
#define __GLOB64 1
diff --git a/libc/misc/gnu/obstack.c b/libc/misc/gnu/obstack.c
index 9cc90bd42..6521bd1d4 100644
--- a/libc/misc/gnu/obstack.c
+++ b/libc/misc/gnu/obstack.c
@@ -502,7 +502,7 @@ print_and_abort ()
else
# endif
fprintf (stderr, "%s\n", _("memory exhausted"));
- exit (obstack_exit_failure);
+ __exit (obstack_exit_failure);
}
# if 0
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
index 618fad74c..3876c7606 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -36,8 +36,6 @@
#ifndef SHARED
void *__libc_stack_end=NULL;
-/* probably all the weak_*function stuff below should be in here */
-
#ifdef __UCLIBC_HAS_SSP__
#include <dl-osinfo.h>
#ifndef THREAD_SET_STACK_GUARD
@@ -56,39 +54,46 @@ strong_alias(__stack_chk_guard,__guard)
/*
* Prototypes.
*/
-extern void weak_function _stdio_init(void);
+extern void weak_function _stdio_init(void) attribute_hidden;
extern int *weak_const_function __errno_location(void);
extern int *weak_const_function __h_errno_location(void);
#ifdef __UCLIBC_HAS_LOCALE__
-extern void weak_function _locale_init(void);
+extern void weak_function _locale_init(void) attribute_hidden;
#endif
#ifdef __UCLIBC_HAS_THREADS__
extern void weak_function __pthread_initialize_minimal(void);
#endif
+attribute_hidden const char *__uclibc_progname = NULL;
+#ifdef __UCLIBC_HAS___PROGNAME__
+strong_alias (__uclibc_progname, __progname)
+#endif
+#ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
+attribute_hidden const char *__progname_full = NULL;
+strong_alias (__uclibc_progname, program_invocation_short_name)
+strong_alias (__progname_full, program_invocation_name)
+#endif
+
/*
* Declare the __environ global variable and create a weak alias environ.
* Note: Apparently we must initialize __environ to ensure that the weak
* environ symbol is also included.
*/
char **__environ = 0;
-weak_alias(__environ, environ);
+weak_alias(__environ, environ)
size_t __pagesize = 0;
-const char *__progname = 0;
#ifndef O_NOFOLLOW
# define O_NOFOLLOW 0
#endif
-extern int __libc_fcntl(int fd, int cmd, ...);
-
#ifdef __ARCH_HAS_MMU__
static void __check_one_fd(int fd, int mode)
{
/* Check if the specified fd is already open */
- if (unlikely(__libc_fcntl(fd, F_GETFD)==-1 && *(__errno_location())==EBADF))
+ if (unlikely(__fcntl(fd, F_GETFD)==-1 && *(__errno_location())==EBADF))
{
/* The descriptor is probably not open, so try to use /dev/null */
struct stat st;
@@ -96,13 +101,11 @@ static void __check_one_fd(int fd, int mode)
/* /dev/null is major=1 minor=3. Make absolutely certain
* that is in fact the device that we have opened and not
* some other wierd file... */
- if ( (nullfd!=fd) || fstat(fd, &st) || !S_ISCHR(st.st_mode) ||
+ if ( (nullfd!=fd) || __fstat(fd, &st) || !S_ISCHR(st.st_mode) ||
(st.st_rdev != makedev(1, 3)))
{
/* Somebody is trying some trickery here... */
- while (1) {
abort();
- }
}
}
}
@@ -195,7 +198,7 @@ void attribute_hidden (*__rtld_fini)(void) = NULL;
* called from crt1 (version 0.9.28 or newer), after ALL shared libraries
* are initialized, just before we call the application's main function.
*/
-void __attribute__ ((__noreturn__))
+void attribute_noreturn
__uClibc_main(int (*main)(int, char **, char **), int argc,
char **argv, void (*app_init)(void), void (*app_fini)(void),
void (*rtld_fini)(void), void *stack_end)
@@ -221,8 +224,8 @@ __uClibc_main(int (*main)(int, char **, char **), int argc,
__environ = &argv[argc];
}
- /* Pull stuff from the ELF header when possible */
#ifdef __ARCH_HAS_MMU__
+ /* Pull stuff from the ELF header when possible */
aux_dat = (unsigned long*)__environ;
while (*aux_dat) {
aux_dat++;
@@ -235,19 +238,21 @@ __uClibc_main(int (*main)(int, char **, char **), int argc,
}
aux_dat += 2;
}
+#endif
/* We need to initialize uClibc. If we are dynamically linked this
* may have already been completed by the shared lib loader. We call
* __uClibc_init() regardless, to be sure the right thing happens. */
__uClibc_init();
+#ifdef __ARCH_HAS_MMU__
/* Make certain getpagesize() gives the correct answer */
__pagesize = (auxvt[AT_PAGESZ].a_un.a_val)? auxvt[AT_PAGESZ].a_un.a_val : PAGE_SIZE;
/* Prevent starting SUID binaries where the stdin. stdout, and
* stderr file descriptors are not already opened. */
- if ((auxvt[AT_UID].a_un.a_val==-1 && __check_suid()) ||
- (auxvt[AT_UID].a_un.a_val != -1 &&
+ if ((auxvt[AT_UID].a_un.a_val == (size_t)-1 && __check_suid()) ||
+ (auxvt[AT_UID].a_un.a_val != (size_t)-1 &&
(auxvt[AT_UID].a_un.a_val != auxvt[AT_EUID].a_un.a_val ||
auxvt[AT_GID].a_un.a_val != auxvt[AT_EGID].a_un.a_val)))
{
@@ -257,7 +262,16 @@ __uClibc_main(int (*main)(int, char **, char **), int argc,
}
#endif
- __progname = *argv;
+#ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
+ __progname_full = *argv;
+ __progname = __strrchr(*argv, '/');
+ if (__progname != NULL)
+ ++__progname;
+ else
+ __progname = __progname_full;
+#else
+ __uclibc_progname = *argv;
+#endif
#ifdef __UCLIBC_CTOR_DTOR__
/* Arrange for the application's dtors to run before we exit. */
@@ -283,5 +297,5 @@ __uClibc_main(int (*main)(int, char **, char **), int argc,
/*
* Finally, invoke application's main and then exit.
*/
- exit(main(argc, argv, __environ));
+ __exit(main(argc, argv, __environ));
}
diff --git a/libc/misc/internals/errno.c b/libc/misc/internals/errno.c
index 107b61403..23b2bb375 100644
--- a/libc/misc/internals/errno.c
+++ b/libc/misc/internals/errno.c
@@ -31,6 +31,6 @@ int _errno = 0;
int _h_errno = 0;
#endif
-weak_alias (_errno, errno)
-weak_alias(_h_errno, h_errno);
+weak_alias(_errno, errno)
+weak_alias(_h_errno, h_errno)
#endif
diff --git a/libc/misc/internals/tempname.c b/libc/misc/internals/tempname.c
index fae3687ad..5bcd78390 100644
--- a/libc/misc/internals/tempname.c
+++ b/libc/misc/internals/tempname.c
@@ -54,7 +54,7 @@
static int direxists (const char *dir)
{
struct stat buf;
- return stat(dir, &buf) == 0 && S_ISDIR (buf.st_mode);
+ return __stat(dir, &buf) == 0 && S_ISDIR (buf.st_mode);
}
/* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is
@@ -212,7 +212,7 @@ int attribute_hidden __gen_tempname (char *tmpl, int kind)
case __GT_NOCREATE:
{
struct stat st;
- if (stat (tmpl, &st) < 0)
+ if (__stat (tmpl, &st) < 0)
{
if (errno == ENOENT)
{
diff --git a/libc/misc/locale/locale.c b/libc/misc/locale/locale.c
index bf0628ee1..1a20300db 100644
--- a/libc/misc/locale/locale.c
+++ b/libc/misc/locale/locale.c
@@ -48,6 +48,7 @@
#define stpcpy __stpcpy
#define strtok_r __strtok_r
+/* #define fflush __fflush */
#define _GNU_SOURCE
@@ -122,8 +123,8 @@
#define MAX_LOCALE_CATEGORY_STR 32 /* TODO: Only sufficient for current case. */
/* Note: Best if MAX_LOCALE_CATEGORY_STR is a power of 2. */
-extern int _locale_set_l(const unsigned char *p, __locale_t base);
-extern void _locale_init_l(__locale_t base);
+extern int _locale_set_l(const unsigned char *p, __locale_t base) attribute_hidden;
+extern void _locale_init_l(__locale_t base) attribute_hidden;
#endif /* __LOCALE_C_ONLY */
@@ -262,6 +263,9 @@ static void update_hr_locale(const unsigned char *spec)
} while (!done);
}
+extern __locale_t __newlocale (int __category_mask, __const char *__locale,
+ __locale_t __base) __THROW attribute_hidden;
+
char *setlocale(int category, const char *locale)
{
if (((unsigned int)(category)) > LC_ALL) {
@@ -564,7 +568,7 @@ static int init_cur_collate(int der_num, __collate_t *cur_collate)
return 1;
}
-int _locale_set_l(const unsigned char *p, __locale_t base)
+int attribute_hidden _locale_set_l(const unsigned char *p, __locale_t base)
{
const char **x;
unsigned char *s = base->cur_locale + 1;
@@ -846,7 +850,7 @@ static const uint16_t __code2flag[16] = {
_IScntrl /* cntrl_nonspace */
};
-void _locale_init_l(__locale_t base)
+void attribute_hidden _locale_init_l(__locale_t base)
{
__memset(base->cur_locale, 0, LOCALE_SELECTOR_SIZE);
base->cur_locale[0] = '#';
@@ -909,7 +913,7 @@ void _locale_init_l(__locale_t base)
_locale_set_l(C_LOCALE_SELECTOR, base);
}
-void _locale_init(void)
+void attribute_hidden _locale_init(void)
{
/* TODO: mmap the locale file */
@@ -1208,7 +1212,7 @@ static unsigned char *composite_locale(int category_mask, const char *locale,
return new_locale;
}
-__locale_t __newlocale(int category_mask, const char *locale, __locale_t base)
+__locale_t attribute_hidden __newlocale(int category_mask, const char *locale, __locale_t base)
{
const unsigned char *p;
int i, j, k;
@@ -1303,7 +1307,7 @@ weak_alias(__newlocale, newlocale)
#warning REMINDER: When we allocate ctype tables, remember to dup them.
#endif
-__locale_t __duplocale(__locale_t dataset)
+__locale_t attribute_hidden __duplocale(__locale_t dataset)
{
__locale_t r;
uint16_t * i2w;
@@ -1352,7 +1356,7 @@ weak_alias(__freelocale, freelocale)
/**********************************************************************/
#ifdef L_uselocale
-__locale_t __uselocale(__locale_t dataset)
+__locale_t attribute_hidden __uselocale(__locale_t dataset)
{
__locale_t old;
@@ -1424,7 +1428,7 @@ extern size_t _wchar_utf8sntowcs(wchar_t *__restrict pwc, size_t wn,
const char **__restrict src, size_t n,
mbstate_t *ps, int allow_continuation) attribute_hidden;
-int __locale_mbrtowc_l(wchar_t *__restrict dst,
+int attribute_hidden __locale_mbrtowc_l(wchar_t *__restrict dst,
const char *__restrict src,
__locale_t loc )
{
diff --git a/libc/misc/mntent/mntent.c b/libc/misc/mntent/mntent.c
index 7e9febb1f..01970148f 100644
--- a/libc/misc/mntent/mntent.c
+++ b/libc/misc/mntent/mntent.c
@@ -1,6 +1,8 @@
#define strtok_r __strtok_r
#define strstr __strstr
#define atoi __atoi
+#define fseek __fseek
+#define fgets __fgets
#include <stdio.h>
#include <stdlib.h>
diff --git a/libc/misc/pthread/Makefile.in b/libc/misc/pthread/Makefile.in
index 0bbe0fd36..7ce9a84ae 100644
--- a/libc/misc/pthread/Makefile.in
+++ b/libc/misc/pthread/Makefile.in
@@ -5,21 +5,16 @@
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
-CSRC:=no-tsd.c weaks.c
+MISC_PTHREAD_DIR := $(top_srcdir)libc/misc/pthread
+MISC_PTHREAD_OUT := $(top_builddir)libc/misc/pthread
-MISC_PTHREAD_DIR:=$(top_srcdir)libc/misc/pthread
-MISC_PTHREAD_OUT:=$(top_builddir)libc/misc/pthread
+MISC_PTHREAD_CSRC := no-tsd.c
+MISC_PTHREAD_STATIC_CSRC := weaks.c
-MISC_PTHREAD_SRC:=$(patsubst %.c,$(MISC_PTHREAD_DIR)/%.c,$(CSRC))
-MISC_PTHREAD_OBJ:=$(patsubst %.c,$(MISC_PTHREAD_OUT)/%.o,$(CSRC))
+libc-static-$(UCLIBC_HAS_THREADS) += $(patsubst %.c,$(MISC_PTHREAD_OUT)/%.o,$(MISC_PTHREAD_STATIC_CSRC))
+libc-shared-$(UCLIBC_HAS_THREADS) += $(patsubst %.c,$(MISC_PTHREAD_OUT)/%.oS,$(MISC_PTHREAD_CSRC))
-libc-a-$(UCLIBC_HAS_THREADS)+=$(MISC_PTHREAD_OBJ)
-libc-so-$(UCLIBC_HAS_THREADS)+=$(MISC_PTHREAD_OBJ:.o=.os)
-
-libc-multi-$(UCLIBC_HAS_THREADS)+=$(MISC_PTHREAD_DIR)/no-tsd.c
-libc-nomulti-$(UCLIBC_HAS_THREADS)+=$(MISC_PTHREAD_OUT)/weaks.o
-
-objclean-y+=misc_pthread_objclean
+objclean-y += misc_pthread_objclean
misc_pthread_objclean:
- $(RM) $(MISC_PTHREAD_OUT)/*.{o,os}
+ $(RM) $(MISC_PTHREAD_OUT)/*.{o,os,oS}
diff --git a/libc/misc/pthread/weaks.c b/libc/misc/pthread/weaks.c
index b28470251..20a98a3fe 100644
--- a/libc/misc/pthread/weaks.c
+++ b/libc/misc/pthread/weaks.c
@@ -18,109 +18,21 @@
Boston, MA 02111-1307, USA. */
#define _GNU_SOURCE
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
+#include <libc-internal.h>
-/**********************************************************************/
-/* Weaks for application/library use.
+/* Weaks for internal library use only.
*
* We need to define weaks here to cover all the pthread functions that
- * libc itself will use so that we aren't forced to link libc.so to
- * libpthread.so. When an application doesn't use pthreads support,
- * the locking functions used by libc itself basically become no-ops.
- * However, if the application uses pthreads, then it will pull in
- * libpthread.so whose symbols will override these weaks magically
- * turning the internal libc mutex calls from no-ops to real locking
- * calls.
+ * libc itself will use so that we aren't forced to link libc against
+ * libpthread. This file is only used in libc.a and since we have
+ * weaks here, they will be automatically overridden by libpthread.a
+ * if it gets linked in.
*/
-/* glibc itself defines all these, but we don't need them in uClibc
- *
- * Verified by comparing to glibc's linuxthreads/forward.c and defined
- * only those that are in the glibc abi.
- * The commented aliases are ones that were previously defined in uClibc
- * and which I left in for documentation.
- */
-
-static int __pthread_return_0 __P ((void));
+static int __pthread_return_0 (void);
static int __pthread_return_0 (void) { return 0; }
-/*
-weak_alias (__pthread_return_0, pthread_attr_destroy)
-weak_alias (__pthread_return_0, pthread_attr_getdetachstate)
-weak_alias (__pthread_return_0, pthread_attr_getinheritsched)
-weak_alias (__pthread_return_0, pthread_attr_getschedparam)
-weak_alias (__pthread_return_0, pthread_attr_getschedpolicy)
-weak_alias (__pthread_return_0, pthread_attr_getscope)
-weak_alias (__pthread_return_0, pthread_attr_getstackaddr)
-weak_alias (__pthread_return_0, pthread_attr_getstacksize)
-weak_alias (__pthread_return_0, pthread_attr_init)
-weak_alias (__pthread_return_0, pthread_attr_setdetachstate)
-weak_alias (__pthread_return_0, pthread_attr_setinheritsched)
-weak_alias (__pthread_return_0, pthread_attr_setschedparam)
-weak_alias (__pthread_return_0, pthread_attr_setschedpolicy)
-weak_alias (__pthread_return_0, pthread_attr_setscope)
-weak_alias (__pthread_return_0, pthread_attr_setstackaddr)
-weak_alias (__pthread_return_0, pthread_attr_setstacksize)
-weak_alias (__pthread_return_0, pthread_cond_broadcast)
-weak_alias (__pthread_return_0, pthread_cond_destroy)
-weak_alias (__pthread_return_0, pthread_cond_init)
-weak_alias (__pthread_return_0, pthread_cond_signal)
-weak_alias (__pthread_return_0, pthread_cond_timedwait)
-weak_alias (__pthread_return_0, pthread_cond_wait)
-weak_alias (__pthread_return_0, pthread_condattr_destroy)
-weak_alias (__pthread_return_0, pthread_condattr_init)
-weak_alias (__pthread_return_0, pthread_getschedparam)
-weak_alias (__pthread_return_0, pthread_getcancelstate)
-weak_alias (__pthread_return_0, pthread_getconcurrency)
-weak_alias (__pthread_return_0, pthread_mutex_destroy)
-weak_alias (__pthread_return_0, pthread_mutex_init)
-weak_alias (__pthread_return_0, pthread_mutex_lock)
-weak_alias (__pthread_return_0, pthread_mutex_trylock)
-weak_alias (__pthread_return_0, pthread_mutex_unlock)
-weak_alias (__pthread_return_0, pthread_mutexattr_destroy)
-weak_alias (__pthread_return_0, pthread_mutexattr_gettype)
-weak_alias (__pthread_return_0, pthread_mutexattr_init)
-weak_alias (__pthread_return_0, pthread_mutexattr_settype)
-weak_alias (__pthread_return_0, pthread_rwlock_destroy)
-weak_alias (__pthread_return_0, pthread_rwlock_init)
-weak_alias (__pthread_return_0, pthread_rwlock_rdlock)
-weak_alias (__pthread_return_0, pthread_rwlock_tryrdlock)
-weak_alias (__pthread_return_0, pthread_rwlock_trywrlock)
-weak_alias (__pthread_return_0, pthread_rwlock_unlock)
-weak_alias (__pthread_return_0, pthread_rwlock_wrlock)
-weak_alias (__pthread_return_0, pthread_rwlockattr_destroy)
-weak_alias (__pthread_return_0, pthread_rwlockattr_getpshared)
-weak_alias (__pthread_return_0, pthread_rwlockattr_init)
-weak_alias (__pthread_return_0, pthread_rwlockattr_setpshared)
-weak_alias (__pthread_return_0, pthread_self)
-weak_alias (__pthread_return_0, pthread_setcancelstate)
-weak_alias (__pthread_return_0, pthread_setcanceltype)
-weak_alias (__pthread_return_0, pthread_setconcurrency)
-weak_alias (__pthread_return_0, pthread_setschedparam)
-
-static int __pthread_return_1 __P ((void));
-static int __pthread_return_1 (void) { return 1; }
-
-weak_alias (__pthread_return_1, pthread_equal)
-
-void weak_function pthread_exit (void *retval)
-{
- exit (EXIT_SUCCESS);
-}
-*/
-
-/**********************************************************************/
-/* Weaks used internally by the C library. */
weak_alias (__pthread_return_0, __pthread_mutex_init)
weak_alias (__pthread_return_0, __pthread_mutex_lock)
weak_alias (__pthread_return_0, __pthread_mutex_trylock)
weak_alias (__pthread_return_0, __pthread_mutex_unlock)
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
-weak_alias (__pthread_return_0, pthread_mutexattr_init)
-weak_alias (__pthread_return_0, pthread_mutexattr_settype)
-weak_alias (__pthread_return_0, pthread_mutexattr_destroy)
-#endif
-
-/**********************************************************************/
diff --git a/libc/misc/regex/regcomp.c b/libc/misc/regex/regcomp.c
index 83df61108..419d879be 100644
--- a/libc/misc/regex/regcomp.c
+++ b/libc/misc/regex/regcomp.c
@@ -292,7 +292,7 @@ re_set_fastmap (char *fastmap, int icase, int ch)
{
fastmap[ch] = 1;
if (icase)
- fastmap[tolower (ch)] = 1;
+ fastmap[__tolower (ch)] = 1;
}
/* Helper function for re_compile_fastmap.
@@ -833,7 +833,14 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);
dfa->state_hash_mask = table_size - 1;
+#ifdef __UCLIBC_HAS_WCHAR__
+# undef MB_CUR_MAX
+# define MB_CUR_MAX (_stdlib_mb_cur_max_internal ())
+extern size_t _stdlib_mb_cur_max_internal (void) __THROW __wur attribute_hidden;
dfa->mb_cur_max = MB_CUR_MAX;
+#else
+ dfa->mb_cur_max = 1;
+#endif
#ifdef _LIBC
if (dfa->mb_cur_max == 6
&& strcmp (_NL_CURRENT (LC_CTYPE, _NL_CTYPE_CODESET_NAME), "UTF-8") == 0)
diff --git a/libc/misc/regex/regex.c b/libc/misc/regex/regex.c
index 5220ba57c..99de9fd6c 100644
--- a/libc/misc/regex/regex.c
+++ b/libc/misc/regex/regex.c
@@ -38,6 +38,9 @@
#define iswctype __iswctype
#define iswlower __iswlower
#define iswalnum __iswalnum
+#define towlower __towlower
+#define towupper __towupper
+#define mbsinit __mbsinit
#include <wchar.h>
#include <wctype.h>
diff --git a/libc/misc/regex/regex_internal.c b/libc/misc/regex/regex_internal.c
index f9814d290..c1ee85040 100644
--- a/libc/misc/regex/regex_internal.c
+++ b/libc/misc/regex/regex_internal.c
@@ -289,7 +289,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
{
/* In case of a singlebyte character. */
pstr->mbs[byte_idx]
- = toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]);
+ = __toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]);
/* The next step uses the assumption that wchar_t is encoded
ASCII-safe: all ASCII values can be converted like this. */
pstr->wcs[byte_idx] = (wchar_t) pstr->mbs[byte_idx];
@@ -523,7 +523,7 @@ build_upper_buffer (re_string_t *pstr)
if (BE (pstr->trans != NULL, 0))
ch = pstr->trans[ch];
if (islower (ch))
- pstr->mbs[char_idx] = toupper (ch);
+ pstr->mbs[char_idx] = __toupper (ch);
else
pstr->mbs[char_idx] = ch;
}
diff --git a/libc/misc/regex/regex_internal.h b/libc/misc/regex/regex_internal.h
index 14d14da3c..4782883c1 100644
--- a/libc/misc/regex/regex_internal.h
+++ b/libc/misc/regex/regex_internal.h
@@ -670,7 +670,9 @@ typedef struct
{
unsigned char ch;
unsigned char *name;
+#ifdef __UCLIBC_HAS_WCHAR__
wchar_t wch;
+#endif
} opr;
} bracket_elem_t;
diff --git a/libc/misc/regex/regex_old.c b/libc/misc/regex/regex_old.c
index 6bb319acd..9031cebff 100644
--- a/libc/misc/regex/regex_old.c
+++ b/libc/misc/regex/regex_old.c
@@ -35,12 +35,15 @@
#define iswctype __iswctype
#define iswalnum __iswalnum
#define printf __printf
+#define btowc __btowc
/* To exclude some unwanted junk.... */
-#undef _LIBC
#undef emacs
#define _REGEX_RE_COMP
#include <features.h>
+#ifdef __UCLIBC__
+# undef _LIBC
+#endif
#include <stdlib.h>
#include <string.h>
#define STDC_HEADERS
@@ -88,7 +91,7 @@ extern void *__mempcpy (void *__restrict __dest,
# include <wctype.h>
# endif
-# ifdef _LIBC
+# if defined _LIBC || defined __UCLIBC__
/* We have to keep the namespace clean. */
# define regfree(preg) __regfree (preg)
# define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef)
@@ -113,11 +116,13 @@ extern void *__mempcpy (void *__restrict __dest,
# define btowc __btowc
/* We are also using some library internals. */
+# ifndef __UCLIBC__
# include <locale/localeinfo.h>
# include <locale/elem-hash.h>
# include <langinfo.h>
# include <locale/coll-lookup.h>
# endif
+# endif
/* This is for other GNU distributions with internationalized messages. */
# if HAVE_LIBINTL_H || defined _LIBC
@@ -217,6 +222,9 @@ char *realloc ();
# endif
/* Get the interface, including the syntax bits. */
+# ifdef __UCLIBC__
+# include "_regex.h"
+# endif
# include <regex.h>
/* isalpha etc. are used for the character classes. */
@@ -267,7 +275,7 @@ char *realloc ();
# ifdef _tolower
# define TOLOWER(c) _tolower(c)
# else
-# define TOLOWER(c) tolower(c)
+# define TOLOWER(c) __tolower(c)
# endif
# ifndef NULL
@@ -1380,7 +1388,7 @@ re_set_syntax (syntax)
# endif /* DEBUG */
return ret;
}
-# ifdef _LIBC
+# if defined _LIBC || defined __UCLIBC__
weak_alias (__re_set_syntax, re_set_syntax)
# endif
@@ -5000,7 +5008,7 @@ re_compile_fastmap (bufp)
# endif
return byte_re_compile_fastmap(bufp);
} /* re_compile_fastmap */
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_alias (__re_compile_fastmap, re_compile_fastmap)
#endif
@@ -5039,7 +5047,7 @@ re_set_registers (bufp, regs, num_regs, starts, ends)
regs->start = regs->end = (regoff_t *) 0;
}
}
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_alias (__re_set_registers, re_set_registers)
#endif
@@ -5058,7 +5066,7 @@ re_search (bufp, string, size, startpos, range, regs)
return re_search_2 (bufp, NULL, 0, string, size, startpos, range,
regs, size);
}
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_alias (__re_search, re_search)
#endif
@@ -5103,7 +5111,7 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop)
return byte_re_search_2 (bufp, string1, size1, string2, size2, startpos,
range, regs, stop);
} /* re_search_2 */
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_alias (__re_search_2, re_search_2)
#endif
@@ -5562,7 +5570,7 @@ re_match (bufp, string, size, pos, regs)
# endif
return result;
}
-# ifdef _LIBC
+# if defined _LIBC || defined __UCLIBC__
weak_alias (__re_match, re_match)
# endif
#endif /* not emacs */
@@ -5623,7 +5631,7 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
#endif
return result;
}
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_alias (__re_match_2, re_match_2)
#endif
@@ -7962,7 +7970,7 @@ re_compile_pattern (pattern, length, bufp)
return NULL;
return gettext (re_error_msgid + re_error_msgid_idx[(int) ret]);
}
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_alias (__re_compile_pattern, re_compile_pattern)
#endif
@@ -8029,7 +8037,7 @@ re_comp (s)
int
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_function
#endif
re_exec (s)
@@ -8158,7 +8166,7 @@ regcomp (preg, pattern, cflags)
return (int) ret;
}
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_alias (__regcomp, regcomp)
#endif
@@ -8236,7 +8244,7 @@ regexec (preg, string, nmatch, pmatch, eflags)
/* We want zero return to mean success, unlike `re_search'. */
return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
}
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_alias (__regexec, regexec)
#endif
@@ -8284,7 +8292,7 @@ regerror (errcode, preg, errbuf, errbuf_size)
return msg_size;
}
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_alias (__regerror, regerror)
#endif
@@ -8311,7 +8319,7 @@ regfree (preg)
free (preg->translate);
preg->translate = NULL;
}
-#ifdef _LIBC
+#if defined _LIBC || defined __UCLIBC__
weak_alias (__regfree, regfree)
#endif
diff --git a/libc/misc/statfs/fstatfs64.c b/libc/misc/statfs/fstatfs64.c
index b793002fb..63bd640b7 100644
--- a/libc/misc/statfs/fstatfs64.c
+++ b/libc/misc/statfs/fstatfs64.c
@@ -18,6 +18,8 @@
02111-1307 USA. */
#include <features.h>
+#undef __fstatfs64
+#undef __fstatfs
#ifdef __UCLIBC_HAS_LFS__
@@ -40,12 +42,13 @@
#include <sys/statvfs.h>
#include <stddef.h>
+#undef fstatfs64
/* Return information about the filesystem on which FD resides. */
-int fstatfs64 (int fd, struct statfs64 *buf)
+int attribute_hidden __fstatfs64 (int fd, struct statfs64 *buf)
{
struct statfs buf32;
- if (fstatfs (fd, &buf32) < 0)
+ if (__fstatfs (fd, &buf32) < 0)
return -1;
buf->f_type = buf32.f_type;
@@ -61,6 +64,6 @@ int fstatfs64 (int fd, struct statfs64 *buf)
return 0;
}
+strong_alias(__fstatfs64,fstatfs64)
#endif /* __UCLIBC_HAS_LFS__ */
-
diff --git a/libc/misc/statfs/fstatvfs.c b/libc/misc/statfs/fstatvfs.c
index b79195e73..14ef6ecce 100644
--- a/libc/misc/statfs/fstatvfs.c
+++ b/libc/misc/statfs/fstatvfs.c
@@ -17,8 +17,6 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#define strsep __strsep
-
#include <features.h>
#define __USE_GNU
@@ -37,10 +35,10 @@ int fstatvfs (int fd, struct statvfs *buf)
struct stat st;
/* Get as much information as possible from the system. */
- if (fstatfs (fd, &fsbuf) < 0)
+ if (__fstatfs (fd, &fsbuf) < 0)
return -1;
-#define STAT(st) fstat (fd, st)
+#define STAT(st) __fstat (fd, st)
#include "internal_statvfs.c"
/* We signal success if the statfs call succeeded. */
diff --git a/libc/misc/statfs/fstatvfs64.c b/libc/misc/statfs/fstatvfs64.c
index 0d7416df3..993caf955 100644
--- a/libc/misc/statfs/fstatvfs64.c
+++ b/libc/misc/statfs/fstatvfs64.c
@@ -17,8 +17,6 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#define strsep __strsep
-
#include <features.h>
#ifdef __UCLIBC_HAS_LFS__
@@ -50,10 +48,10 @@ int fstatvfs (int fd, struct statvfs *buf)
struct stat st;
/* Get as much information as possible from the system. */
- if (fstatfs (fd, &fsbuf) < 0)
+ if (__fstatfs (fd, &fsbuf) < 0)
return -1;
-#define STAT(st) fstat (fd, st)
+#define STAT(st) __fstat (fd, st)
#include "internal_statvfs.c"
/* We signal success if the statfs call succeeded. */
diff --git a/libc/misc/statfs/internal_statvfs.c b/libc/misc/statfs/internal_statvfs.c
index 4e25edc3f..d41c3052d 100644
--- a/libc/misc/statfs/internal_statvfs.c
+++ b/libc/misc/statfs/internal_statvfs.c
@@ -18,12 +18,18 @@
02111-1307 USA. */
extern FILE *__setmntent (__const char *__file, __const char *__mode) __THROW attribute_hidden;
+
extern struct mntent *__getmntent_r (FILE *__restrict __stream,
struct mntent *__restrict __result,
char *__restrict __buffer,
int __bufsize) __THROW attribute_hidden;
+
extern int __endmntent (FILE *__stream) __THROW attribute_hidden;
+extern char *__strsep (char **__restrict __stringp,
+ __const char *__restrict __delim)
+ __THROW __nonnull ((1, 2)) attribute_hidden;
+
/* Now fill in the fields we have information for. */
buf->f_bsize = fsbuf.f_bsize;
/* Linux does not support f_frsize, so set it to the full block size. */
@@ -77,7 +83,7 @@ extern int __endmntent (FILE *__stream) __THROW attribute_hidden;
struct stat fsst;
/* Find out about the device the current entry is for. */
- if (stat (mntbuf.mnt_dir, &fsst) >= 0
+ if (__stat (mntbuf.mnt_dir, &fsst) >= 0
&& st.st_dev == fsst.st_dev)
{
/* Bingo, we found the entry for the device FD is on.
@@ -85,7 +91,7 @@ extern int __endmntent (FILE *__stream) __THROW attribute_hidden;
char *cp = mntbuf.mnt_opts;
char *opt;
- while ((opt = strsep (&cp, ",")) != NULL)
+ while ((opt = __strsep (&cp, ",")) != NULL)
if (__strcmp (opt, "ro") == 0)
buf->f_flag |= ST_RDONLY;
else if (__strcmp (opt, "nosuid") == 0)
diff --git a/libc/misc/statfs/statfs64.c b/libc/misc/statfs/statfs64.c
index 7144cce71..9d326f1f8 100644
--- a/libc/misc/statfs/statfs64.c
+++ b/libc/misc/statfs/statfs64.c
@@ -18,6 +18,8 @@
02111-1307 USA. */
#include <features.h>
+#undef __statfs64
+#undef __statfs
#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64
#undef _FILE_OFFSET_BITS
@@ -37,13 +39,13 @@
#include <sys/statfs.h>
#if defined __UCLIBC_HAS_LFS__
-
+#undef statfs64
/* Return information about the filesystem on which FILE resides. */
-int statfs64 (const char *file, struct statfs64 *buf)
+int attribute_hidden __statfs64 (const char *file, struct statfs64 *buf)
{
struct statfs buf32;
- if (statfs (file, &buf32) < 0)
+ if (__statfs (file, &buf32) < 0)
return -1;
buf->f_type = buf32.f_type;
@@ -59,4 +61,6 @@ int statfs64 (const char *file, struct statfs64 *buf)
return 0;
}
+strong_alias(__statfs64,statfs64)
+
#endif
diff --git a/libc/misc/statfs/statvfs.c b/libc/misc/statfs/statvfs.c
index 0fe239573..a7c553fb6 100644
--- a/libc/misc/statfs/statvfs.c
+++ b/libc/misc/statfs/statvfs.c
@@ -17,8 +17,6 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#define strsep __strsep
-
#include <features.h>
#define __USE_GNU
@@ -31,17 +29,16 @@
#include <sys/statfs.h>
#include <sys/statvfs.h>
-
int statvfs (const char *file, struct statvfs *buf)
{
struct statfs fsbuf;
struct stat st;
/* Get as much information as possible from the system. */
- if (statfs (file, &fsbuf) < 0)
+ if (__statfs (file, &fsbuf) < 0)
return -1;
-#define STAT(st) stat (file, st)
+#define STAT(st) __stat (file, st)
#include "internal_statvfs.c"
/* We signal success if the statfs call succeeded. */
diff --git a/libc/misc/statfs/statvfs64.c b/libc/misc/statfs/statvfs64.c
index 8bacbba70..dc2458f5f 100644
--- a/libc/misc/statfs/statvfs64.c
+++ b/libc/misc/statfs/statvfs64.c
@@ -17,8 +17,6 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#define strsep __strsep
-
#include <features.h>
#ifdef __UCLIBC_HAS_LFS__
@@ -51,10 +49,10 @@ int statvfs (const char *file, struct statvfs *buf)
struct stat st;
/* Get as much information as possible from the system. */
- if (statfs (file, &fsbuf) < 0)
+ if (__statfs (file, &fsbuf) < 0)
return -1;
-#define STAT(st) stat (file, st)
+#define STAT(st) __stat (file, st)
#include "internal_statvfs.c"
/* We signal success if the statfs call succeeded. */
diff --git a/libc/misc/syslog/syslog.c b/libc/misc/syslog/syslog.c
index 649f36d65..a4bb56bfc 100644
--- a/libc/misc/syslog/syslog.c
+++ b/libc/misc/syslog/syslog.c
@@ -153,7 +153,7 @@ retry:
UNLOCK;
return;
}
- /* fcntl(LogFile, F_SETFD, 1); */
+ /* __fcntl(LogFile, F_SETFD, 1); */
}
}
diff --git a/libc/misc/sysvipc/ftok.c b/libc/misc/sysvipc/ftok.c
index 2bd8b2ec0..fd4021d3e 100644
--- a/libc/misc/sysvipc/ftok.c
+++ b/libc/misc/sysvipc/ftok.c
@@ -25,7 +25,7 @@ key_t ftok (const char *pathname, int proj_id)
struct stat st;
key_t key;
- if (stat(pathname, &st) < 0)
+ if (__stat(pathname, &st) < 0)
return (key_t) -1;
key = ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16)
diff --git a/libc/misc/time/time.c b/libc/misc/time/time.c
index fac85638e..74b38f99e 100644
--- a/libc/misc/time/time.c
+++ b/libc/misc/time/time.c
@@ -754,7 +754,7 @@ time_t mktime(struct tm *timeptr)
/* Another name for `mktime'. */
/* time_t timelocal(struct tm *tp) */
-weak_alias(mktime,timelocal);
+weak_alias(mktime,timelocal)
#endif
/**********************************************************************/
diff --git a/libc/misc/ttyent/getttyent.c b/libc/misc/ttyent/getttyent.c
index 8e104733c..9b83b6ede 100644
--- a/libc/misc/ttyent/getttyent.c
+++ b/libc/misc/ttyent/getttyent.c
@@ -29,6 +29,7 @@
#define __fsetlocking __fsetlocking_internal
#define rewind __rewind
+#define fgets_unlocked __fgets_unlocked
#define _GNU_SOURCE
#include <features.h>
@@ -42,6 +43,8 @@
#include <pthread.h>
#endif
+extern int __getc_unlocked (FILE *__stream) attribute_hidden;
+
static char zapchar;
static FILE *tf;
static struct ttyent tty;
@@ -130,7 +133,7 @@ struct ttyent attribute_hidden * __getttyent(void)
}
/* skip lines that are too big */
if (!__strchr(p, '\n')) {
- while ((c = getc_unlocked(tf)) != '\n' && c != EOF)
+ while ((c = __getc_unlocked(tf)) != '\n' && c != EOF)
;
continue;
}
diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c
index 374b53b93..3ad5bc828 100644
--- a/libc/misc/utmp/utent.c
+++ b/libc/misc/utmp/utent.c
@@ -49,9 +49,9 @@ void attribute_hidden __setutent(void)
}
}
/* Make sure the file will be closed on exec() */
- ret = fcntl(static_fd, F_GETFD, 0);
+ ret = __fcntl(static_fd, F_GETFD, 0);
if (ret >= 0) {
- ret = fcntl(static_fd, F_GETFD, 0);
+ ret = __fcntl(static_fd, F_GETFD, 0);
}
if (ret < 0) {
bummer:
@@ -61,7 +61,7 @@ bummer:
return;
}
}
- lseek(static_fd, 0, SEEK_SET);
+ __lseek(static_fd, 0, SEEK_SET);
UNLOCK;
return;
}
@@ -151,14 +151,14 @@ struct utmp *pututline (const struct utmp *utmp_entry)
LOCK;
/* Ignore the return value. That way, if they've already positioned
the file pointer where they want it, everything will work out. */
- lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
+ __lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
if (__getutid(utmp_entry) != NULL) {
- lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
+ __lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
if (__write(static_fd, utmp_entry, sizeof(struct utmp)) != sizeof(struct utmp))
return NULL;
} else {
- lseek(static_fd, (off_t) 0, SEEK_END);
+ __lseek(static_fd, (off_t) 0, SEEK_END);
if (__write(static_fd, utmp_entry, sizeof(struct utmp)) != sizeof(struct utmp))
return NULL;
}
diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c
index bfedeaa70..35947f19e 100644
--- a/libc/misc/utmp/wtent.c
+++ b/libc/misc/utmp/wtent.c
@@ -52,9 +52,9 @@ extern void updwtmp(const char *wtmp_file, const struct utmp *lutmp)
fd = __open(wtmp_file, O_APPEND | O_WRONLY, 0);
if (fd >= 0) {
- if (lockf(fd, F_LOCK, 0)==0) {
+ if (__lockf(fd, F_LOCK, 0)==0) {
__write(fd, (const char *) lutmp, sizeof(struct utmp));
- lockf(fd, F_ULOCK, 0);
+ __lockf(fd, F_ULOCK, 0);
__close(fd);
}
}
diff --git a/libc/misc/wchar/wchar.c b/libc/misc/wchar/wchar.c
index 1a16fc9d6..2535b5fff 100644
--- a/libc/misc/wchar/wchar.c
+++ b/libc/misc/wchar/wchar.c
@@ -260,10 +260,11 @@ int wctob(wint_t c)
/**********************************************************************/
#ifdef L_mbsinit
-int mbsinit(const mbstate_t *ps)
+int attribute_hidden __mbsinit(const mbstate_t *ps)
{
return !ps || !ps->__mask;
}
+strong_alias(__mbsinit,mbsinit)
#endif
/**********************************************************************/
@@ -787,10 +788,7 @@ size_t attribute_hidden __mbsnrtowcs(wchar_t *__restrict dst, const char **__res
}
return len - count;
}
-
-size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
- size_t NMC, size_t len, mbstate_t *__restrict ps)
- __attribute__ ((__weak__, __alias__("__mbsnrtowcs")));
+weak_alias(__mbsnrtowcs,mbsnrtowcs)
#endif
/**********************************************************************/
@@ -909,10 +907,7 @@ size_t attribute_hidden __wcsnrtombs(char *__restrict dst, const wchar_t **__res
}
return len - count;
}
-
-size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
- size_t NWC, size_t len, mbstate_t *__restrict ps)
- __attribute__ ((__weak__, __alias__("__wcsnrtombs")));
+weak_alias(__wcsnrtombs,wcsnrtombs)
#endif
/**********************************************************************/
diff --git a/libc/misc/wchar/wstdio.c b/libc/misc/wchar/wstdio.c
index 91917683a..55e7fef6b 100644
--- a/libc/misc/wchar/wstdio.c
+++ b/libc/misc/wchar/wstdio.c
@@ -53,6 +53,7 @@
#define wcsrtombs __wcsrtombs
#define mbrtowc __mbrtowc
#define wcrtomb __wcrtomb
+#define fflush_unlocked __fflush_unlocked
#define _GNU_SOURCE
#include <stdio.h>
@@ -288,7 +289,7 @@ UNLOCKED(wchar_t *,fgetws,(wchar_t *__restrict ws, int n,
wint_t wi;
while ((n > 1)
- && ((wi = fgetwc_unlocked(stream)) != WEOF)
+ && ((wi = __fgetwc_unlocked(stream)) != WEOF)
&& ((*p++ = wi) != '\n')
) {
--n;
diff --git a/libc/misc/wctype/wctype.c b/libc/misc/wctype/wctype.c
index 8ef373205..659000558 100644
--- a/libc/misc/wctype/wctype.c
+++ b/libc/misc/wctype/wctype.c
@@ -39,6 +39,8 @@
#include <bits/uClibc_uwchar.h>
extern wctype_t __wctype (__const char *__property) attribute_hidden;
+extern wint_t __towlower (wint_t __wc) __THROW attribute_hidden;
+extern wint_t __towupper (wint_t __wc) __THROW attribute_hidden;
#if defined(__LOCALE_C_ONLY) && defined(__UCLIBC_DO_XLOCALE)
#error xlocale functionality is not supported in stub locale mode.
@@ -46,10 +48,10 @@ extern wctype_t __wctype (__const char *__property) attribute_hidden;
#ifdef __UCLIBC_HAS_XLOCALE__
#include <xlocale.h>
-extern wint_t __towlower_l(wint_t __wc, __locale_t __locale) __THROW;
-extern wint_t __towupper_l(wint_t __wc, __locale_t __locale) __THROW;
+extern wint_t __towlower_l(wint_t __wc, __locale_t __locale) __THROW attribute_hidden;
+extern wint_t __towupper_l(wint_t __wc, __locale_t __locale) __THROW attribute_hidden;
extern int __iswctype_l(wint_t __wc, wctype_t __desc, __locale_t __locale) __THROW attribute_hidden;
-extern wint_t __towctrans_l(wint_t __wc, wctrans_t __desc, __locale_t __locale) __THROW;
+extern wint_t __towctrans_l(wint_t __wc, wctrans_t __desc, __locale_t __locale) __THROW attribute_hidden;
#endif /* __UCLIBC_HAS_XLOCALE__ */
/* We know wide char support is enabled. We wouldn't be here otherwise. */
@@ -278,7 +280,7 @@ ISW_FUNC_BODY(xdigit);
#if defined(L_towlower) || defined(L_towlower_l)
#ifdef L_towlower
-#define TOWLOWER(w) towlower(w)
+#define TOWLOWER(w) __towlower(w)
#else /* L_towlower */
#define TOWLOWER(w) __towlower_l(w, __locale_t locale)
#undef __UCLIBC_CURLOCALE_DATA
@@ -290,7 +292,7 @@ ISW_FUNC_BODY(xdigit);
#ifdef __UCLIBC_HAS_XLOCALE__
#define TOWCTRANS(w,d) __towctrans_l(w,d, __UCLIBC_CURLOCALE)
#else /* __UCLIBC_HAS_XLOCALE__ */
-#define TOWCTRANS(w,d) towctrans(w,d)
+#define TOWCTRANS(w,d) __towctrans(w,d)
#endif /* __UCLIBC_HAS_XLOCALE__ */
#define __C_towlower(wc) \
@@ -298,7 +300,7 @@ ISW_FUNC_BODY(xdigit);
#ifdef __LOCALE_C_ONLY
-wint_t towlower(wint_t wc)
+wint_t attribute_hidden __towlower(wint_t wc)
{
#ifdef __UCLIBC_HAS_CTYPE_TABLES__
return __C_towlower(wc);
@@ -315,14 +317,14 @@ wint_t towlower(wint_t wc)
#if defined(L_towlower) && defined(__UCLIBC_HAS_XLOCALE__)
-wint_t towlower(wint_t wc)
+wint_t attribute_hidden __towlower(wint_t wc)
{
return __towctrans_l(wc, _CTYPE_tolower, __UCLIBC_CURLOCALE);
}
#else /* defined(L_towlower) && defined(__UCLIBC_HAS_XLOCALE__) */
-wint_t TOWLOWER(wint_t wc)
+wint_t attribute_hidden TOWLOWER(wint_t wc)
{
return TOWCTRANS(wc, _CTYPE_tolower);
}
@@ -333,14 +335,14 @@ wint_t TOWLOWER(wint_t wc)
#if defined(L_towlower) && defined(__UCLIBC_HAS_XLOCALE__)
-wint_t towlower(wint_t wc)
+wint_t attribute_hidden __towlower(wint_t wc)
{
return __towlower_l(wc, __UCLIBC_CURLOCALE);
}
#else /* defined(L_towlower) && defined(__UCLIBC_HAS_XLOCALE__) */
-wint_t TOWLOWER(wint_t wc)
+wint_t attribute_hidden TOWLOWER(wint_t wc)
{
unsigned int sc, n, i;
__uwchar_t u = wc;
@@ -371,17 +373,21 @@ wint_t TOWLOWER(wint_t wc)
#endif /* SMALL_UPLOW */
#ifdef L_towlower_l
-weak_alias(__towlower_l, towlower_l)
+strong_alias(__towlower_l,towlower_l)
#endif /* L_towlower_l */
#endif /* __LOCALE_C_ONLY */
+#ifndef L_towlower_l
+strong_alias(__towlower,towlower)
+#endif
+
#endif
/**********************************************************************/
#if defined(L_towupper) || defined(L_towupper_l)
#ifdef L_towupper
-#define TOWUPPER(w) towupper(w)
+#define TOWUPPER(w) __towupper(w)
#else /* L_towupper */
#define TOWUPPER(w) __towupper_l(w, __locale_t locale)
#undef __UCLIBC_CURLOCALE_DATA
@@ -393,7 +399,7 @@ weak_alias(__towlower_l, towlower_l)
#ifdef __UCLIBC_HAS_XLOCALE__
#define TOWCTRANS(w,d) __towctrans_l(w,d, __UCLIBC_CURLOCALE)
#else /* __UCLIBC_HAS_XLOCALE__ */
-#define TOWCTRANS(w,d) towctrans(w,d)
+#define TOWCTRANS(w,d) __towctrans(w,d)
#endif /* __UCLIBC_HAS_XLOCALE__ */
#define __C_towupper(wc) \
@@ -401,7 +407,7 @@ weak_alias(__towlower_l, towlower_l)
#ifdef __LOCALE_C_ONLY
-wint_t towupper(wint_t wc)
+wint_t attribute_hidden __towupper(wint_t wc)
{
#ifdef __UCLIBC_HAS_CTYPE_TABLES__
return __C_towupper(wc);
@@ -419,14 +425,14 @@ wint_t towupper(wint_t wc)
#if defined(L_towupper) && defined(__UCLIBC_HAS_XLOCALE__)
-wint_t towupper(wint_t wc)
+wint_t attribute_hidden __towupper(wint_t wc)
{
return __towctrans_l(wc, _CTYPE_toupper, __UCLIBC_CURLOCALE);
}
#else /* defined(L_towupper) && defined(__UCLIBC_HAS_XLOCALE__) */
-wint_t TOWUPPER(wint_t wc)
+wint_t attribute_hidden TOWUPPER(wint_t wc)
{
return TOWCTRANS(wc, _CTYPE_toupper);
}
@@ -437,14 +443,14 @@ wint_t TOWUPPER(wint_t wc)
#if defined(L_towupper) && defined(__UCLIBC_HAS_XLOCALE__)
-wint_t towupper(wint_t wc)
+wint_t attribute_hidden __towupper(wint_t wc)
{
return __towupper_l(wc, __UCLIBC_CURLOCALE);
}
#else /* defined(L_towupper) && defined(__UCLIBC_HAS_XLOCALE__) */
-wint_t TOWUPPER(wint_t wc)
+wint_t attribute_hidden TOWUPPER(wint_t wc)
{
unsigned int sc, n, i;
__uwchar_t u = wc;
@@ -475,11 +481,15 @@ wint_t TOWUPPER(wint_t wc)
#endif /* SMALL_UPLOW */
#ifdef L_towupper_l
-weak_alias(__towupper_l, towupper_l)
+strong_alias(__towupper_l,towupper_l)
#endif /* L_towupper_l */
#endif /* __LOCALE_C_ONLY */
+#ifndef L_towupper_l
+strong_alias(__towupper,towupper)
+#endif
+
#endif
/**********************************************************************/
#ifdef L_wctype
@@ -718,14 +728,14 @@ weak_alias(__iswctype, iswctype)
#ifndef _tolower
#warning _tolower is undefined!
-#define _tolower(c) tolower(c)
+#define _tolower(c) __tolower(c)
#endif
#ifndef _toupper
#warning _toupper is undefined!
-#define _toupper(c) toupper(c)
+#define _toupper(c) __toupper(c)
#endif
-wint_t towctrans(wint_t wc, wctrans_t desc)
+wint_t attribute_hidden __towctrans(wint_t wc, wctrans_t desc)
{
if (((unsigned int)(desc - _CTYPE_tolower))
<= (_CTYPE_toupper - _CTYPE_tolower)
@@ -743,7 +753,7 @@ wint_t towctrans(wint_t wc, wctrans_t desc)
#else /* __LOCALE_C_ONLY */
#ifdef L_towctrans
-#define TOWCTRANS(w,d) towctrans(w,d)
+#define TOWCTRANS(w,d) __towctrans(w,d)
#else /* L_towctrans */
#define TOWCTRANS(w,d) __towctrans_l(w,d, __locale_t locale)
#undef __UCLIBC_CURLOCALE_DATA
@@ -756,13 +766,13 @@ wint_t towctrans(wint_t wc, wctrans_t desc)
#define TOWLOWER(w,l) __towlower_l(w,l)
#define TOWUPPER(w,l) __towupper_l(w,l)
#else /* __UCLIBC_HAS_XLOCALE__ */
-#define TOWLOWER(w,l) towlower(w)
-#define TOWUPPER(w,l) towupper(w)
+#define TOWLOWER(w,l) __towlower(w)
+#define TOWUPPER(w,l) __towupper(w)
#endif /* __UCLIBC_HAS_XLOCALE__ */
#if defined(L_towctrans) && defined(__UCLIBC_HAS_XLOCALE__)
-wint_t towctrans(wint_t wc, wctrans_t desc)
+wint_t attribute_hidden __towctrans(wint_t wc, wctrans_t desc)
{
return __towctrans_l(wc, desc, __UCLIBC_CURLOCALE);
}
@@ -771,7 +781,7 @@ wint_t towctrans(wint_t wc, wctrans_t desc)
#ifdef SMALL_UPLOW
-wint_t TOWCTRANS(wint_t wc, wctrans_t desc)
+wint_t attribute_hidden TOWCTRANS(wint_t wc, wctrans_t desc)
{
unsigned int sc, n, i;
__uwchar_t u = wc;
@@ -829,7 +839,7 @@ wint_t TOWCTRANS(wint_t wc, wctrans_t desc)
#else /* SMALL_UPLOW */
-wint_t TOWCTRANS(wint_t wc, wctrans_t desc)
+wint_t attribute_hidden TOWCTRANS(wint_t wc, wctrans_t desc)
{
if (ENCODING == __ctype_encoding_7_bit) {
if ((((__uwchar_t) wc) > 0x7f)
@@ -872,18 +882,22 @@ wint_t TOWCTRANS(wint_t wc, wctrans_t desc)
#endif /* defined(L_towctrans) && defined(__UCLIBC_HAS_XLOCALE__) */
#ifdef L_towctrans_l
-weak_alias(__towctrans_l, towctrans_l)
+strong_alias(__towctrans_l, towctrans_l)
#endif /* L_towctrans_l */
#endif /* __LOCALE_C_ONLY */
+#ifndef L_towctrans_l
+strong_alias(__towctrans,towctrans)
+#endif
+
#endif
/**********************************************************************/
#ifdef L_wctrans
static const char transstring[] = __CTYPE_TRANSTRING;
-wctrans_t wctrans(const char *property)
+wctrans_t attribute_hidden __wctrans(const char *property)
{
const unsigned char *p;
int i;
@@ -901,6 +915,7 @@ wctrans_t wctrans(const char *property)
/* TODO - Add locale-specific translations. */
return 0;
}
+strong_alias(__wctrans,wctrans)
#endif
/**********************************************************************/
@@ -910,9 +925,11 @@ wctrans_t wctrans(const char *property)
#warning REMINDER: Currently wctrans_l simply calls wctrans.
#endif /* __UCLIBC_MJN3_ONLY__ */
+extern wctrans_t __wctrans (__const char *__property) __THROW attribute_hidden;
+
wctrans_t __wctrans_l(const char *property, __locale_t locale)
{
- return wctrans(property);
+ return __wctrans(property);
}
weak_alias(__wctrans_l, wctrans_l)
diff --git a/libc/misc/wordexp/wordexp.c b/libc/misc/wordexp/wordexp.c
index e76d6a63a..a91e64e3c 100644
--- a/libc/misc/wordexp/wordexp.c
+++ b/libc/misc/wordexp/wordexp.c
@@ -23,6 +23,8 @@
#define stpcpy __stpcpy
#define strndup __strndup
#define strspn __strspn
+#define strcspn __strcspn
+#define setenv __setenv
#define unsetenv __unsetenv
#define waitpid __waitpid
#define kill __kill
@@ -34,13 +36,10 @@
#define atoi __atoi
#define fnmatch __fnmatch
#define pipe __pipe
-#if 0
-#define glob __glob
-#define globfree __globfree
-#endif
+#define fork __fork
#define _GNU_SOURCE
-#include <sys/cdefs.h>
+#include <features.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
@@ -56,6 +55,12 @@
#include <glob.h>
#include <wordexp.h>
+extern void __wordfree (wordexp_t *__wordexp) __THROW attribute_hidden;
+extern int __glob (__const char *__restrict __pattern, int __flags,
+ int (*__errfunc) (__const char *, int),
+ glob_t *__restrict __pglob) __THROW attribute_hidden;
+extern void __globfree (glob_t *__pglob) __THROW attribute_hidden;
+
#define __WORDEXP_FULL
//#undef __WORDEXP_FULL
@@ -362,7 +367,7 @@ do_parse_glob(const char *glob_word, char **word, size_t * word_length,
int match;
glob_t globbuf;
- error = glob(glob_word, GLOB_NOCHECK, NULL, &globbuf);
+ error = __glob(glob_word, GLOB_NOCHECK, NULL, &globbuf);
if (error != 0) {
/* We can only run into memory problems. */
@@ -381,7 +386,7 @@ do_parse_glob(const char *glob_word, char **word, size_t * word_length,
globbuf.gl_pathv[match]);
}
- globfree(&globbuf);
+ __globfree(&globbuf);
return *word ? 0 : WRDE_NOSPACE;
}
@@ -395,12 +400,12 @@ do_parse_glob(const char *glob_word, char **word, size_t * word_length,
char *matching_word = __strdup(globbuf.gl_pathv[match]);
if (matching_word == NULL || w_addword(pwordexp, matching_word)) {
- globfree(&globbuf);
+ __globfree(&globbuf);
return WRDE_NOSPACE;
}
}
- globfree(&globbuf);
+ __globfree(&globbuf);
return 0;
}
@@ -483,7 +488,7 @@ parse_glob(char **word, size_t * word_length, size_t * max_length,
/* Now tidy up */
tidy_up:
- wordfree(&glob_list);
+ __wordfree(&glob_list);
return error;
}
@@ -2023,7 +2028,7 @@ parse_dquote(char **word, size_t * word_length, size_t * max_length,
* wordfree() is to be called after pwordexp is finished with.
*/
-void wordfree(wordexp_t * pwordexp)
+void attribute_hidden __wordfree(wordexp_t * pwordexp)
{
/* wordexp can set pwordexp to NULL */
@@ -2037,6 +2042,7 @@ void wordfree(wordexp_t * pwordexp)
pwordexp->we_wordv = NULL;
}
}
+strong_alias(__wordfree,wordfree)
/*
* wordexp()
@@ -2055,7 +2061,7 @@ int wordexp(const char *words, wordexp_t * we, int flags)
if (flags & WRDE_REUSE) {
/* Minimal implementation of WRDE_REUSE for now */
- wordfree(we);
+ __wordfree(we);
old_word.we_wordv = NULL;
}
@@ -2257,7 +2263,7 @@ int wordexp(const char *words, wordexp_t * we, int flags)
return WRDE_NOSPACE;
if ((flags & WRDE_APPEND) == 0)
- wordfree(we);
+ __wordfree(we);
*we = old_word;
return error;
diff --git a/libc/pwd_grp/lckpwdf.c b/libc/pwd_grp/lckpwdf.c
index 72f8e3c83..f99e9f026 100644
--- a/libc/pwd_grp/lckpwdf.c
+++ b/libc/pwd_grp/lckpwdf.c
@@ -73,7 +73,7 @@ int lckpwdf (void)
}
/* Make sure file gets correctly closed when process finished. */
- flags = fcntl (lock_fd, F_GETFD, 0);
+ flags = __fcntl (lock_fd, F_GETFD, 0);
if (flags == -1) {
/* Cannot get file flags. */
__close(lock_fd);
@@ -82,7 +82,7 @@ int lckpwdf (void)
return -1;
}
flags |= FD_CLOEXEC; /* Close on exit. */
- if (fcntl (lock_fd, F_SETFD, flags) < 0) {
+ if (__fcntl (lock_fd, F_SETFD, flags) < 0) {
/* Cannot set new flags. */
__close(lock_fd);
lock_fd = -1;
@@ -131,7 +131,7 @@ int lckpwdf (void)
__memset (&fl, '\0', sizeof (struct flock));
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
- result = fcntl (lock_fd, F_SETLKW, &fl);
+ result = __fcntl (lock_fd, F_SETLKW, &fl);
/* Clear alarm. */
alarm (0);
diff --git a/libc/pwd_grp/pwd_grp.c b/libc/pwd_grp/pwd_grp.c
index 82c99360a..0f7c564f0 100644
--- a/libc/pwd_grp/pwd_grp.c
+++ b/libc/pwd_grp/pwd_grp.c
@@ -21,6 +21,7 @@
#define setgroups __setgroups
#define strtoul __strtoul
#define rewind __rewind
+#define fgets_unlocked __fgets_unlocked
#define _GNU_SOURCE
#include <features.h>
@@ -51,6 +52,8 @@ extern int __getpwuid_r (__uid_t __uid,
char *__restrict __buffer, size_t __buflen,
struct passwd **__restrict __result) attribute_hidden;
+extern int __fputc_unlocked_internal(int c, FILE *stream) attribute_hidden;
+
/**********************************************************************/
/* Sizes for staticly allocated buffers. */
@@ -806,7 +809,7 @@ int putgrent(const struct group *__restrict p, FILE *__restrict f)
do {
if (!*m) {
- if (fputc_unlocked('\n', f) >= 0) {
+ if (__fputc_unlocked_internal('\n', f) >= 0) {
rv = 0;
}
break;
@@ -872,7 +875,7 @@ int putspent(const struct spwd *p, FILE *stream)
goto DO_UNLOCK;
}
- if (fputc_unlocked('\n', stream) > 0) {
+ if (__fputc_unlocked_internal('\n', stream) > 0) {
rv = 0;
}
diff --git a/libc/stdio/_READ.c b/libc/stdio/_READ.c
index 013ca0281..e27309c11 100644
--- a/libc/stdio/_READ.c
+++ b/libc/stdio/_READ.c
@@ -5,6 +5,8 @@
* Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
*/
+#define read __read
+
#include "_stdio.h"
/* Given a reading stream without its end-of-file indicator set and
diff --git a/libc/stdio/_WRITE.c b/libc/stdio/_WRITE.c
index 877d055f7..c2b0e7b5d 100644
--- a/libc/stdio/_WRITE.c
+++ b/libc/stdio/_WRITE.c
@@ -5,6 +5,8 @@
* Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
*/
+#define write __write
+
#include "_stdio.h"
/* Given a writing stream with no buffered output, write the
diff --git a/libc/stdio/_cs_funcs.c b/libc/stdio/_cs_funcs.c
index 3bec64c19..ef92048c0 100644
--- a/libc/stdio/_cs_funcs.c
+++ b/libc/stdio/_cs_funcs.c
@@ -30,9 +30,9 @@ int attribute_hidden _cs_seek(void *cookie, register __offmax_t *pos, int whence
__offmax_t res;
#ifdef __UCLIBC_HAS_LFS__
- res = lseek64(*((int *) cookie), *pos, whence);
+ res = __lseek64(*((int *) cookie), *pos, whence);
#else
- res = lseek(*((int *) cookie), *pos, whence);
+ res = __lseek(*((int *) cookie), *pos, whence);
#endif
return (res >= 0) ? ((*pos = res), 0) : ((int) res);
@@ -54,9 +54,9 @@ int attribute_hidden __stdio_seek(FILE *stream, register __offmax_t *pos, int wh
__offmax_t res;
#ifdef __UCLIBC_HAS_LFS__
- res = lseek64(stream->__filedes, *pos, whence);
+ res = __lseek64(stream->__filedes, *pos, whence);
#else
- res = lseek(stream->__filedes, *pos, whence);
+ res = __lseek(stream->__filedes, *pos, whence);
#endif
return (res >= 0) ? ((*pos = res), 0) : ((int) res);
diff --git a/libc/stdio/_fopen.c b/libc/stdio/_fopen.c
index 6c2ef81f3..33b7b89ad 100644
--- a/libc/stdio/_fopen.c
+++ b/libc/stdio/_fopen.c
@@ -125,7 +125,7 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
/* NOTE: fopencookie needs changing if the basic check changes! */
if (((i & (((int) fname_or_mode) + 1)) != i) /* Basic agreement? */
|| (((open_mode & ~((__mode_t) fname_or_mode)) & O_APPEND)
- && fcntl(filedes, F_SETFL, O_APPEND)) /* Need O_APPEND. */
+ && __fcntl(filedes, F_SETFL, O_APPEND)) /* Need O_APPEND. */
) {
goto DO_EINVAL;
}
diff --git a/libc/stdio/_stdio.c b/libc/stdio/_stdio.c
index d0c221361..e8d90a800 100644
--- a/libc/stdio/_stdio.c
+++ b/libc/stdio/_stdio.c
@@ -188,7 +188,7 @@ void attribute_hidden __stdio_init_mutex(pthread_mutex_t *m)
/**********************************************************************/
/* We assume here that we are the only remaining thread. */
-void _stdio_term(void)
+void attribute_hidden _stdio_term(void)
{
#if defined(__STDIO_BUFFERS) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
register FILE *ptr;
@@ -258,7 +258,7 @@ void _stdio_term(void)
#endif
}
-void _stdio_init(void)
+void attribute_hidden _stdio_init(void)
{
#ifdef __STDIO_BUFFERS
int old_errno = errno;
diff --git a/libc/stdio/_stdio.h b/libc/stdio/_stdio.h
index 4d45a5448..50229ffb0 100644
--- a/libc/stdio/_stdio.h
+++ b/libc/stdio/_stdio.h
@@ -411,6 +411,7 @@ extern int __feof_unlocked(FILE *stream);
extern int __ferror_unlocked(FILE *stream);
extern int __fgetc_unlocked_internal(FILE *stream) attribute_hidden;
+extern int __getc_unlocked(FILE *stream) attribute_hidden;
extern char *__fgets_unlocked(char *__restrict s, int n,
FILE * __restrict stream) attribute_hidden;
diff --git a/libc/stdio/_trans2w.c b/libc/stdio/_trans2w.c
index e85f45a24..650a5e1a0 100644
--- a/libc/stdio/_trans2w.c
+++ b/libc/stdio/_trans2w.c
@@ -64,7 +64,7 @@ int attribute_hidden __stdio_trans2w(FILE * __restrict stream)
* the end even if not reading.*/
if (((__STDIO_STREAM_BUFFER_RAVAIL(stream))
|| (stream->__modeflags & __FLAG_UNGOT))
- && fseek(stream, 0L,
+ && __fseek(stream, 0L,
((stream->__modeflags & __FLAG_APPEND)
? SEEK_END : SEEK_CUR))
) {
diff --git a/libc/stdio/clearerr.c b/libc/stdio/clearerr.c
index 2772bed3c..cf1e623c7 100644
--- a/libc/stdio/clearerr.c
+++ b/libc/stdio/clearerr.c
@@ -16,9 +16,9 @@ void __clearerr_unlocked(register FILE *stream)
__CLEARERR_UNLOCKED(stream);
}
-weak_alias(__clearerr_unlocked,clearerr_unlocked);
+weak_alias(__clearerr_unlocked,clearerr_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__clearerr_unlocked,clearerr);
+weak_alias(__clearerr_unlocked,clearerr)
#endif
#elif defined __UCLIBC_HAS_THREADS__
diff --git a/libc/stdio/fclose.c b/libc/stdio/fclose.c
index 4f5e479fe..e019ad53e 100644
--- a/libc/stdio/fclose.c
+++ b/libc/stdio/fclose.c
@@ -5,6 +5,8 @@
* Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
*/
+#define close __close
+
#include "_stdio.h"
#undef fclose
diff --git a/libc/stdio/fdopen.c b/libc/stdio/fdopen.c
index 9b08b4b71..bca7f23fb 100644
--- a/libc/stdio/fdopen.c
+++ b/libc/stdio/fdopen.c
@@ -11,7 +11,7 @@ FILE attribute_hidden *__fdopen(int filedes, const char *mode)
{
intptr_t cur_mode;
- return (((cur_mode = fcntl(filedes, F_GETFL))) != -1)
+ return (((cur_mode = __fcntl(filedes, F_GETFL))) != -1)
? _stdio_fopen(cur_mode, mode, NULL, filedes)
: NULL;
}
diff --git a/libc/stdio/feof.c b/libc/stdio/feof.c
index 907872f7f..b0528d5ae 100644
--- a/libc/stdio/feof.c
+++ b/libc/stdio/feof.c
@@ -16,9 +16,9 @@ int __feof_unlocked(register FILE *stream)
return __FEOF_UNLOCKED(stream);
}
-weak_alias(__feof_unlocked,feof_unlocked);
+weak_alias(__feof_unlocked,feof_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__feof_unlocked,feof);
+weak_alias(__feof_unlocked,feof)
#endif
#elif defined __UCLIBC_HAS_THREADS__
diff --git a/libc/stdio/ferror.c b/libc/stdio/ferror.c
index 95014d3b0..e8d19bfa4 100644
--- a/libc/stdio/ferror.c
+++ b/libc/stdio/ferror.c
@@ -16,9 +16,9 @@ int __ferror_unlocked(register FILE *stream)
return __FERROR_UNLOCKED(stream);
}
-weak_alias(__ferror_unlocked,ferror_unlocked);
+weak_alias(__ferror_unlocked,ferror_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__ferror_unlocked,ferror);
+weak_alias(__ferror_unlocked,ferror)
#endif
#elif defined __UCLIBC_HAS_THREADS__
diff --git a/libc/stdio/fflush.c b/libc/stdio/fflush.c
index b4226d0f1..0a74afe3f 100644
--- a/libc/stdio/fflush.c
+++ b/libc/stdio/fflush.c
@@ -126,14 +126,15 @@ int attribute_hidden __fflush_unlocked(register FILE *stream)
#endif /* __STDIO_BUFFERS */
}
-weak_alias(__fflush_unlocked,fflush_unlocked);
+weak_alias(__fflush_unlocked,fflush_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__fflush_unlocked,fflush);
+hidden_strong_alias(__fflush_unlocked,__fflush)
+weak_alias(__fflush_unlocked,fflush)
#endif
#elif defined __UCLIBC_HAS_THREADS__
-int fflush(register FILE *stream)
+int attribute_hidden __fflush(register FILE *stream)
{
int retval;
__STDIO_AUTO_THREADLOCK_VAR;
@@ -155,5 +156,6 @@ int fflush(register FILE *stream)
return retval;
}
+strong_alias(__fflush,fflush)
#endif
diff --git a/libc/stdio/fgetc.c b/libc/stdio/fgetc.c
index be9322714..d83b6c92a 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/stdio/fgetc.c
@@ -71,15 +71,17 @@ int attribute_hidden __fgetc_unlocked_internal(FILE *stream)
strong_alias(__fgetc_unlocked_internal,__fgetc_unlocked)
weak_alias(__fgetc_unlocked_internal,fgetc_unlocked)
+hidden_strong_alias(__fgetc_unlocked_internal,__getc_unlocked)
weak_alias(__fgetc_unlocked_internal,getc_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
+hidden_strong_alias(__fgetc_unlocked_internal,__fgetc)
weak_alias(__fgetc_unlocked_internal,fgetc)
weak_alias(__fgetc_unlocked_internal,getc)
#endif
#elif defined __UCLIBC_HAS_THREADS__
-int fgetc(register FILE *stream)
+int attribute_hidden __fgetc(register FILE *stream)
{
if (stream->__user_locking != 0) {
return __GETC_UNLOCKED_MACRO(stream);
@@ -91,7 +93,7 @@ int fgetc(register FILE *stream)
return retval;
}
}
-
-weak_alias(fgetc,getc);
+strong_alias(__fgetc,fgetc)
+weak_alias(__fgetc,getc)
#endif
diff --git a/libc/stdio/fgets.c b/libc/stdio/fgets.c
index 52c856f35..5baf63a58 100644
--- a/libc/stdio/fgets.c
+++ b/libc/stdio/fgets.c
@@ -58,15 +58,16 @@ char attribute_hidden *__fgets_unlocked(char *__restrict s, int n,
return NULL;
}
-weak_alias(__fgets_unlocked,fgets_unlocked);
+weak_alias(__fgets_unlocked,fgets_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__fgets_unlocked,fgets);
+hidden_strong_alias(__fgets_unlocked,__fgets)
+weak_alias(__fgets_unlocked,fgets)
#endif
#elif defined __UCLIBC_HAS_THREADS__
-char *fgets(char *__restrict s, int n,
+char attribute_hidden *__fgets(char *__restrict s, int n,
register FILE * __restrict stream)
{
char *retval;
@@ -80,5 +81,6 @@ char *fgets(char *__restrict s, int n,
return retval;
}
+strong_alias(__fgets,fgets)
#endif
diff --git a/libc/stdio/fgetwc.c b/libc/stdio/fgetwc.c
index cb200851b..45ff86b80 100644
--- a/libc/stdio/fgetwc.c
+++ b/libc/stdio/fgetwc.c
@@ -108,16 +108,17 @@ wint_t attribute_hidden __fgetwc_unlocked(register FILE *stream)
return wi;
}
-weak_alias(__fgetwc_unlocked,fgetwc_unlocked);
-weak_alias(__fgetwc_unlocked,getwc_unlocked);
+weak_alias(__fgetwc_unlocked,fgetwc_unlocked)
+weak_alias(__fgetwc_unlocked,getwc_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__fgetwc_unlocked,fgetwc);
-weak_alias(__fgetwc_unlocked,getwc);
+hidden_strong_alias(__fgetwc_unlocked,__fgetwc)
+weak_alias(__fgetwc_unlocked,fgetwc)
+weak_alias(__fgetwc_unlocked,getwc)
#endif
#elif defined __UCLIBC_HAS_THREADS__
-wint_t fgetwc(register FILE *stream)
+wint_t attribute_hidden __fgetwc(register FILE *stream)
{
wint_t retval;
__STDIO_AUTO_THREADLOCK_VAR;
@@ -130,7 +131,7 @@ wint_t fgetwc(register FILE *stream)
return retval;
}
-
-weak_alias(fgetwc,getwc);
+strong_alias(__fgetwc,fgetwc)
+weak_alias(__fgetwc,getwc)
#endif
diff --git a/libc/stdio/fgetws.c b/libc/stdio/fgetws.c
index e31ea3c41..fe8da002d 100644
--- a/libc/stdio/fgetws.c
+++ b/libc/stdio/fgetws.c
@@ -37,9 +37,9 @@ wchar_t attribute_hidden *__fgetws_unlocked(wchar_t *__restrict ws, int n,
return ws;
}
-weak_alias(__fgetws_unlocked,fgetws_unlocked);
+weak_alias(__fgetws_unlocked,fgetws_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__fgetws_unlocked,fgetws);
+weak_alias(__fgetws_unlocked,fgetws)
#endif
#elif defined __UCLIBC_HAS_THREADS__
diff --git a/libc/stdio/fileno.c b/libc/stdio/fileno.c
index 526a4eb9f..bc1ade952 100644
--- a/libc/stdio/fileno.c
+++ b/libc/stdio/fileno.c
@@ -21,10 +21,10 @@ int attribute_hidden __fileno_unlocked(register FILE *stream)
return -1;
}
-weak_alias(__fileno_unlocked,fileno_unlocked);
+weak_alias(__fileno_unlocked,fileno_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-hidden_weak_alias(__fileno_unlocked,__fileno);
-weak_alias(__fileno_unlocked,fileno);
+hidden_weak_alias(__fileno_unlocked,__fileno)
+weak_alias(__fileno_unlocked,fileno)
#endif
#elif defined __UCLIBC_HAS_THREADS__
diff --git a/libc/stdio/fopen.c b/libc/stdio/fopen.c
index 244304acf..ad5d1aa92 100644
--- a/libc/stdio/fopen.c
+++ b/libc/stdio/fopen.c
@@ -9,9 +9,15 @@
#ifndef __DO_LARGEFILE
# define FILEDES_ARG (-1)
+#undef __fopen
+#undef fopen
+#else
+#undef __fopen64
+#undef fopen64
#endif
-FILE *fopen(const char * __restrict filename, const char * __restrict mode)
+FILE attribute_hidden *__fopen(const char * __restrict filename, const char * __restrict mode)
{
return _stdio_fopen(((intptr_t) filename), mode, NULL, FILEDES_ARG);
}
+strong_alias(__fopen,fopen)
diff --git a/libc/stdio/fopen64.c b/libc/stdio/fopen64.c
index 64ba30501..c65e9a4e9 100644
--- a/libc/stdio/fopen64.c
+++ b/libc/stdio/fopen64.c
@@ -8,6 +8,8 @@
#include "_stdio.h"
#define __DO_LARGEFILE
+#define __fopen __fopen64
+#undef fopen
#define fopen fopen64
#define FILEDES_ARG (-2)
#include "fopen.c"
diff --git a/libc/stdio/fputc.c b/libc/stdio/fputc.c
index b319263a1..4cc396e08 100644
--- a/libc/stdio/fputc.c
+++ b/libc/stdio/fputc.c
@@ -73,13 +73,15 @@ strong_alias(__fputc_unlocked_internal,__fputc_unlocked)
weak_alias(__fputc_unlocked_internal,fputc_unlocked)
weak_alias(__fputc_unlocked_internal,putc_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
+hidden_strong_alias(__fputc_unlocked_internal,__fputc)
weak_alias(__fputc_unlocked_internal,fputc)
+hidden_strong_alias(__fputc_unlocked_internal,__putc)
weak_alias(__fputc_unlocked_internal,putc)
#endif
#elif defined __UCLIBC_HAS_THREADS__
-int fputc(int c, register FILE *stream)
+int attribute_hidden __fputc(int c, register FILE *stream)
{
if (stream->__user_locking != 0) {
return __PUTC_UNLOCKED_MACRO(c, stream);
@@ -91,7 +93,8 @@ int fputc(int c, register FILE *stream)
return retval;
}
}
-
-weak_alias(fputc,putc)
+strong_alias(__fputc,fputc)
+hidden_strong_alias(__fputc,__putc)
+weak_alias(__fputc,putc)
#endif
diff --git a/libc/stdio/fputs.c b/libc/stdio/fputs.c
index 211fc1018..64e7fd57f 100644
--- a/libc/stdio/fputs.c
+++ b/libc/stdio/fputs.c
@@ -22,14 +22,15 @@ int attribute_hidden __fputs_unlocked(register const char * __restrict s,
return ((__fwrite_unlocked(s, 1, n, stream) == n) ? n : EOF);
}
-weak_alias(__fputs_unlocked,fputs_unlocked);
+weak_alias(__fputs_unlocked,fputs_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__fputs_unlocked,fputs);
+hidden_strong_alias(__fputs_unlocked,__fputs)
+weak_alias(__fputs_unlocked,fputs)
#endif
#elif defined __UCLIBC_HAS_THREADS__
-int fputs(const char * __restrict s, register FILE * __restrict stream)
+int attribute_hidden __fputs(const char * __restrict s, register FILE * __restrict stream)
{
int retval;
__STDIO_AUTO_THREADLOCK_VAR;
@@ -42,5 +43,6 @@ int fputs(const char * __restrict s, register FILE * __restrict stream)
return retval;
}
+strong_alias(__fputs,fputs)
#endif
diff --git a/libc/stdio/fputwc.c b/libc/stdio/fputwc.c
index dbea948dc..8f1178710 100644
--- a/libc/stdio/fputwc.c
+++ b/libc/stdio/fputwc.c
@@ -14,11 +14,11 @@ wint_t attribute_hidden __fputwc_unlocked(wchar_t wc, FILE *stream)
return _wstdio_fwrite(&wc, 1, stream) ? wc : WEOF;
}
-weak_alias(__fputwc_unlocked,fputwc_unlocked);
-weak_alias(__fputwc_unlocked,putwc_unlocked);
+weak_alias(__fputwc_unlocked,fputwc_unlocked)
+weak_alias(__fputwc_unlocked,putwc_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__fputwc_unlocked,fputwc);
-weak_alias(__fputwc_unlocked,putwc);
+weak_alias(__fputwc_unlocked,fputwc)
+weak_alias(__fputwc_unlocked,putwc)
#endif
#elif defined __UCLIBC_HAS_THREADS__
@@ -37,6 +37,6 @@ wint_t fputwc(wchar_t wc, register FILE *stream)
return retval;
}
-weak_alias(fputwc,putwc);
+weak_alias(fputwc,putwc)
#endif
diff --git a/libc/stdio/fputws.c b/libc/stdio/fputws.c
index e83cc9fcb..74919d6ea 100644
--- a/libc/stdio/fputws.c
+++ b/libc/stdio/fputws.c
@@ -9,9 +9,6 @@
#include "_stdio.h"
-extern int __fputws_unlocked(const wchar_t *__restrict ws,
- FILE *__restrict stream) attribute_hidden;
-
#ifdef __DO_UNLOCKED
int attribute_hidden __fputws_unlocked(const wchar_t *__restrict ws,
@@ -24,12 +21,16 @@ int attribute_hidden __fputws_unlocked(const wchar_t *__restrict ws,
weak_alias(__fputws_unlocked,fputws_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
+hidden_strong_alias(__fputws_unlocked,__fputws)
weak_alias(__fputws_unlocked,fputws)
#endif
#elif defined __UCLIBC_HAS_THREADS__
-int fputws(const wchar_t *__restrict ws, register FILE *__restrict stream)
+extern int __fputws_unlocked(const wchar_t *__restrict ws,
+ FILE *__restrict stream) attribute_hidden;
+
+int attribute_hidden __fputws(const wchar_t *__restrict ws, register FILE *__restrict stream)
{
int retval;
__STDIO_AUTO_THREADLOCK_VAR;
@@ -42,5 +43,6 @@ int fputws(const wchar_t *__restrict ws, register FILE *__restrict stream)
return retval;
}
+strong_alias(__fputws,fputws)
#endif
diff --git a/libc/stdio/fseeko.c b/libc/stdio/fseeko.c
index c795356e7..190485775 100644
--- a/libc/stdio/fseeko.c
+++ b/libc/stdio/fseeko.c
@@ -74,8 +74,8 @@ int attribute_hidden FSEEK(register FILE *stream, OFFSET_TYPE offset, int whence
}
#ifdef __DO_LARGEFILE
-weak_alias(__fseeko64,fseeko64)
+strong_alias(__fseeko64,fseeko64)
#else
-weak_alias(__fseek,fseek)
-weak_alias(fseek,fseeko)
+strong_alias(__fseek,fseek)
+weak_alias(__fseek,fseeko)
#endif
diff --git a/libc/stdio/fsetpos.c b/libc/stdio/fsetpos.c
index 2b02f25e0..f33043f3b 100644
--- a/libc/stdio/fsetpos.c
+++ b/libc/stdio/fsetpos.c
@@ -7,6 +7,10 @@
#include "_stdio.h"
+#ifndef __DO_LARGEFILE
+#define FSEEK __fseek
+#endif
+
int fsetpos(FILE *stream, register const fpos_t *pos)
{
#ifdef __STDIO_MBSTATE
@@ -16,7 +20,7 @@ int fsetpos(FILE *stream, register const fpos_t *pos)
__STDIO_AUTO_THREADLOCK(stream);
- if ((retval = fseek(stream, pos->__pos, SEEK_SET)) == 0) {
+ if ((retval = FSEEK(stream, pos->__pos, SEEK_SET)) == 0) {
__COPY_MBSTATE(&(stream->__state), &(pos->__mbstate));
stream->__ungot_width[0]= pos->__mblen_pending;
}
@@ -27,7 +31,7 @@ int fsetpos(FILE *stream, register const fpos_t *pos)
#else
- return fseek(stream, pos->__pos, SEEK_SET);
+ return FSEEK(stream, pos->__pos, SEEK_SET);
#endif
}
diff --git a/libc/stdio/fsetpos64.c b/libc/stdio/fsetpos64.c
index 92906e302..bf7d574cb 100644
--- a/libc/stdio/fsetpos64.c
+++ b/libc/stdio/fsetpos64.c
@@ -10,5 +10,5 @@
#define __DO_LARGEFILE
#define fsetpos fsetpos64
#define fpos_t fpos64_t
-#define fseek fseeko64
+#define FSEEK __fseeko64
#include "fsetpos.c"
diff --git a/libc/stdio/getchar.c b/libc/stdio/getchar.c
index ec578919b..d17704056 100644
--- a/libc/stdio/getchar.c
+++ b/libc/stdio/getchar.c
@@ -19,9 +19,9 @@ int attribute_hidden __getchar_unlocked(void)
return __GETC_UNLOCKED_MACRO(stream);
}
-weak_alias(__getchar_unlocked,getchar_unlocked);
+weak_alias(__getchar_unlocked,getchar_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__getchar_unlocked,getchar);
+weak_alias(__getchar_unlocked,getchar)
#endif
#elif defined __UCLIBC_HAS_THREADS__
diff --git a/libc/stdio/getwchar.c b/libc/stdio/getwchar.c
index 642162fed..90e5a032e 100644
--- a/libc/stdio/getwchar.c
+++ b/libc/stdio/getwchar.c
@@ -14,16 +14,18 @@ wint_t __getwchar_unlocked(void)
return __fgetwc_unlocked(stdin);
}
-weak_alias(__getwchar_unlocked,getwchar_unlocked);
+weak_alias(__getwchar_unlocked,getwchar_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__getwchar_unlocked,getwchar);
+weak_alias(__getwchar_unlocked,getwchar)
#endif
#elif defined __UCLIBC_HAS_THREADS__
+extern wint_t __fgetwc (__FILE *__stream) attribute_hidden;
+
wint_t getwchar(void)
{
- return fgetwc(stdin);
+ return __fgetwc(stdin);
}
#endif
diff --git a/libc/stdio/old_vfprintf.c b/libc/stdio/old_vfprintf.c
index 8b54ca849..ce6bde1a4 100644
--- a/libc/stdio/old_vfprintf.c
+++ b/libc/stdio/old_vfprintf.c
@@ -166,7 +166,7 @@
#ifdef __STDIO_BUFFERS
-#define PUTC(C,F) putc_unlocked((C),(F))
+#define PUTC(C,F) __putc_unlocked((C),(F))
#define OUTNSTR _outnstr
#define _outnstr(stream, string, len) __stdio_fwrite(string, len, stream)
@@ -199,7 +199,7 @@ static void _outnstr(FILE *stream, const unsigned char *s, size_t n)
static void putc_unlocked_sprintf(int c, __FILE_vsnprintf *f)
{
if (!__STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(&f->f)) {
- putc_unlocked(c, &f->f);
+ __putc_unlocked(c, &f->f);
} else if (f->bufpos < f->bufend) {
*f->bufpos++ = c;
}
diff --git a/libc/stdio/popen.c b/libc/stdio/popen.c
index c3ee09381..f84a27a3c 100644
--- a/libc/stdio/popen.c
+++ b/libc/stdio/popen.c
@@ -19,6 +19,8 @@
#define dup2 __dup2
#define fdopen __fdopen
#define pipe __pipe
+#define vfork __vfork
+#define fork __fork
#include <stdio.h>
#include <stdlib.h>
@@ -109,7 +111,7 @@ FILE *popen(const char *command, const char *modes)
/* SUSv3 mandates an exit code of 127 for the child if the
* command interpreter can not be invoked. */
- _exit(127);
+ _exit_internal(127);
}
VFORK_UNLOCK;
diff --git a/libc/stdio/putchar.c b/libc/stdio/putchar.c
index fa6d6c372..e503b9484 100644
--- a/libc/stdio/putchar.c
+++ b/libc/stdio/putchar.c
@@ -19,9 +19,9 @@ int __putchar_unlocked(int c)
return __PUTC_UNLOCKED_MACRO(c, stream);
}
-weak_alias(__putchar_unlocked,putchar_unlocked);
+weak_alias(__putchar_unlocked,putchar_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__putchar_unlocked,putchar);
+weak_alias(__putchar_unlocked,putchar)
#endif
#elif defined __UCLIBC_HAS_THREADS__
diff --git a/libc/stdio/putwchar.c b/libc/stdio/putwchar.c
index 47bc173e1..d093656e6 100644
--- a/libc/stdio/putwchar.c
+++ b/libc/stdio/putwchar.c
@@ -14,16 +14,18 @@ wint_t __putwchar_unlocked(wchar_t wc)
return __fputwc_unlocked(wc, stdout);
}
-weak_alias(__putwchar_unlocked,putwchar_unlocked);
+weak_alias(__putwchar_unlocked,putwchar_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
-weak_alias(__putwchar_unlocked,putwchar);
+weak_alias(__putwchar_unlocked,putwchar)
#endif
#elif defined __UCLIBC_HAS_THREADS__
+extern int __fputc (int __c, FILE *__stream) attribute_hidden;
+
wint_t putwchar(wchar_t wc)
{
- return fputc(wc, stdout);
+ return __fputc(wc, stdout);
}
#endif
diff --git a/libc/stdio/remove.c b/libc/stdio/remove.c
index d471ae291..2d4fedcc1 100644
--- a/libc/stdio/remove.c
+++ b/libc/stdio/remove.c
@@ -19,7 +19,7 @@
* equivalent to rmdir(path).
*/
-int remove(register const char *filename)
+int attribute_hidden __remove(register const char *filename)
{
int saved_errno = errno;
int rv;
@@ -30,3 +30,4 @@ int remove(register const char *filename)
}
return rv;
}
+strong_alias(__remove,remove)
diff --git a/libc/stdio/rewind.c b/libc/stdio/rewind.c
index aa4534aa7..8e0acc2d0 100644
--- a/libc/stdio/rewind.c
+++ b/libc/stdio/rewind.c
@@ -14,7 +14,7 @@ void attribute_hidden __rewind(register FILE *stream)
__STDIO_AUTO_THREADLOCK(stream);
__STDIO_STREAM_CLEAR_ERROR(stream); /* Clear the error indicator */
- fseek(stream, 0L, SEEK_SET); /* first since fseek could set it. */
+ __fseek(stream, 0L, SEEK_SET); /* first since fseek could set it. */
__STDIO_AUTO_THREADUNLOCK(stream);
}
diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c
index 3132026bb..ddc2bd75f 100644
--- a/libc/stdio/scanf.c
+++ b/libc/stdio/scanf.c
@@ -607,7 +607,7 @@ typedef unsigned char __uchar_t;
#ifdef __UCLIBC_HAS_WCHAR__
#define GETC(SC) (SC)->sc_getc((SC))
#else /* __UCLIBC_HAS_WCHAR__ */
-#define GETC(SC) getc_unlocked((SC)->fp)
+#define GETC(SC) __getc_unlocked((SC)->fp)
#endif /* __UCLIBC_HAS_WCHAR__ */
#endif
@@ -971,7 +971,7 @@ int attribute_hidden __psfs_parse_spec(register psfs_t *psfs)
#ifdef L_vfscanf
static int sc_getc(register struct scan_cookie *sc)
{
- return (getc_unlocked)(sc->fp); /* Disable the macro. */
+ return (__getc_unlocked)(sc->fp); /* Disable the macro. */
}
static int scan_getwc(register struct scan_cookie *sc)
diff --git a/libc/stdio/tmpfile.c b/libc/stdio/tmpfile.c
index fa9bd5019..606fcc436 100644
--- a/libc/stdio/tmpfile.c
+++ b/libc/stdio/tmpfile.c
@@ -17,6 +17,7 @@
Boston, MA 02111-1307, USA. */
#define fdopen __fdopen
+#define remove __remove
#include <features.h>
#include <stdio.h>
@@ -49,5 +50,5 @@ FILE * tmpfile (void)
return f;
}
#ifdef __UCLIBC_HAS_LFS__
-weak_alias(tmpfile, tmpfile64);
+weak_alias(tmpfile,tmpfile64)
#endif
diff --git a/libc/stdio/vfprintf.c b/libc/stdio/vfprintf.c
index 11fe926a0..bdbf0c788 100644
--- a/libc/stdio/vfprintf.c
+++ b/libc/stdio/vfprintf.c
@@ -95,6 +95,7 @@
#define mbsrtowcs __mbsrtowcs
#define btowc __btowc
#define wcrtomb __wcrtomb
+#define fputws __fputws
#define _ISOC99_SOURCE /* for ULLONG primarily... */
#define _GNU_SOURCE
diff --git a/libc/stdlib/abort.c b/libc/stdlib/abort.c
index d24d1a94c..47252d1f7 100644
--- a/libc/stdlib/abort.c
+++ b/libc/stdlib/abort.c
@@ -64,13 +64,12 @@ Cambridge, MA 02139, USA. */
#define ABORT_INSTRUCTION asm ("hlt")
#else
#define ABORT_INSTRUCTION
-#warning no abort instruction define for your arch
+#warning no abort instruction defined for your arch
#endif
#ifdef __UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT__
-extern void weak_function _stdio_term(void);
+extern void weak_function _stdio_term(void) attribute_hidden;
#endif
-extern void _exit __P((int __status)) __attribute__ ((__noreturn__));
static int been_there_done_that = 0;
/* Be prepared in case multiple threads try to abort() */
@@ -81,10 +80,12 @@ static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
#define LOCK __pthread_mutex_lock(&mylock)
#define UNLOCK __pthread_mutex_unlock(&mylock)
-
extern int __raise (int __sig) __THROW attribute_hidden;
+
/* Cause an abnormal program termination with core-dump */
-void abort(void)
+#undef __abort
+#undef abort
+void attribute_hidden __abort(void)
{
sigset_t sigset;
@@ -140,7 +141,7 @@ abort_it:
/* Still here? Try to at least exit */
if (been_there_done_that == 3) {
been_there_done_that++;
- _exit(127);
+ _exit_internal(127);
}
/* Still here? We're screwed. Sleepy time. Good night. */
@@ -149,3 +150,4 @@ abort_it:
ABORT_INSTRUCTION;
}
}
+strong_alias(__abort,abort)
diff --git a/libc/stdlib/atexit.c b/libc/stdlib/atexit.c
index fcf85391a..f6944edc5 100644
--- a/libc/stdlib/atexit.c
+++ b/libc/stdlib/atexit.c
@@ -121,7 +121,7 @@ int old_atexit(aefuncp func)
&__dso_handle == NULL ? NULL : __dso_handle);
}
#ifndef L_atexit
-weak_alias(old_atexit,atexit);
+weak_alias(old_atexit,atexit)
#endif
#endif
@@ -305,7 +305,7 @@ void __exit_handler(int status)
#endif
#ifdef L_exit
-extern void weak_function _stdio_term(void);
+extern void weak_function _stdio_term(void) attribute_hidden;
void (*__exit_cleanup) (int) = 0;
#ifdef __UCLIBC_HAS_THREADS__
pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
@@ -320,7 +320,9 @@ extern void (*__rtld_fini)(void);
/*
* Normal program termination
*/
-void exit(int rv)
+#undef exit
+#undef __exit
+void attribute_hidden __exit(int rv)
{
/* Perform exit-specific cleanup (atexit and on_exit) */
LOCK;
@@ -343,6 +345,7 @@ void exit(int rv)
if (_stdio_term)
_stdio_term();
- _exit(rv);
+ _exit_internal(rv);
}
+strong_alias(__exit,exit)
#endif
diff --git a/libc/stdlib/ldiv.c b/libc/stdlib/ldiv.c
index c66470fb2..f8e789a92 100644
--- a/libc/stdlib/ldiv.c
+++ b/libc/stdlib/ldiv.c
@@ -57,6 +57,5 @@ ldiv (long int numer, long int denom)
#if __WORDSIZE == 64
#undef imaxdiv
-weak_alias (ldiv, imaxdiv);
+weak_alias (ldiv, imaxdiv)
#endif
-
diff --git a/libc/stdlib/lldiv.c b/libc/stdlib/lldiv.c
index 2b382db6c..56ccb2612 100644
--- a/libc/stdlib/lldiv.c
+++ b/libc/stdlib/lldiv.c
@@ -58,6 +58,5 @@ lldiv (long long int numer, long long int denom)
#if __WORDSIZE != 64
#undef imaxdiv
-weak_alias (lldiv, imaxdiv);
+weak_alias (lldiv, imaxdiv)
#endif
-
diff --git a/libc/stdlib/malloc-standard/free.c b/libc/stdlib/malloc-standard/free.c
index aa8edec97..1b294d706 100644
--- a/libc/stdlib/malloc-standard/free.c
+++ b/libc/stdlib/malloc-standard/free.c
@@ -169,7 +169,7 @@ static void malloc_init_state(mstate av)
malloc anyway, it turns out to be the perfect place to trigger
initialization code.
*/
-void __malloc_consolidate(mstate av)
+void attribute_hidden __malloc_consolidate(mstate av)
{
mfastbinptr* fb; /* current fastbin being consolidated */
mfastbinptr* maxfb; /* last fastbin (for loop control) */
diff --git a/libc/stdlib/malloc-standard/mallinfo.c b/libc/stdlib/malloc-standard/mallinfo.c
index f6c2a9104..029ceda1f 100644
--- a/libc/stdlib/malloc-standard/mallinfo.c
+++ b/libc/stdlib/malloc-standard/mallinfo.c
@@ -22,7 +22,7 @@ struct mallinfo attribute_hidden __mallinfo(void)
{
mstate av;
struct mallinfo mi;
- int i;
+ unsigned int i;
mbinptr b;
mchunkptr p;
size_t avail;
diff --git a/libc/stdlib/malloc-standard/malloc.h b/libc/stdlib/malloc-standard/malloc.h
index 338edeabf..68d38cb3d 100644
--- a/libc/stdlib/malloc-standard/malloc.h
+++ b/libc/stdlib/malloc-standard/malloc.h
@@ -16,6 +16,7 @@
#define mmap __mmap
#define sysconf __sysconf
+#define sbrk __sbrk
#include <features.h>
#include <stddef.h>
@@ -929,7 +930,7 @@ extern struct malloc_state __malloc_state; /* never directly referenced */
#define get_malloc_state() (&(__malloc_state))
/* External internal utilities operating on mstates */
-void __malloc_consolidate(mstate);
+void __malloc_consolidate(mstate) attribute_hidden;
/* Debugging support */
diff --git a/libc/stdlib/malloc/Makefile.in b/libc/stdlib/malloc/Makefile.in
index cf61011a4..55831c379 100644
--- a/libc/stdlib/malloc/Makefile.in
+++ b/libc/stdlib/malloc/Makefile.in
@@ -37,4 +37,4 @@ stdlib_malloc_objclean:
malloc.o free.o realloc.o memalign.o: malloc.h
# Depend on uClinux_config.h to cache changes in __UCLIBC_MALLOC_DEBUGGING__
-$(STDLIB_MALLOC_OBJ): heap.h $(top_builddir)include/bits/uClibc_config.h
+$(STDLIB_MALLOC_OBJ): $(STDLIB_MALLOC_DIR)/heap.h $(top_builddir)include/bits/uClibc_config.h
diff --git a/libc/stdlib/malloc/free.c b/libc/stdlib/malloc/free.c
index eb35e78ee..81ec38cd9 100644
--- a/libc/stdlib/malloc/free.c
+++ b/libc/stdlib/malloc/free.c
@@ -12,6 +12,7 @@
*/
#define munmap __munmap
+#define sbrk __sbrk
#include <stdlib.h>
#include <unistd.h>
diff --git a/libc/stdlib/malloc/heap_debug.c b/libc/stdlib/malloc/heap_debug.c
index 4804ba9ee..7dab95627 100644
--- a/libc/stdlib/malloc/heap_debug.c
+++ b/libc/stdlib/malloc/heap_debug.c
@@ -80,13 +80,13 @@ __heap_check_failure (struct heap *heap, struct heap_free_area *fa,
vfprintf (stderr, fmt, val);
va_end (val);
- putc ('\n', stderr);
+ __putc ('\n', stderr);
__malloc_debug_set_indent (0);
__malloc_debug_printf (1, "heap dump:");
__heap_dump_freelist (heap);
- exit (22);
+ __exit (22);
}
/* Do some consistency checks on HEAP. If they fail, output an error
diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c
index 44eb2c66f..6bc8d8773 100644
--- a/libc/stdlib/malloc/malloc.c
+++ b/libc/stdlib/malloc/malloc.c
@@ -12,6 +12,7 @@
*/
#define mmap __mmap
+#define sbrk __sbrk
#include <stdlib.h>
#include <unistd.h>
diff --git a/libc/stdlib/malloc/malloc.h b/libc/stdlib/malloc/malloc.h
index 08ebfdf5b..707cad13d 100644
--- a/libc/stdlib/malloc/malloc.h
+++ b/libc/stdlib/malloc/malloc.h
@@ -79,6 +79,8 @@ extern struct heap __malloc_mmb_heap;
to stderr, when the variable __malloc_mmb_debug is set to true. */
#ifdef MALLOC_MMB_DEBUGGING
# include <stdio.h>
+extern int __putc(int c, FILE *stream) attribute_hidden;
+
extern int __malloc_mmb_debug;
# define MALLOC_MMB_DEBUG(indent, fmt, args...) \
(__malloc_mmb_debug ? __malloc_debug_printf (indent, fmt , ##args) : 0)
diff --git a/libc/stdlib/malloc/malloc_debug.c b/libc/stdlib/malloc/malloc_debug.c
index e8711ff77..abe5546ca 100644
--- a/libc/stdlib/malloc/malloc_debug.c
+++ b/libc/stdlib/malloc/malloc_debug.c
@@ -42,7 +42,7 @@ __malloc_debug_printf (int indent, const char *fmt, ...)
while (spaces > 0)
{
- putc (' ', stderr);
+ __putc (' ', stderr);
spaces--;
}
@@ -50,7 +50,7 @@ __malloc_debug_printf (int indent, const char *fmt, ...)
vfprintf (stderr, fmt, val);
va_end (val);
- putc ('\n', stderr);
+ __putc ('\n', stderr);
__malloc_debug_indent (indent);
}
diff --git a/libc/stdlib/ptsname.c b/libc/stdlib/ptsname.c
index c56f18a91..8e18e3989 100644
--- a/libc/stdlib/ptsname.c
+++ b/libc/stdlib/ptsname.c
@@ -136,7 +136,7 @@ int attribute_hidden __ptsname_r (int fd, char *buf, size_t buflen)
return ERANGE;
}
- if (fstat (fd, &st) < 0)
+ if (__fstat (fd, &st) < 0)
return errno;
/* Check if FD really is a master pseudo terminal. */
@@ -165,7 +165,7 @@ int attribute_hidden __ptsname_r (int fd, char *buf, size_t buflen)
p[2] = '\0';
}
- if (stat(buf, &st) < 0)
+ if (__stat(buf, &st) < 0)
return errno;
/* Check if the name we're about to return really corresponds to a
diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c
index 07af88465..413ebed9e 100644
--- a/libc/stdlib/setenv.c
+++ b/libc/stdlib/setenv.c
@@ -132,10 +132,11 @@ int attribute_hidden __add_to_environ (const char *name, const char *value,
return 0;
}
-int setenv (const char *name, const char *value, int replace)
+int attribute_hidden __setenv (const char *name, const char *value, int replace)
{
return __add_to_environ (name, value, NULL, replace);
}
+strong_alias(__setenv,setenv)
int attribute_hidden __unsetenv (const char *name)
{
diff --git a/libc/stdlib/stdlib.c b/libc/stdlib/stdlib.c
index 3b7d37ccb..8203881a4 100644
--- a/libc/stdlib/stdlib.c
+++ b/libc/stdlib/stdlib.c
@@ -724,7 +724,7 @@ unsigned long long attribute_hidden __XL_NPP(_stdlib_strto_ll)(register const Wc
/* void _Exit(int status) */
/* { */
-/* _exit(status); */
+/* _exit_internal(status); */
/* } */
/* #endif */
@@ -868,7 +868,7 @@ void ssort (void *base,
/**********************************************************************/
#ifdef L__stdlib_mb_cur_max
-size_t _stdlib_mb_cur_max(void)
+size_t attribute_hidden _stdlib_mb_cur_max_internal(void)
{
#ifdef __CTYPE_HAS_UTF_8_LOCALES
return __UCLIBC_CURLOCALE_DATA.mb_cur_max;
@@ -881,6 +881,7 @@ size_t _stdlib_mb_cur_max(void)
return 1;
#endif
}
+strong_alias(_stdlib_mb_cur_max_internal,_stdlib_mb_cur_max)
#endif
/**********************************************************************/
diff --git a/libc/stdlib/system.c b/libc/stdlib/system.c
index 616d2dda6..a537156fd 100644
--- a/libc/stdlib/system.c
+++ b/libc/stdlib/system.c
@@ -1,6 +1,8 @@
#define wait4 __wait4
#define execl __execl
#define signal __signal
+#define vfork __vfork
+#define fork __fork
#include <stdio.h>
#include <stddef.h>
@@ -38,7 +40,7 @@ int __libc_system(char *command)
signal(SIGCHLD, SIG_DFL);
execl("/bin/sh", "sh", "-c", command, (char *) 0);
- _exit(127);
+ _exit_internal(127);
}
/* Signals are not absolutly guarenteed with vfork */
signal(SIGQUIT, SIG_IGN);
diff --git a/libc/stdlib/unix_grantpt.c b/libc/stdlib/unix_grantpt.c
index e087d18c8..0e7d50a99 100644
--- a/libc/stdlib/unix_grantpt.c
+++ b/libc/stdlib/unix_grantpt.c
@@ -23,6 +23,9 @@
#define setrlimit __setrlimit
#define waitpid __waitpid
#define dup2 __dup2
+#define chmod __chmod
+#define vfork __vfork
+#define fork __fork
#include <assert.h>
#include <errno.h>
@@ -41,7 +44,7 @@
/* uClinux-2.0 has vfork, but Linux 2.0 doesn't */
#include <sys/syscall.h>
#if ! defined __NR_vfork
-#define vfork fork
+#define vfork fork
#endif
extern int __ptsname_r (int fd, char *buf, size_t buflen) attribute_hidden;
@@ -119,7 +122,7 @@ grantpt (int fd)
if (pts_name (fd, &buf, sizeof (_buf)))
return -1;
- if (stat(buf, &st) < 0)
+ if (__stat(buf, &st) < 0)
goto cleanup;
/* Make sure that we own the device. */
@@ -165,10 +168,10 @@ grantpt (int fd)
/* We pase the master pseudo terminal as file descriptor PTY_FILENO. */
if (fd != PTY_FILENO)
if (dup2 (fd, PTY_FILENO) < 0)
- _exit (FAIL_EBADF);
+ _exit_internal (FAIL_EBADF);
execle (_PATH_PT_CHOWN, _PATH_PT_CHOWN, NULL, NULL);
- _exit (FAIL_EXEC);
+ _exit_internal (FAIL_EXEC);
}
else
{
diff --git a/libc/string/Makefile.in b/libc/string/Makefile.in
index 0adcaee39..4f96b8354 100644
--- a/libc/string/Makefile.in
+++ b/libc/string/Makefile.in
@@ -9,112 +9,69 @@
-include $(top_srcdir)libc/string/$(TARGET_ARCH)/Makefile.arch
include $(top_srcdir)libc/string/generic/Makefile.in
-MSRC:=wstring.c
-MOBJ:= basename.o bcopy.o bzero.o dirname.o ffs.o memccpy.o \
- memrchr.o rawmemchr.o strcasecmp.o strcasestr.o \
- strncasecmp.o strndup.o strsep.o \
- strtok.o strerror.o __xpg_strerror_r.o \
- _string_syserrmsgs.o __glibc_strerror_r.o \
- _string_syssigmsgs.o sys_siglist.o strsignal.o psignal.o \
- __xpg_basename.o strlcat.o sys_errlist.o memmem.o
+STRING_DIR:=$(top_srcdir)libc/string
+STRING_OUT:=$(top_builddir)libc/string
-MOBJW:=
-ifeq ($(UCLIBC_HAS_WCHAR),y)
-MOBJW:= wcscasecmp.o wcsncasecmp.o \
- wcsxfrm.o strxfrm.o # wcscoll strcoll.o
+STRING_ALL_WXSRC:=$(wildcard $(STRING_DIR)/w*_l.c)
+ifeq ($(UCLIBC_HAS_LOCALE),y)
+STRING_WXSRC:=$(STRING_ALL_WXSRC)
+else
+# wcscoll_l
+STRING_WXSRC:=$(filter-out $(STRING_DIR)/wcsxfrm_l.c,$(STRING_ALL_WXSRC))
endif
-MOBJx:=
-MOBJWx:=
-ifeq ($(UCLIBC_HAS_XLOCALE),y)
-MOBJx:=strcasecmp_l.o strncasecmp_l.o
-ifeq ($(UCLIBC_HAS_WCHAR),y)
-MOBJWx:=wcscasecmp_l.o wcsncasecmp_l.o wcsxfrm_l.o strxfrm_l.o
+STRING_ALL_XLSRC:=$(filter-out $(STRING_ALL_WXSRC),$(wildcard $(STRING_DIR)/*_l.c))
+ifeq ($(UCLIBC_HAS_LOCALE),y)
+STRING_XLSRC:=$(STRING_ALL_XLSRC)
+else
+# strcoll_l
+STRING_XLSRC:=$(filter-out $(STRING_DIR)/strxfrm_l.c,$(STRING_ALL_XLSRC))
endif
-endif
-
-#ffsl ffsll
-ifeq ($(UCLIBC_HAS_STRING_ARCH_OPT),y)
-ifneq ($(strip $(STRING_ARCH_OBJS)),)
-MOBJ:=$(filter-out $(notdir $(STRING_ARCH_OBJS)),$(MOBJ))
+STRING_ALL_WSRC:=$(filter-out $(STRING_ALL_WXSRC),$(wildcard $(STRING_DIR)/w*.c))
+ifeq ($(UCLIBC_HAS_LOCALE),y)
+STRING_WSRC:=$(STRING_ALL_WSRC)
+else
+# wcscoll
+STRING_WSRC:=$(filter-out $(STRING_DIR)/wcsxfrm.c,$(STRING_ALL_WSRC))
endif
+
+STRING_ALL_CSRC:=$(filter-out $(STRING_ALL_WXSRC) $(STRING_ALL_XLSRC) $(STRING_ALL_WSRC) $(STRING_DIR)/_collate.c,$(wildcard $(STRING_DIR)/*.c))
+ifeq ($(UCLIBC_HAS_LOCALE),y)
+STRING_CSRC:=$(STRING_ALL_CSRC)
+else
+# strcoll
+STRING_CSRC:=$(filter-out $(STRING_DIR)/strxfrm.c,$(STRING_ALL_CSRC))
endif
-ifeq ($(UCLIBC_HAS_STRING_GENERIC_OPT),y)
-ifneq ($(strip $(STRING_GENERIC_OBJS)),)
-MOBJ:=$(filter-out $(notdir $(STRING_GENERIC_OBJS)),$(MOBJ))
+ifeq ($(UCLIBC_HAS_WCHAR),y)
+STRING_CSRC+=$(STRING_WSRC)
+endif
+ifeq ($(UCLIBC_HAS_XLOCALE),y)
+STRING_CSRC+=$(STRING_XLSRC)
+ifeq ($(UCLIBC_HAS_WCHAR),y)
+STRING_CSRC+=$(STRING_WXSRC)
endif
endif
-
-STRING_DIR:=$(top_srcdir)libc/string
-STRING_OUT:=$(top_builddir)libc/string
-
-STRING_WSRC:=$(filter-out $(STRING_DIR)/wstring.c,$(wildcard $(STRING_DIR)/w*.c))
-STRING_CSRC:=$(filter-out $(STRING_DIR)/wstring.c $(STRING_WSRC),$(wildcard $(STRING_DIR)/*.c))
ifeq ($(UCLIBC_HAS_STRING_ARCH_OPT),y)
ifneq ($(strip $(STRING_ARCH_OBJS)),)
-MOBJ:=$(filter-out $(notdir $(STRING_ARCH_OBJS)),$(MOBJ))
STRING_CSRC:=$(filter-out $(patsubst %.o,$(STRING_DIR)/%.c,$(notdir $(STRING_ARCH_OBJS))),$(STRING_CSRC))
-STRING_WSRC:=$(filter-out $(patsubst %.o,$(STRING_DIR)/%.c,$(notdir $(STRING_ARCH_OBJS))),$(STRING_WSRC))
endif
endif
ifeq ($(UCLIBC_HAS_STRING_GENERIC_OPT),y)
ifneq ($(strip $(STRING_GENERIC_OBJS)),)
-MOBJ:=$(filter-out $(notdir $(STRING_GENERIC_OBJS)),$(MOBJ))
STRING_CSRC:=$(filter-out $(patsubst %.o,$(STRING_DIR)/%.c,$(notdir $(STRING_GENERIC_OBJS))),$(STRING_CSRC))
-STRING_WSRC:=$(filter-out $(patsubst %.o,$(STRING_DIR)/%.c,$(notdir $(STRING_GENERIC_OBJS))),$(STRING_WSRC))
endif
endif
-
STRING_COBJ:=$(patsubst $(STRING_DIR)/%.c,$(STRING_OUT)/%.o,$(STRING_CSRC))
-ifeq ($(UCLIBC_HAS_WCHAR),y)
-STRING_WOBJ:=$(patsubst $(STRING_DIR)/%.c,$(STRING_OUT)/%.o,$(STRING_WSRC))
-endif
-STRING_MSRC:=$(patsubst %.c,$(STRING_DIR)/%.c,$(MSRC))
-STRING_MOBJ:=$(patsubst %.o,$(STRING_OUT)/%.o,$(MOBJ))
-STRING_MOBJW:=$(patsubst %.o,$(STRING_OUT)/%.o,$(MOBJW))
-STRING_MOBJx:=$(patsubst %.o,$(STRING_OUT)/%.o,$(MOBJx))
-STRING_MOBJWx:=$(patsubst %.o,$(STRING_OUT)/%.o,$(MOBJWx))
-
-STRING_DEF:=$(patsubst %,-DL_%,$(subst .o,,$(notdir $(STRING_MOBJ))))
-
-STRING_Wx:=$(STRING_MOBJW) $(STRING_MOBJx) $(STRING_MOBJWx)
-STRING_OBJS:=$(STRING_COBJ) $(STRING_WOBJ) $(STRING_MOBJ) $(STRING_Wx)
-
-$(STRING_MOBJ): $(STRING_MSRC)
- $(compile.m)
-
-$(STRING_MOBJ:.o=.os): $(STRING_MSRC)
- $(compile.m)
-
-$(STRING_MOBJW): $(STRING_MSRC)
- $(compile.m) -DWANT_WIDE
-
-$(STRING_MOBJW:.o=.os): $(STRING_MSRC)
- $(compile.m) -DWANT_WIDE
-
-$(STRING_MOBJx): $(STRING_MSRC)
- $(compile.m) -D__UCLIBC_DO_XLOCALE
-
-$(STRING_MOBJx:.o=.os): $(STRING_MSRC)
- $(compile.m) -D__UCLIBC_DO_XLOCALE
-
-$(STRING_MOBJWx): $(STRING_MSRC)
- $(compile.m) -DWANT_WIDE -D__UCLIBC_DO_XLOCALE
-
-$(STRING_MOBJWx:.o=.os): $(STRING_MSRC)
- $(compile.m) -DWANT_WIDE -D__UCLIBC_DO_XLOCALE
-libc-a-y+=$(STRING_OBJS)
-libc-so-y+=$(STRING_OBJS:.o=.os)
+libc-a-y+=$(STRING_COBJ)
+libc-so-y+=$(STRING_COBJ:.o=.os)
-CFLAGS-multi-y+=$(STRING_DEF)
-libc-multi-y+=$(STRING_MSRC) $(STRING_CSRC) $(STRING_WSRC)
-libc-nomulti-y+=$(STRING_Wx)
+libc-multi-y+=$(STRING_CSRC)
objclean-y+=string_objclean
diff --git a/libc/string/__glibc_strerror_r.c b/libc/string/__glibc_strerror_r.c
new file mode 100644
index 000000000..54955ec25
--- /dev/null
+++ b/libc/string/__glibc_strerror_r.c
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <features.h>
+#include <string.h>
+
+char attribute_hidden *__glibc_strerror_r_internal(int errnum, char *strerrbuf, size_t buflen)
+{
+ __xpg_strerror_r_internal(errnum, strerrbuf, buflen);
+
+ return strerrbuf;
+}
+
+strong_alias(__glibc_strerror_r_internal,__glibc_strerror_r)
+/*hidden_weak_alias(__glibc_strerror_r_internal,__strerror_r)*/
diff --git a/libc/string/__xpg_basename.c b/libc/string/__xpg_basename.c
new file mode 100644
index 000000000..6281f015c
--- /dev/null
+++ b/libc/string/__xpg_basename.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+
+char *__xpg_basename(register char *path)
+{
+ static const char null_or_empty[] = ".";
+ char *first;
+ register char *last;
+
+ first = (char *) null_or_empty;
+
+ if (path && *path) {
+ first = path;
+ last = path - 1;
+
+ do {
+ if ((*path != '/') && (path > ++last)) {
+ last = first = path;
+ }
+ } while (*++path);
+
+ if (*first == '/') {
+ last = first;
+ }
+ last[1] = 0;
+ }
+
+ return first;
+}
diff --git a/libc/string/__xpg_strerror_r.c b/libc/string/__xpg_strerror_r.c
new file mode 100644
index 000000000..93dffc732
--- /dev/null
+++ b/libc/string/__xpg_strerror_r.c
@@ -0,0 +1,273 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define _GNU_SOURCE
+#include <features.h>
+#include <errno.h>
+#include <bits/uClibc_uintmaxtostr.h>
+#include "_syserrmsg.h"
+
+#ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
+
+extern const char _string_syserrmsgs[];
+
+#if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
+
+static const unsigned char estridx[] = {
+ 0, /* success is always 0 */
+ EPERM,
+ ENOENT,
+ ESRCH,
+ EINTR,
+ EIO,
+ ENXIO,
+ E2BIG,
+ ENOEXEC,
+ EBADF,
+ ECHILD,
+ EAGAIN,
+ ENOMEM,
+ EACCES,
+ EFAULT,
+ ENOTBLK,
+ EBUSY,
+ EEXIST,
+ EXDEV,
+ ENODEV,
+ ENOTDIR,
+ EISDIR,
+ EINVAL,
+ ENFILE,
+ EMFILE,
+ ENOTTY,
+ ETXTBSY,
+ EFBIG,
+ ENOSPC,
+ ESPIPE,
+ EROFS,
+ EMLINK,
+ EPIPE,
+ EDOM,
+ ERANGE,
+ EDEADLK,
+ ENAMETOOLONG,
+ ENOLCK,
+ ENOSYS,
+ ENOTEMPTY,
+ ELOOP,
+ 0,
+ ENOMSG,
+ EIDRM,
+ ECHRNG,
+ EL2NSYNC,
+ EL3HLT,
+ EL3RST,
+ ELNRNG,
+ EUNATCH,
+ ENOCSI,
+ EL2HLT,
+ EBADE,
+ EBADR,
+ EXFULL,
+ ENOANO,
+ EBADRQC,
+ EBADSLT,
+ 0,
+ EBFONT,
+ ENOSTR,
+ ENODATA,
+ ETIME,
+ ENOSR,
+ ENONET,
+ ENOPKG,
+ EREMOTE,
+ ENOLINK,
+ EADV,
+ ESRMNT,
+ ECOMM,
+ EPROTO,
+ EMULTIHOP,
+ EDOTDOT,
+ EBADMSG,
+ EOVERFLOW,
+ ENOTUNIQ,
+ EBADFD,
+ EREMCHG,
+ ELIBACC,
+ ELIBBAD,
+ ELIBSCN,
+ ELIBMAX,
+ ELIBEXEC,
+ EILSEQ,
+ ERESTART,
+ ESTRPIPE,
+ EUSERS,
+ ENOTSOCK,
+ EDESTADDRREQ,
+ EMSGSIZE,
+ EPROTOTYPE,
+ ENOPROTOOPT,
+ EPROTONOSUPPORT,
+ ESOCKTNOSUPPORT,
+ EOPNOTSUPP,
+ EPFNOSUPPORT,
+ EAFNOSUPPORT,
+ EADDRINUSE,
+ EADDRNOTAVAIL,
+ ENETDOWN,
+ ENETUNREACH,
+ ENETRESET,
+ ECONNABORTED,
+ ECONNRESET,
+ ENOBUFS,
+ EISCONN,
+ ENOTCONN,
+ ESHUTDOWN,
+ ETOOMANYREFS,
+ ETIMEDOUT,
+ ECONNREFUSED,
+ EHOSTDOWN,
+ EHOSTUNREACH,
+ EALREADY,
+ EINPROGRESS,
+ ESTALE,
+ EUCLEAN,
+ ENOTNAM,
+ ENAVAIL,
+ EISNAM,
+ EREMOTEIO,
+#ifdef __mips__
+ 0, /* mips has an outrageous value for this... */
+#else
+ EDQUOT,
+#endif
+ ENOMEDIUM,
+ EMEDIUMTYPE,
+#if defined(__mips__) || defined(__sparc__)
+ EDEADLOCK,
+#endif
+};
+
+#endif
+
+/* __xpg_strerror_r is used in header */
+int attribute_hidden __xpg_strerror_r_internal(int errnum, char *strerrbuf, size_t buflen)
+{
+ register char *s;
+ int i, retval;
+ char buf[_STRERROR_BUFSIZE];
+ static const char unknown[] = {
+ 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
+ };
+
+ retval = EINVAL;
+
+
+#ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
+
+#if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
+ /* Need to translate errno to string index. */
+ for (i = 0 ; i < sizeof(estridx)/sizeof(estridx[0]) ; i++) {
+ if (estridx[i] == errnum) {
+ goto GOT_ESTRIDX;
+ }
+ }
+ i = INT_MAX; /* Failed, but may need to check mips special case. */
+#ifdef __mips__
+ if (errnum == EDQUOT) { /* Deal with large EDQUOT value on mips */
+ i = 122;
+ }
+#endif /* __mips__ */
+ GOT_ESTRIDX:
+#else
+ /* No errno to string index translation needed. */
+ i = errnum;
+#endif
+
+ if (((unsigned int) i) < _SYS_NERR) {
+ /* Trade time for space. This function should rarely be called
+ * so rather than keeping an array of pointers for the different
+ * messages, just run through the buffer until we find the
+ * correct string. */
+ for (s = (char *) _string_syserrmsgs ; i ; ++s) {
+ if (!*s) {
+ --i;
+ }
+ }
+ if (*s) { /* Make sure we have an actual message. */
+ retval = 0;
+ goto GOT_MESG;
+ }
+ }
+
+#endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
+
+ s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
+ __memcpy(s, unknown, sizeof(unknown));
+
+ GOT_MESG:
+ if (!strerrbuf) { /* SUSv3 */
+ buflen = 0;
+ }
+ i = __strlen(s) + 1;
+ if (i > buflen) {
+ i = buflen;
+ retval = ERANGE;
+ }
+
+ if (i) {
+ __memcpy(strerrbuf, s, i);
+ strerrbuf[i-1] = 0; /* In case buf was too small. */
+ }
+
+ if (retval) {
+ __set_errno(retval);
+ }
+
+ return retval;
+}
+
+#else /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
+
+int attribute_hidden __xpg_strerror_r_internal(int errnum, char *strerrbuf, size_t buflen)
+{
+ register char *s;
+ int i, retval;
+ char buf[_STRERROR_BUFSIZE];
+ static const char unknown[] = {
+ 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
+ };
+
+ s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
+ __memcpy(s, unknown, sizeof(unknown));
+
+ if (!strerrbuf) { /* SUSv3 */
+ buflen = 0;
+ }
+
+ retval = EINVAL;
+
+ i = buf + sizeof(buf) - s;
+
+ if (i > buflen) {
+ i = buflen;
+ retval = ERANGE;
+ }
+
+ if (i) {
+ __memcpy(strerrbuf, s, i);
+ strerrbuf[i-1] = 0; /* In case buf was too small. */
+ }
+
+ __set_errno(retval);
+
+ return retval;
+}
+
+#endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
+
+strong_alias(__xpg_strerror_r_internal,__xpg_strerror_r)
diff --git a/libc/string/_collate.c b/libc/string/_collate.c
new file mode 100644
index 000000000..35fe7dc1b
--- /dev/null
+++ b/libc/string/_collate.c
@@ -0,0 +1,686 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+/* Dec 20, 2002
+ * Initial test implementation of strcoll, strxfrm, wcscoll, and wcsxfrm.
+ * The code needs to be cleaned up a good bit, but I'd like to see people
+ * test it out.
+ *
+ */
+
+#include "_string.h"
+#include <ctype.h>
+#include <locale.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <assert.h>
+
+extern size_t __strlcpy(char *__restrict dst, const char *__restrict src,
+ size_t n) attribute_hidden;
+
+#ifdef WANT_WIDE
+extern int __wcscmp (__const wchar_t *__s1, __const wchar_t *__s2) attribute_hidden;
+extern size_t __wcsxfrm (wchar_t *__restrict __s1,
+ __const wchar_t *__restrict __s2, size_t __n) attribute_hidden;
+#endif
+#ifdef __UCLIBC_HAS_XLOCALE__
+extern int __strcoll_l (__const char *__s1, __const char *__s2, __locale_t __l) attribute_hidden;
+extern size_t __strxfrm_l (char *__dest, __const char *__src, size_t __n, __locale_t __l) attribute_hidden;
+extern int __wcscoll_l (__const wchar_t *__s1, __const wchar_t *__s2, __locale_t __loc) attribute_hidden;
+extern size_t __wcsxfrm_l (wchar_t *__s1, __const wchar_t *__s2, size_t __n, __locale_t __loc) attribute_hidden;
+#endif
+
+#ifdef __UCLIBC_HAS_LOCALE__
+#if defined(L_strxfrm) || defined(L_strxfrm_l) || defined(L_wcsxfrm) || defined(L_wcsxfrm_l)
+
+#ifdef L_strxfrm
+#ifndef WANT_WIDE
+#error WANT_WIDE should be defined for L_strxfrm
+#endif
+#ifdef L_wcsxfrm
+#error L_wcsxfrm already defined for L_strxfrm
+#endif
+#endif /* L_strxfrm */
+
+#if defined(L_strxfrm) || defined(L_strxfrm_l)
+
+#define wcscoll strcoll
+#define __wcscoll __strcoll
+#define wcscoll_l strcoll_l
+#define __wcscoll_l __strcoll_l
+#define wcsxfrm strxfrm
+#define __wcsxfrm __strxfrm
+#define wcsxfrm_l strxfrm_l
+#define __wcsxfrm_l __strxfrm_l
+
+#undef WANT_WIDE
+#undef Wvoid
+#undef Wchar
+#undef Wuchar
+#undef Wint
+
+#define Wchar char
+
+#endif /* defined(L_strxfrm) || defined(L_strxfrm_l) */
+
+#if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
+
+int attribute_hidden __wcscoll (const Wchar *s0, const Wchar *s1)
+{
+ return __wcscoll_l(s0, s1, __UCLIBC_CURLOCALE );
+}
+strong_alias(__wcscoll,wcscoll)
+
+size_t attribute_hidden __wcsxfrm(Wchar *__restrict ws1, const Wchar *__restrict ws2, size_t n)
+{
+ return __wcsxfrm_l(ws1, ws2, n, __UCLIBC_CURLOCALE );
+}
+strong_alias(__wcsxfrm,wcsxfrm)
+
+#else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
+
+
+#if 0
+#define CUR_COLLATE (&__UCLIBC_CURLOCALE_DATA.collate)
+#else
+#define CUR_COLLATE (& __LOCALE_PTR->collate)
+#endif
+
+#define MAX_PENDING 8
+
+typedef struct {
+ const Wchar *s;
+ const Wchar *eob; /* end of backward */
+
+ __uwchar_t weight;
+ __uwchar_t ui_weight; /* undefined or invalid */
+ int colitem;
+ int weightidx;
+ int rule;
+ size_t position;
+ /* should be wchar_t. if wchar < 0 do EILSEQ? */
+ __uwchar_t *cip;
+ __uwchar_t ci_pending[MAX_PENDING]; /* nul-terminated */
+
+ char *back_buf;
+ char *bbe; /* end of back_buf (actual last... not 1 past end) */
+ char *bp; /* ptr into backbuf, NULL if not in backward mode */
+ char ibb[128];
+ size_t bb_size;
+
+ int ru_pushed;
+} col_state_t;
+
+
+#define WEIGHT_MASK 0x3fffU
+#define RULE_MASK 0xc000U
+
+#define RULE_FORWARD (1 << 14)
+#define RULE_POSITION (1 << 15)
+
+#define UI_IDX (WEIGHT_MASK-6)
+#define POSIT_IDX (WEIGHT_MASK-5)
+#define RANGE_IDX (WEIGHT_MASK-4)
+#define UNDEF_IDX (WEIGHT_MASK-3)
+#define INVAL_IDX (WEIGHT_MASK-2)
+#define DITTO_IDX (WEIGHT_MASK-1)
+
+
+#undef TRACE
+#if 0
+#define TRACE(X) printf X
+#else
+#define TRACE(X) ((void)0)
+#endif
+
+static int lookup(wchar_t wc __LOCALE_PARAM )
+{
+ unsigned int sc, n, i0, i1;
+
+ if (((__uwchar_t) wc) > 0xffffU) {
+ return 0;
+ }
+
+ sc = wc & CUR_COLLATE->ti_mask;
+ wc >>= CUR_COLLATE->ti_shift;
+ n = wc & CUR_COLLATE->ii_mask;
+ wc >>= CUR_COLLATE->ii_shift;
+
+ i0 = CUR_COLLATE->wcs2colidt_tbl[wc];
+ i0 <<= CUR_COLLATE->ii_shift;
+ i1 = CUR_COLLATE->wcs2colidt_tbl[CUR_COLLATE->ii_len + i0 + n];
+ i1 <<= CUR_COLLATE->ti_shift;
+ return CUR_COLLATE->wcs2colidt_tbl[CUR_COLLATE->ii_len + CUR_COLLATE->ti_len + i1 + sc];
+
+}
+
+static void init_col_state(col_state_t *cs, const Wchar *wcs)
+{
+ __memset(cs, 0, sizeof(col_state_t));
+ cs->s = wcs;
+ cs->bp = cs->back_buf = cs->ibb;
+ cs->bb_size = 128;
+ cs->bbe = cs->back_buf + (cs->bb_size -1);
+}
+
+static void next_weight(col_state_t *cs, int pass __LOCALE_PARAM )
+{
+ int r, w, ru, ri, popping_backup_stack;
+ ssize_t n;
+ const uint16_t *p;
+#ifdef WANT_WIDE
+#define WC (*cs->s)
+#define N (1)
+#else /* WANT_WIDE */
+ wchar_t WC;
+ size_t n0, nx;
+#define N n0
+
+#endif /* WANT_WIDE */
+
+ do {
+
+ if (cs->ru_pushed) {
+ ru = cs->ru_pushed;
+ TRACE(("ru_pushed = %d\n", ru));
+ cs->ru_pushed = 0;
+ goto POSITION_SKIP;
+ }
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning should we walk pendings backwards?
+#endif
+ if (cs->cip) { /* possible pending weight */
+ if ((r = *(cs->cip++)) == 0) {
+ cs->cip = NULL;
+ continue;
+ }
+ cs->weightidx = r & WEIGHT_MASK;
+ assert(cs->weightidx);
+/* assert(cs->weightidx != WEIGHT_MASK); */
+ } else { /* get the next collation item from the string */
+ TRACE(("clearing popping flag\n"));
+ popping_backup_stack = 0;
+
+ IGNORE_LOOP:
+ /* keep first pos as 0 for a sentinal */
+ if (*cs->bp) { /* pending backward chars */
+ POP_BACKUP:
+ popping_backup_stack = 1;
+ TRACE(("setting popping flag\n"));
+ n = 0;
+ if (*cs->bp > 0) { /* singles pending */
+ cs->s -= 1;
+ if ((*cs->bp -= 1) == 0) {
+ cs->bp -= 1;
+ }
+ } else { /* last was a multi */
+ cs->s += *cs->bp;
+ cs->bp -= 1;
+ }
+ } else if (!*cs->s) { /* not in backward mode and end of string */
+ cs->weight = 0;
+ return;
+ } else {
+ cs->position += 1;
+ }
+
+ BACK_LOOP:
+#ifdef WANT_WIDE
+ n = 1;
+ cs->colitem = r = lookup(*cs->s __LOCALE_ARG );
+#else /* WANT_WIDE */
+ n = n0 = __locale_mbrtowc_l(&WC, cs->s, __LOCALE_PTR);
+ if (n < 0) {
+ __set_errno(EILSEQ);
+ cs->weight = 0;
+ return;
+ }
+ cs->colitem = r = lookup(WC __LOCALE_ARG );
+#endif /* WANT_WIDE */
+
+ TRACE((" r=%d WC=%#lx\n", r, (unsigned long)(WC)));
+
+ if (r > CUR_COLLATE->max_col_index) { /* starting char for one or more sequences */
+ p = CUR_COLLATE->multistart_tbl;
+ p += p[r-CUR_COLLATE->max_col_index -1];
+ do {
+ n = N;
+ r = *p++;
+ do {
+ if (!*p) { /* found it */
+ cs->colitem = r;
+ TRACE((" found multi %d\n", n));
+ goto FOUND;
+ }
+#ifdef WANT_WIDE
+ /* the lookup check here is safe since we're assured that *p is a valid colidx */
+ if (!cs->s[n] || (lookup(cs->s[n] __LOCALE_ARG ) != *p)) {
+ do {} while (*p++);
+ break;
+ }
+ ++p;
+ ++n;
+#else /* WANT_WIDE */
+ if (cs->s[n]) {
+ nx = __locale_mbrtowc_l(&WC, cs->s + n, __LOCALE_PTR);
+ if (nx < 0) {
+ __set_errno(EILSEQ);
+ cs->weight = 0;
+ return;
+ }
+ }
+ if (!cs->s[n] || (lookup(WC __LOCALE_ARG ) != *p)) {
+ do {} while (*p++);
+ break;
+ }
+ ++p;
+ n += nx; /* Only gets here if cs->s[n] != 0, so nx is set. */
+#endif /* WANT_WIDE */
+ } while (1);
+ } while (1);
+ } else if (r == 0) { /* illegal, undefined, or part of a range */
+ if ((CUR_COLLATE->range_count)
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning .. need to introduce range as a collating item?
+#endif
+ && (((__uwchar_t)(WC - CUR_COLLATE->range_low)) <= CUR_COLLATE->range_count)
+ ) { /* part of a range */
+ /* Note: cs->colitem = 0 already. */
+ TRACE((" found range\n"));
+ ru = CUR_COLLATE->ruletable[CUR_COLLATE->range_rule_offset*CUR_COLLATE->MAX_WEIGHTS + pass];
+ assert((ru & WEIGHT_MASK) != DITTO_IDX);
+ if ((ru & WEIGHT_MASK) == WEIGHT_MASK) {
+ ru = (ru & RULE_MASK) | RANGE_IDX;
+ cs->weight = CUR_COLLATE->range_base_weight + (WC - CUR_COLLATE->range_low);
+ }
+ goto RANGE_SKIP_TO;
+ } else if (((__uwchar_t)(WC)) <= 0x7fffffffUL) { /* legal but undefined */
+ UNDEFINED:
+ /* Note: cs->colitem = 0 already. */
+ ri = CUR_COLLATE->undefined_idx;
+ assert(ri != 0); /* implicit undefined isn't supported */
+
+ TRACE((" found explicit UNDEFINED\n"));
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning right now single weight locales do not support ..
+#endif
+ if (CUR_COLLATE->num_weights == 1) {
+ TRACE((" single weight UNDEFINED\n"));
+ cs->weightidx = RANGE_IDX;
+ cs->weight = ri;
+ cs->s += n;
+ goto PROCESS_WEIGHT;
+ }
+
+ ri = CUR_COLLATE->index2ruleidx[ri - 1];
+ ru = CUR_COLLATE->ruletable[ri * CUR_COLLATE->MAX_WEIGHTS + pass];
+ assert((ru & WEIGHT_MASK) != WEIGHT_MASK); /* TODO: handle ".." */
+ if ((ru & WEIGHT_MASK) == DITTO_IDX) {
+ cs->colitem = CUR_COLLATE->undefined_idx;
+ }
+ goto RANGE_SKIP_TO;
+ } else { /* illegal */
+ TRACE((" found illegal\n"));
+ __set_errno(EINVAL);
+ /* We put all illegals in the same equiv class with maximal weight,
+ * and ignore them after the first pass. */
+ if (pass > 0) {
+ cs->s += n;
+ goto IGNORE_LOOP;
+ }
+ ru = (RULE_FORWARD | RANGE_IDX);
+ cs->weight = 0xffffU;
+ goto RANGE_SKIP_TO;
+ }
+ } else if (CUR_COLLATE->num_weights == 1) {
+ TRACE((" single weight\n"));
+ cs->weightidx = RANGE_IDX;
+ cs->weight = cs->colitem;
+ cs->s += n;
+ goto PROCESS_WEIGHT;
+ } else {
+ TRACE((" normal\n"));
+ }
+
+ /* if we get here, it is a normal char either singlely weighted, undefined, or in a range */
+ FOUND:
+ ri = CUR_COLLATE->index2ruleidx[cs->colitem - 1];
+ TRACE((" ri=%d ", ri));
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning make sure this is correct
+#endif
+ if (!ri) {
+ TRACE(("NOT IN THIS LOCALE\n"));
+ goto UNDEFINED;
+ }
+ ru = CUR_COLLATE->ruletable[ri * CUR_COLLATE->MAX_WEIGHTS + pass];
+
+ RANGE_SKIP_TO:
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning ignoreables probably should not interrupt backwards processing, but this is wrong
+#endif
+/* if (!(ru & WEIGHT_MASK)) { */
+/* TRACE(("IGNORE\n")); */
+/* cs->s += n; */
+/* continue; */
+/* } */
+
+
+ TRACE((" rule = %#x weight = %#x popping = %d s = %p eob = %p\n",
+ ru & RULE_MASK, ru & WEIGHT_MASK, popping_backup_stack,
+ cs->s, cs->eob));
+ /* now we need to check if we're going backwards... */
+
+ if (!popping_backup_stack) {
+ if (!(ru & RULE_MASK)) { /* backward */
+ TRACE(("backwards\n"));
+ assert(cs->bp <= cs->bbe);
+ if (cs->bp == cs->bbe) {
+ if (cs->back_buf == cs->ibb) { /* was using internal buffer */
+ cs->bp = malloc(cs->bb_size + 128);
+ if (!cs->bp) {
+ __set_errno(ENOMEM);
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning what to do here?
+#endif
+ cs->weight = 0;
+ return;
+ }
+ __memcpy(cs->bp, cs->back_buf, cs->bb_size);
+
+ } else {
+ cs->bp = realloc(cs->back_buf, cs->bb_size + 128);
+ if (!cs->bp) {
+ __set_errno(ENOMEM);
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning what to do here?
+#endif
+ cs->weight = 0;
+ return;
+ }
+ }
+ cs->bb_size += 128;
+ cs->bbe = cs->bp + (cs->bbe - cs->back_buf);
+ cs->back_buf = cs->bp;
+ cs->bp = cs->bbe;
+
+ }
+ if (n==1) { /* single char */
+ if (*cs->bp && (((unsigned char)(*cs->bp)) < CHAR_MAX)) {
+ *cs->bp += 1; /* increment last single's count */
+ } else { /* last was a multi, or just starting */
+ if (!cs->bp) {
+ cs->bp = cs->back_buf;
+ } else {
+ assert(cs->bp < cs->bbe);
+ ++cs->bp;
+ }
+ *cs->bp = 1;
+ }
+ } else { /* multichar */
+ assert(n>1);
+ assert(cs->bp < cs->bbe);
+ *++cs->bp = -n;
+ }
+ cs->s += n;
+ if (*cs->s) {
+ goto BACK_LOOP;
+ }
+ /* end-of-string so start popping */
+ cs->eob = cs->s;
+ TRACE(("popping\n"));
+ goto POP_BACKUP;
+ } else if (*cs->bp) { /* was going backward but this element isn't */
+ /* discard current and use previous backward element */
+ assert(!cs->cip);
+ cs->eob = cs->s;
+ TRACE(("popping\n"));
+ goto POP_BACKUP;
+ } else { /* was and still going forward */
+ TRACE(("forwards\n"));
+ if ((ru & (RULE_POSITION|WEIGHT_MASK)) > RULE_POSITION) {
+ assert(ru & WEIGHT_MASK);
+ cs->ru_pushed = ru;
+ cs->weight = cs->position;
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning devel code
+#endif
+ cs->position = 0; /* reset to reduce size for strcoll? */
+ cs->s += n;
+ cs->weightidx = RANGE_IDX;
+ goto PROCESS_WEIGHT;
+ }
+ }
+ } else { /* popping backwards stack */
+ TRACE(("popping (continued)\n"));
+ if (!*cs->bp) {
+ cs->s = cs->eob;
+ }
+ cs->s -= n;
+ }
+
+ cs->s += n;
+ POSITION_SKIP:
+ cs->weightidx = ru & WEIGHT_MASK;
+ cs->rule = ru & RULE_MASK;
+ }
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning for pending we only want the weight... _not_ the rule
+#endif
+ if (!cs->weightidx) { /* ignore */
+ continue;
+ }
+
+ PROCESS_WEIGHT:
+ assert(cs->weightidx);
+
+
+ if (((unsigned int)(cs->weightidx - UI_IDX)) <= (INVAL_IDX-UI_IDX)) {
+ if (cs->weightidx == UI_IDX) {
+ cs->weight = cs->ui_weight;
+ }
+ return;
+ }
+
+ assert(cs->weightidx != WEIGHT_MASK);
+ if (cs->weightidx == DITTO_IDX) { /* want the weight of the current collating item */
+ TRACE(("doing ditto\n"));
+ w = CUR_COLLATE->index2weight[cs->colitem -1];
+ } else if (cs->weightidx <= CUR_COLLATE->max_col_index) { /* normal */
+ TRACE(("doing normal\n"));
+ w = CUR_COLLATE->index2weight[cs->weightidx -1];
+ } else { /* a string */
+ TRACE(("doing string\n"));
+ assert(!(cs->weightidx & RULE_MASK));
+ /* note: iso14561 allows null string here */
+ p = CUR_COLLATE->weightstr + (cs->weightidx - (CUR_COLLATE->max_col_index + 2));
+ if (*p & WEIGHT_MASK) {
+ r = 0;
+ do {
+ assert(r < MAX_PENDING);
+ cs->ci_pending[r++] = *p++;
+ } while (*p & WEIGHT_MASK);
+ cs->cip = cs->ci_pending;
+ }
+ continue;
+ }
+
+ cs->weight = w;
+ return;
+ } while (1);
+}
+
+int attribute_hidden __UCXL(wcscoll) (const Wchar *s0, const Wchar *s1 __LOCALE_PARAM )
+{
+ col_state_t ws[2];
+ int pass;
+
+ if (!CUR_COLLATE->num_weights) { /* C locale */
+#ifdef WANT_WIDE
+ return __wcscmp(s0, s1);
+#else /* WANT_WIDE */
+ return __strcmp(s0, s1);
+#endif /* WANT_WIDE */
+ }
+
+ pass = 0;
+ do { /* loop through the weights levels */
+ init_col_state(ws, s0);
+ init_col_state(ws+1, s1);
+ do { /* loop through the strings */
+ /* for each string, get the next weight */
+ next_weight(ws, pass __LOCALE_ARG );
+ next_weight(ws+1, pass __LOCALE_ARG );
+ TRACE(("w0=%lu w1=%lu\n",
+ (unsigned long) ws[0].weight,
+ (unsigned long) ws[1].weight));
+
+ if (ws[0].weight != ws[1].weight) {
+ return ws[0].weight - ws[1].weight;
+ }
+ } while (ws[0].weight);
+ } while (++pass < CUR_COLLATE->num_weights);
+
+ return 0;
+}
+__UCXL_ALIAS(wcscoll)
+
+#ifdef WANT_WIDE
+
+size_t attribute_hidden __UCXL(wcsxfrm)(wchar_t *__restrict ws1, const wchar_t *__restrict ws2,
+ size_t n __LOCALE_PARAM )
+{
+ col_state_t cs;
+ size_t count;
+ int pass;
+
+ if (!CUR_COLLATE->num_weights) { /* C locale */
+ return __wcsxfrm(ws1, ws2, n);
+ }
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning handle empty string as a special case
+#endif
+
+ count = pass = 0;
+ do { /* loop through the weights levels */
+ init_col_state(&cs, ws2);
+ do { /* loop through the string */
+ next_weight(&cs, pass __LOCALE_ARG );
+ TRACE(("weight=%lu (%#lx)\n", (unsigned long) cs.weight, (unsigned long) cs.weight));
+ if (count < n) {
+ ws1[count] = cs.weight +1;
+ }
+ ++count;
+ TRACE(("--------------------------------------------\n"));
+ } while (cs.weight);
+ if (count <= n) { /* overwrite the trailing 0 end-of-pass marker */
+ ws1[count-1] = 1;
+ }
+ TRACE(("-------------------- pass %d --------------------\n", pass));
+ } while (++pass < CUR_COLLATE->num_weights);
+ if (count <= n) { /* oops... change it back */
+ ws1[count-1] = 0;
+ }
+ return count-1;
+}
+
+__UCXL_ALIAS(wcsxfrm)
+
+#else /* WANT_WIDE */
+
+static const unsigned long bound[] = {
+ 1UL << 7,
+ 1UL << 11,
+ 1UL << 16,
+ 1UL << 21,
+ 1UL << 26,
+};
+
+static unsigned char first[] = {
+ 0x0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc
+};
+
+/* Use an extension of UTF-8 to store a 32 bit val in max 6 bytes. */
+
+static size_t store(unsigned char *s, size_t count, size_t n, __uwchar_t weight)
+{
+ int i, r;
+
+ i = 0;
+ do {
+ if (weight < bound[i]) {
+ break;
+ }
+ } while (++i < sizeof(bound)/sizeof(bound[0]));
+
+ r = i+1;
+ if (i + count < n) {
+ s += count;
+ s[0] = first[i];
+ while (i) {
+ s[i] = 0x80 | (weight & 0x3f);
+ weight >>= 6;
+ --i;
+ }
+ s[0] |= weight;
+ }
+
+ return r;
+}
+
+size_t attribute_hidden __UCXL(strxfrm)(char *__restrict ws1, const char *__restrict ws2, size_t n
+ __LOCALE_PARAM )
+{
+ col_state_t cs;
+ size_t count, inc;
+ int pass;
+
+ if (!CUR_COLLATE->num_weights) { /* C locale */
+ return __strlcpy(ws1, ws2, n);
+ }
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning handle empty string as a special case
+#endif
+
+ inc = count = pass = 0;
+ do { /* loop through the weights levels */
+ init_col_state(&cs, ws2);
+ do { /* loop through the string */
+ next_weight(&cs, pass __LOCALE_ARG );
+ TRACE(("weight=%lu (%#lx)\n", (unsigned long) cs.weight, (unsigned long) cs.weight));
+ inc = store((unsigned char *)ws1, count, n, cs.weight + 1);
+ count += inc;
+ TRACE(("--------------------------------------------\n"));
+ } while (cs.weight);
+ /* overwrite the trailing 0 end-of-pass marker */
+ assert(inc == 1);
+ if (count <= n) {
+ ws1[count-1] = 1;
+ }
+ TRACE(("-------------------- pass %d --------------------\n", pass));
+ } while (++pass < CUR_COLLATE->num_weights);
+ if (count <= n) { /* oops... change it back */
+ ws1[count-1] = 0;
+ }
+ return count-1;
+}
+
+__UCXL_ALIAS(strxfrm)
+
+#endif /* WANT_WIDE */
+
+#endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
+
+#endif /* defined(L_strxfrm) || defined(L_strxfrm_l) || defined(L_wcsxfrm) || defined(L_wcsxfrm_l) */
+
+#endif /* __UCLIBC_HAS_LOCALE__ */
+/**********************************************************************/
diff --git a/libc/string/_string.h b/libc/string/_string.h
new file mode 100644
index 000000000..4ecde30a7
--- /dev/null
+++ b/libc/string/_string.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#ifndef __STRING_H
+#define __STRING_H
+
+#define _GNU_SOURCE
+#include <features.h>
+#include <string.h>
+#include <limits.h>
+#include <stdint.h>
+
+#ifdef WANT_WIDE
+# include <wchar.h>
+# include <wctype.h>
+# include <bits/uClibc_uwchar.h>
+# define Wvoid wchar_t
+# define Wchar wchar_t
+# define Wuchar __uwchar_t
+# define Wint wchar_t
+#else
+# define Wvoid void
+# define Wchar char
+typedef unsigned char __string_uchar_t;
+# define Wuchar __string_uchar_t
+# define Wint int
+#endif
+
+#endif /* __STRING_H */
diff --git a/libc/string/_string_syserrmsgs.c b/libc/string/_string_syserrmsgs.c
new file mode 100644
index 000000000..a76c0e3af
--- /dev/null
+++ b/libc/string/_string_syserrmsgs.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <features.h>
+
+#ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
+
+const char _string_syserrmsgs[] = {
+ /* 0: 0, 8 */ "Success\0"
+ /* 1: 8, 24 */ "Operation not permitted\0"
+ /* 2: 32, 26 */ "No such file or directory\0"
+ /* 3: 58, 16 */ "No such process\0"
+ /* 4: 74, 24 */ "Interrupted system call\0"
+ /* 5: 98, 19 */ "Input/output error\0"
+ /* 6: 117, 26 */ "No such device or address\0"
+ /* 7: 143, 23 */ "Argument list too long\0"
+ /* 8: 166, 18 */ "Exec format error\0"
+ /* 9: 184, 20 */ "Bad file descriptor\0"
+ /* 10: 204, 19 */ "No child processes\0"
+ /* 11: 223, 33 */ "Resource temporarily unavailable\0"
+ /* 12: 256, 23 */ "Cannot allocate memory\0"
+ /* 13: 279, 18 */ "Permission denied\0"
+ /* 14: 297, 12 */ "Bad address\0"
+ /* 15: 309, 22 */ "Block device required\0"
+ /* 16: 331, 24 */ "Device or resource busy\0"
+ /* 17: 355, 12 */ "File exists\0"
+ /* 18: 367, 26 */ "Invalid cross-device link\0"
+ /* 19: 393, 15 */ "No such device\0"
+ /* 20: 408, 16 */ "Not a directory\0"
+ /* 21: 424, 15 */ "Is a directory\0"
+ /* 22: 439, 17 */ "Invalid argument\0"
+ /* 23: 456, 30 */ "Too many open files in system\0"
+ /* 24: 486, 20 */ "Too many open files\0"
+ /* 25: 506, 31 */ "Inappropriate ioctl for device\0"
+ /* 26: 537, 15 */ "Text file busy\0"
+ /* 27: 552, 15 */ "File too large\0"
+ /* 28: 567, 24 */ "No space left on device\0"
+ /* 29: 591, 13 */ "Illegal seek\0"
+ /* 30: 604, 22 */ "Read-only file system\0"
+ /* 31: 626, 15 */ "Too many links\0"
+ /* 32: 641, 12 */ "Broken pipe\0"
+ /* 33: 653, 33 */ "Numerical argument out of domain\0"
+ /* 34: 686, 30 */ "Numerical result out of range\0"
+ /* 35: 716, 26 */ "Resource deadlock avoided\0"
+ /* 36: 742, 19 */ "File name too long\0"
+ /* 37: 761, 19 */ "No locks available\0"
+ /* 38: 780, 25 */ "Function not implemented\0"
+ /* 39: 805, 20 */ "Directory not empty\0"
+ /* 40: 825, 34 */ "Too many levels of symbolic links\0"
+ /* 41: 859, 1 */ "\0"
+ /* 42: 860, 27 */ "No message of desired type\0"
+ /* 43: 887, 19 */ "Identifier removed\0"
+ /* 44: 906, 28 */ "Channel number out of range\0"
+ /* 45: 934, 25 */ "Level 2 not synchronized\0"
+ /* 46: 959, 15 */ "Level 3 halted\0"
+ /* 47: 974, 14 */ "Level 3 reset\0"
+ /* 48: 988, 25 */ "Link number out of range\0"
+ /* 49: 1013, 29 */ "Protocol driver not attached\0"
+ /* 50: 1042, 27 */ "No CSI structure available\0"
+ /* 51: 1069, 15 */ "Level 2 halted\0"
+ /* 52: 1084, 17 */ "Invalid exchange\0"
+ /* 53: 1101, 27 */ "Invalid request descriptor\0"
+ /* 54: 1128, 14 */ "Exchange full\0"
+ /* 55: 1142, 9 */ "No anode\0"
+ /* 56: 1151, 21 */ "Invalid request code\0"
+ /* 57: 1172, 13 */ "Invalid slot\0"
+ /* 58: 1185, 1 */ "\0"
+ /* 59: 1186, 21 */ "Bad font file format\0"
+ /* 60: 1207, 20 */ "Device not a stream\0"
+ /* 61: 1227, 18 */ "No data available\0"
+ /* 62: 1245, 14 */ "Timer expired\0"
+ /* 63: 1259, 25 */ "Out of streams resources\0"
+ /* 64: 1284, 30 */ "Machine is not on the network\0"
+ /* 65: 1314, 22 */ "Package not installed\0"
+ /* 66: 1336, 17 */ "Object is remote\0"
+ /* 67: 1353, 22 */ "Link has been severed\0"
+ /* 68: 1375, 16 */ "Advertise error\0"
+ /* 69: 1391, 14 */ "Srmount error\0"
+ /* 70: 1405, 28 */ "Communication error on send\0"
+ /* 71: 1433, 15 */ "Protocol error\0"
+ /* 72: 1448, 19 */ "Multihop attempted\0"
+ /* 73: 1467, 19 */ "RFS specific error\0"
+ /* 74: 1486, 12 */ "Bad message\0"
+ /* 75: 1498, 38 */ "Value too large for defined data type\0"
+ /* 76: 1536, 27 */ "Name not unique on network\0"
+ /* 77: 1563, 29 */ "File descriptor in bad state\0"
+ /* 78: 1592, 23 */ "Remote address changed\0"
+ /* 79: 1615, 39 */ "Can not access a needed shared library\0"
+ /* 80: 1654, 37 */ "Accessing a corrupted shared library\0"
+ /* 81: 1691, 32 */ ".lib section in a.out corrupted\0"
+ /* 82: 1723, 48 */ "Attempting to link in too many shared libraries\0"
+ /* 83: 1771, 38 */ "Cannot exec a shared library directly\0"
+ /* 84: 1809, 50 */ "Invalid or incomplete multibyte or wide character\0"
+ /* 85: 1859, 44 */ "Interrupted system call should be restarted\0"
+ /* 86: 1903, 19 */ "Streams pipe error\0"
+ /* 87: 1922, 15 */ "Too many users\0"
+ /* 88: 1937, 31 */ "Socket operation on non-socket\0"
+ /* 89: 1968, 29 */ "Destination address required\0"
+ /* 90: 1997, 17 */ "Message too long\0"
+ /* 91: 2014, 31 */ "Protocol wrong type for socket\0"
+ /* 92: 2045, 23 */ "Protocol not available\0"
+ /* 93: 2068, 23 */ "Protocol not supported\0"
+ /* 94: 2091, 26 */ "Socket type not supported\0"
+ /* 95: 2117, 24 */ "Operation not supported\0"
+ /* 96: 2141, 30 */ "Protocol family not supported\0"
+ /* 97: 2171, 41 */ "Address family not supported by protocol\0"
+ /* 98: 2212, 23 */ "Address already in use\0"
+ /* 99: 2235, 32 */ "Cannot assign requested address\0"
+ /* 100: 2267, 16 */ "Network is down\0"
+ /* 101: 2283, 23 */ "Network is unreachable\0"
+ /* 102: 2306, 36 */ "Network dropped connection on reset\0"
+ /* 103: 2342, 33 */ "Software caused connection abort\0"
+ /* 104: 2375, 25 */ "Connection reset by peer\0"
+ /* 105: 2400, 26 */ "No buffer space available\0"
+ /* 106: 2426, 40 */ "Transport endpoint is already connected\0"
+ /* 107: 2466, 36 */ "Transport endpoint is not connected\0"
+ /* 108: 2502, 46 */ "Cannot send after transport endpoint shutdown\0"
+ /* 109: 2548, 35 */ "Too many references: cannot splice\0"
+ /* 110: 2583, 21 */ "Connection timed out\0"
+ /* 111: 2604, 19 */ "Connection refused\0"
+ /* 112: 2623, 13 */ "Host is down\0"
+ /* 113: 2636, 17 */ "No route to host\0"
+ /* 114: 2653, 30 */ "Operation already in progress\0"
+ /* 115: 2683, 26 */ "Operation now in progress\0"
+ /* 116: 2709, 22 */ "Stale NFS file handle\0"
+ /* 117: 2731, 25 */ "Structure needs cleaning\0"
+ /* 118: 2756, 28 */ "Not a XENIX named type file\0"
+ /* 119: 2784, 30 */ "No XENIX semaphores available\0"
+ /* 120: 2814, 21 */ "Is a named type file\0"
+ /* 121: 2835, 17 */ "Remote I/O error\0"
+ /* 122: 2852, 20 */ "Disk quota exceeded\0"
+ /* 123: 2872, 16 */ "No medium found\0"
+ /* 124: 2888, 18 */ "Wrong medium type"
+#if defined(__mips__) || defined(__sparc__)
+ "\0"
+ /* 125: 2906, 28 */ "File locking deadlock error"
+#endif
+ /* Note: for mips we are ignoring ECANCELED since glibc doesn't have a
+ * corresponsding message.*/
+};
+
+#endif
diff --git a/libc/string/_string_syssigmsgs.c b/libc/string/_string_syssigmsgs.c
new file mode 100644
index 000000000..4a94ddf4f
--- /dev/null
+++ b/libc/string/_string_syssigmsgs.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <features.h>
+
+#ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
+
+const char _string_syssigmsgs[] = {
+ /* 0: 0, 1 */ "\0"
+ /* 1: 1, 7 */ "Hangup\0"
+ /* 2: 8, 10 */ "Interrupt\0"
+ /* 3: 18, 5 */ "Quit\0"
+ /* 4: 23, 20 */ "Illegal instruction\0"
+ /* 5: 43, 22 */ "Trace/breakpoint trap\0"
+ /* 6: 65, 8 */ "Aborted\0"
+ /* 7: 73, 10 */ "Bus error\0"
+ /* 8: 83, 25 */ "Floating point exception\0"
+ /* 9: 108, 7 */ "Killed\0"
+ /* 10: 115, 22 */ "User defined signal 1\0"
+ /* 11: 137, 19 */ "Segmentation fault\0"
+ /* 12: 156, 22 */ "User defined signal 2\0"
+ /* 13: 178, 12 */ "Broken pipe\0"
+ /* 14: 190, 12 */ "Alarm clock\0"
+ /* 15: 202, 11 */ "Terminated\0"
+ /* 16: 213, 12 */ "Stack fault\0"
+ /* 17: 225, 13 */ "Child exited\0"
+ /* 18: 238, 10 */ "Continued\0"
+ /* 19: 248, 17 */ "Stopped (signal)\0"
+ /* 20: 265, 8 */ "Stopped\0"
+ /* 21: 273, 20 */ "Stopped (tty input)\0"
+ /* 22: 293, 21 */ "Stopped (tty output)\0"
+ /* 23: 314, 21 */ "Urgent I/O condition\0"
+ /* 24: 335, 24 */ "CPU time limit exceeded\0"
+ /* 25: 359, 25 */ "File size limit exceeded\0"
+ /* 26: 384, 22 */ "Virtual timer expired\0"
+ /* 27: 406, 24 */ "Profiling timer expired\0"
+ /* 28: 430, 15 */ "Window changed\0"
+ /* 29: 445, 13 */ "I/O possible\0"
+ /* 30: 458, 14 */ "Power failure\0"
+ /* 31: 472, 16 */ "Bad system call"
+#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
+ /* 32: 488, 9 */ "\0EMT trap"
+#endif
+};
+
+#endif
diff --git a/libc/string/_syserrmsg.h b/libc/string/_syserrmsg.h
new file mode 100644
index 000000000..efb7a1d59
--- /dev/null
+++ b/libc/string/_syserrmsg.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#ifndef __SYSERRMSG_H
+#define __SYSERRMSG_H 1
+
+/**********************************************************************/
+/* NOTE: If we ever do internationalized syserr messages, this will
+ * have to be changed! */
+
+#if defined(__mips__) || defined(__sparc__)
+/* sparce and mips have an extra error entry, as EDEADLK and EDEADLOCK have
+ * different meanings on those platforms. */
+# define _SYS_NERR 126
+#else
+# define _SYS_NERR 125
+#endif
+
+#ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
+# define _SYS_ERRMSG_MAXLEN 50
+#else /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
+# define _SYS_ERRMSG_MAXLEN 0
+#endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
+
+#if _SYS_ERRMSG_MAXLEN < __UIM_BUFLEN_INT + 14
+# define _STRERROR_BUFSIZE (__UIM_BUFLEN_INT + 14)
+#else
+# define _STRERROR_BUFSIZE _SYS_ERRMSG_MAXLEN
+#endif
+
+#endif
diff --git a/libc/string/arm/_memcpy.S b/libc/string/arm/_memcpy.S
index 236500e5f..e8d78af23 100644
--- a/libc/string/arm/_memcpy.S
+++ b/libc/string/arm/_memcpy.S
@@ -73,6 +73,7 @@
.text
.global _memcpy
+.hidden _memcpy
.type _memcpy,%function
.align 4
diff --git a/libc/string/arm/bcopy.S b/libc/string/arm/bcopy.S
index a02807527..2914b8972 100644
--- a/libc/string/arm/bcopy.S
+++ b/libc/string/arm/bcopy.S
@@ -39,8 +39,8 @@
/* bcopy = memcpy/memmove with arguments reversed. */
-.global bcopy
-.set bcopy,__bcopy
+#include <features.h>
+
.text
.global __bcopy
.hidden __bcopy
@@ -55,3 +55,5 @@ __bcopy:
b _memcpy (PLT)
.size __bcopy,.-__bcopy
+
+strong_alias(__bcopy,bcopy)
diff --git a/libc/string/arm/bzero.S b/libc/string/arm/bzero.S
index 93582f7c8..2cb67097e 100644
--- a/libc/string/arm/bzero.S
+++ b/libc/string/arm/bzero.S
@@ -37,16 +37,19 @@
* by Erik Andersen <andersen@codepoet.org>
*/
+#include <features.h>
+
.text
.global __bzero
+.hidden __bzero
.type __bzero,%function
.align 4
__bzero:
mov r2, r1
mov r1, #0
- b memset (PLT)
+ b __memset
.size __bzero,.-__bzero
-.weak bzero ; bzero = __bzero
+strong_alias(__bzero,bzero)
diff --git a/libc/string/arm/memcmp.S b/libc/string/arm/memcmp.S
index bdb5aca18..a97e02742 100644
--- a/libc/string/arm/memcmp.S
+++ b/libc/string/arm/memcmp.S
@@ -29,9 +29,8 @@
* by Erik Andersen <andersen@codepoet.org>
*/
+#include <features.h>
-.global memcmp
-.set memcmp,__memcmp
.text
.global __memcmp
.hidden __memcmp
@@ -56,4 +55,6 @@ __memcmp:
mov pc, lr
.size __memcmp,.-__memcmp
-.weak bcmp ; bcmp = memcmp
+
+strong_alias(__memcmp,memcmp)
+strong_alias(__memcmp,bcmp)
diff --git a/libc/string/arm/memcpy.S b/libc/string/arm/memcpy.S
index 372da4c49..8f81a15e5 100644
--- a/libc/string/arm/memcpy.S
+++ b/libc/string/arm/memcpy.S
@@ -37,8 +37,8 @@
* by Erik Andersen <andersen@codepoet.org>
*/
-.global memcpy
-.set memcpy,__memcpy
+#include <features.h>
+
.text
.global __memcpy
.hidden __memcpy
@@ -47,7 +47,9 @@
__memcpy:
stmfd sp!, {r0, lr}
- bl _memcpy (PLT)
+ bl _memcpy
ldmfd sp!, {r0, pc}
.size __memcpy,.-__memcpy
+
+strong_alias(__memcpy,memcpy)
diff --git a/libc/string/arm/memmove.S b/libc/string/arm/memmove.S
index eafd345b4..a26cf731e 100644
--- a/libc/string/arm/memmove.S
+++ b/libc/string/arm/memmove.S
@@ -37,8 +37,8 @@
* by Erik Andersen <andersen@codepoet.org>
*/
-.global memmove
-.set memmove,__memmove
+#include <features.h>
+
.text
.global __memmove
.hidden __memmove
@@ -47,7 +47,9 @@
__memmove:
stmfd sp!, {r0, lr}
- bl _memcpy (PLT)
+ bl _memcpy
ldmfd sp!, {r0, pc}
.size __memmove,.-__memmove
+
+strong_alias(__memmove,memmove)
diff --git a/libc/string/arm/memset.S b/libc/string/arm/memset.S
index 5fca03a13..dea05a6b0 100644
--- a/libc/string/arm/memset.S
+++ b/libc/string/arm/memset.S
@@ -17,10 +17,9 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <features.h>
#include <sys/syscall.h>
-.global memset
-.set memset,__memset
.text
.global __memset
.hidden __memset
@@ -72,3 +71,5 @@ __memset:
mov pc, lr
.size __memset,.-__memset
+
+strong_alias(__memset,memset)
diff --git a/libc/string/arm/strcmp.S b/libc/string/arm/strcmp.S
index 33acc14cf..3f462dec0 100644
--- a/libc/string/arm/strcmp.S
+++ b/libc/string/arm/strcmp.S
@@ -31,8 +31,6 @@
#include <features.h>
-.global strcmp
-.set strcmp,__strcmp
.text
.global __strcmp
.hidden __strcmp
@@ -50,7 +48,9 @@ __strcmp:
mov pc, lr
.size __strcmp,.-__strcmp
+
+strong_alias(__strcmp,strcmp)
#ifndef __UCLIBC_HAS_LOCALE__
-.global __strcoll ; .hidden __strcoll ; __strcoll = __strcmp
-.global strcoll ; .set strcoll,__strcmp
+hidden_strong_alias(__strcmp,__strcoll)
+strong_alias(__strcmp,strcoll)
#endif
diff --git a/libc/string/arm/strlen.S b/libc/string/arm/strlen.S
index 7d91fd033..f623cbe20 100644
--- a/libc/string/arm/strlen.S
+++ b/libc/string/arm/strlen.S
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <features.h>
#include <endian.h>
#include <sys/syscall.h>
@@ -25,8 +26,6 @@
* exit: r0 = len
*/
-.global strlen
-.set strlen,__strlen
.text
.global __strlen
.hidden __strlen
@@ -80,3 +79,5 @@ Llastword: @ drop through to here once we find a
mov pc,lr
.size __strlen,.-__strlen
+
+strong_alias(__strlen,strlen)
diff --git a/libc/string/arm/strncmp.S b/libc/string/arm/strncmp.S
index 94e93f7df..a3278727e 100644
--- a/libc/string/arm/strncmp.S
+++ b/libc/string/arm/strncmp.S
@@ -29,8 +29,8 @@
* by Erik Andersen <andersen@codepoet.org>
*/
-.global strncmp
-.set strncmp,__strncmp
+#include <features.h>
+
.text
.global __strncmp
.hidden __strncmp
@@ -57,3 +57,5 @@ __strncmp:
mov pc, lr
.size __strncmp,.-__strncmp
+
+strong_alias(__strncmp,strncmp)
diff --git a/libc/string/basename.c b/libc/string/basename.c
new file mode 100644
index 000000000..403cd770b
--- /dev/null
+++ b/libc/string/basename.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+
+char attribute_hidden *__basename(const char *path)
+{
+ register const char *s;
+ register const char *p;
+
+ p = s = path;
+
+ while (*s) {
+ if (*s++ == '/') {
+ p = s;
+ }
+ }
+
+ return (char *) p;
+}
+
+strong_alias(__basename,basename)
diff --git a/libc/string/bcopy.c b/libc/string/bcopy.c
new file mode 100644
index 000000000..59e586b34
--- /dev/null
+++ b/libc/string/bcopy.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+
+void attribute_hidden __bcopy(const void *s2, void *s1, size_t n)
+{
+#if 1
+ __memmove(s1, s2, n);
+#else
+#ifdef __BCC__
+ register char *s;
+ register const char *p;
+
+ s = s1;
+ p = s2;
+ if (p >= s) {
+ while (n--) {
+ *s++ = *p++;
+ }
+ } else {
+ s += n;
+ p += n;
+ while (n--) {
+ *--s = *--p;
+ }
+ }
+#else
+ register char *s;
+ register const char *p;
+
+ s = s1;
+ p = s2;
+ if (p >= s) {
+ while (n) {
+ *s++ = *p++;
+ --n;
+ }
+ } else {
+ while (n) {
+ --n;
+ s[n] = p[n];
+ }
+ }
+#endif
+#endif
+}
+
+strong_alias(__bcopy,bcopy)
diff --git a/libc/string/bzero.c b/libc/string/bzero.c
new file mode 100644
index 000000000..0439e39a1
--- /dev/null
+++ b/libc/string/bzero.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+
+void attribute_hidden __bzero(void *s, size_t n)
+{
+#if 1
+ (void)__memset(s, 0, n);
+#else
+ register unsigned char *p = s;
+#ifdef __BCC__
+ /* bcc can optimize the counter if it thinks it is a pointer... */
+ register const char *np = (const char *) n;
+#else
+#define np n
+#endif
+
+ while (np) {
+ *p++ = 0;
+ --np;
+ }
+#endif
+}
+#undef np
+
+strong_alias(__bzero,bzero)
diff --git a/libc/string/dirname.c b/libc/string/dirname.c
new file mode 100644
index 000000000..a6242e238
--- /dev/null
+++ b/libc/string/dirname.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+
+char *dirname(char *path)
+{
+ static const char null_or_empty_or_noslash[] = ".";
+ register char *s;
+ register char *last;
+ char *first;
+
+ last = s = path;
+
+ if (s != NULL) {
+
+ LOOP:
+ while (*s && (*s != '/')) ++s;
+ first = s;
+ while (*s == '/') ++s;
+ if (*s) {
+ last = first;
+ goto LOOP;
+ }
+
+ if (last == path) {
+ if (*last != '/') {
+ goto DOT;
+ }
+ if ((*++last == '/') && (last[1] == 0)) {
+ ++last;
+ }
+ }
+ *last = 0;
+ return path;
+ }
+ DOT:
+ return (char *) null_or_empty_or_noslash;
+}
diff --git a/libc/string/ffs.c b/libc/string/ffs.c
new file mode 100644
index 000000000..fc76e6c70
--- /dev/null
+++ b/libc/string/ffs.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+/* ffsl,ffsll */
+
+#include "_string.h"
+
+int attribute_hidden __ffs(int i)
+{
+#if 1
+ /* inlined binary search method */
+ char n = 1;
+#if UINT_MAX == 0xffffU
+ /* nothing to do here -- just trying to avoiding possible problems */
+#elif UINT_MAX == 0xffffffffU
+ if (!(i & 0xffff)) {
+ n += 16;
+ i >>= 16;
+ }
+#else
+#error ffs needs rewriting!
+#endif
+
+ if (!(i & 0xff)) {
+ n += 8;
+ i >>= 8;
+ }
+ if (!(i & 0x0f)) {
+ n += 4;
+ i >>= 4;
+ }
+ if (!(i & 0x03)) {
+ n += 2;
+ i >>= 2;
+ }
+ return (i) ? (n + ((i+1) & 0x01)) : 0;
+
+#else
+ /* linear search -- slow, but small */
+ int n;
+
+ for (n = 0 ; i ; ++n) {
+ i >>= 1;
+ }
+
+ return n;
+#endif
+}
+
+strong_alias(__ffs,ffs)
diff --git a/libc/string/frv/memcpy.S b/libc/string/frv/memcpy.S
index 1ffc7c398..abd8a28db 100644
--- a/libc/string/frv/memcpy.S
+++ b/libc/string/frv/memcpy.S
@@ -18,6 +18,7 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <features.h>
.text
.p2align 4
@@ -30,8 +31,6 @@
# to caller's fixup routine, aborting the remainder of the copy
#
###############################################################################
- .globl memcpy
- .set memcpy,__memcpy
.globl __memcpy
.hidden __memcpy
.type __memcpy,@function
@@ -125,3 +124,5 @@ memcpy_32:
bralr
.size __memcpy, .-__memcpy
+
+strong_alias(__memcpy,memcpy)
diff --git a/libc/string/frv/memset.S b/libc/string/frv/memset.S
index 62e705a44..a548b3779 100644
--- a/libc/string/frv/memset.S
+++ b/libc/string/frv/memset.S
@@ -18,6 +18,7 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <features.h>
.text
.p2align 4
@@ -31,8 +32,6 @@
# GR4, GR7, GR8, and GR11 must be managed
#
###############################################################################
- .globl memset
- .set memset,__memset
.globl __memset
.hidden __memset
.type __memset,@function
@@ -156,3 +155,5 @@ __memset:
cstb.p gr12,@(gr4,gr0) ,cc7,#1
bralr
.size __memset, .-__memset
+
+strong_alias(__memset,memset)
diff --git a/libc/string/generic/memchr.c b/libc/string/generic/memchr.c
index bc0623f3f..68c820814 100644
--- a/libc/string/generic/memchr.c
+++ b/libc/string/generic/memchr.c
@@ -29,8 +29,6 @@
#define LONG_MAX_32_BITS 2147483647
-#undef memchr
-
/* Search no more than N bytes of S for C. */
void attribute_hidden *__memchr (const void * s, int c_in, size_t n)
{
@@ -174,4 +172,4 @@ void attribute_hidden *__memchr (const void * s, int c_in, size_t n)
return 0;
}
-strong_alias(__memchr, memchr)
+strong_alias(__memchr,memchr)
diff --git a/libc/string/generic/memcmp.c b/libc/string/generic/memcmp.c
index a3fcba036..13e11692a 100644
--- a/libc/string/generic/memcmp.c
+++ b/libc/string/generic/memcmp.c
@@ -20,8 +20,6 @@
#include <string.h>
-#undef memcmp
-
#include "memcopy.h"
#include <endian.h>
@@ -332,6 +330,6 @@ attribute_hidden __memcmp (const __ptr_t s1, const __ptr_t s2, size_t len)
return 0;
}
-strong_alias(__memcmp, memcmp)
+strong_alias(__memcmp,memcmp)
-weak_alias(memcmp, bcmp)
+strong_alias(__memcmp,bcmp)
diff --git a/libc/string/generic/memcpy.c b/libc/string/generic/memcpy.c
index 2fb48ebef..6db4d0d44 100644
--- a/libc/string/generic/memcpy.c
+++ b/libc/string/generic/memcpy.c
@@ -23,8 +23,6 @@
#include "memcopy.h"
#include "pagecopy.h"
-#undef memcpy
-
/* _wordcopy_fwd_aligned -- Copy block beginning at SRCP to
block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
Both SRCP and DSTP should be aligned for memory operations on `op_t's. */
@@ -245,4 +243,4 @@ void attribute_hidden *__memcpy (void *dstpp, const void *srcpp, size_t len)
return dstpp;
}
-strong_alias(__memcpy, memcpy)
+strong_alias(__memcpy,memcpy)
diff --git a/libc/string/generic/memmem.c b/libc/string/generic/memmem.c
index 05d7de639..0353759e3 100644
--- a/libc/string/generic/memmem.c
+++ b/libc/string/generic/memmem.c
@@ -19,8 +19,6 @@
#include <string.h>
#include <stddef.h>
-#undef memmem
-
/* Return the first occurrence of NEEDLE in HAYSTACK. */
void attribute_hidden *__memmem (const void *haystack, size_t haystack_len,
const void *needle, size_t needle_len)
@@ -49,4 +47,4 @@ void attribute_hidden *__memmem (const void *haystack, size_t haystack_len,
return NULL;
}
-strong_alias(__memmem, memmem)
+strong_alias(__memmem,memmem)
diff --git a/libc/string/generic/memmove.c b/libc/string/generic/memmove.c
index 0e649a1a9..e34b0005d 100644
--- a/libc/string/generic/memmove.c
+++ b/libc/string/generic/memmove.c
@@ -206,8 +206,6 @@ static void _wordcopy_bwd_dest_aligned (long int dstp, long int srcp, size_t len
((op_t *) dstp)[3] = MERGE (a0, sh_1, a1, sh_2);
}
-#undef memmove
-
void attribute_hidden *__memmove (void *dest, const void *src, size_t len)
{
unsigned long int dstp = (long int) dest;
@@ -279,4 +277,4 @@ void attribute_hidden *__memmove (void *dest, const void *src, size_t len)
return (dest);
}
-strong_alias(__memmove, memmove)
+strong_alias(__memmove,memmove)
diff --git a/libc/string/generic/mempcpy.c b/libc/string/generic/mempcpy.c
index f2c860107..d121967cd 100644
--- a/libc/string/generic/mempcpy.c
+++ b/libc/string/generic/mempcpy.c
@@ -7,8 +7,6 @@
#include <string.h>
-#undef mempcpy
-
void attribute_hidden *__mempcpy (void *dstpp, const void *srcpp, size_t len)
{
__memcpy(dstpp, srcpp, len);
diff --git a/libc/string/generic/memrchr.c b/libc/string/generic/memrchr.c
index 3f7583919..d27ae03ef 100644
--- a/libc/string/generic/memrchr.c
+++ b/libc/string/generic/memrchr.c
@@ -30,8 +30,6 @@
#define LONG_MAX_32_BITS 2147483647
-#undef memrchr
-
/* Search no more than N bytes of S for C. */
void attribute_hidden *__memrchr (const void * s, int c_in, size_t n)
{
@@ -173,4 +171,4 @@ void attribute_hidden *__memrchr (const void * s, int c_in, size_t n)
return 0;
}
-strong_alias(__memrchr, memrchr)
+strong_alias(__memrchr,memrchr)
diff --git a/libc/string/generic/memset.c b/libc/string/generic/memset.c
index 0185ad57b..91401d7ee 100644
--- a/libc/string/generic/memset.c
+++ b/libc/string/generic/memset.c
@@ -19,8 +19,6 @@
#include <string.h>
#include "memcopy.h"
-#undef memset
-
void attribute_hidden *__memset (void *dstpp, int c, size_t len)
{
long int dstp = (long int) dstpp;
@@ -85,4 +83,4 @@ void attribute_hidden *__memset (void *dstpp, int c, size_t len)
return dstpp;
}
-strong_alias(__memset, memset)
+strong_alias(__memset,memset)
diff --git a/libc/string/generic/rawmemchr.c b/libc/string/generic/rawmemchr.c
index 02cb8f629..d1be620eb 100644
--- a/libc/string/generic/rawmemchr.c
+++ b/libc/string/generic/rawmemchr.c
@@ -29,8 +29,6 @@
#define LONG_MAX_32_BITS 2147483647
-#undef rawmemchr
-
/* Find the first occurrence of C in S. */
void attribute_hidden *__rawmemchr (const void * s, int c_in)
{
@@ -159,4 +157,4 @@ void attribute_hidden *__rawmemchr (const void * s, int c_in)
}
}
-strong_alias(__rawmemchr, rawmemchr)
+strong_alias(__rawmemchr,rawmemchr)
diff --git a/libc/string/generic/strcat.c b/libc/string/generic/strcat.c
index 0996f9a29..96412acc5 100644
--- a/libc/string/generic/strcat.c
+++ b/libc/string/generic/strcat.c
@@ -19,8 +19,6 @@
#include <string.h>
#include "memcopy.h"
-#undef strcat
-
/* Append SRC on the end of DEST. */
char attribute_hidden *__strcat (char *dest, const char *src)
{
@@ -47,4 +45,4 @@ char attribute_hidden *__strcat (char *dest, const char *src)
return dest;
}
-strong_alias(__strcat, strcat)
+strong_alias(__strcat,strcat)
diff --git a/libc/string/generic/strchr.c b/libc/string/generic/strchr.c
index c776380e2..dcb30ad7b 100644
--- a/libc/string/generic/strchr.c
+++ b/libc/string/generic/strchr.c
@@ -26,8 +26,6 @@
#include "memcopy.h"
-#undef strchr
-
/* Find the first occurrence of C in S. */
char attribute_hidden *__strchr (const char *s, int c_in)
{
@@ -181,6 +179,6 @@ char attribute_hidden *__strchr (const char *s, int c_in)
return NULL;
}
-strong_alias(__strchr, strchr)
+strong_alias(__strchr,strchr)
-weak_alias(strchr, index)
+strong_alias(__strchr,index)
diff --git a/libc/string/generic/strchrnul.c b/libc/string/generic/strchrnul.c
index faa0f4ff9..a2aafbfb0 100644
--- a/libc/string/generic/strchrnul.c
+++ b/libc/string/generic/strchrnul.c
@@ -26,8 +26,6 @@
#include "memcopy.h"
-#undef strchrnul
-
/* Find the first occurrence of C in S or the final NUL byte. */
char attribute_hidden *__strchrnul (const char *s, int c_in)
{
@@ -164,4 +162,4 @@ char attribute_hidden *__strchrnul (const char *s, int c_in)
return NULL;
}
-strong_alias(__strchrnul, strchrnul)
+strong_alias(__strchrnul,strchrnul)
diff --git a/libc/string/generic/strcmp.c b/libc/string/generic/strcmp.c
index f12424243..209aeed15 100644
--- a/libc/string/generic/strcmp.c
+++ b/libc/string/generic/strcmp.c
@@ -17,12 +17,9 @@
02111-1307 USA. */
#include <string.h>
-#include <locale.h>
#include "memcopy.h"
-#undef strcmp
-
/* Compare S1 and S2, returning less than, equal to or
greater than zero if S1 is lexicographically less than,
equal to or greater than S2. */
@@ -44,9 +41,9 @@ int attribute_hidden __strcmp (const char *p1, const char *p2)
return c1 - c2;
}
-strong_alias(__strcmp, strcmp)
+strong_alias(__strcmp,strcmp)
-#ifdef __LOCALE_C_ONLY
-hidden_strong_alias(__strcmp, __strcoll)
-strong_alias(__strcmp, strcoll)
-#endif /* __LOCALE_C_ONLY */
+#ifndef __UCLIBC_HAS_LOCALE__
+hidden_strong_alias(__strcmp,__strcoll)
+strong_alias(__strcmp,strcoll)
+#endif
diff --git a/libc/string/generic/strcpy.c b/libc/string/generic/strcpy.c
index 08c810f31..9280d3561 100644
--- a/libc/string/generic/strcpy.c
+++ b/libc/string/generic/strcpy.c
@@ -22,8 +22,6 @@
#include "memcopy.h"
#include "bp-checks.h"
-#undef strcpy
-
/* Copy SRC to DEST. */
char attribute_hidden *__strcpy (char *dest, const char *src)
{
@@ -46,4 +44,4 @@ char attribute_hidden *__strcpy (char *dest, const char *src)
return dest;
}
-strong_alias(__strcpy, strcpy)
+strong_alias(__strcpy,strcpy)
diff --git a/libc/string/generic/strcspn.c b/libc/string/generic/strcspn.c
index a10912e25..a06577bca 100644
--- a/libc/string/generic/strcspn.c
+++ b/libc/string/generic/strcspn.c
@@ -18,8 +18,6 @@
#include <string.h>
-#undef strcspn
-
/* Return the length of the maximum initial segment of S
which contains no characters from REJECT. */
size_t attribute_hidden __strcspn (const char *s, const char *reject)
@@ -35,4 +33,4 @@ size_t attribute_hidden __strcspn (const char *s, const char *reject)
return count;
}
-strong_alias(__strcspn, strcspn)
+strong_alias(__strcspn,strcspn)
diff --git a/libc/string/generic/strlen.c b/libc/string/generic/strlen.c
index aca8c2bd9..6c1b5eae3 100644
--- a/libc/string/generic/strlen.c
+++ b/libc/string/generic/strlen.c
@@ -22,8 +22,6 @@
#include <string.h>
#include <stdlib.h>
-#undef strlen
-
/* Return the length of the null-terminated string STR. Scan for
the null terminator quickly by testing four bytes at a time. */
size_t attribute_hidden __strlen (const char *str)
@@ -149,4 +147,4 @@ size_t attribute_hidden __strlen (const char *str)
}
}
-strong_alias(__strlen, strlen)
+strong_alias(__strlen,strlen)
diff --git a/libc/string/generic/strncat.c b/libc/string/generic/strncat.c
index f35e0865b..5ece4d248 100644
--- a/libc/string/generic/strncat.c
+++ b/libc/string/generic/strncat.c
@@ -20,8 +20,6 @@
#include "memcopy.h"
-#undef strncat
-
char attribute_hidden *__strncat (char *s1, const char *s2, size_t n)
{
reg_char c;
@@ -76,4 +74,4 @@ char attribute_hidden *__strncat (char *s1, const char *s2, size_t n)
return s;
}
-strong_alias(__strncat, strncat)
+strong_alias(__strncat,strncat)
diff --git a/libc/string/generic/strncmp.c b/libc/string/generic/strncmp.c
index 22aa179b0..849726f6b 100644
--- a/libc/string/generic/strncmp.c
+++ b/libc/string/generic/strncmp.c
@@ -19,8 +19,6 @@
#include <string.h>
#include "memcopy.h"
-#undef strncmp
-
/* Compare no more than N characters of S1 and S2,
returning less than, equal to or greater than zero
if S1 is lexicographically less than, equal to or
@@ -67,4 +65,4 @@ int attribute_hidden __strncmp (const char *s1, const char *s2, size_t n)
return c1 - c2;
}
-strong_alias(__strncmp, strncmp)
+strong_alias(__strncmp,strncmp)
diff --git a/libc/string/generic/strncpy.c b/libc/string/generic/strncpy.c
index a43c48502..ca4f59e52 100644
--- a/libc/string/generic/strncpy.c
+++ b/libc/string/generic/strncpy.c
@@ -19,8 +19,6 @@
#include <string.h>
#include "memcopy.h"
-#undef strncpy
-
char attribute_hidden *__strncpy (char *s1, const char *s2, size_t n)
{
reg_char c;
@@ -81,4 +79,4 @@ char attribute_hidden *__strncpy (char *s1, const char *s2, size_t n)
return s;
}
-strong_alias(__strncpy, strncpy)
+strong_alias(__strncpy,strncpy)
diff --git a/libc/string/generic/strnlen.c b/libc/string/generic/strnlen.c
index ff5c13739..4b96dde31 100644
--- a/libc/string/generic/strnlen.c
+++ b/libc/string/generic/strnlen.c
@@ -24,8 +24,6 @@
#include <string.h>
#include <stdlib.h>
-#undef strnlen
-
/* Find the length of S, but scan at most MAXLEN characters. If no
'\0' terminator is found in that many characters, return MAXLEN. */
size_t attribute_hidden __strnlen (const char *str, size_t maxlen)
@@ -159,4 +157,4 @@ size_t attribute_hidden __strnlen (const char *str, size_t maxlen)
return char_ptr - str;
}
-strong_alias(__strnlen, strnlen)
+strong_alias(__strnlen,strnlen)
diff --git a/libc/string/generic/strrchr.c b/libc/string/generic/strrchr.c
index 325be7d48..529016ede 100644
--- a/libc/string/generic/strrchr.c
+++ b/libc/string/generic/strrchr.c
@@ -18,8 +18,6 @@
#include <string.h>
-#undef strrchr
-
/* Find the last occurrence of C in S. */
char attribute_hidden *__strrchr (const char *s, int c)
{
@@ -42,6 +40,6 @@ char attribute_hidden *__strrchr (const char *s, int c)
return (char *) found;
}
-strong_alias(__strrchr, strrchr)
+strong_alias(__strrchr,strrchr)
-weak_alias (strrchr, rindex)
+strong_alias (__strrchr,rindex)
diff --git a/libc/string/generic/strsep.c b/libc/string/generic/strsep.c
index 9515fa193..762b07ff9 100644
--- a/libc/string/generic/strsep.c
+++ b/libc/string/generic/strsep.c
@@ -20,8 +20,6 @@
#include <string.h>
-#undef strsep
-
char attribute_hidden *__strsep (char **stringp, const char *delim)
{
char *begin, *end;
@@ -66,4 +64,4 @@ char attribute_hidden *__strsep (char **stringp, const char *delim)
return begin;
}
-strong_alias(__strsep, strsep)
+strong_alias(__strsep,strsep)
diff --git a/libc/string/generic/strspn.c b/libc/string/generic/strspn.c
index 1923f8afd..129c58742 100644
--- a/libc/string/generic/strspn.c
+++ b/libc/string/generic/strspn.c
@@ -18,8 +18,6 @@
#include <string.h>
-#undef strspn
-
/* Return the length of the maximum initial segment
of S which contains only characters in ACCEPT. */
size_t attribute_hidden __strspn (const char *s, const char *accept)
@@ -42,4 +40,4 @@ size_t attribute_hidden __strspn (const char *s, const char *accept)
return count;
}
-strong_alias(__strspn, strspn)
+strong_alias(__strspn,strspn)
diff --git a/libc/string/generic/strstr.c b/libc/string/generic/strstr.c
index b16261e56..12e384014 100644
--- a/libc/string/generic/strstr.c
+++ b/libc/string/generic/strstr.c
@@ -30,8 +30,6 @@
typedef unsigned chartype;
-#undef strstr
-
char attribute_hidden *__strstr (const char *phaystack, const char *pneedle)
{
const unsigned char *haystack, *needle;
@@ -112,4 +110,4 @@ ret0:
return 0;
}
-strong_alias(__strstr, strstr)
+strong_alias(__strstr,strstr)
diff --git a/libc/string/generic/strtok_r.c b/libc/string/generic/strtok_r.c
index 56eb64bb9..1a11166dd 100644
--- a/libc/string/generic/strtok_r.c
+++ b/libc/string/generic/strtok_r.c
@@ -17,15 +17,9 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#define rawmemchr __rawmemchr
-#define strspn __strspn
-#define strpbrk __strpbrk
-
#define _GNU_SOURCE
#include <string.h>
-#undef strtok_r
-
/* Parse S into tokens separated by characters in DELIM.
If S is NULL, the saved pointer in SAVE_PTR is used as
the next starting point. For example:
@@ -44,7 +38,7 @@ char attribute_hidden *__strtok_r (char *s, const char *delim, char **save_ptr)
s = *save_ptr;
/* Scan leading delimiters. */
- s += strspn (s, delim);
+ s += __strspn (s, delim);
if (*s == '\0')
{
*save_ptr = s;
@@ -53,10 +47,10 @@ char attribute_hidden *__strtok_r (char *s, const char *delim, char **save_ptr)
/* Find the end of the token. */
token = s;
- s = strpbrk (token, delim);
+ s = __strpbrk (token, delim);
if (s == NULL)
/* This token finishes the string. */
- *save_ptr = rawmemchr (token, '\0');
+ *save_ptr = __rawmemchr (token, '\0');
else
{
/* Terminate the token and make *SAVE_PTR point past it. */
@@ -66,4 +60,4 @@ char attribute_hidden *__strtok_r (char *s, const char *delim, char **save_ptr)
return token;
}
-strong_alias(__strtok_r, strtok_r)
+strong_alias(__strtok_r,strtok_r)
diff --git a/libc/string/i386/memchr.c b/libc/string/i386/memchr.c
index 5994a4b67..c7cd33758 100644
--- a/libc/string/i386/memchr.c
+++ b/libc/string/i386/memchr.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef memchr
void attribute_hidden *__memchr(const void *cs, int c, size_t count)
{
int d0;
@@ -49,4 +48,4 @@ void attribute_hidden *__memchr(const void *cs, int c, size_t count)
return __res;
}
-strong_alias(__memchr, memchr)
+strong_alias(__memchr,memchr)
diff --git a/libc/string/i386/memcpy.c b/libc/string/i386/memcpy.c
index 1cd234685..12ba8d7de 100644
--- a/libc/string/i386/memcpy.c
+++ b/libc/string/i386/memcpy.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef memcpy
void attribute_hidden *__memcpy(void * to, const void * from, size_t n)
{
int d0, d1, d2;
@@ -51,4 +50,4 @@ void attribute_hidden *__memcpy(void * to, const void * from, size_t n)
return (to);
}
-strong_alias(__memcpy, memcpy)
+strong_alias(__memcpy,memcpy)
diff --git a/libc/string/i386/memmove.c b/libc/string/i386/memmove.c
index 4bc5f3e42..d6e29e553 100644
--- a/libc/string/i386/memmove.c
+++ b/libc/string/i386/memmove.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef memmove
void attribute_hidden *__memmove(void *dest, const void *src, size_t n)
{
int d0, d1, d2;
@@ -57,4 +56,4 @@ void attribute_hidden *__memmove(void *dest, const void *src, size_t n)
return dest;
}
-strong_alias(__memmove, memmove)
+strong_alias(__memmove,memmove)
diff --git a/libc/string/i386/memset.c b/libc/string/i386/memset.c
index 0fd9e2019..eadbf9feb 100644
--- a/libc/string/i386/memset.c
+++ b/libc/string/i386/memset.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef memset
void attribute_hidden *__memset(void *s, int c, size_t count)
{
int d0, d1;
@@ -45,4 +44,4 @@ void attribute_hidden *__memset(void *s, int c, size_t count)
return s;
}
-strong_alias(__memset, memset)
+strong_alias(__memset,memset)
diff --git a/libc/string/i386/strcat.c b/libc/string/i386/strcat.c
index eb3c81ec1..02b2a3c5b 100644
--- a/libc/string/i386/strcat.c
+++ b/libc/string/i386/strcat.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef strcat
char attribute_hidden *__strcat(char * dest, const char * src)
{
int d0, d1, d2, d3;
@@ -49,4 +48,4 @@ char attribute_hidden *__strcat(char * dest, const char * src)
return dest;
}
-strong_alias(__strcat, strcat)
+strong_alias(__strcat,strcat)
diff --git a/libc/string/i386/strchr.c b/libc/string/i386/strchr.c
index 5fe689d1a..a8343fa00 100644
--- a/libc/string/i386/strchr.c
+++ b/libc/string/i386/strchr.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef strchr
char attribute_hidden *__strchr(const char *s, int c)
{
int d0;
@@ -51,6 +50,6 @@ char attribute_hidden *__strchr(const char *s, int c)
return __res;
}
-strong_alias(__strchr, strchr)
+strong_alias(__strchr,strchr)
-weak_alias(strchr, index)
+strong_alias(__strchr,index)
diff --git a/libc/string/i386/strcmp.c b/libc/string/i386/strcmp.c
index 3786d5983..f335da646 100644
--- a/libc/string/i386/strcmp.c
+++ b/libc/string/i386/strcmp.c
@@ -31,9 +31,7 @@
*/
#include <string.h>
-#include <locale.h> /* for __LOCALE_C_ONLY */
-#undef strcmp
int attribute_hidden __strcmp(const char *cs, const char *ct)
{
int d0, d1;
@@ -54,9 +52,9 @@ int attribute_hidden __strcmp(const char *cs, const char *ct)
return __res;
}
-strong_alias(__strcmp, strcmp)
+strong_alias(__strcmp,strcmp)
-#ifdef __LOCALE_C_ONLY
-hidden_strong_alias(__strcmp, __strcoll)
-strong_alias(__strcmp, strcoll)
-#endif /* __LOCALE_C_ONLY */
+#ifndef __UCLIBC_HAS_LOCALE__
+hidden_strong_alias(__strcmp,__strcoll)
+strong_alias(__strcmp,strcoll)
+#endif
diff --git a/libc/string/i386/strcpy.c b/libc/string/i386/strcpy.c
index 1b9bcfded..59effd45e 100644
--- a/libc/string/i386/strcpy.c
+++ b/libc/string/i386/strcpy.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef strcpy
char attribute_hidden *__strcpy(char * dest, const char * src)
{
int d0, d1, d2;
@@ -46,4 +45,4 @@ char attribute_hidden *__strcpy(char * dest, const char * src)
return dest;
}
-strong_alias(__strcpy, strcpy)
+strong_alias(__strcpy,strcpy)
diff --git a/libc/string/i386/strlen.c b/libc/string/i386/strlen.c
index 859d0928c..01cc46f9e 100644
--- a/libc/string/i386/strlen.c
+++ b/libc/string/i386/strlen.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef strlen
size_t attribute_hidden __strlen(const char *s)
{
int d0;
@@ -46,4 +45,4 @@ size_t attribute_hidden __strlen(const char *s)
return __res;
}
-strong_alias(__strlen, strlen)
+strong_alias(__strlen,strlen)
diff --git a/libc/string/i386/strncat.c b/libc/string/i386/strncat.c
index b57568166..b55b87b59 100644
--- a/libc/string/i386/strncat.c
+++ b/libc/string/i386/strncat.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef strncat
char attribute_hidden *__strncat(char * dest,
const char * src, size_t count)
{
@@ -59,4 +58,4 @@ char attribute_hidden *__strncat(char * dest,
return dest;
}
-strong_alias(__strncat, strncat)
+strong_alias(__strncat,strncat)
diff --git a/libc/string/i386/strncmp.c b/libc/string/i386/strncmp.c
index 825980d4d..2e22bf642 100644
--- a/libc/string/i386/strncmp.c
+++ b/libc/string/i386/strncmp.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef strncmp
int attribute_hidden __strncmp(const char *cs, const char *ct, size_t count)
{
register int __res;
@@ -56,4 +55,4 @@ int attribute_hidden __strncmp(const char *cs, const char *ct, size_t count)
return __res;
}
-strong_alias(__strncmp, strncmp)
+strong_alias(__strncmp,strncmp)
diff --git a/libc/string/i386/strncpy.c b/libc/string/i386/strncpy.c
index db135ee4a..272c60ee4 100644
--- a/libc/string/i386/strncpy.c
+++ b/libc/string/i386/strncpy.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef strncpy
char attribute_hidden *__strncpy(char * dest, const char * src, size_t count)
{
int d0, d1, d2, d3;
@@ -54,4 +53,4 @@ char attribute_hidden *__strncpy(char * dest, const char * src, size_t count)
return dest;
}
-strong_alias(__strncpy, strncpy)
+strong_alias(__strncpy,strncpy)
diff --git a/libc/string/i386/strnlen.c b/libc/string/i386/strnlen.c
index 4fceedf51..ef5c83a9a 100644
--- a/libc/string/i386/strnlen.c
+++ b/libc/string/i386/strnlen.c
@@ -33,7 +33,6 @@
#define _GNU_SOURCE
#include <string.h>
-#undef strnlen
size_t attribute_hidden __strnlen(const char *s, size_t count)
{
int d0;
@@ -53,4 +52,4 @@ size_t attribute_hidden __strnlen(const char *s, size_t count)
return __res;
}
-strong_alias(__strnlen, strnlen)
+strong_alias(__strnlen,strnlen)
diff --git a/libc/string/i386/strrchr.c b/libc/string/i386/strrchr.c
index 8468ee511..9f0f65a36 100644
--- a/libc/string/i386/strrchr.c
+++ b/libc/string/i386/strrchr.c
@@ -32,7 +32,6 @@
#include <string.h>
-#undef strrchr
char attribute_hidden *__strrchr(const char *s, int c)
{
int d0, d1;
@@ -49,6 +48,6 @@ char attribute_hidden *__strrchr(const char *s, int c)
return __res;
}
-strong_alias(__strrchr, strrchr)
+strong_alias(__strrchr,strrchr)
-weak_alias(strrchr, rindex)
+strong_alias(__strrchr,rindex)
diff --git a/libc/string/memccpy.c b/libc/string/memccpy.c
new file mode 100644
index 000000000..81d20b19c
--- /dev/null
+++ b/libc/string/memccpy.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+/* No wide analog. */
+
+#include "_string.h"
+
+void attribute_hidden *__memccpy(void * __restrict s1, const void * __restrict s2, int c, size_t n)
+{
+ register char *r1 = s1;
+ register const char *r2 = s2;
+
+ while (n-- && (((unsigned char)(*r1++ = *r2++)) != ((unsigned char) c)));
+
+ return (n == (size_t) -1) ? NULL : r1;
+}
+
+strong_alias(__memccpy,memccpy)
diff --git a/libc/string/memchr.c b/libc/string/memchr.c
index d0aa004d7..288bd9748 100644
--- a/libc/string/memchr.c
+++ b/libc/string/memchr.c
@@ -1,14 +1,40 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_memchr
-#define Wmemchr __memchr
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wmemchr __wmemchr
+# define Wmemchr wmemchr
+#else
+# define __Wmemchr __memchr
+# define Wmemchr memchr
+#endif
-strong_alias(__memchr, memchr)
+Wvoid attribute_hidden *__Wmemchr(const Wvoid *s, Wint c, size_t n)
+{
+ register const Wuchar *r = (const Wuchar *) s;
+#ifdef __BCC__
+ /* bcc can optimize the counter if it thinks it is a pointer... */
+ register const char *np = (const char *) n;
+#else
+# define np n
+#endif
-#undef L_memchr
+ while (np) {
+ if (*r == ((Wuchar)c)) {
+ return (Wvoid *) r; /* silence the warning */
+ }
+ ++r;
+ --np;
+ }
+
+ return NULL;
+}
+#undef np
+
+strong_alias(__Wmemchr,Wmemchr)
diff --git a/libc/string/memcmp.c b/libc/string/memcmp.c
index 5963dd174..9808b3785 100644
--- a/libc/string/memcmp.c
+++ b/libc/string/memcmp.c
@@ -1,16 +1,43 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_memcmp
-#define Wmemcmp __memcmp
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wmemcmp __wmemcmp
+# define Wmemcmp wmemcmp
+#else
+# define __Wmemcmp __memcmp
+# define Wmemcmp memcmp
+#endif
-strong_alias(__memcmp, memcmp)
+int attribute_hidden __Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n)
+{
+ register const Wuchar *r1 = (const Wuchar *) s1;
+ register const Wuchar *r2 = (const Wuchar *) s2;
-weak_alias(memcmp, bcmp)
+#ifdef WANT_WIDE
+ while (n && (*r1 == *r2)) {
+ ++r1;
+ ++r2;
+ --n;
+ }
-#undef L_memcmp
+ return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);
+#else
+ int r = 0;
+
+ while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0));
+
+ return r;
+#endif
+}
+
+strong_alias(__Wmemcmp,Wmemcmp)
+#ifndef WANT_WIDE
+strong_alias(__memcmp,bcmp)
+#endif
diff --git a/libc/string/memcpy.c b/libc/string/memcpy.c
index 6889271ae..abfe1b4ef 100644
--- a/libc/string/memcpy.c
+++ b/libc/string/memcpy.c
@@ -1,14 +1,37 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_memcpy
-#define Wmemcpy __memcpy
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wmemcpy __wmemcpy
+# define Wmemcpy wmemcpy
+#else
+# define __Wmemcpy __memcpy
+# define Wmemcpy memcpy
+#endif
-strong_alias(__memcpy, memcpy)
+Wvoid attribute_hidden *__Wmemcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
+{
+ register Wchar *r1 = s1;
+ register const Wchar *r2 = s2;
-#undef L_memcpy
+#ifdef __BCC__
+ while (n--) {
+ *r1++ = *r2++;
+ }
+#else
+ while (n) {
+ *r1++ = *r2++;
+ --n;
+ }
+#endif
+
+ return s1;
+}
+
+strong_alias(__Wmemcpy,Wmemcpy)
diff --git a/libc/string/memmem.c b/libc/string/memmem.c
new file mode 100644
index 000000000..a42176181
--- /dev/null
+++ b/libc/string/memmem.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+
+void attribute_hidden *__memmem(const void *haystack, size_t haystacklen,
+ const void *needle, size_t needlelen)
+{
+ register const char *ph;
+ register const char *pn;
+ const char *plast;
+ size_t n;
+
+ if (needlelen == 0) {
+ return (void *) haystack;
+ }
+
+ if (haystacklen >= needlelen) {
+ ph = (const char *) haystack;
+ pn = (const char *) needle;
+ plast = ph + (haystacklen - needlelen);
+
+ do {
+ n = 0;
+ while (ph[n] == pn[n]) {
+ if (++n == needlelen) {
+ return (void *) ph;
+ }
+ }
+ } while (++ph <= plast);
+ }
+
+ return NULL;
+}
+
+strong_alias(__memmem,memmem)
diff --git a/libc/string/memmove.c b/libc/string/memmove.c
index 0626ce1f5..9e50cf5a9 100644
--- a/libc/string/memmove.c
+++ b/libc/string/memmove.c
@@ -1,14 +1,57 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_memmove
-#define Wmemmove __memmove
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wmemmove __wmemmove
+# define Wmemmove wmemmove
+#else
+# define __Wmemmove __memmove
+# define Wmemmove memmove
+#endif
-strong_alias(__memmove, memmove)
+Wvoid attribute_hidden *__Wmemmove(Wvoid *s1, const Wvoid *s2, size_t n)
+{
+#ifdef __BCC__
+ register Wchar *s = (Wchar *) s1;
+ register const Wchar *p = (const Wchar *) s2;
-#undef L_memmove
+ if (p >= s) {
+ while (n--) {
+ *s++ = *p++;
+ }
+ } else {
+ s += n;
+ p += n;
+ while (n--) {
+ *--s = *--p;
+ }
+ }
+
+ return s1;
+#else
+ register Wchar *s = (Wchar *) s1;
+ register const Wchar *p = (const Wchar *) s2;
+
+ if (p >= s) {
+ while (n) {
+ *s++ = *p++;
+ --n;
+ }
+ } else {
+ while (n) {
+ --n;
+ s[n] = p[n];
+ }
+ }
+
+ return s1;
+#endif
+}
+
+strong_alias(__Wmemmove,Wmemmove)
diff --git a/libc/string/mempcpy.c b/libc/string/mempcpy.c
index 9f7fab351..aed37d03a 100644
--- a/libc/string/mempcpy.c
+++ b/libc/string/mempcpy.c
@@ -1,14 +1,37 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_mempcpy
-#define Wmempcpy __mempcpy
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wmempcpy __wmempcpy
+# define Wmempcpy wmempcpy
+#else
+# define __Wmempcpy __mempcpy
+# define Wmempcpy mempcpy
+#endif
-strong_alias(__mempcpy,mempcpy)
+Wvoid attribute_hidden *__Wmempcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
+{
+ register Wchar *r1 = s1;
+ register const Wchar *r2 = s2;
-#undef L_mempcpy
+#ifdef __BCC__
+ while (n--) {
+ *r1++ = *r2++;
+ }
+#else
+ while (n) {
+ *r1++ = *r2++;
+ --n;
+ }
+#endif
+
+ return r1;
+}
+
+strong_alias(__Wmempcpy,Wmempcpy)
diff --git a/libc/string/memrchr.c b/libc/string/memrchr.c
new file mode 100644
index 000000000..fb696bc6d
--- /dev/null
+++ b/libc/string/memrchr.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+
+void attribute_hidden *__memrchr(const void *s, int c, size_t n)
+{
+ register const unsigned char *r;
+#ifdef __BCC__
+ /* bcc can optimize the counter if it thinks it is a pointer... */
+ register const char *np = (const char *) n;
+#else
+#define np n
+#endif
+
+ r = ((unsigned char *)s) + ((size_t) np);
+
+ while (np) {
+ if (*--r == ((unsigned char)c)) {
+ return (void *) r; /* silence the warning */
+ }
+ --np;
+ }
+
+ return NULL;
+}
+#undef np
+
+strong_alias(__memrchr,memrchr)
diff --git a/libc/string/memset.c b/libc/string/memset.c
index 8a5d69ce8..cb97dbce8 100644
--- a/libc/string/memset.c
+++ b/libc/string/memset.c
@@ -1,14 +1,37 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_memset
-#define Wmemset __memset
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wmemset __wmemset
+# define Wmemset wmemset
+#else
+# define __Wmemset __memset
+# define Wmemset memset
+#endif
-strong_alias(__memset, memset)
+Wvoid attribute_hidden *__Wmemset(Wvoid *s, Wint c, size_t n)
+{
+ register Wuchar *p = (Wuchar *) s;
+#ifdef __BCC__
+ /* bcc can optimize the counter if it thinks it is a pointer... */
+ register const char *np = (const char *) n;
+#else
+# define np n
+#endif
-#undef L_memset
+ while (np) {
+ *p++ = (Wuchar) c;
+ --np;
+ }
+
+ return s;
+}
+#undef np
+
+strong_alias(__Wmemset,Wmemset)
diff --git a/libc/string/mips/memcpy.S b/libc/string/mips/memcpy.S
index 369c82f39..2e42b1793 100644
--- a/libc/string/mips/memcpy.S
+++ b/libc/string/mips/memcpy.S
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <features.h>
/*#include <sysdep.h>*/
#include <endian.h>
#include "sysdep.h"
@@ -39,7 +40,7 @@
# define SWLO swl /* low part is left in little-endian */
#endif
-ENTRY (memcpy)
+ENTRY (__memcpy)
.set noreorder
slti t0, a2, 8 # Less than 8?
@@ -136,5 +137,6 @@ L(shfth):
move a2, t0
.set reorder
-END (memcpy)
-libc_hidden_builtin_def (memcpy)
+END (__memcpy)
+
+strong_alias(__memcpy,memcpy)
diff --git a/libc/string/mips/memset.S b/libc/string/mips/memset.S
index 0919fb82e..4269ebc6e 100644
--- a/libc/string/mips/memset.S
+++ b/libc/string/mips/memset.S
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <features.h>
/*#include <sysdep.h>*/
#include <endian.h>
#include "sysdep.h"
@@ -33,7 +34,7 @@
# define SWHI swr /* high part is right in little-endian */
#endif
-ENTRY (memset)
+ENTRY (__memset)
.set noreorder
slti t1, a2, 8 # Less than 8?
@@ -86,5 +87,6 @@ L(exit):
nop
.set reorder
-END (memset)
-libc_hidden_builtin_def (memset)
+END (__memset)
+
+strong_alias(__memset,memset)
diff --git a/libc/string/mips/sysdep.h b/libc/string/mips/sysdep.h
index 89674fef7..27518ac42 100644
--- a/libc/string/mips/sysdep.h
+++ b/libc/string/mips/sysdep.h
@@ -27,6 +27,7 @@
#define ENTRY(name) \
.globl name; \
+ .hidden name; \
.align 2; \
.ent name,0; \
name##:
@@ -42,10 +43,4 @@
# define L(label) .L ## label
#endif
-#ifdef libc_hidden_builtin_def
-#error "WHOA!!! libc_hidden_builtin_def is defined"
-#else
-#define libc_hidden_builtin_def(name) .global __ ## name ; __ ## name = name
-#endif
-
#endif
diff --git a/libc/string/powerpc/memcpy.c b/libc/string/powerpc/memcpy.c
index 34573b29f..5af96869b 100644
--- a/libc/string/powerpc/memcpy.c
+++ b/libc/string/powerpc/memcpy.c
@@ -21,7 +21,6 @@
#include <string.h>
-#undef memcpy
void attribute_hidden *__memcpy(void *to, const void *from, size_t n)
/* PPC can do pre increment and load/store, but not post increment and load/store.
Therefore use *++ptr instead of *ptr++. */
@@ -78,4 +77,4 @@ void attribute_hidden *__memcpy(void *to, const void *from, size_t n)
goto lessthan8;
}
-strong_alias(__memcpy, memcpy)
+strong_alias(__memcpy,memcpy)
diff --git a/libc/string/powerpc/memmove.c b/libc/string/powerpc/memmove.c
index b5b70c9fd..1d513a966 100644
--- a/libc/string/powerpc/memmove.c
+++ b/libc/string/powerpc/memmove.c
@@ -21,7 +21,6 @@
#include <string.h>
-#undef memmove
void attribute_hidden *__memmove(void *to, const void *from, size_t n)
{
unsigned long rem, chunks, tmp1, tmp2;
@@ -74,4 +73,4 @@ void attribute_hidden *__memmove(void *to, const void *from, size_t n)
goto lessthan8;
}
-strong_alias(__memmove, memmove)
+strong_alias(__memmove,memmove)
diff --git a/libc/string/powerpc/memset.c b/libc/string/powerpc/memset.c
index 372047797..f6cda9579 100644
--- a/libc/string/powerpc/memset.c
+++ b/libc/string/powerpc/memset.c
@@ -32,7 +32,6 @@ static inline int expand_byte_word(int c){
return c;
}
-#undef memset
void attribute_hidden *__memset(void *to, int c, size_t n)
{
unsigned long rem, chunks;
@@ -80,4 +79,4 @@ void attribute_hidden *__memset(void *to, int c, size_t n)
goto lessthan8;
}
-strong_alias(__memset, memset)
+strong_alias(__memset,memset)
diff --git a/libc/string/psignal.c b/libc/string/psignal.c
new file mode 100644
index 000000000..b6d6a30c0
--- /dev/null
+++ b/libc/string/psignal.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <features.h>
+#include <stdio.h>
+#include <string.h>
+
+extern char *__strsignal (int __sig) __THROW attribute_hidden;
+
+/* TODO: make this threadsafe with a reentrant version of strsignal? */
+
+void psignal(int signum, register const char *message)
+{
+ /* If the program is calling psignal, it's a safe bet that printf and
+ * friends are used as well. It is also possible that the calling
+ * program could buffer stderr, or reassign it. */
+
+ register const char *sep;
+
+ sep = ": ";
+ if (!(message && *message)) { /* Caller did not supply a prefix message */
+ message = (sep += 2); /* or passed an empty string. */
+ }
+
+ fprintf(stderr, "%s%s%s\n", message, sep, __strsignal(signum));
+}
diff --git a/libc/string/rawmemchr.c b/libc/string/rawmemchr.c
new file mode 100644
index 000000000..81d578a0f
--- /dev/null
+++ b/libc/string/rawmemchr.c
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+
+void attribute_hidden *__rawmemchr(const void *s, int c)
+{
+ register const unsigned char *r = s;
+
+ while (*r != ((unsigned char)c)) ++r;
+
+ return (void *) r; /* silence the warning */
+}
+
+strong_alias(__rawmemchr,rawmemchr)
diff --git a/libc/string/sh64/memcpy.S b/libc/string/sh64/memcpy.S
index 0ee386a96..d74980613 100644
--- a/libc/string/sh64/memcpy.S
+++ b/libc/string/sh64/memcpy.S
@@ -36,14 +36,14 @@
! enirety if at least one byte is included in the copy.
!
+#include <features.h>
+
.section .text..SHmedia32,"ax"
- .globl memcpy
- .set memcpy,__memcpy
.globl __memcpy
.hidden __memcpy
.type __memcpy, @function
-
.align 5
+
__memcpy:
#define LDUAQ(P,O,D0,D1) ldlo.q P,O,D0; ldhi.q P,O+7,D1
@@ -202,3 +202,5 @@ Loop_ua:
blink tr1, r63
.size __memcpy,.-__memcpy
+
+strong_alias(__memcpy,memcpy)
diff --git a/libc/string/sh64/memset.S b/libc/string/sh64/memset.S
index e1679230b..cd2ad7998 100644
--- a/libc/string/sh64/memset.S
+++ b/libc/string/sh64/memset.S
@@ -9,7 +9,10 @@
! Copyright 2002 SuperH Ltd.
!
-#ifdef __LITTLE_ENDIAN__
+#include <features.h>
+#include <endian.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
#define SHHI shlld
#define SHLO shlrd
#else
@@ -18,8 +21,6 @@
#endif
.section .text..SHmedia32,"ax"
- .globl memset
- .set memset,__memset
.globl __memset
.hidden __memset
.type __memset, @function
@@ -92,3 +93,5 @@ loop:
blink tr2,r63
.size __memset,.-__memset
+
+strong_alias(__memset,memset)
diff --git a/libc/string/sh64/strcpy.S b/libc/string/sh64/strcpy.S
index faa071c50..2ce998257 100644
--- a/libc/string/sh64/strcpy.S
+++ b/libc/string/sh64/strcpy.S
@@ -6,7 +6,10 @@
!
! SH5 code Copyright 2002 SuperH Ltd.
-#ifdef __LITTLE_ENDIAN__
+#include <features.h>
+#include <endian.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
#define SHHI shlld
#define SHLO shlrd
#else
@@ -15,13 +18,11 @@
#endif
.section .text..SHmedia32,"ax"
- .globl strcpy
- .set strcpy,__strcpy
.globl __strcpy
.hidden __strcpy
.type __strcpy, @function
-
.align 5
+
__strcpy:
pta/l shortstring,tr1
@@ -67,7 +68,7 @@ no_lddst:
add r5, r63, r4
addi r0, 8, r0
shortstring:
-#ifndef __LITTLE_ENDIAN__
+#if __BYTE_ORDER != __LITTLE_ENDIAN
pta/l shortstring2,tr1
byterev r4,r4
#endif
@@ -98,3 +99,5 @@ loop:
blink tr1, r63 // shortstring
.size __strcpy,.-__strcpy
+
+strong_alias(__strcpy,strcpy)
diff --git a/libc/string/sh64/strlen.S b/libc/string/sh64/strlen.S
index 0f99488d5..673a34dbd 100644
--- a/libc/string/sh64/strlen.S
+++ b/libc/string/sh64/strlen.S
@@ -30,9 +30,9 @@
* SUCH DAMAGE.
*/
+#include <features.h>
+
.section .text..SHmedia32,"ax"
- .globl strlen
- .set strlen,__strlen
.globl __strlen
.hidden __strlen
.type __strlen,@function
@@ -60,3 +60,5 @@ loop:
blink tr4, r63
.size __strlen,.-__strlen
+
+strong_alias(__strlen,strlen)
diff --git a/libc/string/sparc/_glibc_inc.h b/libc/string/sparc/_glibc_inc.h
index 7840ba1bf..6ef1dbde6 100644
--- a/libc/string/sparc/_glibc_inc.h
+++ b/libc/string/sparc/_glibc_inc.h
@@ -14,6 +14,7 @@
#define ENTRY(sym) \
.global sym; \
+ .hidden sym; \
.align ENTRY_ALIGN; \
.type sym,%function; \
sym:
@@ -23,8 +24,3 @@
#define END(sym) \
.size sym,.-sym;
-
-#undef weak_alias
-#define weak_alias(sym, alias) \
- .weak alias; \
- alias = sym;
diff --git a/libc/string/sparc/sparc32/memchr.S b/libc/string/sparc/sparc32/memchr.S
index e8f44f176..e012844ba 100644
--- a/libc/string/sparc/sparc32/memchr.S
+++ b/libc/string/sparc/sparc32/memchr.S
@@ -63,9 +63,6 @@
1: retl
sub %o0, 1, %o0
-.globl memchr
-.set memchr,__memchr
-.hidden __memchr
ENTRY(__memchr)
andcc %o1, 0xff, %o1
sll %o1, 8, %g6
@@ -140,7 +137,8 @@ ENTRY(__memchr)
4: retl
sub %o0, 4, %o0
END(__memchr)
+strong_alias(__memchr,memchr)
#if !__BOUNDED_POINTERS__
-weak_alias (__memchr, __ubp_memchr)
+weak_alias(__memchr,__ubp_memchr)
#endif
diff --git a/libc/string/sparc/sparc32/memcpy.S b/libc/string/sparc/sparc32/memcpy.S
index b2a9b1602..a1dd246e6 100644
--- a/libc/string/sparc/sparc32/memcpy.S
+++ b/libc/string/sparc/sparc32/memcpy.S
@@ -161,18 +161,13 @@
b 3f
sub %o0, 2, %o0
-.globl bcopy
-.set bcopy,__bcopy
-.hidden __bcopy
ENTRY(__bcopy)
mov %o0, %o3
mov %o1, %o0
mov %o3, %o1
END(__bcopy)
+strong_alias(__bcopy,bcopy)
-.globl memmove
-.set memmove,__memmove
-.hidden __memmove
ENTRY(__memmove)
cmp %o0, %o1
st %o0, [%sp + 64]
@@ -454,10 +449,8 @@ ENTRY(__memmove)
b 3f
add %o0, 2, %o0
END(__memmove)
+strong_alias(__memmove,memmove)
-.globl memcpy
-.set memcpy,__memcpy
-.hidden __memcpy
ENTRY(__memcpy) /* %o0=dst %o1=src %o2=len */
sub %o0, %o1, %o4
st %o0, [%sp + 64]
@@ -974,3 +967,4 @@ ENTRY(__memcpy) /* %o0=dst %o1=src %o2=len */
110: retl
sub %o7, %g6, %o5
END(__memcpy)
+strong_alias(__memcpy,memcpy)
diff --git a/libc/string/sparc/sparc32/memset.S b/libc/string/sparc/sparc32/memset.S
index ef8a5b634..b60b881be 100644
--- a/libc/string/sparc/sparc32/memset.S
+++ b/libc/string/sparc/sparc32/memset.S
@@ -61,10 +61,8 @@ ENTRY(__bzero)
b 4f
sub %o0, %o2, %o0
END(__bzero)
+strong_alias(__bzero,bzero)
-.globl memset
-.set memset,__memset
-.hidden __memset
ENTRY(__memset)
and %o1, 0xff, %g3
sll %g3, 8, %g2
@@ -151,5 +149,4 @@ ENTRY(__memset)
0: retl
nop
END(__memset)
-
-weak_alias (__bzero, bzero)
+strong_alias(__memset,memset)
diff --git a/libc/string/sparc/sparc32/stpcpy.S b/libc/string/sparc/sparc32/stpcpy.S
index 97a5dce0e..26d2fecbd 100644
--- a/libc/string/sparc/sparc32/stpcpy.S
+++ b/libc/string/sparc/sparc32/stpcpy.S
@@ -65,9 +65,6 @@
1: retl
add %o0, -1, %o0
-.globl stpcpy
-.set stpcpy,__stpcpy
-.hidden __stpcpy
ENTRY(__stpcpy)
andcc %o1, 3, %g0
bne 10b
@@ -160,3 +157,5 @@ ENTRY(__stpcpy)
19: retl
nop
END(__stpcpy)
+
+strong_alias(__stpcpy,stpcpy)
diff --git a/libc/string/sparc/sparc32/strcat.S b/libc/string/sparc/sparc32/strcat.S
index 8efe6aebf..2ee630b23 100644
--- a/libc/string/sparc/sparc32/strcat.S
+++ b/libc/string/sparc/sparc32/strcat.S
@@ -91,9 +91,6 @@
b 3f
sub %o0, 1, %o0
-.globl strcat
-.set strcat,__strcat
-.hidden __strcat
ENTRY(__strcat)
mov %o0, %g2
andcc %o0, 3, %g0
@@ -347,3 +344,5 @@ ENTRY(__strcat)
retl
mov %g2, %o0
END(__strcat)
+
+strong_alias(__strcat,strcat)
diff --git a/libc/string/sparc/sparc32/strchr.S b/libc/string/sparc/sparc32/strchr.S
index 450b4ffe6..69360c53a 100644
--- a/libc/string/sparc/sparc32/strchr.S
+++ b/libc/string/sparc/sparc32/strchr.S
@@ -67,9 +67,6 @@
1: retl
sub %o0, 1, %o0
-.globl strchr
-.set strchr,__strchr
-.hidden __strchr
ENTRY(__strchr)
andcc %o1, 0xff, %o1
be 12f
@@ -219,10 +216,9 @@ ENTRY(__strchr)
b 7f
ld [%o0], %g4
END(__strchr)
+strong_alias(__strchr,strchr)
+strong_alias(__strchr,index)
-.globl strrchr
-.set strrchr,__strrchr
-.hidden __strrchr
ENTRY(__strrchr)
andcc %o1, 0xff, %o1
clr %o5
@@ -281,6 +277,5 @@ ENTRY(__strrchr)
9: retl
mov %o5, %o0
END(__strrchr)
-
-weak_alias (strchr, index)
-weak_alias (strrchr, rindex)
+strong_alias(__strrchr,strrchr)
+strong_alias(__strrchr,rindex)
diff --git a/libc/string/sparc/sparc32/strcmp.S b/libc/string/sparc/sparc32/strcmp.S
index 2ae1b2ef4..6a807e08a 100644
--- a/libc/string/sparc/sparc32/strcmp.S
+++ b/libc/string/sparc/sparc32/strcmp.S
@@ -74,9 +74,6 @@
2: retl
mov %o4, %o0
-.globl strcmp
-.set strcmp,__strcmp
-.hidden __strcmp
ENTRY(__strcmp)
andcc %o0, 3, %g0
bne 10b
@@ -256,3 +253,5 @@ ENTRY(__strcmp)
jmpl %i7 + 8, %g0
restore %g4, %g0, %o0
END(__strcmp)
+
+strong_alias(__strcmp,strcmp)
diff --git a/libc/string/sparc/sparc32/strcpy.S b/libc/string/sparc/sparc32/strcpy.S
index 6dc3517b5..ab57e00a5 100644
--- a/libc/string/sparc/sparc32/strcpy.S
+++ b/libc/string/sparc/sparc32/strcpy.S
@@ -63,9 +63,6 @@
b 6f
andcc %o0, 3, %g3
-.globl strcpy
-.set strcpy,__strcpy
-.hidden __strcpy
ENTRY(__strcpy)
mov %o0, %g2
andcc %o1, 3, %g0
@@ -273,3 +270,5 @@ ENTRY(__strcpy)
retl
mov %g2, %o0
END(__strcpy)
+
+strong_alias(__strcpy,strcpy)
diff --git a/libc/string/sparc/sparc32/strlen.S b/libc/string/sparc/sparc32/strlen.S
index 116700e24..81beb7f62 100644
--- a/libc/string/sparc/sparc32/strlen.S
+++ b/libc/string/sparc/sparc32/strlen.S
@@ -63,9 +63,6 @@
3: retl
mov 2, %o0
-.globl strlen
-.set strlen,__strlen
-.hidden __strlen
ENTRY(__strlen)
mov %o0, %o1
andcc %o0, 3, %g0
@@ -102,3 +99,5 @@ ENTRY(__strlen)
13: retl
sub %o4, %o1, %o0
END(__strlen)
+
+strong_alias(__strlen,strlen)
diff --git a/libc/string/sparc/sparc64/memchr.S b/libc/string/sparc/sparc64/memchr.S
index a10dfbc63..7017b5540 100644
--- a/libc/string/sparc/sparc64/memchr.S
+++ b/libc/string/sparc/sparc64/memchr.S
@@ -255,7 +255,7 @@ ENTRY(__memchr)
add %o0, -1, %o0 /* IEU0 */
END(__memchr)
-weak_alias (__memchr, memchr)
+strong_alias(__memchr,memchr)
#if !__BOUNDED_POINTERS__
-weak_alias (__memchr, __ubp_memchr)
+weak_alias(__memchr,__ubp_memchr)
#endif
diff --git a/libc/string/sparc/sparc64/memcpy.S b/libc/string/sparc/sparc64/memcpy.S
index 47f812a1e..4201b5ec2 100644
--- a/libc/string/sparc/sparc64/memcpy.S
+++ b/libc/string/sparc/sparc64/memcpy.S
@@ -191,9 +191,6 @@
.text
.align 32
-.globl bcopy
-.set bcopy,__bcopy
-.hidden __bcopy
ENTRY(__bcopy)
sub %o1, %o0, %o4 /* IEU0 Group */
mov %o0, %g3 /* IEU1 */
@@ -209,6 +206,7 @@ ENTRY(__bcopy)
retl
nop
END(__bcopy)
+strong_alias(__bcopy,bcopy)
.align 32
200: be,pt %xcc, 201f /* CTI */
@@ -506,9 +504,6 @@ END(__align_cpy_16)
#endif
.align 32
-.globl memcpy
-.set memcpy,__memcpy
-.hidden __memcpy
ENTRY(__memcpy)
210:
#ifndef USE_BPR
@@ -701,6 +696,7 @@ ENTRY(__memcpy)
retl
mov %g4, %o0
END(__memcpy)
+strong_alias(__memcpy,memcpy)
.align 32
228: andcc %o2, 1, %g0 /* IEU1 Group */
@@ -725,9 +721,6 @@ END(__memcpy)
nop
.align 32
-.globl memmove
-.set memmove,__memmove
-.hidden __memmove
ENTRY(__memmove)
#ifndef USE_BPR
srl %o2, 0, %o2 /* IEU1 Group */
@@ -920,8 +913,9 @@ ENTRY(__memmove)
retl
mov %g4, %o0
END(__memmove)
+strong_alias(__memmove,memmove)
#ifdef USE_BPR
-weak_alias (memcpy, __align_cpy_1)
-weak_alias (memcpy, __align_cpy_2)
+weak_alias(__memcpy,__align_cpy_1)
+weak_alias(__memcpy,__align_cpy_2)
#endif
diff --git a/libc/string/sparc/sparc64/memset.S b/libc/string/sparc/sparc64/memset.S
index 5d2911451..6fb25d211 100644
--- a/libc/string/sparc/sparc64/memset.S
+++ b/libc/string/sparc/sparc64/memset.S
@@ -36,9 +36,6 @@
/* Well, memset is a lot easier to get right than bcopy... */
.text
.align 32
-.globl memset
-.set memset,__memset
-.hidden __memset
ENTRY(__memset)
andcc %o1, 0xff, %o1
mov %o0, %o5
@@ -180,6 +177,7 @@ ENTRY(__memset)
ba,pt %xcc, 18b
ldd [%o0], %f0
END(__memset)
+strong_alias(__memset,memset)
#define ZERO_BLOCKS(base, offset, source) \
stx source, [base - offset - 0x38]; \
@@ -312,5 +310,4 @@ ENTRY(__bzero)
0: retl
mov %o5, %o0
END(__bzero)
-
-weak_alias (__bzero, bzero)
+strong_alias(__bzero,bzero)
diff --git a/libc/string/sparc/sparc64/sparcv9b/memcpy.S b/libc/string/sparc/sparc64/sparcv9b/memcpy.S
index 91e74d438..dd381c7ef 100644
--- a/libc/string/sparc/sparc64/sparcv9b/memcpy.S
+++ b/libc/string/sparc/sparc64/sparcv9b/memcpy.S
@@ -36,9 +36,6 @@
.text
.align 32
-.globl bcopy
-.set bcopy,__bcopy
-.hidden __bcopy
ENTRY(__bcopy)
sub %o1, %o0, %o4
mov %o0, %g4
@@ -54,6 +51,7 @@ ENTRY(__bcopy)
retl
nop
END(__bcopy)
+strong_alias(__bcopy,bcopy)
/* Special/non-trivial issues of this code:
*
@@ -70,9 +68,6 @@ END(__bcopy)
* of up to 2.4GB per second.
*/
.align 32
-.globl memcpy
-.set memcpy,__memcpy
-.hidden __memcpy
ENTRY(__memcpy)
100: /* %o0=dst, %o1=src, %o2=len */
@@ -335,6 +330,7 @@ small_copy_unaligned:
mov %g5, %o0
END(__memcpy)
+strong_alias(__memcpy,memcpy)
#define RMOVE_BIGCHUNK(src, dst, offset, t0, t1, t2, t3) \
ldx [%src - offset - 0x20], %t0; \
@@ -409,9 +405,6 @@ END(__memcpy)
mov %g4, %o0
.align 32
-.globl memmove
-.set memmove,__memmove
-.hidden __memmove
ENTRY(__memmove)
mov %o0, %g5
#ifndef USE_BPR
@@ -605,11 +598,12 @@ ENTRY(__memmove)
retl
mov %g4, %o0
END(__memmove)
+strong_alias(__memmove,memmove)
#ifdef USE_BPR
-weak_alias (memcpy, __align_cpy_1)
-weak_alias (memcpy, __align_cpy_2)
-weak_alias (memcpy, __align_cpy_4)
-weak_alias (memcpy, __align_cpy_8)
-weak_alias (memcpy, __align_cpy_16)
+weak_alias(memcpy,__align_cpy_1)
+weak_alias(memcpy,__align_cpy_2)
+weak_alias(memcpy,__align_cpy_4)
+weak_alias(memcpy,__align_cpy_8)
+weak_alias(memcpy,__align_cpy_16)
#endif
diff --git a/libc/string/sparc/sparc64/stpcpy.S b/libc/string/sparc/sparc64/stpcpy.S
index a66f9d152..6bd24cfee 100644
--- a/libc/string/sparc/sparc64/stpcpy.S
+++ b/libc/string/sparc/sparc64/stpcpy.S
@@ -269,4 +269,4 @@ ENTRY(__stpcpy)
mov %g6, %o0 /* IEU0 */
END(__stpcpy)
-weak_alias (__stpcpy, stpcpy)
+strong_alias(__stpcpy,stpcpy)
diff --git a/libc/string/sparc/sparc64/strcat.S b/libc/string/sparc/sparc64/strcat.S
index 3b81e59e6..fb3ad2d12 100644
--- a/libc/string/sparc/sparc64/strcat.S
+++ b/libc/string/sparc/sparc64/strcat.S
@@ -47,9 +47,6 @@
.text
.align 32
-.globl strcat
-.set strcat,__strcat
-.hidden __strcat
ENTRY(__strcat)
sethi %hi(0x01010101), %g1 /* IEU0 Group */
ldub [%o0], %o3 /* Load */
@@ -339,3 +336,5 @@ ENTRY(__strcat)
retl /* CTI+IEU1 Group */
mov %g6, %o0 /* IEU0 */
END(__strcat)
+
+strong_alias(__strcat,strcat)
diff --git a/libc/string/sparc/sparc64/strchr.S b/libc/string/sparc/sparc64/strchr.S
index 6943e8b96..34c30df31 100644
--- a/libc/string/sparc/sparc64/strchr.S
+++ b/libc/string/sparc/sparc64/strchr.S
@@ -47,9 +47,6 @@
.text
.align 32
-.globl strchr
-.set strchr,__strchr
-.hidden __strchr
ENTRY(__strchr)
andcc %o1, 0xff, %o1 /* IEU1 Group */
be,pn %icc, 17f /* CTI */
@@ -331,11 +328,10 @@ ENTRY(__strchr)
retl /* CTI+IEU1 Group */
add %o0, -1, %o0 /* IEU0 */
END(__strchr)
+strong_alias(__strchr,strchr)
+strong_alias(__strchr,index)
.align 32
-.globl strrchr
-.set strrchr,__strrchr
-.hidden __strrchr
ENTRY(__strrchr)
andcc %o1, 0xff, %o1 /* IEU1 Group */
be,pn %icc, 17b /* CTI */
@@ -481,6 +477,5 @@ ENTRY(__strrchr)
ldx [%o0], %o3 /* Load */
END(__strrchr)
-
-weak_alias (strchr, index)
-weak_alias (strrchr, rindex)
+strong_alias(__strrchr,strrchr)
+strong_alias(__strrchr,rindex)
diff --git a/libc/string/sparc/sparc64/strcmp.S b/libc/string/sparc/sparc64/strcmp.S
index a4eb36632..0e078e9ac 100644
--- a/libc/string/sparc/sparc64/strcmp.S
+++ b/libc/string/sparc/sparc64/strcmp.S
@@ -45,9 +45,6 @@
.text
.align 32
-.globl strcmp
-.set strcmp,__strcmp
-.hidden __strcmp
ENTRY(__strcmp)
sethi %hi(0x01010101), %g1 /* IEU0 Group */
andcc %o0, 7, %g0 /* IEU1 */
@@ -279,3 +276,5 @@ ENTRY(__strcmp)
ba,pt %xcc, 11b /* CTI Group */
ldxa [%o1 + %o0] ASI_PNF, %g6 /* Load */
END(__strcmp)
+
+strong_alias(__strcmp,strcmp)
diff --git a/libc/string/sparc/sparc64/strcpy.S b/libc/string/sparc/sparc64/strcpy.S
index cc906bae7..d9dff104a 100644
--- a/libc/string/sparc/sparc64/strcpy.S
+++ b/libc/string/sparc/sparc64/strcpy.S
@@ -45,9 +45,6 @@
.text
.align 32
-.globl strcpy
-.set strcpy,__strcpy
-.hidden __strcpy
ENTRY(__strcpy)
sethi %hi(0x01010101), %g1 /* IEU0 Group */
mov %o0, %g6 /* IEU1 */
@@ -244,3 +241,5 @@ ENTRY(__strcpy)
retl /* CTI+IEU1 Group */
mov %g6, %o0 /* IEU0 */
END(__strcpy)
+
+strong_alias(__strcpy,strcpy)
diff --git a/libc/string/sparc/sparc64/strlen.S b/libc/string/sparc/sparc64/strlen.S
index 9f48fe6a1..3c1cfc0d8 100644
--- a/libc/string/sparc/sparc64/strlen.S
+++ b/libc/string/sparc/sparc64/strlen.S
@@ -39,9 +39,6 @@
.text
.align 32
-.globl strlen
-.set strlen,__strlen
-.hidden __strlen
ENTRY(__strlen)
sethi %hi(0x01010101), %g1 /* IEU0 Group */
ldub [%o0], %o3 /* Load */
@@ -173,3 +170,5 @@ ENTRY(__strlen)
retl /* CTI+IEU1 Group */
sub %o0, %o1, %o0 /* IEU0 */
END(__strlen)
+
+strong_alias(__strlen,strlen)
diff --git a/libc/string/stpcpy.c b/libc/string/stpcpy.c
index c7baf5b9d..540d04831 100644
--- a/libc/string/stpcpy.c
+++ b/libc/string/stpcpy.c
@@ -1,14 +1,31 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_stpcpy
-#define Wstpcpy __stpcpy
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstpcpy __wcpcpy
+# define Wstpcpy wcpcpy
+#else
+# define __Wstpcpy __stpcpy
+# define Wstpcpy stpcpy
+#endif
-strong_alias(__stpcpy, stpcpy)
+Wchar attribute_hidden *__Wstpcpy(register Wchar * __restrict s1, const Wchar * __restrict s2)
+{
+#ifdef __BCC__
+ do {
+ *s1 = *s2++;
+ } while (*s1++ != 0);
+#else
+ while ( (*s1++ = *s2++) != 0 );
+#endif
-#undef L_stpcpy
+ return s1 - 1;
+}
+
+strong_alias(__Wstpcpy,Wstpcpy)
diff --git a/libc/string/stpncpy.c b/libc/string/stpncpy.c
index 9875ad4cf..5b45d0ef9 100644
--- a/libc/string/stpncpy.c
+++ b/libc/string/stpncpy.c
@@ -1,14 +1,41 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_stpncpy
-#define Wstpncpy __stpncpy
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstpncpy __wcpncpy
+# define Wstpncpy wcpncpy
+#else
+# define __Wstpncpy __stpncpy
+# define Wstpncpy stpncpy
+#endif
-strong_alias(__stpncpy, stpncpy)
+Wchar attribute_hidden *__Wstpncpy(register Wchar * __restrict s1,
+ register const Wchar * __restrict s2,
+ size_t n)
+{
+ Wchar *s = s1;
+ const Wchar *p = s2;
-#undef L_stpncpy
+#ifdef __BCC__
+ while (n--) {
+ if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
+ ++s;
+ }
+ return s1 + (s2 - p);
+#else
+ while (n) {
+ if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
+ ++s;
+ --n;
+ }
+ return s1 + (s2 - p);
+#endif
+}
+
+strong_alias(__Wstpncpy,Wstpncpy)
diff --git a/libc/string/strcasecmp.c b/libc/string/strcasecmp.c
new file mode 100644
index 000000000..1d758e2ca
--- /dev/null
+++ b/libc/string/strcasecmp.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+#include <ctype.h>
+#include <locale.h>
+
+#ifdef __UCLIBC_HAS_XLOCALE__
+extern int __strcasecmp_l (__const char *__s1, __const char *__s2,
+ __locale_t __loc)
+ __THROW __attribute_pure__ __nonnull ((1, 2, 3)) attribute_hidden;
+extern int __wcscasecmp_l (__const wchar_t *__s1, __const wchar_t *__s2,
+ __locale_t __loc) __THROW attribute_hidden;
+#endif
+
+#ifdef WANT_WIDE
+# define strcasecmp wcscasecmp
+# define __strcasecmp __wcscasecmp
+# define strcasecmp_l wcscasecmp_l
+# define __strcasecmp_l __wcscasecmp_l
+# ifdef __UCLIBC_DO_XLOCALE
+# define TOLOWER(C) __towlower_l((C), locale_arg)
+extern wint_t __towlower_l (wint_t __wc, __locale_t __locale) __THROW attribute_hidden;
+# else
+# define TOLOWER(C) __towlower((C))
+# endif
+#else
+# ifdef __UCLIBC_DO_XLOCALE
+# define TOLOWER(C) __tolower_l((C), locale_arg)
+# else
+# define TOLOWER(C) __tolower((C))
+# endif
+#endif
+
+#if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
+
+int attribute_hidden __strcasecmp(register const Wchar *s1, register const Wchar *s2)
+{
+ return __strcasecmp_l(s1, s2, __UCLIBC_CURLOCALE);
+}
+strong_alias(__strcasecmp,strcasecmp)
+
+#else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
+
+int attribute_hidden __UCXL(strcasecmp)(register const Wchar *s1, register const Wchar *s2
+ __LOCALE_PARAM )
+{
+#ifdef WANT_WIDE
+ while ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2))) {
+ if (!*s1++) {
+ return 0;
+ }
+ ++s2;
+ }
+
+ return (((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1;
+ /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
+#else
+ int r = 0;
+
+ while ( ((s1 == s2) ||
+ !(r = ((int)( TOLOWER(*((Wuchar *)s1))))
+ - TOLOWER(*((Wuchar *)s2))))
+ && (++s2, *s1++));
+
+ return r;
+#endif
+}
+__UCXL_ALIAS(strcasecmp)
+
+#endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
diff --git a/libc/string/strcasecmp_l.c b/libc/string/strcasecmp_l.c
new file mode 100644
index 000000000..a3f74c4f8
--- /dev/null
+++ b/libc/string/strcasecmp_l.c
@@ -0,0 +1,8 @@
+/*
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define __UCLIBC_DO_XLOCALE
+#include "strcasecmp.c"
diff --git a/libc/string/strcasestr.c b/libc/string/strcasestr.c
new file mode 100644
index 000000000..5222eda71
--- /dev/null
+++ b/libc/string/strcasestr.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+#include <ctype.h>
+
+char attribute_hidden *__strcasestr(const char *s1, const char *s2)
+{
+ register const char *s = s1;
+ register const char *p = s2;
+
+#if 1
+ do {
+ if (!*p) {
+ return (char *) s1;;
+ }
+ if ((*p == *s)
+ || (__tolower(*((unsigned char *)p)) == __tolower(*((unsigned char *)s)))
+ ) {
+ ++p;
+ ++s;
+ } else {
+ p = s2;
+ if (!*s) {
+ return NULL;
+ }
+ s = ++s1;
+ }
+ } while (1);
+#else
+ while (*p && *s) {
+ if ((*p == *s)
+ || (__tolower(*((unsigned char *)p)) == __tolower(*((unsigned char *)s)))
+ ) {
+ ++p;
+ ++s;
+ } else {
+ p = s2;
+ s = ++s1;
+ }
+ }
+
+ return (*p) ? NULL : (char *) s1;
+#endif
+}
+
+strong_alias(__strcasestr,strcasestr)
diff --git a/libc/string/strcat.c b/libc/string/strcat.c
index 208501d66..5288f93ed 100644
--- a/libc/string/strcat.c
+++ b/libc/string/strcat.c
@@ -1,14 +1,29 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strcat
-#define Wstrcat __strcat
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrcat __wcscat
+# define Wstrcat wcscat
+#else
+# define __Wstrcat __strcat
+# define Wstrcat strcat
+#endif
-strong_alias(__strcat, strcat)
+Wchar attribute_hidden *__Wstrcat(Wchar * __restrict s1, register const Wchar * __restrict s2)
+{
+ register Wchar *s = s1;
-#undef L_strcat
+ while (*s++);
+ --s;
+ while ((*s++ = *s2++) != 0);
+
+ return s1;
+}
+
+strong_alias(__Wstrcat,Wstrcat)
diff --git a/libc/string/strchr.c b/libc/string/strchr.c
index a58e1f56d..93f394ab1 100644
--- a/libc/string/strchr.c
+++ b/libc/string/strchr.c
@@ -1,16 +1,33 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strchr
-#define Wstrchr __strchr
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrchr __wcschr
+# define Wstrchr wcschr
+#else
+# define __Wstrchr __strchr
+# define Wstrchr strchr
+#endif
-strong_alias(__strchr, strchr)
+Wchar attribute_hidden *__Wstrchr(register const Wchar *s, Wint c)
+{
+ do {
+ if (*s == ((Wchar)c)) {
+ return (Wchar *) s; /* silence the warning */
+ }
+ } while (*s++);
-weak_alias(strchr, index)
+ return NULL;
+}
-#undef L_strchr
+strong_alias(__Wstrchr,Wstrchr)
+
+#ifndef WANT_WIDE
+strong_alias(__strchr,index)
+#endif
diff --git a/libc/string/strchrnul.c b/libc/string/strchrnul.c
index 2656c2801..c498532fd 100644
--- a/libc/string/strchrnul.c
+++ b/libc/string/strchrnul.c
@@ -1,14 +1,25 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strchrnul
-#define Wstrchrnul __strchrnul
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrchrnul __wcschrnul
+# define Wstrchrnul wcschrnul
+#else
+# define __Wstrchrnul __strchrnul
+# define Wstrchrnul strchrnul
+#endif
-strong_alias(__strchrnul, strchrnul)
+Wchar attribute_hidden *__Wstrchrnul(register const Wchar *s, Wint c)
+{
+ --s;
+ while (*++s && (*s != ((Wchar)c)));
+ return (Wchar *) s;
+}
-#undef L_strchrnul
+strong_alias(__Wstrchrnul,Wstrchrnul)
diff --git a/libc/string/strcmp.c b/libc/string/strcmp.c
index fbcd6380c..1fb8625ff 100644
--- a/libc/string/strcmp.c
+++ b/libc/string/strcmp.c
@@ -1,19 +1,49 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strcmp
-#define Wstrcmp __strcmp
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrcmp __wcscmp
+# define Wstrcmp wcscmp
+#else
+# define __Wstrcmp __strcmp
+# define Wstrcmp strcmp
+#endif
+
+int attribute_hidden __Wstrcmp(register const Wchar *s1, register const Wchar *s2)
+{
+#ifdef WANT_WIDE
+ while (*((Wuchar *)s1) == *((Wuchar *)s2)) {
+ if (!*s1++) {
+ return 0;
+ }
+ ++s2;
+ }
-strong_alias(__strcmp, strcmp)
+ return (*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1;
+#else
+ int r;
-#ifdef __LOCALE_C_ONLY
-hidden_strong_alias(__strcmp, __strcoll)
-strong_alias(__strcmp, strcoll)
+ while (((r = ((int)(*((Wuchar *)s1))) - *((Wuchar *)s2++))
+ == 0) && *s1++);
+
+ return r;
#endif
+}
-#undef L_strcmp
+strong_alias(__Wstrcmp,Wstrcmp)
+
+#ifndef __UCLIBC_HAS_LOCALE__
+# ifdef WANT_WIDE
+hidden_strong_alias(__wcscmp,__wcscoll)
+strong_alias(__wcscmp,wcscoll)
+# else
+hidden_strong_alias(__strcmp,__strcoll)
+strong_alias(__strcmp,strcoll)
+# endif
+#endif
diff --git a/libc/string/strcpy.c b/libc/string/strcpy.c
index 8dcdddde4..3b0e490eb 100644
--- a/libc/string/strcpy.c
+++ b/libc/string/strcpy.c
@@ -1,14 +1,33 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strcpy
-#define Wstrcpy __strcpy
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrcpy __wcscpy
+# define Wstrcpy wcscpy
+#else
+# define __Wstrcpy __strcpy
+# define Wstrcpy strcpy
+#endif
-strong_alias(__strcpy, strcpy)
+Wchar attribute_hidden *__Wstrcpy(Wchar * __restrict s1, const Wchar * __restrict s2)
+{
+ register Wchar *s = s1;
-#undef L_strcpy
+#ifdef __BCC__
+ do {
+ *s = *s2++;
+ } while (*s++ != 0);
+#else
+ while ( (*s++ = *s2++) != 0 );
+#endif
+
+ return s1;
+}
+
+strong_alias(__Wstrcpy,Wstrcpy)
diff --git a/libc/string/strcspn.c b/libc/string/strcspn.c
index b8f8fdc08..7a709a77f 100644
--- a/libc/string/strcspn.c
+++ b/libc/string/strcspn.c
@@ -1,14 +1,32 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strcspn
-#define Wstrcspn __strcspn
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrcspn __wcscspn
+# define Wstrcspn wcscspn
+#else
+# define __Wstrcspn __strcspn
+# define Wstrcspn strcspn
+#endif
-strong_alias(__strcspn, strcspn)
+size_t attribute_hidden __Wstrcspn(const Wchar *s1, const Wchar *s2)
+{
+ register const Wchar *s;
+ register const Wchar *p;
-#undef L_strcspn
+ for ( s=s1 ; *s ; s++ ) {
+ for ( p=s2 ; *p ; p++ ) {
+ if (*p == *s) goto done;
+ }
+ }
+ done:
+ return s - s1;
+}
+
+strong_alias(__Wstrcspn,Wstrcspn)
diff --git a/libc/string/strdup.c b/libc/string/strdup.c
index 2bf2462fb..e2ccead9d 100644
--- a/libc/string/strdup.c
+++ b/libc/string/strdup.c
@@ -1,19 +1,34 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strdup
-#define Wstrdup __strdup
+#include "_string.h"
+#include <stdlib.h>
-#undef Wstrlen
-#undef Wstrcpy
-#define Wstrlen __strlen
-#define Wstrcpy __strcpy
+#ifdef WANT_WIDE
+# define __Wstrdup __wcsdup
+# define Wstrdup wcsdup
+# define Wstrlen __wcslen
+# define Wstrcpy __wcscpy
+#else
+# define __Wstrdup __strdup
+# define Wstrdup strdup
+# define Wstrlen __strlen
+# define Wstrcpy __strcpy
+#endif
-#include "wstring.c"
+Wchar attribute_hidden *__Wstrdup(register const Wchar *s1)
+{
+ register Wchar *s;
-strong_alias(__strdup, strdup)
+ if ((s = malloc((Wstrlen(s1) + 1) * sizeof(Wchar))) != NULL) {
+ Wstrcpy(s, s1);
+ }
-#undef L_strdup
+ return s;
+}
+
+strong_alias(__Wstrdup,Wstrdup)
diff --git a/libc/string/strerror.c b/libc/string/strerror.c
new file mode 100644
index 000000000..a2f1f4833
--- /dev/null
+++ b/libc/string/strerror.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <features.h>
+#include <string.h>
+#include "_syserrmsg.h"
+
+char attribute_hidden *__strerror(int errnum)
+{
+ static char buf[_STRERROR_BUFSIZE];
+
+ __xpg_strerror_r_internal(errnum, buf, sizeof(buf));
+
+ return buf;
+}
+
+strong_alias(__strerror,strerror)
diff --git a/libc/string/strlcat.c b/libc/string/strlcat.c
new file mode 100644
index 000000000..117b8e552
--- /dev/null
+++ b/libc/string/strlcat.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+/* OpenBSD function:
+ * Append at most n-1-strlen(dst) chars from src to dst and nul-terminate dst.
+ * Returns strlen(src) + strlen({original} dst), so truncation occurred if the
+ * return val is >= n.
+ * Note: If dst doesn't contain a nul in the first n chars, strlen(dst) is
+ * taken as n. */
+
+#include "_string.h"
+
+size_t strlcat(register char *__restrict dst,
+ register const char *__restrict src,
+ size_t n)
+{
+ size_t len;
+ char dummy[1];
+
+ len = 0;
+
+ while (1) {
+ if (len >= n) {
+ dst = dummy;
+ break;
+ }
+ if (!*dst) {
+ break;
+ }
+ ++dst;
+ ++len;
+ }
+
+ while ((*dst = *src) != 0) {
+ if (++len < n) {
+ ++dst;
+ }
+ ++src;
+ }
+
+ return len;
+}
diff --git a/libc/string/strlcpy.c b/libc/string/strlcpy.c
index e8a435bce..3920db083 100644
--- a/libc/string/strlcpy.c
+++ b/libc/string/strlcpy.c
@@ -1,19 +1,56 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strlcpy
-#define Wstrlcpy __strlcpy
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrlcpy __wcslcpy
+# define Wstrlcpy wcslcpy
+#else
+# define __Wstrlcpy __strlcpy
+# define Wstrlcpy strlcpy
+#endif
-strong_alias(__strlcpy, strlcpy)
+/* OpenBSD function:
+ * Copy at most n-1 chars from src to dst and nul-terminate dst.
+ * Returns strlen(src), so truncation occurred if the return value is >= n. */
-#ifdef __LOCALE_C_ONLY
-hidden_strong_alias(__strlcpy, __strxfrm)
-strong_alias(__strlcpy, strxfrm)
-#endif
+size_t attribute_hidden __Wstrlcpy(register Wchar *__restrict dst,
+ register const Wchar *__restrict src,
+ size_t n)
+{
+ const Wchar *src0 = src;
+ Wchar dummy[1];
+
+ if (!n) {
+ dst = dummy;
+ } else {
+ --n;
+ }
+
+ while ((*dst = *src) != 0) {
+ if (n) {
+ --n;
+ ++dst;
+ }
+ ++src;
+ }
-#undef L_strlcpy
+ return src - src0;
+}
+
+strong_alias(__Wstrlcpy,Wstrlcpy)
+
+#ifndef __UCLIBC_HAS_LOCALE__
+# ifdef WANT_WIDE
+hidden_strong_alias(__wcslcpy,__wcsxfrm)
+strong_alias(__wcslcpy,wcsxfrm)
+# else
+hidden_strong_alias(__strlcpy,__strxfrm)
+strong_alias(__strlcpy,strxfrm)
+# endif
+#endif
diff --git a/libc/string/strlen.c b/libc/string/strlen.c
index 282f34d93..27cd8481c 100644
--- a/libc/string/strlen.c
+++ b/libc/string/strlen.c
@@ -1,14 +1,27 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strlen
-#define Wstrlen __strlen
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrlen __wcslen
+# define Wstrlen wcslen
+#else
+# define __Wstrlen __strlen
+# define Wstrlen strlen
+#endif
-strong_alias(__strlen, strlen)
+size_t attribute_hidden __Wstrlen(const Wchar *s)
+{
+ register const Wchar *p;
-#undef L_strlen
+ for (p=s ; *p ; p++);
+
+ return p - s;
+}
+
+strong_alias(__Wstrlen,Wstrlen)
diff --git a/libc/string/strncasecmp.c b/libc/string/strncasecmp.c
new file mode 100644
index 000000000..bfc865a8c
--- /dev/null
+++ b/libc/string/strncasecmp.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+#include <ctype.h>
+#include <locale.h>
+
+#ifdef __UCLIBC_HAS_XLOCALE__
+extern int __strncasecmp_l (__const char *__s1, __const char *__s2,
+ size_t __n, __locale_t __loc)
+ __THROW __attribute_pure__ __nonnull ((1, 2, 4)) attribute_hidden;
+extern int __wcsncasecmp_l (__const wchar_t *__s1, __const wchar_t *__s2,
+ size_t __n, __locale_t __loc) __THROW attribute_hidden;
+#endif
+
+#ifdef WANT_WIDE
+# define strncasecmp wcsncasecmp
+# define __strncasecmp __wcsncasecmp
+# define strncasecmp_l wcsncasecmp_l
+# define __strncasecmp_l __wcsncasecmp_l
+# ifdef __UCLIBC_DO_XLOCALE
+# define TOLOWER(C) __towlower_l((C), locale_arg)
+extern wint_t __towlower_l (wint_t __wc, __locale_t __locale) __THROW attribute_hidden;
+# else
+# define TOLOWER(C) __towlower((C))
+# endif
+#else
+# ifdef __UCLIBC_DO_XLOCALE
+# define TOLOWER(C) __tolower_l((C), locale_arg)
+# else
+# define TOLOWER(C) __tolower((C))
+# endif
+#endif
+
+#if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
+
+int attribute_hidden __strncasecmp(register const Wchar *s1, register const Wchar *s2, size_t n)
+{
+ return __strncasecmp_l(s1, s2, n, __UCLIBC_CURLOCALE);
+}
+strong_alias(__strncasecmp,strncasecmp)
+
+#else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
+
+int attribute_hidden __UCXL(strncasecmp)(register const Wchar *s1, register const Wchar *s2,
+ size_t n __LOCALE_PARAM )
+{
+#ifdef WANT_WIDE
+ while (n && ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2)))) {
+ if (!*s1++) {
+ return 0;
+ }
+ ++s2;
+ --n;
+ }
+
+ return (n == 0)
+ ? 0
+ : ((((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1);
+ /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
+#else
+ int r = 0;
+
+ while ( n
+ && ((s1 == s2) ||
+ !(r = ((int)( TOLOWER(*((unsigned char *)s1))))
+ - TOLOWER(*((unsigned char *)s2))))
+ && (--n, ++s2, *s1++));
+ return r;
+#endif
+}
+__UCXL_ALIAS(strncasecmp)
+
+#endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
diff --git a/libc/string/strncasecmp_l.c b/libc/string/strncasecmp_l.c
new file mode 100644
index 000000000..7f251bae2
--- /dev/null
+++ b/libc/string/strncasecmp_l.c
@@ -0,0 +1,8 @@
+/*
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define __UCLIBC_DO_XLOCALE
+#include "strncasecmp.c"
diff --git a/libc/string/strncat.c b/libc/string/strncat.c
index 623354305..20fbcfa27 100644
--- a/libc/string/strncat.c
+++ b/libc/string/strncat.c
@@ -1,14 +1,38 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strncat
-#define Wstrncat __strncat
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrncat __wcsncat
+# define Wstrncat wcsncat
+#else
+# define __Wstrncat __strncat
+# define Wstrncat strncat
+#endif
-strong_alias(__strncat, strncat)
+Wchar attribute_hidden *__Wstrncat(Wchar * __restrict s1, register const Wchar * __restrict s2,
+ size_t n)
+{
+ register Wchar *s = s1;
-#undef L_strncat
+ while (*s++);
+ --s;
+#if __BCC__
+ while (n-- && ((*s = *s2++) != 0)) ++s;
+#else
+ while (n && ((*s = *s2++) != 0)) {
+ --n;
+ ++s;
+ }
+#endif
+ *s = 0;
+
+ return s1;
+}
+
+strong_alias(__Wstrncat,Wstrncat)
diff --git a/libc/string/strncmp.c b/libc/string/strncmp.c
index d36003ab6..ad80ce8e5 100644
--- a/libc/string/strncmp.c
+++ b/libc/string/strncmp.c
@@ -1,14 +1,42 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strncmp
-#define Wstrncmp __strncmp
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrncmp __wcsncmp
+# define Wstrncmp wcsncmp
+#else
+# define __Wstrncmp __strncmp
+# define Wstrncmp strncmp
+#endif
-strong_alias(__strncmp, strncmp)
+int attribute_hidden __Wstrncmp(register const Wchar *s1, register const Wchar *s2, size_t n)
+{
+#ifdef WANT_WIDE
+ while (n && (*((Wuchar *)s1) == *((Wuchar *)s2))) {
+ if (!*s1++) {
+ return 0;
+ }
+ ++s2;
+ --n;
+ }
-#undef L_strncmp
+ return (n == 0) ? 0 : ((*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1);
+#else
+ int r = 0;
+
+ while (n--
+ && ((r = ((int)(*((unsigned char *)s1))) - *((unsigned char *)s2++))
+ == 0)
+ && *s1++);
+
+ return r;
+#endif
+}
+
+strong_alias(__Wstrncmp,Wstrncmp)
diff --git a/libc/string/strncpy.c b/libc/string/strncpy.c
index c96be715e..09124ac99 100644
--- a/libc/string/strncpy.c
+++ b/libc/string/strncpy.c
@@ -1,14 +1,39 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strncpy
-#define Wstrncpy __strncpy
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrncpy __wcsncpy
+# define Wstrncpy wcsncpy
+#else
+# define __Wstrncpy __strncpy
+# define Wstrncpy strncpy
+#endif
-strong_alias(__strncpy, strncpy)
+Wchar attribute_hidden *__Wstrncpy(Wchar * __restrict s1, register const Wchar * __restrict s2,
+ size_t n)
+{
+ register Wchar *s = s1;
-#undef L_strncpy
+#ifdef __BCC__
+ while (n--) {
+ if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
+ ++s;
+ }
+#else
+ while (n) {
+ if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
+ ++s;
+ --n;
+ }
+#endif
+
+ return s1;
+}
+
+strong_alias(__Wstrncpy,Wstrncpy)
diff --git a/libc/string/strndup.c b/libc/string/strndup.c
new file mode 100644
index 000000000..5cee0272d
--- /dev/null
+++ b/libc/string/strndup.c
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+#include <stdlib.h>
+
+char attribute_hidden *__strndup(register const char *s1, size_t n)
+{
+ register char *s;
+
+ n = __strnlen(s1,n); /* Avoid problems if s1 not nul-terminated. */
+
+ if ((s = malloc(n + 1)) != NULL) {
+ __memcpy(s, s1, n);
+ s[n] = 0;
+ }
+
+ return s;
+}
+
+strong_alias(__strndup,strndup)
diff --git a/libc/string/strnlen.c b/libc/string/strnlen.c
index a480e29d1..6732cc532 100644
--- a/libc/string/strnlen.c
+++ b/libc/string/strnlen.c
@@ -1,14 +1,37 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strnlen
-#define Wstrnlen __strnlen
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrnlen __wcsnlen
+# define Wstrnlen wcsnlen
+#else
+# define __Wstrnlen __strnlen
+# define Wstrnlen strnlen
+#endif
-strong_alias(__strnlen, strnlen)
+size_t attribute_hidden __Wstrnlen(const Wchar *s, size_t max)
+{
+ register const Wchar *p = s;
+#ifdef __BCC__
+ /* bcc can optimize the counter if it thinks it is a pointer... */
+ register const char *maxp = (const char *) max;
+#else
+# define maxp max
+#endif
-#undef L_strnlen
+ while (maxp && *p) {
+ ++p;
+ --maxp;
+ }
+
+ return p - s;
+}
+#undef maxp
+
+strong_alias(__Wstrnlen,Wstrnlen)
diff --git a/libc/string/strpbrk.c b/libc/string/strpbrk.c
index 88e0b4051..704b1bc71 100644
--- a/libc/string/strpbrk.c
+++ b/libc/string/strpbrk.c
@@ -1,14 +1,31 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strpbrk
-#define Wstrpbrk __strpbrk
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrpbrk __wcspbrk
+# define Wstrpbrk wcspbrk
+#else
+# define __Wstrpbrk __strpbrk
+# define Wstrpbrk strpbrk
+#endif
-strong_alias(__strpbrk, strpbrk)
+Wchar attribute_hidden *__Wstrpbrk(const Wchar *s1, const Wchar *s2)
+{
+ register const Wchar *s;
+ register const Wchar *p;
-#undef L_strpbrk
+ for ( s=s1 ; *s ; s++ ) {
+ for ( p=s2 ; *p ; p++ ) {
+ if (*p == *s) return (Wchar *) s; /* silence the warning */
+ }
+ }
+ return NULL;
+}
+
+strong_alias(__Wstrpbrk,Wstrpbrk)
diff --git a/libc/string/strrchr.c b/libc/string/strrchr.c
index 374abb694..cb30afea7 100644
--- a/libc/string/strrchr.c
+++ b/libc/string/strrchr.c
@@ -1,16 +1,35 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strrchr
-#define Wstrrchr __strrchr
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrrchr __wcsrchr
+# define Wstrrchr wcsrchr
+#else
+# define __Wstrrchr __strrchr
+# define Wstrrchr strrchr
+#endif
-strong_alias(__strrchr, strrchr)
+Wchar attribute_hidden *__Wstrrchr(register const Wchar *s, Wint c)
+{
+ register const Wchar *p;
-weak_alias(strrchr, rindex)
+ p = NULL;
+ do {
+ if (*s == (Wchar) c) {
+ p = s;
+ }
+ } while (*s++);
-#undef L_strrchr
+ return (Wchar *) p; /* silence the warning */
+}
+
+strong_alias(__Wstrrchr,Wstrrchr)
+#ifndef WANT_WIDE
+strong_alias(__strrchr,rindex)
+#endif
diff --git a/libc/string/strsep.c b/libc/string/strsep.c
new file mode 100644
index 000000000..993fafecb
--- /dev/null
+++ b/libc/string/strsep.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+
+char attribute_hidden *__strsep(char ** __restrict s1, const char * __restrict s2)
+{
+ register char *s = *s1;
+ register char *p;
+
+#if 1
+ p = NULL;
+ if (s && *s && (p = __strpbrk(s, s2))) {
+ *p++ = 0;
+ }
+#else
+ if (s && *s && *(p = s + __strcspn(s, s2))) {
+ *p++ = 0;
+ } else {
+ p = NULL;
+ }
+#endif
+ *s1 = p;
+ return s;
+}
+
+strong_alias(__strsep,strsep)
diff --git a/libc/string/strspn.c b/libc/string/strspn.c
index e03250593..9074c13ad 100644
--- a/libc/string/strspn.c
+++ b/libc/string/strspn.c
@@ -1,14 +1,32 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strspn
-#define Wstrspn __strspn
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrspn __wcsspn
+# define Wstrspn wcsspn
+#else
+# define __Wstrspn __strspn
+# define Wstrspn strspn
+#endif
-strong_alias(__strspn, strspn)
+size_t attribute_hidden __Wstrspn(const Wchar *s1, const Wchar *s2)
+{
+ register const Wchar *s = s1;
+ register const Wchar *p = s2;
-#undef L_strspn
+ while (*p) {
+ if (*p++ == *s) {
+ ++s;
+ p = s2;
+ }
+ }
+ return s - s1;
+}
+
+strong_alias(__Wstrspn,Wstrspn)
diff --git a/libc/string/strstr.c b/libc/string/strstr.c
index f7ae4ffaf..7256b9da2 100644
--- a/libc/string/strstr.c
+++ b/libc/string/strstr.c
@@ -1,14 +1,45 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strstr
-#define Wstrstr __strstr
+#include "_string.h"
-#include "wstring.c"
+#ifdef WANT_WIDE
+# define __Wstrstr __wcsstr
+# define Wstrstr wcsstr
+#else
+# define __Wstrstr __strstr
+# define Wstrstr strstr
+#endif
-strong_alias(__strstr, strstr)
+/* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
-#undef L_strstr
+Wchar attribute_hidden *__Wstrstr(const Wchar *s1, const Wchar *s2)
+{
+ register const Wchar *s = s1;
+ register const Wchar *p = s2;
+
+ do {
+ if (!*p) {
+ return (Wchar *) s1;;
+ }
+ if (*p == *s) {
+ ++p;
+ ++s;
+ } else {
+ p = s2;
+ if (!*s) {
+ return NULL;
+ }
+ s = ++s1;
+ }
+ } while (1);
+}
+
+strong_alias(__Wstrstr,Wstrstr)
+#ifdef WANT_WIDE
+strong_alias(__wcsstr,wcswcs)
+#endif
diff --git a/libc/string/strtok.c b/libc/string/strtok.c
new file mode 100644
index 000000000..4b8aef6b5
--- /dev/null
+++ b/libc/string/strtok.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include "_string.h"
+
+#if 0 /*def WANT_WIDE*/
+# define Wstrtok wcstok
+# define Wstrtok_r __wcstok_r
+#else
+# define Wstrtok strtok
+# define Wstrtok_r __strtok_r
+#endif
+
+Wchar *Wstrtok(Wchar * __restrict s1, const Wchar * __restrict s2)
+{
+ static Wchar *next_start; /* Initialized to 0 since in bss. */
+ return Wstrtok_r(s1, s2, &next_start);
+}
diff --git a/libc/string/strtok_r.c b/libc/string/strtok_r.c
index 3f92c034d..c8ba588eb 100644
--- a/libc/string/strtok_r.c
+++ b/libc/string/strtok_r.c
@@ -1,19 +1,55 @@
/*
+ * Copyright (C) 2002 Manuel Novoa III
* Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strtok_r
-#define Wstrtok_r __strtok_r
+#include "_string.h"
-#undef Wstrspn
-#define Wstrspn __strspn
-#undef Wstrpbrk
-#define Wstrpbrk __strpbrk
+#ifdef WANT_WIDE
+# define __Wstrtok_r __wcstok
+# define Wstrtok_r wcstok
+# define Wstrspn __wcsspn
+# define Wstrpbrk __wcspbrk
+#else
+# define __Wstrtok_r __strtok_r
+# define Wstrtok_r strtok_r
+# define Wstrspn __strspn
+# define Wstrpbrk __strpbrk
+#endif
-#include "wstring.c"
+Wchar attribute_hidden *__Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
+ Wchar ** __restrict next_start)
+{
+ register Wchar *s;
+ register Wchar *p;
-strong_alias(__strtok_r, strtok_r)
+#if 1
+ if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
+ if (*(s += Wstrspn(s, s2))) {
+ if ((p = Wstrpbrk(s, s2)) != NULL) {
+ *p++ = 0;
+ }
+ } else {
+ p = s = NULL;
+ }
+ *next_start = p;
+ }
+ return s;
+#else
+ if (!(s = s1)) {
+ s = *next_start;
+ }
+ if (s && *(s += Wstrspn(s, s2))) {
+ if (*(p = s + Wstrcspn(s, s2))) {
+ *p++ = 0;
+ }
+ *next_start = p;
+ return s;
+ }
+ return NULL; /* TODO: set *next_start = NULL for safety? */
+#endif
+}
-#undef L_strtok_r
+strong_alias(__Wstrtok_r,Wstrtok_r)
diff --git a/libc/string/strxfrm.c b/libc/string/strxfrm.c
new file mode 100644
index 000000000..037d47bd0
--- /dev/null
+++ b/libc/string/strxfrm.c
@@ -0,0 +1,9 @@
+/*
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define WANT_WIDE
+#define L_strxfrm
+#include "_collate.c"
diff --git a/libc/string/strxfrm_l.c b/libc/string/strxfrm_l.c
new file mode 100644
index 000000000..85e1cdfd6
--- /dev/null
+++ b/libc/string/strxfrm_l.c
@@ -0,0 +1,10 @@
+/*
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define WANT_WIDE
+#define __UCLIBC_DO_XLOCALE
+#define L_strxfrm_l
+#include "_collate.c"
diff --git a/libc/string/sys_errlist.c b/libc/string/sys_errlist.c
new file mode 100644
index 000000000..a0b5e3b2f
--- /dev/null
+++ b/libc/string/sys_errlist.c
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <features.h>
+#include <errno.h>
+
+extern const char _string_syserrmsgs[];
+
+#ifdef __UCLIBC_HAS_SYS_ERRLIST__
+
+link_warning(_sys_errlist, "sys_nerr and sys_errlist are obsolete and uClibc support for them (in at least some configurations) will probably be unavailable in the near future.")
+
+const char *const sys_errlist[] = {
+ [0] = _string_syserrmsgs + 0,
+ [EPERM] = _string_syserrmsgs + 8,
+ [ENOENT] = _string_syserrmsgs + 32,
+ [ESRCH] = _string_syserrmsgs + 58,
+ [EINTR] = _string_syserrmsgs + 74,
+ [EIO] = _string_syserrmsgs + 98,
+ [ENXIO] = _string_syserrmsgs + 117,
+ [E2BIG] = _string_syserrmsgs + 143,
+ [ENOEXEC] = _string_syserrmsgs + 166,
+ [EBADF] = _string_syserrmsgs + 184,
+ [ECHILD] = _string_syserrmsgs + 204,
+ [EAGAIN] = _string_syserrmsgs + 223,
+ [ENOMEM] = _string_syserrmsgs + 256,
+ [EACCES] = _string_syserrmsgs + 279,
+ [EFAULT] = _string_syserrmsgs + 297,
+ [ENOTBLK] = _string_syserrmsgs + 309,
+ [EBUSY] = _string_syserrmsgs + 331,
+ [EEXIST] = _string_syserrmsgs + 355,
+ [EXDEV] = _string_syserrmsgs + 367,
+ [ENODEV] = _string_syserrmsgs + 393,
+ [ENOTDIR] = _string_syserrmsgs + 408,
+ [EISDIR] = _string_syserrmsgs + 424,
+ [EINVAL] = _string_syserrmsgs + 439,
+ [ENFILE] = _string_syserrmsgs + 456,
+ [EMFILE] = _string_syserrmsgs + 486,
+ [ENOTTY] = _string_syserrmsgs + 506,
+ [ETXTBSY] = _string_syserrmsgs + 537,
+ [EFBIG] = _string_syserrmsgs + 552,
+ [ENOSPC] = _string_syserrmsgs + 567,
+ [ESPIPE] = _string_syserrmsgs + 591,
+ [EROFS] = _string_syserrmsgs + 604,
+ [EMLINK] = _string_syserrmsgs + 626,
+ [EPIPE] = _string_syserrmsgs + 641,
+ [EDOM] = _string_syserrmsgs + 653,
+ [ERANGE] = _string_syserrmsgs + 686,
+ [EDEADLK] = _string_syserrmsgs + 716,
+ [ENAMETOOLONG] = _string_syserrmsgs + 742,
+ [ENOLCK] = _string_syserrmsgs + 761,
+ [ENOSYS] = _string_syserrmsgs + 780,
+ [ENOTEMPTY] = _string_syserrmsgs + 805,
+ [ELOOP] = _string_syserrmsgs + 825,
+ /* _string_syserrmsgs + 859, */
+ [ENOMSG] = _string_syserrmsgs + 860,
+ [EIDRM] = _string_syserrmsgs + 887,
+ [ECHRNG] = _string_syserrmsgs + 906,
+ [EL2NSYNC] = _string_syserrmsgs + 934,
+ [EL3HLT] = _string_syserrmsgs + 959,
+ [EL3RST] = _string_syserrmsgs + 974,
+ [ELNRNG] = _string_syserrmsgs + 988,
+ [EUNATCH] = _string_syserrmsgs + 1013,
+ [ENOCSI] = _string_syserrmsgs + 1042,
+ [EL2HLT] = _string_syserrmsgs + 1069,
+ [EBADE] = _string_syserrmsgs + 1084,
+ [EBADR] = _string_syserrmsgs + 1101,
+ [EXFULL] = _string_syserrmsgs + 1128,
+ [ENOANO] = _string_syserrmsgs + 1142,
+ [EBADRQC] = _string_syserrmsgs + 1151,
+ [EBADSLT] = _string_syserrmsgs + 1172,
+ /* _string_syserrmsgs + 1185, */
+ [EBFONT] = _string_syserrmsgs + 1186,
+ [ENOSTR] = _string_syserrmsgs + 1207,
+ [ENODATA] = _string_syserrmsgs + 1227,
+ [ETIME] = _string_syserrmsgs + 1245,
+ [ENOSR] = _string_syserrmsgs + 1259,
+ [ENONET] = _string_syserrmsgs + 1284,
+ [ENOPKG] = _string_syserrmsgs + 1314,
+ [EREMOTE] = _string_syserrmsgs + 1336,
+ [ENOLINK] = _string_syserrmsgs + 1353,
+ [EADV] = _string_syserrmsgs + 1375,
+ [ESRMNT] = _string_syserrmsgs + 1391,
+ [ECOMM] = _string_syserrmsgs + 1405,
+ [EPROTO] = _string_syserrmsgs + 1433,
+ [EMULTIHOP] = _string_syserrmsgs + 1448,
+ [EDOTDOT] = _string_syserrmsgs + 1467,
+ [EBADMSG] = _string_syserrmsgs + 1486,
+ [EOVERFLOW] = _string_syserrmsgs + 1498,
+ [ENOTUNIQ] = _string_syserrmsgs + 1536,
+ [EBADFD] = _string_syserrmsgs + 1563,
+ [EREMCHG] = _string_syserrmsgs + 1592,
+ [ELIBACC] = _string_syserrmsgs + 1615,
+ [ELIBBAD] = _string_syserrmsgs + 1654,
+ [ELIBSCN] = _string_syserrmsgs + 1691,
+ [ELIBMAX] = _string_syserrmsgs + 1723,
+ [ELIBEXEC] = _string_syserrmsgs + 1771,
+ [EILSEQ] = _string_syserrmsgs + 1809,
+ [ERESTART] = _string_syserrmsgs + 1859,
+ [ESTRPIPE] = _string_syserrmsgs + 1903,
+ [EUSERS] = _string_syserrmsgs + 1922,
+ [ENOTSOCK] = _string_syserrmsgs + 1937,
+ [EDESTADDRREQ] = _string_syserrmsgs + 1968,
+ [EMSGSIZE] = _string_syserrmsgs + 1997,
+ [EPROTOTYPE] = _string_syserrmsgs + 2014,
+ [ENOPROTOOPT] = _string_syserrmsgs + 2045,
+ [EPROTONOSUPPORT] = _string_syserrmsgs + 2068,
+ [ESOCKTNOSUPPORT] = _string_syserrmsgs + 2091,
+ [EOPNOTSUPP] = _string_syserrmsgs + 2117,
+ [EPFNOSUPPORT] = _string_syserrmsgs + 2141,
+ [EAFNOSUPPORT] = _string_syserrmsgs + 2171,
+ [EADDRINUSE] = _string_syserrmsgs + 2212,
+ [EADDRNOTAVAIL] = _string_syserrmsgs + 2235,
+ [ENETDOWN] = _string_syserrmsgs + 2267,
+ [ENETUNREACH] = _string_syserrmsgs + 2283,
+ [ENETRESET] = _string_syserrmsgs + 2306,
+ [ECONNABORTED] = _string_syserrmsgs + 2342,
+ [ECONNRESET] = _string_syserrmsgs + 2375,
+ [ENOBUFS] = _string_syserrmsgs + 2400,
+ [EISCONN] = _string_syserrmsgs + 2426,
+ [ENOTCONN] = _string_syserrmsgs + 2466,
+ [ESHUTDOWN] = _string_syserrmsgs + 2502,
+ [ETOOMANYREFS] = _string_syserrmsgs + 2548,
+ [ETIMEDOUT] = _string_syserrmsgs + 2583,
+ [ECONNREFUSED] = _string_syserrmsgs + 2604,
+ [EHOSTDOWN] = _string_syserrmsgs + 2623,
+ [EHOSTUNREACH] = _string_syserrmsgs + 2636,
+ [EALREADY] = _string_syserrmsgs + 2653,
+ [EINPROGRESS] = _string_syserrmsgs + 2683,
+ [ESTALE] = _string_syserrmsgs + 2709,
+ [EUCLEAN] = _string_syserrmsgs + 2731,
+ [ENOTNAM] = _string_syserrmsgs + 2756,
+ [ENAVAIL] = _string_syserrmsgs + 2784,
+ [EISNAM] = _string_syserrmsgs + 2814,
+ [EREMOTEIO] = _string_syserrmsgs + 2835,
+ [EDQUOT] = _string_syserrmsgs + 2852,
+ [ENOMEDIUM] = _string_syserrmsgs + 2872,
+ [EMEDIUMTYPE] = _string_syserrmsgs + 2888,
+
+#if EDEADLOCK != EDEADLK
+ [EDEADLOCK] = _string_syserrmsgs + 2906,
+#endif
+
+#if EWOULDBLOCK != EAGAIN
+#error EWOULDBLOCK does not equal EAGAIN
+#endif
+
+ /* For now, ignore the other arch-specific errors. glibc only maps EPROCLIM. */
+
+ /* some other mips errors */
+#ifdef ECANCELED
+#endif
+#ifdef EINIT
+#endif
+#ifdef EREMDEV
+#endif
+
+ /* some other sparc errors */
+#ifdef EPROCLIM
+#endif
+#ifdef ERREMOTE
+#endif
+};
+
+int sys_nerr = sizeof(sys_errlist)/sizeof(sys_errlist[0]);
+
+#endif
diff --git a/libc/string/sys_siglist.c b/libc/string/sys_siglist.c
new file mode 100644
index 000000000..9337d00a9
--- /dev/null
+++ b/libc/string/sys_siglist.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2002 Manuel Novoa III
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <features.h>
+#define __need_NULL
+#include <stddef.h>
+#include <signal.h>
+
+extern const char _string_syssigmsgs[];
+
+#ifdef __UCLIBC_HAS_SYS_SIGLIST__
+
+const char *const sys_siglist[_NSIG] = {
+ [0] = NULL,
+ [SIGHUP] = _string_syssigmsgs + 1,
+ [SIGINT] = _string_syssigmsgs + 8,
+ [SIGQUIT] = _string_syssigmsgs + 18,
+ [SIGILL] = _string_syssigmsgs + 23,
+ [SIGTRAP] = _string_syssigmsgs + 43,
+ [SIGABRT] = _string_syssigmsgs + 65,
+ [SIGBUS] = _string_syssigmsgs + 73,
+ [SIGFPE] = _string_syssigmsgs + 83,
+ [SIGKILL] = _string_syssigmsgs + 108,
+ [SIGUSR1] = _string_syssigmsgs + 115,
+ [SIGSEGV] = _string_syssigmsgs + 137,
+ [SIGUSR2] = _string_syssigmsgs + 156,
+ [SIGPIPE] = _string_syssigmsgs + 178,
+ [SIGALRM] = _string_syssigmsgs + 190,
+ [SIGTERM] = _string_syssigmsgs + 202,
+#if !(defined(__alpha__) || defined(__mips__) || defined(__sparc__))
+ [SIGSTKFLT] = _string_syssigmsgs + 213,
+#endif
+ [SIGCHLD] = _string_syssigmsgs + 225,
+ [SIGCONT] = _string_syssigmsgs + 238,
+ [SIGSTOP] = _string_syssigmsgs + 248,
+ [SIGTSTP] = _string_syssigmsgs + 265,
+ [SIGTTIN] = _string_syssigmsgs + 273,
+ [SIGTTOU] = _string_syssigmsgs + 293,
+ [SIGURG] = _string_syssigmsgs + 314,
+ [SIGXCPU] = _string_syssigmsgs + 335,
+ [SIGXFSZ] = _string_syssigmsgs + 359,
+ [SIGVTALRM] = _string_syssigmsgs + 384,
+ [SIGPROF] = _string_syssigmsgs + 406,
+ [SIGWINCH] = _string_syssigmsgs + 430,
+ [SIGIO] = _string_syssigmsgs + 445,
+ [SIGPWR] = _string_syssigmsgs + 458,
+ [SIGSYS] = _string_syssigmsgs + 472,
+#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
+ [SIGEMT] = _string_syssigmsgs + 488,
+#endif
+};
+
+#endif
diff --git a/libc/string/wcpcpy.c b/libc/string/wcpcpy.c
index ca65b702a..b4fc8e61d 100644
--- a/libc/string/wcpcpy.c
+++ b/libc/string/wcpcpy.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_stpcpy
#define WANT_WIDE
-#define Wstpcpy __wcpcpy
-
-#include "wstring.c"
-
-strong_alias(__wcpcpy, wcpcpy)
-
-#undef L_stpcpy
+#include "stpcpy.c"
diff --git a/libc/string/wcpncpy.c b/libc/string/wcpncpy.c
index ce942a63f..c5e5a7617 100644
--- a/libc/string/wcpncpy.c
+++ b/libc/string/wcpncpy.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_stpncpy
#define WANT_WIDE
-#define Wstpncpy __wcpncpy
-
-#include "wstring.c"
-
-strong_alias(__wcpncpy, wcpncpy)
-
-#undef L_stpncpy
+#include "stpncpy.c"
diff --git a/libc/string/wcscasecmp.c b/libc/string/wcscasecmp.c
new file mode 100644
index 000000000..95291b152
--- /dev/null
+++ b/libc/string/wcscasecmp.c
@@ -0,0 +1,8 @@
+/*
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define WANT_WIDE
+#include "strcasecmp.c"
diff --git a/libc/string/wcscasecmp_l.c b/libc/string/wcscasecmp_l.c
new file mode 100644
index 000000000..99e5723a3
--- /dev/null
+++ b/libc/string/wcscasecmp_l.c
@@ -0,0 +1,9 @@
+/*
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define WANT_WIDE
+#define __UCLIBC_DO_XLOCALE
+#include "strcasecmp.c"
diff --git a/libc/string/wcscat.c b/libc/string/wcscat.c
index b2f189662..36b4b6388 100644
--- a/libc/string/wcscat.c
+++ b/libc/string/wcscat.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strcat
#define WANT_WIDE
-#define Wstrcat __wcscat
-
-#include "wstring.c"
-
-strong_alias(__wcscat, wcscat)
-
-#undef L_strcat
+#include "strcat.c"
diff --git a/libc/string/wcschr.c b/libc/string/wcschr.c
index 6dbab9402..d16650ace 100644
--- a/libc/string/wcschr.c
+++ b/libc/string/wcschr.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strchr
#define WANT_WIDE
-#define Wstrchr __wcschr
-
-#include "wstring.c"
-
-strong_alias(__wcschr, wcschr)
-
-#undef L_strchr
+#include "strchr.c"
diff --git a/libc/string/wcschrnul.c b/libc/string/wcschrnul.c
index 6d962c7af..dc1b1bcd6 100644
--- a/libc/string/wcschrnul.c
+++ b/libc/string/wcschrnul.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strchrnul
#define WANT_WIDE
-#define Wstrchrnul __wcschrnul
-
-#include "wstring.c"
-
-strong_alias(__wcschrnul, wcschrnul)
-
-#undef L_strchrnul
+#include "strchrnul.c"
diff --git a/libc/string/wcscmp.c b/libc/string/wcscmp.c
index b2f2916bc..a33ed835e 100644
--- a/libc/string/wcscmp.c
+++ b/libc/string/wcscmp.c
@@ -4,17 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strcmp
#define WANT_WIDE
-#define Wstrcmp __wcscmp
-
-#include "wstring.c"
-
-strong_alias(__wcscmp, wcscmp)
-
-#ifdef __LOCALE_C_ONLY
-hidden_strong_alias(__wcscmp, __wcscoll)
-strong_alias(__wcscmp, wcscoll)
-#endif
-
-#undef L_strcmp
+#include "strcmp.c"
diff --git a/libc/string/wcscpy.c b/libc/string/wcscpy.c
index bf5ba0da2..347998424 100644
--- a/libc/string/wcscpy.c
+++ b/libc/string/wcscpy.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strcpy
#define WANT_WIDE
-#define Wstrcpy __wcscpy
-
-#include "wstring.c"
-
-strong_alias(__wcscpy, wcscpy)
-
-#undef L_strcpy
+#include "strcpy.c"
diff --git a/libc/string/wcscspn.c b/libc/string/wcscspn.c
index b156f8597..945ecef68 100644
--- a/libc/string/wcscspn.c
+++ b/libc/string/wcscspn.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strcspn
#define WANT_WIDE
-#define Wstrcspn __wcscspn
-
-#include "wstring.c"
-
-strong_alias(__wcscspn, wcscspn)
-
-#undef L_strcspn
+#include "strcspn.c"
diff --git a/libc/string/wcsdup.c b/libc/string/wcsdup.c
index 25043ced1..8885a2ba1 100644
--- a/libc/string/wcsdup.c
+++ b/libc/string/wcsdup.c
@@ -4,17 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strdup
#define WANT_WIDE
-#define Wstrdup __wcsdup
-
-#undef Wstrlen
-#undef Wstrcpy
-#define Wstrlen __wcslen
-#define Wstrcpy __wcscpy
-
-#include "wstring.c"
-
-strong_alias(__wcsdup, wcsdup)
-
-#undef L_strdup
+#include "strdup.c"
diff --git a/libc/string/wcslcpy.c b/libc/string/wcslcpy.c
index 283a51ed9..f62ea14e5 100644
--- a/libc/string/wcslcpy.c
+++ b/libc/string/wcslcpy.c
@@ -4,14 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strlcpy
#define WANT_WIDE
-#define Wstrlcpy __wcslcpy
-
-#include "wstring.c"
-
-#ifdef __LOCALE_C_ONLY
-weak_alias(__wcslcpy, wcsxfrm)
-#endif
-
-#undef L_strlcpy
+#include "strlcpy.c"
diff --git a/libc/string/wcslen.c b/libc/string/wcslen.c
index 746abf7d5..ac4637e89 100644
--- a/libc/string/wcslen.c
+++ b/libc/string/wcslen.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strlen
#define WANT_WIDE
-#define Wstrlen __wcslen
-
-#include "wstring.c"
-
-strong_alias(__wcslen, wcslen)
-
-#undef L_strlen
+#include "strlen.c"
diff --git a/libc/string/wcsncasecmp.c b/libc/string/wcsncasecmp.c
new file mode 100644
index 000000000..230efdadf
--- /dev/null
+++ b/libc/string/wcsncasecmp.c
@@ -0,0 +1,8 @@
+/*
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define WANT_WIDE
+#include "strncasecmp.c"
diff --git a/libc/string/wcsncasecmp_l.c b/libc/string/wcsncasecmp_l.c
new file mode 100644
index 000000000..acdb26b16
--- /dev/null
+++ b/libc/string/wcsncasecmp_l.c
@@ -0,0 +1,9 @@
+/*
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define WANT_WIDE
+#define __UCLIBC_DO_XLOCALE
+#include "strncasecmp.c"
diff --git a/libc/string/wcsncat.c b/libc/string/wcsncat.c
index 33e27e943..776f1b7b8 100644
--- a/libc/string/wcsncat.c
+++ b/libc/string/wcsncat.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strncat
#define WANT_WIDE
-#define Wstrncat __wcsncat
-
-#include "wstring.c"
-
-strong_alias(__wcsncat, wcsncat)
-
-#undef L_strncat
+#include "strncat.c"
diff --git a/libc/string/wcsncmp.c b/libc/string/wcsncmp.c
index 708846105..224844fd6 100644
--- a/libc/string/wcsncmp.c
+++ b/libc/string/wcsncmp.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strncmp
#define WANT_WIDE
-#define Wstrncmp __wcsncmp
-
-#include "wstring.c"
-
-strong_alias(__wcsncmp, wcsncmp)
-
-#undef L_strncmp
+#include "strncmp.c"
diff --git a/libc/string/wcsncpy.c b/libc/string/wcsncpy.c
index 24f6245a3..ac267e81f 100644
--- a/libc/string/wcsncpy.c
+++ b/libc/string/wcsncpy.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strncpy
#define WANT_WIDE
-#define Wstrncpy __wcsncpy
-
-#include "wstring.c"
-
-strong_alias(__wcsncpy, wcsncpy)
-
-#undef L_strncpy
+#include "strncpy.c"
diff --git a/libc/string/wcsnlen.c b/libc/string/wcsnlen.c
index e991586ed..917a2c9f7 100644
--- a/libc/string/wcsnlen.c
+++ b/libc/string/wcsnlen.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strnlen
#define WANT_WIDE
-#define Wstrnlen __wcsnlen
-
-#include "wstring.c"
-
-strong_alias(__wcsnlen, wcsnlen)
-
-#undef L_strnlen
+#include "strnlen.c"
diff --git a/libc/string/wcspbrk.c b/libc/string/wcspbrk.c
index c1b5d0bce..b416f7c2b 100644
--- a/libc/string/wcspbrk.c
+++ b/libc/string/wcspbrk.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strpbrk
#define WANT_WIDE
-#define Wstrpbrk __wcspbrk
-
-#include "wstring.c"
-
-strong_alias(__wcspbrk, wcspbrk)
-
-#undef L_strpbrk
+#include "strpbrk.c"
diff --git a/libc/string/wcsrchr.c b/libc/string/wcsrchr.c
index 256e2bdd1..3290820d5 100644
--- a/libc/string/wcsrchr.c
+++ b/libc/string/wcsrchr.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strrchr
#define WANT_WIDE
-#define Wstrrchr __wcsrchr
-
-#include "wstring.c"
-
-strong_alias(__wcsrchr, wcsrchr)
-
-#undef L_strrchr
+#include "strrchr.c"
diff --git a/libc/string/wcsspn.c b/libc/string/wcsspn.c
index 9d4aaa7cf..9716315a3 100644
--- a/libc/string/wcsspn.c
+++ b/libc/string/wcsspn.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strspn
#define WANT_WIDE
-#define Wstrspn __wcsspn
-
-#include "wstring.c"
-
-strong_alias(__wcsspn, wcsspn)
-
-#undef L_strspn
+#include "strspn.c"
diff --git a/libc/string/wcsstr.c b/libc/string/wcsstr.c
index 0f4280f1a..69a94e58f 100644
--- a/libc/string/wcsstr.c
+++ b/libc/string/wcsstr.c
@@ -4,14 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strstr
#define WANT_WIDE
-#define Wstrstr __wcsstr
-
-#include "wstring.c"
-
-strong_alias(__wcsstr, wcsstr)
-
-weak_alias(wcsstr, wcswcs)
-
-#undef L_strstr
+#include "strstr.c"
diff --git a/libc/string/wcstok.c b/libc/string/wcstok.c
index 625ee65e8..591c214a8 100644
--- a/libc/string/wcstok.c
+++ b/libc/string/wcstok.c
@@ -4,17 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_strtok_r
#define WANT_WIDE
-#define Wstrtok_r __wcstok
-
-#undef Wstrspn
-#define Wstrspn __wcsspn
-#undef Wstrpbrk
-#define Wstrpbrk __wcspbrk
-
-#include "wstring.c"
-
-strong_alias(__wcstok, wcstok)
-
-#undef L_strtok_r
+#include "strtok_r.c"
diff --git a/libc/string/wcsxfrm.c b/libc/string/wcsxfrm.c
new file mode 100644
index 000000000..8b37495af
--- /dev/null
+++ b/libc/string/wcsxfrm.c
@@ -0,0 +1,9 @@
+/*
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define WANT_WIDE
+#define L_wcsxfrm
+#include "_collate.c"
diff --git a/libc/string/wcsxfrm_l.c b/libc/string/wcsxfrm_l.c
new file mode 100644
index 000000000..67e2f170e
--- /dev/null
+++ b/libc/string/wcsxfrm_l.c
@@ -0,0 +1,10 @@
+/*
+ * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define WANT_WIDE
+#define __UCLIBC_DO_XLOCALE
+#define L_wcsxfrm_l
+#include "_collate.c"
diff --git a/libc/string/wmemchr.c b/libc/string/wmemchr.c
index 26acaf313..f4069e40c 100644
--- a/libc/string/wmemchr.c
+++ b/libc/string/wmemchr.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_memchr
#define WANT_WIDE
-#define Wmemchr __wmemchr
-
-#include "wstring.c"
-
-strong_alias(__wmemchr, wmemchr)
-
-#undef L_memchr
+#include "memchr.c"
diff --git a/libc/string/wmemcmp.c b/libc/string/wmemcmp.c
index d9274bf7a..9168705cf 100644
--- a/libc/string/wmemcmp.c
+++ b/libc/string/wmemcmp.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_memcmp
#define WANT_WIDE
-#define Wmemcmp __wmemcmp
-
-#include "wstring.c"
-
-strong_alias(__wmemcmp, wmemcmp)
-
-#undef L_memcmp
+#include "memcmp.c"
diff --git a/libc/string/wmemcpy.c b/libc/string/wmemcpy.c
index 14aaf8c71..6991ece76 100644
--- a/libc/string/wmemcpy.c
+++ b/libc/string/wmemcpy.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_memcpy
#define WANT_WIDE
-#define Wmemcpy __wmemcpy
-
-#include "wstring.c"
-
-strong_alias(__wmemcpy, wmemcpy)
-
-#undef L_memcpy
+#include "memcpy.c"
diff --git a/libc/string/wmemmove.c b/libc/string/wmemmove.c
index f7ba41fa5..17270491f 100644
--- a/libc/string/wmemmove.c
+++ b/libc/string/wmemmove.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_memmove
#define WANT_WIDE
-#define Wmemmove __wmemmove
-
-#include "wstring.c"
-
-strong_alias(__wmemmove, wmemmove)
-
-#undef L_memmove
+#include "memmove.c"
diff --git a/libc/string/wmempcpy.c b/libc/string/wmempcpy.c
index 35b4ff6a5..d995a809d 100644
--- a/libc/string/wmempcpy.c
+++ b/libc/string/wmempcpy.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_mempcpy
#define WANT_WIDE
-#define Wmempcpy __wmempcpy
-
-#include "wstring.c"
-
-strong_alias(__wmempcpy, wmempcpy)
-
-#undef L_mempcpy
+#include "mempcpy.c"
diff --git a/libc/string/wmemset.c b/libc/string/wmemset.c
index 9505cb7cb..0efe17833 100644
--- a/libc/string/wmemset.c
+++ b/libc/string/wmemset.c
@@ -4,12 +4,5 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_memset
#define WANT_WIDE
-#define Wmemset __wmemset
-
-#include "wstring.c"
-
-strong_alias(__wmemset, wmemset)
-
-#undef L_memset
+#include "memset.c"
diff --git a/libc/string/wstring.c b/libc/string/wstring.c
deleted file mode 100644
index c3ac10667..000000000
--- a/libc/string/wstring.c
+++ /dev/null
@@ -1,3246 +0,0 @@
-/*
- * Copyright (C) 2002 Manuel Novoa III
- * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
- *
- * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
- */
-
-/* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
- *
- * Besides uClibc, I'm using this code in my libc for elks, which is
- * a 16-bit environment with a fairly limited compiler. It would make
- * things much easier for me if this file isn't modified unnecessarily.
- * In particular, please put any new or replacement functions somewhere
- * else, and modify the makefile to use your version instead.
- * Thanks. Manuel
- *
- * ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! */
-
-/* Dec 20, 2002
- * Initial test implementation of strcoll, strxfrm, wcscoll, and wcsxfrm.
- * The code needs to be cleaned up a good bit, but I'd like to see people
- * test it out.
- *
- * Sep 11, 2003
- * Patch by Atsushi Nemoto <anemo@mba.ocn.ne.jp> to do arch-required
- * mapping of signal strings (alpha, mips, hppa, sparc).
- */
-
-#define _GNU_SOURCE
-#include <features.h>
-#include <string.h>
-#include <strings.h>
-#include <stdio.h>
-#include <limits.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <signal.h>
-#include <assert.h>
-#include <locale.h>
-#include <bits/uClibc_uintmaxtostr.h>
-
-#ifdef WANT_WIDE
-#include <wchar.h>
-#include <wctype.h>
-#include <bits/uClibc_uwchar.h>
-
-#define Wvoid wchar_t
-#define Wchar wchar_t
-#define Wuchar __uwchar_t
-#define Wint wchar_t
-
-#else
-
-#define Wvoid void
-#define Wchar char
-typedef unsigned char __string_uchar_t;
-#define Wuchar __string_uchar_t
-#define Wint int
-
-#endif
-
-
-extern size_t __strnlen (__const char *__string, size_t __maxlen) attribute_hidden;
-extern char *__strpbrk (__const char *__s, __const char *__accept) attribute_hidden;
-extern size_t __strspn (__const char *__s, __const char *__accept) attribute_hidden;
-extern char *__strsignal (int __sig) attribute_hidden;
-extern char *__strtok_r (char *__restrict __s,
- __const char *__restrict __delim,
- char **__restrict __save_ptr) attribute_hidden;
-extern size_t __strlcpy(char *__restrict dst, const char *__restrict src,
- size_t n) attribute_hidden;
-
-#ifdef WANT_WIDE
-extern wchar_t *__wcsdup (__const wchar_t *__s) attribute_hidden;
-extern size_t __wcslen (__const wchar_t *__s) attribute_hidden;
-extern wchar_t *__wcscpy (wchar_t *__restrict __dest,
- __const wchar_t *__restrict __src) attribute_hidden;
-extern size_t __wcsspn (__const wchar_t *__wcs, __const wchar_t *__accept) attribute_hidden;
-extern wchar_t *__wcspbrk (__const wchar_t *__wcs, __const wchar_t *__accept) attribute_hidden;
-extern int __wcscmp (__const wchar_t *__s1, __const wchar_t *__s2) attribute_hidden;
-extern size_t __wcsxfrm (wchar_t *__restrict __s1,
- __const wchar_t *__restrict __s2, size_t __n) attribute_hidden;
-#endif
-#ifdef __UCLIBC_HAS_XLOCALE__
-extern int __strcoll_l (__const char *__s1, __const char *__s2, __locale_t __l) attribute_hidden;
-extern size_t __strxfrm_l (char *__dest, __const char *__src, size_t __n, __locale_t __l) attribute_hidden;
-extern int __strcasecmp_l (__const char *__s1, __const char *__s2, __locale_t __loc) attribute_hidden;
-extern int __strncasecmp_l (__const char *__s1, __const char *__s2, size_t __n, __locale_t __loc) attribute_hidden;
-extern int __wcscasecmp_l (__const wchar_t *__s1, __const wchar_t *__s2, __locale_t __loc) attribute_hidden;
-extern int __wcsncasecmp_l (__const wchar_t *__s1, __const wchar_t *__s2, size_t __n, __locale_t __loc) attribute_hidden;
-extern int __wcscoll_l (__const wchar_t *__s1, __const wchar_t *__s2, __locale_t __loc) attribute_hidden;
-extern size_t __wcsxfrm_l (wchar_t *__s1, __const wchar_t *__s2, size_t __n, __locale_t __loc) attribute_hidden;
-#ifdef __UCLIBC_DO_XLOCALE
-extern wint_t __towlower_l(wint_t __wc, __locale_t __locale) __THROW;
-#endif
-#endif
-
-/**********************************************************************/
-/* NOTE: If we ever do internationalized syserr messages, this will
- * have to be changed! */
-
-#define _SYS_NERR 125
-#if defined(__mips__) || defined(__sparc__)
-/* sparce and mips have an extra error entry, as EDEADLK and EDEADLOCK have
- * different meanings on those platforms. */
-#undef _SYS_NERR
-#define _SYS_NERR 126
-#endif
-
-#ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
-#define _SYS_ERRMSG_MAXLEN 50
-#else /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
-#define _SYS_ERRMSG_MAXLEN 0
-#endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
-
-
-extern const char _string_syserrmsgs[];
-
-#define _SYS_NSIG 32
-
-#ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
-#define _SYS_SIGMSG_MAXLEN 25
-#else /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
-#define _SYS_SIGMSG_MAXLEN 0
-#endif /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
-
-extern const char _string_syssigmsgs[];
-
-
-#if _SYS_ERRMSG_MAXLEN < __UIM_BUFLEN_INT + 14
-#define _STRERROR_BUFSIZE (__UIM_BUFLEN_INT + 14)
-#else
-#define _STRERROR_BUFSIZE _SYS_ERRMSG_MAXLEN
-#endif
-
-#if _SYS_SIGMSG_MAXLEN < __UIM_BUFLEN_INT + 15
-#define _STRSIGNAL_BUFSIZE (__UIM_BUFLEN_INT + 15)
-#else
-#define _STRSIGNAL_BUFSIZE _SYS_SIGMSG_MAXLEN
-#endif
-
-/**********************************************************************/
-#if defined(L__string_syserrmsgs) && defined(__UCLIBC_HAS_ERRNO_MESSAGES__)
-
-const char _string_syserrmsgs[] = {
- /* 0: 0, 8 */ "Success\0"
- /* 1: 8, 24 */ "Operation not permitted\0"
- /* 2: 32, 26 */ "No such file or directory\0"
- /* 3: 58, 16 */ "No such process\0"
- /* 4: 74, 24 */ "Interrupted system call\0"
- /* 5: 98, 19 */ "Input/output error\0"
- /* 6: 117, 26 */ "No such device or address\0"
- /* 7: 143, 23 */ "Argument list too long\0"
- /* 8: 166, 18 */ "Exec format error\0"
- /* 9: 184, 20 */ "Bad file descriptor\0"
- /* 10: 204, 19 */ "No child processes\0"
- /* 11: 223, 33 */ "Resource temporarily unavailable\0"
- /* 12: 256, 23 */ "Cannot allocate memory\0"
- /* 13: 279, 18 */ "Permission denied\0"
- /* 14: 297, 12 */ "Bad address\0"
- /* 15: 309, 22 */ "Block device required\0"
- /* 16: 331, 24 */ "Device or resource busy\0"
- /* 17: 355, 12 */ "File exists\0"
- /* 18: 367, 26 */ "Invalid cross-device link\0"
- /* 19: 393, 15 */ "No such device\0"
- /* 20: 408, 16 */ "Not a directory\0"
- /* 21: 424, 15 */ "Is a directory\0"
- /* 22: 439, 17 */ "Invalid argument\0"
- /* 23: 456, 30 */ "Too many open files in system\0"
- /* 24: 486, 20 */ "Too many open files\0"
- /* 25: 506, 31 */ "Inappropriate ioctl for device\0"
- /* 26: 537, 15 */ "Text file busy\0"
- /* 27: 552, 15 */ "File too large\0"
- /* 28: 567, 24 */ "No space left on device\0"
- /* 29: 591, 13 */ "Illegal seek\0"
- /* 30: 604, 22 */ "Read-only file system\0"
- /* 31: 626, 15 */ "Too many links\0"
- /* 32: 641, 12 */ "Broken pipe\0"
- /* 33: 653, 33 */ "Numerical argument out of domain\0"
- /* 34: 686, 30 */ "Numerical result out of range\0"
- /* 35: 716, 26 */ "Resource deadlock avoided\0"
- /* 36: 742, 19 */ "File name too long\0"
- /* 37: 761, 19 */ "No locks available\0"
- /* 38: 780, 25 */ "Function not implemented\0"
- /* 39: 805, 20 */ "Directory not empty\0"
- /* 40: 825, 34 */ "Too many levels of symbolic links\0"
- /* 41: 859, 1 */ "\0"
- /* 42: 860, 27 */ "No message of desired type\0"
- /* 43: 887, 19 */ "Identifier removed\0"
- /* 44: 906, 28 */ "Channel number out of range\0"
- /* 45: 934, 25 */ "Level 2 not synchronized\0"
- /* 46: 959, 15 */ "Level 3 halted\0"
- /* 47: 974, 14 */ "Level 3 reset\0"
- /* 48: 988, 25 */ "Link number out of range\0"
- /* 49: 1013, 29 */ "Protocol driver not attached\0"
- /* 50: 1042, 27 */ "No CSI structure available\0"
- /* 51: 1069, 15 */ "Level 2 halted\0"
- /* 52: 1084, 17 */ "Invalid exchange\0"
- /* 53: 1101, 27 */ "Invalid request descriptor\0"
- /* 54: 1128, 14 */ "Exchange full\0"
- /* 55: 1142, 9 */ "No anode\0"
- /* 56: 1151, 21 */ "Invalid request code\0"
- /* 57: 1172, 13 */ "Invalid slot\0"
- /* 58: 1185, 1 */ "\0"
- /* 59: 1186, 21 */ "Bad font file format\0"
- /* 60: 1207, 20 */ "Device not a stream\0"
- /* 61: 1227, 18 */ "No data available\0"
- /* 62: 1245, 14 */ "Timer expired\0"
- /* 63: 1259, 25 */ "Out of streams resources\0"
- /* 64: 1284, 30 */ "Machine is not on the network\0"
- /* 65: 1314, 22 */ "Package not installed\0"
- /* 66: 1336, 17 */ "Object is remote\0"
- /* 67: 1353, 22 */ "Link has been severed\0"
- /* 68: 1375, 16 */ "Advertise error\0"
- /* 69: 1391, 14 */ "Srmount error\0"
- /* 70: 1405, 28 */ "Communication error on send\0"
- /* 71: 1433, 15 */ "Protocol error\0"
- /* 72: 1448, 19 */ "Multihop attempted\0"
- /* 73: 1467, 19 */ "RFS specific error\0"
- /* 74: 1486, 12 */ "Bad message\0"
- /* 75: 1498, 38 */ "Value too large for defined data type\0"
- /* 76: 1536, 27 */ "Name not unique on network\0"
- /* 77: 1563, 29 */ "File descriptor in bad state\0"
- /* 78: 1592, 23 */ "Remote address changed\0"
- /* 79: 1615, 39 */ "Can not access a needed shared library\0"
- /* 80: 1654, 37 */ "Accessing a corrupted shared library\0"
- /* 81: 1691, 32 */ ".lib section in a.out corrupted\0"
- /* 82: 1723, 48 */ "Attempting to link in too many shared libraries\0"
- /* 83: 1771, 38 */ "Cannot exec a shared library directly\0"
- /* 84: 1809, 50 */ "Invalid or incomplete multibyte or wide character\0"
- /* 85: 1859, 44 */ "Interrupted system call should be restarted\0"
- /* 86: 1903, 19 */ "Streams pipe error\0"
- /* 87: 1922, 15 */ "Too many users\0"
- /* 88: 1937, 31 */ "Socket operation on non-socket\0"
- /* 89: 1968, 29 */ "Destination address required\0"
- /* 90: 1997, 17 */ "Message too long\0"
- /* 91: 2014, 31 */ "Protocol wrong type for socket\0"
- /* 92: 2045, 23 */ "Protocol not available\0"
- /* 93: 2068, 23 */ "Protocol not supported\0"
- /* 94: 2091, 26 */ "Socket type not supported\0"
- /* 95: 2117, 24 */ "Operation not supported\0"
- /* 96: 2141, 30 */ "Protocol family not supported\0"
- /* 97: 2171, 41 */ "Address family not supported by protocol\0"
- /* 98: 2212, 23 */ "Address already in use\0"
- /* 99: 2235, 32 */ "Cannot assign requested address\0"
- /* 100: 2267, 16 */ "Network is down\0"
- /* 101: 2283, 23 */ "Network is unreachable\0"
- /* 102: 2306, 36 */ "Network dropped connection on reset\0"
- /* 103: 2342, 33 */ "Software caused connection abort\0"
- /* 104: 2375, 25 */ "Connection reset by peer\0"
- /* 105: 2400, 26 */ "No buffer space available\0"
- /* 106: 2426, 40 */ "Transport endpoint is already connected\0"
- /* 107: 2466, 36 */ "Transport endpoint is not connected\0"
- /* 108: 2502, 46 */ "Cannot send after transport endpoint shutdown\0"
- /* 109: 2548, 35 */ "Too many references: cannot splice\0"
- /* 110: 2583, 21 */ "Connection timed out\0"
- /* 111: 2604, 19 */ "Connection refused\0"
- /* 112: 2623, 13 */ "Host is down\0"
- /* 113: 2636, 17 */ "No route to host\0"
- /* 114: 2653, 30 */ "Operation already in progress\0"
- /* 115: 2683, 26 */ "Operation now in progress\0"
- /* 116: 2709, 22 */ "Stale NFS file handle\0"
- /* 117: 2731, 25 */ "Structure needs cleaning\0"
- /* 118: 2756, 28 */ "Not a XENIX named type file\0"
- /* 119: 2784, 30 */ "No XENIX semaphores available\0"
- /* 120: 2814, 21 */ "Is a named type file\0"
- /* 121: 2835, 17 */ "Remote I/O error\0"
- /* 122: 2852, 20 */ "Disk quota exceeded\0"
- /* 123: 2872, 16 */ "No medium found\0"
- /* 124: 2888, 18 */ "Wrong medium type"
-#if defined(__mips__) || defined(__sparc__)
- "\0"
- /* 125: 2906, 28 */ "File locking deadlock error"
-#endif
- /* Note: for mips we are ignoring ECANCELED since glibc doesn't have a
- * corresponsding message.*/
-};
-
-#endif
-/**********************************************************************/
-#if defined(L_sys_errlist) && defined(__UCLIBC_HAS_SYS_ERRLIST__)
-
-link_warning(_sys_errlist, "sys_nerr and sys_errlist are obsolete and uClibc support for them (in at least some configurations) will probably be unavailable in the near future.")
-
-const char *const sys_errlist[] = {
- [0] = _string_syserrmsgs + 0,
- [EPERM] = _string_syserrmsgs + 8,
- [ENOENT] = _string_syserrmsgs + 32,
- [ESRCH] = _string_syserrmsgs + 58,
- [EINTR] = _string_syserrmsgs + 74,
- [EIO] = _string_syserrmsgs + 98,
- [ENXIO] = _string_syserrmsgs + 117,
- [E2BIG] = _string_syserrmsgs + 143,
- [ENOEXEC] = _string_syserrmsgs + 166,
- [EBADF] = _string_syserrmsgs + 184,
- [ECHILD] = _string_syserrmsgs + 204,
- [EAGAIN] = _string_syserrmsgs + 223,
- [ENOMEM] = _string_syserrmsgs + 256,
- [EACCES] = _string_syserrmsgs + 279,
- [EFAULT] = _string_syserrmsgs + 297,
- [ENOTBLK] = _string_syserrmsgs + 309,
- [EBUSY] = _string_syserrmsgs + 331,
- [EEXIST] = _string_syserrmsgs + 355,
- [EXDEV] = _string_syserrmsgs + 367,
- [ENODEV] = _string_syserrmsgs + 393,
- [ENOTDIR] = _string_syserrmsgs + 408,
- [EISDIR] = _string_syserrmsgs + 424,
- [EINVAL] = _string_syserrmsgs + 439,
- [ENFILE] = _string_syserrmsgs + 456,
- [EMFILE] = _string_syserrmsgs + 486,
- [ENOTTY] = _string_syserrmsgs + 506,
- [ETXTBSY] = _string_syserrmsgs + 537,
- [EFBIG] = _string_syserrmsgs + 552,
- [ENOSPC] = _string_syserrmsgs + 567,
- [ESPIPE] = _string_syserrmsgs + 591,
- [EROFS] = _string_syserrmsgs + 604,
- [EMLINK] = _string_syserrmsgs + 626,
- [EPIPE] = _string_syserrmsgs + 641,
- [EDOM] = _string_syserrmsgs + 653,
- [ERANGE] = _string_syserrmsgs + 686,
- [EDEADLK] = _string_syserrmsgs + 716,
- [ENAMETOOLONG] = _string_syserrmsgs + 742,
- [ENOLCK] = _string_syserrmsgs + 761,
- [ENOSYS] = _string_syserrmsgs + 780,
- [ENOTEMPTY] = _string_syserrmsgs + 805,
- [ELOOP] = _string_syserrmsgs + 825,
- /* _string_syserrmsgs + 859, */
- [ENOMSG] = _string_syserrmsgs + 860,
- [EIDRM] = _string_syserrmsgs + 887,
- [ECHRNG] = _string_syserrmsgs + 906,
- [EL2NSYNC] = _string_syserrmsgs + 934,
- [EL3HLT] = _string_syserrmsgs + 959,
- [EL3RST] = _string_syserrmsgs + 974,
- [ELNRNG] = _string_syserrmsgs + 988,
- [EUNATCH] = _string_syserrmsgs + 1013,
- [ENOCSI] = _string_syserrmsgs + 1042,
- [EL2HLT] = _string_syserrmsgs + 1069,
- [EBADE] = _string_syserrmsgs + 1084,
- [EBADR] = _string_syserrmsgs + 1101,
- [EXFULL] = _string_syserrmsgs + 1128,
- [ENOANO] = _string_syserrmsgs + 1142,
- [EBADRQC] = _string_syserrmsgs + 1151,
- [EBADSLT] = _string_syserrmsgs + 1172,
- /* _string_syserrmsgs + 1185, */
- [EBFONT] = _string_syserrmsgs + 1186,
- [ENOSTR] = _string_syserrmsgs + 1207,
- [ENODATA] = _string_syserrmsgs + 1227,
- [ETIME] = _string_syserrmsgs + 1245,
- [ENOSR] = _string_syserrmsgs + 1259,
- [ENONET] = _string_syserrmsgs + 1284,
- [ENOPKG] = _string_syserrmsgs + 1314,
- [EREMOTE] = _string_syserrmsgs + 1336,
- [ENOLINK] = _string_syserrmsgs + 1353,
- [EADV] = _string_syserrmsgs + 1375,
- [ESRMNT] = _string_syserrmsgs + 1391,
- [ECOMM] = _string_syserrmsgs + 1405,
- [EPROTO] = _string_syserrmsgs + 1433,
- [EMULTIHOP] = _string_syserrmsgs + 1448,
- [EDOTDOT] = _string_syserrmsgs + 1467,
- [EBADMSG] = _string_syserrmsgs + 1486,
- [EOVERFLOW] = _string_syserrmsgs + 1498,
- [ENOTUNIQ] = _string_syserrmsgs + 1536,
- [EBADFD] = _string_syserrmsgs + 1563,
- [EREMCHG] = _string_syserrmsgs + 1592,
- [ELIBACC] = _string_syserrmsgs + 1615,
- [ELIBBAD] = _string_syserrmsgs + 1654,
- [ELIBSCN] = _string_syserrmsgs + 1691,
- [ELIBMAX] = _string_syserrmsgs + 1723,
- [ELIBEXEC] = _string_syserrmsgs + 1771,
- [EILSEQ] = _string_syserrmsgs + 1809,
- [ERESTART] = _string_syserrmsgs + 1859,
- [ESTRPIPE] = _string_syserrmsgs + 1903,
- [EUSERS] = _string_syserrmsgs + 1922,
- [ENOTSOCK] = _string_syserrmsgs + 1937,
- [EDESTADDRREQ] = _string_syserrmsgs + 1968,
- [EMSGSIZE] = _string_syserrmsgs + 1997,
- [EPROTOTYPE] = _string_syserrmsgs + 2014,
- [ENOPROTOOPT] = _string_syserrmsgs + 2045,
- [EPROTONOSUPPORT] = _string_syserrmsgs + 2068,
- [ESOCKTNOSUPPORT] = _string_syserrmsgs + 2091,
- [EOPNOTSUPP] = _string_syserrmsgs + 2117,
- [EPFNOSUPPORT] = _string_syserrmsgs + 2141,
- [EAFNOSUPPORT] = _string_syserrmsgs + 2171,
- [EADDRINUSE] = _string_syserrmsgs + 2212,
- [EADDRNOTAVAIL] = _string_syserrmsgs + 2235,
- [ENETDOWN] = _string_syserrmsgs + 2267,
- [ENETUNREACH] = _string_syserrmsgs + 2283,
- [ENETRESET] = _string_syserrmsgs + 2306,
- [ECONNABORTED] = _string_syserrmsgs + 2342,
- [ECONNRESET] = _string_syserrmsgs + 2375,
- [ENOBUFS] = _string_syserrmsgs + 2400,
- [EISCONN] = _string_syserrmsgs + 2426,
- [ENOTCONN] = _string_syserrmsgs + 2466,
- [ESHUTDOWN] = _string_syserrmsgs + 2502,
- [ETOOMANYREFS] = _string_syserrmsgs + 2548,
- [ETIMEDOUT] = _string_syserrmsgs + 2583,
- [ECONNREFUSED] = _string_syserrmsgs + 2604,
- [EHOSTDOWN] = _string_syserrmsgs + 2623,
- [EHOSTUNREACH] = _string_syserrmsgs + 2636,
- [EALREADY] = _string_syserrmsgs + 2653,
- [EINPROGRESS] = _string_syserrmsgs + 2683,
- [ESTALE] = _string_syserrmsgs + 2709,
- [EUCLEAN] = _string_syserrmsgs + 2731,
- [ENOTNAM] = _string_syserrmsgs + 2756,
- [ENAVAIL] = _string_syserrmsgs + 2784,
- [EISNAM] = _string_syserrmsgs + 2814,
- [EREMOTEIO] = _string_syserrmsgs + 2835,
- [EDQUOT] = _string_syserrmsgs + 2852,
- [ENOMEDIUM] = _string_syserrmsgs + 2872,
- [EMEDIUMTYPE] = _string_syserrmsgs + 2888,
-
-#if EDEADLOCK != EDEADLK
- [EDEADLOCK] = _string_syserrmsgs + 2906,
-#endif
-
-#if EWOULDBLOCK != EAGAIN
-#error EWOULDBLOCK does not equal EAGAIN
-#endif
-
- /* For now, ignore the other arch-specific errors. glibc only maps EPROCLIM. */
-
- /* some other mips errors */
-#ifdef ECANCELED
-#endif
-#ifdef EINIT
-#endif
-#ifdef EREMDEV
-#endif
-
- /* some other sparc errors */
-#ifdef EPROCLIM
-#endif
-#ifdef ERREMOTE
-#endif
-};
-
-int sys_nerr = sizeof(sys_errlist)/sizeof(sys_errlist[0]);
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmemcpy
-#define L_memcpy
-#define Wmemcpy wmemcpy
-#else
-#define Wmemcpy memcpy
-#endif
-#endif
-
-#ifdef L_memcpy
-
-#ifndef WANT_WIDE
-#undef memcpy
-#else
-#undef wmemcpy
-#endif
-Wvoid attribute_hidden *Wmemcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
-{
- register Wchar *r1 = s1;
- register const Wchar *r2 = s2;
-
-#ifdef __BCC__
- while (n--) {
- *r1++ = *r2++;
- }
-#else
- while (n) {
- *r1++ = *r2++;
- --n;
- }
-#endif
-
- return s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmemmove
-#define L_memmove
-#define Wmemmove wmemmove
-#else
-#define Wmemmove memmove
-#endif
-#endif
-
-#ifdef L_memmove
-
-#ifndef WANT_WIDE
-#undef memmove
-#else
-#undef wmemmove
-#endif
-Wvoid attribute_hidden *Wmemmove(Wvoid *s1, const Wvoid *s2, size_t n)
-{
-#ifdef __BCC__
- register Wchar *s = (Wchar *) s1;
- register const Wchar *p = (const Wchar *) s2;
-
- if (p >= s) {
- while (n--) {
- *s++ = *p++;
- }
- } else {
- s += n;
- p += n;
- while (n--) {
- *--s = *--p;
- }
- }
-
- return s1;
-#else
- register Wchar *s = (Wchar *) s1;
- register const Wchar *p = (const Wchar *) s2;
-
- if (p >= s) {
- while (n) {
- *s++ = *p++;
- --n;
- }
- } else {
- while (n) {
- --n;
- s[n] = p[n];
- }
- }
-
- return s1;
-#endif
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcscpy
-#define L_strcpy
-#define Wstrcpy wcscpy
-#else
-#define Wstrcpy strcpy
-#endif
-#endif
-
-#ifdef L_strcpy
-
-#ifndef WANT_WIDE
-#undef strcpy
-#else
-#undef wcscpy
-#endif
-Wchar attribute_hidden *Wstrcpy(Wchar * __restrict s1, const Wchar * __restrict s2)
-{
- register Wchar *s = s1;
-
-#ifdef __BCC__
- do {
- *s = *s2++;
- } while (*s++ != 0);
-#else
- while ( (*s++ = *s2++) != 0 );
-#endif
-
- return s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsncpy
-#define L_strncpy
-#define Wstrncpy wcsncpy
-#else
-#define Wstrncpy strncpy
-#endif
-#endif
-
-#ifdef L_strncpy
-
-#ifndef WANT_WIDE
-#undef strncpy
-#else
-#undef wcsncpy
-#endif
-Wchar attribute_hidden *Wstrncpy(Wchar * __restrict s1, register const Wchar * __restrict s2,
- size_t n)
-{
- register Wchar *s = s1;
-
-#ifdef __BCC__
- while (n--) {
- if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
- ++s;
- }
-#else
- while (n) {
- if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
- ++s;
- --n;
- }
-#endif
-
- return s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcscat
-#define L_strcat
-#define Wstrcat wcscat
-#else
-#define Wstrcat strcat
-#endif
-#endif
-
-#ifdef L_strcat
-
-#ifndef WANT_WIDE
-#undef strcat
-#else
-#undef wcscat
-#endif
-Wchar attribute_hidden *Wstrcat(Wchar * __restrict s1, register const Wchar * __restrict s2)
-{
- register Wchar *s = s1;
-
- while (*s++);
- --s;
- while ((*s++ = *s2++) != 0);
-
- return s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsncat
-#define L_strncat
-#define Wstrncat wcsncat
-#else
-#define Wstrncat strncat
-#endif
-#endif
-
-#ifdef L_strncat
-
-#ifndef WANT_WIDE
-#undef strncat
-#else
-#undef wcsncat
-#endif
-Wchar attribute_hidden *Wstrncat(Wchar * __restrict s1, register const Wchar * __restrict s2,
- size_t n)
-{
- register Wchar *s = s1;
-
- while (*s++);
- --s;
-#if __BCC__
- while (n-- && ((*s = *s2++) != 0)) ++s;
-#else
- while (n && ((*s = *s2++) != 0)) {
- --n;
- ++s;
- }
-#endif
- *s = 0;
-
- return s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmemcmp
-#define L_memcmp
-#define Wmemcmp wmemcmp
-#else
-#define Wmemcmp memcmp
-#endif
-#endif
-
-#ifdef L_memcmp
-
-#ifndef WANT_WIDE
-#undef memcmp
-#else
-#undef wmemcmp
-#endif
-int attribute_hidden Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n)
-{
- register const Wuchar *r1 = (const Wuchar *) s1;
- register const Wuchar *r2 = (const Wuchar *) s2;
-
-#ifdef WANT_WIDE
- while (n && (*r1 == *r2)) {
- ++r1;
- ++r2;
- --n;
- }
-
- return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);
-#else
- int r = 0;
-
- while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0));
-
- return r;
-#endif
-}
-
-#if 0 /* ndef L_wmemcmp */
-weak_alias(memcmp, bcmp)
-#endif
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcscmp
-#define L_strcmp
-#define Wstrcmp wcscmp
-#else
-#define Wstrcmp strcmp
-#endif
-#endif
-
-#ifdef L_strcmp
-
-#ifndef WANT_WIDE
-#undef strcmp
-#else
-#undef wcscmp
-#endif
-int attribute_hidden Wstrcmp(register const Wchar *s1, register const Wchar *s2)
-{
-#ifdef WANT_WIDE
- while (*((Wuchar *)s1) == *((Wuchar *)s2)) {
- if (!*s1++) {
- return 0;
- }
- ++s2;
- }
-
- return (*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1;
-#else
- int r;
-
- while (((r = ((int)(*((Wuchar *)s1))) - *((Wuchar *)s2++))
- == 0) && *s1++);
-
- return r;
-#endif
-}
-
-#if 0 /* def __LOCALE_C_ONLY */
-#ifdef L_wcscmp
-weak_alias(wcscmp, wcscoll)
-#else /* L_wcscmp */
-weak_alias(strcmp, strcoll)
-#endif /* L_wcscmp */
-#endif /* __LOCALE_C_ONLY */
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsncmp
-#define L_strncmp
-#define Wstrncmp wcsncmp
-#else
-#define Wstrncmp strncmp
-#endif
-#endif
-
-#ifdef L_strncmp
-
-#ifndef WANT_WIDE
-#undef strncmp
-#else
-#undef wcsncmp
-#endif
-int attribute_hidden Wstrncmp(register const Wchar *s1, register const Wchar *s2, size_t n)
-{
-#ifdef WANT_WIDE
- while (n && (*((Wuchar *)s1) == *((Wuchar *)s2))) {
- if (!*s1++) {
- return 0;
- }
- ++s2;
- --n;
- }
-
- return (n == 0) ? 0 : ((*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1);
-#else
- int r = 0;
-
- while (n--
- && ((r = ((int)(*((unsigned char *)s1))) - *((unsigned char *)s2++))
- == 0)
- && *s1++);
-
- return r;
-#endif
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmemchr
-#define L_memchr
-#define Wmemchr wmemchr
-#else
-#define Wmemchr memchr
-#endif
-#endif
-
-#ifdef L_memchr
-
-#ifndef WANT_WIDE
-#undef memchr
-#else
-#undef wmemchr
-#endif
-Wvoid attribute_hidden *Wmemchr(const Wvoid *s, Wint c, size_t n)
-{
- register const Wuchar *r = (const Wuchar *) s;
-#ifdef __BCC__
- /* bcc can optimize the counter if it thinks it is a pointer... */
- register const char *np = (const char *) n;
-#else
-#define np n
-#endif
-
- while (np) {
- if (*r == ((Wuchar)c)) {
- return (Wvoid *) r; /* silence the warning */
- }
- ++r;
- --np;
- }
-
- return NULL;
-}
-#undef np
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcschr
-#define L_strchr
-#define Wstrchr wcschr
-#else
-#define Wstrchr strchr
-#endif
-#endif
-
-#ifdef L_strchr
-
-#ifndef WANT_WIDE
-#undef strchr
-#else
-#undef wcschr
-#endif
-Wchar attribute_hidden *Wstrchr(register const Wchar *s, Wint c)
-{
- do {
- if (*s == ((Wchar)c)) {
- return (Wchar *) s; /* silence the warning */
- }
- } while (*s++);
-
- return NULL;
-}
-
-#if 0 /* ndef L_wcschr */
-weak_alias(strchr, index)
-#endif
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcscspn
-#define L_strcspn
-#define Wstrcspn wcscspn
-#else
-#define Wstrcspn strcspn
-#endif
-#endif
-
-#ifdef L_strcspn
-
-#ifndef WANT_WIDE
-#undef strcspn
-#else
-#undef wcscspn
-#endif
-size_t attribute_hidden Wstrcspn(const Wchar *s1, const Wchar *s2)
-{
- register const Wchar *s;
- register const Wchar *p;
-
- for ( s=s1 ; *s ; s++ ) {
- for ( p=s2 ; *p ; p++ ) {
- if (*p == *s) goto done;
- }
- }
- done:
- return s - s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcspbrk
-#define L_strpbrk
-#define Wstrpbrk wcspbrk
-#else
-#define Wstrpbrk strpbrk
-#endif
-#endif
-
-#ifdef L_strpbrk
-
-#ifndef WANT_WIDE
-#undef strpbrk
-#else
-#undef wcspbrk
-#endif
-Wchar attribute_hidden *Wstrpbrk(const Wchar *s1, const Wchar *s2)
-{
- register const Wchar *s;
- register const Wchar *p;
-
- for ( s=s1 ; *s ; s++ ) {
- for ( p=s2 ; *p ; p++ ) {
- if (*p == *s) return (Wchar *) s; /* silence the warning */
- }
- }
- return NULL;
-}
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsrchr
-#define L_strrchr
-#define Wstrrchr wcsrchr
-#else
-#define Wstrrchr strrchr
-#endif
-#endif
-
-#ifdef L_strrchr
-
-#ifndef WANT_WIDE
-#undef strrchr
-#else
-#undef wcsrchr
-#endif
-Wchar attribute_hidden *Wstrrchr(register const Wchar *s, Wint c)
-{
- register const Wchar *p;
-
- p = NULL;
- do {
- if (*s == (Wchar) c) {
- p = s;
- }
- } while (*s++);
-
- return (Wchar *) p; /* silence the warning */
-}
-
-#if 0 /* ndef L_wcsrchr */
-weak_alias(strrchr, rindex)
-#endif
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsspn
-#define L_strspn
-#define Wstrspn wcsspn
-#else
-#define Wstrspn strspn
-#endif
-#endif
-
-#ifdef L_strspn
-
-#ifndef WANT_WIDE
-#undef strspn
-#else
-#undef wcsspn
-#endif
-size_t attribute_hidden Wstrspn(const Wchar *s1, const Wchar *s2)
-{
- register const Wchar *s = s1;
- register const Wchar *p = s2;
-
- while (*p) {
- if (*p++ == *s) {
- ++s;
- p = s2;
- }
- }
- return s - s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsstr
-#define L_strstr
-#define Wstrstr wcsstr
-#else
-#define Wstrstr strstr
-#endif
-#endif
-
-#ifdef L_strstr
-
-/* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
-
-#ifndef WANT_WIDE
-#undef strstr
-#else
-#undef wcsstr
-#endif
-Wchar attribute_hidden *Wstrstr(const Wchar *s1, const Wchar *s2)
-{
- register const Wchar *s = s1;
- register const Wchar *p = s2;
-
- do {
- if (!*p) {
- return (Wchar *) s1;;
- }
- if (*p == *s) {
- ++p;
- ++s;
- } else {
- p = s2;
- if (!*s) {
- return NULL;
- }
- s = ++s1;
- }
- } while (1);
-}
-
-#if 0 /* def L_wcsstr */
-weak_alias(wcsstr, wcswcs)
-#endif
-
-#endif
-/**********************************************************************/
-#if 0
-#undef Wstrspn
-#undef Wstrpbrk
-
-#ifdef L_wcstok
-#define L_strtok_r
-#define Wstrtok_r wcstok
-#define Wstrspn wcsspn
-#define Wstrpbrk wcspbrk
-#else
-#define Wstrtok_r __strtok_r
-#define Wstrspn strspn
-#define Wstrpbrk strpbrk
-#endif
-#endif
-
-#ifdef L_strtok_r
-
-#ifndef WANT_WIDE
-#undef strtok_r
-#else
-#undef wcstok
-#endif
-Wchar attribute_hidden *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
- Wchar ** __restrict next_start)
-{
- register Wchar *s;
- register Wchar *p;
-
-#if 1
- if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
- if (*(s += Wstrspn(s, s2))) {
- if ((p = Wstrpbrk(s, s2)) != NULL) {
- *p++ = 0;
- }
- } else {
- p = s = NULL;
- }
- *next_start = p;
- }
- return s;
-#else
- if (!(s = s1)) {
- s = *next_start;
- }
- if (s && *(s += Wstrspn(s, s2))) {
- if (*(p = s + Wstrcspn(s, s2))) {
- *p++ = 0;
- }
- *next_start = p;
- return s;
- }
- return NULL; /* TODO: set *next_start = NULL for safety? */
-#endif
-}
-
-#if 0 /* ndef L_wcstok */
-weak_alias(__strtok_r, strtok_r)
-#endif
-
-#endif
-/**********************************************************************/
-/* #ifdef L_wcstok */
-/* #define L_strtok */
-/* #define Wstrtok wcstok */
-/* #define Wstrtok_r wcstok_r */
-/* #else */
-/* #define Wstrtok strtok */
-/* #define Wstrtok_r strtok_r */
-/* #endif */
-
-#ifdef L_strtok
-#define Wstrtok strtok
-#define Wstrtok_r __strtok_r
-
-Wchar *Wstrtok(Wchar * __restrict s1, const Wchar * __restrict s2)
-{
- static Wchar *next_start; /* Initialized to 0 since in bss. */
- return Wstrtok_r(s1, s2, &next_start);
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmemset
-#define L_memset
-#define Wmemset wmemset
-#else
-#define Wmemset memset
-#endif
-#endif
-
-#ifdef L_memset
-
-#ifndef WANT_WIDE
-#undef memset
-#else
-#undef wmemset
-#endif
-Wvoid attribute_hidden *Wmemset(Wvoid *s, Wint c, size_t n)
-{
- register Wuchar *p = (Wuchar *) s;
-#ifdef __BCC__
- /* bcc can optimize the counter if it thinks it is a pointer... */
- register const char *np = (const char *) n;
-#else
-#define np n
-#endif
-
- while (np) {
- *p++ = (Wuchar) c;
- --np;
- }
-
- return s;
-}
-#undef np
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcslen
-#define L_strlen
-#define Wstrlen wcslen
-#else
-#define Wstrlen strlen
-#endif
-#endif
-
-#ifdef L_strlen
-
-#ifndef WANT_WIDE
-#undef strlen
-#else
-#undef wcslen
-#endif
-size_t attribute_hidden Wstrlen(const Wchar *s)
-{
- register const Wchar *p;
-
- for (p=s ; *p ; p++);
-
- return p - s;
-}
-
-#endif
-/**********************************************************************/
-/* ANSI/ISO end here */
-/**********************************************************************/
-#ifdef L_ffs
-
-#undef ffs
-int attribute_hidden __ffs(int i)
-{
-#if 1
- /* inlined binary search method */
- char n = 1;
-#if UINT_MAX == 0xffffU
- /* nothing to do here -- just trying to avoiding possible problems */
-#elif UINT_MAX == 0xffffffffU
- if (!(i & 0xffff)) {
- n += 16;
- i >>= 16;
- }
-#else
-#error ffs needs rewriting!
-#endif
-
- if (!(i & 0xff)) {
- n += 8;
- i >>= 8;
- }
- if (!(i & 0x0f)) {
- n += 4;
- i >>= 4;
- }
- if (!(i & 0x03)) {
- n += 2;
- i >>= 2;
- }
- return (i) ? (n + ((i+1) & 0x01)) : 0;
-
-#else
- /* linear search -- slow, but small */
- int n;
-
- for (n = 0 ; i ; ++n) {
- i >>= 1;
- }
-
- return n;
-#endif
-}
-
-strong_alias(__ffs, ffs)
-
-#endif
-/**********************************************************************/
-#if defined(L_strcasecmp) || defined(L_strcasecmp_l) || defined(L_wcscasecmp) || defined(L_wcscasecmp_l)
-
-#if defined(L_wcscasecmp) || defined(L_wcscasecmp_l)
-
-#define strcasecmp wcscasecmp
-#define __strcasecmp __wcscasecmp
-#define strcasecmp_l wcscasecmp_l
-#define __strcasecmp_l __wcscasecmp_l
-#ifdef __UCLIBC_DO_XLOCALE
-#define TOLOWER(C) __towlower_l((C), locale_arg)
-#else
-#define TOLOWER(C) towlower((C))
-#endif
-
-#else /* defined(L_wcscasecmp) || defined(L_wcscasecmp_l) */
-
-#ifdef __UCLIBC_DO_XLOCALE
-#define TOLOWER(C) __tolower_l((C), locale_arg)
-#else
-#define TOLOWER(C) tolower((C))
-#endif
-
-#endif /* defined(L_wcscasecmp) || defined(L_wcscasecmp_l) */
-
-
-#if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
-
-int attribute_hidden __strcasecmp(register const Wchar *s1, register const Wchar *s2)
-{
- return __strcasecmp_l(s1, s2, __UCLIBC_CURLOCALE);
-}
-strong_alias(__strcasecmp,strcasecmp)
-
-#else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
-
-int attribute_hidden __UCXL(strcasecmp)(register const Wchar *s1, register const Wchar *s2
- __LOCALE_PARAM )
-{
-#ifdef WANT_WIDE
- while ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2))) {
- if (!*s1++) {
- return 0;
- }
- ++s2;
- }
-
- return (((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1;
- /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
-#else
- int r = 0;
-
- while ( ((s1 == s2) ||
- !(r = ((int)( TOLOWER(*((Wuchar *)s1))))
- - TOLOWER(*((Wuchar *)s2))))
- && (++s2, *s1++));
-
- return r;
-#endif
-}
-__UCXL_ALIAS(strcasecmp)
-
-#endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
-
-#endif
-/**********************************************************************/
-#if defined(L_strncasecmp) || defined(L_strncasecmp_l) || defined(L_wcsncasecmp) || defined(L_wcsncasecmp_l)
-
-#if defined(L_wcsncasecmp) || defined(L_wcsncasecmp_l)
-
-#define strncasecmp wcsncasecmp
-#define __strncasecmp __wcsncasecmp
-#define strncasecmp_l wcsncasecmp_l
-#define __strncasecmp_l __wcsncasecmp_l
-#ifdef __UCLIBC_DO_XLOCALE
-#define TOLOWER(C) __towlower_l((C), locale_arg)
-#else
-#define TOLOWER(C) towlower((C))
-#endif
-
-#else /* defined(L_wcsncasecmp) || defined(L_wcsncasecmp_l) */
-
-#ifdef __UCLIBC_DO_XLOCALE
-#define TOLOWER(C) __tolower_l((C), locale_arg)
-#else
-#define TOLOWER(C) tolower((C))
-#endif
-
-#endif /* defined(L_wcsncasecmp) || defined(L_wcsncasecmp_l) */
-
-
-#if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
-
-int attribute_hidden __strncasecmp(register const Wchar *s1, register const Wchar *s2, size_t n)
-{
- return __strncasecmp_l(s1, s2, n, __UCLIBC_CURLOCALE);
-}
-strong_alias(__strncasecmp,strncasecmp)
-
-#else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
-
-int attribute_hidden __UCXL(strncasecmp)(register const Wchar *s1, register const Wchar *s2,
- size_t n __LOCALE_PARAM )
-{
-#ifdef WANT_WIDE
- while (n && ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2)))) {
- if (!*s1++) {
- return 0;
- }
- ++s2;
- --n;
- }
-
- return (n == 0)
- ? 0
- : ((((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1);
- /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
-#else
- int r = 0;
-
- while ( n
- && ((s1 == s2) ||
- !(r = ((int)( TOLOWER(*((unsigned char *)s1))))
- - TOLOWER(*((unsigned char *)s2))))
- && (--n, ++s2, *s1++));
- return r;
-#endif
-}
-__UCXL_ALIAS(strncasecmp)
-
-#endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsnlen
-#define L_strnlen
-#define Wstrnlen wcsnlen
-#else
-#define Wstrnlen strnlen
-#endif
-#endif
-
-#ifdef L_strnlen
-
-#ifndef WANT_WIDE
-#undef strnlen
-#else
-#undef wcsnlen
-#endif
-size_t attribute_hidden Wstrnlen(const Wchar *s, size_t max)
-{
- register const Wchar *p = s;
-#ifdef __BCC__
- /* bcc can optimize the counter if it thinks it is a pointer... */
- register const char *maxp = (const char *) max;
-#else
-#define maxp max
-#endif
-
- while (maxp && *p) {
- ++p;
- --maxp;
- }
-
- return p - s;
-}
-#undef maxp
-#endif
-/**********************************************************************/
-/* No wide analog. */
-
-#ifdef L_memccpy
-
-#undef memccpy
-void attribute_hidden *__memccpy(void * __restrict s1, const void * __restrict s2, int c, size_t n)
-{
- register char *r1 = s1;
- register const char *r2 = s2;
-
- while (n-- && (((unsigned char)(*r1++ = *r2++)) != ((unsigned char) c)));
-
- return (n == (size_t) -1) ? NULL : r1;
-}
-
-strong_alias(__memccpy, memccpy)
-
-#endif
-/**********************************************************************/
-#if 0
-#undef Wstrlen
-#undef Wstrcpy
-
-#ifdef L_wcsdup
-#define L_strdup
-#define Wstrdup wcsdup
-#define Wstrlen wcslen
-#define Wstrcpy wcscpy
-#else
-#define Wstrdup strdup
-#define Wstrlen strlen
-#define Wstrcpy strcpy
-#endif
-#endif
-
-#ifdef L_strdup
-
-#ifndef WANT_WIDE
-#undef strdup
-#else
-#undef wcsdup
-#endif
-Wchar attribute_hidden *Wstrdup(register const Wchar *s1)
-{
- register Wchar *s;
-
- if ((s = malloc((Wstrlen(s1) + 1) * sizeof(Wchar))) != NULL) {
- Wstrcpy(s, s1);
- }
-
- return s;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_strerror
-
-#undef strerror
-char attribute_hidden *__strerror(int errnum)
-{
- static char buf[_STRERROR_BUFSIZE];
-
- __xpg_strerror_r_internal(errnum, buf, sizeof(buf));
-
- return buf;
-}
-
-strong_alias(__strerror, strerror)
-
-#endif
-/**********************************************************************/
-/* SUSv3 functions. */
-/**********************************************************************/
-#ifdef L___xpg_strerror_r
-
-#ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
-#if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
-
-static const unsigned char estridx[] = {
- 0, /* success is always 0 */
- EPERM,
- ENOENT,
- ESRCH,
- EINTR,
- EIO,
- ENXIO,
- E2BIG,
- ENOEXEC,
- EBADF,
- ECHILD,
- EAGAIN,
- ENOMEM,
- EACCES,
- EFAULT,
- ENOTBLK,
- EBUSY,
- EEXIST,
- EXDEV,
- ENODEV,
- ENOTDIR,
- EISDIR,
- EINVAL,
- ENFILE,
- EMFILE,
- ENOTTY,
- ETXTBSY,
- EFBIG,
- ENOSPC,
- ESPIPE,
- EROFS,
- EMLINK,
- EPIPE,
- EDOM,
- ERANGE,
- EDEADLK,
- ENAMETOOLONG,
- ENOLCK,
- ENOSYS,
- ENOTEMPTY,
- ELOOP,
- 0,
- ENOMSG,
- EIDRM,
- ECHRNG,
- EL2NSYNC,
- EL3HLT,
- EL3RST,
- ELNRNG,
- EUNATCH,
- ENOCSI,
- EL2HLT,
- EBADE,
- EBADR,
- EXFULL,
- ENOANO,
- EBADRQC,
- EBADSLT,
- 0,
- EBFONT,
- ENOSTR,
- ENODATA,
- ETIME,
- ENOSR,
- ENONET,
- ENOPKG,
- EREMOTE,
- ENOLINK,
- EADV,
- ESRMNT,
- ECOMM,
- EPROTO,
- EMULTIHOP,
- EDOTDOT,
- EBADMSG,
- EOVERFLOW,
- ENOTUNIQ,
- EBADFD,
- EREMCHG,
- ELIBACC,
- ELIBBAD,
- ELIBSCN,
- ELIBMAX,
- ELIBEXEC,
- EILSEQ,
- ERESTART,
- ESTRPIPE,
- EUSERS,
- ENOTSOCK,
- EDESTADDRREQ,
- EMSGSIZE,
- EPROTOTYPE,
- ENOPROTOOPT,
- EPROTONOSUPPORT,
- ESOCKTNOSUPPORT,
- EOPNOTSUPP,
- EPFNOSUPPORT,
- EAFNOSUPPORT,
- EADDRINUSE,
- EADDRNOTAVAIL,
- ENETDOWN,
- ENETUNREACH,
- ENETRESET,
- ECONNABORTED,
- ECONNRESET,
- ENOBUFS,
- EISCONN,
- ENOTCONN,
- ESHUTDOWN,
- ETOOMANYREFS,
- ETIMEDOUT,
- ECONNREFUSED,
- EHOSTDOWN,
- EHOSTUNREACH,
- EALREADY,
- EINPROGRESS,
- ESTALE,
- EUCLEAN,
- ENOTNAM,
- ENAVAIL,
- EISNAM,
- EREMOTEIO,
-#ifdef __mips__
- 0, /* mips has an outrageous value for this... */
-#else
- EDQUOT,
-#endif
- ENOMEDIUM,
- EMEDIUMTYPE,
-#if defined(__mips__) || defined(__sparc__)
- EDEADLOCK,
-#endif
-};
-
-#endif
-
-/* __xpg_strerror_r is used in header */
-int attribute_hidden __xpg_strerror_r_internal(int errnum, char *strerrbuf, size_t buflen)
-{
- register char *s;
- int i, retval;
- char buf[_STRERROR_BUFSIZE];
- static const char unknown[] = {
- 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
- };
-
- retval = EINVAL;
-
-
-#ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
-
-#if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
- /* Need to translate errno to string index. */
- for (i = 0 ; i < sizeof(estridx)/sizeof(estridx[0]) ; i++) {
- if (estridx[i] == errnum) {
- goto GOT_ESTRIDX;
- }
- }
- i = INT_MAX; /* Failed, but may need to check mips special case. */
-#ifdef __mips__
- if (errnum == EDQUOT) { /* Deal with large EDQUOT value on mips */
- i = 122;
- }
-#endif /* __mips__ */
- GOT_ESTRIDX:
-#else
- /* No errno to string index translation needed. */
- i = errnum;
-#endif
-
- if (((unsigned int) i) < _SYS_NERR) {
- /* Trade time for space. This function should rarely be called
- * so rather than keeping an array of pointers for the different
- * messages, just run through the buffer until we find the
- * correct string. */
- for (s = (char *) _string_syserrmsgs ; i ; ++s) {
- if (!*s) {
- --i;
- }
- }
- if (*s) { /* Make sure we have an actual message. */
- retval = 0;
- goto GOT_MESG;
- }
- }
-
-#endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
-
- s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
- __memcpy(s, unknown, sizeof(unknown));
-
- GOT_MESG:
- if (!strerrbuf) { /* SUSv3 */
- buflen = 0;
- }
- i = __strlen(s) + 1;
- if (i > buflen) {
- i = buflen;
- retval = ERANGE;
- }
-
- if (i) {
- __memcpy(strerrbuf, s, i);
- strerrbuf[i-1] = 0; /* In case buf was too small. */
- }
-
- if (retval) {
- __set_errno(retval);
- }
-
- return retval;
-}
-
-#else /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
-
-int attribute_hidden __xpg_strerror_r_internal(int errnum, char *strerrbuf, size_t buflen)
-{
- register char *s;
- int i, retval;
- char buf[_STRERROR_BUFSIZE];
- static const char unknown[] = {
- 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
- };
-
- s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
- __memcpy(s, unknown, sizeof(unknown));
-
- if (!strerrbuf) { /* SUSv3 */
- buflen = 0;
- }
-
- retval = EINVAL;
-
- i = buf + sizeof(buf) - s;
-
- if (i > buflen) {
- i = buflen;
- retval = ERANGE;
- }
-
- if (i) {
- __memcpy(strerrbuf, s, i);
- strerrbuf[i-1] = 0; /* In case buf was too small. */
- }
-
- __set_errno(retval);
-
- return retval;
-}
-
-#endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
-strong_alias(__xpg_strerror_r_internal,__xpg_strerror_r)
-
-#endif
-/**********************************************************************/
-/* GNU extension functions. */
-/**********************************************************************/
-#ifdef L___glibc_strerror_r
-
-char attribute_hidden *__glibc_strerror_r_internal(int errnum, char *strerrbuf, size_t buflen)
-{
- __xpg_strerror_r_internal(errnum, strerrbuf, buflen);
-
- return strerrbuf;
-}
-
-strong_alias(__glibc_strerror_r_internal,__glibc_strerror_r)
-weak_alias(__glibc_strerror_r_internal, __strerror_r)
-#endif
-/**********************************************************************/
-#ifdef L_memmem
-
-#undef memmem
-void attribute_hidden *__memmem(const void *haystack, size_t haystacklen,
- const void *needle, size_t needlelen)
-{
- register const char *ph;
- register const char *pn;
- const char *plast;
- size_t n;
-
- if (needlelen == 0) {
- return (void *) haystack;
- }
-
- if (haystacklen >= needlelen) {
- ph = (const char *) haystack;
- pn = (const char *) needle;
- plast = ph + (haystacklen - needlelen);
-
- do {
- n = 0;
- while (ph[n] == pn[n]) {
- if (++n == needlelen) {
- return (void *) ph;
- }
- }
- } while (++ph <= plast);
- }
-
- return NULL;
-}
-
-strong_alias(__memmem, memmem)
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmempcpy
-#define L_mempcpy
-#define Wmempcpy wmempcpy
-#else
-#define Wmempcpy __mempcpy
-#endif
-#endif
-
-#ifdef L_mempcpy
-
-#ifndef WANT_WIDE
-#undef mempcpy
-#else
-#undef wmempcpy
-#endif
-Wvoid attribute_hidden *Wmempcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
-{
- register Wchar *r1 = s1;
- register const Wchar *r2 = s2;
-
-#ifdef __BCC__
- while (n--) {
- *r1++ = *r2++;
- }
-#else
- while (n) {
- *r1++ = *r2++;
- --n;
- }
-#endif
-
- return r1;
-}
-
-#if 0 /* ndef L_wmempcpy */
-weak_alias(__mempcpy, mempcpy)
-#endif
-
-#endif
-/**********************************************************************/
-#ifdef L_memrchr
-
-#undef memrchr
-void attribute_hidden *__memrchr(const void *s, int c, size_t n)
-{
- register const unsigned char *r;
-#ifdef __BCC__
- /* bcc can optimize the counter if it thinks it is a pointer... */
- register const char *np = (const char *) n;
-#else
-#define np n
-#endif
-
- r = ((unsigned char *)s) + ((size_t) np);
-
- while (np) {
- if (*--r == ((unsigned char)c)) {
- return (void *) r; /* silence the warning */
- }
- --np;
- }
-
- return NULL;
-}
-#undef np
-
-strong_alias(__memrchr, memrchr)
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcpcpy
-#define L_stpcpy
-#define Wstpcpy wcpcpy
-#else
-#define Wstpcpy stpcpy
-#endif
-#endif
-
-#ifdef L_stpcpy
-
-#ifndef WANT_WIDE
-#undef stpcpy
-#else
-#undef wcpcpy
-#endif
-Wchar attribute_hidden *Wstpcpy(register Wchar * __restrict s1, const Wchar * __restrict s2)
-{
-#ifdef __BCC__
- do {
- *s1 = *s2++;
- } while (*s1++ != 0);
-#else
- while ( (*s1++ = *s2++) != 0 );
-#endif
-
- return s1 - 1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcpncpy
-#define L_stpncpy
-#define Wstpncpy wcpncpy
-#else
-#define Wstpncpy stpncpy
-#endif
-#endif
-
-#ifdef L_stpncpy
-
-#ifndef WANT_WIDE
-#undef stpncpy
-#else
-#undef wcpncpy
-#endif
-Wchar attribute_hidden *Wstpncpy(register Wchar * __restrict s1,
- register const Wchar * __restrict s2,
- size_t n)
-{
- Wchar *s = s1;
- const Wchar *p = s2;
-
-#ifdef __BCC__
- while (n--) {
- if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
- ++s;
- }
- return s1 + (s2 - p);
-#else
- while (n) {
- if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
- ++s;
- --n;
- }
- return s1 + (s2 - p);
-#endif
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_bzero
-
-#undef bzero
-void attribute_hidden __bzero(void *s, size_t n)
-{
-#if 1
- (void)__memset(s, 0, n);
-#else
- register unsigned char *p = s;
-#ifdef __BCC__
- /* bcc can optimize the counter if it thinks it is a pointer... */
- register const char *np = (const char *) n;
-#else
-#define np n
-#endif
-
- while (np) {
- *p++ = 0;
- --np;
- }
-#endif
-}
-#if 0
-weak_alias(__bzero, bzero)
-#else
-strong_alias(__bzero, bzero)
-#endif
-#undef np
-
-#endif
-/**********************************************************************/
-#ifdef L_bcopy
-
-#undef bcopy
-void attribute_hidden __bcopy(const void *s2, void *s1, size_t n)
-{
-#if 1
- __memmove(s1, s2, n);
-#else
-#ifdef __BCC__
- register char *s;
- register const char *p;
-
- s = s1;
- p = s2;
- if (p >= s) {
- while (n--) {
- *s++ = *p++;
- }
- } else {
- s += n;
- p += n;
- while (n--) {
- *--s = *--p;
- }
- }
-#else
- register char *s;
- register const char *p;
-
- s = s1;
- p = s2;
- if (p >= s) {
- while (n) {
- *s++ = *p++;
- --n;
- }
- } else {
- while (n) {
- --n;
- s[n] = p[n];
- }
- }
-#endif
-#endif
-}
-
-strong_alias(__bcopy, bcopy)
-
-#endif
-/**********************************************************************/
-#ifdef L_strcasestr
-
-#undef strcasestr
-char attribute_hidden *__strcasestr(const char *s1, const char *s2)
-{
- register const char *s = s1;
- register const char *p = s2;
-
-#if 1
- do {
- if (!*p) {
- return (char *) s1;;
- }
- if ((*p == *s)
- || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
- ) {
- ++p;
- ++s;
- } else {
- p = s2;
- if (!*s) {
- return NULL;
- }
- s = ++s1;
- }
- } while (1);
-#else
- while (*p && *s) {
- if ((*p == *s)
- || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
- ) {
- ++p;
- ++s;
- } else {
- p = s2;
- s = ++s1;
- }
- }
-
- return (*p) ? NULL : (char *) s1;
-#endif
-}
-
-strong_alias(__strcasestr, strcasestr)
-
-#endif
-/**********************************************************************/
-#ifdef L_strndup
-
-#undef strndup
-char attribute_hidden *__strndup(register const char *s1, size_t n)
-{
- register char *s;
-
- n = __strnlen(s1,n); /* Avoid problems if s1 not nul-terminated. */
-
- if ((s = malloc(n + 1)) != NULL) {
- __memcpy(s, s1, n);
- s[n] = 0;
- }
-
- return s;
-}
-
-strong_alias(__strndup, strndup)
-
-#endif
-/**********************************************************************/
-#ifdef L_strsep
-
-#undef strsep
-char attribute_hidden *__strsep(char ** __restrict s1, const char * __restrict s2)
-{
- register char *s = *s1;
- register char *p;
-
-#if 1
- p = NULL;
- if (s && *s && (p = __strpbrk(s, s2))) {
- *p++ = 0;
- }
-#else
- if (s && *s && *(p = s + strcspn(s, s2))) {
- *p++ = 0;
- } else {
- p = NULL;
- }
-#endif
- *s1 = p;
- return s;
-}
-
-strong_alias(__strsep, strsep)
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcschrnul
-#define L_strchrnul
-#define __Wstrchrnul __wcschrnul
-#define Wstrchrnul wcschrnul
-#else
-#define __Wstrchrnul __strchrnul
-#define Wstrchrnul strchrnul
-#endif
-#endif
-
-#ifdef L_strchrnul
-
-#ifndef WANT_WIDE
-#undef strchrnul
-#else
-#undef wcschrnul
-#endif
-Wchar attribute_hidden *Wstrchrnul(register const Wchar *s, Wint c)
-{
- --s;
- while (*++s && (*s != ((Wchar)c)));
- return (Wchar *) s;
-}
-#if 0
-weak_alias(__Wstrchrnul, Wstrchrnul)
-#endif
-
-#endif
-/**********************************************************************/
-#ifdef L_rawmemchr
-
-#undef rawmemchr
-void attribute_hidden *__rawmemchr(const void *s, int c)
-{
- register const unsigned char *r = s;
-
- while (*r != ((unsigned char)c)) ++r;
-
- return (void *) r; /* silence the warning */
-}
-
-strong_alias(__rawmemchr, rawmemchr)
-
-#endif
-/**********************************************************************/
-#ifdef L_basename
-
-#undef basename
-char attribute_hidden *__basename(const char *path)
-{
- register const char *s;
- register const char *p;
-
- p = s = path;
-
- while (*s) {
- if (*s++ == '/') {
- p = s;
- }
- }
-
- return (char *) p;
-}
-
-strong_alias(__basename, basename)
-
-#endif
-/**********************************************************************/
-#ifdef L___xpg_basename
-
-char *__xpg_basename(register char *path)
-{
- static const char null_or_empty[] = ".";
- char *first;
- register char *last;
-
- first = (char *) null_or_empty;
-
- if (path && *path) {
- first = path;
- last = path - 1;
-
- do {
- if ((*path != '/') && (path > ++last)) {
- last = first = path;
- }
- } while (*++path);
-
- if (*first == '/') {
- last = first;
- }
- last[1] = 0;
- }
-
- return first;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_dirname
-
-char *dirname(char *path)
-{
- static const char null_or_empty_or_noslash[] = ".";
- register char *s;
- register char *last;
- char *first;
-
- last = s = path;
-
- if (s != NULL) {
-
- LOOP:
- while (*s && (*s != '/')) ++s;
- first = s;
- while (*s == '/') ++s;
- if (*s) {
- last = first;
- goto LOOP;
- }
-
- if (last == path) {
- if (*last != '/') {
- goto DOT;
- }
- if ((*++last == '/') && (last[1] == 0)) {
- ++last;
- }
- }
- *last = 0;
- return path;
- }
- DOT:
- return (char *) null_or_empty_or_noslash;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_strlcat
-
-/* OpenBSD function:
- * Append at most n-1-strlen(dst) chars from src to dst and nul-terminate dst.
- * Returns strlen(src) + strlen({original} dst), so truncation occurred if the
- * return val is >= n.
- * Note: If dst doesn't contain a nul in the first n chars, strlen(dst) is
- * taken as n. */
-
-size_t strlcat(register char *__restrict dst,
- register const char *__restrict src,
- size_t n)
-{
- size_t len;
- char dummy[1];
-
- len = 0;
-
- while (1) {
- if (len >= n) {
- dst = dummy;
- break;
- }
- if (!*dst) {
- break;
- }
- ++dst;
- ++len;
- }
-
- while ((*dst = *src) != 0) {
- if (++len < n) {
- ++dst;
- }
- ++src;
- }
-
- return len;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef WANT_WIDE
-extern size_t __wcslcpy(wchar_t *__restrict dst,
- const wchar_t *__restrict src,
- size_t n);
-#endif
-
-
-#ifdef L___wcslcpy
-#define L_strlcpy
-#define Wstrlcpy __wcslcpy
-#else
-#define Wstrlcpy strlcpy
-#endif
-#endif
-
-#ifdef L_strlcpy
-
-/* OpenBSD function:
- * Copy at most n-1 chars from src to dst and nul-terminate dst.
- * Returns strlen(src), so truncation occurred if the return value is >= n. */
-
-#ifndef WANT_WIDE
-#undef strlcpy
-#else
-#undef wcslcpy
-#endif
-size_t attribute_hidden Wstrlcpy(register Wchar *__restrict dst,
- register const Wchar *__restrict src,
- size_t n)
-{
- const Wchar *src0 = src;
- Wchar dummy[1];
-
- if (!n) {
- dst = dummy;
- } else {
- --n;
- }
-
- while ((*dst = *src) != 0) {
- if (n) {
- --n;
- ++dst;
- }
- ++src;
- }
-
- return src - src0;
-}
-
-#if 0 /* def __LOCALE_C_ONLY */
-#ifdef L___wcslcpy
-weak_alias(__wcslcpy,wcsxfrm);
-#else
-weak_alias(strlcpy,strxfrm);
-#endif
-#endif
-
-#endif
-/**********************************************************************/
-#if defined(L__string_syssigmsgs) && defined(__UCLIBC_HAS_SIGNUM_MESSAGES__)
-
-const char _string_syssigmsgs[] = {
- /* 0: 0, 1 */ "\0"
- /* 1: 1, 7 */ "Hangup\0"
- /* 2: 8, 10 */ "Interrupt\0"
- /* 3: 18, 5 */ "Quit\0"
- /* 4: 23, 20 */ "Illegal instruction\0"
- /* 5: 43, 22 */ "Trace/breakpoint trap\0"
- /* 6: 65, 8 */ "Aborted\0"
- /* 7: 73, 10 */ "Bus error\0"
- /* 8: 83, 25 */ "Floating point exception\0"
- /* 9: 108, 7 */ "Killed\0"
- /* 10: 115, 22 */ "User defined signal 1\0"
- /* 11: 137, 19 */ "Segmentation fault\0"
- /* 12: 156, 22 */ "User defined signal 2\0"
- /* 13: 178, 12 */ "Broken pipe\0"
- /* 14: 190, 12 */ "Alarm clock\0"
- /* 15: 202, 11 */ "Terminated\0"
- /* 16: 213, 12 */ "Stack fault\0"
- /* 17: 225, 13 */ "Child exited\0"
- /* 18: 238, 10 */ "Continued\0"
- /* 19: 248, 17 */ "Stopped (signal)\0"
- /* 20: 265, 8 */ "Stopped\0"
- /* 21: 273, 20 */ "Stopped (tty input)\0"
- /* 22: 293, 21 */ "Stopped (tty output)\0"
- /* 23: 314, 21 */ "Urgent I/O condition\0"
- /* 24: 335, 24 */ "CPU time limit exceeded\0"
- /* 25: 359, 25 */ "File size limit exceeded\0"
- /* 26: 384, 22 */ "Virtual timer expired\0"
- /* 27: 406, 24 */ "Profiling timer expired\0"
- /* 28: 430, 15 */ "Window changed\0"
- /* 29: 445, 13 */ "I/O possible\0"
- /* 30: 458, 14 */ "Power failure\0"
- /* 31: 472, 16 */ "Bad system call"
-#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
- /* 32: 488, 9 */ "\0EMT trap"
-#endif
-};
-
-#endif
-
-/**********************************************************************/
-#if defined(L_sys_siglist) && defined(__UCLIBC_HAS_SYS_SIGLIST__)
-
-const char *const sys_siglist[_NSIG] = {
- [0] = NULL,
- [SIGHUP] = _string_syssigmsgs + 1,
- [SIGINT] = _string_syssigmsgs + 8,
- [SIGQUIT] = _string_syssigmsgs + 18,
- [SIGILL] = _string_syssigmsgs + 23,
- [SIGTRAP] = _string_syssigmsgs + 43,
- [SIGABRT] = _string_syssigmsgs + 65,
- [SIGBUS] = _string_syssigmsgs + 73,
- [SIGFPE] = _string_syssigmsgs + 83,
- [SIGKILL] = _string_syssigmsgs + 108,
- [SIGUSR1] = _string_syssigmsgs + 115,
- [SIGSEGV] = _string_syssigmsgs + 137,
- [SIGUSR2] = _string_syssigmsgs + 156,
- [SIGPIPE] = _string_syssigmsgs + 178,
- [SIGALRM] = _string_syssigmsgs + 190,
- [SIGTERM] = _string_syssigmsgs + 202,
-#if !(defined(__alpha__) || defined(__mips__) || defined(__sparc__))
- [SIGSTKFLT] = _string_syssigmsgs + 213,
-#endif
- [SIGCHLD] = _string_syssigmsgs + 225,
- [SIGCONT] = _string_syssigmsgs + 238,
- [SIGSTOP] = _string_syssigmsgs + 248,
- [SIGTSTP] = _string_syssigmsgs + 265,
- [SIGTTIN] = _string_syssigmsgs + 273,
- [SIGTTOU] = _string_syssigmsgs + 293,
- [SIGURG] = _string_syssigmsgs + 314,
- [SIGXCPU] = _string_syssigmsgs + 335,
- [SIGXFSZ] = _string_syssigmsgs + 359,
- [SIGVTALRM] = _string_syssigmsgs + 384,
- [SIGPROF] = _string_syssigmsgs + 406,
- [SIGWINCH] = _string_syssigmsgs + 430,
- [SIGIO] = _string_syssigmsgs + 445,
- [SIGPWR] = _string_syssigmsgs + 458,
- [SIGSYS] = _string_syssigmsgs + 472,
-#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
- [SIGEMT] = _string_syssigmsgs + 488,
-#endif
-};
-
-#endif
-/**********************************************************************/
-#ifdef L_strsignal
-
-/* TODO: make a threadsafe version? */
-
-#undef strsignal
-#ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
-
-#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
-static const unsigned char sstridx[] = {
- 0,
- SIGHUP,
- SIGINT,
- SIGQUIT,
- SIGILL,
- SIGTRAP,
- SIGIOT,
- SIGBUS,
- SIGFPE,
- SIGKILL,
- SIGUSR1,
- SIGSEGV,
- SIGUSR2,
- SIGPIPE,
- SIGALRM,
- SIGTERM,
-#if defined(__alpha__) || defined(__mips__) || defined(__sparc__)
- 0,
-#else
- SIGSTKFLT,
-#endif
- SIGCHLD,
- SIGCONT,
- SIGSTOP,
- SIGTSTP,
- SIGTTIN,
- SIGTTOU,
- SIGURG,
- SIGXCPU,
- SIGXFSZ,
- SIGVTALRM,
- SIGPROF,
- SIGWINCH,
- SIGIO,
- SIGPWR,
- SIGSYS,
-#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
- SIGEMT,
-#endif
-};
-#endif
-
-char attribute_hidden *__strsignal(int signum)
-{
- register char *s;
- int i;
- static char buf[_STRSIGNAL_BUFSIZE];
- static const char unknown[] = {
- 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' '
- };
-
-#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)
- /* Need to translate signum to string index. */
- for (i = 0 ; i < sizeof(sstridx)/sizeof(sstridx[0]) ; i++) {
- if (sstridx[i] == signum) {
- goto GOT_SSTRIDX;
- }
- }
- i = INT_MAX; /* Failed. */
- GOT_SSTRIDX:
-#else
- /* No signum to string index translation needed. */
- i = signum;
-#endif
-
- if (((unsigned int) signum) < _SYS_NSIG) {
- /* Trade time for space. This function should rarely be called
- * so rather than keeping an array of pointers for the different
- * messages, just run through the buffer until we find the
- * correct string. */
- for (s = (char *) _string_syssigmsgs ; i ; ++s) {
- if (!*s) {
- --i;
- }
- }
- if (*s) { /* Make sure we have an actual message. */
- goto DONE;
- }
- }
-
- s = _int10tostr(buf+sizeof(buf)-1, signum) - sizeof(unknown);
- __memcpy(s, unknown, sizeof(unknown));
-
- DONE:
- return s;
-}
-
-#else /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
-
-char attribute_hidden *__strsignal(int signum)
-{
- static char buf[_STRSIGNAL_BUFSIZE];
- static const char unknown[] = {
- 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' '
- };
-
- return (char *) __memcpy(_int10tostr(buf+sizeof(buf)-1, signum)
- - sizeof(unknown),
- unknown, sizeof(unknown));
-}
-
-#endif /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
-
-strong_alias(__strsignal, strsignal)
-
-#endif
-/**********************************************************************/
-#ifdef L_psignal
-
-/* TODO: make this threadsafe with a reentrant version of strsignal? */
-
-void psignal(int signum, register const char *message)
-{
- /* If the program is calling psignal, it's a safe bet that printf and
- * friends are used as well. It is also possible that the calling
- * program could buffer stderr, or reassign it. */
-
- register const char *sep;
-
- sep = ": ";
- if (!(message && *message)) { /* Caller did not supply a prefix message */
- message = (sep += 2); /* or passed an empty string. */
- }
-
- fprintf(stderr, "%s%s%s\n", message, sep, __strsignal(signum));
-}
-
-#endif
-/**********************************************************************/
-#ifndef __LOCALE_C_ONLY
-#if defined(L_strxfrm) || defined(L_strxfrm_l) || defined(L_wcsxfrm) || defined(L_wcsxfrm_l)
-
-#ifdef L_strxfrm
-#ifndef WANT_WIDE
-#error WANT_WIDE should be defined for L_strxfrm
-#endif
-#ifdef L_wcsxfrm
-#error L_wcsxfrm already defined for L_strxfrm
-#endif
-#endif /* L_strxfrm */
-
-#if defined(L_strxfrm) || defined(L_strxfrm_l)
-
-#define wcscoll strcoll
-#define __wcscoll __strcoll
-#define wcscoll_l strcoll_l
-#define __wcscoll_l __strcoll_l
-#define wcsxfrm strxfrm
-#define __wcsxfrm __strxfrm
-#define wcsxfrm_l strxfrm_l
-#define __wcsxfrm_l __strxfrm_l
-
-#undef WANT_WIDE
-#undef Wvoid
-#undef Wchar
-#undef Wuchar
-#undef Wint
-
-#define Wchar char
-
-#endif /* defined(L_strxfrm) || defined(L_strxfrm_l) */
-
-#if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
-
-int attribute_hidden __wcscoll (const Wchar *s0, const Wchar *s1)
-{
- return __wcscoll_l(s0, s1, __UCLIBC_CURLOCALE );
-}
-strong_alias(__wcscoll,wcscoll)
-
-size_t attribute_hidden __wcsxfrm(Wchar *__restrict ws1, const Wchar *__restrict ws2, size_t n)
-{
- return __wcsxfrm_l(ws1, ws2, n, __UCLIBC_CURLOCALE );
-}
-strong_alias(__wcsxfrm,wcsxfrm)
-
-#else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
-
-
-#if 0
-#define CUR_COLLATE (&__UCLIBC_CURLOCALE_DATA.collate)
-#else
-#define CUR_COLLATE (& __LOCALE_PTR->collate)
-#endif
-
-#define MAX_PENDING 8
-
-typedef struct {
- const Wchar *s;
- const Wchar *eob; /* end of backward */
-
- __uwchar_t weight;
- __uwchar_t ui_weight; /* undefined or invalid */
- int colitem;
- int weightidx;
- int rule;
- size_t position;
- /* should be wchar_t. if wchar < 0 do EILSEQ? */
- __uwchar_t *cip;
- __uwchar_t ci_pending[MAX_PENDING]; /* nul-terminated */
-
- char *back_buf;
- char *bbe; /* end of back_buf (actual last... not 1 past end) */
- char *bp; /* ptr into backbuf, NULL if not in backward mode */
- char ibb[128];
- size_t bb_size;
-
- int ru_pushed;
-} col_state_t;
-
-
-#define WEIGHT_MASK 0x3fffU
-#define RULE_MASK 0xc000U
-
-#define RULE_FORWARD (1 << 14)
-#define RULE_POSITION (1 << 15)
-
-#define UI_IDX (WEIGHT_MASK-6)
-#define POSIT_IDX (WEIGHT_MASK-5)
-#define RANGE_IDX (WEIGHT_MASK-4)
-#define UNDEF_IDX (WEIGHT_MASK-3)
-#define INVAL_IDX (WEIGHT_MASK-2)
-#define DITTO_IDX (WEIGHT_MASK-1)
-
-
-#undef TRACE
-#if 0
-#define TRACE(X) printf X
-#else
-#define TRACE(X) ((void)0)
-#endif
-
-static int lookup(wchar_t wc __LOCALE_PARAM )
-{
- unsigned int sc, n, i0, i1;
-
- if (((__uwchar_t) wc) > 0xffffU) {
- return 0;
- }
-
- sc = wc & CUR_COLLATE->ti_mask;
- wc >>= CUR_COLLATE->ti_shift;
- n = wc & CUR_COLLATE->ii_mask;
- wc >>= CUR_COLLATE->ii_shift;
-
- i0 = CUR_COLLATE->wcs2colidt_tbl[wc];
- i0 <<= CUR_COLLATE->ii_shift;
- i1 = CUR_COLLATE->wcs2colidt_tbl[CUR_COLLATE->ii_len + i0 + n];
- i1 <<= CUR_COLLATE->ti_shift;
- return CUR_COLLATE->wcs2colidt_tbl[CUR_COLLATE->ii_len + CUR_COLLATE->ti_len + i1 + sc];
-
-}
-
-static void init_col_state(col_state_t *cs, const Wchar *wcs)
-{
- __memset(cs, 0, sizeof(col_state_t));
- cs->s = wcs;
- cs->bp = cs->back_buf = cs->ibb;
- cs->bb_size = 128;
- cs->bbe = cs->back_buf + (cs->bb_size -1);
-}
-
-static void next_weight(col_state_t *cs, int pass __LOCALE_PARAM )
-{
- int r, w, ru, ri, popping_backup_stack;
- ssize_t n;
- const uint16_t *p;
-#ifdef WANT_WIDE
-#define WC (*cs->s)
-#define N (1)
-#else /* WANT_WIDE */
- wchar_t WC;
- size_t n0, nx;
-#define N n0
-
-#endif /* WANT_WIDE */
-
- do {
-
- if (cs->ru_pushed) {
- ru = cs->ru_pushed;
- TRACE(("ru_pushed = %d\n", ru));
- cs->ru_pushed = 0;
- goto POSITION_SKIP;
- }
-
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning should we walk pendings backwards?
-#endif
- if (cs->cip) { /* possible pending weight */
- if ((r = *(cs->cip++)) == 0) {
- cs->cip = NULL;
- continue;
- }
- cs->weightidx = r & WEIGHT_MASK;
- assert(cs->weightidx);
-/* assert(cs->weightidx != WEIGHT_MASK); */
- } else { /* get the next collation item from the string */
- TRACE(("clearing popping flag\n"));
- popping_backup_stack = 0;
-
- IGNORE_LOOP:
- /* keep first pos as 0 for a sentinal */
- if (*cs->bp) { /* pending backward chars */
- POP_BACKUP:
- popping_backup_stack = 1;
- TRACE(("setting popping flag\n"));
- n = 0;
- if (*cs->bp > 0) { /* singles pending */
- cs->s -= 1;
- if ((*cs->bp -= 1) == 0) {
- cs->bp -= 1;
- }
- } else { /* last was a multi */
- cs->s += *cs->bp;
- cs->bp -= 1;
- }
- } else if (!*cs->s) { /* not in backward mode and end of string */
- cs->weight = 0;
- return;
- } else {
- cs->position += 1;
- }
-
- BACK_LOOP:
-#ifdef WANT_WIDE
- n = 1;
- cs->colitem = r = lookup(*cs->s __LOCALE_ARG );
-#else /* WANT_WIDE */
- n = n0 = __locale_mbrtowc_l(&WC, cs->s, __LOCALE_PTR);
- if (n < 0) {
- __set_errno(EILSEQ);
- cs->weight = 0;
- return;
- }
- cs->colitem = r = lookup(WC __LOCALE_ARG );
-#endif /* WANT_WIDE */
-
- TRACE((" r=%d WC=%#lx\n", r, (unsigned long)(WC)));
-
- if (r > CUR_COLLATE->max_col_index) { /* starting char for one or more sequences */
- p = CUR_COLLATE->multistart_tbl;
- p += p[r-CUR_COLLATE->max_col_index -1];
- do {
- n = N;
- r = *p++;
- do {
- if (!*p) { /* found it */
- cs->colitem = r;
- TRACE((" found multi %d\n", n));
- goto FOUND;
- }
-#ifdef WANT_WIDE
- /* the lookup check here is safe since we're assured that *p is a valid colidx */
- if (!cs->s[n] || (lookup(cs->s[n] __LOCALE_ARG ) != *p)) {
- do {} while (*p++);
- break;
- }
- ++p;
- ++n;
-#else /* WANT_WIDE */
- if (cs->s[n]) {
- nx = __locale_mbrtowc_l(&WC, cs->s + n, __LOCALE_PTR);
- if (nx < 0) {
- __set_errno(EILSEQ);
- cs->weight = 0;
- return;
- }
- }
- if (!cs->s[n] || (lookup(WC __LOCALE_ARG ) != *p)) {
- do {} while (*p++);
- break;
- }
- ++p;
- n += nx; /* Only gets here if cs->s[n] != 0, so nx is set. */
-#endif /* WANT_WIDE */
- } while (1);
- } while (1);
- } else if (r == 0) { /* illegal, undefined, or part of a range */
- if ((CUR_COLLATE->range_count)
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning .. need to introduce range as a collating item?
-#endif
- && (((__uwchar_t)(WC - CUR_COLLATE->range_low)) <= CUR_COLLATE->range_count)
- ) { /* part of a range */
- /* Note: cs->colitem = 0 already. */
- TRACE((" found range\n"));
- ru = CUR_COLLATE->ruletable[CUR_COLLATE->range_rule_offset*CUR_COLLATE->MAX_WEIGHTS + pass];
- assert((ru & WEIGHT_MASK) != DITTO_IDX);
- if ((ru & WEIGHT_MASK) == WEIGHT_MASK) {
- ru = (ru & RULE_MASK) | RANGE_IDX;
- cs->weight = CUR_COLLATE->range_base_weight + (WC - CUR_COLLATE->range_low);
- }
- goto RANGE_SKIP_TO;
- } else if (((__uwchar_t)(WC)) <= 0x7fffffffUL) { /* legal but undefined */
- UNDEFINED:
- /* Note: cs->colitem = 0 already. */
- ri = CUR_COLLATE->undefined_idx;
- assert(ri != 0); /* implicit undefined isn't supported */
-
- TRACE((" found explicit UNDEFINED\n"));
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning right now single weight locales do not support ..
-#endif
- if (CUR_COLLATE->num_weights == 1) {
- TRACE((" single weight UNDEFINED\n"));
- cs->weightidx = RANGE_IDX;
- cs->weight = ri;
- cs->s += n;
- goto PROCESS_WEIGHT;
- }
-
- ri = CUR_COLLATE->index2ruleidx[ri - 1];
- ru = CUR_COLLATE->ruletable[ri * CUR_COLLATE->MAX_WEIGHTS + pass];
- assert((ru & WEIGHT_MASK) != WEIGHT_MASK); /* TODO: handle ".." */
- if ((ru & WEIGHT_MASK) == DITTO_IDX) {
- cs->colitem = CUR_COLLATE->undefined_idx;
- }
- goto RANGE_SKIP_TO;
- } else { /* illegal */
- TRACE((" found illegal\n"));
- __set_errno(EINVAL);
- /* We put all illegals in the same equiv class with maximal weight,
- * and ignore them after the first pass. */
- if (pass > 0) {
- cs->s += n;
- goto IGNORE_LOOP;
- }
- ru = (RULE_FORWARD | RANGE_IDX);
- cs->weight = 0xffffU;
- goto RANGE_SKIP_TO;
- }
- } else if (CUR_COLLATE->num_weights == 1) {
- TRACE((" single weight\n"));
- cs->weightidx = RANGE_IDX;
- cs->weight = cs->colitem;
- cs->s += n;
- goto PROCESS_WEIGHT;
- } else {
- TRACE((" normal\n"));
- }
-
- /* if we get here, it is a normal char either singlely weighted, undefined, or in a range */
- FOUND:
- ri = CUR_COLLATE->index2ruleidx[cs->colitem - 1];
- TRACE((" ri=%d ", ri));
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning make sure this is correct
-#endif
- if (!ri) {
- TRACE(("NOT IN THIS LOCALE\n"));
- goto UNDEFINED;
- }
- ru = CUR_COLLATE->ruletable[ri * CUR_COLLATE->MAX_WEIGHTS + pass];
-
- RANGE_SKIP_TO:
-
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning ignoreables probably should not interrupt backwards processing, but this is wrong
-#endif
-/* if (!(ru & WEIGHT_MASK)) { */
-/* TRACE(("IGNORE\n")); */
-/* cs->s += n; */
-/* continue; */
-/* } */
-
-
- TRACE((" rule = %#x weight = %#x popping = %d s = %p eob = %p\n",
- ru & RULE_MASK, ru & WEIGHT_MASK, popping_backup_stack,
- cs->s, cs->eob));
- /* now we need to check if we're going backwards... */
-
- if (!popping_backup_stack) {
- if (!(ru & RULE_MASK)) { /* backward */
- TRACE(("backwards\n"));
- assert(cs->bp <= cs->bbe);
- if (cs->bp == cs->bbe) {
- if (cs->back_buf == cs->ibb) { /* was using internal buffer */
- cs->bp = malloc(cs->bb_size + 128);
- if (!cs->bp) {
- __set_errno(ENOMEM);
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning what to do here?
-#endif
- cs->weight = 0;
- return;
- }
- __memcpy(cs->bp, cs->back_buf, cs->bb_size);
-
- } else {
- cs->bp = realloc(cs->back_buf, cs->bb_size + 128);
- if (!cs->bp) {
- __set_errno(ENOMEM);
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning what to do here?
-#endif
- cs->weight = 0;
- return;
- }
- }
- cs->bb_size += 128;
- cs->bbe = cs->bp + (cs->bbe - cs->back_buf);
- cs->back_buf = cs->bp;
- cs->bp = cs->bbe;
-
- }
- if (n==1) { /* single char */
- if (*cs->bp && (((unsigned char)(*cs->bp)) < CHAR_MAX)) {
- *cs->bp += 1; /* increment last single's count */
- } else { /* last was a multi, or just starting */
- if (!cs->bp) {
- cs->bp = cs->back_buf;
- } else {
- assert(cs->bp < cs->bbe);
- ++cs->bp;
- }
- *cs->bp = 1;
- }
- } else { /* multichar */
- assert(n>1);
- assert(cs->bp < cs->bbe);
- *++cs->bp = -n;
- }
- cs->s += n;
- if (*cs->s) {
- goto BACK_LOOP;
- }
- /* end-of-string so start popping */
- cs->eob = cs->s;
- TRACE(("popping\n"));
- goto POP_BACKUP;
- } else if (*cs->bp) { /* was going backward but this element isn't */
- /* discard current and use previous backward element */
- assert(!cs->cip);
- cs->eob = cs->s;
- TRACE(("popping\n"));
- goto POP_BACKUP;
- } else { /* was and still going forward */
- TRACE(("forwards\n"));
- if ((ru & (RULE_POSITION|WEIGHT_MASK)) > RULE_POSITION) {
- assert(ru & WEIGHT_MASK);
- cs->ru_pushed = ru;
- cs->weight = cs->position;
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning devel code
-#endif
- cs->position = 0; /* reset to reduce size for strcoll? */
- cs->s += n;
- cs->weightidx = RANGE_IDX;
- goto PROCESS_WEIGHT;
- }
- }
- } else { /* popping backwards stack */
- TRACE(("popping (continued)\n"));
- if (!*cs->bp) {
- cs->s = cs->eob;
- }
- cs->s -= n;
- }
-
- cs->s += n;
- POSITION_SKIP:
- cs->weightidx = ru & WEIGHT_MASK;
- cs->rule = ru & RULE_MASK;
- }
-
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning for pending we only want the weight... _not_ the rule
-#endif
- if (!cs->weightidx) { /* ignore */
- continue;
- }
-
- PROCESS_WEIGHT:
- assert(cs->weightidx);
-
-
- if (((unsigned int)(cs->weightidx - UI_IDX)) <= (INVAL_IDX-UI_IDX)) {
- if (cs->weightidx == UI_IDX) {
- cs->weight = cs->ui_weight;
- }
- return;
- }
-
- assert(cs->weightidx != WEIGHT_MASK);
- if (cs->weightidx == DITTO_IDX) { /* want the weight of the current collating item */
- TRACE(("doing ditto\n"));
- w = CUR_COLLATE->index2weight[cs->colitem -1];
- } else if (cs->weightidx <= CUR_COLLATE->max_col_index) { /* normal */
- TRACE(("doing normal\n"));
- w = CUR_COLLATE->index2weight[cs->weightidx -1];
- } else { /* a string */
- TRACE(("doing string\n"));
- assert(!(cs->weightidx & RULE_MASK));
- /* note: iso14561 allows null string here */
- p = CUR_COLLATE->weightstr + (cs->weightidx - (CUR_COLLATE->max_col_index + 2));
- if (*p & WEIGHT_MASK) {
- r = 0;
- do {
- assert(r < MAX_PENDING);
- cs->ci_pending[r++] = *p++;
- } while (*p & WEIGHT_MASK);
- cs->cip = cs->ci_pending;
- }
- continue;
- }
-
- cs->weight = w;
- return;
- } while (1);
-}
-
-int attribute_hidden __UCXL(wcscoll) (const Wchar *s0, const Wchar *s1 __LOCALE_PARAM )
-{
- col_state_t ws[2];
- int pass;
-
- if (!CUR_COLLATE->num_weights) { /* C locale */
-#ifdef WANT_WIDE
- return __wcscmp(s0, s1);
-#else /* WANT_WIDE */
- return __strcmp(s0, s1);
-#endif /* WANT_WIDE */
- }
-
- pass = 0;
- do { /* loop through the weights levels */
- init_col_state(ws, s0);
- init_col_state(ws+1, s1);
- do { /* loop through the strings */
- /* for each string, get the next weight */
- next_weight(ws, pass __LOCALE_ARG );
- next_weight(ws+1, pass __LOCALE_ARG );
- TRACE(("w0=%lu w1=%lu\n",
- (unsigned long) ws[0].weight,
- (unsigned long) ws[1].weight));
-
- if (ws[0].weight != ws[1].weight) {
- return ws[0].weight - ws[1].weight;
- }
- } while (ws[0].weight);
- } while (++pass < CUR_COLLATE->num_weights);
-
- return 0;
-}
-__UCXL_ALIAS(wcscoll)
-
-#ifdef WANT_WIDE
-
-size_t attribute_hidden __UCXL(wcsxfrm)(wchar_t *__restrict ws1, const wchar_t *__restrict ws2,
- size_t n __LOCALE_PARAM )
-{
- col_state_t cs;
- size_t count;
- int pass;
-
- if (!CUR_COLLATE->num_weights) { /* C locale */
- return __wcsxfrm(ws1, ws2, n);
- }
-
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning handle empty string as a special case
-#endif
-
- count = pass = 0;
- do { /* loop through the weights levels */
- init_col_state(&cs, ws2);
- do { /* loop through the string */
- next_weight(&cs, pass __LOCALE_ARG );
- TRACE(("weight=%lu (%#lx)\n", (unsigned long) cs.weight, (unsigned long) cs.weight));
- if (count < n) {
- ws1[count] = cs.weight +1;
- }
- ++count;
- TRACE(("--------------------------------------------\n"));
- } while (cs.weight);
- if (count <= n) { /* overwrite the trailing 0 end-of-pass marker */
- ws1[count-1] = 1;
- }
- TRACE(("-------------------- pass %d --------------------\n", pass));
- } while (++pass < CUR_COLLATE->num_weights);
- if (count <= n) { /* oops... change it back */
- ws1[count-1] = 0;
- }
- return count-1;
-}
-
-__UCXL_ALIAS(wcsxfrm)
-
-#else /* WANT_WIDE */
-
-static const unsigned long bound[] = {
- 1UL << 7,
- 1UL << 11,
- 1UL << 16,
- 1UL << 21,
- 1UL << 26,
-};
-
-static unsigned char first[] = {
- 0x0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc
-};
-
-/* Use an extension of UTF-8 to store a 32 bit val in max 6 bytes. */
-
-static size_t store(unsigned char *s, size_t count, size_t n, __uwchar_t weight)
-{
- int i, r;
-
- i = 0;
- do {
- if (weight < bound[i]) {
- break;
- }
- } while (++i < sizeof(bound)/sizeof(bound[0]));
-
- r = i+1;
- if (i + count < n) {
- s += count;
- s[0] = first[i];
- while (i) {
- s[i] = 0x80 | (weight & 0x3f);
- weight >>= 6;
- --i;
- }
- s[0] |= weight;
- }
-
- return r;
-}
-
-size_t attribute_hidden __UCXL(strxfrm)(char *__restrict ws1, const char *__restrict ws2, size_t n
- __LOCALE_PARAM )
-{
- col_state_t cs;
- size_t count, inc;
- int pass;
-
- if (!CUR_COLLATE->num_weights) { /* C locale */
- return __strlcpy(ws1, ws2, n);
- }
-
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning handle empty string as a special case
-#endif
-
- inc = count = pass = 0;
- do { /* loop through the weights levels */
- init_col_state(&cs, ws2);
- do { /* loop through the string */
- next_weight(&cs, pass __LOCALE_ARG );
- TRACE(("weight=%lu (%#lx)\n", (unsigned long) cs.weight, (unsigned long) cs.weight));
- inc = store((unsigned char *)ws1, count, n, cs.weight + 1);
- count += inc;
- TRACE(("--------------------------------------------\n"));
- } while (cs.weight);
- /* overwrite the trailing 0 end-of-pass marker */
- assert(inc == 1);
- if (count <= n) {
- ws1[count-1] = 1;
- }
- TRACE(("-------------------- pass %d --------------------\n", pass));
- } while (++pass < CUR_COLLATE->num_weights);
- if (count <= n) { /* oops... change it back */
- ws1[count-1] = 0;
- }
- return count-1;
-}
-
-__UCXL_ALIAS(strxfrm)
-
-#endif /* WANT_WIDE */
-
-#endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
-
-#endif /* defined(L_strxfrm) || defined(L_strxfrm_l) || defined(L_wcsxfrm) || defined(L_wcsxfrm_l) */
-
-#endif /* __LOCALE_C_ONLY */
-/**********************************************************************/
diff --git a/libc/string/x86_64/_glibc_inc.h b/libc/string/x86_64/_glibc_inc.h
index f14b23c94..3c31957db 100644
--- a/libc/string/x86_64/_glibc_inc.h
+++ b/libc/string/x86_64/_glibc_inc.h
@@ -14,6 +14,7 @@
#define ENTRY(sym) \
.global sym; \
+ .hidden sym; \
.align ENTRY_ALIGN; \
.type sym,%function; \
sym:
@@ -26,8 +27,3 @@
#define END(sym) \
.size sym,.-sym;
-
-#undef weak_alias
-#define weak_alias(sym, alias) \
- .weak alias; \
- alias = sym;
diff --git a/libc/string/x86_64/bzero.S b/libc/string/x86_64/bzero.S
index abd252e7b..73ba75436 100644
--- a/libc/string/x86_64/bzero.S
+++ b/libc/string/x86_64/bzero.S
@@ -1,3 +1,3 @@
-#define memset __bzero
+#define __memset __bzero
#include "memset.S"
-weak_alias (__bzero, bzero)
+strong_alias(__bzero,bzero)
diff --git a/libc/string/x86_64/memcpy.S b/libc/string/x86_64/memcpy.S
index c375bf3fb..973cd513f 100644
--- a/libc/string/x86_64/memcpy.S
+++ b/libc/string/x86_64/memcpy.S
@@ -23,7 +23,7 @@
/* BEWARE: `#ifdef memcpy' means that memcpy is redefined as `mempcpy',
and the return value is the byte after the last one copied in
the destination. */
-#define MEMPCPY_P (defined memcpy)
+#define MEMPCPY_P (defined __memcpy)
.text
#if defined PIC && !defined NOT_IN_libc
@@ -32,9 +32,6 @@ ENTRY (__memcpy_chk)
jb HIDDEN_JUMPTARGET (__chk_fail)
END (__memcpy_chk)
#endif
-.global memcpy
-.set memcpy,__memcpy
-.hidden __memcpy
ENTRY (BP_SYM (__memcpy))
/* Cutoff for the big loop is a size of 32 bytes since otherwise
the loop will never be entered. */
@@ -96,3 +93,6 @@ ENTRY (BP_SYM (__memcpy))
ret
END (BP_SYM (__memcpy))
+#if !MEMPCPY_P
+strong_alias(__memcpy,memcpy)
+#endif
diff --git a/libc/string/x86_64/mempcpy.S b/libc/string/x86_64/mempcpy.S
new file mode 100644
index 000000000..3a8e925fd
--- /dev/null
+++ b/libc/string/x86_64/mempcpy.S
@@ -0,0 +1,3 @@
+#define __memcpy __mempcpy
+#include "memcpy.S"
+strong_alias(__mempcpy,mempcpy)
diff --git a/libc/string/x86_64/memset.S b/libc/string/x86_64/memset.S
index d66195580..923e1c208 100644
--- a/libc/string/x86_64/memset.S
+++ b/libc/string/x86_64/memset.S
@@ -22,7 +22,7 @@
#include "_glibc_inc.h"
/* BEWARE: `#ifdef memset' means that memset is redefined as `bzero' */
-#define BZERO_P (defined memset)
+#define BZERO_P (defined __memset)
/* This is somehow experimental and could made dependend on the cache
size. */
@@ -35,9 +35,6 @@ ENTRY (__memset_chk)
jb HIDDEN_JUMPTARGET (__chk_fail)
END (__memset_chk)
#endif
-.global memset
-.set memset,__memset
-.hidden __memset
ENTRY (__memset)
#if BZERO_P
mov %rsi,%rdx /* Adjust parameter. */
@@ -135,6 +132,9 @@ ENTRY (__memset)
jmp 4b
END (__memset)
+#if !BZERO_P
+strong_alias(__memset,memset)
+#endif
#if !BZERO_P && defined PIC && !defined NOT_IN_libc
strong_alias (__memset_chk, __memset_zero_constant_len_parameter)
diff --git a/libc/string/x86_64/stpcpy.S b/libc/string/x86_64/stpcpy.S
index 83294e1a8..075773371 100644
--- a/libc/string/x86_64/stpcpy.S
+++ b/libc/string/x86_64/stpcpy.S
@@ -1,6 +1,4 @@
#define USE_AS_STPCPY
#define STRCPY __stpcpy
-
#include "strcpy.S"
-
-weak_alias (__stpcpy, stpcpy)
+strong_alias(__stpcpy,stpcpy)
diff --git a/libc/string/x86_64/strcat.S b/libc/string/x86_64/strcat.S
index 9ee10b202..6c7189a21 100644
--- a/libc/string/x86_64/strcat.S
+++ b/libc/string/x86_64/strcat.S
@@ -23,9 +23,6 @@
.text
-.global strcat
-.set strcat,__strcat
-.hidden __strcat
ENTRY (BP_SYM (__strcat))
movq %rdi, %rcx /* Dest. register. */
andl $7, %ecx /* mask alignment bits */
@@ -257,3 +254,5 @@ ENTRY (BP_SYM (__strcat))
movq %rdi, %rax /* Source is return value. */
retq
END (BP_SYM (__strcat))
+
+strong_alias(__strcat,strcat)
diff --git a/libc/string/x86_64/strchr.S b/libc/string/x86_64/strchr.S
index 04d365a82..312d62b61 100644
--- a/libc/string/x86_64/strchr.S
+++ b/libc/string/x86_64/strchr.S
@@ -22,9 +22,6 @@
.text
-.globl strchr
-.set strchr,__strchr
-.hidden __strchr
ENTRY (BP_SYM (__strchr))
/* Before we start with the main loop we process single bytes
@@ -287,4 +284,5 @@ ENTRY (BP_SYM (__strchr))
retq
END (BP_SYM (__strchr))
-weak_alias (BP_SYM (strchr), BP_SYM (index))
+strong_alias(__strchr,strchr)
+strong_alias (BP_SYM (__strchr), BP_SYM (index))
diff --git a/libc/string/x86_64/strcmp.S b/libc/string/x86_64/strcmp.S
index f933c1156..1eaff1691 100644
--- a/libc/string/x86_64/strcmp.S
+++ b/libc/string/x86_64/strcmp.S
@@ -22,9 +22,6 @@
#include "_glibc_inc.h"
.text
-.global strcmp
-.set strcmp,__strcmp
-.hidden __strcmp
ENTRY (BP_SYM (__strcmp))
L(oop): movb (%rdi), %al
cmpb (%rsi), %al
@@ -42,3 +39,5 @@ L(neq): movl $1, %eax
cmovbl %ecx, %eax
ret
END (BP_SYM (__strcmp))
+
+strong_alias(__strcmp,strcmp)
diff --git a/libc/string/x86_64/strcpy.S b/libc/string/x86_64/strcpy.S
index 1a64d2745..0bd2a6471 100644
--- a/libc/string/x86_64/strcpy.S
+++ b/libc/string/x86_64/strcpy.S
@@ -22,9 +22,6 @@
#ifndef USE_AS_STPCPY
# define STRCPY __strcpy
-.global strcpy
-.set strcpy,__strcpy
-.hidden __strcpy
#endif
.text
@@ -154,3 +151,6 @@ ENTRY (BP_SYM (STRCPY))
#endif
retq
END (BP_SYM (STRCPY))
+#ifndef USE_AS_STPCPY
+strong_alias(__strcpy,strcpy)
+#endif
diff --git a/libc/string/x86_64/strcspn.S b/libc/string/x86_64/strcspn.S
index e25100bc1..35959e500 100644
--- a/libc/string/x86_64/strcspn.S
+++ b/libc/string/x86_64/strcspn.S
@@ -29,12 +29,6 @@
#define STRPBRK_P (defined __strcspn)
.text
-#if STRPBRK_P
-#else
-.global strcspn
-.set strcspn,__strcspn
-.hidden __strcspn
-#endif
ENTRY (__strcspn)
movq %rdi, %rdx /* Save SRC. */
@@ -127,3 +121,7 @@ L(4): addq $256, %rsp /* remove skipset */
#endif
ret
END (__strcspn)
+
+#if !STRPBRK_P
+strong_alias(__strcspn,strcspn)
+#endif
diff --git a/libc/string/x86_64/strlen.S b/libc/string/x86_64/strlen.S
index ab25515f8..77aae71ba 100644
--- a/libc/string/x86_64/strlen.S
+++ b/libc/string/x86_64/strlen.S
@@ -22,9 +22,6 @@
.text
-.global strlen
-.set strlen,__strlen
-.hidden __strlen
ENTRY (__strlen)
movq %rdi, %rcx /* Duplicate source pointer. */
andl $7, %ecx /* mask alignment bits */
@@ -136,3 +133,5 @@ ENTRY (__strlen)
subq %rdi, %rax /* compute difference to string start */
ret
END (__strlen)
+
+strong_alias(__strlen,strlen)
diff --git a/libc/string/x86_64/strpbrk.S b/libc/string/x86_64/strpbrk.S
index c37befe72..94b14d091 100644
--- a/libc/string/x86_64/strpbrk.S
+++ b/libc/string/x86_64/strpbrk.S
@@ -1,5 +1,3 @@
#define __strcspn __strpbrk
-.global strpbrk
-.set strpbrk,__strpbrk
-.hidden __strpbrk
#include "strcspn.S"
+strong_alias(__strpbrk,strpbrk)
diff --git a/libc/string/x86_64/strspn.S b/libc/string/x86_64/strspn.S
index 8d5903c1b..ae5b4a1df 100644
--- a/libc/string/x86_64/strspn.S
+++ b/libc/string/x86_64/strspn.S
@@ -26,9 +26,6 @@
#include "_glibc_inc.h"
.text
-.global strspn
-.set strspn,__strspn
-.hidden __strspn
ENTRY (__strspn)
movq %rdi, %rdx /* Save SRC. */
@@ -115,3 +112,5 @@ L(4): addq $256, %rsp /* remove stopset */
non-valid character */
ret
END (__strspn)
+
+strong_alias(__strspn,strspn)
diff --git a/libc/sysdeps/linux/alpha/brk.S b/libc/sysdeps/linux/alpha/brk.S
index 4e15518d2..a3f2edfe7 100644
--- a/libc/sysdeps/linux/alpha/brk.S
+++ b/libc/sysdeps/linux/alpha/brk.S
@@ -39,6 +39,7 @@ __curbrk: .skip 8
.text
.globl __brk;
+.hidden __brk;
.align 3;
.ent __brk , 0;
diff --git a/libc/sysdeps/linux/alpha/clone.S b/libc/sysdeps/linux/alpha/clone.S
index b326925d7..ed5a4f487 100644
--- a/libc/sysdeps/linux/alpha/clone.S
+++ b/libc/sysdeps/linux/alpha/clone.S
@@ -87,7 +87,7 @@ thread_start:
/* Call _exit rather than doing it inline for breakpoint purposes */
mov v0,a0
- jsr ra,_exit
+ jsr ra,_exit_internal
/* Die horribly. */
halt
diff --git a/libc/sysdeps/linux/arm/brk.c b/libc/sysdeps/linux/arm/brk.c
index 82b9835ae..e711db3b1 100644
--- a/libc/sysdeps/linux/arm/brk.c
+++ b/libc/sysdeps/linux/arm/brk.c
@@ -24,7 +24,7 @@
/* This must be initialized data because commons can't have aliases. */
void *__curbrk = 0;
-int brk (void *addr)
+int attribute_hidden __brk (void *addr)
{
void *newbrk = (void*)INTERNAL_SYSCALL(brk, , 1, addr);
@@ -37,3 +37,4 @@ int brk (void *addr)
return 0;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/arm/clone.S b/libc/sysdeps/linux/arm/clone.S
index a4d5f99bd..946d4bdda 100644
--- a/libc/sysdeps/linux/arm/clone.S
+++ b/libc/sysdeps/linux/arm/clone.S
@@ -59,11 +59,7 @@ __clone:
ldr pc, [sp]
@ and we are done, passing the return value through r0
-#ifdef __PIC__
- b _exit(PLT)
-#else
- b _exit
-#endif
+ b _exit_internal
__error:
b __syscall_error
diff --git a/libc/sysdeps/linux/arm/ioperm.c b/libc/sysdeps/linux/arm/ioperm.c
index 837de8adf..0c0c21182 100644
--- a/libc/sysdeps/linux/arm/ioperm.c
+++ b/libc/sysdeps/linux/arm/ioperm.c
@@ -37,6 +37,7 @@
#define mmap __mmap
#define sscanf __sscanf
#define fscanf __fscanf
+#define fgets __fgets
#include <errno.h>
#include <fcntl.h>
diff --git a/libc/sysdeps/linux/arm/vfork.S b/libc/sysdeps/linux/arm/vfork.S
index 530bba07c..68798995a 100644
--- a/libc/sysdeps/linux/arm/vfork.S
+++ b/libc/sysdeps/linux/arm/vfork.S
@@ -8,16 +8,20 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
+#include <features.h>
+
#define _ERRNO_H
#include <bits/errno.h>
#include <sys/syscall.h>
#ifdef __NR_fork
.text
-.global vfork
-.type vfork,%function
+.global __vfork
+.hidden __vfork
+.type __vfork,%function
.align 4
-vfork:
+
+__vfork:
#ifdef __NR_vfork
swi __NR_vfork
@@ -34,11 +38,12 @@ vfork:
swi __NR_fork
cmn r0, #4096
- /* Syscal worked. Return to child/parent */
+ /* Syscall worked. Return to child/parent */
movcc pc, lr
__error:
b __syscall_error
-.size vfork,.-vfork
+.size __vfork,.-__vfork
+strong_alias(__vfork,vfork)
#endif
diff --git a/libc/sysdeps/linux/bfin/Makefile b/libc/sysdeps/linux/bfin/Makefile
index 85f3cb910..3970f6263 100644
--- a/libc/sysdeps/linux/bfin/Makefile
+++ b/libc/sysdeps/linux/bfin/Makefile
@@ -1,55 +1,13 @@
# Makefile for uClibc
#
-# Copyright (C) 2000-2004 Erik Andersen <andersen@uclibc.org>
+# Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
#
-# This program is free software; you can redistribute it and/or modify it under
-# the terms of the GNU Library General Public License as published by the Free
-# Software Foundation; either version 2 of the License, or (at your option) any
-# later version.
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Library General Public License
-# along with this program; if not, write to the Free Software Foundation, Inc.,
-# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-TOPDIR=../../../../
-include $(TOPDIR)Rules.mak
-
-CRT_SRC := crt0.S
-CRT_OBJ := crt0.o
-
-SSRC := __longjmp.S setjmp.S bsd-_setjmp.S vfork.S
-SOBJ := $(patsubst %.S,%.o, $(SSRC))
-
-CSRC := brk.c bsdsetjmp.c clone.c syscall.c
-COBJ := $(patsubst %.c,%.o, $(CSRC))
-
-OBJS := $(SOBJ) $(COBJ)
-
-OBJ_LIST := ../../../obj.sysdeps.$(TARGET_ARCH)
-
-all: $(OBJ_LIST)
-
-$(OBJ_LIST): $(OBJS) $(CRT_OBJ)
- $(STRIPTOOL) -x -R .note -R .comment $^
- $(INSTALL) -d $(TOPDIR)lib/
- cp $(CRT_OBJ) $(TOPDIR)lib/
- echo $(patsubst %, sysdeps/linux/$(TARGET_ARCH)/%, $(OBJS)) > $@
-
-$(CRT_OBJ): $(CRT_SRC)
- $(CC) $(ASFLAGS) -DL_$* $< -c -o $*.o
-
-$(SOBJ): %.o : %.S
- $(CC) $(ASFLAGS) -c $< -o $@
-
-$(COBJ): %.o : %.c
- $(CC) $(CFLAGS) -c $< -o $@
-
-headers:
-clean:
- $(RM) *.o *~ core
+top_srcdir=../../../../
+top_builddir=../../../../
+all: objs
+include $(top_builddir)Rules.mak
+include Makefile.arch
+include $(top_srcdir)Makerules
diff --git a/libc/sysdeps/linux/bfin/Makefile.arch b/libc/sysdeps/linux/bfin/Makefile.arch
new file mode 100644
index 000000000..7a428b380
--- /dev/null
+++ b/libc/sysdeps/linux/bfin/Makefile.arch
@@ -0,0 +1,12 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+
+CSRC := brk.c bsdsetjmp.c clone.c syscall.c
+
+SSRC := __longjmp.S setjmp.S bsd-_setjmp.S vfork.S
+
+include $(top_srcdir)libc/sysdeps/linux/Makefile.commonarch
diff --git a/libc/sysdeps/linux/bfin/bits/syscalls.h b/libc/sysdeps/linux/bfin/bits/syscalls.h
index 62541b873..82692fc65 100644
--- a/libc/sysdeps/linux/bfin/bits/syscalls.h
+++ b/libc/sysdeps/linux/bfin/bits/syscalls.h
@@ -6,14 +6,138 @@
#include <features.h>
-/* Do something very evil for now. Until we create our own syscall
- * macros, short circuit bits/sysnum.h and use asm/unistd.h instead */
-#include <asm/unistd.h>
-
/* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
* header files. It also defines the traditional `SYS_<name>' macros for older
* programs. */
#include <bits/sysnum.h>
-#endif /* _BITS_SYSCALLS_H */
+/* This code is mostly cut & paste from the uClinux bfin port */
+
+#ifndef __ASSEMBLER__
+
+#define __syscall_return(type, res) \
+do { \
+ if ((unsigned long)(res) >= (unsigned long)(-125)) \
+ { __set_errno(-(res)); \
+ res = -1; \
+ } \
+ return (type) (res); \
+} while (0)
+
+#define _syscall0(type,name) \
+type name(void) { \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "p0 = %1;\n\t" \
+ "excpt 0;\n\t" \
+ "%0=r0;\n\t" \
+ : "=da" (__res) \
+ : "i" (__NR_##name) \
+ : "CC", "P0"); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall1(type,name,type1,arg1) \
+type name(type1 arg1) { \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "r0=%2;\n\t" \
+ "p0=%1;\n\t" \
+ "excpt 0;\n\t" \
+ "%0=r0;\n\t" \
+ : "=da" (__res) \
+ : "i" (__NR_##name), \
+ "a" ((long)(arg1)) \
+ : "CC", "R0", "P0"); \
+__syscall_return(type,__res); \
+}
+#define _syscall2(type,name,type1,arg1,type2,arg2) \
+type name(type1 arg1,type2 arg2) { \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "r1=%3;\n\t" \
+ "r0=%2;\n\t" \
+ "p0=%1;\n\t" \
+ "excpt 0;\n\t" \
+ "%0=r0;\n\t" \
+ : "=da" (__res) \
+ : "i" (__NR_##name), \
+ "a" ((long)(arg1)), \
+ "a" ((long)(arg2)) \
+ : "CC", "R0","R1", "P0"); \
+__syscall_return(type,__res); \
+}
+
+
+#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
+type name(type1 arg1,type2 arg2,type3 arg3) { \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "r2=%4;\n\t" \
+ "r1=%3;\n\t" \
+ "r0=%2;\n\t" \
+ "p0=%1;\n\t" \
+ "excpt 0;\n\t" \
+ "%0=r0;\n\t" \
+ : "=da" (__res) \
+ : "i" (__NR_##name), \
+ "a" ((long)(arg1)), \
+ "a" ((long)(arg2)), \
+ "a" ((long)(arg3)) \
+ : "CC", "R0","R1","R2", "P0"); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\
+type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "[--sp] = r3;\n\t" \
+ "r3=%5;\n\t" \
+ "r2=%4;\n\t" \
+ "r1=%3;\n\t" \
+ "r0=%2;\n\t" \
+ "p0=%1;\n\t" \
+ "excpt 0;\n\t" \
+ "%0=r0;\n\t" \
+ "r3 = [sp++];\n\t" \
+ : "=da" (__res) \
+ : "i" (__NR_##name), \
+ "a" ((long)(arg1)), \
+ "a" ((long)(arg2)), \
+ "a" ((long)(arg3)), \
+ "a" ((long)(arg4)) \
+ : "CC", "R0","R1","R2","R3", "P0"); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
+type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \
+ long __res; \
+ __asm__ __volatile__ ( \
+ "[--sp] = r4;\n\t" \
+ "[--sp] = r3;\n\t" \
+ "r4=%6;\n\t" \
+ "r3=%5;\n\t" \
+ "r2=%4;\n\t" \
+ "r1=%3;\n\t" \
+ "r0=%2;\n\t" \
+ "P0=%1;\n\t" \
+ "excpt 0;\n\t" \
+ "%0=r0;\n\t" \
+ "r3 = [sp++];\n\t" \
+ "r4 = [sp++];\n\t" \
+ : "=da" (__res) \
+ : "i" (__NR_##name), \
+ "rm" ((long)(arg1)), \
+ "rm" ((long)(arg2)), \
+ "rm" ((long)(arg3)), \
+ "rm" ((long)(arg4)), \
+ "rm" ((long)(arg5)) \
+ : "CC","R0","R1","R2","R3","R4","P0"); \
+__syscall_return(type,__res); \
+}
+
+#endif /* __ASSEMBLER__ */
+#endif /* _BITS_SYSCALLS_H */
diff --git a/libc/sysdeps/linux/bfin/bits/uClibc_page.h b/libc/sysdeps/linux/bfin/bits/uClibc_page.h
new file mode 100644
index 000000000..311dd40ab
--- /dev/null
+++ b/libc/sysdeps/linux/bfin/bits/uClibc_page.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2004 Erik Andersen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * The GNU C Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the GNU C Library; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307 USA.
+ */
+
+/* Supply an architecture specific value for PAGE_SIZE and friends. */
+
+#ifndef _UCLIBC_PAGE_H
+#define _UCLIBC_PAGE_H
+
+/* PAGE_SHIFT determines the page size -- in this case 4096 */
+#define PAGE_SHIFT (12)
+#define PAGE_SIZE (1UL << PAGE_SHIFT)
+#define PAGE_MASK (~(PAGE_SIZE-1))
+
+#endif /* _UCLIBC_PAGE_H */
diff --git a/libc/sysdeps/linux/bfin/brk.c b/libc/sysdeps/linux/bfin/brk.c
index 178124ed3..1cb30216d 100644
--- a/libc/sysdeps/linux/bfin/brk.c
+++ b/libc/sysdeps/linux/bfin/brk.c
@@ -6,7 +6,7 @@
/* This must be initialized data because commons can't have aliases. */
void * __curbrk = 0;
-int brk (void *addr)
+int attribute_hidden __brk (void *addr)
{
void *newbrk;
@@ -28,3 +28,4 @@ int brk (void *addr)
return 0;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/cris/brk.c b/libc/sysdeps/linux/cris/brk.c
index 0bc08d5e6..10965d3b9 100644
--- a/libc/sysdeps/linux/cris/brk.c
+++ b/libc/sysdeps/linux/cris/brk.c
@@ -7,7 +7,7 @@ extern void * __curbrk;
extern int __init_brk (void);
-int brk(void * end_data_seg)
+int attribute_hidden __brk(void * end_data_seg)
{
if (__init_brk () == 0) {
/*
@@ -29,3 +29,4 @@ int brk(void * end_data_seg)
return -1;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/cris/clone.S b/libc/sysdeps/linux/cris/clone.S
index 56ea05c72..19ba71996 100644
--- a/libc/sysdeps/linux/cris/clone.S
+++ b/libc/sysdeps/linux/cris/clone.S
@@ -69,7 +69,7 @@ ENTRY (__clone)
jsr r0
SETUP_PIC
- PLTCALL (_exit)
+ PLTCALL (_exit_internal)
/* Die horribly. */
test.d [6809]
diff --git a/libc/sysdeps/linux/cris/fork.c b/libc/sysdeps/linux/cris/fork.c
index 0399edce8..4dd8e0269 100644
--- a/libc/sysdeps/linux/cris/fork.c
+++ b/libc/sysdeps/linux/cris/fork.c
@@ -8,5 +8,4 @@ SYSCALL__ (__libc_fork, 0)
R0&-1==R0, and the child gets R0&0==0. */
/* i dunno what the blurb above is useful for. we just return. */
__asm__("ret\n\tnop");
-weak_alias(__libc_fork, fork);
-
+weak_alias(__libc_fork, fork)
diff --git a/libc/sysdeps/linux/cris/sbrk.c b/libc/sysdeps/linux/cris/sbrk.c
index 1ed1d9df9..3683435bf 100644
--- a/libc/sysdeps/linux/cris/sbrk.c
+++ b/libc/sysdeps/linux/cris/sbrk.c
@@ -9,8 +9,8 @@ extern void * __curbrk;
extern int __init_brk (void);
-void *
-sbrk(intptr_t increment)
+void attribute_hidden *
+__sbrk(intptr_t increment)
{
if (__init_brk () == 0) {
void * tmp = __curbrk + increment;
@@ -34,3 +34,4 @@ sbrk(intptr_t increment)
}
return ((void *) -1);
}
+strong_alias(__sbrk,sbrk)
diff --git a/libc/sysdeps/linux/frv/__init_brk.c b/libc/sysdeps/linux/frv/__init_brk.c
index c9a2a3ec5..92e07c49d 100644
--- a/libc/sysdeps/linux/frv/__init_brk.c
+++ b/libc/sysdeps/linux/frv/__init_brk.c
@@ -7,7 +7,7 @@
void * __curbrk = 0;
#define __NR__brk __NR_brk
-_syscall1(void *, _brk, void *, ptr);
+attribute_hidden _syscall1(void *, _brk, void *, ptr);
int
__init_brk (void)
diff --git a/libc/sysdeps/linux/frv/brk.c b/libc/sysdeps/linux/frv/brk.c
index 2406904a3..d6063fc27 100644
--- a/libc/sysdeps/linux/frv/brk.c
+++ b/libc/sysdeps/linux/frv/brk.c
@@ -7,9 +7,9 @@
extern void * __curbrk;
extern int __init_brk (void);
-extern void *_brk(void *ptr);
+extern void *_brk(void *ptr) attribute_hidden;
-int brk(void * end_data_seg)
+int attribute_hidden __brk(void * end_data_seg)
{
if (__init_brk () == 0)
{
@@ -20,3 +20,4 @@ int brk(void * end_data_seg)
}
return -1;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/frv/clone.S b/libc/sysdeps/linux/frv/clone.S
index f835f0ba2..b714b45b1 100644
--- a/libc/sysdeps/linux/frv/clone.S
+++ b/libc/sysdeps/linux/frv/clone.S
@@ -75,7 +75,7 @@ __clone:
breakpoints work.*/
mov.p gr17, gr15
- call _exit
+ call _exit_internal
/* Should never get here. */
jmpl @(gr0, gr0)
diff --git a/libc/sysdeps/linux/frv/sbrk.c b/libc/sysdeps/linux/frv/sbrk.c
index 1c9e5b172..e9faf7db0 100644
--- a/libc/sysdeps/linux/frv/sbrk.c
+++ b/libc/sysdeps/linux/frv/sbrk.c
@@ -7,10 +7,10 @@
extern void * __curbrk;
extern int __init_brk (void);
-extern void *_brk(void *ptr);
+extern void *_brk(void *ptr) attribute_hidden;
-void *
-sbrk(intptr_t increment)
+void attribute_hidden *
+__sbrk(intptr_t increment)
{
if (__init_brk () == 0)
{
@@ -23,3 +23,4 @@ sbrk(intptr_t increment)
}
return ((void *) -1);
}
+strong_alias(__sbrk,sbrk)
diff --git a/libc/sysdeps/linux/frv/vfork.S b/libc/sysdeps/linux/frv/vfork.S
index 230f2f820..b5ecc09af 100644
--- a/libc/sysdeps/linux/frv/vfork.S
+++ b/libc/sysdeps/linux/frv/vfork.S
@@ -17,15 +17,18 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <features.h>
+
#include <asm/unistd.h>
#define _ERRNO_H 1
#include <bits/errno.h>
.text
- .globl vfork
- .type vfork,@function
+ .globl __vfork
+ .hidden __vfork
+ .type __vfork,@function
/* int vfork(void) */
-vfork:
+__vfork:
setlos.p #__NR_vfork, gr7
setlos #-4096, gr4
tra gr0, gr0
@@ -38,5 +41,6 @@ vfork:
ldd @(gr14, gr15), gr14
jmpl @(gr14, gr0)
- .size vfork,.-vfork
+ .size __vfork,.-__vfork
+strong_alias(__vfork,vfork)
diff --git a/libc/sysdeps/linux/h8300/brk.c b/libc/sysdeps/linux/h8300/brk.c
index bd0ecaa5c..d69f9a2d3 100644
--- a/libc/sysdeps/linux/h8300/brk.c
+++ b/libc/sysdeps/linux/h8300/brk.c
@@ -9,7 +9,7 @@
void *__curbrk = 0;
-int brk (void *addr)
+int attribute_hidden __brk (void *addr)
{
void *newbrk;
@@ -31,3 +31,4 @@ int brk (void *addr)
return 0;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/hppa/brk.c b/libc/sysdeps/linux/hppa/brk.c
index 68bc3ffc8..f50360aa5 100644
--- a/libc/sysdeps/linux/hppa/brk.c
+++ b/libc/sysdeps/linux/hppa/brk.c
@@ -23,8 +23,8 @@
/* This must be initialized data because commons can't have aliases. */
void *__curbrk = 0;
-int
-brk (void *addr)
+int attribute_hidden
+__brk (void *addr)
{
void *newbrk;
@@ -38,3 +38,4 @@ brk (void *addr)
return 0;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/hppa/clone.S b/libc/sysdeps/linux/hppa/clone.S
index 56a40eadc..8395cdada 100644
--- a/libc/sysdeps/linux/hppa/clone.S
+++ b/libc/sysdeps/linux/hppa/clone.S
@@ -90,7 +90,7 @@ thread_start:
bl $$dyncall,%r31
copy %r31,%rp
- bl _exit,%rp
+ bl _exit_internal,%rp
copy %ret0,%arg0
/* Die horribly. */
diff --git a/libc/sysdeps/linux/i386/bits/syscalls.h b/libc/sysdeps/linux/i386/bits/syscalls.h
index df3b0b429..6ad3b1dd9 100644
--- a/libc/sysdeps/linux/i386/bits/syscalls.h
+++ b/libc/sysdeps/linux/i386/bits/syscalls.h
@@ -101,6 +101,14 @@ type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \
}
+#undef _syscall6
+#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
+ type5,arg5,type6,arg6) \
+type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
+{ \
+return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \
+}
+
#define INLINE_SYSCALL(name, nr, args...) \
({ \
unsigned int resultvar; \
@@ -126,6 +134,7 @@ return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \
#define LOADARGS_3 LOADARGS_1
#define LOADARGS_4 LOADARGS_1
#define LOADARGS_5 LOADARGS_1
+#define LOADARGS_6 LOADARGS_1 "push %%ebp ; movl %7, %%ebp\n\t"
#define RESTOREARGS_0
#define RESTOREARGS_1 \
@@ -134,6 +143,7 @@ return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \
#define RESTOREARGS_3 RESTOREARGS_1
#define RESTOREARGS_4 RESTOREARGS_1
#define RESTOREARGS_5 RESTOREARGS_1
+#define RESTOREARGS_6 "pop %%ebp\n\t" RESTOREARGS_1
#define ASMFMT_0()
#define ASMFMT_1(arg1) \
@@ -146,6 +156,8 @@ return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \
, "aD" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
#define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
, "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
+#define ASMFMT_6(arg1, arg2, arg3, arg4, arg5, arg6) \
+ , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5), "m" (arg6)
#endif /* __ASSEMBLER__ */
#endif /* _BITS_SYSCALLS_H */
diff --git a/libc/sysdeps/linux/i386/brk.c b/libc/sysdeps/linux/i386/brk.c
index 09c6be7e3..5790e2fca 100644
--- a/libc/sysdeps/linux/i386/brk.c
+++ b/libc/sysdeps/linux/i386/brk.c
@@ -25,8 +25,7 @@
/* This must be initialized data because commons can't have aliases. */
void *__curbrk = 0;
-
-int brk (void *addr)
+int attribute_hidden __brk (void *addr)
{
void *__unbounded newbrk, *__unbounded scratch;
@@ -47,3 +46,4 @@ int brk (void *addr)
return 0;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/i386/vfork.S b/libc/sysdeps/linux/i386/vfork.S
index d382dbac3..18a8e5dfa 100644
--- a/libc/sysdeps/linux/i386/vfork.S
+++ b/libc/sysdeps/linux/i386/vfork.S
@@ -3,17 +3,20 @@
*
*/
+#include <features.h>
#include <sys/syscall.h>
#ifndef __NR_vfork
/* No vfork so use fork instead */
-.weak vfork ; vfork = __libc_fork
+hidden_strong_alias(__fork,__vfork)
+weak_alias(vfork,__libc_fork)
#else
.text
.global __vfork
+.hidden __vfork
.type __vfork,%function
.align 1<<4
@@ -27,7 +30,5 @@ __vfork:
ret
.size __vfork,.-__vfork
-
-
-.weak vfork ; vfork = __vfork
#endif
+strong_alias(__vfork,vfork)
diff --git a/libc/sysdeps/linux/m68k/Makefile.arch b/libc/sysdeps/linux/m68k/Makefile.arch
index 81e5b27f7..2ebd602d7 100644
--- a/libc/sysdeps/linux/m68k/Makefile.arch
+++ b/libc/sysdeps/linux/m68k/Makefile.arch
@@ -11,8 +11,6 @@ SSRC := __longjmp.S bsd-_setjmp.S bsd-setjmp.S clone.S setjmp.S vfork.S
ifneq ($(HAVE_ELF),y)
ARCH_HEADERS := float.h
-else
-ARCH_HEADERS := fpu_control.h
endif
include $(top_srcdir)libc/sysdeps/linux/Makefile.commonarch
diff --git a/libc/sysdeps/linux/m68k/brk.c b/libc/sysdeps/linux/m68k/brk.c
index 689bc5bf7..4c33549cc 100644
--- a/libc/sysdeps/linux/m68k/brk.c
+++ b/libc/sysdeps/linux/m68k/brk.c
@@ -7,7 +7,7 @@
/* This must be initialized data because commons can't have aliases. */
void * __curbrk = 0;
-int brk (void *addr)
+int attribute_hidden __brk (void *addr)
{
void *newbrk;
@@ -28,3 +28,4 @@ int brk (void *addr)
return 0;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/m68k/vfork.S b/libc/sysdeps/linux/m68k/vfork.S
index 5db163bf5..e58b9e949 100644
--- a/libc/sysdeps/linux/m68k/vfork.S
+++ b/libc/sysdeps/linux/m68k/vfork.S
@@ -1,3 +1,4 @@
+#include <features.h>
#include <asm/unistd.h>
@@ -10,11 +11,13 @@
.text
.align 2
.globl errno
- .globl vfork
-#if defined __HAVE_ELF__
- .type vfork,@function
+ .globl __vfork
+#ifdef __HAVE_ELF__
+ .hidden __vfork
+ .type __vfork,@function
#endif
-vfork:
+
+__vfork:
movl %sp@+, %a1 /* save the return address for later */
movl IMM __NR_vfork,%d0
trap #0
@@ -24,7 +27,7 @@ vfork:
jmp %a1@ /* don't return, just jmp directly */
fix_errno:
negl %d0
-#ifndef __PIC__
+#ifndef __PIC__ /* needs handling as the other archs */
movl errno, %a0
#else
movl errno@GOT(%a5), %a0
@@ -33,3 +36,5 @@ fix_errno:
movl IMM -1, %d0
jmp %a1@ /* don't return, just jmp directly */
+.size __vfork,.-__vfork
+strong_alias(__vfork,vfork)
diff --git a/libc/sysdeps/linux/nios/Makefile b/libc/sysdeps/linux/nios/Makefile
index b1c558fee..3970f6263 100644
--- a/libc/sysdeps/linux/nios/Makefile
+++ b/libc/sysdeps/linux/nios/Makefile
@@ -1,56 +1,13 @@
# Makefile for uClibc
#
-# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
+# Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
#
-# This program is free software; you can redistribute it and/or modify it under
-# the terms of the GNU Library General Public License as published by the Free
-# Software Foundation; either version 2 of the License, or (at your option) any
-# later version.
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Library General Public License
-# along with this program; if not, write to the Free Software Foundation, Inc.,
-# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-TOPDIR=../../../../
-include $(TOPDIR)Rules.mak
-
-CRT_SRC := crt0.S
-CRT_OBJ := crt0.o crt1.o
-
-SSRC := __longjmp.S bsd-_setjmp.S bsd-setjmp.S setjmp.S clone.S vfork.S
-SOBJ := $(patsubst %.S,%.o, $(SSRC))
-
-CSRC := brk.c crtbegin.c crtend.c
-COBJ := $(patsubst %.c,%.o, $(CSRC))
-
-OBJS := $(SOBJ) $(COBJ)
-
-OBJ_LIST := ../../../obj.sysdeps.$(TARGET_ARCH)
-
-all: $(OBJ_LIST)
-
-$(OBJ_LIST): $(OBJS) $(CRT_OBJ)
- $(STRIPTOOL) -x -R .note -R .comment $^
- $(INSTALL) -d $(TOPDIR)lib/
- cp $(CRT_OBJ) $(TOPDIR)lib/
- echo $(patsubst %, sysdeps/linux/$(TARGET_ARCH)/%, $(OBJS)) > $@
-
-$(CRT_OBJ): $(CRT_SRC)
- $(CC) $(ASFLAGS) -DL_$* $< -c -o $*.o
-
-$(SOBJ): %.o : %.S
- $(CC) $(ASFLAGS) -c $< -o $@
-
-$(COBJ): %.o : %.c
- $(CC) $(CFLAGS) -c $< -o $@
-
-headers:
- $(LN) -fs ../libc/sysdeps/linux/nios/fpu_control.h $(TOPDIR)/include/
-clean:
- $(RM) *.o *~ core
+top_srcdir=../../../../
+top_builddir=../../../../
+all: objs
+include $(top_builddir)Rules.mak
+include Makefile.arch
+include $(top_srcdir)Makerules
diff --git a/libc/sysdeps/linux/nios/Makefile.arch b/libc/sysdeps/linux/nios/Makefile.arch
new file mode 100644
index 000000000..9bcd0be7e
--- /dev/null
+++ b/libc/sysdeps/linux/nios/Makefile.arch
@@ -0,0 +1,14 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+
+CSRC := brk.c crtbegin.c crtend.c
+
+SSRC := \
+ __longjmp.S bsd-_setjmp.S bsd-setjmp.S setjmp.S \
+ clone.S vfork.S
+
+include $(top_srcdir)libc/sysdeps/linux/Makefile.commonarch
diff --git a/libc/sysdeps/linux/nios/brk.c b/libc/sysdeps/linux/nios/brk.c
index 797a66d0a..2e785b734 100644
--- a/libc/sysdeps/linux/nios/brk.c
+++ b/libc/sysdeps/linux/nios/brk.c
@@ -25,8 +25,7 @@
/* This must be initialized data because commons can't have aliases. */
void *__curbrk = 0;
-
-int brk (void *addr)
+int attribute_hidden __brk (void *addr)
{
void *newbrk;
register int g1 asm("%g1") = __NR_brk;
@@ -43,3 +42,4 @@ int brk (void *addr)
return 0;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/nios/crt0.c b/libc/sysdeps/linux/nios/crt0.c
deleted file mode 100644
index 48b1a0f07..000000000
--- a/libc/sysdeps/linux/nios/crt0.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
-
-This file is part of the GNU C Library.
-
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
-
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
-
-#include <asm/ptrace.h>
-
-#define nop() __asm__ __volatile__ ("nop")
-
-extern inline int _stack_frame_address(void)
-{
- int retval;
- __asm__ __volatile__(
- "mov %0, %%fp\n\t"
- : "=r" (retval) );
- return retval;
-}
-
-void __uClibc_main(int argc,void *argv,void *envp);
-
-void _start(void)
-{
- void **p;
-
- nop(); /* placeholder for breakpoint */
- nop();
-
- p = (int *) (_stack_frame_address() + REGWIN_SZ);
- __uClibc_main( (int) *p, *(p+1), *(p+2) );
-
-/* If that didn't kill us, ... */
-
- asm("trap 0");
-}
-
-/*
- * this was needed for gcc/g++-builds, atexit was not getting included
- * for some stupid reason, this gets us a compiler
- */
-// empty_func:
-// // rts
-// .weak atexit
-// atexit = empty_func
-//
-// /*
-// * a little bit of stuff to support C++
-// */
-// .section .ctors,"aw"
-// .align 4
-// .global __CTOR_LIST__
-// __CTOR_LIST__:
-// .long -1
-//
-// .section .dtors,"aw"
-// .align 4
-// .global __DTOR_LIST__
-// __DTOR_LIST__:
-// .long -1
-
diff --git a/libc/sysdeps/linux/nios/crt0.S b/libc/sysdeps/linux/nios/crt1.S
index bbf4ede6a..98777e831 100644
--- a/libc/sysdeps/linux/nios/crt0.S
+++ b/libc/sysdeps/linux/nios/crt1.S
@@ -27,7 +27,8 @@ Cambridge, MA 02139, USA. */
.type __start,@function
.weak _init
.weak _fini
- .type __uClibc_start_main,@function
+ .type main,@function
+ .type __uClibc_main,@function
.type __h_errno_location, @function
.type _stdio_init, @function
.type _stdio_term, @function
@@ -38,15 +39,17 @@ _start:
nop
nop
- lds %o0,[%sp, (REGWIN_SZ / 4) + 0] // main's argc
- lds %o1,[%sp, (REGWIN_SZ / 4) + 1] // main's argv
- lds %o2,[%sp, (REGWIN_SZ / 4) + 2] // main's envp
+ MOVIA %o0, main@h
+ lds %o1,[%sp, (REGWIN_SZ / 4) + 0] // main's argc
+ lds %o2,[%sp, (REGWIN_SZ / 4) + 1] // main's argv
MOVIA %o3, _init@h
MOVIA %o4, _fini@h
- MOVIA %o5, __uClibc_start_main@h
-
- call %o5
+ mov %o5, %i0 /* rtld_fini */
+ mov %o6, %sp /* stack_end */
+ MOVIA %o7, __uClibc_main@h
+
+ call %o7
nop
@@ -54,4 +57,3 @@ _start:
__exit:
MOVIP %g1, __NR_exit
trap 63
- \ No newline at end of file
diff --git a/libc/sysdeps/linux/nios2/Makefile b/libc/sysdeps/linux/nios2/Makefile
index 4202eb611..633c91f3e 100644
--- a/libc/sysdeps/linux/nios2/Makefile
+++ b/libc/sysdeps/linux/nios2/Makefile
@@ -1,71 +1,13 @@
# Makefile for uClibc
#
-# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
+# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
#
-# This program is free software; you can redistribute it and/or modify it under
-# the terms of the GNU Library General Public License as published by the Free
-# Software Foundation; either version 2 of the License, or (at your option) any
-# later version.
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Library General Public License
-# along with this program; if not, write to the Free Software Foundation, Inc.,
-# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-TOPDIR=../../../../
-include $(TOPDIR)Rules.mak
-
-CRT_SRC := crt0.S
-CRT_OBJ := crt0.o crt1.o
-CTOR_TARGETS := $(TOPDIR)lib/crti.o $(TOPDIR)lib/crtn.o
-
-SSRC := __longjmp.S bsd-_setjmp.S bsd-setjmp.S setjmp.S vfork.S clone.S
-SOBJ := $(patsubst %.S,%.o, $(SSRC))
-
-CSRC := brk.c syscall.c
-COBJ := $(patsubst %.c,%.o, $(CSRC))
-
-OBJS := $(SOBJ) $(COBJ)
-
-OBJ_LIST := ../../../obj.sysdeps.$(TARGET_ARCH)
-
-all: $(OBJ_LIST) $(CTOR_TARGETS)
-
-$(OBJ_LIST): $(OBJS) $(CRT_OBJ)
- $(STRIPTOOL) -x -R .note -R .comment $^
- $(INSTALL) -d $(TOPDIR)lib/
- cp $(CRT_OBJ) $(TOPDIR)lib/
- echo $(patsubst %, sysdeps/linux/$(TARGET_ARCH)/%, $(OBJS)) > $@
-
-$(CRT_OBJ): $(CRT_SRC)
- $(CC) $(ASFLAGS) -DL_$* $< -c -o $*.o
-
-$(SOBJ): %.o : %.S
- $(CC) $(ASFLAGS) -c $< -o $@
-
-$(COBJ): %.o : %.c
- $(CC) $(CFLAGS) -c $< -o $@
-
-ifeq ($(UCLIBC_CTOR_DTOR),y)
-$(TOPDIR)lib/crti.o: crti.S
- $(INSTALL) -d $(TOPDIR)lib/
- $(CC) $(ASFLAGS) $(SSP_DISABLE_FLAGS) -c $< -o $@
-
-$(TOPDIR)lib/crtn.o: crtn.S
- $(INSTALL) -d $(TOPDIR)lib/
- $(CC) $(ASFLAGS) $(SSP_DISABLE_FLAGS) -c $< -o $@
-else
-$(CTOR_TARGETS):
- $(INSTALL) -d $(TOPDIR)lib/
- $(AR) $(ARFLAGS) $@
-endif
-
-headers:
- $(LN) -fs ../libc/sysdeps/linux/nios2/fpu_control.h $(TOPDIR)/include/
-clean:
- $(RM) *.o *~ core
+top_srcdir=../../../../
+top_builddir=../../../../
+all: objs
+include $(top_builddir)Rules.mak
+include Makefile.arch
+include $(top_srcdir)Makerules
diff --git a/libc/sysdeps/linux/nios2/Makefile.arch b/libc/sysdeps/linux/nios2/Makefile.arch
new file mode 100644
index 000000000..fadde953e
--- /dev/null
+++ b/libc/sysdeps/linux/nios2/Makefile.arch
@@ -0,0 +1,14 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+
+CSRC := brk.c syscall.c
+
+SSRC := \
+ __longjmp.S bsd-_setjmp.S bsd-setjmp.S setjmp.S \
+ vfork.S clone.S
+
+include $(top_srcdir)libc/sysdeps/linux/Makefile.commonarch
diff --git a/libc/sysdeps/linux/nios2/brk.c b/libc/sysdeps/linux/nios2/brk.c
index 1e7eb0382..e5a4c5d07 100644
--- a/libc/sysdeps/linux/nios2/brk.c
+++ b/libc/sysdeps/linux/nios2/brk.c
@@ -26,7 +26,7 @@
void *__curbrk = 0;
-int brk (void *addr)
+int attribute_hidden __brk (void *addr)
{
void *newbrk;
register int r2 asm("r2") = TRAP_ID_SYSCALL;
@@ -44,3 +44,4 @@ int brk (void *addr)
return 0;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/nios2/crt0.S b/libc/sysdeps/linux/nios2/crt1.S
index 95c9450cd..948eeb1ed 100644
--- a/libc/sysdeps/linux/nios2/crt0.S
+++ b/libc/sysdeps/linux/nios2/crt1.S
@@ -8,6 +8,7 @@
* directory of this archive for more details.
*
* Written by Wentao Xu <wentao@microtronix.com>
+ * Updated by Thomas Chou <thomas@wytron.com.tw> for crt1.S
*
*/
@@ -18,7 +19,8 @@
.type __start,@function
.weak _init
.weak _fini
- .type __uClibc_start_main,@function
+ .type main,@function
+ .type __uClibc_main,@function
.type __h_errno_location, @function
.type _stdio_init, @function
.type _stdio_term, @function
@@ -35,30 +37,34 @@ _start:
movhi gp, %hiadj(_gp)
addi gp, gp, %lo(_gp)
- /* load argc, argv, envp from stack */
- ldw r4, 0(sp)
- ldw r5, 4(sp)
- ldw r6, 8(sp)
-
+ /* load main, argc, argv from stack */
+ movhi r4, %hi(main)
+ ori r4, r4, %lo(main) /* main */
+ ldw r5, 0(sp) /* argc */
+ ldw r6, 4(sp) /* argv */
+
/* load the 4th arg */
movhi r7, %hi(_init)
ori r7, r7, %lo(_init)
-
+
/* reuse the argc stack slot for the 5th arg */
movhi r8, %hi(_fini)
ori r8, r8, %lo(_fini)
stw r8, 0(sp)
-
+
+ stw r2, 4(sp) /* rtld_fini */
+ stw sp, 8(sp) /* stack_end */
+
/* call uClibc_main, shouldn't return */
#ifdef __PIC__
/* just pray 16 bit offset is enough */
- br __uClibc_start_main
+ br __uClibc_main
#else
- call __uClibc_start_main
+ call __uClibc_main
#endif
/* crash in the event of return */
__exit:
movui r2, TRAP_ID_SYSCALL
movui r3, __NR_exit
- trap \ No newline at end of file
+ trap
diff --git a/libc/sysdeps/linux/powerpc/brk.S b/libc/sysdeps/linux/powerpc/brk.S
index c0b436d96..b718c0de4 100644
--- a/libc/sysdeps/linux/powerpc/brk.S
+++ b/libc/sysdeps/linux/powerpc/brk.S
@@ -26,6 +26,7 @@
.comm __curbrk,4,4
.text
.globl __brk
+ .hidden __brk
.type __brk,@function
.align 2
diff --git a/libc/sysdeps/linux/powerpc/clone.S b/libc/sysdeps/linux/powerpc/clone.S
index f7c6bd18e..9e8a1ca53 100644
--- a/libc/sysdeps/linux/powerpc/clone.S
+++ b/libc/sysdeps/linux/powerpc/clone.S
@@ -78,11 +78,7 @@ __clone:
mr r3,r31
bctrl
/* Call _exit with result from procedure. */
-#ifdef __PIC__
- b _exit@plt
-#else
- b _exit
-#endif
+ b _exit_internal
.Lparent:
/* Parent. Restore registers & return. */
diff --git a/libc/sysdeps/linux/powerpc/crt1.S b/libc/sysdeps/linux/powerpc/crt1.S
index c042462e9..47419bb52 100644
--- a/libc/sysdeps/linux/powerpc/crt1.S
+++ b/libc/sysdeps/linux/powerpc/crt1.S
@@ -60,7 +60,8 @@ _start:
lwz r4,0(r9)
/* find argv one word offset from the stack pointer */
addi r5,r9,4
- mr r8,r7 /* Pass _dl_fini from ldso or NULL if statically linked */
+ mr r8,r3 /* Pass _dl_fini from ldso or NULL if statically linked
+ Note: using r3 instead of r7, since linux 2.6 clobbers r7 */
/* Ok, now run uClibc's main() -- shouldn't return */
#ifdef __PIC__
lwz r6,_init@got(r31)
diff --git a/libc/sysdeps/linux/powerpc/pread_write.c b/libc/sysdeps/linux/powerpc/pread_write.c
index 7f8923720..8115d4d01 100644
--- a/libc/sysdeps/linux/powerpc/pread_write.c
+++ b/libc/sysdeps/linux/powerpc/pread_write.c
@@ -96,11 +96,11 @@ static ssize_t __fake_pread_write(int fd, void *buf,
/* Since we must not change the file pointer preserve the
* value so that we can restore it later. */
- if ((old_offset=lseek(fd, 0, SEEK_CUR)) == (off_t) -1)
+ if ((old_offset=__lseek(fd, 0, SEEK_CUR)) == (off_t) -1)
return -1;
/* Set to wanted position. */
- if (lseek (fd, offset, SEEK_SET) == (off_t) -1)
+ if (__lseek (fd, offset, SEEK_SET) == (off_t) -1)
return -1;
if (do_pwrite==1) {
@@ -114,7 +114,7 @@ static ssize_t __fake_pread_write(int fd, void *buf,
/* Now we have to restore the position. If this fails we
* have to return this as an error. */
save_errno = errno;
- if (lseek(fd, old_offset, SEEK_SET) == (off_t) -1)
+ if (__lseek(fd, old_offset, SEEK_SET) == (off_t) -1)
{
if (result == -1)
__set_errno(save_errno);
@@ -134,11 +134,11 @@ static ssize_t __fake_pread_write64(int fd, void *buf,
/* Since we must not change the file pointer preserve the
* value so that we can restore it later. */
- if ((old_offset=lseek64(fd, 0, SEEK_CUR)) == (off64_t) -1)
+ if ((old_offset=__lseek64(fd, 0, SEEK_CUR)) == (off64_t) -1)
return -1;
/* Set to wanted position. */
- if (lseek64(fd, offset, SEEK_SET) == (off64_t) -1)
+ if (__lseek64(fd, offset, SEEK_SET) == (off64_t) -1)
return -1;
if (do_pwrite==1) {
@@ -151,7 +151,7 @@ static ssize_t __fake_pread_write64(int fd, void *buf,
/* Now we have to restore the position. */
save_errno = errno;
- if (lseek64 (fd, old_offset, SEEK_SET) == (off64_t) -1) {
+ if (__lseek64 (fd, old_offset, SEEK_SET) == (off64_t) -1) {
if (result == -1)
__set_errno (save_errno);
return -1;
diff --git a/libc/sysdeps/linux/powerpc/vfork.S b/libc/sysdeps/linux/powerpc/vfork.S
index 67d8aaeac..7cf5eaa16 100644
--- a/libc/sysdeps/linux/powerpc/vfork.S
+++ b/libc/sysdeps/linux/powerpc/vfork.S
@@ -1,14 +1,17 @@
+#include <features.h>
#include <sys/syscall.h>
#ifndef __NR_vfork
/* No vfork so use fork instead */
-.weak vfork ; vfork = __libc_fork
+hidden_strong_alias(__fork,__vfork)
+weak_alias(vfork,__libc_fork)
#else
.text
.global __vfork
+.hidden __vfork
.type __vfork,@function
.type __syscall_error,@function
@@ -17,7 +20,7 @@ __vfork:
sc
bnslr+
b __syscall_error
-.size __vfork,.-__vfork
-.weak vfork ; vfork = __vfork
+.size __vfork,.-__vfork
#endif
+strong_alias(__vfork,vfork)
diff --git a/libc/sysdeps/linux/powerpc/vfork.c b/libc/sysdeps/linux/powerpc/vfork.c
index 6623d8dde..39f992513 100644
--- a/libc/sysdeps/linux/powerpc/vfork.c
+++ b/libc/sysdeps/linux/powerpc/vfork.c
@@ -9,7 +9,7 @@
return (__sc_err & 0x10000000 ? errno = __sc_ret, __sc_ret = -1 : 0), \
(type) __sc_ret
-pid_t vfork(void)
+pid_t attribute_hidden __vfork(void)
{
unsigned long __sc_ret, __sc_err;
register unsigned long __sc_0 __asm__ ("r0");
@@ -46,4 +46,4 @@ pid_t vfork(void)
__syscall_return (pid_t);
}
-
+strong_alias(__vfork,vfork)
diff --git a/libc/sysdeps/linux/sh/__init_brk.c b/libc/sysdeps/linux/sh/__init_brk.c
index c9a2a3ec5..92e07c49d 100644
--- a/libc/sysdeps/linux/sh/__init_brk.c
+++ b/libc/sysdeps/linux/sh/__init_brk.c
@@ -7,7 +7,7 @@
void * __curbrk = 0;
#define __NR__brk __NR_brk
-_syscall1(void *, _brk, void *, ptr);
+attribute_hidden _syscall1(void *, _brk, void *, ptr);
int
__init_brk (void)
diff --git a/libc/sysdeps/linux/sh/bits/kernel_stat.h b/libc/sysdeps/linux/sh/bits/kernel_stat.h
index cd818464d..c841b0cee 100644
--- a/libc/sysdeps/linux/sh/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/sh/bits/kernel_stat.h
@@ -30,10 +30,10 @@ struct kernel_stat {
};
struct kernel_stat64 {
-#if defined(__BIG_ENDIAN__)
+#if (__BYTE_ORDER == __BIG_ENDIAN)
unsigned char __pad0b[6];
unsigned short st_dev;
-#elif defined(__LITTLE_ENDIAN__)
+#elif (__BYTE_ORDER == __LITTLE_ENDIAN)
unsigned short st_dev;
unsigned char __pad0b[6];
#else
@@ -48,7 +48,7 @@ struct kernel_stat64 {
unsigned long st_uid;
unsigned long st_gid;
-#if defined(__BIG_ENDIAN__)
+#if (__BYTE_ORDER == __BIG_ENDIAN)
unsigned char __pad3b[6];
unsigned short st_rdev;
#else /* Must be little */
@@ -60,7 +60,7 @@ struct kernel_stat64 {
long long st_size;
unsigned long st_blksize;
-#if defined(__BIG_ENDIAN__)
+#if (__BYTE_ORDER == __BIG_ENDIAN)
unsigned long __pad4; /* Future possible st_blocks hi bits */
unsigned long st_blocks; /* Number 512-byte blocks allocated. */
#else /* Must be little */
diff --git a/libc/sysdeps/linux/sh/brk.c b/libc/sysdeps/linux/sh/brk.c
index 2406904a3..d6063fc27 100644
--- a/libc/sysdeps/linux/sh/brk.c
+++ b/libc/sysdeps/linux/sh/brk.c
@@ -7,9 +7,9 @@
extern void * __curbrk;
extern int __init_brk (void);
-extern void *_brk(void *ptr);
+extern void *_brk(void *ptr) attribute_hidden;
-int brk(void * end_data_seg)
+int attribute_hidden __brk(void * end_data_seg)
{
if (__init_brk () == 0)
{
@@ -20,3 +20,4 @@ int brk(void * end_data_seg)
}
return -1;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/sh/clone.S b/libc/sysdeps/linux/sh/clone.S
index 98086ef09..7824d4771 100644
--- a/libc/sysdeps/linux/sh/clone.S
+++ b/libc/sysdeps/linux/sh/clone.S
@@ -118,7 +118,7 @@ __clone:
#endif
.align 2
.L1:
- .long PLTJMP(_exit)
+ .long PLTJMP(_exit_internal)
.size __clone,.-__clone;
.globl clone;
diff --git a/libc/sysdeps/linux/sh/sbrk.c b/libc/sysdeps/linux/sh/sbrk.c
index 1c9e5b172..e9faf7db0 100644
--- a/libc/sysdeps/linux/sh/sbrk.c
+++ b/libc/sysdeps/linux/sh/sbrk.c
@@ -7,10 +7,10 @@
extern void * __curbrk;
extern int __init_brk (void);
-extern void *_brk(void *ptr);
+extern void *_brk(void *ptr) attribute_hidden;
-void *
-sbrk(intptr_t increment)
+void attribute_hidden *
+__sbrk(intptr_t increment)
{
if (__init_brk () == 0)
{
@@ -23,3 +23,4 @@ sbrk(intptr_t increment)
}
return ((void *) -1);
}
+strong_alias(__sbrk,sbrk)
diff --git a/libc/sysdeps/linux/sh/vfork.S b/libc/sysdeps/linux/sh/vfork.S
index 981928e08..f3c20a9d6 100644
--- a/libc/sysdeps/linux/sh/vfork.S
+++ b/libc/sysdeps/linux/sh/vfork.S
@@ -32,9 +32,11 @@
and the process ID of the new process to the old process. */
.text
-.align 4
+.globl __vfork
+.hidden __vfork
.type __vfork,@function
-.globl __vfork;
+.align 4
+
__vfork:
mov.w .L2, r3
trapa #0x10
@@ -104,9 +106,9 @@ __vfork:
.word __NR_vfork
.L3:
.word __NR_fork
- .size __vfork, .-__vfork
-.weak vfork
- vfork = __vfork
+
+.size __vfork, .-__vfork
+strong_alias(__vfork,vfork)
#include "syscall_error.S"
diff --git a/libc/sysdeps/linux/sh64/__init_brk.c b/libc/sysdeps/linux/sh64/__init_brk.c
index c9a2a3ec5..92e07c49d 100644
--- a/libc/sysdeps/linux/sh64/__init_brk.c
+++ b/libc/sysdeps/linux/sh64/__init_brk.c
@@ -7,7 +7,7 @@
void * __curbrk = 0;
#define __NR__brk __NR_brk
-_syscall1(void *, _brk, void *, ptr);
+attribute_hidden _syscall1(void *, _brk, void *, ptr);
int
__init_brk (void)
diff --git a/libc/sysdeps/linux/sh64/brk.c b/libc/sysdeps/linux/sh64/brk.c
index 2406904a3..d6063fc27 100644
--- a/libc/sysdeps/linux/sh64/brk.c
+++ b/libc/sysdeps/linux/sh64/brk.c
@@ -7,9 +7,9 @@
extern void * __curbrk;
extern int __init_brk (void);
-extern void *_brk(void *ptr);
+extern void *_brk(void *ptr) attribute_hidden;
-int brk(void * end_data_seg)
+int attribute_hidden __brk(void * end_data_seg)
{
if (__init_brk () == 0)
{
@@ -20,3 +20,4 @@ int brk(void * end_data_seg)
}
return -1;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/sh64/sbrk.c b/libc/sysdeps/linux/sh64/sbrk.c
index 1c9e5b172..e9faf7db0 100644
--- a/libc/sysdeps/linux/sh64/sbrk.c
+++ b/libc/sysdeps/linux/sh64/sbrk.c
@@ -7,10 +7,10 @@
extern void * __curbrk;
extern int __init_brk (void);
-extern void *_brk(void *ptr);
+extern void *_brk(void *ptr) attribute_hidden;
-void *
-sbrk(intptr_t increment)
+void attribute_hidden *
+__sbrk(intptr_t increment)
{
if (__init_brk () == 0)
{
@@ -23,3 +23,4 @@ sbrk(intptr_t increment)
}
return ((void *) -1);
}
+strong_alias(__sbrk,sbrk)
diff --git a/libc/sysdeps/linux/sparc/brk.c b/libc/sysdeps/linux/sparc/brk.c
index 82d6147ca..9e178e34f 100644
--- a/libc/sysdeps/linux/sparc/brk.c
+++ b/libc/sysdeps/linux/sparc/brk.c
@@ -26,7 +26,7 @@
void *__curbrk = 0;
-int brk (void *addr)
+int attribute_hidden __brk (void *addr)
{
void *newbrk;
@@ -47,3 +47,4 @@ int brk (void *addr)
return 0;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/sparc/clone.S b/libc/sysdeps/linux/sparc/clone.S
index 7421ef672..e9e6b17dd 100644
--- a/libc/sysdeps/linux/sparc/clone.S
+++ b/libc/sysdeps/linux/sparc/clone.S
@@ -59,7 +59,7 @@ __error:
__thread_start:
call %i0
mov %i3,%o0
- call _exit,0
+ call _exit_internal,0
nop
.size __thread_start,.-__thread_start
diff --git a/libc/sysdeps/linux/sparc/fork.S b/libc/sysdeps/linux/sparc/fork.S
index c382f4b4e..dfa109dcd 100644
--- a/libc/sysdeps/linux/sparc/fork.S
+++ b/libc/sysdeps/linux/sparc/fork.S
@@ -19,14 +19,16 @@
/* Code taken from glibc2.2.2/sysdeps/unix/sysv/linux/sparc/vfork.S */
+#include <features.h>
#include <sys/syscall.h>
.text
-.global __libc_fork
-.type __libc_fork,%function
+.global __fork
+.hidden __fork
+.type __fork,%function
.align 4
-__libc_fork:
+__fork:
mov __NR_fork, %g1
ta 0x10
bcc,a 9000f
@@ -43,7 +45,6 @@ __libc_fork:
retl
and %o0, %o1, %o0
-.size __libc_fork,.-__libc_fork
-
-.weak fork
- fork = __libc_fork
+.size __fork,.-__fork
+strong_alias(__fork,fork)
+weak_alias(fork,__libc_fork)
diff --git a/libc/sysdeps/linux/sparc/vfork.S b/libc/sysdeps/linux/sparc/vfork.S
index 854b66182..9b7092c98 100644
--- a/libc/sysdeps/linux/sparc/vfork.S
+++ b/libc/sysdeps/linux/sparc/vfork.S
@@ -23,14 +23,16 @@
#ifndef __NR_vfork
/* No vfork so use fork instead */
-.weak vfork
- vfork = __libc_fork
+
+hidden_strong_alias(__fork,__vfork)
+weak_alias(vfork,__libc_fork)
#else
.text
-.global vfork
-.type vfork,%function
+.global __vfork
+.hidden __vfork
+.type __vfork,%function
.align 4
__vfork:
@@ -51,8 +53,5 @@ __vfork:
and %o0, %o1, %o0
.size __vfork,.-__vfork
-
-.weak vfork
- vfork = __vfork
-
#endif /* __NR_vfork */
+strong_alias(__vfork,vfork)
diff --git a/libc/sysdeps/linux/x86_64/brk.c b/libc/sysdeps/linux/x86_64/brk.c
index 303b5c0de..a00e2361e 100644
--- a/libc/sysdeps/linux/x86_64/brk.c
+++ b/libc/sysdeps/linux/x86_64/brk.c
@@ -24,7 +24,7 @@
/* This must be initialized data because commons can't have aliases. */
void *__curbrk = 0;
-int brk (void *addr)
+int attribute_hidden __brk (void *addr)
{
void *__unbounded newbrk;
@@ -42,3 +42,4 @@ int brk (void *addr)
return 0;
}
+strong_alias(__brk,brk)
diff --git a/libc/sysdeps/linux/x86_64/clone.S b/libc/sysdeps/linux/x86_64/clone.S
index cb614a5dc..4a7e96500 100644
--- a/libc/sysdeps/linux/x86_64/clone.S
+++ b/libc/sysdeps/linux/x86_64/clone.S
@@ -109,7 +109,7 @@ __clone:
call *%rax
/* Call exit with return value from function call. */
movq %rax, %rdi
- call _exit@PLT //HIDDEN_JUMPTARGET (_exit)
+ call _exit_internal
__error:
jmp __syscall_error
diff --git a/libc/sysdeps/linux/x86_64/vfork.S b/libc/sysdeps/linux/x86_64/vfork.S
index dde29e96a..5786058d2 100644
--- a/libc/sysdeps/linux/x86_64/vfork.S
+++ b/libc/sysdeps/linux/x86_64/vfork.S
@@ -16,6 +16,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <features.h>
#include <sys/syscall.h>
/* Clone the calling process, but without copying the whole address space.
@@ -25,15 +26,17 @@
#ifndef __NR_vfork
/* No vfork so use fork instead */
-.weak vfork
- vfork = __libc_fork
+hidden_strong_alias(__fork,__vfork)
+weak_alias(vfork,__libc_fork)
#else
.text
.global __vfork
+.hidden __vfork
.type __vfork,%function
.align 16
+
__vfork:
/* Pop the return PC value into RDI. We need a register that
@@ -58,7 +61,5 @@ __error:
.size __vfork,.-__vfork
-.weak vfork
- vfork = __vfork
-
#endif /* __NR_vfork */
+strong_alias(__vfork,vfork)
diff --git a/libc/termios/ttyname.c b/libc/termios/ttyname.c
index aa796c892..271c9a4ab 100644
--- a/libc/termios/ttyname.c
+++ b/libc/termios/ttyname.c
@@ -1,5 +1,6 @@
#define opendir __opendir
#define closedir __closedir
+#define readdir __readdir
#define isatty __isatty
#include <string.h>
@@ -50,7 +51,7 @@ int attribute_hidden __ttyname_r(int fd, char *ubuf, size_t ubuflen)
size_t len;
char buf[TTYNAME_BUFLEN];
- if (fstat(fd, &st) < 0) {
+ if (__fstat(fd, &st) < 0) {
return errno;
}
@@ -82,7 +83,7 @@ int attribute_hidden __ttyname_r(int fd, char *ubuf, size_t ubuflen)
__strcpy(s, d->d_name);
- if ((lstat(buf, &dst) == 0)
+ if ((__lstat(buf, &dst) == 0)
#if 0
/* Stupid filesystems like cramfs fail to guarantee that
* st_ino and st_dev uniquely identify a file, contrary to
diff --git a/libc/unistd/daemon.c b/libc/unistd/daemon.c
index 233dbbac4..4c18e55fa 100644
--- a/libc/unistd/daemon.c
+++ b/libc/unistd/daemon.c
@@ -26,6 +26,7 @@
#define dup2 __dup2
#define setsid __setsid
#define chdir __chdir
+#define fork __fork
#include <stdio.h>
#include <features.h>
@@ -45,7 +46,7 @@ int daemon( int nochdir, int noclose )
case 0:
break;
default:
- _exit(0);
+ _exit_internal(0);
}
if (setsid() == -1)
@@ -54,7 +55,7 @@ int daemon( int nochdir, int noclose )
/* Make certain we are not a session leader, or else we
* might reacquire a controlling terminal */
if (fork())
- _exit(0);
+ _exit_internal(0);
if (!nochdir)
chdir("/");
diff --git a/libc/unistd/fpathconf.c b/libc/unistd/fpathconf.c
index 2f6cf7214..5404e7b01 100644
--- a/libc/unistd/fpathconf.c
+++ b/libc/unistd/fpathconf.c
@@ -53,7 +53,7 @@ long int fpathconf(int fd, int name)
struct statfs fsbuf;
/* Determine the filesystem type. */
- if (fstatfs (fd, &fsbuf) < 0)
+ if (__fstatfs (fd, &fsbuf) < 0)
{
if (errno == ENOSYS)
/* not possible, return the default value. */
@@ -127,7 +127,7 @@ long int fpathconf(int fd, int name)
struct statfs buf;
int save_errno = errno;
- if (fstatfs (fd, &buf) < 0)
+ if (__fstatfs (fd, &buf) < 0)
{
if (errno == ENOSYS)
{
@@ -201,7 +201,7 @@ long int fpathconf(int fd, int name)
/* AIO is only allowed on regular files and block devices. */
struct stat st;
- if (fstat (fd, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
+ if (__fstat (fd, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
return -1;
else
return 1;
diff --git a/libc/unistd/getpass.c b/libc/unistd/getpass.c
index 8a23c99bf..834fba9d9 100644
--- a/libc/unistd/getpass.c
+++ b/libc/unistd/getpass.c
@@ -20,6 +20,9 @@
#define tcsetattr __tcsetattr
#define tcgetattr __tcgetattr
#define fileno __fileno
+#define fflush __fflush
+#define fgets __fgets
+#define fputs __fputs
#include <stdio.h>
#include <string.h>
@@ -27,6 +30,8 @@
#include <unistd.h>
#include <string.h>
+extern int __putc(int c, FILE *stream) attribute_hidden;
+
/* It is desirable to use this bit on systems that have it.
The only bit of terminal state we want to twiddle is echoing, which is
done in software; there is no need to change the state of the terminal
@@ -94,7 +99,7 @@ getpass (prompt)
buf[nread - 1] = '\0';
if (tty_changed)
/* Write the newline that was not echoed. */
- putc('\n', out);
+ __putc('\n', out);
}
}
diff --git a/libc/unistd/pathconf.c b/libc/unistd/pathconf.c
index affec4e69..579b99be0 100644
--- a/libc/unistd/pathconf.c
+++ b/libc/unistd/pathconf.c
@@ -57,7 +57,7 @@ long int pathconf(const char *path, int name)
struct statfs fsbuf;
/* Determine the filesystem type. */
- if (statfs (path, &fsbuf) < 0)
+ if (__statfs (path, &fsbuf) < 0)
{
if (errno == ENOSYS)
/* not possible, return the default value. */
@@ -131,7 +131,7 @@ long int pathconf(const char *path, int name)
struct statfs buf;
int save_errno = errno;
- if (statfs (path, &buf) < 0)
+ if (__statfs (path, &buf) < 0)
{
if (errno == ENOSYS)
{
@@ -205,7 +205,7 @@ long int pathconf(const char *path, int name)
/* AIO is only allowed on regular files and block devices. */
struct stat st;
- if (stat (path, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
+ if (__stat (path, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
return -1;
else
return 1;
diff --git a/libc/unistd/usershell.c b/libc/unistd/usershell.c
index 2e1f75d38..bc29cf247 100644
--- a/libc/unistd/usershell.c
+++ b/libc/unistd/usershell.c
@@ -32,6 +32,7 @@
#define __fsetlocking __fsetlocking_internal
#define fileno __fileno
+#define fgets_unlocked __fgets_unlocked
#define _GNU_SOURCE
#include <sys/param.h>
@@ -103,7 +104,7 @@ static char ** initshells(void)
if ((fp = fopen(_PATH_SHELLS, "r")) == NULL)
return (char **) validsh;
- if (fstat(fileno(fp), &statb) == -1) {
+ if (__fstat(fileno(fp), &statb) == -1) {
goto cleanup;
}
if ((strings = malloc((unsigned)statb.st_size + 1)) == NULL) {
diff --git a/libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h b/libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h
index c30d00964..740e793be 100644
--- a/libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h
+++ b/libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h
@@ -24,7 +24,7 @@
#include <pthread.h>
#if defined _LIBC && !defined NOT_IN_libc
-#include <linuxthreads/internals.h>
+#include <linuxthreads.old/internals.h>
#endif
/* Mutex type. */