summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/Makefile42
-rw-r--r--lib/libc/Makefile.inc25
-rw-r--r--lib/libc/amd64/SYS.h86
-rw-r--r--lib/libc/amd64/gen/Makefile.inc5
-rw-r--r--lib/libc/amd64/gen/_setjmp.S92
-rw-r--r--lib/libc/amd64/gen/frexp.c67
-rw-r--r--lib/libc/amd64/gen/infinity.c9
-rw-r--r--lib/libc/amd64/gen/isinf.c68
-rw-r--r--lib/libc/amd64/gen/ldexp.c (renamed from lib/libc/db/btree/bt_stack.c)78
-rw-r--r--lib/libc/amd64/gen/setjmp.S113
-rw-r--r--lib/libc/amd64/gen/sigsetjmp.S125
-rw-r--r--lib/libc/amd64/net/Makefile.inc4
-rw-r--r--lib/libc/amd64/net/htonl.S53
-rw-r--r--lib/libc/amd64/net/htons.S51
-rw-r--r--lib/libc/amd64/net/ntohl.S53
-rw-r--r--lib/libc/amd64/net/ntohs.S51
-rw-r--r--lib/libc/amd64/sys/Makefile.inc13
-rw-r--r--lib/libc/amd64/sys/brk.S91
-rw-r--r--lib/libc/amd64/sys/cerror.S87
-rw-r--r--lib/libc/amd64/sys/exect.S56
-rw-r--r--lib/libc/amd64/sys/pipe.S51
-rw-r--r--lib/libc/amd64/sys/ptrace.S62
-rw-r--r--lib/libc/amd64/sys/reboot.S47
-rw-r--r--lib/libc/amd64/sys/sbrk.S95
-rw-r--r--lib/libc/amd64/sys/setlogin.S59
-rw-r--r--lib/libc/amd64/sys/sigreturn.S52
-rw-r--r--lib/libc/amd64/sys/vfork.S101
-rw-r--r--lib/libc/compat-43/Makefile.inc19
-rw-r--r--lib/libc/compat-43/creat.27
-rw-r--r--lib/libc/compat-43/creat.c1
-rw-r--r--lib/libc/compat-43/gethostid.36
-rw-r--r--lib/libc/compat-43/getwd.c2
-rw-r--r--lib/libc/compat-43/killpg.25
-rw-r--r--lib/libc/compat-43/killpg.c1
-rw-r--r--lib/libc/compat-43/setpgrp.c1
-rw-r--r--lib/libc/compat-43/setruid.312
-rw-r--r--lib/libc/compat-43/sigblock.24
-rw-r--r--lib/libc/compat-43/sigcompat.c4
-rw-r--r--lib/libc/compat-43/sigpause.26
-rw-r--r--lib/libc/compat-43/sigsetmask.26
-rw-r--r--lib/libc/compat-43/sigvec.211
-rw-r--r--lib/libc/db/Makefile.inc15
-rw-r--r--lib/libc/db/README40
-rw-r--r--lib/libc/db/btree/Makefile.inc5
-rw-r--r--lib/libc/db/btree/bt_open.c8
-rw-r--r--lib/libc/db/changelog (renamed from lib/libc/db/VERSION)80
-rw-r--r--lib/libc/db/db/Makefile.inc5
-rw-r--r--lib/libc/db/doc/hash.usenix.ps12209
-rw-r--r--lib/libc/db/doc/libtp.usenix.ps12340
-rw-r--r--lib/libc/db/hash/Makefile.inc5
-rw-r--r--lib/libc/db/hash/hash.c23
-rw-r--r--lib/libc/db/hash/hash.h6
-rw-r--r--lib/libc/db/hash/hash_bigkey.c2
-rw-r--r--lib/libc/db/hash/hash_page.c2
-rw-r--r--lib/libc/db/hash/hsearch.c2
-rw-r--r--lib/libc/db/hash/ndbm.c61
-rw-r--r--lib/libc/db/man/Makefile.inc11
-rw-r--r--lib/libc/db/man/hash.38
-rw-r--r--lib/libc/db/man/mpool.33
-rw-r--r--lib/libc/db/man/recno.34
-rw-r--r--lib/libc/db/mpool/Makefile.inc5
-rw-r--r--lib/libc/db/mpool/mpool.libtp2
-rw-r--r--lib/libc/db/recno/Makefile.inc5
-rw-r--r--lib/libc/db/recno/rec_close.c2
-rw-r--r--lib/libc/db/recno/rec_open.c2
-rw-r--r--lib/libc/db/test/btree.tests/main.c2
-rw-r--r--lib/libc/db/test/hash.tests/driver2.c2
-rw-r--r--lib/libc/db/test/hash.tests/tcreat3.c2
-rw-r--r--lib/libc/db/test/hash.tests/tdel.c4
-rw-r--r--lib/libc/db/test/hash.tests/thash4.c10
-rw-r--r--lib/libc/db/test/hash.tests/tseq.c2
-rw-r--r--lib/libc/gen/Makefile.inc110
-rw-r--r--lib/libc/gen/__xuname.c125
-rw-r--r--lib/libc/gen/_rand48.c46
-rw-r--r--lib/libc/gen/alarm.343
-rw-r--r--lib/libc/gen/arc4random.383
-rw-r--r--lib/libc/gen/arc4random.c172
-rw-r--r--lib/libc/gen/assert.c1
-rw-r--r--lib/libc/gen/clock.38
-rw-r--r--lib/libc/gen/clock.c5
-rw-r--r--lib/libc/gen/closedir.c7
-rw-r--r--lib/libc/gen/config.c187
-rw-r--r--lib/libc/gen/config_open.373
-rw-r--r--lib/libc/gen/confstr.312
-rw-r--r--lib/libc/gen/confstr.c1
-rw-r--r--lib/libc/gen/crypt.339
-rw-r--r--lib/libc/gen/crypt.c21
-rw-r--r--lib/libc/gen/ctermid.32
-rw-r--r--lib/libc/gen/daemon.312
-rw-r--r--lib/libc/gen/devname.32
-rw-r--r--lib/libc/gen/directory.36
-rw-r--r--lib/libc/gen/disklabel.c20
-rw-r--r--lib/libc/gen/drand48.c22
-rw-r--r--lib/libc/gen/erand48.c23
-rw-r--r--lib/libc/gen/err.341
-rw-r--r--lib/libc/gen/err.c66
-rw-r--r--lib/libc/gen/exec.317
-rw-r--r--lib/libc/gen/exec.c47
-rw-r--r--lib/libc/gen/fnmatch.318
-rw-r--r--lib/libc/gen/fnmatch.c96
-rw-r--r--lib/libc/gen/frexp.34
-rw-r--r--lib/libc/gen/fstab.c71
-rw-r--r--lib/libc/gen/ftok.385
-rw-r--r--lib/libc/gen/ftok.c47
-rw-r--r--lib/libc/gen/fts-compat.c995
-rw-r--r--lib/libc/gen/fts-compat.h128
-rw-r--r--lib/libc/gen/fts.37
-rw-r--r--lib/libc/gen/fts.c995
-rw-r--r--lib/libc/gen/getbootfile.3 (renamed from lib/libc/stdlib/calloc.3)62
-rw-r--r--lib/libc/gen/getbootfile.c55
-rw-r--r--lib/libc/gen/getbsize.38
-rw-r--r--lib/libc/gen/getcap.3147
-rw-r--r--lib/libc/gen/getcap.c63
-rw-r--r--lib/libc/gen/getcwd.35
-rw-r--r--lib/libc/gen/getcwd.c166
-rw-r--r--lib/libc/gen/getdomainname.399
-rw-r--r--lib/libc/gen/getdomainname.c61
-rw-r--r--lib/libc/gen/getfsent.314
-rw-r--r--lib/libc/gen/getgrent.343
-rw-r--r--lib/libc/gen/getgrent.c418
-rw-r--r--lib/libc/gen/getgrouplist.33
-rw-r--r--lib/libc/gen/getgrouplist.c8
-rw-r--r--lib/libc/gen/gethostname.36
-rw-r--r--lib/libc/gen/gethostname.c2
-rw-r--r--lib/libc/gen/getloadavg.35
-rw-r--r--lib/libc/gen/getlogin.c4
-rw-r--r--lib/libc/gen/getmntinfo.39
-rw-r--r--lib/libc/gen/getnetgrent.38
-rw-r--r--lib/libc/gen/getnetgrent.c304
-rw-r--r--lib/libc/gen/getosreldate.c63
-rw-r--r--lib/libc/gen/getpagesize.39
-rw-r--r--lib/libc/gen/getpagesize.c20
-rw-r--r--lib/libc/gen/getpass.324
-rw-r--r--lib/libc/gen/getpass.c73
-rw-r--r--lib/libc/gen/getpwent.365
-rw-r--r--lib/libc/gen/getpwent.c658
-rw-r--r--lib/libc/gen/getttyent.350
-rw-r--r--lib/libc/gen/getttyent.c101
-rw-r--r--lib/libc/gen/getusershell.31
-rw-r--r--lib/libc/gen/getusershell.c2
-rw-r--r--lib/libc/gen/getvfsbyname.39
-rw-r--r--lib/libc/gen/getvfsbyname.c7
-rw-r--r--lib/libc/gen/getvfsent.3228
-rw-r--r--lib/libc/gen/getvfsent.c248
-rw-r--r--lib/libc/gen/glob.312
-rw-r--r--lib/libc/gen/glob.c77
-rw-r--r--lib/libc/gen/initgroups.34
-rw-r--r--lib/libc/gen/initgroups.c2
-rw-r--r--lib/libc/gen/isatty.c17
-rw-r--r--lib/libc/gen/jrand48.c21
-rw-r--r--lib/libc/gen/lcong48.c30
-rw-r--r--lib/libc/gen/ldexp.36
-rw-r--r--lib/libc/gen/lrand48.c23
-rw-r--r--lib/libc/gen/mrand48.c23
-rw-r--r--lib/libc/gen/msgctl.3207
-rw-r--r--lib/libc/gen/msgctl.c15
-rw-r--r--lib/libc/gen/msgget.3134
-rw-r--r--lib/libc/gen/msgget.c14
-rw-r--r--lib/libc/gen/msgrcv.3207
-rw-r--r--lib/libc/gen/msgrcv.c17
-rw-r--r--lib/libc/gen/msgsnd.3159
-rw-r--r--lib/libc/gen/msgsnd.c16
-rw-r--r--lib/libc/gen/nice.33
-rw-r--r--lib/libc/gen/nlist.34
-rw-r--r--lib/libc/gen/nlist.c87
-rw-r--r--lib/libc/gen/nrand48.c21
-rw-r--r--lib/libc/gen/ntp_gettime.c59
-rw-r--r--lib/libc/gen/opendir.c63
-rw-r--r--lib/libc/gen/pause.38
-rw-r--r--lib/libc/gen/popen.320
-rw-r--r--lib/libc/gen/popen.c41
-rw-r--r--lib/libc/gen/psignal.36
-rw-r--r--lib/libc/gen/psignal.c2
-rw-r--r--lib/libc/gen/pw_scan.c141
-rw-r--r--lib/libc/gen/pw_scan.h36
-rw-r--r--lib/libc/gen/pwcache.314
-rw-r--r--lib/libc/gen/pwcache.c41
-rw-r--r--lib/libc/gen/raise.c1
-rw-r--r--lib/libc/gen/rand48.3160
-rw-r--r--lib/libc/gen/rand48.h30
-rw-r--r--lib/libc/gen/rewinddir.c2
-rw-r--r--lib/libc/gen/scandir.c5
-rw-r--r--lib/libc/gen/seed48.c36
-rw-r--r--lib/libc/gen/seekdir.c2
-rw-r--r--lib/libc/gen/semconfig.c13
-rw-r--r--lib/libc/gen/semctl.c15
-rw-r--r--lib/libc/gen/semget.c15
-rw-r--r--lib/libc/gen/semop.c15
-rw-r--r--lib/libc/gen/setdomainname.c (renamed from lib/libc/net/getnetbyaddr.c)33
-rw-r--r--lib/libc/gen/setflags.c163
-rw-r--r--lib/libc/gen/setflagsbyname.c163
-rw-r--r--lib/libc/gen/sethostname.c4
-rw-r--r--lib/libc/gen/setjmp.37
-rw-r--r--lib/libc/gen/setmode.34
-rw-r--r--lib/libc/gen/setmode.c12
-rw-r--r--lib/libc/gen/setproctitle.3113
-rw-r--r--lib/libc/gen/setproctitle.c125
-rw-r--r--lib/libc/gen/shmat.c19
-rw-r--r--lib/libc/gen/shmctl.c19
-rw-r--r--lib/libc/gen/shmdt.c17
-rw-r--r--lib/libc/gen/shmget.c19
-rw-r--r--lib/libc/gen/siginterrupt.36
-rw-r--r--lib/libc/gen/siginterrupt.c1
-rw-r--r--lib/libc/gen/signal.324
-rw-r--r--lib/libc/gen/sigsetops.37
-rw-r--r--lib/libc/gen/sigsetops.c5
-rw-r--r--lib/libc/gen/sleep.323
-rw-r--r--lib/libc/gen/sleep.c118
-rw-r--r--lib/libc/gen/srand48.c30
-rw-r--r--lib/libc/gen/stringlist.3120
-rw-r--r--lib/libc/gen/stringlist.c120
-rw-r--r--lib/libc/gen/strtofflags.c163
-rw-r--r--lib/libc/gen/sysconf.316
-rw-r--r--lib/libc/gen/sysconf.c6
-rw-r--r--lib/libc/gen/sysctl.3120
-rw-r--r--lib/libc/gen/sysctl.c1
-rw-r--r--lib/libc/gen/sysctlbyname.c33
-rw-r--r--lib/libc/gen/syslog.314
-rw-r--r--lib/libc/gen/syslog.c212
-rw-r--r--lib/libc/gen/tcgetpgrp.312
-rw-r--r--lib/libc/gen/tcsendbreak.320
-rw-r--r--lib/libc/gen/tcsetattr.3100
-rw-r--r--lib/libc/gen/tcsetpgrp.34
-rw-r--r--lib/libc/gen/telldir.c31
-rw-r--r--lib/libc/gen/termios.c21
-rw-r--r--lib/libc/gen/time.32
-rw-r--r--lib/libc/gen/times.33
-rw-r--r--lib/libc/gen/timezone.32
-rw-r--r--lib/libc/gen/timezone.c32
-rw-r--r--lib/libc/gen/ttyname.c122
-rw-r--r--lib/libc/gen/ttyslot.c8
-rw-r--r--lib/libc/gen/tzset.37
-rw-r--r--lib/libc/gen/ualarm.37
-rw-r--r--lib/libc/gen/ualarm.c2
-rw-r--r--lib/libc/gen/uname.39
-rw-r--r--lib/libc/gen/uname.c71
-rw-r--r--lib/libc/gen/unvis.39
-rw-r--r--lib/libc/gen/unvis.c35
-rw-r--r--lib/libc/gen/usleep.36
-rw-r--r--lib/libc/gen/usleep.c122
-rw-r--r--lib/libc/gen/utime.36
-rw-r--r--lib/libc/gen/valloc.34
-rw-r--r--lib/libc/gen/vis.334
-rw-r--r--lib/libc/gen/vis.c11
-rw-r--r--lib/libc/gmon/Makefile.inc12
-rw-r--r--lib/libc/gmon/gmon.c8
-rw-r--r--lib/libc/gmon/mcount.c169
-rw-r--r--lib/libc/gmon/moncontrol.36
-rw-r--r--lib/libc/i386/DEFS.h18
-rw-r--r--lib/libc/i386/SYS.h61
-rw-r--r--lib/libc/i386/gen/Makefile.inc6
-rw-r--r--lib/libc/i386/gen/_setjmp.S34
-rw-r--r--lib/libc/i386/gen/alloca.S13
-rw-r--r--lib/libc/i386/gen/fabs.S13
-rw-r--r--lib/libc/i386/gen/frexp.c8
-rw-r--r--lib/libc/i386/gen/infinity.c9
-rw-r--r--lib/libc/i386/gen/isinf.c10
-rw-r--r--lib/libc/i386/gen/ldexp.c18
-rw-r--r--lib/libc/i386/gen/modf.S20
-rw-r--r--lib/libc/i386/gen/setjmp.S51
-rw-r--r--lib/libc/i386/gen/sigsetjmp.S125
-rw-r--r--lib/libc/i386/net/Makefile.inc3
-rw-r--r--lib/libc/i386/net/htonl.S53
-rw-r--r--lib/libc/i386/net/htons.S51
-rw-r--r--lib/libc/i386/net/ntohl.S53
-rw-r--r--lib/libc/i386/net/ntohs.S51
-rw-r--r--lib/libc/i386/stdlib/Makefile.inc3
-rw-r--r--lib/libc/i386/stdlib/abs.S17
-rw-r--r--lib/libc/i386/stdlib/div.S47
-rw-r--r--lib/libc/i386/stdlib/labs.S51
-rw-r--r--lib/libc/i386/stdlib/ldiv.S47
-rw-r--r--lib/libc/i386/string/Makefile.inc9
-rw-r--r--lib/libc/i386/string/bcmp.S70
-rw-r--r--lib/libc/i386/string/bcopy.S103
-rw-r--r--lib/libc/i386/string/bzero.S98
-rw-r--r--lib/libc/i386/string/ffs.S59
-rw-r--r--lib/libc/i386/string/index.S69
-rw-r--r--lib/libc/i386/string/memchr.S64
-rw-r--r--lib/libc/i386/string/memcmp.S81
-rw-r--r--lib/libc/i386/string/memcpy.S2
-rw-r--r--lib/libc/i386/string/memmove.S2
-rw-r--r--lib/libc/i386/string/memset.S95
-rw-r--r--lib/libc/i386/string/rindex.S70
-rw-r--r--lib/libc/i386/string/strcat.S106
-rw-r--r--lib/libc/i386/string/strchr.S69
-rw-r--r--lib/libc/i386/string/strcmp.S125
-rw-r--r--lib/libc/i386/string/strcpy.S95
-rw-r--r--lib/libc/i386/string/strlen.S59
-rw-r--r--lib/libc/i386/string/strncmp.S172
-rw-r--r--lib/libc/i386/string/strrchr.S70
-rw-r--r--lib/libc/i386/string/swab.S105
-rw-r--r--lib/libc/i386/sys/Makefile.inc13
-rw-r--r--lib/libc/i386/sys/Ovfork.S55
-rw-r--r--lib/libc/i386/sys/brk.S58
-rw-r--r--lib/libc/i386/sys/cerror.S56
-rw-r--r--lib/libc/i386/sys/exect.S18
-rw-r--r--lib/libc/i386/sys/fork.S15
-rw-r--r--lib/libc/i386/sys/i386_get_ldt.298
-rw-r--r--lib/libc/i386/sys/i386_get_ldt.c55
-rw-r--r--lib/libc/i386/sys/i386_set_ldt.c55
-rw-r--r--lib/libc/i386/sys/mount.S13
-rw-r--r--lib/libc/i386/sys/pipe.S15
-rw-r--r--lib/libc/i386/sys/ptrace.S27
-rw-r--r--lib/libc/i386/sys/reboot.S13
-rw-r--r--lib/libc/i386/sys/rfork.S51
-rw-r--r--lib/libc/i386/sys/sbrk.S66
-rw-r--r--lib/libc/i386/sys/setlogin.S26
-rw-r--r--lib/libc/i386/sys/sigpending.S15
-rw-r--r--lib/libc/i386/sys/sigprocmask.S24
-rw-r--r--lib/libc/i386/sys/sigreturn.S24
-rw-r--r--lib/libc/i386/sys/sigsuspend.S24
-rw-r--r--lib/libc/i386/sys/syscall.S20
-rw-r--r--lib/libc/locale/Makefile.inc29
-rw-r--r--lib/libc/locale/ansi.c7
-rw-r--r--lib/libc/locale/collate.c197
-rw-r--r--lib/libc/locale/collate.h66
-rw-r--r--lib/libc/locale/collcmp.c93
-rw-r--r--lib/libc/locale/ctype.317
-rw-r--r--lib/libc/locale/euc.438
-rw-r--r--lib/libc/locale/euc.5241
-rw-r--r--lib/libc/locale/euc.c2
-rw-r--r--lib/libc/locale/isalnum.34
-rw-r--r--lib/libc/locale/isalpha.34
-rw-r--r--lib/libc/locale/isascii.32
-rw-r--r--lib/libc/locale/isblank.32
-rw-r--r--lib/libc/locale/iscntrl.34
-rw-r--r--lib/libc/locale/isctype.c11
-rw-r--r--lib/libc/locale/isdigit.34
-rw-r--r--lib/libc/locale/isgraph.34
-rw-r--r--lib/libc/locale/islower.34
-rw-r--r--lib/libc/locale/isprint.34
-rw-r--r--lib/libc/locale/ispunct.34
-rw-r--r--lib/libc/locale/isspace.34
-rw-r--r--lib/libc/locale/isupper.36
-rw-r--r--lib/libc/locale/isxdigit.34
-rw-r--r--lib/libc/locale/mbrune.34
-rw-r--r--lib/libc/locale/multibyte.36
-rw-r--r--lib/libc/locale/nomacros.c9
-rw-r--r--lib/libc/locale/none.c2
-rw-r--r--lib/libc/locale/rune.315
-rw-r--r--lib/libc/locale/rune.c171
-rw-r--r--lib/libc/locale/runetype.c64
-rw-r--r--lib/libc/locale/setinvalidrune.c44
-rw-r--r--lib/libc/locale/setlocale.326
-rw-r--r--lib/libc/locale/setlocale.c226
-rw-r--r--lib/libc/locale/setlocale.h34
-rw-r--r--lib/libc/locale/setrunelocale.c130
-rw-r--r--lib/libc/locale/table.c6
-rw-r--r--lib/libc/locale/toascii.34
-rw-r--r--lib/libc/locale/tolower.34
-rw-r--r--lib/libc/locale/tolower.c60
-rw-r--r--lib/libc/locale/toupper.38
-rw-r--r--lib/libc/locale/toupper.c60
-rw-r--r--lib/libc/locale/utf2.411
-rw-r--r--lib/libc/locale/utf2.5 (renamed from lib/libc/gen/realpath.3)132
-rw-r--r--lib/libc/locale/utf2.c2
-rw-r--r--lib/libc/net/Makefile.inc46
-rw-r--r--lib/libc/net/addr2ascii.3215
-rw-r--r--lib/libc/net/addr2ascii.c92
-rw-r--r--lib/libc/net/ascii2addr.c72
-rw-r--r--lib/libc/net/base64.c321
-rw-r--r--lib/libc/net/ether_addr.c226
-rw-r--r--lib/libc/net/ethers.3193
-rw-r--r--lib/libc/net/gethostbydns.c736
-rw-r--r--lib/libc/net/gethostbyht.c202
-rw-r--r--lib/libc/net/gethostbyname.377
-rw-r--r--lib/libc/net/gethostbynis.c142
-rw-r--r--lib/libc/net/gethostnamadr.c542
-rw-r--r--lib/libc/net/getnetbydns.c310
-rw-r--r--lib/libc/net/getnetbyht.c173
-rw-r--r--lib/libc/net/getnetbynis.c177
-rw-r--r--lib/libc/net/getnetent.317
-rw-r--r--lib/libc/net/getnetnamadr.c190
-rw-r--r--lib/libc/net/getproto.c2
-rw-r--r--lib/libc/net/getprotoent.38
-rw-r--r--lib/libc/net/getprotoname.c2
-rw-r--r--lib/libc/net/getservbyname.c16
-rw-r--r--lib/libc/net/getservbyport.c16
-rw-r--r--lib/libc/net/getservent.313
-rw-r--r--lib/libc/net/getservent.c157
-rw-r--r--lib/libc/net/herror.c23
-rw-r--r--lib/libc/net/inet.329
-rw-r--r--lib/libc/net/inet_addr.c76
-rw-r--r--lib/libc/net/inet_net_ntop.c140
-rw-r--r--lib/libc/net/inet_net_pton.c208
-rw-r--r--lib/libc/net/inet_neta.c83
-rw-r--r--lib/libc/net/inet_network.c6
-rw-r--r--lib/libc/net/inet_ntop.c190
-rw-r--r--lib/libc/net/inet_pton.c214
-rw-r--r--lib/libc/net/iso_addr.c38
-rw-r--r--lib/libc/net/linkaddr.315
-rw-r--r--lib/libc/net/linkaddr.c4
-rw-r--r--lib/libc/net/map_v4v6.c128
-rw-r--r--lib/libc/net/ns.33
-rw-r--r--lib/libc/net/ns_addr.c6
-rw-r--r--lib/libc/net/nsap_addr.c103
-rw-r--r--lib/libc/net/rcmd.310
-rw-r--r--lib/libc/net/rcmd.c150
-rw-r--r--lib/libc/net/res_comp.c496
-rw-r--r--lib/libc/net/res_config.h8
-rw-r--r--lib/libc/net/res_data.c111
-rw-r--r--lib/libc/net/res_debug.c1520
-rw-r--r--lib/libc/net/res_init.c459
-rw-r--r--lib/libc/net/res_mkquery.c186
-rw-r--r--lib/libc/net/res_query.c401
-rw-r--r--lib/libc/net/res_send.c767
-rw-r--r--lib/libc/net/res_stubs.c64
-rw-r--r--lib/libc/net/resolver.354
-rw-r--r--lib/libc/nls/Makefile.inc11
-rw-r--r--lib/libc/nls/catclose.354
-rw-r--r--lib/libc/nls/catclose.c25
-rw-r--r--lib/libc/nls/catgets.366
-rw-r--r--lib/libc/nls/catgets.c28
-rw-r--r--lib/libc/nls/catopen.382
-rw-r--r--lib/libc/nls/catopen.c26
-rw-r--r--lib/libc/nls/msgcat.c428
-rw-r--r--lib/libc/nls/msgcat.h170
-rw-r--r--lib/libc/quad/Makefile.inc16
-rw-r--r--lib/libc/quad/muldi3.c2
-rw-r--r--lib/libc/quad/qdivrem.c2
-rw-r--r--lib/libc/quad/quad.h7
-rw-r--r--lib/libc/regex/Makefile.inc12
-rw-r--r--lib/libc/regex/cclass.h44
-rw-r--r--lib/libc/regex/cname.h192
-rw-r--r--lib/libc/regex/engine.c9
-rw-r--r--lib/libc/regex/regcomp.c163
-rw-r--r--lib/libc/regex/regerror.c38
-rw-r--r--lib/libc/regex/regex.34
-rw-r--r--lib/libc/regex/regex2.h8
-rw-r--r--lib/libc/rpc/DISCLAIMER28
-rw-r--r--lib/libc/rpc/Makefile.inc120
-rw-r--r--lib/libc/rpc/PSD.doc/nfs.rfc.ms1372
-rw-r--r--lib/libc/rpc/PSD.doc/rpc.prog.ms2684
-rw-r--r--lib/libc/rpc/PSD.doc/rpc.rfc.ms1302
-rw-r--r--lib/libc/rpc/PSD.doc/rpcgen.ms1299
-rw-r--r--lib/libc/rpc/PSD.doc/xdr.nts.ms1966
-rw-r--r--lib/libc/rpc/PSD.doc/xdr.rfc.ms1058
-rw-r--r--lib/libc/rpc/README233
-rw-r--r--lib/libc/rpc/auth_des.c554
-rw-r--r--lib/libc/rpc/auth_none.c136
-rw-r--r--lib/libc/rpc/auth_time.c501
-rw-r--r--lib/libc/rpc/auth_unix.c349
-rw-r--r--lib/libc/rpc/authdes_prot.c82
-rw-r--r--lib/libc/rpc/authunix_prot.c68
-rw-r--r--lib/libc/rpc/bindresvport.330
-rw-r--r--lib/libc/rpc/bindresvport.c107
-rw-r--r--lib/libc/rpc/clnt_generic.c137
-rw-r--r--lib/libc/rpc/clnt_perror.c254
-rw-r--r--lib/libc/rpc/clnt_raw.c242
-rw-r--r--lib/libc/rpc/clnt_simple.c122
-rw-r--r--lib/libc/rpc/clnt_tcp.c580
-rw-r--r--lib/libc/rpc/clnt_udp.c553
-rw-r--r--lib/libc/rpc/clnt_unix.c635
-rw-r--r--lib/libc/rpc/crypt_client.c89
-rw-r--r--lib/libc/rpc/des_crypt.3126
-rw-r--r--lib/libc/rpc/des_crypt.c153
-rw-r--r--lib/libc/rpc/des_soft.c67
-rw-r--r--lib/libc/rpc/get_myaddress.c109
-rw-r--r--lib/libc/rpc/getrpcent.396
-rw-r--r--lib/libc/rpc/getrpcent.c303
-rw-r--r--lib/libc/rpc/getrpcport.329
-rw-r--r--lib/libc/rpc/getrpcport.c63
-rw-r--r--lib/libc/rpc/key_call.c425
-rw-r--r--lib/libc/rpc/key_prot_xdr.c166
-rw-r--r--lib/libc/rpc/netname.c136
-rw-r--r--lib/libc/rpc/netnamer.c327
-rw-r--r--lib/libc/rpc/pmap_clnt.c149
-rw-r--r--lib/libc/rpc/pmap_getmaps.c86
-rw-r--r--lib/libc/rpc/pmap_getport.c91
-rw-r--r--lib/libc/rpc/pmap_prot.c59
-rw-r--r--lib/libc/rpc/pmap_prot2.c118
-rw-r--r--lib/libc/rpc/pmap_rmt.c415
-rw-r--r--lib/libc/rpc/publickey.344
-rw-r--r--lib/libc/rpc/publickey.537
-rw-r--r--lib/libc/rpc/rpc.31737
-rw-r--r--lib/libc/rpc/rpc.534
-rw-r--r--lib/libc/rpc/rpc_callmsg.c193
-rw-r--r--lib/libc/rpc/rpc_commondata.c43
-rw-r--r--lib/libc/rpc/rpc_dtablesize.c61
-rw-r--r--lib/libc/rpc/rpc_prot.c297
-rw-r--r--lib/libc/rpc/rpc_secure.3330
-rw-r--r--lib/libc/rpc/rpcdname.c77
-rw-r--r--lib/libc/rpc/rstat.157
-rw-r--r--lib/libc/rpc/rstat_svc.821
-rw-r--r--lib/libc/rpc/rtime.343
-rw-r--r--lib/libc/rpc/rtime.c157
-rw-r--r--lib/libc/rpc/svc.c494
-rw-r--r--lib/libc/rpc/svc_auth.c211
-rw-r--r--lib/libc/rpc/svc_auth_des.c531
-rw-r--r--lib/libc/rpc/svc_auth_unix.c148
-rw-r--r--lib/libc/rpc/svc_raw.c168
-rw-r--r--lib/libc/rpc/svc_run.c87
-rw-r--r--lib/libc/rpc/svc_simple.c150
-rw-r--r--lib/libc/rpc/svc_tcp.c448
-rw-r--r--lib/libc/rpc/svc_udp.c480
-rw-r--r--lib/libc/rpc/svc_unix.c511
-rw-r--r--lib/libc/stdio/Makefile.inc26
-rw-r--r--lib/libc/stdio/asprintf.c59
-rw-r--r--lib/libc/stdio/clrerr.c14
-rw-r--r--lib/libc/stdio/fclose.c16
-rw-r--r--lib/libc/stdio/feof.c5
-rw-r--r--lib/libc/stdio/ferror.c5
-rw-r--r--lib/libc/stdio/fflush.32
-rw-r--r--lib/libc/stdio/fflush.c23
-rw-r--r--lib/libc/stdio/fgetc.c19
-rw-r--r--lib/libc/stdio/fgetln.33
-rw-r--r--lib/libc/stdio/fgetln.c9
-rw-r--r--lib/libc/stdio/fgetpos.c19
-rw-r--r--lib/libc/stdio/fgets.321
-rw-r--r--lib/libc/stdio/fgets.c28
-rw-r--r--lib/libc/stdio/fileno.c5
-rw-r--r--lib/libc/stdio/findfp.c10
-rw-r--r--lib/libc/stdio/flags.c8
-rw-r--r--lib/libc/stdio/fopen.310
-rw-r--r--lib/libc/stdio/fprintf.c5
-rw-r--r--lib/libc/stdio/fpurge.c32
-rw-r--r--lib/libc/stdio/fputc.c19
-rw-r--r--lib/libc/stdio/fputs.32
-rw-r--r--lib/libc/stdio/fputs.c19
-rw-r--r--lib/libc/stdio/fread.36
-rw-r--r--lib/libc/stdio/fread.c15
-rw-r--r--lib/libc/stdio/freopen.c4
-rw-r--r--lib/libc/stdio/fscanf.c16
-rw-r--r--lib/libc/stdio/fseek.32
-rw-r--r--lib/libc/stdio/fseek.c33
-rw-r--r--lib/libc/stdio/fsetpos.c5
-rw-r--r--lib/libc/stdio/ftell.c20
-rw-r--r--lib/libc/stdio/funopen.37
-rw-r--r--lib/libc/stdio/fvwrite.c5
-rw-r--r--lib/libc/stdio/fwalk.c7
-rw-r--r--lib/libc/stdio/fwrite.c20
-rw-r--r--lib/libc/stdio/getc.310
-rw-r--r--lib/libc/stdio/getc.c19
-rw-r--r--lib/libc/stdio/getchar.c19
-rw-r--r--lib/libc/stdio/gets.c9
-rw-r--r--lib/libc/stdio/getw.c5
-rw-r--r--lib/libc/stdio/mktemp.322
-rw-r--r--lib/libc/stdio/mktemp.c15
-rw-r--r--lib/libc/stdio/perror.c2
-rw-r--r--lib/libc/stdio/printf.3102
-rw-r--r--lib/libc/stdio/printf.c5
-rw-r--r--lib/libc/stdio/putc.c19
-rw-r--r--lib/libc/stdio/putchar.c19
-rw-r--r--lib/libc/stdio/puts.c19
-rw-r--r--lib/libc/stdio/putw.c19
-rw-r--r--lib/libc/stdio/refill.c11
-rw-r--r--lib/libc/stdio/remove.c5
-rw-r--r--lib/libc/stdio/rewind.c14
-rw-r--r--lib/libc/stdio/rget.c10
-rw-r--r--lib/libc/stdio/scanf.321
-rw-r--r--lib/libc/stdio/scanf.c16
-rw-r--r--lib/libc/stdio/setbuf.38
-rw-r--r--lib/libc/stdio/setbuffer.c6
-rw-r--r--lib/libc/stdio/setvbuf.c18
-rw-r--r--lib/libc/stdio/snprintf.c7
-rw-r--r--lib/libc/stdio/sprintf.c6
-rw-r--r--lib/libc/stdio/sscanf.c9
-rw-r--r--lib/libc/stdio/stdio.338
-rw-r--r--lib/libc/stdio/stdio.c17
-rw-r--r--lib/libc/stdio/tempnam.c17
-rw-r--r--lib/libc/stdio/tmpnam.32
-rw-r--r--lib/libc/stdio/ungetc.32
-rw-r--r--lib/libc/stdio/ungetc.c45
-rw-r--r--lib/libc/stdio/vasprintf.c119
-rw-r--r--lib/libc/stdio/vfprintf.c509
-rw-r--r--lib/libc/stdio/vfscanf.c92
-rw-r--r--lib/libc/stdio/vprintf.c5
-rw-r--r--lib/libc/stdio/vscanf.c19
-rw-r--r--lib/libc/stdio/vsnprintf.c6
-rw-r--r--lib/libc/stdio/vsprintf.c6
-rw-r--r--lib/libc/stdio/vsscanf.c10
-rw-r--r--lib/libc/stdio/wbuf.c5
-rw-r--r--lib/libc/stdio/wsetup.c5
-rw-r--r--lib/libc/stdlib/Makefile.inc32
-rw-r--r--lib/libc/stdlib/abort.38
-rw-r--r--lib/libc/stdlib/abort.c23
-rw-r--r--lib/libc/stdlib/abs.37
-rw-r--r--lib/libc/stdlib/alloca.34
-rw-r--r--lib/libc/stdlib/atexit.c3
-rw-r--r--lib/libc/stdlib/atoi.c1
-rw-r--r--lib/libc/stdlib/bsearch.32
-rw-r--r--lib/libc/stdlib/calloc.c2
-rw-r--r--lib/libc/stdlib/exit.36
-rw-r--r--lib/libc/stdlib/getenv.c44
-rw-r--r--lib/libc/stdlib/getopt.316
-rw-r--r--lib/libc/stdlib/getsubopt.33
-rw-r--r--lib/libc/stdlib/getsubopt.c3
-rw-r--r--lib/libc/stdlib/heapsort.c3
-rw-r--r--lib/libc/stdlib/labs.32
-rw-r--r--lib/libc/stdlib/ldiv.32
-rw-r--r--lib/libc/stdlib/malloc.3393
-rw-r--r--lib/libc/stdlib/malloc.c1410
-rw-r--r--lib/libc/stdlib/memory.35
-rw-r--r--lib/libc/stdlib/merge.c4
-rw-r--r--lib/libc/stdlib/qsort.c34
-rw-r--r--lib/libc/stdlib/radixsort.37
-rw-r--r--lib/libc/stdlib/radixsort.c10
-rw-r--r--lib/libc/stdlib/random.353
-rw-r--r--lib/libc/stdlib/random.c106
-rw-r--r--lib/libc/stdlib/realpath.32
-rw-r--r--lib/libc/stdlib/realpath.c2
-rw-r--r--lib/libc/stdlib/setenv.c7
-rw-r--r--lib/libc/stdlib/strhash.c436
-rw-r--r--lib/libc/stdlib/strtod.c72
-rw-r--r--lib/libc/stdlib/strtol.34
-rw-r--r--lib/libc/stdlib/strtol.c6
-rw-r--r--lib/libc/stdlib/strtoll.c138
-rw-r--r--lib/libc/stdlib/strtoq.c6
-rw-r--r--lib/libc/stdlib/strtoul.c6
-rw-r--r--lib/libc/stdlib/strtoull.c116
-rw-r--r--lib/libc/stdlib/strtouq.c8
-rw-r--r--lib/libc/stdlib/system.35
-rw-r--r--lib/libc/stdlib/system.c52
-rw-r--r--lib/libc/stdtime/Makefile.inc16
-rw-r--r--lib/libc/stdtime/asctime.c61
-rw-r--r--lib/libc/stdtime/ctime.3257
-rw-r--r--lib/libc/stdtime/difftime.c77
-rw-r--r--lib/libc/stdtime/localtime.c1754
-rw-r--r--lib/libc/stdtime/private.h218
-rw-r--r--lib/libc/stdtime/strftime.3212
-rw-r--r--lib/libc/stdtime/strftime.c574
-rw-r--r--lib/libc/stdtime/time2posix.3114
-rw-r--r--lib/libc/stdtime/tzfile.5122
-rw-r--r--lib/libc/stdtime/tzfile.h187
-rw-r--r--lib/libc/string/Makefile.inc61
-rw-r--r--lib/libc/string/memccpy.33
-rw-r--r--lib/libc/string/memccpy.c5
-rw-r--r--lib/libc/string/memcmp.33
-rw-r--r--lib/libc/string/memset.c2
-rw-r--r--lib/libc/string/strcasecmp.33
-rw-r--r--lib/libc/string/strcasecmp.c53
-rw-r--r--lib/libc/string/strcat.35
-rw-r--r--lib/libc/string/strcmp.c2
-rw-r--r--lib/libc/string/strcoll.36
-rw-r--r--lib/libc/string/strcoll.c77
-rw-r--r--lib/libc/string/strdup.36
-rw-r--r--lib/libc/string/strdup.c6
-rw-r--r--lib/libc/string/strerror.318
-rw-r--r--lib/libc/string/strerror.c14
-rw-r--r--lib/libc/string/string.313
-rw-r--r--lib/libc/string/strmode.33
-rw-r--r--lib/libc/string/strncmp.c3
-rw-r--r--lib/libc/string/strsep.35
-rw-r--r--lib/libc/string/strsep.c2
-rw-r--r--lib/libc/string/strspn.32
-rw-r--r--lib/libc/string/strxfrm.327
-rw-r--r--lib/libc/string/strxfrm.c99
-rw-r--r--lib/libc/sys/Makefile.inc184
-rw-r--r--lib/libc/sys/_exit.214
-rw-r--r--lib/libc/sys/accept.228
-rw-r--r--lib/libc/sys/access.215
-rw-r--r--lib/libc/sys/acct.27
-rw-r--r--lib/libc/sys/adjtime.26
-rw-r--r--lib/libc/sys/bind.232
-rw-r--r--lib/libc/sys/brk.232
-rw-r--r--lib/libc/sys/chdir.214
-rw-r--r--lib/libc/sys/chflags.219
-rw-r--r--lib/libc/sys/chmod.229
-rw-r--r--lib/libc/sys/chown.247
-rw-r--r--lib/libc/sys/chroot.26
-rw-r--r--lib/libc/sys/clock_gettime.2124
-rw-r--r--lib/libc/sys/close.243
-rw-r--r--lib/libc/sys/connect.239
-rw-r--r--lib/libc/sys/dup.292
-rw-r--r--lib/libc/sys/execve.243
-rw-r--r--lib/libc/sys/fcntl.281
-rw-r--r--lib/libc/sys/flock.240
-rw-r--r--lib/libc/sys/fork.227
-rw-r--r--lib/libc/sys/fsync.228
-rw-r--r--lib/libc/sys/ftruncate.c16
-rw-r--r--lib/libc/sys/getdirentries.250
-rw-r--r--lib/libc/sys/getfh.212
-rw-r--r--lib/libc/sys/getfsstat.246
-rw-r--r--lib/libc/sys/getgid.213
-rw-r--r--lib/libc/sys/getgroups.22
-rw-r--r--lib/libc/sys/getitimer.27
-rw-r--r--lib/libc/sys/getlogin.259
-rw-r--r--lib/libc/sys/getpeername.232
-rw-r--r--lib/libc/sys/getpgrp.219
-rw-r--r--lib/libc/sys/getpid.215
-rw-r--r--lib/libc/sys/getpriority.22
-rw-r--r--lib/libc/sys/getrlimit.222
-rw-r--r--lib/libc/sys/getrusage.223
-rw-r--r--lib/libc/sys/getsockname.229
-rw-r--r--lib/libc/sys/getsockopt.268
-rw-r--r--lib/libc/sys/gettimeofday.211
-rw-r--r--lib/libc/sys/getuid.220
-rw-r--r--lib/libc/sys/intro.290
-rw-r--r--lib/libc/sys/ioctl.231
-rw-r--r--lib/libc/sys/issetugid.294
-rw-r--r--lib/libc/sys/kill.214
-rw-r--r--lib/libc/sys/ktrace.213
-rw-r--r--lib/libc/sys/link.226
-rw-r--r--lib/libc/sys/listen.257
-rw-r--r--lib/libc/sys/lseek.216
-rw-r--r--lib/libc/sys/lseek.c17
-rw-r--r--lib/libc/sys/madvise.289
-rw-r--r--lib/libc/sys/mincore.237
-rw-r--r--lib/libc/sys/minherit.294
-rw-r--r--lib/libc/sys/mkdir.212
-rw-r--r--lib/libc/sys/mkfifo.29
-rw-r--r--lib/libc/sys/mknod.228
-rw-r--r--lib/libc/sys/mlock.225
-rw-r--r--lib/libc/sys/mmap.275
-rw-r--r--lib/libc/sys/mount.249
-rw-r--r--lib/libc/sys/mprotect.239
-rw-r--r--lib/libc/sys/msync.243
-rw-r--r--lib/libc/sys/munmap.216
-rw-r--r--lib/libc/sys/nanosleep.2119
-rw-r--r--lib/libc/sys/nfssvc.242
-rw-r--r--lib/libc/sys/open.240
-rw-r--r--lib/libc/sys/pathconf.219
-rw-r--r--lib/libc/sys/pipe.228
-rw-r--r--lib/libc/sys/profil.217
-rw-r--r--lib/libc/sys/ptrace.2293
-rw-r--r--lib/libc/sys/quotactl.27
-rw-r--r--lib/libc/sys/read.265
-rw-r--r--lib/libc/sys/readlink.216
-rw-r--r--lib/libc/sys/reboot.210
-rw-r--r--lib/libc/sys/recv.232
-rw-r--r--lib/libc/sys/rename.212
-rw-r--r--lib/libc/sys/revoke.29
-rw-r--r--lib/libc/sys/rfork.2137
-rw-r--r--lib/libc/sys/rmdir.24
-rw-r--r--lib/libc/sys/rtprio.2108
-rw-r--r--lib/libc/sys/select.244
-rw-r--r--lib/libc/sys/semctl.2173
-rw-r--r--lib/libc/sys/semget.2137
-rw-r--r--lib/libc/sys/semop.2192
-rw-r--r--lib/libc/sys/send.238
-rw-r--r--lib/libc/sys/setgroups.22
-rw-r--r--lib/libc/sys/setpgid.27
-rw-r--r--lib/libc/sys/setregid.292
-rw-r--r--lib/libc/sys/setreuid.290
-rw-r--r--lib/libc/sys/setsid.225
-rw-r--r--lib/libc/sys/setuid.245
-rw-r--r--lib/libc/sys/shmat.2110
-rw-r--r--lib/libc/sys/shmctl.2136
-rw-r--r--lib/libc/sys/shmget.2138
-rw-r--r--lib/libc/sys/shutdown.25
-rw-r--r--lib/libc/sys/sigaction.260
-rw-r--r--lib/libc/sys/sigaltstack.217
-rw-r--r--lib/libc/sys/sigpending.210
-rw-r--r--lib/libc/sys/sigprocmask.28
-rw-r--r--lib/libc/sys/sigreturn.232
-rw-r--r--lib/libc/sys/sigstack.22
-rw-r--r--lib/libc/sys/sigsuspend.210
-rw-r--r--lib/libc/sys/socket.242
-rw-r--r--lib/libc/sys/socketpair.28
-rw-r--r--lib/libc/sys/stat.267
-rw-r--r--lib/libc/sys/statfs.249
-rw-r--r--lib/libc/sys/swapon.28
-rw-r--r--lib/libc/sys/symlink.215
-rw-r--r--lib/libc/sys/sync.211
-rw-r--r--lib/libc/sys/syscall.210
-rw-r--r--lib/libc/sys/truncate.217
-rw-r--r--lib/libc/sys/truncate.c4
-rw-r--r--lib/libc/sys/umask.210
-rw-r--r--lib/libc/sys/unlink.221
-rw-r--r--lib/libc/sys/utimes.26
-rw-r--r--lib/libc/sys/vfork.237
-rw-r--r--lib/libc/sys/wait.214
-rw-r--r--lib/libc/sys/write.267
-rw-r--r--lib/libc/xdr/Makefile.inc44
-rw-r--r--lib/libc/xdr/xdr.3825
-rw-r--r--lib/libc/xdr/xdr.c719
-rw-r--r--lib/libc/xdr/xdr_array.c155
-rw-r--r--lib/libc/xdr/xdr_float.c314
-rw-r--r--lib/libc/xdr/xdr_mem.c242
-rw-r--r--lib/libc/xdr/xdr_rec.c586
-rw-r--r--lib/libc/xdr/xdr_reference.c136
-rw-r--r--lib/libc/xdr/xdr_sizeof.c163
-rw-r--r--lib/libc/xdr/xdr_stdio.c189
-rw-r--r--lib/libc/yp/Makefile.inc17
-rw-r--r--lib/libc/yp/xdryp.c119
-rw-r--r--lib/libc/yp/yplib.c1033
776 files changed, 66119 insertions, 29360 deletions
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
index 043119e..ef476fa 100644
--- a/lib/libc/Makefile
+++ b/lib/libc/Makefile
@@ -1,27 +1,24 @@
# @(#)Makefile 8.2 (Berkeley) 2/3/94
+# $Id: Makefile,v 1.18 1997/05/03 03:49:51 jb Exp $
#
-# All library objects contain sccsid strings by default; they may be
+# All library objects contain rcsid strings by default; they may be
# excluded as a space-saving measure. To produce a library that does
-# not contain these strings, delete -DLIBC_SCCS and -DSYSLIBC_SCCS
+# not contain these strings, delete -DLIBC_RCS and -DSYSLIBC_RCS
# from CFLAGS below. To remove these strings from just the system call
-# stubs, remove just -DSYSLIBC_SCCS from CFLAGS.
+# stubs, remove just -DSYSLIBC_RCS from CFLAGS.
LIB=c
-CFLAGS+=-DLIBC_SCCS -DSYSLIBC_SCCS
+SHLIB_MAJOR= 3
+SHLIB_MINOR= 0
+CFLAGS+=-DLIBC_RCS -DSYSLIBC_RCS
AINC= -I${.CURDIR}/${MACHINE}
CLEANFILES+=tags
+INSTALL_PIC_ARCHIVE= yes
+PRECIOUSLIB= yes
-.include "${.CURDIR}/db/Makefile.inc"
-.include "${.CURDIR}/compat-43/Makefile.inc"
-.include "${.CURDIR}/gen/Makefile.inc"
-.include "${.CURDIR}/gmon/Makefile.inc"
-.include "${.CURDIR}/locale/Makefile.inc"
-.include "${.CURDIR}/net/Makefile.inc"
-.include "${.CURDIR}/quad/Makefile.inc"
-.include "${.CURDIR}/regex/Makefile.inc"
-.include "${.CURDIR}/stdio/Makefile.inc"
-.include "${.CURDIR}/stdlib/Makefile.inc"
-.include "${.CURDIR}/string/Makefile.inc"
-.include "${.CURDIR}/sys/Makefile.inc"
+#
+# Include make rules that are shared with libc_r.
+#
+.include "${.CURDIR}/Makefile.inc"
KQSRCS= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
@@ -32,20 +29,11 @@ KSRCS= bcmp.c ffs.c index.c mcount.c rindex.c strcat.c strcmp.c strcpy.c \
libkern: libkern.gen libkern.${MACHINE}
libkern.gen: ${KQSRCS} ${KSRCS}
- cp -p ${.CURDIR}/quad/quad.h ${.ALLSRC} /sys/libkern
+ cp -p ${.CURDIR}/quad/quad.h ${.ALLSRC} ${DESTDIR}/sys/libkern
libkern.${MACHINE}:: ${KMSRCS}
.if defined(KMSRCS) && !empty(KMSRCS)
- cp -p ${.ALLSRC} /sys/libkern/${MACHINE}
+ cp -p ${.ALLSRC} ${DESTDIR}/sys/libkern/${MACHINE}
.endif
-beforeinstall: tags
- install -c -o bin -g bin -m 444 tags /var/db/libc.tags
-
-tags: ${SRCS}
- ctags ${.ALLSRC:M*.c}
- egrep -o "^ENTRY(.*)|^FUNC(.*)|^SYSCALL(.*)" ${.ALLSRC:M*.s} | \
- sed "s;\([^:]*\):\([^(]*\)(\([^, )]*\)\(.*\);\3 \1 /^\2(\3\4$$/;" \
- >> tags; sort -o tags tags
-
.include <bsd.lib.mk>
diff --git a/lib/libc/Makefile.inc b/lib/libc/Makefile.inc
new file mode 100644
index 0000000..1f51b57
--- /dev/null
+++ b/lib/libc/Makefile.inc
@@ -0,0 +1,25 @@
+# $Id$
+#
+# This file contains make rules that are shared by libc and libc_r.
+#
+.include "${.CURDIR}/../libc/db/Makefile.inc"
+.include "${.CURDIR}/../libc/compat-43/Makefile.inc"
+.include "${.CURDIR}/../libc/gen/Makefile.inc"
+.include "${.CURDIR}/../libc/gmon/Makefile.inc"
+.include "${.CURDIR}/../libc/locale/Makefile.inc"
+.include "${.CURDIR}/../libc/net/Makefile.inc"
+.include "${.CURDIR}/../libc/nls/Makefile.inc"
+.include "${.CURDIR}/../libc/quad/Makefile.inc"
+.include "${.CURDIR}/../libc/regex/Makefile.inc"
+.include "${.CURDIR}/../libc/stdio/Makefile.inc"
+.include "${.CURDIR}/../libc/stdlib/Makefile.inc"
+.include "${.CURDIR}/../libc/stdtime/Makefile.inc"
+.include "${.CURDIR}/../libc/string/Makefile.inc"
+.include "${.CURDIR}/../libc/sys/Makefile.inc"
+.include "${.CURDIR}/../libc/rpc/Makefile.inc"
+.include "${.CURDIR}/../libc/xdr/Makefile.inc"
+.if !defined(NO_YP_LIBC)
+CFLAGS+= -DYP
+.include "${.CURDIR}/../libc/yp/Makefile.inc"
+.endif
+.include "${.CURDIR}/../libc/${MACHINE}/sys/Makefile.inc"
diff --git a/lib/libc/amd64/SYS.h b/lib/libc/amd64/SYS.h
new file mode 100644
index 0000000..593b2ed
--- /dev/null
+++ b/lib/libc/amd64/SYS.h
@@ -0,0 +1,86 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91
+ *
+ * $Id: SYS.h,v 1.10 1997/02/22 14:58:30 peter Exp $
+ */
+
+#include <sys/syscall.h>
+#include "DEFS.h"
+
+#define SYSCALL(x) 2: PIC_PROLOGUE; jmp PIC_PLT(HIDENAME(cerror)); \
+ ENTRY(x); lea __CONCAT(SYS_,x),%eax; KERNCALL; jb 2b
+#define RSYSCALL(x) SYSCALL(x); ret
+
+#define PSEUDO(x,y) ENTRY(x); lea __CONCAT(SYS_,y), %eax; KERNCALL; ret
+/* gas messes up offset -- although we don't currently need it, do for BCS */
+#define LCALL(x,y) .byte 0x9a ; .long y; .word x
+
+/*
+ * Design note:
+ *
+ * The macros PSYSCALL() and PRSYSCALL() are intended for use where a
+ * syscall needs to be renamed in the threaded library. When building
+ * a normal library, they default to the traditional SYSCALL() and
+ * RSYSCALL(). This avoids the need to #ifdef _THREAD_SAFE everywhere
+ * that the renamed function needs to be called.
+ */
+#ifdef _THREAD_SAFE
+/*
+ * For the thread_safe versions, we prepend _thread_sys_ to the function
+ * name so that the 'C' wrapper can go around the real name.
+ */
+#define PSYSCALL(x) 2: PIC_PROLOGUE; jmp PIC_PLT(HIDENAME(cerror)); \
+ ENTRY(__CONCAT(_thread_sys_,x)); \
+ lea __CONCAT(SYS_,x),%eax; KERNCALL; jb 2b
+#define PRSYSCALL(x) PSYSCALL(x); ret
+#define PPSEUDO(x,y) ENTRY(__CONCAT(_thread_sys_,x)); \
+ lea __CONCAT(SYS_,y), %eax; KERNCALL; ret
+#else
+/*
+ * The non-threaded library defaults to traditional syscalls where
+ * the function name matches the syscall name.
+ */
+#define PSYSCALL(x) SYSCALL(x)
+#define PRSYSCALL(x) RSYSCALL(x)
+#define PPSEUDO(x,y) PSEUDO(x,y)
+#endif
+
+#ifdef __ELF__
+#define KERNCALL int $0x80 /* Faster */
+#else
+#define KERNCALL LCALL(7,0) /* The old way */
+#endif
diff --git a/lib/libc/amd64/gen/Makefile.inc b/lib/libc/amd64/gen/Makefile.inc
new file mode 100644
index 0000000..457d5c3
--- /dev/null
+++ b/lib/libc/amd64/gen/Makefile.inc
@@ -0,0 +1,5 @@
+# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
+
+SRCS+= isinf.c infinity.c
+SRCS+= _setjmp.S alloca.S fabs.S ldexp.c modf.S setjmp.S sigsetjmp.S
diff --git a/lib/libc/amd64/gen/_setjmp.S b/lib/libc/amd64/gen/_setjmp.S
new file mode 100644
index 0000000..62259ce
--- /dev/null
+++ b/lib/libc/amd64/gen/_setjmp.S
@@ -0,0 +1,92 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+/*
+ * C library -- _setjmp, _longjmp
+ *
+ * _longjmp(a,v)
+ * will generate a "return(v)" from the last call to
+ * _setjmp(a)
+ * by restoring registers from the environment 'a'.
+ * The previous signal state is NOT restored.
+ */
+
+#include "DEFS.h"
+
+#ifdef _THREAD_SAFE
+ENTRY(__thread_sys_setjmp)
+#else
+ENTRY(_setjmp)
+#endif
+ movl 4(%esp),%eax
+ movl 0(%esp),%edx
+ movl %edx, 0(%eax) /* rta */
+ movl %ebx, 4(%eax)
+ movl %esp, 8(%eax)
+ movl %ebp,12(%eax)
+ movl %esi,16(%eax)
+ movl %edi,20(%eax)
+ fnstcw 28(%eax)
+ xorl %eax,%eax
+ ret
+
+#ifdef _THREAD_SAFE
+ENTRY(__thread_sys_longjmp)
+#else
+ENTRY(_longjmp)
+#endif
+ movl 4(%esp),%edx
+ movl 8(%esp),%eax
+ movl 0(%edx),%ecx
+ movl 4(%edx),%ebx
+ movl 8(%edx),%esp
+ movl 12(%edx),%ebp
+ movl 16(%edx),%esi
+ movl 20(%edx),%edi
+ fninit
+ fldcw 28(%edx)
+ testl %eax,%eax
+ jnz 1f
+ incl %eax
+1: movl %ecx,0(%esp)
+ ret
diff --git a/lib/libc/amd64/gen/frexp.c b/lib/libc/amd64/gen/frexp.c
new file mode 100644
index 0000000..aba4802
--- /dev/null
+++ b/lib/libc/amd64/gen/frexp.c
@@ -0,0 +1,67 @@
+/*-
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif /* LIBC_RCS and not lint */
+
+#include <sys/types.h>
+#include <math.h>
+
+double
+frexp(value, eptr)
+ double value;
+ int *eptr;
+{
+ union {
+ double v;
+ struct {
+ u_int u_mant2 : 32;
+ u_int u_mant1 : 20;
+ u_int u_exp : 11;
+ u_int u_sign : 1;
+ } s;
+ } u;
+
+ if (value) {
+ u.v = value;
+ *eptr = u.s.u_exp - 1022;
+ u.s.u_exp = 1022;
+ return(u.v);
+ } else {
+ *eptr = 0;
+ return((double)0);
+ }
+}
diff --git a/lib/libc/amd64/gen/infinity.c b/lib/libc/amd64/gen/infinity.c
new file mode 100644
index 0000000..e46f676
--- /dev/null
+++ b/lib/libc/amd64/gen/infinity.c
@@ -0,0 +1,9 @@
+/*
+ * infinity.c
+ * $Id$
+ */
+
+#include <math.h>
+
+/* bytes for +Infinity on a 387 */
+char __infinity[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
diff --git a/lib/libc/amd64/gen/isinf.c b/lib/libc/amd64/gen/isinf.c
new file mode 100644
index 0000000..a796dcf
--- /dev/null
+++ b/lib/libc/amd64/gen/isinf.c
@@ -0,0 +1,68 @@
+/*-
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif /* LIBC_RCS and not lint */
+
+#include <sys/types.h>
+
+int
+isnan(d)
+ double d;
+{
+ register struct IEEEdp {
+ u_int manl : 32;
+ u_int manh : 20;
+ u_int exp : 11;
+ u_int sign : 1;
+ } *p = (struct IEEEdp *)&d;
+
+ return(p->exp == 2047 && (p->manh || p->manl));
+}
+
+int
+isinf(d)
+ double d;
+{
+ register struct IEEEdp {
+ u_int manl : 32;
+ u_int manh : 20;
+ u_int exp : 11;
+ u_int sign : 1;
+ } *p = (struct IEEEdp *)&d;
+
+ return(p->exp == 2047 && !p->manh && !p->manl);
+}
diff --git a/lib/libc/db/btree/bt_stack.c b/lib/libc/amd64/gen/ldexp.c
index 5c7fab9..8b63f52 100644
--- a/lib/libc/db/btree/bt_stack.c
+++ b/lib/libc/amd64/gen/ldexp.c
@@ -3,7 +3,7 @@
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
- * Mike Olson.
+ * Sean Eric Fagan.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,61 +32,43 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)bt_stack.c 8.3 (Berkeley) 2/21/94";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <db.h>
-#include "btree.h"
+#if defined(LIBC_RCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif /* LIBC_RCS and not lint */
/*
- * When a page splits, a new record has to be inserted into its parent page.
- * This page may have to split as well, all the way up to the root. Since
- * parent pointers in each page would be expensive, we maintain a stack of
- * parent pages as we descend the tree.
+ * ldexp(value, exp): return value * (2 ** exp).
*
- * XXX
- * This is a concurrency problem -- if user a builds a stack, then user b
- * splits the tree, then user a tries to split the tree, there's a new level
- * in the tree that user a doesn't know about.
+ * Written by Sean Eric Fagan (sef@kithrup.COM)
+ * Sun Mar 11 20:27:09 PST 1990
*/
/*
- * __BT_PUSH -- Push parent page info onto the stack (LIFO).
- *
- * Parameters:
- * t: tree
- * pgno: page
- * index: page index
- *
- * Returns:
- * RET_ERROR, RET_SUCCESS
+ * We do the conversion in C to let gcc optimize it away, if possible.
+ * The "fxch ; fstp" stuff is because value is still on the stack
+ * (stupid 8087!).
*/
-int
-__bt_push(t, pgno, index)
- BTREE *t;
- pgno_t pgno;
- indx_t index;
+double
+ldexp (double value, int exp)
{
- if (t->bt_sp == t->bt_maxstack) {
- t->bt_maxstack += 50;
- if ((t->bt_stack = (EPGNO *)realloc(t->bt_stack,
- t->bt_maxstack * sizeof(EPGNO))) == NULL) {
- t->bt_maxstack -= 50;
- return (RET_ERROR);
- }
- }
-
- t->bt_stack[t->bt_sp].pgno = pgno;
- t->bt_stack[t->bt_sp].index = index;
- ++t->bt_sp;
- return (RET_SUCCESS);
+ double temp, texp, temp2;
+ texp = exp;
+#ifdef __GNUC__
+#if __GNUC__ >= 2
+ asm ("fscale "
+ : "=u" (temp2), "=t" (temp)
+ : "0" (texp), "1" (value));
+#else
+ asm ("fscale ; fxch %%st(1) ; fstp%L1 %1 "
+ : "=f" (temp), "=0" (temp2)
+ : "0" (texp), "f" (value));
+#endif
+#else
+error unknown asm
+#endif
+ return (temp);
}
diff --git a/lib/libc/amd64/gen/setjmp.S b/lib/libc/amd64/gen/setjmp.S
new file mode 100644
index 0000000..6525a16
--- /dev/null
+++ b/lib/libc/amd64/gen/setjmp.S
@@ -0,0 +1,113 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+/*
+ * C library -- _setjmp, _longjmp
+ *
+ * longjmp(a,v)
+ * will generate a "return(v)" from the last call to
+ * setjmp(a)
+ * by restoring registers from the environment 'a'.
+ * The previous signal state is restored.
+ */
+
+#include "DEFS.h"
+#include "SYS.h"
+
+#ifdef _THREAD_SAFE
+ENTRY(_thread_sys_setjmp)
+#else
+ENTRY(setjmp)
+#endif
+ PIC_PROLOGUE
+ pushl $0
+#ifdef _THREAD_SAFE
+ call PIC_PLT(CNAME(_thread_sys_sigblock))
+#else
+ call PIC_PLT(CNAME(sigblock))
+#endif
+ popl %edx
+ PIC_EPILOGUE
+ movl 4(%esp),%ecx
+ movl 0(%esp),%edx
+ movl %edx, 0(%ecx)
+ movl %ebx, 4(%ecx)
+ movl %esp, 8(%ecx)
+ movl %ebp,12(%ecx)
+ movl %esi,16(%ecx)
+ movl %edi,20(%ecx)
+ movl %eax,24(%ecx)
+ fnstcw 28(%ecx)
+ xorl %eax,%eax
+ ret
+
+#ifdef _THREAD_SAFE
+ENTRY(_thread_sys_longjmp)
+#else
+ENTRY(longjmp)
+#endif
+ movl 4(%esp),%edx
+ PIC_PROLOGUE
+ pushl 24(%edx)
+#ifdef _THREAD_SAFE
+ call PIC_PLT(CNAME(_thread_sys_sigsetmask))
+#else
+ call PIC_PLT(CNAME(sigsetmask)) /* XXX this is not reentrant */
+#endif
+ popl %eax
+ PIC_EPILOGUE
+ movl 4(%esp),%edx
+ movl 8(%esp),%eax
+ movl 0(%edx),%ecx
+ movl 4(%edx),%ebx
+ movl 8(%edx),%esp
+ movl 12(%edx),%ebp
+ movl 16(%edx),%esi
+ movl 20(%edx),%edi
+ fninit
+ fldcw 28(%edx)
+ testl %eax,%eax
+ jnz 1f
+ incl %eax
+1: movl %ecx,0(%esp)
+ ret
diff --git a/lib/libc/amd64/gen/sigsetjmp.S b/lib/libc/amd64/gen/sigsetjmp.S
new file mode 100644
index 0000000..1220598
--- /dev/null
+++ b/lib/libc/amd64/gen/sigsetjmp.S
@@ -0,0 +1,125 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+#include "SYS.h"
+
+/*-
+ * TODO:
+ * Rename sigsetjmp to __sigsetjmp and siglongjmp to __siglongjmp,
+ * remove the other *jmp functions and define everything in terms
+ * of the renamed functions. This requires compiler support for
+ * the renamed functions (introduced in gcc-2.5.3; previous versions
+ * only supported *jmp with 0 or 1 leading underscores).
+ *
+ * Use sigprocmask() instead of sigblock() and sigsetmask(), and
+ * check for and handle errors.
+ *
+ * Restore _all_ the registers and the signal mask atomically. Can
+ * use sigreturn() if sigreturn() works.
+ */
+
+#ifdef _THREAD_SAFE
+ENTRY(_thread_sys_sigsetjmp)
+#else
+ENTRY(sigsetjmp)
+#endif
+ movl 8(%esp),%eax
+ movl 4(%esp),%ecx
+ movl %eax,32(%ecx)
+ testl %eax,%eax
+ jz 2f
+ PIC_PROLOGUE
+ pushl $0
+#ifdef _THREAD_SAFE
+ call PIC_PLT(CNAME(_thread_sys_sigblock))
+#else
+ call PIC_PLT(CNAME(sigblock))
+#endif
+ addl $4,%esp
+ PIC_EPILOGUE
+ movl 4(%esp),%ecx
+ movl %eax,24(%ecx)
+2: movl 0(%esp),%edx
+ movl %edx, 0(%ecx)
+ movl %ebx, 4(%ecx)
+ movl %esp, 8(%ecx)
+ movl %ebp,12(%ecx)
+ movl %esi,16(%ecx)
+ movl %edi,20(%ecx)
+ fnstcw 28(%ecx)
+ xorl %eax,%eax
+ ret
+
+#ifdef _THREAD_SAFE
+ENTRY(_thread_sys_siglongjmp)
+#else
+ENTRY(siglongjmp)
+#endif
+ movl 4(%esp),%edx
+ cmpl $0,32(%edx)
+ jz 2f
+ PIC_PROLOGUE
+ pushl 24(%edx)
+#ifdef _THREAD_SAFE
+ call PIC_PLT(CNAME(_thread_sys_sigsetmask))
+#else
+ call PIC_PLT(CNAME(sigsetmask))
+#endif
+ addl $4,%esp
+ PIC_EPILOGUE
+2: movl 4(%esp),%edx
+ movl 8(%esp),%eax
+ movl 0(%edx),%ecx
+ movl 4(%edx),%ebx
+ movl 8(%edx),%esp
+ movl 12(%edx),%ebp
+ movl 16(%edx),%esi
+ movl 20(%edx),%edi
+ fninit
+ fldcw 28(%edx)
+ testl %eax,%eax
+ jnz 1f
+ incl %eax
+1: movl %ecx,0(%esp)
+ ret
diff --git a/lib/libc/amd64/net/Makefile.inc b/lib/libc/amd64/net/Makefile.inc
new file mode 100644
index 0000000..dff7fd1
--- /dev/null
+++ b/lib/libc/amd64/net/Makefile.inc
@@ -0,0 +1,4 @@
+# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
+
+SRCS+= htonl.S htons.S ntohl.S ntohs.S
diff --git a/lib/libc/amd64/net/htonl.S b/lib/libc/amd64/net/htonl.S
new file mode 100644
index 0000000..095c40a
--- /dev/null
+++ b/lib/libc/amd64/net/htonl.S
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+/* netorder = htonl(hostorder) */
+
+#include "DEFS.h"
+
+ENTRY(htonl)
+ movl 4(%esp),%eax
+ xchgb %al,%ah
+ roll $16,%eax
+ xchgb %al,%ah
+ ret
diff --git a/lib/libc/amd64/net/htons.S b/lib/libc/amd64/net/htons.S
new file mode 100644
index 0000000..238dfc2
--- /dev/null
+++ b/lib/libc/amd64/net/htons.S
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+/* netorder = htons(hostorder) */
+
+#include "DEFS.h"
+
+ENTRY(htons)
+ movzwl 4(%esp),%eax
+ xchgb %al,%ah
+ ret
diff --git a/lib/libc/amd64/net/ntohl.S b/lib/libc/amd64/net/ntohl.S
new file mode 100644
index 0000000..5af5008
--- /dev/null
+++ b/lib/libc/amd64/net/ntohl.S
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+/* hostorder = ntohl(netorder) */
+
+#include "DEFS.h"
+
+ENTRY(ntohl)
+ movl 4(%esp),%eax
+ xchgb %al,%ah
+ roll $16,%eax
+ xchgb %al,%ah
+ ret
diff --git a/lib/libc/amd64/net/ntohs.S b/lib/libc/amd64/net/ntohs.S
new file mode 100644
index 0000000..4bed4a2
--- /dev/null
+++ b/lib/libc/amd64/net/ntohs.S
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+/* hostorder = ntohs(netorder) */
+
+#include "DEFS.h"
+
+ENTRY(ntohs)
+ movzwl 4(%esp),%eax
+ xchgb %al,%ah
+ ret
diff --git a/lib/libc/amd64/sys/Makefile.inc b/lib/libc/amd64/sys/Makefile.inc
new file mode 100644
index 0000000..0cf1aad
--- /dev/null
+++ b/lib/libc/amd64/sys/Makefile.inc
@@ -0,0 +1,13 @@
+# from: Makefile.inc,v 1.1 1993/09/03 19:04:23 jtc Exp
+# $Id: Makefile.inc,v 1.4 1997/02/22 14:59:27 peter Exp $
+
+.PATH: ${.CURDIR}/../libc/${MACHINE}/sys
+
+SRCS+= i386_get_ldt.c i386_set_ldt.c
+
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN2+= i386/sys/i386_get_ldt.2
+
+MLINKS+=i386_get_ldt.2 i386_set_ldt.2
+.endif
diff --git a/lib/libc/amd64/sys/brk.S b/lib/libc/amd64/sys/brk.S
new file mode 100644
index 0000000..4fdf0c6
--- /dev/null
+++ b/lib/libc/amd64/sys/brk.S
@@ -0,0 +1,91 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+
+#include "SYS.h"
+
+ .globl HIDENAME(curbrk)
+ .globl HIDENAME(minbrk)
+ENTRY(_brk)
+ jmp ok
+
+ENTRY(brk)
+#ifdef PIC
+ movl 4(%esp),%eax
+ PIC_PROLOGUE
+ movl PIC_GOT(HIDENAME(curbrk)),%edx # set up GOT addressing
+ movl PIC_GOT(HIDENAME(minbrk)),%ecx #
+ PIC_EPILOGUE
+ cmpl %eax,(%ecx)
+ jbe ok
+ movl (%ecx),%eax
+ movl %eax,4(%esp)
+ok:
+ lea SYS_break,%eax
+ KERNCALL
+ jb err
+ movl 4(%esp),%eax
+ movl %eax,(%edx)
+ movl $0,%eax
+ ret
+err:
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror))
+
+#else
+
+ movl 4(%esp),%eax
+ cmpl %eax,HIDENAME(minbrk)
+ jbe ok
+ movl HIDENAME(minbrk),%eax
+ movl %eax,4(%esp)
+ok:
+ lea SYS_break,%eax
+ KERNCALL
+ jb err
+ movl 4(%esp),%eax
+ movl %eax,HIDENAME(curbrk)
+ movl $0,%eax
+ ret
+err:
+ jmp HIDENAME(cerror)
+#endif
diff --git a/lib/libc/amd64/sys/cerror.S b/lib/libc/amd64/sys/cerror.S
new file mode 100644
index 0000000..2d8f935
--- /dev/null
+++ b/lib/libc/amd64/sys/cerror.S
@@ -0,0 +1,87 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+
+#include "SYS.h"
+
+ .globl HIDENAME(cerror)
+
+#ifdef _THREAD_SAFE
+ /*
+ * Threaded version using __error().
+ */
+ .globl CNAME(__error)
+ .type CNAME(__error),@function
+HIDENAME(cerror):
+ pushl %eax
+#ifdef PIC
+ /* The caller must execute the PIC prologue before jumping to cerror. */
+ call PIC_PLT(CNAME(__error))
+ popl %ecx
+ PIC_EPILOGUE
+#else
+ call CNAME(__error)
+ popl %ecx
+#endif
+ movl %ecx,(%eax)
+ movl $-1,%eax
+ movl $-1,%edx
+ ret
+
+#else /* _THREAD_SAFE */
+ /*
+ * Non-threaded version using global errno.
+ */
+ .globl CNAME(errno)
+HIDENAME(cerror):
+#ifdef PIC
+ /* The caller must execute the PIC prologue before jumping to cerror. */
+ movl PIC_GOT(CNAME(errno)),%ecx
+ movl %eax,(%ecx)
+ PIC_EPILOGUE
+#else
+ movl %eax,CNAME(errno)
+#endif
+ movl $-1,%eax
+ movl $-1,%edx
+ ret
+#endif /* _THREAD_SAFE */
diff --git a/lib/libc/amd64/sys/exect.S b/lib/libc/amd64/sys/exect.S
new file mode 100644
index 0000000..af0d2ee
--- /dev/null
+++ b/lib/libc/amd64/sys/exect.S
@@ -0,0 +1,56 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+
+#include "SYS.h"
+#include <machine/psl.h>
+
+ENTRY(exect)
+ lea SYS_execve,%eax
+ pushf
+ popl %edx
+ orl $ PSL_T,%edx
+ pushl %edx
+ popf
+ KERNCALL
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror)) /* exect(file, argv, env); */
diff --git a/lib/libc/amd64/sys/pipe.S b/lib/libc/amd64/sys/pipe.S
new file mode 100644
index 0000000..637b86f
--- /dev/null
+++ b/lib/libc/amd64/sys/pipe.S
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+
+#include "SYS.h"
+
+PSYSCALL(pipe)
+ movl 4(%esp),%ecx
+ movl %eax,(%ecx)
+ movl %edx,4(%ecx)
+ movl $0,%eax
+ ret
diff --git a/lib/libc/amd64/sys/ptrace.S b/lib/libc/amd64/sys/ptrace.S
new file mode 100644
index 0000000..018a02c
--- /dev/null
+++ b/lib/libc/amd64/sys/ptrace.S
@@ -0,0 +1,62 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+
+#include "SYS.h"
+
+ENTRY(ptrace)
+ xorl %eax,%eax
+#ifdef PIC
+ PIC_PROLOGUE
+ movl PIC_GOT(CNAME(errno)),%edx
+ movl %eax,(%edx)
+ PIC_EPILOGUE
+#else
+ movl %eax,CNAME(errno)
+#endif
+ lea SYS_ptrace,%eax
+ KERNCALL
+ jb err
+ ret
+err:
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror))
diff --git a/lib/libc/amd64/sys/reboot.S b/lib/libc/amd64/sys/reboot.S
new file mode 100644
index 0000000..70049b2
--- /dev/null
+++ b/lib/libc/amd64/sys/reboot.S
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+
+#include "SYS.h"
+
+SYSCALL(reboot)
+ iret
diff --git a/lib/libc/amd64/sys/sbrk.S b/lib/libc/amd64/sys/sbrk.S
new file mode 100644
index 0000000..a3afd89
--- /dev/null
+++ b/lib/libc/amd64/sys/sbrk.S
@@ -0,0 +1,95 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+
+#include "SYS.h"
+
+ .globl CNAME(end)
+ .globl HIDENAME(minbrk)
+ .globl HIDENAME(curbrk)
+
+ .data
+HIDENAME(minbrk): .long CNAME(end)
+HIDENAME(curbrk): .long CNAME(end)
+ .text
+
+ENTRY(sbrk)
+#ifdef PIC
+ movl 4(%esp),%ecx
+ PIC_PROLOGUE
+ movl PIC_GOT(HIDENAME(curbrk)),%edx
+ movl (%edx),%eax
+ PIC_EPILOGUE
+ testl %ecx,%ecx
+ jz back
+ addl %eax,4(%esp)
+ lea SYS_break,%eax
+ KERNCALL
+ jb err
+ PIC_PROLOGUE
+ movl PIC_GOT(HIDENAME(curbrk)),%edx
+ movl (%edx),%eax
+ addl %ecx,(%edx)
+ PIC_EPILOGUE
+back:
+ ret
+err:
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror))
+
+#else /* !PIC */
+
+ movl 4(%esp),%ecx
+ movl HIDENAME(curbrk),%eax
+ testl %ecx,%ecx
+ jz back
+ addl %eax,4(%esp)
+ lea SYS_break,%eax
+ KERNCALL
+ jb err
+ movl HIDENAME(curbrk),%eax
+ addl %ecx,HIDENAME(curbrk)
+back:
+ ret
+err:
+ jmp HIDENAME(cerror)
+#endif /* PIC */
diff --git a/lib/libc/amd64/sys/setlogin.S b/lib/libc/amd64/sys/setlogin.S
new file mode 100644
index 0000000..7bcf3bd
--- /dev/null
+++ b/lib/libc/amd64/sys/setlogin.S
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "SYS.h"
+
+.globl CNAME(_logname_valid) /* in getlogin() */
+
+SYSCALL(setlogin)
+#ifdef PIC
+ PIC_PROLOGUE
+ pushl %eax
+ movl PIC_GOT(CNAME(_logname_valid)),%eax
+ movl $0,(%eax)
+ popl %eax
+ PIC_EPILOGUE
+#else
+ movl $0,CNAME(_logname_valid)
+#endif
+ ret /* setlogin(name) */
diff --git a/lib/libc/amd64/sys/sigreturn.S b/lib/libc/amd64/sys/sigreturn.S
new file mode 100644
index 0000000..65deb40
--- /dev/null
+++ b/lib/libc/amd64/sys/sigreturn.S
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+
+#include "SYS.h"
+
+/*
+ * NOTE: If the profiling ENTRY() code ever changes any registers, they
+ * must be saved. On FreeBSD, this is not the case.
+ */
+
+PSYSCALL(sigreturn)
+ ret
diff --git a/lib/libc/amd64/sys/vfork.S b/lib/libc/amd64/sys/vfork.S
new file mode 100644
index 0000000..e4ed257
--- /dev/null
+++ b/lib/libc/amd64/sys/vfork.S
@@ -0,0 +1,101 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+
+#include "DEFS.h"
+#include "SYS.h"
+
+/*
+ * pid = vfork();
+ *
+ * %edx == 0 in parent process, %edx == 1 in child process.
+ * %eax == pid of child in parent, %eax == pid of parent in child.
+ *
+ */
+
+ENTRY(vfork)
+ popl %ecx /* my rta into ecx */
+ lea SYS_vfork,%eax
+ KERNCALL
+ jb verror
+vforkok:
+ cmpl $0,%edx /* child process? */
+ jne child /* yes */
+ jmp parent
+#ifdef _THREAD_SAFE
+ /*
+ * Threaded version using __error().
+ */
+ .globl CNAME(__error)
+ .type CNAME(__error),@function
+verror:
+ pushl %eax
+#ifdef PIC
+ call PIC_PLT(CNAME(__error))
+#else
+ call CNAME(__error)
+#endif
+ popl %ecx
+ movl %ecx,(%eax)
+ movl $-1,%eax
+ movl $-1,%edx
+#else /* !_THREAD_SAFE */
+ /*
+ * Non-threaded version using global errno.
+ */
+ .globl CNAME(errno)
+verror:
+#ifdef PIC
+ PIC_PROLOGUE
+ movl PIC_GOT(CNAME(errno)), %edx
+ movl %eax,(%edx)
+ PIC_EPILOGUE
+#else
+ movl %eax,CNAME(errno)
+#endif
+ movl $-1,%eax
+#endif /* !_THREAD_SAFE */
+ jmp %ecx
+child:
+ movl $0,%eax
+parent:
+ jmp %ecx
diff --git a/lib/libc/compat-43/Makefile.inc b/lib/libc/compat-43/Makefile.inc
index e4d66f5..25d7763 100644
--- a/lib/libc/compat-43/Makefile.inc
+++ b/lib/libc/compat-43/Makefile.inc
@@ -1,13 +1,20 @@
# @(#)Makefile.inc 8.1 (Berkeley) 6/2/93
+# $Id$
# compat-43 sources
-.PATH: ${.CURDIR}/${MACHINE}/compat-43 ${.CURDIR}/compat-43
+.PATH: ${.CURDIR}/../libc/${MACHINE}/compat-43 ${.CURDIR}/../libc/compat-43
SRCS+= creat.c gethostid.c getwd.c killpg.c sethostid.c setpgrp.c \
- setregid.c setreuid.c setrgid.c setruid.c sigcompat.c
+ setrgid.c setruid.c sigcompat.c
-MAN2+= creat.0 gethostid.0 killpg.0 setregid.0 setreuid.0 setruid.0 \
- sigblock.0 sigpause.0 sigsetmask.0 sigvec.0
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN2+= compat-43/creat.2 compat-43/killpg.2 \
+ compat-43/sigblock.2 \
+ compat-43/sigpause.2 compat-43/sigsetmask.2 compat-43/sigvec.2
-MLINKS+=setruid.2 setrgid.2
-MLINKS+=gethostid.2 sethostid.2
+MAN3+= compat-43/gethostid.3 compat-43/setruid.3
+
+MLINKS+=setruid.3 setrgid.3
+MLINKS+=gethostid.3 sethostid.3
+.endif
diff --git a/lib/libc/compat-43/creat.2 b/lib/libc/compat-43/creat.2
index 826909a..b4a035c 100644
--- a/lib/libc/compat-43/creat.2
+++ b/lib/libc/compat-43/creat.2
@@ -40,7 +40,7 @@
.Sh SYNOPSIS
.Fd #include <fcntl.h>
.Ft int
-.Fn creat "char *path" "mode_t mode"
+.Fn creat "const char *path" "mode_t mode"
.Sh DESCRIPTION
.Bf -symbolic
This interface is made obsolete by:
@@ -56,5 +56,6 @@ open(path, O_CREAT | O_TRUNC | O_WRONLY, mode);
.Xr open 2
.Sh HISTORY
The
-.Nm
-function call appeared in Version 6 AT&T UNIX.
+.Fn creat
+function call appeared in
+.At v6 .
diff --git a/lib/libc/compat-43/creat.c b/lib/libc/compat-43/creat.c
index 31d60b8..a4f1234 100644
--- a/lib/libc/compat-43/creat.c
+++ b/lib/libc/compat-43/creat.c
@@ -37,6 +37,7 @@ static char sccsid[] = "@(#)creat.c 8.1 (Berkeley) 6/2/93";
#include <fcntl.h>
+int
#if __STDC__
creat(const char *path, mode_t mode)
#else
diff --git a/lib/libc/compat-43/gethostid.3 b/lib/libc/compat-43/gethostid.3
index 8f56a28..b4f6b62 100644
--- a/lib/libc/compat-43/gethostid.3
+++ b/lib/libc/compat-43/gethostid.3
@@ -42,7 +42,7 @@
.Fd #include <unistd.h>
.Ft long
.Fn gethostid void
-.Ft int
+.Ft void
.Fn sethostid "long hostid"
.Sh DESCRIPTION
.Fn Sethostid
@@ -57,10 +57,10 @@ returns the 32-bit identifier for the current processor.
.Pp
This function has been deprecated.
The hostid should be set or retrieved by use of
-.Xr sysctl 2 .
+.Xr sysctl 3 .
.Sh SEE ALSO
-.Xr sysctl 2 ,
.Xr gethostname 3 ,
+.Xr sysctl 3 ,
.Xr sysctl 8 .
.Sh BUGS
32 bits for the identifier is too small.
diff --git a/lib/libc/compat-43/getwd.c b/lib/libc/compat-43/getwd.c
index f105150e..9f0e633 100644
--- a/lib/libc/compat-43/getwd.c
+++ b/lib/libc/compat-43/getwd.c
@@ -47,7 +47,7 @@ getwd(buf)
{
char *p;
- if (p = getcwd(buf, MAXPATHLEN))
+ if ( (p = getcwd(buf, MAXPATHLEN)) )
return(p);
(void)strcpy(buf, strerror(errno));
return((char *)NULL);
diff --git a/lib/libc/compat-43/killpg.2 b/lib/libc/compat-43/killpg.2
index b57e406..01e44f4 100644
--- a/lib/libc/compat-43/killpg.2
+++ b/lib/libc/compat-43/killpg.2
@@ -38,6 +38,7 @@
.Nm killpg
.Nd send signal to a process group
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
.Fd #include <signal.h>
.Ft int
.Fn killpg "pid_t pgrp" "int sig"
@@ -85,11 +86,11 @@ of the target processes has an effective user ID different from that
of the sending process.
.El
.Sh SEE ALSO
-.Xr kill 2 ,
.Xr getpgrp 2 ,
+.Xr kill 2 ,
.Xr sigaction 2
.Sh HISTORY
The
-.Nm
+.Fn killpg
function call appeared in
.Bx 4.0 .
diff --git a/lib/libc/compat-43/killpg.c b/lib/libc/compat-43/killpg.c
index f9b7901..ac3ba6e 100644
--- a/lib/libc/compat-43/killpg.c
+++ b/lib/libc/compat-43/killpg.c
@@ -42,6 +42,7 @@ static char sccsid[] = "@(#)killpg.c 8.1 (Berkeley) 6/2/93";
/*
* Backwards-compatible killpg().
*/
+int
#if __STDC__
killpg(pid_t pgid, int sig)
#else
diff --git a/lib/libc/compat-43/setpgrp.c b/lib/libc/compat-43/setpgrp.c
index df63ebd..dc0dd3f 100644
--- a/lib/libc/compat-43/setpgrp.c
+++ b/lib/libc/compat-43/setpgrp.c
@@ -38,6 +38,7 @@ static char sccsid[] = "@(#)setpgrp.c 8.1 (Berkeley) 6/2/93";
#include <sys/types.h>
#include <unistd.h>
+int
#if __STDC__
setpgrp(pid_t pid, pid_t pgid)
#else
diff --git a/lib/libc/compat-43/setruid.3 b/lib/libc/compat-43/setruid.3
index 7342b21..32245c1 100644
--- a/lib/libc/compat-43/setruid.3
+++ b/lib/libc/compat-43/setruid.3
@@ -39,7 +39,7 @@
.Nm setrgid
.Nd set user and group ID
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
+.Fd #include <unistd.h>
.Ft int
.Fn setruid "uid_t ruid"
.Ft int
@@ -62,12 +62,12 @@ functions return \-1.
The use of these calls is not portable.
Their use is discouraged; they will be removed in the future.
.Sh SEE ALSO
-.Xr setuid 2 ,
-.Xr setgid 2 ,
-.Xr seteuid 2 ,
-.Xr setegid 2 ,
+.Xr getgid 2 ,
.Xr getuid 2 ,
-.Xr getgid 2
+.Xr setegid 2 ,
+.Xr seteuid 2 ,
+.Xr setgid 2 ,
+.Xr setuid 2
.Sh HISTORY
The
.Fn setruid
diff --git a/lib/libc/compat-43/sigblock.2 b/lib/libc/compat-43/sigblock.2
index 60e4251..bb61f61 100644
--- a/lib/libc/compat-43/sigblock.2
+++ b/lib/libc/compat-43/sigblock.2
@@ -72,13 +72,13 @@ imposed by the system.
The previous set of masked signals is returned.
.Sh SEE ALSO
.Xr kill 2 ,
-.Xr sigprocmask 2 ,
.Xr sigaction 2 ,
+.Xr sigprocmask 2 ,
.Xr sigsetmask 2 ,
.Xr sigsetops 3
.Sh HISTORY
The
-.Nm
+.Fn sigblock
function call appeared in
.Bx 4.2
and has been deprecated.
diff --git a/lib/libc/compat-43/sigcompat.c b/lib/libc/compat-43/sigcompat.c
index 69b1870..56550d2 100644
--- a/lib/libc/compat-43/sigcompat.c
+++ b/lib/libc/compat-43/sigcompat.c
@@ -38,6 +38,7 @@ static char sccsid[] = "@(#)sigcompat.c 8.1 (Berkeley) 6/2/93";
#include <sys/param.h>
#include <signal.h>
+int
sigvec(signo, sv, osv)
int signo;
struct sigvec *sv, *osv;
@@ -52,6 +53,7 @@ sigvec(signo, sv, osv)
return (ret);
}
+int
sigsetmask(mask)
int mask;
{
@@ -63,6 +65,7 @@ sigsetmask(mask)
return (omask);
}
+int
sigblock(mask)
int mask;
{
@@ -74,6 +77,7 @@ sigblock(mask)
return (omask);
}
+int
sigpause(mask)
int mask;
{
diff --git a/lib/libc/compat-43/sigpause.2 b/lib/libc/compat-43/sigpause.2
index 7c6c097..52230cc 100644
--- a/lib/libc/compat-43/sigpause.2
+++ b/lib/libc/compat-43/sigpause.2
@@ -60,15 +60,15 @@ always terminates by being interrupted, returning -1 with
set to
.Dv EINTR
.Sh SEE ALSO
-.Xr sigsuspend 2 ,
.Xr kill 2 ,
.Xr sigaction 2 ,
-.Xr sigprocmask 2 ,
.Xr sigblock 2 ,
+.Xr sigprocmask 2 ,
+.Xr sigsuspend 2 ,
.Xr sigvec 2
.Sh HISTORY
The
-.Nm
+.Fn sigpause
function call appeared in
.Bx 4.2
and has been deprecated.
diff --git a/lib/libc/compat-43/sigsetmask.2 b/lib/libc/compat-43/sigsetmask.2
index 13b7c1a..6131b0f 100644
--- a/lib/libc/compat-43/sigsetmask.2
+++ b/lib/libc/compat-43/sigsetmask.2
@@ -67,16 +67,16 @@ to be blocked.
.Sh RETURN VALUES
The previous set of masked signals is returned.
.Sh SEE ALSO
-.Xr sigprocmask 2 ,
.Xr kill 2 ,
.Xr sigaction 2 ,
+.Xr sigblock 2 ,
+.Xr sigprocmask 2 ,
.Xr sigsuspend 2 ,
.Xr sigvec 2 ,
-.Xr sigblock 2 ,
.Xr sigsetops 3
.Sh HISTORY
The
-.Nm
+.Fn sigsetmask
function call appeared in
.Bx 4.2
and has been deprecated.
diff --git a/lib/libc/compat-43/sigvec.2 b/lib/libc/compat-43/sigvec.2
index 1b5244f..de8d452 100644
--- a/lib/libc/compat-43/sigvec.2
+++ b/lib/libc/compat-43/sigvec.2
@@ -46,6 +46,7 @@ struct sigvec {
int sv_flags;
};
.Ed
+.Ft int
.Fn sigvec "int sig" "struct sigvec *vec" "struct sigvec *ovec"
.Sh DESCRIPTION
.Bf -symbolic
@@ -102,9 +103,9 @@ must arrange to restore the previous context itself.
When a signal is delivered to a process a new signal mask is
installed for the duration of the process' signal handler
(or until a
-.Xr sigblock
+.Xr sigblock 2
or
-.Xr sigsetmask
+.Xr sigsetmask 2
call is made).
This mask is formed by taking the current signal mask,
adding the signal to be delivered, and
@@ -140,7 +141,7 @@ with names as in the include file
.It Dv SIGQUIT No " create core image" " quit program"
.It Dv SIGILL No " create core image" " illegal instruction"
.It Dv SIGTRAP No " create core image" " trace trap"
-.It Dv SIGABRT No " create core image" Xr abort 2
+.It Dv SIGABRT No " create core image" Xr abort 3
call (formerly
.Dv SIGIOT )
.It Dv SIGEMT No " create core image" " emulate instruction executed"
@@ -148,7 +149,7 @@ call (formerly
.It Dv SIGKILL No " terminate process" " kill program"
.It Dv SIGBUS No " create core image" " bus error"
.It Dv SIGSEGV No " create core image" " segmentation violation"
-.It Dv SIGSYS No " create core image" " system call given invalid argument"
+.It Dv SIGSYS No " create core image" " non-existent system call invoked"
.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader"
.It Dv SIGALRM No " terminate process" " real-time timer expired"
.It Dv SIGTERM No " terminate process" " software termination signal"
@@ -289,7 +290,7 @@ or
.Xr sigsuspend 2 ,
.Xr setjmp 3 ,
.Xr siginterrupt 3 ,
-.Xr signal 3,
+.Xr signal 3 ,
.Xr sigsetops 3 ,
.Xr tty 4
.Sh EXAMPLE
diff --git a/lib/libc/db/Makefile.inc b/lib/libc/db/Makefile.inc
index 77af9c5..518205c 100644
--- a/lib/libc/db/Makefile.inc
+++ b/lib/libc/db/Makefile.inc
@@ -1,10 +1,11 @@
-# @(#)Makefile.inc 8.2 (Berkeley) 2/21/94
+# from @(#)Makefile.inc 8.2 (Berkeley) 2/21/94
+# $Id$
#
CFLAGS+=-D__DBINTERFACE_PRIVATE
-.include "${.CURDIR}/db/btree/Makefile.inc"
-.include "${.CURDIR}/db/db/Makefile.inc"
-.include "${.CURDIR}/db/hash/Makefile.inc"
-.include "${.CURDIR}/db/man/Makefile.inc"
-.include "${.CURDIR}/db/mpool/Makefile.inc"
-.include "${.CURDIR}/db/recno/Makefile.inc"
+.include "${.CURDIR}/../libc/db/btree/Makefile.inc"
+.include "${.CURDIR}/../libc/db/db/Makefile.inc"
+.include "${.CURDIR}/../libc/db/hash/Makefile.inc"
+.include "${.CURDIR}/../libc/db/man/Makefile.inc"
+.include "${.CURDIR}/../libc/db/mpool/Makefile.inc"
+.include "${.CURDIR}/../libc/db/recno/Makefile.inc"
diff --git a/lib/libc/db/README b/lib/libc/db/README
new file mode 100644
index 0000000..bed2c92
--- /dev/null
+++ b/lib/libc/db/README
@@ -0,0 +1,40 @@
+# @(#)README 8.27 (Berkeley) 9/1/94
+
+This is version 1.85 of the Berkeley DB code.
+
+For information on compiling and installing this software, see the file
+PORT/README.
+
+Newer versions of this software will periodically be made available by
+anonymous ftp from ftp.cs.berkeley.edu. An archive in compressed format
+is in ucb/4bsd/db.tar.Z, or in gzip format in ucb/4bsd/db.tar.gz. If
+you'd like to receive announcements of future releases of this software,
+send email to the contact address below.
+
+Email questions may be addressed to Keith Bostic at bostic@cs.berkeley.edu.
+
+============================================
+Distribution contents:
+
+Makefile.inc Ignore this, it's the 4.4BSD subsystem Makefile.
+PORT The per OS/architecture directories to use to build
+ libdb.a, if you're not running 4.4BSD. See the file
+ PORT/README for more information.
+README This file.
+btree The B+tree routines.
+changelog List of changes, per version.
+db The dbopen(3) interface routine.
+docs Various USENIX papers, and the formatted manual pages.
+hash The extended linear hashing routines.
+man The unformatted manual pages.
+mpool The memory pool routines.
+recno The fixed/variable length record routines.
+test Test package.
+
+============================================
+Debugging:
+
+If you're running a memory checker (e.g. Purify) on DB, make sure that
+you recompile it with "-DPURIFY" in the CFLAGS, first. By default,
+allocated pages are not initialized by the DB code, and they will show
+up as reads of uninitialized memory in the buffer write routines.
diff --git a/lib/libc/db/btree/Makefile.inc b/lib/libc/db/btree/Makefile.inc
index 8ed7649..f373a21 100644
--- a/lib/libc/db/btree/Makefile.inc
+++ b/lib/libc/db/btree/Makefile.inc
@@ -1,6 +1,7 @@
-# @(#)Makefile.inc 8.2 (Berkeley) 7/14/94
+# from @(#)Makefile.inc 8.2 (Berkeley) 7/14/94
+# $Id$
-.PATH: ${.CURDIR}/db/btree
+.PATH: ${.CURDIR}/../libc/db/btree
SRCS+= bt_close.c bt_conv.c bt_debug.c bt_delete.c bt_get.c bt_open.c \
bt_overflow.c bt_page.c bt_put.c bt_search.c bt_seq.c bt_split.c \
diff --git a/lib/libc/db/btree/bt_open.c b/lib/libc/db/btree/bt_open.c
index f052249..5fc3168 100644
--- a/lib/libc/db/btree/bt_open.c
+++ b/lib/libc/db/btree/bt_open.c
@@ -125,7 +125,7 @@ __bt_open(fname, flags, mode, openinfo, dflags)
*/
if (b.psize &&
(b.psize < MINPSIZE || b.psize > MAX_PAGE_OFFSET + 1 ||
- b.psize & sizeof(indx_t) - 1))
+ b.psize & (sizeof(indx_t) - 1) ))
goto einval;
/* Minimum number of keys per page; absolute minimum is 2. */
@@ -245,7 +245,7 @@ __bt_open(fname, flags, mode, openinfo, dflags)
if (m.magic != BTREEMAGIC || m.version != BTREEVERSION)
goto eftype;
if (m.psize < MINPSIZE || m.psize > MAX_PAGE_OFFSET + 1 ||
- m.psize & sizeof(indx_t) - 1)
+ m.psize & (sizeof(indx_t) - 1) )
goto eftype;
if (m.flags & ~SAVEMETA)
goto eftype;
@@ -278,8 +278,8 @@ __bt_open(fname, flags, mode, openinfo, dflags)
t->bt_psize = b.psize;
/* Set the cache size; must be a multiple of the page size. */
- if (b.cachesize && b.cachesize & b.psize - 1)
- b.cachesize += (~b.cachesize & b.psize - 1) + 1;
+ if (b.cachesize && b.cachesize & (b.psize - 1) )
+ b.cachesize += (~b.cachesize & (b.psize - 1) ) + 1;
if (b.cachesize < b.psize * MINCACHE)
b.cachesize = b.psize * MINCACHE;
diff --git a/lib/libc/db/VERSION b/lib/libc/db/changelog
index be08b78..1540ca8 100644
--- a/lib/libc/db/VERSION
+++ b/lib/libc/db/changelog
@@ -1,39 +1,45 @@
-# @(#)VERSION 8.9 (Berkeley) 4/2/94
-
-This is version 1.74 of the Berkeley DB code.
-
-If your version of the DB code doesn't have a copy
-of this version file, it's really old, please update it!
-
-New versions of this software are periodically made
-available by anonymous ftp from ftp.cs.berkeley.edu,
-in the file ucb/4bsd/db.tar.Z, or from ftp.uu.net.
-If you'd like to get announcements of future releases
-of this software, send email to the contact address
-below.
-
-Email questions may be addressed to Keith Bostic at
-bostic@cs.berkeley.edu.
-
-============================================
-Distribution contents:
-
-Makefile.inc Ignore this, it's the 4.4BSD subsystem Makefile.
-PORT The per OS/architecture directories to use to build
- libdb.a, if you're not running 4.4BSD. See the file
- PORT/README for more information.
-README This file.
-VERSION This file.
-btree B+tree routines.
-db Dbopen(3) interface routine.
-doc USENIX papers, formatted manual pages.
-hash Extended linear hashing routines.
-man Unformatted manual pages.
-mpool Memory pool routines.
-recno Fixed/variable length record routines.
-test Test package.
-
-============================================
+1.84 -> 1.85
+ recno: #ifdef out use of mmap, it's not portable enough.
+
+1.83 -> 1.84 Thu Aug 18 15:46:07 EDT 1994
+ recno: Rework fixed-length records so that closing and reopening
+ the file now works. Pad short records on input. Never do
+ signed comparison in recno input reading functions.
+
+1.82 -> 1.83 Tue Jul 26 15:33:44 EDT 1994
+ btree: Rework cursor deletion code yet again; bugs with
+ deleting empty pages that only contained the cursor
+ record.
+
+1.81 -> 1.82 Sat Jul 16 11:01:50 EDT 1994
+ btree: Fix bugs introduced by new cursor/deletion code.
+ Replace return kbuf/dbuf with real DBT's.
+
+1.80 -> 1.81
+ btree: Fix bugs introduced by new cursor/deletion code.
+ all: Add #defines for Purify.
+
+1.79 -> 1.80 Wed Jul 13 22:41:54 EDT 1994
+ btree Change deletion to coalesce empty pages. This is a major
+ change, cursors and duplicate pages all had to be reworked.
+ Return to a fixed stack.
+ recno: Affected by cursor changes. New cursor structures should
+ permit multiple cursors in the future.
+
+1.78 -> 1.79 Mon Jun 20 17:36:47 EDT 1994
+ all: Minor cleanups of 1.78 for porting reasons; only
+ major change was inlining check of NULL pointer
+ so that __fix_realloc goes away.
+
+1.77 -> 1.78 Thu Jun 16 19:06:43 EDT 1994
+ all: Move "standard" size typedef's into db.h.
+
+1.76 -> 1.77 Thu Jun 16 16:48:38 EDT 1994
+ hash: Delete __init_ routine, has special meaning to OSF 2.0.
+
+1.74 -> 1.76
+ all: Finish up the port to the Alpha.
+
1.73 -> 1.74
recno: Don't put the record if rec_search fails, in rec_rdelete.
Create fixed-length intermediate records past "end" of DB
@@ -52,7 +58,7 @@ test Test package.
1.7 -> 1.72 12 Oct 1993
hash: Support NET/2 hash formats.
-
+
1.7 -> 1.71 16 Sep 1993
btree/recno:
Fix bug in internal search routines that caused
diff --git a/lib/libc/db/db/Makefile.inc b/lib/libc/db/db/Makefile.inc
index 59478ba1..a10f0fc 100644
--- a/lib/libc/db/db/Makefile.inc
+++ b/lib/libc/db/db/Makefile.inc
@@ -1,5 +1,6 @@
-# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
-.PATH: ${.CURDIR}/db/db
+.PATH: ${.CURDIR}/../libc/db/db
SRCS+= db.c
diff --git a/lib/libc/db/doc/hash.usenix.ps b/lib/libc/db/doc/hash.usenix.ps
deleted file mode 100644
index c884778..0000000
--- a/lib/libc/db/doc/hash.usenix.ps
+++ /dev/null
@@ -1,12209 +0,0 @@
-%!PS-Adobe-1.0
-%%Creator: utopia:margo (& Seltzer,608-13E,8072,)
-%%Title: stdin (ditroff)
-%%CreationDate: Tue Dec 11 15:06:45 1990
-%%EndComments
-% @(#)psdit.pro 1.3 4/15/88
-% lib/psdit.pro -- prolog for psdit (ditroff) files
-% Copyright (c) 1984, 1985 Adobe Systems Incorporated. All Rights Reserved.
-% last edit: shore Sat Nov 23 20:28:03 1985
-% RCSID: $Header: psdit.pro,v 2.1 85/11/24 12:19:43 shore Rel $
-
-% Changed by Edward Wang (edward@ucbarpa.berkeley.edu) to handle graphics,
-% 17 Feb, 87.
-
-/$DITroff 140 dict def $DITroff begin
-/fontnum 1 def /fontsize 10 def /fontheight 10 def /fontslant 0 def
-/xi{0 72 11 mul translate 72 resolution div dup neg scale 0 0 moveto
- /fontnum 1 def /fontsize 10 def /fontheight 10 def /fontslant 0 def F
- /pagesave save def}def
-/PB{save /psv exch def currentpoint translate
- resolution 72 div dup neg scale 0 0 moveto}def
-/PE{psv restore}def
-/arctoobig 90 def /arctoosmall .05 def
-/m1 matrix def /m2 matrix def /m3 matrix def /oldmat matrix def
-/tan{dup sin exch cos div}def
-/point{resolution 72 div mul}def
-/dround {transform round exch round exch itransform}def
-/xT{/devname exch def}def
-/xr{/mh exch def /my exch def /resolution exch def}def
-/xp{}def
-/xs{docsave restore end}def
-/xt{}def
-/xf{/fontname exch def /slotno exch def fontnames slotno get fontname eq not
- {fonts slotno fontname findfont put fontnames slotno fontname put}if}def
-/xH{/fontheight exch def F}def
-/xS{/fontslant exch def F}def
-/s{/fontsize exch def /fontheight fontsize def F}def
-/f{/fontnum exch def F}def
-/F{fontheight 0 le{/fontheight fontsize def}if
- fonts fontnum get fontsize point 0 0 fontheight point neg 0 0 m1 astore
- fontslant 0 ne{1 0 fontslant tan 1 0 0 m2 astore m3 concatmatrix}if
- makefont setfont .04 fontsize point mul 0 dround pop setlinewidth}def
-/X{exch currentpoint exch pop moveto show}def
-/N{3 1 roll moveto show}def
-/Y{exch currentpoint pop exch moveto show}def
-/S{show}def
-/ditpush{}def/ditpop{}def
-/AX{3 -1 roll currentpoint exch pop moveto 0 exch ashow}def
-/AN{4 2 roll moveto 0 exch ashow}def
-/AY{3 -1 roll currentpoint pop exch moveto 0 exch ashow}def
-/AS{0 exch ashow}def
-/MX{currentpoint exch pop moveto}def
-/MY{currentpoint pop exch moveto}def
-/MXY{moveto}def
-/cb{pop}def % action on unknown char -- nothing for now
-/n{}def/w{}def
-/p{pop showpage pagesave restore /pagesave save def}def
-/Dt{/Dlinewidth exch def}def 1 Dt
-/Ds{/Ddash exch def}def -1 Ds
-/Di{/Dstipple exch def}def 1 Di
-/Dsetlinewidth{2 Dlinewidth mul setlinewidth}def
-/Dsetdash{Ddash 4 eq{[8 12]}{Ddash 16 eq{[32 36]}
- {Ddash 20 eq{[32 12 8 12]}{[]}ifelse}ifelse}ifelse 0 setdash}def
-/Dstroke{gsave Dsetlinewidth Dsetdash 1 setlinecap stroke grestore
- currentpoint newpath moveto}def
-/Dl{rlineto Dstroke}def
-/arcellipse{/diamv exch def /diamh exch def oldmat currentmatrix pop
- currentpoint translate 1 diamv diamh div scale /rad diamh 2 div def
- currentpoint exch rad add exch rad -180 180 arc oldmat setmatrix}def
-/Dc{dup arcellipse Dstroke}def
-/De{arcellipse Dstroke}def
-/Da{/endv exch def /endh exch def /centerv exch def /centerh exch def
- /cradius centerv centerv mul centerh centerh mul add sqrt def
- /eradius endv endv mul endh endh mul add sqrt def
- /endang endv endh atan def
- /startang centerv neg centerh neg atan def
- /sweep startang endang sub dup 0 lt{360 add}if def
- sweep arctoobig gt
- {/midang startang sweep 2 div sub def /midrad cradius eradius add 2 div def
- /midh midang cos midrad mul def /midv midang sin midrad mul def
- midh neg midv neg endh endv centerh centerv midh midv Da
- Da}
- {sweep arctoosmall ge
- {/controldelt 1 sweep 2 div cos sub 3 sweep 2 div sin mul div 4 mul def
- centerv neg controldelt mul centerh controldelt mul
- endv neg controldelt mul centerh add endh add
- endh controldelt mul centerv add endv add
- centerh endh add centerv endv add rcurveto Dstroke}
- {centerh endh add centerv endv add rlineto Dstroke}
- ifelse}
- ifelse}def
-/Dpatterns[
-[%cf[widthbits]
-[8<0000000000000010>]
-[8<0411040040114000>]
-[8<0204081020408001>]
-[8<0000103810000000>]
-[8<6699996666999966>]
-[8<0000800100001008>]
-[8<81c36666c3810000>]
-[8<0f0e0c0800000000>]
-[8<0000000000000010>]
-[8<0411040040114000>]
-[8<0204081020408001>]
-[8<0000001038100000>]
-[8<6699996666999966>]
-[8<0000800100001008>]
-[8<81c36666c3810000>]
-[8<0f0e0c0800000000>]
-[8<0042660000246600>]
-[8<0000990000990000>]
-[8<0804020180402010>]
-[8<2418814242811824>]
-[8<6699996666999966>]
-[8<8000000008000000>]
-[8<00001c3e363e1c00>]
-[8<0000000000000000>]
-[32<00000040000000c00000004000000040000000e0000000000000000000000000>]
-[32<00000000000060000000900000002000000040000000f0000000000000000000>]
-[32<000000000000000000e0000000100000006000000010000000e0000000000000>]
-[32<00000000000000002000000060000000a0000000f00000002000000000000000>]
-[32<0000000e0000000000000000000000000000000f000000080000000e00000001>]
-[32<0000090000000600000000000000000000000000000007000000080000000e00>]
-[32<00010000000200000004000000040000000000000000000000000000000f0000>]
-[32<0900000006000000090000000600000000000000000000000000000006000000>]]
-[%ug
-[8<0000020000000000>]
-[8<0000020000002000>]
-[8<0004020000002000>]
-[8<0004020000402000>]
-[8<0004060000402000>]
-[8<0004060000406000>]
-[8<0006060000406000>]
-[8<0006060000606000>]
-[8<00060e0000606000>]
-[8<00060e000060e000>]
-[8<00070e000060e000>]
-[8<00070e000070e000>]
-[8<00070e020070e000>]
-[8<00070e020070e020>]
-[8<04070e020070e020>]
-[8<04070e024070e020>]
-[8<04070e064070e020>]
-[8<04070e064070e060>]
-[8<06070e064070e060>]
-[8<06070e066070e060>]
-[8<06070f066070e060>]
-[8<06070f066070f060>]
-[8<060f0f066070f060>]
-[8<060f0f0660f0f060>]
-[8<060f0f0760f0f060>]
-[8<060f0f0760f0f070>]
-[8<0e0f0f0760f0f070>]
-[8<0e0f0f07e0f0f070>]
-[8<0e0f0f0fe0f0f070>]
-[8<0e0f0f0fe0f0f0f0>]
-[8<0f0f0f0fe0f0f0f0>]
-[8<0f0f0f0ff0f0f0f0>]
-[8<1f0f0f0ff0f0f0f0>]
-[8<1f0f0f0ff1f0f0f0>]
-[8<1f0f0f8ff1f0f0f0>]
-[8<1f0f0f8ff1f0f0f8>]
-[8<9f0f0f8ff1f0f0f8>]
-[8<9f0f0f8ff9f0f0f8>]
-[8<9f0f0f9ff9f0f0f8>]
-[8<9f0f0f9ff9f0f0f9>]
-[8<9f8f0f9ff9f0f0f9>]
-[8<9f8f0f9ff9f8f0f9>]
-[8<9f8f1f9ff9f8f0f9>]
-[8<9f8f1f9ff9f8f1f9>]
-[8<bf8f1f9ff9f8f1f9>]
-[8<bf8f1f9ffbf8f1f9>]
-[8<bf8f1fdffbf8f1f9>]
-[8<bf8f1fdffbf8f1fd>]
-[8<ff8f1fdffbf8f1fd>]
-[8<ff8f1fdffff8f1fd>]
-[8<ff8f1ffffff8f1fd>]
-[8<ff8f1ffffff8f1ff>]
-[8<ff9f1ffffff8f1ff>]
-[8<ff9f1ffffff9f1ff>]
-[8<ff9f9ffffff9f1ff>]
-[8<ff9f9ffffff9f9ff>]
-[8<ffbf9ffffff9f9ff>]
-[8<ffbf9ffffffbf9ff>]
-[8<ffbfdffffffbf9ff>]
-[8<ffbfdffffffbfdff>]
-[8<ffffdffffffbfdff>]
-[8<ffffdffffffffdff>]
-[8<fffffffffffffdff>]
-[8<ffffffffffffffff>]]
-[%mg
-[8<8000000000000000>]
-[8<0822080080228000>]
-[8<0204081020408001>]
-[8<40e0400000000000>]
-[8<66999966>]
-[8<8001000010080000>]
-[8<81c36666c3810000>]
-[8<f0e0c08000000000>]
-[16<07c00f801f003e007c00f800f001e003c007800f001f003e007c00f801f003e0>]
-[16<1f000f8007c003e001f000f8007c003e001f800fc007e003f001f8007c003e00>]
-[8<c3c300000000c3c3>]
-[16<0040008001000200040008001000200040008000000100020004000800100020>]
-[16<0040002000100008000400020001800040002000100008000400020001000080>]
-[16<1fc03fe07df0f8f8f07de03fc01f800fc01fe03ff07df8f87df03fe01fc00f80>]
-[8<80>]
-[8<8040201000000000>]
-[8<84cc000048cc0000>]
-[8<9900009900000000>]
-[8<08040201804020100800020180002010>]
-[8<2418814242811824>]
-[8<66999966>]
-[8<8000000008000000>]
-[8<70f8d8f870000000>]
-[8<0814224180402010>]
-[8<aa00440a11a04400>]
-[8<018245aa45820100>]
-[8<221c224180808041>]
-[8<88000000>]
-[8<0855800080550800>]
-[8<2844004482440044>]
-[8<0810204080412214>]
-[8<00>]]]def
-/Dfill{
- transform /maxy exch def /maxx exch def
- transform /miny exch def /minx exch def
- minx maxx gt{/minx maxx /maxx minx def def}if
- miny maxy gt{/miny maxy /maxy miny def def}if
- Dpatterns Dstipple 1 sub get exch 1 sub get
- aload pop /stip exch def /stipw exch def /stiph 128 def
- /imatrix[stipw 0 0 stiph 0 0]def
- /tmatrix[stipw 0 0 stiph 0 0]def
- /minx minx cvi stiph idiv stiph mul def
- /miny miny cvi stipw idiv stipw mul def
- gsave eoclip 0 setgray
- miny stiph maxy{
- tmatrix exch 5 exch put
- minx stipw maxx{
- tmatrix exch 4 exch put tmatrix setmatrix
- stipw stiph true imatrix {stip} imagemask
- }for
- }for
- grestore
-}def
-/Dp{Dfill Dstroke}def
-/DP{Dfill currentpoint newpath moveto}def
-end
-
-/ditstart{$DITroff begin
- /nfonts 60 def % NFONTS makedev/ditroff dependent!
- /fonts[nfonts{0}repeat]def
- /fontnames[nfonts{()}repeat]def
-/docsave save def
-}def
-
-% character outcalls
-/oc{
- /pswid exch def /cc exch def /name exch def
- /ditwid pswid fontsize mul resolution mul 72000 div def
- /ditsiz fontsize resolution mul 72 div def
- ocprocs name known{ocprocs name get exec}{name cb}ifelse
-}def
-/fractm [.65 0 0 .6 0 0] def
-/fraction{
- /fden exch def /fnum exch def gsave /cf currentfont def
- cf fractm makefont setfont 0 .3 dm 2 copy neg rmoveto
- fnum show rmoveto currentfont cf setfont(\244)show setfont fden show
- grestore ditwid 0 rmoveto
-}def
-/oce{grestore ditwid 0 rmoveto}def
-/dm{ditsiz mul}def
-/ocprocs 50 dict def ocprocs begin
-(14){(1)(4)fraction}def
-(12){(1)(2)fraction}def
-(34){(3)(4)fraction}def
-(13){(1)(3)fraction}def
-(23){(2)(3)fraction}def
-(18){(1)(8)fraction}def
-(38){(3)(8)fraction}def
-(58){(5)(8)fraction}def
-(78){(7)(8)fraction}def
-(sr){gsave 0 .06 dm rmoveto(\326)show oce}def
-(is){gsave 0 .15 dm rmoveto(\362)show oce}def
-(->){gsave 0 .02 dm rmoveto(\256)show oce}def
-(<-){gsave 0 .02 dm rmoveto(\254)show oce}def
-(==){gsave 0 .05 dm rmoveto(\272)show oce}def
-(uc){gsave currentpoint 400 .009 dm mul add translate
- 8 -8 scale ucseal oce}def
-end
-
-% an attempt at a PostScript FONT to implement ditroff special chars
-% this will enable us to
-% cache the little buggers
-% generate faster, more compact PS out of psdit
-% confuse everyone (including myself)!
-50 dict dup begin
-/FontType 3 def
-/FontName /DIThacks def
-/FontMatrix [.001 0 0 .001 0 0] def
-/FontBBox [-260 -260 900 900] def% a lie but ...
-/Encoding 256 array def
-0 1 255{Encoding exch /.notdef put}for
-Encoding
- dup 8#040/space put %space
- dup 8#110/rc put %right ceil
- dup 8#111/lt put %left top curl
- dup 8#112/bv put %bold vert
- dup 8#113/lk put %left mid curl
- dup 8#114/lb put %left bot curl
- dup 8#115/rt put %right top curl
- dup 8#116/rk put %right mid curl
- dup 8#117/rb put %right bot curl
- dup 8#120/rf put %right floor
- dup 8#121/lf put %left floor
- dup 8#122/lc put %left ceil
- dup 8#140/sq put %square
- dup 8#141/bx put %box
- dup 8#142/ci put %circle
- dup 8#143/br put %box rule
- dup 8#144/rn put %root extender
- dup 8#145/vr put %vertical rule
- dup 8#146/ob put %outline bullet
- dup 8#147/bu put %bullet
- dup 8#150/ru put %rule
- dup 8#151/ul put %underline
- pop
-/DITfd 100 dict def
-/BuildChar{0 begin
- /cc exch def /fd exch def
- /charname fd /Encoding get cc get def
- /charwid fd /Metrics get charname get def
- /charproc fd /CharProcs get charname get def
- charwid 0 fd /FontBBox get aload pop setcachedevice
- 2 setlinejoin 40 setlinewidth
- newpath 0 0 moveto gsave charproc grestore
- end}def
-/BuildChar load 0 DITfd put
-/CharProcs 50 dict def
-CharProcs begin
-/space{}def
-/.notdef{}def
-/ru{500 0 rls}def
-/rn{0 840 moveto 500 0 rls}def
-/vr{0 800 moveto 0 -770 rls}def
-/bv{0 800 moveto 0 -1000 rls}def
-/br{0 840 moveto 0 -1000 rls}def
-/ul{0 -140 moveto 500 0 rls}def
-/ob{200 250 rmoveto currentpoint newpath 200 0 360 arc closepath stroke}def
-/bu{200 250 rmoveto currentpoint newpath 200 0 360 arc closepath fill}def
-/sq{80 0 rmoveto currentpoint dround newpath moveto
- 640 0 rlineto 0 640 rlineto -640 0 rlineto closepath stroke}def
-/bx{80 0 rmoveto currentpoint dround newpath moveto
- 640 0 rlineto 0 640 rlineto -640 0 rlineto closepath fill}def
-/ci{500 360 rmoveto currentpoint newpath 333 0 360 arc
- 50 setlinewidth stroke}def
-
-/lt{0 -200 moveto 0 550 rlineto currx 800 2cx s4 add exch s4 a4p stroke}def
-/lb{0 800 moveto 0 -550 rlineto currx -200 2cx s4 add exch s4 a4p stroke}def
-/rt{0 -200 moveto 0 550 rlineto currx 800 2cx s4 sub exch s4 a4p stroke}def
-/rb{0 800 moveto 0 -500 rlineto currx -200 2cx s4 sub exch s4 a4p stroke}def
-/lk{0 800 moveto 0 300 -300 300 s4 arcto pop pop 1000 sub
- 0 300 4 2 roll s4 a4p 0 -200 lineto stroke}def
-/rk{0 800 moveto 0 300 s2 300 s4 arcto pop pop 1000 sub
- 0 300 4 2 roll s4 a4p 0 -200 lineto stroke}def
-/lf{0 800 moveto 0 -1000 rlineto s4 0 rls}def
-/rf{0 800 moveto 0 -1000 rlineto s4 neg 0 rls}def
-/lc{0 -200 moveto 0 1000 rlineto s4 0 rls}def
-/rc{0 -200 moveto 0 1000 rlineto s4 neg 0 rls}def
-end
-
-/Metrics 50 dict def Metrics begin
-/.notdef 0 def
-/space 500 def
-/ru 500 def
-/br 0 def
-/lt 416 def
-/lb 416 def
-/rt 416 def
-/rb 416 def
-/lk 416 def
-/rk 416 def
-/rc 416 def
-/lc 416 def
-/rf 416 def
-/lf 416 def
-/bv 416 def
-/ob 350 def
-/bu 350 def
-/ci 750 def
-/bx 750 def
-/sq 750 def
-/rn 500 def
-/ul 500 def
-/vr 0 def
-end
-
-DITfd begin
-/s2 500 def /s4 250 def /s3 333 def
-/a4p{arcto pop pop pop pop}def
-/2cx{2 copy exch}def
-/rls{rlineto stroke}def
-/currx{currentpoint pop}def
-/dround{transform round exch round exch itransform} def
-end
-end
-/DIThacks exch definefont pop
-ditstart
-(psc)xT
-576 1 1 xr
-1(Times-Roman)xf 1 f
-2(Times-Italic)xf 2 f
-3(Times-Bold)xf 3 f
-4(Times-BoldItalic)xf 4 f
-5(Helvetica)xf 5 f
-6(Helvetica-Bold)xf 6 f
-7(Courier)xf 7 f
-8(Courier-Bold)xf 8 f
-9(Symbol)xf 9 f
-10(DIThacks)xf 10 f
-10 s
-1 f
-xi
-%%EndProlog
-
-%%Page: 1 1
-10 s 10 xH 0 xS 1 f
-3 f
-22 s
-1249 626(A)N
-1420(N)X
-1547(ew)X
-1796(H)X
-1933(ashing)X
-2467(P)X
-2574(ackage)X
-3136(for)X
-3405(U)X
-3532(N)X
-3659(IX)X
-2 f
-20 s
-3855 562(1)N
-1 f
-12 s
-1607 779(Margo)N
-1887(Seltzer)X
-9 f
-2179(-)X
-1 f
-2256(University)X
-2686(of)X
-2790(California,)X
-3229(Berkeley)X
-2015 875(Ozan)N
-2242(Yigit)X
-9 f
-2464(-)X
-1 f
-2541(York)X
-2762(University)X
-3 f
-2331 1086(ABSTRACT)N
-1 f
-10 s
-1152 1222(UNIX)N
-1385(support)X
-1657(of)X
-1756(disk)X
-1921(oriented)X
-2216(hashing)X
-2497(was)X
-2654(originally)X
-2997(provided)X
-3314(by)X
-2 f
-3426(dbm)X
-1 f
-3595([ATT79])X
-3916(and)X
-1152 1310(subsequently)N
-1595(improved)X
-1927(upon)X
-2112(in)X
-2 f
-2199(ndbm)X
-1 f
-2402([BSD86].)X
-2735(In)X
-2826(AT&T)X
-3068(System)X
-3327(V,)X
-3429(in-memory)X
-3809(hashed)X
-1152 1398(storage)N
-1420(and)X
-1572(access)X
-1814(support)X
-2090(was)X
-2251(added)X
-2479(in)X
-2577(the)X
-2 f
-2711(hsearch)X
-1 f
-3000(library)X
-3249(routines)X
-3542([ATT85].)X
-3907(The)X
-1152 1486(result)N
-1367(is)X
-1457(a)X
-1530(system)X
-1789(with)X
-1968(two)X
-2125(incompatible)X
-2580(hashing)X
-2865(schemes,)X
-3193(each)X
-3377(with)X
-3555(its)X
-3666(own)X
-3840(set)X
-3965(of)X
-1152 1574(shortcomings.)N
-1152 1688(This)N
-1316(paper)X
-1517(presents)X
-1802(the)X
-1922(design)X
-2152(and)X
-2289(performance)X
-2717(characteristics)X
-3198(of)X
-3286(a)X
-3343(new)X
-3498(hashing)X
-3768(package)X
-1152 1776(providing)N
-1483(a)X
-1539(superset)X
-1822(of)X
-1909(the)X
-2027(functionality)X
-2456(provided)X
-2761(by)X
-2 f
-2861(dbm)X
-1 f
-3019(and)X
-2 f
-3155(hsearch)X
-1 f
-3409(.)X
-3469(The)X
-3614(new)X
-3768(package)X
-1152 1864(uses)N
-1322(linear)X
-1537(hashing)X
-1818(to)X
-1912(provide)X
-2189(ef\256cient)X
-2484(support)X
-2755(of)X
-2853(both)X
-3026(memory)X
-3324(based)X
-3538(and)X
-3685(disk)X
-3849(based)X
-1152 1952(hash)N
-1319(tables)X
-1526(with)X
-1688(performance)X
-2115(superior)X
-2398(to)X
-2480(both)X
-2 f
-2642(dbm)X
-1 f
-2800(and)X
-2 f
-2936(hsearch)X
-1 f
-3210(under)X
-3413(most)X
-3588(conditions.)X
-3 f
-1380 2128(Introduction)N
-1 f
-892 2260(Current)N
-1196(UNIX)X
-1456(systems)X
-1768(offer)X
-1984(two)X
-2163(forms)X
-2409(of)X
-720 2348(hashed)N
-973(data)X
-1137(access.)X
-2 f
-1413(Dbm)X
-1 f
-1599(and)X
-1745(its)X
-1850(derivatives)X
-2231(provide)X
-720 2436(keyed)N
-939(access)X
-1171(to)X
-1259(disk)X
-1418(resident)X
-1698(data)X
-1858(while)X
-2 f
-2062(hsearch)X
-1 f
-2342(pro-)X
-720 2524(vides)N
-929(access)X
-1175(for)X
-1309(memory)X
-1616(resident)X
-1910(data.)X
-2124(These)X
-2356(two)X
-720 2612(access)N
-979(methods)X
-1302(are)X
-1453(incompatible)X
-1923(in)X
-2037(that)X
-2209(memory)X
-720 2700(resident)N
-1011(hash)X
-1195(tables)X
-1419(may)X
-1593(not)X
-1731(be)X
-1843(stored)X
-2075(on)X
-2191(disk)X
-2360(and)X
-720 2788(disk)N
-884(resident)X
-1169(tables)X
-1387(cannot)X
-1632(be)X
-1739(read)X
-1909(into)X
-2063(memory)X
-2360(and)X
-720 2876(accessed)N
-1022(using)X
-1215(the)X
-1333(in-memory)X
-1709(routines.)X
-2 f
-892 2990(Dbm)N
-1 f
-1091(has)X
-1241(several)X
-1512(shortcomings.)X
-2026(Since)X
-2247(data)X
-2423(is)X
-720 3078(assumed)N
-1032(to)X
-1130(be)X
-1242(disk)X
-1411(resident,)X
-1721(each)X
-1905(access)X
-2146(requires)X
-2440(a)X
-720 3166(system)N
-963(call,)X
-1120(and)X
-1257(almost)X
-1491(certainly,)X
-1813(a)X
-1869(disk)X
-2022(operation.)X
-2365(For)X
-720 3254(extremely)N
-1072(large)X
-1264(databases,)X
-1623(where)X
-1851(caching)X
-2131(is)X
-2214(unlikely)X
-720 3342(to)N
-810(be)X
-914(effective,)X
-1244(this)X
-1386(is)X
-1466(acceptable,)X
-1853(however,)X
-2177(when)X
-2378(the)X
-720 3430(database)N
-1022(is)X
-1100(small)X
-1298(\(i.e.)X
-1447(the)X
-1569(password)X
-1896(\256le\),)X
-2069(performance)X
-720 3518(improvements)N
-1204(can)X
-1342(be)X
-1443(obtained)X
-1744(through)X
-2018(caching)X
-2293(pages)X
-720 3606(of)N
-818(the)X
-947(database)X
-1255(in)X
-1348(memory.)X
-1685(In)X
-1782(addition,)X
-2 f
-2094(dbm)X
-1 f
-2262(cannot)X
-720 3694(store)N
-902(data)X
-1062(items)X
-1261(whose)X
-1492(total)X
-1660(key)X
-1802(and)X
-1943(data)X
-2102(size)X
-2252(exceed)X
-720 3782(the)N
-850(page)X
-1034(size)X
-1191(of)X
-1290(the)X
-1420(hash)X
-1599(table.)X
-1827(Similarly,)X
-2176(if)X
-2257(two)X
-2409(or)X
-720 3870(more)N
-907(keys)X
-1076(produce)X
-1357(the)X
-1477(same)X
-1664(hash)X
-1833(value)X
-2029(and)X
-2166(their)X
-2334(total)X
-720 3958(size)N
-876(exceeds)X
-1162(the)X
-1291(page)X
-1474(size,)X
-1650(the)X
-1779(table)X
-1966(cannot)X
-2210(store)X
-2396(all)X
-720 4046(the)N
-838(colliding)X
-1142(keys.)X
-892 4160(The)N
-1050(in-memory)X
-2 f
-1439(hsearch)X
-1 f
-1725(routines)X
-2015(have)X
-2199(different)X
-720 4248(shortcomings.)N
-1219(First,)X
-1413(the)X
-1539(notion)X
-1771(of)X
-1865(a)X
-1928(single)X
-2146(hash)X
-2320(table)X
-720 4336(is)N
-807(embedded)X
-1171(in)X
-1266(the)X
-1397(interface,)X
-1732(preventing)X
-2108(an)X
-2217(applica-)X
-720 4424(tion)N
-902(from)X
-1116(accessing)X
-1482(multiple)X
-1806(tables)X
-2050(concurrently.)X
-720 4512(Secondly,)N
-1063(the)X
-1186(routine)X
-1438(to)X
-1525(create)X
-1743(a)X
-1804(hash)X
-1976(table)X
-2157(requires)X
-2440(a)X
-720 4600(parameter)N
-1066(which)X
-1286(declares)X
-1573(the)X
-1694(size)X
-1842(of)X
-1932(the)X
-2053(hash)X
-2223(table.)X
-2422(If)X
-720 4688(this)N
-856(size)X
-1001(is)X
-1074(set)X
-1183(too)X
-1305(low,)X
-1465(performance)X
-1892(degradation)X
-2291(or)X
-2378(the)X
-720 4776(inability)N
-1008(to)X
-1092(add)X
-1230(items)X
-1425(to)X
-1509(the)X
-1628(table)X
-1805(may)X
-1964(result.)X
-2223(In)X
-2311(addi-)X
-720 4864(tion,)N
-2 f
-910(hsearch)X
-1 f
-1210(requires)X
-1515(that)X
-1681(the)X
-1825(application)X
-2226(allocate)X
-720 4952(memory)N
-1037(for)X
-1181(the)X
-1329(key)X
-1495(and)X
-1661(data)X
-1845(items.)X
-2108(Lastly,)X
-2378(the)X
-2 f
-720 5040(hsearch)N
-1 f
-1013(routines)X
-1310(provide)X
-1594(no)X
-1713(interface)X
-2034(to)X
-2135(store)X
-2329(hash)X
-720 5128(tables)N
-927(on)X
-1027(disk.)X
-16 s
-720 5593 MXY
-864 0 Dl
-2 f
-8 s
-760 5648(1)N
-1 f
-9 s
-5673(UNIX)Y
-990(is)X
-1056(a)X
-1106(registered)X
-1408(trademark)X
-1718(of)X
-1796(AT&T.)X
-10 s
-2878 2128(The)N
-3032(goal)X
-3199(of)X
-3295(our)X
-3431(work)X
-3625(was)X
-3779(to)X
-3870(design)X
-4108(and)X
-4253(imple-)X
-2706 2216(ment)N
-2900(a)X
-2970(new)X
-3138(package)X
-3436(that)X
-3590(provides)X
-3899(a)X
-3968(superset)X
-4264(of)X
-4364(the)X
-2706 2304(functionality)N
-3144(of)X
-3240(both)X
-2 f
-3411(dbm)X
-1 f
-3578(and)X
-2 f
-3723(hsearch)X
-1 f
-3977(.)X
-4045(The)X
-4198(package)X
-2706 2392(had)N
-2871(to)X
-2982(overcome)X
-3348(the)X
-3495(interface)X
-3826(shortcomings)X
-4306(cited)X
-2706 2480(above)N
-2930(and)X
-3078(its)X
-3185(implementation)X
-3719(had)X
-3867(to)X
-3961(provide)X
-4238(perfor-)X
-2706 2568(mance)N
-2942(equal)X
-3142(or)X
-3235(superior)X
-3524(to)X
-3612(that)X
-3758(of)X
-3851(the)X
-3975(existing)X
-4253(imple-)X
-2706 2656(mentations.)N
-3152(In)X
-3274(order)X
-3498(to)X
-3614(provide)X
-3913(a)X
-4003(compact)X
-4329(disk)X
-2706 2744(representation,)N
-3224(graceful)X
-3531(table)X
-3729(growth,)X
-4018(and)X
-4176(expected)X
-2706 2832(constant)N
-3033(time)X
-3234(performance,)X
-3720(we)X
-3873(selected)X
-4191(Litwin's)X
-2706 2920(linear)N
-2923(hashing)X
-3206(algorithm)X
-3551([LAR88,)X
-3872(LIT80].)X
-4178(We)X
-4324(then)X
-2706 3008(enhanced)N
-3037(the)X
-3161(algorithm)X
-3498(to)X
-3586(handle)X
-3826(page)X
-4004(over\257ows)X
-4346(and)X
-2706 3096(large)N
-2900(key)X
-3049(handling)X
-3362(with)X
-3537(a)X
-3606(single)X
-3830(mechanism,)X
-4248(named)X
-2706 3184(buddy-in-waiting.)N
-3 f
-2975 3338(Existing)N
-3274(UNIX)X
-3499(Hashing)X
-3802(Techniques)X
-1 f
-2878 3470(Over)N
-3076(the)X
-3210(last)X
-3357(decade,)X
-3637(several)X
-3901(dynamic)X
-4213(hashing)X
-2706 3558(schemes)N
-3000(have)X
-3174(been)X
-3348(developed)X
-3700(for)X
-3816(the)X
-3936(UNIX)X
-4159(timeshar-)X
-2706 3646(ing)N
-2856(system,)X
-3146(starting)X
-3433(with)X
-3622(the)X
-3767(inclusion)X
-4107(of)X
-2 f
-4221(dbm)X
-1 f
-4359(,)X
-4426(a)X
-2706 3734(minimal)N
-3008(database)X
-3321(library)X
-3571(written)X
-3834(by)X
-3950(Ken)X
-4120(Thompson)X
-2706 3822([THOM90],)N
-3141(in)X
-3248(the)X
-3391(Seventh)X
-3694(Edition)X
-3974(UNIX)X
-4220(system.)X
-2706 3910(Since)N
-2916(then,)X
-3106(an)X
-3214(extended)X
-3536(version)X
-3804(of)X
-3903(the)X
-4032(same)X
-4228(library,)X
-2 f
-2706 3998(ndbm)N
-1 f
-2884(,)X
-2933(and)X
-3078(a)X
-3142(public-domain)X
-3637(clone)X
-3839(of)X
-3934(the)X
-4060(latter,)X
-2 f
-4273(sdbm)X
-1 f
-4442(,)X
-2706 4086(have)N
-2902(been)X
-3098(developed.)X
-3491(Another)X
-3797 0.1645(interface-compatible)AX
-2706 4174(library)N
-2 f
-2950(gdbm)X
-1 f
-3128(,)X
-3178(was)X
-3333(recently)X
-3622(made)X
-3826(available)X
-4145(as)X
-4241(part)X
-4395(of)X
-2706 4262(the)N
-2829(Free)X
-2997(Software)X
-3312(Foundation's)X
-3759(\(FSF\))X
-3970(software)X
-4271(distri-)X
-2706 4350(bution.)N
-2878 4464(All)N
-3017(of)X
-3121(these)X
-3323(implementations)X
-3893(are)X
-4029(based)X
-4248(on)X
-4364(the)X
-2706 4552(idea)N
-2871(of)X
-2969(revealing)X
-3299(just)X
-3445(enough)X
-3711(bits)X
-3856(of)X
-3953(a)X
-4019(hash)X
-4196(value)X
-4400(to)X
-2706 4640(locate)N
-2920(a)X
-2978(page)X
-3151(in)X
-3234(a)X
-3291(single)X
-3503(access.)X
-3770(While)X
-2 f
-3987(dbm/ndbm)X
-1 f
-4346(and)X
-2 f
-2706 4728(sdbm)N
-1 f
-2908(map)X
-3079(the)X
-3210(hash)X
-3390(value)X
-3597(directly)X
-3874(to)X
-3968(a)X
-4036(disk)X
-4201(address,)X
-2 f
-2706 4816(gdbm)N
-1 f
-2921(uses)X
-3096(the)X
-3231(hash)X
-3414(value)X
-3624(to)X
-3722(index)X
-3936(into)X
-4096(a)X
-2 f
-4168(directory)X
-1 f
-2706 4904([ENB88])N
-3020(containing)X
-3378(disk)X
-3531(addresses.)X
-2878 5018(The)N
-2 f
-3033(hsearch)X
-1 f
-3317(routines)X
-3605(in)X
-3697(System)X
-3962(V)X
-4049(are)X
-4177(designed)X
-2706 5106(to)N
-2804(provide)X
-3085(memory-resident)X
-3669(hash)X
-3852(tables.)X
-4115(Since)X
-4328(data)X
-2706 5194(access)N
-2948(does)X
-3131(not)X
-3269(require)X
-3533(disk)X
-3702(access,)X
-3964(simple)X
-4213(hashing)X
-2706 5282(schemes)N
-3010(which)X
-3238(may)X
-3408(require)X
-3667(multiple)X
-3964(probes)X
-4209(into)X
-4364(the)X
-2706 5370(table)N
-2889(are)X
-3015(used.)X
-3209(A)X
-3294(more)X
-3486(interesting)X
-3851(version)X
-4114(of)X
-2 f
-4208(hsearch)X
-1 f
-2706 5458(is)N
-2784(a)X
-2845(public)X
-3070(domain)X
-3335(library,)X
-2 f
-3594(dynahash)X
-1 f
-3901(,)X
-3945(that)X
-4089(implements)X
-2706 5546(Larson's)N
-3036(in-memory)X
-3440(adaptation)X
-3822([LAR88])X
-4164(of)X
-4279(linear)X
-2706 5634(hashing)N
-2975([LIT80].)X
-3 f
-720 5960(USENIX)N
-9 f
-1042(-)X
-3 f
-1106(Winter)X
-1371('91)X
-9 f
-1498(-)X
-3 f
-1562(Dallas,)X
-1815(TX)X
-1 f
-4424(1)X
-
-2 p
-%%Page: 2 2
-10 s 10 xH 0 xS 1 f
-3 f
-432 258(A)N
-510(New)X
-682(Hashing)X
-985(Package)X
-1290(for)X
-1413(UNIX)X
-3663(Seltzer)X
-3920(&)X
-4007(Yigit)X
-2 f
-1074 538(dbm)N
-1 f
-1232(and)X
-2 f
-1368(ndbm)X
-1 f
-604 670(The)N
-2 f
-760(dbm)X
-1 f
-928(and)X
-2 f
-1074(ndbm)X
-1 f
-1282(library)X
-1526(implementations)X
-2089(are)X
-432 758(based)N
-667(on)X
-799(the)X
-949(same)X
-1166(algorithm)X
-1529(by)X
-1661(Ken)X
-1846(Thompson)X
-432 846([THOM90,)N
-824(TOR88,)X
-1113(WAL84],)X
-1452(but)X
-1582(differ)X
-1789(in)X
-1879(their)X
-2054(pro-)X
-432 934(grammatic)N
-801(interfaces.)X
-1160(The)X
-1311(latter)X
-1502(is)X
-1581(a)X
-1643(modi\256ed)X
-1952(version)X
-432 1022(of)N
-533(the)X
-665(former)X
-918(which)X
-1148(adds)X
-1328(support)X
-1601(for)X
-1728(multiple)X
-2027(data-)X
-432 1110(bases)N
-634(to)X
-724(be)X
-828(open)X
-1011(concurrently.)X
-1484(The)X
-1636(discussion)X
-1996(of)X
-2090(the)X
-432 1198(algorithm)N
-774(that)X
-925(follows)X
-1196(is)X
-1280(applicable)X
-1640(to)X
-1732(both)X
-2 f
-1904(dbm)X
-1 f
-2072(and)X
-2 f
-432 1286(ndbm)N
-1 f
-610(.)X
-604 1400(The)N
-760(basic)X
-956(structure)X
-1268(of)X
-2 f
-1366(dbm)X
-1 f
-1535(calls)X
-1712(for)X
-1836(\256xed-sized)X
-432 1488(disk)N
-612(blocks)X
-868(\(buckets\))X
-1214(and)X
-1377(an)X
-2 f
-1499(access)X
-1 f
-1755(function)X
-2068(that)X
-432 1576(maps)N
-623(a)X
-681(key)X
-819(to)X
-902(a)X
-959(bucket.)X
-1234(The)X
-1380(interface)X
-1683(routines)X
-1962(use)X
-2090(the)X
-2 f
-432 1664(access)N
-1 f
-673(function)X
-970(to)X
-1062(obtain)X
-1292(the)X
-1420(appropriate)X
-1816(bucket)X
-2060(in)X
-2152(a)X
-432 1752(single)N
-643(disk)X
-796(access.)X
-604 1866(Within)N
-869(the)X
-2 f
-1010(access)X
-1 f
-1263(function,)X
-1593(a)X
-1672(bit-randomizing)X
-432 1954(hash)N
-610(function)X
-2 f
-8 s
-877 1929(2)N
-1 f
-10 s
-940 1954(is)N
-1024(used)X
-1202(to)X
-1294(convert)X
-1565(a)X
-1631(key)X
-1777(into)X
-1931(a)X
-1997(32-bit)X
-432 2042(hash)N
-605(value.)X
-825(Out)X
-971(of)X
-1064(these)X
-1254(32)X
-1359(bits,)X
-1519(only)X
-1686(as)X
-1778(many)X
-1981(bits)X
-2121(as)X
-432 2130(necessary)N
-773(are)X
-900(used)X
-1075(to)X
-1165(determine)X
-1514(the)X
-1639(particular)X
-1974(bucket)X
-432 2218(on)N
-533(which)X
-750(a)X
-807(key)X
-944(resides.)X
-1228(An)X
-1347(in-memory)X
-1724(bitmap)X
-1967(is)X
-2041(used)X
-432 2306(to)N
-533(determine)X
-893(how)X
-1070(many)X
-1287(bits)X
-1441(are)X
-1579(required.)X
-1905(Each)X
-2104(bit)X
-432 2394(indicates)N
-746(whether)X
-1033(its)X
-1136(associated)X
-1494(bucket)X
-1736(has)X
-1871(been)X
-2051(split)X
-432 2482(yet)N
-562(\(a)X
-657(0)X
-728(indicating)X
-1079(that)X
-1230(the)X
-1359(bucket)X
-1604(has)X
-1742(not)X
-1875(yet)X
-2004(split\).)X
-432 2570(The)N
-590(use)X
-730(of)X
-830(the)X
-961(hash)X
-1141(function)X
-1441(and)X
-1590(the)X
-1720(bitmap)X
-1974(is)X
-2059(best)X
-432 2658(described)N
-769(by)X
-878(stepping)X
-1177(through)X
-1454(database)X
-1759(creation)X
-2046(with)X
-432 2746(multiple)N
-718(invocations)X
-1107(of)X
-1194(a)X
-2 f
-1250(store)X
-1 f
-1430(operation.)X
-604 2860(Initially,)N
-906(the)X
-1033(hash)X
-1209(table)X
-1394(contains)X
-1690(a)X
-1755(single)X
-1974(bucket)X
-432 2948(\(bucket)N
-711(0\),)X
-836(the)X
-972(bit)X
-1094(map)X
-1270(contains)X
-1575(a)X
-1649(single)X
-1878(bit)X
-2000(\(bit)X
-2148(0)X
-432 3036(corresponding)N
-913(to)X
-997(bucket)X
-1233(0\),)X
-1342(and)X
-1480(0)X
-1542(bits)X
-1699(of)X
-1788(a)X
-1846(hash)X
-2014(value)X
-432 3124(are)N
-560(examined)X
-901(to)X
-992(determine)X
-1342(where)X
-1568(a)X
-1633(key)X
-1778(is)X
-1860(placed)X
-2099(\(in)X
-432 3212(bucket)N
-670(0\).)X
-801(When)X
-1017(bucket)X
-1255(0)X
-1319(is)X
-1396(full,)X
-1551(its)X
-1650(bit)X
-1758(in)X
-1844(the)X
-1966(bitmap)X
-432 3300(\(bit)N
-564(0\))X
-652(is)X
-726(set,)X
-856(and)X
-993(its)X
-1089(contents)X
-1377(are)X
-1497(split)X
-1655(between)X
-1943(buckets)X
-432 3388(0)N
-499(and)X
-641(1,)X
-727(by)X
-833(considering)X
-1233(the)X
-1357(0)X
-2 f
-7 s
-3356(th)Y
-10 s
-1 f
-1480 3388(bit)N
-1590(\(the)X
-1741(lowest)X
-1976(bit)X
-2086(not)X
-432 3476(previously)N
-800(examined\))X
-1169(of)X
-1266(the)X
-1393(hash)X
-1569(value)X
-1772(for)X
-1895(each)X
-2072(key)X
-432 3564(within)N
-668(the)X
-798(bucket.)X
-1064(Given)X
-1292(a)X
-1359(well-designed)X
-1840(hash)X
-2018(func-)X
-432 3652(tion,)N
-613(approximately)X
-1112(half)X
-1273(of)X
-1376(the)X
-1510(keys)X
-1693(will)X
-1853(have)X
-2041(hash)X
-432 3740(values)N
-666(with)X
-837(the)X
-964(0)X
-2 f
-7 s
-3708(th)Y
-10 s
-1 f
-1090 3740(bit)N
-1203(set.)X
-1341(All)X
-1471(such)X
-1646(keys)X
-1821(and)X
-1965(associ-)X
-432 3828(ated)N
-586(data)X
-740(are)X
-859(moved)X
-1097(to)X
-1179(bucket)X
-1413(1,)X
-1493(and)X
-1629(the)X
-1747(rest)X
-1883(remain)X
-2126(in)X
-432 3916(bucket)N
-666(0.)X
-604 4030(After)N
-804(this)X
-949(split,)X
-1135(the)X
-1262(\256le)X
-1393(now)X
-1560(contains)X
-1856(two)X
-2005(buck-)X
-432 4118(ets,)N
-562(and)X
-699(the)X
-818(bitmap)X
-1061(contains)X
-1349(three)X
-1530(bits:)X
-1687(the)X
-1805(0)X
-2 f
-7 s
-4086(th)Y
-10 s
-1 f
-1922 4118(bit)N
-2026(is)X
-2099(set)X
-432 4206(to)N
-525(indicate)X
-810(a)X
-876(bucket)X
-1120(0)X
-1190(split)X
-1357(when)X
-1561(no)X
-1671(bits)X
-1816(of)X
-1913(the)X
-2041(hash)X
-432 4294(value)N
-648(are)X
-789(considered,)X
-1199(and)X
-1357(two)X
-1519(more)X
-1726(unset)X
-1937(bits)X
-2094(for)X
-432 4382(buckets)N
-706(0)X
-775(and)X
-920(1.)X
-1029(The)X
-1183(placement)X
-1542(of)X
-1638(an)X
-1742(incoming)X
-2072(key)X
-432 4470(now)N
-604(requires)X
-897(examination)X
-1327(of)X
-1428(the)X
-1560(0)X
-2 f
-7 s
-4438(th)Y
-10 s
-1 f
-1691 4470(bit)N
-1809(of)X
-1910(the)X
-2041(hash)X
-432 4558(value,)N
-667(and)X
-824(the)X
-963(key)X
-1119(is)X
-1212(placed)X
-1462(either)X
-1685(in)X
-1787(bucket)X
-2041(0)X
-2121(or)X
-432 4646(bucket)N
-674(1.)X
-782(If)X
-864(either)X
-1075(bucket)X
-1317(0)X
-1385(or)X
-1480(bucket)X
-1722(1)X
-1790(\256lls)X
-1937(up,)X
-2064(it)X
-2135(is)X
-432 4734(split)N
-598(as)X
-693(before,)X
-947(its)X
-1050(bit)X
-1162(is)X
-1243(set)X
-1360(in)X
-1450(the)X
-1576(bitmap,)X
-1846(and)X
-1990(a)X
-2054(new)X
-432 4822(set)N
-541(of)X
-628(unset)X
-817(bits)X
-952(are)X
-1071(added)X
-1283(to)X
-1365(the)X
-1483(bitmap.)X
-604 4936(Each)N
-791(time)X
-959(we)X
-1079(consider)X
-1376(a)X
-1437(new)X
-1596(bit)X
-1705(\(bit)X
-1841(n\),)X
-1953(we)X
-2072(add)X
-432 5024(2)N
-2 f
-7 s
-4992(n)Y
-9 f
-509(+)X
-1 f
-540(1)X
-10 s
-595 5024(bits)N
-737(to)X
-826(the)X
-951(bitmap)X
-1199(and)X
-1341(obtain)X
-1567(2)X
-2 f
-7 s
-4992(n)Y
-9 f
-1644(+)X
-1 f
-1675(1)X
-10 s
-1729 5024(more)N
-1920(address-)X
-432 5112(able)N
-595(buckets)X
-869(in)X
-960(the)X
-1087(\256le.)X
-1258(As)X
-1376(a)X
-1441(result,)X
-1668(the)X
-1795(bitmap)X
-2045(con-)X
-432 5200(tains)N
-618(the)X
-751(previous)X
-1062(2)X
-2 f
-7 s
-5168(n)Y
-9 f
-1139(+)X
-1 f
-1170(1)X
-2 f
-10 s
-9 f
-5200(-)Y
-1 f
-1242(1)X
-1317(bits)X
-1467(\(1)X
-2 f
-9 f
-1534(+)X
-1 f
-1578(2)X
-2 f
-9 f
-(+)S
-1 f
-1662(4)X
-2 f
-9 f
-(+)S
-1 f
-1746(...)X
-2 f
-9 f
-(+)S
-1 f
-1850(2)X
-2 f
-7 s
-5168(n)Y
-10 s
-1 f
-1931 5200(\))N
-1992(which)X
-432 5288(trace)N
-649(the)X
-807(entire)X
-2 f
-1050(split)X
-1247(history)X
-1 f
-1529(of)X
-1656(the)X
-1813(addressable)X
-16 s
-432 5433 MXY
-864 0 Dl
-2 f
-8 s
-472 5488(2)N
-1 f
-9 s
-523 5513(This)N
-670(bit-randomizing)X
-1153(property)X
-1416(is)X
-1482(important)X
-1780(to)X
-1854(obtain)X
-2052(radi-)X
-432 5593(cally)N
-599(different)X
-874(hash)X
-1033(values)X
-1244(for)X
-1355(nearly)X
-1562(identical)X
-1836(keys,)X
-2012(which)X
-432 5673(in)N
-506(turn)X
-640(avoids)X
-846(clustering)X
-1148(of)X
-1226(such)X
-1376(keys)X
-1526(in)X
-1600(a)X
-1650(single)X
-1840(bucket.)X
-10 s
-2418 538(buckets.)N
-2590 652(Given)N
-2809(a)X
-2868(key)X
-3007(and)X
-3146(the)X
-3267(bitmap)X
-3512(created)X
-3768(by)X
-3871(this)X
-4009(algo-)X
-2418 740(rithm,)N
-2638(we)X
-2759(\256rst)X
-2910(examine)X
-3209(bit)X
-3320(0)X
-3386(of)X
-3479(the)X
-3603(bitmap)X
-3851(\(the)X
-4002(bit)X
-4112(to)X
-2418 828(consult)N
-2673(when)X
-2871(0)X
-2934(bits)X
-3072(of)X
-3162(the)X
-3283(hash)X
-3453(value)X
-3650(are)X
-3772(being)X
-3973(exam-)X
-2418 916(ined\).)N
-2631(If)X
-2713(it)X
-2785(is)X
-2866(set)X
-2982(\(indicating)X
-3356(that)X
-3503(the)X
-3628(bucket)X
-3869(split\),)X
-4080(we)X
-2418 1004(begin)N
-2617(considering)X
-3012(the)X
-3131(bits)X
-3267(of)X
-3355(the)X
-3473(32-bit)X
-3684(hash)X
-3851(value.)X
-4085(As)X
-2418 1092(bit)N
-2525(n)X
-2587(is)X
-2662(revealed,)X
-2977(a)X
-3035(mask)X
-3226(equal)X
-3422(to)X
-3506(2)X
-2 f
-7 s
-1060(n)Y
-9 f
-3583(+)X
-1 f
-3614(1)X
-2 f
-10 s
-9 f
-1092(-)Y
-1 f
-3686(1)X
-3748(will)X
-3894(yield)X
-4076(the)X
-2418 1180(current)N
-2675(bucket)X
-2918(address.)X
-3228(Adding)X
-3496(2)X
-2 f
-7 s
-1148(n)Y
-9 f
-3573(+)X
-1 f
-3604(1)X
-2 f
-10 s
-9 f
-1180(-)Y
-1 f
-3676(1)X
-3744(to)X
-3834(the)X
-3960(bucket)X
-2418 1268(address)N
-2701(identi\256es)X
-3035(which)X
-3272(bit)X
-3397(in)X
-3500(the)X
-3639(bitmap)X
-3902(must)X
-4098(be)X
-2418 1356(checked.)N
-2743(We)X
-2876(continue)X
-3173(revealing)X
-3493(bits)X
-3628(of)X
-3715(the)X
-3833(hash)X
-4000(value)X
-2418 1444(until)N
-2591(all)X
-2698(set)X
-2814(bits)X
-2955(in)X
-3043(the)X
-3167(bitmap)X
-3415(are)X
-3540(exhausted.)X
-3907(The)X
-4058(fol-)X
-2418 1532(lowing)N
-2682(algorithm,)X
-3055(a)X
-3133(simpli\256cation)X
-3614(of)X
-3723(the)X
-3863(algorithm)X
-2418 1620(due)N
-2565(to)X
-2658(Ken)X
-2823(Thompson)X
-3196([THOM90,)X
-3590(TOR88],)X
-3908(uses)X
-4076(the)X
-2418 1708(hash)N
-2625(value)X
-2839(and)X
-2995(the)X
-3133(bitmap)X
-3395(to)X
-3497(calculate)X
-3823(the)X
-3960(bucket)X
-2418 1796(address)N
-2679(as)X
-2766(discussed)X
-3093(above.)X
-0(Courier)xf 0 f
-1 f
-0 f
-8 s
-2418 2095(hash)N
-2608(=)X
-2684 -0.4038(calchash\(key\);)AX
-2418 2183(mask)N
-2608(=)X
-2684(0;)X
-2418 2271(while)N
-2646 -0.4018(\(isbitset\(\(hash)AX
-3254(&)X
-3330(mask\))X
-3558(+)X
-3634(mask\)\))X
-2706 2359(mask)N
-2896(=)X
-2972(\(mask)X
-3200(<<)X
-3314(1\))X
-3428(+)X
-3504(1;)X
-2418 2447(bucket)N
-2684(=)X
-2760(hash)X
-2950(&)X
-3026(mask;)X
-2 f
-10 s
-3211 2812(sdbm)N
-1 f
-2590 2944(The)N
-2 f
-2738(sdbm)X
-1 f
-2930(library)X
-3167(is)X
-3243(a)X
-3302(public-domain)X
-3791(clone)X
-3987(of)X
-4076(the)X
-2 f
-2418 3032(ndbm)N
-1 f
-2638(library,)X
-2914(developed)X
-3286(by)X
-3408(Ozan)X
-3620(Yigit)X
-3826(to)X
-3929(provide)X
-2 f
-2418 3120(ndbm)N
-1 f
-2596('s)X
-2692(functionality)X
-3139(under)X
-3359(some)X
-3565(versions)X
-3869(of)X
-3973(UNIX)X
-2418 3208(that)N
-2559(exclude)X
-2830(it)X
-2894(for)X
-3008(licensing)X
-3317(reasons)X
-3578([YIG89].)X
-3895(The)X
-4040(pro-)X
-2418 3296(grammer)N
-2735(interface,)X
-3064(and)X
-3207(the)X
-3332(basic)X
-3524(structure)X
-3832(of)X
-2 f
-3926(sdbm)X
-1 f
-4121(is)X
-2418 3384(identical)N
-2733(to)X
-2 f
-2834(ndbm)X
-1 f
-3051(but)X
-3192(internal)X
-3476(details)X
-3723(of)X
-3828(the)X
-2 f
-3964(access)X
-1 f
-2418 3472(function,)N
-2726(such)X
-2894(as)X
-2982(the)X
-3101(calculation)X
-3474(of)X
-3561(the)X
-3679(bucket)X
-3913(address,)X
-2418 3560(and)N
-2563(the)X
-2690(use)X
-2825(of)X
-2920(different)X
-3225(hash)X
-3400(functions)X
-3726(make)X
-3928(the)X
-4054(two)X
-2418 3648(incompatible)N
-2856(at)X
-2934(the)X
-3052(database)X
-3349(level.)X
-2590 3762(The)N
-2 f
-2740(sdbm)X
-1 f
-2934(library)X
-3173(is)X
-3251(based)X
-3458(on)X
-3562(a)X
-3622(simpli\256ed)X
-3965(imple-)X
-2418 3850(mentation)N
-2778(of)X
-2885(Larson's)X
-3206(1978)X
-2 f
-3406(dynamic)X
-3717(hashing)X
-1 f
-4009(algo-)X
-2418 3938(rithm)N
-2616(including)X
-2943(the)X
-2 f
-3066(re\256nements)X
-3461(and)X
-3605(variations)X
-1 f
-3953(of)X
-4044(sec-)X
-2418 4026(tion)N
-2562(5)X
-2622([LAR78].)X
-2956(Larson's)X
-3257(original)X
-3526(algorithm)X
-3857(calls)X
-4024(for)X
-4138(a)X
-2418 4114(forest)N
-2635(of)X
-2736(binary)X
-2975(hash)X
-3156(trees)X
-3341(that)X
-3494(are)X
-3626(accessed)X
-3941(by)X
-4054(two)X
-2418 4202(hash)N
-2586(functions.)X
-2925(The)X
-3071(\256rst)X
-3216(hash)X
-3384(function)X
-3672(selects)X
-3907(a)X
-3964(partic-)X
-2418 4290(ular)N
-2571(tree)X
-2720(within)X
-2952(the)X
-3078(forest.)X
-3309(The)X
-3462(second)X
-3713(hash)X
-3887(function,)X
-2418 4378(which)N
-2659(is)X
-2757(required)X
-3070(to)X
-3177(be)X
-3297(a)X
-3377(boolean)X
-3675(pseudo-random)X
-2418 4466(number)N
-2687(generator)X
-3015(that)X
-3159(is)X
-3236(seeded)X
-3479(by)X
-3583(the)X
-3705(key,)X
-3865(is)X
-3942(used)X
-4112(to)X
-2418 4554(traverse)N
-2733(the)X
-2890(tree)X
-3070(until)X
-3275(internal)X
-3579(\(split\))X
-3829(nodes)X
-4075(are)X
-2418 4642(exhausted)N
-2763(and)X
-2903(an)X
-3003(external)X
-3286(\(non-split\))X
-3648(node)X
-3827(is)X
-3903(reached.)X
-2418 4730(The)N
-2571(bucket)X
-2813(addresses)X
-3149(are)X
-3276(stored)X
-3500(directly)X
-3772(in)X
-3861(the)X
-3986(exter-)X
-2418 4818(nal)N
-2536(nodes.)X
-2590 4932(Larson's)N
-2903(re\256nements)X
-3309(are)X
-3440(based)X
-3655(on)X
-3767(the)X
-3897(observa-)X
-2418 5020(tion)N
-2570(that)X
-2718(the)X
-2844(nodes)X
-3059(can)X
-3199(be)X
-3303(represented)X
-3702(by)X
-3809(a)X
-3872(single)X
-4090(bit)X
-2418 5108(that)N
-2569(is)X
-2653(set)X
-2773(for)X
-2898(internal)X
-3174(nodes)X
-3392(and)X
-3539(not)X
-3672(set)X
-3791(for)X
-3915(external)X
-2418 5196(nodes,)N
-2652(resulting)X
-2959(in)X
-3048(a)X
-3111(radix)X
-3303(search)X
-3536(trie.)X
-3709(Figure)X
-3944(1)X
-4010(illus-)X
-2418 5284(trates)N
-2621(this.)X
-2804(Nodes)X
-3037(A)X
-3123(and)X
-3267(B)X
-3348(are)X
-3475(internal)X
-3748(\(split\))X
-3967(nodes,)X
-2418 5372(thus)N
-2573(having)X
-2813(no)X
-2915(bucket)X
-3151(addresses)X
-3480(associated)X
-3831(with)X
-3994(them.)X
-2418 5460(Instead,)N
-2693(the)X
-2814(external)X
-3096(nodes)X
-3306(\(C,)X
-3429(D,)X
-3530(and)X
-3669(E\))X
-3768(each)X
-3938(need)X
-4112(to)X
-2418 5548(refer)N
-2594(to)X
-2679(a)X
-2738(bucket)X
-2975(address.)X
-3279(These)X
-3494(bucket)X
-3731(addresses)X
-4062(can)X
-2418 5636(be)N
-2529(stored)X
-2760(in)X
-2857(the)X
-2990(trie)X
-3132(itself)X
-3327(where)X
-3559(the)X
-3691(subtries)X
-3974(would)X
-3 f
-432 5960(2)N
-2970(USENIX)X
-9 f
-3292(-)X
-3 f
-3356(Winter)X
-3621('91)X
-9 f
-3748(-)X
-3 f
-3812(Dallas,)X
-4065(TX)X
-
-3 p
-%%Page: 3 3
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-720 258(Seltzer)N
-977(&)X
-1064(Yigit)X
-3278(A)X
-3356(New)X
-3528(Hashing)X
-3831(Package)X
-4136(for)X
-4259(UNIX)X
-1 f
-720 538(live)N
-862(if)X
-933(they)X
-1092(existed)X
-1340([KNU68].)X
-1709(For)X
-1841(example,)X
-2154(if)X
-2224(nodes)X
-2432(F)X
-720 626(and)N
-858(G)X
-938(were)X
-1117(the)X
-1237(children)X
-1522(of)X
-1610(node)X
-1787(C,)X
-1881(the)X
-2000(bucket)X
-2235(address)X
-720 714(L00)N
-886(could)X
-1101(reside)X
-1330(in)X
-1429(the)X
-1563(bits)X
-1714(that)X
-1870(will)X
-2030(eventually)X
-2400(be)X
-720 802(used)N
-887(to)X
-969(store)X
-1145(nodes)X
-1352(F)X
-1416(and)X
-1552(G)X
-1630(and)X
-1766(all)X
-1866(their)X
-2033(children.)X
-10 f
-720 890 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-3 f
-1894 2247(L1)N
-784 1925(A)N
-1431(E)X
-1106 2247(D)N
-1428 1281(C)N
-1109 1603(B)N
-1884 1930(L01)N
-1879 1286(L00)N
-1221 1814(1)N
-903 2131(1)N
-1221 1402(0)N
-903 1714(0)N
-1 Dt
-1397 1821 MXY
--8 -32 Dl
--5 19 Dl
--20 6 Dl
-33 7 Dl
--187 -182 Dl
-1397 1322 MXY
--33 7 Dl
-20 6 Dl
-5 19 Dl
-8 -32 Dl
--187 182 Dl
-1069 1639 MXY
--32 7 Dl
-20 6 Dl
-5 19 Dl
-7 -32 Dl
--186 182 Dl
-1374 1891 MXY
-185 Dc
-1779 2133 MXY
-0 161 Dl
-322 0 Dl
-0 -161 Dl
--322 0 Dl
-1811 MY
-0 161 Dl
-322 0 Dl
-0 -161 Dl
--322 0 Dl
-1166 MY
-0 161 Dl
-322 0 Dl
-0 -161 Dl
--322 0 Dl
-1052 2213 MXY
-185 Dc
-1569 MY
-185 Dc
-720 1881 MXY
-185 Dc
-1779 2213 MXY
--28 -17 Dl
-10 17 Dl
--10 18 Dl
-28 -18 Dl
--543 0 Dl
-1769 1891 MXY
--28 -18 Dl
-10 18 Dl
--10 18 Dl
-28 -18 Dl
--201 0 Dl
-1364 1247 MXY
-185 Dc
-1769 MX
--28 -18 Dl
-10 18 Dl
--10 18 Dl
-28 -18 Dl
--201 0 Dl
-1064 2143 MXY
--7 -32 Dl
--5 19 Dl
--20 6 Dl
-32 7 Dl
--181 -181 Dl
-3 Dt
--1 Ds
-8 s
-720 2482(Figure)N
-925(1:)X
-1 f
-1002(Radix)X
-1179(search)X
-1365(trie)X
-1474(with)X
-1612(internal)X
-1831(nodes)X
-2004(A)X
-2074(and)X
-2189(B,)X
-2271(external)X
-720 2570(nodes)N
-891(C,)X
-972(D,)X
-1056(and)X
-1170(E,)X
-1247(and)X
-1361(bucket)X
-1553(addresses)X
-1819(stored)X
-1997(in)X
-2069(the)X
-2168(unused)X
-2370(por-)X
-720 2658(tion)N
-836(of)X
-905(the)X
-999(trie.)X
-10 s
-10 f
-720 2922 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-1 f
-892 3124(Further)N
-1153(simpli\256cations)X
-1647(of)X
-1738(the)X
-1860(above)X
-2076([YIG89])X
-2377(are)X
-720 3212(possible.)N
-1038(Using)X
-1265(a)X
-1337(single)X
-1564(radix)X
-1765(trie)X
-1908(to)X
-2006(avoid)X
-2219(the)X
-2352(\256rst)X
-720 3300(hash)N
-904(function,)X
-1227(replacing)X
-1562(the)X
-1696(pseudo-random)X
-2231(number)X
-720 3388(generator)N
-1052(with)X
-1222(a)X
-1286(well)X
-1452(designed,)X
-1785(bit-randomizing)X
-2329(hash)X
-720 3476(function,)N
-1053(and)X
-1215(using)X
-1434(the)X
-1578(portion)X
-1855(of)X
-1967(the)X
-2110(hash)X
-2302(value)X
-720 3564(exposed)N
-1021(during)X
-1268(the)X
-1404(trie)X
-1549(traversal)X
-1864(as)X
-1969(a)X
-2042(direct)X
-2262(bucket)X
-720 3652(address)N
-990(results)X
-1228(in)X
-1319(an)X
-2 f
-1424(access)X
-1 f
-1663(function)X
-1959(that)X
-2108(works)X
-2333(very)X
-720 3740(similar)N
-974(to)X
-1068(Thompson's)X
-1499(algorithm)X
-1841(above.)X
-2084(The)X
-2240(follow-)X
-720 3828(ing)N
-847(algorithm)X
-1183(uses)X
-1346(the)X
-1469(hash)X
-1641(value)X
-1840(to)X
-1927(traverse)X
-2206(a)X
-2266(linear-)X
-720 3916(ized)N
-874(radix)X
-1059(trie)X
-2 f
-8 s
-1166 3891(3)N
-1 f
-10 s
-1218 3916(starting)N
-1478(at)X
-1556(the)X
-1674(0)X
-2 f
-7 s
-3884(th)Y
-10 s
-1 f
-1791 3916(bit.)N
-0 f
-8 s
-720 4215(tbit)N
-910(=)X
-986(0;)X
-1296(/*)X
-1410(radix)X
-1638(trie)X
-1828(index)X
-2056(*/)X
-720 4303(hbit)N
-910(=)X
-986(0;)X
-1296(/*)X
-1410(hash)X
-1600(bit)X
-1752(index)X
-2056(*/)X
-720 4391(mask)N
-910(=)X
-986(0;)X
-720 4479(hash)N
-910(=)X
-986 -0.4038(calchash\(key\);)AX
-720 4655(for)N
-872(\(mask)X
-1100(=)X
-1176(0;)X
-910 4743 -0.4018(isbitset\(tbit\);)AN
-910 4831(mask)N
-1100(=)X
-1176(\(mask)X
-1404(<<)X
-1518(1\))X
-1632(+)X
-1708(1\))X
-1008 4919(if)N
-1122(\(hash)X
-1350(&)X
-1426(\(1)X
-1540(<<)X
-1654 -0.4219(hbit++\)\)\))AX
-1160 5007(/*)N
-1274(right)X
-1502(son)X
-1692(*/)X
-1160 5095(tbit)N
-1350(=)X
-1426(2)X
-1502(*)X
-1578(tbit)X
-1768(+)X
-1844(2;)X
-1008 5183(else)N
-1 f
-16 s
-720 5353 MXY
-864 0 Dl
-2 f
-8 s
-760 5408(3)N
-1 f
-9 s
-818 5433(A)N
-896(linearized)X
-1206(radix)X
-1380(trie)X
-1502(is)X
-1576(merely)X
-1802(an)X
-1895(array)X
-2068(representation)X
-720 5513(of)N
-800(the)X
-908(radix)X
-1076(search)X
-1280(trie)X
-1396(described)X
-1692(above.)X
-1920(The)X
-2052(children)X
-2308(of)X
-2388(the)X
-720 5593(node)N
-885(with)X
-1038(index)X
-1223(i)X
-1267(can)X
-1391(be)X
-1483(found)X
-1675(at)X
-1751(the)X
-1863(nodes)X
-2055(indexed)X
-2307(2*i+1)X
-720 5673(and)N
-842(2*i+2.)X
-0 f
-8 s
-3146 538(/*)N
-3260(left)X
-3450(son)X
-3678(*/)X
-3146 626(tbit)N
-3336(=)X
-3412(2)X
-3488(*)X
-3564(tbit)X
-3754(+)X
-3830(1;)X
-2706 802(bucket)N
-2972(=)X
-3048(hash)X
-3238(&)X
-3314(mask;)X
-2 f
-10 s
-3495 1167(gdbm)N
-1 f
-2878 1299(The)N
-3027(gdbm)X
-3233(\(GNU)X
-3458(data)X
-3616(base)X
-3783(manager\))X
-4111(library)X
-4349(is)X
-4426(a)X
-2706 1387(UNIX)N
-2933(database)X
-3236(manager)X
-3539(written)X
-3792(by)X
-3897(Philip)X
-4112(A.)X
-4215(Nelson,)X
-2706 1475(and)N
-2848(made)X
-3048(available)X
-3364(as)X
-3457(a)X
-3518(part)X
-3668(of)X
-3760(the)X
-3883(FSF)X
-4040(software)X
-4342(dis-)X
-2706 1563(tribution.)N
-3052(The)X
-3207(gdbm)X
-3419(library)X
-3663(provides)X
-3969(the)X
-4097(same)X
-4292(func-)X
-2706 1651(tionality)N
-3028(of)X
-3151(the)X
-2 f
-3304(dbm)X
-1 f
-3442(/)X
-2 f
-3464(ndbm)X
-1 f
-3697(libraries)X
-4015([NEL90])X
-4360(but)X
-2706 1739(attempts)N
-3018(to)X
-3121(avoid)X
-3340(some)X
-3550(of)X
-3658(their)X
-3846(shortcomings.)X
-4337(The)X
-2706 1827(gdbm)N
-2918(library)X
-3162(allows)X
-3401(for)X
-3525(arbitrary-length)X
-4059(data,)X
-4242(and)X
-4387(its)X
-2706 1915(database)N
-3027(is)X
-3124(a)X
-3203(singular,)X
-3524(non-sparse)X
-2 f
-8 s
-3872 1890(4)N
-1 f
-10 s
-3947 1915(\256le.)N
-4112(The)X
-4280(gdbm)X
-2706 2003(library)N
-2947(also)X
-3103(includes)X
-2 f
-3396(dbm)X
-1 f
-3560(and)X
-2 f
-3702(ndbm)X
-1 f
-3906(compatible)X
-4288(inter-)X
-2706 2091(faces.)N
-2878 2205(The)N
-3025(gdbm)X
-3229(library)X
-3465(is)X
-3540(based)X
-3745(on)X
-2 f
-3847(extensible)X
-4189(hashing)X
-1 f
-4442(,)X
-2706 2293(a)N
-2766(dynamic)X
-3066(hashing)X
-3339(algorithm)X
-3674(by)X
-3778(Fagin)X
-3984(et)X
-4066(al)X
-4148([FAG79].)X
-2706 2381(This)N
-2881(algorithm)X
-3225(differs)X
-3467(from)X
-3655(the)X
-3785(previously)X
-4155(discussed)X
-2706 2469(algorithms)N
-3069(in)X
-3152(that)X
-3293(it)X
-3358(uses)X
-3517(a)X
-2 f
-3574(directory)X
-1 f
-3889(that)X
-4030(is)X
-4103(a)X
-4159(collapsed)X
-2706 2557(representation)N
-3192([ENB88])X
-3517(of)X
-3615(the)X
-3744(radix)X
-3940(search)X
-4177(trie)X
-4315(used)X
-2706 2645(by)N
-2 f
-2806(sdbm)X
-1 f
-2975(.)X
-10 f
-2706 2733 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-3 f
-7 s
-3572 3761(L1)N
-1 Dt
-3485 3738 MXY
--20 -13 Dl
-7 13 Dl
--7 13 Dl
-20 -13 Dl
--400 0 Dl
-3180 3027 MXY
-136 Dc
-2706 3494 MXY
-136 Dc
-2950 3264 MXY
-136 Dc
-3738 MY
-136 Dc
-3485 2968 MXY
-0 118 Dl
-238 0 Dl
-0 -118 Dl
--238 0 Dl
-3442 MY
-0 119 Dl
-238 0 Dl
-0 -119 Dl
--238 0 Dl
-3679 MY
-0 119 Dl
-238 0 Dl
-0 -119 Dl
--238 0 Dl
-3187 3501 MXY
-136 Dc
-2963 3316 MXY
--24 5 Dl
-15 4 Dl
-4 15 Dl
-5 -24 Dl
--137 134 Dl
-3204 3083 MXY
--24 5 Dl
-15 4 Dl
-3 14 Dl
-6 -23 Dl
--137 133 Dl
-3204 3450 MXY
--6 -24 Dl
--3 14 Dl
--15 5 Dl
-24 5 Dl
--137 -134 Dl
-2842 3369(0)N
-3075 3139(0)N
-2842 3676(1)N
-3075 3443(1)N
-3562 3054(L00)N
-3565 3528(L01)N
-4197 2968 MXY
-0 118 Dl
-237 0 Dl
-0 -118 Dl
--237 0 Dl
-3205 MY
-0 119 Dl
-237 0 Dl
-0 -119 Dl
--237 0 Dl
-3561 MY
-0 118 Dl
-237 0 Dl
-0 -118 Dl
--237 0 Dl
-3960 2909 MXY
-0 237 Dl
-118 0 Dl
-0 -237 Dl
--118 0 Dl
-3146 MY
-0 237 Dl
-118 0 Dl
-0 -237 Dl
--118 0 Dl
-3383 MY
-0 237 Dl
-118 0 Dl
-0 -237 Dl
--118 0 Dl
-3620 MY
-0 237 Dl
-118 0 Dl
-0 -237 Dl
--118 0 Dl
-4197 3027 MXY
--21 -13 Dl
-8 13 Dl
--8 13 Dl
-21 -13 Dl
--119 0 Dl
-4197 3264 MXY
--21 -13 Dl
-8 13 Dl
--8 13 Dl
-21 -13 Dl
--119 0 Dl
-3501 MY
-59 0 Dl
-0 89 Dl
-4078 3738 MXY
-59 0 Dl
-0 -88 Dl
-4197 3590 MXY
--21 -13 Dl
-8 13 Dl
--8 13 Dl
-21 -13 Dl
--60 0 Dl
-4197 3650 MXY
--21 -13 Dl
-8 13 Dl
--8 13 Dl
-21 -13 Dl
--60 0 Dl
-3991 3050(00)N
-3991 3287(01)N
-3991 3524(10)N
-3991 3761(11)N
-4269 3050(L00)N
-4269 3287(L01)N
-4283 3643(L1)N
-3485 3501 MXY
--20 -13 Dl
-7 13 Dl
--7 13 Dl
-20 -13 Dl
--155 0 Dl
-3485 3027 MXY
--20 -13 Dl
-7 13 Dl
--7 13 Dl
-20 -13 Dl
--163 0 Dl
-2967 3687 MXY
--5 -24 Dl
--4 14 Dl
--15 4 Dl
-24 6 Dl
--141 -141 Dl
-3 Dt
--1 Ds
-8 s
-2706 4033(Figure)N
-2903(2:)X
-1 f
-2972(A)X
-3034(radix)X
-3181(search)X
-3359(trie)X
-3460(and)X
-3568(a)X
-3612(directory)X
-3858(representing)X
-4189(the)X
-4283(trie.)X
-10 s
-10 f
-2706 4209 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-1 f
-2878 4411(In)N
-2968(this)X
-3106(algorithm,)X
-3460(a)X
-3519(directory)X
-3832(consists)X
-4108(of)X
-4198(a)X
-4256(search)X
-2706 4499(trie)N
-2847(of)X
-2947(depth)X
-2 f
-3158(n)X
-1 f
-3211(,)X
-3264(containing)X
-3635(2)X
-2 f
-7 s
-4467(n)Y
-10 s
-1 f
-3749 4499(bucket)N
-3996(addresses)X
-4337(\(i.e.)X
-2706 4587(each)N
-2897(element)X
-3194(of)X
-3304(the)X
-3445(trie)X
-3594(is)X
-3689(a)X
-3767(bucket)X
-4023(address\).)X
-4373(To)X
-2706 4675(access)N
-2935(the)X
-3056(hash)X
-3226(table,)X
-3425(a)X
-3483(32-bit)X
-3696(hash)X
-3865(value)X
-4061(is)X
-4136(calculated)X
-2706 4763(and)N
-2 f
-2861(n)X
-1 f
-2953(bits)X
-3107(of)X
-3213(the)X
-3350(value)X
-3563(are)X
-3701(used)X
-3886(to)X
-3986(index)X
-4202(into)X
-4364(the)X
-2706 4851(directory)N
-3018(to)X
-3102(obtain)X
-3324(a)X
-3382(bucket)X
-3618(address.)X
-3921(It)X
-3992(is)X
-4067(important)X
-4400(to)X
-2706 4939(note)N
-2866(that)X
-3008(multiple)X
-3296(entries)X
-3532(of)X
-3620(this)X
-3756(directory)X
-4067(may)X
-4226(contain)X
-2706 5027(the)N
-2833(same)X
-3026(bucket)X
-3268(address)X
-3537(as)X
-3632(a)X
-3696(result)X
-3902(of)X
-3997(directory)X
-4315(dou-)X
-2706 5115(bling)N
-2903(during)X
-3145(bucket)X
-3392(splitting.)X
-3706(Figure)X
-3948(2)X
-4021(illustrates)X
-4364(the)X
-2706 5203(relationship)N
-3126(between)X
-3436(a)X
-3513(typical)X
-3772(\(skewed\))X
-4108(search)X
-4355(trie)X
-2706 5291(and)N
-2850(its)X
-2953(directory)X
-3271(representation.)X
-3774(The)X
-3927(formation)X
-4270(of)X
-4364(the)X
-2706 5379(directory)N
-3016(shown)X
-3245(in)X
-3327(the)X
-3445(\256gure)X
-3652(is)X
-3725(as)X
-3812(follows.)X
-16 s
-2706 5593 MXY
-864 0 Dl
-2 f
-8 s
-2746 5648(4)N
-1 f
-9 s
-2796 5673(It)N
-2858(does)X
-3008(not)X
-3118(contain)X
-3348(holes.)X
-3 f
-10 s
-720 5960(USENIX)N
-9 f
-1042(-)X
-3 f
-1106(Winter)X
-1371('91)X
-9 f
-1498(-)X
-3 f
-1562(Dallas,)X
-1815(TX)X
-4424(3)X
-
-4 p
-%%Page: 4 4
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-432 258(A)N
-510(New)X
-682(Hashing)X
-985(Package)X
-1290(for)X
-1413(UNIX)X
-3663(Seltzer)X
-3920(&)X
-4007(Yigit)X
-1 f
-604 538(Initially,)N
-937(there)X
-1158(is)X
-1271(one)X
-1446(slot)X
-1620(in)X
-1741(the)X
-1898(directory)X
-432 626(addressing)N
-802(a)X
-865(single)X
-1083(bucket.)X
-1364(The)X
-1515(depth)X
-1719(of)X
-1812(the)X
-1936(trie)X
-2069(is)X
-2148(0)X
-432 714(and)N
-577(0)X
-646(bits)X
-790(of)X
-886(each)X
-1063(hash)X
-1239(value)X
-1442(are)X
-1570(examined)X
-1910(to)X
-2000(deter-)X
-432 802(mine)N
-624(in)X
-718(which)X
-946(bucket)X
-1192(to)X
-1286(place)X
-1488(a)X
-1556(key;)X
-1726(all)X
-1837(keys)X
-2015(go)X
-2126(in)X
-432 890(bucket)N
-682(0.)X
-797(When)X
-1024(this)X
-1174(bucket)X
-1423(is)X
-1511(full,)X
-1677(its)X
-1787(contents)X
-2089(are)X
-432 978(divided)N
-698(between)X
-992(L0)X
-1107(and)X
-1249(L1)X
-1363(as)X
-1455(was)X
-1605(done)X
-1786(in)X
-1873(the)X
-1996(previ-)X
-432 1066(ously)N
-664(discussed)X
-1030(algorithms.)X
-1471(After)X
-1700(this)X
-1874(split,)X
-2090(the)X
-432 1154(address)N
-710(of)X
-814(the)X
-948(second)X
-1207(bucket)X
-1457(must)X
-1648(be)X
-1760(stored)X
-1992(in)X
-2090(the)X
-432 1242(directory.)N
-796(To)X
-939(accommodate)X
-1438(the)X
-1589(new)X
-1776(address,)X
-2090(the)X
-432 1330(directory)N
-752(is)X
-835(split)X
-2 f
-8 s
-972 1305(5)N
-1 f
-10 s
-1330(,)Y
-1054(by)X
-1163(doubling)X
-1476(it,)X
-1569(thus)X
-1731(increasing)X
-2090(the)X
-432 1418(depth)N
-630(of)X
-717(the)X
-835(directory)X
-1145(by)X
-1245(one.)X
-604 1532(After)N
-813(this)X
-967(split,)X
-1163(a)X
-1237(single)X
-1466(bit)X
-1588(of)X
-1693(the)X
-1829(hash)X
-2014(value)X
-432 1620(needs)N
-663(to)X
-773(be)X
-896(examined)X
-1255(to)X
-1364(decide)X
-1621(whether)X
-1927(the)X
-2072(key)X
-432 1708(belongs)N
-711(to)X
-803(L0)X
-922(or)X
-1019(L1.)X
-1158(Once)X
-1358(one)X
-1504(of)X
-1601(these)X
-1795(buckets)X
-2069(\256lls)X
-432 1796(\(L0)N
-578(for)X
-702(example\),)X
-1051(it)X
-1125(is)X
-1208(split)X
-1375(as)X
-1472(before,)X
-1728(and)X
-1873(the)X
-2000(direc-)X
-432 1884(tory)N
-585(is)X
-662(split)X
-823(again)X
-1021(to)X
-1107(make)X
-1305(room)X
-1498(for)X
-1615(the)X
-1736(address)X
-2000(of)X
-2090(the)X
-432 1972(third)N
-618(bucket.)X
-927(This)X
-1104(splitting)X
-1400(causes)X
-1645(the)X
-1778(addresses)X
-2121(of)X
-432 2060(the)N
-567(non-splitting)X
-1012(bucket)X
-1263(\(L1\))X
-1443(to)X
-1541(be)X
-1653(duplicated.)X
-2063(The)X
-432 2148(directory)N
-766(now)X
-948(has)X
-1099(four)X
-1277(entries,)X
-1555(a)X
-1635(depth)X
-1857(of)X
-1968(2,)X
-2072(and)X
-432 2236(indexes)N
-700(the)X
-821(buckets)X
-1089(L00,)X
-1261(L01)X
-1413(and)X
-1552(L1,)X
-1684(as)X
-1774(shown)X
-2006(in)X
-2090(the)X
-432 2324(Figure)N
-661(2.)X
-604 2438(The)N
-756(crucial)X
-1002(part)X
-1154(of)X
-1247(the)X
-1371(algorithm)X
-1708(is)X
-1787(the)X
-1911(observa-)X
-432 2526(tion)N
-580(that)X
-724(L1)X
-837(is)X
-914(addressed)X
-1255(twice)X
-1453(in)X
-1539(the)X
-1661(directory.)X
-1995(If)X
-2073(this)X
-432 2614(bucket)N
-679(were)X
-869(to)X
-964(split)X
-1134(now,)X
-1324(the)X
-1454(directory)X
-1776(already)X
-2045(con-)X
-432 2702(tains)N
-611(room)X
-808(to)X
-898(hold)X
-1067(the)X
-1192(address)X
-1460(of)X
-1554(the)X
-1679(new)X
-1840(bucket.)X
-2121(In)X
-432 2790(general,)N
-711(the)X
-831(relationship)X
-1231(between)X
-1521(the)X
-1641(directory)X
-1953(and)X
-2090(the)X
-432 2878(number)N
-704(of)X
-798(bucket)X
-1039(addresses)X
-1374(contained)X
-1713(therein)X
-1962(is)X
-2041(used)X
-432 2966(to)N
-517(decide)X
-750(when)X
-947(to)X
-1031(split)X
-1190(the)X
-1310(directory.)X
-1662(Each)X
-1845(bucket)X
-2081(has)X
-432 3054(a)N
-505(depth,)X
-740(\()X
-2 f
-767(n)X
-7 s
-3070(b)Y
-10 s
-1 f
-848 3054(\),)N
-932(associated)X
-1299(with)X
-1478(it)X
-1558(and)X
-1710(appears)X
-1992(in)X
-2090(the)X
-432 3142(directory)N
-744(exactly)X
-998(2)X
-2 f
-7 s
-3106(n)Y
-9 f
-1075(-)X
-2 f
-1106(n)X
-4 s
-3110(b)Y
-7 s
-1 f
-10 s
-1181 3142(times.)N
-1396(When)X
-1610(a)X
-1668(bucket)X
-1904(splits,)X
-2113(its)X
-432 3230(depth)N
-638(increases)X
-961(by)X
-1069(one.)X
-1253(The)X
-1406(directory)X
-1724(must)X
-1907(split)X
-2072(any)X
-432 3318(time)N
-602(a)X
-665(bucket's)X
-964(depth)X
-1169(exceeds)X
-1451(the)X
-1576(depth)X
-1781(of)X
-1875(the)X
-2000(direc-)X
-432 3406(tory.)N
-630(The)X
-784(following)X
-1123(code)X
-1303(fragment)X
-1621(helps)X
-1818(to)X
-1908(illustrate)X
-432 3494(the)N
-554(extendible)X
-912(hashing)X
-1185(algorithm)X
-1520([FAG79])X
-1838(for)X
-1955(access-)X
-432 3582(ing)N
-554(individual)X
-898(buckets)X
-1163(and)X
-1299(maintaining)X
-1701(the)X
-1819(directory.)X
-0 f
-8 s
-432 3881(hash)N
-622(=)X
-698 -0.4038(calchash\(key\);)AX
-432 3969(mask)N
-622(=)X
-698 -0.4018(maskvec[depth];)AX
-432 4145(bucket)N
-698(=)X
-774 -0.4038(directory[hash)AX
-1344(&)X
-1420(mask];)X
-432 4321(/*)N
-546(Key)X
-698 -0.4219(Insertion)AX
-1078(*/)X
-432 4409(if)N
-546 -0.4038(\(store\(bucket,)AX
-1116(key,)X
-1306(data\))X
-1534(==)X
-1648(FAIL\))X
-1876({)X
-720 4497(newbl)N
-948(=)X
-1024 -0.4167(getpage\(\);)AX
-720 4585 -0.4000(bucket->depth++;)AN
-720 4673 -0.4091(newbl->depth)AN
-1214(=)X
-1290 -0.4038(bucket->depth;)AX
-720 4761(if)N
-834 -0.4038(\(bucket->depth)AX
-1404(>)X
-1480(depth\))X
-1746({)X
-1008 4849(/*)N
-1122(double)X
-1388 -0.4219(directory)AX
-1768(*/)X
-1008 4937(depth++;)N
-1 f
-16 s
-432 5033 MXY
-864 0 Dl
-2 f
-8 s
-472 5088(5)N
-1 f
-9 s
-534 5113(This)N
-692(decision)X
-962(to)X
-1048(split)X
-1202(the)X
-1319(directory)X
-1608(is)X
-1685(based)X
-1878(on)X
-1979(a)X
-2040(com-)X
-432 5193(parison)N
-666(of)X
-748(the)X
-858(depth)X
-1040(of)X
-1121(the)X
-1230(page)X
-1387(being)X
-1568(split)X
-1713(and)X
-1838(the)X
-1947(depth)X
-2128(of)X
-432 5273(the)N
-543(trie.)X
-698(In)X
-781(Figure)X
-992(2,)X
-1069(the)X
-1180(depths)X
-1390(of)X
-1472(both)X
-1622(L00)X
-1760(and)X
-1886(L01)X
-2024(are)X
-2134(2,)X
-432 5353(whereas)N
-689(the)X
-798(depth)X
-979(of)X
-1060(L1)X
-1161(is)X
-1230(1.)X
-1323(Therefore,)X
-1646(if)X
-1710(L1)X
-1810(were)X
-1970(to)X
-2046(split,)X
-432 5433(the)N
-543(directory)X
-826(would)X
-1029(not)X
-1144(need)X
-1303(to)X
-1382(split.)X
-1565(In)X
-1648(reality,)X
-1872(a)X
-1926(bucket)X
-2140(is)X
-432 5513(allocated)N
-727(for)X
-846(the)X
-969(directory)X
-1264(at)X
-1351(the)X
-1474(time)X
-1637(of)X
-1732(\256le)X
-1858(creation)X
-2124(so)X
-432 5593(although)N
-707(the)X
-818(directory)X
-1100(splits)X
-1274(logically,)X
-1566(physical)X
-1828(splits)X
-2002(do)X
-2096(not)X
-432 5673(occur)N
-610(until)X
-760(the)X
-866(\256le)X
-976(becomes)X
-1246(quite)X
-1408(large.)X
-0 f
-8 s
-2994 538 -0.4219(directory)AN
-3374(=)X
-3450 -0.3971(double\(directory\);)AX
-2706 626(})N
-2706 714 -0.3958(splitbucket\(bucket,)AN
-3466(newbl\))X
-2706 802(...)N
-2418 890(})N
-2 f
-10 s
-3169 1255(hsearch)N
-1 f
-2590 1387(Since)N
-2 f
-2807(hsearch)X
-1 f
-3100(does)X
-3286(not)X
-3427(have)X
-3617(to)X
-3717(translate)X
-4027(hash)X
-2418 1475(values)N
-2659(into)X
-2819(disk)X
-2988(addresses,)X
-3352(it)X
-3432(can)X
-3579(use)X
-3721(much)X
-3934(simpler)X
-2418 1563(algorithms)N
-2808(than)X
-2994(those)X
-3211(de\256ned)X
-3495(above.)X
-3775(System)X
-4058(V's)X
-2 f
-2418 1651(hsearch)N
-1 f
-2708(constructs)X
-3069(a)X
-3141(\256xed-size)X
-3489(hash)X
-3671(table)X
-3862(\(speci\256ed)X
-2418 1739(by)N
-2519(the)X
-2637(user)X
-2791(at)X
-2869(table)X
-3045(creation\).)X
-3391(By)X
-3504(default,)X
-3767(a)X
-3823(multiplica-)X
-2418 1827(tive)N
-2570(hash)X
-2748(function)X
-3046(based)X
-3260(on)X
-3371(that)X
-3522(described)X
-3861(in)X
-3954(Knuth,)X
-2418 1915(Volume)N
-2710(3,)X
-2804(section)X
-3065(6.4)X
-3199([KNU68])X
-3541(is)X
-3628(used)X
-3809(to)X
-3905(obtain)X
-4138(a)X
-2418 2003(primary)N
-2694(bucket)X
-2930(address.)X
-3233(If)X
-3309(this)X
-3446(bucket)X
-3681(is)X
-3755(full,)X
-3907(a)X
-3964(secon-)X
-2418 2091(dary)N
-2593(multiplicative)X
-3069(hash)X
-3248(value)X
-3454(is)X
-3538(computed)X
-3885(to)X
-3978(de\256ne)X
-2418 2179(the)N
-2542(probe)X
-2751(interval.)X
-3062(The)X
-3213(probe)X
-3422(interval)X
-3693(is)X
-3772(added)X
-3989(to)X
-4076(the)X
-2418 2267(original)N
-2712(bucket)X
-2971(address)X
-3257(\(modulo)X
-3573(the)X
-3716(table)X
-3916(size\))X
-4112(to)X
-2418 2355(obtain)N
-2658(a)X
-2734(new)X
-2908(bucket)X
-3162(address.)X
-3483(This)X
-3665(process)X
-3946(repeats)X
-2418 2443(until)N
-2588(an)X
-2688(empty)X
-2911(bucket)X
-3148(is)X
-3224(found.)X
-3474(If)X
-3551(no)X
-3654(bucket)X
-3891(is)X
-3967(found,)X
-2418 2531(an)N
-2514(insertion)X
-2814(fails)X
-2972(with)X
-3134(a)X
-3190(``table)X
-3420(full'')X
-3605(condition.)X
-2590 2645(The)N
-2768(basic)X
-2986(algorithm)X
-3350(may)X
-3541(be)X
-3670(modi\256ed)X
-4006(by)X
-4138(a)X
-2418 2733(number)N
-2705(of)X
-2813(compile)X
-3112(time)X
-3295(options)X
-3571(available)X
-3902(to)X
-4005(those)X
-2418 2821(users)N
-2604(with)X
-2767(AT&T)X
-3006(source)X
-3237(code.)X
-3450(First,)X
-3637(the)X
-3756(package)X
-4040(pro-)X
-2418 2909(vides)N
-2638(two)X
-2809(options)X
-3094(for)X
-3238(hash)X
-3435(functions.)X
-3803(Users)X
-4036(may)X
-2418 2997(specify)N
-2690(their)X
-2877(own)X
-3055(hash)X
-3242(function)X
-3549(by)X
-3669(compiling)X
-4032(with)X
-2418 3085(``USCR'')N
-2757(de\256ned)X
-3016(and)X
-3155(declaring)X
-3477(and)X
-3616(de\256ning)X
-3901(the)X
-4022(vari-)X
-2418 3173(able)N
-2 f
-2578(hcompar)X
-1 f
-2863(,)X
-2909(a)X
-2971(function)X
-3263(taking)X
-3488(two)X
-3633(string)X
-3840(arguments)X
-2418 3261(and)N
-2560(returning)X
-2880(an)X
-2982(integer.)X
-3271(Users)X
-3480(may)X
-3643(also)X
-3797(request)X
-4054(that)X
-2418 3349(hash)N
-2587(values)X
-2814(be)X
-2912(computed)X
-3250(simply)X
-3489(by)X
-3590(taking)X
-3811(the)X
-3930(modulo)X
-2418 3437(of)N
-2521(key)X
-2673(\(using)X
-2909(division)X
-3201(rather)X
-3424(than)X
-3597(multiplication)X
-4080(for)X
-2418 3525(hash)N
-2589(value)X
-2787(calculation\).)X
-3230(If)X
-3308(this)X
-3447(technique)X
-3783(is)X
-3859(used,)X
-4049(col-)X
-2418 3613(lisions)N
-2651(are)X
-2775(resolved)X
-3072(by)X
-3176(scanning)X
-3485(sequentially)X
-3896(from)X
-4076(the)X
-2418 3701(selected)N
-2702(bucket)X
-2941(\(linear)X
-3176(probing\).)X
-3517(This)X
-3684(option)X
-3913(is)X
-3991(avail-)X
-2418 3789(able)N
-2572(by)X
-2672(de\256ning)X
-2954(the)X
-3072(variable)X
-3351(``DIV'')X
-3622(at)X
-3700(compile)X
-3978(time.)X
-2590 3903(A)N
-2720(second)X
-3015(option,)X
-3311(based)X
-3565(on)X
-3716(an)X
-3863(algorithm)X
-2418 3991(discovered)N
-2787(by)X
-2888(Richard)X
-3163(P.)X
-3248(Brent,)X
-3466(rearranges)X
-3822(the)X
-3940(table)X
-4116(at)X
-2418 4079(the)N
-2549(time)X
-2724(of)X
-2824(insertion)X
-3137(in)X
-3232(order)X
-3434(to)X
-3528(speed)X
-3743(up)X
-3855(retrievals.)X
-2418 4167(The)N
-2571(basic)X
-2764(idea)X
-2926(is)X
-3007(to)X
-3097(shorten)X
-3361(long)X
-3531(probe)X
-3741(sequences)X
-4094(by)X
-2418 4255(lengthening)N
-2833(short)X
-3030(probe)X
-3249(sequences.)X
-3651(Once)X
-3857(the)X
-3991(probe)X
-2418 4343(chain)N
-2613(has)X
-2741(exceeded)X
-3062(some)X
-3252(threshold)X
-3571(\(Brent)X
-3796(suggests)X
-4087(2\),)X
-2418 4431(we)N
-2541(attempt)X
-2809(to)X
-2899(shuf\257e)X
-3145(any)X
-3289(colliding)X
-3601(keys)X
-3776(\(keys)X
-3978(which)X
-2418 4519(appeared)N
-2734(in)X
-2821(the)X
-2944(probe)X
-3152(sequence)X
-3471(of)X
-3562(the)X
-3684(new)X
-3842(key\).)X
-4049(The)X
-2418 4607(details)N
-2652(of)X
-2744(this)X
-2884(key)X
-3025(shuf\257ing)X
-3333(can)X
-3469(be)X
-3569(found)X
-3780(in)X
-3866([KNU68])X
-2418 4695(and)N
-2576([BRE73].)X
-2946(This)X
-3129(algorithm)X
-3481(may)X
-3660(be)X
-3777(obtained)X
-4094(by)X
-2418 4783(de\256ning)N
-2700(the)X
-2818(variable)X
-3097(``BRENT'')X
-3487(at)X
-3565(compile)X
-3843(time.)X
-2590 4897(A)N
-2698(third)X
-2899(set)X
-3038(of)X
-3154(options,)X
-3458(obtained)X
-3783(by)X
-3912(de\256ning)X
-2418 4985(``CHAINED'',)N
-2943(use)X
-3086(linked)X
-3321(lists)X
-3484(to)X
-3581(resolve)X
-3848(collisions.)X
-2418 5073(Either)N
-2647(of)X
-2747(the)X
-2878(primary)X
-3164(hash)X
-3343(function)X
-3642(described)X
-3982(above)X
-2418 5161(may)N
-2584(be)X
-2688(used,)X
-2882(but)X
-3011(all)X
-3118(collisions)X
-3451(are)X
-3577(resolved)X
-3876(by)X
-3983(build-)X
-2418 5249(ing)N
-2554(a)X
-2623(linked)X
-2856(list)X
-2986(of)X
-3086(entries)X
-3333(from)X
-3522(the)X
-3653(primary)X
-3940(bucket.)X
-2418 5337(By)N
-2542(default,)X
-2816(new)X
-2981(entries)X
-3226(will)X
-3381(be)X
-3488(added)X
-3711(to)X
-3804(a)X
-3871(bucket)X
-4116(at)X
-2418 5425(the)N
-2541(beginning)X
-2886(of)X
-2978(the)X
-3101(bucket)X
-3339(chain.)X
-3577(However,)X
-3916(compile)X
-2418 5513(options)N
-2706(``SORTUP'')X
-3173(or)X
-3293(``SORTDOWN'')X
-3908(may)X
-4098(be)X
-2418 5601(speci\256ed)N
-2723(to)X
-2805(order)X
-2995(the)X
-3113(hash)X
-3280(chains)X
-3505(within)X
-3729(each)X
-3897(bucket.)X
-3 f
-432 5960(4)N
-2970(USENIX)X
-9 f
-3292(-)X
-3 f
-3356(Winter)X
-3621('91)X
-9 f
-3748(-)X
-3 f
-3812(Dallas,)X
-4065(TX)X
-
-5 p
-%%Page: 5 5
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-720 258(Seltzer)N
-977(&)X
-1064(Yigit)X
-3278(A)X
-3356(New)X
-3528(Hashing)X
-3831(Package)X
-4136(for)X
-4259(UNIX)X
-2 f
-1444 538(dynahash)N
-1 f
-892 670(The)N
-2 f
-1054(dynahash)X
-1 f
-1398(library,)X
-1669(written)X
-1932(by)X
-2048(Esmond)X
-2346(Pitt,)X
-720 758(implements)N
-1183(Larson's)X
-1554(linear)X
-1827(hashing)X
-2165(algorithm)X
-720 846([LAR88])N
-1097(with)X
-1302(an)X
-2 f
-1440(hsearch)X
-1 f
-1756(compatible)X
-2174(interface.)X
-720 934(Intuitively,)N
-1099(a)X
-1161(hash)X
-1334(table)X
-1516(begins)X
-1751(as)X
-1844(a)X
-1905(single)X
-2121(bucket)X
-2360(and)X
-720 1022(grows)N
-941(in)X
-1028(generations,)X
-1443(where)X
-1665(a)X
-1725(generation)X
-2088(corresponds)X
-720 1110(to)N
-815(a)X
-884(doubling)X
-1201(in)X
-1296(the)X
-1427(size)X
-1585(of)X
-1685(the)X
-1815(hash)X
-1994(table.)X
-2222(The)X
-2379(0)X
-2 f
-7 s
-1078(th)Y
-10 s
-1 f
-720 1198(generation)N
-1085(occurs)X
-1321(as)X
-1414(the)X
-1538(table)X
-1719(grows)X
-1940(from)X
-2121(one)X
-2262(bucket)X
-720 1286(to)N
-814(two.)X
-1006(In)X
-1105(the)X
-1235(next)X
-1405(generation)X
-1776(the)X
-1906(table)X
-2093(grows)X
-2320(from)X
-720 1374(two)N
-862(to)X
-946(four.)X
-1122(During)X
-1371(each)X
-1541(generation,)X
-1921(every)X
-2121(bucket)X
-2356(that)X
-720 1462(existed)N
-967(at)X
-1045(the)X
-1163(beginning)X
-1503(of)X
-1590(the)X
-1708(generation)X
-2067(is)X
-2140(split.)X
-892 1576(The)N
-1041(table)X
-1221(starts)X
-1414(as)X
-1505(a)X
-1565(single)X
-1780(bucket)X
-2018(\(numbered)X
-2389(0\),)X
-720 1664(the)N
-839(current)X
-1088(split)X
-1245(bucket)X
-1479(is)X
-1552(set)X
-1661(to)X
-1743(bucket)X
-1977(0,)X
-2057(and)X
-2193(the)X
-2311(max-)X
-720 1752(imum)N
-933(split)X
-1097(point)X
-1288(is)X
-1368(set)X
-1483(to)X
-1571(twice)X
-1771(the)X
-1895(current)X
-2149(split)X
-2312(point)X
-720 1840(\(0\).)N
-863(When)X
-1084(it)X
-1157(is)X
-1239(time)X
-1410(for)X
-1532(a)X
-1596(bucket)X
-1838(to)X
-1928(split,)X
-2113(the)X
-2239(keys)X
-2414(in)X
-720 1928(the)N
-872(current)X
-1154(split)X
-1345(bucket)X
-1612(are)X
-1764(divided)X
-2057(between)X
-2378(the)X
-720 2016(current)N
-981(split)X
-1151(bucket)X
-1397(and)X
-1545(a)X
-1613(new)X
-1779(bucket)X
-2025(whose)X
-2262(bucket)X
-720 2104(number)N
-1000(is)X
-1088(equal)X
-1297(to)X
-1394(1)X
-1469(+)X
-1549(current)X
-1812(split)X
-1984(bucket)X
-2232(+)X
-2311(max-)X
-720 2192(imum)N
-927(split)X
-1085(point.)X
-1310(We)X
-1442(can)X
-1574(determine)X
-1915(which)X
-2131(keys)X
-2298(move)X
-720 2280(to)N
-807(the)X
-929(new)X
-1087(bucket)X
-1325(by)X
-1429(examining)X
-1791(the)X
-2 f
-1913(n)X
-7 s
-1962 2248(th)N
-10 s
-1 f
-2043 2280(bit)N
-2151(of)X
-2242(a)X
-2302(key's)X
-720 2368(hash)N
-899(value)X
-1105(where)X
-1334(n)X
-1406(is)X
-1491(the)X
-1620(generation)X
-1990(number.)X
-2306(After)X
-720 2456(the)N
-846(bucket)X
-1088(at)X
-1174(the)X
-1300(maximum)X
-1651(split)X
-1815(point)X
-2006(has)X
-2140(been)X
-2319(split,)X
-720 2544(the)N
-839(generation)X
-1198(number)X
-1463(is)X
-1536(incremented,)X
-1973(the)X
-2091(current)X
-2339(split)X
-720 2632(point)N
-908(is)X
-985(set)X
-1098(back)X
-1274(to)X
-1360(zero,)X
-1543(and)X
-1683(the)X
-1805(maximum)X
-2152(split)X
-2312(point)X
-720 2720(is)N
-815(set)X
-946(to)X
-1050(the)X
-1190(number)X
-1477(of)X
-1586(the)X
-1725(last)X
-1877(bucket)X
-2132(in)X
-2235(the)X
-2374(\256le)X
-720 2808(\(which)N
-971(is)X
-1052(equal)X
-1253(to)X
-1342(twice)X
-1543(the)X
-1668(old)X
-1797(maximum)X
-2148(split)X
-2312(point)X
-720 2896(plus)N
-873(1\).)X
-892 3010(To)N
-1031(facilitate)X
-1361(locating)X
-1668(keys,)X
-1884(we)X
-2027(maintain)X
-2356(two)X
-720 3098(masks.)N
-989(The)X
-1143(low)X
-1291(mask)X
-1488(is)X
-1569(equal)X
-1771(to)X
-1861(the)X
-1987(maximum)X
-2339(split)X
-720 3186(bucket)N
-967(and)X
-1116(the)X
-1247(high)X
-1422(mask)X
-1624(is)X
-1710(equal)X
-1917(to)X
-2011(the)X
-2141(next)X
-2311(max-)X
-720 3274(imum)N
-931(split)X
-1093(bucket.)X
-1372(To)X
-1486(locate)X
-1703(a)X
-1764(speci\256c)X
-2033(key,)X
-2193(we)X
-2311(com-)X
-720 3362(pute)N
-881(a)X
-940(32-bit)X
-1154(hash)X
-1324(value)X
-1520(using)X
-1715(a)X
-1773(bit-randomizing)X
-2311(algo-)X
-720 3450(rithm)N
-932(such)X
-1118(as)X
-1224(the)X
-1361(one)X
-1516(described)X
-1862(in)X
-1962([LAR88].)X
-2334(This)X
-720 3538(hash)N
-893(value)X
-1093(is)X
-1172(then)X
-1336(masked)X
-1607(with)X
-1775(the)X
-1898(high)X
-2065(mask.)X
-2299(If)X
-2378(the)X
-720 3626(resulting)N
-1026(number)X
-1297(is)X
-1376(greater)X
-1626(than)X
-1790(the)X
-1913(maximum)X
-2262(bucket)X
-720 3714(in)N
-823(the)X
-962(table)X
-1159(\(current)X
-1455(split)X
-1633(bucket)X
-1888(+)X
-1974(maximum)X
-2339(split)X
-720 3802(point\),)N
-962(the)X
-1091(hash)X
-1269(value)X
-1474(is)X
-1558(masked)X
-1834(with)X
-2007(the)X
-2136(low)X
-2287(mask.)X
-720 3890(In)N
-825(either)X
-1046(case,)X
-1242(the)X
-1377(result)X
-1592(of)X
-1696(the)X
-1831(mask)X
-2037(is)X
-2127(the)X
-2262(bucket)X
-720 3978(number)N
-989(for)X
-1107(the)X
-1229(given)X
-1431(key.)X
-1611(The)X
-1759(algorithm)X
-2093(below)X
-2312(illus-)X
-720 4066(trates)N
-914(this)X
-1049(process.)X
-0 f
-8 s
-720 4365(h)N
-796(=)X
-872 -0.4038(calchash\(key\);)AX
-720 4453(bucket)N
-986(=)X
-1062(h)X
-1138(&)X
-1214 -0.4167(high_mask;)AX
-720 4541(if)N
-834(\()X
-910(bucket)X
-1176(>)X
-1252 -0.4167(max_bucket)AX
-1670(\))X
-1008 4629(bucket)N
-1274(=)X
-1350(h)X
-1426(&)X
-1502 -0.4219(low_mask;)AX
-720 4717 -0.4018(return\(bucket\);)AN
-1 f
-10 s
-892 5042(In)N
-1013(order)X
-1237(to)X
-1353(decide)X
-1617(when)X
-1845(to)X
-1961(split)X
-2152(a)X
-2242(bucket,)X
-2 f
-720 5130(dynahash)N
-1 f
-1050(uses)X
-2 f
-1210(controlled)X
-1561(splitting)X
-1 f
-1822(.)X
-1884(A)X
-1964(hash)X
-2133(table)X
-2311(has)X
-2440(a)X
-720 5218(\256ll)N
-837(factor)X
-1054(which)X
-1279(is)X
-1361(expressed)X
-1707(in)X
-1798(terms)X
-2004(of)X
-2099(the)X
-2225(average)X
-720 5306(number)N
-990(of)X
-1082(keys)X
-1253(in)X
-1339(each)X
-1511(bucket.)X
-1789(Each)X
-1974(time)X
-2140(the)X
-2262(table's)X
-720 5394(total)N
-885(number)X
-1153(of)X
-1243(keys)X
-1413(divided)X
-1676(by)X
-1778(its)X
-1875(number)X
-2142(of)X
-2231(buckets)X
-720 5482(exceeds)N
-995(this)X
-1130(\256ll)X
-1238(factor,)X
-1466(a)X
-1522(bucket)X
-1756(is)X
-1829(split.)X
-2878 538(Since)N
-3079(the)X
-2 f
-3200(hsearch)X
-1 f
-3477(create)X
-3693(interface)X
-3998(\()X
-2 f
-4025(hcreate)X
-1 f
-4266(\))X
-4315(calls)X
-2706 626(for)N
-2842(an)X
-2960(estimate)X
-3269(of)X
-3378(the)X
-3518(\256nal)X
-3702(size)X
-3869(of)X
-3978(the)X
-4118(hash)X
-4306(table)X
-2706 714(\()N
-2 f
-2733(nelem)X
-1 f
-2925(\),)X
-2 f
-3007(dynahash)X
-1 f
-3349(uses)X
-3522(this)X
-3672(information)X
-4085(to)X
-4182(initialize)X
-2706 802(the)N
-2848(table.)X
-3088(The)X
-3257(initial)X
-3486(number)X
-3774(of)X
-3884(buckets)X
-4172(is)X
-4268(set)X
-4400(to)X
-2 f
-2706 890(nelem)N
-1 f
-2926(rounded)X
-3217(to)X
-3306(the)X
-3431(next)X
-3596(higher)X
-3828(power)X
-4056(of)X
-4150(two.)X
-4337(The)X
-2706 978(current)N
-2958(split)X
-3118(point)X
-3305(is)X
-3381(set)X
-3493(to)X
-3578(0)X
-3641(and)X
-3780(the)X
-3901(maximum)X
-4248(bucket)X
-2706 1066(and)N
-2842(maximum)X
-3186(split)X
-3343(point)X
-3527(are)X
-3646(set)X
-3755(to)X
-3837(this)X
-3972(rounded)X
-4255(value.)X
-3 f
-3148 1220(The)N
-3301(New)X
-3473(Implementation)X
-1 f
-2878 1352(Our)N
-3042(implementation)X
-3583(is)X
-3675(also)X
-3842(based)X
-4063(on)X
-4181(Larson's)X
-2706 1440(linear)N
-2939(hashing)X
-3238([LAR88])X
-3582(algorithm)X
-3943(as)X
-4060(well)X
-4248(as)X
-4364(the)X
-2 f
-2706 1528(dynahash)N
-1 f
-3047(implementation.)X
-3623(The)X
-2 f
-3782(dbm)X
-1 f
-3954(family)X
-4197(of)X
-4297(algo-)X
-2706 1616(rithms)N
-2942(decide)X
-3184(dynamically)X
-3612(which)X
-3840(bucket)X
-4085(to)X
-4178(split)X
-4346(and)X
-2706 1704(when)N
-2914(to)X
-3010(split)X
-3180(it)X
-3257(\(when)X
-3491(it)X
-3568(over\257ows\))X
-3944(while)X
-2 f
-4155(dynahash)X
-1 f
-2706 1792(splits)N
-2933(in)X
-3054(a)X
-3149(prede\256ned)X
-3547(order)X
-3776(\(linearly\))X
-4134(and)X
-4309(at)X
-4426(a)X
-2706 1880(prede\256ned)N
-3116(time)X
-3328(\(when)X
-3599(the)X
-3767(table)X
-3993(\256ll)X
-4151(factor)X
-4409(is)X
-2706 1968(exceeded\).)N
-3121(We)X
-3280(use)X
-3434(a)X
-3517(hybrid)X
-3773(of)X
-3887(these)X
-4099(techniques.)X
-2706 2056(Splits)N
-2913(occur)X
-3118(in)X
-3206(the)X
-3330(prede\256ned)X
-3695(order)X
-3891(of)X
-3984(linear)X
-4193(hashing,)X
-2706 2144(but)N
-2845(the)X
-2980(time)X
-3159(at)X
-3253(which)X
-3485(pages)X
-3704(are)X
-3839(split)X
-4012(is)X
-4101(determined)X
-2706 2232(both)N
-2869(by)X
-2970(page)X
-3143(over\257ows)X
-3480(\()X
-2 f
-3507(uncontrolled)X
-3937(splitting)X
-1 f
-4198(\))X
-4246(and)X
-4382(by)X
-2706 2320(exceeding)N
-3052(the)X
-3170(\256ll)X
-3278(factor)X
-3486(\()X
-2 f
-3513(controlled)X
-3862(splitting)X
-1 f
-4123(\))X
-2878 2434(A)N
-2962(hash)X
-3135(table)X
-3317(is)X
-3395(parameterized)X
-3876(by)X
-3981(both)X
-4148(its)X
-4248(bucket)X
-2706 2522(size)N
-2904(\()X
-2 f
-2931(bsize)X
-1 f
-(\))S
-3191(and)X
-3380(\256ll)X
-3541(factor)X
-3801(\()X
-2 f
-3828(ffactor)X
-1 f
-4041(\).)X
-4180(Whereas)X
-2 f
-2706 2610(dynahash's)N
-1 f
-3095(buckets)X
-3364(can)X
-3500(be)X
-3599(represented)X
-3993(as)X
-4083(a)X
-4142(linked)X
-4365(list)X
-2706 2698(of)N
-2798(elements)X
-3108(in)X
-3195(memory,)X
-3507(our)X
-3639(package)X
-3928(needs)X
-4136(to)X
-4222(support)X
-2706 2786(disk)N
-2874(access,)X
-3135(and)X
-3286(must)X
-3476(represent)X
-3806(buckets)X
-4086(in)X
-4183(terms)X
-4395(of)X
-2706 2874(pages.)N
-2955(The)X
-2 f
-3106(bsize)X
-1 f
-3291(is)X
-3369(the)X
-3492(size)X
-3642(\(in)X
-3756(bytes\))X
-3977(of)X
-4069(these)X
-4259(pages.)X
-2706 2962(As)N
-2833(in)X
-2933(linear)X
-3154(hashing,)X
-3461(the)X
-3597(number)X
-3879(of)X
-3983(buckets)X
-4265(in)X
-4364(the)X
-2706 3050(table)N
-2906(is)X
-3003(equal)X
-3221(to)X
-3327(the)X
-3469(number)X
-3758(of)X
-3869(keys)X
-4060(in)X
-4165(the)X
-4306(table)X
-2706 3138(divided)N
-2988(by)X
-2 f
-3110(ffactor)X
-1 f
-3323(.)X
-2 f
-8 s
-3113(6)Y
-1 f
-10 s
-3417 3138(The)N
-3584(controlled)X
-3950(splitting)X
-4252(occurs)X
-2706 3226(each)N
-2878(time)X
-3044(the)X
-3166(number)X
-3435(of)X
-3526(keys)X
-3697(in)X
-3783(the)X
-3905(table)X
-4085(exceeds)X
-4364(the)X
-2706 3314(\256ll)N
-2814(factor)X
-3022(multiplied)X
-3370(by)X
-3470(the)X
-3588(number)X
-3853(of)X
-3940(buckets.)X
-2878 3428(Inserting)N
-3187(keys)X
-3358(and)X
-3498(splitting)X
-3783(buckets)X
-4051(is)X
-4127(performed)X
-2706 3516(precisely)N
-3018(as)X
-3107(described)X
-3437(previously)X
-3796(for)X
-2 f
-3911(dynahash)X
-1 f
-4218(.)X
-4279(How-)X
-2706 3604(ever,)N
-2897(since)X
-3094(buckets)X
-3371(are)X
-3502(now)X
-3671(comprised)X
-4036(of)X
-4134(pages,)X
-4368(we)X
-2706 3692(must)N
-2883(be)X
-2981(prepared)X
-3284(to)X
-3367(handle)X
-3602(cases)X
-3793(where)X
-4011(the)X
-4130(size)X
-4276(of)X
-4364(the)X
-2706 3780(keys)N
-2873(and)X
-3009(data)X
-3163(in)X
-3245(a)X
-3301(bucket)X
-3535(exceed)X
-3779(the)X
-3897(bucket)X
-4131(size.)X
-3 f
-3318 3934(Over\257ow)N
-3654(Pages)X
-1 f
-2878 4066(There)N
-3095(are)X
-3223(two)X
-3372(cases)X
-3571(where)X
-3797(a)X
-3862(key)X
-4007(may)X
-4174(not)X
-4305(\256t)X
-4400(in)X
-2706 4154(its)N
-2802(designated)X
-3166(bucket.)X
-3441(In)X
-3529(the)X
-3647(\256rst)X
-3791(case,)X
-3970(the)X
-4088(total)X
-4250(size)X
-4395(of)X
-2706 4242(the)N
-2833(key)X
-2978(and)X
-3123(data)X
-3286(may)X
-3453(exceed)X
-3706(the)X
-3833(bucket)X
-4076(size.)X
-4269(In)X
-4364(the)X
-2706 4330(second,)N
-3008(addition)X
-3328(of)X
-3453(a)X
-3547(new)X
-3739(key)X
-3913(could)X
-4149(cause)X
-4386(an)X
-2706 4418(over\257ow,)N
-3068(but)X
-3227(the)X
-3382(bucket)X
-3652(in)X
-3770(question)X
-4097(is)X
-4206(not)X
-4364(yet)X
-2706 4506(scheduled)N
-3049(to)X
-3133(be)X
-3230(split.)X
-3428(In)X
-3516(existing)X
-3790(implementations,)X
-4364(the)X
-2706 4594(second)N
-2953(case)X
-3115(never)X
-3317(arises)X
-3523(\(since)X
-3738(buckets)X
-4006(are)X
-4128(split)X
-4288(when)X
-2706 4682(they)N
-2871(over\257ow\))X
-3210(and)X
-3352(the)X
-3476(\256rst)X
-3626(case)X
-3791(is)X
-3870(not)X
-3998(handled)X
-4278(at)X
-4362(all.)X
-2706 4770(Although)N
-3036(large)X
-3225(key/data)X
-3525(pair)X
-3678(handling)X
-3986(is)X
-4066(dif\256cult)X
-4346(and)X
-2706 4858(expensive,)N
-3083(it)X
-3163(is)X
-3252(essential.)X
-3604(In)X
-3706(a)X
-3777(linear)X
-3995(hashed)X
-4253(imple-)X
-2706 4946(mentation,)N
-3087(over\257ow)X
-3413(pages)X
-3636(are)X
-3775(required)X
-4083(for)X
-4217(buckets)X
-2706 5034(which)N
-2935(over\257ow)X
-3253(before)X
-3492(they)X
-3662(are)X
-3793(split,)X
-3982(so)X
-4085(we)X
-4211(can)X
-4355(use)X
-2706 5122(the)N
-2833(same)X
-3027(mechanism)X
-3421(for)X
-3544(large)X
-3734(key/data)X
-4035(pairs)X
-4220(that)X
-4368(we)X
-2706 5210(use)N
-2837(for)X
-2955(over\257ow)X
-3264(pages.)X
-3511(Logically,)X
-3862(we)X
-3980(chain)X
-4177(over\257ow)X
-16 s
-2706 5353 MXY
-864 0 Dl
-2 f
-8 s
-2746 5408(6)N
-1 f
-9 s
-2801 5433(This)N
-2952(is)X
-3023(not)X
-3138(strictly)X
-3361(true.)X
-3532(The)X
-3667(\256le)X
-3782(does)X
-3937(not)X
-4052(contract)X
-4306(when)X
-2706 5513(keys)N
-2861(are)X
-2972(deleted,)X
-3221(so)X
-3308(the)X
-3419(number)X
-3662(of)X
-3744(buckets)X
-3986(is)X
-4056(actually)X
-4306(equal)X
-2706 5593(to)N
-2782(the)X
-2890(maximum)X
-3202(number)X
-3441(of)X
-3520(keys)X
-3671(ever)X
-3814(present)X
-4041(in)X
-4116(the)X
-4223(table)X
-4382(di-)X
-2706 5673(vided)N
-2884(by)X
-2974(the)X
-3080(\256ll)X
-3178(factor.)X
-3 f
-10 s
-720 5960(USENIX)N
-9 f
-1042(-)X
-3 f
-1106(Winter)X
-1371('91)X
-9 f
-1498(-)X
-3 f
-1562(Dallas,)X
-1815(TX)X
-4424(5)X
-
-6 p
-%%Page: 6 6
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-432 258(A)N
-510(New)X
-682(Hashing)X
-985(Package)X
-1290(for)X
-1413(UNIX)X
-3663(Seltzer)X
-3920(&)X
-4007(Yigit)X
-1 f
-432 538(pages)N
-639(to)X
-725(the)X
-847(buckets)X
-1116(\(also)X
-1296(called)X
-1512(primary)X
-1789(pages\).)X
-2062(In)X
-2152(a)X
-432 626(memory)N
-730(based)X
-943(representation,)X
-1448(over\257ow)X
-1763(pages)X
-1976(do)X
-2086(not)X
-432 714(pose)N
-628(any)X
-792(special)X
-1063(problems)X
-1409(because)X
-1712(we)X
-1854(can)X
-2014(chain)X
-432 802(over\257ow)N
-776(pages)X
-1017(to)X
-1137(primary)X
-1449(pages)X
-1690(using)X
-1921(memory)X
-432 890(pointers.)N
-776(However,)X
-1137(mapping)X
-1463(these)X
-1674(over\257ow)X
-2005(pages)X
-432 978(into)N
-584(a)X
-648(disk)X
-809(\256le)X
-939(is)X
-1019(more)X
-1211(of)X
-1305(a)X
-1368(challenge,)X
-1723(since)X
-1915(we)X
-2036(need)X
-432 1066(to)N
-547(be)X
-675(able)X
-861(to)X
-975(address)X
-1268(both)X
-1462(bucket)X
-1728(pages,)X
-1983(whose)X
-432 1154(numbers)N
-729(are)X
-849(growing)X
-1137(linearly,)X
-1422(and)X
-1558(some)X
-1747(indeterminate)X
-432 1242(number)N
-715(of)X
-820(over\257ow)X
-1143(pages)X
-1364(without)X
-1646(reorganizing)X
-2090(the)X
-432 1330(\256le.)N
-604 1444(One)N
-789(simple)X
-1053(solution)X
-1361(would)X
-1612(be)X
-1739(to)X
-1852(allocate)X
-2152(a)X
-432 1532(separate)N
-737(\256le)X
-880(for)X
-1015(over\257ow)X
-1341(pages.)X
-1604(The)X
-1769(disadvantage)X
-432 1620(with)N
-605(such)X
-783(a)X
-850(technique)X
-1193(is)X
-1276(that)X
-1426(it)X
-1500(requires)X
-1789(an)X
-1895(extra)X
-2086(\256le)X
-432 1708(descriptor,)N
-794(an)X
-891(extra)X
-1073(system)X
-1316(call)X
-1453(on)X
-1554(open)X
-1731(and)X
-1867(close,)X
-2072(and)X
-432 1796(logically)N
-739(associating)X
-1122(two)X
-1269(independent)X
-1687(\256les.)X
-1886(For)X
-2023(these)X
-432 1884(reasons,)N
-728(we)X
-857(wanted)X
-1123(to)X
-1219(map)X
-1391(both)X
-1567(primary)X
-1855(pages)X
-2072(and)X
-432 1972(over\257ow)N
-737(pages)X
-940(into)X
-1084(the)X
-1202(same)X
-1387(\256le)X
-1509(space.)X
-604 2086(The)N
-799(buddy-in-waiting)X
-1425(algorithm)X
-1806(provides)X
-2152(a)X
-432 2174(mechanism)N
-851(to)X
-966(support)X
-1259(multiple)X
-1578(pages)X
-1814(per)X
-1970(logical)X
-432 2262(bucket)N
-685(while)X
-902(retaining)X
-1226(the)X
-1362(simple)X
-1613(split)X
-1788(sequence)X
-2121(of)X
-432 2350(linear)N
-681(hashing.)X
-1015(Over\257ow)X
-1383(pages)X
-1631(are)X
-1795(preallocated)X
-432 2438(between)N
-781(generations)X
-1232(of)X
-1379(primary)X
-1713(pages.)X
-1996(These)X
-432 2526(over\257ow)N
-759(pages)X
-984(are)X
-1125(used)X
-1314(by)X
-1436(any)X
-1594(bucket)X
-1850(containing)X
-432 2614(more)N
-646(keys)X
-842(than)X
-1029(\256t)X
-1144(on)X
-1273(the)X
-1420(primary)X
-1723(page)X
-1924(and)X
-2089(are)X
-432 2702(reclaimed,)N
-808(if)X
-896(possible,)X
-1217(when)X
-1430(the)X
-1567(bucket)X
-1819(later)X
-2000(splits.)X
-432 2790(Figure)N
-687(3)X
-773(depicts)X
-1045(the)X
-1188(layout)X
-1433(of)X
-1545(primary)X
-1844(pages)X
-2072(and)X
-432 2878(over\257ow)N
-752(pages)X
-970(within)X
-1209(the)X
-1342(same)X
-1542(\256le.)X
-1699(Over\257ow)X
-2036(page)X
-432 2966(use)N
-586(information)X
-1011(is)X
-1111(recorded)X
-1440(in)X
-1548(bitmaps)X
-1847(which)X
-2089(are)X
-432 3054(themselves)N
-819(stored)X
-1046(on)X
-1157(over\257ow)X
-1472(pages.)X
-1725(The)X
-1880(addresses)X
-432 3142(of)N
-520(the)X
-639(bitmap)X
-882(pages)X
-1086(and)X
-1223(the)X
-1342(number)X
-1608(of)X
-1695(pages)X
-1898(allocated)X
-432 3230(at)N
-515(each)X
-688(split)X
-850(point)X
-1039(are)X
-1163(stored)X
-1384(in)X
-1470(the)X
-1592(\256le)X
-1718(header.)X
-1997(Using)X
-432 3318(this)N
-577(information,)X
-1005(both)X
-1177(over\257ow)X
-1492(addresses)X
-1829(and)X
-1974(bucket)X
-432 3406(addresses)N
-764(can)X
-900(be)X
-999(mapped)X
-1276(to)X
-1361(disk)X
-1517(addresses)X
-1848(by)X
-1951(the)X
-2072(fol-)X
-432 3494(lowing)N
-674(calculation:)X
-0 f
-8 s
-432 3793(int)N
-736(bucket;)X
-1192(/*)X
-1306(bucket)X
-1572(address)X
-1876(*/)X
-432 3881(u_short)N
-736(oaddr;)X
-1192(/*)X
-1306(OVERFLOW)X
-1648(address)X
-1952(*/)X
-432 3969(int)N
-736 -0.4125(nhdr_pages;)AX
-1192(/*)X
-1306(npages)X
-1572(in)X
-1686 -112.4062(\256le)AX
-1838(header)X
-2104(*/)X
-432 4057(int)N
-736 -0.4125(spares[32];)AX
-1192(/*)X
-1306(npages)X
-1572(at)X
-1686(each)X
-1876(split)X
-2104(*/)X
-432 4145(int)N
-736(log2\(\);)X
-1198(/*)X
-1312(ceil\(log)X
-1654(base)X
-1844(2\))X
-1958(*/)X
-432 4321(#DEFINE)N
-736 -0.3929(BUCKET_TO_PAGE\(bucket\))AX
-1610(\\)X
-584 4409(bucket)N
-850(+)X
-926 -0.4167(nhdr_pages)AX
-1344(+)X
-1420(\\)X
-584 4497 -0.3894(\(bucket?spares[logs2\(bucket)AN
-1648(+)X
-1724(1\)-1]:0\))X
-432 4673(#DEFINE)N
-736 -0.3947(OADDR_TO_PAGE\(oaddr\))AX
-1534(\\)X
-584 4761 -0.3984(BUCKET_TO_PAGE\(\(1)AN
-1268(<<)X
-1382 -0.4091(\(oaddr>>11\)\))AX
-1876(-)X
-1952(1\))X
-2066(+)X
-2142(\\)X
-584 4849(oaddr)N
-812(&)X
-888(0x7ff;)X
-1 f
-10 s
-604 5262(An)N
-728(over\257ow)X
-1039(page)X
-1217(is)X
-1295(addressed)X
-1637(by)X
-1742(its)X
-1842(split)X
-2004(point,)X
-432 5350(identifying)N
-858(the)X
-1031(generations)X
-1476(between)X
-1819(which)X
-2090(the)X
-432 5438(over\257ow)N
-740(page)X
-915(is)X
-991(allocated,)X
-1324(and)X
-1463(its)X
-1561(page)X
-1736(number,)X
-2023(iden-)X
-432 5526(tifying)N
-665(the)X
-783(particular)X
-1111(page)X
-1283(within)X
-1507(the)X
-1625(split)X
-1782(point.)X
-1986(In)X
-2073(this)X
-432 5614(implementation,)N
-983(offsets)X
-1225(within)X
-1457(pages)X
-1668(are)X
-1795(16)X
-1903(bits)X
-2046(long)X
-432 5702(\(limiting)N
-732(the)X
-851(maximum)X
-1196(page)X
-1368(size)X
-1513(to)X
-1595(32K\),)X
-1800(so)X
-1891(we)X
-2005(select)X
-2418 538(an)N
-2535(over\257ow)X
-2860(page)X
-3052(addressing)X
-3435(algorithm)X
-3786(that)X
-3946(can)X
-4098(be)X
-2418 626(expressed)N
-2760(in)X
-2847(16)X
-2952(bits)X
-3091(and)X
-3231(which)X
-3451(allows)X
-3684(quick)X
-3886(retrieval.)X
-2418 714(The)N
-2568(top)X
-2695(\256ve)X
-2840(bits)X
-2980(indicate)X
-3258(the)X
-3380(split)X
-3541(point)X
-3729(and)X
-3869(the)X
-3991(lower)X
-2418 802(eleven)N
-2650(indicate)X
-2926(the)X
-3046(page)X
-3220(number)X
-3487(within)X
-3713(the)X
-3832(split)X
-3990(point.)X
-2418 890(Since)N
-2633(\256ve)X
-2789(bits)X
-2940(are)X
-3075(reserved)X
-3384(for)X
-3514(the)X
-3648(split)X
-3821(point,)X
-4041(\256les)X
-2418 978(may)N
-2578(split)X
-2737(32)X
-2839(times)X
-3034(yielding)X
-3318(a)X
-3376(maximum)X
-3721(\256le)X
-3844(size)X
-3990(of)X
-4078(2)X
-7 s
-946(32)Y
-10 s
-2418 1066(buckets)N
-2698(and)X
-2849(32)X
-2 f
-(*)S
-1 f
-2982(2)X
-7 s
-1034(11)Y
-10 s
-3113 1066(over\257ow)N
-3433(pages.)X
-3691(The)X
-3850(maximum)X
-2418 1154(page)N
-2597(size)X
-2749(is)X
-2829(2)X
-7 s
-1122(15)Y
-10 s
-1154(,)Y
-2971(yielding)X
-3259(a)X
-3321(maximum)X
-3671(\256le)X
-3799(size)X
-3950(greater)X
-2418 1242(than)N
-2601(131,000)X
-2906(GB)X
-3061(\(on)X
-3212(\256le)X
-3358(systems)X
-3655(supporting)X
-4041(\256les)X
-2418 1330(larger)N
-2626(than)X
-2784(4GB\).)X
-10 f
-2418 1418 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-1 Dt
-4014 2275 MXY
-0 133 Dl
-3881 2275 MXY
-0 133 Dl
-3748 2275 MXY
-0 133 Dl
-3083 2275 MXY
-0 133 Dl
-5 s
-1 f
-3523 2475(2/3)N
-3390(2/2)X
-3257(2/1)X
-2859(1/2)X
-2726(1/1)X
-5 Dt
-3814 1743 MXY
-0 133 Dl
-3282 1743 MXY
-0 133 Dl
-3017 1743 MXY
-0 133 Dl
-2884 1743 MXY
-0 133 Dl
-1 Dt
-3681 1743 MXY
-0 133 Dl
-133 0 Dl
-0 -133 Dl
--133 0 Dl
-3548 MX
-0 133 Dl
-133 0 Dl
-0 -133 Dl
--133 0 Dl
-3415 MX
-0 133 Dl
-133 0 Dl
-0 -133 Dl
--133 0 Dl
-3282 MX
-0 133 Dl
-133 0 Dl
-0 -133 Dl
--133 0 Dl
-3150 MX
-0 133 Dl
-132 0 Dl
-0 -133 Dl
--132 0 Dl
-3017 MX
-0 133 Dl
-133 0 Dl
-0 -133 Dl
--133 0 Dl
-2884 MX
-0 133 Dl
-133 0 Dl
-0 -133 Dl
--133 0 Dl
-3 f
-8 s
-3017 2601(Over\257ow)N
-3285(Addresses)X
-3515 2833(Over\257ow)N
-3783(Pages)X
-2850(Buckets)X
-1 Di
-3349 2740 MXY
- 3349 2740 lineto
- 3482 2740 lineto
- 3482 2873 lineto
- 3349 2873 lineto
- 3349 2740 lineto
-closepath 3 3349 2740 3482 2873 Dp
-2684 MX
-0 133 Dl
-133 0 Dl
-0 -133 Dl
--133 0 Dl
-5 Dt
-4146 2275 MXY
-0 133 Dl
-3216 2275 MXY
-0 133 Dl
-2684 2275 MXY
-0 133 Dl
-2551 2275 MXY
-0 133 Dl
-1 f
-3798 1963(3)N
-3266 1980(2)N
-3001(1)X
-2868(0)X
-1 Dt
-2751 1743 MXY
-0 133 Dl
-133 0 Dl
-0 -133 Dl
--133 0 Dl
-3548 2275 MXY
--15 -22 Dl
-2 16 Dl
--13 11 Dl
-26 -5 Dl
--282 -117 Dl
-3432 2275 MXY
--10 -25 Dl
--2 16 Dl
--15 8 Dl
-27 1 Dl
--166 -117 Dl
-3282 2275 MXY
-12 -25 Dl
--14 10 Dl
--15 -6 Dl
-17 21 Dl
--16 -117 Dl
-2884 2275 MXY
-26 7 Dl
--12 -12 Dl
-3 -16 Dl
--17 21 Dl
-382 -117 Dl
-2751 2275 MXY
-25 9 Dl
--11 -12 Dl
-5 -17 Dl
--19 20 Dl
-515 -117 Dl
-3 f
-3070 2152(Over\257ow)N
-3338(Pages)X
-3482 2275 MXY
- 3482 2275 lineto
- 3615 2275 lineto
- 3615 2408 lineto
- 3482 2408 lineto
- 3482 2275 lineto
-closepath 3 3482 2275 3615 2408 Dp
-3349 MX
- 3349 2275 lineto
- 3482 2275 lineto
- 3482 2408 lineto
- 3349 2408 lineto
- 3349 2275 lineto
-closepath 3 3349 2275 3482 2408 Dp
-3216 MX
- 3216 2275 lineto
- 3349 2275 lineto
- 3349 2408 lineto
- 3216 2408 lineto
- 3216 2275 lineto
-closepath 3 3216 2275 3349 2408 Dp
-2817 MX
- 2817 2275 lineto
- 2950 2275 lineto
- 2950 2408 lineto
- 2817 2408 lineto
- 2817 2275 lineto
-closepath 3 2817 2275 2950 2408 Dp
-2684 MX
- 2684 2275 lineto
- 2817 2275 lineto
- 2817 2408 lineto
- 2684 2408 lineto
- 2684 2275 lineto
-closepath 3 2684 2275 2817 2408 Dp
-3615 MX
-0 133 Dl
-531 0 Dl
-0 -133 Dl
--531 0 Dl
-2950 MX
-0 133 Dl
-266 0 Dl
-0 -133 Dl
--266 0 Dl
-2551 MX
-0 133 Dl
-133 0 Dl
-0 -133 Dl
--133 0 Dl
-3798 1726 MXY
--21 -18 Dl
-6 16 Dl
--10 13 Dl
-25 -11 Dl
--599 -99 Dl
-3266 1726 MXY
--1 -27 Dl
--7 15 Dl
--17 1 Dl
-25 11 Dl
--67 -99 Dl
-3033 1726 MXY
-27 1 Dl
--14 -8 Dl
--1 -17 Dl
--12 24 Dl
-166 -99 Dl
-2900 1726 MXY
-27 7 Dl
--13 -11 Dl
-3 -17 Dl
--17 21 Dl
-299 -99 Dl
-3058 1621(Split)N
-3203(Points)X
-2418 2275 MXY
-0 133 Dl
-133 0 Dl
-0 -133 Dl
--133 0 Dl
-3 Dt
--1 Ds
-3137(Figure)Y
-2619(3:)X
-1 f
-2691(Split)X
-2832(points)X
-3008(occur)X
-3168(between)X
-3399(generations)X
-3712(and)X
-3823(are)X
-3919(numbered)X
-2418 3225(from)N
-2560(0.)X
-2642(In)X
-2713(this)X
-2824(\256gure)X
-2991(there)X
-3136(are)X
-3231(two)X
-3345(over\257ow)X
-3590(pages)X
-3753(allocated)X
-4000(at)X
-4063(split)X
-2418 3313(point)N
-2566(1)X
-2614(and)X
-2722(three)X
-2865(allocated)X
-3111(at)X
-3173(split)X
-3300(point)X
-3448(2.)X
-10 s
-10 f
-2418 3489 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-3 f
-2949 3731(Buffer)N
-3192(Management)X
-1 f
-2590 3863(The)N
-2744(hash)X
-2920(table)X
-3105(is)X
-3187(stored)X
-3412(in)X
-3502(memory)X
-3797(as)X
-3892(a)X
-3956(logical)X
-2418 3951(array)N
-2633(of)X
-2749(bucket)X
-3012(pointers.)X
-3359(Physically,)X
-3761(the)X
-3907(array)X
-4121(is)X
-2418 4039(arranged)N
-2728(in)X
-2818(segments)X
-3144(of)X
-3239(256)X
-3387(pointers.)X
-3713(Initially,)X
-4013(there)X
-2418 4127(is)N
-2530(space)X
-2767(to)X
-2887(allocate)X
-3195(256)X
-3373(segments.)X
-3769(Reallocation)X
-2418 4215(occurs)N
-2651(when)X
-2847(the)X
-2967(number)X
-3234(of)X
-3323(buckets)X
-3590(exceeds)X
-3867(32K)X
-4027(\(256)X
-2418 4303(*)N
-2508(256\).)X
-2745(Primary)X
-3053(pages)X
-3286(may)X
-3473(be)X
-3598(accessed)X
-3929(directly)X
-2418 4391(through)N
-2711(the)X
-2853(array)X
-3062(by)X
-3185(bucket)X
-3442(number)X
-3730(and)X
-3889(over\257ow)X
-2418 4479(pages)N
-2628(are)X
-2754 0.4028(referenced)AX
-3122(logically)X
-3429(by)X
-3536(their)X
-3710(over\257ow)X
-4022(page)X
-2418 4567(address.)N
-2726(For)X
-2864(small)X
-3063(hash)X
-3236(tables,)X
-3469(it)X
-3539(is)X
-3618(desirable)X
-3934(to)X
-4022(keep)X
-2418 4655(all)N
-2525(pages)X
-2735(in)X
-2823(main)X
-3009(memory)X
-3302(while)X
-3506(on)X
-3612(larger)X
-3826(tables,)X
-4059(this)X
-2418 4743(is)N
-2523(probably)X
-2860(impossible.)X
-3298(To)X
-3438(satisfy)X
-3698(both)X
-3891(of)X
-4009(these)X
-2418 4831(requirements,)N
-2900(the)X
-3041(package)X
-3348(includes)X
-3658(buffer)X
-3897(manage-)X
-2418 4919(ment)N
-2598(with)X
-2760(LRU)X
-2940(\(least)X
-3134(recently)X
-3413(used\))X
-3607(replacement.)X
-2590 5033(By)N
-2730(default,)X
-3020(the)X
-3165(package)X
-3475(allocates)X
-3802(up)X
-3928(to)X
-4036(64K)X
-2418 5121(bytes)N
-2616(of)X
-2712(buffered)X
-3014(pages.)X
-3246(All)X
-3377(pages)X
-3589(in)X
-3680(the)X
-3807(buffer)X
-4032(pool)X
-2418 5209(are)N
-2542(linked)X
-2766(in)X
-2852(LRU)X
-3036(order)X
-3230(to)X
-3316(facilitate)X
-3621(fast)X
-3761(replacement.)X
-2418 5297(Whereas)N
-2724(ef\256cient)X
-3011(access)X
-3241(to)X
-3327(primary)X
-3605(pages)X
-3812(is)X
-3889(provided)X
-2418 5385(by)N
-2521(the)X
-2642(bucket)X
-2879(array,)X
-3087(ef\256cient)X
-3372(access)X
-3600(to)X
-3684(over\257ow)X
-3991(pages)X
-2418 5473(is)N
-2501(provided)X
-2816(by)X
-2926(linking)X
-3182(over\257ow)X
-3497(page)X
-3679(buffers)X
-3936(to)X
-4027(their)X
-2418 5561(predecessor)N
-2827(page)X
-3008(\(either)X
-3247(the)X
-3374(primary)X
-3657(page)X
-3838(or)X
-3933(another)X
-2418 5649(over\257ow)N
-2742(page\).)X
-3000(This)X
-3181(means)X
-3425(that)X
-3584(an)X
-3699(over\257ow)X
-4022(page)X
-3 f
-432 5960(6)N
-2970(USENIX)X
-9 f
-3292(-)X
-3 f
-3356(Winter)X
-3621('91)X
-9 f
-3748(-)X
-3 f
-3812(Dallas,)X
-4065(TX)X
-
-7 p
-%%Page: 7 7
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-720 258(Seltzer)N
-977(&)X
-1064(Yigit)X
-3278(A)X
-3356(New)X
-3528(Hashing)X
-3831(Package)X
-4136(for)X
-4259(UNIX)X
-1 f
-720 538(cannot)N
-955(be)X
-1052(present)X
-1305(in)X
-1388(the)X
-1507(buffer)X
-1724(pool)X
-1886(if)X
-1955(its)X
-2050(primary)X
-2324(page)X
-720 626(is)N
-804(not)X
-937(present.)X
-1240(This)X
-1413(does)X
-1591(not)X
-1724(impact)X
-1972(performance)X
-2409(or)X
-720 714(functionality,)N
-1209(because)X
-1524(an)X
-1660(over\257ow)X
-2005(page)X
-2217(will)X
-2400(be)X
-720 802(accessed)N
-1048(only)X
-1236(after)X
-1430(its)X
-1550(predecessor)X
-1975(page)X
-2172(has)X
-2324(been)X
-720 890(accessed.)N
-1068(Figure)X
-1303(4)X
-1369(depicts)X
-1622(the)X
-1746(data)X
-1905(structures)X
-2242(used)X
-2414(to)X
-720 978(manage)N
-990(the)X
-1108(buffer)X
-1325(pool.)X
-892 1092(The)N
-1040(in-memory)X
-1419(bucket)X
-1656(array)X
-1845(contains)X
-2134(pointers)X
-2414(to)X
-720 1180(buffer)N
-975(header)X
-1248(structures)X
-1617(which)X
-1870(represent)X
-2222(primary)X
-720 1268(pages.)N
-968(Buffer)X
-1203(headers)X
-1474(contain)X
-1735(modi\256ed)X
-2043(bits,)X
-2202(the)X
-2324(page)X
-720 1356(address)N
-995(of)X
-1096(the)X
-1228(buffer,)X
-1479(a)X
-1548(pointer)X
-1808(to)X
-1903(the)X
-2034(actual)X
-2259(buffer,)X
-720 1444(and)N
-875(a)X
-950(pointer)X
-1216(to)X
-1317(the)X
-1454(buffer)X
-1690(header)X
-1944(for)X
-2077(an)X
-2191(over\257ow)X
-720 1532(page)N
-901(if)X
-979(it)X
-1052(exists,)X
-1283(in)X
-1374(addition)X
-1665(to)X
-1756(the)X
-1883(LRU)X
-2072(links.)X
-2296(If)X
-2378(the)X
-720 1620(buffer)N
-950(corresponding)X
-1442(to)X
-1537(a)X
-1606(particular)X
-1947(bucket)X
-2194(is)X
-2280(not)X
-2414(in)X
-720 1708(memory,)N
-1048(its)X
-1164(pointer)X
-1432(is)X
-1526(NULL.)X
-1801(In)X
-1909(effect,)X
-2154(pages)X
-2377(are)X
-720 1796(linked)N
-950(in)X
-1042(three)X
-1233(ways.)X
-1468(Using)X
-1689(the)X
-1817(buffer)X
-2043(headers,)X
-2338(they)X
-720 1884(are)N
-851(linked)X
-1083(physically)X
-1444(through)X
-1725(the)X
-1854(LRU)X
-2045(links)X
-2231(and)X
-2378(the)X
-720 1972(over\257ow)N
-1036(links.)X
-1241(Using)X
-1462(the)X
-1590(pages)X
-1803(themselves,)X
-2209(they)X
-2377(are)X
-720 2060(linked)N
-943(logically)X
-1246(through)X
-1518(the)X
-1639(over\257ow)X
-1946(addresses)X
-2276(on)X
-2378(the)X
-720 2148(page.)N
-948(Since)X
-1162(over\257ow)X
-1482(pages)X
-1700(are)X
-1834(accessed)X
-2151(only)X
-2328(after)X
-720 2236(their)N
-904(predecessor)X
-1321(pages,)X
-1560(they)X
-1734(are)X
-1869(removed)X
-2186(from)X
-2378(the)X
-720 2324(buffer)N
-937(pool)X
-1099(when)X
-1293(their)X
-1460(primary)X
-1734(is)X
-1807(removed.)X
-10 f
-720 2412 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-1 Dt
-2309 3177 MXY
-24 15 Dl
--8 -15 Dl
-8 -15 Dl
--24 15 Dl
-52 0 Dl
-789 3160 MXY
--35 0 Dl
-0 -156 Dl
-1607 0 Dl
-0 173 Dl
-789 3091 MXY
--24 -15 Dl
-9 15 Dl
--9 15 Dl
-24 -15 Dl
--69 0 Dl
-2309 3125 MXY
-104 0 Dl
-0 -155 Dl
--1693 0 Dl
-0 121 Dl
-927 3160 MXY
-24 15 Dl
--9 -15 Dl
-9 -15 Dl
--24 15 Dl
-553 0 Dl
-1618 3177 MXY
-8 27 Dl
-4 -17 Dl
-16 -6 Dl
--28 -4 Dl
-138 121 Dl
-1895 3315 MXY
-28 3 Dl
--15 -9 Dl
-1 -18 Dl
--14 24 Dl
-276 -138 Dl
-3108 MY
--28 -3 Dl
-15 10 Dl
--1 17 Dl
-14 -24 Dl
--276 138 Dl
-1756 3229 MXY
--8 -27 Dl
--3 17 Dl
--16 6 Dl
-27 4 Dl
--138 -121 Dl
-1480 MX
--24 -15 Dl
-9 15 Dl
--9 15 Dl
-24 -15 Dl
--553 0 Dl
-3 f
-5 s
-1083 3073(LRU)N
-1178(chain)X
-4 Ds
-1402 3851 MXY
- 1402 3851 lineto
- 1471 3851 lineto
- 1471 3920 lineto
- 1402 3920 lineto
- 1402 3851 lineto
-closepath 19 1402 3851 1471 3920 Dp
-1445 3747(Over\257ow)N
-1613(Address)X
-1549 3609 MXY
-0 69 Dl
-1756 MX
--23 -15 Dl
-8 15 Dl
--8 15 Dl
-23 -15 Dl
--207 0 Dl
--1 Ds
-3 Dt
-1756 3419 MXY
--6 -28 Dl
--4 17 Dl
--17 5 Dl
-27 6 Dl
--138 -138 Dl
-2240 3471 MXY
-15 -24 Dl
--15 9 Dl
--15 -9 Dl
-15 24 Dl
-0 -138 Dl
-1826 3609 MXY
-15 -24 Dl
--15 9 Dl
--16 -9 Dl
-16 24 Dl
-0 -138 Dl
-1549 MX
-15 -24 Dl
--15 9 Dl
--15 -9 Dl
-15 24 Dl
-0 -138 Dl
-858 3471 MXY
-15 -24 Dl
--15 9 Dl
--15 -9 Dl
-15 24 Dl
-0 -138 Dl
-2240 3056 MXY
-15 -24 Dl
--15 9 Dl
--15 -9 Dl
-15 24 Dl
-0 -138 Dl
-1549 3056 MXY
-15 -24 Dl
--15 9 Dl
--15 -9 Dl
-15 24 Dl
-0 -138 Dl
-858 3056 MXY
-15 -24 Dl
--15 9 Dl
--15 -9 Dl
-15 24 Dl
-0 -138 Dl
-1 Dt
-2171 3471 MXY
- 2171 3471 lineto
- 2448 3471 lineto
- 2448 3609 lineto
- 2171 3609 lineto
- 2171 3471 lineto
-closepath 19 2171 3471 2448 3609 Dp
-1756 3609 MXY
- 1756 3609 lineto
- 2033 3609 lineto
- 2033 3747 lineto
- 1756 3747 lineto
- 1756 3609 lineto
-closepath 3 1756 3609 2033 3747 Dp
-1480 3471 MXY
- 1480 3471 lineto
- 1756 3471 lineto
- 1756 3609 lineto
- 1480 3609 lineto
- 1480 3471 lineto
-closepath 19 1480 3471 1756 3609 Dp
-789 MX
- 789 3471 lineto
- 1065 3471 lineto
- 1065 3609 lineto
- 789 3609 lineto
- 789 3471 lineto
-closepath 19 789 3471 1065 3609 Dp
-962 3903(Buffer)N
-1083(Header)X
-849 3851 MXY
- 849 3851 lineto
- 918 3851 lineto
- 918 3920 lineto
- 849 3920 lineto
- 849 3851 lineto
-closepath 14 849 3851 918 3920 Dp
-1756 3194 MXY
- 1756 3194 lineto
- 1895 3194 lineto
- 1895 3471 lineto
- 1756 3471 lineto
- 1756 3194 lineto
-closepath 14 1756 3194 1895 3471 Dp
-2171 3056 MXY
- 2171 3056 lineto
- 2309 3056 lineto
- 2309 3333 lineto
- 2171 3333 lineto
- 2171 3056 lineto
-closepath 14 2171 3056 2309 3333 Dp
-1480 MX
- 1480 3056 lineto
- 1618 3056 lineto
- 1618 3333 lineto
- 1480 3333 lineto
- 1480 3056 lineto
-closepath 14 1480 3056 1618 3333 Dp
-789 MX
- 789 3056 lineto
- 927 3056 lineto
- 927 3333 lineto
- 789 3333 lineto
- 789 3056 lineto
-closepath 14 789 3056 927 3333 Dp
-2780 MY
-0 138 Dl
-138 0 Dl
-0 -138 Dl
--138 0 Dl
-927 MX
-0 138 Dl
-138 0 Dl
-0 -138 Dl
--138 0 Dl
-1065 MX
-0 138 Dl
-138 0 Dl
-0 -138 Dl
--138 0 Dl
-1203 MX
-0 138 Dl
-139 0 Dl
-0 -138 Dl
--139 0 Dl
-1342 MX
-0 138 Dl
-138 0 Dl
-0 -138 Dl
--138 0 Dl
-1480 MX
-0 138 Dl
-138 0 Dl
-0 -138 Dl
--138 0 Dl
-1618 MX
-0 138 Dl
-138 0 Dl
-0 -138 Dl
--138 0 Dl
-1756 MX
-0 138 Dl
-139 0 Dl
-0 -138 Dl
--139 0 Dl
-1895 MX
-0 138 Dl
-138 0 Dl
-0 -138 Dl
--138 0 Dl
-2033 MX
-0 138 Dl
-138 0 Dl
-0 -138 Dl
--138 0 Dl
-2171 MX
-0 138 Dl
-138 0 Dl
-0 -138 Dl
--138 0 Dl
-2309 MX
-0 138 Dl
-139 0 Dl
-0 -138 Dl
--139 0 Dl
-13 s
-1048 2720(In)N
-1173(Memory)X
-1580(Bucket)X
-1918(Array)X
-867 3584(B0)N
-1558(B5)X
-2223(B10)X
-1788 3722(O1/1)N
-5 s
-1515 3903(Primay)N
-1651(Buffer)X
-4 Ds
-1990 3851 MXY
- 1990 3851 lineto
- 2059 3851 lineto
- 2059 3920 lineto
- 1990 3920 lineto
- 1990 3851 lineto
-closepath 3 1990 3851 2059 3920 Dp
-2102 3903(Over\257ow)N
-2270(Buffer)X
-3 Dt
--1 Ds
-8 s
-720 4184(Figure)N
-922(4:)X
-1 f
-996(Three)X
-1164(primary)X
-1386(pages)X
-1551(\(B0,)X
-1683(B5,)X
-1794(B10\))X
-1942(are)X
-2039(accessed)X
-2281(directly)X
-720 4272(from)N
-862(the)X
-958(bucket)X
-1146(array.)X
-1326(The)X
-1443(one)X
-1553(over\257ow)X
-1798(page)X
-1935(\(O1/1\))X
-2122(is)X
-2182(linked)X
-2359(phy-)X
-720 4360(sically)N
-915(from)X
-1067(its)X
-1155(primary)X
-1384(page's)X
-1577(buffer)X
-1759(header)X
-1955(as)X
-2035(well)X
-2172(as)X
-2252(logically)X
-720 4448(from)N
-860(its)X
-937(predecessor)X
-1253(page)X
-1389(buffer)X
-1560(\(B5\).)X
-10 s
-10 f
-720 4624 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-3 f
-1191 4954(Table)N
-1406(Parameterization)X
-1 f
-892 5086(When)N
-1107(a)X
-1166(hash)X
-1336(table)X
-1515(is)X
-1590(created,)X
-1865(the)X
-1985(bucket)X
-2221(size,)X
-2388(\256ll)X
-720 5174(factor,)N
-953(initial)X
-1164(number)X
-1434(of)X
-1526(elements,)X
-1856(number)X
-2125(of)X
-2216(bytes)X
-2409(of)X
-720 5262(main)N
-919(memory)X
-1225(used)X
-1411(for)X
-1543(caching,)X
-1851(and)X
-2005(a)X
-2079(user-de\256ned)X
-720 5350(hash)N
-892(function)X
-1184(may)X
-1347(be)X
-1448(speci\256ed.)X
-1797(The)X
-1946(bucket)X
-2184(size)X
-2333(\(and)X
-720 5438(page)N
-906(size)X
-1064(for)X
-1191(over\257ow)X
-1509(pages\))X
-1752(defaults)X
-2039(to)X
-2134(256)X
-2287(bytes.)X
-720 5526(For)N
-858(tables)X
-1072(with)X
-1241(large)X
-1429(data)X
-1590(items,)X
-1810(it)X
-1881(may)X
-2046(be)X
-2149(preferable)X
-720 5614(to)N
-803(increase)X
-1088(the)X
-1207(page)X
-1380(size,)X
-1545(and,)X
-1701(conversely,)X
-2089(applications)X
-720 5702(storing)N
-1002(small)X
-1235(items)X
-1467(exclusively)X
-1891(in)X
-2012(memory)X
-2338(may)X
-2706 538(bene\256t)N
-2966(from)X
-3164(a)X
-3242(smaller)X
-3520(bucket)X
-3776(size.)X
-3983(A)X
-4082(bucket)X
-4337(size)X
-2706 626(smaller)N
-2962(than)X
-3120(64)X
-3220(bytes)X
-3409(is)X
-3482(not)X
-3604(recommended.)X
-2878 740(The)N
-3031(\256ll)X
-3147(factor)X
-3363(indicates)X
-3676(a)X
-3740(desired)X
-4000(density)X
-4258(within)X
-2706 828(the)N
-2833(hash)X
-3009(table.)X
-3234(It)X
-3312(is)X
-3394(an)X
-3499(approximation)X
-3995(of)X
-4091(the)X
-4217(number)X
-2706 916(of)N
-2815(keys)X
-3004(allowed)X
-3300(to)X
-3404(accumulate)X
-3811(in)X
-3914(any)X
-4071(one)X
-4228(bucket,)X
-2706 1004(determining)N
-3119(when)X
-3319(the)X
-3442(hash)X
-3614(table)X
-3795(grows.)X
-4056(Its)X
-4161(default)X
-4409(is)X
-2706 1092(eight.)N
-2953(If)X
-3054(the)X
-3199(user)X
-3380(knows)X
-3636(the)X
-3781(average)X
-4079(size)X
-4251(of)X
-4364(the)X
-2706 1180(key/data)N
-3008(pairs)X
-3194(being)X
-3402(stored)X
-3627(in)X
-3718(the)X
-3845(table,)X
-4050(near)X
-4218(optimal)X
-2706 1268(bucket)N
-2943(sizes)X
-3122(and)X
-3261(\256ll)X
-3372(factors)X
-3614(may)X
-3775(be)X
-3874(selected)X
-4155(by)X
-4257(apply-)X
-2706 1356(ing)N
-2828(the)X
-2946(equation:)X
-0 f
-8 s
-2706 1655(\(1\))N
-2994 -0.3938(\(\(average_pair_length)AX
-3830(+)X
-3906(4\))X
-4020(*)X
-3032 1743(ffactor\))N
-3374(>=)X
-3488(bsize)X
-1 f
-10 s
-2706 2042(For)N
-2859(highly)X
-3104(time)X
-3287(critical)X
-3551(applications,)X
-3999(experimenting)X
-2706 2130(with)N
-2919(different)X
-3266(bucket)X
-3550(sizes)X
-3776(and)X
-3962(\256ll)X
-4120(factors)X
-4409(is)X
-2706 2218(encouraged.)N
-2878 2332(Figures)N
-3144(5a,b,)X
-3326(and)X
-3468(c)X
-3530(illustrate)X
-3836(the)X
-3960(effects)X
-4200(of)X
-4292(vary-)X
-2706 2420(ing)N
-2841(page)X
-3026(sizes)X
-3215(and)X
-3363(\256ll)X
-3483(factors)X
-3734(for)X
-3860(the)X
-3990(same)X
-4187(data)X
-4353(set.)X
-2706 2508(The)N
-2864(data)X
-3031(set)X
-3152(consisted)X
-3482(of)X
-3581(24474)X
-3813(keys)X
-3992(taken)X
-4198(from)X
-4386(an)X
-2706 2596(online)N
-2931(dictionary.)X
-3301(The)X
-3451(data)X
-3609(value)X
-3807(for)X
-3925(each)X
-4097(key)X
-4237(was)X
-4386(an)X
-2706 2684(ASCII)N
-2938(string)X
-3143(for)X
-3260(an)X
-3359(integer)X
-3605(from)X
-3784(1)X
-3847(to)X
-3931(24474)X
-4153(inclusive.)X
-2706 2772(The)N
-2867(test)X
-3013(run)X
-3155(consisted)X
-3488(of)X
-3590(creating)X
-3884(a)X
-3955(new)X
-4124(hash)X
-4306(table)X
-2706 2860(\(where)N
-2966(the)X
-3100(ultimate)X
-3398(size)X
-3559(of)X
-3662(the)X
-3796(table)X
-3987(was)X
-4147(known)X
-4400(in)X
-2706 2948(advance\),)N
-3054(entering)X
-3354(each)X
-3539(key/data)X
-3848(pair)X
-4010(into)X
-4171(the)X
-4306(table)X
-2706 3036(and)N
-2849(then)X
-3014(retrieving)X
-3353(each)X
-3528(key/data)X
-3827(pair)X
-3979(from)X
-4162(the)X
-4286(table.)X
-2706 3124(Each)N
-2898(of)X
-2996(the)X
-3125(graphs)X
-3369(shows)X
-3599(the)X
-3727(timings)X
-3996(resulting)X
-4306(from)X
-2706 3212(varying)N
-2973(the)X
-3093(pagesize)X
-3392(from)X
-3570(128)X
-3712(bytes)X
-3903(to)X
-3986(1M)X
-4118(and)X
-4255(the)X
-4374(\256ll)X
-2706 3300(factor)N
-2929(from)X
-3120(1)X
-3195(to)X
-3292(128.)X
-3486(For)X
-3631(each)X
-3813(run,)X
-3974(the)X
-4106(buffer)X
-4337(size)X
-2706 3388(was)N
-2874(set)X
-3006(at)X
-3106(1M.)X
-3299(The)X
-3466(tests)X
-3650(were)X
-3849(all)X
-3971(run)X
-4120(on)X
-4242(an)X
-4360(HP)X
-2706 3476(9000/370)N
-3077(\(33.3)X
-3312(Mhz)X
-3527(MC68030\),)X
-3966(with)X
-4176(16M)X
-4395(of)X
-2706 3564(memory,)N
-3042(64K)X
-3228(physically)X
-3605(addressed)X
-3970(cache,)X
-4222(and)X
-4386(an)X
-2706 3652(HP7959S)N
-3055(disk)X
-3231(drive,)X
-3459(running)X
-3751(4.3BSD-Reno)X
-4244(single-)X
-2706 3740(user.)N
-2878 3854(Both)N
-3066(system)X
-3321(time)X
-3496(\(Figure)X
-3764(5a\))X
-3899(and)X
-4047(elapsed)X
-4320(time)X
-2706 3942(\(Figure)N
-2966(5b\))X
-3097(show)X
-3290(that)X
-3434(for)X
-3552(all)X
-3655(bucket)X
-3892(sizes,)X
-4091(the)X
-4212(greatest)X
-2706 4030(performance)N
-3137(gains)X
-3329(are)X
-3451(made)X
-3648(by)X
-3751(increasing)X
-4104(the)X
-4225(\256ll)X
-4336(fac-)X
-2706 4118(tor)N
-2822(until)X
-2995(equation)X
-3298(1)X
-3365(is)X
-3445(satis\256ed.)X
-3774(The)X
-3925(user)X
-4085(time)X
-4253(shown)X
-2706 4206(in)N
-2791(Figure)X
-3023(5c)X
-3122(gives)X
-3314(a)X
-3373(more)X
-3561(detailed)X
-3838(picture)X
-4083(of)X
-4172(how)X
-4332(per-)X
-2706 4294(formance)N
-3054(varies.)X
-3330(The)X
-3499(smaller)X
-3778(bucket)X
-4035(sizes)X
-4234(require)X
-2706 4382(fewer)N
-2921(keys)X
-3099(per)X
-3233(page)X
-3416(to)X
-3509(satisfy)X
-3749(equation)X
-4056(1)X
-4127(and)X
-4274(there-)X
-2706 4470(fore)N
-2860(incur)X
-3049(fewer)X
-3257(collisions.)X
-3607(However,)X
-3946(when)X
-4144(the)X
-4265(buffer)X
-2706 4558(pool)N
-2884(size)X
-3045(is)X
-3134(\256xed,)X
-3349(smaller)X
-3620(pages)X
-3838(imply)X
-4059(more)X
-4259(pages.)X
-2706 4646(An)N
-2830(increased)X
-3160(number)X
-3430(of)X
-3522(pages)X
-3730(means)X
-3960(more)X
-2 f
-4150(malloc\(3\))X
-1 f
-2706 4734(calls)N
-2879(and)X
-3021(more)X
-3212(overhead)X
-3533(in)X
-3621(the)X
-3745(hash)X
-3918(package's)X
-4265(buffer)X
-2706 4822(manager)N
-3003(to)X
-3085(manage)X
-3355(the)X
-3473(additional)X
-3813(pages.)X
-2878 4936(The)N
-3028(tradeoff)X
-3308(works)X
-3529(out)X
-3655(most)X
-3834(favorably)X
-4166(when)X
-4364(the)X
-2706 5024(page)N
-2886(size)X
-3039(is)X
-3120(256)X
-3268(and)X
-3412(the)X
-3538(\256ll)X
-3654(factor)X
-3870(is)X
-3950(8.)X
-4057(Similar)X
-4319(con-)X
-2706 5112(clusions)N
-3009(were)X
-3207(obtained)X
-3524(if)X
-3614(the)X
-3753(test)X
-3905(was)X
-4071(run)X
-4218(without)X
-2706 5200(knowing)N
-3007(the)X
-3126(\256nal)X
-3289(table)X
-3466(size)X
-3612(in)X
-3695(advance.)X
-4020(If)X
-4095(the)X
-4214(\256le)X
-4337(was)X
-2706 5288(closed)N
-2942(and)X
-3088(written)X
-3345(to)X
-3437(disk,)X
-3620(the)X
-3748(conclusions)X
-4156(were)X
-4343(still)X
-2706 5376(the)N
-2832(same.)X
-3065(However,)X
-3408(rereading)X
-3740(the)X
-3865(\256le)X
-3994(from)X
-4177(disk)X
-4337(was)X
-2706 5464(slightly)N
-2983(faster)X
-3199(if)X
-3285(a)X
-3358(larger)X
-3583(bucket)X
-3834(size)X
-3996(and)X
-4149(\256ll)X
-4274(factor)X
-2706 5552(were)N
-2898(used)X
-3079(\(1K)X
-3238(bucket)X
-3486(size)X
-3645(and)X
-3795(32)X
-3909(\256ll)X
-4031(factor\).)X
-4320(This)X
-2706 5640(follows)N
-2987(intuitively)X
-3356(from)X
-3553(the)X
-3691(improved)X
-4038(ef\256ciency)X
-4395(of)X
-3 f
-720 5960(USENIX)N
-9 f
-1042(-)X
-3 f
-1106(Winter)X
-1371('91)X
-9 f
-1498(-)X
-3 f
-1562(Dallas,)X
-1815(TX)X
-4424(7)X
-
-8 p
-%%Page: 8 8
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-432 258(A)N
-510(New)X
-682(Hashing)X
-985(Package)X
-1290(for)X
-1413(UNIX)X
-3663(Seltzer)X
-3920(&)X
-4007(Yigit)X
-1 f
-432 538(performing)N
-830(1K)X
-965(reads)X
-1172(from)X
-1365(the)X
-1500(disk)X
-1670(rather)X
-1894(than)X
-2068(256)X
-432 626(byte)N
-609(reads.)X
-857(In)X
-962(general,)X
-1257(performance)X
-1702(for)X
-1834(disk)X
-2005(based)X
-432 714(tables)N
-639(is)X
-712(best)X
-861(when)X
-1055(the)X
-1173(page)X
-1345(size)X
-1490(is)X
-1563(approximately)X
-2046(1K.)X
-10 f
-432 802 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-619 2380 MXY
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-629 2437 MXY
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-648 2504 MXY
--12 25 Dl
-24 0 Dl
--12 -25 Dl
-686 2515 MXY
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-762 2516 MXY
--12 24 Dl
-25 0 Dl
--13 -24 Dl
-916 2515 MXY
--13 24 Dl
-25 0 Dl
--12 -24 Dl
-1222 2516 MXY
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-1834 2515 MXY
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-1 Dt
-619 2392 MXY
-10 57 Dl
-19 67 Dl
-38 11 Dl
-76 1 Dl
-154 -1 Dl
-306 1 Dl
-612 -1 Dl
-8 s
-1 f
-1628 2522(128)N
-3 Dt
-607 2245 MXY
-24 Dc
-617 2375 MXY
-23 Dc
-635 2442 MXY
-24 Dc
-674 2525 MXY
-23 Dc
-750 2529 MXY
-24 Dc
-904 2527 MXY
-23 Dc
-1210 MX
-23 Dc
-1822 2528 MXY
-23 Dc
-20 Ds
-1 Dt
-619 2245 MXY
-10 130 Dl
-19 67 Dl
-38 83 Dl
-76 4 Dl
-154 -2 Dl
-306 0 Dl
-612 1 Dl
-678 2482(256)N
--1 Ds
-3 Dt
-619 2127 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-629 2191 MXY
-0 25 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-648 2334 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-686 2409 MXY
-0 25 Dl
-0 -13 Dl
-12 0 Dl
--24 0 Dl
-762 2516 MXY
-0 25 Dl
-0 -12 Dl
-13 0 Dl
--25 0 Dl
-916 2516 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--25 0 Dl
-1222 2515 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-1834 2515 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-5 Dt
-619 2139 MXY
-10 65 Dl
-19 142 Dl
-38 75 Dl
-76 108 Dl
-154 -1 Dl
-306 -1 Dl
-612 0 Dl
-694 2401(512)N
-3 Dt
-631 2064 MXY
--24 24 Dl
-12 -12 Dl
--12 -12 Dl
-24 24 Dl
-641 2077 MXY
--24 25 Dl
-12 -12 Dl
--12 -13 Dl
-24 25 Dl
-660 2132 MXY
--24 24 Dl
-12 -12 Dl
--12 -12 Dl
-24 24 Dl
-698 2292 MXY
--24 24 Dl
-12 -12 Dl
--12 -12 Dl
-24 24 Dl
-775 2382 MXY
--25 24 Dl
-12 -12 Dl
--12 -12 Dl
-25 24 Dl
-928 2516 MXY
--25 24 Dl
-13 -12 Dl
--13 -12 Dl
-25 24 Dl
-1234 2516 MXY
--24 25 Dl
-12 -12 Dl
--12 -13 Dl
-24 25 Dl
-1846 2516 MXY
--24 24 Dl
-12 -12 Dl
--12 -12 Dl
-24 24 Dl
-16 Ds
-1 Dt
-619 2076 MXY
-10 14 Dl
-19 54 Dl
-38 160 Dl
-76 90 Dl
-154 134 Dl
-306 1 Dl
-612 -1 Dl
-694 2257(1024)N
--1 Ds
-3 Dt
-619 1877 MXY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-629 1855 MXY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-648 1838 MXY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-686 1860 MXY
-12 -25 Dl
--24 0 Dl
-12 25 Dl
-762 1923 MXY
-13 -24 Dl
--25 0 Dl
-12 24 Dl
-916 2087 MXY
-12 -24 Dl
--25 0 Dl
-13 24 Dl
-1222 2256 MXY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-1834 2541 MXY
-12 -25 Dl
--24 0 Dl
-12 25 Dl
-619 1865 MXY
-10 -22 Dl
-19 -17 Dl
-38 21 Dl
-76 64 Dl
-154 164 Dl
-306 169 Dl
-612 285 Dl
-1645 2427(4096)N
-619 1243 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-629 1196 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-648 1146 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-686 1174 MXY
-0 25 Dl
-0 -13 Dl
-12 0 Dl
--24 0 Dl
-762 1249 MXY
-0 24 Dl
-0 -12 Dl
-13 0 Dl
--25 0 Dl
-916 1371 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--25 0 Dl
-1222 1680 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-1834 1999 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-619 1255 MXY
-10 -47 Dl
-19 -50 Dl
-38 28 Dl
-76 75 Dl
-154 122 Dl
-306 309 Dl
-612 319 Dl
-1741 1934(8192)N
-5 Dt
-609 2531 MXY
-1225 0 Dl
-609 MX
-0 -1553 Dl
-2531 MY
-0 16 Dl
-4 Ds
-1 Dt
-2531 MY
-0 -1553 Dl
-593 2625(0)N
--1 Ds
-5 Dt
-916 2531 MXY
-0 16 Dl
-4 Ds
-1 Dt
-2531 MY
-0 -1553 Dl
-884 2625(32)N
--1 Ds
-5 Dt
-1222 2531 MXY
-0 16 Dl
-4 Ds
-1 Dt
-2531 MY
-0 -1553 Dl
-1190 2625(64)N
--1 Ds
-5 Dt
-1528 2531 MXY
-0 16 Dl
-4 Ds
-1 Dt
-2531 MY
-0 -1553 Dl
-1496 2625(96)N
--1 Ds
-5 Dt
-1834 2531 MXY
-0 16 Dl
-4 Ds
-1 Dt
-2531 MY
-0 -1553 Dl
-1786 2625(128)N
--1 Ds
-5 Dt
-609 2531 MXY
--16 0 Dl
-4 Ds
-1 Dt
-609 MX
-1225 0 Dl
-545 2558(0)N
--1 Ds
-5 Dt
-609 2013 MXY
--16 0 Dl
-4 Ds
-1 Dt
-609 MX
-1225 0 Dl
-481 2040(100)N
--1 Ds
-5 Dt
-609 1496 MXY
--16 0 Dl
-4 Ds
-1 Dt
-609 MX
-1225 0 Dl
-481 1523(200)N
--1 Ds
-5 Dt
-609 978 MXY
--16 0 Dl
-4 Ds
-1 Dt
-609 MX
-1225 0 Dl
-481 1005(300)N
-1088 2724(Fill)N
-1194(Factor)X
-422 1611(S)N
-426 1667(e)N
-426 1724(c)N
-424 1780(o)N
-424 1837(n)N
-424 1893(d)N
-428 1949(s)N
-3 Dt
--1 Ds
-3 f
-432 2882(Figure)N
-636(5a:)X
-1 f
-744(System)X
-956(Time)X
-1113(for)X
-1209(dictionary)X
-1490(data)X
-1618(set)X
-1711(with)X
-1847(1M)X
-1958(of)X
-2033(buffer)X
-432 2970(space)N
-594(and)X
-707(varying)X
-923(bucket)X
-1114(sizes)X
-1259(and)X
-1372(\256ll)X
-1465(factors.)X
-1675(Each)X
-1823(line)X
-1940(is)X
-2004(labeled)X
-432 3058(with)N
-562(its)X
-639(bucket)X
-825(size.)X
-10 s
-10 f
-432 3234 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-8 s
-1 f
-428 4381(s)N
-424 4325(d)N
-424 4269(n)N
-424 4212(o)N
-426 4156(c)N
-426 4099(e)N
-422 4043(S)N
-1116 5156(Fill)N
-1222(Factor)X
-506 3437(3200)N
-4 Ds
-1 Dt
-666 3410 MXY
-1168 0 Dl
--1 Ds
-5 Dt
-666 MX
--16 0 Dl
-506 3825(2400)N
-4 Ds
-1 Dt
-666 3799 MXY
-1168 0 Dl
--1 Ds
-5 Dt
-666 MX
--16 0 Dl
-506 4214(1600)N
-4 Ds
-1 Dt
-666 4186 MXY
-1168 0 Dl
--1 Ds
-5 Dt
-666 MX
--16 0 Dl
-538 4602(800)N
-4 Ds
-1 Dt
-666 4575 MXY
-1168 0 Dl
--1 Ds
-5 Dt
-666 MX
--16 0 Dl
-602 4990(0)N
-4 Ds
-1 Dt
-666 4963 MXY
-1168 0 Dl
--1 Ds
-5 Dt
-666 MX
--16 0 Dl
-1786 5057(128)N
-4 Ds
-1 Dt
-1834 4963 MXY
-0 -1553 Dl
--1 Ds
-5 Dt
-4963 MY
-0 16 Dl
-1510 5057(96)N
-4 Ds
-1 Dt
-1542 4963 MXY
-0 -1553 Dl
--1 Ds
-5 Dt
-4963 MY
-0 16 Dl
-1218 5057(64)N
-4 Ds
-1 Dt
-1250 4963 MXY
-0 -1553 Dl
--1 Ds
-5 Dt
-4963 MY
-0 16 Dl
-926 5057(32)N
-4 Ds
-1 Dt
-958 4963 MXY
-0 -1553 Dl
--1 Ds
-5 Dt
-4963 MY
-0 16 Dl
-650 5057(0)N
-4 Ds
-1 Dt
-666 4963 MXY
-0 -1553 Dl
--1 Ds
-5 Dt
-4963 MY
-0 16 Dl
-4963 MY
-0 -1553 Dl
-4963 MY
-1168 0 Dl
-1741 4752(8192)N
-3 Dt
-675 3732 MXY
-9 -172 Dl
-18 -118 Dl
-37 128 Dl
-73 -121 Dl
-146 623 Dl
-292 497 Dl
-584 245 Dl
-4802 MY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-1250 4557 MXY
-0 25 Dl
-0 -13 Dl
-12 0 Dl
--24 0 Dl
-958 4060 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-812 3437 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-739 3558 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-702 3430 MXY
-0 25 Dl
-0 -13 Dl
-13 0 Dl
--25 0 Dl
-684 3548 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-675 3720 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-1637 4912(4096)N
-675 4307 MXY
-9 -58 Dl
-18 30 Dl
-37 89 Dl
-73 144 Dl
-146 235 Dl
-292 122 Dl
-584 89 Dl
-4970 MY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-1250 4881 MXY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-958 4759 MXY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-812 4524 MXY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-739 4380 MXY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-702 4291 MXY
-13 -24 Dl
--25 0 Dl
-12 24 Dl
-684 4261 MXY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-675 4319 MXY
-12 -24 Dl
--24 0 Dl
-12 24 Dl
-734 4662(1024)N
-16 Ds
-1 Dt
-675 4352 MXY
-9 60 Dl
-18 134 Dl
-37 266 Dl
-73 117 Dl
-146 30 Dl
-292 0 Dl
-584 -1 Dl
--1 Ds
-3 Dt
-1846 4946 MXY
--24 24 Dl
-12 -12 Dl
--12 -12 Dl
-24 24 Dl
-1262 4946 MXY
--24 25 Dl
-12 -12 Dl
--12 -13 Dl
-24 25 Dl
-970 4947 MXY
--24 24 Dl
-12 -12 Dl
--12 -12 Dl
-24 24 Dl
-824 4917 MXY
--24 24 Dl
-12 -12 Dl
--12 -12 Dl
-24 24 Dl
-751 4800 MXY
--24 24 Dl
-12 -12 Dl
--12 -12 Dl
-24 24 Dl
-715 4534 MXY
--25 25 Dl
-12 -13 Dl
--12 -12 Dl
-25 25 Dl
-696 4400 MXY
--24 24 Dl
-12 -12 Dl
--12 -12 Dl
-24 24 Dl
-687 4339 MXY
--24 25 Dl
-12 -12 Dl
--12 -13 Dl
-24 25 Dl
-718 4792(512)N
-5 Dt
-675 4422 MXY
-9 137 Dl
-18 278 Dl
-37 105 Dl
-73 18 Dl
-146 -1 Dl
-292 0 Dl
-584 -1 Dl
-3 Dt
-4946 MY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-1250 4946 MXY
-0 25 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-958 4947 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-812 4948 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-739 4930 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-702 4824 MXY
-0 25 Dl
-0 -12 Dl
-13 0 Dl
--25 0 Dl
-684 4547 MXY
-0 24 Dl
-0 -12 Dl
-12 0 Dl
--24 0 Dl
-675 4410 MXY
-0 25 Dl
-0 -13 Dl
-12 0 Dl
--24 0 Dl
-750 4921(256)N
-20 Ds
-1 Dt
-675 4597 MXY
-9 246 Dl
-18 106 Dl
-37 10 Dl
-73 0 Dl
-146 0 Dl
-292 0 Dl
-584 -1 Dl
--1 Ds
-3 Dt
-1822 MX
-23 Dc
-1238 4959 MXY
-23 Dc
-946 MX
-23 Dc
-800 MX
-23 Dc
-727 MX
-23 Dc
-691 4949 MXY
-23 Dc
-672 4843 MXY
-24 Dc
-663 4597 MXY
-24 Dc
-1395 4961(128)N
-1 Dt
-675 4855 MXY
-9 93 Dl
-18 10 Dl
-37 1 Dl
-73 0 Dl
-146 -1 Dl
-292 0 Dl
-584 0 Dl
-3 Dt
-4946 MY
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-1250 MX
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-958 MX
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-812 MX
--12 25 Dl
-24 0 Dl
--12 -25 Dl
-739 4947 MXY
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-702 4946 MXY
--12 24 Dl
-25 0 Dl
--13 -24 Dl
-684 4936 MXY
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-675 4843 MXY
--12 24 Dl
-24 0 Dl
--12 -24 Dl
-3 Dt
--1 Ds
-3 f
-432 5314(Figure)N
-634(5b:)X
-1 f
-744(Elapsed)X
-967(Time)X
-1123(for)X
-1218(dictionary)X
-1498(data)X
-1625(set)X
-1717(with)X
-1851(1M)X
-1960(of)X
-2033(buffer)X
-432 5402(space)N
-593(and)X
-705(varying)X
-920(bucket)X
-1110(sizes)X
-1254(and)X
-1366(\256ll)X
-1457(factors.)X
-1681(Each)X
-1827(line)X
-1942(is)X
-2004(labeled)X
-432 5490(with)N
-562(its)X
-639(bucket)X
-825(size.)X
-10 s
-2590 538(If)N
-2677(an)X
-2785(approximation)X
-3284(of)X
-3383(the)X
-3513(number)X
-3790(of)X
-3889(elements)X
-2418 626(ultimately)N
-2773(to)X
-2866(be)X
-2973(stored)X
-3200(in)X
-3293(the)X
-3422(hash)X
-3599(table)X
-3785(is)X
-3868(known)X
-4116(at)X
-2418 714(the)N
-2564(time)X
-2754(of)X
-2869(creation,)X
-3196(the)X
-3342(hash)X
-3536(package)X
-3847(takes)X
-4059(this)X
-2418 802(number)N
-2688(as)X
-2779(a)X
-2839(parameter)X
-3185(and)X
-3325(uses)X
-3487(it)X
-3555(to)X
-3641(hash)X
-3812(entries)X
-4050(into)X
-2418 890(the)N
-2541(full)X
-2677(sized)X
-2867(table)X
-3048(rather)X
-3261(than)X
-3424(growing)X
-3716(the)X
-3838(table)X
-4018(from)X
-2418 978(a)N
-2477(single)X
-2691(bucket.)X
-2968(If)X
-3044(this)X
-3181(number)X
-3448(is)X
-3523(not)X
-3647(known,)X
-3907(the)X
-4027(hash)X
-2418 1066(table)N
-2632(starts)X
-2859(with)X
-3059(a)X
-3153(single)X
-3402(bucket)X
-3674(and)X
-3848(gracefully)X
-2418 1154(expands)N
-2707(as)X
-2800(elements)X
-3111(are)X
-3236(added,)X
-3474(although)X
-3780(a)X
-3842(slight)X
-4044(per-)X
-2418 1242(formance)N
-2747(degradation)X
-3151(may)X
-3313(be)X
-3413(noticed.)X
-3713(Figure)X
-3946(6)X
-4010(illus-)X
-2418 1330(trates)N
-2625(the)X
-2756(difference)X
-3116(in)X
-3211(performance)X
-3651(between)X
-3952(storing)X
-2418 1418(keys)N
-2588(in)X
-2673(a)X
-2732(\256le)X
-2857(when)X
-3054(the)X
-3174(ultimate)X
-3458(size)X
-3605(is)X
-3680(known)X
-3920(\(the)X
-4067(left)X
-2418 1506(bars)N
-2581(in)X
-2672(each)X
-2849(set\),)X
-3014(compared)X
-3360(to)X
-3450(building)X
-3744(the)X
-3870(\256le)X
-4000(when)X
-2418 1594(the)N
-2550(ultimate)X
-2846(size)X
-3005(is)X
-3091(unknown)X
-3422(\(the)X
-3580(right)X
-3764(bars)X
-3931(in)X
-4026(each)X
-2418 1682(set\).)N
-2609(Once)X
-2814(the)X
-2947(\256ll)X
-3069(factor)X
-3291(is)X
-3378(suf\256ciently)X
-3772(high)X
-3948(for)X
-4076(the)X
-2418 1770(page)N
-2596(size)X
-2747(\(8\),)X
-2887(growing)X
-3180(the)X
-3304(table)X
-3486(dynamically)X
-3908(does)X
-4081(lit-)X
-2418 1858(tle)N
-2518(to)X
-2600(degrade)X
-2875(performance.)X
-10 f
-2418 1946 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-9 s
-1 f
-2413 3238(s)N
-2409 3173(d)N
-2409 3108(n)N
-2409 3043(o)N
-2411 2979(c)N
-2411 2914(e)N
-2407 2849(S)N
-3143 4129(Fill)N
-3261(Factor)X
-2448 2152(15)N
-4 Ds
-1 Dt
-2557 2122 MXY
-1473 0 Dl
--1 Ds
-5 Dt
-2557 MX
--19 0 Dl
-2448 2747(10)N
-4 Ds
-1 Dt
-2557 2717 MXY
-1473 0 Dl
--1 Ds
-5 Dt
-2557 MX
--19 0 Dl
-2484 3343(5)N
-4 Ds
-1 Dt
-2557 3313 MXY
-1473 0 Dl
--1 Ds
-5 Dt
-2557 MX
--19 0 Dl
-2484 3938(0)N
-4 Ds
-1 Dt
-2557 3908 MXY
-1473 0 Dl
--1 Ds
-5 Dt
-2557 MX
--19 0 Dl
-3976 4015(128)N
-4 Ds
-1 Dt
-4030 3908 MXY
-0 -1786 Dl
--1 Ds
-5 Dt
-3908 MY
-0 19 Dl
-3626 4015(96)N
-4 Ds
-1 Dt
-3662 3908 MXY
-0 -1786 Dl
--1 Ds
-5 Dt
-3908 MY
-0 19 Dl
-3258 4015(64)N
-4 Ds
-1 Dt
-3294 3908 MXY
-0 -1786 Dl
--1 Ds
-5 Dt
-3908 MY
-0 19 Dl
-2889 4015(32)N
-4 Ds
-1 Dt
-2925 3908 MXY
-0 -1786 Dl
--1 Ds
-5 Dt
-3908 MY
-0 19 Dl
-2539 4015(0)N
-4 Ds
-1 Dt
-2557 3908 MXY
-0 -1786 Dl
--1 Ds
-5 Dt
-3908 MY
-0 19 Dl
-3908 MY
-0 -1786 Dl
-3908 MY
-1473 0 Dl
-4053 2378(8192)N
-3 Dt
-2569 2277 MXY
-11 0 Dl
-23 48 Dl
-46 -167 Dl
-92 35 Dl
-184 12 Dl
-369 143 Dl
-736 0 Dl
-2334 MY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-3294 2334 MXY
-0 28 Dl
-0 -14 Dl
-13 0 Dl
--27 0 Dl
-2925 2192 MXY
-0 27 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-2741 2180 MXY
-0 27 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-2649 2144 MXY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-2603 2311 MXY
-0 27 Dl
-0 -13 Dl
-14 0 Dl
--28 0 Dl
-2580 2263 MXY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-2569 2263 MXY
-0 28 Dl
-0 -14 Dl
-13 0 Dl
--27 0 Dl
-4053 2591(4096)N
-2569 2348 MXY
-11 -11 Dl
-23 -96 Dl
-46 71 Dl
-92 72 Dl
-184 226 Dl
-369 48 Dl
-736 -60 Dl
-2612 MY
-14 -28 Dl
--28 0 Dl
-14 28 Dl
-3294 2672 MXY
-13 -28 Dl
--27 0 Dl
-14 28 Dl
-2925 2624 MXY
-14 -28 Dl
--28 0 Dl
-14 28 Dl
-2741 2398 MXY
-14 -28 Dl
--28 0 Dl
-14 28 Dl
-2649 2326 MXY
-14 -27 Dl
--28 0 Dl
-14 27 Dl
-2603 2255 MXY
-14 -28 Dl
--28 0 Dl
-14 28 Dl
-2580 2350 MXY
-14 -27 Dl
--28 0 Dl
-14 27 Dl
-2569 2362 MXY
-13 -28 Dl
--27 0 Dl
-14 28 Dl
-4053 2681(1024)N
-16 Ds
-1 Dt
-2569 2300 MXY
-11 48 Dl
-23 96 Dl
-46 95 Dl
-92 274 Dl
-184 202 Dl
-369 -155 Dl
-736 -190 Dl
--1 Ds
-3 Dt
-4044 2656 MXY
--28 28 Dl
-14 -14 Dl
--14 -14 Dl
-28 28 Dl
-3307 2846 MXY
--27 28 Dl
-14 -14 Dl
--14 -14 Dl
-27 28 Dl
-2939 3001 MXY
--28 28 Dl
-14 -14 Dl
--14 -14 Dl
-28 28 Dl
-2755 2799 MXY
--28 28 Dl
-14 -14 Dl
--14 -14 Dl
-28 28 Dl
-2663 2525 MXY
--28 28 Dl
-14 -14 Dl
--14 -14 Dl
-28 28 Dl
-2617 2430 MXY
--28 28 Dl
-14 -14 Dl
--14 -14 Dl
-28 28 Dl
-2594 2334 MXY
--28 28 Dl
-14 -14 Dl
--14 -14 Dl
-28 28 Dl
-2582 2287 MXY
--27 27 Dl
-14 -14 Dl
--14 -13 Dl
-27 27 Dl
-4053 2851(512)N
-5 Dt
-2569 2372 MXY
-11 -24 Dl
-23 405 Dl
-46 83 Dl
-92 227 Dl
-184 -72 Dl
-369 -119 Dl
-736 -107 Dl
-3 Dt
-2751 MY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-3294 2858 MXY
-0 28 Dl
-0 -14 Dl
-13 0 Dl
--27 0 Dl
-2925 2977 MXY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-2741 3049 MXY
-0 27 Dl
-0 -13 Dl
-14 0 Dl
--28 0 Dl
-2649 2823 MXY
-0 27 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-2603 2739 MXY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-2580 2334 MXY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-2569 2358 MXY
-0 28 Dl
-0 -14 Dl
-13 0 Dl
--27 0 Dl
-4053 2795(256)N
-20 Ds
-1 Dt
-2569 2456 MXY
-11 285 Dl
-23 95 Dl
-46 251 Dl
-92 -60 Dl
-184 -84 Dl
-369 -107 Dl
-736 -71 Dl
--1 Ds
-3 Dt
-4016 MX
-27 Dc
-3280 2836 MXY
-27 Dc
-2912 2943 MXY
-27 Dc
-2728 3027 MXY
-27 Dc
-2635 3087 MXY
-28 Dc
-2589 2836 MXY
-28 Dc
-2566 2741 MXY
-27 Dc
-2554 2456 MXY
-28 Dc
-4053 2741(128)N
-1 Dt
-2569 2729 MXY
-11 203 Dl
-23 131 Dl
-46 -60 Dl
-92 -119 Dl
-184 -60 Dl
-369 -83 Dl
-736 -12 Dl
-3 Dt
-2716 MY
--14 27 Dl
-28 0 Dl
--14 -27 Dl
-3294 2727 MXY
--14 28 Dl
-27 0 Dl
--13 -28 Dl
-2925 2811 MXY
--14 27 Dl
-28 0 Dl
--14 -27 Dl
-2741 2870 MXY
--14 28 Dl
-28 0 Dl
--14 -28 Dl
-2649 2989 MXY
--14 28 Dl
-28 0 Dl
--14 -28 Dl
-2603 3049 MXY
--14 27 Dl
-28 0 Dl
--14 -27 Dl
-2580 2918 MXY
--14 28 Dl
-28 0 Dl
--14 -28 Dl
-2569 2716 MXY
--14 27 Dl
-27 0 Dl
--13 -27 Dl
-3 Dt
--1 Ds
-3 f
-8 s
-2418 4286(Figure)N
-2628(5c:)X
-1 f
-2738(User)X
-2887(Time)X
-3051(for)X
-3154(dictionary)X
-3442(data)X
-3577(set)X
-3677(with)X
-3820(1M)X
-3938(of)X
-4019(buffer)X
-2418 4374(space)N
-2579(and)X
-2691(varying)X
-2906(bucket)X
-3096(sizes)X
-3240(and)X
-3352(\256ll)X
-3443(factors.)X
-3667(Each)X
-3813(line)X
-3928(is)X
-3990(labeled)X
-2418 4462(with)N
-2548(its)X
-2625(bucket)X
-2811(size.)X
-10 s
-10 f
-2418 4638 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-1 f
-2590 4840(Since)N
-2796(no)X
-2904(known)X
-3150(hash)X
-3325(function)X
-3620(performs)X
-3938(equally)X
-2418 4928(well)N
-2589(on)X
-2702(all)X
-2815(possible)X
-3110(data,)X
-3297(the)X
-3428(user)X
-3595(may)X
-3766(\256nd)X
-3923(that)X
-4076(the)X
-2418 5016(built-in)N
-2678(hash)X
-2849(function)X
-3140(does)X
-3311(poorly)X
-3544(on)X
-3648(a)X
-3708(particular)X
-4040(data)X
-2418 5104(set.)N
-2548(In)X
-2636(this)X
-2771(case,)X
-2950(a)X
-3006(hash)X
-3173(function,)X
-3480(taking)X
-3700(two)X
-3840(arguments)X
-2418 5192(\(a)N
-2507(pointer)X
-2760(to)X
-2848(a)X
-2910(byte)X
-3074(string)X
-3282(and)X
-3424(a)X
-3486(length\))X
-3739(and)X
-3880(returning)X
-2418 5280(an)N
-2517(unsigned)X
-2829(long)X
-2993(to)X
-3077(be)X
-3175(used)X
-3344(as)X
-3433(the)X
-3553(hash)X
-3722(value,)X
-3938(may)X
-4098(be)X
-2418 5368(speci\256ed)N
-2731(at)X
-2817(hash)X
-2992(table)X
-3176(creation)X
-3463(time.)X
-3673(When)X
-3893(an)X
-3996(exist-)X
-2418 5456(ing)N
-2570(hash)X
-2767(table)X
-2973(is)X
-3076(opened)X
-3358(and)X
-3524(a)X
-3609(hash)X
-3805(function)X
-4121(is)X
-2418 5544(speci\256ed,)N
-2752(the)X
-2879(hash)X
-3054(package)X
-3346(will)X
-3498(try)X
-3615(to)X
-3705(determine)X
-4054(that)X
-2418 5632(the)N
-2546(hash)X
-2723(function)X
-3020(supplied)X
-3321(is)X
-3404(the)X
-3532(one)X
-3678(with)X
-3850(which)X
-4076(the)X
-2418 5720(table)N
-2630(was)X
-2811(created.)X
-3139(There)X
-3382(are)X
-3536(a)X
-3627(variety)X
-3905(of)X
-4027(hash)X
-3 f
-432 5960(8)N
-2970(USENIX)X
-9 f
-3292(-)X
-3 f
-3356(Winter)X
-3621('91)X
-9 f
-3748(-)X
-3 f
-3812(Dallas,)X
-4065(TX)X
-
-9 p
-%%Page: 9 9
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-720 258(Seltzer)N
-977(&)X
-1064(Yigit)X
-3278(A)X
-3356(New)X
-3528(Hashing)X
-3831(Package)X
-4136(for)X
-4259(UNIX)X
-1 f
-720 538(functions)N
-1065(provided)X
-1397(with)X
-1586(the)X
-1731(package.)X
-2082(The)X
-2253(default)X
-720 626(function)N
-1014(for)X
-1135(the)X
-1260(package)X
-1551(is)X
-1631(the)X
-1755(one)X
-1897(which)X
-2119(offered)X
-2378(the)X
-720 714(best)N
-875(performance)X
-1308(in)X
-1396(terms)X
-1600(of)X
-1693(cycles)X
-1920(executed)X
-2232(per)X
-2360(call)X
-720 802(\(it)N
-827(did)X
-965(not)X
-1103(produce)X
-1398(the)X
-1531(fewest)X
-1776(collisions)X
-2117(although)X
-2432(it)X
-720 890(was)N
-866(within)X
-1091(a)X
-1148(small)X
-1341(percentage)X
-1710(of)X
-1797(the)X
-1915(function)X
-2202(that)X
-2342(pro-)X
-720 978(duced)N
-947(the)X
-1080(fewest)X
-1324(collisions\).)X
-1731(Again,)X
-1981(in)X
-2077(time)X
-2253(critical)X
-720 1066(applications,)N
-1152(users)X
-1342(are)X
-1466(encouraged)X
-1862(to)X
-1949(experiment)X
-2334(with)X
-720 1154(a)N
-783(variety)X
-1032(of)X
-1125(hash)X
-1298(functions)X
-1622(to)X
-1710(achieve)X
-1982(optimal)X
-2252(perfor-)X
-720 1242(mance.)N
-10 f
-720 1330 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-3 f
-7 s
-1038 2925(Full)N
-1149(size)X
-1251(table)X
-1384(\(left\))X
-1547 2718(Fill)N
-1643(Factor)X
-2268 2662(64)N
-1964(32)X
-1674(16)X
-1384(8)X
-1093(4)X
-4 Ds
-1 Dt
-900 2280 MXY
-1548 0 Dl
-900 1879 MXY
-1548 0 Dl
-900 1506 MXY
-1548 0 Dl
-1563 2902 MXY
-111 0 Dl
--1 Ds
-900 MX
-110 0 Dl
-1425 2828(System)N
-983(User)X
-1895 2778 MXY
- 1895 2778 lineto
- 1950 2778 lineto
- 1950 2833 lineto
- 1895 2833 lineto
- 1895 2778 lineto
-closepath 21 1895 2778 1950 2833 Dp
-1342 MX
- 1342 2778 lineto
- 1397 2778 lineto
- 1397 2833 lineto
- 1342 2833 lineto
- 1342 2778 lineto
-closepath 14 1342 2778 1397 2833 Dp
-900 MX
- 900 2778 lineto
- 955 2778 lineto
- 955 2833 lineto
- 900 2833 lineto
- 900 2778 lineto
-closepath 3 900 2778 955 2833 Dp
-5 Dt
-2283 2211 MXY
-96 0 Dl
-1992 MX
-97 0 Dl
-1702 MX
-97 0 Dl
-1411 2252 MXY
-97 0 Dl
-4 Ds
-1 Dt
-2283 2211 MXY
- 2283 2211 lineto
- 2379 2211 lineto
- 2379 2252 lineto
- 2283 2252 lineto
- 2283 2211 lineto
-closepath 14 2283 2211 2379 2252 Dp
-1992 MX
- 1992 2211 lineto
- 2089 2211 lineto
- 2089 2252 lineto
- 1992 2252 lineto
- 1992 2211 lineto
-closepath 14 1992 2211 2089 2252 Dp
-1702 MX
- 1702 2211 lineto
- 1799 2211 lineto
- 1799 2252 lineto
- 1702 2252 lineto
- 1702 2211 lineto
-closepath 14 1702 2211 1799 2252 Dp
-1411 2252 MXY
- 1411 2252 lineto
- 1508 2252 lineto
- 1508 2294 lineto
- 1411 2294 lineto
- 1411 2252 lineto
-closepath 14 1411 2252 1508 2294 Dp
-2283 MX
- 2283 2252 lineto
- 2379 2252 lineto
- 2379 2612 lineto
- 2283 2612 lineto
- 2283 2252 lineto
-closepath 3 2283 2252 2379 2612 Dp
-1992 MX
- 1992 2252 lineto
- 2089 2252 lineto
- 2089 2612 lineto
- 1992 2612 lineto
- 1992 2252 lineto
-closepath 3 1992 2252 2089 2612 Dp
-1702 MX
- 1702 2252 lineto
- 1799 2252 lineto
- 1799 2612 lineto
- 1702 2612 lineto
- 1702 2252 lineto
-closepath 3 1702 2252 1799 2612 Dp
-1411 2294 MXY
- 1411 2294 lineto
- 1508 2294 lineto
- 1508 2612 lineto
- 1411 2612 lineto
- 1411 2294 lineto
-closepath 3 1411 2294 1508 2612 Dp
--1 Ds
-2158 2238 MXY
- 2158 2238 lineto
- 2255 2238 lineto
- 2255 2252 lineto
- 2158 2252 lineto
- 2158 2238 lineto
-closepath 21 2158 2238 2255 2252 Dp
-1868 MX
- 1868 2238 lineto
- 1965 2238 lineto
- 1965 2280 lineto
- 1868 2280 lineto
- 1868 2238 lineto
-closepath 21 1868 2238 1965 2280 Dp
-1577 MX
- 1577 2238 lineto
- 1674 2238 lineto
- 1674 2308 lineto
- 1577 2308 lineto
- 1577 2238 lineto
-closepath 21 1577 2238 1674 2308 Dp
-1287 2308 MXY
- 1287 2308 lineto
- 1287 2280 lineto
- 1384 2280 lineto
- 1384 2308 lineto
- 1287 2308 lineto
-closepath 21 1287 2280 1384 2308 Dp
-2158 2280 MXY
- 2158 2280 lineto
- 2158 2252 lineto
- 2255 2252 lineto
- 2255 2280 lineto
- 2158 2280 lineto
-closepath 14 2158 2252 2255 2280 Dp
-1868 2308 MXY
- 1868 2308 lineto
- 1868 2280 lineto
- 1965 2280 lineto
- 1965 2308 lineto
- 1868 2308 lineto
-closepath 14 1868 2280 1965 2308 Dp
-1577 2335 MXY
- 1577 2335 lineto
- 1577 2308 lineto
- 1674 2308 lineto
- 1674 2335 lineto
- 1577 2335 lineto
-closepath 14 1577 2308 1674 2335 Dp
-1287 2363 MXY
- 1287 2363 lineto
- 1287 2308 lineto
- 1384 2308 lineto
- 1384 2363 lineto
- 1287 2363 lineto
-closepath 14 1287 2308 1384 2363 Dp
-2158 2280 MXY
- 2158 2280 lineto
- 2255 2280 lineto
- 2255 2612 lineto
- 2158 2612 lineto
- 2158 2280 lineto
-closepath 3 2158 2280 2255 2612 Dp
-1868 2308 MXY
- 1868 2308 lineto
- 1965 2308 lineto
- 1965 2612 lineto
- 1868 2612 lineto
- 1868 2308 lineto
-closepath 3 1868 2308 1965 2612 Dp
-1577 2335 MXY
- 1577 2335 lineto
- 1674 2335 lineto
- 1674 2612 lineto
- 1577 2612 lineto
- 1577 2335 lineto
-closepath 3 1577 2335 1674 2612 Dp
-1287 2363 MXY
- 1287 2363 lineto
- 1384 2363 lineto
- 1384 2612 lineto
- 1287 2612 lineto
- 1287 2363 lineto
-closepath 3 1287 2363 1384 2612 Dp
-4 Ds
-1121 2066 MXY
- 1121 2066 lineto
- 1218 2066 lineto
- 1224 2080 lineto
- 1127 2080 lineto
- 1121 2066 lineto
-closepath 21 1121 2066 1224 2080 Dp
-2080 MY
- 1121 2080 lineto
- 1218 2080 lineto
- 1218 2273 lineto
- 1121 2273 lineto
- 1121 2080 lineto
-closepath 14 1121 2080 1218 2273 Dp
-2273 MY
- 1121 2273 lineto
- 1218 2273 lineto
- 1218 2612 lineto
- 1121 2612 lineto
- 1121 2273 lineto
-closepath 3 1121 2273 1218 2612 Dp
--1 Ds
-997 1589 MXY
- 997 1589 lineto
- 1093 1589 lineto
- 1093 1644 lineto
- 997 1644 lineto
- 997 1589 lineto
-closepath 21 997 1589 1093 1644 Dp
-1644 MY
- 997 1644 lineto
- 1093 1644 lineto
- 1093 2280 lineto
- 997 2280 lineto
- 997 1644 lineto
-closepath 14 997 1644 1093 2280 Dp
-2280 MY
- 997 2280 lineto
- 1093 2280 lineto
- 1093 2612 lineto
- 997 2612 lineto
- 997 2280 lineto
-closepath 3 997 2280 1093 2612 Dp
-10 s
-719 2093(s)N
-712 2037(d)N
-712 1982(n)N
-714 1927(o)N
-716 1872(c)N
-716 1816(e)N
-712 1761(S)N
-804 2286(10)N
-804 1899(20)N
-804 1540(30)N
-3 Dt
-900 1506 MXY
-0 1106 Dl
-1548 0 Dl
-7 s
-1978 2828(Elapsed)N
-1701 2925(Dynamically)N
-2018(grown)X
-2184(table)X
-2317(\(right\))X
-3 Dt
--1 Ds
-8 s
-720 3180(Figure)N
-934(6:)X
-1 f
-1020(The)X
-1152(total)X
-1299(regions)X
-1520(indicate)X
-1755(the)X
-1865(difference)X
-2154(between)X
-2398(the)X
-720 3268(elapsed)N
-931(time)X
-1065(and)X
-1177(the)X
-1275(sum)X
-1402(of)X
-1475(the)X
-1573(system)X
-1771(and)X
-1883(user)X
-2008(time.)X
-2173(The)X
-2291(left)X
-2395(bar)X
-720 3356(of)N
-798(each)X
-939(set)X
-1035(depicts)X
-1241(the)X
-1344(timing)X
-1537(of)X
-1615(the)X
-1718(test)X
-1831(run)X
-1940(when)X
-2102(the)X
-2204(number)X
-2423(of)X
-720 3444(entries)N
-910(is)X
-973(known)X
-1167(in)X
-1237(advance.)X
-1496(The)X
-1614(right)X
-1754(bars)X
-1879(depict)X
-2054(the)X
-2151(timing)X
-2338(when)X
-720 3532(the)N
-814(\256le)X
-912(is)X
-971(grown)X
-1150(from)X
-1290(a)X
-1334(single)X
-1503(bucket.)X
-10 s
-10 f
-720 3708 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-1 f
-892 3910(Since)N
-1131(this)X
-1307(hashing)X
-1617(package)X
-1942(provides)X
-2279(buffer)X
-720 3998(management,)N
-1188(the)X
-1323(amount)X
-1600(of)X
-1704(space)X
-1920(allocated)X
-2247(for)X
-2378(the)X
-720 4086(buffer)N
-948(pool)X
-1121(may)X
-1290(be)X
-1397(speci\256ed)X
-1713(by)X
-1824(the)X
-1953(user.)X
-2157(Using)X
-2378(the)X
-720 4174(same)N
-910(data)X
-1069(set)X
-1183(and)X
-1324(test)X
-1459(procedure)X
-1805(as)X
-1896(used)X
-2067(to)X
-2153(derive)X
-2378(the)X
-720 4262(graphs)N
-962(in)X
-1052(Figures)X
-1320(5a-c,)X
-1507(Figure)X
-1744(7)X
-1812(shows)X
-2039(the)X
-2164(impact)X
-2409(of)X
-720 4350(varying)N
-997(the)X
-1126(size)X
-1282(of)X
-1380(the)X
-1509(buffer)X
-1737(pool.)X
-1950(The)X
-2106(bucket)X
-2351(size)X
-720 4438(was)N
-873(set)X
-989(to)X
-1078(256)X
-1225(bytes)X
-1421(and)X
-1564(the)X
-1689(\256ll)X
-1804(factor)X
-2019(was)X
-2171(set)X
-2287(to)X
-2376(16.)X
-720 4526(The)N
-869(buffer)X
-1090(pool)X
-1256(size)X
-1404(was)X
-1552(varied)X
-1776(from)X
-1955(0)X
-2018(\(the)X
-2166(minimum)X
-720 4614(number)N
-986(of)X
-1074(pages)X
-1277(required)X
-1565(to)X
-1647(be)X
-1743(buffered\))X
-2063(to)X
-2145(1M.)X
-2316(With)X
-720 4702(1M)N
-854(of)X
-944(buffer)X
-1164(space,)X
-1386(the)X
-1507(package)X
-1794(performed)X
-2151(no)X
-2253(I/O)X
-2382(for)X
-720 4790(this)N
-871(data)X
-1040(set.)X
-1204(As)X
-1328(Figure)X
-1572(7)X
-1647(illustrates,)X
-2013(increasing)X
-2378(the)X
-720 4878(buffer)N
-944(pool)X
-1113(size)X
-1265(can)X
-1404(have)X
-1583(a)X
-1646(dramatic)X
-1954(affect)X
-2165(on)X
-2271(result-)X
-720 4966(ing)N
-842(performance.)X
-2 f
-8 s
-1269 4941(7)N
-1 f
-16 s
-720 5353 MXY
-864 0 Dl
-2 f
-8 s
-760 5408(7)N
-1 f
-9 s
-826 5433(Some)N
-1024(allocators)X
-1338(are)X
-1460(extremely)X
-1782(inef\256cient)X
-2107(at)X
-2192(allocating)X
-720 5513(memory.)N
-1029(If)X
-1110(you)X
-1251(\256nd)X
-1396(that)X
-1536(applications)X
-1916(are)X
-2036(running)X
-2292(out)X
-2416(of)X
-720 5593(memory)N
-1005(before)X
-1234(you)X
-1386(think)X
-1578(they)X
-1746(should,)X
-2000(try)X
-2124(varying)X
-2388(the)X
-720 5673(pagesize)N
-986(to)X
-1060(get)X
-1166(better)X
-1348(utilization)X
-1658(from)X
-1816(the)X
-1922(memory)X
-2180(allocator.)X
-10 s
-2830 1975 MXY
-0 -28 Dl
-28 0 Dl
-0 28 Dl
--28 0 Dl
-2853 2004 MXY
-0 -27 Dl
-28 0 Dl
-0 27 Dl
--28 0 Dl
-2876 2016 MXY
-0 -27 Dl
-27 0 Dl
-0 27 Dl
--27 0 Dl
-2922 1998 MXY
-0 -27 Dl
-27 0 Dl
-0 27 Dl
--27 0 Dl
-2967 2025 MXY
-0 -28 Dl
-28 0 Dl
-0 28 Dl
--28 0 Dl
-3013 2031 MXY
-0 -28 Dl
-28 0 Dl
-0 28 Dl
--28 0 Dl
-3059 MX
-0 -28 Dl
-27 0 Dl
-0 28 Dl
--27 0 Dl
-3196 2052 MXY
-0 -28 Dl
-27 0 Dl
-0 28 Dl
--27 0 Dl
-3561 2102 MXY
-0 -28 Dl
-28 0 Dl
-0 28 Dl
--28 0 Dl
-4292 2105 MXY
-0 -28 Dl
-27 0 Dl
-0 28 Dl
--27 0 Dl
-4 Ds
-1 Dt
-2844 1961 MXY
-23 30 Dl
-23 12 Dl
-45 -18 Dl
-46 26 Dl
-46 6 Dl
-45 0 Dl
-137 21 Dl
-366 50 Dl
-730 3 Dl
-9 s
-4227 2158(User)N
--1 Ds
-3 Dt
-2830 1211 MXY
-27 Dc
-2853 1261 MXY
-27 Dc
-2876 1267 MXY
-27 Dc
-2921 1341 MXY
-27 Dc
-2967 1385 MXY
-27 Dc
-3013 1450 MXY
-27 Dc
-3059 1497 MXY
-27 Dc
-3196 1686 MXY
-27 Dc
-3561 2109 MXY
-27 Dc
-4292 2295 MXY
-27 Dc
-20 Ds
-1 Dt
-2844 1211 MXY
-23 50 Dl
-23 6 Dl
-45 74 Dl
-46 44 Dl
-46 65 Dl
-45 47 Dl
-137 189 Dl
-366 423 Dl
-730 186 Dl
-4181 2270(System)N
--1 Ds
-3 Dt
-2844 583 MXY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-2867 672 MXY
-0 27 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-2890 701 MXY
-0 28 Dl
-0 -14 Dl
-13 0 Dl
--27 0 Dl
-2935 819 MXY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--27 0 Dl
-2981 849 MXY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-3027 908 MXY
-0 27 Dl
-0 -13 Dl
-14 0 Dl
--28 0 Dl
-3072 1026 MXY
-0 27 Dl
-0 -13 Dl
-14 0 Dl
--27 0 Dl
-3209 1292 MXY
-0 27 Dl
-0 -14 Dl
-14 0 Dl
--27 0 Dl
-3575 1823 MXY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--28 0 Dl
-4305 2059 MXY
-0 28 Dl
-0 -14 Dl
-14 0 Dl
--27 0 Dl
-5 Dt
-2844 597 MXY
-23 88 Dl
-23 30 Dl
-45 118 Dl
-46 30 Dl
-46 59 Dl
-45 118 Dl
-137 265 Dl
-366 532 Dl
-730 236 Dl
-4328 2103(Total)N
-2844 2310 MXY
-1461 0 Dl
-2844 MX
-0 -1772 Dl
-2310 MY
-0 18 Dl
-4 Ds
-1 Dt
-2310 MY
-0 -1772 Dl
-2826 2416(0)N
--1 Ds
-5 Dt
-3209 2310 MXY
-0 18 Dl
-4 Ds
-1 Dt
-2310 MY
-0 -1772 Dl
-3155 2416(256)N
--1 Ds
-5 Dt
-3575 2310 MXY
-0 18 Dl
-4 Ds
-1 Dt
-2310 MY
-0 -1772 Dl
-3521 2416(512)N
--1 Ds
-5 Dt
-3940 2310 MXY
-0 18 Dl
-4 Ds
-1 Dt
-2310 MY
-0 -1772 Dl
-3886 2416(768)N
--1 Ds
-5 Dt
-4305 2310 MXY
-0 18 Dl
-4 Ds
-1 Dt
-2310 MY
-0 -1772 Dl
-4233 2416(1024)N
--1 Ds
-5 Dt
-2844 2310 MXY
--18 0 Dl
-4 Ds
-1 Dt
-2844 MX
-1461 0 Dl
-2771 2340(0)N
--1 Ds
-5 Dt
-2844 2014 MXY
--18 0 Dl
-2844 1719 MXY
--18 0 Dl
-4 Ds
-1 Dt
-2844 MX
-1461 0 Dl
-2735 1749(20)N
--1 Ds
-5 Dt
-2844 1423 MXY
--18 0 Dl
-2844 1128 MXY
--18 0 Dl
-4 Ds
-1 Dt
-2844 MX
-1461 0 Dl
-2735 1158(40)N
--1 Ds
-5 Dt
-2844 833 MXY
--18 0 Dl
-2844 538 MXY
--18 0 Dl
-4 Ds
-1 Dt
-2844 MX
-1461 0 Dl
-2735 568(60)N
-3239 2529(Buffer)N
-3445(Pool)X
-3595(Size)X
-3737(\(in)X
-3835(K\))X
-2695 1259(S)N
-2699 1324(e)N
-2699 1388(c)N
-2697 1452(o)N
-2697 1517(n)N
-2697 1581(d)N
-2701 1645(s)N
-3 Dt
--1 Ds
-3 f
-8 s
-2706 2773(Figure)N
-2908(7:)X
-1 f
-2982(User)X
-3123(time)X
-3258(is)X
-3322(virtually)X
-3560(insensitive)X
-3854(to)X
-3924(the)X
-4022(amount)X
-4234(of)X
-4307(buffer)X
-2706 2861(pool)N
-2852(available,)X
-3130(however,)X
-3396(both)X
-3541(system)X
-3750(time)X
-3895(and)X
-4018(elapsed)X
-4240(time)X
-4385(are)X
-2706 2949(inversely)N
-2960(proportional)X
-3296(to)X
-3366(the)X
-3464(size)X
-3583(of)X
-3656(the)X
-3753(buffer)X
-3927(pool.)X
-4092(Even)X
-4242(for)X
-4335(large)X
-2706 3037(data)N
-2831(sets)X
-2946(where)X
-3120(one)X
-3230(expects)X
-3439(few)X
-3552(collisions,)X
-3832(specifying)X
-4116(a)X
-4162(large)X
-4307(buffer)X
-2706 3125(pool)N
-2836(dramatically)X
-3171(improves)X
-3425(performance.)X
-10 s
-10 f
-2706 3301 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-3 f
-3175 3543(Enhanced)N
-3536(Functionality)X
-1 f
-2878 3675(This)N
-3046(hashing)X
-3320(package)X
-3609(provides)X
-3910(a)X
-3971(set)X
-4085(of)X
-4177(compati-)X
-2706 3763(bility)N
-2895(routines)X
-3174(to)X
-3257(implement)X
-3620(the)X
-2 f
-3739(ndbm)X
-1 f
-3937(interface.)X
-4279(How-)X
-2706 3851(ever,)N
-2893(when)X
-3095(the)X
-3220(native)X
-3443(interface)X
-3752(is)X
-3832(used,)X
-4026(the)X
-4151(following)X
-2706 3939(additional)N
-3046(functionality)X
-3475(is)X
-3548(provided:)X
-10 f
-2798 4071(g)N
-1 f
-2946(Inserts)X
-3197(never)X
-3413(fail)X
-3556(because)X
-3847(too)X
-3985(many)X
-4199(keys)X
-2946 4159(hash)N
-3113(to)X
-3195(the)X
-3313(same)X
-3498(value.)X
-10 f
-2798 4247(g)N
-1 f
-2946(Inserts)X
-3187(never)X
-3393(fail)X
-3527(because)X
-3808(key)X
-3950(and/or)X
-4181(asso-)X
-2946 4335(ciated)N
-3158(data)X
-3312(is)X
-3385(too)X
-3507(large)X
-10 f
-2798 4423(g)N
-1 f
-2946(Hash)X
-3131(functions)X
-3449(may)X
-3607(be)X
-3703(user-speci\256ed.)X
-10 f
-2798 4511(g)N
-1 f
-2946(Multiple)X
-3268(pages)X
-3498(may)X
-3683(be)X
-3806(cached)X
-4077(in)X
-4186(main)X
-2946 4599(memory.)N
-2706 4731(It)N
-2801(also)X
-2976(provides)X
-3298(a)X
-3380(set)X
-3514(of)X
-3626(compatibility)X
-4097(routines)X
-4400(to)X
-2706 4819(implement)N
-3087(the)X
-2 f
-3224(hsearch)X
-1 f
-3516(interface.)X
-3876(Again,)X
-4130(the)X
-4266(native)X
-2706 4907(interface)N
-3008(offers)X
-3216(enhanced)X
-3540(functionality:)X
-10 f
-2798 5039(g)N
-1 f
-2946(Files)X
-3121(may)X
-3279(grow)X
-3464(beyond)X
-2 f
-3720(nelem)X
-1 f
-3932(elements.)X
-10 f
-2798 5127(g)N
-1 f
-2946(Multiple)X
-3247(hash)X
-3420(tables)X
-3632(may)X
-3795(be)X
-3896(accessed)X
-4203(con-)X
-2946 5215(currently.)N
-10 f
-2798 5303(g)N
-1 f
-2946(Hash)X
-3134(tables)X
-3344(may)X
-3505(be)X
-3604(stored)X
-3823(and)X
-3962(accessed)X
-4266(on)X
-2946 5391(disk.)N
-10 f
-2798 5479(g)N
-1 f
-2946(Hash)X
-3155(functions)X
-3497(may)X
-3679(be)X
-3799(user-speci\256ed)X
-4288(at)X
-2946 5567(runtime.)N
-3 f
-720 5960(USENIX)N
-9 f
-1042(-)X
-3 f
-1106(Winter)X
-1371('91)X
-9 f
-1498(-)X
-3 f
-1562(Dallas,)X
-1815(TX)X
-4424(9)X
-
-10 p
-%%Page: 10 10
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-432 258(A)N
-510(New)X
-682(Hashing)X
-985(Package)X
-1290(for)X
-1413(UNIX)X
-3663(Seltzer)X
-3920(&)X
-4007(Yigit)X
-459 538(Relative)N
-760(Performance)X
-1227(of)X
-1314(the)X
-1441(New)X
-1613(Implementation)X
-1 f
-604 670(The)N
-761(performance)X
-1200(testing)X
-1445(of)X
-1544(the)X
-1674(new)X
-1840(package)X
-2135(is)X
-432 758(divided)N
-711(into)X
-874(two)X
-1033(test)X
-1183(suites.)X
-1424(The)X
-1588(\256rst)X
-1751(suite)X
-1941(of)X
-2046(tests)X
-432 846(requires)N
-727(that)X
-882(the)X
-1015(tables)X
-1237(be)X
-1348(read)X
-1522(from)X
-1713(and)X
-1864(written)X
-2126(to)X
-432 934(disk.)N
-640(In)X
-742(these)X
-942(tests,)X
-1139(the)X
-1272(basis)X
-1467(for)X
-1595(comparison)X
-2003(is)X
-2090(the)X
-432 1022(4.3BSD-Reno)N
-908(version)X
-1169(of)X
-2 f
-1260(ndbm)X
-1 f
-1438(.)X
-1502(Based)X
-1722(on)X
-1826(the)X
-1948(designs)X
-432 1110(of)N
-2 f
-521(sdbm)X
-1 f
-712(and)X
-2 f
-850(gdbm)X
-1 f
-1028(,)X
-1070(they)X
-1230(are)X
-1351(expected)X
-1659(to)X
-1743(perform)X
-2024(simi-)X
-432 1198(larly)N
-605(to)X
-2 f
-693(ndbm)X
-1 f
-871(,)X
-917(and)X
-1059(we)X
-1179(do)X
-1285(not)X
-1413(show)X
-1608(their)X
-1781(performance)X
-432 1286(numbers.)N
-800(The)X
-977(second)X
-1252(suite)X
-1454(contains)X
-1772(the)X
-1921(memory)X
-432 1374(resident)N
-712(test)X
-849(which)X
-1071(does)X
-1243(not)X
-1370(require)X
-1623(that)X
-1768(the)X
-1891(\256les)X
-2049(ever)X
-432 1462(be)N
-533(written)X
-784(to)X
-870(disk,)X
-1047(only)X
-1213(that)X
-1357(hash)X
-1528(tables)X
-1739(may)X
-1901(be)X
-2001(mani-)X
-432 1550(pulated)N
-692(in)X
-778(main)X
-961(memory.)X
-1291(In)X
-1381(this)X
-1519(test,)X
-1673(we)X
-1790(compare)X
-2090(the)X
-432 1638(performance)N
-859(to)X
-941(that)X
-1081(of)X
-1168(the)X
-2 f
-1286(hsearch)X
-1 f
-1560(routines.)X
-604 1752(For)N
-760(both)X
-947(suites,)X
-1194(two)X
-1358(different)X
-1679(databases)X
-2031(were)X
-432 1840(used.)N
-656(The)X
-818(\256rst)X
-979(is)X
-1069(the)X
-1204(dictionary)X
-1566(database)X
-1880(described)X
-432 1928(previously.)N
-836(The)X
-987(second)X
-1236(was)X
-1386(constructed)X
-1781(from)X
-1962(a)X
-2023(pass-)X
-432 2016(word)N
-647(\256le)X
-799(with)X
-990(approximately)X
-1502(300)X
-1671(accounts.)X
-2041(Two)X
-432 2104(records)N
-700(were)X
-887(constructed)X
-1287(for)X
-1411(each)X
-1589(account.)X
-1909(The)X
-2064(\256rst)X
-432 2192(used)N
-604(the)X
-727(logname)X
-1028(as)X
-1120(the)X
-1243(key)X
-1384(and)X
-1525(the)X
-1648(remainder)X
-1999(of)X
-2090(the)X
-432 2280(password)N
-768(entry)X
-965(for)X
-1091(the)X
-1221(data.)X
-1427(The)X
-1584(second)X
-1839(was)X
-1996(keyed)X
-432 2368(by)N
-541(uid)X
-672(and)X
-817(contained)X
-1157(the)X
-1283(entire)X
-1494(password)X
-1825(entry)X
-2018(as)X
-2113(its)X
-432 2456(data)N
-589(\256eld.)X
-794(The)X
-942(tests)X
-1107(were)X
-1287(all)X
-1389(run)X
-1518(on)X
-1620(the)X
-1740(HP)X
-1864(9000)X
-2046(with)X
-432 2544(the)N
-574(same)X
-783(con\256guration)X
-1254(previously)X
-1636(described.)X
-2027(Each)X
-432 2632(test)N
-576(was)X
-734(run)X
-874(\256ve)X
-1027(times)X
-1232(and)X
-1380(the)X
-1510(timing)X
-1750(results)X
-1991(of)X
-2090(the)X
-432 2720(runs)N
-602(were)X
-791(averaged.)X
-1154(The)X
-1311(variance)X
-1616(across)X
-1849(the)X
-1979(5)X
-2050(runs)X
-432 2808(was)N
-591(approximately)X
-1088(1%)X
-1229(of)X
-1330(the)X
-1462(average)X
-1746(yielding)X
-2041(95%)X
-432 2896(con\256dence)N
-800(intervals)X
-1096(of)X
-1183(approximately)X
-1666(2%.)X
-3 f
-1021 3050(Disk)N
-1196(Based)X
-1420(Tests)X
-1 f
-604 3182(In)N
-693(these)X
-880(tests,)X
-1064(we)X
-1180(use)X
-1308(a)X
-1365(bucket)X
-1600(size)X
-1746(of)X
-1834(1024)X
-2015(and)X
-2152(a)X
-432 3270(\256ll)N
-540(factor)X
-748(of)X
-835(32.)X
-3 f
-432 3384(create)N
-663(test)X
-1 f
-547 3498(The)N
-703(keys)X
-881(are)X
-1011(entered)X
-1279(into)X
-1433(the)X
-1561(hash)X
-1738(table,)X
-1944(and)X
-2090(the)X
-547 3586(\256le)N
-669(is)X
-742(\257ushed)X
-993(to)X
-1075(disk.)X
-3 f
-432 3700(read)N
-608(test)X
-1 f
-547 3814(A)N
-640(lookup)X
-897(is)X
-984(performed)X
-1353(for)X
-1481(each)X
-1663(key)X
-1813(in)X
-1909(the)X
-2041(hash)X
-547 3902(table.)N
-3 f
-432 4016(verify)N
-653(test)X
-1 f
-547 4130(A)N
-640(lookup)X
-897(is)X
-984(performed)X
-1353(for)X
-1481(each)X
-1663(key)X
-1813(in)X
-1909(the)X
-2041(hash)X
-547 4218(table,)N
-759(and)X
-911(the)X
-1045(data)X
-1215(returned)X
-1519(is)X
-1608(compared)X
-1961(against)X
-547 4306(that)N
-687(originally)X
-1018(stored)X
-1234(in)X
-1316(the)X
-1434(hash)X
-1601(table.)X
-3 f
-432 4420(sequential)N
-798(retrieve)X
-1 f
-547 4534(All)N
-674(keys)X
-846(are)X
-970(retrieved)X
-1281(in)X
-1367(sequential)X
-1716(order)X
-1910(from)X
-2090(the)X
-547 4622(hash)N
-724(table.)X
-950(The)X
-2 f
-1105(ndbm)X
-1 f
-1313(interface)X
-1625(allows)X
-1863(sequential)X
-547 4710(retrieval)N
-848(of)X
-948(the)X
-1079(keys)X
-1259(from)X
-1448(the)X
-1578(database,)X
-1907(but)X
-2041(does)X
-547 4798(not)N
-701(return)X
-945(the)X
-1094(data)X
-1279(associated)X
-1660(with)X
-1853(each)X
-2052(key.)X
-547 4886(Therefore,)N
-929(we)X
-1067(compare)X
-1388(the)X
-1530(performance)X
-1980(of)X
-2090(the)X
-547 4974(new)N
-703(package)X
-989(to)X
-1073(two)X
-1215(different)X
-1514(runs)X
-1674(of)X
-2 f
-1763(ndbm)X
-1 f
-1941(.)X
-2002(In)X
-2090(the)X
-547 5062(\256rst)N
-697(case,)X
-2 f
-882(ndbm)X
-1 f
-1086(returns)X
-1335(only)X
-1503(the)X
-1627(keys)X
-1800(while)X
-2003(in)X
-2090(the)X
-547 5150(second,)N
-2 f
-823(ndbm)X
-1 f
-1034(returns)X
-1290(both)X
-1465(the)X
-1596(keys)X
-1776(and)X
-1924(the)X
-2054(data)X
-547 5238(\(requiring)N
-894(a)X
-956(second)X
-1204(call)X
-1345(to)X
-1432(the)X
-1555(library\).)X
-1861(There)X
-2074(is)X
-2152(a)X
-547 5326(single)N
-764(run)X
-897(for)X
-1017(the)X
-1141(new)X
-1300(library)X
-1539(since)X
-1729(it)X
-1798(returns)X
-2046(both)X
-547 5414(the)N
-665(key)X
-801(and)X
-937(the)X
-1055(data.)X
-3 f
-3014 538(In-Memory)N
-3431(Test)X
-1 f
-2590 670(This)N
-2757(test)X
-2892(uses)X
-3054(a)X
-3114(bucket)X
-3352(size)X
-3501(of)X
-3592(256)X
-3736(and)X
-3876(a)X
-3936(\256ll)X
-4048(fac-)X
-2418 758(tor)N
-2527(of)X
-2614(8.)X
-3 f
-2418 872(create/read)N
-2827(test)X
-1 f
-2533 986(In)N
-2627(this)X
-2769(test,)X
-2927(a)X
-2989(hash)X
-3162(table)X
-3344(is)X
-3423(created)X
-3682(by)X
-3788(inserting)X
-4094(all)X
-2533 1074(the)N
-2660(key/data)X
-2961(pairs.)X
-3186(Then)X
-3380(a)X
-3445(keyed)X
-3666(retrieval)X
-3963(is)X
-4044(per-)X
-2533 1162(formed)N
-2801(for)X
-2931(each)X
-3115(pair,)X
-3295(and)X
-3446(the)X
-3579(hash)X
-3761(table)X
-3952(is)X
-4040(des-)X
-2533 1250(troyed.)N
-3 f
-2938 1404(Performance)N
-3405(Results)X
-1 f
-2590 1536(Figures)N
-2866(8a)X
-2978(and)X
-3130(8b)X
-3246(show)X
-3451(the)X
-3585(user)X
-3755(time,)X
-3952(system)X
-2418 1624(time,)N
-2608(and)X
-2752(elapsed)X
-3021(time)X
-3191(for)X
-3312(each)X
-3487(test)X
-3625(for)X
-3746(both)X
-3915(the)X
-4040(new)X
-2418 1712(implementation)N
-2951(and)X
-3098(the)X
-3227(old)X
-3360(implementation)X
-3893(\()X
-2 f
-3920(hsearch)X
-1 f
-2418 1800(or)N
-2 f
-2528(ndbm)X
-1 f
-2706(,)X
-2769(whichever)X
-3147(is)X
-3243(appropriate\))X
-3678(as)X
-3787(well)X
-3967(as)X
-4076(the)X
-2418 1888(improvement.)N
-2929(The)X
-3098(improvement)X
-3569(is)X
-3666(expressed)X
-4027(as)X
-4138(a)X
-2418 1976(percentage)N
-2787(of)X
-2874(the)X
-2992(old)X
-3114(running)X
-3383(time:)X
-0 f
-8 s
-2418 2275(%)N
-2494(=)X
-2570(100)X
-2722(*)X
-2798 -0.4219(\(old_time)AX
-3178(-)X
-3254 -0.4219(new_time\))AX
-3634(/)X
-3710(old_time)X
-1 f
-10 s
-2590 2600(In)N
-2700(nearly)X
-2944(all)X
-3067(cases,)X
-3299(the)X
-3439(new)X
-3615(routines)X
-3915(perform)X
-2418 2688(better)N
-2628(than)X
-2793(the)X
-2918(old)X
-3047(routines)X
-3332(\(both)X
-2 f
-3527(hsearch)X
-1 f
-3807(and)X
-2 f
-3949(ndbm)X
-1 f
-4127(\).)X
-2418 2776(Although)N
-2755(the)X
-3 f
-2888(create)X
-1 f
-3134(tests)X
-3311(exhibit)X
-3567(superior)X
-3864(user)X
-4032(time)X
-2418 2864(performance,)N
-2869(the)X
-2991(test)X
-3126(time)X
-3292(is)X
-3369(dominated)X
-3731(by)X
-3834(the)X
-3955(cost)X
-4107(of)X
-2418 2952(writing)N
-2677(the)X
-2803(actual)X
-3023(\256le)X
-3153(to)X
-3243(disk.)X
-3444(For)X
-3583(the)X
-3709(large)X
-3897(database)X
-2418 3040(\(the)N
-2564(dictionary\),)X
-2957(this)X
-3093(completely)X
-3470(overwhelmed)X
-3927(the)X
-4045(sys-)X
-2418 3128(tem)N
-2570(time.)X
-2783(However,)X
-3129(for)X
-3254(the)X
-3383(small)X
-3587(data)X
-3752(base,)X
-3946(we)X
-4071(see)X
-2418 3216(that)N
-2569(differences)X
-2958(in)X
-3051(both)X
-3224(user)X
-3389(and)X
-3536(system)X
-3788(time)X
-3960(contri-)X
-2418 3304(bute)N
-2576(to)X
-2658(the)X
-2776(superior)X
-3059(performance)X
-3486(of)X
-3573(the)X
-3691(new)X
-3845(package.)X
-2590 3418(The)N
-3 f
-2764(read)X
-1 f
-2920(,)X
-3 f
-2989(verify)X
-1 f
-3190(,)X
-3259(and)X
-3 f
-3424(sequential)X
-1 f
-3818(results)X
-4075(are)X
-2418 3506(deceptive)N
-2758(for)X
-2883(the)X
-3012(small)X
-3216(database)X
-3524(since)X
-3720(the)X
-3849(entire)X
-4063(test)X
-2418 3594(ran)N
-2551(in)X
-2643(under)X
-2856(a)X
-2922(second.)X
-3215(However,)X
-3560(on)X
-3669(the)X
-3796(larger)X
-4013(data-)X
-2418 3682(base)N
-2590(the)X
-3 f
-2716(read)X
-1 f
-2900(and)X
-3 f
-3044(verify)X
-1 f
-3273(tests)X
-3443(bene\256t)X
-3689(from)X
-3873(the)X
-3999(cach-)X
-2418 3770(ing)N
-2546(of)X
-2639(buckets)X
-2910(in)X
-2998(the)X
-3122(new)X
-3282(package)X
-3571(to)X
-3658(improve)X
-3950(perfor-)X
-2418 3858(mance)N
-2666(by)X
-2784(over)X
-2965(80%.)X
-3169(Since)X
-3384(the)X
-3519(\256rst)X
-3 f
-3680(sequential)X
-1 f
-4063(test)X
-2418 3946(does)N
-2598(not)X
-2733(require)X
-2 f
-2994(ndbm)X
-1 f
-3205(to)X
-3299(return)X
-3523(the)X
-3653(data)X
-3819(values,)X
-4076(the)X
-2418 4034(user)N
-2573(time)X
-2735(is)X
-2808(lower)X
-3011(than)X
-3169(for)X
-3283(the)X
-3401(new)X
-3555(package.)X
-3879(However)X
-2418 4122(when)N
-2613(we)X
-2728(require)X
-2977(both)X
-3139(packages)X
-3454(to)X
-3536(return)X
-3748(data,)X
-3922(the)X
-4040(new)X
-2418 4210(package)N
-2702(excels)X
-2923(in)X
-3005(all)X
-3105(three)X
-3286(timings.)X
-2590 4324(The)N
-2773(small)X
-3003(database)X
-3337(runs)X
-3532(so)X
-3660(quickly)X
-3957(in)X
-4076(the)X
-2418 4412(memory-resident)N
-3000(case)X
-3173(that)X
-3326(the)X
-3457(results)X
-3699(are)X
-3831(uninterest-)X
-2418 4500(ing.)N
-2589(However,)X
-2933(for)X
-3056(the)X
-3183(larger)X
-3400(database)X
-3706(the)X
-3833(new)X
-3995(pack-)X
-2418 4588(age)N
-2567(pays)X
-2751(a)X
-2824(small)X
-3033(penalty)X
-3305(in)X
-3403(system)X
-3661(time)X
-3839(because)X
-4130(it)X
-2418 4676(limits)N
-2636(its)X
-2748(main)X
-2944(memory)X
-3247(utilization)X
-3607(and)X
-3759(swaps)X
-3991(pages)X
-2418 4764(out)N
-2550(to)X
-2642(temporary)X
-3002(storage)X
-3264(in)X
-3356(the)X
-3484(\256le)X
-3616(system)X
-3868(while)X
-4076(the)X
-2 f
-2418 4852(hsearch)N
-1 f
-2698(package)X
-2988(requires)X
-3273(that)X
-3419(the)X
-3543(application)X
-3924(allocate)X
-2418 4940(enough)N
-2692(space)X
-2909(for)X
-3041(all)X
-3159(key/data)X
-3468(pair.)X
-3670(However,)X
-4022(even)X
-2418 5028(with)N
-2600(the)X
-2738(system)X
-3000(time)X
-3182(penalty,)X
-3477(the)X
-3614(resulting)X
-3933(elapsed)X
-2418 5116(time)N
-2580(improves)X
-2898(by)X
-2998(over)X
-3161(50%.)X
-3 f
-432 5960(10)N
-2970(USENIX)X
-9 f
-3292(-)X
-3 f
-3356(Winter)X
-3621('91)X
-9 f
-3748(-)X
-3 f
-3812(Dallas,)X
-4065(TX)X
-
-11 p
-%%Page: 11 11
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-720 258(Seltzer)N
-977(&)X
-1064(Yigit)X
-3278(A)X
-3356(New)X
-3528(Hashing)X
-3831(Package)X
-4136(for)X
-4259(UNIX)X
-1 f
-10 f
-908 454(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2 f
-1379 546(hash)N
-1652(ndbm)X
-1950(%change)X
-1 f
-10 f
-908 550(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-948 642(CREATE)N
-10 f
-908 646(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-1125 738(user)N
-1424(6.4)X
-1671(12.2)X
-2073(48)X
-1157 826(sys)N
-1384(32.5)X
-1671(34.7)X
-2113(6)X
-3 f
-1006 914(elapsed)N
-10 f
-1310 922(c)N
-890(c)Y
-810(c)Y
-730(c)Y
-3 f
-1384 914(90.4)N
-10 f
-1581 922(c)N
-890(c)Y
-810(c)Y
-730(c)Y
-3 f
-1671 914(99.6)N
-10 f
-1883 922(c)N
-890(c)Y
-810(c)Y
-730(c)Y
-3 f
-2113 914(9)N
-1 f
-10 f
-908 910(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-908 926(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-948 1010(READ)N
-10 f
-908 1014(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-1125 1106(user)N
-1424(3.4)X
-1711(6.1)X
-2073(44)X
-1157 1194(sys)N
-1424(1.2)X
-1671(15.3)X
-2073(92)X
-3 f
-1006 1282(elapsed)N
-10 f
-1310 1290(c)N
-1258(c)Y
-1178(c)Y
-1098(c)Y
-3 f
-1424 1282(4.0)N
-10 f
-1581 1290(c)N
-1258(c)Y
-1178(c)Y
-1098(c)Y
-3 f
-1671 1282(21.2)N
-10 f
-1883 1290(c)N
-1258(c)Y
-1178(c)Y
-1098(c)Y
-3 f
-2073 1282(81)N
-1 f
-10 f
-908 1278(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-908 1294(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-948 1378(VERIFY)N
-10 f
-908 1382(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-1125 1474(user)N
-1424(3.5)X
-1711(6.3)X
-2073(44)X
-1157 1562(sys)N
-1424(1.2)X
-1671(15.3)X
-2073(92)X
-3 f
-1006 1650(elapsed)N
-10 f
-1310 1658(c)N
-1626(c)Y
-1546(c)Y
-1466(c)Y
-3 f
-1424 1650(4.0)N
-10 f
-1581 1658(c)N
-1626(c)Y
-1546(c)Y
-1466(c)Y
-3 f
-1671 1650(21.2)N
-10 f
-1883 1658(c)N
-1626(c)Y
-1546(c)Y
-1466(c)Y
-3 f
-2073 1650(81)N
-1 f
-10 f
-908 1646(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-908 1662(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-948 1746(SEQUENTIAL)N
-10 f
-908 1750(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-1125 1842(user)N
-1424(2.7)X
-1711(1.9)X
-2046(-42)X
-1157 1930(sys)N
-1424(0.7)X
-1711(3.9)X
-2073(82)X
-3 f
-1006 2018(elapsed)N
-10 f
-1310 2026(c)N
-1994(c)Y
-1914(c)Y
-1834(c)Y
-3 f
-1424 2018(3.0)N
-10 f
-1581 2026(c)N
-1994(c)Y
-1914(c)Y
-1834(c)Y
-3 f
-1711 2018(5.0)N
-10 f
-1883 2026(c)N
-1994(c)Y
-1914(c)Y
-1834(c)Y
-3 f
-2073 2018(40)N
-1 f
-10 f
-908 2014(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-908 2030(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-948 2114(SEQUENTIAL)N
-1467(\(with)X
-1656(data)X
-1810(retrieval\))X
-10 f
-908 2118(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-1125 2210(user)N
-1424(2.7)X
-1711(8.2)X
-2073(67)X
-1157 2298(sys)N
-1424(0.7)X
-1711(4.3)X
-2073(84)X
-3 f
-1006 2386(elapsed)N
-1424(3.0)X
-1671(12.0)X
-2073(75)X
-1 f
-10 f
-908 2390(i)N
-927(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-899 2394(c)N
-2378(c)Y
-2298(c)Y
-2218(c)Y
-2138(c)Y
-2058(c)Y
-1978(c)Y
-1898(c)Y
-1818(c)Y
-1738(c)Y
-1658(c)Y
-1578(c)Y
-1498(c)Y
-1418(c)Y
-1338(c)Y
-1258(c)Y
-1178(c)Y
-1098(c)Y
-1018(c)Y
-938(c)Y
-858(c)Y
-778(c)Y
-698(c)Y
-618(c)Y
-538(c)Y
-1310 2394(c)N
-2362(c)Y
-2282(c)Y
-2202(c)Y
-1581 2394(c)N
-2362(c)Y
-2282(c)Y
-2202(c)Y
-1883 2394(c)N
-2362(c)Y
-2282(c)Y
-2202(c)Y
-2278 2394(c)N
-2378(c)Y
-2298(c)Y
-2218(c)Y
-2138(c)Y
-2058(c)Y
-1978(c)Y
-1898(c)Y
-1818(c)Y
-1738(c)Y
-1658(c)Y
-1578(c)Y
-1498(c)Y
-1418(c)Y
-1338(c)Y
-1258(c)Y
-1178(c)Y
-1098(c)Y
-1018(c)Y
-938(c)Y
-858(c)Y
-778(c)Y
-698(c)Y
-618(c)Y
-538(c)Y
-905 2574(i)N
-930(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2 f
-1318 2666(hash)N
-1585(hsearch)X
-1953(%change)X
-1 f
-10 f
-905 2670(i)N
-930(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-945 2762(CREATE/READ)N
-10 f
-905 2766(i)N
-930(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-1064 2858(user)N
-1343(6.6)X
-1642(17.2)X
-2096(62)X
-1096 2946(sys)N
-1343(1.1)X
-1682(0.3)X
-2029(-266)X
-3 f
-945 3034(elapsed)N
-1343(7.8)X
-1642(17.0)X
-2096(54)X
-1 f
-10 f
-905 3038(i)N
-930(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-896 3050(c)N
-2978(c)Y
-2898(c)Y
-2818(c)Y
-2738(c)Y
-2658(c)Y
-1249 3034(c)N
-3010(c)Y
-2930(c)Y
-2850(c)Y
-1520 3034(c)N
-3010(c)Y
-2930(c)Y
-2850(c)Y
-1886 3034(c)N
-3010(c)Y
-2930(c)Y
-2850(c)Y
-2281 3050(c)N
-2978(c)Y
-2898(c)Y
-2818(c)Y
-2738(c)Y
-2658(c)Y
-3 f
-720 3174(Figure)N
-967(8a:)X
-1 f
-1094(Timing)X
-1349(results)X
-1578(for)X
-1692(the)X
-1810(dictionary)X
-2155(database.)X
-10 f
-720 3262 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-3 f
-1407 3504(Conclusion)N
-1 f
-892 3636(This)N
-1063(paper)X
-1271(has)X
-1407(presented)X
-1744(the)X
-1871(design,)X
-2129(implemen-)X
-720 3724(tation)N
-928(and)X
-1070(performance)X
-1503(of)X
-1596(a)X
-1658(new)X
-1818(hashing)X
-2093(package)X
-2382(for)X
-720 3812(UNIX.)N
-993(The)X
-1150(new)X
-1316(package)X
-1612(provides)X
-1919(a)X
-1986(superset)X
-2280(of)X
-2378(the)X
-720 3900(functionality)N
-1159(of)X
-1255(existing)X
-1537(hashing)X
-1815(packages)X
-2139(and)X
-2284(incor-)X
-720 3988(porates)N
-975(additional)X
-1318(features)X
-1596(such)X
-1766(as)X
-1855(large)X
-2038(key)X
-2176(handling,)X
-720 4076(user)N
-876(de\256ned)X
-1134(hash)X
-1302(functions,)X
-1641(multiple)X
-1928(hash)X
-2096(tables,)X
-2324(vari-)X
-720 4164(able)N
-894(sized)X
-1099(pages,)X
-1342(and)X
-1498(linear)X
-1721(hashing.)X
-2050(In)X
-2156(nearly)X
-2396(all)X
-720 4252(cases,)N
-954(the)X
-1096(new)X
-1274(package)X
-1582(provides)X
-1902(improved)X
-2252(perfor-)X
-720 4340(mance)N
-974(on)X
-1098(the)X
-1240(order)X
-1454(of)X
-1565(50-80%)X
-1863(for)X
-2001(the)X
-2142(workloads)X
-720 4428(shown.)N
-990(Applications)X
-1420(such)X
-1588(as)X
-1676(the)X
-1794(loader,)X
-2035(compiler,)X
-2360(and)X
-720 4516(mail,)N
-921(which)X
-1156(currently)X
-1485(implement)X
-1866(their)X
-2051(own)X
-2227(hashing)X
-720 4604(routines,)N
-1032(should)X
-1279(be)X
-1389(modi\256ed)X
-1706(to)X
-1801(use)X
-1941(the)X
-2072(generic)X
-2342(rou-)X
-720 4692(tines.)N
-892 4806(This)N
-1087(hashing)X
-1389(package)X
-1705(is)X
-1810(one)X
-1978(access)X
-2236(method)X
-720 4894(which)N
-953(is)X
-1043(part)X
-1205(of)X
-1309(a)X
-1382(generic)X
-1656(database)X
-1970(access)X
-2212(package)X
-720 4982(being)N
-955(developed)X
-1342(at)X
-1457(the)X
-1612(University)X
-2007(of)X
-2131(California,)X
-720 5070(Berkeley.)N
-1089(It)X
-1177(will)X
-1340(include)X
-1614(a)X
-1688(btree)X
-1887(access)X
-2131(method)X
-2409(as)X
-720 5158(well)N
-916(as)X
-1041(\256xed)X
-1259(and)X
-1433(variable)X
-1750(length)X
-2007(record)X
-2270(access)X
-720 5246(methods)N
-1024(in)X
-1119(addition)X
-1414(to)X
-1509(the)X
-1640(hashed)X
-1896(support)X
-2168(presented)X
-720 5334(here.)N
-948(All)X
-1099(of)X
-1215(the)X
-1361(access)X
-1615(methods)X
-1934(are)X
-2081(based)X
-2312(on)X
-2440(a)X
-720 5422(key/data)N
-1037(pair)X
-1207(interface)X
-1533(and)X
-1693(appear)X
-1952(identical)X
-2272(to)X
-2378(the)X
-720 5510(application)N
-1121(layer,)X
-1347(allowing)X
-1671(application)X
-2071(implementa-)X
-720 5598(tions)N
-906(to)X
-999(be)X
-1106(largely)X
-1360(independent)X
-1783(of)X
-1881(the)X
-2010(database)X
-2318(type.)X
-720 5686(The)N
-873(package)X
-1165(is)X
-1246(expected)X
-1560(to)X
-1650(be)X
-1754(an)X
-1858(integral)X
-2131(part)X
-2284(of)X
-2378(the)X
-2706 538(4.4BSD)N
-3006(system,)X
-3293(with)X
-3479(various)X
-3759(standard)X
-4075(applications)X
-2706 626(such)N
-2879(as)X
-2972(more\(1\),)X
-3277(sort\(1\))X
-3517(and)X
-3659(vi\(1\))X
-3841(based)X
-4050(on)X
-4156(it.)X
-4266(While)X
-2706 714(the)N
-2833(current)X
-3089(design)X
-3326(does)X
-3501(not)X
-3631(support)X
-3899(multi-user)X
-4256(access)X
-2706 802(or)N
-2804(transactions,)X
-3238(they)X
-3407(could)X
-3616(be)X
-3723(incorporated)X
-4159(relatively)X
-2706 890(easily.)N
-10 f
-2894 938(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2 f
-3365 1030(hash)N
-3638(ndbm)X
-3936(%change)X
-1 f
-10 f
-2894 1034(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-2934 1126(CREATE)N
-10 f
-2894 1130(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-3111 1222(user)N
-3390(0.2)X
-3677(0.4)X
-4079(50)X
-3143 1310(sys)N
-3390(0.1)X
-3677(1.0)X
-4079(90)X
-3 f
-2992 1398(elapsed)N
-10 f
-3296 1406(c)N
-1374(c)Y
-1294(c)Y
-1214(c)Y
-3 f
-3390 1398(0)N
-10 f
-3567 1406(c)N
-1374(c)Y
-1294(c)Y
-1214(c)Y
-3 f
-3677 1398(3.2)N
-10 f
-3869 1406(c)N
-1374(c)Y
-1294(c)Y
-1214(c)Y
-3 f
-4039 1398(100)N
-1 f
-10 f
-2894 1394(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2894 1410(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-2934 1494(READ)N
-10 f
-2894 1498(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-3111 1590(user)N
-3390(0.1)X
-3677(0.1)X
-4119(0)X
-3143 1678(sys)N
-3390(0.1)X
-3677(0.4)X
-4079(75)X
-3 f
-2992 1766(elapsed)N
-10 f
-3296 1774(c)N
-1742(c)Y
-1662(c)Y
-1582(c)Y
-3 f
-3390 1766(0.0)N
-10 f
-3567 1774(c)N
-1742(c)Y
-1662(c)Y
-1582(c)Y
-3 f
-3677 1766(0.0)N
-10 f
-3869 1774(c)N
-1742(c)Y
-1662(c)Y
-1582(c)Y
-3 f
-4119 1766(0)N
-1 f
-10 f
-2894 1762(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2894 1778(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-2934 1862(VERIFY)N
-10 f
-2894 1866(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-3111 1958(user)N
-3390(0.1)X
-3677(0.2)X
-4079(50)X
-3143 2046(sys)N
-3390(0.1)X
-3677(0.3)X
-4079(67)X
-3 f
-2992 2134(elapsed)N
-10 f
-3296 2142(c)N
-2110(c)Y
-2030(c)Y
-1950(c)Y
-3 f
-3390 2134(0.0)N
-10 f
-3567 2142(c)N
-2110(c)Y
-2030(c)Y
-1950(c)Y
-3 f
-3677 2134(0.0)N
-10 f
-3869 2142(c)N
-2110(c)Y
-2030(c)Y
-1950(c)Y
-3 f
-4119 2134(0)N
-1 f
-10 f
-2894 2130(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2894 2146(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-2934 2230(SEQUENTIAL)N
-10 f
-2894 2234(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-3111 2326(user)N
-3390(0.1)X
-3677(0.0)X
-4012(-100)X
-3143 2414(sys)N
-3390(0.1)X
-3677(0.1)X
-4119(0)X
-3 f
-2992 2502(elapsed)N
-10 f
-3296 2510(c)N
-2478(c)Y
-2398(c)Y
-2318(c)Y
-3 f
-3390 2502(0.0)N
-10 f
-3567 2510(c)N
-2478(c)Y
-2398(c)Y
-2318(c)Y
-3 f
-3677 2502(0.0)N
-10 f
-3869 2510(c)N
-2478(c)Y
-2398(c)Y
-2318(c)Y
-3 f
-4119 2502(0)N
-1 f
-10 f
-2894 2498(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2894 2514(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-2934 2598(SEQUENTIAL)N
-3453(\(with)X
-3642(data)X
-3796(retrieval\))X
-10 f
-2894 2602(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-3111 2694(user)N
-3390(0.1)X
-3677(0.1)X
-4119(0)X
-3143 2782(sys)N
-3390(0.1)X
-3677(0.1)X
-4119(0)X
-3 f
-2992 2870(elapsed)N
-3390(0.0)X
-3677(0.0)X
-4119(0)X
-1 f
-10 f
-2894 2874(i)N
-2913(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2885 2878(c)N
-2862(c)Y
-2782(c)Y
-2702(c)Y
-2622(c)Y
-2542(c)Y
-2462(c)Y
-2382(c)Y
-2302(c)Y
-2222(c)Y
-2142(c)Y
-2062(c)Y
-1982(c)Y
-1902(c)Y
-1822(c)Y
-1742(c)Y
-1662(c)Y
-1582(c)Y
-1502(c)Y
-1422(c)Y
-1342(c)Y
-1262(c)Y
-1182(c)Y
-1102(c)Y
-1022(c)Y
-3296 2878(c)N
-2846(c)Y
-2766(c)Y
-2686(c)Y
-3567 2878(c)N
-2846(c)Y
-2766(c)Y
-2686(c)Y
-3869 2878(c)N
-2846(c)Y
-2766(c)Y
-2686(c)Y
-4264 2878(c)N
-2862(c)Y
-2782(c)Y
-2702(c)Y
-2622(c)Y
-2542(c)Y
-2462(c)Y
-2382(c)Y
-2302(c)Y
-2222(c)Y
-2142(c)Y
-2062(c)Y
-1982(c)Y
-1902(c)Y
-1822(c)Y
-1742(c)Y
-1662(c)Y
-1582(c)Y
-1502(c)Y
-1422(c)Y
-1342(c)Y
-1262(c)Y
-1182(c)Y
-1102(c)Y
-1022(c)Y
-2891 3058(i)N
-2916(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2 f
-3304 3150(hash)N
-3571(hsearch)X
-3939(%change)X
-1 f
-10 f
-2891 3154(i)N
-2916(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-2931 3246(CREATE/READ)N
-10 f
-2891 3250(i)N
-2916(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-3050 3342(user)N
-3329(0.3)X
-3648(0.4)X
-4048(25)X
-3082 3430(sys)N
-3329(0.0)X
-3648(0.0)X
-4088(0)X
-3 f
-2931 3518(elapsed)N
-3329(0.0)X
-3648(0.0)X
-4088(0)X
-1 f
-10 f
-2891 3522(i)N
-2916(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2882 3534(c)N
-3462(c)Y
-3382(c)Y
-3302(c)Y
-3222(c)Y
-3142(c)Y
-3235 3518(c)N
-3494(c)Y
-3414(c)Y
-3334(c)Y
-3506 3518(c)N
-3494(c)Y
-3414(c)Y
-3334(c)Y
-3872 3518(c)N
-3494(c)Y
-3414(c)Y
-3334(c)Y
-4267 3534(c)N
-3462(c)Y
-3382(c)Y
-3302(c)Y
-3222(c)Y
-3142(c)Y
-3 f
-2706 3658(Figure)N
-2953(8b:)X
-1 f
-3084(Timing)X
-3339(results)X
-3568(for)X
-3682(the)X
-3800(password)X
-4123(database.)X
-10 f
-2706 3746 -0.0930(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)AN
-3 f
-3396 3988(References)N
-1 f
-2706 4120([ATT79])N
-3058(AT&T,)X
-3358(DBM\(3X\),)X
-2 f
-3773(Unix)X
-3990(Programmer's)X
-2878 4208(Manual,)N
-3194(Seventh)X
-3491(Edition,)X
-3793(Volume)X
-4085(1)X
-1 f
-(,)S
-4192(January,)X
-2878 4296(1979.)N
-2706 4472([ATT85])N
-3027(AT&T,)X
-3296(HSEARCH\(BA_LIB\),)X
-2 f
-4053(Unix)X
-4239(System)X
-2878 4560(User's)N
-3112(Manual,)X
-3401(System)X
-3644(V.3)X
-1 f
-3753(,)X
-3793(pp.)X
-3913(506-508,)X
-4220(1985.)X
-2706 4736([BRE73])N
-3025(Brent,)X
-3253(Richard)X
-3537(P.,)X
-3651(``Reducing)X
-4041(the)X
-4168(Retrieval)X
-2878 4824(Time)N
-3071(of)X
-3162(Scatter)X
-3409(Storage)X
-3678(Techniques'',)X
-2 f
-4146(Commun-)X
-2878 4912(ications)N
-3175(of)X
-3281(the)X
-3422(ACM)X
-1 f
-3591(,)X
-3654(Volume)X
-3955(16,)X
-4098(No.)X
-4259(2,)X
-4362(pp.)X
-2878 5000(105-109,)N
-3185(February,)X
-3515(1973.)X
-2706 5176([BSD86])N
-3055(NDBM\(3\),)X
-2 f
-3469(4.3BSD)X
-3775(Unix)X
-3990(Programmer's)X
-2878 5264(Manual)N
-3155(Reference)X
-3505(Guide)X
-1 f
-3701(,)X
-3749(University)X
-4114(of)X
-4208(Califor-)X
-2878 5352(nia,)N
-3016(Berkeley,)X
-3346(1986.)X
-2706 5528([ENB88])N
-3025(Enbody,)X
-3319(R.)X
-3417(J.,)X
-3533(Du,)X
-3676(H.)X
-3779(C.,)X
-3897(``Dynamic)X
-4270(Hash-)X
-2878 5616(ing)N
-3034(Schemes'',)X
-2 f
-3427(ACM)X
-3630(Computing)X
-4019(Surveys)X
-1 f
-4269(,)X
-4322(Vol.)X
-2878 5704(20,)N
-2998(No.)X
-3136(2,)X
-3216(pp.)X
-3336(85-113,)X
-3603(June)X
-3770(1988.)X
-3 f
-720 5960(USENIX)N
-9 f
-1042(-)X
-3 f
-1106(Winter)X
-1371('91)X
-9 f
-1498(-)X
-3 f
-1562(Dallas,)X
-1815(TX)X
-4384(11)X
-
-12 p
-%%Page: 12 12
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-432 258(A)N
-510(New)X
-682(Hashing)X
-985(Package)X
-1290(for)X
-1413(UNIX)X
-3663(Seltzer)X
-3920(&)X
-4007(Yigit)X
-1 f
-432 538([FAG79])N
-776(Ronald)X
-1057(Fagin,)X
-1308(Jurg)X
-1495(Nievergelt,)X
-1903(Nicholas)X
-604 626(Pippenger,)N
-1003(H.)X
-1135(Raymond)X
-1500(Strong,)X
-1787(``Extendible)X
-604 714(Hashing)N
-901(--)X
-985(A)X
-1073(Fast)X
-1236(Access)X
-1493(Method)X
-1771(for)X
-1894(Dynamic)X
-604 802(Files'',)N
-2 f
-855(ACM)X
-1046(Transactions)X
-1485(on)X
-1586(Database)X
-1914(Systems)X
-1 f
-2168(,)X
-604 890(Volume)N
-882(4,)X
-962(No.)X
-1100(3.,)X
-1200(September)X
-1563(1979,)X
-1763(pp)X
-1863(315-34)X
-432 1066([KNU68],)N
-802(Knuth,)X
-1064(D.E.,)X
-2 f
-1273(The)X
-1434(Art)X
-1577(of)X
-1680(Computer)X
-2041(Pro-)X
-604 1154(gramming)N
-971(Vol.)X
-1140(3:)X
-1245(Sorting)X
-1518(and)X
-1676(Searching)X
-1 f
-2001(,)X
-2058(sec-)X
-604 1242(tions)N
-779(6.3-6.4,)X
-1046(pp)X
-1146(481-550.)X
-432 1418([LAR78])N
-747(Larson,)X
-1011(Per-Ake,)X
-1319(``Dynamic)X
-1687(Hashing'',)X
-2 f
-2048(BIT)X
-1 f
-(,)S
-604 1506(Vol.)N
-764(18,)X
-884(1978,)X
-1084(pp.)X
-1204(184-201.)X
-432 1682([LAR88])N
-752(Larson,)X
-1021(Per-Ake,)X
-1335(``Dynamic)X
-1709(Hash)X
-1900(Tables'',)X
-2 f
-604 1770(Communications)N
-1183(of)X
-1281(the)X
-1415(ACM)X
-1 f
-1584(,)X
-1640(Volume)X
-1934(31,)X
-2070(No.)X
-604 1858(4.,)N
-704(April)X
-893(1988,)X
-1093(pp)X
-1193(446-457.)X
-432 2034([LIT80])N
-731(Witold,)X
-1013(Litwin,)X
-1286(``Linear)X
-1590(Hashing:)X
-1939(A)X
-2036(New)X
-604 2122(Tool)N
-786(for)X
-911(File)X
-1065(and)X
-1211(Table)X
-1424(Addressing'',)X
-2 f
-1893(Proceed-)X
-604 2210(ings)N
-761(of)X
-847(the)X
-969(6th)X
-1095(International)X
-1540(Conference)X
-1933(on)X
-2036(Very)X
-604 2298(Large)N
-815(Databases)X
-1 f
-1153(,)X
-1193(1980.)X
-432 2474([NEL90])N
-743(Nelson,)X
-1011(Philip)X
-1222(A.,)X
-2 f
-1341(Gdbm)X
-1558(1.4)X
-1679(source)X
-1913(distribu-)X
-604 2562(tion)N
-748(and)X
-888(README)X
-1 f
-1209(,)X
-1249(August)X
-1500(1990.)X
-432 2738([THOM90])N
-840(Ken)X
-1011(Thompson,)X
-1410(private)X
-1670(communication,)X
-604 2826(Nov.)N
-782(1990.)X
-432 3002([TOR87])N
-790(Torek,)X
-1066(C.,)X
-1222(``Re:)X
-1470(dbm.a)X
-1751(and)X
-1950(ndbm.a)X
-604 3090(archives'',)N
-2 f
-966(USENET)X
-1279(newsgroup)X
-1650(comp.unix)X
-1 f
-2002(1987.)X
-432 3266([TOR88])N
-760(Torek,)X
-1006(C.,)X
-1133(``Re:)X
-1351(questions)X
-1686(regarding)X
-2027(data-)X
-604 3354(bases)N
-826(created)X
-1106(with)X
-1295(dbm)X
-1484(and)X
-1647(ndbm)X
-1876(routines'')X
-2 f
-604 3442(USENET)N
-937(newsgroup)X
-1328(comp.unix.questions)X
-1 f
-1982(,)X
-2041(June)X
-604 3530(1988.)N
-432 3706([WAL84])N
-773(Wales,)X
-1018(R.,)X
-1135(``Discussion)X
-1564(of)X
-1655("dbm")X
-1887(data)X
-2045(base)X
-604 3794(system'',)N
-2 f
-973(USENET)X
-1339(newsgroup)X
-1762(unix.wizards)X
-1 f
-2168(,)X
-604 3882(January,)N
-894(1984.)X
-432 4058([YIG89])N
-751(Ozan)X
-963(S.)X
-1069(Yigit,)X
-1294(``How)X
-1545(to)X
-1648(Roll)X
-1826(Your)X
-2032(Own)X
-604 4146(Dbm/Ndbm'',)N
-2 f
-1087(unpublished)X
-1504(manuscript)X
-1 f
-(,)S
-1910(Toronto,)X
-604 4234(July,)N
-777(1989)X
-3 f
-432 5960(12)N
-2970(USENIX)X
-9 f
-3292(-)X
-3 f
-3356(Winter)X
-3621('91)X
-9 f
-3748(-)X
-3 f
-3812(Dallas,)X
-4065(TX)X
-
-13 p
-%%Page: 13 13
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-720 258(Seltzer)N
-977(&)X
-1064(Yigit)X
-3278(A)X
-3356(New)X
-3528(Hashing)X
-3831(Package)X
-4136(for)X
-4259(UNIX)X
-1 f
-720 538(Margo)N
-960(I.)X
-1033(Seltzer)X
-1282(is)X
-1361(a)X
-1423(Ph.D.)X
-1631(student)X
-1887(in)X
-1974(the)X
-2097(Department)X
-720 626(of)N
-823(Electrical)X
-1167(Engineering)X
-1595(and)X
-1747(Computer)X
-2102(Sciences)X
-2418(at)X
-720 714(the)N
-850(University)X
-1220(of)X
-1318(California,)X
-1694(Berkeley.)X
-2055(Her)X
-2207(research)X
-720 802(interests)N
-1017(include)X
-1283(\256le)X
-1415(systems,)X
-1718(databases,)X
-2076(and)X
-2221(transac-)X
-720 890(tion)N
-896(processing)X
-1291(systems.)X
-1636(She)X
-1807(spent)X
-2027(several)X
-2306(years)X
-720 978(working)N
-1026(at)X
-1123(startup)X
-1380(companies)X
-1762(designing)X
-2112(and)X
-2267(imple-)X
-720 1066(menting)N
-1048(\256le)X
-1216(systems)X
-1535(and)X
-1716(transaction)X
-2133(processing)X
-720 1154(software)N
-1026(and)X
-1170(designing)X
-1509(microprocessors.)X
-2103(Ms.)X
-2253(Seltzer)X
-720 1242(received)N
-1057(her)X
-1223(AB)X
-1397(in)X
-1522(Applied)X
-1843(Mathematics)X
-2320(from)X
-720 1330 0.1953(Harvard/Radcliffe)AN
-1325(College)X
-1594(in)X
-1676(1983.)X
-720 1444(In)N
-810(her)X
-936(spare)X
-1129(time,)X
-1313(Margo)X
-1549(can)X
-1683(usually)X
-1936(be)X
-2034(found)X
-2243(prepar-)X
-720 1532(ing)N
-868(massive)X
-1171(quantities)X
-1527(of)X
-1639(food)X
-1831(for)X
-1970(hungry)X
-2242(hoards,)X
-720 1620(studying)N
-1022(Japanese,)X
-1355(or)X
-1449(playing)X
-1716(soccer)X
-1948(with)X
-2116(an)X
-2218(exciting)X
-720 1708(Bay)N
-912(Area)X
-1132(Women's)X
-1507(Soccer)X
-1788(team,)X
-2026(the)X
-2186(Berkeley)X
-720 1796(Bruisers.)N
-720 1910(Ozan)N
-915(\()X
-3 f
-942(Oz)X
-1 f
-1040(\))X
-1092(Yigit)X
-1281(is)X
-1358(currently)X
-1672(a)X
-1732(software)X
-2033(engineer)X
-2334(with)X
-720 1998(the)N
-886(Communications)X
-1499(Research)X
-1861(and)X
-2044(Development)X
-720 2086(group,)N
-948(Computing)X
-1328(Services,)X
-1641(York)X
-1826(University.)X
-2224(His)X
-2355(for-)X
-720 2174(mative)N
-967(years)X
-1166(were)X
-1352(also)X
-1510(spent)X
-1708(at)X
-1795(York,)X
-2009(where)X
-2234(he)X
-2338(held)X
-720 2262(system)N
-985(programmer)X
-1425(and)X
-1583(administrator)X
-2052(positions)X
-2382(for)X
-720 2350(various)N
-995(mixtures)X
-1314(of)X
-1420(of)X
-1526(UNIX)X
-1765(systems)X
-2056(starting)X
-2334(with)X
-720 2438(Berkeley)N
-1031(4.1)X
-1151(in)X
-1233(1982,)X
-1433(while)X
-1631(at)X
-1709(the)X
-1827(same)X
-2012(time)X
-2174(obtaining)X
-720 2526(a)N
-776(degree)X
-1011(in)X
-1093(Computer)X
-1433(Science.)X
-720 2640(In)N
-813(his)X
-931(copious)X
-1205(free)X
-1356(time,)X
-1543(Oz)X
-1662(enjoys)X
-1896(working)X
-2188(on)X
-2293(what-)X
-720 2728(ever)N
-890(software)X
-1197(looks)X
-1400(interesting,)X
-1788(which)X
-2014(often)X
-2209(includes)X
-720 2816(language)N
-1044(interpreters,)X
-1464(preprocessors,)X
-1960(and)X
-2110(lately,)X
-2342(pro-)X
-720 2904(gram)N
-905(generators)X
-1260(and)X
-1396(expert)X
-1617(systems.)X
-720 3018(Oz)N
-836(has)X
-964(authored)X
-1266(several)X
-1515(public-domain)X
-2003(software)X
-2301(tools,)X
-720 3106(including)N
-1069(an)X
-1191(nroff-like)X
-1545(text)X
-1711(formatter)X
-2 f
-2056(proff)X
-1 f
-2257(that)X
-2423(is)X
-720 3194(apparently)N
-1083(still)X
-1226(used)X
-1397(in)X
-1483(some)X
-1676(basement)X
-2002(PCs.)X
-2173(His)X
-2307(latest)X
-720 3282(obsessions)N
-1143(include)X
-1460(the)X
-1639(incredible)X
-2040(programming)X
-720 3370(language)N
-1030(Scheme,)X
-1324(and)X
-1460(Chinese)X
-1738(Brush)X
-1949(painting.)X
-3 f
-720 5960(USENIX)N
-9 f
-1042(-)X
-3 f
-1106(Winter)X
-1371('91)X
-9 f
-1498(-)X
-3 f
-1562(Dallas,)X
-1815(TX)X
-4384(13)X
-
-14 p
-%%Page: 14 14
-0(Courier)xf 0 f
-10 s 10 xH 0 xS 0 f
-3 f
-432 5960(14)N
-2970(USENIX)X
-9 f
-3292(-)X
-3 f
-3356(Winter)X
-3621('91)X
-9 f
-3748(-)X
-3 f
-3812(Dallas,)X
-4065(TX)X
-
-14 p
-%%Trailer
-xt
-
-xs
diff --git a/lib/libc/db/doc/libtp.usenix.ps b/lib/libc/db/doc/libtp.usenix.ps
deleted file mode 100644
index ea821a9..0000000
--- a/lib/libc/db/doc/libtp.usenix.ps
+++ /dev/null
@@ -1,12340 +0,0 @@
-%!PS-Adobe-1.0
-%%Creator: utopia:margo (& Seltzer,608-13E,8072,)
-%%Title: stdin (ditroff)
-%%CreationDate: Thu Dec 12 15:32:11 1991
-%%EndComments
-% @(#)psdit.pro 1.3 4/15/88
-% lib/psdit.pro -- prolog for psdit (ditroff) files
-% Copyright (c) 1984, 1985 Adobe Systems Incorporated. All Rights Reserved.
-% last edit: shore Sat Nov 23 20:28:03 1985
-% RCSID: $Header: psdit.pro,v 2.1 85/11/24 12:19:43 shore Rel $
-
-% Changed by Edward Wang (edward@ucbarpa.berkeley.edu) to handle graphics,
-% 17 Feb, 87.
-
-/$DITroff 140 dict def $DITroff begin
-/fontnum 1 def /fontsize 10 def /fontheight 10 def /fontslant 0 def
-/xi{0 72 11 mul translate 72 resolution div dup neg scale 0 0 moveto
- /fontnum 1 def /fontsize 10 def /fontheight 10 def /fontslant 0 def F
- /pagesave save def}def
-/PB{save /psv exch def currentpoint translate
- resolution 72 div dup neg scale 0 0 moveto}def
-/PE{psv restore}def
-/arctoobig 90 def /arctoosmall .05 def
-/m1 matrix def /m2 matrix def /m3 matrix def /oldmat matrix def
-/tan{dup sin exch cos div}def
-/point{resolution 72 div mul}def
-/dround {transform round exch round exch itransform}def
-/xT{/devname exch def}def
-/xr{/mh exch def /my exch def /resolution exch def}def
-/xp{}def
-/xs{docsave restore end}def
-/xt{}def
-/xf{/fontname exch def /slotno exch def fontnames slotno get fontname eq not
- {fonts slotno fontname findfont put fontnames slotno fontname put}if}def
-/xH{/fontheight exch def F}def
-/xS{/fontslant exch def F}def
-/s{/fontsize exch def /fontheight fontsize def F}def
-/f{/fontnum exch def F}def
-/F{fontheight 0 le{/fontheight fontsize def}if
- fonts fontnum get fontsize point 0 0 fontheight point neg 0 0 m1 astore
- fontslant 0 ne{1 0 fontslant tan 1 0 0 m2 astore m3 concatmatrix}if
- makefont setfont .04 fontsize point mul 0 dround pop setlinewidth}def
-/X{exch currentpoint exch pop moveto show}def
-/N{3 1 roll moveto show}def
-/Y{exch currentpoint pop exch moveto show}def
-/S{show}def
-/ditpush{}def/ditpop{}def
-/AX{3 -1 roll currentpoint exch pop moveto 0 exch ashow}def
-/AN{4 2 roll moveto 0 exch ashow}def
-/AY{3 -1 roll currentpoint pop exch moveto 0 exch ashow}def
-/AS{0 exch ashow}def
-/MX{currentpoint exch pop moveto}def
-/MY{currentpoint pop exch moveto}def
-/MXY{moveto}def
-/cb{pop}def % action on unknown char -- nothing for now
-/n{}def/w{}def
-/p{pop showpage pagesave restore /pagesave save def}def
-/Dt{/Dlinewidth exch def}def 1 Dt
-/Ds{/Ddash exch def}def -1 Ds
-/Di{/Dstipple exch def}def 1 Di
-/Dsetlinewidth{2 Dlinewidth mul setlinewidth}def
-/Dsetdash{Ddash 4 eq{[8 12]}{Ddash 16 eq{[32 36]}
- {Ddash 20 eq{[32 12 8 12]}{[]}ifelse}ifelse}ifelse 0 setdash}def
-/Dstroke{gsave Dsetlinewidth Dsetdash 1 setlinecap stroke grestore
- currentpoint newpath moveto}def
-/Dl{rlineto Dstroke}def
-/arcellipse{/diamv exch def /diamh exch def oldmat currentmatrix pop
- currentpoint translate 1 diamv diamh div scale /rad diamh 2 div def
- currentpoint exch rad add exch rad -180 180 arc oldmat setmatrix}def
-/Dc{dup arcellipse Dstroke}def
-/De{arcellipse Dstroke}def
-/Da{/endv exch def /endh exch def /centerv exch def /centerh exch def
- /cradius centerv centerv mul centerh centerh mul add sqrt def
- /eradius endv endv mul endh endh mul add sqrt def
- /endang endv endh atan def
- /startang centerv neg centerh neg atan def
- /sweep startang endang sub dup 0 lt{360 add}if def
- sweep arctoobig gt
- {/midang startang sweep 2 div sub def /midrad cradius eradius add 2 div def
- /midh midang cos midrad mul def /midv midang sin midrad mul def
- midh neg midv neg endh endv centerh centerv midh midv Da
- Da}
- {sweep arctoosmall ge
- {/controldelt 1 sweep 2 div cos sub 3 sweep 2 div sin mul div 4 mul def
- centerv neg controldelt mul centerh controldelt mul
- endv neg controldelt mul centerh add endh add
- endh controldelt mul centerv add endv add
- centerh endh add centerv endv add rcurveto Dstroke}
- {centerh endh add centerv endv add rlineto Dstroke}
- ifelse}
- ifelse}def
-/Dpatterns[
-[%cf[widthbits]
-[8<0000000000000010>]
-[8<0411040040114000>]
-[8<0204081020408001>]
-[8<0000103810000000>]
-[8<6699996666999966>]
-[8<0000800100001008>]
-[8<81c36666c3810000>]
-[8<0f0e0c0800000000>]
-[8<0000000000000010>]
-[8<0411040040114000>]
-[8<0204081020408001>]
-[8<0000001038100000>]
-[8<6699996666999966>]
-[8<0000800100001008>]
-[8<81c36666c3810000>]
-[8<0f0e0c0800000000>]
-[8<0042660000246600>]
-[8<0000990000990000>]
-[8<0804020180402010>]
-[8<2418814242811824>]
-[8<6699996666999966>]
-[8<8000000008000000>]
-[8<00001c3e363e1c00>]
-[8<0000000000000000>]
-[32<00000040000000c00000004000000040000000e0000000000000000000000000>]
-[32<00000000000060000000900000002000000040000000f0000000000000000000>]
-[32<000000000000000000e0000000100000006000000010000000e0000000000000>]
-[32<00000000000000002000000060000000a0000000f00000002000000000000000>]
-[32<0000000e0000000000000000000000000000000f000000080000000e00000001>]
-[32<0000090000000600000000000000000000000000000007000000080000000e00>]
-[32<00010000000200000004000000040000000000000000000000000000000f0000>]
-[32<0900000006000000090000000600000000000000000000000000000006000000>]]
-[%ug
-[8<0000020000000000>]
-[8<0000020000002000>]
-[8<0004020000002000>]
-[8<0004020000402000>]
-[8<0004060000402000>]
-[8<0004060000406000>]
-[8<0006060000406000>]
-[8<0006060000606000>]
-[8<00060e0000606000>]
-[8<00060e000060e000>]
-[8<00070e000060e000>]
-[8<00070e000070e000>]
-[8<00070e020070e000>]
-[8<00070e020070e020>]
-[8<04070e020070e020>]
-[8<04070e024070e020>]
-[8<04070e064070e020>]
-[8<04070e064070e060>]
-[8<06070e064070e060>]
-[8<06070e066070e060>]
-[8<06070f066070e060>]
-[8<06070f066070f060>]
-[8<060f0f066070f060>]
-[8<060f0f0660f0f060>]
-[8<060f0f0760f0f060>]
-[8<060f0f0760f0f070>]
-[8<0e0f0f0760f0f070>]
-[8<0e0f0f07e0f0f070>]
-[8<0e0f0f0fe0f0f070>]
-[8<0e0f0f0fe0f0f0f0>]
-[8<0f0f0f0fe0f0f0f0>]
-[8<0f0f0f0ff0f0f0f0>]
-[8<1f0f0f0ff0f0f0f0>]
-[8<1f0f0f0ff1f0f0f0>]
-[8<1f0f0f8ff1f0f0f0>]
-[8<1f0f0f8ff1f0f0f8>]
-[8<9f0f0f8ff1f0f0f8>]
-[8<9f0f0f8ff9f0f0f8>]
-[8<9f0f0f9ff9f0f0f8>]
-[8<9f0f0f9ff9f0f0f9>]
-[8<9f8f0f9ff9f0f0f9>]
-[8<9f8f0f9ff9f8f0f9>]
-[8<9f8f1f9ff9f8f0f9>]
-[8<9f8f1f9ff9f8f1f9>]
-[8<bf8f1f9ff9f8f1f9>]
-[8<bf8f1f9ffbf8f1f9>]
-[8<bf8f1fdffbf8f1f9>]
-[8<bf8f1fdffbf8f1fd>]
-[8<ff8f1fdffbf8f1fd>]
-[8<ff8f1fdffff8f1fd>]
-[8<ff8f1ffffff8f1fd>]
-[8<ff8f1ffffff8f1ff>]
-[8<ff9f1ffffff8f1ff>]
-[8<ff9f1ffffff9f1ff>]
-[8<ff9f9ffffff9f1ff>]
-[8<ff9f9ffffff9f9ff>]
-[8<ffbf9ffffff9f9ff>]
-[8<ffbf9ffffffbf9ff>]
-[8<ffbfdffffffbf9ff>]
-[8<ffbfdffffffbfdff>]
-[8<ffffdffffffbfdff>]
-[8<ffffdffffffffdff>]
-[8<fffffffffffffdff>]
-[8<ffffffffffffffff>]]
-[%mg
-[8<8000000000000000>]
-[8<0822080080228000>]
-[8<0204081020408001>]
-[8<40e0400000000000>]
-[8<66999966>]
-[8<8001000010080000>]
-[8<81c36666c3810000>]
-[8<f0e0c08000000000>]
-[16<07c00f801f003e007c00f800f001e003c007800f001f003e007c00f801f003e0>]
-[16<1f000f8007c003e001f000f8007c003e001f800fc007e003f001f8007c003e00>]
-[8<c3c300000000c3c3>]
-[16<0040008001000200040008001000200040008000000100020004000800100020>]
-[16<0040002000100008000400020001800040002000100008000400020001000080>]
-[16<1fc03fe07df0f8f8f07de03fc01f800fc01fe03ff07df8f87df03fe01fc00f80>]
-[8<80>]
-[8<8040201000000000>]
-[8<84cc000048cc0000>]
-[8<9900009900000000>]
-[8<08040201804020100800020180002010>]
-[8<2418814242811824>]
-[8<66999966>]
-[8<8000000008000000>]
-[8<70f8d8f870000000>]
-[8<0814224180402010>]
-[8<aa00440a11a04400>]
-[8<018245aa45820100>]
-[8<221c224180808041>]
-[8<88000000>]
-[8<0855800080550800>]
-[8<2844004482440044>]
-[8<0810204080412214>]
-[8<00>]]]def
-/Dfill{
- transform /maxy exch def /maxx exch def
- transform /miny exch def /minx exch def
- minx maxx gt{/minx maxx /maxx minx def def}if
- miny maxy gt{/miny maxy /maxy miny def def}if
- Dpatterns Dstipple 1 sub get exch 1 sub get
- aload pop /stip exch def /stipw exch def /stiph 128 def
- /imatrix[stipw 0 0 stiph 0 0]def
- /tmatrix[stipw 0 0 stiph 0 0]def
- /minx minx cvi stiph idiv stiph mul def
- /miny miny cvi stipw idiv stipw mul def
- gsave eoclip 0 setgray
- miny stiph maxy{
- tmatrix exch 5 exch put
- minx stipw maxx{
- tmatrix exch 4 exch put tmatrix setmatrix
- stipw stiph true imatrix {stip} imagemask
- }for
- }for
- grestore
-}def
-/Dp{Dfill Dstroke}def
-/DP{Dfill currentpoint newpath moveto}def
-end
-
-/ditstart{$DITroff begin
- /nfonts 60 def % NFONTS makedev/ditroff dependent!
- /fonts[nfonts{0}repeat]def
- /fontnames[nfonts{()}repeat]def
-/docsave save def
-}def
-
-% character outcalls
-/oc{
- /pswid exch def /cc exch def /name exch def
- /ditwid pswid fontsize mul resolution mul 72000 div def
- /ditsiz fontsize resolution mul 72 div def
- ocprocs name known{ocprocs name get exec}{name cb}ifelse
-}def
-/fractm [.65 0 0 .6 0 0] def
-/fraction{
- /fden exch def /fnum exch def gsave /cf currentfont def
- cf fractm makefont setfont 0 .3 dm 2 copy neg rmoveto
- fnum show rmoveto currentfont cf setfont(\244)show setfont fden show
- grestore ditwid 0 rmoveto
-}def
-/oce{grestore ditwid 0 rmoveto}def
-/dm{ditsiz mul}def
-/ocprocs 50 dict def ocprocs begin
-(14){(1)(4)fraction}def
-(12){(1)(2)fraction}def
-(34){(3)(4)fraction}def
-(13){(1)(3)fraction}def
-(23){(2)(3)fraction}def
-(18){(1)(8)fraction}def
-(38){(3)(8)fraction}def
-(58){(5)(8)fraction}def
-(78){(7)(8)fraction}def
-(sr){gsave 0 .06 dm rmoveto(\326)show oce}def
-(is){gsave 0 .15 dm rmoveto(\362)show oce}def
-(->){gsave 0 .02 dm rmoveto(\256)show oce}def
-(<-){gsave 0 .02 dm rmoveto(\254)show oce}def
-(==){gsave 0 .05 dm rmoveto(\272)show oce}def
-(uc){gsave currentpoint 400 .009 dm mul add translate
- 8 -8 scale ucseal oce}def
-end
-
-% an attempt at a PostScript FONT to implement ditroff special chars
-% this will enable us to
-% cache the little buggers
-% generate faster, more compact PS out of psdit
-% confuse everyone (including myself)!
-50 dict dup begin
-/FontType 3 def
-/FontName /DIThacks def
-/FontMatrix [.001 0 0 .001 0 0] def
-/FontBBox [-260 -260 900 900] def% a lie but ...
-/Encoding 256 array def
-0 1 255{Encoding exch /.notdef put}for
-Encoding
- dup 8#040/space put %space
- dup 8#110/rc put %right ceil
- dup 8#111/lt put %left top curl
- dup 8#112/bv put %bold vert
- dup 8#113/lk put %left mid curl
- dup 8#114/lb put %left bot curl
- dup 8#115/rt put %right top curl
- dup 8#116/rk put %right mid curl
- dup 8#117/rb put %right bot curl
- dup 8#120/rf put %right floor
- dup 8#121/lf put %left floor
- dup 8#122/lc put %left ceil
- dup 8#140/sq put %square
- dup 8#141/bx put %box
- dup 8#142/ci put %circle
- dup 8#143/br put %box rule
- dup 8#144/rn put %root extender
- dup 8#145/vr put %vertical rule
- dup 8#146/ob put %outline bullet
- dup 8#147/bu put %bullet
- dup 8#150/ru put %rule
- dup 8#151/ul put %underline
- pop
-/DITfd 100 dict def
-/BuildChar{0 begin
- /cc exch def /fd exch def
- /charname fd /Encoding get cc get def
- /charwid fd /Metrics get charname get def
- /charproc fd /CharProcs get charname get def
- charwid 0 fd /FontBBox get aload pop setcachedevice
- 2 setlinejoin 40 setlinewidth
- newpath 0 0 moveto gsave charproc grestore
- end}def
-/BuildChar load 0 DITfd put
-/CharProcs 50 dict def
-CharProcs begin
-/space{}def
-/.notdef{}def
-/ru{500 0 rls}def
-/rn{0 840 moveto 500 0 rls}def
-/vr{0 800 moveto 0 -770 rls}def
-/bv{0 800 moveto 0 -1000 rls}def
-/br{0 840 moveto 0 -1000 rls}def
-/ul{0 -140 moveto 500 0 rls}def
-/ob{200 250 rmoveto currentpoint newpath 200 0 360 arc closepath stroke}def
-/bu{200 250 rmoveto currentpoint newpath 200 0 360 arc closepath fill}def
-/sq{80 0 rmoveto currentpoint dround newpath moveto
- 640 0 rlineto 0 640 rlineto -640 0 rlineto closepath stroke}def
-/bx{80 0 rmoveto currentpoint dround newpath moveto
- 640 0 rlineto 0 640 rlineto -640 0 rlineto closepath fill}def
-/ci{500 360 rmoveto currentpoint newpath 333 0 360 arc
- 50 setlinewidth stroke}def
-
-/lt{0 -200 moveto 0 550 rlineto currx 800 2cx s4 add exch s4 a4p stroke}def
-/lb{0 800 moveto 0 -550 rlineto currx -200 2cx s4 add exch s4 a4p stroke}def
-/rt{0 -200 moveto 0 550 rlineto currx 800 2cx s4 sub exch s4 a4p stroke}def
-/rb{0 800 moveto 0 -500 rlineto currx -200 2cx s4 sub exch s4 a4p stroke}def
-/lk{0 800 moveto 0 300 -300 300 s4 arcto pop pop 1000 sub
- 0 300 4 2 roll s4 a4p 0 -200 lineto stroke}def
-/rk{0 800 moveto 0 300 s2 300 s4 arcto pop pop 1000 sub
- 0 300 4 2 roll s4 a4p 0 -200 lineto stroke}def
-/lf{0 800 moveto 0 -1000 rlineto s4 0 rls}def
-/rf{0 800 moveto 0 -1000 rlineto s4 neg 0 rls}def
-/lc{0 -200 moveto 0 1000 rlineto s4 0 rls}def
-/rc{0 -200 moveto 0 1000 rlineto s4 neg 0 rls}def
-end
-
-/Metrics 50 dict def Metrics begin
-/.notdef 0 def
-/space 500 def
-/ru 500 def
-/br 0 def
-/lt 416 def
-/lb 416 def
-/rt 416 def
-/rb 416 def
-/lk 416 def
-/rk 416 def
-/rc 416 def
-/lc 416 def
-/rf 416 def
-/lf 416 def
-/bv 416 def
-/ob 350 def
-/bu 350 def
-/ci 750 def
-/bx 750 def
-/sq 750 def
-/rn 500 def
-/ul 500 def
-/vr 0 def
-end
-
-DITfd begin
-/s2 500 def /s4 250 def /s3 333 def
-/a4p{arcto pop pop pop pop}def
-/2cx{2 copy exch}def
-/rls{rlineto stroke}def
-/currx{currentpoint pop}def
-/dround{transform round exch round exch itransform} def
-end
-end
-/DIThacks exch definefont pop
-ditstart
-(psc)xT
-576 1 1 xr
-1(Times-Roman)xf 1 f
-2(Times-Italic)xf 2 f
-3(Times-Bold)xf 3 f
-4(Times-BoldItalic)xf 4 f
-5(Helvetica)xf 5 f
-6(Helvetica-Bold)xf 6 f
-7(Courier)xf 7 f
-8(Courier-Bold)xf 8 f
-9(Symbol)xf 9 f
-10(DIThacks)xf 10 f
-10 s
-1 f
-xi
-%%EndProlog
-
-%%Page: 1 1
-10 s 10 xH 0 xS 1 f
-3 f
-14 s
-1205 1206(LIBTP:)N
-1633(Portable,)X
-2100(M)X
-2206(odular)X
-2551(Transactions)X
-3202(for)X
-3374(UNIX)X
-1 f
-11 s
-3661 1162(1)N
-2 f
-12 s
-2182 1398(Margo)N
-2467(Seltzer)X
-2171 1494(Michael)N
-2511(Olson)X
-1800 1590(University)N
-2225(of)X
-2324(California,)X
-2773(Berkeley)X
-3 f
-2277 1878(Abstract)N
-1 f
-10 s
-755 2001(Transactions)N
-1198(provide)X
-1475(a)X
-1543(useful)X
-1771(programming)X
-2239(paradigm)X
-2574(for)X
-2700(maintaining)X
-3114(logical)X
-3364(consistency,)X
-3790(arbitrating)X
-4156(con-)X
-555 2091(current)N
-808(access,)X
-1059(and)X
-1200(managing)X
-1540(recovery.)X
-1886(In)X
-1977(traditional)X
-2330(UNIX)X
-2555(systems,)X
-2852(the)X
-2974(only)X
-3140(easy)X
-3307(way)X
-3465(of)X
-3556(using)X
-3753(transactions)X
-4160(is)X
-4237(to)X
-555 2181(purchase)N
-876(a)X
-947(database)X
-1258(system.)X
-1554(Such)X
-1748(systems)X
-2035(are)X
-2168(often)X
-2367(slow,)X
-2572(costly,)X
-2817(and)X
-2967(may)X
-3139(not)X
-3275(provide)X
-3554(the)X
-3686(exact)X
-3890(functionality)X
-555 2271(desired.)N
-848(This)X
-1011(paper)X
-1210(presents)X
-1493(the)X
-1611(design,)X
-1860(implementation,)X
-2402(and)X
-2538(performance)X
-2965(of)X
-3052(LIBTP,)X
-3314(a)X
-3370(simple,)X
-3623(non-proprietary)X
-4147(tran-)X
-555 2361(saction)N
-809(library)X
-1050(using)X
-1249(the)X
-1373(4.4BSD)X
-1654(database)X
-1957(access)X
-2189(routines)X
-2473(\()X
-3 f
-2500(db)X
-1 f
-2588(\(3\)\).)X
-2775(On)X
-2899(a)X
-2961(conventional)X
-3401(transaction)X
-3779(processing)X
-4148(style)X
-555 2451(benchmark,)N
-959(its)X
-1061(performance)X
-1495(is)X
-1575(approximately)X
-2065(85%)X
-2239(that)X
-2386(of)X
-2480(the)X
-2604(database)X
-2907(access)X
-3139(routines)X
-3423(without)X
-3693(transaction)X
-4071(protec-)X
-555 2541(tion,)N
-725(200%)X
-938(that)X
-1084(of)X
-1177(using)X
-3 f
-1376(fsync)X
-1 f
-1554(\(2\))X
-1674(to)X
-1761(commit)X
-2030(modi\256cations)X
-2490(to)X
-2577(disk,)X
-2755(and)X
-2896(125%)X
-3108(that)X
-3253(of)X
-3345(a)X
-3406(commercial)X
-3810(relational)X
-4138(data-)X
-555 2631(base)N
-718(system.)X
-3 f
-555 2817(1.)N
-655(Introduction)X
-1 f
-755 2940(Transactions)N
-1186(are)X
-1306(used)X
-1474(in)X
-1557(database)X
-1855(systems)X
-2129(to)X
-2212(enable)X
-2443(concurrent)X
-2807(users)X
-2992(to)X
-3074(apply)X
-3272(multi-operation)X
-3790(updates)X
-4055(without)X
-555 3030(violating)N
-863(the)X
-985(integrity)X
-1280(of)X
-1371(the)X
-1493(database.)X
-1814(They)X
-2003(provide)X
-2271(the)X
-2392(properties)X
-2736(of)X
-2826(atomicity,)X
-3171(consistency,)X
-3588(isolation,)X
-3906(and)X
-4045(durabil-)X
-555 3120(ity.)N
-701(By)X
-816(atomicity,)X
-1160(we)X
-1276(mean)X
-1472(that)X
-1614(the)X
-1734(set)X
-1845(of)X
-1934(updates)X
-2200(comprising)X
-2581(a)X
-2638(transaction)X
-3011(must)X
-3187(be)X
-3284(applied)X
-3541(as)X
-3629(a)X
-3686(single)X
-3898(unit;)X
-4085(that)X
-4226(is,)X
-555 3210(they)N
-714(must)X
-890(either)X
-1094(all)X
-1195(be)X
-1292(applied)X
-1549(to)X
-1632(the)X
-1751(database)X
-2049(or)X
-2137(all)X
-2238(be)X
-2335(absent.)X
-2601(Consistency)X
-3013(requires)X
-3293(that)X
-3434(a)X
-3491(transaction)X
-3864(take)X
-4019(the)X
-4138(data-)X
-555 3300(base)N
-725(from)X
-908(one)X
-1051(logically)X
-1358(consistent)X
-1704(state)X
-1877(to)X
-1965(another.)X
-2272(The)X
-2423(property)X
-2721(of)X
-2814(isolation)X
-3115(requires)X
-3400(that)X
-3546(concurrent)X
-3916(transactions)X
-555 3390(yield)N
-750(results)X
-994(which)X
-1225(are)X
-1358(indistinguishable)X
-1938(from)X
-2128(the)X
-2260(results)X
-2503(which)X
-2733(would)X
-2967(be)X
-3077(obtained)X
-3387(by)X
-3501(running)X
-3784(the)X
-3916(transactions)X
-555 3480(sequentially.)N
-1002(Finally,)X
-1268(durability)X
-1599(requires)X
-1878(that)X
-2018(once)X
-2190(transactions)X
-2593(have)X
-2765(been)X
-2937(committed,)X
-3319(their)X
-3486(results)X
-3715(must)X
-3890(be)X
-3986(preserved)X
-555 3570(across)N
-776(system)X
-1018(failures)X
-1279([TPCB90].)X
-755 3693(Although)N
-1080(these)X
-1268(properties)X
-1612(are)X
-1734(most)X
-1912(frequently)X
-2265(discussed)X
-2595(in)X
-2680(the)X
-2801(context)X
-3060(of)X
-3150(databases,)X
-3501(they)X
-3661(are)X
-3782(useful)X
-4000(program-)X
-555 3783(ming)N
-750(paradigms)X
-1114(for)X
-1238(more)X
-1433(general)X
-1700(purpose)X
-1984(applications.)X
-2441(There)X
-2659(are)X
-2788(several)X
-3046(different)X
-3353(situations)X
-3689(where)X
-3916(transactions)X
-555 3873(can)N
-687(be)X
-783(used)X
-950(to)X
-1032(replace)X
-1285(current)X
-1533(ad-hoc)X
-1772(mechanisms.)X
-755 3996(One)N
-910(situation)X
-1206(is)X
-1280(when)X
-1475(multiple)X
-1762(\256les)X
-1916(or)X
-2004(parts)X
-2181(of)X
-2269(\256les)X
-2422(need)X
-2594(to)X
-2676(be)X
-2772(updated)X
-3046(in)X
-3128(an)X
-3224(atomic)X
-3462(fashion.)X
-3758(For)X
-3889(example,)X
-4201(the)X
-555 4086(traditional)N
-907(UNIX)X
-1131(\256le)X
-1256(system)X
-1501(uses)X
-1661(ordering)X
-1955(constraints)X
-2324(to)X
-2408(achieve)X
-2676(recoverability)X
-3144(in)X
-3228(the)X
-3348(face)X
-3505(of)X
-3594(crashes.)X
-3893(When)X
-4107(a)X
-4165(new)X
-555 4176(\256le)N
-678(is)X
-752(created,)X
-1026(its)X
-1122(inode)X
-1321(is)X
-1395(written)X
-1642(to)X
-1724(disk)X
-1877(before)X
-2103(the)X
-2221(new)X
-2375(\256le)X
-2497(is)X
-2570(added)X
-2782(to)X
-2864(the)X
-2982(directory)X
-3292(structure.)X
-3633(This)X
-3795(guarantees)X
-4159(that,)X
-555 4266(if)N
-627(the)X
-748(system)X
-993(crashes)X
-1253(between)X
-1544(the)X
-1665(two)X
-1808(I/O's,)X
-2016(the)X
-2137(directory)X
-2450(does)X
-2620(not)X
-2744(contain)X
-3002(a)X
-3060 0.4531(reference)AX
-3383(to)X
-3467(an)X
-3565(invalid)X
-3809(inode.)X
-4049(In)X
-4138(actu-)X
-555 4356(ality,)N
-741(the)X
-863(desired)X
-1119(effect)X
-1326(is)X
-1402(that)X
-1545(these)X
-1733(two)X
-1876(updates)X
-2144(have)X
-2319(the)X
-2440(transactional)X
-2873(property)X
-3168(of)X
-3258(atomicity)X
-3583(\(either)X
-3816(both)X
-3981(writes)X
-4200(are)X
-555 4446(visible)N
-790(or)X
-879(neither)X
-1124(is\).)X
-1266(Rather)X
-1501(than)X
-1660(building)X
-1947(special)X
-2191(purpose)X
-2466(recovery)X
-2769(mechanisms)X
-3186(into)X
-3331(the)X
-3450(\256le)X
-3573(system)X
-3816(or)X
-3904(related)X
-4144(tools)X
-555 4536(\()N
-2 f
-582(e.g.)X
-3 f
-726(fsck)X
-1 f
-864(\(8\)\),)X
-1033(one)X
-1177(could)X
-1383(use)X
-1518(general)X
-1783(purpose)X
-2064(transaction)X
-2443(recovery)X
-2752(protocols)X
-3077(after)X
-3252(system)X
-3501(failure.)X
-3778(Any)X
-3943(application)X
-555 4626(that)N
-705(needs)X
-918(to)X
-1010(keep)X
-1192(multiple,)X
-1508(related)X
-1757(\256les)X
-1920(\(or)X
-2044(directories\))X
-2440(consistent)X
-2790(should)X
-3032(do)X
-3141(so)X
-3241(using)X
-3443(transactions.)X
-3895(Source)X
-4147(code)X
-555 4716(control)N
-805(systems,)X
-1101(such)X
-1271(as)X
-1361(RCS)X
-1534(and)X
-1673(SCCS,)X
-1910(should)X
-2146(use)X
-2276(transaction)X
-2651(semantics)X
-2990(to)X
-3075(allow)X
-3276(the)X
-3397(``checking)X
-3764(in'')X
-3903(of)X
-3992(groups)X
-4232(of)X
-555 4806(related)N
-801(\256les.)X
-1001(In)X
-1095(this)X
-1237(way,)X
-1418(if)X
-1493(the)X
-1617 0.2841(``check-in'')AX
-2028(fails,)X
-2212(the)X
-2336(transaction)X
-2714(may)X
-2878(be)X
-2980(aborted,)X
-3267(backing)X
-3547(out)X
-3675(the)X
-3799(partial)X
-4030(``check-)X
-555 4896(in'')N
-691(leaving)X
-947(the)X
-1065(source)X
-1295(repository)X
-1640(in)X
-1722(a)X
-1778(consistent)X
-2118(state.)X
-755 5019(A)N
-842(second)X
-1094(situation)X
-1398(where)X
-1624(transactions)X
-2036(can)X
-2177(be)X
-2282(used)X
-2458(to)X
-2549(replace)X
-2811(current)X
-3068(ad-hoc)X
-3316(mechanisms)X
-3741(is)X
-3822(in)X
-3912(applications)X
-555 5109(where)N
-776(concurrent)X
-1144(updates)X
-1413(to)X
-1499(a)X
-1559(shared)X
-1793(\256le)X
-1919(are)X
-2042(desired,)X
-2318(but)X
-2444(there)X
-2629(is)X
-2706(logical)X
-2948(consistency)X
-3345(of)X
-3435(the)X
-3556(data)X
-3713(which)X
-3932(needs)X
-4138(to)X
-4223(be)X
-555 5199(preserved.)N
-928(For)X
-1059(example,)X
-1371(when)X
-1565(the)X
-1683(password)X
-2006(\256le)X
-2128(is)X
-2201(updated,)X
-2495(\256le)X
-2617(locking)X
-2877(is)X
-2950(used)X
-3117(to)X
-3199(disallow)X
-3490(concurrent)X
-3854(access.)X
-4120(Tran-)X
-555 5289(saction)N
-804(semantics)X
-1142(on)X
-1244(the)X
-1364(password)X
-1689(\256les)X
-1844(would)X
-2066(allow)X
-2266(concurrent)X
-2632(updates,)X
-2919(while)X
-3119(preserving)X
-3479(the)X
-3598(logical)X
-3837(consistency)X
-4232(of)X
-555 5379(the)N
-681(password)X
-1012(database.)X
-1357(Similarly,)X
-1702(UNIX)X
-1930(utilities)X
-2196(which)X
-2419(rewrite)X
-2674(\256les)X
-2834(face)X
-2996(a)X
-3059(potential)X
-3366(race)X
-3528(condition)X
-3857(between)X
-4152(their)X
-555 5469(rewriting)N
-871(a)X
-929(\256le)X
-1053(and)X
-1191(another)X
-1453(process)X
-1715(reading)X
-1977(the)X
-2096(\256le.)X
-2259(For)X
-2391(example,)X
-2704(the)X
-2823(compiler)X
-3129(\(more)X
-3342(precisely,)X
-3673(the)X
-3792(assembler\))X
-4161(may)X
-8 s
-10 f
-555 5541(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)N
-5 s
-1 f
-727 5619(1)N
-8 s
-763 5644(To)N
-850(appear)X
-1035(in)X
-1101(the)X
-2 f
-1195(Proceedings)X
-1530(of)X
-1596(the)X
-1690(1992)X
-1834(Winter)X
-2024(Usenix)X
-1 f
-2201(,)X
-2233(San)X
-2345(Francisco,)X
-2625(CA,)X
-2746(January)X
-2960(1992.)X
-
-2 p
-%%Page: 2 2
-8 s 8 xH 0 xS 1 f
-10 s
-3 f
-1 f
-555 630(have)N
-737(to)X
-829(rewrite)X
-1087(a)X
-1152(\256le)X
-1283(to)X
-1374(which)X
-1599(it)X
-1672(has)X
-1808(write)X
-2002(permission)X
-2382(in)X
-2473(a)X
-2538(directory)X
-2857(to)X
-2948(which)X
-3173(it)X
-3246(does)X
-3422(not)X
-3553(have)X
-3734(write)X
-3928(permission.)X
-555 720(While)N
-779(the)X
-904(``.o'')X
-1099(\256le)X
-1228(is)X
-1308(being)X
-1513(written,)X
-1787(another)X
-2055(utility)X
-2272(such)X
-2446(as)X
-3 f
-2540(nm)X
-1 f
-2651(\(1\))X
-2772(or)X
-3 f
-2866(ar)X
-1 f
-2942(\(1\))X
-3063(may)X
-3228(read)X
-3394(the)X
-3519(\256le)X
-3648(and)X
-3791(produce)X
-4077(invalid)X
-555 810(results)N
-790(since)X
-981(the)X
-1105(\256le)X
-1233(has)X
-1366(not)X
-1494(been)X
-1672(completely)X
-2054(written.)X
-2347(Currently,)X
-2700(some)X
-2895(utilities)X
-3160(use)X
-3293(special)X
-3542(purpose)X
-3821(code)X
-3998(to)X
-4085(handle)X
-555 900(such)N
-722(cases)X
-912(while)X
-1110(others)X
-1326(ignore)X
-1551(the)X
-1669(problem)X
-1956(and)X
-2092(force)X
-2278(users)X
-2463(to)X
-2545(live)X
-2685(with)X
-2847(the)X
-2965(consequences.)X
-755 1023(In)N
-845(this)X
-983(paper,)X
-1205(we)X
-1322(present)X
-1577(a)X
-1635(simple)X
-1870(library)X
-2106(which)X
-2324(provides)X
-2622(transaction)X
-2996(semantics)X
-3334(\(atomicity,)X
-3705(consistency,)X
-4121(isola-)X
-555 1113(tion,)N
-720(and)X
-857(durability\).)X
-1236(The)X
-1382(4.4BSD)X
-1658(database)X
-1956(access)X
-2182(methods)X
-2473(have)X
-2645(been)X
-2817(modi\256ed)X
-3121(to)X
-3203(use)X
-3330(this)X
-3465(library,)X
-3719(optionally)X
-4063(provid-)X
-555 1203(ing)N
-682(shared)X
-917(buffer)X
-1139(management)X
-1574(between)X
-1867(applications,)X
-2298(locking,)X
-2582(and)X
-2722(transaction)X
-3098(semantics.)X
-3478(Any)X
-3640(UNIX)X
-3865(program)X
-4161(may)X
-555 1293(transaction)N
-930(protect)X
-1176(its)X
-1274(data)X
-1430(by)X
-1532(requesting)X
-1888(transaction)X
-2262(protection)X
-2609(with)X
-2773(the)X
-3 f
-2893(db)X
-1 f
-2981(\(3\))X
-3097(library)X
-3333(or)X
-3422(by)X
-3524(adding)X
-3764(appropriate)X
-4152(calls)X
-555 1383(to)N
-646(the)X
-773(transaction)X
-1154(manager,)X
-1480(buffer)X
-1706(manager,)X
-2032(lock)X
-2199(manager,)X
-2525(and)X
-2670(log)X
-2801(manager.)X
-3147(The)X
-3301(library)X
-3543(routines)X
-3829(may)X
-3995(be)X
-4099(linked)X
-555 1473(into)N
-708(the)X
-834(host)X
-995(application)X
-1379(and)X
-1523(called)X
-1743(by)X
-1851(subroutine)X
-2217(interface,)X
-2547(or)X
-2642(they)X
-2808(may)X
-2974(reside)X
-3194(in)X
-3284(a)X
-3348(separate)X
-3640(server)X
-3865(process.)X
-4174(The)X
-555 1563(server)N
-772(architecture)X
-1172(provides)X
-1468(for)X
-1582(network)X
-1865(access)X
-2091(and)X
-2227(better)X
-2430(protection)X
-2775(mechanisms.)X
-3 f
-555 1749(2.)N
-655(Related)X
-938(Work)X
-1 f
-755 1872(There)N
-1000(has)X
-1164(been)X
-1373(much)X
-1608(discussion)X
-1998(in)X
-2117(recent)X
-2371(years)X
-2597(about)X
-2831(new)X
-3021(transaction)X
-3429(models)X
-3716(and)X
-3888(architectures)X
-555 1962 0.1172([SPEC88][NODI90][CHEN91][MOHA91].)AN
-2009(Much)X
-2220(of)X
-2310(this)X
-2448(work)X
-2636(focuses)X
-2900(on)X
-3003(new)X
-3160(ways)X
-3348(to)X
-3433(model)X
-3656(transactions)X
-4062(and)X
-4201(the)X
-555 2052(interactions)N
-953(between)X
-1245(them,)X
-1449(while)X
-1651(the)X
-1772(work)X
-1960(presented)X
-2291(here)X
-2453(focuses)X
-2717(on)X
-2820(the)X
-2941(implementation)X
-3466(and)X
-3605(performance)X
-4035(of)X
-4125(tradi-)X
-555 2142(tional)N
-757(transaction)X
-1129(techniques)X
-1492(\(write-ahead)X
-1919(logging)X
-2183(and)X
-2319(two-phase)X
-2669(locking\))X
-2956(on)X
-3056(a)X
-3112(standard)X
-3404(operating)X
-3727(system)X
-3969(\(UNIX\).)X
-755 2265(Such)N
-947(traditional)X
-1308(operating)X
-1643(systems)X
-1928(are)X
-2059(often)X
-2256(criticized)X
-2587(for)X
-2713(their)X
-2892(inability)X
-3190(to)X
-3283(perform)X
-3573(transaction)X
-3956(processing)X
-555 2355(adequately.)N
-971([STON81])X
-1342(cites)X
-1517(three)X
-1706(main)X
-1894(areas)X
-2088(of)X
-2183(inadequate)X
-2559(support:)X
-2849(buffer)X
-3074(management,)X
-3532(the)X
-3658(\256le)X
-3788(system,)X
-4058(and)X
-4201(the)X
-555 2445(process)N
-823(structure.)X
-1191(These)X
-1410(arguments)X
-1771(are)X
-1897(summarized)X
-2316(in)X
-2405(table)X
-2587(one.)X
-2769(Fortunately,)X
-3184(much)X
-3388(has)X
-3521(changed)X
-3815(since)X
-4006(1981.)X
-4232(In)X
-555 2535(the)N
-683(area)X
-848(of)X
-945(buffer)X
-1172(management,)X
-1632(most)X
-1817(UNIX)X
-2048(systems)X
-2331(provide)X
-2606(the)X
-2734(ability)X
-2968(to)X
-3060(memory)X
-3357(map)X
-3525(\256les,)X
-3708(thus)X
-3870(obviating)X
-4201(the)X
-555 2625(need)N
-734(for)X
-855(a)X
-918(copy)X
-1101(between)X
-1396(kernel)X
-1624(and)X
-1766(user)X
-1926(space.)X
-2171(If)X
-2251(a)X
-2313(database)X
-2616(system)X
-2864(is)X
-2943(going)X
-3151(to)X
-3239(use)X
-3372(the)X
-3496(\256le)X
-3624(system)X
-3872(buffer)X
-4095(cache,)X
-555 2715(then)N
-719(a)X
-781(system)X
-1029(call)X
-1171(is)X
-1250(required.)X
-1584(However,)X
-1924(if)X
-1998(buffering)X
-2322(is)X
-2400(provided)X
-2710(at)X
-2793(user)X
-2952(level)X
-3133(using)X
-3331(shared)X
-3566(memory,)X
-3878(as)X
-3970(in)X
-4057(LIBTP,)X
-555 2805(buffer)N
-776(management)X
-1210(is)X
-1287(only)X
-1452(as)X
-1542(slow)X
-1716(as)X
-1806(access)X
-2035(to)X
-2120(shared)X
-2353(memory)X
-2643(and)X
-2782(any)X
-2921(replacement)X
-3337(algorithm)X
-3671(may)X
-3832(be)X
-3931(used.)X
-4121(Since)X
-555 2895(multiple)N
-849(processes)X
-1185(can)X
-1325(access)X
-1559(the)X
-1685(shared)X
-1923(data,)X
-2105(prefetching)X
-2499(may)X
-2665(be)X
-2769(accomplished)X
-3238(by)X
-3346(separate)X
-3638(processes)X
-3973(or)X
-4067(threads)X
-555 2985(whose)N
-782(sole)X
-932(purpose)X
-1207(is)X
-1281(to)X
-1364(prefetch)X
-1649(pages)X
-1853(and)X
-1990(wait)X
-2149(on)X
-2250(them.)X
-2471(There)X
-2680(is)X
-2754(still)X
-2894(no)X
-2995(way)X
-3150(to)X
-3233(enforce)X
-3496(write)X
-3682(ordering)X
-3975(other)X
-4161(than)X
-555 3075(keeping)N
-829(pages)X
-1032(in)X
-1114(user)X
-1268(memory)X
-1555(and)X
-1691(using)X
-1884(the)X
-3 f
-2002(fsync)X
-1 f
-2180(\(3\))X
-2294(system)X
-2536(call)X
-2672(to)X
-2754(perform)X
-3033(synchronous)X
-3458(writes.)X
-755 3198(In)N
-845(the)X
-966(area)X
-1124(of)X
-1214(\256le)X
-1339(systems,)X
-1635(the)X
-1756(fast)X
-1895(\256le)X
-2020(system)X
-2265(\(FFS\))X
-2474([MCKU84])X
-2871(allows)X
-3103(allocation)X
-3442(in)X
-3527(units)X
-3704(up)X
-3806(to)X
-3890(64KBytes)X
-4232(as)X
-555 3288(opposed)N
-846(to)X
-932(the)X
-1054(4KByte)X
-1327(and)X
-1466(8KByte)X
-1738(\256gures)X
-1979(quoted)X
-2220(in)X
-2305([STON81].)X
-2711(The)X
-2859(measurements)X
-3341(in)X
-3426(this)X
-3564(paper)X
-3766(were)X
-3946(taken)X
-4143(from)X
-555 3378(an)N
-655(8KByte)X
-928(FFS,)X
-1104(but)X
-1230(as)X
-1320(LIBTP)X
-1565(runs)X
-1726(exclusively)X
-2114(in)X
-2199(user)X
-2356(space,)X
-2578(there)X
-2762(is)X
-2838(nothing)X
-3105(to)X
-3190(prevent)X
-3454(it)X
-3521(from)X
-3700(being)X
-3901(run)X
-4031(on)X
-4134(other)X
-555 3468(UNIX)N
-776(compatible)X
-1152(\256le)X
-1274(systems)X
-1547(\(e.g.)X
-1710(log-structured)X
-2180([ROSE91],)X
-2558(extent-based,)X
-3004(or)X
-3091(multi-block)X
-3484([SELT91]\).)X
-755 3591(Finally,)N
-1029(with)X
-1199(regard)X
-1433(to)X
-1523(the)X
-1648(process)X
-1916(structure,)X
-2244(neither)X
-2494(context)X
-2757(switch)X
-2993(time)X
-3162(nor)X
-3296(scheduling)X
-3670(around)X
-3920(semaphores)X
-555 3681(seems)N
-785(to)X
-881(affect)X
-1099(the)X
-1231(system)X
-1487(performance.)X
-1968(However,)X
-2317(the)X
-2449(implementation)X
-2984(of)X
-3084(semaphores)X
-3496(can)X
-3641(impact)X
-3892(performance)X
-555 3771(tremendously.)N
-1051(This)X
-1213(is)X
-1286(discussed)X
-1613(in)X
-1695(more)X
-1880(detail)X
-2078(in)X
-2160(section)X
-2407(4.3.)X
-755 3894(The)N
-908(Tuxedo)X
-1181(system)X
-1431(from)X
-1615(AT&T)X
-1861(is)X
-1941(a)X
-2004(transaction)X
-2383(manager)X
-2687(which)X
-2910(coordinates)X
-3307(distributed)X
-3676(transaction)X
-4055(commit)X
-555 3984(from)N
-738(a)X
-801(variety)X
-1051(of)X
-1145(different)X
-1449(local)X
-1632(transaction)X
-2011(managers.)X
-2386(At)X
-2493(this)X
-2634(time,)X
-2822(LIBTP)X
-3070(does)X
-3243(not)X
-3371(have)X
-3549(its)X
-3650(own)X
-3814(mechanism)X
-4205(for)X
-555 4074(distributed)N
-942(commit)X
-1231(processing,)X
-1639(but)X
-1786(could)X
-2009(be)X
-2130(used)X
-2322(as)X
-2434(a)X
-2515(local)X
-2716(transaction)X
-3113(agent)X
-3331(by)X
-3455(systems)X
-3752(such)X
-3943(as)X
-4054(Tuxedo)X
-555 4164([ANDR89].)N
-10 f
-863 4393(i)N
-870(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-903 4483(Buffer)N
-1133(Management)X
-10 f
-1672(g)X
-1 f
-1720(Data)X
-1892(must)X
-2067(be)X
-2163(copied)X
-2397(between)X
-2685(kernel)X
-2906(space)X
-3105(and)X
-3241(user)X
-3395(space.)X
-10 f
-1672 4573(g)N
-1 f
-1720(Buffer)X
-1950(pool)X
-2112(access)X
-2338(is)X
-2411(too)X
-2533(slow.)X
-10 f
-1672 4663(g)N
-1 f
-1720(There)X
-1928(is)X
-2001(no)X
-2101(way)X
-2255(to)X
-2337(request)X
-2589(prefetch.)X
-10 f
-1672 4753(g)N
-1 f
-1720(Replacement)X
-2159(is)X
-2232(usually)X
-2483(LRU)X
-2663(which)X
-2879(may)X
-3037(be)X
-3133(suboptimal)X
-3508(for)X
-3622(databases.)X
-10 f
-1672 4843(g)N
-1 f
-1720(There)X
-1928(is)X
-2001(no)X
-2101(way)X
-2255(to)X
-2337(guarantee)X
-2670(write)X
-2855(ordering.)X
-10 f
-863 4853(i)N
-870(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-903 4943(File)N
-1047(System)X
-10 f
-1672(g)X
-1 f
-1720(Allocation)X
-2078(is)X
-2151(done)X
-2327(in)X
-2409(small)X
-2602(blocks)X
-2831(\(usually)X
-3109(4K)X
-3227(or)X
-3314(8K\).)X
-10 f
-1672 5033(g)N
-1 f
-1720(Logical)X
-1985(organization)X
-2406(of)X
-2493(\256les)X
-2646(is)X
-2719(redundantly)X
-3122(expressed.)X
-10 f
-863 5043(i)N
-870(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-903 5133(Process)N
-1168(Structure)X
-10 f
-1672(g)X
-1 f
-1720(Context)X
-1993(switching)X
-2324(and)X
-2460(message)X
-2752(passing)X
-3012(are)X
-3131(too)X
-3253(slow.)X
-10 f
-1672 5223(g)N
-1 f
-1720(A)X
-1798(process)X
-2059(may)X
-2217(be)X
-2313(descheduled)X
-2730(while)X
-2928(holding)X
-3192(a)X
-3248(semaphore.)X
-10 f
-863 5233(i)N
-870(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-863(c)X
-5193(c)Y
-5113(c)Y
-5033(c)Y
-4953(c)Y
-4873(c)Y
-4793(c)Y
-4713(c)Y
-4633(c)Y
-4553(c)Y
-4473(c)Y
-3990 5233(c)N
-5193(c)Y
-5113(c)Y
-5033(c)Y
-4953(c)Y
-4873(c)Y
-4793(c)Y
-4713(c)Y
-4633(c)Y
-4553(c)Y
-4473(c)Y
-3 f
-1156 5446(Table)N
-1371(One:)X
-1560(Shortcomings)X
-2051(of)X
-2138(UNIX)X
-2363(transaction)X
-2770(support)X
-3056(cited)X
-3241(in)X
-3327([STON81].)X
-
-3 p
-%%Page: 3 3
-10 s 10 xH 0 xS 3 f
-1 f
-755 630(The)N
-901(transaction)X
-1274(architecture)X
-1675(presented)X
-2004(in)X
-2087([YOUN91])X
-2474(is)X
-2548(very)X
-2712(similar)X
-2955(to)X
-3038(that)X
-3179(implemented)X
-3618(in)X
-3701(the)X
-3820(LIBTP.)X
-4103(While)X
-555 720([YOUN91])N
-947(presents)X
-1236(a)X
-1298(model)X
-1524(for)X
-1644(providing)X
-1981(transaction)X
-2359(services,)X
-2663(this)X
-2803(paper)X
-3007(focuses)X
-3273(on)X
-3378(the)X
-3501(implementation)X
-4028(and)X
-4169(per-)X
-555 810(formance)N
-881(of)X
-970(a)X
-1028(particular)X
-1358(system.)X
-1642(In)X
-1731(addition,)X
-2034(we)X
-2149(provide)X
-2415(detailed)X
-2690(comparisons)X
-3116(with)X
-3279(alternative)X
-3639(solutions:)X
-3970(traditional)X
-555 900(UNIX)N
-776(services)X
-1055(and)X
-1191(commercial)X
-1590(database)X
-1887(management)X
-2317(systems.)X
-3 f
-555 1086(3.)N
-655(Architecture)X
-1 f
-755 1209(The)N
-906(library)X
-1146(is)X
-1224(designed)X
-1534(to)X
-1621(provide)X
-1891(well)X
-2054(de\256ned)X
-2315(interfaces)X
-2653(to)X
-2740(the)X
-2863(services)X
-3147(required)X
-3440(for)X
-3559(transaction)X
-3936(processing.)X
-555 1299(These)N
-777(services)X
-1066(are)X
-1195(recovery,)X
-1527(concurrency)X
-1955(control,)X
-2232(and)X
-2378(the)X
-2506(management)X
-2946(of)X
-3043(shared)X
-3283(data.)X
-3487(First)X
-3663(we)X
-3787(will)X
-3941(discuss)X
-4201(the)X
-555 1389(design)N
-795(tradeoffs)X
-1112(in)X
-1205(the)X
-1334(selection)X
-1650(of)X
-1748(recovery,)X
-2081(concurrency)X
-2510(control,)X
-2787(and)X
-2933(buffer)X
-3160(management)X
-3600(implementations,)X
-4183(and)X
-555 1479(then)N
-713(we)X
-827(will)X
-971(present)X
-1223(the)X
-1341(overall)X
-1584(library)X
-1818(architecture)X
-2218(and)X
-2354(module)X
-2614(descriptions.)X
-3 f
-555 1665(3.1.)N
-715(Design)X
-966(Tradeoffs)X
-1 f
-3 f
-555 1851(3.1.1.)N
-775(Crash)X
-1004(Recovery)X
-1 f
-755 1974(The)N
-909(recovery)X
-1220(protocol)X
-1516(is)X
-1598(responsible)X
-1992(for)X
-2115(providing)X
-2455(the)X
-2582(transaction)X
-2963(semantics)X
-3308(discussed)X
-3644(earlier.)X
-3919(There)X
-4136(are)X
-4263(a)X
-555 2064(wide)N
-739(range)X
-946(of)X
-1041(recovery)X
-1351(protocols)X
-1677(available)X
-1995([HAER83],)X
-2395(but)X
-2525(we)X
-2647(can)X
-2786(crudely)X
-3054(divide)X
-3281(them)X
-3468(into)X
-3619(two)X
-3766(main)X
-3953(categories.)X
-555 2154(The)N
-706(\256rst)X
-856(category)X
-1159(records)X
-1422(all)X
-1528(modi\256cations)X
-1989(to)X
-2077(the)X
-2201(database)X
-2504(in)X
-2592(a)X
-2653(separate)X
-2942(\256le,)X
-3089(and)X
-3230(uses)X
-3393(this)X
-3533(\256le)X
-3660(\(log\))X
-3841(to)X
-3928(back)X
-4105(out)X
-4232(or)X
-555 2244(reapply)N
-825(these)X
-1019(modi\256cations)X
-1483(if)X
-1561(a)X
-1626(transaction)X
-2007(aborts)X
-2232(or)X
-2328(the)X
-2455(system)X
-2706(crashes.)X
-3012(We)X
-3153(call)X
-3298(this)X
-3442(set)X
-3560(the)X
-3 f
-3687(logging)X
-3963(protocols)X
-1 f
-4279(.)X
-555 2334(The)N
-703(second)X
-949(category)X
-1249(avoids)X
-1481(the)X
-1602(use)X
-1732(of)X
-1822(a)X
-1881(log)X
-2006(by)X
-2109(carefully)X
-2418(controlling)X
-2792(when)X
-2989(data)X
-3146(are)X
-3268(written)X
-3518(to)X
-3603(disk.)X
-3799(We)X
-3934(call)X
-4073(this)X
-4210(set)X
-555 2424(the)N
-3 f
-673(non-logging)X
-1096(protocols)X
-1 f
-1412(.)X
-755 2547(Non-logging)N
-1185(protocols)X
-1504(hold)X
-1666(dirty)X
-1837(buffers)X
-2085(in)X
-2167(main)X
-2347(memory)X
-2634(or)X
-2721(temporary)X
-3071(\256les)X
-3224(until)X
-3390(commit)X
-3654(and)X
-3790(then)X
-3948(force)X
-4134(these)X
-555 2637(pages)N
-769(to)X
-862(disk)X
-1026(at)X
-1115(transaction)X
-1498(commit.)X
-1813(While)X
-2040(we)X
-2165(can)X
-2308(use)X
-2446(temporary)X
-2807(\256les)X
-2971(to)X
-3064(hold)X
-3237(dirty)X
-3418(pages)X
-3631(that)X
-3781(may)X
-3949(need)X
-4131(to)X
-4223(be)X
-555 2727(evicted)N
-810(from)X
-988(memory)X
-1277(during)X
-1508(a)X
-1566(long-running)X
-2006(transaction,)X
-2400(the)X
-2520(only)X
-2684(user-level)X
-3023(mechanism)X
-3410(to)X
-3494(force)X
-3682(pages)X
-3887(to)X
-3971(disk)X
-4126(is)X
-4201(the)X
-3 f
-555 2817(fsync)N
-1 f
-733(\(2\))X
-850(system)X
-1095(call.)X
-1274(Unfortunately,)X
-3 f
-1767(fsync)X
-1 f
-1945(\(2\))X
-2062(is)X
-2138(an)X
-2237(expensive)X
-2581(system)X
-2826(call)X
-2965(in)X
-3050(that)X
-3193(it)X
-3260(forces)X
-3480(all)X
-3583(pages)X
-3789(of)X
-3879(a)X
-3938(\256le)X
-4062(to)X
-4146(disk,)X
-555 2907(and)N
-691(transactions)X
-1094(that)X
-1234(manage)X
-1504(more)X
-1689(than)X
-1847(one)X
-1983(\256le)X
-2105(must)X
-2280(issue)X
-2460(one)X
-2596(call)X
-2732(per)X
-2855(\256le.)X
-755 3030(In)N
-853(addition,)X
-3 f
-1166(fsync)X
-1 f
-1344(\(2\))X
-1469(provides)X
-1776(no)X
-1887(way)X
-2051(to)X
-2143(control)X
-2400(the)X
-2528(order)X
-2728(in)X
-2820(which)X
-3046(dirty)X
-3227(pages)X
-3440(are)X
-3569(written)X
-3826(to)X
-3918(disk.)X
-4121(Since)X
-555 3120(non-logging)N
-976(protocols)X
-1304(must)X
-1489(sometimes)X
-1861(order)X
-2061(writes)X
-2287(carefully)X
-2603([SULL92],)X
-2987(they)X
-3155(are)X
-3284(dif\256cult)X
-3567(to)X
-3659(implement)X
-4030(on)X
-4139(Unix)X
-555 3210(systems.)N
-868(As)X
-977(a)X
-1033(result,)X
-1251(we)X
-1365(have)X
-1537(chosen)X
-1780(to)X
-1862(implement)X
-2224(a)X
-2280(logging)X
-2544(protocol.)X
-755 3333(Logging)N
-1050(protocols)X
-1372(may)X
-1534(be)X
-1634(categorized)X
-2029(based)X
-2236(on)X
-2340(how)X
-2502(information)X
-2904(is)X
-2981(logged)X
-3223(\(physically)X
-3602(or)X
-3692(logically\))X
-4022(and)X
-4161(how)X
-555 3423(much)N
-767(is)X
-854(logged)X
-1106(\(before)X
-1373(images,)X
-1654(after)X
-1836(images)X
-2097(or)X
-2198(both\).)X
-2441(In)X
-3 f
-2542(physical)X
-2855(logging)X
-1 f
-3103(,)X
-3157(images)X
-3417(of)X
-3517(complete)X
-3844(physical)X
-4144(units)X
-555 3513(\(pages)N
-786(or)X
-874(buffers\))X
-1150(are)X
-1270(recorded,)X
-1593(while)X
-1792(in)X
-3 f
-1875(logical)X
-2118(logging)X
-1 f
-2387(a)X
-2444(description)X
-2820(of)X
-2907(the)X
-3025(operation)X
-3348(is)X
-3421(recorded.)X
-3763(Therefore,)X
-4121(while)X
-555 3603(we)N
-675(may)X
-839(record)X
-1071(entire)X
-1280(pages)X
-1489(in)X
-1577(a)X
-1639(physical)X
-1932(log,)X
-2080(we)X
-2200(need)X
-2378(only)X
-2546(record)X
-2777(the)X
-2900(records)X
-3162(being)X
-3365(modi\256ed)X
-3674(in)X
-3761(a)X
-3822(logical)X
-4065(log.)X
-4232(In)X
-555 3693(fact,)N
-718(physical)X
-1006(logging)X
-1271(can)X
-1404(be)X
-1501(thought)X
-1766(of)X
-1854(as)X
-1942(a)X
-1999(special)X
-2243(case)X
-2403(of)X
-2491(logical)X
-2730(logging,)X
-3015(since)X
-3201(the)X
-3320 0.3125(``records'')AX
-3686(that)X
-3827(we)X
-3942(log)X
-4065(in)X
-4148(logi-)X
-555 3783(cal)N
-673(logging)X
-941(might)X
-1151(be)X
-1251(physical)X
-1542(pages.)X
-1789(Since)X
-1991(logical)X
-2233(logging)X
-2501(is)X
-2578(both)X
-2743(more)X
-2931(space-ef\256cient)X
-3423(and)X
-3562(more)X
-3750(general,)X
-4030(we)X
-4147(have)X
-555 3873(chosen)N
-798(it)X
-862(for)X
-976(our)X
-1103(logging)X
-1367(protocol.)X
-755 3996(In)N
-3 f
-843(before-image)X
-1315(logging)X
-1 f
-1563(,)X
-1604(we)X
-1719(log)X
-1842(a)X
-1899(copy)X
-2076(of)X
-2164(the)X
-2283(data)X
-2438(before)X
-2665(the)X
-2784(update,)X
-3039(while)X
-3238(in)X
-3 f
-3321(after-image)X
-3739(logging)X
-1 f
-3987(,)X
-4027(we)X
-4141(log)X
-4263(a)X
-555 4086(copy)N
-740(of)X
-836(the)X
-963(data)X
-1126(after)X
-1303(the)X
-1429(update.)X
-1711(If)X
-1793(we)X
-1915(log)X
-2045(only)X
-2215(before-images,)X
-2723(then)X
-2889(there)X
-3078(is)X
-3159(suf\256cient)X
-3485(information)X
-3891(in)X
-3981(the)X
-4107(log)X
-4237(to)X
-555 4176(allow)N
-761(us)X
-860(to)X
-3 f
-950(undo)X
-1 f
-1150(the)X
-1276(transaction)X
-1656(\(go)X
-1791(back)X
-1971(to)X
-2061(the)X
-2187(state)X
-2361(represented)X
-2759(by)X
-2866(the)X
-2991(before-image\).)X
-3514(However,)X
-3876(if)X
-3952(the)X
-4077(system)X
-555 4266(crashes)N
-814(and)X
-952(a)X
-1010(committed)X
-1374(transaction's)X
-1806(changes)X
-2087(have)X
-2261(not)X
-2385(reached)X
-2658(the)X
-2778(disk,)X
-2953(we)X
-3068(have)X
-3241(no)X
-3342(means)X
-3568(to)X
-3 f
-3651(redo)X
-1 f
-3828(the)X
-3947(transaction)X
-555 4356(\(reapply)N
-849(the)X
-973(updates\).)X
-1311(Therefore,)X
-1675(logging)X
-1945(only)X
-2113(before-images)X
-2599(necessitates)X
-3004(forcing)X
-3262(dirty)X
-3439(pages)X
-3648(at)X
-3732(commit)X
-4002(time.)X
-4210(As)X
-555 4446(mentioned)N
-913(above,)X
-1145(forcing)X
-1397(pages)X
-1600(at)X
-1678(commit)X
-1942(is)X
-2015(considered)X
-2383(too)X
-2505(costly.)X
-755 4569(If)N
-834(we)X
-953(log)X
-1080(only)X
-1247(after-images,)X
-1694(then)X
-1857(there)X
-2043(is)X
-2121(suf\256cient)X
-2444(information)X
-2847(in)X
-2934(the)X
-3057(log)X
-3184(to)X
-3271(allow)X
-3474(us)X
-3570(to)X
-3657(redo)X
-3825(the)X
-3947(transaction)X
-555 4659(\(go)N
-687(forward)X
-967(to)X
-1054(the)X
-1177(state)X
-1348(represented)X
-1743(by)X
-1847(the)X
-1969(after-image\),)X
-2411(but)X
-2537(we)X
-2655(do)X
-2759(not)X
-2885(have)X
-3061(the)X
-3183(information)X
-3585(required)X
-3877(to)X
-3963(undo)X
-4147(tran-)X
-555 4749(sactions)N
-845(which)X
-1073(aborted)X
-1346(after)X
-1526(dirty)X
-1709(pages)X
-1924(were)X
-2113(written)X
-2372(to)X
-2466(disk.)X
-2670(Therefore,)X
-3039(logging)X
-3314(only)X
-3487(after-images)X
-3920(necessitates)X
-555 4839(holding)N
-819(all)X
-919(dirty)X
-1090(buffers)X
-1338(in)X
-1420(main)X
-1600(memory)X
-1887(until)X
-2053(commit)X
-2317(or)X
-2404(writing)X
-2655(them)X
-2835(to)X
-2917(a)X
-2973(temporary)X
-3323(\256le.)X
-755 4962(Since)N
-956(neither)X
-1202(constraint)X
-1541(\(forcing)X
-1823(pages)X
-2029(on)X
-2132(commit)X
-2399(or)X
-2489(buffering)X
-2811(pages)X
-3016(until)X
-3184(commit\))X
-3477(was)X
-3624(feasible,)X
-3916(we)X
-4032(chose)X
-4237(to)X
-555 5052(log)N
-683(both)X
-851(before)X
-1083(and)X
-1225(after)X
-1399(images.)X
-1672(The)X
-1823(only)X
-1991(remaining)X
-2342(consideration)X
-2800(is)X
-2879(when)X
-3079(changes)X
-3363(get)X
-3486(written)X
-3738(to)X
-3825(disk.)X
-4023(Changes)X
-555 5142(affect)N
-764(both)X
-931(data)X
-1090(pages)X
-1298(and)X
-1438(the)X
-1560(log.)X
-1726(If)X
-1804(the)X
-1926(changed)X
-2218(data)X
-2376(page)X
-2552(is)X
-2629(written)X
-2880(before)X
-3110(the)X
-3232(log)X
-3358(page,)X
-3554(and)X
-3694(the)X
-3816(system)X
-4062(crashes)X
-555 5232(before)N
-787(the)X
-911(log)X
-1039(page)X
-1217(is)X
-1296(written,)X
-1569(the)X
-1693(log)X
-1820(will)X
-1969(contain)X
-2230(insuf\256cient)X
-2615(information)X
-3018(to)X
-3105(undo)X
-3290(the)X
-3413(change.)X
-3706(This)X
-3873(violates)X
-4147(tran-)X
-555 5322(saction)N
-803(semantics,)X
-1160(since)X
-1346(some)X
-1536(changed)X
-1825(data)X
-1980(pages)X
-2184(may)X
-2343(not)X
-2466(have)X
-2638(been)X
-2810(written,)X
-3077(and)X
-3213(the)X
-3331(database)X
-3628(cannot)X
-3862(be)X
-3958(restored)X
-4237(to)X
-555 5412(its)N
-650(pre-transaction)X
-1152(state.)X
-755 5535(The)N
-914(log)X
-1050(record)X
-1290(describing)X
-1658(an)X
-1768(update)X
-2016(must)X
-2205(be)X
-2315(written)X
-2576(to)X
-2672(stable)X
-2893(storage)X
-3159(before)X
-3398(the)X
-3529(modi\256ed)X
-3846(page.)X
-4071(This)X
-4246(is)X
-3 f
-555 5625(write-ahead)N
-992(logging)X
-1 f
-1240(.)X
-1307(If)X
-1388(log)X
-1517(records)X
-1781(are)X
-1907(safely)X
-2126(written)X
-2380(to)X
-2469(disk,)X
-2649(data)X
-2810(pages)X
-3020(may)X
-3185(be)X
-3288(written)X
-3542(at)X
-3627(any)X
-3770(time)X
-3939(afterwards.)X
-555 5715(This)N
-721(means)X
-950(that)X
-1094(the)X
-1216(only)X
-1382(\256le)X
-1508(that)X
-1652(ever)X
-1815(needs)X
-2022(to)X
-2108(be)X
-2208(forced)X
-2438(to)X
-2524(disk)X
-2681(is)X
-2758(the)X
-2880(log.)X
-3046(Since)X
-3248(the)X
-3370(log)X
-3495(is)X
-3571(append-only,)X
-4015(modi\256ed)X
-
-4 p
-%%Page: 4 4
-10 s 10 xH 0 xS 1 f
-3 f
-1 f
-555 630(pages)N
-760(always)X
-1005(appear)X
-1242(at)X
-1322(the)X
-1442(end)X
-1580(and)X
-1718(may)X
-1878(be)X
-1976(written)X
-2224(to)X
-2307(disk)X
-2461(ef\256ciently)X
-2807(in)X
-2890(any)X
-3027(\256le)X
-3150(system)X
-3393(that)X
-3534(favors)X
-3756(sequential)X
-4102(order-)X
-555 720(ing)N
-677(\()X
-2 f
-704(e.g.)X
-1 f
-820(,)X
-860(FFS,)X
-1032(log-structured)X
-1502(\256le)X
-1624(system,)X
-1886(or)X
-1973(an)X
-2069(extent-based)X
-2495(system\).)X
-3 f
-555 906(3.1.2.)N
-775(Concurrency)X
-1245(Control)X
-1 f
-755 1029(The)N
-918(concurrency)X
-1354(control)X
-1619(protocol)X
-1923(is)X
-2013(responsible)X
-2415(for)X
-2546(maintaining)X
-2965(consistency)X
-3376(in)X
-3475(the)X
-3610(presence)X
-3929(of)X
-4033(multiple)X
-555 1119(accesses.)N
-897(There)X
-1114(are)X
-1242(several)X
-1499(alternative)X
-1867(solutions)X
-2183(such)X
-2358(as)X
-2453(locking,)X
-2741(optimistic)X
-3088(concurrency)X
-3514(control)X
-3769([KUNG81],)X
-4183(and)X
-555 1209(timestamp)N
-912(ordering)X
-1208([BERN80].)X
-1619(Since)X
-1821(optimistic)X
-2164(methods)X
-2459(and)X
-2599(timestamp)X
-2956(ordering)X
-3252(are)X
-3374(generally)X
-3696(more)X
-3884(complex)X
-4183(and)X
-555 1299(restrict)N
-804(concurrency)X
-1228(without)X
-1498(eliminating)X
-1888(starvation)X
-2230(or)X
-2323(deadlocks,)X
-2690(we)X
-2810(chose)X
-3018(two-phase)X
-3373(locking)X
-3638(\(2PL\).)X
-3890(Strict)X
-4088(2PL)X
-4246(is)X
-555 1389(suboptimal)N
-935(for)X
-1054(certain)X
-1297(data)X
-1455(structures)X
-1791(such)X
-1962(as)X
-2053(B-trees)X
-2309(because)X
-2588(it)X
-2656(can)X
-2792(limit)X
-2966(concurrency,)X
-3408(so)X
-3503(we)X
-3621(use)X
-3752(a)X
-3812(special)X
-4059(locking)X
-555 1479(protocol)N
-842(based)X
-1045(on)X
-1145(one)X
-1281(described)X
-1609(in)X
-1691([LEHM81].)X
-755 1602(The)N
-901(B-tree)X
-1123(locking)X
-1384(protocol)X
-1672(we)X
-1787(implemented)X
-2226(releases)X
-2502(locks)X
-2691(at)X
-2769(internal)X
-3034(nodes)X
-3241(in)X
-3323(the)X
-3441(tree)X
-3582(as)X
-3669(it)X
-3733(descends.)X
-4083(A)X
-4161(lock)X
-555 1692(on)N
-658(an)X
-757(internal)X
-1025(page)X
-1200(is)X
-1276(always)X
-1522(released)X
-1808(before)X
-2036(a)X
-2094(lock)X
-2254(on)X
-2356(its)X
-2453(child)X
-2635(is)X
-2710(obtained)X
-3008(\(that)X
-3177(is,)X
-3272(locks)X
-3463(are)X
-3584(not)X
-3 f
-3708(coupled)X
-1 f
-3996([BAY77])X
-555 1782(during)N
-786(descent\).)X
-1116(When)X
-1330(a)X
-1388(leaf)X
-1531(\(or)X
-1647(internal\))X
-1941(page)X
-2115(is)X
-2190(split,)X
-2369(a)X
-2427(write)X
-2614(lock)X
-2774(is)X
-2849(acquired)X
-3148(on)X
-3250(the)X
-3370(parent)X
-3593(before)X
-3821(the)X
-3941(lock)X
-4100(on)X
-4201(the)X
-555 1872(just-split)N
-855(page)X
-1028(is)X
-1102(released)X
-1387(\(locks)X
-1604(are)X
-3 f
-1724(coupled)X
-1 f
-2011(during)X
-2241(ascent\).)X
-2530(Write)X
-2734(locks)X
-2924(on)X
-3025(internal)X
-3291(pages)X
-3495(are)X
-3615(released)X
-3899(immediately)X
-555 1962(after)N
-723(the)X
-841(page)X
-1013(is)X
-1086(updated,)X
-1380(but)X
-1502(locks)X
-1691(on)X
-1791(leaf)X
-1932(pages)X
-2135(are)X
-2254(held)X
-2412(until)X
-2578(the)X
-2696(end)X
-2832(of)X
-2919(the)X
-3037(transaction.)X
-755 2085(Since)N
-964(locks)X
-1164(are)X
-1294(released)X
-1589(during)X
-1828(descent,)X
-2119(the)X
-2247(structure)X
-2558(of)X
-2655(the)X
-2783(tree)X
-2934(may)X
-3102(change)X
-3360(above)X
-3582(a)X
-3648(node)X
-3834(being)X
-4042(used)X
-4219(by)X
-555 2175(some)N
-752(process.)X
-1061(If)X
-1143(that)X
-1291(process)X
-1560(must)X
-1743(later)X
-1914(ascend)X
-2161(the)X
-2287(tree)X
-2435(because)X
-2717(of)X
-2811(a)X
-2874(page)X
-3053(split,)X
-3237(any)X
-3380(such)X
-3554(change)X
-3809(must)X
-3991(not)X
-4120(cause)X
-555 2265(confusion.)N
-938(We)X
-1077(use)X
-1211(the)X
-1336(technique)X
-1675(described)X
-2010(in)X
-2099([LEHM81])X
-2487(which)X
-2710(exploits)X
-2989(the)X
-3113(ordering)X
-3411(of)X
-3504(data)X
-3664(on)X
-3770(a)X
-3832(B-tree)X
-4059(page)X
-4237(to)X
-555 2355(guarantee)N
-888(that)X
-1028(no)X
-1128(process)X
-1389(ever)X
-1548(gets)X
-1697(lost)X
-1832(as)X
-1919(a)X
-1975(result)X
-2173(of)X
-2260(internal)X
-2525(page)X
-2697(updates)X
-2962(made)X
-3156(by)X
-3256(other)X
-3441(processes.)X
-755 2478(If)N
-836(a)X
-899(transaction)X
-1278(that)X
-1425(updates)X
-1697(a)X
-1760(B-tree)X
-1988(aborts,)X
-2231(the)X
-2356(user-visible)X
-2757(changes)X
-3043(to)X
-3131(the)X
-3255(tree)X
-3402(must)X
-3583(be)X
-3685(rolled)X
-3898(back.)X
-4116(How-)X
-555 2568(ever,)N
-735(changes)X
-1015(to)X
-1097(the)X
-1215(internal)X
-1480(nodes)X
-1687(of)X
-1774(the)X
-1892(tree)X
-2033(need)X
-2205(not)X
-2327(be)X
-2423(rolled)X
-2630(back,)X
-2822(since)X
-3007(these)X
-3192(pages)X
-3395(contain)X
-3651(no)X
-3751(user-visible)X
-4145(data.)X
-555 2658(When)N
-771(rolling)X
-1008(back)X
-1184(a)X
-1244(transaction,)X
-1640(we)X
-1758(roll)X
-1893(back)X
-2069(all)X
-2173(leaf)X
-2318(page)X
-2494(updates,)X
-2783(but)X
-2909(no)X
-3013(internal)X
-3281(insertions)X
-3615(or)X
-3705(page)X
-3880(splits.)X
-4111(In)X
-4201(the)X
-555 2748(worst)N
-759(case,)X
-944(this)X
-1085(will)X
-1235(leave)X
-1431(a)X
-1493(leaf)X
-1640(page)X
-1818(less)X
-1964(than)X
-2128(half)X
-2279(full.)X
-2456(This)X
-2624(may)X
-2788(cause)X
-2993(poor)X
-3166(space)X
-3371(utilization,)X
-3741(but)X
-3869(does)X
-4042(not)X
-4170(lose)X
-555 2838(user)N
-709(data.)X
-755 2961(Holding)N
-1038(locks)X
-1228(on)X
-1329(leaf)X
-1471(pages)X
-1675(until)X
-1842(transaction)X
-2215(commit)X
-2480(guarantees)X
-2845(that)X
-2986(no)X
-3087(other)X
-3273(process)X
-3535(can)X
-3668(insert)X
-3866(or)X
-3953(delete)X
-4165(data)X
-555 3051(that)N
-711(has)X
-854(been)X
-1042(touched)X
-1332(by)X
-1448(this)X
-1598(process.)X
-1914(Rolling)X
-2188(back)X
-2375(insertions)X
-2721(and)X
-2872(deletions)X
-3196(on)X
-3311(leaf)X
-3467(pages)X
-3685(guarantees)X
-4064(that)X
-4219(no)X
-555 3141(aborted)N
-819(updates)X
-1087(are)X
-1209(ever)X
-1371(visible)X
-1607(to)X
-1692(other)X
-1880(transactions.)X
-2326(Leaving)X
-2612(page)X
-2787(splits)X
-2978(intact)X
-3179(permits)X
-3442(us)X
-3536(to)X
-3621(release)X
-3867(internal)X
-4134(write)X
-555 3231(locks)N
-744(early.)X
-965(Thus)X
-1145(transaction)X
-1517(semantics)X
-1853(are)X
-1972(preserved,)X
-2325(and)X
-2461(locks)X
-2650(are)X
-2769(held)X
-2927(for)X
-3041(shorter)X
-3284(periods.)X
-755 3354(The)N
-901(extra)X
-1083(complexity)X
-1464(introduced)X
-1828(by)X
-1929(this)X
-2065(locking)X
-2326(protocol)X
-2614(appears)X
-2881(substantial,)X
-3264(but)X
-3387(it)X
-3452(is)X
-3525(important)X
-3856(for)X
-3970(multi-user)X
-555 3444(execution.)N
-950(The)X
-1118(bene\256ts)X
-1410(of)X
-1520(non-two-phase)X
-2040(locking)X
-2323(on)X
-2446(B-trees)X
-2721(are)X
-2863(well)X
-3044(established)X
-3443(in)X
-3548(the)X
-3689(database)X
-4009(literature)X
-555 3534([BAY77],)N
-899([LEHM81].)X
-1320(If)X
-1394(a)X
-1450(process)X
-1711(held)X
-1869(locks)X
-2058(until)X
-2224(it)X
-2288(committed,)X
-2670(then)X
-2828(a)X
-2884(long-running)X
-3322(update)X
-3556(could)X
-3754(lock)X
-3912(out)X
-4034(all)X
-4134(other)X
-555 3624(transactions)N
-967(by)X
-1076(preventing)X
-1448(any)X
-1593(other)X
-1787(process)X
-2057(from)X
-2241(locking)X
-2509(the)X
-2635(root)X
-2792(page)X
-2972(of)X
-3067(the)X
-3193(tree.)X
-3382(The)X
-3535(B-tree)X
-3764(locking)X
-4032(protocol)X
-555 3714(described)N
-884(above)X
-1096(guarantees)X
-1460(that)X
-1600(locks)X
-1789(on)X
-1889(internal)X
-2154(pages)X
-2357(are)X
-2476(held)X
-2634(for)X
-2748(extremely)X
-3089(short)X
-3269(periods,)X
-3545(thereby)X
-3806(increasing)X
-4156(con-)X
-555 3804(currency.)N
-3 f
-555 3990(3.1.3.)N
-775(Management)X
-1245(of)X
-1332(Shared)X
-1596(Data)X
-1 f
-755 4113(Database)N
-1075(systems)X
-1353(permit)X
-1587(many)X
-1790(users)X
-1980(to)X
-2067(examine)X
-2364(and)X
-2505(update)X
-2744(the)X
-2866(same)X
-3055(data)X
-3213(concurrently.)X
-3683(In)X
-3774(order)X
-3968(to)X
-4054(provide)X
-555 4203(this)N
-702(concurrent)X
-1078(access)X
-1316(and)X
-1464(enforce)X
-1738(the)X
-1868(write-ahead)X
-2280(logging)X
-2556(protocol)X
-2855(described)X
-3195(in)X
-3289(section)X
-3548(3.1.1,)X
-3759(we)X
-3884(use)X
-4022(a)X
-4089(shared)X
-555 4293(memory)N
-848(buffer)X
-1071(manager.)X
-1414(Not)X
-1559(only)X
-1726(does)X
-1898(this)X
-2038(provide)X
-2308(the)X
-2431(guarantees)X
-2800(we)X
-2919(require,)X
-3192(but)X
-3319(a)X
-3380(user-level)X
-3722(buffer)X
-3944(manager)X
-4246(is)X
-555 4383(frequently)N
-916(faster)X
-1126(than)X
-1295(using)X
-1498(the)X
-1626(\256le)X
-1758(system)X
-2010(buffer)X
-2237(cache.)X
-2491(Reads)X
-2717(or)X
-2814(writes)X
-3040(involving)X
-3376(the)X
-3504(\256le)X
-3636(system)X
-3888(buffer)X
-4115(cache)X
-555 4473(often)N
-746(require)X
-1000(copying)X
-1284(data)X
-1444(between)X
-1738(user)X
-1898(and)X
-2040(kernel)X
-2266(space)X
-2470(while)X
-2673(a)X
-2734(user-level)X
-3076(buffer)X
-3298(manager)X
-3600(can)X
-3737(return)X
-3954(pointers)X
-4237(to)X
-555 4563(data)N
-709(pages)X
-912(directly.)X
-1217(Additionally,)X
-1661(if)X
-1730(more)X
-1915(than)X
-2073(one)X
-2209(process)X
-2470(uses)X
-2628(the)X
-2746(same)X
-2931(page,)X
-3123(then)X
-3281(fewer)X
-3485(copies)X
-3710(may)X
-3868(be)X
-3964(required.)X
-3 f
-555 4749(3.2.)N
-715(Module)X
-997(Architecture)X
-1 f
-755 4872(The)N
-913(preceding)X
-1262(sections)X
-1552(described)X
-1892(modules)X
-2195(for)X
-2321(managing)X
-2669(the)X
-2799(transaction)X
-3183(log,)X
-3337(locks,)X
-3558(and)X
-3706(a)X
-3774(cache)X
-3990(of)X
-4089(shared)X
-555 4962(buffers.)N
-847(In)X
-938(addition,)X
-1244(we)X
-1362(need)X
-1538(to)X
-1624(provide)X
-1893(functionality)X
-2326(for)X
-2444(transaction)X
-2 f
-2819(begin)X
-1 f
-2997(,)X
-2 f
-3040(commit)X
-1 f
-3276(,)X
-3319(and)X
-2 f
-3458(abort)X
-1 f
-3654(processing,)X
-4040(necessi-)X
-555 5052(tating)N
-769(a)X
-837(transaction)X
-1221(manager.)X
-1570(In)X
-1669(order)X
-1871(to)X
-1965(arbitrate)X
-2265(concurrent)X
-2641(access)X
-2879(to)X
-2973(locks)X
-3173(and)X
-3320(buffers,)X
-3599(we)X
-3724(include)X
-3991(a)X
-4058(process)X
-555 5142(management)N
-995(module)X
-1264(which)X
-1489(manages)X
-1799(a)X
-1864(collection)X
-2209(of)X
-2305(semaphores)X
-2713(used)X
-2889(to)X
-2980(block)X
-3187(and)X
-3332(release)X
-3585(processes.)X
-3962(Finally,)X
-4237(in)X
-555 5232(order)N
-752(to)X
-841(provide)X
-1113(a)X
-1176(simple,)X
-1436(standard)X
-1735(interface)X
-2044(we)X
-2165(have)X
-2344(modi\256ed)X
-2655(the)X
-2780(database)X
-3084(access)X
-3317(routines)X
-3602(\()X
-3 f
-3629(db)X
-1 f
-3717(\(3\)\).)X
-3904(For)X
-4041(the)X
-4165(pur-)X
-555 5322(poses)N
-758(of)X
-850(this)X
-990(paper)X
-1194(we)X
-1313(call)X
-1453(the)X
-1575(modi\256ed)X
-1883(package)X
-2171(the)X
-3 f
-2293(Record)X
-2567(Manager)X
-1 f
-2879(.)X
-2943(Figure)X
-3176(one)X
-3316(shows)X
-3540(the)X
-3662(main)X
-3846(interfaces)X
-4183(and)X
-555 5412(architecture)N
-955(of)X
-1042(LIBTP.)X
-
-5 p
-%%Page: 5 5
-10 s 10 xH 0 xS 1 f
-3 f
-1 f
-11 s
-1851 1520(log_commit)N
-2764 2077(buf_unpin)N
-2764 1987(buf_get)N
-3633 1408(buf_unpin)N
-3633 1319(buf_pin)N
-3633 1230(buf_get)N
-3 f
-17 s
-1163 960(Txn)N
-1430(M)X
-1559(anager)X
-2582(Record)X
-3040(M)X
-3169(anager)X
-1 Dt
-2363 726 MXY
-0 355 Dl
-1426 0 Dl
-0 -355 Dl
--1426 0 Dl
-3255 1616 MXY
-0 535 Dl
-534 0 Dl
-0 -535 Dl
--534 0 Dl
-2185 MX
-0 535 Dl
-535 0 Dl
-0 -535 Dl
--535 0 Dl
-1116 MX
-0 535 Dl
-534 0 Dl
-0 -535 Dl
--534 0 Dl
-726 MY
-0 355 Dl
-891 0 Dl
-0 -355 Dl
--891 0 Dl
-1 f
-11 s
-2207 1297(lock)N
-2564 1386(log)N
-865(unlock_all)X
-1851 1609(log_unroll)N
-1650 2508 MXY
-0 178 Dl
-1605 0 Dl
-0 -178 Dl
--1605 0 Dl
-1294 1616 MXY
-19 -30 Dl
--19 11 Dl
--20 -11 Dl
-20 30 Dl
-0 -535 Dl
-2319 2508 MXY
--22 -30 Dl
-4 23 Dl
--18 14 Dl
-36 -7 Dl
--936 -357 Dl
-3277 2455(sleep_on)N
-1405 1616 MXY
-36 4 Dl
--18 -13 Dl
-1 -22 Dl
--19 31 Dl
-1070 -535 Dl
-2631 2508 MXY
-36 6 Dl
--18 -14 Dl
-3 -22 Dl
--21 30 Dl
-891 -357 Dl
-1426 2455(sleep_on)N
-3255 1884 MXY
--31 -20 Dl
-11 20 Dl
--11 19 Dl
-31 -19 Dl
--535 0 Dl
-1554 2366(wake)N
-3277(wake)X
-2185 1884 MXY
--31 -20 Dl
-12 20 Dl
--12 19 Dl
-31 -19 Dl
--356 0 Dl
-0 -803 Dl
-3 f
-17 s
-1236 1851(Lock)N
-1118 2030(M)N
-1247(anager)X
-2339 1851(Log)N
-2187 2030(M)N
-2316(anager)X
-3333 1851(Buffer)N
-3257 2030(M)N
-3386(anager)X
-3522 1616 MXY
-20 -30 Dl
--20 11 Dl
--20 -11 Dl
-20 30 Dl
-0 -535 Dl
-1950 2654(Process)N
-2424(M)X
-2553(anager)X
-2542 1616 MXY
-19 -30 Dl
--19 11 Dl
--20 -11 Dl
-20 30 Dl
-0 -535 Dl
-1 f
-11 s
-2207 1364(unlock)N
-2452 2508 MXY
-20 -31 Dl
--20 11 Dl
--19 -11 Dl
-19 31 Dl
-0 -357 Dl
-2497 2322(sleep_on)N
-2497 2233(wake)N
-3 Dt
--1 Ds
-3 f
-10 s
-1790 2830(Figure)N
-2037(1:)X
-2144(Library)X
-2435(module)X
-2708(interfaces.)X
-1 f
-10 f
-555 3010(h)N
-579(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)X
-3 f
-555 3286(3.2.1.)N
-775(The)X
-928(Log)X
-1081(Manager)X
-1 f
-755 3409(The)N
-3 f
-907(Log)X
-1067(Manager)X
-1 f
-1406(enforces)X
-1706(the)X
-1831(write-ahead)X
-2238(logging)X
-2509(protocol.)X
-2843(Its)X
-2949(primitive)X
-3268(operations)X
-3628(are)X
-2 f
-3753(log)X
-1 f
-3855(,)X
-2 f
-3901(log_commit)X
-1 f
-4279(,)X
-2 f
-555 3499(log_read)N
-1 f
-844(,)X
-2 f
-889(log_roll)X
-1 f
-1171(and)X
-2 f
-1312(log_unroll)X
-1 f
-1649(.)X
-1714(The)X
-2 f
-1864(log)X
-1 f
-1991(call)X
-2132(performs)X
-2447(a)X
-2508(buffered)X
-2806(write)X
-2996(of)X
-3088(the)X
-3211(speci\256ed)X
-3520(log)X
-3646(record)X
-3876(and)X
-4016(returns)X
-4263(a)X
-555 3589(unique)N
-809(log)X
-947(sequence)X
-1278(number)X
-1559(\(LSN\).)X
-1840(This)X
-2017(LSN)X
-2203(may)X
-2376(then)X
-2549(be)X
-2660(used)X
-2842(to)X
-2939(retrieve)X
-3220(a)X
-3291(record)X
-3532(from)X
-3723(the)X
-3856(log)X
-3993(using)X
-4201(the)X
-2 f
-555 3679(log_read)N
-1 f
-865(call.)X
-1042(The)X
-2 f
-1188(log)X
-1 f
-1311(interface)X
-1614(knows)X
-1844(very)X
-2008(little)X
-2175(about)X
-2374(the)X
-2493(internal)X
-2759(format)X
-2993(of)X
-3080(the)X
-3198(log)X
-3320(records)X
-3577(it)X
-3641(receives.)X
-3965(Rather,)X
-4219(all)X
-555 3769(log)N
-681(records)X
-942(are)X
-1065 0.4028(referenced)AX
-1430(by)X
-1534(a)X
-1594(header)X
-1833(structure,)X
-2158(a)X
-2218(log)X
-2344(record)X
-2574(type,)X
-2756(and)X
-2896(a)X
-2956(character)X
-3276(buffer)X
-3497(containing)X
-3859(the)X
-3981(data)X
-4138(to)X
-4223(be)X
-555 3859(logged.)N
-834(The)X
-980(log)X
-1103(record)X
-1330(type)X
-1489(is)X
-1563(used)X
-1731(to)X
-1814(call)X
-1951(the)X
-2070(appropriate)X
-2457(redo)X
-2621(and)X
-2758(undo)X
-2939(routines)X
-3217(during)X
-2 f
-3446(abort)X
-1 f
-3639(and)X
-2 f
-3775(commit)X
-1 f
-4031(process-)X
-555 3949(ing.)N
-721(While)X
-941(we)X
-1059(have)X
-1235(used)X
-1406(the)X
-3 f
-1528(Log)X
-1684(Manager)X
-1 f
-2019(to)X
-2104(provide)X
-2372(before)X
-2601(and)X
-2740(after)X
-2911(image)X
-3130(logging,)X
-3417(it)X
-3484(may)X
-3645(also)X
-3797(be)X
-3896(used)X
-4066(for)X
-4183(any)X
-555 4039(of)N
-642(the)X
-760(logging)X
-1024(algorithms)X
-1386(discussed.)X
-755 4162(The)N
-2 f
-905(log_commit)X
-1 f
-1308(operation)X
-1636(behaves)X
-1920(exactly)X
-2177(like)X
-2322(the)X
-2 f
-2445(log)X
-1 f
-2572(operation)X
-2900(but)X
-3026(guarantees)X
-3394(that)X
-3538(the)X
-3660(log)X
-3786(has)X
-3917(been)X
-4093(forced)X
-555 4252(to)N
-643(disk)X
-802(before)X
-1034(returning.)X
-1394(A)X
-1478(discussion)X
-1837(of)X
-1930(our)X
-2063(commit)X
-2333(strategy)X
-2613(appears)X
-2884(in)X
-2971(the)X
-3094(implementation)X
-3621(section)X
-3873(\(section)X
-4152(4.2\).)X
-2 f
-555 4342(Log_unroll)N
-1 f
-935(reads)X
-1126(log)X
-1249(records)X
-1507(from)X
-1684(the)X
-1803(log,)X
-1946(following)X
-2278(backward)X
-2611(transaction)X
-2983(pointers)X
-3261(and)X
-3397(calling)X
-3635(the)X
-3753(appropriate)X
-4139(undo)X
-555 4432(routines)N
-839(to)X
-927(implement)X
-1295(transaction)X
-1673(abort.)X
-1904(In)X
-1997(a)X
-2059(similar)X
-2307(manner,)X
-2 f
-2594(log_roll)X
-1 f
-2877(reads)X
-3073(log)X
-3201(records)X
-3464(sequentially)X
-3877(forward,)X
-4178(cal-)X
-555 4522(ling)N
-699(the)X
-817(appropriate)X
-1203(redo)X
-1366(routines)X
-1644(to)X
-1726(recover)X
-1988(committed)X
-2350(transactions)X
-2753(after)X
-2921(a)X
-2977(system)X
-3219(crash.)X
-3 f
-555 4708(3.2.2.)N
-775(The)X
-928(Buffer)X
-1171(Manager)X
-1 f
-755 4831(The)N
-3 f
-912(Buffer)X
-1167(Manager)X
-1 f
-1511(uses)X
-1681(a)X
-1749(pool)X
-1923(of)X
-2022(shared)X
-2264(memory)X
-2563(to)X
-2657(provide)X
-2934(a)X
-3002(least-recently-used)X
-3641(\(LRU\))X
-3886(block)X
-4095(cache.)X
-555 4921(Although)N
-886(the)X
-1013(current)X
-1270(library)X
-1513(provides)X
-1818(an)X
-1923(LRU)X
-2112(cache,)X
-2345(it)X
-2418(would)X
-2647(be)X
-2752(simple)X
-2994(to)X
-3085(add)X
-3229(alternate)X
-3534(replacement)X
-3955(policies)X
-4232(as)X
-555 5011(suggested)N
-903(by)X
-1015([CHOU85])X
-1408(or)X
-1507(to)X
-1601(provide)X
-1878(multiple)X
-2176(buffer)X
-2405(pools)X
-2610(with)X
-2784(different)X
-3092(policies.)X
-3412(Transactions)X
-3853(request)X
-4116(pages)X
-555 5101(from)N
-736(the)X
-859(buffer)X
-1081(manager)X
-1383(and)X
-1524(keep)X
-1701(them)X
-3 f
-1886(pinned)X
-1 f
-2145(to)X
-2232(ensure)X
-2466(that)X
-2610(they)X
-2772(are)X
-2895(not)X
-3021(written)X
-3272(to)X
-3358(disk)X
-3515(while)X
-3717(they)X
-3879(are)X
-4002(in)X
-4088(a)X
-4148(logi-)X
-555 5191(cally)N
-732(inconsistent)X
-1135(state.)X
-1343(When)X
-1556(page)X
-1729(replacement)X
-2143(is)X
-2217(necessary,)X
-2571(the)X
-3 f
-2689(Buffer)X
-2932(Manager)X
-1 f
-3264(\256nds)X
-3439(an)X
-3535(unpinned)X
-3853(page)X
-4025(and)X
-4161(then)X
-555 5281(checks)N
-794(with)X
-956(the)X
-3 f
-1074(Log)X
-1227(Manager)X
-1 f
-1559(to)X
-1641(ensure)X
-1871(that)X
-2011(the)X
-2129(write-ahead)X
-2529(protocol)X
-2816(is)X
-2889(enforced.)X
-3 f
-555 5467(3.2.3.)N
-775(The)X
-928(Lock)X
-1121(Manager)X
-1 f
-755 5590(The)N
-3 f
-901(Lock)X
-1095(Manager)X
-1 f
-1428(supports)X
-1720(general)X
-1978(purpose)X
-2253(locking)X
-2514(\(single)X
-2753(writer,)X
-2986(multiple)X
-3273(readers\))X
-3553(which)X
-3769(is)X
-3842(currently)X
-4152(used)X
-555 5680(to)N
-638(provide)X
-904(two-phase)X
-1254(locking)X
-1514(and)X
-1650(high)X
-1812(concurrency)X
-2230(B-tree)X
-2451(locking.)X
-2751(However,)X
-3086(the)X
-3204(general)X
-3461(purpose)X
-3735(nature)X
-3956(of)X
-4043(the)X
-4161(lock)X
-
-6 p
-%%Page: 6 6
-10 s 10 xH 0 xS 1 f
-3 f
-1 f
-555 630(manager)N
-857(provides)X
-1158(the)X
-1281(ability)X
-1510(to)X
-1597(support)X
-1862(a)X
-1923(variety)X
-2171(of)X
-2263(locking)X
-2528(protocols.)X
-2890(Currently,)X
-3241(all)X
-3345(locks)X
-3538(are)X
-3661(issued)X
-3885(at)X
-3967(the)X
-4089(granu-)X
-555 720(larity)N
-747(of)X
-837(a)X
-896(page)X
-1071(\(the)X
-1219(size)X
-1367(of)X
-1457(a)X
-1516(buffer)X
-1736(in)X
-1821(the)X
-1942(buffer)X
-2161(pool\))X
-2352(which)X
-2570(is)X
-2645(identi\256ed)X
-2969(by)X
-3071(two)X
-3213(4-byte)X
-3440(integers)X
-3716(\(a)X
-3801(\256le)X
-3925(id)X
-4009(and)X
-4147(page)X
-555 810(number\).)N
-898(This)X
-1071(provides)X
-1378(the)X
-1507(necessary)X
-1851(information)X
-2259(to)X
-2351(extend)X
-2595(the)X
-3 f
-2723(Lock)X
-2926(Manager)X
-1 f
-3268(to)X
-3360(perform)X
-3649(hierarchical)X
-4059(locking)X
-555 900([GRAY76].)N
-982(The)X
-1133(current)X
-1387(implementation)X
-1915(does)X
-2088(not)X
-2216(support)X
-2482(locks)X
-2677(at)X
-2760(other)X
-2950(granularities)X
-3376(and)X
-3517(does)X
-3689(not)X
-3816(promote)X
-4108(locks;)X
-555 990(these)N
-740(are)X
-859(obvious)X
-1132(future)X
-1344(additions)X
-1657(to)X
-1739(the)X
-1857(system.)X
-755 1113(If)N
-831(an)X
-929(incoming)X
-1253(lock)X
-1413(request)X
-1667(cannot)X
-1903(be)X
-2001(granted,)X
-2284(the)X
-2404(requesting)X
-2760(process)X
-3023(is)X
-3098(queued)X
-3352(for)X
-3467(the)X
-3586(lock)X
-3745(and)X
-3882(descheduled.)X
-555 1203(When)N
-769(a)X
-827(lock)X
-987(is)X
-1062(released,)X
-1368(the)X
-1488(wait)X
-1647(queue)X
-1860(is)X
-1934(traversed)X
-2250(and)X
-2387(any)X
-2524(newly)X
-2741(compatible)X
-3118(locks)X
-3308(are)X
-3428(granted.)X
-3730(Locks)X
-3947(are)X
-4067(located)X
-555 1293(via)N
-680(a)X
-743(\256le)X
-872(and)X
-1015(page)X
-1194(hash)X
-1368(table)X
-1551(and)X
-1694(are)X
-1820(chained)X
-2097(both)X
-2266(by)X
-2373(object)X
-2595(and)X
-2737(by)X
-2843(transaction,)X
-3241(facilitating)X
-3614(rapid)X
-3805(traversal)X
-4108(of)X
-4201(the)X
-555 1383(lock)N
-713(table)X
-889(during)X
-1118(transaction)X
-1490(commit)X
-1754(and)X
-1890(abort.)X
-755 1506(The)N
-907(primary)X
-1188(interfaces)X
-1528(to)X
-1617(the)X
-1742(lock)X
-1907(manager)X
-2211(are)X
-2 f
-2337(lock)X
-1 f
-2471(,)X
-2 f
-2518(unlock)X
-1 f
-2732(,)X
-2779(and)X
-2 f
-2922(lock_unlock_all)X
-1 f
-3434(.)X
-2 f
-3500(Lock)X
-1 f
-3682(obtains)X
-3939(a)X
-4001(new)X
-4161(lock)X
-555 1596(for)N
-680(a)X
-747(speci\256c)X
-1023(object.)X
-1290(There)X
-1509(are)X
-1638(also)X
-1797(two)X
-1947(variants)X
-2231(of)X
-2328(the)X
-2 f
-2456(lock)X
-1 f
-2620(request,)X
-2 f
-2902(lock_upgrade)X
-1 f
-3373(and)X
-2 f
-3519(lock_downgrade)X
-1 f
-4053(,)X
-4103(which)X
-555 1686(allow)N
-755(the)X
-875(caller)X
-1076(to)X
-1160(atomically)X
-1519(trade)X
-1701(a)X
-1758(lock)X
-1917(of)X
-2005(one)X
-2142(type)X
-2301(for)X
-2416(a)X
-2473(lock)X
-2632(of)X
-2720(another.)X
-2 f
-3022(Unlock)X
-1 f
-3275(releases)X
-3551(a)X
-3608(speci\256c)X
-3874(mode)X
-4073(of)X
-4161(lock)X
-555 1776(on)N
-655(a)X
-711(speci\256c)X
-976(object.)X
-2 f
-1232(Lock_unlock_all)X
-1 f
-1786(releases)X
-2061(all)X
-2161(the)X
-2279(locks)X
-2468(associated)X
-2818(with)X
-2980(a)X
-3036(speci\256c)X
-3301(transaction.)X
-3 f
-555 1962(3.2.4.)N
-775(The)X
-928(Process)X
-1207(Manager)X
-1 f
-755 2085(The)N
-3 f
-900(Process)X
-1179(Manager)X
-1 f
-1511(acts)X
-1656(as)X
-1743(a)X
-1799(user-level)X
-2136(scheduler)X
-2464(to)X
-2546(make)X
-2740(processes)X
-3068(wait)X
-3226(on)X
-3326(unavailable)X
-3716(locks)X
-3905(and)X
-4041(pending)X
-555 2175(buffer)N
-778(cache)X
-988(I/O.)X
-1161(For)X
-1297(each)X
-1470(process,)X
-1756(a)X
-1817(semaphore)X
-2190(is)X
-2268(maintained)X
-2649(upon)X
-2834(which)X
-3055(that)X
-3200(process)X
-3466(waits)X
-3660(when)X
-3859(it)X
-3928(needs)X
-4136(to)X
-4223(be)X
-555 2265(descheduled.)N
-1014(When)X
-1228(a)X
-1286(process)X
-1549(needs)X
-1754(to)X
-1838(be)X
-1936(run,)X
-2084(its)X
-2180(semaphore)X
-2549(is)X
-2623(cleared,)X
-2897(and)X
-3034(the)X
-3153(operating)X
-3477(system)X
-3720(reschedules)X
-4116(it.)X
-4201(No)X
-555 2355(sophisticated)N
-1002(scheduling)X
-1378(algorithm)X
-1718(is)X
-1799(applied;)X
-2085(if)X
-2162(the)X
-2288(lock)X
-2454(for)X
-2576(which)X
-2800(a)X
-2864(process)X
-3133(was)X
-3286(waiting)X
-3554(becomes)X
-3863(available,)X
-4201(the)X
-555 2445(process)N
-824(is)X
-905(made)X
-1107(runnable.)X
-1456(It)X
-1533(would)X
-1761(have)X
-1941(been)X
-2121(possible)X
-2411(to)X
-2501(change)X
-2757(the)X
-2883(kernel's)X
-3170(process)X
-3439(scheduler)X
-3775(to)X
-3865(interact)X
-4134(more)X
-555 2535(ef\256ciently)N
-900(with)X
-1062(the)X
-1180(lock)X
-1338(manager,)X
-1655(but)X
-1777(doing)X
-1979(so)X
-2070(would)X
-2290(have)X
-2462(compromised)X
-2918(our)X
-3045(commitment)X
-3469(to)X
-3551(a)X
-3607(user-level)X
-3944(package.)X
-3 f
-555 2721(3.2.5.)N
-775(The)X
-928(Transaction)X
-1361(Manager)X
-1 f
-755 2844(The)N
-3 f
-901(Transaction)X
-1335(Manager)X
-1 f
-1668(provides)X
-1965(the)X
-2084(standard)X
-2377(interface)X
-2680(of)X
-2 f
-2768(txn_begin)X
-1 f
-3084(,)X
-2 f
-3125(txn_commit)X
-1 f
-3499(,)X
-3540(and)X
-2 f
-3676(txn_abort)X
-1 f
-3987(.)X
-4047(It)X
-4116(keeps)X
-555 2934(track)N
-742(of)X
-835(all)X
-941(active)X
-1159(transactions,)X
-1588(assigns)X
-1845(unique)X
-2089(transaction)X
-2467(identi\256ers,)X
-2833(and)X
-2974(directs)X
-3213(the)X
-3336(abort)X
-3526(and)X
-3667(commit)X
-3936(processing.)X
-555 3024(When)N
-772(a)X
-2 f
-833(txn_begin)X
-1 f
-1174(is)X
-1252(issued,)X
-1497(the)X
-3 f
-1620(Transaction)X
-2058(Manager)X
-1 f
-2395(assigns)X
-2651(the)X
-2773(next)X
-2935(available)X
-3249(transaction)X
-3625(identi\256er,)X
-3958(allocates)X
-4263(a)X
-555 3114(per-process)N
-948(transaction)X
-1322(structure)X
-1625(in)X
-1709(shared)X
-1941(memory,)X
-2249(increments)X
-2622(the)X
-2741(count)X
-2940(of)X
-3028(active)X
-3241(transactions,)X
-3665(and)X
-3802(returns)X
-4046(the)X
-4165(new)X
-555 3204(transaction)N
-937(identi\256er)X
-1256(to)X
-1348(the)X
-1476(calling)X
-1724(process.)X
-2034(The)X
-2188(in-memory)X
-2573(transaction)X
-2954(structure)X
-3264(contains)X
-3560(a)X
-3625(pointer)X
-3881(into)X
-4034(the)X
-4161(lock)X
-555 3294(table)N
-734(for)X
-851(locks)X
-1043(held)X
-1204(by)X
-1307(this)X
-1445(transaction,)X
-1840(the)X
-1961(last)X
-2095(log)X
-2220(sequence)X
-2538(number,)X
-2826(a)X
-2885(transaction)X
-3260(state)X
-3430(\()X
-2 f
-3457(idle)X
-1 f
-(,)S
-2 f
-3620(running)X
-1 f
-3873(,)X
-2 f
-3915(aborting)X
-1 f
-4190(,)X
-4232(or)X
-2 f
-555 3384(committing\))N
-1 f
-942(,)X
-982(an)X
-1078(error)X
-1255(code,)X
-1447(and)X
-1583(a)X
-1639(semaphore)X
-2007(identi\256er.)X
-755 3507(At)N
-859(commit,)X
-1147(the)X
-3 f
-1269(Transaction)X
-1706(Manager)X
-1 f
-2042(calls)X
-2 f
-2213(log_commit)X
-1 f
-2615(to)X
-2700(record)X
-2929(the)X
-3050(end)X
-3189(of)X
-3279(transaction)X
-3654(and)X
-3793(to)X
-3878(\257ush)X
-4056(the)X
-4177(log.)X
-555 3597(Then)N
-743(it)X
-810(directs)X
-1047(the)X
-3 f
-1168(Lock)X
-1364(Manager)X
-1 f
-1699(to)X
-1784(release)X
-2031(all)X
-2134(locks)X
-2325(associated)X
-2677(with)X
-2841(the)X
-2961(given)X
-3161(transaction.)X
-3575(If)X
-3651(a)X
-3709(transaction)X
-4083(aborts,)X
-555 3687(the)N
-3 f
-680(Transaction)X
-1120(Manager)X
-1 f
-1459(calls)X
-1633(on)X
-2 f
-1739(log_unroll)X
-1 f
-2102(to)X
-2190(read)X
-2355(the)X
-2479(transaction's)X
-2915(log)X
-3043(records)X
-3306(and)X
-3448(undo)X
-3634(any)X
-3776(modi\256cations)X
-4237(to)X
-555 3777(the)N
-673(database.)X
-1010(As)X
-1119(in)X
-1201(the)X
-1319(commit)X
-1583(case,)X
-1762(it)X
-1826(then)X
-1984(calls)X
-2 f
-2151(lock_unlock_all)X
-1 f
-2683(to)X
-2765(release)X
-3009(the)X
-3127(transaction's)X
-3557(locks.)X
-3 f
-555 3963(3.2.6.)N
-775(The)X
-928(Record)X
-1198(Manager)X
-1 f
-755 4086(The)N
-3 f
-919(Record)X
-1208(Manager)X
-1 f
-1559(supports)X
-1869(the)X
-2006(abstraction)X
-2397(of)X
-2503(reading)X
-2783(and)X
-2938(writing)X
-3208(records)X
-3484(to)X
-3585(a)X
-3660(database.)X
-3996(We)X
-4147(have)X
-555 4176(modi\256ed)N
-861(the)X
-981(the)X
-1101(database)X
-1399(access)X
-1626(routines)X
-3 f
-1905(db)X
-1 f
-1993(\(3\))X
-2108([BSD91])X
-2418(to)X
-2501(call)X
-2638(the)X
-2757(log,)X
-2900(lock,)X
-3079(and)X
-3216(buffer)X
-3434(managers.)X
-3803(In)X
-3891(order)X
-4082(to)X
-4165(pro-)X
-555 4266(vide)N
-718(functionality)X
-1152(to)X
-1239(perform)X
-1523(undo)X
-1708(and)X
-1849(redo,)X
-2037(the)X
-3 f
-2160(Record)X
-2434(Manager)X
-1 f
-2770(de\256nes)X
-3021(a)X
-3081(collection)X
-3421(of)X
-3512(log)X
-3638(record)X
-3868(types)X
-4061(and)X
-4201(the)X
-555 4356(associated)N
-920(undo)X
-1115(and)X
-1266(redo)X
-1444(routines.)X
-1777(The)X
-3 f
-1937(Log)X
-2105(Manager)X
-1 f
-2452(performs)X
-2777(a)X
-2848(table)X
-3039(lookup)X
-3296(on)X
-3411(the)X
-3543(record)X
-3783(type)X
-3955(to)X
-4051(call)X
-4201(the)X
-555 4446(appropriate)N
-951(routines.)X
-1299(For)X
-1440(example,)X
-1762(the)X
-1890(B-tree)X
-2121(access)X
-2356(method)X
-2625(requires)X
-2913(two)X
-3062(log)X
-3193(record)X
-3428(types:)X
-3648(insert)X
-3855(and)X
-4000(delete.)X
-4241(A)X
-555 4536(replace)N
-808(operation)X
-1131(is)X
-1204(implemented)X
-1642(as)X
-1729(a)X
-1785(delete)X
-1997(followed)X
-2302(by)X
-2402(an)X
-2498(insert)X
-2696(and)X
-2832(is)X
-2905(logged)X
-3143(accordingly.)X
-3 f
-555 4722(3.3.)N
-715(Application)X
-1134(Architectures)X
-1 f
-755 4845(The)N
-907(structure)X
-1215(of)X
-1309(LIBTP)X
-1558(allows)X
-1794(application)X
-2177(designers)X
-2507(to)X
-2596(trade)X
-2784(off)X
-2905(performance)X
-3339(and)X
-3481(protection.)X
-3872(Since)X
-4076(a)X
-4138(large)X
-555 4935(portion)N
-810(of)X
-901(LIBTP's)X
-1205(functionality)X
-1638(is)X
-1715(provided)X
-2024(by)X
-2128(managing)X
-2468(structures)X
-2804(in)X
-2889(shared)X
-3122(memory,)X
-3432(its)X
-3530(structures)X
-3865(are)X
-3987(subject)X
-4237(to)X
-555 5025(corruption)N
-926(by)X
-1043(applications)X
-1467(when)X
-1678(the)X
-1813(library)X
-2064(is)X
-2154(linked)X
-2391(directly)X
-2673(with)X
-2852(the)X
-2987(application.)X
-3420(For)X
-3568(this)X
-3720(reason,)X
-3987(LIBTP)X
-4246(is)X
-555 5115(designed)N
-864(to)X
-950(allow)X
-1152(compilation)X
-1558(into)X
-1706(a)X
-1766(separate)X
-2053(server)X
-2273(process)X
-2537(which)X
-2756(may)X
-2917(be)X
-3016(accessed)X
-3321(via)X
-3442(a)X
-3501(socket)X
-3729(interface.)X
-4094(In)X
-4184(this)X
-555 5205(way)N
-712(LIBTP's)X
-1015(data)X
-1172(structures)X
-1507(are)X
-1629(protected)X
-1951(from)X
-2130(application)X
-2509(code,)X
-2704(but)X
-2829(communication)X
-3349(overhead)X
-3666(is)X
-3741(increased.)X
-4107(When)X
-555 5295(applications)N
-975(are)X
-1107(trusted,)X
-1377(LIBTP)X
-1631(may)X
-1801(be)X
-1909(compiled)X
-2239(directly)X
-2516(into)X
-2672(the)X
-2802(application)X
-3190(providing)X
-3533(improved)X
-3872(performance.)X
-555 5385(Figures)N
-815(two)X
-955(and)X
-1091(three)X
-1272(show)X
-1461(the)X
-1579(two)X
-1719(alternate)X
-2016(application)X
-2392(architectures.)X
-755 5508(There)N
-964(are)X
-1084(potentially)X
-1447(two)X
-1588(modes)X
-1818(in)X
-1901(which)X
-2118(one)X
-2255(might)X
-2462(use)X
-2590(LIBTP)X
-2833(in)X
-2916(a)X
-2972(server)X
-3189(based)X
-3392(architecture.)X
-3832(In)X
-3919(the)X
-4037(\256rst,)X
-4201(the)X
-555 5598(server)N
-778(would)X
-1004(provide)X
-1275(the)X
-1399(capability)X
-1741(to)X
-1829(respond)X
-2109(to)X
-2197(requests)X
-2486(to)X
-2574(each)X
-2747(of)X
-2839(the)X
-2962(low)X
-3107(level)X
-3288(modules)X
-3584(\(lock,)X
-3794(log,)X
-3941(buffer,)X
-4183(and)X
-555 5688(transaction)N
-944(managers\).)X
-1356(Unfortunately,)X
-1863(the)X
-1998(performance)X
-2442(of)X
-2546(such)X
-2730(a)X
-2803(system)X
-3062(is)X
-3152(likely)X
-3371(to)X
-3470(be)X
-3583(blindingly)X
-3947(slow)X
-4134(since)X
-
-7 p
-%%Page: 7 7
-10 s 10 xH 0 xS 1 f
-3 f
-1 f
-1 Dt
-1864 1125 MXY
-15 -26 Dl
--15 10 Dl
--14 -10 Dl
-14 26 Dl
-0 -266 Dl
-1315 1125 MXY
-15 -26 Dl
--15 10 Dl
--14 -10 Dl
-14 26 Dl
-0 -266 Dl
-3 Dt
-1133 1125 MXY
-0 798 Dl
-931 0 Dl
-0 -798 Dl
--931 0 Dl
-1 Dt
-1266 1257 MXY
-0 133 Dl
-665 0 Dl
-0 -133 Dl
--665 0 Dl
-3 f
-8 s
-1513 1351(driver)N
-1502 1617(LIBTP)N
-1266 1390 MXY
-0 400 Dl
-665 0 Dl
-0 -400 Dl
--665 0 Dl
-3 Dt
-1133 726 MXY
-0 133 Dl
-931 0 Dl
-0 -133 Dl
--931 0 Dl
-1 f
-1029 1098(txn_abort)N
-964 1015(txn_commit)N
-1018 932(txn_begin)N
-1910 1015(db_ops)N
-3 f
-1308 820(Application)N
-1645(Program)X
-1398 1218(Server)N
-1594(Process)X
-1 f
-1390 986(socket)N
-1569(interface)X
-1 Dt
-1848 967 MXY
--23 -14 Dl
-8 14 Dl
--8 15 Dl
-23 -15 Dl
--50 0 Dl
-1324 MX
-23 15 Dl
--9 -15 Dl
-9 -14 Dl
--23 14 Dl
-50 0 Dl
-3 Dt
-2862 859 MXY
-0 1064 Dl
-932 0 Dl
-0 -1064 Dl
--932 0 Dl
-1 Dt
-3178 1390 MXY
-24 -12 Dl
--17 0 Dl
--8 -15 Dl
-1 27 Dl
-150 -265 Dl
-3494 1390 MXY
-0 -27 Dl
--8 15 Dl
--16 1 Dl
-24 11 Dl
--166 -265 Dl
-3 f
-3232 1617(LIBTP)N
-2995 1390 MXY
-0 400 Dl
-666 0 Dl
-0 -400 Dl
--666 0 Dl
-992 MY
-0 133 Dl
-666 0 Dl
-0 -133 Dl
--666 0 Dl
-3168 1086(Application)N
-1 f
-2939 1201(txn_begin)N
-2885 1284(txn_commit)N
-2950 1368(txn_abort)N
-3465 1284(db_ops)N
-3 f
-3155 766(Single)N
-3339(Process)X
-3 Dt
--1 Ds
-811 2100(Figure)N
-1023(2:)X
-1107(Server)X
-1318(Architecture.)X
-1 f
-1727(In)X
-1811(this)X
-1934(con\256guration,)X
-811 2190(the)N
-916(library)X
-1113(is)X
-1183(loaded)X
-1380(into)X
-1507(a)X
-1562(server)X
-1744(process)X
-1962(which)X
-2145(is)X
-2214(ac-)X
-811 2280(cessed)N
-993(via)X
-1087(a)X
-1131(socket)X
-1310(interface.)X
-3 f
-2563 2100(Figure)N
-2803(3:)X
-2914(Single)X
-3140(Process)X
-3403(Architecture.)X
-1 f
-3839(In)X
-3950(this)X
-2563 2190(con\256guration,)N
-2948(the)X
-3053(library)X
-3250(routines)X
-3483(are)X
-3587(loaded)X
-3784(as)X
-3864(part)X
-3990(of)X
-2563 2280(the)N
-2657(application)X
-2957(and)X
-3065(accessed)X
-3303(via)X
-3397(a)X
-3441(subroutine)X
-3727(interface.)X
-10 s
-10 f
-555 2403(h)N
-579(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)X
-1 f
-555 2679(modifying)N
-909(a)X
-966(piece)X
-1157(of)X
-1245(data)X
-1400(would)X
-1621(require)X
-1870(three)X
-2051(or)X
-2138(possibly)X
-2424(four)X
-2578(separate)X
-2862(communications:)X
-3433(one)X
-3569(to)X
-3651(lock)X
-3809(the)X
-3927(data,)X
-4101(one)X
-4237(to)X
-555 2769(obtain)N
-781(the)X
-905(data,)X
-1085(one)X
-1227(to)X
-1315(log)X
-1443(the)X
-1567(modi\256cation,)X
-2017(and)X
-2159(possibly)X
-2451(one)X
-2593(to)X
-2681(transmit)X
-2969(the)X
-3093(modi\256ed)X
-3403(data.)X
-3583(Figure)X
-3817(four)X
-3976(shows)X
-4201(the)X
-555 2859(relative)N
-826(performance)X
-1263(for)X
-1387(retrieving)X
-1728(a)X
-1793(single)X
-2013(record)X
-2248(using)X
-2450(the)X
-2577(record)X
-2812(level)X
-2997(call)X
-3142(versus)X
-3376(using)X
-3578(the)X
-3705(lower)X
-3917(level)X
-4102(buffer)X
-555 2949(management)N
-987(and)X
-1125(locking)X
-1387(calls.)X
-1616(The)X
-1763(2:1)X
-1887(ratio)X
-2056(observed)X
-2367(in)X
-2450(the)X
-2569(single)X
-2781(process)X
-3043(case)X
-3203(re\257ects)X
-3456(the)X
-3575(additional)X
-3916(overhead)X
-4232(of)X
-555 3039(parsing)N
-819(eight)X
-1006(commands)X
-1380(rather)X
-1595(than)X
-1760(one)X
-1903(while)X
-2108(the)X
-2233(3:1)X
-2362(ratio)X
-2536(observed)X
-2853(in)X
-2942(the)X
-3067(client/server)X
-3491(architecture)X
-3898(re\257ects)X
-4157(both)X
-555 3129(the)N
-679(parsing)X
-941(and)X
-1083(the)X
-1207(communication)X
-1731(overheard.)X
-2118(Although)X
-2445(there)X
-2631(may)X
-2794(be)X
-2895(applications)X
-3307(which)X
-3528(could)X
-3731(tolerate)X
-3997(such)X
-4169(per-)X
-555 3219(formance,)N
-904(it)X
-973(seems)X
-1194(far)X
-1309(more)X
-1499(feasible)X
-1774(to)X
-1861(support)X
-2126(a)X
-2187(higher)X
-2417(level)X
-2597(interface,)X
-2923(such)X
-3094(as)X
-3185(that)X
-3329(provided)X
-3638(by)X
-3742(a)X
-3802(query)X
-4009(language)X
-555 3309(\()N
-2 f
-582(e.g.)X
-1 f
-718(SQL)X
-889([SQL86]\).)X
-755 3432(Although)N
-1081(LIBTP)X
-1327(does)X
-1498(not)X
-1624(have)X
-1800(an)X
-1900(SQL)X
-2075(parser,)X
-2316(we)X
-2433(have)X
-2608(built)X
-2777(a)X
-2836(server)X
-3056(application)X
-3435(using)X
-3631(the)X
-3752(toolkit)X
-3983(command)X
-555 3522(language)N
-882(\(TCL\))X
-1124([OUST90].)X
-1544(The)X
-1706(server)X
-1940(supports)X
-2248(a)X
-2321(command)X
-2674(line)X
-2831(interface)X
-3150(similar)X
-3409(to)X
-3508(the)X
-3643(subroutine)X
-4017(interface)X
-555 3612(de\256ned)N
-811(in)X
-3 f
-893(db)X
-1 f
-981(\(3\).)X
-1135(Since)X
-1333(it)X
-1397(is)X
-1470(based)X
-1673(on)X
-1773(TCL,)X
-1964(it)X
-2028(provides)X
-2324(control)X
-2571(structures)X
-2903(as)X
-2990(well.)X
-3 f
-555 3798(4.)N
-655(Implementation)X
-1 f
-3 f
-555 3984(4.1.)N
-715(Locking)X
-1014(and)X
-1162(Deadlock)X
-1502(Detection)X
-1 f
-755 4107(LIBTP)N
-1007(uses)X
-1175(two-phase)X
-1535(locking)X
-1805(for)X
-1929(user)X
-2093(data.)X
-2297(Strictly)X
-2562(speaking,)X
-2897(the)X
-3024(two)X
-3173(phases)X
-3416(in)X
-3507(two-phase)X
-3866(locking)X
-4135(are)X
-4263(a)X
-3 f
-555 4197(grow)N
-1 f
-756(phase,)X
-986(during)X
-1221(which)X
-1443(locks)X
-1638(are)X
-1763(acquired,)X
-2086(and)X
-2228(a)X
-3 f
-2290(shrink)X
-1 f
-2537(phase,)X
-2766(during)X
-3001(which)X
-3223(locks)X
-3418(are)X
-3543(released.)X
-3873(No)X
-3997(lock)X
-4161(may)X
-555 4287(ever)N
-720(be)X
-822(acquired)X
-1124(during)X
-1358(the)X
-1481(shrink)X
-1706(phase.)X
-1954(The)X
-2104(grow)X
-2294(phase)X
-2502(lasts)X
-2669(until)X
-2840(the)X
-2963(\256rst)X
-3112(release,)X
-3381(which)X
-3602(marks)X
-3823(the)X
-3946(start)X
-4109(of)X
-4201(the)X
-555 4377(shrink)N
-780(phase.)X
-1028(In)X
-1120(practice,)X
-1420(the)X
-1543(grow)X
-1733(phase)X
-1941(lasts)X
-2108(for)X
-2227(the)X
-2350(duration)X
-2642(of)X
-2734(a)X
-2795(transaction)X
-3172(in)X
-3259(LIBTP)X
-3506(and)X
-3647(in)X
-3734(commercial)X
-4138(data-)X
-555 4467(base)N
-721(systems.)X
-1037(The)X
-1184(shrink)X
-1406(phase)X
-1611(takes)X
-1798(place)X
-1990(during)X
-2221(transaction)X
-2595(commit)X
-2861(or)X
-2950(abort.)X
-3177(This)X
-3341(means)X
-3568(that)X
-3710(locks)X
-3901(are)X
-4022(acquired)X
-555 4557(on)N
-655(demand)X
-929(during)X
-1158(the)X
-1276(lifetime)X
-1545(of)X
-1632(a)X
-1688(transaction,)X
-2080(and)X
-2216(held)X
-2374(until)X
-2540(commit)X
-2804(time,)X
-2986(at)X
-3064(which)X
-3280(point)X
-3464(all)X
-3564(locks)X
-3753(are)X
-3872(released.)X
-755 4680(If)N
-832(multiple)X
-1121(transactions)X
-1527(are)X
-1649(active)X
-1864(concurrently,)X
-2313(deadlocks)X
-2657(can)X
-2792(occur)X
-2994(and)X
-3133(must)X
-3311(be)X
-3410(detected)X
-3701(and)X
-3840(resolved.)X
-4174(The)X
-555 4770(lock)N
-715(table)X
-893(can)X
-1027(be)X
-1125(thought)X
-1391(of)X
-1480(as)X
-1569(a)X
-1627(representation)X
-2104(of)X
-2193(a)X
-2251(directed)X
-2532(graph.)X
-2777(The)X
-2924(nodes)X
-3133(in)X
-3216(the)X
-3335(graph)X
-3539(are)X
-3659(transactions.)X
-4103(Edges)X
-555 4860(represent)N
-878(the)X
-3 f
-1004(waits-for)X
-1 f
-1340(relation)X
-1613(between)X
-1909(transactions;)X
-2342(if)X
-2419(transaction)X
-2 f
-2799(A)X
-1 f
-2876(is)X
-2957(waiting)X
-3225(for)X
-3347(a)X
-3411(lock)X
-3577(held)X
-3743(by)X
-3851(transaction)X
-2 f
-4230(B)X
-1 f
-4279(,)X
-555 4950(then)N
-716(a)X
-775(directed)X
-1057(edge)X
-1232(exists)X
-1437(from)X
-2 f
-1616(A)X
-1 f
-1687(to)X
-2 f
-1771(B)X
-1 f
-1842(in)X
-1926(the)X
-2046(graph.)X
-2291(A)X
-2371(deadlock)X
-2683(exists)X
-2887(if)X
-2958(a)X
-3016(cycle)X
-3208(appears)X
-3476(in)X
-3560(the)X
-3680(graph.)X
-3925(By)X
-4040(conven-)X
-555 5040(tion,)N
-719(no)X
-819(transaction)X
-1191(ever)X
-1350(waits)X
-1539(for)X
-1653(a)X
-1709(lock)X
-1867(it)X
-1931(already)X
-2188(holds,)X
-2401(so)X
-2492(re\257exive)X
-2793(edges)X
-2996(are)X
-3115(impossible.)X
-755 5163(A)N
-836(distinguished)X
-1285(process)X
-1549(monitors)X
-1856(the)X
-1977(lock)X
-2138(table,)X
-2337(searching)X
-2668(for)X
-2785(cycles.)X
-3048(The)X
-3195(frequency)X
-3539(with)X
-3703(which)X
-3921(this)X
-4058(process)X
-555 5253(runs)N
-716(is)X
-792(user-settable;)X
-1243(for)X
-1360(the)X
-1481(multi-user)X
-1833(tests)X
-1998(discussed)X
-2328(in)X
-2413(section)X
-2663(5.1.2,)X
-2866(it)X
-2933(has)X
-3063(been)X
-3238(set)X
-3350(to)X
-3435(wake)X
-3628(up)X
-3731(every)X
-3932(second,)X
-4197(but)X
-555 5343(more)N
-742(sophisticated)X
-1182(schedules)X
-1516(are)X
-1636(certainly)X
-1938(possible.)X
-2261(When)X
-2474(a)X
-2531(cycle)X
-2722(is)X
-2796(detected,)X
-3105(one)X
-3242(of)X
-3330(the)X
-3449(transactions)X
-3853(in)X
-3936(the)X
-4055(cycle)X
-4246(is)X
-555 5433(nominated)N
-917(and)X
-1057(aborted.)X
-1362(When)X
-1578(the)X
-1700(transaction)X
-2076(aborts,)X
-2315(it)X
-2382(rolls)X
-2547(back)X
-2722(its)X
-2820(changes)X
-3102(and)X
-3241(releases)X
-3519(its)X
-3617(locks,)X
-3829(thereby)X
-4093(break-)X
-555 5523(ing)N
-677(the)X
-795(cycle)X
-985(in)X
-1067(the)X
-1185(graph.)X
-
-8 p
-%%Page: 8 8
-10 s 10 xH 0 xS 1 f
-3 f
-1 f
-4 Ds
-1 Dt
-1866 865 MXY
-1338 0 Dl
-1866 1031 MXY
-1338 0 Dl
-1866 1199 MXY
-1338 0 Dl
-1866 1366 MXY
-1338 0 Dl
-1866 1533 MXY
-1338 0 Dl
-1866 1701 MXY
-1338 0 Dl
--1 Ds
-5 Dt
-1866 1868 MXY
-1338 0 Dl
-1 Dt
-1 Di
-2981 MX
- 2981 1868 lineto
- 2981 1575 lineto
- 3092 1575 lineto
- 3092 1868 lineto
- 2981 1868 lineto
-closepath 21 2981 1575 3092 1868 Dp
-2646 MX
- 2646 1868 lineto
- 2646 949 lineto
- 2758 949 lineto
- 2758 1868 lineto
- 2646 1868 lineto
-closepath 14 2646 949 2758 1868 Dp
-2312 MX
- 2312 1868 lineto
- 2312 1701 lineto
- 2423 1701 lineto
- 2423 1868 lineto
- 2312 1868 lineto
-closepath 3 2312 1701 2423 1868 Dp
-1977 MX
- 1977 1868 lineto
- 1977 1512 lineto
- 2089 1512 lineto
- 2089 1868 lineto
- 1977 1868 lineto
-closepath 19 1977 1512 2089 1868 Dp
-3 f
-2640 2047(Client/Server)N
-1957(Single)X
-2185(Process)X
-7 s
-2957 1957(record)N
-2570(component)X
-2289(record)X
-1890(components)X
-1733 1724(.1)N
-1733 1556(.2)N
-1733 1389(.3)N
-1733 1222(.4)N
-1733 1055(.5)N
-1733 889(.6)N
-1590 726(Elapsed)N
-1794(Time)X
-1613 782(\(in)N
-1693(seconds\))X
-3 Dt
--1 Ds
-8 s
-555 2255(Figure)N
-756(4:)X
-829(Comparison)X
-1187(of)X
-1260(High)X
-1416(and)X
-1540(Low)X
-1681(Level)X
-1850(Interfaces.)X
-1 f
-2174(Elapsed)X
-2395(time)X
-2528(in)X
-2597(seconds)X
-2818(to)X
-2887(perform)X
-3111(a)X
-3158(single)X
-3330(record)X
-3511(retrieval)X
-3742(from)X
-3885(a)X
-3932(command)X
-4203(line)X
-555 2345(\(rather)N
-751(than)X
-888(a)X
-943(procedural)X
-1241(interface\))X
-1510(is)X
-1579(shown)X
-1772(on)X
-1862(the)X
-1966(y)X
-2024(axis.)X
-2185(The)X
-2310(``component'')X
-2704(numbers)X
-2950(re\257ect)X
-3135(the)X
-3239(timings)X
-3458(when)X
-3622(the)X
-3726(record)X
-3914(is)X
-3983(retrieved)X
-4235(by)X
-555 2435(separate)N
-785(calls)X
-924(to)X
-996(the)X
-1096(lock)X
-1228(manager)X
-1469(and)X
-1583(buffer)X
-1760(manager)X
-2001(while)X
-2165(the)X
-2264(``record'')X
-2531(timings)X
-2745(were)X
-2889(obtained)X
-3130(by)X
-3215(using)X
-3375(a)X
-3424(single)X
-3598(call)X
-3711(to)X
-3782(the)X
-3881(record)X
-4064(manager.)X
-555 2525(The)N
-674(2:1)X
-776(ratio)X
-913(observed)X
-1163(for)X
-1257(the)X
-1355(single)X
-1528(process)X
-1739(case)X
-1868(is)X
-1930(a)X
-1977(re\257ection)X
-2237(of)X
-2309(the)X
-2406(parsing)X
-2613(overhead)X
-2865(for)X
-2958(executing)X
-3225(eight)X
-3372(separate)X
-3599(commands)X
-3895(rather)X
-4062(than)X
-4191(one.)X
-555 2615(The)N
-673(additional)X
-948(factor)X
-1115(of)X
-1187(one)X
-1298(re\257ected)X
-1536(in)X
-1605(the)X
-1702(3:1)X
-1803(ratio)X
-1939(for)X
-2031(the)X
-2127(client/server)X
-2460(architecture)X
-2794(is)X
-2855(due)X
-2965(to)X
-3033(the)X
-3129(communication)X
-3545(overhead.)X
-3828(The)X
-3945(true)X
-4062(ratios)X
-4222(are)X
-555 2705(actually)N
-775(worse)X
-945(since)X
-1094(the)X
-1190(component)X
-1492(timings)X
-1703(do)X
-1785(not)X
-1884(re\257ect)X
-2060(the)X
-2155(search)X
-2334(times)X
-2490(within)X
-2671(each)X
-2804(page)X
-2941(or)X
-3011(the)X
-3106(time)X
-3237(required)X
-3466(to)X
-3533(transmit)X
-3760(the)X
-3855(page)X
-3992(between)X
-4221(the)X
-555 2795(two)N
-667(processes.)X
-10 s
-10 f
-555 2885(h)N
-579(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)X
-3 f
-555 3161(4.2.)N
-715(Group)X
-961(Commit)X
-1 f
-755 3284(Since)N
-959(the)X
-1083(log)X
-1211(must)X
-1392(be)X
-1494(\257ushed)X
-1751(to)X
-1839(disk)X
-1997(at)X
-2080(commit)X
-2349(time,)X
-2536(disk)X
-2694(bandwidth)X
-3057(fundamentally)X
-3545(limits)X
-3751(the)X
-3874(rate)X
-4020(at)X
-4103(which)X
-555 3374(transactions)N
-959(complete.)X
-1314(Since)X
-1513(most)X
-1688(transactions)X
-2091(write)X
-2276(only)X
-2438(a)X
-2494(few)X
-2635(small)X
-2828(records)X
-3085(to)X
-3167(the)X
-3285(log,)X
-3427(the)X
-3545(last)X
-3676(page)X
-3848(of)X
-3935(the)X
-4053(log)X
-4175(will)X
-555 3464(be)N
-658(\257ushed)X
-916(once)X
-1095(by)X
-1202(every)X
-1408(transaction)X
-1787(which)X
-2010(writes)X
-2233(to)X
-2322(it.)X
-2433(In)X
-2527(the)X
-2652(naive)X
-2853(implementation,)X
-3402(these)X
-3593(\257ushes)X
-3841(would)X
-4067(happen)X
-555 3554(serially.)N
-755 3677(LIBTP)N
-1008(uses)X
-3 f
-1177(group)X
-1412(commit)X
-1 f
-1702([DEWI84])X
-2077(in)X
-2170(order)X
-2371(to)X
-2464(amortize)X
-2775(the)X
-2903(cost)X
-3062(of)X
-3159(one)X
-3305(synchronous)X
-3740(disk)X
-3903(write)X
-4098(across)X
-555 3767(multiple)N
-851(transactions.)X
-1304(Group)X
-1539(commit)X
-1812(provides)X
-2117(a)X
-2182(way)X
-2345(for)X
-2468(a)X
-2533(group)X
-2749(of)X
-2845(transactions)X
-3257(to)X
-3348(commit)X
-3621(simultaneously.)X
-4174(The)X
-555 3857(\256rst)N
-709(several)X
-967(transactions)X
-1380(to)X
-1472(commit)X
-1745(write)X
-1939(their)X
-2115(changes)X
-2403(to)X
-2494(the)X
-2621(in-memory)X
-3006(log)X
-3137(page,)X
-3338(then)X
-3505(sleep)X
-3699(on)X
-3808(a)X
-3873(distinguished)X
-555 3947(semaphore.)N
-966(Later,)X
-1179(a)X
-1238(committing)X
-1629(transaction)X
-2004(\257ushes)X
-2249(the)X
-2370(page)X
-2545(to)X
-2630(disk,)X
-2805(and)X
-2943(wakes)X
-3166(up)X
-3268(all)X
-3370(its)X
-3467(sleeping)X
-3756(peers.)X
-3988(The)X
-4135(point)X
-555 4037(at)N
-635(which)X
-853(changes)X
-1134(are)X
-1255(actually)X
-1531(written)X
-1780(is)X
-1855(determined)X
-2238(by)X
-2340(three)X
-2523(thresholds.)X
-2914(The)X
-3061(\256rst)X
-3207(is)X
-3281(the)X
-2 f
-3400(group)X
-3612(threshold)X
-1 f
-3935(and)X
-4072(de\256nes)X
-555 4127(the)N
-674(minimum)X
-1005(number)X
-1271(of)X
-1359(transactions)X
-1763(which)X
-1979(must)X
-2154(be)X
-2250(active)X
-2462(in)X
-2544(the)X
-2662(system)X
-2904(before)X
-3130(transactions)X
-3533(are)X
-3652(forced)X
-3878(to)X
-3960(participate)X
-555 4217(in)N
-646(a)X
-711(group)X
-927(commit.)X
-1240(The)X
-1394(second)X
-1646(is)X
-1728(the)X
-2 f
-1855(wait)X
-2021(threshold)X
-1 f
-2352(which)X
-2577(is)X
-2658(expressed)X
-3003(as)X
-3098(the)X
-3224(percentage)X
-3601(of)X
-3696(active)X
-3916(transactions)X
-555 4307(waiting)N
-826(to)X
-919(be)X
-1026(committed.)X
-1439(The)X
-1595(last)X
-1737(is)X
-1821(the)X
-2 f
-1950(logdelay)X
-2257(threshold)X
-1 f
-2590(which)X
-2816(indicates)X
-3131(how)X
-3299(much)X
-3507(un\257ushed)X
-3848(log)X
-3980(should)X
-4223(be)X
-555 4397(allowed)N
-829(to)X
-911(accumulate)X
-1297(before)X
-1523(a)X
-1579(waiting)X
-1839(transaction's)X
-2289(commit)X
-2553(record)X
-2779(is)X
-2852(\257ushed.)X
-755 4520(Group)N
-981(commit)X
-1246(can)X
-1379(substantially)X
-1803(improve)X
-2090(performance)X
-2517(for)X
-2631(high-concurrency)X
-3218(environments.)X
-3714(If)X
-3788(only)X
-3950(a)X
-4006(few)X
-4147(tran-)X
-555 4610(sactions)N
-836(are)X
-957(running,)X
-1248(it)X
-1314(is)X
-1389(unlikely)X
-1673(to)X
-1757(improve)X
-2046(things)X
-2263(at)X
-2343(all.)X
-2485(The)X
-2632(crossover)X
-2962(point)X
-3148(is)X
-3223(the)X
-3343(point)X
-3529(at)X
-3609(which)X
-3827(the)X
-3947(transaction)X
-555 4700(commit)N
-823(rate)X
-968(is)X
-1045(limited)X
-1295(by)X
-1399(the)X
-1521(bandwidth)X
-1883(of)X
-1974(the)X
-2096(device)X
-2330(on)X
-2434(which)X
-2654(the)X
-2776(log)X
-2902(resides.)X
-3189(If)X
-3267(processes)X
-3599(are)X
-3722(trying)X
-3937(to)X
-4023(\257ush)X
-4201(the)X
-555 4790(log)N
-677(faster)X
-876(than)X
-1034(the)X
-1152(log)X
-1274(disk)X
-1427(can)X
-1559(accept)X
-1785(data,)X
-1959(then)X
-2117(group)X
-2324(commit)X
-2588(will)X
-2732(increase)X
-3016(the)X
-3134(commit)X
-3398(rate.)X
-3 f
-555 4976(4.3.)N
-715(Kernel)X
-971(Intervention)X
-1418(for)X
-1541(Synchronization)X
-1 f
-755 5099(Since)N
-954(LIBTP)X
-1197(uses)X
-1356(data)X
-1511(in)X
-1594(shared)X
-1825(memory)X
-2113(\()X
-2 f
-2140(e.g.)X
-1 f
-2277(the)X
-2395(lock)X
-2553(table)X
-2729(and)X
-2865(buffer)X
-3082(pool\))X
-3271(it)X
-3335(must)X
-3510(be)X
-3606(possible)X
-3888(for)X
-4002(a)X
-4058(process)X
-555 5189(to)N
-640(acquire)X
-900(exclusive)X
-1226(access)X
-1454(to)X
-1538(shared)X
-1770(data)X
-1926(in)X
-2010(order)X
-2202(to)X
-2286(prevent)X
-2549(corruption.)X
-2945(In)X
-3034(addition,)X
-3338(the)X
-3458(process)X
-3721(manager)X
-4020(must)X
-4197(put)X
-555 5279(processes)N
-886(to)X
-971(sleep)X
-1159(when)X
-1356(the)X
-1477(lock)X
-1638(or)X
-1728(buffer)X
-1948(they)X
-2109(request)X
-2364(is)X
-2440(in)X
-2525(use)X
-2655(by)X
-2758(some)X
-2950(other)X
-3138(process.)X
-3441(In)X
-3530(the)X
-3650(LIBTP)X
-3894(implementa-)X
-555 5385(tion)N
-705(under)X
-914(Ultrix)X
-1131(4.0)X
-7 s
-5353(2)Y
-10 s
-5385(,)Y
-1305(we)X
-1424(use)X
-1556(System)X
-1816(V)X
-1899(semaphores)X
-2303(to)X
-2390(provide)X
-2660(this)X
-2800(synchronization.)X
-3377(Semaphores)X
-3794(implemented)X
-4237(in)X
-555 5475(this)N
-701(fashion)X
-968(turn)X
-1128(out)X
-1261(to)X
-1354(be)X
-1461(an)X
-1568(expensive)X
-1920(choice)X
-2161(for)X
-2285(synchronization,)X
-2847(because)X
-3132(each)X
-3310(access)X
-3546(traps)X
-3732(to)X
-3824(the)X
-3952(kernel)X
-4183(and)X
-8 s
-10 f
-555 5547(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)N
-5 s
-1 f
-727 5625(2)N
-8 s
-763 5650(Ultrix)N
-932(and)X
-1040(DEC)X
-1184(are)X
-1277(trademarks)X
-1576(of)X
-1645(Digital)X
-1839(Equipment)X
-2136(Corporation.)X
-
-9 p
-%%Page: 9 9
-8 s 8 xH 0 xS 1 f
-10 s
-3 f
-1 f
-555 630(executes)N
-852(atomically)X
-1210(there.)X
-755 753(On)N
-878(architectures)X
-1314(that)X
-1459(support)X
-1724(atomic)X
-1967(test-and-set,)X
-2382(a)X
-2443(much)X
-2646(better)X
-2854(choice)X
-3089(would)X
-3314(be)X
-3415(to)X
-3502(attempt)X
-3767(to)X
-3854(obtain)X
-4079(a)X
-4139(spin-)X
-555 843(lock)N
-714(with)X
-877(a)X
-934(test-and-set,)X
-1345(and)X
-1482(issue)X
-1663(a)X
-1720(system)X
-1963(call)X
-2100(only)X
-2263(if)X
-2333(the)X
-2452(spinlock)X
-2744(is)X
-2818(unavailable.)X
-3249(Since)X
-3447(virtually)X
-3738(all)X
-3838(semaphores)X
-4237(in)X
-555 933(LIBTP)N
-801(are)X
-924(uncontested)X
-1330(and)X
-1469(are)X
-1591(held)X
-1752(for)X
-1869(very)X
-2035(short)X
-2218(periods)X
-2477(of)X
-2567(time,)X
-2752(this)X
-2890(would)X
-3113(improve)X
-3403(performance.)X
-3873(For)X
-4007(example,)X
-555 1023(processes)N
-885(must)X
-1062(acquire)X
-1321(exclusive)X
-1646(access)X
-1874(to)X
-1958(buffer)X
-2177(pool)X
-2341(metadata)X
-2653(in)X
-2737(order)X
-2929(to)X
-3013(\256nd)X
-3159(and)X
-3297(pin)X
-3421(a)X
-3479(buffer)X
-3698(in)X
-3781(shared)X
-4012(memory.)X
-555 1113(This)N
-721(semaphore)X
-1093(is)X
-1170(requested)X
-1502(most)X
-1681(frequently)X
-2034(in)X
-2119(LIBTP.)X
-2404(However,)X
-2742(once)X
-2917(it)X
-2984(is)X
-3060(acquired,)X
-3380(only)X
-3545(a)X
-3604(few)X
-3748(instructions)X
-4144(must)X
-555 1203(be)N
-656(executed)X
-966(before)X
-1196(it)X
-1264(is)X
-1341(released.)X
-1669(On)X
-1791(one)X
-1931(architecture)X
-2335(for)X
-2453(which)X
-2673(we)X
-2791(were)X
-2972(able)X
-3130(to)X
-3216(gather)X
-3441(detailed)X
-3719(pro\256ling)X
-4018(informa-)X
-555 1293(tion,)N
-729(the)X
-857(cost)X
-1015(of)X
-1111(the)X
-1238(semaphore)X
-1615(calls)X
-1791(accounted)X
-2146(for)X
-2269(25%)X
-2445(of)X
-2541(the)X
-2668(total)X
-2839(time)X
-3010(spent)X
-3208(updating)X
-3517(the)X
-3644(metadata.)X
-4003(This)X
-4174(was)X
-555 1383(fairly)N
-749(consistent)X
-1089(across)X
-1310(most)X
-1485(of)X
-1572(the)X
-1690(critical)X
-1933(sections.)X
-755 1506(In)N
-848(an)X
-950(attempt)X
-1216(to)X
-1304(quantify)X
-1597(the)X
-1720(overhead)X
-2040(of)X
-2132(kernel)X
-2358(synchronization,)X
-2915(we)X
-3034(ran)X
-3162(tests)X
-3329(on)X
-3434(a)X
-3495(version)X
-3756(of)X
-3848(4.3BSD-Reno)X
-555 1596(which)N
-786(had)X
-937(been)X
-1123(modi\256ed)X
-1441(to)X
-1537(support)X
-1811(binary)X
-2050(semaphore)X
-2432(facilities)X
-2742(similar)X
-2998(to)X
-3094(those)X
-3297(described)X
-3639(in)X
-3735([POSIX91].)X
-4174(The)X
-555 1686(hardware)N
-880(platform)X
-1181(consisted)X
-1504(of)X
-1595(an)X
-1695(HP300)X
-1941(\(33MHz)X
-2237(MC68030\))X
-2612(workstation)X
-3014(with)X
-3180(16MBytes)X
-3537(of)X
-3628(main)X
-3812(memory,)X
-4123(and)X
-4263(a)X
-555 1776(600MByte)N
-920(HP7959)X
-1205(SCSI)X
-1396(disk)X
-1552(\(17)X
-1682(ms)X
-1798(average)X
-2072(seek)X
-2237(time\).)X
-2468(We)X
-2602(ran)X
-2727(three)X
-2910(sets)X
-3052(of)X
-3141(comparisons)X
-3568(which)X
-3786(are)X
-3907(summarized)X
-555 1866(in)N
-645(\256gure)X
-860(\256ve.)X
-1028(In)X
-1123(each)X
-1299(comparison)X
-1701(we)X
-1823(ran)X
-1954(two)X
-2102(tests,)X
-2292(one)X
-2436(using)X
-2637(hardware)X
-2965(spinlocks)X
-3295(and)X
-3438(the)X
-3563(other)X
-3755(using)X
-3955(kernel)X
-4183(call)X
-555 1956(synchronization.)N
-1135(Since)X
-1341(the)X
-1467(test)X
-1606(was)X
-1758(run)X
-1892(single-user,)X
-2291(none)X
-2474(of)X
-2568(the)X
-2693(the)X
-2818(locks)X
-3014(were)X
-3198(contested.)X
-3568(In)X
-3662(the)X
-3787(\256rst)X
-3938(two)X
-4085(sets)X
-4232(of)X
-555 2046(tests,)N
-743(we)X
-863(ran)X
-992(the)X
-1116(full)X
-1253(transaction)X
-1631(processing)X
-2000(benchmark)X
-2383(described)X
-2717(in)X
-2805(section)X
-3058(5.1.)X
-3223(In)X
-3315(one)X
-3456(case)X
-3620(we)X
-3739(ran)X
-3867(with)X
-4034(both)X
-4201(the)X
-555 2136(database)N
-854(and)X
-992(log)X
-1116(on)X
-1218(the)X
-1338(same)X
-1525(disk)X
-1680(\(1)X
-1769(Disk\))X
-1969(and)X
-2107(in)X
-2191(the)X
-2311(second,)X
-2576(we)X
-2692(ran)X
-2817(with)X
-2981(the)X
-3101(database)X
-3400(and)X
-3538(log)X
-3661(on)X
-3762(separate)X
-4047(disks)X
-4232(\(2)X
-555 2226(Disk\).)N
-800(In)X
-894(the)X
-1019(last)X
-1157(test,)X
-1315(we)X
-1436(wanted)X
-1695(to)X
-1784(create)X
-2004(a)X
-2067(CPU)X
-2249(bound)X
-2476(environment,)X
-2928(so)X
-3026(we)X
-3146(used)X
-3319(a)X
-3381(database)X
-3684(small)X
-3883(enough)X
-4145(to)X
-4233(\256t)X
-555 2316(completely)N
-941(in)X
-1033(the)X
-1161(cache)X
-1375(and)X
-1521(issued)X
-1751(read-only)X
-2089(transactions.)X
-2541(The)X
-2695(results)X
-2933(in)X
-3024(\256gure)X
-3240(\256ve)X
-3389(express)X
-3659(the)X
-3786(kernel)X
-4016(call)X
-4161(syn-)X
-555 2406(chronization)N
-980(performance)X
-1411(as)X
-1502(a)X
-1562(percentage)X
-1935(of)X
-2026(the)X
-2148(spinlock)X
-2443(performance.)X
-2914(For)X
-3049(example,)X
-3365(in)X
-3451(the)X
-3573(1)X
-3637(disk)X
-3794(case,)X
-3977(the)X
-4098(kernel)X
-555 2496(call)N
-697(implementation)X
-1225(achieved)X
-1537(4.4)X
-1662(TPS)X
-1824(\(transactions)X
-2259(per)X
-2387(second\))X
-2662(while)X
-2865(the)X
-2988(semaphore)X
-3361(implementation)X
-3888(achieved)X
-4199(4.6)X
-555 2586(TPS,)N
-735(and)X
-874(the)X
-995(relative)X
-1259(performance)X
-1689(of)X
-1779(the)X
-1900(kernel)X
-2123(synchronization)X
-2657(is)X
-2732(96%)X
-2901(that)X
-3043(of)X
-3132(the)X
-3252(spinlock)X
-3545(\(100)X
-3714(*)X
-3776(4.4)X
-3898(/)X
-3942(4.6\).)X
-4111(There)X
-555 2676(are)N
-674(two)X
-814(striking)X
-1078(observations)X
-1503(from)X
-1679(these)X
-1864(results:)X
-10 f
-635 2799(g)N
-1 f
-755(even)X
-927(when)X
-1121(the)X
-1239(system)X
-1481(is)X
-1554(disk)X
-1707(bound,)X
-1947(the)X
-2065(CPU)X
-2240(cost)X
-2389(of)X
-2476(synchronization)X
-3008(is)X
-3081(noticeable,)X
-3451(and)X
-10 f
-635 2922(g)N
-1 f
-755(when)X
-949(we)X
-1063(are)X
-1182(CPU)X
-1357(bound,)X
-1597(the)X
-1715(difference)X
-2062(is)X
-2135(dramatic)X
-2436(\(67%\).)X
-3 f
-555 3108(4.4.)N
-715(Transaction)X
-1148(Protected)X
-1499(Access)X
-1747(Methods)X
-1 f
-755 3231(The)N
-903(B-tree)X
-1127(and)X
-1266(\256xed)X
-1449(length)X
-1671(recno)X
-1872(\(record)X
-2127(number\))X
-2421(access)X
-2649(methods)X
-2942(have)X
-3116(been)X
-3290(modi\256ed)X
-3596(to)X
-3680(provide)X
-3947(transaction)X
-555 3321(protection.)N
-941(Whereas)X
-1244(the)X
-1363(previously)X
-1722(published)X
-2054(interface)X
-2357(to)X
-2440(the)X
-2559(access)X
-2786(routines)X
-3065(had)X
-3202(separate)X
-3487(open)X
-3664(calls)X
-3832(for)X
-3946(each)X
-4114(of)X
-4201(the)X
-10 f
-555 3507(h)N
-579(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)X
-1 Dt
-2978 5036 MXY
- 2978 5036 lineto
- 2978 4662 lineto
- 3093 4662 lineto
- 3093 5036 lineto
- 2978 5036 lineto
-closepath 21 2978 4662 3093 5036 Dp
-2518 MX
- 2518 5036 lineto
- 2518 3960 lineto
- 2633 3960 lineto
- 2633 5036 lineto
- 2518 5036 lineto
-closepath 3 2518 3960 2633 5036 Dp
-2059 MX
- 2059 5036 lineto
- 2059 3946 lineto
- 2174 3946 lineto
- 2174 5036 lineto
- 2059 5036 lineto
-closepath 1 2059 3946 2174 5036 Dp
-3 f
-7 s
-2912 5141(Read-only)N
-1426 3767(of)N
-1487(Spinlock)X
-1710(Throughput)X
-1480 3710(Throughput)N
-1786(as)X
-1850(a)X
-1892(%)X
-11 s
-1670 4843(20)N
-1670 4614(40)N
-1670 4384(60)N
-1670 4155(80)N
-1648 3925(100)N
-7 s
-2041 5141(1)N
-2083(Disk)X
-2490(2)X
-2532(Disks)X
-5 Dt
-1829 5036 MXY
-1494 0 Dl
-4 Ds
-1 Dt
-1829 4806 MXY
-1494 0 Dl
-1829 4577 MXY
-1494 0 Dl
-1829 4347 MXY
-1494 0 Dl
-1829 4118 MXY
-1494 0 Dl
-1829 3888 MXY
-1494 0 Dl
-3 Dt
--1 Ds
-8 s
-555 5360(Figure)N
-753(5:)X
-823(Kernel)X
-1028(Overhead)X
-1315(for)X
-1413(System)X
-1625(Call)X
-1756(Synchronization.)X
-1 f
-2254(The)X
-2370(performance)X
-2708(of)X
-2778(the)X
-2873(kernel)X
-3049(call)X
-3158(synchronization)X
-3583(is)X
-3643(expressed)X
-3911(as)X
-3980(a)X
-4024(percentage)X
-555 5450(of)N
-625(the)X
-720(spinlock)X
-954(synchronization)X
-1379(performance.)X
-1749(In)X
-1819(disk)X
-1943(bound)X
-2120(cases)X
-2271(\(1)X
-2341(Disk)X
-2479(and)X
-2588(2)X
-2637(Disks\),)X
-2837(we)X
-2928(see)X
-3026(that)X
-3139(4-6%)X
-3294(of)X
-3364(the)X
-3459(performance)X
-3797(is)X
-3857(lost)X
-3966(due)X
-4074(to)X
-4140(kernel)X
-555 5540(calls)N
-688(while)X
-846(in)X
-912(the)X
-1006(CPU)X
-1147(bound)X
-1323(case,)X
-1464(we)X
-1554(have)X
-1690(lost)X
-1799(67%)X
-1932(of)X
-2001(the)X
-2095(performance)X
-2432(due)X
-2540(to)X
-2606(kernel)X
-2781(calls.)X
-
-10 p
-%%Page: 10 10
-8 s 8 xH 0 xS 1 f
-10 s
-3 f
-1 f
-555 630(access)N
-781(methods,)X
-1092(we)X
-1206(now)X
-1364(have)X
-1536(an)X
-1632(integrated)X
-1973(open)X
-2149(call)X
-2285(with)X
-2447(the)X
-2565(following)X
-2896(calling)X
-3134(conventions:)X
-7 f
-715 753(DB)N
-859(*dbopen)X
-1243(\(const)X
-1579(char)X
-1819(*file,)X
-2155(int)X
-2347(flags,)X
-2683(int)X
-2875(mode,)X
-3163(DBTYPE)X
-3499(type,)X
-1291 843(int)N
-1483(dbflags,)X
-1915(const)X
-2203(void)X
-2443(*openinfo\))X
-1 f
-555 966(where)N
-2 f
-774(\256le)X
-1 f
-894(is)X
-969(the)X
-1089(name)X
-1285(of)X
-1374(the)X
-1494(\256le)X
-1618(being)X
-1818(opened,)X
-2 f
-2092(\257ags)X
-1 f
-2265(and)X
-2 f
-2402(mode)X
-1 f
-2597(are)X
-2717(the)X
-2836(standard)X
-3129(arguments)X
-3484(to)X
-3 f
-3567(open)X
-1 f
-3731(\(2\),)X
-2 f
-3866(type)X
-1 f
-4021(is)X
-4095(one)X
-4232(of)X
-555 1056(the)N
-680(access)X
-913(method)X
-1180(types,)X
-2 f
-1396(db\257ags)X
-1 f
-1654(indicates)X
-1966(the)X
-2091(mode)X
-2296(of)X
-2390(the)X
-2515(buffer)X
-2739(pool)X
-2907(and)X
-3049(transaction)X
-3427(protection,)X
-3798(and)X
-2 f
-3940(openinfo)X
-1 f
-4246(is)X
-555 1146(the)N
-681(access)X
-915(method)X
-1183(speci\256c)X
-1456(information.)X
-1902(Currently,)X
-2257(the)X
-2383(possible)X
-2673(values)X
-2906(for)X
-2 f
-3028(db\257ags)X
-1 f
-3287(are)X
-3414(DB_SHARED)X
-3912(and)X
-4055(DB_TP)X
-555 1236(indicating)N
-895(that)X
-1035(buffers)X
-1283(should)X
-1516(be)X
-1612(kept)X
-1770(in)X
-1852(a)X
-1908(shared)X
-2138(buffer)X
-2355(pool)X
-2517(and)X
-2653(that)X
-2793(the)X
-2911(\256le)X
-3033(should)X
-3266(be)X
-3362(transaction)X
-3734(protected.)X
-755 1359(The)N
-900(modi\256cations)X
-1355(required)X
-1643(to)X
-1725(add)X
-1861(transaction)X
-2233(protection)X
-2578(to)X
-2660(an)X
-2756(access)X
-2982(method)X
-3242(are)X
-3361(quite)X
-3541(simple)X
-3774(and)X
-3910(localized.)X
-715 1482(1.)N
-795(Replace)X
-1074(\256le)X
-2 f
-1196(open)X
-1 f
-1372(with)X
-2 f
-1534(buf_open)X
-1 f
-1832(.)X
-715 1572(2.)N
-795(Replace)X
-1074(\256le)X
-2 f
-1196(read)X
-1 f
-1363(and)X
-2 f
-1499(write)X
-1 f
-1683(calls)X
-1850(with)X
-2012(buffer)X
-2229(manager)X
-2526(calls)X
-2693(\()X
-2 f
-2720(buf_get)X
-1 f
-(,)S
-2 f
-3000(buf_unpin)X
-1 f
-3324(\).)X
-715 1662(3.)N
-795(Precede)X
-1070(buffer)X
-1287(manager)X
-1584(calls)X
-1751(with)X
-1913(an)X
-2009(appropriate)X
-2395(\(read)X
-2581(or)X
-2668(write\))X
-2880(lock)X
-3038(call.)X
-715 1752(4.)N
-795(Before)X
-1034(updates,)X
-1319(issue)X
-1499(a)X
-1555(logging)X
-1819(operation.)X
-715 1842(5.)N
-795(After)X
-985(data)X
-1139(have)X
-1311(been)X
-1483(accessed,)X
-1805(release)X
-2049(the)X
-2167(buffer)X
-2384(manager)X
-2681(pin.)X
-715 1932(6.)N
-795(Provide)X
-1064(undo/redo)X
-1409(code)X
-1581(for)X
-1695(each)X
-1863(type)X
-2021(of)X
-2108(log)X
-2230(record)X
-2456(de\256ned.)X
-555 2071(The)N
-702(following)X
-1035(code)X
-1209(fragments)X
-1552(show)X
-1743(how)X
-1903(to)X
-1987(transaction)X
-2361(protect)X
-2606(several)X
-2856(updates)X
-3123(to)X
-3206(a)X
-3263(B-tree.)X
-7 s
-3484 2039(3)N
-10 s
-3533 2071(In)N
-3621(the)X
-3740(unprotected)X
-4140(case,)X
-555 2161(an)N
-652(open)X
-829(call)X
-966(is)X
-1040(followed)X
-1346(by)X
-1447(a)X
-1504(read)X
-1664(call)X
-1801(to)X
-1884(obtain)X
-2105(the)X
-2224(meta-data)X
-2562(for)X
-2677(the)X
-2796(B-tree.)X
-3058(Instead,)X
-3331(we)X
-3446(issue)X
-3627(an)X
-3724(open)X
-3901(to)X
-3984(the)X
-4102(buffer)X
-555 2251(manager)N
-852(to)X
-934(obtain)X
-1154(a)X
-1210(\256le)X
-1332(id)X
-1414(and)X
-1550(a)X
-1606(buffer)X
-1823(request)X
-2075(to)X
-2157(obtain)X
-2377(the)X
-2495(meta-data)X
-2832(as)X
-2919(shown)X
-3148(below.)X
-7 f
-715 2374(char)N
-955(*path;)X
-715 2464(int)N
-907(fid,)X
-1147(flags,)X
-1483(len,)X
-1723(mode;)X
-715 2644(/*)N
-859(Obtain)X
-1195(a)X
-1291(file)X
-1531(id)X
-1675(with)X
-1915(which)X
-2203(to)X
-2347(access)X
-2683(the)X
-2875(buffer)X
-3211(pool)X
-3451(*/)X
-715 2734(fid)N
-907(=)X
-1003(buf_open\(path,)X
-1723(flags,)X
-2059(mode\);)X
-715 2914(/*)N
-859(Read)X
-1099(the)X
-1291(meta)X
-1531(data)X
-1771(\(page)X
-2059(0\))X
-2203(for)X
-2395(the)X
-2587(B-tree)X
-2923(*/)X
-715 3004(if)N
-859(\(tp_lock\(fid,)X
-1531(0,)X
-1675(READ_LOCK\)\))X
-1003 3094(return)N
-1339(error;)X
-715 3184(meta_data_ptr)N
-1387(=)X
-1483(buf_get\(fid,)X
-2107(0,)X
-2251(BF_PIN,)X
-2635(&len\);)X
-1 f
-555 3307(The)N
-714(BF_PIN)X
-1014(argument)X
-1350(to)X
-2 f
-1445(buf_get)X
-1 f
-1718(indicates)X
-2036(that)X
-2189(we)X
-2316(wish)X
-2500(to)X
-2595(leave)X
-2798(this)X
-2946(page)X
-3131(pinned)X
-3382(in)X
-3477(memory)X
-3777(so)X
-3881(that)X
-4034(it)X
-4111(is)X
-4197(not)X
-555 3397(swapped)N
-862(out)X
-990(while)X
-1194(we)X
-1314(are)X
-1439(accessing)X
-1772(it.)X
-1881(The)X
-2031(last)X
-2167(argument)X
-2495(to)X
-2 f
-2582(buf_get)X
-1 f
-2847(returns)X
-3095(the)X
-3218(number)X
-3488(of)X
-3580(bytes)X
-3774(on)X
-3879(the)X
-4002(page)X
-4179(that)X
-555 3487(were)N
-732(valid)X
-912(so)X
-1003(that)X
-1143(the)X
-1261(access)X
-1487(method)X
-1747(may)X
-1905(initialize)X
-2205(the)X
-2323(page)X
-2495(if)X
-2564(necessary.)X
-755 3610(Next,)N
-955(consider)X
-1251(inserting)X
-1555(a)X
-1615(record)X
-1845(on)X
-1949(a)X
-2009(particular)X
-2341(page)X
-2517(of)X
-2608(a)X
-2668(B-tree.)X
-2932(In)X
-3022(the)X
-3143(unprotected)X
-3545(case,)X
-3727(we)X
-3844(read)X
-4006(the)X
-4127(page,)X
-555 3700(call)N
-2 f
-693(_bt_insertat)X
-1 f
-1079(,)X
-1121(and)X
-1258(write)X
-1444(the)X
-1563(page.)X
-1776(Instead,)X
-2049(we)X
-2164(lock)X
-2323(the)X
-2442(page,)X
-2635(request)X
-2888(the)X
-3007(buffer,)X
-3245(log)X
-3368(the)X
-3487(change,)X
-3756(modify)X
-4008(the)X
-4127(page,)X
-555 3790(and)N
-691(release)X
-935(the)X
-1053(buffer.)X
-7 f
-715 3913(int)N
-907(fid,)X
-1147(len,)X
-1387(pageno;)X
-1867(/*)X
-2011(Identifies)X
-2539(the)X
-2731(buffer)X
-3067(*/)X
-715 4003(int)N
-907(index;)X
-1867(/*)X
-2011(Location)X
-2443(at)X
-2587(which)X
-2875(to)X
-3019(insert)X
-3355(the)X
-3547(new)X
-3739(pair)X
-3979(*/)X
-715 4093(DBT)N
-907(*keyp,)X
-1243(*datap;)X
-1867(/*)X
-2011(Key/Data)X
-2443(pair)X
-2683(to)X
-2827(be)X
-2971(inserted)X
-3403(*/)X
-715 4183(DATUM)N
-1003(*d;)X
-1867(/*)X
-2011(Key/data)X
-2443(structure)X
-2923(to)X
-3067(insert)X
-3403(*/)X
-715 4363(/*)N
-859(Lock)X
-1099(and)X
-1291(request)X
-1675(the)X
-1867(buffer)X
-2203(*/)X
-715 4453(if)N
-859(\(tp_lock\(fid,)X
-1531(pageno,)X
-1915(WRITE_LOCK\)\))X
-1003 4543(return)N
-1339(error;)X
-715 4633(buffer_ptr)N
-1243(=)X
-1339(buf_get\(fid,)X
-1963(pageno,)X
-2347(BF_PIN,)X
-2731(&len\);)X
-715 4813(/*)N
-859(Log)X
-1051(and)X
-1243(perform)X
-1627(the)X
-1819(update)X
-2155(*/)X
-715 4903(log_insdel\(BTREE_INSERT,)N
-1915(fid,)X
-2155(pageno,)X
-2539(keyp,)X
-2827(datap\);)X
-715 4993(_bt_insertat\(buffer_ptr,)N
-1915(d,)X
-2059(index\);)X
-715 5083(buf_unpin\(buffer_ptr\);)N
-1 f
-555 5206(Succinctly,)N
-942(the)X
-1068(algorithm)X
-1407(for)X
-1529(turning)X
-1788(unprotected)X
-2195(code)X
-2375(into)X
-2527(protected)X
-2854(code)X
-3034(is)X
-3115(to)X
-3205(replace)X
-3466(read)X
-3633(operations)X
-3995(with)X
-2 f
-4165(lock)X
-1 f
-555 5296(and)N
-2 f
-691(buf_get)X
-1 f
-951(operations)X
-1305(and)X
-1441(write)X
-1626(operations)X
-1980(with)X
-2 f
-2142(log)X
-1 f
-2264(and)X
-2 f
-2400(buf_unpin)X
-1 f
-2744(operations.)X
-8 s
-10 f
-555 5458(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)N
-5 s
-1 f
-727 5536(3)N
-8 s
-766 5561(The)N
-884(following)X
-1152(code)X
-1291(fragments)X
-1565(are)X
-1661(examples,)X
-1937(but)X
-2038(do)X
-2120(not)X
-2220(de\256ne)X
-2394(the)X
-2490(\256nal)X
-2622(interface.)X
-2894(The)X
-3011(\256nal)X
-3143(interface)X
-3383(will)X
-3501(be)X
-3579(determined)X
-3884(after)X
-4018(LIBTP)X
-4214(has)X
-555 5633(been)N
-691(fully)X
-828(integrated)X
-1099(with)X
-1229(the)X
-1323(most)X
-1464(recent)X
-3 f
-1635(db)X
-1 f
-1707(\(3\))X
-1797(release)X
-1989(from)X
-2129(the)X
-2223(Computer)X
-2495(Systems)X
-2725(Research)X
-2974(Group)X
-3153(at)X
-3215(University)X
-3501(of)X
-3570(California,)X
-3861(Berkeley.)X
-
-11 p
-%%Page: 11 11
-8 s 8 xH 0 xS 1 f
-10 s
-3 f
-555 630(5.)N
-655(Performance)X
-1 f
-755 753(In)N
-845(this)X
-983(section,)X
-1253(we)X
-1370(present)X
-1625(the)X
-1746(results)X
-1978(of)X
-2067(two)X
-2209(very)X
-2374(different)X
-2673(benchmarks.)X
-3103(The)X
-3250(\256rst)X
-3396(is)X
-3471(an)X
-3569(online)X
-3791(transaction)X
-4165(pro-)X
-555 843(cessing)N
-824(benchmark,)X
-1234(similar)X
-1489(to)X
-1584(the)X
-1715(standard)X
-2020(TPCB,)X
-2272(but)X
-2407(has)X
-2547(been)X
-2732(adapted)X
-3015(to)X
-3110(run)X
-3250(in)X
-3345(a)X
-3414(desktop)X
-3696(environment.)X
-4174(The)X
-555 933(second)N
-798(emulates)X
-1103(a)X
-1159(computer-aided)X
-1683(design)X
-1912(environment)X
-2337(and)X
-2473(provides)X
-2769(more)X
-2954(complex)X
-3250(query)X
-3453(processing.)X
-3 f
-555 1119(5.1.)N
-715(Transaction)X
-1148(Processing)X
-1533(Benchmark)X
-1 f
-755 1242(For)N
-887(this)X
-1023(section,)X
-1291(all)X
-1392(performance)X
-1820(numbers)X
-2117(shown)X
-2346(except)X
-2576(for)X
-2690(the)X
-2808(commercial)X
-3207(database)X
-3504(system)X
-3746(were)X
-3923(obtained)X
-4219(on)X
-555 1332(a)N
-614(DECstation)X
-1009(5000/200)X
-1333(with)X
-1497(32MBytes)X
-1852(of)X
-1941(memory)X
-2230(running)X
-2501(Ultrix)X
-2714(V4.0,)X
-2914(accessing)X
-3244(a)X
-3302(DEC)X
-3484(RZ57)X
-3688(1GByte)X
-3959(disk)X
-4114(drive.)X
-555 1422(The)N
-720(commercial)X
-1139(relational)X
-1482(database)X
-1799(system)X
-2061(tests)X
-2242(were)X
-2438(run)X
-2584(on)X
-2703(a)X
-2778(comparable)X
-3192(machine,)X
-3523(a)X
-3598(Sparcstation)X
-4033(1+)X
-4157(with)X
-555 1512(32MBytes)N
-915(memory)X
-1209(and)X
-1352(a)X
-1415(1GByte)X
-1691(external)X
-1976(disk)X
-2135(drive.)X
-2366(The)X
-2517(database,)X
-2840(binaries)X
-3120(and)X
-3262(log)X
-3390(resided)X
-3648(on)X
-3754(the)X
-3878(same)X
-4069(device.)X
-555 1602(Reported)N
-869(times)X
-1062(are)X
-1181(the)X
-1299(means)X
-1524(of)X
-1611(\256ve)X
-1751(tests)X
-1913(and)X
-2049(have)X
-2221(standard)X
-2513(deviations)X
-2862(within)X
-3086(two)X
-3226(percent)X
-3483(of)X
-3570(the)X
-3688(mean.)X
-755 1725(The)N
-905(test)X
-1041(database)X
-1343(was)X
-1493(con\256gured)X
-1861(according)X
-2203(to)X
-2290(the)X
-2413(TPCB)X
-2637(scaling)X
-2889(rules)X
-3070(for)X
-3189(a)X
-3250(10)X
-3355(transaction)X
-3732(per)X
-3860(second)X
-4108(\(TPS\))X
-555 1815(system)N
-817(with)X
-999(1,000,000)X
-1359(account)X
-1649(records,)X
-1946(100)X
-2106(teller)X
-2311(records,)X
-2607(and)X
-2762(10)X
-2881(branch)X
-3139(records.)X
-3455(Where)X
-3709(TPS)X
-3885(numbers)X
-4200(are)X
-555 1905(reported,)N
-865(we)X
-981(are)X
-1102(running)X
-1373(a)X
-1431(modi\256ed)X
-1737(version)X
-1995(of)X
-2084(the)X
-2203(industry)X
-2486(standard)X
-2779(transaction)X
-3152(processing)X
-3516(benchmark,)X
-3914(TPCB.)X
-4174(The)X
-555 1995(TPCB)N
-780(benchmark)X
-1163(simulates)X
-1491(a)X
-1553(withdrawal)X
-1940(performed)X
-2301(by)X
-2407(a)X
-2469(hypothetical)X
-2891(teller)X
-3082(at)X
-3166(a)X
-3228(hypothetical)X
-3650(bank.)X
-3872(The)X
-4022(database)X
-555 2085(consists)N
-831(of)X
-921(relations)X
-1220(\(\256les\))X
-1430(for)X
-1547(accounts,)X
-1871(branches,)X
-2200(tellers,)X
-2439(and)X
-2578(history.)X
-2863(For)X
-2997(each)X
-3168(transaction,)X
-3563(the)X
-3684(account,)X
-3976(teller,)X
-4183(and)X
-555 2175(branch)N
-795(balances)X
-1093(must)X
-1269(be)X
-1366(updated)X
-1641(to)X
-1724(re\257ect)X
-1946(the)X
-2065(withdrawal)X
-2447(and)X
-2584(a)X
-2640(history)X
-2882(record)X
-3108(is)X
-3181(written)X
-3428(which)X
-3644(contains)X
-3931(the)X
-4049(account)X
-555 2265(id,)N
-657(branch)X
-896(id,)X
-998(teller)X
-1183(id,)X
-1285(and)X
-1421(the)X
-1539(amount)X
-1799(of)X
-1886(the)X
-2004(withdrawal)X
-2385([TPCB90].)X
-755 2388(Our)N
-914(implementation)X
-1450(of)X
-1551(the)X
-1683(benchmark)X
-2074(differs)X
-2317(from)X
-2506(the)X
-2637(speci\256cation)X
-3075(in)X
-3170(several)X
-3431(aspects.)X
-3736(The)X
-3894(speci\256cation)X
-555 2478(requires)N
-840(that)X
-985(the)X
-1108(database)X
-1410(keep)X
-1587(redundant)X
-1933(logs)X
-2091(on)X
-2196(different)X
-2498(devices,)X
-2784(but)X
-2911(we)X
-3030(use)X
-3162(a)X
-3223(single)X
-3439(log.)X
-3606(Furthermore,)X
-4052(all)X
-4157(tests)X
-555 2568(were)N
-734(run)X
-863(on)X
-965(a)X
-1023(single,)X
-1256(centralized)X
-1631(system)X
-1875(so)X
-1968(there)X
-2151(is)X
-2226(no)X
-2328(notion)X
-2553(of)X
-2641(remote)X
-2885(accesses.)X
-3219(Finally,)X
-3486(we)X
-3601(calculated)X
-3948(throughput)X
-555 2658(by)N
-662(dividing)X
-955(the)X
-1080(total)X
-1249(elapsed)X
-1517(time)X
-1686(by)X
-1793(the)X
-1918(number)X
-2190(of)X
-2284(transactions)X
-2694(processed)X
-3038(rather)X
-3253(than)X
-3418(by)X
-3525(computing)X
-3894(the)X
-4018(response)X
-555 2748(time)N
-717(for)X
-831(each)X
-999(transaction.)X
-755 2871(The)N
-912(performance)X
-1351(comparisons)X
-1788(focus)X
-1993(on)X
-2104(traditional)X
-2464(Unix)X
-2655(techniques)X
-3029(\(unprotected,)X
-3486(using)X
-3 f
-3690(\257ock)X
-1 f
-3854(\(2\))X
-3979(and)X
-4126(using)X
-3 f
-555 2961(fsync)N
-1 f
-733(\(2\)\))X
-884(and)X
-1030(a)X
-1096(commercial)X
-1504(relational)X
-1836(database)X
-2142(system.)X
-2433(Well-behaved)X
-2913(applications)X
-3329(using)X
-3 f
-3531(\257ock)X
-1 f
-3695(\(2\))X
-3818(are)X
-3946(guaranteed)X
-555 3051(that)N
-704(concurrent)X
-1077(processes')X
-1441(updates)X
-1715(do)X
-1824(not)X
-1955(interact)X
-2225(with)X
-2396(one)X
-2541(another,)X
-2831(but)X
-2962(no)X
-3070(guarantees)X
-3442(about)X
-3648(atomicity)X
-3978(are)X
-4105(made.)X
-555 3141(That)N
-731(is,)X
-833(if)X
-911(the)X
-1038(system)X
-1289(crashes)X
-1555(in)X
-1646(mid-transaction,)X
-2198(only)X
-2369(parts)X
-2554(of)X
-2649(that)X
-2797(transaction)X
-3177(will)X
-3329(be)X
-3433(re\257ected)X
-3738(in)X
-3828(the)X
-3954 0.3125(after-crash)AX
-555 3231(state)N
-725(of)X
-815(the)X
-936(database.)X
-1276(The)X
-1424(use)X
-1554(of)X
-3 f
-1643(fsync)X
-1 f
-1821(\(2\))X
-1937(at)X
-2017(transaction)X
-2391(commit)X
-2657(time)X
-2821(provides)X
-3119(guarantees)X
-3485(of)X
-3574(durability)X
-3907(after)X
-4077(system)X
-555 3321(failure.)N
-825(However,)X
-1160(there)X
-1341(is)X
-1414(no)X
-1514(mechanism)X
-1899(to)X
-1981(perform)X
-2260(transaction)X
-2632(abort.)X
-3 f
-555 3507(5.1.1.)N
-775(Single-User)X
-1191(Tests)X
-1 f
-755 3630(These)N
-978(tests)X
-1151(compare)X
-1459(LIBTP)X
-1712(in)X
-1804(a)X
-1870(variety)X
-2123(of)X
-2220(con\256gurations)X
-2708(to)X
-2800(traditional)X
-3159(UNIX)X
-3390(solutions)X
-3708(and)X
-3854(a)X
-3920(commercial)X
-555 3720(relational)N
-884(database)X
-1187(system)X
-1435(\(RDBMS\).)X
-1814(To)X
-1929(demonstrate)X
-2347(the)X
-2471(server)X
-2694(architecture)X
-3100(we)X
-3220(built)X
-3392(a)X
-3454(front)X
-3636(end)X
-3777(test)X
-3913(process)X
-4179(that)X
-555 3810(uses)N
-732(TCL)X
-922([OUST90])X
-1304(to)X
-1405(parse)X
-1614(database)X
-1930(access)X
-2175(commands)X
-2561(and)X
-2716(call)X
-2870(the)X
-3006(database)X
-3321(access)X
-3565(routines.)X
-3901(In)X
-4006(one)X
-4160(case)X
-555 3900(\(SERVER\),)N
-956(frontend)X
-1249(and)X
-1386(backend)X
-1675(processes)X
-2004(were)X
-2181(created)X
-2434(which)X
-2650(communicated)X
-3142(via)X
-3260(an)X
-3356(IP)X
-3447(socket.)X
-3712(In)X
-3799(the)X
-3917(second)X
-4160(case)X
-555 3990(\(TCL\),)N
-802(a)X
-860(single)X
-1073(process)X
-1336(read)X
-1497(queries)X
-1751(from)X
-1929(standard)X
-2223(input,)X
-2429(parsed)X
-2660(them,)X
-2861(and)X
-2998(called)X
-3211(the)X
-3330(database)X
-3628(access)X
-3855(routines.)X
-4174(The)X
-555 4080(performance)N
-987(difference)X
-1338(between)X
-1630(the)X
-1752(TCL)X
-1927(and)X
-2067(SERVER)X
-2397(tests)X
-2563(quanti\256es)X
-2898(the)X
-3020(communication)X
-3542(overhead)X
-3861(of)X
-3952(the)X
-4074(socket.)X
-555 4170(The)N
-732(RDBMS)X
-1063(implementation)X
-1617(used)X
-1816(embedded)X
-2198(SQL)X
-2401(in)X
-2515(C)X
-2620(with)X
-2814(stored)X
-3062(database)X
-3391(procedures.)X
-3835(Therefore,)X
-4224(its)X
-555 4260(con\256guration)N
-1003(is)X
-1076(a)X
-1132(hybrid)X
-1361(of)X
-1448(the)X
-1566(single)X
-1777(process)X
-2038(architecture)X
-2438(and)X
-2574(the)X
-2692(server)X
-2909(architecture.)X
-3349(The)X
-3494(graph)X
-3697(in)X
-3779(\256gure)X
-3986(six)X
-4099(shows)X
-555 4350(a)N
-611(comparison)X
-1005(of)X
-1092(the)X
-1210(following)X
-1541(six)X
-1654(con\256gurations:)X
-1126 4506(LIBTP)N
-1552(Uses)X
-1728(the)X
-1846(LIBTP)X
-2088(library)X
-2322(in)X
-2404(a)X
-2460(single)X
-2671(application.)X
-1126 4596(TCL)N
-1552(Uses)X
-1728(the)X
-1846(LIBTP)X
-2088(library)X
-2322(in)X
-2404(a)X
-2460(single)X
-2671(application,)X
-3067(requires)X
-3346(query)X
-3549(parsing.)X
-1126 4686(SERVER)N
-1552(Uses)X
-1728(the)X
-1846(LIBTP)X
-2088(library)X
-2322(in)X
-2404(a)X
-2460(server)X
-2677(con\256guration,)X
-3144(requires)X
-3423(query)X
-3626(parsing.)X
-1126 4776(NOTP)N
-1552(Uses)X
-1728(no)X
-1828(locking,)X
-2108(logging,)X
-2392(or)X
-2479(concurrency)X
-2897(control.)X
-1126 4866(FLOCK)N
-1552(Uses)X
-3 f
-1728(\257ock)X
-1 f
-1892(\(2\))X
-2006(for)X
-2120(concurrency)X
-2538(control)X
-2785(and)X
-2921(nothing)X
-3185(for)X
-3299(durability.)X
-1126 4956(FSYNC)N
-1552(Uses)X
-3 f
-1728(fsync)X
-1 f
-1906(\(2\))X
-2020(for)X
-2134(durability)X
-2465(and)X
-2601(nothing)X
-2865(for)X
-2979(concurrency)X
-3397(control.)X
-1126 5046(RDBMS)N
-1552(Uses)X
-1728(a)X
-1784(commercial)X
-2183(relational)X
-2506(database)X
-2803(system.)X
-755 5235(The)N
-902(results)X
-1133(show)X
-1324(that)X
-1466(LIBTP,)X
-1730(both)X
-1894(in)X
-1978(the)X
-2098(procedural)X
-2464(and)X
-2602(parsed)X
-2834(environments,)X
-3312(is)X
-3387(competitive)X
-3787(with)X
-3951(a)X
-4009(commer-)X
-555 5325(cial)N
-692(system)X
-935(\(comparing)X
-1326(LIBTP,)X
-1589(TCL,)X
-1781(and)X
-1917(RDBMS\).)X
-2263(Compared)X
-2617(to)X
-2699(existing)X
-2972(UNIX)X
-3193(solutions,)X
-3521(LIBTP)X
-3763(is)X
-3836(approximately)X
-555 5415(15%)N
-738(slower)X
-988(than)X
-1162(using)X
-3 f
-1371(\257ock)X
-1 f
-1535(\(2\))X
-1665(or)X
-1768(no)X
-1884(protection)X
-2245(but)X
-2383(over)X
-2562(80%)X
-2745(better)X
-2964(than)X
-3137(using)X
-3 f
-3345(fsync)X
-1 f
-3523(\(2\))X
-3652(\(comparing)X
-4057(LIBTP,)X
-555 5505(FLOCK,)N
-857(NOTP,)X
-1106(and)X
-1242(FSYNC\).)X
-
-12 p
-%%Page: 12 12
-10 s 10 xH 0 xS 1 f
-3 f
-8 s
-3500 2184(RDBMS)N
-1 Dt
-3553 2085 MXY
- 3553 2085 lineto
- 3676 2085 lineto
- 3676 1351 lineto
- 3553 1351 lineto
- 3553 2085 lineto
-closepath 16 3553 1351 3676 2085 Dp
-2018 2184(SERVER)N
-1720 1168 MXY
-0 917 Dl
-122 0 Dl
-0 -917 Dl
--122 0 Dl
-1715 2184(TCL)N
-2087 1534 MXY
- 2087 1534 lineto
- 2209 1534 lineto
- 2209 2085 lineto
- 2087 2085 lineto
- 2087 1534 lineto
-closepath 12 2087 1534 2209 2085 Dp
-3187 MX
- 3187 1534 lineto
- 3309 1534 lineto
- 3309 2085 lineto
- 3187 2085 lineto
- 3187 1534 lineto
-closepath 19 3187 1534 3309 2085 Dp
-3142 2184(FSYNC)N
-2425(NOTP)X
-2453 955 MXY
- 2453 955 lineto
- 2576 955 lineto
- 2576 2085 lineto
- 2453 2085 lineto
- 2453 955 lineto
-closepath 21 2453 955 2576 2085 Dp
-2820 1000 MXY
- 2820 1000 lineto
- 2942 1000 lineto
- 2942 2085 lineto
- 2820 2085 lineto
- 2820 1000 lineto
-closepath 14 2820 1000 2942 2085 Dp
-5 Dt
-1231 2085 MXY
-2567 0 Dl
-4 Ds
-1 Dt
-1231 1840 MXY
-2567 0 Dl
-1231 1596 MXY
-2567 0 Dl
-1231 1351 MXY
-2567 0 Dl
-1231 1108 MXY
-2567 0 Dl
-1231 863 MXY
-2567 0 Dl
-11 s
-1087 1877(2)N
-1087 1633(4)N
-1087 1388(6)N
-1087 1145(8)N
-1065 900(10)N
-1028 763(TPS)N
--1 Ds
-1353 2085 MXY
- 1353 2085 lineto
- 1353 1151 lineto
- 1476 1151 lineto
- 1476 2085 lineto
- 1353 2085 lineto
-closepath 3 1353 1151 1476 2085 Dp
-8 s
-1318 2184(LIBTP)N
-2767(FLOCK)X
-3 Dt
--1 Ds
-10 s
-1597 2399(Figure)N
-1844(6:)X
-1931(Single-User)X
-2347(Performance)X
-2814(Comparison.)X
-1 f
-10 f
-555 2579(h)N
-579(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)X
-3 f
-555 2855(5.1.2.)N
-775(Multi-User)X
-1174(Tests)X
-1 f
-755 2978(While)N
-975(the)X
-1097(single-user)X
-1473(tests)X
-1639(form)X
-1819(a)X
-1878(basis)X
-2061(for)X
-2178(comparing)X
-2544(LIBTP)X
-2789(to)X
-2874(other)X
-3062(systems,)X
-3358(our)X
-3488(goal)X
-3649(in)X
-3734(multi-user)X
-4086(testing)X
-555 3068(was)N
-714(to)X
-810(analyze)X
-1089(its)X
-1197(scalability.)X
-1579(To)X
-1701(this)X
-1849(end,)X
-2018(we)X
-2145(have)X
-2330(run)X
-2470(the)X
-2601(benchmark)X
-2991(in)X
-3086(three)X
-3280(modes,)X
-3542(the)X
-3673(normal)X
-3933(disk)X
-4099(bound)X
-555 3158(con\256guration)N
-1010(\(\256gure)X
-1252(seven\),)X
-1510(a)X
-1573(CPU)X
-1755(bound)X
-1982(con\256guration)X
-2436(\(\256gure)X
-2677(eight,)X
-2884(READ-ONLY\),)X
-3426(and)X
-3569(lock)X
-3734(contention)X
-4099(bound)X
-555 3248(\(\256gure)N
-796(eight,)X
-1003(NO_FSYNC\).)X
-1510(Since)X
-1715(the)X
-1840(normal)X
-2094(con\256guration)X
-2548(is)X
-2628(completely)X
-3011(disk)X
-3171(bound)X
-3398(\(each)X
-3600(transaction)X
-3978(requires)X
-4263(a)X
-555 3354(random)N
-823(read,)X
-1005(a)X
-1064(random)X
-1332(write,)X
-1540(and)X
-1679(a)X
-1738(sequential)X
-2086(write)X
-7 s
-2251 3322(4)N
-10 s
-3354(\))Y
-2329(we)X
-2446(expect)X
-2679(to)X
-2764(see)X
-2890(little)X
-3059(performance)X
-3489(improvement)X
-3939(as)X
-4028(the)X
-4148(mul-)X
-555 3444(tiprogramming)N
-1064(level)X
-1249(increases.)X
-1613(In)X
-1709(fact,)X
-1879(\256gure)X
-2095(seven)X
-2307(reveals)X
-2564(that)X
-2713(we)X
-2836(are)X
-2964(able)X
-3127(to)X
-3218(overlap)X
-3487(CPU)X
-3670(and)X
-3814(disk)X
-3975(utilization)X
-555 3534(slightly)N
-825(producing)X
-1181(approximately)X
-1674(a)X
-1740(10%)X
-1917(performance)X
-2354(improvement)X
-2811(with)X
-2983(two)X
-3133(processes.)X
-3511(After)X
-3711(that)X
-3861(point,)X
-4075(perfor-)X
-555 3624(mance)N
-785(drops)X
-983(off,)X
-1117(and)X
-1253(at)X
-1331(a)X
-1387(multi-programming)X
-2038(level)X
-2214(of)X
-2301(4,)X
-2381(we)X
-2495(are)X
-2614(performing)X
-2995(worse)X
-3207(than)X
-3365(in)X
-3447(the)X
-3565(single)X
-3776(process)X
-4037(case.)X
-755 3747(Similar)N
-1021(behavior)X
-1333(was)X
-1489(reported)X
-1787(on)X
-1897(the)X
-2025(commercial)X
-2434(relational)X
-2767(database)X
-3074(system)X
-3326(using)X
-3529(the)X
-3657(same)X
-3852(con\256guration.)X
-555 3837(The)N
-707(important)X
-1045(conclusion)X
-1419(to)X
-1508(draw)X
-1696(from)X
-1879(this)X
-2021(is)X
-2101(that)X
-2248(you)X
-2395(cannot)X
-2636(attain)X
-2841(good)X
-3028(multi-user)X
-3384(scaling)X
-3638(on)X
-3745(a)X
-3808(badly)X
-4013(balanced)X
-555 3927(system.)N
-839(If)X
-915(multi-user)X
-1266(performance)X
-1695(on)X
-1797(applications)X
-2205(of)X
-2293(this)X
-2429(sort)X
-2570(is)X
-2644(important,)X
-2996(one)X
-3133(must)X
-3309(have)X
-3482(a)X
-3539(separate)X
-3824(logging)X
-4089(device)X
-555 4017(and)N
-697(horizontally)X
-1110(partition)X
-1407(the)X
-1531(database)X
-1834(to)X
-1921(allow)X
-2124(a)X
-2185(suf\256ciently)X
-2570(high)X
-2737(degree)X
-2977(of)X
-3069(multiprogramming)X
-3698(that)X
-3843(group)X
-4055(commit)X
-555 4107(can)N
-687(amortize)X
-988(the)X
-1106(cost)X
-1255(of)X
-1342(log)X
-1464(\257ushing.)X
-755 4230(By)N
-871(using)X
-1067(a)X
-1126(very)X
-1292(small)X
-1488(database)X
-1788(\(one)X
-1954(that)X
-2097(can)X
-2232(be)X
-2331(entirely)X
-2599(cached)X
-2846(in)X
-2930(main)X
-3112(memory\))X
-3428(and)X
-3566(read-only)X
-3896(transactions,)X
-555 4320(we)N
-670(generated)X
-1004(a)X
-1061(CPU)X
-1236(bound)X
-1456(environment.)X
-1921(By)X
-2034(using)X
-2227(the)X
-2345(same)X
-2530(small)X
-2723(database,)X
-3040(the)X
-3158(complete)X
-3472(TPCB)X
-3691(transaction,)X
-4083(and)X
-4219(no)X
-3 f
-555 4410(fsync)N
-1 f
-733(\(2\))X
-862(on)X
-977(the)X
-1110(log)X
-1247(at)X
-1340(commit,)X
-1639(we)X
-1768(created)X
-2036(a)X
-2107(lock)X
-2280(contention)X
-2652(bound)X
-2886(environment.)X
-3365(The)X
-3524(small)X
-3731(database)X
-4042(used)X
-4223(an)X
-555 4500(account)N
-828(\256le)X
-953(containing)X
-1314(only)X
-1479(1000)X
-1662(records)X
-1922(rather)X
-2133(than)X
-2294(the)X
-2415(full)X
-2549(1,000,000)X
-2891(records)X
-3150(and)X
-3288(ran)X
-3413(enough)X
-3671(transactions)X
-4076(to)X
-4160(read)X
-555 4590(the)N
-677(entire)X
-883(database)X
-1183(into)X
-1330(the)X
-1451(buffer)X
-1671(pool)X
-1836(\(2000\))X
-2073(before)X
-2302(beginning)X
-2645(measurements.)X
-3147(The)X
-3295(read-only)X
-3626(transaction)X
-4001(consisted)X
-555 4680(of)N
-646(three)X
-831(database)X
-1132(reads)X
-1326(\(from)X
-1533(the)X
-1655(1000)X
-1839(record)X
-2069(account)X
-2343(\256le,)X
-2489(the)X
-2611(100)X
-2754(record)X
-2983(teller)X
-3171(\256le,)X
-3316(and)X
-3455(the)X
-3576(10)X
-3679(record)X
-3908(branch)X
-4150(\256le\).)X
-555 4770(Since)N
-759(no)X
-865(data)X
-1025(were)X
-1208(modi\256ed)X
-1518(and)X
-1660(no)X
-1766(history)X
-2014(records)X
-2277(were)X
-2460(written,)X
-2733(no)X
-2839(log)X
-2966(records)X
-3228(were)X
-3410(written.)X
-3702(For)X
-3838(the)X
-3961(contention)X
-555 4860(bound)N
-780(con\256guration,)X
-1252(we)X
-1371(used)X
-1543(the)X
-1666(normal)X
-1918(TPCB)X
-2142(transaction)X
-2519(\(against)X
-2798(the)X
-2920(small)X
-3117(database\))X
-3445(and)X
-3585(disabled)X
-3876(the)X
-3998(log)X
-4124(\257ush.)X
-555 4950(Figure)N
-784(eight)X
-964(shows)X
-1184(both)X
-1346(of)X
-1433(these)X
-1618(results.)X
-755 5073(The)N
-902(read-only)X
-1231(test)X
-1363(indicates)X
-1669(that)X
-1810(we)X
-1925(barely)X
-2147(scale)X
-2329(at)X
-2408(all)X
-2509(in)X
-2592(the)X
-2711(CPU)X
-2887(bound)X
-3108(case.)X
-3308(The)X
-3454(explanation)X
-3849(for)X
-3964(that)X
-4105(is)X
-4179(that)X
-555 5163(even)N
-735(with)X
-905(a)X
-969(single)X
-1188(process,)X
-1477(we)X
-1599(are)X
-1726(able)X
-1888(to)X
-1978(drive)X
-2171(the)X
-2297(CPU)X
-2480(utilization)X
-2832(to)X
-2922(96%.)X
-3137(As)X
-3254(a)X
-3317(result,)X
-3542(that)X
-3689(gives)X
-3885(us)X
-3983(very)X
-4153(little)X
-555 5253(room)N
-753(for)X
-876(improvement,)X
-1352(and)X
-1497(it)X
-1570(takes)X
-1764(a)X
-1829(multiprogramming)X
-2462(level)X
-2647(of)X
-2743(four)X
-2906(to)X
-2997(approach)X
-3321(100%)X
-3537(CPU)X
-3721(saturation.)X
-4106(In)X
-4201(the)X
-555 5343(case)N
-718(where)X
-939(we)X
-1057(do)X
-1161(perform)X
-1444(writes,)X
-1684(we)X
-1802(are)X
-1925(interested)X
-2261(in)X
-2347(detecting)X
-2665(when)X
-2863(lock)X
-3025(contention)X
-3387(becomes)X
-3691(a)X
-3750(dominant)X
-4075(perfor-)X
-555 5433(mance)N
-787(factor.)X
-1037(Contention)X
-1414(will)X
-1560(cause)X
-1761(two)X
-1903(phenomena;)X
-2317(we)X
-2433(will)X
-2579(see)X
-2704(transactions)X
-3109(queueing)X
-3425(behind)X
-3665(frequently)X
-4017(accessed)X
-555 5523(data,)N
-731(and)X
-869(we)X
-985(will)X
-1131(see)X
-1256(transaction)X
-1629(abort)X
-1815(rates)X
-1988(increasing)X
-2339(due)X
-2476(to)X
-2559(deadlock.)X
-2910(Given)X
-3127(that)X
-3268(the)X
-3387(branch)X
-3627(\256le)X
-3750(contains)X
-4038(only)X
-4201(ten)X
-8 s
-10 f
-555 5595(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)N
-5 s
-1 f
-727 5673(4)N
-8 s
-763 5698(Although)N
-1021(the)X
-1115(log)X
-1213(is)X
-1272(written)X
-1469(sequentially,)X
-1810(we)X
-1900(do)X
-1980(not)X
-2078(get)X
-2172(the)X
-2266(bene\256t)X
-2456(of)X
-2525(sequentiality)X
-2868(since)X
-3015(the)X
-3109(log)X
-3207(and)X
-3315(database)X
-3550(reside)X
-3718(on)X
-3798(the)X
-3892(same)X
-4039(disk.)X
-
-13 p
-%%Page: 13 13
-8 s 8 xH 0 xS 1 f
-10 s
-3 f
-1 f
-3187 2051 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3286 2028 MXY
-0 17 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3384 1926 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3483 1910 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3581 1910 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3680 1832 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3778 1909 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3877 1883 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3975 1679 MXY
-0 17 Dl
-0 -8 Dl
-9 0 Dl
--18 0 Dl
-4074 1487 MXY
-0 17 Dl
-0 -8 Dl
-9 0 Dl
--18 0 Dl
-5 Dt
-3187 2060 MXY
-99 -24 Dl
-98 -101 Dl
-99 -16 Dl
-98 0 Dl
-99 -78 Dl
-98 77 Dl
-99 -26 Dl
-98 -204 Dl
-99 -192 Dl
-3 f
-6 s
-4088 1516(SMALL)N
-3 Dt
-3187 2051 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3286 2051 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3384 2041 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3483 1990 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3581 1843 MXY
-0 17 Dl
-0 -8 Dl
-9 0 Dl
--18 0 Dl
-3680 1578 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3778 1496 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3877 1430 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-3975 1269 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-4074 1070 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-1 Dt
-3187 2060 MXY
-99 0 Dl
-98 -10 Dl
-99 -51 Dl
-98 -147 Dl
-99 -265 Dl
-98 -82 Dl
-99 -66 Dl
-98 -161 Dl
-99 -199 Dl
-4088 1099(LARGE)N
-5 Dt
-3089 2060 MXY
-985 0 Dl
-3089 MX
-0 -1174 Dl
-4 Ds
-1 Dt
-3581 2060 MXY
-0 -1174 Dl
-4074 2060 MXY
-0 -1174 Dl
-3089 1825 MXY
-985 0 Dl
-9 s
-2993 1855(25)N
-3089 1591 MXY
-985 0 Dl
-2993 1621(50)N
-3089 1356 MXY
-985 0 Dl
-2993 1386(75)N
-3089 1121 MXY
-985 0 Dl
-2957 1151(100)N
-3089 886 MXY
-985 0 Dl
-2957 916(125)N
-3281 2199(Multiprogramming)N
-3071 2152(0)N
-3569(5)X
-4038(10)X
-2859 787(Aborts)N
-3089(per)X
-3211(500)X
-2901 847(transactions)N
--1 Ds
-3 Dt
-2037 1342 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2125 1358 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2213 1341 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2301 1191 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2388 1124 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--17 0 Dl
-2476 1157 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2564 1157 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2652 1161 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2740 1153 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2828 1150 MXY
-0 18 Dl
-0 -9 Dl
-8 0 Dl
--17 0 Dl
-5 Dt
-2037 1351 MXY
-88 16 Dl
-88 -17 Dl
-88 -150 Dl
-87 -67 Dl
-88 33 Dl
-88 0 Dl
-88 4 Dl
-88 -8 Dl
-88 -3 Dl
-6 s
-2685 1234(READ-ONLY)N
-3 Dt
-2037 1464 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2125 1640 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2213 1854 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2301 1872 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2388 1871 MXY
-0 17 Dl
-0 -9 Dl
-9 0 Dl
--17 0 Dl
-2476 1933 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2564 1914 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2652 1903 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2740 1980 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-2828 2004 MXY
-0 18 Dl
-0 -9 Dl
-8 0 Dl
--17 0 Dl
-1 Dt
-2037 1473 MXY
-88 176 Dl
-88 214 Dl
-88 18 Dl
-87 -2 Dl
-88 63 Dl
-88 -19 Dl
-88 -11 Dl
-88 77 Dl
-88 24 Dl
-2759 1997(NO-FSYNC)N
-5 Dt
-1949 2060 MXY
-879 0 Dl
-1949 MX
-0 -1174 Dl
-4 Ds
-1 Dt
-2388 2060 MXY
-0 -1174 Dl
-2828 2060 MXY
-0 -1174 Dl
-1949 1825 MXY
-879 0 Dl
-9 s
-1842 1855(40)N
-1949 1591 MXY
-879 0 Dl
-1842 1621(80)N
-1949 1356 MXY
-879 0 Dl
-1806 1386(120)N
-1949 1121 MXY
-879 0 Dl
-1806 1151(160)N
-1949 886 MXY
-879 0 Dl
-1806 916(200)N
-2088 2199(Multiprogramming)N
-1844 863(in)N
-1922(TPS)X
-1761 792(Throughput)N
-1931 2121(0)N
-2370 2133(5)N
-2792(10)X
-6 s
-1679 1833(LIBTP)N
--1 Ds
-3 Dt
-837 1019 MXY
-0 17 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-929 878 MXY
-0 17 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-1021 939 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-1113 1043 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-1205 1314 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-1297 1567 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-1389 1665 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-1481 1699 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-1573 1828 MXY
-0 18 Dl
-0 -9 Dl
-9 0 Dl
--18 0 Dl
-1665 1804 MXY
-0 18 Dl
-0 -9 Dl
-8 0 Dl
--17 0 Dl
-5 Dt
-837 1027 MXY
-92 -141 Dl
-92 62 Dl
-92 104 Dl
-92 271 Dl
-92 253 Dl
-92 98 Dl
-92 34 Dl
-92 129 Dl
-92 -24 Dl
-745 2060 MXY
-920 0 Dl
-745 MX
-0 -1174 Dl
-4 Ds
-1 Dt
-1205 2060 MXY
-0 -1174 Dl
-1665 2060 MXY
-0 -1174 Dl
-745 1766 MXY
-920 0 Dl
-9 s
-673 1796(3)N
-745 1473 MXY
-920 0 Dl
-673 1503(5)N
-745 1180 MXY
-920 0 Dl
-673 1210(8)N
-745 886 MXY
-920 0 Dl
-637 916(10)N
-905 2199(Multiprogramming)N
-622 851(in)N
-700(TPS)X
-575 792(Throughput)N
-733 2152(0)N
-1196(5)X
-1629(10)X
-3 Dt
--1 Ds
-8 s
-655 2441(Figure)N
-872(7:)X
-960(Multi-user)X
-1286(Performance.)X
-1 f
-655 2531(Since)N
-825(the)X
-931(con\256guration)X
-1300(is)X
-1371(completely)X
-655 2621(disk)N
-790(bound,)X
-994(we)X
-1096(see)X
-1204(only)X
-1345(a)X
-1400(small)X
-1566(im-)X
-655 2711(provement)N
-964(by)X
-1064(adding)X
-1274(a)X
-1337(second)X
-1549(pro-)X
-655 2801(cess.)N
-849(Adding)X
-1081(any)X
-1213(more)X
-1383(concurrent)X
-655 2891(processes)N
-935(causes)X
-1137(performance)X
-1493(degra-)X
-655 2981(dation.)N
-3 f
-1927 2441(Figure)N
-2149(8:)X
-2243(Multi-user)X
-2574(Performance)X
-1927 2531(on)N
-2021(a)X
-2079(small)X
-2251(database.)X
-1 f
-2551(With)X
-2704(one)X
-2821(pro-)X
-1927 2621(cess,)N
-2075(we)X
-2174(are)X
-2276(driving)X
-2486(the)X
-2589(CPU)X
-2739(at)X
-2810(96%)X
-1927 2711(utilization)N
-2215(leaving)X
-2430(little)X
-2575(room)X
-2737(for)X
-2838(im-)X
-1927 2801(provement)N
-2238(as)X
-2328(the)X
-2443(multiprogramming)X
-1927 2891(level)N
-2091(increases.)X
-2396(In)X
-2489(the)X
-2607(NO-FSYNC)X
-1927 2981(case,)N
-2076(lock)X
-2209(contention)X
-2502(degrades)X
-2751(perfor-)X
-1927 3071(mance)N
-2117(as)X
-2194(soon)X
-2339(as)X
-2416(a)X
-2468(second)X
-2669(process)X
-2884(is)X
-1927 3161(added.)N
-3 f
-3199 2441(Figure)N
-3405(9:)X
-3482(Abort)X
-3669(rates)X
-3827(on)X
-3919(the)X
-4028(TPCB)X
-3199 2531(Benchmark.)N
-1 f
-3589(The)X
-3726(abort)X
-3895(rate)X
-4028(climbs)X
-3199 2621(more)N
-3366(quickly)X
-3594(for)X
-3704(the)X
-3818(large)X
-3980(database)X
-3199 2711(test)N
-3324(since)X
-3491(processes)X
-3771(are)X
-3884(descheduled)X
-3199 2801(more)N
-3409(frequently,)X
-3766(allowing)X
-4068(more)X
-3199 2891(processes)N
-3459(to)X
-3525(vie)X
-3619(for)X
-3709(the)X
-3803(same)X
-3950(locks.)X
-10 s
-10 f
-555 3284(h)N
-579(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)X
-1 f
-555 3560(records,)N
-835(we)X
-952(expect)X
-1185(contention)X
-1546(to)X
-1631(become)X
-1904(a)X
-1963(factor)X
-2174(quickly)X
-2437(and)X
-2576(the)X
-2697(NO-FSYNC)X
-3120(line)X
-3263(in)X
-3348(\256gure)X
-3557(eight)X
-3739(demonstrates)X
-4184(this)X
-555 3650(dramatically.)N
-1022(Each)X
-1209(additional)X
-1555(process)X
-1822(causes)X
-2058(both)X
-2226(more)X
-2417(waiting)X
-2682(and)X
-2823(more)X
-3013(deadlocking.)X
-3470(Figure)X
-3704(nine)X
-3867(shows)X
-4092(that)X
-4237(in)X
-555 3740(the)N
-681(small)X
-882(database)X
-1187(case)X
-1353(\(SMALL\),)X
-1725(waiting)X
-1992(is)X
-2072(the)X
-2197(dominant)X
-2526(cause)X
-2732(of)X
-2826(declining)X
-3151(performance)X
-3585(\(the)X
-3737(number)X
-4009(of)X
-4103(aborts)X
-555 3830(increases)N
-878(less)X
-1026(steeply)X
-1281(than)X
-1447(the)X
-1573(performance)X
-2008(drops)X
-2214(off)X
-2336(in)X
-2426(\256gure)X
-2641(eight\),)X
-2876(while)X
-3082(in)X
-3172(the)X
-3298(large)X
-3487(database)X
-3792(case)X
-3958(\(LARGE\),)X
-555 3920(deadlocking)N
-967(contributes)X
-1343(more)X
-1528(to)X
-1610(the)X
-1728(declining)X
-2046(performance.)X
-755 4043(Deadlocks)N
-1116(are)X
-1237(more)X
-1424(likely)X
-1628(to)X
-1712(occur)X
-1913(in)X
-1997(the)X
-2116(LARGE)X
-2404(test)X
-2536(than)X
-2695(in)X
-2778(the)X
-2897(SMALL)X
-3189(test)X
-3321(because)X
-3597(there)X
-3779(are)X
-3899(more)X
-4085(oppor-)X
-555 4133(tunities)N
-814(to)X
-900(wait.)X
-1082(In)X
-1173(the)X
-1295(SMALL)X
-1590(case,)X
-1773(processes)X
-2105(never)X
-2307(do)X
-2410(I/O)X
-2540(and)X
-2679(are)X
-2801(less)X
-2944(likely)X
-3149(to)X
-3234(be)X
-3333(descheduled)X
-3753(during)X
-3985(a)X
-4044(transac-)X
-555 4223(tion.)N
-740(In)X
-828(the)X
-947(LARGE)X
-1235(case,)X
-1415(processes)X
-1744(will)X
-1889(frequently)X
-2240(be)X
-2337(descheduled)X
-2755(since)X
-2941(they)X
-3100(have)X
-3273(to)X
-3356(perform)X
-3636(I/O.)X
-3804(This)X
-3967(provides)X
-4263(a)X
-555 4313(window)N
-837(where)X
-1058(a)X
-1118(second)X
-1365(process)X
-1630(can)X
-1766(request)X
-2022(locks)X
-2215(on)X
-2318(already)X
-2578(locked)X
-2815(pages,)X
-3041(thus)X
-3197(increasing)X
-3550(the)X
-3671(likelihood)X
-4018(of)X
-4108(build-)X
-555 4403(ing)N
-677(up)X
-777(long)X
-939(chains)X
-1164(of)X
-1251(waiting)X
-1511(processes.)X
-1879(Eventually,)X
-2266(this)X
-2401(leads)X
-2586(to)X
-2668(deadlock.)X
-3 f
-555 4589(5.2.)N
-715(The)X
-868(OO1)X
-1052(Benchmark)X
-1 f
-755 4712(The)N
-903(TPCB)X
-1125(benchmark)X
-1505(described)X
-1836(in)X
-1921(the)X
-2042(previous)X
-2341(section)X
-2591(measures)X
-2913(performance)X
-3343(under)X
-3549(a)X
-3608(conventional)X
-4044(transac-)X
-555 4802(tion)N
-706(processing)X
-1076(workload.)X
-1446(Other)X
-1656(application)X
-2039(domains,)X
-2357(such)X
-2531(as)X
-2625(computer-aided)X
-3156(design,)X
-3412(have)X
-3591(substantially)X
-4022(different)X
-555 4892(access)N
-786(patterns.)X
-1105(In)X
-1197(order)X
-1392(to)X
-1479(measure)X
-1772(the)X
-1895(performance)X
-2327(of)X
-2418(LIBTP)X
-2664(under)X
-2871(workloads)X
-3229(of)X
-3320(this)X
-3459(type,)X
-3641(we)X
-3759(implemented)X
-4201(the)X
-555 4982(OO1)N
-731(benchmark)X
-1108(described)X
-1436(in)X
-1518([CATT91].)X
-755 5105(The)N
-908(database)X
-1213(models)X
-1472(a)X
-1535(set)X
-1651(of)X
-1745(electronics)X
-2120(components)X
-2534(with)X
-2703(connections)X
-3113(among)X
-3358(them.)X
-3585(One)X
-3746(table)X
-3929(stores)X
-4143(parts)X
-555 5195(and)N
-696(another)X
-962(stores)X
-1174(connections.)X
-1622(There)X
-1835(are)X
-1959(three)X
-2145(connections)X
-2552(originating)X
-2927(at)X
-3009(any)X
-3149(given)X
-3351(part.)X
-3540(Ninety)X
-3782(percent)X
-4043(of)X
-4134(these)X
-555 5285(connections)N
-960(are)X
-1081(to)X
-1165(nearby)X
-1406(parts)X
-1584(\(those)X
-1802(with)X
-1966(nearby)X
-2 f
-2207(ids)X
-1 f
-2300(\))X
-2348(to)X
-2431(model)X
-2652(the)X
-2771(spatial)X
-3001(locality)X
-3262(often)X
-3448(exhibited)X
-3767(in)X
-3850(CAD)X
-4040(applica-)X
-555 5375(tions.)N
-779(Ten)X
-933(percent)X
-1198(of)X
-1293(the)X
-1419(connections)X
-1830(are)X
-1957(randomly)X
-2292(distributed)X
-2662(among)X
-2908(all)X
-3016(other)X
-3209(parts)X
-3393(in)X
-3483(the)X
-3609(database.)X
-3954(Every)X
-4174(part)X
-555 5465(appears)N
-829(exactly)X
-1089(three)X
-1278(times)X
-1479(in)X
-1569(the)X
-2 f
-1695(from)X
-1 f
-1874(\256eld)X
-2043(of)X
-2137(a)X
-2200(connection)X
-2579(record,)X
-2832(and)X
-2975(zero)X
-3141(or)X
-3235(more)X
-3427(times)X
-3627(in)X
-3716(the)X
-2 f
-3841(to)X
-1 f
-3930(\256eld.)X
-4139(Parts)X
-555 5555(have)N
-2 f
-727(x)X
-1 f
-783(and)X
-2 f
-919(y)X
-1 f
-975(locations)X
-1284(set)X
-1393(randomly)X
-1720(in)X
-1802(an)X
-1898(appropriate)X
-2284(range.)X
-
-14 p
-%%Page: 14 14
-10 s 10 xH 0 xS 1 f
-3 f
-1 f
-755 630(The)N
-900(intent)X
-1102(of)X
-1189(OO1)X
-1365(is)X
-1438(to)X
-1520(measure)X
-1808(the)X
-1926(overall)X
-2169(cost)X
-2318(of)X
-2405(a)X
-2461(query)X
-2664(mix)X
-2808(characteristic)X
-3257(of)X
-3344(engineering)X
-3743(database)X
-4040(applica-)X
-555 720(tions.)N
-770(There)X
-978(are)X
-1097(three)X
-1278(tests:)X
-10 f
-635 843(g)N
-2 f
-755(Lookup)X
-1 f
-1022(generates)X
-1353(1,000)X
-1560(random)X
-1832(part)X
-2 f
-1984(ids)X
-1 f
-2077(,)X
-2124(fetches)X
-2378(the)X
-2502(corresponding)X
-2987(parts)X
-3169(from)X
-3351(the)X
-3475(database,)X
-3798(and)X
-3940(calls)X
-4113(a)X
-4175(null)X
-755 933(procedure)N
-1097(in)X
-1179(the)X
-1297(host)X
-1450(programming)X
-1906(language)X
-2216(with)X
-2378(the)X
-2496(parts')X
-2 f
-2699(x)X
-1 f
-2755(and)X
-2 f
-2891(y)X
-1 f
-2947(positions.)X
-10 f
-635 1056(g)N
-2 f
-755(Traverse)X
-1 f
-1067(retrieves)X
-1371(a)X
-1434(random)X
-1706(part)X
-1858(from)X
-2041(the)X
-2166(database)X
-2470(and)X
-2613(follows)X
-2880(connections)X
-3290(from)X
-3473(it)X
-3544(to)X
-3632(other)X
-3823(parts.)X
-4045(Each)X
-4232(of)X
-755 1146(those)N
-947(parts)X
-1126(is)X
-1202(retrieved,)X
-1531(and)X
-1670(all)X
-1773(connections)X
-2179(from)X
-2358(it)X
-2424(followed.)X
-2771(This)X
-2935(procedure)X
-3279(is)X
-3354(repeated)X
-3649(depth-\256rst)X
-4000(for)X
-4116(seven)X
-755 1236(hops)N
-930(from)X
-1110(the)X
-1232(original)X
-1505(part,)X
-1674(for)X
-1792(a)X
-1852(total)X
-2018(of)X
-2109(3280)X
-2293(parts.)X
-2513(Backward)X
-2862(traversal)X
-3162(also)X
-3314(exists,)X
-3539(and)X
-3678(follows)X
-3941(all)X
-4044(connec-)X
-755 1326(tions)N
-930(into)X
-1074(a)X
-1130(given)X
-1328(part)X
-1473(to)X
-1555(their)X
-1722(origin.)X
-10 f
-635 1449(g)N
-2 f
-755(Insert)X
-1 f
-962(adds)X
-1129(100)X
-1269(new)X
-1423(parts)X
-1599(and)X
-1735(their)X
-1902(connections.)X
-755 1572(The)N
-913(benchmark)X
-1303(is)X
-1389(single-user,)X
-1794(but)X
-1929(multi-user)X
-2291(access)X
-2530(controls)X
-2821(\(locking)X
-3120(and)X
-3268(transaction)X
-3652(protection\))X
-4036(must)X
-4223(be)X
-555 1662(enforced.)N
-898(It)X
-968(is)X
-1042(designed)X
-1348(to)X
-1431(be)X
-1528(run)X
-1656(on)X
-1757(a)X
-1814(database)X
-2112(with)X
-2275(20,000)X
-2516(parts,)X
-2713(and)X
-2850(on)X
-2951(one)X
-3087(with)X
-3249(200,000)X
-3529(parts.)X
-3745(Because)X
-4033(we)X
-4147(have)X
-555 1752(insuf\256cient)N
-935(disk)X
-1088(space)X
-1287(for)X
-1401(the)X
-1519(larger)X
-1727(database,)X
-2044(we)X
-2158(report)X
-2370(results)X
-2599(only)X
-2761(for)X
-2875(the)X
-2993(20,000)X
-3233(part)X
-3378(database.)X
-3 f
-555 1938(5.2.1.)N
-775(Implementation)X
-1 f
-755 2061(The)N
-920(LIBTP)X
-1182(implementation)X
-1724(of)X
-1831(OO1)X
-2027(uses)X
-2205(the)X
-2342(TCL)X
-2532([OUST90])X
-2914(interface)X
-3235(described)X
-3582(earlier.)X
-3867(The)X
-4031(backend)X
-555 2151(accepts)N
-813(commands)X
-1181(over)X
-1345(an)X
-1442(IP)X
-1534(socket)X
-1760(and)X
-1897(performs)X
-2208(the)X
-2327(requested)X
-2656(database)X
-2954(actions.)X
-3242(The)X
-3387(frontend)X
-3679(opens)X
-3886(and)X
-4022(executes)X
-555 2241(a)N
-618(TCL)X
-796(script.)X
-1041(This)X
-1210(script)X
-1415(contains)X
-1709(database)X
-2013(accesses)X
-2313(interleaved)X
-2697(with)X
-2866(ordinary)X
-3165(program)X
-3463(control)X
-3716(statements.)X
-4120(Data-)X
-555 2331(base)N
-718(commands)X
-1085(are)X
-1204(submitted)X
-1539(to)X
-1621(the)X
-1739(backend)X
-2027(and)X
-2163(results)X
-2392(are)X
-2511(bound)X
-2731(to)X
-2813(program)X
-3105(variables.)X
-755 2454(The)N
-903(parts)X
-1082(table)X
-1261(was)X
-1409(stored)X
-1628(as)X
-1718(a)X
-1776(B-tree)X
-1999(indexed)X
-2275(by)X
-2 f
-2377(id)X
-1 f
-2439(.)X
-2501(The)X
-2648(connection)X
-3022(table)X
-3200(was)X
-3347(stored)X
-3565(as)X
-3654(a)X
-3712(set)X
-3823(of)X
-3912(\256xed-length)X
-555 2544(records)N
-824(using)X
-1029(the)X
-1159(4.4BSD)X
-1446(recno)X
-1657(access)X
-1895(method.)X
-2207(In)X
-2306(addition,)X
-2620(two)X
-2771(B-tree)X
-3003(indices)X
-3261(were)X
-3449(maintained)X
-3836(on)X
-3947(connection)X
-555 2634(table)N
-732(entries.)X
-1007(One)X
-1162(index)X
-1360(mapped)X
-1634(the)X
-2 f
-1752(from)X
-1 f
-1923(\256eld)X
-2085(to)X
-2167(a)X
-2223(connection)X
-2595(record)X
-2821(number,)X
-3106(and)X
-3242(the)X
-3360(other)X
-3545(mapped)X
-3819(the)X
-2 f
-3937(to)X
-1 f
-4019(\256eld)X
-4181(to)X
-4263(a)X
-555 2724(connection)N
-932(record)X
-1163(number.)X
-1473(These)X
-1690(indices)X
-1941(support)X
-2205(fast)X
-2345(lookups)X
-2622(on)X
-2726(connections)X
-3133(in)X
-3219(both)X
-3385(directions.)X
-3765(For)X
-3900(the)X
-4022(traversal)X
-555 2814(tests,)N
-743(the)X
-867(frontend)X
-1165(does)X
-1338(an)X
-1439(index)X
-1642(lookup)X
-1889(to)X
-1976(discover)X
-2273(the)X
-2396(connected)X
-2747(part's)X
-2 f
-2955(id)X
-1 f
-3017(,)X
-3062(and)X
-3203(then)X
-3366(does)X
-3538(another)X
-3804(lookup)X
-4051(to)X
-4138(fetch)X
-555 2904(the)N
-673(part)X
-818(itself.)X
-3 f
-555 3090(5.2.2.)N
-775(Performance)X
-1242(Measurements)X
-1766(for)X
-1889(OO1)X
-1 f
-755 3213(We)N
-888(compare)X
-1186(LIBTP's)X
-1487(OO1)X
-1664(performance)X
-2092(to)X
-2174(that)X
-2314(reported)X
-2602(in)X
-2684([CATT91].)X
-3087(Those)X
-3303(results)X
-3532(were)X
-3709(collected)X
-4019(on)X
-4119(a)X
-4175(Sun)X
-555 3303(3/280)N
-759(\(25)X
-888(MHz)X
-1075(MC68020\))X
-1448(with)X
-1612(16)X
-1714(MBytes)X
-1989(of)X
-2078(memory)X
-2367(and)X
-2505(two)X
-2647(Hitachi)X
-2904(892MByte)X
-3267(disks)X
-3452(\(15)X
-3580(ms)X
-3694(average)X
-3966(seek)X
-4130(time\))X
-555 3393(behind)N
-793(an)X
-889(SMD-4)X
-1149(controller.)X
-1521(Frontends)X
-1861(ran)X
-1984(on)X
-2084(an)X
-2180(8MByte)X
-2462(Sun)X
-2606(3/260.)X
-755 3516(In)N
-844(order)X
-1036(to)X
-1120(measure)X
-1410(performance)X
-1839(on)X
-1941(a)X
-1999(machine)X
-2293(of)X
-2382(roughly)X
-2653(equivalent)X
-3009(processor)X
-3339(power,)X
-3582(we)X
-3698(ran)X
-3822(one)X
-3959(set)X
-4069(of)X
-4157(tests)X
-555 3606(on)N
-666(a)X
-733(standalone)X
-1107(MC68030-based)X
-1671(HP300)X
-1923(\(33MHz)X
-2225(MC68030\).)X
-2646(The)X
-2801(database)X
-3108(was)X
-3263(stored)X
-3489(on)X
-3599(a)X
-3665(300MByte)X
-4037(HP7959)X
-555 3696(SCSI)N
-744(disk)X
-898(\(17)X
-1026(ms)X
-1139(average)X
-1410(seek)X
-1573(time\).)X
-1802(Since)X
-2000(this)X
-2135(machine)X
-2427(is)X
-2500(not)X
-2622(connected)X
-2968(to)X
-3050(a)X
-3106(network,)X
-3409(we)X
-3523(ran)X
-3646(local)X
-3822(tests)X
-3984(where)X
-4201(the)X
-555 3786(frontend)N
-855(and)X
-999(backend)X
-1295(run)X
-1430(on)X
-1538(the)X
-1664(same)X
-1856(machine.)X
-2195(We)X
-2334(compare)X
-2638(these)X
-2830(measurements)X
-3316(with)X
-3485(Cattell's)X
-3783(local)X
-3966(Sun)X
-4117(3/280)X
-555 3876(numbers.)N
-755 3999(Because)N
-1051(the)X
-1177(benchmark)X
-1562(requires)X
-1849(remote)X
-2100(access,)X
-2354(we)X
-2476(ran)X
-2607(another)X
-2876(set)X
-2993(of)X
-3088(tests)X
-3258(on)X
-3365(a)X
-3428(DECstation)X
-3828(5000/200)X
-4157(with)X
-555 4089(32M)N
-732(of)X
-825(memory)X
-1118(running)X
-1393(Ultrix)X
-1610(V4.0)X
-1794(and)X
-1936(a)X
-1998(DEC)X
-2184(1GByte)X
-2459(RZ57)X
-2666(SCSI)X
-2859(disk.)X
-3057(We)X
-3194(compare)X
-3496(the)X
-3619(local)X
-3800(performance)X
-4232(of)X
-555 4179(OO1)N
-734(on)X
-837(the)X
-958(DECstation)X
-1354(to)X
-1439(its)X
-1536(remote)X
-1781(performance.)X
-2250(For)X
-2383(the)X
-2503(remote)X
-2748(case,)X
-2929(we)X
-3045(ran)X
-3170(the)X
-3290(frontend)X
-3584(on)X
-3686(a)X
-3744(DECstation)X
-4139(3100)X
-555 4269(with)N
-717(16)X
-817(MBytes)X
-1090(of)X
-1177(main)X
-1357(memory.)X
-755 4392(The)N
-900(databases)X
-1228(tested)X
-1435(in)X
-1517([CATT91])X
-1880(are)X
-10 f
-635 4515(g)N
-1 f
-755(INDEX,)X
-1045(a)X
-1101(highly-optimized)X
-1672(access)X
-1898(method)X
-2158(package)X
-2442(developed)X
-2792(at)X
-2870(Sun)X
-3014(Microsystems.)X
-10 f
-635 4638(g)N
-1 f
-755(OODBMS,)X
-1137(a)X
-1193(beta)X
-1347(release)X
-1591(of)X
-1678(a)X
-1734(commercial)X
-2133(object-oriented)X
-2639(database)X
-2936(management)X
-3366(system.)X
-10 f
-635 4761(g)N
-1 f
-755(RDBMS,)X
-1076(a)X
-1133(UNIX-based)X
-1565(commercial)X
-1965(relational)X
-2289(data)X
-2444(manager)X
-2742(at)X
-2821(production)X
-3189(release.)X
-3474(The)X
-3620(OO1)X
-3797(implementation)X
-755 4851(used)N
-922(embedded)X
-1272(SQL)X
-1443(in)X
-1525(C.)X
-1638(Stored)X
-1867(procedures)X
-2240(were)X
-2417(de\256ned)X
-2673(to)X
-2755(reduce)X
-2990(client-server)X
-3412(traf\256c.)X
-755 4974(Table)N
-974(two)X
-1130(shows)X
-1366(the)X
-1500(measurements)X
-1995(from)X
-2187([CATT91])X
-2566(and)X
-2718(LIBTP)X
-2976(for)X
-3106(a)X
-3178(local)X
-3370(test)X
-3517(on)X
-3632(the)X
-3765(MC680x0-based)X
-555 5064(hardware.)N
-915(All)X
-1037(caches)X
-1272(are)X
-1391(cleared)X
-1644(before)X
-1870(each)X
-2038(test.)X
-2209(All)X
-2331(times)X
-2524(are)X
-2643(in)X
-2725(seconds.)X
-755 5187(Table)N
-960(two)X
-1102(shows)X
-1324(that)X
-1466(LIBTP)X
-1710(outperforms)X
-2123(the)X
-2242(commercial)X
-2642(relational)X
-2966(system,)X
-3229(but)X
-3352(is)X
-3426(slower)X
-3661(than)X
-3820(OODBMS)X
-4183(and)X
-555 5277(INDEX.)N
-872(Since)X
-1077(the)X
-1202(caches)X
-1444(were)X
-1628(cleared)X
-1888(at)X
-1973(the)X
-2098(start)X
-2263(of)X
-2356(each)X
-2530(test,)X
-2687(disk)X
-2846(throughput)X
-3223(is)X
-3302(critical)X
-3551(in)X
-3639(this)X
-3780(test.)X
-3957(The)X
-4108(single)X
-555 5367(SCSI)N
-749(HP)X
-877(drive)X
-1068(used)X
-1241(by)X
-1347(LIBTP)X
-1595(is)X
-1674(approximately)X
-2163(13%)X
-2336(slower)X
-2576(than)X
-2739(the)X
-2862(disks)X
-3051(used)X
-3223(in)X
-3310([CATT91])X
-3678(which)X
-3899(accounts)X
-4205(for)X
-555 5457(part)N
-700(of)X
-787(the)X
-905(difference.)X
-755 5580(OODBMS)N
-1118(and)X
-1255(INDEX)X
-1525(outperform)X
-1906(LIBTP)X
-2148(most)X
-2323(dramatically)X
-2744(on)X
-2844(traversal.)X
-3181(This)X
-3343(is)X
-3416(because)X
-3691(we)X
-3805(use)X
-3932(index)X
-4130(look-)X
-555 5670(ups)N
-689(to)X
-774(\256nd)X
-921(connections,)X
-1347(whereas)X
-1634(the)X
-1755(other)X
-1942(two)X
-2084(systems)X
-2359(use)X
-2488(a)X
-2546(link)X
-2692(access)X
-2920(method.)X
-3222(The)X
-3369(index)X
-3569(requires)X
-3850(us)X
-3943(to)X
-4027(examine)X
-
-15 p
-%%Page: 15 15
-10 s 10 xH 0 xS 1 f
-3 f
-1 f
-10 f
-555 679(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)N
-2 f
-606 769(Measure)N
-1 f
-1019(INDEX)X
-1389(OODBMS)X
-1851(RDBMS)X
-2250(LIBTP)X
-10 f
-555 771(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)N
-555 787(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)N
-1 f
-595 869(Lookup)N
-1114(5.4)X
-1490(12.9)X
-1950(27)X
-2291(27.2)X
-595 959(Traversal)N
-1074(13)X
-1530(9.8)X
-1950(90)X
-2291(47.3)X
-595 1049(Insert)N
-1114(7.4)X
-1530(1.5)X
-1950(22)X
-2331(9.7)X
-10 f
-555 1059(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)N
-555(c)X
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-959 1059(c)N
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-1329 1059(c)N
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-1791 1059(c)N
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-2190 1059(c)N
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-2512 1059(c)N
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-2618 679(i)N
-2629(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2 f
-2829 769(Measure)N
-3401(Cache)X
-3726(Local)X
-4028(Remote)X
-1 f
-10 f
-2618 771(i)N
-2629(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2618 787(i)N
-2629(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-2658 869(Lookup)N
-3401(cold)X
-3747(15.7)X
-4078(20.6)X
-3401 959(warm)N
-3787(7.8)X
-4078(12.4)X
-10 f
-2618 969(i)N
-2629(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-2658 1059(Forward)N
-2950(traversal)X
-3401(cold)X
-3747(28.4)X
-4078(52.6)X
-3401 1149(warm)N
-3747(23.5)X
-4078(47.4)X
-10 f
-2618 1159(i)N
-2629(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-2658 1249(Backward)N
-3004(traversal)X
-3401(cold)X
-3747(24.2)X
-4078(47.4)X
-3401 1339(warm)N
-3747(24.3)X
-4078(47.6)X
-10 f
-2618 1349(i)N
-2629(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-1 f
-2658 1439(Insert)N
-3401(cold)X
-3787(7.5)X
-4078(10.3)X
-3401 1529(warm)N
-3787(6.7)X
-4078(10.9)X
-10 f
-2618 1539(i)N
-2629(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii)X
-2618(c)X
-1479(c)Y
-1399(c)Y
-1319(c)Y
-1239(c)Y
-1159(c)Y
-1079(c)Y
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-3341 1539(c)N
-1479(c)Y
-1399(c)Y
-1319(c)Y
-1239(c)Y
-1159(c)Y
-1079(c)Y
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-3666 1539(c)N
-1479(c)Y
-1399(c)Y
-1319(c)Y
-1239(c)Y
-1159(c)Y
-1079(c)Y
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-3968 1539(c)N
-1479(c)Y
-1399(c)Y
-1319(c)Y
-1239(c)Y
-1159(c)Y
-1079(c)Y
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-4309 1539(c)N
-1479(c)Y
-1399(c)Y
-1319(c)Y
-1239(c)Y
-1159(c)Y
-1079(c)Y
-999(c)Y
-919(c)Y
-839(c)Y
-759(c)Y
-3 f
-587 1785(Table)N
-823(2:)X
-931(Local)X
-1163(MC680x0)X
-1538(Performance)X
-2026(of)X
-2133(Several)X
-587 1875(Systems)N
-883(on)X
-987(OO1.)X
-2667 1785(Table)N
-2909(3:)X
-3023(Local)X
-3260(vs.)X
-3397(Remote)X
-3707(Performance)X
-4200(of)X
-2667 1875(LIBTP)N
-2926(on)X
-3030(OO1.)X
-1 f
-10 f
-555 1998(h)N
-579(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)X
-1 f
-555 2274(two)N
-696(disk)X
-850(pages,)X
-1074(but)X
-1197(the)X
-1316(links)X
-1492(require)X
-1741(only)X
-1904(one,)X
-2061(regardless)X
-2408(of)X
-2496(database)X
-2794(size.)X
-2980(Cattell)X
-3214(reports)X
-3458(that)X
-3599(lookups)X
-3873(using)X
-4067(B-trees)X
-555 2364(instead)N
-808(of)X
-901(links)X
-1082(makes)X
-1313(traversal)X
-1616(take)X
-1776(twice)X
-1976(as)X
-2069(long)X
-2237(in)X
-2325(INDEX.)X
-2641(Adding)X
-2907(a)X
-2969(link)X
-3119(access)X
-3351(method)X
-3617(to)X
-3 f
-3704(db)X
-1 f
-3792(\(3\))X
-3911(or)X
-4003(using)X
-4201(the)X
-555 2454(existing)N
-828(hash)X
-995(method)X
-1255(would)X
-1475(apparently)X
-1834(be)X
-1930(a)X
-1986(good)X
-2166(idea.)X
-755 2577(Both)N
-936(OODBMS)X
-1304(and)X
-1446(INDEX)X
-1722(issue)X
-1908 0.1944(coarser-granularity)AX
-2545(locks)X
-2739(than)X
-2902(LIBTP.)X
-3189(This)X
-3356(limits)X
-3562(concurrency)X
-3985(for)X
-4104(multi-)X
-555 2667(user)N
-711(applications,)X
-1140(but)X
-1264(helps)X
-1455(single-user)X
-1829(applications.)X
-2278(In)X
-2367(addition,)X
-2671(the)X
-2791(fact)X
-2934(that)X
-3076(LIBTP)X
-3319(releases)X
-3595(B-tree)X
-3817(locks)X
-4007(early)X
-4189(is)X
-4263(a)X
-555 2757(drawback)N
-896(in)X
-986(OO1.)X
-1210(Since)X
-1416(there)X
-1605(is)X
-1686(no)X
-1793(concurrency)X
-2218(in)X
-2307(the)X
-2432(benchmark,)X
-2836(high-concurrency)X
-3430(strategies)X
-3760(only)X
-3929(show)X
-4125(up)X
-4232(as)X
-555 2847(increased)N
-882(locking)X
-1145(overhead.)X
-1503(Finally,)X
-1772(the)X
-1892(architecture)X
-2294(of)X
-2383(the)X
-2503(LIBTP)X
-2747(implementation)X
-3271(was)X
-3418(substantially)X
-3844(different)X
-4143(from)X
-555 2937(that)N
-702(of)X
-796(either)X
-1006(OODBMS)X
-1375(or)X
-1469(INDEX.)X
-1786(Both)X
-1968(of)X
-2062(those)X
-2258(systems)X
-2538(do)X
-2645(the)X
-2770(searches)X
-3070(in)X
-3159(the)X
-3284(user's)X
-3503(address)X
-3771(space,)X
-3997(and)X
-4139(issue)X
-555 3027(requests)N
-844(for)X
-964(pages)X
-1173(to)X
-1260(the)X
-1383(server)X
-1605(process.)X
-1911(Pages)X
-2123(are)X
-2247(cached)X
-2496(in)X
-2583(the)X
-2706(client,)X
-2929(and)X
-3070(many)X
-3273(queries)X
-3530(can)X
-3667(be)X
-3768(satis\256ed)X
-4055(without)X
-555 3117(contacting)N
-910(the)X
-1029(server)X
-1247(at)X
-1326(all.)X
-1467(LIBTP)X
-1710(submits)X
-1979(all)X
-2080(the)X
-2199(queries)X
-2452(to)X
-2535(the)X
-2653(server)X
-2870(process,)X
-3151(and)X
-3287(receives)X
-3571(database)X
-3868(records)X
-4125(back;)X
-555 3207(it)N
-619(does)X
-786(no)X
-886(client)X
-1084(caching.)X
-755 3330(The)N
-911(RDBMS)X
-1221(architecture)X
-1632(is)X
-1716(much)X
-1925(closer)X
-2148(to)X
-2241(that)X
-2392(of)X
-2490(LIBTP.)X
-2783(A)X
-2872(server)X
-3100(process)X
-3372(receives)X
-3667(queries)X
-3930(and)X
-4076(returns)X
-555 3420(results)N
-786(to)X
-870(a)X
-928(client.)X
-1168(The)X
-1315(timing)X
-1545(results)X
-1776(in)X
-1860(table)X
-2038(two)X
-2180(clearly)X
-2421(show)X
-2612(that)X
-2754(the)X
-2874(conventional)X
-3309(database)X
-3607(client/server)X
-4025(model)X
-4246(is)X
-555 3510(expensive.)N
-941(LIBTP)X
-1188(outperforms)X
-1605(the)X
-1728(RDBMS)X
-2032(on)X
-2136(traversal)X
-2437(and)X
-2577(insertion.)X
-2921(We)X
-3057(speculate)X
-3380(that)X
-3524(this)X
-3663(is)X
-3740(due)X
-3880(in)X
-3966(part)X
-4115(to)X
-4201(the)X
-555 3600(overhead)N
-870(of)X
-957(query)X
-1160(parsing,)X
-1436(optimization,)X
-1880(and)X
-2016(repeated)X
-2309(interpretation)X
-2761(of)X
-2848(the)X
-2966(plan)X
-3124(tree)X
-3265(in)X
-3347(the)X
-3465(RDBMS')X
-3791(query)X
-3994(executor.)X
-755 3723(Table)N
-962(three)X
-1147(shows)X
-1371(the)X
-1492(differences)X
-1873(between)X
-2164(local)X
-2343(and)X
-2482(remote)X
-2728(execution)X
-3063(of)X
-3153(LIBTP's)X
-3456(OO1)X
-3635(implementation)X
-4160(on)X
-4263(a)X
-555 3813(DECstation.)N
-989(We)X
-1122(measured)X
-1451(performance)X
-1879(with)X
-2042(a)X
-2099(populated)X
-2436(\(warm\))X
-2694(cache)X
-2899(and)X
-3036(an)X
-3133(empty)X
-3354(\(cold\))X
-3567(cache.)X
-3812(Reported)X
-4126(times)X
-555 3903(are)N
-681(the)X
-806(means)X
-1037(of)X
-1130(twenty)X
-1374(tests,)X
-1562(and)X
-1704(are)X
-1829(in)X
-1917(seconds.)X
-2237(Standard)X
-2548(deviations)X
-2903(were)X
-3086(within)X
-3316(seven)X
-3525(percent)X
-3788(of)X
-3881(the)X
-4005(mean)X
-4205(for)X
-555 3993(remote,)N
-818(and)X
-954(two)X
-1094(percent)X
-1351(of)X
-1438(the)X
-1556(mean)X
-1750(for)X
-1864(local.)X
-755 4116(The)N
-914(20ms)X
-1121(overhead)X
-1450(of)X
-1551(TCP/IP)X
-1824(on)X
-1938(an)X
-2048(Ethernet)X
-2354(entirely)X
-2633(accounts)X
-2948(for)X
-3076(the)X
-3207(difference)X
-3567(in)X
-3662(speed.)X
-3918(The)X
-4076(remote)X
-555 4206(traversal)N
-857(times)X
-1055(are)X
-1179(nearly)X
-1405(double)X
-1648(the)X
-1771(local)X
-1952(times)X
-2150(because)X
-2430(we)X
-2549(do)X
-2653(index)X
-2855(lookups)X
-3132(and)X
-3272(part)X
-3421(fetches)X
-3673(in)X
-3759(separate)X
-4047(queries.)X
-555 4296(It)N
-629(would)X
-854(make)X
-1053(sense)X
-1252(to)X
-1339(do)X
-1444(indexed)X
-1723(searches)X
-2021(on)X
-2126(the)X
-2248(server,)X
-2489(but)X
-2615(we)X
-2733(were)X
-2914(unwilling)X
-3244(to)X
-3330(hard-code)X
-3676(knowledge)X
-4052(of)X
-4143(OO1)X
-555 4386(indices)N
-803(into)X
-948(our)X
-1075(LIBTP)X
-1317(TCL)X
-1488(server.)X
-1745(Cold)X
-1920(and)X
-2056(warm)X
-2259(insertion)X
-2559(times)X
-2752(are)X
-2871(identical)X
-3167(since)X
-3352(insertions)X
-3683(do)X
-3783(not)X
-3905(bene\256t)X
-4143(from)X
-555 4476(caching.)N
-755 4599(One)N
-915(interesting)X
-1279(difference)X
-1632(shown)X
-1867(by)X
-1973(table)X
-2155(three)X
-2342(is)X
-2421(the)X
-2545(cost)X
-2700(of)X
-2793(forward)X
-3074(versus)X
-3305(backward)X
-3644(traversal.)X
-3987(When)X
-4205(we)X
-555 4689(built)N
-725(the)X
-847(database,)X
-1168(we)X
-1285(inserted)X
-1562(parts)X
-1741(in)X
-1826(part)X
-2 f
-1974(id)X
-1 f
-2059(order.)X
-2292(We)X
-2427(built)X
-2596(the)X
-2717(indices)X
-2967(at)X
-3048(the)X
-3169(same)X
-3357(time.)X
-3562(Therefore,)X
-3923(the)X
-4044(forward)X
-555 4779(index)N
-757(had)X
-897(keys)X
-1068(inserted)X
-1346(in)X
-1432(order,)X
-1646(while)X
-1848(the)X
-1970(backward)X
-2307(index)X
-2509(had)X
-2649(keys)X
-2820(inserted)X
-3098(more)X
-3286(randomly.)X
-3656(In-order)X
-3943(insertion)X
-4246(is)X
-555 4885(pessimal)N
-858(for)X
-975(B-tree)X
-1199(indices,)X
-1469(so)X
-1563(the)X
-1684(forward)X
-1962(index)X
-2163(is)X
-2239(much)X
-2440(larger)X
-2651(than)X
-2812(the)X
-2933(backward)X
-3269(one)X
-7 s
-3385 4853(5)N
-10 s
-4885(.)Y
-3476(This)X
-3640(larger)X
-3850(size)X
-3997(shows)X
-4219(up)X
-555 4975(as)N
-642(extra)X
-823(disk)X
-976(reads)X
-1166(in)X
-1248(the)X
-1366(cold)X
-1524(benchmark.)X
-3 f
-555 5161(6.)N
-655(Conclusions)X
-1 f
-755 5284(LIBTP)N
-1006(provides)X
-1311(the)X
-1438(basic)X
-1632(building)X
-1927(blocks)X
-2165(to)X
-2256(support)X
-2525(transaction)X
-2906(protection.)X
-3300(In)X
-3396(comparison)X
-3799(with)X
-3970(traditional)X
-555 5374(Unix)N
-746(libraries)X
-1040(and)X
-1187(commercial)X
-1597(systems,)X
-1900(it)X
-1974(offers)X
-2192(a)X
-2258(variety)X
-2511(of)X
-2608(tradeoffs.)X
-2964(Using)X
-3185(complete)X
-3509(transaction)X
-3891(protection)X
-4246(is)X
-555 5464(more)N
-747(complicated)X
-1166(than)X
-1331(simply)X
-1575(adding)X
-3 f
-1820(fsync)X
-1 f
-1998(\(2\))X
-2119(and)X
-3 f
-2262(\257ock)X
-1 f
-2426(\(2\))X
-2547(calls)X
-2721(to)X
-2810(code,)X
-3008(but)X
-3136(it)X
-3206(is)X
-3285(faster)X
-3490(in)X
-3578(some)X
-3773(cases)X
-3969(and)X
-4111(offers)X
-8 s
-10 f
-555 5536(hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh)N
-5 s
-1 f
-727 5614(5)N
-8 s
-763 5639(The)N
-878(next)X
-1004(release)X
-1196(of)X
-1265(the)X
-1359(4.4BSD)X
-1580(access)X
-1758(method)X
-1966(will)X
-2082(automatically)X
-2446(detect)X
-2614(and)X
-2722(compensate)X
-3039(for)X
-3129(in-order)X
-3350(insertion,)X
-3606(eliminating)X
-3914(this)X
-4023(problem.)X
-
-16 p
-%%Page: 16 16
-8 s 8 xH 0 xS 1 f
-10 s
-3 f
-1 f
-555 630(stricter)N
-801(guarantees)X
-1168(\(atomicity,)X
-1540(consistency,)X
-1957(isolation,)X
-2275(and)X
-2414(durability\).)X
-2815(If)X
-2892(the)X
-3013(data)X
-3170(to)X
-3255(be)X
-3354(protected)X
-3676(are)X
-3798(already)X
-4058(format-)X
-555 720(ted)N
-675(\()X
-2 f
-702(i.e.)X
-1 f
-821(use)X
-949(one)X
-1086(of)X
-1174(the)X
-1293(database)X
-1591(access)X
-1818(methods\),)X
-2157(then)X
-2316(adding)X
-2555(transaction)X
-2928(protection)X
-3274(requires)X
-3554(no)X
-3655(additional)X
-3996(complex-)X
-555 810(ity,)N
-679(but)X
-801(incurs)X
-1017(a)X
-1073(performance)X
-1500(penalty)X
-1756(of)X
-1843(approximately)X
-2326(15%.)X
-755 933(In)N
-844(comparison)X
-1240(with)X
-1404(commercial)X
-1805(database)X
-2104(systems,)X
-2399(the)X
-2519(tradeoffs)X
-2827(are)X
-2948(more)X
-3135(complex.)X
-3473(LIBTP)X
-3717(does)X
-3886(not)X
-4009(currently)X
-555 1023(support)N
-825(a)X
-891(standard)X
-1193(query)X
-1406(language.)X
-1766(The)X
-1921(TCL-based)X
-2312(server)X
-2539(process)X
-2810(allows)X
-3049(a)X
-3115(certain)X
-3364(ease)X
-3533(of)X
-3630(use)X
-3767(which)X
-3993(would)X
-4223(be)X
-555 1113(enhanced)N
-882(with)X
-1047(a)X
-1106(more)X
-1294(user-friendly)X
-1732(interface)X
-2037(\()X
-2 f
-2064(e.g.)X
-1 f
-2203(a)X
-2261(windows)X
-2572(based)X
-2777(query-by-form)X
-3272(application\),)X
-3697(for)X
-3813(which)X
-4031(we)X
-4147(have)X
-555 1203(a)N
-620(working)X
-916(prototype.)X
-1292(When)X
-1513(accesses)X
-1815(do)X
-1924(not)X
-2055(require)X
-2312(sophisticated)X
-2758(query)X
-2969(processing,)X
-3360(the)X
-3486(TCL)X
-3665(interface)X
-3975(is)X
-4056(an)X
-4160(ade-)X
-555 1293(quate)N
-756(solution.)X
-1080(What)X
-1281(LIBTP)X
-1529(fails)X
-1693(to)X
-1781(provide)X
-2052(in)X
-2140(functionality,)X
-2595(it)X
-2665(makes)X
-2896(up)X
-3002(for)X
-3122(in)X
-3210(performance)X
-3643(and)X
-3785(\257exibility.)X
-4161(Any)X
-555 1383(application)N
-931(may)X
-1089(make)X
-1283(use)X
-1410(of)X
-1497(its)X
-1592(record)X
-1818(interface)X
-2120(or)X
-2207(the)X
-2325(more)X
-2510(primitive)X
-2823(log,)X
-2965(lock,)X
-3143(and)X
-3279(buffer)X
-3496(calls.)X
-755 1506(Future)N
-987(work)X
-1175(will)X
-1322(focus)X
-1519(on)X
-1621(overcoming)X
-2026(some)X
-2217(of)X
-2306(the)X
-2426(areas)X
-2614(in)X
-2698(which)X
-2916(LIBTP)X
-3160(is)X
-3235(currently)X
-3547(de\256cient)X
-3845(and)X
-3983(extending)X
-555 1596(its)N
-652(transaction)X
-1026(model.)X
-1288(The)X
-1435(addition)X
-1719(of)X
-1808(an)X
-1905(SQL)X
-2077(parser)X
-2295(and)X
-2432(forms)X
-2640(front)X
-2817(end)X
-2954(will)X
-3099(improve)X
-3387(the)X
-3506(system's)X
-3807(ease)X
-3967(of)X
-4055(use)X
-4183(and)X
-555 1686(make)N
-750(it)X
-815(more)X
-1001(competitive)X
-1400(with)X
-1563(commercial)X
-1963(systems.)X
-2277(In)X
-2365(the)X
-2484(long)X
-2647(term,)X
-2835(we)X
-2950(would)X
-3170(like)X
-3310(to)X
-3392(add)X
-3528(generalized)X
-3919(hierarchical)X
-555 1776(locking,)N
-836(nested)X
-1062(transactions,)X
-1486(parallel)X
-1748(transactions,)X
-2171(passing)X
-2431(of)X
-2518(transactions)X
-2921(between)X
-3209(processes,)X
-3557(and)X
-3693(distributed)X
-4055(commit)X
-555 1866(handling.)N
-900(In)X
-992(the)X
-1115(short)X
-1300(term,)X
-1492(the)X
-1614(next)X
-1776(step)X
-1929(is)X
-2006(to)X
-2092(integrate)X
-2397(LIBTP)X
-2643(with)X
-2809(the)X
-2931(most)X
-3110(recent)X
-3331(release)X
-3579(of)X
-3670(the)X
-3792(database)X
-4093(access)X
-555 1956(routines)N
-833(and)X
-969(make)X
-1163(it)X
-1227(freely)X
-1435(available)X
-1745(via)X
-1863(anonymous)X
-2252(ftp.)X
-3 f
-555 2142(7.)N
-655(Acknowledgements)X
-1 f
-755 2265(We)N
-888(would)X
-1109(like)X
-1250(to)X
-1332(thank)X
-1530(John)X
-1701(Wilkes)X
-1948(and)X
-2084(Carl)X
-2242(Staelin)X
-2484(of)X
-2571(Hewlett-Packard)X
-3131(Laboratories)X
-3557(and)X
-3693(Jon)X
-3824(Krueger.)X
-4148(John)X
-555 2355(and)N
-694(Carl)X
-855(provided)X
-1162(us)X
-1255(with)X
-1419(an)X
-1517(extra)X
-1700(disk)X
-1855(for)X
-1971(the)X
-2091(HP)X
-2215(testbed)X
-2464(less)X
-2606(than)X
-2766(24)X
-2868(hours)X
-3068(after)X
-3238(we)X
-3354(requested)X
-3684(it.)X
-3770(Jon)X
-3903(spent)X
-4094(count-)X
-555 2445(less)N
-699(hours)X
-901(helping)X
-1164(us)X
-1258(understand)X
-1633(the)X
-1754(intricacies)X
-2107(of)X
-2197(commercial)X
-2599(database)X
-2899(products)X
-3198(and)X
-3337(their)X
-3507(behavior)X
-3811(under)X
-4017(a)X
-4076(variety)X
-555 2535(of)N
-642(system)X
-884(con\256gurations.)X
-3 f
-555 2721(8.)N
-655(References)X
-1 f
-555 2901([ANDR89])N
-942(Andrade,)X
-1265(J.,)X
-1361(Carges,)X
-1629(M.,)X
-1765(Kovach,)X
-2060(K.,)X
-2183(``Building)X
-2541(an)X
-2642(On-Line)X
-2939(Transaction)X
-3343(Processing)X
-3715(System)X
-3975(On)X
-4098(UNIX)X
-727 2991(System)N
-982(V'',)X
-2 f
-1134(CommUNIXations)X
-1 f
-1725(,)X
-1765 0.2188(November/December)AX
-2477(1989.)X
-555 3171([BAY77])N
-878(Bayer,)X
-1110(R.,)X
-1223(Schkolnick,)X
-1623(M.,)X
-1754(``Concurrency)X
-2243(of)X
-2330(Operations)X
-2702(on)X
-2802(B-Trees'',)X
-2 f
-3155(Acta)X
-3322(Informatica)X
-1 f
-3700(,)X
-3740(1977.)X
-555 3351([BERN80])N
-936(Bernstein,)X
-1297(P.,)X
-1415(Goodman,)X
-1785(N.,)X
-1917(``Timestamp)X
-2365(Based)X
-2595(Algorithms)X
-2992(for)X
-3119(Concurrency)X
-3567(Control)X
-3844(in)X
-3939(Distributed)X
-727 3441(Database)N
-1042(Systems'',)X
-2 f
-1402(Proceedings)X
-1823(6th)X
-1945(International)X
-2387(Conference)X
-2777(on)X
-2877(Very)X
-3049(Large)X
-3260(Data)X
-3440(Bases)X
-1 f
-3627(,)X
-3667(October)X
-3946(1980.)X
-555 3621([BSD91])N
-864(DB\(3\),)X
-2 f
-1109(4.4BSD)X
-1376(Unix)X
-1552(Programmer's)X
-2044(Manual)X
-2313(Reference)X
-2655(Guide)X
-1 f
-2851(,)X
-2891(University)X
-3249(of)X
-3336(California,)X
-3701(Berkeley,)X
-4031(1991.)X
-555 3801([CATT91])N
-923(Cattell,)X
-1181(R.G.G.,)X
-1455(``An)X
-1632(Engineering)X
-2049(Database)X
-2369(Benchmark'',)X
-2 f
-2838(The)X
-2983(Benchmark)X
-3373(Handbook)X
-3731(for)X
-3848(Database)X
-4179(and)X
-727 3891(Transaction)N
-1133(Processing)X
-1509(Systems)X
-1 f
-1763(,)X
-1803(J.)X
-1874(Gray,)X
-2075(editor,)X
-2302(Morgan)X
-2576(Kaufman)X
-2895(1991.)X
-555 4071([CHEN91])N
-929(Cheng,)X
-1180(E.,)X
-1291(Chang,)X
-1542(E.,)X
-1653(Klein,)X
-1872(J.,)X
-1964(Lee,)X
-2126(D.,)X
-2245(Lu,)X
-2375(E.,)X
-2485(Lutgardo,)X
-2820(A.,)X
-2939(Obermarck,)X
-3342(R.,)X
-3456(``An)X
-3629(Open)X
-3824(and)X
-3961(Extensible)X
-727 4161(Event-Based)N
-1157(Transaction)X
-1556(Manager'',)X
-2 f
-1936(Proceedings)X
-2357(1991)X
-2537(Summer)X
-2820(Usenix)X
-1 f
-3043(,)X
-3083(Nashville,)X
-3430(TN,)X
-3577(June)X
-3744(1991.)X
-555 4341([CHOU85])N
-943(Chou,)X
-1163(H.,)X
-1288(DeWitt,)X
-1570(D.,)X
-1694(``An)X
-1872(Evaluation)X
-2245(of)X
-2338(Buffer)X
-2574(Management)X
-3019(Strategies)X
-3361(for)X
-3481(Relational)X
-3836(Database)X
-4157(Sys-)X
-727 4431(tems'',)N
-2 f
-972(Proceedings)X
-1393(of)X
-1475(the)X
-1593(11th)X
-1755(International)X
-2197(Conference)X
-2587(on)X
-2687(Very)X
-2859(Large)X
-3070(Databases)X
-1 f
-3408(,)X
-3448(1985.)X
-555 4611([DEWI84])N
-925(DeWitt,)X
-1207(D.,)X
-1331(Katz,)X
-1529(R.,)X
-1648(Olken,)X
-1890(F.,)X
-2000(Shapiro,)X
-2295(L.,)X
-2410(Stonebraker,)X
-2843(M.,)X
-2979(Wood,)X
-3220(D.,)X
-3343(``Implementation)X
-3929(Techniques)X
-727 4701(for)N
-841(Main)X
-1030(Memory)X
-1326(Database)X
-1641(Systems'',)X
-2 f
-2001(Proceedings)X
-2422(of)X
-2504(SIGMOD)X
-1 f
-2812(,)X
-2852(pp.)X
-2972(1-8,)X
-3119(June)X
-3286(1984.)X
-555 4881([GRAY76])N
-944(Gray,)X
-1153(J.,)X
-1252(Lorie,)X
-1474(R.,)X
-1595(Putzolu,)X
-1887(F.,)X
-1999(and)X
-2143(Traiger,)X
-2428(I.,)X
-2522(``Granularity)X
-2973(of)X
-3067(locks)X
-3263(and)X
-3406(degrees)X
-3679(of)X
-3773(consistency)X
-4174(in)X
-4263(a)X
-727 4971(large)N
-909(shared)X
-1140(data)X
-1295(base'',)X
-2 f
-1533(Modeling)X
-1861(in)X
-1944(Data)X
-2125(Base)X
-2301(Management)X
-2740(Systems)X
-1 f
-2994(,)X
-3034(Elsevier)X
-3317(North)X
-3524(Holland,)X
-3822(New)X
-3994(York,)X
-4199(pp.)X
-727 5061(365-394.)N
-555 5241([HAER83])N
-931(Haerder,)X
-1235(T.)X
-1348(Reuter,)X
-1606(A.)X
-1728(``Principles)X
-2126(of)X
-2217(Transaction-Oriented)X
-2928(Database)X
-3246(Recovery'',)X
-2 f
-3651(Computing)X
-4029(Surveys)X
-1 f
-4279(,)X
-727 5331(15\(4\);)N
-943(237-318,)X
-1250(1983.)X
-555 5511([KUNG81])N
-943(Kung,)X
-1162(H.)X
-1261(T.,)X
-1371(Richardson,)X
-1777(J.,)X
-1869(``On)X
-2042(Optimistic)X
-2400(Methods)X
-2701(for)X
-2816(Concurrency)X
-3252(Control'',)X
-2 f
-3591(ACM)X
-3781(Transactions)X
-4219(on)X
-727 5601(Database)N
-1054(Systems)X
-1 f
-1328(6\(2\);)X
-1504(213-226,)X
-1811(1981.)X
-
-17 p
-%%Page: 17 17
-10 s 10 xH 0 xS 1 f
-3 f
-1 f
-555 630([LEHM81])N
-939(Lehman,)X
-1245(P.,)X
-1352(Yao,)X
-1529(S.,)X
-1636(``Ef\256cient)X
-1989(Locking)X
-2279(for)X
-2396(Concurrent)X
-2780(Operations)X
-3155(on)X
-3258(B-trees'',)X
-2 f
-3587(ACM)X
-3779(Transactions)X
-4219(on)X
-727 720(Database)N
-1054(Systems)X
-1 f
-1308(,)X
-1348(6\(4\),)X
-1522(December)X
-1873(1981.)X
-555 900([MOHA91])N
-964(Mohan,)X
-1241(C.,)X
-1364(Pirahesh,)X
-1690(H.,)X
-1818(``ARIES-RRH:)X
-2366(Restricted)X
-2721(Repeating)X
-3076(of)X
-3173(History)X
-3442(in)X
-3533(the)X
-3660(ARIES)X
-3920(Transaction)X
-727 990(Recovery)N
-1055(Method'',)X
-2 f
-1398(Proceedings)X
-1819(7th)X
-1941(International)X
-2383(Conference)X
-2773(on)X
-2873(Data)X
-3053(Engineering)X
-1 f
-3449(,)X
-3489(Kobe,)X
-3703(Japan,)X
-3926(April)X
-4115(1991.)X
-555 1170([NODI90])N
-914(Nodine,)X
-1194(M.,)X
-1328(Zdonik,)X
-1602(S.,)X
-1709(``Cooperative)X
-2178(Transaction)X
-2580(Hierarchies:)X
-2996(A)X
-3077(Transaction)X
-3479(Model)X
-3711(to)X
-3796(Support)X
-4072(Design)X
-727 1260(Applications'',)N
-2 f
-1242(Proceedings)X
-1675(16th)X
-1849(International)X
-2303(Conference)X
-2704(on)X
-2815(Very)X
-2998(Large)X
-3220(Data)X
-3411(Bases)X
-1 f
-3598(,)X
-3649(Brisbane,)X
-3985(Australia,)X
-727 1350(August)N
-978(1990.)X
-555 1530([OUST90])N
-923(Ousterhout,)X
-1324(J.,)X
-1420(``Tcl:)X
-1648(An)X
-1771(Embeddable)X
-2197(Command)X
-2555(Language'',)X
-2 f
-2971(Proceedings)X
-3396(1990)X
-3580(Winter)X
-3822(Usenix)X
-1 f
-4045(,)X
-4089(Wash-)X
-727 1620(ington,)N
-971(D.C.,)X
-1162(January)X
-1432(1990.)X
-555 1800([POSIX91])N
-955(``Unapproved)X
-1441(Draft)X
-1645(for)X
-1773(Realtime)X
-2096(Extension)X
-2450(for)X
-2578(Portable)X
-2879(Operating)X
-3234(Systems'',)X
-3608(Draft)X
-3812(11,)X
-3946(October)X
-4239(7,)X
-727 1890(1991,)N
-927(IEEE)X
-1121(Computer)X
-1461(Society.)X
-555 2070([ROSE91])N
-925(Rosenblum,)X
-1341(M.,)X
-1484(Ousterhout,)X
-1892(J.,)X
-1995(``The)X
-2206(Design)X
-2464(and)X
-2611(Implementation)X
-3149(of)X
-3247(a)X
-3314(Log-Structured)X
-3835(File)X
-3990(System'',)X
-2 f
-727 2160(Proceedings)N
-1148(of)X
-1230(the)X
-1348(13th)X
-1510(Symposium)X
-1895(on)X
-1995(Operating)X
-2344(Systems)X
-2618(Principles)X
-1 f
-2947(,)X
-2987(1991.)X
-555 2340([SELT91])N
-904(Seltzer,)X
-1171(M.,)X
-1306(Stonebraker,)X
-1738(M.,)X
-1873(``Read)X
-2116(Optimized)X
-2478(File)X
-2626(Systems:)X
-2938(A)X
-3020(Performance)X
-3454(Evaluation'',)X
-2 f
-3898(Proceedings)X
-727 2430(7th)N
-849(Annual)X
-1100(International)X
-1542(Conference)X
-1932(on)X
-2032(Data)X
-2212(Engineering)X
-1 f
-2608(,)X
-2648(Kobe,)X
-2862(Japan,)X
-3085(April)X
-3274(1991.)X
-555 2610([SPEC88])N
-907(Spector,)X
-1200(Rausch,)X
-1484(Bruell,)X
-1732(``Camelot:)X
-2107(A)X
-2192(Flexible,)X
-2501(Distributed)X
-2888(Transaction)X
-3294(Processing)X
-3668(System'',)X
-2 f
-4004(Proceed-)X
-727 2700(ings)N
-880(of)X
-962(Spring)X
-1195(COMPCON)X
-1606(1988)X
-1 f
-(,)S
-1806(February)X
-2116(1988.)X
-555 2880([SQL86])N
-862(American)X
-1201(National)X
-1499(Standards)X
-1836(Institute,)X
-2139(``Database)X
-2509(Language)X
-2847(SQL'',)X
-3093(ANSI)X
-3301(X3.135-1986)X
-3747(\(ISO)X
-3924(9075\),)X
-4152(May)X
-727 2970(1986.)N
-555 3150([STON81])N
-919(Stonebraker,)X
-1348(M.,)X
-1480(``Operating)X
-1876(System)X
-2132(Support)X
-2406(for)X
-2520(Database)X
-2835(Management'',)X
-2 f
-3348(Communications)X
-3910(of)X
-3992(the)X
-4110(ACM)X
-1 f
-4279(,)X
-727 3240(1981.)N
-555 3420([SULL92])N
-925(Sullivan,)X
-1247(M.,)X
-1394(Olson,)X
-1641(M.,)X
-1788(``An)X
-1976(Index)X
-2195(Implementation)X
-2737(Supporting)X
-3127(Fast)X
-3295(Recovery)X
-3638(for)X
-3767(the)X
-3900(POSTGRES)X
-727 3510(Storage)N
-1014(System'',)X
-1365(to)X
-1469(appear)X
-1726(in)X
-2 f
-1830(Proceedings)X
-2272(8th)X
-2415(Annual)X
-2687(International)X
-3150(Conference)X
-3561(on)X
-3682(Data)X
-3883(Engineering)X
-1 f
-4279(,)X
-727 3600(Tempe,)N
-990(Arizona,)X
-1289(February)X
-1599(1992.)X
-555 3780([TPCB90])N
-914(Transaction)X
-1319(Processing)X
-1692(Performance)X
-2129(Council,)X
-2428(``TPC)X
-2653(Benchmark)X
-3048(B'',)X
-3200(Standard)X
-3510(Speci\256cation,)X
-3973(Waterside)X
-727 3870(Associates,)N
-1110(Fremont,)X
-1421(CA.,)X
-1592(1990.)X
-555 4050([YOUN91])N
-947(Young,)X
-1211(M.)X
-1328(W.,)X
-1470(Thompson,)X
-1858(D.)X
-1962(S.,)X
-2072(Jaffe,)X
-2274(E.,)X
-2388(``A)X
-2525(Modular)X
-2826(Architecture)X
-3253(for)X
-3372(Distributed)X
-3757(Transaction)X
-4161(Pro-)X
-727 4140(cessing'',)N
-2 f
-1057(Proceedings)X
-1478(1991)X
-1658(Winter)X
-1896(Usenix)X
-1 f
-2119(,)X
-2159(Dallas,)X
-2404(TX,)X
-2551(January)X
-2821(1991.)X
-3 f
-755 4263(Margo)N
-1008(I.)X
-1080(Seltzer)X
-1 f
-1338(is)X
-1411(a)X
-1467(Ph.D.)X
-1669(student)X
-1920(in)X
-2002(the)X
-2120(Department)X
-2519(of)X
-2606(Electrical)X
-2934(Engineering)X
-3346(and)X
-3482(Computer)X
-3822(Sciences)X
-4123(at)X
-4201(the)X
-555 4353(University)N
-919(of)X
-1012(California,)X
-1383(Berkeley.)X
-1739(Her)X
-1886(research)X
-2181(interests)X
-2474(include)X
-2735(\256le)X
-2862(systems,)X
-3160(databases,)X
-3513(and)X
-3654(transaction)X
-4031(process-)X
-555 4443(ing)N
-686(systems.)X
-1008(She)X
-1157(spent)X
-1355(several)X
-1612(years)X
-1811(working)X
-2107(at)X
-2194(startup)X
-2441(companies)X
-2813(designing)X
-3153(and)X
-3298(implementing)X
-3771(\256le)X
-3902(systems)X
-4183(and)X
-555 4533(transaction)N
-929(processing)X
-1294(software)X
-1592(and)X
-1729(designing)X
-2061(microprocessors.)X
-2648(Ms.)X
-2791(Seltzer)X
-3035(received)X
-3329(her)X
-3453(AB)X
-3585(in)X
-3668(Applied)X
-3947(Mathemat-)X
-555 4623(ics)N
-664(from)X
-840 0.1953(Harvard/Radcliffe)AX
-1445(College)X
-1714(in)X
-1796(1983.)X
-755 4746(In)N
-845(her)X
-971(spare)X
-1163(time,)X
-1347(Margo)X
-1583(can)X
-1717(usually)X
-1970(be)X
-2068(found)X
-2277(preparing)X
-2607(massive)X
-2887(quantities)X
-3220(of)X
-3309(food)X
-3478(for)X
-3594(hungry)X
-3843(hordes,)X
-4099(study-)X
-555 4836(ing)N
-677(Japanese,)X
-1003(or)X
-1090(playing)X
-1350(soccer)X
-1576(with)X
-1738(an)X
-1834(exciting)X
-2112(Bay)X
-2261(Area)X
-2438(Women's)X
-2770(Soccer)X
-3009(team,)X
-3205(the)X
-3323(Berkeley)X
-3633(Bruisers.)X
-3 f
-755 5049(Michael)N
-1056(A.)X
-1159(Olson)X
-1 f
-1383(is)X
-1461(a)X
-1522(Master's)X
-1828(student)X
-2084(in)X
-2170(the)X
-2292(Department)X
-2695(of)X
-2786(Electrical)X
-3118(Engineering)X
-3534(and)X
-3674(Computer)X
-4018(Sciences)X
-555 5139(at)N
-645(the)X
-774(University)X
-1143(of)X
-1241(California,)X
-1617(Berkeley.)X
-1978(His)X
-2120(primary)X
-2405(interests)X
-2703(are)X
-2833(database)X
-3141(systems)X
-3425(and)X
-3572(mass)X
-3763(storage)X
-4026(systems.)X
-555 5229(Mike)N
-759(spent)X
-963(two)X
-1118(years)X
-1323(working)X
-1625(for)X
-1754(a)X
-1825(commercial)X
-2239(database)X
-2551(system)X
-2808(vendor)X
-3066(before)X
-3307(joining)X
-3567(the)X
-3699(Postgres)X
-4004(Research)X
-555 5319(Group)N
-780(at)X
-858(Berkeley)X
-1168(in)X
-1250(1988.)X
-1470(He)X
-1584(received)X
-1877(his)X
-1990(B.A.)X
-2161(in)X
-2243(Computer)X
-2583(Science)X
-2853(from)X
-3029(Berkeley)X
-3339(in)X
-3421(May)X
-3588(1991.)X
-755 5442(Mike)N
-945(only)X
-1108(recently)X
-1388(transferred)X
-1758(into)X
-1903(Sin)X
-2030(City,)X
-2208(but)X
-2330(is)X
-2403(rapidly)X
-2650(adopting)X
-2950(local)X
-3126(customs)X
-3408(and)X
-3544(coloration.)X
-3929(In)X
-4016(his)X
-4129(spare)X
-555 5532(time,)N
-742(he)X
-843(organizes)X
-1176(informal)X
-1477(Friday)X
-1711(afternoon)X
-2043(study)X
-2240(groups)X
-2482(to)X
-2568(discuss)X
-2823(recent)X
-3044(technical)X
-3358(and)X
-3498(economic)X
-3834(developments.)X
-555 5622(Among)N
-815(his)X
-928(hobbies)X
-1197(are)X
-1316(Charles)X
-1581(Dickens,)X
-1884(Red)X
-2033(Rock,)X
-2242(and)X
-2378(speaking)X
-2683(Dutch)X
-2899(to)X
-2981(anyone)X
-3233(who)X
-3391(will)X
-3535(permit)X
-3764(it.)X
-
-17 p
-%%Trailer
-xt
-
-xs
-
diff --git a/lib/libc/db/hash/Makefile.inc b/lib/libc/db/hash/Makefile.inc
index cac96fe..080a1a2 100644
--- a/lib/libc/db/hash/Makefile.inc
+++ b/lib/libc/db/hash/Makefile.inc
@@ -1,6 +1,7 @@
-# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
-.PATH: ${.CURDIR}/db/hash
+.PATH: ${.CURDIR}/../libc/db/hash
SRCS+= hash.c hash_bigkey.c hash_buf.c hash_func.c hash_log2.c \
hash_page.c hsearch.c ndbm.c
diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c
index 4b7b732..7d000dc 100644
--- a/lib/libc/db/hash/hash.c
+++ b/lib/libc/db/hash/hash.c
@@ -130,6 +130,13 @@ __hash_open(file, flags, mode, info, dflags)
if (file) {
if ((hashp->fp = open(file, flags, mode)) == -1)
RETURN_ERROR(errno, error0);
+
+ /* if the .db file is empty, and we had permission to create
+ a new .db file, then reinitialize the database */
+ if ((flags & O_CREAT) &&
+ fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0)
+ new_table = 1;
+
(void)fcntl(hashp->fp, F_SETFD, 1);
}
if (new_table) {
@@ -505,7 +512,7 @@ flush_meta(hashp)
else
if (wsize != sizeof(HASHHDR)) {
errno = EFTYPE;
- hashp->errno = errno;
+ hashp->error = errno;
return (-1);
}
for (i = 0; i < NCACHED; i++)
@@ -536,7 +543,7 @@ hash_get(dbp, key, data, flag)
hashp = (HTAB *)dbp->internal;
if (flag) {
- hashp->errno = errno = EINVAL;
+ hashp->error = errno = EINVAL;
return (ERROR);
}
return (hash_access(hashp, HASH_GET, (DBT *)key, data));
@@ -553,11 +560,11 @@ hash_put(dbp, key, data, flag)
hashp = (HTAB *)dbp->internal;
if (flag && flag != R_NOOVERWRITE) {
- hashp->errno = errno = EINVAL;
+ hashp->error = errno = EINVAL;
return (ERROR);
}
if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
- hashp->errno = errno = EPERM;
+ hashp->error = errno = EPERM;
return (ERROR);
}
return (hash_access(hashp, flag == R_NOOVERWRITE ?
@@ -574,11 +581,11 @@ hash_delete(dbp, key, flag)
hashp = (HTAB *)dbp->internal;
if (flag && flag != R_CURSOR) {
- hashp->errno = errno = EINVAL;
+ hashp->error = errno = EINVAL;
return (ERROR);
}
if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
- hashp->errno = errno = EPERM;
+ hashp->error = errno = EPERM;
return (ERROR);
}
return (hash_access(hashp, HASH_DELETE, (DBT *)key, NULL));
@@ -729,7 +736,7 @@ hash_seq(dbp, key, data, flag)
hashp = (HTAB *)dbp->internal;
if (flag && flag != R_FIRST && flag != R_NEXT) {
- hashp->errno = errno = EINVAL;
+ hashp->error = errno = EINVAL;
return (ERROR);
}
#ifdef HASH_STATISTICS
@@ -868,7 +875,7 @@ hash_realloc(p_ptr, oldsize, newsize)
{
register void *p;
- if (p = malloc(newsize)) {
+ if ( (p = malloc(newsize)) ) {
memmove(p, *p_ptr, oldsize);
memset((char *)p + oldsize, 0, newsize - oldsize);
free(*p_ptr);
diff --git a/lib/libc/db/hash/hash.h b/lib/libc/db/hash/hash.h
index 913e82b..504a9b6 100644
--- a/lib/libc/db/hash/hash.h
+++ b/lib/libc/db/hash/hash.h
@@ -103,7 +103,7 @@ typedef struct htab { /* Memory resident data structure */
BUFHEAD *cpage; /* Current page */
int cbucket; /* Current bucket */
int cndx; /* Index of next item on cpage */
- int errno; /* Error Number -- for DBM
+ int error; /* Error Number -- for DBM
* compatability */
int new_file; /* Indicates if fd is backing store
* or no */
@@ -194,7 +194,7 @@ typedef struct htab { /* Memory resident data structure */
* so it starts on this page and continues on the next.
* The format of the page is:
* KEY_OFF PARTIAL_KEY OVFL_PAGENO OVFLPAGE
- *
+ *
* KEY_OFF -- offset of the beginning of the key
* PARTIAL_KEY -- 1
* OVFL_PAGENO - page number of the next overflow page
@@ -229,7 +229,7 @@ typedef struct htab { /* Memory resident data structure */
* OVFL_PAGENO - page number of the next overflow page
* OVFLPAGE -- 0
*
- * FULL_KEY_DATA
+ * FULL_KEY_DATA
* This must be the first key/data pair on the page.
* There are two cases:
*
diff --git a/lib/libc/db/hash/hash_bigkey.c b/lib/libc/db/hash/hash_bigkey.c
index 578314a..0cee07e 100644
--- a/lib/libc/db/hash/hash_bigkey.c
+++ b/lib/libc/db/hash/hash_bigkey.c
@@ -590,7 +590,7 @@ __big_split(hashp, op, np, big_keyp, addr, obucket, ret)
return (-1);
change = (__call_hash(hashp, key.data, key.size) != obucket);
- if (ret->next_addr = __find_last_page(hashp, &big_keyp)) {
+ if ( (ret->next_addr = __find_last_page(hashp, &big_keyp)) ) {
if (!(ret->nextp =
__get_buf(hashp, ret->next_addr, big_keyp, 0)))
return (-1);;
diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c
index e1dfe6b..2c05090 100644
--- a/lib/libc/db/hash/hash_page.c
+++ b/lib/libc/db/hash/hash_page.c
@@ -688,7 +688,7 @@ overflow_page(hashp)
in_use_bits = free_bit;
else
in_use_bits = (hashp->BSIZE << BYTE_SHIFT) - 1;
-
+
if (i == first_page) {
bit = hashp->LAST_FREED &
((hashp->BSIZE << BYTE_SHIFT) - 1);
diff --git a/lib/libc/db/hash/hsearch.c b/lib/libc/db/hash/hsearch.c
index cc8f7a4..6185330 100644
--- a/lib/libc/db/hash/hsearch.c
+++ b/lib/libc/db/hash/hsearch.c
@@ -62,7 +62,7 @@ hcreate(nel)
info.hash = NULL;
info.lorder = 0;
dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR, 0600, &info, 0);
- return ((int)dbp);
+ return (dbp != NULL);
}
extern ENTRY *
diff --git a/lib/libc/db/hash/ndbm.c b/lib/libc/db/hash/ndbm.c
index 2cbbe91..2e8165d 100644
--- a/lib/libc/db/hash/ndbm.c
+++ b/lib/libc/db/hash/ndbm.c
@@ -47,6 +47,7 @@ static char sccsid[] = "@(#)ndbm.c 8.4 (Berkeley) 7/21/94";
#include <stdio.h>
#include <string.h>
+#include <errno.h>
#include <ndbm.h>
#include "hash.h"
@@ -70,6 +71,11 @@ dbm_open(file, flags, mode)
info.cachesize = 0;
info.hash = NULL;
info.lorder = 0;
+
+ if( strlen(file) >= sizeof(path) - strlen(DBM_SUFFIX)) {
+ errno = ENAMETOOLONG;
+ return(NULL);
+ }
(void)strcpy(path, file);
(void)strcat(path, DBM_SUFFIX);
return ((DBM *)__hash_open(path, flags, mode, &info, 0));
@@ -92,15 +98,20 @@ dbm_fetch(db, key)
DBM *db;
datum key;
{
- datum retval;
+ datum retdata;
int status;
+ DBT dbtkey, dbtretdata;
- status = (db->get)(db, (DBT *)&key, (DBT *)&retval, 0);
+ dbtkey.data = key.dptr;
+ dbtkey.size = key.dsize;
+ status = (db->get)(db, &dbtkey, &dbtretdata, 0);
if (status) {
- retval.dptr = NULL;
- retval.dsize = 0;
+ dbtretdata.data = NULL;
+ dbtretdata.size = 0;
}
- return (retval);
+ retdata.dptr = dbtretdata.data;
+ retdata.dsize = dbtretdata.size;
+ return (retdata);
}
/*
@@ -113,11 +124,14 @@ dbm_firstkey(db)
DBM *db;
{
int status;
- datum retdata, retkey;
+ datum retkey;
+ DBT dbtretkey, dbtretdata;
- status = (db->seq)(db, (DBT *)&retkey, (DBT *)&retdata, R_FIRST);
+ status = (db->seq)(db, &dbtretkey, &dbtretdata, R_FIRST);
if (status)
- retkey.dptr = NULL;
+ dbtretkey.data = NULL;
+ retkey.dptr = dbtretkey.data;
+ retkey.dsize = dbtretkey.size;
return (retkey);
}
@@ -131,13 +145,17 @@ dbm_nextkey(db)
DBM *db;
{
int status;
- datum retdata, retkey;
+ datum retkey;
+ DBT dbtretkey, dbtretdata;
- status = (db->seq)(db, (DBT *)&retkey, (DBT *)&retdata, R_NEXT);
+ status = (db->seq)(db, &dbtretkey, &dbtretdata, R_NEXT);
if (status)
- retkey.dptr = NULL;
+ dbtretkey.data = NULL;
+ retkey.dptr = dbtretkey.data;
+ retkey.dsize = dbtretkey.size;
return (retkey);
}
+
/*
* Returns:
* 0 on success
@@ -149,8 +167,11 @@ dbm_delete(db, key)
datum key;
{
int status;
+ DBT dbtkey;
- status = (db->del)(db, (DBT *)&key, 0);
+ dbtkey.data = key.dptr;
+ dbtkey.size = key.dsize;
+ status = (db->del)(db, &dbtkey, 0);
if (status)
return (-1);
else
@@ -164,12 +185,18 @@ dbm_delete(db, key)
* 1 if DBM_INSERT and entry exists
*/
extern int
-dbm_store(db, key, content, flags)
+dbm_store(db, key, data, flags)
DBM *db;
- datum key, content;
+ datum key, data;
int flags;
{
- return ((db->put)(db, (DBT *)&key, (DBT *)&content,
+ DBT dbtkey, dbtdata;
+
+ dbtkey.data = key.dptr;
+ dbtkey.size = key.dsize;
+ dbtdata.data = data.dptr;
+ dbtdata.size = data.dsize;
+ return ((db->put)(db, &dbtkey, &dbtdata,
(flags == DBM_INSERT) ? R_NOOVERWRITE : 0));
}
@@ -180,7 +207,7 @@ dbm_error(db)
HTAB *hp;
hp = (HTAB *)db->internal;
- return (hp->errno);
+ return (hp->error);
}
extern int
@@ -190,7 +217,7 @@ dbm_clearerr(db)
HTAB *hp;
hp = (HTAB *)db->internal;
- hp->errno = 0;
+ hp->error = 0;
return (0);
}
diff --git a/lib/libc/db/man/Makefile.inc b/lib/libc/db/man/Makefile.inc
index d8d93f9..a1474b1 100644
--- a/lib/libc/db/man/Makefile.inc
+++ b/lib/libc/db/man/Makefile.inc
@@ -1,7 +1,12 @@
-# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# #Id$
-.PATH: ${.CURDIR}/db/man
+.PATH: ${.CURDIR}/../libc/db/man
+# Only build man pages with libc.
+.if ${LIB} == "c"
# mpool.3
-MAN3+= btree.0 dbopen.0 hash.0 recno.0
+MAN3+= db/man/btree.3 db/man/dbopen.3 db/man/hash.3 db/man/recno.3
+MAN3+= db/man/mpool.3
MLINKS+= dbopen.3 db.3
+.endif
diff --git a/lib/libc/db/man/hash.3 b/lib/libc/db/man/hash.3
index 4367031..d408b5d 100644
--- a/lib/libc/db/man/hash.3
+++ b/lib/libc/db/man/hash.3
@@ -131,11 +131,11 @@ If a hash function is specified,
will attempt to determine if the hash function specified is the same as
the one with which the database was created, and will fail if it is not.
.PP
-Backward compatible interfaces to the routines described in
-.IR dbm (3),
+Backward compatible interfaces to the older
+.I dbm
and
-.IR ndbm (3)
-are provided, however these interfaces are not compatible with
+.I ndbm
+routines are provided, however these interfaces are not compatible with
previous file formats.
.SH ERRORS
The
diff --git a/lib/libc/db/man/mpool.3 b/lib/libc/db/man/mpool.3
index c17606e..e625dc4 100644
--- a/lib/libc/db/man/mpool.3
+++ b/lib/libc/db/man/mpool.3
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)mpool.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.TH MPOOL 3 "June 4, 1993"
.UC 7
@@ -115,7 +116,7 @@ If the
.I pgout
function is specified, it is called each time a buffer is written into the
backing file.
-Both functions are are called with the
+Both functions are called with the
.I pgcookie
pointer, the page number and a pointer to the page to being read or written.
.PP
diff --git a/lib/libc/db/man/recno.3 b/lib/libc/db/man/recno.3
index 516bef0..bb5f353 100644
--- a/lib/libc/db/man/recno.3
+++ b/lib/libc/db/man/recno.3
@@ -204,10 +204,10 @@ or the following:
An attempt was made to add a record to a fixed-length database that
was too large to fit.
.SH "SEE ALSO"
-.IR btree (3)
+.IR btree (3),
.IR dbopen (3),
.IR hash (3),
-.IR mpool (3),
+.IR mpool (3)
.sp
.IR "Document Processing in a Relational Database System" ,
Michael Stonebraker, Heidi Stettner, Joseph Kalash, Antonin Guttman,
diff --git a/lib/libc/db/mpool/Makefile.inc b/lib/libc/db/mpool/Makefile.inc
index 93210c8..c8f2949 100644
--- a/lib/libc/db/mpool/Makefile.inc
+++ b/lib/libc/db/mpool/Makefile.inc
@@ -1,5 +1,6 @@
-# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
-.PATH: ${.CURDIR}/db/mpool
+.PATH: ${.CURDIR}/../libc/db/mpool
SRCS+= mpool.c
diff --git a/lib/libc/db/mpool/mpool.libtp b/lib/libc/db/mpool/mpool.libtp
index 8c0fc27..dbb0469 100644
--- a/lib/libc/db/mpool/mpool.libtp
+++ b/lib/libc/db/mpool/mpool.libtp
@@ -1,6 +1,6 @@
/******************************************************************************
-VERSION $Id: buf.c,v 1.26 92/01/09 09:15:26 margo Exp $
+VERSION $Id$
PACKAGE: User Level Shared Memory Manager
DESCRIPTION:
diff --git a/lib/libc/db/recno/Makefile.inc b/lib/libc/db/recno/Makefile.inc
index e49e225..5241fa5 100644
--- a/lib/libc/db/recno/Makefile.inc
+++ b/lib/libc/db/recno/Makefile.inc
@@ -1,6 +1,7 @@
-# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
-.PATH: ${.CURDIR}/db/recno
+.PATH: ${.CURDIR}/../libc/db/recno
SRCS+= rec_close.c rec_delete.c rec_get.c rec_open.c rec_put.c rec_search.c \
rec_seq.c rec_utils.c
diff --git a/lib/libc/db/recno/rec_close.c b/lib/libc/db/recno/rec_close.c
index 16fb0b4..1c124de 100644
--- a/lib/libc/db/recno/rec_close.c
+++ b/lib/libc/db/recno/rec_close.c
@@ -155,7 +155,7 @@ __rec_sync(dbp, flags)
status = (dbp->seq)(dbp, &key, &data, R_NEXT);
}
} else {
- iov[1].iov_base = &t->bt_bval;
+ iov[1].iov_base = (char *)&t->bt_bval;
iov[1].iov_len = 1;
status = (dbp->seq)(dbp, &key, &data, R_FIRST);
diff --git a/lib/libc/db/recno/rec_open.c b/lib/libc/db/recno/rec_open.c
index 51d8a3c..8f8eff2 100644
--- a/lib/libc/db/recno/rec_open.c
+++ b/lib/libc/db/recno/rec_open.c
@@ -169,7 +169,7 @@ slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL)
t->bt_msize = sb.st_size;
if ((t->bt_smap = mmap(NULL, t->bt_msize,
PROT_READ, MAP_PRIVATE, rfd,
- (off_t)0)) == (caddr_t)-1)
+ (off_t)0)) == MAP_FAILED)
goto slow;
t->bt_cmap = t->bt_smap;
t->bt_emap = t->bt_smap + sb.st_size;
diff --git a/lib/libc/db/test/btree.tests/main.c b/lib/libc/db/test/btree.tests/main.c
index f26e193..39c1da0 100644
--- a/lib/libc/db/test/btree.tests/main.c
+++ b/lib/libc/db/test/btree.tests/main.c
@@ -629,7 +629,7 @@ load(db, argv)
key.size = sizeof(recno_t);
data.data = lp;
data.size = len + 1;
- } else {
+ } else {
key.data = lp;
key.size = len + 1;
for (p = lp + len - 1, t = buf; p >= lp; *t++ = *p--);
diff --git a/lib/libc/db/test/hash.tests/driver2.c b/lib/libc/db/test/hash.tests/driver2.c
index 2008a28..896820c 100644
--- a/lib/libc/db/test/hash.tests/driver2.c
+++ b/lib/libc/db/test/hash.tests/driver2.c
@@ -110,5 +110,5 @@ main(argc, argv)
exit(0);
}
-
+
diff --git a/lib/libc/db/test/hash.tests/tcreat3.c b/lib/libc/db/test/hash.tests/tcreat3.c
index bd125ac..31211c5 100644
--- a/lib/libc/db/test/hash.tests/tcreat3.c
+++ b/lib/libc/db/test/hash.tests/tcreat3.c
@@ -97,7 +97,7 @@ char **argv;
fprintf(stderr, "cannot enter: key %s\n",
item.data);
exit(1);
- }
+ }
}
(dbp->close)(dbp);
diff --git a/lib/libc/db/test/hash.tests/tdel.c b/lib/libc/db/test/hash.tests/tdel.c
index ed3f90a..fb99431 100644
--- a/lib/libc/db/test/hash.tests/tdel.c
+++ b/lib/libc/db/test/hash.tests/tdel.c
@@ -99,7 +99,7 @@ char **argv;
fprintf(stderr, "cannot enter: key %s\n",
item.data);
exit(1);
- }
+ }
}
if ( --argc ) {
@@ -113,7 +113,7 @@ char **argv;
if (stat) {
fprintf ( stderr, "Error retrieving %s\n", key.data );
exit(1);
- }
+ }
}
fclose(fp);
}
diff --git a/lib/libc/db/test/hash.tests/thash4.c b/lib/libc/db/test/hash.tests/thash4.c
index 9e344cb..952dccb 100644
--- a/lib/libc/db/test/hash.tests/thash4.c
+++ b/lib/libc/db/test/hash.tests/thash4.c
@@ -86,8 +86,8 @@ char **argv;
key.data = wp1;
item.data = wp2;
- while ( fgets(wp1, 8192, stdin) &&
- fgets(wp2, 8192, stdin) &&
+ while ( fgets(wp1, 8192, stdin) &&
+ fgets(wp2, 8192, stdin) &&
i++ < MAXWORDS) {
/*
* put info in structure, and structure in the item
@@ -103,14 +103,14 @@ char **argv;
item.data);
fprintf(stderr, "\terrno: %d\n", errno);
exit(1);
- }
+ }
}
if ( --argc ) {
fp = fopen ( argv[0], "r");
i = 0;
- while ( fgets(wp1, 256, fp) &&
- fgets(wp2, 8192, fp) &&
+ while ( fgets(wp1, 256, fp) &&
+ fgets(wp2, 8192, fp) &&
i++ < MAXWORDS) {
key.size = strlen(wp1);
diff --git a/lib/libc/db/test/hash.tests/tseq.c b/lib/libc/db/test/hash.tests/tseq.c
index f45700e..f41c172 100644
--- a/lib/libc/db/test/hash.tests/tseq.c
+++ b/lib/libc/db/test/hash.tests/tseq.c
@@ -72,7 +72,7 @@ char **argv;
/*
* put info in structure, and structure in the item
*/
- for ( stat = (dbp->seq) (dbp, &res, &item, 1 );
+ for ( stat = (dbp->seq) (dbp, &res, &item, 1 );
stat == 0;
stat = (dbp->seq) (dbp, &res, &item, 0 ) ) {
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index b24f7da..59ffcbb 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,56 +1,80 @@
# @(#)Makefile.inc 8.6 (Berkeley) 5/4/95
+# $Id: Makefile.inc,v 1.35 1997/06/14 01:15:41 ache Exp $
# machine-independent gen sources
-.PATH: ${.CURDIR}/${MACHINE}/gen ${.CURDIR}/gen
+.PATH: ${.CURDIR}/../libc/${MACHINE}/gen ${.CURDIR}/../libc/gen
-SRCS+= alarm.c assert.c clock.c closedir.c confstr.c crypt.c ctermid.c \
- ctime.c daemon.c devname.c difftime.c disklabel.c err.c errlst.c \
- exec.c fnmatch.c frexp.c fstab.c fts.c getbsize.c getcap.c getcwd.c \
- getgrent.c getgrouplist.c gethostname.c getloadavg.c getlogin.c \
- getmntinfo.c getnetgrent.c getpagesize.c getpass.c getpwent.c \
- getttyent.c getusershell.c getvfsbyname.c glob.c initgroups.c isatty.c \
- nice.c nlist.c opendir.c pause.c popen.c psignal.c pwcache.c raise.c \
- readdir.c rewinddir.c scandir.c seekdir.c sethostname.c setjmperr.c \
- setmode.c siginterrupt.c siglist.c signal.c \
- sigsetops.c sleep.c sysconf.c sysctl.c syslog.c telldir.c \
- termios.c time.c times.c timezone.c ttyname.c ttyslot.c ualarm.c \
- uname.c unvis.c usleep.c utime.c valloc.c vis.c wait.c wait3.c \
- waitpid.c
+SRCS+= alarm.c arc4random.c assert.c clock.c closedir.c config.c confstr.c \
+ crypt.c ctermid.c daemon.c devname.c disklabel.c err.c errlst.c \
+ exec.c fnmatch.c frexp.c fstab.c fts.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 getpass.c getpwent.c getttyent.c \
+ getusershell.c getvfsbyname.c getvfsent.c glob.c \
+ initgroups.c isatty.c msgctl.c \
+ msgget.c msgrcv.c msgsnd.c nice.c nlist.c ntp_gettime.c opendir.c \
+ pause.c popen.c psignal.c pwcache.c raise.c readdir.c rewinddir.c \
+ scandir.c seekdir.c semconfig.c semctl.c semget.c semop.c \
+ setdomainname.c sethostname.c setjmperr.c setmode.c shmat.c \
+ shmctl.c shmdt.c shmget.c siginterrupt.c siglist.c signal.c \
+ sigsetops.c sleep.c stringlist.c sysconf.c sysctl.c sysctlbyname.c \
+ syslog.c telldir.c termios.c time.c times.c timezone.c ttyname.c \
+ ttyslot.c ualarm.c uname.c unvis.c usleep.c utime.c valloc.c vis.c \
+ wait.c wait3.c waitpid.c
+
+# *rand48 family, from 1.1.5
+SRCS+= _rand48.c drand48.c erand48.c jrand48.c lcong48.c lrand48.c \
+ mrand48.c nrand48.c seed48.c srand48.c
# machine-dependent gen sources
-.include "${.CURDIR}/${MACHINE}/gen/Makefile.inc"
+.include "${.CURDIR}/../libc/${MACHINE}/gen/Makefile.inc"
.if (${MACHINE} == "tahoe" || ${MACHINE} == "vax")
errlst.o errlst.po:
${CC} -S ${CFLAGS} ${.IMPSRC}
- ed - < ${.CURDIR}/${MACHINE}/:errfix errlst.s
+ ed - < ${.CURDIR}/../libc/${MACHINE}/:errfix errlst.s
${AS} -o ${.TARGET} errlst.s
rm -f errlst.s
.endif
-MAN3+= alarm.0 clock.0 confstr.0 crypt.0 ctermid.0 ctime.0 daemon.0 \
- devname.0 directory.0 err.0 exec.0 fnmatch.0 frexp.0 fts.0 \
- getbsize.0 getcap.0 getcwd.0 getdiskbyname.0 getfsent.0 \
- getgrent.0 getgrouplist.0 gethostname.0 getloadavg.0 \
- getmntinfo.0 getnetgrent.0 getpagesize.0 getpass.0 getpwent.0 \
- getttyent.0 getusershell.0 getvfsbyname.0 glob.0 initgroups.0 isinf.0 \
- ldexp.0 modf.0 nice.0 nlist.0 pause.0 popen.0 psignal.0 pwcache.0 \
- raise.0 realpath.0 scandir.0 setjmp.0 setmode.0 siginterrupt.0 \
- signal.0 sigsetops.0 sleep.0 sysconf.0 sysctl.0 syslog.0 tcgetpgrp.0 \
- tcsendbreak.0 tcsetattr.0 tcsetpgrp.0 time.0 times.0 timezone.0 \
- ttyname.0 tzset.0 ualarm.0 uname.0 unvis.0 usleep.0 utime.0 \
- valloc.0 vis.0
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN3+= gen/alarm.3 gen/arc4random.3 gen/clock.3 gen/confstr.3 \
+ gen/config_open.3 gen/crypt.3 gen/ctermid.3 \
+ gen/daemon.3 gen/devname.3 gen/directory.3 gen/err.3 gen/exec.3 \
+ gen/fnmatch.3 gen/frexp.3 gen/fts.3 gen/getbsize.3 gen/getbootfile.3 \
+ gen/getcap.3 gen/getcwd.3 gen/getdiskbyname.3 gen/getdomainname.3 \
+ gen/getfsent.3 gen/getgrent.3 gen/getgrouplist.3 gen/gethostname.3 \
+ gen/getloadavg.3 \
+ gen/getmntinfo.3 gen/getnetgrent.3 gen/getpagesize.3 gen/getpass.3 \
+ gen/getpwent.3 gen/getttyent.3 gen/getusershell.3 gen/getvfsbyname.3 \
+ gen/getvfsent.3 gen/glob.3 \
+ gen/initgroups.3 gen/isinf.3 gen/ldexp.3 \
+ gen/msgctl.3 gen/msgget.3 gen/msgrcv.3 gen/msgsnd.3 \
+ gen/modf.3 gen/nice.3 \
+ gen/nlist.3 gen/pause.3 gen/popen.3 gen/psignal.3 gen/pwcache.3 \
+ gen/raise.3 gen/rand48.3 \
+ gen/scandir.3 gen/setjmp.3 gen/setmode.3 \
+ gen/siginterrupt.3 gen/signal.3 gen/sigsetops.3 gen/sleep.3 \
+ gen/stringlist.3 \
+ gen/sysconf.3 gen/sysctl.3 gen/syslog.3 gen/tcgetpgrp.3 \
+ gen/tcsendbreak.3 gen/tcsetattr.3 gen/tcsetpgrp.3 gen/time.3 \
+ gen/times.3 gen/timezone.3 gen/ttyname.3 gen/tzset.3 gen/ualarm.3 \
+ gen/uname.3 gen/unvis.3 gen/usleep.3 gen/utime.3 gen/valloc.3 gen/vis.3
-MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3
-MLINKS+=ctime.3 asctime.3 ctime.3 difftime.3 ctime.3 gmtime.3 \
- ctime.3 localtime.3 ctime.3 mktime.3
+MLINKS+=arc4random.3 arc4random_stir.3 arc4random.3 arc4random_addrandom.3
+MLINKS+=config_open.3 config_next.3 config_open.3 config_close.3 \
+ config_open.3 config_skip.3
+MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 crypt.3 des_setkey.3 \
+ crypt.3 des_cipher.3
MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \
directory.3 readdir.3 directory.3 rewinddir.3 directory.3 seekdir.3 \
directory.3 telldir.3
MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 execv.3 \
- exec.3 execvp.3
+ exec.3 execvp.3 exec.3 exect.3
MLINKS+=err.3 verr.3 err.3 errx.3 err.3 verrx.3 err.3 warn.3 err.3 vwarn.3 \
- err.3 warnx.3 err.3 vwarnx.3
+ err.3 warnx.3 err.3 vwarnx.3 err.3 err_set_file.3 \
+ err.3 err_set_exit.3
MLINKS+=isinf.3 isnan.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 \
@@ -60,18 +84,28 @@ MLINKS+=getcwd.3 getwd.3
MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \
getfsent.3 getfstype.3 getfsent.3 setfsent.3
MLINKS+=getgrent.3 endgrent.3 getgrent.3 setgroupent.3 getgrent.3 getgrgid.3 \
- getgrent.3 getgrnam.3 getgrent.3 setgrent.3 getgrent.3 setgrfile.3
+ getgrent.3 getgrnam.3 getgrent.3 setgrent.3
MLINKS+=gethostname.3 sethostname.3
+MLINKS+=getdomainname.3 setdomainname.3
MLINKS+=getnetgrent.3 endnetgrent.3 getnetgrent.3 setnetgrent.3 \
getnetgrent.3 innetgr.3
MLINKS+=getpwent.3 endpwent.3 getpwent.3 setpassent.3 getpwent.3 getpwnam.3 \
getpwent.3 getpwuid.3 getpwent.3 setpwent.3 getpwent.3 setpwfile.3
-MLINKS+=getttyent.3 endttyent.3 getttyent.3 getttynam.3 getttyent.3 setttyent.3
+MLINKS+=getttyent.3 endttyent.3 getttyent.3 getttynam.3 \
+ getttyent.3 setttyent.3 getttyent.3 isdialuptty.3 \
+ getttyent.3 isnetworktty.3
+MLINKS+=getvfsent.3 getvfsbytype.3 \
+ getvfsent.3 setvfsent.3 getvfsent.3 endvfsent.3 \
+ getvfsent.3 vfsisloadable.3 getvfsent.3 vfsload.3
MLINKS+=getusershell.3 endusershell.3 getusershell.3 setusershell.3
MLINKS+=glob.3 globfree.3
MLINKS+=popen.3 pclose.3
-MLINKS+=psignal.3 sys_siglist.3
+MLINKS+=psignal.3 sys_siglist.3 psignal.3 sys_signame.3
MLINKS+=pwcache.3 user_from_uid.3 pwcache.3 group_from_gid.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+=setjmp.3 _longjmp.3 setjmp.3 _setjmp.3 setjmp.3 longjmp.3 \
setjmp.3 longjmperr.3 setjmp.3 longjmperror.3 \
@@ -90,3 +124,7 @@ MLINKS+=tcsetattr.3 tcgetattr.3 tcsetattr.3 cfsetospeed.3 \
MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyslot.3
MLINKS+=tzset.3 tzsetwall.3
MLINKS+=vis.3 strvis.3 vis.3 strvisx.3
+MLINKS+=unvis.3 strunvis.3
+MLINKS+=fts.3 fts_open.3 fts.3 fts_read.3 fts.3 fts_children.3 \
+ fts.3 fts_close.3 fts.3 fts_set.3
+.endif
diff --git a/lib/libc/gen/__xuname.c b/lib/libc/gen/__xuname.c
new file mode 100644
index 0000000..25431d4
--- /dev/null
+++ b/lib/libc/gen/__xuname.c
@@ -0,0 +1,125 @@
+/*-
+ * Copyright (c) 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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[] = "From: @(#)uname.c 8.1 (Berkeley) 1/4/94";*/
+static const char rcsid[] =
+ "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/utsname.h>
+#include <errno.h>
+
+int
+uname(name)
+ struct utsname *name;
+{
+ int mib[2], rval;
+ size_t len;
+ char *p;
+ int oerrno;
+
+ rval = 0;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_OSTYPE;
+ len = sizeof(name->sysname);
+ oerrno = errno;
+ if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1) {
+ if(errno == ENOMEM)
+ errno = oerrno;
+ else
+ rval = -1;
+ }
+ name->sysname[sizeof(name->sysname) - 1] = '\0';
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_HOSTNAME;
+ len = sizeof(name->nodename);
+ oerrno = errno;
+ if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1) {
+ if(errno == ENOMEM)
+ errno = oerrno;
+ else
+ rval = -1;
+ }
+ name->nodename[sizeof(name->nodename) - 1] = '\0';
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_OSRELEASE;
+ len = sizeof(name->release);
+ oerrno = errno;
+ if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1) {
+ if(errno == ENOMEM)
+ errno = oerrno;
+ else
+ rval = -1;
+ }
+ name->release[sizeof(name->release) - 1] = '\0';
+
+ /* The version may have newlines in it, turn them into spaces. */
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_VERSION;
+ len = sizeof(name->version);
+ oerrno = errno;
+ if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) {
+ if (errno == ENOMEM)
+ errno = oerrno;
+ else
+ rval = -1;
+ }
+ name->version[sizeof(name->version) - 1] = '\0';
+ for (p = name->version; len--; ++p) {
+ if (*p == '\n' || *p == '\t') {
+ if (len > 1)
+ *p = ' ';
+ else
+ *p = '\0';
+ }
+ }
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_MACHINE;
+ len = sizeof(name->machine);
+ oerrno = errno;
+ if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) {
+ if (errno == ENOMEM)
+ errno = oerrno;
+ else
+ rval = -1;
+ }
+ name->machine[sizeof(name->machine) - 1] = '\0';
+ return (rval);
+}
diff --git a/lib/libc/gen/_rand48.c b/lib/libc/gen/_rand48.c
new file mode 100644
index 0000000..990e2c8
--- /dev/null
+++ b/lib/libc/gen/_rand48.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#include "rand48.h"
+
+unsigned short _rand48_seed[3] = {
+ RAND48_SEED_0,
+ RAND48_SEED_1,
+ RAND48_SEED_2
+};
+unsigned short _rand48_mult[3] = {
+ RAND48_MULT_0,
+ RAND48_MULT_1,
+ RAND48_MULT_2
+};
+unsigned short _rand48_add = RAND48_ADD;
+
+void
+_dorand48(unsigned short xseed[3])
+{
+ unsigned long accu;
+ unsigned short temp[2];
+
+ accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] +
+ (unsigned long) _rand48_add;
+ temp[0] = (unsigned short) accu; /* lower 16 bits */
+ accu >>= sizeof(unsigned short) * 8;
+ accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] +
+ (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0];
+ temp[1] = (unsigned short) accu; /* middle 16 bits */
+ accu >>= sizeof(unsigned short) * 8;
+ accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0];
+ xseed[0] = temp[0];
+ xseed[1] = temp[1];
+ xseed[2] = (unsigned short) accu;
+}
diff --git a/lib/libc/gen/alarm.3 b/lib/libc/gen/alarm.3
index fb1893f..4d99fa1 100644
--- a/lib/libc/gen/alarm.3
+++ b/lib/libc/gen/alarm.3
@@ -39,8 +39,8 @@
.Nd set signal timer alarm
.Sh SYNOPSIS
.Fd #include <unistd.h>
-.Ft u_int
-.Fn alarm "u_int seconds"
+.Ft unsigned int
+.Fn alarm "unsigned int seconds"
.Sh DESCRIPTION
.Bf -symbolic
This interface is made obsolete by setitimer(2).
@@ -48,37 +48,42 @@ This interface is made obsolete by setitimer(2).
.Pp
The
.Fn alarm
-function
-waits a count of
-.Ar seconds
-before asserting the terminating signal
-.Dv SIGALRM .
-When the signal has successfully been caught,
+function sets a timer to deliver the signal
+.Dv SIGALRM
+to the calling process after the specified number of
+.Fa seconds .
+If an alarm has already been set with
+.Fn alarm
+but has not been delivered, another call to
.Fn alarm
-returns the amount of time left on the clock.
-The maximum number of
+will supersede the prior call.
+The request
+.Fn alarm "0"
+voids the current
+alarm and the signal SIGALRM will not be delivered. The maximum number of
.Ar seconds
allowed
is 2147483647.
.Pp
-If an alarm has been set with
-.Fn alarm ,
-another call to
+The return value of
.Fn alarm
-will supersede the prior call.
-The request
-.Fn alarm "0"
-voids the current
-alarm.
+is the amount of time left on the timer from a previous call to
+.Fn alarm .
+If no alarm is currently set, the return value is 0.
.Sh SEE ALSO
-.Xr sigaction 2 ,
.Xr setitimer 2 ,
+.Xr sigaction 2 ,
.Xr sigpause 2 ,
.Xr sigvec 2 ,
.Xr signal 3 ,
.Xr sleep 3 ,
.Xr ualarm 3 ,
.Xr usleep 3
+.\" .Sh STANDARDS
+.\" The
+.\" .Fn alarm
+.\" function conforms to
+.\" .St -p1003.1-90 .
.Sh HISTORY
An
.Fn alarm
diff --git a/lib/libc/gen/arc4random.3 b/lib/libc/gen/arc4random.3
new file mode 100644
index 0000000..25c6d4d
--- /dev/null
+++ b/lib/libc/gen/arc4random.3
@@ -0,0 +1,83 @@
+.\" $OpenBSD: arc4random.3,v 1.2 1997/04/27 22:40:25 angelos Exp $
+.\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Niels Provos.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"
+.\" Manual page, using -mandoc macros
+.\"
+.Dd April 15, 1997
+.Dt ARC4RANDOM 3
+.Os
+.Sh NAME
+.Nm arc4random,
+.Nm arc4random_stir,
+.Nm arc4random_addrandom
+.Nd arc4 random number generator.
+.Sh SYNOPSIS
+.Fd #include <stdlib.h>
+.Ft u_int32_t
+.Fn arc4random "void"
+.Ft void
+.Fn arc4random_stir "void"
+.Ft void
+.Fn arc4random_addrandom "unsigned char *dat" "int datlen"
+.Sh DESCRIPTION
+The
+.Fn arc4random
+function uses the key stream generator employed by the
+arc4 cipher, which uses 8*8 8 bit S-Boxes. The S-Boxes
+can be in about
+.if t 2\u\s71700\s10\d
+.if n (2**1700)
+states.
+.Pp
+The
+.Fn arc4random_stir
+function reads data from
+.Pa /dev/urandom
+and uses it to permutate the S-Boxes via
+.Fn arc4random_addrandom .
+.Pp
+There is no need to call
+.Fn arc4random_stir
+before using
+.Fn arc4random ,
+since
+.Fn arc4random
+automatically initalizes itself.
+.Sh SEE ALSO
+.Xr rand 3 ,
+.Xr random 3 ,
+.Xr srandomdev 3
+.Sh HISTORY
+.Pa RC4
+has been designed by RSA Data Security, Inc. It was posted anonymously
+to the USENET and was confirmed to be equivalent by several sources who
+had access to the original cipher. Since
+.Pa RC4
+used to be a trade secret, the cipher is now refered to as
+.Pa ARC4 .
diff --git a/lib/libc/gen/arc4random.c b/lib/libc/gen/arc4random.c
new file mode 100644
index 0000000..b9f8a48
--- /dev/null
+++ b/lib/libc/gen/arc4random.c
@@ -0,0 +1,172 @@
+/* $Id: arc4random.c,v 1.1 1996/12/28 06:33:01 dm Exp $ */
+
+/*
+ * Arc4 random number generator for OpenBSD.
+ * Copyright 1996 David Mazieres <dm@lcs.mit.edu>.
+ *
+ * Modification and redistribution in source and binary forms is
+ * permitted provided that due credit is given to the author and the
+ * OpenBSD project (for instance by leaving this copyright notice
+ * intact).
+ */
+
+/*
+ * This code is derived from section 17.1 of Applied Cryptography,
+ * second edition, which describes a stream cipher allegedly
+ * compatible with RSA Labs "RC4" cipher (the actual description of
+ * which is a trade secret). The same algorithm is used as a stream
+ * cipher called "arcfour" in Tatu Ylonen's ssh package.
+ *
+ * Here the stream cipher has been modified always to include the time
+ * when initializing the state. That makes it impossible to
+ * regenerate the same random sequence twice, so this can't be used
+ * for encryption, but will generate good random numbers.
+ *
+ * RC4 is a registered trademark of RSA Laboratories.
+ */
+
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+struct arc4_stream {
+ u_int8_t i;
+ u_int8_t j;
+ u_int8_t s[256];
+};
+
+static int rs_initialized;
+static struct arc4_stream rs;
+
+static inline void
+arc4_init(as)
+ struct arc4_stream *as;
+{
+ int n;
+
+ for (n = 0; n < 256; n++)
+ as->s[n] = n;
+ as->i = 0;
+ as->j = 0;
+}
+
+static inline void
+arc4_addrandom(as, dat, datlen)
+ struct arc4_stream *as;
+ u_char *dat;
+ int datlen;
+{
+ int n;
+ u_int8_t si;
+
+ as->i--;
+ for (n = 0; n < 256; n++) {
+ as->i = (as->i + 1);
+ si = as->s[as->i];
+ as->j = (as->j + si + dat[n % datlen]);
+ as->s[as->i] = as->s[as->j];
+ as->s[as->j] = si;
+ }
+}
+
+static void
+arc4_stir(as)
+ struct arc4_stream *as;
+{
+ int fd;
+ struct {
+ struct timeval tv;
+ pid_t pid;
+ u_int8_t rnd[128 - sizeof(struct timeval) - sizeof(pid_t)];
+ } rdat;
+
+ gettimeofday(&rdat.tv, NULL);
+ rdat.pid = getpid();
+ fd = open("/dev/urandom", O_RDONLY, 0);
+ if (fd >= 0) {
+ (void) read(fd, rdat.rnd, sizeof(rdat.rnd));
+ close(fd);
+ }
+ /* fd < 0? Ah, what the heck. We'll just take whatever was on the
+ * stack... */
+
+ arc4_addrandom(as, (void *) &rdat, sizeof(rdat));
+}
+
+static inline u_int8_t
+arc4_getbyte(as)
+ struct arc4_stream *as;
+{
+ u_int8_t si, sj;
+
+ as->i = (as->i + 1);
+ si = as->s[as->i];
+ as->j = (as->j + si);
+ sj = as->s[as->j];
+ as->s[as->i] = sj;
+ as->s[as->j] = si;
+ return (as->s[(si + sj) & 0xff]);
+}
+
+static inline u_int32_t
+arc4_getword(as)
+ struct arc4_stream *as;
+{
+ u_int32_t val;
+ val = arc4_getbyte(as) << 24;
+ val |= arc4_getbyte(as) << 16;
+ val |= arc4_getbyte(as) << 8;
+ val |= arc4_getbyte(as);
+ return val;
+}
+
+void
+arc4random_stir()
+{
+ if (!rs_initialized) {
+ arc4_init(&rs);
+ rs_initialized = 1;
+ }
+ arc4_stir(&rs);
+}
+
+void
+arc4random_addrandom(dat, datlen)
+ u_char *dat;
+ int datlen;
+{
+ if (!rs_initialized)
+ arc4random_stir();
+ arc4_addrandom(&rs, dat, datlen);
+}
+
+u_int32_t
+arc4random()
+{
+ if (!rs_initialized)
+ arc4random_stir();
+ return arc4_getword(&rs);
+}
+
+#if 0
+/*-------- Test code for i386 --------*/
+#include <stdio.h>
+#include <machine/pctr.h>
+int
+main(int argc, char **argv)
+{
+ const int iter = 1000000;
+ int i;
+ pctrval v;
+
+ v = rdtsc();
+ for (i = 0; i < iter; i++)
+ arc4random();
+ v = rdtsc() - v;
+ v /= iter;
+
+ printf("%qd cycles\n", v);
+}
+#endif
diff --git a/lib/libc/gen/assert.c b/lib/libc/gen/assert.c
index 4914aca..eb2748c 100644
--- a/lib/libc/gen/assert.c
+++ b/lib/libc/gen/assert.c
@@ -35,7 +35,6 @@
static char sccsid[] = "@(#)assert.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/types.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/clock.3 b/lib/libc/gen/clock.3
index f70184e..0e5ad06 100644
--- a/lib/libc/gen/clock.3
+++ b/lib/libc/gen/clock.3
@@ -42,7 +42,7 @@
.Nm clock
.Nd determine processor time used
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
+.Fd #include <time.h>
.Ft clock_t
.Fn clock void
.Sh DESCRIPTION
@@ -51,14 +51,16 @@ The
function
determines the amount of processor time used since the invocation of the
calling process, measured in
-.Dv CLK_TCK Ns s.
+.Dv CLOCKS_PER_SEC Ns 's
+of a second.
.Sh RETURN VALUES
The
.Fn clock
function returns the amount of time used unless an error occurs, in which
case the return value is \-1.
.Sh SEE ALSO
-.Xr getrusage 2
+.Xr getrusage 2 ,
+.Xr clocks 7
.Sh STANDARDS
The
.Fn clock
diff --git a/lib/libc/gen/clock.c b/lib/libc/gen/clock.c
index 12dc866..fe867c2 100644
--- a/lib/libc/gen/clock.c
+++ b/lib/libc/gen/clock.c
@@ -40,10 +40,11 @@ static char sccsid[] = "@(#)clock.c 8.1 (Berkeley) 6/4/93";
#include <sys/resource.h>
/*
- * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000,
+ * Convert usec to clock ticks; could do (usec * CLOCKS_PER_SEC) / 1000000,
* but this would overflow if we switch to nanosec.
*/
-#define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK))
+#define CONVTCK(r) ((r).tv_sec * CLOCKS_PER_SEC \
+ + (r).tv_usec / (1000000 / CLOCKS_PER_SEC))
clock_t
clock()
diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c
index d3fc00b..6c46e70 100644
--- a/lib/libc/gen/closedir.c
+++ b/lib/libc/gen/closedir.c
@@ -40,6 +40,8 @@ static char sccsid[] = "@(#)closedir.c 8.1 (Berkeley) 6/10/93";
#include <stdlib.h>
#include <unistd.h>
+extern void _reclaim_telldir __P(( const DIR * ));
+
/*
* close a directory.
*/
@@ -53,7 +55,8 @@ closedir(dirp)
fd = dirp->dd_fd;
dirp->dd_fd = -1;
dirp->dd_loc = 0;
- (void)free((void *)dirp->dd_buf);
- (void)free((void *)dirp);
+ free((void *)dirp->dd_buf);
+ free((void *)dirp);
+ _reclaim_telldir(dirp);
return(close(fd));
}
diff --git a/lib/libc/gen/config.c b/lib/libc/gen/config.c
new file mode 100644
index 0000000..2d1ed44
--- /dev/null
+++ b/lib/libc/gen/config.c
@@ -0,0 +1,187 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
+ *
+ * $Id$
+ *
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * This file contains four procedures used to read config-files.
+ *
+ * char * config_open(const char *filename,int contlines)
+ * Will open the named file, read it into a private malloc'ed area,
+ * and close the file again.
+ * All lines where the first !isspace() char is '#' are deleted.
+ * If contlines are non-zero lines where the first char is isspace()
+ * will be joined to the preceeding line.
+ * In case of trouble the name of the offending system call will be
+ * returned. On success NULL is returned.
+ *
+ * void config_close()
+ * This will free the internal malloc'ed area.
+ *
+ * char * config_next()
+ * This will return a pointer to the next entry in the area. NULL is
+ * returned at "end of file". The return value is '\0' terminated, and
+ * can be modified, but the contents must be copied somewhere else for
+ * permanent use.
+ *
+ * char * config_skip(char **p)
+ * This will pick out the next word from the string. The return-value
+ * points to the word found, and *p is advanced past the word. NULL is
+ * returned at "end of string".
+ *
+ * Many programs have a n*100 bytes config-file and N*1000 bytes of source
+ * to read it. Doing pointer-aerobics on files that small is a waste of
+ * time, and bashing around with getchar/ungetc isn't much better. These
+ * routines implement a simple algorithm and syntax.
+ *
+ * config_skip consider a contiguous string of !isspace() chars a word.
+ *
+ * 13nov1994 Poul-Henning Kamp phk@login.dknet.dk
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <string.h>
+
+static char *file_buf;
+static char *ptr;
+
+char *
+config_open(const char *filename, int contlines)
+{
+ int fd;
+ struct stat st;
+ char *p, *q;
+
+ if ((fd = open(filename, O_RDONLY)) < 0)
+ return "open";
+ if (fstat(fd, &st) < 0) {
+ close(fd);
+ return "fstat";
+ }
+ if (file_buf)
+ free(file_buf);
+ file_buf = malloc(st.st_size + 2);
+ if (!file_buf) {
+ close(fd);
+ return "malloc";
+ }
+ if (st.st_size != read(fd, file_buf, st.st_size)) {
+ free(file_buf);
+ file_buf = (char *) 0;
+ close(fd);
+ return "read";
+ }
+ close(fd);
+ file_buf[st.st_size] = '\n';
+ file_buf[st.st_size + 1] = '\0';
+
+ /*
+ * /^[ \t]*#[^\n]*$/d
+ *
+ * Delete all lines where the first !isspace() char is '#'
+ */
+
+ ptr = file_buf;
+ for (p = ptr; *p;) {
+ for (q = p; *q != '\n' && isspace(*q); q++)
+ continue;
+ if (*q == '#') {
+ p = strchr(p, '\n');
+ if (p)
+ p++;
+ } else {
+ q = strchr(p, '\n');
+ q++;
+ memcpy(ptr, p, q - p);
+ ptr += q - p;
+ p = q;
+ }
+ }
+ *ptr = '\0';
+ ptr = file_buf;
+
+ if (!contlines)
+ return 0;
+
+ /* Join all lines starting with a isspace() char to the preceeding
+ * line */
+
+ for (p = ptr; *p;) {
+ q = strchr(p, '\n');
+ if (isspace(*(q + 1)))
+ *q = ' ';
+ p = q + 1;
+ }
+
+ return 0;
+}
+
+void
+config_close(void)
+{
+ if (file_buf)
+ free(file_buf);
+ ptr = file_buf = 0;
+}
+
+/*
+ * Get next entry. config_open did all the weird stuff, so just return
+ * the next line.
+ */
+
+char *
+config_next(void)
+{
+ char *p;
+
+ /* We might be done already ! */
+ if (!ptr || !*ptr)
+ return 0;
+
+ while (isspace(*ptr))
+ ptr++;
+ p = ptr;
+ ptr = strchr(p, '\n');
+ if (ptr) {
+ *ptr = '\0';
+ ptr++;
+ }
+ return p;
+}
+
+/*
+ * Return next word
+ */
+
+char *
+config_skip(char **p)
+{
+ char *q, *r;
+
+ if (!*p || !**p)
+ return 0;
+ for (q = *p; isspace(*q); q++);
+ if (!*q)
+ return 0;
+ for (r = q; *r && !isspace(*r); r++);
+ if (*r)
+ *r++ = '\0';
+ *p = r;
+ return q;
+}
diff --git a/lib/libc/gen/config_open.3 b/lib/libc/gen/config_open.3
new file mode 100644
index 0000000..a2ef707
--- /dev/null
+++ b/lib/libc/gen/config_open.3
@@ -0,0 +1,73 @@
+.\" ----------------------------------------------------------------------------
+.\" "THE BEER-WARE LICENSE" (Revision 42):
+.\" <phk@login.dknet.dk> wrote this file. As long as you retain this notice you
+.\" can do whatever you want with this stuff. If we meet some day, and you think
+.\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
+.\" ----------------------------------------------------------------------------
+.\"
+.\" $Id$
+.\"
+.Dd November 13, 1994
+.Dt config_open 3
+.Os FreeBSD
+.Sh NAME
+.Nm config_open ,
+.Nm config_close ,
+.Nm config_next ,
+.Nm config_skip
+.Nd read config files
+.Sh SYNOPSIS
+.Ft char *
+.Fn config_open "const char *filename" "int contlines"
+.Ft void
+.Fn config_close
+.Ft char *
+.Fn config_next
+.Ft char *
+.Fn config_skip "char **string"
+.Sh DESCRIPTION
+These functions are used to read config files with the following syntax:
+.Bl -bullet -compact
+.It
+All lines where the first
+.Sq !isspace()
+is '#' are comments which are discarded.
+.It
+If continuation-lines are enabled, any line starting with a
+.Sq isspace()
+character is joined to the preceding line and blank lines are discarded.
+.It
+An entry starts at the first
+.Sq !isspace()
+character and ends at the first
+.Sq Li \en
+.Li .
+.El
+.Pp
+.Fn config_open
+will open the specified
+.Fa filename
+and read it into a private malloced area, and close the file again. If
+.Fa contlines
+is non-zero, continuation lines will be allowed.
+In case of trouble, the name of the system-call causing the trouble will
+be returned. If successful,
+.Fn config_open
+returns NULL.
+.Pp
+.Fn config_close
+will free the malloced area.
+.Pp
+.Fn config_next
+returns the next entry in the area. NULL is returned to indicate End-of-file.
+The returned string is null-terminated.
+.Pp
+.Fn config_skip
+returns the next word from the string
+.Fa *string
+.Li .
+.Fa *string
+will be advanced to point to the next word.
+NULL is returned to indicate the end of the string.
+.Sh AUTHOR
+Poul-Henning Kamp <phk@login.dknet.dk>
diff --git a/lib/libc/gen/confstr.3 b/lib/libc/gen/confstr.3
index 8714452..90115e3 100644
--- a/lib/libc/gen/confstr.3
+++ b/lib/libc/gen/confstr.3
@@ -43,7 +43,8 @@
.Fn confstr "int name" "char *buf" "size_t len"
.Sh DESCRIPTION
.Bf -symbolic
-This interface is obsoleted by sysctl(3).
+This interface is obsoleted by
+.Xr sysctl 3 .
.Ef
.Pp
The
@@ -84,7 +85,7 @@ environment variable that finds all the standard utilities.
.El
.Sh RETURN VALUES
If the call to
-.Nm confstr
+.Fn confstr
is not successful, \-1 is returned and
.Va errno
is set appropriately.
@@ -101,7 +102,7 @@ the string in
was truncated.
.Sh ERRORS
The
-.Nm confstr
+.Fn confstr
function may fail and set
.Va error
for any of the errors specified for the library functions
@@ -119,5 +120,6 @@ argument is invalid.
.Xr sysctl 3
.Sh HISTORY
The
-.Nm confstr
-function first appeared in 4.4BSD.
+.Fn confstr
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/confstr.c b/lib/libc/gen/confstr.c
index cc4df53..0a7078e 100644
--- a/lib/libc/gen/confstr.c
+++ b/lib/libc/gen/confstr.c
@@ -42,6 +42,7 @@ static char sccsid[] = "@(#)confstr.c 8.1 (Berkeley) 6/4/93";
#include <paths.h>
#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
size_t
confstr(name, buf, len)
diff --git a/lib/libc/gen/crypt.3 b/lib/libc/gen/crypt.3
index 7ecf0cf..0f97a70 100644
--- a/lib/libc/gen/crypt.3
+++ b/lib/libc/gen/crypt.3
@@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)crypt.3 8.1.1.1 (Berkeley) 8/18/93
+.\" @(#)crypt.3 8.2 (Berkeley) 12/11/93
.\"
-.Dd August 18, 1993
+.Dd December 11, 1993
.Dt CRYPT 3
.Os
.Sh NAME
@@ -42,10 +42,11 @@
.Nm des_cipher
.Nd DES encryption
.Sh SYNOPSIS
-.Ft char
-.Fn *crypt "const char *key" "const char *setting"
+.Fd #include <unistd.h>
+.Ft char *
+.Fn crypt "const char *key" "const char *setting"
.Ft int
-.Fn setkey "char *key"
+.Fn setkey "const char *key"
.Ft int
.Fn encrypt "char *block" "int flag"
.Ft int
@@ -54,7 +55,7 @@
.Fn des_cipher "const char *in" "char *out" "long salt" "int count"
.Sh DESCRIPTION
The
-.Xr crypt
+.Fn crypt
function
performs password encryption.
It is derived from the
@@ -161,8 +162,9 @@ If the value of
is 0,
the argument
.Fa block
-is encrypted, otherwise it fails.
-The encryption is returned in the original
+is encrypted, otherwise it
+is decrypted.
+The encryption or decryption is returned in the original
array
.Fa block
after using the
@@ -188,7 +190,9 @@ significant bit in each character is ignored and the next 7 bits of each
character are concatenated to yield a 56-bit key.
The function
.Fn des_cipher
-encrypts the 64-bits stored in the 8 characters at
+encrypts (or decrypts if
+.Fa count
+is negative) the 64-bits stored in the 8 characters at
.Fa in
using
.Xr abs 3
@@ -223,12 +227,27 @@ They have been provided return values primarily to distinguish
implementations where hardware support is provided but not
available or where the DES encryption is not available due to the
usual political silliness.
+.Pp
+Use of
+.Fn crypt
+requires linking with the
+.Nm libcrypt
+library. The
+.Fn setkey ,
+.Fn encrypt ,
+.Fn des_setkey
+and
+.Fn des_cipher
+can be found in the
+.Nm libcipher
+library (the standard C library,
+.Nm libc ,
+only contains stubs to these routines).
.Sh SEE ALSO
.Xr login 1 ,
.Xr passwd 1 ,
.Xr getpass 3 ,
.Xr passwd 5
-.sp
.Rs
.%T "Mathematical Cryptology for Computer Scientists and Mathematicians"
.%A Wayne Patterson
diff --git a/lib/libc/gen/crypt.c b/lib/libc/gen/crypt.c
index 1aad9c6..c1417b8 100644
--- a/lib/libc/gen/crypt.c
+++ b/lib/libc/gen/crypt.c
@@ -36,19 +36,24 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from static char sccsid[] = "@(#)crypt.c 5.11 (Berkeley) 6/25/91"; */
-static char rcsid[] = "$Header: /a/cvs/386BSD/src/lib/libc/gen/crypt.c,v 1.6 1993/08/29 22:03:56 nate Exp $";
+static char rcsid[] = "$Header: /home/ncvs/src/lib/libc/gen/crypt.c,v 1.3 1995/05/30 05:40:10 rgrimes Exp $";
#endif /* LIBC_SCCS and not lint */
#include <unistd.h>
#include <stdio.h>
+#include <string.h>
/*
* UNIX password, and DES, encryption.
- *
+ *
* since this is non-exportable, this is just a dummy. if you want real
* encryption, make sure you've got libcrypt.a around.
*/
+__warn_references(des_setkey,
+ "WARNING! des_setkey(3) not present in the system!");
+
+int
des_setkey(key)
register const char *key;
{
@@ -56,6 +61,10 @@ des_setkey(key)
return (0);
}
+__warn_references(des_cipher,
+ "WARNING! des_cipher(3) not present in the system!");
+
+int
des_cipher(in, out, salt, num_iter)
const char *in;
char *out;
@@ -67,6 +76,10 @@ des_cipher(in, out, salt, num_iter)
return (0);
}
+__warn_references(setkey,
+ "WARNING! setkey(3) not present in the system!");
+
+int
setkey(key)
register const char *key;
{
@@ -74,6 +87,10 @@ setkey(key)
return (0);
}
+__warn_references(encrypt,
+ "WARNING! encrypt(3) not present in the system!");
+
+int
encrypt(block, flag)
register char *block;
int flag;
diff --git a/lib/libc/gen/ctermid.3 b/lib/libc/gen/ctermid.3
index ff92420..2e3e9e6 100644
--- a/lib/libc/gen/ctermid.3
+++ b/lib/libc/gen/ctermid.3
@@ -80,7 +80,7 @@ The current implementation detects no error conditions.
.Xr ttyname 3
.Sh STANDARDS
The
-.Xr ctermid
+.Fn ctermid
function conforms to
.St -p1003.1-88 .
.Sh BUGS
diff --git a/lib/libc/gen/daemon.3 b/lib/libc/gen/daemon.3
index 1905923..afbbee2 100644
--- a/lib/libc/gen/daemon.3
+++ b/lib/libc/gen/daemon.3
@@ -37,6 +37,8 @@
.Nm daemon
.Nd run in the background
.Sh SYNOPSIS
+.Fd #include <stdlib.h>
+.Ft int
.Fn daemon "int nochdir" "int noclose"
.Sh DESCRIPTION
.Pp
@@ -58,17 +60,19 @@ is non-zero,
will redirect standard input, standard output and standard error
to ``/dev/null''.
.Sh ERRORS
-The function
+If an error occurs,
.Fn daemon
-may fail and set
+returns -1 and sets the global variable
.Va errno
-for any of the errors specified for the library functions
+to any of the errors specified for the library functions
.Xr fork 2
and
.Xr setsid 2 .
.Sh SEE ALSO
+.Xr fork 2 ,
.Xr setsid 2
.Sh HISTORY
The
.Fn daemon
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/devname.3 b/lib/libc/gen/devname.3
index 49fcc78..8f9ad92 100644
--- a/lib/libc/gen/devname.3
+++ b/lib/libc/gen/devname.3
@@ -63,6 +63,6 @@ found is the string
.Xr dev_mkdb 8
.Sh HISTORY
The
-.Nm devname
+.Fn devname
function call appeared in
.Bx 4.4 .
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3
index 0503989..0abbe5f 100644
--- a/lib/libc/gen/directory.3
+++ b/lib/libc/gen/directory.3
@@ -151,7 +151,7 @@ returns the integer file descriptor associated with the named
see
.Xr open 2 .
.Pp
-Sample code which searchs a directory for entry ``name'' is:
+Sample code which searches a directory for entry ``name'' is:
.Bd -literal -offset indent
len = strlen(name);
dirp = opendir(".");
@@ -164,10 +164,10 @@ while ((dp = readdir(dirp)) != NULL)
return NOT_FOUND;
.Ed
.Sh SEE ALSO
-.Xr open 2 ,
.Xr close 2 ,
-.Xr read 2 ,
.Xr lseek 2 ,
+.Xr open 2 ,
+.Xr read 2 ,
.Xr dir 5
.Sh HISTORY
The
diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c
index eaefbab..b5cef89 100644
--- a/lib/libc/gen/disklabel.c
+++ b/lib/libc/gen/disklabel.c
@@ -32,7 +32,11 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)disklabel.c 8.2 (Berkeley) 5/3/95";
+#endif
+static const char rcsid[] =
+ "$Id: disklabel.c,v 1.5 1997/02/22 14:58:01 peter Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -47,8 +51,8 @@ static char sccsid[] = "@(#)disklabel.c 8.2 (Berkeley) 5/3/95";
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
-static int error __P((int));
static int gettype __P((char *, char **));
struct disklabel *
@@ -168,17 +172,3 @@ gettype(t, names)
return (atoi(t));
return (0);
}
-
-static int
-error(err)
- int err;
-{
- char *p;
-
- (void)write(STDERR_FILENO, "disktab: ", 9);
- (void)write(STDERR_FILENO, _PATH_DISKTAB, sizeof(_PATH_DISKTAB) - 1);
- (void)write(STDERR_FILENO, ": ", 2);
- p = strerror(err);
- (void)write(STDERR_FILENO, p, strlen(p));
- (void)write(STDERR_FILENO, "\n", 1);
-}
diff --git a/lib/libc/gen/drand48.c b/lib/libc/gen/drand48.c
new file mode 100644
index 0000000..cec04a6
--- /dev/null
+++ b/lib/libc/gen/drand48.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#include "rand48.h"
+
+extern unsigned short _rand48_seed[3];
+
+double
+drand48(void)
+{
+ return erand48(_rand48_seed);
+}
diff --git a/lib/libc/gen/erand48.c b/lib/libc/gen/erand48.c
new file mode 100644
index 0000000..286904c
--- /dev/null
+++ b/lib/libc/gen/erand48.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#include "rand48.h"
+
+double
+erand48(unsigned short xseed[3])
+{
+ _dorand48(xseed);
+ return ldexp((double) xseed[0], -48) +
+ ldexp((double) xseed[1], -32) +
+ ldexp((double) xseed[2], -16);
+}
diff --git a/lib/libc/gen/err.3 b/lib/libc/gen/err.3
index 2a3f4c3..aa340f6 100644
--- a/lib/libc/gen/err.3
+++ b/lib/libc/gen/err.3
@@ -29,9 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)err.3 8.1 (Berkeley) 6/9/93
+.\" From: @(#)err.3 8.1 (Berkeley) 6/9/93
+.\" $Id: err.3,v 1.6 1997/02/22 14:58:02 peter Exp $
.\"
-.Dd "June 9, 1993"
+.Dd April 13, 1995
.Dt ERR 3
.Os BSD 4
.Sh NAME
@@ -42,25 +43,32 @@
.Nm warn ,
.Nm vwarn ,
.Nm warnx ,
-.Nm vwarnx
+.Nm vwarnx ,
+.Nm err_set_file ,
+.Nm err_set_exit
.Nd formatted error messages
.Sh SYNOPSIS
.Fd #include <err.h>
.Ft void
.Fn err "int eval" "const char *fmt" "..."
.Ft void
-.Fn verr "int eval" "const char *fmt" "va_list args"
-.Ft void
.Fn errx "int eval" "const char *fmt" "..."
.Ft void
-.Fn verrx "int eval" "const char *fmt" "va_list args"
-.Ft void
.Fn warn "const char *fmt" "..."
.Ft void
-.Fn vwarn "const char *fmt" "va_list args"
-.Ft void
.Fn warnx "const char *fmt" "..."
.Ft void
+.Fn err_set_file "void *fp"
+.Ft void
+.Fn err_set_exit "void (*exitf)(int)"
+.Fd #include <stdarg.h>
+.Ft void
+.Fn verr "int eval" "const char *fmt" "va_list args"
+.Ft void
+.Fn verrx "int eval" "const char *fmt" "va_list args"
+.Ft void
+.Fn vwarn "const char *fmt" "va_list args"
+.Ft void
.Fn vwarnx "const char *fmt" "va_list args"
.Sh DESCRIPTION
The
@@ -68,7 +76,9 @@ The
and
.Fn warn
family of functions display a formatted error message on the standard
-error output.
+error output, or on another file specified using the
+.Fn err_set_file
+function.
In all cases, the last component of the program name, a colon character,
and a space are output.
If the
@@ -95,6 +105,13 @@ and
.Fn verrx
functions do not return, but exit with the value of the argument
.Fa eval .
+The
+.Fn err_set_exit
+function can be used to specify a function which is called before
+.Xr exit 3
+to perform any necessary cleanup; passing a null function pointer for
+.Va exitf
+resets the hook to do nothing.
.Sh EXAMPLES
Display the current errno information string and exit:
.Bd -literal -offset indent
@@ -119,10 +136,12 @@ if ((fd = open(block_device, O_RDONLY, 0)) == -1)
err(1, "%s", block_device);
.Ed
.Sh SEE ALSO
+.Xr exit 3 ,
.Xr strerror 3
.Sh HISTORY
The
.Fn err
and
.Fn warn
-functions first appeared in 4.4BSD.
+functions first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c
index 71cd1d9..bf7d347 100644
--- a/lib/libc/gen/err.c
+++ b/lib/libc/gen/err.c
@@ -49,7 +49,25 @@ static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
extern char *__progname; /* Program name, from crt0. */
-__dead void
+static FILE *err_file; /* file to use for error output */
+static void (*err_exit)(int);
+
+void
+err_set_file(void *fp)
+{
+ if (fp)
+ err_file = fp;
+ else
+ err_file = stderr;
+}
+
+void
+err_set_exit(void (*ef)(int))
+{
+ err_exit = ef;
+}
+
+void
#ifdef __STDC__
err(int eval, const char *fmt, ...)
#else
@@ -69,7 +87,7 @@ err(eval, fmt, va_alist)
va_end(ap);
}
-__dead void
+void
verr(eval, fmt, ap)
int eval;
const char *fmt;
@@ -78,16 +96,20 @@ verr(eval, fmt, ap)
int sverrno;
sverrno = errno;
- (void)fprintf(stderr, "%s: ", __progname);
+ if (! err_file)
+ err_set_file((FILE *)0);
+ (void)fprintf(err_file, "%s: ", __progname);
if (fmt != NULL) {
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, ": ");
+ (void)vfprintf(err_file, fmt, ap);
+ (void)fprintf(err_file, ": ");
}
- (void)fprintf(stderr, "%s\n", strerror(sverrno));
+ (void)fprintf(err_file, "%s\n", strerror(sverrno));
+ if(err_exit)
+ err_exit(eval);
exit(eval);
}
-__dead void
+void
#if __STDC__
errx(int eval, const char *fmt, ...)
#else
@@ -107,16 +129,20 @@ errx(eval, fmt, va_alist)
va_end(ap);
}
-__dead void
+void
verrx(eval, fmt, ap)
int eval;
const char *fmt;
va_list ap;
{
- (void)fprintf(stderr, "%s: ", __progname);
+ if (! err_file)
+ err_set_file((FILE *)0);
+ (void)fprintf(err_file, "%s: ", __progname);
if (fmt != NULL)
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, "\n");
+ (void)vfprintf(err_file, fmt, ap);
+ (void)fprintf(err_file, "\n");
+ if (err_exit)
+ err_exit(eval);
exit(eval);
}
@@ -147,12 +173,14 @@ vwarn(fmt, ap)
int sverrno;
sverrno = errno;
- (void)fprintf(stderr, "%s: ", __progname);
+ if (! err_file)
+ err_set_file((FILE *)0);
+ (void)fprintf(err_file, "%s: ", __progname);
if (fmt != NULL) {
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, ": ");
+ (void)vfprintf(err_file, fmt, ap);
+ (void)fprintf(err_file, ": ");
}
- (void)fprintf(stderr, "%s\n", strerror(sverrno));
+ (void)fprintf(err_file, "%s\n", strerror(sverrno));
}
void
@@ -179,8 +207,10 @@ vwarnx(fmt, ap)
const char *fmt;
va_list ap;
{
- (void)fprintf(stderr, "%s: ", __progname);
+ if (! err_file)
+ err_set_file((FILE *)0);
+ (void)fprintf(err_file, "%s: ", __progname);
if (fmt != NULL)
- (void)vfprintf(stderr, fmt, ap);
- (void)fprintf(stderr, "\n");
+ (void)vfprintf(err_file, fmt, ap);
+ (void)fprintf(err_file, "\n");
}
diff --git a/lib/libc/gen/exec.3 b/lib/libc/gen/exec.3
index 3438bec..367d71a 100644
--- a/lib/libc/gen/exec.3
+++ b/lib/libc/gen/exec.3
@@ -65,7 +65,7 @@ new process image.
The functions described in this manual page are front-ends for the function
.Xr execve 2 .
(See the manual page for
-.Xr execve
+.Xr execve 2
for detailed information about the replacement of the current process.)
.Pp
The initial argument for these functions is the pathname of a file which
@@ -148,7 +148,7 @@ used.
In addition, certain errors are treated specially.
.Pp
If permission is denied for a file (the attempted
-.Xr execve
+.Fn execve
returned
.Er EACCES ) ,
these functions will continue searching the rest of
@@ -159,7 +159,7 @@ set to
.Er EACCES .
.Pp
If the header of a file isn't recognized (the attempted
-.Xr execve
+.Fn execve
returned
.Er ENOEXEC ) ,
these functions will execute the shell with the path of
@@ -167,7 +167,7 @@ the file as its first argument.
(If this attempt fails, no further searching is done.)
.Pp
If the file is currently busy (the attempted
-.Xr execve
+.Fn execve
returned
.Er ETXTBUSY ) ,
these functions will sleep for several seconds,
@@ -179,13 +179,13 @@ executes a file with the program tracing facilities enabled (see
.Xr ptrace 2 ) .
.Sh RETURN VALUES
If any of the
-.Xr exec
+.Fn exec
functions returns, an error will have occurred.
The return value is \-1, and the global variable
.Va errno
will be set to indicate the error.
.Sh FILES
-.Bl -tag -width /bin/sh - compact
+.Bl -tag -width /bin/sh -compact
.It Pa /bin/sh
The shell.
.El
@@ -213,10 +213,9 @@ for any of the errors specified for the library function
.Xr sh 1 ,
.Xr execve 2 ,
.Xr fork 2 ,
-.Xr trace 2 ,
-.Xr environ 7 ,
+.Xr ktrace 2 ,
.Xr ptrace 2 ,
-.Xr environ 7 ,
+.Xr environ 7 .
.Sh COMPATIBILITY
Historically, the default path for the
.Fn execlp
diff --git a/lib/libc/gen/exec.c b/lib/libc/gen/exec.c
index 2f7eadd..72b6db4 100644
--- a/lib/libc/gen/exec.c
+++ b/lib/libc/gen/exec.c
@@ -58,19 +58,20 @@ buildargv(ap, arg, envpp)
const char *arg;
char ***envpp;
{
- static int memsize;
- static char **argv;
- register int off;
+ register char **argv, **nargv;
+ register int memsize, off;
argv = NULL;
- for (off = 0;; ++off) {
+ for (off = memsize = 0;; ++off) {
if (off >= memsize) {
memsize += 50; /* Starts out at 0. */
memsize *= 2; /* Ramp up fast. */
- if (!(argv = realloc(argv, memsize * sizeof(char *)))) {
- memsize = 0;
+ nargv = realloc(argv, memsize * sizeof(char *));
+ if (nargv == NULL) {
+ free(argv);
return (NULL);
}
+ argv = nargv;
if (off == 0) {
argv[0] = (char *)arg;
off = 1;
@@ -104,7 +105,7 @@ execl(name, arg, va_alist)
#else
va_start(ap);
#endif
- if (argv = buildargv(ap, arg, NULL))
+ if ( (argv = buildargv(ap, arg, NULL)) )
(void)execve(name, argv, environ);
va_end(ap);
sverrno = errno;
@@ -132,7 +133,7 @@ execle(name, arg, va_alist)
#else
va_start(ap);
#endif
- if (argv = buildargv(ap, arg, &envp))
+ if ( (argv = buildargv(ap, arg, &envp)) )
(void)execve(name, argv, envp);
va_end(ap);
sverrno = errno;
@@ -160,7 +161,7 @@ execlp(name, arg, va_alist)
#else
va_start(ap);
#endif
- if (argv = buildargv(ap, arg, NULL))
+ if ( (argv = buildargv(ap, arg, NULL)) )
(void)execvp(name, argv);
va_end(ap);
sverrno = errno;
@@ -183,13 +184,14 @@ execvp(name, argv)
const char *name;
char * const *argv;
{
- static int memsize;
- static char **memp;
+ char **memp;
register int cnt, lp, ln;
register char *p;
int eacces, etxtbsy;
char *bp, *cur, *path, buf[MAXPATHLEN];
+ eacces = etxtbsy = 0;
+
/* If it's an absolute or relative path name, it's easy. */
if (index(name, '/')) {
bp = (char *)name;
@@ -198,13 +200,18 @@ execvp(name, argv)
}
bp = buf;
+ /* If it's an empty path name, fail in the usual POSIX way. */
+ if (*name == '\0') {
+ errno = ENOENT;
+ return (-1);
+ }
+
/* Get the path we're searching. */
if (!(path = getenv("PATH")))
path = _PATH_DEFPATH;
cur = path = strdup(path);
- eacces = etxtbsy = 0;
- while (p = strsep(&cur, ":")) {
+ while ( (p = strsep(&cur, ":")) ) {
/*
* It's a SHELL path -- double, leading and trailing colons
* mean the current directory.
@@ -240,18 +247,16 @@ retry: (void)execve(bp, argv, environ);
case ENOENT:
break;
case ENOEXEC:
- for (cnt = 0; argv[cnt]; ++cnt);
- if ((cnt + 2) * sizeof(char *) > memsize) {
- memsize = (cnt + 2) * sizeof(char *);
- if ((memp = realloc(memp, memsize)) == NULL) {
- memsize = 0;
- goto done;
- }
- }
+ for (cnt = 0; argv[cnt]; ++cnt)
+ ;
+ memp = malloc((cnt + 2) * sizeof(char *));
+ if (memp == NULL)
+ goto done;
memp[0] = "sh";
memp[1] = bp;
bcopy(argv + 1, memp + 2, cnt * sizeof(char *));
(void)execve(_PATH_BSHELL, memp, environ);
+ free(memp);
goto done;
case ETXTBSY:
if (etxtbsy < 3)
diff --git a/lib/libc/gen/fnmatch.3 b/lib/libc/gen/fnmatch.3
index 3b87da1..1da91a8 100644
--- a/lib/libc/gen/fnmatch.3
+++ b/lib/libc/gen/fnmatch.3
@@ -85,7 +85,12 @@ must be explicitly matched by slashes in
.Fa pattern .
If this flag is not set, then slashes are treated as regular characters.
.It Dv FNM_PERIOD
-Leading periods in strings match periods in patterns.
+Leading periods in
+.Fa string
+must be explicitly matched by periods in
+.Fa pattern .
+If this flag is not set, then leading periods are treated as regular
+characters.
The definition of ``leading'' is related to the specification of
.Dv FNM_PATHNAME.
A period is always ``leading'' if it is the first character in
@@ -94,6 +99,17 @@ Additionally, if
.Dv FNM_PATHNAME
is set,
a period is ``leading'' if it immediately follows a slash.
+.It Dv FNM_LEADING_DIR
+Ignore
+.Nm /*
+rest after successful
+.Fa pattern
+matching.
+.It Dv FNM_CASEFOLD
+Ignore case distinctions in both the
+.Fa pattern
+and the
+.Fa string .
.El
.Sh RETURN VALUES
The
diff --git a/lib/libc/gen/fnmatch.c b/lib/libc/gen/fnmatch.c
index dc7f151..c3312b4 100644
--- a/lib/libc/gen/fnmatch.c
+++ b/lib/libc/gen/fnmatch.c
@@ -43,12 +43,20 @@ static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
* Compares a filename or pathname to a pattern.
*/
+#include <ctype.h>
#include <fnmatch.h>
#include <string.h>
+#include <stdio.h>
+
+#include "collate.h"
#define EOS '\0'
-static const char *rangematch __P((const char *, int, int));
+#define RANGE_MATCH 1
+#define RANGE_NOMATCH 0
+#define RANGE_ERROR (-1)
+
+static int rangematch __P((const char *, char, int, char **));
int
fnmatch(pattern, string, flags)
@@ -56,11 +64,14 @@ fnmatch(pattern, string, flags)
int flags;
{
const char *stringstart;
+ char *newp;
char c, test;
for (stringstart = string;;)
switch (c = *pattern++) {
case EOS:
+ if ((flags & FNM_LEADING_DIR) && *string == '/')
+ return (0);
return (*string == EOS ? 0 : FNM_NOMATCH);
case '?':
if (*string == EOS)
@@ -87,7 +98,8 @@ fnmatch(pattern, string, flags)
/* Optimize for pattern with * at end or before /. */
if (c == EOS)
if (flags & FNM_PATHNAME)
- return (strchr(string, '/') == NULL ?
+ return ((flags & FNM_LEADING_DIR) ||
+ strchr(string, '/') == NULL ?
0 : FNM_NOMATCH);
else
return (0);
@@ -109,11 +121,22 @@ fnmatch(pattern, string, flags)
case '[':
if (*string == EOS)
return (FNM_NOMATCH);
- if (*string == '/' && flags & FNM_PATHNAME)
+ if (*string == '/' && (flags & FNM_PATHNAME))
return (FNM_NOMATCH);
- if ((pattern =
- rangematch(pattern, *string, flags)) == NULL)
+ if (*string == '.' && (flags & FNM_PERIOD) &&
+ (string == stringstart ||
+ ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
return (FNM_NOMATCH);
+
+ switch (rangematch(pattern, *string, flags, &newp)) {
+ case RANGE_ERROR:
+ goto norm;
+ case RANGE_MATCH:
+ pattern = newp;
+ break;
+ case RANGE_NOMATCH:
+ return (FNM_NOMATCH);
+ }
++string;
break;
case '\\':
@@ -125,17 +148,27 @@ fnmatch(pattern, string, flags)
}
/* FALLTHROUGH */
default:
- if (c != *string++)
+ norm:
+ if (c == *string)
+ ;
+ else if ((flags & FNM_CASEFOLD) &&
+ (tolower((unsigned char)c) ==
+ tolower((unsigned char)*string)))
+ ;
+ else
return (FNM_NOMATCH);
+ string++;
break;
}
/* NOTREACHED */
}
-static const char *
-rangematch(pattern, test, flags)
+static int
+rangematch(pattern, test, flags, newp)
const char *pattern;
- int test, flags;
+ char test;
+ int flags;
+ char **newp;
{
int negate, ok;
char c, c2;
@@ -147,25 +180,52 @@ rangematch(pattern, test, flags)
* consistency with the regular expression syntax.
* J.T. Conklin (conklin@ngai.kaleida.com)
*/
- if (negate = (*pattern == '!' || *pattern == '^'))
+ if ( (negate = (*pattern == '!' || *pattern == '^')) )
++pattern;
-
- for (ok = 0; (c = *pattern++) != ']';) {
+
+ if (flags & FNM_CASEFOLD)
+ test = tolower((unsigned char)test);
+
+ /*
+ * A right bracket shall lose its special meaning and represent
+ * itself in a bracket expression if it occurs first in the list.
+ * -- POSIX.2 2.8.3.2
+ */
+ ok = 0;
+ c = *pattern++;
+ do {
if (c == '\\' && !(flags & FNM_NOESCAPE))
c = *pattern++;
if (c == EOS)
- return (NULL);
- if (*pattern == '-'
+ return (RANGE_ERROR);
+
+ if (c == '/' && (flags & FNM_PATHNAME))
+ return (RANGE_NOMATCH);
+
+ if (flags & FNM_CASEFOLD)
+ c = tolower((unsigned char)c);
+
+ if (*pattern == '-'
&& (c2 = *(pattern+1)) != EOS && c2 != ']') {
pattern += 2;
if (c2 == '\\' && !(flags & FNM_NOESCAPE))
c2 = *pattern++;
if (c2 == EOS)
- return (NULL);
- if (c <= test && test <= c2)
+ return (RANGE_ERROR);
+
+ if (flags & FNM_CASEFOLD)
+ c2 = tolower((unsigned char)c2);
+
+ if (__collate_load_error ?
+ c <= test && test <= c2 :
+ __collate_range_cmp(c, test) <= 0
+ && __collate_range_cmp(test, c2) <= 0
+ )
ok = 1;
} else if (c == test)
ok = 1;
- }
- return (ok == negate ? NULL : pattern);
+ } while ((c = *pattern++) != ']');
+
+ *newp = (char *)pattern;
+ return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH);
}
diff --git a/lib/libc/gen/frexp.3 b/lib/libc/gen/frexp.3
index 574efa3..58c25fc 100644
--- a/lib/libc/gen/frexp.3
+++ b/lib/libc/gen/frexp.3
@@ -76,8 +76,8 @@ If
is zero, both parts of the result are zero.
.Sh SEE ALSO
.Xr ldexp 3 ,
-.Xr modf 3 ,
-.Xr math 3
+.Xr math 3 ,
+.Xr modf 3
.Sh STANDARDS
The
.Fn frexp
diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c
index 48e5352..a526068 100644
--- a/lib/libc/gen/fstab.c
+++ b/lib/libc/gen/fstab.c
@@ -44,27 +44,32 @@ static char sccsid[] = "@(#)fstab.c 8.1 (Berkeley) 6/4/93";
static FILE *_fs_fp;
static struct fstab _fs_fstab;
+static int LineNo = 0;
-static error __P((int));
-static fstabscan __P((void));
+static void error __P((int));
+static int fstabscan __P((void));
-static
+static int
fstabscan()
{
- register char *cp;
+ char *cp, *p;
#define MAXLINELENGTH 1024
static char line[MAXLINELENGTH];
char subline[MAXLINELENGTH];
int typexx;
for (;;) {
- if (!(cp = fgets(line, sizeof(line), _fs_fp)))
+
+ if (!(p = fgets(line, sizeof(line), _fs_fp)))
return(0);
/* OLD_STYLE_FSTAB */
- if (!strpbrk(cp, " \t")) {
- _fs_fstab.fs_spec = strtok(cp, ":\n");
- _fs_fstab.fs_file = strtok((char *)NULL, ":\n");
- _fs_fstab.fs_type = strtok((char *)NULL, ":\n");
+ ++LineNo;
+ if (*line == '#' || *line == '\n')
+ continue;
+ if (!strpbrk(p, " \t")) {
+ _fs_fstab.fs_spec = strsep(&p, ":\n");
+ _fs_fstab.fs_file = strsep(&p, ":\n");
+ _fs_fstab.fs_type = strsep(&p, ":\n");
if (_fs_fstab.fs_type) {
if (!strcmp(_fs_fstab.fs_type, FSTAB_XX))
continue;
@@ -72,9 +77,9 @@ fstabscan()
_fs_fstab.fs_vfstype =
strcmp(_fs_fstab.fs_type, FSTAB_SW) ?
"ufs" : "swap";
- if (cp = strtok((char *)NULL, ":\n")) {
+ if ((cp = strsep(&p, ":\n")) != NULL) {
_fs_fstab.fs_freq = atoi(cp);
- if (cp = strtok((char *)NULL, ":\n")) {
+ if ((cp = strsep(&p, ":\n")) != NULL) {
_fs_fstab.fs_passno = atoi(cp);
return(1);
}
@@ -83,24 +88,37 @@ fstabscan()
goto bad;
}
/* OLD_STYLE_FSTAB */
- _fs_fstab.fs_spec = strtok(cp, " \t\n");
+ while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
+ ;
+ _fs_fstab.fs_spec = cp;
if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec == '#')
continue;
- _fs_fstab.fs_file = strtok((char *)NULL, " \t\n");
- _fs_fstab.fs_vfstype = strtok((char *)NULL, " \t\n");
- _fs_fstab.fs_mntops = strtok((char *)NULL, " \t\n");
+ while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
+ ;
+ _fs_fstab.fs_file = cp;
+ while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
+ ;
+ _fs_fstab.fs_vfstype = cp;
+ while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
+ ;
+ _fs_fstab.fs_mntops = cp;
if (_fs_fstab.fs_mntops == NULL)
goto bad;
_fs_fstab.fs_freq = 0;
_fs_fstab.fs_passno = 0;
- if ((cp = strtok((char *)NULL, " \t\n")) != NULL) {
+ while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
+ ;
+ if (cp != NULL) {
_fs_fstab.fs_freq = atoi(cp);
- if ((cp = strtok((char *)NULL, " \t\n")) != NULL)
+ while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
+ ;
+ if (cp != NULL)
_fs_fstab.fs_passno = atoi(cp);
}
strcpy(subline, _fs_fstab.fs_mntops);
- for (typexx = 0, cp = strtok(subline, ","); cp;
- cp = strtok((char *)NULL, ",")) {
+ p = subline;
+ for (typexx = 0, cp = strsep(&p, ","); cp;
+ cp = strsep(&p, ",")) {
if (strlen(cp) != 2)
continue;
if (!strcmp(cp, FSTAB_RW)) {
@@ -139,7 +157,7 @@ bad: /* no way to distinguish between EOF and syntax error */
struct fstab *
getfsent()
{
- if (!_fs_fp && !setfsent() || !fstabscan())
+ if ((!_fs_fp && !setfsent()) || !fstabscan())
return((struct fstab *)NULL);
return(&_fs_fstab);
}
@@ -166,14 +184,18 @@ getfsfile(name)
return((struct fstab *)NULL);
}
+int
setfsent()
{
if (_fs_fp) {
rewind(_fs_fp);
+ LineNo = 0;
return(1);
}
- if (_fs_fp = fopen(_PATH_FSTAB, "r"))
+ if ((_fs_fp = fopen(_PATH_FSTAB, "r")) != NULL) {
+ LineNo = 0;
return(1);
+ }
error(errno);
return(0);
}
@@ -187,15 +209,18 @@ endfsent()
}
}
-static
+static void
error(err)
int err;
{
char *p;
+ char num[30];
(void)write(STDERR_FILENO, "fstab: ", 7);
(void)write(STDERR_FILENO, _PATH_FSTAB, sizeof(_PATH_FSTAB) - 1);
- (void)write(STDERR_FILENO, ": ", 1);
+ (void)write(STDERR_FILENO, ":", 1);
+ sprintf(num, "%d: ", LineNo);
+ (void)write(STDERR_FILENO, num, strlen(num));
p = strerror(err);
(void)write(STDERR_FILENO, p, strlen(p));
(void)write(STDERR_FILENO, "\n", 1);
diff --git a/lib/libc/gen/ftok.3 b/lib/libc/gen/ftok.3
new file mode 100644
index 0000000..03b586d
--- /dev/null
+++ b/lib/libc/gen/ftok.3
@@ -0,0 +1,85 @@
+.\" Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"
+.\" $Id: ftok.3,v 1.7 1997/02/22 15:06:08 peter Exp $
+.Dd June 24, 1994
+.Os
+.Dt ftok 3
+.Sh NAME
+.Nm ftok
+.Nd create IPC identifier from path name
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Ft key_t
+.Fn ftok "const char *path" "int id"
+.Sh DESCRIPTION
+.Bf -symbolic
+This function is available from the compatibility library, libcompat.
+.Ef
+The
+.Fn ftok
+function attempts to create a unique key suitable for use with the
+.Xr msgget 3 ,
+.Xr semget 2
+and
+.Xr shmget 2
+functions given the
+.Fa path
+of an existing file and a user-selectable
+.Fa id .
+.Pp
+The specified
+.Fa path
+must specify an existing file that is accessible to the calling process
+or the call will fail. Also, note that links to files will return the
+same key, given the same
+.Fa id .
+.Sh RETURN VALUES
+The
+.Fn ftok
+function will return -1 if
+.Fa path
+does not exist or if it cannot be accessed by the calling process.
+.Sh SEE ALSO
+.Xr semget 2 ,
+.Xr shmget 2 ,
+.Xr msgget 3
+.Sh HISTORY
+The
+.Fn ftok
+function originates with System V and is typically used by programs
+that use the System V IPC routines.
+.Sh AUTHOR
+.Bl -tag
+Thorsten Lockert <tholo@sigmasoft.com>
+.El
+.Sh BUGS
+The returned key is computed based on the device minor number and inode of the
+specified
+.Fa path
+in combination with the lower 8 bits of the given
+.Fa id .
+Thus it is quite possible for the routine to return duplicate keys.
diff --git a/lib/libc/gen/ftok.c b/lib/libc/gen/ftok.c
new file mode 100644
index 0000000..4f59725
--- /dev/null
+++ b/lib/libc/gen/ftok.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 *rcsid = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ipc.h>
+
+key_t
+ftok(path, id)
+ const char *path;
+ char id;
+{
+ struct stat st;
+
+ if (stat(path, &st) < 0)
+ return (key_t)-1;
+
+ return (key_t) (id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff));
+}
diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c
new file mode 100644
index 0000000..e532707
--- /dev/null
+++ b/lib/libc/gen/fts-compat.c
@@ -0,0 +1,995 @@
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fts.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static FTSENT *fts_alloc __P((FTS *, char *, int));
+static FTSENT *fts_build __P((FTS *, int));
+static void fts_lfree __P((FTSENT *));
+static void fts_load __P((FTS *, FTSENT *));
+static size_t fts_maxarglen __P((char * const *));
+static void fts_padjust __P((FTS *, void *));
+static int fts_palloc __P((FTS *, size_t));
+static FTSENT *fts_sort __P((FTS *, FTSENT *, int));
+static u_short fts_stat __P((FTS *, FTSENT *, int));
+
+#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])) )
+
+#define ISSET(opt) (sp->fts_options & opt)
+#define SET(opt) (sp->fts_options |= opt)
+
+#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path))
+#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd))
+
+/* fts_build flags */
+#define BCHILD 1 /* fts_children */
+#define BNAMES 2 /* fts_children, names only */
+#define BREAD 3 /* fts_read */
+
+FTS *
+fts_open(argv, options, compar)
+ char * const *argv;
+ register int options;
+ int (*compar)();
+{
+ register FTS *sp;
+ register FTSENT *p, *root;
+ register int nitems;
+ FTSENT *parent, *tmp;
+ int len;
+
+ /* Options check. */
+ if (options & ~FTS_OPTIONMASK) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* Allocate/initialize the stream */
+ if ((sp = malloc((u_int)sizeof(FTS))) == NULL)
+ return (NULL);
+ memset(sp, 0, sizeof(FTS));
+ sp->fts_compar = compar;
+ sp->fts_options = options;
+
+ /* Logical walks turn on NOCHDIR; symbolic links are too hard. */
+ if (ISSET(FTS_LOGICAL))
+ SET(FTS_NOCHDIR);
+
+ /*
+ * Start out with 1K of path space, and enough, in any case,
+ * to hold the user's paths.
+ */
+ if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN)))
+ goto mem1;
+
+ /* Allocate/initialize root's parent. */
+ if ((parent = fts_alloc(sp, "", 0)) == NULL)
+ goto mem2;
+ parent->fts_level = FTS_ROOTPARENTLEVEL;
+
+ /* Allocate/initialize root(s). */
+ for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) {
+ /* Don't allow zero-length paths. */
+ if ((len = strlen(*argv)) == 0) {
+ errno = ENOENT;
+ goto mem3;
+ }
+
+ p = fts_alloc(sp, *argv, len);
+ p->fts_level = FTS_ROOTLEVEL;
+ p->fts_parent = parent;
+ p->fts_accpath = p->fts_name;
+ p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW));
+
+ /* Command-line "." and ".." are real directories. */
+ if (p->fts_info == FTS_DOT)
+ p->fts_info = FTS_D;
+
+ /*
+ * If comparison routine supplied, traverse in sorted
+ * order; otherwise traverse in the order specified.
+ */
+ if (compar) {
+ p->fts_link = root;
+ root = p;
+ } else {
+ p->fts_link = NULL;
+ if (root == NULL)
+ tmp = root = p;
+ else {
+ tmp->fts_link = p;
+ tmp = p;
+ }
+ }
+ }
+ if (compar && nitems > 1)
+ root = fts_sort(sp, root, nitems);
+
+ /*
+ * Allocate a dummy pointer and make fts_read think that we've just
+ * finished the node before the root(s); set p->fts_info to FTS_INIT
+ * so that everything about the "current" node is ignored.
+ */
+ if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL)
+ goto mem3;
+ sp->fts_cur->fts_link = root;
+ sp->fts_cur->fts_info = FTS_INIT;
+
+ /*
+ * If using chdir(2), grab a file descriptor pointing to dot to insure
+ * that we can get back here; this could be avoided for some paths,
+ * but almost certainly not worth the effort. Slashes, symbolic links,
+ * and ".." are all fairly nasty problems. Note, if we can't get the
+ * descriptor we run anyway, just more slowly.
+ */
+ if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = open(".", O_RDONLY, 0)) < 0)
+ SET(FTS_NOCHDIR);
+
+ return (sp);
+
+mem3: fts_lfree(root);
+ free(parent);
+mem2: free(sp->fts_path);
+mem1: free(sp);
+ return (NULL);
+}
+
+static void
+fts_load(sp, p)
+ FTS *sp;
+ register FTSENT *p;
+{
+ register int len;
+ register char *cp;
+
+ /*
+ * Load the stream structure for the next traversal. Since we don't
+ * actually enter the directory until after the preorder visit, set
+ * the fts_accpath field specially so the chdir gets done to the right
+ * place and the user can access the first node. From fts_open it's
+ * known that the path will fit.
+ */
+ len = p->fts_pathlen = p->fts_namelen;
+ memmove(sp->fts_path, p->fts_name, len + 1);
+ if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) {
+ len = strlen(++cp);
+ memmove(p->fts_name, cp, len + 1);
+ p->fts_namelen = len;
+ }
+ p->fts_accpath = p->fts_path = sp->fts_path;
+ sp->fts_dev = p->fts_dev;
+}
+
+int
+fts_close(sp)
+ FTS *sp;
+{
+ register FTSENT *freep, *p;
+ int saved_errno;
+
+ /*
+ * This still works if we haven't read anything -- the dummy structure
+ * points to the root list, so we step through to the end of the root
+ * list which has a valid parent pointer.
+ */
+ if (sp->fts_cur) {
+ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
+ freep = p;
+ p = p->fts_link ? p->fts_link : p->fts_parent;
+ free(freep);
+ }
+ free(p);
+ }
+
+ /* Free up child linked list, sort array, path buffer. */
+ if (sp->fts_child)
+ fts_lfree(sp->fts_child);
+ if (sp->fts_array)
+ free(sp->fts_array);
+ free(sp->fts_path);
+
+ /* Return to original directory, save errno if necessary. */
+ if (!ISSET(FTS_NOCHDIR)) {
+ saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
+ (void)close(sp->fts_rfd);
+ }
+
+ /* Free up the stream pointer. */
+ free(sp);
+
+ /* Set errno and return. */
+ if (!ISSET(FTS_NOCHDIR) && saved_errno) {
+ errno = saved_errno;
+ return (-1);
+ }
+ return (0);
+}
+
+/*
+ * Special case a root of "/" so that slashes aren't appended which would
+ * cause paths to be written as "//foo".
+ */
+#define NAPPEND(p) \
+ (p->fts_level == FTS_ROOTLEVEL && p->fts_pathlen == 1 && \
+ p->fts_path[0] == '/' ? 0 : p->fts_pathlen)
+
+FTSENT *
+fts_read(sp)
+ register FTS *sp;
+{
+ register FTSENT *p, *tmp;
+ register int instr;
+ register char *t;
+ int saved_errno;
+
+ /* If finished or unrecoverable error, return NULL. */
+ if (sp->fts_cur == NULL || ISSET(FTS_STOP))
+ return (NULL);
+
+ /* Set current node pointer. */
+ p = sp->fts_cur;
+
+ /* Save and zero out user instructions. */
+ instr = p->fts_instr;
+ p->fts_instr = FTS_NOINSTR;
+
+ /* Any type of file may be re-visited; re-stat and re-turn. */
+ if (instr == FTS_AGAIN) {
+ p->fts_info = fts_stat(sp, p, 0);
+ return (p);
+ }
+
+ /*
+ * Following a symlink -- SLNONE test allows application to see
+ * SLNONE and recover. If indirecting through a symlink, have
+ * keep a pointer to current location. If unable to get that
+ * pointer, follow fails.
+ */
+ if (instr == FTS_FOLLOW &&
+ (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
+ p->fts_info = fts_stat(sp, p, 1);
+ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR))
+ if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
+ } else
+ p->fts_flags |= FTS_SYMFOLLOW;
+ return (p);
+ }
+
+ /* Directory in pre-order. */
+ if (p->fts_info == FTS_D) {
+ /* If skipped or crossed mount point, do post-order visit. */
+ if (instr == FTS_SKIP ||
+ (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev) ) {
+ if (p->fts_flags & FTS_SYMFOLLOW)
+ (void)close(p->fts_symfd);
+ if (sp->fts_child) {
+ fts_lfree(sp->fts_child);
+ sp->fts_child = NULL;
+ }
+ p->fts_info = FTS_DP;
+ return (p);
+ }
+
+ /* Rebuild if only read the names and now traversing. */
+ if (sp->fts_child && sp->fts_options & FTS_NAMEONLY) {
+ sp->fts_options &= ~FTS_NAMEONLY;
+ fts_lfree(sp->fts_child);
+ sp->fts_child = NULL;
+ }
+
+ /*
+ * Cd to the subdirectory.
+ *
+ * If have already read and now fail to chdir, whack the list
+ * to make the names come out right, and set the parent errno
+ * so the application will eventually get an error condition.
+ * Set the FTS_DONTCHDIR flag so that when we logically change
+ * directories back to the parent we don't do a chdir.
+ *
+ * If haven't read do so. If the read fails, fts_build sets
+ * FTS_STOP or the fts_info field of the node.
+ */
+ if (sp->fts_child) {
+ if (CHDIR(sp, p->fts_accpath)) {
+ p->fts_errno = errno;
+ p->fts_flags |= FTS_DONTCHDIR;
+ for (p = sp->fts_child; p; p = p->fts_link)
+ p->fts_accpath =
+ p->fts_parent->fts_accpath;
+ }
+ } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
+ if (ISSET(FTS_STOP))
+ return (NULL);
+ return (p);
+ }
+ p = sp->fts_child;
+ sp->fts_child = NULL;
+ goto name;
+ }
+
+ /* Move to the next node on this level. */
+next: tmp = p;
+ if ( (p = p->fts_link) ) {
+ free(tmp);
+
+ /*
+ * If reached the top, return to the original directory, and
+ * load the paths for the next root.
+ */
+ if (p->fts_level == FTS_ROOTLEVEL) {
+ if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ fts_load(sp, p);
+ return (sp->fts_cur = p);
+ }
+
+ /*
+ * User may have called fts_set on the node. If skipped,
+ * ignore. If followed, get a file descriptor so we can
+ * get back if necessary.
+ */
+ if (p->fts_instr == FTS_SKIP)
+ goto next;
+ if (p->fts_instr == FTS_FOLLOW) {
+ p->fts_info = fts_stat(sp, p, 1);
+ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR))
+ if ((p->fts_symfd =
+ open(".", O_RDONLY, 0)) < 0) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
+ } else
+ p->fts_flags |= FTS_SYMFOLLOW;
+ p->fts_instr = FTS_NOINSTR;
+ }
+
+name: t = sp->fts_path + NAPPEND(p->fts_parent);
+ *t++ = '/';
+ memmove(t, p->fts_name, p->fts_namelen + 1);
+ return (sp->fts_cur = p);
+ }
+
+ /* Move up to the parent node. */
+ p = tmp->fts_parent;
+ free(tmp);
+
+ if (p->fts_level == FTS_ROOTPARENTLEVEL) {
+ /*
+ * Done; free everything up and set errno to 0 so the user
+ * can distinguish between error and EOF.
+ */
+ free(p);
+ errno = 0;
+ return (sp->fts_cur = NULL);
+ }
+
+ /* Nul terminate the pathname. */
+ sp->fts_path[p->fts_pathlen] = '\0';
+
+ /*
+ * Return to the parent directory. If at a root node or came through
+ * a symlink, go back through the file descriptor. Otherwise, cd up
+ * one directory.
+ */
+ if (p->fts_level == FTS_ROOTLEVEL) {
+ if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ } else if (p->fts_flags & FTS_SYMFOLLOW) {
+ if (FCHDIR(sp, p->fts_symfd)) {
+ saved_errno = errno;
+ (void)close(p->fts_symfd);
+ errno = saved_errno;
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ (void)close(p->fts_symfd);
+ } else if (!(p->fts_flags & FTS_DONTCHDIR)) {
+ if (CHDIR(sp, "..")) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ }
+ p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
+ return (sp->fts_cur = p);
+}
+
+/*
+ * Fts_set takes the stream as an argument although it's not used in this
+ * implementation; it would be necessary if anyone wanted to add global
+ * semantics to fts using fts_set. An error return is allowed for similar
+ * reasons.
+ */
+/* ARGSUSED */
+int
+fts_set(sp, p, instr)
+ FTS *sp;
+ FTSENT *p;
+ int instr;
+{
+ if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW &&
+ instr != FTS_NOINSTR && instr != FTS_SKIP) {
+ errno = EINVAL;
+ return (1);
+ }
+ p->fts_instr = instr;
+ return (0);
+}
+
+FTSENT *
+fts_children(sp, instr)
+ register FTS *sp;
+ int instr;
+{
+ register FTSENT *p;
+ int fd;
+
+ if (instr && instr != FTS_NAMEONLY) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* Set current node pointer. */
+ p = sp->fts_cur;
+
+ /*
+ * Errno set to 0 so user can distinguish empty directory from
+ * an error.
+ */
+ errno = 0;
+
+ /* Fatal errors stop here. */
+ if (ISSET(FTS_STOP))
+ return (NULL);
+
+ /* Return logical hierarchy of user's arguments. */
+ if (p->fts_info == FTS_INIT)
+ return (p->fts_link);
+
+ /*
+ * If not a directory being visited in pre-order, stop here. Could
+ * allow FTS_DNR, assuming the user has fixed the problem, but the
+ * same effect is available with FTS_AGAIN.
+ */
+ if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */)
+ return (NULL);
+
+ /* Free up any previous child list. */
+ if (sp->fts_child)
+ fts_lfree(sp->fts_child);
+
+ if (instr == FTS_NAMEONLY) {
+ sp->fts_options |= FTS_NAMEONLY;
+ instr = BNAMES;
+ } else
+ instr = BCHILD;
+
+ /*
+ * If using chdir on a relative path and called BEFORE fts_read does
+ * its chdir to the root of a traversal, we can lose -- we need to
+ * chdir into the subdirectory, and we don't know where the current
+ * directory is, so we can't get back so that the upcoming chdir by
+ * fts_read will work.
+ */
+ if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' ||
+ ISSET(FTS_NOCHDIR))
+ return (sp->fts_child = fts_build(sp, instr));
+
+ if ((fd = open(".", O_RDONLY, 0)) < 0)
+ return (NULL);
+ sp->fts_child = fts_build(sp, instr);
+ if (fchdir(fd))
+ return (NULL);
+ (void)close(fd);
+ return (sp->fts_child);
+}
+
+/*
+ * This is the tricky part -- do not casually change *anything* in here. The
+ * idea is to build the linked list of entries that are used by fts_children
+ * and fts_read. There are lots of special cases.
+ *
+ * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is
+ * set and it's a physical walk (so that symbolic links can't be directories),
+ * we can do things quickly. First, if it's a 4.4BSD file system, the type
+ * of the file is in the directory entry. Otherwise, we assume that the number
+ * of subdirectories in a node is equal to the number of links to the parent.
+ * The former skips all stat calls. The latter skips stat calls in any leaf
+ * directories and for any files after the subdirectories in the directory have
+ * been found, cutting the stat calls by about 2/3.
+ */
+static FTSENT *
+fts_build(sp, type)
+ register FTS *sp;
+ int type;
+{
+ register struct dirent *dp;
+ register FTSENT *p, *head;
+ register int nitems;
+ FTSENT *cur, *tail;
+ DIR *dirp;
+ void *adjaddr;
+ int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno;
+ char *cp;
+
+ /* Set current node pointer. */
+ cur = sp->fts_cur;
+
+ /*
+ * Open the directory for reading. If this fails, we're done.
+ * If being called from fts_read, set the fts_info field.
+ */
+#ifdef FTS_WHITEOUT
+ if (ISSET(FTS_WHITEOUT))
+ oflag = DTF_NODUP|DTF_REWIND;
+ else
+ oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND;
+#else
+#define __opendir2(path, flag) opendir(path)
+#endif
+ if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) {
+ if (type == BREAD) {
+ cur->fts_info = FTS_DNR;
+ cur->fts_errno = errno;
+ }
+ return (NULL);
+ }
+
+ /*
+ * Nlinks is the number of possible entries of type directory in the
+ * directory if we're cheating on stat calls, 0 if we're not doing
+ * any stat calls at all, -1 if we're doing stats on everything.
+ */
+ if (type == BNAMES)
+ nlinks = 0;
+ else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL))
+ nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
+ else
+ nlinks = -1;
+
+#ifdef notdef
+ (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink);
+ (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n",
+ ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT));
+#endif
+ /*
+ * If we're going to need to stat anything or we want to descend
+ * and stay in the directory, chdir. If this fails we keep going,
+ * but set a flag so we don't chdir after the post-order visit.
+ * We won't be able to stat anything, but we can still return the
+ * names themselves. Note, that since fts_read won't be able to
+ * chdir into the directory, it will have to return different path
+ * names than before, i.e. "a/b" instead of "b". Since the node
+ * has already been visited in pre-order, have to wait until the
+ * post-order visit to return the error. There is a special case
+ * here, if there was nothing to stat then it's not an error to
+ * not be able to stat. This is all fairly nasty. If a program
+ * needed sorted entries or stat information, they had better be
+ * checking FTS_NS on the returned nodes.
+ */
+ cderrno = 0;
+ if (nlinks || type == BREAD)
+ if (FCHDIR(sp, dirfd(dirp))) {
+ if (nlinks && type == BREAD)
+ cur->fts_errno = errno;
+ cur->fts_flags |= FTS_DONTCHDIR;
+ descend = 0;
+ cderrno = errno;
+ } else
+ descend = 1;
+ else
+ descend = 0;
+
+ /*
+ * Figure out the max file name length that can be stored in the
+ * current path -- the inner loop allocates more path as necessary.
+ * We really wouldn't have to do the maxlen calculations here, we
+ * could do them in fts_read before returning the path, but it's a
+ * lot easier here since the length is part of the dirent structure.
+ *
+ * If not changing directories set a pointer so that can just append
+ * each new name into the path.
+ */
+ maxlen = sp->fts_pathlen - cur->fts_pathlen - 1;
+ len = NAPPEND(cur);
+ if (ISSET(FTS_NOCHDIR)) {
+ cp = sp->fts_path + len;
+ *cp++ = '/';
+ }
+
+ level = cur->fts_level + 1;
+
+ /* Read the directory, attaching each entry to the `link' pointer. */
+ adjaddr = NULL;
+ for (head = tail = NULL, nitems = 0; (dp = readdir(dirp)); ) {
+ if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
+ continue;
+
+ if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL)
+ goto mem1;
+ if (dp->d_namlen > maxlen) {
+ if (fts_palloc(sp, (size_t)dp->d_namlen)) {
+ /*
+ * No more memory for path or structures. Save
+ * errno, free up the current structure and the
+ * structures already allocated.
+ */
+mem1: saved_errno = errno;
+ if (p)
+ free(p);
+ fts_lfree(head);
+ (void)closedir(dirp);
+ errno = saved_errno;
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ adjaddr = sp->fts_path;
+ maxlen = sp->fts_pathlen - sp->fts_cur->fts_pathlen - 1;
+ }
+
+ p->fts_pathlen = len + dp->d_namlen + 1;
+ p->fts_parent = sp->fts_cur;
+ p->fts_level = level;
+
+#ifdef FTS_WHITEOUT
+ if (dp->d_type == DT_WHT)
+ p->fts_flags |= FTS_ISW;
+#endif
+
+ if (cderrno) {
+ if (nlinks) {
+ p->fts_info = FTS_NS;
+ p->fts_errno = cderrno;
+ } else
+ p->fts_info = FTS_NSOK;
+ p->fts_accpath = cur->fts_accpath;
+ } else if (nlinks == 0
+#ifdef DT_DIR
+ || (nlinks > 0 &&
+ dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
+#endif
+ ) {
+ p->fts_accpath =
+ ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
+ p->fts_info = FTS_NSOK;
+ } else {
+ /* Build a file name for fts_stat to stat. */
+ if (ISSET(FTS_NOCHDIR)) {
+ p->fts_accpath = p->fts_path;
+ memmove(cp, p->fts_name, p->fts_namelen + 1);
+ } else
+ p->fts_accpath = p->fts_name;
+ /* Stat it. */
+ p->fts_info = fts_stat(sp, p, 0);
+
+ /* Decrement link count if applicable. */
+ if (nlinks > 0 && (p->fts_info == FTS_D ||
+ p->fts_info == FTS_DC || p->fts_info == FTS_DOT))
+ --nlinks;
+ }
+
+ /* We walk in directory order so "ls -f" doesn't get upset. */
+ p->fts_link = NULL;
+ if (head == NULL)
+ head = tail = p;
+ else {
+ tail->fts_link = p;
+ tail = p;
+ }
+ ++nitems;
+ }
+ (void)closedir(dirp);
+
+ /*
+ * If had to realloc the path, adjust the addresses for the rest
+ * of the tree.
+ */
+ if (adjaddr)
+ fts_padjust(sp, adjaddr);
+
+ /*
+ * If not changing directories, reset the path back to original
+ * state.
+ */
+ if (ISSET(FTS_NOCHDIR)) {
+ if (cp - 1 > sp->fts_path)
+ --cp;
+ *cp = '\0';
+ }
+
+ /*
+ * If descended after called from fts_children or after called from
+ * fts_read and nothing found, get back. At the root level we use
+ * the saved fd; if one of fts_open()'s arguments is a relative path
+ * to an empty directory, we wind up here with no other way back. If
+ * can't get back, we're done.
+ */
+ if (descend && (type == BCHILD || !nitems) &&
+ (cur->fts_level == FTS_ROOTLEVEL ?
+ FCHDIR(sp, sp->fts_rfd) : CHDIR(sp, ".."))) {
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ return (NULL);
+ }
+
+ /* If didn't find anything, return NULL. */
+ if (!nitems) {
+ if (type == BREAD)
+ cur->fts_info = FTS_DP;
+ return (NULL);
+ }
+
+ /* Sort the entries. */
+ if (sp->fts_compar && nitems > 1)
+ head = fts_sort(sp, head, nitems);
+ return (head);
+}
+
+static u_short
+fts_stat(sp, p, follow)
+ FTS *sp;
+ register FTSENT *p;
+ int follow;
+{
+ register FTSENT *t;
+ register dev_t dev;
+ register ino_t ino;
+ struct stat *sbp, sb;
+ int saved_errno;
+
+ /* If user needs stat info, stat buffer already allocated. */
+ sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
+
+#ifdef FTS_WHITEOUT
+ /* check for whiteout */
+ if (p->fts_flags & FTS_ISW) {
+ if (sbp != &sb) {
+ memset(sbp, '\0', sizeof (*sbp));
+ sbp->st_mode = S_IFWHT;
+ }
+ return (FTS_W);
+ }
+#endif
+
+ /*
+ * If doing a logical walk, or application requested FTS_FOLLOW, do
+ * a stat(2). If that fails, check for a non-existent symlink. If
+ * fail, set the errno from the stat call.
+ */
+ if (ISSET(FTS_LOGICAL) || follow) {
+ if (stat(p->fts_accpath, sbp)) {
+ saved_errno = errno;
+ if (!lstat(p->fts_accpath, sbp)) {
+ errno = 0;
+ return (FTS_SLNONE);
+ }
+ p->fts_errno = saved_errno;
+ goto err;
+ }
+ } else if (lstat(p->fts_accpath, sbp)) {
+ p->fts_errno = errno;
+err: memset(sbp, 0, sizeof(struct stat));
+ return (FTS_NS);
+ }
+
+ if (S_ISDIR(sbp->st_mode)) {
+ /*
+ * Set the device/inode. Used to find cycles and check for
+ * crossing mount points. Also remember the link count, used
+ * in fts_build to limit the number of stat calls. It is
+ * understood that these fields are only referenced if fts_info
+ * is set to FTS_D.
+ */
+ dev = p->fts_dev = sbp->st_dev;
+ ino = p->fts_ino = sbp->st_ino;
+ p->fts_nlink = sbp->st_nlink;
+
+ if (ISDOT(p->fts_name))
+ return (FTS_DOT);
+
+ /*
+ * Cycle detection is done by brute force when the directory
+ * is first encountered. If the tree gets deep enough or the
+ * number of symbolic links to directories is high enough,
+ * something faster might be worthwhile.
+ */
+ for (t = p->fts_parent;
+ t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent)
+ if (ino == t->fts_ino && dev == t->fts_dev) {
+ p->fts_cycle = t;
+ return (FTS_DC);
+ }
+ return (FTS_D);
+ }
+ if (S_ISLNK(sbp->st_mode))
+ return (FTS_SL);
+ if (S_ISREG(sbp->st_mode))
+ return (FTS_F);
+ return (FTS_DEFAULT);
+}
+
+static FTSENT *
+fts_sort(sp, head, nitems)
+ FTS *sp;
+ FTSENT *head;
+ register int nitems;
+{
+ register FTSENT **ap, *p;
+
+ /*
+ * Construct an array of pointers to the structures and call qsort(3).
+ * Reassemble the array in the order returned by qsort. If unable to
+ * sort for memory reasons, return the directory entries in their
+ * current order. Allocate enough space for the current needs plus
+ * 40 so don't realloc one entry at a time.
+ */
+ if (nitems > sp->fts_nitems) {
+ sp->fts_nitems = nitems + 40;
+ if ((sp->fts_array = realloc(sp->fts_array,
+ (size_t)(sp->fts_nitems * sizeof(FTSENT *)))) == NULL) {
+ sp->fts_nitems = 0;
+ return (head);
+ }
+ }
+ for (ap = sp->fts_array, p = head; p; p = p->fts_link)
+ *ap++ = p;
+ qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar);
+ for (head = *(ap = sp->fts_array); --nitems; ++ap)
+ ap[0]->fts_link = ap[1];
+ ap[0]->fts_link = NULL;
+ return (head);
+}
+
+static FTSENT *
+fts_alloc(sp, name, namelen)
+ FTS *sp;
+ char *name;
+ register int namelen;
+{
+ register FTSENT *p;
+ size_t len;
+
+ /*
+ * The file name is a variable length array and no stat structure is
+ * necessary if the user has set the nostat bit. Allocate the FTSENT
+ * structure, the file name and the stat structure in one chunk, but
+ * be careful that the stat structure is reasonably aligned. Since the
+ * fts_name field is declared to be of size 1, the fts_name pointer is
+ * namelen + 2 before the first possible address of the stat structure.
+ */
+ len = sizeof(FTSENT) + namelen;
+ if (!ISSET(FTS_NOSTAT))
+ len += sizeof(struct stat) + ALIGNBYTES;
+ if ((p = malloc(len)) == NULL)
+ return (NULL);
+
+ /* Copy the name plus the trailing NULL. */
+ memmove(p->fts_name, name, namelen + 1);
+
+ if (!ISSET(FTS_NOSTAT))
+ p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2);
+ p->fts_namelen = namelen;
+ p->fts_path = sp->fts_path;
+ p->fts_errno = 0;
+ p->fts_flags = 0;
+ p->fts_instr = FTS_NOINSTR;
+ p->fts_number = 0;
+ p->fts_pointer = NULL;
+ return (p);
+}
+
+static void
+fts_lfree(head)
+ register FTSENT *head;
+{
+ register FTSENT *p;
+
+ /* Free a linked list of structures. */
+ while ( (p = head) ) {
+ head = head->fts_link;
+ free(p);
+ }
+}
+
+/*
+ * Allow essentially unlimited paths; find, rm, ls should all work on any tree.
+ * Most systems will allow creation of paths much longer than MAXPATHLEN, even
+ * though the kernel won't resolve them. Add the size (not just what's needed)
+ * plus 256 bytes so don't realloc the path 2 bytes at a time.
+ */
+static int
+fts_palloc(sp, more)
+ FTS *sp;
+ size_t more;
+{
+ sp->fts_pathlen += more + 256;
+ sp->fts_path = realloc(sp->fts_path, (size_t)sp->fts_pathlen);
+ return (sp->fts_path == NULL);
+}
+
+/*
+ * When the path is realloc'd, have to fix all of the pointers in structures
+ * already returned.
+ */
+static void
+fts_padjust(sp, addr)
+ FTS *sp;
+ void *addr;
+{
+ FTSENT *p;
+
+#define ADJUST(p) { \
+ (p)->fts_accpath = \
+ (char *)addr + ((p)->fts_accpath - (p)->fts_path); \
+ (p)->fts_path = addr; \
+}
+ /* Adjust the current set of children. */
+ for (p = sp->fts_child; p; p = p->fts_link)
+ ADJUST(p);
+
+ /* Adjust the rest of the tree. */
+ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
+ ADJUST(p);
+ p = p->fts_link ? p->fts_link : p->fts_parent;
+ }
+}
+
+static size_t
+fts_maxarglen(argv)
+ char * const *argv;
+{
+ size_t len, max;
+
+ for (max = 0; *argv; ++argv)
+ if ((len = strlen(*argv)) > max)
+ max = len;
+ return (max);
+}
diff --git a/lib/libc/gen/fts-compat.h b/lib/libc/gen/fts-compat.h
new file mode 100644
index 0000000..4fa4a3a
--- /dev/null
+++ b/lib/libc/gen/fts-compat.h
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * @(#)fts.h 8.3 (Berkeley) 8/14/94
+ */
+
+#ifndef _FTS_H_
+#define _FTS_H_
+
+typedef struct {
+ struct _ftsent *fts_cur; /* current node */
+ struct _ftsent *fts_child; /* linked list of children */
+ struct _ftsent **fts_array; /* sort array */
+ dev_t fts_dev; /* starting device # */
+ char *fts_path; /* path for this descent */
+ int fts_rfd; /* fd for root */
+ int fts_pathlen; /* sizeof(path) */
+ int fts_nitems; /* elements in the sort array */
+ int (*fts_compar)(); /* compare function */
+
+#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */
+#define FTS_LOGICAL 0x002 /* logical walk */
+#define FTS_NOCHDIR 0x004 /* don't change directories */
+#define FTS_NOSTAT 0x008 /* don't get stat info */
+#define FTS_PHYSICAL 0x010 /* physical walk */
+#define FTS_SEEDOT 0x020 /* return dot and dot-dot */
+#define FTS_XDEV 0x040 /* don't cross devices */
+#define FTS_WHITEOUT 0x080 /* return whiteout information */
+#define FTS_OPTIONMASK 0x0ff /* valid user option mask */
+
+#define FTS_NAMEONLY 0x100 /* (private) child names only */
+#define FTS_STOP 0x200 /* (private) unrecoverable error */
+ int fts_options; /* fts_open options, global flags */
+} FTS;
+
+typedef struct _ftsent {
+ struct _ftsent *fts_cycle; /* cycle node */
+ struct _ftsent *fts_parent; /* parent directory */
+ struct _ftsent *fts_link; /* next file in directory */
+ long fts_number; /* local numeric value */
+ void *fts_pointer; /* local address value */
+ char *fts_accpath; /* access path */
+ char *fts_path; /* root path */
+ int fts_errno; /* errno for this node */
+ int fts_symfd; /* fd for symlink */
+ u_short fts_pathlen; /* strlen(fts_path) */
+ u_short fts_namelen; /* strlen(fts_name) */
+
+ ino_t fts_ino; /* inode */
+ dev_t fts_dev; /* device */
+ nlink_t fts_nlink; /* link count */
+
+#define FTS_ROOTPARENTLEVEL -1
+#define FTS_ROOTLEVEL 0
+ short fts_level; /* depth (-1 to N) */
+
+#define FTS_D 1 /* preorder directory */
+#define FTS_DC 2 /* directory that causes cycles */
+#define FTS_DEFAULT 3 /* none of the above */
+#define FTS_DNR 4 /* unreadable directory */
+#define FTS_DOT 5 /* dot or dot-dot */
+#define FTS_DP 6 /* postorder directory */
+#define FTS_ERR 7 /* error; errno is set */
+#define FTS_F 8 /* regular file */
+#define FTS_INIT 9 /* initialized only */
+#define FTS_NS 10 /* stat(2) failed */
+#define FTS_NSOK 11 /* no stat(2) requested */
+#define FTS_SL 12 /* symbolic link */
+#define FTS_SLNONE 13 /* symbolic link without target */
+#define FTS_W 14 /* whiteout object */
+ u_short fts_info; /* user flags for FTSENT structure */
+
+#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
+#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
+#define FTS_ISW 0x04 /* this is a whiteout object */
+ u_short fts_flags; /* private flags for FTSENT structure */
+
+#define FTS_AGAIN 1 /* read node again */
+#define FTS_FOLLOW 2 /* follow symbolic link */
+#define FTS_NOINSTR 3 /* no instructions */
+#define FTS_SKIP 4 /* discard node */
+ u_short fts_instr; /* fts_set() instructions */
+
+ struct stat *fts_statp; /* stat(2) information */
+ char fts_name[1]; /* file name */
+} FTSENT;
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+FTSENT *fts_children __P((FTS *, int));
+int fts_close __P((FTS *));
+FTS *fts_open __P((char * const *, int,
+ int (*)(const FTSENT **, const FTSENT **)));
+FTSENT *fts_read __P((FTS *));
+int fts_set __P((FTS *, FTSENT *, int));
+__END_DECLS
+
+#endif /* !_FTS_H_ */
diff --git a/lib/libc/gen/fts.3 b/lib/libc/gen/fts.3
index dde076d..7813665 100644
--- a/lib/libc/gen/fts.3
+++ b/lib/libc/gen/fts.3
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)fts.3 8.5 (Berkeley) 4/16/94
+.\" $Id$
.\"
.Dd April 16, 1994
.Dt FTS 3
@@ -42,13 +43,13 @@
.Fd #include <sys/stat.h>
.Fd #include <fts.h>
.Ft FTS *
-.Fn fts_open "char * const *path_argv" "int options" "int *compar(const FTSENT **, const FTSENT **)"
+.Fn fts_open "char * const *path_argv" "int options" "int (*compar)(const FTSENT **, const FTSENT **)"
.Ft FTSENT *
.Fn fts_read "FTS *ftsp"
.Ft FTSENT *
.Fn fts_children "FTS *ftsp" "int options"
.Ft int
-.Fn fts_set "FTS ftsp" "FTSENT *f" "int options"
+.Fn fts_set "FTS *ftsp" "FTSENT *f" "int options"
.Ft int
.Fn fts_close "FTS *ftsp"
.Sh DESCRIPTION
@@ -122,7 +123,7 @@ typedef struct _ftsent {
These fields are defined as follows:
.Bl -tag -width "fts_namelen"
.It Fa fts_info
-One of the following flags describing the returned
+One of the following values describing the returned
.Fa FTSENT
structure and
the file it represents.
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
new file mode 100644
index 0000000..e532707
--- /dev/null
+++ b/lib/libc/gen/fts.c
@@ -0,0 +1,995 @@
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fts.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static FTSENT *fts_alloc __P((FTS *, char *, int));
+static FTSENT *fts_build __P((FTS *, int));
+static void fts_lfree __P((FTSENT *));
+static void fts_load __P((FTS *, FTSENT *));
+static size_t fts_maxarglen __P((char * const *));
+static void fts_padjust __P((FTS *, void *));
+static int fts_palloc __P((FTS *, size_t));
+static FTSENT *fts_sort __P((FTS *, FTSENT *, int));
+static u_short fts_stat __P((FTS *, FTSENT *, int));
+
+#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])) )
+
+#define ISSET(opt) (sp->fts_options & opt)
+#define SET(opt) (sp->fts_options |= opt)
+
+#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path))
+#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd))
+
+/* fts_build flags */
+#define BCHILD 1 /* fts_children */
+#define BNAMES 2 /* fts_children, names only */
+#define BREAD 3 /* fts_read */
+
+FTS *
+fts_open(argv, options, compar)
+ char * const *argv;
+ register int options;
+ int (*compar)();
+{
+ register FTS *sp;
+ register FTSENT *p, *root;
+ register int nitems;
+ FTSENT *parent, *tmp;
+ int len;
+
+ /* Options check. */
+ if (options & ~FTS_OPTIONMASK) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* Allocate/initialize the stream */
+ if ((sp = malloc((u_int)sizeof(FTS))) == NULL)
+ return (NULL);
+ memset(sp, 0, sizeof(FTS));
+ sp->fts_compar = compar;
+ sp->fts_options = options;
+
+ /* Logical walks turn on NOCHDIR; symbolic links are too hard. */
+ if (ISSET(FTS_LOGICAL))
+ SET(FTS_NOCHDIR);
+
+ /*
+ * Start out with 1K of path space, and enough, in any case,
+ * to hold the user's paths.
+ */
+ if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN)))
+ goto mem1;
+
+ /* Allocate/initialize root's parent. */
+ if ((parent = fts_alloc(sp, "", 0)) == NULL)
+ goto mem2;
+ parent->fts_level = FTS_ROOTPARENTLEVEL;
+
+ /* Allocate/initialize root(s). */
+ for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) {
+ /* Don't allow zero-length paths. */
+ if ((len = strlen(*argv)) == 0) {
+ errno = ENOENT;
+ goto mem3;
+ }
+
+ p = fts_alloc(sp, *argv, len);
+ p->fts_level = FTS_ROOTLEVEL;
+ p->fts_parent = parent;
+ p->fts_accpath = p->fts_name;
+ p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW));
+
+ /* Command-line "." and ".." are real directories. */
+ if (p->fts_info == FTS_DOT)
+ p->fts_info = FTS_D;
+
+ /*
+ * If comparison routine supplied, traverse in sorted
+ * order; otherwise traverse in the order specified.
+ */
+ if (compar) {
+ p->fts_link = root;
+ root = p;
+ } else {
+ p->fts_link = NULL;
+ if (root == NULL)
+ tmp = root = p;
+ else {
+ tmp->fts_link = p;
+ tmp = p;
+ }
+ }
+ }
+ if (compar && nitems > 1)
+ root = fts_sort(sp, root, nitems);
+
+ /*
+ * Allocate a dummy pointer and make fts_read think that we've just
+ * finished the node before the root(s); set p->fts_info to FTS_INIT
+ * so that everything about the "current" node is ignored.
+ */
+ if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL)
+ goto mem3;
+ sp->fts_cur->fts_link = root;
+ sp->fts_cur->fts_info = FTS_INIT;
+
+ /*
+ * If using chdir(2), grab a file descriptor pointing to dot to insure
+ * that we can get back here; this could be avoided for some paths,
+ * but almost certainly not worth the effort. Slashes, symbolic links,
+ * and ".." are all fairly nasty problems. Note, if we can't get the
+ * descriptor we run anyway, just more slowly.
+ */
+ if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = open(".", O_RDONLY, 0)) < 0)
+ SET(FTS_NOCHDIR);
+
+ return (sp);
+
+mem3: fts_lfree(root);
+ free(parent);
+mem2: free(sp->fts_path);
+mem1: free(sp);
+ return (NULL);
+}
+
+static void
+fts_load(sp, p)
+ FTS *sp;
+ register FTSENT *p;
+{
+ register int len;
+ register char *cp;
+
+ /*
+ * Load the stream structure for the next traversal. Since we don't
+ * actually enter the directory until after the preorder visit, set
+ * the fts_accpath field specially so the chdir gets done to the right
+ * place and the user can access the first node. From fts_open it's
+ * known that the path will fit.
+ */
+ len = p->fts_pathlen = p->fts_namelen;
+ memmove(sp->fts_path, p->fts_name, len + 1);
+ if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) {
+ len = strlen(++cp);
+ memmove(p->fts_name, cp, len + 1);
+ p->fts_namelen = len;
+ }
+ p->fts_accpath = p->fts_path = sp->fts_path;
+ sp->fts_dev = p->fts_dev;
+}
+
+int
+fts_close(sp)
+ FTS *sp;
+{
+ register FTSENT *freep, *p;
+ int saved_errno;
+
+ /*
+ * This still works if we haven't read anything -- the dummy structure
+ * points to the root list, so we step through to the end of the root
+ * list which has a valid parent pointer.
+ */
+ if (sp->fts_cur) {
+ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
+ freep = p;
+ p = p->fts_link ? p->fts_link : p->fts_parent;
+ free(freep);
+ }
+ free(p);
+ }
+
+ /* Free up child linked list, sort array, path buffer. */
+ if (sp->fts_child)
+ fts_lfree(sp->fts_child);
+ if (sp->fts_array)
+ free(sp->fts_array);
+ free(sp->fts_path);
+
+ /* Return to original directory, save errno if necessary. */
+ if (!ISSET(FTS_NOCHDIR)) {
+ saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
+ (void)close(sp->fts_rfd);
+ }
+
+ /* Free up the stream pointer. */
+ free(sp);
+
+ /* Set errno and return. */
+ if (!ISSET(FTS_NOCHDIR) && saved_errno) {
+ errno = saved_errno;
+ return (-1);
+ }
+ return (0);
+}
+
+/*
+ * Special case a root of "/" so that slashes aren't appended which would
+ * cause paths to be written as "//foo".
+ */
+#define NAPPEND(p) \
+ (p->fts_level == FTS_ROOTLEVEL && p->fts_pathlen == 1 && \
+ p->fts_path[0] == '/' ? 0 : p->fts_pathlen)
+
+FTSENT *
+fts_read(sp)
+ register FTS *sp;
+{
+ register FTSENT *p, *tmp;
+ register int instr;
+ register char *t;
+ int saved_errno;
+
+ /* If finished or unrecoverable error, return NULL. */
+ if (sp->fts_cur == NULL || ISSET(FTS_STOP))
+ return (NULL);
+
+ /* Set current node pointer. */
+ p = sp->fts_cur;
+
+ /* Save and zero out user instructions. */
+ instr = p->fts_instr;
+ p->fts_instr = FTS_NOINSTR;
+
+ /* Any type of file may be re-visited; re-stat and re-turn. */
+ if (instr == FTS_AGAIN) {
+ p->fts_info = fts_stat(sp, p, 0);
+ return (p);
+ }
+
+ /*
+ * Following a symlink -- SLNONE test allows application to see
+ * SLNONE and recover. If indirecting through a symlink, have
+ * keep a pointer to current location. If unable to get that
+ * pointer, follow fails.
+ */
+ if (instr == FTS_FOLLOW &&
+ (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
+ p->fts_info = fts_stat(sp, p, 1);
+ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR))
+ if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
+ } else
+ p->fts_flags |= FTS_SYMFOLLOW;
+ return (p);
+ }
+
+ /* Directory in pre-order. */
+ if (p->fts_info == FTS_D) {
+ /* If skipped or crossed mount point, do post-order visit. */
+ if (instr == FTS_SKIP ||
+ (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev) ) {
+ if (p->fts_flags & FTS_SYMFOLLOW)
+ (void)close(p->fts_symfd);
+ if (sp->fts_child) {
+ fts_lfree(sp->fts_child);
+ sp->fts_child = NULL;
+ }
+ p->fts_info = FTS_DP;
+ return (p);
+ }
+
+ /* Rebuild if only read the names and now traversing. */
+ if (sp->fts_child && sp->fts_options & FTS_NAMEONLY) {
+ sp->fts_options &= ~FTS_NAMEONLY;
+ fts_lfree(sp->fts_child);
+ sp->fts_child = NULL;
+ }
+
+ /*
+ * Cd to the subdirectory.
+ *
+ * If have already read and now fail to chdir, whack the list
+ * to make the names come out right, and set the parent errno
+ * so the application will eventually get an error condition.
+ * Set the FTS_DONTCHDIR flag so that when we logically change
+ * directories back to the parent we don't do a chdir.
+ *
+ * If haven't read do so. If the read fails, fts_build sets
+ * FTS_STOP or the fts_info field of the node.
+ */
+ if (sp->fts_child) {
+ if (CHDIR(sp, p->fts_accpath)) {
+ p->fts_errno = errno;
+ p->fts_flags |= FTS_DONTCHDIR;
+ for (p = sp->fts_child; p; p = p->fts_link)
+ p->fts_accpath =
+ p->fts_parent->fts_accpath;
+ }
+ } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
+ if (ISSET(FTS_STOP))
+ return (NULL);
+ return (p);
+ }
+ p = sp->fts_child;
+ sp->fts_child = NULL;
+ goto name;
+ }
+
+ /* Move to the next node on this level. */
+next: tmp = p;
+ if ( (p = p->fts_link) ) {
+ free(tmp);
+
+ /*
+ * If reached the top, return to the original directory, and
+ * load the paths for the next root.
+ */
+ if (p->fts_level == FTS_ROOTLEVEL) {
+ if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ fts_load(sp, p);
+ return (sp->fts_cur = p);
+ }
+
+ /*
+ * User may have called fts_set on the node. If skipped,
+ * ignore. If followed, get a file descriptor so we can
+ * get back if necessary.
+ */
+ if (p->fts_instr == FTS_SKIP)
+ goto next;
+ if (p->fts_instr == FTS_FOLLOW) {
+ p->fts_info = fts_stat(sp, p, 1);
+ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR))
+ if ((p->fts_symfd =
+ open(".", O_RDONLY, 0)) < 0) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
+ } else
+ p->fts_flags |= FTS_SYMFOLLOW;
+ p->fts_instr = FTS_NOINSTR;
+ }
+
+name: t = sp->fts_path + NAPPEND(p->fts_parent);
+ *t++ = '/';
+ memmove(t, p->fts_name, p->fts_namelen + 1);
+ return (sp->fts_cur = p);
+ }
+
+ /* Move up to the parent node. */
+ p = tmp->fts_parent;
+ free(tmp);
+
+ if (p->fts_level == FTS_ROOTPARENTLEVEL) {
+ /*
+ * Done; free everything up and set errno to 0 so the user
+ * can distinguish between error and EOF.
+ */
+ free(p);
+ errno = 0;
+ return (sp->fts_cur = NULL);
+ }
+
+ /* Nul terminate the pathname. */
+ sp->fts_path[p->fts_pathlen] = '\0';
+
+ /*
+ * Return to the parent directory. If at a root node or came through
+ * a symlink, go back through the file descriptor. Otherwise, cd up
+ * one directory.
+ */
+ if (p->fts_level == FTS_ROOTLEVEL) {
+ if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ } else if (p->fts_flags & FTS_SYMFOLLOW) {
+ if (FCHDIR(sp, p->fts_symfd)) {
+ saved_errno = errno;
+ (void)close(p->fts_symfd);
+ errno = saved_errno;
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ (void)close(p->fts_symfd);
+ } else if (!(p->fts_flags & FTS_DONTCHDIR)) {
+ if (CHDIR(sp, "..")) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ }
+ p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
+ return (sp->fts_cur = p);
+}
+
+/*
+ * Fts_set takes the stream as an argument although it's not used in this
+ * implementation; it would be necessary if anyone wanted to add global
+ * semantics to fts using fts_set. An error return is allowed for similar
+ * reasons.
+ */
+/* ARGSUSED */
+int
+fts_set(sp, p, instr)
+ FTS *sp;
+ FTSENT *p;
+ int instr;
+{
+ if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW &&
+ instr != FTS_NOINSTR && instr != FTS_SKIP) {
+ errno = EINVAL;
+ return (1);
+ }
+ p->fts_instr = instr;
+ return (0);
+}
+
+FTSENT *
+fts_children(sp, instr)
+ register FTS *sp;
+ int instr;
+{
+ register FTSENT *p;
+ int fd;
+
+ if (instr && instr != FTS_NAMEONLY) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* Set current node pointer. */
+ p = sp->fts_cur;
+
+ /*
+ * Errno set to 0 so user can distinguish empty directory from
+ * an error.
+ */
+ errno = 0;
+
+ /* Fatal errors stop here. */
+ if (ISSET(FTS_STOP))
+ return (NULL);
+
+ /* Return logical hierarchy of user's arguments. */
+ if (p->fts_info == FTS_INIT)
+ return (p->fts_link);
+
+ /*
+ * If not a directory being visited in pre-order, stop here. Could
+ * allow FTS_DNR, assuming the user has fixed the problem, but the
+ * same effect is available with FTS_AGAIN.
+ */
+ if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */)
+ return (NULL);
+
+ /* Free up any previous child list. */
+ if (sp->fts_child)
+ fts_lfree(sp->fts_child);
+
+ if (instr == FTS_NAMEONLY) {
+ sp->fts_options |= FTS_NAMEONLY;
+ instr = BNAMES;
+ } else
+ instr = BCHILD;
+
+ /*
+ * If using chdir on a relative path and called BEFORE fts_read does
+ * its chdir to the root of a traversal, we can lose -- we need to
+ * chdir into the subdirectory, and we don't know where the current
+ * directory is, so we can't get back so that the upcoming chdir by
+ * fts_read will work.
+ */
+ if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' ||
+ ISSET(FTS_NOCHDIR))
+ return (sp->fts_child = fts_build(sp, instr));
+
+ if ((fd = open(".", O_RDONLY, 0)) < 0)
+ return (NULL);
+ sp->fts_child = fts_build(sp, instr);
+ if (fchdir(fd))
+ return (NULL);
+ (void)close(fd);
+ return (sp->fts_child);
+}
+
+/*
+ * This is the tricky part -- do not casually change *anything* in here. The
+ * idea is to build the linked list of entries that are used by fts_children
+ * and fts_read. There are lots of special cases.
+ *
+ * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is
+ * set and it's a physical walk (so that symbolic links can't be directories),
+ * we can do things quickly. First, if it's a 4.4BSD file system, the type
+ * of the file is in the directory entry. Otherwise, we assume that the number
+ * of subdirectories in a node is equal to the number of links to the parent.
+ * The former skips all stat calls. The latter skips stat calls in any leaf
+ * directories and for any files after the subdirectories in the directory have
+ * been found, cutting the stat calls by about 2/3.
+ */
+static FTSENT *
+fts_build(sp, type)
+ register FTS *sp;
+ int type;
+{
+ register struct dirent *dp;
+ register FTSENT *p, *head;
+ register int nitems;
+ FTSENT *cur, *tail;
+ DIR *dirp;
+ void *adjaddr;
+ int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno;
+ char *cp;
+
+ /* Set current node pointer. */
+ cur = sp->fts_cur;
+
+ /*
+ * Open the directory for reading. If this fails, we're done.
+ * If being called from fts_read, set the fts_info field.
+ */
+#ifdef FTS_WHITEOUT
+ if (ISSET(FTS_WHITEOUT))
+ oflag = DTF_NODUP|DTF_REWIND;
+ else
+ oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND;
+#else
+#define __opendir2(path, flag) opendir(path)
+#endif
+ if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) {
+ if (type == BREAD) {
+ cur->fts_info = FTS_DNR;
+ cur->fts_errno = errno;
+ }
+ return (NULL);
+ }
+
+ /*
+ * Nlinks is the number of possible entries of type directory in the
+ * directory if we're cheating on stat calls, 0 if we're not doing
+ * any stat calls at all, -1 if we're doing stats on everything.
+ */
+ if (type == BNAMES)
+ nlinks = 0;
+ else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL))
+ nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
+ else
+ nlinks = -1;
+
+#ifdef notdef
+ (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink);
+ (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n",
+ ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT));
+#endif
+ /*
+ * If we're going to need to stat anything or we want to descend
+ * and stay in the directory, chdir. If this fails we keep going,
+ * but set a flag so we don't chdir after the post-order visit.
+ * We won't be able to stat anything, but we can still return the
+ * names themselves. Note, that since fts_read won't be able to
+ * chdir into the directory, it will have to return different path
+ * names than before, i.e. "a/b" instead of "b". Since the node
+ * has already been visited in pre-order, have to wait until the
+ * post-order visit to return the error. There is a special case
+ * here, if there was nothing to stat then it's not an error to
+ * not be able to stat. This is all fairly nasty. If a program
+ * needed sorted entries or stat information, they had better be
+ * checking FTS_NS on the returned nodes.
+ */
+ cderrno = 0;
+ if (nlinks || type == BREAD)
+ if (FCHDIR(sp, dirfd(dirp))) {
+ if (nlinks && type == BREAD)
+ cur->fts_errno = errno;
+ cur->fts_flags |= FTS_DONTCHDIR;
+ descend = 0;
+ cderrno = errno;
+ } else
+ descend = 1;
+ else
+ descend = 0;
+
+ /*
+ * Figure out the max file name length that can be stored in the
+ * current path -- the inner loop allocates more path as necessary.
+ * We really wouldn't have to do the maxlen calculations here, we
+ * could do them in fts_read before returning the path, but it's a
+ * lot easier here since the length is part of the dirent structure.
+ *
+ * If not changing directories set a pointer so that can just append
+ * each new name into the path.
+ */
+ maxlen = sp->fts_pathlen - cur->fts_pathlen - 1;
+ len = NAPPEND(cur);
+ if (ISSET(FTS_NOCHDIR)) {
+ cp = sp->fts_path + len;
+ *cp++ = '/';
+ }
+
+ level = cur->fts_level + 1;
+
+ /* Read the directory, attaching each entry to the `link' pointer. */
+ adjaddr = NULL;
+ for (head = tail = NULL, nitems = 0; (dp = readdir(dirp)); ) {
+ if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
+ continue;
+
+ if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL)
+ goto mem1;
+ if (dp->d_namlen > maxlen) {
+ if (fts_palloc(sp, (size_t)dp->d_namlen)) {
+ /*
+ * No more memory for path or structures. Save
+ * errno, free up the current structure and the
+ * structures already allocated.
+ */
+mem1: saved_errno = errno;
+ if (p)
+ free(p);
+ fts_lfree(head);
+ (void)closedir(dirp);
+ errno = saved_errno;
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ adjaddr = sp->fts_path;
+ maxlen = sp->fts_pathlen - sp->fts_cur->fts_pathlen - 1;
+ }
+
+ p->fts_pathlen = len + dp->d_namlen + 1;
+ p->fts_parent = sp->fts_cur;
+ p->fts_level = level;
+
+#ifdef FTS_WHITEOUT
+ if (dp->d_type == DT_WHT)
+ p->fts_flags |= FTS_ISW;
+#endif
+
+ if (cderrno) {
+ if (nlinks) {
+ p->fts_info = FTS_NS;
+ p->fts_errno = cderrno;
+ } else
+ p->fts_info = FTS_NSOK;
+ p->fts_accpath = cur->fts_accpath;
+ } else if (nlinks == 0
+#ifdef DT_DIR
+ || (nlinks > 0 &&
+ dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
+#endif
+ ) {
+ p->fts_accpath =
+ ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
+ p->fts_info = FTS_NSOK;
+ } else {
+ /* Build a file name for fts_stat to stat. */
+ if (ISSET(FTS_NOCHDIR)) {
+ p->fts_accpath = p->fts_path;
+ memmove(cp, p->fts_name, p->fts_namelen + 1);
+ } else
+ p->fts_accpath = p->fts_name;
+ /* Stat it. */
+ p->fts_info = fts_stat(sp, p, 0);
+
+ /* Decrement link count if applicable. */
+ if (nlinks > 0 && (p->fts_info == FTS_D ||
+ p->fts_info == FTS_DC || p->fts_info == FTS_DOT))
+ --nlinks;
+ }
+
+ /* We walk in directory order so "ls -f" doesn't get upset. */
+ p->fts_link = NULL;
+ if (head == NULL)
+ head = tail = p;
+ else {
+ tail->fts_link = p;
+ tail = p;
+ }
+ ++nitems;
+ }
+ (void)closedir(dirp);
+
+ /*
+ * If had to realloc the path, adjust the addresses for the rest
+ * of the tree.
+ */
+ if (adjaddr)
+ fts_padjust(sp, adjaddr);
+
+ /*
+ * If not changing directories, reset the path back to original
+ * state.
+ */
+ if (ISSET(FTS_NOCHDIR)) {
+ if (cp - 1 > sp->fts_path)
+ --cp;
+ *cp = '\0';
+ }
+
+ /*
+ * If descended after called from fts_children or after called from
+ * fts_read and nothing found, get back. At the root level we use
+ * the saved fd; if one of fts_open()'s arguments is a relative path
+ * to an empty directory, we wind up here with no other way back. If
+ * can't get back, we're done.
+ */
+ if (descend && (type == BCHILD || !nitems) &&
+ (cur->fts_level == FTS_ROOTLEVEL ?
+ FCHDIR(sp, sp->fts_rfd) : CHDIR(sp, ".."))) {
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ return (NULL);
+ }
+
+ /* If didn't find anything, return NULL. */
+ if (!nitems) {
+ if (type == BREAD)
+ cur->fts_info = FTS_DP;
+ return (NULL);
+ }
+
+ /* Sort the entries. */
+ if (sp->fts_compar && nitems > 1)
+ head = fts_sort(sp, head, nitems);
+ return (head);
+}
+
+static u_short
+fts_stat(sp, p, follow)
+ FTS *sp;
+ register FTSENT *p;
+ int follow;
+{
+ register FTSENT *t;
+ register dev_t dev;
+ register ino_t ino;
+ struct stat *sbp, sb;
+ int saved_errno;
+
+ /* If user needs stat info, stat buffer already allocated. */
+ sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
+
+#ifdef FTS_WHITEOUT
+ /* check for whiteout */
+ if (p->fts_flags & FTS_ISW) {
+ if (sbp != &sb) {
+ memset(sbp, '\0', sizeof (*sbp));
+ sbp->st_mode = S_IFWHT;
+ }
+ return (FTS_W);
+ }
+#endif
+
+ /*
+ * If doing a logical walk, or application requested FTS_FOLLOW, do
+ * a stat(2). If that fails, check for a non-existent symlink. If
+ * fail, set the errno from the stat call.
+ */
+ if (ISSET(FTS_LOGICAL) || follow) {
+ if (stat(p->fts_accpath, sbp)) {
+ saved_errno = errno;
+ if (!lstat(p->fts_accpath, sbp)) {
+ errno = 0;
+ return (FTS_SLNONE);
+ }
+ p->fts_errno = saved_errno;
+ goto err;
+ }
+ } else if (lstat(p->fts_accpath, sbp)) {
+ p->fts_errno = errno;
+err: memset(sbp, 0, sizeof(struct stat));
+ return (FTS_NS);
+ }
+
+ if (S_ISDIR(sbp->st_mode)) {
+ /*
+ * Set the device/inode. Used to find cycles and check for
+ * crossing mount points. Also remember the link count, used
+ * in fts_build to limit the number of stat calls. It is
+ * understood that these fields are only referenced if fts_info
+ * is set to FTS_D.
+ */
+ dev = p->fts_dev = sbp->st_dev;
+ ino = p->fts_ino = sbp->st_ino;
+ p->fts_nlink = sbp->st_nlink;
+
+ if (ISDOT(p->fts_name))
+ return (FTS_DOT);
+
+ /*
+ * Cycle detection is done by brute force when the directory
+ * is first encountered. If the tree gets deep enough or the
+ * number of symbolic links to directories is high enough,
+ * something faster might be worthwhile.
+ */
+ for (t = p->fts_parent;
+ t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent)
+ if (ino == t->fts_ino && dev == t->fts_dev) {
+ p->fts_cycle = t;
+ return (FTS_DC);
+ }
+ return (FTS_D);
+ }
+ if (S_ISLNK(sbp->st_mode))
+ return (FTS_SL);
+ if (S_ISREG(sbp->st_mode))
+ return (FTS_F);
+ return (FTS_DEFAULT);
+}
+
+static FTSENT *
+fts_sort(sp, head, nitems)
+ FTS *sp;
+ FTSENT *head;
+ register int nitems;
+{
+ register FTSENT **ap, *p;
+
+ /*
+ * Construct an array of pointers to the structures and call qsort(3).
+ * Reassemble the array in the order returned by qsort. If unable to
+ * sort for memory reasons, return the directory entries in their
+ * current order. Allocate enough space for the current needs plus
+ * 40 so don't realloc one entry at a time.
+ */
+ if (nitems > sp->fts_nitems) {
+ sp->fts_nitems = nitems + 40;
+ if ((sp->fts_array = realloc(sp->fts_array,
+ (size_t)(sp->fts_nitems * sizeof(FTSENT *)))) == NULL) {
+ sp->fts_nitems = 0;
+ return (head);
+ }
+ }
+ for (ap = sp->fts_array, p = head; p; p = p->fts_link)
+ *ap++ = p;
+ qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar);
+ for (head = *(ap = sp->fts_array); --nitems; ++ap)
+ ap[0]->fts_link = ap[1];
+ ap[0]->fts_link = NULL;
+ return (head);
+}
+
+static FTSENT *
+fts_alloc(sp, name, namelen)
+ FTS *sp;
+ char *name;
+ register int namelen;
+{
+ register FTSENT *p;
+ size_t len;
+
+ /*
+ * The file name is a variable length array and no stat structure is
+ * necessary if the user has set the nostat bit. Allocate the FTSENT
+ * structure, the file name and the stat structure in one chunk, but
+ * be careful that the stat structure is reasonably aligned. Since the
+ * fts_name field is declared to be of size 1, the fts_name pointer is
+ * namelen + 2 before the first possible address of the stat structure.
+ */
+ len = sizeof(FTSENT) + namelen;
+ if (!ISSET(FTS_NOSTAT))
+ len += sizeof(struct stat) + ALIGNBYTES;
+ if ((p = malloc(len)) == NULL)
+ return (NULL);
+
+ /* Copy the name plus the trailing NULL. */
+ memmove(p->fts_name, name, namelen + 1);
+
+ if (!ISSET(FTS_NOSTAT))
+ p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2);
+ p->fts_namelen = namelen;
+ p->fts_path = sp->fts_path;
+ p->fts_errno = 0;
+ p->fts_flags = 0;
+ p->fts_instr = FTS_NOINSTR;
+ p->fts_number = 0;
+ p->fts_pointer = NULL;
+ return (p);
+}
+
+static void
+fts_lfree(head)
+ register FTSENT *head;
+{
+ register FTSENT *p;
+
+ /* Free a linked list of structures. */
+ while ( (p = head) ) {
+ head = head->fts_link;
+ free(p);
+ }
+}
+
+/*
+ * Allow essentially unlimited paths; find, rm, ls should all work on any tree.
+ * Most systems will allow creation of paths much longer than MAXPATHLEN, even
+ * though the kernel won't resolve them. Add the size (not just what's needed)
+ * plus 256 bytes so don't realloc the path 2 bytes at a time.
+ */
+static int
+fts_palloc(sp, more)
+ FTS *sp;
+ size_t more;
+{
+ sp->fts_pathlen += more + 256;
+ sp->fts_path = realloc(sp->fts_path, (size_t)sp->fts_pathlen);
+ return (sp->fts_path == NULL);
+}
+
+/*
+ * When the path is realloc'd, have to fix all of the pointers in structures
+ * already returned.
+ */
+static void
+fts_padjust(sp, addr)
+ FTS *sp;
+ void *addr;
+{
+ FTSENT *p;
+
+#define ADJUST(p) { \
+ (p)->fts_accpath = \
+ (char *)addr + ((p)->fts_accpath - (p)->fts_path); \
+ (p)->fts_path = addr; \
+}
+ /* Adjust the current set of children. */
+ for (p = sp->fts_child; p; p = p->fts_link)
+ ADJUST(p);
+
+ /* Adjust the rest of the tree. */
+ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
+ ADJUST(p);
+ p = p->fts_link ? p->fts_link : p->fts_parent;
+ }
+}
+
+static size_t
+fts_maxarglen(argv)
+ char * const *argv;
+{
+ size_t len, max;
+
+ for (max = 0; *argv; ++argv)
+ if ((len = strlen(*argv)) > max)
+ max = len;
+ return (max);
+}
diff --git a/lib/libc/stdlib/calloc.3 b/lib/libc/gen/getbootfile.3
index 0ca15e5..3c2e783 100644
--- a/lib/libc/stdlib/calloc.3
+++ b/lib/libc/gen/getbootfile.3
@@ -1,10 +1,6 @@
-.\" Copyright (c) 1991, 1993
+.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" the American National Standards Committee X3, on Information
-.\" Processing Systems.
-.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
@@ -33,38 +29,42 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)calloc.3 8.1 (Berkeley) 6/4/93
+.\" From: @(#)gethostname.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
-.Dd June 4, 1993
-.Dt CALLOC 3
+.Dd September 23, 1994
+.Dt GETBOOTFILE 3
.Os
.Sh NAME
-.Nm calloc
-.Nd allocate clean memory (zero initialized space)
+.Nm getbootfile
+.Nd get kernel boot file name
.Sh SYNOPSIS
-.Fd #include <stdlib.h>
-.Ft void *
-.Fn calloc "size_t nmemb" "size_t size"
+.Fd #include <paths.h>
+.Ft const char *
+.Fn getbootfile void
.Sh DESCRIPTION
The
-.Fn calloc
-function allocates space for an array of
-.Fa nmemb
-objects, each of whose size is
-.Fa size .
-The space is initialized to all bits zero.
+.Fn getbootfile
+function retrieves the full pathname of the file from which the
+current kernel was loaded, and returns a static pointer to the name.
+A read/write interface to this information is available via the
+.Xr sysctl 3
+MIB variable
+.Dq Li kern.bootfile .
.Sh RETURN VALUES
-The
-.Fn calloc
-function returns
-a pointer to the
-the allocated space if successful; otherwise a null pointer is returned.
+If the call succeeds a string giving the pathname is returned. If it
+fails, a a null pointer is returned and an error code is
+placed in the global location
+.Va errno .
.Sh SEE ALSO
-.Xr malloc 3 ,
-.Xr realloc 3 ,
-.Xr free 3 ,
-.Sh STANDARDS
+.Xr sysctl 3
+.Sh BUGS
+If the boot blocks have not been modified to pass this information into
+the kernel at boot time, the static string
+.Dq Pa /kernel
+is returned instead of the real boot file.
+.Sh HISTORY
The
-.Fn calloc
-function conforms to
-.St -ansiC .
+.Fn getbootfile
+function call appeared in
+.Fx 2.0 .
diff --git a/lib/libc/gen/getbootfile.c b/lib/libc/gen/getbootfile.c
new file mode 100644
index 0000000..5b293a7
--- /dev/null
+++ b/lib/libc/gen/getbootfile.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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[] = "From: @(#)gethostname.c 8.1 (Berkeley) 6/4/93";*/
+static const char rcsid[] =
+ "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
+const char *
+getbootfile(void)
+{
+ static char name[MAXPATHLEN];
+ size_t size = sizeof name;
+ int mib[2];
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_BOOTFILE;
+ if (sysctl(mib, 2, name, &size, NULL, 0) == -1)
+ return ("/kernel");
+ return (name);
+}
diff --git a/lib/libc/gen/getbsize.3 b/lib/libc/gen/getbsize.3
index 0455573..48ef7ac 100644
--- a/lib/libc/gen/getbsize.3
+++ b/lib/libc/gen/getbsize.3
@@ -43,7 +43,7 @@
.Fn getbsize "int *headerlenp" "long *blocksizep"
.Sh DESCRIPTION
The
-.Nm getbsize
+.Fn getbsize
function determines the user's preferred block size based on the value of the
.Dq BLOCKSIZE
environment variable; see
@@ -51,7 +51,7 @@ environment variable; see
for details on its use and format.
.Pp
The
-.Nm getbsize
+.Fn getbsize
function returns a pointer to a null-terminated string describing
the block size, something like
.Dq 1K-blocks .
@@ -74,6 +74,6 @@ a block size of 512 bytes.
.Xr environ 7
.Sh HISTORY
The
-.Nm getbsize
-function call appeared in
+.Fn getbsize
+function first appeared in
.Bx 4.4 .
diff --git a/lib/libc/gen/getcap.3 b/lib/libc/gen/getcap.3
index f8fcc81..55507a4 100644
--- a/lib/libc/gen/getcap.3
+++ b/lib/libc/gen/getcap.3
@@ -34,7 +34,7 @@
.\"
.\" @(#)getcap.3 8.4 (Berkeley) 5/13/94
.\"
-.Dd "May 13, 1994"
+.Dd May 13, 1994
.Dt GETCAP 3
.Os
.Sh NAME
@@ -58,7 +58,7 @@
.Ft int
.Fn cgetmatch "char *buf" "char *name"
.Ft char *
-.Fn cgetcap "char *buf" "char *cap" "char type"
+.Fn cgetcap "char *buf" "char *cap" "int type"
.Ft int
.Fn cgetnum "char *buf" "char *cap" "long *num"
.Ft int
@@ -83,8 +83,9 @@ and returns a pointer to a
.Xr malloc Ns \&'d
copy of it in
.Fa buf .
-.Nm Cgetent
-will first look for files ending in
+The
+.Fn cgetent
+function will first look for files ending in
.Nm .db
(see
.Xr cap_mkdb 1)
@@ -98,7 +99,7 @@ must be retained through all subsequent calls to
and
.Fn cgetustr ,
but may then be
-.Xr free Ns \&'d.
+.Xr free 3 Ns \&'d.
On success 0 is returned, 1 if the returned
record contains an unresolved
.Nm tc
@@ -111,13 +112,14 @@ and \-3 if a potential reference loop is detected (see
.Ic tc=
comments below).
.Pp
-.Nm Cgetset
-enables the addition of a character buffer containing a single capability
+The
+.Fn cgetset
+function enables the addition of a character buffer containing a single capability
record entry
to the capability database.
Conceptually, the entry is added as the first ``file'' in the database, and
is therefore searched first on the call to
-.Nm cgetent .
+.Fn cgetent .
The entry is passed in
.Fa ent .
If
@@ -125,29 +127,32 @@ If
is
.Dv NULL ,
the current entry is removed from the database.
-.Nm Cgetset
+A call to
+.Fn cgetset
must precede the database traversal. It must be called before the
-.Nm cgetent
+.Fn cgetent
call. If a sequential access is being performed (see below), it must be called
before the first sequential access call (
-.Nm cgetfirst
+.Fn cgetfirst
or
-.Nm cgetnext
+.Fn cgetnext
), or be directly preceded by a
-.Nm cgetclose
+.Fn cgetclose
call.
On success 0 is returned and \-1 on failure.
.Pp
-.Nm Cgetmatch
-will return 0 if
+The
+.Fn cgetmatch
+function will return 0 if
.Fa name
is one of the names of the capability record
.Fa buf ,
\-1 if
not.
.Pp
-.Nm Cgetcap
-searches the capability record
+The
+.Fn cgetcap
+function searches the capability record
.Fa buf
for the capability
.Fa cap
@@ -169,8 +174,9 @@ found. The end of the capability value is signaled by a `:' or
.Dv NUL
(see below for capability database syntax).
.Pp
-.Nm Cgetnum
-retrieves the value of the numeric capability
+The
+.Fn cgetnum
+function retrieves the value of the numeric capability
.Fa cap
from the capability record pointed to by
.Fa buf .
@@ -181,8 +187,9 @@ pointed to by
0 is returned on success, \-1 if the requested numeric capability couldn't
be found.
.Pp
-.Nm Cgetstr
-retrieves the value of the string capability
+The
+.Fn cgetstr
+function retrieves the value of the string capability
.Fa cap
from the capability record pointed to by
.Fa buf .
@@ -200,28 +207,33 @@ is returned on success, \-1 if the requested string capability couldn't
be found, \-2 if a system error was encountered (storage allocation
failure).
.Pp
-.Nm Cgetustr
-is identical to
-.Nm cgetstr
+The
+.Fn cgetustr
+function is identical to
+.Fn cgetstr
except that it does not expand special characters, but rather returns each
character of the capability string literally.
.Pp
-.Nm Cgetfirst ,
-.Nm cgetnext ,
-comprise a function group that provides for sequential
+The
+.Fn cgetfirst
+and
+.Fn cgetnext
+functions comprise a function group that provides for sequential
access of the
.Dv NULL
pointer terminated array of file names,
.Fa db_array .
-.Nm Cgetfirst
-returns the first record in the database and resets the access
+The
+.Fn cgetfirst
+function returns the first record in the database and resets the access
to the first record.
-.Nm Cgetnext
-returns the next record in the database with respect to the
+The
+.Fn cgetnext
+function returns the next record in the database with respect to the
record returned by the previous
-.Nm cgetfirst
+.Fn cgetfirst
or
-.Nm cgetnext
+.Fn cgetnext
call. If there is no such previous call, the first record in the database is
returned.
Each record is returned in a
@@ -242,10 +254,11 @@ is returned if a potential reference loop is detected (see
comments below).
Upon completion of database (0 return) the database is closed.
.Pp
-.Nm Cgetclose
-closes the sequential access and frees any memory and file descriptors
+The
+.Fn cgetclose
+function closes the sequential access and frees any memory and file descriptors
being used. Note that it does not erase the buffer pushed by a call to
-.Nm cgetset .
+.Fn cgetset .
.Sh CAPABILITY DATABASE SYNTAX
Capability databases are normally
.Tn ASCII
@@ -301,16 +314,17 @@ Capability records describe a set of (name, value) bindings. Names may
have multiple values bound to them. Different values for a name are
distinguished by their
.Fa types .
-.Nm Cgetcap
-will return a pointer to a value of a name given the capability name and
-the type of the value.
+The
+.Fn cgetcap
+function will return a pointer to a value of a name given the capability
+name and the type of the value.
.Pp
The types `#' and `=' are conventionally used to denote numeric and
string typed values, but no restriction on those types is enforced. The
functions
-.Nm cgetnum
+.Fn cgetnum
and
-.Nm cgetstr
+.Fn cgetstr
can be used to implement the traditional syntax and semantics of `#'
and `='.
Typeless capabilities are typically used to denote boolean objects with
@@ -380,7 +394,7 @@ file2:
.Ed
.Pp
The records are extracted by calling
-.Nm cgetent
+.Fn cgetent
with file1 preceding file2.
In the capability record new in file1, fript=bar overrides the definition
of fript=foo interpolated from the capability record old in file2,
@@ -392,9 +406,9 @@ tc=old is important here. If they were after, the definitions in old
would take precedence.
.Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICS
Two types are predefined by
-.Nm cgetnum
+.Fn cgetnum
and
-.Nm cgetstr :
+.Fn cgetstr :
.Bl -column "nameXnumber"
.Sm off
.It Em name No \&# Em number Ta numeric
@@ -431,7 +445,7 @@ String capability values may contain any character. Non-printable
codes, new lines, and colons may be conveniently represented by the use
of escape sequences:
.Bl -column "\e\|X,X\e\|X" "(ASCII octal nnn)"
-^X ('\fIX\fP' & 037) control-\fIX\fP
+^X ('X' & 037) control-X
\e\|b, \e\|B (ASCII 010) backspace
\e\|t, \e\|T (ASCII 011) tab
\e\|n, \e\|N (ASCII 012) line feed (newline)
@@ -441,7 +455,7 @@ of escape sequences:
\e\|c, \e\|C (:) colon
\e\|\e (\e\|) back slash
\e\|^ (^) caret
-\e\|\fInnn\fP (ASCII octal \fInnn\fP)
+\e\|nnn (ASCII octal nnn)
.El
.Pp
A `\|\e' may be followed by up to three octal digits directly specifies
@@ -455,26 +469,28 @@ are typically used to denote the end of strings; many applications
use `\e\|200' to represent a
.Dv NUL .
.Sh DIAGNOSTICS
-.Nm Cgetent ,
-.Nm cgetset ,
-.Nm cgetmatch ,
-.Nm cgetnum ,
-.Nm cgetstr ,
-.Nm cgetustr ,
-.Nm cgetfirst ,
+.Fn Cgetent ,
+.Fn cgetset ,
+.Fn cgetmatch ,
+.Fn cgetnum ,
+.Fn cgetstr ,
+.Fn cgetustr ,
+.Fn cgetfirst ,
and
-.Nm cgetnext
+.Fn cgetnext
return a value greater than or equal to 0 on success and a value less
than 0 on failure.
-.Nm Cgetcap
-returns a character pointer on success and a
+The
+.Fn cgetcap
+function returns a character pointer on success and a
.Dv NULL
on failure.
.Pp
-.Nm Cgetent ,
+The
+.Fn cgetent ,
and
-.Nm cgetseq
-may fail and set
+.Fn cgetseq
+functions may fail and set
.Va errno
for any of the errors specified for the library functions:
.Xr fopen 2 ,
@@ -483,11 +499,12 @@ for any of the errors specified for the library functions:
and
.Xr close 2 .
.Pp
-.Nm Cgetent ,
-.Nm cgetset ,
-.Nm cgetstr ,
+The
+.Fn cgetent ,
+.Fn cgetset ,
+.Fn cgetstr ,
and
-.Nm cgetustr
+.Fn cgetustr
may fail and set
.Va errno
as follows:
@@ -504,8 +521,8 @@ Colons (`:') can't be used in names, types, or values.
There are no checks for
.Ic tc= name
loops in
-.Nm cgetent .
+.Fn cgetent .
.Pp
The buffer added to the database by a call to
-.Nm cgetset
+.Fn cgetset
is not unique to the database but is rather prepended to any database used.
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c
index 2a81a35..93d1952 100644
--- a/lib/libc/gen/getcap.c
+++ b/lib/libc/gen/getcap.c
@@ -42,7 +42,7 @@ static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94";
#include <ctype.h>
#include <db.h>
-#include <errno.h>
+#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
@@ -192,13 +192,12 @@ getent(cap, len, db_array, fd, name, depth, nfield)
int fd, depth;
{
DB *capdbp;
- DBT key, data;
register char *r_end, *rp, **db_p;
int myfd, eof, foundit, retval, clen;
char *record, *cbuf;
int tc_not_resolved;
char pbuf[_POSIX_PATH_MAX];
-
+
/*
* Return with ``loop detected'' error if we've recursed more than
* MAX_RECURSION times.
@@ -306,7 +305,7 @@ getent(cap, len, db_array, fd, name, depth, nfield)
for (;;) {
if (bp >= b_end) {
int n;
-
+
n = read(fd, buf, sizeof(buf));
if (n <= 0) {
if (myfd)
@@ -323,7 +322,7 @@ getent(cap, len, db_array, fd, name, depth, nfield)
b_end = buf+n;
bp = buf;
}
-
+
c = *bp++;
if (c == '\n') {
if (rp > record && *(rp-1) == '\\') {
@@ -335,7 +334,7 @@ getent(cap, len, db_array, fd, name, depth, nfield)
*rp++ = c;
/*
- * Enforce loop invariant: if no room
+ * Enforce loop invariant: if no room
* left in record buffer, try to get
* some more.
*/
@@ -364,13 +363,13 @@ getent(cap, len, db_array, fd, name, depth, nfield)
*/
if (eof)
break;
-
+
/*
* Toss blank lines and comments.
*/
if (*record == '\0' || *record == '#')
continue;
-
+
/*
* See if this is the record we want ...
*/
@@ -431,7 +430,7 @@ tc_exp: {
tclen = s - tcstart;
tcend = s;
- iret = getent(&icap, &ilen, db_p, fd, tc, depth+1,
+ iret = getent(&icap, &ilen, db_p, fd, tc, depth+1,
NULL);
newicap = icap; /* Put into a register. */
newilen = ilen;
@@ -447,11 +446,11 @@ tc_exp: {
tc_not_resolved = 1;
/* couldn't resolve tc */
if (iret == -1) {
- *(s - 1) = ':';
+ *(s - 1) = ':';
scan = s - 1;
tc_not_resolved = 1;
continue;
-
+
}
}
/* not interested in name field of tc'ed record */
@@ -514,7 +513,7 @@ tc_exp: {
*/
scan = s-1;
}
-
+
}
/*
* Close file (if we opened it), give back any extra memory, and
@@ -524,17 +523,17 @@ tc_exp: {
(void)close(fd);
*len = rp - record - 1; /* don't count NUL */
if (r_end > rp)
- if ((record =
+ if ((record =
realloc(record, (size_t)(rp - record))) == NULL) {
errno = ENOMEM;
return (-2);
}
-
+
*cap = record;
if (tc_not_resolved)
return (1);
return (0);
-}
+}
static int
cdbget(capdbp, bp, name)
@@ -542,8 +541,6 @@ cdbget(capdbp, bp, name)
char **bp, *name;
{
DBT key, data;
- char *buf;
- int st;
key.data = name;
key.size = strlen(name);
@@ -564,7 +561,7 @@ cdbget(capdbp, bp, name)
key.data = (char *)data.data + 1;
key.size = data.size - 1;
}
-
+
*bp = (char *)data.data + 1;
return (((char *)(data.data))[0] == TCERR ? 1 : 0);
}
@@ -641,7 +638,7 @@ cgetclose()
}
/*
- * Cgetnext() gets either the first or next entry in the logical database
+ * Cgetnext() gets either the first or next entry in the logical database
* specified by db_array. It returns 0 upon completion of the database, 1
* upon returning an entry with more remaining, and -1 if an error occurs.
*/
@@ -702,10 +699,10 @@ cgetnext(bp, db_array)
slash = 1;
else
slash = 0;
- }
+ }
- /*
+ /*
* Line points to a name line.
*/
i = 0;
@@ -745,12 +742,12 @@ cgetnext(bp, db_array)
*rp++ = *cp;
*rp = '\0';
- /*
- * XXX
+ /*
+ * XXX
* Last argument of getent here should be nbuf if we want true
- * sequential access in the case of duplicates.
+ * sequential access in the case of duplicates.
* With NULL, getent will return the first entry found
- * rather than the duplicate entry record. This is a
+ * rather than the duplicate entry record. This is a
* matter of semantics that should be resolved.
*/
status = getent(bp, &dummy, db_array, -1, buf, 0, NULL);
@@ -810,7 +807,11 @@ cgetstr(buf, cap, str)
bp++;
if (*bp == ':' || *bp == '\0')
break; /* drop unfinished escape */
- *mp++ = *bp++ & 037;
+ if (*bp == '?') {
+ *mp++ = '\177';
+ bp++;
+ } else
+ *mp++ = *bp++ & 037;
} else if (*bp == '\\') {
bp++;
if (*bp == ':' || *bp == '\0')
@@ -890,10 +891,10 @@ cgetstr(buf, cap, str)
* Cgetustr retrieves the value of the string capability cap from the
* capability record pointed to by buf. The difference between cgetustr()
* and cgetstr() is that cgetustr does not decode escapes but rather treats
- * all characters literally. A pointer to a NUL terminated malloc'd
- * copy of the string is returned in the char pointed to by str. The
+ * all characters literally. A pointer to a NUL terminated malloc'd
+ * copy of the string is returned in the char pointed to by str. The
* length of the string not including the trailing NUL is returned on success,
- * -1 if the requested string capability couldn't be found, -2 if a system
+ * -1 if the requested string capability couldn't be found, -2 if a system
* error was encountered (storage allocation failure).
*/
int
@@ -1035,10 +1036,10 @@ nfcmp(nf, rec)
{
char *cp, tmp;
int ret;
-
+
for (cp = rec; *cp != ':'; cp++)
;
-
+
tmp = *(cp + 1);
*(cp + 1) = '\0';
ret = strcmp(nf, rec);
diff --git a/lib/libc/gen/getcwd.3 b/lib/libc/gen/getcwd.3
index b66aa1c..8b385be 100644
--- a/lib/libc/gen/getcwd.3
+++ b/lib/libc/gen/getcwd.3
@@ -35,10 +35,11 @@
.Dt GETCWD 3
.Os BSD 4.2
.Sh NAME
-.Nm getcwd
+.Nm getcwd ,
+.Nm getwd
.Nd get working directory pathname
.Sh SYNOPSIS
-.Fd #include <stdio.h>
+.Fd #include <unistd.h>
.Ft char *
.Fn getcwd "char *buf" "size_t size"
.Ft char *
diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c
index 90ecfd7..42ca336 100644
--- a/lib/libc/gen/getcwd.c
+++ b/lib/libc/gen/getcwd.c
@@ -2,9 +2,6 @@
* Copyright (c) 1989, 1991, 1993, 1995
* The Regents of the University of California. All rights reserved.
*
- * This code is derived from software contributed to Berkeley by
- * Jan-Simon Pendry.
- *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -49,165 +46,15 @@ static char sccsid[] = "@(#)getcwd.c 8.5 (Berkeley) 2/7/95";
#include <string.h>
#include <unistd.h>
-static char *getcwd_physical __P((char *, size_t));
-
#define ISDOT(dp) \
(dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \
- dp->d_name[1] == '.' && dp->d_name[2] == '\0'))
+ (dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
char *
getcwd(pt, size)
char *pt;
size_t size;
{
- char *pwd;
- size_t pwdlen;
- dev_t dev;
- ino_t ino;
- struct stat s;
-
- /* Check $PWD -- if it's right, it's fast. */
- if ((pwd = getenv("PWD")) != NULL && pwd[0] == '/' && !stat(pwd, &s)) {
- dev = s.st_dev;
- ino = s.st_ino;
- if (!stat(".", &s) && dev == s.st_dev && ino == s.st_ino) {
- pwdlen = strlen(pwd);
- if (size != 0) {
- if (pwdlen + 1 > size) {
- errno = ERANGE;
- return (NULL);
- }
- } else if ((pt = malloc(pwdlen + 1)) == NULL)
- return (NULL);
- memmove(pt, pwd, pwdlen);
- pt[pwdlen] = '\0';
- return (pt);
- }
- }
-
- return (getcwd_physical(pt, size));
-}
-
-/*
- * char *realpath(const char *path, char resolved_path[MAXPATHLEN]);
- *
- * Find the real name of path, by removing all ".", ".." and symlink
- * components. Returns (resolved) on success, or (NULL) on failure,
- * in which case the path which caused trouble is left in (resolved).
- */
-char *
-realpath(path, resolved)
- const char *path;
- char *resolved;
-{
- struct stat sb;
- int fd, n, rootd, serrno;
- char *p, *q, wbuf[MAXPATHLEN];
-
- /* Save the starting point. */
- if ((fd = open(".", O_RDONLY)) < 0) {
- (void)strcpy(resolved, ".");
- return (NULL);
- }
-
- /*
- * Find the dirname and basename from the path to be resolved.
- * Change directory to the dirname component.
- * lstat the basename part.
- * if it is a symlink, read in the value and loop.
- * if it is a directory, then change to that directory.
- * get the current directory name and append the basename.
- */
- (void)strncpy(resolved, path, MAXPATHLEN - 1);
- resolved[MAXPATHLEN - 1] = '\0';
-loop:
- q = strrchr(resolved, '/');
- if (q != NULL) {
- p = q + 1;
- if (q == resolved)
- q = "/";
- else {
- do {
- --q;
- } while (q > resolved && *q == '/');
- q[1] = '\0';
- q = resolved;
- }
- if (chdir(q) < 0)
- goto err1;
- } else
- p = resolved;
-
- /* Deal with the last component. */
- if (lstat(p, &sb) == 0) {
- if (S_ISLNK(sb.st_mode)) {
- n = readlink(p, resolved, MAXPATHLEN);
- if (n < 0)
- goto err1;
- resolved[n] = '\0';
- goto loop;
- }
- if (S_ISDIR(sb.st_mode)) {
- if (chdir(p) < 0)
- goto err1;
- p = "";
- }
- }
-
- /*
- * Save the last component name and get the full pathname of
- * the current directory.
- */
- (void)strcpy(wbuf, p);
-
- /*
- * Call the inernal internal version of getcwd which
- * does a physical search rather than using the $PWD short-cut
- */
- if (getcwd_physical(resolved, MAXPATHLEN) == 0)
- goto err1;
-
- /*
- * Join the two strings together, ensuring that the right thing
- * happens if the last component is empty, or the dirname is root.
- */
- if (resolved[0] == '/' && resolved[1] == '\0')
- rootd = 1;
- else
- rootd = 0;
-
- if (*wbuf) {
- if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) {
- errno = ENAMETOOLONG;
- goto err1;
- }
- if (rootd == 0)
- (void)strcat(resolved, "/");
- (void)strcat(resolved, wbuf);
- }
-
- /* Go back to where we came from. */
- if (fchdir(fd) < 0) {
- serrno = errno;
- goto err2;
- }
-
- /* It's okay if the close fails, what's an fd more or less? */
- (void)close(fd);
- return (resolved);
-
-err1: serrno = errno;
- (void)fchdir(fd);
-err2: (void)close(fd);
- errno = serrno;
- return (NULL);
-}
-
-static char *
-getcwd_physical(pt, size)
- char *pt;
- size_t size;
-{
register struct dirent *dp;
register DIR *dir;
register dev_t dev;
@@ -232,6 +79,10 @@ getcwd_physical(pt, size)
errno = EINVAL;
return (NULL);
}
+ if (size == 1) {
+ errno = ERANGE;
+ return (NULL);
+ }
ept = pt + size;
} else {
if ((pt = malloc(ptsize = 1024 - 4)) == NULL)
@@ -278,7 +129,7 @@ getcwd_physical(pt, size)
* path to the beginning of the buffer, but it's always
* been that way and stuff would probably break.
*/
- (void)bcopy(bpt, pt, ept - bpt);
+ bcopy(bpt, pt, ept - bpt);
free(up);
return (pt);
}
@@ -304,6 +155,7 @@ getcwd_physical(pt, size)
/* Add trailing slash for next directory. */
*bup++ = '/';
+ *bup = '\0';
/*
* If it's a mount point, have to stat each element because
@@ -341,7 +193,7 @@ getcwd_physical(pt, size)
* Check for length of the current name, preceding slash,
* leading slash.
*/
- if (bpt - pt <= dp->d_namlen + (first ? 1 : 2)) {
+ if (bpt - pt < dp->d_namlen + (first ? 1 : 2)) {
size_t len, off;
if (!ptsize) {
@@ -354,7 +206,7 @@ getcwd_physical(pt, size)
goto err;
bpt = pt + off;
ept = pt + ptsize;
- (void)bcopy(bpt, ept - len, len);
+ bcopy(bpt, ept - len, len);
bpt = ept - len;
}
if (!first)
diff --git a/lib/libc/gen/getdomainname.3 b/lib/libc/gen/getdomainname.3
new file mode 100644
index 0000000..75214d2
--- /dev/null
+++ b/lib/libc/gen/getdomainname.3
@@ -0,0 +1,99 @@
+.\" Copyright (c) 1983, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\" @(#)gethostname.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
+.\"
+.Dd May 6, 1994
+.Dt GETDOMAINNAME 3
+.Os BSD 4.2
+.Sh NAME
+.Nm getdomainname ,
+.Nm setdomainname
+.Nd get/set domain name of current host
+.Sh SYNOPSIS
+.Fd #include <unistd.h>
+.Ft int
+.Fn getdomainname "char *name" "int namelen"
+.Ft int
+.Fn setdomainname "const char *name" "int namelen"
+.Sh DESCRIPTION
+.Fn Getdomainname
+returns the standard domain name for the current processor, as
+previously set by
+.Fn setdomainname .
+The parameter
+.Fa namelen
+specifies the size of the
+.Fa name
+array. The returned name is null-terminated unless insufficient
+space is provided.
+.Pp
+.Fn Setdomainname
+sets the domain name of the host machine to be
+.Fa name ,
+which has length
+.Fa namelen .
+This call is restricted to the super-user and
+is normally used only when the system is bootstrapped.
+.Sh RETURN VALUES
+If the call succeeds a value of 0 is returned. If the call
+fails, a value of -1 is returned and an error code is
+placed in the global location
+.Va errno .
+.Sh ERRORS
+The following errors may be returned by these calls:
+.Bl -tag -width Er
+.It Bq Er EFAULT
+The
+.Fa name
+or
+.Fa namelen
+parameter gave an
+invalid address.
+.It Bq Er EPERM
+The caller tried to set the hostname and was not the super-user.
+.El
+.Sh SEE ALSO
+.Xr gethostid 3 ,
+.Xr gethostname 3 ,
+.Xr sysctl 3
+.Sh BUGS
+Domain names are limited to
+.Dv MAXHOSTNAMELEN
+(from
+.Ao Pa sys/param.h Ac )
+characters, currently 256.
+.Sh HISTORY
+The
+.Fn getdomainname
+function call appeared in
+.Bx 4.2 .
diff --git a/lib/libc/gen/getdomainname.c b/lib/libc/gen/getdomainname.c
new file mode 100644
index 0000000..ba04803
--- /dev/null
+++ b/lib/libc/gen/getdomainname.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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[] = "From: @(#)gethostname.c 8.1 (Berkeley) 6/4/93";
+*/
+static const char rcsid[] =
+ "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
+#include <unistd.h>
+
+int
+getdomainname(name, namelen)
+ char *name;
+ int namelen;
+{
+ int mib[2];
+ size_t size;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_NISDOMAINNAME;
+ size = namelen;
+ if (sysctl(mib, 2, name, &size, NULL, 0) == -1)
+ return (-1);
+ return (0);
+}
diff --git a/lib/libc/gen/getfsent.3 b/lib/libc/gen/getfsent.3
index 1051837..17f3d77 100644
--- a/lib/libc/gen/getfsent.3
+++ b/lib/libc/gen/getfsent.3
@@ -43,7 +43,7 @@
.Nd get file system descriptor file entry
.Sh SYNOPSIS
.Fd #include <fstab.h>
-.Ft fstab *
+.Ft struct fstab *
.Fn getfsent void
.Ft struct fstab *
.Fn getfsspec "const char *spec"
@@ -68,11 +68,11 @@ description file,
struct fstab {
char *fs_spec; /* block special device name */
char *fs_file; /* file system path prefix */
- char *fs_vfstype; /* type of file system */
- char *fs_mntops; /* comma separated mount options */
- char *fs_type; /* rw, ro, sw, or xx */
+ char *fs_vfstype; /* File system type, ufs, nfs */
+ char *fs_mntops; /* Mount options ala -o */
+ char *fs_type; /* FSTAB_* from fs_mntops */
int fs_freq; /* dump frequency, in days */
- int fs_passno; /* pass number on parallel dump */
+ int fs_passno; /* pass number on parallel fsck */
};
.Ed
.Pp
@@ -112,7 +112,9 @@ The
and
.Fn getfsfile
functions
-return a null pointer (0) on
+return a
+.Dv NULL
+pointer on
.Dv EOF
or error.
The
diff --git a/lib/libc/gen/getgrent.3 b/lib/libc/gen/getgrent.3
index e0e2782..a9f226a 100644
--- a/lib/libc/gen/getgrent.3
+++ b/lib/libc/gen/getgrent.3
@@ -29,9 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getgrent.3 8.2 (Berkeley) 4/19/94
+.\" From: @(#)getgrent.3 8.2 (Berkeley) 4/19/94
+.\" $Id: getgrent.3,v 1.9 1997/02/22 14:58:07 peter Exp $
.\"
-.Dd April 19, 1994
+.Dd September 29, 1994
.Dt GETGRENT 3
.Os
.Sh NAME
@@ -44,6 +45,7 @@
.Nm endgrent
.Nd group database operations
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
.Fd #include <grp.h>
.Ft struct group *
.Fn getgrent void
@@ -51,7 +53,7 @@
.Fn getgrnam "const char *name"
.Ft struct group *
.Fn getgrgid "gid_t gid"
-.Ft struct group *
+.Ft int
.Fn setgroupent "int stayopen"
.\" .Ft void
.\" .Fn setgrfile "const char *name"
@@ -74,7 +76,7 @@ file
struct group {
char *gr_name; /* group name */
char *gr_passwd; /* group password */
- gid_t gr_gid; /* group id */
+ int gr_gid; /* group id */
char **gr_mem; /* group members */
};
.Ed
@@ -121,6 +123,25 @@ The
.Fn endgrent
function
closes any open files.
+.Sh YP/NIS INTERACTION
+When the
+.Xr yp 4
+group database is enabled, the
+.Fn getgrnam
+and
+.Fn getgrgid
+functions use the YP maps
+.Dq Li group.byname
+and
+.Dq Li group.bygid ,
+respectively, if the requested group is not found in the local
+.Pa /etc/group
+file. The
+.Fn getgrent
+function will step through the YP map
+.Dq Li group.byname
+if the entire map is enabled as described in
+.Xr group 5 .
.Sh RETURN VALUES
The functions
.Fn getgrent ,
@@ -146,8 +167,9 @@ have no return value.
group database file
.El
.Sh SEE ALSO
-.Fn getpwent 3 ,
-.Fn group 5
+.Xr getpwent 3 ,
+.Xr yp 4 ,
+.Xr group 5
.Sh HISTORY
The functions
.Fn endgrent ,
@@ -181,12 +203,3 @@ leave their results in an internal static object and return
a pointer to that object. Subsequent calls to
the same function
will modify the same object.
-.Pp
-The functions
-.Fn getgrent ,
-.Fn endgrent ,
-.Fn setgroupent ,
-and
-.Fn setgrent
-are fairly useless in a networked environment and should be
-avoided, if possible.
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index 102546a..26069c6 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -38,23 +38,68 @@ static char sccsid[] = "@(#)getgrent.c 8.2 (Berkeley) 3/21/94";
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <grp.h>
static FILE *_gr_fp;
static struct group _gr_group;
static int _gr_stayopen;
static int grscan(), start_gr();
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+static int _gr_stepping_yp;
+static int _gr_yp_enabled;
+static int _getypgroup(struct group *, const char *, char *);
+static int _nextypgroup(struct group *);
+#endif
+
+/* initial size for malloc and increase steps for realloc */
+#define MAXGRP 64
+#define MAXLINELENGTH 256
-#define MAXGRP 200
-static char *members[MAXGRP];
-#define MAXLINELENGTH 1024
-static char line[MAXLINELENGTH];
+static char **members; /* list of group members */
+static int maxgrp; /* current length of **mebers */
+static char *line; /* temp buffer for group line */
+static int maxlinelength; /* current length of *line */
+
+/*
+ * Lines longer than MAXLINELENGTHLIMIT will be count as an error.
+ * <= 0 disable check for maximum line length
+ * 256K is enough for 64,000 uids
+ */
+#define MAXLINELENGTHLIMIT (256 * 1024)
+#define GROUP_IGNORE_COMMENTS 1 /* allow comments in /etc/group */
struct group *
getgrent()
{
- if (!_gr_fp && !start_gr() || !grscan(0, 0, NULL))
+ if (!_gr_fp && !start_gr()) {
+ return NULL;
+ }
+
+#ifdef YP
+ if (_gr_stepping_yp) {
+ if (_nextypgroup(&_gr_group))
+ return(&_gr_group);
+ }
+tryagain:
+#endif
+
+ if (!grscan(0, 0, NULL))
return(NULL);
+#ifdef YP
+ if(_gr_group.gr_name[0] == '+' && _gr_group.gr_name[1]) {
+ _getypgroup(&_gr_group, &_gr_group.gr_name[1],
+ "group.byname");
+ } else if(_gr_group.gr_name[0] == '+') {
+ if (!_nextypgroup(&_gr_group))
+ goto tryagain;
+ else
+ return(&_gr_group);
+ }
+#endif
return(&_gr_group);
}
@@ -66,7 +111,17 @@ getgrnam(name)
if (!start_gr())
return(NULL);
+#ifdef YP
+ tryagain:
+#endif
rval = grscan(1, 0, name);
+#ifdef YP
+ if(rval == -1 && (_gr_yp_enabled < 0 || (_gr_yp_enabled &&
+ _gr_group.gr_name[0] == '+'))) {
+ if (!(rval = _getypgroup(&_gr_group, name, "group.byname")))
+ goto tryagain;
+ }
+#endif
if (!_gr_stayopen)
endgrent();
return(rval ? &_gr_group : NULL);
@@ -84,20 +139,71 @@ getgrgid(gid)
if (!start_gr())
return(NULL);
+#ifdef YP
+ tryagain:
+#endif
rval = grscan(1, gid, NULL);
+#ifdef YP
+ if(rval == -1 && _gr_yp_enabled) {
+ char buf[16];
+ snprintf(buf, sizeof buf, "%d", (unsigned)gid);
+ if (!(rval = _getypgroup(&_gr_group, buf, "group.bygid")))
+ goto tryagain;
+ }
+#endif
if (!_gr_stayopen)
endgrent();
return(rval ? &_gr_group : NULL);
}
-static
+static int
start_gr()
{
if (_gr_fp) {
rewind(_gr_fp);
return(1);
}
- return((_gr_fp = fopen(_PATH_GROUP, "r")) ? 1 : 0);
+ _gr_fp = fopen(_PATH_GROUP, "r");
+ if(!_gr_fp) return 0;
+#ifdef YP
+ /*
+ * This is a disgusting hack, used to determine when YP is enabled.
+ * This would be easier if we had a group database to go along with
+ * the password database.
+ */
+ {
+ char *line;
+ size_t linelen;
+ _gr_yp_enabled = 0;
+ while((line = fgetln(_gr_fp, &linelen)) != NULL) {
+ if(line[0] == '+') {
+ if(line[1] && line[1] != ':' && !_gr_yp_enabled) {
+ _gr_yp_enabled = 1;
+ } else {
+ _gr_yp_enabled = -1;
+ break;
+ }
+ }
+ }
+ rewind(_gr_fp);
+ }
+#endif
+
+ if (maxlinelength == 0) {
+ if ((line = (char *)malloc(sizeof(char) *
+ MAXLINELENGTH)) == NULL)
+ return(0);
+ maxlinelength += MAXLINELENGTH;
+ }
+
+ if (maxgrp == 0) {
+ if ((members = (char **)malloc(sizeof(char **) *
+ MAXGRP)) == NULL)
+ return(0);
+ maxgrp += MAXGRP;
+ }
+
+ return 1;
}
int
@@ -113,52 +219,175 @@ setgroupent(stayopen)
if (!start_gr())
return(0);
_gr_stayopen = stayopen;
+#ifdef YP
+ _gr_stepping_yp = 0;
+#endif
return(1);
}
void
endgrent()
{
+#ifdef YP
+ _gr_stepping_yp = 0;
+#endif
if (_gr_fp) {
(void)fclose(_gr_fp);
_gr_fp = NULL;
}
}
-static
+static int
grscan(search, gid, name)
register int search, gid;
register char *name;
{
register char *cp, **m;
char *bp;
- char *fgets(), *strsep(), *index();
+
+#ifdef YP
+ int _ypfound;
+#endif
for (;;) {
- if (!fgets(line, sizeof(line), _gr_fp))
+#ifdef YP
+ _ypfound = 0;
+#endif
+ if (fgets(line, maxlinelength, _gr_fp) == NULL)
return(0);
- bp = line;
- /* skip lines that are too big */
+
if (!index(line, '\n')) {
- int ch;
+ do {
+ if (feof(_gr_fp))
+ return(0);
+
+ /* don't allocate infinite memory */
+ if (MAXLINELENGTHLIMIT > 0 &&
+ maxlinelength >= MAXLINELENGTHLIMIT)
+ return(0);
+
+ if ((line = (char *)realloc(line,
+ sizeof(char) *
+ (maxlinelength + MAXLINELENGTH))) == NULL)
+ return(0);
+
+ if (fgets(line + maxlinelength - 1,
+ MAXLINELENGTH + 1, _gr_fp) == NULL)
+ return(0);
- while ((ch = getc(_gr_fp)) != '\n' && ch != EOF)
- ;
+ maxlinelength += MAXLINELENGTH;
+ } while (!index(line + maxlinelength -
+ MAXLINELENGTH - 1, '\n'));
+ }
+
+#ifdef GROUP_IGNORE_COMMENTS
+ /*
+ * Ignore comments: ^[ \t]*#
+ */
+ for (cp = line; *cp != '\0'; cp++)
+ if (*cp != ' ' && *cp != '\t')
+ break;
+ if (*cp == '#' || *cp == '\0')
continue;
+#endif
+
+ bp = line;
+
+ if ((_gr_group.gr_name = strsep(&bp, ":\n")) == NULL)
+ break;
+#ifdef YP
+ /*
+ * XXX We need to be careful to avoid proceeding
+ * past this point under certain circumstances or
+ * we risk dereferencing null pointers down below.
+ */
+ if (_gr_group.gr_name[0] == '+') {
+ if (strlen(_gr_group.gr_name) == 1) {
+ switch(search) {
+ case 0:
+ return(1);
+ case 1:
+ return(-1);
+ default:
+ return(0);
+ }
+ } else {
+ cp = &_gr_group.gr_name[1];
+ if (search && name != NULL)
+ if (strcmp(cp, name))
+ continue;
+ if (!_getypgroup(&_gr_group, cp,
+ "group.byname"))
+ continue;
+ if (search && name == NULL)
+ if (gid != _gr_group.gr_gid)
+ continue;
+ /* We're going to override -- tell the world. */
+ _ypfound++;
+ }
}
- _gr_group.gr_name = strsep(&bp, ":\n");
- if (search && name && strcmp(_gr_group.gr_name, name))
+#else
+ if (_gr_group.gr_name[0] == '+')
continue;
- _gr_group.gr_passwd = strsep(&bp, ":\n");
+#endif /* YP */
+ if (search && name) {
+ if(strcmp(_gr_group.gr_name, name)) {
+ continue;
+ }
+ }
+#ifdef YP
+ if ((cp = strsep(&bp, ":\n")) == NULL)
+ if (_ypfound)
+ return(1);
+ else
+ break;
+ if (strlen(cp) || !_ypfound)
+ _gr_group.gr_passwd = cp;
+#else
+ if ((_gr_group.gr_passwd = strsep(&bp, ":\n")) == NULL)
+ break;
+#endif
if (!(cp = strsep(&bp, ":\n")))
- continue;
+#ifdef YP
+ if (_ypfound)
+ return(1);
+ else
+#endif
+ continue;
+#ifdef YP
+ /*
+ * Hurm. Should we be doing this? We allow UIDs to
+ * be overridden -- what about GIDs?
+ */
+ if (!_ypfound)
+#endif
_gr_group.gr_gid = atoi(cp);
if (search && name == NULL && _gr_group.gr_gid != gid)
continue;
cp = NULL;
- for (m = _gr_group.gr_mem = members;; bp++) {
- if (m == &members[MAXGRP - 1])
- break;
+ if (bp == NULL) /* !!! Must check for this! */
+ break;
+#ifdef YP
+ if ((cp = strsep(&bp, ":\n")) == NULL)
+ break;
+
+ if (!strlen(cp) && _ypfound)
+ return(1);
+ else
+ members[0] = NULL;
+ bp = cp;
+ cp = NULL;
+#endif
+ for (m = members; ; bp++) {
+ if (m == (members + maxgrp - 1)) {
+ if ((members = (char **)
+ realloc(members,
+ sizeof(char **) *
+ (maxgrp + MAXGRP))) == NULL)
+ return(0);
+ m = members + maxgrp - 1;
+ maxgrp += MAXGRP;
+ }
if (*bp == ',') {
if (cp) {
*bp = '\0';
@@ -169,13 +398,156 @@ grscan(search, gid, name)
if (cp) {
*bp = '\0';
*m++ = cp;
- }
+ }
break;
} else if (cp == NULL)
cp = bp;
+
}
+ _gr_group.gr_mem = members;
*m = NULL;
return(1);
}
/* NOTREACHED */
+ return (0);
}
+
+#ifdef YP
+
+static int
+_gr_breakout_yp(struct group *gr, char *result)
+{
+ char *s, *cp;
+ char **m;
+
+ /*
+ * XXX If 's' ends up being a NULL pointer, punt on this group.
+ * It means the NIS group entry is badly formatted and should
+ * be skipped.
+ */
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* name */
+ gr->gr_name = s;
+
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* password */
+ gr->gr_passwd = s;
+
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* gid */
+ gr->gr_gid = atoi(s);
+
+ if ((s = result) == NULL) return 0;
+ cp = 0;
+
+ for (m = members; ; s++) {
+ if (m == members + maxgrp - 1) {
+ if ((members = (char **)realloc(members,
+ sizeof(char **) * (maxgrp + MAXGRP))) == NULL)
+ return(0);
+ m = members + maxgrp - 1;
+ maxgrp += MAXGRP;
+ }
+ if (*s == ',') {
+ if (cp) {
+ *s = '\0';
+ *m++ = cp;
+ cp = NULL;
+ }
+ } else if (*s == '\0' || *s == '\n' || *s == ' ') {
+ if (cp) {
+ *s = '\0';
+ *m++ = cp;
+ }
+ break;
+ } else if (cp == NULL) {
+ cp = s;
+ }
+ }
+ _gr_group.gr_mem = members;
+ *m = NULL;
+
+ return 1;
+}
+
+static char *_gr_yp_domain;
+
+static int
+_getypgroup(struct group *gr, const char *name, char *map)
+{
+ char *result, *s;
+ static char resultbuf[YPMAXRECORD + 2];
+ int resultlen;
+
+ if(!_gr_yp_domain) {
+ if(yp_get_default_domain(&_gr_yp_domain))
+ return 0;
+ }
+
+ if(yp_match(_gr_yp_domain, map, name, strlen(name),
+ &result, &resultlen))
+ return 0;
+
+ s = strchr(result, '\n');
+ if(s) *s = '\0';
+
+ if(resultlen >= sizeof resultbuf) return 0;
+ strncpy(resultbuf, result, resultlen);
+ resultbuf[resultlen] = '\0';
+ free(result);
+ return(_gr_breakout_yp(gr, resultbuf));
+
+}
+
+
+static int
+_nextypgroup(struct group *gr)
+{
+ static char *key;
+ static int keylen;
+ char *lastkey, *result;
+ static char resultbuf[YPMAXRECORD + 2];
+ int resultlen;
+ int rv;
+
+ if(!_gr_yp_domain) {
+ if(yp_get_default_domain(&_gr_yp_domain))
+ return 0;
+ }
+
+ if(!_gr_stepping_yp) {
+ if(key) free(key);
+ rv = yp_first(_gr_yp_domain, "group.byname",
+ &key, &keylen, &result, &resultlen);
+ if(rv) {
+ return 0;
+ }
+ _gr_stepping_yp = 1;
+ goto unpack;
+ } else {
+tryagain:
+ lastkey = key;
+ rv = yp_next(_gr_yp_domain, "group.byname", key, keylen,
+ &key, &keylen, &result, &resultlen);
+ free(lastkey);
+unpack:
+ if(rv) {
+ _gr_stepping_yp = 0;
+ return 0;
+ }
+
+ if(resultlen > sizeof(resultbuf)) {
+ free(result);
+ goto tryagain;
+ }
+
+ strncpy(resultbuf, result, resultlen);
+ resultbuf[resultlen] = '\0';
+ free(result);
+ if((result = strchr(resultbuf, '\n')) != NULL)
+ *result = '\0';
+ if (_gr_breakout_yp(gr, resultbuf))
+ return(1);
+ else
+ goto tryagain;
+ }
+}
+
+#endif /* YP */
diff --git a/lib/libc/gen/getgrouplist.3 b/lib/libc/gen/getgrouplist.3
index 7878574..0d04a27 100644
--- a/lib/libc/gen/getgrouplist.3
+++ b/lib/libc/gen/getgrouplist.3
@@ -79,7 +79,8 @@ group membership list
.Sh HISTORY
The
.Fn getgrouplist
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
.Sh BUGS
The
.Fn getgrouplist
diff --git a/lib/libc/gen/getgrouplist.c b/lib/libc/gen/getgrouplist.c
index daab7f5..31f90b4 100644
--- a/lib/libc/gen/getgrouplist.c
+++ b/lib/libc/gen/getgrouplist.c
@@ -50,7 +50,6 @@ getgrouplist(uname, agroup, groups, grpcnt)
int *grpcnt;
{
register struct group *grp;
- register struct passwd *pw;
register int i, ngroups;
int ret, maxgroups;
@@ -70,8 +69,10 @@ getgrouplist(uname, agroup, groups, grpcnt)
*/
setgrent();
while (grp = getgrent()) {
- if (grp->gr_gid == agroup)
- continue;
+ for (i = 0; i < ngroups; i++) {
+ if (grp->gr_gid == groups[i])
+ goto skip;
+ }
for (i = 0; grp->gr_mem[i]; i++) {
if (!strcmp(grp->gr_mem[i], uname)) {
if (ngroups >= maxgroups) {
@@ -82,6 +83,7 @@ getgrouplist(uname, agroup, groups, grpcnt)
break;
}
}
+skip:
}
endgrent();
*grpcnt = ngroups;
diff --git a/lib/libc/gen/gethostname.3 b/lib/libc/gen/gethostname.3
index fcb0303..84241f0 100644
--- a/lib/libc/gen/gethostname.3
+++ b/lib/libc/gen/gethostname.3
@@ -82,8 +82,8 @@ invalid address.
The caller tried to set the hostname and was not the super-user.
.El
.Sh SEE ALSO
-.Xr sysctl 2
-.Xr gethostid 3
+.Xr gethostid 3 ,
+.Xr sysctl 3
.Sh BUGS
Host names are limited to
.Dv MAXHOSTNAMELEN
@@ -92,6 +92,6 @@ Host names are limited to
characters, currently 256.
.Sh HISTORY
The
-.Nm
+.Fn gethostname
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/gen/gethostname.c b/lib/libc/gen/gethostname.c
index 058e4b6..64bd64d 100644
--- a/lib/libc/gen/gethostname.c
+++ b/lib/libc/gen/gethostname.c
@@ -38,7 +38,7 @@ static char sccsid[] = "@(#)gethostname.c 8.1 (Berkeley) 6/4/93";
#include <sys/param.h>
#include <sys/sysctl.h>
-long
+int
gethostname(name, namelen)
char *name;
int namelen;
diff --git a/lib/libc/gen/getloadavg.3 b/lib/libc/gen/getloadavg.3
index 2eafd5b..fa5b571 100644
--- a/lib/libc/gen/getloadavg.3
+++ b/lib/libc/gen/getloadavg.3
@@ -38,6 +38,7 @@
.Nm getloadavg
.Nd get system load averages
.Sh SYNOPSIS
+.Ft int
.Fn getloadavg "double loadavg[]" "int nelem"
.Sh DESCRIPTION
The
@@ -55,8 +56,8 @@ If the load average was unobtainable, \-1 is returned; otherwise,
the number of samples actually retrieved is returned.
.Sh SEE ALSO
.Xr uptime 1 ,
-.Xr sysctl 2 ,
-.Xr kvm_getloadavg 3
+.Xr kvm_getloadavg 3 ,
+.Xr sysctl 3
.Sh HISTORY
The
.Fn getloadavg
diff --git a/lib/libc/gen/getlogin.c b/lib/libc/gen/getlogin.c
index b6f55a4..5829539 100644
--- a/lib/libc/gen/getlogin.c
+++ b/lib/libc/gen/getlogin.c
@@ -47,10 +47,10 @@ int _logname_valid; /* known to setlogin() */
char *
getlogin()
{
- static char logname[MAXLOGNAME + 1];
+ static char logname[MAXLOGNAME];
if (_logname_valid == 0) {
- if (_getlogin(logname, sizeof(logname) - 1) < 0)
+ if (_getlogin(logname, sizeof(logname)) < 0)
return ((char *)NULL);
_logname_valid = 1;
}
diff --git a/lib/libc/gen/getmntinfo.3 b/lib/libc/gen/getmntinfo.3
index f0e83ea3..e92755b 100644
--- a/lib/libc/gen/getmntinfo.3
+++ b/lib/libc/gen/getmntinfo.3
@@ -48,7 +48,7 @@ The
.Fn getmntinfo
function
returns an array of
-.Xr statfs
+.Fn statfs
structures describing each currently mounted file system (see
.Xr statfs 2 ) .
.Pp
@@ -85,13 +85,14 @@ or
.Xr malloc 3 .
.Sh SEE ALSO
.Xr getfsstat 2 ,
-.Xr statfs 2 ,
.Xr mount 2 ,
+.Xr statfs 2 ,
.Xr mount 8
.Sh HISTORY
The
.Fn getmntinfo
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
.Sh BUGS
The
.Fn getmntinfo
@@ -104,5 +105,5 @@ will modify the same object.
The memory allocated by
.Fn getmntinfo
cannot be
-.Xr free 2 Ns 'd
+.Xr free 3 Ns 'd
by the application.
diff --git a/lib/libc/gen/getnetgrent.3 b/lib/libc/gen/getnetgrent.3
index 1e38538..38da3c0 100644
--- a/lib/libc/gen/getnetgrent.3
+++ b/lib/libc/gen/getnetgrent.3
@@ -42,9 +42,9 @@
.Nd netgroup database operations
.Sh SYNOPSIS
.Ft int
-.Fn getnetgrent "char **host, char **user, char **domain"
+.Fn getnetgrent "char **host" "char **user" "char **domain"
.Ft int
-.Fn innetgr "const char *netgroup, const char *host, const char *user, const char *domain"
+.Fn innetgr "const char *netgroup" "const char *host" "const char *user" "const char *domain"
.Ft void
.Fn setnetgrent "const char *netgroup"
.Ft void
@@ -113,7 +113,7 @@ have no return value.
netgroup database file
.El
.Sh SEE ALSO
-.Fn netgroup 5
+.Xr netgroup 5
.Sh COMPATIBILITY
The netgroup members have three string fields to maintain compatibility
with other vendor implementations, however it is not obvious what use the
@@ -122,7 +122,7 @@ string has within BSD.
.Sh BUGS
The function
.Fn getnetgrent
-returns pointers to dynamically allocated data areas that are free'd when
+returns pointers to dynamically allocated data areas that are freed when
the function
.Fn endnetgrent
is called.
diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c
index b34b78b..662958a 100644
--- a/lib/libc/gen/getnetgrent.c
+++ b/lib/libc/gen/getnetgrent.c
@@ -40,8 +40,64 @@ static char sccsid[] = "@(#)getnetgrent.c 8.2 (Berkeley) 4/27/95";
#include <stdio.h>
#include <strings.h>
+#include <stdlib.h>
+#include <unistd.h>
+#ifdef YP
+/*
+ * Notes:
+ * We want to be able to use NIS netgroups properly while retaining
+ * the ability to use a local /etc/netgroup file. Unfortunately, you
+ * can't really do both at the same time - at least, not efficiently.
+ * NetBSD deals with this problem by creating a netgroup database
+ * using Berkeley DB (just like the password database) that allows
+ * for lookups using netgroup, netgroup.byuser or netgroup.byhost
+ * searches. This is a neat idea, but I don't have time to implement
+ * something like that now. (I think ultimately it would be nice
+ * if we DB-fied the group and netgroup stuff all in one shot, but
+ * for now I'm satisfied just to have something that works well
+ * without requiring massive code changes.)
+ *
+ * Therefore, to still permit the use of the local file and maintain
+ * optimum NIS performance, we allow for the following conditions:
+ *
+ * - If /etc/netgroup does not exist and NIS is turned on, we use
+ * NIS netgroups only.
+ *
+ * - If /etc/netgroup exists but is empty, we use NIS netgroups
+ * only.
+ *
+ * - If /etc/netgroup exists and contains _only_ a '+', we use
+ * NIS netgroups only.
+ *
+ * - If /etc/netgroup exists, contains locally defined netgroups
+ * and a '+', we use a mixture of NIS and the local entries.
+ * This method should return the same NIS data as just using
+ * NIS alone, but it will be slower if the NIS netgroup database
+ * is large (innetgr() in particular will suffer since extra
+ * processing has to be done in order to determine memberships
+ * using just the raw netgroup data).
+ *
+ * - If /etc/netgroup exists and contains only locally defined
+ * netgroup entries, we use just those local entries and ignore
+ * NIS (this is the original, pre-NIS behavior).
+ */
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/errno.h>
+static char *_netgr_yp_domain;
+int _use_only_yp;
+static int _netgr_yp_enabled;
+static int _yp_innetgr;
+#endif
+
+#ifndef _PATH_NETGROUP
#define _PATH_NETGROUP "/etc/netgroup"
+#endif
/*
* Static Variables and functions used by setnetgrent(), getnetgrent() and
@@ -93,11 +149,55 @@ void
setnetgrent(group)
char *group;
{
+#ifdef YP
+ struct stat _yp_statp;
+ char _yp_plus;
+#endif
+
+ /* Sanity check */
+
+ if (group == NULL || !strlen(group))
+ return;
if (grouphead.gr == (struct netgrp *)0 ||
strcmp(group, grouphead.grname)) {
endnetgrent();
+#ifdef YP
+ /* Presumed guilty until proven innocent. */
+ _use_only_yp = 0;
+ /*
+ * If /etc/netgroup doesn't exist or is empty,
+ * use NIS exclusively.
+ */
+ if (((stat(_PATH_NETGROUP, &_yp_statp) < 0) &&
+ errno == ENOENT) || _yp_statp.st_size == 0)
+ _use_only_yp = _netgr_yp_enabled = 1;
+ if ((netf = fopen(_PATH_NETGROUP,"r")) != NULL ||_use_only_yp){
+ /*
+ * Icky: grab the first character of the netgroup file
+ * and turn on NIS if it's a '+'. rewind the stream
+ * afterwards so we don't goof up read_for_group() later.
+ */
+ if (netf) {
+ fscanf(netf, "%c", &_yp_plus);
+ rewind(netf);
+ if (_yp_plus == '+')
+ _use_only_yp = _netgr_yp_enabled = 1;
+ }
+ /*
+ * If we were called specifically for an innetgr()
+ * lookup and we're in NIS-only mode, short-circuit
+ * parse_netgroup() and cut directly to the chase.
+ */
+ if (_use_only_yp && _yp_innetgr) {
+ /* dohw! */
+ if (netf != NULL)
+ fclose(netf);
+ return;
+ }
+#else
if (netf = fopen(_PATH_NETGROUP, "r")) {
+#endif
if (parse_netgrp(group))
endnetgrent();
else {
@@ -105,7 +205,8 @@ setnetgrent(group)
malloc(strlen(group) + 1);
strcpy(grouphead.grname, group);
}
- fclose(netf);
+ if (netf)
+ fclose(netf);
}
}
nextgrp = grouphead.gr;
@@ -118,6 +219,9 @@ int
getnetgrent(hostp, userp, domp)
char **hostp, **userp, **domp;
{
+#ifdef YP
+ _yp_innetgr = 0;
+#endif
if (nextgrp) {
*hostp = nextgrp->ng_str[NG_HOST];
@@ -164,22 +268,112 @@ endnetgrent()
free((char *)ogp);
}
grouphead.gr = (struct netgrp *)0;
+#ifdef YP
+ _netgr_yp_enabled = 0;
+#endif
}
+#ifdef YP
+static int _listmatch(list, group, len)
+char *list, *group;
+int len;
+{
+ char *ptr = list;
+
+ while ( (ptr = strstr(ptr, group)) ) {
+
+ ptr += strlen(group);
+
+ if (*ptr == ',' || *ptr == '\0')
+ return(1);
+ }
+
+ return(0);
+}
+
+static int _buildkey(key, str, dom, rotation)
+char *key, *str, *dom;
+int *rotation;
+{
+ (*rotation)++;
+ if (*rotation > 4)
+ return(0);
+ switch(*rotation) {
+ case(1): sprintf((char *)key, "%s.%s", str, dom ? dom : "*");
+ break;
+ case(2): sprintf((char *)key, "%s.*", str);
+ break;
+ case(3): sprintf((char *)key, "*.%s", dom ? dom : "*");
+ break;
+ case(4): sprintf((char *)key, "*.*");
+ break;
+ }
+ return(1);
+}
+#endif
+
/*
* Search for a match in a netgroup.
*/
int
innetgr(group, host, user, dom)
- char *group, *host, *user, *dom;
+ const char *group, *host, *user, *dom;
{
char *hst, *usr, *dm;
+#ifdef YP
+ char *result;
+ int resultlen;
+ int rv;
+#endif
+ /* Sanity check */
+
+ if (group == NULL || !strlen(group))
+ return (0);
+#ifdef YP
+ _yp_innetgr = 1;
+#endif
setnetgrent(group);
+#ifdef YP
+ _yp_innetgr = 0;
+ /*
+ * If we're in NIS-only mode, do the search using
+ * NIS 'reverse netgroup' lookups.
+ */
+ if (_use_only_yp) {
+ char _key[MAXHOSTNAMELEN];
+ int rot = 0;
+
+ if(yp_get_default_domain(&_netgr_yp_domain))
+ return(0);
+ while(_buildkey(_key, user ? user : host, dom, &rot)) {
+ if (!yp_match(_netgr_yp_domain, user? "netgroup.byuser":
+ "netgroup.byhost", _key, strlen(_key), &result,
+ &resultlen)) {
+ rv = _listmatch(result, group, resultlen);
+ free(result);
+ if (rv)
+ return(1);
+ else
+ return(0);
+ }
+ }
+#ifdef CHARITABLE
+ }
+ /*
+ * Couldn't match using NIS-exclusive mode -- try
+ * standard mode.
+ */
+ setnetgrent(group);
+#else
+ return(0);
+ }
+#endif /* CHARITABLE */
+#endif /* YP */
while (getnetgrent(&hst, &usr, &dm))
- if ((host == (char *)0 || !strcmp(host, hst)) &&
- (user == (char *)0 || !strcmp(user, usr)) &&
- (dom == (char *)0 || !strcmp(dom, dm))) {
+ if ((host == NULL || hst == NULL || !strcmp(host, hst)) &&
+ (user == NULL || usr == NULL || !strcmp(user, usr)) &&
+ ( dom == NULL || dm == NULL || !strcmp(dom, dm))) {
endnetgrent();
return (1);
}
@@ -196,6 +390,9 @@ parse_netgrp(group)
{
register char *spos, *epos;
register int len, strpos;
+#ifdef DEBUG
+ register int fields;
+#endif
char *pos, *gpos;
struct netgrp *grp;
struct linelist *lp = linehead;
@@ -212,12 +409,21 @@ parse_netgrp(group)
(lp = read_for_group(group)) == (struct linelist *)0)
return (1);
if (lp->l_parsed) {
+#ifdef DEBUG
+ /*
+ * This error message is largely superflous since the
+ * code handles the error condition sucessfully, and
+ * spewing it out from inside libc can actually hose
+ * certain programs.
+ */
fprintf(stderr, "Cycle in netgroup %s\n", lp->l_groupname);
+#endif
return (1);
} else
lp->l_parsed = 1;
pos = lp->l_line;
- while (*pos != '\0') {
+ /* Watch for null pointer dereferences, dammit! */
+ while (pos != NULL && *pos != '\0') {
if (*pos == '(') {
grp = (struct netgrp *)malloc(sizeof (struct netgrp));
bzero((char *)grp, sizeof (struct netgrp));
@@ -225,11 +431,17 @@ parse_netgrp(group)
grouphead.gr = grp;
pos++;
gpos = strsep(&pos, ")");
+#ifdef DEBUG
+ fields = 0;
+#endif
for (strpos = 0; strpos < 3; strpos++) {
- if (spos = strsep(&gpos, ",")) {
+ if ((spos = strsep(&gpos, ","))) {
+#ifdef DEBUG
+ fields++;
+#endif
while (*spos == ' ' || *spos == '\t')
spos++;
- if (epos = strpbrk(spos, " \t")) {
+ if ((epos = strpbrk(spos, " \t"))) {
*epos = '\0';
len = epos - spos;
} else
@@ -240,13 +452,36 @@ parse_netgrp(group)
bcopy(spos, grp->ng_str[strpos],
len + 1);
}
- } else
- goto errout;
+ } else {
+ /*
+ * All other systems I've tested
+ * return NULL for empty netgroup
+ * fields. It's up to user programs
+ * to handle the NULLs appropriately.
+ */
+ grp->ng_str[strpos] = NULL;
+ }
}
+#ifdef DEBUG
+ /*
+ * Note: on other platforms, malformed netgroup
+ * entries are not normally flagged. While we
+ * can catch bad entries and report them, we should
+ * stay silent by default for compatibility's sake.
+ */
+ if (fields < 3)
+ fprintf(stderr, "Bad entry (%s%s%s%s%s) in netgroup \"%s\"\n",
+ grp->ng_str[NG_HOST] == NULL ? "" : grp->ng_str[NG_HOST],
+ grp->ng_str[NG_USER] == NULL ? "" : ",",
+ grp->ng_str[NG_USER] == NULL ? "" : grp->ng_str[NG_USER],
+ grp->ng_str[NG_DOM] == NULL ? "" : ",",
+ grp->ng_str[NG_DOM] == NULL ? "" : grp->ng_str[NG_DOM],
+ lp->l_groupname);
+#endif
} else {
spos = strsep(&pos, ", \t");
if (parse_netgrp(spos))
- return (1);
+ continue;
}
if (pos == NULL)
break;
@@ -254,10 +489,6 @@ parse_netgrp(group)
pos++;
}
return (0);
-errout:
- fprintf(stderr, "Bad netgroup %s at ..%s\n", lp->l_groupname,
- spos);
- return (1);
}
/*
@@ -272,10 +503,39 @@ read_for_group(group)
register int len, olen;
int cont;
struct linelist *lp;
- char line[LINSIZ + 1];
+ char line[LINSIZ + 2];
+#ifdef YP
+ char *result;
+ int resultlen;
+ while (_netgr_yp_enabled || fgets(line, LINSIZ, netf) != NULL) {
+ if (_netgr_yp_enabled) {
+ if(!_netgr_yp_domain)
+ if(yp_get_default_domain(&_netgr_yp_domain))
+ continue;
+ if (yp_match(_netgr_yp_domain, "netgroup", group,
+ strlen(group), &result, &resultlen)) {
+ free(result);
+ if (_use_only_yp)
+ return ((struct linelist *)0);
+ else {
+ _netgr_yp_enabled = 0;
+ continue;
+ }
+ }
+ snprintf(line, LINSIZ, "%s %s", group, result);
+ free(result);
+ }
+#else
while (fgets(line, LINSIZ, netf) != NULL) {
- pos = line;
+#endif
+ pos = (char *)&line;
+#ifdef YP
+ if (*pos == '+') {
+ _netgr_yp_enabled = 1;
+ continue;
+ }
+#endif
if (*pos == '#')
continue;
while (*pos == ' ' || *pos == '\t')
@@ -337,5 +597,15 @@ read_for_group(group)
return (lp);
}
}
+#ifdef YP
+ /*
+ * Yucky. The recursive nature of this whole mess might require
+ * us to make more than one pass through the netgroup file.
+ * This might be best left outside the #ifdef YP, but YP is
+ * defined by default anyway, so I'll leave it like this
+ * until I know better.
+ */
+ rewind(netf);
+#endif
return ((struct linelist *)0);
}
diff --git a/lib/libc/gen/getosreldate.c b/lib/libc/gen/getosreldate.c
new file mode 100644
index 0000000..808e16b
--- /dev/null
+++ b/lib/libc/gen/getosreldate.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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)
+/* From:
+static char sccsid[] = "@(#)gethostid.c 8.1 (Berkeley) 6/2/93";
+*/
+static const char rcsid[] =
+ "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
+#if __STDC__
+int
+getosreldate(void)
+#else
+int
+getosreldate()
+#endif
+{
+ int mib[2];
+ size_t size;
+ int value;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_OSRELDATE;
+ size = sizeof value;
+ if (sysctl(mib, 2, &value, &size, NULL, 0) == -1)
+ return (-1);
+ return (value);
+}
diff --git a/lib/libc/gen/getpagesize.3 b/lib/libc/gen/getpagesize.3
index 1a26297..51dbcd1 100644
--- a/lib/libc/gen/getpagesize.3
+++ b/lib/libc/gen/getpagesize.3
@@ -47,15 +47,14 @@ returns the number of bytes in a page.
Page granularity is the granularity of many of the memory
management calls.
.Pp
-The page size is a
-.Xr system
+The page size is a system
page size and may not be the same as the underlying
hardware page size.
.Sh SEE ALSO
-.Xr sbrk 2 ,
-.Xr pagesize 1
+.Xr pagesize 1 ,
+.Xr sbrk 2
.Sh HISTORY
The
-.Nm
+.Fn getpagesze
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c
index d586cf6..556ff9e 100644
--- a/lib/libc/gen/getpagesize.c
+++ b/lib/libc/gen/getpagesize.c
@@ -38,16 +38,24 @@ static char sccsid[] = "@(#)getpagesize.c 8.1 (Berkeley) 6/4/93";
#include <sys/param.h>
#include <sys/sysctl.h>
+/*
+ * This is unlikely to change over the running time of any
+ * program, so we cache the result to save some syscalls.
+ */
+
int
getpagesize()
{
- int mib[2], value;
+ int mib[2];
+ static int value;
size_t size;
- mib[0] = CTL_HW;
- mib[1] = HW_PAGESIZE;
- size = sizeof value;
- if (sysctl(mib, 2, &value, &size, NULL, 0) == -1)
- return (-1);
+ if (!value) {
+ mib[0] = CTL_HW;
+ mib[1] = HW_PAGESIZE;
+ size = sizeof value;
+ if (sysctl(mib, 2, &value, &size, NULL, 0) == -1)
+ return (-1);
+ }
return (value);
}
diff --git a/lib/libc/gen/getpass.3 b/lib/libc/gen/getpass.3
index 34e91cb..c1fb0e6 100644
--- a/lib/libc/gen/getpass.3
+++ b/lib/libc/gen/getpass.3
@@ -48,7 +48,7 @@ The
function displays a prompt to, and reads in a password from,
.Pa /dev/tty .
If this file is not accessible,
-.Nm getpass
+.Fn getpass
displays the prompt on the standard error output and reads from the standard
input.
.Pp
@@ -57,32 +57,38 @@ characters in length.
Any additional
characters and the terminating newline character are discarded.
.Pp
-.Nm Getpass
-turns off character echoing while reading the password.
+The
+.Fn getpass
+function turns off character echoing while reading the password.
.Pp
.Sh RETURN VALUES
-.Nm Getpass
-returns a pointer to the null terminated password.
+The
+.Fn getpass
+function returns a pointer to the null terminated password.
.Sh FILES
-.Bl -tag -width /dev/tty - compact
+.Bl -tag -width /dev/tty -compact
.It Pa /dev/tty
.El
.Sh SEE ALSO
.Xr crypt 3
.Sh HISTORY
A
-.Nm getpass
+.Fn getpass
function appeared in
.At v7 .
.Sh BUGS
The
-.Nm getpass
+.Fn getpass
function leaves its result in an internal static object and returns
a pointer to that object.
Subsequent calls to
-.Nm getpass
+.Fn getpass
will modify the same object.
.Pp
The calling process should zero the password as soon as possible to
avoid leaving the cleartext password visible in the process's address
space.
+.Pp
+Upon receipt of a SIGTSTP, the input buffer will be flushed, so any
+partially typed password must be retyped when the process
+continues.
diff --git a/lib/libc/gen/getpass.c b/lib/libc/gen/getpass.c
index f6391a1..b053d34 100644
--- a/lib/libc/gen/getpass.c
+++ b/lib/libc/gen/getpass.c
@@ -36,23 +36,53 @@ static char sccsid[] = "@(#)getpass.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/termios.h>
-#include <sys/signal.h>
+#include <signal.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
+static struct termios oterm, term;
+static sig_t ointhandler, oquithandler, otstphandler, oconthandler;
+static FILE *fp;
+
+static void
+sighandler(int signo)
+{
+ /* restore tty state */
+ (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &oterm);
+
+ /* restore old sig handlers */
+ (void)signal(SIGINT, ointhandler);
+ (void)signal(SIGQUIT, oquithandler);
+ (void)signal(SIGTSTP, otstphandler);
+
+ /* resend us this signal */
+ (void)kill(getpid(), signo);
+}
+
+/* ARGSUSED */
+static void
+sigconthandler(int signo)
+{
+ /* re-install our signal handlers */
+ ointhandler = signal(SIGINT, sighandler);
+ oquithandler = signal(SIGQUIT, sighandler);
+ otstphandler = signal(SIGTSTP, sighandler);
+
+ /* turn off echo again */
+ (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term);
+}
+
+
char *
getpass(prompt)
const char *prompt;
{
- struct termios term;
register int ch;
register char *p;
- FILE *fp, *outfp;
- long omask;
- int echo;
+ FILE *outfp;
static char buf[_PASSWORD_LEN + 1];
/*
@@ -63,16 +93,16 @@ getpass(prompt)
outfp = stderr;
fp = stdin;
}
- /*
- * note - blocking signals isn't necessarily the
- * right thing, but we leave it for now.
- */
- omask = sigblock(sigmask(SIGINT)|sigmask(SIGTSTP));
- (void)tcgetattr(fileno(fp), &term);
- if (echo = (term.c_lflag & ECHO)) {
- term.c_lflag &= ~ECHO;
- (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term);
- }
+
+ ointhandler = signal(SIGINT, sighandler);
+ oquithandler = signal(SIGQUIT, sighandler);
+ otstphandler = signal(SIGTSTP, sighandler);
+ oconthandler = signal(SIGCONT, sigconthandler);
+
+ (void)tcgetattr(fileno(fp), &oterm);
+ term = oterm;
+ term.c_lflag &= ~ECHO;
+ (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term);
(void)fputs(prompt, outfp);
rewind(outfp); /* implied flush */
for (p = buf; (ch = getc(fp)) != EOF && ch != '\n';)
@@ -80,11 +110,14 @@ getpass(prompt)
*p++ = ch;
*p = '\0';
(void)write(fileno(outfp), "\n", 1);
- if (echo) {
- term.c_lflag |= ECHO;
- (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term);
- }
- (void)sigsetmask(omask);
+ (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &oterm);
+
+ /* restore old sig handlers */
+ (void)signal(SIGINT, ointhandler);
+ (void)signal(SIGQUIT, oquithandler);
+ (void)signal(SIGTSTP, otstphandler);
+ (void)signal(SIGCONT, oconthandler);
+
if (fp != stdin)
(void)fclose(fp);
return(buf);
diff --git a/lib/libc/gen/getpwent.3 b/lib/libc/gen/getpwent.3
index 1208f53..6badc19 100644
--- a/lib/libc/gen/getpwent.3
+++ b/lib/libc/gen/getpwent.3
@@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getpwent.3 8.2 (Berkeley) 12/11/93
+.\" From: @(#)getpwent.3 8.2 (Berkeley) 12/11/93
.\"
-.Dd December 11, 1993
+.Dd September 20, 1994
.Dt GETPWENT 3
.Os
.Sh NAME
@@ -72,14 +72,15 @@ file
struct passwd {
char *pw_name; /* user name */
char *pw_passwd; /* encrypted password */
- uid_t pw_uid; /* user uid */
- gid_t pw_gid; /* user gid */
+ int pw_uid; /* user uid */
+ int pw_gid; /* user gid */
time_t pw_change; /* password change time */
char *pw_class; /* user access class */
char *pw_gecos; /* Honeywell login info */
char *pw_dir; /* home directory */
char *pw_shell; /* default shell */
time_t pw_expire; /* account expiration */
+ int pw_fields; /* internal: fields filled in */
};
.Ed
.Pp
@@ -133,6 +134,24 @@ If the process which calls them has an effective uid of 0, the encrypted
password will be returned, otherwise, the password field of the returned
structure will point to the string
.Ql * .
+.Sh YP/NIS INTERACTION
+When the
+.Xr yp 4
+password database is enabled, the
+.Fn getpwnam
+and
+.Fn getpwuid
+functions use the YP maps
+.Dq Li passwd.byname
+and
+.Dq Li passwd.byuid ,
+respectively, if the requested password entry is not found in the
+local database. The
+.Fn getpwent
+function will step through the YP map
+.Dq Li passwd.byname
+if the entire map is enabled as described in
+.Xr passwd 5 .
.Sh RETURN VALUES
The functions
.Fn getpwent ,
@@ -152,9 +171,9 @@ function
has no return value.
.Sh FILES
.Bl -tag -width /etc/master.passwd -compact
-.It Pa /var/db/pwd.db
+.It Pa /etc/pwd.db
The insecure password database file
-.It Pa /var/db/spwd.db
+.It Pa /etc/spwd.db
The secure password database file
.It Pa /etc/master.passwd
The current password file
@@ -162,25 +181,31 @@ The current password file
A Version 7 format password file
.El
.Sh SEE ALSO
-.Xr getlogin 3 ,
+.Xr getlogin 2 ,
.Xr getgrent 3 ,
+.Xr yp 4 ,
.Xr passwd 5 ,
.Xr pwd_mkdb 8 ,
.Xr vipw 8
.Sh HISTORY
The
-.Nm getpwent ,
-.Nm getpwnam ,
-.Nm getpwuid ,
-.Nm setpwent,
+.Fn getpwent ,
+.Fn getpwnam ,
+.Fn getpwuid ,
+.Fn setpwent,
and
-.Nm endpwent
+.Fn endpwent
functions appeared in
.At v7 .
The
-.Nm setpassent
+.Fn setpassent
function appeared in
.Bx 4.3 Reno .
+.Sh COMPATIBILITY
+The historic function
+.Xr setpwfile 3 ,
+which allowed the specification of alternate password databases,
+has been deprecated and is no longer available.
.Sh BUGS
The functions
.Fn getpwent ,
@@ -191,17 +216,3 @@ leave their results in an internal static object and return
a pointer to that object. Subsequent calls to
the same function
will modify the same object.
-.Pp
-The routines
-.Fn getpwent ,
-.Fn endpwent ,
-.Fn setpassent ,
-and
-.Fn setpwent
-are fairly useless in a networked environment and should be
-avoided, if possible.
-.Sh COMPATIBILITY
-The historic function
-.Xr setpwfile 3 ,
-which allowed the specification of alternate password databases,
-has been deprecated and is no longer available.
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index 155ba56..d1cec3e 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -35,6 +35,7 @@
static char sccsid[] = "@(#)getpwent.c 8.2 (Berkeley) 4/27/95";
#endif /* LIBC_SCCS and not lint */
+#include <stdio.h>
#include <sys/param.h>
#include <fcntl.h>
#include <db.h>
@@ -46,6 +47,11 @@ static char sccsid[] = "@(#)getpwent.c 8.2 (Berkeley) 4/27/95";
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <grp.h>
+
+extern void setnetgrent __P(( char * ));
+extern int getnetgrent __P(( char **, char **, char ** ));
+extern int innetgr __P(( const char *, const char *, const char *, const char * ));
/*
* The lookup techniques and data extraction code here must be kept
@@ -56,6 +62,29 @@ static struct passwd _pw_passwd; /* password structure */
static DB *_pw_db; /* password database */
static int _pw_keynum; /* key counter */
static int _pw_stayopen; /* keep fd's open */
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+
+static struct passwd _pw_copy;
+static DBT empty = { NULL, 0 };
+static DB *_ypcache = (DB *)NULL;
+static int _yp_exclusions = 0;
+static int _yp_enabled; /* set true when yp enabled */
+static int _pw_stepping_yp; /* set true when stepping thru map */
+static char _ypnam[YPMAXRECORD];
+#define YP_HAVE_MASTER 2
+#define YP_HAVE_ADJUNCT 1
+#define YP_HAVE_NONE 0
+static int _gotmaster;
+static char *_pw_yp_domain;
+static inline int unwind __P(( char * ));
+static inline void _ypinitdb __P(( void ));
+static int _havemaster __P((char *));
+static int _getyppass __P((struct passwd *, const char *, const char * ));
+static int _nextyppass __P((struct passwd *));
+#endif
static int __hashpw(), __initdb();
struct passwd *
@@ -63,16 +92,45 @@ getpwent()
{
DBT key;
char bf[sizeof(_pw_keynum) + 1];
+ int rv;
if (!_pw_db && !__initdb())
return((struct passwd *)NULL);
+#ifdef YP
+ if(_pw_stepping_yp) {
+ _pw_passwd = _pw_copy;
+ if (unwind((char *)&_ypnam))
+ return(&_pw_passwd);
+ }
+#endif
+tryagain:
+
++_pw_keynum;
bf[0] = _PW_KEYBYNUM;
bcopy((char *)&_pw_keynum, bf + 1, sizeof(_pw_keynum));
key.data = (u_char *)bf;
key.size = sizeof(_pw_keynum) + 1;
- return(__hashpw(&key) ? &_pw_passwd : (struct passwd *)NULL);
+ rv = __hashpw(&key);
+ if(!rv) return (struct passwd *)NULL;
+#ifdef YP
+ if(_pw_passwd.pw_name[0] == '+' || _pw_passwd.pw_name[0] == '-') {
+ bzero((char *)&_ypnam, sizeof(_ypnam));
+ bcopy(_pw_passwd.pw_name, _ypnam,
+ strlen(_pw_passwd.pw_name));
+ _pw_copy = _pw_passwd;
+ if (unwind((char *)&_ypnam) == 0)
+ goto tryagain;
+ else
+ return(&_pw_passwd);
+ }
+#else
+ /* Ignore YP password file entries when YP is disabled. */
+ if(_pw_passwd.pw_name[0] == '+' || _pw_passwd.pw_name[0] == '-') {
+ goto tryagain;
+ }
+#endif
+ return(&_pw_passwd);
}
struct passwd *
@@ -81,7 +139,7 @@ getpwnam(name)
{
DBT key;
int len, rval;
- char bf[UT_NAMESIZE + 1];
+ char bf[UT_NAMESIZE + 2];
if (!_pw_db && !__initdb())
return((struct passwd *)NULL);
@@ -93,10 +151,18 @@ getpwnam(name)
key.size = len + 1;
rval = __hashpw(&key);
- if (!_pw_stayopen) {
- (void)(_pw_db->close)(_pw_db);
- _pw_db = (DB *)NULL;
- }
+#ifdef YP
+ if (!rval && _yp_enabled)
+ rval = _getyppass(&_pw_passwd, name, "passwd.byname");
+#endif
+ /*
+ * Prevent login attempts when YP is not enabled but YP entries
+ * are in /etc/master.passwd.
+ */
+ if (rval && (_pw_passwd.pw_name[0] == '+'||
+ _pw_passwd.pw_name[0] == '-')) rval = 0;
+
+ endpwent();
return(rval ? &_pw_passwd : (struct passwd *)NULL);
}
@@ -118,10 +184,21 @@ getpwuid(uid)
key.size = sizeof(keyuid) + 1;
rval = __hashpw(&key);
- if (!_pw_stayopen) {
- (void)(_pw_db->close)(_pw_db);
- _pw_db = (DB *)NULL;
+#ifdef YP
+ if (!rval && _yp_enabled) {
+ char ypbuf[16]; /* big enough for 32-bit uids and then some */
+ snprintf(ypbuf, sizeof ypbuf, "%u", (unsigned)uid);
+ rval = _getyppass(&_pw_passwd, ypbuf, "passwd.byuid");
}
+#endif
+ /*
+ * Prevent login attempts when YP is not enabled but YP entries
+ * are in /etc/master.passwd.
+ */
+ if (rval && (_pw_passwd.pw_name[0] == '+'||
+ _pw_passwd.pw_name[0] == '-')) rval = 0;
+
+ endpwent();
return(rval ? &_pw_passwd : (struct passwd *)NULL);
}
@@ -130,6 +207,9 @@ setpassent(stayopen)
int stayopen;
{
_pw_keynum = 0;
+#ifdef YP
+ _pw_stepping_yp = 0;
+#endif
_pw_stayopen = stayopen;
return(1);
}
@@ -138,6 +218,9 @@ int
setpwent()
{
_pw_keynum = 0;
+#ifdef YP
+ _pw_stepping_yp = 0;
+#endif
_pw_stayopen = 0;
return(1);
}
@@ -146,13 +229,23 @@ void
endpwent()
{
_pw_keynum = 0;
+#ifdef YP
+ _pw_stepping_yp = 0;
+#endif
if (_pw_db) {
(void)(_pw_db->close)(_pw_db);
_pw_db = (DB *)NULL;
}
+#ifdef YP
+ if (_ypcache) {
+ (void)(_ypcache->close)(_ypcache);
+ _ypcache = (DB *)NULL;
+ _yp_exclusions = 0;
+ }
+#endif
}
-static
+static int
__initdb()
{
static int warned;
@@ -160,14 +253,35 @@ __initdb()
p = (geteuid()) ? _PATH_MP_DB : _PATH_SMP_DB;
_pw_db = dbopen(p, O_RDONLY, 0, DB_HASH, NULL);
- if (_pw_db)
+ if (_pw_db) {
+#ifdef YP
+ DBT key, data;
+ char buf[] = { _PW_KEYYPENABLED };
+ key.data = buf;
+ key.size = 1;
+ if ((_pw_db->get)(_pw_db, &key, &data, 0)) {
+ _yp_enabled = 0;
+ } else {
+ _yp_enabled = (int)*((char *)data.data) - 2;
+ /* Don't even bother with this if we aren't root. */
+ if (!geteuid()) {
+ if (!_pw_yp_domain)
+ if (yp_get_default_domain(&_pw_yp_domain))
+ return(1);
+ _gotmaster = _havemaster(_pw_yp_domain);
+ } else _gotmaster = YP_HAVE_NONE;
+ if (!_ypcache)
+ _ypinitdb();
+ }
+#endif
return(1);
- if (!warned)
+ }
+ if (!warned++)
syslog(LOG_ERR, "%s: %m", p);
return(0);
}
-static
+static int
__hashpw(key)
DBT *key;
{
@@ -184,7 +298,7 @@ __hashpw(key)
/* THIS CODE MUST MATCH THAT IN pwd_mkdb. */
t = line;
-#define EXPAND(e) e = t; while (*t++ = *p++);
+#define EXPAND(e) e = t; while ( (*t++ = *p++) );
#define SCALAR(v) memmove(&(v), p, sizeof v); p += sizeof v
EXPAND(_pw_passwd.pw_name);
EXPAND(_pw_passwd.pw_passwd);
@@ -196,5 +310,521 @@ __hashpw(key)
EXPAND(_pw_passwd.pw_dir);
EXPAND(_pw_passwd.pw_shell);
SCALAR(_pw_passwd.pw_expire);
+ bcopy(p, (char *)&_pw_passwd.pw_fields, sizeof _pw_passwd.pw_fields);
+ p += sizeof _pw_passwd.pw_fields;
+ return(1);
+}
+
+#ifdef YP
+
+/*
+ * Create a DB hash database in memory. Bet you didn't know you
+ * could do a dbopen() will a NULL filename, did you.
+ */
+static inline void _ypinitdb()
+{
+ if (_ypcache == (DB *)NULL)
+ _ypcache = dbopen(NULL, O_RDWR, 600, DB_HASH, NULL);
+ return;
+}
+
+/*
+ * See if a user is in the blackballed list.
+ */
+static inline int lookup(name)
+ char *name;
+{
+ DBT key;
+
+ if (!_yp_exclusions)
+ return(0);
+
+ key.data = name;
+ key.size = strlen(name);
+
+ if ((_ypcache->get)(_ypcache, &key, &empty, 0)) {
+ return(0);
+ }
+
return(1);
}
+
+/*
+ * Store a blackballed user in an in-core hash database.
+ */
+static inline void store(key)
+ char *key;
+{
+ DBT lkey;
+/*
+ if (lookup(key))
+ return;
+*/
+
+ _yp_exclusions = 1;
+
+ lkey.data = key;
+ lkey.size = strlen(key);
+
+ (void)(_ypcache->put)(_ypcache, &lkey, &empty, R_NOOVERWRITE);
+}
+
+/*
+ * Parse the + entries in the password database and do appropriate
+ * NIS lookups. While ugly to look at, this is optimized to do only
+ * as many lookups as are absolutely necessary in any given case.
+ * Basically, the getpwent() function will feed us + and - lines
+ * as they appear in the database. For + lines, we do netgroup/group
+ * and user lookups to find all usernames that match the rule and
+ * extract them from the NIS passwd maps. For - lines, we save the
+ * matching names in a database and a) exlude them, and b) make sure
+ * we don't consider them when processing other + lines that appear
+ * later.
+ */
+static inline int unwind(grp)
+ char *grp;
+{
+ char *user, *host, *domain;
+ static int latch = 0;
+ static struct group *gr = NULL;
+ int rv = 0;
+
+ if (grp[0] == '+') {
+ if (strlen(grp) == 1) {
+ return(_nextyppass(&_pw_passwd));
+ }
+ if (grp[1] == '@') {
+ _pw_stepping_yp = 1;
+grpagain:
+ if (gr != NULL) {
+ if (*gr->gr_mem != NULL) {
+ if (lookup(*gr->gr_mem)) {
+ gr->gr_mem++;
+ goto grpagain;
+ }
+ rv = _getyppass(&_pw_passwd,
+ *gr->gr_mem,
+ "passwd.byname");
+ gr->gr_mem++;
+ return(rv);
+ } else {
+ endgrent();
+ latch = 0;
+ gr = NULL;
+ return(0);
+ }
+ }
+ if (!latch) {
+ setnetgrent(grp+2);
+ latch++;
+ }
+again:
+ if (getnetgrent(&host, &user, &domain) == NULL) {
+ if ((gr = getgrnam(grp+2)) != NULL)
+ goto grpagain;
+ latch = 0;
+ _pw_stepping_yp = 0;
+ return(0);
+ } else {
+ if (lookup(user))
+ goto again;
+ if (_getyppass(&_pw_passwd, user,
+ "passwd.byname"))
+ return(1);
+ else
+ goto again;
+ }
+ } else {
+ if (lookup(grp+1))
+ return(0);
+ return(_getyppass(&_pw_passwd, grp+1, "passwd.byname"));
+ }
+ } else {
+ if (grp[1] == '@') {
+ setnetgrent(grp+2);
+ rv = 0;
+ while(getnetgrent(&host, &user, &domain) != NULL) {
+ store(user);
+ rv++;
+ }
+ if (!rv && (gr = getgrnam(grp+2)) != NULL) {
+ while(gr->gr_mem) {
+ store(gr->gr_mem);
+ gr->gr_mem++;
+ }
+ }
+ } else {
+ store(grp+1);
+ }
+ }
+ return(0);
+}
+
+/*
+ * See if a user is a member of a particular group.
+ */
+static inline int ingr(grp, name)
+ char *grp;
+ char *name;
+{
+ register struct group *gr;
+
+ if ((gr = getgrnam(grp)) == NULL)
+ return(0);
+
+ while(*gr->gr_mem) {
+ if (!strcmp(*gr->gr_mem, name)) {
+ endgrent();
+ return(1);
+ }
+ gr->gr_mem++;
+ }
+
+ endgrent();
+ return(0);
+}
+
+/*
+ * Check a user against the +@netgroup/-@netgroup lines listed in
+ * the local password database. Also checks +user/-user lines.
+ * If no netgroup exists that matches +@netgroup/-@netgroup,
+ * try searching regular groups with the same name.
+ */
+static inline int verf(name)
+ char *name;
+{
+ DBT key;
+ char bf[sizeof(_pw_keynum) + 1];
+ int keynum = 0;
+
+again:
+ ++keynum;
+ bf[0] = _PW_KEYYPBYNUM;
+ bcopy((char *)&keynum, bf + 1, sizeof(keynum));
+ key.data = (u_char *)bf;
+ key.size = sizeof(keynum) + 1;
+ if (!__hashpw(&key)) {
+ /* Try again using old format */
+ bf[0] = _PW_KEYBYNUM;
+ bcopy((char *)&keynum, bf + 1, sizeof(keynum));
+ key.data = (u_char *)bf;
+ if (!__hashpw(&key))
+ return(0);
+ }
+ if (_pw_passwd.pw_name[0] != '+' && (_pw_passwd.pw_name[0] != '-'))
+ goto again;
+ if (_pw_passwd.pw_name[0] == '+') {
+ if (strlen(_pw_passwd.pw_name) == 1) /* Wildcard */
+ return(1);
+ if (_pw_passwd.pw_name[1] == '@') {
+ if ((innetgr(_pw_passwd.pw_name+2, NULL, name,
+ _pw_yp_domain) ||
+ ingr(_pw_passwd.pw_name+2, name)) && !lookup(name))
+ return(1);
+ else
+ goto again;
+ } else {
+ if (!strcmp(name, _pw_passwd.pw_name+1) &&
+ !lookup(name))
+ return(1);
+ else
+ goto again;
+ }
+ }
+ if (_pw_passwd.pw_name[0] == '-') {
+ /* Note that a minus wildcard is a no-op. */
+ if (_pw_passwd.pw_name[1] == '@') {
+ if (innetgr(_pw_passwd.pw_name+2, NULL, name,
+ _pw_yp_domain) ||
+ ingr(_pw_passwd.pw_name+2, name)) {
+ store(name);
+ return(0);
+ } else
+ goto again;
+ } else {
+ if (!strcmp(name, _pw_passwd.pw_name+1)) {
+ store(name);
+ return(0);
+ } else
+ goto again;
+ }
+
+ }
+ return(0);
+}
+
+static char * _get_adjunct_pw(name)
+ char *name;
+{
+ static char adjunctbuf[YPMAXRECORD+2];
+ int rval;
+ char *result;
+ int resultlen;
+ char *map = "passwd.adjunct.byname";
+ char *s;
+
+ if ((rval = yp_match(_pw_yp_domain, map, name, strlen(name),
+ &result, &resultlen)))
+ return(NULL);
+
+ strncpy(adjunctbuf, result, resultlen);
+ adjunctbuf[resultlen] = '\0';
+ free(result);
+ result = (char *)&adjunctbuf;
+
+ /* Don't care about the name. */
+ if ((s = strsep(&result, ":")) == NULL)
+ return (NULL); /* name */
+ if ((s = strsep(&result, ":")) == NULL)
+ return (NULL); /* password */
+
+ return(s);
+}
+
+static int
+_pw_breakout_yp(struct passwd *pw, char *res, int resultlen, int master)
+{
+ char *s, *result;
+ static char resbuf[YPMAXRECORD+2];
+
+ /*
+ * Be triple, ultra super-duper paranoid: reject entries
+ * that start with a + or -. yp_mkdb and /var/yp/Makefile
+ * are _both_ supposed to strip these out, but you never
+ * know.
+ */
+ if (*res == '+' || *res == '-')
+ return 0;
+
+ /*
+ * The NIS protocol definition limits the size of an NIS
+ * record to YPMAXRECORD bytes. We need to do a copy to
+ * a static buffer here since the memory pointed to by
+ * res will be free()ed when this function returns.
+ */
+ strncpy((char *)&resbuf, res, resultlen);
+ resbuf[resultlen] = '\0';
+ result = (char *)&resbuf;
+
+ /*
+ * XXX Sanity check: make sure all fields are valid (no NULLs).
+ * If we find a badly formatted entry, we punt.
+ */
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* name */
+ /*
+ * We don't care what pw_fields says: we _always_ want the
+ * username returned to us by NIS.
+ */
+ pw->pw_name = s;
+ pw->pw_fields |= _PWF_NAME;
+
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* password */
+ if(!(pw->pw_fields & _PWF_PASSWD)) {
+ /* SunOS passwd.adjunct hack */
+ if (master == YP_HAVE_ADJUNCT && strstr(s, "##") != NULL) {
+ char *realpw;
+ realpw = _get_adjunct_pw(pw->pw_name);
+ if (realpw == NULL)
+ pw->pw_passwd = s;
+ else
+ pw->pw_passwd = realpw;
+ } else {
+ pw->pw_passwd = s;
+ }
+ pw->pw_fields |= _PWF_PASSWD;
+ }
+
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* uid */
+ if(!(pw->pw_fields & _PWF_UID)) {
+ pw->pw_uid = atoi(s);
+ pw->pw_fields |= _PWF_UID;
+ }
+
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* gid */
+ if(!(pw->pw_fields & _PWF_GID)) {
+ pw->pw_gid = atoi(s);
+ pw->pw_fields |= _PWF_GID;
+ }
+
+ if (master == YP_HAVE_MASTER) {
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* class */
+ if(!(pw->pw_fields & _PWF_CLASS)) {
+ pw->pw_class = s;
+ pw->pw_fields |= _PWF_CLASS;
+ }
+
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* change */
+ if(!(pw->pw_fields & _PWF_CHANGE)) {
+ pw->pw_change = atol(s);
+ pw->pw_fields |= _PWF_CHANGE;
+ }
+
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* expire */
+ if(!(pw->pw_fields & _PWF_EXPIRE)) {
+ pw->pw_expire = atol(s);
+ pw->pw_fields |= _PWF_EXPIRE;
+ }
+ }
+
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* gecos */
+ if(!(pw->pw_fields & _PWF_GECOS)) {
+ pw->pw_gecos = s;
+ pw->pw_fields |= _PWF_GECOS;
+ }
+
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* dir */
+ if(!(pw->pw_fields & _PWF_DIR)) {
+ pw->pw_dir = s;
+ pw->pw_fields |= _PWF_DIR;
+ }
+
+ if ((s = strsep(&result, ":")) == NULL) return 0; /* shell */
+ if(!(pw->pw_fields & _PWF_SHELL)) {
+ pw->pw_shell = s;
+ pw->pw_fields |= _PWF_SHELL;
+ }
+
+ /* Be consistent. */
+ if ((s = strchr(pw->pw_shell, '\n'))) *s = '\0';
+
+ return 1;
+}
+
+static int
+_havemaster(char *_yp_domain)
+{
+ int order;
+ int rval;
+
+ if (!(rval = yp_order(_yp_domain, "master.passwd.byname", &order)))
+ return(YP_HAVE_MASTER);
+
+ /*
+ * NIS+ in YP compat mode doesn't support
+ * YPPROC_ORDER -- no point in continuing.
+ */
+ if (rval == YPERR_YPERR)
+ return(YP_HAVE_NONE);
+
+ /* master.passwd doesn't exist -- try passwd.adjunct */
+ if (rval == YPERR_MAP) {
+ rval = yp_order(_yp_domain, "passwd.adjunct.byname", &order);
+ if (!rval)
+ return(YP_HAVE_ADJUNCT);
+ }
+
+ return (YP_HAVE_NONE);
+}
+
+static int
+_getyppass(struct passwd *pw, const char *name, const char *map)
+{
+ char *result, *s;
+ int resultlen;
+ int rv;
+ char mastermap[YPMAXRECORD];
+
+ if(!_pw_yp_domain) {
+ if(yp_get_default_domain(&_pw_yp_domain))
+ return 0;
+ }
+
+ sprintf(mastermap,"%s",map);
+
+ if (_gotmaster == YP_HAVE_MASTER)
+ sprintf(mastermap,"master.%s", map);
+
+ if(yp_match(_pw_yp_domain, (char *)&mastermap, name, strlen(name),
+ &result, &resultlen))
+ return 0;
+
+ if (!_pw_stepping_yp) {
+ s = strchr(result, ':');
+ if (s) {
+ *s = '\0';
+ } else {
+ /* Must be a malformed entry if no colons. */
+ free(result);
+ return(0);
+ }
+
+ if (!verf(result)) {
+ *s = ':';
+ free(result);
+ return(0);
+ }
+
+ *s = ':'; /* Put back the colon we previously replaced with a NUL. */
+ }
+
+ rv = _pw_breakout_yp(pw, result, resultlen, _gotmaster);
+ free(result);
+ return(rv);
+}
+
+static int
+_nextyppass(struct passwd *pw)
+{
+ static char *key;
+ static int keylen;
+ char *lastkey, *result, *s;
+ int resultlen;
+ int rv;
+ char *map = "passwd.byname";
+
+ if(!_pw_yp_domain) {
+ if(yp_get_default_domain(&_pw_yp_domain))
+ return 0;
+ }
+
+ if (_gotmaster == YP_HAVE_MASTER)
+ map = "master.passwd.byname";
+
+ if(!_pw_stepping_yp) {
+ if(key) free(key);
+ rv = yp_first(_pw_yp_domain, map,
+ &key, &keylen, &result, &resultlen);
+ if(rv) {
+ return 0;
+ }
+ _pw_stepping_yp = 1;
+ goto unpack;
+ } else {
+tryagain:
+ lastkey = key;
+ rv = yp_next(_pw_yp_domain, map, key, keylen,
+ &key, &keylen, &result, &resultlen);
+ free(lastkey);
+unpack:
+ if(rv) {
+ _pw_stepping_yp = 0;
+ return 0;
+ }
+
+ s = strchr(result, ':');
+ if (s) {
+ *s = '\0';
+ } else {
+ /* Must be a malformed entry if no colons. */
+ free(result);
+ goto tryagain;
+ }
+
+ if (lookup(result)) {
+ *s = ':';
+ free(result);
+ goto tryagain;
+ }
+
+ *s = ':'; /* Put back the colon we previously replaced with a NUL. */
+ if (_pw_breakout_yp(pw, result, resultlen, _gotmaster)) {
+ free(result);
+ return(1);
+ } else {
+ free(result);
+ goto tryagain;
+ }
+ }
+}
+
+#endif /* YP */
diff --git a/lib/libc/gen/getttyent.3 b/lib/libc/gen/getttyent.3
index 7ee453d..7d2e7ba 100644
--- a/lib/libc/gen/getttyent.3
+++ b/lib/libc/gen/getttyent.3
@@ -31,7 +31,7 @@
.\"
.\" @(#)getttyent.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd June 4, 1993
+.Dd November 17, 1996
.Dt GETTTYENT 3
.Os BSD 4.3
.Sh NAME
@@ -40,16 +40,23 @@
.Nm setttyent ,
.Nm endttyent
.Nd get ttys file entry
+.Nm isdialuptty ,
+.Nm isnetworktty
+.Nd determine tty type from ttys file entry
.Sh SYNOPSIS
.Fd #include <ttyent.h>
.Ft struct ttyent *
-.Fn getttyent
+.Fn getttyent void
.Ft struct ttyent *
-.Fn getttynam "char *name"
+.Fn getttynam "const char *name"
.Ft int
.Fn setttyent void
.Ft int
.Fn endttyent void
+.Ft int
+.Fn isdialuptty "const char *name"
+.Ft int
+.Fn isnetworktty "const char *name"
.Sh DESCRIPTION
The
.Fn getttyent ,
@@ -62,13 +69,16 @@ file.
.Bd -literal
struct ttyent {
char *ty_name; /* terminal device name */
- char *ty_getty; /* command to execute */
- char *ty_type; /* terminal type */
-#define TTY_ON 0x01 /* enable logins */
+ char *ty_getty; /* command to execute, usually getty */
+ char *ty_type; /* terminal type for termcap */
+#define TTY_ON 0x01 /* enable logins (start ty_getty program) */
#define TTY_SECURE 0x02 /* allow uid of 0 to login */
- int ty_status; /* flag values */
- char *ty_window; /* command for window manager */
+#define TTY_DIALUP 0x04 /* is a dialup tty */
+#define TTY_NETWORK 0x08 /* is a network tty */
+ int ty_status; /* status flags */
+ char *ty_window; /* command to start up window manager */
char *ty_comment; /* comment field */
+ char *ty_group; /* tty group name */
};
.Ed
.Pp
@@ -86,7 +96,7 @@ The name of the default terminal type connected to this tty line.
A mask of bit fields which indicate various actions allowed on this
tty line.
The possible flags are as follows:
-.Bl -tag -width TTY_SECURE
+.Bl -tag -width TTY_NETWORK
.It Dv TTY_ON
Enables logins (i.e.,
.Xr init 8
@@ -95,9 +105,23 @@ will start the command referenced by
on this entry).
.It Dv TTY_SECURE
Allow users with a uid of 0 to login on this terminal.
+.It Dv TTY_DIALUP
+Identifies a tty as a dialin line.
+If this flag is set, then
+.Fn isdialuptty
+will return a non-zero value.
+.It Dv TTY_NETWORK
+Identifies a tty used for network connections.
+If this flag is set, then
+.Fn isnetworktty
+will return a non-zero value.
.El
.It Fa ty_window
The command to execute for a window system associated with the line.
+.It Fa ty_group
+A group name to which the tty belongs.
+If no group is specified in the ttys description file,
+then the tty is placed in an anonymous group called "none".
.It Fa ty_comment
Any trailing comment field, with any leading hash marks (``#'') or
whitespace removed.
@@ -150,6 +174,14 @@ function
and
.Fn endttyent
return 0 on failure and 1 on success.
+.Pp
+The routines
+.Fn isdialuptty
+and
+.Fn isnetworktty
+return non-zero if the dialup or network flag is set for the
+tty entry relating to the tty named by the parameter, and
+zero otherwise.
.Sh FILES
.Bl -tag -width /etc/ttys -compact
.It Pa /etc/ttys
diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c
index f9b1e0d..ac3e138 100644
--- a/lib/libc/gen/getttyent.c
+++ b/lib/libc/gen/getttyent.c
@@ -37,11 +37,19 @@ static char sccsid[] = "@(#)getttyent.c 8.1 (Berkeley) 6/4/93";
#include <ttyent.h>
#include <stdio.h>
+#include <stdlib.h>
#include <ctype.h>
#include <string.h>
static char zapchar;
static FILE *tf;
+static size_t lbsize;
+static char *line;
+
+#define MALLOCCHUNK 100
+
+static char *skip __P((char *));
+static char *value __P((char *));
struct ttyent *
getttynam(tty)
@@ -49,8 +57,10 @@ getttynam(tty)
{
register struct ttyent *t;
+ if (strncmp(tty, "/dev/", 5) == 0)
+ tty += 5;
setttyent();
- while (t = getttyent())
+ while ( (t = getttyent()) )
if (!strcmp(tty, t->ty_name))
break;
endttyent();
@@ -61,22 +71,26 @@ struct ttyent *
getttyent()
{
static struct ttyent tty;
- register int c;
register char *p;
-#define MAXLINELENGTH 100
- static char line[MAXLINELENGTH];
- static char *skip(), *value();
+ register int c;
+ size_t i;
if (!tf && !setttyent())
return (NULL);
for (;;) {
- if (!fgets(p = line, sizeof(line), tf))
+ if (!fgets(p = line, lbsize, tf))
return (NULL);
- /* skip lines that are too big */
- if (!index(p, '\n')) {
- while ((c = getc(tf)) != '\n' && c != EOF)
- ;
- continue;
+ /* extend buffer if line was too big, and retry */
+ while (!index(p, '\n')) {
+ i = strlen(p);
+ lbsize += MALLOCCHUNK;
+ if ((p = realloc(line, lbsize)) == NULL) {
+ (void)endttyent();
+ return (NULL);
+ }
+ line = p;
+ if (!fgets(&line[i], lbsize - i, tf))
+ return (NULL);
}
while (isspace(*p))
++p;
@@ -84,6 +98,9 @@ getttyent()
break;
}
+#define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1])
+#define vcmp(e) !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '='
+
zapchar = 0;
tty.ty_name = p;
p = skip(p);
@@ -93,14 +110,19 @@ getttyent()
p = skip(p);
if (!*(tty.ty_type = p))
tty.ty_type = NULL;
- else
+ else {
+ /* compatibility kludge: handle network/dialup specially */
+ if (scmp(_TTYS_DIALUP))
+ tty.ty_status |= TTY_DIALUP;
+ else if (scmp(_TTYS_NETWORK))
+ tty.ty_status |= TTY_NETWORK;
p = skip(p);
+ }
}
tty.ty_status = 0;
tty.ty_window = NULL;
+ tty.ty_group = _TTYS_NOGROUP;
-#define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1])
-#define vcmp(e) !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '='
for (; *p; p = skip(p)) {
if (scmp(_TTYS_OFF))
tty.ty_status &= ~TTY_ON;
@@ -108,8 +130,16 @@ getttyent()
tty.ty_status |= TTY_ON;
else if (scmp(_TTYS_SECURE))
tty.ty_status |= TTY_SECURE;
+ else if (scmp(_TTYS_INSECURE))
+ tty.ty_status &= ~TTY_SECURE;
+ else if (scmp(_TTYS_DIALUP))
+ tty.ty_status |= TTY_DIALUP;
+ else if (scmp(_TTYS_NETWORK))
+ tty.ty_status |= TTY_NETWORK;
else if (vcmp(_TTYS_WINDOW))
tty.ty_window = value(p);
+ else if (vcmp(_TTYS_GROUP))
+ tty.ty_group = value(p);
else
break;
}
@@ -120,7 +150,7 @@ getttyent()
tty.ty_comment = p;
if (*p == 0)
tty.ty_comment = 0;
- if (p = index(p, '\n'))
+ if ( (p = index(p, '\n')) )
*p = '\0';
return (&tty);
}
@@ -177,10 +207,15 @@ int
setttyent()
{
+ if (line == NULL) {
+ if ((line = malloc(MALLOCCHUNK)) == NULL)
+ return (0);
+ lbsize = MALLOCCHUNK;
+ }
if (tf) {
- (void)rewind(tf);
+ rewind(tf);
return (1);
- } else if (tf = fopen(_PATH_TTYS, "r"))
+ } else if ( (tf = fopen(_PATH_TTYS, "r")) )
return (1);
return (0);
}
@@ -190,10 +225,40 @@ endttyent()
{
int rval;
+ /*
+ * NB: Don't free `line' because getttynam()
+ * may still be referencing it
+ */
if (tf) {
- rval = !(fclose(tf) == EOF);
+ rval = (fclose(tf) != EOF);
tf = NULL;
return (rval);
}
return (1);
}
+
+static int
+isttystat(tty, flag)
+ const char *tty;
+ int flag;
+{
+ register struct ttyent *t;
+
+ return ((t = getttynam(tty)) == NULL) ? 0 : !!(t->ty_status & flag);
+}
+
+
+int
+isdialuptty(tty)
+ const char *tty;
+{
+
+ return isttystat(tty, TTY_DIALUP);
+}
+
+int isnettty(tty)
+ const char *tty;
+{
+
+ return isttystat(tty, TTY_NETWORK);
+}
diff --git a/lib/libc/gen/getusershell.3 b/lib/libc/gen/getusershell.3
index 48aa859..223caef 100644
--- a/lib/libc/gen/getusershell.3
+++ b/lib/libc/gen/getusershell.3
@@ -40,6 +40,7 @@
.Nm endusershell
.Nd get legal user shells
.Sh SYNOPSIS
+.Fd #include <unistd.h>
.Ft char *
.Fn getusershell void
.Ft void
diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c
index 2bcdaf7..408f9f3 100644
--- a/lib/libc/gen/getusershell.c
+++ b/lib/libc/gen/getusershell.c
@@ -72,7 +72,7 @@ getusershell()
void
endusershell()
{
-
+
if (shells != NULL)
free(shells);
shells = NULL;
diff --git a/lib/libc/gen/getvfsbyname.3 b/lib/libc/gen/getvfsbyname.3
index 746d4df..db6152f 100644
--- a/lib/libc/gen/getvfsbyname.3
+++ b/lib/libc/gen/getvfsbyname.3
@@ -38,10 +38,8 @@
.Nm getvfsbyname
.Nd get information about a filesystem
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
+.Fd #include <sys/param.h>
.Fd #include <sys/mount.h>
-.Fd #include <kvm.h>
-.br
.Ft int
.Fn getvfsbyname "const char *name" "struct vfsconf *vfc"
.Sh DESCRIPTION
@@ -53,7 +51,7 @@ If successful,
the requested filesystem
.Fa vfsconf
is returned in the location pointed to by
-.Nm vfc .
+.Fa vfc .
The fields in a
.Dq Li struct vfsconf
are defined as follows:
@@ -95,4 +93,5 @@ specifies a filesystem that is unknown or not configured in the kernel.
.Sh HISTORY
A variant of the
.Fn getvfsbyname
-function first appeared in FreeBSD 2.0.
+function first appeared in
+.Fx 2.0 .
diff --git a/lib/libc/gen/getvfsbyname.c b/lib/libc/gen/getvfsbyname.c
index 9818bae..ae63bfe 100644
--- a/lib/libc/gen/getvfsbyname.c
+++ b/lib/libc/gen/getvfsbyname.c
@@ -32,17 +32,20 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)kvm_getvfsbyname.c 8.1 (Berkeley) 4/3/95";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
+#define _NEW_VFSCONF
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
#include <errno.h>
#include <kvm.h>
-int getvfsbyname __P((const char *, struct vfsconf *));
-
/*
* Given a filesystem name, determine if it is resident in the kernel,
* and if it is resident, return its vfsconf structure.
diff --git a/lib/libc/gen/getvfsent.3 b/lib/libc/gen/getvfsent.3
new file mode 100644
index 0000000..756fec4
--- /dev/null
+++ b/lib/libc/gen/getvfsent.3
@@ -0,0 +1,228 @@
+.\" $Id: getvfsent.3,v 1.8 1997/02/28 06:22:28 mpp Exp $
+.\" Written by Garrett A. Wollman, September 1994.
+.\" This manual page is in the public domain.
+.\"
+.Dd September 24, 1994
+.Dt GETVFSBYNAME 3
+.Os
+.Sh NAME
+.Nm getvfsbyname ,
+.Nm getvfsbytype ,
+.Nm getvfsent ,
+.Nm setvfsent ,
+.Nm endvfsent ,
+.Nm vfsisloadable ,
+.Nm vfsload
+.Nd manage virtual filesystem modules
+.Sh SYNOPSIS
+.Fd #include <sys/param.h>
+.Fd #include <sys/mount.h>
+.Ft struct vfsconf *
+.Fn getvfsbyname "const char *name"
+.Ft struct vfsconf *
+.Fn getvfsbytype "int type"
+.Ft struct vfsconf *
+.Fn getvfsent "void"
+.Ft void
+.Fn setvfsent "int cachelist"
+.Ft void
+.Fn endvfsent "void"
+.Ft int
+.Fn vfsisloadable "const char *name"
+.Ft int
+.Fn vfsload "const char *name"
+.Sh DESCRIPTION
+The
+.Fn getvfsbyname ,
+.Fn getvfsbytype ,
+and
+.Fn getvfsent
+functions provide convenient access to a list of installed virtual
+filesystem modules managed by the kernel.
+.Fn getvfsbyname
+and
+.Fn getvfsbytype
+provide direct access to a single filesystem's information;
+.Fn getvfsent
+steps through the list of filesystems one at a time. All three
+functions return a null pointer when no data is available. The fields
+in a
+.Dq Li struct vfsconf
+are as follows:
+.Pp
+.Bl -tag -compact -width vfc_refcount
+.It vfc_name
+the name of the filesystem
+.It vfc_index
+the filesystem type number assigned by the kernel and used in calls to
+.Xr mount 2
+.It vfc_refcount
+the number of references to this filesystem
+(usually the number of mounts, but one greater for filesystems which
+cannot be unloaded or which are statically linked into the kernel)
+.It vfc_flags
+flag bits, of which none are currently defined
+.El
+.Pp
+The
+.Fn setvfsent
+and
+.Fn endvfsent
+functions are used to control caching of the filesystem list, which is
+obtained in toto from the kernel via
+.Xr sysctl 3 .
+If the
+.Fa cachelist
+parameter to
+.Fn setvfsent
+is non-zero, the list will be retrieved only once, upon the first call
+to one of the retrieval functions, until
+.Fn endvfsent
+is called to clear the cache. In general,
+.Fn setvfsent 1
+should be called by programs using the
+.Fn getvfsent
+function, and
+.Fn setvfsent 0
+(which is also the default state)
+should be called by programs using the
+.Fn vfsload
+function.
+.Pp
+The
+.Fn vfsisloadable
+function returns a non-zero value if a later call to
+.Fn vfsload name
+is likely to succeed. We say ``likely'' because the conditions
+checked by
+.Fn vfsisloadable
+are only a small subset of the conditions necessary for
+.Fn vfsload
+to succeed. In particular,
+.Fn vfsisloadable
+checks that
+.Pa /dev/lkm
+is present and can be opened for writing, and that
+.Pa Ns Fa name Ns _mod.o
+can be found in one of the directories designated for LKMs.
+.Pp
+The
+.Fn vfsload
+function attempts to load a kernel module implementing filesystem
+.Fa name .
+It returns zero if the filesystem module was successfully located and
+loaded, or non-zero otherwise. It should only be called in the
+following circumstances:
+.Bl -enum
+.It
+.Fn getvfsbyname name
+has been called and returned a null pointer.
+.It
+.Fn vfsisloadable name
+has been called and returned a non-zero value.
+.It
+sufficient temporary file space is available
+.Em and writable
+in one of
+.No Ns \&${ Ns Ev TMPDIR Ns \&} ,
+.Pa /var/tmp ,
+or
+.Pa /tmp .
+.El
+.Pp
+Here is an example, taken from the source to
+.Xr mount_cd9660 8 :
+.Bd -literal -offset indent
+
+struct vfsconf *vfc;
+
+/* setup code here */
+
+vfc = getvfsbyname("cd9660");
+if(!vfc && vfsisloadable("cd9660")) {
+ if(vfsload("cd9660"))
+ err(1, "vfsload(cd9660)");
+ endvfsent(); /* flush cache */
+ vfc = getvfsbyname("cd9660");
+}
+
+mount(vfc ? vfc->vfc_index : MOUNT_CD9660, /* more arguments */
+
+.Ed
+The odd conditional in the call to
+.Xr mount 2
+is present for compatibility with old, non-LKM cognizant kernels, and
+will be removed (along with all vestiges of
+.Dv MOUNT_* )
+in a future release.
+.Sh RETURN VALUES
+The
+.Fn getvfsbyname ,
+.Fn getvfsbytype ,
+and
+.Fn getvfsent
+routines all return a pointer to the same static data structure when
+they succeed, and return a null pointer when they fail. On failure,
+.Va errno
+may be set to one of the values documented for
+.Xr sysctl 3
+or
+.Xr malloc 3 ,
+if a failure of that function was the cause; otherwise
+.Va errno
+will be unmodified.
+.Pp
+The
+.Fn vfsload
+function returns a non-zero value on failure, or zero on success. If
+.Fn vfsload
+fails,
+.Va errno
+may be set to one of the values documented for
+.Xr fork 2 ,
+.Xr waitpid 2 ,
+.Xr chdir 2 ,
+or
+.Xr execlp 3 ,
+or the return status of the
+.Xr modload 8
+program, which is not currently particularly useful but eventually
+will be. In addition, if
+.Xr modload 8
+exits on a signal,
+.Fn vfsload
+will fail and set
+.Va errno
+to
+.Er EINVAL .
+.Sh ENVIRONMENT
+.Bl -tag -compact -width TMPDIRx
+.It Ev TMPDIR
+location for temporary file created by
+.Xr modload 8
+on behalf of
+.Fn vfsload .
+.It Ev LKMDIR
+alternate directory for
+.Fn vfsisloadable
+and
+.Fn vfsload
+to search for loadable modules.
+.Sh SEE ALSO
+.Xr mount 2 ,
+.Xr modload 8 ,
+.Xr mount 8
+.Sh BUGS
+The return value of the
+.Xr modload 8
+command isn't particularly useful when interpreted as an
+.Va errno
+value (or anything else, for that matter).
+.Sh AUTHOR
+The loadable filesystem support was written by Garrett A. Wollman,
+based on generic loadable kernel module support by Terry Lambert.
+.Sh HISTORY
+The
+.Fn getvfsbyname
+family of functions first appeared in
+.Fx 2.0 .
diff --git a/lib/libc/gen/getvfsent.c b/lib/libc/gen/getvfsent.c
new file mode 100644
index 0000000..c4ce2cc
--- /dev/null
+++ b/lib/libc/gen/getvfsent.c
@@ -0,0 +1,248 @@
+/*
+ * getvfsent.c - get a listing of installed filesystems
+ * Written September 1994 by Garrett A. Wollman
+ * This file is in the public domain.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/sysctl.h>
+#include <unistd.h>
+#include <sys/file.h>
+#include <sys/wait.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <paths.h>
+
+#define _PATH_MODLOAD "/sbin/modload" /* XXX should be in header file */
+
+static struct vfsconf *_vfslist = 0;
+static struct vfsconf _vfsconf;
+static size_t _vfslistlen = 0;
+static int _vfs_keeplist = 0;
+static int _vfs_index = 0;
+
+static int
+initvfs(void)
+{
+ int mib[2] = { CTL_VFS, VFS_VFSCONF };
+ size_t size = 0;
+ int rv;
+
+ rv = sysctl(mib, 2, (void *)0, &size, (void *)0, (size_t)0);
+ if(rv < 0)
+ return 0;
+
+ if(_vfslist)
+ free(_vfslist);
+ _vfslist = malloc(size);
+ if(!_vfslist)
+ return 0;
+
+ rv = sysctl(mib, 2, _vfslist, &size, (void *)0, (size_t)0);
+ if(rv < 0) {
+ free(_vfslist);
+ _vfslist = 0;
+ return 0;
+ }
+
+ _vfslistlen = size / sizeof _vfslist[0];
+ return 1;
+}
+
+struct vfsconf *
+getvfsent(void)
+{
+ if(!_vfslist && !initvfs()) {
+ return 0;
+ }
+
+ do {
+ if(_vfs_index >= _vfslistlen) {
+ return 0;
+ }
+
+ _vfsconf = _vfslist[_vfs_index++];
+ } while(!_vfsconf.vfc_vfsops);
+
+ if(!_vfs_keeplist) {
+ free(_vfslist);
+ _vfslist = 0;
+ }
+ return &_vfsconf;
+}
+
+struct vfsconf *
+getvfsbyname(const char *name)
+{
+ int i;
+
+ if(!_vfslist && !initvfs()) {
+ return 0;
+ }
+
+ for(i = 0; i < _vfslistlen; i++) {
+ if( ! strcmp(_vfslist[i].vfc_name, name) )
+ break;
+ }
+
+ if(i < _vfslistlen) {
+ _vfsconf = _vfslist[i];
+ }
+
+ if(!_vfs_keeplist) {
+ free(_vfslist);
+ _vfslist = 0;
+ }
+
+ if(i < _vfslistlen) {
+ return &_vfsconf;
+ } else {
+ return 0;
+ }
+}
+
+struct vfsconf *
+getvfsbytype(int type)
+{
+ int i;
+
+ if(!_vfslist && !initvfs()) {
+ return 0;
+ }
+
+ for(i = 0; i < _vfslistlen; i++) {
+ if(_vfslist[i].vfc_index == type)
+ break;
+ }
+
+ if(i < _vfslistlen) {
+ _vfsconf = _vfslist[i];
+ }
+
+ if(!_vfs_keeplist) {
+ free(_vfslist);
+ _vfslist = 0;
+ }
+
+ if(i < _vfslistlen) {
+ return &_vfsconf;
+ } else {
+ return 0;
+ }
+}
+
+void
+setvfsent(int keep)
+{
+ if(_vfslist && !keep) {
+ free(_vfslist);
+ _vfslist = 0;
+ }
+
+ _vfs_keeplist = keep;
+ _vfs_index = 0;
+}
+
+void
+endvfsent(void)
+{
+ if(_vfslist) {
+ free(_vfslist);
+ _vfslist = 0;
+ }
+
+ _vfs_index = 0;
+}
+
+static const char *vfs_lkmdirs[] = {
+ "/lkm",
+ "/usr/lkm",
+ 0,
+ 0
+};
+#define NLKMDIRS ((sizeof vfs_lkmdirs) / (sizeof vfs_lkmdirs[0]))
+
+static const char *
+vfspath(const char *name)
+{
+ static char pnbuf[MAXPATHLEN];
+ char *userdir = getenv("LKMDIR");
+ int i;
+
+ if(userdir && getuid() == geteuid() && getuid() == 0) {
+ vfs_lkmdirs[NLKMDIRS - 2] = userdir;
+ }
+
+ for(i = 0; vfs_lkmdirs[i]; i++) {
+ snprintf(pnbuf, sizeof pnbuf, "%s/%s_mod.o", vfs_lkmdirs[i], name);
+ if( ! access(pnbuf, R_OK) )
+ return pnbuf;
+ }
+
+ return 0;
+}
+
+int
+vfsisloadable(const char *name)
+{
+ int fd;
+
+ fd = open("/dev/lkm", O_RDWR, 0);
+ if(fd < 0) {
+ return 0;
+ }
+ close(fd);
+
+ return !!vfspath(name);
+}
+
+int
+vfsload(const char *name)
+{
+ const char *path = vfspath(name);
+ char name_mod[sizeof("_mod") + strlen(name)];
+ pid_t pid;
+ int status;
+
+ if(!path) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ pid = fork();
+ if(pid < 0)
+ return -1;
+
+ if(pid > 0) {
+ waitpid(pid, &status, 0);
+ if(WIFEXITED(status)) {
+ errno = WEXITSTATUS(status);
+ return errno ? -1 : 0;
+ }
+ errno = EINVAL; /* not enough errno values, >sigh< */
+ return -1;
+ }
+
+ status = -1;
+ unsetenv("TMPDIR");
+ if(status) {
+ status = chdir(_PATH_VARTMP);
+ }
+ if(status) {
+ status = chdir(_PATH_TMP);
+ }
+ if(status) {
+ exit(errno);
+ }
+
+ snprintf(name_mod, sizeof name_mod, "%s%s", name, "_mod");
+ status = execl(_PATH_MODLOAD, "modload", "-e", name_mod, "-o",
+ name_mod, "-u", "-q", path, (const char *)0);
+
+ exit(status ? errno : 0);
+}
+
diff --git a/lib/libc/gen/glob.3 b/lib/libc/gen/glob.3
index f28bc2a..50fd91a 100644
--- a/lib/libc/gen/glob.3
+++ b/lib/libc/gen/glob.3
@@ -43,7 +43,7 @@
.Sh SYNOPSIS
.Fd #include <glob.h>
.Ft int
-.Fn glob "const char *pattern" "int flags" "const int (*errfunc)(const char *, int)" "glob_t *pglob"
+.Fn glob "const char *pattern" "int flags" "int (*errfunc)(const char *, int)" "glob_t *pglob"
.Ft void
.Fn globfree "glob_t *pglob"
.Sh DESCRIPTION
@@ -220,10 +220,11 @@ to provide globbing from directories stored on tape.
Pre-process the pattern string to expand
.Ql {pat,pat,...}
strings like
-.Xr csh 1. The pattern
+.Xr csh 1 .
+The pattern
.Ql {}
-is left unexpanded for historical reasons
-.Xr (Csh 1
+is left unexpanded for historical reasons (and
+.Xr csh 1
does the same thing to
ease typing
of
@@ -424,7 +425,8 @@ The
.Fn glob
and
.Fn globfree
-functions first appeared in 4.4BSD.
+functions first appeared in
+.Bx 4.4 .
.Sh BUGS
Patterns longer than
.Dv MAXPATHLEN
diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c
index 8c8e162..f58fd8d 100644
--- a/lib/libc/gen/glob.c
+++ b/lib/libc/gen/glob.c
@@ -58,7 +58,7 @@ static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
* GLOB_TILDE:
* expand ~user/foo to the /home/dir/of/user/foo
* GLOB_BRACE:
- * expand {1,2}{a,b} to 1a 1b 2a 2b
+ * expand {1,2}{a,b} to 1a 1b 2a 2b
* gl_matchc:
* Number of matches in the current invocation of glob.
*/
@@ -76,6 +76,8 @@ static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
#include <string.h>
#include <unistd.h>
+#include "collate.h"
+
#define DOLLAR '$'
#define DOT '.'
#define EOS '\0'
@@ -140,7 +142,7 @@ static int glob1 __P((Char *, glob_t *));
static int glob2 __P((Char *, Char *, Char *, glob_t *));
static int glob3 __P((Char *, Char *, Char *, Char *, glob_t *));
static int globextend __P((const Char *, glob_t *));
-static const Char * globtilde __P((const Char *, Char *, glob_t *));
+static const Char * globtilde __P((const Char *, Char *, size_t, glob_t *));
static int globexp1 __P((const Char *, glob_t *));
static int globexp2 __P((const Char *, const Char *, glob_t *, int *));
static int match __P((Char *, Char *, Char *));
@@ -173,7 +175,7 @@ glob(pattern, flags, errfunc, pglob)
bufend = bufnext + MAXPATHLEN;
if (flags & GLOB_QUOTE) {
/* Protect the quoted characters. */
- while (bufnext < bufend && (c = *patnext++) != EOS)
+ while (bufnext < bufend && (c = *patnext++) != EOS)
if (c == QUOTE) {
if ((c = *patnext++) == EOS) {
c = QUOTE;
@@ -184,8 +186,8 @@ glob(pattern, flags, errfunc, pglob)
else
*bufnext++ = c;
}
- else
- while (bufnext < bufend && (c = *patnext++) != EOS)
+ else
+ while (bufnext < bufend && (c = *patnext++) != EOS)
*bufnext++ = c;
*bufnext = EOS;
@@ -246,7 +248,7 @@ static int globexp2(ptr, pattern, pglob, rv)
for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
continue;
if (*pe == EOS) {
- /*
+ /*
* We could not find a matching RBRACKET.
* Ignore and just look for RBRACE
*/
@@ -274,7 +276,7 @@ static int globexp2(ptr, pattern, pglob, rv)
for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
continue;
if (*pm == EOS) {
- /*
+ /*
* We could not find a matching RBRACKET.
* Ignore and just look for RBRACE
*/
@@ -299,7 +301,7 @@ static int globexp2(ptr, pattern, pglob, rv)
/* Append the current string */
for (lm = ls; (pl < pm); *lm++ = *pl++)
continue;
- /*
+ /*
* Append the rest of the pattern after the
* closing brace
*/
@@ -330,29 +332,33 @@ static int globexp2(ptr, pattern, pglob, rv)
* expand tilde from the passwd file.
*/
static const Char *
-globtilde(pattern, patbuf, pglob)
+globtilde(pattern, patbuf, patbuf_len, pglob)
const Char *pattern;
Char *patbuf;
+ size_t patbuf_len;
glob_t *pglob;
{
struct passwd *pwd;
char *h;
const Char *p;
- Char *b;
+ Char *b, *eb;
if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
return pattern;
- /* Copy up to the end of the string or / */
- for (p = pattern + 1, h = (char *) patbuf; *p && *p != SLASH;
- *h++ = *p++)
+ /*
+ * Copy up to the end of the string or /
+ */
+ eb = &patbuf[patbuf_len - 1];
+ for (p = pattern + 1, h = (char *) patbuf;
+ h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
continue;
*h = EOS;
if (((char *) patbuf)[0] == EOS) {
- /*
- * handle a plain ~ or ~/ by expanding $HOME
+ /*
+ * handle a plain ~ or ~/ by expanding $HOME
* first and then trying the password file
*/
if ((h = getenv("HOME")) == NULL) {
@@ -373,16 +379,17 @@ globtilde(pattern, patbuf, pglob)
}
/* Copy the home directory */
- for (b = patbuf; *h; *b++ = *h++)
+ for (b = patbuf; b < eb && *h; *b++ = *h++)
continue;
-
+
/* Append the rest of the pattern */
- while ((*b++ = *p++) != EOS)
+ while (b < eb && (*b++ = *p++) != EOS)
continue;
+ *b = EOS;
return patbuf;
}
-
+
/*
* The main glob() routine: compiles the pattern (optionally processing
@@ -400,7 +407,8 @@ glob0(pattern, pglob)
int c, err, oldpathc;
Char *bufnext, patbuf[MAXPATHLEN+1];
- qpatnext = globtilde(pattern, patbuf, pglob);
+ qpatnext = globtilde(pattern, patbuf, sizeof(patbuf) / sizeof(Char),
+ pglob);
oldpathc = pglob->gl_pathc;
bufnext = patbuf;
@@ -440,7 +448,7 @@ glob0(pattern, pglob)
break;
case STAR:
pglob->gl_flags |= GLOB_MAGCHAR;
- /* collapse adjacent stars to one,
+ /* collapse adjacent stars to one,
* to avoid exponential behavior
*/
if (bufnext == patbuf || bufnext[-1] != M_ALL)
@@ -460,17 +468,17 @@ glob0(pattern, pglob)
return(err);
/*
- * If there was no match we are going to append the pattern
+ * If there was no match we are going to append the pattern
* if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
* and the pattern did not contain any magic characters
* GLOB_NOMAGIC is there just for compatibility with csh.
*/
- if (pglob->gl_pathc == oldpathc &&
- ((pglob->gl_flags & GLOB_NOCHECK) ||
+ if (pglob->gl_pathc == oldpathc &&
+ ((pglob->gl_flags & GLOB_NOCHECK) ||
((pglob->gl_flags & GLOB_NOMAGIC) &&
!(pglob->gl_flags & GLOB_MAGCHAR))))
return(globextend(pattern, pglob));
- else if (!(pglob->gl_flags & GLOB_NOSORT))
+ else if (!(pglob->gl_flags & GLOB_NOSORT))
qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
pglob->gl_pathc - oldpathc, sizeof(char *), compare);
return(0);
@@ -519,7 +527,7 @@ glob2(pathbuf, pathend, pattern, pglob)
*pathend = EOS;
if (g_lstat(pathbuf, &sb, pglob))
return(0);
-
+
if (((pglob->gl_flags & GLOB_MARK) &&
pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
|| (S_ISLNK(sb.st_mode) &&
@@ -572,7 +580,7 @@ glob3(pathbuf, pathend, pattern, restpattern, pglob)
*pathend = EOS;
errno = 0;
-
+
if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
/* TODO: don't call for ENOENT or ENOTDIR? */
if (pglob->gl_errfunc) {
@@ -598,7 +606,7 @@ glob3(pathbuf, pathend, pattern, restpattern, pglob)
/* Initial DOT must be matched literally. */
if (dp->d_name[0] == DOT && *pattern != DOT)
continue;
- for (sc = (u_char *) dp->d_name, dc = pathend;
+ for (sc = (u_char *) dp->d_name, dc = pathend;
(*dc++ = *sc++) != EOS;)
continue;
if (!match(pathend, pattern, restpattern)) {
@@ -644,7 +652,7 @@ globextend(path, pglob)
const Char *p;
newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
- pathv = pglob->gl_pathv ?
+ pathv = pglob->gl_pathv ?
realloc((char *)pglob->gl_pathv, newsize) :
malloc(newsize);
if (pathv == NULL)
@@ -668,7 +676,6 @@ globextend(path, pglob)
return(copy == NULL ? GLOB_NOSPACE : 0);
}
-
/*
* pattern matching function for filenames. Each occurrence of the *
* pattern causes a recursion level.
@@ -686,7 +693,7 @@ match(name, pat, patend)
case M_ALL:
if (pat == patend)
return(1);
- do
+ do
if (match(name, pat, patend))
return(1);
while (*name++ != EOS);
@@ -703,7 +710,11 @@ match(name, pat, patend)
++pat;
while (((c = *pat++) & M_MASK) != M_END)
if ((*pat & M_MASK) == M_RNG) {
- if (c <= k && k <= pat[1])
+ if (__collate_load_error ?
+ CHAR(c) <= CHAR(k) && CHAR(k) <= CHAR(pat[1]) :
+ __collate_range_cmp(CHAR(c), CHAR(k)) <= 0
+ && __collate_range_cmp(CHAR(k), CHAR(pat[1])) <= 0
+ )
ok = 1;
pat += 2;
} else if (c == k)
@@ -825,7 +836,7 @@ g_Ctoc(str, buf)
}
#ifdef DEBUG
-static void
+static void
qprintf(str, s)
const char *str;
register Char *s;
diff --git a/lib/libc/gen/initgroups.3 b/lib/libc/gen/initgroups.3
index a0b1c4f..474265d 100644
--- a/lib/libc/gen/initgroups.3
+++ b/lib/libc/gen/initgroups.3
@@ -67,14 +67,14 @@ returns \-1 if it was not invoked by the super-user.
.Xr getgrouplist 3
.Sh HISTORY
The
-.Nm
+.Fn initgroups
function appeared in
.Bx 4.2 .
.Sh BUGS
The
.Fn getgrouplist
function called by
-.Nm
+.Fn initgroups
uses the routines based on
.Xr getgrent 3 .
If the invoking program uses any of these routines,
diff --git a/lib/libc/gen/initgroups.c b/lib/libc/gen/initgroups.c
index d427539..b1ddd86 100644
--- a/lib/libc/gen/initgroups.c
+++ b/lib/libc/gen/initgroups.c
@@ -38,6 +38,8 @@ static char sccsid[] = "@(#)initgroups.c 8.1 (Berkeley) 6/4/93";
#include <sys/param.h>
#include <stdio.h>
+#include <err.h>
+#include <unistd.h>
int
initgroups(uname, agroup)
diff --git a/lib/libc/gen/isatty.c b/lib/libc/gen/isatty.c
index f6bb04b..c8356c7 100644
--- a/lib/libc/gen/isatty.c
+++ b/lib/libc/gen/isatty.c
@@ -37,12 +37,27 @@ static char sccsid[] = "@(#)isatty.c 8.1 (Berkeley) 6/4/93";
#include <termios.h>
#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
int
isatty(fd)
int fd;
{
+ int retval;
struct termios t;
- return(tcgetattr(fd, &t) != -1);
+#ifdef _THREAD_SAFE
+ if (_thread_fd_lock(fd, FD_READ, NULL,__FILE__,__LINE__) == 0) {
+#endif
+ retval = (tcgetattr(fd, &t) != -1);
+#ifdef _THREAD_SAFE
+ _thread_fd_unlock(fd, FD_READ);
+ } else {
+ retval = 0;
+ }
+#endif
+ return(retval);
}
diff --git a/lib/libc/gen/jrand48.c b/lib/libc/gen/jrand48.c
new file mode 100644
index 0000000..051d5a6
--- /dev/null
+++ b/lib/libc/gen/jrand48.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#include "rand48.h"
+
+long
+jrand48(unsigned short xseed[3])
+{
+ _dorand48(xseed);
+ return ((long) xseed[2] << 16) + (long) xseed[1];
+}
diff --git a/lib/libc/gen/lcong48.c b/lib/libc/gen/lcong48.c
new file mode 100644
index 0000000..f13826b
--- /dev/null
+++ b/lib/libc/gen/lcong48.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#include "rand48.h"
+
+extern unsigned short _rand48_seed[3];
+extern unsigned short _rand48_mult[3];
+extern unsigned short _rand48_add;
+
+void
+lcong48(unsigned short p[7])
+{
+ _rand48_seed[0] = p[0];
+ _rand48_seed[1] = p[1];
+ _rand48_seed[2] = p[2];
+ _rand48_mult[0] = p[3];
+ _rand48_mult[1] = p[4];
+ _rand48_mult[2] = p[5];
+ _rand48_add = p[6];
+}
diff --git a/lib/libc/gen/ldexp.3 b/lib/libc/gen/ldexp.3
index bffcacf..0307ad1 100644
--- a/lib/libc/gen/ldexp.3
+++ b/lib/libc/gen/ldexp.3
@@ -68,10 +68,10 @@ and the value
is returned.
.Sh SEE ALSO
.Xr frexp 3 ,
-.Xr modf 3 ,
-.Xr math 3
+.Xr math 3 ,
+.Xr modf 3
.Sh STANDARDS
The
.Fn ldexp
-function conforms
+function conforms to
.St -ansiC .
diff --git a/lib/libc/gen/lrand48.c b/lib/libc/gen/lrand48.c
new file mode 100644
index 0000000..a3d0111
--- /dev/null
+++ b/lib/libc/gen/lrand48.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#include "rand48.h"
+
+extern unsigned short _rand48_seed[3];
+
+long
+lrand48(void)
+{
+ _dorand48(_rand48_seed);
+ return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >> 1);
+}
diff --git a/lib/libc/gen/mrand48.c b/lib/libc/gen/mrand48.c
new file mode 100644
index 0000000..b23db51
--- /dev/null
+++ b/lib/libc/gen/mrand48.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#include "rand48.h"
+
+extern unsigned short _rand48_seed[3];
+
+long
+mrand48(void)
+{
+ _dorand48(_rand48_seed);
+ return ((long) _rand48_seed[2] << 16) + (long) _rand48_seed[1];
+}
diff --git a/lib/libc/gen/msgctl.3 b/lib/libc/gen/msgctl.3
new file mode 100644
index 0000000..c505e7d
--- /dev/null
+++ b/lib/libc/gen/msgctl.3
@@ -0,0 +1,207 @@
+.\" $NetBSD: msgctl.2,v 1.1 1995/10/16 23:49:15 jtc Exp $
+.\"
+.\" Copyright (c) 1995 Frank van der Linden
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed for the NetBSD Project
+.\" by Frank van der Linden
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"/
+.Dd August 17, 1995
+.Dt MSGCTL 3
+.Os FreeBSD
+.Sh NAME
+.Nm msgctl
+.Nd message control operations
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Fd #include <sys/msg.h>
+.Ft int
+.Fn msgctl "int msqid" "int cmd" "struct msqid_ds *buf"
+.Sh DESCRIPTION
+The
+.Fn msgctl
+system call performs some control operations on the message queue specified
+by
+.Fa msqid .
+
+Each message queue has a data structure associated with it, parts of which
+may be altered by
+.Fn msgctl
+and parts of which determine the actions of
+.Fn msgctl .
+The data structure is defined in
+.Aq Pa sys/msg.h
+and contains (amongst others) the following members:
+.Bd -literal
+struct msqid_ds {
+ struct ipc_perm msg_perm; /* msg queue permission bits */
+ struct msg *msg_first; /* first message in the queue */
+ struct msg *msg_last; /* last message in the queue */
+ u_long msg_cbytes; /* number of bytes in use on the queue */
+ u_long msg_qnum; /* number of msgs in the queue */
+ u_long msg_qbytes; /* max # of bytes on the queue */
+ pid_t msg_lspid; /* pid of last msgsnd() */
+ pid_t msg_lrpid; /* pid of last msgrcv() */
+ time_t msg_stime; /* time of last msgsnd() */
+ long msg_pad1;
+ time_t msg_rtime; /* time of last msgrcv() */
+ long msg_pad2;
+ time_t msg_ctime; /* time of last msgctl() */
+ long msg_pad3;
+ long msg_pad4[4];
+};
+.Ed
+.Pp
+The
+.Bf -literal
+ipc_perm
+.Ef
+structure used inside the
+.Bf -literal
+shmid_ds
+.Ef
+structure is defined in
+.Aq Pa sys/ipc.h
+and looks like this:
+.Bd -literal
+struct ipc_perm {
+ ushort cuid; /* creator user id */
+ ushort cgid; /* creator group id */
+ ushort uid; /* user id */
+ ushort gid; /* group id */
+ ushort mode; /* r/w permission */
+ ushort seq; /* sequence # (to generate unique msg/sem/shm id) */
+ key_t key; /* user specified msg/sem/shm key */
+};
+.Ed
+.Pp
+The operation to be performed by
+.Fn msgctl
+is specified in
+.Fa cmd
+and is one of:
+.Bl -tag -width IPC_RMIDX
+.It Dv IPC_STAT
+Gather information about the message queue and place it in the
+structure pointed to by
+.Fa buf .
+.It Dv IPC_SET
+Set the value of the
+.Va msg_perm.uid ,
+.Va msg_perm.gid ,
+.Va msg_perm.mode
+and
+.Va msg_qbytes
+fields in the structure associated with
+.Fa msqid .
+The values are taken from the corresponding fields in the structure
+pointed to by
+.Fa buf .
+This operation can only be executed by the super-user, or a process that
+has an effective user id equal to either
+.Va msg_perm.cuid
+or
+.Va msg_perm.uid
+in the data structure associated with the message queue.
+The value of
+.Va msg_qbytes
+can only be increased by the super-user. Values for
+.Va msg_qbytes
+that exceed the system limit (MSGMNB from
+.Aq Pa sys/msg.h )
+are silently truncated to that limit.
+
+.It Dv IPC_RMID
+Remove the message queue specified by
+.Fa msqid
+and destroy the data associated with it. Only the super-user or a process
+with an effective uid equal to the
+.Va msg_perm.cuid
+or
+.Va msg_perm.uid
+values in the data structure associated with the queue can do this.
+.El
+
+The permission to read from or write to a message queue (see
+.Xr msgsnd 3
+and
+.Xr msgrcv 3 )
+is determined by the
+.Va msg_perm.mode
+field in the same way as is
+done with files (see
+.Xr chmod 2 ),
+but the effective uid can match either the
+.Va msg_perm.cuid
+field or the
+.Va msg_perm.uid
+field, and the
+effective gid can match either
+.Va msg_perm.cgid
+or
+.Va msg_perm.gid .
+.Sh RETURN VALUES
+Upon successful completion, a value of 0 is returned. Otherwise, -1 is
+returned and the global variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn msgctl
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EPERM
+.Fa cmd
+is equal to IPC_SET or IPC_RMID and the caller is not the super-user, nor does
+the effective uid match either the
+.Va msg_perm.uid
+or
+.Va msg_perm.cuid
+fields of the data structure associated with the message queue.
+
+An attempt is made to increase the value of
+.Va msg_qbytes
+through IPC_SET
+but the caller is not the super-user.
+.It Bq Er EACCESS
+The command is IPC_STAT
+and the caller has no read permission for this message queue.
+.It Bq Er EINVAL
+.Fa msqid
+is not a valid message queue identifier.
+
+.Va cmd
+is not a valid command.
+.It Bq Er EFAULT
+.Fa buf
+specifies an invalid address.
+.El
+.Sh SEE ALSO
+.Xr msgget 3 ,
+.Xr msgrcv 3 ,
+.Xr msgsnd 3
+.Sh HISTORY
+Message queues appeared in the first release of AT&T Unix System V.
diff --git a/lib/libc/gen/msgctl.c b/lib/libc/gen/msgctl.c
new file mode 100644
index 0000000..7b74c51e
--- /dev/null
+++ b/lib/libc/gen/msgctl.c
@@ -0,0 +1,15 @@
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+#if __STDC__
+int msgctl(int msqid, int cmd, struct msqid_ds *buf)
+#else
+int msgctl(msqid,cmd,buf)
+ int msqid;
+ int cmd;
+ caddr_t buf;
+#endif
+{
+ return (msgsys(0, msqid, cmd, buf));
+}
diff --git a/lib/libc/gen/msgget.3 b/lib/libc/gen/msgget.3
new file mode 100644
index 0000000..72a07e4
--- /dev/null
+++ b/lib/libc/gen/msgget.3
@@ -0,0 +1,134 @@
+.\" $NetBSD: msgget.2,v 1.1 1995/10/16 23:49:19 jtc Exp $
+.\"
+.\" Copyright (c) 1995 Frank van der Linden
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed for the NetBSD Project
+.\" by Frank van der Linden
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"/
+.Dd August 17, 1995
+.Dt MSGGET 3
+.Os FreeBSD
+.Sh NAME
+.Nm msgget
+.Nd get message queue
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Fd #include <sys/msg.h>
+.Ft int
+.Fn msgget "key_t key" "int msgflg"
+.Sh DESCRIPTION
+.Fn msgget
+returns the message queue identifier associated with
+.Fa key .
+A message queue identifier is a unique integer greater than zero.
+.Pp
+A message queue is created if either
+.Fa key
+is equal to
+.Dv IPC_PRIVATE ,
+or
+.Fa key
+does not have a message queue identifier associated with it, and the
+.Dv IPC_CREAT
+bit is set in
+.Fa msgflg.
+.Pp
+If a new message queue is created, the data structure associated with it (the
+.Va msqid_ds
+structure, see
+.Xr msgctl 3 )
+is initialized as follows:
+.Bl -bullet
+.It
+.Va msg_perm.cuid
+and
+.Va msg_perm.uid
+are set to the effective uid of the calling process.
+.It
+.Va msg_perm.gid
+and
+.Va msg_perm.cgid
+are set to the effective gid of the calling process.
+.It
+.Va msg_perm.mode
+is set to the lower 9 bits of
+.Fa msgflg .
+.It
+.Va msg_cbytes ,
+.Va msg_qnum ,
+.Va msg_lspid ,
+.Va msg_lrpid ,
+.Va msg_rtime ,
+and
+.Va msg_stime
+are set to 0.
+.It
+.Va msg_qbytes
+is set to the system wide maximum value for the number of bytes in a queue
+.Pf ( Dv MSGMNB ) .
+.It
+.Va msg_ctime
+is set to the current time.
+.El
+.Sh RETURN VALUES
+Upon successful completion a positive message queue identifier is returned.
+Otherwise, -1 is returned and the global variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er EACESS
+A message queue is already associated with
+.Fa key
+and the caller has no permission to access it.
+.It Bq Er EEXIST
+Both
+.Dv IPC_CREAT
+and
+.Dv IPC_EXCL
+are set in
+.Fa msgflg ,
+and a message queue is already associated with
+.Fa key .
+.It Bq Er ENOSPC
+A new message queue could not be created because the system limit for
+the number of message queues has been reached.
+.It Bq Er ENOENT
+.Dv IPC_CREAT
+was not set in
+.Fa msgflg
+and no message queue associated with
+.Fa key
+was found.
+.El
+.Sh SEE ALSO
+.Xr msgctl 3 ,
+.Xr msgrcv 3 ,
+.Xr msgsnd 3
+.Sh HISTORY
+Message queues appeared in the first release of AT&T Unix System V.
diff --git a/lib/libc/gen/msgget.c b/lib/libc/gen/msgget.c
new file mode 100644
index 0000000..3e146b0
--- /dev/null
+++ b/lib/libc/gen/msgget.c
@@ -0,0 +1,14 @@
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+#if __STDC__
+int msgget(key_t key, int msgflg)
+#else
+int msgget(key,msgflg)
+ key_t key;
+ int msgflg;
+#endif
+{
+ return (msgsys(1, key, msgflg));
+}
diff --git a/lib/libc/gen/msgrcv.3 b/lib/libc/gen/msgrcv.3
new file mode 100644
index 0000000..11099ca
--- /dev/null
+++ b/lib/libc/gen/msgrcv.3
@@ -0,0 +1,207 @@
+.\" $NetBSD: msgrcv.2,v 1.1 1995/10/16 23:49:20 jtc Exp $
+.\"
+.\" Copyright (c) 1995 Frank van der Linden
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed for the NetBSD Project
+.\" by Frank van der Linden
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"/
+.Dd August 17, 1995
+.Dt MSGRCV 3
+.Os FreeBSD
+.Sh NAME
+.Nm msgrcv
+.Nd receive a message from a message queue
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Fd #include <sys/msg.h>
+.Ft int
+.Fn msgrcv "int msqid" "void *msgp" "size_t msgsz" "long msgtyp" "int msgflg"
+.Sh DESCRIPTION
+The
+.Fn msgrcv
+function receives a message from the message queue specified in
+.Fa msqid ,
+and places it into the structure pointed to by
+.Fa msgp .
+This structure should consist of the following members:
+.Bd -literal
+ long mtype; /* message type */
+ char mtext[1]; /* body of message */
+.Ed
+.Pp
+.Va mtype
+is an integer greater than 0 that can be used for selecting messages,
+.Va mtext
+is an array of bytes, with a size up to that of the system limit
+.Pf ( Dv MSGMAX ) .
+.Pp
+The value of
+.Fa msgtyp
+has one of the following meanings:
+.Bl -bullet
+.It
+.Fa msgtyp
+is greater than 0. The first message of type
+.Fa msgtyp
+will be received.
+.It
+.Fa msgtyp
+is equal to 0. The first message on the queue will be received.
+.It
+.Fa msgtyp
+is less than 0. The first message of the lowest message type that is
+less than or equal to the absolute value of
+.Fa msgtyp
+will be received.
+.El
+.Pp
+.Fa msgsz
+specifies the maximum length of the requested message. If the received
+message has a length greater than
+.Fa msgsz
+it will be silently truncated if the
+.Dv MSG_NOERROR
+flag is set in
+.Fa msgflg ,
+otherwise an error will be returned.
+.Pp
+If no matching message is present on the message queue specified by
+.Fa msqid ,
+the behavior of
+.Fn msgrcv
+depends on whether the
+.Dv IPC_NOWAIT
+flag is set in
+.Fa msgflg
+or not. If
+.Dv IPC_NOWAIT
+is set,
+.Fn msgrcv
+will immediately return a value of -1, and set
+.Va errno
+to
+.Er EAGAIN .
+If
+.Dv IPC_NOWAIT
+is not set, the calling process will be blocked
+until:
+.Bl -bullet
+.It
+A message of the requested type becomes available on the message queue.
+.It
+The message queue is removed, in which case -1 will be returned, and
+.Va errno
+set to
+.Er EINVAL .
+.It
+A signal is received and caught. -1 is returned, and
+.Va errno
+set to
+.Er EINTR .
+.El
+.Pp
+If a message is successfully received, the data structure associated with
+.Fa msqid
+is updated as follows:
+.Bl -bullet
+.It
+.Va msg_cbytes
+is decremented by the size of the message.
+.It
+.Va msg_lrpid
+is set to the pid of the caller.
+.It
+.Va msg_lrtime
+is set to the current time.
+.It
+.Va msg_qnum
+is decremented by 1.
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn msgrcv
+returns the number of bytes received into the
+.Va mtext
+field of the structure pointed to by
+.Fa msgp .
+Otherwise, -1 is returned, and
+.Va errno
+set to indicate the error.
+.Sh ERRORS
+.Fn msgrcv
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+.Fa msqid
+is not a valid message queue identifier.
+.Pp
+The message queue was removed while
+.Fn msgrcv
+was waiting for a message of the requested type to become available on it.
+.Pp
+.Fa msgsz
+is less than 0.
+.It Bq Er E2BIG
+A matching message was received, but its size was greater than
+.Fa msgsz
+and the
+.Dv MSG_NOERROR
+flag was not set in
+.Fa msgflg .
+.It Bq Er EACCESS
+The calling process does not have read access to the message queue.
+.It Bq Er EFAULT
+.Fa msgp
+points to an invalid address.
+.It Bq Er EINTR
+The system call was interrupted by the delivery of a signal.
+.It Bq Er EAGAIN
+There is no message of the requested type available on the message queue,
+and
+.Dv IPC_NOWAIT
+is set in
+.Fa msgflg .
+.Sh SEE ALSO
+.Xr msgctl 3 ,
+.Xr msgget 3 ,
+.Xr msgsnd 3
+.Sh BUGS
+.Tn NetBSD
+and
+.Tn FreeBSD
+do not define the
+.Er EIDRM
+error value, which should be used in
+the case of a removed message queue, nor the
+.Er ENOMSG
+value, which
+should be used when no suitable message is available and
+.Dv IPC_NOWAIT
+is set.
+.Sh HISTORY
+Message queues appeared in the first release of
+AT&T Unix System V.
diff --git a/lib/libc/gen/msgrcv.c b/lib/libc/gen/msgrcv.c
new file mode 100644
index 0000000..5c1e387
--- /dev/null
+++ b/lib/libc/gen/msgrcv.c
@@ -0,0 +1,17 @@
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+#if __STDC__
+int msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
+#else
+int msgrcv(msqid, msgp, msgsz, msgtyp, msgflg)
+ int msqid;
+ void *msgp;
+ size_t msgsz;
+ long msgtyp;
+ int msgflg;
+#endif
+{
+ return (msgsys(3, msqid, msgp, msgsz, msgtyp, msgflg));
+}
diff --git a/lib/libc/gen/msgsnd.3 b/lib/libc/gen/msgsnd.3
new file mode 100644
index 0000000..5a3c80c
--- /dev/null
+++ b/lib/libc/gen/msgsnd.3
@@ -0,0 +1,159 @@
+.\" $NetBSD: msgsnd.2,v 1.1 1995/10/16 23:49:24 jtc Exp $
+.\"
+.\" Copyright (c) 1995 Frank van der Linden
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed for the NetBSD Project
+.\" by Frank van der Linden
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"/
+.Dd August 17, 1995
+.Dt MSGSND 3
+.Os FreeBSD
+.Sh NAME
+.Nm msgsnd
+.Nd send a message to a message queue
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Fd #include <sys/msg.h>
+.Ft int
+.Fn msgsnd "int msqid" "void *msgp" "size_t msgsz" "int msgflg"
+.Sh DESCRIPTION
+The
+.Fn msgsnd
+function sends a message from the message queue specified in
+.Fa msqid .
+.Fa msgp
+points to a structure containing the message. This structure should
+consist of the following members:
+.Bd -literal
+ long mtype; /* message type */
+ char mtext[1]; /* body of message */
+.Ed
+.Pp
+.Va mtype
+is an integer greater than 0 that can be used for selecting messages (see
+.Xr msgrcv 3 ) ,
+.Va mtext
+is an array of bytes, with a size up to that of the system limit
+.Pf ( Dv MSGMAX ) .
+.Pp
+If the number of bytes already on the message queue plus
+.Fa msgsz
+is bigger than the maximum number of bytes on the message queue
+.Pf ( Va msg_qbytes ,
+see
+.Xr msgctl 3 ) ,
+or the number of messages on all queues system-wide is already equal to
+the system limit,
+.Fa msgflg
+determines the action of
+.Fn msgsnd .
+If
+.Fa msgflg
+has
+.Dv IPC_NOWAIT
+mask set in it, the call will return immediately. If
+.Fa msgflg
+does not have
+.Dv IPC_NOWAIT
+set in it, the call will block until:
+.Bl -bullet
+.It
+The condition which caused the call to block does no longer exist.
+The message will be sent.
+.It
+The message queue is removed, in which case -1 will be returned, and
+.Va errno
+is set to
+.Er EINVAL .
+.It
+The caller catches a signal. The call returns with
+.Va errno
+set to
+.Er EINTR .
+.El
+.Pp
+After a successful call, the data structure associated with the message
+queue is updated in the following way:
+.Bl -bullet
+.It
+.Va msg_cbytes
+is incremented by the size of the message.
+.It
+.Va msg_qnum
+is incremented by 1.
+.It
+.Va msg_lspid
+is set to the pid of the calling process.
+.It
+.Va msg_stime
+is set to the current time.
+.El
+.Sh RETURN VALUES
+Upon successful completion, 0 is returned. Otherwise, -1 is returned and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn msgsnd
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+.Fa msqid
+is not a valid message queue identifier
+.Pp
+The message queue was removed while
+.Fn msgsnd
+was waiting for a resource to become available in order to deliver the
+message.
+.Pp
+.Fa msgsz
+is less than 0, or greater than
+.Va msg_qbytes .
+.It Bq Er EACCESS
+The calling process does not have write access to the message queue.
+.It Bq Er EAGAIN
+There was no space for this message either on the queue, or in the whole
+system, and
+.Dv IPC_NOWAIT
+was set in
+.Fa msgflg .
+.It Bq Er EFAULT
+.Fa msgp
+points to an invalid address.
+.It Bq Er EINTR
+The system call was interrupted by the delivery of a signal.
+.El
+.Sh BUGS
+.Tn NetBSD
+and
+.Tn FreeBSD
+do not define the
+.Er EIDRM
+error value, which should be used
+in the case of a removed message queue.
+.Sh HISTORY
+Message queues appeared in the first release of AT&T Unix System V.
diff --git a/lib/libc/gen/msgsnd.c b/lib/libc/gen/msgsnd.c
new file mode 100644
index 0000000..a620915
--- /dev/null
+++ b/lib/libc/gen/msgsnd.c
@@ -0,0 +1,16 @@
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+#if __STDC__
+int msgsnd(int msqid, void *msgp, size_t msgsz, int msgflg)
+#else
+int msgsnd(msqid, msgp, msgsz, msgflg)
+ int msqid;
+ void *msgp;
+ size_t msgsz;
+ int msgflg;
+#endif
+{
+ return (msgsys(2, msqid, msgp, msgsz, msgflg));
+}
diff --git a/lib/libc/gen/nice.3 b/lib/libc/gen/nice.3
index 64a87c6..8179250 100644
--- a/lib/libc/gen/nice.3
+++ b/lib/libc/gen/nice.3
@@ -38,6 +38,7 @@
.Nm nice
.Nd set program scheduling priority
.Sh SYNOPSIS
+.Ft int
.Fn nice "int incr"
.Sh DESCRIPTION
.Bf -symbolic
@@ -57,8 +58,8 @@ Children inherit the priority of their parent processes via
.Xr fork 2 .
.Sh SEE ALSO
.Xr nice 1 ,
-.Xr setpriority 2 ,
.Xr fork 2 ,
+.Xr setpriority 2 ,
.Xr renice 8
.Sh HISTORY
A
diff --git a/lib/libc/gen/nlist.3 b/lib/libc/gen/nlist.3
index 11c9ee4..981a4c8 100644
--- a/lib/libc/gen/nlist.3
+++ b/lib/libc/gen/nlist.3
@@ -46,8 +46,8 @@ The
.Fn nlist
function
retrieves name list entries from the symbol table of an
-executable file. (See
-.Xr a.out 5 . )
+executable file (see
+.Xr a.out 5 ) .
The argument
.Fa \&nl
is set to reference the
diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c
index 874f26e..7415cbe 100644
--- a/lib/libc/gen/nlist.c
+++ b/lib/libc/gen/nlist.c
@@ -46,6 +46,8 @@ static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93";
#include <string.h>
#include <unistd.h>
+int __fdnlist __P(( int, struct nlist * ));
+
int
nlist(name, list)
const char *name;
@@ -68,40 +70,53 @@ __fdnlist(fd, list)
register int fd;
register struct nlist *list;
{
- register struct nlist *p, *s;
- register caddr_t strtab;
+ register struct nlist *p, *symtab;
+ register caddr_t strtab, a_out_mmap;
register off_t stroff, symoff;
register u_long symsize;
- register int nent, cc;
- size_t strsize;
- struct nlist nbuf[1024];
- struct exec exec;
+ register int nent;
+ struct exec * exec;
struct stat st;
- if (lseek(fd, (off_t)0, SEEK_SET) == -1 ||
- read(fd, &exec, sizeof(exec)) != sizeof(exec) ||
- N_BADMAG(exec) || fstat(fd, &st) < 0)
+ /* check that file is at least as large as struct exec! */
+ if ((fstat(fd, &st) < 0) || (st.st_size < sizeof(struct exec)))
return (-1);
- symoff = N_SYMOFF(exec);
- symsize = exec.a_syms;
- stroff = symoff + symsize;
-
/* Check for files too large to mmap. */
- if (st.st_size - stroff > SIZE_T_MAX) {
+ if (st.st_size > SIZE_T_MAX) {
errno = EFBIG;
return (-1);
}
+
/*
- * Map string table into our address space. This gives us
- * an easy way to randomly access all the strings, without
- * making the memory allocation permanent as with malloc/free
- * (i.e., munmap will return it to the system).
+ * Map the whole a.out file into our address space.
+ * We then find the string table withing this area.
+ * We do not just mmap the string table, as it probably
+ * does not start at a page boundary - we save ourselves a
+ * lot of nastiness by mmapping the whole file.
+ *
+ * This gives us an easy way to randomly access all the strings,
+ * without making the memory allocation permanent as with
+ * malloc/free (i.e., munmap will return it to the system).
*/
- strsize = st.st_size - stroff;
- strtab = mmap(NULL, (size_t)strsize, PROT_READ, 0, fd, stroff);
- if (strtab == (char *)-1)
+ a_out_mmap = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0);
+ if (a_out_mmap == MAP_FAILED)
+ return (-1);
+
+ exec = (struct exec *)a_out_mmap;
+ if (N_BADMAG(*exec)) {
+ munmap(a_out_mmap, (size_t)st.st_size);
return (-1);
+ }
+
+ symoff = N_SYMOFF(*exec);
+ symsize = exec->a_syms;
+ stroff = symoff + symsize;
+
+ /* find the string table in our mmapped area */
+ strtab = a_out_mmap + stroff;
+ symtab = (struct nlist *)(a_out_mmap + symoff);
+
/*
* clean out any left-over information for all valid entries.
* Type and value defined to be 0 if not found; historical
@@ -120,30 +135,26 @@ __fdnlist(fd, list)
p->n_value = 0;
++nent;
}
- if (lseek(fd, symoff, SEEK_SET) == -1)
- return (-1);
while (symsize > 0) {
- cc = MIN(symsize, sizeof(nbuf));
- if (read(fd, nbuf, cc) != cc)
- break;
- symsize -= cc;
- for (s = nbuf; cc > 0; ++s, cc -= sizeof(*s)) {
- register int soff = s->n_un.n_strx;
-
- if (soff == 0 || (s->n_type & N_STAB) != 0)
- continue;
+ register int soff;
+
+ symsize-= sizeof(struct nlist);
+ soff = symtab->n_un.n_strx;
+
+
+ if (soff != 0 && (symtab->n_type & N_STAB) == 0)
for (p = list; !ISLAST(p); p++)
if (!strcmp(&strtab[soff], p->n_un.n_name)) {
- p->n_value = s->n_value;
- p->n_type = s->n_type;
- p->n_desc = s->n_desc;
- p->n_other = s->n_other;
+ p->n_value = symtab->n_value;
+ p->n_type = symtab->n_type;
+ p->n_desc = symtab->n_desc;
+ p->n_other = symtab->n_other;
if (--nent <= 0)
break;
}
- }
+ symtab++;
}
- munmap(strtab, strsize);
+ munmap(a_out_mmap, (size_t)st.st_size);
return (nent);
}
diff --git a/lib/libc/gen/nrand48.c b/lib/libc/gen/nrand48.c
new file mode 100644
index 0000000..6c54065
--- /dev/null
+++ b/lib/libc/gen/nrand48.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#include "rand48.h"
+
+long
+nrand48(unsigned short xseed[3])
+{
+ _dorand48(xseed);
+ return ((long) xseed[2] << 15) + ((long) xseed[1] >> 1);
+}
diff --git a/lib/libc/gen/ntp_gettime.c b/lib/libc/gen/ntp_gettime.c
new file mode 100644
index 0000000..1f18337
--- /dev/null
+++ b/lib/libc/gen/ntp_gettime.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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 const char rcsid[] =
+ "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+
+int
+ntp_gettime(struct ntptimeval *ntv)
+{
+ int mib[3];
+ struct ntptimeval tv;
+ size_t size = sizeof tv;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_NTP_PLL;
+ mib[2] = NTP_PLL_GETTIME;
+ if (sysctl(mib, 3, &tv, &size, NULL, 0) == -1)
+ return TIME_ERROR;
+ if(ntv) *ntv = tv;
+ return tv.time_state;
+}
+
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index 9c2b0ad..119791f 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -64,31 +64,40 @@ __opendir2(name, flags)
DIR *dirp;
int fd;
int incr;
+ int saved_errno;
int unionstack;
struct stat statb;
- if ((fd = open(name, O_RDONLY)) == -1)
+ /*
+ * stat() before open() because opening of special files may be
+ * harmful. fstat() after open because the file may have changed.
+ */
+ if (stat(name, &statb) != 0)
return (NULL);
- if (fstat(fd, &statb) || !S_ISDIR(statb.st_mode)) {
+ if (!S_ISDIR(statb.st_mode)) {
errno = ENOTDIR;
- close(fd);
return (NULL);
}
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 ||
- (dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
- close(fd);
+ if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1)
return (NULL);
+ dirp = NULL;
+ if (fstat(fd, &statb) != 0)
+ goto fail;
+ if (!S_ISDIR(statb.st_mode)) {
+ errno = ENOTDIR;
+ goto fail;
}
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 ||
+ (dirp = malloc(sizeof(DIR))) == NULL)
+ goto fail;
/*
- * If CLBYTES is an exact multiple of DIRBLKSIZ, use a CLBYTES
- * buffer that it cluster boundary aligned.
+ * Use the system page size if that is a multiple of DIRBLKSIZ.
* Hopefully this can be a big win someday by allowing page
- * trades to user space to be done by getdirentries()
+ * trades to user space to be done by getdirentries().
*/
- if ((CLBYTES % DIRBLKSIZ) == 0)
- incr = CLBYTES;
- else
+ incr = getpagesize();
+ if ((incr % DIRBLKSIZ) != 0)
incr = DIRBLKSIZ;
/*
@@ -97,11 +106,8 @@ __opendir2(name, flags)
if (flags & DTF_NODUP) {
struct statfs sfb;
- if (fstatfs(fd, &sfb) < 0) {
- free(dirp);
- close(fd);
- return (NULL);
- }
+ if (fstatfs(fd, &sfb) < 0)
+ goto fail;
unionstack = !strcmp(sfb.f_fstypename, "union");
} else {
unionstack = 0;
@@ -132,11 +138,8 @@ __opendir2(name, flags)
space += incr;
len += incr;
buf = realloc(buf, len);
- if (buf == NULL) {
- free(dirp);
- close(fd);
- return (NULL);
- }
+ if (buf == NULL)
+ goto fail;
ddptr = buf + (len - space);
}
@@ -160,8 +163,10 @@ __opendir2(name, flags)
if (flags & DTF_REWIND) {
(void) close(fd);
if ((fd = open(name, O_RDONLY)) == -1) {
+ saved_errno = errno;
free(buf);
free(dirp);
+ errno = saved_errno;
return (NULL);
}
}
@@ -243,11 +248,8 @@ __opendir2(name, flags)
} else {
dirp->dd_len = incr;
dirp->dd_buf = malloc(dirp->dd_len);
- if (dirp->dd_buf == NULL) {
- free(dirp);
- close (fd);
- return (NULL);
- }
+ if (dirp->dd_buf == NULL)
+ goto fail;
dirp->dd_seek = 0;
flags &= ~DTF_REWIND;
}
@@ -262,4 +264,11 @@ __opendir2(name, flags)
dirp->dd_rewind = telldir(dirp);
return (dirp);
+
+fail:
+ saved_errno = errno;
+ free(dirp);
+ (void) close(fd);
+ errno = saved_errno;
+ return (NULL);
}
diff --git a/lib/libc/gen/pause.3 b/lib/libc/gen/pause.3
index b5fd207..962c6cb 100644
--- a/lib/libc/gen/pause.3
+++ b/lib/libc/gen/pause.3
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)pause.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt PAUSE 3
@@ -42,9 +43,8 @@
.Ft int
.Fn pause void
.Sh DESCRIPTION
-.Bf -symbolic
-Pause is made obsolete by sigpause(3).
-.Ef
+.Sy Pause is made obsolete by
+.Xr sigsuspend 2 .
.Pp
The
.Fn pause
@@ -75,7 +75,7 @@ The call was interrupted.
.Sh SEE ALSO
.Xr kill 2 ,
.Xr select 2 ,
-.Xr sigpause 2
+.Xr sigsuspend 2
.Sh HISTORY
A
.Fn pause
diff --git a/lib/libc/gen/popen.3 b/lib/libc/gen/popen.3
index 9ca1bb3..2d2856b 100644
--- a/lib/libc/gen/popen.3
+++ b/lib/libc/gen/popen.3
@@ -50,7 +50,7 @@ The
.Fn popen
function
.Dq opens
-a process by creating an IPC connection,
+a process by creating a bidirectional pipe
forking,
and invoking the shell.
Historically,
@@ -63,9 +63,9 @@ only allow the
argument to specify reading or writing, not both.
Since
.Nm popen
-is now implemented using sockets, the
+is now implemented using a bidirectional pipe, the
.Fa type
-may request a bidirectional data flow.
+argument may request a bidirectional data flow.
The
.Fa type
argument is a pointer to a null-terminated string
@@ -123,10 +123,9 @@ The
function returns
.Dv NULL
if the
-.Xr fork 2 ,
-.Xr pipe 2 ,
+.Xr fork 2
or
-.Xr socketpair 2
+.Xr pipe 2
calls fail,
or if it cannot allocate memory.
.Pp
@@ -150,13 +149,12 @@ The
function does not reliably set
.Va errno .
.Sh SEE ALSO
-.Xr fork 2 ,
.Xr sh 1 ,
+.Xr fork 2 ,
.Xr pipe 2 ,
-.Xr socketpair 2 ,
.Xr wait4 2 ,
-.Xr fflush 3 ,
.Xr fclose 3 ,
+.Xr fflush 3 ,
.Xr fopen 3 ,
.Xr stdio 3 ,
.Xr system 3
@@ -182,9 +180,9 @@ The
.Fn popen
argument
always calls
-.Xr sh ,
+.Xr sh 1 ,
never calls
-.Xr csh .
+.Xr csh 1 .
.Sh HISTORY
A
.Fn popen
diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c
index 3c3bd6f..8cb7950 100644
--- a/lib/libc/gen/popen.c
+++ b/lib/libc/gen/popen.c
@@ -40,7 +40,6 @@ static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95";
#include <sys/param.h>
#include <sys/wait.h>
-#include <sys/socket.h>
#include <signal.h>
#include <errno.h>
@@ -54,8 +53,8 @@ static struct pid {
struct pid *next;
FILE *fp;
pid_t pid;
-} *pidlist;
-
+} *pidlist;
+
FILE *
popen(command, type)
const char *command, *type;
@@ -64,37 +63,51 @@ popen(command, type)
FILE *iop;
int pdes[2], pid, twoway;
+ /*
+ * Lite2 introduced two-way popen() pipes using socketpair().
+ * FreeBSD's pipe() is bidirectional, so we use that.
+ */
if (strchr(type, '+')) {
twoway = 1;
type = "r+";
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, pdes) < 0)
- return (NULL);
} else {
twoway = 0;
- if (*type != 'r' && *type != 'w' || type[1] ||
- (pipe(pdes) < 0))
+ if ((*type != 'r' && *type != 'w') || type[1])
return (NULL);
}
+ if (pipe(pdes) < 0)
+ return (NULL);
- if ((cur = malloc(sizeof(struct pid))) == NULL)
+ if ((cur = malloc(sizeof(struct pid))) == NULL) {
+ (void)close(pdes[0]);
+ (void)close(pdes[1]);
return (NULL);
+ }
switch (pid = vfork()) {
case -1: /* Error. */
(void)close(pdes[0]);
(void)close(pdes[1]);
- (void)free(cur);
+ free(cur);
return (NULL);
/* NOTREACHED */
case 0: /* Child. */
if (*type == 'r') {
+ /*
+ * The dup2() to STDIN_FILENO is repeated to avoid
+ * writing to pdes[1], which might corrupt the
+ * parent's copy. This isn't good enough in
+ * general, since the _exit() is no return, so
+ * the compiler is free to corrupt all the local
+ * variables.
+ */
+ (void) close(pdes[0]);
if (pdes[1] != STDOUT_FILENO) {
(void)dup2(pdes[1], STDOUT_FILENO);
(void)close(pdes[1]);
- pdes[1] = STDOUT_FILENO;
- }
- (void) close(pdes[0]);
- if (twoway && (pdes[1] != STDIN_FILENO))
+ if (twoway)
+ (void)dup2(STDOUT_FILENO, STDIN_FILENO);
+ } else if (twoway && (pdes[1] != STDIN_FILENO))
(void)dup2(pdes[1], STDIN_FILENO);
} else {
if (pdes[0] != STDIN_FILENO) {
@@ -159,6 +172,6 @@ pclose(iop)
else
last->next = cur->next;
free(cur);
-
+
return (pid == -1 ? -1 : pstat);
}
diff --git a/lib/libc/gen/psignal.3 b/lib/libc/gen/psignal.3
index 1fdcbad..773759c 100644
--- a/lib/libc/gen/psignal.3
+++ b/lib/libc/gen/psignal.3
@@ -40,11 +40,11 @@
.Nm sys_signame
.Nd system signal messages
.Sh SYNOPSIS
-.Fd #include <sys/signal.h>
+.Fd #include <signal.h>
.Ft void
.Fn psignal "unsigned sig" "const char *s"
-.Vt extern char *sys_siglist[];
-.Vt extern char *sys_signame[];
+.Vt extern const char * const sys_siglist[];
+.Vt extern const char * const sys_signame[];
.Sh DESCRIPTION
The
.Fn psignal
diff --git a/lib/libc/gen/psignal.c b/lib/libc/gen/psignal.c
index 51491b4..b7e7ab6 100644
--- a/lib/libc/gen/psignal.c
+++ b/lib/libc/gen/psignal.c
@@ -39,7 +39,7 @@ static char sccsid[] = "@(#)psignal.c 8.1 (Berkeley) 6/4/93";
* Print the name of the signal indicated
* along with the supplied message.
*/
-#include <sys/signal.h>
+#include <signal.h>
#include <string.h>
#include <unistd.h>
diff --git a/lib/libc/gen/pw_scan.c b/lib/libc/gen/pw_scan.c
new file mode 100644
index 0000000..00f640b
--- /dev/null
+++ b/lib/libc/gen/pw_scan.c
@@ -0,0 +1,141 @@
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)pw_scan.c 8.3 (Berkeley) 4/2/94";
+#endif /* not lint */
+
+/*
+ * This module is used to "verify" password entries by chpass(1) and
+ * pwd_mkdb(8).
+ */
+
+#include <sys/param.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <pwd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "pw_scan.h"
+
+int
+pw_scan(bp, pw)
+ char *bp;
+ struct passwd *pw;
+{
+ long id;
+ int root;
+ char *p, *sh;
+
+ pw->pw_fields = 0;
+ if (!(pw->pw_name = strsep(&bp, ":"))) /* login */
+ goto fmt;
+ root = !strcmp(pw->pw_name, "root");
+ if(pw->pw_name[0] && (pw->pw_name[0] != '+' || pw->pw_name[1] == '\0'))
+ pw->pw_fields |= _PWF_NAME;
+
+ if (!(pw->pw_passwd = strsep(&bp, ":"))) /* passwd */
+ goto fmt;
+ if(pw->pw_passwd[0]) pw->pw_fields |= _PWF_PASSWD;
+
+ if (!(p = strsep(&bp, ":"))) /* uid */
+ goto fmt;
+ if(p[0]) pw->pw_fields |= _PWF_UID;
+ id = atol(p);
+ if (root && id) {
+ warnx("root uid should be 0");
+ return (0);
+ }
+ if (id > USHRT_MAX) {
+ warnx("%s > max uid value (%d)", p, USHRT_MAX);
+ /*return (0);*/ /* THIS SHOULD NOT BE FATAL! */
+ }
+ pw->pw_uid = id;
+
+ if (!(p = strsep(&bp, ":"))) /* gid */
+ goto fmt;
+ if(p[0]) pw->pw_fields |= _PWF_GID;
+ id = atol(p);
+ if (id > USHRT_MAX) {
+ warnx("%s > max gid value (%d)", p, USHRT_MAX);
+ /* return (0); This should not be fatal! */
+ }
+ pw->pw_gid = id;
+
+ pw->pw_class = strsep(&bp, ":"); /* class */
+ if(pw->pw_class[0]) pw->pw_fields |= _PWF_CLASS;
+
+ if (!(p = strsep(&bp, ":"))) /* change */
+ goto fmt;
+ if(p[0]) pw->pw_fields |= _PWF_CHANGE;
+ pw->pw_change = atol(p);
+
+ if (!(p = strsep(&bp, ":"))) /* expire */
+ goto fmt;
+ if(p[0]) pw->pw_fields |= _PWF_EXPIRE;
+ pw->pw_expire = atol(p);
+
+ if (!(pw->pw_gecos = strsep(&bp, ":"))) /* gecos */
+ goto fmt;
+ if(pw->pw_gecos[0]) pw->pw_fields |= _PWF_GECOS;
+
+ if (!(pw->pw_dir = strsep(&bp, ":"))) /* directory */
+ goto fmt;
+ if(pw->pw_dir[0]) pw->pw_fields |= _PWF_DIR;
+
+ if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */
+ goto fmt;
+
+ p = pw->pw_shell;
+ if (root && *p) /* empty == /bin/sh */
+ for (setusershell();;) {
+ if (!(sh = getusershell())) {
+ warnx("warning, unknown root shell");
+ break;
+ }
+ if (!strcmp(p, sh))
+ break;
+ }
+ if(p[0]) pw->pw_fields |= _PWF_SHELL;
+
+ if (p = strsep(&bp, ":")) { /* too many */
+fmt: warnx("corrupted entry");
+ return (0);
+ }
+ return (1);
+}
diff --git a/lib/libc/gen/pw_scan.h b/lib/libc/gen/pw_scan.h
new file mode 100644
index 0000000..d1d4bc1
--- /dev/null
+++ b/lib/libc/gen/pw_scan.h
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * @(#)pw_scan.h 8.1 (Berkeley) 4/1/94
+ */
+
+extern int pw_scan __P((char *, struct passwd *));
diff --git a/lib/libc/gen/pwcache.3 b/lib/libc/gen/pwcache.3
index 74afa74..e44b5ef 100644
--- a/lib/libc/gen/pwcache.3
+++ b/lib/libc/gen/pwcache.3
@@ -38,8 +38,11 @@
.Nm pwcache
.Nd cache password and group entries
.Sh SYNOPSIS
-.Fn user_from_uid "uid_t uid" "int nouser"
-.Fn group_from_gid "gid_t gid" "int nogroup"
+.Fd #include <stdlib.h>
+.Ft char *
+.Fn user_from_uid "unsigned long uid" "int nouser"
+.Ft char *
+.Fn group_from_gid "unsigned long gid" "int nogroup"
.Sh DESCRIPTION
.Pp
The
@@ -84,7 +87,8 @@ pointer is returned.
.Xr getpwuid 3
.Sh HISTORY
The
-.Fn user_from_id
+.Fn user_from_uid
and
-.Fn group_from_id
-functions first appeared in 4.4BSD.
+.Fn group_from_gid
+functions first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/pwcache.c b/lib/libc/gen/pwcache.c
index 1dcbf5d..aea7f55 100644
--- a/lib/libc/gen/pwcache.c
+++ b/lib/libc/gen/pwcache.c
@@ -38,12 +38,13 @@ static char sccsid[] = "@(#)pwcache.c 8.1 (Berkeley) 6/4/93";
#include <sys/types.h>
#include <grp.h>
+#include <string.h>
#include <pwd.h>
#include <stdio.h>
#include <utmp.h>
#define NCACHE 64 /* power of 2 */
-#define MASK NCACHE - 1 /* bits to store with */
+#define MASK (NCACHE - 1) /* bits to store with */
char *
user_from_uid(uid, nouser)
@@ -52,10 +53,10 @@ user_from_uid(uid, nouser)
{
static struct ncache {
uid_t uid;
+ int found;
char name[UT_NAMESIZE + 1];
} c_uid[NCACHE];
static int pwopen;
- static char nbuf[15]; /* 32 bits == 10 digits */
register struct passwd *pw;
register struct ncache *cp;
@@ -65,17 +66,20 @@ user_from_uid(uid, nouser)
setpassent(1);
pwopen = 1;
}
- if ((pw = getpwuid(uid)) == NULL) {
+ pw = getpwuid(uid);
+ cp->uid = uid;
+ if (pw != NULL) {
+ cp->found = 1;
+ (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE);
+ cp->name[UT_NAMESIZE] = '\0';
+ } else {
+ cp->found = 0;
+ (void)snprintf(cp->name, UT_NAMESIZE, "%u", uid);
if (nouser)
return (NULL);
- (void)snprintf(nbuf, sizeof(nbuf), "%u", uid);
- return (nbuf);
}
- cp->uid = uid;
- (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE);
- cp->name[UT_NAMESIZE] = '\0';
}
- return (cp->name);
+ return ((nouser && !cp->found) ? NULL : cp->name);
}
char *
@@ -85,10 +89,10 @@ group_from_gid(gid, nogroup)
{
static struct ncache {
gid_t gid;
+ int found;
char name[UT_NAMESIZE + 1];
} c_gid[NCACHE];
static int gropen;
- static char nbuf[15]; /* 32 bits == 10 digits */
struct group *gr;
struct ncache *cp;
@@ -98,15 +102,18 @@ group_from_gid(gid, nogroup)
setgroupent(1);
gropen = 1;
}
- if ((gr = getgrgid(gid)) == NULL) {
+ gr = getgrgid(gid);
+ cp->gid = gid;
+ if (gr != NULL) {
+ cp->found = 1;
+ (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE);
+ cp->name[UT_NAMESIZE] = '\0';
+ } else {
+ cp->found = 0;
+ (void)snprintf(cp->name, UT_NAMESIZE, "%u", gid);
if (nogroup)
return (NULL);
- (void)snprintf(nbuf, sizeof(nbuf), "%u", gid);
- return (nbuf);
}
- cp->gid = gid;
- (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE);
- cp->name[UT_NAMESIZE] = '\0';
}
- return (cp->name);
+ return ((nogroup && !cp->found) ? NULL : cp->name);
}
diff --git a/lib/libc/gen/raise.c b/lib/libc/gen/raise.c
index 75ecaa1..2562c81 100644
--- a/lib/libc/gen/raise.c
+++ b/lib/libc/gen/raise.c
@@ -38,6 +38,7 @@ static char sccsid[] = "@(#)raise.c 8.1 (Berkeley) 6/4/93";
#include <signal.h>
#include <unistd.h>
+int
raise(s)
int s;
{
diff --git a/lib/libc/gen/rand48.3 b/lib/libc/gen/rand48.3
new file mode 100644
index 0000000..356f2f3
--- /dev/null
+++ b/lib/libc/gen/rand48.3
@@ -0,0 +1,160 @@
+\" Copyright (c) 1993 Martin Birgmeier
+.\" All rights reserved.
+.\"
+.\" You may redistribute unmodified or modified versions of this source
+.\" code provided that the above copyright notice and this and the
+.\" following conditions are retained.
+.\"
+.\" This software is provided ``as is'', and comes with no warranties
+.\" of any kind. I shall in no event be liable for anything that happens
+.\" to anyone/anything when using this software.
+.\"
+.\" @(#)rand48.3 V1.0 MB 8 Oct 1993
+.\"
+.Dd October 8, 1993
+.Dt RAND48 3
+.Os FreeBSD
+.Sh NAME
+.Nm drand48 ,
+.Nm erand48 ,
+.Nm lrand48 ,
+.Nm nrand48 ,
+.Nm mrand48 ,
+.Nm jrand48 ,
+.Nm srand48 ,
+.Nm seed48 ,
+.Nm lcong48
+.Nd pseudo random number generators and initialization routines
+.Sh SYNOPSIS
+.Fd #include <stdlib.h>
+.Ft double
+.Fn drand48 void
+.Ft double
+.Fn erand48 "unsigned short xseed[3]"
+.Ft long
+.Fn lrand48 void
+.Ft long
+.Fn nrand48 "unsigned short xseed[3]"
+.Ft long
+.Fn mrand48 void
+.Ft long
+.Fn jrand48 "unsigned short xseed[3]"
+.Ft void
+.Fn srand48 "long seed"
+.Ft "unsigned short *"
+.Fn seed48 "unsigned short xseed[3]"
+.Ft void
+.Fn lcong48 "unsigned short p[7]"
+.Sh DESCRIPTION
+The
+.Fn rand48
+family of functions generates pseudo-random numbers using a linear
+congruential algorithm working on integers 48 bits in size. The
+particular formula employed is
+r(n+1) = (a * r(n) + c) mod m
+where the default values are
+for the multiplicand a = 0xfdeece66d = 25214903917 and
+the addend c = 0xb = 11. The modulo is always fixed at m = 2 ** 48.
+r(n) is called the seed of the random number generator.
+.Pp
+For all the six generator routines described next, the first
+computational step is to perform a single iteration of the algorithm.
+.Pp
+.Fn drand48
+and
+.Fn erand48
+return values of type double. The full 48 bits of r(n+1) are
+loaded into the mantissa of the returned value, with the exponent set
+such that the values produced lie in the interval [0.0, 1.0).
+.Pp
+.Fn lrand48
+and
+.Fn nrand48
+return values of type long in the range
+[0, 2**31-1]. The high-order (31) bits of
+r(n+1) are loaded into the lower bits of the returned value, with
+the topmost (sign) bit set to zero.
+.Pp
+.Fn mrand48
+and
+.Fn jrand48
+return values of type long in the range
+[-2**31, 2**31-1]. The high-order (32) bits of
+r(n+1) are loaded into the returned value.
+.Pp
+.Fn drand48 ,
+.Fn lrand48 ,
+and
+.Fn mrand48
+use an internal buffer to store r(n). For these functions
+the initial value of r(0) = 0x1234abcd330e = 20017429951246.
+.Pp
+On the other hand,
+.Fn erand48 ,
+.Fn nrand48 ,
+and
+.Fn jrand48
+use a user-supplied buffer to store the seed r(n),
+which consists of an array of 3 shorts, where the zeroth member
+holds the least significant bits.
+.Pp
+All functions share the same multiplicand and addend.
+.Pp
+.Fn srand48
+is used to initialize the internal buffer r(n) of
+.Fn drand48 ,
+.Fn lrand48 ,
+and
+.Fn mrand48
+such that the 32 bits of the seed value are copied into the upper 32 bits
+of r(n), with the lower 16 bits of r(n) arbitrarily being set to 0x330e.
+Additionally, the constant multiplicand and addend of the algorithm are
+reset to the default values given above.
+.Pp
+.Fn seed48
+also initializes the internal buffer r(n) of
+.Fn drand48 ,
+.Fn lrand48 ,
+and
+.Fn mrand48 ,
+but here all 48 bits of the seed can be specified in an array of 3 shorts,
+where the zeroth member specifies the lowest bits. Again,
+the constant multiplicand and addend of the algorithm are
+reset to the default values given above.
+.Fn seed48
+returns a pointer to an array of 3 shorts which contains the old seed.
+This array is statically allocated, thus its contents are lost after
+each new call to
+.Fn seed48 .
+.Pp
+Finally,
+.Fn lcong48
+allows full control over the multiplicand and addend used in
+.Fn drand48 ,
+.Fn erand48 ,
+.Fn lrand48 ,
+.Fn nrand48 ,
+.Fn mrand48 ,
+and
+.Fn jrand48 ,
+and the seed used in
+.Fn drand48 ,
+.Fn lrand48 ,
+and
+.Fn mrand48 .
+An array of 7 shorts is passed as parameter; the first three shorts are
+used to initialize the seed; the second three are used to initialize the
+multiplicand; and the last short is used to initialize the addend.
+It is thus not possible to use values greater than 0xffff as the addend.
+.Pp
+Note that all three methods of seeding the random number generator
+always also set the multiplicand and addend for any of the six
+generator calls.
+.Pp
+For a more powerful random number generator, see
+.Xr random 3
+.Sh AUTHOR
+Martin Birgmeier
+.Sh SEE ALSO
+.Xr rand 3 ,
+.Xr random 3 .
diff --git a/lib/libc/gen/rand48.h b/lib/libc/gen/rand48.h
new file mode 100644
index 0000000..5b9f87d
--- /dev/null
+++ b/lib/libc/gen/rand48.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#ifndef _RAND48_H_
+#define _RAND48_H_
+
+#include <math.h>
+#include <stdlib.h>
+
+void _dorand48 __P((unsigned short[3]));
+
+#define RAND48_SEED_0 (0x330e)
+#define RAND48_SEED_1 (0xabcd)
+#define RAND48_SEED_2 (0x1234)
+#define RAND48_MULT_0 (0xe66d)
+#define RAND48_MULT_1 (0xdeec)
+#define RAND48_MULT_2 (0x0005)
+#define RAND48_ADD (0x000b)
+
+#endif /* _RAND48_H_ */
diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/rewinddir.c
index b46bcf3..2076ddd 100644
--- a/lib/libc/gen/rewinddir.c
+++ b/lib/libc/gen/rewinddir.c
@@ -38,6 +38,8 @@ static char sccsid[] = "@(#)rewinddir.c 8.1 (Berkeley) 6/8/93";
#include <sys/types.h>
#include <dirent.h>
+extern void _seekdir __P(( DIR *, long ));
+
void
rewinddir(dirp)
DIR *dirp;
diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c
index 1c1fee1..e6e8408 100644
--- a/lib/libc/gen/scandir.c
+++ b/lib/libc/gen/scandir.c
@@ -79,7 +79,7 @@ scandir(dirname, namelist, select, dcomp)
/*
* estimate the array size by taking the size of the directory file
- * and dividing it by a multiple of the minimum size entry.
+ * and dividing it by a multiple of the minimum size entry.
*/
arraysz = (stb.st_size / 24);
names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *));
@@ -96,7 +96,8 @@ scandir(dirname, namelist, select, dcomp)
p = (struct dirent *)malloc(DIRSIZ(d));
if (p == NULL)
return(-1);
- p->d_ino = d->d_ino;
+ p->d_fileno = d->d_fileno;
+ p->d_type = d->d_type;
p->d_reclen = d->d_reclen;
p->d_namlen = d->d_namlen;
bcopy(d->d_name, p->d_name, p->d_namlen + 1);
diff --git a/lib/libc/gen/seed48.c b/lib/libc/gen/seed48.c
new file mode 100644
index 0000000..258c4ba
--- /dev/null
+++ b/lib/libc/gen/seed48.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#include "rand48.h"
+
+extern unsigned short _rand48_seed[3];
+extern unsigned short _rand48_mult[3];
+extern unsigned short _rand48_add;
+
+unsigned short *
+seed48(unsigned short xseed[3])
+{
+ static unsigned short sseed[3];
+
+ sseed[0] = _rand48_seed[0];
+ sseed[1] = _rand48_seed[1];
+ sseed[2] = _rand48_seed[2];
+ _rand48_seed[0] = xseed[0];
+ _rand48_seed[1] = xseed[1];
+ _rand48_seed[2] = xseed[2];
+ _rand48_mult[0] = RAND48_MULT_0;
+ _rand48_mult[1] = RAND48_MULT_1;
+ _rand48_mult[2] = RAND48_MULT_2;
+ _rand48_add = RAND48_ADD;
+ return sseed;
+}
diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/seekdir.c
index 48b4646..1934bcc 100644
--- a/lib/libc/gen/seekdir.c
+++ b/lib/libc/gen/seekdir.c
@@ -38,6 +38,8 @@ static char sccsid[] = "@(#)seekdir.c 8.1 (Berkeley) 6/4/93";
#include <sys/param.h>
#include <dirent.h>
+extern void _seekdir __P(( DIR *, long ));
+
/*
* Seek to an entry in a directory.
* _seekdir is in telldir.c so that it can share opaque data structures.
diff --git a/lib/libc/gen/semconfig.c b/lib/libc/gen/semconfig.c
new file mode 100644
index 0000000..cf5399b
--- /dev/null
+++ b/lib/libc/gen/semconfig.c
@@ -0,0 +1,13 @@
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#if __STDC__
+int semconfig(int cmd, int p1, int p2, int p3)
+#else
+int semconfig(cmd, p1, p2, p3)
+ int cmd, p1, p2, p3;
+#endif
+{
+ return (semsys(3, cmd, p1, p2, p3));
+}
diff --git a/lib/libc/gen/semctl.c b/lib/libc/gen/semctl.c
new file mode 100644
index 0000000..313a1db
--- /dev/null
+++ b/lib/libc/gen/semctl.c
@@ -0,0 +1,15 @@
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#if __STDC__
+int semctl(int semid, int semnum, int cmd, union semun semun)
+#else
+int semctl(semid, int semnum, cmd, semun)
+ int semid, semnum;
+ int cmd;
+ union semun semun;
+#endif
+{
+ return (semsys(0, semid, semnum, cmd, &semun));
+}
diff --git a/lib/libc/gen/semget.c b/lib/libc/gen/semget.c
new file mode 100644
index 0000000..81c6a86
--- /dev/null
+++ b/lib/libc/gen/semget.c
@@ -0,0 +1,15 @@
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#if __STDC__
+int semget(key_t key, int nsems, int semflg)
+#else
+int semget(key, nsems, semflg)
+ key_t key;
+ int nsems;
+ int semflg;
+#endif
+{
+ return (semsys(1, key, nsems, semflg));
+}
diff --git a/lib/libc/gen/semop.c b/lib/libc/gen/semop.c
new file mode 100644
index 0000000..0b97c6a
--- /dev/null
+++ b/lib/libc/gen/semop.c
@@ -0,0 +1,15 @@
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#if __STDC__
+int semop(int semid, struct sembuf *sops, unsigned nsops)
+#else
+int semop(semid, sops, nsops)
+ int semid;
+ struct sembuf *sops;
+ unsigned nsops;
+#endif
+{
+ return (semsys(2, semid, sops, nsops, 0));
+}
diff --git a/lib/libc/net/getnetbyaddr.c b/lib/libc/gen/setdomainname.c
index fd3f260..b7021a5 100644
--- a/lib/libc/net/getnetbyaddr.c
+++ b/lib/libc/gen/setdomainname.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1983, 1993
+ * Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -32,25 +32,26 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93";
+/*
+static char sccsid[] = "From: @(#)sethostname.c 8.1 (Berkeley) 6/4/93";
+*/
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
-#include <netdb.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
-extern int _net_stayopen;
+#include <unistd.h>
-struct netent *
-getnetbyaddr(net, type)
- register long net;
- register int type;
+int
+setdomainname(const char *name, int namelen)
{
- register struct netent *p;
+ int mib[2];
- setnetent(_net_stayopen);
- while (p = getnetent())
- if (p->n_addrtype == type && p->n_net == net)
- break;
- if (!_net_stayopen)
- endnetent();
- return (p);
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_NISDOMAINNAME;
+ if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1)
+ return (-1);
+ return (0);
}
diff --git a/lib/libc/gen/setflags.c b/lib/libc/gen/setflags.c
new file mode 100644
index 0000000..b1e7062
--- /dev/null
+++ b/lib/libc/gen/setflags.c
@@ -0,0 +1,163 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id: stat_flags.c,v 1.5 1997/02/22 14:04:02 peter Exp $
+ */
+
+#ifndef lint
+static char const sccsid[] = "@(#)stat_flags.c 8.1 (Berkeley) 5/31/93";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stddef.h>
+#include <string.h>
+
+#define SAPPEND(s) { \
+ if (prefix != NULL) \
+ (void)strcat(string, prefix); \
+ (void)strcat(string, s); \
+ prefix = ","; \
+}
+
+/*
+ * flags_to_string --
+ * Convert stat flags to a comma-separated string. If no flags
+ * are set, return the default string.
+ */
+char *
+flags_to_string(flags, def)
+ u_long flags;
+ char *def;
+{
+ static char string[128];
+ char *prefix;
+
+ string[0] = '\0';
+ prefix = NULL;
+ if (flags & UF_APPEND)
+ SAPPEND("uappnd");
+ if (flags & UF_IMMUTABLE)
+ SAPPEND("uchg");
+ if (flags & UF_NOUNLINK)
+ SAPPEND("uunlnk");
+ if (flags & UF_NODUMP)
+ SAPPEND("nodump");
+ if (flags & UF_OPAQUE)
+ SAPPEND("opaque");
+ if (flags & SF_APPEND)
+ SAPPEND("sappnd");
+ if (flags & SF_ARCHIVED)
+ SAPPEND("arch");
+ if (flags & SF_IMMUTABLE)
+ SAPPEND("schg");
+ if (flags & SF_NOUNLINK)
+ SAPPEND("sunlnk");
+ return (prefix == NULL && def != NULL ? def : string);
+}
+
+#define TEST(a, b, f) { \
+ if (!memcmp(a, b, sizeof(b))) { \
+ if (clear) { \
+ if (clrp) \
+ *clrp |= (f); \
+ } else if (setp) \
+ *setp |= (f); \
+ break; \
+ } \
+}
+
+/*
+ * string_to_flags --
+ * Take string of arguments and return stat flags. Return 0 on
+ * success, 1 on failure. On failure, stringp is set to point
+ * to the offending token.
+ */
+int
+string_to_flags(stringp, setp, clrp)
+ char **stringp;
+ u_long *setp, *clrp;
+{
+ int clear;
+ char *string, *p;
+
+ clear = 0;
+ if (setp)
+ *setp = 0;
+ if (clrp)
+ *clrp = 0;
+ string = *stringp;
+ while ((p = strsep(&string, "\t ,")) != NULL) {
+ *stringp = p;
+ if (*p == '\0')
+ continue;
+ if (p[0] == 'n' && p[1] == 'o') {
+ clear = 1;
+ p += 2;
+ }
+ switch (p[0]) {
+ case 'a':
+ TEST(p, "arch", SF_ARCHIVED);
+ TEST(p, "archived", SF_ARCHIVED);
+ return (1);
+ case 'd':
+ clear = !clear;
+ TEST(p, "dump", UF_NODUMP);
+ return (1);
+ case 'o':
+ TEST(p, "opaque", UF_OPAQUE);
+ return (1);
+ case 's':
+ TEST(p, "sappnd", SF_APPEND);
+ TEST(p, "sappend", SF_APPEND);
+ TEST(p, "schg", SF_IMMUTABLE);
+ TEST(p, "schange", SF_IMMUTABLE);
+ TEST(p, "simmutable", SF_IMMUTABLE);
+ TEST(p, "sunlnk", SF_NOUNLINK);
+ TEST(p, "sunlink", SF_NOUNLINK);
+ return (1);
+ case 'u':
+ TEST(p, "uappnd", UF_APPEND);
+ TEST(p, "uappend", UF_APPEND);
+ TEST(p, "uchg", UF_IMMUTABLE);
+ TEST(p, "uchange", UF_IMMUTABLE);
+ TEST(p, "uimmutable", UF_IMMUTABLE);
+ TEST(p, "uunlnk", UF_NOUNLINK);
+ TEST(p, "uunlink", UF_NOUNLINK);
+ /* FALLTHROUGH */
+ default:
+ return (1);
+ }
+ }
+ return (0);
+}
diff --git a/lib/libc/gen/setflagsbyname.c b/lib/libc/gen/setflagsbyname.c
new file mode 100644
index 0000000..b1e7062
--- /dev/null
+++ b/lib/libc/gen/setflagsbyname.c
@@ -0,0 +1,163 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id: stat_flags.c,v 1.5 1997/02/22 14:04:02 peter Exp $
+ */
+
+#ifndef lint
+static char const sccsid[] = "@(#)stat_flags.c 8.1 (Berkeley) 5/31/93";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stddef.h>
+#include <string.h>
+
+#define SAPPEND(s) { \
+ if (prefix != NULL) \
+ (void)strcat(string, prefix); \
+ (void)strcat(string, s); \
+ prefix = ","; \
+}
+
+/*
+ * flags_to_string --
+ * Convert stat flags to a comma-separated string. If no flags
+ * are set, return the default string.
+ */
+char *
+flags_to_string(flags, def)
+ u_long flags;
+ char *def;
+{
+ static char string[128];
+ char *prefix;
+
+ string[0] = '\0';
+ prefix = NULL;
+ if (flags & UF_APPEND)
+ SAPPEND("uappnd");
+ if (flags & UF_IMMUTABLE)
+ SAPPEND("uchg");
+ if (flags & UF_NOUNLINK)
+ SAPPEND("uunlnk");
+ if (flags & UF_NODUMP)
+ SAPPEND("nodump");
+ if (flags & UF_OPAQUE)
+ SAPPEND("opaque");
+ if (flags & SF_APPEND)
+ SAPPEND("sappnd");
+ if (flags & SF_ARCHIVED)
+ SAPPEND("arch");
+ if (flags & SF_IMMUTABLE)
+ SAPPEND("schg");
+ if (flags & SF_NOUNLINK)
+ SAPPEND("sunlnk");
+ return (prefix == NULL && def != NULL ? def : string);
+}
+
+#define TEST(a, b, f) { \
+ if (!memcmp(a, b, sizeof(b))) { \
+ if (clear) { \
+ if (clrp) \
+ *clrp |= (f); \
+ } else if (setp) \
+ *setp |= (f); \
+ break; \
+ } \
+}
+
+/*
+ * string_to_flags --
+ * Take string of arguments and return stat flags. Return 0 on
+ * success, 1 on failure. On failure, stringp is set to point
+ * to the offending token.
+ */
+int
+string_to_flags(stringp, setp, clrp)
+ char **stringp;
+ u_long *setp, *clrp;
+{
+ int clear;
+ char *string, *p;
+
+ clear = 0;
+ if (setp)
+ *setp = 0;
+ if (clrp)
+ *clrp = 0;
+ string = *stringp;
+ while ((p = strsep(&string, "\t ,")) != NULL) {
+ *stringp = p;
+ if (*p == '\0')
+ continue;
+ if (p[0] == 'n' && p[1] == 'o') {
+ clear = 1;
+ p += 2;
+ }
+ switch (p[0]) {
+ case 'a':
+ TEST(p, "arch", SF_ARCHIVED);
+ TEST(p, "archived", SF_ARCHIVED);
+ return (1);
+ case 'd':
+ clear = !clear;
+ TEST(p, "dump", UF_NODUMP);
+ return (1);
+ case 'o':
+ TEST(p, "opaque", UF_OPAQUE);
+ return (1);
+ case 's':
+ TEST(p, "sappnd", SF_APPEND);
+ TEST(p, "sappend", SF_APPEND);
+ TEST(p, "schg", SF_IMMUTABLE);
+ TEST(p, "schange", SF_IMMUTABLE);
+ TEST(p, "simmutable", SF_IMMUTABLE);
+ TEST(p, "sunlnk", SF_NOUNLINK);
+ TEST(p, "sunlink", SF_NOUNLINK);
+ return (1);
+ case 'u':
+ TEST(p, "uappnd", UF_APPEND);
+ TEST(p, "uappend", UF_APPEND);
+ TEST(p, "uchg", UF_IMMUTABLE);
+ TEST(p, "uchange", UF_IMMUTABLE);
+ TEST(p, "uimmutable", UF_IMMUTABLE);
+ TEST(p, "uunlnk", UF_NOUNLINK);
+ TEST(p, "uunlink", UF_NOUNLINK);
+ /* FALLTHROUGH */
+ default:
+ return (1);
+ }
+ }
+ return (0);
+}
diff --git a/lib/libc/gen/sethostname.c b/lib/libc/gen/sethostname.c
index 639837e..6c3adc3 100644
--- a/lib/libc/gen/sethostname.c
+++ b/lib/libc/gen/sethostname.c
@@ -39,10 +39,10 @@ static char sccsid[] = "@(#)sethostname.c 8.1 (Berkeley) 6/4/93";
#include <sys/sysctl.h>
#if __STDC__
-long
+int
sethostname(const char *name, int namelen)
#else
-long
+int
sethostname(name, namelen)
char *name;
int namelen;
diff --git a/lib/libc/gen/setjmp.3 b/lib/libc/gen/setjmp.3
index 47cdfa5..3b5d89e 100644
--- a/lib/libc/gen/setjmp.3
+++ b/lib/libc/gen/setjmp.3
@@ -44,7 +44,8 @@
.Nm setjmp ,
.Nm longjmp ,
.Nm _setjmp ,
-.Nm _longjmp longjmperror
+.Nm _longjmp ,
+.Nm longjmperror
.Nd non-local jumps
.Sh SYNOPSIS
.Fd #include <setjmp.h>
@@ -125,7 +126,7 @@ pairs save and restore the signal mask while
.Fn _setjmp Ns / Ns Fn _longjmp
pairs save and restore only the register set and the stack.
(See
-.Fn sigmask 2 . )
+.Fn sigprocmask 2 . )
.Pp
The
.Fn sigsetjmp Ns / Ns Fn siglongjmp
@@ -144,7 +145,7 @@ routine calls the routine
If
.Fn longjmperror
returns the program is aborted (see
-.Xr abort 2 ) .
+.Xr abort 3 ) .
The default version of
.Fn longjmperror
prints the message
diff --git a/lib/libc/gen/setmode.3 b/lib/libc/gen/setmode.3
index 04c2a6b..4c85b30 100644
--- a/lib/libc/gen/setmode.3
+++ b/lib/libc/gen/setmode.3
@@ -39,6 +39,7 @@
.Nm setmode
.Nd modify mode bits
.Sh SYNOPSIS
+.Fd #include <unistd.h>
.Ft mode_t
.Fn getmode "const void *set" "mode_t mode"
.Ft void *
@@ -101,4 +102,5 @@ The
.Fn getmode
and
.Fn setmode
-functions first appeared in 4.4BSD.
+functions first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c
index 84cadcb..c69d775 100644
--- a/lib/libc/gen/setmode.c
+++ b/lib/libc/gen/setmode.c
@@ -67,7 +67,7 @@ typedef struct bitcmd {
#define CMD2_UBITS 0x10
static BITCMD *addcmd __P((BITCMD *, int, int, int, u_int));
-static int compress_mode __P((BITCMD *));
+static void compress_mode __P((BITCMD *));
#ifdef SETMODE_DEBUG
static void dumpmode __P((BITCMD *));
#endif
@@ -172,7 +172,7 @@ setmode(p)
BITCMD *set, *saveset, *endset;
sigset_t sigset, sigoset;
mode_t mask;
- int equalopdone, permXbits, setlen;
+ int equalopdone=0, permXbits, setlen;
if (!*p)
return (NULL);
@@ -190,7 +190,7 @@ setmode(p)
(void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
setlen = SET_LEN + 2;
-
+
if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL)
return (NULL);
saveset = set;
@@ -368,7 +368,7 @@ addcmd(set, op, who, oparg, mask)
set->cmd2 = CMD2_UBITS | CMD2_GBITS | CMD2_OBITS;
set->bits = mask;
}
-
+
if (oparg == '+')
set->cmd2 |= CMD2_SET;
else if (oparg == '-')
@@ -399,10 +399,10 @@ dumpmode(set)
/*
* Given an array of bitcmd structures, compress by compacting consecutive
* '+', '-' and 'X' commands into at most 3 commands, one of each. The 'u',
- * 'g' and 'o' commands continue to be separate. They could probably be
+ * 'g' and 'o' commands continue to be separate. They could probably be
* compacted, but it's not worth the effort.
*/
-static int
+static void
compress_mode(set)
register BITCMD *set;
{
diff --git a/lib/libc/gen/setproctitle.3 b/lib/libc/gen/setproctitle.3
new file mode 100644
index 0000000..c3f2031
--- /dev/null
+++ b/lib/libc/gen/setproctitle.3
@@ -0,0 +1,113 @@
+.\" Copyright (c) 1995 Peter Wemm <peter@freebsd.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, is permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice immediately at the beginning of the file, without modification,
+.\" 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.
+.\" 3. This work was done expressly for inclusion into FreeBSD. Other use
+.\" is permitted provided this notation is included.
+.\" 4. Absolutely no warranty of function or purpose is made by the author
+.\" Peter Wemm.
+.\" 5. Modifications may be freely made to this file providing the above
+.\" conditions are met.
+.\"
+.\" $Id: setproctitle.3,v 1.8 1997/04/17 23:31:47 danny Exp $
+.\"
+.\" The following requests are required for all man pages.
+.Dd December 16, 1995
+.Os FreeBSD
+.Dt SETPROCTITLE 3
+.Sh NAME
+.Nm setproctitle
+.Nd set the process title for
+.Xr ps 1
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <libutil.h>
+.Ft void
+.Fn setproctitle "const char *fmt" "..."
+.Pp
+Link with
+.Va -lutil
+on the
+.Xr cc 1
+command line.
+.Sh DESCRIPTION
+The
+.Fn setproctitle
+library routine sets the process title that appears on the
+.Xr ps 1
+command.
+.Pp
+The title is set from the executable's name, followed by the
+result of a
+.Xr printf 3
+style expansion of the arguments as specified by the
+.Va fmt
+argument.
+.Pp
+If
+.Va fmt
+is NULL, the process title is reset to simply the name of the executable.
+.\" The following requests should be uncommented and used where appropriate.
+.\" This next request is for sections 2 and 3 function return values only.
+.\" .Sh RETURN VALUES
+.\" This next request is for sections 1, 6, 7 & 8 only
+.\" .Sh ENVIRONMENT
+.\" .Sh FILES
+.Sh EXAMPLES
+To set the title on a daemon to indicate its activity:
+.Bd -literal -offset indent
+setproctitle("talking to %s", inet_ntoa(addr));
+.Ed
+.\" This next request is for sections 1, 6, 7 & 8 only
+.\" (command return values (to shell) and fprintf/stderr type diagnostics)
+.\" .Sh DIAGNOSTICS
+.\" The next request is for sections 2 and 3 error and signal handling only.
+.\" .Sh ERRORS
+.Sh SEE ALSO
+.Xr ps 1 ,
+.Xr w 1 ,
+.Xr kvm 3 ,
+.Xr kvm_getargv 3 ,
+.Xr printf 3
+.Sh STANDARDS
+.Fn setproctitle
+is implicitly non-standard. Other methods of causing the
+.Xr ps 1
+command line to change, including copying over the argv[0] string are
+also implicitly non-portable. It is preferable to use an operating system
+supplied
+.Fn setproctitle
+if present.
+.Pp
+Unfortunately, it is possible that there are other calling conventions
+to other versions of
+.Fn setproctitle ,
+although none have been found by the author as yet. This is believed to be
+the predominant convention.
+.Pp
+It is thought that the implementation is compatible with other systems,
+including
+.Tn NetBSD
+and
+.Tn BSD/OS .
+.Sh HISTORY
+.Fn setproctitle
+first appeared in
+.Fx 2.2 .
+Other operating systems have
+similar functions.
+.Sh AUTHORS
+.Sy "Peter Wemm <peter@FreeBSD.org>"
+stole the idea from the
+.Sy "Sendmail 8.7.3"
+source code by
+.Sy "Eric Allman <eric@sendmail.org>" .
+.\" .Sh BUGS
diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c
new file mode 100644
index 0000000..ba21d1c
--- /dev/null
+++ b/lib/libc/gen/setproctitle.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 1995 Peter Wemm <peter@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, is permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice immediately at the beginning of the file, without modification,
+ * 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.
+ * 3. Absolutely no warranty of function or purpose is made by the author
+ * Peter Wemm.
+ *
+ * $Id$
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/exec.h>
+#include <sys/sysctl.h>
+
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+#include <vm/pmap.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+/*
+ * Older FreeBSD 2.0, 2.1 and 2.2 had different ps_strings structures and
+ * in different locations.
+ * 1: old_ps_strings at the very top of the stack.
+ * 2: old_ps_strings at SPARE_USRSPACE below the top of the stack.
+ * 3: ps_strings at the very top of the stack.
+ * This attempts to support a kernel built in the #2 and #3 era.
+ */
+
+struct old_ps_strings {
+ char *old_ps_argvstr;
+ int old_ps_nargvstr;
+ char *old_ps_envstr;
+ int old_ps_nenvstr;
+};
+#define OLD_PS_STRINGS ((struct old_ps_strings *) \
+ (USRSTACK - SPARE_USRSPACE - sizeof(struct old_ps_strings)))
+
+#if defined(__STDC__) /* from other parts of sendmail */
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+
+#define SPT_BUFSIZE 2048 /* from other parts of sendmail */
+extern char * __progname; /* is this defined in a .h anywhere? */
+
+void
+#if defined(__STDC__)
+setproctitle(const char *fmt, ...)
+#else
+setproctitle(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
+{
+ static char buf[SPT_BUFSIZE];
+ static char *ps_argv[2];
+ va_list ap;
+ int mib[2];
+ struct ps_strings *ps_strings;
+ size_t len;
+
+#if defined(__STDC__)
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+
+ buf[sizeof(buf) - 1] = '\0';
+ if (fmt) {
+
+ /* print program name heading for grep */
+ (void) snprintf(buf, sizeof(buf) - 1, "%s: ", __progname);
+
+ /*
+ * can't use return from sprintf, as that is the count of how
+ * much it wanted to write, not how much it actually did.
+ */
+
+ len = strlen(buf);
+
+ /* print the argument string */
+ (void) vsnprintf(buf + len, sizeof(buf) - 1 - len, fmt, ap);
+ } else {
+ /* Idea from NetBSD - reset the title on fmt == NULL */
+ strncpy(buf, __progname, sizeof(buf) - 1);
+ }
+
+ va_end(ap);
+
+ ps_strings = NULL;
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PS_STRINGS;
+ len = sizeof(ps_strings);
+ if (sysctl(mib, 2, &ps_strings, &len, NULL, 0) < 0 ||
+ ps_strings == NULL)
+ ps_strings = PS_STRINGS;
+
+ /* PS_STRINGS points to zeroed memory on a style #2 kernel */
+ if (ps_strings->ps_argvstr) {
+ /* style #3 */
+ ps_argv[0] = buf;
+ ps_argv[1] = NULL;
+ ps_strings->ps_nargvstr = 1;
+ ps_strings->ps_argvstr = ps_argv;
+ } else {
+ /* style #2 */
+ OLD_PS_STRINGS->old_ps_nargvstr = 1;
+ OLD_PS_STRINGS->old_ps_argvstr = buf;
+ }
+}
diff --git a/lib/libc/gen/shmat.c b/lib/libc/gen/shmat.c
new file mode 100644
index 0000000..1cd0779
--- /dev/null
+++ b/lib/libc/gen/shmat.c
@@ -0,0 +1,19 @@
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#if __STDC__
+void *shmat(int shmid, void *shmaddr, int shmflg)
+#else
+void *shmat(shmid, shmaddr, shmflg)
+ int shmid;
+ void *shmaddr;
+ int shmflg;
+#endif
+{
+ return ((void *)shmsys(0, shmid, shmaddr, shmflg));
+}
diff --git a/lib/libc/gen/shmctl.c b/lib/libc/gen/shmctl.c
new file mode 100644
index 0000000..b0585fd
--- /dev/null
+++ b/lib/libc/gen/shmctl.c
@@ -0,0 +1,19 @@
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#if __STDC__
+int shmctl(int shmid, int cmd, struct shmid_ds *buf)
+#else
+int shmctl(shmid, cmd, buf)
+ int shmid;
+ int cmd;
+ struct shmid_ds *buf;
+#endif
+{
+ return (shmsys(4, shmid, cmd, buf));
+}
diff --git a/lib/libc/gen/shmdt.c b/lib/libc/gen/shmdt.c
new file mode 100644
index 0000000..feae3d1
--- /dev/null
+++ b/lib/libc/gen/shmdt.c
@@ -0,0 +1,17 @@
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#if __STDC__
+int shmdt(void *shmaddr)
+#else
+int shmdt(shmaddr)
+ void *shmaddr;
+#endif
+{
+ return (shmsys(2, shmaddr));
+}
diff --git a/lib/libc/gen/shmget.c b/lib/libc/gen/shmget.c
new file mode 100644
index 0000000..0119511
--- /dev/null
+++ b/lib/libc/gen/shmget.c
@@ -0,0 +1,19 @@
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#if __STDC__
+int shmget(key_t key, int size, int shmflg)
+#else
+int shmget(key, size, shmflg)
+ key_t key;
+ int size;
+ int shmflg;
+#endif
+{
+ return (shmsys(3, key, size, shmflg));
+}
diff --git a/lib/libc/gen/siginterrupt.3 b/lib/libc/gen/siginterrupt.3
index 1dadb28..46eb8de 100644
--- a/lib/libc/gen/siginterrupt.3
+++ b/lib/libc/gen/siginterrupt.3
@@ -50,8 +50,10 @@ behavior when a system call is interrupted by the specified signal.
If the flag is false (0), then system calls will be restarted if
they are interrupted by the specified signal
and no data has been transferred yet.
-System call restart is the default behavior on
-.Bx 4.2 .
+System call restart has been the default behavior since
+.Bx 4.2 ,
+and is the default behaviour on
+.Tn FreeBSD .
.Pp
If the flag is true (1),
then restarting of system calls is disabled.
diff --git a/lib/libc/gen/siginterrupt.c b/lib/libc/gen/siginterrupt.c
index 3105d13..06960ab 100644
--- a/lib/libc/gen/siginterrupt.c
+++ b/lib/libc/gen/siginterrupt.c
@@ -41,6 +41,7 @@ static char sccsid[] = "@(#)siginterrupt.c 8.1 (Berkeley) 6/4/93";
* Set signal state to prevent restart of system calls
* after an instance of the indicated signal.
*/
+int
siginterrupt(sig, flag)
int sig, flag;
{
diff --git a/lib/libc/gen/signal.3 b/lib/libc/gen/signal.3
index e17c2df..192e2d8 100644
--- a/lib/libc/gen/signal.3
+++ b/lib/libc/gen/signal.3
@@ -39,12 +39,13 @@
.Nd simplified software signal facilities
.Sh SYNOPSIS
.Fd #include <signal.h>
-.Ft void
-.Fn *signal sig func\*(lp\*(rp
-.Ft void
-.\" can not do this with .Fn yet
-.br
-\*(lp\|\*(fN*func\*(rp\*(lp\|\*(rp\fR
+.Ft void \*(lp*
+.Fn signal "int sig" "void \*(lp*func\*(rp\*(lpint\*(rp\*(rp\*(rp\*(lpint"
+
+or in FreeBSD's equivalent but easier to read typedef'd version:
+.Ft typedef "void \*(lp*sig_t\*(rp \*(lpint\*(rp"
+.Ft sig_t
+.Fn signal "int sig" "sig_t func"
.Sh DESCRIPTION
This
.Fn signal
@@ -97,7 +98,7 @@ call (formerly
.It Dv SIGKILL No " terminate process" " kill program"
.It Dv SIGBUS No " create core image" " bus error"
.It Dv SIGSEGV No " create core image" " segmentation violation"
-.It Dv SIGSYS No " create core image" " system call given invalid argument"
+.It Dv SIGSYS No " create core image" " non-existent system call invoked"
.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader"
.It Dv SIGALRM No " terminate process" " real-time timer expired"
.It Dv SIGTERM No " terminate process" " software termination signal"
@@ -126,6 +127,9 @@ is possible on a descriptor (see
.El
.Pp
The
+.Fa sig
+parameter specifies which signal was received.
+The
.Fa func
procedure allows a user to choose the action upon receipt of a signal.
To set the default action of the signal to occur as listed above,
@@ -148,7 +152,7 @@ automatically blocked and
.Fa func
is called.
.Pp
-The handled signal is unblocked with the
+The handled signal is unblocked when the
function returns and
the process continues from where it left off when the signal occurred.
.Bf -symbolic
@@ -192,7 +196,7 @@ Otherwise, \-1 is returned and the global variable
.Va errno
is set to indicate the error.
.Sh ERRORS
-.Xr Signal
+.Fn Signal
will fail and no action will take place if one of the
following occur:
.Bl -tag -width [EINVAL]
@@ -206,8 +210,8 @@ or
.Ev SIGSTOP .
.Sh SEE ALSO
.Xr kill 1 ,
-.Xr ptrace 2 ,
.Xr kill 2 ,
+.Xr ptrace 2 ,
.Xr sigaction 2 ,
.Xr sigaltstack 2 ,
.Xr sigprocmask 2 ,
diff --git a/lib/libc/gen/sigsetops.3 b/lib/libc/gen/sigsetops.3
index b62253e..97b3316 100644
--- a/lib/libc/gen/sigsetops.3
+++ b/lib/libc/gen/sigsetops.3
@@ -43,11 +43,16 @@
.Nd manipulate signal sets
.Sh SYNOPSIS
.Fd #include <signal.h>
+.Ft int
.Fn sigemptyset "sigset_t *set"
+.Ft int
.Fn sigfillset "sigset_t *set"
+.Ft int
.Fn sigaddset "sigset_t *set" "int signo"
+.Ft int
.Fn sigdelset "sigset_t *set" "int signo"
-.Fn sigismember "sigset_t *set" "int signo"
+.Ft int
+.Fn sigismember "const sigset_t *set" "int signo"
.Sh DESCRIPTION
These functions manipulate signal sets stored in a
.Fa sigset_t .
diff --git a/lib/libc/gen/sigsetops.c b/lib/libc/gen/sigsetops.c
index e6acb77..c3bd870 100644
--- a/lib/libc/gen/sigsetops.c
+++ b/lib/libc/gen/sigsetops.c
@@ -45,6 +45,7 @@ static char sccsid[] = "@(#)sigsetops.c 8.1 (Berkeley) 6/4/93";
#undef sigdelset
#undef sigismember
+int
sigemptyset(set)
sigset_t *set;
{
@@ -52,6 +53,7 @@ sigemptyset(set)
return (0);
}
+int
sigfillset(set)
sigset_t *set;
{
@@ -59,6 +61,7 @@ sigfillset(set)
return (0);
}
+int
sigaddset(set, signo)
sigset_t *set;
int signo;
@@ -67,6 +70,7 @@ sigaddset(set, signo)
return (0);
}
+int
sigdelset(set, signo)
sigset_t *set;
int signo;
@@ -75,6 +79,7 @@ sigdelset(set, signo)
return (0);
}
+int
sigismember(set, signo)
const sigset_t *set;
int signo;
diff --git a/lib/libc/gen/sleep.3 b/lib/libc/gen/sleep.3
index 9e3c797..f488a0b 100644
--- a/lib/libc/gen/sleep.3
+++ b/lib/libc/gen/sleep.3
@@ -70,12 +70,33 @@ A similar but less compatible function can be obtained with a single
.Xr select 2 ;
such a function would not restart after signals, but would not interfere
with other uses of
-.Xr setitimer .
+.Xr setitimer 2 .
.Sh RETURN VALUES
+The
+.Fn sleep
+function returns the number of seconds remaining to complete the operation. If
+sleep is interrupted or cannot allocate a timer it may will return the value
+needed to be passed to a subsequent sleep to complete the necessary delay.
+.Fn sleep
+repeatedly until it returns zero may busy-wait until a timer
+is available.
.Sh SEE ALSO
.Xr setitimer 2 ,
.Xr sigpause 2 ,
.Xr usleep 3
+.Sh CAVEAT
+In practice the
+.Tn FreeBSD
+implementation will not be interrupted: it will
+always return the original argument or zero. Code that depends on
+sleep being interrupted (using it as a timed pause, for example) needs
+to be recoded to use
+.Xr select 2
+or some other delay mechanism. Code that
+calls
+.Fn sleep
+repeatedly until it returns zero may busy-wait until a timer
+is available.
.Sh HISTORY
A
.Fn sleep
diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c
index 3c0b8fa..49f2d89 100644
--- a/lib/libc/gen/sleep.c
+++ b/lib/libc/gen/sleep.c
@@ -36,62 +36,88 @@ static char sccsid[] = "@(#)sleep.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/time.h>
-#include <sys/signal.h>
+#include <signal.h>
#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
-#define setvec(vec, a) \
- vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0
-
-static int ringring;
+#ifndef _THREAD_SAFE
+static void
+sleephandler()
+{
+ return;
+}
+#endif /* _THREAD_SAFE */
unsigned int
sleep(seconds)
unsigned int seconds;
{
- register struct itimerval *itp;
- struct itimerval itv, oitv;
- struct sigvec vec, ovec;
- long omask;
- static void sleephandler();
+#ifdef _THREAD_SAFE
+ struct timespec time_to_sleep;
+ struct timespec time_remaining;
+
+ if (seconds != 0) {
+ time_to_sleep.tv_sec = seconds;
+ time_to_sleep.tv_nsec = 0;
+ nanosleep(&time_to_sleep, &time_remaining);
+ seconds = time_remaining.tv_sec;
+ if (time_remaining.tv_nsec > 0)
+ seconds++; /* round up */
+ }
+ return (seconds);
+#else
+ struct timespec time_to_sleep;
+ struct timespec time_remaining;
+ struct sigaction act, oact;
+ sigset_t mask, omask;
+ int alarm_blocked;
+
+ if (seconds != 0) {
+ time_to_sleep.tv_sec = seconds;
+ time_to_sleep.tv_nsec = 0;
+
+ /* Block SIGALRM while fiddling with it */
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGALRM);
+ sigprocmask(SIG_BLOCK, &mask, &omask);
+
+ /* Was SIGALRM blocked already? */
+ alarm_blocked = sigismember(&omask, SIGALRM);
- itp = &itv;
- if (!seconds)
- return 0;
- timerclear(&itp->it_interval);
- timerclear(&itp->it_value);
- if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
- return seconds;
- itp->it_value.tv_sec = seconds;
- if (timerisset(&oitv.it_value)) {
- if (timercmp(&oitv.it_value, &itp->it_value, >))
- oitv.it_value.tv_sec -= itp->it_value.tv_sec;
- else {
- itp->it_value = oitv.it_value;
+ if (!alarm_blocked) {
/*
- * This is a hack, but we must have time to return
- * from the setitimer after the alarm or else it'll
- * be restarted. And, anyway, sleep never did
- * anything more than this before.
+ * Set up handler to interrupt signanosleep only if
+ * SIGALRM was unblocked. (Save some syscalls)
*/
- oitv.it_value.tv_sec = 1;
- oitv.it_value.tv_usec = 0;
+ memset(&act, 0, sizeof(act));
+ act.sa_handler = sleephandler;
+ sigaction(SIGALRM, &act, &oact);
}
- }
- setvec(vec, sleephandler);
- (void) sigvec(SIGALRM, &vec, &ovec);
- omask = sigblock(sigmask(SIGALRM));
- ringring = 0;
- (void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0);
- while (!ringring)
- sigpause(omask &~ sigmask(SIGALRM));
- (void) sigvec(SIGALRM, &ovec, (struct sigvec *)0);
- (void) sigsetmask(omask);
- (void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0);
- return 0;
-}
-static void
-sleephandler()
-{
- ringring = 1;
+ /*
+ * signanosleep() uses the given mask for the lifetime of
+ * the syscall only - it resets on return. Note that the
+ * Old sleep explicitly unblocks SIGALRM during the sleep,
+ * we don't do that now since we don't depend on SIGALRM
+ * to end the timout. If the process blocks SIGALRM, it
+ * gets what it asks for.
+ */
+ signanosleep(&time_to_sleep, &time_remaining, &omask);
+
+ if (!alarm_blocked) {
+ /* Unwind */
+ sigaction(SIGALRM, &oact, (struct sigaction *)0);
+ sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
+ }
+
+ /* return how long is left */
+ seconds = time_remaining.tv_sec;
+ if (time_remaining.tv_nsec > 0)
+ seconds++; /* round up */
+ }
+ return (seconds);
+#endif /* _THREAD_SAFE */
}
diff --git a/lib/libc/gen/srand48.c b/lib/libc/gen/srand48.c
new file mode 100644
index 0000000..fd369a0
--- /dev/null
+++ b/lib/libc/gen/srand48.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+
+#include "rand48.h"
+
+extern unsigned short _rand48_seed[3];
+extern unsigned short _rand48_mult[3];
+extern unsigned short _rand48_add;
+
+void
+srand48(long seed)
+{
+ _rand48_seed[0] = RAND48_SEED_0;
+ _rand48_seed[1] = (unsigned short) seed;
+ _rand48_seed[2] = (unsigned short) (seed >> 16);
+ _rand48_mult[0] = RAND48_MULT_0;
+ _rand48_mult[1] = RAND48_MULT_1;
+ _rand48_mult[2] = RAND48_MULT_2;
+ _rand48_add = RAND48_ADD;
+}
diff --git a/lib/libc/gen/stringlist.3 b/lib/libc/gen/stringlist.3
new file mode 100644
index 0000000..5023c5c
--- /dev/null
+++ b/lib/libc/gen/stringlist.3
@@ -0,0 +1,120 @@
+.\" $NetBSD: stringlist.3,v 1.2 1997/04/09 08:59:25 kleink Exp $
+.\"
+.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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.
+.\"
+.Dd February 24, 1997
+.Os NetBSD 1.3
+.Dt STRINGLIST 3
+.Sh NAME
+.Nm stringlist ,
+.Nm sl_init ,
+.Nm sl_add ,
+.Nm sl_free ,
+.Nm sl_find
+.Nd stringlist manipulation functions
+.Sh SYNOPSIS
+.Fd #include <stringlist.h>
+.Ft StringList *
+.Fn sl_init
+.Ft void
+.Fn sl_add "StringList *sl" "char *item"
+.Ft void
+.Fn sl_free "StringList *sl" "int freeall"
+.Ft char *
+.Fn sl_find "StringList *sl" "char *item"
+.Sh DESCRIPTION
+The
+.Nm
+functions manipulate stringlists, which are lists of
+strings that extend automatically if necessary.
+.Pp
+The
+.Ar StringList
+structure has the following definition:
+.Bd -literal -offset indent
+typedef struct _stringlist {
+ char **sl_str;
+ size_t sl_max;
+ size_t sl_cur;
+} StringList;
+.Ed
+.Pp
+.Bl -tag -width "sl_str" -offset indent
+.It Ar sl_str
+a pointer to the base of the array containing the list.
+.It Ar sl_max
+the size of
+.Ar sl_str .
+.It Ar sl_cur
+the offset in
+.Ar sl_str
+of the current element.
+.El
+.Pp
+The following stringlist manipulation functions are available:
+.Bl -tag -width "sl_init()"
+.It Fn sl_init
+Create a stringlist.
+Returns a pointer to a
+.Ar StringList .
+.It Fn sl_free
+Releases memory occupied by
+.Ar sl
+and the
+.Ar sl->sl_str
+array.
+If
+.Ar freeall
+is non-zero, then each of the items within
+.Ar sl->sl_str
+is released as well.
+.It Fn sl_add
+Add
+.Ar item
+to
+.Ar sl->sl_str
+at
+.Ar sl->sl_cur ,
+extending the size of
+.Ar sl->sl_str
+.It Fn sl_find
+Find
+.Ar item
+in
+.Ar sl ,
+returning NULL if it's not found.
+.El
+.Sh SEE ALSO
+.Xr free 3 ,
+.Xr malloc 3
diff --git a/lib/libc/gen/stringlist.c b/lib/libc/gen/stringlist.c
new file mode 100644
index 0000000..57c4d91
--- /dev/null
+++ b/lib/libc/gen/stringlist.c
@@ -0,0 +1,120 @@
+/* $NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $ */
+
+/*
+ * Copyright (c) 1994 Christos Zoulas
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 *rcsid = "$NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <string.h>
+#include <err.h>
+#include <stdlib.h>
+#include <stringlist.h>
+
+#define _SL_CHUNKSIZE 20
+
+/*
+ * sl_init(): Initialize a string list
+ */
+StringList *
+sl_init()
+{
+ StringList *sl = malloc(sizeof(StringList));
+ if (sl == NULL)
+ err(1, "stringlist: %m");
+
+ sl->sl_cur = 0;
+ sl->sl_max = _SL_CHUNKSIZE;
+ sl->sl_str = malloc(sl->sl_max * sizeof(char *));
+ if (sl->sl_str == NULL)
+ err(1, "stringlist: %m");
+ return sl;
+}
+
+
+/*
+ * sl_add(): Add an item to the string list
+ */
+void
+sl_add(sl, name)
+ StringList *sl;
+ char *name;
+{
+ if (sl->sl_cur == sl->sl_max - 1) {
+ sl->sl_max += _SL_CHUNKSIZE;
+ sl->sl_str = realloc(sl->sl_str, sl->sl_max * sizeof(char *));
+ if (sl->sl_str == NULL)
+ err(1, "stringlist: %m");
+ }
+ sl->sl_str[sl->sl_cur++] = name;
+}
+
+
+/*
+ * sl_free(): Free a stringlist
+ */
+void
+sl_free(sl, all)
+ StringList *sl;
+ int all;
+{
+ size_t i;
+
+ if (sl == NULL)
+ return;
+ if (sl->sl_str) {
+ if (all)
+ for (i = 0; i < sl->sl_cur; i++)
+ free(sl->sl_str[i]);
+ free(sl->sl_str);
+ }
+ free(sl);
+}
+
+
+/*
+ * sl_find(): Find a name in the string list
+ */
+char *
+sl_find(sl, name)
+ StringList *sl;
+ char *name;
+{
+ size_t i;
+
+ for (i = 0; i < sl->sl_cur; i++)
+ if (strcmp(sl->sl_str[i], name) == 0)
+ return sl->sl_str[i];
+
+ return NULL;
+}
diff --git a/lib/libc/gen/strtofflags.c b/lib/libc/gen/strtofflags.c
new file mode 100644
index 0000000..b1e7062
--- /dev/null
+++ b/lib/libc/gen/strtofflags.c
@@ -0,0 +1,163 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id: stat_flags.c,v 1.5 1997/02/22 14:04:02 peter Exp $
+ */
+
+#ifndef lint
+static char const sccsid[] = "@(#)stat_flags.c 8.1 (Berkeley) 5/31/93";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stddef.h>
+#include <string.h>
+
+#define SAPPEND(s) { \
+ if (prefix != NULL) \
+ (void)strcat(string, prefix); \
+ (void)strcat(string, s); \
+ prefix = ","; \
+}
+
+/*
+ * flags_to_string --
+ * Convert stat flags to a comma-separated string. If no flags
+ * are set, return the default string.
+ */
+char *
+flags_to_string(flags, def)
+ u_long flags;
+ char *def;
+{
+ static char string[128];
+ char *prefix;
+
+ string[0] = '\0';
+ prefix = NULL;
+ if (flags & UF_APPEND)
+ SAPPEND("uappnd");
+ if (flags & UF_IMMUTABLE)
+ SAPPEND("uchg");
+ if (flags & UF_NOUNLINK)
+ SAPPEND("uunlnk");
+ if (flags & UF_NODUMP)
+ SAPPEND("nodump");
+ if (flags & UF_OPAQUE)
+ SAPPEND("opaque");
+ if (flags & SF_APPEND)
+ SAPPEND("sappnd");
+ if (flags & SF_ARCHIVED)
+ SAPPEND("arch");
+ if (flags & SF_IMMUTABLE)
+ SAPPEND("schg");
+ if (flags & SF_NOUNLINK)
+ SAPPEND("sunlnk");
+ return (prefix == NULL && def != NULL ? def : string);
+}
+
+#define TEST(a, b, f) { \
+ if (!memcmp(a, b, sizeof(b))) { \
+ if (clear) { \
+ if (clrp) \
+ *clrp |= (f); \
+ } else if (setp) \
+ *setp |= (f); \
+ break; \
+ } \
+}
+
+/*
+ * string_to_flags --
+ * Take string of arguments and return stat flags. Return 0 on
+ * success, 1 on failure. On failure, stringp is set to point
+ * to the offending token.
+ */
+int
+string_to_flags(stringp, setp, clrp)
+ char **stringp;
+ u_long *setp, *clrp;
+{
+ int clear;
+ char *string, *p;
+
+ clear = 0;
+ if (setp)
+ *setp = 0;
+ if (clrp)
+ *clrp = 0;
+ string = *stringp;
+ while ((p = strsep(&string, "\t ,")) != NULL) {
+ *stringp = p;
+ if (*p == '\0')
+ continue;
+ if (p[0] == 'n' && p[1] == 'o') {
+ clear = 1;
+ p += 2;
+ }
+ switch (p[0]) {
+ case 'a':
+ TEST(p, "arch", SF_ARCHIVED);
+ TEST(p, "archived", SF_ARCHIVED);
+ return (1);
+ case 'd':
+ clear = !clear;
+ TEST(p, "dump", UF_NODUMP);
+ return (1);
+ case 'o':
+ TEST(p, "opaque", UF_OPAQUE);
+ return (1);
+ case 's':
+ TEST(p, "sappnd", SF_APPEND);
+ TEST(p, "sappend", SF_APPEND);
+ TEST(p, "schg", SF_IMMUTABLE);
+ TEST(p, "schange", SF_IMMUTABLE);
+ TEST(p, "simmutable", SF_IMMUTABLE);
+ TEST(p, "sunlnk", SF_NOUNLINK);
+ TEST(p, "sunlink", SF_NOUNLINK);
+ return (1);
+ case 'u':
+ TEST(p, "uappnd", UF_APPEND);
+ TEST(p, "uappend", UF_APPEND);
+ TEST(p, "uchg", UF_IMMUTABLE);
+ TEST(p, "uchange", UF_IMMUTABLE);
+ TEST(p, "uimmutable", UF_IMMUTABLE);
+ TEST(p, "uunlnk", UF_NOUNLINK);
+ TEST(p, "uunlink", UF_NOUNLINK);
+ /* FALLTHROUGH */
+ default:
+ return (1);
+ }
+ }
+ return (0);
+}
diff --git a/lib/libc/gen/sysconf.3 b/lib/libc/gen/sysconf.3
index 53622f6..aca1a432 100644
--- a/lib/libc/gen/sysconf.3
+++ b/lib/libc/gen/sysconf.3
@@ -64,11 +64,11 @@ The available values are as follows:
.Pp
.It Li _SC_ARG_MAX
The maximum bytes of argument to
-.Xr exec 2 .
+.Xr execve 2 .
.It Li _SC_CHILD_MAX
The maximum number of simultaneous processes per user id.
.It Li _SC_CLK_TCK
-Number of micro-seconds per hz tick.
+The frequency of the statistics clock in ticks per second.
.It Li _SC_NGROUPS_MAX
The maximum number of supplemental groups.
.It Li _SC_OPEN_MAX
@@ -145,7 +145,7 @@ otherwise \-1.
.El
.Sh RETURN VALUES
If the call to
-.Nm sysconf
+.Fn sysconf
is not successful, \-1 is returned and
.Va errno
is set appropriately.
@@ -174,11 +174,13 @@ The value for _SC_STREAM_MAX is a minimum maximum, and required to be
the same as ANSI C's FOPEN_MAX, so the returned value is a ridiculously
small and misleading number.
.Sh STANDARDS
-The
+Except for the fact that values returned by
.Fn sysconf
-function conforms to
+may change over the lifetime of the calling process,
+this function conforms to
.St -p1003.1-88 .
.Sh HISTORY
The
-.Nm sysconf
-function first appeared in 4.4BSD.
+.Fn sysconf
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index 12d6f58..16a3efa 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -39,11 +39,12 @@ static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
-#include <sys/sysctl.h>
#include <sys/time.h>
+#include <sys/sysctl.h>
#include <sys/resource.h>
#include <errno.h>
+#include <time.h>
#include <unistd.h>
/*
@@ -62,7 +63,6 @@ long
sysconf(name)
int name;
{
- struct clockinfo clk;
struct rlimit rl;
size_t len;
int mib[2], value;
@@ -184,5 +184,5 @@ yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
errno = EINVAL;
return (-1);
}
- return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value);
+ return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value);
}
diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3
index 5470574..df0b4c2 100644
--- a/lib/libc/gen/sysctl.3
+++ b/lib/libc/gen/sysctl.3
@@ -31,36 +31,37 @@
.\"
.\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95
.\"
-.Dd "May 9, 1995"
+.Dd May 9, 1995
.Dt SYSCTL 3
.Os
.Sh NAME
.Nm sysctl
.Nd get or set system information
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
.Fd #include <sys/sysctl.h>
.Ft int
.Fn sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen"
.Sh DESCRIPTION
The
-.Nm sysctl
+.Fn sysctl
function retrieves system information and allows processes with
appropriate privileges to set system information.
The information available from
-.Nm sysctl
+.Fn sysctl
consists of integers, strings, and tables.
Information may be retrieved and set from the command interface
using the
-.Xr sysctl 1
+.Xr sysctl 8
utility.
.Pp
Unless explicitly noted below,
-.Nm sysctl
+.Fn sysctl
returns a consistent snapshot of the data requested.
Consistency is obtained by locking the destination
buffer into memory so that the data may be copied out without blocking.
Calls to
-.Nm sysctl
+.Fn sysctl
are serialized to avoid deadlock.
.Pp
The state is described using a ``Management Information Base'' (MIB)
@@ -75,7 +76,8 @@ The information is copied into the buffer specified by
The size of the buffer is given by the location specified by
.Fa oldlenp
before the call,
-and that location gives the amount of data copied after a successful call.
+and that location gives the amount of data copied after a successful call
+and after a call that returns with the error code ENOMEM.
If the amount of data available is greater
than the size of the buffer supplied,
the call supplies as much data as fits in the buffer provided
@@ -87,7 +89,7 @@ and
should be set to NULL.
.Pp
The size of the available data can be determined by calling
-.Nm sysctl
+.Fn sysctl
with a NULL parameter for
.Fa oldp .
The size of the available data will be returned in the location pointed to by
@@ -128,22 +130,24 @@ listed here, and described in separate sections below.
.Pp
For example, the following retrieves the maximum number of processes allowed
in the system:
+.Pp
.Bd -literal -offset indent -compact
int mib[2], maxproc;
size_t len;
-.sp
+
mib[0] = CTL_KERN;
mib[1] = KERN_MAXPROC;
len = sizeof(maxproc);
sysctl(mib, 2, &maxproc, &len, NULL, 0);
.Ed
-.sp
+.Pp
To retrieve the standard search path for the system utilities:
+.Pp
.Bd -literal -offset indent -compact
int mib[2];
size_t len;
char *p;
-.sp
+
mib[0] = CTL_USER;
mib[1] = USER_CS_PATH;
sysctl(mib, 2, NULL, &len, NULL, 0);
@@ -153,10 +157,10 @@ sysctl(mib, 2, p, &len, NULL, 0);
.Sh CTL_DEBUG
The debugging variables vary from system to system.
A debugging variable may be added or deleted without need to recompile
-.Nm sysctl
+.Fn sysctl
to know about it.
Each time it runs,
-.Nm sysctl
+.Fn sysctl
gets the list of debugging variables from the kernel and
displays their current values.
The system defines twenty
@@ -207,6 +211,7 @@ privilege may change the value.
.It HW\_PHYSMEM integer no
.It HW\_USERMEM integer no
.It HW\_PAGESIZE integer no
+.It HW\_FLOATINGPOINT integer no
.\".It HW\_DISKNAMES integer no
.\".It HW\_DISKSTATS integer no
.El
@@ -227,6 +232,8 @@ The bytes of physical memory.
The bytes of non-kernel memory.
.It Li HW_PAGESIZE
The software page size.
+.It Li HW_FLOATINGPOINT
+Nonzero if the floating point support is in hardware.
.\".It Fa HW_DISKNAMES
.\".It Fa HW_DISKSTATS
.El
@@ -239,36 +246,33 @@ The types of data currently available are process information,
system vnodes, the open file entries, routing table entries,
virtual memory statistics, load average history, and clock rate
information.
-.Bl -column "KERNXCHOWNXRESTRICTEDXXX" "struct clockrateXXX" -offset indent
+.Bl -column "KERNXMAXFILESPERPROCXXX" "struct clockrateXXX" -offset indent
.It Sy Pa Second level name Type Changeable
.It KERN\_ARGMAX integer no
+.It KERN\_BOOTFILE string yes
.It KERN\_BOOTTIME struct timeval no
-.It KERN\_CHOWN\_RESTRICTED integer no
.It KERN\_CLOCKRATE struct clockinfo no
.It KERN\_FILE struct file no
.It KERN\_HOSTID integer yes
.It KERN\_HOSTNAME string yes
.It KERN\_JOB\_CONTROL integer no
-.It KERN\_LINK\_MAX integer no
.It KERN\_MAXFILES integer yes
+.It KERN\_MAXFILESPERPROC integer yes
.It KERN\_MAXPROC integer yes
+.It KERN\_MAXPROCPERUID integer yes
.It KERN\_MAXVNODES integer yes
-.It KERN\_MAX\_CANON integer no
-.It KERN\_MAX\_INPUT integer no
-.It KERN\_NAME\_MAX integer no
.It KERN\_NGROUPS integer no
-.It KERN\_NO\_TRUNC integer no
+.It KERN\_NISDOMAINNAME string yes
+.It KERN\_OSRELDATE integer no
.It KERN\_OSRELEASE string no
.It KERN\_OSREV integer no
.It KERN\_OSTYPE string no
-.It KERN\_PATH\_MAX integer no
-.It KERN\_PIPE\_BUF integer no
.It KERN\_POSIX1 integer no
.It KERN\_PROC struct proc no
.It KERN\_PROF node not applicable
.It KERN\_SAVED\_IDS integer no
.It KERN\_SECURELVL integer raise only
-.It KERN\_VDISABLE integer no
+.It KERN\_UPDATEINTERVAL integer no
.It KERN\_VERSION string no
.It KERN\_VNODE struct vnode no
.El
@@ -277,22 +281,20 @@ information.
.Bl -tag -width "123456"
.It Li KERN_ARGMAX
The maximum bytes of argument to
-.Xr exec 2 .
+.Xr execve 2 .
+.It Li KERN_BOOTFILE
+The full pathname of the file from which the kernel was loaded.
.It Li KERN_BOOTTIME
A
.Va struct timeval
structure is returned.
This structure contains the time that the system was booted.
-.It Li KERN_CHOWN_RESTRICTED
-Return 1 if appropriate privileges are required for the
-.Xr chown 2
-system call, otherwise 0.
.It Li KERN_CLOCKRATE
A
.Va struct clockinfo
structure is returned.
This structure contains the clock, statistics clock and profiling clock
-frequencies, and the number of micro-seconds per hz tick.
+frequencies, the number of micro-seconds per hz tick and the skew rate.
.It Li KERN_FILE
Return the entire file table.
The returned data consists of a single
@@ -306,35 +308,38 @@ Get or set the host id.
Get or set the hostname.
.It Li KERN_JOB_CONTROL
Return 1 if job control is available on this system, otherwise 0.
-.It Li KERN_LINK_MAX
-The maximum file link count.
.It Li KERN_MAXFILES
-The maximum number of open files that may be open in the system.
+The maximum number of files that may be open in the system.
+.It Li KERN_MAXFILESPERPROC
+The maximum number of files that may be open for a single process.
+This limit only applies to processes with an effective uid of nonzero
+at the time of the open request.
+Files that have already been opened are not affected if the limit
+or the effective uid is changed.
.It Li KERN_MAXPROC
-The maximum number of simultaneous processes the system will allow.
+The maximum number of concurrent processes the system will allow.
+.It Li KERN_MAXPROCPERUID
+The maximum number of concurrent processes the system will allow
+for a single effective uid.
+This limit only applies to processes with an effective uid of nonzero
+at the time of a fork request.
+Processes that have already been started are not affected if the limit
+is changed.
.It Li KERN_MAXVNODES
The maximum number of vnodes available on the system.
-.It Li KERN_MAX_CANON
-The maximum number of bytes in terminal canonical input line.
-.It Li KERN_MAX_INPUT
-The minimum maximum number of bytes for which space is available in
-a terminal input queue.
-.It Li KERN_NAME_MAX
-The maximum number of bytes in a file name.
.It Li KERN_NGROUPS
The maximum number of supplemental groups.
-.It Li KERN_NO_TRUNC
-Return 1 if file names longer than KERN_NAME_MAX are truncated.
+.It Li KERN_NISDOMAINNAME
+The name of the current YP/NIS domain.
+.It Li KERN_OSRELDATE
+The system release date in YYYYMM format
+(January 1996 is encoded as 199601).
.It Li KERN_OSRELEASE
The system release string.
.It Li KERN_OSREV
The system revision string.
.It Li KERN_OSTYPE
The system type string.
-.It Li KERN_PATH_MAX
-The maximum number of bytes in a pathname.
-.It Li KERN_PIPE_BUF
-The maximum number of bytes which will be written atomically to a pipe.
.It Li KERN_POSIX1
The version of ISO/IEC 9945 (POSIX 1003.1) with which the system
attempts to comply.
@@ -395,8 +400,6 @@ Returns 1 if saved set-group and saved set-user ID is available.
The system security level.
This level may be raised by processes with appropriate privilege.
It may only be lowered by process 1.
-.It Li KERN_VDISABLE
-Returns the terminal character disabling value.
.It Li KERN_VERSION
The system version string.
.It Li KERN_VNODE
@@ -409,13 +412,23 @@ Each element of the array contains the kernel address of a vnode
.Va struct vnode *
followed by the vnode itself
.Va struct vnode .
+.It Li KERN_UPDATEINTERVAL
+The interval between
+.Xr sync 2
+calls in the
+.Xr update 4
+process.
.El
.Sh CTL_MACHDEP
The set of variables defined is architecture dependent.
-Most architectures define at least the following variables.
-.Bl -column "CONSOLE_DEVICEXXX" "integerXXX" -offset indent
+The following variables are defined for the i386 architecture.
+.Bl -column "CONSOLE_DEVICEXXX" "struct bootinfoXXX" -offset indent
.It Sy Pa Second level name Type Changeable
.It Li CPU_CONSDEV dev_t no
+.It Li CPU_ADJKERNTZ int yes
+.It Li CPU_DISRTCSET int yes
+.It Li CPU_BOOTINFO struct bootinfo no
+.It Li CPU_WALLCLOCK int yes
.El
.Sh CTL_NET
The string and integer information available for the CTL_NET level
@@ -600,7 +613,7 @@ The returned data consists of a
.El
.Sh RETURN VALUES
If the call to
-.Nm sysctl
+.Fn sysctl
is successful, the number of bytes copied out is returned.
Otherwise \-1 is returned and
.Va errno
@@ -666,5 +679,6 @@ definitions for fourth level UDP identifiers
.Xr sysctl 8
.Sh HISTORY
The
-.Nm sysctl
-function first appeared in 4.4BSD.
+.Fn sysctl
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/sysctl.c b/lib/libc/gen/sysctl.c
index f67a533..cb7448a 100644
--- a/lib/libc/gen/sysctl.c
+++ b/lib/libc/gen/sysctl.c
@@ -43,6 +43,7 @@ static char sccsid[] = "@(#)sysctl.c 8.2 (Berkeley) 1/4/94";
#include <paths.h>
#include <stdio.h>
#include <unistd.h>
+#include <string.h>
int
sysctl(name, namelen, oldp, oldlenp, newp, newlen)
diff --git a/lib/libc/gen/sysctlbyname.c b/lib/libc/gen/sysctlbyname.c
new file mode 100644
index 0000000..a3133af
--- /dev/null
+++ b/lib/libc/gen/sysctlbyname.c
@@ -0,0 +1,33 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
+ *
+ * $Id$
+ *
+ */
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+int
+sysctlbyname(char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
+{
+ int name2oid_oid[2];
+ int real_oid[CTL_MAXNAME+2];
+ int error, oidlen;
+
+ name2oid_oid[0] = 0; /* This is magic & undocumented! */
+ name2oid_oid[1] = 3;
+
+ oidlen = sizeof(real_oid);
+ error = sysctl(name2oid_oid, 2, real_oid, &oidlen, name, strlen(name));
+ if (error < 0)
+ return error;
+ oidlen /= sizeof (int);
+ error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen);
+ return (error);
+}
+
diff --git a/lib/libc/gen/syslog.3 b/lib/libc/gen/syslog.3
index 8a46d05..ab1bd9d 100644
--- a/lib/libc/gen/syslog.3
+++ b/lib/libc/gen/syslog.3
@@ -139,12 +139,12 @@ one or more of the following values:
If
.Fn syslog
cannot pass the message to
-.Xr syslogd
+.Xr syslogd 8
it will attempt to write the message to the console
.Pq Dq Pa /dev/console.
.It Dv LOG_NDELAY
Open the connection to
-.Xr syslogd
+.Xr syslogd 8
immediately.
Normally the open is delayed until the first message is logged.
Useful for programs that need to manage the order in which file
@@ -173,11 +173,15 @@ The same as
but logged to a file readable only by
selected individuals.
.It Dv LOG_CRON
-The clock daemon.
+The cron daemon:
+.Xr cron 8 .
.It Dv LOG_DAEMON
System daemons, such as
.Xr routed 8 ,
that are not provided for explicitly by other facilities.
+.It Dv LOG_FTP
+The file transfer protocol daemon:
+.Xr ftpd 8 .
.It Dv LOG_KERN
Messages generated by the kernel.
These cannot be generated by any user processes.
@@ -248,8 +252,10 @@ always returns the previous log mask level.
.Bd -literal -offset indent -compact
syslog(LOG_ALERT, "who: internal error 23");
-openlog("ftpd", LOG_PID, LOG_DAEMON);
+openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
+
setlogmask(LOG_UPTO(LOG_ERR));
+
syslog(LOG_INFO, "Connection from host %d", CallingHost);
syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c
index c18c776..0eb721e 100644
--- a/lib/libc/gen/syslog.c
+++ b/lib/libc/gen/syslog.c
@@ -32,7 +32,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+/*
static char sccsid[] = "@(#)syslog.c 8.5 (Berkeley) 4/29/95";
+*/
+static const char rcsid[] =
+ "$Id: syslog.c,v 1.12 1997/03/11 11:52:33 peter Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -57,12 +61,50 @@ static char sccsid[] = "@(#)syslog.c 8.5 (Berkeley) 4/29/95";
static int LogFile = -1; /* fd for log */
static int connected; /* have done connect */
+static int opened; /* have done openlog() */
static int LogStat = 0; /* status bits, set by openlog() */
static const char *LogTag = NULL; /* string to tag the entry with */
static int LogFacility = LOG_USER; /* default facility code */
static int LogMask = 0xff; /* mask of priorities to be logged */
extern char *__progname; /* Program name, from crt0. */
+static void disconnectlog __P((void)); /* disconnect from syslogd */
+static void connectlog __P((void)); /* (re)connect to syslogd */
+
+/*
+ * Format of the magic cookie passed through the stdio hook
+ */
+struct bufcookie {
+ char *base; /* start of buffer */
+ int left;
+};
+
+/*
+ * stdio write hook for writing to a static string buffer
+ * XXX: Maybe one day, dynamically allocate it so that the line length
+ * is `unlimited'.
+ */
+static
+int writehook(cookie, buf, len)
+ void *cookie; /* really [struct bufcookie *] */
+ char *buf; /* characters to copy */
+ int len; /* length to copy */
+{
+ struct bufcookie *h; /* private `handle' */
+
+ h = (struct bufcookie *)cookie;
+ if (len > h->left) {
+ /* clip in case of wraparound */
+ len = h->left;
+ }
+ if (len > 0) {
+ (void)memcpy(h->base, buf, len); /* `write' it. */
+ h->base += len;
+ h->left -= len;
+ }
+ return 0;
+}
+
/*
* syslog, vsyslog --
* print message on log file; output is intended for syslogd(8).
@@ -95,10 +137,13 @@ vsyslog(pri, fmt, ap)
va_list ap;
{
register int cnt;
- register char ch, *p, *t;
+ register char ch, *p;
time_t now;
int fd, saved_errno;
char *stdp, tbuf[2048], fmt_cpy[1024];
+ FILE *fp, *fmt_fp;
+ struct bufcookie tbuf_cookie;
+ struct bufcookie fmt_cookie;
#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
/* Check for invalid bits. */
@@ -118,35 +163,66 @@ vsyslog(pri, fmt, ap)
if ((pri & LOG_FACMASK) == 0)
pri |= LogFacility;
+ /* Create the primary stdio hook */
+ tbuf_cookie.base = tbuf;
+ tbuf_cookie.left = sizeof(tbuf);
+ fp = fwopen(&tbuf_cookie, writehook);
+ if (fp == NULL)
+ return;
+
/* Build the message. */
(void)time(&now);
- p = tbuf + sprintf(tbuf, "<%d>", pri);
- p += strftime(p, sizeof (tbuf) - (p - tbuf), "%h %e %T ",
- localtime(&now));
- if (LogStat & LOG_PERROR)
- stdp = p;
+ (void)fprintf(fp, "<%d>", pri);
+ (void)fprintf(fp, "%.15s ", ctime(&now) + 4);
+ if (LogStat & LOG_PERROR) {
+ /* Transfer to string buffer */
+ (void)fflush(fp);
+ stdp = tbuf + (sizeof(tbuf) - tbuf_cookie.left);
+ }
if (LogTag == NULL)
LogTag = __progname;
if (LogTag != NULL)
- p += sprintf(p, "%s", LogTag);
+ (void)fprintf(fp, "%s", LogTag);
if (LogStat & LOG_PID)
- p += sprintf(p, "[%d]", getpid());
+ (void)fprintf(fp, "[%d]", getpid());
if (LogTag != NULL) {
- *p++ = ':';
- *p++ = ' ';
+ (void)fprintf(fp, ": ");
+ }
+
+ /* Check to see if we can skip expanding the %m */
+ if (strstr(fmt, "%m")) {
+
+ /* Create the second stdio hook */
+ fmt_cookie.base = fmt_cpy;
+ fmt_cookie.left = sizeof(fmt_cpy) - 1;
+ fmt_fp = fwopen(&fmt_cookie, writehook);
+ if (fmt_fp == NULL) {
+ fclose(fp);
+ return;
+ }
+
+ /* Substitute error message for %m. */
+ for ( ; (ch = *fmt); ++fmt)
+ if (ch == '%' && fmt[1] == 'm') {
+ ++fmt;
+ fputs(strerror(saved_errno), fmt_fp);
+ } else
+ fputc(ch, fmt_fp);
+
+ /* Null terminate if room */
+ fputc(0, fmt_fp);
+ fclose(fmt_fp);
+
+ /* Guarantee null termination */
+ fmt_cpy[sizeof(fmt_cpy) - 1] = '\0';
+
+ fmt = fmt_cpy;
}
- /* Substitute error message for %m. */
- for (t = fmt_cpy; ch = *fmt; ++fmt)
- if (ch == '%' && fmt[1] == 'm') {
- ++fmt;
- t += sprintf(t, "%s", strerror(saved_errno));
- } else
- *t++ = ch;
- *t = '\0';
+ (void)vfprintf(fp, fmt, ap);
+ (void)fclose(fp);
- p += vsprintf(p, fmt_cpy, ap);
- cnt = p - tbuf;
+ cnt = sizeof(tbuf) - tbuf_cookie.left;
/* Output to stderr if requested. */
if (LogStat & LOG_PERROR) {
@@ -162,8 +238,18 @@ vsyslog(pri, fmt, ap)
}
/* Get connected, output the message to the local logger. */
- if (!connected)
+ if (!opened)
openlog(LogTag, LogStat | LOG_NDELAY, 0);
+ connectlog();
+ if (send(LogFile, tbuf, cnt, 0) >= 0)
+ return;
+
+ /*
+ * If the send() failed, the odds are syslogd was restarted.
+ * Make one (only) attempt to reconnect to /dev/log.
+ */
+ disconnectlog();
+ connectlog();
if (send(LogFile, tbuf, cnt, 0) >= 0)
return;
@@ -174,15 +260,69 @@ vsyslog(pri, fmt, ap)
*/
if (LogStat & LOG_CONS &&
(fd = open(_PATH_CONSOLE, O_WRONLY, 0)) >= 0) {
- (void)strcat(tbuf, "\r\n");
- cnt += 2;
- p = index(tbuf, '>') + 1;
- (void)write(fd, p, cnt - (p - tbuf));
+ struct iovec iov[2];
+ register struct iovec *v = iov;
+
+ p = strchr(tbuf, '>') + 1;
+ v->iov_base = p;
+ v->iov_len = cnt - (p - tbuf);
+ ++v;
+ v->iov_base = "\r\n";
+ v->iov_len = 2;
+ (void)writev(fd, iov, 2);
(void)close(fd);
}
}
+static void
+disconnectlog()
+{
+ /*
+ * If the user closed the FD and opened another in the same slot,
+ * that's their problem. They should close it before calling on
+ * system services.
+ */
+ if (LogFile != -1) {
+ close(LogFile);
+ LogFile = -1;
+ }
+ connected = 0; /* retry connect */
+}
+
+static void
+connectlog()
+{
+ struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
+
+ if (LogFile == -1) {
+ if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
+ return;
+ (void)fcntl(LogFile, F_SETFD, 1);
+ }
+ if (LogFile != -1 && !connected) {
+ SyslogAddr.sa_len = sizeof(SyslogAddr);
+ SyslogAddr.sa_family = AF_UNIX;
+ (void)strncpy(SyslogAddr.sa_data, _PATH_LOG,
+ sizeof(SyslogAddr.sa_data));
+ connected = connect(LogFile, &SyslogAddr,
+ sizeof(SyslogAddr)) != -1;
-static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
+ if (!connected) {
+ /*
+ * Try the old "/dev/log" path, for backward
+ * compatibility.
+ */
+ (void)strncpy(SyslogAddr.sa_data, _PATH_OLDLOG,
+ sizeof(SyslogAddr.sa_data));
+ connected = connect(LogFile, &SyslogAddr,
+ sizeof(SyslogAddr)) != -1;
+ }
+
+ if (!connected) {
+ (void)close(LogFile);
+ LogFile = -1;
+ }
+ }
+}
void
openlog(ident, logstat, logfac)
@@ -195,22 +335,10 @@ openlog(ident, logstat, logfac)
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));
- if (LogStat & LOG_NDELAY) {
- if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
- return;
- (void)fcntl(LogFile, F_SETFD, 1);
- }
- }
- if (LogFile != -1 && !connected)
- if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) == -1) {
- (void)close(LogFile);
- LogFile = -1;
- } else
- connected = 1;
+ if (LogStat & LOG_NDELAY) /* open immediately */
+ connectlog();
+
+ opened = 1; /* ident and facility has been set */
}
void
diff --git a/lib/libc/gen/tcgetpgrp.3 b/lib/libc/gen/tcgetpgrp.3
index e97c256..045c569 100644
--- a/lib/libc/gen/tcgetpgrp.3
+++ b/lib/libc/gen/tcgetpgrp.3
@@ -31,7 +31,7 @@
.\"
.\" @(#)tcgetpgrp.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd "June 4, 1993"
+.Dd June 4, 1993
.Dt TCGETPGRP 3
.Os
.Sh NAME
@@ -44,15 +44,15 @@
.Fn tcgetpgrp "int fd"
.Sh DESCRIPTION
The
-.Nm tcgetpgrp
+.Fn tcgetpgrp
function returns the value of the process group ID of the foreground
process group associated with the terminal device.
If there is no foreground process group,
-.Nm tcgetpgrp
+.Fn tcgetpgrp
returns an invalid process ID.
.Sh ERRORS
If an error occurs,
-.Nm tcgetpgrp
+.Fn tcgetpgrp
returns -1 and the global variable
.Va errno
is set to indicate the error, as follows:
@@ -68,12 +68,12 @@ underlying terminal device represented by
is not the controlling terminal.
.El
.Sh SEE ALSO
-.Xr setpgid 3 ,
+.Xr setpgid 2 ,
.Xr setsid 2 ,
.Xr tcsetpgrp 3
.Sh STANDARDS
The
-.Nm tcgetpgrp
+.Fn tcgetpgrp
function is expected to be compliant with the
.St -p1003.1-88
specification.
diff --git a/lib/libc/gen/tcsendbreak.3 b/lib/libc/gen/tcsendbreak.3
index 2ff9ece..1e80265 100644
--- a/lib/libc/gen/tcsendbreak.3
+++ b/lib/libc/gen/tcsendbreak.3
@@ -31,7 +31,7 @@
.\"
.\" @(#)tcsendbreak.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd "June 4, 1993"
+.Dd June 4, 1993
.Dt TCSENDBREAK 3
.Os
.Sh NAME
@@ -52,13 +52,13 @@
.Fn tcsendbreak "int fd" "int len"
.Sh DESCRIPTION
The
-.Nm tcdrain
+.Fn tcdrain
function waits until all output written to the terminal referenced by
.Fa fd
has been transmitted to the terminal.
.Pp
The
-.Nm tcflow
+.Fn tcflow
function suspends transmission of data to or the reception of data from
the terminal referenced by
.Fa fd
@@ -89,7 +89,7 @@ section of
.El
.Pp
The
-.Nm tcflush
+.Fn tcflush
function discards any data written to the terminal referenced by
.Fa fd
which has not been transmitted to the terminal, or any data received
@@ -108,7 +108,7 @@ Flush both data received but not read and data written but not transmitted.
.El
.Pp
The
-.Nm tcsendbreak
+.Fn tcsendbreak
function transmits a continuous stream of zero-valued bits for four-tenths
of a second to the terminal referenced by
.Fa fd .
@@ -136,7 +136,7 @@ The file associated with
is not a terminal.
.It Bq Er EINTR
A signal interrupted the
-.Nm tcdrain
+.Fn tcdrain
function.
.El
.Sh SEE ALSO
@@ -144,11 +144,11 @@ function.
.Xr termios 4
.Sh STANDARDS
The
-.Nm tcsendbreak ,
-.Nm tcdrain ,
-.Nm tcflush
+.Fn tcsendbreak ,
+.Fn tcdrain ,
+.Fn tcflush
and
-.Nm tcflow
+.Fn tcflow
functions are expected to be compliant with the
.St -p1003.1-88
specification.
diff --git a/lib/libc/gen/tcsetattr.3 b/lib/libc/gen/tcsetattr.3
index d3b2b4f..05dbe08 100644
--- a/lib/libc/gen/tcsetattr.3
+++ b/lib/libc/gen/tcsetattr.3
@@ -31,7 +31,7 @@
.\"
.\" @(#)tcsetattr.3 8.3 (Berkeley) 1/2/94
.\"
-.Dd "January 2, 1994"
+.Dd January 2, 1994
.Dt TCSETATTR 3
.Os
.Sh NAME
@@ -47,11 +47,11 @@
.Sh SYNOPSIS
.Fd #include <termios.h>
.Ft speed_t
-.Fn cfgetispeed "struct termios *t"
+.Fn cfgetispeed "const struct termios *t"
.Ft int
.Fn cfsetispeed "struct termios *t" "speed_t speed"
.Ft speed_t
-.Fn cfgetospeed "struct termios *t"
+.Fn cfgetospeed "const struct termios *t"
.Ft int
.Fn cfsetospeed "struct termios *t" "speed_t speed"
.Ft int
@@ -61,33 +61,33 @@
.Ft int
.Fn tcgetattr "int fd" "struct termios *t"
.Ft int
-.Fn tcsetattr "int fd" "int action" "struct termios *t"
+.Fn tcsetattr "int fd" "int action" "const struct termios *t"
.Sh DESCRIPTION
The
-.Nm cfmakeraw ,
-.Nm tcgetattr
+.Fn cfmakeraw ,
+.Fn tcgetattr
and
-.Nm tcsetattr
+.Fn tcsetattr
functions are provided for getting and setting the termios structure.
.Pp
The
-.Nm cfgetispeed ,
-.Nm cfsetispeed ,
-.Nm cfgetospeed ,
-.Nm cfsetospeed
+.Fn cfgetispeed ,
+.Fn cfsetispeed ,
+.Fn cfgetospeed ,
+.Fn cfsetospeed
and
-.Nm cfsetspeed
+.Fn cfsetspeed
functions are provided for getting and setting the baud rate values in
the termios structure.
The effects of the functions on the terminal as described below
do not become effective, nor are all errors detected, until the
-.Nm tcsetattr
+.Fn tcsetattr
function is called.
Certain values for baud rates set in the termios structure and passed to
-.Nm tcsetattr
+.Fn tcsetattr
have special meanings.
These are discussed in the portion of the manual page that describes the
-.Nm tcsetattr
+.Fn tcsetattr
function.
.Sh GETTING AND SETTING THE BAUD RATE
The input and output baud rates are found in the termios structure.
@@ -121,31 +121,31 @@ represented, however, the following symbolic values are defined.
.Ed
.Pp
The
-.Nm cfgetispeed
+.Fn cfgetispeed
function returns the input baud rate in the termios structure referenced by
.Fa tp .
.Pp
The
-.Nm cfsetispeed
+.Fn cfsetispeed
function sets the input baud rate in the termios structure referenced by
.Fa tp
to
.Fa speed .
.Pp
The
-.Nm cfgetospeed
+.Fn cfgetospeed
function returns the output baud rate in the termios structure referenced by
.Fa tp .
.Pp
The
-.Nm cfsetospeed
+.Fn cfsetospeed
function sets the output baud rate in the termios structure referenced by
.Fa tp
to
.Fa speed .
.Pp
The
-.Nm cfsetspeed
+.Fn cfsetspeed
function sets both the input and output baud rate in the termios structure
referenced by
.Fa tp
@@ -153,10 +153,10 @@ to
.Fa speed .
.Pp
Upon successful completion, the functions
-.Nm cfsetispeed ,
-.Nm cfsetospeed ,
+.Fn cfsetispeed ,
+.Fn cfsetospeed ,
and
-.Nm cfsetspeed
+.Fn cfsetspeed
return a value of 0.
Otherwise, a value of -1 is returned and the global variable
.Va errno
@@ -178,7 +178,7 @@ file, not just the open file description associated with the particular
file descriptor.
.Pp
The
-.Nm cfmakeraw
+.Fn cfmakeraw
function sets the flags stored in the termios structure to a state disabling
all input and output processing, giving a
.Dq raw I/O path.
@@ -186,17 +186,17 @@ It should be noted that there is no function to reverse this effect.
This is because there are a variety of processing options that could be
re-enabled and the correct method is for an application to snapshot the
current terminal state using the function
-.Nm tcgetattr ,
+.Fn tcgetattr ,
setting raw mode with
-.Nm cfmakeraw
+.Fn cfmakeraw
and the subsequent
-.Nm tcsetattr ,
+.Fn tcsetattr ,
and then using another
-.Nm tcsetattr
+.Fn tcsetattr
with the saved state to revert to the previous terminal state.
.Pp
The
-.Nm tcgetattr
+.Fn tcgetattr
function copies the parameters associated with the terminal referenced
by
.Fa fd
@@ -206,7 +206,7 @@ This function is allowed from a background process, however, the terminal
attributes may be subsequently changed by a foreground process.
.Pp
The
-.Nm tcsetattr
+.Fn tcsetattr
function sets the parameters associated with the terminal from the
termios structure referenced by
.Fa tp .
@@ -246,17 +246,17 @@ fields are ignored.
.Pp
The 0 baud rate is used to terminate the connection.
If 0 is specified as the output speed to the function
-.Nm tcsetattr ,
+.Fn tcsetattr ,
modem control will no longer be asserted on the terminal, disconnecting
the terminal.
.Pp
If zero is specified as the input speed to the function
-.Nm tcsetattr ,
+.Fn tcsetattr ,
the input baud rate will be set to the same value as that specified by
the output baud rate.
.Pp
If
-.Nm tcsetattr
+.Fn tcsetattr
is unable to make any of the requested changes, it returns -1 and
sets errno.
Otherwise, it makes all of the requested changes it can.
@@ -264,9 +264,9 @@ If the specified input and output baud rates differ and are a combination
that is not supported, neither baud rate is changed.
.Pp
Upon successful completion, the functions
-.Nm tcgetattr
+.Fn tcgetattr
and
-.Nm tcsetattr
+.Fn tcsetattr
return a value of 0.
Otherwise, they
return -1 and the global variable
@@ -277,28 +277,28 @@ is set to indicate the error, as follows:
The
.Fa fd
argument to
-.Nm tcgetattr
+.Fn tcgetattr
or
-.Nm tcsetattr
+.Fn tcsetattr
was not a valid file descriptor.
.It Bq Er EINTR
The
-.Nm tcsetattr
+.Fn tcsetattr
function was interrupted by a signal.
.It Bq Er EINVAL
The
.Fa action
argument to the
-.Nm tcsetattr
+.Fn tcsetattr
function was not valid, or an attempt was made to change an attribute
represented in the termios structure to an unsupported value.
.It Bq Er ENOTTY
The file associated with the
.Fa fd
argument to
-.Nm tcgetattr
+.Fn tcgetattr
or
-.Nm tcsetattr
+.Fn tcsetattr
is not a terminal.
.El
.Sh SEE ALSO
@@ -306,25 +306,25 @@ is not a terminal.
.Xr termios 4
.Sh STANDARDS
The
-.Nm cfgetispeed ,
-.Nm cfsetispeed ,
-.Nm cfgetospeed ,
-.Nm cfsetospeed ,
-.Nm tcgetattr
+.Fn cfgetispeed ,
+.Fn cfsetispeed ,
+.Fn cfgetospeed ,
+.Fn cfsetospeed ,
+.Fn tcgetattr
and
-.Nm tcsetattr
+.Fn tcsetattr
functions are expected to be compliant with the
.St -p1003.1-88
specification.
The
-.Nm cfmakeraw
+.Fn cfmakeraw
and
-.Nm cfsetspeed
+.Fn cfsetspeed
functions,
as well as the
.Li TCSASOFT
option to the
-.Nm tcsetattr
+.Fn tcsetattr
function are extensions to the
.St -p1003.1-88
specification.
diff --git a/lib/libc/gen/tcsetpgrp.3 b/lib/libc/gen/tcsetpgrp.3
index e1f8af0..684ec4c 100644
--- a/lib/libc/gen/tcsetpgrp.3
+++ b/lib/libc/gen/tcsetpgrp.3
@@ -31,7 +31,7 @@
.\"
.\" @(#)tcsetpgrp.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd "June 4, 1993"
+.Dd June 4, 1993
.Dt TCSETPGRP 3
.Os
.Sh NAME
@@ -89,7 +89,7 @@ argument does not match the process group ID of a process in the same
session as the calling process.
.El
.Sh SEE ALSO
-.Xr setpgid 3 ,
+.Xr setpgid 2 ,
.Xr setsid 2 ,
.Xr tcgetpgrp 3
.Sh STANDARDS
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c
index 979fee4..ab23d9d 100644
--- a/lib/libc/gen/telldir.c
+++ b/lib/libc/gen/telldir.c
@@ -49,7 +49,7 @@ static char sccsid[] = "@(#)telldir.c 8.1 (Berkeley) 6/4/93";
/*
* One of these structures is malloced to describe the current directory
- * position each time telldir is called. It records the current magic
+ * position each time telldir is called. It records the current magic
* cookie returned by getdirentries and the offset within the buffer
* associated with that return value.
*/
@@ -58,6 +58,7 @@ struct ddloc {
long loc_index; /* key associated with structure */
long loc_seek; /* magic cookie returned by getdirentries */
long loc_loc; /* offset of entry in buffer */
+ const DIR* loc_dirp; /* directory which used this entry */
};
#define NDIRHASH 32 /* Num of hash lists, must be a power of 2 */
@@ -82,6 +83,7 @@ telldir(dirp)
lp->loc_index = index;
lp->loc_seek = dirp->dd_seek;
lp->loc_loc = dirp->dd_loc;
+ lp->loc_dirp = dirp;
lp->loc_next = dd_hash[LOCHASH(index)];
dd_hash[LOCHASH(index)] = lp;
return (index);
@@ -126,3 +128,30 @@ found:
free((caddr_t)lp);
#endif
}
+
+/*
+ * Reclaim memory for telldir cookies which weren't used.
+ */
+void
+_reclaim_telldir(dirp)
+ register const DIR *dirp;
+{
+ register struct ddloc *lp;
+ register struct ddloc **prevlp;
+ int i;
+
+ for (i = 0; i < NDIRHASH; i++) {
+ prevlp = &dd_hash[i];
+ lp = *prevlp;
+ while (lp != NULL) {
+ if (lp->loc_dirp == dirp) {
+ *prevlp = lp->loc_next;
+ free((caddr_t)lp);
+ lp = *prevlp;
+ continue;
+ }
+ prevlp = &lp->loc_next;
+ lp = lp->loc_next;
+ }
+ }
+}
diff --git a/lib/libc/gen/termios.c b/lib/libc/gen/termios.c
index a99d86f..5264a2d 100644
--- a/lib/libc/gen/termios.c
+++ b/lib/libc/gen/termios.c
@@ -36,15 +36,11 @@ static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
+#include <sys/fcntl.h>
#include <sys/ioctl.h>
-#include <sys/tty.h>
#include <sys/time.h>
-#define KERNEL /* XXX - FREAD and FWRITE ifdef'd KERNEL*/
-#include <sys/fcntl.h>
-#undef KERNEL
#include <errno.h>
-#include <stdio.h>
#include <termios.h>
#include <unistd.h>
@@ -99,6 +95,7 @@ tcsetpgrp(fd, pgrp)
pid_t
tcgetpgrp(fd)
+ int fd;
{
int s;
@@ -163,14 +160,17 @@ cfmakeraw(t)
struct termios *t;
{
- t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
+ t->c_iflag &= ~(IMAXBEL|IXOFF|INPCK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IGNPAR);
+ t->c_iflag |= IGNBRK;
t->c_oflag &= ~OPOST;
- t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
+ t->c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|IEXTEN|NOFLSH|TOSTOP|PENDIN);
t->c_cflag &= ~(CSIZE|PARENB);
- t->c_cflag |= CS8;
- /* XXX set MIN/TIME */
+ t->c_cflag |= CS8|CREAD;
+ t->c_cc[VMIN] = 1;
+ t->c_cc[VTIME] = 0;
}
+int
tcsendbreak(fd, len)
int fd, len;
{
@@ -186,6 +186,7 @@ tcsendbreak(fd, len)
return (0);
}
+int
tcdrain(fd)
int fd;
{
@@ -193,6 +194,7 @@ tcdrain(fd)
return (ioctl(fd, TIOCDRAIN, 0));
}
+int
tcflush(fd, which)
int fd, which;
{
@@ -215,6 +217,7 @@ tcflush(fd, which)
return (ioctl(fd, TIOCFLUSH, &com));
}
+int
tcflow(fd, action)
int fd, action;
{
diff --git a/lib/libc/gen/time.3 b/lib/libc/gen/time.3
index 1343836..ecf767d 100644
--- a/lib/libc/gen/time.3
+++ b/lib/libc/gen/time.3
@@ -42,7 +42,7 @@
.Nm time
.Nd get time of day
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
+.Fd #include <time.h>
.Ft time_t
.Fn time "time_t *tloc"
.Sh DESCRIPTION
diff --git a/lib/libc/gen/times.3 b/lib/libc/gen/times.3
index 93207b1..4bf6689 100644
--- a/lib/libc/gen/times.3
+++ b/lib/libc/gen/times.3
@@ -127,7 +127,8 @@ and
.Xr time 1 ,
.Xr getrusage 2 ,
.Xr gettimeofday 2 ,
-.Xr wait 2
+.Xr wait 2 ,
+.Xr clocks 7
.Sh STANDARDS
The
.Fn times
diff --git a/lib/libc/gen/timezone.3 b/lib/libc/gen/timezone.3
index 68adeb9..d7ac13c 100644
--- a/lib/libc/gen/timezone.3
+++ b/lib/libc/gen/timezone.3
@@ -31,7 +31,7 @@
.\"
.\" @(#)timezone.3 8.2 (Berkeley) 4/19/94
.\"
-.Dd "April 19, 1994"
+.Dd April 19, 1994
.Dt TIMEZONE 3
.Os
.Sh NAME
diff --git a/lib/libc/gen/timezone.c b/lib/libc/gen/timezone.c
index 9ce6142..fe3ce23 100644
--- a/lib/libc/gen/timezone.c
+++ b/lib/libc/gen/timezone.c
@@ -40,7 +40,7 @@ static char sccsid[] = "@(#)timezone.c 8.1 (Berkeley) 6/4/93";
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <tzfile.h>
+#define TZ_MAX_CHARS 255
char *_tztab();
@@ -62,8 +62,8 @@ timezone(zone, dst)
register char *beg,
*end;
- if (beg = getenv("TZNAME")) { /* set in environment */
- if (end = index(beg, ',')) { /* "PST,PDT" */
+ if ( (beg = getenv("TZNAME")) ) { /* set in environment */
+ if ( (end = index(beg, ',')) ) {/* "PST,PDT" */
if (dst)
return(++end);
*end = '\0';
@@ -82,22 +82,22 @@ static struct zone {
char *stdzone;
char *dlzone;
} zonetab[] = {
- -1*60, "MET", "MET DST", /* Middle European */
- -2*60, "EET", "EET DST", /* Eastern European */
- 4*60, "AST", "ADT", /* Atlantic */
- 5*60, "EST", "EDT", /* Eastern */
- 6*60, "CST", "CDT", /* Central */
- 7*60, "MST", "MDT", /* Mountain */
- 8*60, "PST", "PDT", /* Pacific */
+ {-1*60, "MET", "MET DST"}, /* Middle European */
+ {-2*60, "EET", "EET DST"}, /* Eastern European */
+ {4*60, "AST", "ADT"}, /* Atlantic */
+ {5*60, "EST", "EDT"}, /* Eastern */
+ {6*60, "CST", "CDT"}, /* Central */
+ {7*60, "MST", "MDT"}, /* Mountain */
+ {8*60, "PST", "PDT"}, /* Pacific */
#ifdef notdef
/* there's no way to distinguish this from WET */
- 0, "GMT", 0, /* Greenwich */
+ {0, "GMT", 0}, /* Greenwich */
#endif
- 0*60, "WET", "WET DST", /* Western European */
- -10*60, "EST", "EST", /* Aust: Eastern */
- -10*60+30, "CST", "CST", /* Aust: Central */
- -8*60, "WST", 0, /* Aust: Western */
- -1
+ {0*60, "WET", "WET DST"}, /* Western European */
+ {-10*60,"EST", "EST"}, /* Aust: Eastern */
+ {-10*60+30,"CST", "CST"}, /* Aust: Central */
+ {-8*60, "WST", 0}, /* Aust: Western */
+ {-1}
};
/*
diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c
index 2f47bd6..b2f3f79 100644
--- a/lib/libc/gen/ttyname.c
+++ b/lib/libc/gen/ttyname.c
@@ -39,11 +39,122 @@ static char sccsid[] = "@(#)ttyname.c 8.2 (Berkeley) 1/27/94";
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
-#include <sgtty.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
#include <db.h>
#include <string.h>
#include <paths.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+static struct pthread_mutex _ttyname_lockd = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t ttyname_lock = &_ttyname_lockd;
+static pthread_key_t ttyname_key;
+static int ttyname_init = 0;
+
+char *
+ttyname(int fd)
+{
+ char *ret;
+
+ if (_thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__) == 0) {
+ ret = __ttyname_basic(fd);
+ _thread_fd_unlock(fd, FD_READ);
+ } else {
+ ret = NULL;
+ }
+
+ return (ret);
+}
+
+char *
+__ttyname_r_basic(int fd, char *buf, size_t len)
+{
+ register struct dirent *dirp;
+ register DIR *dp;
+ struct stat dsb;
+ struct stat sb;
+ char *rval;
+ int minlen;
+
+ rval = NULL;
+
+ /* Must be a terminal. */
+ if (!isatty(fd))
+ return (rval);
+ /* Must be a character device. */
+ if (_thread_sys_fstat(fd, &sb) || !S_ISCHR(sb.st_mode))
+ return (rval);
+ /* Must have enough room */
+ if (len <= sizeof(_PATH_DEV))
+ return (rval);
+
+ if ((dp = opendir(_PATH_DEV)) != NULL) {
+ memcpy(buf, _PATH_DEV, sizeof(_PATH_DEV));
+ for (rval = NULL; (dirp = readdir(dp)) != NULL;) {
+ if (dirp->d_fileno != sb.st_ino)
+ continue;
+ minlen = (len - (sizeof(_PATH_DEV) - 1)) < (dirp->d_namlen + 1) ?
+ (len - (sizeof(_PATH_DEV) - 1)) : (dirp->d_namlen + 1);
+ memcpy(buf + sizeof(_PATH_DEV) - 1, dirp->d_name, minlen);
+ if (stat(buf, &dsb) || sb.st_dev != dsb.st_dev ||
+ sb.st_ino != dsb.st_ino)
+ continue;
+ rval = buf;
+ break;
+ }
+ (void) closedir(dp);
+ }
+ return (rval);
+}
+
+char *
+__ttyname_basic(int fd)
+{
+ char *buf;
+
+ pthread_mutex_lock(&ttyname_lock);
+ if (ttyname_init == 0) {
+ if (pthread_key_create(&ttyname_key, free)) {
+ pthread_mutex_unlock(&ttyname_lock);
+ return (NULL);
+ }
+ ttyname_init = 1;
+ }
+ pthread_mutex_unlock(&ttyname_lock);
+
+ /* Must have thread specific data field to put data */
+ if ((buf = pthread_getspecific(ttyname_key)) != 0) {
+ return (NULL);
+ } else if (buf == NULL) {
+ if ((buf = malloc(sizeof(_PATH_DEV) + MAXNAMLEN)) != NULL) {
+ if (pthread_setspecific(ttyname_key, buf) != 0) {
+ free(buf);
+ return (NULL);
+ }
+ } else {
+ return (NULL);
+ }
+ }
+ return (__ttyname_r_basic(fd, buf, sizeof(_PATH_DEV) + MAXNAMLEN));
+}
+
+char *
+ttyname_r(int fd, char *buf, size_t len)
+{
+ char *ret;
+
+ if (_thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__) == 0) {
+ ret = __ttyname_r_basic(fd, buf, len);
+ _thread_fd_unlock(fd, FD_READ);
+ } else {
+ ret = NULL;
+ }
+ return (ret);
+}
+#else
static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV;
static char *oldttyname __P((int, struct stat *));
@@ -52,7 +163,7 @@ ttyname(fd)
int fd;
{
struct stat sb;
- struct sgttyb ttyb;
+ struct termios ttyb;
DB *db;
DBT data, key;
struct {
@@ -61,13 +172,13 @@ ttyname(fd)
} bkey;
/* Must be a terminal. */
- if (ioctl(fd, TIOCGETP, &ttyb) < 0)
+ if (tcgetattr(fd, &ttyb) < 0)
return (NULL);
/* Must be a character device. */
if (fstat(fd, &sb) || !S_ISCHR(sb.st_mode))
return (NULL);
- if (db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL)) {
+ if ( (db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL)) ) {
memset(&bkey, 0, sizeof(bkey));
bkey.type = S_IFCHR;
bkey.dev = sb.st_rdev;
@@ -96,7 +207,7 @@ oldttyname(fd, sb)
if ((dp = opendir(_PATH_DEV)) == NULL)
return (NULL);
- while (dirp = readdir(dp)) {
+ while ( (dirp = readdir(dp)) ) {
if (dirp->d_fileno != sb->st_ino)
continue;
bcopy(dirp->d_name, buf + sizeof(_PATH_DEV) - 1,
@@ -110,3 +221,4 @@ oldttyname(fd, sb)
(void)closedir(dp);
return (NULL);
}
+#endif
diff --git a/lib/libc/gen/ttyslot.c b/lib/libc/gen/ttyslot.c
index 3d9fee6..2f72ebb 100644
--- a/lib/libc/gen/ttyslot.c
+++ b/lib/libc/gen/ttyslot.c
@@ -50,13 +50,13 @@ ttyslot()
char *name;
setttyent();
- for (cnt = 0; cnt < 3; ++cnt)
- if (name = ttyname(cnt)) {
- if (p = rindex(name, '/'))
+ for (cnt = 0; cnt < 3; ++cnt)
+ if ( (name = ttyname(cnt)) ) {
+ if ( (p = rindex(name, '/')) )
++p;
else
p = name;
- for (slot = 1; ttyp = getttyent(); ++slot)
+ for (slot = 1; (ttyp = getttyent()); ++slot)
if (!strcmp(ttyp->ty_name, p)) {
endttyent();
return(slot);
diff --git a/lib/libc/gen/tzset.3 b/lib/libc/gen/tzset.3
index d9606c5..3c5b276 100644
--- a/lib/libc/gen/tzset.3
+++ b/lib/libc/gen/tzset.3
@@ -318,7 +318,8 @@ leap seconds are loaded from
.Xr tzfile 5
.Sh HISTORY
The
-.Nm tzset
+.Fn tzset
and
-.Nm tzsetwall
-functions first appeared in 4.4BSD.
+.Fn tzsetwall
+functions first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/ualarm.3 b/lib/libc/gen/ualarm.3
index 666029a..958dda5 100644
--- a/lib/libc/gen/ualarm.3
+++ b/lib/libc/gen/ualarm.3
@@ -29,7 +29,8 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)ualarm.3 8.2 (Berkeley) 4/19/94
+.\" From: @(#)ualarm.3 8.2 (Berkeley) 4/19/94
+.\" $Id$
.\"
.Dd April 19, 1994
.Dt UALARM 3
@@ -68,7 +69,7 @@ microseconds after the timer expires (e.g. after
microseconds have passed).
.Sh RETURN VALUES
When the signal has successfully been caught,
-.Fn alarm
+.Fn ualarm
returns the amount of time left on the clock.
The maximum number of
.Ar microseconds
@@ -79,9 +80,9 @@ is 2147483647.
.Xr setitimer 2 ,
.Xr sigpause 2 ,
.Xr sigvec 2 ,
+.Xr alarm 3 ,
.Xr signal 3 ,
.Xr sleep 3 ,
-.Xr alarm 3 ,
.Xr usleep 3
.Sh HISTORY
The
diff --git a/lib/libc/gen/ualarm.c b/lib/libc/gen/ualarm.c
index e9e051d..ec49a2d 100644
--- a/lib/libc/gen/ualarm.c
+++ b/lib/libc/gen/ualarm.c
@@ -54,7 +54,7 @@ ualarm(usecs, reload)
new.it_interval.tv_usec = reload % USPS;
new.it_interval.tv_sec = reload / USPS;
-
+
new.it_value.tv_usec = usecs % USPS;
new.it_value.tv_sec = usecs / USPS;
diff --git a/lib/libc/gen/uname.3 b/lib/libc/gen/uname.3
index a72e21f..8155289 100644
--- a/lib/libc/gen/uname.3
+++ b/lib/libc/gen/uname.3
@@ -31,7 +31,7 @@
.\"
.\" @(#)uname.3 8.1 (Berkeley) 1/4/94
.\"
-.Dd "January 4, 1994"
+.Dd January 4, 1994
.Dt UNAME 3
.Os
.Sh NAME
@@ -67,7 +67,7 @@ Machine hardware platform.
.El
.Sh RETURN VALUES
If
-.Nm uname
+.Fn uname
is successful, 0 is returned, otherwise, -1 is returned and
.Va errno
is set appropriately.
@@ -88,5 +88,6 @@ function conforms to
.St -p1003.1-88 .
.Sh HISTORY
The
-.Nm uname
-function first appeared in 4.4BSD.
+.Fn uname
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/uname.c b/lib/libc/gen/uname.c
index 9857b29..25431d4 100644
--- a/lib/libc/gen/uname.c
+++ b/lib/libc/gen/uname.c
@@ -32,12 +32,15 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)uname.c 8.1 (Berkeley) 1/4/94";
+/*static char sccsid[] = "From: @(#)uname.c 8.1 (Berkeley) 1/4/94";*/
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/utsname.h>
+#include <errno.h>
int
uname(name)
@@ -46,45 +49,77 @@ uname(name)
int mib[2], rval;
size_t len;
char *p;
+ int oerrno;
rval = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_OSTYPE;
len = sizeof(name->sysname);
- if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1)
- rval = -1;
+ oerrno = errno;
+ if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1) {
+ if(errno == ENOMEM)
+ errno = oerrno;
+ else
+ rval = -1;
+ }
+ name->sysname[sizeof(name->sysname) - 1] = '\0';
mib[0] = CTL_KERN;
mib[1] = KERN_HOSTNAME;
len = sizeof(name->nodename);
- if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1)
- rval = -1;
+ oerrno = errno;
+ if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1) {
+ if(errno == ENOMEM)
+ errno = oerrno;
+ else
+ rval = -1;
+ }
+ name->nodename[sizeof(name->nodename) - 1] = '\0';
mib[0] = CTL_KERN;
mib[1] = KERN_OSRELEASE;
len = sizeof(name->release);
- if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1)
- rval = -1;
+ oerrno = errno;
+ if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1) {
+ if(errno == ENOMEM)
+ errno = oerrno;
+ else
+ rval = -1;
+ }
+ name->release[sizeof(name->release) - 1] = '\0';
/* The version may have newlines in it, turn them into spaces. */
mib[0] = CTL_KERN;
mib[1] = KERN_VERSION;
len = sizeof(name->version);
- if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1)
- rval = -1;
- else
- for (p = name->version; len--; ++p)
- if (*p == '\n' || *p == '\t')
- if (len > 1)
- *p = ' ';
- else
- *p = '\0';
+ oerrno = errno;
+ if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) {
+ if (errno == ENOMEM)
+ errno = oerrno;
+ else
+ rval = -1;
+ }
+ name->version[sizeof(name->version) - 1] = '\0';
+ for (p = name->version; len--; ++p) {
+ if (*p == '\n' || *p == '\t') {
+ if (len > 1)
+ *p = ' ';
+ else
+ *p = '\0';
+ }
+ }
mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
len = sizeof(name->machine);
- if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1)
- rval = -1;
+ oerrno = errno;
+ if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) {
+ if (errno == ENOMEM)
+ errno = oerrno;
+ else
+ rval = -1;
+ }
+ name->machine[sizeof(name->machine) - 1] = '\0';
return (rval);
}
diff --git a/lib/libc/gen/unvis.3 b/lib/libc/gen/unvis.3
index 807a851..833e13c 100644
--- a/lib/libc/gen/unvis.3
+++ b/lib/libc/gen/unvis.3
@@ -41,9 +41,9 @@
.Sh SYNOPSIS
.Fd #include <vis.h>
.Ft int
-.Fn unvis "u_char *cp" "u_char c" "int *astate" "int flag"
+.Fn unvis "char *cp" "int c" "int *astate" "int flag"
.Ft int
-.Fn strunvis "char *dst" "char *src"
+.Fn strunvis "char *dst" "const char *src"
.Sh DESCRIPTION
The
.Fn unvis
@@ -100,7 +100,7 @@ to zero. Call
with each successive byte, along with a pointer
to this integer, and a pointer to a destination character.
The
-.Xr unvis
+.Fn unvis
function
has several return codes that must be handled properly. They are:
.Bl -tag -width UNVIS_VALIDPUSH
@@ -159,4 +159,5 @@ if (unvis(&out, (char)0, &state, UNVIS_END) == UNVIS_VALID)
The
.Nm unvis
function
-first appeared in 4.4BSD.
+first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/unvis.c b/lib/libc/gen/unvis.c
index 6126d6a..32405df 100644
--- a/lib/libc/gen/unvis.c
+++ b/lib/libc/gen/unvis.c
@@ -36,7 +36,6 @@ static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
-#include <ctype.h>
#include <vis.h>
/*
@@ -65,7 +64,7 @@ unvis(cp, c, astate, flag)
if (*astate == S_OCTAL2 || *astate == S_OCTAL3) {
*astate = S_GROUND;
return (UNVIS_VALID);
- }
+ }
return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD);
}
@@ -76,7 +75,7 @@ unvis(cp, c, astate, flag)
if (c == '\\') {
*astate = S_START;
return (0);
- }
+ }
*cp = c;
return (UNVIS_VALID);
@@ -149,7 +148,7 @@ unvis(cp, c, astate, flag)
}
*astate = S_GROUND;
return (UNVIS_SYNBAD);
-
+
case S_META:
if (c == '-')
*astate = S_META1;
@@ -160,12 +159,12 @@ unvis(cp, c, astate, flag)
return (UNVIS_SYNBAD);
}
return (0);
-
+
case S_META1:
*astate = S_GROUND;
*cp |= c;
return (UNVIS_VALID);
-
+
case S_CTRL:
if (c == '?')
*cp |= 0177;
@@ -176,15 +175,15 @@ unvis(cp, c, astate, flag)
case S_OCTAL2: /* second possible octal digit */
if (isoctal(c)) {
- /*
- * yes - and maybe a third
+ /*
+ * yes - and maybe a third
*/
*cp = (*cp << 3) + (c - '0');
- *astate = S_OCTAL3;
+ *astate = S_OCTAL3;
return (0);
- }
- /*
- * no - done with current sequence, push back passed char
+ }
+ /*
+ * no - done with current sequence, push back passed char
*/
*astate = S_GROUND;
return (UNVIS_VALIDPUSH);
@@ -199,10 +198,10 @@ unvis(cp, c, astate, flag)
* we were done, push back passed char
*/
return (UNVIS_VALIDPUSH);
-
- default:
- /*
- * decoder in unknown state - (probably uninitialized)
+
+ default:
+ /*
+ * decoder in unknown state - (probably uninitialized)
*/
*astate = S_GROUND;
return (UNVIS_SYNBAD);
@@ -210,7 +209,7 @@ unvis(cp, c, astate, flag)
}
/*
- * strunvis - decode src into dst
+ * strunvis - decode src into dst
*
* Number of chars decoded into dst is returned, -1 on error.
* Dst is null terminated.
@@ -225,7 +224,7 @@ strunvis(dst, src)
char *start = dst;
int state = 0;
- while (c = *src++) {
+ while ( (c = *src++) ) {
again:
switch (unvis(dst, c, &state, 0)) {
case UNVIS_VALID:
diff --git a/lib/libc/gen/usleep.3 b/lib/libc/gen/usleep.3
index 630e386..66b317a 100644
--- a/lib/libc/gen/usleep.3
+++ b/lib/libc/gen/usleep.3
@@ -72,12 +72,12 @@ such a function would not restart after signals, but would not interfere
with other uses of
.Xr setitimer .
.Sh SEE ALSO
-.Xr setitimer 2 ,
.Xr getitimer 2 ,
+.Xr setitimer 2 ,
.Xr sigpause 2 ,
-.Xr ualarm 3 ,
+.Xr alarm 3 ,
.Xr sleep 3 ,
-.Xr alarm 3
+.Xr ualarm 3
.Sh HISTORY
The
.Fn usleep
diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c
index 9127bfc..4bcb7e9 100644
--- a/lib/libc/gen/usleep.c
+++ b/lib/libc/gen/usleep.c
@@ -36,64 +36,88 @@ static char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/time.h>
-#include <sys/signal.h>
+#include <signal.h>
#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
-#define TICK 10000 /* system clock resolution in microseconds */
-#define USPS 1000000 /* number of microseconds in a second */
-
-#define setvec(vec, a) \
- vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0
+#ifndef _THREAD_SAFE
+static void
+sleephandler()
+{
+ return;
+}
+#endif /* _THREAD_SAFE */
-static int ringring;
void
usleep(useconds)
unsigned int useconds;
{
- register struct itimerval *itp;
- struct itimerval itv, oitv;
- struct sigvec vec, ovec;
- long omask;
- static void sleephandler();
+#ifdef _THREAD_SAFE
+ struct timespec time_to_sleep;
+ struct timespec time_remaining;
- itp = &itv;
- if (!useconds)
- return;
- timerclear(&itp->it_interval);
- timerclear(&itp->it_value);
- if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
- return;
- itp->it_value.tv_sec = useconds / USPS;
- itp->it_value.tv_usec = useconds % USPS;
- if (timerisset(&oitv.it_value)) {
- if (timercmp(&oitv.it_value, &itp->it_value, >)) {
- oitv.it_value.tv_sec -= itp->it_value.tv_sec;
- oitv.it_value.tv_usec -= itp->it_value.tv_usec;
- if (oitv.it_value.tv_usec < 0) {
- oitv.it_value.tv_usec += USPS;
- oitv.it_value.tv_sec--;
- }
- } else {
- itp->it_value = oitv.it_value;
- oitv.it_value.tv_sec = 0;
- oitv.it_value.tv_usec = 2 * TICK;
- }
+ if (useconds) {
+ time_to_sleep.tv_nsec = (useconds % 1000000) * 1000;
+ time_to_sleep.tv_sec = useconds / 1000000;
+ do {
+ nanosleep(&time_to_sleep, &time_remaining);
+ time_to_sleep = time_remaining;
+ } while (time_to_sleep.tv_sec != 0 &&
+ time_to_sleep.tv_nsec != 0);
}
- setvec(vec, sleephandler);
- (void) sigvec(SIGALRM, &vec, &ovec);
- omask = sigblock(sigmask(SIGALRM));
- ringring = 0;
- (void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0);
- while (!ringring)
- sigpause(omask &~ sigmask(SIGALRM));
- (void) sigvec(SIGALRM, &ovec, (struct sigvec *)0);
- (void) sigsetmask(omask);
- (void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0);
-}
+#else
+ struct timespec time_to_sleep;
+ struct timespec time_remaining;
+ struct sigaction act, oact;
+ sigset_t mask, omask;
+ int alarm_blocked;
-static void
-sleephandler()
-{
- ringring = 1;
+ if (useconds != 0) {
+ time_to_sleep.tv_nsec = (useconds % 1000000) * 1000;
+ time_to_sleep.tv_sec = useconds / 1000000;
+
+ /* Block SIGALRM while fiddling with it */
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGALRM);
+ sigprocmask(SIG_BLOCK, &mask, &omask);
+
+ /* Was SIGALRM blocked already? */
+ alarm_blocked = sigismember(&omask, SIGALRM);
+
+ if (!alarm_blocked) {
+ /*
+ * Set up handler to interrupt signanosleep only if
+ * SIGALRM was unblocked. (Save some syscalls)
+ */
+ memset(&act, 0, sizeof(act));
+ act.sa_handler = sleephandler;
+ sigaction(SIGALRM, &act, &oact);
+ }
+
+ /*
+ * signanosleep() uses the given mask for the lifetime of
+ * the syscall only - it resets on return. Note that the
+ * Old sleep explicitly unblocks SIGALRM during the sleep,
+ * we don't do that now since we don't depend on SIGALRM
+ * to end the timout. If the process blocks SIGALRM, it
+ * gets what it asks for.
+ */
+
+ do {
+ signanosleep(&time_to_sleep, &time_remaining, &mask);
+ time_to_sleep = time_remaining;
+ } while (time_to_sleep.tv_sec != 0 &&
+ time_to_sleep.tv_nsec != 0);
+
+ if (!alarm_blocked) {
+ /* Unwind */
+ sigaction(SIGALRM, &oact, (struct sigaction *)0);
+ sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
+ }
+ }
+#endif /* _THREAD_SAFE */
}
diff --git a/lib/libc/gen/utime.3 b/lib/libc/gen/utime.3
index 3397bb7..785a945 100644
--- a/lib/libc/gen/utime.3
+++ b/lib/libc/gen/utime.3
@@ -73,8 +73,8 @@ function may fail and set
for any of the errors specified for the library function
.Xr utimes 2 .
.Sh SEE ALSO
-.Xr utimes 2 ,
-.Xr stat 2
+.Xr stat 2 ,
+.Xr utimes 2
.Sh HISTORY
A
.Fn utime
@@ -82,6 +82,6 @@ function appeared in
.At v7 .
.Sh STANDARDS
The
-.Nm utime
+.Fn utime
function conforms to
.St -p1003.1-88 .
diff --git a/lib/libc/gen/valloc.3 b/lib/libc/gen/valloc.3
index c428552..ee32438 100644
--- a/lib/libc/gen/valloc.3
+++ b/lib/libc/gen/valloc.3
@@ -39,8 +39,8 @@
.Nd aligned memory allocation function
.Sh SYNOPSIS
.Fd #include <unistd.h>
-.Ft char *
-.Fn valloc "unsigned size"
+.Ft void *
+.Fn valloc "size_t size"
.Sh DESCRIPTION
.Bf -symbolic
Valloc is obsoleted by the current version of malloc(3),
diff --git a/lib/libc/gen/vis.3 b/lib/libc/gen/vis.3
index ee77b72..f749573 100644
--- a/lib/libc/gen/vis.3
+++ b/lib/libc/gen/vis.3
@@ -29,9 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)vis.3 8.1 (Berkeley) 6/9/93
+.\" From: @(#)vis.3 8.1 (Berkeley) 6/9/93
+.\" $Id: vis.3,v 1.6 1997/02/22 14:58:21 peter Exp $
.\"
-.Dd June 9, 1993
+.Dd July 25, 1996
.Dt VIS 3
.Os
.Sh NAME
@@ -40,11 +41,11 @@
.Sh SYNOPSIS
.Fd #include <vis.h>
.Ft char *
-.Fn vis "char *dst" "char c" "int flag" "char nextc"
+.Fn vis "char *dst" "int c" "int flag" "int nextc"
.Ft int
-.Fn strvis "char *dst" "char *src" "int flag"
+.Fn strvis "char *dst" "const char *src" "int flag"
.Ft int
-.Fn strvisx "char *dst" "char *src" "int len" "int flag"
+.Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
.Sh DESCRIPTION
The
.Fn vis
@@ -59,11 +60,11 @@ needs no encoding, it is copied in unaltered. The string is
null terminated, and a pointer to the end of the string is
returned. The maximum length of any encoding is four
characters (not including the trailing
-.Dv NULL ) ;
+.Dv NUL ) ;
thus, when
encoding a set of characters into a buffer, the size of the buffer should
be four times the number of characters encoded, plus one for the trailing
-.Dv NULL .
+.Dv NUL .
The flag parameter is used for altering the default range of
characters considered for encoding and for altering the visual
representation.
@@ -88,7 +89,7 @@ function encodes characters from
.Fa src
up to the
first
-.Dv NULL .
+.Dv NUL .
The
.Fn strvisx
function encodes exactly
@@ -97,9 +98,9 @@ characters from
.Fa src
(this
is useful for encoding a block of data that may contain
-.Dv NULL Ns 's).
+.Dv NUL Ns 's).
Both forms
-.Dv NULL
+.Dv NUL
terminate
.Fa dst .
The size of
@@ -108,13 +109,13 @@ must be four times the number
of characters encoded from
.Fa src
(plus one for the
-.Dv NULL ) .
+.Dv NUL ) .
Both
forms return the number of characters in dst (not including
the trailing
-.Dv NULL ) .
+.Dv NUL ) .
.Pp
-The encoding is a unique, invertible representation comprised entirely of
+The encoding is a unique, invertible representation composed entirely of
graphic characters; it can be decoded back into the original form using
the
.Xr unvis 3
@@ -226,7 +227,7 @@ The following sequences are used to represent the indicated characters:
.Pp
When using this format, the nextc parameter is looked at to determine
if a
-.Dv NULL
+.Dv NUL
character can be encoded as
.Ql \e0
instead of
@@ -256,8 +257,9 @@ With this flag set, the encoding is
ambiguous and non-invertible.
.Sh SEE ALSO
.Xr unvis 1 ,
+.Xr strunvis 3 ,
.Xr unvis 3
-.Xr strunvis 3
.Sh HISTORY
-These functions first appeared in 4.4BSD.
+These functions first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c
index 2232149..61aa836 100644
--- a/lib/libc/gen/vis.c
+++ b/lib/libc/gen/vis.c
@@ -51,7 +51,8 @@ vis(dst, c, flag, nextc)
int c, nextc;
register int flag;
{
- if ((u_int)c <= UCHAR_MAX && isgraph(c) ||
+ c = (unsigned char)c;
+ if (isgraph(c) ||
((flag & VIS_SP) == 0 && c == ' ') ||
((flag & VIS_TAB) == 0 && c == '\t') ||
((flag & VIS_NL) == 0 && c == '\n') ||
@@ -111,7 +112,7 @@ vis(dst, c, flag, nextc)
goto done;
}
}
- if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) {
+ if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) {
*dst++ = '\\';
*dst++ = ((u_char)c >> 6 & 07) + '0';
*dst++ = ((u_char)c >> 3 & 07) + '0';
@@ -141,10 +142,10 @@ done:
/*
* strvis, strvisx - visually encode characters from src into dst
- *
+ *
* Dst must be 4 times the size of src to account for possible
* expansion. The length of dst, not including the trailing NULL,
- * is returned.
+ * is returned.
*
* Strvisx encodes exactly len bytes from src into dst.
* This is useful for encoding a block of data.
@@ -158,7 +159,7 @@ strvis(dst, src, flag)
register char c;
char *start;
- for (start = dst; c = *src;)
+ for (start = dst; (c = *src); )
dst = vis(dst, c, flag, *++src);
*dst = '\0';
return (dst - start);
diff --git a/lib/libc/gmon/Makefile.inc b/lib/libc/gmon/Makefile.inc
index 959c3fb..a264d09 100644
--- a/lib/libc/gmon/Makefile.inc
+++ b/lib/libc/gmon/Makefile.inc
@@ -1,10 +1,16 @@
-# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
# gmon sources
-.PATH: ${.CURDIR}/gmon
+.PATH: ${.CURDIR}/../libc/gmon
SRCS+= gmon.c mcount.c
-MAN3+= moncontrol.0
+
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN3+= gmon/moncontrol.3
+MLINKS+= moncontrol.3 monstartup.3
+.endif
# mcount cannot be compiled with profiling
mcount.po: mcount.o
diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c
index 022ffb5..81e36dd 100644
--- a/lib/libc/gmon/gmon.c
+++ b/lib/libc/gmon/gmon.c
@@ -44,7 +44,11 @@ static char sccsid[] = "@(#)gmon.c 8.1 (Berkeley) 6/4/93";
#include <fcntl.h>
#include <unistd.h>
+#if defined(__ELF__)
+extern char *minbrk asm (".minbrk");
+#else
extern char *minbrk asm ("minbrk");
+#endif
struct gmonparam _gmonparam = { GMON_PROF_OFF };
@@ -106,7 +110,7 @@ monstartup(lowpc, highpc)
s_scale = ((float)p->kcountsize / o ) * SCALE_1_TO_1;
#else /* avoid floating point */
int quot = o / p->kcountsize;
-
+
if (quot >= 0x10000)
s_scale = 1;
else if (quot >= 0x100)
@@ -239,7 +243,7 @@ static int
hertz()
{
struct itimerval tim;
-
+
tim.it_interval.tv_sec = 0;
tim.it_interval.tv_usec = 1;
tim.it_value.tv_sec = 0;
diff --git a/lib/libc/gmon/mcount.c b/lib/libc/gmon/mcount.c
index 523217d..a48e558 100644
--- a/lib/libc/gmon/mcount.c
+++ b/lib/libc/gmon/mcount.c
@@ -32,11 +32,25 @@
*/
#if !defined(lint) && !defined(KERNEL) && defined(LIBC_SCCS)
+#if 0
static char sccsid[] = "@(#)mcount.c 8.1 (Berkeley) 6/4/93";
#endif
+static const char rcsid[] =
+ "$Id$";
+#endif
#include <sys/param.h>
#include <sys/gmon.h>
+#ifdef KERNEL
+#include <sys/systm.h>
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+#include <vm/pmap.h>
+void bintr __P((void));
+void btrap __P((void));
+void eintr __P((void));
+void user __P((void));
+#endif
/*
* mcount is called on entry to each function compiled with the profiling
@@ -48,44 +62,132 @@ static char sccsid[] = "@(#)mcount.c 8.1 (Berkeley) 6/4/93";
* _mcount updates data structures that represent traversals of the
* program's call graph edges. frompc and selfpc are the return
* address and function address that represents the given call graph edge.
- *
+ *
* Note: the original BSD code used the same variable (frompcindex) for
* both frompcindex and frompc. Any reasonable, modern compiler will
* perform this optimization.
*/
_MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
- register u_long frompc, selfpc;
+ register fptrint_t frompc, selfpc;
{
+#ifdef GUPROF
+ u_int delta;
+#endif
+ register fptrdiff_t frompci;
register u_short *frompcindex;
register struct tostruct *top, *prevtop;
register struct gmonparam *p;
register long toindex;
#ifdef KERNEL
- register int s;
+ MCOUNT_DECL(s)
#endif
p = &_gmonparam;
+#ifndef GUPROF /* XXX */
/*
* check that we are profiling
* and that we aren't recursively invoked.
*/
if (p->state != GMON_PROF_ON)
return;
+#endif
#ifdef KERNEL
- MCOUNT_ENTER;
+ MCOUNT_ENTER(s);
#else
p->state = GMON_PROF_BUSY;
#endif
+ frompci = frompc - p->lowpc;
+
+#ifdef KERNEL
+ /*
+ * When we are called from an exception handler, frompci may be
+ * for a user address. Convert such frompci's to the index of
+ * user() to merge all user counts.
+ */
+ if (frompci >= p->textsize) {
+ if (frompci + p->lowpc
+ >= (fptrint_t)(VM_MAXUSER_ADDRESS + UPAGES * PAGE_SIZE))
+ goto done;
+ frompci = (fptrint_t)user - p->lowpc;
+ if (frompci >= p->textsize)
+ goto done;
+ }
+#endif /* KERNEL */
+
+#ifdef GUPROF
+ if (p->state != GMON_PROF_HIRES)
+ goto skip_guprof_stuff;
/*
- * check that frompcindex is a reasonable pc value.
+ * Look at the clock and add the count of clock cycles since the
+ * clock was last looked at to a counter for frompc. This
+ * solidifies the count for the function containing frompc and
+ * effectively starts another clock for the current function.
+ * The count for the new clock will be solidified when another
+ * function call is made or the function returns.
+ *
+ * We use the usual sampling counters since they can be located
+ * efficiently. 4-byte counters are usually necessary.
+ *
+ * There are many complications for subtracting the profiling
+ * overheads from the counts for normal functions and adding
+ * them to the counts for mcount(), mexitcount() and cputime().
+ * We attempt to handle fractional cycles, but the overheads
+ * are usually underestimated because they are calibrated for
+ * a simpler than usual setup.
+ */
+ delta = cputime() - p->mcount_overhead;
+ p->cputime_overhead_resid += p->cputime_overhead_frac;
+ p->mcount_overhead_resid += p->mcount_overhead_frac;
+ if ((int)delta < 0)
+ *p->mcount_count += delta + p->mcount_overhead
+ - p->cputime_overhead;
+ else if (delta != 0) {
+ if (p->cputime_overhead_resid >= CALIB_SCALE) {
+ p->cputime_overhead_resid -= CALIB_SCALE;
+ ++*p->cputime_count;
+ --delta;
+ }
+ if (delta != 0) {
+ if (p->mcount_overhead_resid >= CALIB_SCALE) {
+ p->mcount_overhead_resid -= CALIB_SCALE;
+ ++*p->mcount_count;
+ --delta;
+ }
+ KCOUNT(p, frompci) += delta;
+ }
+ *p->mcount_count += p->mcount_overhead_sub;
+ }
+ *p->cputime_count += p->cputime_overhead;
+skip_guprof_stuff:
+#endif /* GUPROF */
+
+#ifdef KERNEL
+ /*
+ * When we are called from an exception handler, frompc is faked
+ * to be for where the exception occurred. We've just solidified
+ * the count for there. Now convert frompci to the index of btrap()
+ * for trap handlers and bintr() for interrupt handlers to make
+ * exceptions appear in the call graph as calls from btrap() and
+ * bintr() instead of calls from all over.
+ */
+ if ((fptrint_t)selfpc >= (fptrint_t)btrap
+ && (fptrint_t)selfpc < (fptrint_t)eintr) {
+ if ((fptrint_t)selfpc >= (fptrint_t)bintr)
+ frompci = (fptrint_t)bintr - p->lowpc;
+ else
+ frompci = (fptrint_t)btrap - p->lowpc;
+ }
+#endif /* KERNEL */
+
+ /*
+ * check that frompc is a reasonable pc value.
* for example: signal catchers get called from the stack,
* not from text space. too bad.
*/
- frompc -= p->lowpc;
- if (frompc > p->textsize)
+ if (frompci >= p->textsize)
goto done;
- frompcindex = &p->froms[frompc / (p->hashfraction * sizeof(*p->froms))];
+ frompcindex = &p->froms[frompci / (p->hashfraction * sizeof(*p->froms))];
toindex = *frompcindex;
if (toindex == 0) {
/*
@@ -154,11 +256,11 @@ _MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
*frompcindex = toindex;
goto done;
}
-
+
}
done:
#ifdef KERNEL
- MCOUNT_EXIT;
+ MCOUNT_EXIT(s);
#else
p->state = GMON_PROF_ON;
#endif
@@ -166,7 +268,7 @@ done:
overflow:
p->state = GMON_PROF_ERROR;
#ifdef KERNEL
- MCOUNT_EXIT;
+ MCOUNT_EXIT(s);
#endif
return;
}
@@ -176,3 +278,48 @@ overflow:
* which is included by <sys/gmon.h>.
*/
MCOUNT
+
+#ifdef GUPROF
+void
+mexitcount(selfpc)
+ fptrint_t selfpc;
+{
+ struct gmonparam *p;
+ fptrint_t selfpcdiff;
+
+ p = &_gmonparam;
+ selfpcdiff = selfpc - (fptrint_t)p->lowpc;
+ if (selfpcdiff < p->textsize) {
+ u_int delta;
+
+ /*
+ * Solidify the count for the current function.
+ */
+ delta = cputime() - p->mexitcount_overhead;
+ p->cputime_overhead_resid += p->cputime_overhead_frac;
+ p->mexitcount_overhead_resid += p->mexitcount_overhead_frac;
+ if ((int)delta < 0)
+ *p->mexitcount_count += delta + p->mexitcount_overhead
+ - p->cputime_overhead;
+ else if (delta != 0) {
+ if (p->cputime_overhead_resid >= CALIB_SCALE) {
+ p->cputime_overhead_resid -= CALIB_SCALE;
+ ++*p->cputime_count;
+ --delta;
+ }
+ if (delta != 0) {
+ if (p->mexitcount_overhead_resid
+ >= CALIB_SCALE) {
+ p->mexitcount_overhead_resid
+ -= CALIB_SCALE;
+ ++*p->mexitcount_count;
+ --delta;
+ }
+ KCOUNT(p, selfpcdiff) += delta;
+ }
+ *p->mexitcount_count += p->mexitcount_overhead_sub;
+ }
+ *p->cputime_count += p->cputime_overhead;
+ }
+}
+#endif /* GUPROF */
diff --git a/lib/libc/gmon/moncontrol.3 b/lib/libc/gmon/moncontrol.3
index 9b01f2b..92993cd 100644
--- a/lib/libc/gmon/moncontrol.3
+++ b/lib/libc/gmon/moncontrol.3
@@ -39,7 +39,10 @@
.Nm monstartup
.Nd control execution profile
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Ft int
.Fn moncontrol "int mode"
+.Ft int
.Fn monstartup "u_long *lowpc" "u_long *highpc"
.Sh DESCRIPTION
An executable program compiled using the
@@ -98,4 +101,5 @@ Profiling begins on return from
.Sh SEE ALSO
.Xr cc 1 ,
.Xr gprof 1 ,
-.Xr profil 2
+.Xr profil 2 ,
+.Xr clocks 7
diff --git a/lib/libc/i386/DEFS.h b/lib/libc/i386/DEFS.h
index 10d9f9b..fbc11bc 100644
--- a/lib/libc/i386/DEFS.h
+++ b/lib/libc/i386/DEFS.h
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -33,15 +33,9 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)DEFS.h 8.1 (Berkeley) 6/4/93
+ * from: @(#)DEFS.h 5.1 (Berkeley) 4/23/90
+ *
+ * $Id: DEFS.h,v 1.6 1997/02/22 14:58:29 peter Exp $
*/
-#ifdef PROF
-#define ENTRY(x) .globl _/**/x; _/**/x: \
- .data; 1:; .long 0; .text; lea 1b,%eax ; call mcount
-#define ASENTRY(x) .globl x; x: \
- .data; 1:; .long 0; .text; lea 1b,%eax ; call mcount
-#else
-#define ENTRY(x) .globl _/**/x; _/**/x:
-#define ASENTRY(x) .globl x; x:
-#endif
+#include <machine/asm.h>
diff --git a/lib/libc/i386/SYS.h b/lib/libc/i386/SYS.h
index dfb679f..593b2ed 100644
--- a/lib/libc/i386/SYS.h
+++ b/lib/libc/i386/SYS.h
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -33,25 +33,54 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)SYS.h 8.1 (Berkeley) 6/4/93
+ * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91
+ *
+ * $Id: SYS.h,v 1.10 1997/02/22 14:58:30 peter Exp $
*/
#include <sys/syscall.h>
+#include "DEFS.h"
-#ifdef PROF
-#define ENTRY(x) .globl _/**/x; \
- .data; 1:; .long 0; .text; .align 2; _/**/x: \
- movl $1b,%eax; call mcount
-#else
-#define ENTRY(x) .globl _/**/x; .text; .align 2; _/**/x:
-#endif PROF
-#define SYSCALL(x) 2: jmp cerror; ENTRY(x); lea SYS_/**/x,%eax; LCALL(7,0); jb 2b
+#define SYSCALL(x) 2: PIC_PROLOGUE; jmp PIC_PLT(HIDENAME(cerror)); \
+ ENTRY(x); lea __CONCAT(SYS_,x),%eax; KERNCALL; jb 2b
#define RSYSCALL(x) SYSCALL(x); ret
-#define PSEUDO(x,y) ENTRY(x); lea SYS_/**/y, %eax; ; LCALL(7,0); ret
-#define CALL(x,y) call _/**/y; addl $4*x,%esp
-/* gas fucks up offset -- although we don't currently need it, do for BCS */
+
+#define PSEUDO(x,y) ENTRY(x); lea __CONCAT(SYS_,y), %eax; KERNCALL; ret
+/* gas messes up offset -- although we don't currently need it, do for BCS */
#define LCALL(x,y) .byte 0x9a ; .long y; .word x
-#define ASMSTR .asciz
+/*
+ * Design note:
+ *
+ * The macros PSYSCALL() and PRSYSCALL() are intended for use where a
+ * syscall needs to be renamed in the threaded library. When building
+ * a normal library, they default to the traditional SYSCALL() and
+ * RSYSCALL(). This avoids the need to #ifdef _THREAD_SAFE everywhere
+ * that the renamed function needs to be called.
+ */
+#ifdef _THREAD_SAFE
+/*
+ * For the thread_safe versions, we prepend _thread_sys_ to the function
+ * name so that the 'C' wrapper can go around the real name.
+ */
+#define PSYSCALL(x) 2: PIC_PROLOGUE; jmp PIC_PLT(HIDENAME(cerror)); \
+ ENTRY(__CONCAT(_thread_sys_,x)); \
+ lea __CONCAT(SYS_,x),%eax; KERNCALL; jb 2b
+#define PRSYSCALL(x) PSYSCALL(x); ret
+#define PPSEUDO(x,y) ENTRY(__CONCAT(_thread_sys_,x)); \
+ lea __CONCAT(SYS_,y), %eax; KERNCALL; ret
+#else
+/*
+ * The non-threaded library defaults to traditional syscalls where
+ * the function name matches the syscall name.
+ */
+#define PSYSCALL(x) SYSCALL(x)
+#define PRSYSCALL(x) RSYSCALL(x)
+#define PPSEUDO(x,y) PSEUDO(x,y)
+#endif
- .globl cerror
+#ifdef __ELF__
+#define KERNCALL int $0x80 /* Faster */
+#else
+#define KERNCALL LCALL(7,0) /* The old way */
+#endif
diff --git a/lib/libc/i386/gen/Makefile.inc b/lib/libc/i386/gen/Makefile.inc
index 814013d..457d5c3 100644
--- a/lib/libc/i386/gen/Makefile.inc
+++ b/lib/libc/i386/gen/Makefile.inc
@@ -1,5 +1,5 @@
# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
-SRCS+= isinf.c
-SRCS+= _setjmp.s alloca.s fabs.s ldexp.c modf.s setjmp.s
-SRCS+= divsi3.s fixdfsi.s fixunsdfsi.s udivsi3.s
+SRCS+= isinf.c infinity.c
+SRCS+= _setjmp.S alloca.S fabs.S ldexp.c modf.S setjmp.S sigsetjmp.S
diff --git a/lib/libc/i386/gen/_setjmp.S b/lib/libc/i386/gen/_setjmp.S
index 47e319a..62259ce 100644
--- a/lib/libc/i386/gen/_setjmp.S
+++ b/lib/libc/i386/gen/_setjmp.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,11 +32,14 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
- .asciz "@(#)_setjmp.s 8.1 (Berkeley) 6/4/93"
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
/*
* C library -- _setjmp, _longjmp
@@ -44,13 +47,17 @@
* _longjmp(a,v)
* will generate a "return(v)" from the last call to
* _setjmp(a)
- * by restoring registers from the stack.
+ * by restoring registers from the environment 'a'.
* The previous signal state is NOT restored.
*/
#include "DEFS.h"
+#ifdef _THREAD_SAFE
+ENTRY(__thread_sys_setjmp)
+#else
ENTRY(_setjmp)
+#endif
movl 4(%esp),%eax
movl 0(%esp),%edx
movl %edx, 0(%eax) /* rta */
@@ -59,10 +66,15 @@ ENTRY(_setjmp)
movl %ebp,12(%eax)
movl %esi,16(%eax)
movl %edi,20(%eax)
- movl $0,%eax
+ fnstcw 28(%eax)
+ xorl %eax,%eax
ret
+#ifdef _THREAD_SAFE
+ENTRY(__thread_sys_longjmp)
+#else
ENTRY(_longjmp)
+#endif
movl 4(%esp),%edx
movl 8(%esp),%eax
movl 0(%edx),%ecx
@@ -71,8 +83,10 @@ ENTRY(_longjmp)
movl 12(%edx),%ebp
movl 16(%edx),%esi
movl 20(%edx),%edi
- cmpl $0,%eax
- jne 1f
- movl $1,%eax
+ fninit
+ fldcw 28(%edx)
+ testl %eax,%eax
+ jnz 1f
+ incl %eax
1: movl %ecx,0(%esp)
ret
diff --git a/lib/libc/i386/gen/alloca.S b/lib/libc/i386/gen/alloca.S
index a2d6a41..f76b37b 100644
--- a/lib/libc/i386/gen/alloca.S
+++ b/lib/libc/i386/gen/alloca.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,11 +32,14 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
- .asciz "@(#)alloca.s 8.1 (Berkeley) 6/4/93"
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
/* like alloc, but automatic automatic free in return */
diff --git a/lib/libc/i386/gen/fabs.S b/lib/libc/i386/gen/fabs.S
index 40e72c8..5ae5370 100644
--- a/lib/libc/i386/gen/fabs.S
+++ b/lib/libc/i386/gen/fabs.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,11 +32,14 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
- .asciz "@(#)fabs.s 8.1 (Berkeley) 6/4/93"
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
#include "DEFS.h"
diff --git a/lib/libc/i386/gen/frexp.c b/lib/libc/i386/gen/frexp.c
index 6cdcd2c..aba4802 100644
--- a/lib/libc/i386/gen/frexp.c
+++ b/lib/libc/i386/gen/frexp.c
@@ -29,11 +29,13 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)frexp.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif /* LIBC_RCS and not lint */
#include <sys/types.h>
#include <math.h>
diff --git a/lib/libc/i386/gen/infinity.c b/lib/libc/i386/gen/infinity.c
new file mode 100644
index 0000000..e46f676
--- /dev/null
+++ b/lib/libc/i386/gen/infinity.c
@@ -0,0 +1,9 @@
+/*
+ * infinity.c
+ * $Id$
+ */
+
+#include <math.h>
+
+/* bytes for +Infinity on a 387 */
+char __infinity[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
diff --git a/lib/libc/i386/gen/isinf.c b/lib/libc/i386/gen/isinf.c
index bcbeded..a796dcf 100644
--- a/lib/libc/i386/gen/isinf.c
+++ b/lib/libc/i386/gen/isinf.c
@@ -29,14 +29,17 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif /* LIBC_RCS and not lint */
#include <sys/types.h>
+int
isnan(d)
double d;
{
@@ -50,6 +53,7 @@ isnan(d)
return(p->exp == 2047 && (p->manh || p->manl));
}
+int
isinf(d)
double d;
{
diff --git a/lib/libc/i386/gen/ldexp.c b/lib/libc/i386/gen/ldexp.c
index 7046c4e..8b63f52 100644
--- a/lib/libc/i386/gen/ldexp.c
+++ b/lib/libc/i386/gen/ldexp.c
@@ -32,11 +32,13 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ldexp.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif /* LIBC_RCS and not lint */
/*
* ldexp(value, exp): return value * (2 ** exp).
@@ -55,8 +57,18 @@ ldexp (double value, int exp)
{
double temp, texp, temp2;
texp = exp;
+#ifdef __GNUC__
+#if __GNUC__ >= 2
+ asm ("fscale "
+ : "=u" (temp2), "=t" (temp)
+ : "0" (texp), "1" (value));
+#else
asm ("fscale ; fxch %%st(1) ; fstp%L1 %1 "
: "=f" (temp), "=0" (temp2)
: "0" (texp), "f" (value));
+#endif
+#else
+error unknown asm
+#endif
return (temp);
}
diff --git a/lib/libc/i386/gen/modf.S b/lib/libc/i386/gen/modf.S
index 2551237..b457097 100644
--- a/lib/libc/i386/gen/modf.S
+++ b/lib/libc/i386/gen/modf.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Sean Eric Fagan.
@@ -32,11 +32,14 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
- .asciz "@(#)modf.s 8.1 (Berkeley) 6/4/93"
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
/*
* modf(value, iptr): return fractional part of value, and stores the
@@ -47,9 +50,10 @@
*/
/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */
-.text
-.globl _modf
-_modf:
+
+#include "DEFS.h"
+
+ENTRY(modf)
pushl %ebp
movl %esp,%ebp
subl $16,%esp
diff --git a/lib/libc/i386/gen/setjmp.S b/lib/libc/i386/gen/setjmp.S
index b24da11..6525a16 100644
--- a/lib/libc/i386/gen/setjmp.S
+++ b/lib/libc/i386/gen/setjmp.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,11 +32,14 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
- .asciz "@(#)setjmp.s 8.1 (Berkeley) 6/4/93"
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
/*
* C library -- _setjmp, _longjmp
@@ -44,16 +47,27 @@
* longjmp(a,v)
* will generate a "return(v)" from the last call to
* setjmp(a)
- * by restoring registers from the stack.
+ * by restoring registers from the environment 'a'.
* The previous signal state is restored.
*/
#include "DEFS.h"
+#include "SYS.h"
+#ifdef _THREAD_SAFE
+ENTRY(_thread_sys_setjmp)
+#else
ENTRY(setjmp)
+#endif
+ PIC_PROLOGUE
pushl $0
- call _sigblock
+#ifdef _THREAD_SAFE
+ call PIC_PLT(CNAME(_thread_sys_sigblock))
+#else
+ call PIC_PLT(CNAME(sigblock))
+#endif
popl %edx
+ PIC_EPILOGUE
movl 4(%esp),%ecx
movl 0(%esp),%edx
movl %edx, 0(%ecx)
@@ -63,14 +77,25 @@ ENTRY(setjmp)
movl %esi,16(%ecx)
movl %edi,20(%ecx)
movl %eax,24(%ecx)
- movl $0,%eax
+ fnstcw 28(%ecx)
+ xorl %eax,%eax
ret
+#ifdef _THREAD_SAFE
+ENTRY(_thread_sys_longjmp)
+#else
ENTRY(longjmp)
+#endif
movl 4(%esp),%edx
+ PIC_PROLOGUE
pushl 24(%edx)
- call _sigsetmask
+#ifdef _THREAD_SAFE
+ call PIC_PLT(CNAME(_thread_sys_sigsetmask))
+#else
+ call PIC_PLT(CNAME(sigsetmask)) /* XXX this is not reentrant */
+#endif
popl %eax
+ PIC_EPILOGUE
movl 4(%esp),%edx
movl 8(%esp),%eax
movl 0(%edx),%ecx
@@ -79,8 +104,10 @@ ENTRY(longjmp)
movl 12(%edx),%ebp
movl 16(%edx),%esi
movl 20(%edx),%edi
- cmpl $0,%eax
- jne 1f
- movl $1,%eax
+ fninit
+ fldcw 28(%edx)
+ testl %eax,%eax
+ jnz 1f
+ incl %eax
1: movl %ecx,0(%esp)
ret
diff --git a/lib/libc/i386/gen/sigsetjmp.S b/lib/libc/i386/gen/sigsetjmp.S
new file mode 100644
index 0000000..1220598
--- /dev/null
+++ b/lib/libc/i386/gen/sigsetjmp.S
@@ -0,0 +1,125 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+#include "SYS.h"
+
+/*-
+ * TODO:
+ * Rename sigsetjmp to __sigsetjmp and siglongjmp to __siglongjmp,
+ * remove the other *jmp functions and define everything in terms
+ * of the renamed functions. This requires compiler support for
+ * the renamed functions (introduced in gcc-2.5.3; previous versions
+ * only supported *jmp with 0 or 1 leading underscores).
+ *
+ * Use sigprocmask() instead of sigblock() and sigsetmask(), and
+ * check for and handle errors.
+ *
+ * Restore _all_ the registers and the signal mask atomically. Can
+ * use sigreturn() if sigreturn() works.
+ */
+
+#ifdef _THREAD_SAFE
+ENTRY(_thread_sys_sigsetjmp)
+#else
+ENTRY(sigsetjmp)
+#endif
+ movl 8(%esp),%eax
+ movl 4(%esp),%ecx
+ movl %eax,32(%ecx)
+ testl %eax,%eax
+ jz 2f
+ PIC_PROLOGUE
+ pushl $0
+#ifdef _THREAD_SAFE
+ call PIC_PLT(CNAME(_thread_sys_sigblock))
+#else
+ call PIC_PLT(CNAME(sigblock))
+#endif
+ addl $4,%esp
+ PIC_EPILOGUE
+ movl 4(%esp),%ecx
+ movl %eax,24(%ecx)
+2: movl 0(%esp),%edx
+ movl %edx, 0(%ecx)
+ movl %ebx, 4(%ecx)
+ movl %esp, 8(%ecx)
+ movl %ebp,12(%ecx)
+ movl %esi,16(%ecx)
+ movl %edi,20(%ecx)
+ fnstcw 28(%ecx)
+ xorl %eax,%eax
+ ret
+
+#ifdef _THREAD_SAFE
+ENTRY(_thread_sys_siglongjmp)
+#else
+ENTRY(siglongjmp)
+#endif
+ movl 4(%esp),%edx
+ cmpl $0,32(%edx)
+ jz 2f
+ PIC_PROLOGUE
+ pushl 24(%edx)
+#ifdef _THREAD_SAFE
+ call PIC_PLT(CNAME(_thread_sys_sigsetmask))
+#else
+ call PIC_PLT(CNAME(sigsetmask))
+#endif
+ addl $4,%esp
+ PIC_EPILOGUE
+2: movl 4(%esp),%edx
+ movl 8(%esp),%eax
+ movl 0(%edx),%ecx
+ movl 4(%edx),%ebx
+ movl 8(%edx),%esp
+ movl 12(%edx),%ebp
+ movl 16(%edx),%esi
+ movl 20(%edx),%edi
+ fninit
+ fldcw 28(%edx)
+ testl %eax,%eax
+ jnz 1f
+ incl %eax
+1: movl %ecx,0(%esp)
+ ret
diff --git a/lib/libc/i386/net/Makefile.inc b/lib/libc/i386/net/Makefile.inc
index 81a6c91..dff7fd1 100644
--- a/lib/libc/i386/net/Makefile.inc
+++ b/lib/libc/i386/net/Makefile.inc
@@ -1,3 +1,4 @@
# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
-SRCS+= htonl.s htons.s ntohl.s ntohs.s
+SRCS+= htonl.S htons.S ntohl.S ntohs.S
diff --git a/lib/libc/i386/net/htonl.S b/lib/libc/i386/net/htonl.S
new file mode 100644
index 0000000..095c40a
--- /dev/null
+++ b/lib/libc/i386/net/htonl.S
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+/* netorder = htonl(hostorder) */
+
+#include "DEFS.h"
+
+ENTRY(htonl)
+ movl 4(%esp),%eax
+ xchgb %al,%ah
+ roll $16,%eax
+ xchgb %al,%ah
+ ret
diff --git a/lib/libc/i386/net/htons.S b/lib/libc/i386/net/htons.S
new file mode 100644
index 0000000..238dfc2
--- /dev/null
+++ b/lib/libc/i386/net/htons.S
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+/* netorder = htons(hostorder) */
+
+#include "DEFS.h"
+
+ENTRY(htons)
+ movzwl 4(%esp),%eax
+ xchgb %al,%ah
+ ret
diff --git a/lib/libc/i386/net/ntohl.S b/lib/libc/i386/net/ntohl.S
new file mode 100644
index 0000000..5af5008
--- /dev/null
+++ b/lib/libc/i386/net/ntohl.S
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+/* hostorder = ntohl(netorder) */
+
+#include "DEFS.h"
+
+ENTRY(ntohl)
+ movl 4(%esp),%eax
+ xchgb %al,%ah
+ roll $16,%eax
+ xchgb %al,%ah
+ ret
diff --git a/lib/libc/i386/net/ntohs.S b/lib/libc/i386/net/ntohs.S
new file mode 100644
index 0000000..4bed4a2
--- /dev/null
+++ b/lib/libc/i386/net/ntohs.S
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+/* hostorder = ntohs(netorder) */
+
+#include "DEFS.h"
+
+ENTRY(ntohs)
+ movzwl 4(%esp),%eax
+ xchgb %al,%ah
+ ret
diff --git a/lib/libc/i386/stdlib/Makefile.inc b/lib/libc/i386/stdlib/Makefile.inc
index 37d5037..65ce348 100644
--- a/lib/libc/i386/stdlib/Makefile.inc
+++ b/lib/libc/i386/stdlib/Makefile.inc
@@ -1,3 +1,4 @@
# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
-SRCS+= abs.s
+SRCS+= abs.S
diff --git a/lib/libc/i386/stdlib/abs.S b/lib/libc/i386/stdlib/abs.S
index 755ea56..4915d16 100644
--- a/lib/libc/i386/stdlib/abs.S
+++ b/lib/libc/i386/stdlib/abs.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,17 +32,20 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
- .asciz "@(#)abs.s 8.1 (Berkeley) 6/4/93"
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
#include "DEFS.h"
ENTRY(abs)
movl 4(%esp),%eax
- cmpl $0,%eax
- jge 1f
+ testl %eax,%eax
+ jns 1f
negl %eax
1: ret
diff --git a/lib/libc/i386/stdlib/div.S b/lib/libc/i386/stdlib/div.S
new file mode 100644
index 0000000..b2a9901
--- /dev/null
+++ b/lib/libc/i386/stdlib/div.S
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+ENTRY(div)
+ movl 4(%esp),%eax
+ movl 8(%esp),%ecx
+ cdq
+ idiv %ecx
+ movl %eax,4(%esp)
+ movl %edx,8(%esp)
+ ret
diff --git a/lib/libc/i386/stdlib/labs.S b/lib/libc/i386/stdlib/labs.S
new file mode 100644
index 0000000..5c5afe1
--- /dev/null
+++ b/lib/libc/i386/stdlib/labs.S
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+ENTRY(labs)
+ movl 4(%esp),%eax
+ testl %eax,%eax
+ jns 1f
+ negl %eax
+1: ret
diff --git a/lib/libc/i386/stdlib/ldiv.S b/lib/libc/i386/stdlib/ldiv.S
new file mode 100644
index 0000000..38cdf3f
--- /dev/null
+++ b/lib/libc/i386/stdlib/ldiv.S
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+ENTRY(ldiv)
+ movl 4(%esp),%eax
+ movl 8(%esp),%ecx
+ cdq
+ idiv %ecx
+ movl %eax,4(%esp)
+ movl %edx,8(%esp)
+ ret
diff --git a/lib/libc/i386/string/Makefile.inc b/lib/libc/i386/string/Makefile.inc
index c36af74..870cc3b 100644
--- a/lib/libc/i386/string/Makefile.inc
+++ b/lib/libc/i386/string/Makefile.inc
@@ -1,5 +1,8 @@
# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id: Makefile.inc,v 1.6 1997/02/22 14:59:02 peter Exp $
-SRCS+= bcmp.c bcopy.c bzero.s ffs.c index.c memchr.c memcmp.c memset.c \
- rindex.c strcat.c strcmp.c strcpy.c strcspn.c strlen.c strncat.c \
- strncmp.c strncpy.c strpbrk.c strsep.c strspn.c strstr.c
+SRCS+= bcmp.S bcopy.S bzero.S ffs.S index.S memchr.S memcmp.S \
+ memmove.S memcpy.S memset.S \
+ rindex.S strcat.S strchr.S strcmp.S strcpy.S strcspn.c \
+ strlen.S strncat.c strncmp.S strncpy.c strpbrk.c strsep.c \
+ strspn.c strrchr.S strstr.c swab.S
diff --git a/lib/libc/i386/string/bcmp.S b/lib/libc/i386/string/bcmp.S
new file mode 100644
index 0000000..1c0c934
--- /dev/null
+++ b/lib/libc/i386/string/bcmp.S
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * bcmp (void *b1, void *b2, size_t len)
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(bcmp)
+ pushl %edi
+ pushl %esi
+ movl 12(%esp),%edi
+ movl 16(%esp),%esi
+ xorl %eax,%eax /* clear return value */
+ cld /* set compare direction forward */
+
+ movl 20(%esp),%ecx /* compare by words */
+ shrl $2,%ecx
+ repe
+ cmpsl
+ jne L1
+
+ movl 20(%esp),%ecx /* compare remainder by bytes */
+ andl $3,%ecx
+ repe
+ cmpsb
+ je L2
+
+L1: incl %eax
+L2: popl %esi
+ popl %edi
+ ret
diff --git a/lib/libc/i386/string/bcopy.S b/lib/libc/i386/string/bcopy.S
new file mode 100644
index 0000000..d2a571e
--- /dev/null
+++ b/lib/libc/i386/string/bcopy.S
@@ -0,0 +1,103 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from locore.s.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ */
+
+#include <machine/asm.h>
+
+ RCSID("$NetBSD: bcopy.S,v 1.6 1996/11/12 00:50:06 jtc Exp $")
+
+ /*
+ * (ov)bcopy (src,dst,cnt)
+ * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
+ */
+
+#ifdef MEMCOPY
+ENTRY(memcpy)
+#else
+#ifdef MEMMOVE
+ENTRY(memmove)
+#else
+ENTRY(bcopy)
+#endif
+#endif
+ pushl %esi
+ pushl %edi
+#if defined(MEMCOPY) || defined(MEMMOVE)
+ movl 12(%esp),%edi
+ movl 16(%esp),%esi
+#else
+ movl 12(%esp),%esi
+ movl 16(%esp),%edi
+#endif
+ movl 20(%esp),%ecx
+ movl %edi,%eax
+ subl %esi,%eax
+ cmpl %ecx,%eax /* overlapping? */
+ jb 1f
+ cld /* nope, copy forwards. */
+ shrl $2,%ecx /* copy by words */
+ rep
+ movsl
+ movl 20(%esp),%ecx
+ andl $3,%ecx /* any bytes left? */
+ rep
+ movsb
+#if defined(MEMCOPY) || defined(MEMMOVE)
+ movl 12(%esp),%eax
+#endif
+ popl %edi
+ popl %esi
+ ret
+1:
+ addl %ecx,%edi /* copy backwards. */
+ addl %ecx,%esi
+ std
+ andl $3,%ecx /* any fractional bytes? */
+ decl %edi
+ decl %esi
+ rep
+ movsb
+ movl 20(%esp),%ecx /* copy remainder by words */
+ shrl $2,%ecx
+ subl $3,%esi
+ subl $3,%edi
+ rep
+ movsl
+#if defined(MEMCOPY) || defined(MEMMOVE)
+ movl 12(%esp),%eax
+#endif
+ popl %edi
+ popl %esi
+ cld
+ ret
diff --git a/lib/libc/i386/string/bzero.S b/lib/libc/i386/string/bzero.S
index 79a5a69..8cc8f9f 100644
--- a/lib/libc/i386/string/bzero.S
+++ b/lib/libc/i386/string/bzero.S
@@ -1,9 +1,6 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -15,39 +12,76 @@
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 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 product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
- * 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.
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
- .asciz "@(#)bzero.s 8.1 (Berkeley) 6/4/93"
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
-/* bzero (base,cnt) */
+#include "DEFS.h"
- .globl _bzero
-_bzero:
+/*
+ * bzero (void *b, size_t len)
+ * write len zero bytes to the string b.
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(bzero)
pushl %edi
- movl 8(%esp),%edi
- movl 12(%esp),%ecx
- movb $0x00,%al
- cld
+ pushl %ebx
+ movl 12(%esp),%edi
+ movl 16(%esp),%ecx
+
+ cld /* set fill direction forward */
+ xorl %eax,%eax /* set fill data to 0 */
+
+ /*
+ * if the string is too short, it's really not worth the overhead
+ * of aligning to word boundries, etc. So we jump to a plain
+ * unaligned set.
+ */
+ cmpl $0x0f,%ecx
+ jle L1
+
+ movl %edi,%edx /* compute misalignment */
+ negl %edx
+ andl $3,%edx
+ movl %ecx,%ebx
+ subl %edx,%ebx
+
+ movl %edx,%ecx /* zero until word aligned */
rep
stosb
+
+ movl %ebx,%ecx /* zero by words */
+ shrl $2,%ecx
+ rep
+ stosl
+
+ movl %ebx,%ecx
+ andl $3,%ecx /* zero remainder by bytes */
+L1: rep
+ stosb
+
+ popl %ebx
popl %edi
ret
diff --git a/lib/libc/i386/string/ffs.S b/lib/libc/i386/string/ffs.S
new file mode 100644
index 0000000..084115b
--- /dev/null
+++ b/lib/libc/i386/string/ffs.S
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * ffs(value)
+ * finds the first bit set in value and returns the index of
+ * that bit. Bits are numbered starting from 1, starting at the
+ * rightmost bit. A return value of 0 means that the argument
+ * was zero.
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(ffs)
+ bsfl 4(%esp),%eax
+ jz L1 /* ZF is set if all bits are 0 */
+ incl %eax /* bits numbered from 1, not 0 */
+ ret
+
+ .align 2
+L1: xorl %eax,%eax /* clear result */
+ ret
diff --git a/lib/libc/i386/string/index.S b/lib/libc/i386/string/index.S
new file mode 100644
index 0000000..0a6c6a3
--- /dev/null
+++ b/lib/libc/i386/string/index.S
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * index(s, c)
+ * return a pointer to the first occurance of the character c in
+ * string s, or NULL if c does not occur in the string.
+ *
+ * %edx - pointer iterating through string
+ * %eax - pointer to first occurance of 'c'
+ * %cl - character we're comparing against
+ * %bl - character at %edx
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(index)
+ pushl %ebx
+ movl 8(%esp),%eax
+ movb 12(%esp),%cl
+ .align 2,0x90
+L1:
+ movb (%eax),%bl
+ cmpb %bl,%cl /* found char??? */
+ je L2
+ incl %eax
+ testb %bl,%bl /* null terminator??? */
+ jne L1
+ xorl %eax,%eax
+L2:
+ popl %ebx
+ ret
diff --git a/lib/libc/i386/string/memchr.S b/lib/libc/i386/string/memchr.S
new file mode 100644
index 0000000..cc2dc76
--- /dev/null
+++ b/lib/libc/i386/string/memchr.S
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * memchr (b, c, len)
+ * locates the first occurance of c in string b.
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(memchr)
+ pushl %edi
+ movl 8(%esp),%edi /* string address */
+ movl 12(%esp),%eax /* set character to search for */
+ movl 16(%esp),%ecx /* set length of search */
+ testl %esp,%esp /* clear Z flag, for len == 0 */
+ cld /* set search forward */
+ repne /* search! */
+ scasb
+ jnz L1 /* scan failed, return null */
+ leal -1(%edi),%eax /* adjust result of scan */
+ popl %edi
+ ret
+ .align 2,0x90
+L1: xorl %eax,%eax
+ popl %edi
+ ret
diff --git a/lib/libc/i386/string/memcmp.S b/lib/libc/i386/string/memcmp.S
new file mode 100644
index 0000000..a362533
--- /dev/null
+++ b/lib/libc/i386/string/memcmp.S
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * memcmp (void *b1, void *b2, size_t len)
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(memcmp)
+ pushl %edi
+ pushl %esi
+ movl 12(%esp),%edi
+ movl 16(%esp),%esi
+ cld /* set compare direction forward */
+
+ movl 20(%esp),%ecx /* compare by words */
+ shrl $2,%ecx
+ repe
+ cmpsl
+ jne L5 /* do we match so far? */
+
+ movl 20(%esp),%ecx /* compare remainder by bytes */
+ andl $3,%ecx
+ repe
+ cmpsb
+ jne L6 /* do we match? */
+
+ xorl %eax,%eax /* we match, return zero */
+ popl %esi
+ popl %edi
+ ret
+
+L5: movl $4,%ecx /* We know that one of the next */
+ subl %ecx,%edi /* four pairs of bytes do not */
+ subl %ecx,%esi /* match. */
+ repe
+ cmpsb
+L6: movzbl -1(%edi),%eax /* Perform unsigned comparison */
+ movzbl -1(%esi),%edx
+ subl %edx,%eax
+ popl %esi
+ popl %edi
+ ret
diff --git a/lib/libc/i386/string/memcpy.S b/lib/libc/i386/string/memcpy.S
new file mode 100644
index 0000000..1617c71
--- /dev/null
+++ b/lib/libc/i386/string/memcpy.S
@@ -0,0 +1,2 @@
+#define MEMCOPY
+#include "bcopy.S"
diff --git a/lib/libc/i386/string/memmove.S b/lib/libc/i386/string/memmove.S
new file mode 100644
index 0000000..f5a94ed
--- /dev/null
+++ b/lib/libc/i386/string/memmove.S
@@ -0,0 +1,2 @@
+#define MEMMOVE
+#include "bcopy.S"
diff --git a/lib/libc/i386/string/memset.S b/lib/libc/i386/string/memset.S
new file mode 100644
index 0000000..5db1661
--- /dev/null
+++ b/lib/libc/i386/string/memset.S
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * memset(void *b, int c, size_t len)
+ * write len bytes of value c (converted to an unsigned char) to
+ * the string b.
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(memset)
+ pushl %edi
+ pushl %ebx
+ movl 12(%esp),%edi
+ movzbl 16(%esp),%eax /* unsigned char, zero extend */
+ movl 20(%esp),%ecx
+ pushl %edi /* push address of buffer */
+
+ cld /* set fill direction forward */
+
+ /*
+ * if the string is too short, it's really not worth the overhead
+ * of aligning to word boundries, etc. So we jump to a plain
+ * unaligned set.
+ */
+ cmpl $0x0f,%ecx
+ jle L1
+
+ movb %al,%ah /* copy char to all bytes in word */
+ movl %eax,%edx
+ sall $16,%eax
+ orl %edx,%eax
+
+ movl %edi,%edx /* compute misalignment */
+ negl %edx
+ andl $3,%edx
+ movl %ecx,%ebx
+ subl %edx,%ebx
+
+ movl %edx,%ecx /* set until word aligned */
+ rep
+ stosb
+
+ movl %ebx,%ecx
+ shrl $2,%ecx /* set by words */
+ rep
+ stosl
+
+ movl %ebx,%ecx /* set remainder by bytes */
+ andl $3,%ecx
+L1: rep
+ stosb
+
+ popl %eax /* pop address of buffer */
+ popl %ebx
+ popl %edi
+ ret
diff --git a/lib/libc/i386/string/rindex.S b/lib/libc/i386/string/rindex.S
new file mode 100644
index 0000000..6e023d1
--- /dev/null
+++ b/lib/libc/i386/string/rindex.S
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * rindex(s, c)
+ * return a pointer to the last occurance of the character c in
+ * string s, or NULL if c does not occur in the string.
+ *
+ * %edx - pointer iterating through string
+ * %eax - pointer to last occurance of 'c'
+ * %cl - character we're comparing against
+ * %bl - character at %edx
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(rindex)
+ pushl %ebx
+ movl 8(%esp),%edx
+ movb 12(%esp),%cl
+ xorl %eax,%eax /* init pointer to null */
+ .align 2,0x90
+L1:
+ movb (%edx),%bl
+ cmpb %bl,%cl
+ jne L2
+ movl %edx,%eax
+L2:
+ incl %edx
+ testb %bl,%bl /* null terminator??? */
+ jne L1
+ popl %ebx
+ ret
diff --git a/lib/libc/i386/string/strcat.S b/lib/libc/i386/string/strcat.S
new file mode 100644
index 0000000..9ec6053
--- /dev/null
+++ b/lib/libc/i386/string/strcat.S
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * strcat(s, append)
+ * append a copy of the null-terminated string "append" to the end
+ * of the null-terminated string s, then add a terminating `\0'.
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+/*
+ * I've unrolled the loop eight times: large enough to make a
+ * significant difference, and small enough not to totally trash the
+ * cashe.
+ */
+
+ENTRY(strcat)
+ pushl %edi /* save edi */
+ movl 8(%esp),%edi /* dst address */
+ movl 12(%esp),%edx /* src address */
+ pushl %edi /* push destination address */
+
+ cld /* set search forward */
+ xorl %eax,%eax /* set search for null terminator */
+ movl $-1,%ecx /* set search for lots of characters */
+ repne /* search! */
+ scasb
+
+ leal -1(%edi),%ecx /* correct dst address */
+
+ .align 2,0x90
+L1: movb (%edx),%al /* unroll loop, but not too much */
+ movb %al,(%ecx)
+ testb %al,%al
+ je L2
+ movb 1(%edx),%al
+ movb %al,1(%ecx)
+ testb %al,%al
+ je L2
+ movb 2(%edx),%al
+ movb %al,2(%ecx)
+ testb %al,%al
+ je L2
+ movb 3(%edx),%al
+ movb %al,3(%ecx)
+ testb %al,%al
+ je L2
+ movb 4(%edx),%al
+ movb %al,4(%ecx)
+ testb %al,%al
+ je L2
+ movb 5(%edx),%al
+ movb %al,5(%ecx)
+ testb %al,%al
+ je L2
+ movb 6(%edx),%al
+ movb %al,6(%ecx)
+ testb %al,%al
+ je L2
+ movb 7(%edx),%al
+ movb %al,7(%ecx)
+ addl $8,%edx
+ addl $8,%ecx
+ testb %al,%al
+ jne L1
+L2: popl %eax /* pop destination address */
+ popl %edi /* restore edi */
+ ret
diff --git a/lib/libc/i386/string/strchr.S b/lib/libc/i386/string/strchr.S
new file mode 100644
index 0000000..a483edd
--- /dev/null
+++ b/lib/libc/i386/string/strchr.S
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * strchr(s, c)
+ * return a pointer to the first occurance of the character c in
+ * string s, or NULL if c does not occur in the string.
+ *
+ * %edx - pointer iterating through string
+ * %eax - pointer to first occurance of 'c'
+ * %cl - character we're comparing against
+ * %bl - character at %edx
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(strchr)
+ pushl %ebx
+ movl 8(%esp),%eax
+ movb 12(%esp),%cl
+ .align 2,0x90
+L1:
+ movb (%eax),%bl
+ cmpb %bl,%cl /* found char??? */
+ je L2
+ incl %eax
+ testb %bl,%bl /* null terminator??? */
+ jne L1
+ xorl %eax,%eax
+L2:
+ popl %ebx
+ ret
diff --git a/lib/libc/i386/string/strcmp.S b/lib/libc/i386/string/strcmp.S
new file mode 100644
index 0000000..ecdb0b0
--- /dev/null
+++ b/lib/libc/i386/string/strcmp.S
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * strcmp(s1, s2)
+ * return an integer greater than, equal to, or less than 0,
+ * according as string s1 is greater than, equal to, or less
+ * than the string s2.
+ *
+ * %eax - pointer to s1
+ * %edx - pointer to s2
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+/*
+ * I've unrolled the loop eight times: large enough to make a
+ * significant difference, and small enough not to totally trash the
+ * cashe.
+ */
+
+ENTRY(strcmp)
+ movl 0x04(%esp),%eax
+ movl 0x08(%esp),%edx
+ jmp L2 /* Jump into the loop! */
+
+ .align 2,0x90
+L1: incl %eax
+ incl %edx
+L2: movb (%eax),%cl
+ testb %cl,%cl
+ je L3
+ cmpb %cl,(%edx)
+ jne L3
+ incl %eax
+ incl %edx
+ movb (%eax),%cl
+ testb %cl,%cl
+ je L3
+ cmpb %cl,(%edx)
+ jne L3
+ incl %eax
+ incl %edx
+ movb (%eax),%cl
+ testb %cl,%cl
+ je L3
+ cmpb %cl,(%edx)
+ jne L3
+ incl %eax
+ incl %edx
+ movb (%eax),%cl
+ testb %cl,%cl
+ je L3
+ cmpb %cl,(%edx)
+ jne L3
+ incl %eax
+ incl %edx
+ movb (%eax),%cl
+ testb %cl,%cl
+ je L3
+ cmpb %cl,(%edx)
+ jne L3
+ incl %eax
+ incl %edx
+ movb (%eax),%cl
+ testb %cl,%cl
+ je L3
+ cmpb %cl,(%edx)
+ jne L3
+ incl %eax
+ incl %edx
+ movb (%eax),%cl
+ testb %cl,%cl
+ je L3
+ cmpb %cl,(%edx)
+ jne L3
+ incl %eax
+ incl %edx
+ movb (%eax),%cl
+ testb %cl,%cl
+ je L3
+ cmpb %cl,(%edx)
+ je L1
+ .align 2, 0x90
+L3: movzbl (%eax),%eax /* unsigned comparison */
+ movzbl (%edx),%edx
+ subl %edx,%eax
+ ret
diff --git a/lib/libc/i386/string/strcpy.S b/lib/libc/i386/string/strcpy.S
new file mode 100644
index 0000000..d8e673a
--- /dev/null
+++ b/lib/libc/i386/string/strcpy.S
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * strcpy (dst, src)
+ * copy the string src to dst.
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+/*
+ * I've unrolled the loop eight times: large enough to make a
+ * significant difference, and small enough not to totally trash the
+ * cashe.
+ */
+
+ENTRY(strcpy)
+ movl 4(%esp),%ecx /* dst address */
+ movl 8(%esp),%edx /* src address */
+ pushl %ecx /* push dst address */
+
+ .align 2,0x90
+L1: movb (%edx),%al /* unroll loop, but not too much */
+ movb %al,(%ecx)
+ testb %al,%al
+ je L2
+ movb 1(%edx),%al
+ movb %al,1(%ecx)
+ testb %al,%al
+ je L2
+ movb 2(%edx),%al
+ movb %al,2(%ecx)
+ testb %al,%al
+ je L2
+ movb 3(%edx),%al
+ movb %al,3(%ecx)
+ testb %al,%al
+ je L2
+ movb 4(%edx),%al
+ movb %al,4(%ecx)
+ testb %al,%al
+ je L2
+ movb 5(%edx),%al
+ movb %al,5(%ecx)
+ testb %al,%al
+ je L2
+ movb 6(%edx),%al
+ movb %al,6(%ecx)
+ testb %al,%al
+ je L2
+ movb 7(%edx),%al
+ movb %al,7(%ecx)
+ addl $8,%edx
+ addl $8,%ecx
+ testb %al,%al
+ jne L1
+L2: popl %eax /* pop dst address */
+ ret
diff --git a/lib/libc/i386/string/strlen.S b/lib/libc/i386/string/strlen.S
new file mode 100644
index 0000000..93190cf
--- /dev/null
+++ b/lib/libc/i386/string/strlen.S
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * strlen (s)
+ * compute the length of the string s.
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(strlen)
+ pushl %edi
+ movl 8(%esp),%edi /* string address */
+ cld /* set search forward */
+ xorl %eax,%eax /* set search for null terminator */
+ movl $-1,%ecx /* set search for lots of characters */
+ repne /* search! */
+ scasb
+ notl %ecx /* get length by taking complement */
+ leal -1(%ecx),%eax /* and subtracting one */
+ popl %edi
+ ret
diff --git a/lib/libc/i386/string/strncmp.S b/lib/libc/i386/string/strncmp.S
new file mode 100644
index 0000000..62686dc
--- /dev/null
+++ b/lib/libc/i386/string/strncmp.S
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 1993,94 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * strncmp(s1, s2, n)
+ * return an integer greater than, equal to, or less than 0,
+ * according as the first n characters of string s1 is greater
+ * than, equal to, or less than the string s2.
+ *
+ * %eax - pointer to s1
+ * %ecx - pointer to s2
+ * %edx - length
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+/*
+ * I've unrolled the loop eight times: large enough to make a
+ * significant difference, and small enough not to totally trash the
+ * cache.
+ *
+ * TODO: change all the jz's back to je for consistency.
+ */
+
+ENTRY(strncmp)
+ pushl %ebx
+ movl 8(%esp),%eax
+ movl 12(%esp),%ecx
+ movl 16(%esp),%edx
+ testl %edx,%edx
+ jmp L2 /* Jump into the loop! */
+
+ .align 2,0x90
+L1: incl %eax
+ incl %ecx
+ decl %edx
+L2: jz L4 /* strings are equal */
+ movb (%eax),%bl
+ testb %bl,%bl
+ jz L3
+ cmpb %bl,(%ecx)
+ jne L3
+
+/*
+ * XXX it might be best to move the next 4 instructions to the end of the
+ * unrolled part of the loop. The unrolled part would then be
+ * movb n(%eax),%bl; testb %bl, %bl; je L3; cmpb n(%ecx); jne L3
+ * or maybe better
+ * movb n(%eax),%bl; cmpb n(%ecx); jne L3; testb %bl,%bl; je return_0
+ * for n = 0, 1, ..., 8. The end of the loop would be
+ * L1: addl $8,%eax; addl $8,%ecx; subl $8,%edx; cmpl $8,%edx; jae Lx
+ * where residual counts of 0 to 7 are handled at Lx. However, this would
+ * be slower for short strings. Cache effects are probably not so
+ * important because we are only handling a byte at a time.
+ */
+ incl %eax
+ incl %ecx
+ decl %edx
+ jz L4
+ movb (%eax),%bl
+ testb %bl,%bl
+ jz L3
+ cmpb %bl,(%ecx)
+ jne L3
+
+ incl %eax
+ incl %ecx
+ decl %edx
+ jz L4
+ movb (%eax),%bl
+ testb %bl,%bl
+ jz L3
+ cmpb %bl,(%ecx)
+ jne L3
+
+ incl %eax
+ incl %ecx
+ decl %edx
+ jz L4
+ movb (%eax),%bl
+ testb %bl,%bl
+ jz L3
+ cmpb %bl,(%ecx)
+ jne L3
+
+ incl %eax
+ incl %ecx
+ decl %edx
+ jz L4
+ movb (%eax),%bl
+ testb %bl,%bl
+ jz L3
+ cmpb %bl,(%ecx)
+ jne L3
+
+ incl %eax
+ incl %ecx
+ decl %edx
+ jz L4
+ movb (%eax),%bl
+ testb %bl,%bl
+ jz L3
+ cmpb %bl,(%ecx)
+ jne L3
+
+ incl %eax
+ incl %ecx
+ decl %edx
+ jz L4
+ movb (%eax),%bl
+ testb %bl,%bl
+ jz L3
+ cmpb %bl,(%ecx)
+ jne L3
+
+ incl %eax
+ incl %ecx
+ decl %edx
+ jz L4
+ movb (%eax),%bl
+ testb %bl,%bl
+ jz L3
+ cmpb %bl,(%ecx)
+ je L1
+
+ .align 2,0x90
+L3: movzbl (%eax),%eax /* unsigned comparison */
+ movzbl (%ecx),%ecx
+ subl %ecx,%eax
+ popl %ebx
+ ret
+ .align 2,0x90
+L4: xorl %eax,%eax
+ popl %ebx
+ ret
diff --git a/lib/libc/i386/string/strrchr.S b/lib/libc/i386/string/strrchr.S
new file mode 100644
index 0000000..0cc08d7
--- /dev/null
+++ b/lib/libc/i386/string/strrchr.S
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 1993 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
+
+#include "DEFS.h"
+
+/*
+ * strrchr(s, c)
+ * return a pointer to the last occurance of the character c in
+ * string s, or NULL if c does not occur in the string.
+ *
+ * %edx - pointer iterating through string
+ * %eax - pointer to last occurance of 'c'
+ * %cl - character we're comparing against
+ * %bl - character at %edx
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(strrchr)
+ pushl %ebx
+ movl 8(%esp),%edx
+ movb 12(%esp),%cl
+ xorl %eax,%eax /* init pointer to null */
+ .align 2,0x90
+L1:
+ movb (%edx),%bl
+ cmpb %bl,%cl
+ jne L2
+ movl %edx,%eax
+L2:
+ incl %edx
+ testb %bl,%bl /* null terminator??? */
+ jne L1
+ popl %ebx
+ ret
diff --git a/lib/libc/i386/string/swab.S b/lib/libc/i386/string/swab.S
new file mode 100644
index 0000000..717b7a2
--- /dev/null
+++ b/lib/libc/i386/string/swab.S
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 1993,94 Winning Strategies, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Winning Strategies, Inc.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif
+
+#include "DEFS.h"
+
+/*
+ * void
+ * swab (const void *src, void *dst, size_t len)
+ * copy len bytes from src to dst, swapping adjacent bytes
+ *
+ * On the i486, this code is negligibly faster than the code generated
+ * by gcc at about half the size. If my i386 databook is correct, it
+ * should be considerably faster than the gcc code on a i386.
+ *
+ * Written by:
+ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
+ */
+
+ENTRY(swab)
+ pushl %esi
+ pushl %edi
+ movl 12(%esp),%esi
+ movl 16(%esp),%edi
+ movl 20(%esp),%ecx
+
+ cld # set direction forward
+
+ shrl $1,%ecx
+ testl $7,%ecx # copy first group of 1 to 7 words
+ jz L2 # while swaping alternate bytes.
+ .align 2,0x90
+L1: lodsw
+ rorw $8,%ax
+ stosw
+ decl %ecx
+ testl $7,%ecx
+ jnz L1
+
+L2: shrl $3,%ecx # copy remainder 8 words at a time
+ jz L4 # while swapping alternate bytes.
+ .align 2,0x90
+L3: lodsw
+ rorw $8,%ax
+ stosw
+ lodsw
+ rorw $8,%ax
+ stosw
+ lodsw
+ rorw $8,%ax
+ stosw
+ lodsw
+ rorw $8,%ax
+ stosw
+ lodsw
+ rorw $8,%ax
+ stosw
+ lodsw
+ rorw $8,%ax
+ stosw
+ lodsw
+ rorw $8,%ax
+ stosw
+ lodsw
+ rorw $8,%ax
+ stosw
+ decl %ecx
+ jnz L3
+
+L4: popl %edi
+ popl %esi
+ ret
diff --git a/lib/libc/i386/sys/Makefile.inc b/lib/libc/i386/sys/Makefile.inc
new file mode 100644
index 0000000..0cf1aad
--- /dev/null
+++ b/lib/libc/i386/sys/Makefile.inc
@@ -0,0 +1,13 @@
+# from: Makefile.inc,v 1.1 1993/09/03 19:04:23 jtc Exp
+# $Id: Makefile.inc,v 1.4 1997/02/22 14:59:27 peter Exp $
+
+.PATH: ${.CURDIR}/../libc/${MACHINE}/sys
+
+SRCS+= i386_get_ldt.c i386_set_ldt.c
+
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN2+= i386/sys/i386_get_ldt.2
+
+MLINKS+=i386_get_ldt.2 i386_set_ldt.2
+.endif
diff --git a/lib/libc/i386/sys/Ovfork.S b/lib/libc/i386/sys/Ovfork.S
index c7e6b8a..e4ed257 100644
--- a/lib/libc/i386/sys/Ovfork.S
+++ b/lib/libc/i386/sys/Ovfork.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,12 +32,16 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)Ovfork.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+#include "DEFS.h"
#include "SYS.h"
/*
@@ -47,22 +51,49 @@
* %eax == pid of child in parent, %eax == pid of parent in child.
*
*/
- .set vfork,66
-.globl _vfork
-_vfork:
+ENTRY(vfork)
popl %ecx /* my rta into ecx */
- movl $vfork, %eax
- LCALL(7,0)
+ lea SYS_vfork,%eax
+ KERNCALL
jb verror
vforkok:
cmpl $0,%edx /* child process? */
jne child /* yes */
jmp parent
-.globl _errno
+#ifdef _THREAD_SAFE
+ /*
+ * Threaded version using __error().
+ */
+ .globl CNAME(__error)
+ .type CNAME(__error),@function
+verror:
+ pushl %eax
+#ifdef PIC
+ call PIC_PLT(CNAME(__error))
+#else
+ call CNAME(__error)
+#endif
+ popl %ecx
+ movl %ecx,(%eax)
+ movl $-1,%eax
+ movl $-1,%edx
+#else /* !_THREAD_SAFE */
+ /*
+ * Non-threaded version using global errno.
+ */
+ .globl CNAME(errno)
verror:
- movl %eax,_errno
+#ifdef PIC
+ PIC_PROLOGUE
+ movl PIC_GOT(CNAME(errno)), %edx
+ movl %eax,(%edx)
+ PIC_EPILOGUE
+#else
+ movl %eax,CNAME(errno)
+#endif
movl $-1,%eax
+#endif /* !_THREAD_SAFE */
jmp %ecx
child:
movl $0,%eax
diff --git a/lib/libc/i386/sys/brk.S b/lib/libc/i386/sys/brk.S
index f85186c..4fdf0c6 100644
--- a/lib/libc/i386/sys/brk.S
+++ b/lib/libc/i386/sys/brk.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,34 +32,60 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)brk.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
-#define SYS_brk 17
-
- .globl curbrk
- .globl minbrk
+ .globl HIDENAME(curbrk)
+ .globl HIDENAME(minbrk)
ENTRY(_brk)
jmp ok
ENTRY(brk)
+#ifdef PIC
+ movl 4(%esp),%eax
+ PIC_PROLOGUE
+ movl PIC_GOT(HIDENAME(curbrk)),%edx # set up GOT addressing
+ movl PIC_GOT(HIDENAME(minbrk)),%ecx #
+ PIC_EPILOGUE
+ cmpl %eax,(%ecx)
+ jbe ok
+ movl (%ecx),%eax
+ movl %eax,4(%esp)
+ok:
+ lea SYS_break,%eax
+ KERNCALL
+ jb err
+ movl 4(%esp),%eax
+ movl %eax,(%edx)
+ movl $0,%eax
+ ret
+err:
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror))
+
+#else
+
movl 4(%esp),%eax
- cmpl %eax,minbrk
- jl ok
- movl minbrk,%eax
+ cmpl %eax,HIDENAME(minbrk)
+ jbe ok
+ movl HIDENAME(minbrk),%eax
movl %eax,4(%esp)
ok:
- lea SYS_brk,%eax
- LCALL(7,0)
+ lea SYS_break,%eax
+ KERNCALL
jb err
movl 4(%esp),%eax
- movl %eax,curbrk
+ movl %eax,HIDENAME(curbrk)
movl $0,%eax
ret
err:
- jmp cerror
+ jmp HIDENAME(cerror)
+#endif
diff --git a/lib/libc/i386/sys/cerror.S b/lib/libc/i386/sys/cerror.S
index cc2d82f..2d8f935 100644
--- a/lib/libc/i386/sys/cerror.S
+++ b/lib/libc/i386/sys/cerror.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,16 +32,56 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)cerror.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
- .globl _errno
-cerror:
- movl %eax,_errno
+ .globl HIDENAME(cerror)
+
+#ifdef _THREAD_SAFE
+ /*
+ * Threaded version using __error().
+ */
+ .globl CNAME(__error)
+ .type CNAME(__error),@function
+HIDENAME(cerror):
+ pushl %eax
+#ifdef PIC
+ /* The caller must execute the PIC prologue before jumping to cerror. */
+ call PIC_PLT(CNAME(__error))
+ popl %ecx
+ PIC_EPILOGUE
+#else
+ call CNAME(__error)
+ popl %ecx
+#endif
+ movl %ecx,(%eax)
+ movl $-1,%eax
+ movl $-1,%edx
+ ret
+
+#else /* _THREAD_SAFE */
+ /*
+ * Non-threaded version using global errno.
+ */
+ .globl CNAME(errno)
+HIDENAME(cerror):
+#ifdef PIC
+ /* The caller must execute the PIC prologue before jumping to cerror. */
+ movl PIC_GOT(CNAME(errno)),%ecx
+ movl %eax,(%ecx)
+ PIC_EPILOGUE
+#else
+ movl %eax,CNAME(errno)
+#endif
movl $-1,%eax
+ movl $-1,%edx
ret
+#endif /* _THREAD_SAFE */
diff --git a/lib/libc/i386/sys/exect.S b/lib/libc/i386/sys/exect.S
index 6b42cf8..af0d2ee 100644
--- a/lib/libc/i386/sys/exect.S
+++ b/lib/libc/i386/sys/exect.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,11 +32,14 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)exect.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
#include <machine/psl.h>
@@ -48,5 +51,6 @@ ENTRY(exect)
orl $ PSL_T,%edx
pushl %edx
popf
- LCALL(7,0)
- jmp cerror /* exect(file, argv, env); */
+ KERNCALL
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror)) /* exect(file, argv, env); */
diff --git a/lib/libc/i386/sys/fork.S b/lib/libc/i386/sys/fork.S
index ff4d948..ab908a9 100644
--- a/lib/libc/i386/sys/fork.S
+++ b/lib/libc/i386/sys/fork.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,15 +32,18 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)fork.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
-SYSCALL(fork)
+PSYSCALL(fork)
cmpl $0,%edx /* parent, since %edx == 0 in parent, 1 in child */
je 1f
movl $0,%eax
diff --git a/lib/libc/i386/sys/i386_get_ldt.2 b/lib/libc/i386/sys/i386_get_ldt.2
new file mode 100644
index 0000000..ddf6e0c
--- /dev/null
+++ b/lib/libc/i386/sys/i386_get_ldt.2
@@ -0,0 +1,98 @@
+.\" Copyright (c) 1980, 1991 Regents of the University of California.
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\" from: @(#)fork.2 6.5 (Berkeley) 3/10/91
+.\" $Id$
+.\"
+.Dd September 20, 1993
+.Dt I386_GET_LDT 2
+.Os FreeBSD
+.Sh NAME
+.Nm i386_get_ldt ,
+.Nm i386_set_ldt
+.Nd manage i386 per-process Local Descriptor Table entries
+.Sh SYNOPSIS
+.Fd #include <machine/segments.h>
+.Fd #include <machine/sysarch.h>
+.Ft int
+.Fn i386_get_ldt "int start_sel" "union descriptor *descs" "int num_sels"
+.Ft int
+.Fn i386_set_ldt "int start_sel" "union descriptor *descs" "int num_sels"
+.Sh DESCRIPTION
+.Fn i386_get_ldt
+will return the list of i386 descriptors that the process has in its
+LDT.
+.Fn i386_set_ldt
+will set a list of i386 descriptors for the current process in its
+LDT.
+Both routines accept a starting selector number
+.Fa start_sel
+, an array of memory that
+will contain the descriptors to be set or returned
+.Fa descs
+, and the number of entries to set or return
+.Fa num_sels .
+.Pp
+The argument
+.Fa descs
+can be either segment_descriptor or gate_descriptor and are defined in
+.Fd <i386/segments.h> .
+These structures are defined by the architecure
+as disjoint bit-fields, so care must be taken in constructing them.
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn i386_get_ldt
+returns the number of descriptors currently in the LDT.
+.Fn i386_set_ldt
+returns the first selector set.
+Otherwise, a value of -1 is returned and the global
+variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn i386_get_ldt
+and
+.Fn i386_set_ldt
+will fail if:
+.Bl -tag -width [EINVAL]
+.It Bq Er EINVAL
+An inappropriate parameter was used for
+.Fa start_sel
+or
+.Fa num_sels .
+.It Bq Er EACESS
+The caller attempted to use a descriptor that would
+circumvent protection or cause a failure.
+.El
+.Sh REFERENCES
+i386 Microprocessor Programmer's Reference Manual, Intel
+.Sh WARNING
+You can really hose your process using this.
diff --git a/lib/libc/i386/sys/i386_get_ldt.c b/lib/libc/i386/sys/i386_get_ldt.c
new file mode 100644
index 0000000..628052b
--- /dev/null
+++ b/lib/libc/i386/sys/i386_get_ldt.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 1993 John Brezak
+ * All rights reserved.
+ *
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif /* LIBC_RCS and not lint */
+
+#include <sys/cdefs.h>
+#include <machine/segments.h>
+#include <machine/sysarch.h>
+
+struct parms {
+ int start;
+ union descriptor *descs;
+ int num;
+};
+
+int
+i386_get_ldt(int start, union descriptor *descs, int num)
+{
+ struct parms p;
+
+ p.start = start;
+ p.descs = descs;
+ p.num = num;
+
+ return sysarch(I386_GET_LDT, (char *)&p);
+}
diff --git a/lib/libc/i386/sys/i386_set_ldt.c b/lib/libc/i386/sys/i386_set_ldt.c
new file mode 100644
index 0000000..6a54b30
--- /dev/null
+++ b/lib/libc/i386/sys/i386_set_ldt.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 1993 John Brezak
+ * All rights reserved.
+ *
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#if defined(LIBC_RCS) && !defined(lint)
+static const char rcsid[] = "$Id$";
+#endif /* LIBC_RCS and not lint */
+
+#include <sys/cdefs.h>
+#include <machine/segments.h>
+#include <machine/sysarch.h>
+
+struct parms {
+ int start;
+ union descriptor *descs;
+ int num;
+};
+
+int
+i386_set_ldt(int start, union descriptor *descs, int num)
+{
+ struct parms p;
+
+ p.start = start;
+ p.descs = descs;
+ p.num = num;
+
+ return sysarch(I386_SET_LDT, (char *)&p);
+}
diff --git a/lib/libc/i386/sys/mount.S b/lib/libc/i386/sys/mount.S
index ac418f7..85b8837 100644
--- a/lib/libc/i386/sys/mount.S
+++ b/lib/libc/i386/sys/mount.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,11 +32,14 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)mount.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
diff --git a/lib/libc/i386/sys/pipe.S b/lib/libc/i386/sys/pipe.S
index 6469397..637b86f 100644
--- a/lib/libc/i386/sys/pipe.S
+++ b/lib/libc/i386/sys/pipe.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,15 +32,18 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)pipe.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
-SYSCALL(pipe)
+PSYSCALL(pipe)
movl 4(%esp),%ecx
movl %eax,(%ecx)
movl %edx,4(%ecx)
diff --git a/lib/libc/i386/sys/ptrace.S b/lib/libc/i386/sys/ptrace.S
index 98994ea..018a02c 100644
--- a/lib/libc/i386/sys/ptrace.S
+++ b/lib/libc/i386/sys/ptrace.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,20 +32,31 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)ptrace.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
ENTRY(ptrace)
xorl %eax,%eax
- movl %eax,_errno
+#ifdef PIC
+ PIC_PROLOGUE
+ movl PIC_GOT(CNAME(errno)),%edx
+ movl %eax,(%edx)
+ PIC_EPILOGUE
+#else
+ movl %eax,CNAME(errno)
+#endif
lea SYS_ptrace,%eax
- LCALL(7,0)
+ KERNCALL
jb err
ret
err:
- jmp cerror
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror))
diff --git a/lib/libc/i386/sys/reboot.S b/lib/libc/i386/sys/reboot.S
index 020bea0..70049b2 100644
--- a/lib/libc/i386/sys/reboot.S
+++ b/lib/libc/i386/sys/reboot.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,11 +32,14 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)reboot.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
diff --git a/lib/libc/i386/sys/rfork.S b/lib/libc/i386/sys/rfork.S
new file mode 100644
index 0000000..189d399
--- /dev/null
+++ b/lib/libc/i386/sys/rfork.S
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ *
+ * $Id$
+ */
+
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
+
+#include "SYS.h"
+
+PSYSCALL(rfork)
+ cmpl $0,%edx /* parent, since %edx == 0 in parent, 1 in child */
+ je 1f
+ movl $0,%eax
+1:
+ ret /* pid = rfork(); */
diff --git a/lib/libc/i386/sys/sbrk.S b/lib/libc/i386/sys/sbrk.S
index 7fecd93..a3afd89 100644
--- a/lib/libc/i386/sys/sbrk.S
+++ b/lib/libc/i386/sys/sbrk.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,34 +32,64 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)sbrk.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
-#define SYS_brk 17
-
- .globl _end
- .globl minbrk
- .globl curbrk
+ .globl CNAME(end)
+ .globl HIDENAME(minbrk)
+ .globl HIDENAME(curbrk)
.data
-minbrk: .long _end
-curbrk: .long _end
+HIDENAME(minbrk): .long CNAME(end)
+HIDENAME(curbrk): .long CNAME(end)
.text
ENTRY(sbrk)
+#ifdef PIC
+ movl 4(%esp),%ecx
+ PIC_PROLOGUE
+ movl PIC_GOT(HIDENAME(curbrk)),%edx
+ movl (%edx),%eax
+ PIC_EPILOGUE
+ testl %ecx,%ecx
+ jz back
+ addl %eax,4(%esp)
+ lea SYS_break,%eax
+ KERNCALL
+ jb err
+ PIC_PROLOGUE
+ movl PIC_GOT(HIDENAME(curbrk)),%edx
+ movl (%edx),%eax
+ addl %ecx,(%edx)
+ PIC_EPILOGUE
+back:
+ ret
+err:
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror))
+
+#else /* !PIC */
+
movl 4(%esp),%ecx
- movl curbrk,%eax
+ movl HIDENAME(curbrk),%eax
+ testl %ecx,%ecx
+ jz back
addl %eax,4(%esp)
- lea SYS_brk,%eax
- LCALL(7,0)
+ lea SYS_break,%eax
+ KERNCALL
jb err
- movl curbrk,%eax
- addl %ecx,curbrk
+ movl HIDENAME(curbrk),%eax
+ addl %ecx,HIDENAME(curbrk)
+back:
ret
err:
- jmp cerror
+ jmp HIDENAME(cerror)
+#endif /* PIC */
diff --git a/lib/libc/i386/sys/setlogin.S b/lib/libc/i386/sys/setlogin.S
index 43d31d7..7bcf3bd 100644
--- a/lib/libc/i386/sys/setlogin.S
+++ b/lib/libc/i386/sys/setlogin.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,16 +32,28 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
- .asciz "@(#)setlogin.s 8.1 (Berkeley) 6/4/93"
-#endif /* LIBC_SCCS and not lint */
+#if defined(LIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* LIBC_RCS and not lint */
#include "SYS.h"
-.globl __logname_valid /* in getlogin() */
+.globl CNAME(_logname_valid) /* in getlogin() */
SYSCALL(setlogin)
- movl $0,__logname_valid
+#ifdef PIC
+ PIC_PROLOGUE
+ pushl %eax
+ movl PIC_GOT(CNAME(_logname_valid)),%eax
+ movl $0,(%eax)
+ popl %eax
+ PIC_EPILOGUE
+#else
+ movl $0,CNAME(_logname_valid)
+#endif
ret /* setlogin(name) */
diff --git a/lib/libc/i386/sys/sigpending.S b/lib/libc/i386/sys/sigpending.S
index 63b06a2..2ce0df8 100644
--- a/lib/libc/i386/sys/sigpending.S
+++ b/lib/libc/i386/sys/sigpending.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,15 +32,18 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)sigpending.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
-SYSCALL(sigpending)
+PSYSCALL(sigpending)
movl 4(%esp),%ecx # fetch pointer to...
movl %eax,(%ecx) # store old mask
xorl %eax,%eax
diff --git a/lib/libc/i386/sys/sigprocmask.S b/lib/libc/i386/sys/sigprocmask.S
index ef91e80..6dbc8c9 100644
--- a/lib/libc/i386/sys/sigprocmask.S
+++ b/lib/libc/i386/sys/sigprocmask.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,18 +32,26 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)sigprocmask.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
err:
- jmp cerror
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror))
+#ifdef _THREAD_SAFE
+ENTRY(_thread_sys_sigprocmask)
+#else
ENTRY(sigprocmask)
+#endif
movl 8(%esp),%ecx # fetch new sigset pointer
cmpl $0,%ecx # check new sigset pointer
jne 1f # if not null, indirect
@@ -52,8 +60,8 @@ ENTRY(sigprocmask)
jmp 2f
1: movl (%ecx),%ecx # fetch indirect ...
movl %ecx,8(%esp) # to new mask arg
-2: movl $ SYS_sigprocmask , %eax
- LCALL(0x7,0)
+2: lea SYS_sigprocmask,%eax
+ KERNCALL
jb err
movl 12(%esp),%ecx # fetch old mask requested
cmpl $0,%ecx # test if old mask requested
diff --git a/lib/libc/i386/sys/sigreturn.S b/lib/libc/i386/sys/sigreturn.S
index 1bd6a3b..65deb40 100644
--- a/lib/libc/i386/sys/sigreturn.S
+++ b/lib/libc/i386/sys/sigreturn.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,23 +32,21 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)sigreturn.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
/*
- * We must preserve the state of the registers as the user has set them up.
+ * NOTE: If the profiling ENTRY() code ever changes any registers, they
+ * must be saved. On FreeBSD, this is not the case.
*/
-#ifdef PROF
-#undef ENTRY
-#define ENTRY(x) \
- .globl _/**/x; .align 2; _/**/x: pusha ; \
- .data; 1:; .long 0; .text; movl $1b,%eax; call mcount; popa ; nop
-#endif /* PROF */
-SYSCALL(sigreturn)
+PSYSCALL(sigreturn)
ret
diff --git a/lib/libc/i386/sys/sigsuspend.S b/lib/libc/i386/sys/sigsuspend.S
index afbc1ba..660eabf 100644
--- a/lib/libc/i386/sys/sigsuspend.S
+++ b/lib/libc/i386/sys/sigsuspend.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,23 +32,31 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)sigsuspend.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
err:
- jmp cerror
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror))
+#ifdef _THREAD_SAFE
+ENTRY(_thread_sys_sigsuspend)
+#else
ENTRY(sigsuspend)
+#endif
movl 4(%esp),%eax # fetch mask arg
movl (%eax),%eax # indirect to mask arg
movl %eax,4(%esp)
- movl $ SYS_sigsuspend ,%eax
- LCALL(0x7,0)
+ lea SYS_sigsuspend,%eax
+ KERNCALL
jb err
xorl %eax,%eax # shouldn t happen
ret
diff --git a/lib/libc/i386/sys/syscall.S b/lib/libc/i386/sys/syscall.S
index 189f4dd..711a770 100644
--- a/lib/libc/i386/sys/syscall.S
+++ b/lib/libc/i386/sys/syscall.S
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
@@ -32,11 +32,14 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)syscall.s 8.1 (Berkeley) 6/4/93"
-#endif /* SYSLIBC_SCCS and not lint */
+#if defined(SYSLIBC_RCS) && !defined(lint)
+ .text
+ .asciz "$Id$"
+#endif /* SYSLIBC_RCS and not lint */
#include "SYS.h"
@@ -44,8 +47,11 @@ ENTRY(syscall)
pop %ecx /* rta */
pop %eax /* syscall number */
push %ecx
- LCALL(7,0)
+ KERNCALL
+ push %ecx /* need to push a word to keep stack frame intact
+ upon return; the word must be the return address. */
jb 1f
ret
1:
- jmp cerror
+ PIC_PROLOGUE
+ jmp PIC_PLT(HIDENAME(cerror))
diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc
index 8d03f24..57ffdcc 100644
--- a/lib/libc/locale/Makefile.inc
+++ b/lib/libc/locale/Makefile.inc
@@ -1,13 +1,26 @@
-# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
# locale sources
-.PATH: ${.CURDIR}/${MACHINE}/locale ${.CURDIR}/locale
+.PATH: ${.CURDIR}/../libc/${MACHINE}/locale ${.CURDIR}/../libc/locale
SRCS+= ansi.c ctype.c euc.c frune.c isctype.c lconv.c localeconv.c \
- mbrune.c none.c rune.c setlocale.c table.c utf2.c
+ mbrune.c none.c rune.c setlocale.c table.c utf2.c setrunelocale.c \
+ runetype.c tolower.c toupper.c nomacros.c collate.c setinvalidrune.c \
+ collcmp.c
-MAN3+= ctype.0 isalnum.0 isalpha.0 isascii.0 isblank.0 iscntrl.0 \
- isdigit.0 isgraph.0 islower.0 isprint.0 ispunct.0 isspace.0 \
- isupper.0 isxdigit.0 mbrune.0 multibyte.0 rune.0 setlocale.0 \
- toascii.0 tolower.0 toupper.0
-MAN4+= euc.0 utf2.0
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN3+= locale/ctype.3 locale/isalnum.3 locale/isalpha.3 locale/isascii.3 \
+ locale/isblank.3 locale/iscntrl.3 locale/isdigit.3 locale/isgraph.3 \
+ locale/islower.3 locale/isprint.3 locale/ispunct.3 locale/isspace.3 \
+ locale/isupper.3 locale/isxdigit.3 locale/mbrune.3 locale/multibyte.3 \
+ locale/rune.3 locale/setlocale.3 locale/toascii.3 locale/tolower.3 \
+ locale/toupper.3
+MAN4+= locale/euc.4 locale/utf2.4
+MLINKS+= rune.3 setrunelocale.3 rune.3 setinvalidrune.3 rune.3 sgetrune.3 \
+ rune.3 sputrune.3 rune.3 fgetrune.3 rune.3 fungetrune.3 \
+ rune.3 fputrune.3 mbrune.3 mbrrune.3 mbrune.3 mbmb.3 \
+ multibyte.3 mblen.3 multibyte.3 mbstowcs.3 multibyte.3 mbtowc.3 \
+ multibyte.3 wcstombs.3 multibyte.3 wctomb.3 setlocale.3 localeconv.3
+.endif
diff --git a/lib/libc/locale/ansi.c b/lib/libc/locale/ansi.c
index e5c8e8f..a5a3362 100644
--- a/lib/libc/locale/ansi.c
+++ b/lib/libc/locale/ansi.c
@@ -53,7 +53,7 @@ mblen(s, n)
if (s == 0 || *s == 0)
return (0); /* No support for state dependent encodings. */
- if (sgetrune(s, (int)n, &e) == _INVALID_RUNE)
+ if (sgetrune(s, n, &e) == _INVALID_RUNE)
return (s - e);
return (e - s);
}
@@ -70,7 +70,7 @@ mbtowc(pwc, s, n)
if (s == 0 || *s == 0)
return (0); /* No support for state dependent encodings. */
- if ((r = sgetrune(s, (int)n, &e)) == _INVALID_RUNE)
+ if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE)
return (s - e);
if (pwc)
*pwc = r;
@@ -137,11 +137,12 @@ wcstombs(s, pwcs, n)
*s = 0;
break;
}
- if (!sputrune(*pwcs++, s, (int)n, &e))
+ if (!sputrune(*pwcs++, s, n, &e))
return (-1); /* encoding error */
if (!e) /* too long */
return (cnt);
cnt += e - s;
+ n -= e - s;
s = e;
}
return (cnt);
diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c
new file mode 100644
index 0000000..d1f03e7
--- /dev/null
+++ b/lib/libc/locale/collate.c
@@ -0,0 +1,197 @@
+/*-
+ * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
+ * at Electronni Visti IA, Kiev, Ukraine.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#include <rune.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sysexits.h>
+#include "collate.h"
+#include "setlocale.h"
+
+int __collate_load_error = 1;
+char __collate_version[STR_LEN];
+u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN];
+struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1];
+struct __collate_st_chain_pri __collate_chain_pri_table[TABLE_SIZE];
+
+#define FREAD(a, b, c, d) \
+ do { \
+ if(fread(a, b, c, d) != c) { \
+ fclose(d); \
+ return -1; \
+ } \
+ } while(0)
+
+void __collate_err(int ex, const char *f) __dead2;
+
+int
+__collate_load_tables(encoding)
+ char *encoding;
+{
+ char buf[PATH_MAX];
+ FILE *fp;
+ int save_load_error;
+
+ save_load_error = __collate_load_error;
+ __collate_load_error = 1;
+ if (!encoding) {
+ __collate_load_error = save_load_error;
+ return -1;
+ }
+ if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX"))
+ return 0;
+ if (!_PathLocale) {
+ __collate_load_error = save_load_error;
+ return -1;
+ }
+ /* Range checking not needed, encoding has fixed size */
+ (void) strcpy(buf, _PathLocale);
+ (void) strcat(buf, "/");
+ (void) strcat(buf, encoding);
+ (void) strcat(buf, "/LC_COLLATE");
+ if ((fp = fopen(buf, "r")) == NULL) {
+ __collate_load_error = save_load_error;
+ return -1;
+ }
+ FREAD(__collate_version, sizeof(__collate_version), 1, fp);
+ if (strcmp(__collate_version, COLLATE_VERSION) != 0) {
+ fclose(fp);
+ return -1;
+ }
+ FREAD(__collate_substitute_table, sizeof(__collate_substitute_table),
+ 1, fp);
+ FREAD(__collate_char_pri_table, sizeof(__collate_char_pri_table), 1,
+ fp);
+ FREAD(__collate_chain_pri_table, sizeof(__collate_chain_pri_table), 1,
+ fp);
+ fclose(fp);
+ __collate_load_error = 0;
+ return 0;
+}
+
+u_char *
+__collate_substitute(s)
+ const u_char *s;
+{
+ int dest_len = 0, len = 0;
+ int delta = strlen(s);
+ u_char *dest_str = NULL;
+
+ if(s == NULL || *s == '\0')
+ return __collate_strdup("");
+ while(*s) {
+ len += strlen(__collate_substitute_table[*s]);
+ while(dest_len <= len) {
+ if(!dest_str)
+ dest_str = calloc(dest_len = delta, 1);
+ else
+ dest_str = realloc(dest_str, dest_len += delta);
+ if(dest_str == NULL)
+ __collate_err(EX_OSERR, __FUNCTION__);
+ }
+ strcat(dest_str, __collate_substitute_table[*s++]);
+ }
+ return dest_str;
+}
+
+void
+__collate_lookup(t, len, prim, sec)
+ u_char *t;
+ int *len, *prim, *sec;
+{
+ struct __collate_st_chain_pri *p2;
+
+ *len = 1;
+ *prim = *sec = 0;
+ for(p2 = __collate_chain_pri_table; p2->str[0]; p2++) {
+ if(strncmp(t, p2->str, strlen(p2->str)) == 0) {
+ *len = strlen(p2->str);
+ *prim = p2->prim;
+ *sec = p2->sec;
+ return;
+ }
+ }
+ *prim = __collate_char_pri_table[*t].prim;
+ *sec = __collate_char_pri_table[*t].sec;
+}
+
+u_char *
+__collate_strdup(s)
+ u_char *s;
+{
+ u_char *t = strdup(s);
+
+ if (t == NULL)
+ __collate_err(EX_OSERR, __FUNCTION__);
+ return t;
+}
+
+void
+__collate_err(int ex, const char *f)
+{
+ extern char *__progname; /* Program name, from crt0. */
+ const char *s;
+ int serrno = errno;
+
+ s = __progname;
+ write(STDERR_FILENO, s, strlen(s));
+ write(STDERR_FILENO, ": ", 2);
+ s = f;
+ write(STDERR_FILENO, s, strlen(s));
+ write(STDERR_FILENO, ": ", 2);
+ s = strerror(serrno);
+ write(STDERR_FILENO, s, strlen(s));
+ write(STDERR_FILENO, "\n", 1);
+ exit(ex);
+}
+
+#ifdef COLLATE_DEBUG
+void
+__collate_print_tables()
+{
+ int i;
+ struct __collate_st_chain_pri *p2;
+
+ printf("Substitute table:\n");
+ for (i = 0; i < UCHAR_MAX + 1; i++)
+ if (i != *__collate_substitute_table[i])
+ printf("\t'%c' --> \"%s\"\n", i,
+ __collate_substitute_table[i]);
+ printf("Chain priority table:\n");
+ for (p2 = __collate_chain_pri_table; p2->str[0]; p2++)
+ printf("\t\"%s\" : %d %d\n\n", p2->str, p2->prim, p2->sec);
+ printf("Char priority table:\n");
+ for (i = 0; i < UCHAR_MAX + 1; i++)
+ printf("\t'%c' : %d %d\n", i, __collate_char_pri_table[i].prim,
+ __collate_char_pri_table[i].sec);
+}
+#endif
diff --git a/lib/libc/locale/collate.h b/lib/libc/locale/collate.h
new file mode 100644
index 0000000..638b4be
--- /dev/null
+++ b/lib/libc/locale/collate.h
@@ -0,0 +1,66 @@
+/*-
+ * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
+ * at Electronni Visti IA, Kiev, Ukraine.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#ifndef COLLATE_H_INCLUDED
+#define COLLATE_H_INCLUDED
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <limits.h>
+
+#define STR_LEN 10
+#define TABLE_SIZE 100
+#define COLLATE_VERSION "1.0\n"
+
+struct __collate_st_char_pri {
+ int prim, sec;
+};
+struct __collate_st_chain_pri {
+ u_char str[STR_LEN];
+ int prim, sec;
+};
+
+extern int __collate_load_error;
+extern char __collate_version[STR_LEN];
+extern u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN];
+extern struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1];
+extern struct __collate_st_chain_pri __collate_chain_pri_table[TABLE_SIZE];
+
+__BEGIN_DECLS
+u_char *__collate_strdup __P((u_char *));
+u_char *__collate_substitute __P((const u_char *));
+int __collate_load_tables __P((char *));
+void __collate_lookup __P((u_char *, int *, int *, int *));
+int __collate_range_cmp __P((int, int));
+#ifdef COLLATE_DEBUG
+void __collate_print_tables __P((void));
+#endif
+__END_DECLS
+
+#endif /* not COLLATE_H_INCLUDED */
diff --git a/lib/libc/locale/collcmp.c b/lib/libc/locale/collcmp.c
new file mode 100644
index 0000000..35d0640
--- /dev/null
+++ b/lib/libc/locale/collcmp.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 1996 by Andrey A. Chernov, Moscow, Russia.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ *
+ * $Id$
+ */
+
+#define ASCII_COMPATIBLE_COLLATE /* see usr.bin/colldef/data */
+
+#include <string.h>
+#include "collate.h"
+#ifndef ASCII_COMPATIBLE_COLLATE
+#include <ctype.h>
+#endif
+
+/* Temporary backward compatibility */
+
+int collate_range_cmp (c1, c2)
+ int c1, c2;
+{
+ return __collate_range_cmp(c1, c2);
+}
+
+
+/*
+ * Compare two characters converting collate information
+ * into ASCII-compatible range, it allows to handle
+ * "[a-z]"-type ranges with national characters.
+ */
+
+int __collate_range_cmp (c1, c2)
+ int c1, c2;
+{
+ static char s1[2], s2[2];
+ int ret;
+#ifndef ASCII_COMPATIBLE_COLLATE
+ int as1, as2, al1, al2;
+#endif
+
+ c1 &= UCHAR_MAX;
+ c2 &= UCHAR_MAX;
+ if (c1 == c2)
+ return (0);
+
+#ifndef ASCII_COMPATIBLE_COLLATE
+ as1 = isascii(c1);
+ as2 = isascii(c2);
+ al1 = isalpha(c1);
+ al2 = isalpha(c2);
+
+ if (as1 || as2 || al1 || al2) {
+ if ((as1 && as2) || (!al1 && !al2))
+ return (c1 - c2);
+ if (al1 && !al2) {
+ if (isupper(c1))
+ return ('A' - c2);
+ else
+ return ('a' - c2);
+ } else if (al2 && !al1) {
+ if (isupper(c2))
+ return (c1 - 'A');
+ else
+ return (c1 - 'a');
+ }
+ }
+#endif
+ s1[0] = c1;
+ s2[0] = c2;
+ if ((ret = strcoll(s1, s2)) != 0)
+ return (ret);
+ return (c1 - c2);
+}
diff --git a/lib/libc/locale/ctype.3 b/lib/libc/locale/ctype.3
index 528df27..1493cc3 100644
--- a/lib/libc/locale/ctype.3
+++ b/lib/libc/locale/ctype.3
@@ -54,22 +54,35 @@
.Nd character classification macros
.Sh SYNOPSIS
.Fd #include <ctype.h>
-.Fa int c
-.br
+.Ft int
.Fn isalnum "int c"
+.Ft int
.Fn isalpha "int c"
+.Ft int
.Fn isascii "int c"
+.Ft int
.Fn iscntrl "int c"
+.Ft int
.Fn isdigit "int c"
+.Ft int
.Fn isgraph "int c"
+.Ft int
.Fn islower "int c"
+.Ft int
.Fn isprint "int c"
+.Ft int
.Fn ispunct "int c"
+.Ft int
.Fn isspace "int c"
+.Ft int
.Fn isupper "int c"
+.Ft int
.Fn isxdigit "int c"
+.Ft int
.Fn toascii "int c"
+.Ft int
.Fn tolower "int c"
+.Ft int
.Fn toupper "int c"
.Sh DESCRIPTION
The above functions perform character tests and conversions on the integer
diff --git a/lib/libc/locale/euc.4 b/lib/libc/locale/euc.4
index 966b896..ffcf6d8 100644
--- a/lib/libc/locale/euc.4
+++ b/lib/libc/locale/euc.4
@@ -34,16 +34,26 @@
.\"
.\" @(#)euc.4 8.1 (Berkeley) 6/4/93
.\"
-.Dd "June 4, 1993"
+.Dd June 4, 1993
.Dt EUC 4
.Os
.Sh NAME
-.Nm EUC
+.Nm euc
.Nd EUC encoding of runes
.Sh SYNOPSIS
-\fBENCODING "EUC"\fP
-.br
-\fBVARIABLE \fP\fIlen1 mask1 len2 mask2 len3 mask3 len4 mask4 mask\fP
+.Nm ENCODING
+.Qq EUC
+.Pp
+.Nm VARIABLE
+.Ar len1
+.Ar mask1
+.Ar len2
+.Ar mask2
+.Ar len3
+.Ar mask3
+.Ar len4
+.Ar mask4
+.Ar mask
.Sh DESCRIPTION
The
.Nm EUC
@@ -89,32 +99,32 @@ as follows:
.Bd -literal
byte0 << ((\fIlen\fPN-1) * 8) | byte1 << ((\fIlen\fPN-2) * 8) | ... | byte\fIlen\fPN-1
.Ed
-.sp
+.Pp
The result is then ANDed with
.Ar ~mask
and ORed with
-.Ar mask\fPN.
+.Ar maskN .
Codesets 2 and 3 are special in that the leading byte (0x8e or 0x8f) is
first removed and the
-.Ar len\fPN
+.Ar lenN
argument is reduced by 1.
-.sp
+.Pp
For example, the Japanese locale has the following
.Ev VARIABLE
line:
.Bd -literal
VARIABLE 1 0x0000 2 0x8080 2 0x0080 3 0x8000 0x8080
.Ed
-.sp
+.Pp
Codeset 1 consists of the values 0x0000 - 0x007f.
-.sp
+.Pp
Codeset 2 consists of the values who have the bits 0x8080 set.
-.sp
+.Pp
Codeset 3 consists of the values 0x0080 - 0x00ff.
-.sp
+.Pp
Codeset 4 consists of the values 0x8000 - 0xff7f excluding the values
which have the 0x0080 bit set.
-.sp
+.Pp
Notice that the global
.Ar mask
is set to 0x8080, this implies that from those 2 bits the codeset can
diff --git a/lib/libc/locale/euc.5 b/lib/libc/locale/euc.5
new file mode 100644
index 0000000..ffcf6d8
--- /dev/null
+++ b/lib/libc/locale/euc.5
@@ -0,0 +1,241 @@
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Paul Borman at Krystal Technologies.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\" @(#)euc.4 8.1 (Berkeley) 6/4/93
+.\"
+.Dd June 4, 1993
+.Dt EUC 4
+.Os
+.Sh NAME
+.Nm euc
+.Nd EUC encoding of runes
+.Sh SYNOPSIS
+.Nm ENCODING
+.Qq EUC
+.Pp
+.Nm VARIABLE
+.Ar len1
+.Ar mask1
+.Ar len2
+.Ar mask2
+.Ar len3
+.Ar mask3
+.Ar len4
+.Ar mask4
+.Ar mask
+.Sh DESCRIPTION
+The
+.Nm EUC
+encoding is provided for compatibility with
+.Ux
+based systems.
+See
+.Xr mklocale 1
+for a complete description of the
+.Ev LC_CTYPE
+source file format.
+.Pp
+.Nm EUC
+implements a system of 4 multibyte codesets.
+A multibyte character in the first codeset consists of
+.Ar len1
+bytes starting with a byte in the range of 0x00 to 0x7f.
+To allow use of ASCII,
+.Ar len1
+is always 1.
+A multibyte character in the second codeset consists of
+.Ar len2
+bytes starting with a byte in the range of 0x80-0xff excluding 0x8e and 0x8f.
+A multibyte character in the third codeset consists of
+.Ar len3
+bytes starting with the byte 0x8e.
+A multibyte character in the fourth codeset consists of
+.Ar len4
+bytes starting with the byte 0x8f.
+.Pp
+The
+.Ev rune_t
+encoding of
+.Nm EUC
+multibyte characters is dependent on the
+.Ar len
+and
+.Ar mask
+arguments.
+First, the bytes are moved into a
+.Ev rune_t
+as follows:
+.Bd -literal
+byte0 << ((\fIlen\fPN-1) * 8) | byte1 << ((\fIlen\fPN-2) * 8) | ... | byte\fIlen\fPN-1
+.Ed
+.Pp
+The result is then ANDed with
+.Ar ~mask
+and ORed with
+.Ar maskN .
+Codesets 2 and 3 are special in that the leading byte (0x8e or 0x8f) is
+first removed and the
+.Ar lenN
+argument is reduced by 1.
+.Pp
+For example, the Japanese locale has the following
+.Ev VARIABLE
+line:
+.Bd -literal
+VARIABLE 1 0x0000 2 0x8080 2 0x0080 3 0x8000 0x8080
+.Ed
+.Pp
+Codeset 1 consists of the values 0x0000 - 0x007f.
+.Pp
+Codeset 2 consists of the values who have the bits 0x8080 set.
+.Pp
+Codeset 3 consists of the values 0x0080 - 0x00ff.
+.Pp
+Codeset 4 consists of the values 0x8000 - 0xff7f excluding the values
+which have the 0x0080 bit set.
+.Pp
+Notice that the global
+.Ar mask
+is set to 0x8080, this implies that from those 2 bits the codeset can
+be determined.
+.Sh "EXAMPLE - Japanese Locale"
+This is a complete example of an
+.Ev LC_CTYPE
+source file for the Japanese locale
+.Bd -literal
+/*
+ * Japanese LOCALE_CTYPE definitions using EUC of JIS character sets
+ */
+
+ENCODING "EUC"
+
+/* JIS JIS JIS */
+/* X201 X208 X201 */
+/* 00-7f 84-fe */
+
+VARIABLE 1 0x0000 2 0x8080 2 0x0080 3 0x8000 0x8080
+
+/*
+ * Code Set 1
+ */
+ALPHA 'A' - 'Z' 'a' - 'z'
+CONTROL 0x00 - 0x1f 0x7f
+DIGIT '0' - '9'
+GRAPH 0x21 - 0x7e
+LOWER 'a' - 'z'
+PUNCT 0x21 - 0x2f 0x3a - 0x40 0x5b - 0x60 0x7b - 0x7e
+SPACE 0x09 - 0x0d 0x20
+UPPER 'A' - 'Z'
+XDIGIT 'a' - 'f' 'A' - 'F'
+BLANK ' ' '\t'
+PRINT 0x20 - 0x7e
+
+MAPLOWER < 'A' - 'Z' : 'a' > < 'a' - 'z' : 'a' >
+MAPUPPER < 'A' - 'Z' : 'A' > < 'a' - 'z' : 'A' >
+TODIGIT < '0' - '9' : 0 >
+TODIGIT < 'A' - 'F' : 10 > < 'a' - 'f' : 10 >
+
+/*
+ * Code Set 2
+ */
+
+SPACE 0xa1a1
+PHONOGRAM 0xa1bc
+SPECIAL 0xa1a2 - 0xa1fe
+PUNCT 0xa1a2 - 0xa1f8 /* A few too many in here... */
+
+SPECIAL 0xa2a1 - 0xa2ae 0xa2ba - 0xa2c1 0xa2ca - 0xa2d0 0xa2dc - 0xa2ea
+SPECIAL 0xa2f2 - 0xa2f9 0xa2fe
+
+DIGIT 0xa3b0 - 0xa3b9
+UPPER 0xa3c1 - 0xa3da /* Romaji */
+LOWER 0xa3e1 - 0xa3fa /* Romaji */
+MAPLOWER < 0xa3c1 - 0xa3da : 0xa3e1 > /* English */
+MAPLOWER < 0xa3e1 - 0xa3fa : 0xa3e1 > /* English */
+MAPUPPER < 0xa3c1 - 0xa3da : 0xa3c1 >
+MAPUPPER < 0xa3e1 - 0xa3fa : 0xa3c1 >
+
+XDIGIT 0xa3c1 - 0xa3c6 0xa3e1 - 0xa3e6
+
+TODIGIT < 0xa3b0 - 0xa3b9 : 0 >
+TODIGIT < 0xa3c1 - 0xa3c6 : 10 > < 0xa3e1 - 0xa3e6 : 10 >
+
+PHONOGRAM 0xa4a1 - 0xa4f3
+PHONOGRAM 0xa5a1 - 0xa5f6
+
+UPPER 0xa6a1 - 0xa6b8 /* Greek */
+LOWER 0xa6c1 - 0xa6d8 /* Greek */
+MAPLOWER < 0xa6a1 - 0xa6b8 : 0xa6c1 > < 0xa6c1 - 0xa6d8 : 0xa6c1 >
+MAPUPPER < 0xa6a1 - 0xa6b8 : 0xa6a1 > < 0xa6c1 - 0xa6d8 : 0xa6a1 >
+
+UPPER 0xa7a1 - 0xa7c1 /* Cyrillic */
+LOWER 0xa7d1 - 0xa7f1 /* Cyrillic */
+MAPLOWER < 0xa7a1 - 0xa7c1 : 0xa7d1 > < 0xa7d1 - 0xa7f1 : 0xa7d1 >
+MAPUPPER < 0xa7a1 - 0xa7c1 : 0xa7a1 > < 0xa7d1 - 0xa7f1 : 0xa7a1 >
+
+SPECIAL 0xa8a1 - 0xa8c0
+
+IDEOGRAM 0xb0a1 - 0xb0fe 0xb1a1 - 0xb1fe 0xb2a1 - 0xb2fe
+IDEOGRAM 0xb3a1 - 0xb3fe 0xb4a1 - 0xb4fe 0xb5a1 - 0xb5fe
+IDEOGRAM 0xb6a1 - 0xb6fe 0xb7a1 - 0xb7fe 0xb8a1 - 0xb8fe
+IDEOGRAM 0xb9a1 - 0xb9fe 0xbaa1 - 0xbafe 0xbba1 - 0xbbfe
+IDEOGRAM 0xbca1 - 0xbcfe 0xbda1 - 0xbdfe 0xbea1 - 0xbefe
+IDEOGRAM 0xbfa1 - 0xbffe 0xc0a1 - 0xc0fe 0xc1a1 - 0xc1fe
+IDEOGRAM 0xc2a1 - 0xc2fe 0xc3a1 - 0xc3fe 0xc4a1 - 0xc4fe
+IDEOGRAM 0xc5a1 - 0xc5fe 0xc6a1 - 0xc6fe 0xc7a1 - 0xc7fe
+IDEOGRAM 0xc8a1 - 0xc8fe 0xc9a1 - 0xc9fe 0xcaa1 - 0xcafe
+IDEOGRAM 0xcba1 - 0xcbfe 0xcca1 - 0xccfe 0xcda1 - 0xcdfe
+IDEOGRAM 0xcea1 - 0xcefe 0xcfa1 - 0xcfd3 0xd0a1 - 0xd0fe
+IDEOGRAM 0xd1a1 - 0xd1fe 0xd2a1 - 0xd2fe 0xd3a1 - 0xd3fe
+IDEOGRAM 0xd4a1 - 0xd4fe 0xd5a1 - 0xd5fe 0xd6a1 - 0xd6fe
+IDEOGRAM 0xd7a1 - 0xd7fe 0xd8a1 - 0xd8fe 0xd9a1 - 0xd9fe
+IDEOGRAM 0xdaa1 - 0xdafe 0xdba1 - 0xdbfe 0xdca1 - 0xdcfe
+IDEOGRAM 0xdda1 - 0xddfe 0xdea1 - 0xdefe 0xdfa1 - 0xdffe
+IDEOGRAM 0xe0a1 - 0xe0fe 0xe1a1 - 0xe1fe 0xe2a1 - 0xe2fe
+IDEOGRAM 0xe3a1 - 0xe3fe 0xe4a1 - 0xe4fe 0xe5a1 - 0xe5fe
+IDEOGRAM 0xe6a1 - 0xe6fe 0xe7a1 - 0xe7fe 0xe8a1 - 0xe8fe
+IDEOGRAM 0xe9a1 - 0xe9fe 0xeaa1 - 0xeafe 0xeba1 - 0xebfe
+IDEOGRAM 0xeca1 - 0xecfe 0xeda1 - 0xedfe 0xeea1 - 0xeefe
+IDEOGRAM 0xefa1 - 0xeffe 0xf0a1 - 0xf0fe 0xf1a1 - 0xf1fe
+IDEOGRAM 0xf2a1 - 0xf2fe 0xf3a1 - 0xf3fe 0xf4a1 - 0xf4a4
+/*
+ * This is for Code Set 3, half-width kana
+ */
+SPECIAL 0xa1 - 0xdf
+PHONOGRAM 0xa1 - 0xdf
+CONTROL 0x84 - 0x97 0x9b - 0x9f 0xe0 - 0xfe
+.Ed
+.Sh "SEE ALSO"
+.Xr mklocale 1 ,
+.Xr setlocale 3
diff --git a/lib/libc/locale/euc.c b/lib/libc/locale/euc.c
index e58c855..bc33ff6 100644
--- a/lib/libc/locale/euc.c
+++ b/lib/libc/locale/euc.c
@@ -34,6 +34,7 @@
* SUCH DAMAGE.
*/
+#ifdef XPG4
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)euc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
@@ -218,3 +219,4 @@ CodeSet1:
}
return (len);
}
+#endif /* XPG4 */
diff --git a/lib/libc/locale/isalnum.3 b/lib/libc/locale/isalnum.3
index ad92c41..5c37978 100644
--- a/lib/libc/locale/isalnum.3
+++ b/lib/libc/locale/isalnum.3
@@ -44,7 +44,7 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn isalnum "int c";
+.Fn isalnum "int c"
.Sh DESCRIPTION
The
.Fn isalnum
@@ -54,7 +54,7 @@ or
.Xr isdigit 3
is true.
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&060\ ``0'' \t061\ ``1'' \t062\ ``2'' \t063\ ``3'' \t064\ ``4''
.It \&065\ ``5'' \t066\ ``6'' \t067\ ``7'' \t070\ ``8'' \t071\ ``9''
diff --git a/lib/libc/locale/isalpha.3 b/lib/libc/locale/isalpha.3
index a36dd4b..23dd46b 100644
--- a/lib/libc/locale/isalpha.3
+++ b/lib/libc/locale/isalpha.3
@@ -44,7 +44,7 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn isalpha "int c";
+.Fn isalpha "int c"
.Sh DESCRIPTION
The
.Fn isalpha
@@ -54,7 +54,7 @@ or
.Xr islower 3
is true.
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&101\ ``A'' \t102\ ``B'' \t103\ ``C'' \t104\ ``D'' \t105\ ``E''
.It \&106\ ``F'' \t107\ ``G'' \t110\ ``H'' \t111\ ``I'' \t112\ ``J''
diff --git a/lib/libc/locale/isascii.3 b/lib/libc/locale/isascii.3
index 9509dc5..0688c9c 100644
--- a/lib/libc/locale/isascii.3
+++ b/lib/libc/locale/isascii.3
@@ -40,7 +40,7 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn isascii "int c";
+.Fn isascii "int c"
.Sh DESCRIPTION
The
.Fn isascii
diff --git a/lib/libc/locale/isblank.3 b/lib/libc/locale/isblank.3
index 7c83d18..7be87bb 100644
--- a/lib/libc/locale/isblank.3
+++ b/lib/libc/locale/isblank.3
@@ -40,7 +40,7 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn isblank "int c";
+.Fn isblank "int c"
.Sh DESCRIPTION
The
.Fn isblank
diff --git a/lib/libc/locale/iscntrl.3 b/lib/libc/locale/iscntrl.3
index 33859a2..5bc3a5a 100644
--- a/lib/libc/locale/iscntrl.3
+++ b/lib/libc/locale/iscntrl.3
@@ -44,13 +44,13 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn iscntrl "int c";
+.Fn iscntrl "int c"
.Sh DESCRIPTION
The
.Fn iscntrl
function tests for any control character.
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&000\ nul \t001\ soh \t002\ stx \t003\ etx \t004\ eot
.It \&005\ enq \t006\ ack \t007\ bel \t010\ bs \t011\ ht
diff --git a/lib/libc/locale/isctype.c b/lib/libc/locale/isctype.c
index 6610e0e..55cfdf0 100644
--- a/lib/libc/locale/isctype.c
+++ b/lib/libc/locale/isctype.c
@@ -43,7 +43,6 @@
static char sccsid[] = "@(#)isctype.c 8.3 (Berkeley) 2/24/94";
#endif /* LIBC_SCCS and not lint */
-#define _ANSI_LIBRARY
#include <ctype.h>
#undef isalnum
@@ -51,7 +50,7 @@ int
isalnum(c)
int c;
{
- return(__istype((c), (_A|_D)));
+ return (__istype((c), (_A|_D)));
}
#undef isalpha
@@ -67,7 +66,7 @@ int
isascii(c)
int c;
{
- return((c & ~0x7F) == 0);
+ return (((c) & ~0x7F) == 0);
}
#undef isblank
@@ -155,7 +154,7 @@ int
toascii(c)
int c;
{
- return (c & 0177);
+ return ((c) & 0x7F);
}
#undef tolower
@@ -163,7 +162,7 @@ int
tolower(c)
int c;
{
- return((c & _CRMASK) ? ___tolower(c) : _CurrentRuneLocale->maplower[c]);
+ return (__tolower(c));
}
#undef toupper
@@ -171,5 +170,5 @@ int
toupper(c)
int c;
{
- return((c & _CRMASK) ? ___toupper(c) : _CurrentRuneLocale->mapupper[c]);
+ return (__toupper(c));
}
diff --git a/lib/libc/locale/isdigit.3 b/lib/libc/locale/isdigit.3
index aa70c30..781a418 100644
--- a/lib/libc/locale/isdigit.3
+++ b/lib/libc/locale/isdigit.3
@@ -44,13 +44,13 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn isdigit "int c";
+.Fn isdigit "int c"
.Sh DESCRIPTION
The
.Fn isdigit
function tests for any decimal-digit character.
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&060\ ``0'' \t061\ ``1'' \t062\ ``2'' \t063\ ``3'' \t064\ ``4''
.It \&065\ ``5'' \t066\ ``6'' \t067\ ``7'' \t070\ ``8'' \t071\ ``9''
diff --git a/lib/libc/locale/isgraph.3 b/lib/libc/locale/isgraph.3
index e8b1ee5..4ef232a 100644
--- a/lib/libc/locale/isgraph.3
+++ b/lib/libc/locale/isgraph.3
@@ -44,13 +44,13 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn isgraph "int c";
+.Fn isgraph "int c"
.Sh DESCRIPTION
The
.Fn isgraph
function tests for any printing character except space.
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&041\ ``!'' \t042\ ``"'' \t043\ ``#'' \t044\ ``$'' \t045\ ``%''
.It \&046\ ``&'' \t047\ ``''' \t050\ ``('' \t051\ ``)'' \t052\ ``*''
diff --git a/lib/libc/locale/islower.3 b/lib/libc/locale/islower.3
index e985498..0c354d2 100644
--- a/lib/libc/locale/islower.3
+++ b/lib/libc/locale/islower.3
@@ -44,13 +44,13 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn islower "int c";
+.Fn islower "int c"
.Sh DESCRIPTION
The
.Fn islower
function tests for any lower-case letters.
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&141\ ``a'' \t142\ ``b'' \t143\ ``c'' \t144\ ``d'' \t145\ ``e''
.It \&146\ ``f'' \t147\ ``g'' \t150\ ``h'' \t151\ ``i'' \t152\ ``j''
diff --git a/lib/libc/locale/isprint.3 b/lib/libc/locale/isprint.3
index dc04d50..8b84dbf 100644
--- a/lib/libc/locale/isprint.3
+++ b/lib/libc/locale/isprint.3
@@ -44,13 +44,13 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn isprint "int c";
+.Fn isprint "int c"
.Sh DESCRIPTION
The
.Fn isprint
function tests for any printing character including space (' ').
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&040\ sp \t041\ ``!'' \t042\ ``"'' \t043\ ``#'' \t044\ ``$''
.It \&045\ ``%'' \t046\ ``&'' \t047\ ``''' \t050\ ``('' \t051\ ``)''
diff --git a/lib/libc/locale/ispunct.3 b/lib/libc/locale/ispunct.3
index d5b3722..f0ed395 100644
--- a/lib/libc/locale/ispunct.3
+++ b/lib/libc/locale/ispunct.3
@@ -44,7 +44,7 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn ispunct "int c";
+.Fn ispunct "int c"
.Sh DESCRIPTION
The
.Fn ispunct
@@ -53,7 +53,7 @@ character for which
.Xr isalnum 3
is true.
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&041\ ``!'' \t042\ ``"'' \t043\ ``#'' \t044\ ``$'' \t045\ ``%''
.It \&046\ ``&'' \t047\ ``''' \t050\ ``('' \t051\ ``)'' \t052\ ``*''
diff --git a/lib/libc/locale/isspace.3 b/lib/libc/locale/isspace.3
index fb077e4..bd38107 100644
--- a/lib/libc/locale/isspace.3
+++ b/lib/libc/locale/isspace.3
@@ -44,13 +44,13 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn isspace "int c";
+.Fn isspace "int c"
.Sh DESCRIPTION
The
.Fn isspace
function tests for the standard white-space characters.
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&011\ ht \t012\ nl \t013\ vt \t014\ np \t015\ cr
.It \&040\ sp
diff --git a/lib/libc/locale/isupper.3 b/lib/libc/locale/isupper.3
index 6035f09..633c1e0 100644
--- a/lib/libc/locale/isupper.3
+++ b/lib/libc/locale/isupper.3
@@ -44,13 +44,13 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn isupper "int c";
+.Fn isupper "int c"
.Sh DESCRIPTION
The
.Fn isupper
function tests for any upper-case letter.
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&101\ ``A'' \t102\ ``B'' \t103\ ``C'' \t104\ ``D'' \t105\ ``E''
.It \&106\ ``F'' \t107\ ``G'' \t110\ ``H'' \t111\ ``I'' \t112\ ``J''
@@ -69,6 +69,6 @@ returns non-zero if the character tests true.
.Xr ascii 7
.Sh STANDARDS
The
-.Xr isupper
+.Fn isupper
function conforms to
.St -ansiC .
diff --git a/lib/libc/locale/isxdigit.3 b/lib/libc/locale/isxdigit.3
index ec1a502..cee6cc7 100644
--- a/lib/libc/locale/isxdigit.3
+++ b/lib/libc/locale/isxdigit.3
@@ -44,13 +44,13 @@
.Sh SYNOPSIS
.Fd #include <ctype.h>
.Ft int
-.Fn isxdigit "int c";
+.Fn isxdigit "int c"
.Sh DESCRIPTION
The
.Fn isxdigit
function tests for any hexadecimal-digit character.
In the ASCII character set, this includes the following characters:
-.sp
+.Pp
.Bl -column \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__ \&000_``0''__
.It \&060\ ``0'' \t061\ ``1'' \t062\ ``2'' \t063\ ``3'' \t064\ ``4''
.It \&065\ ``5'' \t066\ ``6'' \t067\ ``7'' \t070\ ``8'' \t071\ ``9''
diff --git a/lib/libc/locale/mbrune.3 b/lib/libc/locale/mbrune.3
index d843a02..7d0f41e 100644
--- a/lib/libc/locale/mbrune.3
+++ b/lib/libc/locale/mbrune.3
@@ -34,7 +34,7 @@
.\"
.\" @(#)mbrune.3 8.2 (Berkeley) 4/19/94
.\"
-.Dd "April 19, 1994"
+.Dd April 19, 1994
.Dt MBRUNE 3
.Os
.Sh NAME
@@ -138,10 +138,10 @@ if the
.Fa pattern
does not appear in the string.
.Sh "SEE ALSO
-.Xr euc 4 ,
.Xr mbrune 3 ,
.Xr rune 3 ,
.Xr setlocale 3 ,
+.Xr euc 4 ,
.Xr utf2 4
.Sh HISTORY
The
diff --git a/lib/libc/locale/multibyte.3 b/lib/libc/locale/multibyte.3
index 3ea10e5..6eb9c70 100644
--- a/lib/libc/locale/multibyte.3
+++ b/lib/libc/locale/multibyte.3
@@ -34,7 +34,7 @@
.\"
.\" @(#)multibyte.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd "June 4, 1993"
+.Dd June 4, 1993
.Dt MULTIBYTE 3
.Os
.Sh NAME
@@ -47,7 +47,7 @@
.Sh SYNOPSIS
.Fd #include <stdlib.h>
.Ft int
-.Fn mblen "const char *mbchar" "int nbytes"
+.Fn mblen "const char *mbchar" "size_t nbytes"
.Ft size_t
.Fn mbstowcs "wchar_t *wcstring" "const char *mbstring" "size_t nwchars"
.Ft int
@@ -222,10 +222,10 @@ not counting any terminating null byte.
If any invalid multibyte characters are encountered,
both functions return \-1.
.Sh "SEE ALSO
-.Xr euc 4 ,
.Xr mbrune 3 ,
.Xr rune 3 ,
.Xr setlocale 3 ,
+.Xr euc 4 ,
.Xr utf2 4
.Sh STANDARDS
The
diff --git a/lib/libc/locale/nomacros.c b/lib/libc/locale/nomacros.c
new file mode 100644
index 0000000..45c0db7
--- /dev/null
+++ b/lib/libc/locale/nomacros.c
@@ -0,0 +1,9 @@
+/*
+ * Tell <ctype.h> to generate extern versions of all its inline
+ * functions. The extern versions get called if the system doesn't
+ * support inlines or the user defines _DONT_USE_CTYPE_INLINE_
+ * before including <ctype.h>.
+ */
+#define _EXTERNALIZE_CTYPE_INLINES_
+
+#include <ctype.h>
diff --git a/lib/libc/locale/none.c b/lib/libc/locale/none.c
index b5d8e44..41f70ae 100644
--- a/lib/libc/locale/none.c
+++ b/lib/libc/locale/none.c
@@ -64,8 +64,6 @@ _none_sgetrune(string, n, result)
size_t n;
char const **result;
{
- int c;
-
if (n < 1) {
if (result)
*result = string;
diff --git a/lib/libc/locale/rune.3 b/lib/libc/locale/rune.3
index 659133f..5ba1604 100644
--- a/lib/libc/locale/rune.3
+++ b/lib/libc/locale/rune.3
@@ -34,7 +34,7 @@
.\"
.\" @(#)rune.3 8.2 (Berkeley) 12/11/93
.\"
-.Dd "December 11, 1993"
+.Dd December 11, 1993
.Dt RUNE 3
.Os
.Sh NAME
@@ -54,7 +54,7 @@
.Fn sgetrune "const char *string" "size_t n" "char const **result"
.Ft int
.Fn sputrune "rune_t rune" "char *string" "size_t n" "char **result"
-.sp
+.Pp
.Fd #include <stdio.h>
.Ft long
.Fn fgetrune "FILE *stream"
@@ -67,7 +67,7 @@ The
.Fn setrunelocale
controls the type of encoding used to represent runes as multibyte strings
as well as the properties of the runes as defined in
-\fB<ctype.h>\fP.
+.Aq Pa ctype.h .
The
.Fa locale
argument indicates which locale to load.
@@ -233,14 +233,15 @@ function returns the number of bytes needed to store
as a multibyte string.
.Sh FILES
.Bl -tag -width /usr/share/locale/locale/LC_CTYPE -compact
-.It Pa $PATH_LOCALE/\fIlocale\fP/LC_CTYPE
-.It Pa /usr/share/locale/\fIlocale\fP/LC_CTYPE
-binary LC_CTYPE file for the locale \fIlocale\fP.
+.It Pa $PATH_LOCALE/ Ns Em locale Ns /LC_CTYPE
+.It Pa /usr/share/locale/ Ns Em locale Ns /LC_CTYPE
+binary LC_CTYPE file for the locale
+.Em locale .
.El
.Sh "SEE ALSO
-.Xr euc 4 ,
.Xr mbrune 3 ,
.Xr setlocale 3 ,
+.Xr euc 4 ,
.Xr utf2 4
.Sh NOTE
The ANSI C type
diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c
index b239484..bc4d07c 100644
--- a/lib/libc/locale/rune.c
+++ b/lib/libc/locale/rune.c
@@ -38,78 +38,18 @@
static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
#include <rune.h>
#include <stdio.h>
+#include <string.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
-extern int _none_init __P((_RuneLocale *));
-extern int _UTF2_init __P((_RuneLocale *));
-extern int _EUC_init __P((_RuneLocale *));
-static _RuneLocale *_Read_RuneMagi __P((FILE *));
-
-static char *PathLocale = 0;
-
-int
-setrunelocale(encoding)
- char *encoding;
-{
- FILE *fp;
- char name[PATH_MAX];
- _RuneLocale *rl;
-
- if (!encoding)
- return(EFAULT);
-
- /*
- * The "C" and "POSIX" locale are always here.
- */
- if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) {
- _CurrentRuneLocale = &_DefaultRuneLocale;
- return(0);
- }
-
- if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE")))
- PathLocale = _PATH_LOCALE;
-
- sprintf(name, "%s/%s/LC_CTYPE", PathLocale, encoding);
-
- if ((fp = fopen(name, "r")) == NULL)
- return(ENOENT);
-
- if ((rl = _Read_RuneMagi(fp)) == 0) {
- fclose(fp);
- return(EFTYPE);
- }
-
- if (!rl->encoding[0] || !strcmp(rl->encoding, "UTF2")) {
- return(_UTF2_init(rl));
- } else if (!strcmp(rl->encoding, "NONE")) {
- return(_none_init(rl));
- } else if (!strcmp(rl->encoding, "EUC")) {
- return(_EUC_init(rl));
- } else
- return(EINVAL);
-}
-
-void
-setinvalidrune(ir)
- rune_t ir;
-{
- _INVALID_RUNE = ir;
-}
-
-static _RuneLocale *
+_RuneLocale *
_Read_RuneMagi(fp)
FILE *fp;
{
char *data;
- void *np;
void *lastp;
_RuneLocale *rl;
_RuneEntry *rr;
@@ -228,107 +168,6 @@ _Read_RuneMagi(fp)
if (!rl->mapupper_ext.nranges)
rl->mapupper_ext.ranges = 0;
-
- return(rl);
-}
-unsigned long
-___runetype(c)
- _BSD_RUNE_T_ c;
-{
- int x;
- _RuneRange *rr = &_CurrentRuneLocale->runetype_ext;
- _RuneEntry *re = rr->ranges;
-
- if (c == EOF)
- return(0);
- for (x = 0; x < rr->nranges; ++x, ++re) {
- if (c < re->min)
- return(0L);
- if (c <= re->max) {
- if (re->types)
- return(re->types[c - re->min]);
- else
- return(re->map);
- }
- }
- return(0L);
-}
-
-_BSD_RUNE_T_
-___toupper(c)
- _BSD_RUNE_T_ c;
-{
- int x;
- _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext;
- _RuneEntry *re = rr->ranges;
-
- if (c == EOF)
- return(EOF);
- for (x = 0; x < rr->nranges; ++x, ++re) {
- if (c < re->min)
- return(c);
- if (c <= re->max)
- return(re->map + c - re->min);
- }
- return(c);
-}
-
-_BSD_RUNE_T_
-___tolower(c)
- _BSD_RUNE_T_ c;
-{
- int x;
- _RuneRange *rr = &_CurrentRuneLocale->maplower_ext;
- _RuneEntry *re = rr->ranges;
-
- if (c == EOF)
- return(EOF);
- for (x = 0; x < rr->nranges; ++x, ++re) {
- if (c < re->min)
- return(c);
- if (c <= re->max)
- return(re->map + c - re->min);
- }
- return(c);
-}
-
-
-#if !defined(_USE_CTYPE_INLINE_) && !defined(_USE_CTYPE_MACROS_)
-/*
- * See comments in <machine/ansi.h>
- */
-int
-__istype(c, f)
- _BSD_RUNE_T_ c;
- unsigned long f;
-{
- return ((((c & _CRMASK) ? ___runetype(c)
- : _CurrentRuneLocale->runetype[c]) & f) ? 1 : 0);
-}
-
-int
-__isctype(_BSD_RUNE_T_ c, unsigned long f)
- _BSD_RUNE_T_ c;
- unsigned long f;
-{
- return ((((c & _CRMASK) ? 0
- : _DefaultRuneLocale.runetype[c]) & f) ? 1 : 0);
-}
-
-_BSD_RUNE_T_
-toupper(c)
- _BSD_RUNE_T_ c;
-{
- return ((c & _CRMASK) ?
- ___toupper(c) : _CurrentRuneLocale->mapupper[c]);
-}
-
-_BSD_RUNE_T_
-tolower(c)
- _BSD_RUNE_T_ c;
-{
- return ((c & _CRMASK) ?
- ___tolower(c) : _CurrentRuneLocale->maplower[c]);
+ return(rl);
}
-#endif
diff --git a/lib/libc/locale/runetype.c b/lib/libc/locale/runetype.c
new file mode 100644
index 0000000..282f806
--- /dev/null
+++ b/lib/libc/locale/runetype.c
@@ -0,0 +1,64 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ */
+
+#include <stdio.h>
+#include <rune.h>
+
+unsigned long
+___runetype(c)
+ _BSD_CT_RUNE_T_ c;
+{
+#ifdef XPG4
+ int x;
+ _RuneRange *rr = &_CurrentRuneLocale->runetype_ext;
+ _RuneEntry *re = rr->ranges;
+
+ if (c < 0 || c == EOF)
+ return(0L);
+
+ for (x = 0; x < rr->nranges; ++x, ++re) {
+ if (c < re->min)
+ return(0L);
+ if (c <= re->max) {
+ if (re->types)
+ return(re->types[c - re->min]);
+ else
+ return(re->map);
+ }
+ }
+#endif
+ return(0L);
+}
diff --git a/lib/libc/locale/setinvalidrune.c b/lib/libc/locale/setinvalidrune.c
new file mode 100644
index 0000000..45a2a47
--- /dev/null
+++ b/lib/libc/locale/setinvalidrune.c
@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ */
+
+#include <rune.h>
+
+void
+setinvalidrune(ir)
+ rune_t ir;
+{
+ _INVALID_RUNE = ir;
+}
diff --git a/lib/libc/locale/setlocale.3 b/lib/libc/locale/setlocale.3
index 74cce03..18ee80b 100644
--- a/lib/libc/locale/setlocale.3
+++ b/lib/libc/locale/setlocale.3
@@ -271,18 +271,22 @@ or
.Fn localeconv .
.Sh FILES
.Bl -tag -width /usr/share/locale/locale/category -compact
-.It Pa $PATH_LOCALE/\fIlocale\fP/\fIcategory\fP
-.It Pa /usr/share/locale/\fIlocale\fP/\fIcategory\fP
-locale file for the locale \fIlocale\fP
-and the category \fIcategory\fP.
+.It Pa $PATH_LOCALE/ Ns Em locale/category
+.It Pa /usr/share/locale/ Ns Em locale/category
+locale file for the locale
+.Em locale
+and the category
+.Em category .
.El
.Sh "SEE ALSO
-.Xr euc 4 ,
+.Xr colldef 1 ,
+.Xr mklocale 1 ,
.Xr mbrune 3 ,
.Xr multibyte 3 ,
.Xr rune 3 ,
.Xr strcoll 3 ,
.Xr strxfrm 3 ,
+.Xr euc 4 ,
.Xr utf2 4
.Sh STANDARDS
The
@@ -296,21 +300,25 @@ The
.Fn setlocale
and
.Fn localeconv
-functions first appeared in 4.4BSD.
+functions first appeared in
+.Bx 4.4 .
.Sh BUGS
The current implementation supports only the
.Li "\&""C""
and
.Li "\&""POSIX""
-locales for all but the LC_CTYPE locale.
+locales for all but the
+.Dv LC_COLLATE ,
+.Dv LC_CTYPE ,
+and
+.Dv LC_TIME
+categories.
.Pp
In spite of the gnarly currency support in
.Fn localeconv ,
the standards don't include any functions
for generalized currency formatting.
.Pp
-.Dv LC_COLLATE
-does not make sense for many languages.
Use of
.Dv LC_MONETARY
could lead to misleading results until we have a real time currency
diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c
index 414f58e..4b7a1b1 100644
--- a/lib/libc/locale/setlocale.c
+++ b/lib/libc/locale/setlocale.c
@@ -32,17 +32,29 @@
* 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.
+ *
+ * $Id: setlocale.c,v 1.20 1997/02/22 14:59:56 peter Exp $
*/
+#ifdef LIBC_RCS
+static const char rcsid[] =
+ "$Id: setlocale.c,v 1.20 1997/02/22 14:59:56 peter Exp $";
+#endif
+
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93";
#endif /* LIBC_SCCS and not lint */
+#include <sys/types.h>
+#include <sys/stat.h>
#include <limits.h>
#include <locale.h>
#include <rune.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include "collate.h"
+#include "setlocale.h"
/*
* Category names for getenv()
@@ -59,7 +71,7 @@ static char *categories[_LC_LAST] = {
/*
* Current locales for each category
*/
-static char current_categories[_LC_LAST][32] = {
+static char current_categories[_LC_LAST][ENCODING_LEN + 1] = {
"C",
"C",
"C",
@@ -71,30 +83,34 @@ static char current_categories[_LC_LAST][32] = {
/*
* The locales we are going to try and load
*/
-static char new_categories[_LC_LAST][32];
+static char new_categories[_LC_LAST][ENCODING_LEN + 1];
+static char saved_categories[_LC_LAST][ENCODING_LEN + 1];
-static char current_locale_string[_LC_LAST * 33];
-static char *PathLocale;
+static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)];
static char *currentlocale __P((void));
static char *loadlocale __P((int));
+static int stub_load_locale __P((const char *));
+
+extern int __time_load_locale __P((const char *)); /* strftime.c */
+
+#ifdef XPG4
+extern int _xpg4_setrunelocale __P((char *));
+#endif
char *
setlocale(category, locale)
int category;
const char *locale;
{
- int found, i, len;
+ int i, j, len;
char *env, *r;
- if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE")))
- PathLocale = _PATH_LOCALE;
-
- if (category < 0 || category >= _LC_LAST)
+ if (category < LC_ALL || category >= _LC_LAST)
return (NULL);
if (!locale)
- return (category ?
+ return (category != LC_ALL ?
current_categories[category] : currentlocale());
/*
@@ -109,42 +125,43 @@ setlocale(category, locale)
if (!*locale) {
env = getenv(categories[category]);
- if (!env)
- env = getenv(categories[0]);
+ if (category != LC_ALL && (!env || !*env))
+ env = getenv(categories[LC_ALL]);
- if (!env)
+ if (!env || !*env)
env = getenv("LANG");
- if (!env)
+ if (!env || !*env)
env = "C";
- (void) strncpy(new_categories[category], env, 31);
- new_categories[category][31] = 0;
- if (!category) {
+ (void) strncpy(new_categories[category], env, ENCODING_LEN);
+ new_categories[category][ENCODING_LEN] = '\0';
+ if (category == LC_ALL) {
for (i = 1; i < _LC_LAST; ++i) {
- if (!(env = getenv(categories[i])))
- env = new_categories[0];
- (void)strncpy(new_categories[i], env, 31);
- new_categories[i][31] = 0;
+ if (!(env = getenv(categories[i])) || !*env)
+ env = new_categories[LC_ALL];
+ (void)strncpy(new_categories[i], env, ENCODING_LEN);
+ new_categories[i][ENCODING_LEN] = '\0';
}
}
- } else if (category) {
- (void)strncpy(new_categories[category], locale, 31);
- new_categories[category][31] = 0;
+ } else if (category != LC_ALL) {
+ (void)strncpy(new_categories[category], locale, ENCODING_LEN);
+ new_categories[category][ENCODING_LEN] = '\0';
} else {
- if ((r = strchr(locale, '/')) == 0) {
+ if ((r = strchr(locale, '/')) == NULL) {
for (i = 1; i < _LC_LAST; ++i) {
- (void)strncpy(new_categories[i], locale, 31);
- new_categories[i][31] = 0;
+ (void)strncpy(new_categories[i], locale, ENCODING_LEN);
+ new_categories[i][ENCODING_LEN] = '\0';
}
} else {
for (i = 1; r[1] == '/'; ++r);
if (!r[1])
return (NULL); /* Hmm, just slashes... */
do {
- len = r - locale > 31 ? 31 : r - locale;
- (void)strncpy(new_categories[i++], locale, len);
- new_categories[i++][len] = 0;
+ len = r - locale > ENCODING_LEN ? ENCODING_LEN : r - locale;
+ (void)strncpy(new_categories[i], locale, len);
+ new_categories[i][len] = '\0';
+ i++;
locale = r;
while (*locale == '/')
++locale;
@@ -159,13 +176,19 @@ setlocale(category, locale)
if (category)
return (loadlocale(category));
- found = 0;
- for (i = 1; i < _LC_LAST; ++i)
- if (loadlocale(i) != NULL)
- found = 1;
- if (found)
- return (currentlocale());
- return (NULL);
+ for (i = 1; i < _LC_LAST; ++i) {
+ (void)strcpy(saved_categories[i], current_categories[i]);
+ if (loadlocale(i) == NULL) {
+ for (j = 1; j < i; j++) {
+ (void)strcpy(new_categories[j],
+ saved_categories[j]);
+ /* XXX can fail too */
+ (void)loadlocale(j);
+ }
+ return (NULL);
+ }
+ }
+ return (currentlocale());
}
static char *
@@ -177,11 +200,15 @@ currentlocale()
for (i = 2; i < _LC_LAST; ++i)
if (strcmp(current_categories[1], current_categories[i])) {
- (void)snprintf(current_locale_string,
- sizeof(current_locale_string), "%s/%s/%s/%s/%s",
- current_categories[1], current_categories[2],
- current_categories[3], current_categories[4],
- current_categories[5]);
+ (void) strcpy(current_locale_string, current_categories[1]);
+ (void) strcat(current_locale_string, "/");
+ (void) strcat(current_locale_string, current_categories[2]);
+ (void) strcat(current_locale_string, "/");
+ (void) strcat(current_locale_string, current_categories[3]);
+ (void) strcat(current_locale_string, "/");
+ (void) strcat(current_locale_string, current_categories[4]);
+ (void) strcat(current_locale_string, "/");
+ (void) strcat(current_locale_string, current_categories[5]);
break;
}
return (current_locale_string);
@@ -191,44 +218,99 @@ static char *
loadlocale(category)
int category;
{
- char name[PATH_MAX];
+ char *ret;
+ char *new = new_categories[category];
+ char *old = current_categories[category];
+
+ if (_PathLocale == NULL) {
+ char *p = getenv("PATH_LOCALE");
+
+ if (p != NULL && !issetugid()) {
+ if (strlen(p) + 1/*"/"*/ + ENCODING_LEN +
+ 1/*"/"*/ + CATEGORY_LEN >= PATH_MAX)
+ return (NULL);
+ _PathLocale = strdup(p);
+ if (_PathLocale == NULL)
+ return (NULL);
+ } else
+ _PathLocale = _PATH_LOCALE;
+ }
- if (strcmp(new_categories[category],
- current_categories[category]) == 0)
- return (current_categories[category]);
+ if (strcmp(new, old) == 0)
+ return (old);
if (category == LC_CTYPE) {
- if (setrunelocale(new_categories[LC_CTYPE]))
- return (NULL);
- (void)strcpy(current_categories[LC_CTYPE],
- new_categories[LC_CTYPE]);
- return (current_categories[LC_CTYPE]);
+#ifdef XPG4
+ ret = _xpg4_setrunelocale(new) ? NULL : new;
+#else
+ ret = setrunelocale(new) ? NULL : new;
+#endif
+ if (!ret) {
+#ifdef XPG4
+ (void)_xpg4_setrunelocale(old);
+#else
+ (void)setrunelocale(old);
+#endif
+ } else
+ (void)strcpy(old, new);
+ return (ret);
+ }
+
+ if (category == LC_COLLATE) {
+ ret = (__collate_load_tables(new) < 0) ? NULL : new;
+ if (!ret)
+ (void)__collate_load_tables(old);
+ else
+ (void)strcpy(old, new);
+ return (ret);
+ }
+
+ if (category == LC_TIME) {
+ ret = (__time_load_locale(new) < 0) ? NULL : new;
+ if (!ret)
+ (void)__time_load_locale(old);
+ else
+ (void)strcpy(old, new);
+ return (ret);
}
- if (!strcmp(new_categories[category], "C") ||
- !strcmp(new_categories[category], "POSIX")) {
-
- /*
- * Some day this will need to reset the locale to the default
- * C locale. Since we have no way to change them as of yet,
- * there is no need to reset them.
- */
- (void)strcpy(current_categories[category],
- new_categories[category]);
- return (current_categories[category]);
+ if (category == LC_MONETARY || category == LC_NUMERIC) {
+ ret = stub_load_locale(new) ? NULL : new;
+ if (!ret)
+ (void)stub_load_locale(old);
+ else
+ (void)strcpy(old, new);
+ return (ret);
}
+ /* Just in case...*/
+ return (NULL);
+}
+
+static int
+stub_load_locale(encoding)
+const char *encoding;
+{
+ char name[PATH_MAX];
+ struct stat st;
+
+ if (!encoding)
+ return(1);
+ /*
+ * The "C" and "POSIX" locale are always here.
+ */
+ if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX"))
+ return(0);
+ if (!_PathLocale)
+ return(1);
+ /* Range checking not needed, encoding has fixed size */
+ strcpy(name, _PathLocale);
+ strcat(name, "/");
+ strcat(name, encoding);
+#if 0
/*
* Some day we will actually look at this file.
*/
- (void)snprintf(name, sizeof(name), "%s/%s/%s",
- PathLocale, new_categories[category], categories[category]);
-
- switch (category) {
- case LC_COLLATE:
- case LC_MONETARY:
- case LC_NUMERIC:
- case LC_TIME:
- return (NULL);
- }
+#endif
+ return (stat(name, &st) != 0 || !S_ISDIR(st.st_mode));
}
diff --git a/lib/libc/locale/setlocale.h b/lib/libc/locale/setlocale.h
new file mode 100644
index 0000000..f3b2a22
--- /dev/null
+++ b/lib/libc/locale/setlocale.h
@@ -0,0 +1,34 @@
+#ifndef _SETLOCALE_H
+#define _SETLOCALE_H
+/*
+ * Copyright (C) 1997 by Andrey A. Chernov, Moscow, Russia.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#define ENCODING_LEN 31
+#define CATEGORY_LEN 11
+
+extern char *_PathLocale;
+
+#endif /* SETLOCALE_H */
diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c
new file mode 100644
index 0000000..d44f8e2
--- /dev/null
+++ b/lib/libc/locale/setrunelocale.c
@@ -0,0 +1,130 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ */
+
+#include <rune.h>
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "setlocale.h"
+
+extern int _none_init __P((_RuneLocale *));
+#ifdef XPG4
+extern int _UTF2_init __P((_RuneLocale *));
+extern int _EUC_init __P((_RuneLocale *));
+extern int _xpg4_setrunelocale __P((char *));
+#endif
+extern _RuneLocale *_Read_RuneMagi __P((FILE *));
+
+#ifdef XPG4
+int
+setrunelocale(encoding)
+ char *encoding;
+{
+ return _xpg4_setrunelocale(encoding);
+}
+#endif
+
+int
+#ifndef XPG4
+setrunelocale(encoding)
+#else
+_xpg4_setrunelocale(encoding)
+#endif
+ char *encoding;
+{
+ FILE *fp;
+ char name[PATH_MAX];
+ _RuneLocale *rl;
+
+ if (!encoding || strlen(encoding) > ENCODING_LEN)
+ return(EFAULT);
+
+ /*
+ * The "C" and "POSIX" locale are always here.
+ */
+ if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) {
+ _CurrentRuneLocale = &_DefaultRuneLocale;
+ return(0);
+ }
+
+ if (_PathLocale == NULL) {
+ char *p = getenv("PATH_LOCALE");
+
+ if (p != NULL && !issetugid()) {
+ if (strlen(p) + 1/*"/"*/ + ENCODING_LEN +
+ 1/*"/"*/ + CATEGORY_LEN >= PATH_MAX)
+ return(EFAULT);
+ _PathLocale = strdup(p);
+ if (_PathLocale == NULL)
+ return (errno);
+ } else
+ _PathLocale = _PATH_LOCALE;
+ }
+ /* Range checking not needed, encoding length already checked above */
+ (void) strcpy(name, _PathLocale);
+ (void) strcat(name, "/");
+ (void) strcat(name, encoding);
+ (void) strcat(name, "/LC_CTYPE");
+
+ if ((fp = fopen(name, "r")) == NULL)
+ return(ENOENT);
+
+ if ((rl = _Read_RuneMagi(fp)) == 0) {
+ fclose(fp);
+ return(EFTYPE);
+ }
+ fclose(fp);
+
+#ifdef XPG4
+ if (!rl->encoding[0] || !strcmp(rl->encoding, "UTF2")) {
+ return(_UTF2_init(rl));
+#else
+ if (!rl->encoding[0]) {
+ return(EINVAL);
+#endif
+ } else if (!strcmp(rl->encoding, "NONE")) {
+ return(_none_init(rl));
+#ifdef XPG4
+ } else if (!strcmp(rl->encoding, "EUC")) {
+ return(_EUC_init(rl));
+#endif
+ } else
+ return(EINVAL);
+}
+
diff --git a/lib/libc/locale/table.c b/lib/libc/locale/table.c
index fb7344e..00f80d7 100644
--- a/lib/libc/locale/table.c
+++ b/lib/libc/locale/table.c
@@ -32,14 +32,14 @@
* 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.
+ *
+ * $Id: table.c,v 1.10 1997/05/13 11:19:26 ache Exp $
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/27/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/types.h>
-
#include <ctype.h>
#include <rune.h>
@@ -158,3 +158,5 @@ _RuneLocale _DefaultRuneLocale = {
_RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale;
int __mb_cur_max = 1;
+
+char *_PathLocale;
diff --git a/lib/libc/locale/toascii.3 b/lib/libc/locale/toascii.3
index 54fa292..788d2f2 100644
--- a/lib/libc/locale/toascii.3
+++ b/lib/libc/locale/toascii.3
@@ -51,9 +51,9 @@ The
.Fn toascii
function always returns a valid ASCII character.
.Sh SEE ALSO
-.Xr isascii 3 ,
.Xr isalnum 3 ,
.Xr isalpha 3 ,
+.Xr isascii 3 ,
.Xr iscntrl 3 ,
.Xr isdigit 3 ,
.Xr isgraph 3 ,
@@ -63,7 +63,7 @@ function always returns a valid ASCII character.
.Xr isspace 3 ,
.Xr isupper 3 ,
.Xr isxdigit 3 ,
+.Xr stdio 3 ,
.Xr tolower 3 ,
.Xr toupper 3 ,
-.Xr stdio 3 ,
.Xr ascii 7
diff --git a/lib/libc/locale/tolower.3 b/lib/libc/locale/tolower.3
index fe503d4..3f98965 100644
--- a/lib/libc/locale/tolower.3
+++ b/lib/libc/locale/tolower.3
@@ -65,9 +65,9 @@ one; otherwise the argument is returned unchanged.
.\" .Xr islower
.\" is true.
.Sh SEE ALSO
-.Xr isascii 3 ,
.Xr isalnum 3 ,
.Xr isalpha 3 ,
+.Xr isascii 3 ,
.Xr iscntrl 3 ,
.Xr isdigit 3 ,
.Xr isgraph 3 ,
@@ -77,9 +77,9 @@ one; otherwise the argument is returned unchanged.
.Xr isspace 3 ,
.Xr isupper 3 ,
.Xr isxdigit 3 ,
+.Xr stdio 3 ,
.Xr toascii 3 ,
.Xr toupper 3 ,
-.Xr stdio 3
.Xr ascii 7
.Sh STANDARDS
The
diff --git a/lib/libc/locale/tolower.c b/lib/libc/locale/tolower.c
new file mode 100644
index 0000000..65d5175
--- /dev/null
+++ b/lib/libc/locale/tolower.c
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ */
+
+#include <stdio.h>
+#include <rune.h>
+
+_BSD_CT_RUNE_T_
+___tolower(c)
+ _BSD_CT_RUNE_T_ c;
+{
+#ifdef XPG4
+ int x;
+ _RuneRange *rr = &_CurrentRuneLocale->maplower_ext;
+ _RuneEntry *re = rr->ranges;
+
+ if (c < 0 || c == EOF)
+ return(c);
+
+ for (x = 0; x < rr->nranges; ++x, ++re) {
+ if (c < re->min)
+ return(c);
+ if (c <= re->max)
+ return(re->map + c - re->min);
+ }
+#endif
+ return(c);
+}
diff --git a/lib/libc/locale/toupper.3 b/lib/libc/locale/toupper.3
index c3ff593..2802637 100644
--- a/lib/libc/locale/toupper.3
+++ b/lib/libc/locale/toupper.3
@@ -65,9 +65,9 @@ one; otherwise the argument is returned unchanged.
.\" .Xr isupper
.\" is true.
.Sh SEE ALSO
-.Xr isascii 3 ,
.Xr isalnum 3 ,
.Xr isalpha 3 ,
+.Xr isascii 3 ,
.Xr iscntrl 3 ,
.Xr isdigit 3 ,
.Xr isgraph 3 ,
@@ -77,12 +77,12 @@ one; otherwise the argument is returned unchanged.
.Xr isspace 3 ,
.Xr isupper 3 ,
.Xr isxdigit 3 ,
+.Xr stdio 3 ,
.Xr toascii 3 ,
-.Xr toupper 3 ,
-.Xr stdio 3
+.Xr tolower 3 ,
.Xr ascii 7
.Sh STANDARDS
The
-.Fn tolower
+.Fn toupper
function conforms to
.St -ansiC .
diff --git a/lib/libc/locale/toupper.c b/lib/libc/locale/toupper.c
new file mode 100644
index 0000000..d2e4480
--- /dev/null
+++ b/lib/libc/locale/toupper.c
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ */
+
+#include <stdio.h>
+#include <rune.h>
+
+_BSD_CT_RUNE_T_
+___toupper(c)
+ _BSD_CT_RUNE_T_ c;
+{
+#ifdef XPG4
+ int x;
+ _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext;
+ _RuneEntry *re = rr->ranges;
+
+ if (c < 0 || c == EOF)
+ return(c);
+
+ for (x = 0; x < rr->nranges; ++x, ++re) {
+ if (c < re->min)
+ return(c);
+ if (c <= re->max)
+ return(re->map + c - re->min);
+ }
+#endif
+ return(c);
+}
diff --git a/lib/libc/locale/utf2.4 b/lib/libc/locale/utf2.4
index 20a9587..d7ef493 100644
--- a/lib/libc/locale/utf2.4
+++ b/lib/libc/locale/utf2.4
@@ -34,14 +34,15 @@
.\"
.\" @(#)utf2.4 8.1 (Berkeley) 6/4/93
.\"
-.Dd "June 4, 1993"
+.Dd June 4, 1993
.Dt UTF2 4
.Os
.Sh NAME
-.Nm UTF2
+.Nm utf2
.Nd "Universal character set Transformation Format encoding of runes
.Sh SYNOPSIS
-\fBENCODING "UTF2"\fP
+.Nm ENCODING
+.Qq UTF2
.Sh DESCRIPTION
The
.Nm UTF2
@@ -62,7 +63,7 @@ encoding is represented by the following table:
[0x0080 - 0x03ff] [00000bbb.bbbbbbbb] -> 110bbbbb, 10bbbbbb
[0x0400 - 0xffff] [bbbbbbbb.bbbbbbbb] -> 1110bbbb, 10bbbbbb, 10bbbbbb
.Ed
-.sp
+.Pp
If more than a single representation of a value exists (for example,
0x00; 0xC0 0x80; 0xE0 0x80 0x80) the shortest representation is always
used (but the longer ones will be correctly decoded).
@@ -78,7 +79,7 @@ The final three encodings provided by X-Open:
[0bbbbbbb.bbbbbbbb.bbbbbbbb.bbbbbbbb] ->
1111110b, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
.Ed
-.sp
+.Pp
which provides for the entire proposed ISO-10646 31 bit standard are currently
not implemented.
.Sh "SEE ALSO"
diff --git a/lib/libc/gen/realpath.3 b/lib/libc/locale/utf2.5
index 83f4a43..d7ef493 100644
--- a/lib/libc/gen/realpath.3
+++ b/lib/libc/locale/utf2.5
@@ -1,8 +1,8 @@
-.\" Copyright (c) 1994
+.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
-.\" Jan-Simon Pendry.
+.\" Paul Borman at Krystal Technologies.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -32,94 +32,56 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)realpath.3 8.2 (Berkeley) 2/16/94
+.\" @(#)utf2.4 8.1 (Berkeley) 6/4/93
.\"
-.Dd "February 16, 1994"
-.Dt REALPATH 3
+.Dd June 4, 1993
+.Dt UTF2 4
.Os
.Sh NAME
-.Nm realpath
-.Nd returns the canonicalized absolute pathname
+.Nm utf2
+.Nd "Universal character set Transformation Format encoding of runes
.Sh SYNOPSIS
-.Fd #include <sys/param.h>
-.Fd #include <stdlib.h>
-.Ft "char *"
-.Fn realpath "const char *pathname" "char resolvedname[MAXPATHLEN]"
+.Nm ENCODING
+.Qq UTF2
.Sh DESCRIPTION
The
-.Fn realpath
-function resolves all symbolic links, extra
-.Dq /
-characters and references to
-.Pa /./
-and
-.Pa /../
-in
-.Fa pathname ,
-and copies the resulting absolute pathname into
-the memory referenced by
-.Fa resolvedname .
-The
-.Fa resolvedname
-argument
-.Em must
-refer to a buffer capable of storing at least
-.Dv MAXPATHLEN
-characters.
+.Nm UTF2
+encoding is based on a proposed X-Open multibyte
+\s-1FSS-UCS-TF\s+1 (File System Safe Universal Character Set Transformation Format) encoding as used in
+.Nm Plan 9 from Bell Labs.
+Although it is capable of representing more than 16 bits,
+the current implementation is limited to 16 bits as defined by the
+Unicode Standard.
.Pp
-The
-.Fn realpath
-function will resolve both absolute and relative paths
-and return the absolute pathname corresponding to
-.Fa pathname .
-All but the last component of
-.Fa pathname
-must exist when
-.Fn realpath
-is called.
-.Sh "RETURN VALUES"
-The
-.Fn realpath
-function returns
-.Fa resolved_name
-on success.
-If an error occurs,
-.Fn realpath
-returns
-.Dv NULL ,
-and
-.Fa resolved_name
-contains the pathname which caused the problem.
-.Sh ERRORS
-The function
-.Fn realpath
-may fail and set the external variable
-.Va errno
-for any of the errors specified for the library functions
-.Xr chdir 2 ,
-.Xr close 2 ,
-.Xr fchdir 2 ,
-.Xr lstat 2 ,
-.Xr open 2 ,
-.Xr readlink 2
-and
-.Xr getcwd 3 .
-.Sh CAVEATS
-This implementation of
-.Fn realpath
-differs slightly from the Solaris implementation.
-The
-.Bx 4.4
-version always returns absolute pathnames,
-whereas the Solaris implementation will,
-under certain circumstances, return a relative
-.Fa resolved_path
-when given a relative
-.Fa pathname .
+.Nm UTF2
+representation is backwards compatible with ASCII, so 0x00-0x7f refer to the
+ASCII character set. The multibyte encoding of runes between 0x0080 and 0xffff
+consist entirely of bytes whose high order bit is set. The actual
+encoding is represented by the following table:
+.Bd -literal
+[0x0000 - 0x007f] [00000000.0bbbbbbb] -> 0bbbbbbb
+[0x0080 - 0x03ff] [00000bbb.bbbbbbbb] -> 110bbbbb, 10bbbbbb
+[0x0400 - 0xffff] [bbbbbbbb.bbbbbbbb] -> 1110bbbb, 10bbbbbb, 10bbbbbb
+.Ed
+.Pp
+If more than a single representation of a value exists (for example,
+0x00; 0xC0 0x80; 0xE0 0x80 0x80) the shortest representation is always
+used (but the longer ones will be correctly decoded).
+.Pp
+The final three encodings provided by X-Open:
+.Bd -literal
+[00000000.000bbbbb.bbbbbbbb.bbbbbbbb] ->
+ 11110bbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
+
+[000000bb.bbbbbbbb.bbbbbbbb.bbbbbbbb] ->
+ 111110bb, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
+
+[0bbbbbbb.bbbbbbbb.bbbbbbbb.bbbbbbbb] ->
+ 1111110b, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
+.Ed
+.Pp
+which provides for the entire proposed ISO-10646 31 bit standard are currently
+not implemented.
.Sh "SEE ALSO"
-.Xr getcwd 3
-.Sh HISTORY
-The
-.Fn realpath
-function call first appeared in
-.Bx 4.4 .
+.Xr mklocale 1 ,
+.Xr setlocale 3
diff --git a/lib/libc/locale/utf2.c b/lib/libc/locale/utf2.c
index 846fad9..c46dd93 100644
--- a/lib/libc/locale/utf2.c
+++ b/lib/libc/locale/utf2.c
@@ -34,6 +34,7 @@
* SUCH DAMAGE.
*/
+#ifdef XPG4
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)utf2.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
@@ -146,3 +147,4 @@ _UTF2_sputrune(c, string, n, result)
return (1);
}
}
+#endif /* XPG4 */
diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc
index 320b742..d654c02 100644
--- a/lib/libc/net/Makefile.inc
+++ b/lib/libc/net/Makefile.inc
@@ -1,27 +1,44 @@
-# @(#)Makefile.inc 8.2 (Berkeley) 9/5/93
+# from @(#)Makefile.inc 8.2 (Berkeley) 9/5/93
+# $Id$
# machine-independent net sources
-.PATH: ${.CURDIR}/${MACHINE}/net ${.CURDIR}/net
+.PATH: ${.CURDIR}/../libc/${MACHINE}/net ${.CURDIR}/../libc/net
-SRCS+= gethostnamadr.c getnetbyaddr.c getnetbyname.c getnetent.c \
+SRCS+= addr2ascii.c ascii2addr.c base64.c \
+ gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \
+ getnetbydns.c getnetbyht.c getnetbynis.c getnetnamadr.c \
getproto.c getprotoent.c getprotoname.c getservbyname.c \
getservbyport.c getservent.c herror.c inet_addr.c inet_lnaof.c \
- inet_makeaddr.c inet_netof.c inet_network.c inet_ntoa.c \
- iso_addr.c linkaddr.c ns_addr.c ns_ntoa.c rcmd.c recv.c res_comp.c \
- res_debug.c res_init.c res_mkquery.c res_query.c res_send.c \
- send.c sethostent.c
+ inet_makeaddr.c inet_netof.c inet_network.c inet_ntoa.c inet_ntop.c \
+ inet_net_ntop.c inet_net_pton.c inet_neta.c \
+ inet_pton.c linkaddr.c map_v4v6.c nsap_addr.c \
+ rcmd.c recv.c res_comp.c res_data.c res_debug.c \
+ res_init.c res_mkquery.c res_query.c res_send.c res_stubs.c \
+ send.c ether_addr.c \
+ ns_addr.c ns_ntoa.c
+# iso_addr.c
# machine-dependent net sources
-.include "${.CURDIR}/${MACHINE}/net/Makefile.inc"
+.include "${.CURDIR}/../libc/${MACHINE}/net/Makefile.inc"
-MAN3+= byteorder.0 gethostbyname.0 getnetent.0 getprotoent.0 getservent.0 \
- inet.0 linkaddr.0 ns.0 rcmd.0 resolver.0 \
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN3+= net/addr2ascii.3 \
+ net/byteorder.3 net/ethers.3 net/gethostbyname.3 net/getnetent.3 \
+ net/getprotoent.3 net/getservent.3 net/inet.3 net/linkaddr.3 \
+ net/rcmd.3 resolver.3
+# not installed: net/ns.3 net/iso_addr.3
+
+MLINKS+=addr2ascii.3 ascii2addr.3
MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \
byteorder.3 ntohs.3
+MLINKS+=ethers.3 ether_line.3 ethers.3 ether_aton.3 ethers.3 ether_ntoa.3 \
+ ethers.3 ether_ntohost.3 ethers.3 ether_hostton.3
MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \
gethostbyname.3 sethostent.3 gethostbyname.3 gethostent.3 \
- gethostbyname.3 herror.3
+ gethostbyname.3 herror.3 gethostbyname.3 hstrerror.3 \
+ gethostbyname.3 gethostbyname2.3
MLINKS+=getnetent.3 endnetent.3 getnetent.3 getnetbyaddr.3 \
getnetent.3 getnetbyname.3 getnetent.3 setnetent.3
MLINKS+=getprotoent.3 endprotoent.3 getprotoent.3 getprotobyname.3 \
@@ -31,9 +48,10 @@ MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \
MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_lnaof.3 \
inet.3 inet_makeaddr.3 inet.3 inet_netof.3 inet.3 inet_network.3 \
inet.3 inet_ntoa.3 inet.3 network.3 inet.3 ntoa.3 inet.3 inet_aton.3
-MLINKS+=linkaddr.3 linkntoa.3
-MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3
-MLINKS+=rcmd.3 rresvport.3 rcmd.3 ruserok.3
+MLINKS+=linkaddr.3 link_addr.3 linkaddr.3 link_ntoa.3
+#MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3
+MLINKS+=rcmd.3 rresvport.3 rcmd.3 iruserok.3 rcmd.3 ruserok.3
MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \
resolver.3 res_mkquery.3 resolver.3 res_send.3 resolver.3 res_query.3 \
resolver.3 res_search.3
+.endif
diff --git a/lib/libc/net/addr2ascii.3 b/lib/libc/net/addr2ascii.3
new file mode 100644
index 0000000..282acac
--- /dev/null
+++ b/lib/libc/net/addr2ascii.3
@@ -0,0 +1,215 @@
+.\"
+.\" Copyright 1996 Massachusetts Institute of Technology
+.\"
+.\" Permission to use, copy, modify, and distribute this software and
+.\" its documentation for any purpose and without fee is hereby
+.\" granted, provided that both the above copyright notice and this
+.\" permission notice appear in all copies, that both the above
+.\" copyright notice and this permission notice appear in all
+.\" supporting documentation, and that the name of M.I.T. not be used
+.\" in advertising or publicity pertaining to distribution of the
+.\" software without specific, written prior permission. M.I.T. makes
+.\" no representations about the suitability of this software for any
+.\" purpose. It is provided "as is" without express or implied
+.\" warranty.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
+.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
+.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
+.\" SHALL M.I.T. 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.
+.\"
+.\" $ANA: addr2ascii.3,v 1.1 1996/06/13 18:41:46 wollman Exp $
+.\"
+.Dd June 13, 1996
+.Dt ADDR2ASCII 3
+.Os
+.Sh NAME
+.Nm addr2ascii ,
+.Nm ascii2addr
+.Nd Generic address formatting routines
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/socket.h>
+.Fd #include <netinet/in.h>
+.Fd #include <arpa/inet.h>
+.Ft "char *"
+.Fn addr2ascii "int af" "const void *addrp" "int len" "char *buf"
+.Ft int
+.Fn ascii2addr "int af" "const char *ascii" "void *result"
+.Sh DESCRIPTION
+The routines
+.Fn addr2ascii
+and
+.Fn ascii2addr
+are used to convert network addresses between binary form and a
+printable form appropriate to the address family. Both functions take
+an
+.Fa af
+argument, specifying the address family to be used in the conversion
+process.
+(Currently, only the
+.Dv AF_INET
+and
+.Dv AF_LINK
+address families are supported.)
+.Pp
+The
+.Fn addr2ascii
+function
+is used to convert binary, network-format addresses into printable
+form. In addition to
+.Fa af ,
+there are three other arguments. The
+.Fa addrp
+argument is a pointer to the network address to be converted.
+The
+.Fa len
+argument is the length of the address. The
+.Fa buf
+argument is an optional pointer to a caller-allocated buffer to hold
+the result; if a null pointer is passed,
+.Fn addr2ascii
+uses a statically-allocated buffer.
+.Pp
+The
+.Fn ascii2addr
+function performs the inverse operation to
+.Fn addr2ascii .
+In addition to
+.Fa af ,
+it takes two parameters,
+.Fa ascii
+and
+.Fa result .
+The
+.Fa ascii
+parameter is a pointer to the string which is to be converted into
+binary. The
+.Fa result
+parameter is a pointer to an appropriate network address structure for
+the specified family.
+.Pp
+The following gives the appropriate structure to use for binary
+addresses in the specified family:
+.Pp
+.Bl -tag -width AF_INETxxxx -compact
+.It Dv AF_INET
+.Li struct in_addr
+.Pq in Aq Pa netinet/in.h
+.It Dv AF_LINK
+.Li struct sockaddr_dl
+.Pq in Aq Pa net/if_dl.h
+.\" .It Dv AF_INET6
+.\" .Li struct in6_addr
+.\" .Pq in Aq Pa netinet6/in6.h
+.El
+.Sh RETURN VALUES
+The
+.Fn addr2ascii
+function returns the address of the buffer it was passed, or a static
+buffer if the a null pointer was passed; on failure, it returns a null
+pointer.
+The
+.Fn ascii2addr
+function returns the length of the binary address in bytes, or -1 on
+failure.
+.Sh EXAMPLES
+The
+.Xr inet 3
+functions
+.Fn inet_ntoa
+and
+.Fn inet_aton
+could be implemented thusly:
+.Bd -literal -offset indent
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+char *
+inet_ntoa(struct in_addr addr)
+{
+ return addr2ascii(AF_INET, &addr, sizeof addr, 0);
+}
+
+int
+inet_aton(const char *ascii, struct in_addr *addr)
+{
+ return (ascii2addr(AF_INET, ascii, addr)
+ == sizeof(*addr));
+}
+.Ed
+.Pp
+In actuality, this cannot be done because
+.Fn addr2ascii
+and
+.Fn ascii2addr
+are implemented in terms of the
+.Xr inet 3
+functions, rather than the other way around.
+.Sh ERRORS
+When a failure is returned,
+.Li errno
+is set to one of the following values:
+.Bl -tag -width [EPROTONOSUPPORT]
+.It Bq Er ENAMETOOLONG
+The
+.Fn addr2ascii
+routine was passed a
+.Fa len
+parameter which was inappropriate for the address family given by
+.Fa af .
+.It Bq Er EPROTONOSUPPORT
+Either routine was passed an
+.Fa af
+parameter other than
+.Dv AF_INET
+or
+.Dv AF_LINK .
+.It Bq Er EINVAL
+The string passed to
+.Fn ascii2addr
+was improperly formatted for address family
+.Fa af .
+.El
+.Sh SEE ALSO
+.Xr inet 3 ,
+.Xr linkaddr 3 ,
+.Xr inet 4
+.Sh HISTORY
+An interface close to this one was originally suggested by Craig
+Partridge. This particular interface originally apppeared in the
+.Tn INRIA
+.Tn IPv6
+implementation.
+.Sh AUTHOR
+Code and documentation by Garrett A. Wollman, MIT Laboratory for
+Computer Science.
+.Sh BUGS
+The original implementations supported IPv6. This support should
+eventually be resurrected. The
+.Tn NRL
+implementation also included support for the
+.Dv AF_ISO
+and
+.Dv AF_NS
+address families.
+.Pp
+The genericity of this interface is somewhat questionable. A truly
+generic interface would provide a means for determining the length of
+the buffer to be used so that it could be dynamically allocated, and
+would always require a
+.Dq Li "struct sockaddr"
+to hold the binary address. Unfortunately, this is incompatible with existing
+practice. This limitation means that a routine for printing network
+addresses from arbitrary address families must still have internal
+knowledge of the maximum buffer length needed and the appropriate part
+of the address to use as the binary address.
diff --git a/lib/libc/net/addr2ascii.c b/lib/libc/net/addr2ascii.c
new file mode 100644
index 0000000..5bee3ea
--- /dev/null
+++ b/lib/libc/net/addr2ascii.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright 1996 Massachusetts Institute of Technology
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose and without fee is hereby
+ * granted, provided that both the above copyright notice and this
+ * permission notice appear in all copies, that both the above
+ * copyright notice and this permission notice appear in all
+ * supporting documentation, and that the name of M.I.T. not be used
+ * in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. M.I.T. makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
+ * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
+ * SHALL M.I.T. 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.
+ *
+ * $ANA: addr2ascii.c,v 1.1 1996/06/13 18:41:46 wollman Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <errno.h>
+#include <string.h>
+
+#include <net/if_dl.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/*-
+ * Convert a network address from binary to printable numeric format.
+ * This API is copied from INRIA's IPv6 implementation, but it is a
+ * bit bogus in two ways:
+ *
+ * 1) There is no value in passing both an address family and
+ * an address length; either one should imply the other,
+ * or we should be passing sockaddrs instead.
+ * 2) There should by contrast be /added/ a length for the buffer
+ * that we pass in, so that programmers are spared the need to
+ * manually calculate (read: ``guess'') the maximum length.
+ *
+ * Flash: the API is also the same in the NRL implementation, and seems to
+ * be some sort of standard, so we appear to be stuck with both the bad
+ * naming and the poor choice of arguments.
+ */
+char *
+addr2ascii(af, addrp, len, buf)
+ int af;
+ const void *addrp;
+ int len; /* should be size_t XXX */
+ char *buf; /* XXX should pass length of buffer */
+{
+ static char staticbuf[64]; /* 64 for AF_LINK > 16 for AF_INET */
+
+ if (!buf)
+ buf = staticbuf;
+
+ switch(af) {
+ case AF_INET:
+ if (len != sizeof(struct in_addr)) {
+ errno = ENAMETOOLONG;
+ return 0;
+ }
+ strcpy(buf, inet_ntoa(*(const struct in_addr *)addrp));
+ break;
+
+ case AF_LINK:
+ if (len != sizeof(struct sockaddr_dl)) {
+ errno = ENAMETOOLONG;
+ return 0;
+ }
+ strcpy(buf, link_ntoa((const struct sockaddr_dl *)addrp));
+ break;
+
+ default:
+ errno = EPROTONOSUPPORT;
+ return 0;
+ }
+ return buf;
+}
diff --git a/lib/libc/net/ascii2addr.c b/lib/libc/net/ascii2addr.c
new file mode 100644
index 0000000..0b5bab4
--- /dev/null
+++ b/lib/libc/net/ascii2addr.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright 1996 Massachusetts Institute of Technology
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose and without fee is hereby
+ * granted, provided that both the above copyright notice and this
+ * permission notice appear in all copies, that both the above
+ * copyright notice and this permission notice appear in all
+ * supporting documentation, and that the name of M.I.T. not be used
+ * in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. M.I.T. makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
+ * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
+ * SHALL M.I.T. 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.
+ *
+ * $ANA: ascii2addr.c,v 1.2 1996/06/13 18:46:02 wollman Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <errno.h>
+#include <string.h>
+
+#include <net/if_dl.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+ascii2addr(af, ascii, result)
+ int af;
+ const char *ascii;
+ void *result;
+{
+ struct in_addr *ina;
+ char strbuf[4*sizeof("123")]; /* long enough for V4 only */
+
+ switch(af) {
+ case AF_INET:
+ ina = result;
+ strbuf[0] = '\0';
+ strncat(strbuf, ascii, (sizeof strbuf)-1);
+ if (inet_aton(strbuf, ina))
+ return sizeof(struct in_addr);
+ errno = EINVAL;
+ break;
+
+ case AF_LINK:
+ link_addr(ascii, result);
+ /* oops... no way to detect failure */
+ return sizeof(struct sockaddr_dl);
+
+ default:
+ errno = EPROTONOSUPPORT;
+ break;
+ }
+
+ return -1;
+}
diff --git a/lib/libc/net/base64.c b/lib/libc/net/base64.c
new file mode 100644
index 0000000..868826a
--- /dev/null
+++ b/lib/libc/net/base64.c
@@ -0,0 +1,321 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+/*
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software. No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+
+#if defined(BSD) && (BSD >= 199103) && defined(AF_INET6)
+# include <stdlib.h>
+# include <string.h>
+#else
+# include "../conf/portability.h"
+#endif
+
+#define Assert(Cond) if (!(Cond)) abort()
+
+static const char Base64[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char Pad64 = '=';
+
+/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
+ The following encoding technique is taken from RFC 1521 by Borenstein
+ and Freed. It is reproduced here in a slightly edited form for
+ convenience.
+
+ A 65-character subset of US-ASCII is used, enabling 6 bits to be
+ represented per printable character. (The extra 65th character, "=",
+ is used to signify a special processing function.)
+
+ The encoding process represents 24-bit groups of input bits as output
+ strings of 4 encoded characters. Proceeding from left to right, a
+ 24-bit input group is formed by concatenating 3 8-bit input groups.
+ These 24 bits are then treated as 4 concatenated 6-bit groups, each
+ of which is translated into a single digit in the base64 alphabet.
+
+ Each 6-bit group is used as an index into an array of 64 printable
+ characters. The character referenced by the index is placed in the
+ output string.
+
+ Table 1: The Base64 Alphabet
+
+ Value Encoding Value Encoding Value Encoding Value Encoding
+ 0 A 17 R 34 i 51 z
+ 1 B 18 S 35 j 52 0
+ 2 C 19 T 36 k 53 1
+ 3 D 20 U 37 l 54 2
+ 4 E 21 V 38 m 55 3
+ 5 F 22 W 39 n 56 4
+ 6 G 23 X 40 o 57 5
+ 7 H 24 Y 41 p 58 6
+ 8 I 25 Z 42 q 59 7
+ 9 J 26 a 43 r 60 8
+ 10 K 27 b 44 s 61 9
+ 11 L 28 c 45 t 62 +
+ 12 M 29 d 46 u 63 /
+ 13 N 30 e 47 v
+ 14 O 31 f 48 w (pad) =
+ 15 P 32 g 49 x
+ 16 Q 33 h 50 y
+
+ Special processing is performed if fewer than 24 bits are available
+ at the end of the data being encoded. A full encoding quantum is
+ always completed at the end of a quantity. When fewer than 24 input
+ bits are available in an input group, zero bits are added (on the
+ right) to form an integral number of 6-bit groups. Padding at the
+ end of the data is performed using the '=' character.
+
+ Since all base64 input is an integral number of octets, only the
+ -------------------------------------------------
+ following cases can arise:
+
+ (1) the final quantum of encoding input is an integral
+ multiple of 24 bits; here, the final unit of encoded
+ output will be an integral multiple of 4 characters
+ with no "=" padding,
+ (2) the final quantum of encoding input is exactly 8 bits;
+ here, the final unit of encoded output will be two
+ characters followed by two "=" padding characters, or
+ (3) the final quantum of encoding input is exactly 16 bits;
+ here, the final unit of encoded output will be three
+ characters followed by one "=" padding character.
+ */
+
+int
+b64_ntop(src, srclength, target, targsize)
+ u_char const *src;
+ size_t srclength;
+ char *target;
+ size_t targsize;
+{
+ size_t datalength = 0;
+ u_char input[3];
+ u_char output[4];
+ int i;
+
+ while (2 < srclength) {
+ input[0] = *src++;
+ input[1] = *src++;
+ input[2] = *src++;
+ srclength -= 3;
+
+ output[0] = input[0] >> 2;
+ output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+ output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
+ output[3] = input[2] & 0x3f;
+ Assert(output[0] < 64);
+ Assert(output[1] < 64);
+ Assert(output[2] < 64);
+ Assert(output[3] < 64);
+
+ if (datalength + 4 > targsize)
+ return (-1);
+ target[datalength++] = Base64[output[0]];
+ target[datalength++] = Base64[output[1]];
+ target[datalength++] = Base64[output[2]];
+ target[datalength++] = Base64[output[3]];
+ }
+
+ /* Now we worry about padding. */
+ if (0 != srclength) {
+ /* Get what's left. */
+ input[0] = input[1] = input[2] = '\0';
+ for (i = 0; i < srclength; i++)
+ input[i] = *src++;
+
+ output[0] = input[0] >> 2;
+ output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+ output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
+ Assert(output[0] < 64);
+ Assert(output[1] < 64);
+ Assert(output[2] < 64);
+
+ if (datalength + 4 > targsize)
+ return (-1);
+ target[datalength++] = Base64[output[0]];
+ target[datalength++] = Base64[output[1]];
+ if (srclength == 1)
+ target[datalength++] = Pad64;
+ else
+ target[datalength++] = Base64[output[2]];
+ target[datalength++] = Pad64;
+ }
+ if (datalength >= targsize)
+ return (-1);
+ target[datalength] = '\0'; /* Returned value doesn't count \0. */
+ return (datalength);
+}
+
+/* skips all whitespace anywhere.
+ converts characters, four at a time, starting at (or after)
+ src from base - 64 numbers into three 8 bit bytes in the target area.
+ it returns the number of data bytes stored at the target, or -1 on error.
+ */
+
+int
+b64_pton(src, target, targsize)
+ char const *src;
+ u_char *target;
+ size_t targsize;
+{
+ int tarindex, state, ch;
+ char *pos;
+
+ state = 0;
+ tarindex = 0;
+
+ while ((ch = *src++) != '\0') {
+ if (isspace(ch)) /* Skip whitespace anywhere. */
+ continue;
+
+ if (ch == Pad64)
+ break;
+
+ pos = strchr(Base64, ch);
+ if (pos == 0) /* A non-base64 character. */
+ return (-1);
+
+ switch (state) {
+ case 0:
+ if (target) {
+ if (tarindex >= targsize)
+ return (-1);
+ target[tarindex] = (pos - Base64) << 2;
+ }
+ state = 1;
+ break;
+ case 1:
+ if (target) {
+ if (tarindex + 1 >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64) >> 4;
+ target[tarindex+1] = ((pos - Base64) & 0x0f)
+ << 4 ;
+ }
+ tarindex++;
+ state = 2;
+ break;
+ case 2:
+ if (target) {
+ if (tarindex + 1 >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64) >> 2;
+ target[tarindex+1] = ((pos - Base64) & 0x03)
+ << 6;
+ }
+ tarindex++;
+ state = 3;
+ break;
+ case 3:
+ if (target) {
+ if (tarindex >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64);
+ }
+ tarindex++;
+ state = 0;
+ break;
+ default:
+ abort();
+ }
+ }
+
+ /*
+ * We are done decoding Base-64 chars. Let's see if we ended
+ * on a byte boundary, and/or with erroneous trailing characters.
+ */
+
+ if (ch == Pad64) { /* We got a pad char. */
+ ch = *src++; /* Skip it, get next. */
+ switch (state) {
+ case 0: /* Invalid = in first position */
+ case 1: /* Invalid = in second position */
+ return (-1);
+
+ case 2: /* Valid, means one byte of info */
+ /* Skip any number of spaces. */
+ for (NULL; ch != '\0'; ch = *src++)
+ if (!isspace(ch))
+ break;
+ /* Make sure there is another trailing = sign. */
+ if (ch != Pad64)
+ return (-1);
+ ch = *src++; /* Skip the = */
+ /* Fall through to "single trailing =" case. */
+ /* FALLTHROUGH */
+
+ case 3: /* Valid, means two bytes of info */
+ /*
+ * We know this char is an =. Is there anything but
+ * whitespace after it?
+ */
+ for (NULL; ch != '\0'; ch = *src++)
+ if (!isspace(ch))
+ return (-1);
+
+ /*
+ * Now make sure for cases 2 and 3 that the "extra"
+ * bits that slopped past the last full byte were
+ * zeros. If we don't check them, they become a
+ * subliminal channel.
+ */
+ if (target && target[tarindex] != 0)
+ return (-1);
+ }
+ } else {
+ /*
+ * We ended by seeing the end of the string. Make sure we
+ * have no partial bytes lying around.
+ */
+ if (state != 0)
+ return (-1);
+ }
+
+ return (tarindex);
+}
diff --git a/lib/libc/net/ether_addr.c b/lib/libc/net/ether_addr.c
new file mode 100644
index 0000000..9b7a9ab
--- /dev/null
+++ b/lib/libc/net/ether_addr.c
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 1995
+ * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul 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.
+ *
+ * ethernet address conversion and lookup routines
+ *
+ * Written by Bill Paul <wpaul@ctr.columbia.edu>
+ * Center for Telecommunications Research
+ * Columbia University, New York City
+ *
+ * $Id$
+ */
+
+
+#include <stdio.h>
+#include <paths.h>
+#include <sys/types.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <net/ethernet.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+#ifndef _PATH_ETHERS
+#define _PATH_ETHERS "/etc/ethers"
+#endif
+
+/*
+ * Parse a string of text containing an ethernet address and hostname
+ * and separate it into its component parts.
+ */
+int ether_line(l, e, hostname)
+ char *l;
+ struct ether_addr *e;
+ char *hostname;
+{
+ int i, o[6];
+
+ i = sscanf(l, "%x:%x:%x:%x:%x:%x %s", &o[0], &o[1], &o[2],
+ &o[3], &o[4], &o[5],
+ hostname);
+ if (i != 7)
+ return (i);
+
+ for (i=0; i<6; i++)
+ e->octet[i] = o[i];
+ return (0);
+}
+
+/*
+ * Convert an ASCII representation of an ethernet address to
+ * binary form.
+ */
+struct ether_addr *ether_aton(a)
+ char *a;
+{
+ int i;
+ static struct ether_addr o;
+ unsigned int o0, o1, o2, o3, o4, o5;
+
+ i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o0, &o1, &o2, &o3, &o4, &o5);
+
+ if (i != 6)
+ return (NULL);
+
+ o.octet[0]=o0;
+ o.octet[1]=o1;
+ o.octet[2]=o2;
+ o.octet[3]=o3;
+ o.octet[4]=o4;
+ o.octet[5]=o5;
+
+ return ((struct ether_addr *)&o);
+}
+
+/*
+ * Convert a binary representation of an ethernet address to
+ * an ASCII string.
+ */
+char *ether_ntoa(n)
+ struct ether_addr *n;
+{
+ int i;
+ static char a[18];
+
+ i = sprintf(a,"%x:%x:%x:%x:%x:%x",n->octet[0],n->octet[1],n->octet[2],
+ n->octet[3],n->octet[4],n->octet[5]);
+ if (i < 11)
+ return (NULL);
+ return ((char *)&a);
+}
+
+/*
+ * Map an ethernet address to a hostname. Use either /etc/ethers or
+ * NIS/YP.
+ */
+
+int ether_ntohost(hostname, e)
+ char *hostname;
+ struct ether_addr *e;
+{
+ FILE *fp;
+ char buf[BUFSIZ + 2];
+ struct ether_addr local_ether;
+ char local_host[MAXHOSTNAMELEN];
+#ifdef YP
+ char *result;
+ int resultlen;
+ char *ether_a;
+ char *yp_domain;
+#endif
+ if ((fp = fopen(_PATH_ETHERS, "r")) == NULL)
+ return (1);
+
+ while (fgets(buf,BUFSIZ,fp)) {
+ if (buf[0] == '#')
+ continue;
+#ifdef YP
+ if (buf[0] == '+') {
+ if (yp_get_default_domain(&yp_domain))
+ continue;
+ ether_a = ether_ntoa(e);
+ if (yp_match(yp_domain, "ethers.byaddr", ether_a,
+ strlen(ether_a), &result, &resultlen)) {
+ continue;
+ }
+ strncpy(buf, result, resultlen);
+ buf[resultlen] = '\0';
+ free(result);
+ }
+#endif
+ if (!ether_line(buf, &local_ether, local_host)) {
+ if (!bcmp((char *)&local_ether.octet[0],
+ (char *)&e->octet[0], 6)) {
+ /* We have a match */
+ strcpy(hostname, local_host);
+ fclose(fp);
+ return(0);
+ }
+ }
+ }
+ fclose(fp);
+ return (1);
+}
+
+/*
+ * Map a hostname to an ethernet address using /etc/ethers or
+ * NIS/YP.
+ */
+int ether_hostton(hostname, e)
+ char *hostname;
+ struct ether_addr *e;
+{
+ FILE *fp;
+ char buf[BUFSIZ + 2];
+ struct ether_addr local_ether;
+ char local_host[MAXHOSTNAMELEN];
+#ifdef YP
+ char *result;
+ int resultlen;
+ char *yp_domain;
+#endif
+ if ((fp = fopen(_PATH_ETHERS, "r")) == NULL)
+ return (1);
+
+ while (fgets(buf,BUFSIZ,fp)) {
+ if (buf[0] == '#')
+ continue;
+#ifdef YP
+ if (buf[0] == '+') {
+ if (yp_get_default_domain(&yp_domain))
+ continue;
+ if (yp_match(yp_domain, "ethers.byname", hostname,
+ strlen(hostname), &result, &resultlen)) {
+ continue;
+ }
+ strncpy(buf, result, resultlen);
+ buf[resultlen] = '\0';
+ free(result);
+ }
+#endif
+ if (!ether_line(buf, &local_ether, local_host)) {
+ if (!strcmp(hostname, local_host)) {
+ /* We have a match */
+ bcopy((char *)&local_ether.octet[0],
+ (char *)&e->octet[0], 6);
+ fclose(fp);
+ return(0);
+ }
+ }
+ }
+ fclose(fp);
+ return (1);
+}
diff --git a/lib/libc/net/ethers.3 b/lib/libc/net/ethers.3
new file mode 100644
index 0000000..afea483
--- /dev/null
+++ b/lib/libc/net/ethers.3
@@ -0,0 +1,193 @@
+.\" Copyright (c) 1995
+.\" Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Bill Paul.
+.\" 4. Neither the name of the author nor the names of any co-contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY Bill Paul 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.
+.\"
+.\" $Id$
+.\"
+.Dd April 12, 1995
+.Dt ETHERS 3
+.Os FreeBSD 2.1
+.Sh NAME
+.Nm ethers ,
+.Nm ether_line ,
+.Nm ether_aton ,
+.Nm ether_ntoa ,
+.Nm ether_ntohost ,
+.Nm ether_hostton
+.Nd Ethernet address conversion and lookup routines
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/socket.h>
+.Fd #include <net/ethernet.h>
+.Ft int
+.Fn ether_line "char *l" "struct ether_addr *e" "char *hostname"
+.Ft struct ether_addr *
+.Fn ether_aton "char *a"
+.Ft char *
+.Fn ether_ntoa "struct ether_addr *n"
+.Ft int
+.Fn ether_ntohost "char *hostname" "struct ether_addr *e"
+.Ft int
+.Fn ether_hostton "char *hostname" "struct ether_addr *e"
+.Sh DESCRIPTION
+These functions operate on ethernet addresses using an
+.Ar ether_addr
+structure, which is defined in the header file
+.Aq Pa netinet/if_ether.h :
+.Bd -literal -offset indent
+/*
+ * The number of bytes in an ethernet (MAC) address.
+ */
+#define ETHER_ADDR_LEN 6
+
+/*
+ * Structure of a 48-bit Ethernet address.
+ */
+struct ether_addr {
+ u_char octet[ETHER_ADDR_LEN];
+};
+.Ed
+.Pp
+The function
+.Fn ether_line
+scans
+.Ar l ,
+an
+.Tn ASCII
+string in
+.Xr ethers 5
+format and sets
+.Ar e
+to the ethernet address specified in the string and
+.Ar h
+to the hostname. This function is used to parse lines from
+.Pa /etc/ethers
+into their component parts.
+.Pp
+The
+.Fn ether_aton
+function converts an
+.Tn ASCII
+representation of an ethernet address into an
+.Ar ether_addr
+structure. Likewise,
+.Fn ether_ntoa
+converts an ethernet address specified as an
+.Ar ether_addr
+structure into an
+.Tn ASCII
+string.
+.Pp
+The
+.Fn ether_ntohost
+and
+.Fn ether_hostton
+functions map ethernet addresses to their corresponding hostnames
+as specified in the
+.Pa /etc/ethers
+database.
+.Fn ether_ntohost
+converts from ethernet address to hostname, and
+.Fn ether_hostton
+converts from hostname to ethernet address.
+.Sh RETURN VALUES
+.Fn ether_line
+returns zero on success and non-zero if it was unable to parse
+any part of the supplied line
+.Ar l .
+It returns the extracted ethernet address in the supplied
+.Ar ether_addr
+structure
+.Ar e
+and the hostname in the supplied string
+.Ar h .
+.Pp
+On success,
+.Fn ether_ntoa
+returns a pointer to a string containing an
+.Tn ASCII
+representation of an ethernet address. If it is unable to convert
+the supplied
+.Ar ether_addr
+structure, it returns a
+.Dv NULL
+pointer. Likewise,
+.Fn ether_aton
+returns a pointer to an
+.Ar ether_addr
+structure on success and a
+.Dv NULL
+pointer on failure.
+.Pp
+The
+.Fn ether_ntohost
+and
+.Fn ether_hostton
+functions both return zero on success or non-zero if they were
+unable to find a match in the
+.Pa /etc/ethers
+database.
+.Sh NOTES
+The user must insure that the hostname strings passed to the
+the
+.Fn ether_line ,
+.Fn ether_ntohost
+and
+.Fn ether_hostton
+functions are large enough to contain the returned hostnames.
+.Sh NIS INTERACTION
+If the
+.Pa /etc/ethers
+contains a line with a single + in it, the
+.Fn ether_ntohost
+and
+.Fn ether_hostton
+functions will attempt to consult the NIS
+.Pa ethers.byname
+and
+.Pa ethers.byaddr
+maps in addition to the data in the
+.Pa /etc/ethers
+file.
+.Sh SEE ALSO
+.Xr yp 4 ,
+.Xr ethers 5
+.Sh BUGS
+.Pp
+The
+.Fn ether_aton
+and
+.Fn ether_ntoa
+functions returns values that are stored in static memory areas
+which may be overwritten the next time they are called.
+.Sh HISTORY
+This particular implementation of the
+.Nm ethers
+library functions were written for and first appeared in
+.Fx 2.1 .
diff --git a/lib/libc/net/gethostbydns.c b/lib/libc/net/gethostbydns.c
new file mode 100644
index 0000000..4d13e2e
--- /dev/null
+++ b/lib/libc/net/gethostbydns.c
@@ -0,0 +1,736 @@
+/*
+ * ++Copyright++ 1985, 1988, 1993
+ * -
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
+static char fromrcsid[] = "From: Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp";
+static char rcsid[] = "$Id: gethostbydns.c,v 1.21 1997/03/12 11:02:00 peter Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#include <syslog.h>
+
+#include "res_config.h"
+
+#define SPRINTF(x) ((size_t)sprintf x)
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+static const char AskedForGot[] =
+ "gethostby*.gethostanswer: asked for \"%s\", got \"%s\"";
+
+static char *h_addr_ptrs[MAXADDRS + 1];
+
+static struct hostent host;
+static char *host_aliases[MAXALIASES];
+static char hostbuf[8*1024];
+static u_char host_addr[16]; /* IPv4 or IPv6 */
+
+#ifdef RESOLVSORT
+static void addrsort __P((char **, int));
+#endif
+
+#if PACKETSZ > 1024
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 1024
+#endif
+
+typedef union {
+ HEADER hdr;
+ u_char buf[MAXPACKET];
+} querybuf;
+
+typedef union {
+ int32_t al;
+ char ac;
+} align;
+
+extern int h_errno;
+int _dns_ttl_;
+
+#ifdef DEBUG
+static void
+dprintf(msg, num)
+ char *msg;
+ int num;
+{
+ if (_res.options & RES_DEBUG) {
+ int save = errno;
+
+ printf(msg, num);
+ errno = save;
+ }
+}
+#else
+# define dprintf(msg, num) /*nada*/
+#endif
+
+static struct hostent *
+gethostanswer(answer, anslen, qname, qtype)
+ const querybuf *answer;
+ int anslen;
+ const char *qname;
+ int qtype;
+{
+ register const HEADER *hp;
+ register const u_char *cp;
+ register int n;
+ const u_char *eom;
+ char *bp, **ap, **hap;
+ int type, class, buflen, ancount, qdcount;
+ int haveanswer, had_error;
+ int toobig = 0;
+ char tbuf[MAXDNAME];
+ const char *tname;
+ int (*name_ok) __P((const char *));
+
+ tname = qname;
+ host.h_name = NULL;
+ eom = answer->buf + anslen;
+ switch (qtype) {
+ case T_A:
+ case T_AAAA:
+ name_ok = res_hnok;
+ break;
+ case T_PTR:
+ name_ok = res_dnok;
+ break;
+ default:
+ h_errno = NO_RECOVERY;
+ return (NULL); /* XXX should be abort(); */
+ }
+ /*
+ * find first satisfactory answer
+ */
+ hp = &answer->hdr;
+ ancount = ntohs(hp->ancount);
+ qdcount = ntohs(hp->qdcount);
+ bp = hostbuf;
+ buflen = sizeof hostbuf;
+ cp = answer->buf + HFIXEDSZ;
+ if (qdcount != 1) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !(*name_ok)(bp)) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ cp += n + QFIXEDSZ;
+ if (qtype == T_A || qtype == T_AAAA) {
+ /* res_send() has already verified that the query name is the
+ * same as the one we sent; this just gets the expanded name
+ * (i.e., with the succeeding search-domain tacked on).
+ */
+ n = strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ host.h_name = bp;
+ bp += n;
+ buflen -= n;
+ /* The qname can be abbreviated, but h_name is now absolute. */
+ qname = host.h_name;
+ }
+ ap = host_aliases;
+ *ap = NULL;
+ host.h_aliases = host_aliases;
+ hap = h_addr_ptrs;
+ *hap = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ haveanswer = 0;
+ had_error = 0;
+ _dns_ttl_ = -1;
+ while (ancount-- > 0 && cp < eom && !had_error) {
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !(*name_ok)(bp)) {
+ had_error++;
+ continue;
+ }
+ cp += n; /* name */
+ type = _getshort(cp);
+ cp += INT16SZ; /* type */
+ class = _getshort(cp);
+ cp += INT16SZ; /* class */
+ if (qtype == T_A && type == T_A)
+ _dns_ttl_ = _getlong(cp);
+ cp += INT32SZ; /* TTL */
+ n = _getshort(cp);
+ cp += INT16SZ; /* len */
+ if (class != C_IN) {
+ /* XXX - debug? syslog? */
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) {
+ if (ap >= &host_aliases[MAXALIASES-1])
+ continue;
+ n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+ if ((n < 0) || !(*name_ok)(tbuf)) {
+ had_error++;
+ continue;
+ }
+ cp += n;
+ /* Store alias. */
+ *ap++ = bp;
+ n = strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ had_error++;
+ continue;
+ }
+ bp += n;
+ buflen -= n;
+ /* Get canonical name. */
+ n = strlen(tbuf) + 1; /* for the \0 */
+ if (n > buflen || n >= MAXHOSTNAMELEN) {
+ had_error++;
+ continue;
+ }
+ strcpy(bp, tbuf);
+ host.h_name = bp;
+ bp += n;
+ buflen -= n;
+ continue;
+ }
+ if (qtype == T_PTR && type == T_CNAME) {
+ n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+ if (n < 0 || !res_dnok(tbuf)) {
+ had_error++;
+ continue;
+ }
+ cp += n;
+ /* Get canonical name. */
+ n = strlen(tbuf) + 1; /* for the \0 */
+ if (n > buflen || n >= MAXHOSTNAMELEN) {
+ had_error++;
+ continue;
+ }
+ strcpy(bp, tbuf);
+ tname = bp;
+ bp += n;
+ buflen -= n;
+ continue;
+ }
+ if (type != qtype) {
+ syslog(LOG_NOTICE|LOG_AUTH,
+ "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"",
+ qname, p_class(C_IN), p_type(qtype),
+ p_type(type));
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ switch (type) {
+ case T_PTR:
+ if (strcasecmp(tname, bp) != 0) {
+ syslog(LOG_NOTICE|LOG_AUTH,
+ AskedForGot, qname, bp);
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !res_hnok(bp)) {
+ had_error++;
+ break;
+ }
+#if MULTI_PTRS_ARE_ALIASES
+ cp += n;
+ if (!haveanswer)
+ host.h_name = bp;
+ else if (ap < &host_aliases[MAXALIASES-1])
+ *ap++ = bp;
+ else
+ n = -1;
+ if (n != -1) {
+ n = strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ had_error++;
+ break;
+ }
+ bp += n;
+ buflen -= n;
+ }
+ break;
+#else
+ host.h_name = bp;
+ if (_res.options & RES_USE_INET6) {
+ n = strlen(bp) + 1; /* for the \0 */
+ if (n >= MAXHOSTNAMELEN) {
+ had_error++;
+ break;
+ }
+ bp += n;
+ buflen -= n;
+ _map_v4v6_hostent(&host, &bp, &buflen);
+ }
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+#endif
+ case T_A:
+ case T_AAAA:
+ if (strcasecmp(host.h_name, bp) != 0) {
+ syslog(LOG_NOTICE|LOG_AUTH,
+ AskedForGot, host.h_name, bp);
+ cp += n;
+ continue; /* XXX - had_error++ ? */
+ }
+ if (n != host.h_length) {
+ cp += n;
+ continue;
+ }
+ if (!haveanswer) {
+ register int nn;
+
+ host.h_name = bp;
+ nn = strlen(bp) + 1; /* for the \0 */
+ bp += nn;
+ buflen -= nn;
+ }
+
+ bp += sizeof(align) - ((u_long)bp % sizeof(align));
+
+ if (bp + n >= &hostbuf[sizeof hostbuf]) {
+ dprintf("size (%d) too big\n", n);
+ had_error++;
+ continue;
+ }
+ if (hap >= &h_addr_ptrs[MAXADDRS-1]) {
+ if (!toobig++)
+ dprintf("Too many addresses (%d)\n",
+ MAXADDRS);
+ cp += n;
+ continue;
+ }
+ bcopy(cp, *hap++ = bp, n);
+ bp += n;
+ buflen -= n;
+ cp += n;
+ break;
+ default:
+ dprintf("Impossible condition (type=%d)\n", type);
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ /* BIND has abort() here, too risky on bad data */
+ }
+ if (!had_error)
+ haveanswer++;
+ }
+ if (haveanswer) {
+ *ap = NULL;
+ *hap = NULL;
+# if defined(RESOLVSORT)
+ /*
+ * Note: we sort even if host can take only one address
+ * in its return structures - should give it the "best"
+ * address in that case, not some random one
+ */
+ if (_res.nsort && haveanswer > 1 && qtype == T_A)
+ addrsort(h_addr_ptrs, haveanswer);
+# endif /*RESOLVSORT*/
+ if (!host.h_name) {
+ n = strlen(qname) + 1; /* for the \0 */
+ if (n > buflen || n >= MAXHOSTNAMELEN)
+ goto no_recovery;
+ strcpy(bp, qname);
+ host.h_name = bp;
+ bp += n;
+ buflen -= n;
+ }
+ if (_res.options & RES_USE_INET6)
+ _map_v4v6_hostent(&host, &bp, &buflen);
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+ }
+ no_recovery:
+ h_errno = NO_RECOVERY;
+ return (NULL);
+}
+
+struct hostent *
+__dns_getanswer(answer, anslen, qname, qtype)
+ const char *answer;
+ int anslen;
+ const char *qname;
+ int qtype;
+{
+ switch(qtype) {
+ case T_AAAA:
+ host.h_addrtype = AF_INET6;
+ host.h_length = IN6ADDRSZ;
+ break;
+ case T_A:
+ default:
+ host.h_addrtype = AF_INET;
+ host.h_length = INADDRSZ;
+ break;
+ }
+
+ return(gethostanswer((const querybuf *)answer, anslen, qname, qtype));
+}
+
+struct hostent *
+_gethostbydnsname(name, af)
+ const char *name;
+ int af;
+{
+ querybuf buf;
+ register const char *cp;
+ char *bp;
+ int n, size, type, len;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+
+ switch (af) {
+ case AF_INET:
+ size = INADDRSZ;
+ type = T_A;
+ break;
+ case AF_INET6:
+ size = IN6ADDRSZ;
+ type = T_AAAA;
+ break;
+ default:
+ h_errno = NETDB_INTERNAL;
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+
+ host.h_addrtype = af;
+ host.h_length = size;
+
+ /*
+ * if there aren't any dots, it could be a user-level alias.
+ * this is also done in res_query() since we are not the only
+ * function that looks up host names.
+ */
+ if (!strchr(name, '.') && (cp = __hostalias(name)))
+ name = cp;
+
+ /*
+ * disallow names consisting only of digits/dots, unless
+ * they end in a dot.
+ */
+ if (isdigit(name[0]))
+ for (cp = name;; ++cp) {
+ if (!*cp) {
+ if (*--cp == '.')
+ break;
+ /*
+ * All-numeric, no dot at the end.
+ * Fake up a hostent as if we'd actually
+ * done a lookup.
+ */
+ if (inet_pton(af, name, host_addr) <= 0) {
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ strncpy(hostbuf, name, MAXDNAME);
+ hostbuf[MAXDNAME] = '\0';
+ bp = hostbuf + MAXDNAME;
+ len = sizeof hostbuf - MAXDNAME;
+ host.h_name = hostbuf;
+ host.h_aliases = host_aliases;
+ host_aliases[0] = NULL;
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ if (_res.options & RES_USE_INET6)
+ _map_v4v6_hostent(&host, &bp, &len);
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+ }
+ if (!isdigit(*cp) && *cp != '.')
+ break;
+ }
+ if ((isxdigit(name[0]) && strchr(name, ':') != NULL) ||
+ name[0] == ':')
+ for (cp = name;; ++cp) {
+ if (!*cp) {
+ if (*--cp == '.')
+ break;
+ /*
+ * All-IPv6-legal, no dot at the end.
+ * Fake up a hostent as if we'd actually
+ * done a lookup.
+ */
+ if (inet_pton(af, name, host_addr) <= 0) {
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ strncpy(hostbuf, name, MAXDNAME);
+ hostbuf[MAXDNAME] = '\0';
+ bp = hostbuf + MAXDNAME;
+ len = sizeof hostbuf - MAXDNAME;
+ host.h_name = hostbuf;
+ host.h_aliases = host_aliases;
+ host_aliases[0] = NULL;
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+ }
+ if (!isxdigit(*cp) && *cp != ':' && *cp != '.')
+ break;
+ }
+
+ if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) {
+ dprintf("res_search failed (%d)\n", n);
+ return (NULL);
+ }
+ return (gethostanswer(&buf, n, name, type));
+}
+
+struct hostent *
+_gethostbydnsaddr(addr, len, af)
+ const char *addr; /* XXX should have been def'd as u_char! */
+ int len, af;
+{
+ const u_char *uaddr = (const u_char *)addr;
+ static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
+ static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
+ int n, size;
+ querybuf buf;
+ register struct hostent *hp;
+ char qbuf[MAXDNAME+1], *qp;
+#ifdef SUNSECURITY
+ register struct hostent *rhp;
+ char **haddr;
+ u_long old_options;
+ char hname2[MAXDNAME+1];
+#endif /*SUNSECURITY*/
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ if (af == AF_INET6 && len == IN6ADDRSZ &&
+ (!bcmp(uaddr, mapped, sizeof mapped) ||
+ !bcmp(uaddr, tunnelled, sizeof tunnelled))) {
+ /* Unmap. */
+ addr += sizeof mapped;
+ uaddr += sizeof mapped;
+ af = AF_INET;
+ len = INADDRSZ;
+ }
+ switch (af) {
+ case AF_INET:
+ size = INADDRSZ;
+ break;
+ case AF_INET6:
+ size = IN6ADDRSZ;
+ break;
+ default:
+ errno = EAFNOSUPPORT;
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ if (size != len) {
+ errno = EINVAL;
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ switch (af) {
+ case AF_INET:
+ (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
+ (uaddr[3] & 0xff),
+ (uaddr[2] & 0xff),
+ (uaddr[1] & 0xff),
+ (uaddr[0] & 0xff));
+ break;
+ case AF_INET6:
+ qp = qbuf;
+ for (n = IN6ADDRSZ - 1; n >= 0; n--) {
+ qp += SPRINTF((qp, "%x.%x.",
+ uaddr[n] & 0xf,
+ (uaddr[n] >> 4) & 0xf));
+ }
+ strcpy(qp, "ip6.int");
+ break;
+ default:
+ abort();
+ }
+ n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf);
+ if (n < 0) {
+ dprintf("res_query failed (%d)\n", n);
+ return (NULL);
+ }
+ if (!(hp = gethostanswer(&buf, n, qbuf, T_PTR)))
+ return (NULL); /* h_errno was set by gethostanswer() */
+#ifdef SUNSECURITY
+ if (af == AF_INET) {
+ /*
+ * turn off search as the name should be absolute,
+ * 'localhost' should be matched by defnames
+ */
+ strncpy(hname2, hp->h_name, MAXDNAME);
+ hname2[MAXDNAME] = '\0';
+ old_options = _res.options;
+ _res.options &= ~RES_DNSRCH;
+ _res.options |= RES_DEFNAMES;
+ if (!(rhp = gethostbyname(hname2))) {
+ syslog(LOG_NOTICE|LOG_AUTH,
+ "gethostbyaddr: No A record for %s (verifying [%s])",
+ hname2, inet_ntoa(*((struct in_addr *)addr)));
+ _res.options = old_options;
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ _res.options = old_options;
+ for (haddr = rhp->h_addr_list; *haddr; haddr++)
+ if (!memcmp(*haddr, addr, INADDRSZ))
+ break;
+ if (!*haddr) {
+ syslog(LOG_NOTICE|LOG_AUTH,
+ "gethostbyaddr: A record of %s != PTR record [%s]",
+ hname2, inet_ntoa(*((struct in_addr *)addr)));
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ }
+#endif /*SUNSECURITY*/
+ hp->h_addrtype = af;
+ hp->h_length = len;
+ bcopy(addr, host_addr, len);
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ if (af == AF_INET && (_res.options & RES_USE_INET6)) {
+ _map_v4v6_address((char*)host_addr, (char*)host_addr);
+ hp->h_addrtype = AF_INET6;
+ hp->h_length = IN6ADDRSZ;
+ }
+ h_errno = NETDB_SUCCESS;
+ return (hp);
+}
+
+#ifdef RESOLVSORT
+static void
+addrsort(ap, num)
+ char **ap;
+ int num;
+{
+ int i, j;
+ char **p;
+ short aval[MAXADDRS];
+ int needsort = 0;
+
+ p = ap;
+ for (i = 0; i < num; i++, p++) {
+ for (j = 0 ; (unsigned)j < _res.nsort; j++)
+ if (_res.sort_list[j].addr.s_addr ==
+ (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
+ break;
+ aval[i] = j;
+ if (needsort == 0 && i > 0 && j < aval[i-1])
+ needsort = i;
+ }
+ if (!needsort)
+ return;
+
+ while (needsort < num) {
+ for (j = needsort - 1; j >= 0; j--) {
+ if (aval[j] > aval[j+1]) {
+ char *hp;
+
+ i = aval[j];
+ aval[j] = aval[j+1];
+ aval[j+1] = i;
+
+ hp = ap[j];
+ ap[j] = ap[j+1];
+ ap[j+1] = hp;
+
+ } else
+ break;
+ }
+ needsort++;
+ }
+}
+#endif
+void
+_sethostdnsent(stayopen)
+ int stayopen;
+{
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+ return;
+ if (stayopen)
+ _res.options |= RES_STAYOPEN | RES_USEVC;
+}
+
+void
+_endhostdnsent()
+{
+ _res.options &= ~(RES_STAYOPEN | RES_USEVC);
+ res_close();
+}
diff --git a/lib/libc/net/gethostbyht.c b/lib/libc/net/gethostbyht.c
new file mode 100644
index 0000000..cf12f57
--- /dev/null
+++ b/lib/libc/net/gethostbyht.c
@@ -0,0 +1,202 @@
+/*-
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id: gethostbyht.c,v 1.9 1997/02/22 15:00:07 peter Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <arpa/nameser.h> /* XXX */
+#include <resolv.h> /* XXX */
+
+#define MAXALIASES 35
+
+static struct hostent host;
+static char *host_aliases[MAXALIASES];
+static char hostbuf[BUFSIZ+1];
+static FILE *hostf = NULL;
+static u_char host_addr[16]; /* IPv4 or IPv6 */
+static char *h_addr_ptrs[2];
+static int stayopen = 0;
+
+void
+_sethosthtent(f)
+ int f;
+{
+ if (!hostf)
+ hostf = fopen(_PATH_HOSTS, "r" );
+ else
+ rewind(hostf);
+ stayopen = f;
+}
+
+void
+_endhosthtent()
+{
+ if (hostf && !stayopen) {
+ (void) fclose(hostf);
+ hostf = NULL;
+ }
+}
+
+struct hostent *
+gethostent()
+{
+ char *p;
+ register char *cp, **q;
+ int af, len;
+
+ if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ again:
+ if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) {
+ h_errno = HOST_NOT_FOUND;
+ return (NULL);
+ }
+ if (*p == '#')
+ goto again;
+ if (!(cp = strpbrk(p, "#\n")))
+ goto again;
+ *cp = '\0';
+ if (!(cp = strpbrk(p, " \t")))
+ goto again;
+ *cp++ = '\0';
+ if (inet_pton(AF_INET6, p, host_addr) > 0) {
+ af = AF_INET6;
+ len = IN6ADDRSZ;
+ } else if (inet_pton(AF_INET, p, host_addr) > 0) {
+ if (_res.options & RES_USE_INET6) {
+ _map_v4v6_address((char*)host_addr, (char*)host_addr);
+ af = AF_INET6;
+ len = IN6ADDRSZ;
+ } else {
+ af = AF_INET;
+ len = INADDRSZ;
+ }
+ } else {
+ goto again;
+ }
+ h_addr_ptrs[0] = (char *)host_addr;
+ h_addr_ptrs[1] = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ host.h_length = len;
+ host.h_addrtype = af;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ host.h_name = cp;
+ q = host.h_aliases = host_aliases;
+ if ((cp = strpbrk(cp, " \t")) != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &host_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ if ((cp = strpbrk(cp, " \t")) != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ h_errno = NETDB_SUCCESS;
+ return (&host);
+}
+
+struct hostent *
+_gethostbyhtname(name, af)
+ const char *name;
+ int af;
+{
+ register struct hostent *p;
+ register char **cp;
+
+ sethostent(0);
+ while ((p = gethostent()) != NULL) {
+ if (p->h_addrtype != af)
+ continue;
+ if (strcasecmp(p->h_name, name) == 0)
+ break;
+ for (cp = p->h_aliases; *cp != 0; cp++)
+ if (strcasecmp(*cp, name) == 0)
+ goto found;
+ }
+found:
+ endhostent();
+ return (p);
+}
+
+struct hostent *
+_gethostbyhtaddr(addr, len, af)
+ const char *addr;
+ int len, af;
+{
+ register struct hostent *p;
+
+ sethostent(0);
+ while ((p = gethostent()) != NULL)
+ if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len))
+ break;
+ endhostent();
+ return (p);
+}
diff --git a/lib/libc/net/gethostbyname.3 b/lib/libc/net/gethostbyname.3
index b3b2d1f..e520e33 100644
--- a/lib/libc/net/gethostbyname.3
+++ b/lib/libc/net/gethostbyname.3
@@ -29,34 +29,45 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
+.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
+.\" $Id$
.\"
.Dd May 25, 1995
.Dt GETHOSTBYNAME 3
.Os BSD 4.2
.Sh NAME
.Nm gethostbyname ,
+.Nm gethostbyname2 ,
.Nm gethostbyaddr ,
.Nm gethostent ,
.Nm sethostent ,
.Nm endhostent ,
-.Nm herror
+.Nm herror ,
+.Nm hstrerror
.Nd get network host entry
.Sh SYNOPSIS
.Fd #include <netdb.h>
.Fd extern int h_errno;
.Ft struct hostent *
-.Fn gethostbyname "char *name"
+.Fn gethostbyname "const char *name"
.Ft struct hostent *
-.Fn gethostbyaddr "char *addr" "int len" "int type"
+.Fn gethostbyname2 "const char *name" "int af"
+.Ft struct hostent *
+.Fn gethostbyaddr "const char *addr" "int len" "int type"
.Ft struct hostent *
.Fn gethostent void
+.Ft void
.Fn sethostent "int stayopen"
+.Ft void
.Fn endhostent void
-.Fn herror "char *string"
+.Ft void
+.Fn herror "const char *string"
+.Ft const char *
+.Fn hstrerror "int err"
.Sh DESCRIPTION
The
-.Fn gethostbyname
+.Fn gethostbyname ,
+.Fn gethostbyname2
and
.Fn gethostbyaddr
functions
@@ -87,7 +98,7 @@ Official name of the host.
.It Fa h_aliases
A NULL-terminated array of alternate names for the host.
.It Fa h_addrtype
-The type of address being returned; currently always
+The type of address being returned; usually
.Dv AF_INET .
.It Fa h_length
The length, in bytes, of the address.
@@ -102,6 +113,8 @@ this is for backward compatibility.
.Pp
When using the nameserver,
.Fn gethostbyname
+and
+.Fn gethostbyname
will search for the named host in the current domain and its parents
unless the name ends in a dot.
If the name contains no dot, and if the environment variable
@@ -113,6 +126,25 @@ See
for the domain search procedure and the alias file format.
.Pp
The
+.Fn gethostbyname2
+function is an evolution of
+.Fn gethostbyname
+which is intended to allow lookups in address families other than
+.Dv AF_INET ,
+for example
+.Dv AF_INET6 .
+Currently the
+.Fa af
+argument must be specified as
+.Dv AF_INET
+else the fuction will return
+.Dv NULL
+after having set
+.Va h_errno
+to
+.Dv NETDB_INTERNAL
+.Pp
+The
.Fn sethostent
function
may be used to request the use of a connected
@@ -124,7 +156,8 @@ flag is non-zero,
this sets the option to send all queries to the name server using
.Tn TCP
and to retain the connection after each call to
-.Fn gethostbyname
+.Fn gethostbyname ,
+.Fn gethostbyname2
or
.Fn gethostbyaddr .
Otherwise, queries are performed using
@@ -137,13 +170,31 @@ function
closes the
.Tn TCP
connection.
+.Pp
+The
+.Fn herror
+function writes a message to the diagnostic output consisting of the
+string parameter
+.Fa s ,
+the constant string ": ", and a message corresponding to the value of
+.Va h_errno .
+.Pp
+The
+.Fn hstrerror
+function returns a string which is the message text corresponding to the
+value of the
+.Fa err
+parameter.
.Sh FILES
-.Bl -tag -width /etc/hosts -compact
+.Bl -tag -width /etc/resolv.conf -compact
.It Pa /etc/hosts
+.It Pa /etc/host.conf
+.It Pa /etc/resolv.conf
.El
.Sh DIAGNOSTICS
Error return status from
-.Fn gethostbyname
+.Fn gethostbyname ,
+.Fn gethostbyname2
and
.Fn gethostbyaddr
is indicated by return of a null pointer.
@@ -220,7 +271,8 @@ If the
.Fa stayopen
argument is non-zero,
the file will not be closed after each call to
-.Fn gethostbyname
+.Fn gethostbyname ,
+.Fn gethostbyname2
or
.Fn gethostbyaddr .
.Pp
@@ -242,6 +294,9 @@ and
.Fn sethostent
functions appeared in
.Bx 4.2 .
+The
+.Fn gethostbyname2
+function first appeared in bind-4.9.4.
.Sh BUGS
These functions use static data storage;
if the data is needed for future use, it should be
diff --git a/lib/libc/net/gethostbynis.c b/lib/libc/net/gethostbynis.c
new file mode 100644
index 0000000..45dbe5a
--- /dev/null
+++ b/lib/libc/net/gethostbynis.c
@@ -0,0 +1,142 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE 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[] = "@(#)$Id$";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+#ifdef YP
+static char *host_aliases[MAXALIASES];
+static char hostaddr[MAXADDRS];
+static char *host_addrs[2];
+#endif /* YP */
+
+static struct hostent *
+_gethostbynis(name, map, af)
+ const char *name;
+ char *map;
+ int af;
+{
+#ifdef YP
+ register char *cp, **q;
+ char *result;
+ int resultlen;
+ static struct hostent h;
+ static char *domain = (char *)NULL;
+ static char ypbuf[YPMAXRECORD + 2];
+
+ switch(af) {
+ case AF_INET:
+ break;
+ default:
+ case AF_INET6:
+ errno = EAFNOSUPPORT;
+ return NULL;
+ }
+
+ if (domain == (char *)NULL)
+ if (yp_get_default_domain (&domain))
+ return ((struct hostent *)NULL);
+
+ if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
+ return ((struct hostent *)NULL);
+
+ /* avoid potential memory leak */
+ bcopy((char *)result, (char *)&ypbuf, resultlen);
+ ypbuf[resultlen] = '\0';
+ free(result);
+ result = (char *)&ypbuf;
+
+ if ((cp = index(result, '\n')))
+ *cp = '\0';
+
+ cp = strpbrk(result, " \t");
+ *cp++ = '\0';
+ h.h_addr_list = host_addrs;
+ h.h_addr = hostaddr;
+ *((u_long *)h.h_addr) = inet_addr(result);
+ h.h_length = sizeof(u_long);
+ h.h_addrtype = AF_INET;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ h.h_name = cp;
+ q = h.h_aliases = host_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &host_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&h);
+#else
+ return (NULL);
+#endif /* YP */
+}
+
+struct hostent *
+_gethostbynisname(name, af)
+ const char *name;
+ int af;
+{
+ return _gethostbynis(name, "hosts.byname", af);
+}
+
+struct hostent *
+_gethostbynisaddr(addr, len, af)
+ const char *addr;
+ int len;
+ int af;
+{
+ return _gethostbynis(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr", af);
+}
diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c
index e0cc9aa..1912bba 100644
--- a/lib/libc/net/gethostnamadr.c
+++ b/lib/libc/net/gethostnamadr.c
@@ -1,6 +1,5 @@
/*-
- * Copyright (c) 1985, 1988, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1994, Garrett Wollman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,15 +9,8 @@
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 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
+ * THIS SOFTWARE IS PROVIDED BY THE 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
@@ -29,424 +21,204 @@
* 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.
- * -
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- * -
- * --Copyright--
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
-static char rcsid[] = "$Id: gethnamaddr.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel $";
+static char sccsid[] = "@(#)$Id$";
+static char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-#include <arpa/nameser.h>
#include <netdb.h>
-#include <resolv.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
-
-#define MAXALIASES 35
-#define MAXADDRS 35
-
-static char *h_addr_ptrs[MAXADDRS + 1];
-
-static struct hostent host;
-static char *host_aliases[MAXALIASES];
-static char hostbuf[BUFSIZ+1];
-static struct in_addr host_addr;
-static FILE *hostf = NULL;
-static char hostaddr[MAXADDRS];
-static char *host_addrs[2];
-static int stayopen = 0;
-char *strpbrk();
-
-#if PACKETSZ > 1024
-#define MAXPACKET PACKETSZ
-#else
-#define MAXPACKET 1024
-#endif
-
-typedef union {
- HEADER hdr;
- u_char buf[MAXPACKET];
-} querybuf;
-
-typedef union {
- int32_t al;
- char ac;
-} align;
-
-extern int h_errno;
-
-static struct hostent *
-getanswer(answer, anslen, iquery)
- querybuf *answer;
- int anslen;
- int iquery;
-{
- register HEADER *hp;
- register u_char *cp;
- register int n;
- u_char *eom;
- char *bp, **ap;
- int type, class, buflen, ancount, qdcount;
- int haveanswer, getclass = C_ANY;
- char **hap;
-
- eom = answer->buf + anslen;
- /*
- * find first satisfactory answer
- */
- hp = &answer->hdr;
- ancount = ntohs(hp->ancount);
- qdcount = ntohs(hp->qdcount);
- bp = hostbuf;
- buflen = sizeof(hostbuf);
- cp = answer->buf + sizeof(HEADER);
- if (qdcount) {
- if (iquery) {
- if ((n = dn_expand((u_char *)answer->buf,
- (u_char *)eom, (u_char *)cp, (u_char *)bp,
- buflen)) < 0) {
- h_errno = NO_RECOVERY;
- return ((struct hostent *) NULL);
- }
- cp += n + QFIXEDSZ;
- host.h_name = bp;
- n = strlen(bp) + 1;
- bp += n;
- buflen -= n;
- } else
- cp += __dn_skipname(cp, eom) + QFIXEDSZ;
- while (--qdcount > 0)
- cp += __dn_skipname(cp, eom) + QFIXEDSZ;
- } else if (iquery) {
- if (hp->aa)
- h_errno = HOST_NOT_FOUND;
- else
- h_errno = TRY_AGAIN;
- return ((struct hostent *) NULL);
- }
- ap = host_aliases;
- *ap = NULL;
- host.h_aliases = host_aliases;
- hap = h_addr_ptrs;
- *hap = NULL;
-#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
- host.h_addr_list = h_addr_ptrs;
-#endif
- haveanswer = 0;
- while (--ancount >= 0 && cp < eom) {
- if ((n = dn_expand((u_char *)answer->buf, (u_char *)eom,
- (u_char *)cp, (u_char *)bp, buflen)) < 0)
- break;
- cp += n;
- type = _getshort(cp);
- cp += sizeof(u_int16_t);
- class = _getshort(cp);
- cp += sizeof(u_int16_t) + sizeof(u_int32_t);
- n = _getshort(cp);
- cp += sizeof(u_int16_t);
- if (type == T_CNAME) {
- cp += n;
- if (ap >= &host_aliases[MAXALIASES-1])
- continue;
- *ap++ = bp;
- n = strlen(bp) + 1;
- bp += n;
- buflen -= n;
- continue;
+#include <arpa/nameser.h> /* XXX hack for _res */
+#include <resolv.h> /* XXX hack for _res */
+
+#define _PATH_HOSTCONF "/etc/host.conf"
+
+enum service_type {
+ SERVICE_NONE = 0,
+ SERVICE_BIND,
+ SERVICE_HOSTS,
+ SERVICE_NIS };
+#define SERVICE_MAX SERVICE_NIS
+
+static struct {
+ const char *name;
+ enum service_type type;
+} service_names[] = {
+ { "hosts", SERVICE_HOSTS },
+ { "/etc/hosts", SERVICE_HOSTS },
+ { "hosttable", SERVICE_HOSTS },
+ { "htable", SERVICE_HOSTS },
+ { "bind", SERVICE_BIND },
+ { "dns", SERVICE_BIND },
+ { "domain", SERVICE_BIND },
+ { "yp", SERVICE_NIS },
+ { "yellowpages", SERVICE_NIS },
+ { "nis", SERVICE_NIS },
+ { 0, SERVICE_NONE }
+};
+
+static enum service_type service_order[SERVICE_MAX + 1];
+static int service_done = 0;
+
+static enum service_type
+get_service_name(const char *name) {
+ int i;
+ for(i = 0; service_names[i].type != SERVICE_NONE; i++) {
+ if(!strcasecmp(name, service_names[i].name)) {
+ return service_names[i].type;
}
- if (iquery && type == T_PTR) {
- if ((n = dn_expand((u_char *)answer->buf,
- (u_char *)eom, (u_char *)cp, (u_char *)bp,
- buflen)) < 0)
- break;
- cp += n;
- host.h_name = bp;
- return(&host);
- }
- if (iquery || type != T_A) {
-#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf("unexpected answer type %d, size %d\n",
- type, n);
-#endif
- cp += n;
- continue;
- }
- if (haveanswer) {
- if (n != host.h_length) {
- cp += n;
- continue;
- }
- if (class != getclass) {
- cp += n;
- continue;
- }
- } else {
- host.h_length = n;
- getclass = class;
- host.h_addrtype = (class == C_IN) ? AF_INET : AF_UNSPEC;
- if (!iquery) {
- host.h_name = bp;
- bp += strlen(bp) + 1;
- }
- }
-
- bp += sizeof(align) - ((u_int32_t)bp % sizeof(align));
-
- if (bp + n >= &hostbuf[sizeof(hostbuf)]) {
-#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf("size (%d) too big\n", n);
-#endif
- break;
- }
- bcopy(cp, *hap++ = bp, n);
- bp +=n;
- cp += n;
- haveanswer++;
- }
- if (haveanswer) {
- *ap = NULL;
-#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
- *hap = NULL;
-#else
- host.h_addr = h_addr_ptrs[0];
-#endif
- return (&host);
- } else {
- h_errno = TRY_AGAIN;
- return ((struct hostent *) NULL);
}
+ return SERVICE_NONE;
}
-struct hostent *
-gethostbyname(name)
- const char *name;
+static void
+init_services()
{
- querybuf buf;
- register const char *cp;
- int n;
- extern struct hostent *_gethtbyname();
+ char *cp, *p, buf[BUFSIZ];
+ register int cc = 0;
+ FILE *fd;
+
+ if ((fd = (FILE *)fopen(_PATH_HOSTCONF, "r")) == NULL) {
+ /* make some assumptions */
+ service_order[0] = SERVICE_BIND;
+ service_order[1] = SERVICE_HOSTS;
+ service_order[2] = SERVICE_NONE;
+ } else {
+ while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) {
+ if(buf[0] == '#')
+ continue;
- /*
- * disallow names consisting only of digits/dots, unless
- * they end in a dot.
- */
- if (isdigit(name[0]))
- for (cp = name;; ++cp) {
- if (!*cp) {
- if (*--cp == '.')
- break;
- /*
- * All-numeric, no dot at the end.
- * Fake up a hostent as if we'd actually
- * done a lookup.
- */
- if (!inet_aton(name, &host_addr)) {
- h_errno = HOST_NOT_FOUND;
- return((struct hostent *) NULL);
+ p = buf;
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ if (cp == NULL)
+ continue;
+ do {
+ if (isalpha(cp[0])) {
+ service_order[cc] = get_service_name(cp);
+ if(service_order[cc] != SERVICE_NONE)
+ cc++;
}
- host.h_name = (char *)name;
- host.h_aliases = host_aliases;
- host_aliases[0] = NULL;
- host.h_addrtype = AF_INET;
- host.h_length = sizeof(u_int32_t);
- h_addr_ptrs[0] = (char *)&host_addr;
- h_addr_ptrs[1] = (char *)0;
-#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
- host.h_addr_list = h_addr_ptrs;
-#else
- host.h_addr = h_addr_ptrs[0];
-#endif
- return (&host);
- }
- if (!isdigit(*cp) && *cp != '.')
- break;
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ } while(cp != NULL && cc < SERVICE_MAX);
}
-
- if ((n = res_search(name, C_IN, T_A, buf.buf, sizeof(buf))) < 0) {
-#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf("res_search failed\n");
-#endif
- if (errno == ECONNREFUSED)
- return (_gethtbyname(name));
- else
- return ((struct hostent *) NULL);
+ service_order[cc] = SERVICE_NONE;
+ fclose(fd);
}
- return (getanswer(&buf, n, 0));
+ service_done = 1;
}
struct hostent *
-gethostbyaddr(addr, len, type)
- const char *addr;
- int len, type;
+gethostbyname(const char *name)
{
- int n;
- querybuf buf;
- register struct hostent *hp;
- char qbuf[MAXDNAME];
- extern struct hostent *_gethtbyaddr();
-
- if (type != AF_INET)
- return ((struct hostent *) NULL);
- (void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
- ((unsigned)addr[3] & 0xff),
- ((unsigned)addr[2] & 0xff),
- ((unsigned)addr[1] & 0xff),
- ((unsigned)addr[0] & 0xff));
- n = res_query(qbuf, C_IN, T_PTR, (char *)&buf, sizeof(buf));
- if (n < 0) {
-#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf("res_query failed\n");
-#endif
- if (errno == ECONNREFUSED)
- return (_gethtbyaddr(addr, len, type));
- return ((struct hostent *) NULL);
- }
- hp = getanswer(&buf, n, 1);
- if (hp == NULL)
- return ((struct hostent *) NULL);
- hp->h_addrtype = type;
- hp->h_length = len;
- h_addr_ptrs[0] = (char *)&host_addr;
- h_addr_ptrs[1] = (char *)0;
- host_addr = *(struct in_addr *)addr;
-#if BSD < 43 && !defined(h_addr) /* new-style hostent structure */
- hp->h_addr = h_addr_ptrs[0];
-#endif
- return(hp);
+ struct hostent *hp;
+
+ if (_res.options & RES_USE_INET6) { /* XXX */
+ hp = gethostbyname2(name, AF_INET6); /* XXX */
+ if (hp) /* XXX */
+ return (hp); /* XXX */
+ } /* XXX */
+ return (gethostbyname2(name, AF_INET));
}
-void
-_sethtent(f)
- int f;
-{
- if (hostf == NULL)
- hostf = fopen(_PATH_HOSTS, "r" );
- else
- rewind(hostf);
- stayopen |= f;
-}
-
-void
-_endhtent()
+struct hostent *
+gethostbyname2(const char *name, int type)
{
- if (hostf && !stayopen) {
- (void) fclose(hostf);
- hostf = NULL;
+ struct hostent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return NULL;
+ case SERVICE_HOSTS:
+ hp = _gethostbyhtname(name, type);
+ break;
+ case SERVICE_BIND:
+ hp = _gethostbydnsname(name, type);
+ break;
+ case SERVICE_NIS:
+ hp = _gethostbynisname(name, type);
+ break;
+ }
+ nserv++;
}
+ return hp;
}
struct hostent *
-_gethtent()
+gethostbyaddr(const char *addr, int len, int type)
{
- char *p;
- register char *cp, **q;
-
- if (hostf == NULL && (hostf = fopen(_PATH_HOSTS, "r" )) == NULL)
- return (NULL);
-again:
- if ((p = fgets(hostbuf, BUFSIZ, hostf)) == NULL)
- return (NULL);
- if (*p == '#')
- goto again;
- cp = strpbrk(p, "#\n");
- if (cp == NULL)
- goto again;
- *cp = '\0';
- cp = strpbrk(p, " \t");
- if (cp == NULL)
- goto again;
- *cp++ = '\0';
- /* THIS STUFF IS INTERNET SPECIFIC */
-#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
- host.h_addr_list = host_addrs;
-#endif
- host.h_addr = hostaddr;
- *((u_int32_t *)host.h_addr) = inet_addr(p);
- host.h_length = sizeof (u_int32_t);
- host.h_addrtype = AF_INET;
- while (*cp == ' ' || *cp == '\t')
- cp++;
- host.h_name = cp;
- q = host.h_aliases = host_aliases;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
+ struct hostent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return 0;
+ case SERVICE_HOSTS:
+ hp = _gethostbyhtaddr(addr, len, type);
+ break;
+ case SERVICE_BIND:
+ hp = _gethostbydnsaddr(addr, len, type);
+ break;
+ case SERVICE_NIS:
+ hp = _gethostbynisaddr(addr, len, type);
+ break;
}
- if (q < &host_aliases[MAXALIASES - 1])
- *q++ = cp;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
+ nserv++;
}
- *q = NULL;
- return (&host);
+ return hp;
}
-struct hostent *
-_gethtbyname(name)
- char *name;
+#ifdef _THREAD_SAFE
+struct hostent_data;
+
+/*
+ * Temporary function (not thread safe)
+ */
+int gethostbyaddr_r(const char *addr, int len, int type,
+ struct hostent *result, struct hostent_data *buffer)
{
- register struct hostent *p;
- register char **cp;
-
- _sethtent(0);
- while (p = _gethtent()) {
- if (strcasecmp(p->h_name, name) == 0)
- break;
- for (cp = p->h_aliases; *cp != 0; cp++)
- if (strcasecmp(*cp, name) == 0)
- goto found;
+ struct hostent *hp = 0;
+ int ret;
+ if ((hp = gethostbyaddr(addr, len, type)) == NULL) {
+ ret = -1;
+ } else {
+ memcpy(result, hp, sizeof(struct hostent));
+ ret = 0;
}
-found:
- _endhtent();
- return (p);
+ return(ret);
}
+#endif
-struct hostent *
-_gethtbyaddr(addr, len, type)
- const char *addr;
- int len, type;
+void
+sethostent(stayopen)
+ int stayopen;
{
- register struct hostent *p;
+ _sethosthtent(stayopen);
+ _sethostdnsent(stayopen);
+}
- _sethtent(0);
- while (p = _gethtent())
- if (p->h_addrtype == type && !bcmp(p->h_addr, addr, len))
- break;
- _endhtent();
- return (p);
+void
+endhostent()
+{
+ _endhosthtent();
+ _endhostdnsent();
}
diff --git a/lib/libc/net/getnetbydns.c b/lib/libc/net/getnetbydns.c
new file mode 100644
index 0000000..2228a5c
--- /dev/null
+++ b/lib/libc/net/getnetbydns.c
@@ -0,0 +1,310 @@
+/*-
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ * Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id: getnetbydns.c,v 1.10 1997/02/22 15:00:10 peter Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <syslog.h>
+
+#include "res_config.h"
+
+extern int h_errno;
+
+#define BYADDR 0
+#define BYNAME 1
+#define MAXALIASES 35
+
+#if PACKETSZ > 1024
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 1024
+#endif
+
+typedef union {
+ HEADER hdr;
+ u_char buf[MAXPACKET];
+} querybuf;
+
+typedef union {
+ long al;
+ char ac;
+} align;
+
+static struct netent *
+getnetanswer(answer, anslen, net_i)
+ querybuf *answer;
+ int anslen;
+ int net_i;
+{
+
+ register HEADER *hp;
+ register u_char *cp;
+ register int n;
+ u_char *eom;
+ int type, class, buflen, ancount, qdcount, haveanswer, i, nchar;
+ char aux1[30], aux2[30], ans[30], *in, *st, *pauxt, *bp, **ap,
+ *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0;
+static struct netent net_entry;
+static char *net_aliases[MAXALIASES], netbuf[PACKETSZ];
+
+ /*
+ * find first satisfactory answer
+ *
+ * answer --> +------------+ ( MESSAGE )
+ * | Header |
+ * +------------+
+ * | Question | the question for the name server
+ * +------------+
+ * | Answer | RRs answering the question
+ * +------------+
+ * | Authority | RRs pointing toward an authority
+ * | Additional | RRs holding additional information
+ * +------------+
+ */
+ eom = answer->buf + anslen;
+ hp = &answer->hdr;
+ ancount = ntohs(hp->ancount); /* #/records in the answer section */
+ qdcount = ntohs(hp->qdcount); /* #/entries in the question section */
+ bp = netbuf;
+ buflen = sizeof(netbuf);
+ cp = answer->buf + HFIXEDSZ;
+ if (!qdcount) {
+ if (hp->aa)
+ h_errno = HOST_NOT_FOUND;
+ else
+ h_errno = TRY_AGAIN;
+ return (NULL);
+ }
+ while (qdcount-- > 0)
+ cp += __dn_skipname(cp, eom) + QFIXEDSZ;
+ ap = net_aliases;
+ *ap = NULL;
+ net_entry.n_aliases = net_aliases;
+ haveanswer = 0;
+ while (--ancount >= 0 && cp < eom) {
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !res_dnok(bp))
+ break;
+ cp += n;
+ ans[0] = '\0';
+ (void)strcpy(&ans[0], bp);
+ GETSHORT(type, cp);
+ GETSHORT(class, cp);
+ cp += INT32SZ; /* TTL */
+ GETSHORT(n, cp);
+ if (class == C_IN && type == T_PTR) {
+ n = dn_expand(answer->buf, eom, cp, bp, buflen);
+ if ((n < 0) || !res_hnok(bp)) {
+ cp += n;
+ return (NULL);
+ }
+ cp += n;
+ *ap++ = bp;
+ bp += strlen(bp) + 1;
+ net_entry.n_addrtype =
+ (class == C_IN) ? AF_INET : AF_UNSPEC;
+ haveanswer++;
+ }
+ }
+ if (haveanswer) {
+ *ap = NULL;
+ switch (net_i) {
+ case BYADDR:
+ net_entry.n_name = *net_entry.n_aliases;
+ net_entry.n_net = 0L;
+ break;
+ case BYNAME:
+ in = *net_entry.n_aliases;
+ net_entry.n_name = &ans[0];
+ aux2[0] = '\0';
+ for (i = 0; i < 4; i++) {
+ for (st = in, nchar = 0;
+ *st != '.';
+ st++, nchar++)
+ ;
+ if (nchar != 1 || *in != '0' || flag) {
+ flag = 1;
+ (void)strncpy(paux1,
+ (i==0) ? in : in-1,
+ (i==0) ?nchar : nchar+1);
+ paux1[(i==0) ? nchar : nchar+1] = '\0';
+ pauxt = paux2;
+ paux2 = strcat(paux1, paux2);
+ paux1 = pauxt;
+ }
+ in = ++st;
+ }
+ net_entry.n_net = inet_network(paux2);
+ break;
+ }
+ net_entry.n_aliases++;
+ return (&net_entry);
+ }
+ h_errno = TRY_AGAIN;
+ return (NULL);
+}
+
+struct netent *
+_getnetbydnsaddr(net, net_type)
+ register unsigned long net;
+ register int net_type;
+{
+ unsigned int netbr[4];
+ int nn, anslen;
+ querybuf buf;
+ char qbuf[MAXDNAME];
+ unsigned long net2;
+ struct netent *net_entry;
+
+ if (net_type != AF_INET)
+ return (NULL);
+
+ for (nn = 4, net2 = net; net2; net2 >>= 8)
+ netbr[--nn] = net2 & 0xff;
+ switch (nn) {
+ case 3: /* Class A */
+ sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]);
+ break;
+ case 2: /* Class B */
+ sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]);
+ break;
+ case 1: /* Class C */
+ sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
+ netbr[1]);
+ break;
+ case 0: /* Class D - E */
+ sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
+ netbr[1], netbr[0]);
+ break;
+ }
+ anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
+ if (anslen < 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf("res_query failed\n");
+#endif
+ return (NULL);
+ }
+ net_entry = getnetanswer(&buf, anslen, BYADDR);
+ if (net_entry) {
+ unsigned u_net = net; /* maybe net should be unsigned ? */
+
+ /* Strip trailing zeros */
+ while ((u_net & 0xff) == 0 && u_net != 0)
+ u_net >>= 8;
+ net_entry->n_net = u_net;
+ return (net_entry);
+ }
+ return (NULL);
+}
+
+struct netent *
+_getnetbydnsname(net)
+ register const char *net;
+{
+ int anslen;
+ querybuf buf;
+ char qbuf[MAXDNAME];
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ strcpy(&qbuf[0], net);
+ anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
+ if (anslen < 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf("res_query failed\n");
+#endif
+ return (NULL);
+ }
+ return getnetanswer(&buf, anslen, BYNAME);
+}
+
+void
+_setnetdnsent(stayopen)
+ int stayopen;
+{
+ if (stayopen)
+ _res.options |= RES_STAYOPEN | RES_USEVC;
+}
+
+void
+_endnetdnsent()
+{
+ _res.options &= ~(RES_STAYOPEN | RES_USEVC);
+ res_close();
+}
diff --git a/lib/libc/net/getnetbyht.c b/lib/libc/net/getnetbyht.c
new file mode 100644
index 0000000..f7b7b10
--- /dev/null
+++ b/lib/libc/net/getnetbyht.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ */
+
+/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ * Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * from getnetent.c 1.1 (Coimbra) 93/06/02
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid[] = "From: Id: getnetent.c,v 8.4 1997/06/01 20:34:37 vixie Exp";
+static chat rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+
+#define MAXALIASES 35
+
+static FILE *netf;
+static char line[BUFSIZ+1];
+static struct netent net;
+static char *net_aliases[MAXALIASES];
+static int _net_stayopen;
+
+void
+_setnethtent(f)
+ int f;
+{
+
+ if (netf == NULL)
+ netf = fopen(_PATH_NETWORKS, "r" );
+ else
+ rewind(netf);
+ _net_stayopen |= f;
+}
+
+void
+_endnethtent()
+{
+
+ if (netf) {
+ fclose(netf);
+ netf = NULL;
+ }
+ _net_stayopen = 0;
+}
+
+struct netent *
+getnetent()
+{
+ char *p;
+ register char *cp, **q;
+
+ if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
+ return (NULL);
+again:
+ p = fgets(line, sizeof line, netf);
+ if (p == NULL)
+ return (NULL);
+ if (*p == '#')
+ goto again;
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ goto again;
+ *cp = '\0';
+ net.n_name = p;
+ cp = strpbrk(p, " \t");
+ if (cp == NULL)
+ goto again;
+ *cp++ = '\0';
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ p = strpbrk(cp, " \t");
+ if (p != NULL)
+ *p++ = '\0';
+ net.n_net = inet_network(cp);
+ net.n_addrtype = AF_INET;
+ q = net.n_aliases = net_aliases;
+ if (p != NULL)
+ cp = p;
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &net_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&net);
+}
+
+struct netent *
+_getnetbyhtname(name)
+ register const char *name;
+{
+ register struct netent *p;
+ register char **cp;
+
+ setnetent(_net_stayopen);
+ while ( (p = getnetent()) ) {
+ if (strcasecmp(p->n_name, name) == 0)
+ break;
+ for (cp = p->n_aliases; *cp != 0; cp++)
+ if (strcasecmp(*cp, name) == 0)
+ goto found;
+ }
+found:
+ if (!_net_stayopen)
+ endnetent();
+ return (p);
+}
+
+struct netent *
+_getnetbyhtaddr(net, type)
+ register unsigned long net;
+ register int type;
+{
+ register struct netent *p;
+
+ setnetent(_net_stayopen);
+ while ( (p = getnetent()) )
+ if (p->n_addrtype == type && p->n_net == net)
+ break;
+ if (!_net_stayopen)
+ endnetent();
+ return (p);
+}
diff --git a/lib/libc/net/getnetbynis.c b/lib/libc/net/getnetbynis.c
new file mode 100644
index 0000000..0549016
--- /dev/null
+++ b/lib/libc/net/getnetbynis.c
@@ -0,0 +1,177 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE 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[] = "@(#)$Id$";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <arpa/nameser.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+#ifdef YP
+static char *host_aliases[MAXALIASES];
+#endif /* YP */
+
+static struct netent *
+_getnetbynis(name, map, af)
+ const char *name;
+ char *map;
+ int af;
+{
+#ifdef YP
+ register char *cp, **q;
+ static char *result;
+ int resultlen;
+ static struct netent h;
+ static char *domain = (char *)NULL;
+ static char ypbuf[YPMAXRECORD + 2];
+
+ switch(af) {
+ case AF_INET:
+ break;
+ default:
+ case AF_INET6:
+ errno = EAFNOSUPPORT;
+ return NULL;
+ }
+
+ if (domain == (char *)NULL)
+ if (yp_get_default_domain (&domain))
+ return (NULL);
+
+ if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
+ return (NULL);
+
+ bcopy((char *)result, (char *)&ypbuf, resultlen);
+ ypbuf[resultlen] = '\0';
+ free(result);
+ result = (char *)&ypbuf;
+
+ if ((cp = index(result, '\n')))
+ *cp = '\0';
+
+ cp = strpbrk(result, " \t");
+ *cp++ = '\0';
+ h.n_name = result;
+
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+
+ h.n_net = inet_network(cp);
+ h.n_addrtype = AF_INET;
+
+ q = h.n_aliases = host_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &host_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&h);
+#else
+ return (NULL);
+#endif
+}
+
+struct netent *
+_getnetbynisname(name)
+ const char *name;
+{
+ return _getnetbynis(name, "networks.byname", AF_INET);
+}
+
+struct netent *
+_getnetbynisaddr(addr, af)
+ unsigned long addr;
+ int af;
+{
+ char *str, *cp;
+ unsigned long net2;
+ int nn;
+ unsigned int netbr[4];
+ char buf[MAXDNAME];
+
+ if (af != AF_INET) {
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+
+ for (nn = 4, net2 = addr; net2; net2 >>= 8) {
+ netbr[--nn] = net2 & 0xff;
+ }
+
+ switch (nn) {
+ case 3: /* Class A */
+ sprintf(buf, "%u", netbr[3]);
+ break;
+ case 2: /* Class B */
+ sprintf(buf, "%u.%u", netbr[2], netbr[3]);
+ break;
+ case 1: /* Class C */
+ sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]);
+ break;
+ case 0: /* Class D - E */
+ sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1],
+ netbr[2], netbr[3]);
+ break;
+ }
+
+ str = (char *)&buf;
+ cp = str + (strlen(str) - 2);
+
+ while(!strcmp(cp, ".0")) {
+ *cp = '\0';
+ cp = str + (strlen(str) - 2);
+ }
+
+ return _getnetbynis(str, "networks.byaddr", af);
+}
diff --git a/lib/libc/net/getnetent.3 b/lib/libc/net/getnetent.3
index 7514371c..8fb13c0 100644
--- a/lib/libc/net/getnetent.3
+++ b/lib/libc/net/getnetent.3
@@ -44,13 +44,15 @@
.Sh SYNOPSIS
.Fd #include <netdb.h>
.Ft struct netent *
-.Fn getnetent
+.Fn getnetent void
.Ft struct netent *
-.Fn getnetbyname "char *name"
+.Fn getnetbyname "const char *name"
.Ft struct netent *
-.Fn getnetbyaddr "long net" "int type"
+.Fn getnetbyaddr "unsigned long net" "int type"
+.Ft void
.Fn setnetent "int stayopen"
-.Fn endnetent
+.Ft void
+.Fn endnetent void
.Sh DESCRIPTION
The
.Fn getnetent ,
@@ -117,7 +119,10 @@ net name or
net address and type is found,
or until
.Dv EOF
-is encountered.
+is encountered. The
+.Fa type
+must be
+.Dv AF_INET .
Network numbers are supplied in host order.
.Sh FILES
.Bl -tag -width /etc/networks -compact
@@ -130,6 +135,8 @@ Null pointer
or error.
.Sh SEE ALSO
.Xr networks 5
+.Pp
+.%T RFC 1101
.Sh HISTORY
The
.Fn getnetent ,
diff --git a/lib/libc/net/getnetnamadr.c b/lib/libc/net/getnetnamadr.c
new file mode 100644
index 0000000..c964cff
--- /dev/null
+++ b/lib/libc/net/getnetnamadr.c
@@ -0,0 +1,190 @@
+/*-
+ * Copyright (c) 1994, Garrett Wollman
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE 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 rcsid[] = "$Id: getnetnamadr.c,v 1.9 1997/02/22 15:00:12 peter Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+
+#ifndef _PATH_NETCONF
+#define _PATH_NETCONF "/etc/host.conf"
+#endif
+
+enum service_type {
+ SERVICE_NONE = 0,
+ SERVICE_BIND,
+ SERVICE_TABLE,
+ SERVICE_NIS };
+#define SERVICE_MAX SERVICE_NIS
+
+static struct {
+ const char *name;
+ enum service_type type;
+} service_names[] = {
+ { "hosts", SERVICE_TABLE },
+ { "/etc/hosts", SERVICE_TABLE },
+ { "hosttable", SERVICE_TABLE },
+ { "htable", SERVICE_TABLE },
+ { "bind", SERVICE_BIND },
+ { "dns", SERVICE_BIND },
+ { "domain", SERVICE_BIND },
+ { "yp", SERVICE_NIS },
+ { "yellowpages", SERVICE_NIS },
+ { "nis", SERVICE_NIS },
+ { 0, SERVICE_NONE }
+};
+
+static enum service_type service_order[SERVICE_MAX + 1];
+static int service_done = 0;
+
+static enum service_type
+get_service_name(const char *name) {
+ int i;
+ for(i = 0; service_names[i].type != SERVICE_NONE; i++) {
+ if(!strcasecmp(name, service_names[i].name)) {
+ return service_names[i].type;
+ }
+ }
+ return SERVICE_NONE;
+}
+
+static void
+init_services()
+{
+ char *cp, *p, buf[BUFSIZ];
+ register int cc = 0;
+ FILE *fd;
+
+ if ((fd = (FILE *)fopen(_PATH_NETCONF, "r")) == NULL) {
+ /* make some assumptions */
+ service_order[0] = SERVICE_TABLE;
+ service_order[1] = SERVICE_NONE;
+ } else {
+ while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) {
+ if(buf[0] == '#')
+ continue;
+
+ p = buf;
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ if (cp == NULL)
+ continue;
+ do {
+ if (isalpha(cp[0])) {
+ service_order[cc] = get_service_name(cp);
+ if(service_order[cc] != SERVICE_NONE)
+ cc++;
+ }
+ while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
+ ;
+ } while(cp != NULL && cc < SERVICE_MAX);
+ }
+ service_order[cc] = SERVICE_NONE;
+ fclose(fd);
+ }
+ service_done = 1;
+}
+
+struct netent *
+getnetbyname(const char *name)
+{
+ struct netent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return NULL;
+ case SERVICE_TABLE:
+ hp = _getnetbyhtname(name);
+ break;
+ case SERVICE_BIND:
+ hp = _getnetbydnsname(name);
+ break;
+ case SERVICE_NIS:
+ hp = _getnetbynisname(name);
+ break;
+ }
+ nserv++;
+ }
+ return hp;
+}
+
+struct netent *
+getnetbyaddr(addr, af)
+ u_long addr;
+ int af;
+{
+ struct netent *hp = 0;
+ int nserv = 0;
+
+ if (!service_done)
+ init_services();
+
+ while (!hp) {
+ switch (service_order[nserv]) {
+ case SERVICE_NONE:
+ return 0;
+ case SERVICE_TABLE:
+ hp = _getnetbyhtaddr(addr, af);
+ break;
+ case SERVICE_BIND:
+ hp = _getnetbydnsaddr(addr, af);
+ break;
+ case SERVICE_NIS:
+ hp = _getnetbynisaddr(addr, af);
+ break;
+ }
+ nserv++;
+ }
+ return hp;
+}
+
+void
+setnetent(stayopen)
+ int stayopen;
+{
+ _setnethtent(stayopen);
+ _setnetdnsent(stayopen);
+}
+
+void
+endnetent()
+{
+ _endnethtent();
+ _endnetdnsent();
+}
diff --git a/lib/libc/net/getproto.c b/lib/libc/net/getproto.c
index 92f562b..46f46d3 100644
--- a/lib/libc/net/getproto.c
+++ b/lib/libc/net/getproto.c
@@ -46,7 +46,7 @@ getprotobynumber(proto)
register struct protoent *p;
setprotoent(_proto_stayopen);
- while (p = getprotoent())
+ while ( (p = getprotoent()) )
if (p->p_proto == proto)
break;
if (!_proto_stayopen)
diff --git a/lib/libc/net/getprotoent.3 b/lib/libc/net/getprotoent.3
index d5d610e..dbf3d1a 100644
--- a/lib/libc/net/getprotoent.3
+++ b/lib/libc/net/getprotoent.3
@@ -44,13 +44,15 @@
.Sh SYNOPSIS
.Fd #include <netdb.h>
.Ft struct protoent *
-.Fn getprotoent
+.Fn getprotoent void
.Ft struct protoent *
-.Fn getprotobyname "char *name"
+.Fn getprotobyname "const char *name"
.Ft struct protoent *
.Fn getprotobynumber "int proto"
+.Ft void
.Fn setprotoent "int stayopen"
-.Fn endprotoent
+.Ft void
+.Fn endprotoent void
.Sh DESCRIPTION
The
.Fn getprotoent ,
diff --git a/lib/libc/net/getprotoname.c b/lib/libc/net/getprotoname.c
index 3ee6754..0832acf 100644
--- a/lib/libc/net/getprotoname.c
+++ b/lib/libc/net/getprotoname.c
@@ -48,7 +48,7 @@ getprotobyname(name)
register char **cp;
setprotoent(_proto_stayopen);
- while (p = getprotoent()) {
+ while ( (p = getprotoent()) ) {
if (strcmp(p->p_name, name) == 0)
break;
for (cp = p->p_aliases; *cp != 0; cp++)
diff --git a/lib/libc/net/getservbyname.c b/lib/libc/net/getservbyname.c
index 77bf813..124f5ac 100644
--- a/lib/libc/net/getservbyname.c
+++ b/lib/libc/net/getservbyname.c
@@ -47,8 +47,16 @@ getservbyname(name, proto)
register struct servent *p;
register char **cp;
+#ifdef YP
+ extern char *___getservbyname_yp;
+ extern char *___getservbyproto_yp;
+
+ ___getservbyname_yp = (char *)name;
+ ___getservbyproto_yp = (char *)proto;
+#endif
+
setservent(_serv_stayopen);
- while (p = getservent()) {
+ while ( (p = getservent()) ) {
if (strcmp(name, p->s_name) == 0)
goto gotname;
for (cp = p->s_aliases; *cp; cp++)
@@ -61,5 +69,11 @@ gotname:
}
if (!_serv_stayopen)
endservent();
+
+#ifdef YP
+ ___getservbyname_yp = NULL;
+ ___getservbyproto_yp = NULL;
+#endif
+
return (p);
}
diff --git a/lib/libc/net/getservbyport.c b/lib/libc/net/getservbyport.c
index 0acb31b..ef9a2e8 100644
--- a/lib/libc/net/getservbyport.c
+++ b/lib/libc/net/getservbyport.c
@@ -47,8 +47,16 @@ getservbyport(port, proto)
{
register struct servent *p;
+#ifdef YP
+ extern int ___getservbyport_yp;
+ extern char *___getservbyproto_yp;
+
+ ___getservbyport_yp = port;
+ ___getservbyproto_yp = (char *)proto;
+#endif
+
setservent(_serv_stayopen);
- while (p = getservent()) {
+ while ( (p = getservent()) ) {
if (p->s_port != port)
continue;
if (proto == 0 || strcmp(p->s_proto, proto) == 0)
@@ -56,5 +64,11 @@ getservbyport(port, proto)
}
if (!_serv_stayopen)
endservent();
+
+#ifdef YP
+ ___getservbyport_yp = 0;
+ ___getservbyproto_yp = NULL;
+#endif
+
return (p);
}
diff --git a/lib/libc/net/getservent.3 b/lib/libc/net/getservent.3
index f90571e..79c18a3 100644
--- a/lib/libc/net/getservent.3
+++ b/lib/libc/net/getservent.3
@@ -29,9 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getservent.3 8.4 (Berkeley) 5/25/95
+.\" From: @(#)getservent.3 8.3 (Berkeley) 1/12/94
+.\" $Id$
.\"
-.Dd May 25, 1995
+.Dd July 9, 1995
.Dt GETSERVENT 3
.Os BSD 4.2
.Sh NAME
@@ -46,9 +47,9 @@
.Ft struct servent *
.Fn getservent
.Ft struct servent *
-.Fn getservbyname "char *name" "char *proto"
+.Fn getservbyname "const char *name" "const char *proto"
.Ft struct servent *
-.Fn getservbyport "int port" proto
+.Fn getservbyport "int port" "const char *proto"
.Ft void
.Fn setservent "int stayopen"
.Ft void
@@ -79,7 +80,7 @@ The members of this structure are:
.It Fa s_name
The official name of the service.
.It Fa s_aliases
-A NULL-terminated list of alternate names for the service.
+A zero terminated list of alternate names for the service.
.It Fa s_port
The port number at which the service resides.
Port numbers are returned in network byte order.
@@ -121,7 +122,7 @@ port number is found,
or until
.Dv EOF
is encountered.
-If a protocol name is also supplied (non-\c
+If a protocol name is also supplied (non-
.Dv NULL ) ,
searches must also match the protocol.
.ne 1i
diff --git a/lib/libc/net/getservent.c b/lib/libc/net/getservent.c
index 6bee5d3..cd4449f 100644
--- a/lib/libc/net/getservent.c
+++ b/lib/libc/net/getservent.c
@@ -41,6 +41,14 @@ static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93";
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+static int serv_stepping_yp = 0;
+extern int _yp_check __P(( char ** ));
+#endif
+
#define MAXALIASES 35
@@ -50,6 +58,133 @@ static struct servent serv;
static char *serv_aliases[MAXALIASES];
int _serv_stayopen;
+#ifdef YP
+char *___getservbyname_yp = NULL;
+char *___getservbyproto_yp = NULL;
+int ___getservbyport_yp = 0;
+static char *yp_domain = NULL;
+
+static int
+_getservbyport_yp(line)
+ char *line;
+{
+ char *result;
+ int resultlen;
+ char buf[YPMAXRECORD + 2];
+ int rv;
+
+ snprintf(buf, sizeof(buf), "%d/%s", ntohs(___getservbyport_yp),
+ ___getservbyproto_yp);
+
+ ___getservbyport_yp = 0;
+ ___getservbyproto_yp = NULL;
+
+ if(!yp_domain) {
+ if(yp_get_default_domain(&yp_domain))
+ return (0);
+ }
+
+ /*
+ * We have to be a little flexible here. Ideally you're supposed
+ * to have both a services.byname and a services.byport map, but
+ * some systems have only services.byname. FreeBSD cheats a little
+ * by putting the services.byport information in the same map as
+ * services.byname so that either case will work. We allow for both
+ * possibilities here: if there is no services.byport map, we try
+ * services.byname instead.
+ */
+ if ((rv = yp_match(yp_domain, "services.byport", buf, strlen(buf),
+ &result, &resultlen))) {
+ if (rv == YPERR_MAP) {
+ if (yp_match(yp_domain, "services.byname", buf,
+ strlen(buf), &result, &resultlen))
+ return(0);
+ } else
+ return(0);
+ }
+
+ /* getservent() expects lines terminated with \n -- make it happy */
+ snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
+
+ free(result);
+ return(1);
+}
+
+static int
+_getservbyname_yp(line)
+ char *line;
+{
+ char *result;
+ int resultlen;
+ char buf[YPMAXRECORD + 2];
+
+ if(!yp_domain) {
+ if(yp_get_default_domain(&yp_domain))
+ return (0);
+ }
+
+ snprintf(buf, sizeof(buf), "%s/%s", ___getservbyname_yp,
+ ___getservbyproto_yp);
+
+ ___getservbyname_yp = 0;
+ ___getservbyproto_yp = NULL;
+
+ if (yp_match(yp_domain, "services.byname", buf, strlen(buf),
+ &result, &resultlen)) {
+ return(0);
+ }
+
+ /* getservent() expects lines terminated with \n -- make it happy */
+ snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
+
+ free(result);
+ return(1);
+}
+
+static int
+_getservent_yp(line)
+ char *line;
+{
+ static char *key = NULL;
+ static int keylen;
+ char *lastkey, *result;
+ int resultlen;
+ int rv;
+
+ if(!yp_domain) {
+ if(yp_get_default_domain(&yp_domain))
+ return (0);
+ }
+
+ if (!serv_stepping_yp) {
+ if (key)
+ free(key);
+ if ((rv = yp_first(yp_domain, "services.byname", &key, &keylen,
+ &result, &resultlen))) {
+ serv_stepping_yp = 0;
+ return(0);
+ }
+ serv_stepping_yp = 1;
+ } else {
+ lastkey = key;
+ rv = yp_next(yp_domain, "services.byname", key, keylen, &key,
+ &keylen, &result, &resultlen);
+ free(lastkey);
+ if (rv) {
+ serv_stepping_yp = 0;
+ return (0);
+ }
+ }
+
+ /* getservent() expects lines terminated with \n -- make it happy */
+ snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
+
+ free(result);
+
+ return(1);
+}
+#endif
+
void
setservent(f)
int f;
@@ -77,11 +212,33 @@ getservent()
char *p;
register char *cp, **q;
+#ifdef YP
+ if (serv_stepping_yp && _getservent_yp(line)) {
+ p = (char *)&line;
+ goto unpack;
+ }
+tryagain:
+#endif
if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
return (NULL);
again:
if ((p = fgets(line, BUFSIZ, servf)) == NULL)
return (NULL);
+#ifdef YP
+ if (*p == '+' && _yp_check(NULL)) {
+ if (___getservbyname_yp != NULL) {
+ if (!_getservbyname_yp(line))
+ goto tryagain;
+ }
+ else if (___getservbyport_yp != 0) {
+ if (!_getservbyport_yp(line))
+ goto tryagain;
+ }
+ else if (!_getservent_yp(line))
+ goto tryagain;
+ }
+unpack:
+#endif
if (*p == '#')
goto again;
cp = strpbrk(p, "#\n");
diff --git a/lib/libc/net/herror.c b/lib/libc/net/herror.c
index 0366b04..f22f519 100644
--- a/lib/libc/net/herror.c
+++ b/lib/libc/net/herror.c
@@ -31,14 +31,14 @@
* SUCH DAMAGE.
* -
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
+ *
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
@@ -53,7 +53,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93";
-static char rcsid[] = "$Id: herror.c,v 4.9.1.1 1993/05/02 23:14:35 vixie Rel $";
+static char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -62,14 +62,14 @@ static char rcsid[] = "$Id: herror.c,v 4.9.1.1 1993/05/02 23:14:35 vixie Rel $";
#include <unistd.h>
#include <string.h>
-char *h_errlist[] = {
- "Error 0",
+const char *h_errlist[] = {
+ "Resolver Error 0 (no error)",
"Unknown host", /* 1 HOST_NOT_FOUND */
"Host name lookup failure", /* 2 TRY_AGAIN */
"Unknown server error", /* 3 NO_RECOVERY */
"No address associated with name", /* 4 NO_ADDRESS */
};
-int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
+int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
extern int h_errno;
@@ -92,8 +92,7 @@ herror(s)
v->iov_len = 2;
v++;
}
- v->iov_base = (u_int)h_errno < h_nerr ?
- h_errlist[h_errno] : "Unknown error";
+ v->iov_base = (char *)hstrerror(h_errno);
v->iov_len = strlen(v->iov_base);
v++;
v->iov_base = "\n";
@@ -101,9 +100,13 @@ herror(s)
writev(STDERR_FILENO, iov, (v - iov) + 1);
}
-char *
+const char *
hstrerror(err)
int err;
{
- return (u_int)err < h_nerr ? h_errlist[err] : "Unknown resolver error";
+ if (err < 0)
+ return ("Resolver internal error");
+ else if (err < h_nerr)
+ return (h_errlist[err]);
+ return ("Unknown resolver error");
}
diff --git a/lib/libc/net/inet.3 b/lib/libc/net/inet.3
index 9318f45..6ad1bc6 100644
--- a/lib/libc/net/inet.3
+++ b/lib/libc/net/inet.3
@@ -29,9 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)inet.3 8.1 (Berkeley) 6/4/93
+.\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93
+.\" $Id: inet.3,v 1.5 1997/02/22 15:00:15 peter Exp $
.\"
-.Dd June 4, 1993
+.Dd June 17, 1996
.Dt INET 3
.Os BSD 4.2
.Sh NAME
@@ -44,19 +45,20 @@
.Nm inet_netof
.Nd Internet address manipulation routines
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
.Fd #include <sys/socket.h>
.Fd #include <netinet/in.h>
.Fd #include <arpa/inet.h>
.Ft int
-.Fn inet_aton "char *cp" "struct in_addr *pin"
+.Fn inet_aton "const char *cp" "struct in_addr *pin"
.Ft unsigned long
-.Fn inet_addr "char *cp"
+.Fn inet_addr "const char *cp"
.Ft unsigned long
-.Fn inet_network "char *cp"
+.Fn inet_network "const char *cp"
.Ft char *
.Fn inet_ntoa "struct in_addr in"
.Ft struct in_addr
-.Fn inet_makeaddr "int net" "int lna"
+.Fn inet_makeaddr "unsigned long net" "unsigned long lna"
.Ft unsigned long
.Fn inet_lnaof "struct in_addr in"
.Ft unsigned long
@@ -159,6 +161,18 @@ may be decimal, octal, or hexadecimal, as specified
in the C language (i.e., a leading 0x or 0X implies
hexadecimal; otherwise, a leading 0 implies octal;
otherwise, the number is interpreted as decimal).
+.Pp
+The
+.Fn inet_aton
+and
+.Fn inet_ntoa
+functions are semi-deprecated in favor of the
+.Xr addr2ascii 3
+family. However, since those functions are not yet widely implemented,
+portable programs cannot rely on their presence and will continue
+to use the
+.Xr inet 3
+functions for some time.
.Sh DIAGNOSTICS
The constant
.Dv INADDR_NONE
@@ -168,10 +182,11 @@ and
.Fn inet_network
for malformed requests.
.Sh SEE ALSO
+.Xr addr2ascii 3 ,
.Xr gethostbyname 3 ,
.Xr getnetent 3 ,
.Xr hosts 5 ,
-.Xr networks 5 ,
+.Xr networks 5
.Sh HISTORY
These
functions appeared in
diff --git a/lib/libc/net/inet_addr.c b/lib/libc/net/inet_addr.c
index 246a418..a1ac899 100644
--- a/lib/libc/net/inet_addr.c
+++ b/lib/libc/net/inet_addr.c
@@ -1,7 +1,9 @@
/*
+ * ++Copyright++ 1983, 1990, 1993
+ * -
* Copyright (c) 1983, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
+ * The Regents of the University of California. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -12,12 +14,12 @@
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
* 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
@@ -29,10 +31,31 @@
* 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
+static char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -73,50 +96,52 @@ inet_aton(cp, addr)
u_int parts[4];
register u_int *pp = parts;
+ c = *cp;
for (;;) {
/*
* Collect number up to ``.''.
* Values are specified as for C:
- * 0x=hex, 0=octal, other=decimal.
+ * 0x=hex, 0=octal, isdigit=decimal.
*/
+ if (!isdigit(c))
+ return (0);
val = 0; base = 10;
- if (*cp == '0') {
- if (*++cp == 'x' || *cp == 'X')
- base = 16, cp++;
+ if (c == '0') {
+ c = *++cp;
+ if (c == 'x' || c == 'X')
+ base = 16, c = *++cp;
else
base = 8;
}
- while ((c = *cp) != '\0') {
+ for (;;) {
if (isascii(c) && isdigit(c)) {
val = (val * base) + (c - '0');
- cp++;
- continue;
- }
- if (base == 16 && isascii(c) && isxdigit(c)) {
- val = (val << 4) +
+ c = *++cp;
+ } else if (base == 16 && isascii(c) && isxdigit(c)) {
+ val = (val << 4) |
(c + 10 - (islower(c) ? 'a' : 'A'));
- cp++;
- continue;
- }
- break;
+ c = *++cp;
+ } else
+ break;
}
- if (*cp == '.') {
+ if (c == '.') {
/*
* Internet format:
* a.b.c.d
- * a.b.c (with c treated as 16-bits)
+ * a.b.c (with c treated as 16 bits)
* a.b (with b treated as 24 bits)
*/
- if (pp >= parts + 3 || val > 0xff)
+ if (pp >= parts + 3)
return (0);
- *pp++ = val, cp++;
+ *pp++ = val;
+ c = *++cp;
} else
break;
}
/*
* Check for trailing characters.
*/
- if (*cp && (!isascii(*cp) || !isspace(*cp)))
+ if (c != '\0' && (!isascii(c) || !isspace(c)))
return (0);
/*
* Concoct the address according to
@@ -125,6 +150,9 @@ inet_aton(cp, addr)
n = pp - parts + 1;
switch (n) {
+ case 0:
+ return (0); /* initial nondigit */
+
case 1: /* a -- 32 bits */
break;
diff --git a/lib/libc/net/inet_net_ntop.c b/lib/libc/net/inet_net_ntop.c
new file mode 100644
index 0000000..4c7893d
--- /dev/null
+++ b/lib/libc/net/inet_net_ntop.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char orig_rcsid[] = "From Id: inet_net_ntop.c,v 8.2 1996/08/08 06:54:44 vixie Exp";
+static const char rcsid[] = "$Id$";
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+static char * inet_net_ntop_ipv4 __P((const u_char *src, int bits,
+ char *dst, size_t size));
+
+/*
+ * char *
+ * inet_net_ntop(af, src, bits, dst, size)
+ * convert network number from network to presentation format.
+ * generates CIDR style result always.
+ * return:
+ * pointer to dst, or NULL if an error occurred (check errno).
+ * author:
+ * Paul Vixie (ISC), July 1996
+ */
+char *
+inet_net_ntop(af, src, bits, dst, size)
+ int af;
+ const void *src;
+ int bits;
+ char *dst;
+ size_t size;
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_net_ntop_ipv4(src, bits, dst, size));
+ default:
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+}
+
+/*
+ * static char *
+ * inet_net_ntop_ipv4(src, bits, dst, size)
+ * convert IPv4 network number from network to presentation format.
+ * generates CIDR style result always.
+ * return:
+ * pointer to dst, or NULL if an error occurred (check errno).
+ * note:
+ * network byte order assumed. this means 192.5.5.240/28 has
+ * 0x11110000 in its fourth octet.
+ * author:
+ * Paul Vixie (ISC), July 1996
+ */
+static char *
+inet_net_ntop_ipv4(src, bits, dst, size)
+ const u_char *src;
+ int bits;
+ char *dst;
+ size_t size;
+{
+ char *odst = dst;
+ char *t;
+ u_int m;
+ int b;
+
+ if (bits < 0 || bits > 32) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ if (bits == 0) {
+ if (size < sizeof "0")
+ goto emsgsize;
+ *dst++ = '0';
+ *dst = '\0';
+ }
+
+ /* Format whole octets. */
+ for (b = bits / 8; b > 0; b--) {
+ if (size < sizeof "255.")
+ goto emsgsize;
+ t = dst;
+ dst += SPRINTF((dst, "%u", *src++));
+ if (b > 1) {
+ *dst++ = '.';
+ *dst = '\0';
+ }
+ size -= (size_t)(dst - t);
+ }
+
+ /* Format partial octet. */
+ b = bits % 8;
+ if (b > 0) {
+ if (size < sizeof ".255")
+ goto emsgsize;
+ t = dst;
+ if (dst != odst)
+ *dst++ = '.';
+ m = ((1 << b) - 1) << (8 - b);
+ dst += SPRINTF((dst, "%u", *src & m));
+ size -= (size_t)(dst - t);
+ }
+
+ /* Format CIDR /width. */
+ if (size < sizeof "/32")
+ goto emsgsize;
+ dst += SPRINTF((dst, "/%u", bits));
+ return (odst);
+
+ emsgsize:
+ errno = EMSGSIZE;
+ return (NULL);
+}
diff --git a/lib/libc/net/inet_net_pton.c b/lib/libc/net/inet_net_pton.c
new file mode 100644
index 0000000..6fd6a06
--- /dev/null
+++ b/lib/libc/net/inet_net_pton.c
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char orig_rcsid[] = "From Id: inet_net_pton.c,v 8.3 1996/11/11 06:36:52 vixie Exp";
+static const char rcsid[] = "$Id$";
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+static int inet_net_pton_ipv4 __P((const char *src, u_char *dst,
+ size_t size));
+
+/*
+ * static int
+ * inet_net_pton(af, src, dst, size)
+ * convert network number from presentation to network format.
+ * accepts hex octets, hex strings, decimal octets, and /CIDR.
+ * "size" is in bytes and describes "dst".
+ * return:
+ * number of bits, either imputed classfully or specified with /CIDR,
+ * or -1 if some failure occurred (check errno). ENOENT means it was
+ * not a valid network specification.
+ * author:
+ * Paul Vixie (ISC), June 1996
+ */
+int
+inet_net_pton(af, src, dst, size)
+ int af;
+ const char *src;
+ void *dst;
+ size_t size;
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_net_pton_ipv4(src, dst, size));
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+}
+
+/*
+ * static int
+ * inet_net_pton_ipv4(src, dst, size)
+ * convert IPv4 network number from presentation to network format.
+ * accepts hex octets, hex strings, decimal octets, and /CIDR.
+ * "size" is in bytes and describes "dst".
+ * return:
+ * number of bits, either imputed classfully or specified with /CIDR,
+ * or -1 if some failure occurred (check errno). ENOENT means it was
+ * not an IPv4 network specification.
+ * note:
+ * network byte order assumed. this means 192.5.5.240/28 has
+ * 0x11110000 in its fourth octet.
+ * author:
+ * Paul Vixie (ISC), June 1996
+ */
+static int
+inet_net_pton_ipv4(src, dst, size)
+ const char *src;
+ u_char *dst;
+ size_t size;
+{
+ static const char
+ xdigits[] = "0123456789abcdef",
+ digits[] = "0123456789";
+ int n, ch, tmp, dirty, bits;
+ const u_char *odst = dst;
+
+ ch = *src++;
+ if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
+ && isascii(src[1]) && isxdigit(src[1])) {
+ /* Hexadecimal: Eat nybble string. */
+ if (size <= 0)
+ goto emsgsize;
+ *dst = 0, dirty = 0;
+ src++; /* skip x or X. */
+ while ((ch = *src++) != '\0' &&
+ isascii(ch) && isxdigit(ch)) {
+ if (isupper(ch))
+ ch = tolower(ch);
+ n = strchr(xdigits, ch) - xdigits;
+ assert(n >= 0 && n <= 15);
+ *dst |= n;
+ if (!dirty++)
+ *dst <<= 4;
+ else if (size-- > 0)
+ *++dst = 0, dirty = 0;
+ else
+ goto emsgsize;
+ }
+ if (dirty)
+ size--;
+ } else if (isascii(ch) && isdigit(ch)) {
+ /* Decimal: eat dotted digit string. */
+ for (;;) {
+ tmp = 0;
+ do {
+ n = strchr(digits, ch) - digits;
+ assert(n >= 0 && n <= 9);
+ tmp *= 10;
+ tmp += n;
+ if (tmp > 255)
+ goto enoent;
+ } while ((ch = *src++) != '\0' &&
+ isascii(ch) && isdigit(ch));
+ if (size-- <= 0)
+ goto emsgsize;
+ *dst++ = (u_char) tmp;
+ if (ch == '\0' || ch == '/')
+ break;
+ if (ch != '.')
+ goto enoent;
+ ch = *src++;
+ if (!isascii(ch) || !isdigit(ch))
+ goto enoent;
+ }
+ } else
+ goto enoent;
+
+ bits = -1;
+ if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) {
+ /* CIDR width specifier. Nothing can follow it. */
+ ch = *src++; /* Skip over the /. */
+ bits = 0;
+ do {
+ n = strchr(digits, ch) - digits;
+ assert(n >= 0 && n <= 9);
+ bits *= 10;
+ bits += n;
+ } while ((ch = *src++) != '\0' &&
+ isascii(ch) && isdigit(ch));
+ if (ch != '\0')
+ goto enoent;
+ if (bits > 32)
+ goto emsgsize;
+ }
+
+ /* Firey death and destruction unless we prefetched EOS. */
+ if (ch != '\0')
+ goto enoent;
+
+ /* If nothing was written to the destination, we found no address. */
+ if (dst == odst)
+ goto enoent;
+ /* If no CIDR spec was given, infer width from net class. */
+ if (bits == -1) {
+ if (*odst >= 240) /* Class E */
+ bits = 32;
+ else if (*odst >= 224) /* Class D */
+ bits = 4;
+ else if (*odst >= 192) /* Class C */
+ bits = 24;
+ else if (*odst >= 128) /* Class B */
+ bits = 16;
+ else /* Class A */
+ bits = 8;
+ /* If imputed mask is narrower than specified octets, widen. */
+ if (bits >= 8 && bits < ((dst - odst) * 8))
+ bits = (dst - odst) * 8;
+ }
+ /* Extend network to cover the actual mask. */
+ while (bits > ((dst - odst) * 8)) {
+ if (size-- <= 0)
+ goto emsgsize;
+ *dst++ = '\0';
+ }
+ return (bits);
+
+ enoent:
+ errno = ENOENT;
+ return (-1);
+
+ emsgsize:
+ errno = EMSGSIZE;
+ return (-1);
+}
diff --git a/lib/libc/net/inet_neta.c b/lib/libc/net/inet_neta.c
new file mode 100644
index 0000000..15a1c70
--- /dev/null
+++ b/lib/libc/net/inet_neta.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char orig_rcsid[] = "From Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp";
+static const char rcsid[] = "$Id$";
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdio.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+/*
+ * char *
+ * inet_neta(src, dst, size)
+ * format a u_long network number into presentation format.
+ * return:
+ * pointer to dst, or NULL if an error occurred (check errno).
+ * note:
+ * format of ``src'' is as for inet_network().
+ * author:
+ * Paul Vixie (ISC), July 1996
+ */
+char *
+inet_neta(src, dst, size)
+ u_long src;
+ char *dst;
+ size_t size;
+{
+ char *odst = dst;
+ char *tp;
+
+ while (src & 0xffffffff) {
+ u_char b = (src & 0xff000000) >> 24;
+
+ src <<= 8;
+ if (b) {
+ if (size < sizeof "255.")
+ goto emsgsize;
+ tp = dst;
+ dst += SPRINTF((dst, "%u", b));
+ if (src != 0L) {
+ *dst++ = '.';
+ *dst = '\0';
+ }
+ size -= (size_t)(dst - tp);
+ }
+ }
+ if (dst == odst) {
+ if (size < sizeof "0.0.0.0")
+ goto emsgsize;
+ strcpy(dst, "0.0.0.0");
+ }
+ return (odst);
+
+ emsgsize:
+ errno = EMSGSIZE;
+ return (NULL);
+}
diff --git a/lib/libc/net/inet_network.c b/lib/libc/net/inet_network.c
index fda53b6..6da2e8b 100644
--- a/lib/libc/net/inet_network.c
+++ b/lib/libc/net/inet_network.c
@@ -60,7 +60,7 @@ again:
base = 8, cp++;
if (*cp == 'x' || *cp == 'X')
base = 16, cp++;
- while (c = *cp) {
+ while ( (c = *cp) ) {
if (isdigit(c)) {
val = (val * base) + (c - '0');
cp++;
@@ -74,7 +74,7 @@ again:
break;
}
if (*cp == '.') {
- if (pp >= parts + 4)
+ if (pp >= parts + 3)
return (INADDR_NONE);
*pp++ = val, cp++;
goto again;
@@ -83,8 +83,6 @@ again:
return (INADDR_NONE);
*pp++ = val;
n = pp - parts;
- if (n > 4)
- return (INADDR_NONE);
for (val = 0, i = 0; i < n; i++) {
val <<= 8;
val |= parts[i] & 0xff;
diff --git a/lib/libc/net/inet_ntop.c b/lib/libc/net/inet_ntop.c
new file mode 100644
index 0000000..36dcb32
--- /dev/null
+++ b/lib/libc/net/inet_ntop.c
@@ -0,0 +1,190 @@
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+#define SPRINTF(x) ((size_t)sprintf x)
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size));
+static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size));
+
+/* char *
+ * inet_ntop(af, src, dst, size)
+ * convert a network format address to presentation format.
+ * return:
+ * pointer to presentation format address (`dst'), or NULL (see errno).
+ * author:
+ * Paul Vixie, 1996.
+ */
+const char *
+inet_ntop(af, src, dst, size)
+ int af;
+ const void *src;
+ char *dst;
+ size_t size;
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_ntop4(src, dst, size));
+ case AF_INET6:
+ return (inet_ntop6(src, dst, size));
+ default:
+ errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+ /* NOTREACHED */
+}
+
+/* const char *
+ * inet_ntop4(src, dst, size)
+ * format an IPv4 address, more or less like inet_ntoa()
+ * return:
+ * `dst' (as a const)
+ * notes:
+ * (1) uses no statics
+ * (2) takes a u_char* not an in_addr as input
+ * author:
+ * Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop4(src, dst, size)
+ const u_char *src;
+ char *dst;
+ size_t size;
+{
+ static const char fmt[] = "%u.%u.%u.%u";
+ char tmp[sizeof "255.255.255.255"];
+
+ if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) {
+ errno = ENOSPC;
+ return (NULL);
+ }
+ strcpy(dst, tmp);
+ return (dst);
+}
+
+/* const char *
+ * inet_ntop6(src, dst, size)
+ * convert IPv6 binary address into presentation (printable) format
+ * author:
+ * Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop6(src, dst, size)
+ const u_char *src;
+ char *dst;
+ size_t size;
+{
+ /*
+ * Note that int32_t and int16_t need only be "at least" large enough
+ * to contain a value of the specified size. On some systems, like
+ * Crays, there is no such thing as an integer variable with 16 bits.
+ * Keep this in mind if you think this function should have been coded
+ * to use pointer overlays. All the world's not a VAX.
+ */
+ char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
+ struct { int base, len; } best, cur;
+ u_int words[IN6ADDRSZ / INT16SZ];
+ int i;
+
+ /*
+ * Preprocess:
+ * Copy the input (bytewise) array into a wordwise array.
+ * Find the longest run of 0x00's in src[] for :: shorthanding.
+ */
+ memset(words, '\0', sizeof words);
+ for (i = 0; i < IN6ADDRSZ; i++)
+ words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
+ best.base = -1;
+ cur.base = -1;
+ for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
+ if (words[i] == 0) {
+ if (cur.base == -1)
+ cur.base = i, cur.len = 1;
+ else
+ cur.len++;
+ } else {
+ if (cur.base != -1) {
+ if (best.base == -1 || cur.len > best.len)
+ best = cur;
+ cur.base = -1;
+ }
+ }
+ }
+ if (cur.base != -1) {
+ if (best.base == -1 || cur.len > best.len)
+ best = cur;
+ }
+ if (best.base != -1 && best.len < 2)
+ best.base = -1;
+
+ /*
+ * Format the result.
+ */
+ tp = tmp;
+ for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
+ /* Are we inside the best run of 0x00's? */
+ if (best.base != -1 && i >= best.base &&
+ i < (best.base + best.len)) {
+ if (i == best.base)
+ *tp++ = ':';
+ continue;
+ }
+ /* Are we following an initial run of 0x00s or any real hex? */
+ if (i != 0)
+ *tp++ = ':';
+ /* Is this address an encapsulated IPv4? */
+ if (i == 6 && best.base == 0 &&
+ (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
+ if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
+ return (NULL);
+ tp += strlen(tp);
+ break;
+ }
+ tp += SPRINTF((tp, "%x", words[i]));
+ }
+ /* Was it a trailing run of 0x00's? */
+ if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
+ *tp++ = ':';
+ *tp++ = '\0';
+
+ /*
+ * Check for overflow, copy, and we're done.
+ */
+ if ((size_t)(tp - tmp) > size) {
+ errno = ENOSPC;
+ return (NULL);
+ }
+ strcpy(dst, tmp);
+ return (dst);
+}
diff --git a/lib/libc/net/inet_pton.c b/lib/libc/net/inet_pton.c
new file mode 100644
index 0000000..054ff7d
--- /dev/null
+++ b/lib/libc/net/inet_pton.c
@@ -0,0 +1,214 @@
+/* Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <string.h>
+#include <errno.h>
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static int inet_pton4 __P((const char *src, u_char *dst));
+static int inet_pton6 __P((const char *src, u_char *dst));
+
+/* int
+ * inet_pton(af, src, dst)
+ * convert from presentation format (which usually means ASCII printable)
+ * to network format (which is usually some kind of binary format).
+ * return:
+ * 1 if the address was valid for the specified address family
+ * 0 if the address wasn't valid (`dst' is untouched in this case)
+ * -1 if some other error occurred (`dst' is untouched in this case, too)
+ * author:
+ * Paul Vixie, 1996.
+ */
+int
+inet_pton(af, src, dst)
+ int af;
+ const char *src;
+ void *dst;
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_pton4(src, dst));
+ case AF_INET6:
+ return (inet_pton6(src, dst));
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+ /* NOTREACHED */
+}
+
+/* int
+ * inet_pton4(src, dst)
+ * like inet_aton() but without all the hexadecimal and shorthand.
+ * return:
+ * 1 if `src' is a valid dotted quad, else 0.
+ * notice:
+ * does not touch `dst' unless it's returning 1.
+ * author:
+ * Paul Vixie, 1996.
+ */
+static int
+inet_pton4(src, dst)
+ const char *src;
+ u_char *dst;
+{
+ static const char digits[] = "0123456789";
+ int saw_digit, octets, ch;
+ u_char tmp[INADDRSZ], *tp;
+
+ saw_digit = 0;
+ octets = 0;
+ *(tp = tmp) = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr(digits, ch)) != NULL) {
+ u_int new = *tp * 10 + (pch - digits);
+
+ if (new > 255)
+ return (0);
+ *tp = new;
+ if (! saw_digit) {
+ if (++octets > 4)
+ return (0);
+ saw_digit = 1;
+ }
+ } else if (ch == '.' && saw_digit) {
+ if (octets == 4)
+ return (0);
+ *++tp = 0;
+ saw_digit = 0;
+ } else
+ return (0);
+ }
+ if (octets < 4)
+ return (0);
+
+ memcpy(dst, tmp, INADDRSZ);
+ return (1);
+}
+
+/* int
+ * inet_pton6(src, dst)
+ * convert presentation level address to network order binary form.
+ * return:
+ * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
+ * notice:
+ * (1) does not touch `dst' unless it's returning 1.
+ * (2) :: in a full address is silently ignored.
+ * credit:
+ * inspired by Mark Andrews.
+ * author:
+ * Paul Vixie, 1996.
+ */
+static int
+inet_pton6(src, dst)
+ const char *src;
+ u_char *dst;
+{
+ static const char xdigits_l[] = "0123456789abcdef",
+ xdigits_u[] = "0123456789ABCDEF";
+ u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
+ const char *xdigits, *curtok;
+ int ch, saw_xdigit;
+ u_int val;
+
+ memset((tp = tmp), '\0', IN6ADDRSZ);
+ endp = tp + IN6ADDRSZ;
+ colonp = NULL;
+ /* Leading :: requires some special handling. */
+ if (*src == ':')
+ if (*++src != ':')
+ return (0);
+ curtok = src;
+ saw_xdigit = 0;
+ val = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+ pch = strchr((xdigits = xdigits_u), ch);
+ if (pch != NULL) {
+ val <<= 4;
+ val |= (pch - xdigits);
+ if (val > 0xffff)
+ return (0);
+ saw_xdigit = 1;
+ continue;
+ }
+ if (ch == ':') {
+ curtok = src;
+ if (!saw_xdigit) {
+ if (colonp)
+ return (0);
+ colonp = tp;
+ continue;
+ }
+ if (tp + INT16SZ > endp)
+ return (0);
+ *tp++ = (u_char) (val >> 8) & 0xff;
+ *tp++ = (u_char) val & 0xff;
+ saw_xdigit = 0;
+ val = 0;
+ continue;
+ }
+ if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
+ inet_pton4(curtok, tp) > 0) {
+ tp += INADDRSZ;
+ saw_xdigit = 0;
+ break; /* '\0' was seen by inet_pton4(). */
+ }
+ return (0);
+ }
+ if (saw_xdigit) {
+ if (tp + INT16SZ > endp)
+ return (0);
+ *tp++ = (u_char) (val >> 8) & 0xff;
+ *tp++ = (u_char) val & 0xff;
+ }
+ if (colonp != NULL) {
+ /*
+ * Since some memmove()'s erroneously fail to handle
+ * overlapping regions, we'll do the shift by hand.
+ */
+ const int n = tp - colonp;
+ int i;
+
+ for (i = 1; i <= n; i++) {
+ endp[- i] = colonp[n - i];
+ colonp[n - i] = 0;
+ }
+ tp = endp;
+ }
+ if (tp != endp)
+ return (0);
+ memcpy(dst, tmp, IN6ADDRSZ);
+ return (1);
+}
diff --git a/lib/libc/net/iso_addr.c b/lib/libc/net/iso_addr.c
index 9ca92f3..8829497 100644
--- a/lib/libc/net/iso_addr.c
+++ b/lib/libc/net/iso_addr.c
@@ -65,7 +65,7 @@ iso_addr(addr)
new = *addr - 'a' + 10;
} else if ((*addr >= 'A') && (*addr <= 'F')) {
new = *addr - 'A' + 10;
- } else if (*addr == 0)
+ } else if (*addr == 0)
state |= END;
else
state |= DELIM;
@@ -86,34 +86,32 @@ iso_addr(addr)
break;
}
break;
- } while (cp < cplim);
+ } while (cp < cplim);
out_addr.isoa_len = cp - out_addr.isoa_genaddr;
return (&out_addr);
}
+
static char hexlist[] = "0123456789abcdef";
char *
iso_ntoa(isoa)
const struct iso_addr *isoa;
{
- static char obuf[64];
- register char *out = obuf;
- register int i;
- register u_char *in = (u_char *)isoa->isoa_genaddr;
- u_char *inlim = in + isoa->isoa_len;
+ static char tmpbuf[sizeof(isoa->isoa_genaddr)*3];
+ const u_char *binary;
+ char *cp;
+ int i;
+
+ binary = isoa->isoa_genaddr;
+ cp = tmpbuf;
+
+ for (i = 0; i < isoa->isoa_len; i++) {
+ *cp++ = hexlist[*binary >> 4];
+ *cp++ = hexlist[*binary++ & 0xf];
- out[1] = 0;
- while (in < inlim) {
- i = *in++;
- *out++ = '.';
- if (i > 0xf) {
- out[1] = hexlist[i & 0xf];
- i >>= 4;
- out[0] = hexlist[i];
- out += 2;
- } else
- *out++ = hexlist[i];
+ if ((((i % 2) == 0) && ((i + 1) < isoa->isoa_len)))
+ *cp++ = '.';
}
- *out = 0;
- return(obuf + 1);
+ *cp = '\0';
+ return tmpbuf;
}
diff --git a/lib/libc/net/linkaddr.3 b/lib/libc/net/linkaddr.3
index 54e3206..6999add 100644
--- a/lib/libc/net/linkaddr.3
+++ b/lib/libc/net/linkaddr.3
@@ -32,9 +32,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)linkaddr.3 8.1 (Berkeley) 7/28/93
+.\" From: @(#)linkaddr.3 8.1 (Berkeley) 7/28/93
+.\" $Id$
.\"
-.Dd July 28, 1993
+.Dd June 17, 1996
.Dt LINK_ADDR 3
.Os BSD 4.4
.Sh NAME
@@ -75,7 +76,7 @@ may contain
an optional network interface identifier of the form
.Dq "name unit-number" ,
suitable for the first argument to
-.Xr ifconfig 4 ,
+.Xr ifconfig 8 ,
followed in all cases by a colon and
an interface address in the form of
groups of hexadecimal digits
@@ -93,6 +94,11 @@ Thus
.Li le0:8.0.9.13.d.30
represents an ethernet address
to be transmitted on the first Lance ethernet interface.
+.Pp
+The direct use of these functions is deprecated in favor of the
+.Xr addr2ascii 3
+interface; however, portable programs cannot rely on the latter as it is
+not yet widely implemented.
.Sh RETURN VALUES
.Fn link_ntoa
always returns a null terminated string.
@@ -101,7 +107,8 @@ has no return value.
(See
.Sx BUGS . )
.Sh SEE ALSO
-.Xr iso 4 ,
+.Xr addr2ascii 3
+.\" .Xr iso 4
.Sh HISTORY
The
.Fn link_addr
diff --git a/lib/libc/net/linkaddr.c b/lib/libc/net/linkaddr.c
index 50ab392..68eed3d 100644
--- a/lib/libc/net/linkaddr.c
+++ b/lib/libc/net/linkaddr.c
@@ -112,7 +112,7 @@ link_addr(addr, sdl)
break;
}
break;
- } while (cp < cplim);
+ } while (cp < cplim);
sdl->sdl_alen = cp - LLADDR(sdl);
new = cp - (char *)sdl;
if (new > sizeof(*sdl))
@@ -127,7 +127,7 @@ link_ntoa(sdl)
register const struct sockaddr_dl *sdl;
{
static char obuf[64];
- register char *out = obuf;
+ register char *out = obuf;
register int i;
register u_char *in = (u_char *)LLADDR(sdl);
u_char *inlim = in + sdl->sdl_alen;
diff --git a/lib/libc/net/map_v4v6.c b/lib/libc/net/map_v4v6.c
new file mode 100644
index 0000000..0f8658e
--- /dev/null
+++ b/lib/libc/net/map_v4v6.c
@@ -0,0 +1,128 @@
+/*
+ * ++Copyright++ 1985, 1988, 1993
+ * -
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#include <syslog.h>
+
+typedef union {
+ int32_t al;
+ char ac;
+} align;
+
+void
+_map_v4v6_address(src, dst)
+ const char *src;
+ char *dst;
+{
+ u_char *p = (u_char *)dst;
+ char tmp[INADDRSZ];
+ int i;
+
+ /* Stash a temporary copy so our caller can update in place. */
+ bcopy(src, tmp, INADDRSZ);
+ /* Mark this ipv6 addr as a mapped ipv4. */
+ for (i = 0; i < 10; i++)
+ *p++ = 0x00;
+ *p++ = 0xff;
+ *p++ = 0xff;
+ /* Retrieve the saved copy and we're done. */
+ bcopy(tmp, (void*)p, INADDRSZ);
+}
+
+void
+_map_v4v6_hostent(hp, bpp, lenp)
+ struct hostent *hp;
+ char **bpp;
+ int *lenp;
+{
+ char **ap;
+
+ if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)
+ return;
+ hp->h_addrtype = AF_INET6;
+ hp->h_length = IN6ADDRSZ;
+ for (ap = hp->h_addr_list; *ap; ap++) {
+ int i = sizeof(align) - ((u_long)*bpp % sizeof(align));
+
+ if (*lenp < (i + IN6ADDRSZ)) {
+ /* Out of memory. Truncate address list here. XXX */
+ *ap = NULL;
+ return;
+ }
+ *bpp += i;
+ *lenp -= i;
+ _map_v4v6_address(*ap, *bpp);
+ *ap = *bpp;
+ *bpp += IN6ADDRSZ;
+ *lenp -= IN6ADDRSZ;
+ }
+}
diff --git a/lib/libc/net/ns.3 b/lib/libc/net/ns.3
index 8646826..e621ad2 100644
--- a/lib/libc/net/ns.3
+++ b/lib/libc/net/ns.3
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)ns.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt NS 3
@@ -112,7 +113,7 @@ None. (See
.Sx BUGS . )
.Sh SEE ALSO
.Xr hosts 5 ,
-.Xr networks 5 ,
+.Xr networks 5
.Sh HISTORY
The
.Fn ns_addr
diff --git a/lib/libc/net/ns_addr.c b/lib/libc/net/ns_addr.c
index 9b0b9d1..3446e08 100644
--- a/lib/libc/net/ns_addr.c
+++ b/lib/libc/net/ns_addr.c
@@ -47,7 +47,7 @@ static struct ns_addr addr, zero_addr;
static void Field(), cvtbase();
-struct ns_addr
+struct ns_addr
ns_addr(name)
const char *name;
{
@@ -64,7 +64,7 @@ ns_addr(name)
* form 2-272.AA001234H.01777, i.e. XDE standard.
* Great efforts are made to insure backward compatability.
*/
- if (hostname = strchr(buf, '#'))
+ if ((hostname = strchr(buf, '#')) != NULL)
separator = '#';
else {
hostname = strchr(buf, '.');
@@ -157,7 +157,7 @@ Field(buf, out, len)
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
base16 = 1;
break;
-
+
case 'x': case 'X':
*--bp = '0';
base16 = 1;
diff --git a/lib/libc/net/nsap_addr.c b/lib/libc/net/nsap_addr.c
new file mode 100644
index 0000000..b0c6433
--- /dev/null
+++ b/lib/libc/net/nsap_addr.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <ctype.h>
+#include <resolv.h>
+
+static char
+xtob(c)
+ register int c;
+{
+ return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
+}
+
+u_int
+inet_nsap_addr(ascii, binary, maxlen)
+ const char *ascii;
+ u_char *binary;
+ int maxlen;
+{
+ register u_char c, nib;
+ u_int len = 0;
+
+ while ((c = *ascii++) != '\0' && len < maxlen) {
+ if (c == '.' || c == '+' || c == '/')
+ continue;
+ if (!isascii(c))
+ return (0);
+ if (islower(c))
+ c = toupper(c);
+ if (isxdigit(c)) {
+ nib = xtob(c);
+ if ((c = *ascii++) != '\0') {
+ c = toupper(c);
+ if (isxdigit(c)) {
+ *binary++ = (nib << 4) | xtob(c);
+ len++;
+ } else
+ return (0);
+ }
+ else
+ return (0);
+ }
+ else
+ return (0);
+ }
+ return (len);
+}
+
+char *
+inet_nsap_ntoa(binlen, binary, ascii)
+ int binlen;
+ register const u_char *binary;
+ register char *ascii;
+{
+ register int nib;
+ int i;
+ static char tmpbuf[255*3];
+ char *start;
+
+ if (ascii)
+ start = ascii;
+ else {
+ ascii = tmpbuf;
+ start = tmpbuf;
+ }
+
+ if (binlen > 255)
+ binlen = 255;
+
+ for (i = 0; i < binlen; i++) {
+ nib = *binary >> 4;
+ *ascii++ = nib + (nib < 10 ? '0' : '7');
+ nib = *binary++ & 0x0f;
+ *ascii++ = nib + (nib < 10 ? '0' : '7');
+ if (((i % 2) == 0 && (i + 1) < binlen))
+ *ascii++ = '.';
+ }
+ *ascii = '\0';
+ return (start);
+}
diff --git a/lib/libc/net/rcmd.3 b/lib/libc/net/rcmd.3
index 014ef98..e25057f 100644
--- a/lib/libc/net/rcmd.3
+++ b/lib/libc/net/rcmd.3
@@ -29,14 +29,16 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)rcmd.3 8.1 (Berkeley) 6/4/93
+.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
-.Dd June 4, 1993
+.Dd February 15, 1996
.Dt RCMD 3
.Os BSD 4.2
.Sh NAME
.Nm rcmd ,
.Nm rresvport ,
+.Nm iruserok ,
.Nm ruserok
.Nd routines for returning a stream to a remote command
.Sh SYNOPSIS
@@ -150,7 +152,7 @@ in the local user's home directory is checked to see if the request for
service is allowed.
.Pp
If this file does not exist, is not a regular file, is owned by anyone
-other than the user or the super-user, or is writeable by anyone other
+other than the user or the super-user, or is writable by anyone other
than the owner, the check automatically fails.
Zero is returned if the machine name is listed in the
.Dq Pa hosts.equiv
@@ -162,7 +164,7 @@ and
.Fn ruserok
return \-1.
If the local domain (as obtained from
-.Xr gethostname 2 )
+.Xr gethostname 3 )
is the same as the remote domain, only the machine name need be specified.
.Pp
The
diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c
index 279b9bd..ff108d9 100644
--- a/lib/libc/net/rcmd.c
+++ b/lib/libc/net/rcmd.c
@@ -51,6 +51,15 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94";
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+extern int innetgr __P(( const char *, const char *, const char *, const char * ));
+
+#define max(a, b) ((a > b) ? a : b)
int __ivaliduser __P((FILE *, u_long, const char *, const char *));
static int __icheckhost __P((u_long, char *));
@@ -91,9 +100,11 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
return (-1);
}
fcntl(s, F_SETOWN, pid);
+ bzero(&sin, sizeof sin);
+ sin.sin_len = sizeof(struct sockaddr_in);
sin.sin_family = hp->h_addrtype;
- bcopy(hp->h_addr_list[0], &sin.sin_addr, hp->h_length);
sin.sin_port = rport;
+ bcopy(hp->h_addr_list[0], &sin.sin_addr, MIN(hp->h_length, sizeof sin.sin_addr));
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)
break;
(void)close(s);
@@ -114,7 +125,7 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
errno = oerrno;
perror(0);
hp->h_addr_list++;
- bcopy(hp->h_addr_list[0], &sin.sin_addr, hp->h_length);
+ bcopy(hp->h_addr_list[0], &sin.sin_addr, MIN(hp->h_length, sizeof sin.sin_addr));
(void)fprintf(stderr, "Trying %s...\n",
inet_ntoa(sin.sin_addr));
continue;
@@ -131,6 +142,7 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
char num[8];
int s2 = rresvport(&lport), s3;
int len = sizeof(from);
+ int nfds;
if (s2 < 0)
goto bad;
@@ -143,11 +155,18 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
(void)close(s2);
goto bad;
}
+ nfds = max(s, s2)+1;
+ if(nfds > FD_SETSIZE) {
+ fprintf(stderr, "rcmd: too many files\n");
+ (void)close(s2);
+ goto bad;
+ }
+again:
FD_ZERO(&reads);
FD_SET(s, &reads);
FD_SET(s2, &reads);
errno = 0;
- if (select(32, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)) {
+ if (select(nfds, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)){
if (errno != 0)
(void)fprintf(stderr,
"rcmd: select (setting up stderr): %s\n",
@@ -159,6 +178,14 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
goto bad;
}
s3 = accept(s2, (struct sockaddr *)&from, &len);
+ /*
+ * XXX careful for ftp bounce attacks. If discovered, shut them
+ * down and check for the real auxiliary channel to connect.
+ */
+ if (from.sin_family == AF_INET && from.sin_port == htons(20)) {
+ close(s3);
+ goto again;
+ }
(void)close(s2);
if (s3 < 0) {
(void)fprintf(stderr,
@@ -210,26 +237,29 @@ rresvport(alport)
struct sockaddr_in sin;
int s;
+ bzero(&sin, sizeof sin);
+ sin.sin_len = sizeof(struct sockaddr_in);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
return (-1);
- for (;;) {
- sin.sin_port = htons((u_short)*alport);
- if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)
- return (s);
- if (errno != EADDRINUSE) {
- (void)close(s);
- return (-1);
- }
- (*alport)--;
- if (*alport == IPPORT_RESERVED/2) {
- (void)close(s);
- errno = EAGAIN; /* close */
- return (-1);
- }
+#if 0 /* compat_exact_traditional_rresvport_semantics */
+ sin.sin_port = htons((u_short)*alport);
+ if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)
+ return (s);
+ if (errno != EADDRINUSE) {
+ (void)close(s);
+ return (-1);
+ }
+#endif
+ sin.sin_port = 0;
+ if (bindresvport(s, &sin) == -1) {
+ (void)close(s);
+ return (-1);
}
+ *alport = (int)ntohs(sin.sin_port);
+ return (s);
}
int __check_rhosts_file = 1;
@@ -347,6 +377,24 @@ __ivaliduser(hostf, raddr, luser, ruser)
register char *user, *p;
int ch;
char buf[MAXHOSTNAMELEN + 128]; /* host + login */
+ char hname[MAXHOSTNAMELEN];
+ struct hostent *hp;
+ /* Presumed guilty until proven innocent. */
+ int userok = 0, hostok = 0;
+#ifdef YP
+ char *ypdomain;
+
+ if (yp_get_default_domain(&ypdomain))
+ ypdomain = NULL;
+#else
+#define ypdomain NULL
+#endif
+ /* We need to get the damn hostname back for netgroup matching. */
+ if ((hp = gethostbyaddr((char *)&raddr, sizeof(u_long),
+ AF_INET)) == NULL)
+ return (-1);
+ strncpy(hname, hp->h_name, sizeof(hname));
+ hname[sizeof(hname) - 1] = '\0';
while (fgets(buf, sizeof(buf), hostf)) {
p = buf;
@@ -355,6 +403,10 @@ __ivaliduser(hostf, raddr, luser, ruser)
while ((ch = getc(hostf)) != '\n' && ch != EOF);
continue;
}
+ if (*p == '\n' || *p == '#') {
+ /* comment... */
+ continue;
+ }
while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') {
*p = isupper(*p) ? tolower(*p) : *p;
p++;
@@ -370,10 +422,68 @@ __ivaliduser(hostf, raddr, luser, ruser)
} else
user = p;
*p = '\0';
- if (__icheckhost(raddr, buf) &&
- strcmp(ruser, *user ? user : luser) == 0) {
- return (0);
+ /*
+ * Do +/- and +@/-@ checking. This looks really nasty,
+ * but it matches SunOS's behavior so far as I can tell.
+ */
+ switch(buf[0]) {
+ case '+':
+ if (!buf[1]) { /* '+' matches all hosts */
+ hostok = 1;
+ break;
+ }
+ if (buf[1] == '@') /* match a host by netgroup */
+ hostok = innetgr((char *)&buf[2],
+ (char *)&hname, NULL, ypdomain);
+ else /* match a host by addr */
+ hostok = __icheckhost(raddr,(char *)&buf[1]);
+ break;
+ case '-': /* reject '-' hosts and all their users */
+ if (buf[1] == '@') {
+ if (innetgr((char *)&buf[2],
+ (char *)&hname, NULL, ypdomain))
+ return(-1);
+ } else {
+ if (__icheckhost(raddr,(char *)&buf[1]))
+ return(-1);
+ }
+ break;
+ default: /* if no '+' or '-', do a simple match */
+ hostok = __icheckhost(raddr, buf);
+ break;
+ }
+ switch(*user) {
+ case '+':
+ if (!*(user+1)) { /* '+' matches all users */
+ userok = 1;
+ break;
+ }
+ if (*(user+1) == '@') /* match a user by netgroup */
+ userok = innetgr(user+2, NULL, ruser, ypdomain);
+ else /* match a user by direct specification */
+ userok = !(strcmp(ruser, user+1));
+ break;
+ case '-': /* if we matched a hostname, */
+ if (hostok) { /* check for user field rejections */
+ if (!*(user+1))
+ return(-1);
+ if (*(user+1) == '@') {
+ if (innetgr(user+2, NULL,
+ ruser, ypdomain))
+ return(-1);
+ } else {
+ if (!strcmp(ruser, user+1))
+ return(-1);
+ }
+ }
+ break;
+ default: /* no rejections: try to match the user */
+ if (hostok)
+ userok = !(strcmp(ruser,*user ? user : luser));
+ break;
}
+ if (hostok && userok)
+ return(0);
}
return (-1);
}
diff --git a/lib/libc/net/res_comp.c b/lib/libc/net/res_comp.c
new file mode 100644
index 0000000..86fd4ae
--- /dev/null
+++ b/lib/libc/net/res_comp.c
@@ -0,0 +1,496 @@
+/*
+ * ++Copyright++ 1985, 1993
+ * -
+ * Copyright (c) 1985, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid[] = "From: Id: res_comp.c,v 8.12 1997/06/01 20:34:37 vixie Exp";
+static char rcsid[] = "$Id: res_comp.c,v 1.11 1997/06/13 19:21:54 ache Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <resolv.h>
+#include <ctype.h>
+
+#include <unistd.h>
+#include <string.h>
+
+static int dn_find __P((u_char *exp_dn, u_char *msg,
+ u_char **dnptrs, u_char **lastdnptr));
+
+/*
+ * Expand compressed domain name 'comp_dn' to full domain name.
+ * 'msg' is a pointer to the begining of the message,
+ * 'eomorig' points to the first location after the message,
+ * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
+ * Return size of compressed name or -1 if there was an error.
+ */
+int
+dn_expand(msg, eomorig, comp_dn, exp_dn, length)
+ const u_char *msg, *eomorig, *comp_dn;
+ char *exp_dn;
+ int length;
+{
+ register const u_char *cp;
+ register char *dn;
+ register int n, c;
+ char *eom;
+ int len = -1, checked = 0, octets = 0;
+
+ dn = exp_dn;
+ cp = comp_dn;
+ eom = exp_dn + length;
+ /*
+ * fetch next label in domain name
+ */
+ while ( (n = *cp++) ) {
+ /*
+ * Check for indirection
+ */
+ switch (n & INDIR_MASK) {
+ case 0:
+ octets += (n + 1);
+ if (octets > MAXCDNAME)
+ return (-1);
+ if (dn != exp_dn) {
+ if (dn >= eom)
+ return (-1);
+ *dn++ = '.';
+ }
+ if (dn+n >= eom)
+ return (-1);
+ checked += n + 1;
+ while (--n >= 0) {
+ if (((c = *cp++) == '.') || (c == '\\')) {
+ if (dn + n + 2 >= eom)
+ return (-1);
+ *dn++ = '\\';
+ }
+ *dn++ = c;
+ if (cp >= eomorig) /* out of range */
+ return (-1);
+ }
+ break;
+
+ case INDIR_MASK:
+ if (len < 0)
+ len = cp - comp_dn + 1;
+ cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff));
+ if (cp < msg || cp >= eomorig) /* out of range */
+ 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 >= eomorig - msg)
+ return (-1);
+ break;
+
+ default:
+ return (-1); /* flag error */
+ }
+ }
+ *dn = '\0';
+ if (len < 0)
+ len = cp - comp_dn;
+ return (len);
+}
+
+/*
+ * Compress domain name 'exp_dn' into 'comp_dn'.
+ * Return the size of the compressed name or -1.
+ * 'length' is the size of the array pointed to by 'comp_dn'.
+ * 'dnptrs' is a list of pointers to previous compressed names. dnptrs[0]
+ * is a pointer to the beginning of the message. The list ends with NULL.
+ * 'lastdnptr' is a pointer to the end of the arrary pointed to
+ * by 'dnptrs'. Side effect is to update the list of pointers for
+ * labels inserted into the message as we compress the name.
+ * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
+ * is NULL, we don't update the list.
+ */
+int
+dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
+ const char *exp_dn;
+ u_char *comp_dn, **dnptrs, **lastdnptr;
+ int length;
+{
+ register u_char *cp, *dn;
+ register int c, l;
+ u_char **cpp, **lpp, *sp, *eob;
+ u_char *msg;
+
+ dn = (u_char *)exp_dn;
+ cp = comp_dn;
+ if (length > MAXCDNAME)
+ length = MAXCDNAME;
+ eob = cp + length;
+ lpp = cpp = NULL;
+ if (dnptrs != NULL) {
+ if ((msg = *dnptrs++) != NULL) {
+ for (cpp = dnptrs; *cpp != NULL; cpp++)
+ ;
+ lpp = cpp; /* end of list to search */
+ }
+ } else
+ msg = NULL;
+ for (c = *dn++; c != '\0'; ) {
+ /* look to see if we can use pointers */
+ if (msg != NULL) {
+ if ((l = dn_find(dn-1, msg, dnptrs, lpp)) >= 0) {
+ if (cp+1 >= eob)
+ return (-1);
+ *cp++ = (l >> 8) | INDIR_MASK;
+ *cp++ = l % 256;
+ return (cp - comp_dn);
+ }
+ /* not found, save it */
+ if (lastdnptr != NULL && cpp < lastdnptr-1) {
+ *cpp++ = cp;
+ *cpp = NULL;
+ }
+ }
+ sp = cp++; /* save ptr to length byte */
+ do {
+ if (c == '.') {
+ c = *dn++;
+ break;
+ }
+ if (c == '\\') {
+ if ((c = *dn++) == '\0')
+ break;
+ }
+ if (cp >= eob) {
+ if (msg != NULL)
+ *lpp = NULL;
+ return (-1);
+ }
+ *cp++ = c;
+ } while ((c = *dn++) != '\0');
+ /* catch trailing '.'s but not '..' */
+ if ((l = cp - sp - 1) == 0 && c == '\0') {
+ cp--;
+ break;
+ }
+ if (l <= 0 || l > MAXLABEL) {
+ if (msg != NULL)
+ *lpp = NULL;
+ return (-1);
+ }
+ *sp = l;
+ }
+ if (cp >= eob) {
+ if (msg != NULL)
+ *lpp = NULL;
+ return (-1);
+ }
+ *cp++ = '\0';
+ return (cp - comp_dn);
+}
+
+/*
+ * Skip over a compressed domain name. Return the size or -1.
+ */
+int
+__dn_skipname(comp_dn, eom)
+ const u_char *comp_dn, *eom;
+{
+ register const u_char *cp;
+ register int n;
+
+ cp = comp_dn;
+ while (cp < eom && (n = *cp++)) {
+ /*
+ * check for indirection
+ */
+ switch (n & INDIR_MASK) {
+ case 0: /* normal case, n == len */
+ cp += n;
+ continue;
+ case INDIR_MASK: /* indirection */
+ cp++;
+ break;
+ default: /* illegal type */
+ return (-1);
+ }
+ break;
+ }
+ if (cp > eom)
+ return (-1);
+ return (cp - comp_dn);
+}
+
+static int
+mklower(ch)
+ register int ch;
+{
+ if (isascii(ch) && isupper(ch))
+ return (tolower(ch));
+ return (ch);
+}
+
+/*
+ * Search for expanded name from a list of previously compressed names.
+ * Return the offset from msg if found or -1.
+ * dnptrs is the pointer to the first name on the list,
+ * not the pointer to the start of the message.
+ */
+static int
+dn_find(exp_dn, msg, dnptrs, lastdnptr)
+ u_char *exp_dn, *msg;
+ u_char **dnptrs, **lastdnptr;
+{
+ register u_char *dn, *cp, **cpp;
+ register int n;
+ u_char *sp;
+
+ for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
+ dn = exp_dn;
+ sp = cp = *cpp;
+ while ( (n = *cp++) ) {
+ /*
+ * check for indirection
+ */
+ switch (n & INDIR_MASK) {
+ case 0: /* normal case, n == len */
+ while (--n >= 0) {
+ if (*dn == '.')
+ goto next;
+ if (*dn == '\\')
+ dn++;
+ if (mklower(*dn++) != mklower(*cp++))
+ goto next;
+ }
+ if ((n = *dn++) == '\0' && *cp == '\0')
+ return (sp - msg);
+ if (n == '.')
+ continue;
+ goto next;
+
+ case INDIR_MASK: /* indirection */
+ cp = msg + (((n & 0x3f) << 8) | *cp);
+ break;
+
+ default: /* illegal type */
+ return (-1);
+ }
+ }
+ if (*dn == '\0')
+ return (sp - msg);
+ next: ;
+ }
+ return (-1);
+}
+
+/*
+ * Verify that a domain name uses an acceptable character set.
+ */
+
+/*
+ * Note the conspicuous absence of ctype macros in these definitions. On
+ * non-ASCII hosts, we can't depend on string literals or ctype macros to
+ * tell us anything about network-format data. The rest of the BIND system
+ * is not careful about this, but for some reason, we're doing it right here.
+ */
+#define PERIOD 0x2e
+#define hyphenchar(c) ((c) == 0x2d)
+#define bslashchar(c) ((c) == 0x5c)
+#define periodchar(c) ((c) == PERIOD)
+#define asterchar(c) ((c) == 0x2a)
+#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
+ || ((c) >= 0x61 && (c) <= 0x7a))
+#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
+
+#define borderchar(c) (alphachar(c) || digitchar(c))
+#define middlechar(c) (borderchar(c) || hyphenchar(c))
+#define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
+
+int
+res_hnok(dn)
+ const char *dn;
+{
+ int ppch = '\0', pch = PERIOD, ch = *dn++;
+
+ while (ch != '\0') {
+ int nch = *dn++;
+
+ if (periodchar(ch)) {
+ NULL;
+ } else if (periodchar(pch)) {
+ if (!borderchar(ch))
+ return (0);
+ } else if (periodchar(nch) || nch == '\0') {
+ if (!borderchar(ch))
+ return (0);
+ } else {
+ if (!middlechar(ch))
+ return (0);
+ }
+ ppch = pch, pch = ch, ch = nch;
+ }
+ return (1);
+}
+
+/*
+ * hostname-like (A, MX, WKS) owners can have "*" as their first label
+ * but must otherwise be as a host name.
+ */
+int
+res_ownok(dn)
+ const char *dn;
+{
+ if (asterchar(dn[0])) {
+ if (periodchar(dn[1]))
+ return (res_hnok(dn+2));
+ if (dn[1] == '\0')
+ return (1);
+ }
+ return (res_hnok(dn));
+}
+
+/*
+ * SOA RNAMEs and RP RNAMEs can have any printable character in their first
+ * label, but the rest of the name has to look like a host name.
+ */
+int
+res_mailok(dn)
+ const char *dn;
+{
+ int ch, escaped = 0;
+
+ /* "." is a valid missing representation */
+ if (*dn == '\0')
+ return(1);
+
+ /* otherwise <label>.<hostname> */
+ while ((ch = *dn++) != '\0') {
+ if (!domainchar(ch))
+ return (0);
+ if (!escaped && periodchar(ch))
+ break;
+ if (escaped)
+ escaped = 0;
+ else if (bslashchar(ch))
+ escaped = 1;
+ }
+ if (periodchar(ch))
+ return (res_hnok(dn));
+ return(0);
+}
+
+/*
+ * This function is quite liberal, since RFC 1034's character sets are only
+ * recommendations.
+ */
+int
+res_dnok(dn)
+ const char *dn;
+{
+ int ch;
+
+ while ((ch = *dn++) != '\0')
+ if (!domainchar(ch))
+ return (0);
+ return (1);
+}
+
+/*
+ * Routines to insert/extract short/long's.
+ */
+
+u_int16_t
+_getshort(msgp)
+ register const u_char *msgp;
+{
+ register u_int16_t u;
+
+ GETSHORT(u, msgp);
+ return (u);
+}
+
+u_int32_t
+_getlong(msgp)
+ register const u_char *msgp;
+{
+ register u_int32_t u;
+
+ GETLONG(u, msgp);
+ return (u);
+}
+
+void
+#if defined(__STDC__) || defined(__cplusplus)
+__putshort(register u_int16_t s, register u_char *msgp) /* must match proto */
+#else
+__putshort(s, msgp)
+ register u_int16_t s;
+ register u_char *msgp;
+#endif
+{
+ PUTSHORT(s, msgp);
+}
+
+void
+__putlong(l, msgp)
+ register u_int32_t l;
+ register u_char *msgp;
+{
+ PUTLONG(l, msgp);
+}
diff --git a/lib/libc/net/res_config.h b/lib/libc/net/res_config.h
new file mode 100644
index 0000000..f29246a
--- /dev/null
+++ b/lib/libc/net/res_config.h
@@ -0,0 +1,8 @@
+#define DEBUG 1 /* enable debugging code (needed for dig) */
+#undef ALLOW_T_UNSPEC /* enable the "unspec" RR type for old athena */
+#define RESOLVSORT /* allow sorting of addresses in gethostbyname */
+#define RFC1535 /* comply with RFC1535 (STRONGLY reccomended by vixie)*/
+#undef USELOOPBACK /* res_init() bind to localhost */
+#undef SUNSECURITY /* verify gethostbyaddr() calls - WE DONT NEED IT */
+#define MULTI_PTRS_ARE_ALIASES 1 /* fold multiple PTR records into aliases */
+#define CHECK_SRVR_ADDR 1 /* confirm that the server requested sent the reply */
diff --git a/lib/libc/net/res_data.c b/lib/libc/net/res_data.c
new file mode 100644
index 0000000..df0e0dd
--- /dev/null
+++ b/lib/libc/net/res_data.c
@@ -0,0 +1,111 @@
+/*
+ * ++Copyright++ 1995
+ * -
+ * Copyright (c) 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <ctype.h>
+#include <resolv.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+const char *_res_opcodes[] = {
+ "QUERY",
+ "IQUERY",
+ "CQUERYM",
+ "CQUERYU", /* experimental */
+ "NOTIFY", /* experimental */
+ "5",
+ "6",
+ "7",
+ "8",
+ "UPDATEA",
+ "UPDATED",
+ "UPDATEDA",
+ "UPDATEM",
+ "UPDATEMA",
+ "ZONEINIT",
+ "ZONEREF",
+};
+
+const char *_res_resultcodes[] = {
+ "NOERROR",
+ "FORMERR",
+ "SERVFAIL",
+ "NXDOMAIN",
+ "NOTIMP",
+ "REFUSED",
+ "6",
+ "7",
+ "8",
+ "9",
+ "10",
+ "11",
+ "12",
+ "13",
+ "14",
+ "NOCHANGE",
+};
diff --git a/lib/libc/net/res_debug.c b/lib/libc/net/res_debug.c
new file mode 100644
index 0000000..06b8b42
--- /dev/null
+++ b/lib/libc/net/res_debug.c
@@ -0,0 +1,1520 @@
+/*
+ * ++Copyright++ 1985, 1990, 1993
+ * -
+ * Copyright (c) 1985, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software. No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid[] = "From: Id: res_debug.c,v 8.20 1997/06/01 20:34:37 vixie Exp";
+static char rcsid[] = "$Id: res_debug.c,v 1.13 1997/02/22 15:00:31 peter Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include "res_config.h"
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <time.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+extern const char *_res_opcodes[];
+extern const char *_res_resultcodes[];
+
+/* XXX: we should use getservbyport() instead. */
+static const char *
+dewks(wks)
+ int wks;
+{
+ static char nbuf[20];
+
+ switch (wks) {
+ case 5: return "rje";
+ case 7: return "echo";
+ case 9: return "discard";
+ case 11: return "systat";
+ case 13: return "daytime";
+ case 15: return "netstat";
+ case 17: return "qotd";
+ case 19: return "chargen";
+ case 20: return "ftp-data";
+ case 21: return "ftp";
+ case 23: return "telnet";
+ case 25: return "smtp";
+ case 37: return "time";
+ case 39: return "rlp";
+ case 42: return "name";
+ case 43: return "whois";
+ case 53: return "domain";
+ case 57: return "apts";
+ case 59: return "apfs";
+ case 67: return "bootps";
+ case 68: return "bootpc";
+ case 69: return "tftp";
+ case 77: return "rje";
+ case 79: return "finger";
+ case 87: return "link";
+ case 95: return "supdup";
+ case 100: return "newacct";
+ case 101: return "hostnames";
+ case 102: return "iso-tsap";
+ case 103: return "x400";
+ case 104: return "x400-snd";
+ case 105: return "csnet-ns";
+ case 109: return "pop-2";
+ case 111: return "sunrpc";
+ case 113: return "auth";
+ case 115: return "sftp";
+ case 117: return "uucp-path";
+ case 119: return "nntp";
+ case 121: return "erpc";
+ case 123: return "ntp";
+ case 133: return "statsrv";
+ case 136: return "profile";
+ case 144: return "NeWS";
+ case 161: return "snmp";
+ case 162: return "snmp-trap";
+ case 170: return "print-srv";
+ default: (void) sprintf(nbuf, "%d", wks); return (nbuf);
+ }
+}
+
+/* XXX: we should use getprotobynumber() instead. */
+static const char *
+deproto(protonum)
+ int protonum;
+{
+ static char nbuf[20];
+
+ switch (protonum) {
+ case 1: return "icmp";
+ case 2: return "igmp";
+ case 3: return "ggp";
+ case 5: return "st";
+ case 6: return "tcp";
+ case 7: return "ucl";
+ case 8: return "egp";
+ case 9: return "igp";
+ case 11: return "nvp-II";
+ case 12: return "pup";
+ case 16: return "chaos";
+ case 17: return "udp";
+ default: (void) sprintf(nbuf, "%d", protonum); return (nbuf);
+ }
+}
+
+static const u_char *
+do_rrset(msg, len, cp, cnt, pflag, file, hs)
+ int cnt, pflag, len;
+ const u_char *cp, *msg;
+ const char *hs;
+ FILE *file;
+{
+ int n;
+ int sflag;
+
+ /*
+ * Print answer records.
+ */
+ sflag = (_res.pfcode & pflag);
+ if ((n = ntohs(cnt)) != 0) {
+ if ((!_res.pfcode) ||
+ ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
+ fprintf(file, hs);
+ while (--n >= 0) {
+ if ((!_res.pfcode) || sflag) {
+ cp = p_rr(cp, msg, file);
+ } else {
+ unsigned int dlen;
+ cp += __dn_skipname(cp, cp + MAXCDNAME);
+ cp += INT16SZ;
+ cp += INT16SZ;
+ cp += INT32SZ;
+ dlen = _getshort((u_char*)cp);
+ cp += INT16SZ;
+ cp += dlen;
+ }
+ if ((cp - msg) > len)
+ return (NULL);
+ }
+ if ((!_res.pfcode) ||
+ ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
+ putc('\n', file);
+ }
+ return (cp);
+}
+
+void
+__p_query(msg)
+ const u_char *msg;
+{
+ __fp_query(msg, stdout);
+}
+
+/*
+ * Print the current options.
+ * This is intended to be primarily a debugging routine.
+ */
+void
+__fp_resstat(statp, file)
+ struct __res_state *statp;
+ FILE *file;
+{
+ register u_long mask;
+
+ fprintf(file, ";; res options:");
+ if (!statp)
+ statp = &_res;
+ for (mask = 1; mask != 0; mask <<= 1)
+ if (statp->options & mask)
+ fprintf(file, " %s", p_option(mask));
+ putc('\n', file);
+}
+
+/*
+ * Print the contents of a query.
+ * This is intended to be primarily a debugging routine.
+ */
+void
+__fp_nquery(msg, len, file)
+ const u_char *msg;
+ int len;
+ FILE *file;
+{
+ register const u_char *cp, *endMark;
+ register const HEADER *hp;
+ register int n;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+ return;
+
+#define TruncTest(x) if (x > endMark) goto trunc
+#define ErrorTest(x) if (x == NULL) goto error
+
+ /*
+ * Print header fields.
+ */
+ hp = (HEADER *)msg;
+ cp = msg + HFIXEDSZ;
+ endMark = msg + len;
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) {
+ fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d",
+ _res_opcodes[hp->opcode],
+ _res_resultcodes[hp->rcode],
+ ntohs(hp->id));
+ putc('\n', file);
+ }
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
+ putc(';', file);
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
+ fprintf(file, "; flags:");
+ if (hp->qr)
+ fprintf(file, " qr");
+ if (hp->aa)
+ fprintf(file, " aa");
+ if (hp->tc)
+ fprintf(file, " tc");
+ if (hp->rd)
+ fprintf(file, " rd");
+ if (hp->ra)
+ fprintf(file, " ra");
+ if (hp->unused)
+ fprintf(file, " UNUSED-BIT-ON");
+ if (hp->ad)
+ fprintf(file, " ad");
+ if (hp->cd)
+ fprintf(file, " cd");
+ }
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
+ fprintf(file, "; Ques: %d", ntohs(hp->qdcount));
+ fprintf(file, ", Ans: %d", ntohs(hp->ancount));
+ fprintf(file, ", Auth: %d", ntohs(hp->nscount));
+ fprintf(file, ", Addit: %d", ntohs(hp->arcount));
+ }
+ if ((!_res.pfcode) || (_res.pfcode &
+ (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
+ putc('\n',file);
+ }
+ /*
+ * Print question records.
+ */
+ if ((n = ntohs(hp->qdcount)) != 0) {
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+ fprintf(file, ";; QUESTIONS:\n");
+ while (--n >= 0) {
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+ fprintf(file, ";;\t");
+ TruncTest(cp);
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+ cp = p_cdnname(cp, msg, len, file);
+ else {
+ int n;
+ char name[MAXDNAME];
+
+ if ((n = dn_expand(msg, msg+len, cp, name,
+ sizeof name)) < 0)
+ cp = NULL;
+ else
+ cp += n;
+ }
+ ErrorTest(cp);
+ TruncTest(cp);
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+ fprintf(file, ", type = %s",
+ __p_type(_getshort((u_char*)cp)));
+ cp += INT16SZ;
+ TruncTest(cp);
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+ fprintf(file, ", class = %s\n",
+ __p_class(_getshort((u_char*)cp)));
+ cp += INT16SZ;
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
+ putc('\n', file);
+ }
+ }
+ /*
+ * Print authoritative answer records
+ */
+ TruncTest(cp);
+ cp = do_rrset(msg, len, cp, hp->ancount, RES_PRF_ANS, file,
+ ";; ANSWERS:\n");
+ ErrorTest(cp);
+
+ /*
+ * print name server records
+ */
+ TruncTest(cp);
+ cp = do_rrset(msg, len, cp, hp->nscount, RES_PRF_AUTH, file,
+ ";; AUTHORITY RECORDS:\n");
+ ErrorTest(cp);
+
+ TruncTest(cp);
+ /*
+ * print additional records
+ */
+ cp = do_rrset(msg, len, cp, hp->arcount, RES_PRF_ADD, file,
+ ";; ADDITIONAL RECORDS:\n");
+ ErrorTest(cp);
+ return;
+ trunc:
+ fprintf(file, "\n;; ...truncated\n");
+ return;
+ error:
+ fprintf(file, "\n;; ...malformed\n");
+}
+
+void
+__fp_query(msg, file)
+ const u_char *msg;
+ FILE *file;
+{
+ fp_nquery(msg, PACKETSZ, file);
+}
+
+const u_char *
+__p_cdnname(cp, msg, len, file)
+ const u_char *cp, *msg;
+ int len;
+ FILE *file;
+{
+ char name[MAXDNAME];
+ int n;
+
+ if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
+ return (NULL);
+ if (name[0] == '\0')
+ putc('.', file);
+ else
+ fputs(name, file);
+ return (cp + n);
+}
+
+const u_char *
+__p_cdname(cp, msg, file)
+ const u_char *cp, *msg;
+ FILE *file;
+{
+ return (p_cdnname(cp, msg, PACKETSZ, file));
+}
+
+
+/* Return a fully-qualified domain name from a compressed name (with
+ length supplied). */
+
+const u_char *
+__p_fqnname(cp, msg, msglen, name, namelen)
+ const u_char *cp, *msg;
+ int msglen;
+ char *name;
+ int namelen;
+{
+ int n, newlen;
+
+ if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
+ return (NULL);
+ newlen = strlen (name);
+ if (newlen == 0 || name[newlen - 1] != '.')
+ if (newlen+1 >= namelen) /* Lack space for final dot */
+ return (NULL);
+ else
+ strcpy(name + newlen, ".");
+ return (cp + n);
+}
+
+/* XXX: the rest of these functions need to become length-limited, too. (vix)
+ */
+
+const u_char *
+__p_fqname(cp, msg, file)
+ const u_char *cp, *msg;
+ FILE *file;
+{
+ char name[MAXDNAME];
+ const u_char *n;
+
+ n = __p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
+ if (n == NULL)
+ return (NULL);
+ fputs(name, file);
+ return (n);
+}
+
+/*
+ * Print resource record fields in human readable form.
+ */
+const u_char *
+__p_rr(cp, msg, file)
+ const u_char *cp, *msg;
+ FILE *file;
+{
+ int type, class, dlen, n, c;
+ struct in_addr inaddr;
+ const u_char *cp1, *cp2;
+ u_int32_t tmpttl, t;
+ int lcnt;
+ u_int16_t keyflags;
+ char rrname[MAXDNAME]; /* The fqdn of this RR */
+ char base64_key[MAX_KEY_BASE64];
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ cp = __p_fqnname(cp, msg, MAXCDNAME, rrname, sizeof rrname);
+ if (!cp)
+ return (NULL); /* compression error */
+ fputs(rrname, file);
+
+ type = _getshort((u_char*)cp);
+ cp += INT16SZ;
+ class = _getshort((u_char*)cp);
+ cp += INT16SZ;
+ tmpttl = _getlong((u_char*)cp);
+ cp += INT32SZ;
+ dlen = _getshort((u_char*)cp);
+ cp += INT16SZ;
+ cp1 = cp;
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID))
+ fprintf(file, "\t%lu", (u_long)tmpttl);
+ if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS))
+ fprintf(file, "\t%s", __p_class(class));
+ fprintf(file, "\t%s", __p_type(type));
+ /*
+ * Print type specific data, if appropriate
+ */
+ switch (type) {
+ case T_A:
+ switch (class) {
+ case C_IN:
+ case C_HS:
+ bcopy(cp, (char *)&inaddr, INADDRSZ);
+ if (dlen == 4) {
+ fprintf(file, "\t%s", inet_ntoa(inaddr));
+ cp += dlen;
+ } else if (dlen == 7) {
+ char *address;
+ u_char protocol;
+ u_short port;
+
+ address = inet_ntoa(inaddr);
+ cp += INADDRSZ;
+ protocol = *(u_char*)cp;
+ cp += sizeof (u_char);
+ port = _getshort((u_char*)cp);
+ cp += INT16SZ;
+ fprintf(file, "\t%s\t; proto %d, port %d",
+ address, protocol, port);
+ }
+ break;
+ default:
+ cp += dlen;
+ }
+ break;
+ case T_CNAME:
+ case T_MB:
+ case T_MG:
+ case T_MR:
+ case T_NS:
+ case T_PTR:
+ putc('\t', file);
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL);
+ break;
+
+ case T_HINFO:
+ case T_ISDN:
+ cp2 = cp + dlen;
+ (void) fputs("\t\"", file);
+ if ((n = (unsigned char) *cp++) != 0) {
+ for (c = n; c > 0 && cp < cp2; c--) {
+ if (strchr("\n\"\\", *cp))
+ (void) putc('\\', file);
+ (void) putc(*cp++, file);
+ }
+ }
+ putc('"', file);
+ if (cp < cp2 && (n = (unsigned char) *cp++) != 0) {
+ (void) fputs ("\t\"", file);
+ for (c = n; c > 0 && cp < cp2; c--) {
+ if (strchr("\n\"\\", *cp))
+ (void) putc('\\', file);
+ (void) putc(*cp++, file);
+ }
+ putc('"', file);
+ } else if (type == T_HINFO) {
+ (void) fputs("\"?\"", file);
+ fprintf(file, "\n;; *** Warning *** OS-type missing");
+ }
+ break;
+
+ case T_SOA:
+ putc('\t', file);
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL);
+ putc(' ', file);
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL);
+ fputs(" (\n", file);
+ t = _getlong((u_char*)cp); cp += INT32SZ;
+ fprintf(file, "\t\t\t%lu\t; serial\n", (u_long)t);
+ t = _getlong((u_char*)cp); cp += INT32SZ;
+ fprintf(file, "\t\t\t%lu\t; refresh (%s)\n",
+ (u_long)t, __p_time(t));
+ t = _getlong((u_char*)cp); cp += INT32SZ;
+ fprintf(file, "\t\t\t%lu\t; retry (%s)\n",
+ (u_long)t, __p_time(t));
+ t = _getlong((u_char*)cp); cp += INT32SZ;
+ fprintf(file, "\t\t\t%lu\t; expire (%s)\n",
+ (u_long)t, __p_time(t));
+ t = _getlong((u_char*)cp); cp += INT32SZ;
+ fprintf(file, "\t\t\t%lu )\t; minimum (%s)",
+ (u_long)t, __p_time(t));
+ break;
+
+ case T_MX:
+ case T_AFSDB:
+ case T_RT:
+ fprintf(file, "\t%d ", _getshort((u_char*)cp));
+ cp += INT16SZ;
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL);
+ break;
+
+ case T_PX:
+ fprintf(file, "\t%d ", _getshort((u_char*)cp));
+ cp += INT16SZ;
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL);
+ putc(' ', file);
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL);
+ break;
+
+ case T_X25:
+ cp2 = cp + dlen;
+ (void) fputs("\t\"", file);
+ if ((n = (unsigned char) *cp++) != 0) {
+ for (c = n; c > 0 && cp < cp2; c--) {
+ if (strchr("\n\"\\", *cp))
+ (void) putc('\\', file);
+ (void) putc(*cp++, file);
+ }
+ }
+ putc('"', file);
+ break;
+
+ case T_TXT:
+ (void) putc('\t', file);
+ cp2 = cp1 + dlen;
+ while (cp < cp2) {
+ putc('"', file);
+ if ((n = (unsigned char) *cp++) != '\0') {
+ for (c = n; c > 0 && cp < cp2; c--) {
+ if (strchr("\n\"\\", *cp))
+ (void) putc('\\', file);
+ (void) putc(*cp++, file);
+ }
+ }
+ putc('"', file);
+ if (cp < cp2)
+ putc(' ', file);
+ }
+ break;
+
+ case T_NSAP:
+ (void) fprintf(file, "\t%s", inet_nsap_ntoa(dlen, cp, NULL));
+ cp += dlen;
+ break;
+
+ case T_AAAA: {
+ char t[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
+
+ fprintf(file, "\t%s", inet_ntop(AF_INET6, cp, t, sizeof t));
+ cp += dlen;
+ break;
+ }
+
+ case T_LOC: {
+ char t[255];
+
+ fprintf(file, "\t%s", loc_ntoa(cp, t));
+ cp += dlen;
+ break;
+ }
+
+ case T_NAPTR: {
+ u_int order, preference;
+
+ order = _getshort(cp); cp += INT16SZ;
+ preference = _getshort(cp); cp += INT16SZ;
+ fprintf(file, "\t%u %u ",order, preference);
+ /* Flags */
+ n = *cp++;
+ fprintf(file,"\"%.*s\" ", (int)n, cp);
+ cp += n;
+ /* Service */
+ n = *cp++;
+ fprintf(file,"\"%.*s\" ", (int)n, cp);
+ cp += n;
+ /* Regexp */
+ n = *cp++;
+ fprintf(file,"\"%.*s\" ", (int)n, cp);
+ cp += n;
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL);
+ break;
+ }
+
+ case T_SRV: {
+ u_int priority, weight, port;
+
+ priority = _getshort(cp); cp += INT16SZ;
+ weight = _getshort(cp); cp += INT16SZ;
+ port = _getshort(cp); cp += INT16SZ;
+ fprintf(file, "\t%u %u %u ", priority, weight, port);
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL);
+ break;
+ }
+
+ case T_MINFO:
+ case T_RP:
+ putc('\t', file);
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL);
+ putc(' ', file);
+ if ((cp = p_fqname(cp, msg, file)) == NULL)
+ return (NULL);
+ break;
+
+ case T_UINFO:
+ putc('\t', file);
+ fputs((char *)cp, file);
+ cp += dlen;
+ break;
+
+ case T_UID:
+ case T_GID:
+ if (dlen == 4) {
+ fprintf(file, "\t%u", _getlong((u_char*)cp));
+ cp += INT32SZ;
+ }
+ break;
+
+ case T_WKS:
+ if (dlen < INT32SZ + 1)
+ break;
+ bcopy(cp, (char *)&inaddr, INADDRSZ);
+ cp += INT32SZ;
+ fprintf(file, "\t%s %s ( ",
+ inet_ntoa(inaddr),
+ deproto((int) *cp));
+ cp += sizeof (u_char);
+ n = 0;
+ lcnt = 0;
+ while (cp < cp1 + dlen) {
+ c = *cp++;
+ do {
+ if (c & 0200) {
+ if (lcnt == 0) {
+ fputs("\n\t\t\t", file);
+ lcnt = 5;
+ }
+ fputs(dewks(n), file);
+ putc(' ', file);
+ lcnt--;
+ }
+ c <<= 1;
+ } while (++n & 07);
+ }
+ putc(')', file);
+ break;
+
+ case T_KEY:
+ putc('\t', file);
+ keyflags = _getshort(cp);
+ cp += 2;
+ fprintf(file,"0x%04x", keyflags ); /* flags */
+ fprintf(file," %u", *cp++); /* protocol */
+ fprintf(file," %u (", *cp++); /* algorithm */
+
+ n = b64_ntop(cp, (cp1 + dlen) - cp,
+ base64_key, sizeof base64_key);
+ for (c = 0; c < n; ++c) {
+ if (0 == (c & 0x3F))
+ fprintf(file, "\n\t");
+ putc(base64_key[c], file); /* public key data */
+ }
+
+ fprintf(file, " )");
+ if (n < 0)
+ fprintf(file, "\t; BAD BASE64");
+ fflush(file);
+ cp = cp1 + dlen;
+ break;
+
+ case T_SIG:
+ type = _getshort((u_char*)cp);
+ cp += INT16SZ;
+ fprintf(file, " %s", p_type(type));
+ fprintf(file, "\t%d", *cp++); /* algorithm */
+ /* Check label value and print error if wrong. */
+ n = *cp++;
+ c = dn_count_labels (rrname);
+ if (n != c)
+ fprintf(file, "\t; LABELS WRONG (%d should be %d)\n\t",
+ n, c);
+ /* orig ttl */
+ n = _getlong((u_char*)cp);
+ if (n != tmpttl)
+ fprintf(file, " %u", n);
+ cp += INT32SZ;
+ /* sig expire */
+ fprintf(file, " (\n\t%s",
+ __p_secstodate(_getlong((u_char*)cp)));
+ cp += INT32SZ;
+ /* time signed */
+ fprintf(file, " %s", __p_secstodate(_getlong((u_char*)cp)));
+ cp += INT32SZ;
+ /* sig footprint */
+ fprintf(file," %u ", _getshort((u_char*)cp));
+ cp += INT16SZ;
+ /* signer's name */
+ cp = p_fqname(cp, msg, file);
+ n = b64_ntop(cp, (cp1 + dlen) - cp,
+ base64_key, sizeof base64_key);
+ for (c = 0; c < n; c++) {
+ if (0 == (c & 0x3F))
+ fprintf (file, "\n\t");
+ putc(base64_key[c], file); /* signature */
+ }
+ /* Clean up... */
+ fprintf(file, " )");
+ if (n < 0)
+ fprintf(file, "\t; BAD BASE64");
+ fflush(file);
+ cp = cp1+dlen;
+ break;
+
+#ifdef ALLOW_T_UNSPEC
+ case T_UNSPEC:
+ {
+ int NumBytes = 8;
+ u_char *DataPtr;
+ int i;
+
+ if (dlen < NumBytes) NumBytes = dlen;
+ fprintf(file, "\tFirst %d bytes of hex data:",
+ NumBytes);
+ for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++)
+ fprintf(file, " %x", *DataPtr);
+ cp += dlen;
+ }
+ break;
+#endif /* ALLOW_T_UNSPEC */
+
+ default:
+ fprintf(file, "\t?%d?", type);
+ cp += dlen;
+ }
+#if 0
+ fprintf(file, "\t; dlen=%d, ttl %s\n", dlen, __p_time(tmpttl));
+#else
+ putc('\n', file);
+#endif
+ if (cp - cp1 != dlen) {
+ fprintf(file, ";; packet size error (found %d, dlen was %d)\n",
+ cp - cp1, dlen);
+ cp = NULL;
+ }
+ return (cp);
+}
+
+/*
+ * Names of RR classes and qclasses. Classes and qclasses are the same, except
+ * that C_ANY is a qclass but not a class. (You can ask for records of class
+ * C_ANY, but you can't have any records of that class in the database.)
+ */
+const struct res_sym __p_class_syms[] = {
+ {C_IN, "IN"},
+ {C_CHAOS, "CHAOS"},
+ {C_HS, "HS"},
+ {C_HS, "HESIOD"},
+ {C_ANY, "ANY"},
+ {C_IN, (char *)0}
+};
+
+/*
+ * Names of RR types and qtypes. Types and qtypes are the same, except
+ * that T_ANY is a qtype but not a type. (You can ask for records of type
+ * T_ANY, but you can't have any records of that type in the database.)
+ */
+const struct res_sym __p_type_syms[] = {
+ {T_A, "A", "address"},
+ {T_NS, "NS", "name server"},
+ {T_MD, "MD", "mail destination (deprecated)"},
+ {T_MF, "MF", "mail forwarder (deprecated)"},
+ {T_CNAME, "CNAME", "canonical name"},
+ {T_SOA, "SOA", "start of authority"},
+ {T_MB, "MB", "mailbox"},
+ {T_MG, "MG", "mail group member"},
+ {T_MR, "MR", "mail rename"},
+ {T_NULL, "NULL", "null"},
+ {T_WKS, "WKS", "well-known service (deprecated)"},
+ {T_PTR, "PTR", "domain name pointer"},
+ {T_HINFO, "HINFO", "host information"},
+ {T_MINFO, "MINFO", "mailbox information"},
+ {T_MX, "MX", "mail exchanger"},
+ {T_TXT, "TXT", "text"},
+ {T_RP, "RP", "responsible person"},
+ {T_AFSDB, "AFSDB", "DCE or AFS server"},
+ {T_X25, "X25", "X25 address"},
+ {T_ISDN, "ISDN", "ISDN address"},
+ {T_RT, "RT", "router"},
+ {T_NSAP, "NSAP", "nsap address"},
+ {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"},
+ {T_SIG, "SIG", "signature"},
+ {T_KEY, "KEY", "key"},
+ {T_PX, "PX", "mapping information"},
+ {T_GPOS, "GPOS", "geographical position (withdrawn)"},
+ {T_AAAA, "AAAA", "IPv6 address"},
+ {T_LOC, "LOC", "location"},
+ {T_NXT, "NXT", "next valid name (unimplemented)"},
+ {T_EID, "EID", "endpoint identifier (unimplemented)"},
+ {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"},
+ {T_SRV, "SRV", "server selection"},
+ {T_ATMA, "ATMA", "ATM address (unimplemented)"},
+ {T_IXFR, "IXFR", "incremental zone transfer"},
+ {T_AXFR, "AXFR", "zone transfer"},
+ {T_MAILB, "MAILB", "mailbox-related data (deprecated)"},
+ {T_MAILA, "MAILA", "mail agent (deprecated)"},
+ {T_UINFO, "UINFO", "user information (nonstandard)"},
+ {T_UID, "UID", "user ID (nonstandard)"},
+ {T_GID, "GID", "group ID (nonstandard)"},
+ {T_NAPTR, "NAPTR", "URN Naming Authority"},
+#ifdef ALLOW_T_UNSPEC
+ {T_UNSPEC, "UNSPEC", "unspecified data (nonstandard)"},
+#endif /* ALLOW_T_UNSPEC */
+ {T_ANY, "ANY", "\"any\""},
+ {0, NULL, NULL}
+};
+
+int
+__sym_ston(syms, name, success)
+ const struct res_sym *syms;
+ char *name;
+ int *success;
+{
+ for (NULL; syms->name != 0; syms++) {
+ if (strcasecmp (name, syms->name) == 0) {
+ if (success)
+ *success = 1;
+ return (syms->number);
+ }
+ }
+ if (success)
+ *success = 0;
+ return (syms->number); /* The default value. */
+}
+
+const char *
+__sym_ntos(syms, number, success)
+ const struct res_sym *syms;
+ int number;
+ int *success;
+{
+ static char unname[20];
+
+ for (NULL; syms->name != 0; syms++) {
+ if (number == syms->number) {
+ if (success)
+ *success = 1;
+ return (syms->name);
+ }
+ }
+
+ sprintf (unname, "%d", number);
+ if (success)
+ *success = 0;
+ return (unname);
+}
+
+
+const char *
+__sym_ntop(syms, number, success)
+ const struct res_sym *syms;
+ int number;
+ int *success;
+{
+ static char unname[20];
+
+ for (NULL; syms->name != 0; syms++) {
+ if (number == syms->number) {
+ if (success)
+ *success = 1;
+ return (syms->humanname);
+ }
+ }
+ sprintf(unname, "%d", number);
+ if (success)
+ *success = 0;
+ return (unname);
+}
+
+/*
+ * Return a string for the type
+ */
+const char *
+__p_type(type)
+ int type;
+{
+ return (__sym_ntos (__p_type_syms, type, (int *)0));
+}
+
+/*
+ * Return a mnemonic for class
+ */
+const char *
+__p_class(class)
+ int class;
+{
+ return (__sym_ntos (__p_class_syms, class, (int *)0));
+}
+
+/*
+ * Return a mnemonic for an option
+ */
+const char *
+__p_option(option)
+ u_long option;
+{
+ static char nbuf[40];
+
+ switch (option) {
+ case RES_INIT: return "init";
+ case RES_DEBUG: return "debug";
+ case RES_AAONLY: return "aaonly(unimpl)";
+ case RES_USEVC: return "usevc";
+ case RES_PRIMARY: return "primry(unimpl)";
+ case RES_IGNTC: return "igntc";
+ case RES_RECURSE: return "recurs";
+ case RES_DEFNAMES: return "defnam";
+ case RES_STAYOPEN: return "styopn";
+ case RES_DNSRCH: return "dnsrch";
+ case RES_INSECURE1: return "insecure1";
+ case RES_INSECURE2: return "insecure2";
+ default: sprintf(nbuf, "?0x%lx?", (u_long)option);
+ return (nbuf);
+ }
+}
+
+/*
+ * Return a mnemonic for a time to live
+ */
+const char *
+p_time(value)
+ u_int32_t value;
+{
+ static char nbuf[40];
+ int secs, mins, hours, days;
+ register char *p;
+
+ if (value == 0) {
+ strcpy(nbuf, "0 secs");
+ return (nbuf);
+ }
+
+ secs = value % 60;
+ value /= 60;
+ mins = value % 60;
+ value /= 60;
+ hours = value % 24;
+ value /= 24;
+ days = value;
+ value = 0;
+
+#define PLURALIZE(x) x, (x == 1) ? "" : "s"
+ p = nbuf;
+ if (days) {
+ (void)sprintf(p, "%d day%s", PLURALIZE(days));
+ while (*++p);
+ }
+ if (hours) {
+ if (days)
+ *p++ = ' ';
+ (void)sprintf(p, "%d hour%s", PLURALIZE(hours));
+ while (*++p);
+ }
+ if (mins) {
+ if (days || hours)
+ *p++ = ' ';
+ (void)sprintf(p, "%d min%s", PLURALIZE(mins));
+ while (*++p);
+ }
+ if (secs || ! (days || hours || mins)) {
+ if (days || hours || mins)
+ *p++ = ' ';
+ (void)sprintf(p, "%d sec%s", PLURALIZE(secs));
+ }
+ return (nbuf);
+}
+
+/*
+ * routines to convert between on-the-wire RR format and zone file format.
+ * Does not contain conversion to/from decimal degrees; divide or multiply
+ * by 60*60*1000 for that.
+ */
+
+static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
+ 1000000,10000000,100000000,1000000000};
+
+/* takes an XeY precision/size value, returns a string representation. */
+static const char *
+precsize_ntoa(prec)
+ u_int8_t prec;
+{
+ static char retbuf[sizeof "90000000.00"];
+ unsigned long val;
+ int mantissa, exponent;
+
+ mantissa = (int)((prec >> 4) & 0x0f) % 10;
+ exponent = (int)((prec >> 0) & 0x0f) % 10;
+
+ val = mantissa * poweroften[exponent];
+
+ (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100);
+ return (retbuf);
+}
+
+/* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
+static u_int8_t
+precsize_aton(strptr)
+ char **strptr;
+{
+ u_int8_t retval = 0;
+ char *cp;
+ int exponent = 0;
+ int mantissa = 0;
+
+ cp = *strptr;
+ while (isdigit(*cp)) {
+ if (mantissa == 0)
+ mantissa = *cp - '0';
+ else
+ exponent++;
+ cp++;
+ }
+
+ if (*cp == '.') {
+ cp++;
+ if (isdigit(*cp)) {
+ if (mantissa == 0)
+ mantissa = *cp - '0';
+ else
+ exponent++;
+ cp++;
+
+ if (isdigit(*cp)) {
+ if (mantissa == 0)
+ mantissa = *cp - '0';
+ else
+ exponent++;
+ cp++;
+ }
+ else
+ exponent++;
+ }
+ }
+ else
+ exponent += 2;
+
+ if (mantissa == 0)
+ exponent = 0;
+ retval = (mantissa << 4) | exponent;
+ *strptr = cp;
+ return (retval);
+}
+
+/* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
+static u_int32_t
+latlon2ul(latlonstrptr,which)
+ char **latlonstrptr;
+ int *which;
+{
+ register char *cp;
+ u_int32_t retval;
+ int deg = 0, min = 0, secs = 0, secsfrac = 0;
+
+ cp = *latlonstrptr;
+
+ while (isdigit(*cp))
+ deg = deg * 10 + (*cp++ - '0');
+
+ while (isspace(*cp))
+ cp++;
+
+ if (!(isdigit(*cp)))
+ goto fndhemi;
+
+ while (isdigit(*cp))
+ min = min * 10 + (*cp++ - '0');
+
+ while (isspace(*cp))
+ cp++;
+
+ if (!(isdigit(*cp)))
+ goto fndhemi;
+
+ while (isdigit(*cp))
+ secs = secs * 10 + (*cp++ - '0');
+
+ if (*cp == '.') { /* decimal seconds */
+ cp++;
+ if (isdigit(*cp)) {
+ secsfrac = (*cp++ - '0') * 100;
+ if (isdigit(*cp)) {
+ secsfrac += (*cp++ - '0') * 10;
+ if (isdigit(*cp)) {
+ secsfrac += (*cp++ - '0');
+ }
+ }
+ }
+ }
+
+ while (!isspace(*cp)) /* if any trailing garbage */
+ cp++;
+
+ while (isspace(*cp))
+ cp++;
+
+ fndhemi:
+ switch (*cp) {
+ case 'N': case 'n':
+ case 'E': case 'e':
+ retval = ((unsigned)1<<31)
+ + (((((deg * 60) + min) * 60) + secs) * 1000)
+ + secsfrac;
+ break;
+ case 'S': case 's':
+ case 'W': case 'w':
+ retval = ((unsigned)1<<31)
+ - (((((deg * 60) + min) * 60) + secs) * 1000)
+ - secsfrac;
+ break;
+ default:
+ retval = 0; /* invalid value -- indicates error */
+ break;
+ }
+
+ switch (*cp) {
+ case 'N': case 'n':
+ case 'S': case 's':
+ *which = 1; /* latitude */
+ break;
+ case 'E': case 'e':
+ case 'W': case 'w':
+ *which = 2; /* longitude */
+ break;
+ default:
+ *which = 0; /* error */
+ break;
+ }
+
+ cp++; /* skip the hemisphere */
+
+ while (!isspace(*cp)) /* if any trailing garbage */
+ cp++;
+
+ while (isspace(*cp)) /* move to next field */
+ cp++;
+
+ *latlonstrptr = cp;
+
+ return (retval);
+}
+
+/* converts a zone file representation in a string to an RDATA on-the-wire
+ * representation. */
+int
+loc_aton(ascii, binary)
+ const char *ascii;
+ u_char *binary;
+{
+ const char *cp, *maxcp;
+ u_char *bcp;
+
+ u_int32_t latit = 0, longit = 0, alt = 0;
+ u_int32_t lltemp1 = 0, lltemp2 = 0;
+ int altmeters = 0, altfrac = 0, altsign = 1;
+ u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */
+ u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */
+ u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */
+ int which1 = 0, which2 = 0;
+
+ cp = ascii;
+ maxcp = cp + strlen(ascii);
+
+ lltemp1 = latlon2ul(&cp, &which1);
+
+ lltemp2 = latlon2ul(&cp, &which2);
+
+ switch (which1 + which2) {
+ case 3: /* 1 + 2, the only valid combination */
+ if ((which1 == 1) && (which2 == 2)) { /* normal case */
+ latit = lltemp1;
+ longit = lltemp2;
+ } else if ((which1 == 2) && (which2 == 1)) { /* reversed */
+ longit = lltemp1;
+ latit = lltemp2;
+ } else { /* some kind of brokenness */
+ return (0);
+ }
+ break;
+ default: /* we didn't get one of each */
+ return (0);
+ }
+
+ /* altitude */
+ if (*cp == '-') {
+ altsign = -1;
+ cp++;
+ }
+
+ if (*cp == '+')
+ cp++;
+
+ while (isdigit(*cp))
+ altmeters = altmeters * 10 + (*cp++ - '0');
+
+ if (*cp == '.') { /* decimal meters */
+ cp++;
+ if (isdigit(*cp)) {
+ altfrac = (*cp++ - '0') * 10;
+ if (isdigit(*cp)) {
+ altfrac += (*cp++ - '0');
+ }
+ }
+ }
+
+ alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
+
+ while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ cp++;
+
+ while (isspace(*cp) && (cp < maxcp))
+ cp++;
+
+ if (cp >= maxcp)
+ goto defaults;
+
+ siz = precsize_aton(&cp);
+
+ while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ cp++;
+
+ while (isspace(*cp) && (cp < maxcp))
+ cp++;
+
+ if (cp >= maxcp)
+ goto defaults;
+
+ hp = precsize_aton(&cp);
+
+ while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
+ cp++;
+
+ while (isspace(*cp) && (cp < maxcp))
+ cp++;
+
+ if (cp >= maxcp)
+ goto defaults;
+
+ vp = precsize_aton(&cp);
+
+ defaults:
+
+ bcp = binary;
+ *bcp++ = (u_int8_t) 0; /* version byte */
+ *bcp++ = siz;
+ *bcp++ = hp;
+ *bcp++ = vp;
+ PUTLONG(latit,bcp);
+ PUTLONG(longit,bcp);
+ PUTLONG(alt,bcp);
+
+ return (16); /* size of RR in octets */
+}
+
+/* takes an on-the-wire LOC RR and formats it in a human readable format. */
+const char *
+loc_ntoa(binary, ascii)
+ const u_char *binary;
+ char *ascii;
+{
+ static char *error = "?";
+ register const u_char *cp = binary;
+
+ int latdeg, latmin, latsec, latsecfrac;
+ int longdeg, longmin, longsec, longsecfrac;
+ char northsouth, eastwest;
+ int altmeters, altfrac, altsign;
+
+ const int referencealt = 100000 * 100;
+
+ int32_t latval, longval, altval;
+ u_int32_t templ;
+ u_int8_t sizeval, hpval, vpval, versionval;
+
+ char *sizestr, *hpstr, *vpstr;
+
+ versionval = *cp++;
+
+ if (versionval) {
+ sprintf(ascii, "; error: unknown LOC RR version");
+ return (ascii);
+ }
+
+ sizeval = *cp++;
+
+ hpval = *cp++;
+ vpval = *cp++;
+
+ GETLONG(templ, cp);
+ latval = (templ - ((unsigned)1<<31));
+
+ GETLONG(templ, cp);
+ longval = (templ - ((unsigned)1<<31));
+
+ GETLONG(templ, cp);
+ if (templ < referencealt) { /* below WGS 84 spheroid */
+ altval = referencealt - templ;
+ altsign = -1;
+ } else {
+ altval = templ - referencealt;
+ altsign = 1;
+ }
+
+ if (latval < 0) {
+ northsouth = 'S';
+ latval = -latval;
+ } else
+ northsouth = 'N';
+
+ latsecfrac = latval % 1000;
+ latval = latval / 1000;
+ latsec = latval % 60;
+ latval = latval / 60;
+ latmin = latval % 60;
+ latval = latval / 60;
+ latdeg = latval;
+
+ if (longval < 0) {
+ eastwest = 'W';
+ longval = -longval;
+ } else
+ eastwest = 'E';
+
+ longsecfrac = longval % 1000;
+ longval = longval / 1000;
+ longsec = longval % 60;
+ longval = longval / 60;
+ longmin = longval % 60;
+ longval = longval / 60;
+ longdeg = longval;
+
+ altfrac = altval % 100;
+ altmeters = (altval / 100) * altsign;
+
+ if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL)
+ sizestr = error;
+ if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL)
+ hpstr = error;
+ if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL)
+ vpstr = error;
+
+ sprintf(ascii,
+ "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
+ latdeg, latmin, latsec, latsecfrac, northsouth,
+ longdeg, longmin, longsec, longsecfrac, eastwest,
+ altmeters, altfrac, sizestr, hpstr, vpstr);
+
+ if (sizestr != error)
+ free(sizestr);
+ if (hpstr != error)
+ free(hpstr);
+ if (vpstr != error)
+ free(vpstr);
+
+ return (ascii);
+}
+
+
+/* Return the number of DNS hierarchy levels in the name. */
+int
+__dn_count_labels(name)
+ char *name;
+{
+ int i, len, count;
+
+ len = strlen(name);
+
+ for(i = 0, count = 0; i < len; i++) {
+ if (name[i] == '.')
+ count++;
+ }
+
+ /* don't count initial wildcard */
+ if (name[0] == '*')
+ if (count)
+ count--;
+
+ /* don't count the null label for root. */
+ /* if terminating '.' not found, must adjust */
+ /* count to include last label */
+ if (len > 0 && name[len-1] != '.')
+ count++;
+ return (count);
+}
+
+
+/*
+ * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
+ * SIG records are required to be printed like this, by the Secure DNS RFC.
+ */
+char *
+__p_secstodate (secs)
+ unsigned long secs;
+{
+ static char output[15]; /* YYYYMMDDHHMMSS and null */
+ time_t clock = secs;
+ struct tm *time;
+
+ time = gmtime(&clock);
+ time->tm_year += 1900;
+ time->tm_mon += 1;
+ sprintf(output, "%04d%02d%02d%02d%02d%02d",
+ time->tm_year, time->tm_mon, time->tm_mday,
+ time->tm_hour, time->tm_min, time->tm_sec);
+ return (output);
+}
diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c
new file mode 100644
index 0000000..2fa3cbc
--- /dev/null
+++ b/lib/libc/net/res_init.c
@@ -0,0 +1,459 @@
+/*
+ * ++Copyright++ 1985, 1989, 1993
+ * -
+ * Copyright (c) 1985, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
+static char orig_rcsid[] = "From: Id: res_init.c,v 8.8 1997/06/01 20:34:37 vixie Exp";
+static char rcsid[] = "$Id: res_init.c,v 1.12 1997/02/22 15:00:32 peter Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "res_config.h"
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <ctype.h>
+#include <resolv.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void res_setoptions __P((char *, char *));
+
+#ifdef RESOLVSORT
+static const char sort_mask[] = "/&";
+#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
+static u_int32_t net_mask __P((struct in_addr));
+#endif
+
+/*
+ * Resolver state default settings.
+ */
+
+struct __res_state _res
+# if defined(__BIND_RES_TEXT)
+ = { RES_TIMEOUT, } /* Motorola, et al. */
+# endif
+ ;
+
+/*
+ * Set up default settings. If the configuration file exist, the values
+ * there will have precedence. Otherwise, the server address is set to
+ * INADDR_ANY and the default domain name comes from the gethostname().
+ *
+ * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
+ * rather than INADDR_ANY ("0.0.0.0") as the default name server address
+ * since it was noted that INADDR_ANY actually meant ``the first interface
+ * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
+ * it had to be "up" in order for you to reach your own name server. It
+ * was later decided that since the recommended practice is to always
+ * install local static routes through 127.0.0.1 for all your network
+ * interfaces, that we could solve this problem without a code change.
+ *
+ * The configuration file should always be used, since it is the only way
+ * to specify a default domain. If you are running a server on your local
+ * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
+ * in the configuration file.
+ *
+ * Return 0 if completes successfully, -1 on error
+ */
+int
+res_init()
+{
+ register FILE *fp;
+ register char *cp, **pp;
+ register int n;
+ char buf[MAXDNAME];
+ int nserv = 0; /* number of nameserver records read from file */
+ int haveenv = 0;
+ int havesearch = 0;
+#ifdef RESOLVSORT
+ int nsort = 0;
+ char *net;
+#endif
+#ifndef RFC1535
+ int dots;
+#endif
+
+ /*
+ * These three fields used to be statically initialized. This made
+ * it hard to use this code in a shared library. It is necessary,
+ * now that we're doing dynamic initialization here, that we preserve
+ * the old semantics: if an application modifies one of these three
+ * fields of _res before res_init() is called, res_init() will not
+ * alter them. Of course, if an application is setting them to
+ * _zero_ before calling res_init(), hoping to override what used
+ * to be the static default, we can't detect it and unexpected results
+ * will follow. Zero for any of these fields would make no sense,
+ * so one can safely assume that the applications were already getting
+ * unexpected results.
+ *
+ * _res.options is tricky since some apps were known to diddle the bits
+ * before res_init() was first called. We can't replicate that semantic
+ * with dynamic initialization (they may have turned bits off that are
+ * set in RES_DEFAULT). Our solution is to declare such applications
+ * "broken". They could fool us by setting RES_INIT but none do (yet).
+ */
+ if (!_res.retrans)
+ _res.retrans = RES_TIMEOUT;
+ if (!_res.retry)
+ _res.retry = 4;
+ if (!(_res.options & RES_INIT))
+ _res.options = RES_DEFAULT;
+
+ /*
+ * This one used to initialize implicitly to zero, so unless the app
+ * has set it to something in particular, we can randomize it now.
+ */
+ if (!_res.id)
+ _res.id = res_randomid();
+
+#ifdef USELOOPBACK
+ _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
+#else
+ _res.nsaddr.sin_addr.s_addr = INADDR_ANY;
+#endif
+ _res.nsaddr.sin_family = AF_INET;
+ _res.nsaddr.sin_port = htons(NAMESERVER_PORT);
+ _res.nscount = 1;
+ _res.ndots = 1;
+ _res.pfcode = 0;
+
+ /* Allow user to override the local domain definition */
+ if ((cp = getenv("LOCALDOMAIN")) != NULL) {
+ (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+ haveenv++;
+
+ /*
+ * Set search list to be blank-separated strings
+ * from rest of env value. Permits users of LOCALDOMAIN
+ * to still have a search list, and anyone to set the
+ * one that they want to use as an individual (even more
+ * important now that the rfc1535 stuff restricts searches)
+ */
+ cp = _res.defdname;
+ pp = _res.dnsrch;
+ *pp++ = cp;
+ for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
+ if (*cp == '\n') /* silly backwards compat */
+ break;
+ else if (*cp == ' ' || *cp == '\t') {
+ *cp = 0;
+ n = 1;
+ } else if (n) {
+ *pp++ = cp;
+ n = 0;
+ havesearch = 1;
+ }
+ }
+ /* null terminate last domain if there are excess */
+ while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
+ cp++;
+ *cp = '\0';
+ *pp++ = 0;
+ }
+
+#define MATCH(line, name) \
+ (!strncmp(line, name, sizeof(name) - 1) && \
+ (line[sizeof(name) - 1] == ' ' || \
+ line[sizeof(name) - 1] == '\t'))
+
+ if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
+ /* read the config file */
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ /* skip comments */
+ if (*buf == ';' || *buf == '#')
+ continue;
+ /* read default domain name */
+ if (MATCH(buf, "domain")) {
+ if (haveenv) /* skip if have from environ */
+ continue;
+ cp = buf + sizeof("domain") - 1;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if ((*cp == '\0') || (*cp == '\n'))
+ continue;
+ strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+ if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
+ *cp = '\0';
+ havesearch = 0;
+ continue;
+ }
+ /* set search list */
+ if (MATCH(buf, "search")) {
+ if (haveenv) /* skip if have from environ */
+ continue;
+ cp = buf + sizeof("search") - 1;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if ((*cp == '\0') || (*cp == '\n'))
+ continue;
+ strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
+ if ((cp = strchr(_res.defdname, '\n')) != NULL)
+ *cp = '\0';
+ /*
+ * Set search list to be blank-separated strings
+ * on rest of line.
+ */
+ cp = _res.defdname;
+ pp = _res.dnsrch;
+ *pp++ = cp;
+ for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
+ if (*cp == ' ' || *cp == '\t') {
+ *cp = 0;
+ n = 1;
+ } else if (n) {
+ *pp++ = cp;
+ n = 0;
+ }
+ }
+ /* null terminate last domain if there are excess */
+ while (*cp != '\0' && *cp != ' ' && *cp != '\t')
+ cp++;
+ *cp = '\0';
+ *pp++ = 0;
+ havesearch = 1;
+ continue;
+ }
+ /* read nameservers to query */
+ if (MATCH(buf, "nameserver") && nserv < MAXNS) {
+ struct in_addr a;
+
+ cp = buf + sizeof("nameserver") - 1;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) {
+ _res.nsaddr_list[nserv].sin_addr = a;
+ _res.nsaddr_list[nserv].sin_family = AF_INET;
+ _res.nsaddr_list[nserv].sin_port =
+ htons(NAMESERVER_PORT);
+ nserv++;
+ }
+ continue;
+ }
+#ifdef RESOLVSORT
+ if (MATCH(buf, "sortlist")) {
+ struct in_addr a;
+
+ cp = buf + sizeof("sortlist") - 1;
+ while (nsort < MAXRESOLVSORT) {
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ if (*cp == '\0' || *cp == '\n' || *cp == ';')
+ break;
+ net = cp;
+ while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
+ isascii(*cp) && !isspace(*cp))
+ cp++;
+ n = *cp;
+ *cp = 0;
+ if (inet_aton(net, &a)) {
+ _res.sort_list[nsort].addr = a;
+ if (ISSORTMASK(n)) {
+ *cp++ = n;
+ net = cp;
+ while (*cp && *cp != ';' &&
+ isascii(*cp) && !isspace(*cp))
+ cp++;
+ n = *cp;
+ *cp = 0;
+ if (inet_aton(net, &a)) {
+ _res.sort_list[nsort].mask = a.s_addr;
+ } else {
+ _res.sort_list[nsort].mask =
+ net_mask(_res.sort_list[nsort].addr);
+ }
+ } else {
+ _res.sort_list[nsort].mask =
+ net_mask(_res.sort_list[nsort].addr);
+ }
+ nsort++;
+ }
+ *cp = n;
+ }
+ continue;
+ }
+#endif
+ if (MATCH(buf, "options")) {
+ res_setoptions(buf + sizeof("options") - 1, "conf");
+ continue;
+ }
+ }
+ if (nserv > 1)
+ _res.nscount = nserv;
+#ifdef RESOLVSORT
+ _res.nsort = nsort;
+#endif
+ (void) fclose(fp);
+ }
+ if (_res.defdname[0] == 0 &&
+ gethostname(buf, sizeof(_res.defdname) - 1) == 0 &&
+ (cp = strchr(buf, '.')) != NULL)
+ strcpy(_res.defdname, cp + 1);
+
+ /* find components of local domain that might be searched */
+ if (havesearch == 0) {
+ pp = _res.dnsrch;
+ *pp++ = _res.defdname;
+ *pp = NULL;
+
+#ifndef RFC1535
+ dots = 0;
+ for (cp = _res.defdname; *cp; cp++)
+ dots += (*cp == '.');
+
+ cp = _res.defdname;
+ while (pp < _res.dnsrch + MAXDFLSRCH) {
+ if (dots < LOCALDOMAINPARTS)
+ break;
+ cp = strchr(cp, '.') + 1; /* we know there is one */
+ *pp++ = cp;
+ dots--;
+ }
+ *pp = NULL;
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG) {
+ printf(";; res_init()... default dnsrch list:\n");
+ for (pp = _res.dnsrch; *pp; pp++)
+ printf(";;\t%s\n", *pp);
+ printf(";;\t..END..\n");
+ }
+#endif /* DEBUG */
+#endif /* !RFC1535 */
+ }
+
+ if ((cp = getenv("RES_OPTIONS")) != NULL)
+ res_setoptions(cp, "env");
+ _res.options |= RES_INIT;
+ return (0);
+}
+
+static void
+res_setoptions(options, source)
+ char *options, *source;
+{
+ char *cp = options;
+ int i;
+
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_setoptions(\"%s\", \"%s\")...\n",
+ options, source);
+#endif
+ while (*cp) {
+ /* skip leading and inner runs of spaces */
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ /* search for and process individual options */
+ if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
+ i = atoi(cp + sizeof("ndots:") - 1);
+ if (i <= RES_MAXNDOTS)
+ _res.ndots = i;
+ else
+ _res.ndots = RES_MAXNDOTS;
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";;\tndots=%d\n", _res.ndots);
+#endif
+ } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
+#ifdef DEBUG
+ if (!(_res.options & RES_DEBUG)) {
+ printf(";; res_setoptions(\"%s\", \"%s\")..\n",
+ options, source);
+ _res.options |= RES_DEBUG;
+ }
+ printf(";;\tdebug\n");
+#endif
+ } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
+ _res.options |= RES_USE_INET6;
+ } else {
+ /* XXX - print a warning here? */
+ }
+ /* skip to next run of spaces */
+ while (*cp && *cp != ' ' && *cp != '\t')
+ cp++;
+ }
+}
+
+#ifdef RESOLVSORT
+/* XXX - should really support CIDR which means explicit masks always. */
+static u_int32_t
+net_mask(in) /* XXX - should really use system's version of this */
+ struct in_addr in;
+{
+ register u_int32_t i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return (htonl(IN_CLASSA_NET));
+ else if (IN_CLASSB(i))
+ return (htonl(IN_CLASSB_NET));
+ return (htonl(IN_CLASSC_NET));
+}
+#endif
+
+u_int
+res_randomid()
+{
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
+}
diff --git a/lib/libc/net/res_mkquery.c b/lib/libc/net/res_mkquery.c
new file mode 100644
index 0000000..cfc9d33
--- /dev/null
+++ b/lib/libc/net/res_mkquery.c
@@ -0,0 +1,186 @@
+/*
+ * ++Copyright++ 1985, 1993
+ * -
+ * Copyright (c) 1985, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid[] = "From: Id: res_mkquery.c,v 8.5 1996/08/27 08:33:28 vixie Exp ";
+static char rcsid[] = "$Id$";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+
+#include "res_config.h"
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <string.h>
+
+
+/*
+ * Form all types of queries.
+ * Returns the size of the result or -1.
+ */
+int
+res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
+ int op; /* opcode of query */
+ const char *dname; /* domain name */
+ int class, type; /* class and type of query */
+ const u_char *data; /* resource record data */
+ int datalen; /* length of data */
+ const u_char *newrr_in; /* new rr for modify or append */
+ u_char *buf; /* buffer to put query */
+ int buflen; /* size of buffer */
+{
+ register HEADER *hp;
+ register u_char *cp;
+ register int n;
+ u_char *dnptrs[20], **dpp, **lastdnptr;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_mkquery(%d, %s, %d, %d)\n",
+ op, dname, class, type);
+#endif
+ /*
+ * Initialize header fields.
+ */
+ if ((buf == NULL) || (buflen < HFIXEDSZ))
+ return (-1);
+ bzero(buf, HFIXEDSZ);
+ hp = (HEADER *) buf;
+ hp->id = htons(++_res.id);
+ hp->opcode = op;
+ hp->rd = (_res.options & RES_RECURSE) != 0;
+ hp->rcode = NOERROR;
+ cp = buf + HFIXEDSZ;
+ buflen -= HFIXEDSZ;
+ dpp = dnptrs;
+ *dpp++ = buf;
+ *dpp++ = NULL;
+ lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
+ /*
+ * perform opcode specific processing
+ */
+ switch (op) {
+ case QUERY: /*FALLTHROUGH*/
+ case NS_NOTIFY_OP:
+ if ((buflen -= QFIXEDSZ) < 0)
+ return (-1);
+ if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
+ return (-1);
+ cp += n;
+ buflen -= n;
+ __putshort(type, cp);
+ cp += INT16SZ;
+ __putshort(class, cp);
+ cp += INT16SZ;
+ hp->qdcount = htons(1);
+ if (op == QUERY || data == NULL)
+ break;
+ /*
+ * Make an additional record for completion domain.
+ */
+ buflen -= RRFIXEDSZ;
+ n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ buflen -= n;
+ __putshort(T_NULL, cp);
+ cp += INT16SZ;
+ __putshort(class, cp);
+ cp += INT16SZ;
+ __putlong(0, cp);
+ cp += INT32SZ;
+ __putshort(0, cp);
+ cp += INT16SZ;
+ hp->arcount = htons(1);
+ break;
+
+ case IQUERY:
+ /*
+ * Initialize answer section
+ */
+ if (buflen < 1 + RRFIXEDSZ + datalen)
+ return (-1);
+ *cp++ = '\0'; /* no domain name */
+ __putshort(type, cp);
+ cp += INT16SZ;
+ __putshort(class, cp);
+ cp += INT16SZ;
+ __putlong(0, cp);
+ cp += INT32SZ;
+ __putshort(datalen, cp);
+ cp += INT16SZ;
+ if (datalen) {
+ bcopy(data, cp, datalen);
+ cp += datalen;
+ }
+ hp->ancount = htons(1);
+ break;
+
+ default:
+ return (-1);
+ }
+ return (cp - buf);
+}
diff --git a/lib/libc/net/res_query.c b/lib/libc/net/res_query.c
new file mode 100644
index 0000000..8110895
--- /dev/null
+++ b/lib/libc/net/res_query.c
@@ -0,0 +1,401 @@
+/*
+ * ++Copyright++ 1988, 1993
+ * -
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid = "From: Id: res_query.c,v 8.10 1997/06/01 20:34:37 vixie Exp";
+static char rcsid[] = "$Id: res_query.c,v 1.13 1997/03/24 06:11:44 imp Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "res_config.h"
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if PACKETSZ > 1024
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 1024
+#endif
+
+const char *hostalias __P((const char *));
+int h_errno;
+
+/*
+ * Formulate a normal query, send, and await answer.
+ * Returned answer is placed in supplied buffer "answer".
+ * Perform preliminary check of answer, returning success only
+ * if no error is indicated and the answer count is nonzero.
+ * Return the size of the response on success, -1 on error.
+ * Error number is left in h_errno.
+ *
+ * Caller must parse answer and determine whether it answers the question.
+ */
+int
+res_query(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 buffer */
+{
+ u_char buf[MAXPACKET];
+ register HEADER *hp = (HEADER *) answer;
+ int n;
+
+ hp->rcode = NOERROR; /* default */
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_query(%s, %d, %d)\n", name, class, type);
+#endif
+
+ n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL,
+ buf, sizeof(buf));
+ if (n <= 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_query: mkquery failed\n");
+#endif
+ h_errno = NO_RECOVERY;
+ return (n);
+ }
+ n = res_send(buf, n, answer, anslen);
+ if (n < 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_query: send error\n");
+#endif
+ h_errno = TRY_AGAIN;
+ return (n);
+ }
+
+ if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; rcode = %d, ancount=%d\n", hp->rcode,
+ ntohs(hp->ancount));
+#endif
+ switch (hp->rcode) {
+ case NXDOMAIN:
+ h_errno = HOST_NOT_FOUND;
+ break;
+ case SERVFAIL:
+ h_errno = TRY_AGAIN;
+ break;
+ case NOERROR:
+ h_errno = NO_DATA;
+ break;
+ case FORMERR:
+ case NOTIMP:
+ case REFUSED:
+ default:
+ h_errno = NO_RECOVERY;
+ break;
+ }
+ return (-1);
+ }
+ return (n);
+}
+
+/*
+ * Formulate a normal query, send, and retrieve answer in supplied buffer.
+ * Return the size of the response on success, -1 on error.
+ * 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 */
+{
+ register const char *cp, * const *domain;
+ HEADER *hp = (HEADER *) answer;
+ u_int dots;
+ int trailing_dot, ret, saved_herrno;
+ int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+ errno = 0;
+ h_errno = HOST_NOT_FOUND; /* default, if we never query */
+ dots = 0;
+ for (cp = name; *cp; cp++)
+ dots += (*cp == '.');
+ trailing_dot = 0;
+ if (cp > name && *--cp == '.')
+ trailing_dot++;
+
+ /*
+ * if there aren't any dots, it could be a user-level alias
+ */
+ if (!dots && (cp = __hostalias(name)) != NULL)
+ return (res_query(cp, class, type, answer, anslen));
+
+ /*
+ * 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) {
+ ret = res_querydomain(name, NULL, class, type, answer, anslen);
+ if (ret > 0)
+ return (ret);
+ saved_herrno = h_errno;
+ tried_as_is++;
+ }
+
+ /*
+ * We do at least one level of search if
+ * - there is no dot and RES_DEFNAME is set, or
+ * - 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++) {
+
+ ret = res_querydomain(name, *domain, class, type,
+ answer, anslen);
+ if (ret > 0)
+ return (ret);
+
+ /*
+ * If no server present, give up.
+ * If name isn't found in this domain,
+ * keep trying higher domains in the search list
+ * (if that's enabled).
+ * On a NO_DATA error, keep trying, otherwise
+ * a wildcard entry of another type could keep us
+ * from finding this entry higher in the domain.
+ * If we get some other error (negative answer or
+ * server failure), then stop searching up,
+ * but try the input name below in case it's
+ * fully-qualified.
+ */
+ if (errno == ECONNREFUSED) {
+ h_errno = TRY_AGAIN;
+ 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++;
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ /* anything else implies that we're done */
+ done++;
+ }
+
+ /* 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++;
+ }
+ }
+
+ /* if we have not already tried the name "as is", do that now.
+ * 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) {
+ ret = res_querydomain(name, NULL, class, type, answer, anslen);
+ if (ret > 0)
+ return (ret);
+ }
+
+ /* if we got here, we didn't satisfy the search.
+ * if we did an initial full query, return that query's h_errno
+ * (note that we wouldn't be here if that query had succeeded).
+ * else if we ever got a nodata, send that back as the reason.
+ * else send back meaningless h_errno, that being the one from
+ * the last DNSRCH we did.
+ */
+ if (saved_herrno != -1)
+ h_errno = saved_herrno;
+ else if (got_nodata)
+ h_errno = NO_DATA;
+ else if (got_servfail)
+ h_errno = TRY_AGAIN;
+ return (-1);
+}
+
+/*
+ * 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 */
+{
+ char nbuf[MAXDNAME];
+ const char *longname = nbuf;
+ int n, d;
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf(";; res_querydomain(%s, %s, %d, %d)\n",
+ name, domain?domain:"<Nil>", class, type);
+#endif
+ if (domain == NULL) {
+ /*
+ * Check for trailing '.';
+ * copy without '.' if present.
+ */
+ n = strlen(name);
+ if (n >= MAXDNAME) {
+ h_errno = NO_RECOVERY;
+ return (-1);
+ }
+ n--;
+ if (n >= 0 && name[n] == '.') {
+ strncpy(nbuf, name, n);
+ nbuf[n] = '\0';
+ } else
+ longname = name;
+ } else {
+ n = strlen(name);
+ d = strlen(domain);
+ if (n + d + 1 >= MAXDNAME) {
+ h_errno = NO_RECOVERY;
+ return (-1);
+ }
+ sprintf(nbuf, "%s.%s", name, domain);
+ }
+ return (res_query(longname, class, type, answer, anslen));
+}
+
+const char *
+hostalias(name)
+ register const char *name;
+{
+ register char *cp1, *cp2;
+ FILE *fp;
+ char *file;
+ char buf[BUFSIZ];
+ static char abuf[MAXDNAME];
+
+ if (_res.options & RES_NOALIASES)
+ return (NULL);
+ /* XXX issetguid() would be better here, but we don't have that. */
+ if (getuid() != geteuid() || getgid() != getegid())
+ return (NULL);
+ file = getenv("HOSTALIASES");
+ if (file == NULL || (fp = fopen(file, "r")) == NULL)
+ return (NULL);
+ setbuf(fp, NULL);
+ buf[sizeof(buf) - 1] = '\0';
+ while (fgets(buf, sizeof(buf), fp)) {
+ for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1)
+ ;
+ if (!*cp1)
+ break;
+ *cp1 = '\0';
+ if (!strcasecmp(buf, name)) {
+ while (isspace(*++cp1))
+ ;
+ if (!*cp1)
+ break;
+ for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2)
+ ;
+ abuf[sizeof(abuf) - 1] = *cp2 = '\0';
+ strncpy(abuf, cp1, sizeof(abuf) - 1);
+ fclose(fp);
+ return (abuf);
+ }
+ }
+ fclose(fp);
+ return (NULL);
+}
diff --git a/lib/libc/net/res_send.c b/lib/libc/net/res_send.c
new file mode 100644
index 0000000..9061ec6
--- /dev/null
+++ b/lib/libc/net/res_send.c
@@ -0,0 +1,767 @@
+/*
+ * ++Copyright++ 1985, 1989, 1993
+ * -
+ * Copyright (c) 1985, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
+static char orig_rcsid[] = "From: Id: res_send.c,v 8.13 1997/06/01 20:34:37 vixie Exp";
+static char rcsid[] = "$Id: res_send.c,v 1.17 1997/06/27 13:00:51 peter Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * Send query to name server and wait for reply.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "res_config.h"
+#include <arpa/nameser.h>
+
+#include <stdio.h>
+#include <netdb.h>
+#include <errno.h>
+#include <resolv.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static int s = -1; /* socket used for communications */
+static int connected = 0; /* is the socket connected */
+static int vc = 0; /* is the socket a virtual ciruit? */
+
+#define CAN_RECONNECT 1
+
+#ifndef DEBUG
+# define Dprint(cond, args) /*empty*/
+# define DprintQ(cond, args, query, size) /*empty*/
+# define Aerror(file, string, error, address) /*empty*/
+# define Perror(file, string, error) /*empty*/
+#else
+# define Dprint(cond, args) if (cond) {fprintf args;} else {}
+# define DprintQ(cond, args, query, size) if (cond) {\
+ fprintf args;\
+ __fp_nquery(query, size, stdout);\
+ } else {}
+ static void
+ Aerror(file, string, error, address)
+ FILE *file;
+ char *string;
+ int error;
+ struct sockaddr_in address;
+ {
+ int save = errno;
+
+ if (_res.options & RES_DEBUG) {
+ fprintf(file, "res_send: %s ([%s].%u): %s\n",
+ string,
+ inet_ntoa(address.sin_addr),
+ ntohs(address.sin_port),
+ strerror(error));
+ }
+ errno = save;
+ }
+ static void
+ Perror(file, string, error)
+ FILE *file;
+ char *string;
+ int error;
+ {
+ int save = errno;
+
+ if (_res.options & RES_DEBUG) {
+ fprintf(file, "res_send: %s: %s\n",
+ string, strerror(error));
+ }
+ errno = save;
+ }
+#endif
+
+static res_send_qhook Qhook = NULL;
+static res_send_rhook Rhook = NULL;
+
+void
+res_send_setqhook(hook)
+ res_send_qhook hook;
+{
+
+ Qhook = hook;
+}
+
+void
+res_send_setrhook(hook)
+ res_send_rhook hook;
+{
+
+ Rhook = hook;
+}
+
+/* int
+ * res_isourserver(ina)
+ * looks up "ina" in _res.ns_addr_list[]
+ * returns:
+ * 0 : not found
+ * >0 : found
+ * author:
+ * paul vixie, 29may94
+ */
+int
+res_isourserver(inp)
+ const struct sockaddr_in *inp;
+{
+ struct sockaddr_in ina;
+ register int ns, ret;
+
+ ina = *inp;
+ ret = 0;
+ for (ns = 0; ns < _res.nscount; ns++) {
+ register const struct sockaddr_in *srv = &_res.nsaddr_list[ns];
+
+ if (srv->sin_family == ina.sin_family &&
+ srv->sin_port == ina.sin_port &&
+ (srv->sin_addr.s_addr == INADDR_ANY ||
+ srv->sin_addr.s_addr == ina.sin_addr.s_addr)) {
+ ret++;
+ break;
+ }
+ }
+ return (ret);
+}
+
+/* int
+ * res_nameinquery(name, type, class, buf, eom)
+ * look for (name,type,class) in the query section of packet (buf,eom)
+ * returns:
+ * -1 : format error
+ * 0 : not found
+ * >0 : found
+ * author:
+ * paul vixie, 29may94
+ */
+int
+res_nameinquery(name, type, class, buf, eom)
+ const char *name;
+ register int type, class;
+ const u_char *buf, *eom;
+{
+ register const u_char *cp = buf + HFIXEDSZ;
+ int qdcount = ntohs(((HEADER*)buf)->qdcount);
+
+ while (qdcount-- > 0) {
+ char tname[MAXDNAME+1];
+ register int n, ttype, tclass;
+
+ n = dn_expand(buf, eom, cp, tname, sizeof tname);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ ttype = _getshort(cp); cp += INT16SZ;
+ tclass = _getshort(cp); cp += INT16SZ;
+ if (ttype == type &&
+ tclass == class &&
+ strcasecmp(tname, name) == 0)
+ return (1);
+ }
+ return (0);
+}
+
+/* int
+ * res_queriesmatch(buf1, eom1, buf2, eom2)
+ * is there a 1:1 mapping of (name,type,class)
+ * in (buf1,eom1) and (buf2,eom2)?
+ * returns:
+ * -1 : format error
+ * 0 : not a 1:1 mapping
+ * >0 : is a 1:1 mapping
+ * author:
+ * paul vixie, 29may94
+ */
+int
+res_queriesmatch(buf1, eom1, buf2, eom2)
+ const u_char *buf1, *eom1;
+ const u_char *buf2, *eom2;
+{
+ register const u_char *cp = buf1 + HFIXEDSZ;
+ int qdcount = ntohs(((HEADER*)buf1)->qdcount);
+
+ if (qdcount != ntohs(((HEADER*)buf2)->qdcount))
+ return (0);
+ while (qdcount-- > 0) {
+ char tname[MAXDNAME+1];
+ register int n, ttype, tclass;
+
+ n = dn_expand(buf1, eom1, cp, tname, sizeof tname);
+ if (n < 0)
+ return (-1);
+ cp += n;
+ ttype = _getshort(cp); cp += INT16SZ;
+ tclass = _getshort(cp); cp += INT16SZ;
+ if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
+ return (0);
+ }
+ return (1);
+}
+
+int
+res_send(buf, buflen, ans, anssiz)
+ const u_char *buf;
+ int buflen;
+ u_char *ans;
+ int anssiz;
+{
+ HEADER *hp = (HEADER *) buf;
+ HEADER *anhp = (HEADER *) ans;
+ int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns;
+ register int n;
+ u_int badns; /* XXX NSMAX can't exceed #/bits in this var */
+
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ /* errno should have been set by res_init() in this case. */
+ return (-1);
+ }
+ DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY),
+ (stdout, ";; res_send()\n"), buf, buflen);
+ v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ;
+ gotsomewhere = 0;
+ connreset = 0;
+ terrno = ETIMEDOUT;
+ badns = 0;
+
+ /*
+ * Send request, RETRY times, or until successful
+ */
+ for (try = 0; try < _res.retry; try++) {
+ for (ns = 0; ns < _res.nscount; ns++) {
+ struct sockaddr_in *nsap = &_res.nsaddr_list[ns];
+ same_ns:
+ if (badns & (1 << ns)) {
+ res_close();
+ goto next_ns;
+ }
+
+ if (Qhook) {
+ int done = 0, loops = 0;
+
+ do {
+ res_sendhookact act;
+
+ act = (*Qhook)(&nsap, &buf, &buflen,
+ ans, anssiz, &resplen);
+ switch (act) {
+ case res_goahead:
+ done = 1;
+ break;
+ case res_nextns:
+ res_close();
+ goto next_ns;
+ case res_done:
+ return (resplen);
+ case res_modified:
+ /* give the hook another try */
+ if (++loops < 42) /*doug adams*/
+ break;
+ /*FALLTHROUGH*/
+ case res_error:
+ /*FALLTHROUGH*/
+ default:
+ return (-1);
+ }
+ } while (!done);
+ }
+
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; Querying server (# %d) address = %s\n",
+ ns + 1, inet_ntoa(nsap->sin_addr)));
+
+ if (v_circuit) {
+ int truncated;
+ struct iovec iov[2];
+ u_short len;
+ u_char *cp;
+
+ /*
+ * Use virtual circuit;
+ * at most one attempt per server.
+ */
+ try = _res.retry;
+ truncated = 0;
+ if ((s < 0) || (!vc)) {
+ if (s >= 0)
+ res_close();
+
+ s = socket(PF_INET, SOCK_STREAM, 0);
+ if (s < 0) {
+ terrno = errno;
+ Perror(stderr, "socket(vc)", errno);
+ return (-1);
+ }
+ errno = 0;
+ if (connect(s, (struct sockaddr *)nsap,
+ sizeof(struct sockaddr)) < 0) {
+ terrno = errno;
+ Aerror(stderr, "connect/vc",
+ errno, *nsap);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ vc = 1;
+ }
+ /*
+ * Send length & message
+ */
+ putshort((u_short)buflen, (u_char*)&len);
+ iov[0].iov_base = (caddr_t)&len;
+ iov[0].iov_len = INT16SZ;
+ iov[1].iov_base = (caddr_t)buf;
+ iov[1].iov_len = buflen;
+ if (writev(s, iov, 2) != (INT16SZ + buflen)) {
+ terrno = errno;
+ Perror(stderr, "write failed", errno);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ /*
+ * Receive length & response
+ */
+read_len:
+ cp = ans;
+ len = INT16SZ;
+ while ((n = read(s, (char *)cp, (int)len)) > 0) {
+ cp += n;
+ if ((len -= n) <= 0)
+ break;
+ }
+ if (n <= 0) {
+ terrno = errno;
+ Perror(stderr, "read failed", errno);
+ res_close();
+ /*
+ * A long running process might get its TCP
+ * connection reset if the remote server was
+ * restarted. Requery the server instead of
+ * trying a new one. When there is only one
+ * server, this means that a query might work
+ * instead of failing. We only allow one reset
+ * per query to prevent looping.
+ */
+ if (terrno == ECONNRESET && !connreset) {
+ connreset = 1;
+ res_close();
+ goto same_ns;
+ }
+ res_close();
+ goto next_ns;
+ }
+ resplen = _getshort(ans);
+ if (resplen > anssiz) {
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; response truncated\n")
+ );
+ truncated = 1;
+ len = anssiz;
+ } else
+ len = resplen;
+ cp = ans;
+ while (len != 0 &&
+ (n = read(s, (char *)cp, (int)len)) > 0) {
+ cp += n;
+ len -= n;
+ }
+ if (n <= 0) {
+ terrno = errno;
+ Perror(stderr, "read(vc)", errno);
+ res_close();
+ goto next_ns;
+ }
+ if (truncated) {
+ /*
+ * Flush rest of answer
+ * so connection stays in synch.
+ */
+ anhp->tc = 1;
+ len = resplen - anssiz;
+ while (len != 0) {
+ char junk[PACKETSZ];
+
+ n = (len > sizeof(junk)
+ ? sizeof(junk)
+ : len);
+ if ((n = read(s, junk, n)) > 0)
+ len -= n;
+ else
+ break;
+ }
+ }
+ /*
+ * The calling applicating has bailed out of
+ * a previous call and failed to arrange to have
+ * the circuit closed or the server has got
+ * itself confused. Anyway drop the packet and
+ * wait for the correct one.
+ */
+ if (hp->id != anhp->id) {
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; old answer (unexpected):\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto read_len;
+ }
+ } else {
+ /*
+ * Use datagrams.
+ */
+ struct timeval timeout;
+ fd_set dsmask, *dsmaskp;
+ int dsmasklen;
+ struct sockaddr_in from;
+ int fromlen;
+
+ if ((s < 0) || vc) {
+ if (vc)
+ res_close();
+ s = socket(PF_INET, SOCK_DGRAM, 0);
+ if (s < 0) {
+#if !CAN_RECONNECT
+ bad_dg_sock:
+#endif
+ terrno = errno;
+ Perror(stderr, "socket(dg)", errno);
+ return (-1);
+ }
+ connected = 0;
+ }
+ /*
+ * On a 4.3BSD+ machine (client and server,
+ * actually), sending to a nameserver datagram
+ * port with no nameserver will cause an
+ * ICMP port unreachable message to be returned.
+ * If our datagram socket is "connected" to the
+ * server, we get an ECONNREFUSED error on the next
+ * socket operation, and select returns if the
+ * error message is received. We can thus detect
+ * the absence of a nameserver without timing out.
+ * If we have sent queries to at least two servers,
+ * however, we don't want to remain connected,
+ * as we wish to receive answers from the first
+ * server to respond.
+ */
+ if (_res.nscount == 1 || (try == 0 && ns == 0)) {
+ /*
+ * Connect only if we are sure we won't
+ * receive a response from another server.
+ */
+ if (!connected) {
+ if (connect(s, (struct sockaddr *)nsap,
+ sizeof(struct sockaddr)
+ ) < 0) {
+ Aerror(stderr,
+ "connect(dg)",
+ errno, *nsap);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ connected = 1;
+ }
+ if (send(s, (char*)buf, buflen, 0) != buflen) {
+ Perror(stderr, "send", errno);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ } else {
+ /*
+ * Disconnect if we want to listen
+ * for responses from more than one server.
+ */
+ if (connected) {
+#if CAN_RECONNECT
+ struct sockaddr_in no_addr;
+
+ no_addr.sin_family = AF_INET;
+ no_addr.sin_addr.s_addr = INADDR_ANY;
+ no_addr.sin_port = 0;
+ (void) connect(s,
+ (struct sockaddr *)
+ &no_addr,
+ sizeof(no_addr));
+#else
+ int s1 = socket(PF_INET, SOCK_DGRAM,0);
+ if (s1 < 0)
+ goto bad_dg_sock;
+ (void) dup2(s1, s);
+ (void) close(s1);
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; new DG socket\n"))
+#endif
+ connected = 0;
+ errno = 0;
+ }
+ if (sendto(s, (char*)buf, buflen, 0,
+ (struct sockaddr *)nsap,
+ sizeof(struct sockaddr))
+ != buflen) {
+ Aerror(stderr, "sendto", errno, *nsap);
+ badns |= (1 << ns);
+ res_close();
+ goto next_ns;
+ }
+ }
+
+ /*
+ * Wait for reply
+ */
+ timeout.tv_sec = (_res.retrans << try);
+ if (try > 0)
+ timeout.tv_sec /= _res.nscount;
+ if ((long) timeout.tv_sec <= 0)
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+ wait:
+ dsmasklen = howmany(s+1, NFDBITS) * sizeof(fd_mask);
+ if (dsmasklen > sizeof(fd_set)) {
+ dsmaskp = (fd_set *)malloc(dsmasklen);
+ if (dsmaskp == NULL) {
+ res_close();
+ goto next_ns;
+ }
+ } else
+ dsmaskp = &dsmask;
+ /* only zero what we need */
+ bzero((char *)dsmaskp, dsmasklen);
+ FD_SET(s, dsmaskp);
+ n = select(s+1, dsmaskp, (fd_set *)NULL,
+ (fd_set *)NULL, &timeout);
+ if (dsmaskp != &dsmask)
+ free(dsmaskp);
+ if (n < 0) {
+ if (errno == EINTR)
+ goto wait;
+ Perror(stderr, "select", errno);
+ res_close();
+ goto next_ns;
+ }
+ if (n == 0) {
+ /*
+ * timeout
+ */
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; timeout\n"));
+ gotsomewhere = 1;
+ res_close();
+ goto next_ns;
+ }
+ errno = 0;
+ fromlen = sizeof(struct sockaddr_in);
+ resplen = recvfrom(s, (char*)ans, anssiz, 0,
+ (struct sockaddr *)&from, &fromlen);
+ if (resplen <= 0) {
+ Perror(stderr, "recvfrom", errno);
+ res_close();
+ goto next_ns;
+ }
+ gotsomewhere = 1;
+ if (hp->id != anhp->id) {
+ /*
+ * response from old query, ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; old answer:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto wait;
+ }
+#if CHECK_SRVR_ADDR
+ if (!(_res.options & RES_INSECURE1) &&
+ !res_isourserver(&from)) {
+ /*
+ * response from wrong server? ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; not our server:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto wait;
+ }
+#endif
+ if (!(_res.options & RES_INSECURE2) &&
+ !res_queriesmatch(buf, buf + buflen,
+ ans, ans + anssiz)) {
+ /*
+ * response contains wrong query? ignore it.
+ * XXX - potential security hazard could
+ * be detected here.
+ */
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ";; wrong query name:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ goto wait;
+ }
+ if (anhp->rcode == SERVFAIL ||
+ anhp->rcode == NOTIMP ||
+ anhp->rcode == REFUSED) {
+ DprintQ(_res.options & RES_DEBUG,
+ (stdout, "server rejected query:\n"),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ badns |= (1 << ns);
+ res_close();
+ /* don't retry if called from dig */
+ if (!_res.pfcode)
+ goto next_ns;
+ }
+ if (!(_res.options & RES_IGNTC) && anhp->tc) {
+ /*
+ * get rest of answer;
+ * use TCP with same server.
+ */
+ Dprint(_res.options & RES_DEBUG,
+ (stdout, ";; truncated answer\n"));
+ v_circuit = 1;
+ res_close();
+ goto same_ns;
+ }
+ } /*if vc/dg*/
+ Dprint((_res.options & RES_DEBUG) ||
+ ((_res.pfcode & RES_PRF_REPLY) &&
+ (_res.pfcode & RES_PRF_HEAD1)),
+ (stdout, ";; got answer:\n"));
+ DprintQ((_res.options & RES_DEBUG) ||
+ (_res.pfcode & RES_PRF_REPLY),
+ (stdout, ""),
+ ans, (resplen>anssiz)?anssiz:resplen);
+ /*
+ * If using virtual circuits, we assume that the first server
+ * is preferred over the rest (i.e. it is on the local
+ * machine) and only keep that one open.
+ * If we have temporarily opened a virtual circuit,
+ * or if we haven't been asked to keep a socket open,
+ * close the socket.
+ */
+ if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) ||
+ !(_res.options & RES_STAYOPEN)) {
+ res_close();
+ }
+ if (Rhook) {
+ int done = 0, loops = 0;
+
+ do {
+ res_sendhookact act;
+
+ act = (*Rhook)(nsap, buf, buflen,
+ ans, anssiz, &resplen);
+ switch (act) {
+ case res_goahead:
+ case res_done:
+ done = 1;
+ break;
+ case res_nextns:
+ res_close();
+ goto next_ns;
+ case res_modified:
+ /* give the hook another try */
+ if (++loops < 42) /*doug adams*/
+ break;
+ /*FALLTHROUGH*/
+ case res_error:
+ /*FALLTHROUGH*/
+ default:
+ return (-1);
+ }
+ } while (!done);
+
+ }
+ return (resplen);
+ next_ns: ;
+ } /*foreach ns*/
+ } /*foreach retry*/
+ res_close();
+ if (!v_circuit)
+ if (!gotsomewhere)
+ errno = ECONNREFUSED; /* no nameservers found */
+ else
+ errno = ETIMEDOUT; /* no answer obtained */
+ else
+ errno = terrno;
+ return (-1);
+}
+
+/*
+ * This routine is for closing the socket if a virtual circuit is used and
+ * the program wants to close it. This provides support for endhostent()
+ * which expects to close the socket.
+ *
+ * This routine is not expected to be user visible.
+ */
+void
+res_close()
+{
+ if (s >= 0) {
+ (void) close(s);
+ s = -1;
+ connected = 0;
+ vc = 0;
+ }
+}
diff --git a/lib/libc/net/res_stubs.c b/lib/libc/net/res_stubs.c
new file mode 100644
index 0000000..e156608
--- /dev/null
+++ b/lib/libc/net/res_stubs.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 1996 Peter Wemm <peter@freebsd.org>.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $Id: res_stubs.c,v 1.5 1997/02/22 15:00:36 peter Exp $
+ */
+
+/*
+ * This file is for FreeBSD-3.0 that has a bind-4.9.5-P1 derived
+ * resolver in the libc. It provides aliases for functions that
+ * have moved since 4.9.4-P1.
+ *
+ * I'll save everybody the trouble and say it now: *THIS IS A HACK*!
+ *
+ * Yes, many of these are private functions to the resolver, but some are
+ * needed as there is no other way to provide the functionality and they've
+ * turned up all over the place. :-(
+ */
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+
+__weak_reference(__sym_ston, sym_ston);
+__weak_reference(__sym_ntos, sym_ntos);
+__weak_reference(__sym_ntop, sym_ntop);
+__weak_reference(__fp_resstat, fp_resstat);
+__weak_reference(__p_query, p_query);
+__weak_reference(__p_fqnname, p_fqnname);
+__weak_reference(__p_secstodate, p_secstodate);
+__weak_reference(__dn_count_labels, dn_count_labels);
+__weak_reference(__dn_comp, dn_comp);
+__weak_reference(__res_close, _res_close);
+#ifdef BIND_RES_POSIX3
+__weak_reference(__dn_expand, dn_expand);
+__weak_reference(__res_init, res_init);
+__weak_reference(__res_query, res_query);
+__weak_reference(__res_search, res_search);
+__weak_reference(__res_querydomain, res_querydomain);
+__weak_reference(__res_mkquery, res_mkquery);
+__weak_reference(__res_send, res_send);
+#else
+__weak_reference(res_send, __res_send);
+#endif
diff --git a/lib/libc/net/resolver.3 b/lib/libc/net/resolver.3
index 4014c72..6d210c3 100644
--- a/lib/libc/net/resolver.3
+++ b/lib/libc/net/resolver.3
@@ -48,50 +48,56 @@
.Fd #include <netinet/in.h>
.Fd #include <arpa/nameser.h>
.Fd #include <resolv.h>
+.Ft int
.Fo res_query
-.Fa "char *dname"
+.Fa "const char *dname"
.Fa "int class"
.Fa "int type"
.Fa "u_char *answer"
.Fa "int anslen"
.Fc
+.Ft int
.Fo res_search
-.Fa "char *dname"
+.Fa "const char *dname"
.Fa "int class"
.Fa "int type"
.Fa "u_char *answer"
.Fa "int anslen"
.Fc
+.Ft int
.Fo res_mkquery
.Fa "int op"
-.Fa "char *dname"
+.Fa "const char *dname"
.Fa "int class"
.Fa "int type"
-.Fa "char *data"
+.Fa "const u_char *data"
.Fa "int datalen"
-.Fa "struct rrec *newrr"
-.Fa "char *buf"
+.Fa "const u_char *newrr_in"
+.Fa "u_char *buf"
.Fa "int buflen"
.Fc
+.Ft int
.Fo res_send
-.Fa "char *msg"
+.Fa "const char *msg"
.Fa "int msglen"
.Fa "char *answer"
.Fa "int anslen"
.Fc
+.Ft int
.Fn res_init
.Fo dn_comp
-.Fa "char *exp_dn"
+.Fa "const char *exp_dn"
.Fa "char *comp_dn"
.Fa "int length"
.Fa "char **dnptrs"
.Fa "char **lastdnptr"
.Fc
+.Ft int
.Fo dn_expand
-.Fa "u_char *msg"
-.Fa "u_char *eomorig"
-.Fa "u_char *comp_dn"
-.Fa "u_char *exp_dn"
+.Fa "const u_char *msg"
+.Fa "const u_char *eomorig"
+.Fa "const u_char *comp_dn"
+.Fa "char *exp_dn"
.Fa "int length"
.Fc
.Sh DESCRIPTION
@@ -163,6 +169,10 @@ will search for host names in the current domain and in parent domains; see
This is used by the standard host lookup routine
.Xr gethostbyname 3 .
This option is enabled by default.
+.It Dv RES_NOALIASES
+This option turns off the user level aliasing feature controlled by the
+.Dq Ev HOSTALIASES
+environment variable. Network daemons should set this option.
.El
.Pp
The
@@ -179,6 +189,24 @@ The current domain name is defined by the hostname
if not specified in the configuration file;
it can be overridden by the environment variable
.Ev LOCALDOMAIN .
+This environment variable may contain several blank-separated
+tokens if you wish to override the
+.Em "search list"
+on a per-process basis. This is similar to the
+.Em search
+command in the configuration file.
+Another environment variable (
+.Dq Ev RES_OPTIONS
+can be set to
+override certain internal resolver options which are otherwise
+set by changing fields in the
+.Em _res
+structure or are inherited from the configuration file's
+.Em options
+command. The syntax of the
+.Dq Ev RES_OPTIONS
+environment variable is explained in
+.Xr resolver 5 .
Initialization normally occurs on the first call
to one of the following routines.
.Pp
@@ -304,9 +332,9 @@ see
.El
.Sh SEE ALSO
.Xr gethostbyname 3 ,
-.Xr named 8 ,
.Xr resolver 5 ,
.Xr hostname 7 ,
+.Xr named 8
.Pp
.%T RFC1032 ,
.%T RFC1033 ,
diff --git a/lib/libc/nls/Makefile.inc b/lib/libc/nls/Makefile.inc
new file mode 100644
index 0000000..6d2acea
--- /dev/null
+++ b/lib/libc/nls/Makefile.inc
@@ -0,0 +1,11 @@
+# from $NetBSD: Makefile.inc,v 1.7 1995/02/27 13:06:20 cgd Exp $
+# $Id$
+
+.PATH: ${.CURDIR}/../libc/nls
+
+SRCS+= catclose.c catgets.c catopen.c msgcat.c
+
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN3+= nls/catclose.3 nls/catgets.3 nls/catopen.3
+.endif
diff --git a/lib/libc/nls/catclose.3 b/lib/libc/nls/catclose.3
new file mode 100644
index 0000000..e4757bd
--- /dev/null
+++ b/lib/libc/nls/catclose.3
@@ -0,0 +1,54 @@
+.\" $Id$
+.\"
+.\" Copyright (c) 1994 Winning Strategies, Inc.
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Winning Strategies, Inc.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"
+.Dd May 29, 1994
+.Dt CATCLOSE 3
+.Os
+.Sh NAME
+.Nm catclose
+.Nd close message catalog
+.Sh SYNOPSIS
+.Fd #include <nl_types.h>
+.Ft int
+.Fn catclose "nl_catd catd"
+.Sh DESCRIPTION
+The
+.Fn catclose
+function closes the message catalog specified by the argument
+.Fa catd .
+.Sh SEE ALSO
+.Xr catgets 3 ,
+.Xr catopen 3
+.Sh STANDARDS
+The
+.Fn catclose
+function conforms to
+.St -xpg3 .
+
diff --git a/lib/libc/nls/catclose.c b/lib/libc/nls/catclose.c
new file mode 100644
index 0000000..341f664
--- /dev/null
+++ b/lib/libc/nls/catclose.c
@@ -0,0 +1,25 @@
+/* $Id$ */
+
+/*
+ * Written by J.T. Conklin, 10/05/94
+ * Public domain.
+ */
+
+#include <sys/cdefs.h>
+
+#ifdef __indr_reference
+__indr_reference(_catclose,catclose);
+#else
+
+#include <nl_types.h>
+
+extern int _catclose __P((nl_catd));
+
+int
+catclose(catd)
+ nl_catd catd;
+{
+ return _catclose(catd);
+}
+
+#endif
diff --git a/lib/libc/nls/catgets.3 b/lib/libc/nls/catgets.3
new file mode 100644
index 0000000..b50f8a4
--- /dev/null
+++ b/lib/libc/nls/catgets.3
@@ -0,0 +1,66 @@
+.\" $Id$
+.\"
+.\" Copyright (c) 1994 Winning Strategies, Inc.
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Winning Strategies, Inc.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"
+.Dd May 29, 1994
+.Dt CATGETS 3
+.Os
+.Sh NAME
+.Nm catgets
+.Nd retrieve string from message catalog
+.Sh SYNOPSIS
+.Fd #include <nl_types.h>
+.Ft char *
+.Fn catgets "nl_catd catd" "int set_id" "int msg_id" "char *s"
+.Sh DESCRIPTION
+The
+.Fn catgets
+function attempts to retrieve message
+.Fa msg_id
+of set
+.Fa set_id
+from the message catalog referenced by the descriptor
+.Fa catd .
+The argument
+.Fa s
+points to a default message which is returned if the function
+is unable to retrieve the specified message.
+.Sh RETURN VALUE
+If the specified message was retrieved successfully,
+.Fn catgets
+returns a pointer to an internal buffer containing the message string;
+otherwise it returns
+.Fa s .
+.Sh SEE ALSO
+.Xr catclose 3 ,
+.Xr catopen 3
+.Sh STANDARDS
+The
+.Fn catgets
+function conforms to \fBxpg3\fR.
diff --git a/lib/libc/nls/catgets.c b/lib/libc/nls/catgets.c
new file mode 100644
index 0000000..c29cf64
--- /dev/null
+++ b/lib/libc/nls/catgets.c
@@ -0,0 +1,28 @@
+/* $Id$ */
+
+/*
+ * Written by J.T. Conklin, 10/05/94
+ * Public domain.
+ */
+
+#include <sys/cdefs.h>
+
+#ifdef __indr_reference
+__indr_reference(_catgets,catgets);
+#else
+
+#include <nl_types.h>
+
+extern char * _catgets __P((nl_catd, int, int, char *));
+
+char *
+catgets(catd, set_id, msg_id, s)
+ nl_catd catd;
+ int set_id;
+ int msg_id;
+ char *s;
+{
+ return _catgets(catd, set_id, msg_id, s);
+}
+
+#endif
diff --git a/lib/libc/nls/catopen.3 b/lib/libc/nls/catopen.3
new file mode 100644
index 0000000..a792ebd
--- /dev/null
+++ b/lib/libc/nls/catopen.3
@@ -0,0 +1,82 @@
+.\" $Id$
+.\"
+.\" Copyright (c) 1994 Winning Strategies, Inc.
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Winning Strategies, Inc.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"
+.Dd May 29, 1994
+.Dt CATOPEN 3
+.Os
+.Sh NAME
+.Nm catopen
+.Nd open message catalog
+.Sh SYNOPSIS
+.Fd #include <nl_types.h>
+.Ft nl_catd
+.Fn catopen "const char *name" "int oflag"
+.Sh DESCRIPTION
+The
+.Fn catopen
+function opens the message catalog specified by
+.Fa name
+and returns a message catalog descriptor.
+If
+.Fa name
+contains a
+.Sq /
+then
+.Fa name
+specifies the full pathname for the message catalog, otherwise the value
+of the environment variable
+.Ev NLSPATH
+is used with
+.Fa name
+substituted for %N.
+.Pp
+The
+.Fa oflag
+argument is reserved for future use and should be set to zero.
+.Sh RETURN VALUE
+Upon successful completion,
+.Fn catopen
+returns a message catalog descriptor.
+Otherwise, (nl_catd) -1 is returned and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er ENOMEM
+Insufficient memory is available.
+.El
+.Sh SEE ALSO
+.Xr catclose 3 ,
+.Xr catgets 3
+.Sh STANDARDS
+The
+.Fn catopen
+function conforms to
+.St -xpg3 .
diff --git a/lib/libc/nls/catopen.c b/lib/libc/nls/catopen.c
new file mode 100644
index 0000000..5dfb727
--- /dev/null
+++ b/lib/libc/nls/catopen.c
@@ -0,0 +1,26 @@
+/* $Id$ */
+
+/*
+ * Written by J.T. Conklin, 10/05/94
+ * Public domain.
+ */
+
+#include <sys/cdefs.h>
+
+#ifdef __indr_reference
+__indr_reference(_catopen,catopen);
+#else
+
+#include <nl_types.h>
+
+extern nl_catd _catopen __P((__const char *, int));
+
+nl_catd
+catopen(name, oflag)
+ __const char *name;
+ int oflag;
+{
+ return _catopen(name, oflag);
+}
+
+#endif
diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c
new file mode 100644
index 0000000..c90cefb
--- /dev/null
+++ b/lib/libc/nls/msgcat.c
@@ -0,0 +1,428 @@
+/* $Id: msgcat.c,v 1.10 1997/05/10 04:28:17 ache Exp $ */
+
+/***********************************************************
+Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that Alfalfa's name not be used in
+advertising or publicity pertaining to distribution of the software
+without specific, written prior permission.
+
+ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+If you make any modifications, bugfixes or other changes to this software
+we'd appreciate it if you could send a copy to us so we can keep things
+up-to-date. Many thanks.
+ Kee Hinckley
+ Alfalfa Software, Inc.
+ 267 Allston St., #3
+ Cambridge, MA 02139 USA
+ nazgul@alfalfa.com
+
+******************************************************************/
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$NetBSD: msgcat.c,v 1.11 1995/02/27 13:06:51 cgd Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+/* Edit History
+
+03/06/91 4 schulert remove working directory from nlspath
+01/18/91 2 hamilton #if not rescanned
+01/12/91 3 schulert conditionally use prototypes
+11/03/90 1 hamilton Alphalpha->Alfalfa & OmegaMail->Poste
+10/15/90 2 schulert > #include <unistd.h> if MIPS
+08/13/90 1 schulert move from ua to omu
+*/
+
+/*
+ * We need a better way of handling errors than printing text. I need
+ * to add an error handling routine.
+ */
+
+#include "nl_types.h"
+#include "msgcat.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifndef True
+# define True ~0
+# define False 0
+#endif
+
+/* take care of sysv diffs */
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 1024
+#endif
+
+#ifndef FD_CLOEXEC
+#define FD_CLOEXEC 1
+#endif
+
+#define NLERR ((nl_catd) -1)
+
+static nl_catd loadCat();
+static nl_catd loadSet();
+
+nl_catd _catopen( name, type)
+__const char *name;
+int type;
+{
+ char path[MAXPATHLEN];
+ __const char *catpath = NULL;
+ char *nlspath;
+ char *lang;
+ long len;
+ char *base, *cptr, *pathP;
+ struct stat sbuf;
+
+ if (!name || !*name) return(NLERR);
+
+ if (strchr(name, '/')) {
+ catpath = name;
+ if (stat(catpath, &sbuf)) return(0);
+ } else {
+ if ((lang = (char *) getenv("LANG")) == NULL)
+ lang = "C";
+ if ((nlspath = (char *) getenv("NLSPATH")) == NULL || issetugid())
+ nlspath = "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L:/usr/local/share/nls/%L/%N.cat:/usr/local/share/nls/%N/%L";
+
+ len = strlen(nlspath);
+ base = cptr = (char *) malloc(len + 2);
+ if (!base) return(NLERR);
+ strcpy(cptr, nlspath);
+ cptr[len] = ':';
+ cptr[len+1] = '\0';
+
+ for (nlspath = cptr; *cptr; ++cptr) {
+ if (*cptr == ':') {
+ *cptr = '\0';
+ for (pathP = path; *nlspath; ++nlspath) {
+ if (*nlspath == '%') {
+ if (*(nlspath + 1) == 'L') {
+ ++nlspath;
+ strcpy(pathP, lang);
+ pathP += strlen(lang);
+ } else if (*(nlspath + 1) == 'N') {
+ ++nlspath;
+ strcpy(pathP, name);
+ pathP += strlen(name);
+ } else *(pathP++) = *nlspath;
+ } else *(pathP++) = *nlspath;
+ }
+ *pathP = '\0';
+ if (stat(path, &sbuf) == 0) {
+ catpath = path;
+ break;
+ }
+ nlspath = cptr+1;
+ }
+ }
+ free(base);
+
+ if (!catpath) return(0);
+ }
+
+ return(loadCat(catpath, type));
+}
+
+/*
+ * We've got an odd situation here. The odds are real good that the
+ * number we are looking for is almost the same as the index. We could
+ * use the index, check the difference and do something intelligent, but
+ * I haven't quite figured out what's intelligent.
+ *
+ * Here's a start.
+ * Take an id N. If there are > N items in the list, then N cannot
+ * be more than N items from the start, since otherwise there would
+ * have to be duplicate items. So we can safely set the top to N+1
+ * (after taking into account that ids start at 1, and arrays at 0)
+ *
+ * Let's say we are at position P, and we are looking for N, but have
+ * V. If N > V, then the furthest away that N could be is
+ * P + (N-V). So we can safely set hi to P+(N-V)+1. For example:
+ * We are looking for 10, but have 8
+ * 8 ? ? ? ?
+ * >=9 >=10 >=11
+ *
+ */
+static MCSetT *MCGetSet( cat, setId)
+MCCatT *cat;
+int setId;
+{
+ MCSetT *set;
+ long lo, hi, cur, dir;
+
+ if (!cat || setId <= 0) return(NULL);
+
+ lo = 0;
+ if (setId - 1 < cat->numSets) {
+ cur = setId - 1;
+ hi = setId;
+ } else {
+ hi = cat->numSets;
+ cur = (hi - lo) / 2;
+ }
+
+ while (True) {
+ set = cat->sets + cur;
+ if (set->setId == setId) break;
+ if (set->setId < setId) {
+ lo = cur+1;
+ if (hi > cur + (setId - set->setId) + 1) hi = cur+(setId-set->setId)+1;
+ dir = 1;
+ } else {
+ hi = cur;
+ dir = -1;
+ }
+ if (lo >= hi) return(NULL);
+ if (hi - lo == 1) cur += dir;
+ else cur += ((hi - lo) / 2) * dir;
+ }
+ if (set->invalid) loadSet(cat, set);
+ return(set);
+}
+
+
+static MCMsgT *MCGetMsg( set, msgId)
+MCSetT *set;
+int msgId;
+{
+ MCMsgT *msg;
+ long lo, hi, cur, dir;
+
+ if (!set || set->invalid || msgId <= 0) return(NULL);
+
+ lo = 0;
+ if (msgId - 1 < set->numMsgs) {
+ cur = msgId - 1;
+ hi = msgId;
+ } else {
+ hi = set->numMsgs;
+ cur = (hi - lo) / 2;
+ }
+
+ while (True) {
+ msg = set->u.msgs + cur;
+ if (msg->msgId == msgId) break;
+ if (msg->msgId < msgId) {
+ lo = cur+1;
+ if (hi > cur + (msgId - msg->msgId) + 1) hi = cur+(msgId-msg->msgId)+1;
+ dir = 1;
+ } else {
+ hi = cur;
+ dir = -1;
+ }
+ if (lo >= hi) return(NULL);
+ if (hi - lo == 1) cur += dir;
+ else cur += ((hi - lo) / 2) * dir;
+ }
+ return(msg);
+}
+
+char *_catgets( catd, setId, msgId, dflt)
+nl_catd catd;
+int setId;
+int msgId;
+char *dflt;
+{
+ MCMsgT *msg;
+ MCCatT *cat = (MCCatT *) catd;
+ char *cptr;
+
+ msg = MCGetMsg(MCGetSet(cat, setId), msgId);
+ if (msg) cptr = msg->msg.str;
+ else cptr = dflt;
+ return(cptr);
+}
+
+
+int _catclose( catd)
+nl_catd catd;
+{
+ MCCatT *cat = (MCCatT *) catd;
+ MCSetT *set;
+ int i;
+
+ if (!cat) return -1;
+
+ if (cat->loadType != MCLoadAll) close(cat->fd);
+ for (i = 0; i < cat->numSets; ++i) {
+ set = cat->sets + i;
+ if (!set->invalid) {
+ free(set->data.str);
+ free(set->u.msgs);
+ }
+ }
+ free(cat->sets);
+ free(cat);
+
+ return 0;
+}
+
+/*
+ * Internal routines
+ */
+
+/* Note that only malloc failures are allowed to return an error */
+#define ERRNAME "Message Catalog System"
+#define CORRUPT() {fprintf(stderr, "%s: corrupt file.\n", ERRNAME); free(cat); return(0);}
+#define NOSPACE() {fprintf(stderr, "%s: no more memory.\n", ERRNAME); free(cat); return(NLERR);}
+
+static nl_catd loadCat( catpath, type)
+__const char *catpath;
+int type;
+{
+ MCHeaderT header;
+ MCCatT *cat;
+ MCSetT *set;
+ long i, j;
+ off_t nextSet;
+
+ cat = (MCCatT *) malloc(sizeof(MCCatT));
+ if (!cat) return(NLERR);
+ cat->loadType = type;
+
+ if ((cat->fd = open(catpath, O_RDONLY)) < 0) {
+ free(cat);
+ return(0);
+ }
+
+ (void)fcntl(cat->fd, F_SETFD, FD_CLOEXEC);
+
+ if (read(cat->fd, &header, sizeof(header)) != sizeof(header)) CORRUPT();
+
+ if (strncmp(header.magic, MCMagic, MCMagicLen) != 0) CORRUPT();
+
+ if (header.majorVer != MCMajorVer) {
+ free(cat);
+ fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", ERRNAME,
+ catpath, header.majorVer, MCMajorVer);
+ return(0);
+ }
+
+ if (header.numSets <= 0) {
+ free(cat);
+ fprintf(stderr, "%s: %s has %ld sets!\n", ERRNAME, catpath,
+ header.numSets);
+ return(0);
+ }
+
+ cat->numSets = header.numSets;
+ cat->sets = (MCSetT *) malloc(sizeof(MCSetT) * header.numSets);
+ if (!cat->sets) NOSPACE();
+
+ nextSet = header.firstSet;
+ for (i = 0; i < cat->numSets; ++i) {
+ if (lseek(cat->fd, nextSet, 0) == -1) {
+ for (j = 0; j < i; j++) {
+ set = cat->sets + j;
+ if (!set->invalid) {
+ free(set->data.str);
+ free(set->u.msgs);
+ }
+ }
+ free(cat->sets);
+ CORRUPT();
+ }
+
+ /* read in the set header */
+ set = cat->sets + i;
+ if (read(cat->fd, set, sizeof(*set)) != sizeof(*set)) {
+ for (j = 0; j < i; j++) {
+ set = cat->sets + j;
+ if (!set->invalid) {
+ free(set->data.str);
+ free(set->u.msgs);
+ }
+ }
+ free(cat->sets);
+ CORRUPT();
+ }
+
+ /* if it's invalid, skip over it (and backup 'i') */
+
+ if (set->invalid) {
+ --i;
+ nextSet = set->nextSet;
+ continue;
+ }
+
+ if (cat->loadType == MCLoadAll) {
+ nl_catd res;
+
+ if ((res = loadSet(cat, set)) <= 0) {
+ for (j = 0; j < i; j++) {
+ set = cat->sets + j;
+ if (!set->invalid) {
+ free(set->data.str);
+ free(set->u.msgs);
+ }
+ }
+ free(cat->sets);
+ if (res == -1) NOSPACE();
+ CORRUPT();
+ }
+ } else set->invalid = True;
+ nextSet = set->nextSet;
+ }
+ if (cat->loadType == MCLoadAll) {
+ close(cat->fd);
+ cat->fd = -1;
+ }
+ return((nl_catd) cat);
+}
+
+static nl_catd loadSet( cat, set)
+MCCatT *cat;
+MCSetT *set;
+{
+ MCMsgT *msg;
+ int i;
+
+ /* Get the data */
+ if (lseek(cat->fd, set->data.off, 0) == -1) return(0);
+ if ((set->data.str = (char *) malloc(set->dataLen)) == NULL) return(-1);
+ if (read(cat->fd, set->data.str, set->dataLen) != set->dataLen) {
+ free(set->data.str); return(0);
+ }
+
+ /* Get the messages */
+ if (lseek(cat->fd, set->u.firstMsg, 0) == -1) {
+ free(set->data.str); return(0);
+ }
+ if ((set->u.msgs = (MCMsgT *) malloc(sizeof(MCMsgT) * set->numMsgs)) == NULL) {
+ free(set->data.str); return(-1);
+ }
+
+ for (i = 0; i < set->numMsgs; ++i) {
+ msg = set->u.msgs + i;
+ if (read(cat->fd, msg, sizeof(*msg)) != sizeof(*msg)) {
+ free(set->u.msgs); free(set->data.str); return(0);
+ }
+ if (msg->invalid) {
+ --i;
+ continue;
+ }
+ msg->msg.str = (char *) (set->data.str + msg->msg.off);
+ }
+ set->invalid = False;
+ return(1);
+}
diff --git a/lib/libc/nls/msgcat.h b/lib/libc/nls/msgcat.h
new file mode 100644
index 0000000..9df7a82
--- /dev/null
+++ b/lib/libc/nls/msgcat.h
@@ -0,0 +1,170 @@
+/* $Id$ */
+
+/* -*-c++-*- */
+
+#ifndef __msgcath
+
+
+/***********************************************************
+Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that Alfalfa's name not be used in
+advertising or publicity pertaining to distribution of the software
+without specific, written prior permission.
+
+ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+If you make any modifications, bugfixes or other changes to this software
+we'd appreciate it if you could send a copy to us so we can keep things
+up-to-date. Many thanks.
+ Kee Hinckley
+ Alfalfa Software, Inc.
+ 267 Allston St., #3
+ Cambridge, MA 02139 USA
+ nazgul@alfalfa.com
+
+******************************************************************/
+
+
+#include <sys/types.h>
+
+/*
+ * On disk data structures
+ */
+
+/* Edit History
+
+02/25/91 2 nazgul Byte order flags, upped the version number
+11/03/90 1 hamilton Alphalpha->Alfalfa & OmegaMail->Poste
+08/13/90 1 schulert move from ua to omu
+*/
+
+/* For or'd constants */
+#define MCMakeId(s,m) (unsigned long) ( ((unsigned short)s << (sizeof(short)*8)) \
+ | (unsigned short)m )
+#define MCSetId(id) (unsigned int) ( id >> (sizeof(short) * 8) )
+#define MCMsgId(id) (unsigned int) ( (id << (sizeof(short) * 8)) \
+ >> (sizeof(short) * 8) )
+#undef S
+#undef UI
+#undef UL
+
+#define MCMagicLen 8
+#define MCMagic "*nazgul*"
+#define MCLastMsg 0
+#define MCLastSet 0
+
+#define MCMajorVer 1L
+#define MCMinorVer 0
+
+/*
+ * Critical note here. Sets and Messages *MUST* be stored in ascending
+ * order. There are stored that way (by specification) in the original
+ * data file, however in the process of merging in new stuff you might
+ * mix that up. Don't! The catget stuff does a binary search and will
+ * totally lose it if these aren't in order (not contiguous mind you, just
+ * in order. If this turns out to be a major problem this could be enhanced
+ * by adding a 'sorted' flag to the db, and sorting msgs and sets at load
+ * time if things aren't sorted, but I'd like not to have to do that.
+ */
+
+/*
+ * I have tried here to define data structures which can be used
+ * while the catalog is on disk, and at runtime.
+ * This is rather dangerous of course, but I think it can be done without
+ * overly increasing the memory usage, and it makes loading and storing
+ * somewhat simpler and less prone to accidents. I have also tried to
+ * define on disk data structures which can be updated in place, so that
+ * with a very large catalog (e.g. all system errors) you don't have to
+ * load everything in memory in order to add or update one set. With
+ * this in mind there are "invalid" flags which allow items to be
+ * invalidated and thus not loaded at runtime. Note however that although
+ * I pay attention to these when I load the DB, I do not currently use
+ * them in gencat (it just reads everything into memory), so there is
+ * no guarantee that this will all work.
+ */
+
+/* These should be publicly available */
+
+#define MCLoadBySet 0 /* Load entire sets as they are used */
+#define MCLoadAll 1 /* Load entire DB on catopen */
+
+/*
+ * MCOffsetT - Union to handle both disk and runtime pointers
+ */
+typedef union {
+ off_t off;
+ char *str;
+ void *ptr;
+ struct _MCMsgT *msg;
+ struct _MCSetT *set;
+} MCOffsetT;
+
+/*
+ * MCMsgT - Message structure (disk and runtime)
+ */
+typedef struct _MCMsgT {
+ long msgId; /* Id of this message */
+ MCOffsetT msg; /* Relative offset on disk or pointer in memory */
+ long invalid; /* Valid on disk, loaded in memory */
+} MCMsgT;
+
+/*
+ * MCSetT - Set structure (disk and runtime)
+ */
+typedef struct _MCSetT {
+ long setId; /* Id of this set */
+ off_t nextSet; /* Offset of next set on disk */
+ union {
+ off_t firstMsg; /* Offset to first Msg (while on disk) */
+ MCMsgT *msgs; /* Pointer to array of msgs (in mem, loaded) */
+ } u;
+ MCOffsetT data; /* Offset to data, or pointer to data */
+ long dataLen; /* Length of data area on disk */
+ long numMsgs; /* Number of messages */
+ long invalid; /* Valid on disk, loaded in memory */
+} MCSetT;
+
+/*
+ * MCCatT - Runtime catalog pointer
+ */
+typedef struct {
+ long loadType; /* How to load the messages (see MSLoadType) */
+ int fd; /* File descriptor of catalog (if load-on-demand) */
+ long numSets; /* Number of sets */
+ MCSetT *sets; /* Pointer to the sets */
+ off_t firstSet; /* Offset of first set on disk */
+} MCCatT;
+
+/*
+ * MCHeaderT - Disk file header
+ */
+typedef struct {
+ char magic[MCMagicLen]; /* Magic cookie "*nazgul*" */
+ long majorVer; /* ++ on incompatible changes */
+ long minorVer; /* ++ on compatible changes */
+ long flags; /* Informational flags */
+ long numSets; /* Number of valid Sets */
+ off_t firstSet; /* Offset of first set on disk */
+} MCHeaderT;
+
+/* Some flags */
+#define MC68KByteOrder 0x01
+#define MCn86ByteOrder 0x02
+
+
+
+
+#endif
diff --git a/lib/libc/quad/Makefile.inc b/lib/libc/quad/Makefile.inc
index 6273574..8aca699 100644
--- a/lib/libc/quad/Makefile.inc
+++ b/lib/libc/quad/Makefile.inc
@@ -1,10 +1,20 @@
-# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
+
+# Quad support, if needed
+
+.if ${MACHINE} == "i386"
+
+SRCS+= cmpdi2.c divdi3.c moddi3.c qdivrem.c ucmpdi2.c udivdi3.c umoddi3.c
+
+.else
-# Quad support
SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c fixdfdi.c \
fixsfdi.c fixunsdfdi.c fixunssfdi.c floatdidf.c floatdisf.c \
floatunsdidf.c iordi3.c lshldi3.c lshrdi3.c moddi3.c muldi3.c \
negdi2.c notdi2.c qdivrem.c subdi3.c ucmpdi2.c udivdi3.c umoddi3.c \
xordi3.c
-.PATH: ${.CURDIR}/${MACHINE}/quad ${.CURDIR}/quad
+.endif
+
+.PATH: ${.CURDIR}/../libc/${MACHINE}/quad ${.CURDIR}/../libc/quad
diff --git a/lib/libc/quad/muldi3.c b/lib/libc/quad/muldi3.c
index a8d7cfc..5e2331f 100644
--- a/lib/libc/quad/muldi3.c
+++ b/lib/libc/quad/muldi3.c
@@ -49,7 +49,7 @@ static char sccsid[] = "@(#)muldi3.c 8.1 (Berkeley) 6/4/93";
*
* u = 2^n u1 * u0 (n = number of bits in `u_long', usu. 32)
*
- * and
+ * and
*
* v = 2^n v1 * v0
*
diff --git a/lib/libc/quad/qdivrem.c b/lib/libc/quad/qdivrem.c
index 34b94ce..56f91ec 100644
--- a/lib/libc/quad/qdivrem.c
+++ b/lib/libc/quad/qdivrem.c
@@ -198,7 +198,7 @@ __qdivrem(uq, vq, arq)
v2 = v[2]; /* for D3 */
do {
register digit uj0, uj1, uj2;
-
+
/*
* D3: Calculate qhat (\^q, in TeX notation).
* Let qhat = min((u[j]*B + u[j+1])/v[1], B-1), and
diff --git a/lib/libc/quad/quad.h b/lib/libc/quad/quad.h
index bc6a2f8..873a1f6 100644
--- a/lib/libc/quad/quad.h
+++ b/lib/libc/quad/quad.h
@@ -35,6 +35,7 @@
* SUCH DAMAGE.
*
* @(#)quad.h 8.1 (Berkeley) 6/4/93
+ * $Id$
*/
/*
@@ -95,7 +96,11 @@ union uu {
#define LHALF(x) ((x) & ((1 << HALF_BITS) - 1))
#define LHUP(x) ((x) << HALF_BITS)
-extern u_quad_t __qdivrem __P((u_quad_t u, u_quad_t v, u_quad_t *rem));
+quad_t __divdi3 __P((quad_t a, quad_t b));
+quad_t __moddi3 __P((quad_t a, quad_t b));
+u_quad_t __qdivrem __P((u_quad_t u, u_quad_t v, u_quad_t *rem));
+u_quad_t __udivdi3 __P((u_quad_t a, u_quad_t b));
+u_quad_t __umoddi3 __P((u_quad_t a, u_quad_t b));
/*
* XXX
diff --git a/lib/libc/regex/Makefile.inc b/lib/libc/regex/Makefile.inc
index f9853f3..d8c6092 100644
--- a/lib/libc/regex/Makefile.inc
+++ b/lib/libc/regex/Makefile.inc
@@ -1,14 +1,18 @@
-# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id$
# regex sources
-.PATH: ${.CURDIR}/regex
+.PATH: ${.CURDIR}/../libc/regex
CFLAGS+=-DPOSIX_MISTAKE
SRCS+= regcomp.c regerror.c regexec.c regfree.c
-MAN3+= regex.0
-MAN7+= re_format.0
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN3+= regex/regex.3
+MAN7+= regex/re_format.7
MLINKS+=regex.3 regcomp.3 regex.3 regexec.3 regex.3 regerror.3
MLINKS+=regexec.3 regfree.3
+.endif
diff --git a/lib/libc/regex/cclass.h b/lib/libc/regex/cclass.h
index a29a92e..581909c 100644
--- a/lib/libc/regex/cclass.h
+++ b/lib/libc/regex/cclass.h
@@ -37,34 +37,26 @@
* @(#)cclass.h 8.3 (Berkeley) 3/20/94
*/
+
+typedef enum {CALNUM, CALPHA, CBLANK, CCNTRL, CDIGIT, CGRAPH,
+ CLOWER, CPRINT, CPUNCT, CSPACE, CUPPER, CXDIGIT} citype;
+
/* character-class table */
static struct cclass {
char *name;
- char *chars;
- char *multis;
+ citype fidx;
} cclasses[] = {
- "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789", "",
- "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
- "",
- "blank", " \t", "",
- "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
-\25\26\27\30\31\32\33\34\35\36\37\177", "",
- "digit", "0123456789", "",
- "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
- "",
- "lower", "abcdefghijklmnopqrstuvwxyz",
- "",
- "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
- "",
- "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
- "",
- "space", "\t\n\v\f\r ", "",
- "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
- "",
- "xdigit", "0123456789ABCDEFabcdef",
- "",
- NULL, 0, ""
+ {"alnum", CALNUM},
+ {"alpha", CALPHA},
+ {"blank", CBLANK},
+ {"cntrl", CCNTRL},
+ {"digit", CDIGIT},
+ {"graph", CGRAPH},
+ {"lower", CLOWER},
+ {"print", CPRINT},
+ {"punct", CPUNCT},
+ {"space", CSPACE},
+ {"upper", CUPPER},
+ {"xdigit", CXDIGIT},
+ {NULL, }
};
diff --git a/lib/libc/regex/cname.h b/lib/libc/regex/cname.h
index c1632eb..72bbe5e 100644
--- a/lib/libc/regex/cname.h
+++ b/lib/libc/regex/cname.h
@@ -42,100 +42,100 @@ static struct cname {
char *name;
char code;
} cnames[] = {
- "NUL", '\0',
- "SOH", '\001',
- "STX", '\002',
- "ETX", '\003',
- "EOT", '\004',
- "ENQ", '\005',
- "ACK", '\006',
- "BEL", '\007',
- "alert", '\007',
- "BS", '\010',
- "backspace", '\b',
- "HT", '\011',
- "tab", '\t',
- "LF", '\012',
- "newline", '\n',
- "VT", '\013',
- "vertical-tab", '\v',
- "FF", '\014',
- "form-feed", '\f',
- "CR", '\015',
- "carriage-return", '\r',
- "SO", '\016',
- "SI", '\017',
- "DLE", '\020',
- "DC1", '\021',
- "DC2", '\022',
- "DC3", '\023',
- "DC4", '\024',
- "NAK", '\025',
- "SYN", '\026',
- "ETB", '\027',
- "CAN", '\030',
- "EM", '\031',
- "SUB", '\032',
- "ESC", '\033',
- "IS4", '\034',
- "FS", '\034',
- "IS3", '\035',
- "GS", '\035',
- "IS2", '\036',
- "RS", '\036',
- "IS1", '\037',
- "US", '\037',
- "space", ' ',
- "exclamation-mark", '!',
- "quotation-mark", '"',
- "number-sign", '#',
- "dollar-sign", '$',
- "percent-sign", '%',
- "ampersand", '&',
- "apostrophe", '\'',
- "left-parenthesis", '(',
- "right-parenthesis", ')',
- "asterisk", '*',
- "plus-sign", '+',
- "comma", ',',
- "hyphen", '-',
- "hyphen-minus", '-',
- "period", '.',
- "full-stop", '.',
- "slash", '/',
- "solidus", '/',
- "zero", '0',
- "one", '1',
- "two", '2',
- "three", '3',
- "four", '4',
- "five", '5',
- "six", '6',
- "seven", '7',
- "eight", '8',
- "nine", '9',
- "colon", ':',
- "semicolon", ';',
- "less-than-sign", '<',
- "equals-sign", '=',
- "greater-than-sign", '>',
- "question-mark", '?',
- "commercial-at", '@',
- "left-square-bracket", '[',
- "backslash", '\\',
- "reverse-solidus", '\\',
- "right-square-bracket", ']',
- "circumflex", '^',
- "circumflex-accent", '^',
- "underscore", '_',
- "low-line", '_',
- "grave-accent", '`',
- "left-brace", '{',
- "left-curly-bracket", '{',
- "vertical-line", '|',
- "right-brace", '}',
- "right-curly-bracket", '}',
- "tilde", '~',
- "DEL", '\177',
- NULL, 0,
+ {"NUL", '\0'},
+ {"SOH", '\001'},
+ {"STX", '\002'},
+ {"ETX", '\003'},
+ {"EOT", '\004'},
+ {"ENQ", '\005'},
+ {"ACK", '\006'},
+ {"BEL", '\007'},
+ {"alert", '\007'},
+ {"BS", '\010'},
+ {"backspace", '\b'},
+ {"HT", '\011'},
+ {"tab", '\t'},
+ {"LF", '\012'},
+ {"newline", '\n'},
+ {"VT", '\013'},
+ {"vertical-tab", '\v'},
+ {"FF", '\014'},
+ {"form-feed", '\f'},
+ {"CR", '\015'},
+ {"carriage-return", '\r'},
+ {"SO", '\016'},
+ {"SI", '\017'},
+ {"DLE", '\020'},
+ {"DC1", '\021'},
+ {"DC2", '\022'},
+ {"DC3", '\023'},
+ {"DC4", '\024'},
+ {"NAK", '\025'},
+ {"SYN", '\026'},
+ {"ETB", '\027'},
+ {"CAN", '\030'},
+ {"EM", '\031'},
+ {"SUB", '\032'},
+ {"ESC", '\033'},
+ {"IS4", '\034'},
+ {"FS", '\034'},
+ {"IS3", '\035'},
+ {"GS", '\035'},
+ {"IS2", '\036'},
+ {"RS", '\036'},
+ {"IS1", '\037'},
+ {"US", '\037'},
+ {"space", ' '},
+ {"exclamation-mark", '!'},
+ {"quotation-mark", '"'},
+ {"number-sign", '#'},
+ {"dollar-sign", '$'},
+ {"percent-sign", '%'},
+ {"ampersand", '&'},
+ {"apostrophe", '\''},
+ {"left-parenthesis", '('},
+ {"right-parenthesis", ')'},
+ {"asterisk", '*'},
+ {"plus-sign", '+'},
+ {"comma", ','},
+ {"hyphen", '-'},
+ {"hyphen-minus", '-'},
+ {"period", '.'},
+ {"full-stop", '.'},
+ {"slash", '/'},
+ {"solidus", '/'},
+ {"zero", '0'},
+ {"one", '1'},
+ {"two", '2'},
+ {"three", '3'},
+ {"four", '4'},
+ {"five", '5'},
+ {"six", '6'},
+ {"seven", '7'},
+ {"eight", '8'},
+ {"nine", '9'},
+ {"colon", ':'},
+ {"semicolon", ';'},
+ {"less-than-sign", '<'},
+ {"equals-sign", '='},
+ {"greater-than-sign", '>'},
+ {"question-mark", '?'},
+ {"commercial-at", '@'},
+ {"left-square-bracket", '['},
+ {"backslash", '\\'},
+ {"reverse-solidus", '\\'},
+ {"right-square-bracket",']'},
+ {"circumflex", '^'},
+ {"circumflex-accent", '^'},
+ {"underscore", '_'},
+ {"low-line", '_'},
+ {"grave-accent", '`'},
+ {"left-brace", '{'},
+ {"left-curly-bracket", '{'},
+ {"vertical-line", '|'},
+ {"right-brace", '}'},
+ {"right-curly-bracket", '}'},
+ {"tilde", '~'},
+ {"DEL", '\177'},
+ {NULL, 0}
};
diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c
index 02c841a..be569b1 100644
--- a/lib/libc/regex/engine.c
+++ b/lib/libc/regex/engine.c
@@ -148,8 +148,8 @@ int eflags;
struct match mv;
register struct match *m = &mv;
register char *dp;
- const register sopno gf = g->firststate+1; /* +1 for OEND */
- const register sopno gl = g->laststate;
+ register const sopno gf = g->firststate+1; /* +1 for OEND */
+ register const sopno gl = g->laststate;
char *start;
char *stop;
@@ -686,6 +686,7 @@ sopno lev; /* PLUS nesting level */
/* "can't happen" */
assert(nope);
/* NOTREACHED */
+ return "shut up gcc";
}
/*
@@ -1028,7 +1029,7 @@ FILE *d;
fprintf(d, "\n");
}
-/*
+/*
- at - print current situation
== #ifdef REDEBUG
== static void at(struct match *m, char *title, char *start, char *stop, \
@@ -1071,7 +1072,7 @@ int ch;
{
static char pbuf[10];
- if (isprint(ch) || ch == ' ')
+ if (isprint((uch)ch) || ch == ' ')
sprintf(pbuf, "%c", ch);
else
sprintf(pbuf, "\\%o", ch);
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c
index feb24ec..8bb1355 100644
--- a/lib/libc/regex/regcomp.c
+++ b/lib/libc/regex/regcomp.c
@@ -49,6 +49,8 @@ static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
#include <stdlib.h>
#include <regex.h>
+#include "collate.h"
+
#include "utils.h"
#include "regex2.h"
@@ -103,9 +105,11 @@ static int freezeset __P((struct parse *p, cset *cs));
static int firstch __P((struct parse *p, cset *cs));
static int nch __P((struct parse *p, cset *cs));
static void mcadd __P((struct parse *p, cset *cs, char *cp));
+#if used
static void mcsub __P((cset *cs, char *cp));
static int mcin __P((cset *cs, char *cp));
static char *mcfind __P((cset *cs, char *cp));
+#endif
static void mcinvert __P((struct parse *p, cset *cs));
static void mccase __P((struct parse *p, cset *cs));
static int isinsets __P((struct re_guts *g, int c));
@@ -295,7 +299,7 @@ int stop; /* character this ERE should end at */
conc = HERE();
while (MORE() && (c = PEEK()) != '|' && c != stop)
p_ere_exp(p);
- REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */
+ (void)REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */
if (!EAT('|'))
break; /* NOTE BREAK OUT */
@@ -342,7 +346,7 @@ register struct parse *p;
pos = HERE();
switch (c) {
case '(':
- REQUIRE(MORE(), REG_EPAREN);
+ (void)REQUIRE(MORE(), REG_EPAREN);
p->g->nsub++;
subno = p->g->nsub;
if (subno < NPAREN)
@@ -355,7 +359,7 @@ register struct parse *p;
assert(p->pend[subno] != 0);
}
EMIT(ORPAREN, subno);
- MUSTEAT(')', REG_EPAREN);
+ (void)MUSTEAT(')', REG_EPAREN);
break;
#ifndef POSIX_MISTAKE
case ')': /* happens only if no current unmatched ( */
@@ -398,12 +402,12 @@ register struct parse *p;
p_bracket(p);
break;
case '\\':
- REQUIRE(MORE(), REG_EESCAPE);
+ (void)REQUIRE(MORE(), REG_EESCAPE);
c = GETNEXT();
ordinary(p, c);
break;
case '{': /* okay as ordinary except if digit follows */
- REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT);
+ (void)REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT);
/* FALLTHROUGH */
default:
ordinary(p, c);
@@ -419,7 +423,7 @@ register struct parse *p;
return; /* no repetition, we're done */
NEXT();
- REQUIRE(!wascaret, REG_BADRPT);
+ (void)REQUIRE(!wascaret, REG_BADRPT);
switch (c) {
case '*': /* implemented as +? */
/* this case does not require the (y|) trick, noKLUDGE */
@@ -446,7 +450,7 @@ register struct parse *p;
if (EAT(',')) {
if (isdigit(PEEK())) {
count2 = p_count(p);
- REQUIRE(count <= count2, REG_BADBR);
+ (void)REQUIRE(count <= count2, REG_BADBR);
} else /* single number with comma */
count2 = INFINITY;
} else /* just a single number */
@@ -455,7 +459,7 @@ register struct parse *p;
if (!EAT('}')) { /* error heuristics */
while (MORE() && PEEK() != '}')
NEXT();
- REQUIRE(MORE(), REG_EBRACE);
+ (void)REQUIRE(MORE(), REG_EBRACE);
SETERROR(REG_BADBR);
}
break;
@@ -478,7 +482,7 @@ static void
p_str(p)
register struct parse *p;
{
- REQUIRE(MORE(), REG_EMPTY);
+ (void)REQUIRE(MORE(), REG_EMPTY);
while (MORE())
ordinary(p, GETNEXT());
}
@@ -521,7 +525,7 @@ register int end2; /* second terminating character */
p->g->neol++;
}
- REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */
+ (void)REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */
}
/*
@@ -546,7 +550,7 @@ int starordinary; /* is a leading * an ordinary character? */
assert(MORE()); /* caller should have ensured this */
c = GETNEXT();
if (c == '\\') {
- REQUIRE(MORE(), REG_EESCAPE);
+ (void)REQUIRE(MORE(), REG_EESCAPE);
c = BACKSL | (unsigned char)GETNEXT();
}
switch (c) {
@@ -576,7 +580,7 @@ int starordinary; /* is a leading * an ordinary character? */
assert(p->pend[subno] != 0);
}
EMIT(ORPAREN, subno);
- REQUIRE(EATTWO('\\', ')'), REG_EPAREN);
+ (void)REQUIRE(EATTWO('\\', ')'), REG_EPAREN);
break;
case BACKSL|')': /* should not get here -- must be user */
case BACKSL|'}':
@@ -606,7 +610,7 @@ int starordinary; /* is a leading * an ordinary character? */
p->g->backrefs = 1;
break;
case '*':
- REQUIRE(starordinary, REG_BADRPT);
+ (void)REQUIRE(starordinary, REG_BADRPT);
/* FALLTHROUGH */
default:
ordinary(p, c &~ BACKSL);
@@ -624,7 +628,7 @@ int starordinary; /* is a leading * an ordinary character? */
if (EAT(',')) {
if (MORE() && isdigit(PEEK())) {
count2 = p_count(p);
- REQUIRE(count <= count2, REG_BADBR);
+ (void)REQUIRE(count <= count2, REG_BADBR);
} else /* single number with comma */
count2 = INFINITY;
} else /* just a single number */
@@ -633,7 +637,7 @@ int starordinary; /* is a leading * an ordinary character? */
if (!EATTWO('\\', '}')) { /* error heuristics */
while (MORE() && !SEETWO('\\', '}'))
NEXT();
- REQUIRE(MORE(), REG_EBRACE);
+ (void)REQUIRE(MORE(), REG_EBRACE);
SETERROR(REG_BADBR);
}
} else if (c == (unsigned char)'$') /* $ (but not \$) ends it */
@@ -658,7 +662,7 @@ register struct parse *p;
ndigits++;
}
- REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR);
+ (void)REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR);
return(count);
}
@@ -673,7 +677,6 @@ static void
p_bracket(p)
register struct parse *p;
{
- register char c;
register cset *cs = allocset(p);
register int invert = 0;
@@ -699,7 +702,7 @@ register struct parse *p;
p_b_term(p, cs);
if (EAT('-'))
CHadd(cs, '-');
- MUSTEAT(']', REG_EBRACK);
+ (void)MUSTEAT(']', REG_EBRACK);
if (p->error != 0) /* don't mess things up further */
return;
@@ -770,21 +773,21 @@ register cset *cs;
switch (c) {
case ':': /* character class */
NEXT2();
- REQUIRE(MORE(), REG_EBRACK);
+ (void)REQUIRE(MORE(), REG_EBRACK);
c = PEEK();
- REQUIRE(c != '-' && c != ']', REG_ECTYPE);
+ (void)REQUIRE(c != '-' && c != ']', REG_ECTYPE);
p_b_cclass(p, cs);
- REQUIRE(MORE(), REG_EBRACK);
- REQUIRE(EATTWO(':', ']'), REG_ECTYPE);
+ (void)REQUIRE(MORE(), REG_EBRACK);
+ (void)REQUIRE(EATTWO(':', ']'), REG_ECTYPE);
break;
case '=': /* equivalence class */
NEXT2();
- REQUIRE(MORE(), REG_EBRACK);
+ (void)REQUIRE(MORE(), REG_EBRACK);
c = PEEK();
- REQUIRE(c != '-' && c != ']', REG_ECOLLATE);
+ (void)REQUIRE(c != '-' && c != ']', REG_ECOLLATE);
p_b_eclass(p, cs);
- REQUIRE(MORE(), REG_EBRACK);
- REQUIRE(EATTWO('=', ']'), REG_ECOLLATE);
+ (void)REQUIRE(MORE(), REG_EBRACK);
+ (void)REQUIRE(EATTWO('=', ']'), REG_ECOLLATE);
break;
default: /* symbol, ordinary character, or range */
/* xxx revision needed for multichar stuff */
@@ -798,10 +801,23 @@ register cset *cs;
finish = p_b_symbol(p);
} else
finish = start;
-/* xxx what about signed chars here... */
- REQUIRE(start <= finish, REG_ERANGE);
- for (i = start; i <= finish; i++)
- CHadd(cs, i);
+ if (start == finish)
+ CHadd(cs, start);
+ else {
+ if (__collate_load_error) {
+ (void)REQUIRE((uch)start <= (uch)finish, REG_ERANGE);
+ for (i = (uch)start; i <= (uch)finish; i++)
+ CHadd(cs, i);
+ } else {
+ (void)REQUIRE(__collate_range_cmp(start, finish) <= 0, REG_ERANGE);
+ for (i = CHAR_MIN; i <= CHAR_MAX; i++) {
+ if ( __collate_range_cmp(start, i) <= 0
+ && __collate_range_cmp(i, finish) <= 0
+ )
+ CHadd(cs, i);
+ }
+ }
+ }
break;
}
}
@@ -815,13 +831,12 @@ p_b_cclass(p, cs)
register struct parse *p;
register cset *cs;
{
+ register int c;
register char *sp = p->next;
register struct cclass *cp;
register size_t len;
- register char *u;
- register char c;
- while (MORE() && isalpha(PEEK()))
+ while (MORE() && isalpha((uch)PEEK()))
NEXT();
len = p->next - sp;
for (cp = cclasses; cp->name != NULL; cp++)
@@ -833,11 +848,72 @@ register cset *cs;
return;
}
- u = cp->chars;
- while ((c = *u++) != '\0')
- CHadd(cs, c);
+ switch (cp->fidx) {
+ case CALNUM:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (isalnum((uch)c))
+ CHadd(cs, c);
+ break;
+ case CALPHA:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (isalpha((uch)c))
+ CHadd(cs, c);
+ break;
+ case CBLANK:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (isblank((uch)c))
+ CHadd(cs, c);
+ break;
+ case CCNTRL:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (iscntrl((uch)c))
+ CHadd(cs, c);
+ break;
+ case CDIGIT:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (isdigit((uch)c))
+ CHadd(cs, c);
+ break;
+ case CGRAPH:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (isgraph((uch)c))
+ CHadd(cs, c);
+ break;
+ case CLOWER:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (islower((uch)c))
+ CHadd(cs, c);
+ break;
+ case CPRINT:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (isprint((uch)c))
+ CHadd(cs, c);
+ break;
+ case CPUNCT:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (ispunct((uch)c))
+ CHadd(cs, c);
+ break;
+ case CSPACE:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (isspace((uch)c))
+ CHadd(cs, c);
+ break;
+ case CUPPER:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (isupper((uch)c))
+ CHadd(cs, c);
+ break;
+ case CXDIGIT:
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ if (isxdigit((uch)c))
+ CHadd(cs, c);
+ break;
+ }
+#if 0
for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
MCadd(p, cs, u);
+#endif
}
/*
@@ -867,13 +943,13 @@ register struct parse *p;
{
register char value;
- REQUIRE(MORE(), REG_EBRACK);
+ (void)REQUIRE(MORE(), REG_EBRACK);
if (!EATTWO('[', '.'))
return(GETNEXT());
/* collating symbol */
value = p_b_coll_elem(p, '.');
- REQUIRE(EATTWO('.', ']'), REG_ECOLLATE);
+ (void)REQUIRE(EATTWO('.', ']'), REG_ECOLLATE);
return(value);
}
@@ -889,7 +965,6 @@ int endc; /* name ended by endc,']' */
register char *sp = p->next;
register struct cname *cp;
register int len;
- register char c;
while (MORE() && !SEETWO(endc, ']'))
NEXT();
@@ -915,6 +990,7 @@ static char /* if no counterpart, return ch */
othercase(ch)
int ch;
{
+ ch = (unsigned char)ch;
assert(isalpha(ch));
if (isupper(ch))
return(tolower(ch));
@@ -939,6 +1015,7 @@ int ch;
register char *oldend = p->end;
char bracket[3];
+ ch = (unsigned char)ch;
assert(othercase(ch) != ch); /* p_bracket() would recurse */
p->next = bracket;
p->end = bracket+2;
@@ -962,7 +1039,7 @@ register int ch;
{
register cat_t *cap = p->g->categories;
- if ((p->g->cflags&REG_ICASE) && isalpha(ch) && othercase(ch) != ch)
+ if ((p->g->cflags&REG_ICASE) && isalpha((unsigned char)ch) && othercase(ch) != ch)
bothcases(p, ch);
else {
EMIT(OCHAR, (unsigned char)ch);
@@ -1174,7 +1251,7 @@ freezeset(p, cs)
register struct parse *p;
register cset *cs;
{
- register uch h = cs->hash;
+ register short h = cs->hash;
register int i;
register cset *top = &p->g->sets[p->g->ncsets];
register cset *cs2;
@@ -1213,7 +1290,7 @@ register cset *cs;
for (i = 0; i < css; i++)
if (CHIN(cs, i))
- return((char)i);
+ return((unsigned char)i);
assert(never);
return(0); /* arbitrary */
}
@@ -1264,6 +1341,7 @@ register char *cp;
cs->multis[cs->smultis - 1] = '\0';
}
+#if used
/*
- mcsub - subtract a collating element from a cset
== static void mcsub(register cset *cs, register char *cp);
@@ -1321,6 +1399,7 @@ register char *cp;
return(p);
return(NULL);
}
+#endif
/*
- mcinvert - invert the list of collating elements in a cset
diff --git a/lib/libc/regex/regerror.c b/lib/libc/regex/regerror.c
index a8d0945..1ed6771 100644
--- a/lib/libc/regex/regerror.c
+++ b/lib/libc/regex/regerror.c
@@ -88,23 +88,23 @@ static struct rerr {
char *name;
char *explain;
} rerrs[] = {
- REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match",
- REG_BADPAT, "REG_BADPAT", "invalid regular expression",
- REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element",
- REG_ECTYPE, "REG_ECTYPE", "invalid character class",
- REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)",
- REG_ESUBREG, "REG_ESUBREG", "invalid backreference number",
- REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced",
- REG_EPAREN, "REG_EPAREN", "parentheses not balanced",
- REG_EBRACE, "REG_EBRACE", "braces not balanced",
- REG_BADBR, "REG_BADBR", "invalid repetition count(s)",
- REG_ERANGE, "REG_ERANGE", "invalid character range",
- REG_ESPACE, "REG_ESPACE", "out of memory",
- REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid",
- REG_EMPTY, "REG_EMPTY", "empty (sub)expression",
- REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug",
- REG_INVARG, "REG_INVARG", "invalid argument to regex routine",
- 0, "", "*** unknown regexp error code ***",
+ {REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match"},
+ {REG_BADPAT, "REG_BADPAT", "invalid regular expression"},
+ {REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element"},
+ {REG_ECTYPE, "REG_ECTYPE", "invalid character class"},
+ {REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)"},
+ {REG_ESUBREG, "REG_ESUBREG", "invalid backreference number"},
+ {REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced"},
+ {REG_EPAREN, "REG_EPAREN", "parentheses not balanced"},
+ {REG_EBRACE, "REG_EBRACE", "braces not balanced"},
+ {REG_BADBR, "REG_BADBR", "invalid repetition count(s)"},
+ {REG_ERANGE, "REG_ERANGE", "invalid character range"},
+ {REG_ESPACE, "REG_ESPACE", "out of memory"},
+ {REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid"},
+ {REG_EMPTY, "REG_EMPTY", "empty (sub)expression"},
+ {REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug"},
+ {REG_INVARG, "REG_INVARG", "invalid argument to regex routine"},
+ {0, "", "*** unknown regexp error code ***"}
};
/*
@@ -131,7 +131,7 @@ size_t errbuf_size;
for (r = rerrs; r->code != 0; r++)
if (r->code == target)
break;
-
+
if (errcode&REG_ITOA) {
if (r->code != 0)
(void) strcpy(convbuf, r->name);
@@ -166,8 +166,6 @@ const regex_t *preg;
char *localbuf;
{
register struct rerr *r;
- register size_t siz;
- register char *p;
for (r = rerrs; r->code != 0; r++)
if (strcmp(r->name, preg->re_endp) == 0)
diff --git a/lib/libc/regex/regex.3 b/lib/libc/regex/regex.3
index 66a7285..a107eea 100644
--- a/lib/libc/regex/regex.3
+++ b/lib/libc/regex/regex.3
@@ -483,7 +483,9 @@ REG_INVARG invalid argument, e.g. negative-length string
.fi
.SH HISTORY
Originally written by Henry Spencer.
-Altered for inclusion in the 4.4BSD distribution.
+Altered for inclusion in the
+.Bx 4.4
+distribution.
.SH BUGS
This is an alpha release with known defects.
Please report problems.
diff --git a/lib/libc/regex/regex2.h b/lib/libc/regex/regex2.h
index 64b6212..9560e05 100644
--- a/lib/libc/regex/regex2.h
+++ b/lib/libc/regex/regex2.h
@@ -121,13 +121,13 @@ typedef long sopno;
typedef struct {
uch *ptr; /* -> uch [csetsize] */
uch mask; /* bit within array */
- uch hash; /* hash code */
+ short hash; /* hash code */
size_t smultis;
char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */
} cset;
/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
-#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c))
-#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
+#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (uch)(c))
+#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (uch)(c))
#define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
#define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */
#define MCsub(p, cs, cp) mcsub(p, cs, cp)
@@ -170,4 +170,4 @@ struct re_guts {
/* misc utilities */
#define OUT (CHAR_MAX+1) /* a non-character value */
-#define ISWORD(c) (isalnum(c) || (c) == '_')
+#define ISWORD(c) (isalnum((uch)(c)) || (c) == '_')
diff --git a/lib/libc/rpc/DISCLAIMER b/lib/libc/rpc/DISCLAIMER
new file mode 100644
index 0000000..1a66d5f
--- /dev/null
+++ b/lib/libc/rpc/DISCLAIMER
@@ -0,0 +1,28 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
diff --git a/lib/libc/rpc/Makefile.inc b/lib/libc/rpc/Makefile.inc
new file mode 100644
index 0000000..5c96968
--- /dev/null
+++ b/lib/libc/rpc/Makefile.inc
@@ -0,0 +1,120 @@
+# @(#)Makefile 5.11 (Berkeley) 9/6/90
+
+.PATH: ${.CURDIR}/../libc/rpc ${.CURDIR}/.
+SRCS+= auth_none.c auth_unix.c authunix_prot.c bindresvport.c \
+ clnt_generic.c clnt_perror.c clnt_raw.c clnt_simple.c clnt_tcp.c \
+ clnt_udp.c rpc_dtablesize.c get_myaddress.c getrpcent.c getrpcport.c \
+ pmap_clnt.c pmap_getmaps.c pmap_getport.c pmap_prot.c \
+ pmap_prot2.c pmap_rmt.c rpc_prot.c rpc_commondata.c rpc_callmsg.c \
+ svc.c svc_auth.c svc_auth_unix.c svc_raw.c svc_run.c svc_simple.c \
+ svc_tcp.c svc_udp.c
+
+SRCS+= clnt_unix.c svc_unix.c
+
+SRCS+= auth_des.c authdes_prot.c auth_time.c des_soft.c des_crypt.c \
+ key_call.c key_prot_xdr.c netname.c netnamer.c rpcdname.c rtime.c \
+ svc_auth_des.c crypt_clnt.c crypt_xdr.c crypt_client.c
+
+CFLAGS+= -DBROKEN_DES
+
+CLEANFILES= crypt_clnt.c crypt_xdr.c crypt.h
+
+RPCDIR= ${DESTDIR}/usr/include/rpcsvc
+RPCGEN= rpcgen -C
+
+crypt_clnt.c: ${RPCDIR}/crypt.x crypt.h
+ ${RPCGEN} -l -o ${.TARGET} ${RPCDIR}/crypt.x
+
+crypt_xdr.c: ${RPCDIR}/crypt.x crypt.h
+ ${RPCGEN} -c -o ${.TARGET} ${RPCDIR}/crypt.x
+
+crypt.h: ${RPCDIR}/crypt.x
+ ${RPCGEN} -h -o ${.TARGET} ${RPCDIR}/crypt.x
+
+# Only build man pages with libc.
+.if ${LIB} == "c"
+#
+# XXX -- rstat.1 and rstat_svc.8 shouldn't really be here
+# but there's no rstat command, don't know why, so I'm
+# leaving them here in case they're needed sometime later.
+# Paul.
+#
+
+# MAN1+= rpc/rstat.1
+MAN3+= rpc/bindresvport.3 rpc/getrpcent.3 rpc/getrpcport.3 rpc/rpc.3
+MAN5+= rpc/rpc.5
+MAN8+= rpc/rstat_svc.8
+
+MAN3+= rpc/rpc_secure.3 rpc/publickey.3 rpc/rtime.3 rpc/des_crypt.3
+MAN5+= rpc/publickey.5
+
+MLINKS+= getrpcent.3 getrpcbyname.3 \
+ getrpcent.3 getrpcbynumber.3 \
+ getrpcent.3 endrpcent.3 \
+ getrpcent.3 setrpcent.3 \
+ rpc.3 auth_destroy.3 \
+ rpc.3 authnone_create.3 \
+ rpc.3 authunix_create.3 \
+ rpc.3 authunix_create_default.3 \
+ rpc.3 callrpc.3 \
+ rpc.3 clnt_broadcast.3 \
+ rpc.3 clnt_call.3 \
+ rpc.3 clnt_control.3 \
+ rpc.3 clnt_create.3 \
+ rpc.3 clnt_destroy.3 \
+ rpc.3 clnt_freeres.3 \
+ rpc.3 clnt_geterr.3 \
+ rpc.3 clnt_pcreateerror.3 \
+ rpc.3 clnt_perrno.3 \
+ rpc.3 clnt_perror.3 \
+ rpc.3 clnt_spcreateerror.3 \
+ rpc.3 clnt_sperrno.3 \
+ rpc.3 clnt_sperror.3 \
+ rpc.3 clntraw_create.3 \
+ rpc.3 clnttcp_create.3 \
+ rpc.3 clntudp_bufcreate.3 \
+ rpc.3 clntudp_create.3 \
+ rpc.3 get_myaddress.3 \
+ rpc.3 pmap_getmaps.3 \
+ rpc.3 pmap_getport.3 \
+ rpc.3 pmap_rmtcall.3 \
+ rpc.3 pmap_set.3 \
+ rpc.3 pmap_unset.3 \
+ rpc.3 regsterrpc.3 \
+ rpc.3 rpc_createerr.3 \
+ rpc.3 svc_destroy.3 \
+ rpc.3 svc_fds.3 \
+ rpc.3 svc_fdset.3 \
+ rpc.3 svc_getargs.3 \
+ rpc.3 svc_getcaller.3 \
+ rpc.3 svc_getreg.3 \
+ rpc.3 svc_getregset.3 \
+ rpc.3 svc_register.3 \
+ rpc.3 svc_run.3 \
+ rpc.3 svc_sendreply.3 \
+ rpc.3 svc_unregister.3 \
+ rpc.3 svcerr_auth.3 \
+ rpc.3 svcerr_decode.3 \
+ rpc.3 svcerr_noproc.3 \
+ rpc.3 svcerr_noprog.3 \
+ rpc.3 svcerr_progvers.3 \
+ rpc.3 svcerr_systemerr.3 \
+ rpc.3 svcerr_weakauth.3 \
+ rpc.3 svcfd_create.3 \
+ rpc.3 svcraw_create.3 \
+ rpc.3 svctcp_create.3 \
+ rpc.3 svcudp_bufcreate.3 \
+ rpc.3 xdr_accepted_reply.3 \
+ rpc.3 xdr_authunix_parms.3 \
+ rpc.3 xdr_callhdr.3 \
+ rpc.3 xdr_callmsg.3 \
+ rpc.3 xdr_opaque_auth.3 \
+ rpc.3 xdr_pmap.3 \
+ rpc.3 xdr_pmaplist.3 \
+ rpc.3 xdr_rejected_reply.3 \
+ rpc.3 xdr_replymsg.3 \
+ rpc.3 xprt_register.3 \
+ rpc.3 xprt_unregister.3 \
+
+MLINKS+=getrpcent.3 getrpcbyname.3 getrpcent.3 getrpcbynumber.3
+.endif
diff --git a/lib/libc/rpc/PSD.doc/nfs.rfc.ms b/lib/libc/rpc/PSD.doc/nfs.rfc.ms
new file mode 100644
index 0000000..0c9a899
--- /dev/null
+++ b/lib/libc/rpc/PSD.doc/nfs.rfc.ms
@@ -0,0 +1,1372 @@
+.\"
+.\" Must use -- tbl -- with this one
+.\"
+.\" @(#)nfs.rfc.ms 2.2 88/08/05 4.0 RPCSRC
+.de BT
+.if \\n%=1 .tl ''- % -''
+..
+.ND
+.\" prevent excess underlining in nroff
+.if n .fp 2 R
+.OH 'Network File System: Version 2 Protocol Specification''Page %'
+.EH 'Page %''Network File System: Version 2 Protocol Specification'
+.if \\n%=1 .bp
+.SH
+\&Network File System: Version 2 Protocol Specification
+.IX NFS "" "" "" PAGE MAJOR
+.IX "Network File System" "" "" "" PAGE MAJOR
+.IX NFS "version-2 protocol specification"
+.IX "Network File System" "version-2 protocol specification"
+.LP
+.NH 0
+\&Status of this Standard
+.LP
+Note: This document specifies a protocol that Sun Microsystems, Inc.,
+and others are using. It specifies it in standard ARPA RFC form.
+.NH 1
+\&Introduction
+.IX NFS introduction
+.LP
+The Sun Network Filesystem (NFS) protocol provides transparent remote
+access to shared filesystems over local area networks. The NFS
+protocol is designed to be machine, operating system, network architecture,
+and transport protocol independent. This independence is
+achieved through the use of Remote Procedure Call (RPC) primitives
+built on top of an External Data Representation (XDR). Implementations
+exist for a variety of machines, from personal computers to
+supercomputers.
+.LP
+The supporting mount protocol allows the server to hand out remote
+access privileges to a restricted set of clients. It performs the
+operating system-specific functions that allow, for example, to
+attach remote directory trees to some local file system.
+.NH 2
+\&Remote Procedure Call
+.IX "Remote Procedure Call"
+.LP
+Sun's remote procedure call specification provides a procedure-
+oriented interface to remote services. Each server supplies a
+program that is a set of procedures. NFS is one such "program".
+The combination of host address, program number, and procedure
+number specifies one remote service procedure. RPC does not depend
+on services provided by specific protocols, so it can be used with
+any underlying transport protocol. See the
+.I "Remote Procedure Calls: Protocol Specification"
+chapter of this manual.
+.NH 2
+\&External Data Representation
+.IX "External Data Representation"
+.LP
+The External Data Representation (XDR) standard provides a common
+way of representing a set of data types over a network.
+The NFS
+Protocol Specification is written using the RPC data description
+language.
+For more information, see the
+.I " External Data Representation Standard: Protocol Specification."
+Sun provides implementations of XDR and
+RPC, but NFS does not require their use. Any software that
+provides equivalent functionality can be used, and if the encoding
+is exactly the same it can interoperate with other implementations
+of NFS.
+.NH 2
+\&Stateless Servers
+.IX "stateless servers"
+.IX servers stateless
+.LP
+The NFS protocol is stateless. That is, a server does not need to
+maintain any extra state information about any of its clients in
+order to function correctly. Stateless servers have a distinct
+advantage over stateful servers in the event of a failure. With
+stateless servers, a client need only retry a request until the
+server responds; it does not even need to know that the server has
+crashed, or the network temporarily went down. The client of a
+stateful server, on the other hand, needs to either detect a server
+crash and rebuild the server's state when it comes back up, or
+cause client operations to fail.
+.LP
+This may not sound like an important issue, but it affects the
+protocol in some unexpected ways. We feel that it is worth a bit
+of extra complexity in the protocol to be able to write very simple
+servers that do not require fancy crash recovery.
+.LP
+On the other hand, NFS deals with objects such as files and
+directories that inherently have state -- what good would a file be
+if it did not keep its contents intact? The goal is to not
+introduce any extra state in the protocol itself. Another way to
+simplify recovery is by making operations "idempotent" whenever
+possible (so that they can potentially be repeated).
+.NH 1
+\&NFS Protocol Definition
+.IX NFS "protocol definition"
+.IX NFS protocol
+.LP
+Servers have been known to change over time, and so can the
+protocol that they use. So RPC provides a version number with each
+RPC request. This RFC describes version two of the NFS protocol.
+Even in the second version, there are various obsolete procedures
+and parameters, which will be removed in later versions. An RFC
+for version three of the NFS protocol is currently under
+preparation.
+.NH 2
+\&File System Model
+.IX filesystem model
+.LP
+NFS assumes a file system that is hierarchical, with directories as
+all but the bottom-level files. Each entry in a directory (file,
+directory, device, etc.) has a string name. Different operating
+systems may have restrictions on the depth of the tree or the names
+used, as well as using different syntax to represent the "pathname",
+which is the concatenation of all the "components" (directory and
+file names) in the name. A "file system" is a tree on a single
+server (usually a single disk or physical partition) with a specified
+"root". Some operating systems provide a "mount" operation to make
+all file systems appear as a single tree, while others maintain a
+"forest" of file systems. Files are unstructured streams of
+uninterpreted bytes. Version 3 of NFS uses a slightly more general
+file system model.
+.LP
+NFS looks up one component of a pathname at a time. It may not be
+obvious why it does not just take the whole pathname, traipse down
+the directories, and return a file handle when it is done. There are
+several good reasons not to do this. First, pathnames need
+separators between the directory components, and different operating
+systems use different separators. We could define a Network Standard
+Pathname Representation, but then every pathname would have to be
+parsed and converted at each end. Other issues are discussed in
+\fINFS Implementation Issues\fP below.
+.LP
+Although files and directories are similar objects in many ways,
+different procedures are used to read directories and files. This
+provides a network standard format for representing directories. The
+same argument as above could have been used to justify a procedure
+that returns only one directory entry per call. The problem is
+efficiency. Directories can contain many entries, and a remote call
+to return each would be just too slow.
+.NH 2
+\&RPC Information
+.IX NFS "RPC information"
+.IP \fIAuthentication\fP
+The NFS service uses
+.I AUTH_UNIX ,
+.I AUTH_DES ,
+or
+.I AUTH_SHORT
+style
+authentication, except in the NULL procedure where
+.I AUTH_NONE
+is also allowed.
+.IP "\fITransport Protocols\fP"
+NFS currently is supported on UDP/IP only.
+.IP "\fIPort Number\fP"
+The NFS protocol currently uses the UDP port number 2049. This is
+not an officially assigned port, so later versions of the protocol
+use the \*QPortmapping\*U facility of RPC.
+.NH 2
+\&Sizes of XDR Structures
+.IX "XDR structure sizes"
+.LP
+These are the sizes, given in decimal bytes, of various XDR
+structures used in the protocol:
+.DS
+/* \fIThe maximum number of bytes of data in a READ or WRITE request\fP */
+const MAXDATA = 8192;
+
+/* \fIThe maximum number of bytes in a pathname argument\fP */
+const MAXPATHLEN = 1024;
+
+/* \fIThe maximum number of bytes in a file name argument\fP */
+const MAXNAMLEN = 255;
+
+/* \fIThe size in bytes of the opaque "cookie" passed by READDIR\fP */
+const COOKIESIZE = 4;
+
+/* \fIThe size in bytes of the opaque file handle\fP */
+const FHSIZE = 32;
+.DE
+.NH 2
+\&Basic Data Types
+.IX "NFS data types"
+.IX NFS "basic data types"
+.LP
+The following XDR definitions are basic structures and types used
+in other structures described further on.
+.KS
+.NH 3
+\&stat
+.IX "NFS data types" stat "" \fIstat\fP
+.DS
+enum stat {
+ NFS_OK = 0,
+ NFSERR_PERM=1,
+ NFSERR_NOENT=2,
+ NFSERR_IO=5,
+ NFSERR_NXIO=6,
+ NFSERR_ACCES=13,
+ NFSERR_EXIST=17,
+ NFSERR_NODEV=19,
+ NFSERR_NOTDIR=20,
+ NFSERR_ISDIR=21,
+ NFSERR_FBIG=27,
+ NFSERR_NOSPC=28,
+ NFSERR_ROFS=30,
+ NFSERR_NAMETOOLONG=63,
+ NFSERR_NOTEMPTY=66,
+ NFSERR_DQUOT=69,
+ NFSERR_STALE=70,
+ NFSERR_WFLUSH=99
+};
+.DE
+.KE
+.LP
+The
+.I stat
+type is returned with every procedure's results. A
+value of
+.I NFS_OK
+indicates that the call completed successfully and
+the results are valid. The other values indicate some kind of
+error occurred on the server side during the servicing of the
+procedure. The error values are derived from UNIX error numbers.
+.IP \fBNFSERR_PERM\fP:
+Not owner. The caller does not have correct ownership
+to perform the requested operation.
+.IP \fBNFSERR_NOENT\fP:
+No such file or directory. The file or directory
+specified does not exist.
+.IP \fBNFSERR_IO\fP:
+Some sort of hard error occurred when the operation was
+in progress. This could be a disk error, for example.
+.IP \fBNFSERR_NXIO\fP:
+No such device or address.
+.IP \fBNFSERR_ACCES\fP:
+Permission denied. The caller does not have the
+correct permission to perform the requested operation.
+.IP \fBNFSERR_EXIST\fP:
+File exists. The file specified already exists.
+.IP \fBNFSERR_NODEV\fP:
+No such device.
+.IP \fBNFSERR_NOTDIR\fP:
+Not a directory. The caller specified a
+non-directory in a directory operation.
+.IP \fBNFSERR_ISDIR\fP:
+Is a directory. The caller specified a directory in
+a non- directory operation.
+.IP \fBNFSERR_FBIG\fP:
+File too large. The operation caused a file to grow
+beyond the server's limit.
+.IP \fBNFSERR_NOSPC\fP:
+No space left on device. The operation caused the
+server's filesystem to reach its limit.
+.IP \fBNFSERR_ROFS\fP:
+Read-only filesystem. Write attempted on a read-only filesystem.
+.IP \fBNFSERR_NAMETOOLONG\fP:
+File name too long. The file name in an operation was too long.
+.IP \fBNFSERR_NOTEMPTY\fP:
+Directory not empty. Attempted to remove a
+directory that was not empty.
+.IP \fBNFSERR_DQUOT\fP:
+Disk quota exceeded. The client's disk quota on the
+server has been exceeded.
+.IP \fBNFSERR_STALE\fP:
+The "fhandle" given in the arguments was invalid.
+That is, the file referred to by that file handle no longer exists,
+or access to it has been revoked.
+.IP \fBNFSERR_WFLUSH\fP:
+The server's write cache used in the
+.I WRITECACHE
+call got flushed to disk.
+.LP
+.KS
+.NH 3
+\&ftype
+.IX "NFS data types" ftype "" \fIftype\fP
+.DS
+enum ftype {
+ NFNON = 0,
+ NFREG = 1,
+ NFDIR = 2,
+ NFBLK = 3,
+ NFCHR = 4,
+ NFLNK = 5
+};
+.DE
+.KE
+The enumeration
+.I ftype
+gives the type of a file. The type
+.I NFNON
+indicates a non-file,
+.I NFREG
+is a regular file,
+.I NFDIR
+is a directory,
+.I NFBLK
+is a block-special device,
+.I NFCHR
+is a character-special device, and
+.I NFLNK
+is a symbolic link.
+.KS
+.NH 3
+\&fhandle
+.IX "NFS data types" fhandle "" \fIfhandle\fP
+.DS
+typedef opaque fhandle[FHSIZE];
+.DE
+.KE
+The
+.I fhandle
+is the file handle passed between the server and the client.
+All file operations are done using file handles to refer to a file or
+directory. The file handle can contain whatever information the server
+needs to distinguish an individual file.
+.KS
+.NH 3
+\&timeval
+.IX "NFS data types" timeval "" \fItimeval\fP
+.DS
+struct timeval {
+ unsigned int seconds;
+ unsigned int useconds;
+};
+.DE
+.KE
+The
+.I timeval
+structure is the number of seconds and microseconds
+since midnight January 1, 1970, Greenwich Mean Time. It is used to
+pass time and date information.
+.KS
+.NH 3
+\&fattr
+.IX "NFS data types" fattr "" \fIfattr\fP
+.DS
+struct fattr {
+ ftype type;
+ unsigned int mode;
+ unsigned int nlink;
+ unsigned int uid;
+ unsigned int gid;
+ unsigned int size;
+ unsigned int blocksize;
+ unsigned int rdev;
+ unsigned int blocks;
+ unsigned int fsid;
+ unsigned int fileid;
+ timeval atime;
+ timeval mtime;
+ timeval ctime;
+};
+.DE
+.KE
+The
+.I fattr
+structure contains the attributes of a file; "type" is the type of
+the file; "nlink" is the number of hard links to the file (the number
+of different names for the same file); "uid" is the user
+identification number of the owner of the file; "gid" is the group
+identification number of the group of the file; "size" is the size in
+bytes of the file; "blocksize" is the size in bytes of a block of the
+file; "rdev" is the device number of the file if it is type
+.I NFCHR
+or
+.I NFBLK ;
+"blocks" is the number of blocks the file takes up on disk; "fsid" is
+the file system identifier for the filesystem containing the file;
+"fileid" is a number that uniquely identifies the file within its
+filesystem; "atime" is the time when the file was last accessed for
+either read or write; "mtime" is the time when the file data was last
+modified (written); and "ctime" is the time when the status of the
+file was last changed. Writing to the file also changes "ctime" if
+the size of the file changes.
+.LP
+"mode" is the access mode encoded as a set of bits. Notice that the
+file type is specified both in the mode bits and in the file type.
+This is really a bug in the protocol and will be fixed in future
+versions. The descriptions given below specify the bit positions
+using octal numbers.
+.TS
+box tab (&) ;
+cfI cfI
+lfL l .
+Bit&Description
+_
+0040000&This is a directory; "type" field should be NFDIR.
+0020000&This is a character special file; "type" field should be NFCHR.
+0060000&This is a block special file; "type" field should be NFBLK.
+0100000&This is a regular file; "type" field should be NFREG.
+0120000&This is a symbolic link file; "type" field should be NFLNK.
+0140000&This is a named socket; "type" field should be NFNON.
+0004000&Set user id on execution.
+0002000&Set group id on execution.
+0001000&Save swapped text even after use.
+0000400&Read permission for owner.
+0000200&Write permission for owner.
+0000100&Execute and search permission for owner.
+0000040&Read permission for group.
+0000020&Write permission for group.
+0000010&Execute and search permission for group.
+0000004&Read permission for others.
+0000002&Write permission for others.
+0000001&Execute and search permission for others.
+.TE
+.KS
+Notes:
+.IP
+The bits are the same as the mode bits returned by the
+.I stat(2)
+system call in the UNIX system. The file type is specified both in
+the mode bits and in the file type. This is fixed in future
+versions.
+.IP
+The "rdev" field in the attributes structure is an operating system
+specific device specifier. It will be removed and generalized in
+the next revision of the protocol.
+.KE
+.LP
+.KS
+.NH 3
+\&sattr
+.IX "NFS data types" sattr "" \fIsattr\fP
+.DS
+struct sattr {
+ unsigned int mode;
+ unsigned int uid;
+ unsigned int gid;
+ unsigned int size;
+ timeval atime;
+ timeval mtime;
+};
+.DE
+.KE
+The
+.I sattr
+structure contains the file attributes which can be set
+from the client. The fields are the same as for
+.I fattr
+above. A "size" of zero means the file should be truncated.
+A value of -1 indicates a field that should be ignored.
+.LP
+.KS
+.NH 3
+\&filename
+.IX "NFS data types" filename "" \fIfilename\fP
+.DS
+typedef string filename<MAXNAMLEN>;
+.DE
+.KE
+The type
+.I filename
+is used for passing file names or pathname components.
+.LP
+.KS
+.NH 3
+\&path
+.IX "NFS data types" path "" \fIpath\fP
+.DS
+typedef string path<MAXPATHLEN>;
+.DE
+.KE
+The type
+.I path
+is a pathname. The server considers it as a string
+with no internal structure, but to the client it is the name of a
+node in a filesystem tree.
+.LP
+.KS
+.NH 3
+\&attrstat
+.IX "NFS data types" attrstat "" \fIattrstat\fP
+.DS
+union attrstat switch (stat status) {
+ case NFS_OK:
+ fattr attributes;
+ default:
+ void;
+};
+.DE
+.KE
+The
+.I attrstat
+structure is a common procedure result. It contains
+a "status" and, if the call succeeded, it also contains the
+attributes of the file on which the operation was done.
+.LP
+.KS
+.NH 3
+\&diropargs
+.IX "NFS data types" diropargs "" \fIdiropargs\fP
+.DS
+struct diropargs {
+ fhandle dir;
+ filename name;
+};
+.DE
+.KE
+The
+.I diropargs
+structure is used in directory operations. The
+"fhandle" "dir" is the directory in which to find the file "name".
+A directory operation is one in which the directory is affected.
+.LP
+.KS
+.NH 3
+\&diropres
+.IX "NFS data types" diropres "" \fIdiropres\fP
+.DS
+union diropres switch (stat status) {
+ case NFS_OK:
+ struct {
+ fhandle file;
+ fattr attributes;
+ } diropok;
+ default:
+ void;
+};
+.DE
+.KE
+The results of a directory operation are returned in a
+.I diropres
+structure. If the call succeeded, a new file handle "file" and the
+"attributes" associated with that file are returned along with the
+"status".
+.NH 2
+\&Server Procedures
+.IX "NFS server procedures" "" "" "" PAGE MAJOR
+.LP
+The protocol definition is given as a set of procedures with
+arguments and results defined using the RPC language. A brief
+description of the function of each procedure should provide enough
+information to allow implementation.
+.LP
+All of the procedures in the NFS protocol are assumed to be
+synchronous. When a procedure returns to the client, the client
+can assume that the operation has completed and any data associated
+with the request is now on stable storage. For example, a client
+.I WRITE
+request may cause the server to update data blocks,
+filesystem information blocks (such as indirect blocks), and file
+attribute information (size and modify times). When the
+.I WRITE
+returns to the client, it can assume that the write is safe, even
+in case of a server crash, and it can discard the data written.
+This is a very important part of the statelessness of the server.
+If the server waited to flush data from remote requests, the client
+would have to save those requests so that it could resend them in
+case of a server crash.
+.ie t .DS
+.el .DS L
+
+.ft I
+/*
+* Remote file service routines
+*/
+.ft CW
+program NFS_PROGRAM {
+ version NFS_VERSION {
+ void NFSPROC_NULL(void) = 0;
+ attrstat NFSPROC_GETATTR(fhandle) = 1;
+ attrstat NFSPROC_SETATTR(sattrargs) = 2;
+ void NFSPROC_ROOT(void) = 3;
+ diropres NFSPROC_LOOKUP(diropargs) = 4;
+ readlinkres NFSPROC_READLINK(fhandle) = 5;
+ readres NFSPROC_READ(readargs) = 6;
+ void NFSPROC_WRITECACHE(void) = 7;
+ attrstat NFSPROC_WRITE(writeargs) = 8;
+ diropres NFSPROC_CREATE(createargs) = 9;
+ stat NFSPROC_REMOVE(diropargs) = 10;
+ stat NFSPROC_RENAME(renameargs) = 11;
+ stat NFSPROC_LINK(linkargs) = 12;
+ stat NFSPROC_SYMLINK(symlinkargs) = 13;
+ diropres NFSPROC_MKDIR(createargs) = 14;
+ stat NFSPROC_RMDIR(diropargs) = 15;
+ readdirres NFSPROC_READDIR(readdirargs) = 16;
+ statfsres NFSPROC_STATFS(fhandle) = 17;
+ } = 2;
+} = 100003;
+.DE
+.KS
+.NH 3
+\&Do Nothing
+.IX "NFS server procedures" NFSPROC_NULL() "" \fINFSPROC_NULL()\fP
+.DS
+void
+NFSPROC_NULL(void) = 0;
+.DE
+.KE
+This procedure does no work. It is made available in all RPC
+services to allow server response testing and timing.
+.KS
+.NH 3
+\&Get File Attributes
+.IX "NFS server procedures" NFSPROC_GETATTR() "" \fINFSPROC_GETATTR()\fP
+.DS
+attrstat
+NFSPROC_GETATTR (fhandle) = 1;
+.DE
+.KE
+If the reply status is
+.I NFS_OK ,
+then the reply attributes contains
+the attributes for the file given by the input fhandle.
+.KS
+.NH 3
+\&Set File Attributes
+.IX "NFS server procedures" NFSPROC_SETATTR() "" \fINFSPROC_SETATTR()\fP
+.DS
+struct sattrargs {
+ fhandle file;
+ sattr attributes;
+ };
+
+attrstat
+NFSPROC_SETATTR (sattrargs) = 2;
+.DE
+.KE
+The "attributes" argument contains fields which are either -1 or
+are the new value for the attributes of "file". If the reply
+status is
+.I NFS_OK ,
+then the reply attributes have the attributes of
+the file after the "SETATTR" operation has completed.
+.LP
+Note: The use of -1 to indicate an unused field in "attributes" is
+changed in the next version of the protocol.
+.KS
+.NH 3
+\&Get Filesystem Root
+.IX "NFS server procedures" NFSPROC_ROOT "" \fINFSPROC_ROOT\fP
+.DS
+void
+NFSPROC_ROOT(void) = 3;
+.DE
+.KE
+Obsolete. This procedure is no longer used because finding the
+root file handle of a filesystem requires moving pathnames between
+client and server. To do this right we would have to define a
+network standard representation of pathnames. Instead, the
+function of looking up the root file handle is done by the
+.I MNTPROC_MNT()
+procedure. (See the
+.I "Mount Protocol Definition"
+later in this chapter for details).
+.KS
+.NH 3
+\&Look Up File Name
+.IX "NFS server procedures" NFSPROC_LOOKUP() "" \fINFSPROC_LOOKUP()\fP
+.DS
+diropres
+NFSPROC_LOOKUP(diropargs) = 4;
+.DE
+.KE
+If the reply "status" is
+.I NFS_OK ,
+then the reply "file" and reply
+"attributes" are the file handle and attributes for the file "name"
+in the directory given by "dir" in the argument.
+.KS
+.NH 3
+\&Read From Symbolic Link
+.IX "NFS server procedures" NFSPROC_READLINK() "" \fINFSPROC_READLINK()\fP
+.DS
+union readlinkres switch (stat status) {
+ case NFS_OK:
+ path data;
+ default:
+ void;
+};
+
+readlinkres
+NFSPROC_READLINK(fhandle) = 5;
+.DE
+.KE
+If "status" has the value
+.I NFS_OK ,
+then the reply "data" is the data in
+the symbolic link given by the file referred to by the fhandle argument.
+.LP
+Note: since NFS always parses pathnames on the client, the
+pathname in a symbolic link may mean something different (or be
+meaningless) on a different client or on the server if a different
+pathname syntax is used.
+.KS
+.NH 3
+\&Read From File
+.IX "NFS server procedures" NFSPROC_READ "" \fINFSPROC_READ\fP
+.DS
+struct readargs {
+ fhandle file;
+ unsigned offset;
+ unsigned count;
+ unsigned totalcount;
+};
+
+union readres switch (stat status) {
+ case NFS_OK:
+ fattr attributes;
+ opaque data<NFS_MAXDATA>;
+ default:
+ void;
+};
+
+readres
+NFSPROC_READ(readargs) = 6;
+.DE
+.KE
+Returns up to "count" bytes of "data" from the file given by
+"file", starting at "offset" bytes from the beginning of the file.
+The first byte of the file is at offset zero. The file attributes
+after the read takes place are returned in "attributes".
+.LP
+Note: The argument "totalcount" is unused, and is removed in the
+next protocol revision.
+.KS
+.NH 3
+\&Write to Cache
+.IX "NFS server procedures" NFSPROC_WRITECACHE() "" \fINFSPROC_WRITECACHE()\fP
+.DS
+void
+NFSPROC_WRITECACHE(void) = 7;
+.DE
+.KE
+To be used in the next protocol revision.
+.KS
+.NH 3
+\&Write to File
+.IX "NFS server procedures" NFSPROC_WRITE() "" \fINFSPROC_WRITE()\fP
+.DS
+struct writeargs {
+ fhandle file;
+ unsigned beginoffset;
+ unsigned offset;
+ unsigned totalcount;
+ opaque data<NFS_MAXDATA>;
+};
+
+attrstat
+NFSPROC_WRITE(writeargs) = 8;
+.DE
+.KE
+Writes "data" beginning "offset" bytes from the beginning of
+"file". The first byte of the file is at offset zero. If the
+reply "status" is NFS_OK, then the reply "attributes" contains the
+attributes of the file after the write has completed. The write
+operation is atomic. Data from this call to
+.I WRITE
+will not be mixed with data from another client's calls.
+.LP
+Note: The arguments "beginoffset" and "totalcount" are ignored and
+are removed in the next protocol revision.
+.KS
+.NH 3
+\&Create File
+.IX "NFS server procedures" NFSPROC_CREATE() "" \fINFSPROC_CREATE()\fP
+.DS
+struct createargs {
+ diropargs where;
+ sattr attributes;
+};
+
+diropres
+NFSPROC_CREATE(createargs) = 9;
+.DE
+.KE
+The file "name" is created in the directory given by "dir". The
+initial attributes of the new file are given by "attributes". A
+reply "status" of NFS_OK indicates that the file was created, and
+reply "file" and reply "attributes" are its file handle and
+attributes. Any other reply "status" means that the operation
+failed and no file was created.
+.LP
+Note: This routine should pass an exclusive create flag, meaning
+"create the file only if it is not already there".
+.KS
+.NH 3
+\&Remove File
+.IX "NFS server procedures" NFSPROC_REMOVE() "" \fINFSPROC_REMOVE()\fP
+.DS
+stat
+NFSPROC_REMOVE(diropargs) = 10;
+.DE
+.KE
+The file "name" is removed from the directory given by "dir". A
+reply of NFS_OK means the directory entry was removed.
+.LP
+Note: possibly non-idempotent operation.
+.KS
+.NH 3
+\&Rename File
+.IX "NFS server procedures" NFSPROC_RENAME() "" \fINFSPROC_RENAME()\fP
+.DS
+struct renameargs {
+ diropargs from;
+ diropargs to;
+};
+
+stat
+NFSPROC_RENAME(renameargs) = 11;
+.DE
+.KE
+The existing file "from.name" in the directory given by "from.dir"
+is renamed to "to.name" in the directory given by "to.dir". If the
+reply is
+.I NFS_OK ,
+the file was renamed. The
+RENAME
+operation is
+atomic on the server; it cannot be interrupted in the middle.
+.LP
+Note: possibly non-idempotent operation.
+.KS
+.NH 3
+\&Create Link to File
+.IX "NFS server procedures" NFSPROC_LINK() "" \fINFSPROC_LINK()\fP
+.DS
+struct linkargs {
+ fhandle from;
+ diropargs to;
+};
+
+stat
+NFSPROC_LINK(linkargs) = 12;
+.DE
+.KE
+Creates the file "to.name" in the directory given by "to.dir",
+which is a hard link to the existing file given by "from". If the
+return value is
+.I NFS_OK ,
+a link was created. Any other return value
+indicates an error, and the link was not created.
+.LP
+A hard link should have the property that changes to either of the
+linked files are reflected in both files. When a hard link is made
+to a file, the attributes for the file should have a value for
+"nlink" that is one greater than the value before the link.
+.LP
+Note: possibly non-idempotent operation.
+.KS
+.NH 3
+\&Create Symbolic Link
+.IX "NFS server procedures" NFSPROC_SYMLINK() "" \fINFSPROC_SYMLINK()\fP
+.DS
+struct symlinkargs {
+ diropargs from;
+ path to;
+ sattr attributes;
+};
+
+stat
+NFSPROC_SYMLINK(symlinkargs) = 13;
+.DE
+.KE
+Creates the file "from.name" with ftype
+.I NFLNK
+in the directory
+given by "from.dir". The new file contains the pathname "to" and
+has initial attributes given by "attributes". If the return value
+is
+.I NFS_OK ,
+a link was created. Any other return value indicates an
+error, and the link was not created.
+.LP
+A symbolic link is a pointer to another file. The name given in
+"to" is not interpreted by the server, only stored in the newly
+created file. When the client references a file that is a symbolic
+link, the contents of the symbolic link are normally transparently
+reinterpreted as a pathname to substitute. A
+.I READLINK
+operation returns the data to the client for interpretation.
+.LP
+Note: On UNIX servers the attributes are never used, since
+symbolic links always have mode 0777.
+.KS
+.NH 3
+\&Create Directory
+.IX "NFS server procedures" NFSPROC_MKDIR() "" \fINFSPROC_MKDIR()\fP
+.DS
+diropres
+NFSPROC_MKDIR (createargs) = 14;
+.DE
+.KE
+The new directory "where.name" is created in the directory given by
+"where.dir". The initial attributes of the new directory are given
+by "attributes". A reply "status" of NFS_OK indicates that the new
+directory was created, and reply "file" and reply "attributes" are
+its file handle and attributes. Any other reply "status" means
+that the operation failed and no directory was created.
+.LP
+Note: possibly non-idempotent operation.
+.KS
+.NH 3
+\&Remove Directory
+.IX "NFS server procedures" NFSPROC_RMDIR() "" \fINFSPROC_RMDIR()\fP
+.DS
+stat
+NFSPROC_RMDIR(diropargs) = 15;
+.DE
+.KE
+The existing empty directory "name" in the directory given by "dir"
+is removed. If the reply is
+.I NFS_OK ,
+the directory was removed.
+.LP
+Note: possibly non-idempotent operation.
+.KS
+.NH 3
+\&Read From Directory
+.IX "NFS server procedures" NFSPROC_READDIR() "" \fINFSPROC_READDIR()\fP
+.DS
+struct readdirargs {
+ fhandle dir;
+ nfscookie cookie;
+ unsigned count;
+};
+
+struct entry {
+ unsigned fileid;
+ filename name;
+ nfscookie cookie;
+ entry *nextentry;
+};
+
+union readdirres switch (stat status) {
+ case NFS_OK:
+ struct {
+ entry *entries;
+ bool eof;
+ } readdirok;
+ default:
+ void;
+};
+
+readdirres
+NFSPROC_READDIR (readdirargs) = 16;
+.DE
+.KE
+Returns a variable number of directory entries, with a total size
+of up to "count" bytes, from the directory given by "dir". If the
+returned value of "status" is
+.I NFS_OK ,
+then it is followed by a
+variable number of "entry"s. Each "entry" contains a "fileid"
+which consists of a unique number to identify the file within a
+filesystem, the "name" of the file, and a "cookie" which is an
+opaque pointer to the next entry in the directory. The cookie is
+used in the next
+.I READDIR
+call to get more entries starting at a
+given point in the directory. The special cookie zero (all bits
+zero) can be used to get the entries starting at the beginning of
+the directory. The "fileid" field should be the same number as the
+"fileid" in the the attributes of the file. (See the
+.I "Basic Data Types"
+section.)
+The "eof" flag has a value of
+.I TRUE
+if there are no more entries in the directory.
+.KS
+.NH 3
+\&Get Filesystem Attributes
+.IX "NFS server procedures" NFSPROC_STATFS() "" \fINFSPROC_STATFS()\fP
+.DS
+union statfsres (stat status) {
+ case NFS_OK:
+ struct {
+ unsigned tsize;
+ unsigned bsize;
+ unsigned blocks;
+ unsigned bfree;
+ unsigned bavail;
+ } info;
+ default:
+ void;
+};
+
+statfsres
+NFSPROC_STATFS(fhandle) = 17;
+.DE
+.KE
+If the reply "status" is
+.I NFS_OK ,
+then the reply "info" gives the
+attributes for the filesystem that contains file referred to by the
+input fhandle. The attribute fields contain the following values:
+.IP tsize:
+The optimum transfer size of the server in bytes. This is
+the number of bytes the server would like to have in the
+data part of READ and WRITE requests.
+.IP bsize:
+The block size in bytes of the filesystem.
+.IP blocks:
+The total number of "bsize" blocks on the filesystem.
+.IP bfree:
+The number of free "bsize" blocks on the filesystem.
+.IP bavail:
+The number of "bsize" blocks available to non-privileged users.
+.LP
+Note: This call does not work well if a filesystem has variable
+size blocks.
+.NH 1
+\&NFS Implementation Issues
+.IX NFS implementation
+.LP
+The NFS protocol is designed to be operating system independent, but
+since this version was designed in a UNIX environment, many
+operations have semantics similar to the operations of the UNIX file
+system. This section discusses some of the implementation-specific
+semantic issues.
+.NH 2
+\&Server/Client Relationship
+.IX NFS "server/client relationship"
+.LP
+The NFS protocol is designed to allow servers to be as simple and
+general as possible. Sometimes the simplicity of the server can be a
+problem, if the client wants to implement complicated filesystem
+semantics.
+.LP
+For example, some operating systems allow removal of open files. A
+process can open a file and, while it is open, remove it from the
+directory. The file can be read and written as long as the process
+keeps it open, even though the file has no name in the filesystem.
+It is impossible for a stateless server to implement these semantics.
+The client can do some tricks such as renaming the file on remove,
+and only removing it on close. We believe that the server provides
+enough functionality to implement most file system semantics on the
+client.
+.LP
+Every NFS client can also potentially be a server, and remote and
+local mounted filesystems can be freely intermixed. This leads to
+some interesting problems when a client travels down the directory
+tree of a remote filesystem and reaches the mount point on the server
+for another remote filesystem. Allowing the server to follow the
+second remote mount would require loop detection, server lookup, and
+user revalidation. Instead, we decided not to let clients cross a
+server's mount point. When a client does a LOOKUP on a directory on
+which the server has mounted a filesystem, the client sees the
+underlying directory instead of the mounted directory. A client can
+do remote mounts that match the server's mount points to maintain the
+server's view.
+.LP
+.NH 2
+\&Pathname Interpretation
+.IX NFS "pathname interpretation"
+.LP
+There are a few complications to the rule that pathnames are always
+parsed on the client. For example, symbolic links could have
+different interpretations on different clients. Another common
+problem for non-UNIX implementations is the special interpretation of
+the pathname ".." to mean the parent of a given directory. The next
+revision of the protocol uses an explicit flag to indicate the parent
+instead.
+.NH 2
+\&Permission Issues
+.IX NFS "permission issues"
+.LP
+The NFS protocol, strictly speaking, does not define the permission
+checking used by servers. However, it is expected that a server
+will do normal operating system permission checking using
+.I AUTH_UNIX
+style authentication as the basis of its protection mechanism. The
+server gets the client's effective "uid", effective "gid", and groups
+on each call and uses them to check permission. There are various
+problems with this method that can been resolved in interesting ways.
+.LP
+Using "uid" and "gid" implies that the client and server share the
+same "uid" list. Every server and client pair must have the same
+mapping from user to "uid" and from group to "gid". Since every
+client can also be a server, this tends to imply that the whole
+network shares the same "uid/gid" space.
+.I AUTH_DES
+(and the next
+revision of the NFS protocol) uses string names instead of numbers,
+but there are still complex problems to be solved.
+.LP
+Another problem arises due to the usually stateful open operation.
+Most operating systems check permission at open time, and then check
+that the file is open on each read and write request. With stateless
+servers, the server has no idea that the file is open and must do
+permission checking on each read and write call. On a local
+filesystem, a user can open a file and then change the permissions so
+that no one is allowed to touch it, but will still be able to write
+to the file because it is open. On a remote filesystem, by contrast,
+the write would fail. To get around this problem, the server's
+permission checking algorithm should allow the owner of a file to
+access it regardless of the permission setting.
+.LP
+A similar problem has to do with paging in from a file over the
+network. The operating system usually checks for execute permission
+before opening a file for demand paging, and then reads blocks from
+the open file. The file may not have read permission, but after it
+is opened it doesn't matter. An NFS server can not tell the
+difference between a normal file read and a demand page-in read. To
+make this work, the server allows reading of files if the "uid" given
+in the call has execute or read permission on the file.
+.LP
+In most operating systems, a particular user (on the user ID zero)
+has access to all files no matter what permission and ownership they
+have. This "super-user" permission may not be allowed on the server,
+since anyone who can become super-user on their workstation could
+gain access to all remote files. The UNIX server by default maps
+user id 0 to -2 before doing its access checking. This works except
+for NFS root filesystems, where super-user access cannot be avoided.
+.NH 2
+\&Setting RPC Parameters
+.IX NFS "setting RPC parameters"
+.LP
+Various file system parameters and options should be set at mount
+time. The mount protocol is described in the appendix below. For
+example, "Soft" mounts as well as "Hard" mounts are usually both
+provided. Soft mounted file systems return errors when RPC
+operations fail (after a given number of optional retransmissions),
+while hard mounted file systems continue to retransmit forever.
+Clients and servers may need to keep caches of recent operations to
+help avoid problems with non-idempotent operations.
+.NH 1
+\&Mount Protocol Definition
+.IX "mount protocol" "" "" "" PAGE MAJOR
+.sp 1
+.NH 2
+\&Introduction
+.IX "mount protocol" introduction
+.LP
+The mount protocol is separate from, but related to, the NFS
+protocol. It provides operating system specific services to get the
+NFS off the ground -- looking up server path names, validating user
+identity, and checking access permissions. Clients use the mount
+protocol to get the first file handle, which allows them entry into a
+remote filesystem.
+.LP
+The mount protocol is kept separate from the NFS protocol to make it
+easy to plug in new access checking and validation methods without
+changing the NFS server protocol.
+.LP
+Notice that the protocol definition implies stateful servers because
+the server maintains a list of client's mount requests. The mount
+list information is not critical for the correct functioning of
+either the client or the server. It is intended for advisory use
+only, for example, to warn possible clients when a server is going
+down.
+.LP
+Version one of the mount protocol is used with version two of the NFS
+protocol. The only connecting point is the
+.I fhandle
+structure, which is the same for both protocols.
+.NH 2
+\&RPC Information
+.IX "mount protocol" "RPC information"
+.IP \fIAuthentication\fP
+The mount service uses
+.I AUTH_UNIX
+and
+.I AUTH_DES
+style authentication only.
+.IP "\fITransport Protocols\fP"
+The mount service is currently supported on UDP/IP only.
+.IP "\fIPort Number\fP"
+Consult the server's portmapper, described in the chapter
+.I "Remote Procedure Calls: Protocol Specification",
+to find the port number on which the mount service is registered.
+.NH 2
+\&Sizes of XDR Structures
+.IX "mount protocol" "XDR structure sizes"
+.LP
+These are the sizes, given in decimal bytes, of various XDR
+structures used in the protocol:
+.DS
+/* \fIThe maximum number of bytes in a pathname argument\fP */
+const MNTPATHLEN = 1024;
+
+/* \fIThe maximum number of bytes in a name argument\fP */
+const MNTNAMLEN = 255;
+
+/* \fIThe size in bytes of the opaque file handle\fP */
+const FHSIZE = 32;
+.DE
+.NH 2
+\&Basic Data Types
+.IX "mount protocol" "basic data types"
+.IX "mount data types"
+.LP
+This section presents the data types used by the mount protocol.
+In many cases they are similar to the types used in NFS.
+.KS
+.NH 3
+\&fhandle
+.IX "mount data types" fhandle "" \fIfhandle\fP
+.DS
+typedef opaque fhandle[FHSIZE];
+.DE
+.KE
+The type
+.I fhandle
+is the file handle that the server passes to the
+client. All file operations are done using file handles to refer
+to a file or directory. The file handle can contain whatever
+information the server needs to distinguish an individual file.
+.LP
+This is the same as the "fhandle" XDR definition in version 2 of
+the NFS protocol; see
+.I "Basic Data Types"
+in the definition of the NFS protocol, above.
+.KS
+.NH 3
+\&fhstatus
+.IX "mount data types" fhstatus "" \fIfhstatus\fP
+.DS
+union fhstatus switch (unsigned status) {
+ case 0:
+ fhandle directory;
+ default:
+ void;
+};
+.DE
+.KE
+The type
+.I fhstatus
+is a union. If a "status" of zero is returned,
+the call completed successfully, and a file handle for the
+"directory" follows. A non-zero status indicates some sort of
+error. In this case the status is a UNIX error number.
+.KS
+.NH 3
+\&dirpath
+.IX "mount data types" dirpath "" \fIdirpath\fP
+.DS
+typedef string dirpath<MNTPATHLEN>;
+.DE
+.KE
+The type
+.I dirpath
+is a server pathname of a directory.
+.KS
+.NH 3
+\&name
+.IX "mount data types" name "" \fIname\fP
+.DS
+typedef string name<MNTNAMLEN>;
+.DE
+.KE
+The type
+.I name
+is an arbitrary string used for various names.
+.NH 2
+\&Server Procedures
+.IX "mount server procedures"
+.LP
+The following sections define the RPC procedures supplied by a
+mount server.
+.ie t .DS
+.el .DS L
+.ft I
+/*
+* Protocol description for the mount program
+*/
+.ft CW
+
+program MOUNTPROG {
+.ft I
+/*
+* Version 1 of the mount protocol used with
+* version 2 of the NFS protocol.
+*/
+.ft CW
+ version MOUNTVERS {
+ void MOUNTPROC_NULL(void) = 0;
+ fhstatus MOUNTPROC_MNT(dirpath) = 1;
+ mountlist MOUNTPROC_DUMP(void) = 2;
+ void MOUNTPROC_UMNT(dirpath) = 3;
+ void MOUNTPROC_UMNTALL(void) = 4;
+ exportlist MOUNTPROC_EXPORT(void) = 5;
+ } = 1;
+} = 100005;
+.DE
+.KS
+.NH 3
+\&Do Nothing
+.IX "mount server procedures" MNTPROC_NULL() "" \fIMNTPROC_NULL()\fP
+.DS
+void
+MNTPROC_NULL(void) = 0;
+.DE
+.KE
+This procedure does no work. It is made available in all RPC
+services to allow server response testing and timing.
+.KS
+.NH 3
+\&Add Mount Entry
+.IX "mount server procedures" MNTPROC_MNT() "" \fIMNTPROC_MNT()\fP
+.DS
+fhstatus
+MNTPROC_MNT(dirpath) = 1;
+.DE
+.KE
+If the reply "status" is 0, then the reply "directory" contains the
+file handle for the directory "dirname". This file handle may be
+used in the NFS protocol. This procedure also adds a new entry to
+the mount list for this client mounting "dirname".
+.KS
+.NH 3
+\&Return Mount Entries
+.IX "mount server procedures" MNTPROC_DUMP() "" \fIMNTPROC_DUMP()\fP
+.DS
+struct *mountlist {
+ name hostname;
+ dirpath directory;
+ mountlist nextentry;
+};
+
+mountlist
+MNTPROC_DUMP(void) = 2;
+.DE
+.KE
+Returns the list of remote mounted filesystems. The "mountlist"
+contains one entry for each "hostname" and "directory" pair.
+.KS
+.NH 3
+\&Remove Mount Entry
+.IX "mount server procedures" MNTPROC_UMNT() "" \fIMNTPROC_UMNT()\fP
+.DS
+void
+MNTPROC_UMNT(dirpath) = 3;
+.DE
+.KE
+Removes the mount list entry for the input "dirpath".
+.KS
+.NH 3
+\&Remove All Mount Entries
+.IX "mount server procedures" MNTPROC_UMNTALL() "" \fIMNTPROC_UMNTALL()\fP
+.DS
+void
+MNTPROC_UMNTALL(void) = 4;
+.DE
+.KE
+Removes all of the mount list entries for this client.
+.KS
+.NH 3
+\&Return Export List
+.IX "mount server procedures" MNTPROC_EXPORT() "" \fIMNTPROC_EXPORT()\fP
+.DS
+struct *groups {
+ name grname;
+ groups grnext;
+};
+
+struct *exportlist {
+ dirpath filesys;
+ groups groups;
+ exportlist next;
+};
+
+exportlist
+MNTPROC_EXPORT(void) = 5;
+.DE
+.KE
+Returns a variable number of export list entries. Each entry
+contains a filesystem name and a list of groups that are allowed to
+import it. The filesystem name is in "filesys", and the group name
+is in the list "groups".
+.LP
+Note: The exportlist should contain
+more information about the status of the filesystem, such as a
+read-only flag.
diff --git a/lib/libc/rpc/PSD.doc/rpc.prog.ms b/lib/libc/rpc/PSD.doc/rpc.prog.ms
new file mode 100644
index 0000000..3b02447
--- /dev/null
+++ b/lib/libc/rpc/PSD.doc/rpc.prog.ms
@@ -0,0 +1,2684 @@
+.\"
+.\" Must use -- tbl and pic -- with this one
+.\"
+.\" @(#)rpc.prog.ms 2.3 88/08/11 4.0 RPCSRC
+.de BT
+.if \\n%=1 .tl ''- % -''
+..
+.IX "Network Programming" "" "" "" PAGE MAJOR
+.nr OF 0
+.ND
+.\" prevent excess underlining in nroff
+.if n .fp 2 R
+.OH 'Remote Procedure Call Programming Guide''Page %'
+.EH 'Page %''Remote Procedure Call Programming Guide'
+.SH
+\&Remote Procedure Call Programming Guide
+.nr OF 1
+.IX "RPC Programming Guide"
+.LP
+This document assumes a working knowledge of network theory. It is
+intended for programmers who wish to write network applications using
+remote procedure calls (explained below), and who want to understand
+the RPC mechanisms usually hidden by the
+.I rpcgen(1)
+protocol compiler.
+.I rpcgen
+is described in detail in the previous chapter, the
+.I "\fBrpcgen\fP \fIProgramming Guide\fP".
+.SH
+Note:
+.I
+.IX rpcgen "" \fIrpcgen\fP
+Before attempting to write a network application, or to convert an
+existing non-network application to run over the network, you may want to
+understand the material in this chapter. However, for most applications,
+you can circumvent the need to cope with the details presented here by using
+.I rpcgen .
+The
+.I "Generating XDR Routines"
+section of that chapter contains the complete source for a working RPC
+service\(ema remote directory listing service which uses
+.I rpcgen
+to generate XDR routines as well as client and server stubs.
+.LP
+.LP
+What are remote procedure calls? Simply put, they are the high-level
+communications paradigm used in the operating system.
+RPC presumes the existence of
+low-level networking mechanisms (such as TCP/IP and UDP/IP), and upon them
+it implements a logical client to server communications system designed
+specifically for the support of network applications. With RPC, the client
+makes a procedure call to send a data packet to the server. When the
+packet arrives, the server calls a dispatch routine, performs whatever
+service is requested, sends back the reply, and the procedure call returns
+to the client.
+.NH 0
+\&Layers of RPC
+.IX "layers of RPC"
+.IX "RPC" "layers"
+.LP
+The RPC interface can be seen as being divided into three layers.\**
+.FS
+For a complete specification of the routines in the remote procedure
+call Library, see the
+.I rpc(3N)
+manual page.
+.FE
+.LP
+.I "The Highest Layer:"
+.IX RPC "The Highest Layer"
+The highest layer is totally transparent to the operating system,
+machine and network upon which is is run. It's probably best to
+think of this level as a way of
+.I using
+RPC, rather than as
+a \fIpart of\fP RPC proper. Programmers who write RPC routines
+should (almost) always make this layer available to others by way
+of a simple C front end that entirely hides the networking.
+.LP
+To illustrate, at this level a program can simply make a call to
+.I rnusers (),
+a C routine which returns the number of users on a remote machine.
+The user is not explicitly aware of using RPC \(em they simply
+call a procedure, just as they would call
+.I malloc() .
+.LP
+.I "The Middle Layer:"
+.IX RPC "The Middle Layer"
+The middle layer is really \*QRPC proper.\*U Here, the user doesn't
+need to consider details about sockets, the UNIX system, or other low-level
+implementation mechanisms. They simply make remote procedure calls
+to routines on other machines. The selling point here is simplicity.
+It's this layer that allows RPC to pass the \*Qhello world\*U test \(em
+simple things should be simple. The middle-layer routines are used
+for most applications.
+.LP
+RPC calls are made with the system routines
+.I registerrpc()
+.I callrpc()
+and
+.I svc_run ().
+The first two of these are the most fundamental:
+.I registerrpc()
+obtains a unique system-wide procedure-identification number, and
+.I callrpc()
+actually executes a remote procedure call. At the middle level, a
+call to
+.I rnusers()
+is implemented by way of these two routines.
+.LP
+The middle layer is unfortunately rarely used in serious programming
+due to its inflexibility (simplicity). It does not allow timeout
+specifications or the choice of transport. It allows no UNIX
+process control or flexibility in case of errors. It doesn't support
+multiple kinds of call authentication. The programmer rarely needs
+all these kinds of control, but one or two of them is often necessary.
+.LP
+.I "The Lowest Layer:"
+.IX RPC "The Lowest Layer"
+The lowest layer does allow these details to be controlled by the
+programmer, and for that reason it is often necessary. Programs
+written at this level are also most efficient, but this is rarely a
+real issue \(em since RPC clients and servers rarely generate
+heavy network loads.
+.LP
+Although this document only discusses the interface to C,
+remote procedure calls can be made from any language.
+Even though this document discusses RPC
+when it is used to communicate
+between processes on different machines,
+it works just as well for communication
+between different processes on the same machine.
+.br
+.KS
+.NH 2
+\&The RPC Paradigm
+.IX RPC paradigm
+.LP
+Here is a diagram of the RPC paradigm:
+.LP
+\fBFigure 1-1\fI Network Communication with the Remote Reocedure Call\fR
+.LP
+.PS
+L1: arrow down 1i "client " rjust "program " rjust
+L2: line right 1.5i "\fIcallrpc\fP" "function"
+move up 1.5i; line dotted down 6i; move up 4.5i
+arrow right 1i
+L3: arrow down 1i "invoke " rjust "service " rjust
+L4: arrow right 1.5i "call" "service"
+L5: arrow down 1i " service" ljust " executes" ljust
+L6: arrow left 1.5i "\fIreturn\fP" "answer"
+L7: arrow down 1i "request " rjust "completed " rjust
+L8: line left 1i
+arrow left 1.5i "\fIreturn\fP" "reply"
+L9: arrow down 1i "program " rjust "continues " rjust
+line dashed down from L2 to L9
+line dashed down from L4 to L7
+line dashed up 1i from L3 "service " rjust "daemon " rjust
+arrow dashed down 1i from L8
+move right 1i from L3
+box invis "Machine B"
+move left 1.2i from L2; move down
+box invis "Machine A"
+.PE
+.KE
+.KS
+.NH 1
+\&Higher Layers of RPC
+.NH 2
+\&Highest Layer
+.IX "highest layer of RPC"
+.IX RPC "highest layer"
+.LP
+Imagine you're writing a program that needs to know
+how many users are logged into a remote machine.
+You can do this by calling the RPC library routine
+.I rnusers()
+as illustrated below:
+.ie t .DS
+.el .DS L
+.ft CW
+#include <stdio.h>
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int num;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: rnusers hostname\en");
+ exit(1);
+ }
+ if ((num = rnusers(argv[1])) < 0) {
+ fprintf(stderr, "error: rnusers\en");
+ exit(-1);
+ }
+ printf("%d users on %s\en", num, argv[1]);
+ exit(0);
+}
+.DE
+.KE
+RPC library routines such as
+.I rnusers()
+are in the RPC services library
+.I librpcsvc.a
+Thus, the program above should be compiled with
+.DS
+.ft CW
+% cc \fIprogram.c -lrpcsvc\fP
+.DE
+.I rnusers (),
+like the other RPC library routines, is documented in section 3R
+of the
+.I "System Interface Manual for the Sun Workstation" ,
+the same section which documents the standard Sun RPC services.
+.IX "RPC Services"
+See the
+.I intro(3R)
+manual page for an explanation of the documentation strategy
+for these services and their RPC protocols.
+.LP
+Here are some of the RPC service library routines available to the
+C programmer:
+.LP
+\fBTable 3-3\fI RPC Service Library Routines\RP
+.TS
+box tab (&) ;
+cfI cfI
+lfL l .
+Routine&Description
+_
+.sp.5
+rnusers&Return number of users on remote machine
+rusers&Return information about users on remote machine
+havedisk&Determine if remote machine has disk
+rstats&Get performance data from remote kernel
+rwall&Write to specified remote machines
+yppasswd&Update user password in Yellow Pages
+.TE
+.LP
+Other RPC services \(em for example
+.I ether()
+.I mount
+.I rquota()
+and
+.I spray
+\(em are not available to the C programmer as library routines.
+They do, however,
+have RPC program numbers so they can be invoked with
+.I callrpc()
+which will be discussed in the next section. Most of them also
+have compilable
+.I rpcgen(1)
+protocol description files. (The
+.I rpcgen
+protocol compiler radically simplifies the process of developing
+network applications.
+See the \fBrpcgen\fI Programming Guide\fR
+for detailed information about
+.I rpcgen
+and
+.I rpcgen
+protocol description files).
+.KS
+.NH 2
+\&Intermediate Layer
+.IX "intermediate layer of RPC"
+.IX "RPC" "intermediate layer"
+.LP
+The simplest interface, which explicitly makes RPC calls, uses the
+functions
+.I callrpc()
+and
+.I registerrpc()
+Using this method, the number of remote users can be gotten as follows:
+.ie t .DS
+.el .DS L
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <utmp.h>
+#include <rpcsvc/rusers.h>
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ unsigned long nusers;
+ int stat;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: nusers hostname\en");
+ exit(-1);
+ }
+ if (stat = callrpc(argv[1],
+ RUSERSPROG, RUSERSVERS, RUSERSPROC_NUM,
+ xdr_void, 0, xdr_u_long, &nusers) != 0) {
+ clnt_perrno(stat);
+ exit(1);
+ }
+ printf("%d users on %s\en", nusers, argv[1]);
+ exit(0);
+}
+.DE
+.KE
+Each RPC procedure is uniquely defined by a program number,
+version number, and procedure number. The program number
+specifies a group of related remote procedures, each of
+which has a different procedure number. Each program also
+has a version number, so when a minor change is made to a
+remote service (adding a new procedure, for example), a new
+program number doesn't have to be assigned. When you want
+to call a procedure to find the number of remote users, you
+look up the appropriate program, version and procedure numbers
+in a manual, just as you look up the name of a memory allocator
+when you want to allocate memory.
+.LP
+The simplest way of making remote procedure calls is with the the RPC
+library routine
+.I callrpc()
+It has eight parameters. The first is the name of the remote server
+machine. The next three parameters are the program, version, and procedure
+numbers\(emtogether they identify the procedure to be called.
+The fifth and sixth parameters are an XDR filter and an argument to
+be encoded and passed to the remote procedure.
+The final two parameters are a filter for decoding the results
+returned by the remote procedure and a pointer to the place where
+the procedure's results are to be stored. Multiple arguments and
+results are handled by embedding them in structures. If
+.I callrpc()
+completes successfully, it returns zero; else it returns a nonzero
+value. The return codes (of type
+.IX "enum clnt_stat (in RPC programming)" "" "\fIenum clnt_stat\fP (in RPC programming)"
+cast into an integer) are found in
+.I <rpc/clnt.h> .
+.LP
+Since data types may be represented differently on different machines,
+.I callrpc()
+needs both the type of the RPC argument, as well as
+a pointer to the argument itself (and similarly for the result). For
+.I RUSERSPROC_NUM ,
+the return value is an
+.I "unsigned long"
+so
+.I callrpc()
+has
+.I xdr_u_long()
+as its first return parameter, which says
+that the result is of type
+.I "unsigned long"
+and
+.I &nusers
+as its second return parameter,
+which is a pointer to where the long result will be placed. Since
+.I RUSERSPROC_NUM
+takes no argument, the argument parameter of
+.I callrpc()
+is
+.I xdr_void ().
+.LP
+After trying several times to deliver a message, if
+.I callrpc()
+gets no answer, it returns with an error code.
+The delivery mechanism is UDP,
+which stands for User Datagram Protocol.
+Methods for adjusting the number of retries
+or for using a different protocol require you to use the lower
+layer of the RPC library, discussed later in this document.
+The remote server procedure
+corresponding to the above might look like this:
+.ie t .DS
+.el .DS L
+.ft CW
+.ft CW
+char *
+nuser(indata)
+ char *indata;
+{
+ unsigned long nusers;
+
+.ft I
+ /*
+ * Code here to compute the number of users
+ * and place result in variable \fInusers\fP.
+ */
+.ft CW
+ return((char *)&nusers);
+}
+.DE
+.LP
+It takes one argument, which is a pointer to the input
+of the remote procedure call (ignored in our example),
+and it returns a pointer to the result.
+In the current version of C,
+character pointers are the generic pointers,
+so both the input argument and the return value are cast to
+.I "char *" .
+.LP
+Normally, a server registers all of the RPC calls it plans
+to handle, and then goes into an infinite loop waiting to service requests.
+In this example, there is only a single procedure
+to register, so the main body of the server would look like this:
+.ie t .DS
+.el .DS L
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <utmp.h>
+#include <rpcsvc/rusers.h>
+
+char *nuser();
+
+main()
+{
+ registerrpc(RUSERSPROG, RUSERSVERS, RUSERSPROC_NUM,
+ nuser, xdr_void, xdr_u_long);
+ svc_run(); /* \fINever returns\fP */
+ fprintf(stderr, "Error: svc_run returned!\en");
+ exit(1);
+}
+.DE
+.LP
+The
+.I registerrpc()
+routine registers a C procedure as corresponding to a
+given RPC procedure number. The first three parameters,
+.I RUSERPROG ,
+.I RUSERSVERS ,
+and
+.I RUSERSPROC_NUM
+are the program, version, and procedure numbers
+of the remote procedure to be registered;
+.I nuser()
+is the name of the local procedure that implements the remote
+procedure; and
+.I xdr_void()
+and
+.I xdr_u_long()
+are the XDR filters for the remote procedure's arguments and
+results, respectively. (Multiple arguments or multiple results
+are passed as structures).
+.LP
+Only the UDP transport mechanism can use
+.I registerrpc()
+thus, it is always safe in conjunction with calls generated by
+.I callrpc() .
+.SH
+.IX "UDP 8K warning"
+Warning: the UDP transport mechanism can only deal with
+arguments and results less than 8K bytes in length.
+.LP
+.LP
+After registering the local procedure, the server program's
+main procedure calls
+.I svc_run (),
+the RPC library's remote procedure dispatcher. It is this
+function that calls the remote procedures in response to RPC
+call messages. Note that the dispatcher takes care of decoding
+remote procedure arguments and encoding results, using the XDR
+filters specified when the remote procedure was registered.
+.NH 2
+\&Assigning Program Numbers
+.IX "program number assignment"
+.IX "assigning program numbers"
+.LP
+Program numbers are assigned in groups of
+.I 0x20000000
+according to the following chart:
+.DS
+.ft CW
+ 0x0 - 0x1fffffff \fRDefined by Sun\fP
+0x20000000 - 0x3fffffff \fRDefined by user\fP
+0x40000000 - 0x5fffffff \fRTransient\fP
+0x60000000 - 0x7fffffff \fRReserved\fP
+0x80000000 - 0x9fffffff \fRReserved\fP
+0xa0000000 - 0xbfffffff \fRReserved\fP
+0xc0000000 - 0xdfffffff \fRReserved\fP
+0xe0000000 - 0xffffffff \fRReserved\fP
+.ft R
+.DE
+Sun Microsystems administers the first group of numbers, which
+should be identical for all Sun customers. If a customer
+develops an application that might be of general interest, that
+application should be given an assigned number in the first
+range. The second group of numbers is reserved for specific
+customer applications. This range is intended primarily for
+debugging new programs. The third group is reserved for
+applications that generate program numbers dynamically. The
+final groups are reserved for future use, and should not be
+used.
+.LP
+To register a protocol specification, send a request by network
+mail to
+.I rpc@sun
+or write to:
+.DS
+RPC Administrator
+Sun Microsystems
+2550 Garcia Ave.
+Mountain View, CA 94043
+.DE
+Please include a compilable
+.I rpcgen
+\*Q.x\*U file describing your protocol.
+You will be given a unique program number in return.
+.IX RPC administration
+.IX administration "of RPC"
+.LP
+The RPC program numbers and protocol specifications
+of standard Sun RPC services can be
+found in the include files in
+.I "/usr/include/rpcsvc" .
+These services, however, constitute only a small subset
+of those which have been registered. The complete list of
+registered programs, as of the time when this manual was
+printed, is:
+.LP
+\fBTable 3-2\fI RPC Registered Programs\fR
+.TS H
+box tab (&) ;
+lfBI lfBI lfBI
+lfL lfL lfI .
+RPC Number&Program&Description
+_
+.TH
+.sp.5
+100000&PMAPPROG&portmapper
+100001&RSTATPROG&remote stats
+100002&RUSERSPROG&remote users
+100003&NFSPROG&nfs
+100004&YPPROG&Yellow Pages
+100005&MOUNTPROG&mount demon
+100006&DBXPROG&remote dbx
+100007&YPBINDPROG&yp binder
+100008&WALLPROG&shutdown msg
+100009&YPPASSWDPROG&yppasswd server
+100010&ETHERSTATPROG&ether stats
+100011&RQUOTAPROG&disk quotas
+100012&SPRAYPROG&spray packets
+100013&IBM3270PROG&3270 mapper
+100014&IBMRJEPROG&RJE mapper
+100015&SELNSVCPROG&selection service
+100016&RDATABASEPROG&remote database access
+100017&REXECPROG&remote execution
+100018&ALICEPROG&Alice Office Automation
+100019&SCHEDPROG&scheduling service
+100020&LOCKPROG&local lock manager
+100021&NETLOCKPROG&network lock manager
+100022&X25PROG&x.25 inr protocol
+100023&STATMON1PROG&status monitor 1
+100024&STATMON2PROG&status monitor 2
+100025&SELNLIBPROG&selection library
+100026&BOOTPARAMPROG&boot parameters service
+100027&MAZEPROG&mazewars game
+100028&YPUPDATEPROG&yp update
+100029&KEYSERVEPROG&key server
+100030&SECURECMDPROG&secure login
+100031&NETFWDIPROG&nfs net forwarder init
+100032&NETFWDTPROG&nfs net forwarder trans
+100033&SUNLINKMAP_PROG&sunlink MAP
+100034&NETMONPROG&network monitor
+100035&DBASEPROG&lightweight database
+100036&PWDAUTHPROG&password authorization
+100037&TFSPROG&translucent file svc
+100038&NSEPROG&nse server
+100039&NSE_ACTIVATE_PROG&nse activate daemon
+.sp .2i
+150001&PCNFSDPROG&pc passwd authorization
+.sp .2i
+200000&PYRAMIDLOCKINGPROG&Pyramid-locking
+200001&PYRAMIDSYS5&Pyramid-sys5
+200002&CADDS_IMAGE&CV cadds_image
+.sp .2i
+300001&ADT_RFLOCKPROG&ADT file locking
+.TE
+.NH 2
+\&Passing Arbitrary Data Types
+.IX "arbitrary data types"
+.LP
+In the previous example, the RPC call passes a single
+.I "unsigned long"
+RPC can handle arbitrary data structures, regardless of
+different machines' byte orders or structure layout conventions,
+by always converting them to a network standard called
+.I "External Data Representation"
+(XDR) before
+sending them over the wire.
+The process of converting from a particular machine representation
+to XDR format is called
+.I serializing ,
+and the reverse process is called
+.I deserializing .
+The type field parameters of
+.I callrpc()
+and
+.I registerrpc()
+can be a built-in procedure like
+.I xdr_u_long()
+in the previous example, or a user supplied one.
+XDR has these built-in type routines:
+.IX RPC "built-in routines"
+.DS
+.ft CW
+xdr_int() xdr_u_int() xdr_enum()
+xdr_long() xdr_u_long() xdr_bool()
+xdr_short() xdr_u_short() xdr_wrapstring()
+xdr_char() xdr_u_char()
+.DE
+Note that the routine
+.I xdr_string()
+exists, but cannot be used with
+.I callrpc()
+and
+.I registerrpc (),
+which only pass two parameters to their XDR routines.
+.I xdr_wrapstring()
+has only two parameters, and is thus OK. It calls
+.I xdr_string ().
+.LP
+As an example of a user-defined type routine,
+if you wanted to send the structure
+.DS
+.ft CW
+struct simple {
+ int a;
+ short b;
+} simple;
+.DE
+then you would call
+.I callrpc()
+as
+.DS
+.ft CW
+callrpc(hostname, PROGNUM, VERSNUM, PROCNUM,
+ xdr_simple, &simple ...);
+.DE
+where
+.I xdr_simple()
+is written as:
+.ie t .DS
+.el .DS L
+.ft CW
+#include <rpc/rpc.h>
+
+xdr_simple(xdrsp, simplep)
+ XDR *xdrsp;
+ struct simple *simplep;
+{
+ if (!xdr_int(xdrsp, &simplep->a))
+ return (0);
+ if (!xdr_short(xdrsp, &simplep->b))
+ return (0);
+ return (1);
+}
+.DE
+.LP
+An XDR routine returns nonzero (true in the sense of C) if it
+completes successfully, and zero otherwise.
+A complete description of XDR is in the
+.I "XDR Protocol Specification"
+section of this manual, only few implementation examples are
+given here.
+.LP
+In addition to the built-in primitives,
+there are also the prefabricated building blocks:
+.DS
+.ft CW
+xdr_array() xdr_bytes() xdr_reference()
+xdr_vector() xdr_union() xdr_pointer()
+xdr_string() xdr_opaque()
+.DE
+To send a variable array of integers,
+you might package them up as a structure like this
+.DS
+.ft CW
+struct varintarr {
+ int *data;
+ int arrlnth;
+} arr;
+.DE
+and make an RPC call such as
+.DS
+.ft CW
+callrpc(hostname, PROGNUM, VERSNUM, PROCNUM,
+ xdr_varintarr, &arr...);
+.DE
+with
+.I xdr_varintarr()
+defined as:
+.ie t .DS
+.el .DS L
+.ft CW
+xdr_varintarr(xdrsp, arrp)
+ XDR *xdrsp;
+ struct varintarr *arrp;
+{
+ return (xdr_array(xdrsp, &arrp->data, &arrp->arrlnth,
+ MAXLEN, sizeof(int), xdr_int));
+}
+.DE
+This routine takes as parameters the XDR handle,
+a pointer to the array, a pointer to the size of the array,
+the maximum allowable array size,
+the size of each array element,
+and an XDR routine for handling each array element.
+.KS
+.LP
+If the size of the array is known in advance, one can use
+.I xdr_vector (),
+which serializes fixed-length arrays.
+.ie t .DS
+.el .DS L
+.ft CW
+int intarr[SIZE];
+
+xdr_intarr(xdrsp, intarr)
+ XDR *xdrsp;
+ int intarr[];
+{
+ int i;
+
+ return (xdr_vector(xdrsp, intarr, SIZE, sizeof(int),
+ xdr_int));
+}
+.DE
+.KE
+.LP
+XDR always converts quantities to 4-byte multiples when serializing.
+Thus, if either of the examples above involved characters
+instead of integers, each character would occupy 32 bits.
+That is the reason for the XDR routine
+.I xdr_bytes()
+which is like
+.I xdr_array()
+except that it packs characters;
+.I xdr_bytes()
+has four parameters, similar to the first four parameters of
+.I xdr_array ().
+For null-terminated strings, there is also the
+.I xdr_string()
+routine, which is the same as
+.I xdr_bytes()
+without the length parameter.
+On serializing it gets the string length from
+.I strlen (),
+and on deserializing it creates a null-terminated string.
+.LP
+Here is a final example that calls the previously written
+.I xdr_simple()
+as well as the built-in functions
+.I xdr_string()
+and
+.I xdr_reference (),
+which chases pointers:
+.ie t .DS
+.el .DS L
+.ft CW
+struct finalexample {
+ char *string;
+ struct simple *simplep;
+} finalexample;
+
+xdr_finalexample(xdrsp, finalp)
+ XDR *xdrsp;
+ struct finalexample *finalp;
+{
+
+ if (!xdr_string(xdrsp, &finalp->string, MAXSTRLEN))
+ return (0);
+ if (!xdr_reference(xdrsp, &finalp->simplep,
+ sizeof(struct simple), xdr_simple);
+ return (0);
+ return (1);
+}
+.DE
+Note that we could as easily call
+.I xdr_simple()
+here instead of
+.I xdr_reference ().
+.NH 1
+\&Lowest Layer of RPC
+.IX "lowest layer of RPC"
+.IX "RPC" "lowest layer"
+.LP
+In the examples given so far,
+RPC takes care of many details automatically for you.
+In this section, we'll show you how you can change the defaults
+by using lower layers of the RPC library.
+It is assumed that you are familiar with sockets
+and the system calls for dealing with them.
+.LP
+There are several occasions when you may need to use lower layers of
+RPC. First, you may need to use TCP, since the higher layer uses UDP,
+which restricts RPC calls to 8K bytes of data. Using TCP permits calls
+to send long streams of data.
+For an example, see the
+.I TCP
+section below. Second, you may want to allocate and free memory
+while serializing or deserializing with XDR routines.
+There is no call at the higher level to let
+you free memory explicitly.
+For more explanation, see the
+.I "Memory Allocation with XDR"
+section below.
+Third, you may need to perform authentication
+on either the client or server side, by supplying
+credentials or verifying them.
+See the explanation in the
+.I Authentication
+section below.
+.NH 2
+\&More on the Server Side
+.IX RPC "server side"
+.LP
+The server for the
+.I nusers()
+program shown below does the same thing as the one using
+.I registerrpc()
+above, but is written using a lower layer of the RPC package:
+.ie t .DS
+.el .DS L
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <utmp.h>
+#include <rpcsvc/rusers.h>
+
+main()
+{
+ SVCXPRT *transp;
+ int nuser();
+
+ transp = svcudp_create(RPC_ANYSOCK);
+ if (transp == NULL){
+ fprintf(stderr, "can't create an RPC server\en");
+ exit(1);
+ }
+ pmap_unset(RUSERSPROG, RUSERSVERS);
+ if (!svc_register(transp, RUSERSPROG, RUSERSVERS,
+ nuser, IPPROTO_UDP)) {
+ fprintf(stderr, "can't register RUSER service\en");
+ exit(1);
+ }
+ svc_run(); /* \fINever returns\fP */
+ fprintf(stderr, "should never reach this point\en");
+}
+
+nuser(rqstp, transp)
+ struct svc_req *rqstp;
+ SVCXPRT *transp;
+{
+ unsigned long nusers;
+
+ switch (rqstp->rq_proc) {
+ case NULLPROC:
+ if (!svc_sendreply(transp, xdr_void, 0))
+ fprintf(stderr, "can't reply to RPC call\en");
+ return;
+ case RUSERSPROC_NUM:
+.ft I
+ /*
+ * Code here to compute the number of users
+ * and assign it to the variable \fInusers\fP
+ */
+.ft CW
+ if (!svc_sendreply(transp, xdr_u_long, &nusers))
+ fprintf(stderr, "can't reply to RPC call\en");
+ return;
+ default:
+ svcerr_noproc(transp);
+ return;
+ }
+}
+.DE
+.LP
+First, the server gets a transport handle, which is used
+for receiving and replying to RPC messages.
+.I registerrpc()
+uses
+.I svcudp_create()
+to get a UDP handle.
+If you require a more reliable protocol, call
+.I svctcp_create()
+instead.
+If the argument to
+.I svcudp_create()
+is
+.I RPC_ANYSOCK
+the RPC library creates a socket
+on which to receive and reply to RPC calls. Otherwise,
+.I svcudp_create()
+expects its argument to be a valid socket number.
+If you specify your own socket, it can be bound or unbound.
+If it is bound to a port by the user, the port numbers of
+.I svcudp_create()
+and
+.I clnttcp_create()
+(the low-level client routine) must match.
+.LP
+If the user specifies the
+.I RPC_ANYSOCK
+argument, the RPC library routines will open sockets.
+Otherwise they will expect the user to do so. The routines
+.I svcudp_create()
+and
+.I clntudp_create()
+will cause the RPC library routines to
+.I bind()
+their socket if it is not bound already.
+.LP
+A service may choose to register its port number with the
+local portmapper service. This is done is done by specifying
+a non-zero protocol number in
+.I svc_register ().
+Incidently, a client can discover the server's port number by
+consulting the portmapper on their server's machine. This can
+be done automatically by specifying a zero port number in
+.I clntudp_create()
+or
+.I clnttcp_create ().
+.LP
+After creating an
+.I SVCXPRT ,
+the next step is to call
+.I pmap_unset()
+so that if the
+.I nusers()
+server crashed earlier,
+any previous trace of it is erased before restarting.
+More precisely,
+.I pmap_unset()
+erases the entry for
+.I RUSERSPROG
+from the port mapper's tables.
+.LP
+Finally, we associate the program number for
+.I nusers()
+with the procedure
+.I nuser ().
+The final argument to
+.I svc_register()
+is normally the protocol being used,
+which, in this case, is
+.I IPPROTO_UDP
+Notice that unlike
+.I registerrpc (),
+there are no XDR routines involved
+in the registration process.
+Also, registration is done on the program,
+rather than procedure, level.
+.LP
+The user routine
+.I nuser()
+must call and dispatch the appropriate XDR routines
+based on the procedure number.
+Note that
+two things are handled by
+.I nuser()
+that
+.I registerrpc()
+handles automatically.
+The first is that procedure
+.I NULLPROC
+(currently zero) returns with no results.
+This can be used as a simple test
+for detecting if a remote program is running.
+Second, there is a check for invalid procedure numbers.
+If one is detected,
+.I svcerr_noproc()
+is called to handle the error.
+.KS
+.LP
+The user service routine serializes the results and returns
+them to the RPC caller via
+.I svc_sendreply()
+Its first parameter is the
+.I SVCXPRT
+handle, the second is the XDR routine,
+and the third is a pointer to the data to be returned.
+Not illustrated above is how a server
+handles an RPC program that receives data.
+As an example, we can add a procedure
+.I RUSERSPROC_BOOL
+which has an argument
+.I nusers (),
+and returns
+.I TRUE
+or
+.I FALSE
+depending on whether there are nusers logged on.
+It would look like this:
+.ie t .DS
+.el .DS L
+.ft CW
+case RUSERSPROC_BOOL: {
+ int bool;
+ unsigned nuserquery;
+
+ if (!svc_getargs(transp, xdr_u_int, &nuserquery) {
+ svcerr_decode(transp);
+ return;
+ }
+.ft I
+ /*
+ * Code to set \fInusers\fP = number of users
+ */
+.ft CW
+ if (nuserquery == nusers)
+ bool = TRUE;
+ else
+ bool = FALSE;
+ if (!svc_sendreply(transp, xdr_bool, &bool)) {
+ fprintf(stderr, "can't reply to RPC call\en");
+ return (1);
+ }
+ return;
+}
+.DE
+.KE
+.LP
+The relevant routine is
+.I svc_getargs()
+which takes an
+.I SVCXPRT
+handle, the XDR routine,
+and a pointer to where the input is to be placed as arguments.
+.NH 2
+\&Memory Allocation with XDR
+.IX "memory allocation with XDR"
+.IX XDR "memory allocation"
+.LP
+XDR routines not only do input and output,
+they also do memory allocation.
+This is why the second parameter of
+.I xdr_array()
+is a pointer to an array, rather than the array itself.
+If it is
+.I NULL ,
+then
+.I xdr_array()
+allocates space for the array and returns a pointer to it,
+putting the size of the array in the third argument.
+As an example, consider the following XDR routine
+.I xdr_chararr1()
+which deals with a fixed array of bytes with length
+.I SIZE .
+.ie t .DS
+.el .DS L
+.ft CW
+xdr_chararr1(xdrsp, chararr)
+ XDR *xdrsp;
+ char chararr[];
+{
+ char *p;
+ int len;
+
+ p = chararr;
+ len = SIZE;
+ return (xdr_bytes(xdrsp, &p, &len, SIZE));
+}
+.DE
+If space has already been allocated in
+.I chararr ,
+it can be called from a server like this:
+.ie t .DS
+.el .DS L
+.ft CW
+char chararr[SIZE];
+
+svc_getargs(transp, xdr_chararr1, chararr);
+.DE
+If you want XDR to do the allocation,
+you would have to rewrite this routine in the following way:
+.ie t .DS
+.el .DS L
+.ft CW
+xdr_chararr2(xdrsp, chararrp)
+ XDR *xdrsp;
+ char **chararrp;
+{
+ int len;
+
+ len = SIZE;
+ return (xdr_bytes(xdrsp, charrarrp, &len, SIZE));
+}
+.DE
+Then the RPC call might look like this:
+.ie t .DS
+.el .DS L
+.ft CW
+char *arrptr;
+
+arrptr = NULL;
+svc_getargs(transp, xdr_chararr2, &arrptr);
+.ft I
+/*
+ * Use the result here
+ */
+.ft CW
+svc_freeargs(transp, xdr_chararr2, &arrptr);
+.DE
+Note that, after being used, the character array can be freed with
+.I svc_freeargs()
+.I svc_freeargs()
+will not attempt to free any memory if the variable indicating it
+is NULL. For example, in the the routine
+.I xdr_finalexample (),
+given earlier, if
+.I finalp->string
+was NULL, then it would not be freed. The same is true for
+.I finalp->simplep .
+.LP
+To summarize, each XDR routine is responsible
+for serializing, deserializing, and freeing memory.
+When an XDR routine is called from
+.I callrpc()
+the serializing part is used.
+When called from
+.I svc_getargs()
+the deserializer is used.
+And when called from
+.I svc_freeargs()
+the memory deallocator is used. When building simple examples like those
+in this section, a user doesn't have to worry
+about the three modes.
+See the
+.I "External Data Representation: Sun Technical Notes"
+for examples of more sophisticated XDR routines that determine
+which of the three modes they are in and adjust their behavior accordingly.
+.KS
+.NH 2
+\&The Calling Side
+.IX RPC "calling side"
+.LP
+When you use
+.I callrpc()
+you have no control over the RPC delivery
+mechanism or the socket used to transport the data.
+To illustrate the layer of RPC that lets you adjust these
+parameters, consider the following code to call the
+.I nusers
+service:
+.ie t .DS
+.el .DS L
+.ft CW
+.vs 11
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <utmp.h>
+#include <rpcsvc/rusers.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netdb.h>
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ struct hostent *hp;
+ struct timeval pertry_timeout, total_timeout;
+ struct sockaddr_in server_addr;
+ int sock = RPC_ANYSOCK;
+ register CLIENT *client;
+ enum clnt_stat clnt_stat;
+ unsigned long nusers;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: nusers hostname\en");
+ exit(-1);
+ }
+ if ((hp = gethostbyname(argv[1])) == NULL) {
+ fprintf(stderr, "can't get addr for %s\en",argv[1]);
+ exit(-1);
+ }
+ pertry_timeout.tv_sec = 3;
+ pertry_timeout.tv_usec = 0;
+ bcopy(hp->h_addr, (caddr_t)&server_addr.sin_addr,
+ hp->h_length);
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = 0;
+ if ((client = clntudp_create(&server_addr, RUSERSPROG,
+ RUSERSVERS, pertry_timeout, &sock)) == NULL) {
+ clnt_pcreateerror("clntudp_create");
+ exit(-1);
+ }
+ total_timeout.tv_sec = 20;
+ total_timeout.tv_usec = 0;
+ clnt_stat = clnt_call(client, RUSERSPROC_NUM, xdr_void,
+ 0, xdr_u_long, &nusers, total_timeout);
+ if (clnt_stat != RPC_SUCCESS) {
+ clnt_perror(client, "rpc");
+ exit(-1);
+ }
+ clnt_destroy(client);
+ close(sock);
+ exit(0);
+}
+.vs
+.DE
+.KE
+The low-level version of
+.I callrpc()
+is
+.I clnt_call()
+which takes a
+.I CLIENT
+pointer rather than a host name. The parameters to
+.I clnt_call()
+are a
+.I CLIENT
+pointer, the procedure number,
+the XDR routine for serializing the argument,
+a pointer to the argument,
+the XDR routine for deserializing the return value,
+a pointer to where the return value will be placed,
+and the time in seconds to wait for a reply.
+.LP
+The
+.I CLIENT
+pointer is encoded with the transport mechanism.
+.I callrpc()
+uses UDP, thus it calls
+.I clntudp_create()
+to get a
+.I CLIENT
+pointer. To get TCP (Transmission Control Protocol), you would use
+.I clnttcp_create() .
+.LP
+The parameters to
+.I clntudp_create()
+are the server address, the program number, the version number,
+a timeout value (between tries), and a pointer to a socket.
+The final argument to
+.I clnt_call()
+is the total time to wait for a response.
+Thus, the number of tries is the
+.I clnt_call()
+timeout divided by the
+.I clntudp_create()
+timeout.
+.LP
+Note that the
+.I clnt_destroy()
+call
+always deallocates the space associated with the
+.I CLIENT
+handle. It closes the socket associated with the
+.I CLIENT
+handle, however, only if the RPC library opened it. It the
+socket was opened by the user, it stays open. This makes it
+possible, in cases where there are multiple client handles
+using the same socket, to destroy one handle without closing
+the socket that other handles are using.
+.LP
+To make a stream connection, the call to
+.I clntudp_create()
+is replaced with a call to
+.I clnttcp_create() .
+.DS
+.ft CW
+clnttcp_create(&server_addr, prognum, versnum, &sock,
+ inputsize, outputsize);
+.DE
+There is no timeout argument; instead, the receive and send buffer
+sizes must be specified. When the
+.I clnttcp_create()
+call is made, a TCP connection is established.
+All RPC calls using that
+.I CLIENT
+handle would use this connection.
+The server side of an RPC call using TCP has
+.I svcudp_create()
+replaced by
+.I svctcp_create() .
+.DS
+.ft CW
+transp = svctcp_create(RPC_ANYSOCK, 0, 0);
+.DE
+The last two arguments to
+.I svctcp_create()
+are send and receive sizes respectively. If `0' is specified for
+either of these, the system chooses a reasonable default.
+.KS
+.NH 1
+\&Other RPC Features
+.IX "RPC" "miscellaneous features"
+.IX "miscellaneous RPC features"
+.LP
+This section discusses some other aspects of RPC
+that are occasionally useful.
+.NH 2
+\&Select on the Server Side
+.IX RPC select() RPC \fIselect()\fP
+.IX select() "" \fIselect()\fP "on the server side"
+.LP
+Suppose a process is processing RPC requests
+while performing some other activity.
+If the other activity involves periodically updating a data structure,
+the process can set an alarm signal before calling
+.I svc_run()
+But if the other activity
+involves waiting on a a file descriptor, the
+.I svc_run()
+call won't work.
+The code for
+.I svc_run()
+is as follows:
+.ie t .DS
+.el .DS L
+.ft CW
+.vs 11
+void
+svc_run()
+{
+ fd_set readfds;
+ int dtbsz = getdtablesize();
+
+ for (;;) {
+ readfds = svc_fds;
+ switch (select(dtbsz, &readfds, NULL,NULL,NULL)) {
+
+ case -1:
+ if (errno == EINTR)
+ continue;
+ perror("select");
+ return;
+ case 0:
+ break;
+ default:
+ svc_getreqset(&readfds);
+ }
+ }
+}
+.vs
+.DE
+.KE
+.LP
+You can bypass
+.I svc_run()
+and call
+.I svc_getreqset()
+yourself.
+All you need to know are the file descriptors
+of the socket(s) associated with the programs you are waiting on.
+Thus you can have your own
+.I select()
+.IX select() "" \fIselect()\fP
+that waits on both the RPC socket,
+and your own descriptors. Note that
+.I svc_fds()
+is a bit mask of all the file descriptors that RPC is using for
+services. It can change everytime that
+.I any
+RPC library routine is called, because descriptors are constantly
+being opened and closed, for example for TCP connections.
+.NH 2
+\&Broadcast RPC
+.IX "broadcast RPC"
+.IX RPC "broadcast"
+.LP
+The
+.I portmapper
+is a daemon that converts RPC program numbers
+into DARPA protocol port numbers; see the
+.I portmap
+man page. You can't do broadcast RPC without the portmapper.
+Here are the main differences between
+broadcast RPC and normal RPC calls:
+.IP 1.
+Normal RPC expects one answer, whereas
+broadcast RPC expects many answers
+(one or more answer from each responding machine).
+.IP 2.
+Broadcast RPC can only be supported by packet-oriented (connectionless)
+transport protocols like UPD/IP.
+.IP 3.
+The implementation of broadcast RPC
+treats all unsuccessful responses as garbage by filtering them out.
+Thus, if there is a version mismatch between the
+broadcaster and a remote service,
+the user of broadcast RPC never knows.
+.IP 4.
+All broadcast messages are sent to the portmap port.
+Thus, only services that register themselves with their portmapper
+are accessible via the broadcast RPC mechanism.
+.IP 5.
+Broadcast requests are limited in size to the MTU (Maximum Transfer
+Unit) of the local network. For Ethernet, the MTU is 1500 bytes.
+.KS
+.NH 3
+\&Broadcast RPC Synopsis
+.IX "broadcast RPC" synopsis
+.IX "RPC" "broadcast synopsis"
+.ie t .DS
+.el .DS L
+.ft CW
+#include <rpc/pmap_clnt.h>
+ . . .
+enum clnt_stat clnt_stat;
+ . . .
+clnt_stat = clnt_broadcast(prognum, versnum, procnum,
+ inproc, in, outproc, out, eachresult)
+ u_long prognum; /* \fIprogram number\fP */
+ u_long versnum; /* \fIversion number\fP */
+ u_long procnum; /* \fIprocedure number\fP */
+ xdrproc_t inproc; /* \fIxdr routine for args\fP */
+ caddr_t in; /* \fIpointer to args\fP */
+ xdrproc_t outproc; /* \fIxdr routine for results\fP */
+ caddr_t out; /* \fIpointer to results\fP */
+ bool_t (*eachresult)();/* \fIcall with each result gotten\fP */
+.DE
+.KE
+The procedure
+.I eachresult()
+is called each time a valid result is obtained.
+It returns a boolean that indicates
+whether or not the user wants more responses.
+.ie t .DS
+.el .DS L
+.ft CW
+bool_t done;
+ . . .
+done = eachresult(resultsp, raddr)
+ caddr_t resultsp;
+ struct sockaddr_in *raddr; /* \fIAddr of responding machine\fP */
+.DE
+If
+.I done
+is
+.I TRUE ,
+then broadcasting stops and
+.I clnt_broadcast()
+returns successfully.
+Otherwise, the routine waits for another response.
+The request is rebroadcast
+after a few seconds of waiting.
+If no responses come back,
+the routine returns with
+.I RPC_TIMEDOUT .
+.NH 2
+\&Batching
+.IX "batching"
+.IX RPC "batching"
+.LP
+The RPC architecture is designed so that clients send a call message,
+and wait for servers to reply that the call succeeded.
+This implies that clients do not compute
+while servers are processing a call.
+This is inefficient if the client does not want or need
+an acknowledgement for every message sent.
+It is possible for clients to continue computing
+while waiting for a response,
+using RPC batch facilities.
+.LP
+RPC messages can be placed in a \*Qpipeline\*U of calls
+to a desired server; this is called batching.
+Batching assumes that:
+1) each RPC call in the pipeline requires no response from the server,
+and the server does not send a response message; and
+2) the pipeline of calls is transported on a reliable
+byte stream transport such as TCP/IP.
+Since the server does not respond to every call,
+the client can generate new calls in parallel
+with the server executing previous calls.
+Furthermore, the TCP/IP implementation can buffer up
+many call messages, and send them to the server in one
+.I write()
+system call. This overlapped execution
+greatly decreases the interprocess communication overhead of
+the client and server processes,
+and the total elapsed time of a series of calls.
+.LP
+Since the batched calls are buffered,
+the client should eventually do a nonbatched call
+in order to flush the pipeline.
+.LP
+A contrived example of batching follows.
+Assume a string rendering service (like a window system)
+has two similar calls: one renders a string and returns void results,
+while the other renders a string and remains silent.
+The service (using the TCP/IP transport) may look like:
+.ie t .DS
+.el .DS L
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <suntool/windows.h>
+
+void windowdispatch();
+
+main()
+{
+ SVCXPRT *transp;
+
+ transp = svctcp_create(RPC_ANYSOCK, 0, 0);
+ if (transp == NULL){
+ fprintf(stderr, "can't create an RPC server\en");
+ exit(1);
+ }
+ pmap_unset(WINDOWPROG, WINDOWVERS);
+ if (!svc_register(transp, WINDOWPROG, WINDOWVERS,
+ windowdispatch, IPPROTO_TCP)) {
+ fprintf(stderr, "can't register WINDOW service\en");
+ exit(1);
+ }
+ svc_run(); /* \fINever returns\fP */
+ fprintf(stderr, "should never reach this point\en");
+}
+
+void
+windowdispatch(rqstp, transp)
+ struct svc_req *rqstp;
+ SVCXPRT *transp;
+{
+ char *s = NULL;
+
+ switch (rqstp->rq_proc) {
+ case NULLPROC:
+ if (!svc_sendreply(transp, xdr_void, 0))
+ fprintf(stderr, "can't reply to RPC call\en");
+ return;
+ case RENDERSTRING:
+ if (!svc_getargs(transp, xdr_wrapstring, &s)) {
+ fprintf(stderr, "can't decode arguments\en");
+.ft I
+ /*
+ * Tell caller he screwed up
+ */
+.ft CW
+ svcerr_decode(transp);
+ break;
+ }
+.ft I
+ /*
+ * Code here to render the string \fIs\fP
+ */
+.ft CW
+ if (!svc_sendreply(transp, xdr_void, NULL))
+ fprintf(stderr, "can't reply to RPC call\en");
+ break;
+ case RENDERSTRING_BATCHED:
+ if (!svc_getargs(transp, xdr_wrapstring, &s)) {
+ fprintf(stderr, "can't decode arguments\en");
+.ft I
+ /*
+ * We are silent in the face of protocol errors
+ */
+.ft CW
+ break;
+ }
+.ft I
+ /*
+ * Code here to render string s, but send no reply!
+ */
+.ft CW
+ break;
+ default:
+ svcerr_noproc(transp);
+ return;
+ }
+.ft I
+ /*
+ * Now free string allocated while decoding arguments
+ */
+.ft CW
+ svc_freeargs(transp, xdr_wrapstring, &s);
+}
+.DE
+Of course the service could have one procedure
+that takes the string and a boolean
+to indicate whether or not the procedure should respond.
+.LP
+In order for a client to take advantage of batching,
+the client must perform RPC calls on a TCP-based transport
+and the actual calls must have the following attributes:
+1) the result's XDR routine must be zero
+.I NULL ),
+and 2) the RPC call's timeout must be zero.
+.KS
+.LP
+Here is an example of a client that uses batching to render a
+bunch of strings; the batching is flushed when the client gets
+a null string (EOF):
+.ie t .DS
+.el .DS L
+.ft CW
+.vs 11
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netdb.h>
+#include <suntool/windows.h>
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ struct hostent *hp;
+ struct timeval pertry_timeout, total_timeout;
+ struct sockaddr_in server_addr;
+ int sock = RPC_ANYSOCK;
+ register CLIENT *client;
+ enum clnt_stat clnt_stat;
+ char buf[1000], *s = buf;
+
+ if ((client = clnttcp_create(&server_addr,
+ WINDOWPROG, WINDOWVERS, &sock, 0, 0)) == NULL) {
+ perror("clnttcp_create");
+ exit(-1);
+ }
+ total_timeout.tv_sec = 0;
+ total_timeout.tv_usec = 0;
+ while (scanf("%s", s) != EOF) {
+ clnt_stat = clnt_call(client, RENDERSTRING_BATCHED,
+ xdr_wrapstring, &s, NULL, NULL, total_timeout);
+ if (clnt_stat != RPC_SUCCESS) {
+ clnt_perror(client, "batched rpc");
+ exit(-1);
+ }
+ }
+
+ /* \fINow flush the pipeline\fP */
+
+ total_timeout.tv_sec = 20;
+ clnt_stat = clnt_call(client, NULLPROC, xdr_void, NULL,
+ xdr_void, NULL, total_timeout);
+ if (clnt_stat != RPC_SUCCESS) {
+ clnt_perror(client, "rpc");
+ exit(-1);
+ }
+ clnt_destroy(client);
+ exit(0);
+}
+.vs
+.DE
+.KE
+Since the server sends no message,
+the clients cannot be notified of any of the failures that may occur.
+Therefore, clients are on their own when it comes to handling errors.
+.LP
+The above example was completed to render
+all of the (2000) lines in the file
+.I /etc/termcap .
+The rendering service did nothing but throw the lines away.
+The example was run in the following four configurations:
+1) machine to itself, regular RPC;
+2) machine to itself, batched RPC;
+3) machine to another, regular RPC; and
+4) machine to another, batched RPC.
+The results are as follows:
+1) 50 seconds;
+2) 16 seconds;
+3) 52 seconds;
+4) 10 seconds.
+Running
+.I fscanf()
+on
+.I /etc/termcap
+only requires six seconds.
+These timings show the advantage of protocols
+that allow for overlapped execution,
+though these protocols are often hard to design.
+.NH 2
+\&Authentication
+.IX "authentication"
+.IX "RPC" "authentication"
+.LP
+In the examples presented so far,
+the caller never identified itself to the server,
+and the server never required an ID from the caller.
+Clearly, some network services, such as a network filesystem,
+require stronger security than what has been presented so far.
+.LP
+In reality, every RPC call is authenticated by
+the RPC package on the server, and similarly,
+the RPC client package generates and sends authentication parameters.
+Just as different transports (TCP/IP or UDP/IP)
+can be used when creating RPC clients and servers,
+different forms of authentication can be associated with RPC clients;
+the default authentication type used as a default is type
+.I none .
+.LP
+The authentication subsystem of the RPC package is open ended.
+That is, numerous types of authentication are easy to support.
+.NH 3
+\&UNIX Authentication
+.IX "UNIX Authentication"
+.IP "\fIThe Client Side\fP"
+.LP
+When a caller creates a new RPC client handle as in:
+.DS
+.ft CW
+clnt = clntudp_create(address, prognum, versnum,
+ wait, sockp)
+.DE
+the appropriate transport instance defaults
+the associate authentication handle to be
+.DS
+.ft CW
+clnt->cl_auth = authnone_create();
+.DE
+The RPC client can choose to use
+.I UNIX
+style authentication by setting
+.I clnt\->cl_auth
+after creating the RPC client handle:
+.DS
+.ft CW
+clnt->cl_auth = authunix_create_default();
+.DE
+This causes each RPC call associated with
+.I clnt
+to carry with it the following authentication credentials structure:
+.ie t .DS
+.el .DS L
+.ft I
+/*
+ * UNIX style credentials.
+ */
+.ft CW
+struct authunix_parms {
+ u_long aup_time; /* \fIcredentials creation time\fP */
+ char *aup_machname; /* \fIhost name where client is\fP */
+ int aup_uid; /* \fIclient's UNIX effective uid\fP */
+ int aup_gid; /* \fIclient's current group id\fP */
+ u_int aup_len; /* \fIelement length of aup_gids\fP */
+ int *aup_gids; /* \fIarray of groups user is in\fP */
+};
+.DE
+These fields are set by
+.I authunix_create_default()
+by invoking the appropriate system calls.
+Since the RPC user created this new style of authentication,
+the user is responsible for destroying it with:
+.DS
+.ft CW
+auth_destroy(clnt->cl_auth);
+.DE
+This should be done in all cases, to conserve memory.
+.sp
+.IP "\fIThe Server Side\fP"
+.LP
+Service implementors have a harder time dealing with authentication issues
+since the RPC package passes the service dispatch routine a request
+that has an arbitrary authentication style associated with it.
+Consider the fields of a request handle passed to a service dispatch routine:
+.ie t .DS
+.el .DS L
+.ft I
+/*
+ * An RPC Service request
+ */
+.ft CW
+struct svc_req {
+ u_long rq_prog; /* \fIservice program number\fP */
+ u_long rq_vers; /* \fIservice protocol vers num\fP */
+ u_long rq_proc; /* \fIdesired procedure number\fP */
+ struct opaque_auth rq_cred; /* \fIraw credentials from wire\fP */
+ caddr_t rq_clntcred; /* \fIcredentials (read only)\fP */
+};
+.DE
+The
+.I rq_cred
+is mostly opaque, except for one field of interest:
+the style or flavor of authentication credentials:
+.ie t .DS
+.el .DS L
+.ft I
+/*
+ * Authentication info. Mostly opaque to the programmer.
+ */
+.ft CW
+struct opaque_auth {
+ enum_t oa_flavor; /* \fIstyle of credentials\fP */
+ caddr_t oa_base; /* \fIaddress of more auth stuff\fP */
+ u_int oa_length; /* \fInot to exceed \fIMAX_AUTH_BYTES */
+};
+.DE
+.IX RPC guarantees
+The RPC package guarantees the following
+to the service dispatch routine:
+.IP 1.
+That the request's
+.I rq_cred
+is well formed. Thus the service implementor may inspect the request's
+.I rq_cred.oa_flavor
+to determine which style of authentication the caller used.
+The service implementor may also wish to inspect the other fields of
+.I rq_cred
+if the style is not one of the styles supported by the RPC package.
+.IP 2.
+That the request's
+.I rq_clntcred
+field is either
+.I NULL
+or points to a well formed structure
+that corresponds to a supported style of authentication credentials.
+Remember that only
+.I unix
+style is currently supported, so (currently)
+.I rq_clntcred
+could be cast to a pointer to an
+.I authunix_parms
+structure. If
+.I rq_clntcred
+is
+.I NULL ,
+the service implementor may wish to inspect the other (opaque) fields of
+.I rq_cred
+in case the service knows about a new type of authentication
+that the RPC package does not know about.
+.LP
+Our remote users service example can be extended so that
+it computes results for all users except UID 16:
+.ie t .DS
+.el .DS L
+.ft CW
+.vs 11
+nuser(rqstp, transp)
+ struct svc_req *rqstp;
+ SVCXPRT *transp;
+{
+ struct authunix_parms *unix_cred;
+ int uid;
+ unsigned long nusers;
+
+.ft I
+ /*
+ * we don't care about authentication for null proc
+ */
+.ft CW
+ if (rqstp->rq_proc == NULLPROC) {
+ if (!svc_sendreply(transp, xdr_void, 0)) {
+ fprintf(stderr, "can't reply to RPC call\en");
+ return (1);
+ }
+ return;
+ }
+.ft I
+ /*
+ * now get the uid
+ */
+.ft CW
+ switch (rqstp->rq_cred.oa_flavor) {
+ case AUTH_UNIX:
+ unix_cred =
+ (struct authunix_parms *)rqstp->rq_clntcred;
+ uid = unix_cred->aup_uid;
+ break;
+ case AUTH_NULL:
+ default:
+ svcerr_weakauth(transp);
+ return;
+ }
+ switch (rqstp->rq_proc) {
+ case RUSERSPROC_NUM:
+.ft I
+ /*
+ * make sure caller is allowed to call this proc
+ */
+.ft CW
+ if (uid == 16) {
+ svcerr_systemerr(transp);
+ return;
+ }
+.ft I
+ /*
+ * Code here to compute the number of users
+ * and assign it to the variable \fInusers\fP
+ */
+.ft CW
+ if (!svc_sendreply(transp, xdr_u_long, &nusers)) {
+ fprintf(stderr, "can't reply to RPC call\en");
+ return (1);
+ }
+ return;
+ default:
+ svcerr_noproc(transp);
+ return;
+ }
+}
+.vs
+.DE
+A few things should be noted here.
+First, it is customary not to check
+the authentication parameters associated with the
+.I NULLPROC
+(procedure number zero).
+Second, if the authentication parameter's type is not suitable
+for your service, you should call
+.I svcerr_weakauth() .
+And finally, the service protocol itself should return status
+for access denied; in the case of our example, the protocol
+does not have such a status, so we call the service primitive
+.I svcerr_systemerr()
+instead.
+.LP
+The last point underscores the relation between
+the RPC authentication package and the services;
+RPC deals only with
+.I authentication
+and not with individual services'
+.I "access control" .
+The services themselves must implement their own access control policies
+and reflect these policies as return statuses in their protocols.
+.NH 2
+\&DES Authentication
+.IX RPC DES
+.IX RPC authentication
+.LP
+UNIX authentication is quite easy to defeat. Instead of using
+.I authunix_create_default (),
+one can call
+.I authunix_create()
+and then modify the RPC authentication handle it returns by filling in
+whatever user ID and hostname they wish the server to think they have.
+DES authentication is thus recommended for people who want more security
+than UNIX authentication offers.
+.LP
+The details of the DES authentication protocol are complicated and
+are not explained here.
+See
+.I "Remote Procedure Calls: Protocol Specification"
+for the details.
+.LP
+In order for DES authentication to work, the
+.I keyserv(8c)
+daemon must be running on both the server and client machines. The
+users on these machines need public keys assigned by the network
+administrator in the
+.I publickey(5)
+database. And, they need to have decrypted their secret keys
+using their login password. This automatically happens when one
+logs in using
+.I login(1) ,
+or can be done manually using
+.I keylogin(1) .
+The
+.I "Network Services"
+chapter
+./" XXX
+explains more how to setup secure networking.
+.sp
+.IP "\fIClient Side\fP"
+.LP
+If a client wishes to use DES authentication, it must set its
+authentication handle appropriately. Here is an example:
+.DS
+cl->cl_auth =
+ authdes_create(servername, 60, &server_addr, NULL);
+.DE
+The first argument is the network name or \*Qnetname\*U of the owner of
+the server process. Typically, server processes are root processes
+and their netname can be derived using the following call:
+.DS
+char servername[MAXNETNAMELEN];
+
+host2netname(servername, rhostname, NULL);
+.DE
+Here,
+.I rhostname
+is the hostname of the machine the server process is running on.
+.I host2netname()
+fills in
+.I servername
+to contain this root process's netname. If the
+server process was run by a regular user, one could use the call
+.I user2netname()
+instead. Here is an example for a server process with the same user
+ID as the client:
+.DS
+char servername[MAXNETNAMELEN];
+
+user2netname(servername, getuid(), NULL);
+.DE
+The last argument to both of these calls,
+.I user2netname()
+and
+.I host2netname (),
+is the name of the naming domain where the server is located. The
+.I NULL
+used here means \*Quse the local domain name.\*U
+.LP
+The second argument to
+.I authdes_create()
+is a lifetime for the credential. Here it is set to sixty
+seconds. What that means is that the credential will expire 60
+seconds from now. If some mischievous user tries to reuse the
+credential, the server RPC subsystem will recognize that it has
+expired and not grant any requests. If the same mischievous user
+tries to reuse the credential within the sixty second lifetime,
+he will still be rejected because the server RPC subsystem
+remembers which credentials it has already seen in the near past,
+and will not grant requests to duplicates.
+.LP
+The third argument to
+.I authdes_create()
+is the address of the host to synchronize with. In order for DES
+authentication to work, the server and client must agree upon the
+time. Here we pass the address of the server itself, so the
+client and server will both be using the same time: the server's
+time. The argument can be
+.I NULL ,
+which means \*Qdon't bother synchronizing.\*U You should only do this
+if you are sure the client and server are already synchronized.
+.LP
+The final argument to
+.I authdes_create()
+is the address of a DES encryption key to use for encrypting
+timestamps and data. If this argument is
+.I NULL ,
+as it is in this example, a random key will be chosen. The client
+may find out the encryption key being used by consulting the
+.I ah_key
+field of the authentication handle.
+.sp
+.IP "\fIServer Side\fP"
+.LP
+The server side is a lot simpler than the client side. Here is the
+previous example rewritten to use
+.I AUTH_DES
+instead of
+.I AUTH_UNIX :
+.ie t .DS
+.el .DS L
+.ft CW
+.vs 11
+#include <sys/time.h>
+#include <rpc/auth_des.h>
+ . . .
+ . . .
+nuser(rqstp, transp)
+ struct svc_req *rqstp;
+ SVCXPRT *transp;
+{
+ struct authdes_cred *des_cred;
+ int uid;
+ int gid;
+ int gidlen;
+ int gidlist[10];
+.ft I
+ /*
+ * we don't care about authentication for null proc
+ */
+.ft CW
+
+ if (rqstp->rq_proc == NULLPROC) {
+ /* \fIsame as before\fP */
+ }
+
+.ft I
+ /*
+ * now get the uid
+ */
+.ft CW
+ switch (rqstp->rq_cred.oa_flavor) {
+ case AUTH_DES:
+ des_cred =
+ (struct authdes_cred *) rqstp->rq_clntcred;
+ if (! netname2user(des_cred->adc_fullname.name,
+ &uid, &gid, &gidlen, gidlist))
+ {
+ fprintf(stderr, "unknown user: %s\n",
+ des_cred->adc_fullname.name);
+ svcerr_systemerr(transp);
+ return;
+ }
+ break;
+ case AUTH_NULL:
+ default:
+ svcerr_weakauth(transp);
+ return;
+ }
+
+.ft I
+ /*
+ * The rest is the same as before
+ */
+.ft CW
+.vs
+.DE
+Note the use of the routine
+.I netname2user (),
+the inverse of
+.I user2netname ():
+it takes a network ID and converts to a unix ID.
+.I netname2user ()
+also supplies the group IDs which we don't use in this example,
+but which may be useful to other UNIX programs.
+.NH 2
+\&Using Inetd
+.IX inetd "" "using \fIinetd\fP"
+.LP
+An RPC server can be started from
+.I inetd
+The only difference from the usual code is that the service
+creation routine should be called in the following form:
+.ie t .DS
+.el .DS L
+.ft CW
+transp = svcudp_create(0); /* \fIFor UDP\fP */
+transp = svctcp_create(0,0,0); /* \fIFor listener TCP sockets\fP */
+transp = svcfd_create(0,0,0); /* \fIFor connected TCP sockets\fP */
+.DE
+since
+.I inet
+passes a socket as file descriptor 0.
+Also,
+.I svc_register()
+should be called as
+.ie t .DS
+.el .DS L
+.ft CW
+svc_register(transp, PROGNUM, VERSNUM, service, 0);
+.DE
+with the final flag as 0,
+since the program would already be registered by
+.I inetd
+Remember that if you want to exit
+from the server process and return control to
+.I inet
+you need to explicitly exit, since
+.I svc_run()
+never returns.
+.LP
+The format of entries in
+.I /etc/inetd.conf
+for RPC services is in one of the following two forms:
+.ie t .DS
+.el .DS L
+.ft CW
+p_name/version dgram rpc/udp wait/nowait user server args
+p_name/version stream rpc/tcp wait/nowait user server args
+.DE
+where
+.I p_name
+is the symbolic name of the program as it appears in
+.I rpc(5) ,
+.I server
+is the program implementing the server,
+and
+.I program
+and
+.I version
+are the program and version numbers of the service.
+For more information, see
+.I inetd.conf(5) .
+.LP
+If the same program handles multiple versions,
+then the version number can be a range,
+as in this example:
+.ie t .DS
+.el .DS L
+.ft CW
+rstatd/1-2 dgram rpc/udp wait root /usr/etc/rpc.rstatd
+.DE
+.NH 1
+\&More Examples
+.sp 1
+.NH 2
+\&Versions
+.IX "versions"
+.IX "RPC" "versions"
+.LP
+By convention, the first version number of program
+.I PROG
+is
+.I PROGVERS_ORIG
+and the most recent version is
+.I PROGVERS
+Suppose there is a new version of the
+.I user
+program that returns an
+.I "unsigned short"
+rather than a
+.I long .
+If we name this version
+.I RUSERSVERS_SHORT
+then a server that wants to support both versions
+would do a double register.
+.ie t .DS
+.el .DS L
+.ft CW
+if (!svc_register(transp, RUSERSPROG, RUSERSVERS_ORIG,
+ nuser, IPPROTO_TCP)) {
+ fprintf(stderr, "can't register RUSER service\en");
+ exit(1);
+}
+if (!svc_register(transp, RUSERSPROG, RUSERSVERS_SHORT,
+ nuser, IPPROTO_TCP)) {
+ fprintf(stderr, "can't register RUSER service\en");
+ exit(1);
+}
+.DE
+Both versions can be handled by the same C procedure:
+.ie t .DS
+.el .DS L
+.ft CW
+.vs 11
+nuser(rqstp, transp)
+ struct svc_req *rqstp;
+ SVCXPRT *transp;
+{
+ unsigned long nusers;
+ unsigned short nusers2;
+
+ switch (rqstp->rq_proc) {
+ case NULLPROC:
+ if (!svc_sendreply(transp, xdr_void, 0)) {
+ fprintf(stderr, "can't reply to RPC call\en");
+ return (1);
+ }
+ return;
+ case RUSERSPROC_NUM:
+.ft I
+ /*
+ * Code here to compute the number of users
+ * and assign it to the variable \fInusers\fP
+ */
+.ft CW
+ nusers2 = nusers;
+ switch (rqstp->rq_vers) {
+ case RUSERSVERS_ORIG:
+ if (!svc_sendreply(transp, xdr_u_long,
+ &nusers)) {
+ fprintf(stderr,"can't reply to RPC call\en");
+ }
+ break;
+ case RUSERSVERS_SHORT:
+ if (!svc_sendreply(transp, xdr_u_short,
+ &nusers2)) {
+ fprintf(stderr,"can't reply to RPC call\en");
+ }
+ break;
+ }
+ default:
+ svcerr_noproc(transp);
+ return;
+ }
+}
+.vs
+.DE
+.KS
+.NH 2
+\&TCP
+.IX "TCP"
+.LP
+Here is an example that is essentially
+.I rcp.
+The initiator of the RPC
+.I snd
+call takes its standard input and sends it to the server
+.I rcv
+which prints it on standard output.
+The RPC call uses TCP.
+This also illustrates an XDR procedure that behaves differently
+on serialization than on deserialization.
+.ie t .DS
+.el .DS L
+.vs 11
+.ft I
+/*
+ * The xdr routine:
+ * on decode, read from wire, write onto fp
+ * on encode, read from fp, write onto wire
+ */
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h>
+
+xdr_rcp(xdrs, fp)
+ XDR *xdrs;
+ FILE *fp;
+{
+ unsigned long size;
+ char buf[BUFSIZ], *p;
+
+ if (xdrs->x_op == XDR_FREE)/* nothing to free */
+ return 1;
+ while (1) {
+ if (xdrs->x_op == XDR_ENCODE) {
+ if ((size = fread(buf, sizeof(char), BUFSIZ,
+ fp)) == 0 && ferror(fp)) {
+ fprintf(stderr, "can't fread\en");
+ return (1);
+ }
+ }
+ p = buf;
+ if (!xdr_bytes(xdrs, &p, &size, BUFSIZ))
+ return 0;
+ if (size == 0)
+ return 1;
+ if (xdrs->x_op == XDR_DECODE) {
+ if (fwrite(buf, sizeof(char), size,
+ fp) != size) {
+ fprintf(stderr, "can't fwrite\en");
+ return (1);
+ }
+ }
+ }
+}
+.vs
+.DE
+.KE
+.ie t .DS
+.el .DS L
+.vs 11
+.ft I
+/*
+ * The sender routines
+ */
+.ft CW
+#include <stdio.h>
+#include <netdb.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int xdr_rcp();
+ int err;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s servername\en", argv[0]);
+ exit(-1);
+ }
+ if ((err = callrpctcp(argv[1], RCPPROG, RCPPROC,
+ RCPVERS, xdr_rcp, stdin, xdr_void, 0) != 0)) {
+ clnt_perrno(err);
+ fprintf(stderr, "can't make RPC call\en");
+ exit(1);
+ }
+ exit(0);
+}
+
+callrpctcp(host, prognum, procnum, versnum,
+ inproc, in, outproc, out)
+ char *host, *in, *out;
+ xdrproc_t inproc, outproc;
+{
+ struct sockaddr_in server_addr;
+ int socket = RPC_ANYSOCK;
+ enum clnt_stat clnt_stat;
+ struct hostent *hp;
+ register CLIENT *client;
+ struct timeval total_timeout;
+
+ if ((hp = gethostbyname(host)) == NULL) {
+ fprintf(stderr, "can't get addr for '%s'\en", host);
+ return (-1);
+ }
+ bcopy(hp->h_addr, (caddr_t)&server_addr.sin_addr,
+ hp->h_length);
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = 0;
+ if ((client = clnttcp_create(&server_addr, prognum,
+ versnum, &socket, BUFSIZ, BUFSIZ)) == NULL) {
+ perror("rpctcp_create");
+ return (-1);
+ }
+ total_timeout.tv_sec = 20;
+ total_timeout.tv_usec = 0;
+ clnt_stat = clnt_call(client, procnum,
+ inproc, in, outproc, out, total_timeout);
+ clnt_destroy(client);
+ return (int)clnt_stat;
+}
+.vs
+.DE
+.ie t .DS
+.el .DS L
+.vs 11
+.ft I
+/*
+ * The receiving routines
+ */
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h>
+
+main()
+{
+ register SVCXPRT *transp;
+ int rcp_service(), xdr_rcp();
+
+ if ((transp = svctcp_create(RPC_ANYSOCK,
+ BUFSIZ, BUFSIZ)) == NULL) {
+ fprintf("svctcp_create: error\en");
+ exit(1);
+ }
+ pmap_unset(RCPPROG, RCPVERS);
+ if (!svc_register(transp,
+ RCPPROG, RCPVERS, rcp_service, IPPROTO_TCP)) {
+ fprintf(stderr, "svc_register: error\en");
+ exit(1);
+ }
+ svc_run(); /* \fInever returns\fP */
+ fprintf(stderr, "svc_run should never return\en");
+}
+
+rcp_service(rqstp, transp)
+ register struct svc_req *rqstp;
+ register SVCXPRT *transp;
+{
+ switch (rqstp->rq_proc) {
+ case NULLPROC:
+ if (svc_sendreply(transp, xdr_void, 0) == 0) {
+ fprintf(stderr, "err: rcp_service");
+ return (1);
+ }
+ return;
+ case RCPPROC_FP:
+ if (!svc_getargs(transp, xdr_rcp, stdout)) {
+ svcerr_decode(transp);
+ return;
+ }
+ if (!svc_sendreply(transp, xdr_void, 0)) {
+ fprintf(stderr, "can't reply\en");
+ return;
+ }
+ return (0);
+ default:
+ svcerr_noproc(transp);
+ return;
+ }
+}
+.vs
+.DE
+.NH 2
+\&Callback Procedures
+.IX RPC "callback procedures"
+.LP
+Occasionally, it is useful to have a server become a client,
+and make an RPC call back to the process which is its client.
+An example is remote debugging,
+where the client is a window system program,
+and the server is a debugger running on the remote machine.
+Most of the time,
+the user clicks a mouse button at the debugging window,
+which converts this to a debugger command,
+and then makes an RPC call to the server
+(where the debugger is actually running),
+telling it to execute that command.
+However, when the debugger hits a breakpoint, the roles are reversed,
+and the debugger wants to make an rpc call to the window program,
+so that it can inform the user that a breakpoint has been reached.
+.LP
+In order to do an RPC callback,
+you need a program number to make the RPC call on.
+Since this will be a dynamically generated program number,
+it should be in the transient range,
+.I "0x40000000 - 0x5fffffff" .
+The routine
+.I gettransient()
+returns a valid program number in the transient range,
+and registers it with the portmapper.
+It only talks to the portmapper running on the same machine as the
+.I gettransient()
+routine itself. The call to
+.I pmap_set()
+is a test and set operation,
+in that it indivisibly tests whether a program number
+has already been registered,
+and if it has not, then reserves it. On return, the
+.I sockp
+argument will contain a socket that can be used
+as the argument to an
+.I svcudp_create()
+or
+.I svctcp_create()
+call.
+.ie t .DS
+.el .DS L
+.ft CW
+.vs 11
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+
+gettransient(proto, vers, sockp)
+ int proto, vers, *sockp;
+{
+ static int prognum = 0x40000000;
+ int s, len, socktype;
+ struct sockaddr_in addr;
+
+ switch(proto) {
+ case IPPROTO_UDP:
+ socktype = SOCK_DGRAM;
+ break;
+ case IPPROTO_TCP:
+ socktype = SOCK_STREAM;
+ break;
+ default:
+ fprintf(stderr, "unknown protocol type\en");
+ return 0;
+ }
+ if (*sockp == RPC_ANYSOCK) {
+ if ((s = socket(AF_INET, socktype, 0)) < 0) {
+ perror("socket");
+ return (0);
+ }
+ *sockp = s;
+ }
+ else
+ s = *sockp;
+ addr.sin_addr.s_addr = 0;
+ addr.sin_family = AF_INET;
+ addr.sin_port = 0;
+ len = sizeof(addr);
+.ft I
+ /*
+ * may be already bound, so don't check for error
+ */
+.ft CW
+ bind(s, &addr, len);
+ if (getsockname(s, &addr, &len)< 0) {
+ perror("getsockname");
+ return (0);
+ }
+ while (!pmap_set(prognum++, vers, proto,
+ ntohs(addr.sin_port))) continue;
+ return (prognum-1);
+}
+.vs
+.DE
+.SH
+Note:
+.I
+The call to
+.I ntohs()
+is necessary to ensure that the port number in
+.I "addr.sin_port" ,
+which is in
+.I network
+byte order, is passed in
+.I host
+byte order (as
+.I pmap_set()
+expects). See the
+.I byteorder(3N)
+man page for more details on the conversion of network
+addresses from network to host byte order.
+.KS
+.LP
+The following pair of programs illustrate how to use the
+.I gettransient()
+routine.
+The client makes an RPC call to the server,
+passing it a transient program number.
+Then the client waits around to receive a callback
+from the server at that program number.
+The server registers the program
+.I EXAMPLEPROG
+so that it can receive the RPC call
+informing it of the callback program number.
+Then at some random time (on receiving an
+.I ALRM
+signal in this example), it sends a callback RPC call,
+using the program number it received earlier.
+.ie t .DS
+.el .DS L
+.vs 11
+.ft I
+/*
+ * client
+ */
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h>
+
+int callback();
+char hostname[256];
+
+main()
+{
+ int x, ans, s;
+ SVCXPRT *xprt;
+
+ gethostname(hostname, sizeof(hostname));
+ s = RPC_ANYSOCK;
+ x = gettransient(IPPROTO_UDP, 1, &s);
+ fprintf(stderr, "client gets prognum %d\en", x);
+ if ((xprt = svcudp_create(s)) == NULL) {
+ fprintf(stderr, "rpc_server: svcudp_create\en");
+ exit(1);
+ }
+.ft I
+ /* protocol is 0 - gettransient does registering
+ */
+.ft CW
+ (void)svc_register(xprt, x, 1, callback, 0);
+ ans = callrpc(hostname, EXAMPLEPROG, EXAMPLEVERS,
+ EXAMPLEPROC_CALLBACK, xdr_int, &x, xdr_void, 0);
+ if ((enum clnt_stat) ans != RPC_SUCCESS) {
+ fprintf(stderr, "call: ");
+ clnt_perrno(ans);
+ fprintf(stderr, "\en");
+ }
+ svc_run();
+ fprintf(stderr, "Error: svc_run shouldn't return\en");
+}
+
+callback(rqstp, transp)
+ register struct svc_req *rqstp;
+ register SVCXPRT *transp;
+{
+ switch (rqstp->rq_proc) {
+ case 0:
+ if (!svc_sendreply(transp, xdr_void, 0)) {
+ fprintf(stderr, "err: exampleprog\en");
+ return (1);
+ }
+ return (0);
+ case 1:
+ if (!svc_getargs(transp, xdr_void, 0)) {
+ svcerr_decode(transp);
+ return (1);
+ }
+ fprintf(stderr, "client got callback\en");
+ if (!svc_sendreply(transp, xdr_void, 0)) {
+ fprintf(stderr, "err: exampleprog");
+ return (1);
+ }
+ }
+}
+.vs
+.DE
+.KE
+.ie t .DS
+.el .DS L
+.vs 11
+.ft I
+/*
+ * server
+ */
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h>
+#include <sys/signal.h>
+
+char *getnewprog();
+char hostname[256];
+int docallback();
+int pnum; /* \fIprogram number for callback routine\fP */
+
+main()
+{
+ gethostname(hostname, sizeof(hostname));
+ registerrpc(EXAMPLEPROG, EXAMPLEVERS,
+ EXAMPLEPROC_CALLBACK, getnewprog, xdr_int, xdr_void);
+ fprintf(stderr, "server going into svc_run\en");
+ signal(SIGALRM, docallback);
+ alarm(10);
+ svc_run();
+ fprintf(stderr, "Error: svc_run shouldn't return\en");
+}
+
+char *
+getnewprog(pnump)
+ char *pnump;
+{
+ pnum = *(int *)pnump;
+ return NULL;
+}
+
+docallback()
+{
+ int ans;
+
+ ans = callrpc(hostname, pnum, 1, 1, xdr_void, 0,
+ xdr_void, 0);
+ if (ans != 0) {
+ fprintf(stderr, "server: ");
+ clnt_perrno(ans);
+ fprintf(stderr, "\en");
+ }
+}
+.vs
+.DE
diff --git a/lib/libc/rpc/PSD.doc/rpc.rfc.ms b/lib/libc/rpc/PSD.doc/rpc.rfc.ms
new file mode 100644
index 0000000..af9c2df
--- /dev/null
+++ b/lib/libc/rpc/PSD.doc/rpc.rfc.ms
@@ -0,0 +1,1302 @@
+.\"
+.\" Must use -- tbl -- with this one
+.\"
+.\" @(#)rpc.rfc.ms 2.2 88/08/05 4.0 RPCSRC
+.de BT
+.if \\n%=1 .tl ''- % -''
+..
+.ND
+.\" prevent excess underlining in nroff
+.if n .fp 2 R
+.OH 'Remote Procedure Calls: Protocol Specification''Page %'
+.EH 'Page %''Remote Procedure Calls: Protocol Specification'
+.if \\n%=1 .bp
+.SH
+\&Remote Procedure Calls: Protocol Specification
+.LP
+.NH 0
+\&Status of this Memo
+.LP
+Note: This chapter specifies a protocol that Sun Microsystems, Inc.,
+and others are using.
+It has been designated RFC1050 by the ARPA Network
+Information Center.
+.LP
+.NH 1
+\&Introduction
+.LP
+This chapter specifies a message protocol used in implementing
+Sun's Remote Procedure Call (RPC) package. (The message protocol is
+specified with the External Data Representation (XDR) language.
+See the
+.I "External Data Representation Standard: Protocol Specification"
+for the details. Here, we assume that the reader is familiar
+with XDR and do not attempt to justify it or its uses). The paper
+by Birrell and Nelson [1] is recommended as an excellent background
+to and justification of RPC.
+.NH 2
+\&Terminology
+.LP
+This chapter discusses servers, services, programs, procedures,
+clients, and versions. A server is a piece of software where network
+services are implemented. A network service is a collection of one
+or more remote programs. A remote program implements one or more
+remote procedures; the procedures, their parameters, and results are
+documented in the specific program's protocol specification (see the
+\fIPort Mapper Program Protocol\fP\, below, for an example). Network
+clients are pieces of software that initiate remote procedure calls
+to services. A server may support more than one version of a remote
+program in order to be forward compatible with changing protocols.
+.LP
+For example, a network file service may be composed of two programs.
+One program may deal with high-level applications such as file system
+access control and locking. The other may deal with low-level file
+IO and have procedures like "read" and "write". A client machine of
+the network file service would call the procedures associated with
+the two programs of the service on behalf of some user on the client
+machine.
+.NH 2
+\&The RPC Model
+.LP
+The remote procedure call model is similar to the local procedure
+call model. In the local case, the caller places arguments to a
+procedure in some well-specified location (such as a result
+register). It then transfers control to the procedure, and
+eventually gains back control. At that point, the results of the
+procedure are extracted from the well-specified location, and the
+caller continues execution.
+.LP
+The remote procedure call is similar, in that one thread of control
+logically winds through two processes\(emone is the caller's process,
+the other is a server's process. That is, the caller process sends a
+call message to the server process and waits (blocks) for a reply
+message. The call message contains the procedure's parameters, among
+other things. The reply message contains the procedure's results,
+among other things. Once the reply message is received, the results
+of the procedure are extracted, and caller's execution is resumed.
+.LP
+On the server side, a process is dormant awaiting the arrival of a
+call message. When one arrives, the server process extracts the
+procedure's parameters, computes the results, sends a reply message,
+and then awaits the next call message.
+.LP
+Note that in this model, only one of the two processes is active at
+any given time. However, this model is only given as an example.
+The RPC protocol makes no restrictions on the concurrency model
+implemented, and others are possible. For example, an implementation
+may choose to have RPC calls be asynchronous, so that the client may
+do useful work while waiting for the reply from the server. Another
+possibility is to have the server create a task to process an
+incoming request, so that the server can be free to receive other
+requests.
+.NH 2
+\&Transports and Semantics
+.LP
+The RPC protocol is independent of transport protocols. That is, RPC
+does not care how a message is passed from one process to another.
+The protocol deals only with specification and interpretation of
+messages.
+.LP
+It is important to point out that RPC does not try to implement any
+kind of reliability and that the application must be aware of the
+type of transport protocol underneath RPC. If it knows it is running
+on top of a reliable transport such as TCP/IP[6], then most of the
+work is already done for it. On the other hand, if it is running on
+top of an unreliable transport such as UDP/IP[7], it must implement
+is own retransmission and time-out policy as the RPC layer does not
+provide this service.
+.LP
+Because of transport independence, the RPC protocol does not attach
+specific semantics to the remote procedures or their execution.
+Semantics can be inferred from (but should be explicitly specified
+by) the underlying transport protocol. For example, consider RPC
+running on top of an unreliable transport such as UDP/IP. If an
+application retransmits RPC messages after short time-outs, the only
+thing it can infer if it receives no reply is that the procedure was
+executed zero or more times. If it does receive a reply, then it can
+infer that the procedure was executed at least once.
+.LP
+A server may wish to remember previously granted requests from a
+client and not regrant them in order to insure some degree of
+execute-at-most-once semantics. A server can do this by taking
+advantage of the transaction ID that is packaged with every RPC
+request. The main use of this transaction is by the client RPC layer
+in matching replies to requests. However, a client application may
+choose to reuse its previous transaction ID when retransmitting a
+request. The server application, knowing this fact, may choose to
+remember this ID after granting a request and not regrant requests
+with the same ID in order to achieve some degree of
+execute-at-most-once semantics. The server is not allowed to examine
+this ID in any other way except as a test for equality.
+.LP
+On the other hand, if using a reliable transport such as TCP/IP, the
+application can infer from a reply message that the procedure was
+executed exactly once, but if it receives no reply message, it cannot
+assume the remote procedure was not executed. Note that even if a
+connection-oriented protocol like TCP is used, an application still
+needs time-outs and reconnection to handle server crashes.
+.LP
+There are other possibilities for transports besides datagram- or
+connection-oriented protocols. For example, a request-reply protocol
+such as VMTP[2] is perhaps the most natural transport for RPC.
+.SH
+.I
+NOTE: At Sun, RPC is currently implemented on top of both TCP/IP
+and UDP/IP transports.
+.LP
+.NH 2
+\&Binding and Rendezvous Independence
+.LP
+The act of binding a client to a service is NOT part of the remote
+procedure call specification. This important and necessary function
+is left up to some higher-level software. (The software may use RPC
+itself\(emsee the \fIPort Mapper Program Protocol\fP\, below).
+.LP
+Implementors should think of the RPC protocol as the jump-subroutine
+instruction ("JSR") of a network; the loader (binder) makes JSR
+useful, and the loader itself uses JSR to accomplish its task.
+Likewise, the network makes RPC useful, using RPC to accomplish this
+task.
+.NH 2
+\&Authentication
+.LP
+The RPC protocol provides the fields necessary for a client to
+identify itself to a service and vice-versa. Security and access
+control mechanisms can be built on top of the message authentication.
+Several different authentication protocols can be supported. A field
+in the RPC header indicates which protocol is being used. More
+information on specific authentication protocols can be found in the
+\fIAuthentication Protocols\fP\,
+below.
+.KS
+.NH 1
+\&RPC Protocol Requirements
+.LP
+The RPC protocol must provide for the following:
+.IP 1.
+Unique specification of a procedure to be called.
+.IP 2.
+Provisions for matching response messages to request messages.
+.KE
+.IP 3.
+Provisions for authenticating the caller to service and vice-versa.
+.LP
+Besides these requirements, features that detect the following are
+worth supporting because of protocol roll-over errors, implementation
+bugs, user error, and network administration:
+.IP 1.
+RPC protocol mismatches.
+.IP 2.
+Remote program protocol version mismatches.
+.IP 3.
+Protocol errors (such as misspecification of a procedure's parameters).
+.IP 4.
+Reasons why remote authentication failed.
+.IP 5.
+Any other reasons why the desired procedure was not called.
+.NH 2
+\&Programs and Procedures
+.LP
+The RPC call message has three unsigned fields: remote program
+number, remote program version number, and remote procedure number.
+The three fields uniquely identify the procedure to be called.
+Program numbers are administered by some central authority (like
+Sun). Once an implementor has a program number, he can implement his
+remote program; the first implementation would most likely have the
+version number of 1. Because most new protocols evolve into better,
+stable, and mature protocols, a version field of the call message
+identifies which version of the protocol the caller is using.
+Version numbers make speaking old and new protocols through the same
+server process possible.
+.LP
+The procedure number identifies the procedure to be called. These
+numbers are documented in the specific program's protocol
+specification. For example, a file service's protocol specification
+may state that its procedure number 5 is "read" and procedure number
+12 is "write".
+.LP
+Just as remote program protocols may change over several versions,
+the actual RPC message protocol could also change. Therefore, the
+call message also has in it the RPC version number, which is always
+equal to two for the version of RPC described here.
+.LP
+The reply message to a request message has enough information to
+distinguish the following error conditions:
+.IP 1.
+The remote implementation of RPC does speak protocol version 2.
+The lowest and highest supported RPC version numbers are returned.
+.IP 2.
+The remote program is not available on the remote system.
+.IP 3.
+The remote program does not support the requested version number.
+The lowest and highest supported remote program version numbers are
+returned.
+.IP 4.
+The requested procedure number does not exist. (This is usually a
+caller side protocol or programming error.)
+.IP 5.
+The parameters to the remote procedure appear to be garbage from the
+server's point of view. (Again, this is usually caused by a
+disagreement about the protocol between client and service.)
+.NH 2
+\&Authentication
+.LP
+Provisions for authentication of caller to service and vice-versa are
+provided as a part of the RPC protocol. The call message has two
+authentication fields, the credentials and verifier. The reply
+message has one authentication field, the response verifier. The RPC
+protocol specification defines all three fields to be the following
+opaque type:
+.DS
+.ft CW
+.vs 11
+enum auth_flavor {
+ AUTH_NULL = 0,
+ AUTH_UNIX = 1,
+ AUTH_SHORT = 2,
+ AUTH_DES = 3
+ /* \fIand more to be defined\fP */
+};
+
+struct opaque_auth {
+ auth_flavor flavor;
+ opaque body<400>;
+};
+.DE
+.LP
+In simple English, any
+.I opaque_auth
+structure is an
+.I auth_flavor
+enumeration followed by bytes which are opaque to the RPC protocol
+implementation.
+.LP
+The interpretation and semantics of the data contained within the
+authentication fields is specified by individual, independent
+authentication protocol specifications. (See
+\fIAuthentication Protocols\fP\,
+below, for definitions of the various authentication protocols.)
+.LP
+If authentication parameters were rejected, the response message
+contains information stating why they were rejected.
+.NH 2
+\&Program Number Assignment
+.LP
+Program numbers are given out in groups of
+.I 0x20000000
+(decimal 536870912) according to the following chart:
+.TS
+box tab (&) ;
+lfI lfI
+rfL cfI .
+Program Numbers&Description
+_
+.sp .5
+0 - 1fffffff&Defined by Sun
+20000000 - 3fffffff&Defined by user
+40000000 - 5fffffff&Transient
+60000000 - 7fffffff&Reserved
+80000000 - 9fffffff&Reserved
+a0000000 - bfffffff&Reserved
+c0000000 - dfffffff&Reserved
+e0000000 - ffffffff&Reserved
+.TE
+.LP
+The first group is a range of numbers administered by Sun
+Microsystems and should be identical for all sites. The second range
+is for applications peculiar to a particular site. This range is
+intended primarily for debugging new programs. When a site develops
+an application that might be of general interest, that application
+should be given an assigned number in the first range. The third
+group is for applications that generate program numbers dynamically.
+The final groups are reserved for future use, and should not be used.
+.NH 2
+\&Other Uses of the RPC Protocol
+.LP
+The intended use of this protocol is for calling remote procedures.
+That is, each call message is matched with a response message.
+However, the protocol itself is a message-passing protocol with which
+other (non-RPC) protocols can be implemented. Sun currently uses, or
+perhaps abuses, the RPC message protocol for the following two
+(non-RPC) protocols: batching (or pipelining) and broadcast RPC.
+These two protocols are discussed but not defined below.
+.NH 3
+\&Batching
+.LP
+Batching allows a client to send an arbitrarily large sequence of
+call messages to a server; batching typically uses reliable byte
+stream protocols (like TCP/IP) for its transport. In the case of
+batching, the client never waits for a reply from the server, and the
+server does not send replies to batch requests. A sequence of batch
+calls is usually terminated by a legitimate RPC in order to flush the
+pipeline (with positive acknowledgement).
+.NH 3
+\&Broadcast RPC
+.LP
+In broadcast RPC-based protocols, the client sends a broadcast packet
+to the network and waits for numerous replies. Broadcast RPC uses
+unreliable, packet-based protocols (like UDP/IP) as its transports.
+Servers that support broadcast protocols only respond when the
+request is successfully processed, and are silent in the face of
+errors. Broadcast RPC uses the Port Mapper RPC service to achieve
+its semantics. See the \fIPort Mapper Program Protocol\fP\, below,
+for more information.
+.KS
+.NH 1
+\&The RPC Message Protocol
+.LP
+This section defines the RPC message protocol in the XDR data
+description language. The message is defined in a top-down style.
+.ie t .DS
+.el .DS L
+.ft CW
+enum msg_type {
+ CALL = 0,
+ REPLY = 1
+};
+
+.ft I
+/*
+* A reply to a call message can take on two forms:
+* The message was either accepted or rejected.
+*/
+.ft CW
+enum reply_stat {
+ MSG_ACCEPTED = 0,
+ MSG_DENIED = 1
+};
+
+.ft I
+/*
+* Given that a call message was accepted, the following is the
+* status of an attempt to call a remote procedure.
+*/
+.ft CW
+enum accept_stat {
+ SUCCESS = 0, /* \fIRPC executed successfully \fP*/
+ PROG_UNAVAIL = 1, /* \fIremote hasn't exported program \fP*/
+ PROG_MISMATCH = 2, /* \fIremote can't support version # \fP*/
+ PROC_UNAVAIL = 3, /* \fIprogram can't support procedure \fP*/
+ GARBAGE_ARGS = 4 /* \fIprocedure can't decode params \fP*/
+};
+.DE
+.ie t .DS
+.el .DS L
+.ft I
+/*
+* Reasons why a call message was rejected:
+*/
+.ft CW
+enum reject_stat {
+ RPC_MISMATCH = 0, /* \fIRPC version number != 2 \fP*/
+ AUTH_ERROR = 1 /* \fIremote can't authenticate caller \fP*/
+};
+
+.ft I
+/*
+* Why authentication failed:
+*/
+.ft CW
+enum auth_stat {
+ AUTH_BADCRED = 1, /* \fIbad credentials \fP*/
+ AUTH_REJECTEDCRED = 2, /* \fIclient must begin new session \fP*/
+ AUTH_BADVERF = 3, /* \fIbad verifier \fP*/
+ AUTH_REJECTEDVERF = 4, /* \fIverifier expired or replayed \fP*/
+ AUTH_TOOWEAK = 5 /* \fIrejected for security reasons \fP*/
+};
+.DE
+.KE
+.ie t .DS
+.el .DS L
+.ft I
+/*
+* The RPC message:
+* All messages start with a transaction identifier, xid,
+* followed by a two-armed discriminated union. The union's
+* discriminant is a msg_type which switches to one of the two
+* types of the message. The xid of a \fIREPLY\fP message always
+* matches that of the initiating \fICALL\fP message. NB: The xid
+* field is only used for clients matching reply messages with
+* call messages or for servers detecting retransmissions; the
+* service side cannot treat this id as any type of sequence
+* number.
+*/
+.ft CW
+struct rpc_msg {
+ unsigned int xid;
+ union switch (msg_type mtype) {
+ case CALL:
+ call_body cbody;
+ case REPLY:
+ reply_body rbody;
+ } body;
+};
+.DE
+.ie t .DS
+.el .DS L
+.ft I
+/*
+* Body of an RPC request call:
+* In version 2 of the RPC protocol specification, rpcvers must
+* be equal to 2. The fields prog, vers, and proc specify the
+* remote program, its version number, and the procedure within
+* the remote program to be called. After these fields are two
+* authentication parameters: cred (authentication credentials)
+* and verf (authentication verifier). The two authentication
+* parameters are followed by the parameters to the remote
+* procedure, which are specified by the specific program
+* protocol.
+*/
+.ft CW
+struct call_body {
+ unsigned int rpcvers; /* \fImust be equal to two (2) \fP*/
+ unsigned int prog;
+ unsigned int vers;
+ unsigned int proc;
+ opaque_auth cred;
+ opaque_auth verf;
+ /* \fIprocedure specific parameters start here \fP*/
+};
+.DE
+.ie t .DS
+.el .DS L
+.ft I
+/*
+* Body of a reply to an RPC request:
+* The call message was either accepted or rejected.
+*/
+.ft CW
+union reply_body switch (reply_stat stat) {
+ case MSG_ACCEPTED:
+ accepted_reply areply;
+ case MSG_DENIED:
+ rejected_reply rreply;
+} reply;
+.DE
+.ie t .DS
+.el .DS L
+.ft I
+/*
+* Reply to an RPC request that was accepted by the server:
+* there could be an error even though the request was accepted.
+* The first field is an authentication verifier that the server
+* generates in order to validate itself to the caller. It is
+* followed by a union whose discriminant is an enum
+* accept_stat. The \fISUCCESS\fP arm of the union is protocol
+* specific. The \fIPROG_UNAVAIL\fP, \fIPROC_UNAVAIL\fP, and \fIGARBAGE_ARGP\fP
+* arms of the union are void. The \fIPROG_MISMATCH\fP arm specifies
+* the lowest and highest version numbers of the remote program
+* supported by the server.
+*/
+.ft CW
+struct accepted_reply {
+ opaque_auth verf;
+ union switch (accept_stat stat) {
+ case SUCCESS:
+ opaque results[0];
+ /* \fIprocedure-specific results start here\fP */
+ case PROG_MISMATCH:
+ struct {
+ unsigned int low;
+ unsigned int high;
+ } mismatch_info;
+ default:
+.ft I
+ /*
+ * Void. Cases include \fIPROG_UNAVAIL, PROC_UNAVAIL\fP,
+ * and \fIGARBAGE_ARGS\fP.
+ */
+.ft CW
+ void;
+ } reply_data;
+};
+.DE
+.ie t .DS
+.el .DS L
+.ft I
+/*
+* Reply to an RPC request that was rejected by the server:
+* The request can be rejected for two reasons: either the
+* server is not running a compatible version of the RPC
+* protocol (\fIRPC_MISMATCH\fP), or the server refuses to
+* authenticate the caller (\fIAUTH_ERROR\fP). In case of an RPC
+* version mismatch, the server returns the lowest and highest
+* supported RPC version numbers. In case of refused
+* authentication, failure status is returned.
+*/
+.ft CW
+union rejected_reply switch (reject_stat stat) {
+ case RPC_MISMATCH:
+ struct {
+ unsigned int low;
+ unsigned int high;
+ } mismatch_info;
+ case AUTH_ERROR:
+ auth_stat stat;
+};
+.DE
+.NH 1
+\&Authentication Protocols
+.LP
+As previously stated, authentication parameters are opaque, but
+open-ended to the rest of the RPC protocol. This section defines
+some "flavors" of authentication implemented at (and supported by)
+Sun. Other sites are free to invent new authentication types, with
+the same rules of flavor number assignment as there is for program
+number assignment.
+.NH 2
+\&Null Authentication
+.LP
+Often calls must be made where the caller does not know who he is or
+the server does not care who the caller is. In this case, the flavor
+value (the discriminant of the \fIopaque_auth\fP's union) of the RPC
+message's credentials, verifier, and response verifier is
+.I AUTH_NULL .
+The bytes of the opaque_auth's body are undefined.
+It is recommended that the opaque length be zero.
+.NH 2
+\&UNIX Authentication
+.LP
+The caller of a remote procedure may wish to identify himself as he
+is identified on a UNIX system. The value of the credential's
+discriminant of an RPC call message is
+.I AUTH_UNIX .
+The bytes of
+the credential's opaque body encode the following structure:
+.DS
+.ft CW
+struct auth_unix {
+ unsigned int stamp;
+ string machinename<255>;
+ unsigned int uid;
+ unsigned int gid;
+ unsigned int gids<10>;
+};
+.DE
+The
+.I stamp
+is an arbitrary ID which the caller machine may
+generate. The
+.I machinename
+is the name of the caller's machine (like "krypton"). The
+.I uid
+is the caller's effective user ID. The
+.I gid
+is the caller's effective group ID. The
+.I gids
+is a
+counted array of groups which contain the caller as a member. The
+verifier accompanying the credentials should be of
+.I AUTH_NULL
+(defined above).
+.LP
+The value of the discriminant of the response verifier received in
+the reply message from the server may be
+.I AUTH_NULL
+or
+.I AUTH_SHORT .
+In the case of
+.I AUTH_SHORT ,
+the bytes of the response verifier's string encode an opaque
+structure. This new opaque structure may now be passed to the server
+instead of the original
+.I AUTH_UNIX
+flavor credentials. The server keeps a cache which maps shorthand
+opaque structures (passed back by way of an
+.I AUTH_SHORT
+style response verifier) to the original credentials of the caller.
+The caller can save network bandwidth and server cpu cycles by using
+the new credentials.
+.LP
+The server may flush the shorthand opaque structure at any time. If
+this happens, the remote procedure call message will be rejected due
+to an authentication error. The reason for the failure will be
+.I AUTH_REJECTEDCRED .
+At this point, the caller may wish to try the original
+.I AUTH_UNIX
+style of credentials.
+.KS
+.NH 2
+\&DES Authentication
+.LP
+UNIX authentication suffers from two major problems:
+.IP 1.
+The naming is too UNIX-system oriented.
+.IP 2.
+There is no verifier, so credentials can easily be faked.
+.LP
+DES authentication attempts to fix these two problems.
+.KE
+.NH 3
+\&Naming
+.LP
+The first problem is handled by addressing the caller by a simple
+string of characters instead of by an operating system specific
+integer. This string of characters is known as the "netname" or
+network name of the caller. The server is not allowed to interpret
+the contents of the caller's name in any other way except to
+identify the caller. Thus, netnames should be unique for every
+caller in the internet.
+.LP
+It is up to each operating system's implementation of DES
+authentication to generate netnames for its users that insure this
+uniqueness when they call upon remote servers. Operating systems
+already know how to distinguish users local to their systems. It is
+usually a simple matter to extend this mechanism to the network.
+For example, a UNIX user at Sun with a user ID of 515 might be
+assigned the following netname: "unix.515@sun.com". This netname
+contains three items that serve to insure it is unique. Going
+backwards, there is only one naming domain called "sun.com" in the
+internet. Within this domain, there is only one UNIX user with
+user ID 515. However, there may be another user on another
+operating system, for example VMS, within the same naming domain
+that, by coincidence, happens to have the same user ID. To insure
+that these two users can be distinguished we add the operating
+system name. So one user is "unix.515@sun.com" and the other is
+"vms.515@sun.com".
+.LP
+The first field is actually a naming method rather than an
+operating system name. It just happens that today there is almost
+a one-to-one correspondence between naming methods and operating
+systems. If the world could agree on a naming standard, the first
+field could be the name of that standard, instead of an operating
+system name.
+.LP
+.NH 3
+\&DES Authentication Verifiers
+.LP
+Unlike UNIX authentication, DES authentication does have a verifier
+so the server can validate the client's credential (and
+vice-versa). The contents of this verifier is primarily an
+encrypted timestamp. The server can decrypt this timestamp, and if
+it is close to what the real time is, then the client must have
+encrypted it correctly. The only way the client could encrypt it
+correctly is to know the "conversation key" of the RPC session. And
+if the client knows the conversation key, then it must be the real
+client.
+.LP
+The conversation key is a DES [5] key which the client generates
+and notifies the server of in its first RPC call. The conversation
+key is encrypted using a public key scheme in this first
+transaction. The particular public key scheme used in DES
+authentication is Diffie-Hellman [3] with 192-bit keys. The
+details of this encryption method are described later.
+.LP
+The client and the server need the same notion of the current time
+in order for all of this to work. If network time synchronization
+cannot be guaranteed, then client can synchronize with the server
+before beginning the conversation, perhaps by consulting the
+Internet Time Server (TIME[4]).
+.LP
+The way a server determines if a client timestamp is valid is
+somewhat complicated. For any other transaction but the first, the
+server just checks for two things:
+.IP 1.
+the timestamp is greater than the one previously seen from the
+same client.
+.IP 2.
+the timestamp has not expired.
+.LP
+A timestamp is expired if the server's time is later than the sum
+of the client's timestamp plus what is known as the client's
+"window". The "window" is a number the client passes (encrypted)
+to the server in its first transaction. You can think of it as a
+lifetime for the credential.
+.LP
+This explains everything but the first transaction. In the first
+transaction, the server checks only that the timestamp has not
+expired. If this was all that was done though, then it would be
+quite easy for the client to send random data in place of the
+timestamp with a fairly good chance of succeeding. As an added
+check, the client sends an encrypted item in the first transaction
+known as the "window verifier" which must be equal to the window
+minus 1, or the server will reject the credential.
+.LP
+The client too must check the verifier returned from the server to
+be sure it is legitimate. The server sends back to the client the
+encrypted timestamp it received from the client, minus one second.
+If the client gets anything different than this, it will reject it.
+.LP
+.NH 3
+\&Nicknames and Clock Synchronization
+.LP
+After the first transaction, the server's DES authentication
+subsystem returns in its verifier to the client an integer
+"nickname" which the client may use in its further transactions
+instead of passing its netname, encrypted DES key and window every
+time. The nickname is most likely an index into a table on the
+server which stores for each client its netname, decrypted DES key
+and window.
+.LP
+Though they originally were synchronized, the client's and server's
+clocks can get out of sync again. When this happens the client RPC
+subsystem most likely will get back
+.I RPC_AUTHERROR
+at which point it should resynchronize.
+.LP
+A client may still get the
+.I RPC_AUTHERROR
+error even though it is
+synchronized with the server. The reason is that the server's
+nickname table is a limited size, and it may flush entries whenever
+it wants. A client should resend its original credential in this
+case and the server will give it a new nickname. If a server
+crashes, the entire nickname table gets flushed, and all clients
+will have to resend their original credentials.
+.KS
+.NH 3
+\&DES Authentication Protocol (in XDR language)
+.ie t .DS
+.el .DS L
+.ft I
+/*
+* There are two kinds of credentials: one in which the client uses
+* its full network name, and one in which it uses its "nickname"
+* (just an unsigned integer) given to it by the server. The
+* client must use its fullname in its first transaction with the
+* server, in which the server will return to the client its
+* nickname. The client may use its nickname in all further
+* transactions with the server. There is no requirement to use the
+* nickname, but it is wise to use it for performance reasons.
+*/
+.ft CW
+enum authdes_namekind {
+ ADN_FULLNAME = 0,
+ ADN_NICKNAME = 1
+};
+
+.ft I
+/*
+* A 64-bit block of encrypted DES data
+*/
+.ft CW
+typedef opaque des_block[8];
+
+.ft I
+/*
+* Maximum length of a network user's name
+*/
+.ft CW
+const MAXNETNAMELEN = 255;
+
+.ft I
+/*
+* A fullname contains the network name of the client, an encrypted
+* conversation key and the window. The window is actually a
+* lifetime for the credential. If the time indicated in the
+* verifier timestamp plus the window has past, then the server
+* should expire the request and not grant it. To insure that
+* requests are not replayed, the server should insist that
+* timestamps are greater than the previous one seen, unless it is
+* the first transaction. In the first transaction, the server
+* checks instead that the window verifier is one less than the
+* window.
+*/
+.ft CW
+struct authdes_fullname {
+string name<MAXNETNAMELEN>; /* \fIname of client \f(CW*/
+des_block key; /* \fIPK encrypted conversation key \f(CW*/
+unsigned int window; /* \fIencrypted window \f(CW*/
+};
+
+.ft I
+/*
+* A credential is either a fullname or a nickname
+*/
+.ft CW
+union authdes_cred switch (authdes_namekind adc_namekind) {
+ case ADN_FULLNAME:
+ authdes_fullname adc_fullname;
+ case ADN_NICKNAME:
+ unsigned int adc_nickname;
+};
+
+.ft I
+/*
+* A timestamp encodes the time since midnight, January 1, 1970.
+*/
+.ft CW
+struct timestamp {
+ unsigned int seconds; /* \fIseconds \fP*/
+ unsigned int useconds; /* \fIand microseconds \fP*/
+};
+
+.ft I
+/*
+* Verifier: client variety
+* The window verifier is only used in the first transaction. In
+* conjunction with a fullname credential, these items are packed
+* into the following structure before being encrypted:
+*
+* \f(CWstruct {\fP
+* \f(CWadv_timestamp; \fP-- one DES block
+* \f(CWadc_fullname.window; \fP-- one half DES block
+* \f(CWadv_winverf; \fP-- one half DES block
+* \f(CW}\fP
+* This structure is encrypted using CBC mode encryption with an
+* input vector of zero. All other encryptions of timestamps use
+* ECB mode encryption.
+*/
+.ft CW
+struct authdes_verf_clnt {
+ timestamp adv_timestamp; /* \fIencrypted timestamp \fP*/
+ unsigned int adv_winverf; /* \fIencrypted window verifier \fP*/
+};
+
+.ft I
+/*
+* Verifier: server variety
+* The server returns (encrypted) the same timestamp the client
+* gave it minus one second. It also tells the client its nickname
+* to be used in future transactions (unencrypted).
+*/
+.ft CW
+struct authdes_verf_svr {
+timestamp adv_timeverf; /* \fIencrypted verifier \fP*/
+unsigned int adv_nickname; /* \fInew nickname for client \fP*/
+};
+.DE
+.KE
+.NH 3
+\&Diffie-Hellman Encryption
+.LP
+In this scheme, there are two constants,
+.I BASE
+and
+.I MODULUS .
+The
+particular values Sun has chosen for these for the DES
+authentication protocol are:
+.ie t .DS
+.el .DS L
+.ft CW
+const BASE = 3;
+const MODULUS =
+ "d4a0ba0250b6fd2ec626e7efd637df76c716e22d0944b88b"; /* \fIhex \fP*/
+.DE
+.ft R
+The way this scheme works is best explained by an example. Suppose
+there are two people "A" and "B" who want to send encrypted
+messages to each other. So, A and B both generate "secret" keys at
+random which they do not reveal to anyone. Let these keys be
+represented as SK(A) and SK(B). They also publish in a public
+directory their "public" keys. These keys are computed as follows:
+.ie t .DS
+.el .DS L
+.ft CW
+PK(A) = ( BASE ** SK(A) ) mod MODULUS
+PK(B) = ( BASE ** SK(B) ) mod MODULUS
+.DE
+.ft R
+The "**" notation is used here to represent exponentiation. Now,
+both A and B can arrive at the "common" key between them,
+represented here as CK(A, B), without revealing their secret keys.
+.LP
+A computes:
+.ie t .DS
+.el .DS L
+.ft CW
+CK(A, B) = ( PK(B) ** SK(A)) mod MODULUS
+.DE
+.ft R
+while B computes:
+.ie t .DS
+.el .DS L
+.ft CW
+CK(A, B) = ( PK(A) ** SK(B)) mod MODULUS
+.DE
+.ft R
+These two can be shown to be equivalent:
+.ie t .DS
+.el .DS L
+.ft CW
+(PK(B) ** SK(A)) mod MODULUS = (PK(A) ** SK(B)) mod MODULUS
+.DE
+.ft R
+We drop the "mod MODULUS" parts and assume modulo arithmetic to
+simplify things:
+.ie t .DS
+.el .DS L
+.ft CW
+PK(B) ** SK(A) = PK(A) ** SK(B)
+.DE
+.ft R
+Then, replace PK(B) by what B computed earlier and likewise for
+PK(A).
+.ie t .DS
+.el .DS L
+.ft CW
+((BASE ** SK(B)) ** SK(A) = (BASE ** SK(A)) ** SK(B)
+.DE
+.ft R
+which leads to:
+.ie t .DS
+.el .DS L
+.ft CW
+BASE ** (SK(A) * SK(B)) = BASE ** (SK(A) * SK(B))
+.DE
+.ft R
+This common key CK(A, B) is not used to encrypt the timestamps used
+in the protocol. Rather, it is used only to encrypt a conversation
+key which is then used to encrypt the timestamps. The reason for
+doing this is to use the common key as little as possible, for fear
+that it could be broken. Breaking the conversation key is a far
+less serious offense, since conversations are relatively
+short-lived.
+.LP
+The conversation key is encrypted using 56-bit DES keys, yet the
+common key is 192 bits. To reduce the number of bits, 56 bits are
+selected from the common key as follows. The middle-most 8-bytes
+are selected from the common key, and then parity is added to the
+lower order bit of each byte, producing a 56-bit key with 8 bits of
+parity.
+.KS
+.NH 1
+\&Record Marking Standard
+.LP
+When RPC messages are passed on top of a byte stream protocol (like
+TCP/IP), it is necessary, or at least desirable, to delimit one
+message from another in order to detect and possibly recover from
+user protocol errors. This is called record marking (RM). Sun uses
+this RM/TCP/IP transport for passing RPC messages on TCP streams.
+One RPC message fits into one RM record.
+.LP
+A record is composed of one or more record fragments. A record
+fragment is a four-byte header followed by 0 to (2**31) - 1 bytes of
+fragment data. The bytes encode an unsigned binary number; as with
+XDR integers, the byte order is from highest to lowest. The number
+encodes two values\(ema boolean which indicates whether the fragment
+is the last fragment of the record (bit value 1 implies the fragment
+is the last fragment) and a 31-bit unsigned binary value which is the
+length in bytes of the fragment's data. The boolean value is the
+highest-order bit of the header; the length is the 31 low-order bits.
+(Note that this record specification is NOT in XDR standard form!)
+.KE
+.KS
+.NH 1
+\&The RPC Language
+.LP
+Just as there was a need to describe the XDR data-types in a formal
+language, there is also need to describe the procedures that operate
+on these XDR data-types in a formal language as well. We use the RPC
+Language for this purpose. It is an extension to the XDR language.
+The following example is used to describe the essence of the
+language.
+.NH 2
+\&An Example Service Described in the RPC Language
+.LP
+Here is an example of the specification of a simple ping program.
+.ie t .DS
+.el .DS L
+.vs 11
+.ft I
+/*
+* Simple ping program
+*/
+.ft CW
+program PING_PROG {
+ /* \fILatest and greatest version\fP */
+ version PING_VERS_PINGBACK {
+ void
+ PINGPROC_NULL(void) = 0;
+
+.ft I
+ /*
+ * Ping the caller, return the round-trip time
+ * (in microseconds). Returns -1 if the operation
+ * timed out.
+ */
+.ft CW
+ int
+ PINGPROC_PINGBACK(void) = 1;
+} = 2;
+
+.ft I
+/*
+* Original version
+*/
+.ft CW
+version PING_VERS_ORIG {
+ void
+ PINGPROC_NULL(void) = 0;
+ } = 1;
+} = 1;
+
+const PING_VERS = 2; /* \fIlatest version \fP*/
+.vs
+.DE
+.KE
+.LP
+The first version described is
+.I PING_VERS_PINGBACK
+with two procedures,
+.I PINGPROC_NULL
+and
+.I PINGPROC_PINGBACK .
+.I PINGPROC_NULL
+takes no arguments and returns no results, but it is useful for
+computing round-trip times from the client to the server and back
+again. By convention, procedure 0 of any RPC protocol should have
+the same semantics, and never require any kind of authentication.
+The second procedure is used for the client to have the server do a
+reverse ping operation back to the client, and it returns the amount
+of time (in microseconds) that the operation used. The next version,
+.I PING_VERS_ORIG ,
+is the original version of the protocol
+and it does not contain
+.I PINGPROC_PINGBACK
+procedure. It is useful
+for compatibility with old client programs, and as this program
+matures it may be dropped from the protocol entirely.
+.KS
+.NH 2
+\&The RPC Language Specification
+.LP
+The RPC language is identical to the XDR language, except for the
+added definition of a
+.I program-def
+described below.
+.DS
+.ft CW
+program-def:
+ "program" identifier "{"
+ version-def
+ version-def *
+ "}" "=" constant ";"
+
+version-def:
+ "version" identifier "{"
+ procedure-def
+ procedure-def *
+ "}" "=" constant ";"
+
+procedure-def:
+ type-specifier identifier "(" type-specifier ")"
+ "=" constant ";"
+.DE
+.KE
+.NH 2
+\&Syntax Notes
+.IP 1.
+The following keywords are added and cannot be used as
+identifiers: "program" and "version";
+.IP 2.
+A version name cannot occur more than once within the scope of
+a program definition. Nor can a version number occur more than once
+within the scope of a program definition.
+.IP 3.
+A procedure name cannot occur more than once within the scope
+of a version definition. Nor can a procedure number occur more than
+once within the scope of version definition.
+.IP 4.
+Program identifiers are in the same name space as constant and
+type identifiers.
+.IP 5.
+Only unsigned constants can be assigned to programs, versions
+and procedures.
+.NH 1
+\&Port Mapper Program Protocol
+.LP
+The port mapper program maps RPC program and version numbers to
+transport-specific port numbers. This program makes dynamic binding
+of remote programs possible.
+.LP
+This is desirable because the range of reserved port numbers is very
+small and the number of potential remote programs is very large. By
+running only the port mapper on a reserved port, the port numbers of
+other remote programs can be ascertained by querying the port mapper.
+.LP
+The port mapper also aids in broadcast RPC. A given RPC program will
+usually have different port number bindings on different machines, so
+there is no way to directly broadcast to all of these programs. The
+port mapper, however, does have a fixed port number. So, to
+broadcast to a given program, the client actually sends its message
+to the port mapper located at the broadcast address. Each port
+mapper that picks up the broadcast then calls the local service
+specified by the client. When the port mapper gets the reply from
+the local service, it sends the reply on back to the client.
+.KS
+.NH 2
+\&Port Mapper Protocol Specification (in RPC Language)
+.ie t .DS
+.el .DS L
+.ft CW
+.vs 11
+const PMAP_PORT = 111; /* \fIportmapper port number \fP*/
+
+.ft I
+/*
+* A mapping of (program, version, protocol) to port number
+*/
+.ft CW
+struct mapping {
+ unsigned int prog;
+ unsigned int vers;
+ unsigned int prot;
+ unsigned int port;
+};
+
+.ft I
+/*
+* Supported values for the "prot" field
+*/
+.ft CW
+const IPPROTO_TCP = 6; /* \fIprotocol number for TCP/IP \fP*/
+const IPPROTO_UDP = 17; /* \fIprotocol number for UDP/IP \fP*/
+
+.ft I
+/*
+* A list of mappings
+*/
+.ft CW
+struct *pmaplist {
+ mapping map;
+ pmaplist next;
+};
+.vs
+.DE
+.ie t .DS
+.el .DS L
+.vs 11
+.ft I
+/*
+* Arguments to callit
+*/
+.ft CW
+struct call_args {
+ unsigned int prog;
+ unsigned int vers;
+ unsigned int proc;
+ opaque args<>;
+};
+
+.ft I
+/*
+* Results of callit
+*/
+.ft CW
+struct call_result {
+ unsigned int port;
+ opaque res<>;
+};
+.vs
+.DE
+.KE
+.ie t .DS
+.el .DS L
+.vs 11
+.ft I
+/*
+* Port mapper procedures
+*/
+.ft CW
+program PMAP_PROG {
+ version PMAP_VERS {
+ void
+ PMAPPROC_NULL(void) = 0;
+
+ bool
+ PMAPPROC_SET(mapping) = 1;
+
+ bool
+ PMAPPROC_UNSET(mapping) = 2;
+
+ unsigned int
+ PMAPPROC_GETPORT(mapping) = 3;
+
+ pmaplist
+ PMAPPROC_DUMP(void) = 4;
+
+ call_result
+ PMAPPROC_CALLIT(call_args) = 5;
+ } = 2;
+} = 100000;
+.vs
+.DE
+.NH 2
+\&Port Mapper Operation
+.LP
+The portmapper program currently supports two protocols (UDP/IP and
+TCP/IP). The portmapper is contacted by talking to it on assigned
+port number 111 (SUNRPC [8]) on either of these protocols. The
+following is a description of each of the portmapper procedures:
+.IP \fBPMAPPROC_NULL:\fP
+This procedure does no work. By convention, procedure zero of any
+protocol takes no parameters and returns no results.
+.IP \fBPMAPPROC_SET:\fP
+When a program first becomes available on a machine, it registers
+itself with the port mapper program on the same machine. The program
+passes its program number "prog", version number "vers", transport
+protocol number "prot", and the port "port" on which it awaits
+service request. The procedure returns a boolean response whose
+value is
+.I TRUE
+if the procedure successfully established the mapping and
+.I FALSE
+otherwise. The procedure refuses to establish
+a mapping if one already exists for the tuple "(prog, vers, prot)".
+.IP \fBPMAPPROC_UNSET:\fP
+When a program becomes unavailable, it should unregister itself with
+the port mapper program on the same machine. The parameters and
+results have meanings identical to those of
+.I PMAPPROC_SET .
+The protocol and port number fields of the argument are ignored.
+.IP \fBPMAPPROC_GETPORT:\fP
+Given a program number "prog", version number "vers", and transport
+protocol number "prot", this procedure returns the port number on
+which the program is awaiting call requests. A port value of zeros
+means the program has not been registered. The "port" field of the
+argument is ignored.
+.IP \fBPMAPPROC_DUMP:\fP
+This procedure enumerates all entries in the port mapper's database.
+The procedure takes no parameters and returns a list of program,
+version, protocol, and port values.
+.IP \fBPMAPPROC_CALLIT:\fP
+This procedure allows a caller to call another remote procedure on
+the same machine without knowing the remote procedure's port number.
+It is intended for supporting broadcasts to arbitrary remote programs
+via the well-known port mapper's port. The parameters "prog",
+"vers", "proc", and the bytes of "args" are the program number,
+version number, procedure number, and parameters of the remote
+procedure.
+.LP
+.B Note:
+.RS
+.IP 1.
+This procedure only sends a response if the procedure was
+successfully executed and is silent (no response) otherwise.
+.IP 2.
+The port mapper communicates with the remote program using UDP/IP
+only.
+.RE
+.LP
+The procedure returns the remote program's port number, and the bytes
+of results are the results of the remote procedure.
+.bp
+.NH 1
+\&References
+.LP
+[1] Birrell, Andrew D. & Nelson, Bruce Jay; "Implementing Remote
+Procedure Calls"; XEROX CSL-83-7, October 1983.
+.LP
+[2] Cheriton, D.; "VMTP: Versatile Message Transaction Protocol",
+Preliminary Version 0.3; Stanford University, January 1987.
+.LP
+[3] Diffie & Hellman; "New Directions in Cryptography"; IEEE
+Transactions on Information Theory IT-22, November 1976.
+.LP
+[4] Harrenstien, K.; "Time Server", RFC 738; Information Sciences
+Institute, October 1977.
+.LP
+[5] National Bureau of Standards; "Data Encryption Standard"; Federal
+Information Processing Standards Publication 46, January 1977.
+.LP
+[6] Postel, J.; "Transmission Control Protocol - DARPA Internet
+Program Protocol Specification", RFC 793; Information Sciences
+Institute, September 1981.
+.LP
+[7] Postel, J.; "User Datagram Protocol", RFC 768; Information Sciences
+Institute, August 1980.
+.LP
+[8] Reynolds, J. & Postel, J.; "Assigned Numbers", RFC 923; Information
+Sciences Institute, October 1984.
diff --git a/lib/libc/rpc/PSD.doc/rpcgen.ms b/lib/libc/rpc/PSD.doc/rpcgen.ms
new file mode 100644
index 0000000..b4e50e5
--- /dev/null
+++ b/lib/libc/rpc/PSD.doc/rpcgen.ms
@@ -0,0 +1,1299 @@
+.\"
+.\" Must use -- tbl -- for this one
+.\"
+.\" @(#)rpcgen.ms 2.2 88/08/04 4.0 RPCSRC
+.de BT
+.if \\n%=1 .tl ''- % -''
+..
+.ND
+.\" prevent excess underlining in nroff
+.if n .fp 2 R
+.OH '\fBrpcgen\fP Programming Guide''Page %'
+.EH 'Page %''\fBrpcgen\fP Programming Guide'
+.if \\n%=1 .bp
+.SH
+\&\fBrpcgen\fP Programming Guide
+.NH 0
+\&The \fBrpcgen\fP Protocol Compiler
+.IX rpcgen "" \fIrpcgen\fP "" PAGE MAJOR
+.LP
+.IX RPC "" "" \fIrpcgen\fP
+The details of programming applications to use Remote Procedure Calls
+can be overwhelming. Perhaps most daunting is the writing of the XDR
+routines necessary to convert procedure arguments and results into
+their network format and vice-versa.
+.LP
+Fortunately,
+.I rpcgen(1)
+exists to help programmers write RPC applications simply and directly.
+.I rpcgen
+does most of the dirty work, allowing programmers to debug
+the main features of their application, instead of requiring them to
+spend most of their time debugging their network interface code.
+.LP
+.I rpcgen
+is a compiler. It accepts a remote program interface definition written
+in a language, called RPC Language, which is similar to C. It produces a C
+language output which includes stub versions of the client routines, a
+server skeleton, XDR filter routines for both parameters and results, and a
+header file that contains common definitions. The client stubs interface
+with the RPC library and effectively hide the network from their callers.
+The server stub similarly hides the network from the server procedures that
+are to be invoked by remote clients.
+.I rpcgen 's
+output files can be compiled and linked in the usual way. The developer
+writes server procedures\(emin any language that observes Sun calling
+conventions\(emand links them with the server skeleton produced by
+.I rpcgen
+to get an executable server program. To use a remote program, a programmer
+writes an ordinary main program that makes local procedure calls to the
+client stubs produced by
+.I rpcgen .
+Linking this program with
+.I rpcgen 's
+stubs creates an executable program. (At present the main program must be
+written in C).
+.I rpcgen
+options can be used to suppress stub generation and to specify the transport
+to be used by the server stub.
+.LP
+Like all compilers,
+.I rpcgen
+reduces development time
+that would otherwise be spent coding and debugging low-level routines.
+All compilers, including
+.I rpcgen ,
+do this at a small cost in efficiency
+and flexibility. However, many compilers allow escape hatches for
+programmers to mix low-level code with high-level code.
+.I rpcgen
+is no exception. In speed-critical applications, hand-written routines
+can be linked with the
+.I rpcgen
+output without any difficulty. Also, one may proceed by using
+.I rpcgen
+output as a starting point, and then rewriting it as necessary.
+(If you need a discussion of RPC programming without
+.I rpcgen ,
+see the
+.I "Remote Procedure Call Programming Guide)\.
+.NH 1
+\&Converting Local Procedures into Remote Procedures
+.IX rpcgen "local procedures" \fIrpcgen\fP
+.IX rpcgen "remote procedures" \fIrpcgen\fP
+.LP
+Assume an application that runs on a single machine, one which we want
+to convert to run over the network. Here we will demonstrate such a
+conversion by way of a simple example\(ema program that prints a
+message to the console:
+.ie t .DS
+.el .DS L
+.ft I
+/*
+ * printmsg.c: print a message on the console
+ */
+.ft CW
+#include <stdio.h>
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ char *message;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <message>\en", argv[0]);
+ exit(1);
+ }
+ message = argv[1];
+
+ if (!printmessage(message)) {
+ fprintf(stderr, "%s: couldn't print your message\en",
+ argv[0]);
+ exit(1);
+ }
+ printf("Message Delivered!\en");
+ exit(0);
+}
+.ft I
+/*
+ * Print a message to the console.
+ * Return a boolean indicating whether the message was actually printed.
+ */
+.ft CW
+printmessage(msg)
+ char *msg;
+{
+ FILE *f;
+
+ f = fopen("/dev/console", "w");
+ if (f == NULL) {
+ return (0);
+ }
+ fprintf(f, "%s\en", msg);
+ fclose(f);
+ return(1);
+}
+.DE
+.LP
+And then, of course:
+.ie t .DS
+.el .DS L
+.ft CW
+example% \fBcc printmsg.c -o printmsg\fP
+example% \fBprintmsg "Hello, there."\fP
+Message delivered!
+example%
+.DE
+.LP
+If
+.I printmessage()
+was turned into a remote procedure,
+then it could be called from anywhere in the network.
+Ideally, one would just like to stick a keyword like
+.I remote
+in front of a
+procedure to turn it into a remote procedure. Unfortunately,
+we have to live within the constraints of the C language, since
+it existed long before RPC did. But even without language
+support, it's not very difficult to make a procedure remote.
+.LP
+In general, it's necessary to figure out what the types are for
+all procedure inputs and outputs. In this case, we have a
+procedure
+.I printmessage()
+which takes a string as input, and returns an integer
+as output. Knowing this, we can write a protocol specification in RPC
+language that describes the remote version of
+.I printmessage ().
+Here it is:
+.ie t .DS
+.el .DS L
+.ft I
+/*
+ * msg.x: Remote message printing protocol
+ */
+.ft CW
+
+program MESSAGEPROG {
+ version MESSAGEVERS {
+ int PRINTMESSAGE(string) = 1;
+ } = 1;
+} = 99;
+.DE
+.LP
+Remote procedures are part of remote programs, so we actually declared
+an entire remote program here which contains the single procedure
+.I PRINTMESSAGE .
+This procedure was declared to be in version 1 of the
+remote program. No null procedure (procedure 0) is necessary because
+.I rpcgen
+generates it automatically.
+.LP
+Notice that everything is declared with all capital letters. This is
+not required, but is a good convention to follow.
+.LP
+Notice also that the argument type is \*Qstring\*U and not \*Qchar *\*U. This
+is because a \*Qchar *\*U in C is ambiguous. Programmers usually intend it
+to mean a null-terminated string of characters, but it could also
+represent a pointer to a single character or a pointer to an array of
+characters. In RPC language, a null-terminated string is
+unambiguously called a \*Qstring\*U.
+.LP
+There are just two more things to write. First, there is the remote
+procedure itself. Here's the definition of a remote procedure
+to implement the
+.I PRINTMESSAGE
+procedure we declared above:
+.ie t .DS
+.el .DS L
+.vs 11
+.ft I
+/*
+ * msg_proc.c: implementation of the remote procedure "printmessage"
+ */
+.ft CW
+
+#include <stdio.h>
+#include <rpc/rpc.h> /* \fIalways needed\fP */
+#include "msg.h" /* \fIneed this too: msg.h will be generated by rpcgen\fP */
+
+.ft I
+/*
+ * Remote verson of "printmessage"
+ */
+.ft CW
+int *
+printmessage_1(msg)
+ char **msg;
+{
+ static int result; /* \fImust be static!\fP */
+ FILE *f;
+
+ f = fopen("/dev/console", "w");
+ if (f == NULL) {
+ result = 0;
+ return (&result);
+ }
+ fprintf(f, "%s\en", *msg);
+ fclose(f);
+ result = 1;
+ return (&result);
+}
+.vs
+.DE
+.LP
+Notice here that the declaration of the remote procedure
+.I printmessage_1()
+differs from that of the local procedure
+.I printmessage()
+in three ways:
+.IP 1.
+It takes a pointer to a string instead of a string itself. This
+is true of all remote procedures: they always take pointers to their
+arguments rather than the arguments themselves.
+.IP 2.
+It returns a pointer to an integer instead of an integer itself. This is
+also generally true of remote procedures: they always return a pointer
+to their results.
+.IP 3.
+It has an \*Q_1\*U appended to its name. In general, all remote
+procedures called by
+.I rpcgen
+are named by the following rule: the name in the program definition
+(here
+.I PRINTMESSAGE )
+is converted to all
+lower-case letters, an underbar (\*Q_\*U) is appended to it, and
+finally the version number (here 1) is appended.
+.LP
+The last thing to do is declare the main client program that will call
+the remote procedure. Here it is:
+.ie t .DS
+.el .DS L
+.ft I
+/*
+ * rprintmsg.c: remote version of "printmsg.c"
+ */
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h> /* \fIalways needed\fP */
+#include "msg.h" /* \fIneed this too: msg.h will be generated by rpcgen\fP */
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ CLIENT *cl;
+ int *result;
+ char *server;
+ char *message;
+
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s host message\en", argv[0]);
+ exit(1);
+ }
+
+.ft I
+ /*
+ * Save values of command line arguments
+ */
+.ft CW
+ server = argv[1];
+ message = argv[2];
+
+.ft I
+ /*
+ * Create client "handle" used for calling \fIMESSAGEPROG\fP on the
+ * server designated on the command line. We tell the RPC package
+ * to use the "tcp" protocol when contacting the server.
+ */
+.ft CW
+ cl = clnt_create(server, MESSAGEPROG, MESSAGEVERS, "tcp");
+ if (cl == NULL) {
+.ft I
+ /*
+ * Couldn't establish connection with server.
+ * Print error message and die.
+ */
+.ft CW
+ clnt_pcreateerror(server);
+ exit(1);
+ }
+
+.ft I
+ /*
+ * Call the remote procedure "printmessage" on the server
+ */
+.ft CW
+ result = printmessage_1(&message, cl);
+ if (result == NULL) {
+.ft I
+ /*
+ * An error occurred while calling the server.
+ * Print error message and die.
+ */
+.ft CW
+ clnt_perror(cl, server);
+ exit(1);
+ }
+
+.ft I
+ /*
+ * Okay, we successfully called the remote procedure.
+ */
+.ft CW
+ if (*result == 0) {
+.ft I
+ /*
+ * Server was unable to print our message.
+ * Print error message and die.
+ */
+.ft CW
+ fprintf(stderr, "%s: %s couldn't print your message\en",
+ argv[0], server);
+ exit(1);
+ }
+
+.ft I
+ /*
+ * The message got printed on the server's console
+ */
+.ft CW
+ printf("Message delivered to %s!\en", server);
+}
+.DE
+There are two things to note here:
+.IP 1.
+.IX "client handle, used by rpcgen" "" "client handle, used by \fIrpcgen\fP"
+First a client \*Qhandle\*U is created using the RPC library routine
+.I clnt_create ().
+This client handle will be passed to the stub routines
+which call the remote procedure.
+.IP 2.
+The remote procedure
+.I printmessage_1()
+is called exactly the same way as it is declared in
+.I msg_proc.c
+except for the inserted client handle as the first argument.
+.LP
+Here's how to put all of the pieces together:
+.ie t .DS
+.el .DS L
+.ft CW
+example% \fBrpcgen msg.x\fP
+example% \fBcc rprintmsg.c msg_clnt.c -o rprintmsg\fP
+example% \fBcc msg_proc.c msg_svc.c -o msg_server\fP
+.DE
+Two programs were compiled here: the client program
+.I rprintmsg
+and the server program
+.I msg_server .
+Before doing this though,
+.I rpcgen
+was used to fill in the missing pieces.
+.LP
+Here is what
+.I rpcgen
+did with the input file
+.I msg.x :
+.IP 1.
+It created a header file called
+.I msg.h
+that contained
+.I #define 's
+for
+.I MESSAGEPROG ,
+.I MESSAGEVERS
+and
+.I PRINTMESSAGE
+for use in the other modules.
+.IP 2.
+It created client \*Qstub\*U routines in the
+.I msg_clnt.c
+file. In this case there is only one, the
+.I printmessage_1()
+that was referred to from the
+.I printmsg
+client program. The name of the output file for
+client stub routines is always formed in this way: if the name of the
+input file is
+.I FOO.x ,
+the client stubs output file is called
+.I FOO_clnt.c .
+.IP 3.
+It created the server program which calls
+.I printmessage_1()
+in
+.I msg_proc.c .
+This server program is named
+.I msg_svc.c .
+The rule for naming the server output file is similar to the
+previous one: for an input file called
+.I FOO.x ,
+the output server file is named
+.I FOO_svc.c .
+.LP
+Now we're ready to have some fun. First, copy the server to a
+remote machine and run it. For this example, the
+machine is called \*Qmoon\*U. Server processes are run in the
+background, because they never exit.
+.ie t .DS
+.el .DS L
+.ft CW
+moon% \fBmsg_server &\fP
+.DE
+Then on our local machine (\*Qsun\*U) we can print a message on \*Qmoon\*Us
+console.
+.ie t .DS
+.el .DS L
+.ft CW
+sun% \fBprintmsg moon "Hello, moon."\fP
+.DE
+The message will get printed to \*Qmoon\*Us console. You can print a
+message on anybody's console (including your own) with this program if
+you are able to copy the server to their machine and run it.
+.NH 1
+\&Generating XDR Routines
+.IX RPC "generating XDR routines"
+.LP
+The previous example only demonstrated the automatic generation of
+client and server RPC code.
+.I rpcgen
+may also be used to generate XDR routines, that is, the routines
+necessary to convert local data
+structures into network format and vice-versa. This example presents
+a complete RPC service\(ema remote directory listing service, which uses
+.I rpcgen
+not only to generate stub routines, but also to generate the XDR
+routines. Here is the protocol description file:
+.ie t .DS
+.el .DS L
+.ft I
+/*
+ * dir.x: Remote directory listing protocol
+ */
+.ft CW
+const MAXNAMELEN = 255; /* \fImaximum length of a directory entry\fP */
+
+typedef string nametype<MAXNAMELEN>; /* \fIa directory entry\fP */
+
+typedef struct namenode *namelist; /* \fIa link in the listing\fP */
+
+.ft I
+/*
+ * A node in the directory listing
+ */
+.ft CW
+struct namenode {
+ nametype name; /* \fIname of directory entry\fP */
+ namelist next; /* \fInext entry\fP */
+};
+
+.ft I
+/*
+ * The result of a READDIR operation.
+ */
+.ft CW
+union readdir_res switch (int errno) {
+case 0:
+ namelist list; /* \fIno error: return directory listing\fP */
+default:
+ void; /* \fIerror occurred: nothing else to return\fP */
+};
+
+.ft I
+/*
+ * The directory program definition
+ */
+.ft CW
+program DIRPROG {
+ version DIRVERS {
+ readdir_res
+ READDIR(nametype) = 1;
+ } = 1;
+} = 76;
+.DE
+.SH
+Note:
+.I
+Types (like
+.I readdir_res
+in the example above) can be defined using
+the \*Qstruct\*U, \*Qunion\*U and \*Qenum\*U keywords, but those keywords
+should not be used in subsequent declarations of variables of those types.
+For example, if you define a union \*Qfoo\*U, you should declare using
+only \*Qfoo\*U and not \*Qunion foo\*U. In fact,
+.I rpcgen
+compiles
+RPC unions into C structures and it is an error to declare them using the
+\*Qunion\*U keyword.
+.LP
+Running
+.I rpcgen
+on
+.I dir.x
+creates four output files. Three are the same as before: header file,
+client stub routines and server skeleton. The fourth are the XDR routines
+necessary for converting the data types we declared into XDR format and
+vice-versa. These are output in the file
+.I dir_xdr.c .
+.LP
+Here is the implementation of the
+.I READDIR
+procedure.
+.ie t .DS
+.el .DS L
+.vs 11
+.ft I
+/*
+ * dir_proc.c: remote readdir implementation
+ */
+.ft CW
+#include <rpc/rpc.h>
+#include <sys/dir.h>
+#include "dir.h"
+
+extern int errno;
+extern char *malloc();
+extern char *strdup();
+
+readdir_res *
+readdir_1(dirname)
+ nametype *dirname;
+{
+ DIR *dirp;
+ struct direct *d;
+ namelist nl;
+ namelist *nlp;
+ static readdir_res res; /* \fImust be static\fP! */
+
+.ft I
+ /*
+ * Open directory
+ */
+.ft CW
+ dirp = opendir(*dirname);
+ if (dirp == NULL) {
+ res.errno = errno;
+ return (&res);
+ }
+
+.ft I
+ /*
+ * Free previous result
+ */
+.ft CW
+ xdr_free(xdr_readdir_res, &res);
+
+.ft I
+ /*
+ * Collect directory entries.
+ * Memory allocated here will be freed by \fIxdr_free\fP
+ * next time \fIreaddir_1\fP is called
+ */
+.ft CW
+ nlp = &res.readdir_res_u.list;
+ while (d = readdir(dirp)) {
+ nl = *nlp = (namenode *) malloc(sizeof(namenode));
+ nl->name = strdup(d->d_name);
+ nlp = &nl->next;
+ }
+ *nlp = NULL;
+
+.ft I
+ /*
+ * Return the result
+ */
+.ft CW
+ res.errno = 0;
+ closedir(dirp);
+ return (&res);
+}
+.vs
+.DE
+Finally, there is the client side program to call the server:
+.ie t .DS
+.el .DS L
+.ft I
+/*
+ * rls.c: Remote directory listing client
+ */
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h> /* \fIalways need this\fP */
+#include "dir.h" /* \fIwill be generated by rpcgen\fI */
+
+extern int errno;
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ CLIENT *cl;
+ char *server;
+ char *dir;
+ readdir_res *result;
+ namelist nl;
+
+
+ if (argc != 3) {
+ fprintf(stderr, "usage: %s host directory\en",
+ argv[0]);
+ exit(1);
+ }
+
+.ft I
+ /*
+ * Remember what our command line arguments refer to
+ */
+.ft CW
+ server = argv[1];
+ dir = argv[2];
+
+.ft I
+ /*
+ * Create client "handle" used for calling \fIMESSAGEPROG\fP on the
+ * server designated on the command line. We tell the RPC package
+ * to use the "tcp" protocol when contacting the server.
+ */
+.ft CW
+ cl = clnt_create(server, DIRPROG, DIRVERS, "tcp");
+ if (cl == NULL) {
+.ft I
+ /*
+ * Couldn't establish connection with server.
+ * Print error message and die.
+ */
+.ft CW
+ clnt_pcreateerror(server);
+ exit(1);
+ }
+
+.ft I
+ /*
+ * Call the remote procedure \fIreaddir\fP on the server
+ */
+.ft CW
+ result = readdir_1(&dir, cl);
+ if (result == NULL) {
+.ft I
+ /*
+ * An error occurred while calling the server.
+ * Print error message and die.
+ */
+.ft CW
+ clnt_perror(cl, server);
+ exit(1);
+ }
+
+.ft I
+ /*
+ * Okay, we successfully called the remote procedure.
+ */
+.ft CW
+ if (result->errno != 0) {
+.ft I
+ /*
+ * A remote system error occurred.
+ * Print error message and die.
+ */
+.ft CW
+ errno = result->errno;
+ perror(dir);
+ exit(1);
+ }
+
+.ft I
+ /*
+ * Successfully got a directory listing.
+ * Print it out.
+ */
+.ft CW
+ for (nl = result->readdir_res_u.list; nl != NULL;
+ nl = nl->next) {
+ printf("%s\en", nl->name);
+ }
+ exit(0);
+}
+.DE
+Compile everything, and run.
+.DS
+.ft CW
+sun% \fBrpcgen dir.x\fP
+sun% \fBcc rls.c dir_clnt.c dir_xdr.c -o rls\fP
+sun% \fBcc dir_svc.c dir_proc.c dir_xdr.c -o dir_svc\fP
+
+sun% \fBdir_svc &\fP
+
+moon% \fBrls sun /usr/pub\fP
+\&.
+\&..
+ascii
+eqnchar
+greek
+kbd
+marg8
+tabclr
+tabs
+tabs4
+moon%
+.DE
+.LP
+.IX "debugging with rpcgen" "" "debugging with \fIrpcgen\fP"
+A final note about
+.I rpcgen :
+The client program and the server procedure can be tested together
+as a single program by simply linking them with each other rather
+than with the client and server stubs. The procedure calls will be
+executed as ordinary local procedure calls and the program can be
+debugged with a local debugger such as
+.I dbx .
+When the program is working, the client program can be linked to
+the client stub produced by
+.I rpcgen
+and the server procedures can be linked to the server stub produced
+by
+.I rpcgen .
+.SH
+.I NOTE :
+\fIIf you do this, you may want to comment out calls to RPC library
+routines, and have client-side routines call server routines
+directly.\fP
+.LP
+.NH 1
+\&The C-Preprocessor
+.IX rpcgen "C-preprocessor" \fIrpcgen\fP
+.LP
+The C-preprocessor is run on all input files before they are
+compiled, so all the preprocessor directives are legal within a \*Q.x\*U
+file. Four symbols may be defined, depending upon which output file is
+getting generated. The symbols are:
+.TS
+box tab (&);
+lfI lfI
+lfL l .
+Symbol&Usage
+_
+RPC_HDR&for header-file output
+RPC_XDR&for XDR routine output
+RPC_SVC&for server-skeleton output
+RPC_CLNT&for client stub output
+.TE
+.LP
+Also,
+.I rpcgen
+does a little preprocessing of its own. Any line that
+begins with a percent sign is passed directly into the output file,
+without any interpretation of the line. Here is a simple example that
+demonstrates the preprocessing features.
+.ie t .DS
+.el .DS L
+.ft I
+/*
+ * time.x: Remote time protocol
+ */
+.ft CW
+program TIMEPROG {
+ version TIMEVERS {
+ unsigned int TIMEGET(void) = 1;
+ } = 1;
+} = 44;
+
+#ifdef RPC_SVC
+%int *
+%timeget_1()
+%{
+% static int thetime;
+%
+% thetime = time(0);
+% return (&thetime);
+%}
+#endif
+.DE
+The '%' feature is not generally recommended, as there is no guarantee
+that the compiler will stick the output where you intended.
+.NH 1
+\&\fBrpcgen\fP Programming Notes
+.IX rpcgen "other operations" \fIrpcgen\fP
+.sp
+.NH 2
+\&Timeout Changes
+.IX rpcgen "timeout changes" \fIrpcgen\fP
+.LP
+RPC sets a default timeout of 25 seconds for RPC calls when
+.I clnt_create()
+is used. This timeout may be changed using
+.I clnt_control()
+Here is a small code fragment to demonstrate use of
+.I clnt_control ():
+.ID
+struct timeval tv;
+CLIENT *cl;
+.sp .5
+cl = clnt_create("somehost", SOMEPROG, SOMEVERS, "tcp");
+if (cl == NULL) {
+ exit(1);
+}
+tv.tv_sec = 60; /* \fIchange timeout to 1 minute\fP */
+tv.tv_usec = 0;
+clnt_control(cl, CLSET_TIMEOUT, &tv);
+.DE
+.NH 2
+\&Handling Broadcast on the Server Side
+.IX "broadcast RPC"
+.IX rpcgen "broadcast RPC" \fIrpcgen\fP
+.LP
+When a procedure is known to be called via broadcast RPC,
+it is usually wise for the server to not reply unless it can provide
+some useful information to the client. This prevents the network
+from getting flooded by useless replies.
+.LP
+To prevent the server from replying, a remote procedure can
+return NULL as its result, and the server code generated by
+.I rpcgen
+will detect this and not send out a reply.
+.LP
+Here is an example of a procedure that replies only if it
+thinks it is an NFS server:
+.ID
+void *
+reply_if_nfsserver()
+{
+ char notnull; /* \fIjust here so we can use its address\fP */
+.sp .5
+ if (access("/etc/exports", F_OK) < 0) {
+ return (NULL); /* \fIprevent RPC from replying\fP */
+ }
+.ft I
+ /*
+ * return non-null pointer so RPC will send out a reply
+ */
+.ft L
+ return ((void *)&notnull);
+}
+.DE
+Note that if procedure returns type \*Qvoid *\*U, they must return a non-NULL
+pointer if they want RPC to reply for them.
+.NH 2
+\&Other Information Passed to Server Procedures
+.LP
+Server procedures will often want to know more about an RPC call
+than just its arguments. For example, getting authentication information
+is important to procedures that want to implement some level of security.
+This extra information is actually supplied to the server procedure as a
+second argument. Here is an example to demonstrate its use. What we've
+done here is rewrite the previous
+.I printmessage_1()
+procedure to only allow root users to print a message to the console.
+.ID
+int *
+printmessage_1(msg, rq)
+ char **msg;
+ struct svc_req *rq;
+{
+ static in result; /* \fIMust be static\fP */
+ FILE *f;
+ struct suthunix_parms *aup;
+.sp .5
+ aup = (struct authunix_parms *)rq->rq_clntcred;
+ if (aup->aup_uid != 0) {
+ result = 0;
+ return (&result);
+ }
+.sp
+.ft I
+ /*
+ * Same code as before.
+ */
+.ft L
+}
+.DE
+.NH 1
+\&RPC Language
+.IX RPCL
+.IX rpcgen "RPC Language" \fIrpcgen\fP
+.LP
+RPC language is an extension of XDR language. The sole extension is
+the addition of the
+.I program
+type. For a complete description of the XDR language syntax, see the
+.I "External Data Representation Standard: Protocol Specification"
+chapter. For a description of the RPC extensions to the XDR language,
+see the
+.I "Remote Procedure Calls: Protocol Specification"
+chapter.
+.LP
+However, XDR language is so close to C that if you know C, you know most
+of it already. We describe here the syntax of the RPC language,
+showing a few examples along the way. We also show how the various
+RPC and XDR type definitions get compiled into C type definitions in
+the output header file.
+.KS
+.NH 2
+Definitions
+\&
+.IX rpcgen definitions \fIrpcgen\fP
+.LP
+An RPC language file consists of a series of definitions.
+.DS L
+.ft CW
+ definition-list:
+ definition ";"
+ definition ";" definition-list
+.DE
+.KE
+It recognizes five types of definitions.
+.DS L
+.ft CW
+ definition:
+ enum-definition
+ struct-definition
+ union-definition
+ typedef-definition
+ const-definition
+ program-definition
+.DE
+.NH 2
+Structures
+\&
+.IX rpcgen structures \fIrpcgen\fP
+.LP
+An XDR struct is declared almost exactly like its C counterpart. It
+looks like the following:
+.DS L
+.ft CW
+ struct-definition:
+ "struct" struct-ident "{"
+ declaration-list
+ "}"
+
+ declaration-list:
+ declaration ";"
+ declaration ";" declaration-list
+.DE
+As an example, here is an XDR structure to a two-dimensional
+coordinate, and the C structure that it gets compiled into in the
+output header file.
+.DS
+.ft CW
+ struct coord { struct coord {
+ int x; --> int x;
+ int y; int y;
+ }; };
+ typedef struct coord coord;
+.DE
+The output is identical to the input, except for the added
+.I typedef
+at the end of the output. This allows one to use \*Qcoord\*U instead of
+\*Qstruct coord\*U when declaring items.
+.NH 2
+Unions
+\&
+.IX rpcgen unions \fIrpcgen\fP
+.LP
+XDR unions are discriminated unions, and look quite different from C
+unions. They are more analogous to Pascal variant records than they
+are to C unions.
+.DS L
+.ft CW
+ union-definition:
+ "union" union-ident "switch" "(" declaration ")" "{"
+ case-list
+ "}"
+
+ case-list:
+ "case" value ":" declaration ";"
+ "default" ":" declaration ";"
+ "case" value ":" declaration ";" case-list
+.DE
+Here is an example of a type that might be returned as the result of a
+\*Qread data\*U operation. If there is no error, return a block of data.
+Otherwise, don't return anything.
+.DS L
+.ft CW
+ union read_result switch (int errno) {
+ case 0:
+ opaque data[1024];
+ default:
+ void;
+ };
+.DE
+It gets compiled into the following:
+.DS L
+.ft CW
+ struct read_result {
+ int errno;
+ union {
+ char data[1024];
+ } read_result_u;
+ };
+ typedef struct read_result read_result;
+.DE
+Notice that the union component of the output struct has the name as
+the type name, except for the trailing \*Q_u\*U.
+.NH 2
+Enumerations
+\&
+.IX rpcgen enumerations \fIrpcgen\fP
+.LP
+XDR enumerations have the same syntax as C enumerations.
+.DS L
+.ft CW
+ enum-definition:
+ "enum" enum-ident "{"
+ enum-value-list
+ "}"
+
+ enum-value-list:
+ enum-value
+ enum-value "," enum-value-list
+
+ enum-value:
+ enum-value-ident
+ enum-value-ident "=" value
+.DE
+Here is a short example of an XDR enum, and the C enum that it gets
+compiled into.
+.DS L
+.ft CW
+ enum colortype { enum colortype {
+ RED = 0, RED = 0,
+ GREEN = 1, --> GREEN = 1,
+ BLUE = 2 BLUE = 2,
+ }; };
+ typedef enum colortype colortype;
+.DE
+.NH 2
+Typedef
+\&
+.IX rpcgen typedef \fIrpcgen\fP
+.LP
+XDR typedefs have the same syntax as C typedefs.
+.DS L
+.ft CW
+ typedef-definition:
+ "typedef" declaration
+.DE
+Here is an example that defines a
+.I fname_type
+used for declaring
+file name strings that have a maximum length of 255 characters.
+.DS L
+.ft CW
+typedef string fname_type<255>; --> typedef char *fname_type;
+.DE
+.NH 2
+Constants
+\&
+.IX rpcgen constants \fIrpcgen\fP
+.LP
+XDR constants symbolic constants that may be used wherever a
+integer constant is used, for example, in array size specifications.
+.DS L
+.ft CW
+ const-definition:
+ "const" const-ident "=" integer
+.DE
+For example, the following defines a constant
+.I DOZEN
+equal to 12.
+.DS L
+.ft CW
+ const DOZEN = 12; --> #define DOZEN 12
+.DE
+.NH 2
+Programs
+\&
+.IX rpcgen programs \fIrpcgen\fP
+.LP
+RPC programs are declared using the following syntax:
+.DS L
+.ft CW
+ program-definition:
+ "program" program-ident "{"
+ version-list
+ "}" "=" value
+
+ version-list:
+ version ";"
+ version ";" version-list
+
+ version:
+ "version" version-ident "{"
+ procedure-list
+ "}" "=" value
+
+ procedure-list:
+ procedure ";"
+ procedure ";" procedure-list
+
+ procedure:
+ type-ident procedure-ident "(" type-ident ")" "=" value
+.DE
+For example, here is the time protocol, revisited:
+.ie t .DS
+.el .DS L
+.ft I
+/*
+ * time.x: Get or set the time. Time is represented as number of seconds
+ * since 0:00, January 1, 1970.
+ */
+.ft CW
+program TIMEPROG {
+ version TIMEVERS {
+ unsigned int TIMEGET(void) = 1;
+ void TIMESET(unsigned) = 2;
+ } = 1;
+} = 44;
+.DE
+This file compiles into #defines in the output header file:
+.ie t .DS
+.el .DS L
+.ft CW
+#define TIMEPROG 44
+#define TIMEVERS 1
+#define TIMEGET 1
+#define TIMESET 2
+.DE
+.NH 2
+Declarations
+\&
+.IX rpcgen declarations \fIrpcgen\fP
+.LP
+In XDR, there are only four kinds of declarations.
+.DS L
+.ft CW
+ declaration:
+ simple-declaration
+ fixed-array-declaration
+ variable-array-declaration
+ pointer-declaration
+.DE
+\fB1) Simple declarations\fP are just like simple C declarations.
+.DS L
+.ft CW
+ simple-declaration:
+ type-ident variable-ident
+.DE
+Example:
+.DS L
+.ft CW
+ colortype color; --> colortype color;
+.DE
+\fB2) Fixed-length Array Declarations\fP are just like C array declarations:
+.DS L
+.ft CW
+ fixed-array-declaration:
+ type-ident variable-ident "[" value "]"
+.DE
+Example:
+.DS L
+.ft CW
+ colortype palette[8]; --> colortype palette[8];
+.DE
+\fB3) Variable-Length Array Declarations\fP have no explicit syntax
+in C, so XDR invents its own using angle-brackets.
+.DS L
+.ft CW
+variable-array-declaration:
+ type-ident variable-ident "<" value ">"
+ type-ident variable-ident "<" ">"
+.DE
+The maximum size is specified between the angle brackets. The size may
+be omitted, indicating that the array may be of any size.
+.DS L
+.ft CW
+ int heights<12>; /* \fIat most 12 items\fP */
+ int widths<>; /* \fIany number of items\fP */
+.DE
+Since variable-length arrays have no explicit syntax in C, these
+declarations are actually compiled into \*Qstruct\*Us. For example, the
+\*Qheights\*U declaration gets compiled into the following struct:
+.DS L
+.ft CW
+ struct {
+ u_int heights_len; /* \fI# of items in array\fP */
+ int *heights_val; /* \fIpointer to array\fP */
+ } heights;
+.DE
+Note that the number of items in the array is stored in the \*Q_len\*U
+component and the pointer to the array is stored in the \*Q_val\*U
+component. The first part of each of these component's names is the
+same as the name of the declared XDR variable.
+.LP
+\fB4) Pointer Declarations\fP are made in
+XDR exactly as they are in C. You can't
+really send pointers over the network, but you can use XDR pointers
+for sending recursive data types such as lists and trees. The type is
+actually called \*Qoptional-data\*U, not \*Qpointer\*U, in XDR language.
+.DS L
+.ft CW
+ pointer-declaration:
+ type-ident "*" variable-ident
+.DE
+Example:
+.DS L
+.ft CW
+ listitem *next; --> listitem *next;
+.DE
+.NH 2
+\&Special Cases
+.IX rpcgen "special cases" \fIrpcgen\fP
+.LP
+There are a few exceptions to the rules described above.
+.LP
+.B Booleans:
+C has no built-in boolean type. However, the RPC library does a
+boolean type called
+.I bool_t
+that is either
+.I TRUE
+or
+.I FALSE .
+Things declared as type
+.I bool
+in XDR language are compiled into
+.I bool_t
+in the output header file.
+.LP
+Example:
+.DS L
+.ft CW
+ bool married; --> bool_t married;
+.DE
+.B Strings:
+C has no built-in string type, but instead uses the null-terminated
+\*Qchar *\*U convention. In XDR language, strings are declared using the
+\*Qstring\*U keyword, and compiled into \*Qchar *\*Us in the output header
+file. The maximum size contained in the angle brackets specifies the
+maximum number of characters allowed in the strings (not counting the
+.I NULL
+character). The maximum size may be left off, indicating a string
+of arbitrary length.
+.LP
+Examples:
+.DS L
+.ft CW
+ string name<32>; --> char *name;
+ string longname<>; --> char *longname;
+.DE
+.B "Opaque Data:"
+Opaque data is used in RPC and XDR to describe untyped data, that is,
+just sequences of arbitrary bytes. It may be declared either as a
+fixed or variable length array.
+.DS L
+Examples:
+.ft CW
+ opaque diskblock[512]; --> char diskblock[512];
+
+ opaque filedata<1024>; --> struct {
+ u_int filedata_len;
+ char *filedata_val;
+ } filedata;
+.DE
+.B Voids:
+In a void declaration, the variable is not named. The declaration is
+just \*Qvoid\*U and nothing else. Void declarations can only occur in two
+places: union definitions and program definitions (as the argument or
+result of a remote procedure).
diff --git a/lib/libc/rpc/PSD.doc/xdr.nts.ms b/lib/libc/rpc/PSD.doc/xdr.nts.ms
new file mode 100644
index 0000000..6c2d482
--- /dev/null
+++ b/lib/libc/rpc/PSD.doc/xdr.nts.ms
@@ -0,0 +1,1966 @@
+.\"
+.\" Must use -- eqn -- with this one
+.\"
+.\" @(#)xdr.nts.ms 2.2 88/08/05 4.0 RPCSRC
+.EQ
+delim $$
+.EN
+.de BT
+.if \\n%=1 .tl ''- % -''
+..
+.ND
+.\" prevent excess underlining in nroff
+.if n .fp 2 R
+.OH 'External Data Representation: Sun Technical Notes''Page %'
+.EH 'Page %''External Data Representation: Sun Technical Notes'
+.if \\n%=1 .bp
+.SH
+\&External Data Representation: Sun Technical Notes
+.IX XDR "Sun technical notes"
+.LP
+This chapter contains technical notes on Sun's implementation of the
+External Data Representation (XDR) standard, a set of library routines
+that allow a C programmer to describe arbitrary data structures in a
+machinex-independent fashion.
+For a formal specification of the XDR
+standard, see the
+.I "External Data Representation Standard: Protocol Specification".
+XDR is the backbone of Sun's Remote Procedure Call package, in the
+sense that data for remote procedure calls is transmitted using the
+standard. XDR library routines should be used to transmit data
+that is accessed (read or written) by more than one type of machine.\**
+.FS
+.IX XDR "system routines"
+For a compete specification of the system External Data Representation
+routines, see the
+.I xdr(3N)
+manual page.
+.FE
+.LP
+This chapter contains a short tutorial overview of the XDR library
+routines, a guide to accessing currently available XDR streams, and
+information on defining new streams and data types. XDR was designed
+to work across different languages, operating systems, and machine
+architectures. Most users (particularly RPC users) will only need
+the information in the
+.I "Number Filters",
+.I "Floating Point Filters",
+and
+.I "Enumeration Filters"
+sections.
+Programmers wishing to implement RPC and XDR on new machines
+will be interested in the rest of the chapter, as well as the
+.I "External Data Representaiton Standard: Protocol Specification",
+which will be their primary reference.
+.SH
+Note:
+.I
+.I rpcgen
+can be used to write XDR routines even in cases where no RPC calls are
+being made.
+.LP
+On Sun systems,
+C programs that want to use XDR routines
+must include the file
+.I <rpc/rpc.h> ,
+which contains all the necessary interfaces to the XDR system.
+Since the C library
+.I libc.a
+contains all the XDR routines,
+compile as normal.
+.DS
+example% \fBcc\0\fIprogram\fP.c\fI
+.DE
+.ne 3i
+.NH 0
+\&Justification
+.IX XDR justification
+.LP
+Consider the following two programs,
+.I writer :
+.ie t .DS
+.el .DS L
+.ft CW
+#include <stdio.h>
+.sp.5
+main() /* \fIwriter.c\fP */
+{
+ long i;
+.sp.5
+ for (i = 0; i < 8; i++) {
+ if (fwrite((char *)&i, sizeof(i), 1, stdout) != 1) {
+ fprintf(stderr, "failed!\en");
+ exit(1);
+ }
+ }
+ exit(0);
+}
+.DE
+and
+.I reader :
+.ie t .DS
+.el .DS L
+.ft CW
+#include <stdio.h>
+.sp.5
+main() /* \fIreader.c\fP */
+{
+ long i, j;
+.sp.5
+ for (j = 0; j < 8; j++) {
+ if (fread((char *)&i, sizeof (i), 1, stdin) != 1) {
+ fprintf(stderr, "failed!\en");
+ exit(1);
+ }
+ printf("%ld ", i);
+ }
+ printf("\en");
+ exit(0);
+}
+.DE
+The two programs appear to be portable, because (a) they pass
+.I lint
+checking, and (b) they exhibit the same behavior when executed
+on two different hardware architectures, a Sun and a VAX.
+.LP
+Piping the output of the
+.I writer
+program to the
+.I reader
+program gives identical results on a Sun or a VAX.
+.DS
+.ft CW
+sun% \fBwriter | reader\fP
+0 1 2 3 4 5 6 7
+sun%
+
+
+vax% \fBwriter | reader\fP
+0 1 2 3 4 5 6 7
+vax%
+.DE
+With the advent of local area networks and 4.2BSD came the concept
+of \*Qnetwork pipes\*U \(em a process produces data on one machine,
+and a second process consumes data on another machine.
+A network pipe can be constructed with
+.I writer
+and
+.I reader .
+Here are the results if the first produces data on a Sun,
+and the second consumes data on a VAX.
+.DS
+.ft CW
+sun% \fBwriter | rsh vax reader\fP
+0 16777216 33554432 50331648 67108864 83886080 100663296
+117440512
+sun%
+.DE
+Identical results can be obtained by executing
+.I writer
+on the VAX and
+.I reader
+on the Sun. These results occur because the byte ordering
+of long integers differs between the VAX and the Sun,
+even though word size is the same.
+Note that $16777216$ is $2 sup 24$ \(em
+when four bytes are reversed, the 1 winds up in the 24th bit.
+.LP
+Whenever data is shared by two or more machine types, there is
+a need for portable data. Programs can be made data-portable by
+replacing the
+.I read()
+and
+.I write()
+calls with calls to an XDR library routine
+.I xdr_long() ,
+a filter that knows the standard representation
+of a long integer in its external form.
+Here are the revised versions of
+.I writer :
+.ie t .DS
+.el .DS L
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h> /* \fIxdr is a sub-library of rpc\fP */
+.sp.5
+main() /* \fIwriter.c\fP */
+{
+ XDR xdrs;
+ long i;
+.sp.5
+ xdrstdio_create(&xdrs, stdout, XDR_ENCODE);
+ for (i = 0; i < 8; i++) {
+ if (!xdr_long(&xdrs, &i)) {
+ fprintf(stderr, "failed!\en");
+ exit(1);
+ }
+ }
+ exit(0);
+}
+.DE
+and
+.I reader :
+.ie t .DS
+.el .DS L
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h> /* \fIxdr is a sub-library of rpc\fP */
+.sp.5
+main() /* \fIreader.c\fP */
+{
+ XDR xdrs;
+ long i, j;
+.sp.5
+ xdrstdio_create(&xdrs, stdin, XDR_DECODE);
+ for (j = 0; j < 8; j++) {
+ if (!xdr_long(&xdrs, &i)) {
+ fprintf(stderr, "failed!\en");
+ exit(1);
+ }
+ printf("%ld ", i);
+ }
+ printf("\en");
+ exit(0);
+}
+.DE
+The new programs were executed on a Sun,
+on a VAX, and from a Sun to a VAX;
+the results are shown below.
+.DS
+.ft CW
+sun% \fBwriter | reader\fP
+0 1 2 3 4 5 6 7
+sun%
+
+vax% \fBwriter | reader\fP
+0 1 2 3 4 5 6 7
+vax%
+
+sun% \fBwriter | rsh vax reader\fP
+0 1 2 3 4 5 6 7
+sun%
+.DE
+.SH
+Note:
+.I
+.IX XDR "portable data"
+Integers are just the tip of the portable-data iceberg. Arbitrary
+data structures present portability problems, particularly with
+respect to alignment and pointers. Alignment on word boundaries
+may cause the size of a structure to vary from machine to machine.
+And pointers, which are very convenient to use, have no meaning
+outside the machine where they are defined.
+.LP
+.NH 1
+\&A Canonical Standard
+.IX XDR "canonical standard"
+.LP
+XDR's approach to standardizing data representations is
+.I canonical .
+That is, XDR defines a single byte order (Big Endian), a single
+floating-point representation (IEEE), and so on. Any program running on
+any machine can use XDR to create portable data by translating its
+local representation to the XDR standard representations; similarly, any
+program running on any machine can read portable data by translating the
+XDR standard representaions to its local equivalents. The single standard
+completely decouples programs that create or send portable data from those
+that use or receive portable data. The advent of a new machine or a new
+language has no effect upon the community of existing portable data creators
+and users. A new machine joins this community by being \*Qtaught\*U how to
+convert the standard representations and its local representations; the
+local representations of other machines are irrelevant. Conversely, to
+existing programs running on other machines, the local representations of
+the new machine are also irrelevant; such programs can immediately read
+portable data produced by the new machine because such data conforms to the
+canonical standards that they already understand.
+.LP
+There are strong precedents for XDR's canonical approach. For example,
+TCP/IP, UDP/IP, XNS, Ethernet, and, indeed, all protocols below layer five
+of the ISO model, are canonical protocols. The advantage of any canonical
+approach is simplicity; in the case of XDR, a single set of conversion
+routines is written once and is never touched again. The canonical approach
+has a disadvantage, but it is unimportant in real-world data transfer
+applications. Suppose two Little-Endian machines are transferring integers
+according to the XDR standard. The sending machine converts the integers
+from Little-Endian byte order to XDR (Big-Endian) byte order; the receiving
+machine performs the reverse conversion. Because both machines observe the
+same byte order, their conversions are unnecessary. The point, however, is
+not necessity, but cost as compared to the alternative.
+.LP
+The time spent converting to and from a canonical representation is
+insignificant, especially in networking applications. Most of the time
+required to prepare a data structure for transfer is not spent in conversion
+but in traversing the elements of the data structure. To transmit a tree,
+for example, each leaf must be visited and each element in a leaf record must
+be copied to a buffer and aligned there; storage for the leaf may have to be
+deallocated as well. Similarly, to receive a tree, storage must be
+allocated for each leaf, data must be moved from the buffer to the leaf and
+properly aligned, and pointers must be constructed to link the leaves
+together. Every machine pays the cost of traversing and copying data
+structures whether or not conversion is required. In networking
+applications, communications overhead\(emthe time required to move the data
+down through the sender's protocol layers, across the network and up through
+the receiver's protocol layers\(emdwarfs conversion overhead.
+.NH 1
+\&The XDR Library
+.IX "XDR" "library"
+.LP
+The XDR library not only solves data portability problems, it also
+allows you to write and read arbitrary C constructs in a consistent,
+specified, well-documented manner. Thus, it can make sense to use the
+library even when the data is not shared among machines on a network.
+.LP
+The XDR library has filter routines for
+strings (null-terminated arrays of bytes),
+structures, unions, and arrays, to name a few.
+Using more primitive routines,
+you can write your own specific XDR routines
+to describe arbitrary data structures,
+including elements of arrays, arms of unions,
+or objects pointed at from other structures.
+The structures themselves may contain arrays of arbitrary elements,
+or pointers to other structures.
+.LP
+Let's examine the two programs more closely.
+There is a family of XDR stream creation routines
+in which each member treats the stream of bits differently.
+In our example, data is manipulated using standard I/O routines,
+so we use
+.I xdrstdio_create ().
+.IX xdrstdio_create() "" "\fIxdrstdio_create()\fP"
+The parameters to XDR stream creation routines
+vary according to their function.
+In our example,
+.I xdrstdio_create()
+takes a pointer to an XDR structure that it initializes,
+a pointer to a
+.I FILE
+that the input or output is performed on, and the operation.
+The operation may be
+.I XDR_ENCODE
+for serializing in the
+.I writer
+program, or
+.I XDR_DECODE
+for deserializing in the
+.I reader
+program.
+.LP
+Note: RPC users never need to create XDR streams;
+the RPC system itself creates these streams,
+which are then passed to the users.
+.LP
+The
+.I xdr_long()
+.IX xdr_long() "" "\fIxdr_long()\fP"
+primitive is characteristic of most XDR library
+primitives and all client XDR routines.
+First, the routine returns
+.I FALSE
+(0) if it fails, and
+.I TRUE
+(1) if it succeeds.
+Second, for each data type,
+.I xxx ,
+there is an associated XDR routine of the form:
+.DS
+.ft CW
+xdr_xxx(xdrs, xp)
+ XDR *xdrs;
+ xxx *xp;
+{
+}
+.DE
+In our case,
+.I xxx
+is long, and the corresponding XDR routine is
+a primitive,
+.I xdr_long() .
+The client could also define an arbitrary structure
+.I xxx
+in which case the client would also supply the routine
+.I xdr_xxx (),
+describing each field by calling XDR routines
+of the appropriate type.
+In all cases the first parameter,
+.I xdrs
+can be treated as an opaque handle,
+and passed to the primitive routines.
+.LP
+XDR routines are direction independent;
+that is, the same routines are called to serialize or deserialize data.
+This feature is critical to software engineering of portable data.
+The idea is to call the same routine for either operation \(em
+this almost guarantees that serialized data can also be deserialized.
+One routine is used by both producer and consumer of networked data.
+This is implemented by always passing the address
+of an object rather than the object itself \(em
+only in the case of deserialization is the object modified.
+This feature is not shown in our trivial example,
+but its value becomes obvious when nontrivial data structures
+are passed among machines.
+If needed, the user can obtain the
+direction of the XDR operation.
+See the
+.I "XDR Operation Directions"
+section below for details.
+.LP
+Let's look at a slightly more complicated example.
+Assume that a person's gross assets and liabilities
+are to be exchanged among processes.
+Also assume that these values are important enough
+to warrant their own data type:
+.ie t .DS
+.el .DS L
+.ft CW
+struct gnumbers {
+ long g_assets;
+ long g_liabilities;
+};
+.DE
+The corresponding XDR routine describing this structure would be:
+.ie t .DS
+.el .DS L
+.ft CW
+bool_t /* \fITRUE is success, FALSE is failure\fP */
+xdr_gnumbers(xdrs, gp)
+ XDR *xdrs;
+ struct gnumbers *gp;
+{
+ if (xdr_long(xdrs, &gp->g_assets) &&
+ xdr_long(xdrs, &gp->g_liabilities))
+ return(TRUE);
+ return(FALSE);
+}
+.DE
+Note that the parameter
+.I xdrs
+is never inspected or modified;
+it is only passed on to the subcomponent routines.
+It is imperative to inspect the return value of each XDR routine call,
+and to give up immediately and return
+.I FALSE
+if the subroutine fails.
+.LP
+This example also shows that the type
+.I bool_t
+is declared as an integer whose only values are
+.I TRUE
+(1) and
+.I FALSE
+(0). This document uses the following definitions:
+.ie t .DS
+.el .DS L
+.ft CW
+#define bool_t int
+#define TRUE 1
+#define FALSE 0
+.DE
+.LP
+Keeping these conventions in mind,
+.I xdr_gnumbers()
+can be rewritten as follows:
+.ie t .DS
+.el .DS L
+.ft CW
+xdr_gnumbers(xdrs, gp)
+ XDR *xdrs;
+ struct gnumbers *gp;
+{
+ return(xdr_long(xdrs, &gp->g_assets) &&
+ xdr_long(xdrs, &gp->g_liabilities));
+}
+.DE
+This document uses both coding styles.
+.NH 1
+\&XDR Library Primitives
+.IX "library primitives for XDR"
+.IX XDR "library primitives"
+.LP
+This section gives a synopsis of each XDR primitive.
+It starts with basic data types and moves on to constructed data types.
+Finally, XDR utilities are discussed.
+The interface to these primitives
+and utilities is defined in the include file
+.I <rpc/xdr.h> ,
+automatically included by
+.I <rpc/rpc.h> .
+.NH 2
+\&Number Filters
+.IX "XDR library" "number filters"
+.LP
+The XDR library provides primitives to translate between numbers
+and their corresponding external representations.
+Primitives cover the set of numbers in:
+.DS
+.ft CW
+[signed, unsigned] * [short, int, long]
+.DE
+.ne 2i
+Specifically, the eight primitives are:
+.DS
+.ft CW
+bool_t xdr_char(xdrs, cp)
+ XDR *xdrs;
+ char *cp;
+.sp.5
+bool_t xdr_u_char(xdrs, ucp)
+ XDR *xdrs;
+ unsigned char *ucp;
+.sp.5
+bool_t xdr_int(xdrs, ip)
+ XDR *xdrs;
+ int *ip;
+.sp.5
+bool_t xdr_u_int(xdrs, up)
+ XDR *xdrs;
+ unsigned *up;
+.sp.5
+bool_t xdr_long(xdrs, lip)
+ XDR *xdrs;
+ long *lip;
+.sp.5
+bool_t xdr_u_long(xdrs, lup)
+ XDR *xdrs;
+ u_long *lup;
+.sp.5
+bool_t xdr_short(xdrs, sip)
+ XDR *xdrs;
+ short *sip;
+.sp.5
+bool_t xdr_u_short(xdrs, sup)
+ XDR *xdrs;
+ u_short *sup;
+.DE
+The first parameter,
+.I xdrs ,
+is an XDR stream handle.
+The second parameter is the address of the number
+that provides data to the stream or receives data from it.
+All routines return
+.I TRUE
+if they complete successfully, and
+.I FALSE
+otherwise.
+.NH 2
+\&Floating Point Filters
+.IX "XDR library" "floating point filters"
+.LP
+The XDR library also provides primitive routines
+for C's floating point types:
+.DS
+.ft CW
+bool_t xdr_float(xdrs, fp)
+ XDR *xdrs;
+ float *fp;
+.sp.5
+bool_t xdr_double(xdrs, dp)
+ XDR *xdrs;
+ double *dp;
+.DE
+The first parameter,
+.I xdrs
+is an XDR stream handle.
+The second parameter is the address
+of the floating point number that provides data to the stream
+or receives data from it.
+Both routines return
+.I TRUE
+if they complete successfully, and
+.I FALSE
+otherwise.
+.LP
+Note: Since the numbers are represented in IEEE floating point,
+routines may fail when decoding a valid IEEE representation
+into a machine-specific representation, or vice-versa.
+.NH 2
+\&Enumeration Filters
+.IX "XDR library" "enumeration filters"
+.LP
+The XDR library provides a primitive for generic enumerations.
+The primitive assumes that a C
+.I enum
+has the same representation inside the machine as a C integer.
+The boolean type is an important instance of the
+.I enum .
+The external representation of a boolean is always
+.I TRUE
+(1) or
+.I FALSE
+(0).
+.DS
+.ft CW
+#define bool_t int
+#define FALSE 0
+#define TRUE 1
+.sp.5
+#define enum_t int
+.sp.5
+bool_t xdr_enum(xdrs, ep)
+ XDR *xdrs;
+ enum_t *ep;
+.sp.5
+bool_t xdr_bool(xdrs, bp)
+ XDR *xdrs;
+ bool_t *bp;
+.DE
+The second parameters
+.I ep
+and
+.I bp
+are addresses of the associated type that provides data to, or
+receives data from, the stream
+.I xdrs .
+.NH 2
+\&No Data
+.IX "XDR library" "no data"
+.LP
+Occasionally, an XDR routine must be supplied to the RPC system,
+even when no data is passed or required.
+The library provides such a routine:
+.DS
+.ft CW
+bool_t xdr_void(); /* \fIalways returns TRUE\fP */
+.DE
+.NH 2
+\&Constructed Data Type Filters
+.IX "XDR library" "constructed data type filters"
+.LP
+Constructed or compound data type primitives
+require more parameters and perform more complicated functions
+then the primitives discussed above.
+This section includes primitives for
+strings, arrays, unions, and pointers to structures.
+.LP
+Constructed data type primitives may use memory management.
+In many cases, memory is allocated when deserializing data with
+.I XDR_DECODE
+Therefore, the XDR package must provide means to deallocate memory.
+This is done by an XDR operation,
+.I XDR_FREE
+To review, the three XDR directional operations are
+.I XDR_ENCODE ,
+.I XDR_DECODE
+and
+.I XDR_FREE .
+.NH 3
+\&Strings
+.IX "XDR library" "strings"
+.LP
+In C, a string is defined as a sequence of bytes
+terminated by a null byte,
+which is not considered when calculating string length.
+However, when a string is passed or manipulated,
+a pointer to it is employed.
+Therefore, the XDR library defines a string to be a
+.I "char *"
+and not a sequence of characters.
+The external representation of a string is drastically different
+from its internal representation.
+Externally, strings are represented as
+sequences of ASCII characters,
+while internally, they are represented with character pointers.
+Conversion between the two representations
+is accomplished with the routine
+.I xdr_string ():
+.IX xdr_string() "" \fIxdr_string()\fP
+.DS
+.ft CW
+bool_t xdr_string(xdrs, sp, maxlength)
+ XDR *xdrs;
+ char **sp;
+ u_int maxlength;
+.DE
+The first parameter
+.I xdrs
+is the XDR stream handle.
+The second parameter
+.I sp
+is a pointer to a string (type
+.I "char **" .
+The third parameter
+.I maxlength
+specifies the maximum number of bytes allowed during encoding or decoding.
+its value is usually specified by a protocol. For example, a protocol
+specification may say that a file name may be no longer than 255 characters.
+.LP
+The routine returns
+.I FALSE
+if the number of characters exceeds
+.I maxlength ,
+and
+.I TRUE
+if it doesn't.
+.SH
+Keep
+.I maxlength
+small. If it is too big you can blow the heap, since
+.I xdr_string()
+will call
+.I malloc()
+for space.
+.LP
+The behavior of
+.I xdr_string()
+.IX xdr_string() "" \fIxdr_string()\fP
+is similar to the behavior of other routines
+discussed in this section. The direction
+.I XDR_ENCODE
+is easiest to understand. The parameter
+.I sp
+points to a string of a certain length;
+if the string does not exceed
+.I maxlength ,
+the bytes are serialized.
+.LP
+The effect of deserializing a string is subtle.
+First the length of the incoming string is determined;
+it must not exceed
+.I maxlength .
+Next
+.I sp
+is dereferenced; if the the value is
+.I NULL ,
+then a string of the appropriate length is allocated and
+.I *sp
+is set to this string.
+If the original value of
+.I *sp
+is non-null, then the XDR package assumes
+that a target area has been allocated,
+which can hold strings no longer than
+.I maxlength .
+In either case, the string is decoded into the target area.
+The routine then appends a null character to the string.
+.LP
+In the
+.I XDR_FREE
+operation, the string is obtained by dereferencing
+.I sp .
+If the string is not
+.I NULL ,
+it is freed and
+.I *sp
+is set to
+.I NULL .
+In this operation,
+.I xdr_string()
+ignores the
+.I maxlength
+parameter.
+.NH 3
+\&Byte Arrays
+.IX "XDR library" "byte arrays"
+.LP
+Often variable-length arrays of bytes are preferable to strings.
+Byte arrays differ from strings in the following three ways:
+1) the length of the array (the byte count) is explicitly
+located in an unsigned integer,
+2) the byte sequence is not terminated by a null character, and
+3) the external representation of the bytes is the same as their
+internal representation.
+The primitive
+.I xdr_bytes()
+.IX xdr_bytes() "" \fIxdr_bytes()\fP
+converts between the internal and external
+representations of byte arrays:
+.DS
+.ft CW
+bool_t xdr_bytes(xdrs, bpp, lp, maxlength)
+ XDR *xdrs;
+ char **bpp;
+ u_int *lp;
+ u_int maxlength;
+.DE
+The usage of the first, second and fourth parameters
+are identical to the first, second and third parameters of
+.I xdr_string (),
+respectively.
+The length of the byte area is obtained by dereferencing
+.I lp
+when serializing;
+.I *lp
+is set to the byte length when deserializing.
+.NH 3
+\&Arrays
+.IX "XDR library" "arrays"
+.LP
+The XDR library package provides a primitive
+for handling arrays of arbitrary elements.
+The
+.I xdr_bytes()
+routine treats a subset of generic arrays,
+in which the size of array elements is known to be 1,
+and the external description of each element is built-in.
+The generic array primitive,
+.I xdr_array() ,
+.IX xdr_array() "" \fIxdr_array()\fP
+requires parameters identical to those of
+.I xdr_bytes()
+plus two more:
+the size of array elements,
+and an XDR routine to handle each of the elements.
+This routine is called to encode or decode
+each element of the array.
+.DS
+.ft CW
+bool_t
+xdr_array(xdrs, ap, lp, maxlength, elementsiz, xdr_element)
+ XDR *xdrs;
+ char **ap;
+ u_int *lp;
+ u_int maxlength;
+ u_int elementsiz;
+ bool_t (*xdr_element)();
+.DE
+The parameter
+.I ap
+is the address of the pointer to the array.
+If
+.I *ap
+is
+.I NULL
+when the array is being deserialized,
+XDR allocates an array of the appropriate size and sets
+.I *ap
+to that array.
+The element count of the array is obtained from
+.I *lp
+when the array is serialized;
+.I *lp
+is set to the array length when the array is deserialized.
+The parameter
+.I maxlength
+is the maximum number of elements that the array is allowed to have;
+.I elementsiz
+is the byte size of each element of the array
+(the C function
+.I sizeof()
+can be used to obtain this value).
+The
+.I xdr_element()
+.IX xdr_element() "" \fIxdr_element()\fP
+routine is called to serialize, deserialize, or free
+each element of the array.
+.br
+.LP
+Before defining more constructed data types, it is appropriate to
+present three examples.
+.LP
+.I "Example A:"
+.br
+A user on a networked machine can be identified by
+(a) the machine name, such as
+.I krypton :
+see the
+.I gethostname
+man page; (b) the user's UID: see the
+.I geteuid
+man page; and (c) the group numbers to which the user belongs:
+see the
+.I getgroups
+man page. A structure with this information and its associated
+XDR routine could be coded like this:
+.ie t .DS
+.el .DS L
+.ft CW
+struct netuser {
+ char *nu_machinename;
+ int nu_uid;
+ u_int nu_glen;
+ int *nu_gids;
+};
+#define NLEN 255 /* \fImachine names < 256 chars\fP */
+#define NGRPS 20 /* \fIuser can't be in > 20 groups\fP */
+.sp.5
+bool_t
+xdr_netuser(xdrs, nup)
+ XDR *xdrs;
+ struct netuser *nup;
+{
+ return(xdr_string(xdrs, &nup->nu_machinename, NLEN) &&
+ xdr_int(xdrs, &nup->nu_uid) &&
+ xdr_array(xdrs, &nup->nu_gids, &nup->nu_glen,
+ NGRPS, sizeof (int), xdr_int));
+}
+.DE
+.LP
+.I "Example B:"
+.br
+A party of network users could be implemented
+as an array of
+.I netuser
+structure.
+The declaration and its associated XDR routines
+are as follows:
+.ie t .DS
+.el .DS L
+.ft CW
+struct party {
+ u_int p_len;
+ struct netuser *p_nusers;
+};
+#define PLEN 500 /* \fImax number of users in a party\fP */
+.sp.5
+bool_t
+xdr_party(xdrs, pp)
+ XDR *xdrs;
+ struct party *pp;
+{
+ return(xdr_array(xdrs, &pp->p_nusers, &pp->p_len, PLEN,
+ sizeof (struct netuser), xdr_netuser));
+}
+.DE
+.LP
+.I "Example C:"
+.br
+The well-known parameters to
+.I main ,
+.I argc
+and
+.I argv
+can be combined into a structure.
+An array of these structures can make up a history of commands.
+The declarations and XDR routines might look like:
+.ie t .DS
+.el .DS L
+.ft CW
+struct cmd {
+ u_int c_argc;
+ char **c_argv;
+};
+#define ALEN 1000 /* \fIargs cannot be > 1000 chars\fP */
+#define NARGC 100 /* \fIcommands cannot have > 100 args\fP */
+
+struct history {
+ u_int h_len;
+ struct cmd *h_cmds;
+};
+#define NCMDS 75 /* \fIhistory is no more than 75 commands\fP */
+
+bool_t
+xdr_wrap_string(xdrs, sp)
+ XDR *xdrs;
+ char **sp;
+{
+ return(xdr_string(xdrs, sp, ALEN));
+}
+.DE
+.ie t .DS
+.el .DS L
+.ft CW
+bool_t
+xdr_cmd(xdrs, cp)
+ XDR *xdrs;
+ struct cmd *cp;
+{
+ return(xdr_array(xdrs, &cp->c_argv, &cp->c_argc, NARGC,
+ sizeof (char *), xdr_wrap_string));
+}
+.DE
+.ie t .DS
+.el .DS L
+.ft CW
+bool_t
+xdr_history(xdrs, hp)
+ XDR *xdrs;
+ struct history *hp;
+{
+ return(xdr_array(xdrs, &hp->h_cmds, &hp->h_len, NCMDS,
+ sizeof (struct cmd), xdr_cmd));
+}
+.DE
+The most confusing part of this example is that the routine
+.I xdr_wrap_string()
+is needed to package the
+.I xdr_string()
+routine, because the implementation of
+.I xdr_array()
+only passes two parameters to the array element description routine;
+.I xdr_wrap_string()
+supplies the third parameter to
+.I xdr_string ().
+.LP
+By now the recursive nature of the XDR library should be obvious.
+Let's continue with more constructed data types.
+.NH 3
+\&Opaque Data
+.IX "XDR library" "opaque data"
+.LP
+In some protocols, handles are passed from a server to client.
+The client passes the handle back to the server at some later time.
+Handles are never inspected by clients;
+they are obtained and submitted.
+That is to say, handles are opaque.
+The
+.I xdr_opaque()
+.IX xdr_opaque() "" \fIxdr_opaque()\fP
+primitive is used for describing fixed sized, opaque bytes.
+.DS
+.ft CW
+bool_t xdr_opaque(xdrs, p, len)
+ XDR *xdrs;
+ char *p;
+ u_int len;
+.DE
+The parameter
+.I p
+is the location of the bytes;
+.I len
+is the number of bytes in the opaque object.
+By definition, the actual data
+contained in the opaque object are not machine portable.
+.NH 3
+\&Fixed Sized Arrays
+.IX "XDR library" "fixed sized arrays"
+.LP
+The XDR library provides a primitive,
+.I xdr_vector (),
+for fixed-length arrays.
+.ie t .DS
+.el .DS L
+.ft CW
+#define NLEN 255 /* \fImachine names must be < 256 chars\fP */
+#define NGRPS 20 /* \fIuser belongs to exactly 20 groups\fP */
+.sp.5
+struct netuser {
+ char *nu_machinename;
+ int nu_uid;
+ int nu_gids[NGRPS];
+};
+.sp.5
+bool_t
+xdr_netuser(xdrs, nup)
+ XDR *xdrs;
+ struct netuser *nup;
+{
+ int i;
+.sp.5
+ if (!xdr_string(xdrs, &nup->nu_machinename, NLEN))
+ return(FALSE);
+ if (!xdr_int(xdrs, &nup->nu_uid))
+ return(FALSE);
+ if (!xdr_vector(xdrs, nup->nu_gids, NGRPS, sizeof(int),
+ xdr_int)) {
+ return(FALSE);
+ }
+ return(TRUE);
+}
+.DE
+.NH 3
+\&Discriminated Unions
+.IX "XDR library" "discriminated unions"
+.LP
+The XDR library supports discriminated unions.
+A discriminated union is a C union and an
+.I enum_t
+value that selects an \*Qarm\*U of the union.
+.DS
+.ft CW
+struct xdr_discrim {
+ enum_t value;
+ bool_t (*proc)();
+};
+.sp.5
+bool_t xdr_union(xdrs, dscmp, unp, arms, defaultarm)
+ XDR *xdrs;
+ enum_t *dscmp;
+ char *unp;
+ struct xdr_discrim *arms;
+ bool_t (*defaultarm)(); /* \fImay equal NULL\fP */
+.DE
+First the routine translates the discriminant of the union located at
+.I *dscmp .
+The discriminant is always an
+.I enum_t .
+Next the union located at
+.I *unp
+is translated.
+The parameter
+.I arms
+is a pointer to an array of
+.I xdr_discrim
+structures.
+Each structure contains an ordered pair of
+.I [value,proc] .
+If the union's discriminant is equal to the associated
+.I value ,
+then the
+.I proc
+is called to translate the union.
+The end of the
+.I xdr_discrim
+structure array is denoted by a routine of value
+.I NULL
+(0). If the discriminant is not found in the
+.I arms
+array, then the
+.I defaultarm
+procedure is called if it is non-null;
+otherwise the routine returns
+.I FALSE .
+.LP
+.I "Example D:"
+Suppose the type of a union may be integer,
+character pointer (a string), or a
+.I gnumbers
+structure.
+Also, assume the union and its current type
+are declared in a structure.
+The declaration is:
+.ie t .DS
+.el .DS L
+.ft CW
+enum utype { INTEGER=1, STRING=2, GNUMBERS=3 };
+.sp.5
+struct u_tag {
+ enum utype utype; /* \fIthe union's discriminant\fP */
+ union {
+ int ival;
+ char *pval;
+ struct gnumbers gn;
+ } uval;
+};
+.DE
+The following constructs and XDR procedure (de)serialize
+the discriminated union:
+.ie t .DS
+.el .DS L
+.ft CW
+struct xdr_discrim u_tag_arms[4] = {
+ { INTEGER, xdr_int },
+ { GNUMBERS, xdr_gnumbers }
+ { STRING, xdr_wrap_string },
+ { __dontcare__, NULL }
+ /* \fIalways terminate arms with a NULL xdr_proc\fP */
+}
+.sp.5
+bool_t
+xdr_u_tag(xdrs, utp)
+ XDR *xdrs;
+ struct u_tag *utp;
+{
+ return(xdr_union(xdrs, &utp->utype, &utp->uval,
+ u_tag_arms, NULL));
+}
+.DE
+The routine
+.I xdr_gnumbers()
+was presented above in
+.I "The XDR Library"
+section.
+.I xdr_wrap_string()
+was presented in example C.
+The default
+.I arm
+parameter to
+.I xdr_union()
+(the last parameter) is
+.I NULL
+in this example. Therefore the value of the union's discriminant
+may legally take on only values listed in the
+.I u_tag_arms
+array. This example also demonstrates that
+the elements of the arm's array do not need to be sorted.
+.LP
+It is worth pointing out that the values of the discriminant
+may be sparse, though in this example they are not.
+It is always good
+practice to assign explicitly integer values to each element of the
+discriminant's type.
+This practice both documents the external
+representation of the discriminant and guarantees that different
+C compilers emit identical discriminant values.
+.LP
+Exercise: Implement
+.I xdr_union()
+using the other primitives in this section.
+.NH 3
+\&Pointers
+.IX "XDR library" "pointers"
+.LP
+In C it is often convenient to put pointers
+to another structure within a structure.
+The
+.I xdr_reference()
+.IX xdr_reference() "" \fIxdr_reference()\fP
+primitive makes it easy to serialize, deserialize, and free
+these referenced structures.
+.DS
+.ft CW
+bool_t xdr_reference(xdrs, pp, size, proc)
+ XDR *xdrs;
+ char **pp;
+ u_int ssize;
+ bool_t (*proc)();
+.DE
+.LP
+Parameter
+.I pp
+is the address of
+the pointer to the structure;
+parameter
+.I ssize
+is the size in bytes of the structure (use the C function
+.I sizeof()
+to obtain this value); and
+.I proc
+is the XDR routine that describes the structure.
+When decoding data, storage is allocated if
+.I *pp
+is
+.I NULL .
+.LP
+There is no need for a primitive
+.I xdr_struct()
+to describe structures within structures,
+because pointers are always sufficient.
+.LP
+Exercise: Implement
+.I xdr_reference()
+using
+.I xdr_array ().
+Warning:
+.I xdr_reference()
+and
+.I xdr_array()
+are NOT interchangeable external representations of data.
+.LP
+.I "Example E:"
+Suppose there is a structure containing a person's name
+and a pointer to a
+.I gnumbers
+structure containing the person's gross assets and liabilities.
+The construct is:
+.DS
+.ft CW
+struct pgn {
+ char *name;
+ struct gnumbers *gnp;
+};
+.DE
+The corresponding XDR routine for this structure is:
+.DS
+.ft CW
+bool_t
+xdr_pgn(xdrs, pp)
+ XDR *xdrs;
+ struct pgn *pp;
+{
+ if (xdr_string(xdrs, &pp->name, NLEN) &&
+ xdr_reference(xdrs, &pp->gnp,
+ sizeof(struct gnumbers), xdr_gnumbers))
+ return(TRUE);
+ return(FALSE);
+}
+.DE
+.IX "pointer semantics and XDR"
+.I "Pointer Semantics and XDR"
+.LP
+In many applications, C programmers attach double meaning to
+the values of a pointer. Typically the value
+.I NULL
+(or zero) means data is not needed,
+yet some application-specific interpretation applies.
+In essence, the C programmer is encoding
+a discriminated union efficiently
+by overloading the interpretation of the value of a pointer.
+For instance, in example E a
+.I NULL
+pointer value for
+.I gnp
+could indicate that
+the person's assets and liabilities are unknown.
+That is, the pointer value encodes two things:
+whether or not the data is known;
+and if it is known, where it is located in memory.
+Linked lists are an extreme example of the use
+of application-specific pointer interpretation.
+.LP
+The primitive
+.I xdr_reference()
+.IX xdr_reference() "" \fIxdr_reference()\fP
+cannot and does not attach any special
+meaning to a null-value pointer during serialization.
+That is, passing an address of a pointer whose value is
+.I NULL
+to
+.I xdr_reference()
+when serialing data will most likely cause a memory fault and, on the UNIX
+system, a core dump.
+.LP
+.I xdr_pointer()
+correctly handles
+.I NULL
+pointers. For more information about its use, see
+the
+.I "Linked Lists"
+topics below.
+.LP
+.I Exercise:
+After reading the section on
+.I "Linked Lists" ,
+return here and extend example E so that
+it can correctly deal with
+.I NULL
+pointer values.
+.LP
+.I Exercise:
+Using the
+.I xdr_union (),
+.I xdr_reference()
+and
+.I xdr_void()
+primitives, implement a generic pointer handling primitive
+that implicitly deals with
+.I NULL
+pointers. That is, implement
+.I xdr_pointer ().
+.NH 2
+\&Non-filter Primitives
+.IX "XDR" "non-filter primitives"
+.LP
+XDR streams can be manipulated with
+the primitives discussed in this section.
+.DS
+.ft CW
+u_int xdr_getpos(xdrs)
+ XDR *xdrs;
+.sp.5
+bool_t xdr_setpos(xdrs, pos)
+ XDR *xdrs;
+ u_int pos;
+.sp.5
+xdr_destroy(xdrs)
+ XDR *xdrs;
+.DE
+The routine
+.I xdr_getpos()
+.IX xdr_getpos() "" \fIxdr_getpos()\fP
+returns an unsigned integer
+that describes the current position in the data stream.
+Warning: In some XDR streams, the returned value of
+.I xdr_getpos()
+is meaningless;
+the routine returns a \-1 in this case
+(though \-1 should be a legitimate value).
+.LP
+The routine
+.I xdr_setpos()
+.IX xdr_setpos() "" \fIxdr_setpos()\fP
+sets a stream position to
+.I pos .
+Warning: In some XDR streams, setting a position is impossible;
+in such cases,
+.I xdr_setpos()
+will return
+.I FALSE .
+This routine will also fail if the requested position is out-of-bounds.
+The definition of bounds varies from stream to stream.
+.LP
+The
+.I xdr_destroy()
+.IX xdr_destroy() "" \fIxdr_destroy()\fP
+primitive destroys the XDR stream.
+Usage of the stream
+after calling this routine is undefined.
+.NH 2
+\&XDR Operation Directions
+.IX XDR "operation directions"
+.IX "direction of XDR operations"
+.LP
+At times you may wish to optimize XDR routines by taking
+advantage of the direction of the operation \(em
+.I XDR_ENCODE
+.I XDR_DECODE
+or
+.I XDR_FREE
+The value
+.I xdrs->x_op
+always contains the direction of the XDR operation.
+Programmers are not encouraged to take advantage of this information.
+Therefore, no example is presented here. However, an example in the
+.I "Linked Lists"
+topic below, demonstrates the usefulness of the
+.I xdrs->x_op
+field.
+.NH 2
+\&XDR Stream Access
+.IX "XDR" "stream access"
+.LP
+An XDR stream is obtained by calling the appropriate creation routine.
+These creation routines take arguments that are tailored to the
+specific properties of the stream.
+.LP
+Streams currently exist for (de)serialization of data to or from
+standard I/O
+.I FILE
+streams, TCP/IP connections and UNIX files, and memory.
+.NH 3
+\&Standard I/O Streams
+.IX "XDR" "standard I/O streams"
+.LP
+XDR streams can be interfaced to standard I/O using the
+.I xdrstdio_create()
+.IX xdrstdio_create() "" \fIxdrstdio_create()\fP
+routine as follows:
+.DS
+.ft CW
+#include <stdio.h>
+#include <rpc/rpc.h> /* \fIxdr streams part of rpc\fP */
+.sp.5
+void
+xdrstdio_create(xdrs, fp, x_op)
+ XDR *xdrs;
+ FILE *fp;
+ enum xdr_op x_op;
+.DE
+The routine
+.I xdrstdio_create()
+initializes an XDR stream pointed to by
+.I xdrs .
+The XDR stream interfaces to the standard I/O library.
+Parameter
+.I fp
+is an open file, and
+.I x_op
+is an XDR direction.
+.NH 3
+\&Memory Streams
+.IX "XDR" "memory streams"
+.LP
+Memory streams allow the streaming of data into or out of
+a specified area of memory:
+.DS
+.ft CW
+#include <rpc/rpc.h>
+.sp.5
+void
+xdrmem_create(xdrs, addr, len, x_op)
+ XDR *xdrs;
+ char *addr;
+ u_int len;
+ enum xdr_op x_op;
+.DE
+The routine
+.I xdrmem_create()
+.IX xdrmem_create() "" \fIxdrmem_create()\fP
+initializes an XDR stream in local memory.
+The memory is pointed to by parameter
+.I addr ;
+parameter
+.I len
+is the length in bytes of the memory.
+The parameters
+.I xdrs
+and
+.I x_op
+are identical to the corresponding parameters of
+.I xdrstdio_create ().
+Currently, the UDP/IP implementation of RPC uses
+.I xdrmem_create ().
+Complete call or result messages are built in memory before calling the
+.I sendto()
+system routine.
+.NH 3
+\&Record (TCP/IP) Streams
+.IX "XDR" "record (TCP/IP) streams"
+.LP
+A record stream is an XDR stream built on top of
+a record marking standard that is built on top of the
+UNIX file or 4.2 BSD connection interface.
+.DS
+.ft CW
+#include <rpc/rpc.h> /* \fIxdr streams part of rpc\fP */
+.sp.5
+xdrrec_create(xdrs,
+ sendsize, recvsize, iohandle, readproc, writeproc)
+ XDR *xdrs;
+ u_int sendsize, recvsize;
+ char *iohandle;
+ int (*readproc)(), (*writeproc)();
+.DE
+The routine
+.I xdrrec_create()
+provides an XDR stream interface that allows for a bidirectional,
+arbitrarily long sequence of records.
+The contents of the records are meant to be data in XDR form.
+The stream's primary use is for interfacing RPC to TCP connections.
+However, it can be used to stream data into or out of normal
+UNIX files.
+.LP
+The parameter
+.I xdrs
+is similar to the corresponding parameter described above.
+The stream does its own data buffering similar to that of standard I/O.
+The parameters
+.I sendsize
+and
+.I recvsize
+determine the size in bytes of the output and input buffers, respectively;
+if their values are zero (0), then predetermined defaults are used.
+When a buffer needs to be filled or flushed, the routine
+.I readproc()
+or
+.I writeproc()
+is called, respectively.
+The usage and behavior of these
+routines are similar to the UNIX system calls
+.I read()
+and
+.I write ().
+However,
+the first parameter to each of these routines is the opaque parameter
+.I iohandle .
+The other two parameters
+.I buf ""
+and
+.I nbytes )
+and the results
+(byte count) are identical to the system routines.
+If
+.I xxx
+is
+.I readproc()
+or
+.I writeproc (),
+then it has the following form:
+.DS
+.ft CW
+.ft I
+/*
+ * returns the actual number of bytes transferred.
+ * -1 is an error
+ */
+.ft CW
+int
+xxx(iohandle, buf, len)
+ char *iohandle;
+ char *buf;
+ int nbytes;
+.DE
+The XDR stream provides means for delimiting records in the byte stream.
+The implementation details of delimiting records in a stream are
+discussed in the
+.I "Advanced Topics"
+topic below.
+The primitives that are specific to record streams are as follows:
+.DS
+.ft CW
+bool_t
+xdrrec_endofrecord(xdrs, flushnow)
+ XDR *xdrs;
+ bool_t flushnow;
+.sp.5
+bool_t
+xdrrec_skiprecord(xdrs)
+ XDR *xdrs;
+.sp.5
+bool_t
+xdrrec_eof(xdrs)
+ XDR *xdrs;
+.DE
+The routine
+.I xdrrec_endofrecord()
+.IX xdrrec_endofrecord() "" \fIxdrrec_endofrecord()\fP
+causes the current outgoing data to be marked as a record.
+If the parameter
+.I flushnow
+is
+.I TRUE ,
+then the stream's
+.I writeproc
+will be called; otherwise,
+.I writeproc
+will be called when the output buffer has been filled.
+.LP
+The routine
+.I xdrrec_skiprecord()
+.IX xdrrec_skiprecord() "" \fIxdrrec_skiprecord()\fP
+causes an input stream's position to be moved past
+the current record boundary and onto the
+beginning of the next record in the stream.
+.LP
+If there is no more data in the stream's input buffer,
+then the routine
+.I xdrrec_eof()
+.IX xdrrec_eof() "" \fIxdrrec_eof()\fP
+returns
+.I TRUE .
+That is not to say that there is no more data
+in the underlying file descriptor.
+.NH 2
+\&XDR Stream Implementation
+.IX "XDR" "stream implementation"
+.IX "stream implementation in XDR"
+.LP
+This section provides the abstract data types needed
+to implement new instances of XDR streams.
+.NH 3
+\&The XDR Object
+.IX "XDR" "object"
+.LP
+The following structure defines the interface to an XDR stream:
+.ie t .DS
+.el .DS L
+.ft CW
+enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 };
+.sp.5
+typedef struct {
+ enum xdr_op x_op; /* \fIoperation; fast added param\fP */
+ struct xdr_ops {
+ bool_t (*x_getlong)(); /* \fIget long from stream\fP */
+ bool_t (*x_putlong)(); /* \fIput long to stream\fP */
+ bool_t (*x_getbytes)(); /* \fIget bytes from stream\fP */
+ bool_t (*x_putbytes)(); /* \fIput bytes to stream\fP */
+ u_int (*x_getpostn)(); /* \fIreturn stream offset\fP */
+ bool_t (*x_setpostn)(); /* \fIreposition offset\fP */
+ caddr_t (*x_inline)(); /* \fIptr to buffered data\fP */
+ VOID (*x_destroy)(); /* \fIfree private area\fP */
+ } *x_ops;
+ caddr_t x_public; /* \fIusers' data\fP */
+ caddr_t x_private; /* \fIpointer to private data\fP */
+ caddr_t x_base; /* \fIprivate for position info\fP */
+ int x_handy; /* \fIextra private word\fP */
+} XDR;
+.DE
+The
+.I x_op
+field is the current operation being performed on the stream.
+This field is important to the XDR primitives,
+but should not affect a stream's implementation.
+That is, a stream's implementation should not depend
+on this value.
+The fields
+.I x_private ,
+.I x_base ,
+and
+.I x_handy
+are private to the particular
+stream's implementation.
+The field
+.I x_public
+is for the XDR client and should never be used by
+the XDR stream implementations or the XDR primitives.
+.I x_getpostn() ,
+.I x_setpostn()
+and
+.I x_destroy()
+are macros for accessing operations. The operation
+.I x_inline()
+takes two parameters:
+an XDR *, and an unsigned integer, which is a byte count.
+The routine returns a pointer to a piece of
+the stream's internal buffer.
+The caller can then use the buffer segment for any purpose.
+From the stream's point of view, the bytes in the
+buffer segment have been consumed or put.
+The routine may return
+.I NULL
+if it cannot return a buffer segment of the requested size.
+(The
+.I x_inline()
+routine is for cycle squeezers.
+Use of the resulting buffer is not data-portable.
+Users are encouraged not to use this feature.)
+.LP
+The operations
+.I x_getbytes()
+and
+.I x_putbytes()
+blindly get and put sequences of bytes
+from or to the underlying stream;
+they return
+.I TRUE
+if they are successful, and
+.I FALSE
+otherwise. The routines have identical parameters (replace
+.I xxx ):
+.DS
+.ft CW
+bool_t
+xxxbytes(xdrs, buf, bytecount)
+ XDR *xdrs;
+ char *buf;
+ u_int bytecount;
+.DE
+The operations
+.I x_getlong()
+and
+.I x_putlong()
+receive and put
+long numbers from and to the data stream.
+It is the responsibility of these routines
+to translate the numbers between the machine representation
+and the (standard) external representation.
+The UNIX primitives
+.I htonl()
+and
+.I ntohl()
+can be helpful in accomplishing this.
+The higher-level XDR implementation assumes that
+signed and unsigned long integers contain the same number of bits,
+and that nonnegative integers
+have the same bit representations as unsigned integers.
+The routines return
+.I TRUE
+if they succeed, and
+.I FALSE
+otherwise. They have identical parameters:
+.DS
+.ft CW
+bool_t
+xxxlong(xdrs, lp)
+ XDR *xdrs;
+ long *lp;
+.DE
+Implementors of new XDR streams must make an XDR structure
+(with new operation routines) available to clients,
+using some kind of create routine.
+.NH 1
+\&Advanced Topics
+.IX XDR "advanced topics"
+.LP
+This section describes techniques for passing data structures that
+are not covered in the preceding sections. Such structures include
+linked lists (of arbitrary lengths). Unlike the simpler examples
+covered in the earlier sections, the following examples are written
+using both the XDR C library routines and the XDR data description
+language.
+The
+.I "External Data Representation Standard: Protocol Specification"
+describes this
+language in complete detail.
+.NH 2
+\&Linked Lists
+.IX XDR "linked lists"
+.LP
+The last example in the
+.I Pointers
+topic earlier in this chapter
+presented a C data structure and its associated XDR
+routines for a individual's gross assets and liabilities.
+The example is duplicated below:
+.ie t .DS
+.el .DS L
+.ft CW
+struct gnumbers {
+ long g_assets;
+ long g_liabilities;
+};
+.sp.5
+bool_t
+xdr_gnumbers(xdrs, gp)
+ XDR *xdrs;
+ struct gnumbers *gp;
+{
+ if (xdr_long(xdrs, &(gp->g_assets)))
+ return(xdr_long(xdrs, &(gp->g_liabilities)));
+ return(FALSE);
+}
+.DE
+.LP
+Now assume that we wish to implement a linked list of such information.
+A data structure could be constructed as follows:
+.ie t .DS
+.el .DS L
+.ft CW
+struct gnumbers_node {
+ struct gnumbers gn_numbers;
+ struct gnumbers_node *gn_next;
+};
+.sp .5
+typedef struct gnumbers_node *gnumbers_list;
+.DE
+.LP
+The head of the linked list can be thought of as the data object;
+that is, the head is not merely a convenient shorthand for a
+structure. Similarly the
+.I gn_next
+field is used to indicate whether or not the object has terminated.
+Unfortunately, if the object continues, the
+.I gn_next
+field is also the address of where it continues. The link addresses
+carry no useful information when the object is serialized.
+.LP
+The XDR data description of this linked list is described by the
+recursive declaration of
+.I gnumbers_list :
+.ie t .DS
+.el .DS L
+.ft CW
+struct gnumbers {
+ int g_assets;
+ int g_liabilities;
+};
+.sp .5
+struct gnumbers_node {
+ gnumbers gn_numbers;
+ gnumbers_node *gn_next;
+};
+.DE
+.LP
+In this description, the boolean indicates whether there is more data
+following it. If the boolean is
+.I FALSE ,
+then it is the last data field of the structure. If it is
+.I TRUE ,
+then it is followed by a gnumbers structure and (recursively) by a
+.I gnumbers_list .
+Note that the C declaration has no boolean explicitly declared in it
+(though the
+.I gn_next
+field implicitly carries the information), while the XDR data
+description has no pointer explicitly declared in it.
+.LP
+Hints for writing the XDR routines for a
+.I gnumbers_list
+follow easily from the XDR description above. Note how the primitive
+.I xdr_pointer()
+is used to implement the XDR union above.
+.ie t .DS
+.el .DS L
+.ft CW
+bool_t
+xdr_gnumbers_node(xdrs, gn)
+ XDR *xdrs;
+ gnumbers_node *gn;
+{
+ return(xdr_gnumbers(xdrs, &gn->gn_numbers) &&
+ xdr_gnumbers_list(xdrs, &gp->gn_next));
+}
+.sp .5
+bool_t
+xdr_gnumbers_list(xdrs, gnp)
+ XDR *xdrs;
+ gnumbers_list *gnp;
+{
+ return(xdr_pointer(xdrs, gnp,
+ sizeof(struct gnumbers_node),
+ xdr_gnumbers_node));
+}
+.DE
+.LP
+The unfortunate side effect of XDR'ing a list with these routines
+is that the C stack grows linearly with respect to the number of
+node in the list. This is due to the recursion. The following
+routine collapses the above two mutually recursive into a single,
+non-recursive one.
+.ie t .DS
+.el .DS L
+.ft CW
+bool_t
+xdr_gnumbers_list(xdrs, gnp)
+ XDR *xdrs;
+ gnumbers_list *gnp;
+{
+ bool_t more_data;
+ gnumbers_list *nextp;
+.sp .5
+ for (;;) {
+ more_data = (*gnp != NULL);
+ if (!xdr_bool(xdrs, &more_data)) {
+ return(FALSE);
+ }
+ if (! more_data) {
+ break;
+ }
+ if (xdrs->x_op == XDR_FREE) {
+ nextp = &(*gnp)->gn_next;
+ }
+ if (!xdr_reference(xdrs, gnp,
+ sizeof(struct gnumbers_node), xdr_gnumbers)) {
+
+ return(FALSE);
+ }
+ gnp = (xdrs->x_op == XDR_FREE) ?
+ nextp : &(*gnp)->gn_next;
+ }
+ *gnp = NULL;
+ return(TRUE);
+}
+.DE
+.LP
+The first task is to find out whether there is more data or not,
+so that this boolean information can be serialized. Notice that
+this statement is unnecessary in the
+.I XDR_DECODE
+case, since the value of more_data is not known until we
+deserialize it in the next statement.
+.LP
+The next statement XDR's the more_data field of the XDR union.
+Then if there is truly no more data, we set this last pointer to
+.I NULL
+to indicate the end of the list, and return
+.I TRUE
+because we are done. Note that setting the pointer to
+.I NULL
+is only important in the
+.I XDR_DECODE
+case, since it is already
+.I NULL
+in the
+.I XDR_ENCODE
+and
+XDR_FREE
+cases.
+.LP
+Next, if the direction is
+.I XDR_FREE ,
+the value of
+.I nextp
+is set to indicate the location of the next pointer in the list.
+We do this now because we need to dereference gnp to find the
+location of the next item in the list, and after the next
+statement the storage pointed to by
+.I gnp
+will be freed up and no be longer valid. We can't do this for all
+directions though, because in the
+.I XDR_DECODE
+direction the value of
+.I gnp
+won't be set until the next statement.
+.LP
+Next, we XDR the data in the node using the primitive
+.I xdr_reference ().
+.I xdr_reference()
+is like
+.I xdr_pointer()
+which we used before, but it does not
+send over the boolean indicating whether there is more data.
+We use it instead of
+.I xdr_pointer()
+because we have already XDR'd this information ourselves. Notice
+that the xdr routine passed is not the same type as an element
+in the list. The routine passed is
+.I xdr_gnumbers (),
+for XDR'ing gnumbers, but each element in the list is actually of
+type
+.I gnumbers_node .
+We don't pass
+.I xdr_gnumbers_node()
+because it is recursive, and instead use
+.I xdr_gnumbers()
+which XDR's all of the non-recursive part. Note that this trick
+will work only if the
+.I gn_numbers
+field is the first item in each element, so that their addresses
+are identical when passed to
+.I xdr_reference ().
+.LP
+Finally, we update
+.I gnp
+to point to the next item in the list. If the direction is
+.I XDR_FREE ,
+we set it to the previously saved value, otherwise we can
+dereference
+.I gnp
+to get the proper value. Though harder to understand than the
+recursive version, this non-recursive routine is far less likely
+to blow the C stack. It will also run more efficiently since
+a lot of procedure call overhead has been removed. Most lists
+are small though (in the hundreds of items or less) and the
+recursive version should be sufficient for them.
+.EQ
+delim off
+.EN
diff --git a/lib/libc/rpc/PSD.doc/xdr.rfc.ms b/lib/libc/rpc/PSD.doc/xdr.rfc.ms
new file mode 100644
index 0000000..d4baff5
--- /dev/null
+++ b/lib/libc/rpc/PSD.doc/xdr.rfc.ms
@@ -0,0 +1,1058 @@
+.\"
+.\" Must use -- tbl -- with this one
+.\"
+.\" @(#)xdr.rfc.ms 2.2 88/08/05 4.0 RPCSRC
+.de BT
+.if \\n%=1 .tl ''- % -''
+..
+.ND
+.\" prevent excess underlining in nroff
+.if n .fp 2 R
+.OH 'External Data Representation Standard''Page %'
+.EH 'Page %''External Data Representation Standard'
+.IX "External Data Representation"
+.if \\n%=1 .bp
+.SH
+\&External Data Representation Standard: Protocol Specification
+.IX XDR RFC
+.IX XDR "protocol specification"
+.LP
+.NH 0
+\&Status of this Standard
+.nr OF 1
+.IX XDR "RFC status"
+.LP
+Note: This chapter specifies a protocol that Sun Microsystems, Inc., and
+others are using. It has been designated RFC1014 by the ARPA Network
+Information Center.
+.NH 1
+Introduction
+\&
+.LP
+XDR is a standard for the description and encoding of data. It is
+useful for transferring data between different computer
+architectures, and has been used to communicate data between such
+diverse machines as the Sun Workstation, VAX, IBM-PC, and Cray.
+XDR fits into the ISO presentation layer, and is roughly analogous in
+purpose to X.409, ISO Abstract Syntax Notation. The major difference
+between these two is that XDR uses implicit typing, while X.409 uses
+explicit typing.
+.LP
+XDR uses a language to describe data formats. The language can only
+be used only to describe data; it is not a programming language.
+This language allows one to describe intricate data formats in a
+concise manner. The alternative of using graphical representations
+(itself an informal language) quickly becomes incomprehensible when
+faced with complexity. The XDR language itself is similar to the C
+language [1], just as Courier [4] is similar to Mesa. Protocols such
+as Sun RPC (Remote Procedure Call) and the NFS (Network File System)
+use XDR to describe the format of their data.
+.LP
+The XDR standard makes the following assumption: that bytes (or
+octets) are portable, where a byte is defined to be 8 bits of data.
+A given hardware device should encode the bytes onto the various
+media in such a way that other hardware devices may decode the bytes
+without loss of meaning. For example, the Ethernet standard
+suggests that bytes be encoded in "little-endian" style [2], or least
+significant bit first.
+.NH 2
+\&Basic Block Size
+.IX XDR "basic block size"
+.IX XDR "block size"
+.LP
+The representation of all items requires a multiple of four bytes (or
+32 bits) of data. The bytes are numbered 0 through n-1. The bytes
+are read or written to some byte stream such that byte m always
+precedes byte m+1. If the n bytes needed to contain the data are not
+a multiple of four, then the n bytes are followed by enough (0 to 3)
+residual zero bytes, r, to make the total byte count a multiple of 4.
+.LP
+We include the familiar graphic box notation for illustration and
+comparison. In most illustrations, each box (delimited by a plus
+sign at the 4 corners and vertical bars and dashes) depicts a byte.
+Ellipses (...) between boxes show zero or more additional bytes where
+required.
+.ie t .DS
+.el .DS L
+\fIA Block\fP
+
+\f(CW+--------+--------+...+--------+--------+...+--------+
+| byte 0 | byte 1 |...|byte n-1| 0 |...| 0 |
++--------+--------+...+--------+--------+...+--------+
+|<-----------n bytes---------->|<------r bytes------>|
+|<-----------n+r (where (n+r) mod 4 = 0)>----------->|\fP
+
+.DE
+.NH 1
+\&XDR Data Types
+.IX XDR "data types"
+.IX "XDR data types"
+.LP
+Each of the sections that follow describes a data type defined in the
+XDR standard, shows how it is declared in the language, and includes
+a graphic illustration of its encoding.
+.LP
+For each data type in the language we show a general paradigm
+declaration. Note that angle brackets (< and >) denote
+variable length sequences of data and square brackets ([ and ]) denote
+fixed-length sequences of data. "n", "m" and "r" denote integers.
+For the full language specification and more formal definitions of
+terms such as "identifier" and "declaration", refer to
+.I "The XDR Language Specification" ,
+below.
+.LP
+For some data types, more specific examples are included.
+A more extensive example of a data description is in
+.I "An Example of an XDR Data Description"
+below.
+.NH 2
+\&Integer
+.IX XDR integer
+.LP
+An XDR signed integer is a 32-bit datum that encodes an integer in
+the range [-2147483648,2147483647]. The integer is represented in
+two's complement notation. The most and least significant bytes are
+0 and 3, respectively. Integers are declared as follows:
+.ie t .DS
+.el .DS L
+\fIInteger\fP
+
+\f(CW(MSB) (LSB)
++-------+-------+-------+-------+
+|byte 0 |byte 1 |byte 2 |byte 3 |
++-------+-------+-------+-------+
+<------------32 bits------------>\fP
+.DE
+.NH 2
+\&Unsigned Integer
+.IX XDR "unsigned integer"
+.IX XDR "integer, unsigned"
+.LP
+An XDR unsigned integer is a 32-bit datum that encodes a nonnegative
+integer in the range [0,4294967295]. It is represented by an
+unsigned binary number whose most and least significant bytes are 0
+and 3, respectively. An unsigned integer is declared as follows:
+.ie t .DS
+.el .DS L
+\fIUnsigned Integer\fP
+
+\f(CW(MSB) (LSB)
++-------+-------+-------+-------+
+|byte 0 |byte 1 |byte 2 |byte 3 |
++-------+-------+-------+-------+
+<------------32 bits------------>\fP
+.DE
+.NH 2
+\&Enumeration
+.IX XDR enumeration
+.LP
+Enumerations have the same representation as signed integers.
+Enumerations are handy for describing subsets of the integers.
+Enumerated data is declared as follows:
+.ft CW
+.DS
+enum { name-identifier = constant, ... } identifier;
+.DE
+For example, the three colors red, yellow, and blue could be
+described by an enumerated type:
+.DS
+.ft CW
+enum { RED = 2, YELLOW = 3, BLUE = 5 } colors;
+.DE
+It is an error to encode as an enum any other integer than those that
+have been given assignments in the enum declaration.
+.NH 2
+\&Boolean
+.IX XDR boolean
+.LP
+Booleans are important enough and occur frequently enough to warrant
+their own explicit type in the standard. Booleans are declared as
+follows:
+.DS
+.ft CW
+bool identifier;
+.DE
+This is equivalent to:
+.DS
+.ft CW
+enum { FALSE = 0, TRUE = 1 } identifier;
+.DE
+.NH 2
+\&Hyper Integer and Unsigned Hyper Integer
+.IX XDR "hyper integer"
+.IX XDR "integer, hyper"
+.LP
+The standard also defines 64-bit (8-byte) numbers called hyper
+integer and unsigned hyper integer. Their representations are the
+obvious extensions of integer and unsigned integer defined above.
+They are represented in two's complement notation. The most and
+least significant bytes are 0 and 7, respectively. Their
+declarations:
+.ie t .DS
+.el .DS L
+\fIHyper Integer\fP
+\fIUnsigned Hyper Integer\fP
+
+\f(CW(MSB) (LSB)
++-------+-------+-------+-------+-------+-------+-------+-------+
+|byte 0 |byte 1 |byte 2 |byte 3 |byte 4 |byte 5 |byte 6 |byte 7 |
++-------+-------+-------+-------+-------+-------+-------+-------+
+<----------------------------64 bits---------------------------->\fP
+.DE
+.NH 2
+\&Floating-point
+.IX XDR "integer, floating point"
+.IX XDR "floating-point integer"
+.LP
+The standard defines the floating-point data type "float" (32 bits or
+4 bytes). The encoding used is the IEEE standard for normalized
+single-precision floating-point numbers [3]. The following three
+fields describe the single-precision floating-point number:
+.RS
+.IP \fBS\fP:
+The sign of the number. Values 0 and 1 represent positive and
+negative, respectively. One bit.
+.IP \fBE\fP:
+The exponent of the number, base 2. 8 bits are devoted to this
+field. The exponent is biased by 127.
+.IP \fBF\fP:
+The fractional part of the number's mantissa, base 2. 23 bits
+are devoted to this field.
+.RE
+.LP
+Therefore, the floating-point number is described by:
+.DS
+(-1)**S * 2**(E-Bias) * 1.F
+.DE
+It is declared as follows:
+.ie t .DS
+.el .DS L
+\fISingle-Precision Floating-Point\fP
+
+\f(CW+-------+-------+-------+-------+
+|byte 0 |byte 1 |byte 2 |byte 3 |
+S| E | F |
++-------+-------+-------+-------+
+1|<- 8 ->|<-------23 bits------>|
+<------------32 bits------------>\fP
+.DE
+Just as the most and least significant bytes of a number are 0 and 3,
+the most and least significant bits of a single-precision floating-
+point number are 0 and 31. The beginning bit (and most significant
+bit) offsets of S, E, and F are 0, 1, and 9, respectively. Note that
+these numbers refer to the mathematical positions of the bits, and
+NOT to their actual physical locations (which vary from medium to
+medium).
+.LP
+The IEEE specifications should be consulted concerning the encoding
+for signed zero, signed infinity (overflow), and denormalized numbers
+(underflow) [3]. According to IEEE specifications, the "NaN" (not a
+number) is system dependent and should not be used externally.
+.NH 2
+\&Double-precision Floating-point
+.IX XDR "integer, double-precision floating point"
+.IX XDR "double-precision floating-point integer"
+.LP
+The standard defines the encoding for the double-precision floating-
+point data type "double" (64 bits or 8 bytes). The encoding used is
+the IEEE standard for normalized double-precision floating-point
+numbers [3]. The standard encodes the following three fields, which
+describe the double-precision floating-point number:
+.RS
+.IP \fBS\fP:
+The sign of the number. Values 0 and 1 represent positive and
+negative, respectively. One bit.
+.IP \fBE\fP:
+The exponent of the number, base 2. 11 bits are devoted to this
+field. The exponent is biased by 1023.
+.IP \fBF\fP:
+The fractional part of the number's mantissa, base 2. 52 bits
+are devoted to this field.
+.RE
+.LP
+Therefore, the floating-point number is described by:
+.DS
+(-1)**S * 2**(E-Bias) * 1.F
+.DE
+It is declared as follows:
+.ie t .DS
+.el .DS L
+\fIDouble-Precision Floating-Point\fP
+
+\f(CW+------+------+------+------+------+------+------+------+
+|byte 0|byte 1|byte 2|byte 3|byte 4|byte 5|byte 6|byte 7|
+S| E | F |
++------+------+------+------+------+------+------+------+
+1|<--11-->|<-----------------52 bits------------------->|
+<-----------------------64 bits------------------------->\fP
+.DE
+Just as the most and least significant bytes of a number are 0 and 3,
+the most and least significant bits of a double-precision floating-
+point number are 0 and 63. The beginning bit (and most significant
+bit) offsets of S, E , and F are 0, 1, and 12, respectively. Note
+that these numbers refer to the mathematical positions of the bits,
+and NOT to their actual physical locations (which vary from medium to
+medium).
+.LP
+The IEEE specifications should be consulted concerning the encoding
+for signed zero, signed infinity (overflow), and denormalized numbers
+(underflow) [3]. According to IEEE specifications, the "NaN" (not a
+number) is system dependent and should not be used externally.
+.NH 2
+\&Fixed-length Opaque Data
+.IX XDR "fixed-length opaque data"
+.IX XDR "opaque data, fixed length"
+.LP
+At times, fixed-length uninterpreted data needs to be passed among
+machines. This data is called "opaque" and is declared as follows:
+.DS
+.ft CW
+opaque identifier[n];
+.DE
+where the constant n is the (static) number of bytes necessary to
+contain the opaque data. If n is not a multiple of four, then the n
+bytes are followed by enough (0 to 3) residual zero bytes, r, to make
+the total byte count of the opaque object a multiple of four.
+.ie t .DS
+.el .DS L
+\fIFixed-Length Opaque\fP
+
+\f(CW0 1 ...
++--------+--------+...+--------+--------+...+--------+
+| byte 0 | byte 1 |...|byte n-1| 0 |...| 0 |
++--------+--------+...+--------+--------+...+--------+
+|<-----------n bytes---------->|<------r bytes------>|
+|<-----------n+r (where (n+r) mod 4 = 0)------------>|\fP
+.DE
+.NH 2
+\&Variable-length Opaque Data
+.IX XDR "variable-length opaque data"
+.IX XDR "opaque data, variable length"
+.LP
+The standard also provides for variable-length (counted) opaque data,
+defined as a sequence of n (numbered 0 through n-1) arbitrary bytes
+to be the number n encoded as an unsigned integer (as described
+below), and followed by the n bytes of the sequence.
+.LP
+Byte m of the sequence always precedes byte m+1 of the sequence, and
+byte 0 of the sequence always follows the sequence's length (count).
+enough (0 to 3) residual zero bytes, r, to make the total byte count
+a multiple of four. Variable-length opaque data is declared in the
+following way:
+.DS
+.ft CW
+opaque identifier<m>;
+.DE
+or
+.DS
+.ft CW
+opaque identifier<>;
+.DE
+The constant m denotes an upper bound of the number of bytes that the
+sequence may contain. If m is not specified, as in the second
+declaration, it is assumed to be (2**32) - 1, the maximum length.
+The constant m would normally be found in a protocol specification.
+For example, a filing protocol may state that the maximum data
+transfer size is 8192 bytes, as follows:
+.DS
+.ft CW
+opaque filedata<8192>;
+.DE
+This can be illustrated as follows:
+.ie t .DS
+.el .DS L
+\fIVariable-Length Opaque\fP
+
+\f(CW0 1 2 3 4 5 ...
++-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+
+| length n |byte0|byte1|...| n-1 | 0 |...| 0 |
++-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+
+|<-------4 bytes------->|<------n bytes------>|<---r bytes--->|
+|<----n+r (where (n+r) mod 4 = 0)---->|\fP
+.DE
+.LP
+It is an error to encode a length greater than the maximum
+described in the specification.
+.NH 2
+\&String
+.IX XDR string
+.LP
+The standard defines a string of n (numbered 0 through n-1) ASCII
+bytes to be the number n encoded as an unsigned integer (as described
+above), and followed by the n bytes of the string. Byte m of the
+string always precedes byte m+1 of the string, and byte 0 of the
+string always follows the string's length. If n is not a multiple of
+four, then the n bytes are followed by enough (0 to 3) residual zero
+bytes, r, to make the total byte count a multiple of four. Counted
+byte strings are declared as follows:
+.DS
+.ft CW
+string object<m>;
+.DE
+or
+.DS
+.ft CW
+string object<>;
+.DE
+The constant m denotes an upper bound of the number of bytes that a
+string may contain. If m is not specified, as in the second
+declaration, it is assumed to be (2**32) - 1, the maximum length.
+The constant m would normally be found in a protocol specification.
+For example, a filing protocol may state that a file name can be no
+longer than 255 bytes, as follows:
+.DS
+.ft CW
+string filename<255>;
+.DE
+Which can be illustrated as:
+.ie t .DS
+.el .DS L
+\fIA String\fP
+
+\f(CW0 1 2 3 4 5 ...
++-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+
+| length n |byte0|byte1|...| n-1 | 0 |...| 0 |
++-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+
+|<-------4 bytes------->|<------n bytes------>|<---r bytes--->|
+|<----n+r (where (n+r) mod 4 = 0)---->|\fP
+.DE
+.LP
+It is an error to encode a length greater than the maximum
+described in the specification.
+.NH 2
+\&Fixed-length Array
+.IX XDR "fixed-length array"
+.IX XDR "array, fixed length"
+.LP
+Declarations for fixed-length arrays of homogeneous elements are in
+the following form:
+.DS
+.ft CW
+type-name identifier[n];
+.DE
+Fixed-length arrays of elements numbered 0 through n-1 are encoded by
+individually encoding the elements of the array in their natural
+order, 0 through n-1. Each element's size is a multiple of four
+bytes. Though all elements are of the same type, the elements may
+have different sizes. For example, in a fixed-length array of
+strings, all elements are of type "string", yet each element will
+vary in its length.
+.ie t .DS
+.el .DS L
+\fIFixed-Length Array\fP
+
+\f(CW+---+---+---+---+---+---+---+---+...+---+---+---+---+
+| element 0 | element 1 |...| element n-1 |
++---+---+---+---+---+---+---+---+...+---+---+---+---+
+|<--------------------n elements------------------->|\fP
+.DE
+.NH 2
+\&Variable-length Array
+.IX XDR "variable-length array"
+.IX XDR "array, variable length"
+.LP
+Counted arrays provide the ability to encode variable-length arrays
+of homogeneous elements. The array is encoded as the element count n
+(an unsigned integer) followed by the encoding of each of the array's
+elements, starting with element 0 and progressing through element n-
+1. The declaration for variable-length arrays follows this form:
+.DS
+.ft CW
+type-name identifier<m>;
+.DE
+or
+.DS
+.ft CW
+type-name identifier<>;
+.DE
+The constant m specifies the maximum acceptable element count of an
+array; if m is not specified, as in the second declaration, it is
+assumed to be (2**32) - 1.
+.ie t .DS
+.el .DS L
+\fICounted Array\fP
+
+\f(CW0 1 2 3
++--+--+--+--+--+--+--+--+--+--+--+--+...+--+--+--+--+
+| n | element 0 | element 1 |...|element n-1|
++--+--+--+--+--+--+--+--+--+--+--+--+...+--+--+--+--+
+|<-4 bytes->|<--------------n elements------------->|\fP
+.DE
+It is an error to encode a value of n that is greater than the
+maximum described in the specification.
+.NH 2
+\&Structure
+.IX XDR structure
+.LP
+Structures are declared as follows:
+.DS
+.ft CW
+struct {
+ component-declaration-A;
+ component-declaration-B;
+ \&...
+} identifier;
+.DE
+The components of the structure are encoded in the order of their
+declaration in the structure. Each component's size is a multiple of
+four bytes, though the components may be different sizes.
+.ie t .DS
+.el .DS L
+\fIStructure\fP
+
+\f(CW+-------------+-------------+...
+| component A | component B |...
++-------------+-------------+...\fP
+.DE
+.NH 2
+\&Discriminated Union
+.IX XDR "discriminated union"
+.IX XDR union discriminated
+.LP
+A discriminated union is a type composed of a discriminant followed
+by a type selected from a set of prearranged types according to the
+value of the discriminant. The type of discriminant is either "int",
+"unsigned int", or an enumerated type, such as "bool". The component
+types are called "arms" of the union, and are preceded by the value
+of the discriminant which implies their encoding. Discriminated
+unions are declared as follows:
+.DS
+.ft CW
+union switch (discriminant-declaration) {
+ case discriminant-value-A:
+ arm-declaration-A;
+ case discriminant-value-B:
+ arm-declaration-B;
+ \&...
+ default: default-declaration;
+} identifier;
+.DE
+Each "case" keyword is followed by a legal value of the discriminant.
+The default arm is optional. If it is not specified, then a valid
+encoding of the union cannot take on unspecified discriminant values.
+The size of the implied arm is always a multiple of four bytes.
+.LP
+The discriminated union is encoded as its discriminant followed by
+the encoding of the implied arm.
+.ie t .DS
+.el .DS L
+\fIDiscriminated Union\fP
+
+\f(CW0 1 2 3
++---+---+---+---+---+---+---+---+
+| discriminant | implied arm |
++---+---+---+---+---+---+---+---+
+|<---4 bytes--->|\fP
+.DE
+.NH 2
+\&Void
+.IX XDR void
+.LP
+An XDR void is a 0-byte quantity. Voids are useful for describing
+operations that take no data as input or no data as output. They are
+also useful in unions, where some arms may contain data and others do
+not. The declaration is simply as follows:
+.DS
+.ft CW
+void;
+.DE
+Voids are illustrated as follows:
+.ie t .DS
+.el .DS L
+\fIVoid\fP
+
+\f(CW ++
+ ||
+ ++
+--><-- 0 bytes\fP
+.DE
+.NH 2
+\&Constant
+.IX XDR constant
+.LP
+The data declaration for a constant follows this form:
+.DS
+.ft CW
+const name-identifier = n;
+.DE
+"const" is used to define a symbolic name for a constant; it does not
+declare any data. The symbolic constant may be used anywhere a
+regular constant may be used. For example, the following defines a
+symbolic constant DOZEN, equal to 12.
+.DS
+.ft CW
+const DOZEN = 12;
+.DE
+.NH 2
+\&Typedef
+.IX XDR typedef
+.LP
+"typedef" does not declare any data either, but serves to define new
+identifiers for declaring data. The syntax is:
+.DS
+.ft CW
+typedef declaration;
+.DE
+The new type name is actually the variable name in the declaration
+part of the typedef. For example, the following defines a new type
+called "eggbox" using an existing type called "egg":
+.DS
+.ft CW
+typedef egg eggbox[DOZEN];
+.DE
+Variables declared using the new type name have the same type as the
+new type name would have in the typedef, if it was considered a
+variable. For example, the following two declarations are equivalent
+in declaring the variable "fresheggs":
+.DS
+.ft CW
+eggbox fresheggs;
+egg fresheggs[DOZEN];
+.DE
+When a typedef involves a struct, enum, or union definition, there is
+another (preferred) syntax that may be used to define the same type.
+In general, a typedef of the following form:
+.DS
+.ft CW
+typedef <<struct, union, or enum definition>> identifier;
+.DE
+may be converted to the alternative form by removing the "typedef"
+part and placing the identifier after the "struct", "union", or
+"enum" keyword, instead of at the end. For example, here are the two
+ways to define the type "bool":
+.DS
+.ft CW
+typedef enum { /* \fIusing typedef\fP */
+ FALSE = 0,
+ TRUE = 1
+ } bool;
+
+enum bool { /* \fIpreferred alternative\fP */
+ FALSE = 0,
+ TRUE = 1
+ };
+.DE
+The reason this syntax is preferred is one does not have to wait
+until the end of a declaration to figure out the name of the new
+type.
+.NH 2
+\&Optional-data
+.IX XDR "optional data"
+.IX XDR "data, optional"
+.LP
+Optional-data is one kind of union that occurs so frequently that we
+give it a special syntax of its own for declaring it. It is declared
+as follows:
+.DS
+.ft CW
+type-name *identifier;
+.DE
+This is equivalent to the following union:
+.DS
+.ft CW
+union switch (bool opted) {
+ case TRUE:
+ type-name element;
+ case FALSE:
+ void;
+} identifier;
+.DE
+It is also equivalent to the following variable-length array
+declaration, since the boolean "opted" can be interpreted as the
+length of the array:
+.DS
+.ft CW
+type-name identifier<1>;
+.DE
+Optional-data is not so interesting in itself, but it is very useful
+for describing recursive data-structures such as linked-lists and
+trees. For example, the following defines a type "stringlist" that
+encodes lists of arbitrary length strings:
+.DS
+.ft CW
+struct *stringlist {
+ string item<>;
+ stringlist next;
+};
+.DE
+It could have been equivalently declared as the following union:
+.DS
+.ft CW
+union stringlist switch (bool opted) {
+ case TRUE:
+ struct {
+ string item<>;
+ stringlist next;
+ } element;
+ case FALSE:
+ void;
+};
+.DE
+or as a variable-length array:
+.DS
+.ft CW
+struct stringlist<1> {
+ string item<>;
+ stringlist next;
+};
+.DE
+Both of these declarations obscure the intention of the stringlist
+type, so the optional-data declaration is preferred over both of
+them. The optional-data type also has a close correlation to how
+recursive data structures are represented in high-level languages
+such as Pascal or C by use of pointers. In fact, the syntax is the
+same as that of the C language for pointers.
+.NH 2
+\&Areas for Future Enhancement
+.IX XDR futures
+.LP
+The XDR standard lacks representations for bit fields and bitmaps,
+since the standard is based on bytes. Also missing are packed (or
+binary-coded) decimals.
+.LP
+The intent of the XDR standard was not to describe every kind of data
+that people have ever sent or will ever want to send from machine to
+machine. Rather, it only describes the most commonly used data-types
+of high-level languages such as Pascal or C so that applications
+written in these languages will be able to communicate easily over
+some medium.
+.LP
+One could imagine extensions to XDR that would let it describe almost
+any existing protocol, such as TCP. The minimum necessary for this
+are support for different block sizes and byte-orders. The XDR
+discussed here could then be considered the 4-byte big-endian member
+of a larger XDR family.
+.NH 1
+\&Discussion
+.sp 2
+.NH 2
+\&Why a Language for Describing Data?
+.IX XDR language
+.LP
+There are many advantages in using a data-description language such
+as XDR versus using diagrams. Languages are more formal than
+diagrams and lead to less ambiguous descriptions of data.
+Languages are also easier to understand and allow one to think of
+other issues instead of the low-level details of bit-encoding.
+Also, there is a close analogy between the types of XDR and a
+high-level language such as C or Pascal. This makes the
+implementation of XDR encoding and decoding modules an easier task.
+Finally, the language specification itself is an ASCII string that
+can be passed from machine to machine to perform on-the-fly data
+interpretation.
+.NH 2
+\&Why Only one Byte-Order for an XDR Unit?
+.IX XDR "byte order"
+.LP
+Supporting two byte-orderings requires a higher level protocol for
+determining in which byte-order the data is encoded. Since XDR is
+not a protocol, this can't be done. The advantage of this, though,
+is that data in XDR format can be written to a magnetic tape, for
+example, and any machine will be able to interpret it, since no
+higher level protocol is necessary for determining the byte-order.
+.NH 2
+\&Why does XDR use Big-Endian Byte-Order?
+.LP
+Yes, it is unfair, but having only one byte-order means you have to
+be unfair to somebody. Many architectures, such as the Motorola
+68000 and IBM 370, support the big-endian byte-order.
+.NH 2
+\&Why is the XDR Unit Four Bytes Wide?
+.LP
+There is a tradeoff in choosing the XDR unit size. Choosing a small
+size such as two makes the encoded data small, but causes alignment
+problems for machines that aren't aligned on these boundaries. A
+large size such as eight means the data will be aligned on virtually
+every machine, but causes the encoded data to grow too big. We chose
+four as a compromise. Four is big enough to support most
+architectures efficiently, except for rare machines such as the
+eight-byte aligned Cray. Four is also small enough to keep the
+encoded data restricted to a reasonable size.
+.NH 2
+\&Why must Variable-Length Data be Padded with Zeros?
+.IX XDR "variable-length data"
+.LP
+It is desirable that the same data encode into the same thing on all
+machines, so that encoded data can be meaningfully compared or
+checksummed. Forcing the padded bytes to be zero ensures this.
+.NH 2
+\&Why is there No Explicit Data-Typing?
+.LP
+Data-typing has a relatively high cost for what small advantages it
+may have. One cost is the expansion of data due to the inserted type
+fields. Another is the added cost of interpreting these type fields
+and acting accordingly. And most protocols already know what type
+they expect, so data-typing supplies only redundant information.
+However, one can still get the benefits of data-typing using XDR. One
+way is to encode two things: first a string which is the XDR data
+description of the encoded data, and then the encoded data itself.
+Another way is to assign a value to all the types in XDR, and then
+define a universal type which takes this value as its discriminant
+and for each value, describes the corresponding data type.
+.NH 1
+\&The XDR Language Specification
+.IX XDR language
+.sp 1
+.NH 2
+\&Notational Conventions
+.IX "XDR language" notation
+.LP
+This specification uses an extended Backus-Naur Form notation for
+describing the XDR language. Here is a brief description of the
+notation:
+.IP 1.
+The characters
+.I | ,
+.I ( ,
+.I ) ,
+.I [ ,
+.I ] ,
+.I " ,
+and
+.I *
+are special.
+.IP 2.
+Terminal symbols are strings of any characters surrounded by
+double quotes.
+.IP 3.
+Non-terminal symbols are strings of non-special characters.
+.IP 4.
+Alternative items are separated by a vertical bar ("\fI|\fP").
+.IP 5.
+Optional items are enclosed in brackets.
+.IP 6.
+Items are grouped together by enclosing them in parentheses.
+.IP 7.
+A
+.I *
+following an item means 0 or more occurrences of that item.
+.LP
+For example, consider the following pattern:
+.DS L
+"a " "very" (", " " very")* [" cold " "and"] " rainy " ("day" | "night")
+.DE
+.LP
+An infinite number of strings match this pattern. A few of them
+are:
+.DS
+"a very rainy day"
+"a very, very rainy day"
+"a very cold and rainy day"
+"a very, very, very cold and rainy night"
+.DE
+.NH 2
+\&Lexical Notes
+.IP 1.
+Comments begin with '/*' and terminate with '*/'.
+.IP 2.
+White space serves to separate items and is otherwise ignored.
+.IP 3.
+An identifier is a letter followed by an optional sequence of
+letters, digits or underbar ('_'). The case of identifiers is
+not ignored.
+.IP 4.
+A constant is a sequence of one or more decimal digits,
+optionally preceded by a minus-sign ('-').
+.NH 2
+\&Syntax Information
+.IX "XDR language" syntax
+.DS
+.ft CW
+declaration:
+ type-specifier identifier
+ | type-specifier identifier "[" value "]"
+ | type-specifier identifier "<" [ value ] ">"
+ | "opaque" identifier "[" value "]"
+ | "opaque" identifier "<" [ value ] ">"
+ | "string" identifier "<" [ value ] ">"
+ | type-specifier "*" identifier
+ | "void"
+.DE
+.DS
+.ft CW
+value:
+ constant
+ | identifier
+
+type-specifier:
+ [ "unsigned" ] "int"
+ | [ "unsigned" ] "hyper"
+ | "float"
+ | "double"
+ | "bool"
+ | enum-type-spec
+ | struct-type-spec
+ | union-type-spec
+ | identifier
+.DE
+.DS
+.ft CW
+enum-type-spec:
+ "enum" enum-body
+
+enum-body:
+ "{"
+ ( identifier "=" value )
+ ( "," identifier "=" value )*
+ "}"
+.DE
+.DS
+.ft CW
+struct-type-spec:
+ "struct" struct-body
+
+struct-body:
+ "{"
+ ( declaration ";" )
+ ( declaration ";" )*
+ "}"
+.DE
+.DS
+.ft CW
+union-type-spec:
+ "union" union-body
+
+union-body:
+ "switch" "(" declaration ")" "{"
+ ( "case" value ":" declaration ";" )
+ ( "case" value ":" declaration ";" )*
+ [ "default" ":" declaration ";" ]
+ "}"
+
+constant-def:
+ "const" identifier "=" constant ";"
+.DE
+.DS
+.ft CW
+type-def:
+ "typedef" declaration ";"
+ | "enum" identifier enum-body ";"
+ | "struct" identifier struct-body ";"
+ | "union" identifier union-body ";"
+
+definition:
+ type-def
+ | constant-def
+
+specification:
+ definition *
+.DE
+.NH 3
+\&Syntax Notes
+.IX "XDR language" syntax
+.LP
+.IP 1.
+The following are keywords and cannot be used as identifiers:
+"bool", "case", "const", "default", "double", "enum", "float",
+"hyper", "opaque", "string", "struct", "switch", "typedef", "union",
+"unsigned" and "void".
+.IP 2.
+Only unsigned constants may be used as size specifications for
+arrays. If an identifier is used, it must have been declared
+previously as an unsigned constant in a "const" definition.
+.IP 3.
+Constant and type identifiers within the scope of a specification
+are in the same name space and must be declared uniquely within this
+scope.
+.IP 4.
+Similarly, variable names must be unique within the scope of
+struct and union declarations. Nested struct and union declarations
+create new scopes.
+.IP 5.
+The discriminant of a union must be of a type that evaluates to
+an integer. That is, "int", "unsigned int", "bool", an enumerated
+type or any typedefed type that evaluates to one of these is legal.
+Also, the case values must be one of the legal values of the
+discriminant. Finally, a case value may not be specified more than
+once within the scope of a union declaration.
+.NH 1
+\&An Example of an XDR Data Description
+.LP
+Here is a short XDR data description of a thing called a "file",
+which might be used to transfer files from one machine to another.
+.ie t .DS
+.el .DS L
+.ft CW
+
+const MAXUSERNAME = 32; /*\fI max length of a user name \fP*/
+const MAXFILELEN = 65535; /*\fI max length of a file \fP*/
+const MAXNAMELEN = 255; /*\fI max length of a file name \fP*/
+
+.ft I
+/*
+ * Types of files:
+ */
+.ft CW
+
+enum filekind {
+ TEXT = 0, /*\fI ascii data \fP*/
+ DATA = 1, /*\fI raw data \fP*/
+ EXEC = 2 /*\fI executable \fP*/
+};
+
+.ft I
+/*
+ * File information, per kind of file:
+ */
+.ft CW
+
+union filetype switch (filekind kind) {
+ case TEXT:
+ void; /*\fI no extra information \fP*/
+ case DATA:
+ string creator<MAXNAMELEN>; /*\fI data creator \fP*/
+ case EXEC:
+ string interpretor<MAXNAMELEN>; /*\fI program interpretor \fP*/
+};
+
+.ft I
+/*
+ * A complete file:
+ */
+.ft CW
+
+struct file {
+ string filename<MAXNAMELEN>; /*\fI name of file \fP*/
+ filetype type; /*\fI info about file \fP*/
+ string owner<MAXUSERNAME>; /*\fI owner of file \fP*/
+ opaque data<MAXFILELEN>; /*\fI file data \fP*/
+};
+.DE
+.LP
+Suppose now that there is a user named "john" who wants to store
+his lisp program "sillyprog" that contains just the data "(quit)".
+His file would be encoded as follows:
+.TS
+box tab (&) ;
+lfI lfI lfI lfI
+rfL rfL rfL l .
+Offset&Hex Bytes&ASCII&Description
+_
+0&00 00 00 09&....&Length of filename = 9
+4&73 69 6c 6c&sill&Filename characters
+8&79 70 72 6f&ypro& ... and more characters ...
+12&67 00 00 00&g...& ... and 3 zero-bytes of fill
+16&00 00 00 02&....&Filekind is EXEC = 2
+20&00 00 00 04&....&Length of interpretor = 4
+24&6c 69 73 70&lisp&Interpretor characters
+28&00 00 00 04&....&Length of owner = 4
+32&6a 6f 68 6e&john&Owner characters
+36&00 00 00 06&....&Length of file data = 6
+40&28 71 75 69&(qui&File data bytes ...
+44&74 29 00 00&t)..& ... and 2 zero-bytes of fill
+.TE
+.NH 1
+\&References
+.LP
+[1] Brian W. Kernighan & Dennis M. Ritchie, "The C Programming
+Language", Bell Laboratories, Murray Hill, New Jersey, 1978.
+.LP
+[2] Danny Cohen, "On Holy Wars and a Plea for Peace", IEEE Computer,
+October 1981.
+.LP
+[3] "IEEE Standard for Binary Floating-Point Arithmetic", ANSI/IEEE
+Standard 754-1985, Institute of Electrical and Electronics
+Engineers, August 1985.
+.LP
+[4] "Courier: The Remote Procedure Call Protocol", XEROX
+Corporation, XSIS 038112, December 1981.
diff --git a/lib/libc/rpc/README b/lib/libc/rpc/README
new file mode 100644
index 0000000..ad9d70f
--- /dev/null
+++ b/lib/libc/rpc/README
@@ -0,0 +1,233 @@
+RPCSRC 4.0 7/11/89
+
+This distribution contains Sun Microsystem's implementation of the
+RPC and XDR protocols and is compatible with 4.2BSD and 4.3BSD. Also
+included is complete documentation, utilities, RPC service
+specification files, and demonstration services in the format used by
+the RPC protocol compiler (rpcgen). See WHAT'S NEW below for
+details.
+
+NOTE ABOUT SECURE RPC:
+
+This release of RPCSRC contains most of the code needed to implement
+Secure RPC (see "DES Authentication" in the RPC Protocol Specification,
+doc/rpc.rfc.ms). Due to legal considerations, we are unable to
+distribute an implementation of DES, the Data Encryption Standard, which
+Secure RPC requires. For this reason, all of the files, documentation, and
+programs associated with Secure RPC have been placed into a separate
+directory, secure_rpc. The RPC library contained in the main body of this
+release *DOES NOT* support Secure RPC. See secure_rpc/README for more
+details. (A DES library was posted in Volume 18 of comp.sources.unix.)
+
+If you wish to report bugs found in this release, send mail to:
+
+Portable ONC/NFS
+Sun Microsystems, Inc
+MS 12-33
+2550 Garcia Avenue
+Mountain View, CA 94043
+
+or send Email to nfsnet@sun.com (the Internet) or sun!nfsnet (Usenet).
+
+ROADMAP
+
+The directory hierarchy is as follows:
+
+ demo/ Various demonstration services
+ demo/dir Remote directory lister
+ demo/msg Remote console message delivery service
+ demo/sort Remote sort service
+
+ doc/ Documentation for RPC, XDR and NFS in "-ms" format.
+
+ etc/ Utilities (rpcinfo and portmap). portmap must be
+ started by root before any other RPC network services are
+ used. SEE BELOW FOR BUGFIX TO 4.3BSD COMPILER.
+
+ man/ Manual pages for RPC library, rpcgen, and utilities.
+
+ rpc/ The RPC and XDR library. SEE BELOW
+ FOR BUGFIX TO 4.2BSD COMPILER.
+
+ rpcgen/ The RPC Language compiler (for .x files)
+
+ rpcsvc/ Service definition files for various services and the
+ server and client code for the Remote Status service.
+
+ secure_rpc/ The files in this directory are used to build a version of
+ the RPC library with DES Authentication. See the README
+ file in that directory for more details.
+
+BUILD INSTRUCTIONS
+
+Makefiles can be found in all directories except for man. The
+Makefile in the top directory will cause these others to be invoked
+(except for in the doc, man and demo directories), in turn building the
+entire release.
+
+WARNING! THE DEFAULT INSTALLATION PROCEDURES WILL INSTALL FILES
+IN /usr/include, /usr/lib, /usr/bin and /etc.
+
+The master RPC include file, rpc/rpc.h, is used by all programs and
+routines that use RPC. It includes other RPC and system include files
+needed by the RPC system. PLEASE NOTE: If your system has NFS, it
+may have been based on Sun's NFS Source. The include files installed
+by this package may duplicate include files you will find on your NFS
+system. The RPCSRC 4.0 include files are upwardly compatible to all
+NFS Source include files as of the date of this distribution (not
+including any new definitions or declarations added by your system
+vendor). HOWEVER: Please read the comments towards the end of
+rpc/rpc.h regarding rpc/netdb.h. You may need to uncomment the
+inclusion of that file if the structures it defines are already
+defined by your system's include files.
+
+After making any compiler fixes that are needed (see below), at
+the top directory, type:
+
+ make install
+
+For all installations, the Makefile macro DESTDIR is prepended to the
+installation path. It is defined to be null in the Makefiles, so
+installations are relative to root. (You will probably need root
+privileges for installing the files under the default path.) To
+install the files under some other tree (e.g., /usr/local), use the
+command:
+
+ make install DESTDIR=/usr/local
+
+This will place the include files in /usr/local/usr/include, the RPC
+library in /usr/local/usr/lib, rpcgen in /usr/local/usr/bin, and the
+utilities in /usr/local/etc. You'll have to edit the Makefiles or
+install the files by hand if you want to do anything other than this
+kind of relocation of the installation tree.
+
+The RPC library will be built and installed first. By default it is
+installed in /usr/lib as "librpclib.a". The directory
+/usr/include/rpc will also be created, and several header files will
+be installed there. ALL RPC SERVICES INCLUDE THESE HEADER FILES.
+
+The programs in etc/ link in routines from librpclib.a. If you change
+where it is installed, be sure to edit etc/'s Makefile to reflect this.
+These programs are installed in /etc. PORTMAP MUST BE RUNNING ON
+YOUR SYSTEM BEFORE YOU START ANY OTHER RPC SERVICE.
+
+rpcgen is installed in /usr/bin. This program is required to build
+the demonstration services in demo and the rstat client and server in
+rpcsvc/.
+
+The rpcsvc/ directory will install its files in the directory
+/usr/include/rpcsvc. The Remote Status service (rstat_svc) will be
+compiled and installed in /etc. If you wish to make this service
+available, you should either start this service when needed or have
+it started at boot time by invoking it in your /etc/rc.local script.
+(Be sure that portmap is started first!) Sun has modified its
+version of inetd to automatically start RPC services. (Use "make
+LIB=" when building rstat on a Sun Workstation.) The Remote Status
+client (rstat) will be installed in /usr/bin. This program queries
+the rstat_svc on a remote host and prints a system status summary
+similar to the one printed by "uptime".
+
+The documentation is not built during the "make install" command.
+Typing "make" in the doc directory will cause all of the manuals to
+be formatted using nroff into a single file. We have had a report
+that certain "troff" equivalents have trouble processing the full
+manual. If you have trouble, try building the manuals individually
+(see the Makefile).
+
+The demonstration services in the demo directory are not built by the
+top-level "make install" command. To build these, cd to the demo
+directory and enter "make". The three services will be built.
+RPCGEN MUST BE INSTALLED in a path that make can find. To run the
+services, start the portmap program as root and invoke the service
+(you probably will want to put it in the background). rpcinfo can be
+used to check that the service succeeded in getting registered with
+portmap, and to ping the service (see rpcinfo's man page). You can
+then use the corresponding client program to exercise the service.
+To build these services on a Sun workstation, you must prevent the
+Makefile from trying to link the RPC library (as these routines are
+already a part of Sun's libc). Use: "make LIB=".
+
+BUGFIX FOR 4.3BSD COMPILER
+
+The use of a 'void *' declaration for one of the arguments in
+the reply_proc() procedure in etc/rpcinfo.c will trigger a bug
+in the 4.3BSD compiler. The bug is fixed by the following change to
+the compiler file mip/manifest.h:
+
+*** manifest.h.r1.1 Thu Apr 30 13:52:25 1987
+--- manifest.h.r1.2 Mon Nov 23 18:58:17 1987
+***************
+*** 21,27 ****
+ /*
+ * Bogus type values
+ */
+! #define TNULL PTR /* pointer to UNDEF */
+ #define TVOID FTN /* function returning UNDEF (for void) */
+
+ /*
+--- 21,27 ----
+ /*
+ * Bogus type values
+ */
+! #define TNULL INCREF(MOETY) /* pointer to MOETY -- impossible type */
+ #define TVOID FTN /* function returning UNDEF (for void) */
+
+ /*
+
+If you cannot fix your compiler, change the declaration in reply_proc()
+from 'void *' to 'char *'.
+
+BUGFIX FOR 4.2BSD COMPILER
+
+Unpatched 4.2BSD compilers complain about valid C. You can make old
+compilers happy by changing some voids to ints. However, the fix to
+the 4.2 VAX compiler is as follows (to mip/trees.c):
+
+*** trees.c.r1.1 Mon May 11 13:47:58 1987
+--- trees.c.r1.2 Wed Jul 2 18:28:52 1986
+***************
+*** 1247,1253 ****
+ if(o==CAST && mt1==0)return(TYPL+TYMATCH);
+ if( mt12 & MDBI ) return( TYPL+LVAL+TYMATCH );
+ else if( (mt1&MENU)||(mt2&MENU) ) return( LVAL+NCVT+TYPL+PTMATCH+PUN );
+! else if( mt12 == 0 ) break;
+ else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );
+ else if( mt12 & MPTI ) return( TYPL+LVAL+TYMATCH+PUN );
+ break;
+--- 1261,1269 ----
+ if(o==CAST && mt1==0)return(TYPL+TYMATCH);
+ if( mt12 & MDBI ) return( TYPL+LVAL+TYMATCH );
+ else if( (mt1&MENU)||(mt2&MENU) ) return( LVAL+NCVT+TYPL+PTMATCH+PUN );
+! /* if right is TVOID and looks like a CALL, is not ok */
+! else if (mt2 == 0 && (p->in.right->in.op == CALL || p->in.right->in.op == UNARY CALL))
+! break;
+ else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );
+ else if( mt12 & MPTI ) return( TYPL+LVAL+TYMATCH+PUN );
+ break;
+
+WHAT'S NEW IN THIS RELEASE: RPCSRC 4.0
+
+The previous release was RPCSRC 3.9. As with all previous releases,
+this release is based directly on files from Sun Microsystem's
+implementation.
+
+Upgrade from RPCSRC 3.9
+
+1) RPCSRC 4.0 upgrades RPCSRC 3.9. Improvements from SunOS 4.0 have
+ been integrated into this release.
+
+Secure RPC (in the secure_rpc/ directory)
+
+2) DES Authentication routines and programs are provided.
+3) A new manual, "Secure NFS" is provided, which describes Secure RPC
+ and Secure NFS.
+4) Skeleton routines and manual pages are provided which describe the
+ DES encryption procedures required by Secure RPC. HOWEVER, NO DES
+ ROUTINE IS PROVIDED.
+
+New Functionality
+
+5) rpcinfo can now be used to de-register services from the portmapper
+ which may have terminated abnormally.
+6) A new client, rstat, is provided which queries the rstat_svc and
+ prints a status line similar to the one displayed by "uptime".
diff --git a/lib/libc/rpc/auth_des.c b/lib/libc/rpc/auth_des.c
new file mode 100644
index 0000000..3fd2bfe
--- /dev/null
+++ b/lib/libc/rpc/auth_des.c
@@ -0,0 +1,554 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+/*
+ * Copyright (c) 1988 by Sun Microsystems, Inc.
+ */
+/*
+ * auth_des.c, client-side implementation of DES authentication
+ */
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/cdefs.h>
+#include <rpc/des_crypt.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/auth_des.h>
+#include <netinet/in.h> /* XXX: just to get htonl() and ntohl() */
+#include <sys/socket.h>
+#undef NIS
+#include <rpcsvc/nis.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/* from: static char sccsid[] = "@(#)auth_des.c 2.2 88/07/29 4.0 RPCSRC; from 1.9 88/02/08 SMI"; */
+static const char rcsid[] = "$Id$";
+#endif
+
+extern bool_t __rpc_get_time_offset __P(( struct timeval *, nis_server *,
+ char *, char **, struct sockaddr_in * ));
+extern int rtime __P(( struct sockaddr_in *, struct timeval *, struct timeval *));
+extern bool_t xdr_authdes_cred __P(( XDR *, struct authdes_cred * ));
+extern bool_t xdr_authdes_verf __P(( XDR *, struct authdes_verf * ));
+
+#define MILLION 1000000L
+#define RTIME_TIMEOUT 5 /* seconds to wait for sync */
+
+#define AUTH_PRIVATE(auth) (struct ad_private *) auth->ah_private
+#define ALLOC(object_type) (object_type *) mem_alloc(sizeof(object_type))
+#define FREE(ptr, size) mem_free((char *)(ptr), (int) size)
+#define ATTEMPT(xdr_op) if (!(xdr_op)) return (FALSE)
+
+#define debug(msg) /*printf("%s\n", msg) */
+
+/*
+ * DES authenticator operations vector
+ */
+static void authdes_nextverf();
+static bool_t authdes_marshal();
+static bool_t authdes_validate();
+static bool_t authdes_refresh();
+static void authdes_destroy();
+static struct auth_ops authdes_ops = {
+ authdes_nextverf,
+ authdes_marshal,
+ authdes_validate,
+ authdes_refresh,
+ authdes_destroy
+};
+#ifdef foo
+static bool_t synchronize __P(( struct sockaddr *, struct timeval *));
+#endif
+/*
+ * This struct is pointed to by the ah_private field of an "AUTH *"
+ */
+struct ad_private {
+ char *ad_fullname; /* client's full name */
+ u_int ad_fullnamelen; /* length of name, rounded up */
+ char *ad_servername; /* server's full name */
+ u_int ad_servernamelen; /* length of name, rounded up */
+ u_int ad_window; /* client specified window */
+ bool_t ad_dosync; /* synchronize? */
+ struct sockaddr ad_syncaddr; /* remote host to synch with */
+ char *ad_timehost; /* remote host to synch with */
+ struct timeval ad_timediff; /* server's time - client's time */
+ u_long ad_nickname; /* server's nickname for client */
+ struct authdes_cred ad_cred; /* storage for credential */
+ struct authdes_verf ad_verf; /* storage for verifier */
+ struct timeval ad_timestamp; /* timestamp sent */
+ des_block ad_xkey; /* encrypted conversation key */
+ u_char ad_pkey[1024]; /* Server's actual public key */
+ char *ad_netid; /* Timehost netid */
+ char *ad_uaddr; /* Timehost uaddr */
+ nis_server *ad_nis_srvr; /* NIS+ server struct */
+};
+
+
+/*
+ * Create the client des authentication object
+ */
+AUTH *
+authdes_create(servername, window, syncaddr, ckey)
+ char *servername; /* network name of server */
+ u_int window; /* time to live */
+ struct sockaddr *syncaddr; /* optional addr of host to sync with */
+ des_block *ckey; /* optional conversation key to use*/
+{
+
+ AUTH *auth;
+ struct ad_private *ad;
+ char namebuf[MAXNETNAMELEN+1];
+ u_char pkey_data[1024];
+
+ if (!getpublickey(servername, pkey_data))
+ return(NULL);
+
+ /*
+ * Allocate everything now
+ */
+ auth = ALLOC(AUTH);
+ ad = ALLOC(struct ad_private);
+ (void) getnetname(namebuf);
+
+ ad->ad_fullnamelen = RNDUP(strlen(namebuf));
+ ad->ad_fullname = (char *)mem_alloc(ad->ad_fullnamelen + 1);
+
+ ad->ad_servernamelen = strlen(servername);
+ ad->ad_servername = (char *)mem_alloc(ad->ad_servernamelen + 1);
+
+ if (auth == NULL || ad == NULL || ad->ad_fullname == NULL ||
+ ad->ad_servername == NULL) {
+ debug("authdes_create: out of memory");
+ goto failed;
+ }
+
+ /*
+ * Set up private data
+ */
+ bcopy(namebuf, ad->ad_fullname, ad->ad_fullnamelen + 1);
+ bcopy(servername, ad->ad_servername, ad->ad_servernamelen + 1);
+ bcopy(pkey_data, ad->ad_pkey, strlen(pkey_data) + 1);
+ if (syncaddr != NULL) {
+ ad->ad_syncaddr = *syncaddr;
+ ad->ad_dosync = TRUE;
+ } else {
+ ad->ad_dosync = FALSE;
+ }
+ ad->ad_window = window;
+ if (ckey == NULL) {
+ if (key_gendes(&auth->ah_key) < 0) {
+ debug("authdes_create: unable to gen conversation key");
+ return (NULL);
+ }
+ } else {
+ auth->ah_key = *ckey;
+ }
+
+ /*
+ * Set up auth handle
+ */
+ auth->ah_cred.oa_flavor = AUTH_DES;
+ auth->ah_verf.oa_flavor = AUTH_DES;
+ auth->ah_ops = &authdes_ops;
+ auth->ah_private = (caddr_t)ad;
+
+ if (!authdes_refresh(auth)) {
+ goto failed;
+ }
+ return (auth);
+
+failed:
+ if (auth != NULL)
+ FREE(auth, sizeof(AUTH));
+ if (ad != NULL)
+ FREE(ad, sizeof(struct ad_private));
+ if (ad->ad_fullname != NULL)
+ FREE(ad->ad_fullname, ad->ad_fullnamelen + 1);
+ if (ad->ad_servername != NULL)
+ FREE(ad->ad_servername, ad->ad_servernamelen + 1);
+ return (NULL);
+}
+
+/*
+ * Slightly modified version of authdes_create which takes the public key
+ * of the server principal as an argument. This spares us a call to
+ * getpublickey() which in the nameserver context can cause a deadlock.
+ */
+AUTH *
+authdes_pk_create(servername, pkey, window, timehost, ckey, srvr)
+ char *servername; /* network name of server */
+ netobj *pkey; /* public key of server */
+ u_int window; /* time to live */
+ char *timehost; /* optional hostname to sync with */
+ des_block *ckey; /* optional conversation key to use */
+ nis_server *srvr; /* optional NIS+ server struct */
+{
+ AUTH *auth;
+ struct ad_private *ad;
+ char namebuf[MAXNETNAMELEN+1];
+
+ /*
+ * Allocate everything now
+ */
+ auth = ALLOC(AUTH);
+ if (auth == NULL) {
+ debug("authdes_pk_create: out of memory");
+ return (NULL);
+ }
+ ad = ALLOC(struct ad_private);
+ if (ad == NULL) {
+ debug("authdes_pk_create: out of memory");
+ goto failed;
+ }
+ ad->ad_fullname = ad->ad_servername = NULL; /* Sanity reasons */
+ ad->ad_timehost = NULL;
+ ad->ad_netid = NULL;
+ ad->ad_uaddr = NULL;
+ ad->ad_nis_srvr = NULL;
+ ad->ad_timediff.tv_sec = 0;
+ ad->ad_timediff.tv_usec = 0;
+ memcpy(ad->ad_pkey, pkey->n_bytes, pkey->n_len);
+ if (!getnetname(namebuf))
+ goto failed;
+ ad->ad_fullnamelen = RNDUP((u_int) strlen(namebuf));
+ ad->ad_fullname = (char *)mem_alloc(ad->ad_fullnamelen + 1);
+ ad->ad_servernamelen = strlen(servername);
+ ad->ad_servername = (char *)mem_alloc(ad->ad_servernamelen + 1);
+
+ if (ad->ad_fullname == NULL || ad->ad_servername == NULL) {
+ debug("authdes_pk_create: out of memory");
+ goto failed;
+ }
+ if (timehost != NULL) {
+ ad->ad_timehost = (char *)mem_alloc(strlen(timehost) + 1);
+ if (ad->ad_timehost == NULL) {
+ debug("authdes_pk_create: out of memory");
+ goto failed;
+ }
+ memcpy(ad->ad_timehost, timehost, strlen(timehost) + 1);
+ ad->ad_dosync = TRUE;
+ } else if (srvr != NULL) {
+ ad->ad_nis_srvr = srvr; /* transient */
+ ad->ad_dosync = TRUE;
+ } else {
+ ad->ad_dosync = FALSE;
+ }
+ memcpy(ad->ad_fullname, namebuf, ad->ad_fullnamelen + 1);
+ memcpy(ad->ad_servername, servername, ad->ad_servernamelen + 1);
+ ad->ad_window = window;
+ if (ckey == NULL) {
+ if (key_gendes(&auth->ah_key) < 0) {
+ debug("authdes_pk_create: unable to gen conversation key");
+ goto failed;
+ }
+ } else {
+ auth->ah_key = *ckey;
+ }
+
+ /*
+ * Set up auth handle
+ */
+ auth->ah_cred.oa_flavor = AUTH_DES;
+ auth->ah_verf.oa_flavor = AUTH_DES;
+ auth->ah_ops = &authdes_ops;
+ auth->ah_private = (caddr_t)ad;
+
+ if (!authdes_refresh(auth)) {
+ goto failed;
+ }
+ ad->ad_nis_srvr = NULL; /* not needed any longer */
+ return (auth);
+
+failed:
+ if (auth)
+ FREE(auth, sizeof (AUTH));
+ if (ad) {
+ if (ad->ad_fullname)
+ FREE(ad->ad_fullname, ad->ad_fullnamelen + 1);
+ if (ad->ad_servername)
+ FREE(ad->ad_servername, ad->ad_servernamelen + 1);
+ if (ad->ad_timehost)
+ FREE(ad->ad_timehost, strlen(ad->ad_timehost) + 1);
+ if (ad->ad_netid)
+ free(ad->ad_netid);
+ if (ad->ad_uaddr)
+ free(ad->ad_uaddr);
+ FREE(ad, sizeof (struct ad_private));
+ }
+ return (NULL);
+}
+/*
+ * Implement the five authentication operations
+ */
+
+
+/*
+ * 1. Next Verifier
+ */
+/*ARGSUSED*/
+static void
+authdes_nextverf(auth)
+ AUTH *auth;
+{
+ /* what the heck am I supposed to do??? */
+}
+
+
+
+/*
+ * 2. Marshal
+ */
+static bool_t
+authdes_marshal(auth, xdrs)
+ AUTH *auth;
+ XDR *xdrs;
+{
+ struct ad_private *ad = AUTH_PRIVATE(auth);
+ struct authdes_cred *cred = &ad->ad_cred;
+ struct authdes_verf *verf = &ad->ad_verf;
+ des_block cryptbuf[2];
+ des_block ivec;
+ int status;
+ long len;
+ int32_t *ixdr;
+
+ /*
+ * Figure out the "time", accounting for any time difference
+ * with the server if necessary.
+ */
+ (void) gettimeofday(&ad->ad_timestamp, (struct timezone *)NULL);
+ ad->ad_timestamp.tv_sec += ad->ad_timediff.tv_sec;
+ ad->ad_timestamp.tv_usec += ad->ad_timediff.tv_usec;
+ if (ad->ad_timestamp.tv_usec >= MILLION) {
+ ad->ad_timestamp.tv_usec -= MILLION;
+ ad->ad_timestamp.tv_sec += 1;
+ }
+
+ /*
+ * XDR the timestamp and possibly some other things, then
+ * encrypt them.
+ */
+ ixdr = (int32_t *)cryptbuf;
+ IXDR_PUT_LONG(ixdr, ad->ad_timestamp.tv_sec);
+ IXDR_PUT_LONG(ixdr, ad->ad_timestamp.tv_usec);
+ if (ad->ad_cred.adc_namekind == ADN_FULLNAME) {
+ IXDR_PUT_U_LONG(ixdr, ad->ad_window);
+ IXDR_PUT_U_LONG(ixdr, ad->ad_window - 1);
+ ivec.key.high = ivec.key.low = 0;
+ status = cbc_crypt((char *)&auth->ah_key, (char *)cryptbuf,
+ 2*sizeof(des_block), DES_ENCRYPT | DES_HW, (char *)&ivec);
+ } else {
+ status = ecb_crypt((char *)&auth->ah_key, (char *)cryptbuf,
+ sizeof(des_block), DES_ENCRYPT | DES_HW);
+ }
+ if (DES_FAILED(status)) {
+ debug("authdes_marshal: DES encryption failure");
+ return (FALSE);
+ }
+ ad->ad_verf.adv_xtimestamp = cryptbuf[0];
+ if (ad->ad_cred.adc_namekind == ADN_FULLNAME) {
+ ad->ad_cred.adc_fullname.window = cryptbuf[1].key.high;
+ ad->ad_verf.adv_winverf = cryptbuf[1].key.low;
+ } else {
+ ad->ad_cred.adc_nickname = ad->ad_nickname;
+ ad->ad_verf.adv_winverf = 0;
+ }
+
+ /*
+ * Serialize the credential and verifier into opaque
+ * authentication data.
+ */
+ if (ad->ad_cred.adc_namekind == ADN_FULLNAME) {
+ len = ((1 + 1 + 2 + 1)*BYTES_PER_XDR_UNIT + ad->ad_fullnamelen);
+ } else {
+ len = (1 + 1)*BYTES_PER_XDR_UNIT;
+ }
+
+ if ((ixdr = xdr_inline(xdrs, 2*BYTES_PER_XDR_UNIT))) {
+ IXDR_PUT_LONG(ixdr, AUTH_DES);
+ IXDR_PUT_LONG(ixdr, len);
+ } else {
+ ATTEMPT(xdr_putlong(xdrs, (long *)&auth->ah_cred.oa_flavor));
+ ATTEMPT(xdr_putlong(xdrs, &len));
+ }
+ ATTEMPT(xdr_authdes_cred(xdrs, cred));
+
+ len = (2 + 1)*BYTES_PER_XDR_UNIT;
+ if ((ixdr = xdr_inline(xdrs, 2*BYTES_PER_XDR_UNIT))) {
+ IXDR_PUT_LONG(ixdr, AUTH_DES);
+ IXDR_PUT_LONG(ixdr, len);
+ } else {
+ ATTEMPT(xdr_putlong(xdrs, (long *)&auth->ah_verf.oa_flavor));
+ ATTEMPT(xdr_putlong(xdrs, &len));
+ }
+ ATTEMPT(xdr_authdes_verf(xdrs, verf));
+ return (TRUE);
+}
+
+
+/*
+ * 3. Validate
+ */
+static bool_t
+authdes_validate(auth, rverf)
+ AUTH *auth;
+ struct opaque_auth *rverf;
+{
+ struct ad_private *ad = AUTH_PRIVATE(auth);
+ struct authdes_verf verf;
+ int status;
+ register u_long *ixdr;
+
+ if (rverf->oa_length != (2 + 1) * BYTES_PER_XDR_UNIT) {
+ return (FALSE);
+ }
+ ixdr = (u_long *)rverf->oa_base;
+ verf.adv_xtimestamp.key.high = (u_long)*ixdr++;
+ verf.adv_xtimestamp.key.low = (u_long)*ixdr++;
+ verf.adv_int_u = (u_long)*ixdr++; /* nickname not XDR'd ! */
+
+ /*
+ * Decrypt the timestamp
+ */
+ status = ecb_crypt((char *)&auth->ah_key, (char *)&verf.adv_xtimestamp,
+ sizeof(des_block), DES_DECRYPT | DES_HW);
+
+ if (DES_FAILED(status)) {
+ debug("authdes_validate: DES decryption failure");
+ return (FALSE);
+ }
+
+ /*
+ * xdr the decrypted timestamp
+ */
+ ixdr = (u_long *)verf.adv_xtimestamp.c;
+ verf.adv_timestamp.tv_sec = IXDR_GET_LONG(ixdr) + 1;
+ verf.adv_timestamp.tv_usec = IXDR_GET_LONG(ixdr);
+
+ /*
+ * validate
+ */
+ if (bcmp((char *)&ad->ad_timestamp, (char *)&verf.adv_timestamp,
+ sizeof(struct timeval)) != 0) {
+ debug("authdes_validate: verifier mismatch\n");
+ return (FALSE);
+ }
+
+ /*
+ * We have a nickname now, let's use it
+ */
+ ad->ad_nickname = verf.adv_nickname;
+ ad->ad_cred.adc_namekind = ADN_NICKNAME;
+ return (TRUE);
+}
+
+/*
+ * 4. Refresh
+ */
+static bool_t
+authdes_refresh(auth)
+ AUTH *auth;
+{
+ struct ad_private *ad = AUTH_PRIVATE(auth);
+ struct authdes_cred *cred = &ad->ad_cred;
+ netobj pkey;
+
+ if (ad->ad_dosync &&
+#ifdef old
+ !synchronize(&ad->ad_syncaddr, &ad->ad_timediff)) {
+#else
+ !__rpc_get_time_offset(&ad->ad_timediff,ad->ad_nis_srvr,
+ ad->ad_timehost, &(ad->ad_uaddr),
+ (struct sockaddr_in *)&(ad->ad_syncaddr))) {
+#endif
+ /*
+ * Hope the clocks are synced!
+ */
+ ad->ad_timediff.tv_sec = ad->ad_timediff.tv_usec = 0;
+ ad->ad_dosync = 0;
+ debug("authdes_refresh: unable to synchronize with server");
+ }
+ ad->ad_xkey = auth->ah_key;
+ pkey.n_bytes = (char *)(ad->ad_pkey);
+ pkey.n_len = strlen((char *)ad->ad_pkey) + 1;
+ if (key_encryptsession_pk(ad->ad_servername, &pkey, &ad->ad_xkey) < 0) {
+ debug("authdes_create: unable to encrypt conversation key");
+ return (FALSE);
+ }
+ cred->adc_fullname.key = ad->ad_xkey;
+ cred->adc_namekind = ADN_FULLNAME;
+ cred->adc_fullname.name = ad->ad_fullname;
+ return (TRUE);
+}
+
+
+/*
+ * 5. Destroy
+ */
+static void
+authdes_destroy(auth)
+ AUTH *auth;
+{
+ struct ad_private *ad = AUTH_PRIVATE(auth);
+
+ FREE(ad->ad_fullname, ad->ad_fullnamelen + 1);
+ FREE(ad->ad_servername, ad->ad_servernamelen + 1);
+ FREE(ad, sizeof(struct ad_private));
+ FREE(auth, sizeof(AUTH));
+}
+
+
+#ifdef old
+/*
+ * Synchronize with the server at the given address, that is,
+ * adjust timep to reflect the delta between our clocks
+ */
+static bool_t
+synchronize(syncaddr, timep)
+ struct sockaddr *syncaddr;
+ struct timeval *timep;
+{
+ struct timeval mytime;
+ struct timeval timeout;
+
+ timeout.tv_sec = RTIME_TIMEOUT;
+ timeout.tv_usec = 0;
+ if (rtime((struct sockaddr_in *)syncaddr, timep, NULL /*&timeout*/) < 0) {
+ return (FALSE);
+ }
+ (void) gettimeofday(&mytime, (struct timezone *)NULL);
+ timep->tv_sec -= mytime.tv_sec;
+ if (mytime.tv_usec > timep->tv_usec) {
+ timep->tv_sec -= 1;
+ timep->tv_usec += MILLION;
+ }
+ timep->tv_usec -= mytime.tv_usec;
+ return (TRUE);
+}
+#endif
diff --git a/lib/libc/rpc/auth_none.c b/lib/libc/rpc/auth_none.c
new file mode 100644
index 0000000..b2e2995
--- /dev/null
+++ b/lib/libc/rpc/auth_none.c
@@ -0,0 +1,136 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: auth_none.c,v 1.5 1996/12/30 14:13:30 peter Exp $";
+#endif
+
+/*
+ * auth_none.c
+ * Creates a client authentication handle for passing "null"
+ * credentials and verifiers to remote systems.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <stdlib.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#define MAX_MARSHEL_SIZE 20
+
+/*
+ * Authenticator operations routines
+ */
+static void authnone_verf();
+static void authnone_destroy();
+static bool_t authnone_marshal();
+static bool_t authnone_validate();
+static bool_t authnone_refresh();
+
+static struct auth_ops ops = {
+ authnone_verf,
+ authnone_marshal,
+ authnone_validate,
+ authnone_refresh,
+ authnone_destroy
+};
+
+static struct authnone_private {
+ AUTH no_client;
+ char marshalled_client[MAX_MARSHEL_SIZE];
+ u_int mcnt;
+} *authnone_private;
+
+AUTH *
+authnone_create()
+{
+ register struct authnone_private *ap = authnone_private;
+ XDR xdr_stream;
+ register XDR *xdrs;
+
+ if (ap == 0) {
+ ap = (struct authnone_private *)calloc(1, sizeof (*ap));
+ if (ap == 0)
+ return (0);
+ authnone_private = ap;
+ }
+ if (!ap->mcnt) {
+ ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
+ ap->no_client.ah_ops = &ops;
+ xdrs = &xdr_stream;
+ xdrmem_create(xdrs, ap->marshalled_client, (u_int)MAX_MARSHEL_SIZE,
+ XDR_ENCODE);
+ (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
+ (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
+ ap->mcnt = XDR_GETPOS(xdrs);
+ XDR_DESTROY(xdrs);
+ }
+ return (&ap->no_client);
+}
+
+/*ARGSUSED*/
+static bool_t
+authnone_marshal(client, xdrs)
+ AUTH *client;
+ XDR *xdrs;
+{
+ register struct authnone_private *ap = authnone_private;
+
+ if (ap == 0)
+ return (0);
+ return ((*xdrs->x_ops->x_putbytes)(xdrs,
+ ap->marshalled_client, ap->mcnt));
+}
+
+static void
+authnone_verf()
+{
+}
+
+static bool_t
+authnone_validate()
+{
+
+ return (TRUE);
+}
+
+static bool_t
+authnone_refresh()
+{
+
+ return (FALSE);
+}
+
+static void
+authnone_destroy()
+{
+}
diff --git a/lib/libc/rpc/auth_time.c b/lib/libc/rpc/auth_time.c
new file mode 100644
index 0000000..3128e6d
--- /dev/null
+++ b/lib/libc/rpc/auth_time.c
@@ -0,0 +1,501 @@
+#pragma ident "@(#)auth_time.c 1.4 92/11/10 SMI"
+
+/*
+ * auth_time.c
+ *
+ * This module contains the private function __rpc_get_time_offset()
+ * which will return the difference in seconds between the local system's
+ * notion of time and a remote server's notion of time. This must be
+ * possible without calling any functions that may invoke the name
+ * service. (netdir_getbyxxx, getXbyY, etc). The function is used in the
+ * synchronize call of the authdes code to synchronize clocks between
+ * NIS+ clients and their servers.
+ *
+ * Note to minimize the amount of duplicate code, portions of the
+ * synchronize() function were folded into this code, and the synchronize
+ * call becomes simply a wrapper around this function. Further, if this
+ * function is called with a timehost it *DOES* recurse to the name
+ * server so don't use it in that mode if you are doing name service code.
+ *
+ * Copyright (c) 1992 Sun Microsystems Inc.
+ * All rights reserved.
+ *
+ * Side effects :
+ * When called a client handle to a RPCBIND process is created
+ * and destroyed. Two strings "netid" and "uaddr" are malloc'd
+ * and returned. The SIGALRM processing is modified only if
+ * needed to deal with TCP connections.
+ *
+ * NOTE: This code has had the crap beaten out it in order to convert
+ * it from TI-RPC back to TD-RPC for use on FreeBSD.
+ */
+#include <stdio.h>
+#include <syslog.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <sys/signal.h>
+#include <sys/errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <rpc/rpc.h>
+#include <rpc/rpc_com.h>
+#undef NIS
+#include <rpcsvc/nis.h>
+
+/*
+ * FreeBSD currently uses RPC 4.0, which uses portmap rather than
+ * rpcbind. Consequently, we need to fake up these values here.
+ * Luckily, the RPCB_GETTIME procedure uses only base XDR data types
+ * so we don't need anything besides these magic numbers.
+ */
+#define RPCBPROG (u_long)100000
+#define RPCBVERS (u_long)3
+#define RPCBPROC_GETTIME (u_long)6
+
+#ifdef TESTING
+#define msg(x) printf("ERROR: %s\n", x)
+/* #define msg(x) syslog(LOG_ERR, "%s", x) */
+#else
+#define msg(x)
+#endif
+
+static int saw_alarm = 0;
+
+static void
+alarm_hndler(s)
+ int s;
+{
+ saw_alarm = 1;
+ return;
+}
+
+/*
+ * The internet time server defines the epoch to be Jan 1, 1900
+ * whereas UNIX defines it to be Jan 1, 1970. To adjust the result
+ * from internet time-service time, into UNIX time we subtract the
+ * following offset :
+ */
+#define NYEARS (1970 - 1900)
+#define TOFFSET ((u_long)60*60*24*(365*NYEARS + (NYEARS/4)))
+
+
+/*
+ * Stolen from rpc.nisd:
+ * Turn a 'universal address' into a struct sockaddr_in.
+ * Bletch.
+ */
+static int uaddr_to_sockaddr(uaddr, sin)
+#ifdef foo
+ endpoint *endpt;
+#endif
+ char *uaddr;
+ struct sockaddr_in *sin;
+{
+ unsigned char p_bytes[2];
+ int i;
+ unsigned long a[6];
+
+ i = sscanf(uaddr, "%lu.%lu.%lu.%lu.%lu.%lu", &a[0], &a[1], &a[2],
+ &a[3], &a[4], &a[5]);
+
+ if (i < 6)
+ return(1);
+
+ for (i = 0; i < 4; i++)
+ sin->sin_addr.s_addr |= (a[i] & 0x000000FF) << (8 * i);
+
+ p_bytes[0] = (unsigned char)a[4] & 0x000000FF;
+ p_bytes[1] = (unsigned char)a[5] & 0x000000FF;
+
+ sin->sin_family = AF_INET; /* always */
+ bcopy((char *)&p_bytes, (char *)&sin->sin_port, 2);
+
+ return (0);
+}
+
+/*
+ * free_eps()
+ *
+ * Free the strings that were strduped into the eps structure.
+ */
+static void
+free_eps(eps, num)
+ endpoint eps[];
+ int num;
+{
+ int i;
+
+ for (i = 0; i < num; i++) {
+ free(eps[i].uaddr);
+ free(eps[i].proto);
+ free(eps[i].family);
+ }
+ return;
+}
+
+/*
+ * get_server()
+ *
+ * This function constructs a nis_server structure description for the
+ * indicated hostname.
+ *
+ * NOTE: There is a chance we may end up recursing here due to the
+ * fact that gethostbyname() could do an NIS search. Ideally, the
+ * NIS+ server will call __rpc_get_time_offset() with the nis_server
+ * structure already populated.
+ */
+static nis_server *
+get_server(sin, host, srv, eps, maxep)
+ struct sockaddr_in *sin;
+ char *host; /* name of the time host */
+ nis_server *srv; /* nis_server struct to use. */
+ endpoint eps[]; /* array of endpoints */
+ int maxep; /* max array size */
+{
+ char hname[256];
+ int num_ep = 0, i;
+ struct hostent *he;
+ struct hostent dummy;
+ char *ptr[2];
+
+ if (host == NULL && sin == NULL)
+ return (NULL);
+
+ if (sin == NULL) {
+ he = gethostbyname(host);
+ if (he == NULL)
+ return(NULL);
+ } else {
+ he = &dummy;
+ ptr[0] = (char *)&sin->sin_addr.s_addr;
+ ptr[1] = NULL;
+ dummy.h_addr_list = ptr;
+ }
+
+ /*
+ * This is lame. We go around once for TCP, then again
+ * for UDP.
+ */
+ for (i = 0; (he->h_addr_list[i] != NULL) && (num_ep < maxep);
+ i++, num_ep++) {
+ struct in_addr *a;
+
+ a = (struct in_addr *)he->h_addr_list[i];
+ snprintf(hname, sizeof(hname), "%s.0.111", inet_ntoa(*a));
+ eps[num_ep].uaddr = strdup(hname);
+ eps[num_ep].family = strdup("inet");
+ eps[num_ep].proto = strdup("tcp");
+ }
+
+ for (i = 0; (he->h_addr_list[i] != NULL) && (num_ep < maxep);
+ i++, num_ep++) {
+ struct in_addr *a;
+
+ a = (struct in_addr *)he->h_addr_list[i];
+ snprintf(hname, sizeof(hname), "%s.0.111", inet_ntoa(*a));
+ eps[num_ep].uaddr = strdup(hname);
+ eps[num_ep].family = strdup("inet");
+ eps[num_ep].proto = strdup("udp");
+ }
+
+ srv->name = (nis_name) host;
+ srv->ep.ep_len = num_ep;
+ srv->ep.ep_val = eps;
+ srv->key_type = NIS_PK_NONE;
+ srv->pkey.n_bytes = NULL;
+ srv->pkey.n_len = 0;
+ return (srv);
+}
+
+/*
+ * __rpc_get_time_offset()
+ *
+ * This function uses a nis_server structure to contact the a remote
+ * machine (as named in that structure) and returns the offset in time
+ * between that machine and this one. This offset is returned in seconds
+ * and may be positive or negative.
+ *
+ * The first time through, a lot of fiddling is done with the netconfig
+ * stuff to find a suitable transport. The function is very aggressive
+ * about choosing UDP or at worst TCP if it can. This is because
+ * those transports support both the RCPBIND call and the internet
+ * time service.
+ *
+ * Once through, *uaddr is set to the universal address of
+ * the machine and *netid is set to the local netid for the transport
+ * that uaddr goes with. On the second call, the netconfig stuff
+ * is skipped and the uaddr/netid pair are used to fetch the netconfig
+ * structure and to then contact the machine for the time.
+ *
+ * td = "server" - "client"
+ */
+int
+__rpc_get_time_offset(td, srv, thost, uaddr, netid)
+ struct timeval *td; /* Time difference */
+ nis_server *srv; /* NIS Server description */
+ char *thost; /* if no server, this is the timehost */
+ char **uaddr; /* known universal address */
+ struct sockaddr_in *netid; /* known network identifier */
+{
+ CLIENT *clnt; /* Client handle */
+ endpoint *ep, /* useful endpoints */
+ *useep = NULL; /* endpoint of xp */
+ char *useua = NULL; /* uaddr of selected xp */
+ int epl, i; /* counters */
+ enum clnt_stat status; /* result of clnt_call */
+ u_long thetime, delta;
+ int needfree = 0;
+ struct timeval tv;
+ int time_valid;
+ int udp_ep = -1, tcp_ep = -1;
+ int a1, a2, a3, a4;
+ char ut[64], ipuaddr[64];
+ endpoint teps[32];
+ nis_server tsrv;
+ void (*oldsig)() = NULL; /* old alarm handler */
+ struct sockaddr_in sin;
+ int s = RPC_ANYSOCK, len;
+ int type = 0;
+
+ td->tv_sec = 0;
+ td->tv_usec = 0;
+
+ /*
+ * First check to see if we need to find and address for this
+ * server.
+ */
+ if (*uaddr == NULL) {
+ if ((srv != NULL) && (thost != NULL)) {
+ msg("both timehost and srv pointer used!");
+ return (0);
+ }
+ if (! srv) {
+ srv = get_server(netid, thost, &tsrv, teps, 32);
+ if (srv == NULL) {
+ msg("unable to contruct server data.");
+ return (0);
+ }
+ needfree = 1; /* need to free data in endpoints */
+ }
+
+ ep = srv->ep.ep_val;
+ epl = srv->ep.ep_len;
+
+ /* Identify the TCP and UDP endpoints */
+ for (i = 0;
+ (i < epl) && ((udp_ep == -1) || (tcp_ep == -1)); i++) {
+ if (strcasecmp(ep[i].proto, "udp") == 0)
+ udp_ep = i;
+ if (strcasecmp(ep[i].proto, "tcp") == 0)
+ tcp_ep = i;
+ }
+
+ /* Check to see if it is UDP or TCP */
+ if (tcp_ep > -1) {
+ useep = &ep[tcp_ep];
+ useua = ep[tcp_ep].uaddr;
+ type = SOCK_STREAM;
+ } else if (udp_ep > -1) {
+ useep = &ep[udp_ep];
+ useua = ep[udp_ep].uaddr;
+ type = SOCK_DGRAM;
+ }
+
+ if (useep == NULL) {
+ msg("no acceptable transport endpoints.");
+ if (needfree)
+ free_eps(teps, tsrv.ep.ep_len);
+ return (0);
+ }
+ }
+
+ /*
+ * Create a sockaddr from the uaddr.
+ */
+ if (*uaddr != NULL)
+ useua = *uaddr;
+
+ /* Fixup test for NIS+ */
+ sscanf(useua, "%d.%d.%d.%d.", &a1, &a2, &a3, &a4);
+ sprintf(ipuaddr, "%d.%d.%d.%d.0.111", a1, a2, a3, a4);
+ useua = &ipuaddr[0];
+
+ bzero((char *)&sin, sizeof(sin));
+ if (uaddr_to_sockaddr(useua, &sin)) {
+ msg("unable to translate uaddr to sockaddr.");
+ if (needfree)
+ free_eps(teps, tsrv.ep.ep_len);
+ return (0);
+ }
+
+ /*
+ * Create the client handle to rpcbind. Note we always try
+ * version 3 since that is the earliest version that supports
+ * the RPCB_GETTIME call. Also it is the version that comes
+ * standard with SVR4. Since most everyone supports TCP/IP
+ * we could consider trying the rtime call first.
+ */
+ clnt = clnttcp_create(&sin, RPCBPROG, RPCBVERS, &s, 0, 0);
+ if (clnt == NULL) {
+ msg("unable to create client handle to rpcbind.");
+ if (needfree)
+ free_eps(teps, tsrv.ep.ep_len);
+ return (0);
+ }
+
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+ time_valid = 0;
+ status = clnt_call(clnt, RPCBPROC_GETTIME, xdr_void, NULL,
+ xdr_u_long, (char *)&thetime, tv);
+ /*
+ * The only error we check for is anything but success. In
+ * fact we could have seen PROGMISMATCH if talking to a 4.1
+ * machine (pmap v2) or TIMEDOUT if the net was busy.
+ */
+ if (status == RPC_SUCCESS)
+ time_valid = 1;
+ else {
+ int save;
+
+ /* Blow away possible stale CLNT handle. */
+ if (clnt != NULL) {
+ clnt_destroy(clnt);
+ clnt = NULL;
+ }
+
+ /*
+ * Convert PMAP address into timeservice address
+ * We take advantage of the fact that we "know" what
+ * the universal address looks like for inet transports.
+ *
+ * We also know that the internet timeservice is always
+ * listening on port 37.
+ */
+ sscanf(useua, "%d.%d.%d.%d.", &a1, &a2, &a3, &a4);
+ sprintf(ut, "%d.%d.%d.%d.0.37", a1, a2, a3, a4);
+
+ if (uaddr_to_sockaddr(ut, &sin)) {
+ msg("cannot convert timeservice uaddr to sockaddr.");
+ goto error;
+ }
+
+ s = socket(AF_INET, type, 0);
+ if (s == -1) {
+ msg("unable to open fd to network.");
+ goto error;
+ }
+
+ /*
+ * Now depending on whether or not we're talking to
+ * UDP we set a timeout or not.
+ */
+ if (type == SOCK_DGRAM) {
+ struct timeval timeout = { 20, 0 };
+ struct sockaddr_in from;
+ fd_set readfds;
+ int res;
+
+ if (sendto(s, &thetime, sizeof(thetime), 0,
+ (struct sockaddr *)&sin, sizeof(sin)) == -1) {
+ msg("udp : sendto failed.");
+ goto error;
+ }
+ do {
+ FD_ZERO(&readfds);
+ FD_SET(s, &readfds);
+ res = select(_rpc_dtablesize(), &readfds,
+ (fd_set *)NULL, (fd_set *)NULL, &timeout);
+ } while (res < 0 && errno == EINTR);
+ if (res <= 0)
+ goto error;
+ len = sizeof(from);
+ res = recvfrom(s, (char *)&thetime, sizeof(thetime), 0,
+ (struct sockaddr *)&from, &len);
+ if (res == -1) {
+ msg("recvfrom failed on udp transport.");
+ goto error;
+ }
+ time_valid = 1;
+ } else {
+ int res;
+
+ oldsig = (void (*)())signal(SIGALRM, alarm_hndler);
+ saw_alarm = 0; /* global tracking the alarm */
+ alarm(20); /* only wait 20 seconds */
+ res = connect(s, (struct sockaddr *)&sin, sizeof(sin));
+ if (res == -1) {
+ msg("failed to connect to tcp endpoint.");
+ goto error;
+ }
+ if (saw_alarm) {
+ msg("alarm caught it, must be unreachable.");
+ goto error;
+ }
+ res = read(s, (char *)&thetime, sizeof(thetime));
+ if (res != sizeof(thetime)) {
+ if (saw_alarm)
+ msg("timed out TCP call.");
+ else
+ msg("wrong size of results returned");
+
+ goto error;
+ }
+ time_valid = 1;
+ }
+ save = errno;
+ (void) close(s);
+ errno = save;
+ s = RPC_ANYSOCK;
+
+ if (time_valid) {
+ thetime = ntohl(thetime);
+ thetime = thetime - TOFFSET; /* adjust to UNIX time */
+ } else
+ thetime = 0;
+ }
+
+ gettimeofday(&tv, 0);
+
+error:
+ /*
+ * clean up our allocated data structures.
+ */
+
+ if (s != RPC_ANYSOCK)
+ (void) close(s);
+
+ if (clnt != NULL)
+ clnt_destroy(clnt);
+
+ alarm(0); /* reset that alarm if its outstanding */
+ if (oldsig) {
+ signal(SIGALRM, oldsig);
+ }
+
+ /*
+ * note, don't free uaddr strings until after we've made a
+ * copy of them.
+ */
+ if (time_valid) {
+ if (*uaddr == NULL)
+ *uaddr = strdup(useua);
+
+ /* Round to the nearest second */
+ tv.tv_sec += (tv.tv_sec > 500000) ? 1 : 0;
+ delta = (thetime > tv.tv_sec) ? thetime - tv.tv_sec :
+ tv.tv_sec - thetime;
+ td->tv_sec = (thetime < tv.tv_sec) ? - delta : delta;
+ td->tv_usec = 0;
+ } else {
+ msg("unable to get the server's time.");
+ }
+
+ if (needfree)
+ free_eps(teps, tsrv.ep.ep_len);
+
+ return (time_valid);
+}
diff --git a/lib/libc/rpc/auth_unix.c b/lib/libc/rpc/auth_unix.c
new file mode 100644
index 0000000..32200c2
--- /dev/null
+++ b/lib/libc/rpc/auth_unix.c
@@ -0,0 +1,349 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)auth_unix.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)auth_unix.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: auth_unix.c,v 1.7 1996/12/30 14:14:39 peter Exp $";
+#endif
+
+/*
+ * auth_unix.c, Implements UNIX style authentication parameters.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * The system is very weak. The client uses no encryption for it's
+ * credentials and only sends null verifiers. The server sends backs
+ * null verifiers or optionally a verifier that suggests a new short hand
+ * for the credentials.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/param.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/auth_unix.h>
+
+/*
+ * Unix authenticator operations vector
+ */
+static void authunix_nextverf();
+static bool_t authunix_marshal();
+static bool_t authunix_validate();
+static bool_t authunix_refresh();
+static void authunix_destroy();
+
+static struct auth_ops auth_unix_ops = {
+ authunix_nextverf,
+ authunix_marshal,
+ authunix_validate,
+ authunix_refresh,
+ authunix_destroy
+};
+
+/*
+ * This struct is pointed to by the ah_private field of an auth_handle.
+ */
+struct audata {
+ struct opaque_auth au_origcred; /* original credentials */
+ struct opaque_auth au_shcred; /* short hand cred */
+ u_long au_shfaults; /* short hand cache faults */
+ char au_marshed[MAX_AUTH_BYTES];
+ u_int au_mpos; /* xdr pos at end of marshed */
+};
+#define AUTH_PRIVATE(auth) ((struct audata *)auth->ah_private)
+
+static void marshal_new_auth();
+
+/*
+ * This goop is here because some servers refuse to accept a
+ * credential with more than some number (usually 8) supplementary
+ * groups. Blargh!
+ */
+static int authunix_maxgrouplist = 0;
+
+void
+set_rpc_maxgrouplist(int num)
+{
+ authunix_maxgrouplist = num;
+}
+
+/*
+ * Create a unix style authenticator.
+ * Returns an auth handle with the given stuff in it.
+ */
+AUTH *
+authunix_create(machname, uid, gid, len, aup_gids)
+ char *machname;
+ int uid;
+ int gid;
+ register int len;
+ int *aup_gids;
+{
+ struct authunix_parms aup;
+ char mymem[MAX_AUTH_BYTES];
+ struct timeval now;
+ XDR xdrs;
+ register AUTH *auth;
+ register struct audata *au;
+
+ /*
+ * Allocate and set up auth handle
+ */
+ auth = (AUTH *)mem_alloc(sizeof(*auth));
+#ifndef KERNEL
+ if (auth == NULL) {
+ (void)fprintf(stderr, "authunix_create: out of memory\n");
+ return (NULL);
+ }
+#endif
+ au = (struct audata *)mem_alloc(sizeof(*au));
+#ifndef KERNEL
+ if (au == NULL) {
+ (void)fprintf(stderr, "authunix_create: out of memory\n");
+ return (NULL);
+ }
+#endif
+ auth->ah_ops = &auth_unix_ops;
+ auth->ah_private = (caddr_t)au;
+ auth->ah_verf = au->au_shcred = _null_auth;
+ au->au_shfaults = 0;
+
+ /*
+ * fill in param struct from the given params
+ */
+ (void)gettimeofday(&now, (struct timezone *)0);
+ aup.aup_time = now.tv_sec;
+ aup.aup_machname = machname;
+ aup.aup_uid = uid;
+ aup.aup_gid = gid;
+ /* GW: continuation of max group list hack */
+ if(authunix_maxgrouplist != 0) {
+ aup.aup_len = ((len < authunix_maxgrouplist) ? len
+ : authunix_maxgrouplist);
+ } else {
+ aup.aup_len = (u_int)len;
+ }
+ aup.aup_gids = aup_gids;
+
+ /*
+ * Serialize the parameters into origcred
+ */
+ xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
+ if (! xdr_authunix_parms(&xdrs, &aup))
+ abort();
+ au->au_origcred.oa_length = len = XDR_GETPOS(&xdrs);
+ au->au_origcred.oa_flavor = AUTH_UNIX;
+#ifdef KERNEL
+ au->au_origcred.oa_base = mem_alloc((u_int) len);
+#else
+ if ((au->au_origcred.oa_base = mem_alloc((u_int) len)) == NULL) {
+ (void)fprintf(stderr, "authunix_create: out of memory\n");
+ return (NULL);
+ }
+#endif
+ memcpy(au->au_origcred.oa_base, mymem, (u_int)len);
+
+ /*
+ * set auth handle to reflect new cred.
+ */
+ auth->ah_cred = au->au_origcred;
+ marshal_new_auth(auth);
+ return (auth);
+}
+
+/*
+ * Returns an auth handle with parameters determined by doing lots of
+ * syscalls.
+ */
+AUTH *
+authunix_create_default()
+{
+ register int len;
+ char machname[MAX_MACHINE_NAME + 1];
+ register int uid;
+ register int gid;
+ int gids[NGRPS];
+ int i;
+ gid_t real_gids[NGROUPS];
+
+ if (gethostname(machname, MAX_MACHINE_NAME) == -1)
+ abort();
+ machname[MAX_MACHINE_NAME] = 0;
+ uid = (int)geteuid();
+ gid = (int)getegid();
+ if ((len = getgroups(NGROUPS, real_gids)) < 0)
+ abort();
+ if(len > NGRPS) len = NGRPS; /* GW: turn `gid_t's into `int's */
+ for(i = 0; i < len; i++) {
+ gids[i] = (int)real_gids[i];
+ }
+ return (authunix_create(machname, uid, gid, len, gids));
+}
+
+/*
+ * authunix operations
+ */
+
+static void
+authunix_nextverf(auth)
+ AUTH *auth;
+{
+ /* no action necessary */
+}
+
+static bool_t
+authunix_marshal(auth, xdrs)
+ AUTH *auth;
+ XDR *xdrs;
+{
+ register struct audata *au = AUTH_PRIVATE(auth);
+
+ return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
+}
+
+static bool_t
+authunix_validate(auth, verf)
+ register AUTH *auth;
+ struct opaque_auth verf;
+{
+ register struct audata *au;
+ XDR xdrs;
+
+ if (verf.oa_flavor == AUTH_SHORT) {
+ au = AUTH_PRIVATE(auth);
+ xdrmem_create(&xdrs, verf.oa_base, verf.oa_length, XDR_DECODE);
+
+ if (au->au_shcred.oa_base != NULL) {
+ mem_free(au->au_shcred.oa_base,
+ au->au_shcred.oa_length);
+ au->au_shcred.oa_base = NULL;
+ }
+ if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
+ auth->ah_cred = au->au_shcred;
+ } else {
+ xdrs.x_op = XDR_FREE;
+ (void)xdr_opaque_auth(&xdrs, &au->au_shcred);
+ au->au_shcred.oa_base = NULL;
+ auth->ah_cred = au->au_origcred;
+ }
+ marshal_new_auth(auth);
+ }
+ return (TRUE);
+}
+
+static bool_t
+authunix_refresh(auth)
+ register AUTH *auth;
+{
+ register struct audata *au = AUTH_PRIVATE(auth);
+ struct authunix_parms aup;
+ struct timeval now;
+ XDR xdrs;
+ register int stat;
+
+ if (auth->ah_cred.oa_base == au->au_origcred.oa_base) {
+ /* there is no hope. Punt */
+ return (FALSE);
+ }
+ au->au_shfaults ++;
+
+ /* first deserialize the creds back into a struct authunix_parms */
+ aup.aup_machname = NULL;
+ aup.aup_gids = (int *)NULL;
+ xdrmem_create(&xdrs, au->au_origcred.oa_base,
+ au->au_origcred.oa_length, XDR_DECODE);
+ stat = xdr_authunix_parms(&xdrs, &aup);
+ if (! stat)
+ goto done;
+
+ /* update the time and serialize in place */
+ (void)gettimeofday(&now, (struct timezone *)0);
+ aup.aup_time = now.tv_sec;
+ xdrs.x_op = XDR_ENCODE;
+ XDR_SETPOS(&xdrs, 0);
+ stat = xdr_authunix_parms(&xdrs, &aup);
+ if (! stat)
+ goto done;
+ auth->ah_cred = au->au_origcred;
+ marshal_new_auth(auth);
+done:
+ /* free the struct authunix_parms created by deserializing */
+ xdrs.x_op = XDR_FREE;
+ (void)xdr_authunix_parms(&xdrs, &aup);
+ XDR_DESTROY(&xdrs);
+ return (stat);
+}
+
+static void
+authunix_destroy(auth)
+ register AUTH *auth;
+{
+ register struct audata *au = AUTH_PRIVATE(auth);
+
+ mem_free(au->au_origcred.oa_base, au->au_origcred.oa_length);
+
+ if (au->au_shcred.oa_base != NULL)
+ mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
+
+ mem_free(auth->ah_private, sizeof(struct audata));
+
+ if (auth->ah_verf.oa_base != NULL)
+ mem_free(auth->ah_verf.oa_base, auth->ah_verf.oa_length);
+
+ mem_free((caddr_t)auth, sizeof(*auth));
+}
+
+/*
+ * Marshals (pre-serializes) an auth struct.
+ * sets private data, au_marshed and au_mpos
+ */
+static void
+marshal_new_auth(auth)
+ register AUTH *auth;
+{
+ XDR xdr_stream;
+ register XDR *xdrs = &xdr_stream;
+ register struct audata *au = AUTH_PRIVATE(auth);
+
+ xdrmem_create(xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
+ if ((! xdr_opaque_auth(xdrs, &(auth->ah_cred))) ||
+ (! xdr_opaque_auth(xdrs, &(auth->ah_verf)))) {
+ perror("auth_none.c - Fatal marshalling problem");
+ } else {
+ au->au_mpos = XDR_GETPOS(xdrs);
+ }
+ XDR_DESTROY(xdrs);
+}
diff --git a/lib/libc/rpc/authdes_prot.c b/lib/libc/rpc/authdes_prot.c
new file mode 100644
index 0000000..14679c0
--- /dev/null
+++ b/lib/libc/rpc/authdes_prot.c
@@ -0,0 +1,82 @@
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)authdes_prot.c 2.1 88/07/29 4.0 RPCSRC; from 1.6 88/02/08 SMI";
+#endif
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+/*
+ * Copyright (c) 1988 by Sun Microsystems, Inc.
+ */
+
+/*
+ * authdes_prot.c, XDR routines for DES authentication
+ */
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/auth_des.h>
+
+#define ATTEMPT(xdr_op) if (!(xdr_op)) return (FALSE)
+
+bool_t
+xdr_authdes_cred(xdrs, cred)
+ XDR *xdrs;
+ struct authdes_cred *cred;
+{
+ /*
+ * Unrolled xdr
+ */
+ ATTEMPT(xdr_enum(xdrs, (enum_t *)&cred->adc_namekind));
+ switch (cred->adc_namekind) {
+ case ADN_FULLNAME:
+ ATTEMPT(xdr_string(xdrs, &cred->adc_fullname.name, MAXNETNAMELEN));
+ ATTEMPT(xdr_opaque(xdrs, (caddr_t)&cred->adc_fullname.key, sizeof(des_block)));
+ ATTEMPT(xdr_opaque(xdrs, (caddr_t)&cred->adc_fullname.window, sizeof(cred->adc_fullname.window)));
+ return (TRUE);
+ case ADN_NICKNAME:
+ ATTEMPT(xdr_opaque(xdrs, (caddr_t)&cred->adc_nickname, sizeof(cred->adc_nickname)));
+ return (TRUE);
+ default:
+ return (FALSE);
+ }
+}
+
+
+bool_t
+xdr_authdes_verf(xdrs, verf)
+ register XDR *xdrs;
+ register struct authdes_verf *verf;
+{
+ /*
+ * Unrolled xdr
+ */
+ ATTEMPT(xdr_opaque(xdrs, (caddr_t)&verf->adv_xtimestamp, sizeof(des_block)));
+ ATTEMPT(xdr_opaque(xdrs, (caddr_t)&verf->adv_int_u, sizeof(verf->adv_int_u)));
+ return (TRUE);
+}
diff --git a/lib/libc/rpc/authunix_prot.c b/lib/libc/rpc/authunix_prot.c
new file mode 100644
index 0000000..c818ba0
--- /dev/null
+++ b/lib/libc/rpc/authunix_prot.c
@@ -0,0 +1,68 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)authunix_prot.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: authunix_prot.c,v 1.2 1995/05/30 05:41:12 rgrimes Exp $";
+#endif
+
+/*
+ * authunix_prot.c
+ * XDR for UNIX style authentication parameters for RPC
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/auth_unix.h>
+
+/*
+ * XDR for unix authentication parameters.
+ */
+bool_t
+xdr_authunix_parms(xdrs, p)
+ register XDR *xdrs;
+ register struct authunix_parms *p;
+{
+
+ if (xdr_u_long(xdrs, &(p->aup_time))
+ && xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME)
+ && xdr_int(xdrs, &(p->aup_uid))
+ && xdr_int(xdrs, &(p->aup_gid))
+ && xdr_array(xdrs, (caddr_t *)&(p->aup_gids),
+ &(p->aup_len), NGRPS, sizeof(int), xdr_int) ) {
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
diff --git a/lib/libc/rpc/bindresvport.3 b/lib/libc/rpc/bindresvport.3
new file mode 100644
index 0000000..b21d65e
--- /dev/null
+++ b/lib/libc/rpc/bindresvport.3
@@ -0,0 +1,30 @@
+.\" @(#)bindresvport.3n 2.2 88/08/02 4.0 RPCSRC; from 1.7 88/03/14 SMI
+.Dd November 22, 1987
+.Dt BINDRESVPORT 3
+.Os
+.Sh NAME
+.Nm bindresvport
+.Ndbind a socket to a privileged IP port
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <netinet/in.h>
+.Ft int
+.Fn bindresvport "int sd" "struct sockaddr_in **sin"
+.Sh DESCRIPTION
+.Nm Bindresvport
+is used to bind a socket descriptor to a privileged
+.Tn IP
+port, that is, a
+port number in the range 0-1023.
+The routine returns 0 if it is successful,
+otherwise -1 is returned and
+.Va errno
+set to reflect the cause of the error.
+.Pp
+Only root can bind to a privileged port; this call will fail for any
+other users.
+.Pp
+If the value of sin->sin_port is non-zero
+.Fn bindresvport
+will attempt to use that specific port. If it fails, it chooses another
+privileged port automatically.
diff --git a/lib/libc/rpc/bindresvport.c b/lib/libc/rpc/bindresvport.c
new file mode 100644
index 0000000..dea8705
--- /dev/null
+++ b/lib/libc/rpc/bindresvport.c
@@ -0,0 +1,107 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)bindresvport.c 1.8 88/02/08 SMI";*/
+/*static char *sccsid = "from: @(#)bindresvport.c 2.2 88/07/29 4.0 RPCSRC";*/
+/*from: OpenBSD: bindresvport.c,v 1.7 1996/07/30 16:25:47 downsj Exp */
+static char *rcsid = "$Id: bindresvport.c,v 1.6 1996/12/30 14:12:36 peter Exp $";
+#endif
+
+/*
+ * Copyright (c) 1987 by Sun Microsystems, Inc.
+ *
+ * Portions Copyright(C) 1996, Jason Downs. All rights reserved.
+ */
+
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <string.h>
+
+/*
+ * Bind a socket to a privileged IP port
+ */
+int
+bindresvport(sd, sin)
+ int sd;
+ struct sockaddr_in *sin;
+{
+ int on, old, error;
+ struct sockaddr_in myaddr;
+ int sinlen = sizeof(struct sockaddr_in);
+
+ if (sin == (struct sockaddr_in *)0) {
+ sin = &myaddr;
+ memset(sin, 0, sinlen);
+ sin->sin_len = sinlen;
+ sin->sin_family = AF_INET;
+ } else if (sin->sin_family != AF_INET) {
+ errno = EPFNOSUPPORT;
+ return (-1);
+ }
+
+ if (sin->sin_port == 0) {
+ int oldlen = sizeof(old);
+ error = getsockopt(sd, IPPROTO_IP, IP_PORTRANGE,
+ &old, &oldlen);
+ if (error < 0)
+ return(error);
+
+ on = IP_PORTRANGE_LOW;
+ error = setsockopt(sd, IPPROTO_IP, IP_PORTRANGE,
+ &on, sizeof(on));
+ if (error < 0)
+ return(error);
+ }
+
+ error = bind(sd, (struct sockaddr *)sin, sinlen);
+
+ if (sin->sin_port == 0) {
+ int saved_errno = errno;
+
+ if (error) {
+ if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE,
+ &old, sizeof(old)) < 0)
+ errno = saved_errno;
+ return (error);
+ }
+
+ if (sin != &myaddr) {
+ /* Hmm, what did the kernel assign... */
+ if (getsockname(sd, (struct sockaddr *)sin,
+ &sinlen) < 0)
+ errno = saved_errno;
+ return (error);
+ }
+ }
+ return (error);
+}
diff --git a/lib/libc/rpc/clnt_generic.c b/lib/libc/rpc/clnt_generic.c
new file mode 100644
index 0000000..ed754ea
--- /dev/null
+++ b/lib/libc/rpc/clnt_generic.c
@@ -0,0 +1,137 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";*/
+/*static char *sccsid = "from: @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: clnt_generic.c,v 1.5 1996/12/30 14:17:20 peter Exp $";
+#endif
+
+/*
+ * Copyright (C) 1987, Sun Microsystems, Inc.
+ */
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <sys/errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/*
+ * Generic client creation: takes (hostname, program-number, protocol) and
+ * returns client handle. Default options are set, which the user can
+ * change using the rpc equivalent of ioctl()'s.
+ */
+CLIENT *
+clnt_create(hostname, prog, vers, proto)
+ char *hostname;
+ u_long prog;
+ u_long vers;
+ char *proto;
+{
+ struct hostent *h;
+ struct protoent *p;
+ struct sockaddr_in sin;
+ struct sockaddr_un sun;
+ int sock;
+ static struct timeval tv;
+ CLIENT *client;
+
+ if (!strcmp(proto, "unix")) {
+ bzero((char *)&sun, sizeof(sun));
+ sun.sun_family = AF_UNIX;
+ strcpy(sun.sun_path, hostname);
+ sun.sun_len = sizeof(sun.sun_len) + sizeof(sun.sun_family) +
+ strlen(sun.sun_path) + 1;
+ sock = RPC_ANYSOCK;
+ client = clntunix_create(&sun, prog, vers, &sock, 0, 0);
+ if (client == NULL)
+ return(NULL);
+ tv.tv_sec = 25;
+ tv.tv_usec = 0;
+ clnt_control(client, CLSET_TIMEOUT, &tv);
+ return(client);
+ }
+
+ h = gethostbyname(hostname);
+ if (h == NULL) {
+ rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
+ return (NULL);
+ }
+ if (h->h_addrtype != AF_INET) {
+ /*
+ * Only support INET for now
+ */
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = EAFNOSUPPORT;
+ return (NULL);
+ }
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_len = sizeof(struct sockaddr_in);
+ sin.sin_family = h->h_addrtype;
+ sin.sin_port = 0;
+ memcpy((char*)&sin.sin_addr, h->h_addr, h->h_length);
+ p = getprotobyname(proto);
+ if (p == NULL) {
+ rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
+ rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
+ return (NULL);
+ }
+ sock = RPC_ANYSOCK;
+ switch (p->p_proto) {
+ case IPPROTO_UDP:
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+ client = clntudp_create(&sin, prog, vers, tv, &sock);
+ if (client == NULL) {
+ return (NULL);
+ }
+#if 0 /* XXX do we need this? */
+ tv.tv_sec = 25;
+ tv.tv_usec = 0;
+ clnt_control(client, CLSET_TIMEOUT, &tv);
+#endif
+ break;
+ case IPPROTO_TCP:
+ client = clnttcp_create(&sin, prog, vers, &sock, 0, 0);
+ if (client == NULL) {
+ return (NULL);
+ }
+#if 0 /* XXX do we need this? */
+ tv.tv_sec = 25;
+ tv.tv_usec = 0;
+ clnt_control(client, CLSET_TIMEOUT, &tv);
+#endif
+ break;
+ default:
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
+ return (NULL);
+ }
+ return (client);
+}
diff --git a/lib/libc/rpc/clnt_perror.c b/lib/libc/rpc/clnt_perror.c
new file mode 100644
index 0000000..79baac2
--- /dev/null
+++ b/lib/libc/rpc/clnt_perror.c
@@ -0,0 +1,254 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: clnt_perror.c,v 1.6 1996/12/30 14:19:34 peter Exp $";
+#endif
+
+/*
+ * clnt_perror.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <rpc/types.h>
+#include <rpc/auth.h>
+#include <rpc/clnt.h>
+
+static char *auth_errmsg();
+#define CLNT_PERROR_BUFLEN 256
+
+static char *buf;
+
+static char *
+_buf()
+{
+
+ if (buf == 0)
+ buf = (char *)malloc(CLNT_PERROR_BUFLEN);
+ return (buf);
+}
+
+/*
+ * Print reply error info
+ */
+char *
+clnt_sperror(rpch, s)
+ CLIENT *rpch;
+ char *s;
+{
+ struct rpc_err e;
+ char *err;
+ char *str = _buf();
+ char *strstart = str;
+
+ if (str == 0)
+ return (0);
+ CLNT_GETERR(rpch, &e);
+
+ (void) sprintf(str, "%s: %s", s, clnt_sperrno(e.re_status));
+ str += strlen(str);
+
+ switch (e.re_status) {
+ case RPC_SUCCESS:
+ case RPC_CANTENCODEARGS:
+ case RPC_CANTDECODERES:
+ case RPC_TIMEDOUT:
+ case RPC_PROGUNAVAIL:
+ case RPC_PROCUNAVAIL:
+ case RPC_CANTDECODEARGS:
+ case RPC_SYSTEMERROR:
+ case RPC_UNKNOWNHOST:
+ case RPC_UNKNOWNPROTO:
+ case RPC_PMAPFAILURE:
+ case RPC_PROGNOTREGISTERED:
+ case RPC_FAILED:
+ break;
+
+ case RPC_CANTSEND:
+ case RPC_CANTRECV:
+ (void) snprintf(str, CLNT_PERROR_BUFLEN - (str - strstart),
+ "; errno = %s\n", strerror(e.re_errno));
+ break;
+
+ case RPC_VERSMISMATCH:
+ (void) sprintf(str,
+ "; low version = %lu, high version = %lu\n",
+ e.re_vers.low, e.re_vers.high);
+ break;
+
+ case RPC_AUTHERROR:
+ err = auth_errmsg(e.re_why);
+ (void) sprintf(str,"; why = ");
+ str += strlen(str);
+ if (err != NULL) {
+ (void) sprintf(str, "%s\n",err);
+ } else {
+ (void) sprintf(str,
+ "(unknown authentication error - %d)\n",
+ (int) e.re_why);
+ }
+ break;
+
+ case RPC_PROGVERSMISMATCH:
+ (void) sprintf(str,
+ "; low version = %lu, high version = %lu\n",
+ e.re_vers.low, e.re_vers.high);
+ break;
+
+ default: /* unknown */
+ (void) sprintf(str,
+ "; s1 = %lu, s2 = %lu\n",
+ e.re_lb.s1, e.re_lb.s2);
+ break;
+ }
+ strstart[CLNT_PERROR_BUFLEN-2] = '\n';
+ strstart[CLNT_PERROR_BUFLEN-1] = '\0';
+ return(strstart) ;
+}
+
+void
+clnt_perror(rpch, s)
+ CLIENT *rpch;
+ char *s;
+{
+ (void) fprintf(stderr,"%s\n",clnt_sperror(rpch,s));
+}
+
+
+static const char *const rpc_errlist[] = {
+ "RPC: Success", /* 0 - RPC_SUCCESS */
+ "RPC: Can't encode arguments", /* 1 - RPC_CANTENCODEARGS */
+ "RPC: Can't decode result", /* 2 - RPC_CANTDECODERES */
+ "RPC: Unable to send", /* 3 - RPC_CANTSEND */
+ "RPC: Unable to receive", /* 4 - RPC_CANTRECV */
+ "RPC: Timed out", /* 5 - RPC_TIMEDOUT */
+ "RPC: Incompatible versions of RPC", /* 6 - RPC_VERSMISMATCH */
+ "RPC: Authentication error", /* 7 - RPC_AUTHERROR */
+ "RPC: Program unavailable", /* 8 - RPC_PROGUNAVAIL */
+ "RPC: Program/version mismatch", /* 9 - RPC_PROGVERSMISMATCH */
+ "RPC: Procedure unavailable", /* 10 - RPC_PROCUNAVAIL */
+ "RPC: Server can't decode arguments", /* 11 - RPC_CANTDECODEARGS */
+ "RPC: Remote system error", /* 12 - RPC_SYSTEMERROR */
+ "RPC: Unknown host", /* 13 - RPC_UNKNOWNHOST */
+ "RPC: Port mapper failure", /* 14 - RPC_PMAPFAILURE */
+ "RPC: Program not registered", /* 15 - RPC_PROGNOTREGISTERED */
+ "RPC: Failed (unspecified error)", /* 16 - RPC_FAILED */
+ "RPC: Unknown protocol" /* 17 - RPC_UNKNOWNPROTO */
+};
+
+
+/*
+ * This interface for use by clntrpc
+ */
+char *
+clnt_sperrno(stat)
+ enum clnt_stat stat;
+{
+ unsigned int errnum = stat;
+
+ if (errnum < (sizeof(rpc_errlist)/sizeof(rpc_errlist[0])))
+ return (char *)rpc_errlist[errnum];
+
+ return ("RPC: (unknown error code)");
+}
+
+void
+clnt_perrno(num)
+ enum clnt_stat num;
+{
+ (void) fprintf(stderr,"%s\n",clnt_sperrno(num));
+}
+
+
+char *
+clnt_spcreateerror(s)
+ char *s;
+{
+ char *str = _buf();
+
+ if (str == 0)
+ return(0);
+ switch (rpc_createerr.cf_stat) {
+ case RPC_PMAPFAILURE:
+ (void) snprintf(str, CLNT_PERROR_BUFLEN, "%s: %s - %s\n", s,
+ clnt_sperrno(rpc_createerr.cf_stat),
+ clnt_sperrno(rpc_createerr.cf_error.re_status));
+ break;
+
+ case RPC_SYSTEMERROR:
+ (void) snprintf(str, CLNT_PERROR_BUFLEN, "%s: %s - %s\n", s,
+ clnt_sperrno(rpc_createerr.cf_stat),
+ strerror(rpc_createerr.cf_error.re_errno));
+ break;
+ default:
+ (void) snprintf(str, CLNT_PERROR_BUFLEN, "%s: %s\n", s,
+ clnt_sperrno(rpc_createerr.cf_stat));
+ break;
+ }
+ str[CLNT_PERROR_BUFLEN-2] = '\n';
+ str[CLNT_PERROR_BUFLEN-1] = '\0';
+ return (str);
+}
+
+void
+clnt_pcreateerror(s)
+ char *s;
+{
+ (void) fprintf(stderr,"%s\n",clnt_spcreateerror(s));
+}
+
+static const char *const auth_errlist[] = {
+ "Authentication OK", /* 0 - AUTH_OK */
+ "Invalid client credential", /* 1 - AUTH_BADCRED */
+ "Server rejected credential", /* 2 - AUTH_REJECTEDCRED */
+ "Invalid client verifier", /* 3 - AUTH_BADVERF */
+ "Server rejected verifier", /* 4 - AUTH_REJECTEDVERF */
+ "Client credential too weak", /* 5 - AUTH_TOOWEAK */
+ "Invalid server verifier", /* 6 - AUTH_INVALIDRESP */
+ "Failed (unspecified error)" /* 7 - AUTH_FAILED */
+};
+
+static char *
+auth_errmsg(stat)
+ enum auth_stat stat;
+{
+ unsigned int errnum = stat;
+
+ if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0])))
+ return (char *)auth_errlist[errnum];
+
+ return(NULL);
+}
diff --git a/lib/libc/rpc/clnt_raw.c b/lib/libc/rpc/clnt_raw.c
new file mode 100644
index 0000000..c715ef69
--- /dev/null
+++ b/lib/libc/rpc/clnt_raw.c
@@ -0,0 +1,242 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: clnt_raw.c,v 1.6 1996/12/30 14:21:36 peter Exp $";
+#endif
+
+/*
+ * clnt_raw.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * Memory based rpc for simple testing and timing.
+ * Interface to create an rpc client and server in the same process.
+ * This lets us similate rpc and get round trip overhead, without
+ * any interference from the kernal.
+ */
+
+#include <rpc/rpc.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define MCALL_MSG_SIZE 24
+
+/*
+ * This is the "network" we will be moving stuff over.
+ */
+static struct clntraw_private {
+ CLIENT client_object;
+ XDR xdr_stream;
+ char _raw_buf[UDPMSGSIZE];
+ char mashl_callmsg[MCALL_MSG_SIZE];
+ u_int mcnt;
+} *clntraw_private;
+
+static enum clnt_stat clntraw_call();
+static void clntraw_abort();
+static void clntraw_geterr();
+static bool_t clntraw_freeres();
+static bool_t clntraw_control();
+static void clntraw_destroy();
+
+static struct clnt_ops client_ops = {
+ clntraw_call,
+ clntraw_abort,
+ clntraw_geterr,
+ clntraw_freeres,
+ clntraw_destroy,
+ clntraw_control
+};
+
+void svc_getreq();
+
+/*
+ * Create a client handle for memory based rpc.
+ */
+CLIENT *
+clntraw_create(prog, vers)
+ u_long prog;
+ u_long vers;
+{
+ register struct clntraw_private *clp = clntraw_private;
+ struct rpc_msg call_msg;
+ XDR *xdrs = &clp->xdr_stream;
+ CLIENT *client = &clp->client_object;
+
+ if (clp == 0) {
+ clp = (struct clntraw_private *)calloc(1, sizeof (*clp));
+ if (clp == 0)
+ return (0);
+ clntraw_private = clp;
+ }
+ /*
+ * pre-serialize the static part of the call msg and stash it away
+ */
+ call_msg.rm_direction = CALL;
+ call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ call_msg.rm_call.cb_prog = prog;
+ call_msg.rm_call.cb_vers = vers;
+ xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
+ if (! xdr_callhdr(xdrs, &call_msg)) {
+ perror("clnt_raw.c - Fatal header serialization error.");
+ }
+ clp->mcnt = XDR_GETPOS(xdrs);
+ XDR_DESTROY(xdrs);
+
+ /*
+ * Set xdrmem for client/server shared buffer
+ */
+ xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
+
+ /*
+ * create client handle
+ */
+ client->cl_ops = &client_ops;
+ client->cl_auth = authnone_create();
+ return (client);
+}
+
+static enum clnt_stat
+clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
+ CLIENT *h;
+ u_long proc;
+ xdrproc_t xargs;
+ caddr_t argsp;
+ xdrproc_t xresults;
+ caddr_t resultsp;
+ struct timeval timeout;
+{
+ register struct clntraw_private *clp = clntraw_private;
+ register XDR *xdrs = &clp->xdr_stream;
+ struct rpc_msg msg;
+ enum clnt_stat status;
+ struct rpc_err error;
+
+ if (clp == 0)
+ return (RPC_FAILED);
+call_again:
+ /*
+ * send request
+ */
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, 0);
+ ((struct rpc_msg *)clp->mashl_callmsg)->rm_xid ++ ;
+ if ((! XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
+ (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
+ (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
+ (! (*xargs)(xdrs, argsp))) {
+ return (RPC_CANTENCODEARGS);
+ }
+ (void)XDR_GETPOS(xdrs); /* called just to cause overhead */
+
+ /*
+ * We have to call server input routine here because this is
+ * all going on in one process. Yuk.
+ */
+ svc_getreq(1);
+
+ /*
+ * get results
+ */
+ xdrs->x_op = XDR_DECODE;
+ XDR_SETPOS(xdrs, 0);
+ msg.acpted_rply.ar_verf = _null_auth;
+ msg.acpted_rply.ar_results.where = resultsp;
+ msg.acpted_rply.ar_results.proc = xresults;
+ if (! xdr_replymsg(xdrs, &msg))
+ return (RPC_CANTDECODERES);
+ _seterr_reply(&msg, &error);
+ status = error.re_status;
+
+ if (status == RPC_SUCCESS) {
+ if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
+ status = RPC_AUTHERROR;
+ }
+ } /* end successful completion */
+ else {
+ if (AUTH_REFRESH(h->cl_auth))
+ goto call_again;
+ } /* end of unsuccessful completion */
+
+ if (status == RPC_SUCCESS) {
+ if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
+ status = RPC_AUTHERROR;
+ }
+ if (msg.acpted_rply.ar_verf.oa_base != NULL) {
+ xdrs->x_op = XDR_FREE;
+ (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
+ }
+ }
+
+ return (status);
+}
+
+static void
+clntraw_geterr()
+{
+}
+
+
+static bool_t
+clntraw_freeres(cl, xdr_res, res_ptr)
+ CLIENT *cl;
+ xdrproc_t xdr_res;
+ caddr_t res_ptr;
+{
+ register struct clntraw_private *clp = clntraw_private;
+ register XDR *xdrs = &clp->xdr_stream;
+ bool_t rval;
+
+ if (clp == 0)
+ {
+ rval = (bool_t) RPC_FAILED;
+ return (rval);
+ }
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_res)(xdrs, res_ptr));
+}
+
+static void
+clntraw_abort()
+{
+}
+
+static bool_t
+clntraw_control()
+{
+ return (FALSE);
+}
+
+static void
+clntraw_destroy()
+{
+}
diff --git a/lib/libc/rpc/clnt_simple.c b/lib/libc/rpc/clnt_simple.c
new file mode 100644
index 0000000..5bcfd47
--- /dev/null
+++ b/lib/libc/rpc/clnt_simple.c
@@ -0,0 +1,122 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_simple.c 1.35 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_simple.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: clnt_simple.c,v 1.6 1996/12/30 14:23:50 peter Exp $";
+#endif
+
+/*
+ * clnt_simple.c
+ * Simplified front end to rpc.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+static struct callrpc_private {
+ CLIENT *client;
+ int socket;
+ int oldprognum, oldversnum, valid;
+ char *oldhost;
+} *callrpc_private;
+
+int
+callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
+ char *host;
+ int prognum, versnum, procnum;
+ xdrproc_t inproc, outproc;
+ char *in, *out;
+{
+ register struct callrpc_private *crp = callrpc_private;
+ struct sockaddr_in server_addr;
+ enum clnt_stat clnt_stat;
+ struct hostent *hp;
+ struct timeval timeout, tottimeout;
+
+ if (crp == 0) {
+ crp = (struct callrpc_private *)calloc(1, sizeof (*crp));
+ if (crp == 0)
+ return (0);
+ callrpc_private = crp;
+ }
+ if (crp->oldhost == NULL) {
+ crp->oldhost = malloc(MAXHOSTNAMELEN);
+ crp->oldhost[0] = 0;
+ crp->socket = RPC_ANYSOCK;
+ }
+ if (crp->valid && crp->oldprognum == prognum && crp->oldversnum == versnum
+ && strcmp(crp->oldhost, host) == 0) {
+ /* reuse old client */
+ } else {
+ crp->valid = 0;
+ if (crp->socket != -1)
+ (void)close(crp->socket);
+ crp->socket = RPC_ANYSOCK;
+ if (crp->client) {
+ clnt_destroy(crp->client);
+ crp->client = NULL;
+ }
+ if ((hp = gethostbyname(host)) == NULL)
+ return ((int) RPC_UNKNOWNHOST);
+ timeout.tv_usec = 0;
+ timeout.tv_sec = 5;
+ memset(&server_addr, 0, sizeof(server_addr));
+ memcpy((char *)&server_addr.sin_addr, hp->h_addr, hp->h_length);
+ server_addr.sin_len = sizeof(struct sockaddr_in);
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = 0;
+ if ((crp->client = clntudp_create(&server_addr, (u_long)prognum,
+ (u_long)versnum, timeout, &crp->socket)) == NULL)
+ return ((int) rpc_createerr.cf_stat);
+ crp->valid = 1;
+ crp->oldprognum = prognum;
+ crp->oldversnum = versnum;
+ (void) strcpy(crp->oldhost, host);
+ }
+ tottimeout.tv_sec = 25;
+ tottimeout.tv_usec = 0;
+ clnt_stat = clnt_call(crp->client, procnum, inproc, in,
+ outproc, out, tottimeout);
+ /*
+ * if call failed, empty cache
+ */
+ if (clnt_stat != RPC_SUCCESS)
+ crp->valid = 0;
+ return ((int) clnt_stat);
+}
diff --git a/lib/libc/rpc/clnt_tcp.c b/lib/libc/rpc/clnt_tcp.c
new file mode 100644
index 0000000..cfb3746
--- /dev/null
+++ b/lib/libc/rpc/clnt_tcp.c
@@ -0,0 +1,580 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: clnt_tcp.c,v 1.7 1996/12/30 14:36:17 peter Exp $";
+#endif
+
+/*
+ * clnt_tcp.c, Implements a TCP/IP based, client side RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * TCP based RPC supports 'batched calls'.
+ * A sequence of calls may be batched-up in a send buffer. The rpc call
+ * return immediately to the client even though the call was not necessarily
+ * sent. The batching occurs if the results' xdr routine is NULL (0) AND
+ * the rpc timeout value is zero (see clnt.h, rpc).
+ *
+ * Clients should NOT casually batch calls that in fact return results; that is,
+ * the server side should be aware that a call is batched and not produce any
+ * return message. Batched calls that produce many result messages can
+ * deadlock (netlock) the client and the server....
+ *
+ * Now go hang yourself.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <errno.h>
+#include <rpc/pmap_clnt.h>
+
+#define MCALL_MSG_SIZE 24
+
+static int readtcp();
+static int writetcp();
+
+static enum clnt_stat clnttcp_call();
+static void clnttcp_abort();
+static void clnttcp_geterr();
+static bool_t clnttcp_freeres();
+static bool_t clnttcp_control();
+static void clnttcp_destroy();
+
+static struct clnt_ops tcp_ops = {
+ clnttcp_call,
+ clnttcp_abort,
+ clnttcp_geterr,
+ clnttcp_freeres,
+ clnttcp_destroy,
+ clnttcp_control
+};
+
+struct ct_data {
+ int ct_sock;
+ bool_t ct_closeit;
+ struct timeval ct_wait;
+ bool_t ct_waitset; /* wait set by clnt_control? */
+ struct sockaddr_in ct_addr;
+ struct rpc_err ct_error;
+ char ct_mcall[MCALL_MSG_SIZE]; /* marshalled callmsg */
+ u_int ct_mpos; /* pos after marshal */
+ XDR ct_xdrs;
+};
+
+/*
+ * Create a client handle for a tcp/ip connection.
+ * If *sockp<0, *sockp is set to a newly created TCP socket and it is
+ * connected to raddr. If *sockp non-negative then
+ * raddr is ignored. The rpc/tcp package does buffering
+ * similar to stdio, so the client must pick send and receive buffer sizes,];
+ * 0 => use the default.
+ * If raddr->sin_port is 0, then a binder on the remote machine is
+ * consulted for the right port number.
+ * NB: *sockp is copied into a private area.
+ * NB: It is the clients responsibility to close *sockp.
+ * NB: The rpch->cl_auth is set null authentication. Caller may wish to set this
+ * something more useful.
+ */
+CLIENT *
+clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
+ struct sockaddr_in *raddr;
+ u_long prog;
+ u_long vers;
+ register int *sockp;
+ u_int sendsz;
+ u_int recvsz;
+{
+ CLIENT *h;
+ register struct ct_data *ct = NULL;
+ struct timeval now;
+ struct rpc_msg call_msg;
+ static u_int32_t disrupt;
+
+ if (disrupt == 0)
+ disrupt = (u_int32_t)(long)raddr;
+
+ h = (CLIENT *)mem_alloc(sizeof(*h));
+ if (h == NULL) {
+ (void)fprintf(stderr, "clnttcp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ ct = (struct ct_data *)mem_alloc(sizeof(*ct));
+ if (ct == NULL) {
+ (void)fprintf(stderr, "clnttcp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+
+ /*
+ * If no port number given ask the pmap for one
+ */
+ if (raddr->sin_port == 0) {
+ u_short port;
+ if ((port = pmap_getport(raddr, prog, vers, IPPROTO_TCP)) == 0) {
+ mem_free((caddr_t)ct, sizeof(struct ct_data));
+ mem_free((caddr_t)h, sizeof(CLIENT));
+ return ((CLIENT *)NULL);
+ }
+ raddr->sin_port = htons(port);
+ }
+
+ /*
+ * If no socket given, open one
+ */
+ if (*sockp < 0) {
+ *sockp = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ (void)bindresvport(*sockp, (struct sockaddr_in *)0);
+ if ((*sockp < 0)
+ || (connect(*sockp, (struct sockaddr *)raddr,
+ sizeof(*raddr)) < 0)) {
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ if (*sockp != -1)
+ (void)close(*sockp);
+ goto fooy;
+ }
+ ct->ct_closeit = TRUE;
+ } else {
+ ct->ct_closeit = FALSE;
+ }
+
+ /*
+ * Set up private data struct
+ */
+ ct->ct_sock = *sockp;
+ ct->ct_wait.tv_usec = 0;
+ ct->ct_waitset = FALSE;
+ ct->ct_addr = *raddr;
+
+ /*
+ * Initialize call message
+ */
+ (void)gettimeofday(&now, (struct timezone *)0);
+ call_msg.rm_xid = (++disrupt) ^ getpid() ^ now.tv_sec ^ now.tv_usec;
+ call_msg.rm_direction = CALL;
+ call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ call_msg.rm_call.cb_prog = prog;
+ call_msg.rm_call.cb_vers = vers;
+
+ /*
+ * pre-serialize the static part of the call msg and stash it away
+ */
+ xdrmem_create(&(ct->ct_xdrs), ct->ct_mcall, MCALL_MSG_SIZE,
+ XDR_ENCODE);
+ if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
+ if (ct->ct_closeit) {
+ (void)close(*sockp);
+ }
+ goto fooy;
+ }
+ ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
+ XDR_DESTROY(&(ct->ct_xdrs));
+
+ /*
+ * Create a client handle which uses xdrrec for serialization
+ * and authnone for authentication.
+ */
+ xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
+ (caddr_t)ct, readtcp, writetcp);
+ h->cl_ops = &tcp_ops;
+ h->cl_private = (caddr_t) ct;
+ h->cl_auth = authnone_create();
+ return (h);
+
+fooy:
+ /*
+ * Something goofed, free stuff and barf
+ */
+ if (ct)
+ mem_free((caddr_t)ct, sizeof(struct ct_data));
+ if (h)
+ mem_free((caddr_t)h, sizeof(CLIENT));
+ return ((CLIENT *)NULL);
+}
+
+static enum clnt_stat
+clnttcp_call(h, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout)
+ register CLIENT *h;
+ u_long proc;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
+ xdrproc_t xdr_results;
+ caddr_t results_ptr;
+ struct timeval timeout;
+{
+ register struct ct_data *ct = (struct ct_data *) h->cl_private;
+ register XDR *xdrs = &(ct->ct_xdrs);
+ struct rpc_msg reply_msg;
+ u_long x_id;
+ u_int32_t *msg_x_id = (u_int32_t *)(ct->ct_mcall); /* yuk */
+ register bool_t shipnow;
+ int refreshes = 2;
+
+ if (!ct->ct_waitset) {
+ ct->ct_wait = timeout;
+ }
+
+ shipnow =
+ (xdr_results == (xdrproc_t)0 && timeout.tv_sec == 0
+ && timeout.tv_usec == 0) ? FALSE : TRUE;
+
+call_again:
+ xdrs->x_op = XDR_ENCODE;
+ ct->ct_error.re_status = RPC_SUCCESS;
+ x_id = ntohl(--(*msg_x_id));
+ if ((! XDR_PUTBYTES(xdrs, ct->ct_mcall, ct->ct_mpos)) ||
+ (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
+ (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
+ (! (*xdr_args)(xdrs, args_ptr))) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ ct->ct_error.re_status = RPC_CANTENCODEARGS;
+ (void)xdrrec_endofrecord(xdrs, TRUE);
+ return (ct->ct_error.re_status);
+ }
+ if (! xdrrec_endofrecord(xdrs, shipnow))
+ return (ct->ct_error.re_status = RPC_CANTSEND);
+ if (! shipnow)
+ return (RPC_SUCCESS);
+ /*
+ * Hack to provide rpc-based message passing
+ */
+ if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
+ return(ct->ct_error.re_status = RPC_TIMEDOUT);
+ }
+
+
+ /*
+ * Keep receiving until we get a valid transaction id
+ */
+ xdrs->x_op = XDR_DECODE;
+ while (TRUE) {
+ reply_msg.acpted_rply.ar_verf = _null_auth;
+ reply_msg.acpted_rply.ar_results.where = NULL;
+ reply_msg.acpted_rply.ar_results.proc = xdr_void;
+ if (! xdrrec_skiprecord(xdrs))
+ return (ct->ct_error.re_status);
+ /* now decode and validate the response header */
+ if (! xdr_replymsg(xdrs, &reply_msg)) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ continue;
+ return (ct->ct_error.re_status);
+ }
+ if (reply_msg.rm_xid == x_id)
+ break;
+ }
+
+ /*
+ * process header
+ */
+ _seterr_reply(&reply_msg, &(ct->ct_error));
+ if (ct->ct_error.re_status == RPC_SUCCESS) {
+ if (! AUTH_VALIDATE(h->cl_auth, &reply_msg.acpted_rply.ar_verf)) {
+ ct->ct_error.re_status = RPC_AUTHERROR;
+ ct->ct_error.re_why = AUTH_INVALIDRESP;
+ } else if (! (*xdr_results)(xdrs, results_ptr)) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ ct->ct_error.re_status = RPC_CANTDECODERES;
+ }
+ /* free verifier ... */
+ if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
+ xdrs->x_op = XDR_FREE;
+ (void)xdr_opaque_auth(xdrs, &(reply_msg.acpted_rply.ar_verf));
+ }
+ } /* end successful completion */
+ else {
+ /* maybe our credentials need to be refreshed ... */
+ if (refreshes-- && AUTH_REFRESH(h->cl_auth))
+ goto call_again;
+ } /* end of unsuccessful completion */
+ return (ct->ct_error.re_status);
+}
+
+static void
+clnttcp_geterr(h, errp)
+ CLIENT *h;
+ struct rpc_err *errp;
+{
+ register struct ct_data *ct =
+ (struct ct_data *) h->cl_private;
+
+ *errp = ct->ct_error;
+}
+
+static bool_t
+clnttcp_freeres(cl, xdr_res, res_ptr)
+ CLIENT *cl;
+ xdrproc_t xdr_res;
+ caddr_t res_ptr;
+{
+ register struct ct_data *ct = (struct ct_data *)cl->cl_private;
+ register XDR *xdrs = &(ct->ct_xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_res)(xdrs, res_ptr));
+}
+
+static void
+clnttcp_abort()
+{
+}
+
+
+static bool_t
+clnttcp_control(cl, request, info)
+ CLIENT *cl;
+ int request;
+ char *info;
+{
+ register struct ct_data *ct = (struct ct_data *)cl->cl_private;
+ register struct timeval *tv;
+ int len;
+
+ switch (request) {
+ case CLSET_FD_CLOSE:
+ ct->ct_closeit = TRUE;
+ break;
+ case CLSET_FD_NCLOSE:
+ ct->ct_closeit = FALSE;
+ break;
+ case CLSET_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ tv = (struct timeval *)info;
+ ct->ct_wait.tv_sec = tv->tv_sec;
+ ct->ct_wait.tv_usec = tv->tv_usec;
+ ct->ct_waitset = TRUE;
+ break;
+ case CLGET_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ *(struct timeval *)info = ct->ct_wait;
+ break;
+ case CLGET_SERVER_ADDR:
+ if (info == NULL)
+ return(FALSE);
+ *(struct sockaddr_in *)info = ct->ct_addr;
+ break;
+ case CLGET_FD:
+ if (info == NULL)
+ return(FALSE);
+ *(int *)info = ct->ct_sock;
+ break;
+ case CLGET_XID:
+ /*
+ * use the knowledge that xid is the
+ * first element in the call structure *.
+ * This will get the xid of the PREVIOUS call
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)ct->ct_mcall);
+ break;
+ case CLSET_XID:
+ /* This will set the xid of the NEXT call */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)ct->ct_mcall = htonl(*(u_long *)info - 1);
+ /* decrement by 1 as clnttcp_call() increments once */
+ case CLGET_VERS:
+ /*
+ * This RELIES on the information that, in the call body,
+ * the version number field is the fifth field from the
+ * begining of the RPC header. MUST be changed if the
+ * call_struct is changed
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)(ct->ct_mcall +
+ 4 * BYTES_PER_XDR_UNIT));
+ break;
+ case CLSET_VERS:
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)(ct->ct_mcall + 4 * BYTES_PER_XDR_UNIT)
+ = htonl(*(u_long *)info);
+ break;
+ case CLGET_PROG:
+ /*
+ * This RELIES on the information that, in the call body,
+ * the program number field is the field from the
+ * begining of the RPC header. MUST be changed if the
+ * call_struct is changed
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)(ct->ct_mcall +
+ 3 * BYTES_PER_XDR_UNIT));
+ break;
+ case CLSET_PROG:
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)(ct->ct_mcall + 3 * BYTES_PER_XDR_UNIT)
+ = htonl(*(u_long *)info);
+ break;
+ case CLGET_LOCAL_ADDR:
+ len = sizeof(struct sockaddr);
+ if (getsockname(ct->ct_sock, (struct sockaddr *)info, &len) <0)
+ return(FALSE);
+ break;
+ case CLGET_RETRY_TIMEOUT:
+ case CLSET_RETRY_TIMEOUT:
+ case CLGET_SVC_ADDR:
+ case CLSET_SVC_ADDR:
+ case CLSET_PUSH_TIMOD:
+ case CLSET_POP_TIMOD:
+ default:
+ return (FALSE);
+ }
+ return (TRUE);
+}
+
+
+static void
+clnttcp_destroy(h)
+ CLIENT *h;
+{
+ register struct ct_data *ct =
+ (struct ct_data *) h->cl_private;
+
+ if (ct->ct_closeit) {
+ (void)close(ct->ct_sock);
+ }
+ XDR_DESTROY(&(ct->ct_xdrs));
+ mem_free((caddr_t)ct, sizeof(struct ct_data));
+ mem_free((caddr_t)h, sizeof(CLIENT));
+}
+
+/*
+ * Interface between xdr serializer and tcp connection.
+ * Behaves like the system calls, read & write, but keeps some error state
+ * around for the rpc level.
+ */
+static int
+readtcp(ct, buf, len)
+ register struct ct_data *ct;
+ caddr_t buf;
+ register int len;
+{
+ fd_set *fds, readfds;
+ struct timeval start, after, duration, delta, tmp, tv;
+ int r, save_errno;
+
+ if (len == 0)
+ return (0);
+
+ if (ct->ct_sock + 1 > FD_SETSIZE) {
+ int bytes = howmany(ct->ct_sock + 1, NFDBITS) * sizeof(fd_mask);
+ fds = (fd_set *)malloc(bytes);
+ if (fds == NULL)
+ return (-1);
+ memset(fds, 0, bytes);
+ } else {
+ fds = &readfds;
+ FD_ZERO(fds);
+ }
+
+ gettimeofday(&start, NULL);
+ delta = ct->ct_wait;
+ while (TRUE) {
+ /* XXX we know the other bits are still clear */
+ FD_SET(ct->ct_sock, fds);
+ tv = delta; /* in case select writes back */
+ r = select(ct->ct_sock+1, fds, NULL, NULL, &tv);
+ save_errno = errno;
+
+ gettimeofday(&after, NULL);
+ timersub(&start, &after, &duration);
+ timersub(&delta, &duration, &tmp);
+ delta = tmp;
+ if (delta.tv_sec < 0 || !timerisset(&delta))
+ r = 0;
+
+ switch (r) {
+ case 0:
+ if (fds != &readfds)
+ free(fds);
+ ct->ct_error.re_status = RPC_TIMEDOUT;
+ return (-1);
+
+ case -1:
+ if (errno == EINTR)
+ continue;
+ if (fds != &readfds)
+ free(fds);
+ ct->ct_error.re_status = RPC_CANTRECV;
+ ct->ct_error.re_errno = save_errno;
+ return (-1);
+ }
+ break;
+ }
+ switch (len = read(ct->ct_sock, buf, len)) {
+
+ case 0:
+ /* premature eof */
+ ct->ct_error.re_errno = ECONNRESET;
+ ct->ct_error.re_status = RPC_CANTRECV;
+ len = -1; /* it's really an error */
+ break;
+
+ case -1:
+ ct->ct_error.re_errno = errno;
+ ct->ct_error.re_status = RPC_CANTRECV;
+ break;
+ }
+ return (len);
+}
+
+static int
+writetcp(ct, buf, len)
+ struct ct_data *ct;
+ caddr_t buf;
+ int len;
+{
+ register int i, cnt;
+
+ for (cnt = len; cnt > 0; cnt -= i, buf += i) {
+ if ((i = write(ct->ct_sock, buf, cnt)) == -1) {
+ ct->ct_error.re_errno = errno;
+ ct->ct_error.re_status = RPC_CANTSEND;
+ return (-1);
+ }
+ }
+ return (len);
+}
diff --git a/lib/libc/rpc/clnt_udp.c b/lib/libc/rpc/clnt_udp.c
new file mode 100644
index 0000000..035ce96
--- /dev/null
+++ b/lib/libc/rpc/clnt_udp.c
@@ -0,0 +1,553 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_udp.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: clnt_udp.c,v 1.8 1996/12/30 14:40:34 peter Exp $";
+#endif
+
+/*
+ * clnt_udp.c, Implements a UDP/IP based, client side RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <netdb.h>
+#include <errno.h>
+#include <rpc/pmap_clnt.h>
+
+/*
+ * UDP bases client side rpc operations
+ */
+static enum clnt_stat clntudp_call();
+static void clntudp_abort();
+static void clntudp_geterr();
+static bool_t clntudp_freeres();
+static bool_t clntudp_control();
+static void clntudp_destroy();
+
+static struct clnt_ops udp_ops = {
+ clntudp_call,
+ clntudp_abort,
+ clntudp_geterr,
+ clntudp_freeres,
+ clntudp_destroy,
+ clntudp_control
+};
+
+/*
+ * Private data kept per client handle
+ */
+struct cu_data {
+ int cu_sock;
+ bool_t cu_closeit;
+ struct sockaddr_in cu_raddr;
+ int cu_rlen;
+ struct timeval cu_wait;
+ struct timeval cu_total;
+ struct rpc_err cu_error;
+ XDR cu_outxdrs;
+ u_int cu_xdrpos;
+ u_int cu_sendsz;
+ char *cu_outbuf;
+ u_int cu_recvsz;
+ char cu_inbuf[1];
+};
+
+/*
+ * Create a UDP based client handle.
+ * If *sockp<0, *sockp is set to a newly created UPD socket.
+ * If raddr->sin_port is 0 a binder on the remote machine
+ * is consulted for the correct port number.
+ * NB: It is the clients responsibility to close *sockp.
+ * NB: The rpch->cl_auth is initialized to null authentication.
+ * Caller may wish to set this something more useful.
+ *
+ * wait is the amount of time used between retransmitting a call if
+ * no response has been heard; retransmition occurs until the actual
+ * rpc call times out.
+ *
+ * sendsz and recvsz are the maximum allowable packet sizes that can be
+ * sent and received.
+ */
+CLIENT *
+clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
+ struct sockaddr_in *raddr;
+ u_long program;
+ u_long version;
+ struct timeval wait;
+ register int *sockp;
+ u_int sendsz;
+ u_int recvsz;
+{
+ CLIENT *cl;
+ register struct cu_data *cu = NULL;
+ struct timeval now;
+ struct rpc_msg call_msg;
+ static u_int32_t disrupt;
+
+ if (disrupt == 0)
+ disrupt = (u_int32_t)(long)raddr;
+
+ cl = (CLIENT *)mem_alloc(sizeof(CLIENT));
+ if (cl == NULL) {
+ (void) fprintf(stderr, "clntudp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ sendsz = ((sendsz + 3) / 4) * 4;
+ recvsz = ((recvsz + 3) / 4) * 4;
+ cu = (struct cu_data *)mem_alloc(sizeof(*cu) + sendsz + recvsz);
+ if (cu == NULL) {
+ (void) fprintf(stderr, "clntudp_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ cu->cu_outbuf = &cu->cu_inbuf[recvsz];
+
+ (void)gettimeofday(&now, (struct timezone *)0);
+ if (raddr->sin_port == 0) {
+ u_short port;
+ if ((port =
+ pmap_getport(raddr, program, version, IPPROTO_UDP)) == 0) {
+ goto fooy;
+ }
+ raddr->sin_port = htons(port);
+ }
+ cl->cl_ops = &udp_ops;
+ cl->cl_private = (caddr_t)cu;
+ cu->cu_raddr = *raddr;
+ cu->cu_rlen = sizeof (cu->cu_raddr);
+ cu->cu_wait = wait;
+ cu->cu_total.tv_sec = -1;
+ cu->cu_total.tv_usec = -1;
+ cu->cu_sendsz = sendsz;
+ cu->cu_recvsz = recvsz;
+ call_msg.rm_xid = (++disrupt) ^ getpid() ^ now.tv_sec ^ now.tv_usec;
+ call_msg.rm_direction = CALL;
+ call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ call_msg.rm_call.cb_prog = program;
+ call_msg.rm_call.cb_vers = version;
+ xdrmem_create(&(cu->cu_outxdrs), cu->cu_outbuf,
+ sendsz, XDR_ENCODE);
+ if (! xdr_callhdr(&(cu->cu_outxdrs), &call_msg)) {
+ goto fooy;
+ }
+ cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
+ if (*sockp < 0) {
+ int dontblock = 1;
+
+ *sockp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (*sockp < 0) {
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ /* attempt to bind to priv port */
+ (void)bindresvport(*sockp, (struct sockaddr_in *)0);
+ /* the sockets rpc controls are non-blocking */
+ (void)ioctl(*sockp, FIONBIO, (char *) &dontblock);
+ cu->cu_closeit = TRUE;
+ } else {
+ cu->cu_closeit = FALSE;
+ }
+ cu->cu_sock = *sockp;
+ cl->cl_auth = authnone_create();
+ return (cl);
+fooy:
+ if (cu)
+ mem_free((caddr_t)cu, sizeof(*cu) + sendsz + recvsz);
+ if (cl)
+ mem_free((caddr_t)cl, sizeof(CLIENT));
+ return ((CLIENT *)NULL);
+}
+
+CLIENT *
+clntudp_create(raddr, program, version, wait, sockp)
+ struct sockaddr_in *raddr;
+ u_long program;
+ u_long version;
+ struct timeval wait;
+ register int *sockp;
+{
+
+ return(clntudp_bufcreate(raddr, program, version, wait, sockp,
+ UDPMSGSIZE, UDPMSGSIZE));
+}
+
+static enum clnt_stat
+clntudp_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
+ register CLIENT *cl; /* client handle */
+ u_long proc; /* procedure number */
+ xdrproc_t xargs; /* xdr routine for args */
+ caddr_t argsp; /* pointer to args */
+ xdrproc_t xresults; /* xdr routine for results */
+ caddr_t resultsp; /* pointer to results */
+ struct timeval utimeout; /* seconds to wait before giving up */
+{
+ register struct cu_data *cu = (struct cu_data *)cl->cl_private;
+ register XDR *xdrs;
+ register int outlen;
+ register int inlen;
+ int fromlen;
+ fd_set *fds, readfds;
+ struct sockaddr_in from;
+ struct rpc_msg reply_msg;
+ XDR reply_xdrs;
+ struct timeval time_waited, start, after, tmp1, tmp2, tv;
+ bool_t ok;
+ int nrefreshes = 2; /* number of times to refresh cred */
+ struct timeval timeout;
+
+ if (cu->cu_total.tv_usec == -1)
+ timeout = utimeout; /* use supplied timeout */
+ else
+ timeout = cu->cu_total; /* use default timeout */
+
+ if (cu->cu_sock + 1 > FD_SETSIZE) {
+ int bytes = howmany(cu->cu_sock + 1, NFDBITS) * sizeof(fd_mask);
+ fds = (fd_set *)malloc(bytes);
+ if (fds == NULL)
+ return (cu->cu_error.re_status = RPC_CANTSEND);
+ memset(fds, 0, bytes);
+ } else {
+ fds = &readfds;
+ FD_ZERO(fds);
+ }
+
+ timerclear(&time_waited);
+
+call_again:
+ xdrs = &(cu->cu_outxdrs);
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, cu->cu_xdrpos);
+ /*
+ * the transaction is the first thing in the out buffer
+ */
+ (*(u_short *)(cu->cu_outbuf))++;
+ if ((! XDR_PUTLONG(xdrs, (long *)&proc)) ||
+ (! AUTH_MARSHALL(cl->cl_auth, xdrs)) ||
+ (! (*xargs)(xdrs, argsp))) {
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_CANTENCODEARGS);
+ }
+ outlen = (int)XDR_GETPOS(xdrs);
+
+send_again:
+ if (sendto(cu->cu_sock, cu->cu_outbuf, outlen, 0,
+ (struct sockaddr *)&(cu->cu_raddr), cu->cu_rlen) != outlen) {
+ cu->cu_error.re_errno = errno;
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_CANTSEND);
+ }
+
+ /*
+ * Hack to provide rpc-based message passing
+ */
+ if (!timerisset(&timeout)) {
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_TIMEDOUT);
+ }
+ /*
+ * sub-optimal code appears here because we have
+ * some clock time to spare while the packets are in flight.
+ * (We assume that this is actually only executed once.)
+ */
+ reply_msg.acpted_rply.ar_verf = _null_auth;
+ reply_msg.acpted_rply.ar_results.where = resultsp;
+ reply_msg.acpted_rply.ar_results.proc = xresults;
+
+ gettimeofday(&start, NULL);
+ for (;;) {
+ /* XXX we know the other bits are still clear */
+ FD_SET(cu->cu_sock, fds);
+ tv = cu->cu_wait;
+ switch (select(cu->cu_sock+1, fds, NULL, NULL, &tv)) {
+
+ case 0:
+ timeradd(&time_waited, &cu->cu_wait, &tmp1);
+ time_waited = tmp1;
+ if (timercmp(&time_waited, &timeout, <))
+ goto send_again;
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_TIMEDOUT);
+
+ case -1:
+ if (errno == EINTR) {
+ gettimeofday(&after, NULL);
+ timersub(&after, &start, &tmp1);
+ timeradd(&time_waited, &tmp1, &tmp2);
+ time_waited = tmp2;
+ if (timercmp(&time_waited, &timeout, <))
+ continue;
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_TIMEDOUT);
+ }
+ cu->cu_error.re_errno = errno;
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_CANTRECV);
+ }
+
+ do {
+ fromlen = sizeof(struct sockaddr);
+ inlen = recvfrom(cu->cu_sock, cu->cu_inbuf,
+ (int) cu->cu_recvsz, 0,
+ (struct sockaddr *)&from, &fromlen);
+ } while (inlen < 0 && errno == EINTR);
+ if (inlen < 0) {
+ if (errno == EWOULDBLOCK)
+ continue;
+ cu->cu_error.re_errno = errno;
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status = RPC_CANTRECV);
+ }
+ if (inlen < sizeof(u_int32_t))
+ continue;
+ /* see if reply transaction id matches sent id */
+ if (*((u_int32_t *)(cu->cu_inbuf)) != *((u_int32_t *)(cu->cu_outbuf)))
+ continue;
+ /* we now assume we have the proper reply */
+ break;
+ }
+
+ /*
+ * now decode and validate the response
+ */
+ xdrmem_create(&reply_xdrs, cu->cu_inbuf, (u_int)inlen, XDR_DECODE);
+ ok = xdr_replymsg(&reply_xdrs, &reply_msg);
+ /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
+ if (ok) {
+ _seterr_reply(&reply_msg, &(cu->cu_error));
+ if (cu->cu_error.re_status == RPC_SUCCESS) {
+ if (! AUTH_VALIDATE(cl->cl_auth,
+ &reply_msg.acpted_rply.ar_verf)) {
+ cu->cu_error.re_status = RPC_AUTHERROR;
+ cu->cu_error.re_why = AUTH_INVALIDRESP;
+ }
+ if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
+ xdrs->x_op = XDR_FREE;
+ (void)xdr_opaque_auth(xdrs,
+ &(reply_msg.acpted_rply.ar_verf));
+ }
+ } /* end successful completion */
+ else {
+ /* maybe our credentials need to be refreshed ... */
+ if (nrefreshes > 0 && AUTH_REFRESH(cl->cl_auth)) {
+ nrefreshes--;
+ goto call_again;
+ }
+ } /* end of unsuccessful completion */
+ } /* end of valid reply message */
+ else {
+ cu->cu_error.re_status = RPC_CANTDECODERES;
+ }
+ if (fds != &readfds)
+ free(fds);
+ return (cu->cu_error.re_status);
+}
+
+static void
+clntudp_geterr(cl, errp)
+ CLIENT *cl;
+ struct rpc_err *errp;
+{
+ register struct cu_data *cu = (struct cu_data *)cl->cl_private;
+
+ *errp = cu->cu_error;
+}
+
+
+static bool_t
+clntudp_freeres(cl, xdr_res, res_ptr)
+ CLIENT *cl;
+ xdrproc_t xdr_res;
+ caddr_t res_ptr;
+{
+ register struct cu_data *cu = (struct cu_data *)cl->cl_private;
+ register XDR *xdrs = &(cu->cu_outxdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_res)(xdrs, res_ptr));
+}
+
+static void
+clntudp_abort(/*h*/)
+ /*CLIENT *h;*/
+{
+}
+
+
+static bool_t
+clntudp_control(cl, request, info)
+ CLIENT *cl;
+ int request;
+ char *info;
+{
+ register struct cu_data *cu = (struct cu_data *)cl->cl_private;
+ register struct timeval *tv;
+ int len;
+
+ switch (request) {
+ case CLSET_FD_CLOSE:
+ cu->cu_closeit = TRUE;
+ break;
+ case CLSET_FD_NCLOSE:
+ cu->cu_closeit = FALSE;
+ break;
+ case CLSET_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ tv = (struct timeval *)info;
+ cu->cu_total.tv_sec = tv->tv_sec;
+ cu->cu_total.tv_usec = tv->tv_usec;
+ break;
+ case CLGET_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ *(struct timeval *)info = cu->cu_total;
+ break;
+ case CLSET_RETRY_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ tv = (struct timeval *)info;
+ cu->cu_wait.tv_sec = tv->tv_sec;
+ cu->cu_wait.tv_usec = tv->tv_usec;
+ break;
+ case CLGET_RETRY_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ *(struct timeval *)info = cu->cu_wait;
+ break;
+ case CLGET_SERVER_ADDR:
+ if (info == NULL)
+ return(FALSE);
+ *(struct sockaddr_in *)info = cu->cu_raddr;
+ break;
+ case CLGET_FD:
+ if (info == NULL)
+ return(FALSE);
+ *(int *)info = cu->cu_sock;
+ break;
+ case CLGET_XID:
+ /*
+ * use the knowledge that xid is the
+ * first element in the call structure *.
+ * This will get the xid of the PREVIOUS call
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)cu->cu_outbuf);
+ break;
+ case CLSET_XID:
+ /* This will set the xid of the NEXT call */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)cu->cu_outbuf = htonl(*(u_long *)info - 1);
+ /* decrement by 1 as clntudp_call() increments once */
+ case CLGET_VERS:
+ /*
+ * This RELIES on the information that, in the call body,
+ * the version number field is the fifth field from the
+ * begining of the RPC header. MUST be changed if the
+ * call_struct is changed
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)(cu->cu_outbuf +
+ 4 * BYTES_PER_XDR_UNIT));
+ break;
+ case CLSET_VERS:
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)(cu->cu_outbuf + 4 * BYTES_PER_XDR_UNIT)
+ = htonl(*(u_long *)info);
+ break;
+ case CLGET_PROG:
+ /*
+ * This RELIES on the information that, in the call body,
+ * the program number field is the field from the
+ * begining of the RPC header. MUST be changed if the
+ * call_struct is changed
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)(cu->cu_outbuf +
+ 3 * BYTES_PER_XDR_UNIT));
+ break;
+ case CLSET_PROG:
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)(cu->cu_outbuf + 3 * BYTES_PER_XDR_UNIT)
+ = htonl(*(u_long *)info);
+ break;
+ case CLGET_LOCAL_ADDR:
+ len = sizeof(struct sockaddr);
+ if (getsockname(cu->cu_sock, (struct sockaddr *)info, &len) <0)
+ return(FALSE);
+ break;
+ case CLGET_SVC_ADDR:
+ case CLSET_SVC_ADDR:
+ case CLSET_PUSH_TIMOD:
+ case CLSET_POP_TIMOD:
+ default:
+ return (FALSE);
+ }
+ return (TRUE);
+}
+
+static void
+clntudp_destroy(cl)
+ CLIENT *cl;
+{
+ register struct cu_data *cu = (struct cu_data *)cl->cl_private;
+
+ if (cu->cu_closeit) {
+ (void)close(cu->cu_sock);
+ }
+ XDR_DESTROY(&(cu->cu_outxdrs));
+ mem_free((caddr_t)cu, (sizeof(*cu) + cu->cu_sendsz + cu->cu_recvsz));
+ mem_free((caddr_t)cl, sizeof(CLIENT));
+}
diff --git a/lib/libc/rpc/clnt_unix.c b/lib/libc/rpc/clnt_unix.c
new file mode 100644
index 0000000..e4c4309
--- /dev/null
+++ b/lib/libc/rpc/clnt_unix.c
@@ -0,0 +1,635 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)clnt_unix.c 1.37 87/10/05 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)clnt_unix.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: clnt_unix.c,v 1.7 1996/12/30 14:36:17 peter Exp $";
+#endif
+
+/*
+ * clnt_unix.c, Implements a AF_UNIX based, client side RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * AF_UNIX based RPC supports 'batched calls'.
+ * A sequence of calls may be batched-up in a send buffer. The rpc call
+ * return immediately to the client even though the call was not necessarily
+ * sent. The batching occurs if the results' xdr routine is NULL (0) AND
+ * the rpc timeout value is zero (see clnt.h, rpc).
+ *
+ * Clients should NOT casually batch calls that in fact return results; that is,
+ * the server side should be aware that a call is batched and not produce any
+ * return message. Batched calls that produce many result messages can
+ * deadlock (netlock) the client and the server....
+ *
+ * Now go hang yourself.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netdb.h>
+#include <errno.h>
+#include <rpc/pmap_clnt.h>
+
+#define MCALL_MSG_SIZE 24
+
+static int readunix();
+static int writeunix();
+
+static enum clnt_stat clntunix_call();
+static void clntunix_abort();
+static void clntunix_geterr();
+static bool_t clntunix_freeres();
+static bool_t clntunix_control();
+static void clntunix_destroy();
+
+static struct clnt_ops unix_ops = {
+ clntunix_call,
+ clntunix_abort,
+ clntunix_geterr,
+ clntunix_freeres,
+ clntunix_destroy,
+ clntunix_control
+};
+
+struct ct_data {
+ int ct_sock;
+ bool_t ct_closeit;
+ struct timeval ct_wait;
+ bool_t ct_waitset; /* wait set by clnt_control? */
+ struct sockaddr_un ct_addr;
+ struct rpc_err ct_error;
+ char ct_mcall[MCALL_MSG_SIZE]; /* marshalled callmsg */
+ u_int ct_mpos; /* pos after marshal */
+ XDR ct_xdrs;
+};
+
+/*
+ * Create a client handle for a unix/ip connection.
+ * If *sockp<0, *sockp is set to a newly created TCP socket and it is
+ * connected to raddr. If *sockp non-negative then
+ * raddr is ignored. The rpc/unix package does buffering
+ * similar to stdio, so the client must pick send and receive buffer sizes,];
+ * 0 => use the default.
+ * If raddr->sin_port is 0, then a binder on the remote machine is
+ * consulted for the right port number.
+ * NB: *sockp is copied into a private area.
+ * NB: It is the clients responsibility to close *sockp.
+ * NB: The rpch->cl_auth is set null authentication. Caller may wish to set this
+ * something more useful.
+ */
+CLIENT *
+clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz)
+ struct sockaddr_un *raddr;
+ u_long prog;
+ u_long vers;
+ register int *sockp;
+ u_int sendsz;
+ u_int recvsz;
+{
+ CLIENT *h;
+ register struct ct_data *ct = NULL;
+ struct timeval now;
+ struct rpc_msg call_msg;
+ static u_int32_t disrupt;
+ int len;
+
+ if (disrupt == 0)
+ disrupt = (u_int32_t)(long)raddr;
+
+ h = (CLIENT *)mem_alloc(sizeof(*h));
+ if (h == NULL) {
+ (void)fprintf(stderr, "clntunix_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+ ct = (struct ct_data *)mem_alloc(sizeof(*ct));
+ if (ct == NULL) {
+ (void)fprintf(stderr, "clntunix_create: out of memory\n");
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ goto fooy;
+ }
+
+ /*
+ * If no socket given, open one
+ */
+ if (*sockp < 0) {
+ *sockp = socket(AF_UNIX, SOCK_STREAM, 0);
+ len = strlen(raddr->sun_path) + sizeof(raddr->sun_family) +
+ sizeof(raddr->sun_len) + 1;
+ raddr->sun_len = len;
+ if ((*sockp < 0)
+ || (connect(*sockp, (struct sockaddr *)raddr, len) < 0)) {
+ rpc_createerr.cf_stat = RPC_SYSTEMERROR;
+ rpc_createerr.cf_error.re_errno = errno;
+ if (*sockp != -1)
+ (void)close(*sockp);
+ goto fooy;
+ }
+ ct->ct_closeit = TRUE;
+ } else {
+ ct->ct_closeit = FALSE;
+ }
+
+ /*
+ * Set up private data struct
+ */
+ ct->ct_sock = *sockp;
+ ct->ct_wait.tv_usec = 0;
+ ct->ct_waitset = FALSE;
+ ct->ct_addr = *raddr;
+
+ /*
+ * Initialize call message
+ */
+ (void)gettimeofday(&now, (struct timezone *)0);
+ call_msg.rm_xid = (++disrupt) ^ getpid() ^ now.tv_sec ^ now.tv_usec;
+ call_msg.rm_direction = CALL;
+ call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ call_msg.rm_call.cb_prog = prog;
+ call_msg.rm_call.cb_vers = vers;
+
+ /*
+ * pre-serialize the static part of the call msg and stash it away
+ */
+ xdrmem_create(&(ct->ct_xdrs), ct->ct_mcall, MCALL_MSG_SIZE,
+ XDR_ENCODE);
+ if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
+ if (ct->ct_closeit) {
+ (void)close(*sockp);
+ }
+ goto fooy;
+ }
+ ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
+ XDR_DESTROY(&(ct->ct_xdrs));
+
+ /*
+ * Create a client handle which uses xdrrec for serialization
+ * and authnone for authentication.
+ */
+ xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
+ (caddr_t)ct, readunix, writeunix);
+ h->cl_ops = &unix_ops;
+ h->cl_private = (caddr_t) ct;
+ h->cl_auth = authnone_create();
+ return (h);
+
+fooy:
+ /*
+ * Something goofed, free stuff and barf
+ */
+ if (ct)
+ mem_free((caddr_t)ct, sizeof(struct ct_data));
+ if (h)
+ mem_free((caddr_t)h, sizeof(CLIENT));
+ return ((CLIENT *)NULL);
+}
+
+static enum clnt_stat
+clntunix_call(h, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout)
+ register CLIENT *h;
+ u_long proc;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
+ xdrproc_t xdr_results;
+ caddr_t results_ptr;
+ struct timeval timeout;
+{
+ register struct ct_data *ct = (struct ct_data *) h->cl_private;
+ register XDR *xdrs = &(ct->ct_xdrs);
+ struct rpc_msg reply_msg;
+ u_long x_id;
+ u_int32_t *msg_x_id = (u_int32_t *)(ct->ct_mcall); /* yuk */
+ register bool_t shipnow;
+ int refreshes = 2;
+
+ if (!ct->ct_waitset) {
+ ct->ct_wait = timeout;
+ }
+
+ shipnow =
+ (xdr_results == (xdrproc_t)0 && timeout.tv_sec == 0
+ && timeout.tv_usec == 0) ? FALSE : TRUE;
+
+call_again:
+ xdrs->x_op = XDR_ENCODE;
+ ct->ct_error.re_status = RPC_SUCCESS;
+ x_id = ntohl(--(*msg_x_id));
+ if ((! XDR_PUTBYTES(xdrs, ct->ct_mcall, ct->ct_mpos)) ||
+ (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
+ (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
+ (! (*xdr_args)(xdrs, args_ptr))) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ ct->ct_error.re_status = RPC_CANTENCODEARGS;
+ (void)xdrrec_endofrecord(xdrs, TRUE);
+ return (ct->ct_error.re_status);
+ }
+ if (! xdrrec_endofrecord(xdrs, shipnow))
+ return (ct->ct_error.re_status = RPC_CANTSEND);
+ if (! shipnow)
+ return (RPC_SUCCESS);
+ /*
+ * Hack to provide rpc-based message passing
+ */
+ if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
+ return(ct->ct_error.re_status = RPC_TIMEDOUT);
+ }
+
+
+ /*
+ * Keep receiving until we get a valid transaction id
+ */
+ xdrs->x_op = XDR_DECODE;
+ while (TRUE) {
+ reply_msg.acpted_rply.ar_verf = _null_auth;
+ reply_msg.acpted_rply.ar_results.where = NULL;
+ reply_msg.acpted_rply.ar_results.proc = xdr_void;
+ if (! xdrrec_skiprecord(xdrs))
+ return (ct->ct_error.re_status);
+ /* now decode and validate the response header */
+ if (! xdr_replymsg(xdrs, &reply_msg)) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ continue;
+ return (ct->ct_error.re_status);
+ }
+ if (reply_msg.rm_xid == x_id)
+ break;
+ }
+
+ /*
+ * process header
+ */
+ _seterr_reply(&reply_msg, &(ct->ct_error));
+ if (ct->ct_error.re_status == RPC_SUCCESS) {
+ if (! AUTH_VALIDATE(h->cl_auth, &reply_msg.acpted_rply.ar_verf)) {
+ ct->ct_error.re_status = RPC_AUTHERROR;
+ ct->ct_error.re_why = AUTH_INVALIDRESP;
+ } else if (! (*xdr_results)(xdrs, results_ptr)) {
+ if (ct->ct_error.re_status == RPC_SUCCESS)
+ ct->ct_error.re_status = RPC_CANTDECODERES;
+ }
+ /* free verifier ... */
+ if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
+ xdrs->x_op = XDR_FREE;
+ (void)xdr_opaque_auth(xdrs, &(reply_msg.acpted_rply.ar_verf));
+ }
+ } /* end successful completion */
+ else {
+ /* maybe our credentials need to be refreshed ... */
+ if (refreshes-- && AUTH_REFRESH(h->cl_auth))
+ goto call_again;
+ } /* end of unsuccessful completion */
+ return (ct->ct_error.re_status);
+}
+
+static void
+clntunix_geterr(h, errp)
+ CLIENT *h;
+ struct rpc_err *errp;
+{
+ register struct ct_data *ct =
+ (struct ct_data *) h->cl_private;
+
+ *errp = ct->ct_error;
+}
+
+static bool_t
+clntunix_freeres(cl, xdr_res, res_ptr)
+ CLIENT *cl;
+ xdrproc_t xdr_res;
+ caddr_t res_ptr;
+{
+ register struct ct_data *ct = (struct ct_data *)cl->cl_private;
+ register XDR *xdrs = &(ct->ct_xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_res)(xdrs, res_ptr));
+}
+
+static void
+clntunix_abort()
+{
+}
+
+
+static bool_t
+clntunix_control(cl, request, info)
+ CLIENT *cl;
+ int request;
+ char *info;
+{
+ register struct ct_data *ct = (struct ct_data *)cl->cl_private;
+ register struct timeval *tv;
+ int len;
+
+ switch (request) {
+ case CLSET_FD_CLOSE:
+ ct->ct_closeit = TRUE;
+ break;
+ case CLSET_FD_NCLOSE:
+ ct->ct_closeit = FALSE;
+ break;
+ case CLSET_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ tv = (struct timeval *)info;
+ ct->ct_wait.tv_sec = tv->tv_sec;
+ ct->ct_wait.tv_usec = tv->tv_usec;
+ ct->ct_waitset = TRUE;
+ break;
+ case CLGET_TIMEOUT:
+ if (info == NULL)
+ return(FALSE);
+ *(struct timeval *)info = ct->ct_wait;
+ break;
+ case CLGET_SERVER_ADDR:
+ if (info == NULL)
+ return(FALSE);
+ *(struct sockaddr_un *)info = ct->ct_addr;
+ break;
+ case CLGET_FD:
+ if (info == NULL)
+ return(FALSE);
+ *(int *)info = ct->ct_sock;
+ break;
+ case CLGET_XID:
+ /*
+ * use the knowledge that xid is the
+ * first element in the call structure *.
+ * This will get the xid of the PREVIOUS call
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)ct->ct_mcall);
+ break;
+ case CLSET_XID:
+ /* This will set the xid of the NEXT call */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)ct->ct_mcall = htonl(*(u_long *)info - 1);
+ /* decrement by 1 as clntunix_call() increments once */
+ case CLGET_VERS:
+ /*
+ * This RELIES on the information that, in the call body,
+ * the version number field is the fifth field from the
+ * begining of the RPC header. MUST be changed if the
+ * call_struct is changed
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)(ct->ct_mcall +
+ 4 * BYTES_PER_XDR_UNIT));
+ break;
+ case CLSET_VERS:
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)(ct->ct_mcall + 4 * BYTES_PER_XDR_UNIT)
+ = htonl(*(u_long *)info);
+ break;
+ case CLGET_PROG:
+ /*
+ * This RELIES on the information that, in the call body,
+ * the program number field is the field from the
+ * begining of the RPC header. MUST be changed if the
+ * call_struct is changed
+ */
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)info = ntohl(*(u_long *)(ct->ct_mcall +
+ 3 * BYTES_PER_XDR_UNIT));
+ break;
+ case CLSET_PROG:
+ if (info == NULL)
+ return(FALSE);
+ *(u_long *)(ct->ct_mcall + 3 * BYTES_PER_XDR_UNIT)
+ = htonl(*(u_long *)info);
+ break;
+ case CLGET_LOCAL_ADDR:
+ len = sizeof(struct sockaddr);
+ if (getsockname(ct->ct_sock, (struct sockaddr *)info, &len) <0)
+ return(FALSE);
+ break;
+ case CLGET_RETRY_TIMEOUT:
+ case CLSET_RETRY_TIMEOUT:
+ case CLGET_SVC_ADDR:
+ case CLSET_SVC_ADDR:
+ case CLSET_PUSH_TIMOD:
+ case CLSET_POP_TIMOD:
+ default:
+ return (FALSE);
+ }
+ return (TRUE);
+}
+
+
+static void
+clntunix_destroy(h)
+ CLIENT *h;
+{
+ register struct ct_data *ct =
+ (struct ct_data *) h->cl_private;
+
+ if (ct->ct_closeit) {
+ (void)close(ct->ct_sock);
+ }
+ XDR_DESTROY(&(ct->ct_xdrs));
+ mem_free((caddr_t)ct, sizeof(struct ct_data));
+ mem_free((caddr_t)h, sizeof(CLIENT));
+}
+
+/*
+ * read() and write() are replaced with recvmsg()/sendmsg() so that
+ * we can pass ancillary control data. In this case, the data constists
+ * of credential information which the kernel will fill in for us.
+ * XXX: This code is specific to FreeBSD and will not work on other
+ * platforms without the requisite kernel modifications.
+ */
+struct cmessage {
+ struct cmsghdr cmsg;
+ struct cmsgcred cmcred;
+};
+
+static int __msgread(sock, buf, cnt)
+ int sock;
+ void *buf;
+ size_t cnt;
+{
+ struct iovec iov[1];
+ struct msghdr msg;
+ struct cmessage cm;
+
+ bzero((char *)&cm, sizeof(cm));
+ iov[0].iov_base = buf;
+ iov[0].iov_len = cnt;
+
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_control = (caddr_t)&cm;
+ msg.msg_controllen = sizeof(struct cmessage);
+ msg.msg_flags = 0;
+
+ return(recvmsg(sock, &msg, 0));
+}
+
+static int __msgwrite(sock, buf, cnt)
+ int sock;
+ void *buf;
+ size_t cnt;
+{
+ struct iovec iov[1];
+ struct msghdr msg;
+ struct cmessage cm;
+
+ bzero((char *)&cm, sizeof(cm));
+ iov[0].iov_base = buf;
+ iov[0].iov_len = cnt;
+
+ cm.cmsg.cmsg_type = SCM_CREDS;
+ cm.cmsg.cmsg_level = SOL_SOCKET;
+ cm.cmsg.cmsg_len = sizeof(struct cmessage);
+
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_control = (caddr_t)&cm;
+ msg.msg_controllen = sizeof(struct cmessage);
+ msg.msg_flags = 0;
+
+ return(sendmsg(sock, &msg, 0));
+}
+
+/*
+ * Interface between xdr serializer and unix connection.
+ * Behaves like the system calls, read & write, but keeps some error state
+ * around for the rpc level.
+ */
+static int
+readunix(ct, buf, len)
+ register struct ct_data *ct;
+ caddr_t buf;
+ register int len;
+{
+ fd_set *fds, readfds;
+ struct timeval start, after, duration, delta, tmp, tv;
+ int r, save_errno;
+
+ if (len == 0)
+ return (0);
+
+ if (ct->ct_sock + 1 > FD_SETSIZE) {
+ int bytes = howmany(ct->ct_sock + 1, NFDBITS) * sizeof(fd_mask);
+ fds = (fd_set *)malloc(bytes);
+ if (fds == NULL)
+ return (-1);
+ memset(fds, 0, bytes);
+ } else {
+ fds = &readfds;
+ FD_ZERO(fds);
+ }
+
+ gettimeofday(&start, NULL);
+ delta = ct->ct_wait;
+ while (TRUE) {
+ /* XXX we know the other bits are still clear */
+ FD_SET(ct->ct_sock, fds);
+ tv = delta; /* in case select writes back */
+ r = select(ct->ct_sock+1, fds, NULL, NULL, &tv);
+ save_errno = errno;
+
+ gettimeofday(&after, NULL);
+ timersub(&start, &after, &duration);
+ timersub(&delta, &duration, &tmp);
+ delta = tmp;
+ if (delta.tv_sec < 0 || !timerisset(&delta))
+ r = 0;
+
+ switch (r) {
+ case 0:
+ if (fds != &readfds)
+ free(fds);
+ ct->ct_error.re_status = RPC_TIMEDOUT;
+ return (-1);
+
+ case -1:
+ if (errno == EINTR)
+ continue;
+ if (fds != &readfds)
+ free(fds);
+ ct->ct_error.re_status = RPC_CANTRECV;
+ ct->ct_error.re_errno = save_errno;
+ return (-1);
+ }
+ break;
+ }
+ switch (len = __msgread(ct->ct_sock, buf, len)) {
+
+ case 0:
+ /* premature eof */
+ ct->ct_error.re_errno = ECONNRESET;
+ ct->ct_error.re_status = RPC_CANTRECV;
+ len = -1; /* it's really an error */
+ break;
+
+ case -1:
+ ct->ct_error.re_errno = errno;
+ ct->ct_error.re_status = RPC_CANTRECV;
+ break;
+ }
+ return (len);
+}
+
+static int
+writeunix(ct, buf, len)
+ struct ct_data *ct;
+ caddr_t buf;
+ int len;
+{
+ register int i, cnt;
+
+ for (cnt = len; cnt > 0; cnt -= i, buf += i) {
+ if ((i = __msgwrite(ct->ct_sock, buf, cnt)) == -1) {
+ ct->ct_error.re_errno = errno;
+ ct->ct_error.re_status = RPC_CANTSEND;
+ return (-1);
+ }
+ }
+ return (len);
+}
diff --git a/lib/libc/rpc/crypt_client.c b/lib/libc/rpc/crypt_client.c
new file mode 100644
index 0000000..cdc0c06
--- /dev/null
+++ b/lib/libc/rpc/crypt_client.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 1996
+ * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul 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.
+ *
+ * $Id$
+ */
+
+#include <sys/types.h>
+#include <rpc/des_crypt.h>
+#include <rpc/des.h>
+#include <string.h>
+#include <rpcsvc/crypt.h>
+
+#ifndef lint
+static const char rcsid[] = "$Id$";
+#endif
+
+#ifndef KEYSERVSOCK
+#define KEYSERVSOCK "/var/run/keyservsock"
+#endif
+
+int
+_des_crypt_call(buf, len, dparms)
+ char *buf;
+ int len;
+ struct desparams *dparms;
+{
+ CLIENT *clnt;
+ desresp *result_1;
+ desargs des_crypt_1_arg;
+ int stat;
+
+ clnt = clnt_create(KEYSERVSOCK, CRYPT_PROG, CRYPT_VERS, "unix");
+ if (clnt == (CLIENT *) NULL) {
+ return(DESERR_HWERROR);
+ }
+
+ des_crypt_1_arg.desbuf.desbuf_len = len;
+ des_crypt_1_arg.desbuf.desbuf_val = buf;
+ des_crypt_1_arg.des_dir = dparms->des_dir;
+ des_crypt_1_arg.des_mode = dparms->des_mode;
+ bcopy(dparms->des_ivec, des_crypt_1_arg.des_ivec, 8);
+ bcopy(dparms->des_key, des_crypt_1_arg.des_key, 8);
+
+ result_1 = des_crypt_1(&des_crypt_1_arg, clnt);
+ if (result_1 == (desresp *) NULL) {
+ return(DESERR_HWERROR);
+ }
+
+ stat = result_1->stat;
+
+ if (result_1->stat == DESERR_NONE ||
+ result_1->stat == DESERR_NOHWDEVICE) {
+ bcopy(result_1->desbuf.desbuf_val, buf, len);
+ bcopy(result_1->des_ivec, dparms->des_ivec, 8);
+ }
+
+ clnt_freeres(clnt, xdr_desresp, (char *)result_1);
+ clnt_destroy(clnt);
+
+ return(stat);
+}
diff --git a/lib/libc/rpc/des_crypt.3 b/lib/libc/rpc/des_crypt.3
new file mode 100644
index 0000000..ca0a33e
--- /dev/null
+++ b/lib/libc/rpc/des_crypt.3
@@ -0,0 +1,126 @@
+.\" @(#)des_crypt.3 2.1 88/08/11 4.0 RPCSRC; from 1.16 88/03/02 SMI;
+.TH DES_CRYPT 3 "6 October 1987"
+.SH NAME
+des_crypt, ecb_crypt, cbc_crypt, des_setparity \- fast DES encryption
+.SH SYNOPSIS
+.nf
+.B #include <des_crypt.h>
+.LP
+.B int ecb_crypt(key, data, datalen, mode)
+.B char *key;
+.B char *data;
+.B unsigned datalen;
+.B unsigned mode;
+.LP
+.B int cbc_crypt(key, data, datalen, mode, ivec)
+.B char *key;
+.B char *data;
+.B unsigned datalen;
+.B unsigned mode;
+.B char *ivec;
+.LP
+.B void des_setparity(key)
+.B char *key;
+.fi
+.SH DESCRIPTION
+.IX encryption cbc_crypt "" \fLcbc_crypt\fP
+.IX "des encryption" cbc_crypt "DES encryption" \fLcbc_crypt\fP
+.IX encryption des_setparity "" \fLdes_setparity\fP
+.IX "des encryption" des_setparity "DES encryption" \fLdes_setparity\fP
+.B ecb_crypt(\|)
+and
+.B cbc_crypt(\|)
+implement the
+.SM NBS
+.SM DES
+(Data Encryption Standard).
+These routines are faster and more general purpose than
+.BR crypt (3).
+They also are able to utilize
+.SM DES
+hardware if it is available.
+.B ecb_crypt(\|)
+encrypts in
+.SM ECB
+(Electronic Code Book)
+mode, which encrypts blocks of data independently.
+.B cbc_crypt(\|)
+encrypts in
+.SM CBC
+(Cipher Block Chaining)
+mode, which chains together
+successive blocks.
+.SM CBC
+mode protects against insertions, deletions and
+substitutions of blocks. Also, regularities in the clear text will
+not appear in the cipher text.
+.LP
+Here is how to use these routines. The first parameter,
+.IR key ,
+is the 8-byte encryption key with parity.
+To set the key's parity, which for
+.SM DES
+is in the low bit of each byte, use
+.IR des_setparity .
+The second parameter,
+.IR data ,
+contains the data to be encrypted or decrypted. The
+third parameter,
+.IR datalen ,
+is the length in bytes of
+.IR data ,
+which must be a multiple of 8. The fourth parameter,
+.IR mode ,
+is formed by
+.SM OR\s0'ing
+together some things. For the encryption direction 'or' in either
+.SM DES_ENCRYPT
+or
+.SM DES_DECRYPT\s0.
+For software versus hardware
+encryption, 'or' in either
+.SM DES_HW
+or
+.SM DES_SW\s0.
+If
+.SM DES_HW
+is specified, and there is no hardware, then the encryption is performed
+in software and the routine returns
+.SM DESERR_NOHWDEVICE\s0.
+For
+.IR cbc_crypt ,
+the parameter
+.I ivec
+is the the 8-byte initialization
+vector for the chaining. It is updated to the next initialization
+vector upon return.
+.LP
+.SH "SEE ALSO"
+.BR des (1),
+.BR crypt (3)
+.SH DIAGNOSTICS
+.PD 0
+.TP 20
+.SM DESERR_NONE
+No error.
+.TP
+.SM DESERR_NOHWDEVICE
+Encryption succeeded, but done in software instead of the requested hardware.
+.TP
+.SM DESERR_HWERR
+An error occurred in the hardware or driver.
+.TP
+.SM DESERR_BADPARAM
+Bad parameter to routine.
+.PD
+.LP
+Given a result status
+.IR stat ,
+the macro
+.SM DES_FAILED\c
+.BR ( stat )
+is false only for the first two statuses.
+.SH RESTRICTIONS
+These routines are not available in RPCSRC 4.0.
+This information is provided to describe the DES interface expected by
+Secure RPC.
diff --git a/lib/libc/rpc/des_crypt.c b/lib/libc/rpc/des_crypt.c
new file mode 100644
index 0000000..18c9972
--- /dev/null
+++ b/lib/libc/rpc/des_crypt.c
@@ -0,0 +1,153 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+/*
+ * des_crypt.c, DES encryption library routines
+ * Copyright (C) 1986, Sun Microsystems, Inc.
+ */
+
+#include <sys/types.h>
+#include <rpc/des_crypt.h>
+#include <rpc/des.h>
+
+#ifndef lint
+/* from: static char sccsid[] = "@(#)des_crypt.c 2.2 88/08/10 4.0 RPCSRC; from 1.13 88/02/08 SMI"; */
+static const char rcsid[] = "$Id$";
+#endif
+
+static int common_crypt __P(( char *, char *, register unsigned, unsigned, struct desparams * ));
+int (*__des_crypt_LOCAL)() = 0;
+extern _des_crypt_call __P(( char *, int, struct desparams * ));
+/*
+ * Copy 8 bytes
+ */
+#define COPY8(src, dst) { \
+ register char *a = (char *) dst; \
+ register char *b = (char *) src; \
+ *a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
+ *a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
+}
+
+/*
+ * Copy multiple of 8 bytes
+ */
+#define DESCOPY(src, dst, len) { \
+ register char *a = (char *) dst; \
+ register char *b = (char *) src; \
+ register int i; \
+ for (i = (int) len; i > 0; i -= 8) { \
+ *a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
+ *a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
+ } \
+}
+
+/*
+ * CBC mode encryption
+ */
+int
+cbc_crypt(key, buf, len, mode, ivec)
+ char *key;
+ char *buf;
+ unsigned len;
+ unsigned mode;
+ char *ivec;
+{
+ int err;
+ struct desparams dp;
+
+#ifdef BROKEN_DES
+ dp.UDES.UDES_buf = buf;
+ dp.des_mode = ECB;
+#else
+ dp.des_mode = CBC;
+#endif
+ COPY8(ivec, dp.des_ivec);
+ err = common_crypt(key, buf, len, mode, &dp);
+ COPY8(dp.des_ivec, ivec);
+ return(err);
+}
+
+
+/*
+ * ECB mode encryption
+ */
+int
+ecb_crypt(key, buf, len, mode)
+ char *key;
+ char *buf;
+ unsigned len;
+ unsigned mode;
+{
+ struct desparams dp;
+
+#ifdef BROKEN_DES
+ dp.UDES.UDES_buf = buf;
+ dp.des_mode = CBC;
+#else
+ dp.des_mode = ECB;
+#endif
+ return(common_crypt(key, buf, len, mode, &dp));
+}
+
+
+
+/*
+ * Common code to cbc_crypt() & ecb_crypt()
+ */
+static int
+common_crypt(key, buf, len, mode, desp)
+ char *key;
+ char *buf;
+ register unsigned len;
+ unsigned mode;
+ register struct desparams *desp;
+{
+ register int desdev;
+
+ if ((len % 8) != 0 || len > DES_MAXDATA) {
+ return(DESERR_BADPARAM);
+ }
+ desp->des_dir =
+ ((mode & DES_DIRMASK) == DES_ENCRYPT) ? ENCRYPT : DECRYPT;
+
+ desdev = mode & DES_DEVMASK;
+ COPY8(key, desp->des_key);
+ /*
+ * software
+ */
+ if (__des_crypt_LOCAL != NULL) {
+ if (!__des_crypt_LOCAL(buf, len, desp)) {
+ return (DESERR_HWERROR);
+ }
+ } else {
+ if (!_des_crypt_call(buf, len, desp)) {
+ return (DESERR_HWERROR);
+ }
+ }
+ return(desdev == DES_SW ? DESERR_NONE : DESERR_NOHWDEVICE);
+}
diff --git a/lib/libc/rpc/des_soft.c b/lib/libc/rpc/des_soft.c
new file mode 100644
index 0000000..01dd7f2
--- /dev/null
+++ b/lib/libc/rpc/des_soft.c
@@ -0,0 +1,67 @@
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)des_soft.c 2.2 88/08/10 4.0 RPCSRC; from 1.13 88/02/08 SMI";
+#endif
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+/*
+ * Table giving odd parity in the low bit for ASCII characters
+ */
+static char partab[128] = {
+ 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x07, 0x07,
+ 0x08, 0x08, 0x0b, 0x0b, 0x0d, 0x0d, 0x0e, 0x0e,
+ 0x10, 0x10, 0x13, 0x13, 0x15, 0x15, 0x16, 0x16,
+ 0x19, 0x19, 0x1a, 0x1a, 0x1c, 0x1c, 0x1f, 0x1f,
+ 0x20, 0x20, 0x23, 0x23, 0x25, 0x25, 0x26, 0x26,
+ 0x29, 0x29, 0x2a, 0x2a, 0x2c, 0x2c, 0x2f, 0x2f,
+ 0x31, 0x31, 0x32, 0x32, 0x34, 0x34, 0x37, 0x37,
+ 0x38, 0x38, 0x3b, 0x3b, 0x3d, 0x3d, 0x3e, 0x3e,
+ 0x40, 0x40, 0x43, 0x43, 0x45, 0x45, 0x46, 0x46,
+ 0x49, 0x49, 0x4a, 0x4a, 0x4c, 0x4c, 0x4f, 0x4f,
+ 0x51, 0x51, 0x52, 0x52, 0x54, 0x54, 0x57, 0x57,
+ 0x58, 0x58, 0x5b, 0x5b, 0x5d, 0x5d, 0x5e, 0x5e,
+ 0x61, 0x61, 0x62, 0x62, 0x64, 0x64, 0x67, 0x67,
+ 0x68, 0x68, 0x6b, 0x6b, 0x6d, 0x6d, 0x6e, 0x6e,
+ 0x70, 0x70, 0x73, 0x73, 0x75, 0x75, 0x76, 0x76,
+ 0x79, 0x79, 0x7a, 0x7a, 0x7c, 0x7c, 0x7f, 0x7f,
+};
+
+/*
+ * Add odd parity to low bit of 8 byte key
+ */
+void
+des_setparity(p)
+ char *p;
+{
+ int i;
+
+ for (i = 0; i < 8; i++) {
+ *p = partab[*p & 0x7f];
+ p++;
+ }
+}
diff --git a/lib/libc/rpc/get_myaddress.c b/lib/libc/rpc/get_myaddress.c
new file mode 100644
index 0000000..a96b84b
--- /dev/null
+++ b/lib/libc/rpc/get_myaddress.c
@@ -0,0 +1,109 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)get_myaddress.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: get_myaddress.c,v 1.11 1997/05/28 05:05:11 wpaul Exp $";
+#endif
+
+/*
+ * get_myaddress.c
+ *
+ * Get client's IP address via ioctl. This avoids using the yellowpages.
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/pmap_prot.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/*
+ * don't use gethostbyname, which would invoke yellow pages
+ *
+ * Avoid loopback interfaces. We return information from a loopback
+ * interface only if there are no other possible interfaces.
+ */
+int
+get_myaddress(addr)
+ struct sockaddr_in *addr;
+{
+ int s;
+ char buf[BUFSIZ];
+ struct ifconf ifc;
+ struct ifreq ifreq, *ifr, *end;
+ int loopback = 0, gotit = 0;
+
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ return(-1);
+ }
+ ifc.ifc_len = sizeof (buf);
+ ifc.ifc_buf = buf;
+ if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
+ close(s);
+ return(-1);
+ }
+again:
+ ifr = ifc.ifc_req;
+ end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
+
+ while (ifr < end) {
+ ifreq = *ifr;
+ if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
+ close(s);
+ return(-1);
+ }
+ if (((ifreq.ifr_flags & IFF_UP) &&
+ ifr->ifr_addr.sa_family == AF_INET) ||
+ (loopback == 1 && (ifreq.ifr_flags & IFF_LOOPBACK))) {
+ *addr = *((struct sockaddr_in *)&ifr->ifr_addr);
+ addr->sin_port = htons(PMAPPORT);
+ gotit = 1;
+ break;
+ }
+ if (ifr->ifr_addr.sa_len)
+ ifr = (struct ifreq *) ((caddr_t) ifr +
+ ifr->ifr_addr.sa_len -
+ sizeof(struct sockaddr));
+ ifr++;
+ }
+ if (gotit == 0 && loopback == 0) {
+ loopback = 1;
+ goto again;
+ }
+ (void) close(s);
+ return (0);
+}
diff --git a/lib/libc/rpc/getrpcent.3 b/lib/libc/rpc/getrpcent.3
new file mode 100644
index 0000000..d2ea355
--- /dev/null
+++ b/lib/libc/rpc/getrpcent.3
@@ -0,0 +1,96 @@
+.\" @(#)getrpcent.3n 2.2 88/08/02 4.0 RPCSRC; from 1.11 88/03/14 SMI
+.Dd December 14, 1987
+.Dt GETRPCENT 3
+.Os
+.Sh NAME
+.Nm getrpcent ,
+.Nm getrpcbyname ,
+.Nm getrpcbynumber ,
+.Nm endrpcent ,
+.Nm setrpcent
+.Nd get RPC entry
+.Sh SYNOPSIS
+.Fd #include <rpc/rpc.h>
+.Ft struct rpcent *
+.Fn getrpcent void
+.Ft struct rpcent *
+.Fn getrpcbyname "char *name"
+.Ft struct rpcent *
+.Fn getrpcbynumber "int number"
+.Ft void
+.Fn setrpcent "int stayopen"
+.Ft void
+.Fn endrpcent void
+.Sh DESCRIPTION
+The
+.Fn getrpcent ,
+.Fn getrpcbyname ,
+and
+.Fn getrpcbynumber
+functions each return a pointer to an object with the
+following structure
+containing the broken-out
+fields of a line in the rpc program number data base,
+.Pa /etc/rpc .
+.Bd -literal
+
+struct rpcent {
+ char *r_name; /* name of server for this rpc program */
+ char **r_aliases; /* alias list */
+ long r_number; /* rpc program number */
+};
+.Ed
+.Pp
+The members of this structure are:
+.Bl -tag -width r_aliasesxxx
+.It Fa r_name
+The name of the server for this rpc program.
+.It Fa r_aliases
+A zero terminated list of alternate names for the rpc program.
+.It Fa r_number
+The rpc program number for this service.
+.El
+.Pp
+The
+.Fn getrpcent
+function reads the next line of the file, opening the file if necessary.
+The
+.Nm getrpcent
+function opens and rewinds the file. If the
+.Fa stayopen
+flag is non-zero,
+the net data base will not be closed after each call to
+.Fn getrpcent
+(either directly, or indirectly through one of
+the other
+.Fn getrpcent
+function family.
+.Pp
+.Fn endrpcent
+closes the file.
+.Pp
+.Fn getrpcbyname
+and
+.Fn getrpcbynumber
+sequentially search from the beginning
+of the file until a matching rpc program name or
+program number is found, or until end-of-file is encountered.
+.Sh FILES
+.Bl -tag -width /etc/rpc -compact
+.It Pa /etc/rpc
+.El
+.Sh "SEE ALSO"
+.Xr rpc 5 ,
+.Xr rpcinfo 8 ,
+.Xr ypserv 8
+.Sh DIAGNOSTICS
+A
+.Dv NULL
+pointer is returned on
+.Dv EOF
+or error.
+.Sh BUGS
+All information
+is contained in a static area
+so it must be copied if it is
+to be saved.
diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c
new file mode 100644
index 0000000..8266285
--- /dev/null
+++ b/lib/libc/rpc/getrpcent.c
@@ -0,0 +1,303 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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 or with the express written consent of
+ * Sun Microsystems, Inc.
+ *
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro";*/
+static char *rcsid = "$Id: getrpcent.c,v 1.6 1996/12/30 14:42:31 peter Exp $";
+#endif
+
+/*
+ * Copyright (c) 1984 by Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#ifdef YP
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+
+/*
+ * Internet version.
+ */
+struct rpcdata {
+ FILE *rpcf;
+ int stayopen;
+#define MAXALIASES 35
+ char *rpc_aliases[MAXALIASES];
+ struct rpcent rpc;
+ char line[BUFSIZ+1];
+#ifdef YP
+ char *domain;
+ char *current;
+ int currentlen;
+#endif
+} *rpcdata;
+
+#ifdef YP
+static int __yp_nomap = 0;
+extern int _yp_check(char **);
+#endif /* YP */
+
+static struct rpcent *interpret();
+struct hostent *gethostent();
+char *inet_ntoa();
+
+static char RPCDB[] = "/etc/rpc";
+
+static struct rpcdata *
+_rpcdata()
+{
+ register struct rpcdata *d = rpcdata;
+
+ if (d == 0) {
+ d = (struct rpcdata *)calloc(1, sizeof (struct rpcdata));
+ rpcdata = d;
+ }
+ return (d);
+}
+
+struct rpcent *
+getrpcbynumber(number)
+ register int number;
+{
+ register struct rpcdata *d = _rpcdata();
+ register struct rpcent *p;
+#ifdef YP
+ int reason;
+ char adrstr[16];
+#endif
+
+ if (d == 0)
+ return (0);
+#ifdef YP
+ if (!__yp_nomap && _yp_check(&d->domain)) {
+ sprintf(adrstr, "%d", number);
+ reason = yp_match(d->domain, "rpc.bynumber", adrstr, strlen(adrstr),
+ &d->current, &d->currentlen);
+ switch(reason) {
+ case 0:
+ break;
+ case YPERR_MAP:
+ __yp_nomap = 1;
+ goto no_yp;
+ break;
+ default:
+ return(0);
+ break;
+ }
+ d->current[d->currentlen] = '\0';
+ p = interpret(d->current, d->currentlen);
+ (void) free(d->current);
+ return p;
+ }
+no_yp:
+#endif /* YP */
+ setrpcent(0);
+ while ((p = getrpcent())) {
+ if (p->r_number == number)
+ break;
+ }
+ endrpcent();
+ return (p);
+}
+
+struct rpcent *
+getrpcbyname(name)
+ char *name;
+{
+ struct rpcent *rpc = NULL;
+ char **rp;
+
+ setrpcent(0);
+ while ((rpc = getrpcent())) {
+ if (strcmp(rpc->r_name, name) == 0)
+ goto done;
+ for (rp = rpc->r_aliases; *rp != NULL; rp++) {
+ if (strcmp(*rp, name) == 0)
+ goto done;
+ }
+ }
+done:
+ endrpcent();
+ return (rpc);
+}
+
+void
+setrpcent(f)
+ int f;
+{
+ register struct rpcdata *d = _rpcdata();
+
+ if (d == 0)
+ return;
+#ifdef YP
+ if (!__yp_nomap && _yp_check(NULL)) {
+ if (d->current)
+ free(d->current);
+ d->current = NULL;
+ d->currentlen = 0;
+ return;
+ }
+ __yp_nomap = 0;
+#endif /* YP */
+ if (d->rpcf == NULL)
+ d->rpcf = fopen(RPCDB, "r");
+ else
+ rewind(d->rpcf);
+ d->stayopen |= f;
+}
+
+void
+endrpcent()
+{
+ register struct rpcdata *d = _rpcdata();
+
+ if (d == 0)
+ return;
+#ifdef YP
+ if (!__yp_nomap && _yp_check(NULL)) {
+ if (d->current && !d->stayopen)
+ free(d->current);
+ d->current = NULL;
+ d->currentlen = 0;
+ return;
+ }
+ __yp_nomap = 0;
+#endif /* YP */
+ if (d->rpcf && !d->stayopen) {
+ fclose(d->rpcf);
+ d->rpcf = NULL;
+ }
+}
+
+struct rpcent *
+getrpcent()
+{
+ register struct rpcdata *d = _rpcdata();
+#ifdef YP
+ struct rpcent *hp;
+ int reason;
+ char *val = NULL;
+ int vallen;
+#endif
+
+ if (d == 0)
+ return(NULL);
+#ifdef YP
+ if (!__yp_nomap && _yp_check(&d->domain)) {
+ if (d->current == NULL && d->currentlen == 0) {
+ reason = yp_first(d->domain, "rpc.bynumber",
+ &d->current, &d->currentlen,
+ &val, &vallen);
+ } else {
+ reason = yp_next(d->domain, "rpc.bynumber",
+ d->current, d->currentlen,
+ &d->current, &d->currentlen,
+ &val, &vallen);
+ }
+ switch(reason) {
+ case 0:
+ break;
+ case YPERR_MAP:
+ __yp_nomap = 1;
+ goto no_yp;
+ break;
+ default:
+ return(0);
+ break;
+ }
+ val[vallen] = '\0';
+ hp = interpret(val, vallen);
+ (void) free(val);
+ return hp;
+ }
+no_yp:
+#endif /* YP */
+ if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
+ return (NULL);
+ /* -1 so there is room to append a \n below */
+ if (fgets(d->line, BUFSIZ - 1, d->rpcf) == NULL)
+ return (NULL);
+ return (interpret(d->line, strlen(d->line)));
+}
+
+static struct rpcent *
+interpret(val, len)
+ char *val;
+ int len;
+{
+ register struct rpcdata *d = _rpcdata();
+ char *p;
+ register char *cp, **q;
+
+ if (d == 0)
+ return (0);
+ (void) strncpy(d->line, val, BUFSIZ);
+ d->line[BUFSIZ] = '\0';
+ p = d->line;
+ p[len] = '\n';
+ if (*p == '#')
+ return (getrpcent());
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ return (getrpcent());
+ *cp = '\0';
+ cp = strpbrk(p, " \t");
+ if (cp == NULL)
+ return (getrpcent());
+ *cp++ = '\0';
+ /* THIS STUFF IS INTERNET SPECIFIC */
+ d->rpc.r_name = d->line;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ d->rpc.r_number = atoi(cp);
+ q = d->rpc.r_aliases = d->rpc_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &(d->rpc_aliases[MAXALIASES - 1]))
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&d->rpc);
+}
+
diff --git a/lib/libc/rpc/getrpcport.3 b/lib/libc/rpc/getrpcport.3
new file mode 100644
index 0000000..8f4ebed
--- /dev/null
+++ b/lib/libc/rpc/getrpcport.3
@@ -0,0 +1,29 @@
+.\" @(#)getrpcport.3r 2.2 88/08/02 4.0 RPCSRC; from 1.12 88/02/26 SMI
+.Dd October 6, 1987
+.Dt GETRPCPORT 3
+.Os
+.Sh NAME
+.Nm getrpcport
+.Nd get RPC port number
+.Sh SYNOPSIS
+.Ft int
+.Fn getrpcport "char *host" "int prognum" "int versnum" "int proto"
+.Sh DESCRIPTION
+.Fn getrpcport
+returns the port number for version
+.Fa versnum
+of the RPC program
+.Fa prognum
+running on
+.Fa host
+and using protocol
+.Fa proto .
+It returns 0 if it cannot contact the portmapper, or if
+.Fa prognum
+is not registered. If
+.Fa prognum
+is registered but not with version
+.Fa versnum ,
+it will still return a port number (for some version of the program)
+indicating that the program is indeed registered.
+The version mismatch will be detected upon the first call to the service.
diff --git a/lib/libc/rpc/getrpcport.c b/lib/libc/rpc/getrpcport.c
new file mode 100644
index 0000000..04a8de2
--- /dev/null
+++ b/lib/libc/rpc/getrpcport.c
@@ -0,0 +1,63 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)getrpcport.c 1.3 87/08/11 SMI";*/
+/*static char *sccsid = "from: @(#)getrpcport.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: getrpcport.c,v 1.6 1996/12/30 14:43:42 peter Exp $";
+#endif
+
+/*
+ * Copyright (c) 1985 by Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+#include <netdb.h>
+#include <sys/socket.h>
+
+int
+getrpcport(host, prognum, versnum, proto)
+ char *host;
+ int prognum, versnum, proto;
+{
+ struct sockaddr_in addr;
+ struct hostent *hp;
+
+ if ((hp = gethostbyname(host)) == NULL)
+ return (0);
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_len = sizeof(struct sockaddr_in);
+ addr.sin_family = AF_INET;
+ addr.sin_port = 0;
+ memcpy((char *)&addr.sin_addr, hp->h_addr, hp->h_length);
+ return (pmap_getport(&addr, prognum, versnum, proto));
+}
diff --git a/lib/libc/rpc/key_call.c b/lib/libc/rpc/key_call.c
new file mode 100644
index 0000000..bcef22e
--- /dev/null
+++ b/lib/libc/rpc/key_call.c
@@ -0,0 +1,425 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+/*
+ * Copyright (c) 1986-1991 by Sun Microsystems Inc.
+ */
+
+#ident "@(#)key_call.c 1.25 94/04/24 SMI"
+
+/*
+ * key_call.c, Interface to keyserver
+ *
+ * setsecretkey(key) - set your secret key
+ * encryptsessionkey(agent, deskey) - encrypt a session key to talk to agent
+ * decryptsessionkey(agent, deskey) - decrypt ditto
+ * gendeskey(deskey) - generate a secure des key
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <rpc/rpc.h>
+#include <rpc/auth.h>
+#include <rpc/auth_unix.h>
+#include <rpc/key_prot.h>
+#include <string.h>
+#include <sys/utsname.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <sys/fcntl.h>
+
+
+#define KEY_TIMEOUT 5 /* per-try timeout in seconds */
+#define KEY_NRETRY 12 /* number of retries */
+
+#ifdef DEBUG
+#define debug(msg) (void) fprintf(stderr, "%s\n", msg);
+#else
+#define debug(msg)
+#endif /* DEBUG */
+
+/*
+ * Hack to allow the keyserver to use AUTH_DES (for authenticated
+ * NIS+ calls, for example). The only functions that get called
+ * are key_encryptsession_pk, key_decryptsession_pk, and key_gendes.
+ *
+ * The approach is to have the keyserver fill in pointers to local
+ * implementations of these functions, and to call those in key_call().
+ */
+
+cryptkeyres *(*__key_encryptsession_pk_LOCAL)() = 0;
+cryptkeyres *(*__key_decryptsession_pk_LOCAL)() = 0;
+des_block *(*__key_gendes_LOCAL)() = 0;
+
+static int key_call __P(( u_long, xdrproc_t, char *, xdrproc_t, char * ));
+
+int
+key_setsecret(secretkey)
+ const char *secretkey;
+{
+ keystatus status;
+
+ if (!key_call((u_long) KEY_SET, xdr_keybuf, (char *) secretkey,
+ xdr_keystatus, (char *)&status)) {
+ return (-1);
+ }
+ if (status != KEY_SUCCESS) {
+ debug("set status is nonzero");
+ return (-1);
+ }
+ return (0);
+}
+
+
+/* key_secretkey_is_set() returns 1 if the keyserver has a secret key
+ * stored for the caller's effective uid; it returns 0 otherwise
+ *
+ * N.B.: The KEY_NET_GET key call is undocumented. Applications shouldn't
+ * be using it, because it allows them to get the user's secret key.
+ */
+
+int
+key_secretkey_is_set(void)
+{
+ struct key_netstres kres;
+
+ memset((void*)&kres, 0, sizeof (kres));
+ if (key_call((u_long) KEY_NET_GET, xdr_void, (char *)NULL,
+ xdr_key_netstres, (char *) &kres) &&
+ (kres.status == KEY_SUCCESS) &&
+ (kres.key_netstres_u.knet.st_priv_key[0] != 0)) {
+ /* avoid leaving secret key in memory */
+ memset(kres.key_netstres_u.knet.st_priv_key, 0, HEXKEYBYTES);
+ return (1);
+ }
+ return (0);
+}
+
+int
+key_encryptsession_pk(remotename, remotekey, deskey)
+ char *remotename;
+ netobj *remotekey;
+ des_block *deskey;
+{
+ cryptkeyarg2 arg;
+ cryptkeyres res;
+
+ arg.remotename = remotename;
+ arg.remotekey = *remotekey;
+ arg.deskey = *deskey;
+ if (!key_call((u_long)KEY_ENCRYPT_PK, xdr_cryptkeyarg2, (char *)&arg,
+ xdr_cryptkeyres, (char *)&res)) {
+ return (-1);
+ }
+ if (res.status != KEY_SUCCESS) {
+ debug("encrypt status is nonzero");
+ return (-1);
+ }
+ *deskey = res.cryptkeyres_u.deskey;
+ return (0);
+}
+
+int
+key_decryptsession_pk(remotename, remotekey, deskey)
+ char *remotename;
+ netobj *remotekey;
+ des_block *deskey;
+{
+ cryptkeyarg2 arg;
+ cryptkeyres res;
+
+ arg.remotename = remotename;
+ arg.remotekey = *remotekey;
+ arg.deskey = *deskey;
+ if (!key_call((u_long)KEY_DECRYPT_PK, xdr_cryptkeyarg2, (char *)&arg,
+ xdr_cryptkeyres, (char *)&res)) {
+ return (-1);
+ }
+ if (res.status != KEY_SUCCESS) {
+ debug("decrypt status is nonzero");
+ return (-1);
+ }
+ *deskey = res.cryptkeyres_u.deskey;
+ return (0);
+}
+
+int
+key_encryptsession(remotename, deskey)
+ const char *remotename;
+ des_block *deskey;
+{
+ cryptkeyarg arg;
+ cryptkeyres res;
+
+ arg.remotename = (char *) remotename;
+ arg.deskey = *deskey;
+ if (!key_call((u_long)KEY_ENCRYPT, xdr_cryptkeyarg, (char *)&arg,
+ xdr_cryptkeyres, (char *)&res)) {
+ return (-1);
+ }
+ if (res.status != KEY_SUCCESS) {
+ debug("encrypt status is nonzero");
+ return (-1);
+ }
+ *deskey = res.cryptkeyres_u.deskey;
+ return (0);
+}
+
+int
+key_decryptsession(remotename, deskey)
+ const char *remotename;
+ des_block *deskey;
+{
+ cryptkeyarg arg;
+ cryptkeyres res;
+
+ arg.remotename = (char *) remotename;
+ arg.deskey = *deskey;
+ if (!key_call((u_long)KEY_DECRYPT, xdr_cryptkeyarg, (char *)&arg,
+ xdr_cryptkeyres, (char *)&res)) {
+ return (-1);
+ }
+ if (res.status != KEY_SUCCESS) {
+ debug("decrypt status is nonzero");
+ return (-1);
+ }
+ *deskey = res.cryptkeyres_u.deskey;
+ return (0);
+}
+
+int
+key_gendes(key)
+ des_block *key;
+{
+ if (!key_call((u_long)KEY_GEN, xdr_void, (char *)NULL,
+ xdr_des_block, (char *)key)) {
+ return (-1);
+ }
+ return (0);
+}
+
+int
+key_setnet(arg)
+struct netstarg *arg;
+{
+ keystatus status;
+
+
+ if (!key_call((u_long) KEY_NET_PUT, xdr_key_netstarg, (char *) arg,
+ xdr_keystatus, (char *) &status)){
+ return (-1);
+ }
+
+ if (status != KEY_SUCCESS) {
+ debug("key_setnet status is nonzero");
+ return (-1);
+ }
+ return (1);
+}
+
+
+int
+key_get_conv(pkey, deskey)
+ char *pkey;
+ des_block *deskey;
+{
+ cryptkeyres res;
+
+ if (!key_call((u_long) KEY_GET_CONV, xdr_keybuf, pkey,
+ xdr_cryptkeyres, (char *)&res)) {
+ return (-1);
+ }
+ if (res.status != KEY_SUCCESS) {
+ debug("get_conv status is nonzero");
+ return (-1);
+ }
+ *deskey = res.cryptkeyres_u.deskey;
+ return (0);
+}
+
+struct key_call_private {
+ CLIENT *client; /* Client handle */
+ pid_t pid; /* process-id at moment of creation */
+ uid_t uid; /* user-id at last authorization */
+};
+static struct key_call_private *key_call_private_main = NULL;
+
+#ifdef foo
+static void
+key_call_destroy(void *vp)
+{
+ register struct key_call_private *kcp = (struct key_call_private *)vp;
+
+ if (kcp) {
+ if (kcp->client)
+ clnt_destroy(kcp->client);
+ free(kcp);
+ }
+}
+#endif
+
+/*
+ * Keep the handle cached. This call may be made quite often.
+ */
+static CLIENT *
+getkeyserv_handle(vers)
+int vers;
+{
+ struct key_call_private *kcp = key_call_private_main;
+ struct timeval wait_time;
+ int fd;
+ struct sockaddr_un name;
+ int namelen = sizeof(struct sockaddr_un);
+
+#define TOTAL_TIMEOUT 30 /* total timeout talking to keyserver */
+#define TOTAL_TRIES 5 /* Number of tries */
+
+ if (kcp == (struct key_call_private *)NULL) {
+ kcp = (struct key_call_private *)malloc(sizeof (*kcp));
+ if (kcp == (struct key_call_private *)NULL) {
+ return ((CLIENT *) NULL);
+ }
+ key_call_private_main = kcp;
+ kcp->client = NULL;
+ }
+
+ /* if pid has changed, destroy client and rebuild */
+ if (kcp->client != NULL && kcp->pid != getpid()) {
+ clnt_destroy(kcp->client);
+ kcp->client = NULL;
+ }
+
+ if (kcp->client != NULL) {
+ /* if other side closed socket, build handle again */
+ clnt_control(kcp->client, CLGET_FD, (char *)&fd);
+ if (getpeername(fd,(struct sockaddr *)&name,&namelen) == -1) {
+ auth_destroy(kcp->client->cl_auth);
+ clnt_destroy(kcp->client);
+ kcp->client = NULL;
+ }
+ }
+
+ if (kcp->client != NULL) {
+ /* if uid has changed, build client handle again */
+ if (kcp->uid != geteuid()) {
+ kcp->uid = geteuid();
+ auth_destroy(kcp->client->cl_auth);
+ kcp->client->cl_auth =
+ authsys_create("", kcp->uid, 0, 0, NULL);
+ if (kcp->client->cl_auth == NULL) {
+ clnt_destroy(kcp->client);
+ kcp->client = NULL;
+ return ((CLIENT *) NULL);
+ }
+ }
+ /* Change the version number to the new one */
+ clnt_control(kcp->client, CLSET_VERS, (void *)&vers);
+ return (kcp->client);
+ }
+
+ if ((kcp->client == (CLIENT *) NULL))
+ /* Use the AF_UNIX transport */
+ kcp->client = clnt_create("/var/run/keyservsock", KEY_PROG,
+ vers, "unix");
+
+ if (kcp->client == (CLIENT *) NULL) {
+ return ((CLIENT *) NULL);
+ }
+ kcp->uid = geteuid();
+ kcp->pid = getpid();
+ kcp->client->cl_auth = authsys_create("", kcp->uid, 0, 0, NULL);
+ if (kcp->client->cl_auth == NULL) {
+ clnt_destroy(kcp->client);
+ kcp->client = NULL;
+ return ((CLIENT *) NULL);
+ }
+
+ wait_time.tv_sec = TOTAL_TIMEOUT/TOTAL_TRIES;
+ wait_time.tv_usec = 0;
+ (void) clnt_control(kcp->client, CLSET_RETRY_TIMEOUT,
+ (char *)&wait_time);
+ if (clnt_control(kcp->client, CLGET_FD, (char *)&fd))
+ fcntl(fd, F_SETFD, 1); /* make it "close on exec" */
+
+ return (kcp->client);
+}
+
+/* returns 0 on failure, 1 on success */
+
+static int
+key_call(proc, xdr_arg, arg, xdr_rslt, rslt)
+ u_long proc;
+ xdrproc_t xdr_arg;
+ char *arg;
+ xdrproc_t xdr_rslt;
+ char *rslt;
+{
+ CLIENT *clnt;
+ struct timeval wait_time;
+
+ if (proc == KEY_ENCRYPT_PK && __key_encryptsession_pk_LOCAL) {
+ cryptkeyres *res;
+ res = (*__key_encryptsession_pk_LOCAL)(geteuid(), arg);
+ *(cryptkeyres*)rslt = *res;
+ return (1);
+ } else if (proc == KEY_DECRYPT_PK && __key_decryptsession_pk_LOCAL) {
+ cryptkeyres *res;
+ res = (*__key_decryptsession_pk_LOCAL)(geteuid(), arg);
+ *(cryptkeyres*)rslt = *res;
+ return (1);
+ } else if (proc == KEY_GEN && __key_gendes_LOCAL) {
+ des_block *res;
+ res = (*__key_gendes_LOCAL)(geteuid(), 0);
+ *(des_block*)rslt = *res;
+ return (1);
+ }
+
+ if ((proc == KEY_ENCRYPT_PK) || (proc == KEY_DECRYPT_PK) ||
+ (proc == KEY_NET_GET) || (proc == KEY_NET_PUT) ||
+ (proc == KEY_GET_CONV))
+ clnt = getkeyserv_handle(2); /* talk to version 2 */
+ else
+ clnt = getkeyserv_handle(1); /* talk to version 1 */
+
+ if (clnt == NULL) {
+ return (0);
+ }
+
+ wait_time.tv_sec = TOTAL_TIMEOUT;
+ wait_time.tv_usec = 0;
+
+ if (clnt_call(clnt, proc, xdr_arg, arg, xdr_rslt, rslt,
+ wait_time) == RPC_SUCCESS) {
+ return (1);
+ } else {
+ return (0);
+ }
+}
diff --git a/lib/libc/rpc/key_prot_xdr.c b/lib/libc/rpc/key_prot_xdr.c
new file mode 100644
index 0000000..8cd6b6b
--- /dev/null
+++ b/lib/libc/rpc/key_prot_xdr.c
@@ -0,0 +1,166 @@
+/*
+ * Please do not edit this file.
+ * It was generated using rpcgen.
+ */
+
+#include <rpc/key_prot.h>
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+#pragma ident "@(#)key_prot.x 1.7 94/04/29 SMI"
+
+/* Copyright (c) 1990, 1991 Sun Microsystems, Inc. */
+
+/*
+ * Compiled from key_prot.x using rpcgen.
+ * DO NOT EDIT THIS FILE!
+ * This is NOT source code!
+ */
+
+bool_t
+xdr_keystatus(register XDR *xdrs, keystatus *objp)
+{
+
+ if (!xdr_enum(xdrs, (enum_t *)objp))
+ return (FALSE);
+ return (TRUE);
+}
+
+bool_t
+xdr_keybuf(register XDR *xdrs, keybuf objp)
+{
+
+ if (!xdr_opaque(xdrs, objp, HEXKEYBYTES))
+ return (FALSE);
+ return (TRUE);
+}
+
+bool_t
+xdr_netnamestr(register XDR *xdrs, netnamestr *objp)
+{
+
+ if (!xdr_string(xdrs, objp, MAXNETNAMELEN))
+ return (FALSE);
+ return (TRUE);
+}
+
+bool_t
+xdr_cryptkeyarg(register XDR *xdrs, cryptkeyarg *objp)
+{
+
+ if (!xdr_netnamestr(xdrs, &objp->remotename))
+ return (FALSE);
+ if (!xdr_des_block(xdrs, &objp->deskey))
+ return (FALSE);
+ return (TRUE);
+}
+
+bool_t
+xdr_cryptkeyarg2(register XDR *xdrs, cryptkeyarg2 *objp)
+{
+
+ if (!xdr_netnamestr(xdrs, &objp->remotename))
+ return (FALSE);
+ if (!xdr_netobj(xdrs, &objp->remotekey))
+ return (FALSE);
+ if (!xdr_des_block(xdrs, &objp->deskey))
+ return (FALSE);
+ return (TRUE);
+}
+
+bool_t
+xdr_cryptkeyres(register XDR *xdrs, cryptkeyres *objp)
+{
+
+ if (!xdr_keystatus(xdrs, &objp->status))
+ return (FALSE);
+ switch (objp->status) {
+ case KEY_SUCCESS:
+ if (!xdr_des_block(xdrs, &objp->cryptkeyres_u.deskey))
+ return (FALSE);
+ break;
+ }
+ return (TRUE);
+}
+
+bool_t
+xdr_unixcred(register XDR *xdrs, unixcred *objp)
+{
+
+ if (!xdr_u_int(xdrs, &objp->uid))
+ return (FALSE);
+ if (!xdr_u_int(xdrs, &objp->gid))
+ return (FALSE);
+ if (!xdr_array(xdrs, (char **)&objp->gids.gids_val, (u_int *) &objp->gids.gids_len, MAXGIDS,
+ sizeof (u_int), (xdrproc_t) xdr_u_int))
+ return (FALSE);
+ return (TRUE);
+}
+
+bool_t
+xdr_getcredres(register XDR *xdrs, getcredres *objp)
+{
+
+ if (!xdr_keystatus(xdrs, &objp->status))
+ return (FALSE);
+ switch (objp->status) {
+ case KEY_SUCCESS:
+ if (!xdr_unixcred(xdrs, &objp->getcredres_u.cred))
+ return (FALSE);
+ break;
+ }
+ return (TRUE);
+}
+
+bool_t
+xdr_key_netstarg(register XDR *xdrs, key_netstarg *objp)
+{
+
+ if (!xdr_keybuf(xdrs, objp->st_priv_key))
+ return (FALSE);
+ if (!xdr_keybuf(xdrs, objp->st_pub_key))
+ return (FALSE);
+ if (!xdr_netnamestr(xdrs, &objp->st_netname))
+ return (FALSE);
+ return (TRUE);
+}
+
+bool_t
+xdr_key_netstres(register XDR *xdrs, key_netstres *objp)
+{
+
+ if (!xdr_keystatus(xdrs, &objp->status))
+ return (FALSE);
+ switch (objp->status) {
+ case KEY_SUCCESS:
+ if (!xdr_key_netstarg(xdrs, &objp->key_netstres_u.knet))
+ return (FALSE);
+ break;
+ }
+ return (TRUE);
+}
diff --git a/lib/libc/rpc/netname.c b/lib/libc/rpc/netname.c
new file mode 100644
index 0000000..3a3942b
--- /dev/null
+++ b/lib/libc/rpc/netname.c
@@ -0,0 +1,136 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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 or with the express written consent of
+ * Sun Microsystems, Inc.
+ *
+ * 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
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)netname.c 1.8 91/03/11 Copyr 1986 Sun Micro";
+#endif
+
+/*
+ * netname utility routines
+ * convert from unix names to network names and vice-versa
+ * This module is operating system dependent!
+ * What we define here will work with any unix system that has adopted
+ * the sun NIS domain architecture.
+ */
+
+#include <sys/param.h>
+#include <rpc/rpc.h>
+#include <rpc/rpc_com.h>
+#ifdef YP
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+#ifndef MAXHOSTNAMELEN
+#define MAXHOSTNAMELEN 256
+#endif
+#ifndef NGROUPS
+#define NGROUPS 16
+#endif
+
+static char *OPSYS = "unix";
+
+/*
+ * Figure out my fully qualified network name
+ */
+int
+getnetname(name)
+ char name[MAXNETNAMELEN+1];
+{
+ uid_t uid;
+
+ uid = geteuid();
+ if (uid == 0) {
+ return (host2netname(name, (char *) NULL, (char *) NULL));
+ } else {
+ return (user2netname(name, uid, (char *) NULL));
+ }
+}
+
+
+/*
+ * Convert unix cred to network-name
+ */
+int
+user2netname(netname, uid, domain)
+ char netname[MAXNETNAMELEN + 1];
+ uid_t uid;
+ char *domain;
+{
+ char *dfltdom;
+
+#define MAXIPRINT (11) /* max length of printed integer */
+
+ if (domain == NULL) {
+ if (_rpc_get_default_domain(&dfltdom) != 0) {
+ return (0);
+ }
+ domain = dfltdom;
+ }
+ if (strlen(domain) + 1 + MAXIPRINT > MAXNETNAMELEN) {
+ return (0);
+ }
+ (void) sprintf(netname, "%s.%ld@%s", OPSYS, uid, domain);
+ return (1);
+}
+
+
+/*
+ * Convert host to network-name
+ */
+int
+host2netname(netname, host, domain)
+ char netname[MAXNETNAMELEN + 1];
+ char *host;
+ char *domain;
+{
+ char *dfltdom;
+ char hostname[MAXHOSTNAMELEN+1];
+
+ if (domain == NULL) {
+ if (_rpc_get_default_domain(&dfltdom) != 0) {
+ return (0);
+ }
+ domain = dfltdom;
+ }
+ if (host == NULL) {
+ (void) gethostname(hostname, sizeof(hostname));
+ host = hostname;
+ }
+ if (strlen(domain) + 1 + strlen(host) > MAXNETNAMELEN) {
+ return (0);
+ }
+ (void) sprintf(netname, "%s.%s@%s", OPSYS, host, domain);
+ return (1);
+}
diff --git a/lib/libc/rpc/netnamer.c b/lib/libc/rpc/netnamer.c
new file mode 100644
index 0000000..41c5146
--- /dev/null
+++ b/lib/libc/rpc/netnamer.c
@@ -0,0 +1,327 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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 or with the express written consent of
+ * Sun Microsystems, Inc.
+ *
+ * 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
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)netnamer.c 1.13 91/03/11 Copyr 1986 Sun Micro";
+#endif
+/*
+ * netname utility routines convert from unix names to network names and
+ * vice-versa This module is operating system dependent! What we define here
+ * will work with any unix system that has adopted the sun NIS domain
+ * architecture.
+ */
+#include <sys/param.h>
+#include <rpc/rpc.h>
+#include <rpc/rpc_com.h>
+#ifdef YP
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#endif
+#include <ctype.h>
+#include <stdio.h>
+#include <grp.h>
+#include <pwd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static char *OPSYS = "unix";
+static char *NETID = "netid.byname";
+static char *NETIDFILE = "/etc/netid";
+
+static int getnetid __P(( char *, char * ));
+static int _getgroups __P(( char *, gid_t * ));
+
+#ifndef NGROUPS
+#define NGROUPS 16
+#endif
+
+/*
+ * Convert network-name into unix credential
+ */
+int
+netname2user(netname, uidp, gidp, gidlenp, gidlist)
+ char netname[MAXNETNAMELEN + 1];
+ uid_t *uidp;
+ gid_t *gidp;
+ int *gidlenp;
+ gid_t *gidlist;
+{
+ char *p;
+ int gidlen;
+ uid_t uid;
+ struct passwd *pwd;
+ char val[1024];
+ char *val1, *val2;
+ char *domain;
+ int vallen;
+ int err;
+
+ if (getnetid(netname, val)) {
+ p = strtok(val, ":");
+ if (p == NULL)
+ return (0);
+ *uidp = (uid_t) atol(val);
+ p = strtok(NULL, "\n,");
+ *gidp = (gid_t) atol(p);
+ if (p == NULL) {
+ return (0);
+ }
+ gidlen = 0;
+ for (gidlen = 0; gidlen < NGROUPS; gidlen++) {
+ p = strtok(NULL, "\n,");
+ if (p == NULL)
+ break;
+ gidlist[gidlen] = (gid_t) atol(p);
+ }
+ *gidlenp = gidlen;
+
+ return (1);
+ }
+ val1 = strchr(netname, '.');
+ if (val1 == NULL)
+ return (0);
+ if (strncmp(netname, OPSYS, (val1-netname)))
+ return (0);
+ val1++;
+ val2 = strchr(val1, '@');
+ if (val2 == NULL)
+ return (0);
+ vallen = val2 - val1;
+ if (vallen > (1024 - 1))
+ vallen = 1024 - 1;
+ (void) strncpy(val, val1, 1024);
+ val[vallen] = 0;
+
+ err = _rpc_get_default_domain(&domain); /* change to rpc */
+ if (err)
+ return (0);
+
+ if (strcmp(val2 + 1, domain))
+ return (0); /* wrong domain */
+
+ /* XXX: uid_t have different sizes on different OS's. sigh! */
+ if (sizeof (uid_t) == sizeof (short)) {
+ if (sscanf(val, "%hd", (short *)&uid) != 1)
+ return (0);
+ } else {
+ if (sscanf(val, "%ld", &uid) != 1)
+ return (0);
+ }
+ /* use initgroups method */
+ pwd = getpwuid(uid);
+ if (pwd == NULL)
+ return (0);
+ *uidp = pwd->pw_uid;
+ *gidp = pwd->pw_gid;
+ *gidlenp = _getgroups(pwd->pw_name, gidlist);
+ return (1);
+}
+
+/*
+ * initgroups
+ */
+
+static int
+_getgroups(uname, groups)
+ char *uname;
+ gid_t groups[NGROUPS];
+{
+ gid_t ngroups = 0;
+ register struct group *grp;
+ register int i;
+ register int j;
+ int filter;
+
+ setgrent();
+ while ((grp = getgrent())) {
+ for (i = 0; grp->gr_mem[i]; i++)
+ if (!strcmp(grp->gr_mem[i], uname)) {
+ if (ngroups == NGROUPS) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "initgroups: %s is in too many groups\n", uname);
+#endif
+ goto toomany;
+ }
+ /* filter out duplicate group entries */
+ filter = 0;
+ for (j = 0; j < ngroups; j++)
+ if (groups[j] == grp->gr_gid) {
+ filter++;
+ break;
+ }
+ if (!filter)
+ groups[ngroups++] = grp->gr_gid;
+ }
+ }
+toomany:
+ endgrent();
+ return (ngroups);
+}
+
+/*
+ * Convert network-name to hostname
+ */
+int
+netname2host(netname, hostname, hostlen)
+ char netname[MAXNETNAMELEN + 1];
+ char *hostname;
+ int hostlen;
+{
+ int err;
+ char valbuf[1024];
+ char *val;
+ char *val2;
+ int vallen;
+ char *domain;
+
+ if (getnetid(netname, valbuf)) {
+ val = valbuf;
+ if ((*val == '0') && (val[1] == ':')) {
+ (void) strncpy(hostname, val + 2, hostlen);
+ return (1);
+ }
+ }
+ val = strchr(netname, '.');
+ if (val == NULL)
+ return (0);
+ if (strncmp(netname, OPSYS, (val - netname)))
+ return (0);
+ val++;
+ val2 = strchr(val, '@');
+ if (val2 == NULL)
+ return (0);
+ vallen = val2 - val;
+ if (vallen > (hostlen - 1))
+ vallen = hostlen - 1;
+ (void) strncpy(hostname, val, vallen);
+ hostname[vallen] = 0;
+
+ err = _rpc_get_default_domain(&domain); /* change to rpc */
+ if (err)
+ return (0);
+
+ if (strcmp(val2 + 1, domain))
+ return (0); /* wrong domain */
+ else
+ return (1);
+}
+
+/*
+ * reads the file /etc/netid looking for a + to optionally go to the
+ * network information service.
+ */
+int
+getnetid(key, ret)
+ char *key, *ret;
+{
+ char buf[1024]; /* big enough */
+ char *res;
+ char *mkey;
+ char *mval;
+ FILE *fd;
+#ifdef YP
+ char *domain;
+ int err;
+ char *lookup;
+ int len;
+#endif
+
+ fd = fopen(NETIDFILE, "r");
+ if (fd == (FILE *) 0) {
+#ifdef YP
+ res = "+";
+ goto getnetidyp;
+#else
+ return (0);
+#endif
+ }
+ for (;;) {
+ if (fd == (FILE *) 0)
+ return (0); /* getnetidyp brings us here */
+ res = fgets(buf, 1024, fd);
+ if (res == 0) {
+ fclose(fd);
+ return (0);
+ }
+ if (res[0] == '#')
+ continue;
+ else if (res[0] == '+') {
+#ifdef YP
+ getnetidyp:
+ err = yp_get_default_domain(&domain);
+ if (err) {
+ continue;
+ }
+ lookup = NULL;
+ err = yp_match(domain, NETID, key,
+ strlen(key), &lookup, &len);
+ if (err) {
+#ifdef DEBUG
+ fprintf(stderr, "match failed error %d\n", err);
+#endif
+ continue;
+ }
+ lookup[len] = 0;
+ strcpy(ret, lookup);
+ free(lookup);
+ if (fd != NULL)
+ fclose(fd);
+ return (2);
+#else /* YP */
+#ifdef DEBUG
+ fprintf(stderr,
+"Bad record in %s '+' -- NIS not supported in this library copy\n",
+ NETIDFILE);
+#endif
+ continue;
+#endif /* YP */
+ } else {
+ mkey = strtok(buf, "\t ");
+ if (mkey == NULL) {
+ fprintf(stderr,
+ "Bad record in %s -- %s", NETIDFILE, buf);
+ continue;
+ }
+ mval = strtok(NULL, " \t#\n");
+ if (mval == NULL) {
+ fprintf(stderr,
+ "Bad record in %s val problem - %s", NETIDFILE, buf);
+ continue;
+ }
+ if (strcmp(mkey, key) == 0) {
+ strcpy(ret, mval);
+ fclose(fd);
+ return (1);
+
+ }
+ }
+ }
+}
diff --git a/lib/libc/rpc/pmap_clnt.c b/lib/libc/rpc/pmap_clnt.c
new file mode 100644
index 0000000..9901d81
--- /dev/null
+++ b/lib/libc/rpc/pmap_clnt.c
@@ -0,0 +1,149 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: pmap_clnt.c,v 1.5 1996/12/30 14:46:33 peter Exp $";
+#endif
+
+/*
+ * pmap_clnt.c
+ * Client interface to pmap rpc service.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <netinet/in.h>
+
+static struct timeval timeout = { 5, 0 };
+static struct timeval tottimeout = { 60, 0 };
+
+void clnt_perror();
+
+#ifndef PORTMAPSOCK
+#define PORTMAPSOCK "/var/run/portmapsock"
+#endif
+
+/*
+ * Set a mapping between program,version and port.
+ * Calls the pmap service remotely to do the mapping.
+ */
+bool_t
+pmap_set(program, version, protocol, port)
+ u_long program;
+ u_long version;
+ int protocol;
+ u_short port;
+{
+ struct sockaddr_in myaddress;
+ int socket = -1;
+ register CLIENT *client;
+ struct pmap parms;
+ bool_t rslt;
+ struct stat st;
+
+ /*
+ * Temporary hack for backwards compatibility. Eventually
+ * this test will go away and we'll use only the "unix" transport.
+ */
+ if (stat(PORTMAPSOCK, &st) == 0 && st.st_mode & S_IFSOCK)
+ client = clnt_create(PORTMAPSOCK, PMAPPROG, PMAPVERS, "unix");
+ else {
+ if (get_myaddress(&myaddress) != 0)
+ return (FALSE);
+ myaddress.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
+ timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
+ }
+
+ if (client == (CLIENT *)NULL)
+ return (FALSE);
+ parms.pm_prog = program;
+ parms.pm_vers = version;
+ parms.pm_prot = protocol;
+ parms.pm_port = port;
+ if (CLNT_CALL(client, PMAPPROC_SET, xdr_pmap, &parms, xdr_bool, &rslt,
+ tottimeout) != RPC_SUCCESS) {
+ clnt_perror(client, "Cannot register service");
+ return (FALSE);
+ }
+ CLNT_DESTROY(client);
+ if (socket != -1)
+ (void)close(socket);
+ return (rslt);
+}
+
+/*
+ * Remove the mapping between program,version and port.
+ * Calls the pmap service remotely to do the un-mapping.
+ */
+bool_t
+pmap_unset(program, version)
+ u_long program;
+ u_long version;
+{
+ struct sockaddr_in myaddress;
+ int socket = -1;
+ register CLIENT *client;
+ struct pmap parms;
+ bool_t rslt;
+ struct stat st;
+
+ /*
+ * Temporary hack for backwards compatibility. Eventually
+ * this test will go away and we'll use only the "unix" transport.
+ */
+ if (stat(PORTMAPSOCK, &st) == 0 && st.st_mode & S_IFSOCK)
+ client = clnt_create(PORTMAPSOCK, PMAPPROG, PMAPVERS, "unix");
+ else {
+ if (get_myaddress(&myaddress) != 0)
+ return (FALSE);
+ myaddress.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
+ timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
+ }
+ if (client == (CLIENT *)NULL)
+ return (FALSE);
+ parms.pm_prog = program;
+ parms.pm_vers = version;
+ parms.pm_port = parms.pm_prot = 0;
+ CLNT_CALL(client, PMAPPROC_UNSET, xdr_pmap, &parms, xdr_bool, &rslt,
+ tottimeout);
+ CLNT_DESTROY(client);
+ if (socket != -1)
+ (void)close(socket);
+ return (rslt);
+}
diff --git a/lib/libc/rpc/pmap_getmaps.c b/lib/libc/rpc/pmap_getmaps.c
new file mode 100644
index 0000000..d4f2774
--- /dev/null
+++ b/lib/libc/rpc/pmap_getmaps.c
@@ -0,0 +1,86 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_getmaps.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: pmap_getmaps.c,v 1.5 1996/12/30 14:48:28 peter Exp $";
+#endif
+
+/*
+ * pmap_getmap.c
+ * Client interface to pmap rpc service.
+ * contains pmap_getmaps, which is only tcp service involved
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#define NAMELEN 255
+#define MAX_BROADCAST_SIZE 1400
+
+/*
+ * Get a copy of the current port maps.
+ * Calls the pmap service remotely to do get the maps.
+ */
+struct pmaplist *
+pmap_getmaps(address)
+ struct sockaddr_in *address;
+{
+ struct pmaplist *head = (struct pmaplist *)NULL;
+ int socket = -1;
+ struct timeval minutetimeout;
+ register CLIENT *client;
+
+ minutetimeout.tv_sec = 60;
+ minutetimeout.tv_usec = 0;
+ address->sin_port = htons(PMAPPORT);
+ client = clnttcp_create(address, PMAPPROG,
+ PMAPVERS, &socket, 50, 500);
+ if (client != (CLIENT *)NULL) {
+ if (CLNT_CALL(client, PMAPPROC_DUMP, xdr_void, NULL, xdr_pmaplist,
+ &head, minutetimeout) != RPC_SUCCESS) {
+ clnt_perror(client, "pmap_getmaps rpc problem");
+ }
+ CLNT_DESTROY(client);
+ }
+ if (socket != -1)
+ (void)close(socket);
+ address->sin_port = 0;
+ return (head);
+}
diff --git a/lib/libc/rpc/pmap_getport.c b/lib/libc/rpc/pmap_getport.c
new file mode 100644
index 0000000..3d4c48a
--- /dev/null
+++ b/lib/libc/rpc/pmap_getport.c
@@ -0,0 +1,91 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_getport.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: pmap_getport.c,v 1.4 1996/12/30 14:49:24 peter Exp $";
+#endif
+
+/*
+ * pmap_getport.c
+ * Client interface to pmap rpc service.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <unistd.h>
+
+static struct timeval timeout = { 5, 0 };
+static struct timeval tottimeout = { 60, 0 };
+
+/*
+ * Find the mapped port for program,version.
+ * Calls the pmap service remotely to do the lookup.
+ * Returns 0 if no map exists.
+ */
+u_short
+pmap_getport(address, program, version, protocol)
+ struct sockaddr_in *address;
+ u_long program;
+ u_long version;
+ u_int protocol;
+{
+ u_short port = 0;
+ int socket = -1;
+ register CLIENT *client;
+ struct pmap parms;
+
+ address->sin_port = htons(PMAPPORT);
+ client = clntudp_bufcreate(address, PMAPPROG,
+ PMAPVERS, timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
+ if (client != (CLIENT *)NULL) {
+ parms.pm_prog = program;
+ parms.pm_vers = version;
+ parms.pm_prot = protocol;
+ parms.pm_port = 0; /* not needed or used */
+ if (CLNT_CALL(client, PMAPPROC_GETPORT, xdr_pmap, &parms,
+ xdr_u_short, &port, tottimeout) != RPC_SUCCESS){
+ rpc_createerr.cf_stat = RPC_PMAPFAILURE;
+ clnt_geterr(client, &rpc_createerr.cf_error);
+ } else if (port == 0) {
+ rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
+ }
+ CLNT_DESTROY(client);
+ }
+ if (socket != -1)
+ (void)close(socket);
+ address->sin_port = 0;
+ return (port);
+}
diff --git a/lib/libc/rpc/pmap_prot.c b/lib/libc/rpc/pmap_prot.c
new file mode 100644
index 0000000..fcb9c99
--- /dev/null
+++ b/lib/libc/rpc/pmap_prot.c
@@ -0,0 +1,59 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_prot.c 1.17 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_prot.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: pmap_prot.c,v 1.2 1995/05/30 05:41:25 rgrimes Exp $";
+#endif
+
+/*
+ * pmap_prot.c
+ * Protocol for the local binder service, or pmap.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/pmap_prot.h>
+
+
+bool_t
+xdr_pmap(xdrs, regs)
+ XDR *xdrs;
+ struct pmap *regs;
+{
+
+ if (xdr_u_long(xdrs, &regs->pm_prog) &&
+ xdr_u_long(xdrs, &regs->pm_vers) &&
+ xdr_u_long(xdrs, &regs->pm_prot))
+ return (xdr_u_long(xdrs, &regs->pm_port));
+ return (FALSE);
+}
diff --git a/lib/libc/rpc/pmap_prot2.c b/lib/libc/rpc/pmap_prot2.c
new file mode 100644
index 0000000..d81f612
--- /dev/null
+++ b/lib/libc/rpc/pmap_prot2.c
@@ -0,0 +1,118 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_prot2.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: pmap_prot2.c,v 1.3 1996/06/10 20:13:05 jraynard Exp $";
+#endif
+
+/*
+ * pmap_prot2.c
+ * Protocol for the local binder service, or pmap.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/pmap_prot.h>
+
+
+/*
+ * What is going on with linked lists? (!)
+ * First recall the link list declaration from pmap_prot.h:
+ *
+ * struct pmaplist {
+ * struct pmap pml_map;
+ * struct pmaplist *pml_map;
+ * };
+ *
+ * Compare that declaration with a corresponding xdr declaration that
+ * is (a) pointer-less, and (b) recursive:
+ *
+ * typedef union switch (bool_t) {
+ *
+ * case TRUE: struct {
+ * struct pmap;
+ * pmaplist_t foo;
+ * };
+ *
+ * case FALSE: struct {};
+ * } pmaplist_t;
+ *
+ * Notice that the xdr declaration has no nxt pointer while
+ * the C declaration has no bool_t variable. The bool_t can be
+ * interpreted as ``more data follows me''; if FALSE then nothing
+ * follows this bool_t; if TRUE then the bool_t is followed by
+ * an actual struct pmap, and then (recursively) by the
+ * xdr union, pamplist_t.
+ *
+ * This could be implemented via the xdr_union primitive, though this
+ * would cause a one recursive call per element in the list. Rather than do
+ * that we can ``unwind'' the recursion
+ * into a while loop and do the union arms in-place.
+ *
+ * The head of the list is what the C programmer wishes to past around
+ * the net, yet is the data that the pointer points to which is interesting;
+ * this sounds like a job for xdr_reference!
+ */
+bool_t
+xdr_pmaplist(xdrs, rp)
+ register XDR *xdrs;
+ register struct pmaplist **rp;
+{
+ /*
+ * more_elements is pre-computed in case the direction is
+ * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
+ * xdr_bool when the direction is XDR_DECODE.
+ */
+ bool_t more_elements;
+ register int freeing = (xdrs->x_op == XDR_FREE);
+ register struct pmaplist **next = NULL;
+
+ while (TRUE) {
+ more_elements = (bool_t)(*rp != NULL);
+ if (! xdr_bool(xdrs, &more_elements))
+ return (FALSE);
+ if (! more_elements)
+ return (TRUE); /* we are done */
+ /*
+ * the unfortunate side effect of non-recursion is that in
+ * the case of freeing we must remember the next object
+ * before we free the current object ...
+ */
+ if (freeing)
+ next = &((*rp)->pml_next);
+ if (! xdr_reference(xdrs, (caddr_t *)rp,
+ (u_int)sizeof(struct pmaplist), xdr_pmap))
+ return (FALSE);
+ rp = (freeing) ? next : &((*rp)->pml_next);
+ }
+}
diff --git a/lib/libc/rpc/pmap_rmt.c b/lib/libc/rpc/pmap_rmt.c
new file mode 100644
index 0000000..07a81e2
--- /dev/null
+++ b/lib/libc/rpc/pmap_rmt.c
@@ -0,0 +1,415 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: pmap_rmt.c,v 1.9 1996/12/30 14:53:20 peter Exp $";
+#endif
+
+/*
+ * pmap_rmt.c
+ * Client interface to pmap rpc service.
+ * remote call and broadcast service
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_clnt.h>
+#include <rpc/pmap_rmt.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#define MAX_BROADCAST_SIZE 1400
+
+static struct timeval timeout = { 3, 0 };
+
+/*
+ * pmapper remote-call-service interface.
+ * This routine is used to call the pmapper remote call service
+ * which will look up a service program in the port maps, and then
+ * remotely call that routine with the given parameters. This allows
+ * programs to do a lookup and call in one step.
+*/
+enum clnt_stat
+pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, port_ptr)
+ struct sockaddr_in *addr;
+ u_long prog, vers, proc;
+ xdrproc_t xdrargs, xdrres;
+ caddr_t argsp, resp;
+ struct timeval tout;
+ u_long *port_ptr;
+{
+ int socket = -1;
+ register CLIENT *client;
+ struct rmtcallargs a;
+ struct rmtcallres r;
+ enum clnt_stat stat;
+
+ addr->sin_port = htons(PMAPPORT);
+ client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &socket);
+ if (client != (CLIENT *)NULL) {
+ a.prog = prog;
+ a.vers = vers;
+ a.proc = proc;
+ a.args_ptr = argsp;
+ a.xdr_args = xdrargs;
+ r.port_ptr = port_ptr;
+ r.results_ptr = resp;
+ r.xdr_results = xdrres;
+ stat = CLNT_CALL(client, PMAPPROC_CALLIT, xdr_rmtcall_args, &a,
+ xdr_rmtcallres, &r, tout);
+ CLNT_DESTROY(client);
+ } else {
+ stat = RPC_FAILED;
+ }
+ if (socket != -1)
+ (void)close(socket);
+ addr->sin_port = 0;
+ return (stat);
+}
+
+
+/*
+ * XDR remote call arguments
+ * written for XDR_ENCODE direction only
+ */
+bool_t
+xdr_rmtcall_args(xdrs, cap)
+ register XDR *xdrs;
+ register struct rmtcallargs *cap;
+{
+ u_int lenposition, argposition, position;
+
+ if (xdr_u_long(xdrs, &(cap->prog)) &&
+ xdr_u_long(xdrs, &(cap->vers)) &&
+ xdr_u_long(xdrs, &(cap->proc))) {
+ lenposition = XDR_GETPOS(xdrs);
+ if (! xdr_u_long(xdrs, &(cap->arglen)))
+ return (FALSE);
+ argposition = XDR_GETPOS(xdrs);
+ if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
+ return (FALSE);
+ position = XDR_GETPOS(xdrs);
+ cap->arglen = (u_long)position - (u_long)argposition;
+ XDR_SETPOS(xdrs, lenposition);
+ if (! xdr_u_long(xdrs, &(cap->arglen)))
+ return (FALSE);
+ XDR_SETPOS(xdrs, position);
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR remote call results
+ * written for XDR_DECODE direction only
+ */
+bool_t
+xdr_rmtcallres(xdrs, crp)
+ register XDR *xdrs;
+ register struct rmtcallres *crp;
+{
+ caddr_t port_ptr;
+
+ port_ptr = (caddr_t)crp->port_ptr;
+ if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
+ xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
+ crp->port_ptr = (u_long *)port_ptr;
+ return ((*(crp->xdr_results))(xdrs, crp->results_ptr));
+ }
+ return (FALSE);
+}
+
+
+/*
+ * The following is kludged-up support for simple rpc broadcasts.
+ * Someday a large, complicated system will replace these trivial
+ * routines which only support udp/ip .
+ */
+
+static int
+getbroadcastnets(addrs, sock, buf)
+ struct in_addr *addrs;
+ int sock; /* any valid socket will do */
+ char *buf; /* why allocxate more when we can use existing... */
+{
+ struct ifconf ifc;
+ struct ifreq ifreq, *ifr;
+ struct sockaddr_in *sin;
+ struct in_addr addr;
+ char *cp, *cplim;
+ int n, i = 0;
+
+ ifc.ifc_len = UDPMSGSIZE;
+ ifc.ifc_buf = buf;
+ if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
+ perror("broadcast: ioctl (get interface configuration)");
+ return (0);
+ }
+#define max(a, b) (a > b ? a : b)
+#define size(p) max((p).sa_len, sizeof(p))
+ cplim = buf + ifc.ifc_len; /*skip over if's with big ifr_addr's */
+ for (cp = buf; cp < cplim;
+ cp += sizeof (ifr->ifr_name) + size(ifr->ifr_addr)) {
+ ifr = (struct ifreq *)cp;
+ if (ifr->ifr_addr.sa_family != AF_INET)
+ continue;
+ ifreq = *ifr;
+ if (ioctl(sock, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
+ perror("broadcast: ioctl (get interface flags)");
+ continue;
+ }
+ if ((ifreq.ifr_flags & IFF_BROADCAST) &&
+ (ifreq.ifr_flags & IFF_UP)) {
+ sin = (struct sockaddr_in *)&ifr->ifr_addr;
+#ifdef SIOCGIFBRDADDR /* 4.3BSD */
+ if (ioctl(sock, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
+ addr =
+ inet_makeaddr(inet_netof(sin->sin_addr),
+ INADDR_ANY);
+ } else {
+ addr = ((struct sockaddr_in*)
+ &ifreq.ifr_addr)->sin_addr;
+ }
+#else /* 4.2 BSD */
+ addr = inet_makeaddr(inet_netof(sin->sin_addr),
+ INADDR_ANY);
+#endif
+ for (n=i-1; n>=0; n--) {
+ if (addr.s_addr == addrs[n].s_addr)
+ break;
+ }
+ if (n<0) {
+ addrs[i++] = addr;
+ }
+ }
+ }
+ return (i);
+}
+
+typedef bool_t (*resultproc_t)();
+
+enum clnt_stat
+clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
+ u_long prog; /* program number */
+ u_long vers; /* version number */
+ u_long proc; /* procedure number */
+ xdrproc_t xargs; /* xdr routine for args */
+ caddr_t argsp; /* pointer to args */
+ xdrproc_t xresults; /* xdr routine for results */
+ caddr_t resultsp; /* pointer to results */
+ resultproc_t eachresult; /* call with each result obtained */
+{
+ enum clnt_stat stat;
+ AUTH *unix_auth = authunix_create_default();
+ XDR xdr_stream;
+ register XDR *xdrs = &xdr_stream;
+ int outlen, inlen, fromlen, nets;
+ register int sock;
+ int on = 1;
+ fd_set *fds, readfds;
+ register int i;
+ bool_t done = FALSE;
+ register u_long xid;
+ u_long port;
+ struct in_addr addrs[20];
+ struct sockaddr_in baddr, raddr; /* broadcast and response addresses */
+ struct rmtcallargs a;
+ struct rmtcallres r;
+ struct rpc_msg msg;
+ struct timeval t, tv;
+ char outbuf[MAX_BROADCAST_SIZE], inbuf[UDPMSGSIZE];
+ static u_int32_t disrupt;
+
+ if (disrupt == 0)
+ disrupt = (u_int32_t)(long)resultsp;
+
+ /*
+ * initialization: create a socket, a broadcast address, and
+ * preserialize the arguments into a send buffer.
+ */
+ if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("Cannot create socket for broadcast rpc");
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+#ifdef SO_BROADCAST
+ if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
+ perror("Cannot set socket option SO_BROADCAST");
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+#endif /* def SO_BROADCAST */
+ if (sock + 1 > FD_SETSIZE) {
+ int bytes = howmany(sock + 1, NFDBITS) * sizeof(fd_mask);
+ fds = (fd_set *)malloc(bytes);
+ if (fds == NULL) {
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+ memset(fds, 0, bytes);
+ } else {
+ fds = &readfds;
+ FD_ZERO(fds);
+ }
+
+ nets = getbroadcastnets(addrs, sock, inbuf);
+ memset(&baddr, 0, sizeof (baddr));
+ baddr.sin_len = sizeof(struct sockaddr_in);
+ baddr.sin_family = AF_INET;
+ baddr.sin_port = htons(PMAPPORT);
+ baddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ (void)gettimeofday(&t, (struct timezone *)0);
+ msg.rm_xid = xid = (++disrupt) ^ getpid() ^ t.tv_sec ^ t.tv_usec;
+ t.tv_usec = 0;
+ msg.rm_direction = CALL;
+ msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ msg.rm_call.cb_prog = PMAPPROG;
+ msg.rm_call.cb_vers = PMAPVERS;
+ msg.rm_call.cb_proc = PMAPPROC_CALLIT;
+ msg.rm_call.cb_cred = unix_auth->ah_cred;
+ msg.rm_call.cb_verf = unix_auth->ah_verf;
+ a.prog = prog;
+ a.vers = vers;
+ a.proc = proc;
+ a.xdr_args = xargs;
+ a.args_ptr = argsp;
+ r.port_ptr = &port;
+ r.xdr_results = xresults;
+ r.results_ptr = resultsp;
+ xdrmem_create(xdrs, outbuf, MAX_BROADCAST_SIZE, XDR_ENCODE);
+ if ((! xdr_callmsg(xdrs, &msg)) || (! xdr_rmtcall_args(xdrs, &a))) {
+ stat = RPC_CANTENCODEARGS;
+ goto done_broad;
+ }
+ outlen = (int)xdr_getpos(xdrs);
+ xdr_destroy(xdrs);
+ /*
+ * Basic loop: broadcast a packet and wait a while for response(s).
+ * The response timeout grows larger per iteration.
+ *
+ * XXX This will loop about 5 times the stop. If there are
+ * lots of signals being received by the process it will quit
+ * send them all in one quick burst, not paying attention to
+ * the intended function of sending them slowly over half a
+ * minute or so
+ */
+ for (t.tv_sec = 4; t.tv_sec <= 14; t.tv_sec += 2) {
+ for (i = 0; i < nets; i++) {
+ baddr.sin_addr = addrs[i];
+ if (sendto(sock, outbuf, outlen, 0,
+ (struct sockaddr *)&baddr,
+ sizeof (struct sockaddr)) != outlen) {
+ perror("Cannot send broadcast packet");
+ stat = RPC_CANTSEND;
+ goto done_broad;
+ }
+ }
+ if (eachresult == NULL) {
+ stat = RPC_SUCCESS;
+ goto done_broad;
+ }
+ recv_again:
+ msg.acpted_rply.ar_verf = _null_auth;
+ msg.acpted_rply.ar_results.where = (caddr_t)&r;
+ msg.acpted_rply.ar_results.proc = xdr_rmtcallres;
+ /* XXX we know the other bits are still clear */
+ FD_SET(sock, fds);
+ tv = t; /* for select() that copies back */
+ switch (select(sock + 1, fds, NULL, NULL, &tv)) {
+
+ case 0: /* timed out */
+ stat = RPC_TIMEDOUT;
+ continue;
+
+ case -1: /* some kind of error */
+ if (errno == EINTR)
+ goto recv_again;
+ perror("Broadcast select problem");
+ stat = RPC_CANTRECV;
+ goto done_broad;
+
+ } /* end of select results switch */
+ try_again:
+ fromlen = sizeof(struct sockaddr);
+ inlen = recvfrom(sock, inbuf, UDPMSGSIZE, 0,
+ (struct sockaddr *)&raddr, &fromlen);
+ if (inlen < 0) {
+ if (errno == EINTR)
+ goto try_again;
+ perror("Cannot receive reply to broadcast");
+ stat = RPC_CANTRECV;
+ goto done_broad;
+ }
+ if (inlen < sizeof(u_int32_t))
+ goto recv_again;
+ /*
+ * see if reply transaction id matches sent id.
+ * If so, decode the results.
+ */
+ xdrmem_create(xdrs, inbuf, (u_int)inlen, XDR_DECODE);
+ if (xdr_replymsg(xdrs, &msg)) {
+ if ((msg.rm_xid == xid) &&
+ (msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
+ (msg.acpted_rply.ar_stat == SUCCESS)) {
+ raddr.sin_port = htons((u_short)port);
+ done = (*eachresult)(resultsp, &raddr);
+ }
+ /* otherwise, we just ignore the errors ... */
+ }
+ xdrs->x_op = XDR_FREE;
+ msg.acpted_rply.ar_results.proc = xdr_void;
+ (void)xdr_replymsg(xdrs, &msg);
+ (void)(*xresults)(xdrs, resultsp);
+ xdr_destroy(xdrs);
+ if (done) {
+ stat = RPC_SUCCESS;
+ goto done_broad;
+ } else {
+ goto recv_again;
+ }
+ }
+done_broad:
+ if (fds != &readfds)
+ free(fds);
+ if (sock >= 0)
+ (void)close(sock);
+ AUTH_DESTROY(unix_auth);
+ return (stat);
+}
+
diff --git a/lib/libc/rpc/publickey.3 b/lib/libc/rpc/publickey.3
new file mode 100644
index 0000000..7063e8a
--- /dev/null
+++ b/lib/libc/rpc/publickey.3
@@ -0,0 +1,44 @@
+.\" @(#)publickey.3r 2.1 88/08/07 4.0 RPCSRC
+.TH PUBLICKEY 3R "6 October 1987"
+.SH NAME
+publickey, getpublickey, getsecretkey \- get public or secret key
+.SH SYNOPSIS
+.nf
+.B #include <rpc/rpc.h>
+.B #include <rpc/key_prot.h>
+.LP
+.B getpublickey(netname, publickey)
+.B char netname[\s-1MAXNETNAMELEN\s0+1];
+.B char publickey[\s-1HEXKEYBYTES\s0+1];
+.LP
+.B getsecretkey(netname, secretkey, passwd)
+.B char netname[\s-1MAXNETNAMELEN\s0+1];
+.B char secretkey[\s-1HEXKEYBYTES\s0+1];
+.B char *passwd;
+.fi
+.SH DESCRIPTION
+.IX "getpublickey function" "" "\fLgetpublickey()\fP function"
+.IX "getsecretkey function" "" "\fLgetsecretkey()\fP function"
+These routines are used to get public and secret keys from the
+.SM YP
+database.
+.B getsecretkey(\|)
+has an extra argument,
+.IR passwd ,
+which is used to decrypt the encrypted secret key stored in the database.
+Both routines return 1 if they are successful in finding the key, 0 otherwise.
+The keys are returned as
+.SM NULL\s0-terminated,
+hexadecimal strings. If the password supplied to
+.B getsecretkey(\|)
+fails to decrypt the secret key, the routine will return 1 but the
+.I secretkey
+argument will be a
+.SM NULL
+string (``'').
+.SH "SEE ALSO"
+.BR publickey (5)
+.LP
+.I \s-1RPC\s0 Programmer's Manual
+in
+.TX NETP
diff --git a/lib/libc/rpc/publickey.5 b/lib/libc/rpc/publickey.5
new file mode 100644
index 0000000..de3c1e9
--- /dev/null
+++ b/lib/libc/rpc/publickey.5
@@ -0,0 +1,37 @@
+.\" @(#)publickey.5 2.1 88/08/07 4.0 RPCSRC; from 1.6 88/02/29 SMI;
+.TH PUBLICKEY 5 "19 October 1987"
+.SH NAME
+publickey \- public key database
+.SH SYNOPSIS
+.B /etc/publickey
+.SH DESCRIPTION
+.LP
+.B /etc/publickey
+is the public key database used for secure
+networking. Each entry in
+the database consists of a network user
+name (which may either refer to
+a user or a hostname), followed by the user's
+public key (in hex
+notation), a colon, and then the user's
+secret key encrypted with
+its login password (also in hex notation).
+.LP
+This file is altered either by the user through the
+.BR chkey (1)
+command or by the system administrator through the
+.BR newkey (8)
+command.
+The file
+.B /etc/publickey
+should only contain data on the Yellow
+Pages master machine, where it
+is converted into the
+.SM YP
+database
+.BR publickey.byname .
+.SH SEE ALSO
+.BR chkey (1),
+.BR publickey (3R),
+.BR newkey (8),
+.BR ypupdated (8C)
diff --git a/lib/libc/rpc/rpc.3 b/lib/libc/rpc/rpc.3
new file mode 100644
index 0000000..dd55c22
--- /dev/null
+++ b/lib/libc/rpc/rpc.3
@@ -0,0 +1,1737 @@
+.\" @(#)rpc.3n 2.4 88/08/08 4.0 RPCSRC; from 1.19 88/06/24 SMI
+.TH RPC 3 "16 February 1988"
+.SH NAME
+rpc \- library routines for remote procedure calls
+.SH SYNOPSIS AND DESCRIPTION
+These routines allow C programs to make procedure
+calls on other machines across the network.
+First, the client calls a procedure to send a
+data packet to the server.
+Upon receipt of the packet, the server calls a dispatch routine
+to perform the requested service, and then sends back a
+reply.
+Finally, the procedure call returns to the client.
+.LP
+Routines that are used for Secure RPC (DES authentication) are described in
+.BR rpc_secure (3).
+Secure RPC can be used only if DES encryption is available.
+.LP
+.ft B
+.nf
+.sp .5
+#include <rpc/rpc.h>
+.fi
+.ft R
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+auth_destroy(auth)
+\s-1AUTH\s0 *auth;
+.fi
+.ft R
+.IP
+A macro that destroys the authentication information associated with
+.IR auth .
+Destruction usually involves deallocation of private data
+structures. The use of
+.I auth
+is undefined after calling
+.BR auth_destroy(\|) .
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+\s-1AUTH\s0 *
+authnone_create(\|)
+.fi
+.ft R
+.IP
+Create and returns an
+.SM RPC
+authentication handle that passes nonusable authentication
+information with each remote procedure call. This is the
+default authentication used by
+.SM RPC.
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+\s-1AUTH\s0 *
+authunix_create(host, uid, gid, len, aup_gids)
+char *host;
+int uid, gid, len, *aup.gids;
+.fi
+.ft R
+.IP
+Create and return an
+.SM RPC
+authentication handle that contains
+.UX
+authentication information.
+The parameter
+.I host
+is the name of the machine on which the information was
+created;
+.I uid
+is the user's user
+.SM ID ;
+.I gid
+is the user's current group
+.SM ID ;
+.I len
+and
+.I aup_gids
+refer to a counted array of groups to which the user belongs.
+It is easy to impersonate a user.
+.br
+.if t .ne 5
+.LP
+.ft B
+.nf
+.sp .5
+\s-1AUTH\s0 *
+authunix_create_default(\|)
+.fi
+.ft R
+.IP
+Calls
+.B authunix_create(\|)
+with the appropriate parameters.
+.br
+.if t .ne 13
+.LP
+.ft B
+.nf
+.sp .5
+callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
+char *host;
+u_long prognum, versnum, procnum;
+char *in, *out;
+xdrproc_t inproc, outproc;
+.fi
+.ft R
+.IP
+Call the remote procedure associated with
+.IR prognum ,
+.IR versnum ,
+and
+.I procnum
+on the machine,
+.IR host .
+The parameter
+.I in
+is the address of the procedure's argument(s), and
+.I out
+is the address of where to place the result(s);
+.I inproc
+is used to encode the procedure's parameters, and
+.I outproc
+is used to decode the procedure's results.
+This routine returns zero if it succeeds, or the value of
+.B "enum clnt_stat"
+cast to an integer if it fails.
+The routine
+.B clnt_perrno(\|)
+is handy for translating failure statuses into messages.
+.IP
+Warning: calling remote procedures with this routine
+uses
+.SM UDP/IP
+as a transport; see
+.B clntudp_create(\|)
+for restrictions.
+You do not have control of timeouts or authentication using
+this routine.
+.br
+.if t .ne 16
+.LP
+.ft B
+.nf
+.sp .5
+enum clnt_stat
+clnt_broadcast(prognum, versnum, procnum, inproc, in, outproc, out, eachresult)
+u_long prognum, versnum, procnum;
+char *in, *out;
+xdrproc_t inproc, outproc;
+resultproc_t eachresult;
+.fi
+.ft R
+.IP
+Like
+.BR callrpc(\|) ,
+except the call message is broadcast to all locally
+connected broadcast nets. Each time it receives a
+response, this routine calls
+.BR eachresult(\|) ,
+whose form is:
+.IP
+.RS 1i
+.ft B
+.nf
+eachresult(out, addr)
+char *out;
+struct sockaddr_in *addr;
+.ft R
+.fi
+.RE
+.IP
+where
+.I out
+is the same as
+.I out
+passed to
+.BR clnt_broadcast(\|) ,
+except that the remote procedure's output is decoded there;
+.I addr
+points to the address of the machine that sent the results.
+If
+.B eachresult(\|)
+returns zero,
+.B clnt_broadcast(\|)
+waits for more replies; otherwise it returns with appropriate
+status.
+.IP
+Warning: broadcast sockets are limited in size to the
+maximum transfer unit of the data link. For ethernet,
+this value is 1500 bytes.
+.br
+.if t .ne 13
+.LP
+.ft B
+.nf
+.sp .5
+enum clnt_stat
+clnt_call(clnt, procnum, inproc, in, outproc, out, tout)
+\s-1CLIENT\s0 *clnt;
+u_long
+procnum;
+xdrproc_t inproc, outproc;
+char *in, *out;
+struct timeval tout;
+.fi
+.ft R
+.IP
+A macro that calls the remote procedure
+.I procnum
+associated with the client handle,
+.IR clnt ,
+which is obtained with an
+.SM RPC
+client creation routine such as
+.BR clnt_create(\|) .
+The parameter
+.I in
+is the address of the procedure's argument(s), and
+.I out
+is the address of where to place the result(s);
+.I inproc
+is used to encode the procedure's parameters, and
+.I outproc
+is used to decode the procedure's results;
+.I tout
+is the time allowed for results to come back.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+clnt_destroy(clnt)
+\s-1CLIENT\s0 *clnt;
+.fi
+.ft R
+.IP
+A macro that destroys the client's
+.SM RPC
+handle. Destruction usually involves deallocation
+of private data structures, including
+.I clnt
+itself. Use of
+.I clnt
+is undefined after calling
+.BR clnt_destroy(\|) .
+If the
+.SM RPC
+library opened the associated socket, it will close it also.
+Otherwise, the socket remains open.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+\s-1CLIENT\s0 *
+clnt_create(host, prog, vers, proto)
+char *host;
+u_long prog, vers;
+char *proto;
+.fi
+.ft R
+.IP
+Generic client creation routine.
+.I host
+identifies the name of the remote host where the server
+is located.
+.I proto
+indicates which kind of transport protocol to use. The
+currently supported values for this field are \(lqudp\(rq
+and \(lqtcp\(rq.
+Default timeouts are set, but can be modified using
+.BR clnt_control(\|) .
+.IP
+Warning: Using
+.SM UDP
+has its shortcomings. Since
+.SM UDP\s0-based
+.SM RPC
+messages can only hold up to 8 Kbytes of encoded data,
+this transport cannot be used for procedures that take
+large arguments or return huge results.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+bool_t
+clnt_control(cl, req, info)
+\s-1CLIENT\s0 *cl;
+char *info;
+.fi
+.ft R
+.IP
+A macro used to change or retrieve various information
+about a client object.
+.I req
+indicates the type of operation, and
+.I info
+is a pointer to the information. For both
+.SM UDP
+and
+.SM TCP\s0,
+the supported values of
+.I req
+and their argument types and what they do are:
+.IP
+.nf
+.ta +2.0i +2.0i +2.0i
+.SM CLSET_TIMEOUT\s0 struct timeval set total timeout
+.SM CLGET_TIMEOUT\s0 struct timeval get total timeout
+.fi
+.IP
+Note: if you set the timeout using
+.BR clnt_control(\|) ,
+the timeout parameter passed to
+.B clnt_call(\|)
+will be ignored in all future calls.
+.IP
+.nf
+.SM CLGET_SERVER_ADDR\s0 struct sockaddr_in get server's address
+.fi
+.br
+.IP
+The following operations are valid for
+.SM UDP
+only:
+.IP
+.nf
+.ta +2.0i ; +2.0i ; +2.0i
+.SM CLSET_RETRY_TIMEOUT\s0 struct timeval set the retry timeout
+.SM CLGET_RETRY_TIMEOUT\s0 struct timeval get the retry timeout
+.fi
+.br
+.IP
+The retry timeout is the time that
+.SM "UDP RPC"
+waits for the server to reply before
+retransmitting the request.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+clnt_freeres(clnt, outproc, out)
+\s-1CLIENT\s0 *clnt;
+xdrproc_t outproc;
+char *out;
+.fi
+.ft R
+.IP
+A macro that frees any data allocated by the
+.SM RPC/XDR
+system when it decoded the results of an
+.SM RPC
+call. The
+parameter
+.I out
+is the address of the results, and
+.I outproc
+is the
+.SM XDR
+routine describing the results.
+This routine returns one if the results were successfully
+freed,
+and zero otherwise.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+void
+clnt_geterr(clnt, errp)
+\s-1CLIENT\s0 *clnt;
+struct rpc_err *errp;
+.fi
+.ft R
+.IP
+A macro that copies the error structure out of the client
+handle
+to the structure at address
+.IR errp .
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+clnt_pcreateerror(s)
+char *s;
+.fi
+.ft R
+.IP
+Print a message to standard error indicating
+why a client
+.SM RPC
+handle could not be created.
+The message is prepended with string
+.I s
+and a colon.
+Used when a
+.BR clnt_create(\|) ,
+.BR clntraw_create(\|) ,
+.BR clnttcp_create(\|) ,
+or
+.B clntudp_create(\|)
+call fails.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+clnt_perrno(stat)
+enum clnt_stat stat;
+.fi
+.ft R
+.IP
+Print a message to standard error corresponding
+to the condition indicated by
+.IR stat .
+Used after
+.BR callrpc(\|) .
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+clnt_perror(clnt, s)
+\s-1CLIENT\s0 *clnt;
+char *s;
+.fi
+.ft R
+.IP
+Print a message to standard error indicating why an
+.SM RPC
+call failed;
+.I clnt
+is the handle used to do the call.
+The message is prepended with string
+.I s
+and a colon.
+Used after
+.BR clnt_call(\|) .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+char *
+clnt_spcreateerror
+char *s;
+.fi
+.ft R
+.IP
+Like
+.BR clnt_pcreateerror(\|) ,
+except that it returns a string
+instead of printing to the standard error.
+.IP
+Bugs: returns pointer to static data that is overwritten
+on each call.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+char *
+clnt_sperrno(stat)
+enum clnt_stat stat;
+.fi
+.ft R
+.IP
+Take the same arguments as
+.BR clnt_perrno(\|) ,
+but instead of sending a message to the standard error
+indicating why an
+.SM RPC
+call failed, return a pointer to a string which contains
+the message. The string ends with a
+.SM NEWLINE\s0.
+.IP
+.B clnt_sperrno(\|)
+is used instead of
+.B clnt_perrno(\|)
+if the program does not have a standard error (as a program
+running as a server quite likely does not), or if the
+programmer
+does not want the message to be output with
+.BR printf ,
+or if a message format different than that supported by
+.B clnt_perrno(\|)
+is to be used.
+Note: unlike
+.B clnt_sperror(\|)
+and
+.BR clnt_spcreaterror(\|) ,
+.B clnt_sperrno(\|)
+returns pointer to static data, but the
+result will not get overwritten on each call.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+char *
+clnt_sperror(rpch, s)
+\s-1CLIENT\s0 *rpch;
+char *s;
+.fi
+.ft R
+.IP
+Like
+.BR clnt_perror(\|) ,
+except that (like
+.BR clnt_sperrno(\|) )
+it returns a string instead of printing to standard error.
+.IP
+Bugs: returns pointer to static data that is overwritten
+on each call.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+\s-1CLIENT\s0 *
+clntraw_create(prognum, versnum)
+u_long prognum, versnum;
+.fi
+.ft R
+.IP
+This routine creates a toy
+.SM RPC
+client for the remote program
+.IR prognum ,
+version
+.IR versnum .
+The transport used to pass messages to the service is
+actually a buffer within the process's address space, so the
+corresponding
+.SM RPC
+server should live in the same address space; see
+.BR svcraw_create(\|) .
+This allows simulation of
+.SM RPC
+and acquisition of
+.SM RPC
+overheads, such as round trip times, without any
+kernel interference. This routine returns
+.SM NULL
+if it fails.
+.br
+.if t .ne 15
+.LP
+.ft B
+.nf
+.sp .5
+\s-1CLIENT\s0 *
+clnttcp_create(addr, prognum, versnum, sockp, sendsz, recvsz)
+struct sockaddr_in *addr;
+u_long prognum, versnum;
+int *sockp;
+u_int sendsz, recvsz;
+.fi
+.ft R
+.IP
+This routine creates an
+.SM RPC
+client for the remote program
+.IR prognum ,
+version
+.IR versnum ;
+the client uses
+.SM TCP/IP
+as a transport. The remote program is located at Internet
+address
+.IR *addr .
+If
+.\"The following in-line font conversion is necessary for the hyphen indicator
+\fB\%addr\->sin_port\fR
+is zero, then it is set to the actual port that the remote
+program is listening on (the remote
+.B portmap
+service is consulted for this information). The parameter
+.I sockp
+is a socket; if it is
+.BR \s-1RPC_ANYSOCK\s0 ,
+then this routine opens a new one and sets
+.IR sockp .
+Since
+.SM TCP\s0-based
+.SM RPC
+uses buffered
+.SM I/O ,
+the user may specify the size of the send and receive buffers
+with the parameters
+.I sendsz
+and
+.IR recvsz ;
+values of zero choose suitable defaults.
+This routine returns
+.SM NULL
+if it fails.
+.br
+.if t .ne 15
+.LP
+.ft B
+.nf
+.sp .5
+\s-1CLIENT\s0 *
+clntudp_create(addr, prognum, versnum, wait, sockp)
+struct sockaddr_in *addr;
+u_long prognum, versnum;
+struct timeval wait;
+int *sockp;
+.fi
+.ft R
+.IP
+This routine creates an
+.SM RPC
+client for the remote program
+.IR prognum ,
+version
+.IR versnum ;
+the client uses
+.SM UDP/IP
+as a transport. The remote program is located at Internet
+address
+.IR addr .
+If
+\fB\%addr\->sin_port\fR
+is zero, then it is set to actual port that the remote
+program is listening on (the remote
+.B portmap
+service is consulted for this information). The parameter
+.I sockp
+is a socket; if it is
+.BR \s-1RPC_ANYSOCK\s0 ,
+then this routine opens a new one and sets
+.IR sockp .
+The
+.SM UDP
+transport resends the call message in intervals of
+.B wait
+time until a response is received or until the call times
+out.
+The total time for the call to time out is specified by
+.BR clnt_call(\|) .
+.IP
+Warning: since
+.SM UDP\s0-based
+.SM RPC
+messages can only hold up to 8 Kbytes
+of encoded data, this transport cannot be used for procedures
+that take large arguments or return huge results.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+\s-1CLIENT\s0 *
+clntudp_bufcreate(addr, prognum, versnum, wait, sockp, sendsize, recosize)
+struct sockaddr_in *addr;
+u_long prognum, versnum;
+struct timeval wait;
+int *sockp;
+unsigned int sendsize;
+unsigned int recosize;
+.fi
+.ft R
+.IP
+This routine creates an
+.SM RPC
+client for the remote program
+.IR prognum ,
+on
+.IR versnum ;
+the client uses
+.SM UDP/IP
+as a transport. The remote program is located at Internet
+address
+.IR addr .
+If
+\fB\%addr\->sin_port\fR
+is zero, then it is set to actual port that the remote
+program is listening on (the remote
+.B portmap
+service is consulted for this information). The parameter
+.I sockp
+is a socket; if it is
+.BR \s-1RPC_ANYSOCK\s0 ,
+then this routine opens a new one and sets
+.BR sockp .
+The
+.SM UDP
+transport resends the call message in intervals of
+.B wait
+time until a response is received or until the call times
+out.
+The total time for the call to time out is specified by
+.BR clnt_call(\|) .
+.IP
+This allows the user to specify the maximum packet size for sending and receiving
+.SM UDP\s0-based
+.SM RPC
+messages.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+int
+get_myaddress(addr)
+struct sockaddr_in *addr;
+.fi
+.ft R
+.IP
+Stuff the machine's
+.SM IP
+address into
+.IR *addr ,
+without consulting the library routines that deal with
+.BR /etc/hosts .
+The port number is always set to
+.BR htons(\s-1PMAPPORT\s0) .
+Returns zero on success, non-zero on failure.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+struct pmaplist *
+pmap_getmaps(addr)
+struct sockaddr_in *addr;
+.fi
+.ft R
+.IP
+A user interface to the
+.B portmap
+service, which returns a list of the current
+.SM RPC
+program-to-port mappings
+on the host located at
+.SM IP
+address
+.IR *addr .
+This routine can return
+.SM NULL .
+The command
+.RB ` "rpcinfo \-p" '
+uses this routine.
+.br
+.if t .ne 12
+.LP
+.ft B
+.nf
+.sp .5
+u_short
+pmap_getport(addr, prognum, versnum, protocol)
+struct sockaddr_in *addr;
+u_long prognum, versnum, protocol;
+.fi
+.ft R
+.IP
+A user interface to the
+.B portmap
+service, which returns the port number
+on which waits a service that supports program number
+.IR prognum ,
+version
+.IR versnum ,
+and speaks the transport protocol associated with
+.IR protocol .
+The value of
+.I protocol
+is most likely
+.B
+.SM IPPROTO_UDP
+or
+.BR \s-1IPPROTO_TCP\s0 .
+A return value of zero means that the mapping does not exist
+or that
+the
+.SM RPC
+system failed to contact the remote
+.B portmap
+service. In the latter case, the global variable
+.B rpc_createerr(\|)
+contains the
+.SM RPC
+status.
+.br
+.if t .ne 15
+.LP
+.ft B
+.nf
+.sp .5
+enum clnt_stat
+pmap_rmtcall(addr, prognum, versnum, procnum, inproc, in, outproc, out, tout, portp)
+struct sockaddr_in *addr;
+u_long prognum, versnum, procnum;
+char *in, *out;
+xdrproc_t inproc, outproc;
+struct timeval tout;
+u_long *portp;
+.fi
+.ft R
+.IP
+A user interface to the
+.B portmap
+service, which instructs
+.B portmap
+on the host at
+.SM IP
+address
+.I *addr
+to make an
+.SM RPC
+call on your behalf to a procedure on that host.
+The parameter
+.I *portp
+will be modified to the program's port number if the
+procedure
+succeeds. The definitions of other parameters are discussed
+in
+.B callrpc(\|)
+and
+.BR clnt_call(\|) .
+This procedure should be used for a \(lqping\(rq and nothing
+else.
+See also
+.BR clnt_broadcast(\|) .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+pmap_set(prognum, versnum, protocol, port)
+u_long prognum, versnum, protocol;
+u_short port;
+.fi
+.ft R
+.IP
+A user interface to the
+.B portmap
+service, which establishes a mapping between the triple
+.RI [ prognum , versnum , protocol\fR]
+and
+.I port
+on the machine's
+.B portmap
+service. The value of
+.I protocol
+is most likely
+.B
+.SM IPPROTO_UDP
+or
+.BR \s-1IPPROTO_TCP\s0 .
+This routine returns one if it succeeds, zero otherwise.
+Automatically done by
+.BR svc_register(\|) .
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+pmap_unset(prognum, versnum)
+u_long prognum, versnum;
+.fi
+.ft R
+.IP
+A user interface to the
+.B portmap
+service, which destroys all mapping between the triple
+.RI [ prognum , versnum , *\fR]
+and
+.B ports
+on the machine's
+.B portmap
+service. This routine returns one if it succeeds, zero
+otherwise.
+.br
+.if t .ne 15
+.LP
+.ft B
+.nf
+.sp .5
+registerrpc(prognum, versnum, procnum, procname, inproc, outproc)
+u_long prognum, versnum, procnum;
+char *(*procname) (\|) ;
+xdrproc_t inproc, outproc;
+.fi
+.ft R
+.IP
+Register procedure
+.I procname
+with the
+.SM RPC
+service package. If a request arrives for program
+.IR prognum ,
+version
+.IR versnum ,
+and procedure
+.IR procnum ,
+.I procname
+is called with a pointer to its parameter(s);
+.I progname
+should return a pointer to its static result(s);
+.I inproc
+is used to decode the parameters while
+.I outproc
+is used to encode the results.
+This routine returns zero if the registration succeeded, \-1
+otherwise.
+.IP
+Warning: remote procedures registered in this form
+are accessed using the
+.SM UDP/IP
+transport; see
+.B svcudp_create(\|)
+for restrictions.
+.br
+.if t .ne 5
+.LP
+.ft B
+.nf
+.sp .5
+struct rpc_createerr rpc_createerr;
+.fi
+.ft R
+.IP
+A global variable whose value is set by any
+.SM RPC
+client creation routine
+that does not succeed. Use the routine
+.B clnt_pcreateerror(\|)
+to print the reason why.
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+svc_destroy(xprt)
+\s-1SVCXPRT\s0 *
+xprt;
+.fi
+.ft R
+.IP
+A macro that destroys the
+.SM RPC
+service transport handle,
+.IR xprt .
+Destruction usually involves deallocation
+of private data structures, including
+.I xprt
+itself. Use of
+.I xprt
+is undefined after calling this routine.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+fd_set svc_fdset;
+.fi
+.ft R
+.IP
+A global variable reflecting the
+.SM RPC
+service side's
+read file descriptor bit mask; it is suitable as a template parameter
+to the
+.B select
+system call. This is only of interest
+if a service implementor does not call
+.BR svc_run(\|) ,
+but rather does his own asynchronous event processing.
+This variable is read-only (do not pass its address to
+.BR select !),
+yet it may change after calls to
+.B svc_getreqset(\|)
+or any creation routines.
+.br
+As well, note that if the process has descriptor limits
+which are extended beyond
+.BR FD_SETSIZE ,
+this variable will only be usable for the first
+.BR FD_SETSIZE
+descriptors.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+int svc_fds;
+.fi
+.ft R
+.IP
+Similar to
+.BR svc_fedset(\|) ,
+but limited to 32 descriptors. This
+interface is obsoleted by
+.BR svc_fdset(\|) .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+svc_freeargs(xprt, inproc, in)
+\s-1SVCXPRT\s0 *xprt;
+xdrproc_t inproc;
+char *in;
+.fi
+.ft R
+.IP
+A macro that frees any data allocated by the
+.SM RPC/XDR
+system when it decoded the arguments to a service procedure
+using
+.BR svc_getargs(\|) .
+This routine returns 1 if the results were successfully
+freed,
+and zero otherwise.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+svc_getargs(xprt, inproc, in)
+\s-1SVCXPRT\s0 *xprt;
+xdrproc_t inproc;
+char *in;
+.fi
+.ft R
+.IP
+A macro that decodes the arguments of an
+.SM RPC
+request
+associated with the
+.SM RPC
+service transport handle,
+.IR xprt .
+The parameter
+.I in
+is the address where the arguments will be placed;
+.I inproc
+is the
+.SM XDR
+routine used to decode the arguments.
+This routine returns one if decoding succeeds, and zero
+otherwise.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+struct sockaddr_in *
+svc_getcaller(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+The approved way of getting the network address of the caller
+of a procedure associated with the
+.SM RPC
+service transport handle,
+.IR xprt .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+svc_getreqset(rdfds)
+fd_set *rdfds;
+.fi
+.ft R
+.IP
+This routine is only of interest if a service implementor
+does not call
+.BR svc_run(\|) ,
+but instead implements custom asynchronous event processing.
+It is called when the
+.B select
+system call has determined that an
+.SM RPC
+request has arrived on some
+.SM RPC
+.B socket(s) ;
+.I rdfds
+is the resultant read file descriptor bit mask.
+The routine returns when all sockets associated with the
+value of
+.I rdfds
+have been serviced.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+svc_getreq(rdfds)
+int rdfds;
+.fi
+.ft R
+.IP
+Similar to
+.BR svc_getreqset(\|) ,
+but limited to 32 descriptors. This interface is obsoleted by
+.BR svc_getreqset(\|) .
+.br
+.if t .ne 17
+.LP
+.ft B
+.nf
+.sp .5
+svc_register(xprt, prognum, versnum, dispatch, protocol)
+\s-1SVCXPRT\s0 *xprt;
+u_long prognum, versnum;
+void (*dispatch) (\|);
+u_long protocol;
+.fi
+.ft R
+.IP
+Associates
+.I prognum
+and
+.I versnum
+with the service dispatch procedure,
+.IR dispatch .
+If
+.I protocol
+is zero, the service is not registered with the
+.B portmap
+service. If
+.I protocol
+is non-zero, then a mapping of the triple
+.RI [ prognum , versnum , protocol\fR]
+to
+\fB\%xprt\->xp_port\fR
+is established with the local
+.B portmap
+service (generally
+.I protocol
+is zero,
+.B
+.SM IPPROTO_UDP
+or
+.B
+.SM IPPROTO_TCP
+).
+The procedure
+.I dispatch
+has the following form:
+.RS 1i
+.ft B
+.nf
+dispatch(request, xprt)
+struct svc_req *request;
+\s-1SVCXPRT\s0 *xprt;
+.ft R
+.fi
+.RE
+.IP
+The
+.B svc_register(\|)
+routine returns one if it succeeds, and zero otherwise.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+svc_run(\|)
+.fi
+.ft R
+.IP
+This routine never returns. It waits for
+.SM RPC
+requests to arrive, and calls the appropriate service
+procedure using
+.B svc_getreq(\|)
+when one arrives. This procedure is usually waiting for a
+.B select(\|)
+system call to return.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+svc_sendreply(xprt, outproc, out)
+\s-1SVCXPRT\s0 *xprt;
+xdrproc_t outproc;
+char *out;
+.fi
+.ft R
+.IP
+Called by an
+.SM RPC
+service's dispatch routine to send the results of a
+remote procedure call. The parameter
+.I xprt
+is the request's associated transport handle;
+.I outproc
+is the
+.SM XDR
+routine which is used to encode the results; and
+.I out
+is the address of the results.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svc_unregister(prognum, versnum)
+u_long prognum, versnum;
+.fi
+.ft R
+.IP
+Remove all mapping of the double
+.RI [ prognum , versnum ]
+to dispatch routines, and of the triple
+.RI [ prognum , versnum , *\fR]
+to port number.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_auth(xprt, why)
+\s-1SVCXPRT\s0 *xprt;
+enum auth_stat why;
+.fi
+.ft R
+.IP
+Called by a service dispatch routine that refuses to perform
+a remote procedure call due to an authentication error.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_decode(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called by a service dispatch routine that cannot successfully
+decode its parameters. See also
+.BR svc_getargs(\|) .
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_noproc(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called by a service dispatch routine that does not implement
+the procedure number that the caller requests.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_noprog(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called when the desired program is not registered with the
+.SM RPC
+package. Service implementors usually do not need this routine.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_progvers(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called when the desired version of a program is not registered
+with the
+.SM RPC
+package. Service implementors usually do not need this routine.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_systemerr(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called by a service dispatch routine when it detects a system
+error
+not covered by any particular protocol.
+For example, if a service can no longer allocate storage,
+it may call this routine.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+svcerr_weakauth(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Called by a service dispatch routine that refuses to perform
+a remote procedure call due to insufficient
+authentication parameters. The routine calls
+.BR "svcerr_auth(xprt, \s-1AUTH_TOOWEAK\s0)" .
+.br
+.if t .ne 11
+.LP
+.ft B
+.nf
+.sp .5
+\s-1SVCXPRT\s0 *
+svcraw_create(\|)
+.fi
+.ft R
+.IP
+This routine creates a toy
+.SM RPC
+service transport, to which it returns a pointer. The
+transport
+is really a buffer within the process's address space,
+so the corresponding
+.SM RPC
+client should live in the same
+address space;
+see
+.BR clntraw_create(\|) .
+This routine allows simulation of
+.SM RPC
+and acquisition of
+.SM RPC
+overheads (such as round trip times), without any kernel
+interference.
+This routine returns
+.SM NULL
+if it fails.
+.br
+.if t .ne 11
+.LP
+.ft B
+.nf
+.sp .5
+\s-1SVCXPRT\s0 *
+svctcp_create(sock, send_buf_size, recv_buf_size)
+int sock;
+u_int send_buf_size, recv_buf_size;
+.fi
+.ft R
+.IP
+This routine creates a
+.SM TCP/IP\s0-based
+.SM RPC
+service transport, to which it returns a pointer.
+The transport is associated with the socket
+.IR sock ,
+which may be
+.BR \s-1RPC_ANYSOCK\s0 ,
+in which case a new socket is created.
+If the socket is not bound to a local
+.SM TCP
+port, then this routine binds it to an arbitrary port. Upon
+completion,
+\fB\%xprt\->xp_sock\fR
+is the transport's socket descriptor, and
+\fB\%xprt\->xp_port\fR
+is the transport's port number.
+This routine returns
+.SM NULL
+if it fails. Since
+.SM TCP\s0-based
+.SM RPC
+uses buffered
+.SM I/O ,
+users may specify the size of buffers; values of zero
+choose suitable defaults.
+.br
+.if t .ne 11
+.LP
+.ft B
+.nf
+.sp .5
+\s-1SVCXPRT\s0 *
+svcfd_create(fd, sendsize, recvsize)
+int fd;
+u_int sendsize;
+u_int recvsize;
+.fi
+.ft R
+.IP
+Create a service on top of any open descriptor. Typically,
+this
+descriptor is a connected socket for a stream protocol such
+as
+.SM TCP\s0.
+.I sendsize
+and
+.I recvsize
+indicate sizes for the send and receive buffers. If they are
+zero, a reasonable default is chosen.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+\s-1SVCXPRT\s0 *
+svcudp_bufcreate(sock, sendsize, recosize)
+int sock;
+.fi
+.ft R
+.IP
+This routine creates a
+.SM UDP/IP\s0-based
+.SM RPC
+service transport, to which it returns a pointer.
+The transport is associated with the socket
+.IR sock ,
+which may be
+.B \s-1RPC_ANYSOCK\s0 ,
+in which case a new socket is created.
+If the socket is not bound to a local
+.SM UDP
+port, then this routine binds it to an arbitrary port. Upon
+completion,
+\fB\%xprt\->xp_sock\fR
+is the transport's socket descriptor, and
+\fB\%xprt\->xp_port\fR
+is the transport's port number.
+This routine returns
+.SM NULL
+if it fails.
+.IP
+This allows the user to specify the maximum packet size for sending and
+receiving
+.SM UDP\s0-based
+.SM RPC messages.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_accepted_reply(xdrs, ar)
+\s-1XDR\s0 *xdrs;
+struct accepted_reply *ar;
+.fi
+.ft R
+.IP
+Used for encoding
+.SM RPC
+reply messages. This routine is useful for users who
+wish to generate
+\s-1RPC\s0-style
+messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_authunix_parms(xdrs, aupp)
+\s-1XDR\s0 *xdrs;
+struct authunix_parms *aupp;
+.fi
+.ft R
+.IP
+Used for describing
+.SM UNIX
+credentials. This routine is useful for users
+who wish to generate these credentials without using the
+.SM RPC
+authentication package.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdr_callhdr(xdrs, chdr)
+\s-1XDR\s0 *xdrs;
+struct rpc_msg *chdr;
+.fi
+.ft R
+.IP
+Used for describing
+.SM RPC
+call header messages.
+This routine is useful for users who wish to generate
+.SM RPC\s0-style
+messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_callmsg(xdrs, cmsg)
+\s-1XDR\s0 *xdrs;
+struct rpc_msg *cmsg;
+.fi
+.ft R
+.IP
+Used for describing
+.SM RPC
+call messages.
+This routine is useful for users who wish to generate
+.SM RPC\s0-style
+messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_opaque_auth(xdrs, ap)
+\s-1XDR\s0 *xdrs;
+struct opaque_auth *ap;
+.fi
+.ft R
+.IP
+Used for describing
+.SM RPC
+authentication information messages.
+This routine is useful for users who wish to generate
+.SM RPC\s0-style
+messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_pmap(xdrs, regs)
+\s-1XDR\s0 *xdrs;
+struct pmap *regs;
+.fi
+.ft R
+.IP
+Used for describing parameters to various
+.B portmap
+procedures, externally.
+This routine is useful for users who wish to generate
+these parameters without using the
+.B pmap
+interface.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_pmaplist(xdrs, rp)
+\s-1XDR\s0 *xdrs;
+struct pmaplist **rp;
+.fi
+.ft R
+.IP
+Used for describing a list of port mappings, externally.
+This routine is useful for users who wish to generate
+these parameters without using the
+.B pmap
+interface.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_rejected_reply(xdrs, rr)
+\s-1XDR\s0 *xdrs;
+struct rejected_reply *rr;
+.fi
+.ft R
+.IP
+Used for describing
+.SM RPC
+reply messages.
+This routine is useful for users who wish to generate
+.SM RPC\s0-style
+messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdr_replymsg(xdrs, rmsg)
+\s-1XDR\s0 *xdrs;
+struct rpc_msg *rmsg;
+.fi
+.ft R
+.IP
+Used for describing
+.SM RPC
+reply messages.
+This routine is useful for users who wish to generate
+.SM RPC
+style messages without using the
+.SM RPC
+package.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+xprt_register(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+After
+.SM RPC
+service transport handles are created,
+they should register themselves with the
+.SM RPC
+service package.
+This routine modifies the global variable
+.BR svc_fds(\|) .
+Service implementors usually do not need this routine.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+xprt_unregister(xprt)
+\s-1SVCXPRT\s0 *xprt;
+.fi
+.ft R
+.IP
+Before an
+.SM RPC
+service transport handle is destroyed,
+it should unregister itself with the
+.SM RPC
+service package.
+This routine modifies the global variable
+.BR svc_fds(\|) .
+Service implementors usually do not need this routine.
+.SH SEE ALSO
+.BR rpc_secure (3),
+.BR xdr (3)
+.br
+The following manuals:
+.RS
+.ft I
+Remote Procedure Calls: Protocol Specification
+.br
+Remote Procedure Call Programming Guide
+.br
+rpcgen Programming Guide
+.br
+.ft R
+.RE
+.IR "\s-1RPC\s0: Remote Procedure Call Protocol Specification" ,
+.SM RFC1050, Sun Microsystems, Inc.,
+.SM USC-ISI\s0.
+
diff --git a/lib/libc/rpc/rpc.5 b/lib/libc/rpc/rpc.5
new file mode 100644
index 0000000..d464395
--- /dev/null
+++ b/lib/libc/rpc/rpc.5
@@ -0,0 +1,34 @@
+.\" @(#)rpc.5 2.2 88/08/03 4.0 RPCSRC; from 1.4 87/11/27 SMI;
+.Dd September 26, 1985
+.Dt RPC 5
+.Sh NAME
+.Nm rpc
+.Nd rpc program number data base
+.Sh SYNOPSIS
+/etc/rpc
+.Sh DESCRIPTION
+The
+.Pa /etc/rpc
+file contains user readable names that
+can be used in place of rpc program numbers.
+Each line has the following information:
+.Pp
+.Bl -bullet -compact
+.It
+name of server for the rpc program
+.It
+rpc program number
+.It
+aliases
+.El
+.Pp
+Items are separated by any number of blanks and/or
+tab characters.
+A ``#'' indicates the beginning of a comment; characters up to the end of
+the line are not interpreted by routines which search the file.
+.Sh FILES
+.Bl -tag -compact -width /etc/rpc
+.Pa /etc/rpc
+.El
+.Sh "SEE ALSO"
+.Xr getrpcent 3
diff --git a/lib/libc/rpc/rpc_callmsg.c b/lib/libc/rpc/rpc_callmsg.c
new file mode 100644
index 0000000..af8e573
--- /dev/null
+++ b/lib/libc/rpc/rpc_callmsg.c
@@ -0,0 +1,193 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: rpc_callmsg.c,v 1.5 1996/12/30 14:55:38 peter Exp $";
+#endif
+
+/*
+ * rpc_callmsg.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ */
+
+#include <sys/param.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/rpc.h>
+
+/*
+ * XDR a call message
+ */
+bool_t
+xdr_callmsg(xdrs, cmsg)
+ register XDR *xdrs;
+ register struct rpc_msg *cmsg;
+{
+ register int32_t *buf;
+ register struct opaque_auth *oa;
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
+ + RNDUP(cmsg->rm_call.cb_cred.oa_length)
+ + 2 * BYTES_PER_XDR_UNIT
+ + RNDUP(cmsg->rm_call.cb_verf.oa_length));
+ if (buf != NULL) {
+ IXDR_PUT_LONG(buf, cmsg->rm_xid);
+ IXDR_PUT_ENUM(buf, cmsg->rm_direction);
+ if (cmsg->rm_direction != CALL) {
+ return (FALSE);
+ }
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
+ if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
+ return (FALSE);
+ }
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
+ IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
+ oa = &cmsg->rm_call.cb_cred;
+ IXDR_PUT_ENUM(buf, oa->oa_flavor);
+ IXDR_PUT_LONG(buf, oa->oa_length);
+ if (oa->oa_length) {
+ memcpy((caddr_t)buf, oa->oa_base, oa->oa_length);
+ buf += RNDUP(oa->oa_length) / sizeof (int32_t);
+ }
+ oa = &cmsg->rm_call.cb_verf;
+ IXDR_PUT_ENUM(buf, oa->oa_flavor);
+ IXDR_PUT_LONG(buf, oa->oa_length);
+ if (oa->oa_length) {
+ memcpy((caddr_t)buf, oa->oa_base, oa->oa_length);
+ /* no real need....
+ buf += RNDUP(oa->oa_length) / sizeof (int32_t);
+ */
+ }
+ return (TRUE);
+ }
+ }
+ if (xdrs->x_op == XDR_DECODE) {
+ buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
+ if (buf != NULL) {
+ cmsg->rm_xid = IXDR_GET_LONG(buf);
+ cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
+ if (cmsg->rm_direction != CALL) {
+ return (FALSE);
+ }
+ cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
+ if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
+ return (FALSE);
+ }
+ cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
+ cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
+ cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
+ oa = &cmsg->rm_call.cb_cred;
+ oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
+ oa->oa_length = IXDR_GET_LONG(buf);
+ if (oa->oa_length) {
+ if (oa->oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ if (oa->oa_base == NULL) {
+ oa->oa_base = (caddr_t)
+ mem_alloc(oa->oa_length);
+ }
+ buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
+ if (buf == NULL) {
+ if (xdr_opaque(xdrs, oa->oa_base,
+ oa->oa_length) == FALSE) {
+ return (FALSE);
+ }
+ } else {
+ memcpy(oa->oa_base, (caddr_t)buf,
+ oa->oa_length);
+ /* no real need....
+ buf += RNDUP(oa->oa_length) /
+ sizeof (int32_t);
+ */
+ }
+ }
+ oa = &cmsg->rm_call.cb_verf;
+ buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
+ xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
+ return (FALSE);
+ }
+ } else {
+ oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
+ oa->oa_length = IXDR_GET_LONG(buf);
+ }
+ if (oa->oa_length) {
+ if (oa->oa_length > MAX_AUTH_BYTES) {
+ return (FALSE);
+ }
+ if (oa->oa_base == NULL) {
+ oa->oa_base = (caddr_t)
+ mem_alloc(oa->oa_length);
+ }
+ buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
+ if (buf == NULL) {
+ if (xdr_opaque(xdrs, oa->oa_base,
+ oa->oa_length) == FALSE) {
+ return (FALSE);
+ }
+ } else {
+ memcpy(oa->oa_base, (caddr_t)buf,
+ oa->oa_length);
+ /* no real need...
+ buf += RNDUP(oa->oa_length) /
+ sizeof (int32_t);
+ */
+ }
+ }
+ return (TRUE);
+ }
+ }
+ if (
+ xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
+ xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
+ (cmsg->rm_direction == CALL) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
+ (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) &&
+ xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
+ return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
+ return (FALSE);
+}
+
diff --git a/lib/libc/rpc/rpc_commondata.c b/lib/libc/rpc/rpc_commondata.c
new file mode 100644
index 0000000..9640782
--- /dev/null
+++ b/lib/libc/rpc/rpc_commondata.c
@@ -0,0 +1,43 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)rpc_commondata.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: rpc_commondata.c,v 1.3 1996/12/30 14:57:33 peter Exp $";
+#endif
+
+#include <rpc/rpc.h>
+/*
+ * This file should only contain common data (global data) that is exported
+ * by public interfaces
+ */
+struct opaque_auth _null_auth;
+fd_set svc_fdset;
+int svc_maxfd = -1;
+struct rpc_createerr rpc_createerr;
diff --git a/lib/libc/rpc/rpc_dtablesize.c b/lib/libc/rpc/rpc_dtablesize.c
new file mode 100644
index 0000000..c2703fa
--- /dev/null
+++ b/lib/libc/rpc/rpc_dtablesize.c
@@ -0,0 +1,61 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)rpc_dtablesize.c 1.2 87/08/11 Copyr 1987 Sun Micro";*/
+/*static char *sccsid = "from: @(#)rpc_dtablesize.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: rpc_dtablesize.c,v 1.6 1996/12/30 18:41:20 peter Exp $";
+#endif
+
+#include <sys/types.h>
+#include <unistd.h>
+
+/*
+ * Cache the result of getdtablesize(), so we don't have to do an
+ * expensive system call every time.
+ */
+/*
+ * XXX In FreeBSD 2.x, you can have the maximum number of open file
+ * descriptors be greater than FD_SETSIZE (which us 256 by default).
+ *
+ * Since old programs tend to use this call to determine the first arg
+ * for select(), having this return > FD_SETSIZE is a Bad Idea(TM)!
+ */
+int
+_rpc_dtablesize(void)
+{
+ static int size;
+
+ if (size == 0) {
+ size = getdtablesize();
+ if (size > FD_SETSIZE)
+ size = FD_SETSIZE;
+ }
+ return (size);
+}
diff --git a/lib/libc/rpc/rpc_prot.c b/lib/libc/rpc/rpc_prot.c
new file mode 100644
index 0000000..8debaf1
--- /dev/null
+++ b/lib/libc/rpc/rpc_prot.c
@@ -0,0 +1,297 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)rpc_prot.c 2.3 88/08/07 4.0 RPCSRC";*/
+static char *rcsid = "$Id: rpc_prot.c,v 1.4 1996/12/30 15:00:53 peter Exp $";
+#endif
+
+/*
+ * rpc_prot.c
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * This set of routines implements the rpc message definition,
+ * its serializer and some common rpc utility routines.
+ * The routines are meant for various implementations of rpc -
+ * they are NOT for the rpc client or rpc service implementations!
+ * Because authentication stuff is easy and is part of rpc, the opaque
+ * routines are also in this program.
+ */
+
+#include <sys/param.h>
+
+#include <rpc/rpc.h>
+
+/* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
+
+struct opaque_auth _null_auth;
+
+/*
+ * XDR an opaque authentication struct
+ * (see auth.h)
+ */
+bool_t
+xdr_opaque_auth(xdrs, ap)
+ register XDR *xdrs;
+ register struct opaque_auth *ap;
+{
+
+ if (xdr_enum(xdrs, &(ap->oa_flavor)))
+ return (xdr_bytes(xdrs, &ap->oa_base,
+ &ap->oa_length, MAX_AUTH_BYTES));
+ return (FALSE);
+}
+
+/*
+ * XDR a DES block
+ */
+bool_t
+xdr_des_block(xdrs, blkp)
+ register XDR *xdrs;
+ register des_block *blkp;
+{
+ return (xdr_opaque(xdrs, (caddr_t)blkp, sizeof(des_block)));
+}
+
+/* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
+
+/*
+ * XDR the MSG_ACCEPTED part of a reply message union
+ */
+bool_t
+xdr_accepted_reply(xdrs, ar)
+ register XDR *xdrs;
+ register struct accepted_reply *ar;
+{
+
+ /* personalized union, rather than calling xdr_union */
+ if (! xdr_opaque_auth(xdrs, &(ar->ar_verf)))
+ return (FALSE);
+ if (! xdr_enum(xdrs, (enum_t *)&(ar->ar_stat)))
+ return (FALSE);
+ switch (ar->ar_stat) {
+
+ case SUCCESS:
+ return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where));
+
+ case PROG_MISMATCH:
+ if (! xdr_u_int32_t(xdrs, &(ar->ar_vers.low)))
+ return (FALSE);
+ return (xdr_u_int32_t(xdrs, &(ar->ar_vers.high)));
+ default:
+ break;
+ }
+ return (TRUE); /* TRUE => open ended set of problems */
+}
+
+/*
+ * XDR the MSG_DENIED part of a reply message union
+ */
+bool_t
+xdr_rejected_reply(xdrs, rr)
+ register XDR *xdrs;
+ register struct rejected_reply *rr;
+{
+
+ /* personalized union, rather than calling xdr_union */
+ if (! xdr_enum(xdrs, (enum_t *)&(rr->rj_stat)))
+ return (FALSE);
+ switch (rr->rj_stat) {
+
+ case RPC_MISMATCH:
+ if (! xdr_u_int32_t(xdrs, &(rr->rj_vers.low)))
+ return (FALSE);
+ return (xdr_u_int32_t(xdrs, &(rr->rj_vers.high)));
+
+ case AUTH_ERROR:
+ return (xdr_enum(xdrs, (enum_t *)&(rr->rj_why)));
+ }
+ return (FALSE);
+}
+
+static struct xdr_discrim reply_dscrm[3] = {
+ { (int)MSG_ACCEPTED, xdr_accepted_reply },
+ { (int)MSG_DENIED, xdr_rejected_reply },
+ { __dontcare__, NULL_xdrproc_t } };
+
+/*
+ * XDR a reply message
+ */
+bool_t
+xdr_replymsg(xdrs, rmsg)
+ register XDR *xdrs;
+ register struct rpc_msg *rmsg;
+{
+ if (
+ xdr_u_int32_t(xdrs, &(rmsg->rm_xid)) &&
+ xdr_enum(xdrs, (enum_t *)&(rmsg->rm_direction)) &&
+ (rmsg->rm_direction == REPLY) )
+ return (xdr_union(xdrs, (enum_t *)&(rmsg->rm_reply.rp_stat),
+ (caddr_t)&(rmsg->rm_reply.ru), reply_dscrm, NULL_xdrproc_t));
+ return (FALSE);
+}
+
+
+/*
+ * Serializes the "static part" of a call message header.
+ * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
+ * The rm_xid is not really static, but the user can easily munge on the fly.
+ */
+bool_t
+xdr_callhdr(xdrs, cmsg)
+ register XDR *xdrs;
+ register struct rpc_msg *cmsg;
+{
+
+ cmsg->rm_direction = CALL;
+ cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ if (
+ (xdrs->x_op == XDR_ENCODE) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
+ xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
+ xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) )
+ return (xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)));
+ return (FALSE);
+}
+
+/* ************************** Client utility routine ************* */
+
+static void
+accepted(acpt_stat, error)
+ register enum accept_stat acpt_stat;
+ register struct rpc_err *error;
+{
+
+ switch (acpt_stat) {
+
+ case PROG_UNAVAIL:
+ error->re_status = RPC_PROGUNAVAIL;
+ return;
+
+ case PROG_MISMATCH:
+ error->re_status = RPC_PROGVERSMISMATCH;
+ return;
+
+ case PROC_UNAVAIL:
+ error->re_status = RPC_PROCUNAVAIL;
+ return;
+
+ case GARBAGE_ARGS:
+ error->re_status = RPC_CANTDECODEARGS;
+ return;
+
+ case SYSTEM_ERR:
+ error->re_status = RPC_SYSTEMERROR;
+ return;
+
+ case SUCCESS:
+ error->re_status = RPC_SUCCESS;
+ return;
+ }
+ /* something's wrong, but we don't know what ... */
+ error->re_status = RPC_FAILED;
+ error->re_lb.s1 = (long)MSG_ACCEPTED;
+ error->re_lb.s2 = (long)acpt_stat;
+}
+
+static void
+rejected(rjct_stat, error)
+ register enum reject_stat rjct_stat;
+ register struct rpc_err *error;
+{
+
+ switch (rjct_stat) {
+
+ case RPC_VERSMISMATCH:
+ error->re_status = RPC_VERSMISMATCH;
+ return;
+
+ case AUTH_ERROR:
+ error->re_status = RPC_AUTHERROR;
+ return;
+ default:
+ break;
+ }
+ /* something's wrong, but we don't know what ... */
+ error->re_status = RPC_FAILED;
+ error->re_lb.s1 = (long)MSG_DENIED;
+ error->re_lb.s2 = (long)rjct_stat;
+}
+
+/*
+ * given a reply message, fills in the error
+ */
+void
+_seterr_reply(msg, error)
+ register struct rpc_msg *msg;
+ register struct rpc_err *error;
+{
+
+ /* optimized for normal, SUCCESSful case */
+ switch (msg->rm_reply.rp_stat) {
+
+ case MSG_ACCEPTED:
+ if (msg->acpted_rply.ar_stat == SUCCESS) {
+ error->re_status = RPC_SUCCESS;
+ return;
+ };
+ accepted(msg->acpted_rply.ar_stat, error);
+ break;
+
+ case MSG_DENIED:
+ rejected(msg->rjcted_rply.rj_stat, error);
+ break;
+
+ default:
+ error->re_status = RPC_FAILED;
+ error->re_lb.s1 = (long)(msg->rm_reply.rp_stat);
+ break;
+ }
+ switch (error->re_status) {
+
+ case RPC_VERSMISMATCH:
+ error->re_vers.low = msg->rjcted_rply.rj_vers.low;
+ error->re_vers.high = msg->rjcted_rply.rj_vers.high;
+ break;
+
+ case RPC_AUTHERROR:
+ error->re_why = msg->rjcted_rply.rj_why;
+ break;
+
+ case RPC_PROGVERSMISMATCH:
+ error->re_vers.low = msg->acpted_rply.ar_vers.low;
+ error->re_vers.high = msg->acpted_rply.ar_vers.high;
+ break;
+ default:
+ break;
+ }
+}
diff --git a/lib/libc/rpc/rpc_secure.3 b/lib/libc/rpc/rpc_secure.3
new file mode 100644
index 0000000..6e9a2ee
--- /dev/null
+++ b/lib/libc/rpc/rpc_secure.3
@@ -0,0 +1,330 @@
+.\" @(#)rpc_secure.3n 2.1 88/08/08 4.0 RPCSRC; from 1.19 88/06/24 SMI
+.TH RPC 3N "16 February 1988"
+.SH NAME
+rpc_secure \- library routines for secure remote procedure calls
+.SH SYNOPSIS AND DESCRIPTION
+These routines are part of the RPC library. They implement DES
+Authentication. See
+.BR rpc (3N)
+for further details about RPC.
+.LP
+.ft B
+.nf
+.sp .5
+#include <rpc/rpc.h>
+.fi
+.ft R
+.br
+.if t .ne 22
+.LP
+.ft B
+.nf
+.sp .5
+\s-1AUTH\s0 *
+authdes_create(name, window, syncaddr, ckey)
+char *name;
+unsigned window;
+struct sockaddr_in *addr;
+des_block *ckey;
+.fi
+.ft R
+.IP
+.B authdes_create(\|)
+is the first of two routines which interface to the
+.SM RPC
+secure authentication system, known as
+.SM DES
+authentication.
+The second is
+.BR authdes_getucred(\|) ,
+below. Note: the keyserver daemon
+.BR keyserv (8C)
+must be running for the
+.SM DES
+authentication system to work.
+.IP
+.BR authdes_create(\|) ,
+used on the client side, returns an authentication handle that
+will enable the use of the secure authentication system.
+The first parameter
+.I name
+is the network name, or
+.IR netname ,
+of the owner of the server process. This field usually
+represents a
+.I hostname
+derived from the utility routine
+.BR host2netname ,
+but could also represent a user name using
+.BR user2netname .
+The second field is window on the validity of
+the client credential, given in seconds. A small
+window is more secure than a large one, but choosing
+too small of a window will increase the frequency of
+resynchronizations because of clock drift. The third
+parameter
+.I syncaddr
+is optional. If it is
+.SM NULL\s0,
+then the authentication system will assume
+that the local clock is always in sync with the server's
+clock, and will not attempt resynchronizations. If an address
+is supplied, however, then the system will use the address
+for consulting the remote time service whenever
+resynchronization
+is required. This parameter is usually the
+address of the
+.SM RPC
+server itself. The final parameter
+.I ckey
+is also optional. If it is
+.SM NULL\s0,
+then the authentication system will
+generate a random
+.SM DES
+key to be used for the encryption of credentials.
+If it is supplied, however, then it will be used instead.
+.br
+.if t .ne 13
+.LP
+.ft B
+.nf
+.sp .5
+authdes_getucred(adc, uid, gid, grouplen, groups)
+struct authdes_cred *adc;
+short *uid;
+short *gid;
+short *grouplen;
+int *groups;
+.fi
+.ft R
+.IP
+.BR authdes_getucred(\|) ,
+the second of the two
+.SM DES
+authentication routines,
+is used on the server side for converting a
+.SM DES
+credential, which is
+operating system independent, into a
+.UX
+credential. This routine differs from utility routine
+.B netname2user
+in that
+.B authdes_getucred(\|)
+pulls its information from a cache, and does not have to do a
+Yellow Pages lookup every time it is called to get its information.
+.br
+.ft .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+host2netname(name, host, domain)
+char *name;
+char *host;
+char *domain;
+.fi
+.ft R
+.IP
+Convert from a domain-specific hostname to an
+operating-system independent netname. Return
+.SM TRUE
+if it succeeds and
+.SM FALSE
+if it fails. Inverse of
+.BR netname2host(\|) .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+key_decryptsession(remotename, deskey)
+char *remotename;
+des_block *deskey;
+.fi
+.ft R
+.IP
+.B key_decryptsession(\|)
+is an interface to the keyserver daemon, which is associated
+with
+.SM RPC\s0's
+secure authentication system (\s-1DES\s0
+authentication).
+User programs rarely need to call it, or its associated routines
+.BR key_encryptsession(\|) ,
+.B key_gendes(\|)
+and
+.BR key_setsecret(\|) .
+System commands such as
+.B login
+and the
+.SM RPC
+library are the main clients of these four routines.
+.IP
+.B key_decryptsession(\|)
+takes a server netname and a des key, and decrypts the key by
+using the the public key of the the server and the secret key
+associated with the effective uid of the calling process. It
+is the inverse of
+.BR key_encryptsession(\|) .
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+key_encryptsession(remotename, deskey)
+char *remotename;
+des_block *deskey;
+.fi
+.ft R
+.IP
+.B key_encryptsession(\|)
+is a keyserver interface routine. It
+takes a server netname and a des key, and encrypts
+it using the public key of the the server and the secret key
+associated with the effective uid of the calling process. It
+is the inverse of
+.BR key_decryptsession(\|) .
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+key_gendes(deskey)
+des_block *deskey;
+.fi
+.ft R
+.IP
+.B key_gendes(\|)
+is a keyserver interface routine. It
+is used to ask the keyserver for a secure conversation key.
+Choosing one at \(lqrandom\(rq is usually not good enough,
+because
+the common ways of choosing random numbers, such as using the
+current time, are very easy to guess.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+key_setsecret(key)
+char *key;
+.fi
+.ft R
+.IP
+.B key_setsecret(\|)
+is a keyserver interface routine. It is used to set the key for
+the effective
+.I uid
+of the calling process.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+getnetname(name)
+char name[\s-1MAXNETNAMELEN\s0];
+.fi
+.ft R
+.IP
+.B getnetname(\|)
+installs the unique, operating-system independent netname of
+the
+caller in the fixed-length array
+.IR name .
+Returns
+.SM TRUE
+if it succeeds and
+.SM FALSE
+if it fails.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+netname2host(name, host, hostlen)
+char *name;
+char *host;
+int hostlen;
+.fi
+.ft R
+.IP
+Convert from an operating-system independent netname to a
+domain-specific hostname. Returns
+.SM TRUE
+if it succeeds and
+.SM FALSE
+if it fails. Inverse of
+.BR host2netname(\|) .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+netname2user(name, uidp, gidp, gidlenp, gidlist)
+char *name;
+int *uidp;
+int *gidp;
+int *gidlenp;
+int *gidlist;
+.fi
+.ft R
+.IP
+Convert from an operating-system independent netname to a
+domain-specific user
+.SM ID.
+Returns
+.SM TRUE
+if it succeeds and
+.SM FALSE
+if it fails. Inverse of
+.BR user2netname(\|) .
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+user2netname(name, uid, domain)
+char *name;
+int uid;
+char *domain;
+.fi
+.ft R
+.IP
+Convert from a domain-specific username to an operating-system
+independent netname. Returns
+.SM TRUE
+if it succeeds and
+.SM FALSE
+if it fails. Inverse of
+.BR netname2user(\|) .
+.br
+.SH SEE ALSO
+.BR xdr (3N),
+.BR keyserv (8C),
+.BR rpc (3N)
+.br
+The following manuals:
+.RS
+.ft I
+Remote Procedure Calls: Protocol Specification
+.br
+Remote Procedure Call Programming Guide
+.br
+rpcgen Programming Guide
+.br
+.ft R
+.RE
+.IR "\s-1RPC\s0: Remote Procedure Call Protocol Specification" ,
+.SM RFC1050, Sun Microsystems, Inc.,
+.SM USC-ISI\s0.
+
diff --git a/lib/libc/rpc/rpcdname.c b/lib/libc/rpc/rpcdname.c
new file mode 100644
index 0000000..f28b4fd
--- /dev/null
+++ b/lib/libc/rpc/rpcdname.c
@@ -0,0 +1,77 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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 or with the express written consent of
+ * Sun Microsystems, Inc.
+ *
+ * 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
+ */
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)rpcdname.c 1.7 91/03/11 Copyr 1989 Sun Micro";
+#endif
+
+/*
+ * rpcdname.c
+ * Gets the default domain name
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+static char *default_domain = 0;
+
+static char *
+get_default_domain()
+{
+ char temp[256];
+
+ if (default_domain)
+ return (default_domain);
+ if (getdomainname(temp, sizeof(temp)) < 0)
+ return (0);
+ if ((int) strlen(temp) > 0) {
+ default_domain = (char *)malloc((strlen(temp)+(unsigned)1));
+ if (default_domain == 0)
+ return (0);
+ (void) strcpy(default_domain, temp);
+ return (default_domain);
+ }
+ return (0);
+}
+
+/*
+ * This is a wrapper for the system call getdomainname which returns a
+ * ypclnt.h error code in the failure case. It also checks to see that
+ * the domain name is non-null, knowing that the null string is going to
+ * get rejected elsewhere in the NIS client package.
+ */
+int
+_rpc_get_default_domain(domain)
+ char **domain;
+{
+ if ((*domain = get_default_domain()) != 0)
+ return (0);
+ return (-1);
+}
diff --git a/lib/libc/rpc/rstat.1 b/lib/libc/rpc/rstat.1
new file mode 100644
index 0000000..03c3a06
--- /dev/null
+++ b/lib/libc/rpc/rstat.1
@@ -0,0 +1,57 @@
+.\" @(#)rstat.1 2.1 88/08/03 4.0 RPCSRC
+.TH RSTAT 1 "3 August 1988"
+.SH NAME
+rstat \- remote status display
+.SH SYNOPSIS
+.B rstat
+.B host
+.SH DESCRIPTION
+.LP
+.B rstat
+displays a summary of the current system status of a particular
+.BR host .
+The output shows the current time of day, how long the system has
+been up,
+and the load averages.
+The load average numbers give the number of jobs in the run queue
+averaged over 1, 5 and 15 minutes.
+.PP
+The
+.B rstat_svc(8)
+daemon must be running on the remote host for this command to
+work.
+.B rstat
+uses an RPC protocol defined in /usr/include/rpcsvc/rstat.x.
+.SH EXAMPLE
+.RS
+.ft B
+.nf
+example% rstat otherhost
+7:36am up 6 days, 16:45, load average: 0.20, 0.23, 0.18
+example%
+.ft R
+.fi
+.RE
+.SH DIAGNOSTICS
+.LP
+rstat: RPC: Program not registered
+.IP
+The
+.B rstat_svc
+daemon has not been started on the remote host.
+.LP
+rstat: RPC: Timed out
+.IP
+A communication error occurred. Either the network is
+excessively congested, or the
+.B rstat_svc
+daemon has terminated on the remote host.
+.LP
+rstat: RPC: Port mapper failure - RPC: Timed out
+.IP
+The remote host is not running the portmapper (see
+.BR portmap(8) ),
+and cannot accommodate any RPC-based services. The host may be down.
+.SH "SEE ALSO"
+.BR portmap (8),
+.BR rstat_svc (8)
diff --git a/lib/libc/rpc/rstat_svc.8 b/lib/libc/rpc/rstat_svc.8
new file mode 100644
index 0000000..b7b4386
--- /dev/null
+++ b/lib/libc/rpc/rstat_svc.8
@@ -0,0 +1,21 @@
+.\" @(#)rstat_svc.8c 2.2 88/08/03 4.0 RPCSRC; from 1.10 87/09/09 SMI
+.TH RSTAT_SVC 8 "24 November 1987"
+.SH NAME
+rstat_svc \- kernel statistics server
+.SH SYNOPSIS
+.B /etc/rstat_svc
+.SH DESCRIPTION
+.LP
+.B rstat_svc
+is a server which returns performance statistics
+obtained from the kernel.
+These statistics are graphically displayed by the Sun Microsystems program,
+.BR perfmeter (1).
+The
+.B rstat_svc
+daemon is normally invoked at boot time through /etc/rc.local.
+.PP
+.B rstat_svc
+uses an RPC protocol defined in /usr/include/rpcsvc/rstat.x.
+.\" .SH "SEE ALSO"
+.\" .BR rstat (1),
diff --git a/lib/libc/rpc/rtime.3 b/lib/libc/rpc/rtime.3
new file mode 100644
index 0000000..af0c1ca
--- /dev/null
+++ b/lib/libc/rpc/rtime.3
@@ -0,0 +1,43 @@
+.\" @(#)rtime.3n 2.1 88/08/08 4.0 RPCSRC; from 1.5 88/02/08 SMI
+.TH RTIME 3 "22 November 1987"
+.SH NAME
+rtime \- get remote time
+.SH SYNOPSIS
+.nf
+.B #include <sys/types.h>
+.B #include <sys/time.h>
+.B #include <netinet/in.h>
+.LP
+.B int rtime(addrp, timep, timeout)
+.B struct sockaddr_in \(**addrp;
+.B struct timeval \(**timep;
+.B struct timeval \(**timeout;
+.fi
+.SH DESCRIPTION
+.B rtime(\|)
+consults the Internet Time Server at the address pointed to by
+.I addrp
+and returns the remote time in the
+.B timeval
+struct pointed to by
+.IR timep .
+Normally, the
+.SM UDP
+protocol is used when consulting the Time Server. The
+.I timeout
+parameter specifies how long the
+routine should wait before giving
+up when waiting for a reply. If
+.I timeout
+is specified as
+.SM NULL\s0,
+however, the routine will instead use
+.SM TCP
+and block until a reply is received from the time server.
+.LP
+The routine returns 0 if it is successful. Otherwise,
+it returns \-1 and
+.B errno
+is set to reflect the cause of the error.
+.SH "SEE ALSO"
+.BR timed (8c)
diff --git a/lib/libc/rpc/rtime.c b/lib/libc/rpc/rtime.c
new file mode 100644
index 0000000..fb2b402
--- /dev/null
+++ b/lib/libc/rpc/rtime.c
@@ -0,0 +1,157 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+/*
+ * Copyright (c) 1988 by Sun Microsystems, Inc.
+
+ */
+
+/*
+ * rtime - get time from remote machine
+ *
+ * gets time, obtaining value from host
+ * on the udp/time socket. Since timeserver returns
+ * with time of day in seconds since Jan 1, 1900, must
+ * subtract seconds before Jan 1, 1970 to get
+ * what unix uses.
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <netdb.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/* from: static char sccsid[] = "@(#)rtime.c 2.2 88/08/10 4.0 RPCSRC; from 1.8 88/02/08 SMI"; */
+static const char rcsid[] = "$Id$";
+#endif
+
+extern int _rpc_dtablesize __P(( void ));
+
+#define NYEARS (unsigned long)(1970 - 1900)
+#define TOFFSET (unsigned long)(60*60*24*(365*NYEARS + (NYEARS/4)))
+
+static void do_close __P(( int ));
+
+int
+rtime(addrp, timep, timeout)
+ struct sockaddr_in *addrp;
+ struct timeval *timep;
+ struct timeval *timeout;
+{
+ int s;
+ fd_set readfds;
+ int res;
+ unsigned long thetime;
+ struct sockaddr_in from;
+ int fromlen;
+ int type;
+ struct servent *serv;
+
+ if (timeout == NULL) {
+ type = SOCK_STREAM;
+ } else {
+ type = SOCK_DGRAM;
+ }
+ s = socket(AF_INET, type, 0);
+ if (s < 0) {
+ return(-1);
+ }
+ addrp->sin_family = AF_INET;
+
+ /* TCP and UDP port are the same in this case */
+ if ((serv = getservbyname("time", "tcp")) == NULL) {
+ return(-1);
+ }
+
+ addrp->sin_port = serv->s_port;
+
+ if (type == SOCK_DGRAM) {
+ res = sendto(s, (char *)&thetime, sizeof(thetime), 0,
+ (struct sockaddr *)addrp, sizeof(*addrp));
+ if (res < 0) {
+ do_close(s);
+ return(-1);
+ }
+ do {
+ FD_ZERO(&readfds);
+ FD_SET(s, &readfds);
+ res = select(_rpc_dtablesize(), &readfds,
+ (fd_set *)NULL, (fd_set *)NULL, timeout);
+ } while (res < 0 && errno == EINTR);
+ if (res <= 0) {
+ if (res == 0) {
+ errno = ETIMEDOUT;
+ }
+ do_close(s);
+ return(-1);
+ }
+ fromlen = sizeof(from);
+ res = recvfrom(s, (char *)&thetime, sizeof(thetime), 0,
+ (struct sockaddr *)&from, &fromlen);
+ do_close(s);
+ if (res < 0) {
+ return(-1);
+ }
+ } else {
+ if (connect(s, (struct sockaddr *)addrp, sizeof(*addrp)) < 0) {
+ do_close(s);
+ return(-1);
+ }
+ res = read(s, (char *)&thetime, sizeof(thetime));
+ do_close(s);
+ if (res < 0) {
+ return(-1);
+ }
+ }
+ if (res != sizeof(thetime)) {
+ errno = EIO;
+ return(-1);
+ }
+ thetime = ntohl(thetime);
+ timep->tv_sec = thetime - TOFFSET;
+ timep->tv_usec = 0;
+ return(0);
+}
+
+static void
+do_close(s)
+ int s;
+{
+ int save;
+
+ save = errno;
+ (void) close(s);
+ errno = save;
+}
diff --git a/lib/libc/rpc/svc.c b/lib/libc/rpc/svc.c
new file mode 100644
index 0000000..ab0e8c1
--- /dev/null
+++ b/lib/libc/rpc/svc.c
@@ -0,0 +1,494 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc.c 1.44 88/02/08 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc.c 2.4 88/08/11 4.0 RPCSRC";*/
+static char *rcsid = "$Id: svc.c,v 1.7 1996/12/30 15:07:33 peter Exp $";
+#endif
+
+/*
+ * svc.c, Server-side remote procedure call interface.
+ *
+ * There are two sets of procedures here. The xprt routines are
+ * for handling transport handles. The svc routines handle the
+ * list of service routines.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <sys/errno.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+
+static SVCXPRT **xports;
+static int xportssize;
+
+#define NULL_SVC ((struct svc_callout *)0)
+#define RQCRED_SIZE 400 /* this size is excessive */
+
+#define max(a, b) (a > b ? a : b)
+
+/*
+ * The services list
+ * Each entry represents a set of procedures (an rpc program).
+ * The dispatch routine takes request structs and runs the
+ * apropriate procedure.
+ */
+static struct svc_callout {
+ struct svc_callout *sc_next;
+ u_long sc_prog;
+ u_long sc_vers;
+ void (*sc_dispatch)();
+} *svc_head;
+
+static struct svc_callout *svc_find();
+
+int __svc_fdsetsize;
+fd_set *__svc_fdset;
+
+/* *************** SVCXPRT related stuff **************** */
+
+/*
+ * Activate a transport handle.
+ */
+void
+xprt_register(xprt)
+ SVCXPRT *xprt;
+{
+ register int sock = xprt->xp_sock;
+
+ if (sock + 1 > __svc_fdsetsize) {
+ int bytes = howmany(sock + 1, NFDBITS) * sizeof(fd_mask);
+ fd_set *fds;
+
+ fds = (fd_set *)malloc(bytes);
+ memset(fds, 0, bytes);
+ if (__svc_fdset) {
+ memcpy(fds, __svc_fdset, howmany(__svc_fdsetsize,
+ NFDBITS) * sizeof(fd_mask));
+ free(__svc_fdset);
+ }
+ __svc_fdset = fds;
+ __svc_fdsetsize = howmany(sock+1, NFDBITS);
+ }
+
+ if (sock < FD_SETSIZE)
+ FD_SET(sock, &svc_fdset);
+ FD_SET(sock, __svc_fdset);
+
+ if (xports == NULL || sock + 1 > xportssize) {
+ SVCXPRT **xp;
+ int size = FD_SETSIZE;
+
+ if (sock + 1 > size)
+ size = sock + 1;
+ xp = (SVCXPRT **)mem_alloc(size * sizeof(SVCXPRT *));
+ memset(xp, 0, size * sizeof(SVCXPRT *));
+ if (xports) {
+ memcpy(xp, xports, xportssize * sizeof(SVCXPRT *));
+ free(xports);
+ }
+ xportssize = size;
+ xports = xp;
+ }
+ xports[sock] = xprt;
+ svc_maxfd = max(svc_maxfd, sock);
+}
+
+/*
+ * De-activate a transport handle.
+ */
+void
+xprt_unregister(xprt)
+ SVCXPRT *xprt;
+{
+ register int sock = xprt->xp_sock;
+
+ if (xports[sock] == xprt) {
+ xports[sock] = (SVCXPRT *)0;
+ if (sock < FD_SETSIZE)
+ FD_CLR(sock, &svc_fdset);
+ FD_CLR(sock, __svc_fdset);
+ if (sock == svc_maxfd) {
+ for (svc_maxfd--; svc_maxfd >= 0; svc_maxfd--)
+ if (xports[svc_maxfd])
+ break;
+ }
+ /*
+ * XXX could use svc_maxfd as a hint to
+ * decrease the size of __svc_fdset
+ */
+ }
+}
+
+
+/* ********************** CALLOUT list related stuff ************* */
+
+/*
+ * Add a service program to the callout list.
+ * The dispatch routine will be called when a rpc request for this
+ * program number comes in.
+ */
+bool_t
+svc_register(xprt, prog, vers, dispatch, protocol)
+ SVCXPRT *xprt;
+ u_long prog;
+ u_long vers;
+ void (*dispatch)();
+ int protocol;
+{
+ struct svc_callout *prev;
+ register struct svc_callout *s;
+
+ if ((s = svc_find(prog, vers, &prev)) != NULL_SVC) {
+ if (s->sc_dispatch == dispatch)
+ goto pmap_it; /* he is registering another xptr */
+ return (FALSE);
+ }
+ s = (struct svc_callout *)mem_alloc(sizeof(struct svc_callout));
+ if (s == (struct svc_callout *)0) {
+ return (FALSE);
+ }
+ s->sc_prog = prog;
+ s->sc_vers = vers;
+ s->sc_dispatch = dispatch;
+ s->sc_next = svc_head;
+ svc_head = s;
+pmap_it:
+ /* now register the information with the local binder service */
+ if (protocol) {
+ return (pmap_set(prog, vers, protocol, xprt->xp_port));
+ }
+ return (TRUE);
+}
+
+/*
+ * Remove a service program from the callout list.
+ */
+void
+svc_unregister(prog, vers)
+ u_long prog;
+ u_long vers;
+{
+ struct svc_callout *prev;
+ register struct svc_callout *s;
+
+ if ((s = svc_find(prog, vers, &prev)) == NULL_SVC)
+ return;
+ if (prev == NULL_SVC) {
+ svc_head = s->sc_next;
+ } else {
+ prev->sc_next = s->sc_next;
+ }
+ s->sc_next = NULL_SVC;
+ mem_free((char *) s, (u_int) sizeof(struct svc_callout));
+ /* now unregister the information with the local binder service */
+ (void)pmap_unset(prog, vers);
+}
+
+/*
+ * Search the callout list for a program number, return the callout
+ * struct.
+ */
+static struct svc_callout *
+svc_find(prog, vers, prev)
+ u_long prog;
+ u_long vers;
+ struct svc_callout **prev;
+{
+ register struct svc_callout *s, *p;
+
+ p = NULL_SVC;
+ for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
+ if ((s->sc_prog == prog) && (s->sc_vers == vers))
+ goto done;
+ p = s;
+ }
+done:
+ *prev = p;
+ return (s);
+}
+
+/* ******************* REPLY GENERATION ROUTINES ************ */
+
+/*
+ * Send a reply to an rpc request
+ */
+bool_t
+svc_sendreply(xprt, xdr_results, xdr_location)
+ register SVCXPRT *xprt;
+ xdrproc_t xdr_results;
+ caddr_t xdr_location;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = SUCCESS;
+ rply.acpted_rply.ar_results.where = xdr_location;
+ rply.acpted_rply.ar_results.proc = xdr_results;
+ return (SVC_REPLY(xprt, &rply));
+}
+
+/*
+ * No procedure error reply
+ */
+void
+svcerr_noproc(xprt)
+ register SVCXPRT *xprt;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = PROC_UNAVAIL;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Can't decode args error reply
+ */
+void
+svcerr_decode(xprt)
+ register SVCXPRT *xprt;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = GARBAGE_ARGS;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Some system error
+ */
+void
+svcerr_systemerr(xprt)
+ register SVCXPRT *xprt;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = SYSTEM_ERR;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Authentication error reply
+ */
+void
+svcerr_auth(xprt, why)
+ SVCXPRT *xprt;
+ enum auth_stat why;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_DENIED;
+ rply.rjcted_rply.rj_stat = AUTH_ERROR;
+ rply.rjcted_rply.rj_why = why;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Auth too weak error reply
+ */
+void
+svcerr_weakauth(xprt)
+ SVCXPRT *xprt;
+{
+
+ svcerr_auth(xprt, AUTH_TOOWEAK);
+}
+
+/*
+ * Program unavailable error reply
+ */
+void
+svcerr_noprog(xprt)
+ register SVCXPRT *xprt;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = PROG_UNAVAIL;
+ SVC_REPLY(xprt, &rply);
+}
+
+/*
+ * Program version mismatch error reply
+ */
+void
+svcerr_progvers(xprt, low_vers, high_vers)
+ register SVCXPRT *xprt;
+ u_long low_vers;
+ u_long high_vers;
+{
+ struct rpc_msg rply;
+
+ rply.rm_direction = REPLY;
+ rply.rm_reply.rp_stat = MSG_ACCEPTED;
+ rply.acpted_rply.ar_verf = xprt->xp_verf;
+ rply.acpted_rply.ar_stat = PROG_MISMATCH;
+ rply.acpted_rply.ar_vers.low = low_vers;
+ rply.acpted_rply.ar_vers.high = high_vers;
+ SVC_REPLY(xprt, &rply);
+}
+
+/* ******************* SERVER INPUT STUFF ******************* */
+
+/*
+ * Get server side input from some transport.
+ *
+ * Statement of authentication parameters management:
+ * This function owns and manages all authentication parameters, specifically
+ * the "raw" parameters (msg.rm_call.cb_cred and msg.rm_call.cb_verf) and
+ * the "cooked" credentials (rqst->rq_clntcred).
+ * However, this function does not know the structure of the cooked
+ * credentials, so it make the following assumptions:
+ * a) the structure is contiguous (no pointers), and
+ * b) the cred structure size does not exceed RQCRED_SIZE bytes.
+ * In all events, all three parameters are freed upon exit from this routine.
+ * The storage is trivially management on the call stack in user land, but
+ * is mallocated in kernel land.
+ */
+
+void
+svc_getreq(rdfds)
+ int rdfds;
+{
+ fd_set readfds;
+
+ FD_ZERO(&readfds);
+ readfds.fds_bits[0] = rdfds;
+ svc_getreqset(&readfds);
+}
+
+void
+svc_getreqset(readfds)
+ fd_set *readfds;
+{
+ svc_getreqset2(readfds, FD_SETSIZE);
+}
+
+void
+svc_getreqset2(readfds, width)
+ fd_set *readfds;
+ int width;
+{
+ enum xprt_stat stat;
+ struct rpc_msg msg;
+ int prog_found;
+ u_long low_vers;
+ u_long high_vers;
+ struct svc_req r;
+ register SVCXPRT *xprt;
+ register int bit;
+ register int sock;
+ register fd_mask mask, *maskp;
+ char cred_area[2*MAX_AUTH_BYTES + RQCRED_SIZE];
+ msg.rm_call.cb_cred.oa_base = cred_area;
+ msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]);
+ r.rq_clntcred = &(cred_area[2*MAX_AUTH_BYTES]);
+
+
+ maskp = readfds->fds_bits;
+ for (sock = 0; sock < width; sock += NFDBITS) {
+ for (mask = *maskp++; (bit = ffs(mask)); mask ^= (1 << (bit - 1))) {
+ /* sock has input waiting */
+ xprt = xports[sock + bit - 1];
+ if (xprt == NULL)
+ /* But do we control sock? */
+ continue;
+ /* now receive msgs from xprtprt (support batch calls) */
+ do {
+ if (SVC_RECV(xprt, &msg)) {
+
+ /* now find the exported program and call it */
+ register struct svc_callout *s;
+ enum auth_stat why;
+
+ r.rq_xprt = xprt;
+ r.rq_prog = msg.rm_call.cb_prog;
+ r.rq_vers = msg.rm_call.cb_vers;
+ r.rq_proc = msg.rm_call.cb_proc;
+ r.rq_cred = msg.rm_call.cb_cred;
+ /* first authenticate the message */
+ if ((why= _authenticate(&r, &msg)) != AUTH_OK) {
+ svcerr_auth(xprt, why);
+ goto call_done;
+ }
+ /* now match message with a registered service*/
+ prog_found = FALSE;
+ low_vers = (u_long) - 1;
+ high_vers = 0;
+ for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
+ if (s->sc_prog == r.rq_prog) {
+ if (s->sc_vers == r.rq_vers) {
+ (*s->sc_dispatch)(&r, xprt);
+ goto call_done;
+ } /* found correct version */
+ prog_found = TRUE;
+ if (s->sc_vers < low_vers)
+ low_vers = s->sc_vers;
+ if (s->sc_vers > high_vers)
+ high_vers = s->sc_vers;
+ } /* found correct program */
+ }
+ /*
+ * if we got here, the program or version
+ * is not served ...
+ */
+ if (prog_found)
+ svcerr_progvers(xprt,
+ low_vers, high_vers);
+ else
+ svcerr_noprog(xprt);
+ /* Fall through to ... */
+ }
+ call_done:
+ if ((stat = SVC_STAT(xprt)) == XPRT_DIED){
+ SVC_DESTROY(xprt);
+ break;
+ }
+ } while (stat == XPRT_MOREREQS);
+ }
+ }
+}
diff --git a/lib/libc/rpc/svc_auth.c b/lib/libc/rpc/svc_auth.c
new file mode 100644
index 0000000..0063e75
--- /dev/null
+++ b/lib/libc/rpc/svc_auth.c
@@ -0,0 +1,211 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+/*
+ * Copyright (c) 1986-1991 by Sun Microsystems Inc.
+ */
+
+#ident "@(#)svc_auth.c 1.16 94/04/24 SMI"
+
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)svc_auth.c 1.26 89/02/07 Copyr 1984 Sun Micro";
+#endif
+
+/*
+ * svc_auth.c, Server-side rpc authenticator interface.
+ *
+ */
+
+#ifdef KERNEL
+#include <sys/param.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/clnt.h>
+#include <rpc/rpc_msg.h>
+#include <rpc/svc.h>
+#include <rpc/svc_auth.h>
+#else
+#include <stdlib.h>
+#include <rpc/rpc.h>
+#endif
+#include <sys/types.h>
+
+/*
+ * svcauthsw is the bdevsw of server side authentication.
+ *
+ * Server side authenticators are called from authenticate by
+ * using the client auth struct flavor field to index into svcauthsw.
+ * The server auth flavors must implement a routine that looks
+ * like:
+ *
+ * enum auth_stat
+ * flavorx_auth(rqst, msg)
+ * register struct svc_req *rqst;
+ * register struct rpc_msg *msg;
+ *
+ */
+
+enum auth_stat _svcauth_null(); /* no authentication */
+enum auth_stat _svcauth_unix(); /* (system) unix style (uid, gids) */
+enum auth_stat _svcauth_short(); /* short hand unix style */
+enum auth_stat _svcauth_des(); /* des style */
+
+/* declarations to allow servers to specify new authentication flavors */
+struct authsvc {
+ int flavor;
+ enum auth_stat (*handler)();
+ struct authsvc *next;
+};
+static struct authsvc *Auths = NULL;
+
+/*
+ * The call rpc message, msg has been obtained from the wire. The msg contains
+ * the raw form of credentials and verifiers. authenticate returns AUTH_OK
+ * if the msg is successfully authenticated. If AUTH_OK then the routine also
+ * does the following things:
+ * set rqst->rq_xprt->verf to the appropriate response verifier;
+ * sets rqst->rq_client_cred to the "cooked" form of the credentials.
+ *
+ * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
+ * its length is set appropriately.
+ *
+ * The caller still owns and is responsible for msg->u.cmb.cred and
+ * msg->u.cmb.verf. The authentication system retains ownership of
+ * rqst->rq_client_cred, the cooked credentials.
+ *
+ * There is an assumption that any flavour less than AUTH_NULL is
+ * invalid.
+ */
+enum auth_stat
+_authenticate(rqst, msg)
+ register struct svc_req *rqst;
+ struct rpc_msg *msg;
+{
+ register int cred_flavor;
+ register struct authsvc *asp;
+
+ rqst->rq_cred = msg->rm_call.cb_cred;
+ rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
+ rqst->rq_xprt->xp_verf.oa_length = 0;
+ cred_flavor = rqst->rq_cred.oa_flavor;
+ switch (cred_flavor) {
+ case AUTH_NULL:
+ return(_svcauth_null(rqst, msg));
+ case AUTH_UNIX:
+ return(_svcauth_unix(rqst, msg));
+ case AUTH_SHORT:
+ return(_svcauth_short(rqst, msg));
+ /*
+ * We leave AUTH_DES turned off by default because svcauth_des()
+ * needs getpublickey(), which is in librpcsvc, not libc. If we
+ * included AUTH_DES as a built-in flavor, programs that don't
+ * have -lrpcsvc in their Makefiles wouldn't link correctly, even
+ * though they don't use AUTH_DES. And I'm too lazy to go through
+ * the tree looking for all of them.
+ */
+#ifdef DES_BUILTIN
+ case AUTH_DES:
+ return(_svcauth_des(rqst, msg));
+#endif
+ }
+
+ /* flavor doesn't match any of the builtin types, so try new ones */
+ for (asp = Auths; asp; asp = asp->next) {
+ if (asp->flavor == cred_flavor) {
+ enum auth_stat as;
+
+ as = (*asp->handler)(rqst, msg);
+ return (as);
+ }
+ }
+
+ return (AUTH_REJECTEDCRED);
+}
+
+/*ARGSUSED*/
+enum auth_stat
+_svcauth_null(rqst, msg)
+ struct svc_req *rqst;
+ struct rpc_msg *msg;
+{
+ return (AUTH_OK);
+}
+
+/*
+ * Allow the rpc service to register new authentication types that it is
+ * prepared to handle. When an authentication flavor is registered,
+ * the flavor is checked against already registered values. If not
+ * registered, then a new Auths entry is added on the list.
+ *
+ * There is no provision to delete a registration once registered.
+ *
+ * This routine returns:
+ * 0 if registration successful
+ * 1 if flavor already registered
+ * -1 if can't register (errno set)
+ */
+
+int
+svc_auth_reg(cred_flavor, handler)
+ register int cred_flavor;
+ enum auth_stat (*handler)();
+{
+ register struct authsvc *asp;
+
+ switch (cred_flavor) {
+ case AUTH_NULL:
+ case AUTH_UNIX:
+ case AUTH_SHORT:
+#ifdef DES_BUILTIN
+ case AUTH_DES:
+#endif
+ /* already registered */
+ return (1);
+
+ default:
+ for (asp = Auths; asp; asp = asp->next) {
+ if (asp->flavor == cred_flavor) {
+ /* already registered */
+ return (1);
+ }
+ }
+
+ /* this is a new one, so go ahead and register it */
+ asp = (struct authsvc *)mem_alloc(sizeof (*asp));
+ if (asp == NULL) {
+ return (-1);
+ }
+ asp->flavor = cred_flavor;
+ asp->handler = handler;
+ asp->next = Auths;
+ Auths = asp;
+ break;
+ }
+ return (0);
+}
diff --git a/lib/libc/rpc/svc_auth_des.c b/lib/libc/rpc/svc_auth_des.c
new file mode 100644
index 0000000..889182e
--- /dev/null
+++ b/lib/libc/rpc/svc_auth_des.c
@@ -0,0 +1,531 @@
+
+/*
+ * Copyright (c) 1988 by Sun Microsystems, Inc.
+ */
+
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+/*
+ * svcauth_des.c, server-side des authentication
+ *
+ * We insure for the service the following:
+ * (1) The timestamp microseconds do not exceed 1 million.
+ * (2) The timestamp plus the window is less than the current time.
+ * (3) The timestamp is not less than the one previously
+ * seen in the current session.
+ *
+ * It is up to the server to determine if the window size is
+ * too small .
+ *
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <rpc/des_crypt.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+#include <rpc/auth_des.h>
+#include <rpc/svc.h>
+#include <rpc/rpc_msg.h>
+#include <rpc/svc_auth.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/* from: static char sccsid[] = "@(#)svcauth_des.c 2.3 89/07/11 4.0 RPCSRC; from 1.15 88/02/08 SMI"; */
+static const char rcsid[] = "$Id$";
+#endif
+
+#define debug(msg) printf("svcauth_des: %s\n", msg)
+
+#define USEC_PER_SEC ((u_long) 1000000L)
+#define BEFORE(t1, t2) timercmp(t1, t2, <)
+
+/*
+ * LRU cache of conversation keys and some other useful items.
+ */
+#define AUTHDES_CACHESZ 64
+struct cache_entry {
+ des_block key; /* conversation key */
+ char *rname; /* client's name */
+ u_int window; /* credential lifetime window */
+ struct timeval laststamp; /* detect replays of creds */
+ char *localcred; /* generic local credential */
+};
+static struct cache_entry *authdes_cache/* [AUTHDES_CACHESZ] */;
+static short *authdes_lru/* [AUTHDES_CACHESZ] */;
+
+static void cache_init(); /* initialize the cache */
+static short cache_spot(); /* find an entry in the cache */
+static void cache_ref(/*short sid*/); /* note that sid was ref'd */
+
+static void invalidate(); /* invalidate entry in cache */
+
+/*
+ * cache statistics
+ */
+static struct {
+ u_long ncachehits; /* times cache hit, and is not replay */
+ u_long ncachereplays; /* times cache hit, and is replay */
+ u_long ncachemisses; /* times cache missed */
+} svcauthdes_stats;
+
+/*
+ * Service side authenticator for AUTH_DES
+ */
+enum auth_stat
+_svcauth_des(rqst, msg)
+ register struct svc_req *rqst;
+ register struct rpc_msg *msg;
+{
+
+ register long *ixdr;
+ des_block cryptbuf[2];
+ register struct authdes_cred *cred;
+ struct authdes_verf verf;
+ int status;
+ register struct cache_entry *entry;
+ short sid = 0;
+ des_block *sessionkey;
+ des_block ivec;
+ u_int window;
+ struct timeval timestamp;
+ u_long namelen;
+ struct area {
+ struct authdes_cred area_cred;
+ char area_netname[MAXNETNAMELEN+1];
+ } *area;
+
+ if (authdes_cache == NULL) {
+ cache_init();
+ }
+
+ area = (struct area *)rqst->rq_clntcred;
+ cred = (struct authdes_cred *)&area->area_cred;
+
+ /*
+ * Get the credential
+ */
+ ixdr = (long *)msg->rm_call.cb_cred.oa_base;
+ cred->adc_namekind = IXDR_GET_ENUM(ixdr, enum authdes_namekind);
+ switch (cred->adc_namekind) {
+ case ADN_FULLNAME:
+ namelen = IXDR_GET_U_LONG(ixdr);
+ if (namelen > MAXNETNAMELEN) {
+ return (AUTH_BADCRED);
+ }
+ cred->adc_fullname.name = area->area_netname;
+ bcopy((char *)ixdr, cred->adc_fullname.name,
+ (u_int)namelen);
+ cred->adc_fullname.name[namelen] = 0;
+ ixdr += (RNDUP(namelen) / BYTES_PER_XDR_UNIT);
+ cred->adc_fullname.key.key.high = (u_long)*ixdr++;
+ cred->adc_fullname.key.key.low = (u_long)*ixdr++;
+ cred->adc_fullname.window = (u_long)*ixdr++;
+ break;
+ case ADN_NICKNAME:
+ cred->adc_nickname = (u_long)*ixdr++;
+ break;
+ default:
+ return (AUTH_BADCRED);
+ }
+
+ /*
+ * Get the verifier
+ */
+ ixdr = (long *)msg->rm_call.cb_verf.oa_base;
+ verf.adv_xtimestamp.key.high = (u_long)*ixdr++;
+ verf.adv_xtimestamp.key.low = (u_long)*ixdr++;
+ verf.adv_int_u = (u_long)*ixdr++;
+
+
+ /*
+ * Get the conversation key
+ */
+ if (cred->adc_namekind == ADN_FULLNAME) {
+ netobj pkey;
+ char pkey_data[1024];
+
+ sessionkey = &cred->adc_fullname.key;
+ if (! getpublickey(cred->adc_fullname.name, pkey_data)) {
+ debug("getpublickey");
+ return(AUTH_BADCRED);
+ }
+ pkey.n_bytes = pkey_data;
+ pkey.n_len = strlen(pkey_data) + 1;
+ if (key_decryptsession_pk(cred->adc_fullname.name, &pkey,
+ sessionkey) < 0) {
+ debug("decryptsessionkey");
+ return (AUTH_BADCRED); /* key not found */
+ }
+ } else { /* ADN_NICKNAME */
+ sid = (short)cred->adc_nickname;
+ if (sid >= AUTHDES_CACHESZ) {
+ debug("bad nickname");
+ return (AUTH_BADCRED); /* garbled credential */
+ }
+ sessionkey = &authdes_cache[sid].key;
+ }
+
+
+ /*
+ * Decrypt the timestamp
+ */
+ cryptbuf[0] = verf.adv_xtimestamp;
+ if (cred->adc_namekind == ADN_FULLNAME) {
+ cryptbuf[1].key.high = cred->adc_fullname.window;
+ cryptbuf[1].key.low = verf.adv_winverf;
+ ivec.key.high = ivec.key.low = 0;
+ status = cbc_crypt((char *)sessionkey, (char *)cryptbuf,
+ 2*sizeof(des_block), DES_DECRYPT | DES_HW,
+ (char *)&ivec);
+ } else {
+ status = ecb_crypt((char *)sessionkey, (char *)cryptbuf,
+ sizeof(des_block), DES_DECRYPT | DES_HW);
+ }
+ if (DES_FAILED(status)) {
+ debug("decryption failure");
+ return (AUTH_FAILED); /* system error */
+ }
+
+ /*
+ * XDR the decrypted timestamp
+ */
+ ixdr = (long *)cryptbuf;
+ timestamp.tv_sec = IXDR_GET_LONG(ixdr);
+ timestamp.tv_usec = IXDR_GET_LONG(ixdr);
+
+ /*
+ * Check for valid credentials and verifiers.
+ * They could be invalid because the key was flushed
+ * out of the cache, and so a new session should begin.
+ * Be sure and send AUTH_REJECTED{CRED, VERF} if this is the case.
+ */
+ {
+ struct timeval current;
+ int nick;
+ int winverf;
+
+ if (cred->adc_namekind == ADN_FULLNAME) {
+ window = IXDR_GET_U_LONG(ixdr);
+ winverf = IXDR_GET_U_LONG(ixdr);
+ if (winverf != window - 1) {
+ debug("window verifier mismatch");
+ return (AUTH_BADCRED); /* garbled credential */
+ }
+ sid = cache_spot(sessionkey, cred->adc_fullname.name,
+ &timestamp);
+ if (sid < 0) {
+ debug("replayed credential");
+ return (AUTH_REJECTEDCRED); /* replay */
+ }
+ nick = 0;
+ } else { /* ADN_NICKNAME */
+ window = authdes_cache[sid].window;
+ nick = 1;
+ }
+
+ if ((u_long)timestamp.tv_usec >= USEC_PER_SEC) {
+ debug("invalid usecs");
+ /* cached out (bad key), or garbled verifier */
+ return (nick ? AUTH_REJECTEDVERF : AUTH_BADVERF);
+ }
+ if (nick && BEFORE(&timestamp,
+ &authdes_cache[sid].laststamp)) {
+ debug("timestamp before last seen");
+ return (AUTH_REJECTEDVERF); /* replay */
+ }
+ (void) gettimeofday(&current, (struct timezone *)NULL);
+ current.tv_sec -= window; /* allow for expiration */
+ if (!BEFORE(&current, &timestamp)) {
+ debug("timestamp expired");
+ /* replay, or garbled credential */
+ return (nick ? AUTH_REJECTEDVERF : AUTH_BADCRED);
+ }
+ }
+
+ /*
+ * Set up the reply verifier
+ */
+ verf.adv_nickname = (u_long)sid;
+
+ /*
+ * xdr the timestamp before encrypting
+ */
+ ixdr = (long *)cryptbuf;
+ IXDR_PUT_LONG(ixdr, timestamp.tv_sec - 1);
+ IXDR_PUT_LONG(ixdr, timestamp.tv_usec);
+
+ /*
+ * encrypt the timestamp
+ */
+ status = ecb_crypt((char *)sessionkey, (char *)cryptbuf,
+ sizeof(des_block), DES_ENCRYPT | DES_HW);
+ if (DES_FAILED(status)) {
+ debug("encryption failure");
+ return (AUTH_FAILED); /* system error */
+ }
+ verf.adv_xtimestamp = cryptbuf[0];
+
+ /*
+ * Serialize the reply verifier, and update rqst
+ */
+ ixdr = (long *)msg->rm_call.cb_verf.oa_base;
+ *ixdr++ = (long)verf.adv_xtimestamp.key.high;
+ *ixdr++ = (long)verf.adv_xtimestamp.key.low;
+ *ixdr++ = (long)verf.adv_int_u;
+
+ rqst->rq_xprt->xp_verf.oa_flavor = AUTH_DES;
+ rqst->rq_xprt->xp_verf.oa_base = msg->rm_call.cb_verf.oa_base;
+ rqst->rq_xprt->xp_verf.oa_length =
+ (char *)ixdr - msg->rm_call.cb_verf.oa_base;
+
+ /*
+ * We succeeded, commit the data to the cache now and
+ * finish cooking the credential.
+ */
+ entry = &authdes_cache[sid];
+ entry->laststamp = timestamp;
+ cache_ref(sid);
+ if (cred->adc_namekind == ADN_FULLNAME) {
+ cred->adc_fullname.window = window;
+ cred->adc_nickname = (u_long)sid; /* save nickname */
+ if (entry->rname != NULL) {
+ mem_free(entry->rname, strlen(entry->rname) + 1);
+ }
+ entry->rname = (char *)mem_alloc((u_int)strlen(cred->adc_fullname.name)
+ + 1);
+ if (entry->rname != NULL) {
+ (void) strcpy(entry->rname, cred->adc_fullname.name);
+ } else {
+ debug("out of memory");
+ }
+ entry->key = *sessionkey;
+ entry->window = window;
+ invalidate(entry->localcred); /* mark any cached cred invalid */
+ } else { /* ADN_NICKNAME */
+ /*
+ * nicknames are cooked into fullnames
+ */
+ cred->adc_namekind = ADN_FULLNAME;
+ cred->adc_fullname.name = entry->rname;
+ cred->adc_fullname.key = entry->key;
+ cred->adc_fullname.window = entry->window;
+ }
+ return (AUTH_OK); /* we made it!*/
+}
+
+
+/*
+ * Initialize the cache
+ */
+static void
+cache_init()
+{
+ register int i;
+
+ authdes_cache = (struct cache_entry *)
+ mem_alloc(sizeof(struct cache_entry) * AUTHDES_CACHESZ);
+ bzero((char *)authdes_cache,
+ sizeof(struct cache_entry) * AUTHDES_CACHESZ);
+
+ authdes_lru = (short *)mem_alloc(sizeof(short) * AUTHDES_CACHESZ);
+ /*
+ * Initialize the lru list
+ */
+ for (i = 0; i < AUTHDES_CACHESZ; i++) {
+ authdes_lru[i] = i;
+ }
+}
+
+
+/*
+ * Find the lru victim
+ */
+static short
+cache_victim()
+{
+ return (authdes_lru[AUTHDES_CACHESZ-1]);
+}
+
+/*
+ * Note that sid was referenced
+ */
+static void
+cache_ref(sid)
+ register short sid;
+{
+ register int i;
+ register short curr;
+ register short prev;
+
+ prev = authdes_lru[0];
+ authdes_lru[0] = sid;
+ for (i = 1; prev != sid; i++) {
+ curr = authdes_lru[i];
+ authdes_lru[i] = prev;
+ prev = curr;
+ }
+}
+
+
+/*
+ * Find a spot in the cache for a credential containing
+ * the items given. Return -1 if a replay is detected, otherwise
+ * return the spot in the cache.
+ */
+static short
+cache_spot(key, name, timestamp)
+ register des_block *key;
+ char *name;
+ struct timeval *timestamp;
+{
+ register struct cache_entry *cp;
+ register int i;
+ register u_long hi;
+
+ hi = key->key.high;
+ for (cp = authdes_cache, i = 0; i < AUTHDES_CACHESZ; i++, cp++) {
+ if (cp->key.key.high == hi &&
+ cp->key.key.low == key->key.low &&
+ cp->rname != NULL &&
+ bcmp(cp->rname, name, strlen(name) + 1) == 0) {
+ if (BEFORE(timestamp, &cp->laststamp)) {
+ svcauthdes_stats.ncachereplays++;
+ return (-1); /* replay */
+ }
+ svcauthdes_stats.ncachehits++;
+ return (i); /* refresh */
+ }
+ }
+ svcauthdes_stats.ncachemisses++;
+ return (cache_victim()); /* new credential */
+}
+
+
+#if (defined(sun) || defined(vax) || defined(__FreeBSD__))
+/*
+ * Local credential handling stuff.
+ * NOTE: bsd unix dependent.
+ * Other operating systems should put something else here.
+ */
+#define UNKNOWN -2 /* grouplen, if cached cred is unknown user */
+#define INVALID -1 /* grouplen, if cache entry is invalid */
+
+struct bsdcred {
+ short uid; /* cached uid */
+ short gid; /* cached gid */
+ short grouplen; /* length of cached groups */
+ short groups[NGROUPS]; /* cached groups */
+};
+
+/*
+ * Map a des credential into a unix cred.
+ * We cache the credential here so the application does
+ * not have to make an rpc call every time to interpret
+ * the credential.
+ */
+int
+authdes_getucred(adc, uid, gid, grouplen, groups)
+ struct authdes_cred *adc;
+ uid_t *uid;
+ gid_t *gid;
+ int *grouplen;
+ register gid_t *groups;
+{
+ unsigned sid;
+ register int i;
+ uid_t i_uid;
+ gid_t i_gid;
+ int i_grouplen;
+ struct bsdcred *cred;
+
+ sid = adc->adc_nickname;
+ if (sid >= AUTHDES_CACHESZ) {
+ debug("invalid nickname");
+ return (0);
+ }
+ cred = (struct bsdcred *)authdes_cache[sid].localcred;
+ if (cred == NULL) {
+ cred = (struct bsdcred *)mem_alloc(sizeof(struct bsdcred));
+ authdes_cache[sid].localcred = (char *)cred;
+ cred->grouplen = INVALID;
+ }
+ if (cred->grouplen == INVALID) {
+ /*
+ * not in cache: lookup
+ */
+ if (!netname2user(adc->adc_fullname.name, &i_uid, &i_gid,
+ &i_grouplen, groups))
+ {
+ debug("unknown netname");
+ cred->grouplen = UNKNOWN; /* mark as lookup up, but not found */
+ return (0);
+ }
+ debug("missed ucred cache");
+ *uid = cred->uid = i_uid;
+ *gid = cred->gid = i_gid;
+ *grouplen = cred->grouplen = i_grouplen;
+ for (i = i_grouplen - 1; i >= 0; i--) {
+ cred->groups[i] = groups[i]; /* int to short */
+ }
+ return (1);
+ } else if (cred->grouplen == UNKNOWN) {
+ /*
+ * Already lookup up, but no match found
+ */
+ return (0);
+ }
+
+ /*
+ * cached credentials
+ */
+ *uid = cred->uid;
+ *gid = cred->gid;
+ *grouplen = cred->grouplen;
+ for (i = cred->grouplen - 1; i >= 0; i--) {
+ groups[i] = cred->groups[i]; /* short to int */
+ }
+ return (1);
+}
+
+static void
+invalidate(cred)
+ char *cred;
+{
+ if (cred == NULL) {
+ return;
+ }
+ ((struct bsdcred *)cred)->grouplen = INVALID;
+}
+#endif
+
diff --git a/lib/libc/rpc/svc_auth_unix.c b/lib/libc/rpc/svc_auth_unix.c
new file mode 100644
index 0000000..959cb73
--- /dev/null
+++ b/lib/libc/rpc/svc_auth_unix.c
@@ -0,0 +1,148 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: svc_auth_unix.c,v 1.4 1996/12/30 15:10:14 peter Exp $";
+#endif
+
+/*
+ * svc_auth_unix.c
+ * Handles UNIX flavor authentication parameters on the service side of rpc.
+ * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
+ * _svcauth_unix does full blown unix style uid,gid+gids auth,
+ * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
+ * Note: the shorthand has been gutted for efficiency.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <rpc/rpc.h>
+
+/*
+ * Unix longhand authenticator
+ */
+enum auth_stat
+_svcauth_unix(rqst, msg)
+ register struct svc_req *rqst;
+ register struct rpc_msg *msg;
+{
+ register enum auth_stat stat;
+ XDR xdrs;
+ register struct authunix_parms *aup;
+ register int32_t *buf;
+ struct area {
+ struct authunix_parms area_aup;
+ char area_machname[MAX_MACHINE_NAME+1];
+ int area_gids[NGRPS];
+ } *area;
+ u_int auth_len;
+ int str_len, gid_len;
+ register int i;
+
+ area = (struct area *) rqst->rq_clntcred;
+ aup = &area->area_aup;
+ aup->aup_machname = area->area_machname;
+ aup->aup_gids = area->area_gids;
+ auth_len = (u_int)msg->rm_call.cb_cred.oa_length;
+ xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);
+ buf = XDR_INLINE(&xdrs, auth_len);
+ if (buf != NULL) {
+ aup->aup_time = IXDR_GET_LONG(buf);
+ str_len = IXDR_GET_U_LONG(buf);
+ if (str_len > MAX_MACHINE_NAME) {
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+ memcpy(aup->aup_machname, (caddr_t)buf, (u_int)str_len);
+ aup->aup_machname[str_len] = 0;
+ str_len = RNDUP(str_len);
+ buf += str_len / sizeof (int32_t);
+ aup->aup_uid = IXDR_GET_LONG(buf);
+ aup->aup_gid = IXDR_GET_LONG(buf);
+ gid_len = IXDR_GET_U_LONG(buf);
+ if (gid_len > NGRPS) {
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+ aup->aup_len = gid_len;
+ for (i = 0; i < gid_len; i++) {
+ aup->aup_gids[i] = IXDR_GET_LONG(buf);
+ }
+ /*
+ * five is the smallest unix credentials structure -
+ * timestamp, hostname len (0), uid, gid, and gids len (0).
+ */
+ if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
+ (void) printf("bad auth_len gid %d str %d auth %d\n",
+ gid_len, str_len, auth_len);
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+ } else if (! xdr_authunix_parms(&xdrs, aup)) {
+ xdrs.x_op = XDR_FREE;
+ (void)xdr_authunix_parms(&xdrs, aup);
+ stat = AUTH_BADCRED;
+ goto done;
+ }
+
+ /* get the verifier */
+ if ((u_int)msg->rm_call.cb_verf.oa_length) {
+ rqst->rq_xprt->xp_verf.oa_flavor =
+ msg->rm_call.cb_verf.oa_flavor;
+ rqst->rq_xprt->xp_verf.oa_base =
+ msg->rm_call.cb_verf.oa_base;
+ rqst->rq_xprt->xp_verf.oa_length =
+ msg->rm_call.cb_verf.oa_length;
+ } else {
+ rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
+ rqst->rq_xprt->xp_verf.oa_length = 0;
+ }
+ stat = AUTH_OK;
+done:
+ XDR_DESTROY(&xdrs);
+ return (stat);
+}
+
+
+/*
+ * Shorthand unix authenticator
+ * Looks up longhand in a cache.
+ */
+/*ARGSUSED*/
+enum auth_stat
+_svcauth_short(rqst, msg)
+ struct svc_req *rqst;
+ struct rpc_msg *msg;
+{
+ return (AUTH_REJECTEDCRED);
+}
diff --git a/lib/libc/rpc/svc_raw.c b/lib/libc/rpc/svc_raw.c
new file mode 100644
index 0000000..3a5bcb3
--- /dev/null
+++ b/lib/libc/rpc/svc_raw.c
@@ -0,0 +1,168 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_raw.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: svc_raw.c,v 1.3 1995/10/22 14:51:36 phk Exp $";
+#endif
+
+/*
+ * svc_raw.c, This a toy for simple testing and timing.
+ * Interface to create an rpc client and server in the same UNIX process.
+ * This lets us similate rpc and get rpc (round trip) overhead, without
+ * any interference from the kernal.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <rpc/rpc.h>
+#include <stdlib.h>
+
+/*
+ * This is the "network" that we will be moving data over
+ */
+static struct svcraw_private {
+ char _raw_buf[UDPMSGSIZE];
+ SVCXPRT server;
+ XDR xdr_stream;
+ char verf_body[MAX_AUTH_BYTES];
+} *svcraw_private;
+
+static bool_t svcraw_recv();
+static enum xprt_stat svcraw_stat();
+static bool_t svcraw_getargs();
+static bool_t svcraw_reply();
+static bool_t svcraw_freeargs();
+static void svcraw_destroy();
+
+static struct xp_ops server_ops = {
+ svcraw_recv,
+ svcraw_stat,
+ svcraw_getargs,
+ svcraw_reply,
+ svcraw_freeargs,
+ svcraw_destroy
+};
+
+SVCXPRT *
+svcraw_create()
+{
+ register struct svcraw_private *srp = svcraw_private;
+
+ if (srp == 0) {
+ srp = (struct svcraw_private *)calloc(1, sizeof (*srp));
+ if (srp == 0)
+ return (0);
+ }
+ srp->server.xp_sock = 0;
+ srp->server.xp_port = 0;
+ srp->server.xp_ops = &server_ops;
+ srp->server.xp_verf.oa_base = srp->verf_body;
+ xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
+ return (&srp->server);
+}
+
+static enum xprt_stat
+svcraw_stat()
+{
+
+ return (XPRT_IDLE);
+}
+
+static bool_t
+svcraw_recv(xprt, msg)
+ SVCXPRT *xprt;
+ struct rpc_msg *msg;
+{
+ register struct svcraw_private *srp = svcraw_private;
+ register XDR *xdrs;
+
+ if (srp == 0)
+ return (0);
+ xdrs = &srp->xdr_stream;
+ xdrs->x_op = XDR_DECODE;
+ XDR_SETPOS(xdrs, 0);
+ if (! xdr_callmsg(xdrs, msg))
+ return (FALSE);
+ return (TRUE);
+}
+
+static bool_t
+svcraw_reply(xprt, msg)
+ SVCXPRT *xprt;
+ struct rpc_msg *msg;
+{
+ register struct svcraw_private *srp = svcraw_private;
+ register XDR *xdrs;
+
+ if (srp == 0)
+ return (FALSE);
+ xdrs = &srp->xdr_stream;
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, 0);
+ if (! xdr_replymsg(xdrs, msg))
+ return (FALSE);
+ (void)XDR_GETPOS(xdrs); /* called just for overhead */
+ return (TRUE);
+}
+
+static bool_t
+svcraw_getargs(xprt, xdr_args, args_ptr)
+ SVCXPRT *xprt;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
+{
+ register struct svcraw_private *srp = svcraw_private;
+
+ if (srp == 0)
+ return (FALSE);
+ return ((*xdr_args)(&srp->xdr_stream, args_ptr));
+}
+
+static bool_t
+svcraw_freeargs(xprt, xdr_args, args_ptr)
+ SVCXPRT *xprt;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
+{
+ register struct svcraw_private *srp = svcraw_private;
+ register XDR *xdrs;
+
+ if (srp == 0)
+ return (FALSE);
+ xdrs = &srp->xdr_stream;
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_args)(xdrs, args_ptr));
+}
+
+static void
+svcraw_destroy()
+{
+}
diff --git a/lib/libc/rpc/svc_run.c b/lib/libc/rpc/svc_run.c
new file mode 100644
index 0000000..0692c25
--- /dev/null
+++ b/lib/libc/rpc/svc_run.c
@@ -0,0 +1,87 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_run.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: svc_run.c,v 1.7 1997/02/22 15:01:32 peter Exp $";
+#endif
+
+/*
+ * This is the rpc server side idle loop
+ * Wait for input, call server program.
+ */
+#include <rpc/rpc.h>
+#include <stdio.h>
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+extern int __svc_fdsetsize;
+extern fd_set *__svc_fdset;
+
+void
+svc_run()
+{
+ fd_set *fds;
+
+ for (;;) {
+ if (__svc_fdset) {
+ int bytes = howmany(__svc_fdsetsize, NFDBITS) *
+ sizeof(fd_mask);
+ fds = (fd_set *)malloc(bytes);
+ memcpy(fds, __svc_fdset, bytes);
+ } else
+ fds = NULL;
+ switch (select(svc_maxfd + 1, fds, NULL, NULL,
+ (struct timeval *)0)) {
+ case -1:
+ if (errno == EINTR) {
+ if (fds)
+ free(fds);
+ continue;
+ }
+ perror("svc_run: - select failed");
+ if (fds)
+ free(fds);
+ return;
+ case 0:
+ if (fds)
+ free(fds);
+ continue;
+ default:
+ /* if fds == NULL, select() can't return a result */
+ svc_getreqset2(fds, svc_maxfd + 1);
+ free(fds);
+ }
+ }
+}
diff --git a/lib/libc/rpc/svc_simple.c b/lib/libc/rpc/svc_simple.c
new file mode 100644
index 0000000..0324675
--- /dev/null
+++ b/lib/libc/rpc/svc_simple.c
@@ -0,0 +1,150 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_simple.c 1.18 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_simple.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: svc_simple.c,v 1.5 1996/12/30 15:16:22 peter Exp $";
+#endif
+
+/*
+ * svc_simple.c
+ * Simplified front end to rpc.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+static struct proglst {
+ char *(*p_progname)();
+ int p_prognum;
+ int p_procnum;
+ xdrproc_t p_inproc, p_outproc;
+ struct proglst *p_nxt;
+} *proglst;
+static void universal();
+static SVCXPRT *transp;
+struct proglst *pl;
+
+int
+registerrpc(prognum, versnum, procnum, progname, inproc, outproc)
+ int prognum, versnum, procnum;
+ char *(*progname)();
+ xdrproc_t inproc, outproc;
+{
+
+ if (procnum == NULLPROC) {
+ (void) fprintf(stderr,
+ "can't reassign procedure number %ld\n", NULLPROC);
+ return (-1);
+ }
+ if (transp == 0) {
+ transp = svcudp_create(RPC_ANYSOCK);
+ if (transp == NULL) {
+ (void) fprintf(stderr, "couldn't create an rpc server\n");
+ return (-1);
+ }
+ }
+ (void) pmap_unset((u_long)prognum, (u_long)versnum);
+ if (!svc_register(transp, (u_long)prognum, (u_long)versnum,
+ universal, IPPROTO_UDP)) {
+ (void) fprintf(stderr, "couldn't register prog %d vers %d\n",
+ prognum, versnum);
+ return (-1);
+ }
+ pl = (struct proglst *)malloc(sizeof(struct proglst));
+ if (pl == NULL) {
+ (void) fprintf(stderr, "registerrpc: out of memory\n");
+ return (-1);
+ }
+ pl->p_progname = progname;
+ pl->p_prognum = prognum;
+ pl->p_procnum = procnum;
+ pl->p_inproc = inproc;
+ pl->p_outproc = outproc;
+ pl->p_nxt = proglst;
+ proglst = pl;
+ return (0);
+}
+
+static void
+universal(rqstp, transp)
+ struct svc_req *rqstp;
+ SVCXPRT *transp;
+{
+ int prog, proc;
+ char *outdata;
+ char xdrbuf[UDPMSGSIZE];
+ struct proglst *pl;
+
+ /*
+ * enforce "procnum 0 is echo" convention
+ */
+ if (rqstp->rq_proc == NULLPROC) {
+ if (svc_sendreply(transp, xdr_void, NULL) == FALSE) {
+ (void) fprintf(stderr, "xxx\n");
+ exit(1);
+ }
+ return;
+ }
+ prog = rqstp->rq_prog;
+ proc = rqstp->rq_proc;
+ for (pl = proglst; pl != NULL; pl = pl->p_nxt)
+ if (pl->p_prognum == prog && pl->p_procnum == proc) {
+ /* decode arguments into a CLEAN buffer */
+ memset(xdrbuf, 0, sizeof(xdrbuf)); /* required ! */
+ if (!svc_getargs(transp, pl->p_inproc, xdrbuf)) {
+ svcerr_decode(transp);
+ return;
+ }
+ outdata = (*(pl->p_progname))(xdrbuf);
+ if (outdata == NULL && pl->p_outproc != xdr_void)
+ /* there was an error */
+ return;
+ if (!svc_sendreply(transp, pl->p_outproc, outdata)) {
+ (void) fprintf(stderr,
+ "trouble replying to prog %d\n",
+ pl->p_prognum);
+ exit(1);
+ }
+ /* free the decoded arguments */
+ (void)svc_freeargs(transp, pl->p_inproc, xdrbuf);
+ return;
+ }
+ (void) fprintf(stderr, "never registered prog %d\n", prog);
+ exit(1);
+}
+
diff --git a/lib/libc/rpc/svc_tcp.c b/lib/libc/rpc/svc_tcp.c
new file mode 100644
index 0000000..1387ee1
--- /dev/null
+++ b/lib/libc/rpc/svc_tcp.c
@@ -0,0 +1,448 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: svc_tcp.c,v 1.8 1996/12/30 15:19:08 peter Exp $";
+#endif
+
+/*
+ * svc_tcp.c, Server side for TCP/IP based RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * Actually implements two flavors of transporter -
+ * a tcp rendezvouser (a listner and connection establisher)
+ * and a record/tcp stream.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <errno.h>
+
+/*
+ * Ops vector for TCP/IP based rpc service handle
+ */
+static bool_t svctcp_recv();
+static enum xprt_stat svctcp_stat();
+static bool_t svctcp_getargs();
+static bool_t svctcp_reply();
+static bool_t svctcp_freeargs();
+static void svctcp_destroy();
+
+static struct xp_ops svctcp_op = {
+ svctcp_recv,
+ svctcp_stat,
+ svctcp_getargs,
+ svctcp_reply,
+ svctcp_freeargs,
+ svctcp_destroy
+};
+
+/*
+ * Ops vector for TCP/IP rendezvous handler
+ */
+static bool_t rendezvous_request();
+static enum xprt_stat rendezvous_stat();
+
+static struct xp_ops svctcp_rendezvous_op = {
+ rendezvous_request,
+ rendezvous_stat,
+ (bool_t (*)())abort,
+ (bool_t (*)())abort,
+ (bool_t (*)())abort,
+ svctcp_destroy
+};
+
+static int readtcp(), writetcp();
+static SVCXPRT *makefd_xprt();
+
+struct tcp_rendezvous { /* kept in xprt->xp_p1 */
+ u_int sendsize;
+ u_int recvsize;
+};
+
+struct tcp_conn { /* kept in xprt->xp_p1 */
+ enum xprt_stat strm_stat;
+ u_long x_id;
+ XDR xdrs;
+ char verf_body[MAX_AUTH_BYTES];
+};
+
+/*
+ * Usage:
+ * xprt = svctcp_create(sock, send_buf_size, recv_buf_size);
+ *
+ * Creates, registers, and returns a (rpc) tcp based transporter.
+ * Once *xprt is initialized, it is registered as a transporter
+ * see (svc.h, xprt_register). This routine returns
+ * a NULL if a problem occurred.
+ *
+ * If sock<0 then a socket is created, else sock is used.
+ * If the socket, sock is not bound to a port then svctcp_create
+ * binds it to an arbitrary port. The routine then starts a tcp
+ * listener on the socket's associated port. In any (successful) case,
+ * xprt->xp_sock is the registered socket number and xprt->xp_port is the
+ * associated port number.
+ *
+ * Since tcp streams do buffered io similar to stdio, the caller can specify
+ * how big the send and receive buffers are via the second and third parms;
+ * 0 => use the system default.
+ */
+SVCXPRT *
+svctcp_create(sock, sendsize, recvsize)
+ register int sock;
+ u_int sendsize;
+ u_int recvsize;
+{
+ bool_t madesock = FALSE;
+ register SVCXPRT *xprt;
+ register struct tcp_rendezvous *r;
+ struct sockaddr_in addr;
+ int len = sizeof(struct sockaddr_in);
+
+ if (sock == RPC_ANYSOCK) {
+ if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ perror("svctcp_.c - udp socket creation problem");
+ return ((SVCXPRT *)NULL);
+ }
+ madesock = TRUE;
+ }
+ memset(&addr, 0, sizeof (addr));
+ addr.sin_len = sizeof(struct sockaddr_in);
+ addr.sin_family = AF_INET;
+ if (bindresvport(sock, &addr)) {
+ addr.sin_port = 0;
+ (void)bind(sock, (struct sockaddr *)&addr, len);
+ }
+ if ((getsockname(sock, (struct sockaddr *)&addr, &len) != 0) ||
+ (listen(sock, 2) != 0)) {
+ perror("svctcp_.c - cannot getsockname or listen");
+ if (madesock)
+ (void)close(sock);
+ return ((SVCXPRT *)NULL);
+ }
+ r = (struct tcp_rendezvous *)mem_alloc(sizeof(*r));
+ if (r == NULL) {
+ (void) fprintf(stderr, "svctcp_create: out of memory\n");
+ return (NULL);
+ }
+ r->sendsize = sendsize;
+ r->recvsize = recvsize;
+ xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
+ if (xprt == NULL) {
+ (void) fprintf(stderr, "svctcp_create: out of memory\n");
+ return (NULL);
+ }
+ xprt->xp_p2 = NULL;
+ xprt->xp_p1 = (caddr_t)r;
+ xprt->xp_verf = _null_auth;
+ xprt->xp_ops = &svctcp_rendezvous_op;
+ xprt->xp_port = ntohs(addr.sin_port);
+ xprt->xp_sock = sock;
+ xprt_register(xprt);
+ return (xprt);
+}
+
+/*
+ * Like svtcp_create(), except the routine takes any *open* UNIX file
+ * descriptor as its first input.
+ */
+SVCXPRT *
+svcfd_create(fd, sendsize, recvsize)
+ int fd;
+ u_int sendsize;
+ u_int recvsize;
+{
+
+ return (makefd_xprt(fd, sendsize, recvsize));
+}
+
+static SVCXPRT *
+makefd_xprt(fd, sendsize, recvsize)
+ int fd;
+ u_int sendsize;
+ u_int recvsize;
+{
+ register SVCXPRT *xprt;
+ register struct tcp_conn *cd;
+
+ xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
+ if (xprt == (SVCXPRT *)NULL) {
+ (void) fprintf(stderr, "svc_tcp: makefd_xprt: out of memory\n");
+ goto done;
+ }
+ cd = (struct tcp_conn *)mem_alloc(sizeof(struct tcp_conn));
+ if (cd == (struct tcp_conn *)NULL) {
+ (void) fprintf(stderr, "svc_tcp: makefd_xprt: out of memory\n");
+ mem_free((char *) xprt, sizeof(SVCXPRT));
+ xprt = (SVCXPRT *)NULL;
+ goto done;
+ }
+ cd->strm_stat = XPRT_IDLE;
+ xdrrec_create(&(cd->xdrs), sendsize, recvsize,
+ (caddr_t)xprt, readtcp, writetcp);
+ xprt->xp_p2 = NULL;
+ xprt->xp_p1 = (caddr_t)cd;
+ xprt->xp_verf.oa_base = cd->verf_body;
+ xprt->xp_addrlen = 0;
+ xprt->xp_ops = &svctcp_op; /* truely deals with calls */
+ xprt->xp_port = 0; /* this is a connection, not a rendezvouser */
+ xprt->xp_sock = fd;
+ xprt_register(xprt);
+ done:
+ return (xprt);
+}
+
+static bool_t
+rendezvous_request(xprt)
+ register SVCXPRT *xprt;
+{
+ int sock;
+ struct tcp_rendezvous *r;
+ struct sockaddr_in addr;
+ int len;
+
+ r = (struct tcp_rendezvous *)xprt->xp_p1;
+ again:
+ len = sizeof(struct sockaddr_in);
+ if ((sock = accept(xprt->xp_sock, (struct sockaddr *)&addr,
+ &len)) < 0) {
+ if (errno == EINTR)
+ goto again;
+ return (FALSE);
+ }
+ /*
+ * XXX careful for ftp bounce attacks. If discovered, close the
+ * socket and look for another connection.
+ */
+ if (addr.sin_port == htons(20)) {
+ close(sock);
+ goto again;
+ }
+ /*
+ * make a new transporter (re-uses xprt)
+ */
+ xprt = makefd_xprt(sock, r->sendsize, r->recvsize);
+ xprt->xp_raddr = addr;
+ xprt->xp_addrlen = len;
+ return (FALSE); /* there is never an rpc msg to be processed */
+}
+
+static enum xprt_stat
+rendezvous_stat()
+{
+
+ return (XPRT_IDLE);
+}
+
+static void
+svctcp_destroy(xprt)
+ register SVCXPRT *xprt;
+{
+ register struct tcp_conn *cd = (struct tcp_conn *)xprt->xp_p1;
+
+ xprt_unregister(xprt);
+ (void)close(xprt->xp_sock);
+ if (xprt->xp_port != 0) {
+ /* a rendezvouser socket */
+ xprt->xp_port = 0;
+ } else {
+ /* an actual connection socket */
+ XDR_DESTROY(&(cd->xdrs));
+ }
+ mem_free((caddr_t)cd, sizeof(struct tcp_conn));
+ mem_free((caddr_t)xprt, sizeof(SVCXPRT));
+}
+
+/*
+ * All read operations timeout after 35 seconds.
+ * A timeout is fatal for the connection.
+ */
+static struct timeval wait_per_try = { 35, 0 };
+
+/*
+ * reads data from the tcp conection.
+ * any error is fatal and the connection is closed.
+ * (And a read of zero bytes is a half closed stream => error.)
+ */
+static int
+readtcp(xprt, buf, len)
+ register SVCXPRT *xprt;
+ caddr_t buf;
+ register int len;
+{
+ register int sock = xprt->xp_sock;
+ struct timeval start, delta, tv;
+ struct timeval tmp1, tmp2;
+ fd_set *fds, readfds;
+
+ if (sock + 1 > FD_SETSIZE) {
+ int bytes = howmany(sock+1, NFDBITS) * sizeof(fd_mask);
+ fds = (fd_set *)malloc(bytes);
+
+ if (fds == NULL)
+ goto fatal_err;
+ memset(fds, 0, bytes);
+ } else {
+ fds = &readfds;
+ FD_ZERO(fds);
+ }
+
+ delta = wait_per_try;
+ gettimeofday(&start, NULL);
+ do {
+ /* XXX we know the other bits are still clear */
+ FD_SET(sock, fds);
+ tv = delta; /* in case select() implements writeback */
+ switch (select(sock + 1, fds, NULL, NULL, &tv)) {
+ case -1:
+ if (errno != EINTR)
+ goto fatal_err;
+ gettimeofday(&tmp1, NULL);
+ timersub(&tmp1, &start, &tmp2);
+ timersub(&delta, &tmp2, &tmp1);
+ if (tmp1.tv_sec < 0 || !timerisset(&tmp1))
+ goto fatal_err;
+ delta = tmp1;
+ continue;
+ case 0:
+ goto fatal_err;
+ }
+ } while (!FD_ISSET(sock, fds));
+ if ((len = read(sock, buf, len)) > 0) {
+ if (fds != &readfds)
+ free(fds);
+ return (len);
+ }
+fatal_err:
+ ((struct tcp_conn *)(xprt->xp_p1))->strm_stat = XPRT_DIED;
+ if (fds != &readfds)
+ free(fds);
+ return (-1);
+}
+
+/*
+ * writes data to the tcp connection.
+ * Any error is fatal and the connection is closed.
+ */
+static int
+writetcp(xprt, buf, len)
+ register SVCXPRT *xprt;
+ caddr_t buf;
+ int len;
+{
+ register int i, cnt;
+
+ for (cnt = len; cnt > 0; cnt -= i, buf += i) {
+ if ((i = write(xprt->xp_sock, buf, cnt)) < 0) {
+ ((struct tcp_conn *)(xprt->xp_p1))->strm_stat =
+ XPRT_DIED;
+ return (-1);
+ }
+ }
+ return (len);
+}
+
+static enum xprt_stat
+svctcp_stat(xprt)
+ SVCXPRT *xprt;
+{
+ register struct tcp_conn *cd =
+ (struct tcp_conn *)(xprt->xp_p1);
+
+ if (cd->strm_stat == XPRT_DIED)
+ return (XPRT_DIED);
+ if (! xdrrec_eof(&(cd->xdrs)))
+ return (XPRT_MOREREQS);
+ return (XPRT_IDLE);
+}
+
+static bool_t
+svctcp_recv(xprt, msg)
+ SVCXPRT *xprt;
+ register struct rpc_msg *msg;
+{
+ register struct tcp_conn *cd =
+ (struct tcp_conn *)(xprt->xp_p1);
+ register XDR *xdrs = &(cd->xdrs);
+
+ xdrs->x_op = XDR_DECODE;
+ (void)xdrrec_skiprecord(xdrs);
+ if (xdr_callmsg(xdrs, msg)) {
+ cd->x_id = msg->rm_xid;
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+static bool_t
+svctcp_getargs(xprt, xdr_args, args_ptr)
+ SVCXPRT *xprt;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
+{
+
+ return ((*xdr_args)(&(((struct tcp_conn *)(xprt->xp_p1))->xdrs), args_ptr));
+}
+
+static bool_t
+svctcp_freeargs(xprt, xdr_args, args_ptr)
+ SVCXPRT *xprt;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
+{
+ register XDR *xdrs =
+ &(((struct tcp_conn *)(xprt->xp_p1))->xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_args)(xdrs, args_ptr));
+}
+
+static bool_t
+svctcp_reply(xprt, msg)
+ SVCXPRT *xprt;
+ register struct rpc_msg *msg;
+{
+ register struct tcp_conn *cd =
+ (struct tcp_conn *)(xprt->xp_p1);
+ register XDR *xdrs = &(cd->xdrs);
+ register bool_t stat;
+
+ xdrs->x_op = XDR_ENCODE;
+ msg->rm_xid = cd->x_id;
+ stat = xdr_replymsg(xdrs, msg);
+ (void)xdrrec_endofrecord(xdrs, TRUE);
+ return (stat);
+}
diff --git a/lib/libc/rpc/svc_udp.c b/lib/libc/rpc/svc_udp.c
new file mode 100644
index 0000000..6622de2
--- /dev/null
+++ b/lib/libc/rpc/svc_udp.c
@@ -0,0 +1,480 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_udp.c 1.24 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_udp.c 2.2 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: svc_udp.c,v 1.7 1996/12/30 15:21:19 peter Exp $";
+#endif
+
+/*
+ * svc_udp.c,
+ * Server side for UDP/IP based RPC. (Does some caching in the hopes of
+ * achieving execute-at-most-once semantics.)
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <errno.h>
+
+#define rpc_buffer(xprt) ((xprt)->xp_p1)
+#define MAX(a, b) ((a > b) ? a : b)
+
+static bool_t svcudp_recv();
+static bool_t svcudp_reply();
+static enum xprt_stat svcudp_stat();
+static bool_t svcudp_getargs();
+static bool_t svcudp_freeargs();
+static void svcudp_destroy();
+static void cache_set __P((SVCXPRT *, u_long));
+static int cache_get __P((SVCXPRT *, struct rpc_msg *, char **, u_long *));
+
+static struct xp_ops svcudp_op = {
+ svcudp_recv,
+ svcudp_stat,
+ svcudp_getargs,
+ svcudp_reply,
+ svcudp_freeargs,
+ svcudp_destroy
+};
+
+/*
+ * kept in xprt->xp_p2
+ */
+struct svcudp_data {
+ u_int su_iosz; /* byte size of send.recv buffer */
+ u_long su_xid; /* transaction id */
+ XDR su_xdrs; /* XDR handle */
+ char su_verfbody[MAX_AUTH_BYTES]; /* verifier body */
+ char * su_cache; /* cached data, NULL if no cache */
+};
+#define su_data(xprt) ((struct svcudp_data *)(xprt->xp_p2))
+
+/*
+ * Usage:
+ * xprt = svcudp_create(sock);
+ *
+ * If sock<0 then a socket is created, else sock is used.
+ * If the socket, sock is not bound to a port then svcudp_create
+ * binds it to an arbitrary port. In any (successful) case,
+ * xprt->xp_sock is the registered socket number and xprt->xp_port is the
+ * associated port number.
+ * Once *xprt is initialized, it is registered as a transporter;
+ * see (svc.h, xprt_register).
+ * The routines returns NULL if a problem occurred.
+ */
+SVCXPRT *
+svcudp_bufcreate(sock, sendsz, recvsz)
+ register int sock;
+ u_int sendsz, recvsz;
+{
+ bool_t madesock = FALSE;
+ register SVCXPRT *xprt;
+ register struct svcudp_data *su;
+ struct sockaddr_in addr;
+ int len = sizeof(struct sockaddr_in);
+
+ if (sock == RPC_ANYSOCK) {
+ if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("svcudp_create: socket creation problem");
+ return ((SVCXPRT *)NULL);
+ }
+ madesock = TRUE;
+ }
+ memset((char *)&addr, 0, sizeof (addr));
+ addr.sin_len = sizeof(struct sockaddr_in);
+ addr.sin_family = AF_INET;
+ if (bindresvport(sock, &addr)) {
+ addr.sin_port = 0;
+ (void)bind(sock, (struct sockaddr *)&addr, len);
+ }
+ if (getsockname(sock, (struct sockaddr *)&addr, &len) != 0) {
+ perror("svcudp_create - cannot getsockname");
+ if (madesock)
+ (void)close(sock);
+ return ((SVCXPRT *)NULL);
+ }
+ xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
+ if (xprt == NULL) {
+ (void)fprintf(stderr, "svcudp_create: out of memory\n");
+ return (NULL);
+ }
+ su = (struct svcudp_data *)mem_alloc(sizeof(*su));
+ if (su == NULL) {
+ (void)fprintf(stderr, "svcudp_create: out of memory\n");
+ return (NULL);
+ }
+ su->su_iosz = ((MAX(sendsz, recvsz) + 3) / 4) * 4;
+ if ((rpc_buffer(xprt) = mem_alloc(su->su_iosz)) == NULL) {
+ (void)fprintf(stderr, "svcudp_create: out of memory\n");
+ return (NULL);
+ }
+ xdrmem_create(
+ &(su->su_xdrs), rpc_buffer(xprt), su->su_iosz, XDR_DECODE);
+ su->su_cache = NULL;
+ xprt->xp_p2 = (caddr_t)su;
+ xprt->xp_verf.oa_base = su->su_verfbody;
+ xprt->xp_ops = &svcudp_op;
+ xprt->xp_port = ntohs(addr.sin_port);
+ xprt->xp_sock = sock;
+ xprt_register(xprt);
+ return (xprt);
+}
+
+SVCXPRT *
+svcudp_create(sock)
+ int sock;
+{
+
+ return(svcudp_bufcreate(sock, UDPMSGSIZE, UDPMSGSIZE));
+}
+
+static enum xprt_stat
+svcudp_stat(xprt)
+ SVCXPRT *xprt;
+{
+
+ return (XPRT_IDLE);
+}
+
+static bool_t
+svcudp_recv(xprt, msg)
+ register SVCXPRT *xprt;
+ struct rpc_msg *msg;
+{
+ register struct svcudp_data *su = su_data(xprt);
+ register XDR *xdrs = &(su->su_xdrs);
+ register int rlen;
+ char *reply;
+ u_long replylen;
+
+ again:
+ xprt->xp_addrlen = sizeof(struct sockaddr_in);
+ rlen = recvfrom(xprt->xp_sock, rpc_buffer(xprt), (int) su->su_iosz,
+ 0, (struct sockaddr *)&(xprt->xp_raddr), &(xprt->xp_addrlen));
+ if (rlen == -1 && errno == EINTR)
+ goto again;
+ if (rlen == -1 || rlen < 4*sizeof(u_int32_t))
+ return (FALSE);
+ xdrs->x_op = XDR_DECODE;
+ XDR_SETPOS(xdrs, 0);
+ if (! xdr_callmsg(xdrs, msg))
+ return (FALSE);
+ su->su_xid = msg->rm_xid;
+ if (su->su_cache != NULL) {
+ if (cache_get(xprt, msg, &reply, &replylen)) {
+ (void) sendto(xprt->xp_sock, reply, (int) replylen, 0,
+ (struct sockaddr *) &xprt->xp_raddr, xprt->xp_addrlen);
+ return (TRUE);
+ }
+ }
+ return (TRUE);
+}
+
+static bool_t
+svcudp_reply(xprt, msg)
+ register SVCXPRT *xprt;
+ struct rpc_msg *msg;
+{
+ register struct svcudp_data *su = su_data(xprt);
+ register XDR *xdrs = &(su->su_xdrs);
+ register int slen;
+ register bool_t stat = FALSE;
+
+ xdrs->x_op = XDR_ENCODE;
+ XDR_SETPOS(xdrs, 0);
+ msg->rm_xid = su->su_xid;
+ if (xdr_replymsg(xdrs, msg)) {
+ slen = (int)XDR_GETPOS(xdrs);
+ if (sendto(xprt->xp_sock, rpc_buffer(xprt), slen, 0,
+ (struct sockaddr *)&(xprt->xp_raddr), xprt->xp_addrlen)
+ == slen) {
+ stat = TRUE;
+ if (su->su_cache && slen >= 0) {
+ cache_set(xprt, (u_long) slen);
+ }
+ }
+ }
+ return (stat);
+}
+
+static bool_t
+svcudp_getargs(xprt, xdr_args, args_ptr)
+ SVCXPRT *xprt;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
+{
+
+ return ((*xdr_args)(&(su_data(xprt)->su_xdrs), args_ptr));
+}
+
+static bool_t
+svcudp_freeargs(xprt, xdr_args, args_ptr)
+ SVCXPRT *xprt;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
+{
+ register XDR *xdrs = &(su_data(xprt)->su_xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_args)(xdrs, args_ptr));
+}
+
+static void
+svcudp_destroy(xprt)
+ register SVCXPRT *xprt;
+{
+ register struct svcudp_data *su = su_data(xprt);
+
+ xprt_unregister(xprt);
+ (void)close(xprt->xp_sock);
+ XDR_DESTROY(&(su->su_xdrs));
+ mem_free(rpc_buffer(xprt), su->su_iosz);
+ mem_free((caddr_t)su, sizeof(struct svcudp_data));
+ mem_free((caddr_t)xprt, sizeof(SVCXPRT));
+}
+
+
+/***********this could be a separate file*********************/
+
+/*
+ * Fifo cache for udp server
+ * Copies pointers to reply buffers into fifo cache
+ * Buffers are sent again if retransmissions are detected.
+ */
+
+#define SPARSENESS 4 /* 75% sparse */
+
+#define CACHE_PERROR(msg) \
+ (void) fprintf(stderr,"%s\n", msg)
+
+#define ALLOC(type, size) \
+ (type *) mem_alloc((unsigned) (sizeof(type) * (size)))
+
+#define BZERO(addr, type, size) \
+ memset((char *) addr, 0, sizeof(type) * (int) (size))
+
+/*
+ * An entry in the cache
+ */
+typedef struct cache_node *cache_ptr;
+struct cache_node {
+ /*
+ * Index into cache is xid, proc, vers, prog and address
+ */
+ u_long cache_xid;
+ u_long cache_proc;
+ u_long cache_vers;
+ u_long cache_prog;
+ struct sockaddr_in cache_addr;
+ /*
+ * The cached reply and length
+ */
+ char * cache_reply;
+ u_long cache_replylen;
+ /*
+ * Next node on the list, if there is a collision
+ */
+ cache_ptr cache_next;
+};
+
+
+
+/*
+ * The entire cache
+ */
+struct udp_cache {
+ u_long uc_size; /* size of cache */
+ cache_ptr *uc_entries; /* hash table of entries in cache */
+ cache_ptr *uc_fifo; /* fifo list of entries in cache */
+ u_long uc_nextvictim; /* points to next victim in fifo list */
+ u_long uc_prog; /* saved program number */
+ u_long uc_vers; /* saved version number */
+ u_long uc_proc; /* saved procedure number */
+ struct sockaddr_in uc_addr; /* saved caller's address */
+};
+
+
+/*
+ * the hashing function
+ */
+#define CACHE_LOC(transp, xid) \
+ (xid % (SPARSENESS*((struct udp_cache *) su_data(transp)->su_cache)->uc_size))
+
+
+/*
+ * Enable use of the cache.
+ * Note: there is no disable.
+ */
+int svcudp_enablecache(transp, size)
+ SVCXPRT *transp;
+ u_long size;
+{
+ struct svcudp_data *su = su_data(transp);
+ struct udp_cache *uc;
+
+ if (su->su_cache != NULL) {
+ CACHE_PERROR("enablecache: cache already enabled");
+ return(0);
+ }
+ uc = ALLOC(struct udp_cache, 1);
+ if (uc == NULL) {
+ CACHE_PERROR("enablecache: could not allocate cache");
+ return(0);
+ }
+ uc->uc_size = size;
+ uc->uc_nextvictim = 0;
+ uc->uc_entries = ALLOC(cache_ptr, size * SPARSENESS);
+ if (uc->uc_entries == NULL) {
+ CACHE_PERROR("enablecache: could not allocate cache data");
+ return(0);
+ }
+ BZERO(uc->uc_entries, cache_ptr, size * SPARSENESS);
+ uc->uc_fifo = ALLOC(cache_ptr, size);
+ if (uc->uc_fifo == NULL) {
+ CACHE_PERROR("enablecache: could not allocate cache fifo");
+ return(0);
+ }
+ BZERO(uc->uc_fifo, cache_ptr, size);
+ su->su_cache = (char *) uc;
+ return(1);
+}
+
+
+/*
+ * Set an entry in the cache
+ */
+static void
+cache_set(xprt, replylen)
+ SVCXPRT *xprt;
+ u_long replylen;
+{
+ register cache_ptr victim;
+ register cache_ptr *vicp;
+ register struct svcudp_data *su = su_data(xprt);
+ struct udp_cache *uc = (struct udp_cache *) su->su_cache;
+ u_int loc;
+ char *newbuf;
+
+ /*
+ * Find space for the new entry, either by
+ * reusing an old entry, or by mallocing a new one
+ */
+ victim = uc->uc_fifo[uc->uc_nextvictim];
+ if (victim != NULL) {
+ loc = CACHE_LOC(xprt, victim->cache_xid);
+ for (vicp = &uc->uc_entries[loc];
+ *vicp != NULL && *vicp != victim;
+ vicp = &(*vicp)->cache_next)
+ ;
+ if (*vicp == NULL) {
+ CACHE_PERROR("cache_set: victim not found");
+ return;
+ }
+ *vicp = victim->cache_next; /* remote from cache */
+ newbuf = victim->cache_reply;
+ } else {
+ victim = ALLOC(struct cache_node, 1);
+ if (victim == NULL) {
+ CACHE_PERROR("cache_set: victim alloc failed");
+ return;
+ }
+ newbuf = mem_alloc(su->su_iosz);
+ if (newbuf == NULL) {
+ CACHE_PERROR("cache_set: could not allocate new rpc_buffer");
+ return;
+ }
+ }
+
+ /*
+ * Store it away
+ */
+ victim->cache_replylen = replylen;
+ victim->cache_reply = rpc_buffer(xprt);
+ rpc_buffer(xprt) = newbuf;
+ xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz, XDR_ENCODE);
+ victim->cache_xid = su->su_xid;
+ victim->cache_proc = uc->uc_proc;
+ victim->cache_vers = uc->uc_vers;
+ victim->cache_prog = uc->uc_prog;
+ victim->cache_addr = uc->uc_addr;
+ loc = CACHE_LOC(xprt, victim->cache_xid);
+ victim->cache_next = uc->uc_entries[loc];
+ uc->uc_entries[loc] = victim;
+ uc->uc_fifo[uc->uc_nextvictim++] = victim;
+ uc->uc_nextvictim %= uc->uc_size;
+}
+
+/*
+ * Try to get an entry from the cache
+ * return 1 if found, 0 if not found
+ */
+static int
+cache_get(xprt, msg, replyp, replylenp)
+ SVCXPRT *xprt;
+ struct rpc_msg *msg;
+ char **replyp;
+ u_long *replylenp;
+{
+ u_int loc;
+ register cache_ptr ent;
+ register struct svcudp_data *su = su_data(xprt);
+ register struct udp_cache *uc = (struct udp_cache *) su->su_cache;
+
+# define EQADDR(a1, a2) (memcmp(&a1, &a2, sizeof(a1)) == 0)
+
+ loc = CACHE_LOC(xprt, su->su_xid);
+ for (ent = uc->uc_entries[loc]; ent != NULL; ent = ent->cache_next) {
+ if (ent->cache_xid == su->su_xid &&
+ ent->cache_proc == uc->uc_proc &&
+ ent->cache_vers == uc->uc_vers &&
+ ent->cache_prog == uc->uc_prog &&
+ EQADDR(ent->cache_addr, uc->uc_addr)) {
+ *replyp = ent->cache_reply;
+ *replylenp = ent->cache_replylen;
+ return(1);
+ }
+ }
+ /*
+ * Failed to find entry
+ * Remember a few things so we can do a set later
+ */
+ uc->uc_proc = msg->rm_call.cb_proc;
+ uc->uc_vers = msg->rm_call.cb_vers;
+ uc->uc_prog = msg->rm_call.cb_prog;
+ uc->uc_addr = xprt->xp_raddr;
+ return(0);
+}
+
diff --git a/lib/libc/rpc/svc_unix.c b/lib/libc/rpc/svc_unix.c
new file mode 100644
index 0000000..04e3223
--- /dev/null
+++ b/lib/libc/rpc/svc_unix.c
@@ -0,0 +1,511 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)svc_unix.c 1.21 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)svc_unix.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: svc_unix.c,v 1.8 1996/12/30 15:19:08 peter Exp $";
+#endif
+
+/*
+ * svc_unix.c, Server side for TCP/IP based RPC.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * Actually implements two flavors of transporter -
+ * a unix rendezvouser (a listner and connection establisher)
+ * and a record/unix stream.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <errno.h>
+
+/*
+ * Ops vector for AF_UNIX based rpc service handle
+ */
+static bool_t svcunix_recv();
+static enum xprt_stat svcunix_stat();
+static bool_t svcunix_getargs();
+static bool_t svcunix_reply();
+static bool_t svcunix_freeargs();
+static void svcunix_destroy();
+
+static struct xp_ops svcunix_op = {
+ svcunix_recv,
+ svcunix_stat,
+ svcunix_getargs,
+ svcunix_reply,
+ svcunix_freeargs,
+ svcunix_destroy
+};
+
+/*
+ * Ops vector for TCP/IP rendezvous handler
+ */
+static bool_t rendezvous_request();
+static enum xprt_stat rendezvous_stat();
+
+static struct xp_ops svcunix_rendezvous_op = {
+ rendezvous_request,
+ rendezvous_stat,
+ (bool_t (*)())abort,
+ (bool_t (*)())abort,
+ (bool_t (*)())abort,
+ svcunix_destroy
+};
+
+static int readunix(), writeunix();
+static SVCXPRT *makefd_xprt();
+
+struct unix_rendezvous { /* kept in xprt->xp_p1 */
+ u_int sendsize;
+ u_int recvsize;
+};
+
+struct unix_conn { /* kept in xprt->xp_p1 */
+ enum xprt_stat strm_stat;
+ u_long x_id;
+ XDR xdrs;
+ char verf_body[MAX_AUTH_BYTES];
+};
+
+
+struct cmessage {
+ struct cmsghdr cmsg;
+ struct cmsgcred cmcred;
+};
+
+static struct cmessage cm;
+
+static int __msgread(sock, buf, cnt)
+ int sock;
+ void *buf;
+ size_t cnt;
+{
+ struct iovec iov[1];
+ struct msghdr msg;
+
+ bzero((char *)&cm, sizeof(cm));
+ iov[0].iov_base = buf;
+ iov[0].iov_len = cnt;
+
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_control = (caddr_t)&cm;
+ msg.msg_controllen = sizeof(struct cmessage);
+ msg.msg_flags = 0;
+
+ return(recvmsg(sock, &msg, 0));
+}
+
+static int __msgwrite(sock, buf, cnt)
+ int sock;
+ void *buf;
+ size_t cnt;
+{
+ struct iovec iov[1];
+ struct msghdr msg;
+
+ bzero((char *)&cm, sizeof(cm));
+ iov[0].iov_base = buf;
+ iov[0].iov_len = cnt;
+
+ cm.cmsg.cmsg_type = SCM_CREDS;
+ cm.cmsg.cmsg_level = SOL_SOCKET;
+ cm.cmsg.cmsg_len = sizeof(struct cmessage);
+
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_control = (caddr_t)&cm;
+ msg.msg_controllen = sizeof(struct cmessage);
+ msg.msg_flags = 0;
+
+ return(sendmsg(sock, &msg, 0));
+}
+
+/*
+ * Usage:
+ * xprt = svcunix_create(sock, send_buf_size, recv_buf_size);
+ *
+ * Creates, registers, and returns a (rpc) unix based transporter.
+ * Once *xprt is initialized, it is registered as a transporter
+ * see (svc.h, xprt_register). This routine returns
+ * a NULL if a problem occurred.
+ *
+ * If sock<0 then a socket is created, else sock is used.
+ * If the socket, sock is not bound to a port then svcunix_create
+ * binds it to an arbitrary port. The routine then starts a unix
+ * listener on the socket's associated port. In any (successful) case,
+ * xprt->xp_sock is the registered socket number and xprt->xp_port is the
+ * associated port number.
+ *
+ * Since unix streams do buffered io similar to stdio, the caller can specify
+ * how big the send and receive buffers are via the second and third parms;
+ * 0 => use the system default.
+ */
+SVCXPRT *
+svcunix_create(sock, sendsize, recvsize, path)
+ register int sock;
+ u_int sendsize;
+ u_int recvsize;
+ char *path;
+{
+ bool_t madesock = FALSE;
+ register SVCXPRT *xprt;
+ register struct unix_rendezvous *r;
+ struct sockaddr_un addr;
+ int len = sizeof(struct sockaddr_un);
+
+ if (sock == RPC_ANYSOCK) {
+ if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ perror("svc_unix.c - AF_UNIX socket creation problem");
+ return ((SVCXPRT *)NULL);
+ }
+ madesock = TRUE;
+ }
+ memset(&addr, 0, sizeof (addr));
+ addr.sun_family = AF_UNIX;
+ strcpy(addr.sun_path, path);
+ len = strlen(addr.sun_path) + sizeof(addr.sun_family) +
+ sizeof(addr.sun_len) + 1;
+ addr.sun_len = len;
+
+ bind(sock, (struct sockaddr *)&addr, len);
+
+ if ((getsockname(sock, (struct sockaddr *)&addr, &len) != 0) ||
+ (listen(sock, 2) != 0)) {
+ perror("svc_unix.c - cannot getsockname or listen");
+ if (madesock)
+ (void)close(sock);
+ return ((SVCXPRT *)NULL);
+ }
+ r = (struct unix_rendezvous *)mem_alloc(sizeof(*r));
+ if (r == NULL) {
+ (void) fprintf(stderr, "svcunix_create: out of memory\n");
+ return (NULL);
+ }
+ r->sendsize = sendsize;
+ r->recvsize = recvsize;
+ xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
+ if (xprt == NULL) {
+ (void) fprintf(stderr, "svcunix_create: out of memory\n");
+ return (NULL);
+ }
+ xprt->xp_p2 = NULL;
+ xprt->xp_p1 = (caddr_t)r;
+ xprt->xp_verf = _null_auth;
+ xprt->xp_ops = &svcunix_rendezvous_op;
+ xprt->xp_port = -1 /*ntohs(addr.sin_port)*/;
+ xprt->xp_sock = sock;
+ xprt_register(xprt);
+ return (xprt);
+}
+
+/*
+ * Like svunix_create(), except the routine takes any *open* UNIX file
+ * descriptor as its first input.
+ */
+SVCXPRT *
+svcunixfd_create(fd, sendsize, recvsize)
+ int fd;
+ u_int sendsize;
+ u_int recvsize;
+{
+
+ return (makefd_xprt(fd, sendsize, recvsize));
+}
+
+static SVCXPRT *
+makefd_xprt(fd, sendsize, recvsize)
+ int fd;
+ u_int sendsize;
+ u_int recvsize;
+{
+ register SVCXPRT *xprt;
+ register struct unix_conn *cd;
+
+ xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
+ if (xprt == (SVCXPRT *)NULL) {
+ (void) fprintf(stderr, "svc_unix: makefd_xprt: out of memory\n");
+ goto done;
+ }
+ cd = (struct unix_conn *)mem_alloc(sizeof(struct unix_conn));
+ if (cd == (struct unix_conn *)NULL) {
+ (void) fprintf(stderr, "svc_unix: makefd_xprt: out of memory\n");
+ mem_free((char *) xprt, sizeof(SVCXPRT));
+ xprt = (SVCXPRT *)NULL;
+ goto done;
+ }
+ cd->strm_stat = XPRT_IDLE;
+ xdrrec_create(&(cd->xdrs), sendsize, recvsize,
+ (caddr_t)xprt, readunix, writeunix);
+ xprt->xp_p2 = NULL;
+ xprt->xp_p1 = (caddr_t)cd;
+ xprt->xp_verf.oa_base = cd->verf_body;
+ xprt->xp_addrlen = 0;
+ xprt->xp_ops = &svcunix_op; /* truely deals with calls */
+ xprt->xp_port = 0; /* this is a connection, not a rendezvouser */
+ xprt->xp_sock = fd;
+ xprt_register(xprt);
+ done:
+ return (xprt);
+}
+
+static bool_t
+rendezvous_request(xprt)
+ register SVCXPRT *xprt;
+{
+ int sock;
+ struct unix_rendezvous *r;
+ struct sockaddr_un addr;
+ struct sockaddr_in in_addr;
+ int len;
+
+ r = (struct unix_rendezvous *)xprt->xp_p1;
+ again:
+ len = sizeof(struct sockaddr_in);
+ if ((sock = accept(xprt->xp_sock, (struct sockaddr *)&addr,
+ &len)) < 0) {
+ if (errno == EINTR)
+ goto again;
+ return (FALSE);
+ }
+
+ /*
+ * make a new transporter (re-uses xprt)
+ */
+ bzero((char *)&in_addr, sizeof(in_addr));
+ in_addr.sin_family = AF_UNIX;
+ xprt = makefd_xprt(sock, r->sendsize, r->recvsize);
+ xprt->xp_raddr = in_addr;
+ xprt->xp_addrlen = len;
+ return (FALSE); /* there is never an rpc msg to be processed */
+}
+
+static enum xprt_stat
+rendezvous_stat()
+{
+
+ return (XPRT_IDLE);
+}
+
+static void
+svcunix_destroy(xprt)
+ register SVCXPRT *xprt;
+{
+ register struct unix_conn *cd = (struct unix_conn *)xprt->xp_p1;
+
+ xprt_unregister(xprt);
+ (void)close(xprt->xp_sock);
+ if (xprt->xp_port != 0) {
+ /* a rendezvouser socket */
+ xprt->xp_port = 0;
+ } else {
+ /* an actual connection socket */
+ XDR_DESTROY(&(cd->xdrs));
+ }
+ mem_free((caddr_t)cd, sizeof(struct unix_conn));
+ mem_free((caddr_t)xprt, sizeof(SVCXPRT));
+}
+
+/*
+ * All read operations timeout after 35 seconds.
+ * A timeout is fatal for the connection.
+ */
+static struct timeval wait_per_try = { 35, 0 };
+
+/*
+ * reads data from the unix conection.
+ * any error is fatal and the connection is closed.
+ * (And a read of zero bytes is a half closed stream => error.)
+ */
+static int
+readunix(xprt, buf, len)
+ register SVCXPRT *xprt;
+ caddr_t buf;
+ register int len;
+{
+ register int sock = xprt->xp_sock;
+ struct timeval start, delta, tv;
+ struct timeval tmp1, tmp2;
+ fd_set *fds, readfds;
+
+ if (sock + 1 > FD_SETSIZE) {
+ int bytes = howmany(sock+1, NFDBITS) * sizeof(fd_mask);
+ fds = (fd_set *)malloc(bytes);
+
+ if (fds == NULL)
+ goto fatal_err;
+ memset(fds, 0, bytes);
+ } else {
+ fds = &readfds;
+ FD_ZERO(fds);
+ }
+
+ delta = wait_per_try;
+ gettimeofday(&start, NULL);
+ do {
+ /* XXX we know the other bits are still clear */
+ FD_SET(sock, fds);
+ tv = delta; /* in case select() implements writeback */
+ switch (select(sock + 1, fds, NULL, NULL, &tv)) {
+ case -1:
+ if (errno != EINTR)
+ goto fatal_err;
+ gettimeofday(&tmp1, NULL);
+ timersub(&tmp1, &start, &tmp2);
+ timersub(&delta, &tmp2, &tmp1);
+ if (tmp1.tv_sec < 0 || !timerisset(&tmp1))
+ goto fatal_err;
+ delta = tmp1;
+ continue;
+ case 0:
+ goto fatal_err;
+ }
+ } while (!FD_ISSET(sock, fds));
+ if ((len = __msgread(sock, buf, len)) > 0) {
+ if (fds != &readfds)
+ free(fds);
+ return (len);
+ }
+fatal_err:
+ ((struct unix_conn *)(xprt->xp_p1))->strm_stat = XPRT_DIED;
+ if (fds != &readfds)
+ free(fds);
+ return (-1);
+}
+
+/*
+ * writes data to the unix connection.
+ * Any error is fatal and the connection is closed.
+ */
+static int
+writeunix(xprt, buf, len)
+ register SVCXPRT *xprt;
+ caddr_t buf;
+ int len;
+{
+ register int i, cnt;
+
+ for (cnt = len; cnt > 0; cnt -= i, buf += i) {
+ if ((i = __msgwrite(xprt->xp_sock, buf, cnt)) < 0) {
+ ((struct unix_conn *)(xprt->xp_p1))->strm_stat =
+ XPRT_DIED;
+ return (-1);
+ }
+ }
+ return (len);
+}
+
+static enum xprt_stat
+svcunix_stat(xprt)
+ SVCXPRT *xprt;
+{
+ register struct unix_conn *cd =
+ (struct unix_conn *)(xprt->xp_p1);
+
+ if (cd->strm_stat == XPRT_DIED)
+ return (XPRT_DIED);
+ if (! xdrrec_eof(&(cd->xdrs)))
+ return (XPRT_MOREREQS);
+ return (XPRT_IDLE);
+}
+
+static bool_t
+svcunix_recv(xprt, msg)
+ SVCXPRT *xprt;
+ register struct rpc_msg *msg;
+{
+ register struct unix_conn *cd =
+ (struct unix_conn *)(xprt->xp_p1);
+ register XDR *xdrs = &(cd->xdrs);
+
+ xdrs->x_op = XDR_DECODE;
+ (void)xdrrec_skiprecord(xdrs);
+ if (xdr_callmsg(xdrs, msg)) {
+ cd->x_id = msg->rm_xid;
+ /* set up verifiers */
+ msg->rm_call.cb_verf.oa_flavor = AUTH_UNIX;
+ msg->rm_call.cb_verf.oa_base = (caddr_t)&cm;
+ msg->rm_call.cb_verf.oa_length = sizeof(cm);
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+static bool_t
+svcunix_getargs(xprt, xdr_args, args_ptr)
+ SVCXPRT *xprt;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
+{
+
+ return ((*xdr_args)(&(((struct unix_conn *)(xprt->xp_p1))->xdrs), args_ptr));
+}
+
+static bool_t
+svcunix_freeargs(xprt, xdr_args, args_ptr)
+ SVCXPRT *xprt;
+ xdrproc_t xdr_args;
+ caddr_t args_ptr;
+{
+ register XDR *xdrs =
+ &(((struct unix_conn *)(xprt->xp_p1))->xdrs);
+
+ xdrs->x_op = XDR_FREE;
+ return ((*xdr_args)(xdrs, args_ptr));
+}
+
+static bool_t
+svcunix_reply(xprt, msg)
+ SVCXPRT *xprt;
+ register struct rpc_msg *msg;
+{
+ register struct unix_conn *cd =
+ (struct unix_conn *)(xprt->xp_p1);
+ register XDR *xdrs = &(cd->xdrs);
+ register bool_t stat;
+
+ xdrs->x_op = XDR_ENCODE;
+ msg->rm_xid = cd->x_id;
+ stat = xdr_replymsg(xdrs, msg);
+ (void)xdrrec_endofrecord(xdrs, TRUE);
+ return (stat);
+}
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc
index 47ea776..b86404a 100644
--- a/lib/libc/stdio/Makefile.inc
+++ b/lib/libc/stdio/Makefile.inc
@@ -1,22 +1,27 @@
# @(#)Makefile.inc 8.3 (Berkeley) 4/17/94
+# $Id: Makefile.inc,v 1.8 1997/02/22 15:01:45 peter Exp $
# stdio sources
-.PATH: ${.CURDIR}/stdio
+.PATH: ${.CURDIR}/../libc/stdio
-SRCS+= clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c \
- fgetln.c fgetpos.c fgets.c fileno.c findfp.c flags.c fopen.c \
+SRCS+= asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c \
+ fgetc.c fgetln.c fgetpos.c fgets.c fileno.c findfp.c flags.c fopen.c \
fprintf.c fpurge.c fputc.c fputs.c fread.c freopen.c fscanf.c \
fseek.c fsetpos.c ftell.c funopen.c fvwrite.c fwalk.c fwrite.c \
getc.c getchar.c gets.c getw.c makebuf.c mktemp.c perror.c \
printf.c putc.c putchar.c puts.c putw.c refill.c remove.c rewind.c \
rget.c scanf.c setbuf.c setbuffer.c setvbuf.c snprintf.c sprintf.c \
- sscanf.c stdio.c tempnam.c tmpfile.c tmpnam.c ungetc.c vfprintf.c \
- vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c vsscanf.c \
- wbuf.c wsetup.c
+ sscanf.c stdio.c tempnam.c tmpfile.c tmpnam.c ungetc.c vasprintf.c \
+ vfprintf.c vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c \
+ vsscanf.c wbuf.c wsetup.c
-MAN3+= fclose.0 ferror.0 fflush.0 fgetln.0 fgets.0 fopen.0 fputs.0 \
- fread.0 fseek.0 funopen.0 getc.0 mktemp.0 printf.0 putc.0 remove.0 \
- scanf.0 setbuf.0 stdio.0 tmpnam.0 ungetc.0
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN3+= stdio/fclose.3 stdio/ferror.3 stdio/fflush.3 stdio/fgetln.3 \
+ stdio/fgets.3 stdio/fopen.3 stdio/fputs.3 stdio/fread.3 stdio/fseek.3 \
+ stdio/funopen.3 stdio/getc.3 stdio/mktemp.3 stdio/printf.3 \
+ stdio/putc.3 stdio/remove.3 stdio/scanf.3 stdio/setbuf.3 \
+ stdio/stdio.3 stdio/tmpnam.3 stdio/ungetc.3
MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
MLINKS+=fflush.3 fpurge.3
@@ -30,9 +35,10 @@ MLINKS+=getc.3 fgetc.3 getc.3 getchar.3 getc.3 getw.3
MLINKS+=mktemp.3 mkstemp.3
MLINKS+=printf.3 fprintf.3 printf.3 snprintf.3 printf.3 sprintf.3 \
printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \
- printf.3 vsprintf.3
+ printf.3 vsprintf.3 printf.3 asprintf.3 printf.3 vasprintf.3
MLINKS+=putc.3 fputc.3 putc.3 putchar.3 putc.3 putw.3
MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \
scanf.3 vsscanf.3
MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3
MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3
+.endif
diff --git a/lib/libc/stdio/asprintf.c b/lib/libc/stdio/asprintf.c
new file mode 100644
index 0000000..9b4d05b
--- /dev/null
+++ b/lib/libc/stdio/asprintf.c
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (c) 1996 Peter Wemm <peter@freebsd.org>
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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_RCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_RCS and not lint */
+
+#include <stdio.h>
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+#if __STDC__
+int
+asprintf(char **str, char const *fmt, ...)
+#else
+int
+asprintf(str, fmt, va_alist)
+ char **str;
+ char *fmt;
+ va_dcl
+#endif
+{
+ int ret;
+ va_list ap;
+
+#if __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ ret = vasprintf(str, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c
index de4526e..a230119 100644
--- a/lib/libc/stdio/clrerr.c
+++ b/lib/libc/stdio/clrerr.c
@@ -35,15 +35,29 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#undef clearerr
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
void
clearerr(fp)
FILE *fp;
{
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
__sclearerr(fp);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
}
diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c
index 8315c3c..1104bd0 100644
--- a/lib/libc/stdio/fclose.c
+++ b/lib/libc/stdio/fclose.c
@@ -35,14 +35,23 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
+int
fclose(fp)
register FILE *fp;
{
@@ -52,6 +61,9 @@ fclose(fp)
errno = EBADF;
return (EOF);
}
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
r = fp->_flags & __SWR ? __sflush(fp) : 0;
if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0)
r = EOF;
@@ -61,7 +73,11 @@ fclose(fp)
FREEUB(fp);
if (HASLB(fp))
FREELB(fp);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
fp->_flags = 0; /* Release this FILE for reuse. */
+ fp->_file = -1;
fp->_r = fp->_w = 0; /* Mess up if reaccessed. */
return (r);
}
diff --git a/lib/libc/stdio/feof.c b/lib/libc/stdio/feof.c
index 7f58057..e42df61 100644
--- a/lib/libc/stdio/feof.c
+++ b/lib/libc/stdio/feof.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -45,6 +49,7 @@ static char sccsid[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93";
*/
#undef feof
+int
feof(fp)
FILE *fp;
{
diff --git a/lib/libc/stdio/ferror.c b/lib/libc/stdio/ferror.c
index 27ca107..8a68500 100644
--- a/lib/libc/stdio/ferror.c
+++ b/lib/libc/stdio/ferror.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -45,6 +49,7 @@ static char sccsid[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93";
*/
#undef ferror
+int
ferror(fp)
FILE *fp;
{
diff --git a/lib/libc/stdio/fflush.3 b/lib/libc/stdio/fflush.3
index ce3f1b7..abc8c67 100644
--- a/lib/libc/stdio/fflush.3
+++ b/lib/libc/stdio/fflush.3
@@ -99,8 +99,8 @@ for any of the errors specified for the routine
.Xr write 2 .
.Sh SEE ALSO
.Xr write 2 ,
-.Xr fopen 3 ,
.Xr fclose 3 ,
+.Xr fopen 3 ,
.Xr setbuf 3
.Sh STANDARDS
The
diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c
index 4a5cf0f..aed57ec 100644
--- a/lib/libc/stdio/fflush.c
+++ b/lib/libc/stdio/fflush.c
@@ -35,27 +35,46 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <errno.h>
#include <stdio.h>
#include "local.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/* Flush a single file, or (if fp is NULL) all files. */
+int
fflush(fp)
register FILE *fp;
{
+ int retval;
if (fp == NULL)
return (_fwalk(__sflush));
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
if ((fp->_flags & (__SWR | __SRW)) == 0) {
errno = EBADF;
- return (EOF);
+ retval = EOF;
+ } else {
+ retval = __sflush(fp);
}
- return (__sflush(fp));
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return (retval);
}
+int
__sflush(fp)
register FILE *fp;
{
diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c
index 800846c..f93a004 100644
--- a/lib/libc/stdio/fgetc.c
+++ b/lib/libc/stdio/fgetc.c
@@ -35,13 +35,30 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
+int
fgetc(fp)
FILE *fp;
{
- return (__sgetc(fp));
+ int retval;
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
+ retval = __sgetc(fp);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/fgetln.3 b/lib/libc/stdio/fgetln.3
index 60089ea..e6c395d 100644
--- a/lib/libc/stdio/fgetln.3
+++ b/lib/libc/stdio/fgetln.3
@@ -120,4 +120,5 @@ or
.Sh HISTORY
The
.Fn fgetln
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/stdio/fgetln.c b/lib/libc/stdio/fgetln.c
index ec81a2d..7c5742b 100644
--- a/lib/libc/stdio/fgetln.c
+++ b/lib/libc/stdio/fgetln.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -50,6 +54,7 @@ static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94";
* so we add 1 here.
#endif
*/
+int
__slbexpand(fp, newsize)
FILE *fp;
size_t newsize;
@@ -91,7 +96,7 @@ fgetln(fp, lenp)
}
/* look for a newline in the input */
- if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) {
+ if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) {
register char *ret;
/*
@@ -133,7 +138,7 @@ fgetln(fp, lenp)
off = len;
if (__srefill(fp))
break; /* EOF or error: return partial line */
- if ((p = memchr((void *)fp->_p, '\n', fp->_r)) == NULL)
+ if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL)
continue;
/* got it: finish up the line (like code above) */
diff --git a/lib/libc/stdio/fgetpos.c b/lib/libc/stdio/fgetpos.c
index 1f4ec1d..ab8a9e5 100644
--- a/lib/libc/stdio/fgetpos.c
+++ b/lib/libc/stdio/fgetpos.c
@@ -35,14 +35,31 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
+int
fgetpos(fp, pos)
FILE *fp;
fpos_t *pos;
{
- return((*pos = ftell(fp)) == (fpos_t)-1);
+ int retval;
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
+ retval = (*pos = ftell(fp)) == (fpos_t)-1;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return(retval);
}
diff --git a/lib/libc/stdio/fgets.3 b/lib/libc/stdio/fgets.3
index 231e8f2..22ce5e6 100644
--- a/lib/libc/stdio/fgets.3
+++ b/lib/libc/stdio/fgets.3
@@ -45,7 +45,7 @@
.Sh SYNOPSIS
.Fd #include <stdio.h>
.Ft char *
-.Fn fgets "char *str" "size_t size" "FILE *stream"
+.Fn fgets "char *str" "int size" "FILE *stream"
.Ft char *
.Fn gets "char *str"
.Sh DESCRIPTION
@@ -53,7 +53,7 @@ The
.Fn fgets
function
reads at most one less than the number of characters specified by
-.Xr size
+.Fa size
from the given
.Fa stream
and stores them in the string
@@ -61,7 +61,7 @@ and stores them in the string
Reading stops when a newline character is found,
at end-of-file or error.
The newline, if any, is retained.
-In any case a
+If any characters are read and there is no error, a
.Ql \e0
character is appended to end the string.
.Pp
@@ -71,7 +71,7 @@ function
is equivalent to
.Fn fgets
with an infinite
-.Xr size
+.Fa size
and a
.Fa stream
of
@@ -87,14 +87,19 @@ and
.Fn gets
return
a pointer to the string.
-If end-of-file or an error occurs before any characters are read,
+If end-of-file occurs before any characters are read,
they return
-.Dv NULL.
+.Dv NULL
+and the buffer contents is unchanged.
+If an error occurs,
+they return
+.Dv NULL
+and the buffer contents is indeterminate.
The
.Fn fgets
and
-functions
.Fn gets
+functions
do not distinguish between end-of-file and error, and callers must use
.Xr feof 3
and
@@ -128,7 +133,7 @@ for any of the errors specified for the routine
.Sh SEE ALSO
.Xr feof 3 ,
.Xr ferror 3 ,
-.Xr fgetline 3
+.Xr fgetln 3
.Sh STANDARDS
The functions
.Fn fgets
diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c
index 09f6877..434fc07 100644
--- a/lib/libc/stdio/fgets.c
+++ b/lib/libc/stdio/fgets.c
@@ -35,11 +35,20 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <string.h>
+#include "local.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* Read at most n-1 characters from the given file.
@@ -49,16 +58,19 @@ static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93";
char *
fgets(buf, n, fp)
char *buf;
- register size_t n;
+ register int n;
register FILE *fp;
{
register size_t len;
register char *s;
register unsigned char *p, *t;
- if (n == 0) /* sanity check */
+ if (n <= 0) /* sanity check */
return (NULL);
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
s = buf;
n--; /* leave space for NUL */
while (n != 0) {
@@ -68,8 +80,12 @@ fgets(buf, n, fp)
if ((len = fp->_r) <= 0) {
if (__srefill(fp)) {
/* EOF/error: stop with partial or no line */
- if (s == buf)
+ if (s == buf) {
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (NULL);
+ }
break;
}
len = fp->_r;
@@ -91,6 +107,9 @@ fgets(buf, n, fp)
fp->_p = t;
(void)memcpy((void *)s, (void *)p, len);
s[len] = 0;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (buf);
}
fp->_r -= len;
@@ -100,5 +119,8 @@ fgets(buf, n, fp)
n -= len;
}
*s = 0;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (buf);
}
diff --git a/lib/libc/stdio/fileno.c b/lib/libc/stdio/fileno.c
index 91e82e8..6ceac0c 100644
--- a/lib/libc/stdio/fileno.c
+++ b/lib/libc/stdio/fileno.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -45,6 +49,7 @@ static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93";
*/
#undef fileno
+int
fileno(fp)
FILE *fp;
{
diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c
index 64548db..8a6cddd 100644
--- a/lib/libc/stdio/findfp.c
+++ b/lib/libc/stdio/findfp.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)findfp.c 8.2 (Berkeley) 1/4/94";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -66,6 +70,8 @@ FILE __sF[3] = {
};
struct glue __sglue = { &uglue, 3, __sF };
+static struct glue * moreglue __P((int));
+
static struct glue *
moreglue(n)
register int n;
@@ -127,6 +133,10 @@ found:
* XXX. Force immediate allocation of internal memory. Not used by stdio,
* but documented historically for certain applications. Bad applications.
*/
+__warn_references(f_prealloc,
+ "warning: this program uses f_prealloc(), which is stupid.");
+
+void
f_prealloc()
{
register struct glue *g;
diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c
index ee1a76c..4ef0db1 100644
--- a/lib/libc/stdio/flags.c
+++ b/lib/libc/stdio/flags.c
@@ -35,21 +35,27 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)flags.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/file.h>
#include <stdio.h>
#include <errno.h>
+#include "local.h"
/*
* Return the (stdio) flags for a given mode. Store the flags
* to be passed to an open() syscall through *optr.
* Return 0 on error.
*/
+int
__sflags(mode, optr)
- register char *mode;
+ register const char *mode;
int *optr;
{
register int ret, m, o;
diff --git a/lib/libc/stdio/fopen.3 b/lib/libc/stdio/fopen.3
index 23d790c..f954d6c 100644
--- a/lib/libc/stdio/fopen.3
+++ b/lib/libc/stdio/fopen.3
@@ -46,11 +46,11 @@
.Sh SYNOPSIS
.Fd #include <stdio.h>
.Ft FILE *
-.Fn fopen "char *path" "char *mode"
+.Fn fopen "const char *path" "const char *mode"
.Ft FILE *
-.Fn fdopen "int fildes" "char *mode"
+.Fn fdopen "int fildes" "const char *mode"
.Ft FILE *
-.Fn freopen "char *path" "char *mode" "FILE *stream"
+.Fn freopen "const char *path" "const char *mode" "FILE *stream"
.Sh DESCRIPTION
The
.Fn fopen
@@ -73,7 +73,7 @@ The stream is positioned at the beginning of the file.
.It Dq Li w
Truncate file to zero length or create text file for writing.
The stream is positioned at the beginning of the file.
-.No It Dq Li w+
+.It Dq Li w+
Open for reading and writing.
The file is created if it does not exist, otherwise it is truncated.
The stream is positioned at the beginning of the file.
@@ -142,7 +142,7 @@ The original stream (if it exists) is closed.
The
.Fa mode
argument is used just as in the
-.Xr fopen
+.Fn fopen
function.
The primary use of the
.Fn freopen
diff --git a/lib/libc/stdio/fprintf.c b/lib/libc/stdio/fprintf.c
index 479ee24..383f1e1 100644
--- a/lib/libc/stdio/fprintf.c
+++ b/lib/libc/stdio/fprintf.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fprintf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -45,6 +49,7 @@ static char sccsid[] = "@(#)fprintf.c 8.1 (Berkeley) 6/4/93";
#include <varargs.h>
#endif
+int
#if __STDC__
fprintf(FILE *fp, const char *fmt, ...)
#else
diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c
index 3bee513..d1d9e87 100644
--- a/lib/libc/stdio/fpurge.c
+++ b/lib/libc/stdio/fpurge.c
@@ -35,13 +35,21 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* fpurge: like fflush, but without writing anything: leave the
@@ -51,15 +59,23 @@ int
fpurge(fp)
register FILE *fp;
{
+ int retval;
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
if (!fp->_flags) {
errno = EBADF;
- return(EOF);
+ retval = EOF;
+ } else {
+ if (HASUB(fp))
+ FREEUB(fp);
+ fp->_p = fp->_bf._base;
+ fp->_r = 0;
+ fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
+ retval = 0;
}
-
- if (HASUB(fp))
- FREEUB(fp);
- fp->_p = fp->_bf._base;
- fp->_r = 0;
- fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
- return (0);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c
index c86f711..89b138d 100644
--- a/lib/libc/stdio/fputc.c
+++ b/lib/libc/stdio/fputc.c
@@ -35,14 +35,31 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
+int
fputc(c, fp)
int c;
register FILE *fp;
{
- return (putc(c, fp));
+ int retval;
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
+ retval = putc(c, fp);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/fputs.3 b/lib/libc/stdio/fputs.3
index 5578ec2..0961366 100644
--- a/lib/libc/stdio/fputs.3
+++ b/lib/libc/stdio/fputs.3
@@ -95,8 +95,8 @@ may also fail and set
for any of the errors specified for the routines
.Xr write 2 .
.Sh SEE ALSO
-.Xr putc 3 ,
.Xr ferror 3 ,
+.Xr putc 3 ,
.Xr stdio 3
.Sh STANDARDS
The functions
diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c
index 9f9be2e..537c348 100644
--- a/lib/libc/stdio/fputs.c
+++ b/lib/libc/stdio/fputs.c
@@ -35,20 +35,30 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <string.h>
#include "fvwrite.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* Write the given string to the given file.
*/
+int
fputs(s, fp)
const char *s;
FILE *fp;
{
+ int retval;
struct __suio uio;
struct __siov iov;
@@ -56,5 +66,12 @@ fputs(s, fp)
iov.iov_len = uio.uio_resid = strlen(s);
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
- return (__sfvwrite(fp, &uio));
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
+ retval = __sfvwrite(fp, &uio);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/fread.3 b/lib/libc/stdio/fread.3
index 8dd65af..c3e591a 100644
--- a/lib/libc/stdio/fread.3
+++ b/lib/libc/stdio/fread.3
@@ -44,9 +44,9 @@
.Nd binary stream input/output
.Sh SYNOPSIS
.Fd #include <stdio.h>
-.Ft int
+.Ft size_t
.Fn fread "void *ptr" "size_t size" "size_t nmemb" "FILE *stream"
-.Ft int
+.Ft size_t
.Fn fwrite "const void *ptr" "size_t size" "size_t nmemb" "FILE *stream"
.Sh DESCRIPTION
The function
@@ -54,7 +54,7 @@ The function
reads
.Fa nmemb
objects, each
-.Xr size
+.Fa size
bytes long, from the stream pointed to by
.Fa stream ,
storing them at the location given by
diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c
index 22436ec..4f67fbf 100644
--- a/lib/libc/stdio/fread.c
+++ b/lib/libc/stdio/fread.c
@@ -35,11 +35,20 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <string.h>
+#include "local.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
size_t
fread(buf, size, count, fp)
@@ -59,6 +68,9 @@ fread(buf, size, count, fp)
*/
if ((resid = count * size) == 0)
return (0);
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
if (fp->_r < 0)
fp->_r = 0;
total = resid;
@@ -77,5 +89,8 @@ fread(buf, size, count, fp)
(void)memcpy((void *)p, (void *)fp->_p, resid);
fp->_r -= resid;
fp->_p += resid;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (count);
}
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c
index 88dd03c..7a8a3ef 100644
--- a/lib/libc/stdio/freopen.c
+++ b/lib/libc/stdio/freopen.c
@@ -47,8 +47,8 @@ static char sccsid[] = "@(#)freopen.c 8.1 (Berkeley) 6/4/93";
#include <stdlib.h>
#include "local.h"
-/*
- * Re-direct an existing, open (probably) file to some other file.
+/*
+ * Re-direct an existing, open (probably) file to some other file.
* ANSI is written such that the original file gets closed if at
* all possible, no matter what.
*/
diff --git a/lib/libc/stdio/fscanf.c b/lib/libc/stdio/fscanf.c
index f0e726a..8513f80 100644
--- a/lib/libc/stdio/fscanf.c
+++ b/lib/libc/stdio/fscanf.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fscanf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -44,14 +48,20 @@ static char sccsid[] = "@(#)fscanf.c 8.1 (Berkeley) 6/4/93";
#else
#include <varargs.h>
#endif
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
#if __STDC__
+int
fscanf(FILE *fp, char const *fmt, ...) {
int ret;
va_list ap;
va_start(ap, fmt);
#else
+int
fscanf(fp, fmt, va_alist)
FILE *fp;
char *fmt;
@@ -62,7 +72,13 @@ fscanf(fp, fmt, va_alist)
va_start(ap);
#endif
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
ret = __svfscanf(fp, fmt, ap);
va_end(ap);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (ret);
}
diff --git a/lib/libc/stdio/fseek.3 b/lib/libc/stdio/fseek.3
index 4d22276..5dd79e9 100644
--- a/lib/libc/stdio/fseek.3
+++ b/lib/libc/stdio/fseek.3
@@ -56,7 +56,7 @@
.Ft int
.Fn fgetpos "FILE *stream" "fpos_t *pos"
.Ft int
-.Fn fsetpos "FILE *stream" "fpos_t *pos"
+.Fn fsetpos "FILE *stream" "const fpos_t *pos"
.Sh DESCRIPTION
The
.Fn fseek
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c
index 6b0cc8b..c6707df 100644
--- a/lib/libc/stdio/fseek.c
+++ b/lib/libc/stdio/fseek.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -45,6 +49,10 @@ static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
#include <stdlib.h>
#include <errno.h>
#include "local.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
#define POS_ERR (-(fpos_t)1)
@@ -68,6 +76,9 @@ fseek(fp, offset, whence)
if (!__sdidinit)
__sinit();
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
/*
* Have to be able to seek.
*/
@@ -92,8 +103,12 @@ fseek(fp, offset, whence)
curoff = fp->_offset;
else {
curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);
- if (curoff == -1L)
+ if (curoff == -1) {
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (EOF);
+ }
}
if (fp->_flags & __SRD) {
curoff -= fp->_r;
@@ -115,6 +130,9 @@ fseek(fp, offset, whence)
default:
errno = EINVAL;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (EOF);
}
@@ -198,6 +216,9 @@ fseek(fp, offset, whence)
if (HASUB(fp))
FREEUB(fp);
fp->_flags &= ~__SEOF;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (0);
}
@@ -213,6 +234,7 @@ fseek(fp, offset, whence)
if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR)
goto dumb;
fp->_r = 0;
+ fp->_p = fp->_bf._base;
if (HASUB(fp))
FREEUB(fp);
fp->_flags &= ~__SEOF;
@@ -223,6 +245,9 @@ fseek(fp, offset, whence)
fp->_p += n;
fp->_r -= n;
}
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (0);
/*
@@ -232,6 +257,9 @@ fseek(fp, offset, whence)
dumb:
if (__sflush(fp) ||
(*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) {
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (EOF);
}
/* success: clear EOF indicator and discard ungetc() data */
@@ -241,5 +269,8 @@ dumb:
fp->_r = 0;
/* fp->_w = 0; */ /* unnecessary (I think...) */
fp->_flags &= ~__SEOF;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (0);
}
diff --git a/lib/libc/stdio/fsetpos.c b/lib/libc/stdio/fsetpos.c
index 4dace2d..d521a20 100644
--- a/lib/libc/stdio/fsetpos.c
+++ b/lib/libc/stdio/fsetpos.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -43,6 +47,7 @@ static char sccsid[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93";
/*
* fsetpos: like fseek.
*/
+int
fsetpos(iop, pos)
FILE *iop;
const fpos_t *pos;
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index e7a5923..9b85ee0 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -35,12 +35,20 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95";
+#endif
+static const char rcsid[] =
+ "$Id: ftell.c,v 1.7 1997/02/22 15:02:07 peter Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <errno.h>
#include "local.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* ftell: return current offset.
@@ -56,6 +64,9 @@ ftell(fp)
return (-1L);
}
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp, __FILE__, __LINE__);
+#endif
/*
* Find offset of underlying I/O object, then
* adjust for buffered bytes.
@@ -64,8 +75,12 @@ ftell(fp)
pos = fp->_offset;
else {
pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);
- if (pos == -1L)
+ if (pos == -1) {
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (pos);
+ }
}
if (fp->_flags & __SRD) {
/*
@@ -84,5 +99,8 @@ ftell(fp)
*/
pos += fp->_p - fp->_bf._base;
}
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (pos);
}
diff --git a/lib/libc/stdio/funopen.3 b/lib/libc/stdio/funopen.3
index 8ed9b30..90e98d4 100644
--- a/lib/libc/stdio/funopen.3
+++ b/lib/libc/stdio/funopen.3
@@ -44,11 +44,11 @@
.Sh SYNOPSIS
.Fd #include <stdio.h>
.Ft FILE *
-.Fn funopen "void *cookie" "int (*readfn)(void *, char *, int)" "int (writefn*)(void *, const char *, int)" "fpos_t (seekfn*)(void *, fpos_t, int)" "int (closefn*)(void *)"
+.Fn funopen "const void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "fpos_t (*seekfn)(void *, fpos_t, int)" "int (*closefn)(void *)"
.Ft FILE *
.Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)"
.Ft FILE *
-.Fn fwopen "void *cookie" "int (*writefn)(void *, char *, int)"
+.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)"
.Sh DESCRIPTION
The
.Fn funopen
@@ -159,7 +159,8 @@ specified for the routine
.Sh HISTORY
The
.Fn funopen
-functions first appeared in 4.4BSD.
+functions first appeared in
+.Bx 4.4 .
.Sh BUGS
The
.Fn funopen
diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c
index 3ab6279..28db2ba 100644
--- a/lib/libc/stdio/fvwrite.c
+++ b/lib/libc/stdio/fvwrite.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -49,6 +53,7 @@ static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93";
* This routine is large and unsightly, but most of the ugliness due
* to the three different kinds of output buffering is handled here.
*/
+int
__sfvwrite(fp, uio)
register FILE *fp;
register struct __suio *uio;
diff --git a/lib/libc/stdio/fwalk.c b/lib/libc/stdio/fwalk.c
index 7771c41..8f91b46 100644
--- a/lib/libc/stdio/fwalk.c
+++ b/lib/libc/stdio/fwalk.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <errno.h>
@@ -43,8 +47,9 @@ static char sccsid[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93";
#include "local.h"
#include "glue.h"
+int
_fwalk(function)
- register int (*function)();
+ register int (*function)(FILE *);
{
register FILE *fp;
register int n, ret;
diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c
index dbc2e97..ba8540d 100644
--- a/lib/libc/stdio/fwrite.c
+++ b/lib/libc/stdio/fwrite.c
@@ -35,12 +35,20 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include "local.h"
#include "fvwrite.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* Write `count' objects (each size `size') from memory to the given file.
@@ -61,12 +69,18 @@ fwrite(buf, size, count, fp)
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
/*
* The usual case is success (__sfvwrite returns 0);
* skip the divide if this happens, since divides are
* generally slow and since this occurs whenever size==0.
*/
- if (__sfvwrite(fp, &uio) == 0)
- return (count);
- return ((n - uio.uio_resid) / size);
+ if (__sfvwrite(fp, &uio) != 0)
+ count = (n - uio.uio_resid) / size;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return (count);
}
diff --git a/lib/libc/stdio/getc.3 b/lib/libc/stdio/getc.3
index de93a19..0c63fbe 100644
--- a/lib/libc/stdio/getc.3
+++ b/lib/libc/stdio/getc.3
@@ -61,7 +61,7 @@ function
obtains the next input character (if present) from the stream pointed at by
.Fa stream ,
or the next character pushed back on the stream via
-.Xr ungetc .
+.Xr ungetc 3 .
.Pp
The
.Fn getc
@@ -103,11 +103,11 @@ The end-of-file condition is remembered, even on a terminal, and all
subsequent attempts to read will return
.Dv EOF
until the condition is cleared with
-.Xr clearerr .
+.Xr clearerr 3 .
.Sh SEE ALSO
.Xr ferror 3 ,
-.Xr fread 3 ,
.Xr fopen 3 ,
+.Xr fread 3 ,
.Xr putc 3 ,
.Xr ungetc 3
.Sh STANDARDS
@@ -123,9 +123,9 @@ conform to
Since
.Dv EOF
is a valid integer value,
-.Xr feof
+.Xr feof 3
and
-.Xr ferror
+.Xr ferror 3
must be used to check for failure after calling
.Fn getw .
The size and byte order of an
diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c
index 1e900cd..ced796b 100644
--- a/lib/libc/stdio/getc.c
+++ b/lib/libc/stdio/getc.c
@@ -35,18 +35,35 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* A subroutine version of the macro getc.
*/
#undef getc
+int
getc(fp)
register FILE *fp;
{
- return (__sgetc(fp));
+ int retval;
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
+ retval = __sgetc(fp);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c
index 20e52b7..0bcbd3a 100644
--- a/lib/libc/stdio/getchar.c
+++ b/lib/libc/stdio/getchar.c
@@ -35,17 +35,34 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
/*
* A subroutine version of the macro getchar.
*/
#include <stdio.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
#undef getchar
+int
getchar()
{
- return (getc(stdin));
+ int retval;
+#ifdef _THREAD_SAFE
+ _thread_flockfile(stdin,__FILE__,__LINE__);
+#endif
+ retval = getc(stdin);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(stdin);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c
index 0517930..0c821ea 100644
--- a/lib/libc/stdio/gets.c
+++ b/lib/libc/stdio/gets.c
@@ -35,11 +35,18 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)gets.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <unistd.h>
#include <stdio.h>
+#include <sys/cdefs.h>
+
+__warn_references(gets, "warning: this program uses gets(), which is unsafe.");
char *
gets(buf)
@@ -49,7 +56,7 @@ gets(buf)
register char *s;
static int warned;
static char w[] =
- "warning: this program uses gets(), which is unsafe.\r\n";
+ "warning: this program uses gets(), which is unsafe.\n";
if (!warned) {
(void) write(STDERR_FILENO, w, sizeof(w) - 1);
diff --git a/lib/libc/stdio/getw.c b/lib/libc/stdio/getw.c
index 5220290..c72756d 100644
--- a/lib/libc/stdio/getw.c
+++ b/lib/libc/stdio/getw.c
@@ -35,11 +35,16 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)getw.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+int
getw(fp)
FILE *fp;
{
diff --git a/lib/libc/stdio/mktemp.3 b/lib/libc/stdio/mktemp.3
index 361bebf..28a662d 100644
--- a/lib/libc/stdio/mktemp.3
+++ b/lib/libc/stdio/mktemp.3
@@ -124,6 +124,28 @@ may also set
to any value specified by the
.Xr open 2
function.
+.Sh NOTES
+A common problem that results in a core dump is that the programmer
+passes in a read-only string to
+.Fn mktemp
+or
+.Fn mkstemp .
+This is common with programs that were developed before
+.St -ansiC
+compilers were common.
+For example, calling
+.Fn mkstemp
+with an argument of
+.Qq /tmp/tempfile.XXXXXX
+will result in a core dump due to
+.Fn mkstemp
+attempting to modify the string constant that was given.
+If the program in question makes heavy use of that type
+of function call, you do have the option of compiling the program
+so that it will store string constants in a writable segment of memory.
+See
+.Xr gcc 1
+for more information.
.Sh SEE ALSO
.Xr chmod 2 ,
.Xr getpid 2 ,
diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c
index 6cedd6a..19125e6 100644
--- a/lib/libc/stdio/mktemp.c
+++ b/lib/libc/stdio/mktemp.c
@@ -32,7 +32,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id: mktemp.c,v 1.6 1997/02/22 15:02:16 peter Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -41,9 +45,11 @@ static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
+#include <unistd.h>
-static int _gettemp();
+static int _gettemp(char *, int *);
+int
mkstemp(path)
char *path;
{
@@ -59,15 +65,14 @@ mktemp(path)
return(_gettemp(path, (int *)NULL) ? path : (char *)NULL);
}
-static
+static int
_gettemp(path, doopen)
char *path;
register int *doopen;
{
- extern int errno;
register char *start, *trv;
struct stat sbuf;
- u_int pid;
+ pid_t pid;
pid = getpid();
for (trv = path; *trv; ++trv); /* extra X's get set to 0's */
@@ -104,7 +109,7 @@ _gettemp(path, doopen)
if (errno != EEXIST)
return(0);
}
- else if (stat(path, &sbuf))
+ else if (lstat(path, &sbuf))
return(errno == ENOENT ? 1 : 0);
/* tricky little algorithm for backward compatibility */
diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c
index 57a73fc..91a7dee 100644
--- a/lib/libc/stdio/perror.c
+++ b/lib/libc/stdio/perror.c
@@ -50,7 +50,7 @@ perror(s)
struct iovec iov[4];
v = iov;
- if (s && *s) {
+ if (s != NULL) {
v->iov_base = (char *)s;
v->iov_len = strlen(s);
v++;
diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3
index 70f8b99..6d5ad8a 100644
--- a/lib/libc/stdio/printf.3
+++ b/lib/libc/stdio/printf.3
@@ -43,10 +43,12 @@
.Nm fprintf ,
.Nm sprintf ,
.Nm snprintf ,
+.Nm asprintf ,
.Nm vprintf ,
.Nm vfprintf,
.Nm vsprintf ,
-.Nm vsnprintf
+.Nm vsnprintf ,
+.Nm vasprintf
.Nd formatted output conversion
.Sh SYNOPSIS
.Fd #include <stdio.h>
@@ -58,19 +60,19 @@
.Fn sprintf "char *str" "const char *format" ...
.Ft int
.Fn snprintf "char *str" "size_t size" "const char *format" ...
-.\" .Ft int
-.\" .Fn smprintf "const char *format" ...
+.Ft int
+.Fn asprintf "char **ret" "const char *format" ...
.Fd #include <stdarg.h>
.Ft int
.Fn vprintf "const char *format" "va_list ap"
.Ft int
.Fn vfprintf "FILE *stream" "const char *format" "va_list ap"
.Ft int
-.Fn vsprintf "char *str" "char *format" "va_list ap"
+.Fn vsprintf "char *str" "const char *format" "va_list ap"
.Ft int
.Fn vsnprintf "char *str" "size_t size" "const char *format" "va_list ap"
-.\" .Ft int
-.\" .Fn vsmprintf "const char *format" "va_list ap"
+.Ft int
+.Fn vasprintf "char **ret" "const char *format" "va_list ap"
.Sh DESCRIPTION
The
.Fn printf
@@ -94,45 +96,47 @@ write output to the given output
and
.Fn vsnprintf
write to the character string
-.Fa str .
-.\" .IR str ;
-.\" and
-.\" .I smprintf
-.\" and
-.\" .I vsmprintf
-.\" dynamically allocate a new string with
-.\" .IR malloc .
+.Fa str ;
+and
+.Fn asprintf
+and
+.Fn vasprintf
+dynamically allocate a new string with
+.Xr malloc 3
+/
+.Xr realloc 3 .
+.Pp
These functions write the output under the control of a
.Fa format
string that specifies how subsequent arguments
(or arguments accessed via the variable-length argument facilities of
.Xr stdarg 3 )
are converted for output.
-.\" Except for
-.\" .I smprintf
-.\" and
-.\" .IR vsmprintf ,
-.\" all of these functions return
+.Pp
These functions return
the number of characters printed
(not including the trailing
.Ql \e0
used to end output to strings).
-.\" .I Smprintf
-.\" and
-.\" .I vsmprintf
-.\" return a pointer to a string of an appropriate length;
-.\" this pointer should be passed to
-.\" .I free
-.\" to release the associated storage
-.\" when it is no longer needed.
-.\" If sufficient space is not avaliable,
-.\" .I smprintf
-.\" and
-.\" .I vsmprintf
-.\" will return
-.\" .SM
-.\" .BR
+.Pp
+.Fn Asprintf
+and
+.Fn vasprintf
+return a pointer to a buffer sufficiently large to hold the
+string in the
+.Fa ret
+argument;
+This pointer should be passed to
+.Xr free 3
+to release the allocated storage when it is no longer needed.
+If sufficient space cannot be allocated,
+.Fn asprintf
+and
+.Fn vasprintf
+will return -1 and set
+.Fa ret
+to be a NULL pointer.
+.Pp
.Fn Snprintf
and
.Fn vsnprintf
@@ -147,6 +151,7 @@ if the return value is greater than or equal to the
.Fa size
argument, the string was too short
and some of the printed characters were discarded.
+.Pp
.Fn Sprintf
and
.Fn vsprintf
@@ -171,6 +176,16 @@ After the
the following appear in sequence:
.Bl -bullet
.It
+An optional field, consisting of a decimal digit string followed by a
+.Cm $ ,
+specifying the next argument to access .
+If this field is not provided, the argument following the last
+argument accessed will be used.
+Arguments are numbered starting at
+.Cm 1 .
+If unaccessed arguments in the format string are interspersed with ones that
+are accessed the results will be indeterminate.
+.It
Zero or more of the following flags:
.Bl -hyphen
.It
@@ -228,7 +243,7 @@ For all conversions except
.Cm n ,
the converted value is padded on the left with zeros rather than blanks.
If a precision is given with a numeric conversion
-.Pf ( Mc d ,
+.Pf ( Cm d ,
.Cm i ,
.Cm o ,
.Cm u ,
@@ -389,6 +404,8 @@ A character that specifies the type of conversion to be applied.
A field width or precision, or both, may be indicated by
an asterisk
.Ql *
+or an asterisk followed by one or more decimal digits and a
+.Ql $
instead of a
digit string.
In this case, an
@@ -397,6 +414,8 @@ argument supplies the field width or precision.
A negative field width is treated as a left adjustment flag followed by a
positive field width; a negative precision is treated as though it were
missing.
+If a single format directive mixes positional (nn$)
+and non-positional arguments, the results are undefined.
.Pp
The conversion specifiers and their meanings are:
.Bl -tag -width "diouxX"
@@ -422,7 +441,7 @@ are used for
conversions; the letters
.Cm ABCDEF
are used for
-.m X
+.Cm X
conversions.
The precision, if any, gives the minimum number of digits that must
appear; if the converted value requires fewer digits, it is padded on
@@ -600,6 +619,15 @@ The functions
and
.Fn vsnprintf
are new to this release.
+.Pp
+The functions
+.Fn asprintf
+and
+.Fn vasprintf
+first appeared in the GNU C library. This implementation is thought
+to be compatable but is not derived from the GNU code. This implementation
+was written by Peter Wemm <peter@FreeBSD.org> and first appeared in
+.Fx 2.2 .
.Sh BUGS
The conversion formats
.Cm \&%D ,
@@ -631,7 +659,7 @@ and
.Fn vsprintf
assume an infinitely long string,
callers must be careful not to overflow the actual space;
-this is often impossible to assure.
+this is often hard to assure.
For safety, programmers should use the
.Fn snprintf
interface instead.
diff --git a/lib/libc/stdio/printf.c b/lib/libc/stdio/printf.c
index eb6ae83..9711549 100644
--- a/lib/libc/stdio/printf.c
+++ b/lib/libc/stdio/printf.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)printf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -45,6 +49,7 @@ static char sccsid[] = "@(#)printf.c 8.1 (Berkeley) 6/4/93";
#include <varargs.h>
#endif
+int
#if __STDC__
printf(char const *fmt, ...)
#else
diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c
index c18353b..a1b0814 100644
--- a/lib/libc/stdio/putc.c
+++ b/lib/libc/stdio/putc.c
@@ -35,19 +35,36 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* A subroutine version of the macro putc.
*/
#undef putc
+int
putc(c, fp)
int c;
register FILE *fp;
{
- return (__sputc(c, fp));
+ int retval;
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
+ retval = __sputc(c, fp);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c
index 036b897..99439ac 100644
--- a/lib/libc/stdio/putchar.c
+++ b/lib/libc/stdio/putchar.c
@@ -35,20 +35,37 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
#undef putchar
/*
* A subroutine version of the macro putchar
*/
+int
putchar(c)
int c;
{
+ int retval;
register FILE *so = stdout;
- return (__sputc(c, so));
+#ifdef _THREAD_SAFE
+ _thread_flockfile(so,__FILE__,__LINE__);
+#endif
+ retval = __sputc(c, so);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(so);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/puts.c b/lib/libc/stdio/puts.c
index 96a8184..91a20de 100644
--- a/lib/libc/stdio/puts.c
+++ b/lib/libc/stdio/puts.c
@@ -35,19 +35,29 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)puts.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <string.h>
#include "fvwrite.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* Write the given string to stdout, appending a newline.
*/
+int
puts(s)
char const *s;
{
+ int retval;
size_t c = strlen(s);
struct __suio uio;
struct __siov iov[2];
@@ -59,5 +69,12 @@ puts(s)
uio.uio_resid = c + 1;
uio.uio_iov = &iov[0];
uio.uio_iovcnt = 2;
- return (__sfvwrite(stdout, &uio) ? EOF : '\n');
+#ifdef _THREAD_SAFE
+ _thread_flockfile(stdout,__FILE__,__LINE__);
+#endif
+ retval = __sfvwrite(stdout, &uio) ? EOF : '\n';
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(stdout);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/putw.c b/lib/libc/stdio/putw.c
index 4ba8982..946a311 100644
--- a/lib/libc/stdio/putw.c
+++ b/lib/libc/stdio/putw.c
@@ -35,16 +35,26 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)putw.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include "fvwrite.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
+int
putw(w, fp)
int w;
FILE *fp;
{
+ int retval;
struct __suio uio;
struct __siov iov;
@@ -52,5 +62,12 @@ putw(w, fp)
iov.iov_len = uio.uio_resid = sizeof(w);
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
- return (__sfvwrite(fp, &uio));
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
+ retval = __sfvwrite(fp, &uio);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/refill.c b/lib/libc/stdio/refill.c
index 35af0c0..f0583f7 100644
--- a/lib/libc/stdio/refill.c
+++ b/lib/libc/stdio/refill.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <errno.h>
@@ -43,12 +47,14 @@ static char sccsid[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93";
#include <stdlib.h>
#include "local.h"
-static
+static int lflush __P((FILE *));
+
+static int
lflush(fp)
FILE *fp;
{
- if ((fp->_flags & (__SLBF|__SWR)) == __SLBF|__SWR)
+ if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
return (__sflush(fp));
return (0);
}
@@ -57,6 +63,7 @@ lflush(fp)
* Refill a stdio buffer.
* Return EOF on eof or error, 0 otherwise.
*/
+int
__srefill(fp)
register FILE *fp;
{
diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c
index 216535a..6a25563 100644
--- a/lib/libc/stdio/remove.c
+++ b/lib/libc/stdio/remove.c
@@ -35,12 +35,17 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <unistd.h>
#include <stdio.h>
+int
remove(file)
const char *file;
{
diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c
index 4f8391b..f6609d6 100644
--- a/lib/libc/stdio/rewind.c
+++ b/lib/libc/stdio/rewind.c
@@ -35,17 +35,31 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)rewind.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <errno.h>
#include <stdio.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
void
rewind(fp)
register FILE *fp;
{
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
(void) fseek(fp, 0L, SEEK_SET);
clearerr(fp);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
errno = 0; /* not required, but seems reasonable */
}
diff --git a/lib/libc/stdio/rget.c b/lib/libc/stdio/rget.c
index 3299fb5..45d817d 100644
--- a/lib/libc/stdio/rget.c
+++ b/lib/libc/stdio/rget.c
@@ -35,17 +35,25 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)rget.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+#include "local.h"
+
+int
+__srefill(FILE *);
/*
* Handle getc() when the buffer ran out:
* Refill, then return the first character
* in the newly-filled buffer.
*/
-__srget(fp)
+int __srget(fp)
register FILE *fp;
{
if (__srefill(fp) == 0) {
diff --git a/lib/libc/stdio/scanf.3 b/lib/libc/stdio/scanf.3
index 377a602..a9bbc41 100644
--- a/lib/libc/stdio/scanf.3
+++ b/lib/libc/stdio/scanf.3
@@ -171,6 +171,15 @@ and the next pointer is a pointer to
(This type is not implemented; the
.Cm L
flag is currently ignored.)
+.It Cm q
+Indicates either that the conversion will be one of
+.Cm dioux
+or
+.Cm n
+and the next pointer is a pointer to a
+.Em long long int
+(rather than
+.Em int ) ,
.El
.Pp
In addition to these flags,
@@ -200,7 +209,7 @@ the next pointer must be a pointer to
.Em int .
.It Cm D
Equivalent to
-.Xr ld ;
+.Cm ld ;
this exists only for backwards compatibility.
.It Cm i
Matches an optionally signed integer;
@@ -221,7 +230,7 @@ the next pointer must be a pointer to
.Em unsigned int .
.It Cm O
Equivalent to
-.Xr lo ;
+.Cm lo ;
this exists for backwards compatibility.
.It Cm u
Matches an optionally signed decimal integer;
@@ -391,11 +400,11 @@ end-of-file occurs. If an error or end-of-file occurs after conversion
has begun,
the number of conversions which were successfully completed is returned.
.Sh SEE ALSO
-.Xr strtol 3 ,
-.Xr strtoul 3 ,
-.Xr strtod 3 ,
.Xr getc 3 ,
-.Xr printf 3
+.Xr printf 3 ,
+.Xr strtod 3 ,
+.Xr strtol 3 ,
+.Xr strtoul 3
.Sh STANDARDS
The functions
.Fn fscanf ,
diff --git a/lib/libc/stdio/scanf.c b/lib/libc/stdio/scanf.c
index d36b13a..7a8bd65 100644
--- a/lib/libc/stdio/scanf.c
+++ b/lib/libc/stdio/scanf.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -44,10 +48,16 @@ static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93";
#else
#include <varargs.h>
#endif
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
#if __STDC__
+int
scanf(char const *fmt, ...)
#else
+int
scanf(fmt, va_alist)
char *fmt;
va_dcl
@@ -61,7 +71,13 @@ scanf(fmt, va_alist)
#else
va_start(ap);
#endif
+#ifdef _THREAD_SAFE
+ _thread_flockfile(stdin,__FILE__,__LINE__);
+#endif
ret = __svfscanf(stdin, fmt, ap);
va_end(ap);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(stdin);
+#endif
return (ret);
}
diff --git a/lib/libc/stdio/setbuf.3 b/lib/libc/stdio/setbuf.3
index 30e9db7..ec5bbd8 100644
--- a/lib/libc/stdio/setbuf.3
+++ b/lib/libc/stdio/setbuf.3
@@ -49,7 +49,7 @@
.Ft void
.Fn setbuf "FILE *stream" "char *buf"
.Ft void
-.Fn setbuffer "FILE *stream" "char *buf" "size_t size"
+.Fn setbuffer "FILE *stream" "char *buf" "int size"
.Ft int
.Fn setlinebuf "FILE *stream"
.Ft int
@@ -170,12 +170,12 @@ function returns what the equivalent
.Fn setvbuf
would have returned.
.Sh SEE ALSO
-.Xr fopen 3 ,
.Xr fclose 3 ,
+.Xr fopen 3 ,
.Xr fread 3 ,
.Xr malloc 3 ,
-.Xr puts 3 ,
-.Xr printf 3
+.Xr printf 3 ,
+.Xr puts 3
.Sh STANDARDS
The
.Fn setbuf
diff --git a/lib/libc/stdio/setbuffer.c b/lib/libc/stdio/setbuffer.c
index a6d06dd..d272177 100644
--- a/lib/libc/stdio/setbuffer.c
+++ b/lib/libc/stdio/setbuffer.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)setbuffer.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -47,7 +51,7 @@ setbuffer(fp, buf, size)
int size;
{
- (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, size);
+ (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size);
}
/*
diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c
index 867f9b4..9cc6bb6 100644
--- a/lib/libc/stdio/setvbuf.c
+++ b/lib/libc/stdio/setvbuf.c
@@ -35,17 +35,26 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)setvbuf.c 8.2 (Berkeley) 11/16/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* Set one of the three kinds of buffering, optionally including
* a buffer.
*/
+int
setvbuf(fp, buf, mode, size)
register FILE *fp;
char *buf;
@@ -65,6 +74,9 @@ setvbuf(fp, buf, mode, size)
if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0)
return (EOF);
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
/*
* Write current buffer, if any. Discard unread input (including
* ungetc data), cancel line buffering, and free old buffer if
@@ -116,6 +128,9 @@ nbf:
fp->_w = 0;
fp->_bf._base = fp->_p = fp->_nbuf;
fp->_bf._size = 1;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (ret);
}
flags |= __SMBF;
@@ -156,5 +171,8 @@ nbf:
}
__cleanup = _cleanup;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (ret);
}
diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c
index 3c3cf7d..0e3c456 100644
--- a/lib/libc/stdio/snprintf.c
+++ b/lib/libc/stdio/snprintf.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -46,8 +50,10 @@ static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
#endif
#if __STDC__
+int
snprintf(char *str, size_t n, char const *fmt, ...)
#else
+int
snprintf(str, n, fmt, va_alist)
char *str;
size_t n;
@@ -66,6 +72,7 @@ snprintf(str, n, fmt, va_alist)
#else
va_start(ap);
#endif
+ f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n - 1;
diff --git a/lib/libc/stdio/sprintf.c b/lib/libc/stdio/sprintf.c
index 254064f..fb0514d 100644
--- a/lib/libc/stdio/sprintf.c
+++ b/lib/libc/stdio/sprintf.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)sprintf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -47,6 +51,7 @@ static char sccsid[] = "@(#)sprintf.c 8.1 (Berkeley) 6/4/93";
#include <limits.h>
#include "local.h"
+int
#if __STDC__
sprintf(char *str, char const *fmt, ...)
#else
@@ -60,6 +65,7 @@ sprintf(str, fmt, va_alist)
va_list ap;
FILE f;
+ f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = INT_MAX;
diff --git a/lib/libc/stdio/sscanf.c b/lib/libc/stdio/sscanf.c
index bb72744..d114ae3 100644
--- a/lib/libc/stdio/sscanf.c
+++ b/lib/libc/stdio/sscanf.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)sscanf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -47,6 +51,8 @@ static char sccsid[] = "@(#)sscanf.c 8.1 (Berkeley) 6/4/93";
#endif
#include "local.h"
+static int eofread __P((void *, char *, int));
+
/* ARGSUSED */
static int
eofread(cookie, buf, len)
@@ -59,8 +65,10 @@ eofread(cookie, buf, len)
}
#if __STDC__
+int
sscanf(const char *str, char const *fmt, ...)
#else
+int
sscanf(str, fmt, va_alist)
char *str;
char *fmt;
@@ -71,6 +79,7 @@ sscanf(str, fmt, va_alist)
va_list ap;
FILE f;
+ f._file = -1;
f._flags = __SRD;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._r = strlen(str);
diff --git a/lib/libc/stdio/stdio.3 b/lib/libc/stdio/stdio.3
index 572df8c..81a6970 100644
--- a/lib/libc/stdio/stdio.3
+++ b/lib/libc/stdio/stdio.3
@@ -48,7 +48,7 @@ The standard
library provides a simple and efficient buffered stream
.Tn I/O
interface.
-Input and ouput is mapped into logical data streams
+Input and output is mapped into logical data streams
and the physical
.Tn I/O
characteristics are concealed. The functions and macros are listed
@@ -63,13 +63,13 @@ If a file can support positioning requests (such as a disk file, as opposed
to a terminal) then a
.Em file position indicator
associated with the stream is positioned at the start of the file (byte
-zero), unless the file is opened with appended mode. If append mode
+zero), unless the file is opened with append mode. If append mode
is used, the position indicator will be placed the end-of-file.
The position indicator is maintained by subsequent reads, writes
and positioning requests. All input occurs as if the characters
were read by successive calls to the
.Xr fgetc 3
-function; all ouput takes place as if all characters were
+function; all output takes place as if all characters were
read by successive calls to the
.Xr fputc 3
function.
@@ -77,7 +77,7 @@ function.
A file is disassociated from a stream by
.Em closing
the file.
-Ouput streams are flushed (any unwritten buffer contents are transferred
+Output streams are flushed (any unwritten buffer contents are transferred
to the host environment) before the stream is disassociated from the file.
The value of a pointer to a
.Dv FILE
@@ -111,7 +111,7 @@ opened explicitly:
(for reading conventional input),
.It
.Em standard output
-(for writing conventional input), and
+(for writing conventional output), and
.It
.Em standard error
(for writing diagnostic output).
@@ -151,7 +151,7 @@ function.
The
.Nm stdio
library is a part of the library
-.Xr libc
+.Nm libc
and routines are automatically loaded as needed by the compilers
.Xr cc 1
and
@@ -169,7 +169,7 @@ without first removing their current definitions with
.Dv BUFSIZ ,
.Dv EOF ,
.Dv FILENAME_MAX ,
-.DV FOPEN_MAX ,
+.Dv FOPEN_MAX ,
.Dv L_cuserid ,
.Dv L_ctermid ,
.Dv L_tmpnam,
@@ -192,28 +192,28 @@ without first removing their current definitions with
.Dv stdin ,
.Dv stdout .
Function versions of the macro functions
-.Xr feof ,
-.Xr ferror ,
-.Xr clearerr ,
-.Xr fileno ,
-.Xr getc ,
-.Xr getchar ,
-.Xr putc ,
+.Fn feof ,
+.Fn ferror ,
+.Fn clearerr ,
+.Fn fileno ,
+.Fn getc ,
+.Fn getchar ,
+.Fn putc ,
and
-.Xr putchar
+.Fn putchar
exist and will be used if the macros
definitions are explicitly removed.
.Sh SEE ALSO
-.Xr open 2 ,
.Xr close 2 ,
+.Xr open 2 ,
.Xr read 2 ,
.Xr write 2
.Sh BUGS
The standard buffered functions do not interact well with certain other
library and system functions, especially
-.Xr vfork
+.Xr vfork 2
and
-.Xr abort .
+.Xr abort 3 .
.Sh STANDARDS
The
.Nm stdio
@@ -229,7 +229,7 @@ feof check and reset stream status
ferror check and reset stream status
fflush flush a stream
fgetc get next character or word from input stream
-fgetline get a line from a stream
+fgetln get a line from a stream
fgetpos reposition a stream
fgets get a line from a stream
fileno check and reset stream status
diff --git a/lib/libc/stdio/stdio.c b/lib/libc/stdio/stdio.c
index 7899387..852e971 100644
--- a/lib/libc/stdio/stdio.c
+++ b/lib/libc/stdio/stdio.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <fcntl.h>
@@ -47,6 +51,7 @@ static char sccsid[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93";
* Small standard I/O/seek/close functions.
* These maintain the `known seek offset' for seek optimisation.
*/
+int
__sread(cookie, buf, n)
void *cookie;
char *buf;
@@ -54,8 +59,8 @@ __sread(cookie, buf, n)
{
register FILE *fp = cookie;
register int ret;
-
- ret = read(fp->_file, buf, n);
+
+ ret = read(fp->_file, buf, (size_t)n);
/* if the read succeeded, update the current offset */
if (ret >= 0)
fp->_offset += ret;
@@ -64,6 +69,7 @@ __sread(cookie, buf, n)
return (ret);
}
+int
__swrite(cookie, buf, n)
void *cookie;
char const *buf;
@@ -74,7 +80,7 @@ __swrite(cookie, buf, n)
if (fp->_flags & __SAPP)
(void) lseek(fp->_file, (off_t)0, SEEK_END);
fp->_flags &= ~__SOFF; /* in case FAPPEND mode is set */
- return (write(fp->_file, buf, n));
+ return (write(fp->_file, buf, (size_t)n));
}
fpos_t
@@ -85,9 +91,9 @@ __sseek(cookie, offset, whence)
{
register FILE *fp = cookie;
register off_t ret;
-
+
ret = lseek(fp->_file, (off_t)offset, whence);
- if (ret == -1L)
+ if (ret == -1)
fp->_flags &= ~__SOFF;
else {
fp->_flags |= __SOFF;
@@ -96,6 +102,7 @@ __sseek(cookie, offset, whence)
return (ret);
}
+int
__sclose(cookie)
void *cookie;
{
diff --git a/lib/libc/stdio/tempnam.c b/lib/libc/stdio/tempnam.c
index 6644ae5..243fa39 100644
--- a/lib/libc/stdio/tempnam.c
+++ b/lib/libc/stdio/tempnam.c
@@ -32,13 +32,18 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <paths.h>
@@ -55,28 +60,28 @@ tempnam(dir, pfx)
if (!pfx)
pfx = "tmp.";
- if (f = getenv("TMPDIR")) {
+ if ((f = getenv("TMPDIR"))) {
(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
*(f + strlen(f) - 1) == '/'? "": "/", pfx);
- if (f = mktemp(name))
+ if ((f = mktemp(name)))
return(f);
}
- if (f = (char *)dir) {
+ if ((f = (char *)dir)) {
(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
*(f + strlen(f) - 1) == '/'? "": "/", pfx);
- if (f = mktemp(name))
+ if ((f = mktemp(name)))
return(f);
}
f = P_tmpdir;
(void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
- if (f = mktemp(name))
+ if ((f = mktemp(name)))
return(f);
f = _PATH_TMP;
(void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
- if (f = mktemp(name))
+ if ((f = mktemp(name)))
return(f);
sverrno = errno;
diff --git a/lib/libc/stdio/tmpnam.3 b/lib/libc/stdio/tmpnam.3
index 3b053ee..d7e0326 100644
--- a/lib/libc/stdio/tmpnam.3
+++ b/lib/libc/stdio/tmpnam.3
@@ -201,7 +201,7 @@ Second, most historic implementations provide only a limited number
of possible temporary file names (usually 26) before file names will
start being recycled.
Third, the System V implementations of these functions (and of
-.Xr mktemp )
+.Xr mktemp 3 )
use the
.Xr access 2
function to determine whether or not the temporary file may be created.
diff --git a/lib/libc/stdio/ungetc.3 b/lib/libc/stdio/ungetc.3
index e88b64f..e5c68d0 100644
--- a/lib/libc/stdio/ungetc.3
+++ b/lib/libc/stdio/ungetc.3
@@ -85,8 +85,8 @@ character equals
.Dv EOF ,
the operation will fail and the stream will remain unchanged.
.Sh SEE ALSO
-.Xr getc 3 ,
.Xr fseek 3 ,
+.Xr getc 3 ,
.Xr setvbuf 3
.Sh STANDARDS
The
diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c
index deaed75..c0355b7 100644
--- a/lib/libc/stdio/ungetc.c
+++ b/lib/libc/stdio/ungetc.c
@@ -35,13 +35,23 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "local.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
+
+static int __submore __P((FILE *));
/*
* Expand the ungetc buffer `in place'. That is, adjust fp->_p when
@@ -49,7 +59,7 @@ static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93";
* and move the bytes in the buffer around as necessary so that they
* are all at the end (stack-style).
*/
-static
+static int
__submore(fp)
register FILE *fp;
{
@@ -71,7 +81,7 @@ __submore(fp)
return (0);
}
i = fp->_ub._size;
- p = realloc(fp->_ub._base, i << 1);
+ p = realloc(fp->_ub._base, (size_t)(i << 1));
if (p == NULL)
return (EOF);
/* no overlap (hence can use memcpy) because we doubled the size */
@@ -82,6 +92,7 @@ __submore(fp)
return (0);
}
+int
ungetc(c, fp)
int c;
register FILE *fp;
@@ -90,16 +101,27 @@ ungetc(c, fp)
return (EOF);
if (!__sdidinit)
__sinit();
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
if ((fp->_flags & __SRD) == 0) {
/*
* Not already reading: no good unless reading-and-writing.
* Otherwise, flush any current write stuff.
*/
- if ((fp->_flags & __SRW) == 0)
+ if ((fp->_flags & __SRW) == 0) {
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (EOF);
+ }
if (fp->_flags & __SWR) {
- if (__sflush(fp))
+ if (__sflush(fp)) {
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (EOF);
+ }
fp->_flags &= ~__SWR;
fp->_w = 0;
fp->_lbfsize = 0;
@@ -113,10 +135,17 @@ ungetc(c, fp)
* This may require expanding the current ungetc buffer.
*/
if (HASUB(fp)) {
- if (fp->_r >= fp->_ub._size && __submore(fp))
+ if (fp->_r >= fp->_ub._size && __submore(fp)) {
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (EOF);
+ }
*--fp->_p = c;
fp->_r++;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (c);
}
fp->_flags &= ~__SEOF;
@@ -130,6 +159,9 @@ ungetc(c, fp)
fp->_p[-1] == c) {
fp->_p--;
fp->_r++;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (c);
}
@@ -144,5 +176,8 @@ ungetc(c, fp)
fp->_ubuf[sizeof(fp->_ubuf) - 1] = c;
fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1];
fp->_r = 1;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (c);
}
diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c
new file mode 100644
index 0000000..8030e11
--- /dev/null
+++ b/lib/libc/stdio/vasprintf.c
@@ -0,0 +1,119 @@
+/*-
+ * Copyright (c) 1996 Peter Wemm <peter@freebsd.org>
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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_RCS) && !defined(lint)
+static char rcsid[] = "$Id$";
+#endif /* LIBC_RCS and not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+#define CHUNK_SPARE 128 /* how much spare to allocate to avoid realloc calls */
+
+struct bufcookie {
+ char *base; /* start of buffer */
+ size_t size;
+ size_t left;
+};
+
+static int writehook __P((void *cookie, const char *, int));
+
+static int
+writehook(cookie, buf, len)
+ void *cookie;
+ const char *buf;
+ int len;
+{
+ struct bufcookie *h = (struct bufcookie *)cookie;
+ char *newbuf;
+
+ if (len == 0)
+ return 0;
+
+ if (len > h->left) {
+ /* grow malloc region */
+ /*
+ * XXX this is linearly expanded, which is slow for obscenely
+ * large strings.
+ */
+ h->left = h->left + len + CHUNK_SPARE;
+ h->size = h->size + len + CHUNK_SPARE;
+ newbuf = realloc(h->base, h->size);
+ if (newbuf == NULL) {
+ free(h->base);
+ h->base = NULL;
+ return (-1);
+ } else
+ h->base = newbuf;
+ }
+ /* "write" it */
+ (void)memcpy(h->base + h->size - h->left, buf, (size_t)len);
+ h->left -= len;
+ return (len);
+}
+
+
+int
+vasprintf(str, fmt, ap)
+ char **str;
+ const char *fmt;
+ va_list ap;
+{
+ int ret;
+ FILE *f;
+ struct bufcookie h;
+
+ h.base = malloc(CHUNK_SPARE);
+ if (h.base == NULL)
+ return (-1);
+ h.size = CHUNK_SPARE;
+ h.left = CHUNK_SPARE;
+
+ f = funopen(&h, NULL, writehook, NULL, NULL);
+ if (f == NULL) {
+ free(h.base);
+ return (-1);
+ }
+ ret = vfprintf(f, fmt, ap);
+ fclose(f);
+ if (ret < 0) {
+ free(h.base);
+ return (-1);
+ }
+ if (h.base == NULL) /* failed to realloc in writehook */
+ return (-1);
+
+ h.base[h.size - h.left] = '\0';
+ *str = realloc(h.base, (size_t)(h.size - h.left + 1));
+ if (*str == NULL) /* failed to realloc it to actual size */
+ *str = h.base; /* return oversize buffer */
+ return (ret);
+}
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index 3610e10..61dba47 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
/*
@@ -59,10 +63,21 @@ static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
#include "local.h"
#include "fvwrite.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/* Define FLOATING_POINT to get floating point. */
#define FLOATING_POINT
+static int __sprint __P((FILE *, struct __suio *));
+static int __sbprintf __P((FILE *, const char *, va_list));
+static char * __ultoa __P((u_long, char *, int, int, char *));
+static char * __uqtoa __P((u_quad_t, char *, int, int, char *));
+static void __find_arguments __P((const char *, va_list, void ***));
+static void __grow_type_table __P((int, unsigned char **, int *));
+
/*
* Flush out all the vectors defined by the given uio,
* then reset it so that it can be reused.
@@ -261,6 +276,7 @@ static int exponent __P((char *, int, int));
#endif /* FLOATING_POINT */
+#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */
/*
* Flags used during conversion.
@@ -282,7 +298,7 @@ vfprintf(fp, fmt0, ap)
{
register char *fmt; /* format string */
register int ch; /* character from fmt */
- register int n; /* handy integer (short term usage) */
+ register int n, n2; /* handy integer (short term usage) */
register char *cp; /* handy char pointer (short term usage) */
register struct __siov *iovp;/* for PRINT macro */
register int flags; /* flags as above */
@@ -302,8 +318,7 @@ vfprintf(fp, fmt0, ap)
u_quad_t uqval; /* %q integers */
int base; /* base for [diouxX] conversion */
int dprec; /* a copy of prec if [diouxX], 0 otherwise */
- int fieldsz; /* field size expanded by sign, etc */
- int realsz; /* field size expanded by dprec */
+ int realsz; /* field size expanded by dprec, sign, etc */
int size; /* size of converted field or string */
char *xdigs; /* digits for [xX] conversion */
#define NIOV 8
@@ -311,6 +326,10 @@ vfprintf(fp, fmt0, ap)
struct __siov iov[NIOV];/* ... and individual io vectors */
char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
char ox[2]; /* space for 0x hex-prefix */
+ void **argtable; /* args, built due to positional arg */
+ void *statargtable [STATIC_ARG_TBL_SIZE];
+ int nextarg; /* 1-based argument index */
+ va_list orgap; /* original argument pointer */
/*
* Choose PADSIZE to trade efficiency vs. size. If larger printf
@@ -353,29 +372,78 @@ vfprintf(fp, fmt0, ap)
iovp = iov; \
}
+ /*
+ * Get the argument indexed by nextarg. If the argument table is
+ * built, use it to get the argument. If its not, get the next
+ * argument (and arguments must be gotten sequentially).
+ */
+#define GETARG(type) \
+ ((argtable != NULL) ? *((type*)(argtable[nextarg++])) : \
+ (nextarg++, va_arg(ap, type)))
+
/*
* To extend shorts properly, we need both signed and unsigned
* argument extraction methods.
*/
#define SARG() \
- (flags&LONGINT ? va_arg(ap, long) : \
- flags&SHORTINT ? (long)(short)va_arg(ap, int) : \
- (long)va_arg(ap, int))
+ (flags&LONGINT ? GETARG(long) : \
+ flags&SHORTINT ? (long)(short)GETARG(int) : \
+ (long)GETARG(int))
#define UARG() \
- (flags&LONGINT ? va_arg(ap, u_long) : \
- flags&SHORTINT ? (u_long)(u_short)va_arg(ap, int) : \
- (u_long)va_arg(ap, u_int))
+ (flags&LONGINT ? GETARG(u_long) : \
+ flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \
+ (u_long)GETARG(u_int))
+
+ /*
+ * Get * arguments, including the form *nn$. Preserve the nextarg
+ * that the argument can be gotten once the type is determined.
+ */
+#define GETASTER(val) \
+ n2 = 0; \
+ cp = fmt; \
+ while (is_digit(*cp)) { \
+ n2 = 10 * n2 + to_digit(*cp); \
+ cp++; \
+ } \
+ if (*cp == '$') { \
+ int hold = nextarg; \
+ if (argtable == NULL) { \
+ argtable = statargtable; \
+ __find_arguments (fmt0, orgap, &argtable); \
+ } \
+ nextarg = n2; \
+ val = GETARG (int); \
+ nextarg = hold; \
+ fmt = ++cp; \
+ } else { \
+ val = GETARG (int); \
+ }
+
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
- if (cantwrite(fp))
+ if (cantwrite(fp)) {
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (EOF);
+ }
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
- fp->_file >= 0)
+ fp->_file >= 0) {
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
return (__sbprintf(fp, fmt0, ap));
+ }
fmt = (char *)fmt0;
+ argtable = NULL;
+ nextarg = 1;
+ orgap = ap;
uio.uio_iov = iovp = iov;
uio.uio_resid = 0;
uio.uio_iovcnt = 0;
@@ -422,7 +490,8 @@ reswitch: switch (ch) {
* -- ANSI X3J11
* They don't exclude field widths read from args.
*/
- if ((width = va_arg(ap, int)) >= 0)
+ GETASTER (width);
+ if (width >= 0)
goto rflag;
width = -width;
/* FALLTHROUGH */
@@ -434,7 +503,7 @@ reswitch: switch (ch) {
goto rflag;
case '.':
if ((ch = *fmt++) == '*') {
- n = va_arg(ap, int);
+ GETASTER (n);
prec = n < 0 ? -1 : n;
goto rflag;
}
@@ -460,6 +529,15 @@ reswitch: switch (ch) {
n = 10 * n + to_digit(ch);
ch = *fmt++;
} while (is_digit(ch));
+ if (ch == '$') {
+ nextarg = n;
+ if (argtable == NULL) {
+ argtable = statargtable;
+ __find_arguments (fmt0, orgap,
+ &argtable);
+ }
+ goto rflag;
+ }
width = n;
goto reswitch;
#ifdef FLOATING_POINT
@@ -477,7 +555,7 @@ reswitch: switch (ch) {
flags |= QUADINT;
goto rflag;
case 'c':
- *(cp = buf) = va_arg(ap, int);
+ *(cp = buf) = GETARG(int);
size = 1;
sign = '\0';
break;
@@ -487,7 +565,7 @@ reswitch: switch (ch) {
case 'd':
case 'i':
if (flags & QUADINT) {
- uqval = va_arg(ap, quad_t);
+ uqval = GETARG(quad_t);
if ((quad_t)uqval < 0) {
uqval = -uqval;
sign = '-';
@@ -502,20 +580,20 @@ reswitch: switch (ch) {
base = 10;
goto number;
#ifdef FLOATING_POINT
- case 'e': /* anomalous precision */
+ case 'e':
case 'E':
- prec = (prec == -1) ?
- DEFPREC + 1 : prec + 1;
- /* FALLTHROUGH */
+ case 'f':
goto fp_begin;
- case 'f': /* always print trailing zeroes */
- if (prec != 0)
- flags |= ALT;
case 'g':
case 'G':
- if (prec == -1)
+ if (prec == 0)
+ prec = 1;
+fp_begin: if (prec == -1)
prec = DEFPREC;
-fp_begin: _double = va_arg(ap, double);
+ if (flags & LONGDBL)
+ _double = (double)GETARG(long double);
+ else
+ _double = GETARG(double);
/* do this before tricky precision changes */
if (isinf(_double)) {
if (_double < 0)
@@ -537,7 +615,7 @@ fp_begin: _double = va_arg(ap, double);
ch = (ch == 'g') ? 'e' : 'E';
else
ch = 'g';
- }
+ }
if (ch <= 'e') { /* 'e' or 'E' fmt */
--expt;
expsize = exponent(expstr, expt, ch);
@@ -565,20 +643,20 @@ fp_begin: _double = va_arg(ap, double);
#endif /* FLOATING_POINT */
case 'n':
if (flags & QUADINT)
- *va_arg(ap, quad_t *) = ret;
+ *GETARG(quad_t *) = ret;
else if (flags & LONGINT)
- *va_arg(ap, long *) = ret;
+ *GETARG(long *) = ret;
else if (flags & SHORTINT)
- *va_arg(ap, short *) = ret;
+ *GETARG(short *) = ret;
else
- *va_arg(ap, int *) = ret;
+ *GETARG(int *) = ret;
continue; /* no output */
case 'O':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'o':
if (flags & QUADINT)
- uqval = va_arg(ap, u_quad_t);
+ uqval = GETARG(u_quad_t);
else
ulval = UARG();
base = 8;
@@ -591,14 +669,14 @@ fp_begin: _double = va_arg(ap, double);
* defined manner.''
* -- ANSI X3J11
*/
- ulval = (u_long)va_arg(ap, void *);
+ ulval = (u_long)GETARG(void *);
base = 16;
xdigs = "0123456789abcdef";
flags = (flags & ~QUADINT) | HEXPREFIX;
ch = 'x';
goto nosign;
case 's':
- if ((cp = va_arg(ap, char *)) == NULL)
+ if ((cp = GETARG(char *)) == NULL)
cp = "(null)";
if (prec >= 0) {
/*
@@ -606,7 +684,7 @@ fp_begin: _double = va_arg(ap, double);
* NUL in the first `prec' characters, and
* strlen() will go further.
*/
- char *p = memchr(cp, 0, prec);
+ char *p = memchr(cp, 0, (size_t)prec);
if (p != NULL) {
size = p - cp;
@@ -623,7 +701,7 @@ fp_begin: _double = va_arg(ap, double);
/*FALLTHROUGH*/
case 'u':
if (flags & QUADINT)
- uqval = va_arg(ap, u_quad_t);
+ uqval = GETARG(u_quad_t);
else
ulval = UARG();
base = 10;
@@ -634,7 +712,7 @@ fp_begin: _double = va_arg(ap, double);
case 'x':
xdigs = "0123456789abcdef";
hex: if (flags & QUADINT)
- uqval = va_arg(ap, u_quad_t);
+ uqval = GETARG(u_quad_t);
else
ulval = UARG();
base = 16;
@@ -693,14 +771,13 @@ number: if ((dprec = prec) >= 0)
* floating precision; finally, if LADJUST, pad with blanks.
*
* Compute actual size, so we know how much to pad.
- * fieldsz excludes decimal prec; realsz includes it.
+ * size excludes decimal prec; realsz includes it.
*/
- fieldsz = size;
+ realsz = dprec > size ? dprec : size;
if (sign)
- fieldsz++;
+ realsz++;
else if (flags & HEXPREFIX)
- fieldsz += 2;
- realsz = dprec > fieldsz ? dprec : fieldsz;
+ realsz += 2;
/* right-adjusting blank padding */
if ((flags & (LADJUST|ZEROPAD)) == 0)
@@ -720,7 +797,7 @@ number: if ((dprec = prec) >= 0)
PAD(width - realsz, zeroes);
/* leading zeroes from decimal precision */
- PAD(dprec - fieldsz, zeroes);
+ PAD(dprec - size, zeroes);
/* the string or number proper */
#ifdef FLOATING_POINT
@@ -729,8 +806,8 @@ number: if ((dprec = prec) >= 0)
} else { /* glue together f_p fragments */
if (ch >= 'f') { /* 'f' or 'g' */
if (_double == 0) {
- /* kludge for __dtoa irregularity */
- if (prec == 0 ||
+ /* kludge for __dtoa irregularity */
+ if (expt >= ndig &&
(flags & ALT) == 0) {
PRINT("0", 1);
} else {
@@ -757,7 +834,7 @@ number: if ((dprec = prec) >= 0)
ox[0] = *cp++;
ox[1] = '.';
PRINT(ox, 2);
- if (_double || flags & ALT == 0) {
+ if (_double) {
PRINT(cp, ndig-1);
} else /* 0.[0..] */
/* __dtoa irregularity */
@@ -782,10 +859,338 @@ number: if ((dprec = prec) >= 0)
done:
FLUSH();
error:
- return (__sferror(fp) ? EOF : ret);
+ if (__sferror(fp))
+ ret = EOF;
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ if ((argtable != NULL) && (argtable != statargtable))
+ free (argtable);
+ return (ret);
/* NOTREACHED */
}
+/*
+ * Type ids for argument type table.
+ */
+#define T_UNUSED 0
+#define T_SHORT 1
+#define T_U_SHORT 2
+#define TP_SHORT 3
+#define T_INT 4
+#define T_U_INT 5
+#define TP_INT 6
+#define T_LONG 7
+#define T_U_LONG 8
+#define TP_LONG 9
+#define T_QUAD 10
+#define T_U_QUAD 11
+#define TP_QUAD 12
+#define T_DOUBLE 13
+#define T_LONG_DOUBLE 14
+#define TP_CHAR 15
+#define TP_VOID 16
+
+/*
+ * Find all arguments when a positional parameter is encountered. Returns a
+ * table, indexed by argument number, of pointers to each arguments. The
+ * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
+ * It will be replaces with a malloc-ed on if it overflows.
+ */
+static void
+__find_arguments (fmt0, ap, argtable)
+ const char *fmt0;
+ va_list ap;
+ void ***argtable;
+{
+ register char *fmt; /* format string */
+ register int ch; /* character from fmt */
+ register int n, n2; /* handy integer (short term usage) */
+ register char *cp; /* handy char pointer (short term usage) */
+ register int flags; /* flags as above */
+ int width; /* width from format (%8d), or 0 */
+ unsigned char *typetable; /* table of types */
+ unsigned char stattypetable [STATIC_ARG_TBL_SIZE];
+ int tablesize; /* current size of type table */
+ int tablemax; /* largest used index in table */
+ int nextarg; /* 1-based argument index */
+
+ /*
+ * Add an argument type to the table, expanding if necessary.
+ */
+#define ADDTYPE(type) \
+ ((nextarg >= tablesize) ? \
+ __grow_type_table(nextarg, &typetable, &tablesize) : 0, \
+ typetable[nextarg++] = type, \
+ (nextarg > tablemax) ? tablemax = nextarg : 0)
+
+#define ADDSARG() \
+ ((flags&LONGINT) ? ADDTYPE(T_LONG) : \
+ ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT)))
+
+#define ADDUARG() \
+ ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \
+ ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT)))
+
+ /*
+ * Add * arguments to the type array.
+ */
+#define ADDASTER() \
+ n2 = 0; \
+ cp = fmt; \
+ while (is_digit(*cp)) { \
+ n2 = 10 * n2 + to_digit(*cp); \
+ cp++; \
+ } \
+ if (*cp == '$') { \
+ int hold = nextarg; \
+ nextarg = n2; \
+ ADDTYPE (T_INT); \
+ nextarg = hold; \
+ fmt = ++cp; \
+ } else { \
+ ADDTYPE (T_INT); \
+ }
+ fmt = (char *)fmt0;
+ typetable = stattypetable;
+ tablesize = STATIC_ARG_TBL_SIZE;
+ tablemax = 0;
+ nextarg = 1;
+ memset (typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
+
+ /*
+ * Scan the format for conversions (`%' character).
+ */
+ for (;;) {
+ for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
+ /* void */;
+ if (ch == '\0')
+ goto done;
+ fmt++; /* skip over '%' */
+
+ flags = 0;
+ width = 0;
+
+rflag: ch = *fmt++;
+reswitch: switch (ch) {
+ case ' ':
+ case '#':
+ goto rflag;
+ case '*':
+ ADDASTER ();
+ goto rflag;
+ case '-':
+ case '+':
+ goto rflag;
+ case '.':
+ if ((ch = *fmt++) == '*') {
+ ADDASTER ();
+ goto rflag;
+ }
+ while (is_digit(ch)) {
+ ch = *fmt++;
+ }
+ goto reswitch;
+ case '0':
+ goto rflag;
+ case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ n = 0;
+ do {
+ n = 10 * n + to_digit(ch);
+ ch = *fmt++;
+ } while (is_digit(ch));
+ if (ch == '$') {
+ nextarg = n;
+ goto rflag;
+ }
+ width = n;
+ goto reswitch;
+#ifdef FLOATING_POINT
+ case 'L':
+ flags |= LONGDBL;
+ goto rflag;
+#endif
+ case 'h':
+ flags |= SHORTINT;
+ goto rflag;
+ case 'l':
+ flags |= LONGINT;
+ goto rflag;
+ case 'q':
+ flags |= QUADINT;
+ goto rflag;
+ case 'c':
+ ADDTYPE(T_INT);
+ break;
+ case 'D':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'd':
+ case 'i':
+ if (flags & QUADINT) {
+ ADDTYPE(T_QUAD);
+ } else {
+ ADDSARG();
+ }
+ break;
+#ifdef FLOATING_POINT
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'g':
+ case 'G':
+ if (flags & LONGDBL)
+ ADDTYPE(T_LONG_DOUBLE);
+ else
+ ADDTYPE(T_DOUBLE);
+ break;
+#endif /* FLOATING_POINT */
+ case 'n':
+ if (flags & QUADINT)
+ ADDTYPE(TP_QUAD);
+ else if (flags & LONGINT)
+ ADDTYPE(TP_LONG);
+ else if (flags & SHORTINT)
+ ADDTYPE(TP_SHORT);
+ else
+ ADDTYPE(TP_INT);
+ continue; /* no output */
+ case 'O':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'o':
+ if (flags & QUADINT)
+ ADDTYPE(T_U_QUAD);
+ else
+ ADDUARG();
+ break;
+ case 'p':
+ ADDTYPE(TP_VOID);
+ break;
+ case 's':
+ ADDTYPE(TP_CHAR);
+ break;
+ case 'U':
+ flags |= LONGINT;
+ /*FALLTHROUGH*/
+ case 'u':
+ if (flags & QUADINT)
+ ADDTYPE(T_U_QUAD);
+ else
+ ADDUARG();
+ break;
+ case 'X':
+ case 'x':
+ if (flags & QUADINT)
+ ADDTYPE(T_U_QUAD);
+ else
+ ADDUARG();
+ break;
+ default: /* "%?" prints ?, unless ? is NUL */
+ if (ch == '\0')
+ goto done;
+ break;
+ }
+ }
+done:
+ /*
+ * Build the argument table.
+ */
+ if (tablemax >= STATIC_ARG_TBL_SIZE) {
+ *argtable = (void **)
+ malloc (sizeof (void *) * (tablemax + 1));
+ }
+
+ (*argtable) [0] = NULL;
+ for (n = 1; n <= tablemax; n++) {
+ (*argtable) [n] = ap;
+ switch (typetable [n]) {
+ case T_UNUSED:
+ (void) va_arg (ap, int);
+ break;
+ case T_SHORT:
+ (void) va_arg (ap, int);
+ break;
+ case T_U_SHORT:
+ (void) va_arg (ap, int);
+ break;
+ case TP_SHORT:
+ (void) va_arg (ap, short *);
+ break;
+ case T_INT:
+ (void) va_arg (ap, int);
+ break;
+ case T_U_INT:
+ (void) va_arg (ap, unsigned int);
+ break;
+ case TP_INT:
+ (void) va_arg (ap, int *);
+ break;
+ case T_LONG:
+ (void) va_arg (ap, long);
+ break;
+ case T_U_LONG:
+ (void) va_arg (ap, unsigned long);
+ break;
+ case TP_LONG:
+ (void) va_arg (ap, long *);
+ break;
+ case T_QUAD:
+ (void) va_arg (ap, quad_t);
+ break;
+ case T_U_QUAD:
+ (void) va_arg (ap, u_quad_t);
+ break;
+ case TP_QUAD:
+ (void) va_arg (ap, quad_t *);
+ break;
+ case T_DOUBLE:
+ (void) va_arg (ap, double);
+ break;
+ case T_LONG_DOUBLE:
+ (void) va_arg (ap, long double);
+ break;
+ case TP_CHAR:
+ (void) va_arg (ap, char *);
+ break;
+ case TP_VOID:
+ (void) va_arg (ap, void *);
+ break;
+ }
+ }
+
+ if ((typetable != NULL) && (typetable != stattypetable))
+ free (typetable);
+}
+
+/*
+ * Increase the size of the type table.
+ */
+static void
+__grow_type_table (nextarg, typetable, tablesize)
+ int nextarg;
+ unsigned char **typetable;
+ int *tablesize;
+{
+ unsigned char *oldtable = *typetable;
+ int newsize = *tablesize * 2;
+
+ if (*tablesize == STATIC_ARG_TBL_SIZE) {
+ *typetable = (unsigned char *)
+ malloc (sizeof (unsigned char) * newsize);
+ bcopy (oldtable, *typetable, *tablesize);
+ } else {
+ *typetable = (unsigned char *)
+ realloc (typetable, sizeof (unsigned char) * newsize);
+
+ }
+ memset (&typetable [*tablesize], T_UNUSED, (newsize - *tablesize));
+
+ *tablesize = newsize;
+}
+
+
#ifdef FLOATING_POINT
extern char *__dtoa __P((double, int, int, int *, int *, char **));
@@ -800,9 +1205,16 @@ cvt(value, ndigits, flags, sign, decpt, ch, length)
char *digits, *bp, *rve;
if (ch == 'f')
- mode = 3;
+ mode = 3; /* ndigits after the decimal point */
else {
- mode = 2;
+ /*
+ * To obtain ndigits after the decimal point for the 'e'
+ * and 'E' formats, round to ndigits + 1 significant
+ * figures.
+ */
+ if (ch == 'e' || ch == 'E')
+ ndigits++;
+ mode = 2; /* ndigits significant digits */
}
if (value < 0) {
value = -value;
@@ -810,7 +1222,8 @@ cvt(value, ndigits, flags, sign, decpt, ch, length)
} else
*sign = '\000';
digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve);
- if (flags & ALT) { /* Print trailing zeros */
+ if ((ch != 'g' && ch != 'G') || flags & ALT) {
+ /* print trailing zeros */
bp = digits + ndigits;
if (ch == 'f') {
if (*digits == '0' && value)
diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c
index 22ed5a0..0df3720 100644
--- a/lib/libc/stdio/vfscanf.c
+++ b/lib/libc/stdio/vfscanf.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id: vfscanf.c,v 1.10 1997/04/04 19:07:02 ache Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -46,6 +50,9 @@ static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
#else
#include <varargs.h>
#endif
+#include <string.h>
+
+#include "collate.h"
#include "local.h"
#define FLOATING_POINT
@@ -62,6 +69,7 @@ static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
#define SUPPRESS 0x08 /* suppress assignment */
#define POINTER 0x10 /* weird %p pointer (`fake hex') */
#define NOSKIP 0x20 /* do not skip blanks */
+#define QUAD 0x400
/*
* The following are used in numeric conversions only:
@@ -83,17 +91,18 @@ static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
#define CT_CHAR 0 /* %c conversion */
#define CT_CCL 1 /* %[...] conversion */
#define CT_STRING 2 /* %s conversion */
-#define CT_INT 3 /* integer, i.e., strtol or strtoul */
+#define CT_INT 3 /* integer, i.e., strtoq or strtouq */
#define CT_FLOAT 4 /* floating, i.e., strtod */
#define u_char unsigned char
#define u_long unsigned long
-static u_char *__sccl();
+static u_char *__sccl(char *, u_char *);
/*
* vfscanf
*/
+int
__svfscanf(fp, fmt0, ap)
register FILE *fp;
char const *fmt0;
@@ -107,9 +116,10 @@ __svfscanf(fp, fmt0, ap)
register int flags; /* flags as defined above */
register char *p0; /* saves original value of p when necessary */
int nassigned; /* number of fields assigned */
+ int nconversions; /* number of conversions */
int nread; /* number of characters consumed from fp */
- int base; /* base argument to strtol/strtoul */
- u_long (*ccfn)(); /* conversion function (strtol/strtoul) */
+ int base; /* base argument to strtoq/strtouq */
+ u_quad_t(*ccfn)(); /* conversion function (strtoq/strtouq) */
char ccltab[256]; /* character class table for %[...] */
char buf[BUF]; /* buffer for numeric conversions */
@@ -118,6 +128,7 @@ __svfscanf(fp, fmt0, ap)
{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
nassigned = 0;
+ nconversions = 0;
nread = 0;
base = 0; /* XXX just to keep gcc happy */
ccfn = NULL; /* XXX just to keep gcc happy */
@@ -128,7 +139,7 @@ __svfscanf(fp, fmt0, ap)
if (isspace(c)) {
for (;;) {
if (fp->_r <= 0 && __srefill(fp))
- return (nassigned);
+ goto input_failure;
if (!isspace(*fp->_p))
break;
nread++, fp->_r--, fp->_p++;
@@ -161,6 +172,9 @@ literal:
case 'l':
flags |= LONG;
goto again;
+ case 'q':
+ flags |= QUAD;
+ goto again;
case 'L':
flags |= LONGDBL;
goto again;
@@ -185,13 +199,13 @@ literal:
/* FALLTHROUGH */
case 'd':
c = CT_INT;
- ccfn = (u_long (*)())strtol;
+ ccfn = (u_quad_t (*)())strtoq;
base = 10;
break;
case 'i':
c = CT_INT;
- ccfn = (u_long (*)())strtol;
+ ccfn = (u_quad_t (*)())strtoq;
base = 0;
break;
@@ -200,13 +214,13 @@ literal:
/* FALLTHROUGH */
case 'o':
c = CT_INT;
- ccfn = strtoul;
+ ccfn = strtouq;
base = 8;
break;
case 'u':
c = CT_INT;
- ccfn = strtoul;
+ ccfn = strtouq;
base = 10;
break;
@@ -216,7 +230,7 @@ literal:
case 'x':
flags |= PFXOK; /* enable 0x prefixing */
c = CT_INT;
- ccfn = strtoul;
+ ccfn = strtouq;
base = 16;
break;
@@ -248,17 +262,20 @@ literal:
case 'p': /* pointer format is like hex */
flags |= POINTER | PFXOK;
c = CT_INT;
- ccfn = strtoul;
+ ccfn = strtouq;
base = 16;
break;
case 'n':
+ nconversions++;
if (flags & SUPPRESS) /* ??? */
continue;
if (flags & SHORT)
*va_arg(ap, short *) = nread;
else if (flags & LONG)
*va_arg(ap, long *) = nread;
+ else if (flags & QUAD)
+ *va_arg(ap, quad_t *) = nread;
else
*va_arg(ap, int *) = nread;
continue;
@@ -273,7 +290,7 @@ literal:
if (isupper(c))
flags |= LONG;
c = CT_INT;
- ccfn = (u_long (*)())strtol;
+ ccfn = (u_quad_t (*)())strtoq;
base = 10;
break;
}
@@ -341,12 +358,13 @@ literal:
nread += r;
nassigned++;
}
+ nconversions++;
break;
case CT_CCL:
/* scan a (nonempty) character class (sets NOSKIP) */
if (width == 0)
- width = ~0; /* `infinity' */
+ width = (size_t)~0; /* `infinity' */
/* take only those things in the class */
if (flags & SUPPRESS) {
n = 0;
@@ -382,12 +400,13 @@ literal:
nassigned++;
}
nread += n;
+ nconversions++;
break;
case CT_STRING:
/* like CCL, but zero-length string OK, & no NOSKIP */
if (width == 0)
- width = ~0;
+ width = (size_t)~0;
if (flags & SUPPRESS) {
n = 0;
while (!isspace(*fp->_p)) {
@@ -412,10 +431,11 @@ literal:
nread += p - p0;
nassigned++;
}
+ nconversions++;
continue;
case CT_INT:
- /* scan an integer as if by strtol/strtoul */
+ /* scan an integer as if by strtoq/strtouq */
#ifdef hardway
if (width == 0 || width > sizeof(buf) - 1)
width = sizeof(buf) - 1;
@@ -533,21 +553,25 @@ literal:
(void) ungetc(c, fp);
}
if ((flags & SUPPRESS) == 0) {
- u_long res;
+ u_quad_t res;
*p = 0;
res = (*ccfn)(buf, (char **)NULL, base);
if (flags & POINTER)
- *va_arg(ap, void **) = (void *)res;
+ *va_arg(ap, void **) =
+ (void *)(u_long)res;
else if (flags & SHORT)
*va_arg(ap, short *) = res;
else if (flags & LONG)
*va_arg(ap, long *) = res;
+ else if (flags & QUAD)
+ *va_arg(ap, quad_t *) = res;
else
*va_arg(ap, int *) = res;
nassigned++;
}
nread += p - buf;
+ nconversions++;
break;
#ifdef FLOATING_POINT
@@ -639,12 +663,13 @@ literal:
nassigned++;
}
nread += p - buf;
+ nconversions++;
break;
#endif /* FLOATING_POINT */
}
}
input_failure:
- return (nassigned ? nassigned : -1);
+ return (nconversions != 0 ? nassigned : EOF);
match_failure:
return (nassigned);
}
@@ -660,7 +685,7 @@ __sccl(tab, fmt)
register char *tab;
register u_char *fmt;
{
- register int c, n, v;
+ register int c, n, v, i;
/* first `clear' the whole table */
c = *fmt++; /* first char hat => negated scanset */
@@ -669,9 +694,10 @@ __sccl(tab, fmt)
c = *fmt++; /* get new first char */
} else
v = 0; /* default => reject */
- /* should probably use memset here */
- for (n = 0; n < 256; n++)
- tab[n] = v;
+
+ /* XXX: Will not work if sizeof(tab*) > sizeof(char) */
+ (void) memset(tab, v, 256);
+
if (c == 0)
return (fmt - 1);/* format ended before closing ] */
@@ -712,15 +738,29 @@ doswitch:
* we just stored in the table (c).
*/
n = *fmt;
- if (n == ']' || n < c) {
+ if (n == ']'
+ || (__collate_load_error ? n < c :
+ __collate_range_cmp (n, c) < 0
+ )
+ ) {
c = '-';
break; /* resume the for(;;) */
}
fmt++;
- do { /* fill in the range */
- tab[++c] = v;
- } while (c < n);
+ /* fill in the range */
+ if (__collate_load_error) {
+ do {
+ tab[++c] = v;
+ } while (c < n);
+ } else {
+ for (i = 0; i < 256; i ++)
+ if ( __collate_range_cmp (c, i) < 0
+ && __collate_range_cmp (i, n) <= 0
+ )
+ tab[i] = v;
+ }
#if 1 /* XXX another disgusting compatibility hack */
+ c = n;
/*
* Alas, the V7 Unix scanf also treats formats
* such as [a-c-e] as `the letters a through e'.
diff --git a/lib/libc/stdio/vprintf.c b/lib/libc/stdio/vprintf.c
index f8184bb..8d449d6 100644
--- a/lib/libc/stdio/vprintf.c
+++ b/lib/libc/stdio/vprintf.c
@@ -35,11 +35,16 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)vprintf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+int
vprintf(fmt, ap)
char const *fmt;
_BSD_VA_LIST_ ap;
diff --git a/lib/libc/stdio/vscanf.c b/lib/libc/stdio/vscanf.c
index 5d12865..9381710 100644
--- a/lib/libc/stdio/vscanf.c
+++ b/lib/libc/stdio/vscanf.c
@@ -35,15 +35,32 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)vscanf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
+int
vscanf(fmt, ap)
const char *fmt;
_BSD_VA_LIST_ ap;
{
+ int retval;
- return (__svfscanf(stdin, fmt, ap));
+#ifdef _THREAD_SAFE
+ _thread_flockfile(stdin,__FILE__,__LINE__);
+#endif
+ retval = __svfscanf(stdin, fmt, ap);
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(stdin);
+#endif
+ return (retval);
}
diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c
index ccc8af6..8837c2e 100644
--- a/lib/libc/stdio/vsnprintf.c
+++ b/lib/libc/stdio/vsnprintf.c
@@ -35,11 +35,16 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
+int
vsnprintf(str, n, fmt, ap)
char *str;
size_t n;
@@ -51,6 +56,7 @@ vsnprintf(str, n, fmt, ap)
if ((int)n < 1)
return (EOF);
+ f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n - 1;
diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c
index c6e192a..911d97f 100644
--- a/lib/libc/stdio/vsprintf.c
+++ b/lib/libc/stdio/vsprintf.c
@@ -35,12 +35,17 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)vsprintf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <limits.h>
+int
vsprintf(str, fmt, ap)
char *str;
const char *fmt;
@@ -49,6 +54,7 @@ vsprintf(str, fmt, ap)
int ret;
FILE f;
+ f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = INT_MAX;
diff --git a/lib/libc/stdio/vsscanf.c b/lib/libc/stdio/vsscanf.c
index 540f290..4cfa662 100644
--- a/lib/libc/stdio/vsscanf.c
+++ b/lib/libc/stdio/vsscanf.c
@@ -35,12 +35,19 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <string.h>
+static int
+eofread __P((void *, char *, int));
+
/* ARGSUSED */
static int
eofread(cookie, buf, len)
@@ -52,14 +59,15 @@ eofread(cookie, buf, len)
return (0);
}
+int
vsscanf(str, fmt, ap)
const char *str;
const char *fmt;
_BSD_VA_LIST_ ap;
{
- int ret;
FILE f;
+ f._file = -1;
f._flags = __SRD;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._r = strlen(str);
diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c
index 36d7c8d..b85ac51 100644
--- a/lib/libc/stdio/wbuf.c
+++ b/lib/libc/stdio/wbuf.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -46,6 +50,7 @@ static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93";
* the given file. Flush the buffer out if it is or becomes full,
* or if c=='\n' and the file is line buffered.
*/
+int
__swbuf(c, fp)
register int c;
register FILE *fp;
diff --git a/lib/libc/stdio/wsetup.c b/lib/libc/stdio/wsetup.c
index 1215edc..74f0f77 100644
--- a/lib/libc/stdio/wsetup.c
+++ b/lib/libc/stdio/wsetup.c
@@ -35,7 +35,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -47,6 +51,7 @@ static char sccsid[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93";
* because either _flags does not include __SWR, or _buf is NULL.
* _wsetup returns 0 if OK to write, nonzero otherwise.
*/
+int
__swsetup(fp)
register FILE *fp;
{
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc
index 9982037..58842bf 100644
--- a/lib/libc/stdlib/Makefile.inc
+++ b/lib/libc/stdlib/Makefile.inc
@@ -1,25 +1,35 @@
-# @(#)Makefile.inc 8.3 (Berkeley) 2/4/95
+# from @(#)Makefile.inc 8.3 (Berkeley) 2/4/95
+# $Id: Makefile.inc,v 1.9 1997/06/22 17:54:24 phk Exp $
# machine-independent stdlib sources
-.PATH: ${.CURDIR}/${MACHINE}/stdlib ${.CURDIR}/stdlib
+.PATH: ${.CURDIR}/../libc/${MACHINE}/stdlib ${.CURDIR}/../libc/stdlib
SRCS+= abort.c atexit.c atof.c atoi.c atol.c bsearch.c calloc.c div.c \
- exit.c getenv.c getopt.c getsubopt.c heapsort.c labs.c ldiv.c \
- malloc.c merge.c putenv.c qsort.c radixsort.c rand.c random.c \
- setenv.c strtod.c strtol.c strtoq.c strtoul.c \
+ exit.c getenv.c getopt.c getsubopt.c strhash.c heapsort.c labs.c \
+ ldiv.c malloc.c merge.c putenv.c qsort.c radixsort.c rand.c random.c \
+ realpath.c setenv.c strtod.c strtol.c strtoq.c strtoul.c \
strtouq.c system.c
# machine-dependent stdlib sources
-.include "${.CURDIR}/${MACHINE}/stdlib/Makefile.inc"
+.include "${.CURDIR}/../libc/${MACHINE}/stdlib/Makefile.inc"
-MAN3+= abort.0 abs.0 alloca.0 atexit.0 atof.0 atoi.0 atol.0 bsearch.0 \
- calloc.0 div.0 exit.0 free.0 getenv.0 getopt.0 getsubopt.0 labs.0 \
- ldiv.0 malloc.0 memory.0 qsort.0 radixsort.0 rand.0 random.0 \
- realloc.0 strtol.0 strtoul.0 system.0
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN3+= stdlib/abort.3 stdlib/abs.3 stdlib/alloca.3 stdlib/atexit.3 \
+ stdlib/atof.3 stdlib/atoi.3 stdlib/atol.3 stdlib/bsearch.3 \
+ stdlib/div.3 stdlib/exit.3 \
+ stdlib/getenv.3 stdlib/getopt.3 stdlib/getsubopt.3 stdlib/labs.3 \
+ stdlib/ldiv.3 stdlib/malloc.3 stdlib/memory.3 stdlib/qsort.3 \
+ stdlib/radixsort.3 stdlib/rand.3 stdlib/random.3 \
+ stdlib/realpath.3 stdlib/strtod.3 stdlib/strtol.3 stdlib/strtoul.3 \
+ stdlib/system.3
MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3
MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3
MLINKS+=rand.3 srand.3
-MLINKS+=random.3 initstate.3 random.3 setstate.3 random.3 srandom.3
+MLINKS+=random.3 initstate.3 random.3 setstate.3 random.3 srandom.3 \
+ random.3 srandomdev.3
MLINKS+=strtol.3 strtoq.3
MLINKS+=strtoul.3 strtouq.3
+MLINKS+=malloc.3 free.3 malloc.3 realloc.3 malloc.3 calloc.3
+.endif
diff --git a/lib/libc/stdlib/abort.3 b/lib/libc/stdlib/abort.3
index 83b4e04..17717e9 100644
--- a/lib/libc/stdlib/abort.3
+++ b/lib/libc/stdlib/abort.3
@@ -53,18 +53,18 @@ signal
.Dv SIGABRT
is being caught and the signal handler does not return.
.Pp
-No open streams are closed or flushed.
+Any open streams are flushed and closed.
.Sh RETURN VALUES
The
-.Nm abort
+.Fn abort
function
never returns.
.Sh SEE ALSO
.Xr sigaction 2 ,
-.Xr exit 2
+.Xr exit 3
.Sh STANDARDS
The
.Fn abort
function
conforms to
-.St -ansiC .
+.St -p1003.1-90 .
diff --git a/lib/libc/stdlib/abort.c b/lib/libc/stdlib/abort.c
index e56e7e9..4fd34dc 100644
--- a/lib/libc/stdlib/abort.c
+++ b/lib/libc/stdlib/abort.c
@@ -35,31 +35,52 @@
static char sccsid[] = "@(#)abort.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/signal.h>
+#include <signal.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
+
+void (*__cleanup)();
void
abort()
{
sigset_t mask;
+ /*
+ * POSIX requires we flush stdio buffers on abort
+ */
+ if (__cleanup)
+ (*__cleanup)();
+
sigfillset(&mask);
/*
* don't block SIGABRT to give any handler a chance; we ignore
* any errors -- X311J doesn't allow abort to return anyway.
*/
sigdelset(&mask, SIGABRT);
+#ifdef _THREAD_SAFE
+ (void) _thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
+#else
(void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
+#endif
(void)kill(getpid(), SIGABRT);
/*
* if SIGABRT ignored, or caught and the handler returns, do
* it again, only harder.
*/
+#ifdef _THREAD_SAFE
+ (void) _thread_sys_signal(SIGABRT, SIG_DFL);
+ (void) _thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
+#else
(void)signal(SIGABRT, SIG_DFL);
(void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
+#endif
(void)kill(getpid(), SIGABRT);
exit(1);
}
diff --git a/lib/libc/stdlib/abs.3 b/lib/libc/stdlib/abs.3
index e12f798..501263e 100644
--- a/lib/libc/stdlib/abs.3
+++ b/lib/libc/stdlib/abs.3
@@ -34,6 +34,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)abs.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt ABS 3
@@ -59,10 +60,10 @@ function
returns
the absolute value.
.Sh SEE ALSO
+.Xr cabs 3 ,
.Xr floor 3 ,
-.Xr labs 3
-.Xr cabs 3
-.Xr hypot 3
+.Xr hypot 3 ,
+.Xr labs 3 ,
.Xr math 3
.Sh STANDARDS
The
diff --git a/lib/libc/stdlib/alloca.3 b/lib/libc/stdlib/alloca.3
index ad5aaf69..498348c 100644
--- a/lib/libc/stdlib/alloca.3
+++ b/lib/libc/stdlib/alloca.3
@@ -59,10 +59,10 @@ If the allocation failed, a
pointer is returned.
.Sh SEE ALSO
.Xr brk 2 ,
-.Xr pagesize 2
.Xr calloc 3 ,
+.Xr getpagesize 3 ,
.Xr malloc 3 ,
-.Xr realloc 3 ,
+.Xr realloc 3
.Sh BUGS
The
.Fn alloca
diff --git a/lib/libc/stdlib/atexit.c b/lib/libc/stdlib/atexit.c
index bbf374e..a65dae5 100644
--- a/lib/libc/stdlib/atexit.c
+++ b/lib/libc/stdlib/atexit.c
@@ -40,6 +40,7 @@ static char sccsid[] = "@(#)atexit.c 8.2 (Berkeley) 7/3/94";
#include <stddef.h>
#include <stdlib.h>
+#include <unistd.h>
#include "atexit.h"
struct atexit *__atexit; /* points to head of LIFO stack */
@@ -57,7 +58,7 @@ atexit(fn)
if ((p = __atexit) == NULL)
__atexit = p = &__atexit0;
else if (p->ind >= ATEXIT_SIZE) {
- if ((p = malloc(sizeof(*p))) == NULL)
+ if ((p = (struct atexit *)sbrk(sizeof(*p))) == (struct atexit *)-1)
return (-1);
p->ind = 0;
p->next = __atexit;
diff --git a/lib/libc/stdlib/atoi.c b/lib/libc/stdlib/atoi.c
index a13c0e2..48e508a 100644
--- a/lib/libc/stdlib/atoi.c
+++ b/lib/libc/stdlib/atoi.c
@@ -38,6 +38,7 @@ static char sccsid[] = "@(#)atoi.c 8.1 (Berkeley) 6/4/93";
#include <stdlib.h>
#include <stddef.h>
+int
atoi(str)
const char *str;
{
diff --git a/lib/libc/stdlib/bsearch.3 b/lib/libc/stdlib/bsearch.3
index e4cf49f..a4e076e 100644
--- a/lib/libc/stdlib/bsearch.3
+++ b/lib/libc/stdlib/bsearch.3
@@ -81,7 +81,7 @@ If two members compare as equal, which member is matched is unspecified.
.Sh SEE ALSO
.Xr db 3 ,
.Xr lsearch 3 ,
-.Xr qsort 3 ,
+.Xr qsort 3
.\" .Xr tsearch 3
.Sh STANDARDS
The
diff --git a/lib/libc/stdlib/calloc.c b/lib/libc/stdlib/calloc.c
index d7c8e07..7a83603 100644
--- a/lib/libc/stdlib/calloc.c
+++ b/lib/libc/stdlib/calloc.c
@@ -46,7 +46,7 @@ calloc(num, size)
register void *p;
size *= num;
- if (p = malloc(size))
+ if ( (p = malloc(size)) )
bzero(p, size);
return(p);
}
diff --git a/lib/libc/stdlib/exit.3 b/lib/libc/stdlib/exit.3
index 43ee3c0..de91276 100644
--- a/lib/libc/stdlib/exit.3
+++ b/lib/libc/stdlib/exit.3
@@ -65,6 +65,11 @@ Unlink all files created with the
.Xr tmpfile 3
function.
.El
+.Pp
+Passing arbitrary values back to the environment as
+.Ar status
+is considered bad style. Instead, use the values as described in
+.Xr sysexits 3 .
.Sh RETURN VALUES
The
.Fn exit
@@ -74,6 +79,7 @@ never returns.
.Xr _exit 2 ,
.Xr atexit 3 ,
.Xr intro 3 ,
+.Xr sysexits 3 ,
.Xr tmpfile 3
.Sh STANDARDS
The
diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c
index 7407e0b..a6bbd35 100644
--- a/lib/libc/stdlib/getenv.c
+++ b/lib/libc/stdlib/getenv.c
@@ -39,20 +39,7 @@ static char sccsid[] = "@(#)getenv.c 8.1 (Berkeley) 6/4/93";
#include <stddef.h>
#include <string.h>
-char *__findenv __P((const char *, int *));
-
-/*
- * getenv --
- * Returns ptr to value associated with name, if any, else NULL.
- */
-char *
-getenv(name)
- const char *name;
-{
- int offset;
-
- return (__findenv(name, &offset));
-}
+inline char *__findenv __P((const char *, int *));
/*
* __findenv --
@@ -63,25 +50,42 @@ getenv(name)
*
* This routine *should* be a static; don't use it.
*/
-char *
+inline char *
__findenv(name, offset)
register const char *name;
int *offset;
{
extern char **environ;
- register int len;
+ register int len, i;
register const char *np;
- register char **p, *c;
+ register char **p, *cp;
if (name == NULL || environ == NULL)
return (NULL);
for (np = name; *np && *np != '='; ++np)
continue;
len = np - name;
- for (p = environ; (c = *p) != NULL; ++p)
- if (strncmp(c, name, len) == 0 && c[len] == '=') {
+ for (p = environ; (cp = *p) != NULL; ++p) {
+ for (np = name, i = len; i && *cp; i--)
+ if (*cp++ != *np++)
+ break;
+ if (i == 0 && *cp++ == '=') {
*offset = p - environ;
- return (c + len + 1);
+ return (cp);
}
+ }
return (NULL);
}
+
+/*
+ * getenv --
+ * Returns ptr to value associated with name, if any, else NULL.
+ */
+char *
+getenv(name)
+ const char *name;
+{
+ int offset;
+
+ return (__findenv(name, &offset));
+}
diff --git a/lib/libc/stdlib/getopt.3 b/lib/libc/stdlib/getopt.3
index 39cc5de..ad4a4dc 100644
--- a/lib/libc/stdlib/getopt.3
+++ b/lib/libc/stdlib/getopt.3
@@ -121,9 +121,11 @@ The
.Fn getopt
function
returns \-1
-when the argument list is exhausted, or a non-recognized
+when the argument list is exhausted, or
+.Ql ?
+if a non-recognized
option is encountered.
-The interpretation of options in the argument list may be cancelled
+The interpretation of options in the argument list may be canceled
by the option
.Ql --
(double dash) which causes
@@ -139,10 +141,10 @@ If the
function encounters a character not found in the string
.Va optarg
or detects
-a missing option argument it writes an error message and returns
-.Ql ?
-to the
-.Em stderr .
+a missing option argument it writes an error message to the
+.Em stderr
+and returns
+.Ql ? .
Setting
.Va opterr
to a zero will disable these error messages.
@@ -213,7 +215,7 @@ from
.Pp
A single dash
.Dq Li -
-may be specified as an character in
+may be specified as a character in
.Fa optstring ,
however it should
.Em never
diff --git a/lib/libc/stdlib/getsubopt.3 b/lib/libc/stdlib/getsubopt.3
index e1040d7..3f6f547 100644
--- a/lib/libc/stdlib/getsubopt.3
+++ b/lib/libc/stdlib/getsubopt.3
@@ -142,4 +142,5 @@ while ((ch = getopt(argc, argv, "ab:")) != \-1) {
.Sh HISTORY
The
.Fn getsubopt
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/stdlib/getsubopt.c b/lib/libc/stdlib/getsubopt.c
index d0ebde2..bc055b8 100644
--- a/lib/libc/stdlib/getsubopt.c
+++ b/lib/libc/stdlib/getsubopt.c
@@ -46,6 +46,7 @@ static char sccsid[] = "@(#)getsubopt.c 8.1 (Berkeley) 6/4/93";
*/
char *suboptarg;
+int
getsubopt(optionp, tokens, valuep)
register char **optionp, **valuep;
register char * const *tokens;
@@ -80,7 +81,7 @@ getsubopt(optionp, tokens, valuep)
*p = '\0';
for (*valuep = ++p;
*p && *p != ',' && *p != ' ' && *p != '\t'; ++p);
- if (*p)
+ if (*p)
*p++ = '\0';
} else
*p++ = '\0';
diff --git a/lib/libc/stdlib/heapsort.c b/lib/libc/stdlib/heapsort.c
index d800064..9649553 100644
--- a/lib/libc/stdlib/heapsort.c
+++ b/lib/libc/stdlib/heapsort.c
@@ -38,10 +38,9 @@
static char sccsid[] = "@(#)heapsort.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/types.h>
#include <errno.h>
-#include <stdlib.h>
#include <stddef.h>
+#include <stdlib.h>
/*
* Swap two areas of size number of bytes. Although qsort(3) permits random
diff --git a/lib/libc/stdlib/labs.3 b/lib/libc/stdlib/labs.3
index ef9ba80..2dba8cc 100644
--- a/lib/libc/stdlib/labs.3
+++ b/lib/libc/stdlib/labs.3
@@ -53,8 +53,8 @@ returns the absolute value of the long integer
.Ar j .
.Sh SEE ALSO
.Xr abs 3 ,
-.Xr floor 3 ,
.Xr cabs 3 ,
+.Xr floor 3 ,
.Xr math 3
.Sh STANDARDS
The
diff --git a/lib/libc/stdlib/ldiv.3 b/lib/libc/stdlib/ldiv.3
index a68952f..2b61499 100644
--- a/lib/libc/stdlib/ldiv.3
+++ b/lib/libc/stdlib/ldiv.3
@@ -44,7 +44,7 @@
.Sh SYNOPSIS
.Fd #include <stdlib.h>
.Ft ldiv_t
-.Fn ldiv "int num" "int denom"
+.Fn ldiv "long num" "long denom"
.Sh DESCRIPTION
The
.Fn ldiv
diff --git a/lib/libc/stdlib/malloc.3 b/lib/libc/stdlib/malloc.3
index 98ebadc..ef77e80 100644
--- a/lib/libc/stdlib/malloc.3
+++ b/lib/libc/stdlib/malloc.3
@@ -34,57 +34,390 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)malloc.3 8.1 (Berkeley) 6/4/93
+.\" $Id: malloc.3,v 1.12 1997/06/22 17:54:27 phk Exp $
.\"
-.Dd June 4, 1993
+.Dd August 27, 1996
.Dt MALLOC 3
-.Os BSD 4
+.Os FreeBSD 2
.Sh NAME
-.Nm malloc ,
-.Nd general memory allocation function
+.Nm malloc, calloc, realloc, free
+.Nd general purpose memory allocation functions
.Sh SYNOPSIS
.Fd #include <stdlib.h>
.Ft void *
.Fn malloc "size_t size"
+.Ft void *
+.Fn calloc "size_t number" "size_t size"
+.Ft void *
+.Fn realloc "void *ptr" "size_t size"
+.Ft void
+.Fn free "void *ptr"
+.Ft char *
+.Va malloc_options;
.Sh DESCRIPTION
The
.Fn malloc
-function allocates uninitialized space for an object whose
-size is specified by
-.Fa size .
+function allocates
+.Fa size
+bytes of memory.
+The allocated space is suitably aligned (after possible pointer coercion)
+for storage of any type of object.
+If the space is at least
+.Em pagesize
+bytes in length (see
+.Xr getpagesize (3)),
+the returned memory will be page boundary aligned as well.
+If
+.Fn malloc
+fails, a NULL pointer is returned.
+.Pp
+The
+.Fn calloc
+function allocates space for
+.Fa number
+objects,
+each
+.Fa size
+bytes in length.
+The result is identical to calling
+.Fn malloc
+with an argument of
+.Dq "number * size" ,
+with the exception that the allocated memory is initialized to nul bytes.
+.Pp
The
+.Fn realloc
+function changes the size of the previously allocated memory referenced by
+.Fa ptr
+to
+.Fa size
+bytes.
+The contents of the memory are unchanged up to the lesser of the new and
+old sizes.
+If the new size is larger,
+the value of the newly allocated portion of the memory is undefined.
+If the requested memory cannot be allocated, NULL is returned and
+the memory referenced by
+.Fa ptr
+is valid and unchanged.
+If
+.Fa ptr
+is NULL, the
+.Fn realloc
+function behaves identically to
.Fn malloc
-function maintains multiple lists of free blocks according to size, allocating
-space from the appropriate list.
+for the specified size.
.Pp
-The allocated space is
-suitably aligned (after possible pointer
-coercion) for storage of any type of object. If the space is of
-.Em pagesize
-or larger, the memory returned will be page-aligned.
+The
+.Fn free
+function causes the allocated memory referenced by
+.Fa ptr
+to be made available for future allocations.
+If
+.Fa ptr
+is NULL, no action occurs.
+.Sh TUNING
+Once, when the first call is made to one of these memory allocation
+routines, various flags will be set or reset, which affect the
+workings of this allocation implementation.
+.Pp
+The ``name'' of the file referenced by the symbolic link named
+.Pa /etc/malloc.conf ,
+the value of the environment variable
+.Ev MALLOC_OPTIONS ,
+and the string pointed to by the global variable
+.Va malloc_options
+will be interpreted, in that order, character by character as flags.
+.Pp
+Most flags are single letters,
+where uppercase indicates that the behavior is set, or on,
+and lowercase means that the behavior is not set, or off.
+.Bl -tag -width indent
+.It A
+All warnings (except for the warning about unknown
+flags being set), and failure to allocate memory become fatal.
+The process will call
+.Fn abort 3
+in these cases.
+.It J
+Each byte of new memory allocated by
+.Fn malloc
+or
+.Fn realloc
+as well as all memory returned by
+.Fn free
+or
+.Fn realloc
+will be initialized to 0xd0.
+This options also sets the
+.Dq R
+option.
+This is intended for debugging and will impact performance negatively.
+.It H
+Pass a hint to the kernel about pages unused by the allocation functions.
+This may help performance if the system is paging excessively.
+.It R
+Cause the
+.Fn realloc
+function to always reallocate memory even if the initial allocation was
+sufficiently large.
+This can substantially aid in compacting memory.
+.It U
+Generate
+.Dq utrace
+entries for
+.Xr ktrace 1 ,
+for all operations.
+Consult the source for details on this option.
+.It V
+Attempting to allocate zero bytes will return a NULL pointer instead of
+a valid pointer.
+(The default behavior is to make a minimal allocation and return a
+pointer to it.)
+This option is provided for System V compatibility.
+This option is incompatible with the
+.Dq X
+option.
+.It X
+Rather than return failure for any allocation function,
+display a diagnostic message on stderr and cause the program to drop
+core (using
+.Fn abort 3 ).
+This option should be set at compile time by including the following in
+the source code:
+.Bd -literal -offset indent
+extern char *malloc_options;
+malloc_options = "X";
+.Ed
+.It Z
+This option implicitly sets the
+.Dq J
+and
+.Dq R
+options, and then zeros out the bytes that were requested.
+This is intended for debugging and will impact performance negatively.
+.It <
+Reduce the size of the cache by a factor of two.
+The default cache size is 16 pages.
+This option can be specified multiple times.
+.It >
+Double the size of the cache by a factor of two.
+The default cache size is 16 pages.
+This option can be specified multiple times.
+.El
+.Pp
+The
+.Dq J
+and
+.Dq Z
+options are intended for testing and debugging.
+An application which changes its behavior when these options are used
+is flawed.
+.Sh EXAMPLES
+To set a systemwide reduction of cache size, and to dump core whenever
+a problem occurs:
+.Pp
+.Bd -literal -offset indent
+ln -s 'A<' /etc/malloc.conf
+.Ed
+.Pp
+To specify in the source that a program does no return value checking
+on calls to these functions:
+.Bd -literal -offset indent
+extern char *malloc_options;
+malloc_options = "X";
+.Ed
+.Sh ENVIRONMENT
+The following environment variables affect the execution of the allocation
+functions:
+.Bl -tag -width MMM
+.It Ev MALLOC_OPTIONS
+If the environmental variable
+.Ev MALLOC_OPTIONS
+is set, the characters it contains will be interpreted as flags to the
+allocation functions.
.Sh RETURN VALUES
The
.Fn malloc
-function returns
-a pointer to the allocated space if successful; otherwise
-a null pointer is returned.
+and
+.Fn calloc
+functions return a pointer to the allocated memory if successful; otherwise
+a NULL pointer is returned.
+.Pp
+The
+.Fn realloc
+function returns a pointer, possibly identical to
+.Fa ptr ,
+to the allocated memory
+if successful; otherwise a NULL pointer is returned, in which case the
+memory referenced by
+.Fa ptr
+is still available and intact.
+.Pp
+The
+.Fn free
+function returns no value.
+.Sh "DEBUGGING MALLOC PROBLEMS"
+.Pp
+The major difference between this implementation and other allocation
+implementations is that the free pages are not accessed unless allocated,
+and are aggressively returned to the kernel for reuse.
+.Bd -filled -offset indent
+Most allocation implementations will store a data structure containing a
+linked list in the free chunks of memory,
+used to tie all the free memory together.
+That can be suboptimal,
+as every time the free-list is traversed,
+the otherwise unused, and likely paged out,
+pages are faulted into primary memory.
+On systems which are paging,
+this can result in a factor of five increase in the number of page-faults
+done by a process.
+.Ed
+.Pp
+A side effect of this architecture is that many minor transgressions on
+the interface which would traditionally not be detected are in fact
+detected. As a result, programs that have been running happily for
+years may suddenly start to complain loudly, when linked with this
+allocation implementation.
+.Pp
+The first and most important thing to do is to set the
+.Dq A
+option.
+This option forces a coredump (if possible) at the first sign of trouble,
+rather than the normal policy of trying to continue if at all possible.
+.Pp
+It is probably also a good idea to recompile the program with suitable
+options and symbols for debugger support.
+.Pp
+If the program starts to give unusual results, coredump or generally behave
+differently without emitting any of the messages listed in the next
+section, it is likely because it depends on the storage being filled with
+nul bytes. Try running it with
+.Dq Z
+option set;
+if that improves the situation, this diagnosis has been confirmed.
+If the program still misbehaves,
+the likely problem is accessing memory outside the allocated area,
+more likely after than before the allocated area.
+.Pp
+Alternatively, if the symptoms are not easy to reproduce, setting the
+.Dq J
+option may help provoke the problem.
+.Pp
+In truly difficult cases, the
+.Dq U
+option, if supported by the kernel, can provide a detailed trace of
+all calls made to these functions.
+.Pp
+Unfortunately this implementation does not provide much detail about
+the problems it detects, the performance impact for storing such information
+would be prohibitive.
+There are a number of allocation implementations available on the 'Net
+which focus on detecting and pinpointing problems by trading performance
+for extra sanity checks and detailed diagnostics.
+.Sh "DIAGNOSTIC MESSAGES
+If
+.Fn malloc ,
+.Fn calloc ,
+.Fn realloc
+or
+.Fn free
+detect an error or warning condition,
+a message will be printed to file descriptor STDERR_FILENO.
+Errors will result in the process dumping core.
+If the
+.Dq A
+option is set, all warnings are treated as errors.
+.Pp
+The following is a brief description of possible error messages and
+their meanings:
+.Pp
+.Bl -tag -width indent
+.It "(ES): mumble mumble mumble
+The allocation functions were compiled with
+.Dq EXTRA_SANITY
+defined, and an error was found during the additional error checking.
+Consult the source code for further information.
+.It "allocation failed
+If the
+.Dq A
+option is specified it is a fatal error for an allocation function to fail.
+.It "mmap(2) failed, check limits
+This most likely means that the system is dangerously overloaded or that
+the process' limits are incorrectly specified.
+.It "freelist is destroyed
+The internal free-list has been corrupted.
+.El
+.Pp
+.Bl -tag -width indent
+The following is a brief description of possible warning messages and
+their meanings:
+.Pp
+.It "chunk/page is already free
+The process attempted to
+.Fn free
+memory which had already been freed.
+.It "junk pointer ...
+A pointer specified to one of the allocation functions points outside the
+bounds of the memory of which they are aware.
+.It "malloc() has never been called
+No memory has been allocated,
+yet something is being freed or
+realloc'ed.
+.It "modified (chunk-/page-) pointer
+The pointer passed to
+.Fn free
+or
+.Fn realloc
+has been modified.
+.It "pointer to wrong page
+The pointer that
+.Fn malloc
+or
+.Fn calloc
+is trying to free does not reference a possible page.
+.It "recursive call
+A process has attempted to call an allocation function recursively.
+This is not permitted. In particular, signal handlers should not
+attempt to allocate memory.
+.It "out of memory
+The
+.Dq X
+option was specified and an allocation of memory failed.
+.It "unknown char in MALLOC_OPTIONS
+An unknown option was specified.
+Even with the
+.Dq A
+option set, this warning is still only a warning.
.Sh SEE ALSO
.Xr brk 2 ,
-.Xr pagesize 2 ,
-.Xr free 3 ,
-.Xr calloc 3 ,
.Xr alloca 3 ,
-.Xr realloc 3 ,
+.Xr getpagesize 3 ,
.Xr memory 3
+.Pa /usr/share/doc/papers/malloc.ascii.gz
.Sh STANDARDS
The
-.Fn malloc
-function conforms to
+.Fn malloc ,
+.Fn calloc ,
+.Fn realloc
+and
+.Fn free
+functions conform to
.St -ansiC .
.Sh BUGS
-The current implementation of
-.Xr malloc
-does not always fail gracefully when system
-memory limits are approached.
-It may fail to allocate memory when larger free blocks could be broken
-up, or when limits are exceeded because the size is rounded up.
-It is optimized for sizes that are powers of two.
+The messages printed in case of problems provide no detail about the
+actual values.
+.Pp
+It can be argued that returning a null pointer when asked to
+allocate zero bytes is a silly response to a silly question.
+.Pp
+This implementation was authored by Poul-Henning Kamp.
+Please report any problems to him at
+.Li <phk@FreeBSD.org> .
+.Sh HISTORY
+The present allocation implementation started out as a filesystem for a
+drum attached to a 20bit binary challenged computer which was built
+with discrete germanium transistors. It has since graduated to
+handle primary storage rather than secondary.
+It first appeared in its new shape and ability in FreeBSD release 2.2.
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index ea8f092..88bd04b 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/lib/libc/stdlib/malloc.c
@@ -1,420 +1,1126 @@
/*
- * Copyright (c) 1983, 1993
- * The Regents of the University of California. All rights reserved.
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
*
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 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.
+ * $Id: malloc.c,v 1.27 1997/07/01 18:39:38 phk Exp $
*
- * 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[] = "@(#)malloc.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+/*
+ * Defining EXTRA_SANITY will enable extra checks which are related
+ * to internal conditions and consistency in malloc.c. This has a
+ * noticeable runtime performance hit, and generally will not do you
+ * any good unless you fiddle with the internals of malloc or want
+ * to catch random pointer corruption as early as possible.
+ */
+#ifndef MALLOC_EXTRA_SANITY
+#undef MALLOC_EXTRA_SANITY
+#endif
+
+/*
+ * What to use for Junk. This is the byte value we use to fill with
+ * when the 'J' option is enabled.
+ */
+#define SOME_JUNK 0xd0 /* as in "Duh" :-) */
/*
- * malloc.c (Caltech) 2/21/82
- * Chris Kingsley, kingsley@cit-20.
+ * The basic parameters you can tweak.
+ *
+ * malloc_pageshift pagesize = 1 << malloc_pageshift
+ * It's probably best if this is the native
+ * page size, but it doesn't have to be.
+ *
+ * malloc_minsize minimum size of an allocation in bytes.
+ * If this is too small it's too much work
+ * to manage them. This is also the smallest
+ * unit of alignment used for the storage
+ * returned by malloc/realloc.
*
- * This is a very fast storage allocator. It allocates blocks of a small
- * number of different sizes, and keeps free lists of each size. Blocks that
- * don't exactly fit are passed up to the next larger size. In this
- * implementation, the available sizes are 2^n-4 (or 2^n-10) bytes long.
- * This is designed for use in a virtual memory environment.
*/
+#if defined(__FreeBSD__)
+# if defined(__i386__)
+# define malloc_pageshift 12U
+# define malloc_minsize 16U
+# endif
+# define HAS_UTRACE
+# if defined(_THREAD_SAFE)
+# include <pthread.h>
+# include "pthread_private.h"
+# define THREAD_LOCK() pthread_mutex_lock(&malloc_lock)
+# define THREAD_UNLOCK() pthread_mutex_unlock(&malloc_lock)
+ static struct pthread_mutex _malloc_lock = PTHREAD_MUTEX_INITIALIZER;
+ static pthread_mutex_t malloc_lock = &_malloc_lock;
+# endif
+#endif /* __FreeBSD__ */
+
+#if defined(__sparc__) && defined(sun)
+# define malloc_pageshirt 12U
+# define malloc_minsize 16U
+# define MAP_ANON (0)
+ static int fdzero;
+# define MMAP_FD fdzero
+# define INIT_MMAP() \
+ { if ((fdzero=open("/dev/zero", O_RDWR, 0000)) == -1) \
+ wrterror("open of /dev/zero"); }
+# define MADV_FREE MADV_DONTNEED
+#endif /* __sparc__ */
+
+/* Insert your combination here... */
+#if defined(__FOOCPU__) && defined(__BAROS__)
+# define malloc_pageshift 12U
+# define malloc_minsize 16U
+#endif /* __FOOCPU__ && __BAROS__ */
+
+
+/*
+ * No user serviceable parts behind this point.
+ */
#include <sys/types.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#define NULL 0
+/*
+ * This structure describes a page worth of chunks.
+ */
-static void morecore();
-static int findbucket();
+struct pginfo {
+ struct pginfo *next; /* next on the free list */
+ void *page; /* Pointer to the page */
+ u_short size; /* size of this page's chunks */
+ u_short shift; /* How far to shift for this size chunks */
+ u_short free; /* How many free chunks */
+ u_short total; /* How many chunk */
+ u_int bits[1]; /* Which chunks are free */
+};
/*
- * The overhead on a block is at least 4 bytes. When free, this space
- * contains a pointer to the next free block, and the bottom two bits must
- * be zero. When in use, the first byte is set to MAGIC, and the second
- * byte is the size index. The remaining bytes are for alignment.
- * If range checking is enabled then a second word holds the size of the
- * requested block, less 1, rounded up to a multiple of sizeof(RMAGIC).
- * The order of elements is critical: ov_magic must overlay the low order
- * bits of ov_next, and ov_magic can not be a valid ov_next bit pattern.
+ * This structure describes a number of free pages.
*/
-union overhead {
- union overhead *ov_next; /* when free */
- struct {
- u_char ovu_magic; /* magic number */
- u_char ovu_index; /* bucket # */
-#ifdef RCHECK
- u_short ovu_rmagic; /* range magic number */
- u_int ovu_size; /* actual block size */
-#endif
- } ovu;
-#define ov_magic ovu.ovu_magic
-#define ov_index ovu.ovu_index
-#define ov_rmagic ovu.ovu_rmagic
-#define ov_size ovu.ovu_size
+
+struct pgfree {
+ struct pgfree *next; /* next run of free pages */
+ struct pgfree *prev; /* prev run of free pages */
+ void *page; /* pointer to free pages */
+ void *end; /* pointer to end of free pages */
+ size_t size; /* number of bytes free */
};
-#define MAGIC 0xef /* magic # on accounting info */
-#define RMAGIC 0x5555 /* magic # on range info */
+/*
+ * How many bits per u_int in the bitmap.
+ * Change only if not 8 bits/byte
+ */
+#define MALLOC_BITS (8*sizeof(u_int))
+
+/*
+ * Magic values to put in the page_directory
+ */
+#define MALLOC_NOT_MINE ((struct pginfo*) 0)
+#define MALLOC_FREE ((struct pginfo*) 1)
+#define MALLOC_FIRST ((struct pginfo*) 2)
+#define MALLOC_FOLLOW ((struct pginfo*) 3)
+#define MALLOC_MAGIC ((struct pginfo*) 4)
+
+#ifndef malloc_pageshift
+#define malloc_pageshift 12U
+#endif
+
+#ifndef malloc_minsize
+#define malloc_minsize 16U
+#endif
+
+#if !defined(malloc_pagesize)
+#define malloc_pagesize (1U<<malloc_pageshift)
+#endif
+
+#if ((1<<malloc_pageshift) != malloc_pagesize)
+#error "(1<<malloc_pageshift) != malloc_pagesize"
+#endif
+
+#ifndef malloc_maxsize
+#define malloc_maxsize ((malloc_pagesize)>>1)
+#endif
+
+/* A mask for the offset inside a page. */
+#define malloc_pagemask ((malloc_pagesize)-1)
+
+#define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask)))
+#define ptr2index(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo)
-#ifdef RCHECK
-#define RSLOP sizeof (u_short)
-#else
-#define RSLOP 0
+#ifndef THREAD_LOCK
+#define THREAD_LOCK()
#endif
+#ifndef THREAD_UNLOCK
+#define THREAD_UNLOCK()
+#endif
+
+#ifndef MMAP_FD
+#define MMAP_FD (-1)
+#endif
+
+#ifndef INIT_MMAP
+#define INIT_MMAP()
+#endif
+
+/* Set when initialization has been done */
+static unsigned malloc_started;
+
+/* Recusion flag for public interface. */
+static int malloc_active;
+
+/* Number of free pages we cache */
+static unsigned malloc_cache = 16;
+
+/* The offset from pagenumber to index into the page directory */
+static u_long malloc_origo;
+
+/* The last index in the page directory we care about */
+static u_long last_index;
+
+/* Pointer to page directory. Allocated "as if with" malloc */
+static struct pginfo **page_dir;
+
+/* How many slots in the page directory */
+static unsigned malloc_ninfo;
+
+/* Free pages line up here */
+static struct pgfree free_list;
+
+/* Abort(), user doesn't handle problems. */
+static int malloc_abort;
+
+/* Are we trying to die ? */
+static int suicide;
+
+/* always realloc ? */
+static int malloc_realloc;
+
+/* pass the kernel a hint on free pages ? */
+static int malloc_hint;
+
+/* xmalloc behaviour ? */
+static int malloc_xmalloc;
+
+/* sysv behaviour for malloc(0) ? */
+static int malloc_sysv;
+
+/* zero fill ? */
+static int malloc_zero;
+
+/* junk fill ? */
+static int malloc_junk;
+
+#ifdef HAS_UTRACE
+
+/* utrace ? */
+static int malloc_utrace;
+
+struct ut { void *p; size_t s; void *r; };
+
+void utrace __P((struct ut *, int));
+
+#define UTRACE(a, b, c) \
+ if (malloc_utrace) \
+ {struct ut u; u.p=a; u.s = b; u.r=c; utrace(&u, sizeof u);}
+#else /* !HAS_UTRACE */
+#define UTRACE(a,b,c)
+#endif /* HAS_UTRACE */
+
+/* my last break. */
+static void *malloc_brk;
+
+/* one location cache for free-list holders */
+static struct pgfree *px;
+
+/* compile-time options */
+char *malloc_options;
+
+/* Name of the current public function */
+static char *malloc_func;
+
+/* Macro for mmap */
+#define MMAP(size) \
+ mmap((caddr_t)0, (size), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, \
+ MMAP_FD, 0);
+
/*
- * nextf[i] is the pointer to the next free block of size 2^(i+3). The
- * smallest allocatable block is 8 bytes. The overhead information
- * precedes the data area returned to the user.
+ * Necessary function declarations
*/
-#define NBUCKETS 30
-static union overhead *nextf[NBUCKETS];
-extern char *sbrk();
+static int extend_pgdir(u_long index);
+static void *imalloc(size_t size);
+static void ifree(void *ptr);
+static void *irealloc(void *ptr, size_t size);
+
+extern char *__progname;
+
+static void
+wrterror(char *p)
+{
+ char *q = " error: ";
+ write(STDERR_FILENO, __progname, strlen(__progname));
+ write(STDERR_FILENO, malloc_func, strlen(malloc_func));
+ write(STDERR_FILENO, q, strlen(q));
+ write(STDERR_FILENO, p, strlen(p));
+ suicide = 1;
+ abort();
+}
+
+static void
+wrtwarning(char *p)
+{
+ char *q = " warning: ";
+ if (malloc_abort)
+ wrterror(p);
+ write(STDERR_FILENO, __progname, strlen(__progname));
+ write(STDERR_FILENO, malloc_func, strlen(malloc_func));
+ write(STDERR_FILENO, q, strlen(q));
+ write(STDERR_FILENO, p, strlen(p));
+}
-static int pagesz; /* page size */
-static int pagebucket; /* page size bucket */
-#ifdef MSTATS
/*
- * nmalloc[i] is the difference between the number of mallocs and frees
- * for a given block size.
+ * Allocate a number of pages from the OS
*/
-static u_int nmalloc[NBUCKETS];
-#include <stdio.h>
-#endif
+static caddr_t
+map_pages(int pages)
+{
+ caddr_t result, tail;
-#if defined(DEBUG) || defined(RCHECK)
-#define ASSERT(p) if (!(p)) botch("p")
-#include <stdio.h>
-static
-botch(s)
- char *s;
+ result = (caddr_t)pageround((u_long)sbrk(0));
+ tail = result + (pages << malloc_pageshift);
+
+ if (brk(tail)) {
+#ifdef EXTRA_SANITY
+ wrterror("(ES): map_pages fails\n");
+#endif /* EXTRA_SANITY */
+ return 0;
+ }
+
+ last_index = ptr2index(tail) - 1;
+ malloc_brk = tail;
+
+ if ((last_index+1) >= malloc_ninfo && !extend_pgdir(last_index))
+ return 0;;
+
+ return result;
+}
+
+/*
+ * Extend page directory
+ */
+static int
+extend_pgdir(u_long index)
{
- fprintf(stderr, "\r\nassertion botched: %s\r\n", s);
- (void) fflush(stderr); /* just in case user buffered it */
- abort();
+ struct pginfo **new, **old;
+ int i, oldlen;
+
+ /* Make it this many pages */
+ i = index * sizeof *page_dir;
+ i /= malloc_pagesize;
+ i += 2;
+
+ /* remember the old mapping size */
+ oldlen = malloc_ninfo * sizeof *page_dir;
+
+ /*
+ * NOTE: we allocate new pages and copy the directory rather than tempt
+ * fate by trying to "grow" the region.. There is nothing to prevent
+ * us from accidently re-mapping space that's been allocated by our caller
+ * via dlopen() or other mmap().
+ *
+ * The copy problem is not too bad, as there is 4K of page index per
+ * 4MB of malloc arena.
+ *
+ * We can totally avoid the copy if we open a file descriptor to associate
+ * the anon mappings with. Then, when we remap the pages at the new
+ * address, the old pages will be "magically" remapped.. But this means
+ * keeping open a "secret" file descriptor.....
+ */
+
+ /* Get new pages */
+ new = (struct pginfo**) MMAP(i * malloc_pagesize);
+ if (new == (struct pginfo **)-1)
+ return 0;
+
+ /* Copy the old stuff */
+ memcpy(new, page_dir,
+ malloc_ninfo * sizeof *page_dir);
+
+ /* register the new size */
+ malloc_ninfo = i * malloc_pagesize / sizeof *page_dir;
+
+ /* swap the pointers */
+ old = page_dir;
+ page_dir = new;
+
+ /* Now free the old stuff */
+ munmap((caddr_t)old, oldlen);
+ return 1;
}
-#else
-#define ASSERT(p)
-#endif
-void *
-malloc(nbytes)
- size_t nbytes;
+/*
+ * Initialize the world
+ */
+static void
+malloc_init ()
{
- register union overhead *op;
- register int bucket, n;
- register unsigned amt;
+ char *p, b[64];
+ int i, j;
- /*
- * First time malloc is called, setup page size and
- * align break pointer so all data will be page aligned.
- */
- if (pagesz == 0) {
- pagesz = n = getpagesize();
- op = (union overhead *)sbrk(0);
- n = n - sizeof (*op) - ((int)op & (n - 1));
- if (n < 0)
- n += pagesz;
- if (n) {
- if (sbrk(n) == (char *)-1)
- return (NULL);
- }
- bucket = 0;
- amt = 8;
- while (pagesz > amt) {
- amt <<= 1;
- bucket++;
- }
- pagebucket = bucket;
+ INIT_MMAP();
+
+#ifdef EXTRA_SANITY
+ malloc_junk = 1;
+#endif /* EXTRA_SANITY */
+
+ for (i = 0; i < 3; i++) {
+ if (i == 0) {
+ j = readlink("/etc/malloc.conf", b, sizeof b - 1);
+ if (j <= 0)
+ continue;
+ b[j] = '\0';
+ p = b;
+ } else if (i == 1) {
+ p = getenv("MALLOC_OPTIONS");
+ } else {
+ p = malloc_options;
}
- /*
- * Convert amount of memory requested into closest block size
- * stored in hash buckets which satisfies request.
- * Account for space used per block for accounting.
- */
- if (nbytes <= (n = pagesz - sizeof (*op) - RSLOP)) {
-#ifndef RCHECK
- amt = 8; /* size of first bucket */
- bucket = 0;
-#else
- amt = 16; /* size of first bucket */
- bucket = 1;
+ for (; p && *p; p++) {
+ switch (*p) {
+ case '>': malloc_cache <<= 1; break;
+ case '<': malloc_cache >>= 1; break;
+ case 'a': malloc_abort = 0; break;
+ case 'A': malloc_abort = 1; break;
+ case 'h': malloc_hint = 0; break;
+ case 'H': malloc_hint = 1; break;
+ case 'r': malloc_realloc = 0; break;
+ case 'R': malloc_realloc = 1; break;
+ case 'j': malloc_junk = 0; break;
+ case 'J': malloc_junk = 1; break;
+#ifdef HAS_UTRACE
+ case 'u': malloc_utrace = 0; break;
+ case 'U': malloc_utrace = 1; break;
#endif
- n = -(sizeof (*op) + RSLOP);
- } else {
- amt = pagesz;
- bucket = pagebucket;
+ case 'v': malloc_sysv = 0; break;
+ case 'V': malloc_sysv = 1; break;
+ case 'x': malloc_xmalloc = 0; break;
+ case 'X': malloc_xmalloc = 1; break;
+ case 'z': malloc_zero = 0; break;
+ case 'Z': malloc_zero = 1; break;
+ default:
+ j = malloc_abort;
+ malloc_abort = 0;
+ wrtwarning("unknown char in MALLOC_OPTIONS\n");
+ malloc_abort = j;
+ break;
+ }
}
- while (nbytes > amt + n) {
- amt <<= 1;
- if (amt == 0)
- return (NULL);
- bucket++;
+ }
+
+ UTRACE(0, 0, 0);
+
+ /*
+ * We want junk in the entire allocation, and zero only in the part
+ * the user asked for.
+ */
+ if (malloc_zero)
+ malloc_junk=1;
+
+ /*
+ * If we run with junk (or implicitly from above: zero), we want to
+ * force realloc() to get new storage, so we can DTRT with it.
+ */
+ if (malloc_junk)
+ malloc_realloc=1;
+
+ /* Allocate one page for the page directory */
+ page_dir = (struct pginfo **) MMAP(malloc_pagesize);
+
+ if (page_dir == (struct pginfo **) -1)
+ wrterror("mmap(2) failed, check limits.\n");
+
+ /*
+ * We need a maximum of malloc_pageshift buckets, steal these from the
+ * front of the page_directory;
+ */
+ malloc_origo = ((u_long)pageround((u_long)sbrk(0))) >> malloc_pageshift;
+ malloc_origo -= malloc_pageshift;
+
+ malloc_ninfo = malloc_pagesize / sizeof *page_dir;
+
+ /* Recalculate the cache size in bytes, and make sure it's nonzero */
+
+ if (!malloc_cache)
+ malloc_cache++;
+
+ malloc_cache <<= malloc_pageshift;
+
+ /*
+ * This is a nice hack from Kaleb Keithly (kaleb@x.org).
+ * We can sbrk(2) further back when we keep this on a low address.
+ */
+ px = (struct pgfree *) imalloc (sizeof *px);
+
+ /* Been here, done that */
+ malloc_started++;
+}
+
+/*
+ * Allocate a number of complete pages
+ */
+static void *
+malloc_pages(size_t size)
+{
+ void *p, *delay_free = 0;
+ int i;
+ struct pgfree *pf;
+ u_long index;
+
+ size = pageround(size);
+
+ p = 0;
+
+ /* Look for free pages before asking for more */
+ for(pf = free_list.next; pf; pf = pf->next) {
+
+#ifdef EXTRA_SANITY
+ if (pf->size & malloc_pagemask)
+ wrterror("(ES): junk length entry on free_list\n");
+ if (!pf->size)
+ wrterror("(ES): zero length entry on free_list\n");
+ if (pf->page == pf->end)
+ wrterror("(ES): zero entry on free_list\n");
+ if (pf->page > pf->end)
+ wrterror("(ES): sick entry on free_list\n");
+ if ((void*)pf->page >= (void*)sbrk(0))
+ wrterror("(ES): entry on free_list past brk\n");
+ if (page_dir[ptr2index(pf->page)] != MALLOC_FREE)
+ wrterror("(ES): non-free first page on free-list\n");
+ if (page_dir[ptr2index(pf->end)-1] != MALLOC_FREE)
+ wrterror("(ES): non-free last page on free-list\n");
+#endif /* EXTRA_SANITY */
+
+ if (pf->size < size)
+ continue;
+
+ if (pf->size == size) {
+ p = pf->page;
+ if (pf->next)
+ pf->next->prev = pf->prev;
+ pf->prev->next = pf->next;
+ delay_free = pf;
+ break;
+ }
+
+ p = pf->page;
+ pf->page = (char *)pf->page + size;
+ pf->size -= size;
+ break;
+ }
+
+#ifdef EXTRA_SANITY
+ if (p && page_dir[ptr2index(p)] != MALLOC_FREE)
+ wrterror("(ES): allocated non-free page on free-list\n");
+#endif /* EXTRA_SANITY */
+
+ size >>= malloc_pageshift;
+
+ /* Map new pages */
+ if (!p)
+ p = map_pages(size);
+
+ if (p) {
+
+ index = ptr2index(p);
+ page_dir[index] = MALLOC_FIRST;
+ for (i=1;i<size;i++)
+ page_dir[index+i] = MALLOC_FOLLOW;
+
+ if (malloc_junk)
+ memset(p, SOME_JUNK, size << malloc_pageshift);
+ }
+
+ if (delay_free) {
+ if (!px)
+ px = delay_free;
+ else
+ ifree(delay_free);
+ }
+
+ return p;
+}
+
+/*
+ * Allocate a page of fragments
+ */
+
+static __inline__ int
+malloc_make_chunks(int bits)
+{
+ struct pginfo *bp;
+ void *pp;
+ int i, k, l;
+
+ /* Allocate a new bucket */
+ pp = malloc_pages(malloc_pagesize);
+ if (!pp)
+ return 0;
+
+ /* Find length of admin structure */
+ l = sizeof *bp - sizeof(u_long);
+ l += sizeof(u_long) *
+ (((malloc_pagesize >> bits)+MALLOC_BITS-1) / MALLOC_BITS);
+
+ /* Don't waste more than two chunks on this */
+ if ((1<<(bits)) <= l+l) {
+ bp = (struct pginfo *)pp;
+ } else {
+ bp = (struct pginfo *)imalloc(l);
+ if (!bp) {
+ ifree(pp);
+ return 0;
}
- /*
- * If nothing in hash bucket right now,
- * request more memory from the system.
- */
- if ((op = nextf[bucket]) == NULL) {
- morecore(bucket);
- if ((op = nextf[bucket]) == NULL)
- return (NULL);
+ }
+
+ bp->size = (1<<bits);
+ bp->shift = bits;
+ bp->total = bp->free = malloc_pagesize >> bits;
+ bp->page = pp;
+
+ /* set all valid bits in the bitmap */
+ k = bp->total;
+ i = 0;
+
+ /* Do a bunch at a time */
+ for(;k-i >= MALLOC_BITS; i += MALLOC_BITS)
+ bp->bits[i / MALLOC_BITS] = ~0;
+
+ for(; i < k; i++)
+ bp->bits[i/MALLOC_BITS] |= 1<<(i%MALLOC_BITS);
+
+ if (bp == bp->page) {
+ /* Mark the ones we stole for ourselves */
+ for(i=0;l > 0;i++) {
+ bp->bits[i/MALLOC_BITS] &= ~(1<<(i%MALLOC_BITS));
+ bp->free--;
+ bp->total--;
+ l -= (1 << bits);
}
- /* remove from linked list */
- nextf[bucket] = op->ov_next;
- op->ov_magic = MAGIC;
- op->ov_index = bucket;
-#ifdef MSTATS
- nmalloc[bucket]++;
-#endif
-#ifdef RCHECK
- /*
- * Record allocated size of block and
- * bound space with magic numbers.
- */
- op->ov_size = (nbytes + RSLOP - 1) & ~(RSLOP - 1);
- op->ov_rmagic = RMAGIC;
- *(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC;
-#endif
- return ((char *)(op + 1));
+ }
+
+ /* MALLOC_LOCK */
+
+ page_dir[ptr2index(pp)] = bp;
+
+ bp->next = page_dir[bits];
+ page_dir[bits] = bp;
+
+ /* MALLOC_UNLOCK */
+
+ return 1;
}
/*
- * Allocate more memory to the indicated bucket.
+ * Allocate a fragment
*/
-static void
-morecore(bucket)
- int bucket;
+static void *
+malloc_bytes(size_t size)
{
- register union overhead *op;
- register int sz; /* size of desired block */
- int amt; /* amount to allocate */
- int nblks; /* how many blocks we get */
+ int i,j;
+ u_int u;
+ struct pginfo *bp;
+ int k;
+ u_int *lp;
- /*
- * sbrk_size <= 0 only for big, FLUFFY, requests (about
- * 2^30 bytes on a VAX, I think) or for a negative arg.
- */
- sz = 1 << (bucket + 3);
-#ifdef DEBUG
- ASSERT(sz > 0);
-#else
- if (sz <= 0)
- return;
-#endif
- if (sz < pagesz) {
- amt = pagesz;
- nblks = amt / sz;
- } else {
- amt = sz + pagesz;
- nblks = 1;
- }
- op = (union overhead *)sbrk(amt);
- /* no more room! */
- if ((int)op == -1)
- return;
- /*
- * Add new memory allocated to that on
- * free list for this hash bucket.
- */
- nextf[bucket] = op;
- while (--nblks > 0) {
- op->ov_next = (union overhead *)((caddr_t)op + sz);
- op = (union overhead *)((caddr_t)op + sz);
- }
+ /* Don't bother with anything less than this */
+ if (size < malloc_minsize)
+ size = malloc_minsize;
+
+ /* Find the right bucket */
+ j = 1;
+ i = size-1;
+ while (i >>= 1)
+ j++;
+
+ /* If it's empty, make a page more of that size chunks */
+ if (!page_dir[j] && !malloc_make_chunks(j))
+ return 0;
+
+ bp = page_dir[j];
+
+ /* Find first word of bitmap which isn't empty */
+ for (lp = bp->bits; !*lp; lp++)
+ ;
+
+ /* Find that bit, and tweak it */
+ u = 1;
+ k = 0;
+ while (!(*lp & u)) {
+ u += u;
+ k++;
+ }
+ *lp ^= u;
+
+ /* If there are no more free, remove from free-list */
+ if (!--bp->free) {
+ page_dir[j] = bp->next;
+ bp->next = 0;
+ }
+
+ /* Adjust to the real offset of that chunk */
+ k += (lp-bp->bits)*MALLOC_BITS;
+ k <<= bp->shift;
+
+ if (malloc_junk)
+ memset((u_char*)bp->page + k, SOME_JUNK, bp->size);
+
+ return (u_char *)bp->page + k;
}
-void
-free(cp)
- void *cp;
-{
- register int size;
- register union overhead *op;
-
- if (cp == NULL)
- return;
- op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
-#ifdef DEBUG
- ASSERT(op->ov_magic == MAGIC); /* make sure it was in use */
-#else
- if (op->ov_magic != MAGIC)
- return; /* sanity */
-#endif
-#ifdef RCHECK
- ASSERT(op->ov_rmagic == RMAGIC);
- ASSERT(*(u_short *)((caddr_t)(op + 1) + op->ov_size) == RMAGIC);
-#endif
- size = op->ov_index;
- ASSERT(size < NBUCKETS);
- op->ov_next = nextf[size]; /* also clobbers ov_magic */
- nextf[size] = op;
-#ifdef MSTATS
- nmalloc[size]--;
-#endif
+/*
+ * Allocate a piece of memory
+ */
+static void *
+imalloc(size_t size)
+{
+ void *result;
+
+ if (suicide)
+ abort();
+
+ if ((size + malloc_pagesize) < size) /* Check for overflow */
+ result = 0;
+ else if (size <= malloc_maxsize)
+ result = malloc_bytes(size);
+ else
+ result = malloc_pages(size);
+
+ if (malloc_abort && !result)
+ wrterror("allocation failed.\n");
+
+ if (malloc_zero && result)
+ memset(result, 0, size);
+
+ return result;
}
/*
- * When a program attempts "storage compaction" as mentioned in the
- * old malloc man page, it realloc's an already freed block. Usually
- * this is the last block it freed; occasionally it might be farther
- * back. We have to search all the free lists for the block in order
- * to determine its bucket: 1st we make one pass thru the lists
- * checking only the first block in each; if that fails we search
- * ``__realloc_srchlen'' blocks in each list for a match (the variable
- * is extern so the caller can modify it). If that fails we just copy
- * however many bytes was given to realloc() and hope it's not huge.
+ * Change the size of an allocation.
*/
-int __realloc_srchlen = 4; /* 4 should be plenty, -1 =>'s whole list */
+static void *
+irealloc(void *ptr, size_t size)
+{
+ void *p;
+ u_long osize, index;
+ struct pginfo **mp;
+ int i;
-void *
-realloc(cp, nbytes)
- void *cp;
- size_t nbytes;
-{
- register u_int onb;
- register int i;
- union overhead *op;
- char *res;
- int was_alloced = 0;
-
- if (cp == NULL)
- return (malloc(nbytes));
- op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
- if (op->ov_magic == MAGIC) {
- was_alloced++;
- i = op->ov_index;
- } else {
- /*
- * Already free, doing "compaction".
- *
- * Search for the old block of memory on the
- * free list. First, check the most common
- * case (last element free'd), then (this failing)
- * the last ``__realloc_srchlen'' items free'd.
- * If all lookups fail, then assume the size of
- * the memory block being realloc'd is the
- * largest possible (so that all "nbytes" of new
- * memory are copied into). Note that this could cause
- * a memory fault if the old area was tiny, and the moon
- * is gibbous. However, that is very unlikely.
- */
- if ((i = findbucket(op, 1)) < 0 &&
- (i = findbucket(op, __realloc_srchlen)) < 0)
- i = NBUCKETS;
+ if (suicide)
+ abort();
+
+ index = ptr2index(ptr);
+
+ if (index < malloc_pageshift) {
+ wrtwarning("junk pointer, too low to make sense.\n");
+ return 0;
+ }
+
+ if (index > last_index) {
+ wrtwarning("junk pointer, too high to make sense.\n");
+ return 0;
+ }
+
+ mp = &page_dir[index];
+
+ if (*mp == MALLOC_FIRST) { /* Page allocation */
+
+ /* Check the pointer */
+ if ((u_long)ptr & malloc_pagemask) {
+ wrtwarning("modified (page-) pointer.\n");
+ return 0;
}
- onb = 1 << (i + 3);
- if (onb < pagesz)
- onb -= sizeof (*op) + RSLOP;
- else
- onb += pagesz - sizeof (*op) - RSLOP;
- /* avoid the copy if same size block */
- if (was_alloced) {
- if (i) {
- i = 1 << (i + 2);
- if (i < pagesz)
- i -= sizeof (*op) + RSLOP;
- else
- i += pagesz - sizeof (*op) - RSLOP;
- }
- if (nbytes <= onb && nbytes > i) {
-#ifdef RCHECK
- op->ov_size = (nbytes + RSLOP - 1) & ~(RSLOP - 1);
- *(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC;
-#endif
- return(cp);
- } else
- free(cp);
+
+ /* Find the size in bytes */
+ for (osize = malloc_pagesize; *++mp == MALLOC_FOLLOW;)
+ osize += malloc_pagesize;
+
+ if (!malloc_realloc && /* unless we have to, */
+ size <= osize && /* .. or are too small, */
+ size > (osize - malloc_pagesize)) { /* .. or can free a page, */
+ return ptr; /* don't do anything. */
}
- if ((res = malloc(nbytes)) == NULL)
- return (NULL);
- if (cp != res) /* common optimization if "compacting" */
- bcopy(cp, res, (nbytes < onb) ? nbytes : onb);
- return (res);
+
+ } else if (*mp >= MALLOC_MAGIC) { /* Chunk allocation */
+
+ /* Check the pointer for sane values */
+ if (((u_long)ptr & ((*mp)->size-1))) {
+ wrtwarning("modified (chunk-) pointer.\n");
+ return 0;
+ }
+
+ /* Find the chunk index in the page */
+ i = ((u_long)ptr & malloc_pagemask) >> (*mp)->shift;
+
+ /* Verify that it isn't a free chunk already */
+ if ((*mp)->bits[i/MALLOC_BITS] & (1<<(i%MALLOC_BITS))) {
+ wrtwarning("chunk is already free.\n");
+ return 0;
+ }
+
+ osize = (*mp)->size;
+
+ if (!malloc_realloc && /* Unless we have to, */
+ size < osize && /* ..or are too small, */
+ (size > osize/2 || /* ..or could use a smaller size, */
+ osize == malloc_minsize)) { /* ..(if there is one) */
+ return ptr; /* ..Don't do anything */
+ }
+
+ } else {
+ wrtwarning("pointer to wrong page.\n");
+ return 0;
+ }
+
+ p = imalloc(size);
+
+ if (p) {
+ /* copy the lesser of the two sizes, and free the old one */
+ if (!size || !osize)
+ ;
+ else if (osize < size)
+ memcpy(p, ptr, osize);
+ else
+ memcpy(p, ptr, size);
+ ifree(ptr);
+ }
+ return p;
}
/*
- * Search ``srchlen'' elements of each free list for a block whose
- * header starts at ``freep''. If srchlen is -1 search the whole list.
- * Return bucket number, or -1 if not found.
+ * Free a sequence of pages
*/
-static
-findbucket(freep, srchlen)
- union overhead *freep;
- int srchlen;
+
+static __inline__ void
+free_pages(void *ptr, int index, struct pginfo *info)
{
- register union overhead *p;
- register int i, j;
-
- for (i = 0; i < NBUCKETS; i++) {
- j = 0;
- for (p = nextf[i]; p && j != srchlen; p = p->ov_next) {
- if (p == freep)
- return (i);
- j++;
- }
+ int i;
+ struct pgfree *pf, *pt=0;
+ u_long l;
+ void *tail;
+
+ if (info == MALLOC_FREE) {
+ wrtwarning("page is already free.\n");
+ return;
+ }
+
+ if (info != MALLOC_FIRST) {
+ wrtwarning("pointer to wrong page.\n");
+ return;
+ }
+
+ if ((u_long)ptr & malloc_pagemask) {
+ wrtwarning("modified (page-) pointer.\n");
+ return;
+ }
+
+ /* Count how many pages and mark them free at the same time */
+ page_dir[index] = MALLOC_FREE;
+ for (i = 1; page_dir[index+i] == MALLOC_FOLLOW; i++)
+ page_dir[index + i] = MALLOC_FREE;
+
+ l = i << malloc_pageshift;
+
+ if (malloc_junk)
+ memset(ptr, SOME_JUNK, l);
+
+ if (malloc_hint)
+ madvise(ptr, l, MADV_FREE);
+
+ tail = (char *)ptr+l;
+
+ /* add to free-list */
+ if (!px)
+ px = imalloc(sizeof *pt); /* This cannot fail... */
+ px->page = ptr;
+ px->end = tail;
+ px->size = l;
+ if (!free_list.next) {
+
+ /* Nothing on free list, put this at head */
+ px->next = free_list.next;
+ px->prev = &free_list;
+ free_list.next = px;
+ pf = px;
+ px = 0;
+
+ } else {
+
+ /* Find the right spot, leave pf pointing to the modified entry. */
+ tail = (char *)ptr+l;
+
+ for(pf = free_list.next; pf->end < ptr && pf->next; pf = pf->next)
+ ; /* Race ahead here */
+
+ if (pf->page > tail) {
+ /* Insert before entry */
+ px->next = pf;
+ px->prev = pf->prev;
+ pf->prev = px;
+ px->prev->next = px;
+ pf = px;
+ px = 0;
+ } else if (pf->end == ptr ) {
+ /* Append to the previous entry */
+ pf->end = (char *)pf->end + l;
+ pf->size += l;
+ if (pf->next && pf->end == pf->next->page ) {
+ /* And collapse the next too. */
+ pt = pf->next;
+ pf->end = pt->end;
+ pf->size += pt->size;
+ pf->next = pt->next;
+ if (pf->next)
+ pf->next->prev = pf;
+ }
+ } else if (pf->page == tail) {
+ /* Prepend to entry */
+ pf->size += l;
+ pf->page = ptr;
+ } else if (!pf->next) {
+ /* Append at tail of chain */
+ px->next = 0;
+ px->prev = pf;
+ pf->next = px;
+ pf = px;
+ px = 0;
+ } else {
+ wrterror("freelist is destroyed.\n");
}
- return (-1);
+ }
+
+ /* Return something to OS ? */
+ if (!pf->next && /* If we're the last one, */
+ pf->size > malloc_cache && /* ..and the cache is full, */
+ pf->end == malloc_brk && /* ..and none behind us, */
+ malloc_brk == sbrk(0)) { /* ..and it's OK to do... */
+
+ /*
+ * Keep the cache intact. Notice that the '>' above guarantees that
+ * the pf will always have at least one page afterwards.
+ */
+ pf->end = (char *)pf->page + malloc_cache;
+ pf->size = malloc_cache;
+
+ brk(pf->end);
+ malloc_brk = pf->end;
+
+ index = ptr2index(pf->end);
+ last_index = index - 1;
+
+ for(i=index;i <= last_index;)
+ page_dir[i++] = MALLOC_NOT_MINE;
+
+ /* XXX: We could realloc/shrink the pagedir here I guess. */
+ }
+ if (pt)
+ ifree(pt);
}
-#ifdef MSTATS
/*
- * mstats - print out statistics about malloc
- *
- * Prints two lines of numbers, one showing the length of the free list
- * for each size category, the second showing the number of mallocs -
- * frees for each size category.
+ * Free a chunk, and possibly the page it's on, if the page becomes empty.
*/
-mstats(s)
- char *s;
+
+static __inline__ void
+free_bytes(void *ptr, int index, struct pginfo *info)
{
- register int i, j;
- register union overhead *p;
- int totfree = 0,
- totused = 0;
-
- fprintf(stderr, "Memory allocation statistics %s\nfree:\t", s);
- for (i = 0; i < NBUCKETS; i++) {
- for (j = 0, p = nextf[i]; p; p = p->ov_next, j++)
- ;
- fprintf(stderr, " %d", j);
- totfree += j * (1 << (i + 3));
- }
- fprintf(stderr, "\nused:\t");
- for (i = 0; i < NBUCKETS; i++) {
- fprintf(stderr, " %d", nmalloc[i]);
- totused += nmalloc[i] * (1 << (i + 3));
- }
- fprintf(stderr, "\n\tTotal in use: %d, total free: %d\n",
- totused, totfree);
+ int i;
+ struct pginfo **mp;
+ void *vp;
+
+ /* Find the chunk number on the page */
+ i = ((u_long)ptr & malloc_pagemask) >> info->shift;
+
+ if (((u_long)ptr & (info->size-1))) {
+ wrtwarning("modified (chunk-) pointer.\n");
+ return;
+ }
+
+ if (info->bits[i/MALLOC_BITS] & (1<<(i%MALLOC_BITS))) {
+ wrtwarning("chunk is already free.\n");
+ return;
+ }
+
+ if (malloc_junk)
+ memset(ptr, SOME_JUNK, info->size);
+
+ info->bits[i/MALLOC_BITS] |= 1<<(i%MALLOC_BITS);
+ info->free++;
+
+ mp = page_dir + info->shift;
+
+ if (info->free == 1) {
+
+ /* Page became non-full */
+
+ mp = page_dir + info->shift;
+ /* Insert in address order */
+ while (*mp && (*mp)->next && (*mp)->next->page < info->page)
+ mp = &(*mp)->next;
+ info->next = *mp;
+ *mp = info;
+ return;
+ }
+
+ if (info->free != info->total)
+ return;
+
+ /* Find & remove this page in the queue */
+ while (*mp != info) {
+ mp = &((*mp)->next);
+#ifdef EXTRA_SANITY
+ if (!*mp)
+ wrterror("(ES): Not on queue\n");
+#endif /* EXTRA_SANITY */
+ }
+ *mp = info->next;
+
+ /* Free the page & the info structure if need be */
+ page_dir[ptr2index(info->page)] = MALLOC_FIRST;
+ vp = info->page; /* Order is important ! */
+ if(vp != (void*)info)
+ ifree(info);
+ ifree(vp);
}
-#endif
+
+static void
+ifree(void *ptr)
+{
+ struct pginfo *info;
+ int index;
+
+ /* This is legal */
+ if (!ptr)
+ return;
+
+ if (!malloc_started) {
+ wrtwarning("malloc() has never been called.\n");
+ return;
+ }
+
+ /* If we're already sinking, don't make matters any worse. */
+ if (suicide)
+ return;
+
+ index = ptr2index(ptr);
+
+ if (index < malloc_pageshift) {
+ wrtwarning("junk pointer, too low to make sense.\n");
+ return;
+ }
+
+ if (index > last_index) {
+ wrtwarning("junk pointer, too high to make sense.\n");
+ return;
+ }
+
+ info = page_dir[index];
+
+ if (info < MALLOC_MAGIC)
+ free_pages(ptr, index, info);
+ else
+ free_bytes(ptr, index, info);
+ return;
+}
+
+/*
+ * These are the public exported interface routines.
+ */
+
+
+void *
+malloc(size_t size)
+{
+ register void *r;
+
+ malloc_func = " in malloc():";
+ THREAD_LOCK();
+ if (malloc_active++) {
+ wrtwarning("recursive call.\n");
+ malloc_active--;
+ return (0);
+ }
+ if (!malloc_started)
+ malloc_init();
+ if (malloc_sysv && !size)
+ r = 0;
+ else
+ r = imalloc(size);
+ UTRACE(0, size, r);
+ malloc_active--;
+ THREAD_UNLOCK();
+ if (malloc_xmalloc && !r)
+ wrterror("out of memory.\n");
+ return (r);
+}
+
+void
+free(void *ptr)
+{
+ malloc_func = " in free():";
+ THREAD_LOCK();
+ if (malloc_active++) {
+ wrtwarning("recursive call.\n");
+ malloc_active--;
+ return;
+ }
+ ifree(ptr);
+ UTRACE(ptr, 0, 0);
+ malloc_active--;
+ THREAD_UNLOCK();
+ return;
+}
+
+void *
+realloc(void *ptr, size_t size)
+{
+ register void *r;
+
+ malloc_func = " in realloc():";
+ THREAD_LOCK();
+ if (malloc_active++) {
+ wrtwarning("recursive call.\n");
+ malloc_active--;
+ return (0);
+ }
+ if (ptr && !malloc_started) {
+ wrtwarning("malloc() has never been called.\n");
+ ptr = 0;
+ }
+ if (!malloc_started)
+ malloc_init();
+ if (malloc_sysv && !size) {
+ ifree(ptr);
+ r = 0;
+ } else if (!ptr) {
+ r = imalloc(size);
+ } else {
+ r = irealloc(ptr, size);
+ }
+ UTRACE(ptr, size, r);
+ malloc_active--;
+ THREAD_UNLOCK();
+ if (malloc_xmalloc && !r)
+ wrterror("out of memory.\n");
+ return (r);
+}
+
diff --git a/lib/libc/stdlib/memory.3 b/lib/libc/stdlib/memory.3
index 9bc600b..0a1fed4 100644
--- a/lib/libc/stdlib/memory.3
+++ b/lib/libc/stdlib/memory.3
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)memory.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt MEMORY 3
@@ -58,11 +59,11 @@ These functions allocate and free memory for the calling process.
They are described in the
individual manual pages.
.Sh SEE ALSO
+.Xr alloca 3 ,
.Xr calloc 3 ,
.Xr free 3 ,
.Xr malloc 3 ,
-.Xr realloc 3 ,
-.Xr alloca 3 ,
+.Xr realloc 3
.Sh STANDARDS
These functions, with the exception of
.Fn alloca
diff --git a/lib/libc/stdlib/merge.c b/lib/libc/stdlib/merge.c
index 7d00844..a47e300 100644
--- a/lib/libc/stdlib/merge.c
+++ b/lib/libc/stdlib/merge.c
@@ -80,7 +80,7 @@ static void insertionsort __P((u_char *, size_t, size_t, int (*)()));
do \
*dst++ = *src++; \
while (i -= 1)
-
+
/*
* Find the next possible pointer head. (Trickery for forcing an array
* to do double duty as a linked list when objects do not align with word
@@ -164,7 +164,7 @@ EXPONENTIAL: for (i = size; ; i <<= 1)
} else if ((*cmp)(q, p) <= sense) {
t = p;
if (i == size)
- big = 0;
+ big = 0;
goto FASTCASE;
} else
b = p;
diff --git a/lib/libc/stdlib/qsort.c b/lib/libc/stdlib/qsort.c
index 1d3aa93..ff3def5 100644
--- a/lib/libc/stdlib/qsort.c
+++ b/lib/libc/stdlib/qsort.c
@@ -32,13 +32,17 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
static char sccsid[] = "@(#)qsort.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* LIBC_SCCS and not lint */
-#include <sys/types.h>
#include <stdlib.h>
-static inline char *med3 __P((char *, char *, char *, int (*)()));
+typedef int cmp_t __P((const void *, const void *));
+static inline char *med3 __P((char *, char *, char *, cmp_t *));
static inline void swapfunc __P((char *, char *, int, int));
#define min(a, b) (a) < (b) ? a : b
@@ -65,7 +69,7 @@ swapfunc(a, b, n, swaptype)
char *a, *b;
int n, swaptype;
{
- if(swaptype <= 1)
+ if(swaptype <= 1)
swapcode(long, a, b, n)
else
swapcode(char, a, b, n)
@@ -84,7 +88,7 @@ swapfunc(a, b, n, swaptype)
static inline char *
med3(a, b, c, cmp)
char *a, *b, *c;
- int (*cmp)();
+ cmp_t *cmp;
{
return cmp(a, b) < 0 ?
(cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
@@ -95,7 +99,7 @@ void
qsort(a, n, es, cmp)
void *a;
size_t n, es;
- int (*cmp)();
+ cmp_t *cmp;
{
char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
int d, r, swaptype, swap_cnt;
@@ -103,16 +107,16 @@ qsort(a, n, es, cmp)
loop: SWAPINIT(a, es);
swap_cnt = 0;
if (n < 7) {
- for (pm = a + es; pm < (char *) a + n * es; pm += es)
- for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
+ for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
+ for (pl = pm; pl > (char *)a && cmp(pl - es, pl) > 0;
pl -= es)
swap(pl, pl - es);
return;
}
- pm = a + (n / 2) * es;
+ pm = (char *)a + (n / 2) * es;
if (n > 7) {
pl = a;
- pn = a + (n - 1) * es;
+ pn = (char *)a + (n - 1) * es;
if (n > 40) {
d = (n / 8) * es;
pl = med3(pl, pl + d, pl + 2 * d, cmp);
@@ -122,9 +126,9 @@ loop: SWAPINIT(a, es);
pm = med3(pl, pm, pn, cmp);
}
swap(a, pm);
- pa = pb = a + es;
+ pa = pb = (char *)a + es;
- pc = pd = a + (n - 1) * es;
+ pc = pd = (char *)a + (n - 1) * es;
for (;;) {
while (pb <= pc && (r = cmp(pb, a)) <= 0) {
if (r == 0) {
@@ -150,21 +154,21 @@ loop: SWAPINIT(a, es);
pc -= es;
}
if (swap_cnt == 0) { /* Switch to insertion sort */
- for (pm = a + es; pm < (char *) a + n * es; pm += es)
- for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
+ for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
+ for (pl = pm; pl > (char *)a && cmp(pl - es, pl) > 0;
pl -= es)
swap(pl, pl - es);
return;
}
- pn = a + n * es;
+ pn = (char *)a + n * es;
r = min(pa - (char *)a, pb - pa);
vecswap(a, pb - r, r);
r = min(pd - pc, pn - pd - es);
vecswap(pb, pn - r, r);
if ((r = pb - pa) > es)
qsort(a, r / es, es, cmp);
- if ((r = pd - pc) > es) {
+ if ((r = pd - pc) > es) {
/* Iterate rather than recurse to save stack space */
a = pn - r;
n = r / es;
diff --git a/lib/libc/stdlib/radixsort.3 b/lib/libc/stdlib/radixsort.3
index ce30378..29a1d9d 100644
--- a/lib/libc/stdlib/radixsort.3
+++ b/lib/libc/stdlib/radixsort.3
@@ -41,9 +41,9 @@
.Fd #include <limits.h>
.Fd #include <stdlib.h>
.Ft int
-.Fn radixsort "u_char **base" "int nmemb" "u_char *table" "u_int endbyte"
+.Fn radixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte"
.Ft int
-.Fn sradixsort "u_char **base" "int nmemb" "u_char *table" "u_int endbyte"
+.Fn sradixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte"
.Sh DESCRIPTION
The
.Fn radixsort
@@ -157,4 +157,5 @@ for any of the errors specified for the library routine
.Sh HISTORY
The
.Fn radixsort
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/stdlib/radixsort.c b/lib/libc/stdlib/radixsort.c
index b932bf5..0a583ac 100644
--- a/lib/libc/stdlib/radixsort.c
+++ b/lib/libc/stdlib/radixsort.c
@@ -3,7 +3,7 @@
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
- * Peter McIlroy and by Dan Bernstein at New York University,
+ * Peter McIlroy and by Dan Bernstein at New York University,
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -40,13 +40,13 @@ static char sccsid[] = "@(#)radixsort.c 8.2 (Berkeley) 4/28/95";
/*
* Radixsort routines.
- *
+ *
* Program r_sort_a() is unstable but uses O(logN) extra memory for a stack.
* Use radixsort(a, n, trace, endchar) for this case.
- *
+ *
* For stable sorting (using N extra pointers) use sradixsort(), which calls
* r_sort_b().
- *
+ *
* For a description of this code, see D. McIlroy, P. McIlroy, K. Bostic,
* "Engineering Radix Sort".
*/
@@ -294,7 +294,7 @@ r_sort_b(a, ta, n, i, tr, endch)
*--top[tr[(*ak)[i]]] = *ak;
}
}
-
+
static inline void
simplesort(a, n, b, tr, endch) /* insertion sort */
register const u_char **a;
diff --git a/lib/libc/stdlib/random.3 b/lib/libc/stdlib/random.3
index 84680e2..4691498 100644
--- a/lib/libc/stdlib/random.3
+++ b/lib/libc/stdlib/random.3
@@ -37,6 +37,7 @@
.Sh NAME
.Nm random ,
.Nm srandom ,
+.Nm srandomdev ,
.Nm initstate ,
.Nm setstate
.Nd better random number generator; routines for changing generators
@@ -45,9 +46,11 @@
.Ft long
.Fn random void
.Ft void
-.Fn srandom "unsigned seed"
+.Fn srandom "unsigned long seed"
+.Ft void
+.Fn srandomdev void
.Ft char *
-.Fn initstate "unsigned seed" "char *state" "int n"
+.Fn initstate "unsigned long seed" "char *state" "long n"
.Ft char *
.Fn setstate "char *state"
.Sh DESCRIPTION
@@ -64,11 +67,16 @@ The period of this random number generator is very large, approximately
.if n 16*((2**31)\(mi1).
.Pp
The
-.Fn random Ns / Fn srandom
-have (almost) the same calling sequence and initialization properties as
-.Xr rand 3 Ns / Xr srand 3 .
+.Fn random
+and
+.Fn srandom
+functions have (almost) the same calling sequence and initialization properties as the
+.Xr rand 3
+and
+.Xr srand 3
+functions.
The difference is that
-.Xr rand
+.Xr rand 3
produces a much less random sequence \(em in fact, the low dozen bits
generated by rand go through a cyclic pattern. All the bits generated by
.Fn random
@@ -77,15 +85,8 @@ are usable. For example,
will produce a random binary
value.
.Pp
-Unlike
-.Xr srand ,
-.Fn srandom
-does not return the old seed; the reason for this is that the amount of
-state information used is much more than a single word. (Two other
-routines are provided to deal with restarting/changing random
-number generators). Like
+Like
.Xr rand 3 ,
-however,
.Fn random
will by default produce a sequence of numbers that can be duplicated
by calling
@@ -95,6 +96,20 @@ with
as the seed.
.Pp
The
+.Fn srandomdev
+routine initialize a state array using
+.Xr urandom 4
+random number device which returns good random numbers,
+suitable for cryptographic use.
+Note that this particular seeding
+procedure can generate states which are impossible to reproduce by
+calling
+.Fn srandom
+with any value, since the succeeding terms in the
+state buffer are no longer derived from the LC algorithm applied to
+a fixed seed.
+.Pp
+The
.Fn initstate
routine allows a state array, passed in as an argument, to be initialized
for future use. The size of the state array (in bytes) is used by
@@ -156,11 +171,19 @@ is called with less than 8 bytes of state information, or if
detects that the state information has been garbled, error
messages are printed on the standard error output.
.Sh SEE ALSO
-.Xr rand 3
+.Xr rand 3 ,
+.Xr srand 3 ,
+.Xr urandom 4
.Sh HISTORY
These
functions appeared in
.Bx 4.2 .
.Sh BUGS
+.Pp
About 2/3 the speed of
.Xr rand 3 .
+.Pp
+The historical implementation used to have a very weak seeding; the
+random sequence did not vary much with the seed.
+The current implementation employs a better pseudo-random number
+generator for the initial state calculation.
diff --git a/lib/libc/stdlib/random.c b/lib/libc/stdlib/random.c
index 7c76158..4737e40 100644
--- a/lib/libc/stdlib/random.c
+++ b/lib/libc/stdlib/random.c
@@ -29,14 +29,20 @@
* 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.
+ *
+ * $Id: random.c,v 1.9 1997/06/14 00:13:56 ache Exp $
+ *
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95";
#endif /* LIBC_SCCS and not lint */
+#include <sys/time.h> /* for srandomdev() */
+#include <fcntl.h> /* for srandomdev() */
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h> /* for srandomdev() */
/*
* random.c:
@@ -61,7 +67,7 @@ static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95";
* state information, which will allow a degree seven polynomial. (Note:
* the zeroeth word of state information also has some other information
* stored in it -- see setstate() for details).
- *
+ *
* The random number generation technique is a linear feedback shift register
* approach, employing trinomials (since there are fewer terms to sum up that
* way). In this approach, the least significant bit of all the numbers in
@@ -141,7 +147,7 @@ static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
/*
* Initially, everything is set up as if from:
*
- * initstate(1, &randtbl, 128);
+ * initstate(1, randtbl, 128);
*
* Note that this initialization takes advantage of the fact that srandom()
* advances the front and rear pointers 10*rand_deg times, and hence the
@@ -154,12 +160,23 @@ static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
static long randtbl[DEG_3 + 1] = {
TYPE_3,
+#ifdef USE_WEAK_SEEDING
+/* Historic implementation compatibility */
+/* The random sequences do not vary much with the seed */
0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5,
0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd,
0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88,
0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc,
0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b,
0x27fb47b9,
+#else /* !USE_WEAK_SEEDING */
+ 0x991539b1, 0x16a5bce3, 0x6774a4cd, 0x3e01511e, 0x4e508aaa, 0x61048c05,
+ 0xf5500617, 0x846b7115, 0x6a19892c, 0x896a97af, 0xdb48f936, 0x14898454,
+ 0x37ffd106, 0xb58bff9c, 0x59e17104, 0xcf918a49, 0x09378c83, 0x52c7a471,
+ 0x8d293ea9, 0x1f4fc301, 0xc3db71be, 0x39b44e1c, 0xf8a44ef9, 0x4c8b80b1,
+ 0x19edc328, 0x87bf4bdd, 0xc9b240e5, 0xe9ee4b1b, 0x4382aee7, 0x535b6b41,
+ 0xf3bec5da
+#endif /* !USE_WEAK_SEEDING */
};
/*
@@ -195,6 +212,38 @@ static long rand_deg = DEG_3;
static long rand_sep = SEP_3;
static long *end_ptr = &randtbl[DEG_3 + 1];
+static inline long good_rand __P((long));
+
+static inline long good_rand (x)
+ register long x;
+{
+#ifdef USE_WEAK_SEEDING
+/*
+ * Historic implementation compatibility.
+ * The random sequences do not vary much with the seed,
+ * even with overflowing.
+ */
+ return (1103515245 * x + 12345);
+#else /* !USE_WEAK_SEEDING */
+/*
+ * Compute x = (7^5 * x) mod (2^31 - 1)
+ * wihout overflowing 31 bits:
+ * (2^31 - 1) = 127773 * (7^5) + 2836
+ * From "Random number generators: good ones are hard to find",
+ * Park and Miller, Communications of the ACM, vol. 31, no. 10,
+ * October 1988, p. 1195.
+ */
+ register long hi, lo;
+
+ hi = x / 127773;
+ lo = x % 127773;
+ x = 16807 * lo - 2836 * hi;
+ if (x <= 0)
+ x += 0x7fffffff;
+ return (x);
+#endif /* !USE_WEAK_SEEDING */
+}
+
/*
* srandom:
*
@@ -218,7 +267,7 @@ srandom(x)
else {
state[0] = x;
for (i = 1; i < rand_deg; i++)
- state[i] = 1103515245 * state[i - 1] + 12345;
+ state[i] = good_rand(state[i - 1]);
fptr = &state[rand_sep];
rptr = &state[0];
for (i = 0; i < 10 * rand_deg; i++)
@@ -227,6 +276,51 @@ srandom(x)
}
/*
+ * srandomdev:
+ *
+ * Many programs choose the seed value in a totally predictable manner.
+ * This often causes problems. We seed the generator using the much more
+ * secure urandom(4) interface. Note that this particular seeding
+ * procedure can generate states which are impossible to reproduce by
+ * calling srandom() with any value, since the succeeding terms in the
+ * state buffer are no longer derived from the LC algorithm applied to
+ * a fixed seed.
+ */
+void
+srandomdev()
+{
+ int fd, done;
+ size_t len;
+
+ if (rand_type == TYPE_0)
+ len = sizeof state[0];
+ else
+ len = rand_deg * sizeof state[0];
+
+ done = 0;
+ fd = open("/dev/urandom", O_RDONLY, 0);
+ if (fd >= 0) {
+ if (read(fd, (void *) state, len) == (ssize_t) len)
+ done = 1;
+ close(fd);
+ }
+
+ if (!done) {
+ struct timeval tv;
+ unsigned long junk;
+
+ gettimeofday(&tv, NULL);
+ srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk);
+ return;
+ }
+
+ if (rand_type != TYPE_0) {
+ fptr = &state[rand_sep];
+ rptr = &state[0];
+ }
+}
+
+/*
* initstate:
*
* Initialize the state information in the given array of n bytes for future
@@ -234,12 +328,12 @@ srandom(x)
* the break values for the different R.N.G.'s, we choose the best (largest)
* one we can and set things up for it. srandom() is then called to
* initialize the state information.
- *
+ *
* Note that on return from srandom(), we set state[-1] to be the type
* multiplexed with the current value of the rear pointer; this is so
* successive calls to initstate() won't lose this information and will be
* able to restart with setstate().
- *
+ *
* Note: the first thing we do is save the current state, if any, just like
* setstate() so that it doesn't matter when initstate is called.
*
@@ -378,7 +472,7 @@ random()
if (rand_type == TYPE_0) {
i = state[0];
- state[0] = i = (i * 1103515245 + 12345) & 0x7fffffff;
+ state[0] = i = (good_rand(i)) & 0x7fffffff;
} else {
/*
* Use local variables rather than static variables for speed.
diff --git a/lib/libc/stdlib/realpath.3 b/lib/libc/stdlib/realpath.3
index 83f4a43..1cbbca9 100644
--- a/lib/libc/stdlib/realpath.3
+++ b/lib/libc/stdlib/realpath.3
@@ -34,7 +34,7 @@
.\"
.\" @(#)realpath.3 8.2 (Berkeley) 2/16/94
.\"
-.Dd "February 16, 1994"
+.Dd February 16, 1994
.Dt REALPATH 3
.Os
.Sh NAME
diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c
index 20efabd..28380d7 100644
--- a/lib/libc/stdlib/realpath.c
+++ b/lib/libc/stdlib/realpath.c
@@ -98,7 +98,7 @@ loop:
p = resolved;
/* Deal with the last component. */
- if (lstat(p, &sb) == 0) {
+ if (*p != '\0' && lstat(p, &sb) == 0) {
if (S_ISLNK(sb.st_mode)) {
n = readlink(p, resolved, MAXPATHLEN);
if (n < 0)
diff --git a/lib/libc/stdlib/setenv.c b/lib/libc/stdlib/setenv.c
index b36d673..d981277 100644
--- a/lib/libc/stdlib/setenv.c
+++ b/lib/libc/stdlib/setenv.c
@@ -39,13 +39,14 @@ static char sccsid[] = "@(#)setenv.c 8.1 (Berkeley) 6/4/93";
#include <stdlib.h>
#include <string.h>
-char *__findenv __P((const char *, int *));
+char *__findenv __P((const char *, int *));
/*
* setenv --
* Set the value of the environmental variable "name" to be
* "value". If rewrite is set, replace any current value.
*/
+int
setenv(name, value, rewrite)
register const char *name;
register const char *value;
@@ -63,7 +64,7 @@ setenv(name, value, rewrite)
if (!rewrite)
return (0);
if (strlen(c) >= l_value) { /* old larger; copy over */
- while (*c++ = *value++);
+ while ( (*c++ = *value++) );
return (0);
}
} else { /* create new slot */
@@ -93,7 +94,7 @@ setenv(name, value, rewrite)
malloc((size_t)((int)(c - name) + l_value + 2))))
return (-1);
for (c = environ[offset]; (*c = *name++) && *c != '='; ++c);
- for (*c++ = '='; *c++ = *value++;);
+ for (*c++ = '='; (*c++ = *value++); );
return (0);
}
diff --git a/lib/libc/stdlib/strhash.c b/lib/libc/stdlib/strhash.c
new file mode 100644
index 0000000..8e2230b
--- /dev/null
+++ b/lib/libc/stdlib/strhash.c
@@ -0,0 +1,436 @@
+#ifndef lint
+static char *rcsid = "$Header: /home/ncvs/src/lib/libc/stdlib/strhash.c,v 1.5 1995/10/22 14:53:17 phk Exp $";
+#endif
+
+/*
+ *
+ * Copyright 1990
+ * Terry Jones & Jordan Hubbard
+ *
+ * PCS Computer Systeme, GmbH.
+ * Munich, West Germany
+ *
+ *
+ * All rights reserved.
+ *
+ * This is unsupported software and is subject to change without notice.
+ * the author makes no representations about the suitability of this software
+ * for any purpose. It is supplied "as is" without express or implied
+ * warranty.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the author not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.
+ *
+ */
+
+/*
+ * This is a fairly simple open addressing hash scheme.
+ * Terry did all the code, I just did the spec.
+ * Thanks again, you crazy Aussie..
+ *
+ */
+
+/*
+ * $Log: strhash.c,v $
+ * Revision 1.5 1995/10/22 14:53:17 phk
+ * Mino cleanup, #includes & unused vars.
+ *
+ * Revision 1.4 1995/05/30 05:41:55 rgrimes
+ * Remove trailing whitespace.
+ *
+ * Revision 1.3 1995/03/28 08:41:02 jkh
+ * Fix a missing _hash() to prevent namespace pollution with the db/hash routines.
+ * Grrr. If the dbhash routines weren't grossly overengineered I wouldn't
+ * even need to do this! :-(
+ *
+ * Also now export the hash_stats routine. Manpage coming RSN - I promise.
+ *
+ * Revision 1.2 1995/03/26 19:32:24 ache
+ * Hash 8bit chars without sign extension
+ *
+ * Revision 1.1 1995/03/26 10:21:55 jkh
+ * Add the strhash family of routines. They provide a number of features
+ * that the db/hash functions don't, and they're much simpler to use for
+ * low-overhead string hashing.
+ *
+ * Revision 1.1 1995/02/25 02:16:34 jkh
+ * Second version of this - now support the essentials of a basic
+ * attributed file system for storing menu information and command
+ * templates. This is not finished yet, but it does compile so I can
+ * commit it to the tree now and continue working on it.
+ *
+ * Revision 2.0 90/03/26 01:44:26 jkh
+ * pre-beta check-in
+ *
+ * Revision 1.8 90/03/09 19:22:35 jkh
+ * Fixed bogus comment.
+ *
+ * Revision 1.7 90/03/09 19:01:08 jkh
+ * Added comments, GPL.
+ *
+ * Revision 1.6 90/03/08 17:55:58 terry
+ * Rearranged hash_purge to be a tiny bit more efficient.
+ * Added verbose option to hash_stats.
+ *
+ * Revision 1.5 90/03/08 17:19:54 terry
+ * Added hash_purge. Added arg to hash_traverse. Changed all
+ * void * to Generic.
+ *
+ * Revision 1.4 90/03/08 12:02:35 terry
+ * Fixed problems with allocation that I screwed up last night.
+ * Changed bucket lists to be singly linked. Thanks to JKH, my hero.
+ *
+ * Revision 1.3 90/03/07 21:33:33 terry
+ * Cleaned up a few decls to keep gcc -Wall quiet.
+ *
+ * Revision 1.2 90/03/07 21:14:53 terry
+ * Comments. Added HASH_STATS define. Removed hash_find()
+ * and new_node().
+ *
+ * Revision 1.1 90/03/07 20:49:45 terry
+ * Initial revision
+ *
+ *
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <strhash.h>
+
+#define HASH_NULL (hash_table *)0
+#define NODE_NULL (hash_node *)0
+#define GENERIC_NULL (void *)0
+
+#define HASH_SZ 97
+
+
+static int _hash(int size, char *key);
+static hash_node *list_find(caddr_t key, hash_node *head);
+
+
+/*
+ * hash_create()
+ *
+ * Malloc room for a new hash table and then room for its
+ * bucket pointers. Then set all the buckets to
+ * point to 0. Return the address of the new table.
+ */
+hash_table *
+hash_create(int size)
+{
+ register int i;
+ hash_table *new = (hash_table *)malloc(sizeof(hash_table));
+
+ if (!new || size < 0){
+ return HASH_NULL;
+ }
+
+ if (size == 0){
+ size = HASH_SZ;
+ }
+
+ if (!(new->buckets = (hash_node **)malloc(size * sizeof(hash_node *)))){
+ return HASH_NULL;
+ }
+
+ for (i = 0; i < size; i++){
+ new->buckets[i] = NODE_NULL;
+ }
+ new->size = size;
+
+ return new;
+}
+
+
+/*
+ * list_find()
+ *
+ * Find the key in the linked list pointed to by head.
+ */
+static hash_node *
+list_find(caddr_t key, hash_node *head)
+{
+ while (head){
+ if (!strcmp(head->key, key)){
+ return head;
+ }
+ head = head->next;
+ }
+ return NODE_NULL;
+}
+
+
+/*
+ * _hash()
+ *
+ * Compute the hash value for the given key.
+ */
+static int
+_hash(int size, char *key)
+{
+ unsigned int h = 0x0;
+
+ while (*key){
+ h = (h << 1) ^ (h ^ (unsigned char) *key++);
+ }
+
+ h %= size;
+ return h;
+}
+
+/*
+ * hash_destroy()
+ *
+ * Find the key and (if it's there) remove it entirely.
+ * The function (*nukefunc)() is in charge of disposing
+ * of the storage help by the data associated with the node.
+ */
+void
+hash_destroy(hash_table *table, char *key, void (*nukefunc)())
+{
+ int bucket = _hash(table->size, key);
+ hash_node *found = table->buckets[bucket];
+ hash_node *to_free = NODE_NULL;
+
+ if (!found) {
+ return;
+ }
+
+ if (!strcmp(found->key, key)) {
+ /*
+ * It was the head of the list.
+ */
+ table->buckets[bucket] = found->next;
+ to_free = found;
+ }
+ else {
+ /*
+ * Walk the list, looking one ahead.
+ */
+ while (found->next) {
+ if (!strcmp(found->next->key, key)) {
+ to_free = found->next;
+ found->next = found->next->next;
+ break;
+ }
+ found = found->next;
+ }
+
+ if (!to_free){
+ return;
+ }
+ }
+
+ if (nukefunc)
+ (*nukefunc)(to_free->key, to_free->data);
+ free(to_free);
+ return;
+}
+
+
+/*
+ * hash_search()
+ *
+ * Search the table for the given key. Then:
+ *
+ * 1) If you find it and there is no replacement function, just
+ * return what you found. (This is a simple search).
+ * 2) If you find it and there is a replacement function, run
+ * the function on the data you found, and replace the old
+ * data with whatever is passed in datum. Return 0.
+ * 3) If you don't find it and there is some datum, insert a
+ * new item into the table. Insertions go at the front of
+ * the bucket. Return 0.
+ * 4) Otherwise just return 0.
+ *
+ */
+void *
+hash_search(hash_table *table, caddr_t key, void *datum,
+ void (*replace_func)())
+{
+ int bucket = _hash(table->size, key);
+ hash_node *found = list_find(key, table->buckets[bucket]);
+
+ if (found){
+ if (!replace_func){
+ return found->data;
+ }
+ else{
+ (*replace_func)(found->data);
+ found->data = datum;
+ }
+ }
+ else{
+ if (datum){
+
+ static int assign_key();
+
+ hash_node *new = (hash_node *)malloc(sizeof(hash_node));
+
+ if (!new || !assign_key(key, new)){
+ return GENERIC_NULL;
+ }
+ new->data = datum;
+ new->next = table->buckets[bucket];
+ table->buckets[bucket] = new;
+ return new;
+ }
+ }
+ return GENERIC_NULL;
+}
+
+
+/*
+ * assign_key()
+ *
+ * Set the key value of a node to be 'key'. Get some space from
+ * malloc and copy it in etc. Return 1 if all is well, 0 otherwise.
+ */
+static int
+assign_key(char *key, hash_node *node)
+{
+ if (!node || !key){
+ return 0;
+ }
+
+ if (!(node->key = (char *)malloc(strlen(key) + 1))){
+ return 0;
+ }
+
+ node->key[0] = '\0';
+ strcat(node->key, key);
+ return 1;
+}
+
+/*
+ * hash_traverse()
+ *
+ * Traverse the hash table and run the function func on the
+ * data found at each node and the argument we're passed for it.
+ */
+void
+hash_traverse(hash_table *table, int (*func)(), void *arg)
+{
+ register int i;
+ register int size = table->size;
+
+ if (!func)
+ return;
+
+ for (i = 0; i < size; i++) {
+ hash_node *n = table->buckets[i];
+ while (n) {
+ if ((*func)(n->key, n->data, arg) == 0)
+ return;
+ n = n->next;
+ }
+ }
+ return;
+}
+
+/*
+ * hash_purge()
+ *
+ * Run through the entire hash table. Call purge_func
+ * on the data found at each node, and then free the node.
+ * Set all the bucket pointers to 0.
+ */
+void
+hash_purge(hash_table *table, void (*purge_func)(char *p1, void *p2))
+{
+ register int i;
+ register int size = table->size;
+
+ for (i = 0; i < size; i++) {
+ hash_node *n = table->buckets[i];
+ if (n) {
+ do {
+ hash_node *to_free = n;
+ if (purge_func) {
+ (*purge_func)(n->key, n->data);
+ }
+ n = n->next;
+ free(to_free);
+ } while (n);
+ table->buckets[i] = NODE_NULL;
+ }
+ }
+}
+
+#undef min
+#define min(a, b) (a) < (b) ? (a) : (b)
+
+/*
+ * hash_stats()
+ *
+ * Print statistics about the current table allocation to stdout.
+ */
+void
+hash_stats(hash_table *table, int verbose)
+{
+ register int i;
+ int total_elements = 0;
+ int non_empty_buckets = 0;
+ int max_count = 0;
+ int max_repeats = 0;
+ int *counts;
+ int size = table->size;
+
+ if (!(counts = (int *)malloc(size * sizeof(int)))){
+ fprintf(stderr, "malloc returns 0\n");
+ exit(1);
+ }
+
+ for (i = 0; i < size; i++){
+ int x = 0;
+ hash_node *n = table->buckets[i];
+ counts[i] = 0;
+ while (n){
+ if (!x){
+ x = 1;
+ non_empty_buckets++;
+ if (verbose){
+ printf("bucket %2d: ", i);
+ }
+ }
+ if (verbose){
+ printf(" %s", n->key);
+ }
+ counts[i]++;
+ n = n->next;
+ }
+
+ total_elements += counts[i];
+ if (counts[i] > max_count){
+ max_count = counts[i];
+ max_repeats = 1;
+ }
+ else if (counts[i] == max_count){
+ max_repeats++;
+ }
+
+ if (counts[i] && verbose){
+ printf(" (%d)\n", counts[i]);
+ }
+ }
+
+ printf("\n");
+ printf("%d element%s in storage.\n", total_elements, total_elements == 1 ? "" : "s");
+
+ if (total_elements){
+ printf("%d of %d (%.2f%%) buckets are in use\n", non_empty_buckets, size,
+ (double)100 * (double)non_empty_buckets / (double)(size));
+ printf("the maximum number of elements in a bucket is %d (%d times)\n", max_count, max_repeats);
+ printf("average per bucket is %f\n", (double)total_elements / (double)non_empty_buckets);
+ printf("optimal would be %f\n", (double)total_elements / (double)(min(size, total_elements)));
+ }
+ return;
+}
diff --git a/lib/libc/stdlib/strtod.c b/lib/libc/stdlib/strtod.c
index cd82c73..27fb499 100644
--- a/lib/libc/stdlib/strtod.c
+++ b/lib/libc/stdlib/strtod.c
@@ -146,6 +146,7 @@ static char sccsid[] = "@(#)strtod.c 8.1 (Berkeley) 6/4/93";
#endif
#include "errno.h"
+#include <ctype.h>
#ifdef Bad_float_h
#undef __STDC__
#ifdef IEEE_MC68k
@@ -381,7 +382,7 @@ Balloc
int x;
Bigint *rv;
- if (rv = freelist[k]) {
+ if ( (rv = freelist[k]) ) {
freelist[k] = rv->next;
} else {
x = 1 << k;
@@ -627,7 +628,7 @@ mult
xc0 = c->x;
#ifdef Pack_32
for (; xb < xbe; xb++, xc0++) {
- if (y = *xb & 0xffff) {
+ if ( (y = *xb & 0xffff) ) {
x = xa;
xc = xc0;
carry = 0;
@@ -640,7 +641,7 @@ mult
} while (x < xae);
*xc = carry;
}
- if (y = *xb >> 16) {
+ if ( (y = *xb >> 16) ) {
x = xa;
xc = xc0;
carry = 0;
@@ -689,7 +690,7 @@ pow5mult
int i;
static int p05[3] = { 5, 25, 125 };
- if (i = k & 3)
+ if ( (i = k & 3) )
b = multadd(b, p05[i-1], 0);
if (!(k >>= 2))
@@ -751,7 +752,7 @@ lshift
*x1++ = *x << k | z;
z = *x++ >> k1;
} while (x < xe);
- if (*x1 = z)
+ if ( (*x1 = z) )
++n1;
}
#else
@@ -917,7 +918,7 @@ ulp
} else {
word0(a) = 0;
L -= Exp_shift;
- word1(a) = L >= 31 ? 1 : 1 << 31 - L;
+ word1(a) = L >= 31 ? 1 : 1 << (31 - L);
}
}
#endif
@@ -952,16 +953,16 @@ b2d
*e = 32 - k;
#ifdef Pack_32
if (k < Ebits) {
- d0 = Exp_1 | y >> Ebits - k;
+ d0 = Exp_1 | (y >> (Ebits - k));
w = xa > xa0 ? *--xa : 0;
- d1 = y << (32-Ebits) + k | w >> Ebits - k;
+ d1 = (y << ((32-Ebits) + k)) | (w >> (Ebits - k));
goto ret_d;
}
z = xa > xa0 ? *--xa : 0;
if (k -= Ebits) {
- d0 = Exp_1 | y << k | z >> 32 - k;
+ d0 = Exp_1 | (y << k) | (z >> (32 - k));
y = xa > xa0 ? *--xa : 0;
- d1 = z << k | y >> 32 - k;
+ d1 = (z << k) | (y >> (32 - k));
} else {
d0 = Exp_1 | y;
d1 = z;
@@ -1028,13 +1029,13 @@ d2b
z |= Exp_msk11;
#endif
#else
- if (de = (int)(d0 >> Exp_shift))
+ if ( (de = (int)(d0 >> Exp_shift)) )
z |= Exp_msk1;
#endif
#ifdef Pack_32
- if (y = d1) {
- if (k = lo0bits(&y)) {
- x[0] = y | z << 32 - k;
+ if ( (y = d1) ) {
+ if ( (k = lo0bits(&y)) ) {
+ x[0] = y | (z << (32 - k));
z >>= k;
}
else
@@ -1212,14 +1213,9 @@ strtod
case 0:
s = s00;
goto ret;
- case '\t':
- case '\n':
- case '\v':
- case '\f':
- case '\r':
- case ' ':
- continue;
default:
+ if (isspace((unsigned char)*s))
+ continue;
goto break2;
}
break2:
@@ -1375,9 +1371,9 @@ strtod
/* Get starting approximation = rv * 10**e1 */
if (e1 > 0) {
- if (i = e1 & 15)
+ if ( (i = e1 & 15) )
rv *= tens[i];
- if (e1 &= ~15) {
+ if ( (e1 &= ~15) ) {
if (e1 > DBL_MAX_10_EXP) {
ovfl:
errno = ERANGE;
@@ -1417,9 +1413,9 @@ strtod
}
} else if (e1 < 0) {
e1 = -e1;
- if (i = e1 & 15)
+ if ( (i = e1 & 15) )
rv /= tens[i];
- if (e1 &= ~15) {
+ if ( (e1 &= ~15) ) {
e1 >>= 4;
for (j = 0; e1 > 1; j++, e1 >>= 1)
if (e1 & 1)
@@ -1950,13 +1946,13 @@ __dtoa
#ifdef Sudden_Underflow
i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
#else
- if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) {
+ if ( (i = (int)((word0(d) >> Exp_shift1) & (Exp_mask>>Exp_shift1))) ) {
#endif
d2 = d;
word0(d2) &= Frac_mask1;
word0(d2) |= Exp_11;
#ifdef IBM
- if (j = 11 - hi0bits(word0(d2) & Frac_mask))
+ if ( (j = 11 - hi0bits(word0(d2) & Frac_mask)) )
d2 /= 1 << j;
#endif
@@ -1993,8 +1989,8 @@ __dtoa
/* d is denormalized */
i = bbits + be + (Bias + (P-1) - 1);
- x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32
- : word1(d) << 32 - i;
+ x = i > 32 ? ((word0(d) << (64 - i)) | (word1(d) >> (i - 32)))
+ : (word1(d) << (32 - i));
d2 = x;
word0(d2) -= 31*Exp_msk1; /* adjust exponent */
i -= (Bias + (P-1) - 1) + 1;
@@ -2091,7 +2087,7 @@ __dtoa
ds *= bigtens[i];
}
d /= ds;
- } else if (j1 = -k) {
+ } else if ( (j1 = -k) ) {
d *= tens[j1 & 0xf];
for (j = j1 >> 4; j; j >>= 1, i++)
if (j & 1) {
@@ -2190,7 +2186,7 @@ __dtoa
*s++ = '0' + (int)L;
if (i == ilim) {
d += d;
- if (d > ds || d == ds && L & 1) {
+ if (d > ds || (d == ds && L & 1)) {
bump_up:
while (*--s == '9')
if (s == s0) {
@@ -2254,7 +2250,7 @@ __dtoa
Bfree(b);
b = b1;
}
- if (j = b5 - m5)
+ if ( (j = b5 - m5) )
b = pow5mult(b, j);
} else
b = pow5mult(b, b5);
@@ -2287,10 +2283,10 @@ __dtoa
* can do shifts and ors to compute the numerator for q.
*/
#ifdef Pack_32
- if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f)
+ if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) )
i = 32 - i;
#else
- if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf)
+ if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) )
i = 16 - i;
#endif
if (i > 4) {
@@ -2363,15 +2359,15 @@ __dtoa
goto ret;
}
#endif
- if (j < 0 || j == 0 && !mode
+ if (j < 0 || (j == 0 && !mode
#ifndef ROUND_BIASED
&& !(word1(d) & 1)
#endif
- ) {
+ )) {
if (j1 > 0) {
b = lshift(b, 1);
j1 = cmp(b, S);
- if ((j1 > 0 || j1 == 0 && dig & 1)
+ if ((j1 > 0 || (j1 == 0 && dig & 1))
&& dig++ == '9')
goto round_9_up;
}
@@ -2410,7 +2406,7 @@ __dtoa
b = lshift(b, 1);
j = cmp(b, S);
- if (j > 0 || j == 0 && dig & 1) {
+ if (j > 0 || (j == 0 && dig & 1)) {
roundoff:
while (*--s == '9')
if (s == s0) {
diff --git a/lib/libc/stdlib/strtol.3 b/lib/libc/stdlib/strtol.3
index 4ebf069..3d43fb3 100644
--- a/lib/libc/stdlib/strtol.3
+++ b/lib/libc/stdlib/strtol.3
@@ -45,13 +45,13 @@
.Fd #include <stdlib.h>
.Fd #include <limits.h>
.Ft long
-.Fn strtol "char *nptr" "char **endptr" "int base"
+.Fn strtol "const char *nptr" "char **endptr" "int base"
.Fd #include <sys/types.h>
.Fd #include <stdlib.h>
.Fd #include <limits.h>
.Ft quad_t
-.Fn strtoq "char *nptr" "char **endptr" "int base"
+.Fn strtoq "const char *nptr" "char **endptr" "int base"
.Sh DESCRIPTION
The
.Fn strtol
diff --git a/lib/libc/stdlib/strtol.c b/lib/libc/stdlib/strtol.c
index 1a7f7b3..18e3972 100644
--- a/lib/libc/stdlib/strtol.c
+++ b/lib/libc/stdlib/strtol.c
@@ -55,7 +55,7 @@ strtol(nptr, endptr, base)
{
register const char *s = nptr;
register unsigned long acc;
- register int c;
+ register unsigned char c;
register unsigned long cutoff;
register int neg = 0, any, cutlim;
@@ -102,6 +102,8 @@ strtol(nptr, endptr, base)
cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
+ if (!isascii(c))
+ break;
if (isdigit(c))
c -= '0';
else if (isalpha(c))
@@ -110,7 +112,7 @@ strtol(nptr, endptr, base)
break;
if (c >= base)
break;
- if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
diff --git a/lib/libc/stdlib/strtoll.c b/lib/libc/stdlib/strtoll.c
new file mode 100644
index 0000000..2666749
--- /dev/null
+++ b/lib/libc/stdlib/strtoll.c
@@ -0,0 +1,138 @@
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+
+#include <limits.h>
+#include <errno.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+/*
+ * Convert a string to a quad integer.
+ *
+ * Ignores `locale' stuff. Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+quad_t
+strtoq(nptr, endptr, base)
+ const char *nptr;
+ char **endptr;
+ register int base;
+{
+ register const char *s;
+ register u_quad_t acc;
+ register unsigned char c;
+ register u_quad_t qbase, cutoff;
+ register int neg, any, cutlim;
+
+ /*
+ * Skip white space and pick up leading +/- sign if any.
+ * If base is 0, allow 0x for hex and 0 for octal, else
+ * assume decimal; if base is already 16, allow 0x.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+ } while (isspace(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')) {
+ c = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = c == '0' ? 8 : 10;
+
+ /*
+ * Compute the cutoff value between legal numbers and illegal
+ * numbers. That is the largest legal value, divided by the
+ * base. An input number that is greater than this value, if
+ * followed by a legal input character, is too big. One that
+ * is equal to this value may be valid or not; the limit
+ * between valid and invalid numbers is then based on the last
+ * digit. For instance, if the range for quads is
+ * [-9223372036854775808..9223372036854775807] and the input base
+ * is 10, cutoff will be set to 922337203685477580 and cutlim to
+ * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+ * accumulated a value > 922337203685477580, or equal but the
+ * next digit is > 7 (or 8), the number is too big, and we will
+ * return a range error.
+ *
+ * Set any if any `digits' consumed; make it negative to indicate
+ * overflow.
+ */
+ qbase = (unsigned)base;
+ cutoff = neg ? -(u_quad_t)QUAD_MIN : QUAD_MAX;
+ cutlim = cutoff % qbase;
+ cutoff /= qbase;
+ for (acc = 0, any = 0;; c = *s++) {
+ if (!isascii(c))
+ break;
+ if (isdigit(c))
+ c -= '0';
+ else if (isalpha(c))
+ c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+ else
+ break;
+ if (c >= base)
+ break;
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+ any = -1;
+ else {
+ any = 1;
+ acc *= qbase;
+ acc += c;
+ }
+ }
+ if (any < 0) {
+ acc = neg ? QUAD_MIN : QUAD_MAX;
+ errno = ERANGE;
+ } else if (neg)
+ acc = -acc;
+ if (endptr != 0)
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+}
diff --git a/lib/libc/stdlib/strtoq.c b/lib/libc/stdlib/strtoq.c
index b31cca4..2666749 100644
--- a/lib/libc/stdlib/strtoq.c
+++ b/lib/libc/stdlib/strtoq.c
@@ -56,7 +56,7 @@ strtoq(nptr, endptr, base)
{
register const char *s;
register u_quad_t acc;
- register int c;
+ register unsigned char c;
register u_quad_t qbase, cutoff;
register int neg, any, cutlim;
@@ -109,6 +109,8 @@ strtoq(nptr, endptr, base)
cutlim = cutoff % qbase;
cutoff /= qbase;
for (acc = 0, any = 0;; c = *s++) {
+ if (!isascii(c))
+ break;
if (isdigit(c))
c -= '0';
else if (isalpha(c))
@@ -117,7 +119,7 @@ strtoq(nptr, endptr, base)
break;
if (c >= base)
break;
- if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
diff --git a/lib/libc/stdlib/strtoul.c b/lib/libc/stdlib/strtoul.c
index e60556c0..304150a 100644
--- a/lib/libc/stdlib/strtoul.c
+++ b/lib/libc/stdlib/strtoul.c
@@ -54,7 +54,7 @@ strtoul(nptr, endptr, base)
{
register const char *s = nptr;
register unsigned long acc;
- register int c;
+ register unsigned char c;
register unsigned long cutoff;
register int neg = 0, any, cutlim;
@@ -80,6 +80,8 @@ strtoul(nptr, endptr, base)
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
+ if (!isascii(c))
+ break;
if (isdigit(c))
c -= '0';
else if (isalpha(c))
@@ -88,7 +90,7 @@ strtoul(nptr, endptr, base)
break;
if (c >= base)
break;
- if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
diff --git a/lib/libc/stdlib/strtoull.c b/lib/libc/stdlib/strtoull.c
new file mode 100644
index 0000000..7656a3c
--- /dev/null
+++ b/lib/libc/stdlib/strtoull.c
@@ -0,0 +1,116 @@
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 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[] = "@(#)strtouq.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+
+#include <limits.h>
+#include <errno.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+/*
+ * Convert a string to an unsigned quad integer.
+ *
+ * Ignores `locale' stuff. Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+u_quad_t
+strtouq(nptr, endptr, base)
+ const char *nptr;
+ char **endptr;
+ register int base;
+{
+ register const char *s = nptr;
+ register u_quad_t acc;
+ register unsigned char c;
+ register u_quad_t qbase, cutoff;
+ register int neg, any, cutlim;
+
+ /*
+ * See strtoq for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+ } while (isspace(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')) {
+ c = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = c == '0' ? 8 : 10;
+ qbase = (unsigned)base;
+ cutoff = (u_quad_t)UQUAD_MAX / qbase;
+ cutlim = (u_quad_t)UQUAD_MAX % qbase;
+ for (acc = 0, any = 0;; c = *s++) {
+ if (!isascii(c))
+ break;
+ if (isdigit(c))
+ c -= '0';
+ else if (isalpha(c))
+ c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+ else
+ break;
+ if (c >= base)
+ break;
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+ any = -1;
+ else {
+ any = 1;
+ acc *= qbase;
+ acc += c;
+ }
+ }
+ if (any < 0) {
+ acc = UQUAD_MAX;
+ errno = ERANGE;
+ } else if (neg)
+ acc = -acc;
+ if (endptr != 0)
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+}
diff --git a/lib/libc/stdlib/strtouq.c b/lib/libc/stdlib/strtouq.c
index cc62a07..7656a3c 100644
--- a/lib/libc/stdlib/strtouq.c
+++ b/lib/libc/stdlib/strtouq.c
@@ -56,7 +56,7 @@ strtouq(nptr, endptr, base)
{
register const char *s = nptr;
register u_quad_t acc;
- register int c;
+ register unsigned char c;
register u_quad_t qbase, cutoff;
register int neg, any, cutlim;
@@ -70,7 +70,7 @@ strtouq(nptr, endptr, base)
if (c == '-') {
neg = 1;
c = *s++;
- } else {
+ } else {
neg = 0;
if (c == '+')
c = *s++;
@@ -87,6 +87,8 @@ strtouq(nptr, endptr, base)
cutoff = (u_quad_t)UQUAD_MAX / qbase;
cutlim = (u_quad_t)UQUAD_MAX % qbase;
for (acc = 0, any = 0;; c = *s++) {
+ if (!isascii(c))
+ break;
if (isdigit(c))
c -= '0';
else if (isalpha(c))
@@ -95,7 +97,7 @@ strtouq(nptr, endptr, base)
break;
if (c >= base)
break;
- if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
diff --git a/lib/libc/stdlib/system.3 b/lib/libc/stdlib/system.3
index d89c79e..9b82e7b 100644
--- a/lib/libc/stdlib/system.3
+++ b/lib/libc/stdlib/system.3
@@ -76,7 +76,7 @@ The
.Fn system
function
returns the exit status of the shell, or \-1 if the
-.Xr wait 3
+.Xr wait 2
for the shell failed.
A return value of 127 means the execution of the shell
failed.
@@ -91,3 +91,6 @@ The
function
conforms to
.St -ansiC .
+and is expected to be
+.St -p1003.2
+compatible.
diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c
index c438f17..00db7d6 100644
--- a/lib/libc/stdlib/system.c
+++ b/lib/libc/stdlib/system.c
@@ -42,35 +42,51 @@ static char sccsid[] = "@(#)system.c 8.1 (Berkeley) 6/4/93";
#include <stddef.h>
#include <unistd.h>
#include <paths.h>
+#include <errno.h>
-system(command)
+int system(command)
const char *command;
{
- union wait pstat;
pid_t pid;
- int omask;
- sig_t intsave, quitsave;
+ int pstat;
+ struct sigaction ign, intact, quitact;
+ sigset_t newsigblock, oldsigblock;
if (!command) /* just checking... */
return(1);
- omask = sigblock(sigmask(SIGCHLD));
- switch(pid = vfork()) {
+ /*
+ * Ignore SIGINT and SIGQUIT, block SIGCHLD. Remember to save
+ * existing signal dispositions.
+ */
+ ign.sa_handler = SIG_IGN;
+ (void)sigemptyset(&ign.sa_mask);
+ ign.sa_flags = 0;
+ (void)sigaction(SIGINT, &ign, &intact);
+ (void)sigaction(SIGQUIT, &ign, &quitact);
+ (void)sigemptyset(&newsigblock);
+ (void)sigaddset(&newsigblock, SIGCHLD);
+ (void)sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock);
+ switch(pid = fork()) {
case -1: /* error */
- (void)sigsetmask(omask);
- pstat.w_status = 0;
- pstat.w_retcode = 127;
- return(pstat.w_status);
+ break;
case 0: /* child */
- (void)sigsetmask(omask);
+ /*
+ * Restore original signal dispositions and exec the command.
+ */
+ (void)sigaction(SIGINT, &intact, NULL);
+ (void)sigaction(SIGQUIT, &quitact, NULL);
+ (void)sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL);
_exit(127);
+ default: /* parent */
+ do {
+ pid = waitpid(pid, &pstat, 0);
+ } while (pid == -1 && errno == EINTR);
+ break;
}
- intsave = signal(SIGINT, SIG_IGN);
- quitsave = signal(SIGQUIT, SIG_IGN);
- pid = waitpid(pid, (int *)&pstat, 0);
- (void)sigsetmask(omask);
- (void)signal(SIGINT, intsave);
- (void)signal(SIGQUIT, quitsave);
- return(pid == -1 ? -1 : pstat.w_status);
+ (void)sigaction(SIGINT, &intact, NULL);
+ (void)sigaction(SIGQUIT, &quitact, NULL);
+ (void)sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
+ return(pid == -1 ? -1 : pstat);
}
diff --git a/lib/libc/stdtime/Makefile.inc b/lib/libc/stdtime/Makefile.inc
new file mode 100644
index 0000000..cdd4b8a
--- /dev/null
+++ b/lib/libc/stdtime/Makefile.inc
@@ -0,0 +1,16 @@
+# Makefile.inc,v 1.2 1994/09/13 21:26:01 wollman Exp
+# $Id$
+
+.PATH: ${.CURDIR}/../libc/stdtime
+
+SRCS+= asctime.c localtime.c strftime.c difftime.c
+
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN5+= stdtime/tzfile.5
+MAN3+= stdtime/ctime.3 stdtime/strftime.3 stdtime/time2posix.3
+
+MLINKS+=ctime.3 asctime.3 ctime.3 difftime.3 ctime.3 gmtime.3 \
+ ctime.3 localtime.3 ctime.3 mktime.3
+MLINKS+=time2posix.3 posix2time.3
+.endif
diff --git a/lib/libc/stdtime/asctime.c b/lib/libc/stdtime/asctime.c
new file mode 100644
index 0000000..a1834b6
--- /dev/null
+++ b/lib/libc/stdtime/asctime.c
@@ -0,0 +1,61 @@
+/*
+** This file is in the public domain, so clarified as of
+** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
+*/
+
+#ifndef lint
+#ifndef NOID
+static char elsieid[] = "@(#)asctime.c 7.7";
+#endif /* !defined NOID */
+#endif /* !defined lint */
+
+/*LINTLIBRARY*/
+
+#include "private.h"
+#include "tzfile.h"
+
+/*
+** A la X3J11, with core dump avoidance.
+*/
+
+char *
+asctime(timeptr)
+register const struct tm * timeptr;
+{
+ static const char wday_name[][3] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+ };
+ static const char mon_name[][3] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ };
+ /*
+ ** Big enough for something such as
+ ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
+ ** (two three-character abbreviations, five strings denoting integers,
+ ** three explicit spaces, two explicit colons, a newline,
+ ** and a trailing ASCII nul).
+ */
+ static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
+ 3 + 2 + 1 + 1];
+ register const char * wn;
+ register const char * mn;
+
+ if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
+ wn = "???";
+ else wn = wday_name[timeptr->tm_wday];
+ if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
+ mn = "???";
+ else mn = mon_name[timeptr->tm_mon];
+ /*
+ ** The X3J11-suggested format is
+ ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
+ ** Since the .2 in 02.2d is ignored, we drop it.
+ */
+ (void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
+ wn, mn,
+ timeptr->tm_mday, timeptr->tm_hour,
+ timeptr->tm_min, timeptr->tm_sec,
+ TM_YEAR_BASE + timeptr->tm_year);
+ return result;
+}
diff --git a/lib/libc/stdtime/ctime.3 b/lib/libc/stdtime/ctime.3
new file mode 100644
index 0000000..eccb664
--- /dev/null
+++ b/lib/libc/stdtime/ctime.3
@@ -0,0 +1,257 @@
+.\" Copyright (c) 1989, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Arthur Olson.
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\" @(#)ctime.3 8.1 (Berkeley) 6/4/93
+.\"
+.Dd June 4, 1993
+.Dt CTIME 3
+.Os BSD 4.3
+.Sh NAME
+.Nm asctime ,
+.Nm ctime ,
+.Nm difftime ,
+.Nm gmtime ,
+.Nm localtime ,
+.Nm mktime
+.Nd transform binary date and time value to
+.Tn ASCII
+.Sh SYNOPSIS
+.Fd #include <time.h>
+.Vt extern char *tzname[2];
+.Ft char *
+.Fn ctime "const time_t *clock"
+.Ft double
+.Fn difftime "time_t time1" "time_t time0"
+.Ft char *
+.Fn asctime "const struct tm *tm"
+.Ft struct tm *
+.Fn localtime "const time_t *clock"
+.Ft struct tm *
+.Fn gmtime "const time_t *clock"
+.Ft time_t
+.Fn mktime "struct tm *tm"
+.Sh DESCRIPTION
+The functions
+.Fn ctime ,
+.Fn gmtime
+and
+.Fn localtime
+all take as an argument a time value representing the time in seconds since
+the Epoch (00:00:00
+.Tn UTC ,
+January 1, 1970; see
+.Xr time 3 ) .
+.Pp
+The function
+.Fn localtime
+converts the time value pointed at by
+.Fa clock ,
+and returns a pointer to a
+.Dq Fa struct tm
+(described below) which contains
+the broken-out time information for the value after adjusting for the current
+time zone (and any other factors such as Daylight Saving Time).
+Time zone adjustments are performed as specified by the
+.Ev TZ
+environmental variable (see
+.Xr tzset 3 ) .
+The function
+.Fn localtime
+uses
+.Xr tzset 3
+to initialize time conversion information if
+.Xr tzset 3
+has not already been called by the process.
+.Pp
+After filling in the tm structure,
+.Fn localtime
+sets the
+.Fa tm_isdst Ns 'th
+element of
+.Fa tzname
+to a pointer to an
+.Tn ASCII
+string that's the time zone abbreviation to be
+used with
+.Fn localtime Ns 's
+return value.
+.Pp
+The function
+.Fn gmtime
+similarly converts the time value, but without any time zone adjustment,
+and returns a pointer to a tm structure (described below).
+.Pp
+The
+.Fn ctime
+function
+adjusts the time value for the current time zone in the same manner as
+.Fn localtime ,
+and returns a pointer to a 26-character string of the form:
+.Bd -literal -offset indent
+Thu Nov 24 18:22:48 1986\en\e0
+.Ed
+.Pp
+All the fields have constant width.
+.Pp
+The
+.Fn asctime
+function
+converts the broken down time in the structure
+.Fa tm
+pointed at by
+.Fa *tm
+to the form
+shown in the example above.
+.Pp
+The function
+.Fn mktime
+converts the broken-down time, expressed as local time, in the structure
+pointed to by tm into a time value with the same encoding as that of the
+values returned by the
+.Xr time 3
+function, that is, seconds from the Epoch,
+.Tn UTC .
+.Pp
+The original values of the
+.Fa tm_wday
+and
+.Fa tm_yday
+components of the structure are ignored, and the original values of the
+other components are not restricted to their normal ranges.
+(A positive or zero value for
+.Fa tm_isdst
+causes
+.Fn mktime
+to presume initially that summer time (for example, Daylight Saving Time)
+is or is not in effect for the specified time, respectively.
+A negative value for
+.Fa tm_isdst
+causes the
+.Fn mktime
+function to attempt to divine whether summer time is in effect for the
+specified time.)
+.Pp
+On successful completion, the values of the
+.Fa tm_wday
+and
+.Fa tm_yday
+components of the structure are set appropriately, and the other components
+are set to represent the specified calendar time, but with their values
+forced to their normal ranges; the final value of
+.Fa tm_mday
+is not set until
+.Fa tm_mon
+and
+.Fa tm_year
+are determined.
+.Fn Mktime
+returns the specified calendar time; if the calendar time cannot be
+represented, it returns \-1;
+.Pp
+The
+.Fn difftime
+function
+returns the difference between two calendar times,
+.Pf ( Fa time1
+-
+.Fa time0 ) ,
+expressed in seconds.
+.Pp
+External declarations as well as the tm structure definition are in the
+.Aq Pa time.h
+include file.
+The tm structure includes at least the following fields:
+.Bd -literal -offset indent
+int tm_sec; /\(** seconds (0 - 60) \(**/
+int tm_min; /\(** minutes (0 - 59) \(**/
+int tm_hour; /\(** hours (0 - 23) \(**/
+int tm_mday; /\(** day of month (1 - 31) \(**/
+int tm_mon; /\(** month of year (0 - 11) \(**/
+int tm_year; /\(** year \- 1900 \(**/
+int tm_wday; /\(** day of week (Sunday = 0) \(**/
+int tm_yday; /\(** day of year (0 - 365) \(**/
+int tm_isdst; /\(** is summer time in effect? \(**/
+char \(**tm_zone; /\(** abbreviation of timezone name \(**/
+long tm_gmtoff; /\(** offset from UTC in seconds \(**/
+.Ed
+.Pp
+The
+field
+.Fa tm_isdst
+is non-zero if summer time is in effect.
+.Pp
+The field
+.Fa tm_gmtoff
+is the offset (in seconds) of the time represented from
+.Tn UTC ,
+with positive
+values indicating east of the Prime Meridian.
+.Sh SEE ALSO
+.Xr date 1 ,
+.Xr gettimeofday 2 ,
+.Xr getenv 3 ,
+.Xr time 3 ,
+.Xr tzset 3 ,
+.Xr tzfile 5
+.Sh HISTORY
+This manual page is derived from
+the time package contributed to Berkeley by
+Arthur Olsen and which appeared in
+.Bx 4.3 .
+.Sh BUGS
+Except for
+.Fn difftime
+and
+.Fn mktime ,
+these functions leaves their result in an internal static object and return
+a pointer to that object. Subsequent calls to these
+function will modify the same object.
+.Pp
+The
+.Fa tm_zone
+field of a returned tm structure points to a static array of characters,
+which will also be overwritten by any subsequent calls (as well as by
+subsequent calls to
+.Xr tzset 3
+and
+.Xr tzsetwall 3 ) .
+.Pp
+Use of the external variable
+.Fa tzname
+is discouraged; the
+.Fa tm_zone
+entry in the tm structure is preferred.
+.Pp
+Avoid using out-of-range values with
+.Fn mktime
+when setting up lunch with promptness sticklers in Riyadh.
diff --git a/lib/libc/stdtime/difftime.c b/lib/libc/stdtime/difftime.c
new file mode 100644
index 0000000..f178524
--- /dev/null
+++ b/lib/libc/stdtime/difftime.c
@@ -0,0 +1,77 @@
+/*
+** This file is in the public domain, so clarified as of
+** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
+*/
+
+#ifndef lint
+#ifndef NOID
+static char elsieid[] = "@(#)difftime.c 7.7";
+#endif /* !defined NOID */
+#endif /* !defined lint */
+
+/*LINTLIBRARY*/
+
+#include "private.h"
+
+/*
+** Algorithm courtesy Paul Eggert (eggert@twinsun.com).
+*/
+
+#ifdef HAVE_LONG_DOUBLE
+#define long_double long double
+#endif /* defined HAVE_LONG_DOUBLE */
+#ifndef HAVE_LONG_DOUBLE
+#define long_double double
+#endif /* !defined HAVE_LONG_DOUBLE */
+
+double
+difftime(time1, time0)
+const time_t time1;
+const time_t time0;
+{
+ time_t delta;
+ time_t hibit;
+
+ if (sizeof(time_t) < sizeof(double))
+ return (double) time1 - (double) time0;
+ if (sizeof(time_t) < sizeof(long_double))
+ return (long_double) time1 - (long_double) time0;
+ if (time1 < time0)
+ return -difftime(time0, time1);
+ /*
+ ** As much as possible, avoid loss of precision
+ ** by computing the difference before converting to double.
+ */
+ delta = time1 - time0;
+ if (delta >= 0)
+ return delta;
+ /*
+ ** Repair delta overflow.
+ */
+ hibit = (~ (time_t) 0) << (TYPE_BIT(time_t) - 1);
+ /*
+ ** The following expression rounds twice, which means
+ ** the result may not be the closest to the true answer.
+ ** For example, suppose time_t is 64-bit signed int,
+ ** long_double is IEEE 754 double with default rounding,
+ ** time1 = 9223372036854775807 and time0 = -1536.
+ ** Then the true difference is 9223372036854777343,
+ ** which rounds to 9223372036854777856
+ ** with a total error of 513.
+ ** But delta overflows to -9223372036854774273,
+ ** which rounds to -9223372036854774784, and correcting
+ ** this by subtracting 2 * (long_double) hibit
+ ** (i.e. by adding 2**64 = 18446744073709551616)
+ ** yields 9223372036854776832, which
+ ** rounds to 9223372036854775808
+ ** with a total error of 1535 instead.
+ ** This problem occurs only with very large differences.
+ ** It's too painful to fix this portably.
+ ** We are not alone in this problem;
+ ** some C compilers round twice when converting
+ ** large unsigned types to small floating types,
+ ** so if time_t is unsigned the "return delta" above
+ ** has the same double-rounding problem with those compilers.
+ */
+ return delta - 2 * (long_double) hibit;
+}
diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c
new file mode 100644
index 0000000..3438cc6
--- /dev/null
+++ b/lib/libc/stdtime/localtime.c
@@ -0,0 +1,1754 @@
+/*
+** This file is in the public domain, so clarified as of
+** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
+*/
+
+#ifndef lint
+#ifndef NOID
+static char elsieid[] = "@(#)localtime.c 7.57";
+#endif /* !defined NOID */
+#endif /* !defined lint */
+
+/*
+** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu).
+** POSIX-style TZ environment variable handling from Guy Harris
+** (guy@auspex.com).
+*/
+
+/*LINTLIBRARY*/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "private.h"
+#include "tzfile.h"
+#include "fcntl.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
+
+/*
+** SunOS 4.1.1 headers lack O_BINARY.
+*/
+
+#ifdef O_BINARY
+#define OPEN_MODE (O_RDONLY | O_BINARY)
+#endif /* defined O_BINARY */
+#ifndef O_BINARY
+#define OPEN_MODE O_RDONLY
+#endif /* !defined O_BINARY */
+
+#ifndef WILDABBR
+/*
+** Someone might make incorrect use of a time zone abbreviation:
+** 1. They might reference tzname[0] before calling tzset (explicitly
+** or implicitly).
+** 2. They might reference tzname[1] before calling tzset (explicitly
+** or implicitly).
+** 3. They might reference tzname[1] after setting to a time zone
+** in which Daylight Saving Time is never observed.
+** 4. They might reference tzname[0] after setting to a time zone
+** in which Standard Time is never observed.
+** 5. They might reference tm.TM_ZONE after calling offtime.
+** What's best to do in the above cases is open to debate;
+** for now, we just set things up so that in any of the five cases
+** WILDABBR is used. Another possibility: initialize tzname[0] to the
+** string "tzname[0] used before set", and similarly for the other cases.
+** And another: initialize tzname[0] to "ERA", with an explanation in the
+** manual page of what this "time zone abbreviation" means (doing this so
+** that tzname[0] has the "normal" length of three characters).
+*/
+#define WILDABBR " "
+#endif /* !defined WILDABBR */
+
+static char wildabbr[] = "WILDABBR";
+
+static const char gmt[] = "GMT";
+
+struct ttinfo { /* time type information */
+ long tt_gmtoff; /* GMT offset in seconds */
+ int tt_isdst; /* used to set tm_isdst */
+ int tt_abbrind; /* abbreviation list index */
+ int tt_ttisstd; /* TRUE if transition is std time */
+ int tt_ttisgmt; /* TRUE if transition is GMT */
+};
+
+struct lsinfo { /* leap second information */
+ time_t ls_trans; /* transition time */
+ long ls_corr; /* correction to apply */
+};
+
+#define BIGGEST(a, b) (((a) > (b)) ? (a) : (b))
+
+#ifdef TZNAME_MAX
+#define MY_TZNAME_MAX TZNAME_MAX
+#endif /* defined TZNAME_MAX */
+#ifndef TZNAME_MAX
+#define MY_TZNAME_MAX 255
+#endif /* !defined TZNAME_MAX */
+
+struct state {
+ int leapcnt;
+ int timecnt;
+ int typecnt;
+ int charcnt;
+ time_t ats[TZ_MAX_TIMES];
+ unsigned char types[TZ_MAX_TIMES];
+ struct ttinfo ttis[TZ_MAX_TYPES];
+ char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt),
+ (2 * (MY_TZNAME_MAX + 1)))];
+ struct lsinfo lsis[TZ_MAX_LEAPS];
+};
+
+struct rule {
+ int r_type; /* type of rule--see below */
+ int r_day; /* day number of rule */
+ int r_week; /* week number of rule */
+ int r_mon; /* month number of rule */
+ long r_time; /* transition time of rule */
+};
+
+#define JULIAN_DAY 0 /* Jn - Julian day */
+#define DAY_OF_YEAR 1 /* n - day of year */
+#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
+
+/*
+** Prototypes for static functions.
+*/
+
+static long detzcode P((const char * codep));
+static const char * getzname P((const char * strp));
+static const char * getnum P((const char * strp, int * nump, int min,
+ int max));
+static const char * getsecs P((const char * strp, long * secsp));
+static const char * getoffset P((const char * strp, long * offsetp));
+static const char * getrule P((const char * strp, struct rule * rulep));
+static void gmtload P((struct state * sp));
+static void gmtsub P((const time_t * timep, long offset,
+ struct tm * tmp));
+static void localsub P((const time_t * timep, long offset,
+ struct tm * tmp));
+static int increment_overflow P((int * number, int delta));
+static int normalize_overflow P((int * tensptr, int * unitsptr,
+ int base));
+static void settzname P((void));
+static time_t time1 P((struct tm * tmp,
+ void(*funcp) P((const time_t *,
+ long, struct tm *)),
+ long offset));
+static time_t time2 P((struct tm *tmp,
+ void(*funcp) P((const time_t *,
+ long, struct tm*)),
+ long offset, int * okayp));
+static void timesub P((const time_t * timep, long offset,
+ const struct state * sp, struct tm * tmp));
+static int tmcomp P((const struct tm * atmp,
+ const struct tm * btmp));
+static time_t transtime P((time_t janfirst, int year,
+ const struct rule * rulep, long offset));
+static int tzload P((const char * name, struct state * sp));
+static int tzparse P((const char * name, struct state * sp,
+ int lastditch));
+
+#ifdef ALL_STATE
+static struct state * lclptr;
+static struct state * gmtptr;
+#endif /* defined ALL_STATE */
+
+#ifndef ALL_STATE
+static struct state lclmem;
+static struct state gmtmem;
+#define lclptr (&lclmem)
+#define gmtptr (&gmtmem)
+#endif /* State Farm */
+
+#ifndef TZ_STRLEN_MAX
+#define TZ_STRLEN_MAX 255
+#endif /* !defined TZ_STRLEN_MAX */
+
+static char lcl_TZname[TZ_STRLEN_MAX + 1];
+static int lcl_is_set;
+static int gmt_is_set;
+#ifdef _THREAD_SAFE
+static struct pthread_mutex _lcl_mutexd = PTHREAD_MUTEX_INITIALIZER;
+static struct pthread_mutex _gmt_mutexd = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t lcl_mutex = &_lcl_mutexd;
+static pthread_mutex_t gmt_mutex = &_gmt_mutexd;
+#endif
+
+char * tzname[2] = {
+ wildabbr,
+ wildabbr
+};
+
+/*
+** Section 4.12.3 of X3.159-1989 requires that
+** Except for the strftime function, these functions [asctime,
+** ctime, gmtime, localtime] return values in one of two static
+** objects: a broken-down time structure and an array of char.
+** Thanks to Paul Eggert (eggert@twinsun.com) for noting this.
+*/
+
+static struct tm tm;
+
+#ifdef USG_COMPAT
+time_t timezone = 0;
+int daylight = 0;
+#endif /* defined USG_COMPAT */
+
+#ifdef ALTZONE
+time_t altzone = 0;
+#endif /* defined ALTZONE */
+
+static long
+detzcode(codep)
+const char * const codep;
+{
+ register long result;
+ register int i;
+
+ result = (codep[0] & 0x80) ? ~0L : 0L;
+ for (i = 0; i < 4; ++i)
+ result = (result << 8) | (codep[i] & 0xff);
+ return result;
+}
+
+static void
+settzname P((void))
+{
+ register struct state * const sp = lclptr;
+ register int i;
+
+ tzname[0] = wildabbr;
+ tzname[1] = wildabbr;
+#ifdef USG_COMPAT
+ daylight = 0;
+ timezone = 0;
+#endif /* defined USG_COMPAT */
+#ifdef ALTZONE
+ altzone = 0;
+#endif /* defined ALTZONE */
+#ifdef ALL_STATE
+ if (sp == NULL) {
+ tzname[0] = tzname[1] = gmt;
+ return;
+ }
+#endif /* defined ALL_STATE */
+ for (i = 0; i < sp->typecnt; ++i) {
+ register const struct ttinfo * const ttisp = &sp->ttis[i];
+
+ tzname[ttisp->tt_isdst] =
+ &sp->chars[ttisp->tt_abbrind];
+#ifdef USG_COMPAT
+ if (ttisp->tt_isdst)
+ daylight = 1;
+ if (i == 0 || !ttisp->tt_isdst)
+ timezone = -(ttisp->tt_gmtoff);
+#endif /* defined USG_COMPAT */
+#ifdef ALTZONE
+ if (i == 0 || ttisp->tt_isdst)
+ altzone = -(ttisp->tt_gmtoff);
+#endif /* defined ALTZONE */
+ }
+ /*
+ ** And to get the latest zone names into tzname. . .
+ */
+ for (i = 0; i < sp->timecnt; ++i) {
+ register const struct ttinfo * const ttisp =
+ &sp->ttis[
+ sp->types[i]];
+
+ tzname[ttisp->tt_isdst] =
+ &sp->chars[ttisp->tt_abbrind];
+ }
+}
+
+static int
+tzload(name, sp)
+register const char * name;
+register struct state * const sp;
+{
+ register const char * p;
+ register int i;
+ register int fid;
+
+ if (name == NULL && (name = TZDEFAULT) == NULL)
+ return -1;
+ {
+ register int doaccess;
+ struct stat stab;
+ /*
+ ** Section 4.9.1 of the C standard says that
+ ** "FILENAME_MAX expands to an integral constant expression
+ ** that is the size needed for an array of char large enough
+ ** to hold the longest file name string that the implementation
+ ** guarantees can be opened."
+ */
+ char fullname[FILENAME_MAX + 1];
+
+ if (name[0] == ':')
+ ++name;
+ doaccess = name[0] == '/';
+ if (!doaccess) {
+ if ((p = TZDIR) == NULL)
+ return -1;
+ if ((strlen(p) + strlen(name) + 1) >= sizeof fullname)
+ return -1;
+ (void) strcpy(fullname, p);
+ (void) strcat(fullname, "/");
+ (void) strcat(fullname, name);
+ /*
+ ** Set doaccess if '.' (as in "../") shows up in name.
+ */
+ if (strchr(name, '.') != NULL)
+ doaccess = TRUE;
+ name = fullname;
+ }
+ if (doaccess && access(name, R_OK) != 0)
+ return -1;
+ if ((fid = open(name, OPEN_MODE)) == -1)
+ return -1;
+ if ((fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode))
+ return -1;
+ }
+ {
+ struct tzhead * tzhp;
+ char buf[sizeof *sp + sizeof *tzhp];
+ int ttisstdcnt;
+ int ttisgmtcnt;
+
+ i = read(fid, buf, sizeof buf);
+ if (close(fid) != 0)
+ return -1;
+ p = buf;
+ p += sizeof tzhp->tzh_reserved;
+ ttisstdcnt = (int) detzcode(p);
+ p += 4;
+ ttisgmtcnt = (int) detzcode(p);
+ p += 4;
+ sp->leapcnt = (int) detzcode(p);
+ p += 4;
+ sp->timecnt = (int) detzcode(p);
+ p += 4;
+ sp->typecnt = (int) detzcode(p);
+ p += 4;
+ sp->charcnt = (int) detzcode(p);
+ p += 4;
+ if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS ||
+ sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES ||
+ sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES ||
+ sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS ||
+ (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) ||
+ (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
+ return -1;
+ if (i - (p - buf) < sp->timecnt * 4 + /* ats */
+ sp->timecnt + /* types */
+ sp->typecnt * (4 + 2) + /* ttinfos */
+ sp->charcnt + /* chars */
+ sp->leapcnt * (4 + 4) + /* lsinfos */
+ ttisstdcnt + /* ttisstds */
+ ttisgmtcnt) /* ttisgmts */
+ return -1;
+ for (i = 0; i < sp->timecnt; ++i) {
+ sp->ats[i] = detzcode(p);
+ p += 4;
+ }
+ for (i = 0; i < sp->timecnt; ++i) {
+ sp->types[i] = (unsigned char) *p++;
+ if (sp->types[i] >= sp->typecnt)
+ return -1;
+ }
+ for (i = 0; i < sp->typecnt; ++i) {
+ register struct ttinfo * ttisp;
+
+ ttisp = &sp->ttis[i];
+ ttisp->tt_gmtoff = detzcode(p);
+ p += 4;
+ ttisp->tt_isdst = (unsigned char) *p++;
+ if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1)
+ return -1;
+ ttisp->tt_abbrind = (unsigned char) *p++;
+ if (ttisp->tt_abbrind < 0 ||
+ ttisp->tt_abbrind > sp->charcnt)
+ return -1;
+ }
+ for (i = 0; i < sp->charcnt; ++i)
+ sp->chars[i] = *p++;
+ sp->chars[i] = '\0'; /* ensure '\0' at end */
+ for (i = 0; i < sp->leapcnt; ++i) {
+ register struct lsinfo * lsisp;
+
+ lsisp = &sp->lsis[i];
+ lsisp->ls_trans = detzcode(p);
+ p += 4;
+ lsisp->ls_corr = detzcode(p);
+ p += 4;
+ }
+ for (i = 0; i < sp->typecnt; ++i) {
+ register struct ttinfo * ttisp;
+
+ ttisp = &sp->ttis[i];
+ if (ttisstdcnt == 0)
+ ttisp->tt_ttisstd = FALSE;
+ else {
+ ttisp->tt_ttisstd = *p++;
+ if (ttisp->tt_ttisstd != TRUE &&
+ ttisp->tt_ttisstd != FALSE)
+ return -1;
+ }
+ }
+ for (i = 0; i < sp->typecnt; ++i) {
+ register struct ttinfo * ttisp;
+
+ ttisp = &sp->ttis[i];
+ if (ttisgmtcnt == 0)
+ ttisp->tt_ttisgmt = FALSE;
+ else {
+ ttisp->tt_ttisgmt = *p++;
+ if (ttisp->tt_ttisgmt != TRUE &&
+ ttisp->tt_ttisgmt != FALSE)
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
+
+static const int mon_lengths[2][MONSPERYEAR] = {
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+};
+
+static const int year_lengths[2] = {
+ DAYSPERNYEAR, DAYSPERLYEAR
+};
+
+/*
+** Given a pointer into a time zone string, scan until a character that is not
+** a valid character in a zone name is found. Return a pointer to that
+** character.
+*/
+
+static const char *
+getzname(strp)
+register const char * strp;
+{
+ register char c;
+
+ while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' &&
+ c != '+')
+ ++strp;
+ return strp;
+}
+
+/*
+** Given a pointer into a time zone string, extract a number from that string.
+** Check that the number is within a specified range; if it is not, return
+** NULL.
+** Otherwise, return a pointer to the first character not part of the number.
+*/
+
+static const char *
+getnum(strp, nump, min, max)
+register const char * strp;
+int * const nump;
+const int min;
+const int max;
+{
+ register char c;
+ register int num;
+
+ if (strp == NULL || !is_digit(c = *strp))
+ return NULL;
+ num = 0;
+ do {
+ num = num * 10 + (c - '0');
+ if (num > max)
+ return NULL; /* illegal value */
+ c = *++strp;
+ } while (is_digit(c));
+ if (num < min)
+ return NULL; /* illegal value */
+ *nump = num;
+ return strp;
+}
+
+/*
+** Given a pointer into a time zone string, extract a number of seconds,
+** in hh[:mm[:ss]] form, from the string.
+** If any error occurs, return NULL.
+** Otherwise, return a pointer to the first character not part of the number
+** of seconds.
+*/
+
+static const char *
+getsecs(strp, secsp)
+register const char * strp;
+long * const secsp;
+{
+ int num;
+
+ /*
+ ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
+ ** "M10.4.6/26", which does not conform to Posix,
+ ** but which specifies the equivalent of
+ ** ``02:00 on the first Sunday on or after 23 Oct''.
+ */
+ strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
+ if (strp == NULL)
+ return NULL;
+ *secsp = num * (long) SECSPERHOUR;
+ if (*strp == ':') {
+ ++strp;
+ strp = getnum(strp, &num, 0, MINSPERHOUR - 1);
+ if (strp == NULL)
+ return NULL;
+ *secsp += num * SECSPERMIN;
+ if (*strp == ':') {
+ ++strp;
+ /* `SECSPERMIN' allows for leap seconds. */
+ strp = getnum(strp, &num, 0, SECSPERMIN);
+ if (strp == NULL)
+ return NULL;
+ *secsp += num;
+ }
+ }
+ return strp;
+}
+
+/*
+** Given a pointer into a time zone string, extract an offset, in
+** [+-]hh[:mm[:ss]] form, from the string.
+** If any error occurs, return NULL.
+** Otherwise, return a pointer to the first character not part of the time.
+*/
+
+static const char *
+getoffset(strp, offsetp)
+register const char * strp;
+long * const offsetp;
+{
+ register int neg = 0;
+
+ if (*strp == '-') {
+ neg = 1;
+ ++strp;
+ } else if (*strp == '+')
+ ++strp;
+ strp = getsecs(strp, offsetp);
+ if (strp == NULL)
+ return NULL; /* illegal time */
+ if (neg)
+ *offsetp = -*offsetp;
+ return strp;
+}
+
+/*
+** Given a pointer into a time zone string, extract a rule in the form
+** date[/time]. See POSIX section 8 for the format of "date" and "time".
+** If a valid rule is not found, return NULL.
+** Otherwise, return a pointer to the first character not part of the rule.
+*/
+
+static const char *
+getrule(strp, rulep)
+const char * strp;
+register struct rule * const rulep;
+{
+ if (*strp == 'J') {
+ /*
+ ** Julian day.
+ */
+ rulep->r_type = JULIAN_DAY;
+ ++strp;
+ strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);
+ } else if (*strp == 'M') {
+ /*
+ ** Month, week, day.
+ */
+ rulep->r_type = MONTH_NTH_DAY_OF_WEEK;
+ ++strp;
+ strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);
+ if (strp == NULL)
+ return NULL;
+ if (*strp++ != '.')
+ return NULL;
+ strp = getnum(strp, &rulep->r_week, 1, 5);
+ if (strp == NULL)
+ return NULL;
+ if (*strp++ != '.')
+ return NULL;
+ strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
+ } else if (is_digit(*strp)) {
+ /*
+ ** Day of year.
+ */
+ rulep->r_type = DAY_OF_YEAR;
+ strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
+ } else return NULL; /* invalid format */
+ if (strp == NULL)
+ return NULL;
+ if (*strp == '/') {
+ /*
+ ** Time specified.
+ */
+ ++strp;
+ strp = getsecs(strp, &rulep->r_time);
+ } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
+ return strp;
+}
+
+/*
+** Given the Epoch-relative time of January 1, 00:00:00 GMT, in a year, the
+** year, a rule, and the offset from GMT at the time that rule takes effect,
+** calculate the Epoch-relative time that rule takes effect.
+*/
+
+static time_t
+transtime(janfirst, year, rulep, offset)
+const time_t janfirst;
+const int year;
+register const struct rule * const rulep;
+const long offset;
+{
+ register int leapyear;
+ register time_t value;
+ register int i;
+ int d, m1, yy0, yy1, yy2, dow;
+
+ INITIALIZE(value);
+ leapyear = isleap(year);
+ switch (rulep->r_type) {
+
+ case JULIAN_DAY:
+ /*
+ ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
+ ** years.
+ ** In non-leap years, or if the day number is 59 or less, just
+ ** add SECSPERDAY times the day number-1 to the time of
+ ** January 1, midnight, to get the day.
+ */
+ value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
+ if (leapyear && rulep->r_day >= 60)
+ value += SECSPERDAY;
+ break;
+
+ case DAY_OF_YEAR:
+ /*
+ ** n - day of year.
+ ** Just add SECSPERDAY times the day number to the time of
+ ** January 1, midnight, to get the day.
+ */
+ value = janfirst + rulep->r_day * SECSPERDAY;
+ break;
+
+ case MONTH_NTH_DAY_OF_WEEK:
+ /*
+ ** Mm.n.d - nth "dth day" of month m.
+ */
+ value = janfirst;
+ for (i = 0; i < rulep->r_mon - 1; ++i)
+ value += mon_lengths[leapyear][i] * SECSPERDAY;
+
+ /*
+ ** Use Zeller's Congruence to get day-of-week of first day of
+ ** month.
+ */
+ m1 = (rulep->r_mon + 9) % 12 + 1;
+ yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
+ yy1 = yy0 / 100;
+ yy2 = yy0 % 100;
+ dow = ((26 * m1 - 2) / 10 +
+ 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
+ if (dow < 0)
+ dow += DAYSPERWEEK;
+
+ /*
+ ** "dow" is the day-of-week of the first day of the month. Get
+ ** the day-of-month (zero-origin) of the first "dow" day of the
+ ** month.
+ */
+ d = rulep->r_day - dow;
+ if (d < 0)
+ d += DAYSPERWEEK;
+ for (i = 1; i < rulep->r_week; ++i) {
+ if (d + DAYSPERWEEK >=
+ mon_lengths[leapyear][rulep->r_mon - 1])
+ break;
+ d += DAYSPERWEEK;
+ }
+
+ /*
+ ** "d" is the day-of-month (zero-origin) of the day we want.
+ */
+ value += d * SECSPERDAY;
+ break;
+ }
+
+ /*
+ ** "value" is the Epoch-relative time of 00:00:00 GMT on the day in
+ ** question. To get the Epoch-relative time of the specified local
+ ** time on that day, add the transition time and the current offset
+ ** from GMT.
+ */
+ return value + rulep->r_time + offset;
+}
+
+/*
+** Given a POSIX section 8-style TZ string, fill in the rule tables as
+** appropriate.
+*/
+
+static int
+tzparse(name, sp, lastditch)
+const char * name;
+register struct state * const sp;
+const int lastditch;
+{
+ const char * stdname;
+ const char * dstname;
+ size_t stdlen;
+ size_t dstlen;
+ long stdoffset;
+ long dstoffset;
+ register time_t * atp;
+ register unsigned char * typep;
+ register char * cp;
+ register int load_result;
+
+ INITIALIZE(dstname);
+ stdname = name;
+ if (lastditch) {
+ stdlen = strlen(name); /* length of standard zone name */
+ name += stdlen;
+ if (stdlen >= sizeof sp->chars)
+ stdlen = (sizeof sp->chars) - 1;
+ stdoffset = 0;
+ } else {
+ name = getzname(name);
+ stdlen = name - stdname;
+ if (stdlen < 3)
+ return -1;
+ if (*name == '\0')
+ return -1; /* was "stdoffset = 0;" */
+ else {
+ name = getoffset(name, &stdoffset);
+ if (name == NULL)
+ return -1;
+ }
+ }
+ load_result = tzload(TZDEFRULES, sp);
+ if (load_result != 0)
+ sp->leapcnt = 0; /* so, we're off a little */
+ if (*name != '\0') {
+ dstname = name;
+ name = getzname(name);
+ dstlen = name - dstname; /* length of DST zone name */
+ if (dstlen < 3)
+ return -1;
+ if (*name != '\0' && *name != ',' && *name != ';') {
+ name = getoffset(name, &dstoffset);
+ if (name == NULL)
+ return -1;
+ } else dstoffset = stdoffset - SECSPERHOUR;
+ if (*name == ',' || *name == ';') {
+ struct rule start;
+ struct rule end;
+ register int year;
+ register time_t janfirst;
+ time_t starttime;
+ time_t endtime;
+
+ ++name;
+ if ((name = getrule(name, &start)) == NULL)
+ return -1;
+ if (*name++ != ',')
+ return -1;
+ if ((name = getrule(name, &end)) == NULL)
+ return -1;
+ if (*name != '\0')
+ return -1;
+ sp->typecnt = 2; /* standard time and DST */
+ /*
+ ** Two transitions per year, from EPOCH_YEAR to 2037.
+ */
+ sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1);
+ if (sp->timecnt > TZ_MAX_TIMES)
+ return -1;
+ sp->ttis[0].tt_gmtoff = -dstoffset;
+ sp->ttis[0].tt_isdst = 1;
+ sp->ttis[0].tt_abbrind = stdlen + 1;
+ sp->ttis[1].tt_gmtoff = -stdoffset;
+ sp->ttis[1].tt_isdst = 0;
+ sp->ttis[1].tt_abbrind = 0;
+ atp = sp->ats;
+ typep = sp->types;
+ janfirst = 0;
+ for (year = EPOCH_YEAR; year <= 2037; ++year) {
+ starttime = transtime(janfirst, year, &start,
+ stdoffset);
+ endtime = transtime(janfirst, year, &end,
+ dstoffset);
+ if (starttime > endtime) {
+ *atp++ = endtime;
+ *typep++ = 1; /* DST ends */
+ *atp++ = starttime;
+ *typep++ = 0; /* DST begins */
+ } else {
+ *atp++ = starttime;
+ *typep++ = 0; /* DST begins */
+ *atp++ = endtime;
+ *typep++ = 1; /* DST ends */
+ }
+ janfirst += year_lengths[isleap(year)] *
+ SECSPERDAY;
+ }
+ } else {
+ register long theirstdoffset;
+ register long theirdstoffset;
+ register long theiroffset;
+ register int isdst;
+ register int i;
+ register int j;
+
+ if (*name != '\0')
+ return -1;
+ if (load_result != 0)
+ return -1;
+ /*
+ ** Initial values of theirstdoffset and theirdstoffset.
+ */
+ theirstdoffset = 0;
+ for (i = 0; i < sp->timecnt; ++i) {
+ j = sp->types[i];
+ if (!sp->ttis[j].tt_isdst) {
+ theirstdoffset =
+ -sp->ttis[j].tt_gmtoff;
+ break;
+ }
+ }
+ theirdstoffset = 0;
+ for (i = 0; i < sp->timecnt; ++i) {
+ j = sp->types[i];
+ if (sp->ttis[j].tt_isdst) {
+ theirdstoffset =
+ -sp->ttis[j].tt_gmtoff;
+ break;
+ }
+ }
+ /*
+ ** Initially we're assumed to be in standard time.
+ */
+ isdst = FALSE;
+ theiroffset = theirstdoffset;
+ /*
+ ** Now juggle transition times and types
+ ** tracking offsets as you do.
+ */
+ for (i = 0; i < sp->timecnt; ++i) {
+ j = sp->types[i];
+ sp->types[i] = sp->ttis[j].tt_isdst;
+ if (sp->ttis[j].tt_ttisgmt) {
+ /* No adjustment to transition time */
+ } else {
+ /*
+ ** If summer time is in effect, and the
+ ** transition time was not specified as
+ ** standard time, add the summer time
+ ** offset to the transition time;
+ ** otherwise, add the standard time
+ ** offset to the transition time.
+ */
+ /*
+ ** Transitions from DST to DDST
+ ** will effectively disappear since
+ ** POSIX provides for only one DST
+ ** offset.
+ */
+ if (isdst && !sp->ttis[j].tt_ttisstd) {
+ sp->ats[i] += dstoffset -
+ theirdstoffset;
+ } else {
+ sp->ats[i] += stdoffset -
+ theirstdoffset;
+ }
+ }
+ theiroffset = -sp->ttis[j].tt_gmtoff;
+ if (sp->ttis[j].tt_isdst)
+ theirdstoffset = theiroffset;
+ else theirstdoffset = theiroffset;
+ }
+ /*
+ ** Finally, fill in ttis.
+ ** ttisstd and ttisgmt need not be handled.
+ */
+ sp->ttis[0].tt_gmtoff = -stdoffset;
+ sp->ttis[0].tt_isdst = FALSE;
+ sp->ttis[0].tt_abbrind = 0;
+ sp->ttis[1].tt_gmtoff = -dstoffset;
+ sp->ttis[1].tt_isdst = TRUE;
+ sp->ttis[1].tt_abbrind = stdlen + 1;
+ }
+ } else {
+ dstlen = 0;
+ sp->typecnt = 1; /* only standard time */
+ sp->timecnt = 0;
+ sp->ttis[0].tt_gmtoff = -stdoffset;
+ sp->ttis[0].tt_isdst = 0;
+ sp->ttis[0].tt_abbrind = 0;
+ }
+ sp->charcnt = stdlen + 1;
+ if (dstlen != 0)
+ sp->charcnt += dstlen + 1;
+ if (sp->charcnt > sizeof sp->chars)
+ return -1;
+ cp = sp->chars;
+ (void) strncpy(cp, stdname, stdlen);
+ cp += stdlen;
+ *cp++ = '\0';
+ if (dstlen != 0) {
+ (void) strncpy(cp, dstname, dstlen);
+ *(cp + dstlen) = '\0';
+ }
+ return 0;
+}
+
+static void
+gmtload(sp)
+struct state * const sp;
+{
+ if (tzload(gmt, sp) != 0)
+ (void) tzparse(gmt, sp, TRUE);
+}
+
+#ifndef STD_INSPIRED
+/*
+** A non-static declaration of tzsetwall in a system header file
+** may cause a warning about this upcoming static declaration...
+*/
+static
+#endif /* !defined STD_INSPIRED */
+#ifdef _THREAD_SAFE
+void
+tzsetwall_basic P((void))
+#else
+void
+tzsetwall P((void))
+#endif
+{
+ if (lcl_is_set < 0)
+ return;
+ lcl_is_set = -1;
+
+#ifdef ALL_STATE
+ if (lclptr == NULL) {
+ lclptr = (struct state *) malloc(sizeof *lclptr);
+ if (lclptr == NULL) {
+ settzname(); /* all we can do */
+ return;
+ }
+ }
+#endif /* defined ALL_STATE */
+ if (tzload((char *) NULL, lclptr) != 0)
+ gmtload(lclptr);
+ settzname();
+}
+
+#ifdef _THREAD_SAFE
+void
+tzsetwall P((void))
+{
+ pthread_mutex_lock(&lcl_mutex);
+ tzsetwall_basic();
+ pthread_mutex_unlock(&lcl_mutex);
+}
+#endif
+
+#ifdef _THREAD_SAFE
+static void
+tzset_basic P((void))
+#else
+void
+tzset P((void))
+#endif
+{
+ register const char * name;
+
+ name = getenv("TZ");
+ if (name == NULL) {
+ tzsetwall();
+ return;
+ }
+
+ if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
+ return;
+ lcl_is_set = (strlen(name) < sizeof(lcl_TZname));
+ if (lcl_is_set)
+ (void) strcpy(lcl_TZname, name);
+
+#ifdef ALL_STATE
+ if (lclptr == NULL) {
+ lclptr = (struct state *) malloc(sizeof *lclptr);
+ if (lclptr == NULL) {
+ settzname(); /* all we can do */
+ return;
+ }
+ }
+#endif /* defined ALL_STATE */
+ if (*name == '\0') {
+ /*
+ ** User wants it fast rather than right.
+ */
+ lclptr->leapcnt = 0; /* so, we're off a little */
+ lclptr->timecnt = 0;
+ lclptr->ttis[0].tt_gmtoff = 0;
+ lclptr->ttis[0].tt_abbrind = 0;
+ (void) strcpy(lclptr->chars, gmt);
+ } else if (tzload(name, lclptr) != 0)
+ if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
+ (void) gmtload(lclptr);
+ settzname();
+}
+
+#ifdef _THREAD_SAFE
+void
+tzset P((void))
+{
+ pthread_mutex_lock(&lcl_mutex);
+ tzset_basic();
+ pthread_mutex_unlock(&lcl_mutex);
+}
+#endif
+
+/*
+** The easy way to behave "as if no library function calls" localtime
+** is to not call it--so we drop its guts into "localsub", which can be
+** freely called. (And no, the PANS doesn't require the above behavior--
+** but it *is* desirable.)
+**
+** The unused offset argument is for the benefit of mktime variants.
+*/
+
+/*ARGSUSED*/
+static void
+localsub(timep, offset, tmp)
+const time_t * const timep;
+const long offset;
+struct tm * const tmp;
+{
+ register struct state * sp;
+ register const struct ttinfo * ttisp;
+ register int i;
+ const time_t t = *timep;
+
+ sp = lclptr;
+#ifdef ALL_STATE
+ if (sp == NULL) {
+ gmtsub(timep, offset, tmp);
+ return;
+ }
+#endif /* defined ALL_STATE */
+ if (sp->timecnt == 0 || t < sp->ats[0]) {
+ i = 0;
+ while (sp->ttis[i].tt_isdst)
+ if (++i >= sp->typecnt) {
+ i = 0;
+ break;
+ }
+ } else {
+ for (i = 1; i < sp->timecnt; ++i)
+ if (t < sp->ats[i])
+ break;
+ i = sp->types[i - 1];
+ }
+ ttisp = &sp->ttis[i];
+ /*
+ ** To get (wrong) behavior that's compatible with System V Release 2.0
+ ** you'd replace the statement below with
+ ** t += ttisp->tt_gmtoff;
+ ** timesub(&t, 0L, sp, tmp);
+ */
+ timesub(&t, ttisp->tt_gmtoff, sp, tmp);
+ tmp->tm_isdst = ttisp->tt_isdst;
+ tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];
+#ifdef TM_ZONE
+ tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind];
+#endif /* defined TM_ZONE */
+}
+
+#ifdef _THREAD_SAFE
+struct tm *
+localtime_r(timep, p_tm)
+const time_t * const timep;
+struct tm *p_tm;
+{
+ pthread_mutex_lock(&lcl_mutex);
+ tzset();
+ localsub(timep, 0L, p_tm);
+ pthread_mutex_unlock(&lcl_mutex);
+ return(p_tm);
+}
+#endif
+
+struct tm *
+localtime(timep)
+const time_t * const timep;
+{
+#ifdef _THREAD_SAFE
+ static struct pthread_mutex _localtime_mutex = PTHREAD_MUTEX_INITIALIZER;
+ static pthread_mutex_t localtime_mutex = &_localtime_mutex;
+ static pthread_key_t localtime_key = -1;
+ struct tm *p_tm;
+
+ pthread_mutex_lock(&localtime_mutex);
+ if (localtime_key < 0) {
+ if (pthread_key_create(&localtime_key, free) < 0) {
+ pthread_mutex_unlock(&localtime_mutex);
+ return(NULL);
+ }
+ }
+ pthread_mutex_unlock(&localtime_mutex);
+ p_tm = pthread_getspecific(localtime_key);
+ if (p_tm == NULL) {
+ if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL)
+ return(NULL);
+ pthread_setspecific(localtime_key, p_tm);
+ }
+ pthread_mutex_lock(&lcl_mutex);
+ tzset();
+ localsub(timep, 0L, p_tm);
+ pthread_mutex_unlock(&lcl_mutex);
+ return p_tm;
+#else
+ tzset();
+ localsub(timep, 0L, &tm);
+ return &tm;
+#endif
+}
+
+/*
+** gmtsub is to gmtime as localsub is to localtime.
+*/
+
+static void
+gmtsub(timep, offset, tmp)
+const time_t * const timep;
+const long offset;
+struct tm * const tmp;
+{
+#ifdef _THREAD_SAFE
+ pthread_mutex_lock(&gmt_mutex);
+#endif
+ if (!gmt_is_set) {
+ gmt_is_set = TRUE;
+#ifdef ALL_STATE
+ gmtptr = (struct state *) malloc(sizeof *gmtptr);
+ if (gmtptr != NULL)
+#endif /* defined ALL_STATE */
+ gmtload(gmtptr);
+ }
+#ifdef _THREAD_SAFE
+ pthread_mutex_unlock(&gmt_mutex);
+#endif
+ timesub(timep, offset, gmtptr, tmp);
+#ifdef TM_ZONE
+ /*
+ ** Could get fancy here and deliver something such as
+ ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero,
+ ** but this is no time for a treasure hunt.
+ */
+ if (offset != 0)
+ tmp->TM_ZONE = wildabbr;
+ else {
+#ifdef ALL_STATE
+ if (gmtptr == NULL)
+ tmp->TM_ZONE = gmt;
+ else tmp->TM_ZONE = gmtptr->chars;
+#endif /* defined ALL_STATE */
+#ifndef ALL_STATE
+ tmp->TM_ZONE = gmtptr->chars;
+#endif /* State Farm */
+ }
+#endif /* defined TM_ZONE */
+}
+
+struct tm *
+gmtime(timep)
+const time_t * const timep;
+{
+#ifdef _THREAD_SAFE
+ static struct pthread_mutex _gmtime_mutex = PTHREAD_MUTEX_INITIALIZER;
+ static pthread_mutex_t gmtime_mutex = &_gmtime_mutex;
+ static pthread_key_t gmtime_key = -1;
+ struct tm *p_tm;
+
+ pthread_mutex_lock(&gmtime_mutex);
+ if (gmtime_key < 0) {
+ if (pthread_key_create(&gmtime_key, free) < 0) {
+ pthread_mutex_unlock(&gmtime_mutex);
+ return(NULL);
+ }
+ }
+ pthread_mutex_unlock(&gmtime_mutex);
+ if ((p_tm = pthread_getspecific(gmtime_key)) != 0) {
+ return(NULL);
+ } else if (p_tm == NULL) {
+ if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) {
+ return(NULL);
+ }
+ pthread_setspecific(gmtime_key, p_tm);
+ }
+ gmtsub(timep, 0L, p_tm);
+ return(p_tm);
+#else
+ gmtsub(timep, 0L, &tm);
+ return &tm;
+#endif
+}
+
+#ifdef _THREAD_SAFE
+struct tm *
+gmtime_r(const time_t * timep, struct tm * tm)
+{
+ gmtsub(timep, 0L, tm);
+ return(tm);
+}
+#endif
+
+#ifdef STD_INSPIRED
+
+struct tm *
+offtime(timep, offset)
+const time_t * const timep;
+const long offset;
+{
+ gmtsub(timep, offset, &tm);
+ return &tm;
+}
+
+#endif /* defined STD_INSPIRED */
+
+static void
+timesub(timep, offset, sp, tmp)
+const time_t * const timep;
+const long offset;
+register const struct state * const sp;
+register struct tm * const tmp;
+{
+ register const struct lsinfo * lp;
+ register long days;
+ register long rem;
+ register int y;
+ register int yleap;
+ register const int * ip;
+ register long corr;
+ register int hit;
+ register int i;
+
+ corr = 0;
+ hit = 0;
+#ifdef ALL_STATE
+ i = (sp == NULL) ? 0 : sp->leapcnt;
+#endif /* defined ALL_STATE */
+#ifndef ALL_STATE
+ i = sp->leapcnt;
+#endif /* State Farm */
+ while (--i >= 0) {
+ lp = &sp->lsis[i];
+ if (*timep >= lp->ls_trans) {
+ if (*timep == lp->ls_trans) {
+ hit = ((i == 0 && lp->ls_corr > 0) ||
+ lp->ls_corr > sp->lsis[i - 1].ls_corr);
+ if (hit)
+ while (i > 0 &&
+ sp->lsis[i].ls_trans ==
+ sp->lsis[i - 1].ls_trans + 1 &&
+ sp->lsis[i].ls_corr ==
+ sp->lsis[i - 1].ls_corr + 1) {
+ ++hit;
+ --i;
+ }
+ }
+ corr = lp->ls_corr;
+ break;
+ }
+ }
+ days = *timep / SECSPERDAY;
+ rem = *timep % SECSPERDAY;
+#ifdef mc68k
+ if (*timep == 0x80000000) {
+ /*
+ ** A 3B1 muffs the division on the most negative number.
+ */
+ days = -24855;
+ rem = -11648;
+ }
+#endif /* defined mc68k */
+ rem += (offset - corr);
+ while (rem < 0) {
+ rem += SECSPERDAY;
+ --days;
+ }
+ while (rem >= SECSPERDAY) {
+ rem -= SECSPERDAY;
+ ++days;
+ }
+ tmp->tm_hour = (int) (rem / SECSPERHOUR);
+ rem = rem % SECSPERHOUR;
+ tmp->tm_min = (int) (rem / SECSPERMIN);
+ /*
+ ** A positive leap second requires a special
+ ** representation. This uses "... ??:59:60" et seq.
+ */
+ tmp->tm_sec = (int) (rem % SECSPERMIN) + hit;
+ tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK);
+ if (tmp->tm_wday < 0)
+ tmp->tm_wday += DAYSPERWEEK;
+ y = EPOCH_YEAR;
+#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
+ while (days < 0 || days >= (long) year_lengths[yleap = isleap(y)]) {
+ register int newy;
+
+ newy = y + days / DAYSPERNYEAR;
+ if (days < 0)
+ --newy;
+ days -= (newy - y) * DAYSPERNYEAR +
+ LEAPS_THRU_END_OF(newy - 1) -
+ LEAPS_THRU_END_OF(y - 1);
+ y = newy;
+ }
+ tmp->tm_year = y - TM_YEAR_BASE;
+ tmp->tm_yday = (int) days;
+ ip = mon_lengths[yleap];
+ for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon))
+ days = days - (long) ip[tmp->tm_mon];
+ tmp->tm_mday = (int) (days + 1);
+ tmp->tm_isdst = 0;
+#ifdef TM_GMTOFF
+ tmp->TM_GMTOFF = offset;
+#endif /* defined TM_GMTOFF */
+}
+
+char *
+ctime(timep)
+const time_t * const timep;
+{
+/*
+** Section 4.12.3.2 of X3.159-1989 requires that
+** The ctime funciton converts the calendar time pointed to by timer
+** to local time in the form of a string. It is equivalent to
+** asctime(localtime(timer))
+*/
+ return asctime(localtime(timep));
+}
+
+/*
+** Adapted from code provided by Robert Elz, who writes:
+** The "best" way to do mktime I think is based on an idea of Bob
+** Kridle's (so its said...) from a long time ago.
+** [kridle@xinet.com as of 1996-01-16.]
+** It does a binary search of the time_t space. Since time_t's are
+** just 32 bits, its a max of 32 iterations (even at 64 bits it
+** would still be very reasonable).
+*/
+
+#ifndef WRONG
+#define WRONG (-1)
+#endif /* !defined WRONG */
+
+/*
+** Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com).
+*/
+
+static int
+increment_overflow(number, delta)
+int * number;
+int delta;
+{
+ int number0;
+
+ number0 = *number;
+ *number += delta;
+ return (*number < number0) != (delta < 0);
+}
+
+static int
+normalize_overflow(tensptr, unitsptr, base)
+int * const tensptr;
+int * const unitsptr;
+const int base;
+{
+ register int tensdelta;
+
+ tensdelta = (*unitsptr >= 0) ?
+ (*unitsptr / base) :
+ (-1 - (-1 - *unitsptr) / base);
+ *unitsptr -= tensdelta * base;
+ return increment_overflow(tensptr, tensdelta);
+}
+
+static int
+tmcomp(atmp, btmp)
+register const struct tm * const atmp;
+register const struct tm * const btmp;
+{
+ register int result;
+
+ if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
+ (result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
+ (result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&
+ (result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
+ (result = (atmp->tm_min - btmp->tm_min)) == 0)
+ result = atmp->tm_sec - btmp->tm_sec;
+ return result;
+}
+
+static time_t
+time2(tmp, funcp, offset, okayp)
+struct tm * const tmp;
+void (* const funcp) P((const time_t*, long, struct tm*));
+const long offset;
+int * const okayp;
+{
+ register const struct state * sp;
+ register int dir;
+ register int bits;
+ register int i, j ;
+ register int saved_seconds;
+ time_t newt;
+ time_t t;
+ struct tm yourtm, mytm;
+
+ *okayp = FALSE;
+ yourtm = *tmp;
+ if (normalize_overflow(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR))
+ return WRONG;
+ if (normalize_overflow(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY))
+ return WRONG;
+ if (normalize_overflow(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR))
+ return WRONG;
+ /*
+ ** Turn yourtm.tm_year into an actual year number for now.
+ ** It is converted back to an offset from TM_YEAR_BASE later.
+ */
+ if (increment_overflow(&yourtm.tm_year, TM_YEAR_BASE))
+ return WRONG;
+ while (yourtm.tm_mday <= 0) {
+ if (increment_overflow(&yourtm.tm_year, -1))
+ return WRONG;
+ i = yourtm.tm_year + (1 < yourtm.tm_mon);
+ yourtm.tm_mday += year_lengths[isleap(i)];
+ }
+ while (yourtm.tm_mday > DAYSPERLYEAR) {
+ i = yourtm.tm_year + (1 < yourtm.tm_mon);
+ yourtm.tm_mday -= year_lengths[isleap(i)];
+ if (increment_overflow(&yourtm.tm_year, 1))
+ return WRONG;
+ }
+ for ( ; ; ) {
+ i = mon_lengths[isleap(yourtm.tm_year)][yourtm.tm_mon];
+ if (yourtm.tm_mday <= i)
+ break;
+ yourtm.tm_mday -= i;
+ if (++yourtm.tm_mon >= MONSPERYEAR) {
+ yourtm.tm_mon = 0;
+ if (increment_overflow(&yourtm.tm_year, 1))
+ return WRONG;
+ }
+ }
+ if (increment_overflow(&yourtm.tm_year, -TM_YEAR_BASE))
+ return WRONG;
+ if (yourtm.tm_year + TM_YEAR_BASE < EPOCH_YEAR) {
+ /*
+ ** We can't set tm_sec to 0, because that might push the
+ ** time below the minimum representable time.
+ ** Set tm_sec to 59 instead.
+ ** This assumes that the minimum representable time is
+ ** not in the same minute that a leap second was deleted from,
+ ** which is a safer assumption than using 58 would be.
+ */
+ if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN))
+ return WRONG;
+ saved_seconds = yourtm.tm_sec;
+ yourtm.tm_sec = SECSPERMIN - 1;
+ } else {
+ saved_seconds = yourtm.tm_sec;
+ yourtm.tm_sec = 0;
+ }
+ /*
+ ** Divide the search space in half
+ ** (this works whether time_t is signed or unsigned).
+ */
+ bits = TYPE_BIT(time_t) - 1;
+ /*
+ ** If time_t is signed, then 0 is just above the median,
+ ** assuming two's complement arithmetic.
+ ** If time_t is unsigned, then (1 << bits) is just above the median.
+ */
+ t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits);
+ for ( ; ; ) {
+ (*funcp)(&t, offset, &mytm);
+ dir = tmcomp(&mytm, &yourtm);
+ if (dir != 0) {
+ if (bits-- < 0)
+ return WRONG;
+ if (bits < 0)
+ --t; /* may be needed if new t is minimal */
+ else if (dir > 0)
+ t -= ((time_t) 1) << bits;
+ else t += ((time_t) 1) << bits;
+ continue;
+ }
+ if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
+ break;
+ /*
+ ** Right time, wrong type.
+ ** Hunt for right time, right type.
+ ** It's okay to guess wrong since the guess
+ ** gets checked.
+ */
+ /*
+ ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
+ */
+ sp = (const struct state *)
+ (((void *) funcp == (void *) localsub) ?
+ lclptr : gmtptr);
+#ifdef ALL_STATE
+ if (sp == NULL)
+ return WRONG;
+#endif /* defined ALL_STATE */
+ for (i = sp->typecnt - 1; i >= 0; --i) {
+ if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
+ continue;
+ for (j = sp->typecnt - 1; j >= 0; --j) {
+ if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
+ continue;
+ newt = t + sp->ttis[j].tt_gmtoff -
+ sp->ttis[i].tt_gmtoff;
+ (*funcp)(&newt, offset, &mytm);
+ if (tmcomp(&mytm, &yourtm) != 0)
+ continue;
+ if (mytm.tm_isdst != yourtm.tm_isdst)
+ continue;
+ /*
+ ** We have a match.
+ */
+ t = newt;
+ goto label;
+ }
+ }
+ return WRONG;
+ }
+label:
+ newt = t + saved_seconds;
+ if ((newt < t) != (saved_seconds < 0))
+ return WRONG;
+ t = newt;
+ (*funcp)(&t, offset, tmp);
+ *okayp = TRUE;
+ return t;
+}
+
+static time_t
+time1(tmp, funcp, offset)
+struct tm * const tmp;
+void (* const funcp) P((const time_t *, long, struct tm *));
+const long offset;
+{
+ register time_t t;
+ register const struct state * sp;
+ register int samei, otheri;
+ int okay;
+
+ if (tmp->tm_isdst > 1)
+ tmp->tm_isdst = 1;
+ t = time2(tmp, funcp, offset, &okay);
+#ifdef PCTS
+ /*
+ ** PCTS code courtesy Grant Sullivan (grant@osf.org).
+ */
+ if (okay)
+ return t;
+ if (tmp->tm_isdst < 0)
+ tmp->tm_isdst = 0; /* reset to std and try again */
+#endif /* defined PCTS */
+#ifndef PCTS
+ if (okay || tmp->tm_isdst < 0)
+ return t;
+#endif /* !defined PCTS */
+ /*
+ ** We're supposed to assume that somebody took a time of one type
+ ** and did some math on it that yielded a "struct tm" that's bad.
+ ** We try to divine the type they started from and adjust to the
+ ** type they need.
+ */
+ /*
+ ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
+ */
+ sp = (const struct state *) (((void *) funcp == (void *) localsub) ?
+ lclptr : gmtptr);
+#ifdef ALL_STATE
+ if (sp == NULL)
+ return WRONG;
+#endif /* defined ALL_STATE */
+ for (samei = sp->typecnt - 1; samei >= 0; --samei) {
+ if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
+ continue;
+ for (otheri = sp->typecnt - 1; otheri >= 0; --otheri) {
+ if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
+ continue;
+ tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
+ sp->ttis[samei].tt_gmtoff;
+ tmp->tm_isdst = !tmp->tm_isdst;
+ t = time2(tmp, funcp, offset, &okay);
+ if (okay)
+ return t;
+ tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff -
+ sp->ttis[samei].tt_gmtoff;
+ tmp->tm_isdst = !tmp->tm_isdst;
+ }
+ }
+ return WRONG;
+}
+
+time_t
+mktime(tmp)
+struct tm * const tmp;
+{
+ time_t mktime_return_value;
+#ifdef _THREAD_SAFE
+ pthread_mutex_lock(&lcl_mutex);
+#endif
+ tzset();
+ mktime_return_value = time1(tmp, localsub, 0L);
+#ifdef _THREAD_SAFE
+ pthread_mutex_unlock(&lcl_mutex);
+#endif
+ return(mktime_return_value);
+}
+
+#ifdef STD_INSPIRED
+
+time_t
+timelocal(tmp)
+struct tm * const tmp;
+{
+ tmp->tm_isdst = -1; /* in case it wasn't initialized */
+ return mktime(tmp);
+}
+
+time_t
+timegm(tmp)
+struct tm * const tmp;
+{
+ tmp->tm_isdst = 0;
+ return time1(tmp, gmtsub, 0L);
+}
+
+time_t
+timeoff(tmp, offset)
+struct tm * const tmp;
+const long offset;
+{
+ tmp->tm_isdst = 0;
+ return time1(tmp, gmtsub, offset);
+}
+
+#endif /* defined STD_INSPIRED */
+
+#ifdef CMUCS
+
+/*
+** The following is supplied for compatibility with
+** previous versions of the CMUCS runtime library.
+*/
+
+long
+gtime(tmp)
+struct tm * const tmp;
+{
+ const time_t t = mktime(tmp);
+
+ if (t == WRONG)
+ return -1;
+ return t;
+}
+
+#endif /* defined CMUCS */
+
+/*
+** XXX--is the below the right way to conditionalize??
+*/
+
+#ifdef STD_INSPIRED
+
+/*
+** IEEE Std 1003.1-1988 (POSIX) legislates that 536457599
+** shall correspond to "Wed Dec 31 23:59:59 GMT 1986", which
+** is not the case if we are accounting for leap seconds.
+** So, we provide the following conversion routines for use
+** when exchanging timestamps with POSIX conforming systems.
+*/
+
+static long
+leapcorr(timep)
+time_t * timep;
+{
+ register struct state * sp;
+ register struct lsinfo * lp;
+ register int i;
+
+ sp = lclptr;
+ i = sp->leapcnt;
+ while (--i >= 0) {
+ lp = &sp->lsis[i];
+ if (*timep >= lp->ls_trans)
+ return lp->ls_corr;
+ }
+ return 0;
+}
+
+time_t
+time2posix(t)
+time_t t;
+{
+ tzset();
+ return t - leapcorr(&t);
+}
+
+time_t
+posix2time(t)
+time_t t;
+{
+ time_t x;
+ time_t y;
+
+ tzset();
+ /*
+ ** For a positive leap second hit, the result
+ ** is not unique. For a negative leap second
+ ** hit, the corresponding time doesn't exist,
+ ** so we return an adjacent second.
+ */
+ x = t + leapcorr(&t);
+ y = x - leapcorr(&x);
+ if (y < t) {
+ do {
+ x++;
+ y = x - leapcorr(&x);
+ } while (y < t);
+ if (t != y)
+ return x - 1;
+ } else if (y > t) {
+ do {
+ --x;
+ y = x - leapcorr(&x);
+ } while (y > t);
+ if (t != y)
+ return x + 1;
+ }
+ return x;
+}
+
+#endif /* defined STD_INSPIRED */
diff --git a/lib/libc/stdtime/private.h b/lib/libc/stdtime/private.h
new file mode 100644
index 0000000..d8fa906
--- /dev/null
+++ b/lib/libc/stdtime/private.h
@@ -0,0 +1,218 @@
+#ifndef PRIVATE_H
+
+#define PRIVATE_H
+/*
+** This file is in the public domain, so clarified as of
+** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
+*/
+
+/* Stuff moved from Makefile.inc to reduce clutter */
+#ifndef TM_GMTOFF
+#define TM_GMTOFF tm_gmtoff
+#define TM_ZONE tm_zone
+#define STD_INSPIRED 1
+#define PCTS 1
+#define HAVE_LONG_DOUBLE 1
+#define HAVE_STRERROR 1
+#define HAVE_UNISTD_H 1
+#define LOCALE_HOME _PATH_LOCALE
+#define TZDIR "/usr/share/zoneinfo"
+#endif /* ndef TM_GMTOFF */
+
+/*
+** This header is for use ONLY with the time conversion code.
+** There is no guarantee that it will remain unchanged,
+** or that it will remain at all.
+** Do NOT copy it to any system include directory.
+** Thank you!
+*/
+
+/*
+** ID
+*/
+
+#ifndef lint
+#ifndef NOID
+/*
+static char privatehid[] = "@(#)private.h 7.43";
+*/
+#endif /* !defined NOID */
+#endif /* !defined lint */
+
+/*
+** Defaults for preprocessor symbols.
+** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
+*/
+
+#ifndef HAVE_ADJTIME
+#define HAVE_ADJTIME 1
+#endif /* !defined HAVE_ADJTIME */
+
+#ifndef HAVE_GETTEXT
+#define HAVE_GETTEXT 0
+#endif /* !defined HAVE_GETTEXT */
+
+#ifndef HAVE_SETTIMEOFDAY
+#define HAVE_SETTIMEOFDAY 3
+#endif /* !defined HAVE_SETTIMEOFDAY */
+
+#ifndef HAVE_STRERROR
+#define HAVE_STRERROR 0
+#endif /* !defined HAVE_STRERROR */
+
+#ifndef HAVE_UNISTD_H
+#define HAVE_UNISTD_H 1
+#endif /* !defined HAVE_UNISTD_H */
+
+#ifndef HAVE_UTMPX_H
+#define HAVE_UTMPX_H 0
+#endif /* !defined HAVE_UTMPX_H */
+
+#ifndef LOCALE_HOME
+#define LOCALE_HOME "/usr/lib/locale"
+#endif /* !defined LOCALE_HOME */
+
+/*
+** Nested includes
+*/
+
+#include "sys/types.h" /* for time_t */
+#include "stdio.h"
+#include "errno.h"
+#include "string.h"
+#include "limits.h" /* for CHAR_BIT */
+#include "time.h"
+#include "stdlib.h"
+
+#if HAVE_GETTEXT - 0
+#include "libintl.h"
+#endif /* HAVE_GETTEXT - 0 */
+
+#if HAVE_UNISTD_H - 0
+#include "unistd.h" /* for F_OK and R_OK */
+#endif /* HAVE_UNISTD_H - 0 */
+
+#if !(HAVE_UNISTD_H - 0)
+#ifndef F_OK
+#define F_OK 0
+#endif /* !defined F_OK */
+#ifndef R_OK
+#define R_OK 4
+#endif /* !defined R_OK */
+#endif /* !(HAVE_UNISTD_H - 0) */
+
+/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
+#define is_digit(c) ((unsigned)(c) - '0' <= 9)
+
+/*
+** Workarounds for compilers/systems.
+*/
+
+#ifndef P
+#ifdef __STDC__
+#define P(x) x
+#endif /* defined __STDC__ */
+#ifndef __STDC__
+#define P(x) ()
+#endif /* !defined __STDC__ */
+#endif /* !defined P */
+
+/*
+** SunOS 4.1.1 headers lack FILENAME_MAX.
+*/
+
+#ifndef FILENAME_MAX
+
+#ifndef MAXPATHLEN
+#ifdef unix
+#include "sys/param.h"
+#endif /* defined unix */
+#endif /* !defined MAXPATHLEN */
+
+#ifdef MAXPATHLEN
+#define FILENAME_MAX MAXPATHLEN
+#endif /* defined MAXPATHLEN */
+#ifndef MAXPATHLEN
+#define FILENAME_MAX 1024 /* Pure guesswork */
+#endif /* !defined MAXPATHLEN */
+
+#endif /* !defined FILENAME_MAX */
+
+/*
+** Finally, some convenience items.
+*/
+
+#ifndef TRUE
+#define TRUE 1
+#endif /* !defined TRUE */
+
+#ifndef FALSE
+#define FALSE 0
+#endif /* !defined FALSE */
+
+#ifndef TYPE_BIT
+#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
+#endif /* !defined TYPE_BIT */
+
+#ifndef TYPE_SIGNED
+#define TYPE_SIGNED(type) (((type) -1) < 0)
+#endif /* !defined TYPE_SIGNED */
+
+#ifndef INT_STRLEN_MAXIMUM
+/*
+** 302 / 1000 is log10(2.0) rounded up.
+** Subtract one for the sign bit if the type is signed;
+** add one for integer division truncation;
+** add one more for a minus sign if the type is signed.
+*/
+#define INT_STRLEN_MAXIMUM(type) \
+ ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 100 + 1 + TYPE_SIGNED(type))
+#endif /* !defined INT_STRLEN_MAXIMUM */
+
+/*
+** INITIALIZE(x)
+*/
+
+#ifndef GNUC_or_lint
+#ifdef lint
+#define GNUC_or_lint
+#endif /* defined lint */
+#ifndef lint
+#ifdef __GNUC__
+#define GNUC_or_lint
+#endif /* defined __GNUC__ */
+#endif /* !defined lint */
+#endif /* !defined GNUC_or_lint */
+
+#ifndef INITIALIZE
+#ifdef GNUC_or_lint
+#define INITIALIZE(x) ((x) = 0)
+#endif /* defined GNUC_or_lint */
+#ifndef GNUC_or_lint
+#define INITIALIZE(x)
+#endif /* !defined GNUC_or_lint */
+#endif /* !defined INITIALIZE */
+
+/*
+** For the benefit of GNU folk...
+** `_(MSGID)' uses the current locale's message library string for MSGID.
+** The default is to use gettext if available, and use MSGID otherwise.
+*/
+
+#ifndef _
+#if HAVE_GETTEXT - 0
+#define _(msgid) gettext(msgid)
+#else /* !(HAVE_GETTEXT - 0) */
+#define _(msgid) msgid
+#endif /* !(HAVE_GETTEXT - 0) */
+#endif /* !defined _ */
+
+#ifndef TZ_DOMAIN
+#define TZ_DOMAIN "tz"
+#endif /* !defined TZ_DOMAIN */
+
+/*
+** UNIX was a registered trademark of UNIX System Laboratories in 1993.
+*/
+
+#endif /* !defined PRIVATE_H */
diff --git a/lib/libc/stdtime/strftime.3 b/lib/libc/stdtime/strftime.3
new file mode 100644
index 0000000..27c826a
--- /dev/null
+++ b/lib/libc/stdtime/strftime.3
@@ -0,0 +1,212 @@
+.\" Copyright (c) 1989, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\" @(#)strftime.3 8.1 (Berkeley) 6/4/93
+.\"
+.Dd June 4, 1993
+.Dt STRFTIME 3
+.Os
+.Sh NAME
+.Nm strftime
+.Nd format date and time
+.Sh SYNOPSIS
+.Fd #include <time.h>
+.Ft size_t
+.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr"
+.Sh DESCRIPTION
+The
+.Fn strftime
+function formats the information from
+.Fa timeptr
+into the buffer
+.Fa buf
+according to the string pointed to by
+.Fa format .
+.Pp
+The
+.Fa format
+string consists of zero or more conversion specifications and
+ordinary characters.
+All ordinary characters are copied directly into the buffer.
+A conversion specification consists of a percent sign
+.Dq Ql %
+and one other character.
+.Pp
+No more than
+.Fa maxsize
+characters will be placed into the array.
+If the total number of resulting characters, including the terminating
+null character, is not more than
+.Fa maxsize ,
+.Fn strftime
+returns the number of characters in the array, not counting the
+terminating null.
+Otherwise, zero is returned and the buffer contents is indeterminate.
+.Pp
+Each conversion specification is replaced by the characters as
+follows which are then copied into the buffer.
+.Bl -tag -width "xxxx"
+.It Cm \&%A
+is replaced by national representation of the full weekday name.
+.It Cm %a
+is replaced by national representation of
+the abbreviated weekday name, where the abbreviation
+is the first three characters.
+.It Cm \&%B
+is replaced by national representation of the full month name.
+.It Cm %b
+is replaced by national representation of
+the abbreviated month name, where the abbreviation is
+the first three characters.
+.It Cm \&%C
+is replaced by (year / 100) as decimal number; single
+digits are preceded by a zero.
+.It Cm %c
+is replaced by national representation of time and date
+(the format is similar with produced by
+.Xr asctime 3 ) .
+.It Cm \&%D
+is equivalent to
+.Dq Li %m/%d/%y .
+.It Cm %d
+is replaced by the day of the month as a decimal number (01-31).
+.It Cm \&%E*
+POSIX locale extensions.
+The sequences
+%Ec %EC %Ex %Ey %EY
+%Od %Oe %OH %OI %Om %OM
+%OS %Ou %OU %OV %Ow %OW %Oy
+are supposed to provide alternate
+representations.
+.It Cm %e
+is replaced by the day of month as a decimal number (1-31); single
+digits are preceded by a blank.
+.It Cm \&%H
+is replaced by the hour (24-hour clock) as a decimal number (00-23).
+.It Cm %h
+the same as %b.
+.It Cm \&%I
+is replaced by the hour (12-hour clock) as a decimal number (01-12).
+.It Cm %j
+is replaced by the day of the year as a decimal number (001-366).
+.It Cm %k
+is replaced by the hour (24-hour clock) as a decimal number (0-23);
+single digits are preceded by a blank.
+.It Cm %l
+is replaced by the hour (12-hour clock) as a decimal number (1-12);
+single digits are preceded by a blank.
+.It Cm \&%M
+is replaced by the minute as a decimal number (00-59).
+.It Cm %m
+is replaced by the month as a decimal number (01-12).
+.It Cm %n
+is replaced by a newline.
+.It Cm \&%O*
+the same as %E*.
+.It Cm %p
+is replaced by national representation of either
+"ante meridiem"
+or
+"post meridiem"
+as appropriate.
+.It Cm \&%R
+is equivalent to
+.Dq Li %H:%M .
+.It Cm %r
+is equivalent to
+.Dq Li %I:%M:%S %p .
+.It Cm \&%S
+is replaced by the second as a decimal number (00-60).
+.It Cm %s
+is replaced by the number of seconds since the Epoch, UTC (see
+.Xr mktime 3 ) .
+.It Cm \&%T
+is equivalent to
+.Dq Li %H:%M:%S .
+.It Cm %t
+is replaced by a tab.
+.It Cm \&%U
+is replaced by the week number of the year (Sunday as the first day of
+the week) as a decimal number (00-53).
+.It Cm %u
+is replaced by the weekday (Monday as the first day of the week)
+as a decimal number (1-7).
+.It Cm \&%V
+is replaced by the week number of the year (the first
+Monday as the first day of week 1) as a
+decimal number (01-53).
+.It Cm %v
+is equivalent to
+.Dq Li %e-%b-%Y .
+.It Cm \&%W
+is replaced by the week number of the year (Monday as the first day of
+the week) as a decimal number (00-53).
+.It Cm %w
+is replaced by the weekday (Sunday as the first day of the week)
+as a decimal number (0-6).
+.It Cm \&%X
+is replaced by national representation of the time.
+.It Cm %x
+is replaced by national representation of the date.
+.It Cm \&%Y
+is replaced by the year with century as a decimal number.
+.It Cm %y
+is replaced by the year without century as a decimal number (00-99).
+.It Cm \&%Z
+is replaced by the time zone name.
+.It Cm %+
+is replaced by national representation of the date and time
+(the format is similar with produced by
+.Xr date 1 ) .
+.It Cm %%
+is replaced by
+.Ql % .
+.El
+.Sh SEE ALSO
+.Xr date 1 ,
+.Xr printf 1 ,
+.Xr ctime 3 ,
+.Xr printf 3
+.Sh STANDARDS
+The
+.Fn strftime
+function
+conforms to
+.St -ansiC .
+The
+.Ql %s
+conversion specification is an extension.
+.Sh BUGS
+There is no conversion specification for the phase of the moon.
diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c
new file mode 100644
index 0000000..b44ff68
--- /dev/null
+++ b/lib/libc/stdtime/strftime.c
@@ -0,0 +1,574 @@
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifdef LIBC_RCS
+static const char rcsid[] =
+ "$Id$";
+#endif
+
+#ifndef lint
+#ifndef NOID
+static const char elsieid[] = "@(#)strftime.c 7.38";
+/*
+** Based on the UCB version with the ID appearing below.
+** This is ANSIish only when "multibyte character == plain character".
+*/
+#endif /* !defined NOID */
+#endif /* !defined lint */
+
+#include "private.h"
+
+#ifndef LIBC_SCCS
+#ifndef lint
+static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89";
+#endif /* !defined lint */
+#endif /* !defined LIBC_SCCS */
+
+#include "tzfile.h"
+#include <fcntl.h>
+#include <locale.h>
+#include <sys/stat.h>
+#include "setlocale.h"
+
+struct lc_time_T {
+ const char * mon[12];
+ const char * month[12];
+ const char * wday[7];
+ const char * weekday[7];
+ const char * X_fmt;
+ const char * x_fmt;
+ const char * c_fmt;
+ const char * am;
+ const char * pm;
+ const char * date_fmt;
+};
+
+static struct lc_time_T localebuf;
+static int using_locale;
+
+#define Locale (using_locale ? &localebuf : &C_time_locale)
+
+static const struct lc_time_T C_time_locale = {
+ {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ }, {
+ "January", "February", "March", "April", "May", "June",
+ "July", "August", "September", "October", "November", "December"
+ }, {
+ "Sun", "Mon", "Tue", "Wed",
+ "Thu", "Fri", "Sat"
+ }, {
+ "Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday"
+ },
+
+ /* X_fmt */
+ "%H:%M:%S",
+
+ /*
+ ** x_fmt
+ ** Since the C language standard calls for
+ ** "date, using locale's date format," anything goes.
+ ** Using just numbers (as here) makes Quakers happier;
+ ** it's also compatible with SVR4.
+ */
+ "%m/%d/%y",
+
+ /*
+ ** c_fmt (ctime-compatible)
+ ** Note that
+ ** "%a %b %d %H:%M:%S %Y"
+ ** is used by Solaris 2.3.
+ */
+ "%a %b %e %X %Y",
+
+ /* am */
+ "AM",
+
+ /* pm */
+ "PM",
+
+ /* date_fmt */
+ "%a %b %e %X %Z %Y"
+};
+
+static char * _add P((const char *, char *, const char *));
+static char * _conv P((int, const char *, char *, const char *));
+static char * _fmt P((const char *, const struct tm *, char *, const char *));
+static char * _secs P((const struct tm *, char *, const char *));
+
+size_t strftime P((char *, size_t, const char *, const struct tm *));
+
+extern char * tzname[];
+
+size_t
+strftime(s, maxsize, format, t)
+ char *const s;
+ const size_t maxsize;
+ const char *const format;
+ const struct tm *const t;
+{
+ char *p;
+
+ tzset();
+ p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize);
+ if (p == s + maxsize)
+ return 0;
+ *p = '\0';
+ return p - s;
+}
+
+static char *
+_fmt(format, t, pt, ptlim)
+ const char *format;
+ const struct tm *const t;
+ char *pt;
+ const char *const ptlim;
+{
+ for ( ; *format; ++format) {
+ if (*format == '%') {
+label:
+ switch (*++format) {
+ case '\0':
+ --format;
+ break;
+ case 'A':
+ pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ?
+ "?" : Locale->weekday[t->tm_wday],
+ pt, ptlim);
+ continue;
+ case 'a':
+ pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ?
+ "?" : Locale->wday[t->tm_wday],
+ pt, ptlim);
+ continue;
+ case 'B':
+ pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ?
+ "?" : Locale->month[t->tm_mon],
+ pt, ptlim);
+ continue;
+ case 'b':
+ case 'h':
+ pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ?
+ "?" : Locale->mon[t->tm_mon],
+ pt, ptlim);
+ continue;
+ case 'C':
+ /*
+ ** %C used to do a...
+ ** _fmt("%a %b %e %X %Y", t);
+ ** ...whereas now POSIX 1003.2 calls for
+ ** something completely different.
+ ** (ado, 5/24/93)
+ */
+ pt = _conv((t->tm_year + TM_YEAR_BASE) / 100,
+ "%02d", pt, ptlim);
+ continue;
+ case 'c':
+ pt = _fmt(Locale->c_fmt, t, pt, ptlim);
+ continue;
+ case 'D':
+ pt = _fmt("%m/%d/%y", t, pt, ptlim);
+ continue;
+ case 'd':
+ pt = _conv(t->tm_mday, "%02d", pt, ptlim);
+ continue;
+ case 'E':
+ case 'O':
+ /*
+ ** POSIX locale extensions, a la
+ ** Arnold Robbins' strftime version 3.0.
+ ** The sequences
+ ** %Ec %EC %Ex %Ey %EY
+ ** %Od %oe %OH %OI %Om %OM
+ ** %OS %Ou %OU %OV %Ow %OW %Oy
+ ** are supposed to provide alternate
+ ** representations.
+ ** (ado, 5/24/93)
+ */
+ goto label;
+ case 'e':
+ pt = _conv(t->tm_mday, "%2d", pt, ptlim);
+ continue;
+ case 'H':
+ pt = _conv(t->tm_hour, "%02d", pt, ptlim);
+ continue;
+ case 'I':
+ pt = _conv((t->tm_hour % 12) ?
+ (t->tm_hour % 12) : 12,
+ "%02d", pt, ptlim);
+ continue;
+ case 'j':
+ pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
+ continue;
+ case 'k':
+ /*
+ ** This used to be...
+ ** _conv(t->tm_hour % 12 ?
+ ** t->tm_hour % 12 : 12, 2, ' ');
+ ** ...and has been changed to the below to
+ ** match SunOS 4.1.1 and Arnold Robbins'
+ ** strftime version 3.0. That is, "%k" and
+ ** "%l" have been swapped.
+ ** (ado, 5/24/93)
+ */
+ pt = _conv(t->tm_hour, "%2d", pt, ptlim);
+ continue;
+#ifdef KITCHEN_SINK
+ case 'K':
+ /*
+ ** After all this time, still unclaimed!
+ */
+ pt = _add("kitchen sink", pt, ptlim);
+ continue;
+#endif /* defined KITCHEN_SINK */
+ case 'l':
+ /*
+ ** This used to be...
+ ** _conv(t->tm_hour, 2, ' ');
+ ** ...and has been changed to the below to
+ ** match SunOS 4.1.1 and Arnold Robbin's
+ ** strftime version 3.0. That is, "%k" and
+ ** "%l" have been swapped.
+ ** (ado, 5/24/93)
+ */
+ pt = _conv((t->tm_hour % 12) ?
+ (t->tm_hour % 12) : 12,
+ "%2d", pt, ptlim);
+ continue;
+ case 'M':
+ pt = _conv(t->tm_min, "%02d", pt, ptlim);
+ continue;
+ case 'm':
+ pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
+ continue;
+ case 'n':
+ pt = _add("\n", pt, ptlim);
+ continue;
+ case 'p':
+ pt = _add((t->tm_hour >= 12) ?
+ Locale->pm :
+ Locale->am,
+ pt, ptlim);
+ continue;
+ case 'R':
+ pt = _fmt("%H:%M", t, pt, ptlim);
+ continue;
+ case 'r':
+ pt = _fmt("%I:%M:%S %p", t, pt, ptlim);
+ continue;
+ case 'S':
+ pt = _conv(t->tm_sec, "%02d", pt, ptlim);
+ continue;
+ case 's':
+ pt = _secs(t, pt, ptlim);
+ continue;
+ case 'T':
+ pt = _fmt("%H:%M:%S", t, pt, ptlim);
+ continue;
+ case 't':
+ pt = _add("\t", pt, ptlim);
+ continue;
+ case 'U':
+ pt = _conv((t->tm_yday + 7 - t->tm_wday) / 7,
+ "%02d", pt, ptlim);
+ continue;
+ case 'u':
+ /*
+ ** From Arnold Robbins' strftime version 3.0:
+ ** "ISO 8601: Weekday as a decimal number
+ ** [1 (Monday) - 7]"
+ ** (ado, 5/24/93)
+ */
+ pt = _conv((t->tm_wday == 0) ? 7 : t->tm_wday,
+ "%d", pt, ptlim);
+ continue;
+ case 'V':
+ /*
+ ** From Arnold Robbins' strftime version 3.0:
+ ** "the week number of the year (the first
+ ** Monday as the first day of week 1) as a
+ ** decimal number (01-53). The method for
+ ** determining the week number is as specified
+ ** by ISO 8601 (to wit: if the week containing
+ ** January 1 has four or more days in the new
+ ** year, then it is week 1, otherwise it is
+ ** week 53 of the previous year and the next
+ ** week is week 1)."
+ ** (ado, 5/24/93)
+ */
+ /*
+ ** XXX--If January 1 falls on a Friday,
+ ** January 1-3 are part of week 53 of the
+ ** previous year. By analogy, if January
+ ** 1 falls on a Thursday, are December 29-31
+ ** of the PREVIOUS year part of week 1???
+ ** (ado 5/24/93)
+ */
+ /*
+ ** You are understood not to expect this.
+ */
+ {
+ int i;
+
+ i = (t->tm_yday + 10 - (t->tm_wday ?
+ (t->tm_wday - 1) : 6)) / 7;
+ if (i == 0) {
+ /*
+ ** What day of the week does
+ ** January 1 fall on?
+ */
+ i = t->tm_wday -
+ (t->tm_yday - 1);
+ /*
+ ** Fri Jan 1: 53
+ ** Sun Jan 1: 52
+ ** Sat Jan 1: 53 if previous
+ ** year a leap
+ ** year, else 52
+ */
+ if (i == TM_FRIDAY)
+ i = 53;
+ else if (i == TM_SUNDAY)
+ i = 52;
+ else i = isleap(t->tm_year +
+ TM_YEAR_BASE) ?
+ 53 : 52;
+#ifdef XPG4_1994_04_09
+ /*
+ ** As of 4/9/94, though,
+ ** XPG4 calls for 53
+ ** unconditionally.
+ */
+ i = 53;
+#endif /* defined XPG4_1994_04_09 */
+ }
+ pt = _conv(i, "%02d", pt, ptlim);
+ }
+ continue;
+ case 'v':
+ /*
+ ** From Arnold Robbins' strftime version 3.0:
+ ** "date as dd-bbb-YYYY"
+ ** (ado, 5/24/93)
+ */
+ pt = _fmt("%e-%b-%Y", t, pt, ptlim);
+ continue;
+ case 'W':
+ pt = _conv((t->tm_yday + 7 -
+ (t->tm_wday ?
+ (t->tm_wday - 1) : 6)) / 7,
+ "%02d", pt, ptlim);
+ continue;
+ case 'w':
+ pt = _conv(t->tm_wday, "%d", pt, ptlim);
+ continue;
+ case 'X':
+ pt = _fmt(Locale->X_fmt, t, pt, ptlim);
+ continue;
+ case 'x':
+ pt = _fmt(Locale->x_fmt, t, pt, ptlim);
+ continue;
+ case 'y':
+ pt = _conv((t->tm_year + TM_YEAR_BASE) % 100,
+ "%02d", pt, ptlim);
+ continue;
+ case 'Y':
+ pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d",
+ pt, ptlim);
+ continue;
+ case 'Z':
+ if (t->tm_zone != NULL)
+ pt = _add(t->tm_zone, pt, ptlim);
+ else
+ if (t->tm_isdst == 0 || t->tm_isdst == 1) {
+ pt = _add(tzname[t->tm_isdst],
+ pt, ptlim);
+ } else pt = _add("?", pt, ptlim);
+ continue;
+ case '+':
+ pt = _fmt(Locale->date_fmt, t, pt, ptlim);
+ continue;
+ case '%':
+ /*
+ * X311J/88-090 (4.12.3.5): if conversion char is
+ * undefined, behavior is undefined. Print out the
+ * character itself as printf(3) also does.
+ */
+ default:
+ break;
+ }
+ }
+ if (pt == ptlim)
+ break;
+ *pt++ = *format;
+ }
+ return pt;
+}
+
+static char *
+_conv(n, format, pt, ptlim)
+ const int n;
+ const char *const format;
+ char *const pt;
+ const char *const ptlim;
+{
+ char buf[INT_STRLEN_MAXIMUM(int) + 1];
+
+ (void) sprintf(buf, format, n);
+ return _add(buf, pt, ptlim);
+}
+
+static char *
+_secs(t, pt, ptlim)
+ const struct tm *t;
+ char *pt;
+ const char *ptlim;
+{
+ char buf[INT_STRLEN_MAXIMUM(int) + 1];
+ register time_t s;
+ struct tm tmp;
+
+ /* Make a copy, mktime(3) modifies the tm struct. */
+ tmp = *t;
+ s = mktime(&tmp);
+ (void) sprintf(buf, "%ld", s);
+ return _add(buf, pt, ptlim);
+}
+
+static char *
+_add(str, pt, ptlim)
+ const char *str;
+ char *pt;
+ const char *const ptlim;
+{
+ while (pt < ptlim && (*pt = *str++) != '\0')
+ ++pt;
+ return pt;
+}
+
+int
+__time_load_locale(const char *name)
+{
+ static char * locale_buf;
+ static char locale_buf_C[] = "C";
+
+ int fd;
+ char * lbuf;
+ char * p;
+ const char ** ap;
+ const char * plim;
+ char filename[PATH_MAX];
+ struct stat st;
+ size_t namesize;
+ size_t bufsize;
+ int save_using_locale;
+
+ save_using_locale = using_locale;
+ using_locale = 0;
+
+ if (name == NULL)
+ goto no_locale;
+
+ if (!strcmp(name, "C") || !strcmp(name, "POSIX"))
+ return 0;
+
+ /*
+ ** If the locale name is the same as our cache, use the cache.
+ */
+ lbuf = locale_buf;
+ if (lbuf != NULL && strcmp(name, lbuf) == 0) {
+ p = lbuf;
+ for (ap = (const char **) &localebuf;
+ ap < (const char **) (&localebuf + 1);
+ ++ap)
+ *ap = p += strlen(p) + 1;
+ using_locale = 1;
+ return 0;
+ }
+ /*
+ ** Slurp the locale file into the cache.
+ */
+ namesize = strlen(name) + 1;
+
+ if (!_PathLocale)
+ goto no_locale;
+ /* Range checking not needed, 'name' size is limited */
+ strcpy(filename, _PathLocale);
+ strcat(filename, "/");
+ strcat(filename, name);
+ strcat(filename, "/LC_TIME");
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ goto no_locale;
+ if (fstat(fd, &st) != 0)
+ goto bad_locale;
+ if (st.st_size <= 0)
+ goto bad_locale;
+ bufsize = namesize + st.st_size;
+ locale_buf = NULL;
+ lbuf = (lbuf == NULL || lbuf == locale_buf_C) ?
+ malloc(bufsize) : realloc(lbuf, bufsize);
+ if (lbuf == NULL)
+ goto bad_locale;
+ (void) strcpy(lbuf, name);
+ p = lbuf + namesize;
+ plim = p + st.st_size;
+ if (read(fd, p, (size_t) st.st_size) != st.st_size)
+ goto bad_lbuf;
+ if (close(fd) != 0)
+ goto bad_lbuf;
+ /*
+ ** Parse the locale file into localebuf.
+ */
+ if (plim[-1] != '\n')
+ goto bad_lbuf;
+ for (ap = (const char **) &localebuf;
+ ap < (const char **) (&localebuf + 1);
+ ++ap) {
+ if (p == plim)
+ goto reset_locale;
+ *ap = p;
+ while (*p != '\n')
+ ++p;
+ *p++ = '\0';
+ }
+ /*
+ ** Record the successful parse in the cache.
+ */
+ locale_buf = lbuf;
+
+ using_locale = 1;
+ return 0;
+
+reset_locale:
+ /*
+ * XXX - This may not be the correct thing to do in this case.
+ * setlocale() assumes that we left the old locale alone.
+ */
+ locale_buf = locale_buf_C;
+ localebuf = C_time_locale;
+ save_using_locale = 0;
+bad_lbuf:
+ free(lbuf);
+bad_locale:
+ (void) close(fd);
+no_locale:
+ using_locale = save_using_locale;
+ return -1;
+}
diff --git a/lib/libc/stdtime/time2posix.3 b/lib/libc/stdtime/time2posix.3
new file mode 100644
index 0000000..38bb1ab
--- /dev/null
+++ b/lib/libc/stdtime/time2posix.3
@@ -0,0 +1,114 @@
+.Dd May 1, 1996
+.Dt TIME2POSIX 3
+.Os
+.Sh NAME
+.Nm time2posix ,
+.Nm posix2time
+.Nd convert seconds since the Epoch
+.Sh SYNOPSIS
+.Fd #include <time.h>
+.Ft time_t
+.Fn time2posix "const time_t *t"
+.Ft time_t
+.Fn posix2time "const time_t *t"
+.Sh DESCRIPTION
+.St -p1003.1-88
+legislates that a time_t value of
+536457599 shall correspond to "Wed Dec 31 23:59:59 GMT 1986."
+This effectively implies that POSIX time_t's cannot include leap
+seconds and,
+therefore,
+that the system time must be adjusted as each leap occurs.
+.Pp
+If the time package is configured with leap-second support
+enabled,
+however,
+no such adjustment is needed and
+time_t values continue to increase over leap events
+(as a true `seconds since...' value).
+This means that these values will differ from those required by POSIX
+by the net number of leap seconds inserted since the Epoch.
+.Pp
+Typically this is not a problem as the type time_t is intended
+to be
+(mostly)
+opaque\(emtime_t values should only be obtained-from and
+passed-to functions such as
+.Xr time 2 ,
+.Xr localtime 3 ,
+.Xr mktime 3
+and
+.Xr difftime 3 .
+However,
+.Std -p1003.1-88
+gives an arithmetic
+expression for directly computing a time_t value from a given date/time,
+and the same relationship is assumed by some
+(usually older)
+applications.
+Any programs creating/dissecting time_t's
+using such a relationship will typically not handle intervals
+over leap seconds correctly.
+.Pp
+The
+.Fn time2posix
+and
+.Fn posix2time
+functions are provided to address this time_t mismatch by converting
+between local time_t values and their POSIX equivalents.
+This is done by accounting for the number of time-base changes that
+would have taken place on a POSIX system as leap seconds were inserted
+or deleted.
+These converted values can then be used in lieu of correcting the older
+applications,
+or when communicating with POSIX-compliant systems.
+.Pp
+The
+.Fn time2posix
+function is single-valued.
+That is,
+every local time_t
+corresponds to a single POSIX time_t.
+The
+.Fn posix2time
+function is less well-behaved:
+for a positive leap second hit the result is not unique,
+and for a negative leap second hit the corresponding
+POSIX time_t doesn't exist so an adjacent value is returned.
+Both of these are good indicators of the inferiority of the
+POSIX representation.
+.Pp
+The following table summarizes the relationship between time_t
+and its conversion to,
+and back from,
+the POSIX representation over the leap second inserted at the end of June,
+1993.
+.ta \w'93/06/30 'u +\w'23:59:59 'u +\w'A+0 'u +\w'X=time2posix(T) 'u
+DATE TIME T X=time2posix(T) posix2time(X)
+93/06/30 23:59:59 A+0 B+0 A+0
+93/06/30 23:59:60 A+1 B+1 A+1 or A+2
+93/07/01 00:00:00 A+2 B+1 A+1 or A+2
+93/07/01 00:00:01 A+3 B+2 A+3
+
+A leap second deletion would look like...
+
+DATE TIME T X=time2posix(T) posix2time(X)
+??/06/30 23:59:58 A+0 B+0 A+0
+??/07/01 00:00:00 A+1 B+2 A+1
+??/07/01 00:00:01 A+2 B+3 A+2
+.Pp
+ [Note: posix2time(B+1) => A+0 or A+1]
+.Pp
+If leap-second support is not enabled,
+local time_t's and
+POSIX time_t's are equivalent,
+and both
+.Fn time2posix
+and
+.Fn posix2time
+degenerate to the identity function.
+.Sh "SEE ALSO"
+.Xr difftime 3 ,
+.Xr localtime 3 ,
+.Xr mktime 3 ,
+.Xr time 3
diff --git a/lib/libc/stdtime/tzfile.5 b/lib/libc/stdtime/tzfile.5
new file mode 100644
index 0000000..f894390
--- /dev/null
+++ b/lib/libc/stdtime/tzfile.5
@@ -0,0 +1,122 @@
+.Dd September 13, 1994
+.Dt TZFILE 5
+.Os FreeBSD 2.0
+.Sh NAME
+.Nm tzfile
+.Nd timezone information
+.Sh SYNOPSIS
+.Fd #include <tzfile.h>
+.Sh DESCRIPTION
+The time zone information files used by
+.Xr tzset 3
+begin with bytes reserved for future use,
+followed by four four-byte values of type
+.Fa long ,
+written in a ``standard'' byte order
+(the high-order byte of the value is written first).
+These values are,
+in order:
+.Pp
+.Bl -tag -compact -width tzh_ttisstdcnt
+.It Li tzh_ttisstdcnt
+The number of standard/wall indicators stored in the file.
+.It Li tzh_leapcnt
+The number of leap seconds for which data is stored in the file.
+.It Li tzh_timecnt
+The number of ``transition times'' for which data is stored
+in the file.
+.It Li tzh_typecnt
+The number of ``local time types'' for which data is stored
+in the file (must not be zero).
+.It Li tzh_charcnt
+The number of characters of ``time zone abbreviation strings''
+stored in the file.
+.El
+.Pp
+The above header is followed by
+.Li tzh_timecnt
+four-byte values of type
+.Fa long ,
+sorted in ascending order.
+These values are written in ``standard'' byte order.
+Each is used as a transition time (as returned by
+.Xr time 3 )
+at which the rules for computing local time change.
+Next come
+.Li tzh_timecnt
+one-byte values of type
+.Fa "unsigned char" ;
+each one tells which of the different types of ``local time'' types
+described in the file is associated with the same-indexed transition time.
+These values serve as indices into an array of
+.Fa ttinfo
+structures that appears next in the file;
+these structures are defined as follows:
+.Pp
+.Bd -literal -offset indent
+struct ttinfo {
+ long tt_gmtoff;
+ int tt_isdst;
+ unsigned int tt_abbrind;
+};
+.Ed
+.Pp
+Each structure is written as a four-byte value for
+.Li tt_gmtoff
+of type
+.Fa long ,
+in a standard byte order, followed by a one-byte value for
+.Li tt_isdst
+and a one-byte value for
+.Li tt_abbrind .
+In each structure,
+.Li tt_gmtoff
+gives the number of seconds to be added to GMT,
+.Li tt_isdst
+tells whether
+.Li tm_isdst
+should be set by
+.Xr localtime 3
+and
+.Li tt_abbrind
+serves as an index into the array of time zone abbreviation characters
+that follow the
+.Li ttinfo
+structure(s) in the file.
+.Pp
+Then there are
+.Li tzh_leapcnt
+pairs of four-byte values, written in standard byte order;
+the first value of each pair gives the time
+(as returned by
+.Xr time 3 )
+at which a leap second occurs;
+the second gives the
+.Em total
+number of leap seconds to be applied after the given time.
+The pairs of values are sorted in ascending order by time.
+.Pp
+Finally there are
+.Li tzh_ttisstdcnt
+standard/wall indicators, each stored as a one-byte value;
+they tell whether the transition times associated with local time types
+were specified as standard time or wall clock time,
+and are used when a time zone file is used in handling POSIX-style
+time zone environment variables.
+.Pp
+.Nm localtime
+uses the first standard-time
+.Li ttinfo
+structure in the file
+(or simply the first
+.Li ttinfo
+structure in the absence of a standard-time structure)
+if either
+.Li tzh_timecnt
+is zero or the time argument is less than the first transition time recorded
+in the file.
+.Sh SEE ALSO
+.Xr ctime 3 ,
+.Xr time2posix 3 ,
+.Xr zic 8
+.\" @(#)tzfile.5 7.2
diff --git a/lib/libc/stdtime/tzfile.h b/lib/libc/stdtime/tzfile.h
new file mode 100644
index 0000000..58cdc3d
--- /dev/null
+++ b/lib/libc/stdtime/tzfile.h
@@ -0,0 +1,187 @@
+#ifndef TZFILE_H
+
+#define TZFILE_H
+
+/*
+** This file is in the public domain, so clarified as of
+** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
+*/
+
+/*
+** This header is for use ONLY with the time conversion code.
+** There is no guarantee that it will remain unchanged,
+** or that it will remain at all.
+** Do NOT copy it to any system include directory.
+** Thank you!
+*/
+
+/*
+** ID
+*/
+
+#ifndef lint
+#ifndef NOID
+/*
+static char tzfilehid[] = "@(#)tzfile.h 7.8";
+*/
+#endif /* !defined NOID */
+#endif /* !defined lint */
+
+/*
+** Information about time zone files.
+*/
+
+#ifndef TZDIR
+#define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */
+#endif /* !defined TZDIR */
+
+#ifndef TZDEFAULT
+#define TZDEFAULT "/etc/localtime"
+#endif /* !defined TZDEFAULT */
+
+#ifndef TZDEFRULES
+#define TZDEFRULES "posixrules"
+#endif /* !defined TZDEFRULES */
+
+/*
+** Each file begins with. . .
+*/
+
+struct tzhead {
+ char tzh_reserved[20]; /* reserved for future use */
+ char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
+ char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
+ char tzh_leapcnt[4]; /* coded number of leap seconds */
+ char tzh_timecnt[4]; /* coded number of transition times */
+ char tzh_typecnt[4]; /* coded number of local time types */
+ char tzh_charcnt[4]; /* coded number of abbr. chars */
+};
+
+/*
+** . . .followed by. . .
+**
+** tzh_timecnt (char [4])s coded transition times a la time(2)
+** tzh_timecnt (unsigned char)s types of local time starting at above
+** tzh_typecnt repetitions of
+** one (char [4]) coded GMT offset in seconds
+** one (unsigned char) used to set tm_isdst
+** one (unsigned char) that's an abbreviation list index
+** tzh_charcnt (char)s '\0'-terminated zone abbreviations
+** tzh_leapcnt repetitions of
+** one (char [4]) coded leap second transition times
+** one (char [4]) total correction after above
+** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
+** time is standard time, if FALSE,
+** transition time is wall clock time
+** if absent, transition times are
+** assumed to be wall clock time
+** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition
+** time is GMT, if FALSE,
+** transition time is local time
+** if absent, transition times are
+** assumed to be local time
+*/
+
+/*
+** In the current implementation, "tzset()" refuses to deal with files that
+** exceed any of the limits below.
+*/
+
+#ifndef TZ_MAX_TIMES
+/*
+** The TZ_MAX_TIMES value below is enough to handle a bit more than a
+** year's worth of solar time (corrected daily to the nearest second) or
+** 138 years of Pacific Presidential Election time
+** (where there are three time zone transitions every fourth year).
+*/
+#define TZ_MAX_TIMES 370
+#endif /* !defined TZ_MAX_TIMES */
+
+#ifndef TZ_MAX_TYPES
+#ifndef NOSOLAR
+#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
+#endif /* !defined NOSOLAR */
+#ifdef NOSOLAR
+/*
+** Must be at least 14 for Europe/Riga as of Jan 12 1995,
+** as noted by Earl Chew <earl@hpato.aus.hp.com>.
+*/
+#define TZ_MAX_TYPES 20 /* Maximum number of local time types */
+#endif /* !defined NOSOLAR */
+#endif /* !defined TZ_MAX_TYPES */
+
+#ifndef TZ_MAX_CHARS
+#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
+ /* (limited by what unsigned chars can hold) */
+#endif /* !defined TZ_MAX_CHARS */
+
+#ifndef TZ_MAX_LEAPS
+#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
+#endif /* !defined TZ_MAX_LEAPS */
+
+#define SECSPERMIN 60
+#define MINSPERHOUR 60
+#define HOURSPERDAY 24
+#define DAYSPERWEEK 7
+#define DAYSPERNYEAR 365
+#define DAYSPERLYEAR 366
+#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
+#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
+#define MONSPERYEAR 12
+
+#define TM_SUNDAY 0
+#define TM_MONDAY 1
+#define TM_TUESDAY 2
+#define TM_WEDNESDAY 3
+#define TM_THURSDAY 4
+#define TM_FRIDAY 5
+#define TM_SATURDAY 6
+
+#define TM_JANUARY 0
+#define TM_FEBRUARY 1
+#define TM_MARCH 2
+#define TM_APRIL 3
+#define TM_MAY 4
+#define TM_JUNE 5
+#define TM_JULY 6
+#define TM_AUGUST 7
+#define TM_SEPTEMBER 8
+#define TM_OCTOBER 9
+#define TM_NOVEMBER 10
+#define TM_DECEMBER 11
+
+#define TM_YEAR_BASE 1900
+
+#define EPOCH_YEAR 1970
+#define EPOCH_WDAY TM_THURSDAY
+
+/*
+** Accurate only for the past couple of centuries;
+** that will probably do.
+*/
+
+#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
+
+#ifndef USG
+
+/*
+** Use of the underscored variants may cause problems if you move your code to
+** certain System-V-based systems; for maximum portability, use the
+** underscore-free variants. The underscored variants are provided for
+** backward compatibility only; they may disappear from future versions of
+** this file.
+*/
+
+#define SECS_PER_MIN SECSPERMIN
+#define MINS_PER_HOUR MINSPERHOUR
+#define HOURS_PER_DAY HOURSPERDAY
+#define DAYS_PER_WEEK DAYSPERWEEK
+#define DAYS_PER_NYEAR DAYSPERNYEAR
+#define DAYS_PER_LYEAR DAYSPERLYEAR
+#define SECS_PER_HOUR SECSPERHOUR
+#define SECS_PER_DAY SECSPERDAY
+#define MONS_PER_YEAR MONSPERYEAR
+
+#endif /* !defined USG */
+
+#endif /* !defined TZFILE_H */
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc
index 55db696..e95d87d 100644
--- a/lib/libc/string/Makefile.inc
+++ b/lib/libc/string/Makefile.inc
@@ -1,92 +1,101 @@
# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
+# $Id: Makefile.inc,v 1.9 1997/02/22 15:03:21 peter Exp $
-.PATH: ${.CURDIR}/${MACHINE}/string ${.CURDIR}/string
+.PATH: ${.CURDIR}/../libc/${MACHINE}/string ${.CURDIR}/../libc/string
+CFLAGS += -I${.CURDIR}/../libc/locale
# machine-independent string sources
SRCS+= memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \
- strftime.c strmode.c strtok.c strxfrm.c swab.c
+ strmode.c strtok.c strxfrm.c
# machine-dependent string sources
-.include "${.CURDIR}/${MACHINE}/string/Makefile.inc"
+.include "${.CURDIR}/../libc/${MACHINE}/string/Makefile.inc"
# If no machine specific bzero(3), build one out of memset(3).
-.if empty(SRCS:Mbzero.s)
+.if empty(SRCS:Mbzero.S)
OBJS+= bzero.o
bzero.o: memset.c
${CC} -DBZERO ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET}
@${LD} -x -r ${.TARGET}
- @mv a.out ${.TARGET}
+ @mv -f a.out ${.TARGET}
bzero.po: memset.c
${CC} -DBZERO ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET}
@${LD} -X -r ${.TARGET}
- @mv a.out ${.TARGET}
+ @mv -f a.out ${.TARGET}
.endif
# If no machine specific memmove(3), build one out of bcopy(3).
-.if empty(SRCS:Mmemmove.s)
+.if empty(SRCS:Mmemmove.S)
OBJS+= memmove.o
memmove.o: bcopy.c
${CC} -DMEMMOVE ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET}
@${LD} -x -r ${.TARGET}
- @mv a.out ${.TARGET}
+ @mv -f a.out ${.TARGET}
memmove.po: bcopy.c
${CC} -DMEMMOVE ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET}
@${LD} -X -r ${.TARGET}
- @mv a.out ${.TARGET}
+ @mv -f a.out ${.TARGET}
.endif
# If no machine specific memcpy(3), build one out of bcopy(3).
-.if empty(SRCS:Mmemcpy.s)
+.if empty(SRCS:Mmemmove.S)
OBJS+= memcpy.o
memcpy.o: bcopy.c
${CC} -DMEMCOPY ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET}
@${LD} -x -r ${.TARGET}
- @mv a.out ${.TARGET}
+ @mv -f a.out ${.TARGET}
memcpy.po: bcopy.c
${CC} -DMEMCOPY ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET}
@${LD} -X -r ${.TARGET}
- @mv a.out ${.TARGET}
+ @mv -f a.out ${.TARGET}
.endif
# If no machine specific strchr(3), build one out of index(3).
-.if empty(SRCS:Mstrchr.s)
+.if empty(SRCS:Mstrchr.S)
OBJS+= strchr.o
strchr.o: index.c
${CC} -DSTRCHR ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET}
@${LD} -x -r ${.TARGET}
- @mv a.out ${.TARGET}
+ @mv -f a.out ${.TARGET}
strchr.po: index.c
${CC} -DSTRCHR ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET}
@${LD} -X -r ${.TARGET}
- @mv a.out ${.TARGET}
+ @mv -f a.out ${.TARGET}
.endif
# If no machine specific strrchr(3), build one out of rindex(3).
-.if empty(SRCS:Mstrrchr.s)
+.if empty(SRCS:Mstrrchr.S)
OBJS+= strrchr.o
strrchr.o: rindex.c
${CC} -DSTRRCHR ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET}
@${LD} -x -r ${.TARGET}
- @mv a.out ${.TARGET}
+ @mv -f a.out ${.TARGET}
strrchr.po: rindex.c
${CC} -DSTRRCHR ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET}
@${LD} -X -r ${.TARGET}
- @mv a.out ${.TARGET}
+ @mv -f a.out ${.TARGET}
.endif
-
-MAN3+= bcmp.0 bcopy.0 bstring.0 bzero.0 ffs.0 index.0 memccpy.0 memchr.0 \
- memcmp.0 memcpy.0 memmove.0 memset.0 rindex.0 strcasecmp.0 strcat.0 \
- strchr.0 strcmp.0 strcoll.0 strcpy.0 strcspn.0 strftime.0 string.0 \
- strlen.0 strmode.0 strdup.0 strerror.0 strpbrk.0 strrchr.0 strsep.0 \
- strspn.0 strstr.0 strtok.0 strxfrm.0 swab.0
-
+#
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN3+= string/bcmp.3 string/bcopy.3 string/bstring.3 string/bzero.3 \
+ string/ffs.3 string/index.3 string/memccpy.3 string/memchr.3 \
+ string/memcmp.3 string/memcpy.3 string/memmove.3 string/memset.3 \
+ string/rindex.3 string/strcasecmp.3 string/strcat.3 string/strchr.3 \
+ string/strcmp.3 string/strcoll.3 string/strcpy.3 string/strcspn.3 \
+ string/string.3 string/strlen.3 string/strmode.3 \
+ string/strdup.3 string/strerror.3 string/strpbrk.3 string/strrchr.3 \
+ string/strsep.3 string/strspn.3 string/strstr.3 string/strtok.3 \
+ string/strxfrm.3 string/swab.3
+#
MLINKS+=strcasecmp.3 strncasecmp.3
MLINKS+=strcat.3 strncat.3
MLINKS+=strcmp.3 strncmp.3
MLINKS+=strcpy.3 strncpy.3
-MLINKS+=strerror.3 perror.3
+MLINKS+=strerror.3 perror.3 strerror.3 sys_errlist.3 strerror.3 sys_nerr.3
+.endif
diff --git a/lib/libc/string/memccpy.3 b/lib/libc/string/memccpy.3
index 28d6441..92009bd 100644
--- a/lib/libc/string/memccpy.3
+++ b/lib/libc/string/memccpy.3
@@ -69,4 +69,5 @@ bytes are copied, and a NULL pointer is returned.
.Sh HISTORY
The
.Fn memccpy
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/string/memccpy.c b/lib/libc/string/memccpy.c
index 878e419..c457110 100644
--- a/lib/libc/string/memccpy.c
+++ b/lib/libc/string/memccpy.c
@@ -49,9 +49,10 @@ memccpy(t, f, c, n)
if (n) {
register unsigned char *tp = t;
register const unsigned char *fp = f;
+ register unsigned char uc = c;
do {
- if ((*tp++ = *fp++) == c)
- return (t);
+ if ((*tp++ = *fp++) == uc)
+ return (tp);
} while (--n != 0);
}
return (0);
diff --git a/lib/libc/string/memcmp.3 b/lib/libc/string/memcmp.3
index a859529..4fbee33 100644
--- a/lib/libc/string/memcmp.3
+++ b/lib/libc/string/memcmp.3
@@ -34,6 +34,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)memcmp.3 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt MEMCMP 3
@@ -60,7 +61,7 @@ bytes long.
The
.Fn memcmp
function
-returns zero if the the two strings are identical,
+returns zero if the two strings are identical,
otherwise returns the difference between the first two differing bytes
(treated as unsigned char values, so that
.Sq Li \e200
diff --git a/lib/libc/string/memset.c b/lib/libc/string/memset.c
index 9c28b7b..99c72dc 100644
--- a/lib/libc/string/memset.c
+++ b/lib/libc/string/memset.c
@@ -84,7 +84,7 @@ memset(dst0, c0, length)
*
* but we use a minimum of 3 here since the overhead of the code
* to do word writes is substantial.
- */
+ */
if (length < 3 * wsize) {
while (length != 0) {
*dst++ = VAL;
diff --git a/lib/libc/string/strcasecmp.3 b/lib/libc/string/strcasecmp.3
index f9d27ff..c26740e 100644
--- a/lib/libc/string/strcasecmp.3
+++ b/lib/libc/string/strcasecmp.3
@@ -83,4 +83,5 @@ The
.Fn strcasecmp
and
.Fn strncasecmp
-functions first appeared in 4.4BSD.
+functions first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/string/strcasecmp.c b/lib/libc/string/strcasecmp.c
index f31c297..463c4de 100644
--- a/lib/libc/string/strcasecmp.c
+++ b/lib/libc/string/strcasecmp.c
@@ -33,6 +33,7 @@
#include <sys/cdefs.h>
#include <string.h>
+#include <ctype.h>
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93";
@@ -40,58 +41,18 @@ static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93";
typedef unsigned char u_char;
-/*
- * This array is designed for mapping upper and lower case letter
- * together for a case independent comparison. The mappings are
- * based upon ascii character sequences.
- */
-static const u_char charmap[] = {
- '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
- '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
- '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
- '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
- '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
- '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
- '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
- '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
- '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
- '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
- '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
- '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
- '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
- '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
- '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
- '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
- '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
- '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
- '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
- '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
- '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
- '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
- '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
- '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
- '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
- '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
- '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
- '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
- '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
- '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
- '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
- '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
-};
-
int
strcasecmp(s1, s2)
const char *s1, *s2;
{
- register const u_char *cm = charmap,
+ register const u_char
*us1 = (const u_char *)s1,
*us2 = (const u_char *)s2;
- while (cm[*us1] == cm[*us2++])
+ while (tolower(*us1) == tolower(*us2++))
if (*us1++ == '\0')
return (0);
- return (cm[*us1] - cm[*--us2]);
+ return (tolower(*us1) - tolower(*--us2));
}
int
@@ -100,13 +61,13 @@ strncasecmp(s1, s2, n)
register size_t n;
{
if (n != 0) {
- register const u_char *cm = charmap,
+ register const u_char
*us1 = (const u_char *)s1,
*us2 = (const u_char *)s2;
do {
- if (cm[*us1] != cm[*us2++])
- return (cm[*us1] - cm[*--us2]);
+ if (tolower(*us1) != tolower(*us2++))
+ return (tolower(*us1) - tolower(*--us2));
if (*us1++ == '\0')
break;
} while (--n != 0);
diff --git a/lib/libc/string/strcat.3 b/lib/libc/string/strcat.3
index 6fe13aa..0d34d58 100644
--- a/lib/libc/string/strcat.3
+++ b/lib/libc/string/strcat.3
@@ -68,7 +68,10 @@ The
function
appends not more than
.Fa count
-characters.
+characters from
+.Fa append ,
+and then adds a terminating
+.Ql \e0.
.Sh RETURN VALUES
The
.Fn strcat
diff --git a/lib/libc/string/strcmp.c b/lib/libc/string/strcmp.c
index 79cfaa8..cf25e50 100644
--- a/lib/libc/string/strcmp.c
+++ b/lib/libc/string/strcmp.c
@@ -51,5 +51,5 @@ strcmp(s1, s2)
while (*s1 == *s2++)
if (*s1++ == 0)
return (0);
- return (*(unsigned char *)s1 - *(unsigned char *)--s2);
+ return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1));
}
diff --git a/lib/libc/string/strcoll.3 b/lib/libc/string/strcoll.3
index 95774f6..08f48ad 100644
--- a/lib/libc/string/strcoll.3
+++ b/lib/libc/string/strcoll.3
@@ -53,17 +53,15 @@ lexicographically compares the null-terminated strings
.Fa s1
and
.Fa s2
-according to the current locale collation
+according to the current locale collation if any, otherwise call
+.Fa strcmp ,
and returns an integer greater than, equal to, or less than 0,
according as
.Fa s1
is greater than, equal to, or less than
.Fa s2 .
.Sh SEE ALSO
-.Xr bcmp 3 ,
-.Xr memcmp 3 ,
.Xr setlocale 3 ,
-.Xr strcasecmp 3 ,
.Xr strcmp 3 ,
.Xr strxfrm 3
.Sh STANDARDS
diff --git a/lib/libc/string/strcoll.c b/lib/libc/string/strcoll.c
index 3b9f42e..259ca23 100644
--- a/lib/libc/string/strcoll.c
+++ b/lib/libc/string/strcoll.c
@@ -1,9 +1,7 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
+ * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
+ * at Electronni Visti IA, Kiev, Ukraine.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -13,18 +11,11 @@
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 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
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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)
@@ -32,22 +23,56 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strcoll.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/cdefs.h>
+#include <stdlib.h>
#include <string.h>
+#include "collate.h"
-/*
- * Compare strings according to LC_COLLATE category of current locale.
- */
int
-strcoll(s1, s2)
- const char *s1, *s2;
+strcoll(s, s2)
+ const char *s, *s2;
{
- /* LC_COLLATE is unimplemented, hence always "C" */
- return (strcmp(s1, s2));
+ int len, len2, prim, prim2, sec, sec2, ret, ret2;
+ char *tt, *t, *tt2, *t2;
+
+ if (__collate_load_error)
+ return strcmp(s, s2);
+
+ len = len2 = 1;
+ ret = ret2 = 0;
+ tt = t = __collate_substitute(s);
+ tt2 = t2 = __collate_substitute(s2);
+ while(*t && *t2) {
+ prim = prim2 = 0;
+ while(*t && !prim) {
+ __collate_lookup(t, &len, &prim, &sec);
+ t += len;
+ }
+ while(*t2 && !prim2) {
+ __collate_lookup(t2, &len2, &prim2, &sec2);
+ t2 += len2;
+ }
+ if(!prim || !prim2)
+ break;
+ if(prim != prim2) {
+ ret = prim - prim2;
+ goto end;
+ }
+ if(!ret2)
+ ret2 = sec - sec2;
+ }
+ if(!*t && *t2)
+ ret = -(int)((u_char)*t2);
+ else if(*t && !*t2)
+ ret = (u_char)*t;
+ else if(!*t && !*t2)
+ ret = ret2;
+ end:
+ free(tt);
+ free(tt2);
+
+ return ret;
}
diff --git a/lib/libc/string/strdup.3 b/lib/libc/string/strdup.3
index 2f1d5d2..c99b416 100644
--- a/lib/libc/string/strdup.3
+++ b/lib/libc/string/strdup.3
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)strdup.3 8.1 (Berkeley) 6/9/93
+.\" $Id$
.\"
.Dd June 9, 1993
.Dt STRDUP 3
@@ -55,9 +56,10 @@ argument to the function
.Pp
If insufficient memory is available, NULL is returned.
.Sh SEE ALSO
+.Xr free 3 ,
.Xr malloc 3
-.Xr free 3
.Sh HISTORY
The
.Fn strdup
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/string/strdup.c b/lib/libc/string/strdup.c
index 6fa50ce..a1c2eed 100644
--- a/lib/libc/string/strdup.c
+++ b/lib/libc/string/strdup.c
@@ -35,8 +35,6 @@
static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/types.h>
-
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -49,8 +47,8 @@ strdup(str)
char *copy;
len = strlen(str) + 1;
- if (!(copy = malloc((u_int)len)))
+ if ((copy = malloc(len)) == NULL)
return (NULL);
- bcopy(str, copy, len);
+ memcpy(copy, str, len);
return (copy);
}
diff --git a/lib/libc/string/strerror.3 b/lib/libc/string/strerror.3
index 784c061..67c22db 100644
--- a/lib/libc/string/strerror.3
+++ b/lib/libc/string/strerror.3
@@ -48,8 +48,8 @@
.Fd #include <stdio.h>
.Ft void
.Fn perror "const char *string"
-.Vt extern char *sys_errlist[];
-.Vt extern int sys_nerr;
+.Vt extern const char * const sys_errlist[];
+.Vt extern const int sys_nerr;
.Fd #include <string.h>
.Ft char *
.Fn strerror "int errnum"
@@ -100,11 +100,11 @@ followed by the error number in decimal.
.Pp
The message strings can be accessed directly using the external
array
-.Fa sys_errlist .
+.Va sys_errlist .
The external value
-.Fa sys_nerr
+.Va sys_nerr
contains a count of the messages in
-.Fa sys_errlist .
+.Va sys_errlist .
The use of these variables is deprecated;
.Fn strerror
should be used instead.
@@ -116,9 +116,15 @@ The
.Fn strerror
and
.Fn perror
-functions first appeared in 4.4BSD.
+functions first appeared in
+.Bx 4.4 .
.Sh BUGS
For unknown error numbers, the
.Fn strerror
function will return its result in a static buffer which
may be overwritten by subsequent calls.
+.Pp
+Programs that use the deprecated
+.Va sys_errlist
+variable often fail to compile because they declare it
+inconsistently.
diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c
index 53f374b..5acefd9 100644
--- a/lib/libc/string/strerror.c
+++ b/lib/libc/string/strerror.c
@@ -35,14 +35,13 @@
static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
+#include <stdio.h>
#include <string.h>
char *
strerror(num)
int num;
{
- extern int sys_nerr;
- extern char *sys_errlist[];
#define UPREFIX "Unknown error: "
static char ebuf[40] = UPREFIX; /* 64-bit number + slop */
register unsigned int errnum;
@@ -51,17 +50,22 @@ strerror(num)
errnum = num; /* convert to unsigned */
if (errnum < sys_nerr)
- return(sys_errlist[errnum]);
+ return ((char *)sys_errlist[errnum]);
- /* Do this by hand, so we don't include stdio(3). */
+ /* Do this by hand, so we don't link to stdio(3). */
t = tmp;
+ if (num < 0)
+ errnum = -errnum;
do {
*t++ = "0123456789"[errnum % 10];
} while (errnum /= 10);
+ if (num < 0)
+ *t++ = '-';
for (p = ebuf + sizeof(UPREFIX) - 1;;) {
*p++ = *--t;
if (t <= tmp)
break;
}
- return(ebuf);
+ *p = '\0';
+ return (ebuf);
}
diff --git a/lib/libc/string/string.3 b/lib/libc/string/string.3
index c257d94..462482f 100644
--- a/lib/libc/string/string.3
+++ b/lib/libc/string/string.3
@@ -32,6 +32,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)string.3 8.2 (Berkeley) 12/11/93
+.\" $Id$
.\"
.Dd December 11, 1993
.Dt STRING 3
@@ -114,23 +115,23 @@ Except as noted in their specific manual pages,
the string functions do not test the destination
for size limitations.
.Sh SEE ALSO
+.Xr bstring 3 ,
.Xr index 3 ,
+.Xr rindex 3 ,
+.Xr strcasecmp 3 ,
.Xr strcat 3 ,
.Xr strchr 3 ,
-.Xr strrchr 3 ,
.Xr strcmp 3 ,
-.Xr strcasecmp 3 ,
.Xr strcpy 3 ,
+.Xr strcspn 3 ,
.Xr strerror 3 ,
.Xr strlen 3 ,
.Xr strpbrk 3 ,
+.Xr strrchr 3 ,
.Xr strsep 3 ,
.Xr strspn 3 ,
-.Xr strcspn 3 ,
.Xr strstr 3 ,
-.Xr strtok 3 ,
-.Xr rindex 3
-.Xr bstring 3
+.Xr strtok 3
.Sh STANDARDS
The
.Fn strcat ,
diff --git a/lib/libc/string/strmode.3 b/lib/libc/string/strmode.3
index 43d0cf1..3efc889 100644
--- a/lib/libc/string/strmode.3
+++ b/lib/libc/string/strmode.3
@@ -146,4 +146,5 @@ always returns 0.
.Sh HISTORY
The
.Fn strmode
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/string/strncmp.c b/lib/libc/string/strncmp.c
index 805b5b0..4b701a9 100644
--- a/lib/libc/string/strncmp.c
+++ b/lib/libc/string/strncmp.c
@@ -48,7 +48,8 @@ strncmp(s1, s2, n)
return (0);
do {
if (*s1 != *s2++)
- return (*(unsigned char *)s1 - *(unsigned char *)--s2);
+ return (*(const unsigned char *)s1 -
+ *(const unsigned char *)(s2 - 1));
if (*s1++ == 0)
break;
} while (--n != 0);
diff --git a/lib/libc/string/strsep.3 b/lib/libc/string/strsep.3
index 938b657..fd10494 100644
--- a/lib/libc/string/strsep.3
+++ b/lib/libc/string/strsep.3
@@ -43,7 +43,7 @@
.Sh SYNOPSIS
.Fd #include <string.h>
.Ft char *
-.Fn strsep "char **stringp" "char *delim"
+.Fn strsep "char **stringp" "const char *delim"
.Sh DESCRIPTION
The
.Fn strsep
@@ -104,4 +104,5 @@ two adjacent delimiter characters, or to be used for more than a single
string at a time.
The
.Fn strsep
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/string/strsep.c b/lib/libc/string/strsep.c
index 18dc398..ddad596 100644
--- a/lib/libc/string/strsep.c
+++ b/lib/libc/string/strsep.c
@@ -41,7 +41,7 @@ static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93";
/*
* Get next token from string *stringp, where tokens are possibly-empty
- * strings separated by characters from delim.
+ * strings separated by characters from delim.
*
* Writes NULs into the string at *stringp to end tokens.
* delim need not remain constant from call to call.
diff --git a/lib/libc/string/strspn.3 b/lib/libc/string/strspn.3
index 04c4bdc..e96cbeb 100644
--- a/lib/libc/string/strspn.3
+++ b/lib/libc/string/strspn.3
@@ -47,7 +47,7 @@
.Fn strspn "const char *s" "const char *charset"
.Sh DESCRIPTION
The
-.Fn strcspn
+.Fn strspn
function
spans the initial part of the null-terminated string
.Fa s
diff --git a/lib/libc/string/strxfrm.3 b/lib/libc/string/strxfrm.3
index ccd8bcb..308f942 100644
--- a/lib/libc/string/strxfrm.3
+++ b/lib/libc/string/strxfrm.3
@@ -48,16 +48,25 @@
.Sh DESCRIPTION
The
.Fn strxfrm
-function
-does something horrible (see
-.Tn ANSI
-standard).
-In this implementation it just copies.
+function transforms a null-terminated string pointed to by
+.Fa src
+according to the current locale collation if any,
+then copies not more than
+.Fa n-1
+characters of the resulting string into
+.Fa dst ,
+terminating it with a null character and then returns the resulting length.
+Comparing two strings using
+.Fn strcmp
+after
+.Fn strxfrm
+is equal to comparing
+two original strings with
+.Fn strcoll .
+.Sh BUGS
+Sometimes the behavior of this function is unpredictable.
.Sh SEE ALSO
-.Xr bcmp 3 ,
-.Xr memcmp 3 ,
-.\" .Xr setlocale 3 ,
-.Xr strcasecmp 3 ,
+.Xr setlocale 3 ,
.Xr strcmp 3 ,
.Xr strcoll 3
.Sh STANDARDS
diff --git a/lib/libc/string/strxfrm.c b/lib/libc/string/strxfrm.c
index 0d6fcb4..64b0bcf 100644
--- a/lib/libc/string/strxfrm.c
+++ b/lib/libc/string/strxfrm.c
@@ -1,9 +1,7 @@
/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
+ * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
+ * at Electronni Visti IA, Kiev, Ukraine.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -13,18 +11,11 @@
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 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
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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)
@@ -32,36 +23,70 @@
* 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.
+ *
+ * $Id$
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strxfrm.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/cdefs.h>
+#include <stdlib.h>
#include <string.h>
+#include "collate.h"
-/*
- * Transform src, storing the result in dst, such that
- * strcmp() on transformed strings returns what strcoll()
- * on the original untransformed strings would return.
- */
size_t
-strxfrm(dst, src, n)
- register char *dst;
+strxfrm(dest, src, len)
+ char *dest;
const char *src;
- size_t n;
+ size_t len;
{
- register size_t srclen, copysize;
+ int prim, sec, l;
+ char *d = dest, *s, *ss;
+
+ if (len < 1)
+ return 0;
+
+ if (!*src) {
+ *d = '\0';
+ return 0;
+ }
+
+ if (__collate_load_error) {
+ size_t slen = strlen(src);
+
+ if (slen < len) {
+ strcpy(d, src);
+ return slen;
+ }
+ strncpy(d, src, len - 1);
+ d[len - 1] = '\0';
+ return len - 1;
+ }
- /*
- * Since locales are unimplemented, this is just a copy.
- */
- srclen = strlen(src);
- if (n != 0) {
- copysize = srclen < n ? srclen : n - 1;
- (void)memcpy(dst, src, copysize);
- dst[copysize] = 0;
+ ss = s = __collate_substitute(src);
+ prim = sec = 0;
+ while (*s && len > 1) {
+ while (*s && !prim) {
+ __collate_lookup(s, &l, &prim, &sec);
+ s += l;
+ }
+ if (prim) {
+ *d++ = (char)prim;
+ len--;
+ }
+ }
+#if 0
+ s = ss;
+ while (*s && len > 1) {
+ while (*s && !prim) {
+ lookup(s, &l, &prim, &sec);
+ s += l;
+ }
+ if (prim && sec) {
+ *d++ = (char)sec;
+ len--;
+ }
}
- return (srclen);
+#endif /* 0 */
+ *d = '\0';
+ free(ss);
+
+ return d - dest;
}
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index c89e36e..fbe9067 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -1,89 +1,131 @@
# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94
+# $Id: Makefile.inc,v 1.33 1997/06/01 09:20:30 peter Exp $
# sys sources
-.PATH: ${.CURDIR}/${MACHINE}/sys ${.CURDIR}/sys
+.PATH: ${.CURDIR}/../libc/${MACHINE}/sys ${.CURDIR}/../libc/sys
# modules with non-default implementations on at least one architecture:
-SRCS+= Ovfork.s brk.s cerror.s exect.s fork.s pipe.s ptrace.s reboot.s \
- sbrk.s setlogin.s sigpending.s sigprocmask.s sigreturn.s \
- sigsuspend.s syscall.s
+SRCS+= Ovfork.S brk.S cerror.S exect.S fork.S pipe.S ptrace.S reboot.S \
+ rfork.S sbrk.S setlogin.S sigpending.S sigprocmask.S sigreturn.S \
+ sigsuspend.S syscall.S
# glue to provide compatibility between GCC 1.X and 2.X
SRCS+= ftruncate.c lseek.c mmap.c truncate.c
# modules with default implementations on all architectures:
-ASM= accept.o access.o acct.o adjtime.o bind.o chdir.o chflags.o chmod.o \
- chown.o chroot.o close.o connect.o dup.o dup2.o execve.o fchdir.o \
- fchflags.o fchmod.o fchown.o fcntl.o flock.o fpathconf.o fstat.o \
- fstatfs.o fsync.o getdirentries.o getdtablesize.o getegid.o \
+ASM= access.o acct.o adjtime.o chdir.o chflags.o chmod.o \
+ chown.o chroot.o \
+ clock_getres.o clock_gettime.o clock_settime.o \
+ getdtablesize.o getegid.o \
geteuid.o getfh.o getfsstat.o getgid.o getgroups.o getitimer.o \
- getpeername.o getpgrp.o getpid.o getppid.o getpriority.o \
- getrlimit.o getrusage.o getsockname.o getsockopt.o gettimeofday.o \
- getuid.o ioctl.o kill.o ktrace.o lfs_bmapv.o lfs_markv.o \
- lfs_segclean.o lfs_segwait.o link.o listen.o lstat.o \
- madvise.o mincore.o mkdir.o mkfifo.o mknod.o mlock.o mount.o \
- mprotect.o msync.o munlock.o munmap.o nfssvc.o open.o \
- pathconf.o profil.o quotactl.o read.o \
- readlink.o readv.o recvfrom.o recvmsg.o rename.o revoke.o rmdir.o \
- select.o sendmsg.o sendto.o setegid.o seteuid.o setgid.o \
- setgroups.o setitimer.o setpgid.o setpriority.o setrlimit.o \
- setsid.o setsockopt.o settimeofday.o setuid.o shutdown.o \
- sigaction.o sigaltstack.o socket.o socketpair.o stat.o statfs.o \
- swapon.o symlink.o sync.o umask.o undelete.o unlink.o unmount.o \
- utimes.o vadvise.o wait4.o write.o writev.o __syscall.o __sysctl.o
-
-PSEUDO= _exit.o _getlogin.o
-
-OBJS+= ${ASM} ${PSEUDO}
-POBJS+= ${ASM:.o=.po} ${PSEUDO:.o=.po}
-CLEANFILES+=${ASM} ${PSEUDO} ${POBJS}
-
-${ASM}: ${.CURDIR}/${MACHINE}/SYS.h /usr/include/sys/syscall.h
- @echo creating ${.PREFIX}.o ${.PREFIX}.po
- @printf '#include "SYS.h"\nRSYSCALL(${.PREFIX})\n' | \
- ${CPP} ${CFLAGS:M-[ID]*} ${AINC} | ${AS} -o ${.PREFIX}.o
- @${LD} -x -r ${.PREFIX}.o
- @mv a.out ${.PREFIX}.o
- @printf '#include "SYS.h"\nRSYSCALL(${.PREFIX})\n' | \
- ${CPP} -DPROF ${CFLAGS:M-[ID]*} ${AINC} | ${AS} -o ${.PREFIX}.po
- @${LD} -x -r ${.PREFIX}.po
- @mv a.out ${.PREFIX}.po
-
-${PSEUDO}: ${.CURDIR}/${MACHINE}/SYS.h /usr/include/sys/syscall.h
- @echo creating ${.PREFIX}.o ${.PREFIX}.po
- @printf '#include "SYS.h"\nPSEUDO(${.PREFIX},${.PREFIX:S/_//})\n' | \
- ${CPP} ${CFLAGS:M-[ID]*} ${AINC} | ${AS} -o ${.PREFIX}.o
- @${LD} -x -r ${.PREFIX}.o
- @mv a.out ${.PREFIX}.o
- @printf '#include "SYS.h"\nPSEUDO(${.PREFIX},${.PREFIX:S/_//})\n' | \
- ${CPP} -DPROF ${CFLAGS:M-[ID]*} ${AINC} | ${AS} -o ${.PREFIX}.po
- @${LD} -x -r ${.PREFIX}.po
- @mv a.out ${.PREFIX}.po
-
-MAN2+= accept.0 access.0 acct.0 adjtime.0 bind.0 brk.0 chdir.0 chflags.0 \
- chmod.0 chown.0 chroot.0 close.0 connect.0 dup.0 execve.0 _exit.0 \
- fcntl.0 flock.0 fork.0 fsync.0 getdirentries.0 getdtablesize.0 \
- getfh.0 getfsstat.0 getgid.0 getgroups.0 getitimer.0 getlogin.0 \
- getpeername.0 getpgrp.0 getpid.0 getpriority.0 getrlimit.0 \
- getrusage.0 getsockname.0 getsockopt.0 gettimeofday.0 getuid.0 \
- intro.0 ioctl.0 kill.0 ktrace.0 link.0 listen.0 lseek.0 \
- mkdir.0 mkfifo.0 mknod.0 madvise.0 mincore.0 mlock.0 mmap.0 \
- mount.0 mprotect.0 msync.0 munmap.0 \
- nfssvc.0 open.0 pathconf.0 pipe.0 profil.0 ptrace.0 quotactl.0 \
- munmap.0 nfssvc.0 open.0 pipe.0 profil.0 ptrace.0 quotactl.0 \
- read.0 readlink.0 reboot.0 recv.0 rename.0 revoke.0 rmdir.0 \
- select.0 send.0 setgroups.0 setpgid.0 setsid.0 setuid.0 shutdown.0 \
- sigaction.0 sigpending.0 sigprocmask.0 sigreturn.0 sigaltstack.0 \
- sigstack.0 sigsuspend.0 socket.0 socketpair.0 stat.0 statfs.0 \
- swapon.0 symlink.0 sync.0 syscall.0 truncate.0 umask.0 unlink.0 \
- undelete.0 utimes.0 vfork.0 wait.0 write.0
+ getpgrp.o getpid.o getppid.o getpriority.o \
+ getrlimit.o getrusage.o gettimeofday.o \
+ getuid.o issetugid.o kill.o ktrace.o lchown.o \
+ lfs_bmapv.o lfs_markv.o \
+ lfs_segclean.o lfs_segwait.o link.o lstat.o \
+ madvise.o mincore.o minherit.o mkdir.o mlock.o \
+ mount.o \
+ mprotect.o msgsys.o msync.o munlock.o munmap.o \
+ ntp_adjtime.o pathconf.o profil.o quotactl.o \
+ readlink.o rename.o revoke.o rmdir.o \
+ rtprio.o semsys.o setegid.o seteuid.o \
+ setgid.o \
+ setgroups.o setitimer.o setpgid.o setpriority.o \
+ setregid.o setreuid.o setrlimit.o \
+ setsid.o settimeofday.o setuid.o shmsys.o \
+ stat.o statfs.o \
+ swapon.o symlink.o sync.o sysarch.o \
+ umask.o undelete.o unlink.o unmount.o utimes.o utrace.o \
+ vadvise.o __syscall.o __sysctl.o \
+ modnext.o modstat.o modfnext.o modfind.o \
+ kldload.o kldunload.o kldfind.o kldnext.o kldstat.o kldfirstmod.o
+
+# Syscalls renamed as _thread_sys_{syscall} when building libc_r.
+ASMR= accept.o bind.o close.o connect.o dup.o dup2.o \
+ execve.o fchdir.o fchflags.o fchmod.o fchown.o fcntl.o \
+ flock.o fpathconf.o fstat.o fstatfs.o fsync.o getdirentries.o \
+ getpeername.o getsockname.o getsockopt.o ioctl.o listen.o \
+ mkfifo.o mknod.o nanosleep.o nfssvc.o open.o read.o readv.o \
+ recvfrom.o recvmsg.o select.o sendmsg.o sendto.o setsockopt.o \
+ shutdown.o sigaction.o sigaltstack.o signanosleep.o socket.o \
+ socketpair.o \
+ wait4.o write.o writev.o
+
+PSEUDO= _getlogin.o
+
+# Pseudo syscalls that are renamed as _thread_sys_{pseudo} when
+# building libc_r.
+PSEUDOR= _exit.o
+
+OBJS+= ${ASM} ${ASMR} ${PSEUDO} ${PSEUDOR}
+
+SASM= ${ASM:S/.o/.S/}
+
+SASMR= ${ASMR:S/.o/.S/}
+
+SPSEUDO= ${PSEUDO:S/.o/.S/}
+
+SPSEUDOR= ${PSEUDOR:S/.o/.S/}
+
+SRCS+= ${SASM} ${SASMR} ${SPSEUDO} ${SPSEUDOR}
+
+# Generated files
+CLEANFILES+= ${SASM} ${SASMR} ${SPSEUDO} ${SPSEUDOR}
+
+${SASM}:
+ printf '#include "SYS.h"\nRSYSCALL(${.PREFIX})\n' > ${.TARGET}
+
+${SASMR}:
+ printf '#include "SYS.h"\nPRSYSCALL(${.PREFIX})\n' > ${.TARGET}
+
+${SPSEUDO}:
+ printf '#include "SYS.h"\nPSEUDO(${.PREFIX},${.PREFIX:S/_//})\n' \
+ > ${.TARGET}
+
+${SPSEUDOR}:
+ printf '#include "SYS.h"\nPPSEUDO(${.PREFIX},${.PREFIX:S/_//})\n' \
+ > ${.TARGET}
+
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN2+= sys/accept.2 sys/access.2 sys/acct.2 sys/adjtime.2 sys/bind.2 \
+ sys/brk.2 sys/chdir.2 sys/chflags.2 sys/chmod.2 sys/chown.2 \
+ sys/chroot.2 sys/clock_gettime.2 sys/close.2 sys/connect.2 sys/dup.2 \
+ sys/execve.2 \
+ sys/_exit.2 sys/fcntl.2 sys/flock.2 sys/fork.2 sys/fsync.2 \
+ sys/getdirentries.2 sys/getdtablesize.2 sys/getfh.2 sys/getfsstat.2 \
+ sys/getgid.2 sys/getgroups.2 sys/getitimer.2 sys/getlogin.2 \
+ sys/getpeername.2 sys/getpgrp.2 sys/getpid.2 sys/getpriority.2 \
+ sys/getrlimit.2 sys/getrusage.2 sys/getsockname.2 sys/getsockopt.2 \
+ sys/gettimeofday.2 sys/getuid.2 sys/intro.2 sys/ioctl.2 \
+ sys/issetugid.2 sys/kill.2 \
+ sys/ktrace.2 sys/link.2 sys/listen.2 sys/lseek.2 sys/mkdir.2 \
+ sys/mkfifo.2 sys/mknod.2 sys/madvise.2 sys/mincore.2 sys/minherit.2 \
+ sys/mlock.2 \
+ sys/mmap.2 sys/mount.2 sys/mprotect.2 sys/msync.2 sys/munmap.2 \
+ sys/nanosleep.2 \
+ sys/ptrace.2 sys/nfssvc.2 sys/open.2 sys/pathconf.2 sys/pipe.2 \
+ sys/profil.2 sys/quotactl.2 sys/read.2 sys/readlink.2 sys/reboot.2 \
+ sys/recv.2 sys/rename.2 sys/revoke.2 sys/rfork.2 sys/rmdir.2 \
+ sys/rtprio.2 sys/select.2 \
+ sys/semctl.2 sys/semget.2 sys/semop.2 \
+ sys/send.2 sys/setgroups.2 \
+ sys/setpgid.2 sys/setregid.2 sys/setreuid.2 \
+ sys/setsid.2 sys/setuid.2 sys/shmat.2 sys/shmctl.2 sys/shmget.2 \
+ sys/shutdown.2 \
+ sys/sigaction.2 sys/sigpending.2 sys/sigprocmask.2 sys/sigreturn.2 \
+ sys/sigaltstack.2 sys/sigstack.2 sys/sigsuspend.2 sys/socket.2 \
+ sys/socketpair.2 sys/stat.2 sys/statfs.2 sys/swapon.2 sys/symlink.2 \
+ sys/sync.2 sys/syscall.2 sys/truncate.2 sys/umask.2 sys/unlink.2 \
+ sys/undelete.2 sys/utimes.2 sys/vfork.2 sys/wait.2 sys/write.2
MLINKS+=brk.2 sbrk.2
MLINKS+=dup.2 dup2.2
MLINKS+=chdir.2 fchdir.2
MLINKS+=chflags.2 fchflags.2
MLINKS+=chmod.2 fchmod.2
-MLINKS+=chown.2 fchown.2
+MLINKS+=chown.2 fchown.2 chown.2 lchown.2
+MLINKS+=clock_gettime.2 clock_settime.2 clock_gettime.2 clock_getres.2
MLINKS+=getgid.2 getegid.2
MLINKS+=getitimer.2 setitimer.2
MLINKS+=getlogin.2 setlogin.2
@@ -97,14 +139,18 @@ MLINKS+=intro.2 errno.2
MLINKS+=lseek.2 seek.2
MLINKS+=mlock.2 munlock.2
MLINKS+=mount.2 unmount.2
+MLINKS+=nanosleep.2 signanosleep.2
MLINKS+=pathconf.2 fpathconf.2
MLINKS+=read.2 readv.2
MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2
MLINKS+=send.2 sendmsg.2 send.2 sendto.2
+MLINKS+=setpgid.2 setpgrp.2
MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2
+MLINKS+=shmat.2 shmdt.2
MLINKS+=stat.2 fstat.2 stat.2 lstat.2
MLINKS+=statfs.2 fstatfs.2
MLINKS+=syscall.2 __syscall.2
MLINKS+=truncate.2 ftruncate.2
MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2
MLINKS+=write.2 writev.2
+.endif
diff --git a/lib/libc/sys/_exit.2 b/lib/libc/sys/_exit.2
index 73e6062..4f6a1c5 100644
--- a/lib/libc/sys/_exit.2
+++ b/lib/libc/sys/_exit.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)_exit.2 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt EXIT 2
@@ -53,7 +54,7 @@ This may entail delays, for example, waiting for output to drain;
a process in this state may not be killed, as it is already dying.
.It
If the parent process of the calling process has an outstanding
-.Xr wait
+.Xr wait 2
call
or catches the
.Dv SIGCHLD
@@ -107,6 +108,11 @@ can never return.
.Xr exit 3
.Sh STANDARDS
The
-.Nm _exit
-function is defined by
-.St -p1003.1-88 .
+.Fn _exit
+function call is expected to conform to
+.St -p1003.1-90 .
+.Sh HISTORY
+An
+.Fn _exit
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/accept.2 b/lib/libc/sys/accept.2
index d475e36..c5d162f 100644
--- a/lib/libc/sys/accept.2
+++ b/lib/libc/sys/accept.2
@@ -129,6 +129,31 @@ by issuing a
call with providing only the control information,
or by calling
.Xr setsockopt 2 .
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn accept
+is implemented as the
+.Va accept
+syscall.
+.Pp
+In the threaded library, the
+.Va accept
+syscall is assembled to
+.Fn _thread_sys_accept
+and
+.Fn accept
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_accept .
+If the call to
+.Fn _thread_sys_accept
+would block, a context switch is performed. Before returning,
+.Fn accept
+unlocks
+.Va s .
+.Pp
.Sh RETURN VALUES
The call returns \-1 on error. If it succeeds, it returns a non-negative
integer that is a descriptor for the accepted socket.
@@ -156,11 +181,12 @@ are present to be accepted.
.Sh SEE ALSO
.Xr bind 2 ,
.Xr connect 2 ,
+.Xr getpeername 2 ,
.Xr listen 2 ,
.Xr select 2 ,
.Xr socket 2
.Sh HISTORY
The
-.Nm
+.Fn accept
function appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/access.2 b/lib/libc/sys/access.2
index 0dc9d2e..cf1fe90 100644
--- a/lib/libc/sys/access.2
+++ b/lib/libc/sys/access.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)access.2 8.2 (Berkeley) 4/1/94
+.\" $Id$
.\"
.Dd April 1, 1994
.Dt ACCESS 2
@@ -88,8 +89,6 @@ Access to the file is denied if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -121,10 +120,16 @@ An I/O error occurred while reading from or writing to the file system.
.Xr chmod 2 ,
.Xr stat 2
.Sh STANDARDS
-.Fn Access
-conforms to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn access
+function call is expected to conform to
+.St -p1003.1-90 .
.Sh CAVEAT
.Fn Access
is a potential security hole and
should never be used.
+.Sh HISTORY
+An
+.Fn access
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/acct.2 b/lib/libc/sys/acct.2
index bcd45ca..879a06f 100644
--- a/lib/libc/sys/acct.2
+++ b/lib/libc/sys/acct.2
@@ -86,8 +86,6 @@ will fail if one of the following is true:
The caller is not the super-user.
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -111,5 +109,6 @@ An I/O error occurred while reading from or writing to the file system.
.Xr sa 8
.Sh HISTORY
An
-.Nm
-function call appeared in Version 7 AT&T UNIX.
+.Fn acct
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/adjtime.2 b/lib/libc/sys/adjtime.2
index 84b9ad8..04673ad 100644
--- a/lib/libc/sys/adjtime.2
+++ b/lib/libc/sys/adjtime.2
@@ -40,7 +40,7 @@
.Sh SYNOPSIS
.Fd #include <sys/time.h>
.Ft int
-.Fn adjtime "struct timeval *delta" "struct timeval *olddelta"
+.Fn adjtime "const struct timeval *delta" "struct timeval *olddelta"
.Sh DESCRIPTION
.Fn Adjtime
makes small adjustments to the system time, as returned by
@@ -98,7 +98,7 @@ The process's effective user ID is not that of the super-user.
.Xr date 1 ,
.Xr gettimeofday 2 ,
.Xr timed 8 ,
-.Xr timedc 8 ,
+.Xr timedc 8
.Rs
.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD"
.%A R. Gusella
@@ -106,6 +106,6 @@ The process's effective user ID is not that of the super-user.
.Re
.Sh HISTORY
The
-.Nm
+.Fn adjtime
function call appeared in
.Bx 4.3 .
diff --git a/lib/libc/sys/bind.2 b/lib/libc/sys/bind.2
index 18512e2..ce6ca0c 100644
--- a/lib/libc/sys/bind.2
+++ b/lib/libc/sys/bind.2
@@ -41,7 +41,7 @@
.Fd #include <sys/types.h>
.Fd #include <sys/socket.h>
.Ft int
-.Fn bind "int s" "struct sockaddr *name" "int namelen"
+.Fn bind "int s" "const struct sockaddr *name" "int namelen"
.Sh DESCRIPTION
.Fn Bind
assigns a name to an unnamed socket.
@@ -62,6 +62,28 @@ needed (using
.Pp
The rules used in name binding vary between communication domains.
Consult the manual entries in section 4 for detailed information.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn bind
+is implemented as the
+.Va bind
+syscall.
+.Pp
+In the threaded library, the
+.Va bind
+syscall is assembled to
+.Fn _thread_sys_bind
+and
+.Fn bind
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_bind .
+Before returning,
+.Fn bind
+unlocks
+.Va s .
.Sh RETURN VALUES
If the bind is successful, a 0 value is returned.
A return value of -1 indicates an error, which is
@@ -82,8 +104,6 @@ is not a socket.
The specified address is not available from the local machine.
.It Bq Er EADDRINUSE
The specified address is already in use.
-.It Bq Er EINVAL
-The socket is already bound to an address.
.It Bq Er EACCES
The requested address is protected, and the current user
has inadequate permission to access it.
@@ -116,11 +136,11 @@ An empty pathname was specified.
.El
.Sh SEE ALSO
.Xr connect 2 ,
+.Xr getsockname 2 ,
.Xr listen 2 ,
-.Xr socket 2 ,
-.Xr getsockname 2
+.Xr socket 2
.Sh HISTORY
The
-.Nm
+.Fn bind
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/brk.2 b/lib/libc/sys/brk.2
index e3c825e..313e47d 100644
--- a/lib/libc/sys/brk.2
+++ b/lib/libc/sys/brk.2
@@ -39,11 +39,11 @@
.Nm sbrk
.Nd change data segment size
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
-.Ft char
-.Fn *brk "const char *addr"
+.Fd #include <unistd.h>
.Ft char *
-.Fn *sbrk "int incr"
+.Fn brk "const char *addr"
+.Ft char *
+.Fn sbrk "int incr"
.Sh DESCRIPTION
.Bf -symbolic
The brk and sbrk functions are historical curiosities
@@ -94,7 +94,7 @@ it will not be possible to set the break
beyond the
.Em rlim_max
value returned from a call to
-.Xr getrlimit ,
+.Xr getrlimit 2 ,
e.g.
.Dq etext + rlp\(->rlim_max.
(see
@@ -102,20 +102,21 @@ e.g.
for the definition of
.Em etext ) .
.Sh RETURN VALUES
-.Nm Brk
+.Fn Brk
returns 0 if successful;
otherwise -1 with
.Va errno
set to indicate why the allocation failed.
-.Nm Sbrk
-returns a pointer to the base of the new storage if successful;
+The
+.Fn sbrk
+function returns a pointer to the base of the new storage if successful;
otherwise -1 with
.Va errno
set to indicate why the allocation failed.
.Sh ERRORS
-.Xr Brk
+.Fn Brk
or
-.Xr sbrk
+.Fn sbrk
will fail and no additional memory will be allocated if
one of the following are true:
.Bl -tag -width [ENOMEM]
@@ -133,15 +134,16 @@ to support the expansion.
.Sh SEE ALSO
.Xr execve 2 ,
.Xr getrlimit 2 ,
-.Xr malloc 3 ,
-.Xr end 3
+.Xr end 3 ,
+.Xr malloc 3
.Sh BUGS
Setting the break may fail due to a temporary lack of
swap space. It is not possible to distinguish this
from a failure caused by exceeding the maximum size of
the data segment without consulting
-.Xr getrlimit .
+.Xr getrlimit 2 .
.Sh HISTORY
A
-.Nm
-function call appeared in Version 7 AT&T UNIX.
+.Fn brk
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/chdir.2 b/lib/libc/sys/chdir.2
index 0b06fa8..215d759 100644
--- a/lib/libc/sys/chdir.2
+++ b/lib/libc/sys/chdir.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)chdir.2 8.2 (Berkeley) 12/11/93
+.\" $Id$
.\"
.Dd December 11, 1993
.Dt CHDIR 2
@@ -82,8 +83,6 @@ one or more of the following are true:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -118,10 +117,15 @@ is not a valid file descriptor.
.Sh SEE ALSO
.Xr chroot 2
.Sh STANDARDS
-.Fn Chdir
-is expected to conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn chdir
+function call is expected to conform to
+.St -p1003.1-90 .
.Sh HISTORY
+A
+.Fn chdir
+function call appeared in
+.At v7 .
The
.Fn fchdir
function call
diff --git a/lib/libc/sys/chflags.2 b/lib/libc/sys/chflags.2
index e10d98d..3305b3a 100644
--- a/lib/libc/sys/chflags.2
+++ b/lib/libc/sys/chflags.2
@@ -65,6 +65,8 @@ Do not dump the file.
The file may not be changed.
.It UF_APPEND
The file may only be appended to.
+.It UF_NOUNLINK
+The file may not be renamed or deleted.
.It UF_OPAQUE
The directory is opaque when viewed through a union stack.
.\".It ARCHIVED
@@ -73,18 +75,24 @@ The directory is opaque when viewed through a union stack.
The file may not be changed.
.It SF_APPEND
The file may only be appended to.
+.It SF_NOUNLINK
+The file may not be renamed or deleted.
.El
.Pp
The
.Dq UF_IMMUTABLE
-and
+,
.Dq UF_APPEND
+and
+.Dq UF_NOUNLINK
flags may be set or unset by either the owner of a file or the super-user.
.Pp
The
.Dq SF_IMMUTABLE
-and
+,
.Dq SF_APPEND
+and
+.Dq SF_NOUNLINK
flags may only be set or unset by the super-user.
Attempts by the non-super-user to set the super-user only flags
are silently ignored.
@@ -100,12 +108,10 @@ Otherwise, -1 is returned and the global variable
is set to indicate the error.
.Sh ERRORS
.Fn Chflags
-will fail it:
+will fail if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -156,4 +162,5 @@ The
.Nm chflags
and
.Nm fchflags
-functions first appeared in 4.4BSD.
+functions first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/chmod.2 b/lib/libc/sys/chmod.2
index 1075158..a2daf6f 100644
--- a/lib/libc/sys/chmod.2
+++ b/lib/libc/sys/chmod.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)chmod.2 8.1 (Berkeley) 6/4/93
+.\" $Id: chmod.2,v 1.8 1997/02/22 15:03:43 peter Exp $
.\"
.Dd June 4, 1993
.Dt CHMOD 2
@@ -88,17 +89,14 @@ defined in
#define S_ISUID 0004000 /* set user id on execution */
#define S_ISGID 0002000 /* set group id on execution */
-#define S_ISVTX 0001000 /* save swapped text even after use */
+#define S_ISVTX 0001000 /* sticky bit */
.Ed
.Pp
The
-.Dv ISVTX
-(the
-.Em sticky bit )
-indicates to the system which executable files are shareable (the
-default) and the system maintains the program text of the files
-in the swap area. The sticky bit may only be set by the super user
-on shareable executable files.
+.Tn FreeBSD
+VM system totally ignores the sticky bit
+.Pf ( Dv ISVTX
+) for executables.
.Pp
If mode
.Dv ISVTX
@@ -128,8 +126,6 @@ will fail and the file mode will be unchanged if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -166,15 +162,20 @@ An I/O error occurred while reading from or writing to the file system.
.El
.Sh SEE ALSO
.Xr chmod 1 ,
-.Xr open 2 ,
.Xr chown 2 ,
+.Xr open 2 ,
.Xr stat 2 ,
.Xr sticky 8
.Sh STANDARDS
-.Fn Chmod
-is expected to conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn chmod
+function call is expected to conform to
+.St -p1003.1-90 .
.Sh HISTORY
+A
+.Fn chmod
+function call appeared in
+.At v7 .
The
.Fn fchmod
function call
diff --git a/lib/libc/sys/chown.2 b/lib/libc/sys/chown.2
index 8b851e2..af1875c 100644
--- a/lib/libc/sys/chown.2
+++ b/lib/libc/sys/chown.2
@@ -30,20 +30,24 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)chown.2 8.4 (Berkeley) 4/19/94
+.\" $Id: chown.2,v 1.10 1997/03/31 12:37:35 peter Exp $
.\"
.Dd April 19, 1994
.Dt CHOWN 2
.Os BSD 4
.Sh NAME
.Nm chown ,
-.Nm fchown
+.Nm fchown ,
+.Nm lchown
.Nd change owner and group of a file
.Sh SYNOPSIS
.Fd #include <unistd.h>
.Ft int
.Fn chown "const char *path" "uid_t owner" "gid_t group"
.Ft int
-.Fn fchown "int fd" "uid_t owner" "uid_t group"
+.Fn fchown "int fd" "uid_t owner" "gid_t group"
+.Ft int
+.Fn lchown "const char *path" "uid_t owner" "gid_t group"
.Sh DESCRIPTION
The owner ID and group ID of the file
named by
@@ -66,13 +70,22 @@ capability is restricted to the super-user.
clears the set-user-id and set-group-id bits
on the file
to prevent accidental or mischievous creation of
-set-user-id and set-group-id programs.
+set-user-id and set-group-id programs if not executed
+by the super-user.
+.Fn chown
+follows symbolic links to operate on the target of the link
+rather than the link itself.
.Pp
.Fn Fchown
is particularly useful when used in conjunction
with the file locking primitives (see
.Xr flock 2 ) .
.Pp
+.Fn Lchown
+is similar to
+.Fn chown
+but does not follow symbolic links.
+.Pp
One of the owner or group id's
may be left unchanged by specifying it as -1.
.Sh RETURN VALUES
@@ -82,12 +95,12 @@ error code being placed in the global variable
.Va errno .
.Sh ERRORS
.Fn Chown
+and
+.Fn lchown
will fail and the file will be unchanged if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -125,15 +138,20 @@ The named file resides on a read-only file system.
An I/O error occurred while reading from or writing to the file system.
.El
.Sh SEE ALSO
-.Xr chown 8 ,
.Xr chgrp 1 ,
.Xr chmod 2 ,
-.Xr flock 2
+.Xr flock 2 ,
+.Xr chown 8
.Sh STANDARDS
-.Fn Chown
-is expected to conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn chown
+function call is expected to conform to
+.St -p1003.1-90 .
.Sh HISTORY
+A
+.Fn chown
+function call appeared in
+.At v7 .
The
.Fn fchown
function call
@@ -142,7 +160,10 @@ appeared in
.Pp
The
.Fn chown
-and
-.Fn fchown
-functions were changed to follow symbolic links in
+function was changed to follow symbolic links in
.Bx 4.4 .
+The
+.Fn lchown
+function was added in
+.Fx 3.0
+to compensate for the loss of functionality.
diff --git a/lib/libc/sys/chroot.2 b/lib/libc/sys/chroot.2
index d8763fe..10a9b5e 100644
--- a/lib/libc/sys/chroot.2
+++ b/lib/libc/sys/chroot.2
@@ -71,8 +71,8 @@ will fail and the root directory will be unchanged if:
.Bl -tag -width [ENOTDIR]
.It Bq Er ENOTDIR
A component of the path name is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
+.It Bq Er EPERM
+The effective user ID is not the super-user.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -92,6 +92,6 @@ An I/O error occurred while reading from or writing to the file system.
.Xr chdir 2
.Sh HISTORY
The
-.Nm
+.Fn chroot
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/clock_gettime.2 b/lib/libc/sys/clock_gettime.2
new file mode 100644
index 0000000..6894c14
--- /dev/null
+++ b/lib/libc/sys/clock_gettime.2
@@ -0,0 +1,124 @@
+.\" $OpenBSD: clock_gettime.2,v 1.4 1997/05/08 20:21:16 kstailey Exp $
+.\" $Id$
+.\"
+.\" Copyright (c) 1980, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.Dd May 8, 1997
+.Dt CLOCK_GETTIME 2
+.Os BSD 4
+.Sh NAME
+.Nm clock_gettime ,
+.Nm clock_settime ,
+.Nm clock_getres
+.Nd get/set/calibrate date and time
+.Sh SYNOPSIS
+.Fd #include <sys/time.h>
+.Ft int
+.Fn clock_gettime "clockid_t clock_id" "struct timespec *tp"
+.Ft int
+.Fn clock_settime "clockid_t clock_id" "const struct timespec *tp"
+.Ft int
+.Fn clock_getres "clockid_t clock_id" "const struct timespec *tp"
+.Sh DESCRIPTION
+The
+.Fn clock_gettime
+and
+.Fn clock_settime
+allow the calling process to retrieve or set the value used by a clock
+which is specifed by
+.Fa clock_id .
+.Pp
+.Fa clock_id
+can be one of three values: CLOCK_REALTIME for time that increments as
+a wall clock should, CLOCK_VIRTUAL for time that increments only when
+the CPU is running in user mode on behalf of the calling process, or
+CLOCK_PROF for time that increments when the CPU is running in user or
+kernel mode.
+.Pp
+The structure pointed to by
+.Fa tp
+is defined in
+.Ao Pa sys/time.h Ac
+as:
+.Pp
+.Bd -literal
+struct timespec {
+ time_t tv_sec; /* seconds */
+ long tv_nsec; /* and nanoseconds */
+};
+.Ed
+.Pp
+Only the super-user may set the time of day.
+If the system securelevel is greater than 1 (see
+.Xr init 8 ),
+the time may only be advanced.
+This limitation is imposed to prevent a malicious super-user
+from setting arbitrary time stamps on files.
+The system time can still be adjusted backwards using the
+.Xr adjtime 2
+system call even when the system is secure.
+.Pp
+The resolution (granularity) of a clock is returned by the
+.Fn clock_getres
+call. This value is placed in a (non-NULL)
+.Fa *tp .
+.Sh RETURN
+A 0 return value indicates that the call succeeded.
+A -1 return value indicates an error occurred, and in this
+case an error code is stored into the global variable
+.Va errno .
+.Sh ERRORS
+The following error codes may be set in
+.Va errno :
+.Bl -tag -width [EFAULT]
+.It Bq Er EINVAL
+The
+.Fa clock_id
+was not a valid value.
+.It Bq Er EFAULT
+The
+.Fa *tp
+argument address referenced invalid memory.
+.It Bq Er EPERM
+A user other than the super-user attempted to set the time.
+.El
+.Sh SEE ALSO
+.Xr date 1 ,
+.Xr adjtime 2 ,
+.Xr ctime 3 ,
+.Xr timed 8
+.Sh STANDARDS
+The
+.Fn clock_gettime ,
+etc.
+functions conform to
+.St -p1003.1b-93 .
diff --git a/lib/libc/sys/close.2 b/lib/libc/sys/close.2
index 885ac80..1a66e39 100644
--- a/lib/libc/sys/close.2
+++ b/lib/libc/sys/close.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)close.2 8.2 (Berkeley) 4/19/94
+.\" $Id$
.\"
.Dd April 19, 1994
.Dt CLOSE 2
@@ -78,7 +79,7 @@ of the descriptors can be rearranged with
or deleted with
.Fn close
before the
-.Xr execve
+.Xr execve 2
is attempted, but if some of these descriptors will still
be needed if the execve fails, it is necessary to arrange for them
to be closed if the execve succeeds.
@@ -90,6 +91,28 @@ execve; the call
.Dq Li fcntl(d, F_SETFD, 0)
restores the default,
which is to not close the descriptor.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn close
+is implemented as the
+.Va close
+syscall.
+.Pp
+In the threaded library, the
+.Va close
+syscall is assembled to
+.Fn _thread_sys_close
+and
+.Fn close
+is implemented as a function which locks
+.Va d
+for read and write, then calls
+.Fn _thread_sys_close .
+Before returning,
+.Fn close
+unlocks
+.Va d .
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of -1 is returned and the global integer variable
@@ -107,14 +130,20 @@ An interrupt was received.
.El
.Sh SEE ALSO
.Xr accept 2 ,
+.Xr execve 2 ,
+.Xr fcntl 2 ,
.Xr flock 2 ,
.Xr open 2 ,
.Xr pipe 2 ,
.Xr socket 2 ,
-.Xr socketpair 2 ,
-.Xr execve 2 ,
-.Xr fcntl 2
+.Xr socketpair 2
.Sh STANDARDS
-.Fn Close
-conforms to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn close
+function call is expected to conform to
+.St -p1003.1-90 .
+.Sh HISTORY
+A
+.Fn close
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/connect.2 b/lib/libc/sys/connect.2
index eb38ab3..f328d86 100644
--- a/lib/libc/sys/connect.2
+++ b/lib/libc/sys/connect.2
@@ -41,7 +41,7 @@
.Fd #include <sys/types.h>
.Fd #include <sys/socket.h>
.Ft int
-.Fn connect "int s" "struct sockaddr *name" "int namelen"
+.Fn connect "int s" "const struct sockaddr *name" "int namelen"
.Sh DESCRIPTION
The parameter
.Fa s
@@ -68,6 +68,30 @@ only once; datagram sockets may use
multiple times to change their association.
Datagram sockets may dissolve the association
by connecting to an invalid address, such as a null address.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn connect
+is implemented as the
+.Va connect
+syscall.
+.Pp
+In the threaded library, the
+.Va connect
+syscall is assembled to
+.Fn _thread_sys_connect
+and
+.Fn connect
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_connect .
+If the call to
+.Fn _thread_sys_connect
+would block, a context switch is performed. Before returning,
+.Fn connect
+unlocks
+.Va s .
.Sh RETURN VALUES
If the connection or binding succeeds, 0 is returned.
Otherwise a -1 is returned, and a more specific error
@@ -79,10 +103,10 @@ The
call fails if:
.Bl -tag -width EADDRNOTAVAILABB
.It Bq Er EBADF
-.Fa S
+.Fa s
is not a valid descriptor.
.It Bq Er ENOTSOCK
-.Fa S
+.Fa s
is a descriptor for a file, not a socket.
.It Bq Er EADDRNOTAVAIL
The specified address is not available on this machine.
@@ -121,8 +145,6 @@ These errors may not apply in future versions of the UNIX IPC domain.
.Bl -tag -width EADDRNOTAVAILABB
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -137,11 +159,12 @@ Too many symbolic links were encountered in translating the pathname.
.El
.Sh SEE ALSO
.Xr accept 2 ,
+.Xr getpeername 2 ,
+.Xr getsockname 2 ,
.Xr select 2 ,
-.Xr socket 2 ,
-.Xr getsockname 2
+.Xr socket 2
.Sh HISTORY
The
-.Nm
+.Fn connect
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/dup.2 b/lib/libc/sys/dup.2
index 8989639..58a967d 100644
--- a/lib/libc/sys/dup.2
+++ b/lib/libc/sys/dup.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)dup.2 8.1 (Berkeley) 6/4/93
+.\" $Id: dup.2,v 1.7 1997/02/22 15:03:49 peter Exp $
.\"
.Dd June 4, 1993
.Dt DUP 2
@@ -91,10 +92,74 @@ In
.Fn dup2 ,
the value of the new descriptor
.Fa newd
-is specified. If this descriptor is already
-in use, the descriptor is first deallocated as if a
+is specified. If this descriptor is already in use and
+.Fa oldd
+!=
+.Fa newd ,
+the descriptor is first deallocated as if a
.Xr close 2
-call had been done first.
+call had been used.
+If
+.Fa oldd
+is not a valid descriptor, then
+.Fa newd
+is not closed.
+If
+.Fa oldd
+==
+.Fa newd
+and
+.Fa oldd
+is a valid descriptor, then
+.Fn dup2
+is successful, and does nothing.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn dup
+is implemented as the
+.Va dup
+syscall.
+.Pp
+In the threaded library, the
+.Va dup
+syscall is assembled to
+.Fn _thread_sys_dup
+and
+.Fn dup
+is implemented as a function which locks
+.Va oldd
+for read and write, then calls
+.Fn _thread_sys_dup .
+Before returning,
+.Fn dup
+unlocks
+.Va oldd .
+.Pp
+In the non-threaded library
+.Fn dup2
+is implemented as the
+.Va dup2
+syscall.
+.Pp
+In the threaded library, the
+.Va dup2
+syscall is assembled to
+.Fn _thread_sys_dup2
+and
+.Fn dup2
+is implemented as a function which locks both
+.Va oldd
+and
+.Va newd
+for read and write, then calls
+.Fn _thread_sys_dup2 .
+Before returning,
+.Fn dup2
+unlocks
+.Va oldd .
+and
+.Va newd .
.Sh RETURN VALUES
The value -1 is returned if an error occurs in either call.
The external variable
@@ -116,17 +181,24 @@ Too many descriptors are active.
.El
.Sh SEE ALSO
.Xr accept 2 ,
-.Xr open 2 ,
.Xr close 2 ,
.Xr fcntl 2 ,
+.Xr getdtablesize 2 ,
+.Xr open 2 ,
.Xr pipe 2 ,
.Xr socket 2 ,
-.Xr socketpair 2 ,
-.Xr getdtablesize 2
+.Xr socketpair 2
.Sh STANDARDS
-.Fn Dup
+The
+.Fn dup
and
.Fn dup2
-are expected to conform
-to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+function calls are expected to conform to
+.St -p1003.1-90 .
+.Sh HISTORY
+A
+.Fn dup
+and a
+.Fn dup2
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/execve.2 b/lib/libc/sys/execve.2
index ca44793..a4af9bf 100644
--- a/lib/libc/sys/execve.2
+++ b/lib/libc/sys/execve.2
@@ -66,11 +66,9 @@ An interpreter file begins with a line of the form:
.Ed
.Pp
When an interpreter file is
-.\" was .Fn execve Ap d ,
-\fBexecve\fP'd,
+.Sy execve Ap d ,
the system
-.\" was .Fn execve Ap s
-\fBexecve\fP's
+.Sy execve Ap s
runs the specified
.Em interpreter .
If the optional
@@ -78,16 +76,13 @@ If the optional
is specified, it becomes the first argument to the
.Em interpreter ,
and the name of the originally
-.\" was .Fn execve Ap d
-\fBexecve\fP'd
+.Sy execve Ap d
file becomes the second argument;
otherwise, the name of the originally
-.\" was .Fn execve Ap d
-\fBexecve\fP'd
+.Sy execve Ap d
file becomes the first argument. The original arguments are shifted over to
become the subsequent arguments. The zeroth argument, normally the name of the
-.\" was .Fn execve Ap d
-\fBexecve\fP'd
+.Sy execve Ap d
file, is left unchanged.
.Pp
The argument
@@ -184,6 +179,23 @@ and
.Fa argv
points to the array of character pointers
to the arguments themselves.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn execve
+is implemented as the
+.Va execve
+syscall.
+.Pp
+In the threaded library, the
+.Va execve
+syscall is assembled to
+.Fn _thread_sys_execve
+and
+.Fn execve
+is implemented as a function which performs user-thread
+library re-initialization and then calls
+.Fn _thread_sys_execve .
.Sh RETURN VALUES
As the
.Fn execve
@@ -202,8 +214,6 @@ will fail and return to the calling process if:
.Bl -tag -width [ENAMETOOLONG]
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -231,10 +241,10 @@ is allowed by the imposed maximum
.It Bq Er E2BIG
The number of bytes in the new process's argument list
is larger than the system-imposed limit.
-The limit in the system as released is 20480 bytes
+The limit in the system as released is 65536 bytes
.Pf ( Dv NCARGS
in
-.Ao Pa sys/param.h Ac .
+.Ao Pa sys/param.h Ac ) .
.It Bq Er EFAULT
The new process file is not as long as indicated by
the size values in its header.
@@ -257,12 +267,13 @@ the real
is ``root'', then the program has some of the powers
of a super-user as well.
.Sh SEE ALSO
-.Xr exit 2 ,
+.Xr _exit 2 ,
.Xr fork 2 ,
.Xr execl 3 ,
+.Xr exit 3 ,
.Xr environ 7
.Sh HISTORY
The
-.Nm
+.Fn execve
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/fcntl.2 b/lib/libc/sys/fcntl.2
index f53c02f..877e830 100644
--- a/lib/libc/sys/fcntl.2
+++ b/lib/libc/sys/fcntl.2
@@ -70,7 +70,7 @@ share the same file status flags).
.It
The close-on-exec flag associated with the new file descriptor
is set to remain open across
-.Xr execv 2
+.Xr execve 2
system calls.
.El
.It Dv F_GETFD
@@ -128,9 +128,9 @@ flags are as follows:
.Bl -tag -width O_NONBLOCKX
.It Dv O_NONBLOCK
Non-blocking I/O; if no data is available to a
-.Xr read
+.Xr read 2
call, or if a
-.Xr write
+.Xr write 2
operation would block,
the read or write call returns -1 with the error
.Er EAGAIN .
@@ -170,7 +170,7 @@ taken as a pointer to a
.Fa "struct flock"
(see above).
The information retrieved overwrites the information passed to
-.Nm fcntl
+.Fn fcntl
in the
.Fa flock
structure.
@@ -193,18 +193,18 @@ or exclusive (or write) locks,
as well as remove either type of lock
.Dv (F_UNLCK) .
If a shared or exclusive lock cannot be set,
-.Nm fcntl
+.Fn fcntl
returns immediately with
-.Er EACCES .
+.Er EAGAIN .
.It Dv F_SETLKW
This command is the same as
.Dv F_SETLK
except that if a shared or exclusive lock is blocked by other locks,
the process waits until the request can be satisfied.
If a signal that is to be caught is received while
-.Nm fcntl
+.Fn fcntl
is waiting for a region, the
-.Nm fcntl
+.Fn fcntl
will be interrupted if the signal handler has not specified the
.Dv SA_RESTART
(see
@@ -290,15 +290,17 @@ locks conflicts with the type specified in the request.
This interface follows the completely stupid semantics of System V and
.St -p1003.1-88
that require that all locks associated with a file for a given process are
-removed when \fIany\fP file descriptor for that file is closed by that process.
+removed when
+.Em any
+file descriptor for that file is closed by that process.
This semantic means that applications must be aware of any files that
a subroutine library may access.
For example if an application for updating the password file locks the
password file database while making the update, and then calls
-.Xr getpwname 3
+.Xr getpwnam 3
to retrieve a record,
the lock will be lost because
-.Xr getpwname 3
+.Xr getpwnam 3
opens, reads, and closes the password database.
The database close will release all locks that the process has
associated with the database, even if the library routine never
@@ -330,6 +332,29 @@ This implementation detects that sleeping until a locked region is unlocked
would cause a deadlock and fails with an
.Er EDEADLK
error.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn fcntl
+is implemented as the
+.Va fcntl
+syscall.
+.Pp
+In the threaded library, the
+.Va fcntl
+syscall is assembled to
+.Fn _thread_sys_fcntl
+and
+.Fn fcntl
+is implemented as a function which disables thread rescheduling, locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_fcntl .
+Before returning,
+.Fn fcntl
+unlocks
+.Va fd
+and enables thread rescheduling.
.Sh RETURN VALUES
Upon successful completion, the value returned depends on
.Fa cmd
@@ -354,9 +379,9 @@ is set to indicate the error.
.Fn Fcntl
will fail if:
.Bl -tag -width Er
-.It Bq Er EACCES
+.It Bq Er EAGAIN
The argument
-.Fa arg
+.Fa cmd
is
.Dv F_SETLK ,
the type of lock
@@ -401,12 +426,6 @@ is an exclusive lock
and
.Fa fildes
is not a valid file descriptor open for writing.
-.It Bq Er EMFILE
-.Fa Cmd
-is
-.Dv F_DUPFD
-and the maximum allowed number of file descriptors are currently
-open.
.It Bq Er EDEADLK
The argument
.Fa cmd
@@ -445,7 +464,7 @@ refers to a file that does not support locking.
The argument
.Fa cmd
is
-.Dv F_DUPED
+.Dv F_DUPFD
and the maximum number of file descriptors permitted for the
process are already in use,
or no file descriptors greater than or equal to
@@ -467,15 +486,33 @@ is
and
the process ID given as argument is not in use.
.El
+.Pp
+In addition, if
+.Fa fd
+refers to a descriptor open on a terminal device (as opposed to a
+descriptor open on a socket), a
+.Fa cmd
+of
+.Dv F_SETOWN
+can fail for the same reasons as in
+.Xr tcsetpgrp 3 ,
+and a
+.Fa cmd
+of
+.Dv F_GETOWN
+for the reasons as stated in
+.Xr tcgetpgrp 3 .
.Sh SEE ALSO
.Xr close 2 ,
.Xr execve 2 ,
.Xr flock 2 ,
.Xr getdtablesize 2 ,
.Xr open 2 ,
-.Xr sigvec 2
+.Xr sigvec 2 ,
+.Xr tcgetpgrp 3 ,
+.Xr tcsetpgrp 3
.Sh HISTORY
The
-.Nm
+.Fn fcntl
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/flock.2 b/lib/libc/sys/flock.2
index bb6abb7..466e347 100644
--- a/lib/libc/sys/flock.2
+++ b/lib/libc/sys/flock.2
@@ -39,10 +39,10 @@
.Nd "apply or remove an advisory lock on an open file"
.Sh SYNOPSIS
.Fd #include <sys/file.h>
-.Fd #define LOCK_SH 1 /* shared lock */
-.Fd #define LOCK_EX 2 /* exclusive lock */
-.Fd #define LOCK_NB 4 /* don't block when locking */
-.Fd #define LOCK_UN 8 /* unlock */
+.Fd #define LOCK_SH 0x01 /* shared file lock */
+.Fd #define LOCK_EX 0x02 /* exclusive file lock */
+.Fd #define LOCK_NB 0x04 /* don't block when locking */
+.Fd #define LOCK_UN 0x08 /* unlock file */
.Ft int
.Fn flock "int fd" "int operation"
.Sh DESCRIPTION
@@ -109,6 +109,28 @@ forks and the child explicitly unlocks the file, the parent will
lose its lock.
.Pp
Processes blocked awaiting a lock may be awakened by signals.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn flock
+is implemented as the
+.Va flock
+syscall.
+.Pp
+In the threaded library, the
+.Va flock
+syscall is assembled to
+.Fn _thread_sys_flock
+and
+.Fn flock
+is implemented as a function which locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_flock .
+Before returning,
+.Fn flock
+unlocks
+.Va fd .
.Sh RETURN VALUES
Zero is returned if the operation was successful;
on an error a -1 is returned and an error code is left in
@@ -131,15 +153,19 @@ is an invalid descriptor.
The argument
.Fa fd
refers to an object other than a file.
+.It Bq Er EOPNOTSUPP
+The argument
+.Fa fd
+refers to an object that does not support file locking.
.El
.Sh SEE ALSO
-.Xr open 2 ,
.Xr close 2 ,
.Xr dup 2 ,
.Xr execve 2 ,
-.Xr fork 2
+.Xr fork 2 ,
+.Xr open 2
.Sh HISTORY
The
-.Nm
+.Fn flock
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/fork.2 b/lib/libc/sys/fork.2
index 0c290f6..a0bb0f6 100644
--- a/lib/libc/sys/fork.2
+++ b/lib/libc/sys/fork.2
@@ -59,9 +59,9 @@ for instance, file pointers in file objects are shared between
the child and the parent, so that an
.Xr lseek 2
on a descriptor in the child process can affect a subsequent
-.Xr read
+.Xr read 2
or
-.Xr write
+.Xr write 2
by the parent.
This descriptor copying is also used by the shell to
establish standard input and output for newly created processes
@@ -88,18 +88,33 @@ will fail and no child process will be created if:
.It Bq Er EAGAIN
The system-imposed limit on the total
number of processes under execution would be exceeded.
-This limit is configuration-dependent.
+The limit is given by the
+.Xr sysctl 3
+MIB variable
+.Dv KERN_MAXPROC .
+(The limit is actually one less than this
+except for the super user).
.It Bq Er EAGAIN
-The system-imposed limit
-.Dv MAXUPRC
-.Pq Aq Pa sys/param.h
+The user is not the super user, and
+the system-imposed limit
on the total number of
processes under execution by a single user would be exceeded.
+The limit is given by the
+.Xr sysctl 3
+MIB variable
+.Dv KERN_MAXPROCPERUID .
+.It Bq Er EAGAIN
+The user is not the super user, and
+the soft resource limit corresponding to the resource parameter
+.Dv RLIMIT_NOFILE
+would be exceeded (see
+.Xr getrlimit 2 ) .
.It Bq Er ENOMEM
There is insufficient swap space for the new process.
.El
.Sh SEE ALSO
.Xr execve 2 ,
+.Xr vfork 2 ,
.Xr wait 2
.Sh HISTORY
A
diff --git a/lib/libc/sys/fsync.2 b/lib/libc/sys/fsync.2
index 234ea6e..74105ec 100644
--- a/lib/libc/sys/fsync.2
+++ b/lib/libc/sys/fsync.2
@@ -53,6 +53,28 @@ of buffers for the associated file to be written to a disk.
should be used by programs that require a file to be
in a known state, for example, in building a simple transaction
facility.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn fsync
+is implemented as the
+.Va fsync
+syscall.
+.Pp
+In the threaded library, the
+.Va fsync
+syscall is assembled to
+.Fn _thread_sys_fsync
+and
+.Fn fsync
+is implemented as a function which locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_fsync .
+Before returning,
+.Fn fsync
+unlocks
+.Va fd .
.Sh RETURN VALUES
A 0 value is returned on success. A -1 value indicates
an error.
@@ -72,10 +94,10 @@ An I/O error occurred while reading from or writing to the file system.
.El
.Sh SEE ALSO
.Xr sync 2 ,
-.Xr sync 8 ,
-.Xr update 8
+.Xr update 4 ,
+.Xr sync 8
.Sh HISTORY
The
-.Nm
+.Fn fsync
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c
index 2f3ae6d..72a6a91 100644
--- a/lib/libc/sys/ftruncate.c
+++ b/lib/libc/sys/ftruncate.c
@@ -37,6 +37,11 @@ static char sccsid[] = "@(#)ftruncate.c 8.1 (Berkeley) 6/17/93";
#include <sys/types.h>
#include <sys/syscall.h>
+#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* This function provides 64-bit offset padding that
@@ -48,5 +53,16 @@ ftruncate(fd, length)
off_t length;
{
+#ifdef _THREAD_SAFE
+ int retval;
+ if (_thread_fd_lock(fd, FD_RDWR, NULL,__FILE__,__LINE__) != 0) {
+ retval = -1;
+ } else {
+ retval = __syscall((quad_t)SYS_ftruncate, fd, 0, length);
+ _thread_fd_unlock(fd, FD_RDWR);
+ }
+ return(retval);
+#else
return(__syscall((quad_t)SYS_ftruncate, fd, 0, length));
+#endif
}
diff --git a/lib/libc/sys/getdirentries.2 b/lib/libc/sys/getdirentries.2
index 532bec1..be85934 100644
--- a/lib/libc/sys/getdirentries.2
+++ b/lib/libc/sys/getdirentries.2
@@ -38,7 +38,8 @@
.Nm getdirentries
.Nd "get directory entries in a filesystem independent format"
.Sh SYNOPSIS
-.Fd #include <sys/dirent.h>
+.Fd #include <sys/types.h>
+.Fd #include <dirent.h>
.Ft int
.Fn getdirentries "int fd" "char *buf" "int nbytes" "long *basep"
.Sh DESCRIPTION
@@ -65,11 +66,11 @@ The data in the buffer is a series of
.Em dirent
structures each containing the following entries:
.Bd -literal -offset indent
-unsigned long d_fileno;
-unsigned short d_reclen;
-unsigned char d_type;
-unsigned char d_namlen;
-char d_name[MAXNAMELEN + 1]; /* see below */
+u_int32_t d_fileno;
+u_int16_t d_reclen;
+u_int8_t d_type;
+u_int8_t d_namelen;
+char d_name[MAXNAMELEN + 1]; /* see below */
.Ed
.Pp
The
@@ -126,6 +127,28 @@ The current position pointer should only be set to a value returned by
a value returned in the location pointed to by
.Fa basep ,
or zero.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn getdirentries
+is implemented as the
+.Va getdirentries
+syscall.
+.Pp
+In the threaded library, the
+.Va getdirentries
+syscall is assembled to
+.Fn _thread_sys_getdirentries
+and
+.Fn getdirentries
+is implemented as a function which locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_getdirentries .
+Before returning,
+.Fn getdirentries
+unlocks
+.Va fd .
.Sh RETURN VALUES
If successful, the number of bytes actually transferred is returned.
Otherwise, -1 is returned and the global variable
@@ -135,24 +158,25 @@ is set to indicate the error.
.Fn Getdirentries
will fail if:
.Bl -tag -width [EFAULT]
-.It EBADF
+.It Bq Er EBADF
.Fa fd
is not a valid file descriptor open for reading.
-.It EFAULT
+.It Bq Er EFAULT
Either
.Fa buf
or
.Fa basep
point outside the allocated address space.
-.It EIO
+.It Bq Er EIO
An
.Tn I/O
error occurred while reading from or writing to the file system.
.El
.Sh SEE ALSO
-.Xr open 2 ,
-.Xr lseek 2
+.Xr lseek 2 ,
+.Xr open 2
.Sh HISTORY
The
-.Nm getdirentries
-function first appeared in 4.4BSD.
+.Fn getdirentries
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/getfh.2 b/lib/libc/sys/getfh.2
index ab73d5a..44ac7e7 100644
--- a/lib/libc/sys/getfh.2
+++ b/lib/libc/sys/getfh.2
@@ -38,10 +38,10 @@
.Nm getfh
.Nd get file handle
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
+.Fd #include <sys/param.h>
.Fd #include <sys/mount.h>
.Ft int
-.Fn getfh "char *path" "fhandle_t *fhp"
+.Fn getfh "const char *path" "fhandle_t *fhp"
.Sh DESCRIPTION
.Fn Getfh
returns a file handle for the specified file or directory
@@ -61,9 +61,6 @@ fails if one or more of the following are true:
A component of the path prefix of
.Fa path
is not a directory.
-.It Bq EINVAL
-.Fa path
-contains a character with the high-order bit set.
.It Bq ENAMETOOLONG
The length of a component of
.Fa path
@@ -91,6 +88,7 @@ error occurred while reading from or writing to the file system.
.El
.Sh HISTORY
The
-.Nm getfh
+.Fn getfh
function
-first appeared in 4.4BSD.
+first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/getfsstat.2 b/lib/libc/sys/getfsstat.2
index b25261c..011a815 100644
--- a/lib/libc/sys/getfsstat.2
+++ b/lib/libc/sys/getfsstat.2
@@ -51,27 +51,32 @@ is a pointer to
.Xr statfs
structures defined as follows:
.Bd -literal
-typedef quad fsid_t;
+typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */
-#define MFSNAMELEN 16 /* length of fs type name, including null */
-#define MNAMELEN 90 /* length of buffer for returned name */
+/*
+ * file system statistics
+ */
+
+#define MFSNAMELEN 16 /* length of fs type name, including null */
+#define MNAMELEN 90 /* length of buffer for returned name */
struct statfs {
- short f_type; /* filesystem type number */
- short f_flags; /* copy of mount flags */
- long f_bsize; /* fundamental file system block size */
- long f_iosize; /* optimal transfer block size */
- long f_blocks; /* total data blocks in file system */
- long f_bfree; /* free blocks in fs */
- long f_bavail; /* free blocks avail to non-superuser */
- long f_files; /* total file nodes in file system */
- long f_ffree; /* free file nodes in fs */
- fsid_t f_fsid; /* file system id */
- uid_t f_owner; /* user that mounted the filesystem */
- long f_spare[4]; /* spare for later */
- char f_fstypename[MFSNAMELEN]; /* fs type name */
- char f_mntonname[MNAMELEN]; /* directory on which mounted */
- char f_mntfromname[MNAMELEN];/* mounted filesystem */
+ long f_spare2; /* placeholder */
+ long f_bsize; /* fundamental file system block size */
+ long f_iosize; /* optimal transfer block size */
+ long f_blocks; /* total data blocks in file system */
+ long f_bfree; /* free blocks in fs */
+ long f_bavail; /* free blocks avail to non-superuser */
+ long f_files; /* total file nodes in file system */
+ long f_ffree; /* free file nodes in fs */
+ fsid_t f_fsid; /* file system id */
+ uid_t f_owner; /* user that mounted the filesystem */
+ int f_type; /* type of filesystem (see below) */
+ int f_flags; /* copy of mount flags */
+ long f_spare[2]; /* spare for later */
+ char f_fstypename[MFSNAMELEN];/* fs type name */
+ char f_mntonname[MNAMELEN];/* directory on which mounted */
+ char f_mntfromname[MNAMELEN];/* mounted filesystem */
};
.Ed
.Pp
@@ -161,5 +166,6 @@ error occurred while reading from or writing to the filesystem.
.Xr mount 8
.Sh HISTORY
The
-.Nm getfsstat
-function first appeared in 4.4BSD.
+.Fn getfsstat
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/getgid.2 b/lib/libc/sys/getgid.2
index 52519d7..bf58d18 100644
--- a/lib/libc/sys/getgid.2
+++ b/lib/libc/sys/getgid.2
@@ -40,6 +40,7 @@
.Nd get group process identification
.Sh SYNOPSIS
.Fd #include <sys/types.h>
+.Fd #include <unistd.h>
.Ft gid_t
.Fn getgid void
.Ft gid_t
@@ -69,11 +70,13 @@ functions are always successful, and no return value is reserved to
indicate an error.
.Sh SEE ALSO
.Xr getuid 2 ,
-.Xr setregid 2 ,
-.Xr setgid 3
+.Xr issetugid 2 ,
+.Xr setgid 2 ,
+.Xr setregid 2
.Sh STANDARDS
-.Fn Getgid
+The
+.Fn getgid
and
.Fn getegid
-conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+function calls are expected to conform to
+.St -p1003.1-90 .
diff --git a/lib/libc/sys/getgroups.2 b/lib/libc/sys/getgroups.2
index 1428d83..ea73890 100644
--- a/lib/libc/sys/getgroups.2
+++ b/lib/libc/sys/getgroups.2
@@ -85,6 +85,6 @@ an invalid address.
.Xr initgroups 3
.Sh HISTORY
The
-.Nm
+.Fn getgroups
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/getitimer.2 b/lib/libc/sys/getitimer.2
index f39501d..c210248 100644
--- a/lib/libc/sys/getitimer.2
+++ b/lib/libc/sys/getitimer.2
@@ -46,7 +46,7 @@
.Ft int
.Fn getitimer "int which" "struct itimerval *value"
.Ft int
-.Fn setitimer "int which" "struct itimerval *value" "struct itimerval *ovalue"
+.Fn setitimer "int which" "const struct itimerval *value" "struct itimerval *ovalue"
.Sh DESCRIPTION
The system provides each process with three interval timers,
defined in
@@ -155,11 +155,12 @@ parameter specified a time that was too large
to be handled.
.El
.Sh SEE ALSO
+.Xr gettimeofday 2 ,
.Xr select 2 ,
.Xr sigvec 2 ,
-.Xr gettimeofday 2
+.Xr clocks 7
.Sh HISTORY
The
-.Nm
+.Fn getitimer
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/getlogin.2 b/lib/libc/sys/getlogin.2
index 5b351ca..6154890 100644
--- a/lib/libc/sys/getlogin.2
+++ b/lib/libc/sys/getlogin.2
@@ -66,6 +66,50 @@ This call is restricted to the super-user, and
is normally used only when a new session is being created on behalf
of the named user
(for example, at login time, or when a remote shell is invoked).
+.Pp
+.Em NOTE:
+There is only one `login name' per `session .
+.Pp
+It is
+.Em CRITICALLY
+important to ensure that
+.Fn setlogin
+is only ever called after the process has taken adequate steps to ensure
+that it is detached from its parent's session.
+Making a
+.Fn setsid
+system call is the
+.Em ONLY
+way to do this. The
+.Fn daemon
+library call calls
+.Fn setsid
+which is an ideal way of detaching from a controlling terminal and
+forking into the background.
+.Pp
+In particular, doing a
+.Fn "ioctl" "ttyfd" "TIOCNOTTY" "..."
+or
+.Fn "setpgrp" "..."
+is
+.Em NOT
+sufficient.
+.Pp
+Once a parent process does a
+.Fn setsid
+call, it is acceptable for some child of that process to then do a
+.Fn setlogin
+even though it is not the session leader, but beware that ALL processes
+in the session will change their login name at the same time, even the
+parent.
+.Pp
+This is not the same as the traditional UNIX behavior of inheriting privilege.
+.Pp
+Since the
+.Fn setlogin
+system call is restricted to the super-user, it is assumed that (like
+all other privileged programs) the programmer has taken adequate
+precautions to prevent security violations.
.Sh RETURN VALUES
If a call to
.Fn getlogin
@@ -96,20 +140,14 @@ Login names are limited to
.Dv MAXLOGNAME
(from
.Ao Pa sys/param.h Ac )
-characters, currently 12.
+characters, currently 17 including null.
.It Bq Er EPERM
The caller tried to set the login name and was not the super-user.
.El
.Sh SEE ALSO
-.Xr setsid 2
+.Xr setsid 2 ,
+.Xr daemon 3
.Sh BUGS
-Login names are limited in length by
-.Fn setlogin .
-However, lower limits are placed on login names elsewhere in the system
-.Pf ( Dv UT_NAMESIZE
-in
-.Ao Pa utmp.h Ac ) .
-.Pp
In earlier versions of the system,
.Fn getlogin
failed unless the process was associated with a login terminal.
@@ -123,4 +161,5 @@ Portable programs should probably still make this check.
.Sh HISTORY
The
.Fn getlogin
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/getpeername.2 b/lib/libc/sys/getpeername.2
index d89488c..b9b6a03 100644
--- a/lib/libc/sys/getpeername.2
+++ b/lib/libc/sys/getpeername.2
@@ -38,6 +38,8 @@
.Nm getpeername
.Nd get name of connected peer
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/socket.h>
.Ft int
.Fn getpeername "int s" "struct sockaddr *name" "int *namelen"
.Sh DESCRIPTION
@@ -53,7 +55,29 @@ the amount of space pointed to by
On return it contains the actual size of the name
returned (in bytes).
The name is truncated if the buffer provided is too small.
-.Sh DIAGNOSTICS
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn getpeername
+is implemented as the
+.Va getpeername
+syscall.
+.Pp
+In the threaded library, the
+.Va getpeername
+syscall is assembled to
+.Fn _thread_sys_getpeername
+and
+.Fn getpeername
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_getpeername .
+Before returning,
+.Fn getpeername
+unlocks
+.Va s .
+.Sh RETURN VALUES
A 0 is returned if the call succeeds, -1 if it fails.
.Sh ERRORS
The call succeeds unless:
@@ -80,10 +104,10 @@ process address space.
.Sh SEE ALSO
.Xr accept 2 ,
.Xr bind 2 ,
-.Xr socket 2 ,
-.Xr getsockname 2
+.Xr getsockname 2 ,
+.Xr socket 2
.Sh HISTORY
The
-.Nm
+.Fn getpeername
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/getpgrp.2 b/lib/libc/sys/getpgrp.2
index 88812b7..9780b19 100644
--- a/lib/libc/sys/getpgrp.2
+++ b/lib/libc/sys/getpgrp.2
@@ -67,15 +67,15 @@ are used to get/set the process group of the control terminal.
.Xr termios 4
.Sh HISTORY
The
-.Nm
+.Fn getpgrp
function call appeared in
.Bx 4.0 .
.Sh STANDARDS
The
.Fn getpgrp
-function conforms to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
-.Sh COMPATABILITY
+function call is expected to conform to
+.St -p1003.1-90 .
+.Sh COMPATIBILITY
This version of
.Fn getpgrp
differs from past Berkeley versions by not taking a
@@ -87,15 +87,18 @@ This incompatibility is required by
From the
.St -p1003.1-88
Rationale:
-.sp
-4.3BSD provides a
+.Pp
+.Bx 4.3
+provides a
.Fn getpgrp
function that returns the process group ID for a specified process.
Although this function is used to support job control, all known
job-control shells always specify the calling process with this
function.
-Thus, the simpler System V
+Thus, the simpler
+.At V
.Fn getpgrp
-suffices, and the added complexity of the 4.3BSD
+suffices, and the added complexity of the
+.Bx 4.3
.Fn getpgrp
has been omitted from POSIX.1.
diff --git a/lib/libc/sys/getpid.2 b/lib/libc/sys/getpid.2
index 5f77706..b57fd60 100644
--- a/lib/libc/sys/getpid.2
+++ b/lib/libc/sys/getpid.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)getpid.2 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt GETPID 2
@@ -63,10 +64,16 @@ and
functions are always successful, and no return value is reserved to
indicate an error.
.Sh SEE ALSO
-.Xr gethostid 2
+.Xr gethostid 3
.Sh STANDARDS
-.Fn Getpid
+The
+.Fn getpid
and
.Fn getppid
-conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+function calls are expected to conform to
+.St -p1003.1-90 .
+.Sh HISTORY
+A
+.Fn getpid
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/getpriority.2 b/lib/libc/sys/getpriority.2
index aa151a0..fdb0a1e 100644
--- a/lib/libc/sys/getpriority.2
+++ b/lib/libc/sys/getpriority.2
@@ -137,6 +137,6 @@ A non super-user attempted to lower a process priority.
.Xr renice 8
.Sh HISTORY
The
-.Nm
+.Fn getpriority
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/getrlimit.2 b/lib/libc/sys/getrlimit.2
index 9aa3c8e..6725520 100644
--- a/lib/libc/sys/getrlimit.2
+++ b/lib/libc/sys/getrlimit.2
@@ -45,7 +45,7 @@
.Ft int
.Fn getrlimit "int resource" "struct rlimit *rlp"
.Ft int
-.Fn setrlimit "int resource" "struct rlimit *rlp"
+.Fn setrlimit "int resource" "const struct rlimit *rlp"
.Sh DESCRIPTION
Limits on the consumption of system resources by the current process
and each process it creates may be obtained with the
@@ -60,7 +60,7 @@ parameter is one of the following:
.Bl -tag -width RLIMIT_FSIZEAA
.It Li RLIMIT_CORE
The largest size (in bytes)
-.Xr core
+.Xr core 5
file that may be created.
.It Li RLIMIT_CPU
The maximum amount of cpu time (in seconds) to be used by
@@ -102,8 +102,8 @@ its resource limit). The
structure is used to specify the hard and soft limits on a resource,
.Bd -literal -offset indent
struct rlimit {
- quad_t rlim_cur; /* current (soft) limit */
- quad_t rlim_max; /* hard limit */
+ rlim_t rlim_cur; /* current (soft) limit */
+ rlim_t rlim_max; /* maximum value for rlim_cur */
};
.Ed
.Pp
@@ -171,21 +171,13 @@ raised the maximum limit value, and the caller is not the super-user.
.El
.Sh SEE ALSO
.Xr csh 1 ,
-.Xr quota 2 ,
+.Xr quota 1 ,
+.Xr quotactl 2 ,
.Xr sigaltstack 2 ,
.Xr sigvec 2 ,
.Xr sysctl 3
-.Sh BUGS
-There should be
-.Ic limit
-and
-.Ic unlimit
-commands in
-.Xr sh 1
-as well as in
-.Xr csh .
.Sh HISTORY
The
-.Nm
+.Fn getrlimit
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/getrusage.2 b/lib/libc/sys/getrusage.2
index 9d1657c..0f92569 100644
--- a/lib/libc/sys/getrusage.2
+++ b/lib/libc/sys/getrusage.2
@@ -38,6 +38,7 @@
.Nm getrusage
.Nd get information about resource utilization
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
.Fd #include <sys/time.h>
.Fd #include <sys/resource.h>
.Fd #define RUSAGE_SELF 0
@@ -62,7 +63,7 @@ the following structure:
struct rusage {
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
- long ru_maxrss; /* integral max resident set size */
+ long ru_maxrss; /* max resident set size */
long ru_ixrss; /* integral shared text memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
@@ -93,6 +94,9 @@ an \*(lqintegral\*(rq value indicating the amount of memory used
by the text segment
that was also shared among other processes. This value is expressed
in units of kilobytes * ticks-of-execution.
+Ticks are statistics clock ticks.
+The statistics clock has a frequency of
+sysconf(_SC_CLOCK_TCK) ticks per second.
.It Fa ru_idrss
an integral value of the amount of unshared memory residing in the
data segment of a process (expressed in units of
@@ -137,10 +141,16 @@ and
account only for real
I/O; data supplied by the caching mechanism is charged only
to the first process to read or write the data.
+.Sh RETURN VALUES
+Uponsuccessful completion,
+.Fn getrusage
+returns 0. Otherwise, a value of -1 is returned and
+.Va errno
+is set to indicate the error.
.Sh ERRORS
-.Fn Getrusage
-returns -1 on error.
-The possible errors are:
+The
+.Fn getrusage
+function will fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
The
@@ -153,12 +163,13 @@ parameter is not in a valid part of the process address space.
.El
.Sh SEE ALSO
.Xr gettimeofday 2 ,
-.Xr wait 2
+.Xr wait 2 ,
+.Xr clocks 7
.Sh BUGS
There is no way to obtain information about a child process
that has not yet terminated.
.Sh HISTORY
The
-.Nm
+.Fn getrusage
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/getsockname.2 b/lib/libc/sys/getsockname.2
index d56e404..bbd9f93 100644
--- a/lib/libc/sys/getsockname.2
+++ b/lib/libc/sys/getsockname.2
@@ -38,6 +38,8 @@
.Nm getsockname
.Nd get socket name
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/socket.h>
.Ft int
.Fn getsockname "int s" "struct sockaddr *name" "int *namelen"
.Sh DESCRIPTION
@@ -51,7 +53,29 @@ the amount of space pointed to by
.Fa name .
On return it contains the actual size of the name
returned (in bytes).
-.Sh DIAGNOSTICS
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn getsockname
+is implemented as the
+.Va getsockname
+syscall.
+.Pp
+In the threaded library, the
+.Va getsockname
+syscall is assembled to
+.Fn _thread_sys_getsockname
+and
+.Fn getsockname
+is implemented as a function which locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_getsockname .
+Before returning,
+.Fn getsockname
+unlocks
+.Va fd .
+.Sh RETURN VALUES
A 0 is returned if the call succeeds, -1 if it fails.
.Sh ERRORS
The call succeeds unless:
@@ -75,6 +99,7 @@ process address space.
.El
.Sh SEE ALSO
.Xr bind 2 ,
+.Xr getpeername 2 ,
.Xr socket 2
.Sh BUGS
Names bound to sockets in the UNIX domain are inaccessible;
@@ -82,6 +107,6 @@ Names bound to sockets in the UNIX domain are inaccessible;
returns a zero length name.
.Sh HISTORY
The
-.Nm
+.Fn getsockname
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2
index 8362d5e..ff9ca90 100644
--- a/lib/libc/sys/getsockopt.2
+++ b/lib/libc/sys/getsockopt.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)getsockopt.2 8.4 (Berkeley) 5/2/95
+.\" $Id: getsockopt.2,v 1.8 1997/02/22 15:03:53 peter Exp $
.\"
.Dd May 2, 1995
.Dt GETSOCKOPT 2
@@ -189,7 +190,7 @@ is performed.
If the socket promises reliable delivery of data and
.Dv SO_LINGER is set,
the system will block the process on the
-.Xr close
+.Xr close 2
attempt until it is able to transmit the data or until it decides it
is unable to deliver the information (a timeout period, termed the
linger interval, is specified in seconds in the
@@ -200,7 +201,7 @@ is requested).
If
.Dv SO_LINGER
is disabled and a
-.Xr close
+.Xr close 2
is issued, the system will process the close in a manner that allows
the process to continue as quickly as possible.
.Pp
@@ -214,9 +215,9 @@ With protocols that support out-of-band data, the
option
requests that out-of-band data be placed in the normal data input queue
as received; it will then be accessible with
-.Xr recv
+.Xr recv 2
or
-.Xr read
+.Xr read 2
calls without the
.Dv MSG_OOB
flag.
@@ -228,7 +229,11 @@ are options to adjust the normal
buffer sizes allocated for output and input buffers, respectively.
The buffer size may be increased for high-volume connections,
or may be decreased to limit the possible backlog of incoming data.
-The system places an absolute limit on these values.
+The system places an absolute maximum on these values, which is accessible
+through the
+.Xr sysctl 3
+MIB variable
+.Dq Li kern.maxsockbuf .
.Pp
.Dv SO_SNDLOWAT
is an option to set the minimum count for output operations.
@@ -261,7 +266,7 @@ wait until they have received the smaller of the low water mark value
or the requested amount.
Receive calls may still return less than the low water mark if an error
occurs, a signal is caught, or the type of data next in the receive queue
-is different than that returned.
+is different from that which was returned.
.Pp
.Dv SO_SNDTIMEO
is an option to set a timeout value for output operations.
@@ -308,6 +313,49 @@ returns any pending error on the socket and clears
the error status.
It may be used to check for asynchronous errors on connected
datagram sockets or for other asynchronous errors.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn getsockopt
+is implemented as the
+.Va getsockopt
+syscall.
+.Pp
+In the threaded library, the
+.Va getsockopt
+syscall is assembled to
+.Fn _thread_sys_getsockopt
+and
+.Fn getsockopt
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_getsockopt .
+Before returning,
+.Fn getsockopt
+unlocks
+.Va s .
+.Pp
+In the non-threaded library
+.Fn setsockopt
+is implemented as the
+.Va setsockopt
+syscall.
+.Pp
+In the threaded library, the
+.Va setsockopt
+syscall is assembled to
+.Fn _thread_sys_setsockopt
+and
+.Fn setsockopt
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_setsockopt .
+Before returning,
+.Fn setsockopt
+unlocks
+.Va s .
.Sh RETURN VALUES
A 0 is returned if the call succeeds, -1 if it fails.
.Sh ERRORS
@@ -336,12 +384,14 @@ is not in a valid part of the process address space.
.Sh SEE ALSO
.Xr ioctl 2 ,
.Xr socket 2 ,
-.Xr getprotoent 3
-.Xr protocols 5
+.Xr getprotoent 3 ,
+.Xr sysctl 3 ,
+.Xr protocols 5 ,
+.Xr sysctl 8
.Sh BUGS
Several of the socket options should be handled at lower levels of the system.
.Sh HISTORY
The
-.Nm
+.Fn getsockopt
system call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/gettimeofday.2 b/lib/libc/sys/gettimeofday.2
index b4d0429..06ee8b1 100644
--- a/lib/libc/sys/gettimeofday.2
+++ b/lib/libc/sys/gettimeofday.2
@@ -43,7 +43,7 @@
.Ft int
.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp"
.Ft int
-.Fn settimeofday "struct timeval *tp" "struct timezone *tzp"
+.Fn settimeofday "const struct timeval *tp" "const struct timezone *tzp"
.Sh DESCRIPTION
.Bf -symbolic
Note: timezone is no longer used; this information is kept outside
@@ -74,13 +74,13 @@ as:
.Pp
.Bd -literal
struct timeval {
- long tv_sec; /* seconds since Jan. 1, 1970 */
+ long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
struct timezone {
- int tz_minuteswest; /* of Greenwich */
- int tz_dsttime; /* type of dst correction to apply */
+ int tz_minuteswest; /* minutes west of Greenwich */
+ int tz_dsttime; /* type of dst correction */
};
.Ed
.Pp
@@ -119,9 +119,10 @@ A user other than the super-user attempted to set the time.
.Xr date 1 ,
.Xr adjtime 2 ,
.Xr ctime 3 ,
+.Xr clocks 7 ,
.Xr timed 8
.Sh HISTORY
The
-.Nm
+.Fn gettimeofday
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/getuid.2 b/lib/libc/sys/getuid.2
index 23b1763..9808cb2 100644
--- a/lib/libc/sys/getuid.2
+++ b/lib/libc/sys/getuid.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)getuid.2 8.1 (Berkeley) 6/4/93
+.\" $Id: getuid.2,v 1.5 1997/02/22 15:03:54 peter Exp $
.\"
.Dd June 4, 1993
.Dt GETUID 2
@@ -71,10 +72,21 @@ functions are always successful, and no return value is reserved to
indicate an error.
.Sh SEE ALSO
.Xr getgid 2 ,
-.Xr setreuid 2
+.Xr issetugid 2 ,
+.Xr setgid 2 ,
+.Xr setreuid 2 ,
+.Xr setuid 2
.Sh STANDARDS
-.Fn Geteuid
+The
+.Fn geteuid
and
.Fn getuid
-conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+function calls are expected to conform to
+.St -p1003.1-90 .
+.Sh HISTORY
+A
+.Fn getuid
+and a
+.Fn geteuid
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/intro.2 b/lib/libc/sys/intro.2
index ddda2ba..ee46085 100644
--- a/lib/libc/sys/intro.2
+++ b/lib/libc/sys/intro.2
@@ -46,13 +46,50 @@ their error returns, and other common definitions and concepts.
.\".Sy System call restart
.\".Pp
.\"<more later...>
-.Sh DIAGNOSTICS
-Nearly all of the system calls provide an error number in the external
-variable
-.Va errno ,
-which is defined as:
+.Sh RETURN VALUES
+Nearly all of the system calls provide an error number referenced via
+the external identifier errno. This identifier is defined in
+.Aq Pa sys/errno.h
+for non-threaded programs as:
.Pp
-.Dl extern int errno
+.Dl extern int errno;
+.Pp
+and for threaded programs as:
+.Pp
+.Dl extern int * __error();
+.Dl #define errno (* __error())
+.Pp
+A threaded program must be compiled with
+.Va _THREAD_SAFE
+defined so that the preprocessor will output the appropriate errno
+definition to the compiler. Failure to do so will mean that error
+variables will not be thread specific.
+.Pp
+The threaded library implementation of
+.Va __error()
+returns a pointer to a field in the thread specific structure for
+threads other than the initial thread. For the initial thread,
+.Va __error()
+returns a pointer to a global
+.Va errno
+variable that is compatible with that used by non-threaded programs.
+This allows the initial thread to call functions in libraries which have
+not been compiled with
+.Va _THREAD_SAFE .
+Programmers should ensure that threads other than the initial thread only
+call functions in libraries that have been compiled with
+.Va _THREAD_SAFE .
+.Pp
+Programmers should include
+.Aq Pa sys/errno.h
+to obtain the definition of
+.Va errno
+rather than coding the definition as an external reference directly. It is
+planned that the
+.Va extern int errno
+definition will eventually be replaced by the threaded definition so that
+all libraries will have a thread-aware treatment of
+.Va errno .
.Pp
When a system call detects an error,
it returns an integer value
@@ -108,7 +145,7 @@ loaded on a drive.
.It Er 7 E2BIG Em "Arg list too long" .
The number of bytes used for the argument and environment
list of the new process exceeded the current limit
-of 20480 bytes
+of 65536 bytes
.Pf ( Dv NCARGS
in
.Aq Pa sys/param.h ) .
@@ -121,12 +158,12 @@ executable file.
A file descriptor argument was out of range, referred to no open file,
or a read (write) request was made to a file that was only open for
writing (reading).
-.sp
+.Pp
.It Er 10 ECHILD Em "\&No child processes" .
A
-.Xr wait
+.Xr wait 2
or
-.Xr waitpid
+.Xr waitpid 2
function was executed by a process that had no existing or unwaited-for
child processes.
.It Er 11 EDEADLK Em "Resource deadlock avoided" .
@@ -152,7 +189,7 @@ in a manner which would have conflicted with the request.
.It Er 17 EEXIST Em "File exists" .
An existing file was mentioned in an inappropriate context,
for instance, as the new link name in a
-.Xr link
+.Xr link 2
function.
.It Er 18 EXDEV Em "Improper link" .
A hard link to a file on another file system
@@ -170,9 +207,9 @@ An attempt was made to open a directory with write mode specified.
.It Er 22 EINVAL Em "Invalid argument" .
Some invalid argument was supplied. (For example,
specifying an undefined signal to a
-.Xr signal
+.Xr signal 3
or
-.Xr kill
+.Xr kill 2
function).
.It Er 23 ENFILE Em "Too many open files in system" .
Maximum number of file descriptors allowable on the system
@@ -192,7 +229,7 @@ special device for which the operation was inappropriate.
The new process was a pure procedure (shared text) file
which was open for writing by another process, or
while the pure procedure file was being executed an
-.Xr open
+.Xr open 2
call requested write access.
.It Er 27 EFBIG Em "File too large" .
The size of a file exceeded the maximum (about
@@ -201,7 +238,7 @@ The size of a file exceeded the maximum (about
bytes).
.It Er 28 ENOSPC Em "Device out of space" .
A
-.Xr write
+.Xr write 2
to an ordinary file, the creation of a
directory or symbolic link, or the creation of a directory
entry failed because no more disk blocks were available
@@ -210,7 +247,7 @@ created file failed because no more inodes were available
on the file system.
.It Er 29 ESPIPE Em "Illegal seek" .
An
-.Xr lseek
+.Xr lseek 2
function was issued on a socket, pipe or
.Tn FIFO .
.It Er 30 EROFS Em "Read-only file system" .
@@ -289,7 +326,7 @@ addresses with
Internet protocols.
.It Er 48 EADDRINUSE Em "Address already in use" .
Only one usage of each address is normally permitted.
-.sp
+.Pp
.It Er 49 EADDRNOTAVAIL Em "Cannot assign requested address" .
Normally results from an attempt to create a socket with an
address not on this machine.
@@ -310,12 +347,12 @@ An operation on a socket or pipe was not performed because
the system lacked sufficient buffer space or because a queue was full.
.It Er 56 EISCONN Em "Socket is already connected" .
A
-.Xr connect
+.Xr connect 2
request was made on an already connected socket; or,
a
-.Xr sendto
+.Xr sendto 2
or
-.Xr sendmsg
+.Xr sendmsg 2
request on a connected socket specified a destination
when already connected.
.It Er 57 ENOTCONN Em "Socket is not connected" .
@@ -329,9 +366,9 @@ had already been shut down with a previous
call.
.It Er 60 ETIMEDOUT Em "Operation timed out" .
A
-.Xr connect
+.Xr connect 2
or
-.Xr send
+.Xr send 2
request failed because the connected party did not
properly respond after a period of time. (The timeout
period is dependent on the communication protocol.)
@@ -363,7 +400,7 @@ was supplied to a remove directory or rename call.
The quota system ran out of table entries.
.It Er 69 EDQUOT Em "Disc quota exceeded" .
A
-.Xr write
+.Xr write 2
to an ordinary file, the creation of a
directory or symbolic link, or the creation of a directory
entry failed because the user's quota of disk blocks was
@@ -417,7 +454,7 @@ A new process is created by a currently active process; (see
The parent process ID of a process is initially the process ID of its creator.
If the creating process exits,
the parent process ID of each child is set to the ID of a system process,
-.Xr init .
+.Xr init 8 .
.It Process Group
Each active process is a member of a process group that is identified by
a non-negative integer called the process group ID. This is the process
@@ -465,7 +502,7 @@ as the group,
but is in a different process group.
Note that when a process exits, the parent process for its children
is changed to be
-.Xr init ,
+.Nm init ,
which is in a separate session.
Not all members of an orphaned process group are necessarily orphaned
processes (those whose creating process has exited).
@@ -555,8 +592,7 @@ excluding 0 (NUL) and the
.Tn ASCII
code for
.Ql \&/
-(slash). (The parity bit,
-bit 7, must be 0.)
+(slash).
.Pp
Note that it is generally unwise to use
.Ql \&* ,
diff --git a/lib/libc/sys/ioctl.2 b/lib/libc/sys/ioctl.2
index 36ce6ff..a1d5f79 100644
--- a/lib/libc/sys/ioctl.2
+++ b/lib/libc/sys/ioctl.2
@@ -68,6 +68,28 @@ Macros and defines used in specifying an ioctl
.Fa request
are located in the file
.Ao Pa sys/ioctl.h Ac .
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn ioctl
+is implemented as the
+.Va ioctl
+syscall.
+.Pp
+In the threaded library, the
+.Va ioctl
+syscall is assembled to
+.Fn _thread_sys_ioctl
+and
+.Fn ioctl
+is implemented as a function which locks
+.Va d
+for read and write, then calls
+.Fn _thread_sys_ioctl .
+Before returning,
+.Fn ioctl
+unlocks
+.Va d .
.Sh RETURN VALUES
If an error has occurred, a value of -1 is returned and
.Va errno
@@ -98,9 +120,10 @@ is not valid.
.Xr mt 1 ,
.Xr execve 2 ,
.Xr fcntl 2 ,
-.Xr tty 4 ,
-.Xr intro 4
+.Xr intro 4 ,
+.Xr tty 4
.Sh HISTORY
An
-.Nm
-function call appeared in Version 7 AT&T UNIX.
+.Fn ioctl
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/issetugid.2 b/lib/libc/sys/issetugid.2
new file mode 100644
index 0000000..943aa7d
--- /dev/null
+++ b/lib/libc/sys/issetugid.2
@@ -0,0 +1,94 @@
+.\" $OpenBSD: issetugid.2,v 1.7 1997/02/18 00:16:09 deraadt Exp $
+.\"
+.\" Copyright (c) 1980, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\" $Id: issetugid.2,v 1.3 1997/04/01 18:45:57 mpp Exp $
+.\"
+.Dd August, 25 1996
+.Dt ISSETUGID 2
+.Os
+.Sh NAME
+.Nm issetugid
+.Nd is current process tainted by uid or gid changes
+.Sh SYNOPSIS
+.Fd #include <unistd.h>
+.Ft int
+.Fn issetugid void
+.Sh DESCRIPTION
+The
+.Fn issetugid
+function returns 1 if the process environment or memory address space
+is considered ``tainted'', and returns 0 otherwise.
+.Pp
+A process is tainted if it was created as a result of an
+.Xr execve 2
+system call which had either of the setuid or setgid bits set (and extra
+privileges were given as a result) or if it has changed any of it's real,
+effective or saved user or group ID's since it began execution.
+.Pp
+This system call exists so that library routines (eg: libc, libtermcap)
+can reliably determine if it is safe to use information
+that was obtained from the user, in particular the results from
+.Xr getenv 3
+should be viewed with suspicion if it is used to control operation.
+.Pp
+A ``tainted'' status is inherited by child processes as a result of the
+.Xr fork 2
+system call (or other library code that calls fork, such as
+.Xr popen 3 ) .
+.Pp
+It is assumed that a program that clears all privileges as it prepares
+to execute another will also reset the environment, hence the ``tainted''
+status will not be passed on. This is important for programs such as
+.Xr su 1
+which begin setuid but need to be able to create an untainted process.
+.Sh ERRORS
+The
+.Fn issetugid
+function is always successful, and no return value is reserved to
+indicate an error.
+.Sh SEE ALSO
+.Xr execve 2 ,
+.Xr fork 2 ,
+.Xr setgid 2 ,
+.Xr setegid 2 ,
+.Xr seteuid 2 ,
+.Xr setregid 2 ,
+.Xr setreuid 2 ,
+.Xr setuid 2
+.Sh HISTORY
+A
+.Fn issetugid
+function call first appeared in
+.Ox 2.0
+and was also implemented in
+.Fx 3.0 .
diff --git a/lib/libc/sys/kill.2 b/lib/libc/sys/kill.2
index a20afd3..6234bc1 100644
--- a/lib/libc/sys/kill.2
+++ b/lib/libc/sys/kill.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)kill.2 8.3 (Berkeley) 4/19/94
+.\" $Id: kill.2,v 1.6 1997/02/22 15:03:55 peter Exp $
.\"
.Dd April 19, 1994
.Dt KILL 2
@@ -38,6 +39,7 @@
.Nm kill
.Nd send signal to a process
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
.Fd #include <signal.h>
.Ft int
.Fn kill "pid_t pid" "int sig"
@@ -119,13 +121,17 @@ When signaling a process group, this error is returned if any members
of the group could not be signaled.
.El
.Sh SEE ALSO
-.Xr getpid 2 ,
.Xr getpgrp 2 ,
+.Xr getpid 2 ,
.Xr killpg 2 ,
.Xr sigaction 2
.Sh STANDARDS
The
.Fn kill
-function is expected to
-conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+function call is expected to conform to
+.St -p1003.1-90 .
+.Sh HISTORY
+A
+.Fn kill
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/ktrace.2 b/lib/libc/sys/ktrace.2
index 9fe61f8..8f41a52 100644
--- a/lib/libc/sys/ktrace.2
+++ b/lib/libc/sys/ktrace.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)ktrace.2 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt KTRACE 2
@@ -38,7 +39,9 @@
.Nm ktrace
.Nd process tracing
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
+.Fd #include <sys/param.h>
+.Fd #include <sys/time.h>
+.Fd #include <sys/uio.h>
.Fd #include <sys/ktrace.h>
.Ft int
.Fn ktrace "const char *tracefile" "int ops" "int trpoints" "int pid"
@@ -52,7 +55,7 @@ Only the super-user can trace setuid or setgid programs.
The
.Ar tracefile
gives the pathname of the file to be used for tracing.
-The file must exist and be writable by the calling process.
+The file must exist and be a regular file writable by the calling process.
All trace records are always appended to the file,
so the file must be truncated to zero length to discard
previous trace data.
@@ -138,8 +141,6 @@ will fail if:
.Bl -tag -width ENAMETOOLONGAA
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -153,8 +154,8 @@ Too many symbolic links were encountered in translating the pathname.
An I/O error occurred while reading from or writing to the file system.
.El
.Sh SEE ALSO
-.Xr ktrace 1 ,
-.Xr kdump 1
+.Xr kdump 1 ,
+.Xr ktrace 1
.Sh HISTORY
A
.Nm ktrace
diff --git a/lib/libc/sys/link.2 b/lib/libc/sys/link.2
index d160786..e0bc45e 100644
--- a/lib/libc/sys/link.2
+++ b/lib/libc/sys/link.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)link.2 8.3 (Berkeley) 1/12/94
+.\" $Id$
.\"
.Dd January 12, 1994
.Dt LINK 2
@@ -74,7 +75,6 @@ both
and
.Fa name2
must be in the same file system.
-Unless the caller is the super-user,
.Fa name1
may not be a directory.
.Sh RETURN VALUES
@@ -88,8 +88,6 @@ will fail and no link will be created if:
.Bl -tag -width Ar
.It Bq Er ENOTDIR
A component of either path prefix is not a directory.
-.It Bq Er EINVAL
-Either pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of either pathname exceeded 255 characters,
or entire length of either path name exceeded 1023 characters.
@@ -113,8 +111,7 @@ does exist.
.It Bq Er EPERM
The file named by
.Fa name1
-is a directory and the effective
-user ID is not super-user.
+is a directory.
.It Bq Er EXDEV
The link named by
.Fa name2
@@ -145,7 +142,18 @@ is outside the process's allocated address space.
.Xr symlink 2 ,
.Xr unlink 2
.Sh STANDARDS
-.Fn Link
-is expected to
-conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn link
+function call is expected to conform to
+.St -p1003.1-90 .
+.Sh HISTORY
+A
+.Fn link
+function call appeared in
+.At v7 .
+.Pp
+The
+.Fn link
+system call traditionally allows the super-user to link directories which
+corrupts the filesystem coherency. This implementation no longer permits
+it.
diff --git a/lib/libc/sys/listen.2 b/lib/libc/sys/listen.2
index 0dd2060..a9b503f 100644
--- a/lib/libc/sys/listen.2
+++ b/lib/libc/sys/listen.2
@@ -29,15 +29,17 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)listen.2 8.2 (Berkeley) 12/11/93
+.\" From: @(#)listen.2 8.2 (Berkeley) 12/11/93
+.\" $Id: listen.2,v 1.9 1997/02/22 15:03:59 peter Exp $
.\"
-.Dd December 11, 1993
+.Dd November 3, 1995
.Dt LISTEN 2
.Os BSD 4.2
.Sh NAME
.Nm listen
.Nd listen for connections on a socket
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
.Fd #include <sys/socket.h>
.Ft int
.Fn listen "int s" "int backlog"
@@ -68,6 +70,41 @@ receive an error with an indication of
.Er ECONNREFUSED ,
or, if the underlying protocol supports retransmission,
the request may be ignored so that retries may succeed.
+.Pp
+The
+.Xr sysctl 3
+MIB variable
+.Dq Li kern.somaxconn
+specifies a hard limit on
+.Fa backlog ;
+if a value greater than
+.Li kern.somaxconn
+or less than zero is specified,
+.Fa backlog
+is silently forced to
+.Li kern.somaxconn .
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn listen
+is implemented as the
+.Va listen
+syscall.
+.Pp
+In the threaded library, the
+.Va listen
+syscall is assembled to
+.Fn _thread_sys_listen
+and
+.Fn listen
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_listen .
+Before returning,
+.Fn listen
+unlocks
+.Va s .
.Sh RETURN VALUES
A 0 return value indicates success; -1 indicates an error.
.Sh ERRORS
@@ -89,13 +126,17 @@ The socket is not of a type that supports the operation
.Sh SEE ALSO
.Xr accept 2 ,
.Xr connect 2 ,
-.Xr socket 2
-.Sh BUGS
-The
-.Fa backlog
-is currently limited (silently) to 5.
+.Xr socket 2 ,
+.Xr sysctl 3 ,
+.Xr sysctl 8
.Sh HISTORY
The
-.Nm
+.Fn listen
function call appeared in
.Bx 4.2 .
+The ability to configure the maximum
+.Fa backlog
+at run-time, and to use a negative
+.Fa backlog
+to request the maximum allowable value, was introduced in
+.Fx 2.2 .
diff --git a/lib/libc/sys/lseek.2 b/lib/libc/sys/lseek.2
index ef38451..39a37fa 100644
--- a/lib/libc/sys/lseek.2
+++ b/lib/libc/sys/lseek.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)lseek.2 8.3 (Berkeley) 4/19/94
+.\" $Id$
.\"
.Dd April 19, 1994
.Dt LSEEK 2
@@ -56,7 +57,8 @@ The argument
must be an open
file descriptor.
.Fn Lseek
-repositions the file pointer
+repositions the file position pointer associated with the file
+descriptor
.Fa fildes
as follows:
.Bl -item -offset indent
@@ -108,7 +110,7 @@ is set to indicate
the error.
.Sh ERRORS
.Fn Lseek
-will fail and the file pointer will remain unchanged if:
+will fail and the file position pointer will remain unchanged if:
.Bl -tag -width [EINVAL]
.It Bq Er EBADF
.Em Fildes
@@ -130,6 +132,10 @@ is incorrect English, but is maintained for historical reasons.
.Sh STANDARDS
The
.Fn lseek
-function
-conforms to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+function call is expected to conform to
+.St -p1003.1-90 .
+.Sh HISTORY
+A
+.Fn lseek
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c
index 52208d1..8896ad8 100644
--- a/lib/libc/sys/lseek.c
+++ b/lib/libc/sys/lseek.c
@@ -37,6 +37,11 @@ static char sccsid[] = "@(#)lseek.c 8.1 (Berkeley) 6/17/93";
#include <sys/types.h>
#include <sys/syscall.h>
+#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* This function provides 64-bit offset padding that
@@ -48,7 +53,17 @@ lseek(fd, offset, whence)
off_t offset;
int whence;
{
- extern off_t __syscall();
+#ifdef _THREAD_SAFE
+ off_t offs;
+ if (_thread_fd_lock(fd, FD_RDWR, NULL,__FILE__,__LINE__) != 0) {
+ offs = -1;
+ } else {
+ offs = __syscall((quad_t) SYS_lseek,fd, 0, offset, whence);
+ _thread_fd_unlock(fd, FD_RDWR);
+ }
+ return(offs);
+#else
return(__syscall((quad_t)SYS_lseek, fd, 0, offset, whence));
+#endif
}
diff --git a/lib/libc/sys/madvise.2 b/lib/libc/sys/madvise.2
index d0676ab..fc71765 100644
--- a/lib/libc/sys/madvise.2
+++ b/lib/libc/sys/madvise.2
@@ -30,15 +30,19 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)madvise.2 8.1 (Berkeley) 6/9/93
+.\" $Id$
.\"
-.Dd June 9, 1993
+.Dd Jul 19, 1996
.Dt MADVISE 2
.Os
.Sh NAME
.Nm madvise
.Nd give advise about use of memory
.Sh SYNOPSIS
-.Fn madvise "caddr_t addr" "int len" "int behav"
+.Fd #include <sys/types.h>
+.Fd #include <sys/mman.h>
+.Ft int
+.Fn madvise "caddr_t addr" "size_t len" "int behav"
.Sh DESCRIPTION
The
.Fn madvise
@@ -46,21 +50,78 @@ system call
allows a process that has knowledge of its memory behavior
to describe it to the system.
The known behaviors are given in
-.Pa <sys/mman.h> :
+.Aq Pa sys/mman.h :
.Bd -literal
-#define MADV_NORMAL 0 /* no further special treatment */
-#define MADV_RANDOM 1 /* expect random page references */
-#define MADV_SEQUENTIAL 2 /* expect sequential references */
-#define MADV_WILLNEED 3 /* will need these pages */
-#define MADV_DONTNEED 4 /* don't need these pages */
-#define MADV_SPACEAVAIL 5 /* insure that resources are reserved */
+#define MADV_NORMAL 0 /* no further special treatment */
+#define MADV_RANDOM 1 /* expect random page references */
+#define MADV_SEQUENTIAL 2 /* expect sequential references */
+#define MADV_WILLNEED 3 /* will need these pages */
+#define MADV_DONTNEED 4 /* don't need these pages */
+#define MADV_FREE 5 /* data is now unimportant */
.Ed
+.Pp
+.Bl -tag -width MADV_SEQUENTIAL
+.It Dv MADV_NORMAL
+Tells the system to revert to the default paging
+behavior.
+.It Dv MADV_RANDOM
+Is a hint that pages will be accessed randomly, and prefetching
+is likely not advantageous.
+.It Dv MADV_SEQUENTIAL
+Causes the VM system to depress the priority of
+pages immediately preceeding a given page when it is faulted in.
+.It Dv MADV_WILLNEED
+Causes pages that are in a given virtual address range
+to temporarily have higher priority, and if they are in
+memory, decrease the likelihood of them being freed. Additionally,
+the pages that are already in memory will be immediately mapped into
+the process, thereby eliminating unnecessary overhead of going through
+the entire process of faulting the pages in. This WILL NOT fault
+pages in from backing store, but quickly map the pages already in memory
+into the calling process.
+.It Dv MADV_DONTNEED
+Allows the VM system to decrease the in-memory priority
+of pages in the specified range. Additionally future references to
+this address range will incur a page fault.
+.Dv MADV_FREE
+gives the VM system the freedom to free pages,
+and tells the system that information in the specified page range
+is no longer important. This is an efficient way of allowing
+.Xr malloc 3
+to free pages anywhere in the address space, while keeping the address space
+valid. The next time that the page is referenced, the page might be demand
+zeroed, or might contain the data that was there before the
+.Dv MADV_FREE
+call.
+References made to that address space range will not make the VM system
+page the information back in from backing store until the page is
+modified again.
+.El
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn madvise
+returns 0. Otherwise a value of -1 is returned and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+The
+.Fn madvise
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The virtual address range specified by the
+.Fa addr
+and
+.Fa len
+arguments is not valid.
+.El
.Sh SEE ALSO
-.Xr msync 2 ,
-.Xr munmap 2 ,
+.Xr mincore 2 ,
.Xr mprotect 2 ,
-.Xr mincore 2
+.Xr msync 2 ,
+.Xr munmap 2 .
.Sh HISTORY
The
-.Nm madvise
-function first appeared in 4.4BSD.
+.Fn madvise
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/mincore.2 b/lib/libc/sys/mincore.2
index 4e73c2a..9c694f4 100644
--- a/lib/libc/sys/mincore.2
+++ b/lib/libc/sys/mincore.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)mincore.2 8.1 (Berkeley) 6/9/93
+.\" $Id$
.\"
.Dd June 9, 1993
.Dt MINCORE 2
@@ -38,7 +39,10 @@
.Nm mincore
.Nd get advise about use of memory
.Sh SYNOPSIS
-.Fn mincore "caddr_t addr" "int len" "char *vec"
+.Fd #include <sys/types.h>
+.Fd #include <sys/mman.h>
+.Ft int
+.Fn mincore "caddr_t addr" "size_t len" "char *vec"
.Sh DESCRIPTION
The
.Fn mincore
@@ -50,12 +54,35 @@ in the character array
.Fa vec ,
with a value of 1 meaning
that the page is in-core.
+.Sh RETURN VALUES
+Upson successful completion,
+.Fn mincore
+returns 0 and
+.Fa vec
+is updated to relect the page status. Otherwise a value of -1
+is returned and
+.Va error
+is set to indicate the error.
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The virtial address range specified by the
+.Fa addr
+and
+.Fa len
+arguments is not valid.
+.It Bq Er EFAULT
+The
+.Fa vec
+argument points to an illegal address.
+.El
.Sh SEE ALSO
-.Xr msync 2 ,
-.Xr munmap 2 ,
-.Xr mprotect 2 ,
.Xr madvise 2 ,
+.Xr mprotect 2 ,
+.Xr msync 2 ,
+.Xr munmap 2
.Sh HISTORY
The
.Fn mincore
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/minherit.2 b/lib/libc/sys/minherit.2
new file mode 100644
index 0000000..a8ebed3
--- /dev/null
+++ b/lib/libc/sys/minherit.2
@@ -0,0 +1,94 @@
+.\" $Id$
+.\"
+.\" Copyright (c) 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\" @(#)minherit.2 8.1 (Berkeley) 6/9/93
+.\"
+.Dd Feb 17, 1996
+.Dt MINHERIT 2
+.Os
+.Sh NAME
+.Nm minherit
+.Nd control the inheritance of pages
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/mman.h>
+.Ft int
+.Fn minherit "caddr_t addr" "size_t len" "int inherit"
+.Sh DESCRIPTION
+The
+.Fn minherit
+system call
+changes the specified pages to have the inheritance characteristic
+.Fa inherit .
+Not all implementations will guarantee that the inheritance characteristic
+can be set on a page basis;
+the granularity of changes may be as large as an entire region.
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn minherit
+returns 0. Otherwise, a value of -1 is returned and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+The
+.Fn minherit
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The virtual address range specified by the
+.Fa addr
+and
+.Fa len
+arguments is not valid.
+.It Bq Er EACESS
+The flags specified by the
+.Fa inherit
+argument were not valid for the pages specified
+by the
+.Fa addr
+and
+.Fa len
+arguments.
+.El
+.Sh SEE ALSO
+.Xr fork 2 ,
+.Xr madvise 2 ,
+.Xr mincore 2 ,
+.Xr mprotect 2 ,
+.Xr msync 2 ,
+.Xr munmap 2 ,
+.Xr rfork 2
+.Sh HISTORY
+The
+.Fn minherit
+function first appeared in OpenBSD.
diff --git a/lib/libc/sys/mkdir.2 b/lib/libc/sys/mkdir.2
index 4bf11be..1dc6ef5 100644
--- a/lib/libc/sys/mkdir.2
+++ b/lib/libc/sys/mkdir.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)mkdir.2 8.2 (Berkeley) 12/11/93
+.\" $Id$
.\"
.Dd December 11, 1993
.Dt MKDIR 2
@@ -46,7 +47,7 @@ The directory
.Fa path
is created with the access permissions specified by
.Fa mode
-and restricted by the the
+and restricted by the
.Xr umask 2
of the calling process.
.Pp
@@ -63,8 +64,6 @@ will fail and no directory will be created if:
.Bl -tag -width ENAMETOOLO
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -108,6 +107,7 @@ points outside the process's allocated address space.
.Xr stat 2 ,
.Xr umask 2
.Sh STANDARDS
-.Fn Mkdir
-conforms to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn mkdir
+function call is expected to conform to
+.St -p1003.1-90 .
diff --git a/lib/libc/sys/mkfifo.2 b/lib/libc/sys/mkfifo.2
index 6f7686e..b39bf9c 100644
--- a/lib/libc/sys/mkfifo.2
+++ b/lib/libc/sys/mkfifo.2
@@ -67,8 +67,6 @@ will fail and no fifo will be created if:
The kernel has not been configured to support fifo's.
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -115,10 +113,11 @@ points outside the process's allocated address space.
.El
.Sh SEE ALSO
.Xr chmod 2 ,
+.Xr mknod 2,
.Xr stat 2 ,
.Xr umask 2
.Sh STANDARDS
The
-.Nm mkfifo
-function call conforms to
-.St -p1003.1-88 .
+.Fn mkfifo
+function call is expected to conform to
+.St -p1003.1-90 .
diff --git a/lib/libc/sys/mknod.2 b/lib/libc/sys/mknod.2
index d77ccbc..2fa6342 100644
--- a/lib/libc/sys/mknod.2
+++ b/lib/libc/sys/mknod.2
@@ -42,25 +42,19 @@
.Ft int
.Fn mknod "const char *path" "mode_t mode" "dev_t dev"
.Sh DESCRIPTION
-The device special file
+The filesystem node
.Fa path
-is created with the major and minor
-device numbers extracted from
-.Fa mode.
-The access permissions of
-.Fa path
-are descendant from the
-.Xr umask 2
-of the parent process.
+is created with the file type and access permissions specified in
+.Fa mode .
+The access permissions are modified by the process's umask value.
.Pp
If
.Fa mode
indicates a block or character special file,
.Fa dev
-is a configuration dependent specification of a character or block
-I/O device and the superblock of the device. If
-.Fa mode
-does not indicate a block special or character special device,
+is a configuration dependent specification denoting a particular device
+on the system.
+Otherwise,
.Fa dev
is ignored.
.Pp
@@ -77,8 +71,6 @@ will fail and the file will be not created if:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -119,9 +111,11 @@ points outside the process's allocated address space.
.El
.Sh SEE ALSO
.Xr chmod 2 ,
+.Xr mkfifo 2 ,
.Xr stat 2 ,
.Xr umask 2
.Sh HISTORY
A
-.Nm
-function call appeared in Version 6 AT&T UNIX.
+.Fn mknod
+function call appeared in
+.At v6 .
diff --git a/lib/libc/sys/mlock.2 b/lib/libc/sys/mlock.2
index 90bb7c7..15ce741 100644
--- a/lib/libc/sys/mlock.2
+++ b/lib/libc/sys/mlock.2
@@ -47,7 +47,7 @@
.Fn munlock "caddr_t addr" "size_t len"
.Sh DESCRIPTION
The
-.Nm mlock
+.Fn mlock
system call
locks into memory the physical pages associated with the virtual address
range starting at
@@ -56,9 +56,9 @@ for
.Fa len
bytes.
The
-.Nm munlock
+.Fn munlock
call unlocks pages previously locked by one or more
-.Nm mlock
+.Fn mlock
calls.
For both, the
.Fa addr
@@ -70,7 +70,7 @@ to be so.
The entire range must be allocated.
.Pp
After an
-.Nm mlock
+.Fn mlock
call, the indicated pages will cause neither a non-resident page
nor address-translation fault until they are unlocked.
They may still cause protection-violation faults or TLB-miss faults on
@@ -81,12 +81,12 @@ Multiple processes may have the same physical pages locked via their own
virtual address mappings.
A single process may likewise have pages multiply-locked via different virtual
mappings of the same pages or via nested
-.Nm mlock
+.Fn mlock
calls on the same address range.
Unlocking is performed explicitly by
-.Nm munlock
+.Fn munlock
or implicitly by a call to
-.Nm munmap
+.Fn munmap
which deallocates the unmapped address range.
Locked mappings are not inherited by the child process after a
.Xr fork 2 .
@@ -94,7 +94,7 @@ Locked mappings are not inherited by the child process after a
Since physical memory is a potentially scarce resource, processes are
limited in how much they can lock down.
A single process can
-.Nm mlock
+.Fn mlock
the minimum of
a system-wide ``wired pages'' limit and
the per-process
@@ -138,11 +138,11 @@ Some portion of the indicated address range is not locked.
.Xr getpagesize 3
.Sh BUGS
Unlike The Sun implementation, multiple
-.Nm mlock
+.Fn mlock
calls on the same address range require the corresponding number of
-.Nm munlock
+.Fn munlock
calls to actually unlock the pages, i.e.
-.Nm mlock
+.Fn mlock
nests.
This should be considered a consequence of the implementation
and not a feature.
@@ -158,4 +158,5 @@ The
.Fn mlock
and
.Fn munlock
-functions first appeared in 4.4BSD.
+functions first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/mmap.2 b/lib/libc/sys/mmap.2
index 7313134..17a3603 100644
--- a/lib/libc/sys/mmap.2
+++ b/lib/libc/sys/mmap.2
@@ -31,7 +31,7 @@
.\"
.\" @(#)mmap.2 8.4 (Berkeley) 5/11/95
.\"
-.Dd "May 11, 1995"
+.Dd May 11, 1995
.Dt MMAP 2
.Os BSD 4
.Sh NAME
@@ -44,7 +44,7 @@
.Fn mmap "caddr_t addr" "size_t len" "int prot" "int flags" "int fd" "off_t offset"
.Sh DESCRIPTION
The
-.Nm mmap
+.Fn mmap
function causes the pages starting at
.Fa addr
and continuing for at most
@@ -113,7 +113,7 @@ parameter is ignored.
Do not permit the system to select a different address than the one
specified.
If the specified address cannot be used,
-.Nm mmap
+.Fn mmap
will fail.
If MAP_FIXED is specified,
.Fa addr
@@ -124,7 +124,7 @@ Notify the kernel that the region may contain semaphores and that special
handling may be necessary.
.It Dv MAP_INHERIT
Permit regions to be inherited across
-.Xr exec 2
+.Xr execve 2
system calls.
.It Dv MAP_PRIVATE
Modifications are private.
@@ -147,9 +147,9 @@ the file descriptor argument specifies a file or device to which swapping
should be done.
.Sh RETURN VALUES
Upon successful completion,
-.Nm mmap
+.Fn mmap
returns a pointer to the mapped region.
-Otherwise, a value of -1 is returned and
+Otherwise, a value of MAP_FAILED is returned and
.Va errno
is set to indicate the error.
.Sh ERRORS
@@ -179,25 +179,27 @@ was not open for writing.
.Fa Fd
is not a valid open file descriptor.
.It Bq Er EINVAL
-.\"One of
-.\".Dv MAP_ANON
-.\"or
-.\".Dv MAP_FILE
-.\"was not specified as part of the
-.\".Fa flags
-.\"parameter.
.Dv MAP_FIXED
was specified and the
.Fa addr
-parameter was not page aligned or was outside of the
-valid address range for a process.
-.Dv MAP_ANON was specified and
+parameter was not page aligned, or part of the desired address space
+resides out of the valid address space for a user process.
+.It Bq Er EINVAL
+.Fa Len
+was negative.
+.It Bq Er EINVAL
+.Dv MAP_ANON
+was specified and the
+.Fa fd
+parameter was not -1.
+.It Bq Er EINVAL
+.Dv MAP_ANON
+has not been specified and
.Fa fd
-was not \-1.
-.Fa Fd
did not reference a regular or character special file.
-.Fa Len
-was less than zero.
+.It Bq Er EINVAL
+.Fa Offset
+was not page-aligned. (See BUGS below.)
.It Bq Er ENOMEM
.Dv MAP_FIXED
was specified and the
@@ -206,9 +208,34 @@ parameter wasn't available.
.Dv MAP_ANON
was specified and insufficient memory was available.
.Sh "SEE ALSO"
-.Xr getpagesize 2 ,
+.Xr madvise 2 ,
+.Xr mincore 2 ,
+.Xr mlock 2 ,
+.Xr mprotect 2 ,
.Xr msync 2 ,
+.Xr munlock 2 ,
.Xr munmap 2 ,
-.Xr mprotect 2 ,
-.Xr madvise 2 ,
-.Xr mincore 2
+.Xr getpagesize 3
+.Sh BUGS
+.Ar len
+is limited to 2GB. Mmapping slightly more than 2GB doesn't work, but
+it is possible to map a window of size (filesize % 2GB) for file sizes
+of slightly less than 2G, 4GB, 6GB and 8GB.
+.Pp
+The limit is imposed for a variety of reasons. Most of them have to do
+with
+.Tn FreeBSD
+not wanting to use 64 bit offsets in the VM system due to
+the extreme performance penalty. So
+.Tn FreeBSD
+uses 32bit page indexes and
+this gives
+.Tn FreeBSD
+a maximum of 8TB filesizes. It's actually bugs in
+the filesystem code that causes the limit to be further restricted to
+1TB (loss of precision when doing blockno calculations).
+.Pp
+Another reason for the 2GB limit is that filesystem metadata can
+reside at negative offsets.
+.Pp
+We currently can only deal with page aligned file offsets.
diff --git a/lib/libc/sys/mount.2 b/lib/libc/sys/mount.2
index 0d95386..e42b8ff 100644
--- a/lib/libc/sys/mount.2
+++ b/lib/libc/sys/mount.2
@@ -42,7 +42,7 @@
.Fd #include <sys/param.h>
.Fd #include <sys/mount.h>
.Ft int
-.Fn mount "int type" "const char *dir" "int flags" "caddr_t data"
+.Fn mount "const char *name" "const char *dir" "int flags" "void *data"
.Ft int
.Fn unmount "const char *dir" "int flags"
.Sh DESCRIPTION
@@ -83,10 +83,20 @@ Even the super-user may not write on it.
Do not allow files to be executed from the filesystem.
.It Dv MNT_NOSUID
Do not honor setuid or setgid bits on files when executing them.
+.It Dv MNT_NOATIME
+Disable update of file access times.
.It Dv MNT_NODEV
Do not interpret special files on the filesystem.
.It Dv MNT_SYNCHRONOUS
All I/O to the filesystem should be done synchronously.
+.It Dv MNT_ASYNC
+All I/O to the filesystem should be done asynchronously.
+.It Dv MNT_WANTRDWR
+Upgrade a mounted read-only filesystem to read-write if MNT_UPDATE
+is also specified.
+.It Dv MNT_FORCE
+Fore a read-write mount even if the filesystem appears to be unclean.
+Dangerous.
.El
.Pp
The flag
@@ -97,7 +107,12 @@ This allows the mount flags to be changed without requiring
that the filesystem be unmounted and remounted.
Some filesystems may not allow all flags to be changed.
For example,
-most filesystems will not allow a change from read-write to read-only.
+many filesystems will not allow a change from read-write to read-only.
+.Pp
+The flag
+.Dv MNT_RELOAD
+causes the vfs subsystem to update its data structures pertaining to
+the specified already mounted filesystem.
.Pp
The
.Fa type
@@ -133,8 +148,9 @@ The
.Fa flags
argument may specify
.Dv MNT_FORCE
-to specify that the filesystem should be forcibly unmounted even if files are
-still active.
+to specify that the filesystem should be forcibly unmounted or made read-only
+(if MNT_UPDATE and MNT_RDONLY are also specified)
+even if files are still active.
Active special devices continue to work,
but any further accesses to any other active files result in errors
even if the filesystem is later remounted.
@@ -146,14 +162,16 @@ and the variable
.Va errno
is set to indicate the error.
.Pp
-.Nm Umount
-returns the value 0 if the umount succeeded; otherwise -1 is returned
+The
+.Fn umount
+function returns the value 0 if the umount succeeded; otherwise -1 is returned
and the variable
.Va errno
is set to indicate the error.
.Sh ERRORS
-.Fn Mount
-will fail when one of the following occurs:
+The
+.Fn mount
+function will fail when one of the following occurs:
.Bl -tag -width [ENOTBLK]
.It Bq Er EPERM
The caller is not the super-user.
@@ -173,8 +191,6 @@ is not a directory,
or a path prefix of
.Ar special
is not a directory.
-.It Bq Er EINVAL
-A pathname contains a character with the high-order bit set.
.It Bq Er EBUSY
Another process currently holds a reference to
.Fa dir .
@@ -250,8 +266,9 @@ cylinder group information.
points outside the process's allocated address space.
.El
.Pp
-.Nm Umount
-may fail with one of the following errors:
+The
+.Fn umount
+function may fail with one of the following errors:
.Bl -tag -width [ENOTBLK]
.It Bq Er EPERM
The caller is not the super-user.
@@ -283,13 +300,15 @@ or
mount can also fail if the maximum number of filesystems are currently
mounted.
.Sh SEE ALSO
+.Xr mfs 8 ,
.Xr mount 8 ,
-.Xr umount 8 ,
-.Xr sysctl 8
+.Xr sysctl 8 ,
+.Xr umount 8
.Sh BUGS
Some of the error codes need translation to more obvious messages.
.Sh HISTORY
.Fn Mount
and
.Fn umount
-function calls appeared in Version 6 AT&T UNIX.
+function calls appeared in
+.At v6 .
diff --git a/lib/libc/sys/mprotect.2 b/lib/libc/sys/mprotect.2
index bb2b9ad..d4e28d7 100644
--- a/lib/libc/sys/mprotect.2
+++ b/lib/libc/sys/mprotect.2
@@ -38,7 +38,10 @@
.Nm mprotect
.Nd control the protection of pages
.Sh SYNOPSIS
-.Fn mprotect "caddr_t addr" "int len" "int prot"
+.Fd #include <sys/types.h>
+.Fd #include <sys/mman.h>
+.Ft int
+.Fn mprotect "caddr_t addr" "size_t len" "int prot"
.Sh DESCRIPTION
The
.Fn mprotect
@@ -47,12 +50,38 @@ changes the specified pages to have protection
.Fa prot .
Not all implementations will guarantee protection on a page basis;
the granularity of protection changes may be as large as an entire region.
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn mprotect
+returns 0. Otherwise a value of -1 is returned
+and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+The
+.Fn mprotect
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The virtual address range specified by the
+.Fa addr
+and
+.Fa len
+arguments is not valid.
+.It Bq Er EACCES
+The calling process was not allowed to change
+the protection to the value specified by
+the
+.Fa prot
+argument.
+.El
.Sh SEE ALSO
-.Xr msync 2 ,
-.Xr munmap 2 ,
.Xr madvise 2 ,
-.Xr mincore 2
+.Xr mincore 2 ,
+.Xr msync 2 ,
+.Xr munmap 2
.Sh HISTORY
The
.Fn mprotect
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/msync.2 b/lib/libc/sys/msync.2
index 2e648c4..425a507 100644
--- a/lib/libc/sys/msync.2
+++ b/lib/libc/sys/msync.2
@@ -38,7 +38,10 @@
.Nm msync
.Nd synchronize a mapped region
.Sh SYNOPSIS
-.Fn msync "caddr_t addr" "int len"
+.Fd #include <sys/types.h>
+.Fd #include <sys/mman.h>
+.Ft int
+.Fn msync "caddr_t addr" "size_t len" "int flags"
.Sh DESCRIPTION
The
.Fn msync
@@ -57,34 +60,38 @@ is non-zero, only the pages containing
and
.Fa len
succeeding locations will be examined.
-Any required synchronization of memory caches
-will also take place at this time.
-Filesystem operations on a file that is mapped for shared modifications
-are unpredictable except after an
-.Fn msync .
+The
+.Fa flags
+argument may be specified as follows:
+.Bd -literal
+MS_ASYNC Return immediately (not currently implemented)
+MS_INVALIDATE Invalidate all cached data
+.Ed
+.Sh RETURN VALUES
+If any errors occur, -1 is returned and errno is set to indicate the
+error. Otherwise, a 0 value is returned.
.Sh ERRORS
-The following errors may be reported:
+.Fn msync
+will fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
-The
-.Fa addr
-parameter was not page aligned.
-.It Bq Er EINVAL
-The
.Fa addr
-parameter did not specify an address part of a mapped region.
+is not a multiple of the hardware page size.
.It Bq Er EINVAL
-The
.Fa len
-parameter was negative.
+is too large or negative.
+.It Bq Er EINVAL
+.Fa flags
+was both MS_ASYNC and MS_INVALIDATE. Only one of these flags is allowed.
.It Bq Er EIO
An I/O error occured while writing to the file system.
.Sh SEE ALSO
.Xr madvise 2 ,
-.Xr munmap 2 ,
+.Xr mincore 2 ,
.Xr mprotect 2 ,
-.Xr mincore 2
+.Xr munmap 2
.Sh HISTORY
The
.Fn msync
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/munmap.2 b/lib/libc/sys/munmap.2
index 97692af..ffa2371 100644
--- a/lib/libc/sys/munmap.2
+++ b/lib/libc/sys/munmap.2
@@ -38,6 +38,9 @@
.Nm munmap
.Nd remove a mapping
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/mman.h>
+.Ft int
.Fn munmap "caddr_t addr" "size_t len"
.Sh DESCRIPTION
The
@@ -48,7 +51,7 @@ and causes further references to addresses within the range
to generate invalid memory references.
.Sh RETURN VALUES
Upon successful completion,
-.Nm munmap
+.Fn munmap
returns zero.
Otherwise, a value of -1 is returned and
.Va errno
@@ -66,13 +69,14 @@ parameter was negative, or
some part of the region being unmapped is outside the
valid address range for a process.
.Sh "SEE ALSO"
-.Xr getpagesize 2 ,
+.Xr madvise 2 ,
+.Xr mincore 2 ,
+.Xr mprotect 2 ,
.Xr msync 2 ,
.Xr munmap 2 ,
-.Xr mprotect 2 ,
-.Xr madvise 2 ,
-.Xr mincore 2
+.Xr getpagesize 3
.Sh HISTORY
The
.Fn munmap
-function first appeared in 4.4BSD.
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/nanosleep.2 b/lib/libc/sys/nanosleep.2
new file mode 100644
index 0000000..598ce1b
--- /dev/null
+++ b/lib/libc/sys/nanosleep.2
@@ -0,0 +1,119 @@
+.\" $Id: nanosleep.2,v 1.1 1997/05/12 12:15:35 peter Exp $
+.\" $OpenBSD: nanosleep.2,v 1.1 1997/04/20 20:56:20 tholo Exp $
+.\" $NetBSD: nanosleep.2,v 1.1 1997/04/17 18:12:02 jtc Exp $
+.\"
+.\" Copyright (c) 1986, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\" @(#)sleep.3 8.1 (Berkeley) 6/4/93
+.\"
+.Dd April 17, 1997
+.Dt NANOSLEEP 2
+.Os
+.Sh NAME
+.Nm nanosleep ,
+.Nm signanosleep
+.Sh SYNOPSIS
+.Fd #include <time.h>
+.Ft int
+.Fn nanosleep "const struct timespec *rqtp" "struct timespec *rmtp"
+.Pp
+.Fd #include <signal.h>
+.Fd #include <time.h>
+.Ft int
+.Fn signanosleep "const struct timespec *rqtp" "struct timespec *rmtp" "sigset_t *mask"
+.Sh DESCRIPTION
+.Fn Nanosleep
+causes the process to sleep for the specified time. An unmasked signal will
+cause it to terminate the sleep early, regardless of the
+.Dv SA_RESTART
+value on the interrupting signal.
+.Pp
+The
+.Fn signanosleep
+function temporarily (and atomically) sets the signal mask of the process
+for the duration of the system call so that specific signals can be
+nominated to cause an early termination of the sleep.
+.Sh RETURN VALUE
+If the
+.Fn nanosleep
+function returns because the requested time has elapsed, the value
+returned will be zero.
+.Pp
+If the
+.Fn nanosleep
+function returns due to the delivery of a signal, the value returned
+will be the -1, and the global variable
+.Va errno
+will be set to indicate the interruption.
+If
+.Fa rmtp
+is
+.Pf non- Dv NULL ,
+the timespec structure it references is updated to contain the
+unslept amount (the request time minus the time actually slept).
+.Sh ERRORS
+If any of the following conditions occur, the
+.Nm
+function shall return -1 and set
+.Va errno
+to the corresponding value.
+.Bl -tag -width Er
+.It Bq Er EFAULT
+Either
+.Fa rqtp
+or
+.Fa rmtp
+points to memory that is not a valid part of the process
+address space.
+.It Bq Er EINTR
+.Nm
+was interrupted by the delivery of a signal.
+.It Bq Er EINVAL
+.Fa rqtp
+specified a nanosecond value less than zero or greater than 1000 million.
+.It Bq Er ENOSYS
+.Nm
+is not supported by this implementation.
+.El
+.Sh SEE ALSO
+.Xr sigsuspend 2
+.Xr sleep 3
+.Sh STANDARDS
+The
+.Fn nanosleep
+function conforms to
+.St -p1003.1b-93 .
+.Pp
+The
+.Fn signanosleep
+function is an extenstion that first appeared in
+.Fx 3.0
diff --git a/lib/libc/sys/nfssvc.2 b/lib/libc/sys/nfssvc.2
index 0c8038f..b2f481e 100644
--- a/lib/libc/sys/nfssvc.2
+++ b/lib/libc/sys/nfssvc.2
@@ -38,8 +38,11 @@
.Nm nfssvc
.Nd NFS services
.Sh SYNOPSIS
-.Fd #include <unistd.h>
+.Fd #include <sys/param.h>
+.Fd #include <sys/mount.h>
+.Fd #include <nfs/rpcv2.h>
.Fd #include <nfs/nfs.h>
+.Fd #include <unistd.h>
.Ft int
.Fn nfssvc "int flags" "void *argstructp"
.Sh DESCRIPTION
@@ -86,10 +89,13 @@ struct nfsd_cargs {
uid_t ncd_authuid; /* Effective uid */
int ncd_authtype; /* Type of authenticator */
int ncd_authlen; /* Length of authenticator string */
- char *ncd_authstr; /* Authenticator string */
+ u_char *ncd_authstr; /* Authenticator string */
+ int ncd_verflen; /* and the verifier */
+ u_char *ncd_verfstr;
+ NFSKERBKEY_T ncd_key; /* Session key */
};
.Ed
-.sp
+.Pp
structure.
The initial call has only the
.Dv NFSSVC_MNTD
@@ -135,10 +141,15 @@ struct nfsd_srvargs {
u_long nsd_haddr; /* Ip address of client */
struct ucred nsd_cr; /* Cred. uid maps to */
int nsd_authlen; /* Length of auth string (ret) */
- char *nsd_authstr; /* Auth string (ret) */
+ u_char *nsd_authstr; /* Auth string (ret) */
+ int nsd_verflen; /* and the verfier */
+ u_char *nsd_verfstr;
+ struct timeval nsd_timestamp; /* timestamp from verifier */
+ u_long nsd_ttl; /* credential ttl (sec) */
+ NFSKERBKEY_T nsd_key; /* Session key */
};
.Ed
-.sp
+.Pp
to enter the kernel as an
.Xr nfsd 8
daemon.
@@ -186,12 +197,12 @@ with the flag
and a pointer to a
.Bd -literal
struct nfsd_args {
- int sock; /* Socket to serve */
- caddr_t name; /* Client address for connection based sockets */
- int namelen; /* Length of name */
+ int sock; /* Socket to serve */
+ caddr_t name; /* Client address for connection based sockets */
+ int namelen;/* Length of name */
};
.Ed
-.sp
+.Pp
to pass a server side
.Tn NFS
socket into the kernel for servicing by the
@@ -199,7 +210,7 @@ socket into the kernel for servicing by the
daemons.
.Sh RETURN VALUES
Normally
-.Nm nfssvc
+.Fn nfssvc
does not return unless the server
is terminated by a signal when a value of 0 is returned.
Otherwise, -1 is returned and the global variable
@@ -215,16 +226,17 @@ as explained above.
The caller is not the super-user.
.El
.Sh SEE ALSO
-.Xr nfsd 8 ,
.Xr mount_nfs 8 ,
+.Xr nfsd 8 ,
.Xr nfsiod 8
.Sh HISTORY
The
-.Nm nfssvc
-function first appeared in 4.4BSD.
+.Fn nfssvc
+function first appeared in
+.Bx 4.4 .
.Sh BUGS
The
-.Nm nfssvc
+.Fn nfssvc
system call is designed specifically for the
.Tn NFS
support daemons and as such is specific to their requirements.
@@ -234,5 +246,5 @@ support, since
is not really an error.
Several fields of the argument structures are assumed to be valid and
sometimes to be unchanged from a previous call, such that
-.Nm nfssvc
+.Fn nfssvc
must be used with extreme care.
diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2
index dea59fc..11d2906 100644
--- a/lib/libc/sys/open.2
+++ b/lib/libc/sys/open.2
@@ -136,7 +136,7 @@ When a new file is created it is given the group of the directory
which contains it.
.Pp
The new descriptor is set to remain open across
-.Xr execve
+.Xr execve 2
system calls; see
.Xr close 2
and
@@ -146,6 +146,33 @@ The system imposes a limit on the number of file descriptors
open simultaneously by one process.
.Xr Getdtablesize 2
returns the current system limit.
+.Pp
+.Sh IMPLEMENTATION NOTES
+In the non-threaded library
+.Fn open
+is implemented as the
+.Va open
+syscall.
+.Pp
+In the threaded library, the
+.Va open
+syscall is assembled to
+.Fn _thread_sys_open
+and
+.Fn open
+is implemented as a function which disables thread rescheduling
+and calls
+.Fn _thread_sys_open .
+Before returning,
+.Fn open
+enables thread rescheduling.
+.Sh RETURN VALUES
+If successful,
+.Fn open
+returns a non-negative integer, termed a file descriptor.
+It returns -1 on failure, and sets
+.Va errno
+to indicate the error.
.Sh ERRORS
The named file is opened unless:
.Bl -tag -width Er
@@ -188,7 +215,7 @@ special file, and the device associated with this special file
does not exist.
.It Bq Er EINTR
The
-.Nm
+.Fn open
operation was interrupted by a signal.
.It Bq Er EOPNOTSUPP
.Dv O_SHLOCK
@@ -249,9 +276,10 @@ An attempt was made to open a socket (not currently implemented).
.Xr getdtablesize 2 ,
.Xr lseek 2 ,
.Xr read 2 ,
-.Xr write 2 ,
-.Xr umask 2
+.Xr umask 2 ,
+.Xr write 2
.Sh HISTORY
An
-.Nm
-function call appeared in Version 6 AT&T UNIX.
+.Fn open
+function call appeared in
+.At v6 .
diff --git a/lib/libc/sys/pathconf.2 b/lib/libc/sys/pathconf.2
index 1b4fbc4..f8500e3 100644
--- a/lib/libc/sys/pathconf.2
+++ b/lib/libc/sys/pathconf.2
@@ -55,12 +55,12 @@ value of a configurable system limit or option variable associated
with a pathname or file descriptor.
.Pp
For
-.Nm pathconf ,
+.Fn pathconf ,
the
.Fa path
argument is the name of a file or directory.
For
-.Nm fpathconf ,
+.Fn fpathconf ,
the
.Fa fd
argument is an open file descriptor.
@@ -98,9 +98,9 @@ Returns the terminal character disabling value.
.El
.Sh RETURN VALUES
If the call to
-.Nm pathconf
+.Fn pathconf
or
-.Nm fpathconf
+.Fn fpathconf
is not successful, \-1 is returned and
.Va errno
is set appropriately.
@@ -111,9 +111,9 @@ is not modified.
Otherwise, the current variable value is returned.
.Sh ERRORS
If any of the following conditions occur, the
-.Nm pathconf
+.Fn pathconf
and
-.Nm fpathconf
+.Fn fpathconf
functions shall return -1 and set
.Va errno
to the corresponding value.
@@ -157,7 +157,8 @@ An I/O error occurred while reading from or writing to the file system.
.Xr sysctl 3
.Sh HISTORY
The
-.Nm pathconf
+.Fn pathconf
and
-.Nm fpathconf
-functions first appeared in 4.4BSD.
+.Fn fpathconf
+functions first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/pipe.2 b/lib/libc/sys/pipe.2
index 51b7364..d50c94f 100644
--- a/lib/libc/sys/pipe.2
+++ b/lib/libc/sys/pipe.2
@@ -48,12 +48,13 @@ function
creates a
.Em pipe ,
which is an object allowing
-unidirectional data flow,
+bidirectional data flow,
and allocates a pair of file descriptors.
-The first descriptor connects to the
+.Pp
+By convention, the first descriptor is normally used as the
.Em read end
of the pipe,
-and the second connects to the
+and the second is normally the
.Em write end ,
so that data written to
.Fa fildes[1]
@@ -69,7 +70,7 @@ the read end of the pipe.
The pipe itself persists until all its associated descriptors are
closed.
.Pp
-A pipe whose read or write end has been closed is considered
+A pipe that has had an end closed is considered
.Em widowed .
Writing on such a pipe causes the writing process to receive
a
@@ -79,9 +80,10 @@ Widowing a pipe is the only way to deliver end-of-file to a reader:
after the reader consumes any buffered data, reading a widowed pipe
returns a zero count.
.Pp
-Pipes are really a special case of the
-.Xr socketpair 2
-call and, in fact, are implemented as such in the system.
+The bidirectional nature of this implementation of pipes is not
+portable to older systems, so it is recommended to use the convention
+for using the endpoints in the traditional manner when using a
+pipe in one direction.
.Sh RETURN VALUES
On successful creation of the pipe, zero is returned. Otherwise,
a value of -1 is returned and the variable
@@ -105,11 +107,13 @@ space.
.El
.Sh SEE ALSO
.Xr sh 1 ,
-.Xr read 2 ,
-.Xr write 2 ,
.Xr fork 2 ,
-.Xr socketpair 2
+.Xr read 2 ,
+.Xr socketpair 2 ,
+.Xr write 2
.Sh HISTORY
A
-.Nm
-function call appeared in Version 6 AT&T UNIX.
+.Fn pipe
+function call appeared in Version 3 AT&T UNIX.
+.Pp
+Bidirectional pipes were first used on Unix System V release 4.
diff --git a/lib/libc/sys/profil.2 b/lib/libc/sys/profil.2
index 670e343..100b8f4 100644
--- a/lib/libc/sys/profil.2
+++ b/lib/libc/sys/profil.2
@@ -33,14 +33,16 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)profil.2 8.1 (Berkeley) 6/4/93
+.\" $Id: profil.2,v 1.6 1997/04/11 18:47:07 bde Exp $
.\"
-.Dd "June 4, 1993"
+.Dd June 4, 1993
.Dt PROFIL 2
.Os
.Sh NAME
.Nm profil
.Nd control process profiling
.Sh SYNOPSIS
+.Fd #include <unistd.h>
.Ft int
.Fn profil "char *samples" "int size" "int offset" "int scale"
.Sh DESCRIPTION
@@ -49,10 +51,12 @@ The
function enables or disables
program counter profiling of the current process.
If profiling is enabled,
-then at every clock tick,
+then at every profiling clock tick,
the kernel updates an appropriate count in the
.Fa samples
buffer.
+The frequency of the profiling clock is recorded
+in the header in the profiling output file.
.Pp
The buffer
.Fa samples
@@ -62,7 +66,7 @@ bytes and is divided into
a series of 16-bit bins.
Each bin counts the number of times the program counter
was in a particular address range in the process
-when a clock tick occurred while profiling was enabled.
+when a profiling clock tick occurred while profiling was enabled.
For a given program counter address,
the number of the corresponding bin is given
by the relation:
@@ -115,8 +119,11 @@ contains an invalid address.
.El
.Sh SEE ALSO
.Xr gprof 1
-.\" .Sh HISTORY
-.\" wish I knew... probably v7.
+.Sh HISTORY
+A
+.Fn profil
+function call appeared in
+.At v7 .
.Sh BUGS
This routine should be named
.Fn profile .
diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2
new file mode 100644
index 0000000..48468a5
--- /dev/null
+++ b/lib/libc/sys/ptrace.2
@@ -0,0 +1,293 @@
+.\" $Id: ptrace.2,v 1.9 1997/02/22 15:04:13 peter Exp $
+.\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $
+.\"
+.\" This file is in the public domain.
+.Dd January 20, 1996
+.Dt PTRACE 2
+.Os FreeBSD 2
+.Sh NAME
+.Nm ptrace
+.Nd process tracing and debugging
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ptrace.h>
+.Ft int
+.Fn ptrace "int request" "pid_t pid" "caddr_t addr" "int data"
+.Sh DESCRIPTION
+.Fn ptrace
+provides tracing and debugging facilities. It allows one process (the
+.Em tracing
+process) to control another (the
+.Em traced
+process). Most of the time, the traced process runs normally, but when
+it receives a signal
+.Po
+see
+.Xr sigaction 2
+.Pc ,
+it stops. The tracing process is expected to notice this via
+.Xr wait 2
+or the delivery of a
+.Dv SIGCHLD
+signal, examine the state of the stopped process, and cause it to
+terminate or continue as appropriate.
+.Fn ptrace
+is the mechanism by which all this happens.
+.Pp
+The
+.Fa request
+argument specifies what operation is being performed; the meaning of
+the rest of the arguments depends on the operation, but except for one
+special case noted below, all
+.Fn ptrace
+calls are made by the tracing process, and the
+.Fa pid
+argument specifies the process ID of the traced process.
+.Fa request
+can be:
+.Bl -tag -width 12n
+.It Dv PT_TRACE_ME
+This request is the only one used by the traced process; it declares
+that the process expects to be traced by its parent. All the other
+arguments are ignored. (If the parent process does not expect to trace
+the child, it will probably be rather confused by the results; once the
+traced process stops, it cannot be made to continue except via
+.Eo \&
+.Fn ptrace
+.Ec \&.)
+When a process has used this request and calls
+.Xr execve 2
+or any of the routines built on it
+.Po
+such as
+.Xr execv 3
+.Pc ,
+it will stop before executing the first instruction of the new image.
+Also, any setuid or setgid bits on the executable being executed will
+be ignored.
+.It Dv PT_READ_I , Dv PT_READ_D
+These requests read a single
+.Li int
+of data from the traced process' address space. Traditionally,
+.Fn ptrace
+has allowed for machines with distinct address spaces for instruction
+and data, which is why there are two requests: conceptually,
+.Dv PT_READ_I
+reads from the instruction space and
+.Dv PT_READ_D
+reads from the data space. In the current
+.Tn FreeBSD
+implementation, these
+two requests are completely identical. The
+.Fa addr
+argument specifies the address (in the traced process' virtual address
+space) at which the read is to be done. This address does not have to
+meet any alignment constraints. The value read is returned as the
+return value from
+.Eo \&
+.Fn ptrace
+.Ec .
+.It Dv PT_WRITE_I , Dv PT_WRITE_D
+These requests parallel
+.Dv PT_READ_I
+and
+.Dv PT_READ_D ,
+except that they write rather than read. The
+.Fa data
+argument supplies the value to be written.
+.It Dv PT_READ_U
+This request reads an
+.Li int
+from the traced process' user structure. The
+.Fa addr
+argument specifies the location of the int relative to the base of the
+user structure; it will usually be an integer value cast to
+.Li caddr_t
+either explicitly or via the presence of a prototype for
+.Eo \&
+.Fn ptrace
+.Ec .
+Unlike
+.Dv PT_READ_I
+and
+.Dv PT_READ_D ,
+.Fa addr
+must be aligned on an
+.Li int
+boundary. The value read is returned as the return value from
+.Eo \&
+.Fn ptrace
+.Ec .
+.It Dv PT_WRITE_U
+This request writes an
+.Li int
+into the traced process' user structure.
+.Fa addr
+specifies the offset, just as for
+.Dv PT_READ_U ,
+and
+.Fa data
+specifies the value to be written, just as for
+.Dv PT_WRITE_I
+and
+.Dv PT_WRITE_D .
+.It Dv PT_CONTINUE
+The traced process continues execution.
+.Fa addr
+is an address specifying the place where execution is to be resumed (a
+new value for the program counter), or
+.Li (caddr_t)1
+to indicate that execution is to pick up where it left off.
+.Fa data
+provides a signal number to be delivered to the traced process as it
+resumes execution, or 0 if no signal is to be sent.
+.It Dv PT_KILL
+The traced process terminates, as if
+.Dv PT_CONTINUE
+had been used with
+.Dv SIGKILL
+given as the signal to be delivered.
+.It Dv PT_ATTACH
+This request allows a process to gain control of an otherwise unrelated
+process and begin tracing it. It does not need any cooperation from
+the to-be-traced process. In this case,
+.Fa pid
+specifies the process ID of the to-be-traced process, and the other two
+arguments are ignored. This request requires that the target process
+must have the same real UID as the tracing process, and that it must
+not be executing a setuid or setgid executable. (If the tracing
+process is running as root, these restrictions do not apply.) The
+tracing process will see the newly-traced process stop and may then
+control it as if it had been traced all along.
+.It Dv PT_DETACH
+This request is like PT_CONTINUE, except that it does not allow
+specifying an alternate place to continue execution, and after it
+succeeds, the traced process is no longer traced and continues
+execution normally.
+.El
+.Pp
+Additionally, machine-specific requests can exist. On the i386, these
+are:
+.Bl -tag -width 12n
+.It Dv PT_GETREGS
+This request reads the traced process' machine registers into the
+.Dq Li "struct reg"
+(defined in
+.Aq Pa machine/reg.h )
+pointed to by
+.Fa addr .
+.It Dv PT_SETREGS
+This request is the converse of
+.Dv PT_GETREGS ;
+it loads the traced process' machine registers from the
+.Dq Li "struct reg"
+(defined in
+.Aq Pa machine/reg.h )
+pointed to by
+.Fa addr .
+.It Dv PT_GETFPREGS
+This request reads the traced process' floating-point registers into
+the
+.Dq Li "struct fpreg"
+(defined in
+.Aq Pa machine/reg.h )
+pointed to by
+.Fa addr .
+.It Dv PT_SETFPREGS
+This request is the converse of
+.Dv PT_GETFPREGS ;
+it loads the traced process' floating-point registers from the
+.Dq Li "struct fpreg"
+(defined in
+.Aq Pa machine/reg.h )
+pointed to by
+.Fa addr .
+.El
+.Sh RETURN VALUES
+Some requests can cause
+.Fn ptrace
+to return
+.Li -1
+as a non-error value; to disambiguate,
+.Va errno
+can be set to 0 before the call and checked afterwards.
+.Sh ERRORS
+The
+.Fn ptrace
+function may fail if:
+.Bl -tag -width 4n
+.It Bq Er ESRCH
+.Bl -bullet -compact
+.It
+No process having the specified process ID exists.
+.El
+.It Bq Er EINVAL
+.Bl -bullet -compact
+.It
+A process attempted to use
+.Dv PT_ATTACH
+on itself.
+.It
+The
+.Fa request
+was not one of the legal requests.
+.It
+The
+.Fa addr
+to
+.Dv PT_READ_U
+or
+.Dv PT_WRITE_U
+was not
+.Li int Ns \&-aligned.
+.It
+The signal number (in
+.Fa data )
+to
+.Dv PT_CONTINUE
+was neither 0 nor a legal signal number.
+.It
+.Dv PT_GETREGS ,
+.Dv PT_SETREGS ,
+.Dv PT_GETFPREGS ,
+or
+.Dv PT_SETFPREGS
+was attempted on a process with no valid register set. (This is
+normally true only of system processes.)
+.El
+.It Bq Er EBUSY
+.Bl -bullet -compact
+.It
+.Dv PT_ATTACH
+was attempted on a process that was already being traced.
+.It
+A request attempted to manipulate a process that was being traced by
+some process other than the one making the request.
+.It
+A request (other than
+.Dv PT_ATTACH )
+specified a process that wasn't stopped.
+.El
+.It Bq Er EPERM
+.Bl -bullet -compact
+.It
+A request (other than
+.Dv PT_ATTACH )
+attempted to manipulate a process that wasn't being traced at all.
+.It
+An attempt was made to use
+.Dv PT_ATTACH
+on a process in violation of the requirements listed under
+.Dv PT_ATTACH
+above.
+.El
+.Sh SEE ALSO
+.Xr execve 2 ,
+.Xr sigaction 2 ,
+.Xr wait 2 ,
+.Xr execv 3
+.Sh HISTORY
+A
+.Fn ptrace
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/quotactl.2 b/lib/libc/sys/quotactl.2
index 1bcdb8b..fc7b667 100644
--- a/lib/libc/sys/quotactl.2
+++ b/lib/libc/sys/quotactl.2
@@ -41,7 +41,8 @@
.Nm quotactl
.Nd manipulate filesystem quotas
.Sh SYNOPSIS
-.Fd #include <ufs/quota.h> /* for ufs quotas */
+.Fd #include <sys/types.h>
+.Fd #include <ufs/ufs/quota.h>
.Ft int
.Fn quotactl "const char *path" "int cmd" "int id" "char *addr"
.Sh DESCRIPTION
@@ -156,8 +157,6 @@ The quota table cannot be expanded.
.It Bq Er EINVAL
.Fa Cmd
or the command type is invalid.
-.It Bq Er EINVAL
-A pathname contains a character with the high-order bit set.
.It Bq Er EACCES
In
.Dv Q_QUOTAON ,
@@ -208,6 +207,6 @@ and
.Xr getrlimit 2 .
.Sh HISTORY
The
-.Nm quotactl
+.Fn quotactl
function call appeared in
.Bx 4.3 Reno .
diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2
index b94341a..723c1bd 100644
--- a/lib/libc/sys/read.2
+++ b/lib/libc/sys/read.2
@@ -70,8 +70,8 @@ structure is defined as:
.Pp
.Bd -literal -offset indent -compact
struct iovec {
- void *iov_base;
- size_t iov_len;
+ char *iov_base; /* Base address. */
+ size_t iov_len; /* Length. */
};
.Ed
.Pp
@@ -107,6 +107,53 @@ The system guarantees to read the number of bytes requested if
the descriptor references a normal file that has that many bytes left
before the end-of-file, but in no other case.
.Pp
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn read
+is implemented as the
+.Va read
+syscall.
+.Pp
+In the threaded library, the
+.Va read
+syscall is assembled to
+.Fn _thread_sys_read
+and
+.Fn read
+is implemented as a function which locks
+.Va d
+for read, then calls
+.Fn _thread_sys_read .
+If the call to
+.Fn _thread_sys_read
+would block, a context switch is performed. Before returning,
+.Fn read
+unlocks
+.Va d .
+.Pp
+In the non-threaded library
+.Fn readv
+is implemented as the
+.Va readv
+syscall.
+.Pp
+In the threaded library, the
+.Va readv
+syscall is assembled to
+.Fn _thread_sys_readv
+and
+.Fn readv
+is implemented as a function which locks
+.Va d
+for read, then calls
+.Fn _thread_sys_readv .
+If the call to
+.Fn _thread_sys_readv
+would block, a context switch is performed. Before returning,
+.Fn readv
+unlocks
+.Va d .
.Sh RETURN VALUES
If successful, the
number of bytes actually read is returned. Upon reading end-of-file,
@@ -173,9 +220,10 @@ points outside the process's allocated address space.
.Xr socket 2 ,
.Xr socketpair 2
.Sh STANDARDS
-.Fn Read
-is expected to conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn read
+function call is expected to conform to
+.St -p1003.1-90 .
.Sh HISTORY
The
.Fn readv
@@ -183,7 +231,6 @@ function call
appeared in
.Bx 4.2 .
A
-.Nm read
-function call
-appeared in
-Version 6 AT&T UNIX.
+.Fn read
+function call appeared in
+.At v6 .
diff --git a/lib/libc/sys/readlink.2 b/lib/libc/sys/readlink.2
index 4827110..8443de2 100644
--- a/lib/libc/sys/readlink.2
+++ b/lib/libc/sys/readlink.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)readlink.2 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt READLINK 2
@@ -49,8 +50,9 @@ in the buffer
.Fa buf ,
which has size
.Fa bufsiz .
-.Nm Readlink
-does not append a
+The
+.Fn readlink
+function does not append a
.Dv NUL
character to
.Fa buf .
@@ -65,8 +67,6 @@ will fail if:
.Bl -tag -width ENAMETOOLONG
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -85,12 +85,12 @@ An I/O error occurred while reading from the file system.
extends outside the process's allocated address space.
.El
.Sh SEE ALSO
-.Xr stat 2 ,
.Xr lstat 2 ,
-.Xr symlink 2
-.Xr symlink 7 ,
+.Xr stat 2 ,
+.Xr symlink 2 ,
+.Xr symlink 7
.Sh HISTORY
The
-.Nm
+.Fn readlink
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/reboot.2 b/lib/libc/sys/reboot.2
index 317c139..1eda9b3 100644
--- a/lib/libc/sys/reboot.2
+++ b/lib/libc/sys/reboot.2
@@ -62,7 +62,7 @@ The default, causing the system to reboot in its usual fashion.
Interpreted by the bootstrap program itself, causing it to
prompt on the console as to what file should be booted.
Normally, the system is booted from the file
-.Dq Em xx Ns No (0,0)vmunix ,
+.Dq Em xx Ns No (0,0)kernel ,
where
.Em xx
is the default disk name,
@@ -81,6 +81,9 @@ for more information.
.It Dv RB_HALT
the processor is simply halted; no reboot takes place.
This option should be used with caution.
+.It Dv RB_POWEROFF
+After halting, the shutdown code will do what it can to turn
+of the power. This requires hardware support.
.It Dv RB_INITNAME
An option allowing the specification of an init program (see
.Xr init 8 )
@@ -123,7 +126,7 @@ program in the newly booted system.
When no options are given (i.e.,
.Dv RB_AUTOBOOT
is used), the system is
-rebooted from file ``vmunix'' in the root file system of unit 0
+rebooted from file ``kernel'' in the root file system of unit 0
of a disk chosen in a processor specific way.
An automatic consistency check of the disks is normally performed
(see
@@ -140,7 +143,6 @@ variable
The caller is not the super-user.
.El
.Sh SEE ALSO
-.Xr kadb 4 ,
.Xr crash 8 ,
.Xr halt 8 ,
.Xr init 8 ,
@@ -153,6 +155,6 @@ nor
.Dv RB_KDB .
.Sh HISTORY
The
-.Nm
+.Fn reboot
function call appeared in
.Bx 4.0 .
diff --git a/lib/libc/sys/recv.2 b/lib/libc/sys/recv.2
index 9ed24a3..fdf02e3 100644
--- a/lib/libc/sys/recv.2
+++ b/lib/libc/sys/recv.2
@@ -200,6 +200,34 @@ and
set to
.Dv SCM_RIGHTS .
.Pp
+Process credentials can also be passed as ancillary data for
+.Dv AF_UNIX
+domain sockets using a
+.Fa cmsg_type
+of
+.Dv SCM_CREDS.
+In this case,
+.Fa cmsg_data
+should be a structure of type
+.Fa cmsgcred ,
+which is defined in
+.Ao Pa sys/socket.h Ac
+as follows:
+.Pp
+.Bd -literal
+struct cmsgcred {
+ pid_t cmcred_pid; /* PID of sending process */
+ uid_t cmcred_uid; /* real UID of sending process */
+ uid_t cmcred_euid; /* effective UID of sending process */
+ gid_t cmcred_gid; /* real GID of sending process */
+ short cmcred_ngroups; /* number or groups */
+ gid_t cmcred_groups[CMGROUP_MAX]; /* groups */
+};
+.Ed
+.Pp
+The kernel will fill in the credential information of the sending process
+and deliver it to the receiver.
+.Pp
The
.Fa msg_flags
field is set on return according to the message received.
@@ -252,12 +280,12 @@ address space.
.El
.Sh SEE ALSO
.Xr fcntl 2 ,
+.Xr getsockopt 2 ,
.Xr read 2 ,
.Xr select 2 ,
-.Xr getsockopt 2 ,
.Xr socket 2
.Sh HISTORY
The
-.Nm
+.Fn recv
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/rename.2 b/lib/libc/sys/rename.2
index be47d58..d9e1b83 100644
--- a/lib/libc/sys/rename.2
+++ b/lib/libc/sys/rename.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)rename.2 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt RENAME 2
@@ -105,8 +106,6 @@ indicates the reason for the failure.
will fail and neither of the argument files will be
affected if:
.Bl -tag -width ENAMETOOLONG
-.It Bq Er EINVAL
-Either pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of either pathname exceeded 255 characters,
or the entire length of either path name exceeded 1023 characters.
@@ -191,9 +190,10 @@ or
is a directory and is not empty.
.El
.Sh SEE ALSO
-.Xr open 2
+.Xr open 2 ,
.Xr symlink 7
.Sh STANDARDS
-.Fn Rename
-conforms to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn rename
+function call is expected to conform to
+.St -p1003.1-90 .
diff --git a/lib/libc/sys/revoke.2 b/lib/libc/sys/revoke.2
index e782874..b64c9dc 100644
--- a/lib/libc/sys/revoke.2
+++ b/lib/libc/sys/revoke.2
@@ -41,11 +41,12 @@
.Nm revoke
.Nd revoke file access
.Sh SYNOPSIS
+.Fd #include <unistd.h>
.Ft int
-.Fn revoke "char *path"
+.Fn revoke "const char *path"
.Sh DESCRIPTION
The
-.Nm revoke
+.Fn revoke
function invalidates all current open file descriptors in the system
for the file named by
.Fa path .
@@ -63,7 +64,7 @@ is called as if all open references to the file had been closed.
.Pp
Access to a file may be revoked only by its owner or the super user.
The
-.Nm revoke
+.Fn revoke
function is currently supported only for block and character special
device files.
It is normally used to prepare a terminal device for a new login session,
@@ -100,6 +101,6 @@ The caller is neither the owner of the file nor the super user.
.Xr close 2
.Sh HISTORY
The
-.Nm revoke
+.Fn revoke
function was introduced in
.Bx 4.3 Reno .
diff --git a/lib/libc/sys/rfork.2 b/lib/libc/sys/rfork.2
new file mode 100644
index 0000000..4a54149
--- /dev/null
+++ b/lib/libc/sys/rfork.2
@@ -0,0 +1,137 @@
+.\"
+.\" This manual page is taken directly from Plan9, and modified to
+.\" describe the actual BSD implementation. Permission for
+.\" use of this page comes from Rob Pike <rob@plan9.att.com>.
+.\"
+.Dd Jan 12, 1996
+.Dt RFORK 2
+.Os
+.Sh NAME
+.Nm rfork
+.Nd manipulate process resources
+.Sh SYNOPSIS
+.Fd #include <unistd.h>
+.Ft int
+.Fn rfork "int flags"
+.Sh DESCRIPTION
+Forking, vforking or rforking are the only ways new processes are created.
+The
+.Fa flags
+argument to
+.Fn rfork
+selects which resources of the
+invoking process (parent) are shared
+by the new process (child) or initialized to
+their default values.
+The resources include
+the open file descriptor table (which, when shared, permits processes
+to open and close files for other processes),
+and open files.
+.Fa Flags
+is the logical OR of some subset of:
+.Bl -tag -width "RFCNAMEG" -compact -offset indent
+.It RFPROC
+If set a new process is created; otherwise changes affect the
+current process.
+The current implementation requires this flag to always be set.
+.It RFNOWAIT
+If set, the child process will be dissociated from the parent. Upon
+exit the child will not leave a status for the parent to collect.
+See
+.Xr wait 2 .
+.It RFFDG
+If set, the invoker's file descriptor table (see
+.Xr intro 2
+) is copied; otherwise the two processes share a
+single table.
+.It RFCFDG
+If set, the new process starts with a clean file descriptor table.
+Is mutually exclusive with
+.Dv RFFDG .
+.It RFMEM
+If set, the kernel will force sharing of the entire address space.
+The child
+will then inherit all the shared segments the parent process owns. Other segment
+types will be unaffected. Subsequent forks by the parent will then
+propagate the shared data and bss between children. The stack segment
+is always split. May be set only with
+.Dv RFPROC .
+.El
+.Pp
+File descriptors in a shared file descriptor table are kept
+open until either they are explicitly closed
+or all processes sharing the table exit.
+.Pp
+If
+.Dv RFPROC
+is set, the
+value returned in the parent process
+is the process id
+of the child process; the value returned in the child is zero.
+Without
+.Dv RFPROC ,
+the return value is zero.
+Process id's range from 1 to the maximum integer
+.Ft ( int )
+value.
+.Fn Rfork
+will sleep, if necessary, until required process resources are available.
+.Pp
+.Fn Fork
+can be implemented as a call to
+.Fn rfork "RFFDG|RFPROC"
+but isn't for backwards compatibility.
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn rfork
+returns a value
+of 0 to the child process and returns the process ID of the child
+process to the parent process. Otherwise, a value of -1 is returned
+to the parent process, no child process is created, and the global
+variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn Rfork
+will fail and no child process will be created if:
+.Bl -tag -width [EAGAIN]
+.It Bq Er EAGAIN
+The system-imposed limit on the total
+number of processes under execution would be exceeded.
+The limit is given by the
+.Xr sysctl 3
+MIB variable
+.Dv KERN_MAXPROC .
+(The limit is actually one less than this
+except for the super user).
+.It Bq Er EAGAIN
+The user is not the super user, and
+the system-imposed limit
+on the total number of
+processes under execution by a single user would be exceeded.
+The limit is given by the
+.Xr sysctl 3
+MIB variable
+.Dv KERN_MAXPROCPERUID .
+.It Bq Er EAGAIN
+The user is not the super user, and
+the soft resource limit corresponding to the resource parameter
+.Dv RLIMIT_NOFILE
+would be exceeded (see
+.Xr getrlimit 2 ) .
+.It Bq Er EINVAL
+The RFPROC flag was not specified.
+.It Bq Er EINVAL
+Both the RFFDG and the RFCFDG flags were specified.
+.It Bq Er ENOMEM
+There is insufficient swap space for the new process.
+.El
+.Sh SEE ALSO
+.Xr fork 2 ,
+.Xr intro 2 ,
+.Xr minherit 2 ,
+.Xr vfork 2
+.Sh HISTORY
+The
+.Fn rfork
+function call first appeared in Plan9.
diff --git a/lib/libc/sys/rmdir.2 b/lib/libc/sys/rmdir.2
index 29f8833..51235f6 100644
--- a/lib/libc/sys/rmdir.2
+++ b/lib/libc/sys/rmdir.2
@@ -60,8 +60,6 @@ The named file is removed unless:
.Bl -tag -width [ENAMETOOLONG]
.It Bq Er ENOTDIR
A component of the path is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -101,6 +99,6 @@ points outside the process's allocated address space.
.Xr unlink 2
.Sh HISTORY
The
-.Nm
+.Fn rmdir
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/rtprio.2 b/lib/libc/sys/rtprio.2
new file mode 100644
index 0000000..9e7c1c9
--- /dev/null
+++ b/lib/libc/sys/rtprio.2
@@ -0,0 +1,108 @@
+.\" Copyright (c) 1994, Henrik Vestergaard Draboel
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Henrik Vestergaard Draboel.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+.\"
+.\" $Id: rtprio.2,v 1.8 1997/02/22 15:04:17 peter Exp $
+.\"
+.Dd July 23, 1994
+.Dt RTPRIO 2
+.Sh NAME
+.Nm rtprio
+.Nd examine or modify a process realtime or idle priority
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/rtprio.h>
+.Ft int
+.Fn rtprio "int function" "pid_t pid" "struct rtprio *rtp"
+.Sh DESCRIPTION
+.Fn rtprio
+is used to lookup or change the realtime or idle priority of a process.
+
+.Fa function
+specifies the operation to be performed. RTP_LOOKUP to lookup the current priority,
+and RTP_SET to set the priority.
+.Fa pid
+specifies the process to be used, 0 for the current process.
+
+.Fa *rtp
+is a pointer to a struct rtprio which is used to specify the priority and priority type.
+This structure has the following form:
+.Bd -literal
+struct rtprio {
+ u_short type;
+ u_short prio;
+};
+.Ed
+.Pp
+The value of the
+.Nm type
+field may be RTP_PRIO_REALTIME for realtime priorities,
+RTP_PRIO_NORMAL for normal priorities, and RTP_PRIO_IDLE for idle priorities.
+The priority specified by the
+.Nm prio
+field ranges between 0 and
+.Dv RTP_PRIO_MAX (usually 31) .
+0 is the highest possible priority.
+
+Realtime and idle priority is inherited through fork() and exec().
+
+A realtime process can only be preempted by a process of equal or
+higher priority, or by an interrupt; idle priority processes will run only
+when no other real/normal priority process is runnable. Higher real/idle priority processes
+preempt lower real/idle priority processes. Processes of equal real/idle priority are run round-robin.
+.Sh RETURN VALUES
+.Fn rtprio
+will return 0 for success and -1 for all errors. The global variable
+.Va errno
+will be set to indicate the error.
+.Sh ERRORS
+.Fn rtprio
+will fail if
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The specified
+.Fa prio
+was out of range.
+.It Bq Er EPERM
+The calling process is not allowed to set the realtime priority. Only
+root is allowed to change the realtime priority of any process, and non-root
+may only change the idle priority of the current process.
+.It Bq Er ESRCH
+The specified process was not found.
+.Sh AUTHOR
+The original author was Henrik Vestergaard Draboel - hvd@terry.ping.dk. This
+implementation in
+.Tn FreeBSD
+was substantially rewritten by David Greenman.
+.Sh SEE ALSO
+.Xr nice 1 ,
+.Xr ps 1 ,
+.Xr rtprio 1 ,
+.Xr setpriority 2 ,
+.Xr nice 3 ,
+.Xr renice 8
diff --git a/lib/libc/sys/select.2 b/lib/libc/sys/select.2
index 3de5b5e..c9a332dc 100644
--- a/lib/libc/sys/select.2
+++ b/lib/libc/sys/select.2
@@ -104,7 +104,7 @@ If
is a non-nil pointer, it specifies a maximum interval to wait for the
selection to complete. If
.Fa timeout
-is a nil pointer, the select blocks indefinitely. To affect a poll, the
+is a nil pointer, the select blocks indefinitely. To effect a poll, the
.Fa timeout
argument should be non-nil, pointing to a zero-valued timeval structure.
.Pp
@@ -140,6 +140,9 @@ before any of the selected events occurred.
.It Bq Er EINVAL
The specified time limit is invalid. One of its components is
negative or too large.
+.It Bq Er EINVAL
+.Fa nfds
+was invalid.
.El
.Sh SEE ALSO
.Xr accept 2 ,
@@ -149,26 +152,31 @@ negative or too large.
.Xr read 2 ,
.Xr recv 2 ,
.Xr send 2 ,
-.Xr write 2
-.Sh BUGS
-Although the provision of
-.Xr getdtablesize 2
-was intended to allow user programs to be written independent
-of the kernel limit on the number of open files, the dimension
-of a sufficiently large bit field for select remains a problem.
-The default size
+.Xr write 2 ,
+.Xr clocks 7
+.Sh NOTES
+The default size of
.Dv FD_SETSIZE
-(currently 256) is somewhat larger than
-the current kernel limit to the number of open files.
-However, in order to accommodate programs which might potentially
-use a larger number of open files with select, it is possible
-to increase this size within a program by providing
-a larger definition of
+is currently 256.
+In order to accomodate programs which might potentially
+use a larger number of open files with
+.Fn select
+, it is possible
+to increase this size by having the program define
.Dv FD_SETSIZE
-before the inclusion of
+before the inclusion of any header which includes
.Aq Pa sys/types.h .
.Pp
-.Fn Select
+If
+.Fa nfds
+is greater than the number of open files,
+.Fn select
+is not guaranteed to examine the unused file descriptors. For historical
+reasons,
+.Fn select
+will always examine the first 256 descriptors.
+.Sh BUGS
+.Fn select
should probably return the time remaining from the original timeout,
if any, by modifying the time value in place.
This may be implemented in future versions of the system.
@@ -178,6 +186,6 @@ by the
call.
.Sh HISTORY
The
-.Nm
+.Fn select
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/semctl.2 b/lib/libc/sys/semctl.2
new file mode 100644
index 0000000..5855a7d
--- /dev/null
+++ b/lib/libc/sys/semctl.2
@@ -0,0 +1,173 @@
+.\"
+.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
+.\"
+.\" All rights reserved.
+.\"
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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.
+.\"
+.\" $Id: semctl.2,v 1.6 1997/02/22 15:04:18 peter Exp $
+.\"
+.Dd September 12, 1995
+.Dt SEMCTL 2
+.Os FreeBSD
+.Sh NAME
+.Nm semctl
+.Nd control operations on a semaphore set
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Fd #include <sys/sem.h>
+.Ft int
+.Fn semctl "int semid" "int semnum" "int cmd" "union semun arg"
+.Sh DESCRIPTION
+.Fn Semctl
+performs the operation indicated by
+.Fa cmd
+on the semaphore set indicated by
+.Fa semid .
+For the commands that use the
+.Fa arg
+parameter,
+.Fa "union semun"
+is defined as follows:
+.Bd -literal
+.\"
+.\" From <sys/sem.h>:
+.\"
+union semun {
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
+ u_short *array; /* array for GETALL & SETALL */
+};
+.Ed
+.Pp
+Commands are performed as follows:
+.\"
+.\" This section based on Stevens, _Advanced Programming in the UNIX
+.\" Environment_.
+.\"
+.Bl -tag -width IPC_RMIDXXX
+.It Dv IPC_STAT
+Fetch the semaphore set's
+.Fa "struct semid_ds" ,
+storing it in the memory pointed to by
+.Fa arg.buf .
+.It Dv IPC_SET
+Changes the
+.Fa sem_perm.uid ,
+.Fa sem_perm.gid ,
+and
+.Fa sem_perm.mode
+members of the semaphore set's
+.Fa "struct semid_ds"
+to match those of the struct pointed to by
+.Fa arg.buf .
+The calling process's effective uid must
+match either
+.Fa sem_perm.uid
+or
+.Fa sem_perm.cuid ,
+or it must have superuser privileges.
+.It IPC_RMID
+Immediately removes the semaphore set from the system. The calling
+process's effective uid must equal the semaphore set's
+.Fa sem_perm.uid
+or
+.Fa sem_perm.cuid ,
+or the process must have superuser privileges.
+.It Dv GETVAL
+Return the value of semaphore number
+.Fa semnum .
+.It Dv SETVAL
+Set the value of semaphore number
+.Fa semnum
+to
+.Fa arg.val .
+.It Dv GETPID
+Return the pid of the last process to perform an operation on
+semaphore number
+.Fa semnum .
+.It Dv GETNCNT
+Return the number of processes waiting for semaphore number
+.Fa semnum Ns 's
+value to become greater than its current value.
+.It Dv GETZCNT
+Return the number of processes waiting for semaphore number
+.Fa semnum Ns 's
+value to become 0.
+.It Dv GETALL
+Fetch the value of all of the semaphores in the set into the
+array pointed to by
+.Fa arg.array .
+.It Dv SETALL
+Set the values of all of the semaphores in the set to the values
+in the array pointed to by
+.Fa arg.array .
+.El
+.Pp
+The
+.Fa "struct semid_ds"
+is defined as follows:
+.Bd -literal
+.\"
+.\" Taken straight from <sys/sem.h>.
+.\"
+struct semid_ds {
+ struct ipc_perm sem_perm; /* operation permission struct */
+ struct sem *sem_base; /* pointer to first semaphore in set */
+ u_short sem_nsems; /* number of sems in set */
+ time_t sem_otime; /* last operation time */
+ long sem_pad1; /* SVABI/386 says I need this here */
+ time_t sem_ctime; /* last change time */
+ /* Times measured in secs since */
+ /* 00:00:00 GMT, Jan. 1, 1970 */
+ long sem_pad2; /* SVABI/386 says I need this here */
+ long sem_pad3[4]; /* SVABI/386 says I need this here */
+};
+.Ed
+.Sh RETURN VALUES
+On success, when
+.Fa cmd
+is one of GETVAL, GETNCNT, or GETZCNT,
+.Fn semctl
+returns the corresponding value; otherwise, 0 is returned.
+On failure, -1 is returned, and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn Semctl
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+No semaphore set corresponds to
+.Fa semid .
+.It Bq Er EINVAL
+.Fa semnum
+is not in the range of valid semaphores for given semaphore set.
+.It Bq Er EPERM
+The calling process's effective uid does not match the uid of
+the semaphore set's owner or creator.
+.It Bq Er EACCES
+Permission denied due to mismatch between operation and mode of
+semaphore set.
+.Sh SEE ALSO
+.Xr semget 2 ,
+.Xr semop 2
diff --git a/lib/libc/sys/semget.2 b/lib/libc/sys/semget.2
new file mode 100644
index 0000000..ed69cfc
--- /dev/null
+++ b/lib/libc/sys/semget.2
@@ -0,0 +1,137 @@
+.\"
+.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
+.\"
+.\" All rights reserved.
+.\"
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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.
+.\"
+.\" $Id: semget.2,v 1.4 1997/02/22 15:04:19 peter Exp $
+.\"
+.Dd September 12, 1995
+.Dt SEMGET 2
+.Os FreeBSD
+.Sh NAME
+.Nm semget
+.Nd obtain a semaphore id
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Fd #include <sys/sem.h>
+.Ft int
+.Fn semget "key_t key" "int nsems" "int flag"
+.Sh DESCRIPTION
+Based on the values of
+.Fa key
+and
+.Fa flag ,
+.Fn semget
+returns the identifier of a newly created or previously existing
+set of semaphores.
+.\"
+.\" This is copied verbatim from the shmget manpage. Perhaps
+.\" it should go in a common manpage, such as .Xr ipc 2
+.\"
+The key
+is analogous to a filename: it provides a handle that names an
+IPC object. There are three ways to specify a key:
+.Bl -bullet
+.It
+IPC_PRIVATE may be specified, in which case a new IPC object
+will be created.
+.It
+An integer constant may be specified. If no IPC object corresponding
+to
+.Fa key
+is specified and the IPC_CREAT bit is set in
+.Fa flag ,
+a new one will be created.
+.It
+.Fn ftok
+may be used to generate a key from a pathname. See
+.Xr ftok 3 .
+.El
+.\"
+.\" Likewise for this section, except SHM_* becomes SEM_*.
+.\"
+.Pp
+The mode of a newly created IPC object is determined by
+.Em OR Ns 'ing
+the following constants into the
+.Fa flag
+parameter:
+.Bl -tag -width XSEM_WXX6XXX
+.It Dv SEM_R
+Read access for user.
+.It Dv SEM_A
+Alter access for user.
+.It Dv (SEM_R>>3)
+Read access for group.
+.It Dv (SEM_A>>3)
+Alter access for group.
+.It Dv (SEM_R>>6)
+Read access for other.
+.It Dv (SEM_A>>6)
+Alter access for other.
+.El
+.Pp
+If a new set of semaphores is being created,
+.Fa nsems
+is used to indicate the number of semaphores the set should contain.
+Otherwise,
+.Fa nsems
+may be specified as 0.
+.Sh RETURN VALUES
+.Fn Semget
+returns the id of a semaphore set if successful; otherwise, -1
+is returned and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn Semget
+will fail if:
+.Bl -tag -width Er
+.\" ipcperm could fail (we're opening to read and write, as it were)
+.It Bq Er EACCES
+Access permission failure.
+.\"
+.\" sysv_sem.c is quite explicit about these, so I'm pretty sure
+.\" this is accurate
+.\"
+.It Bq Er EEXIST
+IPC_CREAT and IPC_EXCL were specified, and a semaphore set
+corresponding to
+.Fa key
+already exists.
+.It Bq Er EINVAL
+The number of semaphores requested exceeds the system imposed maximum
+per set.
+.It Bq Er ENOSPC
+Insufficiently many semaphores are available.
+.It Bq Er ENOSPC
+The kernel could not allocate a
+.Fa "struct semid_ds" .
+.It Bq Er ENOENT
+No semaphore set was found corresponding to
+.Fa key ,
+and IPC_CREAT was not specified.
+.Sh SEE ALSO
+.Xr semctl 2 ,
+.Xr semop 2
diff --git a/lib/libc/sys/semop.2 b/lib/libc/sys/semop.2
new file mode 100644
index 0000000..06dfa3b
--- /dev/null
+++ b/lib/libc/sys/semop.2
@@ -0,0 +1,192 @@
+.\"
+.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
+.\"
+.\" All rights reserved.
+.\"
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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.
+.\"
+.\" $Id: semop.2,v 1.5 1997/02/22 15:04:21 peter Exp $
+.\"
+.Dd September 22, 1995
+.Dt SEMOP 2
+.Os FreeBSD
+.Sh NAME
+.Nm semop
+.Nd atomic array of operations on a semaphore set
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Fd #include <sys/sem.h>
+.Ft int
+.Fn semop "int semid" "struct sembuf array[]" "unsigned nops"
+.Sh DESCRIPTION
+.Fn Semop
+atomically performs the array of operations indicated by
+.Fa array
+on the semaphore set indicated by
+.Fa semid .
+The length of
+.Fa array
+is indicated by
+.Fa nops .
+Each operation is encoded in a
+.Fa "struct sembuf" ,
+which is defined as follows:
+.Bd -literal
+.\"
+.\" From <sys/sem.h>
+.\"
+struct sembuf {
+ u_short sem_num; /* semaphore # */
+ short sem_op; /* semaphore operation */
+ short sem_flg; /* operation flags */
+};
+.Ed
+.Pp
+For each element in
+.Fa array ,
+.Fa sem_op
+and
+.Fa sem_flg
+determine an operation to be performed on semaphore number
+.Fa sem_num
+in the set. The values SEM_UNDO and IPC_NOWAIT may be
+.Em OR Ns 'ed
+into the
+.Fa sem_flg
+member in order to modify the behavior of the given operation.
+.Pp
+The operation performed depends as follows on the value of
+.Fa sem_op :
+.\"
+.\" This section is based on the description of semop() in
+.\" Stevens, _Advanced Programming in the UNIX Environment_.
+.\"
+.Bl -bullet
+.It
+When
+.Fa sem_op
+is positive, the semaphore's value is incremented by
+.Fa sem_op Ns 's
+value. If SEM_UNDO is specified, the semaphore's adjust on exit
+value is decremented by
+.Fa sem_op Ns 's
+value. A positive value for
+.Fa sem_op
+generally corresponds to a process releasing a resource
+associated with the semaphore.
+.It
+The behavior when
+.Fa sem_op
+is negative depends on the current value of the semaphore:
+.Bl -bullet
+.It
+If the current value of the semaphore is greater than or equal to
+the absolute value of
+.Fa sem_op ,
+then the value is decremented by the absolute value of
+.Fa sem_op .
+If SEM_UNDO is specified, the semaphore's adjust on exit
+value is incremented by the absolute value of
+.Fa sem_op .
+.It
+If the current value of the semaphore is less than
+.Fa sem_op Ns 's
+value, one of the following happens:
+.\" XXX a *second* sublist?
+.Bl -bullet
+.It
+If IPC_NOWAIT was specified, then
+.Fn semop
+returns immediately with a return value of EAGAIN.
+.It
+If some other process has removed the semaphore with the IPC_RMID
+option of
+.Fn semctl ,
+then
+.Fn semop
+returns immediately with a return value of EINVAL.
+.It
+Otherwise, the calling process is put to sleep until the semaphore's
+value is greater than or equal to the absolute value of
+.Fa sem_op .
+When this condition becomes true, the semaphore's value is decremented
+by the absolute value of
+.Fa sem_op ,
+and the semaphore's adjust on exit value is incremented by the
+absolute value of
+.Fa sem_op .
+.El
+.Pp
+A negative value for
+.Fa sem_op
+generally means that a process is waiting for a resource to become
+available.
+.El
+.Pp
+.It
+When
+.Fa sem_op
+is zero, the process waits for the semaphore's value to become zero.
+If it is already zero, the call to
+.Fn semop
+can return immediately. Otherwise, the calling process is put to
+sleep until the semaphore's value becomes zero.
+.El
+.Pp
+For each semaphore a process has in use, the kernel maintains an
+`adjust on exit' value, as alluded to earlier. When a process
+exits, either voluntarily or involuntarily, the adjust on exit value
+for each semaphore is added to the semaphore's value. This can
+be used to insure that a resource is released if a process terminates
+unexpectedly.
+.Sh RETURN VALUES
+On success,
+.Fn semop
+returns 0; otherwise, -1 is returned and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn Semop
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+No semaphore set corresponds to
+.Fa semid .
+.It Bq Er EACCES
+Permission denied due to mismatch between operation and mode of
+semaphore set.
+.It Bq Er EAGAIN
+The semaphore's value was less than
+.Fa sem_op ,
+and IPC_NOWAIT was specified.
+.It Bq Er E2BIG
+Too many operations were specified.
+.It Bq Er EFBIG
+.\"
+.\" I'd have thought this would be EINVAL, but the source says
+.\" EFBIG.
+.\"
+.Fa sem_num
+was not in the range of valid semaphores for the set.
+.Sh SEE ALSO
+.Xr semctl 2 ,
+.Xr semget 2
diff --git a/lib/libc/sys/send.2 b/lib/libc/sys/send.2
index 9dc285b..57fcfb3 100644
--- a/lib/libc/sys/send.2
+++ b/lib/libc/sys/send.2
@@ -29,9 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)send.2 8.2 (Berkeley) 2/21/94
+.\" From: @(#)send.2 8.2 (Berkeley) 2/21/94
+.\" $Id$
.\"
-.Dd February 21, 1994
+.Dd February 15, 1995
.Dt SEND 2
.Os BSD 4.2
.Sh NAME
@@ -94,8 +95,11 @@ The
.Fa flags
parameter may include one or more of the following:
.Bd -literal
-#define MSG_OOB 0x1 /* process out-of-band data */
-#define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */
+#define MSG_OOB 0x1 /* process out-of-band data */
+#define MSG_PEEK 0x2 /* peek at incoming message */
+#define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */
+#define MSG_EOR 0x8 /* data completes record */
+#define MSG_EOF 0x100 /* data completes transaction */
.Ed
.Pp
The flag
@@ -107,6 +111,20 @@ data on sockets that support this notion (e.g.
the underlying protocol must also support
.Dq out-of-band
data.
+.Dv MSG_EOR
+is used to indicate a record mark for protocols which support the
+concept.
+.Dv MSG_EOF
+requests that the sender side of a socket be shut down, and that an
+appropriate indication be sent at the end of the specified data;
+this flag is only implemented for
+.Dv SOCK_STREAM
+sockets in the
+.Dv PF_INET
+protocol family, and is used to implement Transaction
+.Tn TCP
+(see
+.Xr ttcp 4 ) .
.Dv MSG_DONTROUTE
is usually used only by diagnostic or routing programs.
.Pp
@@ -124,9 +142,13 @@ if an error occurred.
and
.Fn sendmsg
fail if:
-.Bl -tag -width [EMSGSIZE]
+.Bl -tag -width Er
.It Bq Er EBADF
An invalid descriptor was specified.
+.It Bq Er EACCES
+The destination address is a broadcast address, and
+.Dv SO_BROADCAST
+has not been set on the socket.
.It Bq Er ENOTSOCK
The argument
.Fa s
@@ -146,16 +168,18 @@ The operation may succeed when buffers become available.
The output queue for a network interface was full.
This generally indicates that the interface has stopped sending,
but may be caused by transient congestion.
+.It Bq Er EHOSTUNREACH
+The remote host was unreachable.
.El
.Sh SEE ALSO
.Xr fcntl 2 ,
+.Xr getsockopt 2 ,
.Xr recv 2 ,
.Xr select 2 ,
-.Xr getsockopt 2 ,
.Xr socket 2 ,
.Xr write 2
.Sh HISTORY
The
-.Nm
+.Fn send
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/setgroups.2 b/lib/libc/sys/setgroups.2
index e20b47e..bce9e1a 100644
--- a/lib/libc/sys/setgroups.2
+++ b/lib/libc/sys/setgroups.2
@@ -78,6 +78,6 @@ address space.
.Xr initgroups 3
.Sh HISTORY
The
-.Nm
+.Fn setgroups
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/setpgid.2 b/lib/libc/sys/setpgid.2
index 141c203..4490edf 100644
--- a/lib/libc/sys/setpgid.2
+++ b/lib/libc/sys/setpgid.2
@@ -77,9 +77,10 @@ of the calling process.
.Sh SEE ALSO
.Xr getpgrp 2
.Sh STANDARDS
-.Fn Setpgid
-conforms to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn setpgid
+function call is expected to conform to
+.St -p1003.1-90 .
.Sh COMPATIBILITY
.Fn Setpgrp
is identical to
diff --git a/lib/libc/sys/setregid.2 b/lib/libc/sys/setregid.2
new file mode 100644
index 0000000..0b8343b
--- /dev/null
+++ b/lib/libc/sys/setregid.2
@@ -0,0 +1,92 @@
+.\" Copyright (c) 1980, 1991, 1993, 1994
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\" @(#)setregid.2 8.2 (Berkeley) 4/16/94
+.\"
+.Dd April 16, 1994
+.Dt SETREGID 2
+.Os BSD 4.2
+.Sh NAME
+.Nm setregid
+.Nd set real and effective group ID
+.Sh SYNOPSIS
+.Fd #include <unistd.h>
+.Ft int
+.Fn setregid "gid_t rgid" "gid_t egid"
+.Sh DESCRIPTION
+The real and effective group ID's of the current process
+are set to the arguments.
+Unprivileged users may change the real group
+ID to the effective group ID and vice-versa; only the super-user may
+make other changes.
+.Pp
+Supplying a value of -1 for either the real or effective
+group ID forces the system to substitute the current
+ID in place of the -1 parameter.
+.Pp
+The
+.Fn setregid
+function was intended to allow swapping
+the real and effective group IDs
+in set-group-ID programs to temporarily relinquish the set-group-ID value.
+This function did not work correctly,
+and its purpose is now better served by the use of the
+.Fn setegid
+function (see
+.Xr setuid 2 ) .
+.Pp
+When setting the real and effective group IDs to the same value,
+the standard
+.Fn setgid
+function is preferred.
+.Sh RETURN VALUES
+Upon successful completion, a value of 0 is returned. Otherwise,
+a value of -1 is returned and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Bl -tag -width [EPERM]
+.It Bq Er EPERM
+The current process is not the super-user and a change
+other than changing the effective group-id to the real group-id
+was specified.
+.El
+.Sh SEE ALSO
+.Xr getgid 2 ,
+.Xr issetugid 2 ,
+.Xr setegid 2 ,
+.Xr setgid 2 ,
+.Xr setuid 2
+.Sh HISTORY
+The
+.Fn setregid
+system call appeared in
+.Bx 4.2 .
diff --git a/lib/libc/sys/setreuid.2 b/lib/libc/sys/setreuid.2
new file mode 100644
index 0000000..1736879
--- /dev/null
+++ b/lib/libc/sys/setreuid.2
@@ -0,0 +1,90 @@
+.\" Copyright (c) 1980, 1991, 1993, 1994
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\" @(#)setreuid.2 8.2 (Berkeley) 4/16/94
+.\"
+.Dd April 16, 1994
+.Dt SETREUID 2
+.Os BSD 4
+.Sh NAME
+.Nm setreuid
+.Nd set real and effective user ID's
+.Sh SYNOPSIS
+.Fd #include <unistd.h>
+.Ft int
+.Fn setreuid "uid_t ruid" "uid_t euid"
+.Sh DESCRIPTION
+The real and effective user IDs of the
+current process are set according to the arguments.
+If
+.Fa ruid
+or
+.Fa euid
+is -1, the current uid is filled in by the system.
+Unprivileged users may change the real user
+ID to the effective user ID and vice-versa; only the super-user may
+make other changes.
+.Pp
+The
+.Fn setreuid
+function has been used to swap the real and effective user IDs
+in set-user-ID programs to temporarily relinquish the set-user-ID value.
+This purpose is now better served by the use of the
+.Fn seteuid
+function (see
+.Xr setuid 2 ) .
+.Pp
+When setting the real and effective user IDs to the same value,
+the standard
+.Fn setuid
+function is preferred.
+.Sh RETURN VALUES
+Upon successful completion, a value of 0 is returned. Otherwise,
+a value of -1 is returned and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Bl -tag -width [EPERM]
+.It Bq Er EPERM
+The current process is not the super-user and a change
+other than changing the effective user-id to the real user-id
+was specified.
+.El
+.Sh SEE ALSO
+.Xr getuid 2 ,
+.Xr issetugid 2 ,
+.Xr seteuid 2 ,
+.Xr setuid 2
+.Sh HISTORY
+The
+.Fn setreuid
+system call appeared in
+.Bx 4.2 .
diff --git a/lib/libc/sys/setsid.2 b/lib/libc/sys/setsid.2
index 48ac6a0..73d437d 100644
--- a/lib/libc/sys/setsid.2
+++ b/lib/libc/sys/setsid.2
@@ -31,36 +31,39 @@
.\"
.\" @(#)setsid.2 8.1 (Berkeley) 6/4/93
.\"
-.Dd "June 4, 1993"
+.Dd June 4, 1993
.Dt SETSID 2
.Os
.Sh NAME
.Nm setsid
.Nd create session and set process group ID
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
+.Fd #include <unistd.h>
.Ft pid_t
.Fn setsid "void"
.Sh DESCRIPTION
The
-.Nm setsid
+.Fn setsid
function creates a new session.
The calling process is the session leader of the new session, is the
process group leader of a new process group and has no controlling
terminal.
The calling process is the only process in either the session or the
process group.
-.Pp
+.Sh RETURN VALUES
Upon successful completion, the
-.Nm setsid
+.Fn setsid
function returns the value of the process group ID of the new process
group, which is the same as the process ID of the calling process.
-.Sh ERRORS
If an error occurs,
-.Nm setsid
+.Fn setsid
returns -1 and the global variable
.Va errno
-is set to indicate the error, as follows:
+is set to indicate the error.
+.Sh ERRORS
+The
+.Fn setsid
+function will fail if:
.Bl -tag -width Er
.It Bq Er EPERM
The calling process is already a process group leader, or the process
@@ -68,12 +71,12 @@ group ID of a process other than the calling process matches the process
ID of the calling process.
.El
.Sh SEE ALSO
-.Xr setpgid 3 ,
+.Xr setpgid 2 ,
.Xr tcgetpgrp 3 ,
.Xr tcsetpgrp 3
.Sh STANDARDS
The
-.Nm setsid
+.Fn setsid
function is expected to be compliant with the
-.St -p1003.1-88
+.St -p1003.1-90
specification.
diff --git a/lib/libc/sys/setuid.2 b/lib/libc/sys/setuid.2
index 383a8f5..1f24fb0 100644
--- a/lib/libc/sys/setuid.2
+++ b/lib/libc/sys/setuid.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)setuid.2 8.1 (Berkeley) 6/4/93
+.\" $Id: setuid.2,v 1.10 1997/04/01 18:58:38 mpp Exp $
.\"
.Dd June 4, 1993
.Dt SETUID 2
@@ -58,9 +59,22 @@ function
sets the real and effective
user IDs and the saved set-user-ID of the current process
to the specified value.
+.\" Comment out next block for !_POSIX_SAVED_IDS
+.\" The real user ID and the saved set-user-ID are changed only if the
+.\" effective user ID is that of the super user.
+.\" I.e.
+.\" .Fn setuid
+.\" function is equal to
+.\" .Fn seteuid
+.\" function if the effective user ID is not that of the super user.
+.\" End of block
The
.Fn setuid
function is permitted if the specified ID is equal to the real user ID
+.\" Comment out next line for !_POSIX_SAVED_IDS
+.\" or the saved set-user-ID
+.\" Next line is for Appendix B.4.2.2 case.
+or the effective user ID
of the process, or if the effective user ID is that of the super user.
.Pp
The
@@ -69,9 +83,22 @@ function
sets the real and effective
group IDs and the saved set-group-ID of the current process
to the specified value.
+.\" Comment out next block for !_POSIX_SAVED_IDS
+.\" The real group ID and the saved set-group-ID are changed only if the
+.\" effective user ID is that of the super user.
+.\" I.e.
+.\" .Fn setgid
+.\" function is equal to
+.\" .Fn setegid
+.\" function if the effective user ID is not that of the super user.
+.\" End of block
The
.Fn setgid
function is permitted if the specified ID is equal to the real group ID
+.\" Comment out next line for !_POSIX_SAVED_IDS
+.\" or the saved set-groupd-ID
+.\" Next line is for Appendix B.4.2.2 case.
+or the effective group ID
of the process, or if the effective user ID is that of the super user.
.Pp
The
@@ -99,18 +126,23 @@ If the user is not the super user, or the uid
specified is not the real, effective ID, or saved ID,
these functions return \-1.
.Sh SEE ALSO
+.Xr getgid 2 ,
.Xr getuid 2 ,
-.Xr getgid 2
+.Xr issetugid 2 ,
+.Xr setregid 2 ,
+.Xr setreuid 2
.Sh STANDARDS
The
.Fn setuid
and
.Fn setgid
functions are compliant with the
-.St -p1003.1-88
+.St -p1003.1-90
specification with
.Li _POSIX_SAVED_IDS
-not defined.
+.\" Uncomment next line for !_POSIX_SAVED_IDS
+not
+defined with the permitted extensions from Appendix B.4.2.2.
The
.Fn seteuid
and
@@ -120,3 +152,10 @@ functions are extensions based on the
concept of
.Li _POSIX_SAVED_IDS ,
and have been proposed for a future revision of the standard.
+.Sh HISTORY
+A
+.Fn setuid
+and a
+.Fn setgid
+function calls appeared in
+.At v7 .
diff --git a/lib/libc/sys/shmat.2 b/lib/libc/sys/shmat.2
new file mode 100644
index 0000000..e3f87c9
--- /dev/null
+++ b/lib/libc/sys/shmat.2
@@ -0,0 +1,110 @@
+.\"
+.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
+.\"
+.\" All rights reserved.
+.\"
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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.
+.\"
+.\" $Id: shmat.2,v 1.5 1997/02/22 15:04:25 peter Exp $
+.\"
+.Dd August 2, 1995
+.Dt SHMAT 2
+.Os FreeBSD
+.Sh NAME
+.Nm shmat ,
+.Nm shmdt
+.Nd attach or detach shared memory
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Fd #include <sys/shm.h>
+.Ft void *
+.Fn shmat "int shmid" "void *addr" "int flag"
+.Ft int
+.Fn shmdt "void *addr"
+.Sh DESCRIPTION
+.Fn Shmat
+attaches the shared memory segment identified by
+.Fa shmid
+to the calling process's address space. The address where the segment
+is attached is determined as follows:
+.\"
+.\" These are cribbed almost exactly from Stevens, _Advanced Programming in
+.\" the UNIX Environment_.
+.\"
+.Bl -bullet
+.It
+If
+.Fa addr
+is 0, the segment is attached at an address selected by the
+kernel.
+.It
+If
+.Fa addr
+is nonzero and SHM_RND is not specified in
+.Fa flag ,
+the segment is attached the specified address.
+.It
+If
+.Fa addr
+is specified and SHM_RND is specified,
+.Fa addr
+is rounded down to the nearest multiple of SHMLBA.
+.El
+.Pp
+.Fn Shmdt
+detaches the shared memory segment at the address specified by
+.Fa addr
+from the calling process's address space.
+.Sh RETURN VALUES
+Upon success,
+.Fn shmat
+returns the address where the segment is attached; otherwise, -1
+is returned and
+.Va errno
+is set to indicate the error.
+.Pp
+Upon success,
+.Fn shmdt
+returns 0; otherwise, -1 is returned and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn Shmat
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+No shared memory segment was found corresponding to
+.Fa shmid .
+.It Bq Er EINVAL
+.Fa addr
+was not an acceptable address.
+.El
+.Pp
+.Fn Shmdt
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+.Fa addr
+does not point to a shared memory segment.
+.Sh "SEE ALSO"
+.Xr shmctl 2 ,
+.Xr shmget 2
diff --git a/lib/libc/sys/shmctl.2 b/lib/libc/sys/shmctl.2
new file mode 100644
index 0000000..123a02d
--- /dev/null
+++ b/lib/libc/sys/shmctl.2
@@ -0,0 +1,136 @@
+.\"
+.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
+.\"
+.\" All rights reserved.
+.\"
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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.
+.\"
+.\" $Id: shmctl.2,v 1.5 1997/02/22 15:04:26 peter Exp $
+.\"
+.Dd July 17, 1995
+.Dt SHMCTL 2
+.Os FreeBSD
+.Sh NAME
+.Nm shmctl
+.Nd shared memory control
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Fd #include <sys/shm.h>
+.Ft int
+.Fn shmctl "int shmid" "int cmd" "struct shmid_ds *buf"
+.Sh DESCRIPTION
+Performs the action specified by
+.Fa cmd
+on the shared memory segment identified by
+.Fa shmid :
+.Bl -tag -width SHM_UNLOCKX
+.It Dv IPC_STAT
+Fetch the segment's
+.Fa "struct shmid_ds" ,
+storing it in the memory pointed to by
+.Fa buf .
+.\"
+.\" XXX need to make sure that this is correct for FreeBSD
+.\"
+.It Dv IPC_SET
+Changes the
+.Fa shm_perm.uid ,
+.Fa shm_perm.gid ,
+and
+.Fa shm_perm.mode
+members of the segment's
+.Fa "struct shmid_ds"
+to match those of the struct pointed to by
+.Fa buf .
+The calling process's effective uid must
+match either
+.Fa shm_perm.uid
+or
+.Fa shm_perm.cuid ,
+or it must have superuser privileges.
+.It Dv IPC_RMID
+Removes the segment from the system. The removal will not take
+effect until all processes having attached the segment have exited;
+however, once the IPC_RMID operation has taken place, no further
+processes will be allowed to attach the segment. For the operation
+to succeed, the calling process's effective uid must match
+.Fa shm_perm.uid
+or
+.Fa shm_perm.cuid ,
+or the process must have superuser privileges.
+.\" .It Dv SHM_LOCK
+.\" Locks the segment in memory. The calling process must have
+.\" superuser privileges. Not implemented in FreeBSD.
+.\" .It Dv SHM_UNLOCK
+.\" Unlocks the segment from memory. The calling process must
+.\" have superuser privileges. Not implemented in FreeBSD.
+.El
+.Pp
+The
+.Fa "shmid_ds"
+struct is defined as follows:
+.\"
+.\" I fiddled with the spaces a bit to make it fit well when viewed
+.\" with nroff, but otherwise it's straight from sys/shm.h
+.\"
+.Bd -literal
+struct shmid_ds {
+ struct ipc_perm shm_perm; /* operation permission structure */
+ int shm_segsz; /* size of segment in bytes */
+ pid_t shm_lpid; /* process ID of last shared memory op */
+ pid_t shm_cpid; /* process ID of creator */
+ short shm_nattch; /* number of current attaches */
+ time_t shm_atime; /* time of last shmat() */
+ time_t shm_dtime; /* time of last shmdt() */
+ time_t shm_ctime; /* time of last change by shmctl() */
+ void *shm_internal; /* sysv stupidity */
+};
+.Ed
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn shmctl
+returns 0. Otherwise, it returns -1 and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn Shmctl
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Invalid operation, or
+no shared memory segment was found corresponding to
+.Fa shmid .
+.\"
+.\" XXX I think the following is right: ipcperm() only returns EPERM
+.\" when an attempt is made to modify (IPC_M) by a non-creator
+.\" non-owner
+.It Bq Er EPERM
+The calling process's effective uid does not match the uid of
+the shared memory segment's owner or creator.
+.It Bq Er EACCES
+Permission denied due to mismatch between operation and mode of
+shared memory segment.
+.Sh "SEE ALSO"
+.Xr shmat 2 ,
+.Xr shmdt 2 ,
+.Xr shmget 2 ,
+.Xr ftok 3
diff --git a/lib/libc/sys/shmget.2 b/lib/libc/sys/shmget.2
new file mode 100644
index 0000000..1f8da15
--- /dev/null
+++ b/lib/libc/sys/shmget.2
@@ -0,0 +1,138 @@
+.\"
+.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
+.\"
+.\" All rights reserved.
+.\"
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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.
+.\"
+.\" $Id: shmget.2,v 1.5 1997/02/22 15:04:26 peter Exp $
+.\"
+.Dd July 3, 1995
+.Dt SHMGET 2
+.Os FreeBSD
+.Sh NAME
+.Nm shmget
+.Nd obtain a shared memory identifier
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/ipc.h>
+.Fd #include <sys/shm.h>
+.Ft int
+.Fn shmget "key_t key" "int size" "int flag"
+.Sh DESCRIPTION
+Based on the values of
+.Fa key
+and
+.Fa flag ,
+.Fn shmget
+returns the identifier of a newly created or previously existing shared
+memory segment.
+.\"
+.\" The following bit about keys and modes also applies to semaphores
+.\" and message queues.
+.\"
+The key
+is analogous to a filename: it provides a handle that names an
+IPC object. There are three ways to specify a key:
+.Bl -bullet
+.It
+IPC_PRIVATE may be specified, in which case a new IPC object
+will be created.
+.It
+An integer constant may be specified. If no IPC object corresponding
+to
+.Fa key
+is specified and the IPC_CREAT bit is set in
+.Fa flag ,
+a new one will be created.
+.It
+.Fn ftok
+may be used to generate a key from a pathname. See
+.Xr ftok 3 .
+.El
+.Pp
+The mode of a newly created IPC object is determined by
+.Em OR Ns 'ing
+the following constants into the
+.Fa flag
+parameter:
+.Bl -tag -width XSHM_WXX6XXX
+.It Dv SHM_R
+Read access for user.
+.It Dv SHM_W
+Write access for user.
+.It Dv (SHM_R>>3)
+Read access for group.
+.It Dv (SHM_W>>3)
+Write access for group.
+.It Dv (SHM_R>>6)
+Read access for other.
+.It Dv (SHM_W>>6)
+Write access for other.
+.El
+.\"
+.\" XXX - we should also mention how uid, euid, and gid affect ownership
+.\" and use
+.\"
+.\" end section about keys and modes
+.\"
+.Pp
+When creating a new shared memory segment,
+.Fa size
+indicates the desired size of the new segment in bytes. The size
+of the segment may be rounded up to a multiple convenient to the
+kernel (i.e., the page size).
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn shmget
+returns the positive integer identifier of a shared memory segment.
+Otherwise, -1 is returned and
+.Va errno
+set to indicate the error.
+.Sh ERRORS
+.Fn Shmget
+will fail if:
+.Bl -tag -width Er
+.\"
+.\" XXX What about ipcperm failing?
+.\"
+.It Bq Er EINVAL
+Size specified is greater than the size of the previously existing segment.
+Size specified is less than the system imposed minimum, or greater than
+the system imposed maximum.
+.It Bq Er ENOENT
+No shared memory segment was found matching
+.Fa key ,
+and IPC_CREAT was not specified.
+.It Bq Er ENOSPC
+The kernel was unable to allocate enough memory to
+satisfy the request.
+.It Bq Er EEXIST
+IPC_CREAT and IPC_EXCL were specified, and a shared memory segment
+corresponding to
+.Fa key
+already exists.
+.Pp
+.Sh "SEE ALSO"
+.Xr shmat 2 ,
+.Xr shmctl 2 ,
+.Xr shmdt 2 ,
+.Xr ftok 3
diff --git a/lib/libc/sys/shutdown.2 b/lib/libc/sys/shutdown.2
index 976f958..b83763f 100644
--- a/lib/libc/sys/shutdown.2
+++ b/lib/libc/sys/shutdown.2
@@ -38,6 +38,7 @@
.Nm shutdown
.Nd shut down part of a full-duplex connection
.Sh SYNOPSIS
+.Fd #include <sys/types.h>
.Fd #include <sys/socket.h>
.Ft int
.Fn shutdown "int s" "int how"
@@ -57,7 +58,7 @@ is 1, further sends will be disallowed.
If
.Fa how
is 2, further sends and receives will be disallowed.
-.Sh DIAGNOSTICS
+.Sh RETURN VALUES
A 0 is returned if the call succeeds, -1 if it fails.
.Sh ERRORS
The call succeeds unless:
@@ -76,6 +77,6 @@ The specified socket is not connected.
.Xr socket 2
.Sh HISTORY
The
-.Nm
+.Fn shutdown
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/sigaction.2 b/lib/libc/sys/sigaction.2
index d48b640..cf51196 100644
--- a/lib/libc/sys/sigaction.2
+++ b/lib/libc/sys/sigaction.2
@@ -41,16 +41,17 @@
.Fd #include <signal.h>
.Bd -literal
struct sigaction {
- void (*sa_handler)();
- sigset_t sa_mask;
- int sa_flags;
+ void (*sa_handler)(); /* signal handler */
+ sigset_t sa_mask; /* signal mask to apply */
+ int sa_flags; /* see signal options below */
};
.Ed
-.Fn sigaction "int sig" "struct sigaction *act" "struct sigaction *oact"
+.Ft int
+.Fn sigaction "int sig" "const struct sigaction *act" "struct sigaction *oact"
.Sh DESCRIPTION
The system defines a set of signals that may be delivered to a process.
Signal delivery resembles the occurrence of a hardware interrupt:
-the signal is blocked from further occurrence, the current process
+the signal is normally blocked from further occurrence, the current process
context is saved, and a new one is built. A process may specify a
.Em handler
to which a signal is delivered, or specify that a signal is to be
@@ -68,7 +69,7 @@ of the process. This may be changed, on a per-handler basis,
so that signals are taken on a special
.Em "signal stack" .
.Pp
-Signal routines execute with the signal that caused their
+Signal routines normally execute with the signal that caused their
invocation
.Em blocked ,
but other signals may yet occur.
@@ -117,7 +118,8 @@ the signal to be delivered, and
the signal mask associated with the handler to be invoked.
.Pp
.Fn Sigaction
-assigns an action for a specific signal.
+assigns an action for a signal specified by
+.Fa sig .
If
.Fa act
is non-zero, it
@@ -131,7 +133,7 @@ If
is non-zero, the previous handling information for the signal
is returned to the user.
.Pp
-Once a signal handler is installed, it remains installed
+Once a signal handler is installed, it normally remains installed
until another
.Fn sigaction
call is made, or an
@@ -178,7 +180,16 @@ bit is set in
the system will deliver the signal to the process on a
.Em "signal stack" ,
specified with
-.Xr sigstack 2 .
+.Xr sigaltstack 2 .
+If the
+.Dv SA_NODEFER
+bit is set, further occurrences of the delivered signal are not
+masked during the execution of the handler.
+If the
+.Dv SA_RESETHAND
+bit is set, the handler is reset back to
+.Dv SIG_DFL
+at the moment the signal is delivered.
.Pp
If a signal is caught during the system calls listed below,
the call may be forced to terminate
@@ -234,7 +245,7 @@ with names as in the include file
.It Dv SIGQUIT No " create core image" " quit program"
.It Dv SIGILL No " create core image" " illegal instruction"
.It Dv SIGTRAP No " create core image" " trace trap"
-.It Dv SIGABRT No " create core image" Xr abort 2
+.It Dv SIGABRT No " create core image" Xr abort 3
call (formerly
.Dv SIGIOT )
.It Dv SIGEMT No " create core image" " emulate instruction executed"
@@ -242,7 +253,7 @@ call (formerly
.It Dv SIGKILL No " terminate process" " kill program"
.It Dv SIGBUS No " create core image" " bus error"
.It Dv SIGSEGV No " create core image" " segmentation violation"
-.It Dv SIGSYS No " create core image" " system call given invalid argument"
+.It Dv SIGSYS No " create core image" " non-existent system call invoked"
.It Dv SIGPIPE No " terminate process" " write on a pipe with no reader"
.It Dv SIGALRM No " terminate process" " real-time timer expired"
.It Dv SIGTERM No " terminate process" " software termination signal"
@@ -270,13 +281,15 @@ is possible on a descriptor (see
.It Dv SIGUSR2 No " terminate process" " User defined signal 2"
.El
.Sh NOTE
-The mask specified in
+The
+.Fa sa_mask
+field specified in
.Fa act
is not allowed to block
.Dv SIGKILL
or
.Dv SIGSTOP .
-This is done silently by the system.
+Any attempt to do so will be silently ignored.
.Sh RETURN VALUES
A 0 value indicated that the call succeeded. A \-1 return value
indicates an error occurred and
@@ -327,9 +340,9 @@ or
.El
.Sh STANDARDS
The
-.Nm sigaction
-function is defined by
-.St -p1003.1-88 .
+.Fn sigaction
+function call is expected to conform to
+.St -p1003.1-90 .
The
.Dv SA_ONSTACK
and
@@ -352,17 +365,22 @@ and
Those signals are available on most
.Tn BSD Ns \-derived
systems.
+The
+.Dv SA_NODEFER
+and
+.Dv SA_RESETHAND
+are intended for backwards compatability with other operating systems.
.Sh SEE ALSO
.Xr kill 1 ,
-.Xr ptrace 2 ,
.Xr kill 2 ,
+.Xr ptrace 2 ,
.Xr sigaction 2 ,
-.Xr sigprocmask 2 ,
-.Xr sigsuspend 2 ,
+.Xr sigaltstack 2 ,
.Xr sigblock 2 ,
-.Xr sigsetmask 2 ,
.Xr sigpause 2 ,
-.Xr sigstack 2 ,
+.Xr sigprocmask 2 ,
+.Xr sigsetmask 2 ,
+.Xr sigsuspend 2 ,
.Xr sigvec 2 ,
.Xr setjmp 3 ,
.Xr siginterrupt 3 ,
diff --git a/lib/libc/sys/sigaltstack.2 b/lib/libc/sys/sigaltstack.2
index 1626025..7ea6113 100644
--- a/lib/libc/sys/sigaltstack.2
+++ b/lib/libc/sys/sigaltstack.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)sigaltstack.2 8.2 (Berkeley) 5/1/95
+.\" $Id: sigaltstack.2,v 1.7 1997/03/12 16:23:36 mpp Exp $
.\"
.Dd May 1, 1995
.Dt SIGALTSTACK 2
@@ -42,7 +43,7 @@
.Fd #include <signal.h>
.Bd -literal
struct sigaltstack {
- caddr_t ss_base;
+ char *ss_sp;
long ss_size;
int ss_flags;
};
@@ -71,15 +72,15 @@ the system arranges a switch to the signal stack for the
duration of the signal handler's execution.
.Pp
If
-.Dv SA_DISABLE
+.Dv SS_DISABLE
is set in
.Fa ss_flags ,
-.Fa ss_base
+.Fa ss_sp
and
.Fa ss_size
are ignored and the signal stack will be disabled.
Trying to disable an active stack will cause
-.Nm
+.Fn sigaltstack
to return -1 with
.Va errno
set to
@@ -95,9 +96,9 @@ is non-zero, the current signal stack state is returned.
The
.Fa ss_flags
field will contain the value
-.Dv SA_ONSTACK
+.Dv SS_ONSTACK
if the process is currently on a signal stack and
-.Dv SA_DISABLE
+.Dv SS_DISABLE
if the signal stack is currently disabled.
.Sh NOTES
The value
@@ -106,7 +107,7 @@ is defined to be the number of bytes/chars that would be used to cover
the usual case when allocating an alternate stack area.
The following code fragment is typically used to allocate an alternate stack.
.Bd -literal -offset indent
-if ((sigstk.ss_base = malloc(SIGSTKSZ)) == NULL)
+if ((sigstk.ss_sp = malloc(SIGSTKSZ)) == NULL)
/* error return */
sigstk.ss_size = SIGSTKSZ;
sigstk.ss_flags = 0;
@@ -158,7 +159,7 @@ Size of alternate stack area is less than or equal to
.Xr setjmp 3
.Sh HISTORY
The predecessor to
-.Nm sigaltstack ,
+.Fn sigaltstack ,
the
.Fn sigstack
system call, appeared in
diff --git a/lib/libc/sys/sigpending.2 b/lib/libc/sys/sigpending.2
index 0c87d4f..e8c6b8d 100644
--- a/lib/libc/sys/sigpending.2
+++ b/lib/libc/sys/sigpending.2
@@ -46,7 +46,7 @@
.Fn sigpending "sigset_t *set"
.Sh DESCRIPTION
The
-.Nm sigpending
+.Fn sigpending
function returns a mask of the signals pending for delivery
to the calling process in the location indicated by
.Fa set .
@@ -60,13 +60,13 @@ indicates an error occurred and
is set to indicated the reason.
.Sh ERRORS
The
-.Nm sigpending
+.Fn sigpending
function does not currently detect any errors.
.Sh SEE ALSO
.Xr sigaction 2 ,
.Xr sigprocmask 2
.Sh STANDARDS
The
-.Nm sigpending
-function is defined by
-.St -p1003.1-88 .
+.Fn sigpending
+function call is expected to conform to
+.St -p1003.1-90 .
diff --git a/lib/libc/sys/sigprocmask.2 b/lib/libc/sys/sigprocmask.2
index 73b014d..af1b574 100644
--- a/lib/libc/sys/sigprocmask.2
+++ b/lib/libc/sys/sigprocmask.2
@@ -110,11 +110,11 @@ has a value other than those listed here.
.Sh SEE ALSO
.Xr kill 2 ,
.Xr sigaction 2 ,
-.Xr sigsetops 3 ,
-.Xr sigsuspend 2
+.Xr sigsuspend 2 ,
+.Xr sigsetops 3
.Sh STANDARDS
The
-.Nm sigprocmask
+.Fn sigprocmask
function call is expected to
conform to
-.St -p1003.1-88 .
+.St -p1003.1-90 .
diff --git a/lib/libc/sys/sigreturn.2 b/lib/libc/sys/sigreturn.2
index f995d11..0e848c3 100644
--- a/lib/libc/sys/sigreturn.2
+++ b/lib/libc/sys/sigreturn.2
@@ -40,14 +40,28 @@
.Sh SYNOPSIS
.Fd #include <signal.h>
.Bd -literal
-struct sigcontext {
- int sc_onstack;
- int sc_mask;
- int sc_sp;
- int sc_fp;
- int sc_ap;
- int sc_pc;
- int sc_ps;
+struct sigcontext {
+ int sc_onstack; /* sigstack state to restore */
+ int sc_mask; /* signal mask to restore */
+ int sc_esp; /* machine state */
+ int sc_ebp;
+ int sc_isp;
+ int sc_eip;
+ int sc_efl;
+ int sc_es;
+ int sc_ds;
+ int sc_cs;
+ int sc_ss;
+ int sc_edi;
+ int sc_esi;
+ int sc_ebx;
+ int sc_edx;
+ int sc_ecx;
+ int sc_eax;
+# define sc_sp sc_esp
+# define sc_fp sc_ebp
+# define sc_pc sc_eip
+# define sc_ps sc_efl
};
.Ed
.Ft int
@@ -92,6 +106,6 @@ raise the privilege level of the process.
.Xr setjmp 3
.Sh HISTORY
The
-.Nm
+.Fn sigreturn
function call appeared in
.Bx 4.3 .
diff --git a/lib/libc/sys/sigstack.2 b/lib/libc/sys/sigstack.2
index 54d1c14..3fbe6e6 100644
--- a/lib/libc/sys/sigstack.2
+++ b/lib/libc/sys/sigstack.2
@@ -46,6 +46,6 @@ function has been deprecated in favor of the interface described in
.Xr sigaltstack 2
.Sh HISTORY
The
-.Nm
+.Fn sigstack
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/sigsuspend.2 b/lib/libc/sys/sigsuspend.2
index 2fa3c8d..885c170 100644
--- a/lib/libc/sys/sigsuspend.2
+++ b/lib/libc/sys/sigsuspend.2
@@ -69,12 +69,12 @@ always terminates by being interrupted, returning -1 with
set to
.Dv EINTR .
.Sh SEE ALSO
-.Xr sigprocmask 2 ,
.Xr sigaction 2 ,
+.Xr signanosleep 2 ,
+.Xr sigprocmask 2 ,
.Xr sigsetops 3
.Sh STANDARDS
The
-.Nm sigsuspend
-function call
-conforms to
-.St -p1003.1-88 .
+.Fn sigsupend
+function call is expected to conform to
+.St -p1003.1-90 .
diff --git a/lib/libc/sys/socket.2 b/lib/libc/sys/socket.2
index a16e3fb..fb6e4fa 100644
--- a/lib/libc/sys/socket.2
+++ b/lib/libc/sys/socket.2
@@ -29,9 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)socket.2 8.1 (Berkeley) 6/4/93
+.\" From: @(#)socket.2 8.1 (Berkeley) 6/4/93
+.\" $Id: socket.2,v 1.6 1997/02/22 15:04:28 peter Exp $
.\"
-.Dd June 4, 1993
+.Dd February 15, 1995
.Dt SOCKET 2
.Os BSD 4.2
.Sh NAME
@@ -56,11 +57,12 @@ These families are defined in the include file
The currently understood formats are
.Pp
.Bd -literal -offset indent -compact
-AF_UNIX (UNIX internal protocols),
-AF_INET (ARPA Internet protocols),
-AF_ISO (ISO protocols),
-AF_NS (Xerox Network Systems protocols), and
-AF_IMPLINK (IMP \*(lqhost at IMP\*(rq link layer).
+PF_LOCAL (Host-internal protocols, formerly called PF_UNIX),
+PF_INET (ARPA Internet protocols),
+PF_ISO (ISO protocols),
+PF_CCITT (ITU-T protocols, like X.25),
+PF_NS (Xerox Network Systems protocols), and
+.\"PF_IMPLINK (IMP \*(lqhost at IMP\*(rq link layer).
.Ed
.Pp
The socket has the indicated
@@ -123,7 +125,8 @@ to pipes. A stream socket must be in a
state before any data may be sent or received
on it. A connection to another socket is created with a
.Xr connect 2
-call. Once connected, data may be transferred using
+call.
+Once connected, data may be transferred using
.Xr read 2
and
.Xr write 2
@@ -131,7 +134,15 @@ calls or some variant of the
.Xr send 2
and
.Xr recv 2
-calls. When a session has been completed a
+calls.
+(Some protocol families, such as the Internet family,
+support the notion of an
+.Dq implied connect,
+which permits data to be sent piggybacked onto a connect operation by
+using the
+.Xr sendto 2
+call.)
+When a session has been completed a
.Xr close 2
may be performed.
Out-of-band data may also be transmitted as described in
@@ -230,7 +241,7 @@ The socket cannot be created until sufficient resources are freed.
.Xr accept 2 ,
.Xr bind 2 ,
.Xr connect 2 ,
-.Xr getprotoent 3 ,
+.Xr getpeername 2 ,
.Xr getsockname 2 ,
.Xr getsockopt 2 ,
.Xr ioctl 2 ,
@@ -241,17 +252,20 @@ The socket cannot be created until sufficient resources are freed.
.Xr send 2 ,
.Xr shutdown 2 ,
.Xr socketpair 2 ,
-.Xr write 2
+.Xr write 2 ,
+.Xr getprotoent 3
.Rs
.%T "An Introductory 4.3 BSD Interprocess Communication Tutorial"
-.%O "reprinted in UNIX Programmer's Supplementary Documents Volume 1"
+.%B PS1
+.%N 7
.Re
.Rs
.%T "BSD Interprocess Communication Tutorial"
-.%O "reprinted in UNIX Programmer's Supplementary Documents Volume 1"
+.%B PS1
+.%N 8
.Re
.Sh HISTORY
The
-.Nm
+.Fn socket
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/socketpair.2 b/lib/libc/sys/socketpair.2
index 1e8ba24..62aef76 100644
--- a/lib/libc/sys/socketpair.2
+++ b/lib/libc/sys/socketpair.2
@@ -58,7 +58,7 @@ are returned in
and
.Fa sv Ns [1] .
The two sockets are indistinguishable.
-.Sh DIAGNOSTICS
+.Sh RETURN VALUES
A 0 is returned if the call succeeds, -1 if it fails.
.Sh ERRORS
The call succeeds unless:
@@ -77,15 +77,15 @@ The address
does not specify a valid part of the
process address space.
.Sh SEE ALSO
+.Xr pipe 2 ,
.Xr read 2 ,
-.Xr write 2 ,
-.Xr pipe 2
+.Xr write 2
.Sh BUGS
This call is currently implemented only for the
.Tn UNIX
domain.
.Sh HISTORY
The
-.Nm
+.Fn socketpair
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/stat.2 b/lib/libc/sys/stat.2
index 6c39663..7b92113 100644
--- a/lib/libc/sys/stat.2
+++ b/lib/libc/sys/stat.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)stat.2 8.4 (Berkeley) 5/1/95
+.\" $Id: stat.2,v 1.11 1997/02/22 15:04:29 peter Exp $
.\"
.Dd May 1, 1995
.Dt STAT 2
@@ -93,21 +94,30 @@ as defined by
and into which information is placed concerning the file.
.Bd -literal
struct stat {
- dev_t st_dev; /* device inode resides on */
- ino_t st_ino; /* inode's number */
- mode_t st_mode; /* inode protection mode */
- nlink_t st_nlink; /* number or hard links to the file */
- uid_t st_uid; /* user-id of owner */
- gid_t st_gid; /* group-id of owner */
- dev_t st_rdev; /* device type, for special file inode */
+ dev_t st_dev; /* inode's device */
+ ino_t st_ino; /* inode's number */
+ mode_t st_mode; /* inode protection mode */
+ nlink_t st_nlink; /* number of hard links */
+ 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 type */
+#ifndef _POSIX_SOURCE
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last file status change */
- off_t st_size; /* file size, in bytes */
- quad_t st_blocks; /* blocks allocated for file */
- u_long st_blksize;/* optimal file sys I/O ops blocksize */
- u_long st_flags; /* user defined flags for file */
- u_long st_gen; /* file generation number */
+#else
+ time_t st_atime; /* time of last access */
+ long st_atimensec; /* nsec of last access */
+ time_t st_mtime; /* time of last data modification */
+ long st_mtimensec; /* nsec of last data modification */
+ time_t st_ctime; /* time of last file status change */
+ long st_ctimensec; /* nsec of last file status change */
+#endif
+ off_t st_size; /* file size, in bytes */
+ quad_t st_blocks; /* blocks allocated for file */
+ u_long st_blksize; /* optimal blocksize for I/O */
+ u_long st_flags; /* user defined flags for file */
+ u_long st_gen; /* file generation number */
};
.Ed
.Pp
@@ -146,6 +156,17 @@ and
system calls.
.El
.Pp
+If
+.Dv _POSIX_SOURCE
+is not defined, the time-related fields are defined as:
+.Bd -literal
+#ifndef _POSIX_SOURCE
+#define st_atime st_atimespec.tv_sec
+#define st_mtime st_mtimespec.tv_sec
+#define st_ctime st_ctimespec.tv_sec
+#endif
+.Ed
+.Pp
The size-related fields of the
.Fa struct stat
are as follows:
@@ -170,6 +191,7 @@ has the following bits:
#define S_IFREG 0100000 /* regular */
#define S_IFLNK 0120000 /* symbolic link */
#define S_IFSOCK 0140000 /* socket */
+#define S_IFWHT 0160000 /* whiteout */
#define S_ISUID 0004000 /* set user id on execution */
#define S_ISGID 0002000 /* set group id on execution */
#define S_ISVTX 0001000 /* save swapped text even after use */
@@ -207,8 +229,6 @@ will fail if:
.Bl -tag -width ENAMETOOLONGAA
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -242,13 +262,13 @@ An I/O error occurred while reading from or writing to the file system.
.Sh SEE ALSO
.Xr chmod 2 ,
.Xr chown 2 ,
-.Xr utimes 2
+.Xr utimes 2 ,
.Xr symlink 7
.Sh BUGS
Applying
-.Xr fstat
+.Fn fstat
to a socket (and thus to a pipe)
-returns a zero'd buffer,
+returns a zeroed buffer,
except for the blocksize field,
and a unique device and inode number.
.Sh STANDARDS
@@ -256,11 +276,16 @@ The
.Fn stat
and
.Fn fstat
-function calls are expected to
-conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+function calls are expected to conform to
+.St -p1003.1-90 .
.Sh HISTORY
A
-.Nm lstat
+.Fn stat
+and a
+.Fn fstat
+function call appeared in
+.At v7 .
+A
+.Fn lstat
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/statfs.2 b/lib/libc/sys/statfs.2
index 6db63c6..80164d0 100644
--- a/lib/libc/sys/statfs.2
+++ b/lib/libc/sys/statfs.2
@@ -54,27 +54,32 @@ is a pointer to a
.Fn statfs
structure defined as follows:
.Bd -literal
-typedef quad fsid_t;
+typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */
-#define MFSNAMELEN 16 /* length of fs type name, including null */
-#define MNAMELEN 90 /* length of buffer for returned name */
+/*
+ * file system statistics
+ */
+
+#define MFSNAMELEN 16 /* length of fs type name, including null */
+#define MNAMELEN 90 /* length of buffer for returned name */
struct statfs {
- short f_type; /* filesystem type number */
- short f_flags; /* copy of mount flags */
- long f_bsize; /* fundamental file system block size */
- long f_iosize; /* optimal transfer block size */
- long f_blocks; /* total data blocks in file system */
- long f_bfree; /* free blocks in fs */
- long f_bavail; /* free blocks avail to non-superuser */
- long f_files; /* total file nodes in file system */
- long f_ffree; /* free file nodes in fs */
- fsid_t f_fsid; /* file system id */
- uid_t f_owner; /* user that mounted the filesystem */
- long f_spare[4]; /* spare for later */
- char f_fstypename[MFSNAMELEN]; /* fs type name */
- char f_mntonname[MNAMELEN]; /* directory on which mounted */
- char f_mntfromname[MNAMELEN];/* mounted filesystem */
+long f_spare2; /* placeholder */
+long f_bsize; /* fundamental file system block size */
+long f_iosize; /* optimal transfer block size */
+long f_blocks; /* total data blocks in file system */
+long f_bfree; /* free blocks in fs */
+long f_bavail; /* free blocks avail to non-superuser */
+long f_files; /* total file nodes in file system */
+long f_ffree; /* free file nodes in fs */
+fsid_t f_fsid; /* file system id */
+uid_t f_owner; /* user that mounted the filesystem */
+int f_type; /* type of filesystem (see below) */
+int f_flags; /* copy of mount flags */
+long f_spare[2]; /* spare for later */
+char f_fstypename[MFSNAMELEN];/* fs type name */
+char f_mntonname[MNAMELEN]; /* mount point */
+char f_mntfromname[MNAMELEN]; /* mounted filesystem */
};
.Ed
The flags that may be returned include:
@@ -127,9 +132,6 @@ fails if one or more of the following are true:
A component of the path prefix of
.Fa Path
is not a directory.
-.It Bq Er EINVAL
-.Fa path
-contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
The length of a component of
.Fa path
@@ -174,5 +176,6 @@ error occurred while reading from or writing to the file system.
.El
.Sh HISTORY
The
-.Nm statfs
-function first appeared in 4.4BSD.
+.Fn statfs
+function first appeared in
+.Bx 4.4 .
diff --git a/lib/libc/sys/swapon.2 b/lib/libc/sys/swapon.2
index 5f152cc..b684da1 100644
--- a/lib/libc/sys/swapon.2
+++ b/lib/libc/sys/swapon.2
@@ -62,8 +62,6 @@ succeeds unless:
.Bl -tag -width ENAMETOOLONG
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -99,8 +97,8 @@ An I/O error occurred while opening the swap device.
.Fa Special
points outside the process's allocated address space.
.Sh SEE ALSO
-.Xr swapon 8 ,
-.Xr config 8
+.Xr config 8 ,
+.Xr swapon 8
.Sh BUGS
There is no way to stop swapping on a disk so that the pack may be
dismounted.
@@ -108,6 +106,6 @@ dismounted.
This call will be upgraded in future versions of the system.
.Sh HISTORY
The
-.Nm
+.Fn swapon
function call appeared in
.Bx 4.0 .
diff --git a/lib/libc/sys/symlink.2 b/lib/libc/sys/symlink.2
index c404a3d..ce1fa7e 100644
--- a/lib/libc/sys/symlink.2
+++ b/lib/libc/sys/symlink.2
@@ -66,12 +66,6 @@ The symbolic link succeeds unless:
A component of the
.Fa name2
prefix is not a directory.
-.It Bq Er EINVAL
-Either
-.Fa name1
-or
-.Fa name2
-contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of either pathname exceeded 255 characters,
or the entire length of either path name exceeded 1023 characters.
@@ -129,11 +123,14 @@ or
points outside the process's allocated address space.
.El
.Sh SEE ALSO
-.Xr link 2 ,
.Xr ln 1 ,
-.Xr unlink 2
+.Xr link 2 ,
+.Xr lstat 2 ,
+.Xr readlink 2 ,
+.Xr unlink 2 ,
+.Xr symlink 7
.Sh HISTORY
The
-.Nm
+.Fn symlink
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/sync.2 b/lib/libc/sys/sync.2
index 5e79fef..2b2b664 100644
--- a/lib/libc/sys/sync.2
+++ b/lib/libc/sys/sync.2
@@ -53,7 +53,7 @@ As information in the cache is lost after a system crash a
call is issued
frequently
by the user process
-.Xr update 8
+.Xr update 4
(about every 30 seconds).
.Pp
The function
@@ -62,12 +62,13 @@ may be used to synchronize individual file descriptor
attributes.
.Sh SEE ALSO
.Xr fsync 2 ,
-.Xr sync 8 ,
-.Xr update 8
+.Xr update 4 ,
+.Xr sync 8
.Sh BUGS
.Fn Sync
may return before the buffers are completely flushed.
.Sh HISTORY
A
-.Nm
-function call appeared in Version 6 AT&T UNIX.
+.Fn sync
+function call appeared in
+.At v6 .
diff --git a/lib/libc/sys/syscall.2 b/lib/libc/sys/syscall.2
index 2e020ad..f59f2d1 100644
--- a/lib/libc/sys/syscall.2
+++ b/lib/libc/sys/syscall.2
@@ -42,9 +42,9 @@
.Fd #include <sys/syscall.h>
.Fd #include <unistd.h>
.Ft int
-.Fn syscall "int number" "..."
-.Ft int
-.Fn __syscall "quad_t number" "..."
+.Fn syscall "int number" ...
+.Ft off_t
+.Fn __syscall "quad_t number" ...
.Sh DESCRIPTION
.Fn Syscall
performs the system call whose assembly language
@@ -54,7 +54,7 @@ with the specified arguments.
Symbolic constants for system calls can be found in the header file
.Ao Pa sys/syscall.h Ac .
The
-.Nm __syscall
+.Fn __syscall
form should be used when one or more of the parameters is a
64-bit argument to ensure that argument alignment is correct.
This system call is useful for testing new system calls that
@@ -71,6 +71,6 @@ such as
.Xr pipe 2 .
.Sh HISTORY
The
-.Nm syscall
+.Fn syscall
function call appeared in
.Bx 4.0 .
diff --git a/lib/libc/sys/truncate.2 b/lib/libc/sys/truncate.2
index 2a5f3a6..678dcf6 100644
--- a/lib/libc/sys/truncate.2
+++ b/lib/libc/sys/truncate.2
@@ -37,7 +37,7 @@
.Sh NAME
.Nm truncate ,
.Nm ftruncate
-.Nd truncate a file to a specified length
+.Nd truncate or extend a file to a specified length
.Sh SYNOPSIS
.Fd #include <unistd.h>
.Ft int
@@ -50,11 +50,14 @@ causes the file named by
.Fa path
or referenced by
.Fa fd
-to be truncated to at most
+to be truncated or extended to
.Fa length
-bytes in size. If the file previously
+bytes in size. If the file
was larger than this size, the extra data
is lost.
+If the file was smaller than this size,
+it will be extended as if by writing bytes
+with the value zero.
With
.Fn ftruncate ,
the file must be open for writing.
@@ -69,8 +72,6 @@ succeeds unless:
.Bl -tag -width [ENOTDIR]
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -116,8 +117,12 @@ is not open for writing.
.Sh BUGS
These calls should be generalized to allow ranges
of bytes in a file to be discarded.
+.Pp
+Use of
+.Fn truncate
+to extend a file is not portable.
.Sh HISTORY
The
-.Nm
+.Fn truncate
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/truncate.c b/lib/libc/sys/truncate.c
index 0d50cd7..5bfeeb6 100644
--- a/lib/libc/sys/truncate.c
+++ b/lib/libc/sys/truncate.c
@@ -38,13 +38,15 @@ static char sccsid[] = "@(#)truncate.c 8.1 (Berkeley) 6/17/93";
#include <sys/types.h>
#include <sys/syscall.h>
+#include <unistd.h>
+
/*
* This function provides 64-bit offset padding that
* is not supplied by GCC 1.X but is supplied by GCC 2.X.
*/
int
truncate(path, length)
- char *path;
+ const char *path;
off_t length;
{
diff --git a/lib/libc/sys/umask.2 b/lib/libc/sys/umask.2
index cec3f1d..4ac1db8 100644
--- a/lib/libc/sys/umask.2
+++ b/lib/libc/sys/umask.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)umask.2 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt UMASK 2
@@ -78,5 +79,10 @@ function is always successful.
.Sh STANDARDS
The
.Fn umask
-function call is expected to conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+function call is expected to conform to
+.St -p1003.1-90 .
+.Sh HISTORY
+An
+.Fn umask
+function call appeared in
+.At v7 .
diff --git a/lib/libc/sys/unlink.2 b/lib/libc/sys/unlink.2
index 78221bc..8693f95 100644
--- a/lib/libc/sys/unlink.2
+++ b/lib/libc/sys/unlink.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)unlink.2 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt UNLINK 2
@@ -56,6 +57,8 @@ all resources associated with the file are reclaimed.
If one or more process have the file open when the last link is removed,
the link is removed, but the removal of the file is delayed until
all references to it have been closed.
+.Fa path
+may not be a directory.
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of -1 is returned and
@@ -68,8 +71,6 @@ succeeds unless:
.Bl -tag -width ENAMETOOLONGAA
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er ENAMETOOLONG
A component of a pathname exceeded 255 characters,
or an entire path name exceeded 1023 characters.
@@ -83,8 +84,7 @@ to be removed.
.It Bq Er ELOOP
Too many symbolic links were encountered in translating the pathname.
.It Bq Er EPERM
-The named file is a directory and the effective user ID
-of the process is not the super-user.
+The named file is a directory.
.It Bq Er EPERM
The directory containing the file is marked sticky,
and neither the containing directory nor the file to be removed
@@ -104,9 +104,16 @@ points outside the process's allocated address space.
.Sh SEE ALSO
.Xr close 2 ,
.Xr link 2 ,
-.Xr rmdir 2
+.Xr rmdir 2 ,
.Xr symlink 7
.Sh HISTORY
An
-.Nm
-function call appeared in Version 6 AT&T UNIX.
+.Fn unlink
+function call appeared in
+.At v6 .
+.Pp
+The
+.Fn unlink
+system call traditionally allows the super-user to unlink directories which
+can damage the filesystem integrity. This implementation no longer permits
+it.
diff --git a/lib/libc/sys/utimes.2 b/lib/libc/sys/utimes.2
index 1ebeb37..531d236 100644
--- a/lib/libc/sys/utimes.2
+++ b/lib/libc/sys/utimes.2
@@ -82,12 +82,10 @@ and the effective user ID of the process does not
match the owner of the file, and is not the super-user, and write
access is denied.
.It Bq Er EFAULT
-.Xr File
+.Fa File
or
.Fa times
points outside the process's allocated address space.
-.It Bq Er EINVAL
-The pathname contains a character with the high-order bit set.
.It Bq Er EIO
An I/O error occurred while reading or writing the affected inode.
.It Bq Er ELOOP
@@ -113,6 +111,6 @@ The file system containing the file is mounted read-only.
.Xr stat 2
.Sh HISTORY
The
-.Nm utimes
+.Fn utimes
function call appeared in
.Bx 4.2 .
diff --git a/lib/libc/sys/vfork.2 b/lib/libc/sys/vfork.2
index 8b6e077..a780cbf 100644
--- a/lib/libc/sys/vfork.2
+++ b/lib/libc/sys/vfork.2
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)vfork.2 8.1 (Berkeley) 6/4/93
+.\" $Id$
.\"
.Dd June 4, 1993
.Dt VFORK 2
@@ -48,16 +49,16 @@ space of the old process, which is horrendously inefficient in a paged
environment. It is useful when the purpose of
.Xr fork 2
would have been to create a new system context for an
-.Xr execve .
+.Xr execve 2 .
.Fn Vfork
differs from
-.Xr fork
+.Xr fork 2
in that the child borrows the parent's memory and thread of
control until a call to
.Xr execve 2
or an exit (either by a call to
-.Xr exit 2
-or abnormally.)
+.Xr exit 3
+or abnormally).
The parent process is suspended while the child is using its resources.
.Pp
.Fn Vfork
@@ -66,7 +67,7 @@ the parent's context.
.Pp
.Fn Vfork
can normally be used just like
-.Xr fork .
+.Xr fork 2 .
It does not work, however, to return while running in the childs context
from the procedure that called
.Fn vfork
@@ -74,36 +75,36 @@ since the eventual return from
.Fn vfork
would then return to a no longer existent stack frame.
Be careful, also, to call
-.Xr _exit
+.Xr _exit 2
rather than
-.Xr exit
+.Xr exit 3
if you can't
-.Xr execve ,
+.Xr execve 2 ,
since
-.Xr exit
+.Xr exit 3
will flush and close standard I/O channels, and thereby mess up the
parent processes standard I/O data structures.
(Even with
-.Xr fork
+.Xr fork 2
it is wrong to call
-.Xr exit
+.Xr exit 3
since buffered data would then be flushed twice.)
.Sh SEE ALSO
-.Xr fork 2 ,
.Xr execve 2 ,
+.Xr fork 2 ,
.Xr sigvec 2 ,
-.Xr wait 2 ,
-.Sh DIAGNOSTICS
+.Xr wait 2
+.Sh RETURN VALUES
Same as for
-.Xr fork .
+.Xr fork 2 .
.Sh BUGS
This system call will be eliminated when proper system sharing
mechanisms are implemented.
Users should not depend on the memory
sharing semantics of
-.Xr vfork
+.Xr vfork 2
as it will, in that case, be made synonymous to
-.Xr fork .
+.Xr fork 2 .
.Pp
To avoid a possible deadlock situation,
processes that are children in the middle
@@ -121,6 +122,6 @@ are allowed
and input attempts result in an end-of-file indication.
.Sh HISTORY
The
-.Nm
+.Fn vfork
function call appeared in
.Bx 3.0 .
diff --git a/lib/libc/sys/wait.2 b/lib/libc/sys/wait.2
index c0077b1..d348361 100644
--- a/lib/libc/sys/wait.2
+++ b/lib/libc/sys/wait.2
@@ -156,7 +156,7 @@ One of the first three macros will evaluate to a non-zero (true) value:
True if the process terminated normally by a call to
.Xr _exit 2
or
-.Xr exit 2 .
+.Xr exit 3 .
.It Fn WIFSIGNALED status
True if the process terminated due to receipt of a signal.
.It Fn WIFSTOPPED status
@@ -178,7 +178,7 @@ is true, evaluates to the low-order 8 bits
of the argument passed to
.Xr _exit 2
or
-.Xr exit 2
+.Xr exit 3
by the child.
.It Fn WTERMSIG status
If
@@ -287,9 +287,11 @@ and the ability to restart a pending
.Fn wait
call are extensions to the POSIX interface.
.Sh SEE ALSO
-.Xr exit 2 ,
-.Xr sigaction 2
+.Xr _exit 2 ,
+.Xr sigaction 2 ,
+.Xr exit 3
.Sh HISTORY
A
-.Nm
-function call appeared in Version 6 AT&T UNIX.
+.Fn wait
+function call appeared in
+.At v6 .
diff --git a/lib/libc/sys/write.2 b/lib/libc/sys/write.2
index de2d3ae..f8d8063 100644
--- a/lib/libc/sys/write.2
+++ b/lib/libc/sys/write.2
@@ -70,8 +70,8 @@ structure is defined as:
.Pp
.Bd -literal -offset indent -compact
struct iovec {
- void *iov_base;
- size_t iov_len;
+ char *iov_base; /* Base address. */
+ size_t iov_len; /* Length. */
};
.Ed
.Pp
@@ -115,6 +115,53 @@ and
may write fewer bytes than requested;
the return value must be noted,
and the remainder of the operation should be retried when possible.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn write
+is implemented as the
+.Va write
+syscall.
+.Pp
+In the threaded library, the
+.Va write
+syscall is assembled to
+.Fn _thread_sys_write
+and
+.Fn write
+is implemented as a function which locks
+.Va d
+for read and write, then calls
+.Fn _thread_sys_write .
+If the call to
+.Fn _thread_sys_write
+would block, a context switch is performed. Before returning,
+.Fn write
+unlocks
+.Va d .
+.Pp
+In the non-threaded library
+.Fn writev
+is implemented as the
+.Va writev
+syscall.
+.Pp
+In the threaded library, the
+.Va writev
+syscall is assembled to
+.Fn _thread_sys_writev
+and
+.Fn writev
+is implemented as a function which locks
+.Va d
+for read and write, then calls
+.Fn _thread_sys_writev .
+If the call to
+.Fn _thread_sys_writev
+would block, a context switch is performed. Before returning,
+.Fn writev
+unlocks
+.Va d .
.Sh RETURN VALUES
Upon successful completion the number of bytes which were written
is returned. Otherwise a -1 is returned and the global variable
@@ -134,7 +181,7 @@ An attempt is made to write to a pipe that is not open
for reading by any process.
.It Bq Er EPIPE
An attempt is made to write to a socket of type
-.DV SOCK_STREAM
+.Dv SOCK_STREAM
that is not connected to a peer socket.
.It Bq Er EFBIG
An attempt was made to write a file that exceeds the process's
@@ -189,9 +236,10 @@ array overflowed a 32-bit integer.
.Xr pipe 2 ,
.Xr select 2
.Sh STANDARDS
-.Fn Write
-is expected to conform to IEEE Std 1003.1-1988
-.Pq Dq Tn POSIX .
+The
+.Fn write
+function call is expected to conform to
+.St -p1003.1-90 .
.Sh HISTORY
The
.Fn writev
@@ -199,7 +247,6 @@ function call
appeared in
.Bx 4.2 .
A
-.Nm write
-function call
-appeared in
-Version 6 AT&T UNIX.
+.Fn write
+function call appeared in
+.At v6 .
diff --git a/lib/libc/xdr/Makefile.inc b/lib/libc/xdr/Makefile.inc
new file mode 100644
index 0000000..a60acf4
--- /dev/null
+++ b/lib/libc/xdr/Makefile.inc
@@ -0,0 +1,44 @@
+# @(#)Makefile 5.11 (Berkeley) 9/6/90
+# $Id$
+
+.PATH: ${.CURDIR}/../libc/xdr ${.CURDIR}/.
+SRCS+= xdr.c xdr_array.c xdr_float.c xdr_mem.c \
+ xdr_rec.c xdr_reference.c xdr_stdio.c xdr_sizeof.c
+
+# Only build man pages with libc.
+.if ${LIB} == "c"
+MAN3+= xdr/xdr.3
+
+MLINKS+= xdr.3 xdr_array.3 \
+ xdr.3 xdr_bool.3 \
+ xdr.3 xdr_bytes.3 \
+ xdr.3 xdr_char.3 \
+ xdr.3 xdr_destroy.3 \
+ xdr.3 xdr_double.3 \
+ xdr.3 xdr_enum.3 \
+ xdr.3 xdr_float.3 \
+ xdr.3 xdr_free.3 \
+ xdr.3 xdr_getpos.3 \
+ xdr.3 xdr_inline.3 \
+ xdr.3 xdr_int.3 \
+ xdr.3 xdr_long.3 \
+ xdr.3 xdrmem_create.3 \
+ xdr.3 xdr_opaque.3 \
+ xdr.3 xdr_pointer.3 \
+ xdr.3 xdrrec_create.3 \
+ xdr.3 xdrrec_endofrecord.3 \
+ xdr.3 xdrrec_eof.3 \
+ xdr.3 xdrrec_skiprecord.3 \
+ xdr.3 xdr_reference.3 \
+ xdr.3 xdr_setpos.3 \
+ xdr.3 xdr_short.3 \
+ xdr.3 xdrstdio_create.3 \
+ xdr.3 xdr_string.3 \
+ xdr.3 xdr_u_char.3 \
+ xdr.3 xdr_u_long.3 \
+ xdr.3 xdr_u_short.3 \
+ xdr.3 xdr_union.3 \
+ xdr.3 xdr_vector.3 \
+ xdr.3 xdr_void.3 \
+ xdr.3 xdr_wrapstring.3
+.endif
diff --git a/lib/libc/xdr/xdr.3 b/lib/libc/xdr/xdr.3
new file mode 100644
index 0000000..f64e5b1
--- /dev/null
+++ b/lib/libc/xdr/xdr.3
@@ -0,0 +1,825 @@
+.\" @(#)xdr.3n 2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
+.\" $Id: xdr.3,v 1.3 1996/10/05 22:26:44 wosch Exp $
+.\"
+.TH XDR 3 "16 February 1988"
+.SH NAME
+xdr \- library routines for external data representation
+.SH SYNOPSIS AND DESCRIPTION
+.LP
+These routines allow C programmers to describe
+arbitrary data structures in a machine-independent fashion.
+Data for remote procedure calls are transmitted using these
+routines.
+.LP
+.ft B
+.nf
+.sp .5
+xdr_array(xdrs, arrp, sizep, maxsize, elsize, elproc)
+\s-1XDR\s0 *xdrs;
+char **arrp;
+u_int *sizep, maxsize, elsize;
+xdrproc_t elproc;
+.fi
+.ft R
+.IP
+A filter primitive that translates between variable-length
+arrays
+and their corresponding external representations. The
+parameter
+.I arrp
+is the address of the pointer to the array, while
+.I sizep
+is the address of the element count of the array;
+this element count cannot exceed
+.IR maxsize .
+The parameter
+.I elsize
+is the
+.I sizeof
+each of the array's elements, and
+.I elproc
+is an
+.SM XDR
+filter that translates between
+the array elements' C form, and their external
+representation.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdr_bool(xdrs, bp)
+\s-1XDR\s0 *xdrs;
+bool_t *bp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between booleans (C
+integers)
+and their external representations. When encoding data, this
+filter produces values of either one or zero.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+xdr_bytes(xdrs, sp, sizep, maxsize)
+\s-1XDR\s0 *xdrs;
+char **sp;
+u_int *sizep, maxsize;
+.fi
+.ft R
+.IP
+A filter primitive that translates between counted byte
+strings and their external representations.
+The parameter
+.I sp
+is the address of the string pointer. The length of the
+string is located at address
+.IR sizep ;
+strings cannot be longer than
+.IR maxsize .
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_char(xdrs, cp)
+\s-1XDR\s0 *xdrs;
+char *cp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C characters
+and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+Note: encoded characters are not packed, and occupy 4 bytes
+each. For arrays of characters, it is worthwhile to
+consider
+.BR xdr_bytes(\|) ,
+.B xdr_opaque(\|)
+or
+.BR xdr_string(\|) .
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdr_destroy(xdrs)
+\s-1XDR\s0 *xdrs;
+.fi
+.ft R
+.IP
+A macro that invokes the destroy routine associated with the
+.SM XDR
+stream,
+.IR xdrs .
+Destruction usually involves freeing private data structures
+associated with the stream. Using
+.I xdrs
+after invoking
+.B xdr_destroy(\|)
+is undefined.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_double(xdrs, dp)
+\s-1XDR\s0 *xdrs;
+double *dp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B double
+precision numbers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_enum(xdrs, ep)
+\s-1XDR\s0 *xdrs;
+enum_t *ep;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.BR enum s
+(actually integers) and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdr_float(xdrs, fp)
+\s-1XDR\s0 *xdrs;
+float *fp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.BR float s
+and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdr_free(proc, objp)
+xdrproc_t proc;
+char *objp;
+.fi
+.ft R
+.IP
+Generic freeing routine. The first argument is the
+.SM XDR
+routine for the object being freed. The second argument
+is a pointer to the object itself. Note: the pointer passed
+to this routine is
+.I not
+freed, but what it points to
+.I is
+freed (recursively).
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+u_int
+xdr_getpos(xdrs)
+\s-1XDR\s0 *xdrs;
+.fi
+.ft R
+.IP
+A macro that invokes the get-position routine
+associated with the
+.SM XDR
+stream,
+.IR xdrs .
+The routine returns an unsigned integer,
+which indicates the position of the
+.SM XDR
+byte stream.
+A desirable feature of
+.SM XDR
+streams is that simple arithmetic works with this number,
+although the
+.SM XDR
+stream instances need not guarantee this.
+.br
+.if t .ne 4
+.LP
+.ft B
+.nf
+.sp .5
+.br
+long *
+xdr_inline(xdrs, len)
+\s-1XDR\s0 *xdrs;
+int len;
+.fi
+.ft R
+.IP
+A macro that invokes the in-line routine associated with the
+.SM XDR
+stream,
+.IR xdrs .
+The routine returns a pointer
+to a contiguous piece of the stream's buffer;
+.I len
+is the byte length of the desired buffer.
+Note: pointer is cast to
+.BR "long *" .
+.IP
+Warning:
+.B xdr_inline(\|)
+may return
+.SM NULL
+(0)
+if it cannot allocate a contiguous piece of a buffer.
+Therefore the behavior may vary among stream instances;
+it exists for the sake of efficiency.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_int(xdrs, ip)
+\s-1XDR\s0 *xdrs;
+int *ip;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C integers
+and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_long(xdrs, lp)
+\s-1XDR\s0 *xdrs;
+long *lp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B long
+integers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 12
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdrmem_create(xdrs, addr, size, op)
+\s-1XDR\s0 *xdrs;
+char *addr;
+u_int size;
+enum xdr_op op;
+.fi
+.ft R
+.IP
+This routine initializes the
+.SM XDR
+stream object pointed to by
+.IR xdrs .
+The stream's data is written to, or read from,
+a chunk of memory at location
+.I addr
+whose length is no more than
+.I size
+bytes long. The
+.I op
+determines the direction of the
+.SM XDR
+stream
+(either
+.BR \s-1XDR_ENCODE\s0 ,
+.BR \s-1XDR_DECODE\s0 ,
+or
+.BR \s-1XDR_FREE\s0 ).
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+xdr_opaque(xdrs, cp, cnt)
+\s-1XDR\s0 *xdrs;
+char *cp;
+u_int cnt;
+.fi
+.ft R
+.IP
+A filter primitive that translates between fixed size opaque
+data
+and its external representation.
+The parameter
+.I cp
+is the address of the opaque object, and
+.I cnt
+is its size in bytes.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+xdr_pointer(xdrs, objpp, objsize, xdrobj)
+\s-1XDR\s0 *xdrs;
+char **objpp;
+u_int objsize;
+xdrproc_t xdrobj;
+.fi
+.ft R
+.IP
+Like
+.B xdr_reference(\|)
+execpt that it serializes
+.SM NULL
+pointers, whereas
+.B xdr_reference(\|)
+does not. Thus,
+.B xdr_pointer(\|)
+can represent
+recursive data structures, such as binary trees or
+linked lists.
+.br
+.if t .ne 15
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdrrec_create(xdrs, sendsize, recvsize, handle, readit, writeit)
+\s-1XDR\s0 *xdrs;
+u_int sendsize, recvsize;
+char *handle;
+int (*readit) (\|), (*writeit) (\|);
+.fi
+.ft R
+.IP
+This routine initializes the
+.SM XDR
+stream object pointed to by
+.IR xdrs .
+The stream's data is written to a buffer of size
+.IR sendsize ;
+a value of zero indicates the system should use a suitable
+default. The stream's data is read from a buffer of size
+.IR recvsize ;
+it too can be set to a suitable default by passing a zero
+value.
+When a stream's output buffer is full,
+.I writeit
+is called. Similarly, when a stream's input buffer is empty,
+.I readit
+is called. The behavior of these two routines is similar to
+the
+system calls
+.B read
+and
+.BR write ,
+except that
+.I handle
+is passed to the former routines as the first parameter.
+Note: the
+.SM XDR
+stream's
+.I op
+field must be set by the caller.
+.IP
+Warning: this
+.SM XDR
+stream implements an intermediate record stream.
+Therefore there are additional bytes in the stream
+to provide record boundary information.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+xdrrec_endofrecord(xdrs, sendnow)
+\s-1XDR\s0 *xdrs;
+int sendnow;
+.fi
+.ft R
+.IP
+This routine can be invoked only on
+streams created by
+.BR xdrrec_create(\|) .
+The data in the output buffer is marked as a completed
+record,
+and the output buffer is optionally written out if
+.I sendnow
+is non-zero. This routine returns one if it succeeds, zero
+otherwise.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdrrec_eof(xdrs)
+\s-1XDR\s0 *xdrs;
+int empty;
+.fi
+.ft R
+.IP
+This routine can be invoked only on
+streams created by
+.BR xdrrec_create(\|) .
+After consuming the rest of the current record in the stream,
+this routine returns one if the stream has no more input,
+zero otherwise.
+.br
+.if t .ne 3
+.LP
+.ft B
+.nf
+.sp .5
+xdrrec_skiprecord(xdrs)
+\s-1XDR\s0 *xdrs;
+.fi
+.ft R
+.IP
+This routine can be invoked only on
+streams created by
+.BR xdrrec_create(\|) .
+It tells the
+.SM XDR
+implementation that the rest of the current record
+in the stream's input buffer should be discarded.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 11
+.LP
+.ft B
+.nf
+.sp .5
+xdr_reference(xdrs, pp, size, proc)
+\s-1XDR\s0 *xdrs;
+char **pp;
+u_int size;
+xdrproc_t proc;
+.fi
+.ft R
+.IP
+A primitive that provides pointer chasing within structures.
+The parameter
+.I pp
+is the address of the pointer;
+.I size
+is the
+.I sizeof
+the structure that
+.I *pp
+points to; and
+.I proc
+is an
+.SM XDR
+procedure that filters the structure
+between its C form and its external representation.
+This routine returns one if it succeeds, zero otherwise.
+.IP
+Warning: this routine does not understand
+.SM NULL
+pointers. Use
+.B xdr_pointer(\|)
+instead.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+xdr_setpos(xdrs, pos)
+\s-1XDR\s0 *xdrs;
+u_int pos;
+.fi
+.ft R
+.IP
+A macro that invokes the set position routine associated with
+the
+.SM XDR
+stream
+.IR xdrs .
+The parameter
+.I pos
+is a position value obtained from
+.BR xdr_getpos(\|) .
+This routine returns one if the
+.SM XDR
+stream could be repositioned,
+and zero otherwise.
+.IP
+Warning: it is difficult to reposition some types of
+.SM XDR
+streams, so this routine may fail with one
+type of stream and succeed with another.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdr_short(xdrs, sp)
+\s-1XDR\s0 *xdrs;
+short *sp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B short
+integers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+void
+xdrstdio_create(xdrs, file, op)
+\s-1XDR\s0 *xdrs;
+\s-1FILE\s0 *file;
+enum xdr_op op;
+.fi
+.ft R
+.IP
+This routine initializes the
+.SM XDR
+stream object pointed to by
+.IR xdrs .
+The
+.SM XDR
+stream data is written to, or read from, the Standard
+.B I/O
+stream
+.IR file .
+The parameter
+.I op
+determines the direction of the
+.SM XDR
+stream (either
+.BR \s-1XDR_ENCODE\s0 ,
+.BR \s-1XDR_DECODE\s0 ,
+or
+.BR \s-1XDR_FREE\s0 ).
+.IP
+Warning: the destroy routine associated with such
+.SM XDR
+streams calls
+.B fflush(\|)
+on the
+.I file
+stream, but never
+.BR fclose(\|) .
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+xdr_string(xdrs, sp, maxsize)
+\s-1XDR\s0
+*xdrs;
+char **sp;
+u_int maxsize;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C strings and
+their
+corresponding external representations.
+Strings cannot be longer than
+.IR maxsize .
+Note:
+.I sp
+is the address of the string's pointer.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 8
+.LP
+.ft B
+.nf
+.sp .5
+xdr_u_char(xdrs, ucp)
+\s-1XDR\s0 *xdrs;
+unsigned char *ucp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between
+.B unsigned
+C characters and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 9
+.LP
+.ft B
+.nf
+.sp .5
+xdr_u_int(xdrs, up)
+\s-1XDR\s0 *xdrs;
+unsigned *up;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B unsigned
+integers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_u_long(xdrs, ulp)
+\s-1XDR\s0 *xdrs;
+unsigned long *ulp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B "unsigned long"
+integers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 7
+.LP
+.ft B
+.nf
+.sp .5
+xdr_u_short(xdrs, usp)
+\s-1XDR\s0 *xdrs;
+unsigned short *usp;
+.fi
+.ft R
+.IP
+A filter primitive that translates between C
+.B "unsigned short"
+integers and their external representations.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 16
+.LP
+.ft B
+.nf
+.sp .5
+xdr_union(xdrs, dscmp, unp, choices, dfault)
+\s-1XDR\s0 *xdrs;
+int *dscmp;
+char *unp;
+struct xdr_discrim *choices;
+bool_t (*defaultarm) (\|); /* may equal \s-1NULL\s0 */
+.fi
+.ft R
+.IP
+A filter primitive that translates between a discriminated C
+.B union
+and its corresponding external representation. It first
+translates the discriminant of the union located at
+.IR dscmp .
+This discriminant is always an
+.BR enum_t .
+Next the union located at
+.I unp
+is translated. The parameter
+.I choices
+is a pointer to an array of
+.B xdr_discrim(\|)
+structures. Each structure contains an ordered pair of
+.RI [ value , proc ].
+If the union's discriminant is equal to the associated
+.IR value ,
+then the
+.I proc
+is called to translate the union. The end of the
+.B xdr_discrim(\|)
+structure array is denoted by a routine of value
+.SM NULL\s0.
+If the discriminant is not found in the
+.I choices
+array, then the
+.I defaultarm
+procedure is called (if it is not
+.SM NULL\s0).
+Returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 6
+.LP
+.ft B
+.nf
+.sp .5
+xdr_vector(xdrs, arrp, size, elsize, elproc)
+\s-1XDR\s0 *xdrs;
+char *arrp;
+u_int size, elsize;
+xdrproc_t elproc;
+.fi
+.ft R
+.IP
+A filter primitive that translates between fixed-length
+arrays
+and their corresponding external representations. The
+parameter
+.I arrp
+is the address of the pointer to the array, while
+.I size
+is the element count of the array. The parameter
+.I elsize
+is the
+.I sizeof
+each of the array's elements, and
+.I elproc
+is an
+.SM XDR
+filter that translates between
+the array elements' C form, and their external
+representation.
+This routine returns one if it succeeds, zero otherwise.
+.br
+.if t .ne 5
+.LP
+.ft B
+.nf
+.sp .5
+xdr_void(\|)
+.fi
+.ft R
+.IP
+This routine always returns one.
+It may be passed to
+.SM RPC
+routines that require a function parameter,
+where nothing is to be done.
+.br
+.if t .ne 10
+.LP
+.ft B
+.nf
+.sp .5
+xdr_wrapstring(xdrs, sp)
+\s-1XDR\s0 *xdrs;
+char **sp;
+.fi
+.ft R
+.IP
+A primitive that calls
+.B "xdr_string(xdrs, sp,\s-1MAXUN.UNSIGNED\s0 );"
+where
+.B
+.SM MAXUN.UNSIGNED
+is the maximum value of an unsigned integer.
+.B xdr_wrapstring(\|)
+is handy because the
+.SM RPC
+package passes a maximum of two
+.SM XDR
+routines as parameters, and
+.BR xdr_string(\|) ,
+one of the most frequently used primitives, requires three.
+Returns one if it succeeds, zero otherwise.
+.SH SEE ALSO
+.BR rpc (3)
+.LP
+The following manuals:
+.RS
+.ft I
+eXternal Data Representation Standard: Protocol Specification
+.br
+eXternal Data Representation: Sun Technical Notes
+.ft R
+.br
+.IR "\s-1XDR\s0: External Data Representation Standard" ,
+.SM RFC1014, Sun Microsystems, Inc.,
+.SM USC-ISI\s0.
diff --git a/lib/libc/xdr/xdr.c b/lib/libc/xdr/xdr.c
new file mode 100644
index 0000000..12a787e
--- /dev/null
+++ b/lib/libc/xdr/xdr.c
@@ -0,0 +1,719 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr.c 1.35 87/08/12";*/
+/*static char *sccsid = "from: @(#)xdr.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: xdr.c,v 1.4 1996/12/30 14:07:07 peter Exp $";
+#endif
+
+/*
+ * xdr.c, Generic XDR routines implementation.
+ *
+ * Copyright (C) 1986, Sun Microsystems, Inc.
+ *
+ * These are the "generic" xdr routines used to serialize and de-serialize
+ * most common data items. See xdr.h for more info on the interface to
+ * xdr.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+/*
+ * constants specific to the xdr "protocol"
+ */
+#define XDR_FALSE ((long) 0)
+#define XDR_TRUE ((long) 1)
+#define LASTUNSIGNED ((u_int) 0-1)
+
+/*
+ * for unit alignment
+ */
+static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
+
+/*
+ * Free a data structure using XDR
+ * Not a filter, but a convenient utility nonetheless
+ */
+void
+xdr_free(proc, objp)
+ xdrproc_t proc;
+ char *objp;
+{
+ XDR x;
+
+ x.x_op = XDR_FREE;
+ (*proc)(&x, objp);
+}
+
+/*
+ * XDR nothing
+ */
+bool_t
+xdr_void(/* xdrs, addr */)
+ /* XDR *xdrs; */
+ /* caddr_t addr; */
+{
+
+ return (TRUE);
+}
+
+
+/*
+ * XDR integers
+ */
+bool_t
+xdr_int(xdrs, ip)
+ XDR *xdrs;
+ int *ip;
+{
+ long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (long) *ip;
+ return (XDR_PUTLONG(xdrs, &l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &l)) {
+ return (FALSE);
+ }
+ *ip = (int) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned integers
+ */
+bool_t
+xdr_u_int(xdrs, up)
+ XDR *xdrs;
+ u_int *up;
+{
+ u_long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (u_long) *up;
+ return (XDR_PUTLONG(xdrs, (long *)&l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, (long *)&l)) {
+ return (FALSE);
+ }
+ *up = (u_int) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+
+/*
+ * XDR long integers
+ * same as xdr_u_long - open coded to save a proc call!
+ */
+bool_t
+xdr_long(xdrs, lp)
+ register XDR *xdrs;
+ long *lp;
+{
+ switch (xdrs->x_op) {
+ case XDR_ENCODE:
+ return (XDR_PUTLONG(xdrs, lp));
+ case XDR_DECODE:
+ return (XDR_GETLONG(xdrs, lp));
+ case XDR_FREE:
+ return (TRUE);
+ }
+
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned long integers
+ * same as xdr_long - open coded to save a proc call!
+ */
+bool_t
+xdr_u_long(xdrs, ulp)
+ register XDR *xdrs;
+ u_long *ulp;
+{
+ switch (xdrs->x_op) {
+ case XDR_ENCODE:
+ return (XDR_PUTLONG(xdrs, (long *)ulp));
+ case XDR_DECODE:
+ return (XDR_GETLONG(xdrs, (long *)ulp));
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+
+/*
+ * XDR 32-bit integers
+ * same as xdr_u_int32_t - open coded to save a proc call!
+ */
+bool_t
+xdr_int32_t(xdrs, int32_p)
+ register XDR *xdrs;
+ int32_t *int32_p;
+{
+ long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (long) *int32_p;
+ return (XDR_PUTLONG(xdrs, &l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &l)) {
+ return (FALSE);
+ }
+ *int32_p = (int32_t) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned 32-bit integers
+ * same as xdr_int32_t - open coded to save a proc call!
+ */
+bool_t
+xdr_u_int32_t(xdrs, u_int32_p)
+ register XDR *xdrs;
+ u_int32_t *u_int32_p;
+{
+ u_long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (u_long) *u_int32_p;
+ return (XDR_PUTLONG(xdrs, (long *)&l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, (long *)&l)) {
+ return (FALSE);
+ }
+ *u_int32_p = (u_int32_t) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+
+/*
+ * XDR short integers
+ */
+bool_t
+xdr_short(xdrs, sp)
+ register XDR *xdrs;
+ short *sp;
+{
+ long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (long) *sp;
+ return (XDR_PUTLONG(xdrs, &l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &l)) {
+ return (FALSE);
+ }
+ *sp = (short) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned short integers
+ */
+bool_t
+xdr_u_short(xdrs, usp)
+ register XDR *xdrs;
+ u_short *usp;
+{
+ u_long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (u_long) *usp;
+ return (XDR_PUTLONG(xdrs, (long *)&l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, (long *)&l)) {
+ return (FALSE);
+ }
+ *usp = (u_short) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+
+/*
+ * XDR 16-bit integers
+ */
+bool_t
+xdr_int16_t(xdrs, int16_p)
+ register XDR *xdrs;
+ int16_t *int16_p;
+{
+ long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (long) *int16_p;
+ return (XDR_PUTLONG(xdrs, &l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &l)) {
+ return (FALSE);
+ }
+ *int16_p = (int16_t) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR unsigned 16-bit integers
+ */
+bool_t
+xdr_u_int16_t(xdrs, u_int16_p)
+ register XDR *xdrs;
+ u_int16_t *u_int16_p;
+{
+ u_long l;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ l = (u_long) *u_int16_p;
+ return (XDR_PUTLONG(xdrs, (long *)&l));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, (long *)&l)) {
+ return (FALSE);
+ }
+ *u_int16_p = (u_int16_t) l;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+
+/*
+ * XDR a char
+ */
+bool_t
+xdr_char(xdrs, cp)
+ XDR *xdrs;
+ char *cp;
+{
+ int i;
+
+ i = (*cp);
+ if (!xdr_int(xdrs, &i)) {
+ return (FALSE);
+ }
+ *cp = i;
+ return (TRUE);
+}
+
+/*
+ * XDR an unsigned char
+ */
+bool_t
+xdr_u_char(xdrs, cp)
+ XDR *xdrs;
+ u_char *cp;
+{
+ u_int u;
+
+ u = (*cp);
+ if (!xdr_u_int(xdrs, &u)) {
+ return (FALSE);
+ }
+ *cp = u;
+ return (TRUE);
+}
+
+/*
+ * XDR booleans
+ */
+bool_t
+xdr_bool(xdrs, bp)
+ register XDR *xdrs;
+ bool_t *bp;
+{
+ long lb;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ lb = *bp ? XDR_TRUE : XDR_FALSE;
+ return (XDR_PUTLONG(xdrs, &lb));
+
+ case XDR_DECODE:
+ if (!XDR_GETLONG(xdrs, &lb)) {
+ return (FALSE);
+ }
+ *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
+ return (TRUE);
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * XDR enumerations
+ */
+bool_t
+xdr_enum(xdrs, ep)
+ XDR *xdrs;
+ enum_t *ep;
+{
+#ifndef lint
+ enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
+
+ /*
+ * enums are treated as ints
+ */
+ if (sizeof (enum sizecheck) == sizeof (long)) {
+ return (xdr_long(xdrs, (long *)ep));
+ } else if (sizeof (enum sizecheck) == sizeof (int)) {
+ return (xdr_int(xdrs, (int *)ep));
+ } else if (sizeof (enum sizecheck) == sizeof (short)) {
+ return (xdr_short(xdrs, (short *)ep));
+ } else {
+ return (FALSE);
+ }
+#else
+ (void) (xdr_short(xdrs, (short *)ep));
+ (void) (xdr_int(xdrs, (int *)ep));
+ return (xdr_long(xdrs, (long *)ep));
+#endif
+}
+
+/*
+ * XDR opaque data
+ * Allows the specification of a fixed size sequence of opaque bytes.
+ * cp points to the opaque object and cnt gives the byte length.
+ */
+bool_t
+xdr_opaque(xdrs, cp, cnt)
+ register XDR *xdrs;
+ caddr_t cp;
+ register u_int cnt;
+{
+ register u_int rndup;
+ static crud[BYTES_PER_XDR_UNIT];
+
+ /*
+ * if no data we are done
+ */
+ if (cnt == 0)
+ return (TRUE);
+
+ /*
+ * round byte count to full xdr units
+ */
+ rndup = cnt % BYTES_PER_XDR_UNIT;
+ if (rndup > 0)
+ rndup = BYTES_PER_XDR_UNIT - rndup;
+
+ if (xdrs->x_op == XDR_DECODE) {
+ if (!XDR_GETBYTES(xdrs, cp, cnt)) {
+ return (FALSE);
+ }
+ if (rndup == 0)
+ return (TRUE);
+ return (XDR_GETBYTES(xdrs, (caddr_t)crud, rndup));
+ }
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
+ return (FALSE);
+ }
+ if (rndup == 0)
+ return (TRUE);
+ return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
+ }
+
+ if (xdrs->x_op == XDR_FREE) {
+ return (TRUE);
+ }
+
+ return (FALSE);
+}
+
+/*
+ * XDR counted bytes
+ * *cpp is a pointer to the bytes, *sizep is the count.
+ * If *cpp is NULL maxsize bytes are allocated
+ */
+bool_t
+xdr_bytes(xdrs, cpp, sizep, maxsize)
+ register XDR *xdrs;
+ char **cpp;
+ register u_int *sizep;
+ u_int maxsize;
+{
+ register char *sp = *cpp; /* sp is the actual string pointer */
+ register u_int nodesize;
+
+ /*
+ * first deal with the length since xdr bytes are counted
+ */
+ if (! xdr_u_int(xdrs, sizep)) {
+ return (FALSE);
+ }
+ nodesize = *sizep;
+ if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) {
+ return (FALSE);
+ }
+
+ /*
+ * now deal with the actual bytes
+ */
+ switch (xdrs->x_op) {
+
+ case XDR_DECODE:
+ if (nodesize == 0) {
+ return (TRUE);
+ }
+ if (sp == NULL) {
+ *cpp = sp = (char *)mem_alloc(nodesize);
+ }
+ if (sp == NULL) {
+ (void) fprintf(stderr, "xdr_bytes: out of memory\n");
+ return (FALSE);
+ }
+ /* fall into ... */
+
+ case XDR_ENCODE:
+ return (xdr_opaque(xdrs, sp, nodesize));
+
+ case XDR_FREE:
+ if (sp != NULL) {
+ mem_free(sp, nodesize);
+ *cpp = NULL;
+ }
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * Implemented here due to commonality of the object.
+ */
+bool_t
+xdr_netobj(xdrs, np)
+ XDR *xdrs;
+ struct netobj *np;
+{
+
+ return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ));
+}
+
+/*
+ * XDR a descriminated union
+ * Support routine for discriminated unions.
+ * You create an array of xdrdiscrim structures, terminated with
+ * an entry with a null procedure pointer. The routine gets
+ * the discriminant value and then searches the array of xdrdiscrims
+ * looking for that value. It calls the procedure given in the xdrdiscrim
+ * to handle the discriminant. If there is no specific routine a default
+ * routine may be called.
+ * If there is no specific or default routine an error is returned.
+ */
+bool_t
+xdr_union(xdrs, dscmp, unp, choices, dfault)
+ register XDR *xdrs;
+ enum_t *dscmp; /* enum to decide which arm to work on */
+ char *unp; /* the union itself */
+ struct xdr_discrim *choices; /* [value, xdr proc] for each arm */
+ xdrproc_t dfault; /* default xdr routine */
+{
+ register enum_t dscm;
+
+ /*
+ * we deal with the discriminator; it's an enum
+ */
+ if (! xdr_enum(xdrs, dscmp)) {
+ return (FALSE);
+ }
+ dscm = *dscmp;
+
+ /*
+ * search choices for a value that matches the discriminator.
+ * if we find one, execute the xdr routine for that value.
+ */
+ for (; choices->proc != NULL_xdrproc_t; choices++) {
+ if (choices->value == dscm)
+ return ((*(choices->proc))(xdrs, unp, LASTUNSIGNED));
+ }
+
+ /*
+ * no match - execute the default xdr routine if there is one
+ */
+ return ((dfault == NULL_xdrproc_t) ? FALSE :
+ (*dfault)(xdrs, unp, LASTUNSIGNED));
+}
+
+
+/*
+ * Non-portable xdr primitives.
+ * Care should be taken when moving these routines to new architectures.
+ */
+
+
+/*
+ * XDR null terminated ASCII strings
+ * xdr_string deals with "C strings" - arrays of bytes that are
+ * terminated by a NULL character. The parameter cpp references a
+ * pointer to storage; If the pointer is null, then the necessary
+ * storage is allocated. The last parameter is the max allowed length
+ * of the string as specified by a protocol.
+ */
+bool_t
+xdr_string(xdrs, cpp, maxsize)
+ register XDR *xdrs;
+ char **cpp;
+ u_int maxsize;
+{
+ register char *sp = *cpp; /* sp is the actual string pointer */
+ u_int size;
+ u_int nodesize;
+
+ /*
+ * first deal with the length since xdr strings are counted-strings
+ */
+ switch (xdrs->x_op) {
+ case XDR_FREE:
+ if (sp == NULL) {
+ return(TRUE); /* already free */
+ }
+ /* fall through... */
+ case XDR_ENCODE:
+ size = strlen(sp);
+ break;
+ }
+ if (! xdr_u_int(xdrs, &size)) {
+ return (FALSE);
+ }
+ if (size > maxsize) {
+ return (FALSE);
+ }
+ nodesize = size + 1;
+
+ /*
+ * now deal with the actual bytes
+ */
+ switch (xdrs->x_op) {
+
+ case XDR_DECODE:
+ if (nodesize == 0) {
+ return (TRUE);
+ }
+ if (sp == NULL)
+ *cpp = sp = (char *)mem_alloc(nodesize);
+ if (sp == NULL) {
+ (void) fprintf(stderr, "xdr_string: out of memory\n");
+ return (FALSE);
+ }
+ sp[size] = 0;
+ /* fall into ... */
+
+ case XDR_ENCODE:
+ return (xdr_opaque(xdrs, sp, size));
+
+ case XDR_FREE:
+ mem_free(sp, nodesize);
+ *cpp = NULL;
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * Wrapper for xdr_string that can be called directly from
+ * routines like clnt_call
+ */
+bool_t
+xdr_wrapstring(xdrs, cpp)
+ XDR *xdrs;
+ char **cpp;
+{
+ return xdr_string(xdrs, cpp, LASTUNSIGNED);
+}
diff --git a/lib/libc/xdr/xdr_array.c b/lib/libc/xdr/xdr_array.c
new file mode 100644
index 0000000..f9c34ab
--- /dev/null
+++ b/lib/libc/xdr/xdr_array.c
@@ -0,0 +1,155 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_array.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: xdr_array.c,v 1.4 1996/12/30 14:07:08 peter Exp $";
+#endif
+
+/*
+ * xdr_array.c, Generic XDR routines impelmentation.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * These are the "non-trivial" xdr primitives used to serialize and de-serialize
+ * arrays. See xdr.h for more info on the interface to xdr.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#define LASTUNSIGNED ((u_int) 0-1)
+
+/*
+ * XDR an array of arbitrary elements
+ * *addrp is a pointer to the array, *sizep is the number of elements.
+ * If addrp is NULL (*sizep * elsize) bytes are allocated.
+ * elsize is the size (in bytes) of each element, and elproc is the
+ * xdr procedure to call to handle each element of the array.
+ */
+bool_t
+xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc)
+ register XDR *xdrs;
+ caddr_t *addrp; /* array pointer */
+ u_int *sizep; /* number of elements */
+ u_int maxsize; /* max numberof elements */
+ u_int elsize; /* size in bytes of each element */
+ xdrproc_t elproc; /* xdr routine to handle each element */
+{
+ register u_int i;
+ register caddr_t target = *addrp;
+ register u_int c; /* the actual element count */
+ register bool_t stat = TRUE;
+ register u_int nodesize;
+
+ /* like strings, arrays are really counted arrays */
+ if (! xdr_u_int(xdrs, sizep)) {
+ return (FALSE);
+ }
+ c = *sizep;
+ if ((c > maxsize) && (xdrs->x_op != XDR_FREE)) {
+ return (FALSE);
+ }
+ nodesize = c * elsize;
+
+ /*
+ * if we are deserializing, we may need to allocate an array.
+ * We also save time by checking for a null array if we are freeing.
+ */
+ if (target == NULL)
+ switch (xdrs->x_op) {
+ case XDR_DECODE:
+ if (c == 0)
+ return (TRUE);
+ *addrp = target = mem_alloc(nodesize);
+ if (target == NULL) {
+ (void) fprintf(stderr,
+ "xdr_array: out of memory\n");
+ return (FALSE);
+ }
+ memset(target, 0, nodesize);
+ break;
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+
+ /*
+ * now we xdr each element of array
+ */
+ for (i = 0; (i < c) && stat; i++) {
+ stat = (*elproc)(xdrs, target, LASTUNSIGNED);
+ target += elsize;
+ }
+
+ /*
+ * the array may need freeing
+ */
+ if (xdrs->x_op == XDR_FREE) {
+ mem_free(*addrp, nodesize);
+ *addrp = NULL;
+ }
+ return (stat);
+}
+
+/*
+ * xdr_vector():
+ *
+ * XDR a fixed length array. Unlike variable-length arrays,
+ * the storage of fixed length arrays is static and unfreeable.
+ * > basep: base of the array
+ * > size: size of the array
+ * > elemsize: size of each element
+ * > xdr_elem: routine to XDR each element
+ */
+bool_t
+xdr_vector(xdrs, basep, nelem, elemsize, xdr_elem)
+ register XDR *xdrs;
+ register char *basep;
+ register u_int nelem;
+ register u_int elemsize;
+ register xdrproc_t xdr_elem;
+{
+ register u_int i;
+ register char *elptr;
+
+ elptr = basep;
+ for (i = 0; i < nelem; i++) {
+ if (! (*xdr_elem)(xdrs, elptr, LASTUNSIGNED)) {
+ return(FALSE);
+ }
+ elptr += elemsize;
+ }
+ return(TRUE);
+}
+
diff --git a/lib/libc/xdr/xdr_float.c b/lib/libc/xdr/xdr_float.c
new file mode 100644
index 0000000..b8c8f60
--- /dev/null
+++ b/lib/libc/xdr/xdr_float.c
@@ -0,0 +1,314 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_float.c 1.12 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_float.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: xdr_float.c,v 1.3 1996/12/30 14:07:08 peter Exp $";
+#endif
+
+/*
+ * xdr_float.c, Generic XDR routines impelmentation.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * These are the "floating point" xdr routines used to (de)serialize
+ * most common data items. See xdr.h for more info on the interface to
+ * xdr.
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+/*
+ * NB: Not portable.
+ * This routine works on machines with IEEE754 FP and Vaxen.
+ */
+
+#if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \
+ defined(__mips__) || defined(__ns32k__) || defined(__alpha__) || \
+ defined(__arm32__) || defined(__ppc__)
+#include <machine/endian.h>
+#define IEEEFP
+#endif
+
+#ifdef vax
+
+/* What IEEE single precision floating point looks like on a Vax */
+struct ieee_single {
+ unsigned int mantissa: 23;
+ unsigned int exp : 8;
+ unsigned int sign : 1;
+};
+
+/* Vax single precision floating point */
+struct vax_single {
+ unsigned int mantissa1 : 7;
+ unsigned int exp : 8;
+ unsigned int sign : 1;
+ unsigned int mantissa2 : 16;
+};
+
+#define VAX_SNG_BIAS 0x81
+#define IEEE_SNG_BIAS 0x7f
+
+static struct sgl_limits {
+ struct vax_single s;
+ struct ieee_single ieee;
+} sgl_limits[2] = {
+ {{ 0x7f, 0xff, 0x0, 0xffff }, /* Max Vax */
+ { 0x0, 0xff, 0x0 }}, /* Max IEEE */
+ {{ 0x0, 0x0, 0x0, 0x0 }, /* Min Vax */
+ { 0x0, 0x0, 0x0 }} /* Min IEEE */
+};
+#endif /* vax */
+
+bool_t
+xdr_float(xdrs, fp)
+ register XDR *xdrs;
+ register float *fp;
+{
+#ifdef IEEEFP
+ bool_t rv;
+ long tmpl;
+#else
+ struct ieee_single is;
+ struct vax_single vs, *vsp;
+ struct sgl_limits *lim;
+ int i;
+#endif
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+#ifdef IEEEFP
+ tmpl = *(int32_t *)fp;
+ return (XDR_PUTLONG(xdrs, &tmpl));
+#else
+ vs = *((struct vax_single *)fp);
+ for (i = 0, lim = sgl_limits;
+ i < sizeof(sgl_limits)/sizeof(struct sgl_limits);
+ i++, lim++) {
+ if ((vs.mantissa2 == lim->s.mantissa2) &&
+ (vs.exp == lim->s.exp) &&
+ (vs.mantissa1 == lim->s.mantissa1)) {
+ is = lim->ieee;
+ goto shipit;
+ }
+ }
+ is.exp = vs.exp - VAX_SNG_BIAS + IEEE_SNG_BIAS;
+ is.mantissa = (vs.mantissa1 << 16) | vs.mantissa2;
+ shipit:
+ is.sign = vs.sign;
+ return (XDR_PUTLONG(xdrs, (long *)&is));
+#endif
+
+ case XDR_DECODE:
+#ifdef IEEEFP
+ rv = XDR_GETLONG(xdrs, &tmpl);
+ *(int32_t *)fp = tmpl;
+ return (rv);
+#else
+ vsp = (struct vax_single *)fp;
+ if (!XDR_GETLONG(xdrs, (long *)&is))
+ return (FALSE);
+ for (i = 0, lim = sgl_limits;
+ i < sizeof(sgl_limits)/sizeof(struct sgl_limits);
+ i++, lim++) {
+ if ((is.exp == lim->ieee.exp) &&
+ (is.mantissa == lim->ieee.mantissa)) {
+ *vsp = lim->s;
+ goto doneit;
+ }
+ }
+ vsp->exp = is.exp - IEEE_SNG_BIAS + VAX_SNG_BIAS;
+ vsp->mantissa2 = is.mantissa;
+ vsp->mantissa1 = (is.mantissa >> 16);
+ doneit:
+ vsp->sign = is.sign;
+ return (TRUE);
+#endif
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+#ifdef vax
+/* What IEEE double precision floating point looks like on a Vax */
+struct ieee_double {
+ unsigned int mantissa1 : 20;
+ unsigned int exp : 11;
+ unsigned int sign : 1;
+ unsigned int mantissa2 : 32;
+};
+
+/* Vax double precision floating point */
+struct vax_double {
+ unsigned int mantissa1 : 7;
+ unsigned int exp : 8;
+ unsigned int sign : 1;
+ unsigned int mantissa2 : 16;
+ unsigned int mantissa3 : 16;
+ unsigned int mantissa4 : 16;
+};
+
+#define VAX_DBL_BIAS 0x81
+#define IEEE_DBL_BIAS 0x3ff
+#define MASK(nbits) ((1 << nbits) - 1)
+
+static struct dbl_limits {
+ struct vax_double d;
+ struct ieee_double ieee;
+} dbl_limits[2] = {
+ {{ 0x7f, 0xff, 0x0, 0xffff, 0xffff, 0xffff }, /* Max Vax */
+ { 0x0, 0x7ff, 0x0, 0x0 }}, /* Max IEEE */
+ {{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* Min Vax */
+ { 0x0, 0x0, 0x0, 0x0 }} /* Min IEEE */
+};
+
+#endif /* vax */
+
+
+bool_t
+xdr_double(xdrs, dp)
+ register XDR *xdrs;
+ double *dp;
+{
+#ifdef IEEEFP
+ register int32_t *i32p;
+ bool_t rv;
+ long tmpl;
+#else
+ register long *lp;
+ struct ieee_double id;
+ struct vax_double vd;
+ register struct dbl_limits *lim;
+ int i;
+#endif
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+#ifdef IEEEFP
+ i32p = (int32_t *)dp;
+#if BYTE_ORDER == BIG_ENDIAN
+ tmpl = *i32p++;
+ rv = XDR_PUTLONG(xdrs, &tmpl);
+ if (!rv)
+ return (rv);
+ tmpl = *i32p;
+ rv = XDR_PUTLONG(xdrs, &tmpl);
+#else
+ tmpl = *(i32p+1);
+ rv = XDR_PUTLONG(xdrs, &tmpl);
+ if (!rv)
+ return (rv);
+ tmpl = *i32p;
+ rv = XDR_PUTLONG(xdrs, &tmpl);
+#endif
+ return (rv);
+#else
+ vd = *((struct vax_double *)dp);
+ for (i = 0, lim = dbl_limits;
+ i < sizeof(dbl_limits)/sizeof(struct dbl_limits);
+ i++, lim++) {
+ if ((vd.mantissa4 == lim->d.mantissa4) &&
+ (vd.mantissa3 == lim->d.mantissa3) &&
+ (vd.mantissa2 == lim->d.mantissa2) &&
+ (vd.mantissa1 == lim->d.mantissa1) &&
+ (vd.exp == lim->d.exp)) {
+ id = lim->ieee;
+ goto shipit;
+ }
+ }
+ id.exp = vd.exp - VAX_DBL_BIAS + IEEE_DBL_BIAS;
+ id.mantissa1 = (vd.mantissa1 << 13) | (vd.mantissa2 >> 3);
+ id.mantissa2 = ((vd.mantissa2 & MASK(3)) << 29) |
+ (vd.mantissa3 << 13) |
+ ((vd.mantissa4 >> 3) & MASK(13));
+ shipit:
+ id.sign = vd.sign;
+ lp = (long *)&id;
+ return (XDR_PUTLONG(xdrs, lp++) && XDR_PUTLONG(xdrs, lp));
+#endif
+
+ case XDR_DECODE:
+#ifdef IEEEFP
+ i32p = (int32_t *)dp;
+#if BYTE_ORDER == BIG_ENDIAN
+ rv = XDR_GETLONG(xdrs, &tmpl);
+ *i32p++ = tmpl;
+ if (!rv)
+ return (rv);
+ rv = XDR_GETLONG(xdrs, &tmpl);
+ *i32p = tmpl;
+#else
+ rv = XDR_GETLONG(xdrs, &tmpl);
+ *(i32p+1) = tmpl;
+ if (!rv)
+ return (rv);
+ rv = XDR_GETLONG(xdrs, &tmpl);
+ *i32p = tmpl;
+#endif
+ return (rv);
+#else
+ lp = (long *)&id;
+ if (!XDR_GETLONG(xdrs, lp++) || !XDR_GETLONG(xdrs, lp))
+ return (FALSE);
+ for (i = 0, lim = dbl_limits;
+ i < sizeof(dbl_limits)/sizeof(struct dbl_limits);
+ i++, lim++) {
+ if ((id.mantissa2 == lim->ieee.mantissa2) &&
+ (id.mantissa1 == lim->ieee.mantissa1) &&
+ (id.exp == lim->ieee.exp)) {
+ vd = lim->d;
+ goto doneit;
+ }
+ }
+ vd.exp = id.exp - IEEE_DBL_BIAS + VAX_DBL_BIAS;
+ vd.mantissa1 = (id.mantissa1 >> 13);
+ vd.mantissa2 = ((id.mantissa1 & MASK(13)) << 3) |
+ (id.mantissa2 >> 29);
+ vd.mantissa3 = (id.mantissa2 >> 13);
+ vd.mantissa4 = (id.mantissa2 << 3);
+ doneit:
+ vd.sign = id.sign;
+ *dp = *((double *)&vd);
+ return (TRUE);
+#endif
+
+ case XDR_FREE:
+ return (TRUE);
+ }
+ return (FALSE);
+}
diff --git a/lib/libc/xdr/xdr_mem.c b/lib/libc/xdr/xdr_mem.c
new file mode 100644
index 0000000..36b9ada
--- /dev/null
+++ b/lib/libc/xdr/xdr_mem.c
@@ -0,0 +1,242 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: xdr_mem.c,v 1.4 1996/12/30 14:07:09 peter Exp $";
+#endif
+
+/*
+ * xdr_mem.h, XDR implementation using memory buffers.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * If you have some data to be interpreted as external data representation
+ * or to be converted to external data representation in a memory buffer,
+ * then this is the package for you.
+ *
+ */
+
+#include <string.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <netinet/in.h>
+
+static bool_t xdrmem_getlong_aligned();
+static bool_t xdrmem_putlong_aligned();
+static bool_t xdrmem_getlong_unaligned();
+static bool_t xdrmem_putlong_unaligned();
+static bool_t xdrmem_getbytes();
+static bool_t xdrmem_putbytes();
+static u_int xdrmem_getpos(); /* XXX w/64-bit pointers, u_int not enough! */
+static bool_t xdrmem_setpos();
+static int32_t *xdrmem_inline_aligned();
+static int32_t *xdrmem_inline_unaligned();
+static void xdrmem_destroy();
+
+static struct xdr_ops xdrmem_ops_aligned = {
+ xdrmem_getlong_aligned,
+ xdrmem_putlong_aligned,
+ xdrmem_getbytes,
+ xdrmem_putbytes,
+ xdrmem_getpos,
+ xdrmem_setpos,
+ xdrmem_inline_aligned,
+ xdrmem_destroy
+};
+
+static struct xdr_ops xdrmem_ops_unaligned = {
+ xdrmem_getlong_unaligned,
+ xdrmem_putlong_unaligned,
+ xdrmem_getbytes,
+ xdrmem_putbytes,
+ xdrmem_getpos,
+ xdrmem_setpos,
+ xdrmem_inline_unaligned,
+ xdrmem_destroy
+};
+
+/*
+ * The procedure xdrmem_create initializes a stream descriptor for a
+ * memory buffer.
+ */
+void
+xdrmem_create(xdrs, addr, size, op)
+ register XDR *xdrs;
+ caddr_t addr;
+ u_int size;
+ enum xdr_op op;
+{
+
+ xdrs->x_op = op;
+ xdrs->x_ops = ((size_t)addr & (sizeof(int32_t) - 1))
+ ? &xdrmem_ops_unaligned : &xdrmem_ops_aligned;
+ xdrs->x_private = xdrs->x_base = addr;
+ xdrs->x_handy = size;
+}
+
+static void
+xdrmem_destroy(/*xdrs*/)
+ /*XDR *xdrs;*/
+{
+
+}
+
+static bool_t
+xdrmem_getlong_aligned(xdrs, lp)
+ register XDR *xdrs;
+ long *lp;
+{
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ *lp = ntohl(*(int32_t *)(xdrs->x_private));
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_putlong_aligned(xdrs, lp)
+ register XDR *xdrs;
+ long *lp;
+{
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ *(int32_t *)xdrs->x_private = htonl(*lp);
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_getlong_unaligned(xdrs, lp)
+ register XDR *xdrs;
+ long *lp;
+{
+ int32_t l;
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ memcpy(&l, xdrs->x_private, sizeof(int32_t));
+ *lp = ntohl(l);
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_putlong_unaligned(xdrs, lp)
+ register XDR *xdrs;
+ long *lp;
+{
+ int32_t l;
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ l = htonl(*lp);
+ memcpy(xdrs->x_private, &l, sizeof(int32_t));
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_getbytes(xdrs, addr, len)
+ register XDR *xdrs;
+ caddr_t addr;
+ register u_int len;
+{
+
+ if ((xdrs->x_handy -= len) < 0)
+ return (FALSE);
+ memcpy(addr, xdrs->x_private, len);
+ xdrs->x_private += len;
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_putbytes(xdrs, addr, len)
+ register XDR *xdrs;
+ caddr_t addr;
+ register u_int len;
+{
+
+ if ((xdrs->x_handy -= len) < 0)
+ return (FALSE);
+ memcpy(xdrs->x_private, addr, len);
+ xdrs->x_private += len;
+ return (TRUE);
+}
+
+static u_int
+xdrmem_getpos(xdrs)
+ register XDR *xdrs;
+{
+
+ /* XXX w/64-bit pointers, u_int not enough! */
+ return ((u_long)xdrs->x_private - (u_long)xdrs->x_base);
+}
+
+static bool_t
+xdrmem_setpos(xdrs, pos)
+ register XDR *xdrs;
+ u_int pos;
+{
+ register caddr_t newaddr = xdrs->x_base + pos;
+ register caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
+
+ if ((long)newaddr > (long)lastaddr)
+ return (FALSE);
+ xdrs->x_private = newaddr;
+ xdrs->x_handy = (long)lastaddr - (long)newaddr;
+ return (TRUE);
+}
+
+static int32_t *
+xdrmem_inline_aligned(xdrs, len)
+ register XDR *xdrs;
+ int len;
+{
+ int32_t *buf = 0;
+
+ if (xdrs->x_handy >= len) {
+ xdrs->x_handy -= len;
+ buf = (int32_t *) xdrs->x_private;
+ xdrs->x_private += len;
+ }
+ return (buf);
+}
+
+static int32_t *
+xdrmem_inline_unaligned(xdrs, len)
+ register XDR *xdrs;
+ int len;
+{
+
+ return (0);
+}
diff --git a/lib/libc/xdr/xdr_rec.c b/lib/libc/xdr/xdr_rec.c
new file mode 100644
index 0000000..f54172b
--- /dev/null
+++ b/lib/libc/xdr/xdr_rec.c
@@ -0,0 +1,586 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_rec.c 1.21 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_rec.c 2.2 88/08/01 4.0 RPCSRC";*/
+static char *rcsid = "$Id: xdr_rec.c,v 1.5 1996/12/30 14:07:10 peter Exp $";
+#endif
+
+/*
+ * xdr_rec.c, Implements TCP/IP based XDR streams with a "record marking"
+ * layer above tcp (for rpc's use).
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * These routines interface XDRSTREAMS to a tcp/ip connection.
+ * There is a record marking layer between the xdr stream
+ * and the tcp transport level. A record is composed on one or more
+ * record fragments. A record fragment is a thirty-two bit header followed
+ * by n bytes of data, where n is contained in the header. The header
+ * is represented as a htonl(u_long). Thegh order bit encodes
+ * whether or not the fragment is the last fragment of the record
+ * (1 => fragment is last, 0 => more fragments to follow.
+ * The other 31 bits encode the byte length of the fragment.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <netinet/in.h>
+
+static u_int fix_buf_size();
+static bool_t flush_out();
+static bool_t get_input_bytes();
+static bool_t set_input_fragment();
+static bool_t skip_input_bytes();
+
+static bool_t xdrrec_getlong();
+static bool_t xdrrec_putlong();
+static bool_t xdrrec_getbytes();
+static bool_t xdrrec_putbytes();
+static u_int xdrrec_getpos();
+static bool_t xdrrec_setpos();
+static int32_t *xdrrec_inline();
+static void xdrrec_destroy();
+
+static struct xdr_ops xdrrec_ops = {
+ xdrrec_getlong,
+ xdrrec_putlong,
+ xdrrec_getbytes,
+ xdrrec_putbytes,
+ xdrrec_getpos,
+ xdrrec_setpos,
+ xdrrec_inline,
+ xdrrec_destroy
+};
+
+/*
+ * A record is composed of one or more record fragments.
+ * A record fragment is a two-byte header followed by zero to
+ * 2**32-1 bytes. The header is treated as a long unsigned and is
+ * encode/decoded to the network via htonl/ntohl. The low order 31 bits
+ * are a byte count of the fragment. The highest order bit is a boolean:
+ * 1 => this fragment is the last fragment of the record,
+ * 0 => this fragment is followed by more fragment(s).
+ *
+ * The fragment/record machinery is not general; it is constructed to
+ * meet the needs of xdr and rpc based on tcp.
+ */
+
+#define LAST_FRAG ((u_int32_t)(1 << 31))
+
+typedef struct rec_strm {
+ caddr_t tcp_handle;
+ caddr_t the_buffer;
+ /*
+ * out-goung bits
+ */
+ int (*writeit) __P((caddr_t, caddr_t, int));
+ caddr_t out_base; /* output buffer (points to frag header) */
+ caddr_t out_finger; /* next output position */
+ caddr_t out_boundry; /* data cannot up to this address */
+ u_int32_t *frag_header; /* beginning of current fragment */
+ bool_t frag_sent; /* true if buffer sent in middle of record */
+ /*
+ * in-coming bits
+ */
+ int (*readit) __P((caddr_t, caddr_t, int));
+ u_long in_size; /* fixed size of the input buffer */
+ caddr_t in_base;
+ caddr_t in_finger; /* location of next byte to be had */
+ caddr_t in_boundry; /* can read up to this location */
+ long fbtbc; /* fragment bytes to be consumed */
+ bool_t last_frag;
+ u_int sendsize;
+ u_int recvsize;
+} RECSTREAM;
+
+
+/*
+ * Create an xdr handle for xdrrec
+ * xdrrec_create fills in xdrs. Sendsize and recvsize are
+ * send and recv buffer sizes (0 => use default).
+ * tcp_handle is an opaque handle that is passed as the first parameter to
+ * the procedures readit and writeit. Readit and writeit are read and
+ * write respectively. They are like the system
+ * calls expect that they take an opaque handle rather than an fd.
+ */
+void
+xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit)
+ register XDR *xdrs;
+ register u_int sendsize;
+ register u_int recvsize;
+ caddr_t tcp_handle;
+ int (*readit)(); /* like read, but pass it a tcp_handle, not sock */
+ int (*writeit)(); /* like write, but pass it a tcp_handle, not sock */
+{
+ register RECSTREAM *rstrm =
+ (RECSTREAM *)mem_alloc(sizeof(RECSTREAM));
+
+ if (rstrm == NULL) {
+ (void)fprintf(stderr, "xdrrec_create: out of memory\n");
+ /*
+ * This is bad. Should rework xdrrec_create to
+ * return a handle, and in this case return NULL
+ */
+ return;
+ }
+ /*
+ * adjust sizes and allocate buffer quad byte aligned
+ */
+ rstrm->sendsize = sendsize = fix_buf_size(sendsize);
+ rstrm->recvsize = recvsize = fix_buf_size(recvsize);
+ rstrm->the_buffer = mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT);
+ if (rstrm->the_buffer == NULL) {
+ (void)fprintf(stderr, "xdrrec_create: out of memory\n");
+ return;
+ }
+ for (rstrm->out_base = rstrm->the_buffer;
+ (u_long)rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
+ rstrm->out_base++);
+ rstrm->in_base = rstrm->out_base + sendsize;
+ /*
+ * now the rest ...
+ */
+ xdrs->x_ops = &xdrrec_ops;
+ xdrs->x_private = (caddr_t)rstrm;
+ rstrm->tcp_handle = tcp_handle;
+ rstrm->readit = readit;
+ rstrm->writeit = writeit;
+ rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
+ rstrm->frag_header = (u_int32_t *)rstrm->out_base;
+ rstrm->out_finger += sizeof(u_int32_t);
+ rstrm->out_boundry += sendsize;
+ rstrm->frag_sent = FALSE;
+ rstrm->in_size = recvsize;
+ rstrm->in_boundry = rstrm->in_base;
+ rstrm->in_finger = (rstrm->in_boundry += recvsize);
+ rstrm->fbtbc = 0;
+ rstrm->last_frag = TRUE;
+}
+
+
+/*
+ * The reoutines defined below are the xdr ops which will go into the
+ * xdr handle filled in by xdrrec_create.
+ */
+
+static bool_t
+xdrrec_getlong(xdrs, lp)
+ XDR *xdrs;
+ long *lp;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+ register int32_t *buflp = (int32_t *)(rstrm->in_finger);
+ int32_t mylong;
+
+ /* first try the inline, fast case */
+ if ((rstrm->fbtbc >= sizeof(int32_t)) &&
+ (((long)rstrm->in_boundry - (long)buflp) >= sizeof(int32_t))) {
+ *lp = (long)ntohl((u_int32_t)(*buflp));
+ rstrm->fbtbc -= sizeof(int32_t);
+ rstrm->in_finger += sizeof(int32_t);
+ } else {
+ if (! xdrrec_getbytes(xdrs, (caddr_t)&mylong, sizeof(int32_t)))
+ return (FALSE);
+ *lp = (long)ntohl((u_int32_t)mylong);
+ }
+ return (TRUE);
+}
+
+static bool_t
+xdrrec_putlong(xdrs, lp)
+ XDR *xdrs;
+ long *lp;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+ register int32_t *dest_lp = ((int32_t *)(rstrm->out_finger));
+
+ if ((rstrm->out_finger += sizeof(int32_t)) > rstrm->out_boundry) {
+ /*
+ * this case should almost never happen so the code is
+ * inefficient
+ */
+ rstrm->out_finger -= sizeof(int32_t);
+ rstrm->frag_sent = TRUE;
+ if (! flush_out(rstrm, FALSE))
+ return (FALSE);
+ dest_lp = ((int32_t *)(rstrm->out_finger));
+ rstrm->out_finger += sizeof(int32_t);
+ }
+ *dest_lp = (int32_t)htonl((u_int32_t)(*lp));
+ return (TRUE);
+}
+
+static bool_t /* must manage buffers, fragments, and records */
+xdrrec_getbytes(xdrs, addr, len)
+ XDR *xdrs;
+ register caddr_t addr;
+ register u_int len;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+ register int current;
+
+ while (len > 0) {
+ current = rstrm->fbtbc;
+ if (current == 0) {
+ if (rstrm->last_frag)
+ return (FALSE);
+ if (! set_input_fragment(rstrm))
+ return (FALSE);
+ continue;
+ }
+ current = (len < current) ? len : current;
+ if (! get_input_bytes(rstrm, addr, current))
+ return (FALSE);
+ addr += current;
+ rstrm->fbtbc -= current;
+ len -= current;
+ }
+ return (TRUE);
+}
+
+static bool_t
+xdrrec_putbytes(xdrs, addr, len)
+ XDR *xdrs;
+ register caddr_t addr;
+ register u_int len;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+ register long current;
+
+ while (len > 0) {
+ current = (u_long)rstrm->out_boundry -
+ (u_long)rstrm->out_finger;
+ current = (len < current) ? len : current;
+ memcpy(rstrm->out_finger, addr, current);
+ rstrm->out_finger += current;
+ addr += current;
+ len -= current;
+ if (rstrm->out_finger == rstrm->out_boundry) {
+ rstrm->frag_sent = TRUE;
+ if (! flush_out(rstrm, FALSE))
+ return (FALSE);
+ }
+ }
+ return (TRUE);
+}
+
+static u_int
+xdrrec_getpos(xdrs)
+ register XDR *xdrs;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
+ register long pos;
+
+ pos = lseek((int)(long)rstrm->tcp_handle, (off_t) 0, 1);
+ if (pos != -1)
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ pos += rstrm->out_finger - rstrm->out_base;
+ break;
+
+ case XDR_DECODE:
+ pos -= rstrm->in_boundry - rstrm->in_finger;
+ break;
+
+ default:
+ pos = -1;
+ break;
+ }
+ return ((u_int) pos);
+}
+
+static bool_t
+xdrrec_setpos(xdrs, pos)
+ register XDR *xdrs;
+ u_int pos;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
+ u_int currpos = xdrrec_getpos(xdrs);
+ int delta = currpos - pos;
+ caddr_t newpos;
+
+ if ((int)currpos != -1)
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ newpos = rstrm->out_finger - delta;
+ if ((newpos > (caddr_t)(rstrm->frag_header)) &&
+ (newpos < rstrm->out_boundry)) {
+ rstrm->out_finger = newpos;
+ return (TRUE);
+ }
+ break;
+
+ case XDR_DECODE:
+ newpos = rstrm->in_finger - delta;
+ if ((delta < (int)(rstrm->fbtbc)) &&
+ (newpos <= rstrm->in_boundry) &&
+ (newpos >= rstrm->in_base)) {
+ rstrm->in_finger = newpos;
+ rstrm->fbtbc -= delta;
+ return (TRUE);
+ }
+ break;
+ }
+ return (FALSE);
+}
+
+static int32_t *
+xdrrec_inline(xdrs, len)
+ register XDR *xdrs;
+ int len;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
+ int32_t * buf = NULL;
+
+ switch (xdrs->x_op) {
+
+ case XDR_ENCODE:
+ if ((rstrm->out_finger + len) <= rstrm->out_boundry) {
+ buf = (int32_t *) rstrm->out_finger;
+ rstrm->out_finger += len;
+ }
+ break;
+
+ case XDR_DECODE:
+ if ((len <= rstrm->fbtbc) &&
+ ((rstrm->in_finger + len) <= rstrm->in_boundry)) {
+ buf = (int32_t *) rstrm->in_finger;
+ rstrm->fbtbc -= len;
+ rstrm->in_finger += len;
+ }
+ break;
+ }
+ return (buf);
+}
+
+static void
+xdrrec_destroy(xdrs)
+ register XDR *xdrs;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
+
+ mem_free(rstrm->the_buffer,
+ rstrm->sendsize + rstrm->recvsize + BYTES_PER_XDR_UNIT);
+ mem_free((caddr_t)rstrm, sizeof(RECSTREAM));
+}
+
+
+/*
+ * Exported routines to manage xdr records
+ */
+
+/*
+ * Before reading (deserializing from the stream, one should always call
+ * this procedure to guarantee proper record alignment.
+ */
+bool_t
+xdrrec_skiprecord(xdrs)
+ XDR *xdrs;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+
+ while (rstrm->fbtbc > 0 || (! rstrm->last_frag)) {
+ if (! skip_input_bytes(rstrm, rstrm->fbtbc))
+ return (FALSE);
+ rstrm->fbtbc = 0;
+ if ((! rstrm->last_frag) && (! set_input_fragment(rstrm)))
+ return (FALSE);
+ }
+ rstrm->last_frag = FALSE;
+ return (TRUE);
+}
+
+/*
+ * Look ahead fuction.
+ * Returns TRUE iff there is no more input in the buffer
+ * after consuming the rest of the current record.
+ */
+bool_t
+xdrrec_eof(xdrs)
+ XDR *xdrs;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+
+ while (rstrm->fbtbc > 0 || (! rstrm->last_frag)) {
+ if (! skip_input_bytes(rstrm, rstrm->fbtbc))
+ return (TRUE);
+ rstrm->fbtbc = 0;
+ if ((! rstrm->last_frag) && (! set_input_fragment(rstrm)))
+ return (TRUE);
+ }
+ if (rstrm->in_finger == rstrm->in_boundry)
+ return (TRUE);
+ return (FALSE);
+}
+
+/*
+ * The client must tell the package when an end-of-record has occurred.
+ * The second paraemters tells whether the record should be flushed to the
+ * (output) tcp stream. (This let's the package support batched or
+ * pipelined procedure calls.) TRUE => immmediate flush to tcp connection.
+ */
+bool_t
+xdrrec_endofrecord(xdrs, sendnow)
+ XDR *xdrs;
+ bool_t sendnow;
+{
+ register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
+ register u_long len; /* fragment length */
+
+ if (sendnow || rstrm->frag_sent ||
+ ((u_long)rstrm->out_finger + sizeof(u_int32_t) >=
+ (u_long)rstrm->out_boundry)) {
+ rstrm->frag_sent = FALSE;
+ return (flush_out(rstrm, TRUE));
+ }
+ len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->frag_header) -
+ sizeof(u_int32_t);
+ *(rstrm->frag_header) = htonl((u_long)len | LAST_FRAG);
+ rstrm->frag_header = (u_int32_t *)rstrm->out_finger;
+ rstrm->out_finger += sizeof(u_int32_t);
+ return (TRUE);
+}
+
+
+/*
+ * Internal useful routines
+ */
+static bool_t
+flush_out(rstrm, eor)
+ register RECSTREAM *rstrm;
+ bool_t eor;
+{
+ register u_long eormask = (eor == TRUE) ? LAST_FRAG : 0;
+ register u_int32_t len = (u_long)(rstrm->out_finger) -
+ (u_long)(rstrm->frag_header) - sizeof(u_int32_t);
+
+ *(rstrm->frag_header) = htonl(len | eormask);
+ len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->out_base);
+ if ((*(rstrm->writeit))(rstrm->tcp_handle, rstrm->out_base, (int)len)
+ != (int)len)
+ return (FALSE);
+ rstrm->frag_header = (u_int32_t *)rstrm->out_base;
+ rstrm->out_finger = (caddr_t)rstrm->out_base + sizeof(u_int32_t);
+ return (TRUE);
+}
+
+static bool_t /* knows nothing about records! Only about input buffers */
+fill_input_buf(rstrm)
+ register RECSTREAM *rstrm;
+{
+ register caddr_t where;
+ u_long i;
+ register long len;
+
+ where = rstrm->in_base;
+ i = (u_long)rstrm->in_boundry % BYTES_PER_XDR_UNIT;
+ where += i;
+ len = rstrm->in_size - i;
+ if ((len = (*(rstrm->readit))(rstrm->tcp_handle, where, len)) == -1)
+ return (FALSE);
+ rstrm->in_finger = where;
+ where += len;
+ rstrm->in_boundry = where;
+ return (TRUE);
+}
+
+static bool_t /* knows nothing about records! Only about input buffers */
+get_input_bytes(rstrm, addr, len)
+ register RECSTREAM *rstrm;
+ register caddr_t addr;
+ register int len;
+{
+ register long current;
+
+ while (len > 0) {
+ current = (long)rstrm->in_boundry - (long)rstrm->in_finger;
+ if (current == 0) {
+ if (! fill_input_buf(rstrm))
+ return (FALSE);
+ continue;
+ }
+ current = (len < current) ? len : current;
+ memcpy(addr, rstrm->in_finger, current);
+ rstrm->in_finger += current;
+ addr += current;
+ len -= current;
+ }
+ return (TRUE);
+}
+
+static bool_t /* next two bytes of the input stream are treated as a header */
+set_input_fragment(rstrm)
+ register RECSTREAM *rstrm;
+{
+ u_int32_t header;
+
+ if (! get_input_bytes(rstrm, (caddr_t)&header, sizeof(header)))
+ return (FALSE);
+ header = (long)ntohl(header);
+ rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
+ rstrm->fbtbc = header & (~LAST_FRAG);
+ return (TRUE);
+}
+
+static bool_t /* consumes input bytes; knows nothing about records! */
+skip_input_bytes(rstrm, cnt)
+ register RECSTREAM *rstrm;
+ long cnt;
+{
+ register long current;
+
+ while (cnt > 0) {
+ current = (long)rstrm->in_boundry - (long)rstrm->in_finger;
+ if (current == 0) {
+ if (! fill_input_buf(rstrm))
+ return (FALSE);
+ continue;
+ }
+ current = (cnt < current) ? cnt : current;
+ rstrm->in_finger += current;
+ cnt -= current;
+ }
+ return (TRUE);
+}
+
+static u_int
+fix_buf_size(s)
+ register u_int s;
+{
+
+ if (s < 100)
+ s = 4000;
+ return (RNDUP(s));
+}
diff --git a/lib/libc/xdr/xdr_reference.c b/lib/libc/xdr/xdr_reference.c
new file mode 100644
index 0000000..75607ba
--- /dev/null
+++ b/lib/libc/xdr/xdr_reference.c
@@ -0,0 +1,136 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_reference.c 1.11 87/08/11 SMI";*/
+/*static char *sccsid = "from: @(#)xdr_reference.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: xdr_reference.c,v 1.4 1996/12/30 14:07:11 peter Exp $";
+#endif
+
+/*
+ * xdr_reference.c, Generic XDR routines impelmentation.
+ *
+ * Copyright (C) 1987, Sun Microsystems, Inc.
+ *
+ * These are the "non-trivial" xdr primitives used to serialize and de-serialize
+ * "pointers". See xdr.h for more info on the interface to xdr.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+
+#define LASTUNSIGNED ((u_int) 0-1)
+
+/*
+ * XDR an indirect pointer
+ * xdr_reference is for recursively translating a structure that is
+ * referenced by a pointer inside the structure that is currently being
+ * translated. pp references a pointer to storage. If *pp is null
+ * the necessary storage is allocated.
+ * size is the sizeof the referneced structure.
+ * proc is the routine to handle the referenced structure.
+ */
+bool_t
+xdr_reference(xdrs, pp, size, proc)
+ register XDR *xdrs;
+ caddr_t *pp; /* the pointer to work on */
+ u_int size; /* size of the object pointed to */
+ xdrproc_t proc; /* xdr routine to handle the object */
+{
+ register caddr_t loc = *pp;
+ register bool_t stat;
+
+ if (loc == NULL)
+ switch (xdrs->x_op) {
+ case XDR_FREE:
+ return (TRUE);
+
+ case XDR_DECODE:
+ *pp = loc = (caddr_t) mem_alloc(size);
+ if (loc == NULL) {
+ (void) fprintf(stderr,
+ "xdr_reference: out of memory\n");
+ return (FALSE);
+ }
+ memset(loc, 0, (int)size);
+ break;
+ }
+
+ stat = (*proc)(xdrs, loc, LASTUNSIGNED);
+
+ if (xdrs->x_op == XDR_FREE) {
+ mem_free(loc, size);
+ *pp = NULL;
+ }
+ return (stat);
+}
+
+
+/*
+ * xdr_pointer():
+ *
+ * XDR a pointer to a possibly recursive data structure. This
+ * differs with xdr_reference in that it can serialize/deserialiaze
+ * trees correctly.
+ *
+ * What's sent is actually a union:
+ *
+ * union object_pointer switch (boolean b) {
+ * case TRUE: object_data data;
+ * case FALSE: void nothing;
+ * }
+ *
+ * > objpp: Pointer to the pointer to the object.
+ * > obj_size: size of the object.
+ * > xdr_obj: routine to XDR an object.
+ *
+ */
+bool_t
+xdr_pointer(xdrs,objpp,obj_size,xdr_obj)
+ register XDR *xdrs;
+ char **objpp;
+ u_int obj_size;
+ xdrproc_t xdr_obj;
+{
+
+ bool_t more_data;
+
+ more_data = (*objpp != NULL);
+ if (! xdr_bool(xdrs,&more_data)) {
+ return (FALSE);
+ }
+ if (! more_data) {
+ *objpp = NULL;
+ return (TRUE);
+ }
+ return (xdr_reference(xdrs,objpp,obj_size,xdr_obj));
+}
diff --git a/lib/libc/xdr/xdr_sizeof.c b/lib/libc/xdr/xdr_sizeof.c
new file mode 100644
index 0000000..e9c6a19
--- /dev/null
+++ b/lib/libc/xdr/xdr_sizeof.c
@@ -0,0 +1,163 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+/*
+ * xdr_sizeof.c
+ *
+ * Copyright 1990 Sun Microsystems, Inc.
+ *
+ * General purpose routine to see how much space something will use
+ * when serialized using XDR.
+ */
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <sys/types.h>
+#include <stdlib.h>
+
+/* ARGSUSED */
+static bool_t
+x_putlong(xdrs, longp)
+ XDR *xdrs;
+ long *longp;
+{
+ xdrs->x_handy += BYTES_PER_XDR_UNIT;
+ return (TRUE);
+}
+
+/* ARGSUSED */
+static bool_t
+x_putbytes(xdrs, bp, len)
+ XDR *xdrs;
+ char *bp;
+ int len;
+{
+ xdrs->x_handy += len;
+ return (TRUE);
+}
+
+static u_int
+x_getpostn(xdrs)
+ XDR *xdrs;
+{
+ return (xdrs->x_handy);
+}
+
+/* ARGSUSED */
+static bool_t
+x_setpostn(xdrs, pos)
+ XDR *xdrs;
+ u_int pos;
+{
+ /* This is not allowed */
+ return (FALSE);
+}
+
+static int32_t *
+x_inline(xdrs, len)
+ XDR *xdrs;
+ int len;
+{
+ if (len == 0) {
+ return (NULL);
+ }
+ if (xdrs->x_op != XDR_ENCODE) {
+ return (NULL);
+ }
+ if (len < (int) xdrs->x_base) {
+ /* x_private was already allocated */
+ xdrs->x_handy += len;
+ return ((int32_t *) xdrs->x_private);
+ } else {
+ /* Free the earlier space and allocate new area */
+ if (xdrs->x_private)
+ free(xdrs->x_private);
+ if ((xdrs->x_private = (caddr_t) malloc(len)) == NULL) {
+ xdrs->x_base = 0;
+ return (NULL);
+ }
+ xdrs->x_base = (caddr_t) len;
+ xdrs->x_handy += len;
+ return ((int32_t *) xdrs->x_private);
+ }
+}
+
+static int
+harmless()
+{
+ /* Always return FALSE/NULL, as the case may be */
+ return (0);
+}
+
+static void
+x_destroy(xdrs)
+ XDR *xdrs;
+{
+ xdrs->x_handy = 0;
+ xdrs->x_base = 0;
+ if (xdrs->x_private) {
+ free(xdrs->x_private);
+ xdrs->x_private = NULL;
+ }
+ return;
+}
+
+unsigned long
+xdr_sizeof(func, data)
+ xdrproc_t func;
+ void *data;
+{
+ XDR x;
+ struct xdr_ops ops;
+ bool_t stat;
+ /* to stop ANSI-C compiler from complaining */
+ typedef bool_t (* dummyfunc1)(XDR *, long *);
+ typedef bool_t (* dummyfunc2)(XDR *, caddr_t, u_int);
+
+ ops.x_putlong = x_putlong;
+ ops.x_putbytes = x_putbytes;
+ ops.x_inline = x_inline;
+ ops.x_getpostn = x_getpostn;
+ ops.x_setpostn = x_setpostn;
+ ops.x_destroy = x_destroy;
+
+ /* the other harmless ones */
+ ops.x_getlong = (dummyfunc1) harmless;
+ ops.x_getbytes = (dummyfunc2) harmless;
+
+ x.x_op = XDR_ENCODE;
+ x.x_ops = &ops;
+ x.x_handy = 0;
+ x.x_private = (caddr_t) NULL;
+ x.x_base = (caddr_t) 0;
+
+ stat = func(&x, data);
+ if (x.x_private)
+ free(x.x_private);
+ return (stat == TRUE ? (unsigned) x.x_handy: 0);
+}
diff --git a/lib/libc/xdr/xdr_stdio.c b/lib/libc/xdr/xdr_stdio.c
new file mode 100644
index 0000000..39eda50
--- /dev/null
+++ b/lib/libc/xdr/xdr_stdio.c
@@ -0,0 +1,189 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part. Users
+ * 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
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)xdr_stdio.c 1.16 87/08/11 Copyr 1984 Sun Micro";*/
+/*static char *sccsid = "from: @(#)xdr_stdio.c 2.1 88/07/29 4.0 RPCSRC";*/
+static char *rcsid = "$Id: xdr_stdio.c,v 1.3 1996/12/30 14:07:11 peter Exp $";
+#endif
+
+/*
+ * xdr_stdio.c, XDR implementation on standard i/o file.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * This set of routines implements a XDR on a stdio stream.
+ * XDR_ENCODE serializes onto the stream, XDR_DECODE de-serializes
+ * from the stream.
+ */
+
+#include <rpc/types.h>
+#include <stdio.h>
+#include <rpc/xdr.h>
+
+static bool_t xdrstdio_getlong();
+static bool_t xdrstdio_putlong();
+static bool_t xdrstdio_getbytes();
+static bool_t xdrstdio_putbytes();
+static u_int xdrstdio_getpos();
+static bool_t xdrstdio_setpos();
+static int32_t *xdrstdio_inline();
+static void xdrstdio_destroy();
+
+/*
+ * Ops vector for stdio type XDR
+ */
+static struct xdr_ops xdrstdio_ops = {
+ xdrstdio_getlong, /* deseraialize a long int */
+ xdrstdio_putlong, /* seraialize a long int */
+ xdrstdio_getbytes, /* deserialize counted bytes */
+ xdrstdio_putbytes, /* serialize counted bytes */
+ xdrstdio_getpos, /* get offset in the stream */
+ xdrstdio_setpos, /* set offset in the stream */
+ xdrstdio_inline, /* prime stream for inline macros */
+ xdrstdio_destroy /* destroy stream */
+};
+
+/*
+ * Initialize a stdio xdr stream.
+ * Sets the xdr stream handle xdrs for use on the stream file.
+ * Operation flag is set to op.
+ */
+void
+xdrstdio_create(xdrs, file, op)
+ register XDR *xdrs;
+ FILE *file;
+ enum xdr_op op;
+{
+
+ xdrs->x_op = op;
+ xdrs->x_ops = &xdrstdio_ops;
+ xdrs->x_private = (caddr_t)file;
+ xdrs->x_handy = 0;
+ xdrs->x_base = 0;
+}
+
+/*
+ * Destroy a stdio xdr stream.
+ * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create.
+ */
+static void
+xdrstdio_destroy(xdrs)
+ register XDR *xdrs;
+{
+ (void)fflush((FILE *)xdrs->x_private);
+ /* xx should we close the file ?? */
+}
+
+static bool_t
+xdrstdio_getlong(xdrs, lp)
+ XDR *xdrs;
+ register long *lp;
+{
+
+ if (fread((caddr_t)lp, sizeof(int32_t), 1,
+ (FILE *)xdrs->x_private) != 1)
+ return (FALSE);
+ *lp = (long)ntohl((int32_t)*lp);
+ return (TRUE);
+}
+
+static bool_t
+xdrstdio_putlong(xdrs, lp)
+ XDR *xdrs;
+ long *lp;
+{
+
+ long mycopy = (long)htonl((int32_t)*lp);
+
+ if (fwrite((caddr_t)&mycopy, sizeof(int32_t), 1,
+ (FILE *)xdrs->x_private) != 1)
+ return (FALSE);
+ return (TRUE);
+}
+
+static bool_t
+xdrstdio_getbytes(xdrs, addr, len)
+ XDR *xdrs;
+ caddr_t addr;
+ u_int len;
+{
+
+ if ((len != 0) && (fread(addr, (int)len, 1, (FILE *)xdrs->x_private) != 1))
+ return (FALSE);
+ return (TRUE);
+}
+
+static bool_t
+xdrstdio_putbytes(xdrs, addr, len)
+ XDR *xdrs;
+ caddr_t addr;
+ u_int len;
+{
+
+ if ((len != 0) && (fwrite(addr, (int)len, 1, (FILE *)xdrs->x_private) != 1))
+ return (FALSE);
+ return (TRUE);
+}
+
+static u_int
+xdrstdio_getpos(xdrs)
+ XDR *xdrs;
+{
+
+ return ((u_int) ftell((FILE *)xdrs->x_private));
+}
+
+static bool_t
+xdrstdio_setpos(xdrs, pos)
+ XDR *xdrs;
+ u_int pos;
+{
+
+ return ((fseek((FILE *)xdrs->x_private, (long)pos, 0) < 0) ?
+ FALSE : TRUE);
+}
+
+static int32_t *
+xdrstdio_inline(xdrs, len)
+ XDR *xdrs;
+ u_int len;
+{
+
+ /*
+ * Must do some work to implement this: must insure
+ * enough data in the underlying stdio buffer,
+ * that the buffer is aligned so that we can indirect through a
+ * long *, and stuff this pointer in xdrs->x_buf. Doing
+ * a fread or fwrite to a scratch buffer would defeat
+ * most of the gains to be had here and require storage
+ * management on this buffer, so we don't do this.
+ */
+ return (NULL);
+}
diff --git a/lib/libc/yp/Makefile.inc b/lib/libc/yp/Makefile.inc
new file mode 100644
index 0000000..a1c9473
--- /dev/null
+++ b/lib/libc/yp/Makefile.inc
@@ -0,0 +1,17 @@
+# from: @(#)Makefile.inc 5.3 (Berkeley) 2/20/91
+# $Id: Makefile.inc,v 1.5 1997/05/03 03:50:06 jb Exp $
+
+# yp sources
+.PATH: ${.CURDIR}/../libc/yp
+
+SRCS+= xdryp.c yp_xdr.c yplib.c
+CLEANFILES+= yp_xdr.c yp.h
+
+RPCSRC= ${DESTDIR}/usr/include/rpcsvc/yp.x
+RPCGEN= rpcgen
+
+yp_xdr.c: ${RPCSRC} yp.h
+ ${RPCGEN} -c -o ${.TARGET} ${RPCSRC}
+
+yp.h: ${RPCSRC}
+ ${RPCGEN} -h -o ${.TARGET} ${RPCSRC}
diff --git a/lib/libc/yp/xdryp.c b/lib/libc/yp/xdryp.c
new file mode 100644
index 0000000..9268fc2
--- /dev/null
+++ b/lib/libc/yp/xdryp.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * All rights reserved.
+ *
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#ifndef LINT
+static char *rcsid = "$Id$";
+#endif
+
+#include <rpc/rpc.h>
+#include <rpcsvc/yp.h>
+#include <stdlib.h>
+#include <string.h>
+
+extern int (*ypresp_allfn)();
+extern void *ypresp_data;
+
+/*
+ * I'm leaving the xdr_datum() function in purely for backwards
+ * compatibility. yplib.c doesn't actually use it, but it's listed
+ * in yp_prot.h as being available, so it's probably a good idea to
+ * leave it in in case somebody goes looking for it.
+ */
+typedef struct {
+ char *dptr;
+ int dsize;
+} datum;
+
+bool_t
+xdr_datum(xdrs, objp)
+XDR *xdrs;
+datum *objp;
+{
+ if (!xdr_bytes(xdrs, (char **)&objp->dptr, (u_int *)&objp->dsize, YPMAXRECORD)) {
+ return (FALSE);
+ }
+ return (TRUE);
+}
+
+bool_t
+xdr_ypresp_all_seq(xdrs, objp)
+XDR *xdrs;
+u_long *objp;
+{
+ struct ypresp_all out;
+ u_long status;
+ char *key, *val;
+ int r;
+
+ bzero(&out, sizeof out);
+ while(1) {
+ if( !xdr_ypresp_all(xdrs, &out)) {
+ xdr_free(xdr_ypresp_all, (char *)&out);
+ *objp = YP_YPERR;
+ return FALSE;
+ }
+ if(out.more == 0) {
+ xdr_free(xdr_ypresp_all, (char *)&out);
+ *objp = YP_NOMORE;
+ return TRUE;
+ }
+ status = out.ypresp_all_u.val.stat;
+ switch(status) {
+ case YP_TRUE:
+ key = (char *)malloc(out.ypresp_all_u.val.key.keydat_len + 1);
+ bcopy(out.ypresp_all_u.val.key.keydat_val, key,
+ out.ypresp_all_u.val.key.keydat_len);
+ key[out.ypresp_all_u.val.key.keydat_len] = '\0';
+ val = (char *)malloc(out.ypresp_all_u.val.val.valdat_len + 1);
+ bcopy(out.ypresp_all_u.val.val.valdat_val, val,
+ out.ypresp_all_u.val.val.valdat_len);
+ val[out.ypresp_all_u.val.val.valdat_len] = '\0';
+ xdr_free(xdr_ypresp_all, (char *)&out);
+
+ r = (*ypresp_allfn)(status,
+ key, out.ypresp_all_u.val.key.keydat_len,
+ val, out.ypresp_all_u.val.val.valdat_len,
+ ypresp_data);
+ *objp = status;
+ free(key);
+ free(val);
+ if(r)
+ return TRUE;
+ break;
+ case YP_NOMORE:
+ xdr_free(xdr_ypresp_all, (char *)&out);
+ *objp = YP_NOMORE;
+ return TRUE;
+ default:
+ xdr_free(xdr_ypresp_all, (char *)&out);
+ *objp = status;
+ return TRUE;
+ }
+ }
+}
diff --git a/lib/libc/yp/yplib.c b/lib/libc/yp/yplib.c
new file mode 100644
index 0000000..2e0223d
--- /dev/null
+++ b/lib/libc/yp/yplib.c
@@ -0,0 +1,1033 @@
+/*
+ * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * All rights reserved.
+ *
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#ifndef LINT
+static char *rcsid = "$Id: yplib.c,v 1.28 1997/02/22 15:05:02 peter Exp $";
+#endif
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/file.h>
+#include <sys/uio.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <rpc/rpc.h>
+#include <rpc/xdr.h>
+#include <rpcsvc/yp.h>
+
+
+/*
+ * We have to define these here due to clashes between yp_prot.h and
+ * yp.h.
+ */
+
+struct dom_binding {
+ struct dom_binding *dom_pnext;
+ char dom_domain[YPMAXDOMAIN + 1];
+ struct sockaddr_in dom_server_addr;
+ u_short dom_server_port;
+ int dom_socket;
+ CLIENT *dom_client;
+ u_short dom_local_port; /* now I finally know what this is for. */
+ long dom_vers;
+};
+
+#include <rpcsvc/ypclnt.h>
+
+#ifndef BINDINGDIR
+#define BINDINGDIR "/var/yp/binding"
+#endif
+#define YPMATCHCACHE
+#define MAX_RETRIES 20
+
+extern bool_t xdr_domainname(), xdr_ypbind_resp();
+extern bool_t xdr_ypreq_key(), xdr_ypresp_val();
+extern bool_t xdr_ypreq_nokey(), xdr_ypresp_key_val();
+extern bool_t xdr_ypresp_all(), xdr_ypresp_all_seq();
+extern bool_t xdr_ypresp_master();
+
+int (*ypresp_allfn)();
+void *ypresp_data;
+
+static void _yp_unbind __P(( struct dom_binding * ));
+struct dom_binding *_ypbindlist;
+static char _yp_domain[MAXHOSTNAMELEN];
+int _yplib_timeout = 10;
+
+#ifdef YPMATCHCACHE
+int _yplib_cache = 5;
+
+static struct ypmatch_ent {
+ struct ypmatch_ent *next;
+ char *map, *key, *val;
+ int keylen, vallen;
+ time_t expire_t;
+} *ypmc;
+
+static void
+ypmatch_add(map, key, keylen, val, vallen)
+ char *map;
+ char *key;
+ int keylen;
+ char *val;
+ int vallen;
+{
+ struct ypmatch_ent *ep;
+ time_t t;
+
+ time(&t);
+
+ for(ep=ypmc; ep; ep=ep->next)
+ if(ep->expire_t < t)
+ break;
+ if(ep==NULL) {
+ ep = (struct ypmatch_ent *)malloc(sizeof *ep);
+ bzero((char *)ep, sizeof *ep);
+ if(ypmc)
+ ep->next = ypmc;
+ ypmc = ep;
+ }
+
+ if(ep->key)
+ free(ep->key);
+ if(ep->val)
+ free(ep->val);
+
+ ep->key = NULL;
+ ep->val = NULL;
+
+ ep->key = (char *)malloc(keylen);
+ if(ep->key==NULL)
+ return;
+
+ ep->val = (char *)malloc(vallen);
+ if(ep->key==NULL) {
+ free(ep->key);
+ ep->key = NULL;
+ return;
+ }
+ ep->keylen = keylen;
+ ep->vallen = vallen;
+
+ bcopy(key, ep->key, ep->keylen);
+ bcopy(val, ep->val, ep->vallen);
+
+ if(ep->map) {
+ if( strcmp(ep->map, map) ) {
+ free(ep->map);
+ ep->map = strdup(map);
+ }
+ } else {
+ ep->map = strdup(map);
+ }
+
+ ep->expire_t = t + _yplib_cache;
+}
+
+static bool_t
+ypmatch_find(map, key, keylen, val, vallen)
+ char *map;
+ char *key;
+ int keylen;
+ char **val;
+ int *vallen;
+{
+ struct ypmatch_ent *ep;
+ time_t t;
+
+ if(ypmc==NULL)
+ return 0;
+
+ time(&t);
+
+ for(ep=ypmc; ep; ep=ep->next) {
+ if(ep->keylen != keylen)
+ continue;
+ if(strcmp(ep->map, map))
+ continue;
+ if(bcmp(ep->key, key, keylen))
+ continue;
+ if(t > ep->expire_t)
+ continue;
+
+ *val = ep->val;
+ *vallen = ep->vallen;
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+char *
+ypbinderr_string(incode)
+ int incode;
+{
+ static char err[80];
+ switch(incode) {
+ case 0:
+ return "Success";
+ case YPBIND_ERR_ERR:
+ return "Internal ypbind error";
+ case YPBIND_ERR_NOSERV:
+ return "Domain not bound";
+ case YPBIND_ERR_RESC:
+ return "System resource allocation failure";
+ }
+ sprintf(err, "Unknown ypbind error: #%d\n", incode);
+ return err;
+}
+
+int
+_yp_dobind(dom, ypdb)
+ char *dom;
+ struct dom_binding **ypdb;
+{
+ static pid_t pid = -1;
+ char path[MAXPATHLEN];
+ struct dom_binding *ysd, *ysd2;
+ struct ypbind_resp ypbr;
+ struct timeval tv;
+ struct sockaddr_in clnt_sin;
+ int clnt_sock, fd;
+ pid_t gpid;
+ CLIENT *client;
+ int new = 0, r;
+ int retries = 0;
+ struct sockaddr_in check;
+ int checklen = sizeof(struct sockaddr_in);
+
+ /* Not allowed; bad doggie. Bad. */
+ if (strchr(dom, '/') != NULL)
+ return(YPERR_BADARGS);
+
+ gpid = getpid();
+ if( !(pid==-1 || pid==gpid) ) {
+ ysd = _ypbindlist;
+ while(ysd) {
+ if(ysd->dom_client != NULL)
+ _yp_unbind(ysd);
+ ysd2 = ysd->dom_pnext;
+ free(ysd);
+ ysd = ysd2;
+ }
+ _ypbindlist = NULL;
+ }
+ pid = gpid;
+
+ if(ypdb!=NULL)
+ *ypdb = NULL;
+
+ if(dom==NULL || strlen(dom)==0)
+ return YPERR_BADARGS;
+
+ for(ysd = _ypbindlist; ysd; ysd = ysd->dom_pnext)
+ if( strcmp(dom, ysd->dom_domain) == 0)
+ break;
+
+
+ if(ysd==NULL) {
+ ysd = (struct dom_binding *)malloc(sizeof *ysd);
+ bzero((char *)ysd, sizeof *ysd);
+ ysd->dom_socket = -1;
+ ysd->dom_vers = 0;
+ new = 1;
+ } else {
+ /* Check the socket -- may have been hosed by the caller. */
+ if (getsockname(ysd->dom_socket, (struct sockaddr *)&check,
+ &checklen) == -1 || check.sin_family != AF_INET ||
+ check.sin_port != ysd->dom_local_port) {
+ /* Socket became bogus somehow... need to rebind. */
+ int save, sock;
+
+ sock = ysd->dom_socket;
+ save = dup(ysd->dom_socket);
+ if (ysd->dom_client != NULL)
+ clnt_destroy(ysd->dom_client);
+ ysd->dom_vers = 0;
+ ysd->dom_client = NULL;
+ sock = dup2(save, sock);
+ close(save);
+ }
+ }
+
+again:
+ retries++;
+ if (retries > MAX_RETRIES) {
+ if (new)
+ free(ysd);
+ return(YPERR_YPBIND);
+ }
+#ifdef BINDINGDIR
+ if(ysd->dom_vers==0) {
+ /*
+ * We're trying to make a new binding: zorch the
+ * existing handle now (if any).
+ */
+ if(ysd->dom_client != NULL) {
+ clnt_destroy(ysd->dom_client);
+ ysd->dom_client = NULL;
+ ysd->dom_socket = -1;
+ }
+ sprintf(path, "%s/%s.%d", BINDINGDIR, dom, 2);
+ if( (fd=open(path, O_RDONLY)) == -1) {
+ /* no binding file, YP is dead. */
+ /* Try to bring it back to life. */
+ close(fd);
+ goto skipit;
+ }
+ if( flock(fd, LOCK_EX|LOCK_NB) == -1 && errno==EWOULDBLOCK) {
+ struct iovec iov[2];
+ struct ypbind_resp ybr;
+ u_short ypb_port;
+
+ iov[0].iov_base = (caddr_t)&ypb_port;
+ iov[0].iov_len = sizeof ypb_port;
+ iov[1].iov_base = (caddr_t)&ybr;
+ iov[1].iov_len = sizeof ybr;
+
+ r = readv(fd, iov, 2);
+ if(r != iov[0].iov_len + iov[1].iov_len) {
+ close(fd);
+ ysd->dom_vers = -1;
+ goto again;
+ }
+
+ bzero(&ysd->dom_server_addr, sizeof ysd->dom_server_addr);
+ ysd->dom_server_addr.sin_family = AF_INET;
+ ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in);
+ ysd->dom_server_addr.sin_addr.s_addr =
+ *(u_long *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr;
+ ysd->dom_server_addr.sin_port =
+ *(u_short *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
+
+ ysd->dom_server_port = ysd->dom_server_addr.sin_port;
+ close(fd);
+ goto gotit;
+ } else {
+ /* no lock on binding file, YP is dead. */
+ /* Try to bring it back to life. */
+ close(fd);
+ goto skipit;
+ }
+ }
+skipit:
+#endif
+ if(ysd->dom_vers==-1 || ysd->dom_vers==0) {
+ /*
+ * We're trying to make a new binding: zorch the
+ * existing handle now (if any).
+ */
+ if(ysd->dom_client != NULL) {
+ clnt_destroy(ysd->dom_client);
+ ysd->dom_client = NULL;
+ ysd->dom_socket = -1;
+ }
+ bzero((char *)&clnt_sin, sizeof clnt_sin);
+ clnt_sin.sin_family = AF_INET;
+ clnt_sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ clnt_sock = RPC_ANYSOCK;
+ client = clnttcp_create(&clnt_sin, YPBINDPROG, YPBINDVERS, &clnt_sock,
+ 0, 0);
+ if(client==NULL) {
+ /*
+ * These conditions indicate ypbind just isn't
+ * alive -- we probably don't want to shoot our
+ * mouth off in this case; instead generate error
+ * messages only for really exotic problems.
+ */
+ if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED &&
+ (rpc_createerr.cf_stat != RPC_SYSTEMERROR &&
+ rpc_createerr.cf_error.re_errno == ECONNREFUSED))
+ clnt_pcreateerror("clnttcp_create");
+ if(new)
+ free(ysd);
+ return (YPERR_YPBIND);
+ }
+
+ /*
+ * Check the port number -- should be < IPPORT_RESERVED.
+ * If not, it's possible someone has registered a bogus
+ * ypbind with the portmapper and is trying to trick us.
+ */
+ if (ntohs(clnt_sin.sin_port) >= IPPORT_RESERVED) {
+ if (client != NULL)
+ clnt_destroy(client);
+ if (new)
+ free(ysd);
+ return(YPERR_YPBIND);
+ }
+ tv.tv_sec = _yplib_timeout/2;
+ tv.tv_usec = 0;
+ r = clnt_call(client, YPBINDPROC_DOMAIN,
+ xdr_domainname, (char *)&dom, xdr_ypbind_resp, &ypbr, tv);
+ if(r != RPC_SUCCESS) {
+ clnt_destroy(client);
+ ysd->dom_vers = -1;
+ if (r == RPC_PROGUNAVAIL || r == RPC_PROCUNAVAIL) {
+ if (new)
+ free(ysd);
+ return(YPERR_YPBIND);
+ }
+ fprintf(stderr,
+ "YP: server for domain %s not responding, retrying\n", dom);
+ goto again;
+ } else {
+ if (ypbr.ypbind_status != YPBIND_SUCC_VAL) {
+ clnt_destroy(client);
+ ysd->dom_vers = -1;
+ sleep(_yplib_timeout/2);
+ goto again;
+ }
+ }
+ clnt_destroy(client);
+
+ bzero((char *)&ysd->dom_server_addr, sizeof ysd->dom_server_addr);
+ ysd->dom_server_addr.sin_family = AF_INET;
+ ysd->dom_server_addr.sin_port =
+ *(u_short *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
+ ysd->dom_server_addr.sin_addr.s_addr =
+ *(u_long *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr;
+
+ /*
+ * We could do a reserved port check here too, but this
+ * could pose compatibility problems. The local ypbind is
+ * supposed to decide whether or not to trust yp servers
+ * on insecure ports. For now, we trust its judgement.
+ */
+ ysd->dom_server_port =
+ *(u_short *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
+gotit:
+ ysd->dom_vers = YPVERS;
+ strcpy(ysd->dom_domain, dom);
+ }
+
+ /* Don't rebuild the connection to the server unless we have to. */
+ if (ysd->dom_client == NULL) {
+ tv.tv_sec = _yplib_timeout/2;
+ tv.tv_usec = 0;
+ ysd->dom_socket = RPC_ANYSOCK;
+ ysd->dom_client = clntudp_create(&ysd->dom_server_addr,
+ YPPROG, YPVERS, tv, &ysd->dom_socket);
+ if(ysd->dom_client==NULL) {
+ clnt_pcreateerror("clntudp_create");
+ ysd->dom_vers = -1;
+ goto again;
+ }
+ if( fcntl(ysd->dom_socket, F_SETFD, 1) == -1)
+ perror("fcntl: F_SETFD");
+ /*
+ * We want a port number associated with this socket
+ * so that we can check its authenticity later.
+ */
+ checklen = sizeof(struct sockaddr_in);
+ bzero((char *)&check, checklen);
+ bind(ysd->dom_socket, (struct sockaddr *)&check, checklen);
+ check.sin_family = AF_INET;
+ if (!getsockname(ysd->dom_socket,
+ (struct sockaddr *)&check, &checklen)) {
+ ysd->dom_local_port = check.sin_port;
+ } else {
+ clnt_destroy(ysd->dom_client);
+ if (new)
+ free(ysd);
+ return(YPERR_YPBIND);
+ }
+ }
+
+ if(new) {
+ ysd->dom_pnext = _ypbindlist;
+ _ypbindlist = ysd;
+ }
+
+ if(ypdb!=NULL)
+ *ypdb = ysd;
+ return 0;
+}
+
+static void
+_yp_unbind(ypb)
+ struct dom_binding *ypb;
+{
+ struct sockaddr_in check;
+ int checklen = sizeof(struct sockaddr_in);
+
+ if (ypb->dom_client != NULL) {
+ /* Check the socket -- may have been hosed by the caller. */
+ if (getsockname(ypb->dom_socket, (struct sockaddr *)&check,
+ &checklen) == -1 || check.sin_family != AF_INET ||
+ check.sin_port != ypb->dom_local_port) {
+ int save, sock;
+
+ sock = ypb->dom_socket;
+ save = dup(ypb->dom_socket);
+ clnt_destroy(ypb->dom_client);
+ sock = dup2(save, sock);
+ close(save);
+ } else
+ clnt_destroy(ypb->dom_client);
+ }
+
+ ypb->dom_client = NULL;
+ ypb->dom_socket = -1;
+ ypb->dom_vers = -1;
+}
+
+int
+yp_bind(dom)
+ char *dom;
+{
+ return _yp_dobind(dom, NULL);
+}
+
+void
+yp_unbind(dom)
+ char *dom;
+{
+ struct dom_binding *ypb, *ypbp;
+
+ ypbp = NULL;
+ for(ypb=_ypbindlist; ypb; ypb=ypb->dom_pnext) {
+ if( strcmp(dom, ypb->dom_domain) == 0) {
+ _yp_unbind(ypb);
+ if(ypbp)
+ ypbp->dom_pnext = ypb->dom_pnext;
+ else
+ _ypbindlist = ypb->dom_pnext;
+ free(ypb);
+ return;
+ }
+ ypbp = ypb;
+ }
+ return;
+}
+
+int
+yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen)
+ char *indomain;
+ char *inmap;
+ const char *inkey;
+ int inkeylen;
+ char **outval;
+ int *outvallen;
+{
+ struct dom_binding *ysd;
+ struct ypresp_val yprv;
+ struct timeval tv;
+ struct ypreq_key yprk;
+ int r;
+
+ *outval = NULL;
+ *outvallen = 0;
+
+ /* Sanity check */
+
+ if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
+ inmap == NULL || !strlen(inmap) ||
+ indomain == NULL || !strlen(indomain))
+ return YPERR_BADARGS;
+
+#ifdef YPMATCHCACHE
+ if( !strcmp(_yp_domain, indomain) && ypmatch_find(inmap, inkey,
+ inkeylen, &yprv.val.valdat_val, &yprv.val.valdat_len)) {
+ *outvallen = yprv.val.valdat_len;
+ *outval = (char *)malloc(*outvallen+1);
+ bcopy(yprv.val.valdat_val, *outval, *outvallen);
+ (*outval)[*outvallen] = '\0';
+ return 0;
+ }
+#endif
+
+again:
+ if( _yp_dobind(indomain, &ysd) != 0)
+ return YPERR_DOMAIN;
+
+ tv.tv_sec = _yplib_timeout;
+ tv.tv_usec = 0;
+
+ yprk.domain = indomain;
+ yprk.map = inmap;
+ yprk.key.keydat_val = (char *)inkey;
+ yprk.key.keydat_len = inkeylen;
+
+ bzero((char *)&yprv, sizeof yprv);
+
+ r = clnt_call(ysd->dom_client, YPPROC_MATCH,
+ xdr_ypreq_key, &yprk, xdr_ypresp_val, &yprv, tv);
+ if(r != RPC_SUCCESS) {
+ clnt_perror(ysd->dom_client, "yp_match: clnt_call");
+ _yp_unbind(ysd);
+ goto again;
+ }
+
+ if( !(r=ypprot_err(yprv.stat)) ) {
+ *outvallen = yprv.val.valdat_len;
+ *outval = (char *)malloc(*outvallen+1);
+ bcopy(yprv.val.valdat_val, *outval, *outvallen);
+ (*outval)[*outvallen] = '\0';
+#ifdef YPMATCHCACHE
+ if( strcmp(_yp_domain, indomain)==0 )
+ ypmatch_add(inmap, inkey, inkeylen, *outval, *outvallen);
+#endif
+ }
+
+ xdr_free(xdr_ypresp_val, (char *)&yprv);
+ return r;
+}
+
+int
+yp_get_default_domain(domp)
+char **domp;
+{
+ *domp = NULL;
+ if(_yp_domain[0] == '\0')
+ if( getdomainname(_yp_domain, sizeof _yp_domain))
+ return YPERR_NODOM;
+ *domp = _yp_domain;
+ return 0;
+}
+
+int
+yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen)
+ char *indomain;
+ char *inmap;
+ char **outkey;
+ int *outkeylen;
+ char **outval;
+ int *outvallen;
+{
+ struct ypresp_key_val yprkv;
+ struct ypreq_nokey yprnk;
+ struct dom_binding *ysd;
+ struct timeval tv;
+ int r;
+
+ /* Sanity check */
+
+ if (indomain == NULL || !strlen(indomain) ||
+ inmap == NULL || !strlen(inmap))
+ return YPERR_BADARGS;
+
+ *outkey = *outval = NULL;
+ *outkeylen = *outvallen = 0;
+
+again:
+ if( _yp_dobind(indomain, &ysd) != 0)
+ return YPERR_DOMAIN;
+
+ tv.tv_sec = _yplib_timeout;
+ tv.tv_usec = 0;
+
+ yprnk.domain = indomain;
+ yprnk.map = inmap;
+ bzero((char *)&yprkv, sizeof yprkv);
+
+ r = clnt_call(ysd->dom_client, YPPROC_FIRST,
+ xdr_ypreq_nokey, &yprnk, xdr_ypresp_key_val, &yprkv, tv);
+ if(r != RPC_SUCCESS) {
+ clnt_perror(ysd->dom_client, "yp_first: clnt_call");
+ _yp_unbind(ysd);
+ goto again;
+ }
+ if( !(r=ypprot_err(yprkv.stat)) ) {
+ *outkeylen = yprkv.key.keydat_len;
+ *outkey = (char *)malloc(*outkeylen+1);
+ bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
+ (*outkey)[*outkeylen] = '\0';
+ *outvallen = yprkv.val.valdat_len;
+ *outval = (char *)malloc(*outvallen+1);
+ bcopy(yprkv.val.valdat_val, *outval, *outvallen);
+ (*outval)[*outvallen] = '\0';
+ }
+
+ xdr_free(xdr_ypresp_key_val, (char *)&yprkv);
+ return r;
+}
+
+int
+yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen)
+ char *indomain;
+ char *inmap;
+ char *inkey;
+ int inkeylen;
+ char **outkey;
+ int *outkeylen;
+ char **outval;
+ int *outvallen;
+{
+ struct ypresp_key_val yprkv;
+ struct ypreq_key yprk;
+ struct dom_binding *ysd;
+ struct timeval tv;
+ int r;
+
+ /* Sanity check */
+
+ if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
+ inmap == NULL || !strlen(inmap) ||
+ indomain == NULL || !strlen(indomain))
+ return YPERR_BADARGS;
+
+ *outkey = *outval = NULL;
+ *outkeylen = *outvallen = 0;
+
+again:
+ if( _yp_dobind(indomain, &ysd) != 0)
+ return YPERR_DOMAIN;
+
+ tv.tv_sec = _yplib_timeout;
+ tv.tv_usec = 0;
+
+ yprk.domain = indomain;
+ yprk.map = inmap;
+ yprk.key.keydat_val = inkey;
+ yprk.key.keydat_len = inkeylen;
+ bzero((char *)&yprkv, sizeof yprkv);
+
+ r = clnt_call(ysd->dom_client, YPPROC_NEXT,
+ xdr_ypreq_key, &yprk, xdr_ypresp_key_val, &yprkv, tv);
+ if(r != RPC_SUCCESS) {
+ clnt_perror(ysd->dom_client, "yp_next: clnt_call");
+ _yp_unbind(ysd);
+ goto again;
+ }
+ if( !(r=ypprot_err(yprkv.stat)) ) {
+ *outkeylen = yprkv.key.keydat_len;
+ *outkey = (char *)malloc(*outkeylen+1);
+ bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
+ (*outkey)[*outkeylen] = '\0';
+ *outvallen = yprkv.val.valdat_len;
+ *outval = (char *)malloc(*outvallen+1);
+ bcopy(yprkv.val.valdat_val, *outval, *outvallen);
+ (*outval)[*outvallen] = '\0';
+ }
+
+ xdr_free(xdr_ypresp_key_val, (char *)&yprkv);
+ return r;
+}
+
+int
+yp_all(indomain, inmap, incallback)
+ char *indomain;
+ char *inmap;
+ struct ypall_callback *incallback;
+{
+ struct ypreq_nokey yprnk;
+ struct dom_binding *ysd;
+ struct timeval tv;
+ struct sockaddr_in clnt_sin;
+ CLIENT *clnt;
+ u_long status, savstat;
+ int clnt_sock;
+
+ /* Sanity check */
+
+ if (indomain == NULL || !strlen(indomain) ||
+ inmap == NULL || !strlen(inmap))
+ return YPERR_BADARGS;
+
+again:
+
+ if( _yp_dobind(indomain, &ysd) != 0)
+ return YPERR_DOMAIN;
+
+ tv.tv_sec = _yplib_timeout;
+ tv.tv_usec = 0;
+
+ /* YPPROC_ALL manufactures its own channel to ypserv using TCP */
+
+ clnt_sock = RPC_ANYSOCK;
+ clnt_sin = ysd->dom_server_addr;
+ clnt_sin.sin_port = 0;
+ clnt = clnttcp_create(&clnt_sin, YPPROG, YPVERS, &clnt_sock, 0, 0);
+ if(clnt==NULL) {
+ printf("clnttcp_create failed\n");
+ return YPERR_PMAP;
+ }
+
+ yprnk.domain = indomain;
+ yprnk.map = inmap;
+ ypresp_allfn = incallback->foreach;
+ ypresp_data = (void *)incallback->data;
+
+ if (clnt_call(clnt, YPPROC_ALL,
+ xdr_ypreq_nokey, &yprnk,
+ xdr_ypresp_all_seq, &status, tv) != RPC_SUCCESS) {
+ clnt_perror(ysd->dom_client, "yp_next: clnt_call");
+ clnt_destroy(clnt);
+ _yp_unbind(ysd);
+ goto again;
+ }
+
+ clnt_destroy(clnt);
+ savstat = status;
+ xdr_free(xdr_ypresp_all_seq, (char *)&status); /* not really needed... */
+ if(savstat != YP_NOMORE)
+ return ypprot_err(savstat);
+ return 0;
+}
+
+int
+yp_order(indomain, inmap, outorder)
+ char *indomain;
+ char *inmap;
+ int *outorder;
+{
+ struct dom_binding *ysd;
+ struct ypresp_order ypro;
+ struct ypreq_nokey yprnk;
+ struct timeval tv;
+ int r;
+
+ /* Sanity check */
+
+ if (indomain == NULL || !strlen(indomain) ||
+ inmap == NULL || !strlen(inmap))
+ return YPERR_BADARGS;
+
+again:
+ if( _yp_dobind(indomain, &ysd) != 0)
+ return YPERR_DOMAIN;
+
+ tv.tv_sec = _yplib_timeout;
+ tv.tv_usec = 0;
+
+ yprnk.domain = indomain;
+ yprnk.map = inmap;
+
+ bzero((char *)(char *)&ypro, sizeof ypro);
+
+ r = clnt_call(ysd->dom_client, YPPROC_ORDER,
+ xdr_ypreq_nokey, &yprnk, xdr_ypresp_order, &ypro, tv);
+
+ /*
+ * NIS+ in YP compat mode doesn't support the YPPROC_ORDER
+ * procedure.
+ */
+ if (r == RPC_PROCUNAVAIL) {
+ return(YPERR_YPERR);
+ }
+
+ if(r != RPC_SUCCESS) {
+ clnt_perror(ysd->dom_client, "yp_order: clnt_call");
+ _yp_unbind(ysd);
+ goto again;
+ }
+
+ if( !(r=ypprot_err(ypro.stat)) ) {
+ *outorder = ypro.ordernum;
+ }
+
+ xdr_free(xdr_ypresp_order, (char *)&ypro);
+ return (r);
+}
+
+int
+yp_master(indomain, inmap, outname)
+ char *indomain;
+ char *inmap;
+ char **outname;
+{
+ struct dom_binding *ysd;
+ struct ypresp_master yprm;
+ struct ypreq_nokey yprnk;
+ struct timeval tv;
+ int r;
+
+ /* Sanity check */
+
+ if (indomain == NULL || !strlen(indomain) ||
+ inmap == NULL || !strlen(inmap))
+ return YPERR_BADARGS;
+again:
+ if( _yp_dobind(indomain, &ysd) != 0)
+ return YPERR_DOMAIN;
+
+ tv.tv_sec = _yplib_timeout;
+ tv.tv_usec = 0;
+
+ yprnk.domain = indomain;
+ yprnk.map = inmap;
+
+ bzero((char *)&yprm, sizeof yprm);
+
+ r = clnt_call(ysd->dom_client, YPPROC_MASTER,
+ xdr_ypreq_nokey, &yprnk, xdr_ypresp_master, &yprm, tv);
+ if(r != RPC_SUCCESS) {
+ clnt_perror(ysd->dom_client, "yp_master: clnt_call");
+ _yp_unbind(ysd);
+ goto again;
+ }
+
+ if( !(r=ypprot_err(yprm.stat)) ) {
+ *outname = (char *)strdup(yprm.peer);
+ }
+
+ xdr_free(xdr_ypresp_master, (char *)&yprm);
+ return (r);
+}
+int
+yp_maplist(indomain, outmaplist)
+ char *indomain;
+ struct ypmaplist **outmaplist;
+{
+ struct dom_binding *ysd;
+ struct ypresp_maplist ypml;
+ struct timeval tv;
+ int r;
+
+ /* Sanity check */
+
+ if (indomain == NULL || !strlen(indomain))
+ return YPERR_BADARGS;
+
+again:
+ if( _yp_dobind(indomain, &ysd) != 0)
+ return YPERR_DOMAIN;
+
+ tv.tv_sec = _yplib_timeout;
+ tv.tv_usec = 0;
+
+ bzero((char *)&ypml, sizeof ypml);
+
+ r = clnt_call(ysd->dom_client, YPPROC_MAPLIST,
+ xdr_domainname,(char *)&indomain,xdr_ypresp_maplist,&ypml,tv);
+ if (r != RPC_SUCCESS) {
+ clnt_perror(ysd->dom_client, "yp_maplist: clnt_call");
+ _yp_unbind(ysd);
+ goto again;
+ }
+ if( !(r=ypprot_err(ypml.stat)) ) {
+ *outmaplist = ypml.maps;
+ }
+
+ /* NO: xdr_free(xdr_ypresp_maplist, &ypml);*/
+ return (r);
+}
+
+char *
+yperr_string(incode)
+ int incode;
+{
+ static char err[80];
+
+ switch(incode) {
+ case 0:
+ return "Success";
+ case YPERR_BADARGS:
+ return "Request arguments bad";
+ case YPERR_RPC:
+ return "RPC failure";
+ case YPERR_DOMAIN:
+ return "Can't bind to server which serves this domain";
+ case YPERR_MAP:
+ return "No such map in server's domain";
+ case YPERR_KEY:
+ return "No such key in map";
+ case YPERR_YPERR:
+ return "YP server error";
+ case YPERR_RESRC:
+ return "Local resource allocation failure";
+ case YPERR_NOMORE:
+ return "No more records in map database";
+ case YPERR_PMAP:
+ return "Can't communicate with portmapper";
+ case YPERR_YPBIND:
+ return "Can't communicate with ypbind";
+ case YPERR_YPSERV:
+ return "Can't communicate with ypserv";
+ case YPERR_NODOM:
+ return "Local domain name not set";
+ case YPERR_BADDB:
+ return "Server data base is bad";
+ case YPERR_VERS:
+ return "YP server version mismatch - server can't supply service.";
+ case YPERR_ACCESS:
+ return "Access violation";
+ case YPERR_BUSY:
+ return "Database is busy";
+ }
+ sprintf(err, "YP unknown error %d\n", incode);
+ return err;
+}
+
+int
+ypprot_err(incode)
+ unsigned int incode;
+{
+ switch(incode) {
+ case YP_TRUE:
+ return 0;
+ case YP_FALSE:
+ return YPERR_YPBIND;
+ case YP_NOMORE:
+ return YPERR_NOMORE;
+ case YP_NOMAP:
+ return YPERR_MAP;
+ case YP_NODOM:
+ return YPERR_DOMAIN;
+ case YP_NOKEY:
+ return YPERR_KEY;
+ case YP_BADOP:
+ return YPERR_YPERR;
+ case YP_BADDB:
+ return YPERR_BADDB;
+ case YP_YPERR:
+ return YPERR_YPERR;
+ case YP_BADARGS:
+ return YPERR_BADARGS;
+ case YP_VERS:
+ return YPERR_VERS;
+ }
+ return YPERR_YPERR;
+}
+
+int
+_yp_check(dom)
+ char **dom;
+{
+ char *unused;
+
+ if( _yp_domain[0]=='\0' )
+ if( yp_get_default_domain(&unused) )
+ return 0;
+
+ if(dom)
+ *dom = _yp_domain;
+
+ if( yp_bind(_yp_domain)==0 ) {
+ yp_unbind(_yp_domain);
+ return 1;
+ }
+ return 0;
+}
OpenPOWER on IntegriCloud