summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2013-02-24 16:50:53 +0000
committerattilio <attilio@FreeBSD.org>2013-02-24 16:50:53 +0000
commitcff31deb1a197b29ab976c135fdd01dfb6951a6a (patch)
treedbdcb15ce3419e48e823390b612d613ff00bd567 /lib
parentb4e24f9126f7a4c80ce0c44f6b4230021089bc1e (diff)
parent084e5da56e3c4bc6f9c6ed314310a9b8af2c695b (diff)
downloadFreeBSD-src-cff31deb1a197b29ab976c135fdd01dfb6951a6a.zip
FreeBSD-src-cff31deb1a197b29ab976c135fdd01dfb6951a6a.tar.gz
MFC
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/Makefile.inc543
-rw-r--r--lib/libc/gen/sem_new.c16
-rw-r--r--lib/libc/stdio/setbuf.35
-rw-r--r--lib/libc/stdlib/bsearch.38
-rw-r--r--lib/libc/stdlib/qsort.342
-rw-r--r--lib/libc/sys/Makefile.inc294
-rw-r--r--lib/libelf/elf_data.c8
-rw-r--r--lib/libelf/elf_getdata.319
-rw-r--r--lib/libelf/elf_update.c308
-rw-r--r--lib/libldns/Makefile1
-rw-r--r--lib/libsm/Makefile5
-rw-r--r--lib/libstand/Makefile2
-rw-r--r--lib/libstand/stand.h1
-rw-r--r--lib/libstand/strtoul.c121
14 files changed, 1039 insertions, 334 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 0bbbb33..711cbff 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -4,37 +4,144 @@
# machine-independent gen sources
.PATH: ${.CURDIR}/${LIBC_ARCH}/gen ${.CURDIR}/gen
-SRCS+= __getosreldate.c __xuname.c \
- _once_stub.c _pthread_stubs.c _rand48.c _spinlock_stub.c \
+SRCS+= __getosreldate.c \
+ __xuname.c \
+ _once_stub.c \
+ _pthread_stubs.c \
+ _rand48.c \
+ _spinlock_stub.c \
_thread_init.c \
- alarm.c arc4random.c assert.c auxv.c basename.c check_utility_compat.c \
- clock.c clock_getcpuclockid.c closedir.c confstr.c \
- crypt.c ctermid.c daemon.c devname.c dirfd.c dirname.c disklabel.c \
- dlfcn.c drand48.c elf_utils.c erand48.c err.c errlst.c errno.c \
- exec.c fdevname.c feature_present.c fmtcheck.c fmtmsg.c fnmatch.c \
- fpclassify.c frexp.c fstab.c ftok.c fts.c fts-compat.c ftw.c \
- getbootfile.c getbsize.c \
- getcap.c getcwd.c getdomainname.c getgrent.c getgrouplist.c \
- gethostname.c getloadavg.c getlogin.c getmntinfo.c getnetgrent.c \
- getosreldate.c getpagesize.c getpagesizes.c \
- getpeereid.c getprogname.c getpwent.c getttyent.c \
- getusershell.c getutxent.c getvfsbyname.c glob.c \
- initgroups.c isatty.c isinf.c isnan.c jrand48.c lcong48.c \
+ alarm.c \
+ arc4random.c \
+ assert.c \
+ auxv.c \
+ basename.c \
+ check_utility_compat.c \
+ clock.c \
+ clock_getcpuclockid.c \
+ closedir.c \
+ confstr.c \
+ crypt.c \
+ ctermid.c \
+ daemon.c \
+ devname.c \
+ dirfd.c \
+ dirname.c \
+ disklabel.c \
+ dlfcn.c \
+ drand48.c \
+ elf_utils.c \
+ erand48.c \
+ err.c \
+ errlst.c \
+ errno.c \
+ exec.c \
+ fdevname.c \
+ feature_present.c \
+ fmtcheck.c \
+ fmtmsg.c \
+ fnmatch.c \
+ fpclassify.c \
+ frexp.c \
+ fstab.c \
+ ftok.c \
+ fts.c \
+ fts-compat.c \
+ ftw.c \
+ getbootfile.c \
+ getbsize.c \
+ getcap.c \
+ getcwd.c \
+ getdomainname.c \
+ getgrent.c \
+ getgrouplist.c \
+ gethostname.c \
+ getloadavg.c \
+ getlogin.c \
+ getmntinfo.c \
+ getnetgrent.c \
+ getosreldate.c \
+ getpagesize.c \
+ getpagesizes.c \
+ getpeereid.c \
+ getprogname.c \
+ getpwent.c \
+ getttyent.c \
+ getusershell.c \
+ getutxent.c \
+ getvfsbyname.c \
+ glob.c \
+ initgroups.c \
+ isatty.c \
+ isinf.c \
+ isnan.c \
+ jrand48.c \
+ lcong48.c \
libc_dlopen.c \
- lockf.c lrand48.c mrand48.c nftw.c nice.c \
- nlist.c nrand48.c opendir.c \
- pause.c pmadvise.c popen.c posix_spawn.c \
- psignal.c pututxline.c pw_scan.c \
- raise.c readdir.c readpassphrase.c rewinddir.c \
- scandir.c seed48.c seekdir.c semctl.c \
- setdomainname.c sethostname.c setjmperr.c setmode.c \
- setproctitle.c setprogname.c siginterrupt.c siglist.c signal.c \
- sigsetops.c sleep.c srand48.c statvfs.c stringlist.c strtofflags.c \
- sysconf.c sysctl.c sysctlbyname.c sysctlnametomib.c \
- syslog.c telldir.c termios.c time.c times.c timezone.c tls.c \
- ttyname.c ttyslot.c ualarm.c ulimit.c uname.c unvis-compat.c \
- usleep.c utime.c utxdb.c valloc.c wait.c wait3.c waitpid.c \
- waitid.c wordexp.c
+ lockf.c \
+ lrand48.c \
+ mrand48.c \
+ nftw.c \
+ nice.c \
+ nlist.c \
+ nrand48.c \
+ opendir.c \
+ pause.c \
+ pmadvise.c \
+ popen.c \
+ posix_spawn.c \
+ psignal.c \
+ pututxline.c \
+ pw_scan.c \
+ raise.c \
+ readdir.c \
+ readpassphrase.c \
+ rewinddir.c \
+ scandir.c \
+ seed48.c \
+ seekdir.c \
+ semctl.c \
+ setdomainname.c \
+ sethostname.c \
+ setjmperr.c \
+ setmode.c \
+ setproctitle.c \
+ setprogname.c \
+ siginterrupt.c \
+ siglist.c \
+ signal.c \
+ sigsetops.c \
+ sleep.c \
+ srand48.c \
+ statvfs.c \
+ stringlist.c \
+ strtofflags.c \
+ sysconf.c \
+ sysctl.c \
+ sysctlbyname.c \
+ sysctlnametomib.c \
+ syslog.c \
+ telldir.c \
+ termios.c \
+ time.c \
+ times.c \
+ timezone.c \
+ tls.c \
+ ttyname.c \
+ ttyslot.c \
+ ualarm.c \
+ ulimit.c \
+ uname.c \
+ unvis-compat.c \
+ usleep.c \
+ utime.c \
+ utxdb.c \
+ valloc.c \
+ wait.c \
+ wait3.c \
+ waitpid.c \
+ waitid.c \
+ wordexp.c
.PATH: ${.CURDIR}/../../contrib/libc-pwcache
SRCS+= pwcache.c pwcache.h
@@ -58,101 +165,257 @@ SYM_MAPS+=${.CURDIR}/gen/Symbol.map
# machine-dependent gen sources
.sinclude "${.CURDIR}/${LIBC_ARCH}/gen/Makefile.inc"
-MAN+= alarm.3 arc4random.3 \
- basename.3 check_utility_compat.3 clock.3 clock_getcpuclockid.3 \
- confstr.3 ctermid.3 daemon.3 devname.3 directory.3 dirname.3 \
- dl_iterate_phdr.3 dladdr.3 dlinfo.3 dllockinit.3 dlopen.3 \
- err.3 exec.3 \
- feature_present.3 fmtcheck.3 fmtmsg.3 fnmatch.3 fpclassify.3 frexp.3 \
- ftok.3 fts.3 ftw.3 \
- getbootfile.3 getbsize.3 getcap.3 getcontext.3 getcwd.3 \
- getdiskbyname.3 getdomainname.3 getfsent.3 \
- getgrent.3 getgrouplist.3 gethostname.3 getloadavg.3 \
- getmntinfo.3 getnetgrent.3 getosreldate.3 getpagesize.3 \
- getpagesizes.3 getpass.3 getpeereid.3 getprogname.3 getpwent.3 \
- getttyent.3 getusershell.3 getutxent.3 getvfsbyname.3 \
- glob.3 initgroups.3 isgreater.3 ldexp.3 lockf.3 makecontext.3 \
+MAN+= alarm.3 \
+ arc4random.3 \
+ basename.3 \
+ check_utility_compat.3 \
+ clock.3 \
+ clock_getcpuclockid.3 \
+ confstr.3 \
+ ctermid.3 \
+ daemon.3 \
+ devname.3 \
+ directory.3 \
+ dirname.3 \
+ dl_iterate_phdr.3 \
+ dladdr.3 \
+ dlinfo.3 \
+ dllockinit.3 \
+ dlopen.3 \
+ err.3 \
+ exec.3 \
+ feature_present.3 \
+ fmtcheck.3 \
+ fmtmsg.3 \
+ fnmatch.3 \
+ fpclassify.3 \
+ frexp.3 \
+ ftok.3 \
+ fts.3 \
+ ftw.3 \
+ getbootfile.3 \
+ getbsize.3 \
+ getcap.3 \
+ getcontext.3 \
+ getcwd.3 \
+ getdiskbyname.3 \
+ getdomainname.3 \
+ getfsent.3 \
+ getgrent.3 \
+ getgrouplist.3 \
+ gethostname.3 \
+ getloadavg.3 \
+ getmntinfo.3 \
+ getnetgrent.3 \
+ getosreldate.3 \
+ getpagesize.3 \
+ getpagesizes.3 \
+ getpass.3 \
+ getpeereid.3 \
+ getprogname.3 \
+ getpwent.3 \
+ getttyent.3 \
+ getusershell.3 \
+ getutxent.3 \
+ getvfsbyname.3 \
+ glob.3 \
+ initgroups.3 \
+ isgreater.3 \
+ ldexp.3 \
+ lockf.3 \
+ makecontext.3 \
modf.3 \
- nice.3 nlist.3 pause.3 popen.3 \
- posix_spawn.3 posix_spawn_file_actions_addopen.3 \
- posix_spawn_file_actions_init.3 posix_spawnattr_getflags.3 \
- posix_spawnattr_getpgroup.3 posix_spawnattr_getschedparam.3 \
- posix_spawnattr_getschedpolicy.3 posix_spawnattr_init.3 \
- posix_spawnattr_getsigdefault.3 posix_spawnattr_getsigmask.3 \
- psignal.3 pwcache.3 \
- raise.3 rand48.3 readpassphrase.3 rfork_thread.3 \
- scandir.3 sem_destroy.3 sem_getvalue.3 sem_init.3 \
- sem_open.3 sem_post.3 sem_timedwait.3 sem_wait.3 \
- setjmp.3 setmode.3 setproctitle.3 \
- siginterrupt.3 signal.3 sigsetops.3 sleep.3 \
- statvfs.3 stringlist.3 \
- strtofflags.3 sysconf.3 sysctl.3 syslog.3 tcgetpgrp.3 tcgetsid.3 \
- tcsendbreak.3 tcsetattr.3 tcsetpgrp.3 tcsetsid.3 time.3 times.3 \
- timezone.3 ttyname.3 tzset.3 ualarm.3 ucontext.3 ulimit.3 uname.3 \
- unvis.3 usleep.3 utime.3 valloc.3 vis.3 wordexp.3
+ nice.3 \
+ nlist.3 \
+ pause.3 \
+ popen.3 \
+ posix_spawn.3 \
+ posix_spawn_file_actions_addopen.3 \
+ posix_spawn_file_actions_init.3 \
+ posix_spawnattr_getflags.3 \
+ posix_spawnattr_getpgroup.3 \
+ posix_spawnattr_getschedparam.3 \
+ posix_spawnattr_getschedpolicy.3 \
+ posix_spawnattr_init.3 \
+ posix_spawnattr_getsigdefault.3 \
+ posix_spawnattr_getsigmask.3 \
+ psignal.3 \
+ pwcache.3 \
+ raise.3 \
+ rand48.3 \
+ readpassphrase.3 \
+ rfork_thread.3 \
+ scandir.3 \
+ sem_destroy.3 \
+ sem_getvalue.3 \
+ sem_init.3 \
+ sem_open.3 \
+ sem_post.3 \
+ sem_timedwait.3 \
+ sem_wait.3 \
+ setjmp.3 \
+ setmode.3 \
+ setproctitle.3 \
+ siginterrupt.3 \
+ signal.3 \
+ sigsetops.3 \
+ sleep.3 \
+ statvfs.3 \
+ stringlist.3 \
+ strtofflags.3 \
+ sysconf.3 \
+ sysctl.3 \
+ syslog.3 \
+ tcgetpgrp.3 \
+ tcgetsid.3 \
+ tcsendbreak.3 \
+ tcsetattr.3 \
+ tcsetpgrp.3 \
+ tcsetsid.3 \
+ time.3 \
+ times.3 \
+ timezone.3 \
+ ttyname.3 \
+ tzset.3 \
+ ualarm.3 \
+ ucontext.3 \
+ ulimit.3 \
+ uname.3 \
+ unvis.3 \
+ usleep.3 \
+ utime.3 \
+ valloc.3 \
+ vis.3 \
+ wordexp.3
-MLINKS+=arc4random.3 arc4random_addrandom.3 arc4random.3 arc4random_stir.3 \
- arc4random.3 arc4random_buf.3 arc4random.3 arc4random_uniform.3
+MLINKS+=arc4random.3 arc4random_addrandom.3 \
+ arc4random.3 arc4random_stir.3 \
+ arc4random.3 arc4random_buf.3 \
+ arc4random.3 arc4random_uniform.3
MLINKS+=basename.3 basename_r.3
MLINKS+=ctermid.3 ctermid_r.3
MLINKS+=devname.3 devname_r.3
MLINKS+=devname.3 fdevname.3
MLINKS+=devname.3 fdevname_r.3
-MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \
+MLINKS+=directory.3 closedir.3 \
+ directory.3 dirfd.3 \
+ directory.3 opendir.3 \
directory.3 fdopendir.3 \
- directory.3 readdir.3 directory.3 readdir_r.3 directory.3 rewinddir.3 \
- directory.3 seekdir.3 directory.3 telldir.3
-MLINKS+=dlopen.3 fdlopen.3 dlopen.3 dlclose.3 dlopen.3 dlerror.3 \
- dlopen.3 dlfunc.3 dlopen.3 dlsym.3
-MLINKS+=err.3 err_set_exit.3 err.3 err_set_file.3 err.3 errc.3 err.3 errx.3 \
- err.3 verr.3 err.3 verrc.3 err.3 verrx.3 err.3 vwarn.3 err.3 vwarnc.3 \
- err.3 vwarnx.3 err.3 warnc.3 err.3 warn.3 err.3 warnx.3
-MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 exect.3 \
- exec.3 execv.3 exec.3 execvP.3 exec.3 execvp.3
-MLINKS+=fpclassify.3 finite.3 fpclassify.3 finitef.3 \
- fpclassify.3 isfinite.3 fpclassify.3 isinf.3 fpclassify.3 isnan.3 \
+ directory.3 readdir.3 \
+ directory.3 readdir_r.3 \
+ directory.3 rewinddir.3 \
+ directory.3 seekdir.3 \
+ directory.3 telldir.3
+MLINKS+=dlopen.3 fdlopen.3 \
+ dlopen.3 dlclose.3 \
+ dlopen.3 dlerror.3 \
+ dlopen.3 dlfunc.3 \
+ dlopen.3 dlsym.3
+MLINKS+=err.3 err_set_exit.3 \
+ err.3 err_set_file.3 \
+ err.3 errc.3 \
+ err.3 errx.3 \
+ err.3 verr.3 \
+ err.3 verrc.3 \
+ err.3 verrx.3 \
+ err.3 vwarn.3 \
+ err.3 vwarnc.3 \
+ err.3 vwarnx.3 \
+ err.3 warnc.3 \
+ err.3 warn.3 \
+ err.3 warnx.3
+MLINKS+=exec.3 execl.3 \
+ exec.3 execle.3 \
+ exec.3 execlp.3 \
+ exec.3 exect.3 \
+ exec.3 execv.3 \
+ exec.3 execvP.3 \
+ exec.3 execvp.3
+MLINKS+=fpclassify.3 finite.3 \
+ fpclassify.3 finitef.3 \
+ fpclassify.3 isfinite.3 \
+ fpclassify.3 isinf.3 \
+ fpclassify.3 isnan.3 \
fpclassify.3 isnormal.3
-MLINKS+=frexp.3 frexpf.3 frexp.3 frexpl.3
-MLINKS+=fts.3 fts_children.3 fts.3 fts_close.3 fts.3 fts_open.3 \
- fts.3 fts_read.3 fts.3 fts_set.3 fts.3 fts_set_clientptr.3 \
- fts.3 fts_get_clientptr.3 fts.3 fts_get_stream.3
+MLINKS+=frexp.3 frexpf.3 \
+ frexp.3 frexpl.3
+MLINKS+=fts.3 fts_children.3 \
+ fts.3 fts_close.3 \
+ fts.3 fts_open.3 \
+ fts.3 fts_read.3 \
+ fts.3 fts_set.3 \
+ fts.3 fts_set_clientptr.3 \
+ fts.3 fts_get_clientptr.3 \
+ fts.3 fts_get_stream.3
MLINKS+=ftw.3 nftw.3
-MLINKS+=getcap.3 cgetcap.3 getcap.3 cgetclose.3 getcap.3 cgetent.3 \
- getcap.3 cgetfirst.3 getcap.3 cgetmatch.3 getcap.3 cgetnext.3 \
- getcap.3 cgetnum.3 getcap.3 cgetset.3 getcap.3 cgetstr.3 \
+MLINKS+=getcap.3 cgetcap.3 \
+ getcap.3 cgetclose.3 \
+ getcap.3 cgetent.3 \
+ getcap.3 cgetfirst.3 \
+ getcap.3 cgetmatch.3 \
+ getcap.3 cgetnext.3 \
+ getcap.3 cgetnum.3 \
+ getcap.3 cgetset.3 \
+ getcap.3 cgetstr.3 \
getcap.3 cgetustr.3
MLINKS+=getcwd.3 getwd.3
MLINKS+=getcontext.3 setcontext.3
MLINKS+=getdomainname.3 setdomainname.3
-MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \
- getfsent.3 getfstype.3 getfsent.3 setfsent.3 \
- getfsent.3 setfstab.3 getfsent.3 getfstab.3
-MLINKS+=getgrent.3 endgrent.3 getgrent.3 getgrgid.3 getgrent.3 getgrnam.3 \
- getgrent.3 setgrent.3 getgrent.3 setgroupent.3 \
- getgrent.3 getgrent_r.3 getgrent.3 getgrnam_r.3 getgrent.3 getgrgid_r.3
+MLINKS+=getfsent.3 endfsent.3 \
+ getfsent.3 getfsfile.3 \
+ getfsent.3 getfsspec.3 \
+ getfsent.3 getfstype.3 \
+ getfsent.3 setfsent.3 \
+ getfsent.3 setfstab.3 \
+ getfsent.3 getfstab.3
+MLINKS+=getgrent.3 endgrent.3 \
+ getgrent.3 getgrgid.3 \
+ getgrent.3 getgrnam.3 \
+ getgrent.3 setgrent.3 \
+ getgrent.3 setgroupent.3 \
+ getgrent.3 getgrent_r.3 \
+ getgrent.3 getgrnam_r.3 \
+ getgrent.3 getgrgid_r.3
MLINKS+=gethostname.3 sethostname.3
-MLINKS+=getnetgrent.3 endnetgrent.3 getnetgrent.3 innetgr.3 \
+MLINKS+=getnetgrent.3 endnetgrent.3 \
+ getnetgrent.3 innetgr.3 \
getnetgrent.3 setnetgrent.3
MLINKS+=getprogname.3 setprogname.3
-MLINKS+=getpwent.3 endpwent.3 getpwent.3 getpwnam.3 getpwent.3 getpwuid.3 \
- getpwent.3 setpassent.3 getpwent.3 setpwent.3 getpwent.3 setpwfile.3 \
- getpwent.3 getpwent_r.3 getpwent.3 getpwnam_r.3 \
+MLINKS+=getpwent.3 endpwent.3 \
+ getpwent.3 getpwnam.3 \
+ getpwent.3 getpwuid.3 \
+ getpwent.3 setpassent.3 \
+ getpwent.3 setpwent.3 \
+ getpwent.3 setpwfile.3 \
+ getpwent.3 getpwent_r.3 \
+ getpwent.3 getpwnam_r.3 \
getpwent.3 getpwuid_r.3
-MLINKS+=getttyent.3 endttyent.3 getttyent.3 getttynam.3 \
- getttyent.3 isdialuptty.3 getttyent.3 isnettty.3 \
+MLINKS+=getttyent.3 endttyent.3 \
+ getttyent.3 getttynam.3 \
+ getttyent.3 isdialuptty.3 \
+ getttyent.3 isnettty.3 \
getttyent.3 setttyent.3
-MLINKS+=getusershell.3 endusershell.3 getusershell.3 setusershell.3
-MLINKS+=getutxent.3 endutxent.3 getutxent.3 getutxid.3 \
- getutxent.3 getutxline.3 getutxent.3 getutxuser.3 \
- getutxent.3 pututxline.3 getutxent.3 setutxdb.3 \
- getutxent.3 setutxent.3 getutxent.3 utmpx.3
+MLINKS+=getusershell.3 endusershell.3 \
+ getusershell.3 setusershell.3
+MLINKS+=getutxent.3 endutxent.3 \
+ getutxent.3 getutxid.3 \
+ getutxent.3 getutxline.3 \
+ getutxent.3 getutxuser.3 \
+ getutxent.3 pututxline.3 \
+ getutxent.3 setutxdb.3 \
+ getutxent.3 setutxent.3 \
+ getutxent.3 utmpx.3
MLINKS+=glob.3 globfree.3
-MLINKS+=isgreater.3 isgreaterequal.3 isgreater.3 isless.3 \
- isgreater.3 islessequal.3 isgreater.3 islessgreater.3 \
+MLINKS+=isgreater.3 isgreaterequal.3 \
+ isgreater.3 isless.3 \
+ isgreater.3 islessequal.3 \
+ isgreater.3 islessgreater.3 \
isgreater.3 isunordered.3
-MLINKS+=ldexp.3 ldexpf.3 ldexp.3 ldexpl.3
+MLINKS+=ldexp.3 ldexpf.3 \
+ ldexp.3 ldexpl.3
MLINKS+=makecontext.3 swapcontext.3
-MLINKS+=modf.3 modff.3 modf.3 modfl.3
+MLINKS+=modf.3 modff.3 \
+ modf.3 modfl.3
MLINKS+=popen.3 pclose.3
MLINKS+=posix_spawn.3 posix_spawnp.3 \
posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addclose.3 \
@@ -165,36 +428,66 @@ MLINKS+=posix_spawn.3 posix_spawnp.3 \
posix_spawnattr_getsigdefault.3 posix_spawnattr_setsigdefault.3 \
posix_spawnattr_getsigmask.3 posix_spawnattr_setsigmask.3 \
posix_spawnattr_init.3 posix_spawnattr_destroy.3
-MLINKS+=psignal.3 strsignal.3 psignal.3 sys_siglist.3 psignal.3 sys_signame.3
-MLINKS+=pwcache.3 group_from_gid.3 pwcache.3 user_from_uid.3
-MLINKS+=rand48.3 _rand48.3 rand48.3 drand48.3 rand48.3 erand48.3 \
- rand48.3 jrand48.3 rand48.3 lcong48.3 rand48.3 lrand48.3 \
- rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 seed48.3 \
+MLINKS+=psignal.3 strsignal.3 \
+ psignal.3 sys_siglist.3 \
+ psignal.3 sys_signame.3
+MLINKS+=pwcache.3 group_from_gid.3 \
+ pwcache.3 user_from_uid.3
+MLINKS+=rand48.3 _rand48.3 \
+ rand48.3 drand48.3 \
+ rand48.3 erand48.3 \
+ rand48.3 jrand48.3 \
+ rand48.3 lcong48.3 \
+ rand48.3 lrand48.3 \
+ rand48.3 mrand48.3 \
+ rand48.3 nrand48.3 \
+ rand48.3 seed48.3 \
rand48.3 srand48.3
MLINKS+=scandir.3 alphasort.3
-MLINKS+=sem_open.3 sem_close.3 sem_open.3 sem_unlink.3
+MLINKS+=sem_open.3 sem_close.3 \
+ sem_open.3 sem_unlink.3
MLINKS+=sem_wait.3 sem_trywait.3
-MLINKS+=setjmp.3 _longjmp.3 setjmp.3 _setjmp.3 setjmp.3 longjmp.3 \
- setjmp.3 longjmperr.3 setjmp.3 longjmperror.3 \
- setjmp.3 siglongjmp.3 setjmp.3 sigsetjmp.3
+MLINKS+=setjmp.3 _longjmp.3 \
+ setjmp.3 _setjmp.3 \
+ setjmp.3 longjmp.3 \
+ setjmp.3 longjmperr.3 \
+ setjmp.3 longjmperror.3 \
+ setjmp.3 siglongjmp.3 \
+ setjmp.3 sigsetjmp.3
MLINKS+=setmode.3 getmode.3
-MLINKS+=sigsetops.3 sigaddset.3 sigsetops.3 sigdelset.3 \
- sigsetops.3 sigemptyset.3 sigsetops.3 sigfillset.3 \
+MLINKS+=sigsetops.3 sigaddset.3 \
+ sigsetops.3 sigdelset.3 \
+ sigsetops.3 sigemptyset.3 \
+ sigsetops.3 sigfillset.3 \
sigsetops.3 sigismember.3
MLINKS+=statvfs.3 fstatvfs.3
-MLINKS+=stringlist.3 sl_add.3 stringlist.3 sl_find.3 \
- stringlist.3 sl_free.3 stringlist.3 sl_init.3
+MLINKS+=stringlist.3 sl_add.3 \
+ stringlist.3 sl_find.3 \
+ stringlist.3 sl_free.3 \
+ stringlist.3 sl_init.3
MLINKS+=strtofflags.3 fflagstostr.3
-MLINKS+=sysctl.3 sysctlbyname.3 sysctl.3 sysctlnametomib.3
-MLINKS+=syslog.3 closelog.3 syslog.3 openlog.3 syslog.3 setlogmask.3 \
+MLINKS+=sysctl.3 sysctlbyname.3 \
+ sysctl.3 sysctlnametomib.3
+MLINKS+=syslog.3 closelog.3 \
+ syslog.3 openlog.3 \
+ syslog.3 setlogmask.3 \
syslog.3 vsyslog.3
-MLINKS+=tcsendbreak.3 tcdrain.3 tcsendbreak.3 tcflow.3 tcsendbreak.3 tcflush.3
-MLINKS+=tcsetattr.3 cfgetispeed.3 tcsetattr.3 cfgetospeed.3 \
- tcsetattr.3 cfmakeraw.3 tcsetattr.3 cfmakesane.3 \
- tcsetattr.3 cfsetispeed.3 tcsetattr.3 cfsetospeed.3 \
- tcsetattr.3 cfsetspeed.3 tcsetattr.3 tcgetattr.3
-MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyname_r.3
+MLINKS+=tcsendbreak.3 tcdrain.3 \
+ tcsendbreak.3 tcflow.3 \
+ tcsendbreak.3 tcflush.3
+MLINKS+=tcsetattr.3 cfgetispeed.3 \
+ tcsetattr.3 cfgetospeed.3 \
+ tcsetattr.3 cfmakeraw.3 \
+ tcsetattr.3 cfmakesane.3 \
+ tcsetattr.3 cfsetispeed.3 \
+ tcsetattr.3 cfsetospeed.3 \
+ tcsetattr.3 cfsetspeed.3 \
+ tcsetattr.3 tcgetattr.3
+MLINKS+=ttyname.3 isatty.3 \
+ ttyname.3 ttyname_r.3
MLINKS+=tzset.3 tzsetwall.3
-MLINKS+=unvis.3 strunvis.3 unvis.3 strunvisx.3
-MLINKS+=vis.3 strvis.3 vis.3 strvisx.3
+MLINKS+=unvis.3 strunvis.3 \
+ unvis.3 strunvisx.3
+MLINKS+=vis.3 strvis.3 \
+ vis.3 strvisx.3
MLINKS+=wordexp.3 wordfree.3
diff --git a/lib/libc/gen/sem_new.c b/lib/libc/gen/sem_new.c
index b11d547..1bf84ea 100644
--- a/lib/libc/gen/sem_new.c
+++ b/lib/libc/gen/sem_new.c
@@ -198,15 +198,11 @@ _sem_open(const char *name, int flags, ...)
goto error;
}
- fd = _open(path, flags|O_RDWR|O_CLOEXEC, mode);
+ fd = _open(path, flags|O_RDWR|O_CLOEXEC|O_EXLOCK, mode);
if (fd == -1)
goto error;
- if (flock(fd, LOCK_EX) == -1)
+ if (_fstat(fd, &sb))
goto error;
- if (_fstat(fd, &sb)) {
- flock(fd, LOCK_UN);
- goto error;
- }
if (sb.st_size < sizeof(sem_t)) {
sem_t tmp;
@@ -214,10 +210,8 @@ _sem_open(const char *name, int flags, ...)
tmp._kern._has_waiters = 0;
tmp._kern._count = value;
tmp._kern._flags = USYNC_PROCESS_SHARED | SEM_NAMED;
- if (_write(fd, &tmp, sizeof(tmp)) != sizeof(tmp)) {
- flock(fd, LOCK_UN);
+ if (_write(fd, &tmp, sizeof(tmp)) != sizeof(tmp))
goto error;
- }
}
flock(fd, LOCK_UN);
sem = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ|PROT_WRITE,
@@ -235,18 +229,18 @@ _sem_open(const char *name, int flags, ...)
ni->open_count = 1;
ni->sem = sem;
LIST_INSERT_HEAD(&sem_list, ni, next);
- _pthread_mutex_unlock(&sem_llock);
_close(fd);
+ _pthread_mutex_unlock(&sem_llock);
return (sem);
error:
errsave = errno;
- _pthread_mutex_unlock(&sem_llock);
if (fd != -1)
_close(fd);
if (sem != NULL)
munmap(sem, sizeof(sem_t));
free(ni);
+ _pthread_mutex_unlock(&sem_llock);
errno = errsave;
return (SEM_FAILED);
}
diff --git a/lib/libc/stdio/setbuf.3 b/lib/libc/stdio/setbuf.3
index 337a7c5..d1ae70b 100644
--- a/lib/libc/stdio/setbuf.3
+++ b/lib/libc/stdio/setbuf.3
@@ -32,7 +32,7 @@
.\" @(#)setbuf.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd February 15, 2013
+.Dd February 18, 2013
.Dt SETBUF 3
.Os
.Sh NAME
@@ -195,3 +195,6 @@ and
functions
conform to
.St -isoC .
+.Sh BUGS
+.Fn setbuf
+usually uses a suboptimal buffer size and should be avoided.
diff --git a/lib/libc/stdlib/bsearch.3 b/lib/libc/stdlib/bsearch.3
index b3591f8e..25be842 100644
--- a/lib/libc/stdlib/bsearch.3
+++ b/lib/libc/stdlib/bsearch.3
@@ -32,7 +32,7 @@
.\" @(#)bsearch.3 8.3 (Berkeley) 4/19/94
.\" $FreeBSD$
.\"
-.Dd April 19, 1994
+.Dd February 22, 2013
.Dt BSEARCH 3
.Os
.Sh NAME
@@ -71,6 +71,12 @@ less than, equal to, or greater than zero if the
.Fa key
object is found, respectively, to be less than, to match, or be
greater than the array member.
+See the
+.Fa int_compare
+sample function in
+.Xr qsort 3
+for a comparison function that is also compatible with
+.Fn bsearch .
.Sh RETURN VALUES
The
.Fn bsearch
diff --git a/lib/libc/stdlib/qsort.3 b/lib/libc/stdlib/qsort.3
index 0f7ef73..f34d260 100644
--- a/lib/libc/stdlib/qsort.3
+++ b/lib/libc/stdlib/qsort.3
@@ -32,7 +32,7 @@
.\" @(#)qsort.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd September 30, 2003
+.Dd February 20, 2013
.Dt QSORT 3
.Os
.Sh NAME
@@ -205,6 +205,46 @@ functions
return no value.
.Pp
.Rv -std heapsort mergesort
+.Sh EXAMPLES
+A sample program that sorts an array of
+.Vt int
+values in place using
+.Fn qsort ,
+and then prints the sorted array to standard output is:
+.Bd -literal
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+ * Custom comparison function that can compare 'int' values through pointers
+ * passed by qsort(3).
+ */
+static int
+int_compare(const void *p1, const void *p2)
+{
+ int left = *(const int *)p1;
+ int right = *(const int *)p2;
+
+ return ((left > right) - (left < right));
+}
+
+/*
+ * Sort an array of 'int' values and print it to standard output.
+ */
+int
+main(void)
+{
+ int int_array[] = { 4, 5, 9, 3, 0, 1, 7, 2, 8, 6 };
+ const size_t array_size = sizeof(int_array) / sizeof(int_array[0]);
+ size_t k;
+
+ qsort(&int_array, array_size, sizeof(int_array[0]), int_compare);
+ for (k = 0; k < array_size; k++)
+ printf(" %d", int_array[k]);
+ puts("");
+ return (EXIT_SUCCESS);
+}
+.Ed
.Sh COMPATIBILITY
Previous versions of
.Fn qsort
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index a35ed5d..9f216dc 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -78,59 +78,212 @@ ${SPSEUDO}:
>> ${.TARGET}
printf ${NOTE_GNU_STACK} >>${.TARGET}
-MAN+= abort2.2 accept.2 access.2 acct.2 adjtime.2 \
- aio_cancel.2 aio_error.2 aio_read.2 aio_return.2 \
- aio_suspend.2 aio_waitcomplete.2 aio_write.2 \
- bind.2 brk.2 cap_enter.2 cap_new.2 chdir.2 chflags.2 \
- chmod.2 chown.2 chroot.2 clock_gettime.2 close.2 closefrom.2 \
- connect.2 cpuset.2 cpuset_getaffinity.2 dup.2 execve.2 _exit.2 \
- extattr_get_file.2 fcntl.2 ffclock.2 fhopen.2 flock.2 fork.2 fsync.2 \
- getdirentries.2 getdtablesize.2 \
- getfh.2 getfsstat.2 getgid.2 getgroups.2 getitimer.2 getlogin.2 \
- getloginclass.2 getpeername.2 getpgrp.2 getpid.2 getpriority.2 \
- getrlimit.2 getrusage.2 getsid.2 getsockname.2 \
- getsockopt.2 gettimeofday.2 getuid.2 \
- intro.2 ioctl.2 issetugid.2 jail.2 kenv.2 kill.2 \
- kldfind.2 kldfirstmod.2 kldload.2 kldnext.2 kldstat.2 kldsym.2 \
- kldunload.2 kqueue.2 ktrace.2 link.2 lio_listio.2 listen.2 \
+MAN+= abort2.2 \
+ accept.2 \
+ access.2 \
+ acct.2 \
+ adjtime.2 \
+ aio_cancel.2 \
+ aio_error.2 \
+ aio_read.2 \
+ aio_return.2 \
+ aio_suspend.2 \
+ aio_waitcomplete.2 \
+ aio_write.2 \
+ bind.2 \
+ brk.2 \
+ cap_enter.2 \
+ cap_new.2 \
+ chdir.2 \
+ chflags.2 \
+ chmod.2 \
+ chown.2 \
+ chroot.2 \
+ clock_gettime.2 \
+ close.2 \
+ closefrom.2 \
+ connect.2 \
+ cpuset.2 \
+ cpuset_getaffinity.2 \
+ dup.2 \
+ execve.2 \
+ _exit.2 \
+ extattr_get_file.2 \
+ fcntl.2 \
+ ffclock.2 \
+ fhopen.2 \
+ flock.2 \
+ fork.2 \
+ fsync.2 \
+ getdirentries.2 \
+ getdtablesize.2 \
+ getfh.2 \
+ getfsstat.2 \
+ getgid.2 \
+ getgroups.2 \
+ getitimer.2 \
+ getlogin.2 \
+ getloginclass.2 \
+ getpeername.2 \
+ getpgrp.2 \
+ getpid.2 \
+ getpriority.2 \
+ getrlimit.2 \
+ getrusage.2 \
+ getsid.2 \
+ getsockname.2 \
+ getsockopt.2 \
+ gettimeofday.2 \
+ getuid.2 \
+ intro.2 \
+ ioctl.2 \
+ issetugid.2 \
+ jail.2 \
+ kenv.2 \
+ kill.2 \
+ kldfind.2 \
+ kldfirstmod.2 \
+ kldload.2 \
+ kldnext.2 \
+ kldstat.2 \
+ kldsym.2 \
+ kldunload.2 \
+ kqueue.2 \
+ ktrace.2 \
+ link.2 \
+ lio_listio.2 \
+ listen.2 \
lseek.2 \
- madvise.2 mincore.2 minherit.2 mkdir.2 mkfifo.2 mknod.2 mlock.2 \
- mlockall.2 mmap.2 modfind.2 modnext.2 modstat.2 mount.2 mprotect.2 \
- mq_close.2 mq_getattr.2 mq_notify.2 mq_open.2 mq_receive.2 mq_send.2 \
+ madvise.2 \
+ mincore.2 \
+ minherit.2 \
+ mkdir.2 \
+ mkfifo.2 \
+ mknod.2 \
+ mlock.2 \
+ mlockall.2 \
+ mmap.2 \
+ modfind.2 \
+ modnext.2 \
+ modstat.2 \
+ mount.2 \
+ mprotect.2 \
+ mq_close.2 \
+ mq_getattr.2 \
+ mq_notify.2 \
+ mq_open.2 \
+ mq_receive.2 \
+ mq_send.2 \
mq_setattr.2 \
- msgctl.2 msgget.2 msgrcv.2 msgsnd.2 \
- msync.2 munmap.2 nanosleep.2 nfssvc.2 ntp_adjtime.2 open.2 \
- pathconf.2 pdfork.2 pipe.2 poll.2 posix_fadvise.2 posix_fallocate.2 \
- posix_openpt.2 profil.2 \
- pselect.2 ptrace.2 quotactl.2 \
- read.2 readlink.2 reboot.2 recv.2 rename.2 revoke.2 rfork.2 rmdir.2 \
+ msgctl.2 \
+ msgget.2 \
+ msgrcv.2 \
+ msgsnd.2 \
+ msync.2 \
+ munmap.2 \
+ nanosleep.2 \
+ nfssvc.2 \
+ ntp_adjtime.2 \
+ open.2 \
+ pathconf.2 \
+ pdfork.2 \
+ pipe.2 \
+ poll.2 \
+ posix_fadvise.2 \
+ posix_fallocate.2 \
+ posix_openpt.2 \
+ profil.2 \
+ pselect.2 \
+ ptrace.2 \
+ quotactl.2 \
+ read.2 \
+ readlink.2 \
+ reboot.2 \
+ recv.2 \
+ rename.2 \
+ revoke.2 \
+ rfork.2 \
+ rmdir.2 \
rtprio.2
.if !defined(NO_P1003_1B)
-MAN+= sched_get_priority_max.2 sched_setparam.2 \
- sched_setscheduler.2 sched_yield.2
+MAN+= sched_get_priority_max.2 \
+ sched_setparam.2 \
+ sched_setscheduler.2 \
+ sched_yield.2
.endif
-MAN+= sctp_generic_recvmsg.2 sctp_generic_sendmsg.2 sctp_peeloff.2 \
- select.2 semctl.2 semget.2 semop.2 send.2 setfib.2 sendfile.2 \
- setgroups.2 setpgid.2 setregid.2 setresuid.2 setreuid.2 setsid.2 \
- setuid.2 shmat.2 shmctl.2 shmget.2 shm_open.2 shutdown.2 \
- sigaction.2 sigaltstack.2 sigpending.2 sigprocmask.2 sigqueue.2 \
- sigreturn.2 sigstack.2 sigsuspend.2 sigwait.2 sigwaitinfo.2 \
- socket.2 socketpair.2 stat.2 statfs.2 \
- swapon.2 symlink.2 sync.2 sysarch.2 syscall.2 \
- timer_create.2 timer_delete.2 timer_settime.2 \
- truncate.2 umask.2 undelete.2 \
- unlink.2 utimes.2 utrace.2 uuidgen.2 vfork.2 wait.2 write.2
-
-MLINKS+=access.2 eaccess.2 access.2 faccessat.2
+MAN+= sctp_generic_recvmsg.2 \
+ sctp_generic_sendmsg.2 \
+ sctp_peeloff.2 \
+ select.2 \
+ semctl.2 \
+ semget.2 \
+ semop.2 \
+ send.2 \
+ setfib.2 \
+ sendfile.2 \
+ setgroups.2 \
+ setpgid.2 \
+ setregid.2 \
+ setresuid.2 \
+ setreuid.2 \
+ setsid.2 \
+ setuid.2 \
+ shmat.2 \
+ shmctl.2 \
+ shmget.2 \
+ shm_open.2 \
+ shutdown.2 \
+ sigaction.2 \
+ sigaltstack.2 \
+ sigpending.2 \
+ sigprocmask.2 \
+ sigqueue.2 \
+ sigreturn.2 \
+ sigstack.2 \
+ sigsuspend.2 \
+ sigwait.2 \
+ sigwaitinfo.2 \
+ socket.2 \
+ socketpair.2 \
+ stat.2 \
+ statfs.2 \
+ swapon.2 \
+ symlink.2 \
+ sync.2 \
+ sysarch.2 \
+ syscall.2 \
+ timer_create.2 \
+ timer_delete.2 \
+ timer_settime.2 \
+ truncate.2 \
+ umask.2 \
+ undelete.2 \
+ unlink.2 \
+ utimes.2 \
+ utrace.2 \
+ uuidgen.2 \
+ vfork.2 \
+ wait.2 \
+ write.2
+
+MLINKS+=access.2 eaccess.2 \
+ access.2 faccessat.2
MLINKS+=brk.2 sbrk.2
MLINKS+=cap_enter.2 cap_getmode.2
MLINKS+=cap_new.2 cap_getrights.2
MLINKS+=chdir.2 fchdir.2
-MLINKS+=chflags.2 fchflags.2 chflags.2 lchflags.2
-MLINKS+=chmod.2 fchmod.2 chmod.2 fchmodat.2 chmod.2 lchmod.2
-MLINKS+=chown.2 fchown.2 chown.2 fchownat.2 chown.2 lchown.2
-MLINKS+=clock_gettime.2 clock_getres.2 clock_gettime.2 clock_settime.2
-MLINKS+=cpuset.2 cpuset_getid.2 cpuset.2 cpuset_setid.2
+MLINKS+=chflags.2 fchflags.2 \
+ chflags.2 lchflags.2
+MLINKS+=chmod.2 fchmod.2 \
+ chmod.2 fchmodat.2 \
+ chmod.2 lchmod.2
+MLINKS+=chown.2 fchown.2 \
+ chown.2 fchownat.2 \
+ chown.2 lchown.2
+MLINKS+=clock_gettime.2 clock_getres.2 \
+ clock_gettime.2 clock_settime.2
+MLINKS+=cpuset.2 cpuset_getid.2 \
+ cpuset.2 cpuset_setid.2
MLINKS+=cpuset_getaffinity.2 cpuset_setaffinity.2
MLINKS+=dup.2 dup2.2
MLINKS+=execve.2 fexecve.2
@@ -146,7 +299,8 @@ MLINKS+=extattr_get_file.2 extattr.2 \
extattr_get_file.2 extattr_set_fd.2 \
extattr_get_file.2 extattr_set_file.2 \
extattr_get_file.2 extattr_set_link.2
-MLINKS+=ffclock.2 ffclock_getcounter.2 ffclock.2 ffclock_getestimate.2 \
+MLINKS+=ffclock.2 ffclock_getcounter.2 \
+ ffclock.2 ffclock_getestimate.2 \
ffclock.2 ffclock_setestimate.2
MLINKS+=fhopen.2 fhstat.2 fhopen.2 fhstatfs.2
MLINKS+=getdirentries.2 getdents.2
@@ -169,7 +323,8 @@ MLINKS+=jail.2 jail_attach.2 \
jail.2 jail_remove.2 \
jail.2 jail_set.2
MLINKS+=kldunload.2 kldunloadf.2
-MLINKS+=kqueue.2 kevent.2 kqueue.2 EV_SET.3
+MLINKS+=kqueue.2 kevent.2 \
+ kqueue.2 EV_SET.3
MLINKS+=link.2 linkat.2
MLINKS+=madvise.2 posix_madvise.2
MLINKS+=mkdir.2 mkdirat.2
@@ -178,7 +333,8 @@ MLINKS+=mknod.2 mknodat.2
MLINKS+=mlock.2 munlock.2
MLINKS+=mlockall.2 munlockall.2
MLINKS+=modnext.2 modfnext.2
-MLINKS+=mount.2 nmount.2 mount.2 unmount.2
+MLINKS+=mount.2 nmount.2 \
+ mount.2 unmount.2
MLINKS+=mq_receive.2 mq_timedreceive.2
MLINKS+=mq_send.2 mq_timedsend.2
MLINKS+=ntp_adjtime.2 ntp_gettime.2
@@ -188,9 +344,12 @@ MLINKS+=pathconf.2 lpathconf.2
MLINKS+=pdfork.2 pdgetpid.2\
pdfork.2 pdkill.2 \
pdfork.2 pdwait4.2
-MLINKS+=read.2 pread.2 read.2 preadv.2 read.2 readv.2
+MLINKS+=read.2 pread.2 \
+ read.2 preadv.2 \
+ read.2 readv.2
MLINKS+=readlink.2 readlinkat.2
-MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2
+MLINKS+=recv.2 recvfrom.2 \
+ recv.2 recvmsg.2
MLINKS+=rename.2 renameat.2
MLINKS+=rtprio.2 rtprio_thread.2
.if !defined(NO_P1003_1B)
@@ -199,24 +358,41 @@ MLINKS+=sched_get_priority_max.2 sched_get_priority_min.2 \
MLINKS+=sched_setparam.2 sched_getparam.2
MLINKS+=sched_setscheduler.2 sched_getscheduler.2
.endif
-MLINKS+=select.2 FD_CLR.3 select.2 FD_ISSET.3 select.2 FD_SET.3 \
+MLINKS+=select.2 FD_CLR.3 \
+ select.2 FD_ISSET.3 \
+ select.2 FD_SET.3 \
select.2 FD_ZERO.3
-MLINKS+=send.2 sendmsg.2 send.2 sendto.2
+MLINKS+=send.2 sendmsg.2 \
+ send.2 sendto.2
MLINKS+=setpgid.2 setpgrp.2
-MLINKS+=setresuid.2 getresgid.2 setresuid.2 getresuid.2 setresuid.2 setresgid.2
-MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2
+MLINKS+=setresuid.2 getresgid.2 \
+ setresuid.2 getresuid.2 \
+ setresuid.2 setresgid.2
+MLINKS+=setuid.2 setegid.2 \
+ setuid.2 seteuid.2 \
+ setuid.2 setgid.2
MLINKS+=shmat.2 shmdt.2
MLINKS+=shm_open.2 shm_unlink.2
MLINKS+=sigwaitinfo.2 sigtimedwait.2
-MLINKS+=stat.2 fstat.2 stat.2 fstatat.2 stat.2 lstat.2
+MLINKS+=stat.2 fstat.2 \
+ stat.2 fstatat.2 \
+ stat.2 lstat.2
MLINKS+=statfs.2 fstatfs.2
MLINKS+=swapon.2 swapoff.2
MLINKS+=symlink.2 symlinkat.2
MLINKS+=syscall.2 __syscall.2
-MLINKS+=timer_settime.2 timer_getoverrun.2 timer_settime.2 timer_gettime.2
+MLINKS+=timer_settime.2 timer_getoverrun.2 \
+ timer_settime.2 timer_gettime.2
MLINKS+=truncate.2 ftruncate.2
MLINKS+=unlink.2 unlinkat.2
-MLINKS+=utimes.2 futimes.2 utimes.2 futimesat.2 utimes.2 lutimes.2
-MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2 \
- wait.2 waitid.2 wait.2 wait6.2
-MLINKS+=write.2 pwrite.2 write.2 pwritev.2 write.2 writev.2
+MLINKS+=utimes.2 futimes.2 \
+ utimes.2 futimesat.2 \
+ utimes.2 lutimes.2
+MLINKS+=wait.2 wait3.2 \
+ wait.2 wait4.2 \
+ wait.2 waitpid.2 \
+ wait.2 waitid.2 \
+ wait.2 wait6.2
+MLINKS+=write.2 pwrite.2 \
+ write.2 pwritev.2 \
+ write.2 writev.2
diff --git a/lib/libelf/elf_data.c b/lib/libelf/elf_data.c
index c34c4ad..d3bd390 100644
--- a/lib/libelf/elf_data.c
+++ b/lib/libelf/elf_data.c
@@ -78,8 +78,10 @@ elf_getdata(Elf_Scn *s, Elf_Data *d)
sh_align = s->s_shdr.s_shdr64.sh_addralign;
}
- if (sh_type == SHT_NULL)
+ if (sh_type == SHT_NULL) {
+ LIBELF_SET_ERROR(SECTION, 0);
return (NULL);
+ }
if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST ||
elftype > ELF_T_LAST || (sh_type != SHT_NOBITS &&
@@ -219,8 +221,10 @@ elf_rawdata(Elf_Scn *s, Elf_Data *d)
sh_align = s->s_shdr.s_shdr64.sh_addralign;
}
- if (sh_type == SHT_NULL)
+ if (sh_type == SHT_NULL) {
+ LIBELF_SET_ERROR(SECTION, 0);
return (NULL);
+ }
if ((d = _libelf_allocate_data(s)) == NULL)
return (NULL);
diff --git a/lib/libelf/elf_getdata.3 b/lib/libelf/elf_getdata.3
index 97766d8..7961220 100644
--- a/lib/libelf/elf_getdata.3
+++ b/lib/libelf/elf_getdata.3
@@ -23,7 +23,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 26, 2011
+.Dd February 18, 2013
.Dt ELF_GETDATA 3
.Os
.Sh NAME
@@ -186,6 +186,23 @@ was not associated with section descriptor
.Ar scn .
.It Bq Er ELF_E_RESOURCE
An out of memory condition was detected.
+.It Bq Er ELF_E_SECTION
+Section
+.Ar scn
+had type
+.Dv SHT_NULL .
+.It Bq Er ELF_E_SECTION
+The type of the section
+.Ar scn
+was not recognized by the library.
+.It Bq Er ELF_E_SECTION
+The size of the section
+.Ar scn
+is not a multiple of the file size for its section type.
+.It Bq Er ELF_E_SECTION
+The file offset for section
+.Ar scn
+is incorrect.
.El
.Sh SEE ALSO
.Xr elf 3 ,
diff --git a/lib/libelf/elf_update.c b/lib/libelf/elf_update.c
index 5880c07..813d2bcb 100644
--- a/lib/libelf/elf_update.c
+++ b/lib/libelf/elf_update.c
@@ -41,89 +41,79 @@ __FBSDID("$FreeBSD$");
#include "_libelf.h"
/*
- * Update the internal data structures associated with an ELF object.
- * Returns the size in bytes the ELF object would occupy in its file
- * representation.
+ * Layout strategy:
*
- * After a successful call to this function, the following structures
- * are updated:
+ * - Case 1: ELF_F_LAYOUT is asserted
+ * In this case the application has full control over where the
+ * section header table, program header table, and section data
+ * will reside. The library only perform error checks.
*
- * - The ELF header is updated.
- * - All sections are sorted in order of ascending addresses and their
- * section header table entries updated. An error is signalled
- * if an overlap was detected among sections.
- * - All data descriptors associated with a section are sorted in order
- * of ascending addresses. Overlaps, if detected, are signalled as
- * errors. Other sanity checks for alignments, section types etc. are
- * made.
+ * - Case 2: ELF_F_LAYOUT is not asserted
*
- * After a resync_elf() successfully returns, the ELF descriptor is
- * ready for being handed over to _libelf_write_elf().
+ * The library will do the object layout using the following
+ * ordering:
+ * - The executable header is placed first, are required by the
+ * ELF specification.
+ * - The program header table is placed immediately following the
+ * executable header.
+ * - Section data, if any, is placed after the program header
+ * table, aligned appropriately.
+ * - The section header table, if needed, is placed last.
*
- * File alignments:
- * PHDR - Addr
- * SHDR - Addr
+ * There are two sub-cases to be taken care of:
*
- * XXX: how do we handle 'flags'.
+ * - Case 2a: e->e_cmd == ELF_C_READ or ELF_C_RDWR
+ *
+ * In this sub-case, the underlying ELF object may already have
+ * content in it, which the application may have modified. The
+ * library will retrieve content from the existing object as
+ * needed.
+ *
+ * - Case 2b: e->e_cmd == ELF_C_WRITE
+ *
+ * The ELF object is being created afresh in this sub-case;
+ * there is no pre-existing content in the underlying ELF
+ * object.
*/
/*
* Compute the extents of a section, by looking at the data
- * descriptors associated with it. The function returns zero if an
- * error was detected. `*rc' holds the maximum file extent seen so
- * far.
+ * descriptors associated with it. The function returns 1 if
+ * successful, or zero if an error was detected.
*/
static int
-_libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc)
+_libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t rc)
{
int ec;
- Elf_Data *d, *td;
+ size_t fsz, msz;
+ Elf_Data *d;
+ Elf32_Shdr *shdr32;
+ Elf64_Shdr *shdr64;
unsigned int elftype;
uint32_t sh_type;
uint64_t d_align;
uint64_t sh_align, sh_entsize, sh_offset, sh_size;
uint64_t scn_size, scn_alignment;
- /*
- * We need to recompute library private data structures if one
- * or more of the following is true:
- * - The underlying Shdr structure has been marked `dirty'. Significant
- * fields include: `sh_offset', `sh_type', `sh_size', `sh_addralign'.
- * - The Elf_Data structures part of this section have been marked
- * `dirty'. Affected members include `d_align', `d_offset', `d_type',
- * and `d_size'.
- * - The section as a whole is `dirty', e.g., it has been allocated
- * using elf_newscn(), or if a new Elf_Data structure was added using
- * elf_newdata().
- *
- * Each of these conditions would result in the ELF_F_DIRTY bit being
- * set on the section descriptor's `s_flags' field.
- */
-
ec = e->e_class;
+ shdr32 = &s->s_shdr.s_shdr32;
+ shdr64 = &s->s_shdr.s_shdr64;
if (ec == ELFCLASS32) {
- sh_type = s->s_shdr.s_shdr32.sh_type;
- sh_align = (uint64_t) s->s_shdr.s_shdr32.sh_addralign;
- sh_entsize = (uint64_t) s->s_shdr.s_shdr32.sh_entsize;
- sh_offset = (uint64_t) s->s_shdr.s_shdr32.sh_offset;
- sh_size = (uint64_t) s->s_shdr.s_shdr32.sh_size;
+ sh_type = shdr32->sh_type;
+ sh_align = (uint64_t) shdr32->sh_addralign;
+ sh_entsize = (uint64_t) shdr32->sh_entsize;
+ sh_offset = (uint64_t) shdr32->sh_offset;
+ sh_size = (uint64_t) shdr32->sh_size;
} else {
- sh_type = s->s_shdr.s_shdr64.sh_type;
- sh_align = s->s_shdr.s_shdr64.sh_addralign;
- sh_entsize = s->s_shdr.s_shdr64.sh_entsize;
- sh_offset = s->s_shdr.s_shdr64.sh_offset;
- sh_size = s->s_shdr.s_shdr64.sh_size;
+ sh_type = shdr64->sh_type;
+ sh_align = shdr64->sh_addralign;
+ sh_entsize = shdr64->sh_entsize;
+ sh_offset = shdr64->sh_offset;
+ sh_size = shdr64->sh_size;
}
- if (sh_type == SHT_NULL || sh_type == SHT_NOBITS)
- return (1);
-
- if ((s->s_flags & ELF_F_DIRTY) == 0) {
- if ((size_t) *rc < sh_offset + sh_size)
- *rc = sh_offset + sh_size;
- return (1);
- }
+ assert(sh_type != SHT_NULL && sh_type != SHT_NOBITS);
elftype = _libelf_xlate_shtype(sh_type);
if (elftype > ELF_T_LAST) {
@@ -131,15 +121,52 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc)
return (0);
}
- /*
- * Compute the extent of the data descriptors associated with
- * this section.
- */
- scn_alignment = 0;
if (sh_align == 0)
sh_align = _libelf_falign(elftype, ec);
- /* Compute the section alignment. */
+ /*
+ * Check the section's data buffers for sanity and compute the
+ * section's alignment.
+ * Compute the section's size and alignment using the data
+ * descriptors associated with the section.
+ */
+ if (STAILQ_EMPTY(&s->s_data)) {
+ /*
+ * The section's content (if any) has not been read in
+ * yet. If section is not dirty marked dirty, we can
+ * reuse the values in the 'sh_size' and 'sh_offset'
+ * fields of the section header.
+ */
+ if ((s->s_flags & ELF_F_DIRTY) == 0) {
+ /*
+ * If the library is doing the layout, then we
+ * compute the new start offset for the
+ * section based on the current offset and the
+ * section's alignment needs.
+ *
+ * If the application is doing the layout, we
+ * can use the value in the 'sh_offset' field
+ * in the section header directly.
+ */
+ if (e->e_flags & ELF_F_LAYOUT)
+ goto updatedescriptor;
+ else
+ goto computeoffset;
+ }
+
+ /*
+ * Otherwise, we need to bring in the section's data
+ * from the underlying ELF object.
+ */
+ if (e->e_cmd != ELF_C_WRITE && elf_getdata(s, NULL) == NULL)
+ return (0);
+ }
+
+ /*
+ * Loop through the section's data descriptors.
+ */
+ scn_size = 0L;
+ scn_alignment = 0L;
STAILQ_FOREACH(d, &s->s_data, d_next) {
if (d->d_type > ELF_T_LAST) {
LIBELF_SET_ERROR(DATA, 0);
@@ -153,23 +180,40 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc)
LIBELF_SET_ERROR(DATA, 0);
return (0);
}
- if (d_align > scn_alignment)
- scn_alignment = d_align;
- }
- scn_size = 0L;
+ /*
+ * The buffer's size should be a multiple of the
+ * memory size of the underlying type.
+ */
+ msz = _libelf_msize(d->d_type, ec, e->e_version);
+ if (d->d_size % msz) {
+ LIBELF_SET_ERROR(DATA, 0);
+ return (0);
+ }
- STAILQ_FOREACH_SAFE(d, &s->s_data, d_next, td) {
+ /*
+ * Compute the section's size.
+ */
if (e->e_flags & ELF_F_LAYOUT) {
if ((uint64_t) d->d_off + d->d_size > scn_size)
scn_size = d->d_off + d->d_size;
} else {
scn_size = roundup2(scn_size, d->d_align);
d->d_off = scn_size;
- scn_size += d->d_size;
+ fsz = _libelf_fsize(d->d_type, ec, d->d_version,
+ d->d_size / msz);
+ scn_size += fsz;
}
+
+ /*
+ * The section's alignment is the maximum alignment
+ * needed for its data buffers.
+ */
+ if (d_align > scn_alignment)
+ scn_alignment = d_align;
}
+
/*
* If the application is requesting full control over the layout
* of the section, check its values for sanity.
@@ -180,46 +224,60 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc)
LIBELF_SET_ERROR(LAYOUT, 0);
return (0);
}
- } else {
- /*
- * Otherwise compute the values in the section header.
- */
+ goto updatedescriptor;
+ }
- if (scn_alignment > sh_align)
- sh_align = scn_alignment;
+ /*
+ * Otherwise compute the values in the section header.
+ *
+ * The section alignment is the maximum alignment for any of
+ * its contained data descriptors.
+ */
+ if (scn_alignment > sh_align)
+ sh_align = scn_alignment;
- /*
- * If the section entry size is zero, try and fill in an
- * appropriate entry size. Per the elf(5) manual page
- * sections without fixed-size entries should have their
- * 'sh_entsize' field set to zero.
- */
- if (sh_entsize == 0 &&
- (sh_entsize = _libelf_fsize(elftype, ec, e->e_version,
- (size_t) 1)) == 1)
- sh_entsize = 0;
+ /*
+ * If the section entry size is zero, try and fill in an
+ * appropriate entry size. Per the elf(5) manual page
+ * sections without fixed-size entries should have their
+ * 'sh_entsize' field set to zero.
+ */
+ if (sh_entsize == 0 &&
+ (sh_entsize = _libelf_fsize(elftype, ec, e->e_version,
+ (size_t) 1)) == 1)
+ sh_entsize = 0;
- sh_size = scn_size;
- sh_offset = roundup(*rc, sh_align);
+ sh_size = scn_size;
- if (ec == ELFCLASS32) {
- s->s_shdr.s_shdr32.sh_addralign = (uint32_t) sh_align;
- s->s_shdr.s_shdr32.sh_entsize = (uint32_t) sh_entsize;
- s->s_shdr.s_shdr32.sh_offset = (uint32_t) sh_offset;
- s->s_shdr.s_shdr32.sh_size = (uint32_t) sh_size;
- } else {
- s->s_shdr.s_shdr64.sh_addralign = sh_align;
- s->s_shdr.s_shdr64.sh_entsize = sh_entsize;
- s->s_shdr.s_shdr64.sh_offset = sh_offset;
- s->s_shdr.s_shdr64.sh_size = sh_size;
- }
- }
+computeoffset:
+ /*
+ * Compute the new offset for the section based on
+ * the section's alignment needs.
+ */
+ sh_offset = roundup(rc, sh_align);
- if ((size_t) *rc < sh_offset + sh_size)
- *rc = sh_offset + sh_size;
+ /*
+ * Update the section header.
+ */
+ if (ec == ELFCLASS32) {
+ shdr32->sh_addralign = (uint32_t) sh_align;
+ shdr32->sh_entsize = (uint32_t) sh_entsize;
+ shdr32->sh_offset = (uint32_t) sh_offset;
+ shdr32->sh_size = (uint32_t) sh_size;
+ } else {
+ shdr64->sh_addralign = sh_align;
+ shdr64->sh_entsize = sh_entsize;
+ shdr64->sh_offset = sh_offset;
+ shdr64->sh_size = sh_size;
+ }
+updatedescriptor:
+ /*
+ * Update the section descriptor.
+ */
s->s_size = sh_size;
s->s_offset = sh_offset;
+
return (1);
}
@@ -267,13 +325,16 @@ _libelf_insert_section(Elf *e, Elf_Scn *s)
return (1);
}
+/*
+ * Recompute section layout.
+ */
+
static off_t
_libelf_resync_sections(Elf *e, off_t rc)
{
int ec;
- off_t nrc;
+ Elf_Scn *s;
size_t sh_type, shdr_start, shdr_end;
- Elf_Scn *s, *ts;
ec = e->e_class;
@@ -281,13 +342,7 @@ _libelf_resync_sections(Elf *e, off_t rc)
* Make a pass through sections, computing the extent of each
* section. Order in increasing order of addresses.
*/
-
- nrc = rc;
- STAILQ_FOREACH(s, &e->e_u.e_elf.e_scn, s_next)
- if (_libelf_compute_section_extents(e, s, &nrc) == 0)
- return ((off_t) -1);
-
- STAILQ_FOREACH_SAFE(s, &e->e_u.e_elf.e_scn, s_next, ts) {
+ STAILQ_FOREACH(s, &e->e_u.e_elf.e_scn, s_next) {
if (ec == ELFCLASS32)
sh_type = s->s_shdr.s_shdr32.sh_type;
else
@@ -296,21 +351,22 @@ _libelf_resync_sections(Elf *e, off_t rc)
if (sh_type == SHT_NOBITS || sh_type == SHT_NULL)
continue;
- if (s->s_offset < (uint64_t) rc) {
- if (s->s_offset + s->s_size < (uint64_t) rc) {
- /*
- * Try insert this section in the
- * correct place in the list,
- * detecting overlaps if any.
- */
- STAILQ_REMOVE(&e->e_u.e_elf.e_scn, s, _Elf_Scn,
- s_next);
- if (_libelf_insert_section(e, s) == 0)
- return ((off_t) -1);
- } else {
- LIBELF_SET_ERROR(LAYOUT, 0);
+ if (_libelf_compute_section_extents(e, s, rc) == 0)
+ return ((off_t) -1);
+
+ if (s->s_size == 0)
+ continue;
+
+ if (s->s_offset + s->s_size < (size_t) rc) {
+ /*
+ * Try insert this section in the
+ * correct place in the list,
+ * detecting overlaps if any.
+ */
+ STAILQ_REMOVE(&e->e_u.e_elf.e_scn, s, _Elf_Scn,
+ s_next);
+ if (_libelf_insert_section(e, s) == 0)
return ((off_t) -1);
- }
} else
rc = s->s_offset + s->s_size;
}
@@ -338,8 +394,6 @@ _libelf_resync_sections(Elf *e, off_t rc)
}
}
- assert(nrc == rc);
-
return (rc);
}
diff --git a/lib/libldns/Makefile b/lib/libldns/Makefile
index 268939e..c0b30b0 100644
--- a/lib/libldns/Makefile
+++ b/lib/libldns/Makefile
@@ -11,6 +11,7 @@ INTERNALLIB = true
CFLAGS += -I${LDNSDIR}
SRCS += buffer.c
+SRCS += dane.c
SRCS += dname.c
SRCS += dnssec.c
SRCS += dnssec_sign.c
diff --git a/lib/libsm/Makefile b/lib/libsm/Makefile
index f2f19fb..ce590d7 100644
--- a/lib/libsm/Makefile
+++ b/lib/libsm/Makefile
@@ -18,11 +18,6 @@ CFLAGS+=${SENDMAIL_CFLAGS}
WARNS?= 2
-# Unfortunately, clang gives warnings about sendmail code that cannot
-# be turned off yet. Since this is contrib code, and we don't really
-# care about the warnings, just make them non-fatal for now.
-NO_WERROR.clang=
-
LIB= sm
SRCS+= sm_os.h
diff --git a/lib/libstand/Makefile b/lib/libstand/Makefile
index 807136d..cfc39e9 100644
--- a/lib/libstand/Makefile
+++ b/lib/libstand/Makefile
@@ -39,7 +39,7 @@ CFLAGS+= -msoft-float -D_STANDALONE
# standalone components and stuff we have modified locally
SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \
- globals.c pager.c printf.c strdup.c strerror.c strtol.c random.c \
+ globals.c pager.c printf.c strdup.c strerror.c strtol.c strtoul.c random.c \
sbrk.c twiddle.c zalloc.c zalloc_malloc.c
# private (pruned) versions of libc string functions
diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h
index 10bb829..2a1e9a9 100644
--- a/lib/libstand/stand.h
+++ b/lib/libstand/stand.h
@@ -261,6 +261,7 @@ extern u_long random(void);
/* imports from stdlib, locally modified */
extern long strtol(const char *, char **, int);
+extern unsigned long strtoul(const char *, char **, int);
extern char *optarg; /* getopt(3) external variables */
extern int optind, opterr, optopt, optreset;
extern int getopt(int, char * const [], const char *);
diff --git a/lib/libstand/strtoul.c b/lib/libstand/strtoul.c
new file mode 100644
index 0000000..5735d20
--- /dev/null
+++ b/lib/libstand/strtoul.c
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Copyright (c) 2011 The FreeBSD Foundation
+ * All rights reserved.
+ * Portions of this software were developed by David Chisnall
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "stand.h"
+#include <limits.h>
+
+/*
+ * Convert a string to an unsigned long integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+unsigned long
+strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
+{
+ const char *s;
+ unsigned long acc;
+ char c;
+ unsigned long cutoff;
+ int neg, any, cutlim;
+
+ /*
+ * See strtol for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+ } while (isspace((unsigned char)c));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+ } else {
+ neg = 0;
+ if (c == '+')
+ c = *s++;
+ }
+ if ((base == 0 || base == 16) &&
+ c == '0' && (*s == 'x' || *s == 'X') &&
+ ((s[1] >= '0' && s[1] <= '9') ||
+ (s[1] >= 'A' && s[1] <= 'F') ||
+ (s[1] >= 'a' && s[1] <= 'f'))) {
+ c = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = c == '0' ? 8 : 10;
+ acc = any = 0;
+ if (base < 2 || base > 36)
+ goto noconv;
+
+ cutoff = ULONG_MAX / base;
+ cutlim = ULONG_MAX % base;
+ for ( ; ; c = *s++) {
+ if (c >= '0' && c <= '9')
+ c -= '0';
+ else if (c >= 'A' && c <= 'Z')
+ c -= 'A' - 10;
+ else if (c >= 'a' && c <= 'z')
+ c -= 'a' - 10;
+ else
+ break;
+ if (c >= base)
+ break;
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+ any = -1;
+ else {
+ any = 1;
+ acc *= base;
+ acc += c;
+ }
+ }
+ if (any < 0) {
+ acc = ULONG_MAX;
+ errno = ERANGE;
+ } else if (!any) {
+noconv:
+ errno = EINVAL;
+ } else if (neg)
+ acc = -acc;
+ if (endptr != NULL)
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+}
OpenPOWER on IntegriCloud