summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/inet/addr.c29
-rw-r--r--libc/inet/ether_addr.c2
-rw-r--r--libc/inet/gai_strerror.c2
-rw-r--r--libc/inet/getaddrinfo.c131
-rw-r--r--libc/inet/getnetbyad.c3
-rw-r--r--libc/inet/getnetbynm.c5
-rw-r--r--libc/inet/getnetent.c36
-rw-r--r--libc/inet/getproto.c55
-rw-r--r--libc/inet/getservice.c57
-rw-r--r--libc/inet/hostid.c17
-rw-r--r--libc/inet/if_index.c14
-rw-r--r--libc/inet/ifaddrs.c20
-rw-r--r--libc/inet/inet_net.c86
-rw-r--r--libc/inet/netlinkaccess.h9
-rw-r--r--libc/inet/ntop.c12
-rw-r--r--libc/inet/resolv.c1476
-rw-r--r--libc/inet/rpc/Makefile.in2
-rw-r--r--libc/inet/rpc/auth_unix.c5
-rw-r--r--libc/inet/rpc/bindresvport.c2
-rw-r--r--libc/inet/rpc/clnt_generic.c8
-rw-r--r--libc/inet/rpc/clnt_perror.c4
-rw-r--r--libc/inet/rpc/clnt_simple.c6
-rw-r--r--libc/inet/rpc/clnt_udp.c2
-rw-r--r--libc/inet/rpc/clnt_unix.c4
-rw-r--r--libc/inet/rpc/create_xid.c17
-rw-r--r--libc/inet/rpc/getrpcent.c56
-rw-r--r--libc/inet/rpc/getrpcport.c2
-rw-r--r--libc/inet/rpc/pmap_rmt.c2
-rw-r--r--libc/inet/rpc/rcmd.c29
-rw-r--r--libc/inet/rpc/rexec.c19
-rw-r--r--libc/inet/rpc/rpc_cmsg.c2
-rw-r--r--libc/inet/rpc/rpc_prot.c2
-rw-r--r--libc/inet/rpc/rpc_thread.c3
-rw-r--r--libc/inet/rpc/ruserpass.c18
-rw-r--r--libc/inet/rpc/svc.c2
-rw-r--r--libc/inet/rpc/svc_authux.c2
-rw-r--r--libc/inet/rpc/svc_simple.c4
-rw-r--r--libc/inet/rpc/svc_tcp.c4
-rw-r--r--libc/inet/rpc/svc_udp.c6
-rw-r--r--libc/inet/rpc/svc_unix.c6
-rw-r--r--libc/inet/rpc/xdr.c2
-rw-r--r--libc/inet/rpc/xdr_array.c2
-rw-r--r--libc/inet/rpc/xdr_mem.c2
-rw-r--r--libc/inet/rpc/xdr_rec.c2
-rw-r--r--libc/inet/rpc/xdr_reference.c2
-rw-r--r--libc/inet/socketcalls.c11
-rw-r--r--libc/misc/Makefile.in1
-rw-r--r--libc/misc/assert/__assert.c2
-rw-r--r--libc/misc/ctype/ctype.c8
-rw-r--r--libc/misc/dirent/alphasort.c2
-rw-r--r--libc/misc/dirent/alphasort64.c2
-rw-r--r--libc/misc/dirent/closedir.c4
-rw-r--r--libc/misc/dirent/dirstream.h11
-rw-r--r--libc/misc/dirent/readdir.c4
-rw-r--r--libc/misc/dirent/readdir64.c4
-rw-r--r--libc/misc/dirent/readdir64_r.c8
-rw-r--r--libc/misc/dirent/readdir_r.c9
-rw-r--r--libc/misc/dirent/rewinddir.c4
-rw-r--r--libc/misc/dirent/scandir.c2
-rw-r--r--libc/misc/dirent/scandir64.c2
-rw-r--r--libc/misc/dirent/seekdir.c4
-rw-r--r--libc/misc/error/err.c3
-rw-r--r--libc/misc/error/error.c16
-rw-r--r--libc/misc/file/lockf.c2
-rw-r--r--libc/misc/file/lockf64.c2
-rw-r--r--libc/misc/fnmatch/fnmatch.c19
-rw-r--r--libc/misc/fnmatch/fnmatch_loop.c8
-rw-r--r--libc/misc/ftw/ftw.c33
-rw-r--r--libc/misc/glob/glob-susv3.c12
-rw-r--r--libc/misc/glob/glob.c21
-rw-r--r--libc/misc/gnu/obstack.c65
-rw-r--r--libc/misc/internals/__uClibc_main.c98
-rw-r--r--libc/misc/locale/locale.c22
-rw-r--r--libc/misc/mntent/mntent.c25
-rw-r--r--libc/misc/pthread/weaks.c9
-rw-r--r--libc/misc/regex/regex.c22
-rw-r--r--libc/misc/regex/regex_internal.h2
-rw-r--r--libc/misc/regex/regex_old.c26
-rw-r--r--libc/misc/search/_hsearch_r.c9
-rw-r--r--libc/misc/search/_lsearch.c2
-rw-r--r--libc/misc/statfs/fstatfs64.c2
-rw-r--r--libc/misc/statfs/fstatvfs.c24
-rw-r--r--libc/misc/statfs/fstatvfs64.c6
-rw-r--r--libc/misc/statfs/statfs64.c2
-rw-r--r--libc/misc/statfs/statvfs.c11
-rw-r--r--libc/misc/statfs/statvfs64.c6
-rw-r--r--libc/misc/syslog/syslog.c239
-rw-r--r--libc/misc/sysvipc/ipc.h7
-rw-r--r--libc/misc/sysvipc/msgq.c8
-rw-r--r--libc/misc/sysvipc/sem.c23
-rw-r--r--libc/misc/sysvipc/shm.c8
-rw-r--r--libc/misc/time/ftime.c3
-rw-r--r--libc/misc/time/time.c170
-rw-r--r--libc/misc/ttyent/getttyent.c20
-rw-r--r--libc/misc/utmp/utent.c126
-rw-r--r--libc/misc/utmp/wtent.c4
-rw-r--r--libc/misc/wchar/wchar.c12
-rw-r--r--libc/misc/wctype/_wctype.c4
-rw-r--r--libc/misc/wordexp/wordexp.c50
-rw-r--r--libc/pwd_grp/lckpwdf.c40
-rw-r--r--libc/pwd_grp/pwd_grp.c151
-rw-r--r--libc/signal/killpg.c4
-rw-r--r--libc/signal/sigaction.c2
-rw-r--r--libc/signal/sigaddset.c4
-rw-r--r--libc/signal/sigandset.c6
-rw-r--r--libc/signal/sigempty.c6
-rw-r--r--libc/signal/sigfillset.c2
-rw-r--r--libc/signal/sighold.c4
-rw-r--r--libc/signal/sigignore.c4
-rw-r--r--libc/signal/sigintr.c5
-rw-r--r--libc/signal/sigisempty.c4
-rw-r--r--libc/signal/sigismem.c5
-rw-r--r--libc/signal/sigorset.c6
-rw-r--r--libc/signal/sigrelse.c4
-rw-r--r--libc/signal/sigset.c5
-rw-r--r--libc/signal/sysv_signal.c5
-rw-r--r--libc/stdio/_READ.c2
-rw-r--r--libc/stdio/_WRITE.c2
-rw-r--r--libc/stdio/_fopen.c37
-rw-r--r--libc/stdio/_fpmaxtostr.c2
-rw-r--r--libc/stdio/_fwrite.c6
-rw-r--r--libc/stdio/_scanf.c59
-rw-r--r--libc/stdio/_stdio.c44
-rw-r--r--libc/stdio/_stdio.h174
-rw-r--r--libc/stdio/_store_inttype.c2
-rw-r--r--libc/stdio/_uintmaxtostr.c2
-rw-r--r--libc/stdio/_vfprintf.c157
-rw-r--r--libc/stdio/ctermid.c2
-rw-r--r--libc/stdio/fclose.c31
-rw-r--r--libc/stdio/fcloseall.c35
-rw-r--r--libc/stdio/fflush.c101
-rw-r--r--libc/stdio/flockfile.c2
-rw-r--r--libc/stdio/fmemopen.c2
-rw-r--r--libc/stdio/fputc.c6
-rw-r--r--libc/stdio/fputs.c2
-rw-r--r--libc/stdio/fread.c2
-rw-r--r--libc/stdio/freopen.c15
-rw-r--r--libc/stdio/ftello.c5
-rw-r--r--libc/stdio/ftrylockfile.c2
-rw-r--r--libc/stdio/funlockfile.c2
-rw-r--r--libc/stdio/getchar.c3
-rw-r--r--libc/stdio/gets.c6
-rw-r--r--libc/stdio/old_vfprintf.c12
-rw-r--r--libc/stdio/open_memstream.c8
-rw-r--r--libc/stdio/popen.c34
-rw-r--r--libc/stdio/setvbuf.c4
-rw-r--r--libc/stdio/tempnam.c2
-rw-r--r--libc/stdio/tmpnam.c2
-rw-r--r--libc/stdio/vasprintf.c2
-rw-r--r--libc/stdio/vdprintf.c20
-rw-r--r--libc/stdio/vsnprintf.c36
-rw-r--r--libc/stdio/vswprintf.c12
-rw-r--r--libc/stdlib/_atexit.c50
-rw-r--r--libc/stdlib/_strtod.c6
-rw-r--r--libc/stdlib/a64l.c4
-rw-r--r--libc/stdlib/abort.c18
-rw-r--r--libc/stdlib/bsd_getpt.c6
-rw-r--r--libc/stdlib/drand48-iter.c9
-rw-r--r--libc/stdlib/drand48.c3
-rw-r--r--libc/stdlib/getenv.c4
-rw-r--r--libc/stdlib/getpt.c44
-rw-r--r--libc/stdlib/l64a.c4
-rw-r--r--libc/stdlib/malloc-simple/alloc.c30
-rw-r--r--libc/stdlib/malloc-standard/calloc.c6
-rw-r--r--libc/stdlib/malloc-standard/free.c4
-rw-r--r--libc/stdlib/malloc-standard/mallinfo.c45
-rw-r--r--libc/stdlib/malloc-standard/malloc.c95
-rw-r--r--libc/stdlib/malloc-standard/malloc.h15
-rw-r--r--libc/stdlib/malloc-standard/mallopt.c4
-rw-r--r--libc/stdlib/malloc-standard/memalign.c18
-rw-r--r--libc/stdlib/malloc-standard/realloc.c36
-rw-r--r--libc/stdlib/malloc/calloc.c2
-rw-r--r--libc/stdlib/malloc/free.c2
-rw-r--r--libc/stdlib/malloc/heap.h5
-rw-r--r--libc/stdlib/malloc/heap_alloc.c2
-rw-r--r--libc/stdlib/malloc/heap_alloc_at.c2
-rw-r--r--libc/stdlib/malloc/heap_debug.c2
-rw-r--r--libc/stdlib/malloc/heap_free.c2
-rw-r--r--libc/stdlib/malloc/malloc.c2
-rw-r--r--libc/stdlib/malloc/malloc.h20
-rw-r--r--libc/stdlib/malloc/malloc_debug.c2
-rw-r--r--libc/stdlib/malloc/realloc.c2
-rw-r--r--libc/stdlib/mkdtemp.c2
-rw-r--r--libc/stdlib/ptsname.c8
-rw-r--r--libc/stdlib/random.c24
-rw-r--r--libc/stdlib/realpath.c100
-rw-r--r--libc/stdlib/seed48_r.c2
-rw-r--r--libc/stdlib/setenv.c199
-rw-r--r--libc/stdlib/stdlib.c263
-rw-r--r--libc/stdlib/system.c8
-rw-r--r--libc/stdlib/unix_grantpt.c2
-rw-r--r--libc/sysdeps/linux/common/__rt_sigtimedwait.c2
-rw-r--r--libc/sysdeps/linux/common/__rt_sigwaitinfo.c2
-rw-r--r--libc/sysdeps/linux/common/__socketcall.c2
-rw-r--r--libc/sysdeps/linux/common/__syscall_fcntl.c2
-rw-r--r--libc/sysdeps/linux/common/__syscall_fcntl64.c4
-rw-r--r--libc/sysdeps/linux/common/__syscall_rt_sigaction.c6
-rw-r--r--libc/sysdeps/linux/common/__syscall_sigaction.c2
-rw-r--r--libc/sysdeps/linux/common/access.c2
-rw-r--r--libc/sysdeps/linux/common/acct.c2
-rw-r--r--libc/sysdeps/linux/common/adjtimex.c4
-rw-r--r--libc/sysdeps/linux/common/alarm.c2
-rw-r--r--libc/sysdeps/linux/common/arch_prctl.c2
-rw-r--r--libc/sysdeps/linux/common/bdflush.c2
-rw-r--r--libc/sysdeps/linux/common/bits/confname.h43
-rw-r--r--libc/sysdeps/linux/common/bits/dlfcn.h27
-rw-r--r--libc/sysdeps/linux/common/bits/errno.h35
-rw-r--r--libc/sysdeps/linux/common/bits/huge_val.h66
-rw-r--r--libc/sysdeps/linux/common/bits/local_lim.h28
-rw-r--r--libc/sysdeps/linux/common/bits/mathcalls.h80
-rw-r--r--libc/sysdeps/linux/common/bits/mathdef.h6
-rw-r--r--libc/sysdeps/linux/common/bits/posix1_lim.h1
-rw-r--r--libc/sysdeps/linux/common/bits/posix_opt.h194
-rw-r--r--libc/sysdeps/linux/common/bits/resource.h33
-rw-r--r--libc/sysdeps/linux/common/bits/shm.h1
-rw-r--r--libc/sysdeps/linux/common/bits/siginfo.h26
-rw-r--r--libc/sysdeps/linux/common/bits/signum.h4
-rw-r--r--libc/sysdeps/linux/common/bits/sigthread.h26
-rw-r--r--libc/sysdeps/linux/common/bits/socket.h17
-rw-r--r--libc/sysdeps/linux/common/bits/stat.h49
-rw-r--r--libc/sysdeps/linux/common/bits/syscalls.h4
-rw-r--r--libc/sysdeps/linux/common/bits/termios.h1
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_errno.h9
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_local_lim.h7
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_mutex.h58
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_stdio.h111
-rw-r--r--libc/sysdeps/linux/common/bits/uio.h2
-rw-r--r--libc/sysdeps/linux/common/bits/waitstatus.h18
-rw-r--r--libc/sysdeps/linux/common/capget.c2
-rw-r--r--libc/sysdeps/linux/common/capset.c2
-rw-r--r--libc/sysdeps/linux/common/chdir.c2
-rw-r--r--libc/sysdeps/linux/common/chmod.c2
-rw-r--r--libc/sysdeps/linux/common/chown.c17
-rw-r--r--libc/sysdeps/linux/common/chroot.c2
-rw-r--r--libc/sysdeps/linux/common/clock_getres.c15
-rw-r--r--libc/sysdeps/linux/common/clock_gettime.c2
-rw-r--r--libc/sysdeps/linux/common/clock_settime.c2
-rw-r--r--libc/sysdeps/linux/common/close.c2
-rw-r--r--libc/sysdeps/linux/common/creat64.c9
-rw-r--r--libc/sysdeps/linux/common/delete_module.c2
-rw-r--r--libc/sysdeps/linux/common/dup.c2
-rw-r--r--libc/sysdeps/linux/common/dup2.c2
-rw-r--r--libc/sysdeps/linux/common/epoll.c2
-rw-r--r--libc/sysdeps/linux/common/execve.c2
-rw-r--r--libc/sysdeps/linux/common/fchdir.c2
-rw-r--r--libc/sysdeps/linux/common/fchmod.c2
-rw-r--r--libc/sysdeps/linux/common/fchown.c16
-rw-r--r--libc/sysdeps/linux/common/fdatasync.c2
-rw-r--r--libc/sysdeps/linux/common/flock.c2
-rw-r--r--libc/sysdeps/linux/common/fork.c16
-rw-r--r--libc/sysdeps/linux/common/fpu_control.h2
-rw-r--r--libc/sysdeps/linux/common/fstat.c2
-rw-r--r--libc/sysdeps/linux/common/fstat64.c2
-rw-r--r--libc/sysdeps/linux/common/fstatfs.c28
-rw-r--r--libc/sysdeps/linux/common/fsync.c2
-rw-r--r--libc/sysdeps/linux/common/ftruncate.c2
-rw-r--r--libc/sysdeps/linux/common/get_kernel_syms.c2
-rw-r--r--libc/sysdeps/linux/common/getcwd.c10
-rw-r--r--libc/sysdeps/linux/common/getdents.c44
-rw-r--r--libc/sysdeps/linux/common/getdents64.c3
-rw-r--r--libc/sysdeps/linux/common/getdirname.c2
-rw-r--r--libc/sysdeps/linux/common/getdtablesize.c3
-rw-r--r--libc/sysdeps/linux/common/getegid.c2
-rw-r--r--libc/sysdeps/linux/common/geteuid.c2
-rw-r--r--libc/sysdeps/linux/common/getgid.c8
-rw-r--r--libc/sysdeps/linux/common/getgroups.c5
-rw-r--r--libc/sysdeps/linux/common/getitimer.c2
-rw-r--r--libc/sysdeps/linux/common/getpgid.c5
-rw-r--r--libc/sysdeps/linux/common/getpgrp.c3
-rw-r--r--libc/sysdeps/linux/common/getpid.c2
-rw-r--r--libc/sysdeps/linux/common/getppid.c2
-rw-r--r--libc/sysdeps/linux/common/getpriority.c2
-rw-r--r--libc/sysdeps/linux/common/getresgid.c2
-rw-r--r--libc/sysdeps/linux/common/getresuid.c2
-rw-r--r--libc/sysdeps/linux/common/getrlimit.c4
-rw-r--r--libc/sysdeps/linux/common/getrusage.c2
-rw-r--r--libc/sysdeps/linux/common/getsid.c2
-rw-r--r--libc/sysdeps/linux/common/gettimeofday.c2
-rw-r--r--libc/sysdeps/linux/common/getuid.c10
-rw-r--r--libc/sysdeps/linux/common/init_module.c2
-rw-r--r--libc/sysdeps/linux/common/inotify.c2
-rw-r--r--libc/sysdeps/linux/common/ioctl.c2
-rw-r--r--libc/sysdeps/linux/common/ioperm.c2
-rw-r--r--libc/sysdeps/linux/common/iopl.c2
-rw-r--r--libc/sysdeps/linux/common/kill.c2
-rw-r--r--libc/sysdeps/linux/common/klogctl.c2
-rw-r--r--libc/sysdeps/linux/common/lchown.c17
-rw-r--r--libc/sysdeps/linux/common/link.c2
-rw-r--r--libc/sysdeps/linux/common/llseek.c4
-rw-r--r--libc/sysdeps/linux/common/lseek.c11
-rw-r--r--libc/sysdeps/linux/common/lstat.c2
-rw-r--r--libc/sysdeps/linux/common/lstat64.c2
-rw-r--r--libc/sysdeps/linux/common/madvise.c2
-rw-r--r--libc/sysdeps/linux/common/mincore.c6
-rw-r--r--libc/sysdeps/linux/common/mkdir.c2
-rw-r--r--libc/sysdeps/linux/common/mknod.c2
-rw-r--r--libc/sysdeps/linux/common/mlock.c2
-rw-r--r--libc/sysdeps/linux/common/mlockall.c2
-rw-r--r--libc/sysdeps/linux/common/mmap.c31
-rw-r--r--libc/sysdeps/linux/common/mmap64.c8
-rw-r--r--libc/sysdeps/linux/common/modify_ldt.c2
-rw-r--r--libc/sysdeps/linux/common/mount.c2
-rw-r--r--libc/sysdeps/linux/common/mprotect.c5
-rw-r--r--libc/sysdeps/linux/common/mremap.c7
-rw-r--r--libc/sysdeps/linux/common/msync.c2
-rw-r--r--libc/sysdeps/linux/common/munlock.c2
-rw-r--r--libc/sysdeps/linux/common/munlockall.c6
-rw-r--r--libc/sysdeps/linux/common/munmap.c2
-rw-r--r--libc/sysdeps/linux/common/nanosleep.c2
-rw-r--r--libc/sysdeps/linux/common/nice.c2
-rw-r--r--libc/sysdeps/linux/common/open.c28
-rw-r--r--libc/sysdeps/linux/common/open64.c15
-rw-r--r--libc/sysdeps/linux/common/pause.c3
-rw-r--r--libc/sysdeps/linux/common/personality.c2
-rw-r--r--libc/sysdeps/linux/common/pipe.c2
-rw-r--r--libc/sysdeps/linux/common/pivot_root.c2
-rw-r--r--libc/sysdeps/linux/common/poll.c6
-rw-r--r--libc/sysdeps/linux/common/posix_fadvise.c22
-rw-r--r--libc/sysdeps/linux/common/posix_fadvise64.c21
-rw-r--r--libc/sysdeps/linux/common/prctl.c5
-rw-r--r--libc/sysdeps/linux/common/pread_write.c77
-rw-r--r--libc/sysdeps/linux/common/ptrace.c7
-rw-r--r--libc/sysdeps/linux/common/query_module.c2
-rw-r--r--libc/sysdeps/linux/common/quotactl.c5
-rw-r--r--libc/sysdeps/linux/common/read.c2
-rw-r--r--libc/sysdeps/linux/common/readlink.c7
-rw-r--r--libc/sysdeps/linux/common/readv.c4
-rw-r--r--libc/sysdeps/linux/common/reboot.c2
-rw-r--r--libc/sysdeps/linux/common/rename.c2
-rw-r--r--libc/sysdeps/linux/common/rmdir.c2
-rw-r--r--libc/sysdeps/linux/common/sbrk.c7
-rw-r--r--libc/sysdeps/linux/common/sched_get_priority_max.c2
-rw-r--r--libc/sysdeps/linux/common/sched_get_priority_min.c2
-rw-r--r--libc/sysdeps/linux/common/sched_getparam.c3
-rw-r--r--libc/sysdeps/linux/common/sched_getscheduler.c3
-rw-r--r--libc/sysdeps/linux/common/sched_rr_get_interval.c3
-rw-r--r--libc/sysdeps/linux/common/sched_setparam.c3
-rw-r--r--libc/sysdeps/linux/common/sched_setscheduler.c3
-rw-r--r--libc/sysdeps/linux/common/sched_yield.c2
-rw-r--r--libc/sysdeps/linux/common/select.c2
-rw-r--r--libc/sysdeps/linux/common/sendfile.c6
-rw-r--r--libc/sysdeps/linux/common/setdomainname.c2
-rw-r--r--libc/sysdeps/linux/common/seteuid.c5
-rw-r--r--libc/sysdeps/linux/common/setfsgid.c16
-rw-r--r--libc/sysdeps/linux/common/setfsuid.c16
-rw-r--r--libc/sysdeps/linux/common/setgid.c16
-rw-r--r--libc/sysdeps/linux/common/setgroups.c5
-rw-r--r--libc/sysdeps/linux/common/sethostname.c2
-rw-r--r--libc/sysdeps/linux/common/setitimer.c2
-rw-r--r--libc/sysdeps/linux/common/setpgid.c5
-rw-r--r--libc/sysdeps/linux/common/setpriority.c2
-rw-r--r--libc/sysdeps/linux/common/setregid.c17
-rw-r--r--libc/sysdeps/linux/common/setresgid.c12
-rw-r--r--libc/sysdeps/linux/common/setresuid.c14
-rw-r--r--libc/sysdeps/linux/common/setreuid.c17
-rw-r--r--libc/sysdeps/linux/common/setrlimit.c2
-rw-r--r--libc/sysdeps/linux/common/setsid.c2
-rw-r--r--libc/sysdeps/linux/common/settimeofday.c2
-rw-r--r--libc/sysdeps/linux/common/setuid.c16
-rw-r--r--libc/sysdeps/linux/common/sigaltstack.c6
-rw-r--r--libc/sysdeps/linux/common/sigpending.c5
-rw-r--r--libc/sysdeps/linux/common/sigprocmask.c14
-rw-r--r--libc/sysdeps/linux/common/sigqueue.c4
-rw-r--r--libc/sysdeps/linux/common/sigsuspend.c8
-rw-r--r--libc/sysdeps/linux/common/ssp.c4
-rw-r--r--libc/sysdeps/linux/common/stat.c2
-rw-r--r--libc/sysdeps/linux/common/stat64.c2
-rw-r--r--libc/sysdeps/linux/common/statfs.c14
-rw-r--r--libc/sysdeps/linux/common/stime.c2
-rw-r--r--libc/sysdeps/linux/common/swapoff.c7
-rw-r--r--libc/sysdeps/linux/common/swapon.c7
-rw-r--r--libc/sysdeps/linux/common/symlink.c4
-rw-r--r--libc/sysdeps/linux/common/sync.c7
-rw-r--r--libc/sysdeps/linux/common/syscalls.h1
-rw-r--r--libc/sysdeps/linux/common/sysctl.c17
-rw-r--r--libc/sysdeps/linux/common/sysfs.c5
-rw-r--r--libc/sysdeps/linux/common/sysinfo.c2
-rw-r--r--libc/sysdeps/linux/common/time.c4
-rw-r--r--libc/sysdeps/linux/common/times.c2
-rw-r--r--libc/sysdeps/linux/common/truncate.c2
-rw-r--r--libc/sysdeps/linux/common/truncate64.c2
-rw-r--r--libc/sysdeps/linux/common/ulimit.c2
-rw-r--r--libc/sysdeps/linux/common/umask.c2
-rw-r--r--libc/sysdeps/linux/common/umount.c5
-rw-r--r--libc/sysdeps/linux/common/umount2.c7
-rw-r--r--libc/sysdeps/linux/common/uname.c2
-rw-r--r--libc/sysdeps/linux/common/unlink.c2
-rw-r--r--libc/sysdeps/linux/common/uselib.c5
-rw-r--r--libc/sysdeps/linux/common/ustat.c2
-rw-r--r--libc/sysdeps/linux/common/utime.c9
-rw-r--r--libc/sysdeps/linux/common/utimes.c3
-rw-r--r--libc/sysdeps/linux/common/vfork.c4
-rw-r--r--libc/sysdeps/linux/common/vhangup.c2
-rw-r--r--libc/sysdeps/linux/common/wait3.c5
-rw-r--r--libc/sysdeps/linux/common/wait4.c4
-rw-r--r--libc/sysdeps/linux/common/write.c2
-rw-r--r--libc/sysdeps/linux/common/writev.c7
-rw-r--r--libc/sysdeps/linux/common/xattr.c2
-rw-r--r--libc/sysdeps/linux/common/xstatconv.c11
-rw-r--r--libc/sysdeps/linux/mips/clone.S1
-rw-r--r--libc/sysdeps/linux/mips/sys/asm.h15
-rw-r--r--libc/sysdeps/linux/sh/bits/fcntl.h40
-rw-r--r--libc/sysdeps/linux/sh/bits/syscalls.h2
-rw-r--r--libc/sysdeps/linux/sh/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/sh/crti.S1
-rw-r--r--libc/sysdeps/linux/sh/pread_write.c24
-rw-r--r--libc/sysdeps/linux/sh/sys/procfs.h4
-rw-r--r--libc/sysdeps/linux/sh/sys/ucontext.h4
-rw-r--r--libc/sysdeps/linux/sh/vfork.S5
-rw-r--r--libc/termios/tcgetattr.c6
-rw-r--r--libc/termios/tcgetsid.c5
-rw-r--r--libc/termios/tcsetattr.c2
-rw-r--r--libc/termios/ttyname.c4
-rw-r--r--libc/unistd/confstr.c2
-rw-r--r--libc/unistd/exec.c111
-rw-r--r--libc/unistd/fpathconf.c21
-rw-r--r--libc/unistd/getlogin.c4
-rw-r--r--libc/unistd/getopt-susv3.c2
-rw-r--r--libc/unistd/getopt.c8
-rw-r--r--libc/unistd/getopt_int.h34
-rw-r--r--libc/unistd/getpass.c6
-rw-r--r--libc/unistd/getsubopt-susv3.c6
-rw-r--r--libc/unistd/getsubopt.c6
-rw-r--r--libc/unistd/pathconf.c5
-rw-r--r--libc/unistd/sleep.c55
-rw-r--r--libc/unistd/sysconf.c9
-rw-r--r--libc/unistd/usershell.c11
-rw-r--r--libc/unistd/usleep.c14
429 files changed, 4387 insertions, 3427 deletions
diff --git a/libc/inet/addr.c b/libc/inet/addr.c
index ba2a022d6..2a0bb84a8 100644
--- a/libc/inet/addr.c
+++ b/libc/inet/addr.c
@@ -45,7 +45,7 @@
*/
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
libc_hidden_proto(inet_aton)
@@ -55,6 +55,10 @@ int inet_aton(const char *cp, struct in_addr *addrptr)
int value;
int part;
+ if (cp == NULL) {
+ return 0;
+ }
+
addr = 0;
for (part = 1; part <= 4; part++) {
@@ -75,7 +79,7 @@ int inet_aton(const char *cp, struct in_addr *addrptr)
} else {
char c = *cp++;
if (c != '\0' && !isspace(c))
- return 0;
+ return 0;
}
addr <<= 8;
@@ -118,7 +122,6 @@ libc_hidden_def(inet_addr)
#define INET_NTOA_MAX_LEN 16 /* max 12 digits + 3 '.'s + 1 nul */
-extern char *inet_ntoa_r(struct in_addr in, char buf[INET_NTOA_MAX_LEN]);
libc_hidden_proto(inet_ntoa_r)
char *inet_ntoa_r(struct in_addr in, char buf[INET_NTOA_MAX_LEN])
{
@@ -128,7 +131,7 @@ char *inet_ntoa_r(struct in_addr in, char buf[INET_NTOA_MAX_LEN])
q = 0;
p = buf + INET_NTOA_MAX_LEN - 1; /* cannot use sizeof(buf) here */
- for (i=0 ; i < 4 ; i++ ) {
+ for (i = 0; i < 4; i++ ) {
p = _int10tostr(p, addr & 0xff) - 1;
addr >>= 8;
if (q) {
@@ -145,7 +148,7 @@ libc_hidden_proto(inet_ntoa)
char *inet_ntoa(struct in_addr in)
{
static char buf[INET_NTOA_MAX_LEN];
- return(inet_ntoa_r(in, buf));
+ return inet_ntoa_r(in, buf);
}
libc_hidden_def(inet_ntoa)
#endif
@@ -153,7 +156,7 @@ libc_hidden_def(inet_ntoa)
#ifdef L_inet_makeaddr
/* for some reason it does not remove the jump relocation */
-libc_hidden_proto(memmove)
+/* Experimentally off - libc_hidden_proto(memmove) */
/*
* Formulate an Internet address from network + host. Used in
@@ -173,7 +176,7 @@ struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host)
else
addr = net | host;
addr = htonl(addr);
- return (*(struct in_addr *)&addr);
+ return *(struct in_addr *)&addr;
}
libc_hidden_def(inet_makeaddr)
#endif
@@ -189,11 +192,11 @@ in_addr_t inet_lnaof(struct in_addr in)
in_addr_t i = ntohl(in.s_addr);
if (IN_CLASSA(i))
- return ((i)&IN_CLASSA_HOST);
+ return (i & IN_CLASSA_HOST);
else if (IN_CLASSB(i))
- return ((i)&IN_CLASSB_HOST);
+ return (i & IN_CLASSB_HOST);
else
- return ((i)&IN_CLASSC_HOST);
+ return (i & IN_CLASSC_HOST);
}
#endif
@@ -210,11 +213,11 @@ inet_netof(struct in_addr in)
in_addr_t i = ntohl(in.s_addr);
if (IN_CLASSA(i))
- return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
+ return ((i & IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
else if (IN_CLASSB(i))
- return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
+ return ((i & IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
else
- return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
+ return ((i & IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
}
libc_hidden_def(inet_netof)
#endif
diff --git a/libc/inet/ether_addr.c b/libc/inet/ether_addr.c
index e896e707d..bcea9ba46 100644
--- a/libc/inet/ether_addr.c
+++ b/libc/inet/ether_addr.c
@@ -37,7 +37,7 @@ libc_hidden_proto(sprintf)
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
libc_hidden_proto(__ctype_tolower_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
libc_hidden_proto(__ctype_tolower)
#endif
diff --git a/libc/inet/gai_strerror.c b/libc/inet/gai_strerror.c
index c1c7b767f..61688bad9 100644
--- a/libc/inet/gai_strerror.c
+++ b/libc/inet/gai_strerror.c
@@ -24,7 +24,7 @@
#define N_(x) x
#define _(x) x
-static struct
+static const struct
{
int code;
const char *msg;
diff --git a/libc/inet/getaddrinfo.c b/libc/inet/getaddrinfo.c
index d0d172643..d81888f9a 100644
--- a/libc/inet/getaddrinfo.c
+++ b/libc/inet/getaddrinfo.c
@@ -1,6 +1,8 @@
/*
* Copyright 1996 by Craig Metz
* Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ * Portions from the GNU C library,
+ * Copyright (C) 2003, 2006 Free Software Foundation, Inc.
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
@@ -55,8 +57,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
-#include <resolv.h>
#include <stdlib.h>
+#include <resolv.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
@@ -66,14 +68,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sys/un.h>
#include <sys/utsname.h>
#include <net/if.h>
+#include "ifaddrs.h"
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
/* libc_hidden_proto(strcmp) */
/* libc_hidden_proto(stpcpy) */
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(socket)
libc_hidden_proto(close)
libc_hidden_proto(getservbyname_r)
@@ -156,19 +159,85 @@ static const struct addrinfo default_hints =
{ 0, PF_UNSPEC, 0, 0, 0, NULL, NULL, NULL };
#endif
+#define SEEN_IPV4 1
+#define SEEN_IPV6 2
+
+static unsigned __check_pf (void)
+{
+ unsigned seen = 0;
+#if defined __UCLIBC_SUPPORT_AI_ADDRCONFIG__
+ {
+ /* Get the interface list via getifaddrs. */
+ struct ifaddrs *ifa = NULL;
+ struct ifaddrs *runp;
+ if (getifaddrs (&ifa) != 0)
+ {
+ /* We cannot determine what interfaces are available. Be
+ optimistic. */
+#if defined __UCLIBC_HAS_IPV4__
+ seen |= SEEN_IPV4;
+#endif /* __UCLIBC_HAS_IPV4__ */
+#if defined __UCLIBC_HAS_IPV6__
+ seen |= SEEN_IPV6;
+#endif /* __UCLIBC_HAS_IPV6__ */
+ return seen;
+ }
+
+ for (runp = ifa; runp != NULL; runp = runp->ifa_next)
+#if defined __UCLIBC_HAS_IPV4__
+ if (runp->ifa_addr->sa_family == PF_INET)
+ seen |= SEEN_IPV4;
+#endif /* __UCLIBC_HAS_IPV4__ */
+#if defined __UCLIBC_HAS_IPV4__ && defined __UCLIBC_HAS_IPV6__
+ else /* can't be both at once */
+#endif /* __UCLIBC_HAS_IPV4__ && defined __UCLIBC_HAS_IPV6__ */
+#if defined __UCLIBC_HAS_IPV6__
+ if (runp->ifa_addr->sa_family == PF_INET6)
+ seen |= SEEN_IPV6;
+#endif /* __UCLIBC_HAS_IPV6__ */
+
+ (void) freeifaddrs (ifa);
+ }
+#else
+ /* AI_ADDRCONFIG is disabled, assume both ipv4 and ipv6 available. */
+#if defined __UCLIBC_HAS_IPV4__
+ seen |= SEEN_IPV4;
+#endif /* __UCLIBC_HAS_IPV4__ */
+#if defined __UCLIBC_HAS_IPV6__
+ seen |= SEEN_IPV6;
+#endif /* __UCLIBC_HAS_IPV6__ */
+
+#endif /* __UCLIBC_SUPPORT_AI_ADDRCONFIG__ */
+ return seen;
+}
static int addrconfig (sa_family_t af)
{
int s;
int ret;
int saved_errno = errno;
- s = socket(af, SOCK_DGRAM, 0);
- if (s < 0)
- ret = (errno == EMFILE) ? 1 : 0;
+ unsigned seen;
+
+ seen = __check_pf();
+#if defined __UCLIBC_HAS_IPV4__
+ if (af == AF_INET)
+ ret = seen & SEEN_IPV4;
else
+#endif
+#if defined __UCLIBC_HAS_IPV6__
+ if (af == AF_INET6)
+ ret = seen & SEEN_IPV6;
+ else
+#endif
{
- close(s);
- ret = 1;
+ s = socket(af, SOCK_DGRAM, 0);
+ ret = 1; /* Assume PF_UNIX. */
+ if (s < 0) {
+ if (errno != EMFILE)
+ ret = 0;
+ }
+ else
+ close(s);
}
__set_errno (saved_errno);
return ret;
@@ -373,6 +442,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
int rc;
int v4mapped = (req->ai_family == PF_UNSPEC || req->ai_family == PF_INET6) &&
(req->ai_flags & AI_V4MAPPED);
+ unsigned seen = __check_pf();
if (req->ai_protocol || req->ai_socktype)
{
@@ -501,7 +571,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
return -EAI_FAMILY;
}
-#if __UCLIBC_HAS_IPV6__
+#if defined __UCLIBC_HAS_IPV6__
if (at->family == AF_UNSPEC)
{
char *namebuf = strdupa (name);
@@ -558,16 +628,18 @@ gaih_inet (const char *name, const struct gaih_service *service,
* IPv6 addresses.
*/
-#if __UCLIBC_HAS_IPV6__
+#if defined __UCLIBC_HAS_IPV6__
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
- gethosts (AF_INET6, struct in6_addr);
+ if (!(req->ai_flags & AI_ADDRCONFIG) || (seen & SEEN_IPV6))
+ gethosts (AF_INET6, struct in6_addr);
#endif
no_inet6_data = no_data;
if (req->ai_family == AF_INET ||
(!v4mapped && req->ai_family == AF_UNSPEC) ||
(v4mapped && (no_inet6_data != 0 || (req->ai_flags & AI_ALL))))
- gethosts (AF_INET, struct in_addr);
+ if (!(req->ai_flags & AI_ADDRCONFIG) || (seen & SEEN_IPV4))
+ gethosts (AF_INET, struct in_addr);
if (no_data != 0 && no_inet6_data != 0)
{
@@ -598,7 +670,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
memset (at->next, '\0', sizeof (struct gaih_addrtuple));
}
-#if __UCLIBC_HAS_IPV6__
+#if defined __UCLIBC_HAS_IPV6__
if (req->ai_family == 0 || req->ai_family == AF_INET6)
{
at->family = AF_INET6;
@@ -680,21 +752,32 @@ gaih_inet (const char *name, const struct gaih_service *service,
else
namelen = 0;
-#if __UCLIBC_HAS_IPV6__
+#if defined __UCLIBC_HAS_IPV6__
if (at2->family == AF_INET6 || v4mapped)
{
family = AF_INET6;
socklen = sizeof (struct sockaddr_in6);
}
+#endif
+#if defined __UCLIBC_HAS_IPV4__ && defined __UCLIBC_HAS_IPV6__
else
#endif
+#if defined __UCLIBC_HAS_IPV4__
{
family = AF_INET;
socklen = sizeof (struct sockaddr_in);
}
-
+#endif
for (st2 = st; st2 != NULL; st2 = st2->next)
{
+ if (req->ai_flags & AI_ADDRCONFIG) {
+ if (family == AF_INET && !(seen & SEEN_IPV4))
+ break;
+#if defined __UCLIBC_HAS_IPV6__
+ else if (family == AF_INET6 && !(seen & SEEN_IPV6))
+ break;
+#endif
+ }
*pai = malloc (sizeof (struct addrinfo) + socklen + namelen);
if (*pai == NULL)
return -EAI_MEMORY;
@@ -710,7 +793,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
#endif /* SALEN */
(*pai)->ai_addr->sa_family = family;
-#if __UCLIBC_HAS_IPV6__
+#if defined __UCLIBC_HAS_IPV6__
if (family == AF_INET6)
{
struct sockaddr_in6 *sin6p =
@@ -733,8 +816,11 @@ gaih_inet (const char *name, const struct gaih_service *service,
sin6p->sin6_port = st2->port;
sin6p->sin6_scope_id = at2->scopeid;
}
+#endif
+#if defined __UCLIBC_HAS_IPV4__ && defined __UCLIBC_HAS_IPV6__
else
#endif
+#if defined __UCLIBC_HAS_IPV4__
{
struct sockaddr_in *sinp =
(struct sockaddr_in *) (*pai)->ai_addr;
@@ -744,7 +830,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
sinp->sin_port = st2->port;
memset (sinp->sin_zero, '\0', sizeof (sinp->sin_zero));
}
-
+#endif
if (c)
{
(*pai)->ai_canonname = ((void *) (*pai) +
@@ -766,7 +852,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
static struct gaih gaih[] =
{
-#if __UCLIBC_HAS_IPV6__
+#if defined __UCLIBC_HAS_IPV6__
{ PF_INET6, gaih_inet },
#endif
{ PF_INET, gaih_inet },
@@ -853,7 +939,10 @@ getaddrinfo (const char *name, const char *service,
if (hints->ai_family == g->family || hints->ai_family == AF_UNSPEC)
{
if ((hints->ai_flags & AI_ADDRCONFIG) && !addrconfig(g->family))
+ {
+ ++g;
continue;
+ }
j++;
if (pg == NULL || pg->gaih != g->gaih)
{
diff --git a/libc/inet/getnetbyad.c b/libc/inet/getnetbyad.c
index e353f245b..c916a18cf 100644
--- a/libc/inet/getnetbyad.c
+++ b/libc/inet/getnetbyad.c
@@ -18,12 +18,13 @@
#define __FORCE_GLIBC
#include <features.h>
#include <netdb.h>
+#include <unistd.h>
libc_hidden_proto(setnetent)
libc_hidden_proto(getnetent)
libc_hidden_proto(endnetent)
-extern int _net_stayopen attribute_hidden;
+extern smallint _net_stayopen attribute_hidden;
struct netent *getnetbyaddr (uint32_t net, int type)
{
diff --git a/libc/inet/getnetbynm.c b/libc/inet/getnetbynm.c
index 97d5cb85f..9f3655121 100644
--- a/libc/inet/getnetbynm.c
+++ b/libc/inet/getnetbynm.c
@@ -19,13 +19,14 @@
#include <features.h>
#include <netdb.h>
#include <string.h>
+#include <unistd.h>
-libc_hidden_proto(strcmp)
+/* Experimentally off - libc_hidden_proto(strcmp) */
libc_hidden_proto(setnetent)
libc_hidden_proto(getnetent)
libc_hidden_proto(endnetent)
-extern int _net_stayopen attribute_hidden;
+extern smallint _net_stayopen attribute_hidden;
struct netent *
getnetbyname(const char *name)
diff --git a/libc/inet/getnetent.c b/libc/inet/getnetent.c
index d3fdb988a..863266d48 100644
--- a/libc/inet/getnetent.c
+++ b/libc/inet/getnetent.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <netdb.h>
#include <arpa/inet.h>
+#include <unistd.h>
libc_hidden_proto(fopen)
libc_hidden_proto(fclose)
@@ -29,12 +30,8 @@ libc_hidden_proto(rewind)
libc_hidden_proto(fgets)
libc_hidden_proto(abort)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
@@ -45,18 +42,18 @@ static char *line = NULL;
static struct netent net;
static char *net_aliases[MAXALIASES];
-int _net_stayopen attribute_hidden;
+smallint _net_stayopen attribute_hidden;
libc_hidden_proto(setnetent)
void setnetent(int f)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (netf == NULL)
netf = fopen(NETDB, "r" );
else
rewind(netf);
- _net_stayopen |= f;
- UNLOCK;
+ if (f) _net_stayopen = 1;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return;
}
libc_hidden_def(setnetent)
@@ -64,13 +61,13 @@ libc_hidden_def(setnetent)
libc_hidden_proto(endnetent)
void endnetent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (netf) {
fclose(netf);
netf = NULL;
}
_net_stayopen = 0;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_def(endnetent)
@@ -92,11 +89,11 @@ struct netent *getnetent(void)
{
char *p;
register char *cp, **q;
+ struct netent *rv = NULL;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL) {
- UNLOCK;
- return (NULL);
+ goto DONE;
}
again:
@@ -108,8 +105,7 @@ again:
p = fgets(line, BUFSIZ, netf);
if (p == NULL) {
- UNLOCK;
- return (NULL);
+ goto DONE;
}
if (*p == '#')
goto again;
@@ -144,7 +140,9 @@ again:
*cp++ = '\0';
}
*q = NULL;
- UNLOCK;
- return (&net);
+ rv = &net;
+DONE:
+ __UCLIBC_MUTEX_UNLOCK(mylock);
+ return rv;
}
libc_hidden_def(getnetent)
diff --git a/libc/inet/getproto.c b/libc/inet/getproto.c
index a54532ede..1e3e843f5 100644
--- a/libc/inet/getproto.c
+++ b/libc/inet/getproto.c
@@ -60,22 +60,19 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
libc_hidden_proto(fopen)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strpbrk)
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strpbrk) */
libc_hidden_proto(atoi)
libc_hidden_proto(rewind)
libc_hidden_proto(fgets)
libc_hidden_proto(fclose)
libc_hidden_proto(abort)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
@@ -85,7 +82,7 @@ static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
static FILE *protof = NULL;
static struct protoent proto;
static char *static_aliases = NULL;
-static int proto_stayopen;
+static smallint proto_stayopen;
static void __initbuf(void)
{
@@ -99,26 +96,26 @@ static void __initbuf(void)
libc_hidden_proto(setprotoent)
void setprotoent(int f)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (protof == NULL)
protof = fopen(_PATH_PROTOCOLS, "r" );
else
rewind(protof);
- proto_stayopen |= f;
- UNLOCK;
+ if (f) proto_stayopen = 1;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_def(setprotoent)
libc_hidden_proto(endprotoent)
void endprotoent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (protof) {
fclose(protof);
protof = NULL;
}
proto_stayopen = 0;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_def(endprotoent)
@@ -131,6 +128,7 @@ int getprotoent_r(struct protoent *result_buf,
register char *cp, **q;
char **proto_aliases;
char *line;
+ int rv;
*result = NULL;
@@ -138,28 +136,27 @@ int getprotoent_r(struct protoent *result_buf,
errno=ERANGE;
return errno;
}
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
proto_aliases=(char **)buf;
buf+=sizeof(*proto_aliases)*MAXALIASES;
buflen-=sizeof(*proto_aliases)*MAXALIASES;
if (buflen < BUFSIZ+1) {
- UNLOCK;
- errno=ERANGE;
- return errno;
+ errno=rv=ERANGE;
+ goto DONE;
}
line=buf;
buf+=BUFSIZ+1;
buflen-=BUFSIZ+1;
if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) {
- UNLOCK;
- return errno;
+ rv=errno;
+ goto DONE;
}
again:
if ((p = fgets(line, BUFSIZ, protof)) == NULL) {
- UNLOCK;
- return TRY_AGAIN;
+ rv=TRY_AGAIN;
+ goto DONE;
}
if (*p == '#')
@@ -196,8 +193,10 @@ again:
}
*q = NULL;
*result=result_buf;
- UNLOCK;
- return 0;
+ rv = 0;
+DONE:
+ __UCLIBC_MUTEX_UNLOCK(mylock);
+ return rv;
}
libc_hidden_def(getprotoent_r)
@@ -220,7 +219,7 @@ int getprotobyname_r(const char *name,
register char **cp;
int ret;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
setprotoent(proto_stayopen);
while (!(ret=getprotoent_r(result_buf, buf, buflen, result))) {
if (strcmp(result_buf->p_name, name) == 0)
@@ -232,7 +231,7 @@ int getprotobyname_r(const char *name,
found:
if (!proto_stayopen)
endprotoent();
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return *result?0:ret;
}
libc_hidden_def(getprotobyname_r)
@@ -256,14 +255,14 @@ int getprotobynumber_r (int proto_num,
{
int ret;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
setprotoent(proto_stayopen);
while (!(ret=getprotoent_r(result_buf, buf, buflen, result)))
if (result_buf->p_proto == proto_num)
break;
if (!proto_stayopen)
endprotoent();
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return *result?0:ret;
}
libc_hidden_def(getprotobynumber_r)
diff --git a/libc/inet/getservice.c b/libc/inet/getservice.c
index 7f4939bbd..bb1d6d2e4 100644
--- a/libc/inet/getservice.c
+++ b/libc/inet/getservice.c
@@ -62,9 +62,10 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
+#include <unistd.h>
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strpbrk)
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strpbrk) */
libc_hidden_proto(fopen)
libc_hidden_proto(fclose)
libc_hidden_proto(atoi)
@@ -72,12 +73,8 @@ libc_hidden_proto(rewind)
libc_hidden_proto(fgets)
libc_hidden_proto(abort)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
@@ -88,7 +85,7 @@ static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
static FILE *servf = NULL;
static struct servent serv;
static char *servbuf = NULL;
-static int serv_stayopen;
+static smallint serv_stayopen;
static void __initbuf(void)
{
@@ -102,26 +99,26 @@ static void __initbuf(void)
libc_hidden_proto(setservent)
void setservent(int f)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (servf == NULL)
servf = fopen(_PATH_SERVICES, "r" );
else
rewind(servf);
- serv_stayopen |= f;
- UNLOCK;
+ if (f) serv_stayopen = 1;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_def(setservent)
libc_hidden_proto(endservent)
void endservent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (servf) {
fclose(servf);
servf = NULL;
}
serv_stayopen = 0;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_def(endservent)
@@ -134,6 +131,7 @@ int getservent_r(struct servent * result_buf,
register char *cp, **q;
char **serv_aliases;
char *line;
+ int rv;
*result=NULL;
@@ -141,30 +139,27 @@ int getservent_r(struct servent * result_buf,
errno=ERANGE;
return errno;
}
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
serv_aliases=(char **)buf;
buf+=sizeof(*serv_aliases)*MAXALIASES;
buflen-=sizeof(*serv_aliases)*MAXALIASES;
if (buflen < BUFSIZ+1) {
- UNLOCK;
- errno=ERANGE;
- return errno;
+ errno=rv=ERANGE;
+ goto DONE;
}
line=buf;
buf+=BUFSIZ+1;
buflen-=BUFSIZ+1;
if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) {
- UNLOCK;
- errno=EIO;
- return errno;
+ errno=rv=EIO;
+ goto DONE;
}
again:
if ((p = fgets(line, BUFSIZ, servf)) == NULL) {
- UNLOCK;
- errno=EIO;
- return errno;
+ errno=rv=EIO;
+ goto DONE;
}
if (*p == '#')
goto again;
@@ -202,8 +197,10 @@ again:
}
*q = NULL;
*result=result_buf;
- UNLOCK;
- return 0;
+ rv = 0;
+DONE:
+ __UCLIBC_MUTEX_UNLOCK(mylock);
+ return rv;
}
libc_hidden_def(getservent_r)
@@ -224,7 +221,7 @@ int getservbyname_r(const char *name, const char *proto,
register char **cp;
int ret;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
setservent(serv_stayopen);
while (!(ret=getservent_r(result_buf, buf, buflen, result))) {
if (strcmp(name, result_buf->s_name) == 0)
@@ -239,7 +236,7 @@ gotname:
}
if (!serv_stayopen)
endservent();
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return *result?0:ret;
}
libc_hidden_def(getservbyname_r)
@@ -261,7 +258,7 @@ int getservbyport_r(int port, const char *proto,
{
int ret;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
setservent(serv_stayopen);
while (!(ret=getservent_r(result_buf, buf, buflen, result))) {
if (result_buf->s_port != port)
@@ -271,7 +268,7 @@ int getservbyport_r(int port, const char *proto,
}
if (!serv_stayopen)
endservent();
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return *result?0:ret;
}
libc_hidden_def(getservbyport_r)
diff --git a/libc/inet/hostid.c b/libc/inet/hostid.c
index bd9f5b52b..33668a2fe 100644
--- a/libc/inet/hostid.c
+++ b/libc/inet/hostid.c
@@ -18,7 +18,7 @@
#include <not-cancel.h>
#endif
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(open)
libc_hidden_proto(close)
libc_hidden_proto(read)
@@ -57,7 +57,7 @@ long int gethostid(void)
char host[MAXHOSTNAMELEN + 1];
int fd, id;
- /* If hostid was already set the we can return that value.
+ /* If hostid was already set then we can return that value.
* It is not an error if we cannot read this file. It is not even an
* error if we cannot read all the bytes, we just carry on trying...
*/
@@ -92,8 +92,19 @@ long int gethostid(void)
if (gethostname(host,MAXHOSTNAMELEN)>=0 && *host) {
struct hostent *hp;
struct in_addr in;
+ struct hostent ghbn_h;
+ char ghbn_buf[sizeof(struct in_addr) +
+ sizeof(struct in_addr *)*2 +
+ sizeof(char *)*((2 + 5/*MAX_ALIASES*/ +
+ 1)/*ALIAS_DIM*/) +
+ 256/*namebuffer*/ + 32/* margin */];
+ int ghbn_errno;
- if ((hp = gethostbyname(host)) == (struct hostent *)NULL)
+ /* replace gethostbyname() with gethostbyname_r() - ron@zing.net */
+ /*if ((hp = gethostbyname(host)) == (struct hostent *)NULL)*/
+ gethostbyname_r(host, &ghbn_h, ghbn_buf, sizeof(ghbn_buf), &hp, &ghbn_errno);
+
+ if (hp == (struct hostent *)NULL)
/* This is not a error if we get here, as all it means is that
* this host is not on a network and/or they have not
diff --git a/libc/inet/if_index.c b/libc/inet/if_index.c
index b89051c79..05b7b2669 100644
--- a/libc/inet/if_index.c
+++ b/libc/inet/if_index.c
@@ -38,12 +38,12 @@
#include "netlinkaccess.h"
-libc_hidden_proto(strncpy)
-libc_hidden_proto(strdup)
+/* Experimentally off - libc_hidden_proto(strncpy) */
+/* Experimentally off - libc_hidden_proto(strdup) */
libc_hidden_proto(ioctl)
libc_hidden_proto(close)
#if __ASSUME_NETLINK_SUPPORT
-libc_hidden_proto(strndup)
+/* Experimentally off - libc_hidden_proto(strndup) */
#endif
extern int __opensock(void) attribute_hidden;
@@ -314,14 +314,6 @@ if_nameindex (void)
#endif
libc_hidden_def(if_nameindex)
-#if 0
-struct if_nameindex *
-if_nameindex (void)
-{
- return (if_nameindex_netlink () != NULL ? : if_nameindex_ioctl ());
-}
-#endif
-
char *
if_indextoname (unsigned int ifindex, char *ifname)
{
diff --git a/libc/inet/ifaddrs.c b/libc/inet/ifaddrs.c
index b9f3cbd0e..a96b19a54 100644
--- a/libc/inet/ifaddrs.c
+++ b/libc/inet/ifaddrs.c
@@ -22,7 +22,7 @@
#include <alloca.h>
#include <assert.h>
#include <errno.h>
-/*#include <ifaddrs.h>*/
+#include "ifaddrs.h"
#include <net/if.h>
#include <netinet/in.h>
#include <netpacket/packet.h>
@@ -41,12 +41,12 @@
libc_hidden_proto(socket)
libc_hidden_proto(close)
-libc_hidden_proto(time)
+/* Experimentally off - libc_hidden_proto(time) */
libc_hidden_proto(sendto)
libc_hidden_proto(recvmsg)
libc_hidden_proto(bind)
-libc_hidden_proto(memset)
-libc_hidden_proto(mempcpy)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(mempcpy) */
libc_hidden_proto(getsockname)
libc_hidden_proto(fclose)
libc_hidden_proto(abort)
@@ -57,7 +57,7 @@ libc_hidden_proto(abort)
#if __ASSUME_NETLINK_SUPPORT
-#if 0 /* unused code */
+#ifdef __UCLIBC_SUPPORT_AI_ADDRCONFIG__
/* struct to hold the data for one ifaddrs entry, so we can allocate
everything at once. */
struct ifaddrs_storage
@@ -74,7 +74,7 @@ struct ifaddrs_storage
} addr, netmask, broadaddr;
char name[IF_NAMESIZE + 1];
};
-#endif /* unused code */
+#endif /* __UCLIBC_SUPPORT_AI_ADDRCONFIG__ */
void
@@ -324,7 +324,7 @@ __netlink_open (struct netlink_handle *h)
}
-#if 0 /* unused code */
+#ifdef __UCLIBC_SUPPORT_AI_ADDRCONFIG__
/* We know the number of RTM_NEWLINK entries, so we reserve the first
# of entries for this type. All RTM_NEWADDR entries have an index
pointer to the RTM_NEWLINK entry. To find the entry, create
@@ -562,7 +562,7 @@ getifaddrs (struct ifaddrs **ifap)
if ((rta_payload + 1) <= sizeof (ifas[ifa_index].name))
{
ifas[ifa_index].ifa.ifa_name = ifas[ifa_index].name;
- *(char *) __mempcpy (ifas[ifa_index].name, rta_data,
+ *(char *) mempcpy (ifas[ifa_index].name, rta_data,
rta_payload) = '\0';
}
break;
@@ -761,7 +761,7 @@ getifaddrs (struct ifaddrs **ifap)
if (rta_payload + 1 <= sizeof (ifas[ifa_index].name))
{
ifas[ifa_index].ifa.ifa_name = ifas[ifa_index].name;
- *(char *) __mempcpy (ifas[ifa_index].name, rta_data,
+ *(char *) mempcpy (ifas[ifa_index].name, rta_data,
rta_payload) = '\0';
}
else
@@ -872,6 +872,6 @@ freeifaddrs (struct ifaddrs *ifa)
}
#endif
-#endif /* unused code */
+#endif /* __UCLIBC_SUPPORT_AI_ADDRCONFIG__ */
#endif /* __ASSUME_NETLINK_SUPPORT */
diff --git a/libc/inet/inet_net.c b/libc/inet/inet_net.c
index 71ed8dc88..e46c9a561 100644
--- a/libc/inet/inet_net.c
+++ b/libc/inet/inet_net.c
@@ -37,9 +37,10 @@
#include <ctype.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
@@ -50,55 +51,56 @@ libc_hidden_proto(__ctype_b)
*/
libc_hidden_proto(inet_network)
in_addr_t
-inet_network(cp)
- register const char *cp;
+inet_network(const char *cp)
{
- register u_int32_t val, base, n, i;
- register char c;
- u_int32_t parts[4], *pp = parts;
- int digit;
+ u_char c;
+ int got_data;
+ u_int base, dots;
+ in_addr_t res, val;
-again:
- val = 0; base = 10; digit = 0;
- if (*cp == '0')
- digit = 1, base = 8, cp++;
- if (*cp == 'x' || *cp == 'X')
- base = 16, cp++;
- while ((c = *cp) != 0) {
- if (isdigit(c)) {
- if (base == 8 && (c == '8' || c == '9'))
- return (INADDR_NONE);
- val = (val * base) + (c - '0');
- cp++;
- digit = 1;
- continue;
- }
- if (base == 16 && isxdigit(c)) {
- val = (val << 4) + (tolower (c) + 10 - 'a');
+ res = 0;
+ dots = 0;
+ again:
+ val = 0;
+ got_data = 0;
+ if (*cp == '0') {
+ cp++;
+ if (*cp == 'x' || *cp == 'X') {
cp++;
- digit = 1;
- continue;
+ base = 16;
+ } else {
+ base = 8;
+ got_data = 1;
}
- break;
+ } else
+ base = 10;
+ while ((c = *cp) != '\0') {
+ if (isdigit(c)) {
+ if (base == 8 && c > '7')
+ return (INADDR_NONE);
+ val = val * base + c - '0';
+ } else if (base == 16 && isxdigit(c))
+ val = (val << 4) + 10 - (islower(c) ? 'a' : 'A');
+ else
+ break;
+ if (val > 0xff)
+ return (INADDR_NONE);
+ cp++;
+ got_data = 1;
}
- if (!digit)
- return (INADDR_NONE);
- if (pp >= parts + 4 || val > 0xff)
+ if (!got_data)
return (INADDR_NONE);
- if (*cp == '.') {
- *pp++ = val, cp++;
+ if (dots != 0)
+ res <<= 8;
+ res |= val;
+ if (c == '.') {
+ if (++dots == 4)
+ return (INADDR_NONE);
+ cp++;
goto again;
}
- if (*cp && !isspace(*cp))
+ if (c != '\0')
return (INADDR_NONE);
- if (pp >= parts + 4 || val > 0xff)
- return (INADDR_NONE);
- *pp++ = val;
- n = pp - parts;
- for (val = 0, i = 0; i < n; i++) {
- val <<= 8;
- val |= parts[i] & 0xff;
- }
- return (val);
+ return (res);
}
libc_hidden_def(inet_network)
diff --git a/libc/inet/netlinkaccess.h b/libc/inet/netlinkaccess.h
index a47d8901c..acadcb544 100644
--- a/libc/inet/netlinkaccess.h
+++ b/libc/inet/netlinkaccess.h
@@ -21,6 +21,7 @@
#include <features.h>
#include <stdint.h>
+#include <unistd.h>
#include <sys/types.h>
#define _LINUX_TYPES_H
@@ -33,11 +34,13 @@ typedef int32_t __s32;
#include <linux/netlink.h>
/* Should prob be a configure option or something */
+#ifndef __ASSUME_NETLINK_SUPPORT
#ifdef __UCLIBC_USE_NETLINK__
# define __ASSUME_NETLINK_SUPPORT 1
#else
# define __ASSUME_NETLINK_SUPPORT 0
#endif
+#endif
struct netlink_res
@@ -59,13 +62,13 @@ struct netlink_handle
};
-#if 0 /* unused code */
+#ifdef __UCLIBC_SUPPORT_AI_ADDRCONFIG__
#if __ASSUME_NETLINK_SUPPORT == 0
-extern int __no_netlink_support attribute_hidden;
+extern smallint __no_netlink_support attribute_hidden;
#else
# define __no_netlink_support 0
#endif
-#endif /* unused code */
+#endif /* __UCLIBC_SUPPORT_AI_ADDRCONFIG__ */
extern int __netlink_open (struct netlink_handle *h) attribute_hidden;
diff --git a/libc/inet/ntop.c b/libc/inet/ntop.c
index 88ff6a150..c1f3fc83c 100644
--- a/libc/inet/ntop.c
+++ b/libc/inet/ntop.c
@@ -30,11 +30,11 @@
#include <string.h>
#include <ctype.h>
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(sprintf)
libc_hidden_proto(tolower)
@@ -126,6 +126,8 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
words[i / 2] = (src[i] << 8) | src[i + 1];
best.base = -1;
cur.base = -1;
+ best.len = best.len; /* shutting up compiler warning */
+ cur.len = cur.len; /* shutting up compiler warning */
for (i = 0; i < 8; i++) {
if (words[i] == 0) {
if (cur.base == -1)
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index 6d6d18a96..6ddbd5c31 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -7,7 +7,7 @@
* 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.
-*/
+ */
/*
* Portions Copyright (c) 1985, 1993
@@ -139,6 +139,7 @@
#include <stdio.h>
#include <signal.h>
#include <errno.h>
+#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
@@ -149,36 +150,48 @@
#include <resolv.h>
#include <netdb.h>
#include <ctype.h>
+#include <stdbool.h>
#include <arpa/nameser.h>
#include <sys/utsname.h>
#include <sys/un.h>
+#include <bits/uClibc_mutex.h>
+
+/* poll() is not supported in kernel <= 2.0, therefore if __NR_poll is
+ * not available, we assume an old Linux kernel is in use and we will
+ * use select() instead. */
+#include <sys/syscall.h>
+#ifndef __NR_poll
+# define USE_SELECT
+#endif
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
-libc_hidden_proto(memmove)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strdup)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strncat)
-libc_hidden_proto(strncpy)
+__UCLIBC_MUTEX_EXTERN(__resolv_lock);
+
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(memmove) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strdup) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strncat) */
+/* Experimentally off - libc_hidden_proto(strncpy) */
/* libc_hidden_proto(strnlen) */
-libc_hidden_proto(strstr)
-libc_hidden_proto(strcasecmp)
+/* Experimentally off - libc_hidden_proto(strstr) */
+/* Experimentally off - libc_hidden_proto(strcasecmp) */
libc_hidden_proto(socket)
libc_hidden_proto(close)
libc_hidden_proto(fopen)
libc_hidden_proto(fclose)
libc_hidden_proto(random)
libc_hidden_proto(getservbyport)
-libc_hidden_proto(getdomainname)
libc_hidden_proto(uname)
libc_hidden_proto(inet_addr)
libc_hidden_proto(inet_aton)
libc_hidden_proto(inet_pton)
libc_hidden_proto(inet_ntop)
libc_hidden_proto(connect)
+libc_hidden_proto(poll)
libc_hidden_proto(select)
libc_hidden_proto(recv)
libc_hidden_proto(send)
@@ -202,9 +215,12 @@ libc_hidden_proto(fprintf)
libc_hidden_proto(__h_errno_location)
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
+int __libc_getdomainname(char *name, size_t len);
+libc_hidden_proto(__libc_getdomainname)
+
#define MAX_RECURSE 5
#define REPLY_TIMEOUT 10
@@ -215,7 +231,7 @@ libc_hidden_proto(__ctype_b)
#define MAX_ALIASES 5
/* 1:ip + 1:full + MAX_ALIASES:aliases + 1:NULL */
-#define ALIAS_DIM (2 + MAX_ALIASES + 1)
+#define ALIAS_DIM (2 + MAX_ALIASES + 1)
#undef DEBUG
/* #define DEBUG */
@@ -226,6 +242,14 @@ libc_hidden_proto(__ctype_b)
#define DPRINTF(X,args...)
#endif /* DEBUG */
+/* Make sure the incoming char * buffer is aligned enough to handle our random
+ * structures. This define is the same as we use for malloc alignment (which
+ * has same requirements). The offset is the number of bytes we need to adjust
+ * in order to attain desired alignment.
+ */
+#define ALIGN_ATTR __alignof__(double __attribute_aligned__ (sizeof(size_t)))
+#define ALIGN_BUFFER_OFFSET(buf) ((ALIGN_ATTR - ((size_t)buf % ALIGN_ATTR)) % ALIGN_ATTR)
+
/* Global stuff (stuff needing to be locked to be thread safe)... */
extern int __nameservers attribute_hidden;
@@ -234,14 +258,6 @@ extern int __searchdomains attribute_hidden;
extern char * __searchdomain[MAX_SEARCH] attribute_hidden;
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-extern pthread_mutex_t __resolv_lock;
-#endif
-#define BIGLOCK __pthread_mutex_lock(&__resolv_lock)
-#define BIGUNLOCK __pthread_mutex_unlock(&__resolv_lock)
-
-
/* Structs */
struct resolv_header {
@@ -265,7 +281,7 @@ struct resolv_answer {
int aclass;
int ttl;
int rdlength;
- unsigned char * rdata;
+ const unsigned char * rdata;
int rdoffset;
char* buf;
size_t buflen;
@@ -273,9 +289,9 @@ struct resolv_answer {
};
enum etc_hosts_action {
- GET_HOSTS_BYNAME = 0,
- GETHOSTENT,
- GET_HOSTS_BYADDR,
+ GET_HOSTS_BYNAME = 0,
+ GETHOSTENT,
+ GET_HOSTS_BYADDR,
};
/* function prototypes */
@@ -289,7 +305,7 @@ extern int __get_hosts_byaddr_r(const char * addr, int len, int type,
char * buf, size_t buflen,
struct hostent ** result,
int * h_errnop) attribute_hidden;
-extern void __open_etc_hosts(FILE **fp) attribute_hidden;
+extern FILE * __open_etc_hosts(void) attribute_hidden;
extern int __read_etc_hosts_r(FILE *fp, const char * name, int type,
enum etc_hosts_action action,
struct hostent * result_buf,
@@ -300,21 +316,21 @@ extern int __dns_lookup(const char * name, int type, int nscount,
char ** nsip, unsigned char ** outpacket, struct resolv_answer * a) attribute_hidden;
extern int __encode_dotted(const char * dotted, unsigned char * dest, int maxlen) attribute_hidden;
-extern int __decode_dotted(const unsigned char * message, int offset,
+extern int __decode_dotted(const unsigned char * const message, int offset,
char * dest, int maxlen) attribute_hidden;
-extern int __length_dotted(const unsigned char * message, int offset) attribute_hidden;
+extern int __length_dotted(const unsigned char * const message, int offset) attribute_hidden;
extern int __encode_header(struct resolv_header * h, unsigned char * dest, int maxlen) attribute_hidden;
extern int __decode_header(unsigned char * data, struct resolv_header * h) attribute_hidden;
-extern int __encode_question(struct resolv_question * q,
+extern int __encode_question(const struct resolv_question * const q,
unsigned char * dest, int maxlen) attribute_hidden;
-extern int __decode_question(unsigned char * message, int offset,
+extern int __decode_question(const unsigned char * const message, int offset,
struct resolv_question * q) attribute_hidden;
extern int __encode_answer(struct resolv_answer * a,
unsigned char * dest, int maxlen) attribute_hidden;
-extern int __decode_answer(unsigned char * message, int offset,
+extern int __decode_answer(const unsigned char * message, int offset,
struct resolv_answer * a) attribute_hidden;
-extern int __length_question(unsigned char * message, int offset) attribute_hidden;
-extern int __open_nameservers(void) attribute_hidden;
+extern int __length_question(const unsigned char * const message, int offset) attribute_hidden;
+extern void __open_nameservers(void) attribute_hidden;
extern void __close_nameservers(void) attribute_hidden;
extern int __dn_expand(const u_char *, const u_char *, const u_char *,
char *, int);
@@ -373,12 +389,16 @@ int attribute_hidden __decode_header(unsigned char *data, struct resolv_header *
int attribute_hidden __encode_dotted(const char *dotted, unsigned char *dest, int maxlen)
{
- int used = 0;
+ unsigned used = 0;
while (dotted && *dotted) {
char *c = strchr(dotted, '.');
int l = c ? c - dotted : strlen(dotted);
+ /* two consecutive dots are not valid */
+ if (l == 0)
+ return -1;
+
if (l >= (maxlen - used - 1))
return -1;
@@ -405,20 +425,20 @@ int attribute_hidden __encode_dotted(const char *dotted, unsigned char *dest, in
/* Decode a dotted string from nameserver transport-level encoding.
This routine understands compressed data. */
-int attribute_hidden __decode_dotted(const unsigned char *data, int offset,
+int attribute_hidden __decode_dotted(const unsigned char * const data, int offset,
char *dest, int maxlen)
{
int l;
- int measure = 1;
- int total = 0;
- int used = 0;
+ bool measure = 1;
+ unsigned total = 0;
+ unsigned used = 0;
if (!data)
return -1;
- while ((l=data[offset++])) {
+ while ((l = data[offset++])) {
if (measure)
- total++;
+ total++;
if ((l & 0xc0) == (0xc0)) {
if (measure)
total++;
@@ -444,9 +464,8 @@ int attribute_hidden __decode_dotted(const unsigned char *data, int offset,
}
/* The null byte must be counted too */
- if (measure) {
- total++;
- }
+ if (measure)
+ total++;
DPRINTF("Total decode len = %d\n", total);
@@ -455,7 +474,7 @@ int attribute_hidden __decode_dotted(const unsigned char *data, int offset,
#endif
#ifdef L_lengthd
-int attribute_hidden __length_dotted(const unsigned char *data, int offset)
+int attribute_hidden __length_dotted(const unsigned char * const data, int offset)
{
int orig_offset = offset;
int l;
@@ -478,7 +497,7 @@ int attribute_hidden __length_dotted(const unsigned char *data, int offset)
#endif
#ifdef L_encodeq
-int attribute_hidden __encode_question(struct resolv_question *q,
+int attribute_hidden __encode_question(const struct resolv_question * const q,
unsigned char *dest, int maxlen)
{
int i;
@@ -503,7 +522,7 @@ int attribute_hidden __encode_question(struct resolv_question *q,
#endif
#ifdef L_decodeq
-int attribute_hidden __decode_question(unsigned char *message, int offset,
+int attribute_hidden __decode_question(const unsigned char * const message, int offset,
struct resolv_question *q)
{
char temp[256];
@@ -515,7 +534,7 @@ int attribute_hidden __decode_question(unsigned char *message, int offset,
offset += i;
- q->dotted = strdup(temp);
+ q->dotted = strdup(temp); /* TODO: what if this fails? */
q->qtype = (message[offset + 0] << 8) | message[offset + 1];
q->qclass = (message[offset + 2] << 8) | message[offset + 3];
@@ -524,7 +543,7 @@ int attribute_hidden __decode_question(unsigned char *message, int offset,
#endif
#ifdef L_lengthq
-int attribute_hidden __length_question(unsigned char *message, int offset)
+int attribute_hidden __length_question(const unsigned char * const message, int offset)
{
int i;
@@ -548,7 +567,7 @@ int attribute_hidden __encode_answer(struct resolv_answer *a, unsigned char *des
dest += i;
maxlen -= i;
- if (maxlen < (RRFIXEDSZ+a->rdlength))
+ if (maxlen < (RRFIXEDSZ + a->rdlength))
return -1;
*dest++ = (a->atype & 0xff00) >> 8;
@@ -568,7 +587,7 @@ int attribute_hidden __encode_answer(struct resolv_answer *a, unsigned char *des
#endif
#ifdef L_decodea
-int attribute_hidden __decode_answer(unsigned char *message, int offset,
+int attribute_hidden __decode_answer(const unsigned char *message, int offset,
struct resolv_answer *a)
{
char temp[256];
@@ -580,7 +599,7 @@ int attribute_hidden __decode_answer(unsigned char *message, int offset,
message += offset + i;
- a->dotted = strdup(temp);
+ a->dotted = strdup(temp); /* TODO: what if this fails? */
a->atype = (message[0] << 8) | message[1];
message += 2;
a->aclass = (message[0] << 8) | message[1];
@@ -607,14 +626,14 @@ int __encode_packet(struct resolv_header *h,
struct resolv_answer **ar,
unsigned char *dest, int maxlen) attribute_hidden;
int __encode_packet(struct resolv_header *h,
- struct resolv_question **q,
- struct resolv_answer **an,
- struct resolv_answer **ns,
- struct resolv_answer **ar,
- unsigned char *dest, int maxlen)
+ struct resolv_question **q,
+ struct resolv_answer **an,
+ struct resolv_answer **ns,
+ struct resolv_answer **ar,
+ unsigned char *dest, int maxlen)
{
int i, total = 0;
- int j;
+ unsigned j;
i = __encode_header(h, dest, maxlen);
if (i < 0)
@@ -673,7 +692,7 @@ int __decode_packet(unsigned char *data, struct resolv_header *h)
#ifdef L_formquery
int __form_query(int id, const char *name, int type, unsigned char *packet, int maxlen);
int __form_query(int id, const char *name, int type, unsigned char *packet,
- int maxlen)
+ int maxlen)
{
struct resolv_header h;
struct resolv_question q;
@@ -699,56 +718,60 @@ int __form_query(int id, const char *name, int type, unsigned char *packet,
}
#endif
-#if defined(L_dnslookup) || defined(L_gethostent)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
-#endif
-
#ifdef L_dnslookup
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
/* Just for the record, having to lock __dns_lookup() just for these two globals
* is pretty lame. I think these two variables can probably be de-global-ized,
* which should eliminate the need for doing locking here... Needs a closer
* look anyways. */
-static int ns=0, id=1;
+static int static_ns = 0;
+/* uint16: minimizing rw data size, even if code grows a tiny bit.
+ * rw data costs more. */
+static uint16_t static_id = 1;
int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char **nsip,
unsigned char **outpacket, struct resolv_answer *a)
{
int i, j, len, fd, pos, rc;
+#ifdef USE_SELECT
struct timeval tv;
fd_set fds;
+#else
+ struct pollfd fds;
+#endif
struct resolv_header h;
struct resolv_question q;
struct resolv_answer ma;
- int first_answer = 1;
- int retries = 0;
+ bool first_answer = 1;
+ unsigned retries = 0;
unsigned char * packet = malloc(PACKETSZ);
char *dns, *lookup = malloc(MAXDNAME);
- int variant = -1;
- struct sockaddr_in sa;
+ int variant = -1; /* search domain to append, -1 - none */
int local_ns = -1, local_id = -1;
+ bool ends_with_dot;
#ifdef __UCLIBC_HAS_IPV6__
- int v6;
+ bool v6;
struct sockaddr_in6 sa6;
#endif
+#ifdef __UCLIBC_HAS_IPV4__
+ struct sockaddr_in sa;
+#endif
fd = -1;
- if (!packet || !lookup || !nscount)
- goto fail;
+ if (!packet || !lookup || !nscount || !name[0])
+ goto fail;
DPRINTF("Looking up type %d answer for '%s'\n", type, name);
+ ends_with_dot = (name[strlen(name) - 1] == '.');
+
/* Mess with globals while under lock */
- LOCK;
- local_ns = ns % nscount;
- local_id = id;
- UNLOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
+ local_ns = static_ns % nscount;
+ local_id = static_id;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
while (retries < MAX_RETRIES) {
if (fd != -1)
@@ -761,8 +784,6 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char
++local_id;
local_id &= 0xffff;
h.id = local_id;
- dns = nsip[local_ns];
-
h.qdcount = 1;
h.rd = 1;
@@ -772,15 +793,24 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char
if (i < 0)
goto fail;
- strncpy(lookup,name,MAXDNAME);
+ strncpy(lookup, name, MAXDNAME);
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ /* nsip is really __nameserver[] which is a global that
+ needs to hold __resolv_lock before access!! */
+ dns = nsip[local_ns];
+/* TODO: all future accesses to 'dns' are guarded by __resolv_lock too.
+ * Why? We already fetched nsip[local_ns] here,
+ * future changes to nsip[] by other threads cannot affect us.
+ * We can use 'dns' without locking. If I'm wrong,
+ * please explain in comments why locking is needed. */
if (variant >= 0) {
- BIGLOCK;
- if (variant < __searchdomains) {
- strncat(lookup,".", MAXDNAME);
- strncat(lookup,__searchdomain[variant], MAXDNAME);
- }
- BIGUNLOCK;
- }
+ if (variant < __searchdomains) {
+ strncat(lookup, ".", MAXDNAME);
+ strncat(lookup, __searchdomain[variant], MAXDNAME);
+ }
+ }
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+
DPRINTF("lookup name: %s\n", lookup);
q.dotted = (char *)lookup;
q.qtype = type;
@@ -796,39 +826,49 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char
retries+1, NAMESERVER_PORT, dns);
#ifdef __UCLIBC_HAS_IPV6__
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ /* 'dns' is really __nameserver[] which is a global that
+ needs to hold __resolv_lock before access!! */
v6 = inet_pton(AF_INET6, dns, &sa6.sin6_addr) > 0;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
fd = socket(v6 ? AF_INET6 : AF_INET, SOCK_DGRAM, IPPROTO_UDP);
#else
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
#endif
if (fd < 0) {
- retries++;
- continue;
+ retries++;
+ continue;
}
/* Connect to the UDP socket so that asyncronous errors are returned */
#ifdef __UCLIBC_HAS_IPV6__
if (v6) {
- sa6.sin6_family = AF_INET6;
- sa6.sin6_port = htons(NAMESERVER_PORT);
- /* sa6.sin6_addr is already here */
- rc = connect(fd, (struct sockaddr *) &sa6, sizeof(sa6));
+ sa6.sin6_family = AF_INET6;
+ sa6.sin6_port = htons(NAMESERVER_PORT);
+ /* sa6.sin6_addr is already here */
+ rc = connect(fd, (struct sockaddr *) &sa6, sizeof(sa6));
} else {
#endif
- sa.sin_family = AF_INET;
- sa.sin_port = htons(NAMESERVER_PORT);
- sa.sin_addr.s_addr = inet_addr(dns);
- rc = connect(fd, (struct sockaddr *) &sa, sizeof(sa));
+#ifdef __UCLIBC_HAS_IPV4__
+ sa.sin_family = AF_INET;
+ sa.sin_port = htons(NAMESERVER_PORT);
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ /* 'dns' is really __nameserver[] which is a global that
+ needs to hold __resolv_lock before access!! */
+ sa.sin_addr.s_addr = inet_addr(dns);
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ rc = connect(fd, (struct sockaddr *) &sa, sizeof(sa));
+#endif
#ifdef __UCLIBC_HAS_IPV6__
}
#endif
if (rc < 0) {
- if (errno == ENETUNREACH) {
- /* routing error, presume not transient */
- goto tryall;
- } else
+ if (errno == ENETUNREACH) {
+ /* routing error, presume not transient */
+ goto tryall;
+ }
/* retry */
- retries++;
+ retries++;
continue;
}
@@ -837,19 +877,31 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char
send(fd, packet, len, 0);
+#ifdef USE_SELECT
FD_ZERO(&fds);
FD_SET(fd, &fds);
tv.tv_sec = REPLY_TIMEOUT;
tv.tv_usec = 0;
if (select(fd + 1, &fds, NULL, NULL, &tv) <= 0) {
- DPRINTF("Timeout\n");
+ DPRINTF("Timeout\n");
/* timed out, so retry send and receive,
* to next nameserver on queue */
goto tryall;
}
+#else
+ fds.fd = fd;
+ fds.events = POLLIN;
+ if (poll(&fds, 1, REPLY_TIMEOUT * 1000) <= 0) {
+ DPRINTF("Timeout\n");
- len = recv(fd, packet, 512, 0);
+ /* timed out, so retry send and receive,
+ * to next nameserver on queue */
+ goto tryall;
+ }
+#endif
+
+ len = recv(fd, packet, PACKETSZ, 0);
if (len < HFIXEDSZ) {
/* too short ! */
goto again;
@@ -864,7 +916,6 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char
goto again;
}
-
DPRINTF("Got response %s\n", "(i think)!");
DPRINTF("qrcount=%d,ancount=%d,nscount=%d,arcount=%d\n",
h.qdcount, h.ancount, h.nscount, h.arcount);
@@ -889,55 +940,43 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char
DPRINTF("Decoding answer at pos %d\n", pos);
first_answer = 1;
- for (j=0;j<h.ancount;j++,pos += i)
- {
- i = __decode_answer(packet, pos, &ma);
+ for (j = 0; j < h.ancount; j++, pos += i) {
+ i = __decode_answer(packet, pos, &ma);
- if (i<0) {
- DPRINTF("failed decode %d\n", i);
- goto again;
- }
-
- if ( first_answer )
- {
- ma.buf = a->buf;
- ma.buflen = a->buflen;
- ma.add_count = a->add_count;
- memcpy(a, &ma, sizeof(ma));
- if (a->atype != T_SIG && (0 == a->buf || (type != T_A && type != T_AAAA)))
- {
- break;
- }
- if (a->atype != type)
- {
- free(a->dotted);
- continue;
- }
- a->add_count = h.ancount - j - 1;
- if ((a->rdlength + sizeof(struct in_addr*)) * a->add_count > a->buflen)
- {
- break;
- }
- a->add_count = 0;
- first_answer = 0;
- }
- else
- {
- free(ma.dotted);
- if (ma.atype != type)
- {
- continue;
+ if (i < 0) {
+ DPRINTF("failed decode %d\n", i);
+ goto again;
}
- if (a->rdlength != ma.rdlength)
- {
- free(a->dotted);
- DPRINTF("Answer address len(%u) differs from original(%u)\n",
- ma.rdlength, a->rdlength);
- goto again;
+
+ if (first_answer) {
+ ma.buf = a->buf;
+ ma.buflen = a->buflen;
+ ma.add_count = a->add_count;
+ memcpy(a, &ma, sizeof(ma));
+ if (a->atype != T_SIG && (0 == a->buf || (type != T_A && type != T_AAAA)))
+ break;
+ if (a->atype != type) {
+ free(a->dotted);
+ continue;
+ }
+ a->add_count = h.ancount - j - 1;
+ if ((a->rdlength + sizeof(struct in_addr*)) * a->add_count > a->buflen)
+ break;
+ a->add_count = 0;
+ first_answer = 0;
+ } else {
+ free(ma.dotted);
+ if (ma.atype != type)
+ continue;
+ if (a->rdlength != ma.rdlength) {
+ free(a->dotted);
+ DPRINTF("Answer address len(%u) differs from original(%u)\n",
+ ma.rdlength, a->rdlength);
+ goto again;
+ }
+ memcpy(a->buf + (a->add_count * ma.rdlength), ma.rdata, ma.rdlength);
+ ++a->add_count;
}
- memcpy(a->buf + (a->add_count * ma.rdlength), ma.rdata, ma.rdlength);
- ++a->add_count;
- }
}
DPRINTF("Answer name = |%s|\n", a->dotted);
@@ -952,61 +991,57 @@ int attribute_hidden __dns_lookup(const char *name, int type, int nscount, char
free(lookup);
/* Mess with globals while under lock */
- LOCK;
- ns = local_ns;
- id = local_id;
- UNLOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
+ static_ns = local_ns;
+ static_id = local_id;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
- return (len); /* success! */
+ return len; /* success! */
- tryall:
+ tryall:
/* if there are other nameservers, give them a go,
otherwise return with error */
- {
- variant = -1;
- local_ns = (local_ns + 1) % nscount;
- if (local_ns == 0)
- retries++;
+ variant = -1;
+ local_ns = (local_ns + 1) % nscount;
+ if (local_ns == 0)
+ retries++;
- continue;
- }
+ continue;
- again:
+ again:
/* if there are searchdomains, try them or fallback as passed */
- {
- int sdomains;
- BIGLOCK;
- sdomains=__searchdomains;
- BIGUNLOCK;
-
- if (variant < sdomains - 1) {
- /* next search */
- variant++;
- } else {
- /* next server, first search */
- local_ns = (local_ns + 1) % nscount;
- if (local_ns == 0)
- retries++;
-
- variant = -1;
- }
+ if (!ends_with_dot) {
+ int sdomains;
+
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ sdomains = __searchdomains;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+
+ if (variant < sdomains - 1) {
+ /* next search */
+ variant++;
+ continue;
+ }
}
+ /* next server, first search */
+ local_ns = (local_ns + 1) % nscount;
+ if (local_ns == 0)
+ retries++;
+ variant = -1;
}
-fail:
+ fail:
if (fd != -1)
- close(fd);
- if (lookup)
- free(lookup);
- if (packet)
- free(packet);
+ close(fd);
+ free(lookup);
+ free(packet);
h_errno = NETDB_INTERNAL;
/* Mess with globals while under lock */
if (local_ns != -1) {
- LOCK;
- ns = local_ns;
- id = local_id;
- UNLOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
+ static_ns = local_ns;
+ static_id = local_id;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
return -1;
}
@@ -1014,21 +1049,21 @@ fail:
#ifdef L_opennameservers
+/* We use __resolv_lock to guard access to the
+ * '__nameservers' and __searchdomains globals */
int __nameservers;
char * __nameserver[MAX_SERVERS];
int __searchdomains;
char * __searchdomain[MAX_SEARCH];
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-pthread_mutex_t __resolv_lock = PTHREAD_MUTEX_INITIALIZER;
-#endif
+
+__UCLIBC_MUTEX_INIT(__resolv_lock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
/*
* we currently read formats not quite the same as that on normal
* unix systems, we can have a list of nameservers after the keyword.
*/
-int attribute_hidden __open_nameservers()
+void attribute_hidden __open_nameservers(void)
{
FILE *fp;
int i;
@@ -1036,18 +1071,14 @@ int attribute_hidden __open_nameservers()
char szBuffer[128], *p, *argv[RESOLV_ARGS];
int argc;
- BIGLOCK;
- if (__nameservers > 0) {
- BIGUNLOCK;
- return 0;
- }
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ if (__nameservers > 0)
+ goto DONE;
if ((fp = fopen("/etc/resolv.conf", "r")) ||
- (fp = fopen("/etc/config/resolv.conf", "r")))
+ (fp = fopen("/etc/config/resolv.conf", "r")))
{
-
while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) {
-
for (p = szBuffer; *p && isspace(*p); p++)
/* skip white space */;
if (*p == '\0' || *p == '\n' || *p == '#') /* skip comments etc */
@@ -1063,32 +1094,35 @@ int attribute_hidden __open_nameservers()
if (strcmp(argv[0], "nameserver") == 0) {
for (i = 1; i < argc && __nameservers < MAX_SERVERS; i++) {
- __nameserver[__nameservers++] = strdup(argv[i]);
+ __nameserver[__nameservers++] = strdup(argv[i]); /* TODO: what if this fails? */
DPRINTF("adding nameserver %s\n", argv[i]);
}
}
/* domain and search are mutually exclusive, the last one wins */
- if (strcmp(argv[0],"domain")==0 || strcmp(argv[0],"search")==0) {
+ if (strcmp(argv[0],"domain") == 0 || strcmp(argv[0],"search") == 0) {
while (__searchdomains > 0) {
free(__searchdomain[--__searchdomains]);
__searchdomain[__searchdomains] = NULL;
}
- for (i=1; i < argc && __searchdomains < MAX_SEARCH; i++) {
- __searchdomain[__searchdomains++] = strdup(argv[i]);
+ for (i = 1; i < argc && __searchdomains < MAX_SEARCH; i++) {
+ __searchdomain[__searchdomains++] = strdup(argv[i]); /* TODO: what if this fails? */
DPRINTF("adding search %s\n", argv[i]);
}
}
}
fclose(fp);
DPRINTF("nameservers = %d\n", __nameservers);
- BIGUNLOCK;
- return 0;
+ goto DONE;
}
DPRINTF("failed to open %s\n", "resolv.conf");
h_errno = NO_RECOVERY;
- BIGUNLOCK;
- return -1;
+
+ /* rv = -1; */
+
+ DONE:
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ /* return rv; */
}
#endif
@@ -1097,7 +1131,7 @@ int attribute_hidden __open_nameservers()
void attribute_hidden __close_nameservers(void)
{
- BIGLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
while (__nameservers > 0) {
free(__nameserver[--__nameservers]);
__nameserver[__nameservers] = NULL;
@@ -1106,7 +1140,7 @@ void attribute_hidden __close_nameservers(void)
free(__searchdomain[--__searchdomains]);
__searchdomain[__searchdomains] = NULL;
}
- BIGUNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
}
#endif
@@ -1117,7 +1151,7 @@ struct hostent *gethostbyname(const char *name)
static struct hostent h;
static char buf[sizeof(struct in_addr) +
sizeof(struct in_addr *)*2 +
- sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
+ sizeof(char *)*ALIAS_DIM + 384/*namebuffer*/ + 32/* margin */];
struct hostent *hp;
gethostbyname_r(name, &h, buf, sizeof(buf), &hp, &h_errno);
@@ -1137,7 +1171,7 @@ struct hostent *gethostbyname2(const char *name, int family)
static struct hostent h;
static char buf[sizeof(struct in6_addr) +
sizeof(struct in6_addr *)*2 +
- sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
+ sizeof(char *)*ALIAS_DIM + 384/*namebuffer*/ + 32/* margin */];
struct hostent *hp;
gethostbyname2_r(name, family, &h, buf, sizeof(buf), &hp, &h_errno);
@@ -1150,57 +1184,65 @@ struct hostent *gethostbyname2(const char *name, int family)
#ifdef L_res_init
+/* We use __resolv_lock to guard access to global '_res' */
+#ifdef USE___THREAD && USE___THREAD
+__thread
+#endif
+struct __res_state _res;
+
int res_init(void)
{
+ struct __res_state *rp = &(_res);
+
+ __UCLIBC_MUTEX_LOCK(__resolv_lock); /* must be a recursive lock! */
__close_nameservers();
__open_nameservers();
-
- BIGLOCK;
- _res.retrans = RES_TIMEOUT;
- _res.retry = 4;
- _res.options = RES_INIT;
- _res.id = (u_int) random();
- _res.nsaddr.sin_addr.s_addr = INADDR_ANY;
- _res.nsaddr.sin_family = AF_INET;
- _res.nsaddr.sin_port = htons(NAMESERVER_PORT);
- _res.ndots = 1;
- /** _res.pfcode = 0; **/
- _res._vcsock = -1;
- /** _res._flags = 0; **/
- /** _res.qhook = NULL; **/
- /** _res.rhook = NULL; **/
- /** _res._u._ext.nsinit = 0; **/
-
- if(__searchdomains) {
+ rp->retrans = RES_TIMEOUT;
+ rp->retry = 4;
+ rp->options = RES_INIT;
+ rp->id = (u_int) random();
+ rp->nsaddr.sin_addr.s_addr = INADDR_ANY;
+ rp->nsaddr.sin_family = AF_INET;
+ rp->nsaddr.sin_port = htons(NAMESERVER_PORT);
+ rp->ndots = 1;
+ /** rp->pfcode = 0; **/
+ rp->_vcsock = -1;
+ /** rp->_flags = 0; **/
+ /** rp->qhook = NULL; **/
+ /** rp->rhook = NULL; **/
+ /** rp->_u._ext.nsinit = 0; **/
+
+ if (__searchdomains) {
int i;
- for(i=0; i<__searchdomains; i++) {
- _res.dnsrch[i] = __searchdomain[i];
- }
+ for (i = 0; i < __searchdomains; i++)
+ rp->dnsrch[i] = __searchdomain[i];
}
- if(__nameservers) {
+ if (__nameservers) {
int i;
struct in_addr a;
- for(i=0; i<__nameservers; i++) {
+ for (i = 0; i < __nameservers; i++) {
if (inet_aton(__nameserver[i], &a)) {
- _res.nsaddr_list[i].sin_addr = a;
- _res.nsaddr_list[i].sin_family = AF_INET;
- _res.nsaddr_list[i].sin_port = htons(NAMESERVER_PORT);
+ rp->nsaddr_list[i].sin_addr = a;
+ rp->nsaddr_list[i].sin_family = AF_INET;
+ rp->nsaddr_list[i].sin_port = htons(NAMESERVER_PORT);
}
}
}
- _res.nscount = __nameservers;
- BIGUNLOCK;
+ rp->nscount = __nameservers;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
- return(0);
+ return 0;
}
libc_hidden_def(res_init)
-void res_close( void )
+#ifdef __UCLIBC_HAS_BSD_RES_CLOSE__
+void res_close(void)
{
- return;
+ __close_nameservers();
+ memset(&_res, 0, sizeof(_res));
}
-
+#endif
/* This needs to be after the use of _res in res_init, above. */
#undef _res
@@ -1271,33 +1313,29 @@ int res_query(const char *dname, int class, int type,
__open_nameservers();
if (!dname || class != 1 /* CLASS_IN */) {
h_errno = NO_RECOVERY;
- return(-1);
+ return -1;
}
- memset((char *) &a, '\0', sizeof(a));
+ memset(&a, '\0', sizeof(a));
- BIGLOCK;
- __nameserversXX=__nameservers;
- __nameserverXX=__nameserver;
- BIGUNLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ __nameserversXX = __nameservers;
+ __nameserverXX = __nameserver;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
i = __dns_lookup(dname, type, __nameserversXX, __nameserverXX, &packet, &a);
if (i < 0) {
h_errno = TRY_AGAIN;
- return(-1);
+ return -1;
}
free(a.dotted);
- if (a.atype == type) { /* CNAME*/
- int len = MIN(anslen, i);
- memcpy(answer, packet, len);
- if (packet)
- free(packet);
- return(len);
+ if (a.atype == type) { /* CNAME */
+ i = MIN(anslen, i);
+ memcpy(answer, packet, i);
}
- if (packet)
- free(packet);
+ free(packet);
return i;
}
libc_hidden_def(res_query)
@@ -1308,21 +1346,28 @@ libc_hidden_def(res_query)
* If enabled, implement search rules until answer or unrecoverable failure
* is detected. Error code, if any, is left in h_errno.
*/
-int res_search(name, class, type, answer, anslen)
- const char *name; /* domain name */
- int class, type; /* class and type of query */
- u_char *answer; /* buffer to put answer */
- int anslen; /* size of answer */
+#define __TRAILING_DOT (1<<0)
+#define __GOT_NODATA (1<<1)
+#define __GOT_SERVFAIL (1<<2)
+#define __TRIED_AS_IS (1<<3)
+int res_search(const char *name, int class, int type, u_char *answer,
+ int anslen)
{
const char *cp, * const *domain;
HEADER *hp = (HEADER *)(void *)answer;
u_int dots;
- int trailing_dot, ret, saved_herrno;
- int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
-
- if ((!name || !answer) || ((_res.options & RES_INIT) == 0 && res_init() == -1)) {
+ unsigned _state = 0;
+ int ret, saved_herrno;
+ u_long _res_options;
+ unsigned _res_ndots;
+ char **_res_dnsrch;
+
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ _res_options = _res.options;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ if ((!name || !answer) || ((_res_options & RES_INIT) == 0 && res_init() == -1)) {
h_errno = NETDB_INTERNAL;
- return (-1);
+ return -1;
}
errno = 0;
@@ -1330,21 +1375,24 @@ int res_search(name, class, type, answer, anslen)
dots = 0;
for (cp = name; *cp; cp++)
dots += (*cp == '.');
- trailing_dot = 0;
+
if (cp > name && *--cp == '.')
- trailing_dot++;
+ _state |= __TRAILING_DOT;
/*
* If there are dots in the name already, let's just give it a try
* 'as is'. The threshold can be set with the "ndots" option.
*/
saved_herrno = -1;
- if (dots >= _res.ndots) {
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ _res_ndots = _res.ndots;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ if (dots >= _res_ndots) {
ret = res_querydomain(name, NULL, class, type, answer, anslen);
if (ret > 0)
- return (ret);
+ return ret;
saved_herrno = h_errno;
- tried_as_is++;
+ _state |= __TRIED_AS_IS;
}
/*
@@ -1353,18 +1401,22 @@ int res_search(name, class, type, answer, anslen)
* - there is at least one dot, there is no trailing dot,
* and RES_DNSRCH is set.
*/
- if ((!dots && (_res.options & RES_DEFNAMES)) ||
- (dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
- int done = 0;
-
- for (domain = (const char * const *)_res.dnsrch;
- *domain && !done;
- domain++) {
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ _res_options = _res.options;
+ _res_dnsrch = _res.dnsrch;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ if ((!dots && (_res_options & RES_DEFNAMES)) ||
+ (dots && !(_state & __TRAILING_DOT) && (_res_options & RES_DNSRCH))) {
+ bool done = 0;
+
+ for (domain = (const char * const *)_res_dnsrch;
+ *domain && !done;
+ domain++) {
ret = res_querydomain(name, *domain, class, type,
- answer, anslen);
+ answer, anslen);
if (ret > 0)
- return (ret);
+ return ret;
/*
* If no server present, give up.
@@ -1381,33 +1433,36 @@ int res_search(name, class, type, answer, anslen)
*/
if (errno == ECONNREFUSED) {
h_errno = TRY_AGAIN;
- return (-1);
+ return -1;
}
switch (h_errno) {
- case NO_DATA:
- got_nodata++;
- /* FALLTHROUGH */
- case HOST_NOT_FOUND:
- /* keep trying */
- break;
- case TRY_AGAIN:
- if (hp->rcode == SERVFAIL) {
- /* try next search element, if any */
- got_servfail++;
+ case NO_DATA:
+ _state |= __GOT_NODATA;
+ /* FALLTHROUGH */
+ case HOST_NOT_FOUND:
+ /* keep trying */
break;
- }
- /* FALLTHROUGH */
- default:
- /* anything else implies that we're done */
- done++;
+ case TRY_AGAIN:
+ if (hp->rcode == SERVFAIL) {
+ /* try next search element, if any */
+ _state |= __GOT_SERVFAIL;
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ /* anything else implies that we're done */
+ done = 1;
}
/*
* if we got here for some reason other than DNSRCH,
* we only wanted one iteration of the loop, so stop.
*/
- if (!(_res.options & RES_DNSRCH))
- done++;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ _res_options = _res.options;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ if (!(_res_options & RES_DNSRCH))
+ done = 1;
}
}
@@ -1416,10 +1471,10 @@ int res_search(name, class, type, answer, anslen)
* note that we do this regardless of how many dots were in the
* name or whether it ends with a dot.
*/
- if (!tried_as_is) {
+ if (!(_state & __TRIED_AS_IS)) {
ret = res_querydomain(name, NULL, class, type, answer, anslen);
if (ret > 0)
- return (ret);
+ return ret;
}
/*
@@ -1432,36 +1487,43 @@ int res_search(name, class, type, answer, anslen)
*/
if (saved_herrno != -1)
h_errno = saved_herrno;
- else if (got_nodata)
+ else if (_state & __GOT_NODATA)
h_errno = NO_DATA;
- else if (got_servfail)
+ else if (_state & __GOT_SERVFAIL)
h_errno = TRY_AGAIN;
- return (-1);
+ return -1;
}
-
+#undef __TRAILING_DOT
+#undef __GOT_NODATA
+#undef __GOT_SERVFAIL
+#undef __TRIED_AS_IS
/*
* Perform a call on res_query on the concatenation of name and domain,
* removing a trailing dot from name if domain is NULL.
*/
-int res_querydomain(name, domain, class, type, answer, anslen)
- const char *name, *domain;
- int class, type; /* class and type of query */
- u_char *answer; /* buffer to put answer */
- int anslen; /* size of answer */
+int res_querydomain(const char *name, const char *domain, int class, int type,
+ u_char * answer, int anslen)
{
char nbuf[MAXDNAME];
const char *longname = nbuf;
size_t n, d;
+ u_long _res_options;
- if ((!name || !answer) || ((_res.options & RES_INIT) == 0 && res_init() == -1)) {
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ _res_options = _res.options;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ if ((!name || !answer) || ((_res_options & RES_INIT) == 0 && res_init() == -1)) {
h_errno = NETDB_INTERNAL;
- return (-1);
+ return -1;
}
#ifdef DEBUG
- if (_res.options & RES_DEBUG)
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ _res_options = _res.options;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ if (_res_options & RES_DEBUG)
printf(";; res_querydomain(%s, %s, %d, %d)\n",
- name, domain?domain:"<Nil>", class, type);
+ name, (domain ? domain : "<Nil>"), class, type);
#endif
if (domain == NULL) {
/*
@@ -1471,7 +1533,7 @@ int res_querydomain(name, domain, class, type, answer, anslen)
n = strlen(name);
if (n + 1 > sizeof(nbuf)) {
h_errno = NO_RECOVERY;
- return (-1);
+ return -1;
}
if (n > 0 && name[--n] == '.') {
strncpy(nbuf, name, n);
@@ -1483,11 +1545,11 @@ int res_querydomain(name, domain, class, type, answer, anslen)
d = strlen(domain);
if (n + 1 + d + 1 > sizeof(nbuf)) {
h_errno = NO_RECOVERY;
- return (-1);
+ return -1;
}
snprintf(nbuf, sizeof(nbuf), "%s.%s", name, domain);
}
- return (res_query(longname, class, type, answer, anslen));
+ return res_query(longname, class, type, answer, anslen);
}
libc_hidden_def(res_querydomain)
@@ -1503,11 +1565,11 @@ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type)
static struct hostent h;
static char buf[
#ifndef __UCLIBC_HAS_IPV6__
- sizeof(struct in_addr) + sizeof(struct in_addr *)*2 +
+ sizeof(struct in_addr) + sizeof(struct in_addr *)*2 +
#else
- sizeof(struct in6_addr) + sizeof(struct in6_addr *)*2 +
+ sizeof(struct in6_addr) + sizeof(struct in6_addr *)*2 +
#endif /* __UCLIBC_HAS_IPV6__ */
- sizeof(char *)*(ALIAS_DIM) + 384/*namebuffer*/ + 32/* margin */];
+ sizeof(char *)*ALIAS_DIM + 384 /*namebuffer*/ + 32 /* margin */];
struct hostent *hp;
gethostbyaddr_r(addr, len, type, &h, buf, sizeof(buf), &hp, &h_errno);
@@ -1520,12 +1582,13 @@ libc_hidden_def(gethostbyaddr)
#ifdef L_read_etc_hosts_r
-void attribute_hidden __open_etc_hosts(FILE **fp)
+FILE * __open_etc_hosts(void)
{
- if ((*fp = fopen("/etc/hosts", "r")) == NULL) {
- *fp = fopen("/etc/config/hosts", "r");
+ FILE * fp;
+ if ((fp = fopen("/etc/hosts", "r")) == NULL) {
+ fp = fopen("/etc/config/hosts", "r");
}
- return;
+ return fp;
}
int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
@@ -1535,69 +1598,78 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
struct hostent ** result,
int * h_errnop)
{
- struct in_addr *in=NULL;
- struct in_addr **addr_list=NULL;
+ struct in_addr *in = NULL;
+ struct in_addr **addr_list = NULL;
#ifdef __UCLIBC_HAS_IPV6__
- struct in6_addr *in6=NULL;
- struct in6_addr **addr_list6=NULL;
+ struct in6_addr *in6 = NULL;
+ struct in6_addr **addr_list6 =NULL;
#endif /* __UCLIBC_HAS_IPV6__ */
char *cp, **alias;
- int aliases, i, ret=HOST_NOT_FOUND;
+ int aliases, i, ret = HOST_NOT_FOUND;
- if (buflen < sizeof(char *)*(ALIAS_DIM))
+ /* make sure user char * is aligned */
+ i = ALIGN_BUFFER_OFFSET(buf);
+ if (unlikely(i)) {
+ if (buflen < i)
+ return ERANGE;
+ buf += i;
+ buflen -= i;
+ }
+
+ if (buflen < sizeof(char *)*ALIAS_DIM)
return ERANGE;
- alias=(char **)buf;
- buf+=sizeof(char **)*(ALIAS_DIM);
- buflen-=sizeof(char **)*(ALIAS_DIM);
+ alias = (char **)buf;
+ buf += sizeof(char **)*ALIAS_DIM;
+ buflen -= sizeof(char **)*ALIAS_DIM;
- if (action!=GETHOSTENT) {
+ if (action != GETHOSTENT) {
#ifdef __UCLIBC_HAS_IPV6__
- char *p=buf;
- size_t len=buflen;
+ char *p = buf;
+ size_t len = buflen;
#endif /* __UCLIBC_HAS_IPV6__ */
- *h_errnop=NETDB_INTERNAL;
+ *h_errnop = NETDB_INTERNAL;
if (buflen < sizeof(*in))
return ERANGE;
- in=(struct in_addr*)buf;
- buf+=sizeof(*in);
- buflen-=sizeof(*in);
+ in = (struct in_addr*)buf;
+ buf += sizeof(*in);
+ buflen -= sizeof(*in);
if (buflen < sizeof(*addr_list)*2)
return ERANGE;
- addr_list=(struct in_addr **)buf;
- buf+=sizeof(*addr_list)*2;
- buflen-=sizeof(*addr_list)*2;
+ addr_list = (struct in_addr **)buf;
+ buf += sizeof(*addr_list)*2;
+ buflen -= sizeof(*addr_list)*2;
#ifdef __UCLIBC_HAS_IPV6__
if (len < sizeof(*in6))
return ERANGE;
- in6=(struct in6_addr*)p;
- p+=sizeof(*in6);
- len-=sizeof(*in6);
+ in6 = (struct in6_addr*)p;
+ p += sizeof(*in6);
+ len -= sizeof(*in6);
if (len < sizeof(*addr_list6)*2)
return ERANGE;
- addr_list6=(struct in6_addr**)p;
- p+=sizeof(*addr_list6)*2;
- len-=sizeof(*addr_list6)*2;
+ addr_list6 = (struct in6_addr**)p;
+ p += sizeof(*addr_list6)*2;
+ len -= sizeof(*addr_list6)*2;
if (len < buflen) {
- buflen=len;
- buf=p;
+ buflen = len;
+ buf = p;
}
#endif /* __UCLIBC_HAS_IPV6__ */
if (buflen < 80)
return ERANGE;
- __open_etc_hosts(&fp);
+ fp = __open_etc_hosts();
if (fp == NULL) {
- result=NULL;
+ result = NULL;
return errno;
}
}
- *h_errnop=HOST_NOT_FOUND;
+ *h_errnop = HOST_NOT_FOUND;
while (fgets(buf, buflen, fp)) {
if ((cp = strchr(buf, '#')))
*cp = '\0';
@@ -1620,10 +1692,10 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
if (aliases < 2)
continue; /* syntax error really */
- if (action==GETHOSTENT) {
+ if (action == GETHOSTENT) {
/* Return whatever the next entry happens to be. */
break;
- } else if (action==GET_HOSTS_BYADDR) {
+ } else if (action == GET_HOSTS_BYADDR) {
if (strcmp(name, alias[0]) != 0)
continue;
} else {
@@ -1644,10 +1716,10 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
result_buf->h_length = sizeof(*in);
result_buf->h_addr_list = (char**) addr_list;
result_buf->h_aliases = alias + 2;
- *result=result_buf;
- ret=NETDB_SUCCESS;
+ *result = result_buf;
+ ret = NETDB_SUCCESS;
#ifdef __UCLIBC_HAS_IPV6__
- } else if (type == AF_INET6 && inet_pton(AF_INET6, alias[0], in6) > 0) {
+ } else if (type == AF_INET6 && inet_pton(AF_INET6, alias[0], in6) > 0) {
DPRINTF("Found INET6\n");
addr_list6[0] = in6;
addr_list6[1] = 0;
@@ -1656,92 +1728,100 @@ int attribute_hidden __read_etc_hosts_r(FILE * fp, const char * name, int type,
result_buf->h_length = sizeof(*in6);
result_buf->h_addr_list = (char**) addr_list6;
result_buf->h_aliases = alias + 2;
- *result=result_buf;
- ret=NETDB_SUCCESS;
+ *result = result_buf;
+ ret = NETDB_SUCCESS;
#endif /* __UCLIBC_HAS_IPV6__ */
} else {
- DPRINTF("Error\n");
- ret=TRY_AGAIN;
- break; /* bad ip address */
- }
+ /* continue parsing in the hope the user has multiple
+ * host types listed in the database like so:
+ * <ipv4 addr> host
+ * <ipv6 addr> host
+ * If looking for an IPv6 addr, don't bail when we got the IPv4
+ */
+ DPRINTF("Error: Found host but diff network type\n");
+ ret = TRY_AGAIN;
+ continue;
+ }
- if (action!=GETHOSTENT) {
+ if (action != GETHOSTENT)
fclose(fp);
- }
return ret;
}
- if (action!=GETHOSTENT) {
+ if (action != GETHOSTENT)
fclose(fp);
- }
return ret;
}
#endif
#ifdef L_gethostent
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
-static int __stay_open;
+static smallint __stay_open;
static FILE * __gethostent_fp;
-void endhostent (void)
+void endhostent(void)
{
- LOCK;
- __stay_open = 0;
- if (__gethostent_fp) {
- fclose(__gethostent_fp);
- }
- UNLOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
+ __stay_open = 0;
+ if (__gethostent_fp) {
+ fclose(__gethostent_fp);
+ __gethostent_fp = NULL;
+ }
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
-void sethostent (int stay_open)
+void sethostent(int stay_open)
{
- LOCK;
- __stay_open = stay_open;
- UNLOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
+ __stay_open = (stay_open != 0);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
int gethostent_r(struct hostent *result_buf, char *buf, size_t buflen,
struct hostent **result, int *h_errnop)
{
- int ret;
+ int ret;
- LOCK;
- if (__gethostent_fp == NULL) {
- __open_etc_hosts(&__gethostent_fp);
+ __UCLIBC_MUTEX_LOCK(mylock);
if (__gethostent_fp == NULL) {
- UNLOCK;
- *result=NULL;
- return 0;
+ __gethostent_fp = __open_etc_hosts();
+ if (__gethostent_fp == NULL) {
+ *result = NULL;
+ ret = TRY_AGAIN;
+ goto DONE;
+ }
}
- }
- ret = __read_etc_hosts_r(__gethostent_fp, NULL, AF_INET, GETHOSTENT,
+ ret = __read_etc_hosts_r(__gethostent_fp, NULL, AF_INET, GETHOSTENT,
result_buf, buf, buflen, result, h_errnop);
- if (__stay_open==0) {
- fclose(__gethostent_fp);
- }
- UNLOCK;
- return(ret);
+ if (__stay_open == 0) {
+ fclose(__gethostent_fp);
+ __gethostent_fp = NULL;
+ }
+DONE:
+ __UCLIBC_MUTEX_UNLOCK(mylock);
+ return ret;
}
libc_hidden_def(gethostent_r)
-struct hostent *gethostent (void)
+struct hostent *gethostent(void)
{
- static struct hostent h;
- static char buf[
+ static struct hostent h;
+ static char buf[
#ifndef __UCLIBC_HAS_IPV6__
- sizeof(struct in_addr) + sizeof(struct in_addr *)*2 +
+ sizeof(struct in_addr) + sizeof(struct in_addr *)*2 +
#else
- sizeof(struct in6_addr) + sizeof(struct in6_addr *)*2 +
+ sizeof(struct in6_addr) + sizeof(struct in6_addr *)*2 +
#endif /* __UCLIBC_HAS_IPV6__ */
- sizeof(char *)*(ALIAS_DIM) +
- 80/*namebuffer*/ + 2/* margin */];
- struct hostent *host;
-
- LOCK;
- gethostent_r(&h, buf, sizeof(buf), &host, &h_errno);
- UNLOCK;
- return(host);
+ sizeof(char *)*ALIAS_DIM +
+ 80 /*namebuffer*/ + 2 /* margin */];
+ struct hostent *host;
+
+ __UCLIBC_MUTEX_LOCK(mylock);
+ gethostent_r(&h, buf, sizeof(buf), &host, &h_errno);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
+ return host;
}
#endif
@@ -1753,8 +1833,8 @@ int attribute_hidden __get_hosts_byname_r(const char * name, int type,
struct hostent ** result,
int * h_errnop)
{
- return(__read_etc_hosts_r(NULL, name, type, GET_HOSTS_BYNAME,
- result_buf, buf, buflen, result, h_errnop));
+ return __read_etc_hosts_r(NULL, name, type, GET_HOSTS_BYNAME,
+ result_buf, buf, buflen, result, h_errnop);
}
#endif
@@ -1772,25 +1852,25 @@ int attribute_hidden __get_hosts_byaddr_r(const char * addr, int len, int type,
char ipaddr[INET6_ADDRSTRLEN];
#endif /* __UCLIBC_HAS_IPV6__ */
- switch (type) {
- case AF_INET:
- if (len != sizeof(struct in_addr))
- return 0;
- break;
+ switch (type) {
+ case AF_INET:
+ if (len != sizeof(struct in_addr))
+ return 0;
+ break;
#ifdef __UCLIBC_HAS_IPV6__
- case AF_INET6:
- if (len != sizeof(struct in6_addr))
- return 0;
- break;
+ case AF_INET6:
+ if (len != sizeof(struct in6_addr))
+ return 0;
+ break;
#endif /* __UCLIBC_HAS_IPV6__ */
- default:
- return 0;
+ default:
+ return 0;
}
inet_ntop(type, addr, ipaddr, sizeof(ipaddr));
- return(__read_etc_hosts_r(NULL, ipaddr, type, GET_HOSTS_BYADDR,
- result_buf, buf, buflen, result, h_errnop));
+ return __read_etc_hosts_r(NULL, ipaddr, type, GET_HOSTS_BYADDR,
+ result_buf, buf, buflen, result, h_errnop);
}
#endif
@@ -1801,12 +1881,12 @@ int attribute_hidden __get_hosts_byaddr_r(const char * addr, int len, int type,
#endif /* min */
libc_hidden_proto(getnameinfo)
-int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
- socklen_t hostlen, char *serv, socklen_t servlen,
- unsigned int flags)
+int getnameinfo(const struct sockaddr *sa, socklen_t addrlen, char *host,
+ socklen_t hostlen, char *serv, socklen_t servlen,
+ unsigned int flags)
{
int serrno = errno;
- int ok = 0;
+ unsigned ok;
struct hostent *h = NULL;
char domain[256];
@@ -1814,25 +1894,27 @@ int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
return EAI_BADFLAGS;
if (sa == NULL || addrlen < sizeof (sa_family_t))
- return EAI_FAMILY;
+ goto BAD_FAM;
- switch (sa->sa_family) {
- case AF_LOCAL:
- break;
- case AF_INET:
+ ok = sa->sa_family;
+ if (ok == AF_LOCAL) /* valid */;
+#ifdef __UCLIBC_HAS_IPV4__
+ else if (ok == AF_INET) {
if (addrlen < sizeof (struct sockaddr_in))
- return EAI_FAMILY;
- break;
+ goto BAD_FAM;
+ }
+#endif
#ifdef __UCLIBC_HAS_IPV6__
- case AF_INET6:
+ else if (ok == AF_INET6) {
if (addrlen < sizeof (struct sockaddr_in6))
- return EAI_FAMILY;
- break;
+ goto BAD_FAM;
+ }
#endif /* __UCLIBC_HAS_IPV6__ */
- default:
+ else
+BAD_FAM:
return EAI_FAMILY;
- }
+ ok = 0;
if (host != NULL && hostlen > 0)
switch (sa->sa_family) {
case AF_INET:
@@ -1845,15 +1927,19 @@ int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
h = gethostbyaddr ((const void *)
&(((const struct sockaddr_in6 *) sa)->sin6_addr),
sizeof(struct in6_addr), AF_INET6);
- else
#endif /* __UCLIBC_HAS_IPV6__ */
- h = gethostbyaddr ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
+#if defined __UCLIBC_HAS_IPV6__ && defined __UCLIBC_HAS_IPV4__
+ else
+#endif
+#ifdef __UCLIBC_HAS_IPV4__
+ h = gethostbyaddr ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
sizeof(struct in_addr), AF_INET);
+#endif /* __UCLIBC_HAS_IPV4__ */
if (h) {
char *c;
if ((flags & NI_NOFQDN)
- && (getdomainname (domain, sizeof(domain)) == 0)
+ && (__libc_getdomainname (domain, sizeof(domain)) == 0)
&& (c = strstr (h->h_name, domain))
&& (c != h->h_name) && (*(--c) == '.')) {
strncpy (host, h->h_name,
@@ -1919,11 +2005,16 @@ int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
memcpy (host + real_hostlen, scopebuf, scopelen + 1);
}
#endif
- } else
+ }
#endif /* __UCLIBC_HAS_IPV6__ */
+#if defined __UCLIBC_HAS_IPV6__ && defined __UCLIBC_HAS_IPV4__
+ else
+#endif /* __UCLIBC_HAS_IPV6__ && defined __UCLIBC_HAS_IPV4__ */
+#if defined __UCLIBC_HAS_IPV4__
c = inet_ntop (AF_INET, (const void *)
&(((const struct sockaddr_in *) sa)->sin_addr),
host, hostlen);
+#endif /* __UCLIBC_HAS_IPV4__ */
if (c == NULL) {
errno = serrno;
@@ -1952,34 +2043,29 @@ int getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
strncpy (host, "localhost", hostlen);
break;
- default:
+/*Already checked above default:
return EAI_FAMILY;
+*/
}
if (serv && (servlen > 0)) {
- switch (sa->sa_family) {
- case AF_INET:
-#ifdef __UCLIBC_HAS_IPV6__
- case AF_INET6:
-#endif /* __UCLIBC_HAS_IPV6__ */
+ if (sa->sa_family == AF_LOCAL) {
+ strncpy (serv, ((const struct sockaddr_un *) sa)->sun_path, servlen);
+ } else { /* AF_INET || AF_INET6 */
if (!(flags & NI_NUMERICSERV)) {
struct servent *s;
s = getservbyport (((const struct sockaddr_in *) sa)->sin_port,
((flags & NI_DGRAM) ? "udp" : "tcp"));
if (s) {
strncpy (serv, s->s_name, servlen);
- break;
+ goto DONE;
}
}
snprintf (serv, servlen, "%d",
ntohs (((const struct sockaddr_in *) sa)->sin_port));
- break;
-
- case AF_LOCAL:
- strncpy (serv, ((const struct sockaddr_un *) sa)->sun_path, servlen);
- break;
}
}
+DONE:
if (host && (hostlen > 0))
host[hostlen-1] = 0;
if (serv && (servlen > 0))
@@ -1994,10 +2080,10 @@ libc_hidden_def(getnameinfo)
#ifdef L_gethostbyname_r
int gethostbyname_r(const char * name,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop)
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop)
{
struct in_addr *in;
struct in_addr **addr_list;
@@ -2009,7 +2095,7 @@ int gethostbyname_r(const char * name,
char ** __nameserverXX;
__open_nameservers();
- *result=NULL;
+ *result = NULL;
if (!name)
return EINVAL;
@@ -2018,8 +2104,8 @@ int gethostbyname_r(const char * name,
int old_errno = errno; /* Save the old errno and reset errno */
__set_errno(0); /* to check for missing /etc/hosts. */
- if ((i=__get_hosts_byname_r(name, AF_INET, result_buf,
- buf, buflen, result, h_errnop))==0)
+ if ((i = __get_hosts_byname_r(name, AF_INET, result_buf,
+ buf, buflen, result, h_errnop)) == 0)
return i;
switch (*h_errnop) {
case HOST_NOT_FOUND:
@@ -2038,29 +2124,38 @@ int gethostbyname_r(const char * name,
DPRINTF("Nothing found in /etc/hosts\n");
+ /* make sure user char * is aligned */
+ i = ALIGN_BUFFER_OFFSET(buf);
+ if (unlikely(i)) {
+ if (buflen < i)
+ return ERANGE;
+ buf += i;
+ buflen -= i;
+ }
+
*h_errnop = NETDB_INTERNAL;
if (buflen < sizeof(*in))
return ERANGE;
- in=(struct in_addr*)buf;
- buf+=sizeof(*in);
- buflen-=sizeof(*in);
+ in = (struct in_addr*)buf;
+ buf += sizeof(*in);
+ buflen -= sizeof(*in);
if (buflen < sizeof(*addr_list)*2)
return ERANGE;
- addr_list=(struct in_addr**)buf;
- buf+=sizeof(*addr_list)*2;
- buflen-=sizeof(*addr_list)*2;
+ addr_list = (struct in_addr**)buf;
+ buf += sizeof(*addr_list)*2;
+ buflen -= sizeof(*addr_list)*2;
addr_list[0] = in;
addr_list[1] = 0;
- if (buflen < sizeof(char *)*(ALIAS_DIM))
+ if (buflen < sizeof(char *)*ALIAS_DIM)
return ERANGE;
- alias=(char **)buf;
- buf+=sizeof(char **)*(ALIAS_DIM);
- buflen-=sizeof(char **)*(ALIAS_DIM);
+ alias = (char **)buf;
+ buf += sizeof(char **)*ALIAS_DIM;
+ buflen -= sizeof(char **)*ALIAS_DIM;
- if (buflen<256)
+ if (buflen < 256)
return ERANGE;
strncpy(buf, name, buflen);
@@ -2069,76 +2164,72 @@ int gethostbyname_r(const char * name,
/* First check if this is already an address */
if (inet_aton(name, in)) {
- result_buf->h_name = buf;
- result_buf->h_addrtype = AF_INET;
- result_buf->h_length = sizeof(*in);
- result_buf->h_addr_list = (char **) addr_list;
- result_buf->h_aliases = alias;
- *result=result_buf;
- *h_errnop = NETDB_SUCCESS;
- return NETDB_SUCCESS;
+ result_buf->h_name = buf;
+ result_buf->h_addrtype = AF_INET;
+ result_buf->h_length = sizeof(*in);
+ result_buf->h_addr_list = (char **) addr_list;
+ result_buf->h_aliases = alias;
+ *result = result_buf;
+ *h_errnop = NETDB_SUCCESS;
+ return NETDB_SUCCESS;
}
for (;;) {
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ __nameserversXX = __nameservers;
+ __nameserverXX = __nameserver;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
+ a.buf = buf;
+ a.buflen = buflen;
+ a.add_count = 0;
+ i = __dns_lookup(name, T_A, __nameserversXX, __nameserverXX, &packet, &a);
- BIGLOCK;
- __nameserversXX=__nameservers;
- __nameserverXX=__nameserver;
- BIGUNLOCK;
- a.buf = buf;
- a.buflen = buflen;
- a.add_count = 0;
- i = __dns_lookup(name, T_A, __nameserversXX, __nameserverXX, &packet, &a);
-
- if (i < 0) {
- *h_errnop = HOST_NOT_FOUND;
- DPRINTF("__dns_lookup\n");
- return TRY_AGAIN;
- }
-
- if ((a.rdlength + sizeof(struct in_addr*)) * a.add_count + 256 > buflen)
- {
+ if (i < 0) {
+ *h_errnop = HOST_NOT_FOUND;
+ DPRINTF("__dns_lookup\n");
+ return TRY_AGAIN;
+ }
+
+ if ((a.rdlength + sizeof(struct in_addr*)) * a.add_count + 256 > buflen) {
+ free(a.dotted);
+ free(packet);
+ *h_errnop = NETDB_INTERNAL;
+ DPRINTF("buffer too small for all addresses\n");
+ return ERANGE;
+ } else if (a.add_count > 0) {
+ memmove(buf - sizeof(struct in_addr*)*2, buf, a.add_count * a.rdlength);
+ addr_list = (struct in_addr**)(buf + a.add_count * a.rdlength);
+ addr_list[0] = in;
+ for (i = a.add_count - 1; i >= 0; --i)
+ addr_list[i+1] = (struct in_addr*)(buf - sizeof(struct in_addr*)*2 + a.rdlength * i);
+ addr_list[a.add_count + 1] = 0;
+ buflen -= (((char*)&(addr_list[a.add_count + 2])) - buf);
+ buf = (char*)&addr_list[a.add_count + 2];
+ }
+
+ strncpy(buf, a.dotted, buflen);
free(a.dotted);
- free(packet);
- *h_errnop = NETDB_INTERNAL;
- DPRINTF("buffer too small for all addresses\n");
- return ERANGE;
- }
- else if(a.add_count > 0)
- {
- memmove(buf - sizeof(struct in_addr*)*2, buf, a.add_count * a.rdlength);
- addr_list = (struct in_addr**)(buf + a.add_count * a.rdlength);
- addr_list[0] = in;
- for (i = a.add_count-1; i>=0; --i)
- addr_list[i+1] = (struct in_addr*)(buf - sizeof(struct in_addr*)*2 + a.rdlength * i);
- addr_list[a.add_count + 1] = 0;
- buflen -= (((char*)&(addr_list[a.add_count + 2])) - buf);
- buf = (char*)&addr_list[a.add_count + 2];
- }
-
- strncpy(buf, a.dotted, buflen);
- free(a.dotted);
-
- if (a.atype == T_A) { /* ADDRESS */
- memcpy(in, a.rdata, sizeof(*in));
- result_buf->h_name = buf;
- result_buf->h_addrtype = AF_INET;
- result_buf->h_length = sizeof(*in);
- result_buf->h_addr_list = (char **) addr_list;
+
+ if (a.atype == T_A) { /* ADDRESS */
+ memcpy(in, a.rdata, sizeof(*in));
+ result_buf->h_name = buf;
+ result_buf->h_addrtype = AF_INET;
+ result_buf->h_length = sizeof(*in);
+ result_buf->h_addr_list = (char **) addr_list;
#ifdef __UCLIBC_MJN3_ONLY__
#warning TODO -- generate the full list
#endif
- result_buf->h_aliases = alias; /* TODO: generate the full list */
- free(packet);
- break;
- } else {
- free(packet);
- *h_errnop=HOST_NOT_FOUND;
- return TRY_AGAIN;
- }
+ result_buf->h_aliases = alias; /* TODO: generate the full list */
+ free(packet);
+ break;
+ } else {
+ free(packet);
+ *h_errnop = HOST_NOT_FOUND;
+ return TRY_AGAIN;
+ }
}
- *result=result_buf;
+ *result = result_buf;
*h_errnop = NETDB_SUCCESS;
return NETDB_SUCCESS;
}
@@ -2148,14 +2239,15 @@ libc_hidden_def(gethostbyname_r)
#ifdef L_gethostbyname2_r
int gethostbyname2_r(const char *name, int family,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop)
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop)
{
#ifndef __UCLIBC_HAS_IPV6__
- return family == (AF_INET)? gethostbyname_r(name, result_buf,
- buf, buflen, result, h_errnop) : HOST_NOT_FOUND;
+ return family == (AF_INET)
+ ? gethostbyname_r(name, result_buf, buf, buflen, result, h_errnop)
+ : HOST_NOT_FOUND;
#else /* __UCLIBC_HAS_IPV6__ */
struct in6_addr *in;
struct in6_addr **addr_list;
@@ -2173,7 +2265,7 @@ int gethostbyname2_r(const char *name, int family,
return EINVAL;
__open_nameservers();
- *result=NULL;
+ *result = NULL;
if (!name)
return EINVAL;
@@ -2182,8 +2274,8 @@ int gethostbyname2_r(const char *name, int family,
int old_errno = errno; /* Save the old errno and reset errno */
__set_errno(0); /* to check for missing /etc/hosts. */
- if ((i=__get_hosts_byname_r(name, AF_INET, result_buf,
- buf, buflen, result, h_errnop))==0)
+ if ((i = __get_hosts_byname_r(name, family, result_buf,
+ buf, buflen, result, h_errnop)) == 0)
return i;
switch (*h_errnop) {
case HOST_NOT_FOUND:
@@ -2205,41 +2297,41 @@ int gethostbyname2_r(const char *name, int family,
*h_errnop = NETDB_INTERNAL;
if (buflen < sizeof(*in))
return ERANGE;
- in=(struct in6_addr*)buf;
- buf+=sizeof(*in);
- buflen-=sizeof(*in);
+ in = (struct in6_addr*)buf;
+ buf += sizeof(*in);
+ buflen -= sizeof(*in);
if (buflen < sizeof(*addr_list)*2)
return ERANGE;
- addr_list=(struct in6_addr**)buf;
- buf+=sizeof(*addr_list)*2;
- buflen-=sizeof(*addr_list)*2;
+ addr_list = (struct in6_addr**)buf;
+ buf += sizeof(*addr_list)*2;
+ buflen -= sizeof(*addr_list)*2;
addr_list[0] = in;
addr_list[1] = 0;
- if (buflen<256)
+ if (buflen < 256)
return ERANGE;
strncpy(buf, name, buflen);
/* First check if this is already an address */
if (inet_pton(AF_INET6, name, in)) {
- result_buf->h_name = buf;
- result_buf->h_addrtype = AF_INET6;
- result_buf->h_length = sizeof(*in);
- result_buf->h_addr_list = (char **) addr_list;
- *result=result_buf;
- *h_errnop = NETDB_SUCCESS;
- return NETDB_SUCCESS;
+ result_buf->h_name = buf;
+ result_buf->h_addrtype = AF_INET6;
+ result_buf->h_length = sizeof(*in);
+ result_buf->h_addr_list = (char **) addr_list;
+ *result = result_buf;
+ *h_errnop = NETDB_SUCCESS;
+ return NETDB_SUCCESS;
}
memset((char *) &a, '\0', sizeof(a));
for (;;) {
- BIGLOCK;
- __nameserversXX=__nameservers;
- __nameserverXX=__nameserver;
- BIGUNLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ __nameserversXX = __nameservers;
+ __nameserverXX = __nameserver;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
i = __dns_lookup(buf, T_AAAA, __nameserversXX, __nameserverXX, &packet, &a);
@@ -2275,12 +2367,12 @@ int gethostbyname2_r(const char *name, int family,
break;
} else {
free(packet);
- *h_errnop=HOST_NOT_FOUND;
+ *h_errnop = HOST_NOT_FOUND;
return TRY_AGAIN;
}
}
- *result=result_buf;
+ *result = result_buf;
*h_errnop = NETDB_SUCCESS;
return NETDB_SUCCESS;
#endif /* __UCLIBC_HAS_IPV6__ */
@@ -2289,11 +2381,11 @@ libc_hidden_def(gethostbyname2_r)
#endif
#ifdef L_gethostbyaddr_r
-int gethostbyaddr_r (const void *addr, socklen_t len, int type,
- struct hostent * result_buf,
- char * buf, size_t buflen,
- struct hostent ** result,
- int * h_errnop)
+int gethostbyaddr_r(const void *addr, socklen_t len, int type,
+ struct hostent * result_buf,
+ char * buf, size_t buflen,
+ struct hostent ** result,
+ int * h_errnop)
{
struct in_addr *in;
@@ -2312,7 +2404,7 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
int __nameserversXX;
char ** __nameserverXX;
- *result=NULL;
+ *result = NULL;
if (!addr)
return EINVAL;
@@ -2334,8 +2426,8 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
}
/* do /etc/hosts first */
- if ((i=__get_hosts_byaddr_r(addr, len, type, result_buf,
- buf, buflen, result, h_errnop))==0)
+ if ((i = __get_hosts_byaddr_r(addr, len, type, result_buf,
+ buf, buflen, result, h_errnop)) == 0)
return i;
switch (*h_errnop) {
case HOST_NOT_FOUND:
@@ -2348,52 +2440,52 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
__open_nameservers();
#ifdef __UCLIBC_HAS_IPV6__
- qp=buf;
- plen=buflen;
+ qp = buf;
+ plen = buflen;
#endif /* __UCLIBC_HAS_IPV6__ */
*h_errnop = NETDB_INTERNAL;
if (buflen < sizeof(*in))
return ERANGE;
- in=(struct in_addr*)buf;
- buf+=sizeof(*in);
- buflen-=sizeof(*in);
+ in = (struct in_addr*)buf;
+ buf += sizeof(*in);
+ buflen -= sizeof(*in);
if (buflen < sizeof(*addr_list)*2)
return ERANGE;
- addr_list=(struct in_addr**)buf;
- buf+=sizeof(*addr_list)*2;
- buflen-=sizeof(*addr_list)*2;
+ addr_list = (struct in_addr**)buf;
+ buf += sizeof(*addr_list)*2;
+ buflen -= sizeof(*addr_list)*2;
- if (buflen < sizeof(char *)*(ALIAS_DIM))
+ if (buflen < sizeof(char *)*ALIAS_DIM)
return ERANGE;
- alias=(char **)buf;
- buf+=sizeof(*alias)*(ALIAS_DIM);
- buflen-=sizeof(*alias)*(ALIAS_DIM);
+ alias = (char **)buf;
+ buf += sizeof(*alias)*ALIAS_DIM;
+ buflen -= sizeof(*alias)*ALIAS_DIM;
#ifdef __UCLIBC_HAS_IPV6__
if (plen < sizeof(*in6))
return ERANGE;
- in6=(struct in6_addr*)qp;
- qp+=sizeof(*in6);
- plen-=sizeof(*in6);
+ in6 = (struct in6_addr*)qp;
+ qp += sizeof(*in6);
+ plen -= sizeof(*in6);
if (plen < sizeof(*addr_list6)*2)
return ERANGE;
- addr_list6=(struct in6_addr**)qp;
- qp+=sizeof(*addr_list6)*2;
- plen-=sizeof(*addr_list6)*2;
+ addr_list6 = (struct in6_addr**)qp;
+ qp += sizeof(*addr_list6)*2;
+ plen -= sizeof(*addr_list6)*2;
if (plen < buflen) {
- buflen=plen;
- buf=qp;
+ buflen = plen;
+ buf = qp;
}
#endif /* __UCLIBC_HAS_IPV6__ */
- if (buflen<256)
+ if (buflen < 256)
return ERANGE;
- if(type == AF_INET) {
+ if (type == AF_INET) {
unsigned char *tmp_addr = (unsigned char *)addr;
memcpy(&in->s_addr, addr, len);
@@ -2401,7 +2493,7 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
addr_list[0] = in;
sprintf(buf, "%u.%u.%u.%u.in-addr.arpa",
- tmp_addr[3], tmp_addr[2], tmp_addr[1], tmp_addr[0]);
+ tmp_addr[3], tmp_addr[2], tmp_addr[1], tmp_addr[0]);
#ifdef __UCLIBC_HAS_IPV6__
} else {
memcpy(in6->s6_addr, addr, len);
@@ -2411,9 +2503,9 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
for (i = len - 1; i >= 0; i--) {
qp += sprintf(qp, "%x.%x.", in6->s6_addr[i] & 0xf,
- (in6->s6_addr[i] >> 4) & 0xf);
- }
- strcpy(qp, "ip6.int");
+ (in6->s6_addr[i] >> 4) & 0xf);
+ }
+ strcpy(qp, "ip6.arpa");
#endif /* __UCLIBC_HAS_IPV6__ */
}
@@ -2423,11 +2515,10 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
alias[1] = 0;
for (;;) {
-
- BIGLOCK;
- __nameserversXX=__nameservers;
- __nameserverXX=__nameserver;
- BIGUNLOCK;
+ __UCLIBC_MUTEX_LOCK(__resolv_lock);
+ __nameserversXX = __nameservers;
+ __nameserverXX = __nameserver;
+ __UCLIBC_MUTEX_UNLOCK(__resolv_lock);
i = __dns_lookup(buf, T_PTR, __nameserversXX, __nameserverXX, &packet, &a);
if (i < 0) {
@@ -2459,13 +2550,13 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
result_buf->h_name = buf;
result_buf->h_addrtype = type;
- if(type == AF_INET) {
+ if (type == AF_INET) {
result_buf->h_length = sizeof(*in);
#ifdef __UCLIBC_HAS_IPV6__
} else {
result_buf->h_length = sizeof(*in6);
#endif /* __UCLIBC_HAS_IPV6__ */
- }
+ }
result_buf->h_addr_list = (char **) addr_list;
result_buf->h_aliases = alias;
@@ -2477,7 +2568,7 @@ int gethostbyaddr_r (const void *addr, socklen_t len, int type,
}
}
- *result=result_buf;
+ *result = result_buf;
*h_errnop = NETDB_SUCCESS;
return NETDB_SUCCESS;
}
@@ -2493,13 +2584,13 @@ libc_hidden_def(gethostbyaddr_r)
* Return size of compressed name or -1 if there was an error.
*/
int __dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
- char *dst, int dstsiz)
+ char *dst, int dstsiz)
{
int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
if (n > 0 && dst[0] == '.')
dst[0] = '\0';
- return (n);
+ return n;
}
#endif /* L_res_comp */
@@ -2513,7 +2604,7 @@ int __dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
*/
static int printable(int ch)
{
- return (ch > 0x20 && ch < 0x7f);
+ return (ch > 0x20 && ch < 0x7f);
}
/*
@@ -2525,18 +2616,18 @@ static int printable(int ch)
*/
static int special(int ch)
{
- switch (ch) {
- case 0x22: /* '"' */
- case 0x2E: /* '.' */
- case 0x3B: /* ';' */
- case 0x5C: /* '\\' */
- /* Special modifiers in zone files. */
- case 0x40: /* '@' */
- case 0x24: /* '$' */
- return (1);
- default:
- return (0);
- }
+ switch (ch) {
+ case 0x22: /* '"' */
+ case 0x2E: /* '.' */
+ case 0x3B: /* ';' */
+ case 0x5C: /* '\\' */
+ /* Special modifiers in zone files. */
+ case 0x40: /* '@' */
+ case 0x24: /* '$' */
+ return 1;
+ default:
+ return 0;
+ }
}
/*
@@ -2554,10 +2645,10 @@ int ns_name_uncompress(const u_char *msg, const u_char *eom,
int n;
if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
- return (-1);
+ return -1;
if (ns_name_ntop(tmp, dst, dstsiz) == -1)
- return (-1);
- return (n);
+ return -1;
+ return n;
}
libc_hidden_def(ns_name_uncompress)
@@ -2585,33 +2676,33 @@ int ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
while ((n = *cp++) != 0) {
if ((n & NS_CMPRSFLGS) != 0) {
/* Some kind of compression pointer. */
- __set_errno (EMSGSIZE);
- return (-1);
+ __set_errno(EMSGSIZE);
+ return -1;
}
if (dn != dst) {
if (dn >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
+ __set_errno(EMSGSIZE);
+ return -1;
}
*dn++ = '.';
}
if (dn + n >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
+ __set_errno(EMSGSIZE);
+ return -1;
}
for ((void)NULL; n > 0; n--) {
c = *cp++;
if (special(c)) {
if (dn + 1 >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
+ __set_errno(EMSGSIZE);
+ return -1;
}
*dn++ = '\\';
*dn++ = (char)c;
} else if (!printable(c)) {
if (dn + 3 >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
+ __set_errno(EMSGSIZE);
+ return -1;
}
*dn++ = '\\';
*dn++ = digits[c / 100];
@@ -2619,8 +2710,8 @@ int ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
*dn++ = digits[c % 10];
} else {
if (dn >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
+ __set_errno(EMSGSIZE);
+ return -1;
}
*dn++ = (char)c;
}
@@ -2628,17 +2719,17 @@ int ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
}
if (dn == dst) {
if (dn >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
+ __set_errno(EMSGSIZE);
+ return -1;
}
*dn++ = '.';
}
if (dn >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
+ __set_errno(EMSGSIZE);
+ return -1;
}
*dn++ = '\0';
- return (dn - dst);
+ return (dn - dst);
}
libc_hidden_def(ns_name_ntop)
@@ -2661,59 +2752,60 @@ int ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
srcp = src;
dstlim = dst + dstsiz;
if (srcp < msg || srcp >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
+ __set_errno(EMSGSIZE);
+ return -1;
}
/* Fetch next label in domain name. */
while ((n = *srcp++) != 0) {
/* Check for indirection. */
switch (n & NS_CMPRSFLGS) {
- case 0:
- /* Limit checks. */
- if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
- }
- checked += n + 1;
- *dstp++ = n;
- memcpy(dstp, srcp, n);
- dstp += n;
- srcp += n;
- break;
+ case 0:
+ /* Limit checks. */
+ if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
+ __set_errno(EMSGSIZE);
+ return -1;
+ }
+ checked += n + 1;
+ *dstp++ = n;
+ memcpy(dstp, srcp, n);
+ dstp += n;
+ srcp += n;
+ break;
- case NS_CMPRSFLGS:
- if (srcp >= eom) {
- __set_errno (EMSGSIZE);
- return (-1);
- }
- if (len < 0)
- len = srcp - src + 1;
- srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
- if (srcp < msg || srcp >= eom) { /* Out of range. */
- __set_errno (EMSGSIZE);
- return (-1);
- }
- checked += 2;
- /*
- * Check for loops in the compressed name;
- * if we've looked at the whole message,
- * there must be a loop.
- */
- if (checked >= eom - msg) {
- __set_errno (EMSGSIZE);
- return (-1);
- }
- break;
+ case NS_CMPRSFLGS:
+ if (srcp >= eom) {
+ __set_errno(EMSGSIZE);
+ return -1;
+ }
+ if (len < 0)
+ len = srcp - src + 1;
+ srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
+ if (srcp < msg || srcp >= eom) { /* Out of range. */
+ __set_errno(EMSGSIZE);
+ return -1;
+ }
+ checked += 2;
+ /*
+ * Check for loops in the compressed name;
+ * if we've looked at the whole message,
+ * there must be a loop.
+ */
+ if (checked >= eom - msg) {
+ __set_errno(EMSGSIZE);
+ return -1;
+ }
+ break;
- default:
- __set_errno (EMSGSIZE);
- return (-1); /* flag error */
+ default:
+ __set_errno(EMSGSIZE);
+ return -1; /* flag error */
}
}
*dstp = '\0';
if (len < 0)
len = srcp - src;
- return (len);
+ return len;
}
libc_hidden_def(ns_name_unpack)
#endif /* L_ns_name */
+/* vi: set sw=4 ts=4: */
diff --git a/libc/inet/rpc/Makefile.in b/libc/inet/rpc/Makefile.in
index af047c0df..2f1246b20 100644
--- a/libc/inet/rpc/Makefile.in
+++ b/libc/inet/rpc/Makefile.in
@@ -5,6 +5,8 @@
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
+CFLAGS-rpc := -fno-strict-aliasing
+
ifneq ($(UCLIBC_HAS_FULL_RPC),y)
# For now, only compile the stuff needed to do an NFS mount....
CSRC:= authunix_prot.c auth_none.c auth_unix.c bindresvport.c \
diff --git a/libc/inet/rpc/auth_unix.c b/libc/inet/rpc/auth_unix.c
index 80b60b56b..0654b51c1 100644
--- a/libc/inet/rpc/auth_unix.c
+++ b/libc/inet/rpc/auth_unix.c
@@ -56,7 +56,7 @@
# include <wchar.h>
#endif
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(sysconf)
libc_hidden_proto(getegid)
libc_hidden_proto(geteuid)
@@ -212,8 +212,7 @@ authunix_create_default (void)
list of groups to NGRPS members since the code in
authuxprot.c transforms a fixed array. Grrr. */
ret_auth = authunix_create (machname, uid, gid, MIN (NGRPS, len), gids);
- if (gids)
- free (gids);
+ free (gids);
return ret_auth;
}
libc_hidden_def(authunix_create_default)
diff --git a/libc/inet/rpc/bindresvport.c b/libc/inet/rpc/bindresvport.c
index 32055cdf6..3f266e6cc 100644
--- a/libc/inet/rpc/bindresvport.c
+++ b/libc/inet/rpc/bindresvport.c
@@ -40,7 +40,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(bind)
libc_hidden_proto(getpid)
diff --git a/libc/inet/rpc/clnt_generic.c b/libc/inet/rpc/clnt_generic.c
index 899a9dd0e..54bd0e914 100644
--- a/libc/inet/rpc/clnt_generic.c
+++ b/libc/inet/rpc/clnt_generic.c
@@ -40,10 +40,10 @@
#include <sys/socket.h>
#include <netdb.h>
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
libc_hidden_proto(clnttcp_create)
libc_hidden_proto(clntudp_create)
libc_hidden_proto(clntunix_create)
diff --git a/libc/inet/rpc/clnt_perror.c b/libc/inet/rpc/clnt_perror.c
index ef3ed2d30..89a31a2d6 100644
--- a/libc/inet/rpc/clnt_perror.c
+++ b/libc/inet/rpc/clnt_perror.c
@@ -51,8 +51,8 @@ static char sccsid[] = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
# define fputs(s, f) _IO_fputs (s, f)
#endif
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(sprintf)
libc_hidden_proto(__glibc_strerror_r)
libc_hidden_proto(fputs)
diff --git a/libc/inet/rpc/clnt_simple.c b/libc/inet/rpc/clnt_simple.c
index f9f18f3d4..745a50213 100644
--- a/libc/inet/rpc/clnt_simple.c
+++ b/libc/inet/rpc/clnt_simple.c
@@ -50,9 +50,9 @@ static char sccsid[] = "@(#)clnt_simple.c 1.35 87/08/11 Copyr 1984 Sun Micro";
#include <netdb.h>
#include <string.h>
-libc_hidden_proto(memcpy)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strncpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strncpy) */
libc_hidden_proto(close)
libc_hidden_proto(clntudp_create)
libc_hidden_proto(gethostbyname_r)
diff --git a/libc/inet/rpc/clnt_udp.c b/libc/inet/rpc/clnt_udp.c
index 9e3444069..1d7cb4863 100644
--- a/libc/inet/rpc/clnt_udp.c
+++ b/libc/inet/rpc/clnt_udp.c
@@ -62,7 +62,7 @@ libc_hidden_proto(fwprintf)
#include <sys/uio.h>
#endif
-libc_hidden_proto(memcmp)
+/* Experimentally off - libc_hidden_proto(memcmp) */
libc_hidden_proto(ioctl)
libc_hidden_proto(socket)
libc_hidden_proto(close)
diff --git a/libc/inet/rpc/clnt_unix.c b/libc/inet/rpc/clnt_unix.c
index 82f994e51..73be74288 100644
--- a/libc/inet/rpc/clnt_unix.c
+++ b/libc/inet/rpc/clnt_unix.c
@@ -63,8 +63,8 @@
libc_hidden_proto(fwprintf)
#endif
-libc_hidden_proto(strlen)
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(socket)
libc_hidden_proto(close)
libc_hidden_proto(getpid)
diff --git a/libc/inet/rpc/create_xid.c b/libc/inet/rpc/create_xid.c
index 3b90d7a48..e3ee4799b 100644
--- a/libc/inet/rpc/create_xid.c
+++ b/libc/inet/rpc/create_xid.c
@@ -31,14 +31,11 @@ libc_hidden_proto(gettimeofday)
/* The RPC code is not threadsafe, but new code should be threadsafe. */
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t createxid_lock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&createxid_lock)
-#define UNLOCK __pthread_mutex_unlock(&createxid_lock)
-
-static int is_initialized;
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
+
+
+static smallint is_initialized;
static struct drand48_data __rpc_lrand48_data;
u_long _create_xid (void) attribute_hidden;
@@ -46,7 +43,7 @@ u_long _create_xid (void)
{
unsigned long res;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (!is_initialized)
{
@@ -59,7 +56,7 @@ u_long _create_xid (void)
lrand48_r (&__rpc_lrand48_data, &res);
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return res;
}
diff --git a/libc/inet/rpc/getrpcent.c b/libc/inet/rpc/getrpcent.c
index 428fbcc31..186bd130f 100644
--- a/libc/inet/rpc/getrpcent.c
+++ b/libc/inet/rpc/getrpcent.c
@@ -7,23 +7,23 @@
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
- *
+ *
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- *
+ *
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
- *
+ *
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
- *
+ *
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
- *
+ *
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
@@ -44,11 +44,11 @@
#include <arpa/inet.h>
#include <errno.h>
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(fopen)
libc_hidden_proto(fclose)
libc_hidden_proto(atoi)
@@ -93,10 +93,8 @@ void endrpcent(void)
return;
if (d->stayopen)
return;
- if (d->current) {
- free(d->current);
- d->current = NULL;
- }
+ free(d->current);
+ d->current = NULL;
if (d->rpcf) {
fclose(d->rpcf);
d->rpcf = NULL;
@@ -115,8 +113,7 @@ void setrpcent(int f)
d->rpcf = fopen(RPCDB, "r");
else
rewind(d->rpcf);
- if (d->current)
- free(d->current);
+ free(d->current);
d->current = NULL;
d->stayopen |= f;
}
@@ -275,14 +272,11 @@ static struct rpcent *interpret(register struct rpcdata *d)
#if defined(__UCLIBC_HAS_REENTRANT_RPC__)
-#if defined(__UCLIBC_HAS_THREADS__)
-# include <pthread.h>
-static pthread_mutex_t rpcdata_lock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&rpcdata_lock)
-#define UNLOCK __pthread_mutex_unlock(&rpcdata_lock)
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
+
-static int __copy_rpcent(struct rpcent *r, struct rpcent *result_buf, char *buffer,
+static int __copy_rpcent(struct rpcent *r, struct rpcent *result_buf, char *buffer,
size_t buflen, struct rpcent **result)
{
size_t i, s;
@@ -298,7 +292,7 @@ static int __copy_rpcent(struct rpcent *r, struct rpcent *result_buf, char *buff
result_buf->r_number = r->r_number;
- /* copy the aliases ... need to not only copy the alias strings,
+ /* copy the aliases ... need to not only copy the alias strings,
* but the array of pointers to the alias strings */
i = 0;
while (r->r_aliases[i++]) ;
@@ -339,9 +333,9 @@ int getrpcbynumber_r(int number, struct rpcent *result_buf, char *buffer,
size_t buflen, struct rpcent **result)
{
int ret;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
ret = __copy_rpcent(getrpcbynumber(number), result_buf, buffer, buflen, result);
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return ret;
}
@@ -349,19 +343,19 @@ int getrpcbyname_r(const char *name, struct rpcent *result_buf, char *buffer,
size_t buflen, struct rpcent **result)
{
int ret;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
ret = __copy_rpcent(getrpcbyname(name), result_buf, buffer, buflen, result);
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return ret;
}
-int getrpcent_r(struct rpcent *result_buf, char *buffer,
+int getrpcent_r(struct rpcent *result_buf, char *buffer,
size_t buflen, struct rpcent **result)
{
int ret;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
ret = __copy_rpcent(getrpcent(), result_buf, buffer, buflen, result);
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return ret;
}
diff --git a/libc/inet/rpc/getrpcport.c b/libc/inet/rpc/getrpcport.c
index 82fa8d17a..0a57d1da9 100644
--- a/libc/inet/rpc/getrpcport.c
+++ b/libc/inet/rpc/getrpcport.c
@@ -48,7 +48,7 @@ static char sccsid[] = "@(#)getrpcport.c 1.3 87/08/11 SMI";
#include <rpc/pmap_clnt.h>
#include <sys/socket.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(pmap_getport)
libc_hidden_proto(gethostbyname_r)
diff --git a/libc/inet/rpc/pmap_rmt.c b/libc/inet/rpc/pmap_rmt.c
index a0aa22985..759534aa7 100644
--- a/libc/inet/rpc/pmap_rmt.c
+++ b/libc/inet/rpc/pmap_rmt.c
@@ -59,7 +59,7 @@ static char sccsid[] = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
#include <arpa/inet.h>
#define MAX_BROADCAST_SIZE 1400
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(ioctl)
libc_hidden_proto(perror)
libc_hidden_proto(socket)
diff --git a/libc/inet/rpc/rcmd.c b/libc/inet/rpc/rcmd.c
index ccab7d60a..fe00d6a78 100644
--- a/libc/inet/rpc/rcmd.c
+++ b/libc/inet/rpc/rcmd.c
@@ -87,14 +87,14 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94";
#endif
#include <sys/uio.h>
-libc_hidden_proto(memcmp)
-libc_hidden_proto(strcat)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strncmp)
-libc_hidden_proto(memmove)
+/* Experimentally off - libc_hidden_proto(memcmp) */
+/* Experimentally off - libc_hidden_proto(strcat) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strncmp) */
+/* Experimentally off - libc_hidden_proto(memmove) */
libc_hidden_proto(getpid)
libc_hidden_proto(socket)
libc_hidden_proto(close)
@@ -134,7 +134,7 @@ libc_hidden_proto(__h_errno_location)
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
libc_hidden_proto(__ctype_tolower_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
libc_hidden_proto(__ctype_tolower)
#endif
@@ -197,9 +197,7 @@ int rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
#ifdef __ARCH_USE_MMU__
tmphstbuf = alloca (hstbuflen);
#else
- if (tmphstbuf) {
- free(tmphstbuf);
- }
+ free(tmphstbuf);
tmphstbuf = malloc (hstbuflen);
#endif
}
@@ -411,9 +409,7 @@ int ruserok(rhost, superuser, ruser, luser)
#ifdef __ARCH_USE_MMU__
buffer = alloca (buflen);
#else
- if (buffer) {
- free(buffer);
- }
+ free(buffer);
buffer = malloc (buflen);
#endif
}
@@ -780,8 +776,7 @@ __ivaliduser2(hostf, raddr, luser, ruser, rhost)
}
}
- if (buf != NULL)
- free (buf);
+ free (buf);
return retval;
}
diff --git a/libc/inet/rpc/rexec.c b/libc/inet/rpc/rexec.c
index bbbaac645..2eb567ed2 100644
--- a/libc/inet/rpc/rexec.c
+++ b/libc/inet/rpc/rexec.c
@@ -42,9 +42,9 @@
#include <string.h>
#include <unistd.h>
-libc_hidden_proto(memset)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strncpy)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strncpy) */
libc_hidden_proto(read)
libc_hidden_proto(write)
libc_hidden_proto(close)
@@ -61,14 +61,13 @@ libc_hidden_proto(atoi)
libc_hidden_proto(connect)
libc_hidden_proto(accept)
libc_hidden_proto(listen)
+libc_hidden_proto(ruserpass)
#define SA_LEN(_x) __libc_sa_len((_x)->sa_family)
extern int __libc_sa_len (sa_family_t __af) __THROW attribute_hidden;
int rexecoptions;
char ahostbuf[NI_MAXHOST] attribute_hidden;
-extern int ruserpass(const char *host, const char **aname, const char **apass) attribute_hidden;
-libc_hidden_proto(ruserpass)
libc_hidden_proto(rexec_af)
int
@@ -87,7 +86,7 @@ rexec_af(char **ahost, int rport, const char *name, const char *pass, const char
snprintf(servbuff, sizeof(servbuff), "%d", ntohs(rport));
servbuff[sizeof(servbuff) - 1] = '\0';
- memset(&hints, 0, sizeof(hints));
+ memset(&hints, '\0', sizeof(hints));
hints.ai_family = af;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
@@ -104,6 +103,8 @@ rexec_af(char **ahost, int rport, const char *name, const char *pass, const char
}
else{
*ahost = NULL;
+ __set_errno (ENOENT);
+ return -1;
}
ruserpass(res0->ai_canonname, &name, &pass);
retry:
@@ -127,7 +128,8 @@ retry:
port = 0;
} else {
char num[32];
- int s2, sa2len;
+ int s2;
+ socklen_t sa2len;
s2 = socket(res0->ai_family, res0->ai_socktype, 0);
if (s2 < 0) {
@@ -153,7 +155,8 @@ retry:
(void) sprintf(num, "%u", port);
(void) write(s, num, strlen(num)+1);
{ socklen_t len = sizeof (from);
- s3 = accept(s2, (struct sockaddr *)&from, &len);
+ s3 = TEMP_FAILURE_RETRY (accept(s2, (struct sockaddr *)&from,
+ &len));
close(s2);
if (s3 < 0) {
perror("accept");
diff --git a/libc/inet/rpc/rpc_cmsg.c b/libc/inet/rpc/rpc_cmsg.c
index b47a67c71..3206aae55 100644
--- a/libc/inet/rpc/rpc_cmsg.c
+++ b/libc/inet/rpc/rpc_cmsg.c
@@ -45,7 +45,7 @@ static char sccsid[] = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
#include <sys/param.h>
#include <rpc/rpc.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(xdr_enum)
libc_hidden_proto(xdr_opaque)
libc_hidden_proto(xdr_u_int)
diff --git a/libc/inet/rpc/rpc_prot.c b/libc/inet/rpc/rpc_prot.c
index ebe6c3128..74658e654 100644
--- a/libc/inet/rpc/rpc_prot.c
+++ b/libc/inet/rpc/rpc_prot.c
@@ -89,7 +89,6 @@ xdr_des_block (XDR *xdrs, des_block *blkp)
/*
* XDR the MSG_ACCEPTED part of a reply message union
*/
-extern bool_t xdr_accepted_reply (XDR *xdrs, struct accepted_reply *ar);
libc_hidden_proto(xdr_accepted_reply)
bool_t
xdr_accepted_reply (XDR *xdrs, struct accepted_reply *ar)
@@ -117,7 +116,6 @@ libc_hidden_def(xdr_accepted_reply)
/*
* XDR the MSG_DENIED part of a reply message union
*/
-extern bool_t xdr_rejected_reply (XDR *xdrs, struct rejected_reply *rr);
libc_hidden_proto(xdr_rejected_reply)
bool_t
xdr_rejected_reply (XDR *xdrs, struct rejected_reply *rr)
diff --git a/libc/inet/rpc/rpc_thread.c b/libc/inet/rpc/rpc_thread.c
index b42fab6e0..2c7b8c1ea 100644
--- a/libc/inet/rpc/rpc_thread.c
+++ b/libc/inet/rpc/rpc_thread.c
@@ -18,7 +18,6 @@ libc_hidden_proto(__rpc_thread_svc_max_pollfd)
#ifdef __UCLIBC_HAS_THREADS__
#include <bits/libc-tsd.h>
-#include <bits/libc-lock.h>
/* Variable used in non-threaded applications or for the first thread. */
static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem;
@@ -72,7 +71,7 @@ __rpc_thread_variables (void)
if (tvp != NULL)
__libc_tsd_set (RPC_VARS, tvp);
else
- tvp = __libc_tsd_RPC_VARS;
+ tvp = __libc_tsd_get (RPC_VARS);
}
}
return tvp;
diff --git a/libc/inet/rpc/ruserpass.c b/libc/inet/rpc/ruserpass.c
index 97f1284b3..ad6e703c4 100644
--- a/libc/inet/rpc/ruserpass.c
+++ b/libc/inet/rpc/ruserpass.c
@@ -42,13 +42,13 @@
#include <string.h>
#include <unistd.h>
-libc_hidden_proto(strcat)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strcasecmp)
-libc_hidden_proto(strncasecmp)
+/* Experimentally off - libc_hidden_proto(strcat) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strcasecmp) */
+/* Experimentally off - libc_hidden_proto(strncasecmp) */
libc_hidden_proto(getenv)
libc_hidden_proto(printf)
libc_hidden_proto(fstat)
@@ -112,8 +112,8 @@ static const struct toktab {
};
-
-extern int ruserpass(const char *host, const char **aname, const char **apass);
+/* ruserpass - remote password check.
+ This function also exists in glibc but is undocumented */
libc_hidden_proto(ruserpass)
int ruserpass(const char *host, const char **aname, const char **apass)
{
diff --git a/libc/inet/rpc/svc.c b/libc/inet/rpc/svc.c
index d41d7644c..253c06379 100644
--- a/libc/inet/rpc/svc.c
+++ b/libc/inet/rpc/svc.c
@@ -46,7 +46,7 @@
#include <rpc/pmap_clnt.h>
#include <sys/poll.h>
-libc_hidden_proto(ffs)
+/* Experimentally off - libc_hidden_proto(ffs) */
libc_hidden_proto(pmap_set)
libc_hidden_proto(pmap_unset)
libc_hidden_proto(_authenticate)
diff --git a/libc/inet/rpc/svc_authux.c b/libc/inet/rpc/svc_authux.c
index ef8476784..64c911f93 100644
--- a/libc/inet/rpc/svc_authux.c
+++ b/libc/inet/rpc/svc_authux.c
@@ -46,7 +46,7 @@
#include <rpc/rpc.h>
#include <rpc/svc.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(printf)
libc_hidden_proto(xdrmem_create)
libc_hidden_proto(xdr_authunix_parms)
diff --git a/libc/inet/rpc/svc_simple.c b/libc/inet/rpc/svc_simple.c
index 075b930b1..72c272aa7 100644
--- a/libc/inet/rpc/svc_simple.c
+++ b/libc/inet/rpc/svc_simple.c
@@ -55,8 +55,8 @@ static char sccsid[] = "@(#)svc_simple.c 1.18 87/08/11 Copyr 1984 Sun Micro";
# define fputs(s, f) _IO_fputs (s, f)
#endif
-libc_hidden_proto(strdup)
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(strdup) */
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(asprintf)
libc_hidden_proto(fputs)
libc_hidden_proto(write)
diff --git a/libc/inet/rpc/svc_tcp.c b/libc/inet/rpc/svc_tcp.c
index 035119d7e..5e4667940 100644
--- a/libc/inet/rpc/svc_tcp.c
+++ b/libc/inet/rpc/svc_tcp.c
@@ -59,8 +59,8 @@ static char sccsid[] = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
# define fputs(s, f) _IO_fputs (s, f)
#endif
-libc_hidden_proto(memset)
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(socket)
libc_hidden_proto(close)
libc_hidden_proto(read)
diff --git a/libc/inet/rpc/svc_udp.c b/libc/inet/rpc/svc_udp.c
index d2ed68d1b..e2c97bdc5 100644
--- a/libc/inet/rpc/svc_udp.c
+++ b/libc/inet/rpc/svc_udp.c
@@ -60,9 +60,9 @@ static char sccsid[] = "@(#)svc_udp.c 1.24 87/08/11 Copyr 1984 Sun Micro";
libc_hidden_proto(fwprintf)
#endif
-libc_hidden_proto(memcmp)
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memcmp) */
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(perror)
libc_hidden_proto(socket)
libc_hidden_proto(close)
diff --git a/libc/inet/rpc/svc_unix.c b/libc/inet/rpc/svc_unix.c
index 1683bd3ba..2d7790450 100644
--- a/libc/inet/rpc/svc_unix.c
+++ b/libc/inet/rpc/svc_unix.c
@@ -55,9 +55,9 @@
# include <wchar.h>
#endif
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(socket)
libc_hidden_proto(close)
libc_hidden_proto(perror)
diff --git a/libc/inet/rpc/xdr.c b/libc/inet/rpc/xdr.c
index e8009910f..54e716176 100644
--- a/libc/inet/rpc/xdr.c
+++ b/libc/inet/rpc/xdr.c
@@ -56,7 +56,7 @@ static char sccsid[] = "@(#)xdr.c 1.35 87/08/12";
libc_hidden_proto(fwprintf)
#endif
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(fputs)
/*
diff --git a/libc/inet/rpc/xdr_array.c b/libc/inet/rpc/xdr_array.c
index 5f21fb29e..a2299b683 100644
--- a/libc/inet/rpc/xdr_array.c
+++ b/libc/inet/rpc/xdr_array.c
@@ -54,7 +54,7 @@ static char sccsid[] = "@(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro";
libc_hidden_proto(fwprintf)
#endif
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(fputs)
libc_hidden_proto(xdr_u_int)
diff --git a/libc/inet/rpc/xdr_mem.c b/libc/inet/rpc/xdr_mem.c
index 7613ffc2f..b7410c404 100644
--- a/libc/inet/rpc/xdr_mem.c
+++ b/libc/inet/rpc/xdr_mem.c
@@ -43,7 +43,7 @@
#include <limits.h>
#include <rpc/rpc.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
static bool_t xdrmem_getlong (XDR *, long *);
static bool_t xdrmem_putlong (XDR *, const long *);
diff --git a/libc/inet/rpc/xdr_rec.c b/libc/inet/rpc/xdr_rec.c
index 5f9e2b1fe..ac331c4d3 100644
--- a/libc/inet/rpc/xdr_rec.c
+++ b/libc/inet/rpc/xdr_rec.c
@@ -60,7 +60,7 @@
libc_hidden_proto(fwprintf)
#endif
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(fputs)
libc_hidden_proto(lseek)
diff --git a/libc/inet/rpc/xdr_reference.c b/libc/inet/rpc/xdr_reference.c
index 7201def7a..6282f9cb1 100644
--- a/libc/inet/rpc/xdr_reference.c
+++ b/libc/inet/rpc/xdr_reference.c
@@ -55,7 +55,7 @@ static char sccsid[] = "@(#)xdr_reference.c 1.11 87/08/11 SMI";
libc_hidden_proto(fwprintf)
#endif
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(xdr_bool)
libc_hidden_proto(fputs)
diff --git a/libc/inet/socketcalls.c b/libc/inet/socketcalls.c
index d684a3aaf..9211b01ce 100644
--- a/libc/inet/socketcalls.c
+++ b/libc/inet/socketcalls.c
@@ -193,7 +193,8 @@ libc_hidden_def(listen)
extern __typeof(recv) __libc_recv;
#ifdef __NR_recv
#define __NR___libc_recv __NR_recv
-_syscall4(ssize_t, __libc_recv, int, sockfd, __ptr_t, buffer, size_t, len, int, flags);
+_syscall4(ssize_t, __libc_recv, int, sockfd, __ptr_t, buffer, size_t, len,
+ int, flags);
#elif defined(__NR_socketcall)
/* recv, recvfrom added by bir7@leland.stanford.edu */
ssize_t __libc_recv(int sockfd, __ptr_t buffer, size_t len, int flags)
@@ -231,8 +232,8 @@ libc_hidden_weak(recv)
extern __typeof(recvfrom) __libc_recvfrom;
#ifdef __NR_recvfrom
#define __NR___libc_recvfrom __NR_recvfrom
-_syscall6(ssize_t, __libc_recvfrom, int, sockfd, __ptr_t, buffer, size_t, len, int, flags,
- struct sockaddr *, to, socklen_t *, tolen);
+_syscall6(ssize_t, __libc_recvfrom, int, sockfd, __ptr_t, buffer, size_t, len,
+ int, flags, struct sockaddr *, to, socklen_t *, tolen);
#elif defined(__NR_socketcall)
/* recv, recvfrom added by bir7@leland.stanford.edu */
ssize_t __libc_recvfrom(int sockfd, __ptr_t buffer, size_t len, int flags,
@@ -365,8 +366,8 @@ libc_hidden_weak(sendmsg)
extern __typeof(sendto) __libc_sendto;
#ifdef __NR_sendto
#define __NR___libc_sendto __NR_sendto
-_syscall6(ssize_t, __libc_sendto, int, sockfd, const void *, buffer, size_t, len,
- int, flags, const struct sockaddr *, to, socklen_t, tolen);
+_syscall6(ssize_t, __libc_sendto, int, sockfd, const void *, buffer,
+ size_t, len, int, flags, const struct sockaddr *, to, socklen_t, tolen);
#elif defined(__NR_socketcall)
/* send, sendto added by bir7@leland.stanford.edu */
ssize_t __libc_sendto(int sockfd, const void *buffer, size_t len, int flags,
diff --git a/libc/misc/Makefile.in b/libc/misc/Makefile.in
index 542859576..6c09d3142 100644
--- a/libc/misc/Makefile.in
+++ b/libc/misc/Makefile.in
@@ -12,6 +12,7 @@ include $(top_srcdir)libc/misc/assert/Makefile.in
include $(top_srcdir)libc/misc/ctype/Makefile.in
include $(top_srcdir)libc/misc/dirent/Makefile.in
include $(top_srcdir)libc/misc/error/Makefile.in
+include $(top_srcdir)libc/misc/elf/Makefile.in
include $(top_srcdir)libc/misc/file/Makefile.in
include $(top_srcdir)libc/misc/fnmatch/Makefile.in
include $(top_srcdir)libc/misc/ftw/Makefile.in
diff --git a/libc/misc/assert/__assert.c b/libc/misc/assert/__assert.c
index bd3b3a91d..7a2fa1dce 100644
--- a/libc/misc/assert/__assert.c
+++ b/libc/misc/assert/__assert.c
@@ -44,7 +44,7 @@ libc_hidden_proto(__assert)
#define ASSERT_SHOW_PROGNAME 1
-static int in_assert; /* bss inits to 0. */
+static smallint in_assert; /* bss inits to 0. */
void attribute_noreturn __assert(const char *assertion, const char * filename,
int linenumber, register const char * function)
diff --git a/libc/misc/ctype/ctype.c b/libc/misc/ctype/ctype.c
index d88b342fd..7c25a39fb 100644
--- a/libc/misc/ctype/ctype.c
+++ b/libc/misc/ctype/ctype.c
@@ -37,7 +37,7 @@
#include <locale.h>
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
@@ -278,7 +278,7 @@ IS_FUNC_BODY(xdigit);
#undef tolower
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_tolower_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_tolower)
#endif
libc_hidden_proto(tolower)
@@ -316,6 +316,7 @@ int tolower_l(int c, __locale_t l)
return __UCLIBC_CTYPE_IN_TO_DOMAIN(c) ? l->__ctype_tolower[c] : c;
}
libc_hidden_def(tolower_l)
+weak_alias (tolower_l, __tolower_l)
#endif
/**********************************************************************/
@@ -324,7 +325,7 @@ libc_hidden_def(tolower_l)
#undef toupper
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_toupper_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_toupper)
#endif
libc_hidden_proto(toupper)
@@ -362,6 +363,7 @@ int toupper_l(int c, __locale_t l)
return __UCLIBC_CTYPE_IN_TO_DOMAIN(c) ? l->__ctype_toupper[c] : c;
}
libc_hidden_def(toupper_l)
+weak_alias (toupper_l, __toupper_l)
#endif
/**********************************************************************/
diff --git a/libc/misc/dirent/alphasort.c b/libc/misc/dirent/alphasort.c
index 533366222..70aa2a516 100644
--- a/libc/misc/dirent/alphasort.c
+++ b/libc/misc/dirent/alphasort.c
@@ -8,7 +8,7 @@
#include <string.h>
#include "dirstream.h"
-libc_hidden_proto(strcmp)
+/* Experimentally off - libc_hidden_proto(strcmp) */
int alphasort(const void * a, const void * b)
{
diff --git a/libc/misc/dirent/alphasort64.c b/libc/misc/dirent/alphasort64.c
index 86a91095d..de7a87a9a 100644
--- a/libc/misc/dirent/alphasort64.c
+++ b/libc/misc/dirent/alphasort64.c
@@ -10,7 +10,7 @@
#include <string.h>
#include "dirstream.h"
-libc_hidden_proto(strcmp)
+/* Experimentally off - libc_hidden_proto(strcmp) */
int alphasort64(const void * a, const void * b)
{
diff --git a/libc/misc/dirent/closedir.c b/libc/misc/dirent/closedir.c
index 0da001fce..b6419e11e 100644
--- a/libc/misc/dirent/closedir.c
+++ b/libc/misc/dirent/closedir.c
@@ -30,10 +30,10 @@ int closedir(DIR * dir)
__set_errno(EBADF);
return -1;
}
- __pthread_mutex_lock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
fd = dir->dd_fd;
dir->dd_fd = -1;
- __pthread_mutex_unlock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
free(dir->dd_buf);
free(dir);
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
diff --git a/libc/misc/dirent/dirstream.h b/libc/misc/dirent/dirstream.h
index a90ca6312..761111b9e 100644
--- a/libc/misc/dirent/dirstream.h
+++ b/libc/misc/dirent/dirstream.h
@@ -26,9 +26,8 @@ Cambridge, MA 02139, USA. */
#include <features.h>
#include <sys/types.h>
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-#endif
+
+#include <bits/uClibc_mutex.h>
/* For now, syscall readdir () only supports one entry at a time. It
* will be changed in the future.
@@ -63,11 +62,7 @@ struct __dirstream {
size_t dd_max;
/* lock */
-#ifdef __UCLIBC_HAS_THREADS__
- pthread_mutex_t dd_lock;
-#else
- void *dd_lock;
-#endif
+ __UCLIBC_MUTEX(dd_lock);
}; /* stream data from opendir() */
diff --git a/libc/misc/dirent/readdir.c b/libc/misc/dirent/readdir.c
index 6fb1146eb..2fb7a7246 100644
--- a/libc/misc/dirent/readdir.c
+++ b/libc/misc/dirent/readdir.c
@@ -25,7 +25,7 @@ struct dirent *readdir(DIR * dir)
return NULL;
}
- __pthread_mutex_lock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
do {
if (dir->dd_size <= dir->dd_nextloc) {
@@ -51,7 +51,7 @@ struct dirent *readdir(DIR * dir)
} while (de->d_ino == 0);
all_done:
- __pthread_mutex_unlock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
return de;
}
libc_hidden_def(readdir)
diff --git a/libc/misc/dirent/readdir64.c b/libc/misc/dirent/readdir64.c
index 5386ee17e..36dc35379 100644
--- a/libc/misc/dirent/readdir64.c
+++ b/libc/misc/dirent/readdir64.c
@@ -25,7 +25,7 @@ struct dirent64 *readdir64(DIR * dir)
return NULL;
}
- __pthread_mutex_lock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
do {
if (dir->dd_size <= dir->dd_nextloc) {
@@ -51,7 +51,7 @@ struct dirent64 *readdir64(DIR * dir)
} while (de->d_ino == 0);
all_done:
- __pthread_mutex_unlock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
return de;
}
diff --git a/libc/misc/dirent/readdir64_r.c b/libc/misc/dirent/readdir64_r.c
index b42351702..193d9196d 100644
--- a/libc/misc/dirent/readdir64_r.c
+++ b/libc/misc/dirent/readdir64_r.c
@@ -14,7 +14,7 @@
#include <dirent.h>
#include "dirstream.h"
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(readdir64_r)
int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result)
@@ -29,7 +29,7 @@ int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result)
}
de = NULL;
- __pthread_mutex_lock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
do {
if (dir->dd_size <= dir->dd_nextloc) {
@@ -37,7 +37,7 @@ int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result)
bytes = __getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
if (bytes <= 0) {
*result = NULL;
- ret = errno;
+ ret = (bytes==0)? 0 : errno;
goto all_done;
}
dir->dd_size = bytes;
@@ -63,7 +63,7 @@ int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result)
all_done:
- __pthread_mutex_unlock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
return((de != NULL)? 0 : ret);
}
libc_hidden_def(readdir64_r)
diff --git a/libc/misc/dirent/readdir_r.c b/libc/misc/dirent/readdir_r.c
index 2c44707f2..194af621f 100644
--- a/libc/misc/dirent/readdir_r.c
+++ b/libc/misc/dirent/readdir_r.c
@@ -11,7 +11,7 @@
#include <dirent.h>
#include "dirstream.h"
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(readdir_r)
int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
@@ -26,7 +26,7 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
}
de = NULL;
- __pthread_mutex_lock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
do {
if (dir->dd_size <= dir->dd_nextloc) {
@@ -34,7 +34,7 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
bytes = __getdents(dir->dd_fd, dir->dd_buf, dir->dd_max);
if (bytes <= 0) {
*result = NULL;
- ret = errno;
+ ret = (bytes==0)? 0 : errno;
goto all_done;
}
dir->dd_size = bytes;
@@ -60,8 +60,7 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
all_done:
- __pthread_mutex_unlock(&(dir->dd_lock));
-
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
return((de != NULL)? 0 : ret);
}
libc_hidden_def(readdir_r)
diff --git a/libc/misc/dirent/rewinddir.c b/libc/misc/dirent/rewinddir.c
index 516700183..1bbda0809 100644
--- a/libc/misc/dirent/rewinddir.c
+++ b/libc/misc/dirent/rewinddir.c
@@ -18,8 +18,8 @@ void rewinddir(DIR * dir)
__set_errno(EBADF);
return;
}
- __pthread_mutex_lock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
lseek(dir->dd_fd, 0, SEEK_SET);
dir->dd_nextoff = dir->dd_nextloc = dir->dd_size = 0;
- __pthread_mutex_unlock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
}
diff --git a/libc/misc/dirent/scandir.c b/libc/misc/dirent/scandir.c
index 41491baee..0e823ad98 100644
--- a/libc/misc/dirent/scandir.c
+++ b/libc/misc/dirent/scandir.c
@@ -12,7 +12,7 @@
#include <sys/types.h>
#include "dirstream.h"
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(readdir)
libc_hidden_proto(opendir)
libc_hidden_proto(closedir)
diff --git a/libc/misc/dirent/scandir64.c b/libc/misc/dirent/scandir64.c
index 7b1dbd000..98433f46d 100644
--- a/libc/misc/dirent/scandir64.c
+++ b/libc/misc/dirent/scandir64.c
@@ -30,7 +30,7 @@
#include <sys/types.h>
#include "dirstream.h"
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(opendir)
libc_hidden_proto(closedir)
libc_hidden_proto(qsort)
diff --git a/libc/misc/dirent/seekdir.c b/libc/misc/dirent/seekdir.c
index ba25ffd40..c41844856 100644
--- a/libc/misc/dirent/seekdir.c
+++ b/libc/misc/dirent/seekdir.c
@@ -17,8 +17,8 @@ void seekdir(DIR * dir, long int offset)
__set_errno(EBADF);
return;
}
- __pthread_mutex_lock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
dir->dd_nextoff = lseek(dir->dd_fd, offset, SEEK_SET);
dir->dd_size = dir->dd_nextloc = 0;
- __pthread_mutex_unlock(&(dir->dd_lock));
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
}
diff --git a/libc/misc/error/err.c b/libc/misc/error/err.c
index cd331500a..ab9c8b72b 100644
--- a/libc/misc/error/err.c
+++ b/libc/misc/error/err.c
@@ -19,6 +19,8 @@
#warning REMINDER: Deal with wide oriented stderr case.
#endif
+#if defined __USE_BSD
+
libc_hidden_proto(vwarn)
libc_hidden_proto(vwarnx)
libc_hidden_proto(verr)
@@ -124,3 +126,4 @@ void attribute_noreturn errx(int status, const char *format, ...)
while(1)
va_end(args);
}
+#endif
diff --git a/libc/misc/error/error.c b/libc/misc/error/error.c
index 08044ac83..ed4a62ef6 100644
--- a/libc/misc/error/error.c
+++ b/libc/misc/error/error.c
@@ -26,8 +26,8 @@
#include <string.h>
#include <error.h>
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strerror)
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strerror) */
libc_hidden_proto(fprintf)
libc_hidden_proto(exit)
libc_hidden_proto(putc)
@@ -44,7 +44,7 @@ int error_one_per_line;
/* If NULL, error will flush stdout, then print on stderr the program
name, a colon and a space. Otherwise, error will call this
function without parameters instead. */
-/* void (*error_print_progname) (void) = NULL; */
+void (*error_print_progname) (void) = NULL;
extern __typeof(error) __error attribute_hidden;
void __error (int status, int errnum, const char *message, ...)
@@ -53,6 +53,11 @@ void __error (int status, int errnum, const char *message, ...)
fflush (stdout);
+ if (error_print_progname)
+ (*error_print_progname) ();
+ else
+ fprintf (stderr, "%s: ", __uclibc_progname);
+
va_start (args, message);
vfprintf (stderr, message, args);
va_end (args);
@@ -87,6 +92,11 @@ void __error_at_line (int status, int errnum, const char *file_name,
fflush (stdout);
+ if (error_print_progname)
+ (*error_print_progname) ();
+ else
+ fprintf (stderr, "%s:", __uclibc_progname);
+
if (file_name != NULL)
fprintf (stderr, "%s:%d: ", file_name, line_number);
diff --git a/libc/misc/file/lockf.c b/libc/misc/file/lockf.c
index 6c1184be2..13b56aba4 100644
--- a/libc/misc/file/lockf.c
+++ b/libc/misc/file/lockf.c
@@ -26,7 +26,7 @@
libc_hidden_proto(lockf)
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(fcntl)
libc_hidden_proto(getpid)
diff --git a/libc/misc/file/lockf64.c b/libc/misc/file/lockf64.c
index 48983d448..b2ffe5d8c 100644
--- a/libc/misc/file/lockf64.c
+++ b/libc/misc/file/lockf64.c
@@ -37,7 +37,7 @@ libc_hidden_proto(fcntl64)
libc_hidden_proto(fcntl)
#endif
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(getpid)
/* lockf is a simplified interface to fcntl's locking facilities. */
diff --git a/libc/misc/fnmatch/fnmatch.c b/libc/misc/fnmatch/fnmatch.c
index 2d957772f..8592d4cf6 100644
--- a/libc/misc/fnmatch/fnmatch.c
+++ b/libc/misc/fnmatch/fnmatch.c
@@ -41,6 +41,7 @@
#include <errno.h>
#include <fnmatch.h>
#include <ctype.h>
+#include <unistd.h>
#if HAVE_STRING_H || defined _LIBC
# include <string.h>
@@ -54,19 +55,19 @@
#ifdef __UCLIBC__
#define __memset memset
-libc_hidden_proto(memchr)
-libc_hidden_proto(memset)
-libc_hidden_proto(mempcpy)
-libc_hidden_proto(strcat)
-libc_hidden_proto(strcmp)
+/* Experimentally off - libc_hidden_proto(memchr) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(mempcpy) */
+/* Experimentally off - libc_hidden_proto(strcat) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
/*libc_hidden_proto(strchr)*/
/*libc_hidden_proto(strchrnul)*/
-libc_hidden_proto(strlen)
-libc_hidden_proto(strcoll)
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strcoll) */
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
libc_hidden_proto(__ctype_tolower_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
libc_hidden_proto(__ctype_tolower)
#endif
@@ -211,7 +212,7 @@ extern int errno;
# endif
/* Global variable. */
-static int posixly_correct;
+static smallint posixly_correct;
/* This function doesn't exist on most systems. */
diff --git a/libc/misc/fnmatch/fnmatch_loop.c b/libc/misc/fnmatch/fnmatch_loop.c
index 191cef50c..af41727c0 100644
--- a/libc/misc/fnmatch/fnmatch_loop.c
+++ b/libc/misc/fnmatch/fnmatch_loop.c
@@ -29,12 +29,8 @@ 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;
+FCT (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;
diff --git a/libc/misc/ftw/ftw.c b/libc/misc/ftw/ftw.c
index 6521b44e4..81944ce98 100644
--- a/libc/misc/ftw/ftw.c
+++ b/libc/misc/ftw/ftw.c
@@ -83,9 +83,9 @@ char *alloca ();
# include <sys/stat.h>
#endif
-libc_hidden_proto(memset)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(dirfd)
libc_hidden_proto(tsearch)
libc_hidden_proto(tfind)
@@ -93,7 +93,7 @@ libc_hidden_proto(tdestroy)
libc_hidden_proto(getcwd)
libc_hidden_proto(chdir)
libc_hidden_proto(fchdir)
-libc_hidden_proto(mempcpy)
+/* Experimentally off - libc_hidden_proto(mempcpy) */
libc_hidden_proto(opendir)
#ifdef __UCLIBC_HAS_LFS__
libc_hidden_proto(readdir64)
@@ -101,7 +101,7 @@ libc_hidden_proto(lstat64)
libc_hidden_proto(stat64)
#endif
libc_hidden_proto(closedir)
-libc_hidden_proto(stpcpy)
+/* Experimentally off - libc_hidden_proto(stpcpy) */
libc_hidden_proto(lstat)
libc_hidden_proto(stat)
@@ -776,21 +776,14 @@ ftw_startup (const char *dir, int is_nftw, void *func, int descriptors,
/* Entry points. */
int
-FTW_NAME (path, func, descriptors)
- const char *path;
- FTW_FUNC_T func;
- int descriptors;
+FTW_NAME (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;
+NFTW_NAME (const char *path, NFTW_FUNC_T func, int descriptors, int flags)
{
return ftw_startup (path, 1, func, descriptors, flags);
}
@@ -801,11 +794,7 @@ NFTW_NAME (path, func, descriptors, flags)
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;
+NFTW_NEW_NAME (const char *path, NFTW_FUNC_T func, int descriptors, int flags)
{
if (flags
& ~(FTW_PHYS | FTW_MOUNT | FTW_CHDIR | FTW_DEPTH | FTW_ACTIONRETVAL))
@@ -826,11 +815,7 @@ 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;
+NFTW_OLD_NAME (const char *path, NFTW_FUNC_T func, int descriptors, int flags)
{
flags &= (FTW_PHYS | FTW_MOUNT | FTW_CHDIR | FTW_DEPTH);
return ftw_startup (path, 1, func, descriptors, flags);
diff --git a/libc/misc/glob/glob-susv3.c b/libc/misc/glob/glob-susv3.c
index e5b48cac3..8f441ac68 100644
--- a/libc/misc/glob/glob-susv3.c
+++ b/libc/misc/glob/glob-susv3.c
@@ -23,12 +23,12 @@
#include <unistd.h>
#include <stdio.h>
-libc_hidden_proto(memcpy)
-libc_hidden_proto(strcat)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(strcat) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(opendir)
libc_hidden_proto(closedir)
libc_hidden_proto(qsort)
diff --git a/libc/misc/glob/glob.c b/libc/misc/glob/glob.c
index f510a7b52..8d3e3c450 100644
--- a/libc/misc/glob/glob.c
+++ b/libc/misc/glob/glob.c
@@ -33,17 +33,17 @@
libc_hidden_proto(closedir)
libc_hidden_proto(fnmatch)
-libc_hidden_proto(memcpy)
-libc_hidden_proto(mempcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(mempcpy) */
libc_hidden_proto(opendir)
libc_hidden_proto(qsort)
libc_hidden_proto(readdir)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcoll)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strdup)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strrchr)
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcoll) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strdup) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strrchr) */
#ifdef ENABLE_GLOB_TILDE_EXPANSION
@@ -361,7 +361,7 @@ static int glob_in_dir (const char *pattern, const char *directory, int flags,
{
const char *name;
size_t len;
-#if !defined COMPILE_GLOB64
+#if defined __UCLIBC_HAS_LFS__ && !defined COMPILE_GLOB64
struct dirent64 *d;
union
{
@@ -482,8 +482,7 @@ static int glob_in_dir (const char *pattern, const char *directory, int flags,
}
while (names != NULL)
{
- if (names->name != NULL)
- free (names->name);
+ free (names->name);
names = names->next;
}
return GLOB_NOSPACE;
diff --git a/libc/misc/gnu/obstack.c b/libc/misc/gnu/obstack.c
index 5fc031555..a2e0de63b 100644
--- a/libc/misc/gnu/obstack.c
+++ b/libc/misc/gnu/obstack.c
@@ -164,17 +164,18 @@ struct obstack *_obstack;
allocation fails. */
int
-_obstack_begin (h, size, alignment, chunkfun, freefun)
- struct obstack *h;
- int size;
- int alignment;
+_obstack_begin (
+ struct obstack *h,
+ int size,
+ int alignment,
# if defined __STDC__ && __STDC__
- POINTER (*chunkfun) (long);
- void (*freefun) (void *);
+ POINTER (*chunkfun) (long),
+ void (*freefun) (void *)
# else
- POINTER (*chunkfun) ();
- void (*freefun) ();
+ POINTER (*chunkfun) (),
+ void (*freefun) ()
# endif
+ )
{
register struct _obstack_chunk *chunk; /* points to new chunk */
@@ -222,18 +223,18 @@ _obstack_begin (h, size, alignment, chunkfun, freefun)
}
int
-_obstack_begin_1 (h, size, alignment, chunkfun, freefun, arg)
- struct obstack *h;
- int size;
- int alignment;
+_obstack_begin_1 (
+ struct obstack *h,
+ int size,
+ int alignment,
# if defined __STDC__ && __STDC__
- POINTER (*chunkfun) (POINTER, long);
- void (*freefun) (POINTER, POINTER);
+ POINTER (*chunkfun) (POINTER, long),
+ void (*freefun) (POINTER, POINTER),
# else
- POINTER (*chunkfun) ();
- void (*freefun) ();
+ POINTER (*chunkfun) (),
+ void (*freefun) (),
# endif
- POINTER arg;
+ POINTER arg)
{
register struct _obstack_chunk *chunk; /* points to new chunk */
@@ -288,9 +289,9 @@ _obstack_begin_1 (h, size, alignment, chunkfun, freefun, arg)
to the beginning of the new one. */
void
-_obstack_newchunk (h, length)
- struct obstack *h;
- int length;
+_obstack_newchunk (
+ struct obstack *h,
+ int length)
{
register struct _obstack_chunk *old_chunk = h->chunk;
register struct _obstack_chunk *new_chunk;
@@ -364,9 +365,9 @@ int _obstack_allocated_p (struct obstack *h, POINTER obj);
# endif
int
-_obstack_allocated_p (h, obj)
- struct obstack *h;
- POINTER obj;
+_obstack_allocated_p (
+ struct obstack *h,
+ POINTER obj)
{
register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
register struct _obstack_chunk *plp; /* point to previous chunk if any */
@@ -392,9 +393,9 @@ _obstack_allocated_p (h, obj)
This is the first one, called from non-ANSI code. */
void
-_obstack_free (h, obj)
- struct obstack *h;
- POINTER obj;
+_obstack_free (
+ struct obstack *h,
+ POINTER obj)
{
register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
register struct _obstack_chunk *plp; /* point to previous chunk if any */
@@ -426,9 +427,9 @@ _obstack_free (h, obj)
/* This function is used from ANSI code. */
void
-obstack_free (h, obj)
- struct obstack *h;
- POINTER obj;
+obstack_free (
+ struct obstack *h,
+ POINTER obj)
{
register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
register struct _obstack_chunk *plp; /* point to previous chunk if any */
@@ -458,8 +459,8 @@ obstack_free (h, obj)
}
int
-_obstack_memory_used (h)
- struct obstack *h;
+_obstack_memory_used (
+ struct obstack *h)
{
register struct _obstack_chunk* lp;
register int nbytes = 0;
@@ -490,7 +491,7 @@ _obstack_memory_used (h)
static void
attribute_noreturn
-print_and_abort ()
+print_and_abort (void)
{
/* Don't change any of these strings. Yes, it would be possible to add
the newline to the string and use fputs or so. But this must not
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
index 701e9efbf..189483395 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -1,4 +1,3 @@
-/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2006 by Steven J. Hill <sjhill@realitydiluted.com>
* Copyright (C) 2001 by Manuel Novoa III <mjn3@uclibc.org>
@@ -35,15 +34,16 @@
#include <errno.h>
#include <pthread-functions.h>
#include <not-cancel.h>
+#include <atomic.h>
#endif
libc_hidden_proto(exit)
#ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
-libc_hidden_proto(strrchr)
+/* Experimentally off - libc_hidden_proto(strrchr) */
#endif
-#ifdef __ARCH_USE_MMU__
-libc_hidden_proto(memcpy)
+#ifndef __ARCH_HAS_NO_LDSO__
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(getgid)
libc_hidden_proto(getuid)
libc_hidden_proto(getegid)
@@ -57,8 +57,6 @@ extern __typeof(fcntl) __libc_fcntl;
libc_hidden_proto(__libc_fcntl)
#endif
-#include <pthreadP.h>
-
#ifndef SHARED
void *__libc_stack_end=NULL;
@@ -108,7 +106,9 @@ extern void __pthread_initialize_minimal(void);
#endif
#endif
-#ifdef __UCLIBC_CTOR_DTOR__
+/* If __UCLIBC_FORMAT_SHARED_FLAT__, all array initialisation and finalisation
+ * is handled by the routines passed to __uClibc_main(). */
+#if defined (__UCLIBC_CTOR_DTOR__) && !defined (__UCLIBC_FORMAT_SHARED_FLAT__)
extern void _dl_app_init_array(void);
extern void _dl_app_fini_array(void);
# ifndef SHARED
@@ -136,7 +136,6 @@ weak_alias (program_invocation_name, __progname_full)
* Declare the __environ global variable and create a weak alias environ.
* This must be initialized; we cannot have a weak alias into bss.
*/
-
char **__environ = 0;
weak_alias(__environ, environ)
@@ -147,31 +146,22 @@ size_t __pagesize = 0;
# define O_NOFOLLOW 0
#endif
-#ifdef __ARCH_USE_MMU__
+#ifndef __ARCH_HAS_NO_LDSO__
static void __check_one_fd(int fd, int mode)
{
- /* Check if the specified fd is already open */
- if (unlikely(fcntl(fd, F_GETFD)==-1 && *(__errno_location())==EBADF))
+ /* Check if the specified fd is already open */
+ if (__libc_fcntl(fd, F_GETFD) == -1)
+ {
+ /* The descriptor is probably not open, so try to use /dev/null */
+ int nullfd = __libc_open(_PATH_DEVNULL, 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)
{
- /* The descriptor is probably not open, so try to use /dev/null */
- struct stat st;
-
-#ifndef __UCLIBC_HAS_THREADS_NATIVE__
- int nullfd = open(_PATH_DEVNULL, mode);
-#else
- int nullfd = open_not_cancel (_PATH_DEVNULL, mode, 0);
-#endif
-
- /* /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) ||
- (st.st_rdev != makedev(1, 3)))
- {
- /* Somebody is trying some trickery here... */
- abort();
- }
+ abort();
}
+ }
}
static int __check_suid(void)
@@ -181,13 +171,13 @@ static int __check_suid(void)
uid = getuid();
euid = geteuid();
+ if (uid != euid)
+ return 1;
gid = getgid();
egid = getegid();
-
- if(uid == euid && gid == egid) {
- return 0;
- }
- return 1;
+ if (gid != egid)
+ return 1;
+ return 0; /* we are not suid */
}
#endif
@@ -208,7 +198,7 @@ extern void __uClibc_init(void);
libc_hidden_proto(__uClibc_init)
void __uClibc_init(void)
{
- static int been_there_done_that = 0;
+ static smallint been_there_done_that;
if (been_there_done_that)
return;
@@ -256,6 +246,8 @@ void __uClibc_init(void)
/*
* Initialize stdio here. In the static library case, this will
* be bypassed if not needed because of the weak alias above.
+ * Thus we get a nice size savings because the stdio functions
+ * won't be pulled into the final static binary unless used.
*/
if (likely(_stdio_init != NULL))
_stdio_init();
@@ -274,9 +266,11 @@ libc_hidden_proto(__uClibc_fini)
void __uClibc_fini(void)
{
#ifdef __UCLIBC_CTOR_DTOR__
+ /* If __UCLIBC_FORMAT_SHARED_FLAT__, all array finalisation is handled
+ * by __app_fini. */
# ifdef SHARED
_dl_app_fini_array();
-# else
+# elif !defined (__UCLIBC_FORMAT_SHARED_FLAT__)
size_t i = __fini_array_end - __fini_array_start;
while (i-- > 0)
(*__fini_array_start [i]) ();
@@ -300,7 +294,7 @@ void __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)
{
-#ifdef __ARCH_USE_MMU__
+#ifndef __ARCH_HAS_NO_LDSO__
unsigned long *aux_dat;
ElfW(auxv_t) auxvt[AT_EGID + 1];
#endif
@@ -326,8 +320,9 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc,
__environ = &argv[argc];
}
-#ifdef __ARCH_USE_MMU__
+#ifndef __ARCH_HAS_NO_LDSO__
/* Pull stuff from the ELF header when possible */
+ memset(auxvt, 0x00, sizeof(auxvt));
aux_dat = (unsigned long*)__environ;
while (*aux_dat) {
aux_dat++;
@@ -353,7 +348,7 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc,
* __uClibc_init() regardless, to be sure the right thing happens. */
__uClibc_init();
-#ifdef __ARCH_USE_MMU__
+#ifndef __ARCH_HAS_NO_LDSO__
/* Make certain getpagesize() gives the correct answer */
__pagesize = (auxvt[AT_PAGESZ].a_un.a_val)? auxvt[AT_PAGESZ].a_un.a_val : PAGE_SIZE;
@@ -370,22 +365,25 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc,
}
#endif
-#ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
- __progname_full = *argv;
- __progname = strrchr(*argv, '/');
- if (__progname != NULL)
- ++__progname;
- else
- __progname = __progname_full;
-#else
__uclibc_progname = *argv;
+#ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
+ if (*argv != NULL) {
+ program_invocation_name = *argv;
+ program_invocation_short_name = strrchr(*argv, '/');
+ if (program_invocation_short_name != NULL)
+ ++program_invocation_short_name;
+ else
+ program_invocation_short_name = program_invocation_name;
+ }
#endif
#ifdef __UCLIBC_CTOR_DTOR__
/* Arrange for the application's dtors to run before we exit. */
__app_fini = app_fini;
-# ifndef SHARED
+ /* If __UCLIBC_FORMAT_SHARED_FLAT__, all array initialisation is handled
+ * by __app_init. */
+# if !defined (SHARED) && !defined (__UCLIBC_FORMAT_SHARED_FLAT__)
/* For dynamically linked executables the preinit array is executed by
the dynamic linker (before initializing any shared object).
For static executables, preinit happens rights before init. */
@@ -400,9 +398,11 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc,
if (app_init!=NULL) {
app_init();
}
+ /* If __UCLIBC_FORMAT_SHARED_FLAT__, all array initialisation is handled
+ * by __app_init. */
# ifdef SHARED
_dl_app_init_array();
-# else
+# elif !defined (__UCLIBC_FORMAT_SHARED_FLAT__)
{
const size_t size = __init_array_end - __init_array_start;
size_t i;
diff --git a/libc/misc/locale/locale.c b/libc/misc/locale/locale.c
index b782d5ead..9825798ed 100644
--- a/libc/misc/locale/locale.c
+++ b/libc/misc/locale/locale.c
@@ -58,14 +58,14 @@
#include <ctype.h>
#include <stdio.h>
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
-libc_hidden_proto(strtok_r)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strncmp)
-libc_hidden_proto(strchr)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strtok_r) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strncmp) */
+/* Experimentally off - libc_hidden_proto(strchr) */
libc_hidden_proto(getenv)
#ifdef __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__C_ctype_toupper)
@@ -193,7 +193,7 @@ static const char utf8[] = "UTF-8";
*/
static char hr_locale[(MAX_LOCALE_CATEGORY_STR * LC_ALL) + MAX_LOCALE_STR];
-libc_hidden_proto(stpcpy)
+/* Experimentally off - libc_hidden_proto(stpcpy) */
libc_hidden_proto(newlocale)
static void update_hr_locale(const unsigned char *spec)
@@ -1084,7 +1084,7 @@ libc_hidden_def(__XL_NPP(nl_langinfo))
/**********************************************************************/
#ifdef L_newlocale
-libc_hidden_proto(stpcpy)
+/* Experimentally off - libc_hidden_proto(stpcpy) */
libc_hidden_proto(newlocale)
#ifdef __UCLIBC_MJN3_ONLY__
@@ -1142,7 +1142,7 @@ static int find_locale(int category_mask, const char *p,
/* TODO: maybe CODESET_LIST + *s ??? */
/* 7bit is 1, UTF-8 is 2, 8-bit is >= 3 */
codeset = 2;
- if (strcmp(utf8,p+6) != 0) {/* TODO - fix! */
+ if (strcasecmp(utf8,p+6) != 0) {/* TODO - fix! */
s = CODESET_LIST;
do {
++codeset; /* Increment codeset first. */
diff --git a/libc/misc/mntent/mntent.c b/libc/misc/mntent/mntent.c
index 3164f6634..c3367955c 100644
--- a/libc/misc/mntent/mntent.c
+++ b/libc/misc/mntent/mntent.c
@@ -8,13 +8,16 @@
#include <stdlib.h>
#include <string.h>
#include <mntent.h>
+#include <bits/uClibc_mutex.h>
+
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
libc_hidden_proto(getmntent_r)
libc_hidden_proto(setmntent)
libc_hidden_proto(endmntent)
-libc_hidden_proto(strstr)
-libc_hidden_proto(strtok_r)
+/* Experimentally off - libc_hidden_proto(strstr) */
+/* Experimentally off - libc_hidden_proto(strtok_r) */
libc_hidden_proto(atoi)
libc_hidden_proto(fopen)
libc_hidden_proto(fclose)
@@ -23,13 +26,6 @@ libc_hidden_proto(fgets)
libc_hidden_proto(abort)
libc_hidden_proto(fprintf)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
-
/* Reentrant version of getmntent. */
struct mntent *getmntent_r (FILE *filep,
struct mntent *mnt, char *buff, int bufsize)
@@ -85,7 +81,7 @@ struct mntent *getmntent(FILE * filep)
struct mntent *tmp;
static char *buff = NULL;
static struct mntent mnt;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (!buff) {
buff = malloc(BUFSIZ);
@@ -94,7 +90,7 @@ struct mntent *getmntent(FILE * filep)
}
tmp = getmntent_r(filep, &mnt, buff, BUFSIZ);
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return(tmp);
}
@@ -103,11 +99,8 @@ int addmntent(FILE * filep, const struct mntent *mnt)
if (fseek(filep, 0, SEEK_END) < 0)
return 1;
- if (fprintf (filep, "%s %s %s %s %d %d\n", mnt->mnt_fsname, mnt->mnt_dir,
- mnt->mnt_type, mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno) < 1)
- return 1;
-
- return 0;
+ return (fprintf (filep, "%s %s %s %s %d %d\n", mnt->mnt_fsname, mnt->mnt_dir,
+ mnt->mnt_type, mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno) < 0 ? 1 : 0);
}
char *hasmntopt(const struct mntent *mnt, const char *opt)
diff --git a/libc/misc/pthread/weaks.c b/libc/misc/pthread/weaks.c
index 1d4f05d05..580c3eb07 100644
--- a/libc/misc/pthread/weaks.c
+++ b/libc/misc/pthread/weaks.c
@@ -17,7 +17,6 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#define _GNU_SOURCE
#include <libc-internal.h>
/* Weaks for internal library use only.
@@ -29,17 +28,15 @@
* if it gets linked in.
*/
-static int __pthread_return_0 (void);
static int __pthread_return_0 (void) { return 0; }
+static void __pthread_return_void (void) { return; }
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_cleanup_push_defer)
-weak_alias (__pthread_return_0, _pthread_cleanup_pop_restore)
-
+weak_alias (__pthread_return_void, _pthread_cleanup_push_defer)
+weak_alias (__pthread_return_void, _pthread_cleanup_pop_restore)
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
weak_alias (__pthread_return_0, __pthread_mutexattr_init)
weak_alias (__pthread_return_0, __pthread_mutexattr_destroy)
diff --git a/libc/misc/regex/regex.c b/libc/misc/regex/regex.c
index f39492bdf..10229a265 100644
--- a/libc/misc/regex/regex.c
+++ b/libc/misc/regex/regex.c
@@ -69,7 +69,7 @@ libc_hidden_proto(wctype)
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
libc_hidden_proto(__ctype_toupper_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
libc_hidden_proto(__ctype_toupper)
#else
@@ -77,19 +77,19 @@ libc_hidden_proto(isascii)
#endif
libc_hidden_proto(toupper)
libc_hidden_proto(tolower)
-libc_hidden_proto(memcmp)
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memmove)
-libc_hidden_proto(memset)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strncpy)
+/* Experimentally off - libc_hidden_proto(memcmp) */
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memmove) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strncpy) */
libc_hidden_proto(getenv)
-libc_hidden_proto(strcasecmp)
+/* Experimentally off - libc_hidden_proto(strcasecmp) */
libc_hidden_proto(abort)
#ifdef __USE_GNU
-libc_hidden_proto(mempcpy)
+/* Experimentally off - libc_hidden_proto(mempcpy) */
#endif
#endif
diff --git a/libc/misc/regex/regex_internal.h b/libc/misc/regex/regex_internal.h
index a0dd28247..af38acc42 100644
--- a/libc/misc/regex/regex_internal.h
+++ b/libc/misc/regex/regex_internal.h
@@ -386,7 +386,7 @@ static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
internal_function;
#ifdef RE_ENABLE_I18N
static void build_wcs_buffer (re_string_t *pstr) internal_function;
-static int build_wcs_upper_buffer (re_string_t *pstr) internal_function;
+static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr) internal_function;
#endif /* RE_ENABLE_I18N */
static void build_upper_buffer (re_string_t *pstr) internal_function;
static void re_string_translate_buffer (re_string_t *pstr) internal_function;
diff --git a/libc/misc/regex/regex_old.c b/libc/misc/regex/regex_old.c
index cf5843ec5..dc5781967 100644
--- a/libc/misc/regex/regex_old.c
+++ b/libc/misc/regex/regex_old.c
@@ -35,17 +35,18 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#include <unistd.h>
#include <stdio.h>
-libc_hidden_proto(memset)
-libc_hidden_proto(memcmp)
-libc_hidden_proto(memcpy)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(memcmp) */
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(printf)
libc_hidden_proto(abort)
#ifdef __USE_GNU
-libc_hidden_proto(mempcpy)
+/* Experimentally off - libc_hidden_proto(mempcpy) */
#endif
/* AIX requires this to be the first thing in the file. */
@@ -794,7 +795,7 @@ PREFIX(extract_number_and_incr) (destination, source)
/* It is useful to test things that ``must'' be true when debugging. */
# include <assert.h>
-static int debug;
+static smallint debug;
# define DEBUG_STATEMENT(e) e
# define DEBUG_PRINT1(x) if (debug) printf (x)
@@ -5128,7 +5129,7 @@ strong_alias(__re_search_2, re_search_2)
#ifdef MATCH_MAY_ALLOCATE
# define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL
#else
-# define FREE_VAR(var) if (var) free (var); var = NULL
+# define FREE_VAR(var) free (var); var = NULL
#endif
#ifdef WCHAR
@@ -8309,20 +8310,17 @@ void
regfree (preg)
regex_t *preg;
{
- if (preg->buffer != NULL)
- free (preg->buffer);
+ free (preg->buffer);
preg->buffer = NULL;
preg->allocated = 0;
preg->used = 0;
- if (preg->fastmap != NULL)
- free (preg->fastmap);
+ free (preg->fastmap);
preg->fastmap = NULL;
preg->fastmap_accurate = 0;
- if (preg->translate != NULL)
- free (preg->translate);
+ free (preg->translate);
preg->translate = NULL;
}
#if defined _LIBC || defined __UCLIBC__
diff --git a/libc/misc/search/_hsearch_r.c b/libc/misc/search/_hsearch_r.c
index a1cdbb681..c9c4a9ccf 100644
--- a/libc/misc/search/_hsearch_r.c
+++ b/libc/misc/search/_hsearch_r.c
@@ -110,9 +110,8 @@ void hdestroy_r (struct hsearch_data *htab)
return;
}
- if (htab->table != NULL)
- /* free used memory */
- free (htab->table);
+ /* free used memory */
+ free (htab->table);
/* the sign for an existing table is an value != NULL in htable */
htab->table = NULL;
@@ -135,8 +134,8 @@ libc_hidden_def(hdestroy_r)
equality of the stored and the parameter value. This helps to prevent
unnecessary expensive calls of strcmp. */
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(hsearch_r)
int hsearch_r (ENTRY item, ACTION action, ENTRY **retval,
diff --git a/libc/misc/search/_lsearch.c b/libc/misc/search/_lsearch.c
index eefef2121..6c3afcba1 100644
--- a/libc/misc/search/_lsearch.c
+++ b/libc/misc/search/_lsearch.c
@@ -34,7 +34,7 @@ libc_hidden_def(lfind)
#ifdef L_lsearch
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
void *lsearch(const void *key, void *base, size_t *nmemb,
size_t size, int (*compar)(const void *, const void *))
diff --git a/libc/misc/statfs/fstatfs64.c b/libc/misc/statfs/fstatfs64.c
index dd271e7a3..a7f94b125 100644
--- a/libc/misc/statfs/fstatfs64.c
+++ b/libc/misc/statfs/fstatfs64.c
@@ -25,7 +25,7 @@
#include <sys/statvfs.h>
#include <stddef.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(fstatfs)
/* Return information about the filesystem on which FD resides. */
diff --git a/libc/misc/statfs/fstatvfs.c b/libc/misc/statfs/fstatvfs.c
index c28132022..231d45207 100644
--- a/libc/misc/statfs/fstatvfs.c
+++ b/libc/misc/statfs/fstatvfs.c
@@ -27,14 +27,28 @@
#include <sys/statfs.h>
#include <sys/statvfs.h>
-libc_hidden_proto(memset)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strsep)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strsep) */
libc_hidden_proto(setmntent)
libc_hidden_proto(getmntent_r)
libc_hidden_proto(endmntent)
-libc_hidden_proto(fstatfs)
+#if !defined __UCLIBC_LINUX_SPECIFIC__
+#ifndef __USE_FILE_OFFSET64
+extern int fstatfs (int __fildes, struct statfs *__buf)
+ __THROW __nonnull ((2));
+#else
+# ifdef __REDIRECT_NTH
+extern int __REDIRECT_NTH (fstatfs, (int __fildes, struct statfs *__buf),
+ fstatfs64) __nonnull ((2));
+# else
+# define fstatfs fstatfs64
+# endif
+#endif
+#endif
+extern __typeof(fstatfs) __libc_fstatfs;
+libc_hidden_proto(__libc_fstatfs)
libc_hidden_proto(fstat)
libc_hidden_proto(stat)
@@ -44,7 +58,7 @@ 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 (__libc_fstatfs (fd, &fsbuf) < 0)
return -1;
#define STAT(st) fstat (fd, st)
diff --git a/libc/misc/statfs/fstatvfs64.c b/libc/misc/statfs/fstatvfs64.c
index a37642e70..02e7011cf 100644
--- a/libc/misc/statfs/fstatvfs64.c
+++ b/libc/misc/statfs/fstatvfs64.c
@@ -28,9 +28,9 @@
#include <sys/statfs.h>
#include <sys/statvfs.h>
-libc_hidden_proto(memset)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strsep)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strsep) */
libc_hidden_proto(setmntent)
libc_hidden_proto(getmntent_r)
libc_hidden_proto(endmntent)
diff --git a/libc/misc/statfs/statfs64.c b/libc/misc/statfs/statfs64.c
index 8574c17af..18ce33be8 100644
--- a/libc/misc/statfs/statfs64.c
+++ b/libc/misc/statfs/statfs64.c
@@ -24,7 +24,7 @@
#include <sys/statfs.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(statfs)
/* Return information about the filesystem on which FILE resides. */
diff --git a/libc/misc/statfs/statvfs.c b/libc/misc/statfs/statvfs.c
index 6c3bf7c56..0feb8731d 100644
--- a/libc/misc/statfs/statvfs.c
+++ b/libc/misc/statfs/statvfs.c
@@ -27,14 +27,15 @@
#include <sys/statfs.h>
#include <sys/statvfs.h>
-libc_hidden_proto(memset)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strsep)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strsep) */
libc_hidden_proto(setmntent)
libc_hidden_proto(getmntent_r)
libc_hidden_proto(endmntent)
-libc_hidden_proto(statfs)
+extern __typeof(statfs) __libc_statfs;
+libc_hidden_proto(__libc_statfs)
libc_hidden_proto(stat)
int statvfs (const char *file, struct statvfs *buf)
@@ -43,7 +44,7 @@ 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 (__libc_statfs (file, &fsbuf) < 0)
return -1;
#define STAT(st) stat (file, st)
diff --git a/libc/misc/statfs/statvfs64.c b/libc/misc/statfs/statvfs64.c
index 4a71989ec..c91e1fe26 100644
--- a/libc/misc/statfs/statvfs64.c
+++ b/libc/misc/statfs/statvfs64.c
@@ -28,9 +28,9 @@
#include <sys/statfs.h>
#include <sys/statvfs.h>
-libc_hidden_proto(memset)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strsep)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strsep) */
libc_hidden_proto(setmntent)
libc_hidden_proto(getmntent_r)
libc_hidden_proto(endmntent)
diff --git a/libc/misc/syslog/syslog.c b/libc/misc/syslog/syslog.c
index 10b8e6e58..c90703ab8 100644
--- a/libc/misc/syslog/syslog.c
+++ b/libc/misc/syslog/syslog.c
@@ -84,14 +84,14 @@ libc_hidden_proto(syslog)
libc_hidden_proto(vsyslog)
libc_hidden_proto(closelog)
-libc_hidden_proto(memset)
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memmove)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strncpy)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memmove) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strncpy) */
libc_hidden_proto(open)
-/*libc_hidden_proto(fcntl)*/
+libc_hidden_proto(fcntl)
libc_hidden_proto(socket)
libc_hidden_proto(close)
libc_hidden_proto(write)
@@ -102,99 +102,91 @@ libc_hidden_proto(sigemptyset)
libc_hidden_proto(connect)
libc_hidden_proto(sprintf)
libc_hidden_proto(vsnprintf)
-libc_hidden_proto(time)
-
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
-
-
-static int LogFile = -1; /* fd for log */
-static int connected; /* have done connect */
-static int LogStat = 0; /* status bits, set by openlog() */
-static const char *LogTag = "syslog"; /* string to tag the entry with */
-static int LogFacility = LOG_USER; /* default facility code */
-static int LogMask = 0xff; /* mask of priorities to be logged */
-static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
-
-static void
-closelog_intern(int to_default)
+/* Experimentally off - libc_hidden_proto(time) */
+
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
+
+
+static int LogFile = -1; /* fd for log */
+static smalluint connected; /* have done connect */
+/* all bits in option argument for openlog() fit in 8 bits */
+static smalluint LogStat = 0; /* status bits, set by openlog() */
+static const char *LogTag = "syslog"; /* string to tag the entry with */
+/* this fits in 8 bits too (LOG_LOCAL7 = 23<<3 = 184),
+ * but NB: LOG_FACMASK is bigger (= 0x03f8 = 127<<3) for some strange reason.
+ * Oh well. */
+static int LogFacility = LOG_USER;/* default facility code */
+/* bits mask of priorities (eight prios - 8 bits is enough) */
+static smalluint LogMask = 0xff; /* mask of priorities to be logged */
+/* AF_UNIX address of local logger (we use struct sockaddr
+ * instead of struct sockaddr_un since "/dev/log" is small enough) */
+static const struct sockaddr SyslogAddr = {
+ .sa_family = AF_UNIX, /* sa_family_t (usually a short) */
+ .sa_data = _PATH_LOG /* char [14] */
+};
+
+static void
+closelog_intern(int sig)
{
- LOCK;
+ /* mylock must be held by the caller */
if (LogFile != -1) {
- (void) close(LogFile);
+ (void) close(LogFile);
}
LogFile = -1;
connected = 0;
- if (to_default)
- {
+ if (sig == 0) { /* called from closelog()? - reset to defaults */
LogStat = 0;
LogTag = "syslog";
LogFacility = LOG_USER;
LogMask = 0xff;
}
- UNLOCK;
-}
-
-static void
-sigpipe_handler (attribute_unused int sig)
-{
- closelog_intern (0);
}
/*
* OPENLOG -- open system log
*/
void
-openlog( const char *ident, int logstat, int logfac )
+openlog(const char *ident, int logstat, int logfac)
{
- int logType = SOCK_DGRAM;
-
- LOCK;
-
- if (ident != NULL)
- LogTag = ident;
- LogStat = logstat;
- if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
- LogFacility = logfac;
- if (LogFile == -1) {
- SyslogAddr.sa_family = AF_UNIX;
- (void)strncpy(SyslogAddr.sa_data, _PATH_LOG,
- sizeof(SyslogAddr.sa_data));
+ int logType = SOCK_DGRAM;
+
+ __UCLIBC_MUTEX_LOCK(mylock);
+
+ if (ident != NULL)
+ LogTag = ident;
+ LogStat = logstat;
+ if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
+ LogFacility = logfac;
+ if (LogFile == -1) {
retry:
- if (LogStat & LOG_NDELAY) {
- if ((LogFile = socket(AF_UNIX, logType, 0)) == -1){
- UNLOCK;
- return;
- }
- /* fcntl(LogFile, F_SETFD, 1); */
+ if (LogStat & LOG_NDELAY) {
+ if ((LogFile = socket(AF_UNIX, logType, 0)) == -1) {
+ goto DONE;
+ }
+ fcntl(LogFile, F_SETFD, 1); /* 1 == FD_CLOEXEC */
+ /* We don't want to block if e.g. syslogd is SIGSTOPed */
+ fcntl(LogFile, F_SETFL, O_NONBLOCK | fcntl(LogFile, F_GETFL));
+ }
}
- }
-
- if (LogFile != -1 && !connected) {
- if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr) -
- sizeof(SyslogAddr.sa_data) + strlen(SyslogAddr.sa_data)) != -1)
- {
- connected = 1;
- } else if (logType == SOCK_DGRAM) {
- logType = SOCK_STREAM;
- if (LogFile != -1) {
- close(LogFile);
- LogFile = -1;
- }
- goto retry;
- } else {
- if (LogFile != -1) {
- close(LogFile);
- LogFile = -1;
- }
+
+ if (LogFile != -1 && !connected) {
+ if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) != -1) {
+ connected = 1;
+ } else {
+ if (LogFile != -1) {
+ close(LogFile);
+ LogFile = -1;
+ }
+ if (logType == SOCK_DGRAM) {
+ logType = SOCK_STREAM;
+ goto retry;
+ }
+ }
}
- }
- UNLOCK;
+DONE:
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_def(openlog)
@@ -203,25 +195,27 @@ libc_hidden_def(openlog)
* print message on log file; output is intended for syslogd(8).
*/
void
-vsyslog( int pri, const char *fmt, va_list ap )
+vsyslog(int pri, const char *fmt, va_list ap)
{
register char *p;
char *last_chr, *head_end, *end, *stdp;
time_t now;
int fd, saved_errno;
int rc;
- char tbuf[1024]; /* syslogd is unable to handle longer messages */
-
+ char tbuf[1024]; /* syslogd is unable to handle longer messages */
struct sigaction action, oldaction;
- int sigpipe;
- memset (&action, 0, sizeof (action));
- action.sa_handler = sigpipe_handler;
- sigemptyset (&action.sa_mask);
- sigpipe = sigaction (SIGPIPE, &action, &oldaction);
+
+ memset(&action, 0, sizeof(action));
+ action.sa_handler = closelog_intern;
+ sigemptyset(&action.sa_mask); /* TODO: memset already zeroed it out! */
+ /* Only two errors are possible for sigaction:
+ * EFAULT (bad address of &oldaction) and EINVAL (invalid signo)
+ * none of which can happen here. */
+ /*int sigpipe =*/ sigaction(SIGPIPE, &action, &oldaction);
saved_errno = errno;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
/* See if we should just throw out this message. */
if (!(LogMask & LOG_MASK(LOG_PRI(pri))) || (pri &~ (LOG_PRIMASK|LOG_FACMASK)))
@@ -262,9 +256,9 @@ vsyslog( int pri, const char *fmt, va_list ap )
__set_errno(saved_errno);
p += vsnprintf(p, end - p, fmt, ap);
if (p >= end || p < head_end) { /* Returned -1 in case of error... */
- static const char truncate_msg[12] = "[truncated] ";
+ static const char truncate_msg[12] = "[truncated] "; /* no NUL! */
memmove(head_end + sizeof(truncate_msg), head_end,
- end - head_end - sizeof(truncate_msg));
+ end - head_end - sizeof(truncate_msg));
memcpy(head_end, truncate_msg, sizeof(truncate_msg));
if (p < head_end) {
while (p < end && *p) {
@@ -287,29 +281,33 @@ vsyslog( int pri, const char *fmt, va_list ap )
/* Output the message to the local logger using NUL as a message delimiter. */
p = tbuf;
*last_chr = 0;
- do {
- rc = write(LogFile, p, last_chr + 1 - p);
- if (rc < 0) {
- if ((errno==EAGAIN) || (errno==EINTR))
- rc=0;
- else {
- closelog_intern(0);
- break;
+ if (LogFile >= 0) {
+ do {
+ rc = write(LogFile, p, last_chr + 1 - p);
+ if (rc < 0) {
+ /* I don't think looping forever on EAGAIN is a good idea.
+ * Imagine that syslogd is SIGSTOPed... */
+ if (/* (errno != EAGAIN) && */ (errno != EINTR)) {
+ closelog_intern(1); /* 1: do not reset LogXXX globals to default */
+ goto write_err;
+ }
+ rc = 0;
}
- }
- p+=rc;
- } while (p <= last_chr);
- if (rc >= 0)
+ p += rc;
+ } while (p <= last_chr);
goto getout;
+ }
+ write_err:
/*
* Output the message to the console; don't worry about blocking,
* if console blocks everything will. Make sure the error reported
* is the one from the syslogd failure.
*/
- /* should mode be `O_WRONLY | O_NOCTTY' ? -- Uli */
- if (LogStat & LOG_CONS &&
- (fd = open(_PATH_CONSOLE, O_WRONLY, 0)) >= 0) {
+ /* should mode be O_WRONLY | O_NOCTTY? -- Uli */
+ /* yes, but in Linux "/dev/console" never becomes ctty anyway -- vda */
+ if ((LogStat & LOG_CONS) &&
+ (fd = open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY)) >= 0) {
p = strchr(tbuf, '>') + 1;
last_chr[0] = '\r';
last_chr[1] = '\n';
@@ -318,10 +316,9 @@ vsyslog( int pri, const char *fmt, va_list ap )
}
getout:
- UNLOCK;
- if (sigpipe == 0)
- sigaction (SIGPIPE, &oldaction,
- (struct sigaction *) NULL);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
+ /*if (sigpipe == 0)*/
+ sigaction(SIGPIPE, &oldaction, (struct sigaction *) NULL);
}
libc_hidden_def(vsyslog)
@@ -340,22 +337,24 @@ libc_hidden_def(syslog)
* CLOSELOG -- close the system log
*/
void
-closelog( void )
+closelog(void)
{
- closelog_intern(1);
+ __UCLIBC_MUTEX_LOCK(mylock);
+ closelog_intern(0); /* 0: reset LogXXX globals to default */
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_def(closelog)
/* setlogmask -- set the log mask level */
int setlogmask(int pmask)
{
- int omask;
-
- omask = LogMask;
- LOCK;
- if (pmask != 0)
- LogMask = pmask;
- UNLOCK;
- return (omask);
-}
+ int omask;
+ omask = LogMask;
+ if (pmask != 0) {
+ __UCLIBC_MUTEX_LOCK(mylock);
+ LogMask = pmask;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
+ }
+ return omask;
+}
diff --git a/libc/misc/sysvipc/ipc.h b/libc/misc/sysvipc/ipc.h
index 62c035b20..339d1364b 100644
--- a/libc/misc/sysvipc/ipc.h
+++ b/libc/misc/sysvipc/ipc.h
@@ -3,7 +3,7 @@
#include <syscall.h>
#include <bits/wordsize.h>
-#if __WORDSIZE == 32 || defined __alpha__
+#if __WORDSIZE == 32 || defined __alpha__ || defined __mips__
# define __IPC_64 0x100
#else
# define __IPC_64 0x0
@@ -12,14 +12,15 @@
#ifdef __NR_ipc
/* The actual system call: all functions are multiplexed by this. */
-extern int __syscall_ipc (unsigned int __call, int __first, int __second,
- int __third, void *__ptr) attribute_hidden;
+extern int __syscall_ipc (unsigned int __call, long __first, long __second,
+ long __third, void *__ptr, void *__fifth) attribute_hidden;
/* The codes for the functions to use the multiplexer `__syscall_ipc'. */
#define IPCOP_semop 1
#define IPCOP_semget 2
#define IPCOP_semctl 3
+#define IPCOP_semtimedop 4
#define IPCOP_msgsnd 11
#define IPCOP_msgrcv 12
#define IPCOP_msgget 13
diff --git a/libc/misc/sysvipc/msgq.c b/libc/misc/sysvipc/msgq.c
index 5f695084a..fc0279119 100644
--- a/libc/misc/sysvipc/msgq.c
+++ b/libc/misc/sysvipc/msgq.c
@@ -15,7 +15,7 @@ int msgctl(int msqid, int cmd, struct msqid_ds *buf)
#ifdef __NR_msgctl
return __libc_msgctl(msqid, cmd | __IPC_64, buf);
#else
- return __syscall_ipc(IPCOP_msgctl, msqid, cmd | __IPC_64, 0, buf);
+ return __syscall_ipc(IPCOP_msgctl, msqid, cmd | __IPC_64, 0, buf, 0);
#endif
}
#endif
@@ -28,7 +28,7 @@ _syscall2(int, msgget, key_t, key, int, msgflg)
/* Get messages queue. */
int msgget (key_t key, int msgflg)
{
- return __syscall_ipc(IPCOP_msgget ,key ,msgflg ,0 ,0);
+ return __syscall_ipc(IPCOP_msgget ,key ,msgflg ,0 ,0, 0);
}
#endif
#endif
@@ -80,7 +80,7 @@ int msgrcv (int msqid, void *msgp, size_t msgsz,
temp.r_msgtyp = msgtyp;
temp.oldmsg = msgp;
- return __syscall_ipc(IPCOP_msgrcv ,msqid ,msgsz ,msgflg ,&temp);
+ return __syscall_ipc(IPCOP_msgrcv ,msqid ,msgsz ,msgflg ,&temp, 0);
}
#endif
#endif
@@ -116,7 +116,7 @@ _syscall4(int, msgsnd, int, msqid, const void *, msgp, size_t, msgsz, int, msgfl
/* Send message to message queue. */
int msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg)
{
- return __syscall_ipc(IPCOP_msgsnd, msqid, msgsz, msgflg, (void *)msgp);
+ return __syscall_ipc(IPCOP_msgsnd, msqid, msgsz, msgflg, (void *)msgp, 0);
}
#endif
#endif
diff --git a/libc/misc/sysvipc/sem.c b/libc/misc/sysvipc/sem.c
index ccbe25b46..07705c9d9 100644
--- a/libc/misc/sysvipc/sem.c
+++ b/libc/misc/sysvipc/sem.c
@@ -19,6 +19,7 @@
#include <errno.h>
#include <sys/sem.h>
+#include <stddef.h>
#include "ipc.h"
@@ -26,6 +27,7 @@
/* Return identifier for array of NSEMS semaphores associated with
KEY. */
#include <stdarg.h>
+#include <stdlib.h>
/* arg for semctl system calls. */
union semun {
int val; /* value for SETVAL */
@@ -53,7 +55,7 @@ int semctl(int semid, int semnum, int cmd, ...)
#ifdef __NR_semctl
return __semctl(semid, semnum, cmd | __IPC_64, arg.__pad);
#else
- return __syscall_ipc(IPCOP_semctl, semid, semnum, cmd | __IPC_64, &arg);
+ return __syscall_ipc(IPCOP_semctl, semid, semnum, cmd|__IPC_64, &arg, NULL);
#endif
}
#endif
@@ -70,7 +72,7 @@ _syscall3(int, semget, key_t, key, int, nsems, int, semflg);
* with KEY. */
int semget (key_t key, int nsems, int semflg)
{
- return __syscall_ipc(IPCOP_semget, key, nsems, semflg, NULL);
+ return __syscall_ipc(IPCOP_semget, key, nsems, semflg, NULL, 0);
}
#endif
#endif
@@ -84,7 +86,22 @@ _syscall3(int, semop, int, semid, struct sembuf *, sops, size_t, nsops);
/* Perform user-defined atomical operation of array of semaphores. */
int semop (int semid, struct sembuf *sops, size_t nsops)
{
- return __syscall_ipc(IPCOP_semop, semid, (int) nsops, 0, sops);
+ return __syscall_ipc(IPCOP_semop, semid, (int) nsops, 0, sops, NULL);
+}
+#endif
+#endif
+
+#ifdef L_semtimedop
+
+#ifdef __NR_semtimedop
+_syscall4(int, semtimedop, int, semid, struct sembuf *, sops, size_t, nsops, const struct timespec *, timeout);
+
+#else
+
+int semtimedop(int semid, struct sembuf *sops, size_t nsops,
+ const struct timespec *timeout)
+{
+ return __syscall_ipc(IPCOP_semtimedop, semid, nsops, 0, sops, timeout);
}
#endif
#endif
diff --git a/libc/misc/sysvipc/shm.c b/libc/misc/sysvipc/shm.c
index a466de921..9f76a12ed 100644
--- a/libc/misc/sysvipc/shm.c
+++ b/libc/misc/sysvipc/shm.c
@@ -45,7 +45,7 @@ void * shmat (int shmid, const void *shmaddr, int shmflg)
int retval;
unsigned long raddr;
- retval = __syscall_ipc(IPCOP_shmat, shmid, shmflg, (int) &raddr, (void *) shmaddr);
+ retval = __syscall_ipc(IPCOP_shmat, shmid, shmflg, (int) &raddr, (void *) shmaddr, 0);
return ((unsigned long int) retval > -(unsigned long int) SHMLBA
? (void *) retval : (void *) raddr);
}
@@ -63,7 +63,7 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf)
#ifdef __NR_shmctl
return __libc_shmctl(shmid, cmd | __IPC_64, buf);
#else
- return __syscall_ipc(IPCOP_shmctl, shmid, cmd | __IPC_64, 0, buf);
+ return __syscall_ipc(IPCOP_shmctl, shmid, cmd | __IPC_64, 0, buf, 0);
#endif
}
#endif
@@ -77,7 +77,7 @@ _syscall1(int, shmdt, const void *, shmaddr);
#else
int shmdt (const void *shmaddr)
{
- return __syscall_ipc(IPCOP_shmdt, 0, 0, 0, (void *) shmaddr);
+ return __syscall_ipc(IPCOP_shmdt, 0, 0, 0, (void *) shmaddr, 0);
}
#endif
#endif
@@ -90,7 +90,7 @@ _syscall3(int, shmget, key_t, key, size_t, size, int, shmflg);
#else
int shmget (key_t key, size_t size, int shmflg)
{
- return __syscall_ipc(IPCOP_shmget, key, size, shmflg, NULL);
+ return __syscall_ipc(IPCOP_shmget, key, size, shmflg, NULL, 0);
}
#endif
#endif
diff --git a/libc/misc/time/ftime.c b/libc/misc/time/ftime.c
index 233d6f70d..49c137ce5 100644
--- a/libc/misc/time/ftime.c
+++ b/libc/misc/time/ftime.c
@@ -21,8 +21,7 @@
libc_hidden_proto(gettimeofday)
-int ftime(timebuf)
-struct timeb *timebuf;
+int ftime(struct timeb *timebuf)
{
struct timeval tv;
struct timezone tz;
diff --git a/libc/misc/time/time.c b/libc/misc/time/time.c
index b5278bce1..2d980a068 100644
--- a/libc/misc/time/time.c
+++ b/libc/misc/time/time.c
@@ -86,7 +86,7 @@
* NOTE: uClibc mktime behavior is different than glibc's when
* the struct tm has tm_isdst == -1 and also had fields outside of
* the normal ranges.
- *
+ *
* Apparently, glibc examines (at least) tm_sec and guesses the app's
* intention of assuming increasing or decreasing time when entering an
* ambiguous time period at the dst<->st boundaries.
@@ -144,6 +144,8 @@
#include <fcntl.h>
#include <unistd.h>
#include <bits/uClibc_uintmaxtostr.h>
+#include <bits/uClibc_mutex.h>
+
#ifdef __UCLIBC_HAS_WCHAR__
#include <wchar.h>
@@ -158,12 +160,12 @@ libc_hidden_proto(ctime)
libc_hidden_proto(localtime)
libc_hidden_proto(localtime_r)
-libc_hidden_proto(memset)
-libc_hidden_proto(memcpy)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strncpy)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strncpy) */
/* libc_hidden_proto(sprintf) */
libc_hidden_proto(open)
libc_hidden_proto(read)
@@ -171,18 +173,18 @@ libc_hidden_proto(close)
libc_hidden_proto(getenv)
libc_hidden_proto(tzset)
libc_hidden_proto(gettimeofday)
-libc_hidden_proto(strncasecmp)
+/* Experimentally off - libc_hidden_proto(strncasecmp) */
libc_hidden_proto(strtol)
libc_hidden_proto(strtoul)
libc_hidden_proto(nl_langinfo)
#ifdef __UCLIBC_HAS_XLOCALE__
-libc_hidden_proto(strncasecmp_l)
+/* Experimentally off - libc_hidden_proto(strncasecmp_l) */
libc_hidden_proto(strtol_l)
libc_hidden_proto(strtoul_l)
libc_hidden_proto(nl_langinfo_l)
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
@@ -194,6 +196,22 @@ libc_hidden_proto(__ctype_b)
#define TZNAME_MAX _POSIX_TZNAME_MAX
#endif
+#if defined (L_tzset) || defined (L_localtime_r) || defined(L_strftime) || \
+ defined(L__time_mktime) || defined(L__time_mktime_tzi) || \
+ ((defined(L_strftime) || defined(L_strftime_l)) && \
+ defined(__UCLIBC_HAS_XLOCALE__))
+
+void _time_tzset(int use_old_rules) attribute_hidden;
+
+#ifndef L__time_mktime
+
+ /* Jan 1, 2007 Z - tm = 0,0,0,1,0,107,1,0,0 */
+
+static const time_t new_rule_starts = 1167609600;
+
+#endif
+#endif
+
/**********************************************************************/
/* The era code is currently unfinished. */
/* #define ENABLE_ERA_CODE */
@@ -228,12 +246,7 @@ typedef struct {
char tzname[TZNAME_MAX+1];
} rule_struct;
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-extern pthread_mutex_t _time_tzlock attribute_hidden;
-#endif
-#define TZLOCK __pthread_mutex_lock(&_time_tzlock)
-#define TZUNLOCK __pthread_mutex_unlock(&_time_tzlock)
+__UCLIBC_MUTEX_EXTERN(_time_tzlock);
extern rule_struct _time_tzinfo[2] attribute_hidden;
@@ -274,16 +287,16 @@ libc_hidden_def(asctime)
* };
* static char mon_name[12][3] = {
* "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- * "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ * "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
* };
* static char result[26];
- *
+ *
* sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
- * wday_name[timeptr->tm_wday],
+ * wday_name[timeptr->tm_wday],
* mon_name[timeptr->tm_mon],
* timeptr->tm_mday, timeptr->tm_hour,
- * timeptr->tm_min, timeptr->tm_sec,
- * 1900 + timeptr->tm_year);
+ * timeptr->tm_min, timeptr->tm_sec,
+ * 1900 + timeptr->tm_year);
* return result;
* }
*
@@ -309,10 +322,10 @@ static const unsigned char at_data[] = {
'J', 'a', 'n', 'F', 'e', 'b', 'M', 'a', 'r', 'A', 'p', 'r',
'M', 'a', 'y', 'J', 'u', 'n', 'J', 'u', 'l', 'A', 'u', 'g',
- 'S', 'e', 'p', 'O', 'c', 't', 'N', 'o', 'v', 'D', 'e', 'c',
+ 'S', 'e', 'p', 'O', 'c', 't', 'N', 'o', 'v', 'D', 'e', 'c',
#ifdef SAFE_ASCTIME_R
- '?', '?', '?',
+ '?', '?', '?',
#endif
' ', '?', '?', '?',
' ', '0',
@@ -587,13 +600,13 @@ libc_hidden_def(localtime)
struct tm *localtime_r(register const time_t *__restrict timer,
register struct tm *__restrict result)
{
- TZLOCK;
+ __UCLIBC_MUTEX_LOCK(_time_tzlock);
- tzset();
+ _time_tzset(*timer < new_rule_starts);
__time_localtime_tzi(timer, result, _time_tzinfo);
- TZUNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(_time_tzlock);
return result;
}
@@ -605,7 +618,7 @@ libc_hidden_def(localtime_r)
#ifdef __UCLIBC_HAS_TM_EXTENSIONS__
-libc_hidden_proto(strnlen)
+/* Experimentally off - libc_hidden_proto(strnlen) */
struct ll_tzname_item;
@@ -648,7 +661,7 @@ static const char *lookup_tzname(const char *key)
static const unsigned char day_cor[] = { /* non-leap */
31, 31, 34, 34, 35, 35, 36, 36, 36, 37, 37, 38, 38
-/* 0, 0, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7 */
+/* 0, 0, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7 */
/* 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 */
};
@@ -659,7 +672,7 @@ static int tm_isdst(register const struct tm *__restrict ptm,
{
long sec;
int i, isdst, isleap, day, day0, monlen, mday;
- int oday; /* Note: oday can be uninitialized. */
+ int oday = oday; /* ok to be uninitialized, shutting up compiler warning */
isdst = 0;
if (r[1].tzname[0] != 0) {
@@ -1027,13 +1040,14 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize,
unsigned char mod;
unsigned char code;
- tzset(); /* We'll, let's get this out of the way. */
+ /* We'll, let's get this out of the way. */
+ _time_tzset(_time_mktime((struct tm *) timeptr, 0) < new_rule_starts);
lvl = 0;
p = format;
count = maxsize;
- LOOP:
+LOOP:
if (!count) {
return 0;
}
@@ -1096,7 +1110,7 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize,
goto LOOP;
}
- o = spec + 26; /* set to "????" */
+ o = ((const char *) spec) + 26; /* set to "????" */
if ((code & MASK_SPEC) == CALC_SPEC) {
if (*p == 's') {
@@ -1132,7 +1146,6 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize,
#ifdef __UCLIBC_HAS_TM_EXTENSIONS__
-#define RSP_TZUNLOCK ((void) 0)
# ifdef __USE_BSD
# define RSP_TZNAME timeptr->tm_zone
# define RSP_GMT_OFFSET (-timeptr->tm_gmtoff)
@@ -1143,11 +1156,10 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize,
#else
-#define RSP_TZUNLOCK TZUNLOCK
#define RSP_TZNAME rsp->tzname
#define RSP_GMT_OFFSET rsp->gmt_offset
- TZLOCK;
+ __UCLIBC_MUTEX_LOCK(_time_tzlock);
rsp = _time_tzinfo;
if (timeptr->tm_isdst > 0) {
@@ -1178,24 +1190,30 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize,
}
#endif
o_count = SIZE_MAX;
- RSP_TZUNLOCK;
+#ifdef __UCLIBC_HAS_TM_EXTENSIONS__
goto OUTPUT;
+#endif
} else { /* z */
*s = '+';
if ((tzo = -RSP_GMT_OFFSET) < 0) {
tzo = -tzo;
*s = '-';
}
- RSP_TZUNLOCK;
++s;
--count;
i = tzo / 60;
field_val = ((i / 60) * 100) + (i % 60);
-
+
i = 16 + 6; /* 0-fill, width = 4 */
}
-
+#ifdef __UCLIBC_HAS_TM_EXTENSIONS__
+#else
+ __UCLIBC_MUTEX_UNLOCK(_time_tzlock);
+ if (*p == 'Z') {
+ goto OUTPUT;
+ }
+#endif
} else {
/* TODO: don't need year for U, W */
for (i=0 ; i < 3 ; i++) {
@@ -1267,7 +1285,7 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize,
field_val += 7;
}
}
-
+
if ((code & MASK_SPEC) == STRING_SPEC) {
o_count = SIZE_MAX;
field_val += spec[STRINGS_NL_ITEM_START + (code & 0xf)];
@@ -1285,7 +1303,7 @@ size_t __XL_NPP(strftime)(char *__restrict s, size_t maxsize,
}
}
- OUTPUT:
+OUTPUT:
++p;
while (o_count && count && *o) {
*s++ = *o++;
@@ -1487,7 +1505,7 @@ char *__XL_NPP(strptime)(const char *__restrict buf, const char *__restrict form
lvl = 0;
p = format;
- LOOP:
+LOOP:
if (!*p) {
if (lvl == 0) { /* Done. */
if (fields[6] == 7) { /* Cleanup for %u here since just once. */
@@ -1716,7 +1734,9 @@ static const char vals[] = {
6, 0, 0, /* Note: overloaded for non-M non-J case... */
0, 1, 0, /* J */
',', 'M', '4', '.', '1', '.', '0',
- ',', 'M', '1', '0', '.', '5', '.', '0', 0
+ ',', 'M', '1', '0', '.', '5', '.', '0', 0,
+ ',', 'M', '3', '.', '2', '.', '0',
+ ',', 'M', '1', '1', '.', '1', '.', '0', 0
};
#define TZ vals
@@ -1724,15 +1744,14 @@ static const char vals[] = {
#define RANGE (vals + 7)
#define RULE (vals + 11 - 1)
#define DEFAULT_RULES (vals + 22)
+#define DEFAULT_2007_RULES (vals + 38)
/* Initialize to UTC. */
int daylight = 0;
long timezone = 0;
char *tzname[2] = { (char *) UTC, (char *) (UTC-1) };
-#ifdef __UCLIBC_HAS_THREADS__
-attribute_hidden pthread_mutex_t _time_tzlock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
+__UCLIBC_MUTEX_INIT(_time_tzlock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
rule_struct _time_tzinfo[2];
@@ -1805,7 +1824,7 @@ static const char *getnumber(register const char *e, int *pn)
#ifdef __UCLIBC_HAS_TZ_FILE__
#ifndef __UCLIBC_HAS_TZ_FILE_READ_MANY__
-static int TZ_file_read; /* Let BSS initialization set this to 0. */
+static smallint TZ_file_read; /* Let BSS initialization set this to 0. */
#endif /* __UCLIBC_HAS_TZ_FILE_READ_MANY__ */
static char *read_TZ_file(char *buf)
@@ -1833,10 +1852,10 @@ static char *read_TZ_file(char *buf)
p[-1] = 0;
p = buf;
#ifndef __UCLIBC_HAS_TZ_FILE_READ_MANY__
- ++TZ_file_read;
+ TZ_file_read = 1;
#endif /* __UCLIBC_HAS_TZ_FILE_READ_MANY__ */
} else {
- ERROR:
+ERROR:
p = NULL;
}
close(fd);
@@ -1852,9 +1871,14 @@ libc_hidden_proto(isascii)
void tzset(void)
{
+ _time_tzset((time(NULL)) < new_rule_starts);
+}
+
+void _time_tzset(int use_old_rules)
+{
register const char *e;
register char *s;
- long off;
+ long off = 0;
short *p;
rule_struct new_rules[2];
int n, count, f;
@@ -1866,7 +1890,7 @@ void tzset(void)
static char oldval[TZ_BUFLEN]; /* BSS-zero'd. */
#endif /* __UCLIBC_HAS_TZ_CACHING__ */
- TZLOCK;
+ __UCLIBC_MUTEX_LOCK(_time_tzlock);
e = getenv(TZ); /* TZ env var always takes precedence. */
@@ -1876,7 +1900,7 @@ void tzset(void)
if (e != NULL) {
TZ_file_read = 0; /* Reset if the TZ env var is set. */
- } else if (TZ_file_read > 0) {
+ } else if (TZ_file_read) {
goto FAST_DONE;
}
#endif /* defined(__UCLIBC_HAS_TZ_FILE__) && !defined(__UCLIBC_HAS_TZ_FILE_READ_MANY__) */
@@ -1891,7 +1915,7 @@ void tzset(void)
&& !(e = read_TZ_file(buf)) /* and no file or invalid file */
#endif /* __UCLIBC_HAS_TZ_FILE__ */
) || !*e) { /* or set to empty string. */
- ILLEGAL: /* TODO: Clean up the following... */
+ILLEGAL: /* TODO: Clean up the following... */
#ifdef __UCLIBC_HAS_TZ_CACHING__
*oldval = 0; /* Set oldval to an empty string. */
#endif /* __UCLIBC_HAS_TZ_CACHING__ */
@@ -1913,10 +1937,10 @@ void tzset(void)
* to the empty string anyway. */
strncpy(oldval, e, TZ_BUFLEN);
#endif /* __UCLIBC_HAS_TZ_CACHING__ */
-
+
count = 0;
new_rules[1].tzname[0] = 0;
- LOOP:
+LOOP:
/* Get std or dst name. */
c = 0;
if (*e == '<') {
@@ -1962,7 +1986,7 @@ void tzset(void)
if (*s == '-') {
off = -off; /* Save off in case needed for dst default. */
}
- SKIP_OFFSET:
+SKIP_OFFSET:
new_rules[count].gmt_offset = off;
if (!count) {
@@ -1974,7 +1998,15 @@ void tzset(void)
} else { /* OK, we have dst, so get some rules. */
count = 0;
if (!*e) { /* No rules so default to US rules. */
- e = DEFAULT_RULES;
+ e = use_old_rules ? DEFAULT_RULES : DEFAULT_2007_RULES;
+#ifdef DEBUG_TZSET
+ if (e == DEFAULT_RULES)
+ printf("tzset: Using old rules.\n");
+ else if (e == DEFAULT_2007_RULES)
+ printf("tzset: Using new rules\n");
+ else
+ printf("tzset: Using undefined rules\n");
+#endif /* DEBUG_TZSET */
}
do {
@@ -2026,16 +2058,16 @@ void tzset(void)
}
memcpy(_time_tzinfo, new_rules, sizeof(new_rules));
- DONE:
+DONE:
tzname[0] = _time_tzinfo[0].tzname;
tzname[1] = _time_tzinfo[1].tzname;
daylight = !!_time_tzinfo[1].tzname[0];
timezone = _time_tzinfo[0].gmt_offset;
#if defined(__UCLIBC_HAS_TZ_FILE__) || defined(__UCLIBC_HAS_TZ_CACHING__)
- FAST_DONE:
+FAST_DONE:
#endif
- TZUNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(_time_tzlock);
}
libc_hidden_def(tzset)
#endif
@@ -2100,7 +2132,7 @@ struct tm attribute_hidden *_time_t2tm(const time_t *__restrict timer,
{
register int *p;
time_t t1, t, v;
- int wday; /* Note: wday can be uninitialized. */
+ int wday = wday; /* ok to be uninitialized, shutting up warning */
{
register const uint16_t *vp;
@@ -2136,7 +2168,7 @@ struct tm attribute_hidden *_time_t2tm(const time_t *__restrict timer,
++v;
/* Change to days since 1/1/1601 so that for 32 bit time_t
* values, we'll have t >= 0. This should be changed for
- * archs with larger time_t types.
+ * archs with larger time_t types.
* Also, correct for offset since a multiple of 7. */
/* TODO: Does this still work on archs with time_t > 32 bits? */
@@ -2242,13 +2274,13 @@ time_t attribute_hidden _time_mktime(struct tm *timeptr, int store_on_success)
{
time_t t;
- TZLOCK;
+ __UCLIBC_MUTEX_LOCK(_time_tzlock);
tzset();
t = _time_mktime_tzi(timeptr, store_on_success, _time_tzinfo);
- TZUNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(_time_tzlock);
return t;
}
@@ -2301,7 +2333,7 @@ time_t attribute_hidden _time_mktime_tzi(struct tm *timeptr, int store_on_succes
if (__isleap(d)) {
s += 11;
}
-
+
p[7] = 0;
d = p[4];
while (d) {
@@ -2313,12 +2345,14 @@ time_t attribute_hidden _time_mktime_tzi(struct tm *timeptr, int store_on_succes
--d;
}
+ _time_tzset (x.tm_year < 2007); /* tm_year was expanded above */
+
#ifdef __BCC__
d = p[5] - 1;
days = -719163L + ((long)d)*365 + ((d/4) - (d/100) + (d/400) + p[3] + p[7]);
secs = p[0] + 60*( p[1] + 60*((long)(p[2])) )
+ tzi[default_dst].gmt_offset;
- DST_CORRECT:
+DST_CORRECT:
if (secs < 0) {
secs += 120009600L;
days -= 1389;
@@ -2338,7 +2372,7 @@ time_t attribute_hidden _time_mktime_tzi(struct tm *timeptr, int store_on_succes
+ 24*(((146073L * ((long long)(p[6])) + d)
+ p[3]) + p[7])));
- DST_CORRECT:
+DST_CORRECT:
if (((unsigned long long)(secs - LONG_MIN))
> (((unsigned long long)LONG_MAX) - LONG_MIN)
) {
@@ -2371,7 +2405,7 @@ time_t attribute_hidden _time_mktime_tzi(struct tm *timeptr, int store_on_succes
}
- DONE:
+DONE:
return t;
}
diff --git a/libc/misc/ttyent/getttyent.c b/libc/misc/ttyent/getttyent.c
index 89c39876f..b43422ddc 100644
--- a/libc/misc/ttyent/getttyent.c
+++ b/libc/misc/ttyent/getttyent.c
@@ -38,9 +38,9 @@
#include <pthread.h>
#endif
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strncmp)
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strncmp) */
libc_hidden_proto(__fsetlocking)
libc_hidden_proto(rewind)
libc_hidden_proto(fgets_unlocked)
@@ -51,7 +51,7 @@ libc_hidden_proto(fclose)
libc_hidden_proto(abort)
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
@@ -126,6 +126,7 @@ struct ttyent * getttyent(void)
register int c;
register char *p;
static char *line = NULL;
+ struct ttyent *retval = NULL;
if (!tf && !setttyent())
return (NULL);
@@ -140,8 +141,7 @@ struct ttyent * getttyent(void)
for (;;) {
if (!fgets_unlocked(p = line, BUFSIZ, tf)) {
- __STDIO_ALWAYS_THREADUNLOCK(tf);
- return (NULL);
+ goto DONE;
}
/* skip lines that are too big */
if (!strchr(p, '\n')) {
@@ -184,8 +184,6 @@ struct ttyent * getttyent(void)
else
break;
}
- /* We can release the lock only here since `zapchar' is global. */
- __STDIO_ALWAYS_THREADUNLOCK(tf);
if (zapchar == '#' || *p == '#')
while ((c = *++p) == ' ' || c == '\t')
@@ -195,7 +193,11 @@ struct ttyent * getttyent(void)
tty.ty_comment = 0;
if ((p = strchr(p, '\n')))
*p = '\0';
- return (&tty);
+ retval = &tty;
+
+ DONE:
+ __STDIO_ALWAYS_THREADUNLOCK(tf);
+ return retval;
}
libc_hidden_def(getttyent)
diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c
index 2734f9e95..ad5835f6a 100644
--- a/libc/misc/utmp/utent.c
+++ b/libc/misc/utmp/utent.c
@@ -5,7 +5,7 @@
Note that because of the way this stupid stupid standard works, you
have to call endutent() to close the file even if you've not called
- setutent -- getutid and family use the same file descriptor.
+ setutent -- getutid and family use the same file descriptor.
Modified by Erik Andersen for uClibc...
*/
@@ -19,27 +19,23 @@
#include <errno.h>
#include <string.h>
#include <utmp.h>
+
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <not-cancel.h>
#endif
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strdup)
-libc_hidden_proto(strncmp)
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strdup) */
+/* Experimentally off - libc_hidden_proto(strncmp) */
libc_hidden_proto(read)
libc_hidden_proto(write)
libc_hidden_proto(open)
libc_hidden_proto(fcntl)
libc_hidden_proto(close)
libc_hidden_proto(lseek)
-libc_hidden_proto(setutent)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t utmplock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&utmplock)
-#define UNLOCK __pthread_mutex_unlock(&utmplock)
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER);
@@ -49,11 +45,11 @@ static struct utmp static_utmp;
static const char default_file_name[] = _PATH_UTMP;
static const char *static_ut_name = (const char *) default_file_name;
-void setutent(void)
+/* This function must be called with the LOCK held */
+static void __setutent(void)
{
int ret;
- LOCK;
if (static_fd == -1) {
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
if ((static_fd = open_not_cancel_2(static_ut_name, O_RDWR)) < 0) {
@@ -86,44 +82,49 @@ bummer:
#else
close(static_fd);
#endif
-unlock_and_ret:
- UNLOCK;
return;
}
}
lseek(static_fd, 0, SEEK_SET);
- goto unlock_and_ret;
+ return;
+}
+
+libc_hidden_proto(setutent)
+void setutent(void)
+{
+ __UCLIBC_MUTEX_LOCK(utmplock);
+ __setutent();
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
}
libc_hidden_def(setutent)
+/* This function must be called with the LOCK held */
static struct utmp *__getutent(int utmp_fd)
{
struct utmp *ret = NULL;
if (utmp_fd == -1) {
- setutent();
+ __setutent();
}
if (utmp_fd == -1) {
return NULL;
}
- LOCK;
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
if (read_not_cancel(utmp_fd, (char *) &static_utmp, sizeof(struct utmp)) == sizeof(struct utmp))
#else
- if (read(utmp_fd, (char *) &static_utmp, sizeof(struct utmp)) == sizeof(struct utmp))
+ if (read(utmp_fd, (char *) &static_utmp, sizeof(struct utmp)) == sizeof(struct utmp))
#endif
{
ret = &static_utmp;
}
- UNLOCK;
return ret;
}
void endutent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(utmplock);
if (static_fd != -1)
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status(static_fd);
@@ -131,68 +132,81 @@ void endutent(void)
close(static_fd);
#endif
static_fd = -1;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
}
-/* Locking is done in __getutent */
struct utmp *getutent(void)
{
- return __getutent(static_fd);
+ struct utmp *ret = NULL;
+
+ __UCLIBC_MUTEX_LOCK(utmplock);
+ ret = __getutent(static_fd);
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
+ return ret;
}
-/* Locking is done in __getutent */
-libc_hidden_proto(getutid)
-struct utmp *getutid (const struct utmp *utmp_entry)
+/* This function must be called with the LOCK held */
+static struct utmp *__getutid(const struct utmp *utmp_entry)
{
struct utmp *lutmp;
while ((lutmp = __getutent(static_fd)) != NULL) {
- if ( (utmp_entry->ut_type == RUN_LVL ||
- utmp_entry->ut_type == BOOT_TIME ||
- utmp_entry->ut_type == NEW_TIME ||
- utmp_entry->ut_type == OLD_TIME) &&
- lutmp->ut_type == utmp_entry->ut_type)
- {
- return lutmp;
- }
- if ( (utmp_entry->ut_type == INIT_PROCESS ||
- utmp_entry->ut_type == DEAD_PROCESS ||
- utmp_entry->ut_type == LOGIN_PROCESS ||
- utmp_entry->ut_type == USER_PROCESS) &&
- !strncmp(lutmp->ut_id, utmp_entry->ut_id, sizeof(lutmp->ut_id)))
- {
- return lutmp;
- }
+ if ( (utmp_entry->ut_type == RUN_LVL ||
+ utmp_entry->ut_type == BOOT_TIME ||
+ utmp_entry->ut_type == NEW_TIME ||
+ utmp_entry->ut_type == OLD_TIME) &&
+ lutmp->ut_type == utmp_entry->ut_type)
+ {
+ return lutmp;
+ }
+ if ( (utmp_entry->ut_type == INIT_PROCESS ||
+ utmp_entry->ut_type == DEAD_PROCESS ||
+ utmp_entry->ut_type == LOGIN_PROCESS ||
+ utmp_entry->ut_type == USER_PROCESS) &&
+ !strncmp(lutmp->ut_id, utmp_entry->ut_id, sizeof(lutmp->ut_id)))
+ {
+ return lutmp;
+ }
}
return NULL;
}
+
+libc_hidden_proto(getutid)
+struct utmp *getutid(const struct utmp *utmp_entry)
+{
+ struct utmp *ret = NULL;
+
+ __UCLIBC_MUTEX_LOCK(utmplock);
+ ret = __getutid(utmp_entry);
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
+ return ret;
+}
libc_hidden_def(getutid)
-/* Locking is done in __getutent */
struct utmp *getutline(const struct utmp *utmp_entry)
{
- struct utmp *lutmp;
+ struct utmp *lutmp = NULL;
+ __UCLIBC_MUTEX_LOCK(utmplock);
while ((lutmp = __getutent(static_fd)) != NULL) {
if ((lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) &&
- !strcmp(lutmp->ut_line, utmp_entry->ut_line))
- {
- return lutmp;
+ !strcmp(lutmp->ut_line, utmp_entry->ut_line)) {
+ break;
}
}
-
- return NULL;
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
+ return lutmp;
}
struct utmp *pututline (const struct utmp *utmp_entry)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(utmplock);
/* 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);
- if (getutid(utmp_entry) != NULL)
+ if (__getutid(utmp_entry) != NULL)
lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
else
lseek(static_fd, (off_t) 0, SEEK_END);
@@ -203,19 +217,19 @@ struct utmp *pututline (const struct utmp *utmp_entry)
#endif
utmp_entry = NULL;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
return (struct utmp *)utmp_entry;
}
int utmpname (const char *new_ut_name)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(utmplock);
if (new_ut_name != NULL) {
if (static_ut_name != default_file_name)
free((char *)static_ut_name);
static_ut_name = strdup(new_ut_name);
if (static_ut_name == NULL) {
- /* We should probably whine about out-of-memory
+ /* We should probably whine about out-of-memory
* errors here... Instead just reset to the default */
static_ut_name = default_file_name;
}
@@ -228,6 +242,6 @@ int utmpname (const char *new_ut_name)
close(static_fd);
#endif
static_fd = -1;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(utmplock);
return 0;
}
diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c
index 082e8c184..8f6fdf524 100644
--- a/libc/misc/utmp/wtent.c
+++ b/libc/misc/utmp/wtent.c
@@ -19,8 +19,8 @@
#endif
#if 0
-libc_hidden_proto(memset)
-libc_hidden_proto(strncpy)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strncpy) */
libc_hidden_proto(updwtmp)
#endif
libc_hidden_proto(open)
diff --git a/libc/misc/wchar/wchar.c b/libc/misc/wchar/wchar.c
index 64bab37e0..57c3dbffd 100644
--- a/libc/misc/wchar/wchar.c
+++ b/libc/misc/wchar/wchar.c
@@ -293,10 +293,17 @@ size_t mbrtowc(wchar_t *__restrict pwc, const char *__restrict s,
empty_string[0] = 0; /* Init the empty string when necessary. */
s = empty_string;
n = 1;
+ } else if (*s == '\0') {
+ /* According to the ISO C 89 standard this is the expected behaviour. */
+ return 0;
} else if (!n) {
/* TODO: change error code? */
+#if 0
return (ps->__mask && (ps->__wc == 0xffffU))
? ((size_t) -1) : ((size_t) -2);
+#else
+ return 0;
+#endif
}
p = s;
@@ -865,7 +872,6 @@ size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
+ (wc & ((1 << Cwc2c_TT_SHIFT)-1))];
}
-#define __WCHAR_REPLACEMENT_CHAR '?'
#ifdef __WCHAR_REPLACEMENT_CHAR
*dst = (unsigned char) ( u ? u : __WCHAR_REPLACEMENT_CHAR );
#else /* __WCHAR_REPLACEMENT_CHAR */
@@ -1045,7 +1051,7 @@ int wcswidth(const wchar_t *pwcs, size_t n)
size_t i;
for (i = 0 ; (i < n) && pwcs[i] ; i++) {
- if (pwcs[i] != ((unsigned char)(pwcs[i]))) {
+ if (pwcs[i] != (pwcs[i] & 0x7f)) {
return -1;
}
}
@@ -1267,7 +1273,7 @@ const unsigned char __iconv_codesets[] =
"\x07\x01""ASCII"; /* Must be last! (special case to save a nul) */
libc_hidden_data_def(__iconv_codesets)
-libc_hidden_proto(strcasecmp)
+/* Experimentally off - libc_hidden_proto(strcasecmp) */
static int find_codeset(const char *name)
{
diff --git a/libc/misc/wctype/_wctype.c b/libc/misc/wctype/_wctype.c
index 0f19cad04..25419b500 100644
--- a/libc/misc/wctype/_wctype.c
+++ b/libc/misc/wctype/_wctype.c
@@ -37,7 +37,7 @@
#include <stdint.h>
#include <bits/uClibc_uwchar.h>
-libc_hidden_proto(strcmp)
+/* Experimentally off - libc_hidden_proto(strcmp) */
libc_hidden_proto(tolower)
libc_hidden_proto(toupper)
libc_hidden_proto(towlower)
@@ -55,7 +55,7 @@ libc_hidden_proto(towlower_l)
libc_hidden_proto(towupper_l)
libc_hidden_proto(towctrans_l)
libc_hidden_proto(iswctype_l)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif /* __UCLIBC_HAS_XLOCALE__ */
diff --git a/libc/misc/wordexp/wordexp.c b/libc/misc/wordexp/wordexp.c
index 58094dbc7..358586f75 100644
--- a/libc/misc/wordexp/wordexp.c
+++ b/libc/misc/wordexp/wordexp.c
@@ -35,15 +35,15 @@
#include <glob.h>
#include <wordexp.h>
-libc_hidden_proto(mempcpy)
-libc_hidden_proto(stpcpy)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strdup)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strndup)
-libc_hidden_proto(strspn)
-libc_hidden_proto(strcspn)
+/* Experimentally off - libc_hidden_proto(mempcpy) */
+/* Experimentally off - libc_hidden_proto(stpcpy) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strdup) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strndup) */
+/* Experimentally off - libc_hidden_proto(strspn) */
+/* Experimentally off - libc_hidden_proto(strcspn) */
libc_hidden_proto(setenv)
libc_hidden_proto(unsetenv)
libc_hidden_proto(waitpid)
@@ -70,7 +70,7 @@ libc_hidden_proto(globfree)
libc_hidden_proto(wordfree)
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
@@ -1076,8 +1076,7 @@ parse_comm(char **word, size_t * word_length, size_t * max_length,
}
/* Premature end */
- if (comm)
- free(comm);
+ free(comm);
return WRDE_SYNTAX;
}
@@ -1370,8 +1369,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length,
&buffer[20]);
*word = w_addstr(*word, word_length, max_length, value);
free(env);
- if (pattern)
- free(pattern);
+ free(pattern);
return *word ? 0 : WRDE_NOSPACE;
}
/* Is it `$*' or `$@' (unquoted) ? */
@@ -1530,8 +1528,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length,
if (free_value)
free(value);
- if (expanded)
- free(expanded);
+ free(expanded);
goto do_error;
}
@@ -1550,8 +1547,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length,
if (free_value)
free(value);
- if (expanded)
- free(expanded);
+ free(expanded);
goto do_error;
}
@@ -1573,8 +1569,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length,
goto no_space;
}
- if (pattern)
- free(pattern);
+ free(pattern);
pattern = expanded;
}
@@ -1723,7 +1718,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length,
/* Substitute parameter */
break;
- if (free_value && value)
+ if (free_value)
free(value);
if (!colon_seen && value)
@@ -1740,7 +1735,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length,
case ACT_NONNULL_SUBST:
if (value && (*value || !colon_seen)) {
- if (free_value && value)
+ if (free_value)
free(value);
value = pattern ? strdup(pattern) : pattern;
@@ -1769,7 +1764,7 @@ parse_param(char **word, size_t * word_length, size_t * max_length,
goto success;
}
- if (free_value && value)
+ if (free_value)
free(value);
value = pattern ? strdup(pattern) : pattern;
@@ -1895,11 +1890,9 @@ parse_param(char **word, size_t * word_length, size_t * max_length,
error = WRDE_SYNTAX;
do_error:
- if (env)
- free(env);
+ free(env);
- if (pattern)
- free(pattern);
+ free(pattern);
return error;
}
@@ -2269,8 +2262,7 @@ int wordexp(const char *words, wordexp_t * we, int flags)
* set we members back to what they were.
*/
- if (word != NULL)
- free(word);
+ free(word);
if (error == WRDE_NOSPACE)
return WRDE_NOSPACE;
diff --git a/libc/pwd_grp/lckpwdf.c b/libc/pwd_grp/lckpwdf.c
index 964753458..0b0fb471b 100644
--- a/libc/pwd_grp/lckpwdf.c
+++ b/libc/pwd_grp/lckpwdf.c
@@ -28,7 +28,7 @@
#include <paths.h>
#include <shadow.h>
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(open)
libc_hidden_proto(fcntl)
libc_hidden_proto(close)
@@ -48,13 +48,8 @@ libc_hidden_proto(alarm)
static int lock_fd = -1;
/* Prevent problems in multithreaded program by using mutex. */
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-#include <pthreadP.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
/* Prototypes for local functions. */
@@ -71,19 +66,19 @@ lckpwdf (void)
struct sigaction new_act; /* New signal action. */
struct flock fl; /* Information struct for locking. */
int result;
+ int rv = -1;
if (lock_fd != -1)
/* Still locked by own process. */
return -1;
/* Prevent problems caused by multiple threads. */
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
lock_fd = open (_PATH_PASSWD, O_WRONLY);
if (lock_fd == -1) {
/* Cannot create lock file. */
- UNLOCK;
- return -1;
+ goto DONE;
}
/* Make sure file gets correctly closed when process finished. */
@@ -92,16 +87,14 @@ lckpwdf (void)
/* Cannot get file flags. */
close(lock_fd);
lock_fd = -1;
- UNLOCK;
- return -1;
+ goto DONE;
}
flags |= FD_CLOEXEC; /* Close on exit. */
if (fcntl (lock_fd, F_SETFD, flags) < 0) {
/* Cannot set new flags. */
close(lock_fd);
lock_fd = -1;
- UNLOCK;
- return -1;
+ goto DONE;
}
/* Now we have to get exclusive write access. Since multiple
@@ -122,8 +115,7 @@ lckpwdf (void)
/* Cannot install signal handler. */
close(lock_fd);
lock_fd = -1;
- UNLOCK;
- return -1;
+ goto DONE;
}
/* Now make sure the alarm signal is not blocked. */
@@ -133,8 +125,7 @@ lckpwdf (void)
sigaction (SIGALRM, &saved_act, NULL);
close(lock_fd);
lock_fd = -1;
- UNLOCK;
- return -1;
+ goto DONE;
}
/* Start timer. If we cannot get the lock in the specified time we
@@ -161,11 +152,12 @@ lckpwdf (void)
if (result < 0) {
close(lock_fd);
lock_fd = -1;
- UNLOCK;
- return -1;
+ goto DONE;
}
+ rv = 0;
- UNLOCK;
+DONE:
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return 0;
}
@@ -181,7 +173,7 @@ ulckpwdf (void)
else
{
/* Prevent problems caused by multiple threads. */
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
result = close (lock_fd);
@@ -189,7 +181,7 @@ ulckpwdf (void)
lock_fd = -1;
/* Clear mutex. */
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
return result;
diff --git a/libc/pwd_grp/pwd_grp.c b/libc/pwd_grp/pwd_grp.c
index 2a9d4519a..217ed39a7 100644
--- a/libc/pwd_grp/pwd_grp.c
+++ b/libc/pwd_grp/pwd_grp.c
@@ -34,14 +34,12 @@
#ifdef __UCLIBC_HAS_SHADOW__
#include <shadow.h>
#endif
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-#endif
+#include <bits/uClibc_mutex.h>
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(strtoul)
libc_hidden_proto(rewind)
libc_hidden_proto(fgets_unlocked)
@@ -52,19 +50,11 @@ libc_hidden_proto(fclose)
libc_hidden_proto(fprintf)
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
/**********************************************************************/
-/* Sizes for statically allocated buffers. */
-
-/* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
- * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
-
-/**********************************************************************/
/* Prototypes for internal functions. */
extern int __parsepwent(void *pw, char *line) attribute_hidden;
@@ -167,7 +157,7 @@ libc_hidden_proto(fgetpwent_r)
struct passwd *fgetpwent(FILE *stream)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd resultbuf;
struct passwd *result;
@@ -185,7 +175,7 @@ libc_hidden_proto(fgetgrent_r)
struct group *fgetgrent(FILE *stream)
{
- static char buffer[GRP_BUFFER_SIZE];
+ static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group resultbuf;
struct group *result;
@@ -202,7 +192,7 @@ libc_hidden_proto(fgetspent_r)
struct spwd *fgetspent(FILE *stream)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd resultbuf;
struct spwd *result;
@@ -222,7 +212,7 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
*result = NULL;
- if (buflen < PWD_BUFFER_SIZE) {
+ if (buflen < __UCLIBC_PWD_BUFFER_SIZE__) {
DO_ERANGE:
__set_errno(rv);
goto DONE;
@@ -253,7 +243,7 @@ libc_hidden_def(sgetspent_r)
#ifdef L_getpwnam_r
#define GETXXKEY_R_FUNC getpwnam_r
-#define GETXXKEY_R_PARSER __parsepwent
+#define GETXXKEY_R_PARSER __parsepwent
#define GETXXKEY_R_ENTTYPE struct passwd
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key))
#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
@@ -263,7 +253,7 @@ libc_hidden_def(sgetspent_r)
#ifdef L_getgrnam_r
#define GETXXKEY_R_FUNC getgrnam_r
-#define GETXXKEY_R_PARSER __parsegrent
+#define GETXXKEY_R_PARSER __parsegrent
#define GETXXKEY_R_ENTTYPE struct group
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key))
#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
@@ -273,7 +263,7 @@ libc_hidden_def(sgetspent_r)
#ifdef L_getspnam_r
#define GETXXKEY_R_FUNC getspnam_r
-#define GETXXKEY_R_PARSER __parsespent
+#define GETXXKEY_R_PARSER __parsespent
#define GETXXKEY_R_ENTTYPE struct spwd
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key))
#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
@@ -283,7 +273,7 @@ libc_hidden_def(sgetspent_r)
#ifdef L_getpwuid_r
#define GETXXKEY_R_FUNC getpwuid_r
-#define GETXXKEY_R_PARSER __parsepwent
+#define GETXXKEY_R_PARSER __parsepwent
#define GETXXKEY_R_ENTTYPE struct passwd
#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
#define DO_GETXXKEY_R_KEYTYPE uid_t
@@ -293,7 +283,7 @@ libc_hidden_def(sgetspent_r)
#ifdef L_getgrgid_r
#define GETXXKEY_R_FUNC getgrgid_r
-#define GETXXKEY_R_PARSER __parsegrent
+#define GETXXKEY_R_PARSER __parsegrent
#define GETXXKEY_R_ENTTYPE struct group
#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
#define DO_GETXXKEY_R_KEYTYPE gid_t
@@ -308,7 +298,7 @@ libc_hidden_proto(getpwuid_r)
struct passwd *getpwuid(uid_t uid)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd resultbuf;
struct passwd *result;
@@ -324,7 +314,7 @@ libc_hidden_proto(getgrgid_r)
struct group *getgrgid(gid_t gid)
{
- static char buffer[GRP_BUFFER_SIZE];
+ static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group resultbuf;
struct group *result;
@@ -350,7 +340,7 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
int rv;
struct passwd *pp;
struct passwd password;
- char pwd_buff[PWD_BUFFER_SIZE];
+ char pwd_buff[__UCLIBC_PWD_BUFFER_SIZE__];
*result = NULL;
if (!(rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp))) {
@@ -371,7 +361,7 @@ libc_hidden_proto(getspuid_r)
struct spwd *getspuid(uid_t uid)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd resultbuf;
struct spwd *result;
@@ -387,7 +377,7 @@ libc_hidden_proto(getpwnam_r)
struct passwd *getpwnam(const char *name)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd resultbuf;
struct passwd *result;
@@ -403,7 +393,7 @@ libc_hidden_proto(getgrnam_r)
struct group *getgrnam(const char *name)
{
- static char buffer[GRP_BUFFER_SIZE];
+ static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group resultbuf;
struct group *result;
@@ -419,7 +409,7 @@ libc_hidden_proto(getspnam_r)
struct spwd *getspnam(const char *name)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd resultbuf;
struct spwd *result;
@@ -437,7 +427,7 @@ int getpw(uid_t uid, char *buf)
{
struct passwd resultbuf;
struct passwd *result;
- char buffer[PWD_BUFFER_SIZE];
+ char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
if (!buf) {
__set_errno(EINVAL);
@@ -458,47 +448,40 @@ int getpw(uid_t uid, char *buf)
#endif
/**********************************************************************/
-#if defined(L_getpwent_r) || defined(L_getgrent_r) || defined(L_getspent_r)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
-#endif
#ifdef L_getpwent_r
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
static FILE *pwf /*= NULL*/;
void setpwent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (pwf) {
rewind(pwf);
}
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
void endpwent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (pwf) {
fclose(pwf);
pwf = NULL;
}
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_proto(getpwent_r)
-int getpwent_r(struct passwd *__restrict resultbuf,
+int getpwent_r(struct passwd *__restrict resultbuf,
char *__restrict buffer, size_t buflen,
struct passwd **__restrict result)
{
int rv;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
*result = NULL; /* In case of error... */
@@ -516,7 +499,7 @@ int getpwent_r(struct passwd *__restrict resultbuf,
}
ERR:
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return rv;
}
@@ -525,26 +508,27 @@ libc_hidden_def(getpwent_r)
#endif
/**********************************************************************/
#ifdef L_getgrent_r
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
static FILE *grf /*= NULL*/;
void setgrent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (grf) {
rewind(grf);
}
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
void endgrent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (grf) {
fclose(grf);
grf = NULL;
}
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_proto(getgrent_r)
@@ -554,7 +538,7 @@ int getgrent_r(struct group *__restrict resultbuf,
{
int rv;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
*result = NULL; /* In case of error... */
@@ -572,7 +556,7 @@ int getgrent_r(struct group *__restrict resultbuf,
}
ERR:
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return rv;
}
@@ -581,35 +565,36 @@ libc_hidden_def(getgrent_r)
#endif
/**********************************************************************/
#ifdef L_getspent_r
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
static FILE *spf /*= NULL*/;
void setspent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (spf) {
rewind(spf);
}
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
void endspent(void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (spf) {
fclose(spf);
spf = NULL;
}
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
libc_hidden_proto(getspent_r)
-int getspent_r(struct spwd *resultbuf, char *buffer,
+int getspent_r(struct spwd *resultbuf, char *buffer,
size_t buflen, struct spwd **result)
{
int rv;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
*result = NULL; /* In case of error... */
@@ -627,7 +612,7 @@ int getspent_r(struct spwd *resultbuf, char *buffer,
}
ERR:
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return rv;
}
@@ -641,7 +626,7 @@ libc_hidden_proto(getpwent_r)
struct passwd *getpwent(void)
{
- static char line_buff[PWD_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd pwd;
struct passwd *result;
@@ -657,7 +642,7 @@ libc_hidden_proto(getgrent_r)
struct group *getgrent(void)
{
- static char line_buff[GRP_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group gr;
struct group *result;
@@ -673,7 +658,7 @@ libc_hidden_proto(getspent_r)
struct spwd *getspent(void)
{
- static char line_buff[PWD_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd spwd;
struct spwd *result;
@@ -689,7 +674,7 @@ libc_hidden_proto(sgetspent_r)
struct spwd *sgetspent(const char *string)
{
- static char line_buff[PWD_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd spwd;
struct spwd *result;
@@ -712,7 +697,7 @@ int initgroups(const char *user, gid_t gid)
int num_groups, rv;
char **m;
struct group group;
- char buff[PWD_BUFFER_SIZE];
+ char buff[__UCLIBC_PWD_BUFFER_SIZE__];
rv = -1;
@@ -842,11 +827,11 @@ int putgrent(const struct group *__restrict p, FILE *__restrict f)
static const unsigned char _sp_off[] = {
offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */
- offsetof(struct spwd, sp_min), /* 3 - not a char ptr */
+ offsetof(struct spwd, sp_min), /* 3 - not a char ptr */
offsetof(struct spwd, sp_max), /* 4 - not a char ptr */
- offsetof(struct spwd, sp_warn), /* 5 - not a char ptr */
- offsetof(struct spwd, sp_inact), /* 6 - not a char ptr */
- offsetof(struct spwd, sp_expire), /* 7 - not a char ptr */
+ offsetof(struct spwd, sp_warn), /* 5 - not a char ptr */
+ offsetof(struct spwd, sp_inact), /* 6 - not a char ptr */
+ offsetof(struct spwd, sp_expire), /* 7 - not a char ptr */
};
int putspent(const struct spwd *p, FILE *stream)
@@ -899,13 +884,13 @@ int putspent(const struct spwd *p, FILE *stream)
#ifdef L___parsepwent
static const unsigned char pw_off[] = {
- offsetof(struct passwd, pw_name), /* 0 */
+ offsetof(struct passwd, pw_name), /* 0 */
offsetof(struct passwd, pw_passwd), /* 1 */
offsetof(struct passwd, pw_uid), /* 2 - not a char ptr */
- offsetof(struct passwd, pw_gid), /* 3 - not a char ptr */
+ offsetof(struct passwd, pw_gid), /* 3 - not a char ptr */
offsetof(struct passwd, pw_gecos), /* 4 */
- offsetof(struct passwd, pw_dir), /* 5 */
- offsetof(struct passwd, pw_shell) /* 6 */
+ offsetof(struct passwd, pw_dir), /* 5 */
+ offsetof(struct passwd, pw_shell) /* 6 */
};
int attribute_hidden __parsepwent(void *data, char *line)
@@ -918,7 +903,7 @@ int attribute_hidden __parsepwent(void *data, char *line)
do {
p = ((char *) ((struct passwd *) data)) + pw_off[i];
- if ((i & 6) ^ 2) { /* i!=2 and i!=3 */
+ if ((i & 6) ^ 2) { /* i!=2 and i!=3 */
*((char **) p) = line;
if (i==6) {
return 0;
@@ -958,7 +943,7 @@ int attribute_hidden __parsepwent(void *data, char *line)
#ifdef L___parsegrent
static const unsigned char gr_off[] = {
- offsetof(struct group, gr_name), /* 0 */
+ offsetof(struct group, gr_name), /* 0 */
offsetof(struct group, gr_passwd), /* 1 */
offsetof(struct group, gr_gid) /* 2 - not a char ptr */
};
@@ -1040,7 +1025,7 @@ int attribute_hidden __parsegrent(void *data, char *line)
if (!--i) break;
while (*++p) {}
} while (1);
- }
+ }
*members = NULL;
return 0;
@@ -1059,12 +1044,12 @@ static const unsigned char sp_off[] = {
offsetof(struct spwd, sp_namp), /* 0 */
offsetof(struct spwd, sp_pwdp), /* 1 */
offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */
- offsetof(struct spwd, sp_min), /* 3 - not a char ptr */
+ offsetof(struct spwd, sp_min), /* 3 - not a char ptr */
offsetof(struct spwd, sp_max), /* 4 - not a char ptr */
- offsetof(struct spwd, sp_warn), /* 5 - not a char ptr */
- offsetof(struct spwd, sp_inact), /* 6 - not a char ptr */
- offsetof(struct spwd, sp_expire), /* 7 - not a char ptr */
- offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */
+ offsetof(struct spwd, sp_warn), /* 5 - not a char ptr */
+ offsetof(struct spwd, sp_inact), /* 6 - not a char ptr */
+ offsetof(struct spwd, sp_expire), /* 7 - not a char ptr */
+ offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */
};
int attribute_hidden __parsespent(void *data, char * line)
@@ -1141,7 +1126,7 @@ int attribute_hidden __pgsreader(int (*__parserfunc)(void *d, char *line), void
int rv = ERANGE;
__STDIO_AUTO_THREADLOCK_VAR;
- if (buflen < PWD_BUFFER_SIZE) {
+ if (buflen < __UCLIBC_PWD_BUFFER_SIZE__) {
__set_errno(rv);
} else {
__STDIO_AUTO_THREADLOCK(f);
diff --git a/libc/signal/killpg.c b/libc/signal/killpg.c
index 6de79a714..46b6e4b35 100644
--- a/libc/signal/killpg.c
+++ b/libc/signal/killpg.c
@@ -25,9 +25,7 @@ libc_hidden_proto(kill)
If PGRP is zero, send SIG to all processes in
the current process's process group. */
int
-killpg (pgrp, sig)
- __pid_t pgrp;
- int sig;
+killpg (__pid_t pgrp, int sig)
{
if (pgrp < 0)
{
diff --git a/libc/signal/sigaction.c b/libc/signal/sigaction.c
index 14e3dc9c2..50ab640d5 100644
--- a/libc/signal/sigaction.c
+++ b/libc/signal/sigaction.c
@@ -23,7 +23,7 @@
#include <sys/syscall.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
/* The difference here is that the sigaction structure used in the
kernel is not the same as we use in the libc. Therefore we must
diff --git a/libc/signal/sigaddset.c b/libc/signal/sigaddset.c
index 83721772c..9840a56bf 100644
--- a/libc/signal/sigaddset.c
+++ b/libc/signal/sigaddset.c
@@ -21,9 +21,7 @@
/* Add SIGNO to SET. */
libc_hidden_proto(sigaddset)
int
-sigaddset (set, signo)
- sigset_t *set;
- int signo;
+sigaddset (sigset_t *set, int signo)
{
if (set == NULL || signo <= 0 || signo >= NSIG)
{
diff --git a/libc/signal/sigandset.c b/libc/signal/sigandset.c
index a25225bad..dcc37daba 100644
--- a/libc/signal/sigandset.c
+++ b/libc/signal/sigandset.c
@@ -22,11 +22,7 @@
#include <stddef.h>
/* Combine sets LEFT and RIGHT by logical AND and place result in DEST. */
-int
-sigandset (dest, left, right)
- sigset_t *dest;
- const sigset_t *left;
- const sigset_t *right;
+int sigandset (sigset_t *dest, const sigset_t *left, const sigset_t *right)
{
if (dest == NULL || left == NULL || right == NULL)
{
diff --git a/libc/signal/sigempty.c b/libc/signal/sigempty.c
index e642e9335..7d8687bd1 100644
--- a/libc/signal/sigempty.c
+++ b/libc/signal/sigempty.c
@@ -20,13 +20,11 @@
#include <signal.h>
#include <string.h>
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
/* Clear all signals from SET. */
libc_hidden_proto(sigemptyset)
-int
-sigemptyset (set)
- sigset_t *set;
+int sigemptyset (sigset_t *set)
{
if (set == NULL)
{
diff --git a/libc/signal/sigfillset.c b/libc/signal/sigfillset.c
index 83e47937d..96ab459dc 100644
--- a/libc/signal/sigfillset.c
+++ b/libc/signal/sigfillset.c
@@ -20,7 +20,7 @@
#include <signal.h>
#include <string.h>
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
/* Set all signals in SET. */
libc_hidden_proto(sigfillset)
diff --git a/libc/signal/sighold.c b/libc/signal/sighold.c
index 335af4a34..da723ac86 100644
--- a/libc/signal/sighold.c
+++ b/libc/signal/sighold.c
@@ -25,9 +25,7 @@
libc_hidden_proto(sigprocmask)
libc_hidden_proto(sigaddset)
-int
-sighold (sig)
- int sig;
+int sighold (int sig)
{
sigset_t set;
diff --git a/libc/signal/sigignore.c b/libc/signal/sigignore.c
index c4d347f8d..17d93ce19 100644
--- a/libc/signal/sigignore.c
+++ b/libc/signal/sigignore.c
@@ -26,9 +26,7 @@
libc_hidden_proto(sigaction)
-int
-sigignore (sig)
- int sig;
+int sigignore (int sig)
{
struct sigaction act;
diff --git a/libc/signal/sigintr.c b/libc/signal/sigintr.c
index a977e22de..43136379f 100644
--- a/libc/signal/sigintr.c
+++ b/libc/signal/sigintr.c
@@ -29,10 +29,7 @@ libc_hidden_proto(sigaction)
extern sigset_t _sigintr attribute_hidden; /* Defined in signal.c. */
#endif
-int
-siginterrupt (sig, interrupt)
- int sig;
- int interrupt;
+int siginterrupt (int sig, int interrupt)
{
#ifdef SA_RESTART
struct sigaction action;
diff --git a/libc/signal/sigisempty.c b/libc/signal/sigisempty.c
index 22baa0038..a25bb473d 100644
--- a/libc/signal/sigisempty.c
+++ b/libc/signal/sigisempty.c
@@ -22,9 +22,7 @@
#include <stddef.h>
/* Test whether SET is empty. */
-int
-sigisemptyset (set)
- const sigset_t *set;
+int sigisemptyset (const sigset_t *set)
{
if (set == NULL)
{
diff --git a/libc/signal/sigismem.c b/libc/signal/sigismem.c
index 6423a1a02..b546f626f 100644
--- a/libc/signal/sigismem.c
+++ b/libc/signal/sigismem.c
@@ -19,10 +19,7 @@
#include "sigsetops.h"
/* Return 1 if SIGNO is in SET, 0 if not. */
-int
-sigismember (set, signo)
- const sigset_t *set;
- int signo;
+int sigismember (const sigset_t *set, int signo)
{
if (set == NULL || signo <= 0 || signo >= NSIG)
{
diff --git a/libc/signal/sigorset.c b/libc/signal/sigorset.c
index 7d7bf863d..3588cc482 100644
--- a/libc/signal/sigorset.c
+++ b/libc/signal/sigorset.c
@@ -22,11 +22,7 @@
#include <stddef.h>
/* Combine sets LEFT and RIGHT by logical OR and place result in DEST. */
-int
-sigorset (dest, left, right)
- sigset_t *dest;
- const sigset_t *left;
- const sigset_t *right;
+int sigorset (sigset_t *dest, const sigset_t *left, const sigset_t *right)
{
if (dest == NULL || left == NULL || right == NULL)
{
diff --git a/libc/signal/sigrelse.c b/libc/signal/sigrelse.c
index a1d5a8849..8532a88f3 100644
--- a/libc/signal/sigrelse.c
+++ b/libc/signal/sigrelse.c
@@ -25,9 +25,7 @@
libc_hidden_proto(sigprocmask)
libc_hidden_proto(sigdelset)
-int
-sigrelse (sig)
- int sig;
+int sigrelse (int sig)
{
sigset_t set;
diff --git a/libc/signal/sigset.c b/libc/signal/sigset.c
index 5d8c0d0bd..db1fb7d74 100644
--- a/libc/signal/sigset.c
+++ b/libc/signal/sigset.c
@@ -26,10 +26,7 @@ libc_hidden_proto(sigaction)
libc_hidden_proto(sigprocmask)
/* Set the disposition for SIG. */
-__sighandler_t
-sigset (sig, disp)
- int sig;
- __sighandler_t disp;
+__sighandler_t sigset (int sig, __sighandler_t disp)
{
struct sigaction act, oact;
sigset_t set;
diff --git a/libc/signal/sysv_signal.c b/libc/signal/sysv_signal.c
index 97857a250..6eebf201b 100644
--- a/libc/signal/sysv_signal.c
+++ b/libc/signal/sysv_signal.c
@@ -35,10 +35,7 @@ libc_hidden_proto(sigaction)
/* Set the handler for the signal SIG to HANDLER,
returning the old handler, or SIG_ERR on error. */
-__sighandler_t
-__sysv_signal (sig, handler)
- int sig;
- __sighandler_t handler;
+__sighandler_t __sysv_signal (int sig, __sighandler_t handler)
{
struct sigaction act, oact;
diff --git a/libc/stdio/_READ.c b/libc/stdio/_READ.c
index 0c7febb3c..bafa8dffe 100644
--- a/libc/stdio/_READ.c
+++ b/libc/stdio/_READ.c
@@ -44,7 +44,7 @@ size_t attribute_hidden __stdio_READ(register FILE *stream,
#warning EINTR?
#endif
/* RETRY: */
- if ((rv = __READ(stream, buf, bufsize)) <= 0) {
+ if ((rv = __READ(stream, (char *) buf, bufsize)) <= 0) {
if (rv == 0) {
__STDIO_STREAM_SET_EOF(stream);
} else {
diff --git a/libc/stdio/_WRITE.c b/libc/stdio/_WRITE.c
index 2bd0977fd..83714bd4c 100644
--- a/libc/stdio/_WRITE.c
+++ b/libc/stdio/_WRITE.c
@@ -49,7 +49,7 @@ size_t attribute_hidden __stdio_WRITE(register FILE *stream,
return bufsize;
}
stodo = (todo <= SSIZE_MAX) ? todo : SSIZE_MAX;
- if ((rv = __WRITE(stream, buf, stodo)) >= 0) {
+ if ((rv = __WRITE(stream, (char *) buf, stodo)) >= 0) {
#ifdef __UCLIBC_MJN3_ONLY__
#warning TODO: Make custom stream write return check optional.
#endif
diff --git a/libc/stdio/_fopen.c b/libc/stdio/_fopen.c
index 58066ea3f..d68f2ead1 100644
--- a/libc/stdio/_fopen.c
+++ b/libc/stdio/_fopen.c
@@ -76,13 +76,13 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
while (*++mode) {
# ifdef __UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE__
- if (*mode == 'x') { /* Open exclusive (a glibc extension). */
+ if (*mode == 'x') { /* Open exclusive (a glibc extension). */
open_mode |= O_EXCL;
continue;
}
# endif
# ifdef __UCLIBC_HAS_FOPEN_LARGEFILE_MODE__
- if (*mode == 'F') { /* Open as large file (uClibc extension). */
+ if (*mode == 'F') { /* Open as large file (uClibc extension). */
open_mode |= O_LARGEFILE;
continue;
}
@@ -102,11 +102,7 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
#ifdef __UCLIBC_HAS_THREADS__
/* We only initialize the mutex in the non-freopen case. */
/* stream->__user_locking = _stdio_user_locking; */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (stream->_lock);
-#else
- __stdio_init_mutex(&stream->__lock);
-#endif
+ STDIO_INIT_MUTEX(stream->__lock);
#endif
}
@@ -198,18 +194,27 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
#ifdef __UCLIBC_HAS_THREADS__
/* Even in the freopen case, we reset the user locking flag. */
stream->__user_locking = _stdio_user_locking;
-#ifdef __USE_STDIO_FUTEXES__
- /* _IO_lock_init (stream->_lock); */
-#else
- /* __stdio_init_mutex(&stream->__lock); */
-#endif
+ /* STDIO_INIT_MUTEX(stream->__lock); */
#endif
#ifdef __STDIO_HAS_OPENLIST
- __STDIO_THREADLOCK_OPENLIST;
- stream->__nextopen = _stdio_openlist; /* New files are inserted at */
- _stdio_openlist = stream; /* the head of the list. */
- __STDIO_THREADUNLOCK_OPENLIST;
+#if defined(__UCLIBC_HAS_THREADS__) && defined(__STDIO_BUFFERS)
+ if (!(stream->__modeflags & __FLAG_FREEFILE))
+ {
+ /* An freopen call so the file was never removed from the list. */
+ }
+ else
+#endif
+ {
+ /* We have to lock the del mutex in case another thread wants to fclose()
+ * the last file. */
+ __STDIO_THREADLOCK_OPENLIST_DEL;
+ __STDIO_THREADLOCK_OPENLIST_ADD;
+ stream->__nextopen = _stdio_openlist; /* New files are inserted at */
+ _stdio_openlist = stream; /* the head of the list. */
+ __STDIO_THREADUNLOCK_OPENLIST_ADD;
+ __STDIO_THREADUNLOCK_OPENLIST_DEL;
+ }
#endif
__STDIO_STREAM_VALIDATE(stream);
diff --git a/libc/stdio/_fpmaxtostr.c b/libc/stdio/_fpmaxtostr.c
index f5632337d..2a63fda9d 100644
--- a/libc/stdio/_fpmaxtostr.c
+++ b/libc/stdio/_fpmaxtostr.c
@@ -11,7 +11,7 @@
#include <locale.h>
#include <bits/uClibc_fpmax.h>
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
typedef size_t (__fp_outfunc_t)(FILE *fp, intptr_t type, intptr_t len,
intptr_t buf);
diff --git a/libc/stdio/_fwrite.c b/libc/stdio/_fwrite.c
index 1e0f7ceee..ba4b02fb1 100644
--- a/libc/stdio/_fwrite.c
+++ b/libc/stdio/_fwrite.c
@@ -7,9 +7,9 @@
#include "_stdio.h"
-libc_hidden_proto(memchr)
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memrchr)
+/* Experimentally off - libc_hidden_proto(memchr) */
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memrchr) */
#ifdef __STDIO_BUFFERS
diff --git a/libc/stdio/_scanf.c b/libc/stdio/_scanf.c
index 2957d6748..cb768cffb 100644
--- a/libc/stdio/_scanf.c
+++ b/libc/stdio/_scanf.c
@@ -77,10 +77,10 @@
#include <bits/uClibc_fpmax.h>
#endif /* __UCLIBC_HAS_FLOATS__ */
-libc_hidden_proto(memcmp)
-libc_hidden_proto(memset)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(memcmp) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(ungetc)
libc_hidden_proto(vfscanf)
libc_hidden_proto(vsscanf)
@@ -100,7 +100,7 @@ libc_hidden_proto(fgetwc_unlocked)
#endif
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
@@ -265,17 +265,13 @@ int vsscanf(__const char *sp, __const char *fmt, va_list ap)
#ifdef __UCLIBC_HAS_THREADS__
f.__user_locking = 1; /* Set user locking. */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (f._lock);
-#else
- __stdio_init_mutex(&f.__lock);
-#endif
+ STDIO_INIT_MUTEX(f.__lock);
#endif
f.__nextopen = NULL;
/* Set these last since __bufgetc initialization depends on
* __user_locking and only gets set if user locking is on. */
- f.__bufstart =
+ f.__bufstart =
f.__bufpos = (unsigned char *) ((void *) sp);
f.__bufread =
f.__bufend = f.__bufstart + strlen(sp);
@@ -317,11 +313,7 @@ int vsscanf(__const char *sp, __const char *fmt, va_list ap)
#ifdef __UCLIBC_HAS_THREADS__
f.f.__user_locking = 1; /* Set user locking. */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (f.f._lock);
-#else
- __stdio_init_mutex(&f.f.__lock);
-#endif
+ STDIO_INIT_MUTEX(f.f.__lock);
#endif
f.f.__nextopen = NULL;
@@ -454,11 +446,7 @@ int vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict format,
#ifdef __UCLIBC_HAS_THREADS__
f.__user_locking = 1; /* Set user locking. */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (f._lock);
-#else
- __stdio_init_mutex(&f.__lock);
-#endif
+ STDIO_INIT_MUTEX(f.__lock);
#endif
f.__nextopen = NULL;
@@ -518,7 +506,7 @@ enum {
FLAG_THOUSANDS = 0x20,
FLAG_I18N = 0x40, /* only works for d, i, u */
FLAG_MALLOC = 0x80, /* only works for s, S, and [ (and l[)*/
-};
+};
#define SPEC_RANGES { CONV_n, CONV_p, CONV_i, CONV_A, \
@@ -743,7 +731,7 @@ void attribute_hidden __init_scan_cookie(register struct scan_cookie *sc,
sc->decpt = __UCLIBC_CURLOCALE_DATA.decimal_point;
sc->decpt_len = __UCLIBC_CURLOCALE_DATA.decimal_point_len;
#else /* __UCLIBC_HAS_LOCALE__ */
- sc->fake_decpt = sc->decpt = decpt_str;
+ sc->fake_decpt = sc->decpt = (unsigned char *) decpt_str;
sc->decpt_len = 1;
#endif /* __UCLIBC_HAS_LOCALE__ */
#ifdef __UCLIBC_HAS_WCHAR__
@@ -1036,7 +1024,7 @@ static int scan_getwc(register struct scan_cookie *sc)
__set_errno(EILSEQ); /* In case of incomplete conversion. */
sc->mb_fail = 1;
}
-
+
SUCCESS:
sc->width = width; /* Restore width. */
@@ -1080,9 +1068,6 @@ static int sc_getc(register struct scan_cookie *sc)
wc = '.';
} else
#endif /* __UCLIBC_HAS_FLOATS__ */
- if (!__isascii(wc)) {
- wc = '?';
- }
sc->wc = sc->ungot_char = wc;
return (int) wc;
@@ -1378,7 +1363,7 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
if (psfs.conv_num == CONV_percent) {
goto MATCH_CHAR;
- }
+ }
if (psfs.conv_num == CONV_n) {
#ifdef __UCLIBC_MJN3_ONLY__
@@ -1422,7 +1407,6 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
{
b = (psfs.store ? ((unsigned char *) psfs.cur_ptr) : buf);
fail = 1;
-
if (psfs.conv_num == CONV_c) {
if (sc.width == INT_MAX) {
@@ -1463,7 +1447,7 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
if (*++fmt == '^') {
++fmt;
invert = 1;
- }
+ }
memset(scanset, invert, sizeof(scanset));
invert = 1-invert;
@@ -1531,7 +1515,7 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
wb = (psfs.store ? ((wchar_t *) psfs.cur_ptr) : wbuf);
fail = 1;
-
+
if (psfs.conv_num == CONV_C) {
if (sc.width == INT_MAX) {
sc.width = 1;
@@ -1808,7 +1792,6 @@ int attribute_hidden __psfs_do_numeric(psfs_t *psfs, struct scan_cookie *sc)
unsigned char usflag, base;
unsigned char nonzero = 0;
unsigned char seendigit = 0;
-
#ifdef __UCLIBC_MJN3_ONLY__
#warning CONSIDER: What should be returned for an invalid conversion specifier?
@@ -1840,7 +1823,7 @@ int attribute_hidden __psfs_do_numeric(psfs_t *psfs, struct scan_cookie *sc)
if (psfs->store) {
++psfs->cnt;
_store_inttype(psfs->cur_ptr, psfs->dataargtype,
- (uintmax_t) NULL);
+ (uintmax_t)0);
}
return 0;
}
@@ -2101,7 +2084,7 @@ int attribute_hidden __psfs_do_numeric(psfs_t *psfs, struct scan_cookie *sc)
}
++psfs->cnt;
_store_inttype(psfs->cur_ptr, psfs->dataargtype,
- (uintmax_t) STRTOUIM(buf, NULL, base, 1-usflag));
+ (uintmax_t) STRTOUIM((char *) buf, NULL, base, 1-usflag));
}
return 0;
}
@@ -2115,7 +2098,7 @@ int attribute_hidden __psfs_do_numeric(psfs_t *psfs, struct scan_cookie *sc)
p = sc->fake_decpt;
do {
if (!*p) {
- strcpy(b, sc->decpt);
+ strcpy((char *) b, (char *) sc->decpt);
b += sc->decpt_len;
break;
}
@@ -2222,7 +2205,7 @@ int attribute_hidden __psfs_do_numeric(psfs_t *psfs, struct scan_cookie *sc)
assert(seendigit);
seendigit = 0;
nonzero = 0;
-
+
if (sc->cc == '0') {
seendigit = 1;
*b++ = '0';
@@ -2238,7 +2221,7 @@ int attribute_hidden __psfs_do_numeric(psfs_t *psfs, struct scan_cookie *sc)
}
__scan_getc(sc);
}
-
+
if (!seendigit) { /* No digits. Unrecoverable. */
goto DONE_DO_UNGET;
}
@@ -2250,7 +2233,7 @@ int attribute_hidden __psfs_do_numeric(psfs_t *psfs, struct scan_cookie *sc)
{
__fpmax_t x;
char *e;
- x = __strtofpmax(buf, &e, exp_adjust);
+ x = __strtofpmax((char *) buf, &e, exp_adjust);
assert(!*e);
if (psfs->store) {
if (psfs->dataargtype & PA_FLAG_LONG_LONG) {
diff --git a/libc/stdio/_stdio.c b/libc/stdio/_stdio.c
index 4975ef02e..6084abec9 100644
--- a/libc/stdio/_stdio.c
+++ b/libc/stdio/_stdio.c
@@ -7,7 +7,7 @@
#include "_stdio.h"
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(isatty)
/* This is pretty much straight from uClibc, but with one important
@@ -160,14 +160,18 @@ FILE *_stdio_openlist = _stdio_streams;
# ifdef __UCLIBC_HAS_THREADS__
# ifdef __USE_STDIO_FUTEXES__
-# include <bits/stdio-lock.h>
-_IO_lock_t _stdio_openlist_lock = _IO_lock_initializer;
+# define __UCLIBC_IO_MUTEX_INITIALIZER _IO_lock_initializer
# else
-pthread_mutex_t _stdio_openlist_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+# define __UCLIBC_IO_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
# endif
-int _stdio_openlist_delflag = 0;
-# endif
+__UCLIBC_IO_MUTEX_INIT(_stdio_openlist_add_lock, __UCLIBC_IO_MUTEX_INITIALIZER);
+# ifdef __STDIO_BUFFERS
+__UCLIBC_IO_MUTEX_INIT(_stdio_openlist_del_lock, __UCLIBC_IO_MUTEX_INITIALIZER);
+volatile int _stdio_openlist_use_count = 0;
+int _stdio_openlist_del_count = 0;
+# endif
+# endif
#endif
/**********************************************************************/
#ifdef __UCLIBC_HAS_THREADS__
@@ -175,15 +179,13 @@ int _stdio_openlist_delflag = 0;
/* 2 if threading not initialized and 0 otherwise; */
int _stdio_user_locking = 2;
-#ifndef __USE_STDIO_FUTEXES__
-void attribute_hidden __stdio_init_mutex(pthread_mutex_t *m)
+void attribute_hidden __stdio_init_mutex(__UCLIBC_MUTEX_TYPE *m)
{
- static const pthread_mutex_t __stdio_mutex_initializer
- = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+ const __UCLIBC_MUTEX_STATIC(__stdio_mutex_initializer,
+ PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
memcpy(m, &__stdio_mutex_initializer, sizeof(__stdio_mutex_initializer));
}
-#endif
#endif
/**********************************************************************/
@@ -198,11 +200,11 @@ void attribute_hidden _stdio_term(void)
/* First, make sure the open file list is unlocked. If it was
* locked, then I suppose there is a chance that a pointer in the
* chain might be corrupt due to a partial store.
- */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (_stdio_openlist_lock);
-#else
- __stdio_init_mutex(&_stdio_openlist_lock);
+ */
+ STDIO_INIT_MUTEX(_stdio_openlist_add_lock);
+#warning check
+#ifdef __STDIO_BUFFERS
+ STDIO_INIT_MUTEX(_stdio_openlist_del_lock);
#endif
/* Next we need to worry about the streams themselves. If a stream
@@ -211,7 +213,7 @@ void attribute_hidden _stdio_term(void)
* Then we reinitialize the locks.
*/
for (ptr = _stdio_openlist ; ptr ; ptr = ptr->__nextopen ) {
- if (__STDIO_ALWAYS_THREADTRYLOCK(ptr)) {
+ if (__STDIO_ALWAYS_THREADTRYLOCK_CANCEL_UNSAFE(ptr)) {
/* The stream is already locked, so we don't want to touch it.
* However, if we have custom streams, we can't just close it
* or leave it locked since a custom stream may be stacked
@@ -222,13 +224,9 @@ void attribute_hidden _stdio_term(void)
__STDIO_STREAM_DISABLE_PUTC(ptr);
__STDIO_STREAM_INIT_BUFREAD_BUFPOS(ptr);
}
-
+
ptr->__user_locking = 1; /* Set locking mode to "by caller". */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (ptr->_lock);
-#else
- __stdio_init_mutex(&ptr->__lock); /* Shouldn't be necessary, but... */
-#endif
+ STDIO_INIT_MUTEX(ptr->__lock); /* Shouldn't be necessary, but... */
}
#endif
diff --git a/libc/stdio/_stdio.h b/libc/stdio/_stdio.h
index 58b013dda..e8ef08983 100644
--- a/libc/stdio/_stdio.h
+++ b/libc/stdio/_stdio.h
@@ -15,39 +15,76 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdarg.h>
#include <unistd.h>
#ifdef __UCLIBC_HAS_WCHAR__
#include <wchar.h>
#endif
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+#include <bits/uClibc_mutex.h>
-#ifdef __USE_STDIO_FUTEXES__
-#define __STDIO_THREADLOCK_OPENLIST \
- _IO_lock_lock(_stdio_openlist_lock)
+#define __STDIO_THREADLOCK_OPENLIST_ADD \
+ __UCLIBC_IO_MUTEX_LOCK(_stdio_openlist_add_lock)
-#define __STDIO_THREADUNLOCK_OPENLIST \
- _IO_lock_unlock(_stdio_openlist_lock)
+#define __STDIO_THREADUNLOCK_OPENLIST_ADD \
+ __UCLIBC_IO_MUTEX_UNLOCK(_stdio_openlist_add_lock)
-#define __STDIO_THREADTRYLOCK_OPENLIST \
- _IO_lock_trylock(_stdio_openlist_lock)
-#else
-#define __STDIO_THREADLOCK_OPENLIST \
- __pthread_mutex_lock(&_stdio_openlist_lock)
+#ifdef __STDIO_BUFFERS
-#define __STDIO_THREADUNLOCK_OPENLIST \
- __pthread_mutex_unlock(&_stdio_openlist_lock)
+#define __STDIO_THREADLOCK_OPENLIST_DEL \
+ __UCLIBC_IO_MUTEX_LOCK(_stdio_openlist_del_lock)
-#define __STDIO_THREADTRYLOCK_OPENLIST \
- __pthread_mutex_trylock(&_stdio_openlist_lock)
-#endif
+#define __STDIO_THREADUNLOCK_OPENLIST_DEL \
+ __UCLIBC_IO_MUTEX_UNLOCK(_stdio_openlist_del_lock)
-#else
-#define __STDIO_THREADLOCK_OPENLIST ((void)0)
-#define __STDIO_THREADUNLOCK_OPENLIST ((void)0)
+#ifdef __UCLIBC_HAS_THREADS__
+#define __STDIO_OPENLIST_INC_USE \
+do { \
+ __STDIO_THREADLOCK_OPENLIST_DEL; \
+ ++_stdio_openlist_use_count; \
+ __STDIO_THREADUNLOCK_OPENLIST_DEL; \
+} while (0)
+
+extern void _stdio_openlist_dec_use(void);
+
+#define __STDIO_OPENLIST_DEC_USE \
+ _stdio_openlist_dec_use()
+
+#define __STDIO_OPENLIST_INC_DEL_CNT \
+do { \
+ __STDIO_THREADLOCK_OPENLIST_DEL; \
+ ++_stdio_openlist_del_count; \
+ __STDIO_THREADUNLOCK_OPENLIST_DEL; \
+} while (0)
+
+#define __STDIO_OPENLIST_DEC_DEL_CNT \
+do { \
+ __STDIO_THREADLOCK_OPENLIST_DEL; \
+ --_stdio_openlist_del_count; \
+ __STDIO_THREADUNLOCK_OPENLIST_DEL; \
+} while (0)
+
+#endif /* __UCLIBC_HAS_THREADS__ */
+#endif /* __STDIO_BUFFERS */
+#ifndef __STDIO_THREADLOCK_OPENLIST_DEL
+#define __STDIO_THREADLOCK_OPENLIST_DEL ((void)0)
+#endif
+#ifndef __STDIO_THREADUNLOCK_OPENLIST_DEL
+#define __STDIO_THREADUNLOCK_OPENLIST_DEL ((void)0)
+#endif
+#ifndef __STDIO_OPENLIST_INC_USE
+#define __STDIO_OPENLIST_INC_USE ((void)0)
+#endif
+#ifndef __STDIO_OPENLIST_DEC_USE
+#define __STDIO_OPENLIST_DEC_USE ((void)0)
+#endif
+#ifndef __STDIO_OPENLIST_INC_DEL_CNT
+#define __STDIO_OPENLIST_INC_DEL_CNT ((void)0)
+#endif
+#ifndef __STDIO_OPENLIST_DEC_DEL_CNT
+#define __STDIO_OPENLIST_DEC_DEL_CNT ((void)0)
#endif
#define __UNDEFINED_OR_NONPORTABLE ((void)0)
@@ -91,10 +128,10 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr
(read((STREAMPTR)->__filedes,(BUF),(SIZE)))
#define __WRITE(STREAMPTR,BUF,SIZE) \
(write((STREAMPTR)->__filedes,(BUF),(SIZE)))
-#define __CLOSE(STREAMPTR) \
- (close((STREAMPTR)->__filedes))
#define __SEEK(STREAMPTR,PPOS,WHENCE) \
(__stdio_seek((STREAMPTR),(PPOS),(WHENCE)))
+#define __CLOSE(STREAMPTR) \
+ (close((STREAMPTR)->__filedes))
#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
@@ -131,30 +168,30 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr
/**********************************************************************/
#ifdef __UCLIBC_HAS_WCHAR__
-#define __STDIO_STREAM_IS_NARROW_WRITING(S) \
- (((S)->__modeflags & (__FLAG_WRITING|__FLAG_NARROW)) \
+#define __STDIO_STREAM_IS_NARROW_WRITING(S) \
+ (((S)->__modeflags & (__FLAG_WRITING|__FLAG_NARROW)) \
== (__FLAG_WRITING|__FLAG_NARROW))
-#define __STDIO_STREAM_IS_WIDE_WRITING(S) \
- (((S)->__modeflags & (__FLAG_WRITING|__FLAG_WIDE)) \
+#define __STDIO_STREAM_IS_WIDE_WRITING(S) \
+ (((S)->__modeflags & (__FLAG_WRITING|__FLAG_WIDE)) \
== (__FLAG_WRITING|__FLAG_WIDE))
#if (__FLAG_NARROW <= __MASK_READING)
#error assumption violated regarding __FLAG_NARROW
#endif
-#define __STDIO_STREAM_IS_NARROW_READING(S) \
+#define __STDIO_STREAM_IS_NARROW_READING(S) \
(((S)->__modeflags & (__MASK_READING|__FLAG_NARROW)) > __FLAG_NARROW)
-#define __STDIO_STREAM_IS_WIDE_READING(S) \
+#define __STDIO_STREAM_IS_WIDE_READING(S) \
(((S)->__modeflags & (__MASK_READING|__FLAG_WIDE)) > __FLAG_WIDE)
#define __STDIO_STREAM_IS_NARROW(S) ((S)->__modeflags & __FLAG_NARROW)
#define __STDIO_STREAM_IS_WIDE(S) ((S)->__modeflags & __FLAG_WIDE)
-#define __STDIO_STREAM_SET_NARROW(S) \
+#define __STDIO_STREAM_SET_NARROW(S) \
((void)((S)->__modeflags |= __FLAG_NARROW))
-#define __STDIO_STREAM_SET_WIDE(S) \
+#define __STDIO_STREAM_SET_WIDE(S) \
((void)((S)->__modeflags |= __FLAG_WIDE))
#else
@@ -163,11 +200,11 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr
#define __STDIO_STREAM_IS_NARROW_READING(S) __STDIO_STREAM_IS_READING(S)
-#define __STDIO_STREAM_IS_NARROW(S) (1)
-#define __STDIO_STREAM_IS_WIDE(S) (0)
+#define __STDIO_STREAM_IS_NARROW(S) (1)
+#define __STDIO_STREAM_IS_WIDE(S) (0)
-#define __STDIO_STREAM_SET_NARROW(S) ((void)0)
-#define __STDIO_STREAM_SET_WIDE(S) ((void)0)
+#define __STDIO_STREAM_SET_NARROW(S) ((void)0)
+#define __STDIO_STREAM_SET_WIDE(S) ((void)0)
#endif
/**********************************************************************/
@@ -197,7 +234,7 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr
#else
# define __STDIO_STREAM_DISABLE_GETC(S) ((void)0)
# define __STDIO_STREAM_ENABLE_GETC(S) ((void)0)
-# define __STDIO_STREAM_CAN_USE_BUFFER_GET(S) (0)
+# define __STDIO_STREAM_CAN_USE_BUFFER_GET(S) (0)
#endif
#ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
@@ -210,26 +247,28 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr
#else
# define __STDIO_STREAM_DISABLE_PUTC(S) ((void)0)
# define __STDIO_STREAM_ENABLE_PUTC(S) ((void)0)
-# define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) (0)
+# define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) (0)
#endif
#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
#define __STDIO_STREAM_IS_CUSTOM(S) ((S)->__cookie != &((S)->__filedes))
#else
-#define __STDIO_STREAM_IS_CUSTOM(S) (0)
+#define __STDIO_STREAM_IS_CUSTOM(S) (0)
#endif
/**********************************************************************/
#ifdef __STDIO_BUFFERS
-#define __STDIO_STREAM_FREE_BUFFER(S) \
- do { if ((S)->__modeflags & __FLAG_FREEBUF) free((S)->__bufstart); } while (0)
+#define __STDIO_STREAM_FREE_BUFFER(S) \
+ do { if ((S)->__modeflags & __FLAG_FREEBUF) \
+ free((S)->__bufstart); } while (0)
#else
#define __STDIO_STREAM_FREE_BUFFER(S) ((void)0)
#endif
#define __STDIO_STREAM_FREE_FILE(S) \
- do { if ((S)->__modeflags & __FLAG_FREEFILE) free((S)); } while (0)
+ do { if ((S)->__modeflags & __FLAG_FREEFILE) \
+ free((S)); } while (0)
#ifdef __UCLIBC_HAS_LFS__
@@ -251,7 +290,7 @@ extern size_t __stdio_wcommit(FILE *__restrict stream) attribute_hidden;
extern size_t __stdio_rfill(FILE *__restrict stream) attribute_hidden;
extern size_t __stdio_fwrite(const unsigned char *__restrict buffer,
- size_t bytes, FILE *__restrict stream) attribute_hidden;
+ size_t bytes, FILE *__restrict stream) attribute_hidden;
#else
#define __stdio_fwrite(B,N,S) __stdio_WRITE((S),(B),(N))
@@ -259,8 +298,9 @@ extern size_t __stdio_fwrite(const unsigned char *__restrict buffer,
#endif
extern size_t __stdio_WRITE(FILE *stream, const unsigned char *buf,
- size_t bufsize) attribute_hidden;
-extern size_t __stdio_READ(FILE *stream, unsigned char *buf, size_t bufsize) attribute_hidden;
+ size_t bufsize) attribute_hidden;
+extern size_t __stdio_READ(FILE *stream, unsigned char *buf,
+ size_t bufsize) attribute_hidden;
extern int __stdio_trans2r(FILE *__restrict stream) attribute_hidden;
extern int __stdio_trans2w(FILE *__restrict stream) attribute_hidden;
@@ -293,14 +333,14 @@ extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidde
/* Valid when reading... */
#define __STDIO_STREAM_BUFFER_RAVAIL(S) ((S)->__bufread - (S)->__bufpos)
#define __STDIO_STREAM_BUFFER_GET(S) (*(S)->__bufpos++)
-#define __STDIO_FILL_READ_BUFFER(S) __stdio_rfill((S))
+#define __STDIO_FILL_READ_BUFFER(S) __stdio_rfill((S))
-#define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) \
+#define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) \
(S)->__bufread = (S)->__bufpos = (S)->__bufstart
#define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES (-2)
-#define __STDIO_STREAM_FAKE_VSSCANF_FILEDES (-2)
+#define __STDIO_STREAM_FAKE_VSSCANF_FILEDES (-2)
#define __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES (-3)
#define __STDIO_STREAM_FAKE_VSWSCANF_FILEDES (-3)
@@ -315,9 +355,9 @@ extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidde
#else /* __STDIO_BUFFERS */
-#define __STDIO_STREAM_IS_FBF(S) (0)
-#define __STDIO_STREAM_IS_LBF(S) (0)
-#define __STDIO_STREAM_IS_NBF(S) (1)
+#define __STDIO_STREAM_IS_FBF(S) (0)
+#define __STDIO_STREAM_IS_LBF(S) (0)
+#define __STDIO_STREAM_IS_NBF(S) (1)
#define __STDIO_STREAM_BUFFER_SIZE(S) (0)
#define __STDIO_STREAM_BUFFER_ADD(S,C) ((void)0)
@@ -329,8 +369,8 @@ extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidde
#define __STDIO_STREAM_BUFFER_RAVAIL(S) (0)
#define __STDIO_STREAM_BUFFER_GET(S) (EOF)
-#define __STDIO_FILL_READ_BUFFER(S) (0)
-#define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) ((void)0)
+#define __STDIO_FILL_READ_BUFFER(S) (0)
+#define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) ((void)0)
#undef __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES
#undef __STDIO_STREAM_FAKE_VSSCANF_FILEDES
@@ -341,14 +381,14 @@ extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidde
#undef __STDIO_STREAM_IS_FAKE_VSWPRINTF
# ifdef __USE_OLD_VFPRINTF__
-# define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB (-2)
-# define __STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(S) \
+# define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB (-2)
+# define __STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(S) \
((S)->__filedes == __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB)
# endif
# ifndef __UCLIBC_HAS_WCHAR__
-# define __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB (-2)
-# define __STDIO_STREAM_IS_FAKE_VSSCANF_NB(S) \
+# define __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB (-2)
+# define __STDIO_STREAM_IS_FAKE_VSSCANF_NB(S) \
((S)->__filedes == __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB)
# endif
@@ -359,7 +399,8 @@ extern int __stdio_adjust_position(FILE *__restrict stream, __offmax_t *pos) att
#ifdef __STDIO_HAS_OPENLIST
/* Uses an implementation hack!!! */
-#define __STDIO_FLUSH_LBF_STREAMS fflush_unlocked((FILE *) &_stdio_openlist)
+#define __STDIO_FLUSH_LBF_STREAMS \
+ fflush_unlocked((FILE *) &_stdio_openlist)
#else
#define __STDIO_FLUSH_LBF_STREAMS ((void)0)
#endif
@@ -382,13 +423,24 @@ extern void _stdio_validate_FILE(const FILE *stream);
/**********************************************************************/
-extern FILE *_stdio_fopen(intptr_t fname_or_mode,
- const char *__restrict mode,
- FILE *__restrict stream, int filedes) attribute_hidden;
+extern FILE *_stdio_fopen(intptr_t fname_or_mode, const char *__restrict mode,
+ FILE *__restrict stream, int filedes) attribute_hidden;
+
+#ifdef __UCLIBC_HAS_WCHAR__
+extern size_t _wstdio_fwrite(const wchar_t *__restrict ws,
+ size_t n, FILE *__restrict stream) attribute_hidden;
+#endif
+
+/**********************************************************************/
+
+extern int _vfprintf_internal (FILE * __restrict stream,
+ const char * __restrict format,
+ va_list arg) attribute_hidden;
#ifdef __UCLIBC_HAS_WCHAR__
-extern size_t _wstdio_fwrite(const wchar_t *__restrict ws, size_t n,
- FILE *__restrict stream) attribute_hidden;
+extern int _vfwprintf_internal (FILE * __restrict stream,
+ const wchar_t * __restrict format,
+ va_list arg) attribute_hidden;
#endif
/**********************************************************************/
diff --git a/libc/stdio/_store_inttype.c b/libc/stdio/_store_inttype.c
index 6eb74fe86..fdd4dce05 100644
--- a/libc/stdio/_store_inttype.c
+++ b/libc/stdio/_store_inttype.c
@@ -35,7 +35,7 @@ void _store_inttype(register void *dest, int desttype, uintmax_t val)
*((unsigned char *) dest) = val;
return;
}
-#if defined(LLONG_MAX) && (LONG_MAX != LLONG_MAX)
+#if defined(LLONG_MAX) && (INT_MAX != LLONG_MAX)
if (desttype == PA_FLAG_LONG_LONG) {
*((unsigned long long int *) dest) = val;
return;
diff --git a/libc/stdio/_uintmaxtostr.c b/libc/stdio/_uintmaxtostr.c
index 4310d6458..7a80371b8 100644
--- a/libc/stdio/_uintmaxtostr.c
+++ b/libc/stdio/_uintmaxtostr.c
@@ -11,7 +11,7 @@
#include <locale.h>
#include <bits/uClibc_uintmaxtostr.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
/* Avoid using long long / and % operations to cut down dependencies on
* libgcc.a. Definitely helps on i386 at least. */
diff --git a/libc/stdio/_vfprintf.c b/libc/stdio/_vfprintf.c
index f4bbb1c1e..947b5b077 100644
--- a/libc/stdio/_vfprintf.c
+++ b/libc/stdio/_vfprintf.c
@@ -101,8 +101,6 @@
#include <stdint.h>
#include <errno.h>
#include <locale.h>
-
-#define __PRINTF_INFO_NO_BITFIELD
#include <printf.h>
#ifdef __UCLIBC_HAS_THREADS__
@@ -117,10 +115,10 @@
#include <bits/uClibc_uintmaxtostr.h>
#include <bits/uClibc_va_copy.h>
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strnlen)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strnlen) */
libc_hidden_proto(__glibc_strerror_r)
libc_hidden_proto(fputs_unlocked)
libc_hidden_proto(abort)
@@ -732,7 +730,7 @@ void attribute_hidden _ppfs_setargs(register ppfs_t *ppfs)
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
@@ -898,7 +896,7 @@ int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs)
) {
return -1;
}
- } while (buf[i++]);
+ } while (buf[i++] && (i < sizeof(buf)));
buf[sizeof(buf)-1] = 0;
}
#else /* __UCLIBC_HAS_WCHAR__ */
@@ -1198,7 +1196,7 @@ int register_printf_function(int spec, printf_function handler,
#endif
/**********************************************************************/
-#if defined(L_vfprintf) || defined(L_vfwprintf)
+#if defined(L__vfprintf_internal) || defined(L__vfwprintf_internal)
/* We only support ascii digits (or their USC equivalent codes) in
* precision and width settings in *printf (wide) format strings.
@@ -1207,14 +1205,15 @@ int register_printf_function(int spec, printf_function handler,
static size_t _charpad(FILE * __restrict stream, int padchar, size_t numpad);
-#ifdef L_vfprintf
+#ifdef L__vfprintf_internal
-#define VFPRINTF vfprintf
+#define VFPRINTF_internal _vfprintf_internal
#define FMT_TYPE char
#define OUTNSTR _outnstr
#define STRLEN strlen
#define _PPFS_init _ppfs_init
-#define OUTPUT(F,S) fputs_unlocked(S,F)
+/* Pulls in fseek: #define OUTPUT(F,S) fputs_unlocked(S,F) */
+#define OUTPUT(F,S) __stdio_fwrite((const unsigned char *)(S),strlen(S),(F))
/* #define _outnstr(stream, string, len) __stdio_fwrite(string, len, stream) */
#define _outnstr(stream, string, len) ((len > 0) ? __stdio_fwrite(string, len, stream) : 0)
#define FP_OUT _fp_out_narrow
@@ -1234,19 +1233,21 @@ static size_t _fp_out_narrow(FILE *fp, intptr_t type, intptr_t len, intptr_t buf
}
len = buflen;
}
- return r + OUTNSTR(fp, (const char *) buf, len);
+ return r + OUTNSTR(fp, (const unsigned char *) buf, len);
}
#endif /* __STDIO_PRINTF_FLOAT */
-#else /* L_vfprintf */
+#else /* L__vfprintf_internal */
-#define VFPRINTF vfwprintf
+#define VFPRINTF_internal _vfwprintf_internal
#define FMT_TYPE wchar_t
#define OUTNSTR _outnwcs
#define STRLEN wcslen
#define _PPFS_init _ppwfs_init
+/* Pulls in fseek: */
#define OUTPUT(F,S) fputws(S,F)
+/* TODO: #define OUTPUT(F,S) _wstdio_fwrite((S),wcslen(S),(F)) */
#define _outnwcs(stream, wstring, len) _wstdio_fwrite(wstring, len, stream)
#define FP_OUT _fp_out_wide
@@ -1417,7 +1418,8 @@ static int _ppwfs_init(register ppfs_t *ppfs, const wchar_t *fmt0)
return 0;
}
-#endif /* L_vfprintf */
+#endif /* L__vfprintf_internal */
+
static size_t _charpad(FILE * __restrict stream, int padchar, size_t numpad)
{
@@ -1427,7 +1429,7 @@ static size_t _charpad(FILE * __restrict stream, int padchar, size_t numpad)
FMT_TYPE pad[1];
*pad = padchar;
- while (todo && (OUTNSTR(stream, pad, 1) == 1)) {
+ while (todo && (OUTNSTR(stream, (const unsigned char *) pad, 1) == 1)) {
--todo;
}
@@ -1439,12 +1441,12 @@ static int _do_one_spec(FILE * __restrict stream,
register ppfs_t *ppfs, int *count)
{
static const char spec_base[] = SPEC_BASE;
-#ifdef L_vfprintf
+#ifdef L__vfprintf_internal
static const char prefix[] = "+\0-\0 \0000x\0000X";
/* 0 2 4 6 9 11*/
-#else /* L_vfprintf */
+#else /* L__vfprintf_internal */
static const wchar_t prefix[] = L"+\0-\0 \0000x\0000X";
-#endif /* L_vfprintf */
+#endif /* L__vfprintf_internal */
enum {
PREFIX_PLUS = 0,
PREFIX_MINUS = 2,
@@ -1465,7 +1467,7 @@ static int _do_one_spec(FILE * __restrict stream,
mbstate_t mbstate;
#endif /* __UCLIBC_HAS_WCHAR__ */
size_t slen;
-#ifdef L_vfprintf
+#ifdef L__vfprintf_internal
#define SLEN slen
#else
size_t SLEN;
@@ -1532,7 +1534,7 @@ static int _do_one_spec(FILE * __restrict stream,
alphacase = __UIM_LOWER;
#ifdef __UCLIBC_MJN3_ONLY__
-#ifdef L_vfprintf
+#ifdef L__vfprintf_internal
#warning CONSIDER: Should we ignore these flags if stub locale? What about custom specs?
#endif
#endif /* __UCLIBC_MJN3_ONLY__ */
@@ -1560,13 +1562,13 @@ static int _do_one_spec(FILE * __restrict stream,
padchar = ppfs->info.pad;
}
#ifdef __UCLIBC_MJN3_ONLY__
-#ifdef L_vfprintf
+#ifdef L__vfprintf_internal
#warning CONSIDER: If using outdigits and/or grouping, how should we interpret precision?
#endif
#endif /* __UCLIBC_MJN3_ONLY__ */
s = _uintmaxtostr(buf + sizeof(buf) - 1,
(uintmax_t)
- _load_inttype(*argtype & __PA_INTMASK,
+ _load_inttype(ppfs->conv_num == CONV_p ? PA_FLAG_LONG : *argtype & __PA_INTMASK,
*argptr, base), base, alphacase);
if (ppfs->conv_num > CONV_u) { /* signed int */
if (*s == '-') {
@@ -1580,7 +1582,7 @@ static int _do_one_spec(FILE * __restrict stream,
}
}
slen = (char *)(buf + sizeof(buf) - 1) - s;
-#ifdef L_vfwprintf
+#ifdef L__vfwprintf_internal
{
const char *q = s;
mbstate.__mask = 0; /* Initialize the mbstate. */
@@ -1605,13 +1607,13 @@ static int _do_one_spec(FILE * __restrict stream,
}
if (ppfs->conv_num == CONV_p) {/* null pointer */
s = "(nil)";
-#ifdef L_vfwprintf
+#ifdef L__vfwprintf_internal
SLEN =
#endif
slen = 5;
numfill = 0;
} else if (numfill == 0) { /* if precision 0, no output */
-#ifdef L_vfwprintf
+#ifdef L__vfwprintf_internal
SLEN =
#endif
slen = 0;
@@ -1637,7 +1639,7 @@ static int _do_one_spec(FILE * __restrict stream,
return -1; /* TODO -- try to continue? */
#endif /* __STDIO_PRINTF_FLOAT */
} else if (ppfs->conv_num <= CONV_S) { /* wide char or string */
-#ifdef L_vfprintf
+#ifdef L__vfprintf_internal
#ifdef __UCLIBC_HAS_WCHAR__
mbstate.__mask = 0; /* Initialize the mbstate. */
@@ -1692,7 +1694,7 @@ static int _do_one_spec(FILE * __restrict stream,
slen = 1;
}
-#else /* L_vfprintf */
+#else /* L__vfprintf_internal */
if (ppfs->conv_num == CONV_S) { /* wide string */
ws = *((wchar_t **) (*argptr));
@@ -1713,7 +1715,7 @@ static int _do_one_spec(FILE * __restrict stream,
if (ppfs->conv_num == CONV_s) { /* string */
#ifdef __UCLIBC_MJN3_ONLY__
-#warning TODO: Fix %s for vfwprintf... output upto illegal sequence?
+#warning TODO: Fix %s for _vfwprintf_internal... output upto illegal sequence?
#endif /* __UCLIBC_MJN3_ONLY__ */
s = *((char **) (*argptr));
if (s) {
@@ -1746,7 +1748,7 @@ static int _do_one_spec(FILE * __restrict stream,
goto CHAR_CASE;
}
-#endif /* L_vfprintf */
+#endif /* L__vfprintf_internal */
#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
} else if (ppfs->conv_num == CONV_m) {
@@ -1778,7 +1780,7 @@ static int _do_one_spec(FILE * __restrict stream,
}
#ifdef __UCLIBC_MJN3_ONLY__
-#ifdef L_vfprintf
+#ifdef L__vfprintf_internal
#warning CONSIDER: If using outdigits and/or grouping, how should we pad?
#endif
#endif /* __UCLIBC_MJN3_ONLY__ */
@@ -1805,11 +1807,12 @@ static int _do_one_spec(FILE * __restrict stream,
numpad = 0;
}
OUTPUT(stream, prefix + prefix_num);
+
if (_charpad(stream, '0', numfill) != numfill) {
return -1;
}
-#ifdef L_vfprintf
+#ifdef L__vfprintf_internal
#ifdef __UCLIBC_HAS_WCHAR__
if (!ws) {
@@ -1831,12 +1834,12 @@ static int _do_one_spec(FILE * __restrict stream,
}
}
#else /* __UCLIBC_HAS_WCHAR__ */
- if (_outnstr(stream, s, slen) != slen) {
+ if (_outnstr(stream, (const unsigned char *) s, slen) != slen) {
return -1;
}
#endif /* __UCLIBC_HAS_WCHAR__ */
-#else /* L_vfprintf */
+#else /* L__vfprintf_internal */
if (!ws) {
assert(s);
@@ -1849,7 +1852,7 @@ static int _do_one_spec(FILE * __restrict stream,
}
}
-#endif /* L_vfprintf */
+#endif /* L__vfprintf_internal */
if (_charpad(stream, ' ', numpad) != numpad) {
return -1;
}
@@ -1860,35 +1863,21 @@ static int _do_one_spec(FILE * __restrict stream,
libc_hidden_proto(fprintf)
-libc_hidden_proto(VFPRINTF)
-int VFPRINTF (FILE * __restrict stream,
- register const FMT_TYPE * __restrict format,
+int VFPRINTF_internal (FILE * __restrict stream,
+ const FMT_TYPE * __restrict format,
va_list arg)
{
ppfs_t ppfs;
int count, r;
register const FMT_TYPE *s;
- __STDIO_AUTO_THREADLOCK_VAR;
-
- __STDIO_AUTO_THREADLOCK(stream);
count = 0;
s = format;
- if
-#ifdef L_vfprintf
- (!__STDIO_STREAM_IS_NARROW_WRITING(stream)
- && __STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW))
-#else
- (!__STDIO_STREAM_IS_WIDE_WRITING(stream)
- && __STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_WIDE))
-#endif
- {
- count = -1;
- } else if (_PPFS_init(&ppfs, format) < 0) { /* Bad format string. */
- OUTNSTR(stream, (const FMT_TYPE *) ppfs.fmtpos,
+ if (_PPFS_init(&ppfs, format) < 0) { /* Bad format string. */
+ OUTNSTR(stream, (const unsigned char *) ppfs.fmtpos,
STRLEN((const FMT_TYPE *)(ppfs.fmtpos)));
-#if defined(L_vfprintf) && !defined(NDEBUG)
+#if defined(L__vfprintf_internal) && !defined(NDEBUG)
fprintf(stderr,"\nIMbS: \"%s\"\n\n", format);
#endif
count = -1;
@@ -1901,7 +1890,7 @@ int VFPRINTF (FILE * __restrict stream,
}
if (format-s) { /* output any literal text in format string */
- if ( (r = OUTNSTR(stream, s, format-s)) != (format-s)) {
+ if ( (r = OUTNSTR(stream, (const unsigned char *) s, format-s)) != (format-s)) {
count = -1;
break;
}
@@ -1930,14 +1919,66 @@ int VFPRINTF (FILE * __restrict stream,
va_end(ppfs.arg); /* Need to clean up after va_copy! */
}
-/* #if defined(L_vfprintf) && defined(__UCLIBC_HAS_WCHAR__) */
+/* #if defined(L__vfprintf_internal) && defined(__UCLIBC_HAS_WCHAR__) */
/* DONE: */
/* #endif */
+ return count;
+}
+#endif /* defined(L__vfprintf_internal) || defined(L__vfwprintf_internal) */
+
+
+/**********************************************************************/
+#if defined(L_vfprintf) || defined(L_vfwprintf)
+
+/* This is just a wrapper around VFPRINTF_internal.
+ * Factoring out vfprintf internals allows:
+ * (1) vdprintf and vsnprintf don't need to setup fake locking,
+ * (2) __STDIO_STREAM_TRANS_TO_WRITE is not used in vfprintf internals,
+ * and thus fseek etc is not pulled in by vdprintf and vsnprintf.
+ *
+ * In order to not pull in fseek through fputs, OUTPUT() macro
+ * is using __stdio_fwrite (TODO: do the same for wide functions).
+ */
+#ifdef L_vfprintf
+#define VFPRINTF vfprintf
+#define VFPRINTF_internal _vfprintf_internal
+#define FMT_TYPE char
+#else
+#define VFPRINTF vfwprintf
+#define VFPRINTF_internal _vfwprintf_internal
+#define FMT_TYPE wchar_t
+#endif
+
+libc_hidden_proto(VFPRINTF)
+int VFPRINTF (FILE * __restrict stream,
+ const FMT_TYPE * __restrict format,
+ va_list arg)
+{
+ int count;
+ __STDIO_AUTO_THREADLOCK_VAR;
+
+ __STDIO_AUTO_THREADLOCK(stream);
+
+ if
+#ifdef L_vfprintf
+ (!__STDIO_STREAM_IS_NARROW_WRITING(stream)
+ && __STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW))
+#else
+ (!__STDIO_STREAM_IS_WIDE_WRITING(stream)
+ && __STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_WIDE))
+#endif
+ {
+ count = -1;
+ } else {
+ count = VFPRINTF_internal(stream, format, arg);
+ }
+
__STDIO_AUTO_THREADUNLOCK(stream);
return count;
}
libc_hidden_def(VFPRINTF)
-#endif
+#endif /* defined(L_vfprintf) || defined(L_vfwprintf) */
+
/**********************************************************************/
diff --git a/libc/stdio/ctermid.c b/libc/stdio/ctermid.c
index 1cb8a0845..26369d6f5 100644
--- a/libc/stdio/ctermid.c
+++ b/libc/stdio/ctermid.c
@@ -7,7 +7,7 @@
#include "_stdio.h"
-libc_hidden_proto(strcpy)
+/* Experimentally off - libc_hidden_proto(strcpy) */
char *ctermid(register char *s)
{
diff --git a/libc/stdio/fclose.c b/libc/stdio/fclose.c
index 843599c0f..27d3c7e96 100644
--- a/libc/stdio/fclose.c
+++ b/libc/stdio/fclose.c
@@ -16,12 +16,15 @@ int fclose(register FILE *stream)
int rv = 0;
__STDIO_AUTO_THREADLOCK_VAR;
- /* First, remove the file from the open file list. */
#ifdef __STDIO_HAS_OPENLIST
+#if !defined(__UCLIBC_HAS_THREADS__) || !defined(__STDIO_BUFFERS)
+ /* First, remove the file from the open file list. */
{
- register FILE *ptr;
+ FILE *ptr;
- __STDIO_THREADLOCK_OPENLIST;
+ __STDIO_THREADLOCK_OPENLIST_DEL;
+ __STDIO_THREADLOCK_OPENLIST_ADD;
+ ptr = _stdio_openlist;
if ((ptr = _stdio_openlist) == stream) {
_stdio_openlist = stream->__nextopen;
} else {
@@ -33,13 +36,11 @@ int fclose(register FILE *stream)
ptr = ptr->__nextopen;
}
}
- __STDIO_THREADUNLOCK_OPENLIST;
-
- if (!ptr) { /* Did not find stream in the open file list! */
- return EOF;
- }
+ __STDIO_THREADUNLOCK_OPENLIST_ADD;
+ __STDIO_THREADUNLOCK_OPENLIST_DEL;
}
#endif
+#endif
__STDIO_AUTO_THREADLOCK(stream);
@@ -62,6 +63,11 @@ int fclose(register FILE *stream)
* Since a file can't be both readonly and writeonly, that makes
* an effective signal. It also has the benefit of disabling
* transitions to either reading or writing. */
+#if defined(__UCLIBC_HAS_THREADS__) && defined(__STDIO_BUFFERS)
+ /* Before we mark the file as closed, make sure we increment the openlist use count
+ * so it isn't freed under us while still cleaning up. */
+ __STDIO_OPENLIST_INC_USE;
+#endif
stream->__modeflags &= (__FLAG_FREEBUF|__FLAG_FREEFILE);
stream->__modeflags |= (__FLAG_READONLY|__FLAG_WRITEONLY);
@@ -84,7 +90,16 @@ int fclose(register FILE *stream)
__STDIO_AUTO_THREADUNLOCK(stream);
__STDIO_STREAM_FREE_BUFFER(stream);
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: inefficient - locks and unlocks twice and walks whole list
+#endif
+#if defined(__UCLIBC_HAS_THREADS__) && defined(__STDIO_BUFFERS)
+ /* inefficient - locks/unlocks twice and walks whole list */
+ __STDIO_OPENLIST_INC_DEL_CNT;
+ __STDIO_OPENLIST_DEC_USE; /* This with free the file if necessary. */
+#else
__STDIO_STREAM_FREE_FILE(stream);
+#endif
return rv;
}
diff --git a/libc/stdio/fcloseall.c b/libc/stdio/fcloseall.c
index 7d2422562..d3cbb67f8 100644
--- a/libc/stdio/fcloseall.c
+++ b/libc/stdio/fcloseall.c
@@ -24,14 +24,39 @@ int fcloseall (void)
#ifdef __STDIO_HAS_OPENLIST
int retval = 0;
+ FILE *f;
- __STDIO_THREADLOCK_OPENLIST;
- while (_stdio_openlist) {
- if (fclose(_stdio_openlist)) {
- retval = EOF;
+ __STDIO_OPENLIST_INC_USE;
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: should probably have a get_head() operation
+#endif
+ __STDIO_THREADLOCK_OPENLIST_ADD;
+ f = _stdio_openlist;
+ __STDIO_THREADUNLOCK_OPENLIST_ADD;
+
+ while (f) {
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: should probably have a get_next() operation
+#endif
+ FILE *n = f->__nextopen;
+ __STDIO_AUTO_THREADLOCK_VAR;
+
+ __STDIO_AUTO_THREADLOCK(f);
+ /* Only call fclose on the stream if it is not already closed. */
+ if ((f->__modeflags & (__FLAG_READONLY|__FLAG_WRITEONLY))
+ != (__FLAG_READONLY|__FLAG_WRITEONLY)
+ ) {
+ if (fclose(f)) {
+ retval = EOF;
+ }
}
+ __STDIO_AUTO_THREADUNLOCK(f);
+
+ f = n;
}
- __STDIO_THREADUNLOCK_OPENLIST;
+
+ __STDIO_OPENLIST_DEC_USE;
return retval;
diff --git a/libc/stdio/fflush.c b/libc/stdio/fflush.c
index c0f58d8af..11b837dde 100644
--- a/libc/stdio/fflush.c
+++ b/libc/stdio/fflush.c
@@ -15,24 +15,57 @@ libc_hidden_proto(fflush_unlocked)
#warning WISHLIST: Add option to test for undefined behavior of fflush.
#endif /* __UCLIBC_MJN3_ONLY__ */
-#ifdef __UCLIBC_HAS_THREADS__
/* Even if the stream is set to user-locking, we still need to lock
* when all (lbf) writing streams are flushed. */
-#define MY_STDIO_THREADLOCK(STREAM) \
- if (_stdio_user_locking != 2) { \
- __STDIO_ALWAYS_THREADLOCK(STREAM); \
- }
-#define MY_STDIO_THREADUNLOCK(STREAM) \
- if (_stdio_user_locking != 2) { \
- __STDIO_ALWAYS_THREADUNLOCK(STREAM); \
+#define __MY_STDIO_THREADLOCK(__stream) \
+ __UCLIBC_IO_MUTEX_CONDITIONAL_LOCK((__stream)->__lock, \
+ (_stdio_user_locking != 2))
+
+#define __MY_STDIO_THREADUNLOCK(__stream) \
+ __UCLIBC_IO_MUTEX_CONDITIONAL_UNLOCK((__stream)->__lock, \
+ (_stdio_user_locking != 2))
+
+#if defined(__UCLIBC_HAS_THREADS__) && defined(__STDIO_BUFFERS)
+void _stdio_openlist_dec_use(void)
+{
+ __STDIO_THREADLOCK_OPENLIST_DEL;
+ if ((_stdio_openlist_use_count == 1) && (_stdio_openlist_del_count > 0)) {
+ FILE *p = NULL;
+ FILE *n;
+ FILE *stream;
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: As an optimization, we could unlock after we move past the head.
+#endif
+ /* Grab the openlist add lock since we might change the head of the list. */
+ __STDIO_THREADLOCK_OPENLIST_ADD;
+ for (stream = _stdio_openlist; stream; stream = n) {
+ n = stream->__nextopen;
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: fix for nonatomic
+#endif
+ if ((stream->__modeflags & (__FLAG_READONLY|__FLAG_WRITEONLY|__FLAG_FAILED_FREOPEN))
+ == (__FLAG_READONLY|__FLAG_WRITEONLY)
+ ) { /* The file was closed and should be removed from the list. */
+ if (!p) {
+ _stdio_openlist = n;
+ } else {
+ p->__nextopen = n;
+ }
+ __STDIO_STREAM_FREE_FILE(stream);
+ } else {
+ p = stream;
+ }
+ }
+ __STDIO_THREADUNLOCK_OPENLIST_ADD;
+ _stdio_openlist_del_count = 0; /* Should be clean now. */
}
-#else
-#define MY_STDIO_THREADLOCK(STREAM) ((void)0)
-#define MY_STDIO_THREADUNLOCK(STREAM) ((void)0)
+ --_stdio_openlist_use_count;
+ __STDIO_THREADUNLOCK_OPENLIST_DEL;
+}
#endif
-
int fflush_unlocked(register FILE *stream)
{
#ifdef __STDIO_BUFFERS
@@ -55,23 +88,39 @@ int fflush_unlocked(register FILE *stream)
}
if (!stream) { /* Flush all (lbf) writing streams. */
- __STDIO_THREADLOCK_OPENLIST;
- for (stream = _stdio_openlist; stream ; stream = stream->__nextopen) {
- MY_STDIO_THREADLOCK(stream);
- if (!(((stream->__modeflags | bufmask)
- ^ (__FLAG_WRITING|__FLAG_LBF)
- ) & (__FLAG_WRITING|__MASK_BUFMODE))
- ) {
- if (!__STDIO_COMMIT_WRITE_BUFFER(stream)) {
- __STDIO_STREAM_DISABLE_PUTC(stream);
- __STDIO_STREAM_CLEAR_WRITING(stream);
- } else {
- retval = EOF;
+
+ __STDIO_OPENLIST_INC_USE;
+
+ __STDIO_THREADLOCK_OPENLIST_ADD;
+ stream = _stdio_openlist;
+ __STDIO_THREADUNLOCK_OPENLIST_ADD;
+
+ while(stream) {
+ /* We only care about currently writing streams and do not want to
+ * block trying to obtain mutexes on non-writing streams. */
+#warning fix for nonatomic
+#warning unnecessary check if no threads
+ if (__STDIO_STREAM_IS_WRITING(stream)) { /* ONLY IF ATOMIC!!! */
+ __MY_STDIO_THREADLOCK(stream);
+ /* Need to check again once we have the lock. */
+ if (!(((stream->__modeflags | bufmask)
+ ^ (__FLAG_WRITING|__FLAG_LBF)
+ ) & (__FLAG_WRITING|__MASK_BUFMODE))
+ ) {
+ if (!__STDIO_COMMIT_WRITE_BUFFER(stream)) {
+ __STDIO_STREAM_DISABLE_PUTC(stream);
+ __STDIO_STREAM_CLEAR_WRITING(stream);
+ } else {
+ retval = EOF;
+ }
}
+ __MY_STDIO_THREADUNLOCK(stream);
}
- MY_STDIO_THREADUNLOCK(stream);
+ stream = stream->__nextopen;
}
- __STDIO_THREADUNLOCK_OPENLIST;
+
+ __STDIO_OPENLIST_DEC_USE;
+
} else if (__STDIO_STREAM_IS_WRITING(stream)) {
if (!__STDIO_COMMIT_WRITE_BUFFER(stream)) {
__STDIO_STREAM_DISABLE_PUTC(stream);
diff --git a/libc/stdio/flockfile.c b/libc/stdio/flockfile.c
index 0dcc7c266..3fad7118d 100644
--- a/libc/stdio/flockfile.c
+++ b/libc/stdio/flockfile.c
@@ -11,6 +11,6 @@ void flockfile(FILE *stream)
{
__STDIO_STREAM_VALIDATE(stream);
- __STDIO_ALWAYS_THREADLOCK(stream);
+ __STDIO_ALWAYS_THREADLOCK_CANCEL_UNSAFE(stream);
}
diff --git a/libc/stdio/fmemopen.c b/libc/stdio/fmemopen.c
index a78d56efc..eb4fa736e 100644
--- a/libc/stdio/fmemopen.c
+++ b/libc/stdio/fmemopen.c
@@ -10,7 +10,7 @@
#ifdef __USE_GNU
#include "_stdio.h"
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(fopencookie)
#ifndef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
diff --git a/libc/stdio/fputc.c b/libc/stdio/fputc.c
index 8c80bff27..ac3b23ec5 100644
--- a/libc/stdio/fputc.c
+++ b/libc/stdio/fputc.c
@@ -72,13 +72,19 @@ int __fputc_unlocked(int c, register FILE *stream)
}
libc_hidden_def(__fputc_unlocked)
+/* exposing these would be fundamentally *wrong*! fix you, instead! */
+/* libc_hidden_proto(fputc_unlocked) */
strong_alias(__fputc_unlocked,fputc_unlocked)
+/* exposing these would be fundamentally *wrong*! fix you, instead! */
+/* libc_hidden_def(fputc_unlocked) */
libc_hidden_proto(putc_unlocked)
strong_alias(__fputc_unlocked,putc_unlocked)
libc_hidden_def(putc_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
+libc_hidden_proto(fputc)
strong_alias(__fputc_unlocked,fputc)
+libc_hidden_def(fputc)
libc_hidden_proto(putc)
strong_alias(__fputc_unlocked,putc)
diff --git a/libc/stdio/fputs.c b/libc/stdio/fputs.c
index 4111491d6..8a5fd4087 100644
--- a/libc/stdio/fputs.c
+++ b/libc/stdio/fputs.c
@@ -9,7 +9,7 @@
libc_hidden_proto(fputs_unlocked)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(fwrite_unlocked)
/* Note: The standard says fputs returns a nonnegative number on
diff --git a/libc/stdio/fread.c b/libc/stdio/fread.c
index c603a9d2e..d8b04f733 100644
--- a/libc/stdio/fread.c
+++ b/libc/stdio/fread.c
@@ -11,7 +11,7 @@ libc_hidden_proto(fread_unlocked)
#ifdef __DO_UNLOCKED
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(fflush_unlocked)
size_t fread_unlocked(void * __restrict ptr, size_t size, size_t nmemb,
diff --git a/libc/stdio/freopen.c b/libc/stdio/freopen.c
index 7314807d3..942a67991 100644
--- a/libc/stdio/freopen.c
+++ b/libc/stdio/freopen.c
@@ -37,6 +37,8 @@ FILE *freopen(const char * __restrict filename, const char * __restrict mode,
__STDIO_STREAM_VALIDATE(stream);
+ __STDIO_OPENLIST_INC_USE; /* Do not remove the file from the list. */
+
/* First, flush and close, but don't deallocate, the stream. */
/* This also removes the stream for the open file list. */
dynmode = (stream->__modeflags & (__FLAG_FREEBUF|__FLAG_FREEFILE));
@@ -48,13 +50,26 @@ FILE *freopen(const char * __restrict filename, const char * __restrict mode,
!= (__FLAG_READONLY|__FLAG_WRITEONLY)
) {
fclose(stream); /* Failures are ignored. */
+ /* NOTE: fclose always does __STDIO_OPENLIST_INC_DEL_CNT. But we don't
+ * want to remove this FILE from the open list, even if the freopen fails.
+ * Consider the case of a failed freopen() on stdin. You probably still
+ * want to be able to call freopen() again. Similarly for other "malloc'd"
+ * streams. */
+ __STDIO_OPENLIST_DEC_DEL_CNT;
}
fp = _stdio_fopen(((intptr_t) filename), mode, stream, FILEDES_ARG);
+ if (!fp) {
+ /* Don't remove stream from the open file list and (potentially) free it.
+ * See _stdio_openlist_dec_use() in fflush.c. */
+ stream->__modeflags = __FLAG_READONLY|__FLAG_WRITEONLY|__FLAG_FAILED_FREOPEN;
+ }
/* Reset the allocation flags. */
stream->__modeflags |= dynmode;
+ __STDIO_OPENLIST_DEC_USE;
+
__STDIO_AUTO_THREADUNLOCK(stream);
return fp;
diff --git a/libc/stdio/ftello.c b/libc/stdio/ftello.c
index 4445471a4..bae1d877c 100644
--- a/libc/stdio/ftello.c
+++ b/libc/stdio/ftello.c
@@ -39,7 +39,10 @@ OFFSET_TYPE FTELL(register FILE *stream)
__STDIO_STREAM_VALIDATE(stream);
- if ((__SEEK(stream, &pos, SEEK_CUR) < 0)
+ if ((__SEEK(stream, &pos,
+ ((__STDIO_STREAM_IS_WRITING(stream)
+ && (stream->__modeflags & __FLAG_APPEND))
+ ? SEEK_END : SEEK_CUR)) < 0)
|| (__stdio_adjust_position(stream, &pos) < 0)) {
pos = -1;
}
diff --git a/libc/stdio/ftrylockfile.c b/libc/stdio/ftrylockfile.c
index d85b8ff59..0d2e156af 100644
--- a/libc/stdio/ftrylockfile.c
+++ b/libc/stdio/ftrylockfile.c
@@ -15,5 +15,5 @@ int ftrylockfile(FILE *stream)
{
__STDIO_STREAM_VALIDATE(stream);
- return __STDIO_ALWAYS_THREADTRYLOCK(stream);
+ return __STDIO_ALWAYS_THREADTRYLOCK_CANCEL_UNSAFE(stream);
}
diff --git a/libc/stdio/funlockfile.c b/libc/stdio/funlockfile.c
index 048c093d5..2ddf09797 100644
--- a/libc/stdio/funlockfile.c
+++ b/libc/stdio/funlockfile.c
@@ -11,5 +11,5 @@ void funlockfile(FILE *stream)
{
__STDIO_STREAM_VALIDATE(stream);
- __STDIO_ALWAYS_THREADUNLOCK(stream);
+ __STDIO_ALWAYS_THREADUNLOCK_CANCEL_UNSAFE(stream);
}
diff --git a/libc/stdio/getchar.c b/libc/stdio/getchar.c
index 6da8307b6..e29c426c8 100644
--- a/libc/stdio/getchar.c
+++ b/libc/stdio/getchar.c
@@ -12,13 +12,16 @@ libc_hidden_proto(__fgetc_unlocked)
#undef getchar
#ifdef __DO_UNLOCKED
+/* the only use of the hidden getchar_unlocked is in gets.c */
#undef getchar_unlocked
+libc_hidden_proto(getchar_unlocked)
int getchar_unlocked(void)
{
register FILE *stream = stdin;
return __GETC_UNLOCKED_MACRO(stream);
}
+libc_hidden_def(getchar_unlocked)
#ifndef __UCLIBC_HAS_THREADS__
strong_alias(getchar_unlocked,getchar)
diff --git a/libc/stdio/gets.c b/libc/stdio/gets.c
index dc541339b..85bb8475a 100644
--- a/libc/stdio/gets.c
+++ b/libc/stdio/gets.c
@@ -11,11 +11,9 @@ link_warning(gets, "the 'gets' function is dangerous and should not be used.")
/* UNSAFE FUNCTION -- do not bother optimizing */
+/* disable macro, force actual function call */
+#undef getchar_unlocked
libc_hidden_proto(getchar_unlocked)
-libc_hidden_proto(__fgetc_unlocked)
-#ifndef __STDIO_GETC_MACRO
-#define __stdin stdin
-#endif
char *gets(char *s)
{
diff --git a/libc/stdio/old_vfprintf.c b/libc/stdio/old_vfprintf.c
index f81ef8688..85a0967c1 100644
--- a/libc/stdio/old_vfprintf.c
+++ b/libc/stdio/old_vfprintf.c
@@ -137,17 +137,15 @@
#include <errno.h>
#include <ctype.h>
#include <bits/uClibc_uintmaxtostr.h>
-
-#define __PRINTF_INFO_NO_BITFIELD
#include <printf.h>
#ifdef __UCLIBC_HAS_THREADS__
#include <pthread.h>
#endif /* __UCLIBC_HAS_THREADS__ */
-libc_hidden_proto(strlen)
-libc_hidden_proto(strnlen)
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strnlen) */
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(putc_unlocked)
libc_hidden_proto(__fputc_unlocked)
libc_hidden_proto(__glibc_strerror_r)
@@ -359,13 +357,13 @@ int vfprintf(FILE * __restrict op, register const char * __restrict fmt,
int i;
} intarg;
int i, cnt, dataargtype, len;
- const void *argptr; /* This does not need to be initialized. */
+ const void *argptr = argptr; /* ok to be initialized. */
register char *p;
const char *fmt0;
int preci, width;
#define upcase i
int radix, dpoint /*, upcase*/;
- char tmp[65]; /* TODO - determing needed size from headers */
+ char tmp[65]; /* TODO - determine needed size from headers */
char flag[sizeof(spec)];
__STDIO_AUTO_THREADLOCK_VAR;
diff --git a/libc/stdio/open_memstream.c b/libc/stdio/open_memstream.c
index 25c2f9f61..a9327608a 100644
--- a/libc/stdio/open_memstream.c
+++ b/libc/stdio/open_memstream.c
@@ -10,8 +10,8 @@
#ifdef __USE_GNU
#include "_stdio.h"
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(fopencookie)
#ifndef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
@@ -160,9 +160,7 @@ FILE *open_memstream(char **__restrict bufloc, size_t *__restrict sizeloc)
}
}
- if (cookie->buf != NULL) {
- free(cookie->buf);
- }
+ free(cookie->buf);
EXIT_cookie:
free(cookie);
diff --git a/libc/stdio/popen.c b/libc/stdio/popen.c
index 044426abf..43d07fa0f 100644
--- a/libc/stdio/popen.c
+++ b/libc/stdio/popen.c
@@ -20,6 +20,11 @@
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
+#include <bits/uClibc_mutex.h>
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning "hmm... susv3 says Pipe streams are byte-oriented."
+#endif /* __UCLIBC_MJN3_ONLY__ */
libc_hidden_proto(close)
libc_hidden_proto(_exit)
@@ -34,23 +39,16 @@ libc_hidden_proto(fclose)
/* 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
# define VFORK_LOCK ((void) 0)
-# define VFORK_UNLOCK ((void) 0)
+# define VFORK_UNLOCK ((void) 0)
libc_hidden_proto(fork)
#endif
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-# include <pthreadP.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
-
#ifndef VFORK_LOCK
-# define VFORK_LOCK LOCK
-# define VFORK_UNLOCK UNLOCK
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
+# define VFORK_LOCK __UCLIBC_MUTEX_LOCK(mylock)
+# define VFORK_UNLOCK __UCLIBC_MUTEX_UNLOCK(mylock)
#endif
struct popen_list_item {
@@ -127,11 +125,11 @@ FILE *popen(const char *command, const char *modes)
if (pid > 0) { /* Parent of vfork... */
pi->pid = pid;
pi->f = fp;
- LOCK;
+ VFORK_LOCK;
pi->next = popen_list;
popen_list = pi;
- UNLOCK;
-
+ VFORK_UNLOCK;
+
return fp;
}
@@ -145,6 +143,8 @@ FILE *popen(const char *command, const char *modes)
return NULL;
}
+#warning is pclose correct wrt the new mutex semantics?
+
int pclose(FILE *stream)
{
struct popen_list_item *p;
@@ -153,7 +153,7 @@ int pclose(FILE *stream)
/* First, find the list entry corresponding to stream and remove it
* from the list. Set p to the list item (NULL if not found). */
- LOCK;
+ VFORK_LOCK;
if ((p = popen_list) != NULL) {
if (p->f == stream) {
popen_list = p->next;
@@ -172,7 +172,7 @@ int pclose(FILE *stream)
} while (1);
}
}
- UNLOCK;
+ VFORK_UNLOCK;
if (p) {
pid = p->pid; /* Save the pid we need */
diff --git a/libc/stdio/setvbuf.c b/libc/stdio/setvbuf.c
index c1566504a..6dbb532db 100644
--- a/libc/stdio/setvbuf.c
+++ b/libc/stdio/setvbuf.c
@@ -76,8 +76,8 @@ int setvbuf(register FILE * __restrict stream, register char * __restrict buf,
}
stream->__modeflags |= alloc_flag;
- stream->__bufstart = buf;
- stream->__bufend = buf + size;
+ stream->__bufstart = (unsigned char *) buf;
+ stream->__bufend = (unsigned char *) buf + size;
__STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
__STDIO_STREAM_DISABLE_GETC(stream);
__STDIO_STREAM_DISABLE_PUTC(stream);
diff --git a/libc/stdio/tempnam.c b/libc/stdio/tempnam.c
index 43cbf781b..3673f4bda 100644
--- a/libc/stdio/tempnam.c
+++ b/libc/stdio/tempnam.c
@@ -20,7 +20,7 @@
#include <string.h>
#include "../misc/internals/tempname.h"
-libc_hidden_proto(strdup)
+/* Experimentally off - libc_hidden_proto(strdup) */
/* Generate a unique temporary filename using up to five characters of PFX
if it is not NULL. The directory to put this file in is searched for
diff --git a/libc/stdio/tmpnam.c b/libc/stdio/tmpnam.c
index bc4ffeb6a..8df6ff57f 100644
--- a/libc/stdio/tmpnam.c
+++ b/libc/stdio/tmpnam.c
@@ -20,7 +20,7 @@
#include <string.h>
#include "../misc/internals/tempname.h"
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
static char tmpnam_buffer[L_tmpnam];
diff --git a/libc/stdio/vasprintf.c b/libc/stdio/vasprintf.c
index 7a34f6870..b7e2e0852 100644
--- a/libc/stdio/vasprintf.c
+++ b/libc/stdio/vasprintf.c
@@ -57,7 +57,7 @@ int vasprintf(char **__restrict buf, const char * __restrict format,
#else /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
- /* This implementation actually calls the printf machinery twice, but only
+ /* This implementation actually calls the printf machinery twice, but
* only does one malloc. This can be a problem though when custom printf
* specs or the %m specifier are involved because the results of the
* second call might be different from the first. */
diff --git a/libc/stdio/vdprintf.c b/libc/stdio/vdprintf.c
index 67adf47be..de54a5c7d 100644
--- a/libc/stdio/vdprintf.c
+++ b/libc/stdio/vdprintf.c
@@ -11,7 +11,9 @@
#include "_stdio.h"
#include <stdarg.h>
+#ifdef __USE_OLD_VFPRINTF__
libc_hidden_proto(vfprintf)
+#endif
libc_hidden_proto(fflush_unlocked)
libc_hidden_proto(vdprintf)
@@ -22,8 +24,8 @@ int vdprintf(int filedes, const char * __restrict format, va_list arg)
#ifdef __STDIO_BUFFERS
char buf[64]; /* TODO: provide _optional_ buffering? */
- f.__bufend = buf + sizeof(buf);
- f.__bufstart = buf;
+ f.__bufend = (unsigned char *) buf + sizeof(buf);
+ f.__bufstart = (unsigned char *) buf;
__STDIO_STREAM_DISABLE_GETC(&f);
__STDIO_STREAM_DISABLE_PUTC(&f);
__STDIO_STREAM_INIT_BUFREAD_BUFPOS(&f);
@@ -48,17 +50,19 @@ int vdprintf(int filedes, const char * __restrict format, va_list arg)
__INIT_MBSTATE(&(f.__state));
#endif /* __STDIO_MBSTATE */
-#ifdef __UCLIBC_HAS_THREADS__
+/* _vfprintf_internal doesn't do any locking, locking init is here
+ * only because of fflush_unlocked. TODO? */
+#if (defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__)) && defined(__UCLIBC_HAS_THREADS__)
f.__user_locking = 1; /* Set user locking. */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (f._lock);
-#else
- __stdio_init_mutex(&f.__lock);
-#endif
+ STDIO_INIT_MUTEX(f.__lock);
#endif
f.__nextopen = NULL;
+#ifdef __USE_OLD_VFPRINTF__
rv = vfprintf(&f, format, arg);
+#else
+ rv = _vfprintf_internal(&f, format, arg);
+#endif
#ifdef __STDIO_BUFFERS
/* If not buffering, then fflush is unnecessary. */
diff --git a/libc/stdio/vsnprintf.c b/libc/stdio/vsnprintf.c
index ab6154848..8bc697a48 100644
--- a/libc/stdio/vsnprintf.c
+++ b/libc/stdio/vsnprintf.c
@@ -10,13 +10,16 @@
libc_hidden_proto(vsnprintf)
+#ifdef __USE_OLD_VFPRINTF__
libc_hidden_proto(vfprintf)
+#endif
#ifdef __UCLIBC_MJN3_ONLY__
#warning WISHLIST: Implement vsnprintf for non-buffered and no custom stream case.
#endif /* __UCLIBC_MJN3_ONLY__ */
#ifdef __STDIO_BUFFERS
+/* NB: we can still have __USE_OLD_VFPRINTF__ defined in this case! */
int vsnprintf(char *__restrict buf, size_t size,
const char * __restrict format, va_list arg)
@@ -43,13 +46,9 @@ int vsnprintf(char *__restrict buf, size_t size,
__INIT_MBSTATE(&(f.__state));
#endif /* __STDIO_MBSTATE */
-#ifdef __UCLIBC_HAS_THREADS__
+#if defined(__USE_OLD_VFPRINTF__) && defined(__UCLIBC_HAS_THREADS__)
f.__user_locking = 1; /* Set user locking. */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (f._lock);
-#else
- __stdio_init_mutex(&f.__lock);
-#endif
+ STDIO_INIT_MUTEX(f.__lock);
#endif
f.__nextopen = NULL;
@@ -57,15 +56,20 @@ int vsnprintf(char *__restrict buf, size_t size,
size = SIZE_MAX - (size_t) buf;
}
+/* TODO: this comment seems to be wrong */
/* Set these last since __bufputc initialization depends on
* __user_locking and only gets set if user locking is on. */
- f.__bufstart = buf;
- f.__bufend = buf + size;
+ f.__bufstart = (unsigned char *) buf;
+ f.__bufend = (unsigned char *) buf + size;
__STDIO_STREAM_INIT_BUFREAD_BUFPOS(&f);
__STDIO_STREAM_DISABLE_GETC(&f);
__STDIO_STREAM_ENABLE_PUTC(&f);
+#ifdef __USE_OLD_VFPRINTF__
rv = vfprintf(&f, format, arg);
+#else
+ rv = _vfprintf_internal(&f, format, arg);
+#endif
if (size) {
if (f.__bufpos == f.__bufend) {
--f.__bufpos;
@@ -118,11 +122,7 @@ int vsnprintf(char *__restrict buf, size_t size,
#ifdef __UCLIBC_HAS_THREADS__
f.f.__user_locking = 1; /* Set user locking. */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (f.f._lock);
-#else
- __stdio_init_mutex(&f.f.__lock);
-#endif
+ STDIO_INIT_MUTEX(f.f.__lock);
#endif
f.f.__nextopen = NULL;
@@ -205,17 +205,9 @@ int vsnprintf(char *__restrict buf, size_t size,
__INIT_MBSTATE(&(f.__state));
#endif /* __STDIO_MBSTATE */
-#ifdef __UCLIBC_HAS_THREADS__
- f.__user_locking = 1; /* Set user locking. */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (f._lock);
-#else
- __stdio_init_mutex(&f.__lock);
-#endif
-#endif
f.__nextopen = NULL;
- rv = vfprintf(&f, format, arg);
+ rv = _vfprintf_internal(&f, format, arg);
return rv;
}
diff --git a/libc/stdio/vswprintf.c b/libc/stdio/vswprintf.c
index d95de51a2..cddf1d5d9 100644
--- a/libc/stdio/vswprintf.c
+++ b/libc/stdio/vswprintf.c
@@ -11,7 +11,7 @@
libc_hidden_proto(vswprintf)
-libc_hidden_proto(vfwprintf)
+/* NB: this file is not used if __USE_OLD_VFPRINTF__ */
#ifndef __STDIO_BUFFERS
#warning Skipping vswprintf since no buffering!
@@ -40,14 +40,6 @@ int vswprintf(wchar_t *__restrict buf, size_t size,
__INIT_MBSTATE(&(f.__state));
#endif /* __STDIO_MBSTATE */
-#ifdef __UCLIBC_HAS_THREADS__
- f.__user_locking = 1; /* Set user locking. */
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_init (f._lock);
-#else
- __stdio_init_mutex(&f.__lock);
-#endif
-#endif
f.__nextopen = NULL;
if (size > ((SIZE_MAX - (size_t) buf)/sizeof(wchar_t))) {
@@ -60,7 +52,7 @@ int vswprintf(wchar_t *__restrict buf, size_t size,
__STDIO_STREAM_DISABLE_GETC(&f);
__STDIO_STREAM_DISABLE_PUTC(&f);
- rv = vfwprintf(&f, format, arg);
+ rv = _vfwprintf_internal(&f, format, arg);
/* NOTE: Return behaviour differs from snprintf... */
if (f.__bufpos == f.__bufend) {
diff --git a/libc/stdlib/_atexit.c b/libc/stdlib/_atexit.c
index 75fe41fa2..e5840f471 100644
--- a/libc/stdlib/_atexit.c
+++ b/libc/stdlib/_atexit.c
@@ -20,7 +20,7 @@
* _stdio_term.
*
* Jul 2001 Steve Thayer
- *
+ *
* Added an on_exit implementation (that now matches gnu libc definition.)
* Pulled atexit_handler out of the atexit object since it is now required by
* on_exit as well. Renamed it to __exit_handler.
@@ -43,17 +43,12 @@
#include <errno.h>
#include <atomic.h>
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_EXTERN(__atexit_lock);
+
libc_hidden_proto(exit)
libc_hidden_proto(_exit)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-# include <pthreadP.h>
-extern pthread_mutex_t mylock;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
-
typedef void (*aefuncp) (void); /* atexit function pointer */
typedef void (*oefuncp) (int, void *); /* on_exit function pointer */
@@ -112,12 +107,13 @@ extern void *__dso_handle __attribute__ ((__weak__));
#ifdef L_atexit
int attribute_hidden atexit(aefuncp func)
#else
+int old_atexit(aefuncp func);
int old_atexit(aefuncp func)
#endif
{
/*
* glibc casts aefuncp to cxaefuncp.
- * This seems dodgy, but I guess callling a function with more
+ * This seems dodgy, but I guess calling a function with more
* parameters than it needs will work everywhere?
*/
return __cxa_atexit((cxaefuncp)func, NULL,
@@ -138,7 +134,7 @@ weak_alias(old_atexit,atexit)
int on_exit(oefuncp func, void *arg)
{
struct exit_function *efp;
-
+
if (func == NULL) {
return 0;
}
@@ -162,7 +158,7 @@ libc_hidden_proto(__cxa_atexit)
int __cxa_atexit (cxaefuncp func, void *arg, void *dso_handle)
{
struct exit_function *efp;
-
+
if (func == NULL) {
return 0;
}
@@ -244,26 +240,25 @@ struct exit_function attribute_hidden *__new_exitfn(void)
{
struct exit_function *efp;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(__atexit_lock);
#ifdef __UCLIBC_DYNAMIC_ATEXIT__
/* If we are out of function table slots, make some more */
if (__exit_slots < __exit_count+1) {
- efp=realloc(__exit_function_table,
+ efp=realloc(__exit_function_table,
(__exit_slots+20)*sizeof(struct exit_function));
if (efp == NULL) {
- UNLOCK;
__set_errno(ENOMEM);
- return 0;
+ goto DONE;
}
__exit_function_table = efp;
__exit_slots += 20;
}
#else
if (__exit_count >= __UCLIBC_MAX_ATEXIT) {
- UNLOCK;
__set_errno(ENOMEM);
- return 0;
+ efp = NULL;
+ goto DONE;
}
#endif
@@ -271,8 +266,8 @@ struct exit_function attribute_hidden *__new_exitfn(void)
efp = &__exit_function_table[__exit_count++];
efp->type = ef_in_use;
- UNLOCK;
-
+DONE:
+ __UCLIBC_MUTEX_UNLOCK(__atexit_lock);
return efp;
}
@@ -303,9 +298,8 @@ void __exit_handler(int status)
}
}
#ifdef __UCLIBC_DYNAMIC_ATEXIT__
- /* Free up memory used by the __exit_function_table structure */
- if (__exit_function_table)
- free(__exit_function_table);
+ /* Free up memory used by the __exit_function_table structure */
+ free(__exit_function_table);
#endif
}
#endif
@@ -313,9 +307,7 @@ void __exit_handler(int status)
#ifdef L_exit
extern void weak_function _stdio_term(void) attribute_hidden;
attribute_hidden void (*__exit_cleanup) (int) = 0;
-#ifdef __UCLIBC_HAS_THREADS__
-pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
+__UCLIBC_MUTEX_INIT(__atexit_lock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
extern void __uClibc_fini(void);
libc_hidden_proto(__uClibc_fini)
@@ -326,11 +318,11 @@ libc_hidden_proto(__uClibc_fini)
void exit(int rv)
{
/* Perform exit-specific cleanup (atexit and on_exit) */
- LOCK;
+ __UCLIBC_MUTEX_LOCK(__atexit_lock);
if (__exit_cleanup) {
__exit_cleanup(rv);
}
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(__atexit_lock);
__uClibc_fini();
@@ -338,7 +330,7 @@ void exit(int rv)
* this will attempt to commit all buffered writes. It may also
* unbuffer all writable files, or close them outright.
* Check the stdio routines for details. */
- if (_stdio_term)
+ if (_stdio_term)
_stdio_term();
_exit(rv);
diff --git a/libc/stdlib/_strtod.c b/libc/stdlib/_strtod.c
index 219d0d051..1b2adc986 100644
--- a/libc/stdlib/_strtod.c
+++ b/libc/stdlib/_strtod.c
@@ -177,7 +177,7 @@ extern void __fp_range_check(__fpmax_t y, __fpmax_t x) attribute_hidden;
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
libc_hidden_proto(__ctype_tolower)
#endif
@@ -215,7 +215,7 @@ __fpmax_t attribute_hidden __strtofpmax(const Wchar *str, Wchar **endptr, int ex
#else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
-libc_hidden_proto(memcmp)
+/* Experimentally off - libc_hidden_proto(memcmp) */
__fpmax_t attribute_hidden __XL_NPP(__strtofpmax)(const Wchar *str, Wchar **endptr, int exponent_power
__LOCALE_PARAM )
@@ -234,7 +234,7 @@ __fpmax_t attribute_hidden __XL_NPP(__strtofpmax)(const Wchar *str, Wchar **endp
#endif
#ifdef __UCLIBC_HAS_LOCALE__
#if defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
- wchar_t decpt_wc = __LOCALE_PTR->decimal_point;
+ wchar_t decpt_wc = __LOCALE_PTR->decimal_point_wc;
#else
const char *decpt = __LOCALE_PTR->decimal_point;
int decpt_len = __LOCALE_PTR->decimal_point_len;
diff --git a/libc/stdlib/a64l.c b/libc/stdlib/a64l.c
index 23faf2744..d09dbf464 100644
--- a/libc/stdlib/a64l.c
+++ b/libc/stdlib/a64l.c
@@ -36,9 +36,7 @@ static const char a64l_table[TABLE_SIZE] =
};
-long int
-a64l (string)
- const char *string;
+long int a64l (const char *string)
{
const char *ptr = string;
unsigned long int result = 0ul;
diff --git a/libc/stdlib/abort.c b/libc/stdlib/abort.c
index a940768c0..e2c9962f2 100644
--- a/libc/stdlib/abort.c
+++ b/libc/stdlib/abort.c
@@ -29,7 +29,7 @@ Cambridge, MA 02139, USA. */
libc_hidden_proto(abort)
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(sigaction)
libc_hidden_proto(sigprocmask)
libc_hidden_proto(raise)
@@ -46,15 +46,11 @@ libc_hidden_proto(_exit)
#ifdef __UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT__
extern void weak_function _stdio_term(void) attribute_hidden;
#endif
-static int been_there_done_that = 0;
+static smallint been_there_done_that = 0;
/* Be prepared in case multiple threads try to abort() */
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
/* Cause an abnormal program termination with core-dump */
void abort(void)
@@ -62,7 +58,7 @@ void abort(void)
sigset_t sigs;
/* Make sure we acquire the lock before proceeding */
- LOCK;
+ __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(mylock);
/* Unmask SIGABRT to be sure we can get it */
if (__sigemptyset(&sigs) == 0 && __sigaddset(&sigs, SIGABRT) == 0) {
@@ -85,9 +81,9 @@ void abort(void)
#endif
abort_it:
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE(mylock);
raise(SIGABRT);
- LOCK;
+ __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(mylock);
}
/* Still here? Try to remove any signal handlers */
diff --git a/libc/stdlib/bsd_getpt.c b/libc/stdlib/bsd_getpt.c
index 9b885c4e5..1afd57f47 100644
--- a/libc/stdlib/bsd_getpt.c
+++ b/libc/stdlib/bsd_getpt.c
@@ -22,13 +22,13 @@
#include <string.h>
#include <unistd.h>
+#if defined __USE_BSD
libc_hidden_proto(open)
-libc_hidden_proto(mempcpy)
+/* Experimentally off - libc_hidden_proto(mempcpy) */
/* Prefix for master pseudo terminal nodes. */
#define _PATH_PTY "/dev/pty"
-
/* Letters indicating a series of pseudo terminals. */
#ifndef PTYNAME1
#define PTYNAME1 "pqrsPQRS"
@@ -41,7 +41,6 @@ const char __libc_ptyname1[] attribute_hidden = PTYNAME1;
#endif
const char __libc_ptyname2[] attribute_hidden = PTYNAME2;
-
/* Open a master pseudo terminal and return its file descriptor. */
int
__getpt (void)
@@ -76,3 +75,4 @@ __getpt (void)
__set_errno (ENOENT);
return -1;
}
+#endif /* __USE_BSD */
diff --git a/libc/stdlib/drand48-iter.c b/libc/stdlib/drand48-iter.c
index 0e674a3ce..221cbe08f 100644
--- a/libc/stdlib/drand48-iter.c
+++ b/libc/stdlib/drand48-iter.c
@@ -26,12 +26,11 @@
/* Global state for non-reentrant functions. */
struct drand48_data __libc_drand48_data attribute_hidden;
-
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning turn int __drand48_iterate into void
+#endif /* __UCLIBC_MJN3_ONLY__ */
int __drand48_iterate (unsigned short int xsubi[3], struct drand48_data *buffer) attribute_hidden;
-int
-__drand48_iterate (xsubi, buffer)
- unsigned short int xsubi[3];
- struct drand48_data *buffer;
+int __drand48_iterate (unsigned short int xsubi[3], struct drand48_data *buffer)
{
uint64_t X;
uint64_t result;
diff --git a/libc/stdlib/drand48.c b/libc/stdlib/drand48.c
index ab6239d75..f96947cb2 100644
--- a/libc/stdlib/drand48.c
+++ b/libc/stdlib/drand48.c
@@ -24,8 +24,7 @@ libc_hidden_proto(erand48_r)
/* Global state for non-reentrant functions. Defined in drand48-iter.c. */
extern struct drand48_data __libc_drand48_data attribute_hidden;
-double
-drand48 ()
+double drand48 (void)
{
double result;
diff --git a/libc/stdlib/getenv.c b/libc/stdlib/getenv.c
index c7940f398..230ec0051 100644
--- a/libc/stdlib/getenv.c
+++ b/libc/stdlib/getenv.c
@@ -9,8 +9,8 @@
#include <stdlib.h>
libc_hidden_proto(getenv)
-libc_hidden_proto(memcmp)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(memcmp) */
+/* Experimentally off - libc_hidden_proto(strlen) */
/* IEEE Std 1003.1-2001 says getenv need not be thread safe, so
* don't bother locking access to __environ */
diff --git a/libc/stdlib/getpt.c b/libc/stdlib/getpt.c
index cab96bb06..1b5de7c16 100644
--- a/libc/stdlib/getpt.c
+++ b/libc/stdlib/getpt.c
@@ -20,8 +20,13 @@
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <unistd.h>
#include <paths.h>
+#include <sys/statfs.h>
+
+extern __typeof(statfs) __libc_statfs;
+libc_hidden_proto(__libc_statfs)
libc_hidden_proto(open)
libc_hidden_proto(close)
@@ -40,43 +45,44 @@ libc_hidden_proto(close)
/* Directory containing the UNIX98 pseudo terminals. */
#define _PATH_DEVPTS _PATH_DEV "pts"
-#if !defined __UNIX98PTY_ONLY__
+#if !defined __UNIX98PTY_ONLY__ && defined __UCLIBC_HAS_GETPT__
/* Prototype for function that opens BSD-style master pseudo-terminals. */
extern int __bsd_getpt (void) attribute_hidden;
#endif
/* Open a master pseudo terminal and return its file descriptor. */
int
-getpt (void)
+posix_openpt (int flags)
{
+#define have_no_dev_ptmx (1<<0)
+#define devpts_mounted (1<<1)
#if !defined __UNIX98PTY_ONLY__
- static int have_no_dev_ptmx;
+ static smallint _state;
#endif
int fd;
#if !defined __UNIX98PTY_ONLY__
- if (!have_no_dev_ptmx)
+ if (!(_state & have_no_dev_ptmx))
#endif
{
- fd = open (_PATH_DEVPTMX, O_RDWR);
+ fd = open (_PATH_DEVPTMX, flags);
if (fd != -1)
{
#if defined __ASSUME_DEVPTS__
return fd;
#else
struct statfs fsbuf;
- static int devpts_mounted;
/* Check that the /dev/pts filesystem is mounted
or if /dev is a devfs filesystem (this implies /dev/pts). */
- if (devpts_mounted
- || (statfs (_PATH_DEVPTS, &fsbuf) == 0
+ if ((_state & devpts_mounted)
+ || (__libc_statfs (_PATH_DEVPTS, &fsbuf) == 0
&& fsbuf.f_type == DEVPTS_SUPER_MAGIC)
- || (statfs (_PATH_DEV, &fsbuf) == 0
+ || (__libc_statfs (_PATH_DEV, &fsbuf) == 0
&& fsbuf.f_type == DEVFS_SUPER_MAGIC))
{
/* Everything is ok. */
- devpts_mounted = 1;
+ _state |= devpts_mounted;
return fd;
}
@@ -84,7 +90,7 @@ getpt (void)
are not usable. */
close (fd);
#if !defined __UNIX98PTY_ONLY__
- have_no_dev_ptmx = 1;
+ _state |= have_no_dev_ptmx;
#endif
#endif
}
@@ -92,16 +98,27 @@ getpt (void)
{
#if !defined __UNIX98PTY_ONLY__
if (errno == ENOENT || errno == ENODEV)
- have_no_dev_ptmx = 1;
+ _state |= have_no_dev_ptmx;
else
#endif
return -1;
}
}
+ return -1;
+}
+#undef have_no_dev_ptmx
+#undef devpts_mounted
+#if defined __USE_GNU && defined __UCLIBC_HAS_GETPT__
+int
+getpt (void)
+{
+ int fd = posix_openpt(O_RDWR);
#if !defined __UNIX98PTY_ONLY__
- return __bsd_getpt ();
+ if (fd == -1)
+ fd = __bsd_getpt();
#endif
+ return fd;
}
#if !defined __UNIX98PTY_ONLY__
@@ -111,3 +128,4 @@ getpt (void)
# define __getpt __bsd_getpt
# include "bsd_getpt.c"
#endif
+#endif /* GNU && __UCLIBC_HAS_GETPT__ */
diff --git a/libc/stdlib/l64a.c b/libc/stdlib/l64a.c
index f3a249fed..a8b2d551e 100644
--- a/libc/stdlib/l64a.c
+++ b/libc/stdlib/l64a.c
@@ -32,9 +32,7 @@ static const char conv_table[64] =
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
};
-char *
-l64a (n)
- long int n;
+char * l64a (long int n)
{
unsigned long int m = (unsigned long int) n;
static char result[7];
diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c
index a1c7b93c9..13d4166a7 100644
--- a/libc/stdlib/malloc-simple/alloc.c
+++ b/libc/stdlib/malloc-simple/alloc.c
@@ -13,11 +13,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
/*libc_hidden_proto(memset)*/
libc_hidden_proto(mmap)
libc_hidden_proto(munmap)
@@ -115,12 +114,11 @@ void free(void *ptr)
#endif
#ifdef L_memalign
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-pthread_mutex_t __malloc_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
-#define LOCK __pthread_mutex_lock(&__malloc_lock)
-#define UNLOCK __pthread_mutex_unlock(&__malloc_lock)
+
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(__malloc_lock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
+#define __MALLOC_LOCK __UCLIBC_MUTEX_LOCK(__malloc_lock)
+#define __MALLOC_UNLOCK __UCLIBC_MUTEX_UNLOCK(__malloc_lock)
/* List of blocks allocated with memalign or valloc */
struct alignlist
@@ -139,7 +137,7 @@ int __libc_free_aligned(void *ptr)
if (ptr == NULL)
return 0;
- LOCK;
+ __MALLOC_LOCK;
for (l = _aligned_blocks; l != NULL; l = l->next) {
if (l->aligned == ptr) {
/* Mark the block as free */
@@ -150,7 +148,7 @@ int __libc_free_aligned(void *ptr)
return 1;
}
}
- UNLOCK;
+ __MALLOC_UNLOCK;
return 0;
}
void * memalign (size_t alignment, size_t size)
@@ -162,11 +160,10 @@ void * memalign (size_t alignment, size_t size)
if (result == NULL)
return NULL;
- adj = (unsigned long int) ((unsigned long int) ((char *) result -
- (char *) NULL)) % alignment;
+ adj = (unsigned long int) ((unsigned long int) ((char *) result - (char *) NULL)) % alignment;
if (adj != 0) {
struct alignlist *l;
- LOCK;
+ __MALLOC_LOCK;
for (l = _aligned_blocks; l != NULL; l = l->next)
if (l->aligned == NULL)
/* This slot is free. Use it. */
@@ -175,15 +172,16 @@ void * memalign (size_t alignment, size_t size)
l = (struct alignlist *) malloc (sizeof (struct alignlist));
if (l == NULL) {
free(result);
- UNLOCK;
- return NULL;
+ result = NULL;
+ goto DONE;
}
l->next = _aligned_blocks;
_aligned_blocks = l;
}
l->exact = result;
result = l->aligned = (char *) result + alignment - adj;
- UNLOCK;
+DONE:
+ __MALLOC_UNLOCK;
}
return result;
diff --git a/libc/stdlib/malloc-standard/calloc.c b/libc/stdlib/malloc-standard/calloc.c
index 99e8884ad..80ba3d04a 100644
--- a/libc/stdlib/malloc-standard/calloc.c
+++ b/libc/stdlib/malloc-standard/calloc.c
@@ -16,7 +16,7 @@
#include "malloc.h"
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
/* ------------------------------ calloc ------------------------------ */
void* calloc(size_t n_elements, size_t elem_size)
@@ -36,7 +36,7 @@ void* calloc(size_t n_elements, size_t elem_size)
return NULL;
}
- LOCK;
+ __MALLOC_LOCK;
mem = malloc(size);
if (mem != 0) {
p = mem2chunk(mem);
@@ -88,7 +88,7 @@ void* calloc(size_t n_elements, size_t elem_size)
}
#endif
}
- UNLOCK;
+ __MALLOC_UNLOCK;
return mem;
}
diff --git a/libc/stdlib/malloc-standard/free.c b/libc/stdlib/malloc-standard/free.c
index e0c6ef061..4d24697be 100644
--- a/libc/stdlib/malloc-standard/free.c
+++ b/libc/stdlib/malloc-standard/free.c
@@ -282,7 +282,7 @@ void free(void* mem)
if (mem == NULL)
return;
- LOCK;
+ __MALLOC_LOCK;
av = get_malloc_state();
p = mem2chunk(mem);
size = chunksize(p);
@@ -406,6 +406,6 @@ void free(void* mem)
av->mmapped_mem -= (size + offset);
munmap((char*)p - offset, size + offset);
}
- UNLOCK;
+ __MALLOC_UNLOCK;
}
diff --git a/libc/stdlib/malloc-standard/mallinfo.c b/libc/stdlib/malloc-standard/mallinfo.c
index 4f274ed32..18331010a 100644
--- a/libc/stdlib/malloc-standard/mallinfo.c
+++ b/libc/stdlib/malloc-standard/mallinfo.c
@@ -32,7 +32,7 @@ struct mallinfo mallinfo(void)
int nblocks;
int nfastblocks;
- LOCK;
+ __MALLOC_LOCK;
av = get_malloc_state();
/* Ensure initialization */
if (av->top == 0) {
@@ -77,7 +77,7 @@ struct mallinfo mallinfo(void)
mi.fsmblks = fastavail;
mi.keepcost = chunksize(av->top);
mi.usmblks = av->max_total_mem;
- UNLOCK;
+ __MALLOC_UNLOCK;
return mi;
}
libc_hidden_def(mallinfo)
@@ -91,19 +91,36 @@ void malloc_stats(FILE *file)
}
mi = mallinfo();
- fprintf(file, "total bytes allocated = %10u\n", (unsigned int)(mi.arena + mi.hblkhd));
- fprintf(file, "total bytes in use bytes = %10u\n", (unsigned int)(mi.uordblks + mi.hblkhd));
- fprintf(file, "total non-mmapped bytes allocated = %10d\n", mi.arena);
- fprintf(file, "number of mmapped regions = %10d\n", mi.hblks);
- fprintf(file, "total allocated mmap space = %10d\n", mi.hblkhd);
- fprintf(file, "total allocated sbrk space = %10d\n", mi.uordblks);
+ fprintf(file,
+ "total bytes allocated = %10u\n"
+ "total bytes in use bytes = %10u\n"
+ "total non-mmapped bytes allocated = %10d\n"
+ "number of mmapped regions = %10d\n"
+ "total allocated mmap space = %10d\n"
+ "total allocated sbrk space = %10d\n"
#if 0
- fprintf(file, "number of free chunks = %10d\n", mi.ordblks);
- fprintf(file, "number of fastbin blocks = %10d\n", mi.smblks);
- fprintf(file, "space in freed fastbin blocks = %10d\n", mi.fsmblks);
+ "number of free chunks = %10d\n"
+ "number of fastbin blocks = %10d\n"
+ "space in freed fastbin blocks = %10d\n"
#endif
- fprintf(file, "maximum total allocated space = %10d\n", mi.usmblks);
- fprintf(file, "total free space = %10d\n", mi.fordblks);
- fprintf(file, "memory releasable via malloc_trim = %10d\n", mi.keepcost);
+ "maximum total allocated space = %10d\n"
+ "total free space = %10d\n"
+ "memory releasable via malloc_trim = %10d\n",
+
+ (unsigned int)(mi.arena + mi.hblkhd),
+ (unsigned int)(mi.uordblks + mi.hblkhd),
+ mi.arena,
+ mi.hblks,
+ mi.hblkhd,
+ mi.uordblks,
+#if 0
+ mi.ordblks,
+ mi.smblks,
+ mi.fsmblks,
+#endif
+ mi.usmblks,
+ mi.fordblks,
+ mi.keepcost
+ );
}
diff --git a/libc/stdlib/malloc-standard/malloc.c b/libc/stdlib/malloc-standard/malloc.c
index 0dc208fb6..3253ebda6 100644
--- a/libc/stdlib/malloc-standard/malloc.c
+++ b/libc/stdlib/malloc-standard/malloc.c
@@ -17,9 +17,7 @@
#include "malloc.h"
-#ifdef __UCLIBC_HAS_THREADS__
-pthread_mutex_t __malloc_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
+__UCLIBC_MUTEX_INIT(__malloc_lock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
/*
There is exactly one instance of this struct in this malloc.
@@ -33,7 +31,7 @@ struct malloc_state __malloc_state; /* never directly referenced */
/* forward declaration */
static int __malloc_largebin_index(unsigned int sz);
-#ifdef __MALLOC_DEBUGGING
+#ifdef __UCLIBC_MALLOC_DEBUGGING__
/*
Debugging support
@@ -43,21 +41,21 @@ static int __malloc_largebin_index(unsigned int sz);
programs. This can be very effective (albeit in an annoying way)
in helping track down dangling pointers.
- If you compile with -D__MALLOC_DEBUGGING, a number of assertion checks are
+ If you compile with __UCLIBC_MALLOC_DEBUGGING__, a number of assertion checks are
enabled that will catch more memory errors. You probably won't be
able to make much sense of the actual assertion errors, but they
should help you locate incorrectly overwritten memory. The
checking is fairly extensive, and will slow down execution
- noticeably. Calling malloc_stats or mallinfo with __MALLOC_DEBUGGING set will
+ noticeably. Calling malloc_stats or mallinfo with __UCLIBC_MALLOC_DEBUGGING__ set will
attempt to check every non-mmapped allocated and free chunk in the
course of computing the summmaries. (By nature, mmapped regions
cannot be checked very much automatically.)
- Setting __MALLOC_DEBUGGING may also be helpful if you are trying to modify
+ Setting __UCLIBC_MALLOC_DEBUGGING__ may also be helpful if you are trying to modify
this code. The assertions in the check routines spell out in more
detail the assumptions and invariants underlying the algorithms.
- Setting __MALLOC_DEBUGGING does NOT provide an automated mechanism for checking
+ Setting __UCLIBC_MALLOC_DEBUGGING__ does NOT provide an automated mechanism for checking
that all accesses to malloced memory stay within their
bounds. However, there are several add-ons and adaptations of this
or other mallocs available that do this.
@@ -351,7 +349,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
char* old_end; /* its end address */
long size; /* arg to first MORECORE or mmap call */
- char* brk; /* return value from MORECORE */
+ char* fst_brk; /* return value from MORECORE */
long correction; /* arg to 2nd MORECORE call */
char* snd_brk; /* 2nd return val */
@@ -455,7 +453,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
old_size = chunksize(old_top);
old_end = (char*)(chunk_at_offset(old_top, old_size));
- brk = snd_brk = (char*)(MORECORE_FAILURE);
+ fst_brk = snd_brk = (char*)(MORECORE_FAILURE);
/* If not the first time through, we require old_size to
* be at least MINSIZE and to have prev_inuse set. */
@@ -501,7 +499,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
*/
if (size > 0)
- brk = (char*)(MORECORE(size));
+ fst_brk = (char*)(MORECORE(size));
/*
If have mmap, try using it as a backup when MORECORE fails or
@@ -512,7 +510,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
segregated mmap region.
*/
- if (brk == (char*)(MORECORE_FAILURE)) {
+ if (fst_brk == (char*)(MORECORE_FAILURE)) {
/* Cannot merge with old top, so add its size back in */
if (contiguous(av))
@@ -525,12 +523,12 @@ static void* __malloc_alloc(size_t nb, mstate av)
/* Don't try if size wraps around 0 */
if ((unsigned long)(size) > (unsigned long)(nb)) {
- brk = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE));
+ fst_brk = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE));
- if (brk != (char*)(MORECORE_FAILURE)) {
+ if (fst_brk != (char*)(MORECORE_FAILURE)) {
/* We do not need, and cannot use, another sbrk call to find end */
- snd_brk = brk + size;
+ snd_brk = fst_brk + size;
/* Record that we no longer have a contiguous sbrk region.
After the first time mmap is used as backup, we do not
@@ -542,14 +540,14 @@ static void* __malloc_alloc(size_t nb, mstate av)
}
}
- if (brk != (char*)(MORECORE_FAILURE)) {
+ if (fst_brk != (char*)(MORECORE_FAILURE)) {
av->sbrked_mem += size;
/*
If MORECORE extends previous space, we can likewise extend top size.
*/
- if (brk == old_end && snd_brk == (char*)(MORECORE_FAILURE)) {
+ if (fst_brk == old_end && snd_brk == (char*)(MORECORE_FAILURE)) {
set_head(old_top, (size + old_size) | PREV_INUSE);
}
@@ -576,7 +574,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
front_misalign = 0;
end_misalign = 0;
correction = 0;
- aligned_brk = brk;
+ aligned_brk = fst_brk;
/*
If MORECORE returns an address lower than we have seen before,
@@ -586,7 +584,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
malloc or by other threads. We cannot guarantee to detect
these in all cases, but cope with the ones we do detect.
*/
- if (contiguous(av) && old_size != 0 && brk < old_end) {
+ if (contiguous(av) && old_size != 0 && fst_brk < old_end) {
set_noncontiguous(av);
}
@@ -597,11 +595,11 @@ static void* __malloc_alloc(size_t nb, mstate av)
to foreign calls) but treat them as part of our space for
stats reporting. */
if (old_size != 0)
- av->sbrked_mem += brk - old_end;
+ av->sbrked_mem += fst_brk - old_end;
/* Guarantee alignment of first new chunk made from this space */
- front_misalign = (size_t)chunk2mem(brk) & MALLOC_ALIGN_MASK;
+ front_misalign = (size_t)chunk2mem(fst_brk) & MALLOC_ALIGN_MASK;
if (front_misalign > 0) {
/*
@@ -624,7 +622,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
correction += old_size;
/* Extend the end address to hit a page boundary */
- end_misalign = (size_t)(brk + size + correction);
+ end_misalign = (size_t)(fst_brk + size + correction);
correction += ((end_misalign + pagemask) & ~pagemask) - end_misalign;
assert(correction >= 0);
@@ -638,7 +636,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
correction = 0;
snd_brk = (char*)(MORECORE(0));
}
- else if (snd_brk < brk) {
+ else if (snd_brk < fst_brk) {
/*
If the second call gives noncontiguous space even though
it says it won't, the only course of action is to ignore
@@ -651,7 +649,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
there is no reliable way to detect a noncontiguity
producing a forward gap for the second call.
*/
- snd_brk = brk + size;
+ snd_brk = fst_brk + size;
correction = 0;
set_noncontiguous(av);
}
@@ -661,12 +659,12 @@ static void* __malloc_alloc(size_t nb, mstate av)
/* handle non-contiguous cases */
else {
/* MORECORE/mmap must correctly align */
- assert(aligned_OK(chunk2mem(brk)));
+ assert(aligned_OK(chunk2mem(fst_brk)));
/* Find out current end of memory */
if (snd_brk == (char*)(MORECORE_FAILURE)) {
snd_brk = (char*)(MORECORE(0));
- av->sbrked_mem += snd_brk - brk - size;
+ av->sbrked_mem += snd_brk - fst_brk - size;
}
}
@@ -825,6 +823,7 @@ void* malloc(size_t bytes)
mchunkptr fwd; /* misc temp for linking */
mchunkptr bck; /* misc temp for linking */
void * sysmem;
+ void * retval;
#if !defined(__MALLOC_GLIBC_COMPAT__)
if (!bytes) {
@@ -833,7 +832,7 @@ void* malloc(size_t bytes)
}
#endif
- LOCK;
+ __MALLOC_LOCK;
av = get_malloc_state();
/*
Convert request size to internal form by adding (sizeof(size_t)) bytes
@@ -864,8 +863,8 @@ void* malloc(size_t bytes)
if ( (victim = *fb) != 0) {
*fb = victim->fd;
check_remalloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
}
@@ -888,8 +887,8 @@ void* malloc(size_t bytes)
bck->fd = bin;
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
}
@@ -945,8 +944,8 @@ void* malloc(size_t bytes)
set_foot(remainder, remainder_size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
/* remove from unsorted list */
@@ -958,8 +957,8 @@ void* malloc(size_t bytes)
if (size == nb) {
set_inuse_bit_at_offset(victim, size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
/* place chunk in bin */
@@ -1022,8 +1021,8 @@ void* malloc(size_t bytes)
if (remainder_size < MINSIZE) {
set_inuse_bit_at_offset(victim, size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
/* Split */
else {
@@ -1034,8 +1033,8 @@ void* malloc(size_t bytes)
set_head(remainder, remainder_size | PREV_INUSE);
set_foot(remainder, remainder_size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
}
}
@@ -1103,8 +1102,8 @@ void* malloc(size_t bytes)
if (remainder_size < MINSIZE) {
set_inuse_bit_at_offset(victim, size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
/* Split */
@@ -1121,8 +1120,8 @@ void* malloc(size_t bytes)
set_head(remainder, remainder_size | PREV_INUSE);
set_foot(remainder, remainder_size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
}
}
@@ -1154,13 +1153,15 @@ use_top:
set_head(remainder, remainder_size | PREV_INUSE);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
/* If no space in top, relay to handle system-dependent cases */
sysmem = __malloc_alloc(nb, av);
- UNLOCK;
- return sysmem;
+ retval = sysmem;
+DONE:
+ __MALLOC_UNLOCK;
+ return retval;
}
diff --git a/libc/stdlib/malloc-standard/malloc.h b/libc/stdlib/malloc-standard/malloc.h
index 453d69736..389f1f7d4 100644
--- a/libc/stdlib/malloc-standard/malloc.h
+++ b/libc/stdlib/malloc-standard/malloc.h
@@ -22,18 +22,17 @@
#include <malloc.h>
#include <stdlib.h>
#include <sys/mman.h>
+#include <bits/uClibc_mutex.h>
libc_hidden_proto(mmap)
libc_hidden_proto(sysconf)
libc_hidden_proto(sbrk)
libc_hidden_proto(abort)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-extern pthread_mutex_t __malloc_lock;
-#endif
-#define LOCK __pthread_mutex_lock(&__malloc_lock)
-#define UNLOCK __pthread_mutex_unlock(&__malloc_lock)
+
+__UCLIBC_MUTEX_EXTERN(__malloc_lock);
+#define __MALLOC_LOCK __UCLIBC_MUTEX_LOCK(__malloc_lock)
+#define __MALLOC_UNLOCK __UCLIBC_MUTEX_UNLOCK(__malloc_lock)
@@ -925,7 +924,7 @@ extern struct malloc_state __malloc_state; /* never directly referenced */
At most one "call" to get_malloc_state is made per invocation of
the public versions of malloc and free, but other routines
that in turn invoke malloc and/or free may call more then once.
- Also, it is called in check* routines if __MALLOC_DEBUGGING is set.
+ Also, it is called in check* routines if __UCLIBC_MALLOC_DEBUGGING__ is set.
*/
#define get_malloc_state() (&(__malloc_state))
@@ -935,7 +934,7 @@ void __malloc_consolidate(mstate) attribute_hidden;
/* Debugging support */
-#if ! __MALLOC_DEBUGGING
+#ifndef __UCLIBC_MALLOC_DEBUGGING__
#define check_chunk(P)
#define check_free_chunk(P)
diff --git a/libc/stdlib/malloc-standard/mallopt.c b/libc/stdlib/malloc-standard/mallopt.c
index e28792099..053242dbe 100644
--- a/libc/stdlib/malloc-standard/mallopt.c
+++ b/libc/stdlib/malloc-standard/mallopt.c
@@ -25,7 +25,7 @@ int mallopt(int param_number, int value)
ret = 0;
- LOCK;
+ __MALLOC_LOCK;
av = get_malloc_state();
/* Ensure initialization/consolidation */
__malloc_consolidate(av);
@@ -58,7 +58,7 @@ int mallopt(int param_number, int value)
ret = 1;
break;
}
- UNLOCK;
+ __MALLOC_UNLOCK;
return ret;
}
diff --git a/libc/stdlib/malloc-standard/memalign.c b/libc/stdlib/malloc-standard/memalign.c
index 27502893d..7e0674be5 100644
--- a/libc/stdlib/malloc-standard/memalign.c
+++ b/libc/stdlib/malloc-standard/memalign.c
@@ -35,6 +35,7 @@ void* memalign(size_t alignment, size_t bytes)
mchunkptr remainder; /* spare room at end to split off */
unsigned long remainder_size; /* its size */
size_t size;
+ void *retval;
/* If need less alignment than we give anyway, just relay to malloc */
@@ -51,7 +52,7 @@ void* memalign(size_t alignment, size_t bytes)
alignment = a;
}
- LOCK;
+ __MALLOC_LOCK;
checked_request2size(bytes, nb);
/* Strategy: find a spot within that chunk that meets the alignment
@@ -63,8 +64,8 @@ void* memalign(size_t alignment, size_t bytes)
m = (char*)(malloc(nb + alignment + MINSIZE));
if (m == 0) {
- UNLOCK;
- return 0; /* propagate failure */
+ retval = 0; /* propagate failure */
+ goto DONE;
}
p = mem2chunk(m);
@@ -92,8 +93,8 @@ void* memalign(size_t alignment, size_t bytes)
if (chunk_is_mmapped(p)) {
newp->prev_size = p->prev_size + leadsize;
set_head(newp, newsize|IS_MMAPPED);
- UNLOCK;
- return chunk2mem(newp);
+ retval = chunk2mem(newp);
+ goto DONE;
}
/* Otherwise, give back leader, use the rest */
@@ -120,7 +121,10 @@ void* memalign(size_t alignment, size_t bytes)
}
check_inuse_chunk(p);
- UNLOCK;
- return chunk2mem(p);
+ retval = chunk2mem(p);
+
+ DONE:
+ __MALLOC_UNLOCK;
+ return retval;
}
diff --git a/libc/stdlib/malloc-standard/realloc.c b/libc/stdlib/malloc-standard/realloc.c
index f25d6d989..41cae43d1 100644
--- a/libc/stdlib/malloc-standard/realloc.c
+++ b/libc/stdlib/malloc-standard/realloc.c
@@ -17,7 +17,7 @@
#include "malloc.h"
libc_hidden_proto(mremap)
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
/* ------------------------------ realloc ------------------------------ */
void* realloc(void* oldmem, size_t bytes)
@@ -46,6 +46,7 @@ void* realloc(void* oldmem, size_t bytes)
size_t* s; /* copy source */
size_t* d; /* copy destination */
+ void *retval;
/* Check for special cases. */
if (! oldmem)
@@ -55,7 +56,7 @@ void* realloc(void* oldmem, size_t bytes)
return NULL;
}
- LOCK;
+ __MALLOC_LOCK;
av = get_malloc_state();
checked_request2size(bytes, nb);
@@ -82,8 +83,8 @@ void* realloc(void* oldmem, size_t bytes)
set_head_size(oldp, nb);
av->top = chunk_at_offset(oldp, nb);
set_head(av->top, (newsize - nb) | PREV_INUSE);
- UNLOCK;
- return chunk2mem(oldp);
+ retval = chunk2mem(oldp);
+ goto DONE;
}
/* Try to expand forward into next chunk; split off remainder below */
@@ -99,8 +100,8 @@ void* realloc(void* oldmem, size_t bytes)
else {
newmem = malloc(nb - MALLOC_ALIGN_MASK);
if (newmem == 0) {
- UNLOCK;
- return 0; /* propagate failure */
+ retval = 0; /* propagate failure */
+ goto DONE;
}
newp = mem2chunk(newmem);
@@ -149,8 +150,8 @@ void* realloc(void* oldmem, size_t bytes)
free(oldmem);
check_inuse_chunk(newp);
- UNLOCK;
- return chunk2mem(newp);
+ retval = chunk2mem(newp);
+ goto DONE;
}
}
}
@@ -175,8 +176,8 @@ void* realloc(void* oldmem, size_t bytes)
}
check_inuse_chunk(newp);
- UNLOCK;
- return chunk2mem(newp);
+ retval = chunk2mem(newp);
+ goto DONE;
}
/*
@@ -194,8 +195,8 @@ void* realloc(void* oldmem, size_t bytes)
/* don't need to remap if still within same page */
if (oldsize == newsize - offset) {
- UNLOCK;
- return oldmem;
+ retval = oldmem;
+ goto DONE;
}
cp = (char*)mremap((char*)oldp - offset, oldsize + offset, newsize, 1);
@@ -216,8 +217,8 @@ void* realloc(void* oldmem, size_t bytes)
if (sum > (unsigned long)(av->max_total_mem))
av->max_total_mem = sum;
- UNLOCK;
- return chunk2mem(newp);
+ retval = chunk2mem(newp);
+ goto DONE;
}
/* Note the extra (sizeof(size_t)) overhead. */
@@ -231,8 +232,11 @@ void* realloc(void* oldmem, size_t bytes)
free(oldmem);
}
}
- UNLOCK;
- return newmem;
+ retval = newmem;
}
+
+ DONE:
+ __MALLOC_UNLOCK;
+ return retval;
}
diff --git a/libc/stdlib/malloc/calloc.c b/libc/stdlib/malloc/calloc.c
index 5925a9e0a..79e6ec6c7 100644
--- a/libc/stdlib/malloc/calloc.c
+++ b/libc/stdlib/malloc/calloc.c
@@ -22,7 +22,7 @@
#include <string.h>
#include <errno.h>
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
void * calloc(size_t nmemb, size_t lsize)
{
diff --git a/libc/stdlib/malloc/free.c b/libc/stdlib/malloc/free.c
index 81c718376..da395331b 100644
--- a/libc/stdlib/malloc/free.c
+++ b/libc/stdlib/malloc/free.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
diff --git a/libc/stdlib/malloc/heap.h b/libc/stdlib/malloc/heap.h
index b66b5ecef..38ec41cbf 100644
--- a/libc/stdlib/malloc/heap.h
+++ b/libc/stdlib/malloc/heap.h
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
@@ -17,6 +17,7 @@
/* On multi-threaded systems, the heap includes a lock. */
#ifdef __UCLIBC_HAS_THREADS__
# include <pthread.h>
+# include <bits/uClibc_pthread.h>
# define HEAP_USE_LOCKING
#endif
@@ -24,7 +25,7 @@
/* The heap allocates in multiples of, and aligned to, HEAP_GRANULARITY.
HEAP_GRANULARITY must be a power of 2. Malloc depends on this being the
same as MALLOC_ALIGNMENT. */
-#define HEAP_GRANULARITY_TYPE double
+#define HEAP_GRANULARITY_TYPE double __attribute_aligned__ (sizeof (size_t))
#define HEAP_GRANULARITY (__alignof__ (HEAP_GRANULARITY_TYPE))
diff --git a/libc/stdlib/malloc/heap_alloc.c b/libc/stdlib/malloc/heap_alloc.c
index 8a6c7842e..f8d596506 100644
--- a/libc/stdlib/malloc/heap_alloc.c
+++ b/libc/stdlib/malloc/heap_alloc.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
diff --git a/libc/stdlib/malloc/heap_alloc_at.c b/libc/stdlib/malloc/heap_alloc_at.c
index de84e99ee..296c6e552 100644
--- a/libc/stdlib/malloc/heap_alloc_at.c
+++ b/libc/stdlib/malloc/heap_alloc_at.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
diff --git a/libc/stdlib/malloc/heap_debug.c b/libc/stdlib/malloc/heap_debug.c
index e83831d3a..a2a9f4ec1 100644
--- a/libc/stdlib/malloc/heap_debug.c
+++ b/libc/stdlib/malloc/heap_debug.c
@@ -49,7 +49,7 @@ __heap_dump_freelist (struct heap *heap)
void
__heap_dump (struct heap *heap, const char *str)
{
- static int recursed = 0;
+ static smallint recursed;
if (! recursed)
{
diff --git a/libc/stdlib/malloc/heap_free.c b/libc/stdlib/malloc/heap_free.c
index a4b5259af..8bc740dd8 100644
--- a/libc/stdlib/malloc/heap_free.c
+++ b/libc/stdlib/malloc/heap_free.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c
index 770d7aea3..ce74c5608 100644
--- a/libc/stdlib/malloc/malloc.c
+++ b/libc/stdlib/malloc/malloc.c
@@ -184,7 +184,7 @@ malloc (size_t size)
{
void *mem;
#ifdef MALLOC_DEBUGGING
- static int debugging_initialized = 0;
+ static smallint debugging_initialized;
if (! debugging_initialized)
{
debugging_initialized = 1;
diff --git a/libc/stdlib/malloc/malloc.h b/libc/stdlib/malloc/malloc.h
index b41c4b08e..7277cd2cf 100644
--- a/libc/stdlib/malloc/malloc.h
+++ b/libc/stdlib/malloc/malloc.h
@@ -11,8 +11,13 @@
* Written by Miles Bader <miles@gnu.org>
*/
-/* The alignment we guarantee for malloc return values. */
-#define MALLOC_ALIGNMENT (__alignof__ (double))
+/* The alignment we guarantee for malloc return values. We prefer this
+ to be at least sizeof (size_t) bytes because (a) we have to allocate
+ that many bytes for the header anyway and (b) guaranteeing word
+ alignment can be a significant win on targets like m68k and Coldfire,
+ where __alignof__(double) == 2. */
+#define MALLOC_ALIGNMENT \
+ __alignof__ (double __attribute_aligned__ (sizeof (size_t)))
/* The system pagesize... */
extern size_t __pagesize;
@@ -79,7 +84,6 @@ 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...) \
@@ -98,17 +102,20 @@ extern int __malloc_mmb_debug;
/* The size of a malloc allocation is stored in a size_t word
- MALLOC_ALIGNMENT bytes prior to the start address of the allocation:
+ MALLOC_HEADER_SIZE bytes prior to the start address of the allocation:
+--------+---------+-------------------+
| SIZE |(unused) | allocation ... |
+--------+---------+-------------------+
^ BASE ^ ADDR
- ^ ADDR - MALLOC_ALIGN
+ ^ ADDR - MALLOC_HEADER_SIZE
*/
/* The amount of extra space used by the malloc header. */
-#define MALLOC_HEADER_SIZE MALLOC_ALIGNMENT
+#define MALLOC_HEADER_SIZE \
+ (MALLOC_ALIGNMENT < sizeof (size_t) \
+ ? sizeof (size_t) \
+ : MALLOC_ALIGNMENT)
/* Set up the malloc header, and return the user address of a malloc block. */
#define MALLOC_SETUP(base, size) \
@@ -126,6 +133,7 @@ extern int __malloc_mmb_debug;
#ifdef __UCLIBC_HAS_THREADS__
# include <pthread.h>
+# include <bits/uClibc_pthread.h>
# define MALLOC_USE_LOCKING
diff --git a/libc/stdlib/malloc/malloc_debug.c b/libc/stdlib/malloc/malloc_debug.c
index 6c74d78bb..39c3919c5 100644
--- a/libc/stdlib/malloc/malloc_debug.c
+++ b/libc/stdlib/malloc/malloc_debug.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
diff --git a/libc/stdlib/malloc/realloc.c b/libc/stdlib/malloc/realloc.c
index ec57b874e..948326762 100644
--- a/libc/stdlib/malloc/realloc.c
+++ b/libc/stdlib/malloc/realloc.c
@@ -15,7 +15,7 @@
#include <string.h>
#include <errno.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
#include "malloc.h"
#include "heap.h"
diff --git a/libc/stdlib/mkdtemp.c b/libc/stdlib/mkdtemp.c
index 6773a5bb3..fa9ae3b05 100644
--- a/libc/stdlib/mkdtemp.c
+++ b/libc/stdlib/mkdtemp.c
@@ -29,7 +29,7 @@
(This function comes from OpenBSD.) */
char * mkdtemp (char *template)
{
- if (__gen_tempname (template, __GT_DIR))
+ if (__gen_tempname (template, __GT_DIR))
return NULL;
else
return template;
diff --git a/libc/stdlib/ptsname.c b/libc/stdlib/ptsname.c
index dfb0d19db..1fd516234 100644
--- a/libc/stdlib/ptsname.c
+++ b/libc/stdlib/ptsname.c
@@ -29,9 +29,9 @@
#include <unistd.h>
#include <bits/uClibc_uintmaxtostr.h>
-libc_hidden_proto(strcat)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strcat) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(isatty)
libc_hidden_proto(ioctl)
libc_hidden_proto(fstat)
@@ -129,7 +129,7 @@ int ptsname_r (int fd, char *buf, size_t buflen)
return ENOTTY;
}
#else
-# if !defined TIOCGPTN
+# if defined TIOCGPTN
else if (errno == EINVAL)
# endif
{
diff --git a/libc/stdlib/random.c b/libc/stdlib/random.c
index 80df7890b..3eb8aed8a 100644
--- a/libc/stdlib/random.c
+++ b/libc/stdlib/random.c
@@ -32,14 +32,12 @@ libc_hidden_proto(srandom_r)
libc_hidden_proto(setstate_r)
libc_hidden_proto(initstate_r)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-# include <pthreadP.h>
/* POSIX.1c requires that there is mutual exclusion for the `rand' and
`srand' functions to prevent concurrent calls from modifying common
data. */
-static pthread_mutex_t lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
+
/* An improved random number generation package. In addition to the standard
rand()/srand() like interface, this package also has a special state info
@@ -187,9 +185,9 @@ static struct random_data unsafe_state =
for default usage relies on values produced by this routine. */
void srandom (unsigned int x)
{
- __pthread_mutex_lock(&lock);
+ __UCLIBC_MUTEX_LOCK(mylock);
srandom_r (x, &unsafe_state);
- __pthread_mutex_unlock(&lock);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
strong_alias(srandom,srand)
@@ -208,10 +206,10 @@ char * initstate (unsigned int seed, char *arg_state, size_t n)
{
int32_t *ostate;
- __pthread_mutex_lock(&lock);
+ __UCLIBC_MUTEX_LOCK(mylock);
ostate = &unsafe_state.state[-1];
initstate_r (seed, arg_state, n, &unsafe_state);
- __pthread_mutex_unlock(&lock);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return (char *) ostate;
}
@@ -227,11 +225,11 @@ char * setstate (char *arg_state)
{
int32_t *ostate;
- __pthread_mutex_lock(&lock);
+ __UCLIBC_MUTEX_LOCK(mylock);
ostate = &unsafe_state.state[-1];
if (setstate_r (arg_state, &unsafe_state) < 0)
ostate = NULL;
- __pthread_mutex_unlock(&lock);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return (char *) ostate;
}
@@ -251,9 +249,9 @@ long int random (void)
{
int32_t retval;
- __pthread_mutex_lock(&lock);
+ __UCLIBC_MUTEX_LOCK(mylock);
random_r (&unsafe_state, &retval);
- __pthread_mutex_unlock(&lock);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return retval;
}
libc_hidden_def(random)
diff --git a/libc/stdlib/realpath.c b/libc/stdlib/realpath.c
index b28d6f07e..e9eabdfaa 100644
--- a/libc/stdlib/realpath.c
+++ b/libc/stdlib/realpath.c
@@ -21,9 +21,9 @@
#include <sys/stat.h> /* for S_IFLNK */
-libc_hidden_proto(strcat)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strcat) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(readlink)
libc_hidden_proto(getcwd)
@@ -42,20 +42,23 @@ libc_hidden_proto(getcwd)
#define MAX_READLINKS 32
#ifdef __STDC__
-char *realpath(const char *path, char resolved_path[])
+char *realpath(const char *path, char got_path[])
#else
-char *realpath(path, resolved_path)
+char *realpath(path, got_path)
const char *path;
-char resolved_path[];
+char got_path[];
#endif
{
char copy_path[PATH_MAX];
- char link_path[PATH_MAX];
- char got_path[PATH_MAX];
- char *new_path = got_path;
+ /* use user supplied buffer directly - reduces stack usage */
+ /* char got_path[PATH_MAX]; */
char *max_path;
+ char *new_path;
+ size_t path_len;
int readlinks = 0;
- int n;
+#ifdef S_IFLNK
+ int link_len;
+#endif
if (path == NULL) {
__set_errno(EINVAL);
@@ -66,17 +69,20 @@ char resolved_path[];
return NULL;
}
/* Make a copy of the source path since we may need to modify it. */
- if (strlen(path) >= PATH_MAX - 2) {
+ path_len = strlen(path);
+ if (path_len >= PATH_MAX - 2) {
__set_errno(ENAMETOOLONG);
return NULL;
}
- strcpy(copy_path, path);
- path = copy_path;
- max_path = copy_path + PATH_MAX - 2;
- /* If it's a relative pathname use getcwd for starters. */
+ /* Copy so that path is at the end of copy_path[] */
+ strcpy(copy_path + (PATH_MAX-1) - path_len, path);
+ path = copy_path + (PATH_MAX-1) - path_len;
+ max_path = got_path + PATH_MAX - 2; /* points to last non-NUL char */
+ new_path = got_path;
if (*path != '/') {
- /* Ohoo... */
- getcwd(new_path, PATH_MAX - 1);
+ /* If it's a relative pathname use getcwd for starters. */
+ if (!getcwd(new_path, PATH_MAX - 1))
+ return NULL;
new_path += strlen(new_path);
if (new_path[-1] != '/')
*new_path++ = '/';
@@ -111,7 +117,7 @@ char resolved_path[];
}
/* Safely copy the next pathname component. */
while (*path != '\0' && *path != '/') {
- if (path > max_path) {
+ if (new_path > max_path) {
__set_errno(ENAMETOOLONG);
return NULL;
}
@@ -123,35 +129,36 @@ char resolved_path[];
__set_errno(ELOOP);
return NULL;
}
- /* See if latest pathname component is a symlink. */
+ path_len = strlen(path);
+ /* See if last (so far) pathname component is a symlink. */
*new_path = '\0';
- n = readlink(got_path, link_path, PATH_MAX - 1);
- if (n < 0) {
- /* EINVAL means the file exists but isn't a symlink. */
- if (errno != EINVAL) {
- /* Make sure it's null terminated. */
- *new_path = '\0';
- strcpy(resolved_path, got_path);
- return NULL;
- }
- } else {
- /* Note: readlink doesn't add the null byte. */
- link_path[n] = '\0';
- if (*link_path == '/')
- /* Start over for an absolute symlink. */
- new_path = got_path;
- else
- /* Otherwise back up over this component. */
- while (*(--new_path) != '/');
- /* Safe sex check. */
- if (strlen(path) + n >= PATH_MAX - 2) {
- __set_errno(ENAMETOOLONG);
- return NULL;
+ {
+ int sv_errno = errno;
+ link_len = readlink(got_path, copy_path, PATH_MAX - 1);
+ if (link_len < 0) {
+ /* EINVAL means the file exists but isn't a symlink. */
+ if (errno != EINVAL) {
+ return NULL;
+ }
+ } else {
+ /* Safe sex check. */
+ if (path_len + link_len >= PATH_MAX - 2) {
+ __set_errno(ENAMETOOLONG);
+ return NULL;
+ }
+ /* Note: readlink doesn't add the null byte. */
+ /* copy_path[link_len] = '\0'; - we don't need it too */
+ if (*copy_path == '/')
+ /* Start over for an absolute symlink. */
+ new_path = got_path;
+ else
+ /* Otherwise back up over this component. */
+ while (*(--new_path) != '/');
+ /* Prepend symlink contents to path. */
+ memmove(copy_path + (PATH_MAX-1) - link_len - path_len, copy_path, link_len);
+ path = copy_path + (PATH_MAX-1) - link_len - path_len;
}
- /* Insert symlink contents into path. */
- strcat(link_path, path);
- strcpy(copy_path, link_path);
- path = copy_path;
+ __set_errno(sv_errno);
}
#endif /* S_IFLNK */
*new_path++ = '/';
@@ -161,6 +168,5 @@ char resolved_path[];
new_path--;
/* Make sure it's null terminated. */
*new_path = '\0';
- strcpy(resolved_path, got_path);
- return resolved_path;
+ return got_path;
}
diff --git a/libc/stdlib/seed48_r.c b/libc/stdlib/seed48_r.c
index c88d0f23e..3769e0fa7 100644
--- a/libc/stdlib/seed48_r.c
+++ b/libc/stdlib/seed48_r.c
@@ -21,7 +21,7 @@
#include <string.h>
#include <limits.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(seed48_r)
int seed48_r (unsigned short int seed16v[3], struct drand48_data *buffer)
diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c
index b2d807b50..833bd8fcd 100644
--- a/libc/stdlib/setenv.c
+++ b/libc/stdlib/setenv.c
@@ -14,10 +14,10 @@
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.
-
+ 02111-1307 USA.
+
modified for uClibc by Erik Andersen <andersen@codepoet.org>
- */
+*/
#include <features.h>
#include <errno.h>
@@ -25,20 +25,15 @@
#include <string.h>
#include <unistd.h>
-libc_hidden_proto(memcpy)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strncmp)
-libc_hidden_proto(strndup)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strncmp) */
+/* Experimentally off - libc_hidden_proto(strndup) */
libc_hidden_proto(unsetenv)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-# include <pthreadP.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
/* If this variable is not a null pointer we allocated the current
@@ -52,17 +47,18 @@ static char **last_environ;
must be used directly. This is all complicated by the fact that we try
to reuse values once generated for a `setenv' call since we can never
free the strings. */
-int __add_to_environ (const char *name, const char *value,
+int __add_to_environ (const char *name, const char *value,
const char *combined, int replace) attribute_hidden;
-int __add_to_environ (const char *name, const char *value,
- const char *combined, int replace)
+int __add_to_environ (const char *name, const char *value,
+ const char *combined, int replace)
{
register char **ep;
register size_t size;
const size_t namelen = strlen (name);
const size_t vallen = value != NULL ? strlen (value) + 1 : 0;
+ int rv = -1;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
/* We have to get the pointer now that we have the lock and not earlier
since another thread might have created a new environment. */
@@ -70,72 +66,71 @@ int __add_to_environ (const char *name, const char *value,
size = 0;
if (ep != NULL) {
- for (; *ep != NULL; ++ep) {
- if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=')
- break;
- else
- ++size;
- }
+ for (; *ep != NULL; ++ep) {
+ if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=')
+ break;
+ else
+ ++size;
+ }
}
if (ep == NULL || *ep == NULL) {
- char **new_environ;
-
- /* We allocated this space; we can extend it. */
- new_environ = (char **) realloc (last_environ,
- (size + 2) * sizeof (char *));
- if (new_environ == NULL) {
- UNLOCK;
- return -1;
- }
-
- /* If the whole entry is given add it. */
- if (combined != NULL) {
- /* We must not add the string to the search tree since it belongs
- to the user. */
- new_environ[size] = (char *) combined;
- } else {
- /* See whether the value is already known. */
- new_environ[size] = (char *) malloc (namelen + 1 + vallen);
- if (new_environ[size] == NULL) {
- __set_errno (ENOMEM);
- UNLOCK;
- return -1;
- }
-
- memcpy (new_environ[size], name, namelen);
- new_environ[size][namelen] = '=';
- memcpy (&new_environ[size][namelen + 1], value, vallen);
- }
-
- if (__environ != last_environ) {
- memcpy ((char *) new_environ, (char *) __environ,
- size * sizeof (char *));
- }
-
- new_environ[size + 1] = NULL;
- last_environ = __environ = new_environ;
+ char **new_environ;
+
+ /* We allocated this space; we can extend it. */
+ new_environ = (char **) realloc (last_environ, (size + 2) * sizeof (char *));
+ if (new_environ == NULL) {
+ goto DONE;
+ }
+
+ /* If the whole entry is given add it. */
+ if (combined != NULL) {
+ /* We must not add the string to the search tree since it belongs
+ to the user. */
+ new_environ[size] = (char *) combined;
+ } else {
+ /* See whether the value is already known. */
+ new_environ[size] = (char *) malloc (namelen + 1 + vallen);
+ if (new_environ[size] == NULL) {
+ __set_errno (ENOMEM);
+ goto DONE;
+ }
+
+ memcpy (new_environ[size], name, namelen);
+ new_environ[size][namelen] = '=';
+ memcpy (&new_environ[size][namelen + 1], value, vallen);
+ }
+
+ if (__environ != last_environ) {
+ memcpy ((char *) new_environ, (char *) __environ,
+ size * sizeof (char *));
+ }
+
+ new_environ[size + 1] = NULL;
+ last_environ = __environ = new_environ;
} else if (replace) {
- char *np;
-
- /* Use the user string if given. */
- if (combined != NULL) {
- np = (char *) combined;
- } else {
- np = malloc (namelen + 1 + vallen);
- if (np == NULL) {
- UNLOCK;
- return -1;
- }
- memcpy (np, name, namelen);
- np[namelen] = '=';
- memcpy (&np[namelen + 1], value, vallen);
- }
- *ep = np;
+ char *np;
+
+ /* Use the user string if given. */
+ if (combined != NULL) {
+ np = (char *) combined;
+ } else {
+ np = malloc (namelen + 1 + vallen);
+ if (np == NULL) {
+ goto DONE;
+ }
+ memcpy (np, name, namelen);
+ np[namelen] = '=';
+ memcpy (&np[namelen + 1], value, vallen);
+ }
+ *ep = np;
}
- UNLOCK;
- return 0;
+ rv = 0;
+
+ DONE:
+ __UCLIBC_MUTEX_UNLOCK(mylock);
+ return rv;
}
libc_hidden_proto(setenv)
@@ -152,26 +147,26 @@ int unsetenv (const char *name)
char **ep;
if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) {
- __set_errno (EINVAL);
- return -1;
+ __set_errno (EINVAL);
+ return -1;
}
len = strlen (name);
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
ep = __environ;
while (*ep != NULL) {
- if (!strncmp (*ep, name, len) && (*ep)[len] == '=') {
- /* Found it. Remove this pointer by moving later ones back. */
- char **dp = ep;
- do {
- dp[0] = dp[1];
- } while (*dp++);
- /* Continue the loop in case NAME appears again. */
- } else {
- ++ep;
- }
+ if (!strncmp (*ep, name, len) && (*ep)[len] == '=') {
+ /* Found it. Remove this pointer by moving later ones back. */
+ char **dp = ep;
+ do {
+ dp[0] = dp[1];
+ } while (*dp++);
+ /* Continue the loop in case NAME appears again. */
+ } else {
+ ++ep;
+ }
}
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return 0;
}
libc_hidden_def(unsetenv)
@@ -181,15 +176,15 @@ libc_hidden_def(unsetenv)
for Fortran 77) requires this function. */
int clearenv (void)
{
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (__environ == last_environ && __environ != NULL) {
- /* We allocated this environment so we can free it. */
- free (__environ);
- last_environ = NULL;
+ /* We allocated this environment so we can free it. */
+ free (__environ);
+ last_environ = NULL;
}
/* Clear the environment pointer removes the whole environment. */
__environ = NULL;
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return 0;
}
@@ -200,10 +195,10 @@ int putenv (char *string)
const char *const name_end = strchr (string, '=');
if (name_end != NULL) {
- char *name = strndup(string, name_end - string);
- result = __add_to_environ (name, NULL, string, 1);
- free(name);
- return(result);
+ char *name = strndup(string, name_end - string);
+ result = __add_to_environ (name, NULL, string, 1);
+ free(name);
+ return(result);
}
unsetenv (string);
return 0;
diff --git a/libc/stdlib/stdlib.c b/libc/stdlib/stdlib.c
index ccd3c015d..a864dd574 100644
--- a/libc/stdlib/stdlib.c
+++ b/libc/stdlib/stdlib.c
@@ -34,6 +34,7 @@
#define _ISOC99_SOURCE /* for ULLONG primarily... */
#include <limits.h>
+#include <stdint.h>
/* Work around gcc's refusal to create aliases.
* TODO: Add in a define to disable the aliases? */
@@ -327,9 +328,9 @@ long long atoll(const char *nptr)
libc_hidden_proto(__XL_NPP(strtol))
long __XL_NPP(strtol)(const char * __restrict str, char ** __restrict endptr,
- int base __LOCALE_PARAM )
+ int base __LOCALE_PARAM)
{
- return __XL_NPP(_stdlib_strto_l)(str, endptr, base, 1 __LOCALE_ARG );
+ return __XL_NPP(_stdlib_strto_l)(str, endptr, base, 1 __LOCALE_ARG);
}
libc_hidden_def(__XL_NPP(strtol))
@@ -358,10 +359,9 @@ libc_hidden_def(__XL_NPP(strtoll))
libc_hidden_proto(__XL_NPP(strtoll))
long long __XL_NPP(strtoll)(const char * __restrict str,
char ** __restrict endptr, int base
- __LOCALE_PARAM )
+ __LOCALE_PARAM)
{
- return (long long) __XL_NPP(_stdlib_strto_ll)(str, endptr, base, 1
- __LOCALE_ARG );
+ return (long long) __XL_NPP(_stdlib_strto_ll)(str, endptr, base, 1 __LOCALE_ARG);
}
libc_hidden_def(__XL_NPP(strtoll))
@@ -381,9 +381,9 @@ strong_alias(strtoll,strtoq)
libc_hidden_proto(__XL_NPP(strtoul))
unsigned long __XL_NPP(strtoul)(const char * __restrict str,
char ** __restrict endptr, int base
- __LOCALE_PARAM )
+ __LOCALE_PARAM)
{
- return __XL_NPP(_stdlib_strto_l)(str, endptr, base, 0 __LOCALE_ARG );
+ return __XL_NPP(_stdlib_strto_l)(str, endptr, base, 0 __LOCALE_ARG);
}
libc_hidden_def(__XL_NPP(strtoul))
@@ -413,9 +413,9 @@ libc_hidden_def(__XL_NPP(strtoull))
libc_hidden_proto(__XL_NPP(strtoull))
unsigned long long __XL_NPP(strtoull)(const char * __restrict str,
char ** __restrict endptr, int base
- __LOCALE_PARAM )
+ __LOCALE_PARAM)
{
- return __XL_NPP(_stdlib_strto_ll)(str, endptr, base, 0 __LOCALE_ARG );
+ return __XL_NPP(_stdlib_strto_ll)(str, endptr, base, 0 __LOCALE_ARG);
}
libc_hidden_def(__XL_NPP(strtoull))
@@ -502,39 +502,39 @@ unsigned long attribute_hidden _stdlib_strto_l(register const Wchar * __restrict
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
unsigned long attribute_hidden __XL_NPP(_stdlib_strto_l)(register const Wchar * __restrict str,
Wchar ** __restrict endptr, int base,
- int sflag __LOCALE_PARAM )
+ int sflag __LOCALE_PARAM)
{
- unsigned long number, cutoff;
+ unsigned long number, cutoff;
#if _STRTO_ENDPTR
- const Wchar *fail_char;
-#define SET_FAIL(X) fail_char = (X)
+ const Wchar *fail_char;
+#define SET_FAIL(X) fail_char = (X)
#else
-#define SET_FAIL(X) ((void)(X)) /* Keep side effects. */
+#define SET_FAIL(X) ((void)(X)) /* Keep side effects. */
#endif
- unsigned char negative, digit, cutoff_digit;
+ unsigned char negative, digit, cutoff_digit;
assert(((unsigned int)sflag) <= 1);
SET_FAIL(str);
- while (ISSPACE(*str)) { /* Skip leading whitespace. */
+ while (ISSPACE(*str)) { /* Skip leading whitespace. */
++str;
- }
+ }
- /* Handle optional sign. */
- negative = 0;
- switch(*str) {
+ /* Handle optional sign. */
+ negative = 0;
+ switch (*str) {
case '-': negative = 1; /* Fall through to increment str. */
case '+': ++str;
- }
+ }
- if (!(base & ~0x10)) { /* Either dynamic (base = 0) or base 16. */
+ if (!(base & ~0x10)) { /* Either dynamic (base = 0) or base 16. */
base += 10; /* Default is 10 (26). */
if (*str == '0') {
SET_FAIL(++str);
@@ -548,19 +548,19 @@ unsigned long attribute_hidden __XL_NPP(_stdlib_strto_l)(register const Wchar *
if (base > 16) { /* Adjust in case base wasn't dynamic. */
base = 16;
}
- }
+ }
number = 0;
- if (((unsigned)(base - 2)) < 35) { /* Legal base. */
+ if (((unsigned)(base - 2)) < 35) { /* Legal base. */
cutoff_digit = ULONG_MAX % base;
cutoff = ULONG_MAX / base;
do {
- digit = (((Wuchar)(*str - '0')) <= 9)
- ? (*str - '0')
- : ((*str >= 'A')
- ? (((0x20|(*str)) - 'a' + 10)) /* WARNING: assumes ascii. */
- : 40);
+ digit = ((Wuchar)(*str - '0') <= 9)
+ ? /* 0..9 */ (*str - '0')
+ : /* else */ (((Wuchar)(0x20 | *str) >= 'a') /* WARNING: assumes ascii. */
+ ? /* >= A/a */ ((Wuchar)(0x20 | *str) - ('a' - 10))
+ : /* else */ 40 /* bad value */);
if (digit >= base) {
break;
@@ -580,13 +580,13 @@ unsigned long attribute_hidden __XL_NPP(_stdlib_strto_l)(register const Wchar *
}
#if _STRTO_ENDPTR
- if (endptr) {
+ if (endptr) {
*endptr = (Wchar *) fail_char;
- }
+ }
#endif
{
- unsigned long tmp = ((negative)
+ unsigned long tmp = (negative
? ((unsigned long)(-(1+LONG_MIN)))+1
: LONG_MAX);
if (sflag && (number > tmp)) {
@@ -660,34 +660,34 @@ libc_hidden_proto(__ctype_b)
unsigned long long attribute_hidden __XL_NPP(_stdlib_strto_ll)(register const Wchar * __restrict str,
Wchar ** __restrict endptr, int base,
- int sflag __LOCALE_PARAM )
+ int sflag __LOCALE_PARAM)
{
- unsigned long long number;
+ unsigned long long number;
#if _STRTO_ENDPTR
- const Wchar *fail_char;
-#define SET_FAIL(X) fail_char = (X)
+ const Wchar *fail_char;
+#define SET_FAIL(X) fail_char = (X)
#else
-#define SET_FAIL(X) ((void)(X)) /* Keep side effects. */
+#define SET_FAIL(X) ((void)(X)) /* Keep side effects. */
#endif
unsigned int n1;
- unsigned char negative, digit;
+ unsigned char negative, digit;
assert(((unsigned int)sflag) <= 1);
SET_FAIL(str);
- while (ISSPACE(*str)) { /* Skip leading whitespace. */
+ while (ISSPACE(*str)) { /* Skip leading whitespace. */
++str;
- }
+ }
- /* Handle optional sign. */
- negative = 0;
- switch(*str) {
+ /* Handle optional sign. */
+ negative = 0;
+ switch (*str) {
case '-': negative = 1; /* Fall through to increment str. */
case '+': ++str;
- }
+ }
- if (!(base & ~0x10)) { /* Either dynamic (base = 0) or base 16. */
+ if (!(base & ~0x10)) { /* Either dynamic (base = 0) or base 16. */
base += 10; /* Default is 10 (26). */
if (*str == '0') {
SET_FAIL(++str);
@@ -701,17 +701,17 @@ unsigned long long attribute_hidden __XL_NPP(_stdlib_strto_ll)(register const Wc
if (base > 16) { /* Adjust in case base wasn't dynamic. */
base = 16;
}
- }
+ }
number = 0;
- if (((unsigned)(base - 2)) < 35) { /* Legal base. */
+ if (((unsigned)(base - 2)) < 35) { /* Legal base. */
do {
- digit = (((Wuchar)(*str - '0')) <= 9)
- ? (*str - '0')
- : ((*str >= 'A')
- ? (((0x20|(*str)) - 'a' + 10)) /* WARNING: assumes ascii. */
- : 40);
+ digit = ((Wuchar)(*str - '0') <= 9)
+ ? /* 0..9 */ (*str - '0')
+ : /* else */ (((Wuchar)(0x20 | *str) >= 'a') /* WARNING: assumes ascii. */
+ ? /* >= A/a */ ((Wuchar)(0x20 | *str) - ('a' - 10))
+ : /* else */ 40 /* bad value */);
if (digit >= base) {
break;
@@ -742,9 +742,9 @@ unsigned long long attribute_hidden __XL_NPP(_stdlib_strto_ll)(register const Wc
}
#if _STRTO_ENDPTR
- if (endptr) {
+ if (endptr) {
*endptr = (Wchar *) fail_char;
- }
+ }
#endif
{
@@ -817,16 +817,16 @@ void *bsearch(const void *key, const void *base, size_t /* nmemb */ high,
* bcc and gcc. */
libc_hidden_proto(qsort)
-void qsort (void *base,
- size_t nel,
- size_t width,
- int (*comp)(const void *, const void *))
+void qsort(void *base,
+ size_t nel,
+ size_t width,
+ int (*comp)(const void *, const void *))
{
size_t wgap, i, j, k;
char tmp;
if ((nel > 1) && (width > 0)) {
- assert( nel <= ((size_t)(-1)) / width ); /* check for overflow */
+ assert(nel <= ((size_t)(-1)) / width); /* check for overflow */
wgap = 0;
do {
wgap = 3 * wgap + 1;
@@ -846,7 +846,7 @@ void qsort (void *base,
j -= wgap;
a = j + ((char *)base);
b = a + wgap;
- if ( (*comp)(a, b) <= 0 ) {
+ if ((*comp)(a, b) <= 0) {
break;
}
k = width;
@@ -854,7 +854,7 @@ void qsort (void *base,
tmp = *a;
*a++ = *b;
*b++ = tmp;
- } while ( --k );
+ } while (--k);
} while (j >= wgap);
i += width;
} while (i < nel);
@@ -875,40 +875,36 @@ libc_hidden_def(qsort)
#include <stddef.h>
-void ssort (void *base,
- size_t nel,
- size_t width,
- int (*comp)(const void *, const void *))
+void ssort(void *base,
+ size_t nel,
+ size_t width,
+ int (*comp)(const void *, const void *))
{
- size_t wnel, gap, wgap, i, j, k;
- char *a, *b, tmp;
-
- wnel = width * nel;
- for (gap = 0; ++gap < nel;)
- gap *= 3;
- while ( gap /= 3 )
- {
- wgap = width * gap;
- for (i = wgap; i < wnel; i += width)
- {
- for (j = i - wgap; ;j -= wgap)
- {
- a = j + (char *)base;
- b = a + wgap;
- if ( (*comp)(a, b) <= 0 )
- break;
- k = width;
- do
- {
- tmp = *a;
- *a++ = *b;
- *b++ = tmp;
- } while ( --k );
- if (j < wgap)
- break;
- }
- }
- }
+ size_t wnel, gap, wgap, i, j, k;
+ char *a, *b, tmp;
+
+ wnel = width * nel;
+ for (gap = 0; ++gap < nel;)
+ gap *= 3;
+ while ((gap /= 3) != 0) {
+ wgap = width * gap;
+ for (i = wgap; i < wnel; i += width) {
+ for (j = i - wgap; ;j -= wgap) {
+ a = j + (char *)base;
+ b = a + wgap;
+ if ((*comp)(a, b) <= 0)
+ break;
+ k = width;
+ do {
+ tmp = *a;
+ *a++ = *b;
+ *b++ = tmp;
+ } while (--k);
+ if (j < wgap)
+ break;
+ }
+ }
+ }
}
#endif
@@ -933,6 +929,31 @@ size_t _stdlib_mb_cur_max(void)
libc_hidden_def(_stdlib_mb_cur_max)
#endif
+
+#ifdef __UCLIBC_HAS_LOCALE__
+/*
+ * The following function return 1 if the encoding is stateful, 0 if stateless.
+ * To note, until now all the supported encoding are stateless.
+ */
+
+static inline int
+is_stateful(unsigned char encoding)
+{
+ switch (encoding)
+ {
+ case __ctype_encoding_7_bit:
+ case __ctype_encoding_utf8:
+ case __ctype_encoding_8_bit:
+ return 0;
+ default:
+ assert(0);
+ return -1;
+ }
+}
+#else
+#define is_stateful(encoding) 0
+#endif
+
/**********************************************************************/
#ifdef L_mblen
@@ -945,13 +966,16 @@ int mblen(register const char *s, size_t n)
if (!s) {
state.__mask = 0;
-#ifdef __CTYPE_HAS_UTF_8_LOCALES
- return ENCODING == __ctype_encoding_utf8;
-#else
- return 0;
-#endif
+/* In this case we have to return 0 because the only multibyte supported encoding
+ is utf-8, that is a stateless encoding. See mblen() documentation.*/
+
+ return is_stateful(ENCODING);
}
+ if (*s == '\0')
+ /* According to the ISO C 89 standard this is the expected behaviour. */
+ return 0;
+
if ((r = mbrlen(s, n, &state)) == (size_t) -2) {
/* TODO: Should we set an error state? */
state.__wc = 0xffffU; /* Make sure we're in an error state. */
@@ -973,13 +997,16 @@ int mbtowc(wchar_t *__restrict pwc, register const char *__restrict s, size_t n)
if (!s) {
state.__mask = 0;
-#ifdef __CTYPE_HAS_UTF_8_LOCALES
- return ENCODING == __ctype_encoding_utf8;
-#else
- return 0;
-#endif
+/* In this case we have to return 0 because the only multibyte supported encoding
+ is utf-8, that is a stateless encoding. See mbtowc() documentation.*/
+
+ return is_stateful(ENCODING);
}
+ if (*s == '\0')
+ /* According to the ISO C 89 standard this is the expected behaviour. */
+ return 0;
+
if ((r = mbrtowc(pwc, s, n, &state)) == (size_t) -2) {
/* TODO: Should we set an error state? */
state.__wc = 0xffffU; /* Make sure we're in an error state. */
@@ -1000,11 +1027,10 @@ int wctomb(register char *__restrict s, wchar_t swc)
{
return (!s)
?
-#ifdef __CTYPE_HAS_UTF_8_LOCALES
- (ENCODING == __ctype_encoding_utf8)
-#else
- 0 /* Encoding is stateless. */
-#endif
+/* In this case we have to return 0 because the only multibyte supported encoding
+ is utf-8, that is a stateless encoding. See wctomb() documentation.*/
+
+ is_stateful(ENCODING)
: ((ssize_t) wcrtomb(s, swc, NULL));
}
@@ -1044,9 +1070,9 @@ size_t wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n)
libc_hidden_proto(__XL_NPP(wcstol))
long __XL_NPP(wcstol)(const wchar_t * __restrict str,
- wchar_t ** __restrict endptr, int base __LOCALE_PARAM )
+ wchar_t ** __restrict endptr, int base __LOCALE_PARAM)
{
- return __XL_NPP(_stdlib_wcsto_l)(str, endptr, base, 1 __LOCALE_ARG );
+ return __XL_NPP(_stdlib_wcsto_l)(str, endptr, base, 1 __LOCALE_ARG);
}
libc_hidden_def(__XL_NPP(wcstol))
@@ -1075,10 +1101,9 @@ libc_hidden_def(__XL_NPP(wcstoll))
libc_hidden_proto(__XL_NPP(wcstoll))
long long __XL_NPP(wcstoll)(const wchar_t * __restrict str,
wchar_t ** __restrict endptr, int base
- __LOCALE_PARAM )
+ __LOCALE_PARAM)
{
- return (long long) __XL_NPP(_stdlib_wcsto_ll)(str, endptr, base, 1
- __LOCALE_ARG );
+ return (long long) __XL_NPP(_stdlib_wcsto_ll)(str, endptr, base, 1 __LOCALE_ARG);
}
libc_hidden_def(__XL_NPP(wcstoll))
@@ -1098,9 +1123,9 @@ strong_alias(wcstoll,wcstoq)
libc_hidden_proto(__XL_NPP(wcstoul))
unsigned long __XL_NPP(wcstoul)(const wchar_t * __restrict str,
wchar_t ** __restrict endptr, int base
- __LOCALE_PARAM )
+ __LOCALE_PARAM)
{
- return __XL_NPP(_stdlib_wcsto_l)(str, endptr, base, 0 __LOCALE_ARG );
+ return __XL_NPP(_stdlib_wcsto_l)(str, endptr, base, 0 __LOCALE_ARG);
}
libc_hidden_def(__XL_NPP(wcstoul))
@@ -1129,9 +1154,9 @@ libc_hidden_def(__XL_NPP(wcstoull))
libc_hidden_proto(__XL_NPP(wcstoull))
unsigned long long __XL_NPP(wcstoull)(const wchar_t * __restrict str,
wchar_t ** __restrict endptr, int base
- __LOCALE_PARAM )
+ __LOCALE_PARAM)
{
- return __XL_NPP(_stdlib_wcsto_ll)(str, endptr, base, 0 __LOCALE_ARG );
+ return __XL_NPP(_stdlib_wcsto_ll)(str, endptr, base, 0 __LOCALE_ARG);
}
libc_hidden_def(__XL_NPP(wcstoull))
diff --git a/libc/stdlib/system.c b/libc/stdlib/system.c
index d1ff50f51..5b8feacf2 100644
--- a/libc/stdlib/system.c
+++ b/libc/stdlib/system.c
@@ -3,8 +3,6 @@
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define SHELL_PATH "/bin/sh" /* Path of the shell. */
-#define SHELL_NAME "sh" /* Name to give it. */
#include <stdio.h>
#include <stddef.h>
@@ -57,7 +55,7 @@ int __libc_system(const char *command)
signal(SIGINT, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
- execl(SHELL_PATH, SHELL_NAME, "-c", command, (char *) 0);
+ execl("/bin/sh", "sh", "-c", command, (char *) 0);
_exit(127);
}
/* Signals are not absolutly guarenteed with vfork */
@@ -180,7 +178,7 @@ do_system (const char *line)
{
/* Child side. */
const char *new_argv[4];
- new_argv[0] = SHELL_NAME;
+ new_argv[0] = "/bin/sh";
new_argv[1] = "-c";
new_argv[2] = line;
new_argv[3] = NULL;
@@ -192,7 +190,7 @@ do_system (const char *line)
INIT_LOCK ();
/* Exec the shell. */
- (void) execve (SHELL_PATH, (char *const *) new_argv, __environ);
+ (void) execve ("/bin/sh", (char *const *) new_argv, __environ);
_exit (127);
}
else if (pid < (pid_t) 0)
diff --git a/libc/stdlib/unix_grantpt.c b/libc/stdlib/unix_grantpt.c
index f88a54bc0..d1eef9efd 100644
--- a/libc/stdlib/unix_grantpt.c
+++ b/libc/stdlib/unix_grantpt.c
@@ -30,7 +30,7 @@
#include <unistd.h>
#include "pty-private.h"
-libc_hidden_proto(memchr)
+/* Experimentally off - libc_hidden_proto(memchr) */
libc_hidden_proto(getgid)
libc_hidden_proto(getuid)
libc_hidden_proto(setrlimit)
diff --git a/libc/sysdeps/linux/common/__rt_sigtimedwait.c b/libc/sysdeps/linux/common/__rt_sigtimedwait.c
index 4aaebefa0..554c6b9cb 100644
--- a/libc/sysdeps/linux/common/__rt_sigtimedwait.c
+++ b/libc/sysdeps/linux/common/__rt_sigtimedwait.c
@@ -8,7 +8,7 @@
* GNU Library General Public License (LGPL) version 2 or later.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <signal.h>
#include <string.h>
diff --git a/libc/sysdeps/linux/common/__rt_sigwaitinfo.c b/libc/sysdeps/linux/common/__rt_sigwaitinfo.c
index d7ec55402..5a35a5d49 100644
--- a/libc/sysdeps/linux/common/__rt_sigwaitinfo.c
+++ b/libc/sysdeps/linux/common/__rt_sigwaitinfo.c
@@ -8,7 +8,7 @@
* GNU Library General Public License (LGPL) version 2 or later.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <signal.h>
#include <string.h>
diff --git a/libc/sysdeps/linux/common/__socketcall.c b/libc/sysdeps/linux/common/__socketcall.c
index e3807cf06..5a959a63c 100644
--- a/libc/sysdeps/linux/common/__socketcall.c
+++ b/libc/sysdeps/linux/common/__socketcall.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#ifdef __NR_socketcall
#define __NR___socketcall __NR_socketcall
int __socketcall(int __call, unsigned long *__args) attribute_hidden;
diff --git a/libc/sysdeps/linux/common/__syscall_fcntl.c b/libc/sysdeps/linux/common/__syscall_fcntl.c
index 56a282a6a..6a966d7df 100644
--- a/libc/sysdeps/linux/common/__syscall_fcntl.c
+++ b/libc/sysdeps/linux/common/__syscall_fcntl.c
@@ -8,7 +8,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <stdarg.h>
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <sysdep-cancel.h> /* Must come before <fcntl.h>. */
diff --git a/libc/sysdeps/linux/common/__syscall_fcntl64.c b/libc/sysdeps/linux/common/__syscall_fcntl64.c
index a1daa7375..4c5495c24 100644
--- a/libc/sysdeps/linux/common/__syscall_fcntl64.c
+++ b/libc/sysdeps/linux/common/__syscall_fcntl64.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <stdarg.h>
#include <fcntl.h>
@@ -24,8 +24,8 @@ int __libc_fcntl64(int fd, int cmd, ...)
va_start(list, cmd);
arg = va_arg(list, long);
-
va_end(list);
+
return (__syscall_fcntl64(fd, cmd, arg));
}
libc_hidden_def(__libc_fcntl64)
diff --git a/libc/sysdeps/linux/common/__syscall_rt_sigaction.c b/libc/sysdeps/linux/common/__syscall_rt_sigaction.c
index da0f84dc0..981bb19b0 100644
--- a/libc/sysdeps/linux/common/__syscall_rt_sigaction.c
+++ b/libc/sysdeps/linux/common/__syscall_rt_sigaction.c
@@ -7,14 +7,14 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#ifdef __NR_rt_sigaction
#include <signal.h>
+#include <bits/kernel_sigaction.h>
-int __syscall_rt_sigaction (int __signum, const struct sigaction *__act, struct sigaction *__oldact, size_t __size);
#define __NR___syscall_rt_sigaction __NR_rt_sigaction
_syscall4(int, __syscall_rt_sigaction, int, signum,
- const struct sigaction *, act, struct sigaction *, oldact,
+ const struct kernel_sigaction *, act, struct kernel_sigaction *, oldact,
size_t, size);
#endif
diff --git a/libc/sysdeps/linux/common/__syscall_sigaction.c b/libc/sysdeps/linux/common/__syscall_sigaction.c
index 73d3b645f..c39b49d00 100644
--- a/libc/sysdeps/linux/common/__syscall_sigaction.c
+++ b/libc/sysdeps/linux/common/__syscall_sigaction.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#ifndef __NR_rt_sigaction
#define __NR___syscall_sigaction __NR_sigaction
diff --git a/libc/sysdeps/linux/common/access.c b/libc/sysdeps/linux/common/access.c
index 0b8c3fe3a..85533bde6 100644
--- a/libc/sysdeps/linux/common/access.c
+++ b/libc/sysdeps/linux/common/access.c
@@ -7,6 +7,6 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
_syscall2(int, access, const char *, pathname, int, mode);
diff --git a/libc/sysdeps/linux/common/acct.c b/libc/sysdeps/linux/common/acct.c
index 2e7d1c600..74156d4de 100644
--- a/libc/sysdeps/linux/common/acct.c
+++ b/libc/sysdeps/linux/common/acct.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
_syscall1(int, acct, const char *, filename);
diff --git a/libc/sysdeps/linux/common/adjtimex.c b/libc/sysdeps/linux/common/adjtimex.c
index f6cfda9cb..280f90e5a 100644
--- a/libc/sysdeps/linux/common/adjtimex.c
+++ b/libc/sysdeps/linux/common/adjtimex.c
@@ -7,11 +7,13 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/timex.h>
libc_hidden_proto(adjtimex)
_syscall1(int, adjtimex, struct timex *, buf);
libc_hidden_def(adjtimex)
+#if defined __UCLIBC_NTP_LEGACY__
strong_alias(adjtimex,ntp_adjtime)
+#endif
diff --git a/libc/sysdeps/linux/common/alarm.c b/libc/sysdeps/linux/common/alarm.c
index 4179d3416..8b499861c 100644
--- a/libc/sysdeps/linux/common/alarm.c
+++ b/libc/sysdeps/linux/common/alarm.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(alarm)
diff --git a/libc/sysdeps/linux/common/arch_prctl.c b/libc/sysdeps/linux/common/arch_prctl.c
index 4b35322a6..6d9927a01 100644
--- a/libc/sysdeps/linux/common/arch_prctl.c
+++ b/libc/sysdeps/linux/common/arch_prctl.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#ifdef __NR_arch_prctl
extern int arch_prctl(int code, unsigned long addr);
diff --git a/libc/sysdeps/linux/common/bdflush.c b/libc/sysdeps/linux/common/bdflush.c
index 9d3118875..6cf007759 100644
--- a/libc/sysdeps/linux/common/bdflush.c
+++ b/libc/sysdeps/linux/common/bdflush.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/kdaemon.h>
#ifdef __NR_bdflush
diff --git a/libc/sysdeps/linux/common/bits/confname.h b/libc/sysdeps/linux/common/bits/confname.h
index a66f85aac..ab7fdee9d 100644
--- a/libc/sysdeps/linux/common/bits/confname.h
+++ b/libc/sysdeps/linux/common/bits/confname.h
@@ -63,8 +63,10 @@ enum
#define _PC_REC_XFER_ALIGN _PC_REC_XFER_ALIGN
_PC_ALLOC_SIZE_MIN,
#define _PC_ALLOC_SIZE_MIN _PC_ALLOC_SIZE_MIN
- _PC_SYMLINK_MAX
+ _PC_SYMLINK_MAX,
#define _PC_SYMLINK_MAX _PC_SYMLINK_MAX
+ _PC_2_SYMLINKS
+#define _PC_2_SYMLINKS _PC_2_SYMLINKS
};
/* Values for the argument to `sysconf'. */
@@ -459,8 +461,45 @@ enum
#define _SC_TRACE_EVENT_FILTER _SC_TRACE_EVENT_FILTER
_SC_TRACE_INHERIT,
#define _SC_TRACE_INHERIT _SC_TRACE_INHERIT
- _SC_TRACE_LOG
+ _SC_TRACE_LOG,
#define _SC_TRACE_LOG _SC_TRACE_LOG
+
+ _SC_LEVEL1_ICACHE_SIZE,
+#define _SC_LEVEL1_ICACHE_SIZE _SC_LEVEL1_ICACHE_SIZE
+ _SC_LEVEL1_ICACHE_ASSOC,
+#define _SC_LEVEL1_ICACHE_ASSOC _SC_LEVEL1_ICACHE_ASSOC
+ _SC_LEVEL1_ICACHE_LINESIZE,
+#define _SC_LEVEL1_ICACHE_LINESIZE _SC_LEVEL1_ICACHE_LINESIZE
+ _SC_LEVEL1_DCACHE_SIZE,
+#define _SC_LEVEL1_DCACHE_SIZE _SC_LEVEL1_DCACHE_SIZE
+ _SC_LEVEL1_DCACHE_ASSOC,
+#define _SC_LEVEL1_DCACHE_ASSOC _SC_LEVEL1_DCACHE_ASSOC
+ _SC_LEVEL1_DCACHE_LINESIZE,
+#define _SC_LEVEL1_DCACHE_LINESIZE _SC_LEVEL1_DCACHE_LINESIZE
+ _SC_LEVEL2_CACHE_SIZE,
+#define _SC_LEVEL2_CACHE_SIZE _SC_LEVEL2_CACHE_SIZE
+ _SC_LEVEL2_CACHE_ASSOC,
+#define _SC_LEVEL2_CACHE_ASSOC _SC_LEVEL2_CACHE_ASSOC
+ _SC_LEVEL2_CACHE_LINESIZE,
+#define _SC_LEVEL2_CACHE_LINESIZE _SC_LEVEL2_CACHE_LINESIZE
+ _SC_LEVEL3_CACHE_SIZE,
+#define _SC_LEVEL3_CACHE_SIZE _SC_LEVEL3_CACHE_SIZE
+ _SC_LEVEL3_CACHE_ASSOC,
+#define _SC_LEVEL3_CACHE_ASSOC _SC_LEVEL3_CACHE_ASSOC
+ _SC_LEVEL3_CACHE_LINESIZE,
+#define _SC_LEVEL3_CACHE_LINESIZE _SC_LEVEL3_CACHE_LINESIZE
+ _SC_LEVEL4_CACHE_SIZE,
+#define _SC_LEVEL4_CACHE_SIZE _SC_LEVEL4_CACHE_SIZE
+ _SC_LEVEL4_CACHE_ASSOC,
+#define _SC_LEVEL4_CACHE_ASSOC _SC_LEVEL4_CACHE_ASSOC
+ _SC_LEVEL4_CACHE_LINESIZE,
+#define _SC_LEVEL4_CACHE_LINESIZE _SC_LEVEL4_CACHE_LINESIZE
+ /* Leave room here, maybe we need a few more cache levels some day. */
+
+ _SC_IPV6 = _SC_LEVEL1_ICACHE_SIZE + 50,
+#define _SC_IPV6 _SC_IPV6
+ _SC_RAW_SOCKETS
+#define _SC_RAW_SOCKETS _SC_RAW_SOCKETS
};
#if (defined __USE_POSIX2 || defined __USE_UNIX98 \
diff --git a/libc/sysdeps/linux/common/bits/dlfcn.h b/libc/sysdeps/linux/common/bits/dlfcn.h
index 75122a98a..4bfbbff04 100644
--- a/libc/sysdeps/linux/common/bits/dlfcn.h
+++ b/libc/sysdeps/linux/common/bits/dlfcn.h
@@ -1,5 +1,5 @@
/* System dependent definitions for run-time dynamic loading.
- Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
+ Copyright (C) 1996-2001, 2004 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
@@ -24,8 +24,11 @@
/* The MODE argument to `dlopen' contains one of the following: */
#define RTLD_LAZY 0x00001 /* Lazy function call binding. */
#define RTLD_NOW 0x00002 /* Immediate function call binding. */
+#if 0 /* uClibc doesnt support these */
#define RTLD_BINDING_MASK 0x3 /* Mask of binding time value. */
#define RTLD_NOLOAD 0x00004 /* Do not load the object. */
+#define RTLD_DEEPBIND 0x00008 /* Use deep binding. */
+#endif
/* If the following bit is set in the MODE argument to `dlopen',
the symbols of the loaded object and its dependencies are made
@@ -40,3 +43,25 @@
/* Do not delete object when closed. */
#define RTLD_NODELETE 0x01000
+#if 0 /*def __USE_GNU*/
+/* To support profiling of shared objects it is a good idea to call
+ the function found using `dlsym' using the following macro since
+ these calls do not use the PLT. But this would mean the dynamic
+ loader has no chance to find out when the function is called. The
+ macro applies the necessary magic so that profiling is possible.
+ Rewrite
+ foo = (*fctp) (arg1, arg2);
+ into
+ foo = DL_CALL_FCT (fctp, (arg1, arg2));
+*/
+# define DL_CALL_FCT(fctp, args) \
+ (_dl_mcount_wrapper_check ((void *) (fctp)), (*(fctp)) args)
+
+__BEGIN_DECLS
+
+/* This function calls the profiling functions. */
+extern void _dl_mcount_wrapper_check (void *__selfpc) __THROW;
+
+__END_DECLS
+
+#endif
diff --git a/libc/sysdeps/linux/common/bits/errno.h b/libc/sysdeps/linux/common/bits/errno.h
index f5831ef4d..a5ac1a47f 100644
--- a/libc/sysdeps/linux/common/bits/errno.h
+++ b/libc/sysdeps/linux/common/bits/errno.h
@@ -1,5 +1,5 @@
/* Error constants. Linux specific version.
- Copyright (C) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999, 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
@@ -19,26 +19,41 @@
#ifdef _ERRNO_H
-#include <bits/errno_values.h>
+# undef EDOM
+# undef EILSEQ
+# undef ERANGE
+# include <linux/errno.h>
-#ifndef ENOTSUP
+/* Linux has no ENOTSUP error code. */
# define ENOTSUP EOPNOTSUPP
-#endif
-#ifndef ECANCELED
-# define ECANCELED 125
-#endif
+/* Older Linux versions also had no ECANCELED error code. */
+# ifndef ECANCELED
+# define ECANCELED 125
+# endif
-# ifndef __ASSEMBLER__
+/* Support for error codes to support robust mutexes was added later, too. */
+# ifndef EOWNERDEAD
+# define EOWNERDEAD 130
+# define ENOTRECOVERABLE 131
+# endif
+# ifndef __ASSEMBLER__
/* Function to get address of global `errno' variable. */
extern int *__errno_location (void) __THROW __attribute__ ((__const__));
-# if !defined _LIBC || defined __UCLIBC_HAS_THREADS__
+# ifdef __UCLIBC_HAS_THREADS__
/* When using threads, errno is a per-thread value. */
# define errno (*__errno_location ())
# endif
-
# endif /* !__ASSEMBLER__ */
#endif /* _ERRNO_H */
+#if !defined _ERRNO_H && defined __need_Emath
+/* This is ugly but the kernel header is not clean enough. We must
+ define only the values EDOM, EILSEQ and ERANGE in case __need_Emath is
+ defined. */
+# define EDOM 33 /* Math argument out of domain of function. */
+# define EILSEQ 84 /* Illegal byte sequence. */
+# define ERANGE 34 /* Math result not representable. */
+#endif /* !_ERRNO_H && __need_Emath */
diff --git a/libc/sysdeps/linux/common/bits/huge_val.h b/libc/sysdeps/linux/common/bits/huge_val.h
index b33974364..11ca11f18 100644
--- a/libc/sysdeps/linux/common/bits/huge_val.h
+++ b/libc/sysdeps/linux/common/bits/huge_val.h
@@ -1,6 +1,7 @@
-/* `HUGE_VAL' constants for IEEE 754 machines (where it is infinity).
+/* `HUGE_VAL' constant for IEEE 754 machines (where it is infinity).
Used by <stdlib.h> and <math.h> functions for overflow.
- Copyright (C) 1992, 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1992, 1995, 1996, 1997, 1999, 2000, 2004
+ 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
@@ -22,25 +23,19 @@
# error "Never use <bits/huge_val.h> directly; include <math.h> instead."
#endif
-#include <features.h>
-
/* IEEE positive infinity (-HUGE_VAL is negative infinity). */
-#ifdef __GNUC__
-
-# if __GNUC_PREREQ(2,96)
-
-# define HUGE_VAL (__extension__ 0x1.0p2047)
+#if __GNUC_PREREQ(3,3)
+# define HUGE_VAL (__builtin_huge_val())
+#elif __GNUC_PREREQ(2,96)
+# define HUGE_VAL (__extension__ 0x1.0p2047)
+#elif defined __GNUC__
-# else
-
-# define HUGE_VAL \
+# define HUGE_VAL \
(__extension__ \
((union { unsigned __l __attribute__((__mode__(__DI__))); double __d; }) \
{ __l: 0x7ff0000000000000ULL }).__d)
-# endif
-
#else /* not GCC */
# include <endian.h>
@@ -58,46 +53,3 @@ static __huge_val_t __huge_val = { __HUGE_VAL_bytes };
# define HUGE_VAL (__huge_val.__d)
#endif /* GCC. */
-
-
-/* ISO C99 extensions: (float) HUGE_VALF and (long double) HUGE_VALL. */
-
-#ifdef __USE_ISOC99
-
-# ifdef __GNUC__
-
-# if __GNUC_PREREQ(2,96)
-
-# define HUGE_VALF (__extension__ 0x1.0p255f)
-
-# else
-
-# define HUGE_VALF \
- (__extension__ \
- ((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; }) \
- { __l: 0x7f800000UL }).__d)
-
-# endif
-
-# else /* not GCC */
-
-typedef union { unsigned char __c[4]; float __f; } __huge_valf_t;
-
-# if __BYTE_ORDER == __BIG_ENDIAN
-# define __HUGE_VALF_bytes { 0x7f, 0x80, 0, 0 }
-# endif
-# if __BYTE_ORDER == __LITTLE_ENDIAN
-# define __HUGE_VALF_bytes { 0, 0, 0x80, 0x7f }
-# endif
-
-static __huge_valf_t __huge_valf = { __HUGE_VALF_bytes };
-# define HUGE_VALF (__huge_valf.__f)
-
-# endif /* GCC. */
-
-
-/* Generally there is no separate `long double' format and it is the
- same as `double'. */
-# define HUGE_VALL HUGE_VAL
-
-#endif /* __USE_ISOC99. */
diff --git a/libc/sysdeps/linux/common/bits/local_lim.h b/libc/sysdeps/linux/common/bits/local_lim.h
index d4671e4a8..023ebf3d0 100644
--- a/libc/sysdeps/linux/common/bits/local_lim.h
+++ b/libc/sysdeps/linux/common/bits/local_lim.h
@@ -1,11 +1,11 @@
/* Minimum guaranteed maximum values for system limits. Linux version.
- Copyright (C) 1993-1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1993-1998,2000,2002,2003,2004 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.
+ 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
@@ -13,9 +13,9 @@
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. */
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
/* The kernel header pollutes the namespace with the NR_OPEN symbol
and defines LINK_MAX although filesystems have different maxima. A
@@ -63,16 +63,17 @@
/* The number of threads per process. */
#define _POSIX_THREAD_THREADS_MAX 64
-/* This is the value this implementation supports. */
-#define PTHREAD_THREADS_MAX 1024
-
-/* Minimum size for a thread. We are free to choose a reasonable value. */
-#define PTHREAD_STACK_MIN 16384
/* Maximum amount by which a process can descrease its asynchronous I/O
priority level. */
#define AIO_PRIO_DELTA_MAX 20
+/* Minimum size for a thread. We are free to choose a reasonable value. */
+#define PTHREAD_STACK_MIN 16384
+
+/* Maximum number of timer expiration overruns. */
+#define DELAYTIMER_MAX 2147483647
+
/* Maximum tty name length. */
#define TTY_NAME_MAX 32
@@ -84,6 +85,3 @@
/* Maximum message queue priority level. */
#define MQ_PRIO_MAX 32768
-
-/* Maximum number of POSIX timers available. */
-#define TIMER_MAX 256
diff --git a/libc/sysdeps/linux/common/bits/mathcalls.h b/libc/sysdeps/linux/common/bits/mathcalls.h
index c1181f737..c02007284 100644
--- a/libc/sysdeps/linux/common/bits/mathcalls.h
+++ b/libc/sysdeps/linux/common/bits/mathcalls.h
@@ -1,5 +1,5 @@
/* Prototype declarations for math functions; helper file for <math.h>.
- Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
+ Copyright (C) 1996-2002, 2003, 2006 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
@@ -44,12 +44,13 @@
NAME, to make token pasting work with -traditional. */
#ifndef _MATH_H
- #error "Never include <bits/mathcalls.h> directly; include <math.h> instead."
+# error "Never include <bits/mathcalls.h> directly; include <math.h> instead."
#endif
/* Trigonometric functions. */
+_Mdouble_BEGIN_NAMESPACE
/* Arc cosine of X. */
__MATHCALL (acos,, (_Mdouble_ __x));
/* Arc sine of X. */
@@ -66,12 +67,6 @@ __MATHCALL (sin,, (_Mdouble_ __x));
/* Tangent of X. */
__MATHCALL (tan,, (_Mdouble_ __x));
-#ifdef __USE_GNU
-/* Cosine and sine of X. */
-__MATHDECL (void,sincos,,
- (_Mdouble_ __x, _Mdouble_ *__sinx, _Mdouble_ *__cosx));
-#endif
-
/* Hyperbolic functions. */
/* Hyperbolic cosine of X. */
@@ -80,28 +75,31 @@ __MATHCALL (cosh,, (_Mdouble_ __x));
__MATHCALL (sinh,, (_Mdouble_ __x));
/* Hyperbolic tangent of X. */
__MATHCALL (tanh,, (_Mdouble_ __x));
+_Mdouble_END_NAMESPACE
+
+#if 0 /*def __USE_GNU*/
+/* Cosine and sine of X. */
+__MATHDECL (void,sincos,,
+ (_Mdouble_ __x, _Mdouble_ *__sinx, _Mdouble_ *__cosx));
+#endif
#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
+__BEGIN_NAMESPACE_C99
/* Hyperbolic arc cosine of X. */
__MATHCALL (acosh,, (_Mdouble_ __x));
/* Hyperbolic arc sine of X. */
__MATHCALL (asinh,, (_Mdouble_ __x));
/* Hyperbolic arc tangent of X. */
__MATHCALL (atanh,, (_Mdouble_ __x));
+__END_NAMESPACE_C99
#endif
/* Exponential and logarithmic functions. */
+_Mdouble_BEGIN_NAMESPACE
/* Exponential function of X. */
__MATHCALL (exp,, (_Mdouble_ __x));
-#ifdef __USE_GNU
-/* A function missing in all standards: compute exponent to base ten. */
-__MATHCALL (exp10,, (_Mdouble_ __x));
-/* Another name occasionally used. */
-__MATHCALL (pow10,, (_Mdouble_ __x));
-#endif
-
/* Break VALUE into a normalized fraction and an integral power of 2. */
__MATHCALL (frexp,, (_Mdouble_ __x, int *__exponent));
@@ -116,8 +114,17 @@ __MATHCALL (log10,, (_Mdouble_ __x));
/* Break VALUE into integral and fractional parts. */
__MATHCALL (modf,, (_Mdouble_ __x, _Mdouble_ *__iptr));
+_Mdouble_END_NAMESPACE
+
+#if 0 /*def __USE_GNU*/
+/* A function missing in all standards: compute exponent to base ten. */
+__MATHCALL (exp10,, (_Mdouble_ __x));
+/* Another name occasionally used. */
+__MATHCALL (pow10,, (_Mdouble_ __x));
+#endif
#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
+__BEGIN_NAMESPACE_C99
/* Return exp(X) - 1. */
__MATHCALL (expm1,, (_Mdouble_ __x));
@@ -126,46 +133,56 @@ __MATHCALL (log1p,, (_Mdouble_ __x));
/* Return the base 2 signed integral exponent of X. */
__MATHCALL (logb,, (_Mdouble_ __x));
+__END_NAMESPACE_C99
#endif
#ifdef __USE_ISOC99
+__BEGIN_NAMESPACE_C99
/* Compute base-2 exponential of X. */
__MATHCALL (exp2,, (_Mdouble_ __x));
/* Compute base-2 logarithm of X. */
__MATHCALL (log2,, (_Mdouble_ __x));
+__END_NAMESPACE_C99
#endif
/* Power functions. */
+_Mdouble_BEGIN_NAMESPACE
/* Return X to the Y power. */
__MATHCALL (pow,, (_Mdouble_ __x, _Mdouble_ __y));
/* Return the square root of X. */
__MATHCALL (sqrt,, (_Mdouble_ __x));
+_Mdouble_END_NAMESPACE
#if defined __USE_MISC || defined __USE_XOPEN || defined __USE_ISOC99
+__BEGIN_NAMESPACE_C99
/* Return `sqrt(X*X + Y*Y)'. */
__MATHCALL (hypot,, (_Mdouble_ __x, _Mdouble_ __y));
+__END_NAMESPACE_C99
#endif
#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
+__BEGIN_NAMESPACE_C99
/* Return the cube root of X. */
__MATHCALL (cbrt,, (_Mdouble_ __x));
+__END_NAMESPACE_C99
#endif
/* Nearest integer, absolute value, and remainder functions. */
+_Mdouble_BEGIN_NAMESPACE
/* Smallest integral value not less than X. */
-__MATHCALL (ceil,, (_Mdouble_ __x));
+__MATHCALLX (ceil,, (_Mdouble_ __x), (__const__));
/* Absolute value of X. */
__MATHCALLX (fabs,, (_Mdouble_ __x), (__const__));
/* Largest integer not greater than X. */
-__MATHCALL (floor,, (_Mdouble_ __x));
+__MATHCALLX (floor,, (_Mdouble_ __x), (__const__));
/* Floating-point modulo remainder of X/Y. */
__MATHCALL (fmod,, (_Mdouble_ __x, _Mdouble_ __y));
@@ -177,6 +194,7 @@ __MATHDECL_1 (int,__isinf,, (_Mdouble_ __value)) __attribute__ ((__const__));
/* Return nonzero if VALUE is finite and not NaN. */
__MATHDECL_1 (int,__finite,, (_Mdouble_ __value)) __attribute__ ((__const__));
+_Mdouble_END_NAMESPACE
#ifdef __USE_MISC
/* Return 0 if VALUE is finite or NaN, +1 if it
@@ -195,13 +213,17 @@ __MATHCALL (significand,, (_Mdouble_ __x));
#endif /* Use misc. */
#if defined __USE_MISC || defined __USE_ISOC99
+__BEGIN_NAMESPACE_C99
/* Return X with its signed changed to Y's. */
__MATHCALLX (copysign,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
+__END_NAMESPACE_C99
#endif
#ifdef __USE_ISOC99
+__BEGIN_NAMESPACE_C99
/* Return representation of NaN for double type. */
__MATHCALLX (nan,, (__const char *__tagb), (__const__));
+__END_NAMESPACE_C99
#endif
@@ -223,14 +245,19 @@ __MATHCALL (yn,, (int, _Mdouble_));
#if defined __USE_MISC || defined __USE_XOPEN || defined __USE_ISOC99
+__BEGIN_NAMESPACE_C99
/* Error and gamma functions. */
__MATHCALL (erf,, (_Mdouble_));
__MATHCALL (erfc,, (_Mdouble_));
__MATHCALL (lgamma,, (_Mdouble_));
+__END_NAMESPACE_C99
#endif
#ifdef __USE_ISOC99
+__BEGIN_NAMESPACE_C99
+/* True gamma function. */
__MATHCALL (tgamma,, (_Mdouble_));
+__END_NAMESPACE_C99
#endif
#if defined __USE_MISC || defined __USE_XOPEN
@@ -247,24 +274,20 @@ __MATHCALL (lgamma,_r, (_Mdouble_, int *__signgamp));
#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
+__BEGIN_NAMESPACE_C99
/* Return the integer nearest X in the direction of the
prevailing rounding mode. */
__MATHCALL (rint,, (_Mdouble_ __x));
/* Return X + epsilon if X < Y, X - epsilon if X > Y. */
__MATHCALLX (nextafter,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
-# ifdef __USE_ISOC99
+# if defined __USE_ISOC99 && !defined __LDBL_COMPAT
__MATHCALLX (nexttoward,, (_Mdouble_ __x, long double __y), (__const__));
# endif
/* Return the remainder of integer divison X / Y with infinite precision. */
__MATHCALL (remainder,, (_Mdouble_ __x, _Mdouble_ __y));
-# if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
-/* Return X times (2 to the Nth power). */
-__MATHCALL (scalb,, (_Mdouble_ __x, _Mdouble_ __n));
-# endif
-
# if defined __USE_MISC || defined __USE_ISOC99
/* Return X times (2 to the Nth power). */
__MATHCALL (scalbn,, (_Mdouble_ __x, int __n));
@@ -284,7 +307,7 @@ __MATHCALL (nearbyint,, (_Mdouble_ __x));
/* Round X to nearest integral value, rounding halfway cases away from
zero. */
-__MATHCALL (round,, (_Mdouble_ __x));
+__MATHCALLX (round,, (_Mdouble_ __x), (__const__));
/* Round X to the integral value in floating-point format nearest but
not larger in magnitude. */
@@ -331,3 +354,12 @@ __MATHDECL_1 (int, __signbit,, (_Mdouble_ __value))
/* Multiply-add function computed as a ternary operation. */
__MATHCALL (fma,, (_Mdouble_ __x, _Mdouble_ __y, _Mdouble_ __z));
#endif /* Use ISO C99. */
+
+#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
+__END_NAMESPACE_C99
+#endif
+
+#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
+/* Return X times (2 to the Nth power). */
+__MATHCALL (scalb,, (_Mdouble_ __x, _Mdouble_ __n));
+#endif
diff --git a/libc/sysdeps/linux/common/bits/mathdef.h b/libc/sysdeps/linux/common/bits/mathdef.h
index d08dc3820..00c67241a 100644
--- a/libc/sysdeps/linux/common/bits/mathdef.h
+++ b/libc/sysdeps/linux/common/bits/mathdef.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999, 2000, 2004 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
@@ -30,10 +30,6 @@ typedef double float_t; /* `float' expressions are evaluated as
typedef double double_t; /* `double' expressions are evaluated as
`double'. */
-/* Define `INFINITY' as value of type `float'. */
-# define INFINITY HUGE_VALF
-
-
/* The values returned by `ilogb' for 0 and NaN respectively. */
# define FP_ILOGB0 (-2147483647)
# define FP_ILOGBNAN 2147483647
diff --git a/libc/sysdeps/linux/common/bits/posix1_lim.h b/libc/sysdeps/linux/common/bits/posix1_lim.h
index 71c58f760..3c86dcec1 100644
--- a/libc/sysdeps/linux/common/bits/posix1_lim.h
+++ b/libc/sysdeps/linux/common/bits/posix1_lim.h
@@ -151,6 +151,7 @@
/* Get the implementation-specific values for the above. */
#include <bits/local_lim.h>
+#include <bits/uClibc_local_lim.h>
#ifndef SSIZE_MAX
diff --git a/libc/sysdeps/linux/common/bits/posix_opt.h b/libc/sysdeps/linux/common/bits/posix_opt.h
index ce416c9dd..dfe259b7c 100644
--- a/libc/sysdeps/linux/common/bits/posix_opt.h
+++ b/libc/sysdeps/linux/common/bits/posix_opt.h
@@ -1,11 +1,11 @@
/* Define POSIX options for Linux.
- Copyright (C) 1996,1997,1999,2000,2002,2003 Free Software Foundation, Inc.
+ Copyright (C) 1996-2001, 2002, 2003, 2004 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.
+ 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
@@ -13,16 +13,12 @@
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. */
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
-/*
- * Never include this file directly; use <unistd.h> instead.
- */
-
-#ifndef _BITS_POSIX_OPT_H
-#define _BITS_POSIX_OPT_H 1
+#ifndef _POSIX_OPT_H
+#define _POSIX_OPT_H 1
/* Job control is supported. */
#define _POSIX_JOB_CONTROL 1
@@ -43,31 +39,13 @@
#define _POSIX_MAPPED_FILES 200112L
/* Locking of all memory is supported. */
-#ifdef __ARCH_USE_MMU__
-# define _POSIX_MEMLOCK 200112L
-#else
-# undef _POSIX_MEMLOCK
-#endif
+#define _POSIX_MEMLOCK 200112L
/* Locking of ranges of memory is supported. */
-#ifdef __ARCH_USE_MMU__
-# define _POSIX_MEMLOCK_RANGE 200112L
-#else
-# define _POSIX_MEMLOCK_RANGE
-#endif
+#define _POSIX_MEMLOCK_RANGE 200112L
/* Setting of memory protections is supported. */
-#ifdef __ARCH_USE_MMU__
-# define _POSIX_MEMORY_PROTECTION 200112L
-#else
-# undef _POSIX_MEMORY_PROTECTION
-#endif
-
-/* Implementation supports `poll' function. */
-#define _POSIX_POLL 1
-
-/* Implementation supports `select' and `pselect' functions. */
-#define _POSIX_SELECT 1
+#define _POSIX_MEMORY_PROTECTION 200112L
/* Only root can change owner of file. */
#define _POSIX_CHOWN_RESTRICTED 1
@@ -82,139 +60,121 @@
/* X/Open realtime support is available. */
#define _XOPEN_REALTIME 1
-/* X/Open realtime thread support is available. */
-#ifdef __UCLIBC_HAS_THREADS__
-# define _XOPEN_REALTIME_THREADS 1
-#else
-# undef _XOPEN_REALTIME_THREADS
-#endif
-
/* XPG4.2 shared memory is supported. */
#define _XOPEN_SHM 1
/* Tell we have POSIX threads. */
-#ifdef __UCLIBC_HAS_THREADS__
-# define _POSIX_THREADS 1
-#else
-# undef _POSIX_THREADS
-#endif
+#define _POSIX_THREADS 200112L
/* We have the reentrant functions described in POSIX. */
-#ifdef __UCLIBC_HAS_THREADS__
-# define _POSIX_REENTRANT_FUNCTIONS 1
-# define _POSIX_THREAD_SAFE_FUNCTIONS 1
-#else
-# undef _POSIX_REENTRANT_FUNCTIONS
-# undef _POSIX_THREAD_SAFE_FUNCTIONS
-#endif
+#define _POSIX_REENTRANT_FUNCTIONS 1
+#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
/* We provide priority scheduling for threads. */
-#define _POSIX_THREAD_PRIORITY_SCHEDULING 1
+#define _POSIX_THREAD_PRIORITY_SCHEDULING 200112L
/* We support user-defined stack sizes. */
-#define _POSIX_THREAD_ATTR_STACKSIZE 1
+#define _POSIX_THREAD_ATTR_STACKSIZE 200112L
/* We support user-defined stacks. */
-#define _POSIX_THREAD_ATTR_STACKADDR 1
+#define _POSIX_THREAD_ATTR_STACKADDR 200112L
-/* We support POSIX.1b semaphores, but only the non-shared form for now. */
-#ifdef __UCLIBC_HAS_THREADS__
-# define _POSIX_SEMAPHORES 1
-#else
-# undef _POSIX_SEMAPHORES
-#endif
+/* We support POSIX.1b semaphores. */
+#define _POSIX_SEMAPHORES 200112L
/* Real-time signals are supported. */
#define _POSIX_REALTIME_SIGNALS 200112L
/* We support asynchronous I/O. */
-#define _POSIX_ASYNCHRONOUS_IO 1
+#define _POSIX_ASYNCHRONOUS_IO 200112L
#define _POSIX_ASYNC_IO 1
/* Alternative name for Unix98. */
#define _LFS_ASYNCHRONOUS_IO 1
+/* Support for prioritization is also available. */
+#define _POSIX_PRIORITIZED_IO 200112L
/* The LFS support in asynchronous I/O is also available. */
-#ifdef __UCLIBC_HAS_LFS__
-# define _LFS64_ASYNCHRONOUS_IO 1
-#else
-# undef _LFS64_ASYNCHRONOUS_IO
-#endif
+#define _LFS64_ASYNCHRONOUS_IO 1
-/* The rest of the LFS is also available. */
#ifdef __UCLIBC_HAS_LFS__
-# define _LFS_LARGEFILE 1
-# define _LFS64_LARGEFILE 1
-# define _LFS64_STDIO 1
-#else
-# undef _LFS_LARGEFILE
-# undef _LFS64_LARGEFILE
-# undef _LFS64_STDIO
+/* The rest of the LFS is also available. */
+#define _LFS_LARGEFILE 1
+#define _LFS64_LARGEFILE 1
+#define _LFS64_STDIO 1
#endif
-/* POSIX timers are available. */
-#define _POSIX_TIMERS 200112L
-
/* POSIX shared memory objects are implemented. */
#define _POSIX_SHARED_MEMORY_OBJECTS 200112L
-#if defined(__i386__)
-/* CPU-time clocks supported. */
-# define _POSIX_CPUTIME 200912L
-
-/* We support the clock also in threads. */
-# define _POSIX_THREAD_CPUTIME 200912L
-#endif
-
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
/* CPU-time clocks support needs to be checked at runtime. */
-#define _POSIX_CPUTIME 0
+#define _POSIX_CPUTIME 0
/* Clock support in threads must be also checked at runtime. */
-#define _POSIX_THREAD_CPUTIME 0
-#endif
-
-/* Reader/Writer locks are available. */
-#define _POSIX_READER_WRITER_LOCKS 200912L
+#define _POSIX_THREAD_CPUTIME 0
/* GNU libc provides regular expression handling. */
-#ifdef __UCLIBC_HAS_REGEX__
-# define _POSIX_REGEXP 1
-#else
-# undef _POSIX_REGEXP
-#endif
+#define _POSIX_REGEXP 1
+
+/* Reader/Writer locks are available. */
+#define _POSIX_READER_WRITER_LOCKS 200112L
/* We have a POSIX shell. */
#define _POSIX_SHELL 1
-/* The `spawn' function family is supported. */
-#define _POSIX_SPAWN 200912L
-
/* We support the Timeouts option. */
-#define _POSIX_TIMEOUTS 200912L
+#define _POSIX_TIMEOUTS 200112L
/* We support spinlocks. */
-#define _POSIX_SPIN_LOCKS 200912L
+#define _POSIX_SPIN_LOCKS 200112L
+
+/* The `spawn' function family is supported. */
+#define _POSIX_SPAWN 200112L
+
+/* We have POSIX timers. */
+#define _POSIX_TIMERS 200112L
/* The barrier functions are available. */
-#define _POSIX_BARRIERS 200912L
+#define _POSIX_BARRIERS 200112L
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
/* POSIX message queues are available. */
-# define _POSIX_MESSAGE_PASSING 200112L
-#else
-/* POSIX message queues are not yet supported. */
-# undef _POSIX_MESSAGE_PASSING
-#endif
+#define _POSIX_MESSAGE_PASSING 200112L
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
/* Thread process-shared synchronization is supported. */
-#define _POSIX_THREAD_PROCESS_SHARED 200112L
+#define _POSIX_THREAD_PROCESS_SHARED 200112L
/* The monotonic clock might be available. */
-#define _POSIX_MONOTONIC_CLOCK 0
+#define _POSIX_MONOTONIC_CLOCK 0
/* The clock selection interfaces are available. */
-#define _POSIX_CLOCK_SELECTION 200112L
-#endif
+#define _POSIX_CLOCK_SELECTION 200112L
+
+/* Advisory information interfaces are available. */
+#define _POSIX_ADVISORY_INFO 200112L
+
+/* IPv6 support is available. */
+#define _POSIX_IPV6 200112L
+
+/* Raw socket support is available. */
+#define _POSIX_RAW_SOCKETS 200112L
+
+/* We have at least one terminal. */
+#define _POSIX2_CHAR_TERM 200112L
+
+/* Neither process nor thread sporadic server interfaces is available. */
+#define _POSIX_SPORADIC_SERVER -1
+#define _POSIX_THREAD_SPORADIC_SERVER -1
+
+/* trace.h is not available. */
+#define _POSIX_TRACE -1
+#define _POSIX_TRACE_EVENT_FILTER -1
+#define _POSIX_TRACE_INHERIT -1
+#define _POSIX_TRACE_LOG -1
+
+/* Typed memory objects are not available. */
+#define _POSIX_TYPED_MEMORY_OBJECTS -1
+
+/* No support for priority inheritance or protection so far. */
+#define _POSIX_THREAD_PRIO_INHERIT -1
+#define _POSIX_THREAD_PRIO_PROTECT -1
-#endif /* bits/posix_opt.h */
+#endif /* posix_opt.h */
diff --git a/libc/sysdeps/linux/common/bits/resource.h b/libc/sysdeps/linux/common/bits/resource.h
index 1d438122e..526cdaf53 100644
--- a/libc/sysdeps/linux/common/bits/resource.h
+++ b/libc/sysdeps/linux/common/bits/resource.h
@@ -81,7 +81,26 @@ enum __rlimit_resource
__RLIMIT_LOCKS = 10,
#define RLIMIT_LOCKS __RLIMIT_LOCKS
- __RLIMIT_NLIMITS = 11,
+ /* Maximum number of pending signals. */
+ __RLIMIT_SIGPENDING = 11,
+#define RLIMIT_SIGPENDING __RLIMIT_SIGPENDING
+
+ /* Maximum bytes in POSIX message queues. */
+ __RLIMIT_MSGQUEUE = 12,
+#define RLIMIT_MSGQUEUE __RLIMIT_MSGQUEUE
+
+ /* Maximum nice priority allowed to raise to.
+ Nice levels 19 .. -20 correspond to 0 .. 39
+ values of this resource limit. */
+ __RLIMIT_NICE = 13,
+#define RLIMIT_NICE __RLIMIT_NICE
+
+ /* Maximum realtime priority allowed for non-priviledged
+ processes. */
+ __RLIMIT_RTPRIO = 14,
+#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
+
+ __RLIMIT_NLIMITS = 15,
__RLIM_NLIMITS = __RLIMIT_NLIMITS
#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
#define RLIM_NLIMITS __RLIM_NLIMITS
@@ -89,13 +108,13 @@ enum __rlimit_resource
/* Value to indicate that there is no limit. */
#ifndef __USE_FILE_OFFSET64
-# define RLIM_INFINITY ((long int)(~0UL >> 1))
+# define RLIM_INFINITY ((unsigned long int)(~0UL))
#else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffuLL
#endif
#ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffuLL
#endif
/* We can represent all limits. */
@@ -139,12 +158,8 @@ enum __rusage_who
#define RUSAGE_SELF RUSAGE_SELF
/* All of its terminated child processes. */
- RUSAGE_CHILDREN = -1,
+ RUSAGE_CHILDREN = -1
#define RUSAGE_CHILDREN RUSAGE_CHILDREN
-
- /* Both. */
- RUSAGE_BOTH = -2
-#define RUSAGE_BOTH RUSAGE_BOTH
};
#define __need_timeval
diff --git a/libc/sysdeps/linux/common/bits/shm.h b/libc/sysdeps/linux/common/bits/shm.h
index 225b89db2..318d601ae 100644
--- a/libc/sysdeps/linux/common/bits/shm.h
+++ b/libc/sysdeps/linux/common/bits/shm.h
@@ -73,6 +73,7 @@ struct shmid_ds
# define SHM_DEST 01000 /* segment will be destroyed on last detach */
# define SHM_LOCKED 02000 /* segment will not be swapped */
# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */
+# define SHM_NORESERVE 010000 /* don't check for reservations */
struct shminfo
{
diff --git a/libc/sysdeps/linux/common/bits/siginfo.h b/libc/sysdeps/linux/common/bits/siginfo.h
index 4e9fd6ab4..4ce319dc9 100644
--- a/libc/sysdeps/linux/common/bits/siginfo.h
+++ b/libc/sysdeps/linux/common/bits/siginfo.h
@@ -1,5 +1,5 @@
-/* siginfo_t, sigevent and constants. Linux/SPARC version.
- Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+/* siginfo_t, sigevent and constants. Linux version.
+ Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -69,8 +69,9 @@ typedef struct siginfo
/* POSIX.1b timers. */
struct
{
- unsigned int _timer1;
- unsigned int _timer2;
+ int si_tid; /* Timer ID. */
+ int si_overrun; /* Overrun count. */
+ sigval_t si_sigval; /* Signal value. */
} _timer;
/* POSIX.1b signals. */
@@ -110,8 +111,8 @@ typedef struct siginfo
/* X/Open requires some more fields with fixed names. */
# define si_pid _sifields._kill.si_pid
# define si_uid _sifields._kill.si_uid
-# define si_timer1 _sifields._timer._timer1
-# define si_timer2 _sifields._timer._timer2
+# define si_timerid _sifields._timer.si_tid
+# define si_overrun _sifields._timer.si_overrun
# define si_status _sifields._sigchld.si_status
# define si_utime _sifields._sigchld.si_utime
# define si_stime _sifields._sigchld.si_stime
@@ -269,9 +270,6 @@ enum
# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 3)
# endif
-/* Forward declaration of the `pthread_attr_t' type. */
-struct __pthread_attr_s;
-
typedef struct sigevent
{
sigval_t sigev_value;
@@ -282,10 +280,14 @@ typedef struct sigevent
{
int _pad[__SIGEV_PAD_SIZE];
+ /* When SIGEV_SIGNAL and SIGEV_THREAD_ID set, LWP ID of the
+ thread to receive the signal. */
+ __pid_t _tid;
+
struct
{
- void (*_function) (sigval_t); /* Function to start. */
- struct __pthread_attr_s *_attribute; /* Really pthread_attr_t. */
+ void (*_function) (sigval_t); /* Function to start. */
+ void *_attribute; /* Really pthread_attr_t. */
} _sigev_thread;
} _sigev_un;
} sigevent_t;
@@ -305,7 +307,7 @@ enum
# define SIGEV_THREAD SIGEV_THREAD
SIGEV_THREAD_ID = 4 /* Send signal to specific thread. */
-#define SIGEV_THREAD_ID SIGEV_THREAD_ID
+#define SIGEV_THREAD_ID SIGEV_THREAD_ID
};
#endif /* have _SIGNAL_H. */
diff --git a/libc/sysdeps/linux/common/bits/signum.h b/libc/sysdeps/linux/common/bits/signum.h
index 74259b492..a18ac113a 100644
--- a/libc/sysdeps/linux/common/bits/signum.h
+++ b/libc/sysdeps/linux/common/bits/signum.h
@@ -1,5 +1,5 @@
/* Signal number definitions. Linux version.
- Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1995,1996,1997,1998,1999,2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -66,7 +66,7 @@
#define SIGSYS 31 /* Bad system call. */
#define SIGUNUSED 31
-#define _NSIG 64 /* Biggest signal number + 1
+#define _NSIG 65 /* Biggest signal number + 1
(including real-time signals). */
#define SIGRTMIN (__libc_current_sigrtmin ())
diff --git a/libc/sysdeps/linux/common/bits/sigthread.h b/libc/sysdeps/linux/common/bits/sigthread.h
index 9e6b62e4b..960bde18a 100644
--- a/libc/sysdeps/linux/common/bits/sigthread.h
+++ b/libc/sysdeps/linux/common/bits/sigthread.h
@@ -1,11 +1,11 @@
-/* Signal handling function for threaded programs. Generic version.
- Copyright (C) 2000 Free Software Foundation, Inc.
+/* Signal handling function for threaded programs.
+ Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
+ 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
@@ -13,9 +13,9 @@
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. */
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#ifndef _BITS_SIGTHREAD_H
#define _BITS_SIGTHREAD_H 1
@@ -24,15 +24,15 @@
# error "Never include this file directly. Use <pthread.h> instead"
#endif
-/* Modify the signal mask for the calling thread. The arguments have the
- same meaning as for sigprocmask; in fact, this and sigprocmask might be
- the same function. We declare this the same on all platforms, since it
- doesn't use any thread-related types. */
+/* Functions for handling signals. */
+
+/* Modify the signal mask for the calling thread. The arguments have
+ the same meaning as for sigprocmask(2). */
extern int pthread_sigmask (int __how,
__const __sigset_t *__restrict __newmask,
__sigset_t *__restrict __oldmask)__THROW;
/* Send signal SIGNO to the given thread. */
-extern int pthread_kill (pthread_t __thread_id, int __signo) __THROW;
+extern int pthread_kill (pthread_t __threadid, int __signo) __THROW;
#endif /* bits/sigthread.h */
diff --git a/libc/sysdeps/linux/common/bits/socket.h b/libc/sysdeps/linux/common/bits/socket.h
index 2466c0cd1..2f3dc797b 100644
--- a/libc/sysdeps/linux/common/bits/socket.h
+++ b/libc/sysdeps/linux/common/bits/socket.h
@@ -1,5 +1,5 @@
/* System-specific socket constants and types. Linux version.
- Copyright (C) 1991,1992,1994-2001, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1991,1992,1994-2001,2004,2006 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
@@ -215,16 +215,26 @@ enum
/* Note: do not change these members to match glibc; these match the
SuSv3 spec already (e.g. msg_iovlen/msg_controllen).
http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html */
+/* Note: linux kernel uses __kernel_size_t (which is 8bytes on 64bit
+ platforms, and 4bytes on 32bit platforms) for msg_iovlen/msg_controllen */
struct msghdr
{
void *msg_name; /* Address to send to/receive from. */
socklen_t msg_namelen; /* Length of address data. */
struct iovec *msg_iov; /* Vector of data to send/receive into. */
+#if __WORDSIZE == 32
int msg_iovlen; /* Number of elements in the vector. */
+#else
+ size_t msg_iovlen; /* Number of elements in the vector. */
+#endif
void *msg_control; /* Ancillary data (eg BSD filedesc passing). */
+#if __WORDSIZE == 32
socklen_t msg_controllen; /* Ancillary data buffer length. */
+#else
+ size_t msg_controllen; /* Ancillary data buffer length. */
+#endif
int msg_flags; /* Flags on received message. */
};
@@ -286,13 +296,12 @@ __NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg))
<linux/socket.h>. */
enum
{
- SCM_RIGHTS = 0x01, /* Transfer file descriptors. */
+ SCM_RIGHTS = 0x01 /* Transfer file descriptors. */
#define SCM_RIGHTS SCM_RIGHTS
#ifdef __USE_BSD
- SCM_CREDENTIALS = 0x02, /* Credentials passing. */
+ , SCM_CREDENTIALS = 0x02 /* Credentials passing. */
# define SCM_CREDENTIALS SCM_CREDENTIALS
#endif
- __SCM_CONNECT = 0x03 /* Data array is `struct scm_connect'. */
};
/* User visible structure for SCM_CREDENTIALS message */
diff --git a/libc/sysdeps/linux/common/bits/stat.h b/libc/sysdeps/linux/common/bits/stat.h
index 3e8e77f65..bd5aae267 100644
--- a/libc/sysdeps/linux/common/bits/stat.h
+++ b/libc/sysdeps/linux/common/bits/stat.h
@@ -20,9 +20,6 @@
# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
#endif
-#ifndef _BITS_STAT_H
-#define _BITS_STAT_H
-
/* Versions of the `struct stat' data structure. */
#define _STAT_VER_LINUX_OLD 1
#define _STAT_VER_KERNEL 1
@@ -35,13 +32,15 @@
#define _MKNOD_VER_SVR4 2
#define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
+
struct stat
-{
+ {
__dev_t st_dev; /* Device. */
- unsigned short int __pad1;
#ifndef __USE_FILE_OFFSET64
+ unsigned short int __pad1;
__ino_t st_ino; /* File serial number. */
#else
+ unsigned int __pad1;
__ino_t __st_ino; /* 32bit file serial number. */
#endif
__mode_t st_mode; /* File mode. */
@@ -49,10 +48,11 @@ struct stat
__uid_t st_uid; /* User ID of the file's owner. */
__gid_t st_gid; /* Group ID of the file's group.*/
__dev_t st_rdev; /* Device number, if device. */
- unsigned short int __pad2;
#ifndef __USE_FILE_OFFSET64
+ unsigned short int __pad2;
__off_t st_size; /* Size of file, in bytes. */
#else
+ unsigned int __pad2;
__off64_t st_size; /* Size of file, in bytes. */
#endif
__blksize_t st_blksize; /* Optimal block size for I/O. */
@@ -62,23 +62,38 @@ struct stat
#else
__blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
#endif
+#if 0 /*def __USE_MISC*/
+ /* Nanosecond resolution timestamps are stored in a format
+ equivalent to 'struct timespec'. This is the type used
+ whenever possible but the Unix namespace rules do not allow the
+ identifier 'timespec' to appear in the <sys/stat.h> header.
+ Therefore we have to handle the use of this header in strictly
+ standard-compliant sources special. */
+ struct timespec st_atim; /* Time of last access. */
+ struct timespec st_mtim; /* Time of last modification. */
+ struct timespec st_ctim; /* Time of last status change. */
+# define st_atime st_atim.tv_sec /* Backward compatibility. */
+# define st_mtime st_mtim.tv_sec
+# define st_ctime st_ctim.tv_sec
+#else
__time_t st_atime; /* Time of last access. */
unsigned long int st_atimensec; /* Nscecs of last access. */
__time_t st_mtime; /* Time of last modification. */
unsigned long int st_mtimensec; /* Nsecs of last modification. */
__time_t st_ctime; /* Time of last status change. */
unsigned long int st_ctimensec; /* Nsecs of last status change. */
+#endif
#ifndef __USE_FILE_OFFSET64
unsigned long int __unused4;
unsigned long int __unused5;
#else
__ino64_t st_ino; /* File serial number. */
#endif
-};
+ };
#ifdef __USE_LARGEFILE64
struct stat64
-{
+ {
__dev_t st_dev; /* Device. */
unsigned int __pad1;
@@ -93,17 +108,28 @@ struct stat64
__blksize_t st_blksize; /* Optimal block size for I/O. */
__blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
+#if 0 /*def __USE_MISC*/
+ /* Nanosecond resolution timestamps are stored in a format
+ equivalent to 'struct timespec'. This is the type used
+ whenever possible but the Unix namespace rules do not allow the
+ identifier 'timespec' to appear in the <sys/stat.h> header.
+ Therefore we have to handle the use of this header in strictly
+ standard-compliant sources special. */
+ struct timespec st_atim; /* Time of last access. */
+ struct timespec st_mtim; /* Time of last modification. */
+ struct timespec st_ctim; /* Time of last status change. */
+#else
__time_t st_atime; /* Time of last access. */
unsigned long int st_atimensec; /* Nscecs of last access. */
__time_t st_mtime; /* Time of last modification. */
unsigned long int st_mtimensec; /* Nsecs of last modification. */
__time_t st_ctime; /* Time of last status change. */
unsigned long int st_ctimensec; /* Nsecs of last status change. */
+#endif
__ino64_t st_ino; /* File serial number. */
-};
+ };
#endif
-
/* Tell code we have these members. */
#define _STATBUF_ST_BLKSIZE
#define _STATBUF_ST_RDEV
@@ -137,6 +163,3 @@ struct stat64
#define __S_IREAD 0400 /* Read by owner. */
#define __S_IWRITE 0200 /* Write by owner. */
#define __S_IEXEC 0100 /* Execute by owner. */
-
-#endif /* _BITS_STAT_H */
-
diff --git a/libc/sysdeps/linux/common/bits/syscalls.h b/libc/sysdeps/linux/common/bits/syscalls.h
index e891af8e5..4895c4fa0 100644
--- a/libc/sysdeps/linux/common/bits/syscalls.h
+++ b/libc/sysdeps/linux/common/bits/syscalls.h
@@ -5,6 +5,4 @@
* forbidden. Don't do it. It is bad for you.
*/
-
-#error You have not provided architecture specific _syscall[0-5] macros
-
+#error You have not provided architecture specific _syscall[0-6] macros
diff --git a/libc/sysdeps/linux/common/bits/termios.h b/libc/sysdeps/linux/common/bits/termios.h
index c71e4ad1f..b648d8000 100644
--- a/libc/sysdeps/linux/common/bits/termios.h
+++ b/libc/sysdeps/linux/common/bits/termios.h
@@ -154,6 +154,7 @@ struct termios
#ifdef __USE_MISC
# define CBAUDEX 0010000
#endif
+#define BOTHER 0010000
#define B57600 0010001
#define B115200 0010002
#define B230400 0010003
diff --git a/libc/sysdeps/linux/common/bits/uClibc_arch_features.h b/libc/sysdeps/linux/common/bits/uClibc_arch_features.h
index 7b666e175..66186edbb 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_arch_features.h
@@ -23,9 +23,6 @@
/* does your target have to worry about older [gs]etrlimit() ? */
#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
-/* does your target prefix all symbols with an _ ? */
-#define __UCLIBC_NO_UNDERSCORES__
-
/* does your target have an asm .set ? */
#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
diff --git a/libc/sysdeps/linux/common/bits/uClibc_errno.h b/libc/sysdeps/linux/common/bits/uClibc_errno.h
index 2add9e5c9..631e10c50 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_errno.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_errno.h
@@ -12,7 +12,7 @@
extern int _dl_errno; // attribute_hidden;
#elif defined __UCLIBC_HAS_THREADS__
# include <tls.h>
-# if USE___THREAD
+# if defined USE___THREAD && USE___THREAD
# undef errno
# ifndef NOT_IN_libc
# define errno __libc_errno
@@ -33,16 +33,11 @@ extern int *__errno_location (void) __THROW __attribute__ ((__const__))
;
# if defined __UCLIBC_HAS_THREADS__
# include <tls.h>
-# if USE___THREAD
+# if defined USE___THREAD && USE___THREAD
libc_hidden_proto(__errno_location)
# endif
# endif
-/* We now need a declaration of the `errno' variable. */
-# ifndef __UCLIBC_HAS_THREADS__
-/*extern int errno;*/
-libc_hidden_proto(errno)
-# endif
#endif /* !__ASSEMBLER__ */
#endif
diff --git a/libc/sysdeps/linux/common/bits/uClibc_local_lim.h b/libc/sysdeps/linux/common/bits/uClibc_local_lim.h
index 34575cb50..abfc86de5 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_local_lim.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_local_lim.h
@@ -11,12 +11,13 @@
#define _BITS_UCLIBC_LOCAL_LIM_H 1
/* This file works correctly only if local_lim.h is the NPTL version */
-#if !defined PTHREAD_KEYS_MAX || defined TIMER_MAX
+#if !defined PTHREAD_KEYS_MAX || defined TIMER_MAX
# error local_lim.h was incorrectly updated, use the NPTL version from glibc
#endif
-#if defined __UCLIBC_HAS_THREADS__
-# define PTHREAD_THREADS_MAX 16384
+/* This should really be moved to thread specific directories */
+#if defined __UCLIBC_HAS_THREADS__ && !defined __UCLIBC_HAS_THREADS_NATIVE__
+# define PTHREAD_THREADS_MAX 1024
# define TIMER_MAX 256
#endif
diff --git a/libc/sysdeps/linux/common/bits/uClibc_mutex.h b/libc/sysdeps/linux/common/bits/uClibc_mutex.h
index b202a6bd2..e31767787 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_mutex.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_mutex.h
@@ -12,8 +12,7 @@
#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-#include <bits/uClibc_pthread.h>
+#include <bits/pthreadtypes.h>
#define __UCLIBC_MUTEX_TYPE pthread_mutex_t
@@ -36,7 +35,7 @@
struct _pthread_cleanup_buffer __infunc_pthread_cleanup_buffer; \
if (C) { \
_pthread_cleanup_push_defer(&__infunc_pthread_cleanup_buffer, \
- __uclibc_mutex_unlock, \
+ (void (*) (void *))__pthread_mutex_unlock, \
&(M)); \
__pthread_mutex_lock(&(M)); \
} \
@@ -62,6 +61,53 @@
#define __UCLIBC_MUTEX_UNLOCK(M) \
__UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M, 1)
+#ifdef __USE_STDIO_FUTEXES__
+
+#include <bits/stdio-lock.h>
+
+#define __UCLIBC_IO_MUTEX(M) _IO_lock_t M
+#define __UCLIBC_IO_MUTEX_LOCK(M) _IO_lock_lock(M)
+#define __UCLIBC_IO_MUTEX_UNLOCK(M) _IO_lock_unlock(M)
+#define __UCLIBC_IO_MUTEX_TRYLOCK(M) _IO_lock_trylock(M)
+#define __UCLIBC_IO_MUTEX_INIT(M,I) _IO_lock_t M = I
+#define __UCLIBC_IO_MUTEX_EXTERN(M) extern _IO_lock_t M
+
+#define __UCLIBC_IO_MUTEX_CONDITIONAL_LOCK(M,C) \
+ if (C) { \
+ _IO_lock_lock(M); \
+ }
+
+#define __UCLIBC_IO_MUTEX_CONDITIONAL_UNLOCK(M,C) \
+ if (C) { \
+ _IO_lock_unlock(M); \
+ }
+
+#define __UCLIBC_IO_MUTEX_AUTO_LOCK(M,A,V) \
+ __UCLIBC_IO_MUTEX_CONDITIONAL_LOCK(M,((A=(V))) == 0)
+
+#define __UCLIBC_IO_MUTEX_AUTO_UNLOCK(M,A) \
+ __UCLIBC_IO_MUTEX_CONDITIONAL_UNLOCK(M,((A) ==0))
+
+#define __UCLIBC_IO_MUTEX_LOCK_CANCEL_UNSAFE(M) \
+ __UCLIBC_IO_MUTEX_LOCK(M)
+#define __UCLIBC_IO_MUTEX_UNLOCK_CANCEL_UNSAFE(M) \
+ __UCLIBC_IO_MUTEX_UNLOCK(M)
+#define __UCLIBC_IO_MUTEX_TRYLOCK_CANCEL_UNSAFE(M) \
+ __UCLIBC_IO_MUTEX_TRYLOCK(M)
+
+#else
+#define __UCLIBC_IO_MUTEX(M) __UCLIBC_MUTEX(M)
+#define __UCLIBC_IO_MUTEX_LOCK(M) __UCLIBC_MUTEX_CONDITIONAL_LOCK(M, 1)
+#define __UCLIBC_IO_MUTEX_UNLOCK(M) __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M, 1)
+#define __UCLIBC_IO_MUTEX_TRYLOCK(M) __UCLIBC_MUTEX_TRYLOCK_CANCEL_UNSAFE
+#define __UCLIBC_IO_MUTEX_INIT(M,I) __UCLIBC_MUTEX_INIT(M,I)
+#define __UCLIBC_IO_MUTEX_EXTERN(M) __UCLIBC_MUTEX_EXTERN(M)
+
+#define __UCLIBC_IO_MUTEX_AUTO_LOCK(M,A,V) __UCLIBC_MUTEX_AUTO_LOCK(M,A,V)
+#define __UCLIBC_IO_MUTEX_AUTO_UNLOCK(M,A) __UCLIBC_MUTEX_AUTO_UNLOCK(M,A)
+
+#endif
+
#else
#define __UCLIBC_MUTEX(M) void *__UCLIBC_MUTEX_DUMMY_ ## M
@@ -83,6 +129,12 @@
#define __UCLIBC_MUTEX_LOCK(M) ((void)0)
#define __UCLIBC_MUTEX_UNLOCK(M) ((void)0)
+#define __UCLIBC_IO_MUTEX_LOCK(M) ((void)0)
+#define __UCLIBC_IO_MUTEX_UNLOCK(M) ((void)0)
+#define __UCLIBC_IO_MUTEX_TRYLOCK(M) ((void)0)
+#define __UCLIBC_IO_MUTEX_INIT(M,I) extern void *__UCLIBC_MUTEX_DUMMY_ ## M
+#define __UCLIBC_IO_MUTEX_EXTERN(M) extern void *__UCLIBC_MUTEX_DUMMY_ ## M
#endif
+
#endif /* _UCLIBC_MUTEX_H */
diff --git a/libc/sysdeps/linux/common/bits/uClibc_stdio.h b/libc/sysdeps/linux/common/bits/uClibc_stdio.h
index a75f971eb..0af2d5db5 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_stdio.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_stdio.h
@@ -55,7 +55,7 @@
/**********************************************************************/
/* Make sure defines related to large files are consistent. */
-#if defined _LIBC && (defined IS_IN_libc || defined NOT_IN_libc)
+#ifdef _LIBC
#ifdef __UCLIBC_HAS_LFS__
#undef __USE_LARGEFILE
@@ -116,12 +116,7 @@
#endif
/**********************************************************************/
-#ifdef __UCLIBC_HAS_THREADS__
-/* Need this for pthread_mutex_t. */
-#include <bits/pthreadtypes.h>
-#ifdef __USE_STDIO_FUTEXES__
-#include <bits/stdio-lock.h>
-#endif
+#include <bits/uClibc_mutex.h>
/* user_locking
* 0 : do auto locking/unlocking
@@ -135,70 +130,45 @@
* This way, we avoid calling the weak lock/unlock functions.
*/
-#define __STDIO_AUTO_THREADLOCK_VAR int __infunc_user_locking
+#define __STDIO_AUTO_THREADLOCK_VAR \
+ __UCLIBC_MUTEX_AUTO_LOCK_VAR(__infunc_user_locking)
-#ifdef __USE_STDIO_FUTEXES__
+#define __STDIO_AUTO_THREADLOCK(__stream) \
+ __UCLIBC_IO_MUTEX_AUTO_LOCK((__stream)->__lock, __infunc_user_locking, \
+ (__stream)->__user_locking)
-#define __STDIO_SET_USER_LOCKING(__stream) ((__stream)->__user_locking = 1)
-
-#define __STDIO_AUTO_THREADLOCK(__stream) \
- if ((__infunc_user_locking = (__stream)->__user_locking) == 0) { \
- _IO_lock_lock((__stream)->_lock); \
- }
+#define __STDIO_AUTO_THREADUNLOCK(__stream) \
+ __UCLIBC_IO_MUTEX_AUTO_UNLOCK((__stream)->__lock, __infunc_user_locking)
-#define __STDIO_AUTO_THREADUNLOCK(__stream) \
- if (__infunc_user_locking == 0) { \
- _IO_lock_unlock((__stream)->_lock); \
- }
+#define __STDIO_ALWAYS_THREADLOCK(__stream) \
+ __UCLIBC_IO_MUTEX_LOCK((__stream)->__lock)
-#define __STDIO_ALWAYS_THREADLOCK(__stream) \
- _IO_lock_lock((__stream)->_lock)
+#define __STDIO_ALWAYS_THREADUNLOCK(__stream) \
+ __UCLIBC_IO_MUTEX_UNLOCK((__stream)->__lock)
-#define __STDIO_ALWAYS_THREADTRYLOCK(__stream) \
- _IO_lock_trylock((__stream)->_lock)
+#define __STDIO_ALWAYS_THREADLOCK_CANCEL_UNSAFE(__stream) \
+ __UCLIBC_IO_MUTEX_LOCK_CANCEL_UNSAFE((__stream)->__lock)
-#define __STDIO_ALWAYS_THREADUNLOCK(__stream) \
- _IO_lock_unlock((__stream)->_lock)
-
-#else
+#define __STDIO_ALWAYS_THREADTRYLOCK_CANCEL_UNSAFE(__stream) \
+ __UCLIBC_IO_MUTEX_TRYLOCK_CANCEL_UNSAFE((__stream)->__lock)
-#define __STDIO_AUTO_THREADLOCK(__stream) \
- if ((__infunc_user_locking = (__stream)->__user_locking) == 0) { \
- __pthread_mutex_lock(&(__stream)->__lock); \
- }
-
-#define __STDIO_AUTO_THREADUNLOCK(__stream) \
- if (__infunc_user_locking == 0) { \
- __pthread_mutex_unlock(&(__stream)->__lock); \
- }
+#define __STDIO_ALWAYS_THREADUNLOCK_CANCEL_UNSAFE(__stream) \
+ __UCLIBC_IO_MUTEX_UNLOCK_CANCEL_UNSAFE((__stream)->__lock)
+#ifdef __UCLIBC_HAS_THREADS__
#define __STDIO_SET_USER_LOCKING(__stream) ((__stream)->__user_locking = 1)
-
-#define __STDIO_ALWAYS_THREADLOCK(__stream) \
- __pthread_mutex_lock(&(__stream)->__lock)
-
-#define __STDIO_ALWAYS_THREADTRYLOCK(__stream) \
- __pthread_mutex_trylock(&(__stream)->__lock)
-
-#define __STDIO_ALWAYS_THREADUNLOCK(__stream) \
- __pthread_mutex_unlock(&(__stream)->__lock)
-
-#endif
-
-#else /* __UCLIBC_HAS_THREADS__ */
-
-#define __STDIO_AUTO_THREADLOCK_VAR ((void)0)
-
-#define __STDIO_AUTO_THREADLOCK(__stream) ((void)0)
-#define __STDIO_AUTO_THREADUNLOCK(__stream) ((void)0)
-
+#else
#define __STDIO_SET_USER_LOCKING(__stream) ((void)0)
+#endif
-#define __STDIO_ALWAYS_THREADLOCK(__stream) ((void)0)
-#define __STDIO_ALWAYS_THREADTRYLOCK(__stream) (0) /* Always succeed. */
-#define __STDIO_ALWAYS_THREADUNLOCK(__stream) ((void)0)
+#ifdef __UCLIBC_HAS_THREADS__
+#ifdef __USE_STDIO_FUTEXES__
+#define STDIO_INIT_MUTEX(M) _IO_lock_init(M)
+#else
+#define STDIO_INIT_MUTEX(M) __stdio_init_mutex(& M)
+#endif
+#endif
-#endif /* __UCLIBC_HAS_THREADS__ */
/**********************************************************************/
#define __STDIO_IOFBF 0 /* Fully buffered. */
@@ -313,11 +283,7 @@ struct __STDIO_FILE_STRUCT {
#endif
#ifdef __UCLIBC_HAS_THREADS__
int __user_locking;
-#ifdef __USE_STDIO_FUTEXES__
- _IO_lock_t _lock;
-#else
- pthread_mutex_t __lock;
-#endif
+ __UCLIBC_IO_MUTEX(__lock);
#endif
/* Everything after this is unimplemented... and may be trashed. */
#if __STDIO_BUILTIN_BUF_SIZE > 0
@@ -393,16 +359,14 @@ extern void _stdio_term(void) attribute_hidden;
extern struct __STDIO_FILE_STRUCT *_stdio_openlist;
#ifdef __UCLIBC_HAS_THREADS__
-#ifdef __USE_STDIO_FUTEXES__
-extern _IO_lock_t _stdio_openlist_lock;
-#else
-extern pthread_mutex_t _stdio_openlist_lock;
+__UCLIBC_IO_MUTEX_EXTERN(_stdio_openlist_add_lock);
+#ifdef __STDIO_BUFFERS
+__UCLIBC_IO_MUTEX_EXTERN(_stdio_openlist_del_lock);
+extern volatile int _stdio_openlist_use_count; /* _stdio_openlist_del_lock */
+extern int _stdio_openlist_del_count; /* _stdio_openlist_del_lock */
#endif
-extern int _stdio_openlist_delflag;
extern int _stdio_user_locking;
-/* #ifdef _LIBC */
-extern void __stdio_init_mutex(pthread_mutex_t *m) attribute_hidden;
-/* #endif */
+extern void __stdio_init_mutex(__UCLIBC_MUTEX_TYPE *m) attribute_hidden;
#endif
#endif
@@ -428,7 +392,8 @@ extern void __stdio_init_mutex(pthread_mutex_t *m) attribute_hidden;
extern int __fgetc_unlocked(FILE *__stream);
extern int __fputc_unlocked(int __c, FILE *__stream);
-/* First define the default definitions. They overriden below as necessary. */
+/* First define the default definitions.
+ They are overridden below as necessary. */
#define __FGETC_UNLOCKED(__stream) (__fgetc_unlocked)((__stream))
#define __FGETC(__stream) (fgetc)((__stream))
#define __GETC_UNLOCKED_MACRO(__stream) (__fgetc_unlocked)((__stream))
diff --git a/libc/sysdeps/linux/common/bits/uio.h b/libc/sysdeps/linux/common/bits/uio.h
index 9873a1808..87f916d71 100644
--- a/libc/sysdeps/linux/common/bits/uio.h
+++ b/libc/sysdeps/linux/common/bits/uio.h
@@ -38,7 +38,7 @@
functionality even if the currently running kernel does not support
this large value the readv/writev call will not fail because of this. */
#define UIO_MAXIOV 1024
-#define UIO_FASTIOV 8
+#define UIO_FASTIOV 8
/* Structure for scatter/gather I/O. */
diff --git a/libc/sysdeps/linux/common/bits/waitstatus.h b/libc/sysdeps/linux/common/bits/waitstatus.h
index 982c9dbb2..699c22498 100644
--- a/libc/sysdeps/linux/common/bits/waitstatus.h
+++ b/libc/sysdeps/linux/common/bits/waitstatus.h
@@ -1,5 +1,5 @@
/* Definitions of status bits for `wait' et al.
- Copyright (C) 1992, 1994, 1996, 1997, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1992,1994,1996,1997,2000,2004 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
@@ -38,23 +38,25 @@
#define __WIFEXITED(status) (__WTERMSIG(status) == 0)
/* Nonzero if STATUS indicates termination by a signal. */
-#ifdef __GNUC__
-# define __WIFSIGNALED(status) \
- (__extension__ ({ int __status = (status); \
- !__WIFSTOPPED(__status) && !__WIFEXITED(__status); }))
-#else /* Not GCC. */
-# define __WIFSIGNALED(status) (!__WIFSTOPPED(status) && !__WIFEXITED(status))
-#endif /* GCC. */
+#define __WIFSIGNALED(status) \
+ (((signed char) (((status) & 0x7f) + 1) >> 1) > 0)
/* Nonzero if STATUS indicates the child is stopped. */
#define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
+/* Nonzero if STATUS indicates the child continued after a stop. We only
+ define this if <bits/waitflags.h> provides the WCONTINUED flag bit. */
+#ifdef WCONTINUED
+# define __WIFCONTINUED(status) ((status) == __W_CONTINUED)
+#endif
+
/* Nonzero if STATUS indicates the child dumped core. */
#define __WCOREDUMP(status) ((status) & __WCOREFLAG)
/* Macros for constructing status values. */
#define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
#define __W_STOPCODE(sig) ((sig) << 8 | 0x7f)
+#define __W_CONTINUED 0xffff
#define __WCOREFLAG 0x80
diff --git a/libc/sysdeps/linux/common/capget.c b/libc/sysdeps/linux/common/capget.c
index 8c28e51a5..c8c83249c 100644
--- a/libc/sysdeps/linux/common/capget.c
+++ b/libc/sysdeps/linux/common/capget.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
int capget(void *header, void *data);
#ifdef __NR_capget
_syscall2(int, capget, void *, header, void *, data);
diff --git a/libc/sysdeps/linux/common/capset.c b/libc/sysdeps/linux/common/capset.c
index bee720f92..7a28b0e16 100644
--- a/libc/sysdeps/linux/common/capset.c
+++ b/libc/sysdeps/linux/common/capset.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
int capset(void *header, const void *data);
#ifdef __NR_capset
_syscall2(int, capset, void *, header, const void *, data);
diff --git a/libc/sysdeps/linux/common/chdir.c b/libc/sysdeps/linux/common/chdir.c
index 7afccf20c..d67fa0c9c 100644
--- a/libc/sysdeps/linux/common/chdir.c
+++ b/libc/sysdeps/linux/common/chdir.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
diff --git a/libc/sysdeps/linux/common/chmod.c b/libc/sysdeps/linux/common/chmod.c
index 03438c054..0b9e89426 100644
--- a/libc/sysdeps/linux/common/chmod.c
+++ b/libc/sysdeps/linux/common/chmod.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/stat.h>
libc_hidden_proto(chmod)
diff --git a/libc/sysdeps/linux/common/chown.c b/libc/sysdeps/linux/common/chown.c
index d6461394b..169ea3aea 100644
--- a/libc/sysdeps/linux/common/chown.c
+++ b/libc/sysdeps/linux/common/chown.c
@@ -7,12 +7,23 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
+#include <bits/wordsize.h>
libc_hidden_proto(chown)
-#define __NR___syscall_chown __NR_chown
+#if (__WORDSIZE == 32 && defined(__NR_chown32)) || __WORDSIZE == 64
+# ifdef __NR_chown32
+# undef __NR_chown
+# define __NR_chown __NR_chown32
+# endif
+
+_syscall3(int, chown, const char *, path, uid_t, owner, gid_t, group);
+
+#else
+
+# define __NR___syscall_chown __NR_chown
static inline _syscall3(int, __syscall_chown, const char *, path,
__kernel_uid_t, owner, __kernel_gid_t, group);
@@ -25,4 +36,6 @@ int chown(const char *path, uid_t owner, gid_t group)
}
return (__syscall_chown(path, owner, group));
}
+#endif
+
libc_hidden_def(chown)
diff --git a/libc/sysdeps/linux/common/chroot.c b/libc/sysdeps/linux/common/chroot.c
index 527310a15..5ea76ab0d 100644
--- a/libc/sysdeps/linux/common/chroot.c
+++ b/libc/sysdeps/linux/common/chroot.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <string.h>
#include <sys/param.h>
diff --git a/libc/sysdeps/linux/common/clock_getres.c b/libc/sysdeps/linux/common/clock_getres.c
index 8ee782845..0a3e1d16f 100644
--- a/libc/sysdeps/linux/common/clock_getres.c
+++ b/libc/sysdeps/linux/common/clock_getres.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>
@@ -18,15 +18,18 @@ libc_hidden_proto(sysconf)
int clock_getres(clockid_t clock_id, struct timespec* res)
{
- long clk_tck;
int retval = -1;
switch (clock_id) {
case CLOCK_REALTIME:
- if ((clk_tck = sysconf(_SC_CLK_TCK)) < 0)
- clk_tck = 100;
- res->tv_sec = 0;
- res->tv_nsec = 1000000000 / clk_tck;
+ if (res) {
+ long clk_tck;
+
+ if ((clk_tck = sysconf(_SC_CLK_TCK)) < 0)
+ clk_tck = 100;
+ res->tv_sec = 0;
+ res->tv_nsec = 1000000000 / clk_tck;
+ }
retval = 0;
break;
diff --git a/libc/sysdeps/linux/common/clock_gettime.c b/libc/sysdeps/linux/common/clock_gettime.c
index c6b4111fe..38f7ab7ba 100644
--- a/libc/sysdeps/linux/common/clock_gettime.c
+++ b/libc/sysdeps/linux/common/clock_gettime.c
@@ -8,7 +8,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <time.h>
#include <sys/time.h>
diff --git a/libc/sysdeps/linux/common/clock_settime.c b/libc/sysdeps/linux/common/clock_settime.c
index 6ad7872ae..8ebec7381 100644
--- a/libc/sysdeps/linux/common/clock_settime.c
+++ b/libc/sysdeps/linux/common/clock_settime.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <time.h>
#include <sys/time.h>
diff --git a/libc/sysdeps/linux/common/close.c b/libc/sysdeps/linux/common/close.c
index 9bd11c028..430fb34b7 100644
--- a/libc/sysdeps/linux/common/close.c
+++ b/libc/sysdeps/linux/common/close.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
extern __typeof(close) __libc_close;
diff --git a/libc/sysdeps/linux/common/creat64.c b/libc/sysdeps/linux/common/creat64.c
index c1f250832..f5f00182c 100644
--- a/libc/sysdeps/linux/common/creat64.c
+++ b/libc/sysdeps/linux/common/creat64.c
@@ -22,11 +22,14 @@
#include <fcntl.h>
#include <sys/types.h>
-libc_hidden_proto(open64)
+extern __typeof(open64) __libc_open64;
+libc_hidden_proto(__libc_open64)
+extern __typeof(creat64) __libc_creat64;
/* Create FILE with protections MODE. */
-int creat64 (const char *file, mode_t mode)
+int __libc_creat64 (const char *file, mode_t mode)
{
- return open64 (file, O_WRONLY|O_CREAT|O_TRUNC, mode);
+ return __libc_open64 (file, O_WRONLY|O_CREAT|O_TRUNC, mode);
}
+weak_alias(__libc_creat64,creat64)
#endif /* __UCLIBC_HAS_LFS__ */
diff --git a/libc/sysdeps/linux/common/delete_module.c b/libc/sysdeps/linux/common/delete_module.c
index 66a1610d3..a93921411 100644
--- a/libc/sysdeps/linux/common/delete_module.c
+++ b/libc/sysdeps/linux/common/delete_module.c
@@ -6,7 +6,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
int delete_module(const char *name);
#ifdef __NR_delete_module
_syscall1(int, delete_module, const char *, name);
diff --git a/libc/sysdeps/linux/common/dup.c b/libc/sysdeps/linux/common/dup.c
index 01b467639..ea7f7d0b1 100644
--- a/libc/sysdeps/linux/common/dup.c
+++ b/libc/sysdeps/linux/common/dup.c
@@ -6,6 +6,6 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
_syscall1(int, dup, int, oldfd);
diff --git a/libc/sysdeps/linux/common/dup2.c b/libc/sysdeps/linux/common/dup2.c
index 27d837608..16bcc4221 100644
--- a/libc/sysdeps/linux/common/dup2.c
+++ b/libc/sysdeps/linux/common/dup2.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(dup2)
diff --git a/libc/sysdeps/linux/common/epoll.c b/libc/sysdeps/linux/common/epoll.c
index b2f06f9ef..27f5a7d61 100644
--- a/libc/sysdeps/linux/common/epoll.c
+++ b/libc/sysdeps/linux/common/epoll.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/epoll.h>
/*
diff --git a/libc/sysdeps/linux/common/execve.c b/libc/sysdeps/linux/common/execve.c
index 7183f481f..6bc72dde9 100644
--- a/libc/sysdeps/linux/common/execve.c
+++ b/libc/sysdeps/linux/common/execve.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <string.h>
#include <sys/param.h>
diff --git a/libc/sysdeps/linux/common/fchdir.c b/libc/sysdeps/linux/common/fchdir.c
index 1c59bac00..15c7dbd73 100644
--- a/libc/sysdeps/linux/common/fchdir.c
+++ b/libc/sysdeps/linux/common/fchdir.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(fchdir)
diff --git a/libc/sysdeps/linux/common/fchmod.c b/libc/sysdeps/linux/common/fchmod.c
index f1eb170ce..72ec37a89 100644
--- a/libc/sysdeps/linux/common/fchmod.c
+++ b/libc/sysdeps/linux/common/fchmod.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/stat.h>
#define __NR___syscall_fchmod __NR_fchmod
diff --git a/libc/sysdeps/linux/common/fchown.c b/libc/sysdeps/linux/common/fchown.c
index fa8734284..e8d6eee48 100644
--- a/libc/sysdeps/linux/common/fchown.c
+++ b/libc/sysdeps/linux/common/fchown.c
@@ -2,24 +2,26 @@
/*
* fchown() for uClibc
*
- * Copyright (C) 2000-2006 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@codepoet.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
-#include <linux/version.h>
+#include <bits/wordsize.h>
-/* Linux 2.3.39 introduced 32bit UID/GIDs. Some platforms had 32
- bit type all along. */
-#if LINUX_VERSION_CODE >= 131879
+#if (__WORDSIZE == 32 && defined(__NR_fchown32)) || __WORDSIZE == 64
+# ifdef __NR_fchown32
+# undef __NR_fchown
+# define __NR_fchown __NR_fchown32
+# endif
_syscall3(int, fchown, int, fd, uid_t, owner, gid_t, group);
#else
-#define __NR___syscall_fchown __NR_fchown
+# define __NR___syscall_fchown __NR_fchown
static inline _syscall3(int, __syscall_fchown, int, fd,
__kernel_uid_t, owner, __kernel_gid_t, group);
diff --git a/libc/sysdeps/linux/common/fdatasync.c b/libc/sysdeps/linux/common/fdatasync.c
index c15e47b42..774433f17 100644
--- a/libc/sysdeps/linux/common/fdatasync.c
+++ b/libc/sysdeps/linux/common/fdatasync.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#if defined __NR_osf_fdatasync
diff --git a/libc/sysdeps/linux/common/flock.c b/libc/sysdeps/linux/common/flock.c
index c08783ca9..8a4aa895d 100644
--- a/libc/sysdeps/linux/common/flock.c
+++ b/libc/sysdeps/linux/common/flock.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/file.h>
#define __NR___syscall_flock __NR_flock
diff --git a/libc/sysdeps/linux/common/fork.c b/libc/sysdeps/linux/common/fork.c
index 884e986ab..b4fa3686d 100644
--- a/libc/sysdeps/linux/common/fork.c
+++ b/libc/sysdeps/linux/common/fork.c
@@ -7,10 +7,11 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#ifdef __ARCH_USE_MMU__
+
#ifdef __NR_fork
extern __typeof(fork) __libc_fork;
#define __NR___libc_fork __NR_fork
@@ -19,4 +20,17 @@ libc_hidden_proto(fork)
weak_alias(__libc_fork,fork)
libc_hidden_weak(fork)
#endif
+
+#elif defined __UCLIBC_HAS_STUBS__
+
+pid_t __libc_fork(void)
+{
+ __set_errno(ENOSYS);
+ return -1;
+}
+libc_hidden_proto(fork)
+weak_alias(__libc_fork,fork)
+libc_hidden_weak(fork)
+link_warning(fork, "fork: this function is not implemented on no-mmu systems")
+
#endif
diff --git a/libc/sysdeps/linux/common/fpu_control.h b/libc/sysdeps/linux/common/fpu_control.h
index 4a1b07d23..de261c2eb 100644
--- a/libc/sysdeps/linux/common/fpu_control.h
+++ b/libc/sysdeps/linux/common/fpu_control.h
@@ -33,7 +33,9 @@ typedef unsigned int fpu_control_t;
#define _FPU_GETCW(cw) 0
#define _FPU_SETCW(cw) do { } while (0)
+#if 0
/* Default control word set at startup. */
extern fpu_control_t __fpu_control;
+#endif
#endif /* _FPU_CONTROL_H */
diff --git a/libc/sysdeps/linux/common/fstat.c b/libc/sysdeps/linux/common/fstat.c
index c89d7e57c..437c2d16b 100644
--- a/libc/sysdeps/linux/common/fstat.c
+++ b/libc/sysdeps/linux/common/fstat.c
@@ -11,7 +11,7 @@
* will fail when __NR_fstat64 doesnt exist */
#define fstat64 __hidefstat64
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/stat.h>
#include "xstatconv.h"
diff --git a/libc/sysdeps/linux/common/fstat64.c b/libc/sysdeps/linux/common/fstat64.c
index f992de20a..215868d89 100644
--- a/libc/sysdeps/linux/common/fstat64.c
+++ b/libc/sysdeps/linux/common/fstat64.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#if defined __UCLIBC_HAS_LFS__ && defined __NR_fstat64
#include <unistd.h>
diff --git a/libc/sysdeps/linux/common/fstatfs.c b/libc/sysdeps/linux/common/fstatfs.c
index 2a90a38ed..830de8103 100644
--- a/libc/sysdeps/linux/common/fstatfs.c
+++ b/libc/sysdeps/linux/common/fstatfs.c
@@ -7,10 +7,30 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/vfs.h>
-libc_hidden_proto(fstatfs)
+#if !defined __UCLIBC_LINUX_SPECIFIC__
+#ifndef __USE_FILE_OFFSET64
+extern int fstatfs (int __fildes, struct statfs *__buf)
+ __THROW __nonnull ((2));
+#else
+# ifdef __REDIRECT_NTH
+extern int __REDIRECT_NTH (fstatfs, (int __fildes, struct statfs *__buf),
+ fstatfs64) __nonnull ((2));
+# else
+# define fstatfs fstatfs64
+# endif
+#endif
+#endif
+extern __typeof(fstatfs) __libc_fstatfs;
+libc_hidden_proto(__libc_fstatfs)
+#define __NR___libc_fstatfs __NR_fstatfs
+_syscall2(int, __libc_fstatfs, int, fd, struct statfs *, buf);
+libc_hidden_def(__libc_fstatfs)
-_syscall2(int, fstatfs, int, fd, struct statfs *, buf);
-libc_hidden_def(fstatfs)
+#if defined __UCLIBC_LINUX_SPECIFIC__
+libc_hidden_proto(fstatfs)
+weak_alias(__libc_fstatfs,fstatfs)
+libc_hidden_weak(fstatfs)
+#endif
diff --git a/libc/sysdeps/linux/common/fsync.c b/libc/sysdeps/linux/common/fsync.c
index ecc203c74..be76b2d0d 100644
--- a/libc/sysdeps/linux/common/fsync.c
+++ b/libc/sysdeps/linux/common/fsync.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
diff --git a/libc/sysdeps/linux/common/ftruncate.c b/libc/sysdeps/linux/common/ftruncate.c
index 8c342e7fc..951720ba8 100644
--- a/libc/sysdeps/linux/common/ftruncate.c
+++ b/libc/sysdeps/linux/common/ftruncate.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(ftruncate)
diff --git a/libc/sysdeps/linux/common/get_kernel_syms.c b/libc/sysdeps/linux/common/get_kernel_syms.c
index 2c2d9c028..4f4ee5167 100644
--- a/libc/sysdeps/linux/common/get_kernel_syms.c
+++ b/libc/sysdeps/linux/common/get_kernel_syms.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
struct kernel_sym;
int get_kernel_syms(struct kernel_sym *table attribute_unused);
diff --git a/libc/sysdeps/linux/common/getcwd.c b/libc/sysdeps/linux/common/getcwd.c
index 165ea317e..512a9e1ee 100644
--- a/libc/sysdeps/linux/common/getcwd.c
+++ b/libc/sysdeps/linux/common/getcwd.c
@@ -18,10 +18,10 @@
libc_hidden_proto(getcwd)
libc_hidden_proto(getpagesize)
-libc_hidden_proto(strcat)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strncpy)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strcat) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strncpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(opendir)
libc_hidden_proto(readdir)
libc_hidden_proto(closedir)
@@ -165,7 +165,7 @@ int __syscall_getcwd(char * buf, unsigned long size)
cwd = recurser(buf, size, st.st_dev, st.st_ino);
if (cwd) {
- len = strlen(buf);
+ len = strlen(buf) + 1;
__set_errno(olderrno);
}
return len;
diff --git a/libc/sysdeps/linux/common/getdents.c b/libc/sysdeps/linux/common/getdents.c
index 11c2570c4..55c8f85ee 100644
--- a/libc/sysdeps/linux/common/getdents.c
+++ b/libc/sysdeps/linux/common/getdents.c
@@ -15,10 +15,10 @@
#include <sys/param.h>
#include <sys/types.h>
#include <sys/syscall.h>
+#include <bits/kernel_types.h>
/* With newer versions of linux, the getdents syscall returns d_type
- * information after the name field. Someday, we should add support for
- * that instead of always calling getdents64 ...
+ * information after the name field.
*
* See __ASSUME_GETDENTS32_D_TYPE in glibc's kernel-features.h for specific
* version / arch details.
@@ -38,14 +38,42 @@ struct kernel_dirent
ssize_t __getdents (int fd, char *buf, size_t nbytes) attribute_hidden;
-#if ! defined __UCLIBC_HAS_LFS__ || ! defined __NR_getdents64
-
-libc_hidden_proto(memcpy)
-libc_hidden_proto(lseek)
-
#define __NR___syscall_getdents __NR_getdents
static inline _syscall3(int, __syscall_getdents, int, fd, unsigned char *, kdirp, size_t, count);
+#ifdef __ASSUME_GETDENTS32_D_TYPE
+ssize_t __getdents (int fd, char *buf, size_t nbytes)
+{
+ ssize_t retval;
+
+ retval = __syscall_getdents(fd, (unsigned char *)buf, nbytes);
+
+ /* The kernel added the d_type value after the name. Change
+ this now. */
+ if (retval != -1) {
+ union {
+ struct kernel_dirent k;
+ struct dirent u;
+ } *kbuf = (void *) buf;
+
+ while ((char *) kbuf < buf + retval) {
+ char d_type = *((char *) kbuf + kbuf->k.d_reclen - 1);
+ memmove (kbuf->u.d_name, kbuf->k.d_name,
+ strlen (kbuf->k.d_name) + 1);
+ kbuf->u.d_type = d_type;
+
+ kbuf = (void *) ((char *) kbuf + kbuf->k.d_reclen);
+ }
+ }
+
+ return retval;
+}
+
+#elif ! defined __UCLIBC_HAS_LFS__ || ! defined __NR_getdents64
+
+/* Experimentally off - libc_hidden_proto(memcpy) */
+libc_hidden_proto(lseek)
+
ssize_t __getdents (int fd, char *buf, size_t nbytes)
{
struct dirent *dp;
@@ -107,7 +135,7 @@ attribute_hidden strong_alias(__getdents,__getdents64)
#elif __WORDSIZE == 32
-libc_hidden_proto(memmove)
+/* Experimentally off - libc_hidden_proto(memmove) */
extern __typeof(__getdents) __getdents64 attribute_hidden;
ssize_t __getdents (int fd, char *buf, size_t nbytes)
diff --git a/libc/sysdeps/linux/common/getdents64.c b/libc/sysdeps/linux/common/getdents64.c
index 57936d348..2328df29e 100644
--- a/libc/sysdeps/linux/common/getdents64.c
+++ b/libc/sysdeps/linux/common/getdents64.c
@@ -16,10 +16,11 @@
#include <sys/param.h>
#include <sys/types.h>
#include <sys/syscall.h>
+#include <bits/kernel_types.h>
#if defined __UCLIBC_HAS_LFS__ && defined __NR_getdents64
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(lseek64)
# ifndef offsetof
diff --git a/libc/sysdeps/linux/common/getdirname.c b/libc/sysdeps/linux/common/getdirname.c
index e196d1bd9..5938d7257 100644
--- a/libc/sysdeps/linux/common/getdirname.c
+++ b/libc/sysdeps/linux/common/getdirname.c
@@ -25,7 +25,7 @@
#include <stdlib.h>
#include <string.h>
-libc_hidden_proto(strdup)
+/* Experimentally off - libc_hidden_proto(strdup) */
libc_hidden_proto(getcwd)
libc_hidden_proto(getenv)
#ifdef __UCLIBC_HAS_LFS__
diff --git a/libc/sysdeps/linux/common/getdtablesize.c b/libc/sysdeps/linux/common/getdtablesize.c
index 4efd8280d..44d21862f 100644
--- a/libc/sysdeps/linux/common/getdtablesize.c
+++ b/libc/sysdeps/linux/common/getdtablesize.c
@@ -9,6 +9,8 @@
#include <sys/resource.h>
#include <limits.h>
+/* XXX: _BSD || _XOPEN_SOURCE >= 500 */
+#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
libc_hidden_proto(getdtablesize)
libc_hidden_proto(getrlimit)
@@ -27,3 +29,4 @@ int getdtablesize (void)
return getrlimit (RLIMIT_NOFILE, &ru) < 0 ? __LOCAL_OPEN_MAX : ru.rlim_cur;
}
libc_hidden_def(getdtablesize)
+#endif
diff --git a/libc/sysdeps/linux/common/getegid.c b/libc/sysdeps/linux/common/getegid.c
index 466d63d89..7c34b6c09 100644
--- a/libc/sysdeps/linux/common/getegid.c
+++ b/libc/sysdeps/linux/common/getegid.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(getegid)
diff --git a/libc/sysdeps/linux/common/geteuid.c b/libc/sysdeps/linux/common/geteuid.c
index 247f1bfda..d10c350e4 100644
--- a/libc/sysdeps/linux/common/geteuid.c
+++ b/libc/sysdeps/linux/common/geteuid.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(geteuid)
diff --git a/libc/sysdeps/linux/common/getgid.c b/libc/sysdeps/linux/common/getgid.c
index 3f48c33c8..820ebf0e2 100644
--- a/libc/sysdeps/linux/common/getgid.c
+++ b/libc/sysdeps/linux/common/getgid.c
@@ -7,12 +7,18 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#if defined __NR_getxgid
+# undef __NR_getgid
# define __NR_getgid __NR_getxgid
#endif
+#ifdef __NR_getgid32
+# undef __NR_getgid
+# define __NR_getgid __NR_getgid32
+#endif
+
libc_hidden_proto(getgid)
_syscall0(gid_t, getgid);
libc_hidden_def(getgid)
diff --git a/libc/sysdeps/linux/common/getgroups.c b/libc/sysdeps/linux/common/getgroups.c
index 6903ed14f..10da03ddd 100644
--- a/libc/sysdeps/linux/common/getgroups.c
+++ b/libc/sysdeps/linux/common/getgroups.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <stdlib.h>
#include <unistd.h>
#include <grp.h>
@@ -53,8 +53,7 @@ ret_error:
}
}
- if (kernel_groups)
- free(kernel_groups);
+ free(kernel_groups);
return ngids;
}
}
diff --git a/libc/sysdeps/linux/common/getitimer.c b/libc/sysdeps/linux/common/getitimer.c
index 0d2024dfc..b240f1c6e 100644
--- a/libc/sysdeps/linux/common/getitimer.c
+++ b/libc/sysdeps/linux/common/getitimer.c
@@ -7,6 +7,6 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/time.h>
_syscall2(int, getitimer, __itimer_which_t, which, struct itimerval *, value);
diff --git a/libc/sysdeps/linux/common/getpgid.c b/libc/sysdeps/linux/common/getpgid.c
index 6cdaef172..49f780adf 100644
--- a/libc/sysdeps/linux/common/getpgid.c
+++ b/libc/sysdeps/linux/common/getpgid.c
@@ -7,7 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#if defined __USE_UNIX98
#include <unistd.h>
#define __NR___syscall_getpgid __NR_getpgid
@@ -17,3 +19,4 @@ pid_t getpgid(pid_t pid)
{
return (__syscall_getpgid(pid));
}
+#endif
diff --git a/libc/sysdeps/linux/common/getpgrp.c b/libc/sysdeps/linux/common/getpgrp.c
index 9260e432a..a2fe44560 100644
--- a/libc/sysdeps/linux/common/getpgrp.c
+++ b/libc/sysdeps/linux/common/getpgrp.c
@@ -7,9 +7,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#ifdef __NR_getpgrp
+/* According to the manpage the POSIX.1 version is favoured */
_syscall0(pid_t, getpgrp);
#endif
diff --git a/libc/sysdeps/linux/common/getpid.c b/libc/sysdeps/linux/common/getpid.c
index fd331bd62..56f1ddd66 100644
--- a/libc/sysdeps/linux/common/getpid.c
+++ b/libc/sysdeps/linux/common/getpid.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
extern __typeof(getpid) __libc_getpid;
diff --git a/libc/sysdeps/linux/common/getppid.c b/libc/sysdeps/linux/common/getppid.c
index 6a68ad615..1630234cc 100644
--- a/libc/sysdeps/linux/common/getppid.c
+++ b/libc/sysdeps/linux/common/getppid.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#ifdef __NR_getppid
_syscall0(pid_t, getppid);
diff --git a/libc/sysdeps/linux/common/getpriority.c b/libc/sysdeps/linux/common/getpriority.c
index 41cc3eb49..b66b1ea15 100644
--- a/libc/sysdeps/linux/common/getpriority.c
+++ b/libc/sysdeps/linux/common/getpriority.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/resource.h>
libc_hidden_proto(getpriority)
diff --git a/libc/sysdeps/linux/common/getresgid.c b/libc/sysdeps/linux/common/getresgid.c
index bc19b97ea..9c2d13ba9 100644
--- a/libc/sysdeps/linux/common/getresgid.c
+++ b/libc/sysdeps/linux/common/getresgid.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#ifdef __USE_GNU
#include <unistd.h>
diff --git a/libc/sysdeps/linux/common/getresuid.c b/libc/sysdeps/linux/common/getresuid.c
index b8d1788f6..dbc8df903 100644
--- a/libc/sysdeps/linux/common/getresuid.c
+++ b/libc/sysdeps/linux/common/getresuid.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#ifdef __USE_GNU
#include <unistd.h>
diff --git a/libc/sysdeps/linux/common/getrlimit.c b/libc/sysdeps/linux/common/getrlimit.c
index 2a4d05318..ecb09d1e2 100644
--- a/libc/sysdeps/linux/common/getrlimit.c
+++ b/libc/sysdeps/linux/common/getrlimit.c
@@ -8,7 +8,7 @@
*/
#define getrlimit64 __hide_getrlimit64
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/resource.h>
#undef getrlimit64
@@ -17,7 +17,7 @@ libc_hidden_proto(getrlimit)
/* Only wrap getrlimit if the new ugetrlimit is not present and getrlimit sucks */
-#if defined(__NR_ugetrlimit)
+#if defined __NR_ugetrlimit
/* just call ugetrlimit() */
# define __NR___syscall_ugetrlimit __NR_ugetrlimit
diff --git a/libc/sysdeps/linux/common/getrusage.c b/libc/sysdeps/linux/common/getrusage.c
index 9b87cb1b4..03f524dff 100644
--- a/libc/sysdeps/linux/common/getrusage.c
+++ b/libc/sysdeps/linux/common/getrusage.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <wait.h>
_syscall2(int, getrusage, __rusage_who_t, who, struct rusage *, usage);
diff --git a/libc/sysdeps/linux/common/getsid.c b/libc/sysdeps/linux/common/getsid.c
index aaac0ceb9..398851873 100644
--- a/libc/sysdeps/linux/common/getsid.c
+++ b/libc/sysdeps/linux/common/getsid.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#ifdef __USE_XOPEN_EXTENDED
diff --git a/libc/sysdeps/linux/common/gettimeofday.c b/libc/sysdeps/linux/common/gettimeofday.c
index 8e1cf57eb..697b2dd6c 100644
--- a/libc/sysdeps/linux/common/gettimeofday.c
+++ b/libc/sysdeps/linux/common/gettimeofday.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/time.h>
libc_hidden_proto(gettimeofday)
diff --git a/libc/sysdeps/linux/common/getuid.c b/libc/sysdeps/linux/common/getuid.c
index 21c504d65..7d5a02bc6 100644
--- a/libc/sysdeps/linux/common/getuid.c
+++ b/libc/sysdeps/linux/common/getuid.c
@@ -7,12 +7,18 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#if defined __NR_getxuid
-# define __NR_getuid __NR_getxuid
+# undef __NR_getuid
+# define __NR_getuid __NR_getxuid
#endif
+#ifdef __NR_getuid32
+# undef __NR_getuid
+# define __NR_getuid __NR_getuid32
+#endif
+
libc_hidden_proto(getuid)
_syscall0(uid_t, getuid);
libc_hidden_def(getuid)
diff --git a/libc/sysdeps/linux/common/init_module.c b/libc/sysdeps/linux/common/init_module.c
index 3fb566961..45f1fff23 100644
--- a/libc/sysdeps/linux/common/init_module.c
+++ b/libc/sysdeps/linux/common/init_module.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
int init_module(void *first, void *second, void *third, void *fourth, void *fifth);
#ifdef __NR_init_module
/* This may have 5 arguments (for old 2.0 kernels) or 2 arguments
diff --git a/libc/sysdeps/linux/common/inotify.c b/libc/sysdeps/linux/common/inotify.c
index 87cf4d71e..31bfb0c3b 100644
--- a/libc/sysdeps/linux/common/inotify.c
+++ b/libc/sysdeps/linux/common/inotify.c
@@ -8,7 +8,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/inotify.h>
#ifdef __NR_inotify_init
diff --git a/libc/sysdeps/linux/common/ioctl.c b/libc/sysdeps/linux/common/ioctl.c
index 02393b98e..f27fb05e3 100644
--- a/libc/sysdeps/linux/common/ioctl.c
+++ b/libc/sysdeps/linux/common/ioctl.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <stdarg.h>
#include <sys/ioctl.h>
diff --git a/libc/sysdeps/linux/common/ioperm.c b/libc/sysdeps/linux/common/ioperm.c
index e9ca964cc..880842d97 100644
--- a/libc/sysdeps/linux/common/ioperm.c
+++ b/libc/sysdeps/linux/common/ioperm.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#if defined __ARCH_USE_MMU__ && defined __NR_ioperm
/* psm: can't #include <sys/io.h>, some archs miss it */
extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on) __THROW;
diff --git a/libc/sysdeps/linux/common/iopl.c b/libc/sysdeps/linux/common/iopl.c
index 2a6b619d5..510e1a4f6 100644
--- a/libc/sysdeps/linux/common/iopl.c
+++ b/libc/sysdeps/linux/common/iopl.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#if defined __ARCH_USE_MMU__ && defined __NR_iopl
/* psm: can't #include <sys/io.h>, some archs miss it */
extern int iopl(int __level) __THROW;
diff --git a/libc/sysdeps/linux/common/kill.c b/libc/sysdeps/linux/common/kill.c
index 7e1b330a5..46eabf0c9 100644
--- a/libc/sysdeps/linux/common/kill.c
+++ b/libc/sysdeps/linux/common/kill.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <signal.h>
libc_hidden_proto(kill)
diff --git a/libc/sysdeps/linux/common/klogctl.c b/libc/sysdeps/linux/common/klogctl.c
index 5e36104f1..81451022e 100644
--- a/libc/sysdeps/linux/common/klogctl.c
+++ b/libc/sysdeps/linux/common/klogctl.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/klog.h>
#define __NR__syslog __NR_syslog
diff --git a/libc/sysdeps/linux/common/lchown.c b/libc/sysdeps/linux/common/lchown.c
index ffee39126..8095c941e 100644
--- a/libc/sysdeps/linux/common/lchown.c
+++ b/libc/sysdeps/linux/common/lchown.c
@@ -7,10 +7,21 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
+#include <bits/wordsize.h>
-#define __NR___syscall_lchown __NR_lchown
+#if (__WORDSIZE == 32 && defined(__NR_lchown32)) || __WORDSIZE == 64
+# ifdef __NR_lchown32
+# undef __NR_lchown
+# define __NR_lchown __NR_lchown32
+# endif
+
+_syscall3(int, lchown, const char *, path, uid_t, owner, gid_t, group);
+
+#else
+
+# define __NR___syscall_lchown __NR_lchown
static inline _syscall3(int, __syscall_lchown, const char *, path,
__kernel_uid_t, owner, __kernel_gid_t, group);
@@ -23,3 +34,5 @@ int lchown(const char *path, uid_t owner, gid_t group)
}
return __syscall_lchown(path, owner, group);
}
+
+#endif
diff --git a/libc/sysdeps/linux/common/link.c b/libc/sysdeps/linux/common/link.c
index 21d1f1413..a012cc2c3 100644
--- a/libc/sysdeps/linux/common/link.c
+++ b/libc/sysdeps/linux/common/link.c
@@ -7,6 +7,6 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
_syscall2(int, link, const char *, oldpath, const char *, newpath);
diff --git a/libc/sysdeps/linux/common/llseek.c b/libc/sysdeps/linux/common/llseek.c
index 0cfbe1a46..ea72dc4f3 100644
--- a/libc/sysdeps/linux/common/llseek.c
+++ b/libc/sysdeps/linux/common/llseek.c
@@ -7,8 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
extern __typeof(lseek64) __libc_lseek64;
@@ -39,3 +40,4 @@ loff_t __libc_lseek64(int fd, loff_t offset, int whence)
libc_hidden_proto(lseek64)
weak_alias(__libc_lseek64,lseek64)
libc_hidden_weak(lseek64)
+//strong_alias(__libc_lseek64,_llseek)
diff --git a/libc/sysdeps/linux/common/lseek.c b/libc/sysdeps/linux/common/lseek.c
index 72833b81b..5ba5ad9c8 100644
--- a/libc/sysdeps/linux/common/lseek.c
+++ b/libc/sysdeps/linux/common/lseek.c
@@ -7,14 +7,23 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
extern __typeof(lseek) __libc_lseek;
libc_hidden_proto(__libc_lseek)
+#ifdef __NR_lseek
#define __NR___libc_lseek __NR_lseek
_syscall3(__off_t, __libc_lseek, int, fildes, __off_t, offset, int, whence);
+#else
+extern __typeof(lseek64) __libc_lseek64;
+libc_hidden_proto(__libc_lseek64)
+__off_t __libc_lseek(int fildes, __off_t offset, int whence)
+{
+ return __libc_lseek64(fildes, offset, whence);
+}
+#endif
libc_hidden_def(__libc_lseek)
libc_hidden_proto(lseek)
diff --git a/libc/sysdeps/linux/common/lstat.c b/libc/sysdeps/linux/common/lstat.c
index 06c7c5d90..379ffd30d 100644
--- a/libc/sysdeps/linux/common/lstat.c
+++ b/libc/sysdeps/linux/common/lstat.c
@@ -11,7 +11,7 @@
* will fail when __NR_lstat64 doesnt exist */
#define lstat64 __hidelstat64
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/stat.h>
#include "xstatconv.h"
diff --git a/libc/sysdeps/linux/common/lstat64.c b/libc/sysdeps/linux/common/lstat64.c
index 2dc06c692..1c392636f 100644
--- a/libc/sysdeps/linux/common/lstat64.c
+++ b/libc/sysdeps/linux/common/lstat64.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#if defined __UCLIBC_HAS_LFS__ && defined __NR_lstat64
# include <unistd.h>
diff --git a/libc/sysdeps/linux/common/madvise.c b/libc/sysdeps/linux/common/madvise.c
index 8c3918060..627bcdc59 100644
--- a/libc/sysdeps/linux/common/madvise.c
+++ b/libc/sysdeps/linux/common/madvise.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/mman.h>
#if defined __NR_madvise && defined __USE_BSD
_syscall3(int, madvise, void *, __addr, size_t, __len, int, __advice);
diff --git a/libc/sysdeps/linux/common/mincore.c b/libc/sysdeps/linux/common/mincore.c
index 0e3ade1ce..1dc9a9a1a 100644
--- a/libc/sysdeps/linux/common/mincore.c
+++ b/libc/sysdeps/linux/common/mincore.c
@@ -6,10 +6,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#if defined __NR_mincore && (defined __USE_BSD || defined __USE_SVID)
#include <unistd.h>
#include <sys/mman.h>
-
-#ifdef __NR_mincore
_syscall3(int, mincore, void *, start, size_t, length, unsigned char *, vec);
#endif
diff --git a/libc/sysdeps/linux/common/mkdir.c b/libc/sysdeps/linux/common/mkdir.c
index 93b66ae40..1d7238456 100644
--- a/libc/sysdeps/linux/common/mkdir.c
+++ b/libc/sysdeps/linux/common/mkdir.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/stat.h>
libc_hidden_proto(mkdir)
diff --git a/libc/sysdeps/linux/common/mknod.c b/libc/sysdeps/linux/common/mknod.c
index b71541d95..02b3822f8 100644
--- a/libc/sysdeps/linux/common/mknod.c
+++ b/libc/sysdeps/linux/common/mknod.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
diff --git a/libc/sysdeps/linux/common/mlock.c b/libc/sysdeps/linux/common/mlock.c
index 3eb72bb07..55b77a5d5 100644
--- a/libc/sysdeps/linux/common/mlock.c
+++ b/libc/sysdeps/linux/common/mlock.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/mman.h>
#if defined __ARCH_USE_MMU__ && defined __NR_mlock
_syscall2(int, mlock, const void *, addr, size_t, len);
diff --git a/libc/sysdeps/linux/common/mlockall.c b/libc/sysdeps/linux/common/mlockall.c
index 6e6d3bc36..d75e30fe7 100644
--- a/libc/sysdeps/linux/common/mlockall.c
+++ b/libc/sysdeps/linux/common/mlockall.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/mman.h>
#if defined __ARCH_USE_MMU__ && defined __NR_mlockall
_syscall1(int, mlockall, int, flags);
diff --git a/libc/sysdeps/linux/common/mmap.c b/libc/sysdeps/linux/common/mmap.c
index 6acb73980..f40554ebb 100644
--- a/libc/sysdeps/linux/common/mmap.c
+++ b/libc/sysdeps/linux/common/mmap.c
@@ -7,9 +7,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/mman.h>
+#include <bits/uClibc_page.h>
#ifdef __NR_mmap
@@ -41,4 +42,32 @@ __ptr_t mmap(__ptr_t addr, size_t len, int prot,
#endif
libc_hidden_def(mmap)
+
+#elif defined(__NR_mmap2)
+
+libc_hidden_proto(mmap)
+
+#define __NR___syscall_mmap2 __NR_mmap2
+static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
+ size_t, len, int, prot, int, flags, int, fd, off_t, offset);
+
+/* Some architectures always use 12 as page shift for mmap2() eventhough the
+ * real PAGE_SHIFT != 12. Other architectures use the same value as
+ * PAGE_SHIFT...
+ */
+# ifndef MMAP2_PAGE_SHIFT
+# define MMAP2_PAGE_SHIFT 12
+# endif
+
+__ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
+{
+ if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
+ __set_errno(EINVAL);
+ return MAP_FAILED;
+ }
+ return __syscall_mmap2(addr, len, prot, flags, fd, offset >> MMAP2_PAGE_SHIFT);
+}
+
+libc_hidden_def(mmap)
+
#endif
diff --git a/libc/sysdeps/linux/common/mmap64.c b/libc/sysdeps/linux/common/mmap64.c
index 2cf200dc9..8c0518d1d 100644
--- a/libc/sysdeps/linux/common/mmap64.c
+++ b/libc/sysdeps/linux/common/mmap64.c
@@ -59,7 +59,13 @@ __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t
return MAP_FAILED;
}
- return __syscall_mmap2(addr, len, prot, flags, fd, (off_t) (offset >> MMAP2_PAGE_SHIFT));
+# ifdef __USE_FILE_OFFSET64
+ return __syscall_mmap2(addr, len, prot, flags,
+ fd, ((__u_quad_t) offset >> MMAP2_PAGE_SHIFT));
+# else
+ return __syscall_mmap2(addr, len, prot, flags,
+ fd, ((__u_long) offset >> MMAP2_PAGE_SHIFT));
+# endif
}
# endif
diff --git a/libc/sysdeps/linux/common/modify_ldt.c b/libc/sysdeps/linux/common/modify_ldt.c
index 9ebb68b3c..d5f0105dd 100644
--- a/libc/sysdeps/linux/common/modify_ldt.c
+++ b/libc/sysdeps/linux/common/modify_ldt.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
int modify_ldt (int func, void *ptr, unsigned long bytecount);
#ifdef __NR_modify_ldt
diff --git a/libc/sysdeps/linux/common/mount.c b/libc/sysdeps/linux/common/mount.c
index 9cbefe4a8..a5a2c7fec 100644
--- a/libc/sysdeps/linux/common/mount.c
+++ b/libc/sysdeps/linux/common/mount.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/mount.h>
_syscall5(int, mount, const char *, specialfile, const char *, dir,
const char *, filesystemtype, unsigned long, rwflag,
diff --git a/libc/sysdeps/linux/common/mprotect.c b/libc/sysdeps/linux/common/mprotect.c
index 7eab338d0..7122f0f2f 100644
--- a/libc/sysdeps/linux/common/mprotect.c
+++ b/libc/sysdeps/linux/common/mprotect.c
@@ -7,6 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/mman.h>
+
+#if defined __ARCH_USE_MMU__ && defined __NR_mprotect
_syscall3(int, mprotect, void *, addr, size_t, len, int, prot);
+#endif
diff --git a/libc/sysdeps/linux/common/mremap.c b/libc/sysdeps/linux/common/mremap.c
index 5499c0975..04548d5ec 100644
--- a/libc/sysdeps/linux/common/mremap.c
+++ b/libc/sysdeps/linux/common/mremap.c
@@ -7,8 +7,11 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
+
+#ifdef __NR_mremap
+
#define mremap _hidemremap
#include <sys/mman.h>
#undef mremap
@@ -19,3 +22,5 @@ libc_hidden_proto(mremap)
_syscall5(void *, mremap, void *, old_address, size_t, old_size, size_t,
new_size, int, may_move, void *, new_address);
libc_hidden_def(mremap)
+
+#endif
diff --git a/libc/sysdeps/linux/common/msync.c b/libc/sysdeps/linux/common/msync.c
index 8882a4c91..5d8bf73fd 100644
--- a/libc/sysdeps/linux/common/msync.c
+++ b/libc/sysdeps/linux/common/msync.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/mman.h>
diff --git a/libc/sysdeps/linux/common/munlock.c b/libc/sysdeps/linux/common/munlock.c
index 1d6870ecc..e901cc00a 100644
--- a/libc/sysdeps/linux/common/munlock.c
+++ b/libc/sysdeps/linux/common/munlock.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/mman.h>
#if defined __ARCH_USE_MMU__ && defined __NR_munlock
_syscall2(int, munlock, const void *, addr, size_t, len);
diff --git a/libc/sysdeps/linux/common/munlockall.c b/libc/sysdeps/linux/common/munlockall.c
index 4ee729292..39507715a 100644
--- a/libc/sysdeps/linux/common/munlockall.c
+++ b/libc/sysdeps/linux/common/munlockall.c
@@ -7,8 +7,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#if defined __NR_munlockall && defined __ARCH_USE_MMU__
#include <sys/mman.h>
-#if defined __ARCH_USE_MMU__
+
_syscall0(int, munlockall);
#endif
diff --git a/libc/sysdeps/linux/common/munmap.c b/libc/sysdeps/linux/common/munmap.c
index 7a82df632..5c948abfd 100644
--- a/libc/sysdeps/linux/common/munmap.c
+++ b/libc/sysdeps/linux/common/munmap.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/mman.h>
diff --git a/libc/sysdeps/linux/common/nanosleep.c b/libc/sysdeps/linux/common/nanosleep.c
index 1e541500b..7e3349117 100644
--- a/libc/sysdeps/linux/common/nanosleep.c
+++ b/libc/sysdeps/linux/common/nanosleep.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <time.h>
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
diff --git a/libc/sysdeps/linux/common/nice.c b/libc/sysdeps/linux/common/nice.c
index e6e80e7be..393ffef4e 100644
--- a/libc/sysdeps/linux/common/nice.c
+++ b/libc/sysdeps/linux/common/nice.c
@@ -8,7 +8,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/resource.h>
diff --git a/libc/sysdeps/linux/common/open.c b/libc/sysdeps/linux/common/open.c
index 822ac4f63..b4bef3c63 100644
--- a/libc/sysdeps/linux/common/open.c
+++ b/libc/sysdeps/linux/common/open.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
@@ -15,26 +15,25 @@
#include <sys/param.h>
extern __typeof(open) __libc_open;
-libc_hidden_proto(__libc_open)
+extern __typeof(creat) __libc_creat;
#define __NR___syscall_open __NR_open
static inline _syscall3(int, __syscall_open, const char *, file,
int, flags, __kernel_mode_t, mode);
-int __libc_open(const char *file, int flags, ...)
+libc_hidden_proto(__libc_open)
+int __libc_open(const char *file, int oflag, ...)
{
- /* gcc may warn about mode being uninitialized.
- * Just ignore that, since gcc is wrong. */
- mode_t mode;
+ mode_t mode = 0;
- if (flags & O_CREAT) {
- va_list ap;
-
- va_start(ap, flags);
- mode = va_arg(ap, mode_t);
- va_end(ap);
+ if (oflag & O_CREAT) {
+ va_list arg;
+ va_start (arg, oflag);
+ mode = va_arg (arg, mode_t);
+ va_end (arg);
}
- return __syscall_open(file, flags, mode);
+
+ return __syscall_open(file, oflag, mode);
}
libc_hidden_def(__libc_open)
@@ -42,7 +41,8 @@ libc_hidden_proto(open)
weak_alias(__libc_open,open)
libc_hidden_weak(open)
-int creat(const char *file, mode_t mode)
+int __libc_creat(const char *file, mode_t mode)
{
return __libc_open(file, O_WRONLY | O_CREAT | O_TRUNC, mode);
}
+weak_alias(__libc_creat,creat)
diff --git a/libc/sysdeps/linux/common/open64.c b/libc/sysdeps/linux/common/open64.c
index 5c19d63b5..3f2ea344e 100644
--- a/libc/sysdeps/linux/common/open64.c
+++ b/libc/sysdeps/linux/common/open64.c
@@ -24,16 +24,17 @@ libc_hidden_proto(__libc_open)
/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
a third argument is the file protection. */
+libc_hidden_proto(__libc_open64)
int __libc_open64 (const char *file, int oflag, ...)
{
- int mode = 0;
+ mode_t mode = 0;
- if (oflag & O_CREAT)
+ if (oflag & O_CREAT)
{
- va_list arg;
- va_start (arg, oflag);
- mode = va_arg (arg, int);
- va_end (arg);
+ va_list arg;
+ va_start (arg, oflag);
+ mode = va_arg (arg, mode_t);
+ va_end (arg);
}
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
@@ -51,6 +52,8 @@ int __libc_open64 (const char *file, int oflag, ...)
return __libc_open(file, oflag | O_LARGEFILE, mode);
#endif
}
+libc_hidden_def(__libc_open64)
+
libc_hidden_proto(open64)
weak_alias(__libc_open64,open64)
libc_hidden_weak(open64)
diff --git a/libc/sysdeps/linux/common/pause.c b/libc/sysdeps/linux/common/pause.c
index 74115b281..31d3563fb 100644
--- a/libc/sysdeps/linux/common/pause.c
+++ b/libc/sysdeps/linux/common/pause.c
@@ -7,7 +7,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include <signal.h>
+#define __UCLIBC_HIDE_DEPRECATED__
+#include <sys/syscall.h>
#include <unistd.h>
#include <sysdep-cancel.h>
diff --git a/libc/sysdeps/linux/common/personality.c b/libc/sysdeps/linux/common/personality.c
index 39b15007f..149fb5f08 100644
--- a/libc/sysdeps/linux/common/personality.c
+++ b/libc/sysdeps/linux/common/personality.c
@@ -7,6 +7,6 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/personality.h>
_syscall1(int, personality, unsigned long int, __persona);
diff --git a/libc/sysdeps/linux/common/pipe.c b/libc/sysdeps/linux/common/pipe.c
index 02a6975e9..789b23c40 100644
--- a/libc/sysdeps/linux/common/pipe.c
+++ b/libc/sysdeps/linux/common/pipe.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(pipe)
diff --git a/libc/sysdeps/linux/common/pivot_root.c b/libc/sysdeps/linux/common/pivot_root.c
index f5d1f1d7f..154a37e2d 100644
--- a/libc/sysdeps/linux/common/pivot_root.c
+++ b/libc/sysdeps/linux/common/pivot_root.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
int pivot_root(const char *new_root, const char *put_old);
#ifdef __NR_pivot_root
diff --git a/libc/sysdeps/linux/common/poll.c b/libc/sysdeps/linux/common/poll.c
index 7ce1446f5..1267a30d1 100644
--- a/libc/sysdeps/linux/common/poll.c
+++ b/libc/sysdeps/linux/common/poll.c
@@ -17,7 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/poll.h>
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
@@ -56,8 +56,8 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
#include <sys/param.h>
#include <unistd.h>
-libc_hidden_proto(memcpy)
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
libc_hidden_proto(getdtablesize)
libc_hidden_proto(select)
diff --git a/libc/sysdeps/linux/common/posix_fadvise.c b/libc/sysdeps/linux/common/posix_fadvise.c
index 5fba19ffc..45734f9b2 100644
--- a/libc/sysdeps/linux/common/posix_fadvise.c
+++ b/libc/sysdeps/linux/common/posix_fadvise.c
@@ -12,16 +12,32 @@
* will fail when __NR_fadvise64_64 doesnt exist */
#define posix_fadvise64 __hideposix_fadvise64
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <fcntl.h>
#undef posix_fadvise64
#ifdef __NR_fadvise64
#define __NR_posix_fadvise __NR_fadvise64
+/* get rid of following conditional when
+ all supported arches are having INTERNAL_SYSCALL defined
+*/
+#ifdef INTERNAL_SYSCALL
+int posix_fadvise(int fd, off_t offset, off_t len, int advice)
+{
+ INTERNAL_SYSCALL_DECL(err);
+ int ret = (int) (INTERNAL_SYSCALL(posix_fadvise, err, 5, fd,
+ __LONG_LONG_PAIR (offset >> 31, offset), len, advice));
+ if (INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+ return 0;
+}
+#else
_syscall4(int, posix_fadvise, int, fd, off_t, offset,
off_t, len, int, advice);
+#endif
+
#if defined __UCLIBC_HAS_LFS__ && (!defined __NR_fadvise64_64 || !defined _syscall6)
extern __typeof(posix_fadvise) posix_fadvise64;
strong_alias(posix_fadvise,posix_fadvise64)
@@ -30,7 +46,7 @@ strong_alias(posix_fadvise,posix_fadvise64)
#else
int posix_fadvise(int fd attribute_unused, off_t offset attribute_unused, off_t len attribute_unused, int advice attribute_unused)
{
- __set_errno(ENOSYS);
- return -1;
+#warning This is not correct as far as SUSv3 is concerned.
+ return ENOSYS;
}
#endif
diff --git a/libc/sysdeps/linux/common/posix_fadvise64.c b/libc/sysdeps/linux/common/posix_fadvise64.c
index d931aff60..7944c4985 100644
--- a/libc/sysdeps/linux/common/posix_fadvise64.c
+++ b/libc/sysdeps/linux/common/posix_fadvise64.c
@@ -24,8 +24,25 @@
#if __WORDSIZE == 64
#define __NR_posix_fadvise64 __NR_fadvise64_64
+
+#ifdef INTERNAL_SYSCALL
+int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
+{
+ if (len != (off_t) len)
+ return EOVERFLOW;
+ INTERNAL_SYSCALL_DECL (err);
+ int ret = INTERNAL_SYSCALL (posix_fadvise64, err, 5, fd,
+ __LONG_LONG_PAIR ((long) (offset >> 32),
+ (long) offset),
+ (off_t) len, advice);
+ if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
+ return 0;
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+}
+#else
_syscall4(int, posix_fadvise64, int, fd, __off64_t, offset,
__off64_t, len, int, advice);
+#endif
/* 32 bit implementation is kind of a pita */
#elif __WORDSIZE == 32
@@ -57,8 +74,8 @@ int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
*/
int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
{
- __set_errno(ENOSYS);
- return -1;
+#warning This is not correct as far as SUSv3 is concerned.
+ return ENOSYS;
}
#endif /* __NR_fadvise64_64 */
#endif /* __UCLIBC_HAS_LFS__ */
diff --git a/libc/sysdeps/linux/common/prctl.c b/libc/sysdeps/linux/common/prctl.c
index 52d1e76e0..485386727 100644
--- a/libc/sysdeps/linux/common/prctl.c
+++ b/libc/sysdeps/linux/common/prctl.c
@@ -7,8 +7,11 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <stdarg.h>
/* psm: including sys/prctl.h would depend on kernel headers */
+
+#ifdef __NR_prctl
extern int prctl (int, long, long, long, long);
_syscall5(int, prctl, int, option, long, arg2, long, arg3, long, arg4, long, arg5);
+#endif
diff --git a/libc/sysdeps/linux/common/pread_write.c b/libc/sysdeps/linux/common/pread_write.c
index 2509b7ab6..3c0df19a3 100644
--- a/libc/sysdeps/linux/common/pread_write.c
+++ b/libc/sysdeps/linux/common/pread_write.c
@@ -7,15 +7,16 @@
/*
* Based in part on the files
* ./sysdeps/unix/sysv/linux/pwrite.c,
- * ./sysdeps/unix/sysv/linux/pread.c,
+ * ./sysdeps/unix/sysv/linux/pread.c,
* sysdeps/posix/pread.c
* sysdeps/posix/pwrite.c
* from GNU libc 2.2.5, but reworked considerably...
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <stdint.h>
+#include <endian.h>
extern __typeof(pread) __libc_pread;
extern __typeof(pwrite) __libc_pwrite;
@@ -24,24 +25,26 @@ extern __typeof(pread64) __libc_pread64;
extern __typeof(pwrite64) __libc_pwrite64;
#endif
+#include <bits/kernel_types.h>
+
#ifdef __NR_pread
-# define __NR___syscall_pread __NR_pread
-static inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
+# define __NR___syscall_pread __NR_pread
+static inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
size_t, count, off_t, offset_hi, off_t, offset_lo);
ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
-{
- return(__syscall_pread(fd,buf,count,__LONG_LONG_PAIR (offset >> 31, offset)));
+{
+ return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset));
}
weak_alias(__libc_pread,pread)
-# ifdef __UCLIBC_HAS_LFS__
+# ifdef __UCLIBC_HAS_LFS__
ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
-{
+{
uint32_t low = offset & 0xffffffff;
uint32_t high = offset >> 32;
- return(__syscall_pread(fd, buf, count, __LONG_LONG_PAIR (high, low)));
+ return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(high, low));
}
weak_alias(__libc_pread64,pread64)
# endif /* __UCLIBC_HAS_LFS__ */
@@ -50,22 +53,22 @@ weak_alias(__libc_pread64,pread64)
#ifdef __NR_pwrite
-# define __NR___syscall_pwrite __NR_pwrite
-static inline _syscall5(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
+# define __NR___syscall_pwrite __NR_pwrite
+static inline _syscall5(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
size_t, count, off_t, offset_hi, off_t, offset_lo);
ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
-{
- return(__syscall_pwrite(fd,buf,count,__LONG_LONG_PAIR (offset >> 31, offset)));
+{
+ return __syscall_pwrite(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset));
}
weak_alias(__libc_pwrite,pwrite)
-# ifdef __UCLIBC_HAS_LFS__
+# ifdef __UCLIBC_HAS_LFS__
ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
-{
+{
uint32_t low = offset & 0xffffffff;
uint32_t high = offset >> 32;
- return(__syscall_pwrite(fd, buf, count, __LONG_LONG_PAIR (high, low)));
+ return __syscall_pwrite(fd, buf, count, __LONG_LONG_PAIR(high, low));
}
weak_alias(__libc_pwrite64,pwrite64)
# endif /* __UCLIBC_HAS_LFS__ */
@@ -76,23 +79,23 @@ libc_hidden_proto(read)
libc_hidden_proto(write)
libc_hidden_proto(lseek)
-static ssize_t __fake_pread_write(int fd, void *buf,
+static ssize_t __fake_pread_write(int fd, void *buf,
size_t count, off_t offset, int do_pwrite)
{
int save_errno;
ssize_t result;
off_t old_offset;
- /* Since we must not change the file pointer preserve the
+ /* 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)
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) {
+ if (do_pwrite == 1) {
/* Write the data. */
result = write(fd, buf, count);
} else {
@@ -100,7 +103,7 @@ static ssize_t __fake_pread_write(int fd, void *buf,
result = read(fd, buf, count);
}
- /* Now we have to restore the position. If this fails we
+ /* 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)
@@ -113,26 +116,26 @@ static ssize_t __fake_pread_write(int fd, void *buf,
return(result);
}
-# ifdef __UCLIBC_HAS_LFS__
+# ifdef __UCLIBC_HAS_LFS__
libc_hidden_proto(lseek64)
-static ssize_t __fake_pread_write64(int fd, void *buf,
+static ssize_t __fake_pread_write64(int fd, void *buf,
size_t count, off64_t offset, int do_pwrite)
{
int save_errno;
ssize_t result;
off64_t old_offset;
- /* Since we must not change the file pointer preserve the
+ /* 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)
return -1;
/* Set to wanted position. */
- if (lseek64(fd, offset, SEEK_SET) == (off64_t) -1)
- return -1;
+ if (lseek64(fd, offset, SEEK_SET) == (off64_t) -1)
+ return -1;
- if (do_pwrite==1) {
+ if (do_pwrite == 1) {
/* Write the data. */
result = write(fd, buf, count);
} else {
@@ -142,7 +145,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;
@@ -156,14 +159,14 @@ static ssize_t __fake_pread_write64(int fd, void *buf,
#ifndef __NR_pread
ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
{
- return(__fake_pread_write(fd, buf, count, offset, 0));
+ return __fake_pread_write(fd, buf, count, offset, 0);
}
weak_alias(__libc_pread,pread)
-# ifdef __UCLIBC_HAS_LFS__
+# ifdef __UCLIBC_HAS_LFS__
ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
-{
- return(__fake_pread_write64(fd, buf, count, offset, 0));
+{
+ return __fake_pread_write64(fd, buf, count, offset, 0);
}
weak_alias(__libc_pread64,pread64)
# endif /* __UCLIBC_HAS_LFS__ */
@@ -172,16 +175,16 @@ weak_alias(__libc_pread64,pread64)
#ifndef __NR_pwrite
ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
{
- /* we won't actually be modifying the buffer,
+ /* we won't actually be modifying the buffer,
*just cast it to get rid of warnings */
- return(__fake_pread_write(fd, (void*)buf, count, offset, 1));
+ return __fake_pread_write(fd, (void*)buf, count, offset, 1);
}
weak_alias(__libc_pwrite,pwrite)
-# ifdef __UCLIBC_HAS_LFS__
+# ifdef __UCLIBC_HAS_LFS__
ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
-{
- return(__fake_pread_write64(fd, (void*)buf, count, offset, 1));
+{
+ return __fake_pread_write64(fd, (void*)buf, count, offset, 1);
}
weak_alias(__libc_pwrite64,pwrite64)
# endif /* __UCLIBC_HAS_LFS__ */
diff --git a/libc/sysdeps/linux/common/ptrace.c b/libc/sysdeps/linux/common/ptrace.c
index fda2e9d84..9d6767374 100644
--- a/libc/sysdeps/linux/common/ptrace.c
+++ b/libc/sysdeps/linux/common/ptrace.c
@@ -4,15 +4,15 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include <errno.h>
+#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/ptrace.h>
-#include <sys/syscall.h>
#include <stdarg.h>
+#if defined __NR_ptrace && defined __USE_BSD && defined __USE_MISC
#define __NR___syscall_ptrace __NR_ptrace
-static inline _syscall4(long, __syscall_ptrace, enum __ptrace_request, request,
+static inline _syscall4(long, __syscall_ptrace, enum __ptrace_request, request,
__kernel_pid_t, pid, void*, addr, void*, data);
long int
@@ -40,3 +40,4 @@ ptrace (enum __ptrace_request request, ...)
return res;
}
+#endif
diff --git a/libc/sysdeps/linux/common/query_module.c b/libc/sysdeps/linux/common/query_module.c
index ac77f7e18..b0b72dea9 100644
--- a/libc/sysdeps/linux/common/query_module.c
+++ b/libc/sysdeps/linux/common/query_module.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
int query_module(const char *name attribute_unused, int which attribute_unused,
void *buf attribute_unused, size_t bufsize attribute_unused, size_t * ret attribute_unused);
#ifdef __NR_query_module
diff --git a/libc/sysdeps/linux/common/quotactl.c b/libc/sysdeps/linux/common/quotactl.c
index 2982f4956..cb044a4e8 100644
--- a/libc/sysdeps/linux/common/quotactl.c
+++ b/libc/sysdeps/linux/common/quotactl.c
@@ -7,7 +7,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#if defined __USE_BSD
#include <sys/quota.h>
_syscall4(int, quotactl, int, cmd, const char *, special,
int, id, caddr_t, addr);
+#endif
diff --git a/libc/sysdeps/linux/common/read.c b/libc/sysdeps/linux/common/read.c
index 236029ac6..f837e9f07 100644
--- a/libc/sysdeps/linux/common/read.c
+++ b/libc/sysdeps/linux/common/read.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
extern __typeof(read) __libc_read;
diff --git a/libc/sysdeps/linux/common/readlink.c b/libc/sysdeps/linux/common/readlink.c
index 73d5441c0..d68391302 100644
--- a/libc/sysdeps/linux/common/readlink.c
+++ b/libc/sysdeps/linux/common/readlink.c
@@ -2,15 +2,14 @@
/*
* readlink() for uClibc
*
- * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ * Copyright (C) 2000-2007 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(readlink)
-
-_syscall3(int, readlink, const char *, path, char *, buf, size_t, bufsiz);
+_syscall3(ssize_t, readlink, const char *, path, char *, buf, size_t, bufsiz);
libc_hidden_def(readlink)
diff --git a/libc/sysdeps/linux/common/readv.c b/libc/sysdeps/linux/common/readv.c
index ebe73185f..20c87084d 100644
--- a/libc/sysdeps/linux/common/readv.c
+++ b/libc/sysdeps/linux/common/readv.c
@@ -5,10 +5,10 @@
* Copyright (C) 2006 by Steven J. Hill <sjhill@realitydiluted.com>
* Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
*
- * GNU Library General Public License (LGPL) version 2 or later.
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/uio.h>
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
diff --git a/libc/sysdeps/linux/common/reboot.c b/libc/sysdeps/linux/common/reboot.c
index a015d40ad..44828ce64 100644
--- a/libc/sysdeps/linux/common/reboot.c
+++ b/libc/sysdeps/linux/common/reboot.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/reboot.h>
#define __NR__reboot __NR_reboot
static inline _syscall3(int, _reboot, int, magic, int, magic2, int, flag);
diff --git a/libc/sysdeps/linux/common/rename.c b/libc/sysdeps/linux/common/rename.c
index 55de6b1d0..7e88bf346 100644
--- a/libc/sysdeps/linux/common/rename.c
+++ b/libc/sysdeps/linux/common/rename.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <string.h>
#include <sys/param.h>
diff --git a/libc/sysdeps/linux/common/rmdir.c b/libc/sysdeps/linux/common/rmdir.c
index 0aadd73f2..845b3e371 100644
--- a/libc/sysdeps/linux/common/rmdir.c
+++ b/libc/sysdeps/linux/common/rmdir.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(rmdir)
diff --git a/libc/sysdeps/linux/common/sbrk.c b/libc/sysdeps/linux/common/sbrk.c
index f8b568262..734a4ce01 100644
--- a/libc/sysdeps/linux/common/sbrk.c
+++ b/libc/sysdeps/linux/common/sbrk.c
@@ -7,22 +7,21 @@
#include <unistd.h>
#include <errno.h>
-libc_hidden_proto(sbrk)
-
libc_hidden_proto(brk)
/* Defined in brk.c. */
-extern void *__curbrk;
+extern void *__curbrk attribute_hidden;
/* Extend the process's data space by INCREMENT.
If INCREMENT is negative, shrink data space by - INCREMENT.
Return start of new space allocated, or -1 for errors. */
+libc_hidden_proto(sbrk)
void * sbrk (intptr_t increment)
{
void *oldbrk;
if (__curbrk == NULL)
- if (brk (0) < 0) /* Initialize the break. */
+ if (brk (NULL) < 0) /* Initialize the break. */
return (void *) -1;
if (increment == 0)
diff --git a/libc/sysdeps/linux/common/sched_get_priority_max.c b/libc/sysdeps/linux/common/sched_get_priority_max.c
index c9292ffbd..a9ab24639 100644
--- a/libc/sysdeps/linux/common/sched_get_priority_max.c
+++ b/libc/sysdeps/linux/common/sched_get_priority_max.c
@@ -7,6 +7,6 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sched.h>
_syscall1(int, sched_get_priority_max, int, policy);
diff --git a/libc/sysdeps/linux/common/sched_get_priority_min.c b/libc/sysdeps/linux/common/sched_get_priority_min.c
index 317911fc1..5a78f9393 100644
--- a/libc/sysdeps/linux/common/sched_get_priority_min.c
+++ b/libc/sysdeps/linux/common/sched_get_priority_min.c
@@ -7,6 +7,6 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sched.h>
_syscall1(int, sched_get_priority_min, int, policy);
diff --git a/libc/sysdeps/linux/common/sched_getparam.c b/libc/sysdeps/linux/common/sched_getparam.c
index d9b3dcde5..117c6baa2 100644
--- a/libc/sysdeps/linux/common/sched_getparam.c
+++ b/libc/sysdeps/linux/common/sched_getparam.c
@@ -7,8 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
#include <sched.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
#define __NR___syscall_sched_getparam __NR_sched_getparam
static inline _syscall2(int, __syscall_sched_getparam,
diff --git a/libc/sysdeps/linux/common/sched_getscheduler.c b/libc/sysdeps/linux/common/sched_getscheduler.c
index 13df2aefd..89ecdf911 100644
--- a/libc/sysdeps/linux/common/sched_getscheduler.c
+++ b/libc/sysdeps/linux/common/sched_getscheduler.c
@@ -7,8 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
#include <sched.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
#define __NR___syscall_sched_getscheduler __NR_sched_getscheduler
static inline _syscall1(int, __syscall_sched_getscheduler, __kernel_pid_t, pid);
diff --git a/libc/sysdeps/linux/common/sched_rr_get_interval.c b/libc/sysdeps/linux/common/sched_rr_get_interval.c
index 0eb25016e..a87d27fd2 100644
--- a/libc/sysdeps/linux/common/sched_rr_get_interval.c
+++ b/libc/sysdeps/linux/common/sched_rr_get_interval.c
@@ -7,8 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
#include <sched.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
#define __NR___syscall_sched_rr_get_interval __NR_sched_rr_get_interval
static inline _syscall2(int, __syscall_sched_rr_get_interval,
diff --git a/libc/sysdeps/linux/common/sched_setparam.c b/libc/sysdeps/linux/common/sched_setparam.c
index a0ff56840..94a3cee54 100644
--- a/libc/sysdeps/linux/common/sched_setparam.c
+++ b/libc/sysdeps/linux/common/sched_setparam.c
@@ -7,8 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
#include <sched.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
#define __NR___syscall_sched_setparam __NR_sched_setparam
static inline _syscall2(int, __syscall_sched_setparam,
diff --git a/libc/sysdeps/linux/common/sched_setscheduler.c b/libc/sysdeps/linux/common/sched_setscheduler.c
index 14236e927..05ada79e5 100644
--- a/libc/sysdeps/linux/common/sched_setscheduler.c
+++ b/libc/sysdeps/linux/common/sched_setscheduler.c
@@ -7,8 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
#include <sched.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
#define __NR___syscall_sched_setscheduler __NR_sched_setscheduler
static inline _syscall3(int, __syscall_sched_setscheduler,
diff --git a/libc/sysdeps/linux/common/sched_yield.c b/libc/sysdeps/linux/common/sched_yield.c
index 3953d8d16..2ae5396c9 100644
--- a/libc/sysdeps/linux/common/sched_yield.c
+++ b/libc/sysdeps/linux/common/sched_yield.c
@@ -7,6 +7,6 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sched.h>
_syscall0(int, sched_yield);
diff --git a/libc/sysdeps/linux/common/select.c b/libc/sysdeps/linux/common/select.c
index 55f4c23fb..34b6e8260 100644
--- a/libc/sysdeps/linux/common/select.c
+++ b/libc/sysdeps/linux/common/select.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/select.h>
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
diff --git a/libc/sysdeps/linux/common/sendfile.c b/libc/sysdeps/linux/common/sendfile.c
index af19617bb..18427e85b 100644
--- a/libc/sysdeps/linux/common/sendfile.c
+++ b/libc/sysdeps/linux/common/sendfile.c
@@ -11,15 +11,19 @@
* will fail when __NR_sendfile64 doesnt exist */
#define sendfile64 __hidesendfile64
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/sendfile.h>
#undef sendfile64
+#ifdef __NR_sendfile
+
_syscall4(ssize_t, sendfile, int, out_fd, int, in_fd, __off_t *, offset,
size_t, count);
#if ! defined __NR_sendfile64 && defined __UCLIBC_HAS_LFS__
strong_alias(sendfile,sendfile64)
#endif
+
+#endif /* __NR_sendfile */
diff --git a/libc/sysdeps/linux/common/setdomainname.c b/libc/sysdeps/linux/common/setdomainname.c
index 3b9f535e5..e134b0d45 100644
--- a/libc/sysdeps/linux/common/setdomainname.c
+++ b/libc/sysdeps/linux/common/setdomainname.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
_syscall2(int, setdomainname, const char *, name, size_t, len);
diff --git a/libc/sysdeps/linux/common/seteuid.c b/libc/sysdeps/linux/common/seteuid.c
index 35a68334d..5a6e9a25a 100644
--- a/libc/sysdeps/linux/common/seteuid.c
+++ b/libc/sysdeps/linux/common/seteuid.c
@@ -11,6 +11,11 @@
#include <sys/types.h>
#include <sys/syscall.h>
+#if !defined __UCLIBC_LINUX_SPECIFIC__
+#undef __NR_setresuid
+#undef __NR_setresuid32
+#endif
+
libc_hidden_proto(seteuid)
#if (defined __NR_setresuid || defined __NR_setresuid32) && defined __USE_GNU
diff --git a/libc/sysdeps/linux/common/setfsgid.c b/libc/sysdeps/linux/common/setfsgid.c
index 027dd11f6..b35006306 100644
--- a/libc/sysdeps/linux/common/setfsgid.c
+++ b/libc/sysdeps/linux/common/setfsgid.c
@@ -7,10 +7,21 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/fsuid.h>
+#include <bits/wordsize.h>
-#define __NR___syscall_setfsgid __NR_setfsgid
+#if (__WORDSIZE == 32 && defined(__NR_setfsgid32)) || __WORDSIZE == 64
+# ifdef __NR_setfsgid32
+# undef __NR_setfsgid
+# define __NR_setfsgid __NR_setfsgid32
+# endif
+
+_syscall1(int, setfsgid, gid_t, gid);
+
+#else
+
+# define __NR___syscall_setfsgid __NR_setfsgid
static inline _syscall1(int, __syscall_setfsgid, __kernel_gid_t, gid);
int setfsgid(gid_t gid)
@@ -21,3 +32,4 @@ int setfsgid(gid_t gid)
}
return (__syscall_setfsgid(gid));
}
+#endif
diff --git a/libc/sysdeps/linux/common/setfsuid.c b/libc/sysdeps/linux/common/setfsuid.c
index 4bbc931cf..d302ad48c 100644
--- a/libc/sysdeps/linux/common/setfsuid.c
+++ b/libc/sysdeps/linux/common/setfsuid.c
@@ -7,10 +7,21 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/fsuid.h>
+#include <bits/wordsize.h>
-#define __NR___syscall_setfsuid __NR_setfsuid
+#if (__WORDSIZE == 32 && defined(__NR_setfsuid32)) || __WORDSIZE == 64
+# ifdef __NR_setfsuid32
+# undef __NR_setfsuid
+# define __NR_setfsuid __NR_setfsuid32
+# endif
+
+_syscall1(int, setfsuid, uid_t, uid);
+
+#else
+
+# define __NR___syscall_setfsuid __NR_setfsuid
static inline _syscall1(int, __syscall_setfsuid, __kernel_uid_t, uid);
int setfsuid(uid_t uid)
@@ -21,3 +32,4 @@ int setfsuid(uid_t uid)
}
return (__syscall_setfsuid(uid));
}
+#endif
diff --git a/libc/sysdeps/linux/common/setgid.c b/libc/sysdeps/linux/common/setgid.c
index d0698f517..4a924a047 100644
--- a/libc/sysdeps/linux/common/setgid.c
+++ b/libc/sysdeps/linux/common/setgid.c
@@ -7,10 +7,21 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
+#include <bits/wordsize.h>
-#define __NR___syscall_setgid __NR_setgid
+#if (__WORDSIZE == 32 && defined(__NR_setgid32)) || __WORDSIZE == 64
+# ifdef __NR_setgid32
+# undef __NR_setgid
+# define __NR_setgid __NR_setgid32
+# endif
+
+_syscall1(int, setgid, gid_t, gid);
+
+#else
+
+# define __NR___syscall_setgid __NR_setgid
static inline _syscall1(int, __syscall_setgid, __kernel_gid_t, gid);
int setgid(gid_t gid)
@@ -21,3 +32,4 @@ int setgid(gid_t gid)
}
return (__syscall_setgid(gid));
}
+#endif
diff --git a/libc/sysdeps/linux/common/setgroups.c b/libc/sysdeps/linux/common/setgroups.c
index 49f3dc61f..eb5245d59 100644
--- a/libc/sysdeps/linux/common/setgroups.c
+++ b/libc/sysdeps/linux/common/setgroups.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <stdlib.h>
#include <unistd.h>
#include <grp.h>
@@ -56,8 +56,7 @@ ret_error:
}
i = __syscall_setgroups(size, kernel_groups);
- if (kernel_groups)
- free(kernel_groups);
+ free(kernel_groups);
return i;
}
}
diff --git a/libc/sysdeps/linux/common/sethostname.c b/libc/sysdeps/linux/common/sethostname.c
index 62867fc16..6bd4c2362 100644
--- a/libc/sysdeps/linux/common/sethostname.c
+++ b/libc/sysdeps/linux/common/sethostname.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
_syscall2(int, sethostname, const char *, name, size_t, len);
diff --git a/libc/sysdeps/linux/common/setitimer.c b/libc/sysdeps/linux/common/setitimer.c
index fb6c6b1e6..ca9db82d2 100644
--- a/libc/sysdeps/linux/common/setitimer.c
+++ b/libc/sysdeps/linux/common/setitimer.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/time.h>
libc_hidden_proto(setitimer)
diff --git a/libc/sysdeps/linux/common/setpgid.c b/libc/sysdeps/linux/common/setpgid.c
index 98289ff72..3447b999d 100644
--- a/libc/sysdeps/linux/common/setpgid.c
+++ b/libc/sysdeps/linux/common/setpgid.c
@@ -7,7 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#if defined __USE_UNIX98 || defined __USE_SVID
#include <unistd.h>
libc_hidden_proto(setpgid)
@@ -21,3 +23,4 @@ int setpgid(pid_t pid, pid_t pgid)
return (__syscall_setpgid(pid, pgid));
}
libc_hidden_def(setpgid)
+#endif
diff --git a/libc/sysdeps/linux/common/setpriority.c b/libc/sysdeps/linux/common/setpriority.c
index d836153d5..6674494ab 100644
--- a/libc/sysdeps/linux/common/setpriority.c
+++ b/libc/sysdeps/linux/common/setpriority.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/resource.h>
libc_hidden_proto(setpriority)
diff --git a/libc/sysdeps/linux/common/setregid.c b/libc/sysdeps/linux/common/setregid.c
index a085ed2ab..d56c01f64 100644
--- a/libc/sysdeps/linux/common/setregid.c
+++ b/libc/sysdeps/linux/common/setregid.c
@@ -7,12 +7,23 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
+#include <bits/wordsize.h>
libc_hidden_proto(setregid)
-#define __NR___syscall_setregid __NR_setregid
+#if (__WORDSIZE == 32 && defined(__NR_setregid32)) || __WORDSIZE == 64
+# ifdef __NR_setregid32
+# undef __NR_setregid
+# define __NR_setregid __NR_setregid32
+# endif
+
+_syscall2(int, setregid, gid_t, rgid, gid_t, egid);
+
+#else
+
+# define __NR___syscall_setregid __NR_setregid
static inline _syscall2(int, __syscall_setregid,
__kernel_gid_t, rgid, __kernel_gid_t, egid);
@@ -25,4 +36,6 @@ int setregid(gid_t rgid, gid_t egid)
}
return (__syscall_setregid(rgid, egid));
}
+#endif
+
libc_hidden_def(setregid)
diff --git a/libc/sysdeps/linux/common/setresgid.c b/libc/sysdeps/linux/common/setresgid.c
index 07959e4af..3bb54e3aa 100644
--- a/libc/sysdeps/linux/common/setresgid.c
+++ b/libc/sysdeps/linux/common/setresgid.c
@@ -7,22 +7,25 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#ifdef __USE_GNU
#include <unistd.h>
-libc_hidden_proto(setresgid)
-
#if defined(__NR_setresgid32)
# undef __NR_setresgid
# define __NR_setresgid __NR_setresgid32
+
+libc_hidden_proto(setresgid)
_syscall3(int, setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
+libc_hidden_def(setresgid)
#elif defined(__NR_setresgid)
+
# define __NR___syscall_setresgid __NR_setresgid
static inline _syscall3(int, __syscall_setresgid,
__kernel_gid_t, rgid, __kernel_gid_t, egid, __kernel_gid_t, sgid);
+libc_hidden_proto(setresgid)
int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
{
if (((rgid + 1) > (gid_t) ((__kernel_gid_t) - 1U))
@@ -33,7 +36,8 @@ int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
}
return (__syscall_setresgid(rgid, egid, sgid));
}
+libc_hidden_def(setresgid)
+
#endif
-libc_hidden_def(setresgid)
#endif
diff --git a/libc/sysdeps/linux/common/setresuid.c b/libc/sysdeps/linux/common/setresuid.c
index 1249611a9..54b92465c 100644
--- a/libc/sysdeps/linux/common/setresuid.c
+++ b/libc/sysdeps/linux/common/setresuid.c
@@ -7,22 +7,25 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
-#ifdef __USE_GNU
+#include <sys/syscall.h>
+#if defined __USE_GNU && defined __UCLIBC_LINUX_SPECIFIC__
#include <unistd.h>
-libc_hidden_proto(setresuid)
-
#if defined(__NR_setresuid32)
# undef __NR_setresuid
# define __NR_setresuid __NR_setresuid32
+
+libc_hidden_proto(setresuid)
_syscall3(int, setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
+libc_hidden_def(setresuid)
#elif defined(__NR_setresuid)
+
# define __NR___syscall_setresuid __NR_setresuid
static inline _syscall3(int, __syscall_setresuid,
__kernel_uid_t, rgid, __kernel_uid_t, egid, __kernel_uid_t, sgid);
+libc_hidden_proto(setresuid)
int setresuid(uid_t ruid, uid_t euid, uid_t suid)
{
if (((ruid + 1) > (uid_t) ((__kernel_uid_t) - 1U))
@@ -33,7 +36,8 @@ int setresuid(uid_t ruid, uid_t euid, uid_t suid)
}
return (__syscall_setresuid(ruid, euid, suid));
}
+libc_hidden_def(setresuid)
+
#endif
-libc_hidden_def(setresuid)
#endif
diff --git a/libc/sysdeps/linux/common/setreuid.c b/libc/sysdeps/linux/common/setreuid.c
index dcbe4adfe..7f908a333 100644
--- a/libc/sysdeps/linux/common/setreuid.c
+++ b/libc/sysdeps/linux/common/setreuid.c
@@ -7,12 +7,23 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
+#include <bits/wordsize.h>
libc_hidden_proto(setreuid)
-#define __NR___syscall_setreuid __NR_setreuid
+#if (__WORDSIZE == 32 && defined(__NR_setreuid32)) || __WORDSIZE == 64
+# ifdef __NR_setreuid32
+# undef __NR_setreuid
+# define __NR_setreuid __NR_setreuid32
+# endif
+
+_syscall2(int, setreuid, uid_t, ruid, uid_t, euid);
+
+#else
+
+# define __NR___syscall_setreuid __NR_setreuid
static inline _syscall2(int, __syscall_setreuid,
__kernel_uid_t, ruid, __kernel_uid_t, euid);
@@ -25,4 +36,6 @@ int setreuid(uid_t ruid, uid_t euid)
}
return (__syscall_setreuid(ruid, euid));
}
+#endif
+
libc_hidden_def(setreuid)
diff --git a/libc/sysdeps/linux/common/setrlimit.c b/libc/sysdeps/linux/common/setrlimit.c
index ba2ea0728..ce9fe2275 100644
--- a/libc/sysdeps/linux/common/setrlimit.c
+++ b/libc/sysdeps/linux/common/setrlimit.c
@@ -8,7 +8,7 @@
*/
#define setrlimit64 __hide_setrlimit64
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/resource.h>
#undef setrlimit64
diff --git a/libc/sysdeps/linux/common/setsid.c b/libc/sysdeps/linux/common/setsid.c
index 042ee43a4..7e5bd33a4 100644
--- a/libc/sysdeps/linux/common/setsid.c
+++ b/libc/sysdeps/linux/common/setsid.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(setsid)
diff --git a/libc/sysdeps/linux/common/settimeofday.c b/libc/sysdeps/linux/common/settimeofday.c
index a0ae95fa5..7f7c24d26 100644
--- a/libc/sysdeps/linux/common/settimeofday.c
+++ b/libc/sysdeps/linux/common/settimeofday.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/time.h>
#ifdef __USE_BSD
diff --git a/libc/sysdeps/linux/common/setuid.c b/libc/sysdeps/linux/common/setuid.c
index b4b2e1bd1..4036a3d09 100644
--- a/libc/sysdeps/linux/common/setuid.c
+++ b/libc/sysdeps/linux/common/setuid.c
@@ -7,10 +7,21 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
+#include <bits/wordsize.h>
-#define __NR___syscall_setuid __NR_setuid
+#if (__WORDSIZE == 32 && defined(__NR_setuid32)) || __WORDSIZE == 64
+# ifdef __NR_setuid32
+# undef __NR_setuid
+# define __NR_setuid __NR_setuid32
+# endif
+
+_syscall1(int, setuid, uid_t, uid);
+
+#else
+
+# define __NR___syscall_setuid __NR_setuid
static inline _syscall1(int, __syscall_setuid, __kernel_uid_t, uid);
int setuid(uid_t uid)
@@ -21,3 +32,4 @@ int setuid(uid_t uid)
}
return (__syscall_setuid(uid));
}
+#endif
diff --git a/libc/sysdeps/linux/common/sigaltstack.c b/libc/sysdeps/linux/common/sigaltstack.c
index af087ae57..0c9308408 100644
--- a/libc/sysdeps/linux/common/sigaltstack.c
+++ b/libc/sysdeps/linux/common/sigaltstack.c
@@ -7,7 +7,11 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <signal.h>
+
+#if defined __NR_sigaltstack && (defined __USE_BSD || defined __USE_UNIX98)
+
_syscall2(int, sigaltstack, const struct sigaltstack *, ss,
struct sigaltstack *, oss);
+#endif
diff --git a/libc/sysdeps/linux/common/sigpending.c b/libc/sysdeps/linux/common/sigpending.c
index ea8fc40e6..fa272c0f5 100644
--- a/libc/sysdeps/linux/common/sigpending.c
+++ b/libc/sysdeps/linux/common/sigpending.c
@@ -7,7 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#if defined __USE_POSIX
#include <signal.h>
#undef sigpending
@@ -22,3 +24,4 @@ int sigpending(sigset_t * set)
#else
_syscall1(int, sigpending, sigset_t *, set);
#endif
+#endif
diff --git a/libc/sysdeps/linux/common/sigprocmask.c b/libc/sysdeps/linux/common/sigprocmask.c
index 58be06ea1..ac68b3a53 100644
--- a/libc/sysdeps/linux/common/sigprocmask.c
+++ b/libc/sysdeps/linux/common/sigprocmask.c
@@ -2,13 +2,14 @@
/*
* sigprocmask() for uClibc
*
- * Copyright (C) 2006 by Steven J. Hill <sjhill@uclibc.org>
- * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
*
- * GNU Library General Public License (LGPL) version 2 or later.
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#if defined __USE_POSIX
#include <signal.h>
#undef sigprocmask
@@ -17,7 +18,7 @@ libc_hidden_proto(sigprocmask)
#ifdef __NR_rt_sigprocmask
-#define __NR___rt_sigprocmask __NR_rt_sigprocmask
+# define __NR___rt_sigprocmask __NR_rt_sigprocmask
static inline
_syscall4(int, __rt_sigprocmask, int, how, const sigset_t *, set,
sigset_t *, oldset, size_t, size);
@@ -52,7 +53,7 @@ int sigprocmask(int how, const sigset_t * set, sigset_t * oldset)
#else
-#define __NR___syscall_sigprocmask __NR_sigprocmask
+# define __NR___syscall_sigprocmask __NR_sigprocmask
static inline
_syscall3(int, __syscall_sigprocmask, int, how, const sigset_t *, set,
sigset_t *, oldset);
@@ -85,3 +86,4 @@ int sigprocmask(int how, const sigset_t * set, sigset_t * oldset)
}
#endif
libc_hidden_def(sigprocmask)
+#endif
diff --git a/libc/sysdeps/linux/common/sigqueue.c b/libc/sysdeps/linux/common/sigqueue.c
index 3d86414d9..5d8e852fe 100644
--- a/libc/sysdeps/linux/common/sigqueue.c
+++ b/libc/sysdeps/linux/common/sigqueue.c
@@ -22,10 +22,11 @@
#include <string.h>
#include <sys/syscall.h>
+#if defined __USE_POSIX199309
libc_hidden_proto(getpid)
libc_hidden_proto(getuid)
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
#ifdef __NR_rt_sigqueueinfo
@@ -51,3 +52,4 @@ int sigqueue (pid_t pid, int sig, const union sigval val)
}
#endif
+#endif
diff --git a/libc/sysdeps/linux/common/sigsuspend.c b/libc/sysdeps/linux/common/sigsuspend.c
index 0e0df6c61..b69431be9 100644
--- a/libc/sysdeps/linux/common/sigsuspend.c
+++ b/libc/sysdeps/linux/common/sigsuspend.c
@@ -2,13 +2,14 @@
/*
* sigsuspend() for uClibc
*
- * Copyright (C) 2006 by Steven J. Hill <sjhill@realitydiluted.com>
- * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#if defined __USE_POSIX
#include <signal.h>
#undef sigsuspend
@@ -55,3 +56,4 @@ int sigsuspend(const sigset_t * set)
}
#endif
libc_hidden_def(sigsuspend)
+#endif
diff --git a/libc/sysdeps/linux/common/ssp.c b/libc/sysdeps/linux/common/ssp.c
index 16b9f9c10..d8088ef60 100644
--- a/libc/sysdeps/linux/common/ssp.c
+++ b/libc/sysdeps/linux/common/ssp.c
@@ -31,8 +31,8 @@
#include <signal.h>
#include <sys/syslog.h>
-libc_hidden_proto(memset)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(sigaction)
libc_hidden_proto(sigfillset)
libc_hidden_proto(sigdelset)
diff --git a/libc/sysdeps/linux/common/stat.c b/libc/sysdeps/linux/common/stat.c
index 662ed665a..bbb070dbe 100644
--- a/libc/sysdeps/linux/common/stat.c
+++ b/libc/sysdeps/linux/common/stat.c
@@ -11,7 +11,7 @@
* will fail when __NR_stat64 doesnt exist */
#define stat64 __hidestat64
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/stat.h>
#include "xstatconv.h"
diff --git a/libc/sysdeps/linux/common/stat64.c b/libc/sysdeps/linux/common/stat64.c
index 54e2b436e..1ef39de4a 100644
--- a/libc/sysdeps/linux/common/stat64.c
+++ b/libc/sysdeps/linux/common/stat64.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/stat.h>
#if defined __UCLIBC_HAS_LFS__ && defined __NR_stat64
diff --git a/libc/sysdeps/linux/common/statfs.c b/libc/sysdeps/linux/common/statfs.c
index 5da94d6f2..38c277fad 100644
--- a/libc/sysdeps/linux/common/statfs.c
+++ b/libc/sysdeps/linux/common/statfs.c
@@ -7,11 +7,19 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <string.h>
#include <sys/param.h>
#include <sys/vfs.h>
+extern __typeof(statfs) __libc_statfs;
+libc_hidden_proto(__libc_statfs)
+#define __NR___libc_statfs __NR_statfs
+_syscall2(int, __libc_statfs, const char *, path, struct statfs *, buf);
+libc_hidden_def(__libc_statfs)
+
+#if defined __UCLIBC_LINUX_SPECIFIC__
libc_hidden_proto(statfs)
-_syscall2(int, statfs, const char *, path, struct statfs *, buf);
-libc_hidden_def(statfs)
+weak_alias(__libc_statfs,statfs)
+libc_hidden_weak(statfs)
+#endif
diff --git a/libc/sysdeps/linux/common/stime.c b/libc/sysdeps/linux/common/stime.c
index 387122ff3..af8595533 100644
--- a/libc/sysdeps/linux/common/stime.c
+++ b/libc/sysdeps/linux/common/stime.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <time.h>
#include <sys/time.h>
diff --git a/libc/sysdeps/linux/common/swapoff.c b/libc/sysdeps/linux/common/swapoff.c
index 60df6e473..a0de283ed 100644
--- a/libc/sysdeps/linux/common/swapoff.c
+++ b/libc/sysdeps/linux/common/swapoff.c
@@ -7,6 +7,11 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#ifdef __NR_swapoff
+
#include <sys/swap.h>
_syscall1(int, swapoff, const char *, path);
+
+#endif
diff --git a/libc/sysdeps/linux/common/swapon.c b/libc/sysdeps/linux/common/swapon.c
index d5a5c235a..e9ffb6347 100644
--- a/libc/sysdeps/linux/common/swapon.c
+++ b/libc/sysdeps/linux/common/swapon.c
@@ -7,6 +7,11 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#ifdef __NR_swapon
+
#include <sys/swap.h>
_syscall2(int, swapon, const char *, path, int, swapflags);
+
+#endif
diff --git a/libc/sysdeps/linux/common/symlink.c b/libc/sysdeps/linux/common/symlink.c
index 3c8c39751..97f34eb8f 100644
--- a/libc/sysdeps/linux/common/symlink.c
+++ b/libc/sysdeps/linux/common/symlink.c
@@ -7,6 +7,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+#if defined __USE_BSD || defined __USE_UNIX98 || defined __USE_XOPEN2K
#include <unistd.h>
_syscall2(int, symlink, const char *, oldpath, const char *, newpath);
+#endif
diff --git a/libc/sysdeps/linux/common/sync.c b/libc/sysdeps/linux/common/sync.c
index 48fac63ea..dd69e335b 100644
--- a/libc/sysdeps/linux/common/sync.c
+++ b/libc/sysdeps/linux/common/sync.c
@@ -7,10 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include <features.h>
-#include <errno.h>
-#include <sys/types.h>
#include <sys/syscall.h>
+# if defined __USE_BSD || defined __USE_UNIX98
+#include <sys/types.h>
#include <unistd.h>
#ifndef INLINE_SYSCALL
@@ -23,4 +22,4 @@ void sync(void)
{
INLINE_SYSCALL(sync, 0);
}
-
+#endif
diff --git a/libc/sysdeps/linux/common/syscalls.h b/libc/sysdeps/linux/common/syscalls.h
index af015246a..c4f6a44fd 100644
--- a/libc/sysdeps/linux/common/syscalls.h
+++ b/libc/sysdeps/linux/common/syscalls.h
@@ -21,3 +21,4 @@
# undef __USE_FILE_OFFSET64
#endif
+#include <bits/kernel_types.h>
diff --git a/libc/sysdeps/linux/common/sysctl.c b/libc/sysdeps/linux/common/sysctl.c
index 0d6f49185..adee22837 100644
--- a/libc/sysdeps/linux/common/sysctl.c
+++ b/libc/sysdeps/linux/common/sysctl.c
@@ -7,7 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+#if defined __NR__sysctl && (defined __USE_GNU || defined __USE_BSD)
+
/* psm: including sys/sysctl.h would depend on kernel headers */
extern int sysctl (int *__name, int __nlen, void *__oldval,
size_t *__oldlenp, void *__newval, size_t __newlen) __THROW;
@@ -29,13 +31,14 @@ int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp,
void *newval, size_t newlen)
{
struct __sysctl_args args = {
- name:name,
- nlen:nlen,
- oldval:oldval,
- oldlenp:oldlenp,
- newval:newval,
- newlen:newlen
+ .name = name,
+ .nlen = nlen,
+ .oldval = oldval,
+ .oldlenp = oldlenp,
+ .newval = newval,
+ .newlen = newlen
};
return _sysctl(&args);
}
+#endif
diff --git a/libc/sysdeps/linux/common/sysfs.c b/libc/sysdeps/linux/common/sysfs.c
index e3cf0f15b..a4292f768 100644
--- a/libc/sysdeps/linux/common/sysfs.c
+++ b/libc/sysdeps/linux/common/sysfs.c
@@ -9,8 +9,9 @@
/* libc isn't really supposed to export this */
#if 0
+#include <sys/syscall.h>
-#include "syscalls.h"
+#if defined __USE_SVID
_syscall3(int, sysfs, int, option, unsigned int, index, char, addr);
-
+#endif
#endif
diff --git a/libc/sysdeps/linux/common/sysinfo.c b/libc/sysdeps/linux/common/sysinfo.c
index 67673a290..78bf75150 100644
--- a/libc/sysdeps/linux/common/sysinfo.c
+++ b/libc/sysdeps/linux/common/sysinfo.c
@@ -7,6 +7,6 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/sysinfo.h>
_syscall1(int, sysinfo, struct sysinfo *, info);
diff --git a/libc/sysdeps/linux/common/time.c b/libc/sysdeps/linux/common/time.c
index 405954aa3..a7aa153d4 100644
--- a/libc/sysdeps/linux/common/time.c
+++ b/libc/sysdeps/linux/common/time.c
@@ -7,11 +7,11 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <time.h>
#include <sys/time.h>
-libc_hidden_proto(time)
+/* Experimentally off - libc_hidden_proto(time) */
#ifdef __NR_time
_syscall1(time_t, time, time_t *, t);
diff --git a/libc/sysdeps/linux/common/times.c b/libc/sysdeps/linux/common/times.c
index 178a73fa9..a68a2981f 100644
--- a/libc/sysdeps/linux/common/times.c
+++ b/libc/sysdeps/linux/common/times.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/times.h>
libc_hidden_proto(times)
diff --git a/libc/sysdeps/linux/common/truncate.c b/libc/sysdeps/linux/common/truncate.c
index 08c71fc71..5ae8749ed 100644
--- a/libc/sysdeps/linux/common/truncate.c
+++ b/libc/sysdeps/linux/common/truncate.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(truncate)
diff --git a/libc/sysdeps/linux/common/truncate64.c b/libc/sysdeps/linux/common/truncate64.c
index e227900c5..53c46fc56 100644
--- a/libc/sysdeps/linux/common/truncate64.c
+++ b/libc/sysdeps/linux/common/truncate64.c
@@ -57,7 +57,7 @@ int truncate64 (const char * path, __off64_t length)
}
#else /* __WORDSIZE */
-#error Your machine is not 64 bit or 32 bit, I am dazed and confused.
+#error Your machine is not 64 bit nor 32 bit, I am dazed and confused.
#endif /* __WORDSIZE */
#else /* __NR_truncate64 */
diff --git a/libc/sysdeps/linux/common/ulimit.c b/libc/sysdeps/linux/common/ulimit.c
index 6f0278f60..2a1c88081 100644
--- a/libc/sysdeps/linux/common/ulimit.c
+++ b/libc/sysdeps/linux/common/ulimit.c
@@ -5,7 +5,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#ifdef __NR_ulimit
diff --git a/libc/sysdeps/linux/common/umask.c b/libc/sysdeps/linux/common/umask.c
index 20fb12385..24297e07e 100644
--- a/libc/sysdeps/linux/common/umask.c
+++ b/libc/sysdeps/linux/common/umask.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/stat.h>
#define __NR___syscall_umask __NR_umask
diff --git a/libc/sysdeps/linux/common/umount.c b/libc/sysdeps/linux/common/umount.c
index 550003d1b..c62f9fb7c 100644
--- a/libc/sysdeps/linux/common/umount.c
+++ b/libc/sysdeps/linux/common/umount.c
@@ -7,7 +7,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+
+#if defined __USE_GNU
#include <sys/mount.h>
/* arch provides umount() syscall */
@@ -36,3 +38,4 @@ int umount(const char *special_file)
}
#endif
+#endif
diff --git a/libc/sysdeps/linux/common/umount2.c b/libc/sysdeps/linux/common/umount2.c
index b68c4da9c..25c24d450 100644
--- a/libc/sysdeps/linux/common/umount2.c
+++ b/libc/sysdeps/linux/common/umount2.c
@@ -7,9 +7,11 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
-#ifdef __NR_umount2 /* Old kernels don't have umount2 */
+#include <sys/syscall.h>
+
+#if defined __USE_GNU
#include <sys/mount.h>
+#ifdef __NR_umount2 /* Old kernels don't have umount2 */
_syscall2(int, umount2, const char *, special_file, int, flags);
#else
int umount2(const char *special_file, int flags)
@@ -18,3 +20,4 @@ int umount2(const char *special_file, int flags)
return -1;
}
#endif
+#endif
diff --git a/libc/sysdeps/linux/common/uname.c b/libc/sysdeps/linux/common/uname.c
index 8c51f1f76..22b870370 100644
--- a/libc/sysdeps/linux/common/uname.c
+++ b/libc/sysdeps/linux/common/uname.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/utsname.h>
libc_hidden_proto(uname)
diff --git a/libc/sysdeps/linux/common/unlink.c b/libc/sysdeps/linux/common/unlink.c
index 1ecefd70d..313be9e0b 100644
--- a/libc/sysdeps/linux/common/unlink.c
+++ b/libc/sysdeps/linux/common/unlink.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
libc_hidden_proto(unlink)
diff --git a/libc/sysdeps/linux/common/uselib.c b/libc/sysdeps/linux/common/uselib.c
index 3ccde1de4..ffc5d77a1 100644
--- a/libc/sysdeps/linux/common/uselib.c
+++ b/libc/sysdeps/linux/common/uselib.c
@@ -6,10 +6,13 @@
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
+#if 0
+linux specific and we do not use it in uClibc.
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#ifdef __NR_uselib
int uselib (const char *library);
_syscall1(int, uselib, const char *, library);
#endif
+#endif
diff --git a/libc/sysdeps/linux/common/ustat.c b/libc/sysdeps/linux/common/ustat.c
index 73e74e8e1..27cfa95ad 100644
--- a/libc/sysdeps/linux/common/ustat.c
+++ b/libc/sysdeps/linux/common/ustat.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/ustat.h>
#include <sys/sysmacros.h>
diff --git a/libc/sysdeps/linux/common/utime.c b/libc/sysdeps/linux/common/utime.c
index 5d289aede..6e35be2c1 100644
--- a/libc/sysdeps/linux/common/utime.c
+++ b/libc/sysdeps/linux/common/utime.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <utime.h>
libc_hidden_proto(utime)
@@ -30,13 +30,8 @@ int utime(const char *file, const struct utimbuf *times)
timevals[1].tv_usec = 0L;
timevals[0].tv_sec = (long int) times->actime;
timevals[1].tv_sec = (long int) times->modtime;
- } else {
- if (gettimeofday(&timevals[0], NULL) < 0) {
- return -1;
- }
- timevals[1] = timevals[0];
}
- return utimes(file, timevals);
+ return utimes(file, times ? timevals : NULL);
}
#endif
libc_hidden_def(utime)
diff --git a/libc/sysdeps/linux/common/utimes.c b/libc/sysdeps/linux/common/utimes.c
index 55f60d8c1..83ddb7381 100644
--- a/libc/sysdeps/linux/common/utimes.c
+++ b/libc/sysdeps/linux/common/utimes.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <utime.h>
#include <sys/time.h>
@@ -35,4 +35,5 @@ int utimes(const char *file, const struct timeval tvp[2])
return utime(file, times);
}
#endif
+link_warning(utimes, "the use of LEGACY `utimes' is discouraged, use `utime'")
libc_hidden_def(utimes)
diff --git a/libc/sysdeps/linux/common/vfork.c b/libc/sysdeps/linux/common/vfork.c
index 2b043d293..f9634cd5c 100644
--- a/libc/sysdeps/linux/common/vfork.c
+++ b/libc/sysdeps/linux/common/vfork.c
@@ -9,6 +9,8 @@
#include <sys/types.h>
#include <sys/syscall.h>
+#ifdef __ARCH_USE_MMU__
+
#ifdef __NR_fork
libc_hidden_proto(fork)
@@ -21,3 +23,5 @@ libc_hidden_proto(vfork)
weak_alias(__vfork,vfork)
libc_hidden_weak(vfork)
#endif
+
+#endif
diff --git a/libc/sysdeps/linux/common/vhangup.c b/libc/sysdeps/linux/common/vhangup.c
index 984a09dec..8989a69d6 100644
--- a/libc/sysdeps/linux/common/vhangup.c
+++ b/libc/sysdeps/linux/common/vhangup.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
_syscall0(int, vhangup);
diff --git a/libc/sysdeps/linux/common/wait3.c b/libc/sysdeps/linux/common/wait3.c
index 5de975c25..8a2d43f7a 100644
--- a/libc/sysdeps/linux/common/wait3.c
+++ b/libc/sysdeps/linux/common/wait3.c
@@ -4,11 +4,13 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include <syscall.h>
+#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/resource.h>
+#if defined __USE_BSD
+
libc_hidden_proto(wait4)
/* Wait for a child to exit. When one does, put its status in *STAT_LOC and
@@ -20,3 +22,4 @@ pid_t wait3 (__WAIT_STATUS stat_loc, int options, struct rusage * usage)
{
return wait4 (WAIT_ANY, stat_loc, options, usage);
}
+#endif
diff --git a/libc/sysdeps/linux/common/wait4.c b/libc/sysdeps/linux/common/wait4.c
index 9d9de58d6..ff3b82645 100644
--- a/libc/sysdeps/linux/common/wait4.c
+++ b/libc/sysdeps/linux/common/wait4.c
@@ -7,7 +7,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
+#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
#include <sys/wait.h>
#include <sys/resource.h>
@@ -22,3 +23,4 @@ pid_t wait4(pid_t pid, int *status, int opts, struct rusage *rusage)
return (__syscall_wait4(pid, status, opts, rusage));
}
libc_hidden_def(wait4)
+#endif
diff --git a/libc/sysdeps/linux/common/write.c b/libc/sysdeps/linux/common/write.c
index c150808f0..dbe5c12e6 100644
--- a/libc/sysdeps/linux/common/write.c
+++ b/libc/sysdeps/linux/common/write.c
@@ -7,7 +7,7 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
extern __typeof(write) __libc_write;
diff --git a/libc/sysdeps/linux/common/writev.c b/libc/sysdeps/linux/common/writev.c
index cfb758974..464268b2f 100644
--- a/libc/sysdeps/linux/common/writev.c
+++ b/libc/sysdeps/linux/common/writev.c
@@ -2,13 +2,12 @@
/*
* writev() for uClibc
*
- * Copyright (C) 2006 by Steven J. Hill <sjhill@realitydiluted.com>
- * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
*
- * GNU Library General Public License (LGPL) version 2 or later.
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/uio.h>
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
diff --git a/libc/sysdeps/linux/common/xattr.c b/libc/sysdeps/linux/common/xattr.c
index 6e4e7fa92..0ba17cde7 100644
--- a/libc/sysdeps/linux/common/xattr.c
+++ b/libc/sysdeps/linux/common/xattr.c
@@ -21,7 +21,7 @@
* filesystem, or are disabled, errno is set to ENOSYS.
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <sys/xattr.h>
diff --git a/libc/sysdeps/linux/common/xstatconv.c b/libc/sysdeps/linux/common/xstatconv.c
index 58e05c437..abcb496b8 100644
--- a/libc/sysdeps/linux/common/xstatconv.c
+++ b/libc/sysdeps/linux/common/xstatconv.c
@@ -15,18 +15,22 @@
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.
-
+ 02111-1307 USA.
+
Modified for uClibc by Erik Andersen <andersen@codepoet.org>
*/
-#include "syscalls.h"
+#include <sys/syscall.h>
#include <sys/stat.h>
+#include <string.h>
#include "xstatconv.h"
+/* Experimentally off - libc_hidden_proto(memset) */
+
void attribute_hidden __xstat_conv(struct kernel_stat *kbuf, struct stat *buf)
{
/* Convert to current kernel version of `struct stat'. */
+ memset(buf, 0x00, sizeof(*buf));
buf->st_dev = kbuf->st_dev;
buf->st_ino = kbuf->st_ino;
buf->st_mode = kbuf->st_mode;
@@ -52,6 +56,7 @@ void attribute_hidden __xstat_conv(struct kernel_stat *kbuf, struct stat *buf)
void attribute_hidden __xstat64_conv(struct kernel_stat64 *kbuf, struct stat64 *buf)
{
/* Convert to current kernel version of `struct stat64'. */
+ memset(buf, 0x00, sizeof(*buf));
buf->st_dev = kbuf->st_dev;
buf->st_ino = kbuf->st_ino;
# ifdef _HAVE_STAT64___ST_INO
diff --git a/libc/sysdeps/linux/mips/clone.S b/libc/sysdeps/linux/mips/clone.S
index 03162db43..716cd993f 100644
--- a/libc/sysdeps/linux/mips/clone.S
+++ b/libc/sysdeps/linux/mips/clone.S
@@ -125,4 +125,3 @@ __thread_start:
move a0,v0
jal HIDDEN_JUMPTARGET(_exit)
.end __thread_start
-weak_alias(clone, __clone)
diff --git a/libc/sysdeps/linux/mips/sys/asm.h b/libc/sysdeps/linux/mips/sys/asm.h
index 4c8bd9cb2..76f6af3e1 100644
--- a/libc/sysdeps/linux/mips/sys/asm.h
+++ b/libc/sysdeps/linux/mips/sys/asm.h
@@ -469,20 +469,5 @@ symbol = value
# define MFC0 dmfc0
# define MTC0 dmtc0
#endif
-/* The MIPS archtectures do not have a uniform memory model. Particular
- platforms may provide additional guarantees - for instance, the R4000
- LL and SC instructions implicitly perform a SYNC, and the 4K promises
- strong ordering.
-
- However, in the absence of those guarantees, we must assume weak ordering
- and SYNC explicitly where necessary.
-
- Some obsolete MIPS processors may not support the SYNC instruction. This
- applies to "true" MIPS I processors; most of the processors which compile
- using MIPS I implement parts of MIPS II. */
-
-#ifndef MIPS_SYNC
-# define MIPS_SYNC sync
-#endif
#endif /* sys/asm.h */
diff --git a/libc/sysdeps/linux/sh/bits/fcntl.h b/libc/sysdeps/linux/sh/bits/fcntl.h
index ce8b623c6..0fc129405 100644
--- a/libc/sysdeps/linux/sh/bits/fcntl.h
+++ b/libc/sysdeps/linux/sh/bits/fcntl.h
@@ -1,5 +1,5 @@
/* O_*, F_*, FD_* bit values for Linux.
- Copyright (C) 1995, 1996, 1997, 1998, 2000, 2004, 2006
+ Copyright (C) 1995, 1996, 1997, 1998, 2000, 2004, 2006, 2007
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -24,7 +24,7 @@
#include <sys/types.h>
#ifdef __USE_GNU
-# include <sys/uio.h>
+# include <bits/uio.h>
#endif
@@ -50,6 +50,9 @@
# define O_DIRECTORY 0200000 /* Must be a directory. */
# define O_NOFOLLOW 0400000 /* Do not follow links. */
# define O_NOATIME 01000000 /* Do not set atime. */
+# if 0
+# define O_CLOEXEC 02000000 /* Set close_on_exec. */
+# endif
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -97,9 +100,11 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
#endif
-/* For F_[GET|SET]FL. */
+/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
@@ -185,6 +190,8 @@ struct flock64
#ifdef __USE_GNU
+#if 0
+/* Flags for SYNC_FILE_RANGE. */
# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
in the range before performing the
write. */
@@ -196,6 +203,15 @@ struct flock64
write. */
#endif
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
__BEGIN_DECLS
#ifdef __USE_GNU
@@ -209,21 +225,21 @@ extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
/* Selective file content synch'ing. */
extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
unsigned int __flags);
-
+#endif
/* Splice address range into a pipe. */
-extern int vmsplice (int __fdout, const struct iovec *__iov, size_t __count,
- unsigned int __flags);
+extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
+ size_t __count, unsigned int __flags);
/* Splice two files together. */
-extern int splice (int __fdin, int __fdout, size_t __len, unsigned int __flags)
- __THROW;
+extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
+ __off64_t *__offout, size_t __len,
+ unsigned int __flags);
/* In-kernel implementation of tee for pipe buffers. */
-extern int tee (int __fdin, int __fdout, size_t __len, unsigned int __flags)
- __THROW;
-#endif
+extern ssize_t tee (int __fdin, int __fdout, size_t __len,
+ unsigned int __flags);
#endif
-
__END_DECLS
+
diff --git a/libc/sysdeps/linux/sh/bits/syscalls.h b/libc/sysdeps/linux/sh/bits/syscalls.h
index 2a26d9684..234f80653 100644
--- a/libc/sysdeps/linux/sh/bits/syscalls.h
+++ b/libc/sysdeps/linux/sh/bits/syscalls.h
@@ -4,8 +4,6 @@
# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
#endif
-#include <bits/sysnum.h>
-
/* The Linux kernel uses different trap numbers on sh-2. */
#ifdef __CONFIG_SH2__
# define __SH_SYSCALL_TRAP_BASE 0x20
diff --git a/libc/sysdeps/linux/sh/bits/uClibc_arch_features.h b/libc/sysdeps/linux/sh/bits/uClibc_arch_features.h
index f6b027b95..55e34804f 100644
--- a/libc/sysdeps/linux/sh/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/sh/bits/uClibc_arch_features.h
@@ -24,9 +24,6 @@
/* does your target have to worry about older [gs]etrlimit() ? */
#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
-/* does your target prefix all symbols with an _ ? */
-#define __UCLIBC_NO_UNDERSCORES__
-
/* does your target have an asm .set ? */
#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
diff --git a/libc/sysdeps/linux/sh/crti.S b/libc/sysdeps/linux/sh/crti.S
index 37b833825..a74f96eb7 100644
--- a/libc/sysdeps/linux/sh/crti.S
+++ b/libc/sysdeps/linux/sh/crti.S
@@ -1,4 +1,5 @@
#include <features.h>
+
.file "crti.S"
.text
diff --git a/libc/sysdeps/linux/sh/pread_write.c b/libc/sysdeps/linux/sh/pread_write.c
index ab44204b0..d043ae651 100644
--- a/libc/sysdeps/linux/sh/pread_write.c
+++ b/libc/sysdeps/linux/sh/pread_write.c
@@ -1,20 +1,22 @@
-/* vi: set sw=4 ts=4:
- *
+/* vi: set sw=4 ts=4: */
+/*
* Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-/* Based in part on the files
+/*
+ * Based in part on the files
* ./sysdeps/unix/sysv/linux/pwrite.c,
- * ./sysdeps/unix/sysv/linux/pread.c,
+ * ./sysdeps/unix/sysv/linux/pread.c,
* sysdeps/posix/pread.c
* sysdeps/posix/pwrite.c
* from GNU libc 2.2.5, but reworked considerably...
*/
-#include "../common/syscalls.h"
+#include <sys/syscall.h>
#include <unistd.h>
#include <stdint.h>
+#include <endian.h>
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <sysdep-cancel.h>
@@ -32,8 +34,8 @@
#ifdef __NR_pread
extern __typeof(pread) __libc_pread;
-# define __NR___syscall_pread __NR_pread
-static inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
+# define __NR___syscall_pread __NR_pread
+static inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
@@ -50,7 +52,7 @@ ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
}
weak_alias(__libc_pread,pread)
-# ifdef __UCLIBC_HAS_LFS__
+# ifdef __UCLIBC_HAS_LFS__
extern __typeof(pread64) __libc_pread64;
ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
{
@@ -82,8 +84,8 @@ weak_alias(__libc_pread64,pread64)
#ifdef __NR_pwrite
extern __typeof(pwrite) __libc_pwrite;
-# define __NR___syscall_pwrite __NR_pwrite
-static inline _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
+# define __NR___syscall_pwrite __NR_pwrite
+static inline _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
@@ -101,7 +103,7 @@ ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
}
weak_alias(__libc_pwrite,pwrite)
-# ifdef __UCLIBC_HAS_LFS__
+# ifdef __UCLIBC_HAS_LFS__
extern __typeof(pwrite64) __libc_pwrite64;
ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
{
diff --git a/libc/sysdeps/linux/sh/sys/procfs.h b/libc/sysdeps/linux/sh/sys/procfs.h
index e58d824e2..aad21e5f8 100644
--- a/libc/sysdeps/linux/sh/sys/procfs.h
+++ b/libc/sysdeps/linux/sh/sys/procfs.h
@@ -97,8 +97,8 @@ struct elf_prpsinfo
char pr_zomb; /* Zombie. */
char pr_nice; /* Nice val. */
unsigned long int pr_flag; /* Flags. */
- unsigned short int pr_uid;
- unsigned short int pr_gid;
+ long pr_uid;
+ long pr_gid;
int pr_pid, pr_ppid, pr_pgrp, pr_sid;
/* Lots missing */
char pr_fname[16]; /* Filename of executable. */
diff --git a/libc/sysdeps/linux/sh/sys/ucontext.h b/libc/sysdeps/linux/sh/sys/ucontext.h
index e909f35bb..0996bf2d5 100644
--- a/libc/sysdeps/linux/sh/sys/ucontext.h
+++ b/libc/sysdeps/linux/sh/sys/ucontext.h
@@ -88,7 +88,7 @@ typedef freg_t fpregset_t[NFPREG];
typedef struct
{
unsigned int oldmask;
-
+
/* CPU registers */
gregset_t gregs;
unsigned int pc;
@@ -105,7 +105,7 @@ typedef struct
unsigned int fpscr;
unsigned int fpul;
unsigned int ownedfp;
-#endif
+#endif
} mcontext_t;
/* Userlevel context. */
diff --git a/libc/sysdeps/linux/sh/vfork.S b/libc/sysdeps/linux/sh/vfork.S
index 5d7e51dd5..a9b440d8f 100644
--- a/libc/sysdeps/linux/sh/vfork.S
+++ b/libc/sysdeps/linux/sh/vfork.S
@@ -21,9 +21,8 @@
*/
#include <features.h>
-#define _SYSCALL_H
-#include <bits/sysnum.h>
-#define _ERRNO_H 1
+#include <sys/syscall.h>
+#define _ERRNO_H
#include <bits/errno.h>
#include <bits/sysnum.h>
diff --git a/libc/termios/tcgetattr.c b/libc/termios/tcgetattr.c
index 726c83a44..a5a5df6b5 100644
--- a/libc/termios/tcgetattr.c
+++ b/libc/termios/tcgetattr.c
@@ -24,9 +24,9 @@
#include <sys/types.h>
libc_hidden_proto(ioctl)
-libc_hidden_proto(memset)
-libc_hidden_proto(memcpy)
-libc_hidden_proto(mempcpy)
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(mempcpy) */
libc_hidden_proto(tcgetattr)
/* The difference here is that the termios structure used in the
diff --git a/libc/termios/tcgetsid.c b/libc/termios/tcgetsid.c
index ede8958af..8d3a40242 100644
--- a/libc/termios/tcgetsid.c
+++ b/libc/termios/tcgetsid.c
@@ -28,13 +28,12 @@ libc_hidden_proto(tcgetpgrp)
/* Return the session ID of FD. */
pid_t
-tcgetsid (fd)
- int fd;
+tcgetsid (int fd)
{
pid_t pgrp;
pid_t sid;
#ifdef TIOCGSID
- static int tiocgsid_does_not_work;
+ static smallint tiocgsid_does_not_work;
if (! tiocgsid_does_not_work)
{
diff --git a/libc/termios/tcsetattr.c b/libc/termios/tcsetattr.c
index 847023f86..d0d82c2ac 100644
--- a/libc/termios/tcsetattr.c
+++ b/libc/termios/tcsetattr.c
@@ -23,7 +23,7 @@
#include <sys/types.h>
libc_hidden_proto(tcsetattr)
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
libc_hidden_proto(ioctl)
/* The difference here is that the termios structure used in the
diff --git a/libc/termios/ttyname.c b/libc/termios/ttyname.c
index 001681caa..9d6a8ce36 100644
--- a/libc/termios/ttyname.c
+++ b/libc/termios/ttyname.c
@@ -34,8 +34,8 @@
libc_hidden_proto(ttyname_r)
libc_hidden_proto(fstat)
libc_hidden_proto(lstat)
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(opendir)
libc_hidden_proto(closedir)
libc_hidden_proto(readdir)
diff --git a/libc/unistd/confstr.c b/libc/unistd/confstr.c
index 34ae98483..67a9d585a 100644
--- a/libc/unistd/confstr.c
+++ b/libc/unistd/confstr.c
@@ -22,7 +22,7 @@
#include <unistd.h>
#include <string.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
#define CS_PATH "/bin:/usr/bin"
diff --git a/libc/unistd/exec.c b/libc/unistd/exec.c
index 47aab27e7..9134e4370 100644
--- a/libc/unistd/exec.c
+++ b/libc/unistd/exec.c
@@ -29,57 +29,79 @@
libc_hidden_proto(execl)
libc_hidden_proto(execle)
+libc_hidden_proto(execlp)
+libc_hidden_proto(execv)
libc_hidden_proto(execvp)
-libc_hidden_proto(memcpy)
-libc_hidden_proto(strchr)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(execve)
libc_hidden_proto(mmap)
libc_hidden_proto(munmap)
libc_hidden_proto(getenv)
/**********************************************************************/
-#if defined(__ARCH_USE_MMU__) || defined(__UCLIBC_UCLINUX_BROKEN_MUNMAP__)
+#define EXEC_FUNC_COMMON 0
+#define EXEC_FUNC_EXECVP 1
+#if defined(__ARCH_USE_MMU__)
-/* We have an MMU, so use alloca() to grab space for buffers and
- * arg lists. Also fall back to alloca() if munmap() is broken. */
+/* We have an MMU, so use alloca() to grab space for buffers and arg lists. */
-# define EXEC_ALLOC_SIZE(VAR) /* nothing to do */
-# define EXEC_ALLOC(SIZE,VAR) alloca((SIZE))
-# define EXEC_FREE(PTR,VAR) ((void)0)
+# define EXEC_ALLOC_SIZE(VAR) /* nothing to do */
+# define EXEC_ALLOC(SIZE,VAR,FUNC) alloca((SIZE))
+# define EXEC_FREE(PTR,VAR) ((void)0)
#else
-/* We do not have an MMU, so using alloca() is not an option.
- * Less obviously, using malloc() is not an option either since
- * malloc()ed memory can leak in a vfork() and exec*() situation.
- * Therefore, we must use mmap() and unmap() directly.
+/* We do not have an MMU, so using alloca() is not an option (as this will
+ * easily overflow the stack in most setups). Less obviously, using malloc()
+ * is not an option either since malloc()ed memory can leak in from a vfork()ed
+ * child into the parent as no one is around after the child calls exec*() to
+ * free() the memory. Therefore, we must use mmap() and unmap() directly,
+ * caching the result as we go. This way we minimize the leak by reusing the
+ * memory with every call to an exec*().
+ *
+ * To prevent recursive use of the same cached memory, we have to give execvp()
+ * its own cache. Here are the nested exec calls (a/-: alloc/no-alloc):
+ * execve(-) -> calls straight to kernel
+ * execl(a) -> execve(-)
+ * execlp(a) -> execvp(a) !! recursive usage !!
+ * execle(a) -> execve(-)
+ * execv(-) -> execve(-)
+ * execvp(a) -> execve(-)
*/
-# define EXEC_ALLOC_SIZE(VAR) size_t VAR; /* Semicolon included! */
-# define EXEC_ALLOC(SIZE,VAR) __exec_alloc((VAR = (SIZE)))
-# define EXEC_FREE(PTR,VAR) __exec_free((PTR),(VAR))
+# define EXEC_ALLOC_SIZE(VAR) /* nothing to do */
+# define EXEC_ALLOC(SIZE,VAR,FUNC) __exec_alloc((SIZE), FUNC)
+# define EXEC_FREE(PTR,VAR) ((void)0)
-extern void *__exec_alloc(size_t size) attribute_hidden;
-extern void __exec_free(void *ptr, size_t size) attribute_hidden;
+extern void *__exec_alloc(size_t size, int func) attribute_hidden;
# ifdef L___exec_alloc
-void attribute_hidden *__exec_alloc(size_t size)
-{
- void *p;
-
- p = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
-
- return (p != MAP_FAILED) ? p : NULL;
-}
-
-void attribute_hidden __exec_free(void *ptr, size_t size)
+void attribute_hidden *__exec_alloc(size_t size, int func)
{
- if (ptr) {
- munmap(ptr, size);
- }
+ static void *common_cache, *execvp_cache;
+ static size_t common_size, execvp_size;
+
+ void **cache = (func ? &execvp_cache : &common_cache);
+ size_t *cache_size = (func ? &execvp_size : &common_size);
+
+ if (*cache_size >= size)
+ return *cache;
+ else if (*cache)
+ munmap(*cache, *cache_size);
+
+ *cache_size = size;
+ return *cache = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
+
+ /* We don't actually handle OOM in the exec funcs ...
+ if (*cache != MAP_FAILED)
+ return *cache;
+ else
+ return (*cache = NULL);
+ */
}
# endif
@@ -95,7 +117,7 @@ int execl(const char *path, const char *arg, ...)
char **argv;
char **p;
va_list args;
-
+
n = 0;
va_start(args, arg);
do {
@@ -103,7 +125,7 @@ int execl(const char *path, const char *arg, ...)
} while (va_arg(args, char *));
va_end(args);
- p = argv = (char **) EXEC_ALLOC((n+1) * sizeof(char *), size);
+ p = argv = (char **) EXEC_ALLOC((n+1) * sizeof(char *), size, EXEC_FUNC_COMMON);
p[0] = (char *)arg;
@@ -129,6 +151,7 @@ int execv(__const char *path, char *__const argv[])
{
return execve(path, argv, __environ);
}
+libc_hidden_def(execv)
#endif
/**********************************************************************/
@@ -142,7 +165,7 @@ int execle(const char *path, const char *arg, ...)
char **p;
char *const *envp;
va_list args;
-
+
n = 0;
va_start(args, arg);
do {
@@ -151,7 +174,7 @@ int execle(const char *path, const char *arg, ...)
envp = va_arg(args, char *const *); /* Varies from execl and execlp. */
va_end(args);
- p = argv = (char **) EXEC_ALLOC((n+1) * sizeof(char *), size);
+ p = argv = (char **) EXEC_ALLOC((n+1) * sizeof(char *), size, EXEC_FUNC_COMMON);
p[0] = (char *)arg;
@@ -180,7 +203,7 @@ int execlp(const char *file, const char *arg, ...)
char **argv;
char **p;
va_list args;
-
+
n = 0;
va_start(args, arg);
do {
@@ -188,7 +211,7 @@ int execlp(const char *file, const char *arg, ...)
} while (va_arg(args, char *));
va_end(args);
- p = argv = (char **) EXEC_ALLOC((n+1) * sizeof(char *), size);
+ p = argv = (char **) EXEC_ALLOC((n+1) * sizeof(char *), size, EXEC_FUNC_COMMON);
p[0] = (char *)arg;
@@ -204,12 +227,13 @@ int execlp(const char *file, const char *arg, ...)
return n;
}
+libc_hidden_def(execlp)
#endif
/**********************************************************************/
#ifdef L_execvp
-libc_hidden_proto(strchrnul)
+/* Experimentally off - libc_hidden_proto(strchrnul) */
/* Use a default path that matches glibc behavior, since SUSv3 says
* this is implementation-defined. The default is current working dir,
@@ -235,15 +259,15 @@ int execvp(const char *path, char *const argv[])
if (strchr(path, '/')) {
execve(path, argv, __environ);
- CHECK_ENOEXEC:
if (errno == ENOEXEC) {
char **nargv;
EXEC_ALLOC_SIZE(size2) /* Do NOT add a semicolon! */
size_t n;
+ RUN_BIN_SH:
/* Need the dimension - 1. We omit counting the trailing
* NULL but we actually omit the first entry. */
for (n=0 ; argv[n] ; n++) {}
- nargv = (char **) EXEC_ALLOC((n+2) * sizeof(char *), size2);
+ nargv = (char **) EXEC_ALLOC((n+2) * sizeof(char *), size2, EXEC_FUNC_EXECVP);
nargv[0] = argv[0];
nargv[1] = (char *)path;
memcpy(nargv+2, argv+1, n*sizeof(char *));
@@ -267,7 +291,8 @@ int execvp(const char *path, char *const argv[])
}
len = (FILENAME_MAX - 1) - plen;
- if ((buf = EXEC_ALLOC(FILENAME_MAX, size)) != NULL) {
+ buf = EXEC_ALLOC(FILENAME_MAX, size, EXEC_FUNC_EXECVP);
+ {
int seen_small = 0;
s0 = buf + len;
memcpy(s0, path, plen+1);
@@ -292,9 +317,9 @@ int execvp(const char *path, char *const argv[])
seen_small = 1;
- if (errno != ENOENT) {
+ if (errno == ENOEXEC) {
path = s;
- goto CHECK_ENOEXEC;
+ goto RUN_BIN_SH;
}
NEXT:
diff --git a/libc/unistd/fpathconf.c b/libc/unistd/fpathconf.c
index 9cb66a927..f3e2ffe83 100644
--- a/libc/unistd/fpathconf.c
+++ b/libc/unistd/fpathconf.c
@@ -23,7 +23,6 @@
#include <sys/statfs.h>
#include <errno.h>
#include <stddef.h>
-#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
#include <sys/stat.h>
@@ -33,7 +32,21 @@
//#include "linux_fsinfo.h"
libc_hidden_proto(fstat)
-libc_hidden_proto(fstatfs)
+#if !defined __UCLIBC_LINUX_SPECIFIC__
+#ifndef __USE_FILE_OFFSET64
+extern int fstatfs (int __fildes, struct statfs *__buf)
+ __THROW __nonnull ((2));
+#else
+# ifdef __REDIRECT_NTH
+ extern int __REDIRECT_NTH (fstatfs, (int __fildes, struct statfs *__buf),
+ fstatfs64) __nonnull ((2));
+# else
+# define fstatfs fstatfs64
+# endif
+#endif
+#endif
+extern __typeof(fstatfs) __libc_fstatfs;
+libc_hidden_proto(__libc_fstatfs)
/* The Linux kernel headers mention this as a kind of generic value. */
#define LINUX_LINK_MAX 127
@@ -55,7 +68,7 @@ long int fpathconf(int fd, int name)
struct statfs fsbuf;
/* Determine the filesystem type. */
- if (fstatfs (fd, &fsbuf) < 0)
+ if (__libc_fstatfs (fd, &fsbuf) < 0)
{
if (errno == ENOSYS)
/* not possible, return the default value. */
@@ -129,7 +142,7 @@ long int fpathconf(int fd, int name)
struct statfs buf;
int save_errno = errno;
- if (fstatfs (fd, &buf) < 0)
+ if (__libc_fstatfs (fd, &buf) < 0)
{
if (errno == ENOSYS)
{
diff --git a/libc/unistd/getlogin.c b/libc/unistd/getlogin.c
index 42438b327..1998a7fc8 100644
--- a/libc/unistd/getlogin.c
+++ b/libc/unistd/getlogin.c
@@ -10,8 +10,8 @@
#include <unistd.h>
#include <stdio.h>
-libc_hidden_proto(strcpy)
-libc_hidden_proto(strncpy)
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strncpy) */
libc_hidden_proto(getenv)
/* uClibc makes it policy to not mess with the utmp file whenever
diff --git a/libc/unistd/getopt-susv3.c b/libc/unistd/getopt-susv3.c
index b13368c38..73d7a7e38 100644
--- a/libc/unistd/getopt-susv3.c
+++ b/libc/unistd/getopt-susv3.c
@@ -24,7 +24,7 @@
#include <getopt.h>
libc_hidden_proto(fprintf)
-libc_hidden_proto(strchr)
+/* Experimentally off - libc_hidden_proto(strchr) */
#ifdef __UCLIBC_MJN3_ONLY__
#warning TODO: Enable gettext awareness.
diff --git a/libc/unistd/getopt.c b/libc/unistd/getopt.c
index 0c30032c9..754e86f25 100644
--- a/libc/unistd/getopt.c
+++ b/libc/unistd/getopt.c
@@ -121,10 +121,10 @@
#include <getopt.h>
#include "getopt_int.h"
-libc_hidden_proto(strchr)
-libc_hidden_proto(strcmp)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strncmp)
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcmp) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strncmp) */
libc_hidden_proto(getenv)
libc_hidden_proto(fprintf)
diff --git a/libc/unistd/getopt_int.h b/libc/unistd/getopt_int.h
index e2a005db9..5637c109f 100644
--- a/libc/unistd/getopt_int.h
+++ b/libc/unistd/getopt_int.h
@@ -30,7 +30,13 @@ extern int _getopt_internal (int ___argc, char *const *___argv,
/* Reentrant versions which can handle parsing multiple argument
vectors at the same time. */
+/* For __ordering member */
+enum {
+ REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+};
+
/* Data type for reentrant functions. */
+
struct _getopt_data
{
/* These have exactly the same meaning as the corresponding global
@@ -38,21 +44,13 @@ struct _getopt_data
versions of getopt. */
int optind;
int opterr;
- int optopt;
char *optarg;
+ smalluint optopt; /* we store characters here, a byte is enough */
/* Internal members. */
/* True if the internal members have been initialized. */
- int __initialized;
-
- /* The next char to be scanned in the option-element
- in which the last option character we returned was found.
- This allows us to pick up the scan where we left off.
-
- If this is zero, or a null string, it means resume the scan
- by advancing to the next ARGV-element. */
- char *__nextchar;
+ smallint __initialized;
/* Describe how to deal with options that follow non-option ARGV-elements.
@@ -82,14 +80,18 @@ struct _getopt_data
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return -1 with `optind' != ARGC. */
-
- enum
- {
- REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
- } __ordering;
+ smallint __ordering;
/* If the POSIXLY_CORRECT environment variable is set. */
- int __posixly_correct;
+ smallint __posixly_correct;
+
+ /* The next char to be scanned in the option-element
+ in which the last option character we returned was found.
+ This allows us to pick up the scan where we left off.
+
+ If this is zero, or a null string, it means resume the scan
+ by advancing to the next ARGV-element. */
+ char *__nextchar;
/* Handle permutation of arguments. */
diff --git a/libc/unistd/getpass.c b/libc/unistd/getpass.c
index 34dbf355b..f17a1d71d 100644
--- a/libc/unistd/getpass.c
+++ b/libc/unistd/getpass.c
@@ -24,7 +24,7 @@
#if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
-libc_hidden_proto(strlen)
+/* Experimentally off - libc_hidden_proto(strlen) */
libc_hidden_proto(tcsetattr)
libc_hidden_proto(tcgetattr)
libc_hidden_proto(setvbuf)
@@ -48,9 +48,7 @@ libc_hidden_proto(__fputc_unlocked)
#endif
#define PWD_BUFFER_SIZE 256
-char *
-getpass (prompt)
- const char *prompt;
+char * getpass (const char *prompt)
{
FILE *in, *out;
struct termios s, t;
diff --git a/libc/unistd/getsubopt-susv3.c b/libc/unistd/getsubopt-susv3.c
index 464223c42..10c97ca9a 100644
--- a/libc/unistd/getsubopt-susv3.c
+++ b/libc/unistd/getsubopt-susv3.c
@@ -7,9 +7,9 @@
#include <stdlib.h>
#include <string.h>
-libc_hidden_proto(strchr)
-libc_hidden_proto(strlen)
-libc_hidden_proto(strncmp)
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+/* Experimentally off - libc_hidden_proto(strncmp) */
int getsubopt(char **opt, char *const *keys, char **val)
{
diff --git a/libc/unistd/getsubopt.c b/libc/unistd/getsubopt.c
index 3cac432ec..301410232 100644
--- a/libc/unistd/getsubopt.c
+++ b/libc/unistd/getsubopt.c
@@ -21,9 +21,9 @@
#include <stdlib.h>
#include <string.h>
-libc_hidden_proto(memchr)
-libc_hidden_proto(strncmp)
-libc_hidden_proto(strchrnul)
+/* Experimentally off - libc_hidden_proto(memchr) */
+/* Experimentally off - libc_hidden_proto(strncmp) */
+/* Experimentally off - libc_hidden_proto(strchrnul) */
/* Parse comma separated suboption from *OPTIONP and match against
strings in TOKENS. If found return index and set *VALUEP to
diff --git a/libc/unistd/pathconf.c b/libc/unistd/pathconf.c
index 8e3c0a352..7f7efbb7f 100644
--- a/libc/unistd/pathconf.c
+++ b/libc/unistd/pathconf.c
@@ -31,7 +31,8 @@
#include <sys/statfs.h>
//#include <sys/statvfs.h>
-libc_hidden_proto(statfs)
+extern __typeof(statfs) __libc_statfs;
+libc_hidden_proto(__libc_statfs)
libc_hidden_proto(stat)
@@ -83,7 +84,7 @@ pathconf (const char *path, int name)
struct statfs buf;
int save_errno = errno;
- if (statfs (path, &buf) < 0)
+ if (__libc_statfs (path, &buf) < 0)
{
if (errno == ENOSYS)
{
diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c
index 4381c45c7..c5c9cdd21 100644
--- a/libc/unistd/sleep.c
+++ b/libc/unistd/sleep.c
@@ -27,6 +27,9 @@ libc_hidden_proto(sleep)
libc_hidden_proto(sigaction)
libc_hidden_proto(sigprocmask)
+
+/* version perusing nanosleep */
+#if defined __UCLIBC_HAS_REALTIME__
//libc_hidden_proto(__sigaddset)
//libc_hidden_proto(__sigemptyset)
//libc_hidden_proto(__sigismember)
@@ -114,4 +117,56 @@ unsigned int sleep (unsigned int seconds)
return result;
}
#endif
+#else /* __UCLIBC_HAS_REALTIME__ */
+libc_hidden_proto(sigaction)
+/* no nanosleep, use signals and alarm() */
+static void sleep_alarm_handler(int attribute_unused sig)
+{
+}
+unsigned int sleep (unsigned int seconds)
+{
+ struct sigaction act, oact;
+ sigset_t set, oset;
+ unsigned int result, remaining;
+ time_t before, after;
+ int old_errno = errno;
+
+ /* This is not necessary but some buggy programs depend on this. */
+ if (seconds == 0)
+ return 0;
+
+ /* block SIGALRM */
+ if (__sigemptyset (&set) < 0
+ || __sigaddset (&set, SIGALRM) < 0
+ || sigprocmask (SIG_BLOCK, &set, &oset))
+ return seconds;
+
+ act.sa_handler = sleep_alarm_handler;
+ act.sa_flags = 0;
+ act.sa_mask = oset;
+ if (sigaction(SIGALRM, &act, &oact) < 0)
+ return seconds;
+
+ before = time(NULL);
+ remaining = alarm(seconds);
+ if (remaining && remaining > seconds) {
+ /* restore user's alarm */
+ (void) sigaction(SIGALRM, &oact, (struct sigaction *) NULL);
+ alarm(remaining); /* restore old alarm */
+ sigsuspend(&oset);
+ after = time(NULL);
+ } else {
+ sigsuspend (&oset);
+ after = time(NULL);
+ (void) sigaction (SIGALRM, &oact, NULL);
+ }
+ result = after - before;
+ alarm(remaining > result ? remaining - result : 0);
+ sigprocmask (SIG_SETMASK, &oset, NULL);
+
+ __set_errno(old_errno);
+
+ return result > seconds ? 0 : seconds - result;
+}
+#endif /* __UCLIBC_HAS_REALTIME__ */
libc_hidden_def(sleep)
diff --git a/libc/unistd/sysconf.c b/libc/unistd/sysconf.c
index c2d2b53e2..c1644eaa1 100644
--- a/libc/unistd/sysconf.c
+++ b/libc/unistd/sysconf.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
+#include <sys/syscall.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
#ifdef __UCLIBC_HAS_REGEX__
@@ -571,13 +572,11 @@ long int sysconf(int name)
#endif
/* If you change these, also change libc/pwd_grp/pwd_grp.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
case _SC_GETGR_R_SIZE_MAX:
- return GRP_BUFFER_SIZE;
+ return __UCLIBC_GRP_BUFFER_SIZE__;
case _SC_GETPW_R_SIZE_MAX:
- return PWD_BUFFER_SIZE;
+ return __UCLIBC_PWD_BUFFER_SIZE__;
/* getlogin() is a worthless interface. In uClibc we let the user specify
* whatever they want via the LOGNAME environment variable, or we return NULL
@@ -887,8 +886,8 @@ long int sysconf(int name)
RETURN_NEG_1;
#endif
-#ifdef __NR_clock_getres
case _SC_MONOTONIC_CLOCK:
+#ifdef __NR_clock_getres
/* Check using the clock_getres system call. */
# ifdef __UCLIBC_HAS_THREADS_NATIVE__
{
diff --git a/libc/unistd/usershell.c b/libc/unistd/usershell.c
index ea4a04ba4..5f5b787c2 100644
--- a/libc/unistd/usershell.c
+++ b/libc/unistd/usershell.c
@@ -50,7 +50,7 @@ libc_hidden_proto(fileno)
libc_hidden_proto(fgets_unlocked)
#ifdef __UCLIBC_HAS_XLOCALE__
libc_hidden_proto(__ctype_b_loc)
-#elif __UCLIBC_HAS_CTYPE_TABLES__
+#elif defined __UCLIBC_HAS_CTYPE_TABLES__
libc_hidden_proto(__ctype_b)
#endif
@@ -80,13 +80,9 @@ char * getusershell(void)
static void __free_initshell_memory(void)
{
- if (shells != NULL) {
- free(shells);
- }
+ free(shells);
shells = NULL;
- if (strings != NULL) {
- free(strings);
- }
+ free(strings);
strings = NULL;
}
@@ -98,7 +94,6 @@ void endusershell(void)
void setusershell(void)
{
-
curshell = initshells();
}
diff --git a/libc/unistd/usleep.c b/libc/unistd/usleep.c
index 91b88278d..8a27f900a 100644
--- a/libc/unistd/usleep.c
+++ b/libc/unistd/usleep.c
@@ -9,6 +9,8 @@
#include <sys/types.h>
#include <unistd.h>
+#if defined __USE_BSD || defined __USE_POSIX98
+#if defined __UCLIBC_HAS_REALTIME__
/*libc_hidden_proto(nanosleep) need the reloc for cancellation*/
int usleep (__useconds_t usec)
@@ -19,3 +21,15 @@ int usleep (__useconds_t usec)
};
return(nanosleep(&ts, NULL));
}
+#else /* __UCLIBC_HAS_REALTIME__ */
+libc_hidden_proto(select)
+int usleep (__useconds_t usec)
+{
+ struct timeval tv;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = usec;
+ return select(0, NULL, NULL, NULL, &tv);
+}
+#endif /* __UCLIBC_HAS_REALTIME__ */
+#endif