From b5d655f7532a546b54809da387f7467d128a756b Mon Sep 17 00:00:00 2001 From: Apple Date: Wed, 12 Nov 2008 00:43:47 +0000 Subject: [PATCH] Libc-498.1.5.tar.gz --- BSDmakefile | 50 +- Makefile | 58 +- Makefile.autopatch | 6 - Makefile.fbsd_end | 29 +- Makefile.features | 112 + Makefile.inc | 37 +- Makefile.nbsd_end | 25 +- Makefile.obsd_end | 25 +- Makefile.xbs | 81 +- Platforms/AppleTV/Makefile.inc | 56 + Platforms/AppleTV/i386/libc.syscall.i386 | 46 + Platforms/MacOSX/Makefile.inc | 58 + Platforms/MacOSX/arm/libc.syscall.arm | 88 + .../MacOSX/i386}/libc.syscall.i386 | 6 + .../MacOSX/ppc}/libc.syscall.ppc | 6 + .../MacOSX/ppc64}/libc.syscall.ppc64 | 6 + .../MacOSX/x86_64}/libc.syscall.x86_64 | 6 + Platforms/iPhone/Makefile.inc | 56 + Platforms/iPhone/arm/libc.syscall.arm | 45 + arm/Makefile.inc | 3 + arm/gen/Makefile.inc | 2 + arm/gen/icacheinval.s | 44 + arm/mach/Makefile.inc | 2 + arm/mach/mach_absolute_time.c | 30 + arm/mach/mach_absolute_time.s | 29 + arm/pthreads/Makefile.inc | 7 + arm/pthreads/get_cpu_capabilities.s | 36 + arm/pthreads/init_cpu_capabilities.c | 38 + arm/pthreads/pthread_getspecific.s | 35 + arm/pthreads/pthread_self.s | 32 + arm/pthreads/pthread_set_self.s | 28 + arm/stdlib/gdtoa.mk | 1 + arm/string/Makefile.inc | 14 + arm/string/bcopy.s | 401 ++++ arm/string/bzero.s | 160 ++ arm/string/ffs.s | 50 + arm/string/strcmp.s | 44 + arm/string/strlen.s | 78 + arm/sys/Makefile.inc | 12 + arm/sys/OSAtomic-v4.c | 166 ++ arm/sys/OSAtomic.s | 217 ++ arm/sys/SYS.h | 206 ++ arm/sys/_longjmp.s | 44 + arm/sys/_setjmp.h | 52 + arm/sys/_setjmp.s | 41 + arm/sys/arm_commpage_gettimeofday.c | 70 + arm/sys/arm_gettimeofday.s | 35 + arm/sys/longjmp.s | 57 + arm/sys/setjmp.s | 61 + available.ex | 13 - compat-43/Makefile.inc | 1 + compat-43/gethostid-fbsd.c | 57 +- compat-43/getwd-fbsd.c | 57 +- compat-43/sethostid-fbsd.c | 54 +- compat-43/setrgid-fbsd.c | 48 +- compat-43/setruid-fbsd.c | 48 +- darwin/Makefile.inc | 9 +- db/Makefile.inc | 2 - db/btree/Makefile.inc | 12 +- db/btree/bt_close-fbsd.c | 187 +- db/btree/bt_conv-fbsd.c | 224 +- db/btree/bt_debug-fbsd.c | 333 +-- db/btree/bt_delete-fbsd.c | 660 +----- db/btree/bt_extern.h | 72 +- db/btree/bt_get-fbsd.c | 108 +- db/btree/bt_open-fbsd.c | 450 +--- db/btree/bt_overflow-fbsd.c | 231 +-- db/btree/bt_page-fbsd.c | 103 +- db/btree/bt_put-fbsd.c | 326 +-- db/btree/bt_search-fbsd.c | 216 +- db/btree/bt_seq-fbsd.c | 463 +---- db/btree/bt_split-fbsd.c | 828 +------- db/btree/bt_utils-fbsd.c | 263 +-- db/db/Makefile.inc | 1 + db/db/db-fbsd.c | 102 +- db/hash/Makefile.inc | 10 +- db/hash/hash_extern.h | 67 +- db/hash/hash_log2-fbsd.c | 57 +- db/hash/page.h | 94 +- db/man/Makefile.inc | 1 + db/mpool/Makefile.inc | 1 + db/recno/Makefile.inc | 10 +- db/recno/rec_close-fbsd.c | 189 +- db/recno/rec_delete-fbsd.c | 200 +- db/recno/rec_get-fbsd.c | 314 +-- db/recno/rec_open-fbsd.c | 246 +-- db/recno/rec_put-fbsd.c | 288 +-- db/recno/rec_search-fbsd.c | 129 +- db/recno/rec_seq-fbsd.c | 135 +- db/recno/rec_utils-fbsd.c | 125 +- fbsdcompat/_fpmath.h | 29 + fbsdcompat/port_after.h | 1 + fbsdcompat/port_before.h | 1 + gdtoa/FreeBSD/_hdtoa.c.patch | 27 +- gdtoa/FreeBSD/gdtoa-hexnan.c.patch | 2 +- gdtoa/FreeBSD/gdtoaimp.h.patch | 23 +- gdtoa/FreeBSD/machdep_ldisd.c.patch | 14 + gdtoa/Makefile.inc | 23 +- gdtoa/_hdtoa-fbsd.c | 2 + gdtoa/arith.h | 6 + gdtoa/gd_qnan.h | 2 +- gdtoa/gdtoa-dmisc-fbsd.c | 217 +- gdtoa/gdtoa-dtoa-fbsd.c | 754 +------ gdtoa/gdtoa-gmisc-fbsd.c | 87 +- gdtoa/gdtoa-hd_init-fbsd.c | 56 +- gdtoa/gdtoa-hexnan-fbsd.c | 2 +- gdtoa/gdtoa-misc-fbsd.c | 866 +------- gdtoa/gdtoa-sum-fbsd.c | 99 +- gdtoa/gdtoa-ulp-fbsd.c | 71 +- gdtoa/gdtoa.h | 154 +- gdtoa/gdtoaimp.h | 4 - gdtoa/glue-fbsd.c | 11 +- gdtoa/machdep_ldisd-fbsd.c | 51 + gen/FreeBSD/getmntinfo.3.patch | 41 +- gen/FreeBSD/glob.c.patch | 216 +- gen/FreeBSD/time.c.patch | 14 +- gen/Makefile.inc | 47 +- gen/NetBSD/utmpx.c.patch | 27 +- gen/alarm-fbsd.c | 62 +- gen/asl.3 | 272 ++- gen/asl.c | 406 ++-- gen/asl_core.c | 245 +++ gen/asl_core.h | 84 + gen/asl_file.c | 1837 +++++++++++++++++ gen/asl_file.h | 150 ++ gen/asl_legacy1.c | 1823 ++++++++++++++++ gen/asl_legacy1.h | 86 + gen/asl_private.h | 12 +- gen/asl_store.c | 720 +++++++ gen/asl_store.h | 82 + gen/asl_util.c | 4 +- gen/clock-fbsd.c | 60 +- gen/ctermid-fbsd.c | 62 +- gen/errno_-fbsd.c | 31 +- gen/fmtcheck-fbsd.c | 268 +-- gen/ftok-fbsd.c | 47 +- gen/getbsize-fbsd.c | 110 +- gen/getmntinfo-fbsd.c | 73 +- gen/getmntinfo.3 | 26 + gen/getpagesize-fbsd.c | 67 +- gen/getpeereid-fbsd.c | 55 +- gen/glob-fbsd.c | 72 +- gen/isinf.c | 2 +- gen/isnan.c | 2 +- gen/psignal-fbsd.c | 68 +- gen/raise-fbsd.c | 52 +- gen/rewinddir-fbsd.c | 53 +- gen/scandir-fbsd.c | 151 +- gen/seekdir-fbsd.c | 64 +- gen/sethostname-fbsd.c | 54 +- gen/setmode-fbsd.c | 460 +---- gen/siginterrupt-fbsd.c | 68 +- gen/stringlist-fbsd.c | 126 +- gen/sysctl-fbsd.c | 188 +- gen/sysctlbyname-fbsd.c | 40 +- gen/sysctlnametomib-fbsd.c | 56 +- gen/syslog.c | 45 +- gen/thread_stack_pcs.c | 6 +- gen/time-fbsd.c | 6 + gen/times-fbsd.c | 70 +- gen/timezone-fbsd.c | 138 +- gen/ttyslot-fbsd.c | 71 +- gen/tzset.3 | 4 + gen/ualarm-fbsd.c | 68 +- gen/ulimit-fbsd.c | 69 +- gen/utime-fbsd.c | 60 +- gen/utmpx-darwin.c | 279 ++- gen/utmpx-nbsd.c | 5 +- gen/wait3-fbsd.c | 55 +- gmon/Makefile.inc | 12 +- gmon/gmon.c | 5 +- i386/sys/Makefile.inc | 2 +- include/Makefile.inc | 19 +- include/NetBSD/utmpx.h.patch | 8 +- include/_.libc_internal.h | 87 - include/arpa/nameser_compat.h | 5 +- include/asl.h | 36 +- include/glob.h | 3 - include/libkern/Makefile.inc | 7 +- include/libkern/OSMemoryNotification.h | 99 + include/libkern/OSThermalNotification.h | 68 + include/machine/limits.h | 2 + include/protocols/dumprestore.h | 4 +- include/stdlib.h | 6 +- include/sys/cdefs.h | 114 + include/util.h | 16 +- include/utmp.h | 8 +- include/utmpx.h | 2 + include/xlocale/Makefile.inc | 2 - locale/FreeBSD/localeconv.c.patch | 14 +- locale/FreeBSD/setrunelocale.c.patch | 19 +- locale/Makefile.inc | 50 +- locale/lconv.c | 3 - locale/localeconv-fbsd.c | 4 + locale/nomacros-fbsd.c | 13 +- locale/setrunelocale-fbsd.c | 9 + locale/xlocale.3 | 2 + man/Makefile.inc | 3 + man/utmp.5 | 234 +++ net/FreeBSD/inet_net.3 | 20 +- net/FreeBSD/inet_net.3.patch | 26 + net/FreeBSD/inet_net_pton.c | 354 +++- net/FreeBSD/inet_net_pton.c.patch | 93 +- net/Makefile.inc | 7 +- net/addr2ascii-fbsd.c | 96 +- net/ascii2addr-fbsd.c | 76 +- net/inet_lnaof-fbsd.c | 69 +- net/inet_makeaddr-fbsd.c | 72 +- net/inet_net.3 | 168 +- net/inet_net_ntop-fbsd.c | 149 +- net/inet_net_pton-fbsd.c | 375 +++- net/inet_neta-fbsd.c | 93 +- net/inet_netof-fbsd.c | 68 +- net/inet_ntoa-fbsd.c | 68 +- net/linkaddr-fbsd.c | 161 +- net/sockatmark-fbsd.c | 37 +- nls/Makefile.inc | 1 + ppc/sys/Makefile.inc | 2 +- ppc64/sys/Makefile.inc | 2 +- pthreads/Makefile.inc | 14 +- pthreads/pthread.c | 50 +- pthreads/pthread_cond.c | 8 +- pthreads/pthread_internals.h | 5 +- pthreads/pthread_machdep.h | 3 + pthreads/pthread_mutex.c | 12 +- pthreads/pthread_rwlock.c | 11 +- pthreads/stack.s | 19 + pthreads/thread_setup.c | 46 +- regex/Makefile.inc | 1 + regex/cclass.h | 64 +- regex/cname.h | 143 +- regex/regerror-fbsd.c | 182 +- regex/utils.h | 59 +- stdio/Makefile.inc | 1 + stdio/_flock_stub-fbsd.c | 150 +- stdio/clrerr-fbsd.c | 57 +- stdio/fdopen-fbsd.c | 94 +- stdio/feof-fbsd.c | 60 +- stdio/ferror-fbsd.c | 60 +- stdio/fgetc-fbsd.c | 61 +- stdio/fgetln-fbsd.c | 169 +- stdio/fgetpos-fbsd.c | 56 +- stdio/fgets-fbsd.c | 117 +- stdio/fileno-fbsd.c | 61 +- stdio/floatio.h | 59 +- stdio/fopen-fbsd.c | 89 +- stdio/fpurge-fbsd.c | 75 +- stdio/fputc-fbsd.c | 62 +- stdio/fread-fbsd.c | 92 +- stdio/fseek-fbsd.c | 315 +-- stdio/fsetpos-fbsd.c | 56 +- stdio/funopen-fbsd.c | 81 +- stdio/fvwrite-fbsd.c | 212 +- stdio/fvwrite.h | 54 +- stdio/fwalk-fbsd.c | 72 +- stdio/fwide-fbsd.c | 52 +- stdio/getc-fbsd.c | 62 +- stdio/getchar-fbsd.c | 65 +- stdio/gets-fbsd.c | 82 +- stdio/getw-fbsd.c | 53 +- stdio/putc-fbsd.c | 64 +- stdio/putchar-fbsd.c | 68 +- stdio/putw-fbsd.c | 67 +- stdio/refill-fbsd.c | 151 +- stdio/remove-fbsd.c | 60 +- stdio/rget-fbsd.c | 60 +- stdio/setbuf-fbsd.c | 51 +- stdio/setbuffer-fbsd.c | 65 +- stdio/setvbuf-fbsd.c | 166 +- stdio/stdio-fbsd.c | 192 +- stdio/tmpfile-fbsd.c | 97 +- stdio/tmpnam-fbsd.c | 66 +- stdio/ungetc-fbsd.c | 173 +- stdio/unlocked-fbsd.c | 95 +- stdio/wsetup-fbsd.c | 97 +- stdlib/FreeBSD/atexit.c.patch | 25 +- stdlib/Makefile.inc | 19 +- stdlib/{FreeBSD => NetBSD}/strfmon.3 | 8 +- stdlib/{FreeBSD => NetBSD}/strfmon.3.patch | 16 +- stdlib/{FreeBSD => NetBSD}/strfmon.c | 56 +- stdlib/{FreeBSD => NetBSD}/strfmon.c.patch | 77 +- stdlib/_Exit_-fbsd.c | 23 +- stdlib/abs-fbsd.c | 48 +- stdlib/atexit-fbsd.c | 8 +- stdlib/bsearch-fbsd.c | 84 +- stdlib/div-fbsd.c | 82 +- stdlib/getopt_long-fbsd.c | 643 +----- stdlib/getsubopt-fbsd.c | 102 +- stdlib/hcreate-fbsd.c | 186 +- stdlib/heapsort-fbsd.c | 186 +- stdlib/imaxabs-fbsd.c | 37 +- stdlib/imaxdiv-fbsd.c | 46 +- stdlib/insque-fbsd.c | 48 +- stdlib/labs-fbsd.c | 48 +- stdlib/ldiv-fbsd.c | 61 +- stdlib/llabs-fbsd.c | 37 +- stdlib/lldiv-fbsd.c | 46 +- stdlib/lsearch-fbsd.c | 65 +- stdlib/merge-fbsd.c | 353 +--- stdlib/rand-fbsd.c | 173 +- stdlib/reallocf-fbsd.c | 42 +- stdlib/remque-fbsd.c | 31 +- stdlib/{strfmon-fbsd.c => strfmon-nbsd.c} | 58 +- stdlib/strfmon.3 | 12 +- stdlib/tdelete-fbsd.c | 72 +- stdlib/tfind-fbsd.c | 49 +- stdlib/tsearch-fbsd.c | 59 +- stdlib/twalk-fbsd.c | 59 +- stdtime/FreeBSD/strptime.c.patch | 106 +- stdtime/FreeBSD/tzfile.h.patch | 14 + stdtime/Makefile.inc | 5 +- stdtime/difftime-fbsd.c | 88 +- stdtime/ftime-fbsd.c | 55 +- stdtime/private.h | 261 +-- stdtime/strptime-fbsd.c | 37 +- stdtime/time32-fbsd.c | 101 +- stdtime/tzfile.h | 4 + string/Makefile.inc | 7 +- string/bcmp-fbsd.c | 60 +- string/index-fbsd.c | 66 +- string/memccpy-fbsd.c | 61 +- string/memchr-fbsd.c | 61 +- string/memcmp-fbsd.c | 63 +- string/memset-fbsd.c | 133 +- string/rindex-fbsd.c | 67 +- string/stpcpy-fbsd.c | 47 +- string/strcat-fbsd.c | 51 +- string/strcpy-fbsd.c | 50 +- string/strcspn-fbsd.c | 73 +- string/strdup-fbsd.c | 57 +- string/strlcat-fbsd.c | 76 +- string/strlcpy-fbsd.c | 71 +- string/strlen-fbsd.c | 52 +- string/strmode-fbsd.c | 155 +- string/strncat-fbsd.c | 67 +- string/strncmp-fbsd.c | 59 +- string/strncpy-fbsd.c | 67 +- string/strnstr-fbsd.c | 73 +- string/strpbrk-fbsd.c | 59 +- string/strsep-fbsd.c | 82 +- string/strspn-fbsd.c | 72 +- string/strstr-fbsd.c | 67 +- string/strtok-fbsd.c | 141 +- string/wcscat-fbsd.c | 54 +- string/wcschr-fbsd.c | 42 +- string/wcscmp-fbsd.c | 62 +- string/wcscpy-fbsd.c | 52 +- string/wcscspn-fbsd.c | 61 +- string/wcslcat-fbsd.c | 78 +- string/wcslcpy-fbsd.c | 74 +- string/wcslen-fbsd.c | 51 +- string/wcsncat-fbsd.c | 61 +- string/wcsncmp-fbsd.c | 64 +- string/wcsncpy-fbsd.c | 69 +- string/wcspbrk-fbsd.c | 61 +- string/wcsrchr-fbsd.c | 48 +- string/wcsspn-fbsd.c | 63 +- string/wcsstr-fbsd.c | 68 +- string/wcstok-fbsd.c | 91 +- string/wmemchr-fbsd.c | 56 +- string/wmemcmp-fbsd.c | 57 +- string/wmemcpy-fbsd.c | 49 +- string/wmemmove-fbsd.c | 49 +- string/wmemset-fbsd.c | 55 +- sys/Makefile.inc | 35 +- sys/OSMemoryNotification.c | 143 ++ sys/OSThermalNotification.c | 44 + sys/fix-3375657.c | 4 - sys/libc.syscall | 6 - sys/statx_np.c | 4 +- threads/Makefile.inc | 6 +- util/Makefile.inc | 19 +- uuid/Makefile.inc | 22 +- uuid/clear-uuid.c | 44 +- uuid/compare-uuid.c | 56 +- uuid/copy-uuid.c | 46 +- uuid/isnull-uuid.c | 49 +- uuid/pack-uuid.c | 70 +- uuid/parse-uuid.c | 80 +- uuid/unpack-uuid.c | 64 +- uuid/unparse-uuid.c | 77 +- x86_64/sys/Makefile.inc | 2 +- 382 files changed, 11126 insertions(+), 24812 deletions(-) delete mode 100644 Makefile.autopatch create mode 100644 Makefile.features create mode 100644 Platforms/AppleTV/Makefile.inc create mode 100644 Platforms/AppleTV/i386/libc.syscall.i386 create mode 100644 Platforms/MacOSX/Makefile.inc create mode 100644 Platforms/MacOSX/arm/libc.syscall.arm rename {i386/sys => Platforms/MacOSX/i386}/libc.syscall.i386 (94%) rename {ppc/sys => Platforms/MacOSX/ppc}/libc.syscall.ppc (94%) rename {ppc64/sys => Platforms/MacOSX/ppc64}/libc.syscall.ppc64 (84%) rename {x86_64/sys => Platforms/MacOSX/x86_64}/libc.syscall.x86_64 (84%) create mode 100644 Platforms/iPhone/Makefile.inc create mode 100644 Platforms/iPhone/arm/libc.syscall.arm create mode 100644 arm/Makefile.inc create mode 100644 arm/gen/Makefile.inc create mode 100644 arm/gen/icacheinval.s create mode 100644 arm/mach/Makefile.inc create mode 100644 arm/mach/mach_absolute_time.c create mode 100644 arm/mach/mach_absolute_time.s create mode 100644 arm/pthreads/Makefile.inc create mode 100644 arm/pthreads/get_cpu_capabilities.s create mode 100644 arm/pthreads/init_cpu_capabilities.c create mode 100644 arm/pthreads/pthread_getspecific.s create mode 100644 arm/pthreads/pthread_self.s create mode 100644 arm/pthreads/pthread_set_self.s create mode 100644 arm/stdlib/gdtoa.mk create mode 100644 arm/string/Makefile.inc create mode 100644 arm/string/bcopy.s create mode 100644 arm/string/bzero.s create mode 100644 arm/string/ffs.s create mode 100644 arm/string/strcmp.s create mode 100644 arm/string/strlen.s create mode 100644 arm/sys/Makefile.inc create mode 100644 arm/sys/OSAtomic-v4.c create mode 100644 arm/sys/OSAtomic.s create mode 100644 arm/sys/SYS.h create mode 100644 arm/sys/_longjmp.s create mode 100644 arm/sys/_setjmp.h create mode 100644 arm/sys/_setjmp.s create mode 100644 arm/sys/arm_commpage_gettimeofday.c create mode 100644 arm/sys/arm_gettimeofday.s create mode 100644 arm/sys/longjmp.s create mode 100644 arm/sys/setjmp.s delete mode 100644 available.ex mode change 100644 => 120000 compat-43/gethostid-fbsd.c mode change 100644 => 120000 compat-43/getwd-fbsd.c mode change 100644 => 120000 compat-43/sethostid-fbsd.c mode change 100644 => 120000 compat-43/setrgid-fbsd.c mode change 100644 => 120000 compat-43/setruid-fbsd.c mode change 100644 => 120000 db/btree/bt_close-fbsd.c mode change 100644 => 120000 db/btree/bt_conv-fbsd.c mode change 100644 => 120000 db/btree/bt_debug-fbsd.c mode change 100644 => 120000 db/btree/bt_delete-fbsd.c mode change 100644 => 120000 db/btree/bt_extern.h mode change 100644 => 120000 db/btree/bt_get-fbsd.c mode change 100644 => 120000 db/btree/bt_open-fbsd.c mode change 100644 => 120000 db/btree/bt_overflow-fbsd.c mode change 100644 => 120000 db/btree/bt_page-fbsd.c mode change 100644 => 120000 db/btree/bt_put-fbsd.c mode change 100644 => 120000 db/btree/bt_search-fbsd.c mode change 100644 => 120000 db/btree/bt_seq-fbsd.c mode change 100644 => 120000 db/btree/bt_split-fbsd.c mode change 100644 => 120000 db/btree/bt_utils-fbsd.c mode change 100644 => 120000 db/db/db-fbsd.c mode change 100644 => 120000 db/hash/hash_extern.h mode change 100644 => 120000 db/hash/hash_log2-fbsd.c mode change 100644 => 120000 db/hash/page.h mode change 100644 => 120000 db/recno/rec_close-fbsd.c mode change 100644 => 120000 db/recno/rec_delete-fbsd.c mode change 100644 => 120000 db/recno/rec_get-fbsd.c mode change 100644 => 120000 db/recno/rec_open-fbsd.c mode change 100644 => 120000 db/recno/rec_put-fbsd.c mode change 100644 => 120000 db/recno/rec_search-fbsd.c mode change 100644 => 120000 db/recno/rec_seq-fbsd.c mode change 100644 => 120000 db/recno/rec_utils-fbsd.c create mode 100644 fbsdcompat/port_after.h create mode 100644 fbsdcompat/port_before.h create mode 100644 gdtoa/FreeBSD/machdep_ldisd.c.patch mode change 100644 => 120000 gdtoa/gdtoa-dmisc-fbsd.c mode change 100644 => 120000 gdtoa/gdtoa-dtoa-fbsd.c mode change 100644 => 120000 gdtoa/gdtoa-gmisc-fbsd.c mode change 100644 => 120000 gdtoa/gdtoa-hd_init-fbsd.c mode change 100644 => 120000 gdtoa/gdtoa-misc-fbsd.c mode change 100644 => 120000 gdtoa/gdtoa-sum-fbsd.c mode change 100644 => 120000 gdtoa/gdtoa-ulp-fbsd.c mode change 100644 => 120000 gdtoa/gdtoa.h mode change 100644 => 120000 gdtoa/glue-fbsd.c create mode 100644 gdtoa/machdep_ldisd-fbsd.c mode change 100644 => 120000 gen/alarm-fbsd.c create mode 100644 gen/asl_core.c create mode 100644 gen/asl_core.h create mode 100644 gen/asl_file.c create mode 100644 gen/asl_file.h create mode 100644 gen/asl_legacy1.c create mode 100644 gen/asl_legacy1.h create mode 100644 gen/asl_store.c create mode 100644 gen/asl_store.h mode change 100644 => 120000 gen/clock-fbsd.c mode change 100644 => 120000 gen/ctermid-fbsd.c mode change 100644 => 120000 gen/errno_-fbsd.c mode change 100644 => 120000 gen/fmtcheck-fbsd.c mode change 100644 => 120000 gen/ftok-fbsd.c mode change 100644 => 120000 gen/getbsize-fbsd.c mode change 100644 => 120000 gen/getmntinfo-fbsd.c mode change 100644 => 120000 gen/getpagesize-fbsd.c mode change 100644 => 120000 gen/getpeereid-fbsd.c mode change 100644 => 120000 gen/psignal-fbsd.c mode change 100644 => 120000 gen/raise-fbsd.c mode change 100644 => 120000 gen/rewinddir-fbsd.c mode change 100644 => 120000 gen/scandir-fbsd.c mode change 100644 => 120000 gen/seekdir-fbsd.c mode change 100644 => 120000 gen/sethostname-fbsd.c mode change 100644 => 120000 gen/setmode-fbsd.c mode change 100644 => 120000 gen/siginterrupt-fbsd.c mode change 100644 => 120000 gen/stringlist-fbsd.c mode change 100644 => 120000 gen/sysctl-fbsd.c mode change 100644 => 120000 gen/sysctlbyname-fbsd.c mode change 100644 => 120000 gen/sysctlnametomib-fbsd.c mode change 100644 => 120000 gen/times-fbsd.c mode change 100644 => 120000 gen/timezone-fbsd.c mode change 100644 => 120000 gen/ttyslot-fbsd.c mode change 100644 => 120000 gen/ualarm-fbsd.c mode change 100644 => 120000 gen/ulimit-fbsd.c mode change 100644 => 120000 gen/utime-fbsd.c mode change 100644 => 120000 gen/wait3-fbsd.c delete mode 100644 include/_.libc_internal.h create mode 100644 include/libkern/OSMemoryNotification.h create mode 100644 include/libkern/OSThermalNotification.h create mode 100644 include/sys/cdefs.h mode change 100644 => 120000 locale/nomacros-fbsd.c create mode 100644 man/utmp.5 create mode 100644 net/FreeBSD/inet_net.3.patch mode change 100644 => 120000 net/addr2ascii-fbsd.c mode change 100644 => 120000 net/ascii2addr-fbsd.c mode change 100644 => 120000 net/inet_lnaof-fbsd.c mode change 100644 => 120000 net/inet_makeaddr-fbsd.c mode change 120000 => 100644 net/inet_net.3 mode change 100644 => 120000 net/inet_net_ntop-fbsd.c mode change 100644 => 120000 net/inet_neta-fbsd.c mode change 100644 => 120000 net/inet_netof-fbsd.c mode change 100644 => 120000 net/inet_ntoa-fbsd.c mode change 100644 => 120000 net/linkaddr-fbsd.c mode change 100644 => 120000 net/sockatmark-fbsd.c mode change 100644 => 120000 regex/cclass.h mode change 100644 => 120000 regex/cname.h mode change 100644 => 120000 regex/regerror-fbsd.c mode change 100644 => 120000 regex/utils.h mode change 100644 => 120000 stdio/_flock_stub-fbsd.c mode change 100644 => 120000 stdio/clrerr-fbsd.c mode change 100644 => 120000 stdio/fdopen-fbsd.c mode change 100644 => 120000 stdio/feof-fbsd.c mode change 100644 => 120000 stdio/ferror-fbsd.c mode change 100644 => 120000 stdio/fgetc-fbsd.c mode change 100644 => 120000 stdio/fgetln-fbsd.c mode change 100644 => 120000 stdio/fgetpos-fbsd.c mode change 100644 => 120000 stdio/fgets-fbsd.c mode change 100644 => 120000 stdio/fileno-fbsd.c mode change 100644 => 120000 stdio/floatio.h mode change 100644 => 120000 stdio/fopen-fbsd.c mode change 100644 => 120000 stdio/fpurge-fbsd.c mode change 100644 => 120000 stdio/fputc-fbsd.c mode change 100644 => 120000 stdio/fread-fbsd.c mode change 100644 => 120000 stdio/fseek-fbsd.c mode change 100644 => 120000 stdio/fsetpos-fbsd.c mode change 100644 => 120000 stdio/funopen-fbsd.c mode change 100644 => 120000 stdio/fvwrite-fbsd.c mode change 100644 => 120000 stdio/fvwrite.h mode change 100644 => 120000 stdio/fwalk-fbsd.c mode change 100644 => 120000 stdio/fwide-fbsd.c mode change 100644 => 120000 stdio/getc-fbsd.c mode change 100644 => 120000 stdio/getchar-fbsd.c mode change 100644 => 120000 stdio/gets-fbsd.c mode change 100644 => 120000 stdio/getw-fbsd.c mode change 100644 => 120000 stdio/putc-fbsd.c mode change 100644 => 120000 stdio/putchar-fbsd.c mode change 100644 => 120000 stdio/putw-fbsd.c mode change 100644 => 120000 stdio/refill-fbsd.c mode change 100644 => 120000 stdio/remove-fbsd.c mode change 100644 => 120000 stdio/rget-fbsd.c mode change 100644 => 120000 stdio/setbuf-fbsd.c mode change 100644 => 120000 stdio/setbuffer-fbsd.c mode change 100644 => 120000 stdio/setvbuf-fbsd.c mode change 100644 => 120000 stdio/stdio-fbsd.c mode change 100644 => 120000 stdio/tmpfile-fbsd.c mode change 100644 => 120000 stdio/tmpnam-fbsd.c mode change 100644 => 120000 stdio/ungetc-fbsd.c mode change 100644 => 120000 stdio/unlocked-fbsd.c mode change 100644 => 120000 stdio/wsetup-fbsd.c rename stdlib/{FreeBSD => NetBSD}/strfmon.3 (95%) rename stdlib/{FreeBSD => NetBSD}/strfmon.3.patch (86%) rename stdlib/{FreeBSD => NetBSD}/strfmon.c (93%) rename stdlib/{FreeBSD => NetBSD}/strfmon.c.patch (77%) mode change 100644 => 120000 stdlib/_Exit_-fbsd.c mode change 100644 => 120000 stdlib/abs-fbsd.c mode change 100644 => 120000 stdlib/bsearch-fbsd.c mode change 100644 => 120000 stdlib/div-fbsd.c mode change 100644 => 120000 stdlib/getopt_long-fbsd.c mode change 100644 => 120000 stdlib/getsubopt-fbsd.c mode change 100644 => 120000 stdlib/hcreate-fbsd.c mode change 100644 => 120000 stdlib/heapsort-fbsd.c mode change 100644 => 120000 stdlib/imaxabs-fbsd.c mode change 100644 => 120000 stdlib/imaxdiv-fbsd.c mode change 100644 => 120000 stdlib/insque-fbsd.c mode change 100644 => 120000 stdlib/labs-fbsd.c mode change 100644 => 120000 stdlib/ldiv-fbsd.c mode change 100644 => 120000 stdlib/llabs-fbsd.c mode change 100644 => 120000 stdlib/lldiv-fbsd.c mode change 100644 => 120000 stdlib/lsearch-fbsd.c mode change 100644 => 120000 stdlib/merge-fbsd.c mode change 100644 => 120000 stdlib/rand-fbsd.c mode change 100644 => 120000 stdlib/reallocf-fbsd.c mode change 100644 => 120000 stdlib/remque-fbsd.c rename stdlib/{strfmon-fbsd.c => strfmon-nbsd.c} (92%) mode change 100644 => 120000 stdlib/tdelete-fbsd.c mode change 100644 => 120000 stdlib/tfind-fbsd.c mode change 100644 => 120000 stdlib/tsearch-fbsd.c mode change 100644 => 120000 stdlib/twalk-fbsd.c create mode 100644 stdtime/FreeBSD/tzfile.h.patch mode change 100644 => 120000 stdtime/difftime-fbsd.c mode change 100644 => 120000 stdtime/ftime-fbsd.c mode change 100644 => 120000 stdtime/private.h mode change 100644 => 120000 stdtime/time32-fbsd.c mode change 100644 => 120000 string/bcmp-fbsd.c mode change 100644 => 120000 string/index-fbsd.c mode change 100644 => 120000 string/memccpy-fbsd.c mode change 100644 => 120000 string/memchr-fbsd.c mode change 100644 => 120000 string/memcmp-fbsd.c mode change 100644 => 120000 string/memset-fbsd.c mode change 100644 => 120000 string/rindex-fbsd.c mode change 100644 => 120000 string/stpcpy-fbsd.c mode change 100644 => 120000 string/strcat-fbsd.c mode change 100644 => 120000 string/strcpy-fbsd.c mode change 100644 => 120000 string/strcspn-fbsd.c mode change 100644 => 120000 string/strdup-fbsd.c mode change 100644 => 120000 string/strlcat-fbsd.c mode change 100644 => 120000 string/strlcpy-fbsd.c mode change 100644 => 120000 string/strlen-fbsd.c mode change 100644 => 120000 string/strmode-fbsd.c mode change 100644 => 120000 string/strncat-fbsd.c mode change 100644 => 120000 string/strncmp-fbsd.c mode change 100644 => 120000 string/strncpy-fbsd.c mode change 100644 => 120000 string/strnstr-fbsd.c mode change 100644 => 120000 string/strpbrk-fbsd.c mode change 100644 => 120000 string/strsep-fbsd.c mode change 100644 => 120000 string/strspn-fbsd.c mode change 100644 => 120000 string/strstr-fbsd.c mode change 100644 => 120000 string/strtok-fbsd.c mode change 100644 => 120000 string/wcscat-fbsd.c mode change 100644 => 120000 string/wcschr-fbsd.c mode change 100644 => 120000 string/wcscmp-fbsd.c mode change 100644 => 120000 string/wcscpy-fbsd.c mode change 100644 => 120000 string/wcscspn-fbsd.c mode change 100644 => 120000 string/wcslcat-fbsd.c mode change 100644 => 120000 string/wcslcpy-fbsd.c mode change 100644 => 120000 string/wcslen-fbsd.c mode change 100644 => 120000 string/wcsncat-fbsd.c mode change 100644 => 120000 string/wcsncmp-fbsd.c mode change 100644 => 120000 string/wcsncpy-fbsd.c mode change 100644 => 120000 string/wcspbrk-fbsd.c mode change 100644 => 120000 string/wcsrchr-fbsd.c mode change 100644 => 120000 string/wcsspn-fbsd.c mode change 100644 => 120000 string/wcsstr-fbsd.c mode change 100644 => 120000 string/wcstok-fbsd.c mode change 100644 => 120000 string/wmemchr-fbsd.c mode change 100644 => 120000 string/wmemcmp-fbsd.c mode change 100644 => 120000 string/wmemcpy-fbsd.c mode change 100644 => 120000 string/wmemmove-fbsd.c mode change 100644 => 120000 string/wmemset-fbsd.c create mode 100644 sys/OSMemoryNotification.c create mode 100644 sys/OSThermalNotification.c mode change 100644 => 120000 uuid/clear-uuid.c mode change 100644 => 120000 uuid/compare-uuid.c mode change 100644 => 120000 uuid/copy-uuid.c mode change 100644 => 120000 uuid/isnull-uuid.c mode change 100644 => 120000 uuid/pack-uuid.c mode change 100644 => 120000 uuid/parse-uuid.c mode change 100644 => 120000 uuid/unpack-uuid.c mode change 100644 => 120000 uuid/unparse-uuid.c diff --git a/BSDmakefile b/BSDmakefile index de14ee9..b7e1fde 100644 --- a/BSDmakefile +++ b/BSDmakefile @@ -1,3 +1,4 @@ +ALLARCHS = arm i386 ppc ppc64 x86_64 # installsrc doesn't set RC_ARCHS PWD != pwd .ifdef DSTROOT DESTDIR = $(DSTROOT) @@ -23,10 +24,13 @@ ARCH != arch RC_ARCHS = $(ARCH) RC_$(RC_ARCHS) = 1 .endif +.ifndef RC_NONARCH_CFLAGS +RC_NONARCH_CFLAGS = -pipe +.endif .ifdef ALTUSRLOCALLIBSYSTEM LIBSYS = $(ALTUSRLOCALLIBSYSTEM) .else -LIBSYS = $(NEXT_ROOT)/usr/local/lib/system +LIBSYS = $(SDKROOT)/usr/local/lib/system .endif NJOBS != perl -e '$$n = `/usr/sbin/sysctl -n hw.ncpu`; printf "%d\n", $$n < 2 ? 2 : ($$n * 1.5)' BSDMAKE = bsdmake -f Makefile @@ -41,11 +45,18 @@ BSDMAKEJ = $(BSDMAKE) -j $(NJOBS) dynamic = dynamic static = static -# Remove the arch stuff, since we know better here. -LOCAL_CFLAGS != echo $(RC_CFLAGS) | sed 's/ *-arch [^ ][^ ]*//g' +# Map RC_ARCHS to MACHINE_ARCH +.for A in $(RC_ARCHS) $(ARCH) # { +MACHINE_ARCH-$(A) = $(A:C/^armv.*/arm/) +.endfor # RC_ARCHS } FORMS := dynamic debug profile static +OBJSUFFIX-dynamic = So +OBJSUFFIX-debug = do +OBJSUFFIX-profile = po +OBJSUFFIX-static = o + all: build ROOTS := DSTROOT OBJROOT SYMROOT @@ -107,7 +118,7 @@ FRAMEWORKS = $(OBJROOT)/Frameworks .ifdef ALTFRAMEWORKSPATH FRAMEWORKPATH = ${ALTFRAMEWORKSPATH} .else -FRAMEWORKPATH = ${NEXT_ROOT}/System/Library/Frameworks +FRAMEWORKPATH = ${SDKROOT}/System/Library/Frameworks .endif $(FRAMEWORKS): $(SRCROOT)/patchHeaders $(FRAMEWORKPATH)/$(PRIVATEHEADERPATH) $(FRAMEWORKS)/$(PRIVATEHEADERPATH:H) @@ -128,9 +139,11 @@ PSUFFIX-$(F) = $(PARTIAL)$(SUFFIX-$(F)) ARCHS-$(F) += $(A) build-$(A)-$(F): mkdir -p $(OBJROOT)/obj.$(A) && \ - MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH="$(A)" \ + MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \ DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \ - MAKEFLAGS="" CFLAGS="-arch $(A) $(LOCAL_CFLAGS)" $(BSDMAKEJ) libc$(SUFFIX-$(F)).a + RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" MAKEFLAGS="" \ + OBJSUFFIX="$(OBJSUFFIX-$(F))" \ + $(BSDMAKEJ) libc$(SUFFIX-$(F)).a .else # } { build-$(A)-$(F): @echo Not building libc$(PSUFFIX-$(F)).a for $(A) @@ -160,12 +173,10 @@ build-$(F): # We autopatch the files into the directory containing the Makefile.inc. This # will happen at installsrc. $(AUTOPATCHED): - @set -x && \ - for m in `find $(SRCROOT) -name Makefile.inc`; do \ - cd `dirname $$m` && \ - bsdmake -I $(SRCROOT) -f $(SRCROOT)/Makefile.inc -f Makefile.inc -f $(SRCROOT)/Makefile.autopatch autopatch LIB=c SRCROOT=$(SRCROOT) || \ - exit 1; \ - done +.for A in $(ALLARCHS) # { + MACHINE_ARCH=$(A) SRCROOT="$(SRCROOT)" \ + $(BSDMAKE) -C "$(SRCROOT)" autopatch +.endfor # ALLARCHS # } touch $(AUTOPATCHED) copysrc: @@ -179,9 +190,10 @@ installhdrs-real: $(BSDMAKEJ) installhdrs .for A in $(RC_ARCHS) # { mkdir -p "$(OBJROOT)/obj.$(A)" && \ - MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH="$(A)" \ + MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \ DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \ - MAKEFLAGS="" $(BSDMAKEJ) installhdrs-md + MAKEFLAGS="" RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \ + $(BSDMAKEJ) installhdrs-md .endfor # RC_ARCHS # } .for F in $(FORMS) # { @@ -195,10 +207,11 @@ BI-install-$(F): build-$(F) fi .if $(dynamic) == $(F) # { .for A in $(RC_ARCHS) # { - MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH="$(A)" \ + MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH=$(MACHINE_ARCH-$(A)) CCARCH=$(A) \ DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \ DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \ - MAKEFLAGS="" $(BSDMAKE) copyfiles + MAKEFLAGS="" RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \ + $(BSDMAKE) copyfiles .endfor # RC_ARCHS # } .endif # } .endfor # FORMS } @@ -213,8 +226,9 @@ install-man: mkdir -p $(DSTROOT)/usr/share/man/man7 MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" \ DSTROOT='$(DSTROOT)' OBJROOT='$(OBJROOT)' SYMROOT='$(SYMROOT)' \ - MACHINE_ARCH="$(ARCH)" MAKEFLAGS="" \ - $(BSDMAKE) autopatchman all-man maninstall $(MANARGS) + MACHINE_ARCH="$(MACHINE_ARCH-$(ARCH))" CCARCH=$(ARCH) MAKEFLAGS="" \ + RC_NONARCH_CFLAGS="$(RC_NONARCH_CFLAGS)" \ + $(BSDMAKE) all-man maninstall $(MANARGS) install-all: build install-man .for F in $(FORMS) # { diff --git a/Makefile b/Makefile index 34a4b2d..1cea12a 100644 --- a/Makefile +++ b/Makefile @@ -16,22 +16,48 @@ MACHINE_ARCH != /usr/bin/arch .if !empty $(MACHINE_ARCH:M*64) LP64 = 1 .endif -CC = gcc-4.0 -CFLAGS += -D__LIBC__ -D__DARWIN_UNIX03=1 -D__DARWIN_64_BIT_INO_T=1 -D__DARWIN_NON_CANCELABLE=1 -D__DARWIN_VERS_1050=1 -CFLAGS += -DNOID -I${.CURDIR}/include -std=gnu99 +# RC_TARGET_CONFIG may not be set, so default to MacOSX (which is good enough +# for installsrc to autopatch all files). +.ifndef RC_TARGET_CONFIG +RC_TARGET_CONFIG = MacOSX +.endif + +#use default compiler +#CC = gcc-4.0 +GCC_VERSION != cc -dumpversion | sed -e 's/^\([^.]*\.[^.]*\).*/\1/' +GCC_42 != perl -e "print ($(GCC_VERSION) >= 4.2 ? 'YES' : 'NO')" + .ifdef ALTLIBCHEADERS INCLUDEDIR = ${ALTLIBCHEADERS} LIBCFLAGS += -I${INCLUDEDIR} -.endif -LIBCFLAGS += -I$(SRCROOT)/include -include _.libc_internal.h +.else # !ALTLIBCHEADERS +INCLUDEDIR = ${SDKROOT}/usr/include +.endif # ALTLIBCHEADERS FRAMEWORKS = ${OBJROOT}/Frameworks PRIVATEHEADERS = ${FRAMEWORKS}/System.framework/PrivateHeaders -PRIVINC = -F${FRAMEWORKS} -I${PRIVATEHEADERS} -CFLAGS += ${PRIVINC} -I${.OBJDIR} -CFLAGS += -DLIBC_MAJOR=${SHLIB_MAJOR} -no-cpp-precomp -force_cpusubtype_ALL -CFLAGS += -fno-common -pipe -Wmost -g -D__FBSDID=__RCSID -AINC= -I${.CURDIR}/${MACHINE_ARCH} -no-cpp-precomp -force_cpusubtype_ALL -AINC+=-arch ${MACHINE_ARCH} -g +PRIVINC = -I${PRIVATEHEADERS} +LIBCFLAGS += ${PRIVINC} + +SYMROOTINC = ${SYMROOT}/include +CFLAGS = -g -arch ${CCARCH} ${RC_NONARCH_CFLAGS} -std=gnu99 -fno-common -Wmost +CFLAGS += -D__LIBC__ -D__DARWIN_UNIX03=1 -D__DARWIN_64_BIT_INO_T=1 -D__DARWIN_NON_CANCELABLE=1 -D__DARWIN_VERS_1050=1 +CFLAGS += -DNOID -DLIBC_MAJOR=${SHLIB_MAJOR} +CFLAGS += -I${.OBJDIR} -I${SYMROOTINC} -I${.CURDIR}/include +AINC = -g -arch ${CCARCH} ${RC_NONARCH_CFLAGS} +AINC += -I${.CURDIR}/${MACHINE_ARCH} ${PRIVINC} +.if $(MACHINE_ARCH) != arm +CFLAGS += -force_cpusubtype_ALL +AINC += -force_cpusubtype_ALL +.endif +.ifdef SDKROOT +CFLAGS += -isysroot '${SDKROOT}' +AINC += -isysroot '${SDKROOT}' +.endif # SDKROOT + +.if ${GCC_42} != YES +CFLAGS += -no-cpp-precomp +AINC += -no-cpp-precomp +.endif CLEANFILES+=tags INSTALL_PIC_ARCHIVE= yes PRECIOUSLIB= yes @@ -39,11 +65,6 @@ PRECIOUSLIB= yes # workaround for 3649783 AINC += -fdollars-in-identifiers -# workaround for 4268581 -.if make(lib${LIB}_static.a) -OPTIMIZE-glob-fbsd.c += -O0 -.endif - # If these aren't set give it expected defaults DSTROOT ?= / OBJROOT ?= . @@ -58,10 +79,13 @@ MAKEOBJDIR ?= ${OBJROOT} # add version string SRCS += libc_version.c libc_version.c: - /Developer/Makefiles/bin/version.pl Libc > $@ + ${SDKROOT}/Developer/Makefiles/bin/version.pl Libc > $@ +.include "Makefile.features" .include "${.CURDIR}/Makefile.inc" .include "Makefile.xbs" + +MANFILTER = unifdef -t ${UNIFDEFARGS} .if exists(/usr/share/mk/bsd.init.mk) .include .endif diff --git a/Makefile.autopatch b/Makefile.autopatch deleted file mode 100644 index 2d62585..0000000 --- a/Makefile.autopatch +++ /dev/null @@ -1,6 +0,0 @@ -autopatch: $(AUTOPATCHHDRS) $(AUTOPATCHSRCS) $(AUTOPATCHMAN) - -.SUFFIXES: .3-uuid.in .3 - -.3-uuid.in.3: - sed -f ${SRCROOT}/uuid/uuidman.sed ${.IMPSRC} > ${.TARGET} diff --git a/Makefile.fbsd_end b/Makefile.fbsd_end index 0a279b7..6275b05 100644 --- a/Makefile.fbsd_end +++ b/Makefile.fbsd_end @@ -12,10 +12,13 @@ FBSDSECTIONS= 1 2 3 4 5 6 7 8 9 +# This .for statement forces evaluation of ${_cwd} +.for _cwd in ${CWD} + .for _src in ${FBSDSRCS} .ifmake autopatch -${_src:R}-fbsd.${_src:E}: FreeBSD/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-fbsd.${_src:E} +${_cwd}/${_src:R}-fbsd.${_src:E}: ${_cwd}/FreeBSD/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-fbsd.${_src:E} .else # !autopatch SRCS+= ${_src} .endif # autopatch @@ -23,8 +26,8 @@ SRCS+= ${_src} .for _src in ${FBSDMDSRCS} .ifmake autopatch -${_src:R}-fbsd.${_src:E}: FreeBSD/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-fbsd.${_src:E} +${_cwd}/${_src:R}-fbsd.${_src:E}: ${_cwd}/FreeBSD/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-fbsd.${_src:E} .else # !autopatch MDSRCS+= ${_src} .endif # autopatch @@ -32,8 +35,8 @@ MDSRCS+= ${_src} .for _src in ${FBSDMISRCS} .ifmake autopatch -${_src:R}-fbsd.${_src:E}: FreeBSD/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-fbsd.${_src:E} +${_cwd}/${_src:R}-fbsd.${_src:E}: ${_cwd}/FreeBSD/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-fbsd.${_src:E} .else # !autopatch MISRCS+= ${_src} .endif # autopatch @@ -43,25 +46,27 @@ MISRCS+= ${_src} # in base variant (only in other variants) .ifmake autopatch .for _src in ${FBSDPATCHSRCS} -${_src:R}-fbsd.${_src:E}: FreeBSD/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-fbsd.${_src:E} +${_cwd}/${_src:R}-fbsd.${_src:E}: ${_cwd}/FreeBSD/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-fbsd.${_src:E} .endfor .endif # autopatch .ifmake autopatch .for _src in ${FBSDHDRS} -${_src}: FreeBSD/${_src} _AUTOPATCHCUR -AUTOPATCHHDRS+= ${_src} +${_cwd}/${_src}: ${_cwd}/FreeBSD/${_src} _AUTOPATCH +AUTOPATCHHDRS+= ${_cwd}/${_src} .endfor .endif # autopatch .for _sect in ${FBSDSECTIONS} .for _src in ${FBSDMAN${_sect}} .ifmake autopatch -${_src}: FreeBSD/${_src} _AUTOPATCH -AUTOPATCHMAN+= ${_src} +${_cwd}/${_src}: ${_cwd}/FreeBSD/${_src} _AUTOPATCH +AUTOPATCHMAN+= ${_cwd}/${_src} .else # !autopatch MAN${_sect}+= ${_src} .endif # autopatch .endfor .endfor + +.endfor # _cwd diff --git a/Makefile.features b/Makefile.features new file mode 100644 index 0000000..19c7d29 --- /dev/null +++ b/Makefile.features @@ -0,0 +1,112 @@ +.include "Platforms/${RC_TARGET_CONFIG}/Makefile.inc" + +${SYMROOTINC}/${MACHINE_ARCH}/libc-features.h: + mkdir -p ${.TARGET:H} + echo creating ${.TARGET} + @echo '#ifndef _LIBC_FEATURES_H_' > ${.TARGET} + @echo '#define _LIBC_FEATURES_H_' >> ${.TARGET} + @echo >> ${.TARGET} +.ifdef FEATURE_LEGACY_RUNE_APIS + @echo '#define LEGACY_RUNE_APIS 1' >> ${.TARGET} +.else + @echo '/* #undef LEGACY_RUNE_APIS */' >> ${.TARGET} +.endif +.ifdef FEATURE_LEGACY_UTMP_APIS + @echo '#define LEGACY_UTMP_APIS 1' >> ${.TARGET} +.else + @echo '/* #undef LEGACY_UTMP_APIS */' >> ${.TARGET} +.endif +.ifdef FEATURE_MOVE_LOCALTIME + @echo '#define UNIFDEF_MOVE_LOCALTIME 1' >> ${.TARGET} +.else + @echo '/* #undef UNIFDEF_MOVE_LOCALTIME */' >> ${.TARGET} +.endif +.ifdef FEATURE_ONLY_LONG_DOUBLE_IS_DOUBLE + @echo '#if !__DARWIN_LONG_DOUBLE_IS_DOUBLE' >> ${.TARGET} + @echo '# error Feature mismatch: __DARWIN_LONG_DOUBLE_IS_DOUBLE == 0' >> ${.TARGET} + @echo '#endif /* !__DARWIN_LONG_DOUBLE_IS_DOUBLE */' >> ${.TARGET} + @echo '#define LDBL_COMPAT 1' >> ${.TARGET} +.else + @echo '#if __DARWIN_LONG_DOUBLE_IS_DOUBLE' >> ${.TARGET} + @echo '# if !defined(LDBL_COMPAT)' >> ${.TARGET} + @echo '# error Feature mismatch: __DARWIN_LONG_DOUBLE_IS_DOUBLE == 1' >> ${.TARGET} + @echo '# endif /* !LDBL_COMPAT */' >> ${.TARGET} + @echo '#elif defined(LDBL_COMPAT)' >> ${.TARGET} + @echo '# error Feature mismatch: __DARWIN_LONG_DOUBLE_IS_DOUBLE == 0' >> ${.TARGET} + @echo '#endif /* LDBL_COMPAT */' >> ${.TARGET} +.endif +.ifdef FEATURE_ONLY_1050_VARIANTS + @echo '#if !__DARWIN_ONLY_VERS_1050' >> ${.TARGET} + @echo '# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 0' >> ${.TARGET} + @echo '#endif /* !__DARWIN_ONLY_VERS_1050 */' >> ${.TARGET} +.else + @echo '#if __DARWIN_ONLY_VERS_1050' >> ${.TARGET} + @echo '# error Feature mismatch: __DARWIN_ONLY_VERS_1050 == 1' >> ${.TARGET} + @echo '#endif /* __DARWIN_ONLY_VERS_1050 */' >> ${.TARGET} +.endif +.ifdef FEATURE_ONLY_UNIX_CONFORMANCE + @echo '#if !__DARWIN_ONLY_UNIX_CONFORMANCE' >> ${.TARGET} + @echo '# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 0' >> ${.TARGET} + @echo '#endif /* !__DARWIN_ONLY_UNIX_CONFORMANCE */' >> ${.TARGET} +.else + @echo '#if __DARWIN_ONLY_UNIX_CONFORMANCE' >> ${.TARGET} + @echo '# error Feature mismatch: __DARWIN_ONLY_UNIX_CONFORMANCE == 1' >> ${.TARGET} + @echo '#endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */' >> ${.TARGET} +.endif +.ifdef FEATURE_ONLY_64_BIT_INO_T + @echo '#if !__DARWIN_ONLY_64_BIT_INO_T' >> ${.TARGET} + @echo '# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 0' >> ${.TARGET} + @echo '#endif /* !__DARWIN_ONLY_64_BIT_INO_T */' >> ${.TARGET} +.else + @echo '#if __DARWIN_ONLY_64_BIT_INO_T' >> ${.TARGET} + @echo '# error Feature mismatch: __DARWIN_ONLY_64_BIT_INO_T == 1' >> ${.TARGET} + @echo '#endif /* __DARWIN_ONLY_64_BIT_INO_T */' >> ${.TARGET} +.endif +.ifdef FEATURE_PATCH_3375657 + @echo '#define __APPLE_PR3375657_HACK__ 1' >> ${.TARGET} +.else + @echo '/* #undef __APPLE_PR3375657_HACK__ */' >> ${.TARGET} +.endif +.ifdef FEATURE_PATCH_3417676 + @echo '#define __APPLE_PR3417676_HACK__ 1' >> ${.TARGET} +.else + @echo '/* #undef __APPLE_PR3417676_HACK__ */' >> ${.TARGET} +.endif +.ifdef FEATURE_PATCH_5243343 + @echo '#define PR_5243343 1' >> ${.TARGET} +.else + @echo '/* #undef PR_5243343 */' >> ${.TARGET} +.endif +.ifdef FEATURE_PLOCKSTAT + @echo '#define PLOCKSTAT 1' >> ${.TARGET} +.else + @echo '/* #undef PLOCKSTAT */' >> ${.TARGET} +.endif +.ifdef FEATURE_TIMEZONE_CHANGE_NOTIFICATION + @echo '#define NOTIFY_TZ 1' >> ${.TARGET} +.else + @echo '/* #undef NOTIFY_TZ */' >> ${.TARGET} +.endif + @echo >> ${.TARGET} + @echo '#endif /* _LIBC_FEATURES_H_ */' >> ${.TARGET} + +.ifdef FEATURE_LEGACY_64_APIS +UNIFDEFARGS += -DUNIFDEF_LEGACY_64_APIS +.else +UNIFDEFARGS += -UUNIFDEF_LEGACY_64_APIS +.endif +.ifdef FEATURE_LEGACY_RUNE_APIS +UNIFDEFARGS += -DUNIFDEF_LEGACY_RUNE_APIS +.else +UNIFDEFARGS += -UUNIFDEF_LEGACY_RUNE_APIS +.endif +.ifdef FEATURE_LEGACY_UTMP_APIS +UNIFDEFARGS += -DUNIFDEF_LEGACY_UTMP_APIS +.else +UNIFDEFARGS += -UUNIFDEF_LEGACY_UTMP_APIS +.endif +.ifdef FEATURE_MOVE_LOCALTIME +UNIFDEFARGS += -DUNIFDEF_MOVE_LOCALTIME +.else +UNIFDEFARGS += -UUNIFDEF_MOVE_LOCALTIME +.endif diff --git a/Makefile.inc b/Makefile.inc index ab0eca2..30656c6 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -20,7 +20,7 @@ AUTOPATCHHDRS= AUTOPATCHMAN= AUTOPATCHSRCS= -# Auto-patch into OBJROOT +# Auto-patch (or symlink) _AUTOPATCH: .USE @if [ -f ${.ALLSRC}.patch ]; then \ echo cp ${.ALLSRC} ${.TARGET}; \ @@ -28,16 +28,9 @@ _AUTOPATCH: .USE echo patch ${.TARGET} ${.ALLSRC}.patch; \ patch ${.TARGET} ${.ALLSRC}.patch; \ else \ - echo ln -s ${.ALLSRC} ${.TARGET}; \ - ln -s ${.ALLSRC} ${.TARGET}; \ - fi -# Auto-patch into current directory -_AUTOPATCHCUR: .USE - @echo cp ${.ALLSRC} ${.TARGET}; \ - cp ${.ALLSRC} ${.TARGET}; \ - if [ -f ${.ALLSRC}.patch ]; then \ - echo patch ${.TARGET} ${.ALLSRC}.patch; \ - patch ${.TARGET} ${.ALLSRC}.patch; \ + t=`basename ${.ALLSRC}` && x=`dirname ${.ALLSRC}` && d=`basename $$x`; \ + echo ln -fs $$d/$$t ${.TARGET}; \ + ln -fs $$d/$$t ${.TARGET}; \ fi # Standard compilation for the various forms _STANDARD_STATIC: .USE @@ -65,27 +58,10 @@ _STANDARD_DEBUG: .USE ${VARIANTCFLAGS} ${LIBCFLAGS} \ -c ${.IMPSRC} -o ${.TARGET} -# set object file suffix -.if make(lib${LIB}_static.a) -OBJSUFFIX = o -.endif -.if make(lib${LIB}_profile.a) -OBJSUFFIX = po -.endif -.if make(lib${LIB}_debug.a) -OBJSUFFIX = do -.endif -.if make(lib${LIB}.a) -OBJSUFFIX = So -.endif - -.ifnmake autopatch # # If there is a machine dependent makefile, use it: # -.if exists(${.CURDIR}/${MACHINE_ARCH}/Makefile.inc) -.include "${.CURDIR}/${MACHINE_ARCH}/Makefile.inc" -.endif +.sinclude "${.CURDIR}/${MACHINE_ARCH}/Makefile.inc" .include "${.CURDIR}/darwin/Makefile.inc" .include "${.CURDIR}/db/Makefile.inc" @@ -95,7 +71,9 @@ OBJSUFFIX = So .include "${.CURDIR}/gen/Makefile.inc" .include "${.CURDIR}/gmon/Makefile.inc" .include "${.CURDIR}/include/Makefile.inc" +.ifdef FEATURE_LEGACY_NX_INTERNAT_APIS .include "${.CURDIR}/internat/Makefile.inc" +.endif .include "${.CURDIR}/locale/Makefile.inc" .include "${.CURDIR}/man/Makefile.inc" .include "${.CURDIR}/net/Makefile.inc" @@ -128,4 +106,3 @@ SRCS+= ${_src} .endif .endfor .endif -.endif # !autopatch diff --git a/Makefile.nbsd_end b/Makefile.nbsd_end index c988964..63a8a85 100644 --- a/Makefile.nbsd_end +++ b/Makefile.nbsd_end @@ -12,10 +12,13 @@ NBSDSECTIONS= 1 2 3 4 5 6 7 8 9 +# This .for statement forces evaluation of ${CWD} +.for _cwd in ${CWD} + .for _src in ${NBSDSRCS} .ifmake autopatch -${_src:R}-nbsd.${_src:E}: NetBSD/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-nbsd.${_src:E} +${_cwd}/${_src:R}-nbsd.${_src:E}: ${_cwd}/NetBSD/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-nbsd.${_src:E} .else # !autopatch SRCS+= ${_src} .endif # autopatch @@ -23,8 +26,8 @@ SRCS+= ${_src} .for _src in ${NBSDMDSRCS} .ifmake autopatch -${_src:R}-nbsd.${_src:E}: NetBSD/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-nbsd.${_src:E} +${_cwd}/${_src:R}-nbsd.${_src:E}: ${_cwd}/NetBSD/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-nbsd.${_src:E} .else # !autopatch MDSRCS+= ${_src} .endif # autopatch @@ -32,8 +35,8 @@ MDSRCS+= ${_src} .for _src in ${NBSDMISRCS} .ifmake autopatch -${_src:R}-nbsd.${_src:E}: NetBSD/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-nbsd.${_src:E} +${_cwd}/${_src:R}-nbsd.${_src:E}: ${_cwd}/NetBSD/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-nbsd.${_src:E} .else # !autopatch MISRCS+= ${_src} .endif # autopatch @@ -41,18 +44,20 @@ MISRCS+= ${_src} .ifmake autopatch .for _src in ${NBSDHDRS} -${_src}: NetBSD/${_src} _AUTOPATCHCUR -AUTOPATCHHDRS+= ${_src} +${_cwd}/${_src}: ${_cwd}/NetBSD/${_src} _AUTOPATCH +AUTOPATCHHDRS+= ${_cwd}/${_src} .endfor .endif # autopatch .for _sect in ${NBSDSECTIONS} .for _src in ${NBSDMAN${_sect}} .ifmake autopatch -${_src}: NetBSD/${_src} _AUTOPATCH -AUTOPATCHMAN+= ${_src} +${_cwd}/${_src}: ${_cwd}/NetBSD/${_src} _AUTOPATCH +AUTOPATCHMAN+= ${_cwd}/${_src} .else # !autopatch MAN${_sect}+= ${_src} .endif # autopatch .endfor .endfor + +.endfor # _cwd diff --git a/Makefile.obsd_end b/Makefile.obsd_end index 801a018..9b3ef1a 100644 --- a/Makefile.obsd_end +++ b/Makefile.obsd_end @@ -12,10 +12,13 @@ OBSDSECTIONS= 1 2 3 4 5 6 7 8 9 +# This .for statement forces evaluation of ${CWD} +.for _cwd in ${CWD} + .for _src in ${OBSDSRCS} .ifmake autopatch -${_src:R}-obsd.${_src:E}: OpenBSD/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-obsd.${_src:E} +${_cwd}/${_src:R}-obsd.${_src:E}: ${_cwd}/OpenBSD/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-obsd.${_src:E} .else # !autopatch SRCS+= ${_src} .endif # autopatch @@ -23,8 +26,8 @@ SRCS+= ${_src} .for _src in ${OBSDMDSRCS} .ifmake autopatch -${_src:R}-obsd.${_src:E}: OpenBSD/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-obsd.${_src:E} +${_cwd}/${_src:R}-obsd.${_src:E}: ${_cwd}/OpenBSD/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-obsd.${_src:E} .else # !autopatch MDSRCS+= ${_src} .endif # autopatch @@ -32,8 +35,8 @@ MDSRCS+= ${_src} .for _src in ${OBSDMISRCS} .ifmake autopatch -${_src:R}-obsd.${_src:E}: OpenBSD/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-obsd.${_src:E} +${_cwd}/${_src:R}-obsd.${_src:E}: ${_cwd}/OpenBSD/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-obsd.${_src:E} .else # !autopatch MISRCS+= ${_src} .endif # autopatch @@ -41,18 +44,20 @@ MISRCS+= ${_src} .ifmake autopatch .for _src in ${OBSDHDRS} -${_src}: OpenBSD/${_src} _AUTOPATCHCUR -AUTOPATCHHDRS+= ${_src} +${_cwd}/${_src}: ${_cwd}/OpenBSD/${_src} _AUTOPATCH +AUTOPATCHHDRS+= ${_cwd}/${_src} .endfor .endif # autopatch .for _sect in ${OBSDSECTIONS} .for _src in ${OBSDMAN${_sect}} .ifmake autopatch -${_src}: OpenBSD/${_src} _AUTOPATCH -AUTOPATCHMAN+= ${_src} +${_cwd}/${_src}: ${_cwd}/OpenBSD/${_src} _AUTOPATCH +AUTOPATCHMAN+= ${_cwd}/${_src} .else # !autopatch MAN${_sect}+= ${_src} .endif # autopatch .endfor .endfor + +.endfor # _cwd diff --git a/Makefile.xbs b/Makefile.xbs index b19c831..4596710 100644 --- a/Makefile.xbs +++ b/Makefile.xbs @@ -24,9 +24,9 @@ BSDMAKE = bsdmake -f Makefile .PATH: . .MAIN: all all: libc.a libc_static.a libc_debug.a libc_profile.a -install: installhdrs install_libc.a install_libc_static.a \ +install: ${SYMROOTINC}/${MACHINE_ARCH}/libc-features.h installhdrs install_libc.a \ install_libc_profile.a install_libc_debug.a \ - autopatchman maninstall + maninstall .SUFFIXES: .SUFFIXES: .o .po .So .do @@ -35,6 +35,7 @@ install: installhdrs install_libc.a install_libc_static.a \ .SUFFIXES: .f .y .l .defs .h .SUFFIXES: User.c User.o User.po User.So User.do .SUFFIXES: Server.c Server.o Server.po Server.So Server.do +.SUFFIXES: .3-uuid.in .3 OBJS+= ${SRCS:N*.h:R:S/$/.o/g} DOBJS+= ${OBJS:.o=.do} @@ -57,16 +58,22 @@ SOBJS+= ${OBJS:.o=.So} # specify sources that will build with both the CFLAGS_XXX and CFLAGS_YYY # flags set. The variants are always in alphabetic order. # -VARIANTS= DARWINEXTSN INODE32 CANCELABLE PRE1050 +VARIANTS = DARWINEXTSN CANCELABLE + +.ifndef FEATURE_ONLY_64_BIT_INO_T +VARIANTS += INODE32 +.endif +.ifndef FEATURE_ONLY_1050_VARIANTS +VARIANTS += PRE1050 +.endif +.ifndef FEATURE_ONLY_UNIX_CONFORMANCE +VARIANTS+= LEGACY +.endif # Append the 64-bit long double sources (ppc only) .if (${MACHINE_ARCH} == ppc) -VARIANTS+= LDBL +VARIANTS += LDBL MDSRCS += ldbl64.s .endif -# build LEGACY variant except on LP64 -.ifndef LP64 -VARIANTS+= LEGACY -.endif CFLAGS_LEGACY= -U__DARWIN_UNIX03 -D__DARWIN_UNIX03=0 -U__DARWIN_64_BIT_INO_T -D__DARWIN_64_BIT_INO_T=0 -DVARIANT_LEGACY CFLAGS_LDBL= -mlong-double-64 -DLDBL_COMPAT @@ -155,7 +162,7 @@ FBSDFLAGS= -include _fbsd_compat_.h ${VARIANTCFLAGS} ${FBSDFLAGS} ${LIBCFLAGS} \ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET} -fbsd.c.do: - ${CC} -g -DDEBUG \ + ${CC} -DDEBUG \ ${PREFBSDFLAGS} ${PRECFLAGS} ${PRECFLAGS-${.IMPSRC:T}} \ ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \ ${VARIANTCFLAGS} ${FBSDFLAGS} ${LIBCFLAGS} \ @@ -184,7 +191,7 @@ NBSDFLAGS= -include _nbsd_compat_.h ${VARIANTCFLAGS} ${NBSDFLAGS} ${LIBCFLAGS} \ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET} -nbsd.c.do: - ${CC} -g -DDEBUG \ + ${CC} -DDEBUG \ ${PRENBSDFLAGS} ${PRECFLAGS} ${PRECFLAGS-${.IMPSRC:T}} \ ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \ ${VARIANTCFLAGS} ${NBSDFLAGS} ${LIBCFLAGS} \ @@ -213,7 +220,7 @@ OBSDFLAGS= ${VARIANTCFLAGS} ${OBSDFLAGS} ${LIBCFLAGS} \ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET} -obsd.c.do: - ${CC} -g -DDEBUG \ + ${CC} -DDEBUG \ ${PREOBSDFLAGS} ${PRECFLAGS} ${PRECFLAGS-${.IMPSRC:T}} \ ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \ ${VARIANTCFLAGS} ${OBSDFLAGS} ${LIBCFLAGS} \ @@ -242,11 +249,13 @@ UUIDFLAGS= -include uuid-config.h ${VARIANTCFLAGS} ${UUIDFLAGS} ${LIBCFLAGS} \ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET} -uuid.c.do: - ${CC} -g -DDEBUG \ + ${CC} -DDEBUG \ ${PREUUIDFLAGS} ${PRECFLAGS} ${PRECFLAGS-${.IMPSRC:T}} \ ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \ ${VARIANTCFLAGS} ${UUIDFLAGS} ${LIBCFLAGS} \ -c ${.IMPSRC} -o ${.TARGET} +.3-uuid.in.3: + sed -f ${SRCROOT}/uuid/uuidman.sed ${.IMPSRC} > ${.TARGET} #### Standard C Rules ################################################# # If you change any of these standard rule, make corresponding changes @@ -271,7 +280,7 @@ UUIDFLAGS= -include uuid-config.h ${VARIANTCFLAGS} ${LIBCFLAGS} \ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET} .c.do User.cUser.do Server.cServer.do: - ${CC} -g -DDEBUG \ + ${CC} -DDEBUG \ ${PRECFLAGS} ${PRECFLAGS-${.IMPSRC:T}} \ ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \ ${VARIANTCFLAGS} ${LIBCFLAGS} \ @@ -294,38 +303,38 @@ UUIDFLAGS= -include uuid-config.h ${CFLAGS:M-[BIDFU]*} ${CFLAGS-${.IMPSRC:T}:M-[BIDFU]*} ${AINC} \ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET} .s.do .S.do: - ${CC} -g -x assembler-with-cpp -DDEBUG \ + ${CC} -x assembler-with-cpp -DDEBUG \ ${PRECFLAGS:M-[BIDFU]*} ${PRECFLAGS-${.IMPSRC:T}:M-[BIDFU]*} \ ${CFLAGS:M-[BIDFU]*} ${CFLAGS-${.IMPSRC:T}:M-[BIDFU]*} ${AINC} \ -c ${.IMPSRC} -o ${.TARGET} #### mig Rules ######################################################## .defs.h .defsUser.c .defsServer.c: - mig -arch ${MACHINE_ARCH} -cc ${CC} -user ${.PREFIX}User.c -server ${.PREFIX}Server.c -header ${.PREFIX}.h ${.IMPSRC} + mig -arch ${CCARCH} -cc ${CC} -user ${.PREFIX}User.c -server ${.PREFIX}Server.c -header ${.PREFIX}.h ${.IMPSRC} gen_mig_defs: ${SRVMIGHDRS} ${MIGHDRS} gen_md_mig_defs: ${MD_MIGHDRS} #### Library Rules #################################################### -lib${LIB}_static.a:: ${VARIANTCOMBOS} ${OBJS} ${STATICOBJS} +lib${LIB}_static.a:: ${SYMROOTINC}/${MACHINE_ARCH}/libc-features.h ${VARIANTCOMBOS} ${OBJS} ${STATICOBJS} @${ECHO} building static ${LIB} library @rm -f lib${LIB}_static.a @${AR} cq lib${LIB}_static.a `lorder ${OBJS} ${STATICOBJS} ${VARIANTOBJS} | tsort -q` ${ARADD} ${RANLIB} lib${LIB}_static.a -lib${LIB}_profile.a:: ${VARIANTCOMBOS:S/$/_P/g} ${POBJS} ${POBJS2} +lib${LIB}_profile.a:: ${SYMROOTINC}/${MACHINE_ARCH}/libc-features.h ${VARIANTCOMBOS:S/$/_P/g} ${POBJS} ${POBJS2} @${ECHO} building profiled ${LIB} library @rm -f lib${LIB}_profile.a @${AR} cq lib${LIB}_profile.a `lorder ${POBJS} ${VARIANTPOBJS} | tsort -q` ${ARADD} ${RANLIB} lib${LIB}_profile.a -lib${LIB}_debug.a:: ${VARIANTCOMBOS:S/$/_D/g} ${DOBJS} ${DOBJS2} +lib${LIB}_debug.a:: ${SYMROOTINC}/${MACHINE_ARCH}/libc-features.h ${VARIANTCOMBOS:S/$/_D/g} ${DOBJS} ${DOBJS2} @${ECHO} building debug ${LIB} library @rm -f lib${LIB}_debug.a @${AR} cq lib${LIB}_debug.a `lorder ${DOBJS} ${VARIANTDOBJS} | tsort -q` ${ARADD} ${RANLIB} lib${LIB}_debug.a -lib${LIB}.a:: ${VARIANTCOMBOS:S/$/_S/g} ${SOBJS} ${SOBJS2} +lib${LIB}.a:: ${SYMROOTINC}/${MACHINE_ARCH}/libc-features.h ${VARIANTCOMBOS:S/$/_S/g} ${SOBJS} ${SOBJS2} @${ECHO} building standard ${LIB} library @rm -f lib${LIB}.a @${AR} cq lib${LIB}.a `lorder ${SOBJS} ${VARIANTSOBJS} | tsort -q` ${ARADD} @@ -343,12 +352,16 @@ INSTALLMODE != test `id -u` -eq 0 && echo 444 || echo 644 installhdrs-md: gen_md_mig_defs -installhdrs: gen_mig_defs +installhdrs: modifyhdrs + +copyhdrs: gen_mig_defs mkdir -p ${INCDIR}/arpa mkdir -p ${INCDIR}/libkern mkdir -p ${INCDIR}/machine mkdir -p ${INCDIR}/malloc +.ifdef OBJC_INSTHDRS mkdir -p ${INCDIR}/objc +.endif mkdir -p ${INCDIR}/protocols mkdir -p ${INCDIR}/secure mkdir -p ${INCDIR}/sys @@ -358,7 +371,9 @@ installhdrs: gen_mig_defs ${INSTALL} -c -m ${INSTALLMODE} ${LIBKERN_INSTHDRS} ${INCDIR}/libkern ${INSTALL} -c -m ${INSTALLMODE} ${MACHINE_INSTHDRS} ${INCDIR}/machine ${INSTALL} -c -m ${INSTALLMODE} ${MALLOC_INSTHDRS} ${INCDIR}/malloc +.ifdef OBJC_INSTHDRS ${INSTALL} -c -m ${INSTALLMODE} ${OBJC_INSTHDRS} ${INCDIR}/objc +.endif ${INSTALL} -c -m ${INSTALLMODE} ${PROTO_INSTHDRS} ${INCDIR}/protocols ${INSTALL} -c -m ${INSTALLMODE} ${SECURE_INSTHDRS} ${INCDIR}/secure ${INSTALL} -c -m ${INSTALLMODE} ${SYS_INSTHDRS} ${INCDIR}/sys @@ -378,14 +393,22 @@ installhdrs: gen_mig_defs ${INSTALL} -c -m ${INSTALLMODE} ${SYS_INSTHDRS} ${PRIVHDRS}/sys ${INSTALL} -c -m ${INSTALLMODE} ${PRIVUUID_INSTHDRS} ${PRIVHDRS}/uuid ${INSTALL} -c -m ${INSTALLMODE} ${PRIVUUID_INSTHDRS} ${PRIVKERNELHDRS}/uuid -.for _h in ${STRIP_HDRS} - chmod u+w ${INCDIR}/${_h} - ed - ${INCDIR}/${_h} < ${.CURDIR}/strip-header.ed - chmod u-w ${INCDIR}/${_h} -.endfor - ${INSTALL} -c -m 644 /usr/include/AvailabilityMacros.h ${OBJROOT}/available.h - ex - ${OBJROOT}/available.h < ${.CURDIR}/available.ex - ${INSTALL} -c -m ${INSTALLMODE} ${OBJROOT}/available.h ${INCDIR} + +modifyhdrs: copyhdrs + @for i in `find '${DESTDIR}' -name \*.h -print0 | xargs -0 grep -l '^//Begin-Libc'`; do \ + chmod u+w $$i && \ + echo ed - $$i \< ${.CURDIR}/strip-header.ed && \ + ed - $$i < ${.CURDIR}/strip-header.ed && \ + chmod u-w $$i || exit 1; \ + done + @for i in `find '${DESTDIR}' -name \*.h -print0 | xargs -0 fgrep -l UNIFDEF`; do \ + chmod u+w $$i && \ + cp $$i $$i.orig && \ + echo unifdef ${UNIFDEFARGS} $$i.orig \> $$i && \ + { unifdef ${UNIFDEFARGS} $$i.orig > $$i || [ $$? -ne 2 ]; } && \ + rm -f $$i.orig && \ + chmod u-w $$i || exit 1; \ + done install_lib${LIB}_static.a: ${INSTALL} -c -m ${INSTALLMODE} lib${LIB}_static.a ${DESTDIR}/usr/local/lib/system/ @@ -396,7 +419,7 @@ install_lib${LIB}_debug.a: install_lib${LIB}.a: ${INSTALL} -c -m ${INSTALLMODE} lib${LIB}.a ${DESTDIR}/usr/local/lib/system/ -autopatchman: ${AUTOPATCHMAN} +autopatch: ${AUTOPATCHHDRS} ${AUTOPATCHSRCS} ${AUTOPATCHMAN} copyfiles: .if !empty $(COPYFILES) diff --git a/Platforms/AppleTV/Makefile.inc b/Platforms/AppleTV/Makefile.inc new file mode 100644 index 0000000..1b391d9 --- /dev/null +++ b/Platforms/AppleTV/Makefile.inc @@ -0,0 +1,56 @@ +# +# Selectable features for iPhone +# + +# Legacy *64 APIs +#FEATURE_LEGACY_64_APIS = 1 + +# Legacy NX international APIs +FEATURE_LEGACY_NX_INTERNAT_APIS = 1 + +# Legacy NXZone APIs +FEATURE_LEGACY_NXZONE_APIS = 1 + +# Legacy rune APIs +#FEATURE_LEGACY_RUNE_APIS = 1 + +# Legacy utmp APIs +#FEATURE_LEGACY_UTMP_APIS = 1 + +# New OSMemoryNotification and OSThermalNotification APIs +FEATURE_MEM_THERM_NOTIFICATION_APIS = 1 + +# Move localtime to /var/db/timezone +FEATURE_MOVE_LOCALTIME = 1 + +# Long doubles are doubles (should match sys/cdefs.h) +.if (${MACHINE_ARCH} == arm) +FEATURE_ONLY_LONG_DOUBLE_IS_DOUBLE = 1 +.endif + +# No pre-1050 variants (should match sys/cdefs.h) +FEATURE_ONLY_1050_VARIANTS = 1 + +# No legacy variants (should match sys/cdefs.h) +FEATURE_ONLY_UNIX_CONFORMANCE = 1 + +# Only 64-bit ino_t (should match sys/cdefs.h) +FEATURE_ONLY_64_BIT_INO_T = 1 + +# Patch 3333969 +#FEATURE_PATCH_3333969 = 1 + +# Patch 3375657 +#FEATURE_PATCH_3375657 = 1 + +# Patch 3417676 +#FEATURE_PATCH_3417676 = 1 + +# Patch 5243343 +FEATURE_PATCH_5243343 = 1 + +# plockstat dtrace support +#FEATURE_PLOCKSTAT = 1 + +# Timezone change notification +#FEATURE_TIMEZONE_CHANGE_NOTIFICATION = 1 diff --git a/Platforms/AppleTV/i386/libc.syscall.i386 b/Platforms/AppleTV/i386/libc.syscall.i386 new file mode 100644 index 0000000..50ba3d4 --- /dev/null +++ b/Platforms/AppleTV/i386/libc.syscall.i386 @@ -0,0 +1,46 @@ +_accept$NOCANCEL ___accept_nocancel +_aio_suspend$NOCANCEL ___aio_suspend_nocancel +_close$NOCANCEL ___close_nocancel +_connect$NOCANCEL ___connect_nocancel +_fcntl$NOCANCEL ___fcntl_nocancel +_fstat ___fstat64 +_fstat64 +_fstatfs ___fstatfs64 +_fstatfs64 +_fstatx_np ___fstatx64_np +_fstatx64_np +_fsync$NOCANCEL ___fsync_nocancel +_getfsstat ___getfsstat64 +_getfsstat64 +_getmntinfo ___getmntinfo64 +_getmntinfo64 +_lstat ___lstat64 +_lstat64 +_lstatx_np ___lstatx64_np +_lstatx64_np +_msgrcv$NOCANCEL ___msgrcv_nocancel +_msgsnd$NOCANCEL ___msgsnd_nocancel +_msync$NOCANCEL ___msync_nocancel +_open$NOCANCEL ___open_nocancel +_poll$NOCANCEL ___poll_nocancel +_pread$NOCANCEL ___pread_nocancel +_pwrite$NOCANCEL ___pwrite_nocancel +_read$NOCANCEL ___read_nocancel +_readv$NOCANCEL ___readv_nocancel +_recvfrom$NOCANCEL ___recvfrom_nocancel +_recvmsg$NOCANCEL ___recvmsg_nocancel +_select$DARWIN_EXTSN ___select +_select$DARWIN_EXTSN$NOCANCEL ___select_nocancel +_sem_wait$NOCANCEL ___sem_wait_nocancel +_sendmsg$NOCANCEL ___sendmsg_nocancel +_sendto$NOCANCEL ___sendto_nocancel +_sendto$NOCANCEL ___sendto_nocancel +_stat ___stat64 +_stat64 +_statfs ___statfs64 +_statfs64 +_statx_np ___statx64_np +_statx64_np +_waitid$NOCANCEL ___waitid_nocancel +_write$NOCANCEL ___write_nocancel +_writev$NOCANCEL ___writev_nocancel diff --git a/Platforms/MacOSX/Makefile.inc b/Platforms/MacOSX/Makefile.inc new file mode 100644 index 0000000..0932fb4 --- /dev/null +++ b/Platforms/MacOSX/Makefile.inc @@ -0,0 +1,58 @@ +# +# Selectable features for MacOSX +# + +# Legacy *64 APIs +FEATURE_LEGACY_64_APIS = 1 + +# Legacy NX international APIs +FEATURE_LEGACY_NX_INTERNAT_APIS = 1 + +# Legacy NXZone APIs +FEATURE_LEGACY_NXZONE_APIS = 1 + +# Legacy rune APIs +FEATURE_LEGACY_RUNE_APIS = 1 + +# Legacy utmp APIs +FEATURE_LEGACY_UTMP_APIS = 1 + +# New OSMemoryNotification and OSThermalNotification APIs +#FEATURE_MEM_THERM_NOTIFICATION_APIS = 1 + +# Move localtime to /var/db/timezone +#FEATURE_MOVE_LOCALTIME = 1 + +# Long doubles are doubles (should match sys/cdefs.h) +.if (${MACHINE_ARCH} == arm) +FEATURE_ONLY_LONG_DOUBLE_IS_DOUBLE = 1 +.endif + +# No pre-1050 variants (should match sys/cdefs.h) +#FEATURE_ONLY_1050_VARIANTS = 1 + +# No legacy variants (should match sys/cdefs.h) +.if defined(LP64) +FEATURE_ONLY_UNIX_CONFORMANCE = 1 +.endif + +# Only 64-bit ino_t (should match sys/cdefs.h) +#FEATURE_ONLY_64_BIT_INO_T = 1 + +# Patch 3333969 +FEATURE_PATCH_3333969 = 1 + +# Patch 3375657 +FEATURE_PATCH_3375657 = 1 + +# Patch 3417676 +FEATURE_PATCH_3417676 = 1 + +# Patch 5243343 +FEATURE_PATCH_5243343 = 1 + +# plockstat dtrace support +FEATURE_PLOCKSTAT = 1 + +# Timezone change notification +FEATURE_TIMEZONE_CHANGE_NOTIFICATION = 1 diff --git a/Platforms/MacOSX/arm/libc.syscall.arm b/Platforms/MacOSX/arm/libc.syscall.arm new file mode 100644 index 0000000..9e7e088 --- /dev/null +++ b/Platforms/MacOSX/arm/libc.syscall.arm @@ -0,0 +1,88 @@ +_accept$NOCANCEL$UNIX2003 ___accept_nocancel +_accept$UNIX2003 ___accept +_accept$UNIX2003 ___accept +_aio_suspend ___aio_suspend_nocancel +_aio_suspend$NOCANCEL$UNIX2003 ___aio_suspend_nocancel +_aio_suspend$UNIX2003 ___aio_suspend +_bind$UNIX2003 ___bind +_close ___close_nocancel +_close$NOCANCEL$UNIX2003 ___close_nocancel +_close$UNIX2003 ___close +_connect$NOCANCEL$UNIX2003 ___connect_nocancel +_connect$UNIX2003 ___connect +_connect$UNIX2003 ___connect +_fcntl ___fcntl_nocancel +_fcntl$NOCANCEL$UNIX2003 ___fcntl_nocancel +_fcntl$UNIX2003 ___fcntl +_fstat$INODE64 ___fstat64 +_fstatfs$INODE64 ___fstatfs64 +_fsync ___fsync_nocancel +_fsync$NOCANCEL$UNIX2003 ___fsync_nocancel +_fsync$UNIX2003 ___fsync +_getattrlist$UNIX2003 ___getattrlist +_getfsstat$INODE64 ___getfsstat64 +_getpeername$UNIX2003 ___getpeername +_getsockname$UNIX2003 ___getsockname +_lchown$UNIX2003 ___lchown +_listen$UNIX2003 ___listen +_lstat$INODE64 ___lstat64 +_mprotect$UNIX2003 ___mprotect +_msgctl$UNIX2003 ___msgctl +_msgrcv ___msgrcv_nocancel +_msgrcv$NOCANCEL$UNIX2003 ___msgrcv_nocancel +_msgrcv$UNIX2003 ___msgrcv +_msgsnd ___msgsnd_nocancel +_msgsnd$NOCANCEL$UNIX2003 ___msgsnd_nocancel +_msgsnd$UNIX2003 ___msgsnd +_msync$NOCANCEL$UNIX2003 ___msync_nocancel +_msync$UNIX2003 ___msync +_munmap$UNIX2003 ___munmap +_open$NOCANCEL$UNIX2003 ___open_nocancel +_open$UNIX2003 ___open +_poll ___poll_nocancel +_poll$NOCANCEL$UNIX2003 ___poll_nocancel +_poll$UNIX2003 ___poll +_pread ___pread_nocancel +_pread$NOCANCEL$UNIX2003 ___pread_nocancel +_pread$UNIX2003 ___pread +_pwrite ___pwrite_nocancel +_pwrite$NOCANCEL$UNIX2003 ___pwrite_nocancel +_pwrite$UNIX2003 ___pwrite +_read ___read_nocancel +_read$NOCANCEL$UNIX2003 ___read_nocancel +_read$UNIX2003 ___read +_readv ___readv_nocancel +_readv$NOCANCEL$UNIX2003 ___readv_nocancel +_readv$UNIX2003 ___readv +_recvfrom$NOCANCEL$UNIX2003 ___recvfrom_nocancel +_recvfrom$UNIX2003 ___recvfrom +_recvmsg$NOCANCEL$UNIX2003 ___recvmsg_nocancel +_recvmsg$UNIX2003 ___recvmsg +_select$DARWIN_EXTSN ___select +_select$DARWIN_EXTSN$NOCANCEL ___select_nocancel +_sem_wait ___sem_wait_nocancel +_sem_wait$NOCANCEL$UNIX2003 ___sem_wait_nocancel +_sem_wait$UNIX2003 ___sem_wait +_sendmsg$NOCANCEL$UNIX2003 ___sendmsg_nocancel +_sendmsg$UNIX2003 ___sendmsg +_sendto$NOCANCEL$UNIX2003 ___sendto_nocancel +_sendto$NOCANCEL$UNIX2003 ___sendto_nocancel +_sendto$UNIX2003 ___sendto +_sendto$UNIX2003 ___sendto +_setattrlist$UNIX2003 ___setattrlist +_setpgrp ___setpgid +_setregid$UNIX2003 ___setregid +_setreuid$UNIX2003 ___setreuid +_shmctl$UNIX2003 ___shmctl +_socketpair$UNIX2003 ___socketpair +_stat$INODE64 ___stat64 +_statfs$INODE64 ___statfs64 +_waitid ___waitid_nocancel +_waitid$NOCANCEL$UNIX2003 ___waitid_nocancel +_waitid$UNIX2003 ___waitid +_write ___write_nocancel +_write$NOCANCEL$UNIX2003 ___write_nocancel +_write$UNIX2003 ___write +_writev ___writev_nocancel +_writev$NOCANCEL$UNIX2003 ___writev_nocancel +_writev$UNIX2003 ___writev diff --git a/i386/sys/libc.syscall.i386 b/Platforms/MacOSX/i386/libc.syscall.i386 similarity index 94% rename from i386/sys/libc.syscall.i386 rename to Platforms/MacOSX/i386/libc.syscall.i386 index e009a37..9e7e088 100644 --- a/i386/sys/libc.syscall.i386 +++ b/Platforms/MacOSX/i386/libc.syscall.i386 @@ -14,14 +14,18 @@ _connect$UNIX2003 ___connect _fcntl ___fcntl_nocancel _fcntl$NOCANCEL$UNIX2003 ___fcntl_nocancel _fcntl$UNIX2003 ___fcntl +_fstat$INODE64 ___fstat64 +_fstatfs$INODE64 ___fstatfs64 _fsync ___fsync_nocancel _fsync$NOCANCEL$UNIX2003 ___fsync_nocancel _fsync$UNIX2003 ___fsync _getattrlist$UNIX2003 ___getattrlist +_getfsstat$INODE64 ___getfsstat64 _getpeername$UNIX2003 ___getpeername _getsockname$UNIX2003 ___getsockname _lchown$UNIX2003 ___lchown _listen$UNIX2003 ___listen +_lstat$INODE64 ___lstat64 _mprotect$UNIX2003 ___mprotect _msgctl$UNIX2003 ___msgctl _msgrcv ___msgrcv_nocancel @@ -71,6 +75,8 @@ _setregid$UNIX2003 ___setregid _setreuid$UNIX2003 ___setreuid _shmctl$UNIX2003 ___shmctl _socketpair$UNIX2003 ___socketpair +_stat$INODE64 ___stat64 +_statfs$INODE64 ___statfs64 _waitid ___waitid_nocancel _waitid$NOCANCEL$UNIX2003 ___waitid_nocancel _waitid$UNIX2003 ___waitid diff --git a/ppc/sys/libc.syscall.ppc b/Platforms/MacOSX/ppc/libc.syscall.ppc similarity index 94% rename from ppc/sys/libc.syscall.ppc rename to Platforms/MacOSX/ppc/libc.syscall.ppc index e009a37..9e7e088 100644 --- a/ppc/sys/libc.syscall.ppc +++ b/Platforms/MacOSX/ppc/libc.syscall.ppc @@ -14,14 +14,18 @@ _connect$UNIX2003 ___connect _fcntl ___fcntl_nocancel _fcntl$NOCANCEL$UNIX2003 ___fcntl_nocancel _fcntl$UNIX2003 ___fcntl +_fstat$INODE64 ___fstat64 +_fstatfs$INODE64 ___fstatfs64 _fsync ___fsync_nocancel _fsync$NOCANCEL$UNIX2003 ___fsync_nocancel _fsync$UNIX2003 ___fsync _getattrlist$UNIX2003 ___getattrlist +_getfsstat$INODE64 ___getfsstat64 _getpeername$UNIX2003 ___getpeername _getsockname$UNIX2003 ___getsockname _lchown$UNIX2003 ___lchown _listen$UNIX2003 ___listen +_lstat$INODE64 ___lstat64 _mprotect$UNIX2003 ___mprotect _msgctl$UNIX2003 ___msgctl _msgrcv ___msgrcv_nocancel @@ -71,6 +75,8 @@ _setregid$UNIX2003 ___setregid _setreuid$UNIX2003 ___setreuid _shmctl$UNIX2003 ___shmctl _socketpair$UNIX2003 ___socketpair +_stat$INODE64 ___stat64 +_statfs$INODE64 ___statfs64 _waitid ___waitid_nocancel _waitid$NOCANCEL$UNIX2003 ___waitid_nocancel _waitid$UNIX2003 ___waitid diff --git a/ppc64/sys/libc.syscall.ppc64 b/Platforms/MacOSX/ppc64/libc.syscall.ppc64 similarity index 84% rename from ppc64/sys/libc.syscall.ppc64 rename to Platforms/MacOSX/ppc64/libc.syscall.ppc64 index 0c660de..6fa9db6 100644 --- a/ppc64/sys/libc.syscall.ppc64 +++ b/Platforms/MacOSX/ppc64/libc.syscall.ppc64 @@ -2,7 +2,11 @@ _accept$NOCANCEL ___accept_nocancel _aio_suspend$NOCANCEL ___aio_suspend_nocancel _close$NOCANCEL ___close_nocancel _connect$NOCANCEL ___connect_nocancel +_fstat$INODE64 ___fstat64 +_fstatfs$INODE64 ___fstatfs64 _fsync$NOCANCEL ___fsync_nocancel +_getfsstat$INODE64 ___getfsstat64 +_lstat$INODE64 ___lstat64 _msgrcv$NOCANCEL ___msgrcv_nocancel _msgsnd$NOCANCEL ___msgsnd_nocancel _msync$NOCANCEL ___msync_nocancel @@ -20,6 +24,8 @@ _sem_wait$NOCANCEL ___sem_wait_nocancel _sendmsg$NOCANCEL ___sendmsg_nocancel _sendto$NOCANCEL ___sendto_nocancel _sendto$NOCANCEL ___sendto_nocancel +_stat$INODE64 ___stat64 +_statfs$INODE64 ___statfs64 _waitid$NOCANCEL ___waitid_nocancel _write$NOCANCEL ___write_nocancel _writev$NOCANCEL ___writev_nocancel diff --git a/x86_64/sys/libc.syscall.x86_64 b/Platforms/MacOSX/x86_64/libc.syscall.x86_64 similarity index 84% rename from x86_64/sys/libc.syscall.x86_64 rename to Platforms/MacOSX/x86_64/libc.syscall.x86_64 index 0c660de..6fa9db6 100644 --- a/x86_64/sys/libc.syscall.x86_64 +++ b/Platforms/MacOSX/x86_64/libc.syscall.x86_64 @@ -2,7 +2,11 @@ _accept$NOCANCEL ___accept_nocancel _aio_suspend$NOCANCEL ___aio_suspend_nocancel _close$NOCANCEL ___close_nocancel _connect$NOCANCEL ___connect_nocancel +_fstat$INODE64 ___fstat64 +_fstatfs$INODE64 ___fstatfs64 _fsync$NOCANCEL ___fsync_nocancel +_getfsstat$INODE64 ___getfsstat64 +_lstat$INODE64 ___lstat64 _msgrcv$NOCANCEL ___msgrcv_nocancel _msgsnd$NOCANCEL ___msgsnd_nocancel _msync$NOCANCEL ___msync_nocancel @@ -20,6 +24,8 @@ _sem_wait$NOCANCEL ___sem_wait_nocancel _sendmsg$NOCANCEL ___sendmsg_nocancel _sendto$NOCANCEL ___sendto_nocancel _sendto$NOCANCEL ___sendto_nocancel +_stat$INODE64 ___stat64 +_statfs$INODE64 ___statfs64 _waitid$NOCANCEL ___waitid_nocancel _write$NOCANCEL ___write_nocancel _writev$NOCANCEL ___writev_nocancel diff --git a/Platforms/iPhone/Makefile.inc b/Platforms/iPhone/Makefile.inc new file mode 100644 index 0000000..1b391d9 --- /dev/null +++ b/Platforms/iPhone/Makefile.inc @@ -0,0 +1,56 @@ +# +# Selectable features for iPhone +# + +# Legacy *64 APIs +#FEATURE_LEGACY_64_APIS = 1 + +# Legacy NX international APIs +FEATURE_LEGACY_NX_INTERNAT_APIS = 1 + +# Legacy NXZone APIs +FEATURE_LEGACY_NXZONE_APIS = 1 + +# Legacy rune APIs +#FEATURE_LEGACY_RUNE_APIS = 1 + +# Legacy utmp APIs +#FEATURE_LEGACY_UTMP_APIS = 1 + +# New OSMemoryNotification and OSThermalNotification APIs +FEATURE_MEM_THERM_NOTIFICATION_APIS = 1 + +# Move localtime to /var/db/timezone +FEATURE_MOVE_LOCALTIME = 1 + +# Long doubles are doubles (should match sys/cdefs.h) +.if (${MACHINE_ARCH} == arm) +FEATURE_ONLY_LONG_DOUBLE_IS_DOUBLE = 1 +.endif + +# No pre-1050 variants (should match sys/cdefs.h) +FEATURE_ONLY_1050_VARIANTS = 1 + +# No legacy variants (should match sys/cdefs.h) +FEATURE_ONLY_UNIX_CONFORMANCE = 1 + +# Only 64-bit ino_t (should match sys/cdefs.h) +FEATURE_ONLY_64_BIT_INO_T = 1 + +# Patch 3333969 +#FEATURE_PATCH_3333969 = 1 + +# Patch 3375657 +#FEATURE_PATCH_3375657 = 1 + +# Patch 3417676 +#FEATURE_PATCH_3417676 = 1 + +# Patch 5243343 +FEATURE_PATCH_5243343 = 1 + +# plockstat dtrace support +#FEATURE_PLOCKSTAT = 1 + +# Timezone change notification +#FEATURE_TIMEZONE_CHANGE_NOTIFICATION = 1 diff --git a/Platforms/iPhone/arm/libc.syscall.arm b/Platforms/iPhone/arm/libc.syscall.arm new file mode 100644 index 0000000..a5ff2f1 --- /dev/null +++ b/Platforms/iPhone/arm/libc.syscall.arm @@ -0,0 +1,45 @@ +_accept$NOCANCEL ___accept_nocancel +_aio_suspend$NOCANCEL ___aio_suspend_nocancel +_close$NOCANCEL ___close_nocancel +_connect$NOCANCEL ___connect_nocancel +_fstat ___fstat64 +_fstat64 +_fstatfs ___fstatfs64 +_fstatfs64 +_fstatx_np ___fstatx64_np +_fstatx64_np +_fsync$NOCANCEL ___fsync_nocancel +_getfsstat ___getfsstat64 +_getfsstat64 +_getmntinfo ___getmntinfo64 +_getmntinfo64 +_lstat ___lstat64 +_lstat64 +_lstatx_np ___lstatx64_np +_lstatx64_np +_msgrcv$NOCANCEL ___msgrcv_nocancel +_msgsnd$NOCANCEL ___msgsnd_nocancel +_msync$NOCANCEL ___msync_nocancel +_open$NOCANCEL ___open_nocancel +_poll$NOCANCEL ___poll_nocancel +_pread$NOCANCEL ___pread_nocancel +_pwrite$NOCANCEL ___pwrite_nocancel +_read$NOCANCEL ___read_nocancel +_readv$NOCANCEL ___readv_nocancel +_recvfrom$NOCANCEL ___recvfrom_nocancel +_recvmsg$NOCANCEL ___recvmsg_nocancel +_select$DARWIN_EXTSN ___select +_select$DARWIN_EXTSN$NOCANCEL ___select_nocancel +_sem_wait$NOCANCEL ___sem_wait_nocancel +_sendmsg$NOCANCEL ___sendmsg_nocancel +_sendto$NOCANCEL ___sendto_nocancel +_sendto$NOCANCEL ___sendto_nocancel +_stat ___stat64 +_stat64 +_statfs ___statfs64 +_statfs64 +_statx_np ___statx64_np +_statx64_np +_waitid$NOCANCEL ___waitid_nocancel +_write$NOCANCEL ___write_nocancel +_writev$NOCANCEL ___writev_nocancel diff --git a/arm/Makefile.inc b/arm/Makefile.inc new file mode 100644 index 0000000..2ca2600 --- /dev/null +++ b/arm/Makefile.inc @@ -0,0 +1,3 @@ +.if defined(CCARCH) && ${CCARCH} == armv6 +CFLAGS += -mthumb +.endif diff --git a/arm/gen/Makefile.inc b/arm/gen/Makefile.inc new file mode 100644 index 0000000..160fdbb --- /dev/null +++ b/arm/gen/Makefile.inc @@ -0,0 +1,2 @@ +.PATH: ${.CURDIR}/arm/gen +MDSRCS+= icacheinval.s diff --git a/arm/gen/icacheinval.s b/arm/gen/icacheinval.s new file mode 100644 index 0000000..423e9bd --- /dev/null +++ b/arm/gen/icacheinval.s @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + .text + .align 2 + +#include "../sys/SYS.h" + +/* void sys_icache_invalidate(addr_t start, int length) */ +.globl _sys_icache_invalidate +_sys_icache_invalidate: + /* fast trap for icache_invalidate */ + mov r3, #0 + mov r12, #0x80000000 + swi #SWI_SYSCALL + bx lr + +/* void sys_dcache_flush(addr_t start, int length) */ +.globl _sys_dcache_flush +_sys_dcache_flush: + /* fast trap for dcache_flush */ + mov r3, #1 + mov r12, #0x80000000 + swi #SWI_SYSCALL + bx lr diff --git a/arm/mach/Makefile.inc b/arm/mach/Makefile.inc new file mode 100644 index 0000000..e0881df --- /dev/null +++ b/arm/mach/Makefile.inc @@ -0,0 +1,2 @@ +.PATH: ${.CURDIR}/arm/mach +MDSRCS += mach_absolute_time.s diff --git a/arm/mach/mach_absolute_time.c b/arm/mach/mach_absolute_time.c new file mode 100644 index 0000000..355d560 --- /dev/null +++ b/arm/mach/mach_absolute_time.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include + +int mach_absolute_time(void) +{ + static uint32_t abs_time = 0; + return abs_time++; +} diff --git a/arm/mach/mach_absolute_time.s b/arm/mach/mach_absolute_time.s new file mode 100644 index 0000000..979c6b5 --- /dev/null +++ b/arm/mach/mach_absolute_time.s @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + .text + .align 2 + .globl _mach_absolute_time +_mach_absolute_time: + mov r12, #-3 + swi 0x80 + bx lr diff --git a/arm/pthreads/Makefile.inc b/arm/pthreads/Makefile.inc new file mode 100644 index 0000000..cc92564 --- /dev/null +++ b/arm/pthreads/Makefile.inc @@ -0,0 +1,7 @@ +.PATH: ${.CURDIR}/arm/pthreads +MDSRCS += \ + get_cpu_capabilities.s \ + pthread_set_self.s \ + pthread_self.s \ + pthread_getspecific.s \ + init_cpu_capabilities.c diff --git a/arm/pthreads/get_cpu_capabilities.s b/arm/pthreads/get_cpu_capabilities.s new file mode 100644 index 0000000..e4b5f20 --- /dev/null +++ b/arm/pthreads/get_cpu_capabilities.s @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2007 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* Get the cpu_capabilities bit vector out of the comm page */ + +#define __APPLE_API_PRIVATE +#include +#undef __APPLE_API_PRIVATE + +.text +.align 2 +.private_extern __get_cpu_capabilities +__get_cpu_capabilities: + mov r0, #_COMM_PAGE_CPU_CAPABILITIES + ldr r0, [r0] + bx lr diff --git a/arm/pthreads/init_cpu_capabilities.c b/arm/pthreads/init_cpu_capabilities.c new file mode 100644 index 0000000..476c017 --- /dev/null +++ b/arm/pthreads/init_cpu_capabilities.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* Initialize the "_cpu_capabilities" vector on ARM processors. */ + +#define __APPLE_API_PRIVATE +#include +#undef __APPLE_API_PRIVATE + +extern int _get_cpu_capabilities(void); + +int _cpu_capabilities = 0; +int _cpu_has_altivec = 0; // DEPRECATED: use _cpu_capabilities instead + +__private_extern__ void +_init_cpu_capabilities( void ) +{ +} diff --git a/arm/pthreads/pthread_getspecific.s b/arm/pthreads/pthread_getspecific.s new file mode 100644 index 0000000..d0533f0 --- /dev/null +++ b/arm/pthreads/pthread_getspecific.s @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +#include "pthread_machdep.h" + +#define __APPLE_API_PRIVATE +#include +#undef __APPLE_API_PRIVATE + + .text + .align 4 + .globl _pthread_getspecific +_pthread_getspecific: + add r0, r9, r0, lsl #2 + ldr r0, [r0, #_PTHREAD_TSD_OFFSET] + bx lr diff --git a/arm/pthreads/pthread_self.s b/arm/pthreads/pthread_self.s new file mode 100644 index 0000000..87a4ea4 --- /dev/null +++ b/arm/pthreads/pthread_self.s @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +#define __APPLE_API_PRIVATE +#include +#undef __APPLE_API_PRIVATE + + .text + .align 2 + .globl _pthread_self +_pthread_self: + mov r0, r9 + bx lr diff --git a/arm/pthreads/pthread_set_self.s b/arm/pthreads/pthread_set_self.s new file mode 100644 index 0000000..89125c0 --- /dev/null +++ b/arm/pthreads/pthread_set_self.s @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + .text + .align 2 + .globl ___pthread_set_self +___pthread_set_self: + mov r9, r0 + bx lr diff --git a/arm/stdlib/gdtoa.mk b/arm/stdlib/gdtoa.mk new file mode 100644 index 0000000..c8477d4 --- /dev/null +++ b/arm/stdlib/gdtoa.mk @@ -0,0 +1 @@ +GDTOA_FBSDSRCS+= machdep_ldisd.c diff --git a/arm/string/Makefile.inc b/arm/string/Makefile.inc new file mode 100644 index 0000000..8d4292d --- /dev/null +++ b/arm/string/Makefile.inc @@ -0,0 +1,14 @@ +# $Version$ +# +# ARM-optimised string functions. +# +.PATH: ${.CURDIR}/arm/string + +MDSRCS += \ + bcopy.s \ + bzero.s \ + ffs.s \ + strcmp.s \ + strlen.s + +SUPPRESSSRCS += memcpy.c memmove.c memset.c strlen.c diff --git a/arm/string/bcopy.s b/arm/string/bcopy.s new file mode 100644 index 0000000..da24152 --- /dev/null +++ b/arm/string/bcopy.s @@ -0,0 +1,401 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include + +.text +.align 2 + + .globl _memcpy + .globl _bcopy + .globl _memmove + +_bcopy: /* void bcopy(const void *src, void *dest, size_t len); */ + mov r3, r0 + mov r0, r1 + mov r1, r3 + +_memcpy: /* void *memcpy(void *dest, const void *src, size_t len); */ +_memmove: /* void *memmove(void *dest, const void *src, size_t len); */ + /* check for zero len or if the pointers are the same */ + cmp r2, #0 + cmpne r0, r1 + bxeq lr + + /* save r0 (return value), r4 (scratch), and r5 (scratch) */ + stmfd sp!, { r0, r4, r5, r7, lr } + add r7, sp, #12 + + /* check for overlap. r3 <- distance between src & dest */ + subhs r3, r0, r1 + sublo r3, r1, r0 + cmp r3, r2 /* if distance(src, dest) < len, we have overlap */ + blo Loverlap + +Lnormalforwardcopy: + /* are src and dest dissimilarly word aligned? */ + mov r12, r0, lsl #30 + cmp r12, r1, lsl #30 + bne Lnonwordaligned_forward + + /* if len < 64, do a quick forward copy */ + cmp r2, #64 + blt Lsmallforwardcopy + + /* check for 16 byte src/dest unalignment */ + tst r0, #0xf + bne Lsimilarlyunaligned + + /* check for 32 byte dest unalignment */ + tst r0, #(1<<4) + bne Lunaligned_32 + +Lmorethan64_aligned: + /* save some more registers to use in the copy */ + stmfd sp!, { r6, r8, r10, r11 } + + /* pre-subtract 64 from the len counter to avoid an extra compare in the loop */ + sub r2, r2, #64 + +L64loop: + /* copy 64 bytes at a time */ + ldmia r1!, { r3, r4, r5, r6, r8, r10, r11, r12 } +#ifdef _ARM_ARCH_6 + pld [r1, #32] +#endif + stmia r0!, { r3, r4, r5, r6, r8, r10, r11, r12 } + ldmia r1!, { r3, r4, r5, r6, r8, r10, r11, r12 } + subs r2, r2, #64 +#ifdef _ARM_ARCH_6 + pld [r1, #32] +#endif + stmia r0!, { r3, r4, r5, r6, r8, r10, r11, r12 } + bge L64loop + + /* restore the scratch registers we just saved */ + ldmfd sp!, { r6, r8, r10, r11 } + + /* fix up the len counter (previously subtracted an extra 64 from it) and test for completion */ + adds r2, r2, #64 + beq Lexit + +Llessthan64_aligned: + /* copy 16 bytes at a time until we have < 16 bytes */ + cmp r2, #16 + ldmgeia r1!, { r3, r4, r5, r12 } + stmgeia r0!, { r3, r4, r5, r12 } + subges r2, r2, #16 + bgt Llessthan64_aligned + beq Lexit + +Llessthan16_aligned: + mov r2, r2, lsl #28 + msr cpsr_f, r2 + + ldmmiia r1!, { r2, r3 } + ldreq r4, [r1], #4 + ldrcsh r5, [r1], #2 + ldrvsb r12, [r1], #1 + + stmmiia r0!, { r2, r3 } + streq r4, [r0], #4 + strcsh r5, [r0], #2 + strvsb r12, [r0], #1 + b Lexit + +Lsimilarlyunaligned: + /* both src and dest are unaligned in similar ways, align to dest on 32 byte boundary */ + mov r12, r0, lsl #28 + rsb r12, r12, #0 + msr cpsr_f, r12 + + ldrvsb r3, [r1], #1 + ldrcsh r4, [r1], #2 + ldreq r5, [r1], #4 + + strvsb r3, [r0], #1 + strcsh r4, [r0], #2 + streq r5, [r0], #4 + + ldmmiia r1!, { r3, r4 } + stmmiia r0!, { r3, r4 } + + subs r2, r2, r12, lsr #28 + beq Lexit + +Lunaligned_32: + /* bring up to dest 32 byte alignment */ + tst r0, #(1 << 4) + ldmneia r1!, { r3, r4, r5, r12 } + stmneia r0!, { r3, r4, r5, r12 } + subne r2, r2, #16 + + /* we should now be aligned, see what copy method we should use */ + cmp r2, #64 + bge Lmorethan64_aligned + b Llessthan64_aligned + +Lbytewise2: + /* copy 2 bytes at a time */ + subs r2, r2, #2 + + ldrb r3, [r1], #1 + ldrplb r4, [r1], #1 + + strb r3, [r0], #1 + strplb r4, [r0], #1 + + bhi Lbytewise2 + b Lexit + +Lbytewise: + /* simple bytewise forward copy */ + ldrb r3, [r1], #1 + subs r2, r2, #1 + strb r3, [r0], #1 + bne Lbytewise + b Lexit + +Lsmallforwardcopy: + /* src and dest are word aligned similarly, less than 64 bytes to copy */ + cmp r2, #4 + blt Lbytewise2 + + /* bytewise copy until word aligned */ + tst r1, #3 +Lwordalignloop: + ldrneb r3, [r1], #1 + strneb r3, [r0], #1 + subne r2, r2, #1 + tstne r1, #3 + bne Lwordalignloop + + cmp r2, #16 + bge Llessthan64_aligned + blt Llessthan16_aligned + +Loverlap: + /* src and dest overlap in some way, len > 0 */ + cmp r0, r1 /* if dest > src */ + bhi Loverlap_srclower + +Loverlap_destlower: + /* dest < src, see if we can still do a fast forward copy or fallback to slow forward copy */ + cmp r3, #64 + bge Lnormalforwardcopy /* overlap is greater than one stride of the copy, use normal copy */ + + cmp r3, #2 + bge Lbytewise2 + b Lbytewise + + /* the following routines deal with having to copy in the reverse direction */ +Loverlap_srclower: + /* src < dest, with overlap */ + + /* src += len; dest += len; */ + add r0, r0, r2 + add r1, r1, r2 + + /* we have to copy in reverse no matter what, test if we can we use a large block reverse copy */ + cmp r2, #64 /* less than 64 bytes to copy? */ + cmpgt r3, #64 /* less than 64 bytes of nonoverlap? */ + blt Lbytewise_reverse + + /* test of src and dest are nonword aligned differently */ + mov r3, r0, lsl #30 + cmp r3, r1, lsl #30 + bne Lbytewise_reverse + + /* test if src and dest are non word aligned or dest is non 16 byte aligned */ + tst r0, #0xf + bne Lunaligned_reverse_similarly + + /* test for dest 32 byte alignment */ + tst r0, #(1<<4) + bne Lunaligned_32_reverse_similarly + + /* 64 byte reverse block copy, src and dest aligned */ +Lmorethan64_aligned_reverse: + /* save some more registers to use in the copy */ + stmfd sp!, { r6, r8, r10, r11 } + + /* pre-subtract 64 from the len counter to avoid an extra compare in the loop */ + sub r2, r2, #64 + +L64loop_reverse: + /* copy 64 bytes at a time */ + ldmdb r1!, { r3, r4, r5, r6, r8, r10, r11, r12 } +#ifdef _ARM_ARCH_6 + pld [r1, #-32] +#endif + stmdb r0!, { r3, r4, r5, r6, r8, r10, r11, r12 } + ldmdb r1!, { r3, r4, r5, r6, r8, r10, r11, r12 } + subs r2, r2, #64 +#ifdef _ARM_ARCH_6 + pld [r1, #-32] +#endif + stmdb r0!, { r3, r4, r5, r6, r8, r10, r11, r12 } + bge L64loop_reverse + + /* restore the scratch registers we just saved */ + ldmfd sp!, { r6, r8, r10, r11 } + + /* fix up the len counter (previously subtracted an extra 64 from it) and test for completion */ + adds r2, r2, #64 + beq Lexit + +Lbytewise_reverse: + ldrb r3, [r1, #-1]! + strb r3, [r0, #-1]! + subs r2, r2, #1 + bne Lbytewise_reverse + b Lexit + +Lunaligned_reverse_similarly: + /* both src and dest are unaligned in similar ways, align to dest on 32 byte boundary */ + mov r12, r0, lsl #28 + msr cpsr_f, r12 + + ldrvsb r3, [r1, #-1]! + ldrcsh r4, [r1, #-2]! + ldreq r5, [r1, #-4]! + + strvsb r3, [r0, #-1]! + strcsh r4, [r0, #-2]! + streq r5, [r0, #-4]! + + ldmmidb r1!, { r3, r4 } + stmmidb r0!, { r3, r4 } + + subs r2, r2, r12, lsr #28 + beq Lexit + +Lunaligned_32_reverse_similarly: + /* bring up to dest 32 byte alignment */ + tst r0, #(1 << 4) + ldmnedb r1!, { r3, r4, r5, r12 } + stmnedb r0!, { r3, r4, r5, r12 } + subne r2, r2, #16 + + /* we should now be aligned, see what copy method we should use */ + cmp r2, #64 + bge Lmorethan64_aligned_reverse + b Lbytewise_reverse + + /* the following routines deal with non word aligned copies */ +Lnonwordaligned_forward: + cmp r2, #8 + blt Lbytewise2 /* not worth the effort with less than 24 bytes total */ + + /* bytewise copy until src word aligned */ + tst r1, #3 +Lwordalignloop2: + ldrneb r3, [r1], #1 + strneb r3, [r0], #1 + subne r2, r2, #1 + tstne r1, #3 + bne Lwordalignloop2 + + /* figure out how the src and dest are unaligned */ + and r3, r0, #3 + cmp r3, #2 + blt Lalign1_forward + beq Lalign2_forward + bgt Lalign3_forward + +Lalign1_forward: + /* the dest pointer is 1 byte off from src */ + mov r12, r2, lsr #2 /* number of words we should copy */ + sub r0, r0, #1 + + /* prime the copy */ + ldrb r4, [r0] /* load D[7:0] */ + +Lalign1_forward_loop: + ldr r3, [r1], #4 /* load S */ + orr r4, r4, r3, lsl #8 /* D[31:8] = S[24:0] */ + str r4, [r0], #4 /* save D */ + mov r4, r3, lsr #24 /* D[7:0] = S[31:25] */ + subs r12, r12, #1 + bne Lalign1_forward_loop + + /* finish the copy off */ + strb r4, [r0], #1 /* save D[7:0] */ + + ands r2, r2, #3 + beq Lexit + b Lbytewise2 + +Lalign2_forward: + /* the dest pointer is 2 bytes off from src */ + mov r12, r2, lsr #2 /* number of words we should copy */ + sub r0, r0, #2 + + /* prime the copy */ + ldrh r4, [r0] /* load D[15:0] */ + +Lalign2_forward_loop: + ldr r3, [r1], #4 /* load S */ + orr r4, r4, r3, lsl #16 /* D[31:16] = S[15:0] */ + str r4, [r0], #4 /* save D */ + mov r4, r3, lsr #16 /* D[15:0] = S[31:15] */ + subs r12, r12, #1 + bne Lalign2_forward_loop + + /* finish the copy off */ + strh r4, [r0], #2 /* save D[15:0] */ + + ands r2, r2, #3 + beq Lexit + b Lbytewise2 + +Lalign3_forward: + /* the dest pointer is 3 bytes off from src */ + mov r12, r2, lsr #2 /* number of words we should copy */ + sub r0, r0, #3 + + /* prime the copy */ + ldr r4, [r0] + and r4, r4, #0x00ffffff /* load D[24:0] */ + +Lalign3_forward_loop: + ldr r3, [r1], #4 /* load S */ + orr r4, r4, r3, lsl #24 /* D[31:25] = S[7:0] */ + str r4, [r0], #4 /* save D */ + mov r4, r3, lsr #8 /* D[24:0] = S[31:8] */ + subs r12, r12, #1 + bne Lalign3_forward_loop + + /* finish the copy off */ + strh r4, [r0], #2 /* save D[15:0] */ + mov r4, r4, lsr #16 + strb r4, [r0], #1 /* save D[23:16] */ + + ands r2, r2, #3 + beq Lexit + b Lbytewise2 + +Lexit: + ldmfd sp!, {r0, r4, r5, r7, pc} + + diff --git a/arm/string/bzero.s b/arm/string/bzero.s new file mode 100644 index 0000000..9e2088c --- /dev/null +++ b/arm/string/bzero.s @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include + +/* + * A reasonably well-optimized bzero/memset. Should work equally well on arm11 and arm9 based + * cores. + * + * The algorithm is to align the destination pointer on a 32 byte boundary and then + * blast data 64 bytes at a time, in two stores of 32 bytes per loop. + */ + .text + .align 2 + + .globl _memset +/* void *memset(void *ptr, int c, size_t len); */ +_memset: + /* move len into r1, unpack c into r2 */ + mov r3, r2 + and r1, r1, #0xff + orr r1, r1, r1, lsl #8 + orr r2, r1, r1, lsl #16 + mov r1, r3 + b Lbzeroengine + + .globl _bzero +/* void bzero(void *ptr, size_t len); */ +_bzero: + /* zero out r2 so we can be just like memset(0) */ + mov r2, #0 + +Lbzeroengine: + /* move the base pointer into r12 and leave r0 alone so that we return the original pointer */ + mov r12, r0 + + /* copy r2 into r3 for 64-bit stores */ + mov r3, r2 + + /* check for zero len */ + cmp r1, #0 + bxeq lr + + /* fall back to a bytewise store for less than 32 bytes */ + cmp r1, #32 + blt L_bytewise + + /* check for 32 byte unaligned ptr */ + tst r12, #0x1f + bne L_unaligned + + /* make sure we have more than 64 bytes to zero */ + cmp r1, #64 + blt L_lessthan64aligned + + /* >= 64 bytes of len, 32 byte aligned */ +L_64ormorealigned: + + /* we need some registers, avoid r7 (frame pointer) and r9 (thread register) */ + stmfd sp!, { r4-r6, r8, r10-r11 } + mov r4, r2 + mov r5, r2 + mov r6, r2 + mov r8, r2 + mov r10, r2 + mov r11, r2 + + /* pre-subtract 64 from the len to avoid an extra compare in the loop */ + sub r1, r1, #64 + +L_64loop: + stmia r12!, { r2-r6, r8, r10-r11 } + subs r1, r1, #64 + stmia r12!, { r2-r6, r8, r10-r11 } + bge L_64loop + + /* restore the saved regs */ + ldmfd sp!, { r4-r6, r8, r10-r11 } + + /* check for completion (had previously subtracted an extra 64 from len) */ + adds r1, r1, #64 + bxeq lr + +L_lessthan64aligned: + /* do we have 16 or more bytes left */ + cmp r1, #16 + stmgeia r12!, { r2-r3 } + stmgeia r12!, { r2-r3 } + subges r1, r1, #16 + bgt L_lessthan64aligned + bxeq lr + +L_lessthan16aligned: + /* store 0 to 15 bytes */ + mov r1, r1, lsl #28 /* move the remaining len bits [3:0] to the flags area of cpsr */ + msr cpsr_f, r1 + + stmmiia r12!, { r2-r3 } /* n is set, store 8 bytes */ + streq r2, [r12], #4 /* z is set, store 4 bytes */ + strcsh r2, [r12], #2 /* c is set, store 2 bytes */ + strvsb r2, [r12], #1 /* v is set, store 1 byte */ + bx lr + +L_bytewise: + /* bytewise copy, 2 bytes at a time, alignment not guaranteed */ + subs r1, r1, #2 + strb r2, [r12], #1 + strplb r2, [r12], #1 + bhi L_bytewise + bx lr + +L_unaligned: + /* unaligned on 32 byte boundary, store 1-15 bytes until we're 16 byte aligned */ + mov r3, r12, lsl #28 + rsb r3, r3, #0x00000000 + msr cpsr_f, r3 + + strvsb r2, [r12], #1 /* v is set, unaligned in the 1s column */ + strcsh r2, [r12], #2 /* c is set, unaligned in the 2s column */ + streq r2, [r12], #4 /* z is set, unaligned in the 4s column */ + strmi r2, [r12], #4 /* n is set, unaligned in the 8s column */ + strmi r2, [r12], #4 + + subs r1, r1, r3, lsr #28 + bxeq lr + + /* we had previously trashed r3, restore it */ + mov r3, r2 + + /* now make sure we're 32 byte aligned */ + tst r12, #(1 << 4) + stmneia r12!, { r2-r3 } + stmneia r12!, { r2-r3 } + subnes r1, r1, #16 + + /* we're now aligned, check for >= 64 bytes left */ + cmp r1, #64 + bge L_64ormorealigned + b L_lessthan64aligned + diff --git a/arm/string/ffs.s b/arm/string/ffs.s new file mode 100644 index 0000000..62e492a --- /dev/null +++ b/arm/string/ffs.s @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include + +#ifdef _ARM_ARCH_5 + .text + + .align 2 + .globl _ffs +_ffs: + .globl _ffsl +_ffsl: + rsb r3, r0, #0 + and r0, r0, r3 + clz r0, r0 + rsb r0, r0, #32 + bx lr + + .align 2 + .globl _fls +_fls: + .globl _flsl +_flsl: + clz r0, r0 + rsb r0, r0, #32 + bx lr +#else +#error need to define ffs for this architecture +#endif diff --git a/arm/string/strcmp.s b/arm/string/strcmp.s new file mode 100644 index 0000000..4f1008e --- /dev/null +++ b/arm/string/strcmp.s @@ -0,0 +1,44 @@ +/* $NetBSD: strcmp.S,v 1.3 2003/04/05 23:08:52 bjh21 Exp $ */ +/* $FreeBSD: src/lib/libc/arm/string/strcmp.S,v 1.2 2004/11/09 16:49:14 cognet Exp $ */ + +/* + * Copyright (c) 2002 ARM Ltd + * 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 company may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY ARM LTD ``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 ARM LTD 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. + */ + + .text + .align 2 + .globl _strcmp + +_strcmp: +1: + ldrb r2, [r0], #1 + ldrb r3, [r1], #1 + cmp r2, #1 + cmpcs r2, r3 + beq 1b + sub r0, r2, r3 + bx lr diff --git a/arm/string/strlen.s b/arm/string/strlen.s new file mode 100644 index 0000000..2a18590 --- /dev/null +++ b/arm/string/strlen.s @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +.text + .align 2 + + .globl _strlen +/* size_t strlen(const char *s); */ +_strlen: + /* save the original pointer */ + mov r12, r0 + + /* see if the string is aligned */ + ands r3, r0, #3 + + /* load the first word, address rounded down */ + bic r0, r0, #3 + ldr r2, [r0], #4 + + /* skip the next part if the string is already aligned */ + beq Laligned + +Lunaligned: + /* unaligned pointer, mask out the bytes that we've read that we should be ignoring */ + cmp r3, #2 + orr r2, r2, #0x000000ff + orrge r2, r2, #0x0000ff00 + orrgt r2, r2, #0x00ff0000 + +Laligned: + /* load 0x01010101 into r1 */ + mov r1, #0x01 + orr r1, r1, r1, lsl #8 + orr r1, r1, r1, lsl #16 + +Laligned_loop: + /* ((x - 0x01010101) & ~x & 0x80808080) == hasnull(word) */ + sub r3, r2, r1 /* x - 0x01010101 */ + bic r3, r3, r2 /* above & ~x */ + tst r3, r1, lsl #7 /* above & 0x80808080 */ + ldreq r2, [r0], #4 /* load next word */ + beq Laligned_loop + + /* we found a nullbyte */ + /* r0 (ptr) has overshot by up to 4 bytes, so subtract off until we find a nullbyte */ + sub r0, r0, #1 + tst r2, #0x000000ff + subeq r0, r0, #1 + tstne r2, #0x0000ff00 + subeq r0, r0, #1 + tstne r2, #0x00ff0000 + subeq r0, r0, #1 + +Lexit: + /* len = ptr - original pointer */ + sub r0, r0, r12 + bx lr + diff --git a/arm/sys/Makefile.inc b/arm/sys/Makefile.inc new file mode 100644 index 0000000..63acdf3 --- /dev/null +++ b/arm/sys/Makefile.inc @@ -0,0 +1,12 @@ +.PATH: ${.CURDIR}/arm/sys + +MDSRCS+= \ + OSAtomic-v4.c \ + OSAtomic.s \ + _longjmp.s \ + _setjmp.s \ + arm_commpage_gettimeofday.c \ + longjmp.s \ + setjmp.s + +MDCOPYFILES+= ${.CURDIR}/Platforms/${RC_TARGET_CONFIG}/arm/libc.syscall.arm diff --git a/arm/sys/OSAtomic-v4.c b/arm/sys/OSAtomic-v4.c new file mode 100644 index 0000000..f3a1b37 --- /dev/null +++ b/arm/sys/OSAtomic-v4.c @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include + + +#if !defined(_ARM_ARCH_6) + +/* + * The only atomic operation ARMv4T provides (atomic swap) is not + * sufficient for the general 32-bit arithmetic and compare-and-swap + * operations OSAtomic is supposed to provide. So we use a global + * spin lock around all operations. + * + * Since we have only a single, in-order, CPU, we do not need + * memory barriers for data. + */ + +static OSSpinLock _atomic_lock = OS_SPINLOCK_INIT; + +int32_t OSAtomicAdd32( int32_t theAmount, int32_t *theValue ) +{ + int32_t result; + + OSSpinLockLock(&_atomic_lock); + result = (*theValue += theAmount); + OSSpinLockUnlock(&_atomic_lock); + + return result; +} + +int32_t OSAtomicAdd32Barrier( int32_t theAmount, int32_t *theValue ) +{ + return OSAtomicAdd32(theAmount, theValue); +} + +int32_t OSAtomicOr32( uint32_t theMask, uint32_t *theValue ) +{ + int32_t result; + + OSSpinLockLock(&_atomic_lock); + result = (*theValue |= theMask); + OSSpinLockUnlock(&_atomic_lock); + + return result; +} + +int32_t OSAtomicOr32Barrier( uint32_t theMask, uint32_t *theValue ) +{ + return OSAtomicOr32(theMask, theValue); +} + +int32_t OSAtomicAnd32( uint32_t theMask, uint32_t *theValue ) +{ + int32_t result; + + OSSpinLockLock(&_atomic_lock); + result = (*theValue &= theMask); + OSSpinLockUnlock(&_atomic_lock); + + return result; +} + +int32_t OSAtomicAnd32Barrier( uint32_t theMask, uint32_t *theValue ) +{ + return OSAtomicAnd32(theMask, theValue); +} + +int32_t OSAtomicXor32( uint32_t theMask, uint32_t *theValue ) +{ + int32_t result; + + OSSpinLockLock(&_atomic_lock); + result = (*theValue ^= theMask); + OSSpinLockUnlock(&_atomic_lock); + + return result; +} + +int32_t OSAtomicXor32Barrier( uint32_t theMask, uint32_t *theValue ) +{ + return OSAtomicXor32(theMask, theValue); +} + +bool OSAtomicCompareAndSwap32( int32_t oldValue, int32_t newValue, int32_t *theValue ) +{ + bool result; + + OSSpinLockLock(&_atomic_lock); + result = (*theValue == oldValue); + if (result) *theValue = newValue; + OSSpinLockUnlock(&_atomic_lock); + + return result; +} + +bool OSAtomicCompareAndSwap32Barrier( int32_t oldValue, int32_t newValue, int32_t *theValue ) +{ + return OSAtomicCompareAndSwap32(oldValue, newValue, theValue); +} + +bool OSAtomicTestAndSet( uint32_t n, void *theAddress ) +{ + char *byteAddress = ((char*)theAddress + (n>>3)); + uint32_t byteBit = (0x80>>(n&7)); + bool result; + + OSSpinLockLock(&_atomic_lock); + result = *byteAddress & byteBit; + *byteAddress |= byteBit; + OSSpinLockUnlock(&_atomic_lock); + + return result; +} + +bool OSAtomicTestAndSetBarrier( uint32_t n, void *theAddress ) +{ + return OSAtomicTestAndSet(n, theAddress); +} + +bool OSAtomicTestAndClear( uint32_t n, void *theAddress ) +{ + char *byteAddress = ((char*)theAddress + (n>>3)); + uint32_t byteBit = (0x80>>(n&7)); + bool result; + + OSSpinLockLock(&_atomic_lock); + result = *byteAddress & byteBit; + *byteAddress &= (~byteBit); + OSSpinLockUnlock(&_atomic_lock); + + return result; +} + +bool OSAtomicTestAndClearBarrier( uint32_t n, void *theAddress ) +{ + return OSAtomicTestAndClear(n, theAddress); +} + +void OSMemoryBarrier( void ) +{ + return; +} + +#endif /* !defined(_ARM_ARCH_6) */ diff --git a/arm/sys/OSAtomic.s b/arm/sys/OSAtomic.s new file mode 100644 index 0000000..ce6de9d --- /dev/null +++ b/arm/sys/OSAtomic.s @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include "SYS.h" +#include + +.text + +/* + * Use LDREX/STREX to perform atomic operations. + * Memory barriers are not needed on a UP system + */ + +#if defined(_ARM_ARCH_6) + +/* Implement a generic atomic arithmetic operation: + * operand is in R0, pointer is in R1. Return new + * value into R0 + */ +#define ATOMIC_ARITHMETIC(op) \ +1: ldrex r2, [r1] /* load existing value and tag memory */ ;\ + op r3, r2, r0 /* compute new value */ ;\ + strex r2, r3, [r1] /* store new value if memory is still tagged */ ;\ + cmp r2, #0 /* check if the store succeeded */ ;\ + bne 1b /* if not, try again */ ;\ + mov r0, r3 /* return new value */ + +MI_ENTRY_POINT(_OSAtomicAdd32Barrier) +MI_ENTRY_POINT(_OSAtomicAdd32) + ATOMIC_ARITHMETIC(add) + bx lr + +MI_ENTRY_POINT(_OSAtomicOr32Barrier) +MI_ENTRY_POINT(_OSAtomicOr32) + ATOMIC_ARITHMETIC(orr) + bx lr + +MI_ENTRY_POINT(_OSAtomicAnd32Barrier) +MI_ENTRY_POINT(_OSAtomicAnd32) + ATOMIC_ARITHMETIC(and) + bx lr + +MI_ENTRY_POINT(_OSAtomicXor32Barrier) +MI_ENTRY_POINT(_OSAtomicXor32) + ATOMIC_ARITHMETIC(eor) + bx lr + +MI_ENTRY_POINT(_OSAtomicCompareAndSwap32Barrier) +MI_ENTRY_POINT(_OSAtomicCompareAndSwap32) +MI_ENTRY_POINT(_OSAtomicCompareAndSwapIntBarrier) +MI_ENTRY_POINT(_OSAtomicCompareAndSwapInt) +MI_ENTRY_POINT(_OSAtomicCompareAndSwapLongBarrier) +MI_ENTRY_POINT(_OSAtomicCompareAndSwapLong) +MI_ENTRY_POINT(_OSAtomicCompareAndSwapPtrBarrier) +MI_ENTRY_POINT(_OSAtomicCompareAndSwapPtr) +1: ldrex r3, [r2] // load existing value and tag memory + teq r3, r0 // is it the same as oldValue? + movne r0, #0 // if not, return 0 immediately + bxne lr + strex r3, r1, [r2] // otherwise, try to store new value + cmp r3, #0 // check if the store succeeded + bne 1b // if not, try again + mov r0, #1 // return true + bx lr + + +/* Implement a generic test-and-bit-op operation: + * bit to set is in R0, base address is in R1. Return + * previous value (0 or 1) of the bit in R0. + */ +#define ATOMIC_BITOP(op) \ + /* Adjust pointer to point at the correct word ;\ + * R1 = R1 + 4 * (R0 / 32) ;\ + */ ;\ + mov r3, r0, lsr #5 ;\ + add r1, r1, r3, asl #2 ;\ + /* Generate a bit mask for the bit we want to test ;\ + * R0 = (0x80 >> (R0 & 7)) << (R0 & ~7 & 31) ;\ + */ ;\ + and r2, r0, #7 ;\ + mov r3, #0x80 ;\ + mov r3, r3, asr r2 ;\ + and r0, r0, #0x18 ;\ + mov r0, r3, asl r0 ;\ +1: ;\ + ldrex r2, [r1] /* load existing value and tag memory */ ;\ + op r3, r2, r0 /* compute new value */ ;\ + strex ip, r3, [r1] /* attempt to store new value */ ;\ + cmp ip, #0 /* check if the store succeeded */ ;\ + bne 1b /* if so, try again */ ;\ + ands r0, r2, r0 /* mask off the bit from the old value */ ;\ + movne r0, #1 /* if non-zero, return exactly 1 */ + +MI_ENTRY_POINT(_OSAtomicTestAndSetBarrier) +MI_ENTRY_POINT(_OSAtomicTestAndSet) + ATOMIC_BITOP(orr) + bx lr + +MI_ENTRY_POINT(_OSAtomicTestAndClearBarrier) +MI_ENTRY_POINT(_OSAtomicTestAndClear) + ATOMIC_BITOP(bic) + bx lr + +MI_ENTRY_POINT(_OSMemoryBarrier) + bx lr + + +#if defined(_ARM_ARCH_6K) +/* If we can use LDREXD/STREXD, then we can implement 64-bit atomic operations */ + +MI_ENTRY_POINT(_OSAtomicAdd64) + // R0,R1 contain the amount to add + // R2 contains the pointer + stmfd sp!, {r4, r5, r6, r8, lr} +1: + ldrexd r4, [r2] // load existing value to R4/R5 and tag memory + adds r6, r4, r0 // add lower half of new value into R6 and set carry bit + adc r8, r5, r1 // add upper half of new value into R8 with carry + strexd r3, r6, [r2] // store new value if memory is still tagged + cmp r3, #0 // check if store succeeded + bne 1b // if so, try again + mov r0, r6 // return new value + mov r1, r8 + ldmfd sp!, {r4, r5, r6, r8, pc} + +MI_ENTRY_POINT(_OSAtomicCompareAndSwap64) + // R0,R1 contains the old value + // R2,R3 contains the new value + // the pointer is pushed onto the stack + ldr ip, [sp, #0] // load pointer into IP + stmfd sp!, {r4, r5, lr} +1: + ldrexd r4, [ip] // load existing value into R4/R5 and tag memory + teq r0, r4 // check low word + teqeq r1, r5 // if low words match, check high word + movne r0, #0 // if either match fails, return 0 + bne 2f + strexd r4, r2, [ip] // otherwise, try to store new values + cmp r3, #0 // check if store succeeded + bne 1b // if so, try again + mov r0, #1 // return true +2: + ldmfd sp!, {r4, r5, pc} + +#endif /* defined(_ARM_ARCH_6K) */ + +#endif /* defined(_ARM_ARCH_6) */ + +/* + * void + * _spin_lock(p) + * int *p; + * + * Lock the lock pointed to by p. Spin (possibly forever) until the next + * lock is available. + */ +MI_ENTRY_POINT(_spin_lock) +MI_ENTRY_POINT(__spin_lock) +MI_ENTRY_POINT(_OSSpinLockLock) +L_spin_lock_loop: + mov r1, #1 + swp r2, r1, [r0] + cmp r2, #0 + bxeq lr + mov ip, sp + stmfd sp!, {r0, r8} + mov r0, #0 // THREAD_NULL + mov r1, #1 // SWITCH_OPTION_DEPRESS + mov r2, #1 // timeout (ms) + mov r12, #-61 // SYSCALL_THREAD_SWITCH + swi 0x80 + ldmfd sp!, {r0, r8} + b L_spin_lock_loop + +MI_ENTRY_POINT(_spin_lock_try) +MI_ENTRY_POINT(__spin_lock_try) +MI_ENTRY_POINT(_OSSpinLockTry) + mov r1, #1 + swp r2, r1, [r0] + bic r0, r1, r2 + bx lr + +/* + * void + * _spin_unlock(p) + * int *p; + * + * Unlock the lock pointed to by p. + */ +MI_ENTRY_POINT(_spin_unlock) +MI_ENTRY_POINT(__spin_unlock) +MI_ENTRY_POINT(_OSSpinLockUnlock) + mov r1, #0 + str r1, [r0] + bx lr + diff --git a/arm/sys/SYS.h b/arm/sys/SYS.h new file mode 100644 index 0000000..1fdf570 --- /dev/null +++ b/arm/sys/SYS.h @@ -0,0 +1,206 @@ +/* + * Copyright (c) 1999-2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Header files. + */ +#import +#define SWI_SYSCALL 0x80 // from + +/* + * ARM system call interface: + * + * swi 0x80 + * args: r0-r6 + * return code: r0 + * on error, carry bit is set in the psr, otherwise carry bit is cleared. + */ + +/* + * Macros. + */ + +/* + * until we update the architecture project, these live here + */ + +#if defined(__DYNAMIC__) +#define MI_GET_ADDRESS(reg,var) \ + ldr reg, 4f ;\ +3: ldr reg, [pc, reg] ;\ + b 5f ;\ +4: .long 6f - (3b + 8) ;\ +5: ;\ + .non_lazy_symbol_pointer ;\ +6: ;\ + .indirect_symbol var ;\ + .long 0 ;\ + .text ;\ + .align 2 +#else +#define MI_GET_ADDRESS(reg,var) \ + ldr reg, 3f ;\ + b 4f ;\ +3: .long var ;\ +4: +#endif + +#if defined(__DYNAMIC__) +#define MI_BRANCH_EXTERNAL(var) \ + .globl var ;\ + MI_GET_ADDRESS(ip, var) ;\ + bx ip +#else +#define MI_BRANCH_EXTERNAL(var) ;\ + .globl var ;\ + b var +#endif + +#if defined(__DYNAMIC__) +#define MI_CALL_EXTERNAL(var) \ + .globl var ;\ + MI_GET_ADDRESS(ip,var) ;\ + mov lr, pc ;\ + bx ip +#else +#define MI_CALL_EXTERNAL(var) \ + .globl var ;\ + bl var +#endif + +#define MI_ENTRY_POINT(name) \ + .align 2 ;\ + .globl name ;\ + .text ;\ +name: + +/* load the syscall number into r12 and trap */ +#define DO_SYSCALL(num) \ + .if (((num) & 0xff) == (num)) ;\ + mov r12, #(num) ;\ + .elseif (((num) & 0x3fc) == (num)) ;\ + mov r12, #(num) ;\ + .else ;\ + mov r12, #((num) & 0xffffff00) /* top half of the syscall number */ ;\ + orr r12, r12, #((num) & 0xff) /* bottom half */ ;\ + .endif ;\ + swi #SWI_SYSCALL + +/* simple syscalls (0 to 4 args) */ +#define SYSCALL_0to4(name) \ + MI_ENTRY_POINT(_##name) ;\ + DO_SYSCALL(SYS_##name) ;\ + bxcc lr /* return if carry is clear (no error) */ ; \ +1: MI_BRANCH_EXTERNAL(cerror) + +/* syscalls with 5 args is different, because of the single arg register load */ +#define SYSCALL_5(name) \ + MI_ENTRY_POINT(_##name) ;\ + mov ip, sp /* save a pointer to the args */ ; \ + stmfd sp!, { r4-r5 } /* save r4-r5 */ ;\ + ldr r4, [ip] /* load 5th arg */ ; \ + DO_SYSCALL(SYS_##name) ;\ + ldmfd sp!, { r4-r5 } /* restore r4-r5 */ ; \ + bxcc lr /* return if carry is clear (no error) */ ; \ +1: MI_BRANCH_EXTERNAL(cerror) + +/* syscalls with 6 to 8 args */ +#define SYSCALL_6to8(name, save_regs, arg_regs) \ + MI_ENTRY_POINT(_##name) ;\ + mov ip, sp /* save a pointer to the args */ ; \ + stmfd sp!, { save_regs } /* callee saved regs */ ;\ + ldmia ip, { arg_regs } /* load arg regs */ ; \ + DO_SYSCALL(SYS_##name) ;\ + ldmfd sp!, { save_regs } /* restore callee saved regs */ ; \ + bxcc lr /* return if carry is clear (no error) */ ; \ +1: MI_BRANCH_EXTERNAL(cerror) + +#define COMMA , + +#define SYSCALL_0(name) SYSCALL_0to4(name) +#define SYSCALL_1(name) SYSCALL_0to4(name) +#define SYSCALL_2(name) SYSCALL_0to4(name) +#define SYSCALL_3(name) SYSCALL_0to4(name) +#define SYSCALL_4(name) SYSCALL_0to4(name) +/* SYSCALL_5 declared above */ +#define SYSCALL_6(name) SYSCALL_6to8(name, r4-r5, r4-r5) +#define SYSCALL_7(name) SYSCALL_6to8(name, r4-r6 COMMA r8, r4-r6) +/* there are no 8-argument syscalls currently defined */ + +/* select the appropriate syscall code, based on the number of arguments */ +#define SYSCALL(name, nargs) SYSCALL_##nargs(name) + +#define SYSCALL_NONAME_0to4(name) \ + DO_SYSCALL(SYS_##name) ;\ + bcc 1f /* branch if carry bit is clear (no error) */ ; \ + MI_BRANCH_EXTERNAL(cerror) /* call cerror */ ; \ +1: + +#define SYSCALL_NONAME_5(name) \ + mov ip, sp /* save a pointer to the args */ ; \ + stmfd sp!, { r4-r5 } /* save r4-r5 */ ;\ + ldr r4, [ip] /* load 5th arg */ ; \ + DO_SYSCALL(SYS_##name) ;\ + ldmfd sp!, { r4-r5 } /* restore r4-r7 */ ; \ + bcc 1f /* branch if carry bit is clear (no error) */ ; \ + MI_BRANCH_EXTERNAL(cerror) /* call cerror */ ; \ +1: + +#define SYSCALL_NONAME_6to8(name, save_regs, arg_regs) \ + mov ip, sp /* save a pointer to the args */ ; \ + stmfd sp!, { save_regs } /* callee save regs */ ;\ + ldmia ip, { arg_regs } /* load arguments */ ; \ + DO_SYSCALL(SYS_##name) ;\ + ldmfd sp!, { save_regs } /* restore callee saved regs */ ; \ + bcc 1f /* branch if carry bit is clear (no error) */ ; \ + MI_BRANCH_EXTERNAL(cerror) /* call cerror */ ; \ +1: + +#define SYSCALL_NONAME_0(name) SYSCALL_NONAME_0to4(name) +#define SYSCALL_NONAME_1(name) SYSCALL_NONAME_0to4(name) +#define SYSCALL_NONAME_2(name) SYSCALL_NONAME_0to4(name) +#define SYSCALL_NONAME_3(name) SYSCALL_NONAME_0to4(name) +#define SYSCALL_NONAME_4(name) SYSCALL_NONAME_0to4(name) +/* SYSCALL_NONAME_5 declared above */ +#define SYSCALL_NONAME_6(name) SYSCALL_NONAME_6to8(name, r4-r5, r4-r5) +#define SYSCALL_NONAME_7(name) SYSCALL_NONAME_6to8(name, r4-r6 COMMA r8, r4-r6) +/* there are no 8-argument syscalls currently defined */ + +/* select the appropriate syscall code, based on the number of arguments */ +#define SYSCALL_NONAME(name, nargs) SYSCALL_NONAME_##nargs(name) + +#define PSEUDO(pseudo, name, nargs) \ + .globl _##pseudo ;\ + .text ;\ + .align 2 ;\ +_##pseudo: ;\ + SYSCALL_NONAME(name, nargs) + +#undef END +#import + +#if !defined(SYS___pthread_canceled) +#define SYS___pthread_markcancel 332 +#define SYS___pthread_canceled 333 +#define SYS___semwait_signal 334 +#endif diff --git a/arm/sys/_longjmp.s b/arm/sys/_longjmp.s new file mode 100644 index 0000000..6aba768 --- /dev/null +++ b/arm/sys/_longjmp.s @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1999-2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. + * + * Implements _longjmp() + * + */ + +#include "SYS.h" +#include "_setjmp.h" +#include + +/* int _longjmp(jmp_buf env, int val); */ + +MI_ENTRY_POINT(__longjmp) + ldmia r0!, { r4-r8, r10-r11, sp, lr } +#ifdef _ARM_ARCH_6 + fldmiax r0, { d8-d15 } +#endif + movs r0, r1 + moveq r0, #1 + bx lr diff --git a/arm/sys/_setjmp.h b/arm/sys/_setjmp.h new file mode 100644 index 0000000..2c53d1a --- /dev/null +++ b/arm/sys/_setjmp.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1998, Apple Computer Inc. All rights reserved. + * + * File: _setjmp.h + * + * Defines for register offsets in the save area. + * + */ + +#if defined(__arm__) + +#define JMP_r4 0x00 +#define JMP_r5 0x04 +#define JMP_r6 0x08 +#define JMP_r7 0x0c +#define JMP_r8 0x10 +#define JMP_r10 0x14 +#define JMP_fp 0x18 +#define JMP_sp 0x1c +#define JMP_lr 0x20 + +#define JMP_VFP 0x24 + +#define JMP_sig 0x68 + +#define JMP_SIGFLAG 0x70 + +#else +#error architecture not supported +#endif diff --git a/arm/sys/_setjmp.s b/arm/sys/_setjmp.s new file mode 100644 index 0000000..23963b9 --- /dev/null +++ b/arm/sys/_setjmp.s @@ -0,0 +1,41 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. + * + * Implements _setjmp() + * + */ + +#include "SYS.h" +#include "_setjmp.h" +#include + +MI_ENTRY_POINT(__setjmp) + stmia r0!, { r4-r8, r10-r11, sp, lr } +#ifdef _ARM_ARCH_6 + fstmiax r0, { d8-d15 } +#endif + mov r0, #0 + bx lr diff --git a/arm/sys/arm_commpage_gettimeofday.c b/arm/sys/arm_commpage_gettimeofday.c new file mode 100644 index 0000000..1ba1813 --- /dev/null +++ b/arm/sys/arm_commpage_gettimeofday.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int __commpage_gettimeofday(struct timeval *); + + +#define TIME_ADD(rsecs, secs, rfrac, frac, unit) \ +{ \ + (rfrac) += (frac); \ + while ((rfrac) >= (unit)) { \ + (rfrac) -= (unit); \ + (rsecs) += 1; \ + } \ + (rsecs) += (secs); \ +} + + +int __commpage_gettimeofday(struct timeval *tp) { + commpage_timeofday_data_t *commpage_timeofday_datap; + uint64_t tbr; + uint64_t t64; + uint64_t TimeBase; + uint32_t TimeStamp_usec; + uint32_t TimeStamp_sec; + uint32_t TimeBaseTicks_per_sec; + uint64_t TimeBase_magic; + uint32_t TimeBase_add; + uint32_t TimeBase_shift; + uint32_t x, q; + + + commpage_timeofday_datap = (commpage_timeofday_data_t *)_COMM_PAGE_TIMEOFDAY_DATA; + + do { + TimeBase = commpage_timeofday_datap->TimeBase; + TimeStamp_sec = commpage_timeofday_datap->TimeStamp_sec; + TimeStamp_usec = commpage_timeofday_datap->TimeStamp_usec; + TimeBaseTicks_per_sec = commpage_timeofday_datap->TimeBaseTicks_per_sec; + TimeBase_magic = commpage_timeofday_datap->TimeBase_magic; + TimeBase_add = commpage_timeofday_datap->TimeBase_add; + TimeBase_shift = commpage_timeofday_datap->TimeBase_shift; + } while (TimeBase != commpage_timeofday_datap->TimeBase); + + if (TimeBase == 0) + return(1); + + tbr = mach_absolute_time(); + + t64 = tbr - TimeBase; + + if (t64 >= (uint64_t)TimeBaseTicks_per_sec) + return(1); + + x = (uint32_t)t64; + q = ((uint64_t)x * (uint32_t)(TimeBase_magic)) >> 32; + tp->tv_usec = TimeBase_add ? (((x - q) >> 1) + q) >> (TimeBase_shift - 1) : q >> TimeBase_shift; + tp->tv_sec = 0; + + TIME_ADD(tp->tv_sec, TimeStamp_sec, tp->tv_usec, TimeStamp_usec, USEC_PER_SEC); + + return(0); +} diff --git a/arm/sys/arm_gettimeofday.s b/arm/sys/arm_gettimeofday.s new file mode 100644 index 0000000..0de6710 --- /dev/null +++ b/arm/sys/arm_gettimeofday.s @@ -0,0 +1,35 @@ +/* + * Copyright (c) 1999-2005 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* Copyright 1998 Apple Computer, Inc. */ + +#include "SYS.h" + +/* + * This syscall is special cased: the timeval is returned in r0/r1. + */ +MI_ENTRY_POINT(___gettimeofday) + mov r3, r0 // save ptr to timeval + SYSCALL_NONAME(gettimeofday,2) + stmia r3, { r0, r1 } + mov r0, #0 + bx lr diff --git a/arm/sys/longjmp.s b/arm/sys/longjmp.s new file mode 100644 index 0000000..adfdf7f --- /dev/null +++ b/arm/sys/longjmp.s @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. + * + * File: sys/ppc/longjmp.s + * + * Implements siglongjmp(), longjmp(), _longjmp() + * + */ + +#include "SYS.h" +#include "_setjmp.h" + +/* + * longjmp routines + */ + +/* void siglongjmp(sigjmp_buf env, int val); */ + +MI_ENTRY_POINT(_siglongjmp) + ldr r2, [ r0, #JMP_SIGFLAG ] // load sigflag + tst r2, #0 // test if zero + beq L__exit // if zero do _longjmp() + // else *** fall through *** to longjmp() + +/* void longjmp(jmp_buf env, int val); */ + +MI_ENTRY_POINT(_longjmp) + mov r6, r0 // preserve args across _sigsetmask + mov r8, r1 + ldr r0, [ r0, #JMP_sig ] // restore the signal mask + MI_CALL_EXTERNAL(_sigsetmask) // make a (deprecated!) syscall to set the mask + mov r1, r8 + mov r0, r6 +L__exit: + MI_BRANCH_EXTERNAL(__longjmp) diff --git a/arm/sys/setjmp.s b/arm/sys/setjmp.s new file mode 100644 index 0000000..371ebaa --- /dev/null +++ b/arm/sys/setjmp.s @@ -0,0 +1,61 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. + * + * File: sys/ppc/setjmp.s + * + * Implements sigsetjmp(), setjmp(), _setjmp() + * + */ + +#include "SYS.h" +#include "_setjmp.h" + +/* + * setjmp routines + */ + +/* int sigsetjmp(sigjmp_buf env, int savemask); */ + +MI_ENTRY_POINT(_sigsetjmp) + str r1, [ r0, #JMP_SIGFLAG ] // save sigflag + tst r1, #0 // test if r1 is 0 + beq L__exit // if r1 == 0 do _setjmp() + // else *** fall through *** to setjmp() + +/* int setjmp(jmp_buf env); */ + +MI_ENTRY_POINT(_setjmp) + str lr, [ r0, #JMP_lr ] + str r8, [ r0, #JMP_r8 ] + mov r8, r0 + mov r0, #1 // get the previous signal mask + mov r1, #0 // + add r2, r8, #JMP_sig // get address where previous mask needs to be + MI_CALL_EXTERNAL(_sigprocmask) // make a syscall to get mask + mov r0, r8 // restore jmp_buf ptr + ldr r8, [ r0, #JMP_r8 ] + ldr lr, [ r0, #JMP_lr ] +L__exit: + MI_BRANCH_EXTERNAL(__setjmp) diff --git a/available.ex b/available.ex deleted file mode 100644 index 4221cf5..0000000 --- a/available.ex +++ /dev/null @@ -1,13 +0,0 @@ -g/AvailabilityMacros\.h/s//available.h/ -/Contains:/c - Contains: Double-underbar-prefixed availability macros, derived from - AvailabilityMacros.h -. -g/__AVAILABILITYMACROS__/s//_AVAILABLE_H_/ -g/\ -__FBSDID("$FreeBSD: src/lib/libc/compat-43/gethostid.c,v 1.3 2002/05/28 16:56:57 alfred Exp $"); - -#include -#include - -long -gethostid(void) -{ - int mib[2]; - size_t size; - long value; - - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTID; - size = sizeof value; - if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) - return (-1); - return (value); -} diff --git a/compat-43/gethostid-fbsd.c b/compat-43/gethostid-fbsd.c new file mode 120000 index 0000000..e66bc70 --- /dev/null +++ b/compat-43/gethostid-fbsd.c @@ -0,0 +1 @@ +./gethostid.c \ No newline at end of file diff --git a/compat-43/getwd-fbsd.c b/compat-43/getwd-fbsd.c deleted file mode 100644 index b15d2e2..0000000 --- a/compat-43/getwd-fbsd.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getwd.c 8.1 (Berkeley) 6/2/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/compat-43/getwd.c,v 1.3 2002/03/22 21:51:56 obrien Exp $"); - -#include -#include -#include -#include -#include - -char * -getwd(buf) - char *buf; -{ - char *p; - - if ( (p = getcwd(buf, MAXPATHLEN)) ) - return(p); - (void)strcpy(buf, strerror(errno)); - return((char *)NULL); -} diff --git a/compat-43/getwd-fbsd.c b/compat-43/getwd-fbsd.c new file mode 120000 index 0000000..cee67a2 --- /dev/null +++ b/compat-43/getwd-fbsd.c @@ -0,0 +1 @@ +./getwd.c \ No newline at end of file diff --git a/compat-43/sethostid-fbsd.c b/compat-43/sethostid-fbsd.c deleted file mode 100644 index a23ec8e..0000000 --- a/compat-43/sethostid-fbsd.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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[] = "@(#)sethostid.c 8.1 (Berkeley) 6/2/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/compat-43/sethostid.c,v 1.3 2002/05/28 16:56:57 alfred Exp $"); - -#include -#include - -long -sethostid(long hostid) -{ - int mib[2]; - - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTID; - if (sysctl(mib, 2, NULL, NULL, &hostid, sizeof hostid) == -1) - return (-1); - return (0); -} diff --git a/compat-43/sethostid-fbsd.c b/compat-43/sethostid-fbsd.c new file mode 120000 index 0000000..4754530 --- /dev/null +++ b/compat-43/sethostid-fbsd.c @@ -0,0 +1 @@ +./sethostid.c \ No newline at end of file diff --git a/compat-43/setrgid-fbsd.c b/compat-43/setrgid-fbsd.c deleted file mode 100644 index 360e562..0000000 --- a/compat-43/setrgid-fbsd.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)setrgid.c 8.1 (Berkeley) 6/2/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/compat-43/setrgid.c,v 1.3 2002/05/28 16:56:57 alfred Exp $"); - -#include - -int -setrgid(gid_t rgid) -{ - - return (setregid(rgid, -1)); -} diff --git a/compat-43/setrgid-fbsd.c b/compat-43/setrgid-fbsd.c new file mode 120000 index 0000000..5734593 --- /dev/null +++ b/compat-43/setrgid-fbsd.c @@ -0,0 +1 @@ +./setrgid.c \ No newline at end of file diff --git a/compat-43/setruid-fbsd.c b/compat-43/setruid-fbsd.c deleted file mode 100644 index 5fb6d60..0000000 --- a/compat-43/setruid-fbsd.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)setruid.c 8.1 (Berkeley) 6/2/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/compat-43/setruid.c,v 1.3 2002/05/28 16:56:57 alfred Exp $"); - -#include - -int -setruid(uid_t ruid) -{ - - return (setreuid(ruid, -1)); -} diff --git a/compat-43/setruid-fbsd.c b/compat-43/setruid-fbsd.c new file mode 120000 index 0000000..b76fe9c --- /dev/null +++ b/compat-43/setruid-fbsd.c @@ -0,0 +1 @@ +./setruid.c \ No newline at end of file diff --git a/darwin/Makefile.inc b/darwin/Makefile.inc index a0c9e99..a72b3be 100644 --- a/darwin/Makefile.inc +++ b/darwin/Makefile.inc @@ -1,10 +1,6 @@ .PATH: ${.CURDIR}/darwin -.ifnmake autopatch -.if exists(${.CURDIR}/${MACHINE_ARCH}/darwin/Makefile.inc) -.include "${.CURDIR}/${MACHINE_ARCH}/darwin/Makefile.inc" -.endif -.endif # !autopatch +.sinclude "${.CURDIR}/${MACHINE_ARCH}/darwin/Makefile.inc" DARWINMIGDEFS += dirhelper.defs DARWINMIGHDRS += ${DARWINMIGDEFS:.defs=.h} @@ -22,7 +18,6 @@ MISRCS += kvm.c MKGetTimeBaseInfo.c .endif # force building of the mig stuff before _dirhelper.c -_dirhelper.So _dirhelper.po _dirhelper.do _dirhelper.o: dirhelperUser.c +_dirhelper.${OBJSUFFIX}: dirhelperUser.c -CFLAGS-_dirhelper.c += -I${OBJROOT} CFLAGS-proc_listpidspath.c += -I${.CURDIR}/darwin diff --git a/db/Makefile.inc b/db/Makefile.inc index 1be825e..39357c7 100644 --- a/db/Makefile.inc +++ b/db/Makefile.inc @@ -2,11 +2,9 @@ # $FreeBSD: src/lib/libc/db/Makefile.inc,v 1.4 2002/11/18 09:50:54 ru Exp $ # -.ifnmake autopatch .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" -.endif # !autopatch diff --git a/db/btree/Makefile.inc b/db/btree/Makefile.inc index d294367..1d340f7 100644 --- a/db/btree/Makefile.inc +++ b/db/btree/Makefile.inc @@ -2,6 +2,7 @@ # $FreeBSD: src/lib/libc/db/btree/Makefile.inc,v 1.4 2002/11/18 09:50:54 ru Exp $ .PATH: ${.CURDIR}/db/btree +CWD := ${.CURDIR}/db/btree .include "Makefile.fbsd_begin" FBSDMISRCS= bt_close.c bt_conv.c bt_debug.c bt_delete.c bt_get.c bt_open.c \ @@ -16,10 +17,15 @@ CFLAGS-${_src:R}-fbsd.${_src:E} += -UDEBUG FBSDHDRS= btree.h .include "Makefile.fbsd_end" +# This .for statement forces evaluation of ${CWD} +.for _cwd in ${CWD} + # need to rename extern.h to make it unique .ifmake autopatch -bt_extern.h: FreeBSD/extern.h _AUTOPATCHCUR -AUTOPATCHHDRS+= bt_extern.h +${_cwd}/bt_extern.h: ${_cwd}/FreeBSD/extern.h _AUTOPATCH +AUTOPATCHHDRS+= ${_cwd}/bt_extern.h .endif # autopatch -INSTBTREEPRIVHDRS_AUTOPATCH+= ${.CURDIR}/db/btree/bt_extern.h ${.CURDIR}/db/btree/btree.h +INSTBTREEPRIVHDRS_AUTOPATCH+= ${_cwd}/bt_extern.h ${_cwd}/btree.h + +.endfor # _cwd diff --git a/db/btree/bt_close-fbsd.c b/db/btree/bt_close-fbsd.c deleted file mode 100644 index c211d5b..0000000 --- a/db/btree/bt_close-fbsd.c +++ /dev/null @@ -1,186 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_close.c 8.7 (Berkeley) 8/17/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_close.c,v 1.8 2002/03/22 21:52:00 obrien Exp $"); - -#include "namespace.h" -#include - -#include -#include -#include -#include -#include -#include "un-namespace.h" - -#include -#include "btree.h" - -static int bt_meta(BTREE *); - -/* - * BT_CLOSE -- Close a btree. - * - * Parameters: - * dbp: pointer to access method - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__bt_close(dbp) - DB *dbp; -{ - BTREE *t; - int fd; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* Sync the tree. */ - if (__bt_sync(dbp, 0) == RET_ERROR) - return (RET_ERROR); - - /* Close the memory pool. */ - if (mpool_close(t->bt_mp) == RET_ERROR) - return (RET_ERROR); - - /* Free random memory. */ - if (t->bt_cursor.key.data != NULL) { - free(t->bt_cursor.key.data); - t->bt_cursor.key.size = 0; - t->bt_cursor.key.data = NULL; - } - if (t->bt_rkey.data) { - free(t->bt_rkey.data); - t->bt_rkey.size = 0; - t->bt_rkey.data = NULL; - } - if (t->bt_rdata.data) { - free(t->bt_rdata.data); - t->bt_rdata.size = 0; - t->bt_rdata.data = NULL; - } - - fd = t->bt_fd; - free(t); - free(dbp); - return (_close(fd) ? RET_ERROR : RET_SUCCESS); -} - -/* - * BT_SYNC -- sync the btree to disk. - * - * Parameters: - * dbp: pointer to access method - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__bt_sync(dbp, flags) - const DB *dbp; - u_int flags; -{ - BTREE *t; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* Sync doesn't currently take any flags. */ - if (flags != 0) { - errno = EINVAL; - return (RET_ERROR); - } - - if (F_ISSET(t, B_INMEM | B_RDONLY) || !F_ISSET(t, B_MODIFIED)) - return (RET_SUCCESS); - - if (F_ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR) - return (RET_ERROR); - - if ((status = mpool_sync(t->bt_mp)) == RET_SUCCESS) - F_CLR(t, B_MODIFIED); - - return (status); -} - -/* - * BT_META -- write the tree meta data to disk. - * - * Parameters: - * t: tree - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -static int -bt_meta(t) - BTREE *t; -{ - BTMETA m; - void *p; - - if ((p = mpool_get(t->bt_mp, P_META, 0)) == NULL) - return (RET_ERROR); - - /* Fill in metadata. */ - m.magic = BTREEMAGIC; - m.version = BTREEVERSION; - m.psize = t->bt_psize; - m.free = t->bt_free; - m.nrecs = t->bt_nrecs; - m.flags = F_ISSET(t, SAVEMETA); - - memmove(p, &m, sizeof(BTMETA)); - mpool_put(t->bt_mp, p, MPOOL_DIRTY); - return (RET_SUCCESS); -} diff --git a/db/btree/bt_close-fbsd.c b/db/btree/bt_close-fbsd.c new file mode 120000 index 0000000..445d433 --- /dev/null +++ b/db/btree/bt_close-fbsd.c @@ -0,0 +1 @@ +./bt_close.c \ No newline at end of file diff --git a/db/btree/bt_conv-fbsd.c b/db/btree/bt_conv-fbsd.c deleted file mode 100644 index 7496a3c..0000000 --- a/db/btree/bt_conv-fbsd.c +++ /dev/null @@ -1,223 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_conv.c 8.5 (Berkeley) 8/17/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_conv.c,v 1.2 2002/03/21 22:46:25 obrien Exp $"); - -#include - -#include - -#include -#include "btree.h" - -static void mswap(PAGE *); - -/* - * __BT_BPGIN, __BT_BPGOUT -- - * Convert host-specific number layout to/from the host-independent - * format stored on disk. - * - * Parameters: - * t: tree - * pg: page number - * h: page to convert - */ -void -__bt_pgin(t, pg, pp) - void *t; - pgno_t pg; - void *pp; -{ - PAGE *h; - indx_t i, top; - u_char flags; - char *p; - - if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)) - return; - if (pg == P_META) { - mswap(pp); - return; - } - - h = pp; - M_32_SWAP(h->pgno); - M_32_SWAP(h->prevpg); - M_32_SWAP(h->nextpg); - M_32_SWAP(h->flags); - M_16_SWAP(h->lower); - M_16_SWAP(h->upper); - - top = NEXTINDEX(h); - if ((h->flags & P_TYPE) == P_BINTERNAL) - for (i = 0; i < top; i++) { - M_16_SWAP(h->linp[i]); - p = (char *)GETBINTERNAL(h, i); - P_32_SWAP(p); - p += sizeof(u_int32_t); - P_32_SWAP(p); - p += sizeof(pgno_t); - if (*(u_char *)p & P_BIGKEY) { - p += sizeof(u_char); - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - } - else if ((h->flags & P_TYPE) == P_BLEAF) - for (i = 0; i < top; i++) { - M_16_SWAP(h->linp[i]); - p = (char *)GETBLEAF(h, i); - P_32_SWAP(p); - p += sizeof(u_int32_t); - P_32_SWAP(p); - p += sizeof(u_int32_t); - flags = *(u_char *)p; - if (flags & (P_BIGKEY | P_BIGDATA)) { - p += sizeof(u_char); - if (flags & P_BIGKEY) { - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - if (flags & P_BIGDATA) { - p += sizeof(u_int32_t); - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - } - } -} - -void -__bt_pgout(t, pg, pp) - void *t; - pgno_t pg; - void *pp; -{ - PAGE *h; - indx_t i, top; - u_char flags; - char *p; - - if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)) - return; - if (pg == P_META) { - mswap(pp); - return; - } - - h = pp; - top = NEXTINDEX(h); - if ((h->flags & P_TYPE) == P_BINTERNAL) - for (i = 0; i < top; i++) { - p = (char *)GETBINTERNAL(h, i); - P_32_SWAP(p); - p += sizeof(u_int32_t); - P_32_SWAP(p); - p += sizeof(pgno_t); - if (*(u_char *)p & P_BIGKEY) { - p += sizeof(u_char); - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - M_16_SWAP(h->linp[i]); - } - else if ((h->flags & P_TYPE) == P_BLEAF) - for (i = 0; i < top; i++) { - p = (char *)GETBLEAF(h, i); - P_32_SWAP(p); - p += sizeof(u_int32_t); - P_32_SWAP(p); - p += sizeof(u_int32_t); - flags = *(u_char *)p; - if (flags & (P_BIGKEY | P_BIGDATA)) { - p += sizeof(u_char); - if (flags & P_BIGKEY) { - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - if (flags & P_BIGDATA) { - p += sizeof(u_int32_t); - P_32_SWAP(p); - p += sizeof(pgno_t); - P_32_SWAP(p); - } - } - M_16_SWAP(h->linp[i]); - } - - M_32_SWAP(h->pgno); - M_32_SWAP(h->prevpg); - M_32_SWAP(h->nextpg); - M_32_SWAP(h->flags); - M_16_SWAP(h->lower); - M_16_SWAP(h->upper); -} - -/* - * MSWAP -- Actually swap the bytes on the meta page. - * - * Parameters: - * p: page to convert - */ -static void -mswap(pg) - PAGE *pg; -{ - char *p; - - p = (char *)pg; - P_32_SWAP(p); /* magic */ - p += sizeof(u_int32_t); - P_32_SWAP(p); /* version */ - p += sizeof(u_int32_t); - P_32_SWAP(p); /* psize */ - p += sizeof(u_int32_t); - P_32_SWAP(p); /* free */ - p += sizeof(u_int32_t); - P_32_SWAP(p); /* nrecs */ - p += sizeof(u_int32_t); - P_32_SWAP(p); /* flags */ - p += sizeof(u_int32_t); -} diff --git a/db/btree/bt_conv-fbsd.c b/db/btree/bt_conv-fbsd.c new file mode 120000 index 0000000..4ecb6ae --- /dev/null +++ b/db/btree/bt_conv-fbsd.c @@ -0,0 +1 @@ +./bt_conv.c \ No newline at end of file diff --git a/db/btree/bt_debug-fbsd.c b/db/btree/bt_debug-fbsd.c deleted file mode 100644 index bd95774..0000000 --- a/db/btree/bt_debug-fbsd.c +++ /dev/null @@ -1,332 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_debug.c 8.5 (Berkeley) 8/17/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_debug.c,v 1.3 2004/09/10 05:41:41 kuriyama Exp $"); - -#include - -#include -#include -#include - -#include -#include "btree.h" - -#ifdef DEBUG -/* - * BT_DUMP -- Dump the tree - * - * Parameters: - * dbp: pointer to the DB - */ -void -__bt_dump(dbp) - DB *dbp; -{ - BTREE *t; - PAGE *h; - pgno_t i; - char *sep; - - t = dbp->internal; - (void)fprintf(stderr, "%s: pgsz %d", - F_ISSET(t, B_INMEM) ? "memory" : "disk", t->bt_psize); - if (F_ISSET(t, R_RECNO)) - (void)fprintf(stderr, " keys %u", t->bt_nrecs); -#undef X -#define X(flag, name) \ - if (F_ISSET(t, flag)) { \ - (void)fprintf(stderr, "%s%s", sep, name); \ - sep = ", "; \ - } - if (t->flags != 0) { - sep = " flags ("; - X(R_FIXLEN, "FIXLEN"); - X(B_INMEM, "INMEM"); - X(B_NODUPS, "NODUPS"); - X(B_RDONLY, "RDONLY"); - X(R_RECNO, "RECNO"); - X(B_METADIRTY,"METADIRTY"); - (void)fprintf(stderr, ")\n"); - } -#undef X - - for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) { - __bt_dpage(h); - (void)mpool_put(t->bt_mp, h, 0); - } -} - -/* - * BT_DMPAGE -- Dump the meta page - * - * Parameters: - * h: pointer to the PAGE - */ -void -__bt_dmpage(h) - PAGE *h; -{ - BTMETA *m; - char *sep; - - m = (BTMETA *)h; - (void)fprintf(stderr, "magic %x\n", m->magic); - (void)fprintf(stderr, "version %u\n", m->version); - (void)fprintf(stderr, "psize %u\n", m->psize); - (void)fprintf(stderr, "free %u\n", m->free); - (void)fprintf(stderr, "nrecs %u\n", m->nrecs); - (void)fprintf(stderr, "flags %u", m->flags); -#undef X -#define X(flag, name) \ - if (m->flags & flag) { \ - (void)fprintf(stderr, "%s%s", sep, name); \ - sep = ", "; \ - } - if (m->flags) { - sep = " ("; - X(B_NODUPS, "NODUPS"); - X(R_RECNO, "RECNO"); - (void)fprintf(stderr, ")"); - } -} - -/* - * BT_DNPAGE -- Dump the page - * - * Parameters: - * n: page number to dump. - */ -void -__bt_dnpage(dbp, pgno) - DB *dbp; - pgno_t pgno; -{ - BTREE *t; - PAGE *h; - - t = dbp->internal; - if ((h = mpool_get(t->bt_mp, pgno, 0)) != NULL) { - __bt_dpage(h); - (void)mpool_put(t->bt_mp, h, 0); - } -} - -/* - * BT_DPAGE -- Dump the page - * - * Parameters: - * h: pointer to the PAGE - */ -void -__bt_dpage(h) - PAGE *h; -{ - BINTERNAL *bi; - BLEAF *bl; - RINTERNAL *ri; - RLEAF *rl; - indx_t cur, top; - char *sep; - - (void)fprintf(stderr, " page %d: (", h->pgno); -#undef X -#define X(flag, name) \ - if (h->flags & flag) { \ - (void)fprintf(stderr, "%s%s", sep, name); \ - sep = ", "; \ - } - sep = ""; - X(P_BINTERNAL, "BINTERNAL") /* types */ - X(P_BLEAF, "BLEAF") - X(P_RINTERNAL, "RINTERNAL") /* types */ - X(P_RLEAF, "RLEAF") - X(P_OVERFLOW, "OVERFLOW") - X(P_PRESERVE, "PRESERVE"); - (void)fprintf(stderr, ")\n"); -#undef X - - (void)fprintf(stderr, "\tprev %2d next %2d", h->prevpg, h->nextpg); - if (h->flags & P_OVERFLOW) - return; - - top = NEXTINDEX(h); - (void)fprintf(stderr, " lower %3d upper %3d nextind %d\n", - h->lower, h->upper, top); - for (cur = 0; cur < top; cur++) { - (void)fprintf(stderr, "\t[%03d] %4d ", cur, h->linp[cur]); - switch (h->flags & P_TYPE) { - case P_BINTERNAL: - bi = GETBINTERNAL(h, cur); - (void)fprintf(stderr, - "size %03d pgno %03d", bi->ksize, bi->pgno); - if (bi->flags & P_BIGKEY) - (void)fprintf(stderr, " (indirect)"); - else if (bi->ksize) - (void)fprintf(stderr, - " {%.*s}", (int)bi->ksize, bi->bytes); - break; - case P_RINTERNAL: - ri = GETRINTERNAL(h, cur); - (void)fprintf(stderr, "entries %03d pgno %03d", - ri->nrecs, ri->pgno); - break; - case P_BLEAF: - bl = GETBLEAF(h, cur); - if (bl->flags & P_BIGKEY) - (void)fprintf(stderr, - "big key page %u size %u/", - *(pgno_t *)bl->bytes, - *(u_int32_t *)(bl->bytes + sizeof(pgno_t))); - else if (bl->ksize) - (void)fprintf(stderr, "%.*s/", - bl->ksize, bl->bytes); - if (bl->flags & P_BIGDATA) - (void)fprintf(stderr, - "big data page %u size %u", - *(pgno_t *)(bl->bytes + bl->ksize), - *(u_int32_t *)(bl->bytes + bl->ksize + - sizeof(pgno_t))); - else if (bl->dsize) - (void)fprintf(stderr, "%.*s", - (int)bl->dsize, bl->bytes + bl->ksize); - break; - case P_RLEAF: - rl = GETRLEAF(h, cur); - if (rl->flags & P_BIGDATA) - (void)fprintf(stderr, - "big data page %u size %u", - *(pgno_t *)rl->bytes, - *(u_int32_t *)(rl->bytes + sizeof(pgno_t))); - else if (rl->dsize) - (void)fprintf(stderr, - "%.*s", (int)rl->dsize, rl->bytes); - break; - } - (void)fprintf(stderr, "\n"); - } -} -#endif - -#ifdef STATISTICS -/* - * BT_STAT -- Gather/print the tree statistics - * - * Parameters: - * dbp: pointer to the DB - */ -void -__bt_stat(dbp) - DB *dbp; -{ - extern u_long bt_cache_hit, bt_cache_miss, bt_pfxsaved, bt_rootsplit; - extern u_long bt_sortsplit, bt_split; - BTREE *t; - PAGE *h; - pgno_t i, pcont, pinternal, pleaf; - u_long ifree, lfree, nkeys; - int levels; - - t = dbp->internal; - pcont = pinternal = pleaf = 0; - nkeys = ifree = lfree = 0; - for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) { - switch (h->flags & P_TYPE) { - case P_BINTERNAL: - case P_RINTERNAL: - ++pinternal; - ifree += h->upper - h->lower; - break; - case P_BLEAF: - case P_RLEAF: - ++pleaf; - lfree += h->upper - h->lower; - nkeys += NEXTINDEX(h); - break; - case P_OVERFLOW: - ++pcont; - break; - } - (void)mpool_put(t->bt_mp, h, 0); - } - - /* Count the levels of the tree. */ - for (i = P_ROOT, levels = 0 ;; ++levels) { - h = mpool_get(t->bt_mp, i, 0); - if (h->flags & (P_BLEAF|P_RLEAF)) { - if (levels == 0) - levels = 1; - (void)mpool_put(t->bt_mp, h, 0); - break; - } - i = F_ISSET(t, R_RECNO) ? - GETRINTERNAL(h, 0)->pgno : - GETBINTERNAL(h, 0)->pgno; - (void)mpool_put(t->bt_mp, h, 0); - } - - (void)fprintf(stderr, "%d level%s with %ld keys", - levels, levels == 1 ? "" : "s", nkeys); - if (F_ISSET(t, R_RECNO)) - (void)fprintf(stderr, " (%d header count)", t->bt_nrecs); - (void)fprintf(stderr, - "\n%u pages (leaf %d, internal %d, overflow %d)\n", - pinternal + pleaf + pcont, pleaf, pinternal, pcont); - (void)fprintf(stderr, "%ld cache hits, %ld cache misses\n", - bt_cache_hit, bt_cache_miss); - (void)fprintf(stderr, "%lu splits (%lu root splits, %lu sort splits)\n", - bt_split, bt_rootsplit, bt_sortsplit); - pleaf *= t->bt_psize - BTDATAOFF; - if (pleaf) - (void)fprintf(stderr, - "%.0f%% leaf fill (%ld bytes used, %ld bytes free)\n", - ((double)(pleaf - lfree) / pleaf) * 100, - pleaf - lfree, lfree); - pinternal *= t->bt_psize - BTDATAOFF; - if (pinternal) - (void)fprintf(stderr, - "%.0f%% internal fill (%ld bytes used, %ld bytes free\n", - ((double)(pinternal - ifree) / pinternal) * 100, - pinternal - ifree, ifree); - if (bt_pfxsaved) - (void)fprintf(stderr, "prefix checking removed %lu bytes.\n", - bt_pfxsaved); -} -#endif diff --git a/db/btree/bt_debug-fbsd.c b/db/btree/bt_debug-fbsd.c new file mode 120000 index 0000000..a98b043 --- /dev/null +++ b/db/btree/bt_debug-fbsd.c @@ -0,0 +1 @@ +./bt_debug.c \ No newline at end of file diff --git a/db/btree/bt_delete-fbsd.c b/db/btree/bt_delete-fbsd.c deleted file mode 100644 index 6204464..0000000 --- a/db/btree/bt_delete-fbsd.c +++ /dev/null @@ -1,659 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_delete.c 8.13 (Berkeley) 7/28/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_delete.c,v 1.2 2002/03/21 22:46:25 obrien Exp $"); - -#include - -#include -#include -#include - -#include -#include "btree.h" - -static int __bt_bdelete(BTREE *, const DBT *); -static int __bt_curdel(BTREE *, const DBT *, PAGE *, u_int); -static int __bt_pdelete(BTREE *, PAGE *); -static int __bt_relink(BTREE *, PAGE *); -static int __bt_stkacq(BTREE *, PAGE **, CURSOR *); - -/* - * __bt_delete - * Delete the item(s) referenced by a key. - * - * Return RET_SPECIAL if the key is not found. - */ -int -__bt_delete(dbp, key, flags) - const DB *dbp; - const DBT *key; - u_int flags; -{ - BTREE *t; - CURSOR *c; - PAGE *h; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* Check for change to a read-only tree. */ - if (F_ISSET(t, B_RDONLY)) { - errno = EPERM; - return (RET_ERROR); - } - - switch (flags) { - case 0: - status = __bt_bdelete(t, key); - break; - case R_CURSOR: - /* - * If flags is R_CURSOR, delete the cursor. Must already - * have started a scan and not have already deleted it. - */ - c = &t->bt_cursor; - if (F_ISSET(c, CURS_INIT)) { - if (F_ISSET(c, CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE)) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL) - return (RET_ERROR); - - /* - * If the page is about to be emptied, we'll need to - * delete it, which means we have to acquire a stack. - */ - if (NEXTINDEX(h) == 1) - if (__bt_stkacq(t, &h, &t->bt_cursor)) - return (RET_ERROR); - - status = __bt_dleaf(t, NULL, h, c->pg.index); - - if (NEXTINDEX(h) == 0 && status == RET_SUCCESS) { - if (__bt_pdelete(t, h)) - return (RET_ERROR); - } else - mpool_put(t->bt_mp, - h, status == RET_SUCCESS ? MPOOL_DIRTY : 0); - break; - } - /* FALLTHROUGH */ - default: - errno = EINVAL; - return (RET_ERROR); - } - if (status == RET_SUCCESS) - F_SET(t, B_MODIFIED); - return (status); -} - -/* - * __bt_stkacq -- - * Acquire a stack so we can delete a cursor entry. - * - * Parameters: - * t: tree - * hp: pointer to current, pinned PAGE pointer - * c: pointer to the cursor - * - * Returns: - * 0 on success, 1 on failure - */ -static int -__bt_stkacq(t, hp, c) - BTREE *t; - PAGE **hp; - CURSOR *c; -{ - BINTERNAL *bi; - EPG *e; - EPGNO *parent; - PAGE *h; - indx_t index; - pgno_t pgno; - recno_t nextpg, prevpg; - int exact, level; - - /* - * Find the first occurrence of the key in the tree. Toss the - * currently locked page so we don't hit an already-locked page. - */ - h = *hp; - mpool_put(t->bt_mp, h, 0); - if ((e = __bt_search(t, &c->key, &exact)) == NULL) - return (1); - h = e->page; - - /* See if we got it in one shot. */ - if (h->pgno == c->pg.pgno) - goto ret; - - /* - * Move right, looking for the page. At each move we have to move - * up the stack until we don't have to move to the next page. If - * we have to change pages at an internal level, we have to fix the - * stack back up. - */ - while (h->pgno != c->pg.pgno) { - if ((nextpg = h->nextpg) == P_INVALID) - break; - mpool_put(t->bt_mp, h, 0); - - /* Move up the stack. */ - for (level = 0; (parent = BT_POP(t)) != NULL; ++level) { - /* Get the parent page. */ - if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) - return (1); - - /* Move to the next index. */ - if (parent->index != NEXTINDEX(h) - 1) { - index = parent->index + 1; - BT_PUSH(t, h->pgno, index); - break; - } - mpool_put(t->bt_mp, h, 0); - } - - /* Restore the stack. */ - while (level--) { - /* Push the next level down onto the stack. */ - bi = GETBINTERNAL(h, index); - pgno = bi->pgno; - BT_PUSH(t, pgno, 0); - - /* Lose the currently pinned page. */ - mpool_put(t->bt_mp, h, 0); - - /* Get the next level down. */ - if ((h = mpool_get(t->bt_mp, pgno, 0)) == NULL) - return (1); - index = 0; - } - mpool_put(t->bt_mp, h, 0); - if ((h = mpool_get(t->bt_mp, nextpg, 0)) == NULL) - return (1); - } - - if (h->pgno == c->pg.pgno) - goto ret; - - /* Reacquire the original stack. */ - mpool_put(t->bt_mp, h, 0); - if ((e = __bt_search(t, &c->key, &exact)) == NULL) - return (1); - h = e->page; - - /* - * Move left, looking for the page. At each move we have to move - * up the stack until we don't have to change pages to move to the - * next page. If we have to change pages at an internal level, we - * have to fix the stack back up. - */ - while (h->pgno != c->pg.pgno) { - if ((prevpg = h->prevpg) == P_INVALID) - break; - mpool_put(t->bt_mp, h, 0); - - /* Move up the stack. */ - for (level = 0; (parent = BT_POP(t)) != NULL; ++level) { - /* Get the parent page. */ - if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) - return (1); - - /* Move to the next index. */ - if (parent->index != 0) { - index = parent->index - 1; - BT_PUSH(t, h->pgno, index); - break; - } - mpool_put(t->bt_mp, h, 0); - } - - /* Restore the stack. */ - while (level--) { - /* Push the next level down onto the stack. */ - bi = GETBINTERNAL(h, index); - pgno = bi->pgno; - - /* Lose the currently pinned page. */ - mpool_put(t->bt_mp, h, 0); - - /* Get the next level down. */ - if ((h = mpool_get(t->bt_mp, pgno, 0)) == NULL) - return (1); - - index = NEXTINDEX(h) - 1; - BT_PUSH(t, pgno, index); - } - mpool_put(t->bt_mp, h, 0); - if ((h = mpool_get(t->bt_mp, prevpg, 0)) == NULL) - return (1); - } - - -ret: mpool_put(t->bt_mp, h, 0); - return ((*hp = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL); -} - -/* - * __bt_bdelete -- - * Delete all key/data pairs matching the specified key. - * - * Parameters: - * t: tree - * key: key to delete - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -static int -__bt_bdelete(t, key) - BTREE *t; - const DBT *key; -{ - EPG *e; - PAGE *h; - int deleted, exact, redo; - - deleted = 0; - - /* Find any matching record; __bt_search pins the page. */ -loop: if ((e = __bt_search(t, key, &exact)) == NULL) - return (deleted ? RET_SUCCESS : RET_ERROR); - if (!exact) { - mpool_put(t->bt_mp, e->page, 0); - return (deleted ? RET_SUCCESS : RET_SPECIAL); - } - - /* - * Delete forward, then delete backward, from the found key. If - * there are duplicates and we reach either side of the page, do - * the key search again, so that we get them all. - */ - redo = 0; - h = e->page; - do { - if (__bt_dleaf(t, key, h, e->index)) { - mpool_put(t->bt_mp, h, 0); - return (RET_ERROR); - } - if (F_ISSET(t, B_NODUPS)) { - if (NEXTINDEX(h) == 0) { - if (__bt_pdelete(t, h)) - return (RET_ERROR); - } else - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - return (RET_SUCCESS); - } - deleted = 1; - } while (e->index < NEXTINDEX(h) && __bt_cmp(t, key, e) == 0); - - /* Check for right-hand edge of the page. */ - if (e->index == NEXTINDEX(h)) - redo = 1; - - /* Delete from the key to the beginning of the page. */ - while (e->index-- > 0) { - if (__bt_cmp(t, key, e) != 0) - break; - if (__bt_dleaf(t, key, h, e->index) == RET_ERROR) { - mpool_put(t->bt_mp, h, 0); - return (RET_ERROR); - } - if (e->index == 0) - redo = 1; - } - - /* Check for an empty page. */ - if (NEXTINDEX(h) == 0) { - if (__bt_pdelete(t, h)) - return (RET_ERROR); - goto loop; - } - - /* Put the page. */ - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - - if (redo) - goto loop; - return (RET_SUCCESS); -} - -/* - * __bt_pdelete -- - * Delete a single page from the tree. - * - * Parameters: - * t: tree - * h: leaf page - * - * Returns: - * RET_SUCCESS, RET_ERROR. - * - * Side-effects: - * mpool_put's the page - */ -static int -__bt_pdelete(t, h) - BTREE *t; - PAGE *h; -{ - BINTERNAL *bi; - PAGE *pg; - EPGNO *parent; - indx_t cnt, index, *ip, offset; - u_int32_t nksize; - char *from; - - /* - * Walk the parent page stack -- a LIFO stack of the pages that were - * traversed when we searched for the page where the delete occurred. - * Each stack entry is a page number and a page index offset. The - * offset is for the page traversed on the search. We've just deleted - * a page, so we have to delete the key from the parent page. - * - * If the delete from the parent page makes it empty, this process may - * continue all the way up the tree. We stop if we reach the root page - * (which is never deleted, it's just not worth the effort) or if the - * delete does not empty the page. - */ - while ((parent = BT_POP(t)) != NULL) { - /* Get the parent page. */ - if ((pg = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) - return (RET_ERROR); - - index = parent->index; - bi = GETBINTERNAL(pg, index); - - /* Free any overflow pages. */ - if (bi->flags & P_BIGKEY && - __ovfl_delete(t, bi->bytes) == RET_ERROR) { - mpool_put(t->bt_mp, pg, 0); - return (RET_ERROR); - } - - /* - * Free the parent if it has only the one key and it's not the - * root page. If it's the rootpage, turn it back into an empty - * leaf page. - */ - if (NEXTINDEX(pg) == 1) - if (pg->pgno == P_ROOT) { - pg->lower = BTDATAOFF; - pg->upper = t->bt_psize; - pg->flags = P_BLEAF; - } else { - if (__bt_relink(t, pg) || __bt_free(t, pg)) - return (RET_ERROR); - continue; - } - else { - /* Pack remaining key items at the end of the page. */ - nksize = NBINTERNAL(bi->ksize); - from = (char *)pg + pg->upper; - memmove(from + nksize, from, (char *)bi - from); - pg->upper += nksize; - - /* Adjust indices' offsets, shift the indices down. */ - offset = pg->linp[index]; - for (cnt = index, ip = &pg->linp[0]; cnt--; ++ip) - if (ip[0] < offset) - ip[0] += nksize; - for (cnt = NEXTINDEX(pg) - index; --cnt; ++ip) - ip[0] = ip[1] < offset ? ip[1] + nksize : ip[1]; - pg->lower -= sizeof(indx_t); - } - - mpool_put(t->bt_mp, pg, MPOOL_DIRTY); - break; - } - - /* Free the leaf page, as long as it wasn't the root. */ - if (h->pgno == P_ROOT) { - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - return (RET_SUCCESS); - } - return (__bt_relink(t, h) || __bt_free(t, h)); -} - -/* - * __bt_dleaf -- - * Delete a single record from a leaf page. - * - * Parameters: - * t: tree - * key: referenced key - * h: page - * index: index on page to delete - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__bt_dleaf(t, key, h, index) - BTREE *t; - const DBT *key; - PAGE *h; - u_int index; -{ - BLEAF *bl; - indx_t cnt, *ip, offset; - u_int32_t nbytes; - void *to; - char *from; - - /* If this record is referenced by the cursor, delete the cursor. */ - if (F_ISSET(&t->bt_cursor, CURS_INIT) && - !F_ISSET(&t->bt_cursor, CURS_ACQUIRE) && - t->bt_cursor.pg.pgno == h->pgno && t->bt_cursor.pg.index == index && - __bt_curdel(t, key, h, index)) - return (RET_ERROR); - - /* If the entry uses overflow pages, make them available for reuse. */ - to = bl = GETBLEAF(h, index); - if (bl->flags & P_BIGKEY && __ovfl_delete(t, bl->bytes) == RET_ERROR) - return (RET_ERROR); - if (bl->flags & P_BIGDATA && - __ovfl_delete(t, bl->bytes + bl->ksize) == RET_ERROR) - return (RET_ERROR); - - /* Pack the remaining key/data items at the end of the page. */ - nbytes = NBLEAF(bl); - from = (char *)h + h->upper; - memmove(from + nbytes, from, (char *)to - from); - h->upper += nbytes; - - /* Adjust the indices' offsets, shift the indices down. */ - offset = h->linp[index]; - for (cnt = index, ip = &h->linp[0]; cnt--; ++ip) - if (ip[0] < offset) - ip[0] += nbytes; - for (cnt = NEXTINDEX(h) - index; --cnt; ++ip) - ip[0] = ip[1] < offset ? ip[1] + nbytes : ip[1]; - h->lower -= sizeof(indx_t); - - /* If the cursor is on this page, adjust it as necessary. */ - if (F_ISSET(&t->bt_cursor, CURS_INIT) && - !F_ISSET(&t->bt_cursor, CURS_ACQUIRE) && - t->bt_cursor.pg.pgno == h->pgno && t->bt_cursor.pg.index > index) - --t->bt_cursor.pg.index; - - return (RET_SUCCESS); -} - -/* - * __bt_curdel -- - * Delete the cursor. - * - * Parameters: - * t: tree - * key: referenced key (or NULL) - * h: page - * index: index on page to delete - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -static int -__bt_curdel(t, key, h, index) - BTREE *t; - const DBT *key; - PAGE *h; - u_int index; -{ - CURSOR *c; - EPG e; - PAGE *pg; - int curcopy, status; - - /* - * If there are duplicates, move forward or backward to one. - * Otherwise, copy the key into the cursor area. - */ - c = &t->bt_cursor; - F_CLR(c, CURS_AFTER | CURS_BEFORE | CURS_ACQUIRE); - - curcopy = 0; - if (!F_ISSET(t, B_NODUPS)) { - /* - * We're going to have to do comparisons. If we weren't - * provided a copy of the key, i.e. the user is deleting - * the current cursor position, get one. - */ - if (key == NULL) { - e.page = h; - e.index = index; - if ((status = __bt_ret(t, &e, - &c->key, &c->key, NULL, NULL, 1)) != RET_SUCCESS) - return (status); - curcopy = 1; - key = &c->key; - } - /* Check previous key, if not at the beginning of the page. */ - if (index > 0) { - e.page = h; - e.index = index - 1; - if (__bt_cmp(t, key, &e) == 0) { - F_SET(c, CURS_BEFORE); - goto dup2; - } - } - /* Check next key, if not at the end of the page. */ - if (index < NEXTINDEX(h) - 1) { - e.page = h; - e.index = index + 1; - if (__bt_cmp(t, key, &e) == 0) { - F_SET(c, CURS_AFTER); - goto dup2; - } - } - /* Check previous key if at the beginning of the page. */ - if (index == 0 && h->prevpg != P_INVALID) { - if ((pg = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL) - return (RET_ERROR); - e.page = pg; - e.index = NEXTINDEX(pg) - 1; - if (__bt_cmp(t, key, &e) == 0) { - F_SET(c, CURS_BEFORE); - goto dup1; - } - mpool_put(t->bt_mp, pg, 0); - } - /* Check next key if at the end of the page. */ - if (index == NEXTINDEX(h) - 1 && h->nextpg != P_INVALID) { - if ((pg = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL) - return (RET_ERROR); - e.page = pg; - e.index = 0; - if (__bt_cmp(t, key, &e) == 0) { - F_SET(c, CURS_AFTER); -dup1: mpool_put(t->bt_mp, pg, 0); -dup2: c->pg.pgno = e.page->pgno; - c->pg.index = e.index; - return (RET_SUCCESS); - } - mpool_put(t->bt_mp, pg, 0); - } - } - e.page = h; - e.index = index; - if (curcopy || (status = - __bt_ret(t, &e, &c->key, &c->key, NULL, NULL, 1)) == RET_SUCCESS) { - F_SET(c, CURS_ACQUIRE); - return (RET_SUCCESS); - } - return (status); -} - -/* - * __bt_relink -- - * Link around a deleted page. - * - * Parameters: - * t: tree - * h: page to be deleted - */ -static int -__bt_relink(t, h) - BTREE *t; - PAGE *h; -{ - PAGE *pg; - - if (h->nextpg != P_INVALID) { - if ((pg = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL) - return (RET_ERROR); - pg->prevpg = h->prevpg; - mpool_put(t->bt_mp, pg, MPOOL_DIRTY); - } - if (h->prevpg != P_INVALID) { - if ((pg = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL) - return (RET_ERROR); - pg->nextpg = h->nextpg; - mpool_put(t->bt_mp, pg, MPOOL_DIRTY); - } - return (0); -} diff --git a/db/btree/bt_delete-fbsd.c b/db/btree/bt_delete-fbsd.c new file mode 120000 index 0000000..e240289 --- /dev/null +++ b/db/btree/bt_delete-fbsd.c @@ -0,0 +1 @@ +./bt_delete.c \ No newline at end of file diff --git a/db/btree/bt_extern.h b/db/btree/bt_extern.h deleted file mode 100644 index 478f6af..0000000 --- a/db/btree/bt_extern.h +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * Copyright (c) 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. - * - * @(#)extern.h 8.10 (Berkeley) 7/20/94 - * $FreeBSD: src/lib/libc/db/btree/extern.h,v 1.3 2002/03/22 09:18:22 obrien Exp $ - */ - -int __bt_close(DB *); -int __bt_cmp(BTREE *, const DBT *, EPG *); -int __bt_crsrdel(BTREE *, EPGNO *); -int __bt_defcmp(const DBT *, const DBT *); -size_t __bt_defpfx(const DBT *, const DBT *); -int __bt_delete(const DB *, const DBT *, u_int); -int __bt_dleaf(BTREE *, const DBT *, PAGE *, u_int); -int __bt_fd(const DB *); -int __bt_free(BTREE *, PAGE *); -int __bt_get(const DB *, const DBT *, DBT *, u_int); -PAGE *__bt_new(BTREE *, pgno_t *); -void __bt_pgin(void *, pgno_t, void *); -void __bt_pgout(void *, pgno_t, void *); -int __bt_push(BTREE *, pgno_t, int); -int __bt_put(const DB *dbp, DBT *, const DBT *, u_int); -int __bt_ret(BTREE *, EPG *, DBT *, DBT *, DBT *, DBT *, int); -EPG *__bt_search(BTREE *, const DBT *, int *); -int __bt_seq(const DB *, DBT *, DBT *, u_int); -void __bt_setcur(BTREE *, pgno_t, u_int); -int __bt_split(BTREE *, PAGE *, - const DBT *, const DBT *, int, size_t, u_int32_t); -int __bt_sync(const DB *, u_int); - -int __ovfl_delete(BTREE *, void *); -int __ovfl_get(BTREE *, void *, size_t *, void **, size_t *); -int __ovfl_put(BTREE *, const DBT *, pgno_t *); - -#ifdef DEBUG -void __bt_dnpage(DB *, pgno_t); -void __bt_dpage(PAGE *); -void __bt_dump(DB *); -#endif -#ifdef STATISTICS -void __bt_stat(DB *); -#endif diff --git a/db/btree/bt_extern.h b/db/btree/bt_extern.h new file mode 120000 index 0000000..70017bf --- /dev/null +++ b/db/btree/bt_extern.h @@ -0,0 +1 @@ +./extern.h \ No newline at end of file diff --git a/db/btree/bt_get-fbsd.c b/db/btree/bt_get-fbsd.c deleted file mode 100644 index 0d91ae4..0000000 --- a/db/btree/bt_get-fbsd.c +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_get.c 8.6 (Berkeley) 7/20/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_get.c,v 1.2 2002/03/22 21:52:01 obrien Exp $"); - -#include - -#include -#include -#include - -#include -#include "btree.h" - -/* - * __BT_GET -- Get a record from the btree. - * - * Parameters: - * dbp: pointer to access method - * key: key to find - * data: data to return - * flag: currently unused - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -int -__bt_get(dbp, key, data, flags) - const DB *dbp; - const DBT *key; - DBT *data; - u_int flags; -{ - BTREE *t; - EPG *e; - int exact, status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* Get currently doesn't take any flags. */ - if (flags) { - errno = EINVAL; - return (RET_ERROR); - } - - if ((e = __bt_search(t, key, &exact)) == NULL) - return (RET_ERROR); - if (!exact) { - mpool_put(t->bt_mp, e->page, 0); - return (RET_SPECIAL); - } - - status = __bt_ret(t, e, NULL, NULL, data, &t->bt_rdata, 0); - - /* - * If the user is doing concurrent access, we copied the - * key/data, toss the page. - */ - if (F_ISSET(t, B_DB_LOCK)) - mpool_put(t->bt_mp, e->page, 0); - else - t->bt_pinned = e->page; - return (status); -} diff --git a/db/btree/bt_get-fbsd.c b/db/btree/bt_get-fbsd.c new file mode 120000 index 0000000..fb8f834 --- /dev/null +++ b/db/btree/bt_get-fbsd.c @@ -0,0 +1 @@ +./bt_get.c \ No newline at end of file diff --git a/db/btree/bt_open-fbsd.c b/db/btree/bt_open-fbsd.c deleted file mode 100644 index c8a103a..0000000 --- a/db/btree/bt_open-fbsd.c +++ /dev/null @@ -1,449 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_open.c 8.10 (Berkeley) 8/17/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_open.c,v 1.11 2002/03/22 21:52:01 obrien Exp $"); - -/* - * Implementation of btree access method for 4.4BSD. - * - * The design here was originally based on that of the btree access method - * used in the Postgres database system at UC Berkeley. This implementation - * is wholly independent of the Postgres code. - */ - -#include "namespace.h" -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include "un-namespace.h" - -#include -#include "btree.h" - -#ifdef DEBUG -#undef MINPSIZE -#define MINPSIZE 128 -#endif - -static int byteorder(void); -static int nroot(BTREE *); -static int tmp(void); - -/* - * __BT_OPEN -- Open a btree. - * - * Creates and fills a DB struct, and calls the routine that actually - * opens the btree. - * - * Parameters: - * fname: filename (NULL for in-memory trees) - * flags: open flag bits - * mode: open permission bits - * b: BTREEINFO pointer - * - * Returns: - * NULL on failure, pointer to DB on success. - * - */ -DB * -__bt_open(fname, flags, mode, openinfo, dflags) - const char *fname; - int flags, mode, dflags; - const BTREEINFO *openinfo; -{ - struct stat sb; - BTMETA m; - BTREE *t; - BTREEINFO b; - DB *dbp; - pgno_t ncache; - ssize_t nr; - int machine_lorder; - - t = NULL; - - /* - * Intention is to make sure all of the user's selections are okay - * here and then use them without checking. Can't be complete, since - * we don't know the right page size, lorder or flags until the backing - * file is opened. Also, the file's page size can cause the cachesize - * to change. - */ - machine_lorder = byteorder(); - if (openinfo) { - b = *openinfo; - - /* Flags: R_DUP. */ - if (b.flags & ~(R_DUP)) - goto einval; - - /* - * Page size must be indx_t aligned and >= MINPSIZE. Default - * page size is set farther on, based on the underlying file - * transfer size. - */ - if (b.psize && - (b.psize < MINPSIZE || b.psize > MAX_PAGE_OFFSET + 1 || - b.psize & (sizeof(indx_t) - 1) )) - goto einval; - - /* Minimum number of keys per page; absolute minimum is 2. */ - if (b.minkeypage) { - if (b.minkeypage < 2) - goto einval; - } else - b.minkeypage = DEFMINKEYPAGE; - - /* If no comparison, use default comparison and prefix. */ - if (b.compare == NULL) { - b.compare = __bt_defcmp; - if (b.prefix == NULL) - b.prefix = __bt_defpfx; - } - - if (b.lorder == 0) - b.lorder = machine_lorder; - } else { - b.compare = __bt_defcmp; - b.cachesize = 0; - b.flags = 0; - b.lorder = machine_lorder; - b.minkeypage = DEFMINKEYPAGE; - b.prefix = __bt_defpfx; - b.psize = 0; - } - - /* Check for the ubiquitous PDP-11. */ - if (b.lorder != BIG_ENDIAN && b.lorder != LITTLE_ENDIAN) - goto einval; - - /* Allocate and initialize DB and BTREE structures. */ - if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL) - goto err; - memset(t, 0, sizeof(BTREE)); - t->bt_fd = -1; /* Don't close unopened fd on error. */ - t->bt_lorder = b.lorder; - t->bt_order = NOT; - t->bt_cmp = b.compare; - t->bt_pfx = b.prefix; - t->bt_rfd = -1; - - if ((t->bt_dbp = dbp = (DB *)malloc(sizeof(DB))) == NULL) - goto err; - memset(t->bt_dbp, 0, sizeof(DB)); - if (t->bt_lorder != machine_lorder) - F_SET(t, B_NEEDSWAP); - - dbp->type = DB_BTREE; - dbp->internal = t; - dbp->close = __bt_close; - dbp->del = __bt_delete; - dbp->fd = __bt_fd; - dbp->get = __bt_get; - dbp->put = __bt_put; - dbp->seq = __bt_seq; - dbp->sync = __bt_sync; - - /* - * If no file name was supplied, this is an in-memory btree and we - * open a backing temporary file. Otherwise, it's a disk-based tree. - */ - if (fname) { - switch (flags & O_ACCMODE) { - case O_RDONLY: - F_SET(t, B_RDONLY); - break; - case O_RDWR: - break; - case O_WRONLY: - default: - goto einval; - } - - if ((t->bt_fd = _open(fname, flags, mode)) < 0) - goto err; - - } else { - if ((flags & O_ACCMODE) != O_RDWR) - goto einval; - if ((t->bt_fd = tmp()) == -1) - goto err; - F_SET(t, B_INMEM); - } - - if (_fcntl(t->bt_fd, F_SETFD, 1) == -1) - goto err; - - if (_fstat(t->bt_fd, &sb)) - goto err; - if (sb.st_size) { - if ((nr = _read(t->bt_fd, &m, sizeof(BTMETA))) < 0) - goto err; - if (nr != sizeof(BTMETA)) - goto eftype; - - /* - * Read in the meta-data. This can change the notion of what - * the lorder, page size and flags are, and, when the page size - * changes, the cachesize value can change too. If the user - * specified the wrong byte order for an existing database, we - * don't bother to return an error, we just clear the NEEDSWAP - * bit. - */ - if (m.magic == BTREEMAGIC) - F_CLR(t, B_NEEDSWAP); - else { - F_SET(t, B_NEEDSWAP); - M_32_SWAP(m.magic); - M_32_SWAP(m.version); - M_32_SWAP(m.psize); - M_32_SWAP(m.free); - M_32_SWAP(m.nrecs); - M_32_SWAP(m.flags); - } - 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) ) - goto eftype; - if (m.flags & ~SAVEMETA) - goto eftype; - b.psize = m.psize; - F_SET(t, m.flags); - t->bt_free = m.free; - t->bt_nrecs = m.nrecs; - } else { - /* - * Set the page size to the best value for I/O to this file. - * Don't overflow the page offset type. - */ - if (b.psize == 0) { - b.psize = sb.st_blksize; - if (b.psize < MINPSIZE) - b.psize = MINPSIZE; - if (b.psize > MAX_PAGE_OFFSET + 1) - b.psize = MAX_PAGE_OFFSET + 1; - } - - /* Set flag if duplicates permitted. */ - if (!(b.flags & R_DUP)) - F_SET(t, B_NODUPS); - - t->bt_free = P_INVALID; - t->bt_nrecs = 0; - F_SET(t, B_METADIRTY); - } - - 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.psize * MINCACHE) - b.cachesize = b.psize * MINCACHE; - - /* Calculate number of pages to cache. */ - ncache = (b.cachesize + t->bt_psize - 1) / t->bt_psize; - - /* - * The btree data structure requires that at least two keys can fit on - * a page, but other than that there's no fixed requirement. The user - * specified a minimum number per page, and we translated that into the - * number of bytes a key/data pair can use before being placed on an - * overflow page. This calculation includes the page header, the size - * of the index referencing the leaf item and the size of the leaf item - * structure. Also, don't let the user specify a minkeypage such that - * a key/data pair won't fit even if both key and data are on overflow - * pages. - */ - t->bt_ovflsize = (t->bt_psize - BTDATAOFF) / b.minkeypage - - (sizeof(indx_t) + NBLEAFDBT(0, 0)); - if (t->bt_ovflsize < NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t)) - t->bt_ovflsize = - NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t); - - /* Initialize the buffer pool. */ - if ((t->bt_mp = - mpool_open(NULL, t->bt_fd, t->bt_psize, ncache)) == NULL) - goto err; - if (!F_ISSET(t, B_INMEM)) - mpool_filter(t->bt_mp, __bt_pgin, __bt_pgout, t); - - /* Create a root page if new tree. */ - if (nroot(t) == RET_ERROR) - goto err; - - /* Global flags. */ - if (dflags & DB_LOCK) - F_SET(t, B_DB_LOCK); - if (dflags & DB_SHMEM) - F_SET(t, B_DB_SHMEM); - if (dflags & DB_TXN) - F_SET(t, B_DB_TXN); - - return (dbp); - -einval: errno = EINVAL; - goto err; - -eftype: errno = EFTYPE; - goto err; - -err: if (t) { - if (t->bt_dbp) - free(t->bt_dbp); - if (t->bt_fd != -1) - (void)_close(t->bt_fd); - free(t); - } - return (NULL); -} - -/* - * NROOT -- Create the root of a new tree. - * - * Parameters: - * t: tree - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -static int -nroot(t) - BTREE *t; -{ - PAGE *meta, *root; - pgno_t npg; - - if ((meta = mpool_get(t->bt_mp, 0, 0)) != NULL) { - mpool_put(t->bt_mp, meta, 0); - return (RET_SUCCESS); - } - if (errno != EINVAL) /* It's OK to not exist. */ - return (RET_ERROR); - errno = 0; - - if ((meta = mpool_new(t->bt_mp, &npg)) == NULL) - return (RET_ERROR); - - if ((root = mpool_new(t->bt_mp, &npg)) == NULL) - return (RET_ERROR); - - if (npg != P_ROOT) - return (RET_ERROR); - root->pgno = npg; - root->prevpg = root->nextpg = P_INVALID; - root->lower = BTDATAOFF; - root->upper = t->bt_psize; - root->flags = P_BLEAF; - memset(meta, 0, t->bt_psize); - mpool_put(t->bt_mp, meta, MPOOL_DIRTY); - mpool_put(t->bt_mp, root, MPOOL_DIRTY); - return (RET_SUCCESS); -} - -static int -tmp() -{ - sigset_t set, oset; - int fd; - char *envtmp = NULL; - char path[MAXPATHLEN]; - - if (issetugid() == 0) - envtmp = getenv("TMPDIR"); - (void)snprintf(path, - sizeof(path), "%s/bt.XXXXXXXXXX", envtmp ? envtmp : "/tmp"); - - (void)sigfillset(&set); - (void)_sigprocmask(SIG_BLOCK, &set, &oset); - if ((fd = mkstemp(path)) != -1) - (void)unlink(path); - (void)_sigprocmask(SIG_SETMASK, &oset, NULL); - return(fd); -} - -static int -byteorder() -{ - u_int32_t x; - u_char *p; - - x = 0x01020304; - p = (u_char *)&x; - switch (*p) { - case 1: - return (BIG_ENDIAN); - case 4: - return (LITTLE_ENDIAN); - default: - return (0); - } -} - -int -__bt_fd(dbp) - const DB *dbp; -{ - BTREE *t; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* In-memory database can't have a file descriptor. */ - if (F_ISSET(t, B_INMEM)) { - errno = ENOENT; - return (-1); - } - return (t->bt_fd); -} diff --git a/db/btree/bt_open-fbsd.c b/db/btree/bt_open-fbsd.c new file mode 120000 index 0000000..628e50e --- /dev/null +++ b/db/btree/bt_open-fbsd.c @@ -0,0 +1 @@ +./bt_open.c \ No newline at end of file diff --git a/db/btree/bt_overflow-fbsd.c b/db/btree/bt_overflow-fbsd.c deleted file mode 100644 index 5e0f1ae..0000000 --- a/db/btree/bt_overflow-fbsd.c +++ /dev/null @@ -1,230 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_overflow.c 8.5 (Berkeley) 7/16/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_overflow.c,v 1.3 2002/03/22 21:52:01 obrien Exp $"); - -#include - -#include -#include -#include - -#include -#include "btree.h" - -/* - * Big key/data code. - * - * Big key and data entries are stored on linked lists of pages. The initial - * reference is byte string stored with the key or data and is the page number - * and size. The actual record is stored in a chain of pages linked by the - * nextpg field of the PAGE header. - * - * The first page of the chain has a special property. If the record is used - * by an internal page, it cannot be deleted and the P_PRESERVE bit will be set - * in the header. - * - * XXX - * A single DBT is written to each chain, so a lot of space on the last page - * is wasted. This is a fairly major bug for some data sets. - */ - -/* - * __OVFL_GET -- Get an overflow key/data item. - * - * Parameters: - * t: tree - * p: pointer to { pgno_t, u_int32_t } - * buf: storage address - * bufsz: storage size - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__ovfl_get(t, p, ssz, buf, bufsz) - BTREE *t; - void *p; - size_t *ssz; - void **buf; - size_t *bufsz; -{ - PAGE *h; - pgno_t pg; - size_t nb, plen; - u_int32_t sz; - - memmove(&pg, p, sizeof(pgno_t)); - memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t)); - *ssz = sz; - -#ifdef DEBUG - if (pg == P_INVALID || sz == 0) - abort(); -#endif - /* Make the buffer bigger as necessary. */ - if (*bufsz < sz) { - *buf = (char *)(*buf == NULL ? malloc(sz) : reallocf(*buf, sz)); - if (*buf == NULL) - return (RET_ERROR); - *bufsz = sz; - } - - /* - * Step through the linked list of pages, copying the data on each one - * into the buffer. Never copy more than the data's length. - */ - plen = t->bt_psize - BTDATAOFF; - for (p = *buf;; p = (char *)p + nb, pg = h->nextpg) { - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - - nb = MIN(sz, plen); - memmove(p, (char *)h + BTDATAOFF, nb); - mpool_put(t->bt_mp, h, 0); - - if ((sz -= nb) == 0) - break; - } - return (RET_SUCCESS); -} - -/* - * __OVFL_PUT -- Store an overflow key/data item. - * - * Parameters: - * t: tree - * data: DBT to store - * pgno: storage page number - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__ovfl_put(t, dbt, pg) - BTREE *t; - const DBT *dbt; - pgno_t *pg; -{ - PAGE *h, *last; - void *p; - pgno_t npg; - size_t nb, plen; - u_int32_t sz; - - /* - * Allocate pages and copy the key/data record into them. Store the - * number of the first page in the chain. - */ - plen = t->bt_psize - BTDATAOFF; - for (last = NULL, p = dbt->data, sz = dbt->size;; - p = (char *)p + plen, last = h) { - if ((h = __bt_new(t, &npg)) == NULL) - return (RET_ERROR); - - h->pgno = npg; - h->nextpg = h->prevpg = P_INVALID; - h->flags = P_OVERFLOW; - h->lower = h->upper = 0; - - nb = MIN(sz, plen); - memmove((char *)h + BTDATAOFF, p, nb); - - if (last) { - last->nextpg = h->pgno; - mpool_put(t->bt_mp, last, MPOOL_DIRTY); - } else - *pg = h->pgno; - - if ((sz -= nb) == 0) { - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - break; - } - } - return (RET_SUCCESS); -} - -/* - * __OVFL_DELETE -- Delete an overflow chain. - * - * Parameters: - * t: tree - * p: pointer to { pgno_t, u_int32_t } - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__ovfl_delete(t, p) - BTREE *t; - void *p; -{ - PAGE *h; - pgno_t pg; - size_t plen; - u_int32_t sz; - - memmove(&pg, p, sizeof(pgno_t)); - memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t)); - -#ifdef DEBUG - if (pg == P_INVALID || sz == 0) - abort(); -#endif - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - - /* Don't delete chains used by internal pages. */ - if (h->flags & P_PRESERVE) { - mpool_put(t->bt_mp, h, 0); - return (RET_SUCCESS); - } - - /* Step through the chain, calling the free routine for each page. */ - for (plen = t->bt_psize - BTDATAOFF;; sz -= plen) { - pg = h->nextpg; - __bt_free(t, h); - if (sz <= plen) - break; - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - } - return (RET_SUCCESS); -} diff --git a/db/btree/bt_overflow-fbsd.c b/db/btree/bt_overflow-fbsd.c new file mode 120000 index 0000000..707581f --- /dev/null +++ b/db/btree/bt_overflow-fbsd.c @@ -0,0 +1 @@ +./bt_overflow.c \ No newline at end of file diff --git a/db/btree/bt_page-fbsd.c b/db/btree/bt_page-fbsd.c deleted file mode 100644 index 3392709..0000000 --- a/db/btree/bt_page-fbsd.c +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * 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[] = "@(#)bt_page.c 8.3 (Berkeley) 7/14/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_page.c,v 1.3 2002/03/22 21:52:01 obrien Exp $"); - -#include - -#include - -#include -#include "btree.h" - -/* - * __bt_free -- - * Put a page on the freelist. - * - * Parameters: - * t: tree - * h: page to free - * - * Returns: - * RET_ERROR, RET_SUCCESS - * - * Side-effect: - * mpool_put's the page. - */ -int -__bt_free(t, h) - BTREE *t; - PAGE *h; -{ - /* Insert the page at the head of the free list. */ - h->prevpg = P_INVALID; - h->nextpg = t->bt_free; - t->bt_free = h->pgno; - F_SET(t, B_METADIRTY); - - /* Make sure the page gets written back. */ - return (mpool_put(t->bt_mp, h, MPOOL_DIRTY)); -} - -/* - * __bt_new -- - * Get a new page, preferably from the freelist. - * - * Parameters: - * t: tree - * npg: storage for page number. - * - * Returns: - * Pointer to a page, NULL on error. - */ -PAGE * -__bt_new(t, npg) - BTREE *t; - pgno_t *npg; -{ - PAGE *h; - - if (t->bt_free != P_INVALID && - (h = mpool_get(t->bt_mp, t->bt_free, 0)) != NULL) { - *npg = t->bt_free; - t->bt_free = h->nextpg; - F_SET(t, B_METADIRTY); - return (h); - } - return (mpool_new(t->bt_mp, npg)); -} diff --git a/db/btree/bt_page-fbsd.c b/db/btree/bt_page-fbsd.c new file mode 120000 index 0000000..f41e3f7 --- /dev/null +++ b/db/btree/bt_page-fbsd.c @@ -0,0 +1 @@ +./bt_page.c \ No newline at end of file diff --git a/db/btree/bt_put-fbsd.c b/db/btree/bt_put-fbsd.c deleted file mode 100644 index 0dca165..0000000 --- a/db/btree/bt_put-fbsd.c +++ /dev/null @@ -1,325 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_put.c 8.8 (Berkeley) 7/26/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_put.c,v 1.4 2003/05/30 11:05:08 tmm Exp $"); - -#include - -#include -#include -#include -#include - -#include -#include "btree.h" - -static EPG *bt_fast(BTREE *, const DBT *, const DBT *, int *); - -/* - * __BT_PUT -- Add a btree item to the tree. - * - * Parameters: - * dbp: pointer to access method - * key: key - * data: data - * flag: R_NOOVERWRITE - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is already in the - * tree and R_NOOVERWRITE specified. - */ -int -__bt_put(dbp, key, data, flags) - const DB *dbp; - DBT *key; - const DBT *data; - u_int flags; -{ - BTREE *t; - DBT tkey, tdata; - EPG *e; - PAGE *h; - indx_t index, nxtindex; - pgno_t pg; - u_int32_t nbytes, tmp; - int dflags, exact, status; - char *dest, db[NOVFLSIZE], kb[NOVFLSIZE]; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* Check for change to a read-only tree. */ - if (F_ISSET(t, B_RDONLY)) { - errno = EPERM; - return (RET_ERROR); - } - - switch (flags) { - case 0: - case R_NOOVERWRITE: - break; - case R_CURSOR: - /* - * If flags is R_CURSOR, put the cursor. Must already - * have started a scan and not have already deleted it. - */ - if (F_ISSET(&t->bt_cursor, CURS_INIT) && - !F_ISSET(&t->bt_cursor, - CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE)) - break; - /* FALLTHROUGH */ - default: - errno = EINVAL; - return (RET_ERROR); - } - - /* - * If the key/data pair won't fit on a page, store it on overflow - * pages. Only put the key on the overflow page if the pair are - * still too big after moving the data to an overflow page. - * - * XXX - * If the insert fails later on, the overflow pages aren't recovered. - */ - dflags = 0; - if (key->size + data->size > t->bt_ovflsize) { - if (key->size > t->bt_ovflsize) { -storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) - return (RET_ERROR); - tkey.data = kb; - tkey.size = NOVFLSIZE; - memmove(kb, &pg, sizeof(pgno_t)); - tmp = key->size; - memmove(kb + sizeof(pgno_t), - &tmp, sizeof(u_int32_t)); - dflags |= P_BIGKEY; - key = &tkey; - } - if (key->size + data->size > t->bt_ovflsize) { - if (__ovfl_put(t, data, &pg) == RET_ERROR) - return (RET_ERROR); - tdata.data = db; - tdata.size = NOVFLSIZE; - memmove(db, &pg, sizeof(pgno_t)); - tmp = data->size; - memmove(db + sizeof(pgno_t), - &tmp, sizeof(u_int32_t)); - dflags |= P_BIGDATA; - data = &tdata; - } - if (key->size + data->size > t->bt_ovflsize) - goto storekey; - } - - /* Replace the cursor. */ - if (flags == R_CURSOR) { - if ((h = mpool_get(t->bt_mp, t->bt_cursor.pg.pgno, 0)) == NULL) - return (RET_ERROR); - index = t->bt_cursor.pg.index; - goto delete; - } - - /* - * Find the key to delete, or, the location at which to insert. - * Bt_fast and __bt_search both pin the returned page. - */ - if (t->bt_order == NOT || (e = bt_fast(t, key, data, &exact)) == NULL) - if ((e = __bt_search(t, key, &exact)) == NULL) - return (RET_ERROR); - h = e->page; - index = e->index; - - /* - * Add the key/data pair to the tree. If an identical key is already - * in the tree, and R_NOOVERWRITE is set, an error is returned. If - * R_NOOVERWRITE is not set, the key is either added (if duplicates are - * permitted) or an error is returned. - */ - switch (flags) { - case R_NOOVERWRITE: - if (!exact) - break; - mpool_put(t->bt_mp, h, 0); - return (RET_SPECIAL); - default: - if (!exact || !F_ISSET(t, B_NODUPS)) - break; - /* - * !!! - * Note, the delete may empty the page, so we need to put a - * new entry into the page immediately. - */ -delete: if (__bt_dleaf(t, key, h, index) == RET_ERROR) { - mpool_put(t->bt_mp, h, 0); - return (RET_ERROR); - } - break; - } - - /* - * If not enough room, or the user has put a ceiling on the number of - * keys permitted in the page, split the page. The split code will - * insert the key and data and unpin the current page. If inserting - * into the offset array, shift the pointers up. - */ - nbytes = NBLEAFDBT(key->size, data->size); - if (h->upper - h->lower < nbytes + sizeof(indx_t)) { - if ((status = __bt_split(t, h, key, - data, dflags, nbytes, index)) != RET_SUCCESS) - return (status); - goto success; - } - - if (index < (nxtindex = NEXTINDEX(h))) - memmove(h->linp + index + 1, h->linp + index, - (nxtindex - index) * sizeof(indx_t)); - h->lower += sizeof(indx_t); - - h->linp[index] = h->upper -= nbytes; - dest = (char *)h + h->upper; - WR_BLEAF(dest, key, data, dflags); - - /* If the cursor is on this page, adjust it as necessary. */ - if (F_ISSET(&t->bt_cursor, CURS_INIT) && - !F_ISSET(&t->bt_cursor, CURS_ACQUIRE) && - t->bt_cursor.pg.pgno == h->pgno && t->bt_cursor.pg.index >= index) - ++t->bt_cursor.pg.index; - - if (t->bt_order == NOT) { - if (h->nextpg == P_INVALID) { - if (index == NEXTINDEX(h) - 1) { - t->bt_order = FORWARD; - t->bt_last.index = index; - t->bt_last.pgno = h->pgno; - } - } else if (h->prevpg == P_INVALID) { - if (index == 0) { - t->bt_order = BACK; - t->bt_last.index = 0; - t->bt_last.pgno = h->pgno; - } - } - } - - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - -success: - if (flags == R_SETCURSOR) - __bt_setcur(t, e->page->pgno, e->index); - - F_SET(t, B_MODIFIED); - return (RET_SUCCESS); -} - -#ifdef STATISTICS -u_long bt_cache_hit, bt_cache_miss; -#endif - -/* - * BT_FAST -- Do a quick check for sorted data. - * - * Parameters: - * t: tree - * key: key to insert - * - * Returns: - * EPG for new record or NULL if not found. - */ -static EPG * -bt_fast(t, key, data, exactp) - BTREE *t; - const DBT *key, *data; - int *exactp; -{ - PAGE *h; - u_int32_t nbytes; - int cmp; - - if ((h = mpool_get(t->bt_mp, t->bt_last.pgno, 0)) == NULL) { - t->bt_order = NOT; - return (NULL); - } - t->bt_cur.page = h; - t->bt_cur.index = t->bt_last.index; - - /* - * If won't fit in this page or have too many keys in this page, - * have to search to get split stack. - */ - nbytes = NBLEAFDBT(key->size, data->size); - if (h->upper - h->lower < nbytes + sizeof(indx_t)) - goto miss; - - if (t->bt_order == FORWARD) { - if (t->bt_cur.page->nextpg != P_INVALID) - goto miss; - if (t->bt_cur.index != NEXTINDEX(h) - 1) - goto miss; - if ((cmp = __bt_cmp(t, key, &t->bt_cur)) < 0) - goto miss; - t->bt_last.index = cmp ? ++t->bt_cur.index : t->bt_cur.index; - } else { - if (t->bt_cur.page->prevpg != P_INVALID) - goto miss; - if (t->bt_cur.index != 0) - goto miss; - if ((cmp = __bt_cmp(t, key, &t->bt_cur)) > 0) - goto miss; - t->bt_last.index = 0; - } - *exactp = cmp == 0; -#ifdef STATISTICS - ++bt_cache_hit; -#endif - return (&t->bt_cur); - -miss: -#ifdef STATISTICS - ++bt_cache_miss; -#endif - t->bt_order = NOT; - mpool_put(t->bt_mp, h, 0); - return (NULL); -} diff --git a/db/btree/bt_put-fbsd.c b/db/btree/bt_put-fbsd.c new file mode 120000 index 0000000..0ac099f --- /dev/null +++ b/db/btree/bt_put-fbsd.c @@ -0,0 +1 @@ +./bt_put.c \ No newline at end of file diff --git a/db/btree/bt_search-fbsd.c b/db/btree/bt_search-fbsd.c deleted file mode 100644 index cee177d..0000000 --- a/db/btree/bt_search-fbsd.c +++ /dev/null @@ -1,215 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_search.c 8.8 (Berkeley) 7/31/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_search.c,v 1.2 2002/03/21 22:46:25 obrien Exp $"); - -#include - -#include - -#include -#include "btree.h" - -static int __bt_snext(BTREE *, PAGE *, const DBT *, int *); -static int __bt_sprev(BTREE *, PAGE *, const DBT *, int *); - -/* - * __bt_search -- - * Search a btree for a key. - * - * Parameters: - * t: tree to search - * key: key to find - * exactp: pointer to exact match flag - * - * Returns: - * The EPG for matching record, if any, or the EPG for the location - * of the key, if it were inserted into the tree, is entered into - * the bt_cur field of the tree. A pointer to the field is returned. - */ -EPG * -__bt_search(t, key, exactp) - BTREE *t; - const DBT *key; - int *exactp; -{ - PAGE *h; - indx_t base, index, lim; - pgno_t pg; - int cmp; - - BT_CLR(t); - for (pg = P_ROOT;;) { - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (NULL); - - /* Do a binary search on the current page. */ - t->bt_cur.page = h; - for (base = 0, lim = NEXTINDEX(h); lim; lim >>= 1) { - t->bt_cur.index = index = base + (lim >> 1); - if ((cmp = __bt_cmp(t, key, &t->bt_cur)) == 0) { - if (h->flags & P_BLEAF) { - *exactp = 1; - return (&t->bt_cur); - } - goto next; - } - if (cmp > 0) { - base = index + 1; - --lim; - } - } - - /* - * If it's a leaf page, we're almost done. If no duplicates - * are allowed, or we have an exact match, we're done. Else, - * it's possible that there were matching keys on this page, - * which later deleted, and we're on a page with no matches - * while there are matches on other pages. If at the start or - * end of a page, check the adjacent page. - */ - if (h->flags & P_BLEAF) { - if (!F_ISSET(t, B_NODUPS)) { - if (base == 0 && - h->prevpg != P_INVALID && - __bt_sprev(t, h, key, exactp)) - return (&t->bt_cur); - if (base == NEXTINDEX(h) && - h->nextpg != P_INVALID && - __bt_snext(t, h, key, exactp)) - return (&t->bt_cur); - } - *exactp = 0; - t->bt_cur.index = base; - return (&t->bt_cur); - } - - /* - * No match found. Base is the smallest index greater than - * key and may be zero or a last + 1 index. If it's non-zero, - * decrement by one, and record the internal page which should - * be a parent page for the key. If a split later occurs, the - * inserted page will be to the right of the saved page. - */ - index = base ? base - 1 : base; - -next: BT_PUSH(t, h->pgno, index); - pg = GETBINTERNAL(h, index)->pgno; - mpool_put(t->bt_mp, h, 0); - } -} - -/* - * __bt_snext -- - * Check for an exact match after the key. - * - * Parameters: - * t: tree - * h: current page - * key: key - * exactp: pointer to exact match flag - * - * Returns: - * If an exact match found. - */ -static int -__bt_snext(t, h, key, exactp) - BTREE *t; - PAGE *h; - const DBT *key; - int *exactp; -{ - EPG e; - - /* - * Get the next page. The key is either an exact - * match, or not as good as the one we already have. - */ - if ((e.page = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL) - return (0); - e.index = 0; - if (__bt_cmp(t, key, &e) == 0) { - mpool_put(t->bt_mp, h, 0); - t->bt_cur = e; - *exactp = 1; - return (1); - } - mpool_put(t->bt_mp, e.page, 0); - return (0); -} - -/* - * __bt_sprev -- - * Check for an exact match before the key. - * - * Parameters: - * t: tree - * h: current page - * key: key - * exactp: pointer to exact match flag - * - * Returns: - * If an exact match found. - */ -static int -__bt_sprev(t, h, key, exactp) - BTREE *t; - PAGE *h; - const DBT *key; - int *exactp; -{ - EPG e; - - /* - * Get the previous page. The key is either an exact - * match, or not as good as the one we already have. - */ - if ((e.page = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL) - return (0); - e.index = NEXTINDEX(e.page) - 1; - if (__bt_cmp(t, key, &e) == 0) { - mpool_put(t->bt_mp, h, 0); - t->bt_cur = e; - *exactp = 1; - return (1); - } - mpool_put(t->bt_mp, e.page, 0); - return (0); -} diff --git a/db/btree/bt_search-fbsd.c b/db/btree/bt_search-fbsd.c new file mode 120000 index 0000000..06a108b --- /dev/null +++ b/db/btree/bt_search-fbsd.c @@ -0,0 +1 @@ +./bt_search.c \ No newline at end of file diff --git a/db/btree/bt_seq-fbsd.c b/db/btree/bt_seq-fbsd.c deleted file mode 100644 index 662e195..0000000 --- a/db/btree/bt_seq-fbsd.c +++ /dev/null @@ -1,462 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_seq.c 8.7 (Berkeley) 7/20/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_seq.c,v 1.3 2002/03/21 22:46:25 obrien Exp $"); - -#include - -#include -#include -#include -#include - -#include -#include "btree.h" - -static int __bt_first(BTREE *, const DBT *, EPG *, int *); -static int __bt_seqadv(BTREE *, EPG *, int); -static int __bt_seqset(BTREE *, EPG *, DBT *, int); - -/* - * Sequential scan support. - * - * The tree can be scanned sequentially, starting from either end of the - * tree or from any specific key. A scan request before any scanning is - * done is initialized as starting from the least node. - */ - -/* - * __bt_seq -- - * Btree sequential scan interface. - * - * Parameters: - * dbp: pointer to access method - * key: key for positioning and return value - * data: data return value - * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV. - * - * Returns: - * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. - */ -int -__bt_seq(dbp, key, data, flags) - const DB *dbp; - DBT *key, *data; - u_int flags; -{ - BTREE *t; - EPG e; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* - * If scan unitialized as yet, or starting at a specific record, set - * the scan to a specific key. Both __bt_seqset and __bt_seqadv pin - * the page the cursor references if they're successful. - */ - switch (flags) { - case R_NEXT: - case R_PREV: - if (F_ISSET(&t->bt_cursor, CURS_INIT)) { - status = __bt_seqadv(t, &e, flags); - break; - } - /* FALLTHROUGH */ - case R_FIRST: - case R_LAST: - case R_CURSOR: - status = __bt_seqset(t, &e, key, flags); - break; - default: - errno = EINVAL; - return (RET_ERROR); - } - - if (status == RET_SUCCESS) { - __bt_setcur(t, e.page->pgno, e.index); - - status = - __bt_ret(t, &e, key, &t->bt_rkey, data, &t->bt_rdata, 0); - - /* - * If the user is doing concurrent access, we copied the - * key/data, toss the page. - */ - if (F_ISSET(t, B_DB_LOCK)) - mpool_put(t->bt_mp, e.page, 0); - else - t->bt_pinned = e.page; - } - return (status); -} - -/* - * __bt_seqset -- - * Set the sequential scan to a specific key. - * - * Parameters: - * t: tree - * ep: storage for returned key - * key: key for initial scan position - * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV - * - * Side effects: - * Pins the page the cursor references. - * - * Returns: - * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. - */ -static int -__bt_seqset(t, ep, key, flags) - BTREE *t; - EPG *ep; - DBT *key; - int flags; -{ - PAGE *h; - pgno_t pg; - int exact; - - /* - * Find the first, last or specific key in the tree and point the - * cursor at it. The cursor may not be moved until a new key has - * been found. - */ - switch (flags) { - case R_CURSOR: /* Keyed scan. */ - /* - * Find the first instance of the key or the smallest key - * which is greater than or equal to the specified key. - */ - if (key->data == NULL || key->size == 0) { - errno = EINVAL; - return (RET_ERROR); - } - return (__bt_first(t, key, ep, &exact)); - case R_FIRST: /* First record. */ - case R_NEXT: - /* Walk down the left-hand side of the tree. */ - for (pg = P_ROOT;;) { - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - - /* Check for an empty tree. */ - if (NEXTINDEX(h) == 0) { - mpool_put(t->bt_mp, h, 0); - return (RET_SPECIAL); - } - - if (h->flags & (P_BLEAF | P_RLEAF)) - break; - pg = GETBINTERNAL(h, 0)->pgno; - mpool_put(t->bt_mp, h, 0); - } - ep->page = h; - ep->index = 0; - break; - case R_LAST: /* Last record. */ - case R_PREV: - /* Walk down the right-hand side of the tree. */ - for (pg = P_ROOT;;) { - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - - /* Check for an empty tree. */ - if (NEXTINDEX(h) == 0) { - mpool_put(t->bt_mp, h, 0); - return (RET_SPECIAL); - } - - if (h->flags & (P_BLEAF | P_RLEAF)) - break; - pg = GETBINTERNAL(h, NEXTINDEX(h) - 1)->pgno; - mpool_put(t->bt_mp, h, 0); - } - - ep->page = h; - ep->index = NEXTINDEX(h) - 1; - break; - } - return (RET_SUCCESS); -} - -/* - * __bt_seqadvance -- - * Advance the sequential scan. - * - * Parameters: - * t: tree - * flags: R_NEXT, R_PREV - * - * Side effects: - * Pins the page the new key/data record is on. - * - * Returns: - * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. - */ -static int -__bt_seqadv(t, ep, flags) - BTREE *t; - EPG *ep; - int flags; -{ - CURSOR *c; - PAGE *h; - indx_t index; - pgno_t pg; - int exact; - - /* - * There are a couple of states that we can be in. The cursor has - * been initialized by the time we get here, but that's all we know. - */ - c = &t->bt_cursor; - - /* - * The cursor was deleted where there weren't any duplicate records, - * so the key was saved. Find out where that key would go in the - * current tree. It doesn't matter if the returned key is an exact - * match or not -- if it's an exact match, the record was added after - * the delete so we can just return it. If not, as long as there's - * a record there, return it. - */ - if (F_ISSET(c, CURS_ACQUIRE)) - return (__bt_first(t, &c->key, ep, &exact)); - - /* Get the page referenced by the cursor. */ - if ((h = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL) - return (RET_ERROR); - - /* - * Find the next/previous record in the tree and point the cursor at - * it. The cursor may not be moved until a new key has been found. - */ - switch (flags) { - case R_NEXT: /* Next record. */ - /* - * The cursor was deleted in duplicate records, and moved - * forward to a record that has yet to be returned. Clear - * that flag, and return the record. - */ - if (F_ISSET(c, CURS_AFTER)) - goto usecurrent; - index = c->pg.index; - if (++index == NEXTINDEX(h)) { - pg = h->nextpg; - mpool_put(t->bt_mp, h, 0); - if (pg == P_INVALID) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - index = 0; - } - break; - case R_PREV: /* Previous record. */ - /* - * The cursor was deleted in duplicate records, and moved - * backward to a record that has yet to be returned. Clear - * that flag, and return the record. - */ - if (F_ISSET(c, CURS_BEFORE)) { -usecurrent: F_CLR(c, CURS_AFTER | CURS_BEFORE); - ep->page = h; - ep->index = c->pg.index; - return (RET_SUCCESS); - } - index = c->pg.index; - if (index == 0) { - pg = h->prevpg; - mpool_put(t->bt_mp, h, 0); - if (pg == P_INVALID) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - index = NEXTINDEX(h) - 1; - } else - --index; - break; - } - - ep->page = h; - ep->index = index; - return (RET_SUCCESS); -} - -/* - * __bt_first -- - * Find the first entry. - * - * Parameters: - * t: the tree - * key: the key - * erval: return EPG - * exactp: pointer to exact match flag - * - * Returns: - * The first entry in the tree greater than or equal to key, - * or RET_SPECIAL if no such key exists. - */ -static int -__bt_first(t, key, erval, exactp) - BTREE *t; - const DBT *key; - EPG *erval; - int *exactp; -{ - PAGE *h; - EPG *ep, save; - pgno_t pg; - - /* - * Find any matching record; __bt_search pins the page. - * - * If it's an exact match and duplicates are possible, walk backwards - * in the tree until we find the first one. Otherwise, make sure it's - * a valid key (__bt_search may return an index just past the end of a - * page) and return it. - */ - if ((ep = __bt_search(t, key, exactp)) == NULL) - return (0); - if (*exactp) { - if (F_ISSET(t, B_NODUPS)) { - *erval = *ep; - return (RET_SUCCESS); - } - - /* - * Walk backwards, as long as the entry matches and there are - * keys left in the tree. Save a copy of each match in case - * we go too far. - */ - save = *ep; - h = ep->page; - do { - if (save.page->pgno != ep->page->pgno) { - mpool_put(t->bt_mp, save.page, 0); - save = *ep; - } else - save.index = ep->index; - - /* - * Don't unpin the page the last (or original) match - * was on, but make sure it's unpinned if an error - * occurs. - */ - if (ep->index == 0) { - if (h->prevpg == P_INVALID) - break; - if (h->pgno != save.page->pgno) - mpool_put(t->bt_mp, h, 0); - if ((h = mpool_get(t->bt_mp, - h->prevpg, 0)) == NULL) { - if (h->pgno == save.page->pgno) - mpool_put(t->bt_mp, - save.page, 0); - return (RET_ERROR); - } - ep->page = h; - ep->index = NEXTINDEX(h); - } - --ep->index; - } while (__bt_cmp(t, key, ep) == 0); - - /* - * Reach here with the last page that was looked at pinned, - * which may or may not be the same as the last (or original) - * match page. If it's not useful, release it. - */ - if (h->pgno != save.page->pgno) - mpool_put(t->bt_mp, h, 0); - - *erval = save; - return (RET_SUCCESS); - } - - /* If at the end of a page, find the next entry. */ - if (ep->index == NEXTINDEX(ep->page)) { - h = ep->page; - pg = h->nextpg; - mpool_put(t->bt_mp, h, 0); - if (pg == P_INVALID) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - ep->index = 0; - ep->page = h; - } - *erval = *ep; - return (RET_SUCCESS); -} - -/* - * __bt_setcur -- - * Set the cursor to an entry in the tree. - * - * Parameters: - * t: the tree - * pgno: page number - * index: page index - */ -void -__bt_setcur(t, pgno, index) - BTREE *t; - pgno_t pgno; - u_int index; -{ - /* Lose any already deleted key. */ - if (t->bt_cursor.key.data != NULL) { - free(t->bt_cursor.key.data); - t->bt_cursor.key.size = 0; - t->bt_cursor.key.data = NULL; - } - F_CLR(&t->bt_cursor, CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE); - - /* Update the cursor. */ - t->bt_cursor.pg.pgno = pgno; - t->bt_cursor.pg.index = index; - F_SET(&t->bt_cursor, CURS_INIT); -} diff --git a/db/btree/bt_seq-fbsd.c b/db/btree/bt_seq-fbsd.c new file mode 120000 index 0000000..3a323eb --- /dev/null +++ b/db/btree/bt_seq-fbsd.c @@ -0,0 +1 @@ +./bt_seq.c \ No newline at end of file diff --git a/db/btree/bt_split-fbsd.c b/db/btree/bt_split-fbsd.c deleted file mode 100644 index 07373de..0000000 --- a/db/btree/bt_split-fbsd.c +++ /dev/null @@ -1,827 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_split.c 8.9 (Berkeley) 7/26/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_split.c,v 1.7 2004/09/13 22:07:24 kuriyama Exp $"); - -#include - -#include -#include -#include -#include - -#include -#include "btree.h" - -static int bt_broot(BTREE *, PAGE *, PAGE *, PAGE *); -static PAGE *bt_page (BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t); -static int bt_preserve(BTREE *, pgno_t); -static PAGE *bt_psplit (BTREE *, PAGE *, PAGE *, PAGE *, indx_t *, size_t); -static PAGE *bt_root (BTREE *, PAGE *, PAGE **, PAGE **, indx_t *, size_t); -static int bt_rroot(BTREE *, PAGE *, PAGE *, PAGE *); -static recno_t rec_total(PAGE *); - -#ifdef STATISTICS -u_long bt_rootsplit, bt_split, bt_sortsplit, bt_pfxsaved; -#endif - -/* - * __BT_SPLIT -- Split the tree. - * - * Parameters: - * t: tree - * sp: page to split - * key: key to insert - * data: data to insert - * flags: BIGKEY/BIGDATA flags - * ilen: insert length - * skip: index to leave open - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__bt_split(t, sp, key, data, flags, ilen, argskip) - BTREE *t; - PAGE *sp; - const DBT *key, *data; - int flags; - size_t ilen; - u_int32_t argskip; -{ - BINTERNAL *bi; - BLEAF *bl, *tbl; - DBT a, b; - EPGNO *parent; - PAGE *h, *l, *r, *lchild, *rchild; - indx_t nxtindex; - u_int16_t skip; - u_int32_t n, nbytes, nksize; - int parentsplit; - char *dest; - - /* - * Split the page into two pages, l and r. The split routines return - * a pointer to the page into which the key should be inserted and with - * skip set to the offset which should be used. Additionally, l and r - * are pinned. - */ - skip = argskip; - h = sp->pgno == P_ROOT ? - bt_root(t, sp, &l, &r, &skip, ilen) : - bt_page(t, sp, &l, &r, &skip, ilen); - if (h == NULL) - return (RET_ERROR); - - /* - * Insert the new key/data pair into the leaf page. (Key inserts - * always cause a leaf page to split first.) - */ - h->linp[skip] = h->upper -= ilen; - dest = (char *)h + h->upper; - if (F_ISSET(t, R_RECNO)) - WR_RLEAF(dest, data, flags) - else - WR_BLEAF(dest, key, data, flags) - - /* If the root page was split, make it look right. */ - if (sp->pgno == P_ROOT && - (F_ISSET(t, R_RECNO) ? - bt_rroot(t, sp, l, r) : bt_broot(t, sp, l, r)) == RET_ERROR) - goto err2; - - /* - * Now we walk the parent page stack -- a LIFO stack of the pages that - * were traversed when we searched for the page that split. Each stack - * entry is a page number and a page index offset. The offset is for - * the page traversed on the search. We've just split a page, so we - * have to insert a new key into the parent page. - * - * If the insert into the parent page causes it to split, may have to - * continue splitting all the way up the tree. We stop if the root - * splits or the page inserted into didn't have to split to hold the - * new key. Some algorithms replace the key for the old page as well - * as the new page. We don't, as there's no reason to believe that the - * first key on the old page is any better than the key we have, and, - * in the case of a key being placed at index 0 causing the split, the - * key is unavailable. - * - * There are a maximum of 5 pages pinned at any time. We keep the left - * and right pages pinned while working on the parent. The 5 are the - * two children, left parent and right parent (when the parent splits) - * and the root page or the overflow key page when calling bt_preserve. - * This code must make sure that all pins are released other than the - * root page or overflow page which is unlocked elsewhere. - */ - while ((parent = BT_POP(t)) != NULL) { - lchild = l; - rchild = r; - - /* Get the parent page. */ - if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) - goto err2; - - /* - * The new key goes ONE AFTER the index, because the split - * was to the right. - */ - skip = parent->index + 1; - - /* - * Calculate the space needed on the parent page. - * - * Prefix trees: space hack when inserting into BINTERNAL - * pages. Retain only what's needed to distinguish between - * the new entry and the LAST entry on the page to its left. - * If the keys compare equal, retain the entire key. Note, - * we don't touch overflow keys, and the entire key must be - * retained for the next-to-left most key on the leftmost - * page of each level, or the search will fail. Applicable - * ONLY to internal pages that have leaf pages as children. - * Further reduction of the key between pairs of internal - * pages loses too much information. - */ - switch (rchild->flags & P_TYPE) { - case P_BINTERNAL: - bi = GETBINTERNAL(rchild, 0); - nbytes = NBINTERNAL(bi->ksize); - break; - case P_BLEAF: - bl = GETBLEAF(rchild, 0); - nbytes = NBINTERNAL(bl->ksize); - if (t->bt_pfx && !(bl->flags & P_BIGKEY) && - (h->prevpg != P_INVALID || skip > 1)) { - tbl = GETBLEAF(lchild, NEXTINDEX(lchild) - 1); - a.size = tbl->ksize; - a.data = tbl->bytes; - b.size = bl->ksize; - b.data = bl->bytes; - nksize = t->bt_pfx(&a, &b); - n = NBINTERNAL(nksize); - if (n < nbytes) { -#ifdef STATISTICS - bt_pfxsaved += nbytes - n; -#endif - nbytes = n; - } else - nksize = 0; - } else - nksize = 0; - break; - case P_RINTERNAL: - case P_RLEAF: - nbytes = NRINTERNAL; - break; - default: - abort(); - } - - /* Split the parent page if necessary or shift the indices. */ - if (h->upper - h->lower < nbytes + sizeof(indx_t)) { - sp = h; - h = h->pgno == P_ROOT ? - bt_root(t, h, &l, &r, &skip, nbytes) : - bt_page(t, h, &l, &r, &skip, nbytes); - if (h == NULL) - goto err1; - parentsplit = 1; - } else { - if (skip < (nxtindex = NEXTINDEX(h))) - memmove(h->linp + skip + 1, h->linp + skip, - (nxtindex - skip) * sizeof(indx_t)); - h->lower += sizeof(indx_t); - parentsplit = 0; - } - - /* Insert the key into the parent page. */ - switch (rchild->flags & P_TYPE) { - case P_BINTERNAL: - h->linp[skip] = h->upper -= nbytes; - dest = (char *)h + h->linp[skip]; - memmove(dest, bi, nbytes); - ((BINTERNAL *)dest)->pgno = rchild->pgno; - break; - case P_BLEAF: - h->linp[skip] = h->upper -= nbytes; - dest = (char *)h + h->linp[skip]; - WR_BINTERNAL(dest, nksize ? nksize : bl->ksize, - rchild->pgno, bl->flags & P_BIGKEY); - memmove(dest, bl->bytes, nksize ? nksize : bl->ksize); - if (bl->flags & P_BIGKEY && - bt_preserve(t, *(pgno_t *)bl->bytes) == RET_ERROR) - goto err1; - break; - case P_RINTERNAL: - /* - * Update the left page count. If split - * added at index 0, fix the correct page. - */ - if (skip > 0) - dest = (char *)h + h->linp[skip - 1]; - else - dest = (char *)l + l->linp[NEXTINDEX(l) - 1]; - ((RINTERNAL *)dest)->nrecs = rec_total(lchild); - ((RINTERNAL *)dest)->pgno = lchild->pgno; - - /* Update the right page count. */ - h->linp[skip] = h->upper -= nbytes; - dest = (char *)h + h->linp[skip]; - ((RINTERNAL *)dest)->nrecs = rec_total(rchild); - ((RINTERNAL *)dest)->pgno = rchild->pgno; - break; - case P_RLEAF: - /* - * Update the left page count. If split - * added at index 0, fix the correct page. - */ - if (skip > 0) - dest = (char *)h + h->linp[skip - 1]; - else - dest = (char *)l + l->linp[NEXTINDEX(l) - 1]; - ((RINTERNAL *)dest)->nrecs = NEXTINDEX(lchild); - ((RINTERNAL *)dest)->pgno = lchild->pgno; - - /* Update the right page count. */ - h->linp[skip] = h->upper -= nbytes; - dest = (char *)h + h->linp[skip]; - ((RINTERNAL *)dest)->nrecs = NEXTINDEX(rchild); - ((RINTERNAL *)dest)->pgno = rchild->pgno; - break; - default: - abort(); - } - - /* Unpin the held pages. */ - if (!parentsplit) { - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - break; - } - - /* If the root page was split, make it look right. */ - if (sp->pgno == P_ROOT && - (F_ISSET(t, R_RECNO) ? - bt_rroot(t, sp, l, r) : bt_broot(t, sp, l, r)) == RET_ERROR) - goto err1; - - mpool_put(t->bt_mp, lchild, MPOOL_DIRTY); - mpool_put(t->bt_mp, rchild, MPOOL_DIRTY); - } - - /* Unpin the held pages. */ - mpool_put(t->bt_mp, l, MPOOL_DIRTY); - mpool_put(t->bt_mp, r, MPOOL_DIRTY); - - /* Clear any pages left on the stack. */ - return (RET_SUCCESS); - - /* - * If something fails in the above loop we were already walking back - * up the tree and the tree is now inconsistent. Nothing much we can - * do about it but release any memory we're holding. - */ -err1: mpool_put(t->bt_mp, lchild, MPOOL_DIRTY); - mpool_put(t->bt_mp, rchild, MPOOL_DIRTY); - -err2: mpool_put(t->bt_mp, l, 0); - mpool_put(t->bt_mp, r, 0); - __dbpanic(t->bt_dbp); - return (RET_ERROR); -} - -/* - * BT_PAGE -- Split a non-root page of a btree. - * - * Parameters: - * t: tree - * h: root page - * lp: pointer to left page pointer - * rp: pointer to right page pointer - * skip: pointer to index to leave open - * ilen: insert length - * - * Returns: - * Pointer to page in which to insert or NULL on error. - */ -static PAGE * -bt_page(t, h, lp, rp, skip, ilen) - BTREE *t; - PAGE *h, **lp, **rp; - indx_t *skip; - size_t ilen; -{ - PAGE *l, *r, *tp; - pgno_t npg; - -#ifdef STATISTICS - ++bt_split; -#endif - /* Put the new right page for the split into place. */ - if ((r = __bt_new(t, &npg)) == NULL) - return (NULL); - r->pgno = npg; - r->lower = BTDATAOFF; - r->upper = t->bt_psize; - r->nextpg = h->nextpg; - r->prevpg = h->pgno; - r->flags = h->flags & P_TYPE; - - /* - * If we're splitting the last page on a level because we're appending - * a key to it (skip is NEXTINDEX()), it's likely that the data is - * sorted. Adding an empty page on the side of the level is less work - * and can push the fill factor much higher than normal. If we're - * wrong it's no big deal, we'll just do the split the right way next - * time. It may look like it's equally easy to do a similar hack for - * reverse sorted data, that is, split the tree left, but it's not. - * Don't even try. - */ - if (h->nextpg == P_INVALID && *skip == NEXTINDEX(h)) { -#ifdef STATISTICS - ++bt_sortsplit; -#endif - h->nextpg = r->pgno; - r->lower = BTDATAOFF + sizeof(indx_t); - *skip = 0; - *lp = h; - *rp = r; - return (r); - } - - /* Put the new left page for the split into place. */ - if ((l = (PAGE *)malloc(t->bt_psize)) == NULL) { - mpool_put(t->bt_mp, r, 0); - return (NULL); - } -#ifdef PURIFY - memset(l, 0xff, t->bt_psize); -#endif - l->pgno = h->pgno; - l->nextpg = r->pgno; - l->prevpg = h->prevpg; - l->lower = BTDATAOFF; - l->upper = t->bt_psize; - l->flags = h->flags & P_TYPE; - - /* Fix up the previous pointer of the page after the split page. */ - if (h->nextpg != P_INVALID) { - if ((tp = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL) { - free(l); - /* XXX mpool_free(t->bt_mp, r->pgno); */ - return (NULL); - } - tp->prevpg = r->pgno; - mpool_put(t->bt_mp, tp, MPOOL_DIRTY); - } - - /* - * Split right. The key/data pairs aren't sorted in the btree page so - * it's simpler to copy the data from the split page onto two new pages - * instead of copying half the data to the right page and compacting - * the left page in place. Since the left page can't change, we have - * to swap the original and the allocated left page after the split. - */ - tp = bt_psplit(t, h, l, r, skip, ilen); - - /* Move the new left page onto the old left page. */ - memmove(h, l, t->bt_psize); - if (tp == l) - tp = h; - free(l); - - *lp = h; - *rp = r; - return (tp); -} - -/* - * BT_ROOT -- Split the root page of a btree. - * - * Parameters: - * t: tree - * h: root page - * lp: pointer to left page pointer - * rp: pointer to right page pointer - * skip: pointer to index to leave open - * ilen: insert length - * - * Returns: - * Pointer to page in which to insert or NULL on error. - */ -static PAGE * -bt_root(t, h, lp, rp, skip, ilen) - BTREE *t; - PAGE *h, **lp, **rp; - indx_t *skip; - size_t ilen; -{ - PAGE *l, *r, *tp; - pgno_t lnpg, rnpg; - -#ifdef STATISTICS - ++bt_split; - ++bt_rootsplit; -#endif - /* Put the new left and right pages for the split into place. */ - if ((l = __bt_new(t, &lnpg)) == NULL || - (r = __bt_new(t, &rnpg)) == NULL) - return (NULL); - l->pgno = lnpg; - r->pgno = rnpg; - l->nextpg = r->pgno; - r->prevpg = l->pgno; - l->prevpg = r->nextpg = P_INVALID; - l->lower = r->lower = BTDATAOFF; - l->upper = r->upper = t->bt_psize; - l->flags = r->flags = h->flags & P_TYPE; - - /* Split the root page. */ - tp = bt_psplit(t, h, l, r, skip, ilen); - - *lp = l; - *rp = r; - return (tp); -} - -/* - * BT_RROOT -- Fix up the recno root page after it has been split. - * - * Parameters: - * t: tree - * h: root page - * l: left page - * r: right page - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -static int -bt_rroot(t, h, l, r) - BTREE *t; - PAGE *h, *l, *r; -{ - char *dest; - - /* Insert the left and right keys, set the header information. */ - h->linp[0] = h->upper = t->bt_psize - NRINTERNAL; - dest = (char *)h + h->upper; - WR_RINTERNAL(dest, - l->flags & P_RLEAF ? NEXTINDEX(l) : rec_total(l), l->pgno); - - h->linp[1] = h->upper -= NRINTERNAL; - dest = (char *)h + h->upper; - WR_RINTERNAL(dest, - r->flags & P_RLEAF ? NEXTINDEX(r) : rec_total(r), r->pgno); - - h->lower = BTDATAOFF + 2 * sizeof(indx_t); - - /* Unpin the root page, set to recno internal page. */ - h->flags &= ~P_TYPE; - h->flags |= P_RINTERNAL; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - - return (RET_SUCCESS); -} - -/* - * BT_BROOT -- Fix up the btree root page after it has been split. - * - * Parameters: - * t: tree - * h: root page - * l: left page - * r: right page - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -static int -bt_broot(t, h, l, r) - BTREE *t; - PAGE *h, *l, *r; -{ - BINTERNAL *bi; - BLEAF *bl; - u_int32_t nbytes; - char *dest; - - /* - * If the root page was a leaf page, change it into an internal page. - * We copy the key we split on (but not the key's data, in the case of - * a leaf page) to the new root page. - * - * The btree comparison code guarantees that the left-most key on any - * level of the tree is never used, so it doesn't need to be filled in. - */ - nbytes = NBINTERNAL(0); - h->linp[0] = h->upper = t->bt_psize - nbytes; - dest = (char *)h + h->upper; - WR_BINTERNAL(dest, 0, l->pgno, 0); - - switch (h->flags & P_TYPE) { - case P_BLEAF: - bl = GETBLEAF(r, 0); - nbytes = NBINTERNAL(bl->ksize); - h->linp[1] = h->upper -= nbytes; - dest = (char *)h + h->upper; - WR_BINTERNAL(dest, bl->ksize, r->pgno, 0); - memmove(dest, bl->bytes, bl->ksize); - - /* - * If the key is on an overflow page, mark the overflow chain - * so it isn't deleted when the leaf copy of the key is deleted. - */ - if (bl->flags & P_BIGKEY && - bt_preserve(t, *(pgno_t *)bl->bytes) == RET_ERROR) - return (RET_ERROR); - break; - case P_BINTERNAL: - bi = GETBINTERNAL(r, 0); - nbytes = NBINTERNAL(bi->ksize); - h->linp[1] = h->upper -= nbytes; - dest = (char *)h + h->upper; - memmove(dest, bi, nbytes); - ((BINTERNAL *)dest)->pgno = r->pgno; - break; - default: - abort(); - } - - /* There are two keys on the page. */ - h->lower = BTDATAOFF + 2 * sizeof(indx_t); - - /* Unpin the root page, set to btree internal page. */ - h->flags &= ~P_TYPE; - h->flags |= P_BINTERNAL; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - - return (RET_SUCCESS); -} - -/* - * BT_PSPLIT -- Do the real work of splitting the page. - * - * Parameters: - * t: tree - * h: page to be split - * l: page to put lower half of data - * r: page to put upper half of data - * pskip: pointer to index to leave open - * ilen: insert length - * - * Returns: - * Pointer to page in which to insert. - */ -static PAGE * -bt_psplit(t, h, l, r, pskip, ilen) - BTREE *t; - PAGE *h, *l, *r; - indx_t *pskip; - size_t ilen; -{ - BINTERNAL *bi; - BLEAF *bl; - CURSOR *c; - RLEAF *rl; - PAGE *rval; - void *src; - indx_t full, half, nxt, off, skip, top, used; - u_int32_t nbytes; - int bigkeycnt, isbigkey; - - /* - * Split the data to the left and right pages. Leave the skip index - * open. Additionally, make some effort not to split on an overflow - * key. This makes internal page processing faster and can save - * space as overflow keys used by internal pages are never deleted. - */ - bigkeycnt = 0; - skip = *pskip; - full = t->bt_psize - BTDATAOFF; - half = full / 2; - used = 0; - for (nxt = off = 0, top = NEXTINDEX(h); nxt < top; ++off) { - if (skip == off) { - nbytes = ilen; - isbigkey = 0; /* XXX: not really known. */ - } else - switch (h->flags & P_TYPE) { - case P_BINTERNAL: - src = bi = GETBINTERNAL(h, nxt); - nbytes = NBINTERNAL(bi->ksize); - isbigkey = bi->flags & P_BIGKEY; - break; - case P_BLEAF: - src = bl = GETBLEAF(h, nxt); - nbytes = NBLEAF(bl); - isbigkey = bl->flags & P_BIGKEY; - break; - case P_RINTERNAL: - src = GETRINTERNAL(h, nxt); - nbytes = NRINTERNAL; - isbigkey = 0; - break; - case P_RLEAF: - src = rl = GETRLEAF(h, nxt); - nbytes = NRLEAF(rl); - isbigkey = 0; - break; - default: - abort(); - } - - /* - * If the key/data pairs are substantial fractions of the max - * possible size for the page, it's possible to get situations - * where we decide to try and copy too much onto the left page. - * Make sure that doesn't happen. - */ - if ((skip <= off && used + nbytes + sizeof(indx_t) >= full) - || nxt == top - 1) { - --off; - break; - } - - /* Copy the key/data pair, if not the skipped index. */ - if (skip != off) { - ++nxt; - - l->linp[off] = l->upper -= nbytes; - memmove((char *)l + l->upper, src, nbytes); - } - - used += nbytes + sizeof(indx_t); - if (used >= half) { - if (!isbigkey || bigkeycnt == 3) - break; - else - ++bigkeycnt; - } - } - - /* - * Off is the last offset that's valid for the left page. - * Nxt is the first offset to be placed on the right page. - */ - l->lower += (off + 1) * sizeof(indx_t); - - /* - * If splitting the page that the cursor was on, the cursor has to be - * adjusted to point to the same record as before the split. If the - * cursor is at or past the skipped slot, the cursor is incremented by - * one. If the cursor is on the right page, it is decremented by the - * number of records split to the left page. - */ - c = &t->bt_cursor; - if (F_ISSET(c, CURS_INIT) && c->pg.pgno == h->pgno) { - if (c->pg.index >= skip) - ++c->pg.index; - if (c->pg.index < nxt) /* Left page. */ - c->pg.pgno = l->pgno; - else { /* Right page. */ - c->pg.pgno = r->pgno; - c->pg.index -= nxt; - } - } - - /* - * If the skipped index was on the left page, just return that page. - * Otherwise, adjust the skip index to reflect the new position on - * the right page. - */ - if (skip <= off) { - skip = MAX_PAGE_OFFSET; - rval = l; - } else { - rval = r; - *pskip -= nxt; - } - - for (off = 0; nxt < top; ++off) { - if (skip == nxt) { - ++off; - skip = MAX_PAGE_OFFSET; - } - switch (h->flags & P_TYPE) { - case P_BINTERNAL: - src = bi = GETBINTERNAL(h, nxt); - nbytes = NBINTERNAL(bi->ksize); - break; - case P_BLEAF: - src = bl = GETBLEAF(h, nxt); - nbytes = NBLEAF(bl); - break; - case P_RINTERNAL: - src = GETRINTERNAL(h, nxt); - nbytes = NRINTERNAL; - break; - case P_RLEAF: - src = rl = GETRLEAF(h, nxt); - nbytes = NRLEAF(rl); - break; - default: - abort(); - } - ++nxt; - r->linp[off] = r->upper -= nbytes; - memmove((char *)r + r->upper, src, nbytes); - } - r->lower += off * sizeof(indx_t); - - /* If the key is being appended to the page, adjust the index. */ - if (skip == top) - r->lower += sizeof(indx_t); - - return (rval); -} - -/* - * BT_PRESERVE -- Mark a chain of pages as used by an internal node. - * - * Chains of indirect blocks pointed to by leaf nodes get reclaimed when the - * record that references them gets deleted. Chains pointed to by internal - * pages never get deleted. This routine marks a chain as pointed to by an - * internal page. - * - * Parameters: - * t: tree - * pg: page number of first page in the chain. - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -static int -bt_preserve(t, pg) - BTREE *t; - pgno_t pg; -{ - PAGE *h; - - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); - h->flags |= P_PRESERVE; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - return (RET_SUCCESS); -} - -/* - * REC_TOTAL -- Return the number of recno entries below a page. - * - * Parameters: - * h: page - * - * Returns: - * The number of recno entries below a page. - * - * XXX - * These values could be set by the bt_psplit routine. The problem is that the - * entry has to be popped off of the stack etc. or the values have to be passed - * all the way back to bt_split/bt_rroot and it's not very clean. - */ -static recno_t -rec_total(h) - PAGE *h; -{ - recno_t recs; - indx_t nxt, top; - - for (recs = 0, nxt = 0, top = NEXTINDEX(h); nxt < top; ++nxt) - recs += GETRINTERNAL(h, nxt)->nrecs; - return (recs); -} diff --git a/db/btree/bt_split-fbsd.c b/db/btree/bt_split-fbsd.c new file mode 120000 index 0000000..9f98aa9 --- /dev/null +++ b/db/btree/bt_split-fbsd.c @@ -0,0 +1 @@ +./bt_split.c \ No newline at end of file diff --git a/db/btree/bt_utils-fbsd.c b/db/btree/bt_utils-fbsd.c deleted file mode 100644 index e9acfb7..0000000 --- a/db/btree/bt_utils-fbsd.c +++ /dev/null @@ -1,262 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_utils.c 8.8 (Berkeley) 7/20/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_utils.c,v 1.3 2003/01/01 18:48:42 schweikh Exp $"); - -#include - -#include -#include -#include - -#include -#include "btree.h" - -/* - * __bt_ret -- - * Build return key/data pair. - * - * Parameters: - * t: tree - * e: key/data pair to be returned - * key: user's key structure (NULL if not to be filled in) - * rkey: memory area to hold key - * data: user's data structure (NULL if not to be filled in) - * rdata: memory area to hold data - * copy: always copy the key/data item - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__bt_ret(t, e, key, rkey, data, rdata, copy) - BTREE *t; - EPG *e; - DBT *key, *rkey, *data, *rdata; - int copy; -{ - BLEAF *bl; - void *p; - - bl = GETBLEAF(e->page, e->index); - - /* - * We must copy big keys/data to make them contigous. Otherwise, - * leave the page pinned and don't copy unless the user specified - * concurrent access. - */ - if (key == NULL) - goto dataonly; - - if (bl->flags & P_BIGKEY) { - if (__ovfl_get(t, bl->bytes, - &key->size, &rkey->data, &rkey->size)) - return (RET_ERROR); - key->data = rkey->data; - } else if (copy || F_ISSET(t, B_DB_LOCK)) { - if (bl->ksize > rkey->size) { - p = (void *)(rkey->data == NULL ? - malloc(bl->ksize) : realloc(rkey->data, bl->ksize)); - if (p == NULL) - return (RET_ERROR); - rkey->data = p; - rkey->size = bl->ksize; - } - memmove(rkey->data, bl->bytes, bl->ksize); - key->size = bl->ksize; - key->data = rkey->data; - } else { - key->size = bl->ksize; - key->data = bl->bytes; - } - -dataonly: - if (data == NULL) - return (RET_SUCCESS); - - if (bl->flags & P_BIGDATA) { - if (__ovfl_get(t, bl->bytes + bl->ksize, - &data->size, &rdata->data, &rdata->size)) - return (RET_ERROR); - data->data = rdata->data; - } else if (copy || F_ISSET(t, B_DB_LOCK)) { - /* Use +1 in case the first record retrieved is 0 length. */ - if (bl->dsize + 1 > rdata->size) { - p = (void *)(rdata->data == NULL ? - malloc(bl->dsize + 1) : - realloc(rdata->data, bl->dsize + 1)); - if (p == NULL) - return (RET_ERROR); - rdata->data = p; - rdata->size = bl->dsize + 1; - } - memmove(rdata->data, bl->bytes + bl->ksize, bl->dsize); - data->size = bl->dsize; - data->data = rdata->data; - } else { - data->size = bl->dsize; - data->data = bl->bytes + bl->ksize; - } - - return (RET_SUCCESS); -} - -/* - * __BT_CMP -- Compare a key to a given record. - * - * Parameters: - * t: tree - * k1: DBT pointer of first arg to comparison - * e: pointer to EPG for comparison - * - * Returns: - * < 0 if k1 is < record - * = 0 if k1 is = record - * > 0 if k1 is > record - */ -int -__bt_cmp(t, k1, e) - BTREE *t; - const DBT *k1; - EPG *e; -{ - BINTERNAL *bi; - BLEAF *bl; - DBT k2; - PAGE *h; - void *bigkey; - - /* - * The left-most key on internal pages, at any level of the tree, is - * guaranteed by the following code to be less than any user key. - * This saves us from having to update the leftmost key on an internal - * page when the user inserts a new key in the tree smaller than - * anything we've yet seen. - */ - h = e->page; - if (e->index == 0 && h->prevpg == P_INVALID && !(h->flags & P_BLEAF)) - return (1); - - bigkey = NULL; - if (h->flags & P_BLEAF) { - bl = GETBLEAF(h, e->index); - if (bl->flags & P_BIGKEY) - bigkey = bl->bytes; - else { - k2.data = bl->bytes; - k2.size = bl->ksize; - } - } else { - bi = GETBINTERNAL(h, e->index); - if (bi->flags & P_BIGKEY) - bigkey = bi->bytes; - else { - k2.data = bi->bytes; - k2.size = bi->ksize; - } - } - - if (bigkey) { - if (__ovfl_get(t, bigkey, - &k2.size, &t->bt_rdata.data, &t->bt_rdata.size)) - return (RET_ERROR); - k2.data = t->bt_rdata.data; - } - return ((*t->bt_cmp)(k1, &k2)); -} - -/* - * __BT_DEFCMP -- Default comparison routine. - * - * Parameters: - * a: DBT #1 - * b: DBT #2 - * - * Returns: - * < 0 if a is < b - * = 0 if a is = b - * > 0 if a is > b - */ -int -__bt_defcmp(a, b) - const DBT *a, *b; -{ - size_t len; - u_char *p1, *p2; - - /* - * XXX - * If a size_t doesn't fit in an int, this routine can lose. - * What we need is an integral type which is guaranteed to be - * larger than a size_t, and there is no such thing. - */ - len = MIN(a->size, b->size); - for (p1 = a->data, p2 = b->data; len--; ++p1, ++p2) - if (*p1 != *p2) - return ((int)*p1 - (int)*p2); - return ((int)a->size - (int)b->size); -} - -/* - * __BT_DEFPFX -- Default prefix routine. - * - * Parameters: - * a: DBT #1 - * b: DBT #2 - * - * Returns: - * Number of bytes needed to distinguish b from a. - */ -size_t -__bt_defpfx(a, b) - const DBT *a, *b; -{ - u_char *p1, *p2; - size_t cnt, len; - - cnt = 1; - len = MIN(a->size, b->size); - for (p1 = a->data, p2 = b->data; len--; ++p1, ++p2, ++cnt) - if (*p1 != *p2) - return (cnt); - - /* a->size must be <= b->size, or they wouldn't be in this order. */ - return (a->size < b->size ? a->size + 1 : a->size); -} diff --git a/db/btree/bt_utils-fbsd.c b/db/btree/bt_utils-fbsd.c new file mode 120000 index 0000000..aa281da --- /dev/null +++ b/db/btree/bt_utils-fbsd.c @@ -0,0 +1 @@ +./bt_utils.c \ No newline at end of file diff --git a/db/db/Makefile.inc b/db/db/Makefile.inc index 73c57e9..c5739d4 100644 --- a/db/db/Makefile.inc +++ b/db/db/Makefile.inc @@ -2,6 +2,7 @@ # $FreeBSD: src/lib/libc/db/db/Makefile.inc,v 1.4 2002/11/18 09:50:54 ru Exp $ .PATH: ${.CURDIR}/db/db +CWD := ${.CURDIR}/db/db .include "Makefile.fbsd_begin" FBSDMISRCS= db.c diff --git a/db/db/db-fbsd.c b/db/db/db-fbsd.c deleted file mode 100644 index 9c65e55..0000000 --- a/db/db/db-fbsd.c +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)db.c 8.4 (Berkeley) 2/21/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/db/db.c,v 1.2 2002/03/22 21:52:01 obrien Exp $"); - -#include - -#include -#include -#include -#include - -#include - -DB * -dbopen(fname, flags, mode, type, openinfo) - const char *fname; - int flags, mode; - DBTYPE type; - const void *openinfo; -{ - -#define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN) -#define USE_OPEN_FLAGS \ - (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \ - O_RDWR | O_SHLOCK | O_TRUNC) - - if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) - switch (type) { - case DB_BTREE: - return (__bt_open(fname, flags & USE_OPEN_FLAGS, - mode, openinfo, flags & DB_FLAGS)); - case DB_HASH: - return (__hash_open(fname, flags & USE_OPEN_FLAGS, - mode, openinfo, flags & DB_FLAGS)); - case DB_RECNO: - return (__rec_open(fname, flags & USE_OPEN_FLAGS, - mode, openinfo, flags & DB_FLAGS)); - } - errno = EINVAL; - return (NULL); -} - -static int -__dberr() -{ - return (RET_ERROR); -} - -/* - * __DBPANIC -- Stop. - * - * Parameters: - * dbp: pointer to the DB structure. - */ -void -__dbpanic(dbp) - DB *dbp; -{ - /* The only thing that can succeed is a close. */ - dbp->del = (int (*)())__dberr; - dbp->fd = (int (*)())__dberr; - dbp->get = (int (*)())__dberr; - dbp->put = (int (*)())__dberr; - dbp->seq = (int (*)())__dberr; - dbp->sync = (int (*)())__dberr; -} diff --git a/db/db/db-fbsd.c b/db/db/db-fbsd.c new file mode 120000 index 0000000..0f977fb --- /dev/null +++ b/db/db/db-fbsd.c @@ -0,0 +1 @@ +./db.c \ No newline at end of file diff --git a/db/hash/Makefile.inc b/db/hash/Makefile.inc index 136ae02..7efd016 100644 --- a/db/hash/Makefile.inc +++ b/db/hash/Makefile.inc @@ -2,6 +2,7 @@ # $FreeBSD: src/lib/libc/db/hash/Makefile.inc,v 1.5 2002/11/18 09:50:54 ru Exp $ .PATH: ${.CURDIR}/db/hash +CWD := ${.CURDIR}/db/hash .include "Makefile.fbsd_begin" FBSDMISRCS= hash.c hash_bigkey.c hash_buf.c hash_func.c hash_log2.c \ @@ -17,6 +18,11 @@ FBSDHDRS= hash.h page.h # need to rename extern.h to make it unique .ifmake autopatch -hash_extern.h: FreeBSD/extern.h _AUTOPATCHCUR -AUTOPATCHHDRS+= hash_extern.h + +# This .for statement forces evaluation of ${CWD} +.for _cwd in ${CWD} +${_cwd}/hash_extern.h: ${_cwd}/FreeBSD/extern.h _AUTOPATCH +AUTOPATCHHDRS+= ${_cwd}/hash_extern.h +.endfor # _cwd + .endif # autopatch diff --git a/db/hash/hash_extern.h b/db/hash/hash_extern.h deleted file mode 100644 index 2259ac0..0000000 --- a/db/hash/hash_extern.h +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 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. - * - * @(#)extern.h 8.4 (Berkeley) 6/16/94 - * $FreeBSD: src/lib/libc/db/hash/extern.h,v 1.3 2002/03/22 09:18:22 obrien Exp $ - */ - -BUFHEAD *__add_ovflpage(HTAB *, BUFHEAD *); -int __addel(HTAB *, BUFHEAD *, const DBT *, const DBT *); -int __big_delete(HTAB *, BUFHEAD *); -int __big_insert(HTAB *, BUFHEAD *, const DBT *, const DBT *); -int __big_keydata(HTAB *, BUFHEAD *, DBT *, DBT *, int); -int __big_return(HTAB *, BUFHEAD *, int, DBT *, int); -int __big_split(HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *, - int, u_int32_t, SPLIT_RETURN *); -int __buf_free(HTAB *, int, int); -void __buf_init(HTAB *, int); -u_int32_t __call_hash(HTAB *, char *, int); -int __delpair(HTAB *, BUFHEAD *, int); -int __expand_table(HTAB *); -int __find_bigpair(HTAB *, BUFHEAD *, int, char *, int); -u_int16_t __find_last_page(HTAB *, BUFHEAD **); -void __free_ovflpage(HTAB *, BUFHEAD *); -BUFHEAD *__get_buf(HTAB *, u_int32_t, BUFHEAD *, int); -int __get_page(HTAB *, char *, u_int32_t, int, int, int); -int __ibitmap(HTAB *, int, int, int); -u_int32_t __log2(u_int32_t); -int __put_page(HTAB *, char *, u_int32_t, int, int); -void __reclaim_buf(HTAB *, BUFHEAD *); -int __split_page(HTAB *, u_int32_t, u_int32_t); - -/* Default hash routine. */ -extern u_int32_t (*__default_hash)(const void *, size_t); - -#ifdef HASH_STATISTICS -extern int hash_accesses, hash_collisions, hash_expansions, hash_overflows; -#endif diff --git a/db/hash/hash_extern.h b/db/hash/hash_extern.h new file mode 120000 index 0000000..70017bf --- /dev/null +++ b/db/hash/hash_extern.h @@ -0,0 +1 @@ +./extern.h \ No newline at end of file diff --git a/db/hash/hash_log2-fbsd.c b/db/hash/hash_log2-fbsd.c deleted file mode 100644 index 827dbef..0000000 --- a/db/hash/hash_log2-fbsd.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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[] = "@(#)hash_log2.c 8.2 (Berkeley) 5/31/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/hash/hash_log2.c,v 1.2 2002/03/21 18:47:38 obrien Exp $"); - -#include - -#include - -u_int32_t -__log2(num) - u_int32_t num; -{ - u_int32_t i, limit; - - limit = 1; - for (i = 0; limit < num; limit = limit << 1, i++); - return (i); -} diff --git a/db/hash/hash_log2-fbsd.c b/db/hash/hash_log2-fbsd.c new file mode 120000 index 0000000..ee8306e --- /dev/null +++ b/db/hash/hash_log2-fbsd.c @@ -0,0 +1 @@ +./hash_log2.c \ No newline at end of file diff --git a/db/hash/page.h b/db/hash/page.h deleted file mode 100644 index 2cf7460..0000000 --- a/db/hash/page.h +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * 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. - * - * @(#)page.h 8.2 (Berkeley) 5/31/94 - * $FreeBSD: src/lib/libc/db/hash/page.h,v 1.2 2002/03/22 23:41:40 obrien Exp $ - */ - -/* - * Definitions for hashing page file format. - */ - -/* - * routines dealing with a data page - * - * page format: - * +------------------------------+ - * p | n | keyoff | datoff | keyoff | - * +------------+--------+--------+ - * | datoff | free | ptr | --> | - * +--------+---------------------+ - * | F R E E A R E A | - * +--------------+---------------+ - * | <---- - - - | data | - * +--------+-----+----+----------+ - * | key | data | key | - * +--------+----------+----------+ - * - * Pointer to the free space is always: p[p[0] + 2] - * Amount of free space on the page is: p[p[0] + 1] - */ - -/* - * How many bytes required for this pair? - * 2 shorts in the table at the top of the page + room for the - * key and room for the data - * - * We prohibit entering a pair on a page unless there is also room to append - * an overflow page. The reason for this it that you can get in a situation - * where a single key/data pair fits on a page, but you can't append an - * overflow page and later you'd have to split the key/data and handle like - * a big pair. - * You might as well do this up front. - */ - -#define PAIRSIZE(K,D) (2*sizeof(u_int16_t) + (K)->size + (D)->size) -#define BIGOVERHEAD (4*sizeof(u_int16_t)) -#define KEYSIZE(K) (4*sizeof(u_int16_t) + (K)->size); -#define OVFLSIZE (2*sizeof(u_int16_t)) -#define FREESPACE(P) ((P)[(P)[0]+1]) -#define OFFSET(P) ((P)[(P)[0]+2]) -#define PAIRFITS(P,K,D) \ - (((P)[2] >= REAL_KEY) && \ - (PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P))) -#define PAGE_META(N) (((N)+3) * sizeof(u_int16_t)) - -typedef struct { - BUFHEAD *newp; - BUFHEAD *oldp; - BUFHEAD *nextp; - u_int16_t next_addr; -} SPLIT_RETURN; diff --git a/db/hash/page.h b/db/hash/page.h new file mode 120000 index 0000000..0fb054f --- /dev/null +++ b/db/hash/page.h @@ -0,0 +1 @@ +./page.h \ No newline at end of file diff --git a/db/man/Makefile.inc b/db/man/Makefile.inc index 220233a..86b03ff 100644 --- a/db/man/Makefile.inc +++ b/db/man/Makefile.inc @@ -2,6 +2,7 @@ # $FreeBSD: src/lib/libc/db/man/Makefile.inc,v 1.11 2002/11/18 09:50:54 ru Exp $ .PATH: ${.CURDIR}/db/man +CWD := ${.CURDIR}/db/man .if ${LIB} == "c" .include "Makefile.fbsd_begin" diff --git a/db/mpool/Makefile.inc b/db/mpool/Makefile.inc index e3ecef0..9b5775e 100644 --- a/db/mpool/Makefile.inc +++ b/db/mpool/Makefile.inc @@ -2,6 +2,7 @@ # $FreeBSD: src/lib/libc/db/mpool/Makefile.inc,v 1.4 2002/11/18 09:50:55 ru Exp $ .PATH: ${.CURDIR}/db/mpool +CWD := ${.CURDIR}/db/mpool .include "Makefile.fbsd_begin" FBSDMISRCS= mpool.c diff --git a/db/recno/Makefile.inc b/db/recno/Makefile.inc index 70f2236..5129970 100644 --- a/db/recno/Makefile.inc +++ b/db/recno/Makefile.inc @@ -2,6 +2,7 @@ # $FreeBSD: src/lib/libc/db/recno/Makefile.inc,v 1.4 2002/11/18 09:50:55 ru Exp $ .PATH: ${.CURDIR}/db/recno +CWD := ${.CURDIR}/db/recno .include "Makefile.fbsd_begin" FBSDMISRCS= rec_close.c rec_delete.c rec_get.c rec_open.c rec_put.c rec_search.c \ @@ -14,6 +15,11 @@ FBSDHDRS= recno.h # need to rename extern.h to make it unique .ifmake autopatch -rec_extern.h: FreeBSD/extern.h _AUTOPATCHCUR -AUTOPATCHHDRS+= rec_extern.h + +# This .for statement forces evaluation of ${CWD} +.for _cwd in ${CWD} +${_cwd}/rec_extern.h: ${_cwd}/FreeBSD/extern.h _AUTOPATCH +AUTOPATCHHDRS+= ${_cwd}/rec_extern.h +.endfor # _cwd + .endif # autopatch diff --git a/db/recno/rec_close-fbsd.c b/db/recno/rec_close-fbsd.c deleted file mode 100644 index fea96ae..0000000 --- a/db/recno/rec_close-fbsd.c +++ /dev/null @@ -1,188 +0,0 @@ -/*- - * 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[] = "@(#)rec_close.c 8.6 (Berkeley) 8/18/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/recno/rec_close.c,v 1.7 2003/02/16 17:29:09 nectar Exp $"); - -#include "namespace.h" -#include -#include -#include - -#include -#include -#include -#include -#include "un-namespace.h" - -#include -#include "recno.h" - -/* - * __REC_CLOSE -- Close a recno tree. - * - * Parameters: - * dbp: pointer to access method - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_close(dbp) - DB *dbp; -{ - BTREE *t; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - if (__rec_sync(dbp, 0) == RET_ERROR) - return (RET_ERROR); - - /* Committed to closing. */ - status = RET_SUCCESS; - if (F_ISSET(t, R_MEMMAPPED) && munmap(t->bt_smap, t->bt_msize)) - status = RET_ERROR; - - if (!F_ISSET(t, R_INMEM)) { - if (F_ISSET(t, R_CLOSEFP)) { - if (fclose(t->bt_rfp)) - status = RET_ERROR; - } else - if (_close(t->bt_rfd)) - status = RET_ERROR; - } - - if (__bt_close(dbp) == RET_ERROR) - status = RET_ERROR; - - return (status); -} - -/* - * __REC_SYNC -- sync the recno tree to disk. - * - * Parameters: - * dbp: pointer to access method - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__rec_sync(dbp, flags) - const DB *dbp; - u_int flags; -{ - struct iovec iov[2]; - BTREE *t; - DBT data, key; - off_t off; - recno_t scursor, trec; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - if (flags == R_RECNOSYNC) - return (__bt_sync(dbp, 0)); - - if (F_ISSET(t, R_RDONLY | R_INMEM) || !F_ISSET(t, R_MODIFIED)) - return (RET_SUCCESS); - - /* Read any remaining records into the tree. */ - if (!F_ISSET(t, R_EOF) && t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) - return (RET_ERROR); - - /* Rewind the file descriptor. */ - if (lseek(t->bt_rfd, (off_t)0, SEEK_SET) != 0) - return (RET_ERROR); - - /* Save the cursor. */ - scursor = t->bt_cursor.rcursor; - - key.size = sizeof(recno_t); - key.data = &trec; - - if (F_ISSET(t, R_FIXLEN)) { - /* - * We assume that fixed length records are all fixed length. - * Any that aren't are either EINVAL'd or corrected by the - * record put code. - */ - status = (dbp->seq)(dbp, &key, &data, R_FIRST); - while (status == RET_SUCCESS) { - if (_write(t->bt_rfd, data.data, data.size) != - data.size) - return (RET_ERROR); - status = (dbp->seq)(dbp, &key, &data, R_NEXT); - } - } else { - iov[1].iov_base = (char *)&t->bt_bval; - iov[1].iov_len = 1; - - status = (dbp->seq)(dbp, &key, &data, R_FIRST); - while (status == RET_SUCCESS) { - iov[0].iov_base = data.data; - iov[0].iov_len = data.size; - if (_writev(t->bt_rfd, iov, 2) != data.size + 1) - return (RET_ERROR); - status = (dbp->seq)(dbp, &key, &data, R_NEXT); - } - } - - /* Restore the cursor. */ - t->bt_cursor.rcursor = scursor; - - if (status == RET_ERROR) - return (RET_ERROR); - if ((off = lseek(t->bt_rfd, (off_t)0, SEEK_CUR)) == -1) - return (RET_ERROR); - if (ftruncate(t->bt_rfd, off)) - return (RET_ERROR); - F_CLR(t, R_MODIFIED); - return (RET_SUCCESS); -} diff --git a/db/recno/rec_close-fbsd.c b/db/recno/rec_close-fbsd.c new file mode 120000 index 0000000..31b4ea9 --- /dev/null +++ b/db/recno/rec_close-fbsd.c @@ -0,0 +1 @@ +./rec_close.c \ No newline at end of file diff --git a/db/recno/rec_delete-fbsd.c b/db/recno/rec_delete-fbsd.c deleted file mode 100644 index 1205594..0000000 --- a/db/recno/rec_delete-fbsd.c +++ /dev/null @@ -1,199 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rec_delete.c 8.7 (Berkeley) 7/14/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/recno/rec_delete.c,v 1.2 2002/03/21 22:46:28 obrien Exp $"); - -#include - -#include -#include -#include - -#include -#include "recno.h" - -static int rec_rdelete(BTREE *, recno_t); - -/* - * __REC_DELETE -- Delete the item(s) referenced by a key. - * - * Parameters: - * dbp: pointer to access method - * key: key to delete - * flags: R_CURSOR if deleting what the cursor references - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -int -__rec_delete(dbp, key, flags) - const DB *dbp; - const DBT *key; - u_int flags; -{ - BTREE *t; - recno_t nrec; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - switch(flags) { - case 0: - if ((nrec = *(recno_t *)key->data) == 0) - goto einval; - if (nrec > t->bt_nrecs) - return (RET_SPECIAL); - --nrec; - status = rec_rdelete(t, nrec); - break; - case R_CURSOR: - if (!F_ISSET(&t->bt_cursor, CURS_INIT)) - goto einval; - if (t->bt_nrecs == 0) - return (RET_SPECIAL); - status = rec_rdelete(t, t->bt_cursor.rcursor - 1); - if (status == RET_SUCCESS) - --t->bt_cursor.rcursor; - break; - default: -einval: errno = EINVAL; - return (RET_ERROR); - } - - if (status == RET_SUCCESS) - F_SET(t, B_MODIFIED | R_MODIFIED); - return (status); -} - -/* - * REC_RDELETE -- Delete the data matching the specified key. - * - * Parameters: - * tree: tree - * nrec: record to delete - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -static int -rec_rdelete(t, nrec) - BTREE *t; - recno_t nrec; -{ - EPG *e; - PAGE *h; - int status; - - /* Find the record; __rec_search pins the page. */ - if ((e = __rec_search(t, nrec, SDELETE)) == NULL) - return (RET_ERROR); - - /* Delete the record. */ - h = e->page; - status = __rec_dleaf(t, h, e->index); - if (status != RET_SUCCESS) { - mpool_put(t->bt_mp, h, 0); - return (status); - } - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - return (RET_SUCCESS); -} - -/* - * __REC_DLEAF -- Delete a single record from a recno leaf page. - * - * Parameters: - * t: tree - * index: index on current page to delete - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__rec_dleaf(t, h, index) - BTREE *t; - PAGE *h; - u_int32_t index; -{ - RLEAF *rl; - indx_t *ip, cnt, offset; - u_int32_t nbytes; - char *from; - void *to; - - /* - * Delete a record from a recno leaf page. Internal records are never - * deleted from internal pages, regardless of the records that caused - * them to be added being deleted. Pages made empty by deletion are - * not reclaimed. They are, however, made available for reuse. - * - * Pack the remaining entries at the end of the page, shift the indices - * down, overwriting the deleted record and its index. If the record - * uses overflow pages, make them available for reuse. - */ - to = rl = GETRLEAF(h, index); - if (rl->flags & P_BIGDATA && __ovfl_delete(t, rl->bytes) == RET_ERROR) - return (RET_ERROR); - nbytes = NRLEAF(rl); - - /* - * Compress the key/data pairs. Compress and adjust the [BR]LEAF - * offsets. Reset the headers. - */ - from = (char *)h + h->upper; - memmove(from + nbytes, from, (char *)to - from); - h->upper += nbytes; - - offset = h->linp[index]; - for (cnt = &h->linp[index] - (ip = &h->linp[0]); cnt--; ++ip) - if (ip[0] < offset) - ip[0] += nbytes; - for (cnt = &h->linp[NEXTINDEX(h)] - ip; --cnt; ++ip) - ip[0] = ip[1] < offset ? ip[1] + nbytes : ip[1]; - h->lower -= sizeof(indx_t); - --t->bt_nrecs; - return (RET_SUCCESS); -} diff --git a/db/recno/rec_delete-fbsd.c b/db/recno/rec_delete-fbsd.c new file mode 120000 index 0000000..99b089d --- /dev/null +++ b/db/recno/rec_delete-fbsd.c @@ -0,0 +1 @@ +./rec_delete.c \ No newline at end of file diff --git a/db/recno/rec_get-fbsd.c b/db/recno/rec_get-fbsd.c deleted file mode 100644 index d9da658..0000000 --- a/db/recno/rec_get-fbsd.c +++ /dev/null @@ -1,313 +0,0 @@ -/*- - * 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[] = "@(#)rec_get.c 8.9 (Berkeley) 8/18/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/recno/rec_get.c,v 1.5 2002/03/22 21:52:02 obrien Exp $"); - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include "recno.h" - -/* - * __REC_GET -- Get a record from the btree. - * - * Parameters: - * dbp: pointer to access method - * key: key to find - * data: data to return - * flag: currently unused - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. - */ -int -__rec_get(dbp, key, data, flags) - const DB *dbp; - const DBT *key; - DBT *data; - u_int flags; -{ - BTREE *t; - EPG *e; - recno_t nrec; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* Get currently doesn't take any flags, and keys of 0 are illegal. */ - if (flags || (nrec = *(recno_t *)key->data) == 0) { - errno = EINVAL; - return (RET_ERROR); - } - - /* - * If we haven't seen this record yet, try to find it in the - * original file. - */ - if (nrec > t->bt_nrecs) { - if (F_ISSET(t, R_EOF | R_INMEM)) - return (RET_SPECIAL); - if ((status = t->bt_irec(t, nrec)) != RET_SUCCESS) - return (status); - } - - --nrec; - if ((e = __rec_search(t, nrec, SEARCH)) == NULL) - return (RET_ERROR); - - status = __rec_ret(t, e, 0, NULL, data); - if (F_ISSET(t, B_DB_LOCK)) - mpool_put(t->bt_mp, e->page, 0); - else - t->bt_pinned = e->page; - return (status); -} - -/* - * __REC_FPIPE -- Get fixed length records from a pipe. - * - * Parameters: - * t: tree - * cnt: records to read - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_fpipe(t, top) - BTREE *t; - recno_t top; -{ - DBT data; - recno_t nrec; - size_t len; - int ch; - u_char *p; - - if (t->bt_rdata.size < t->bt_reclen) { - t->bt_rdata.data = t->bt_rdata.data == NULL ? - malloc(t->bt_reclen) : - reallocf(t->bt_rdata.data, t->bt_reclen); - if (t->bt_rdata.data == NULL) - return (RET_ERROR); - t->bt_rdata.size = t->bt_reclen; - } - data.data = t->bt_rdata.data; - data.size = t->bt_reclen; - - for (nrec = t->bt_nrecs; nrec < top;) { - len = t->bt_reclen; - for (p = t->bt_rdata.data;; *p++ = ch) - if ((ch = getc(t->bt_rfp)) == EOF || !--len) { - if (ch != EOF) - *p = ch; - if (len != 0) - memset(p, t->bt_bval, len); - if (__rec_iput(t, - nrec, &data, 0) != RET_SUCCESS) - return (RET_ERROR); - ++nrec; - break; - } - if (ch == EOF) - break; - } - if (nrec < top) { - F_SET(t, R_EOF); - return (RET_SPECIAL); - } - return (RET_SUCCESS); -} - -/* - * __REC_VPIPE -- Get variable length records from a pipe. - * - * Parameters: - * t: tree - * cnt: records to read - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_vpipe(t, top) - BTREE *t; - recno_t top; -{ - DBT data; - recno_t nrec; - size_t len; - size_t sz; - int bval, ch; - u_char *p; - - bval = t->bt_bval; - for (nrec = t->bt_nrecs; nrec < top; ++nrec) { - for (p = t->bt_rdata.data, - sz = t->bt_rdata.size;; *p++ = ch, --sz) { - if ((ch = getc(t->bt_rfp)) == EOF || ch == bval) { - data.data = t->bt_rdata.data; - data.size = p - (u_char *)t->bt_rdata.data; - if (ch == EOF && data.size == 0) - break; - if (__rec_iput(t, nrec, &data, 0) - != RET_SUCCESS) - return (RET_ERROR); - break; - } - if (sz == 0) { - len = p - (u_char *)t->bt_rdata.data; - t->bt_rdata.size += (sz = 256); - t->bt_rdata.data = t->bt_rdata.data == NULL ? - malloc(t->bt_rdata.size) : - reallocf(t->bt_rdata.data, t->bt_rdata.size); - if (t->bt_rdata.data == NULL) - return (RET_ERROR); - p = (u_char *)t->bt_rdata.data + len; - } - } - if (ch == EOF) - break; - } - if (nrec < top) { - F_SET(t, R_EOF); - return (RET_SPECIAL); - } - return (RET_SUCCESS); -} - -/* - * __REC_FMAP -- Get fixed length records from a file. - * - * Parameters: - * t: tree - * cnt: records to read - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_fmap(t, top) - BTREE *t; - recno_t top; -{ - DBT data; - recno_t nrec; - u_char *sp, *ep, *p; - size_t len; - - if (t->bt_rdata.size < t->bt_reclen) { - t->bt_rdata.data = t->bt_rdata.data == NULL ? - malloc(t->bt_reclen) : - reallocf(t->bt_rdata.data, t->bt_reclen); - if (t->bt_rdata.data == NULL) - return (RET_ERROR); - t->bt_rdata.size = t->bt_reclen; - } - data.data = t->bt_rdata.data; - data.size = t->bt_reclen; - - sp = (u_char *)t->bt_cmap; - ep = (u_char *)t->bt_emap; - for (nrec = t->bt_nrecs; nrec < top; ++nrec) { - if (sp >= ep) { - F_SET(t, R_EOF); - return (RET_SPECIAL); - } - len = t->bt_reclen; - for (p = t->bt_rdata.data; - sp < ep && len > 0; *p++ = *sp++, --len); - if (len != 0) - memset(p, t->bt_bval, len); - if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS) - return (RET_ERROR); - } - t->bt_cmap = (caddr_t)sp; - return (RET_SUCCESS); -} - -/* - * __REC_VMAP -- Get variable length records from a file. - * - * Parameters: - * t: tree - * cnt: records to read - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_vmap(t, top) - BTREE *t; - recno_t top; -{ - DBT data; - u_char *sp, *ep; - recno_t nrec; - int bval; - - sp = (u_char *)t->bt_cmap; - ep = (u_char *)t->bt_emap; - bval = t->bt_bval; - - for (nrec = t->bt_nrecs; nrec < top; ++nrec) { - if (sp >= ep) { - F_SET(t, R_EOF); - return (RET_SPECIAL); - } - for (data.data = sp; sp < ep && *sp != bval; ++sp); - data.size = sp - (u_char *)data.data; - if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS) - return (RET_ERROR); - ++sp; - } - t->bt_cmap = (caddr_t)sp; - return (RET_SUCCESS); -} diff --git a/db/recno/rec_get-fbsd.c b/db/recno/rec_get-fbsd.c new file mode 120000 index 0000000..5d7c157 --- /dev/null +++ b/db/recno/rec_get-fbsd.c @@ -0,0 +1 @@ +./rec_get.c \ No newline at end of file diff --git a/db/recno/rec_open-fbsd.c b/db/recno/rec_open-fbsd.c deleted file mode 100644 index a431f6f..0000000 --- a/db/recno/rec_open-fbsd.c +++ /dev/null @@ -1,245 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rec_open.c 8.10 (Berkeley) 9/1/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/recno/rec_open.c,v 1.6 2002/03/22 21:52:02 obrien Exp $"); - -#include "namespace.h" -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include "un-namespace.h" - -#include -#include "recno.h" - -DB * -__rec_open(fname, flags, mode, openinfo, dflags) - const char *fname; - int flags, mode, dflags; - const RECNOINFO *openinfo; -{ - BTREE *t; - BTREEINFO btopeninfo; - DB *dbp; - PAGE *h; - struct stat sb; - int rfd, sverrno; - - /* Open the user's file -- if this fails, we're done. */ - if (fname != NULL && (rfd = _open(fname, flags, mode)) < 0) - return (NULL); - - /* Create a btree in memory (backed by disk). */ - dbp = NULL; - if (openinfo) { - if (openinfo->flags & ~(R_FIXEDLEN | R_NOKEY | R_SNAPSHOT)) - goto einval; - btopeninfo.flags = 0; - btopeninfo.cachesize = openinfo->cachesize; - btopeninfo.maxkeypage = 0; - btopeninfo.minkeypage = 0; - btopeninfo.psize = openinfo->psize; - btopeninfo.compare = NULL; - btopeninfo.prefix = NULL; - btopeninfo.lorder = openinfo->lorder; - dbp = __bt_open(openinfo->bfname, - O_RDWR, S_IRUSR | S_IWUSR, &btopeninfo, dflags); - } else - dbp = __bt_open(NULL, O_RDWR, S_IRUSR | S_IWUSR, NULL, dflags); - if (dbp == NULL) - goto err; - - /* - * Some fields in the tree structure are recno specific. Fill them - * in and make the btree structure look like a recno structure. We - * don't change the bt_ovflsize value, it's close enough and slightly - * bigger. - */ - t = dbp->internal; - if (openinfo) { - if (openinfo->flags & R_FIXEDLEN) { - F_SET(t, R_FIXLEN); - t->bt_reclen = openinfo->reclen; - if (t->bt_reclen == 0) - goto einval; - } - t->bt_bval = openinfo->bval; - } else - t->bt_bval = '\n'; - - F_SET(t, R_RECNO); - if (fname == NULL) - F_SET(t, R_EOF | R_INMEM); - else - t->bt_rfd = rfd; - - if (fname != NULL) { - /* - * In 4.4BSD, stat(2) returns true for ISSOCK on pipes. - * Unfortunately, that's not portable, so we use lseek - * and check the errno values. - */ - errno = 0; - if (lseek(rfd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) { - switch (flags & O_ACCMODE) { - case O_RDONLY: - F_SET(t, R_RDONLY); - break; - default: - goto einval; - } -slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) - goto err; - F_SET(t, R_CLOSEFP); - t->bt_irec = - F_ISSET(t, R_FIXLEN) ? __rec_fpipe : __rec_vpipe; - } else { - switch (flags & O_ACCMODE) { - case O_RDONLY: - F_SET(t, R_RDONLY); - break; - case O_RDWR: - break; - default: - goto einval; - } - - if (_fstat(rfd, &sb)) - goto err; - /* - * Kluge -- we'd like to test to see if the file is too - * big to mmap. Since, we don't know what size or type - * off_t's or size_t's are, what the largest unsigned - * integral type is, or what random insanity the local - * C compiler will perpetrate, doing the comparison in - * a portable way is flatly impossible. Hope that mmap - * fails if the file is too large. - */ - if (sb.st_size == 0) - F_SET(t, R_EOF); - else { -#ifdef MMAP_NOT_AVAILABLE - /* - * XXX - * Mmap doesn't work correctly on many current - * systems. In particular, it can fail subtly, - * with cache coherency problems. Don't use it - * for now. - */ - t->bt_msize = sb.st_size; - if ((t->bt_smap = mmap(NULL, t->bt_msize, - PROT_READ, MAP_PRIVATE, rfd, - (off_t)0)) == MAP_FAILED) - goto slow; - t->bt_cmap = t->bt_smap; - t->bt_emap = t->bt_smap + sb.st_size; - t->bt_irec = F_ISSET(t, R_FIXLEN) ? - __rec_fmap : __rec_vmap; - F_SET(t, R_MEMMAPPED); -#else - goto slow; -#endif - } - } - } - - /* Use the recno routines. */ - dbp->close = __rec_close; - dbp->del = __rec_delete; - dbp->fd = __rec_fd; - dbp->get = __rec_get; - dbp->put = __rec_put; - dbp->seq = __rec_seq; - dbp->sync = __rec_sync; - - /* If the root page was created, reset the flags. */ - if ((h = mpool_get(t->bt_mp, P_ROOT, 0)) == NULL) - goto err; - if ((h->flags & P_TYPE) == P_BLEAF) { - F_CLR(h, P_TYPE); - F_SET(h, P_RLEAF); - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - } else - mpool_put(t->bt_mp, h, 0); - - if (openinfo && openinfo->flags & R_SNAPSHOT && - !F_ISSET(t, R_EOF | R_INMEM) && - t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) - goto err; - return (dbp); - -einval: errno = EINVAL; -err: sverrno = errno; - if (dbp != NULL) - (void)__bt_close(dbp); - if (fname != NULL) - (void)_close(rfd); - errno = sverrno; - return (NULL); -} - -int -__rec_fd(dbp) - const DB *dbp; -{ - BTREE *t; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* In-memory database can't have a file descriptor. */ - if (F_ISSET(t, R_INMEM)) { - errno = ENOENT; - return (-1); - } - return (t->bt_rfd); -} diff --git a/db/recno/rec_open-fbsd.c b/db/recno/rec_open-fbsd.c new file mode 120000 index 0000000..84a4acb --- /dev/null +++ b/db/recno/rec_open-fbsd.c @@ -0,0 +1 @@ +./rec_open.c \ No newline at end of file diff --git a/db/recno/rec_put-fbsd.c b/db/recno/rec_put-fbsd.c deleted file mode 100644 index 14cc811..0000000 --- a/db/recno/rec_put-fbsd.c +++ /dev/null @@ -1,287 +0,0 @@ -/*- - * 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[] = "@(#)rec_put.c 8.7 (Berkeley) 8/18/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/recno/rec_put.c,v 1.6 2002/03/22 21:52:02 obrien Exp $"); - -#include - -#include -#include -#include -#include - -#include -#include "recno.h" - -/* - * __REC_PUT -- Add a recno item to the tree. - * - * Parameters: - * dbp: pointer to access method - * key: key - * data: data - * flag: R_CURSOR, R_IAFTER, R_IBEFORE, R_NOOVERWRITE - * - * Returns: - * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is - * already in the tree and R_NOOVERWRITE specified. - */ -int -__rec_put(dbp, key, data, flags) - const DB *dbp; - DBT *key; - const DBT *data; - u_int flags; -{ - BTREE *t; - DBT fdata, tdata; - recno_t nrec; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - /* - * If using fixed-length records, and the record is long, return - * EINVAL. If it's short, pad it out. Use the record data return - * memory, it's only short-term. - */ - if (F_ISSET(t, R_FIXLEN) && data->size != t->bt_reclen) { - if (data->size > t->bt_reclen) - goto einval; - - if (t->bt_rdata.size < t->bt_reclen) { - t->bt_rdata.data = - reallocf(t->bt_rdata.data, t->bt_reclen); - if (t->bt_rdata.data == NULL) - return (RET_ERROR); - t->bt_rdata.size = t->bt_reclen; - } - memmove(t->bt_rdata.data, data->data, data->size); - memset((char *)t->bt_rdata.data + data->size, - t->bt_bval, t->bt_reclen - data->size); - fdata.data = t->bt_rdata.data; - fdata.size = t->bt_reclen; - } else { - fdata.data = data->data; - fdata.size = data->size; - } - - switch (flags) { - case R_CURSOR: - if (!F_ISSET(&t->bt_cursor, CURS_INIT)) - goto einval; - nrec = t->bt_cursor.rcursor; - break; - case R_SETCURSOR: - if ((nrec = *(recno_t *)key->data) == 0) - goto einval; - break; - case R_IAFTER: - if ((nrec = *(recno_t *)key->data) == 0) { - nrec = 1; - flags = R_IBEFORE; - } - break; - case 0: - case R_IBEFORE: - if ((nrec = *(recno_t *)key->data) == 0) - goto einval; - break; - case R_NOOVERWRITE: - if ((nrec = *(recno_t *)key->data) == 0) - goto einval; - if (nrec <= t->bt_nrecs) - return (RET_SPECIAL); - break; - default: -einval: errno = EINVAL; - return (RET_ERROR); - } - - /* - * Make sure that records up to and including the put record are - * already in the database. If skipping records, create empty ones. - */ - if (nrec > t->bt_nrecs) { - if (!F_ISSET(t, R_EOF | R_INMEM) && - t->bt_irec(t, nrec) == RET_ERROR) - return (RET_ERROR); - if (nrec > t->bt_nrecs + 1) { - if (F_ISSET(t, R_FIXLEN)) { - if ((tdata.data = - (void *)malloc(t->bt_reclen)) == NULL) - return (RET_ERROR); - tdata.size = t->bt_reclen; - memset(tdata.data, t->bt_bval, tdata.size); - } else { - tdata.data = NULL; - tdata.size = 0; - } - while (nrec > t->bt_nrecs + 1) - if (__rec_iput(t, - t->bt_nrecs, &tdata, 0) != RET_SUCCESS) - return (RET_ERROR); - if (F_ISSET(t, R_FIXLEN)) - free(tdata.data); - } - } - - if ((status = __rec_iput(t, nrec - 1, &fdata, flags)) != RET_SUCCESS) - return (status); - - switch (flags) { - case R_IAFTER: - nrec++; - break; - case R_SETCURSOR: - t->bt_cursor.rcursor = nrec; - break; - } - - F_SET(t, R_MODIFIED); - return (__rec_ret(t, NULL, nrec, key, NULL)); -} - -/* - * __REC_IPUT -- Add a recno item to the tree. - * - * Parameters: - * t: tree - * nrec: record number - * data: data - * - * Returns: - * RET_ERROR, RET_SUCCESS - */ -int -__rec_iput(t, nrec, data, flags) - BTREE *t; - recno_t nrec; - const DBT *data; - u_int flags; -{ - DBT tdata; - EPG *e; - PAGE *h; - indx_t index, nxtindex; - pgno_t pg; - u_int32_t nbytes; - int dflags, status; - char *dest, db[NOVFLSIZE]; - - /* - * If the data won't fit on a page, store it on indirect pages. - * - * XXX - * If the insert fails later on, these pages aren't recovered. - */ - if (data->size > t->bt_ovflsize) { - if (__ovfl_put(t, data, &pg) == RET_ERROR) - return (RET_ERROR); - tdata.data = db; - tdata.size = NOVFLSIZE; - *(pgno_t *)db = pg; - *(u_int32_t *)(db + sizeof(pgno_t)) = data->size; - dflags = P_BIGDATA; - data = &tdata; - } else - dflags = 0; - - /* __rec_search pins the returned page. */ - if ((e = __rec_search(t, nrec, - nrec > t->bt_nrecs || flags == R_IAFTER || flags == R_IBEFORE ? - SINSERT : SEARCH)) == NULL) - return (RET_ERROR); - - h = e->page; - index = e->index; - - /* - * Add the specified key/data pair to the tree. The R_IAFTER and - * R_IBEFORE flags insert the key after/before the specified key. - * - * Pages are split as required. - */ - switch (flags) { - case R_IAFTER: - ++index; - break; - case R_IBEFORE: - break; - default: - if (nrec < t->bt_nrecs && - __rec_dleaf(t, h, index) == RET_ERROR) { - mpool_put(t->bt_mp, h, 0); - return (RET_ERROR); - } - break; - } - - /* - * If not enough room, split the page. The split code will insert - * the key and data and unpin the current page. If inserting into - * the offset array, shift the pointers up. - */ - nbytes = NRLEAFDBT(data->size); - if (h->upper - h->lower < nbytes + sizeof(indx_t)) { - status = __bt_split(t, h, NULL, data, dflags, nbytes, index); - if (status == RET_SUCCESS) - ++t->bt_nrecs; - return (status); - } - - if (index < (nxtindex = NEXTINDEX(h))) - memmove(h->linp + index + 1, h->linp + index, - (nxtindex - index) * sizeof(indx_t)); - h->lower += sizeof(indx_t); - - h->linp[index] = h->upper -= nbytes; - dest = (char *)h + h->upper; - WR_RLEAF(dest, data, dflags); - - ++t->bt_nrecs; - F_SET(t, B_MODIFIED); - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - - return (RET_SUCCESS); -} diff --git a/db/recno/rec_put-fbsd.c b/db/recno/rec_put-fbsd.c new file mode 120000 index 0000000..73a5bdc --- /dev/null +++ b/db/recno/rec_put-fbsd.c @@ -0,0 +1 @@ +./rec_put.c \ No newline at end of file diff --git a/db/recno/rec_search-fbsd.c b/db/recno/rec_search-fbsd.c deleted file mode 100644 index 3353bfb..0000000 --- a/db/recno/rec_search-fbsd.c +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rec_search.c 8.4 (Berkeley) 7/14/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/recno/rec_search.c,v 1.4 2002/03/21 18:47:38 obrien Exp $"); - -#include - -#include -#include - -#include -#include "recno.h" - -/* - * __REC_SEARCH -- Search a btree for a key. - * - * Parameters: - * t: tree to search - * recno: key to find - * op: search operation - * - * Returns: - * EPG for matching record, if any, or the EPG for the location of the - * key, if it were inserted into the tree. - * - * Returns: - * The EPG for matching record, if any, or the EPG for the location - * of the key, if it were inserted into the tree, is entered into - * the bt_cur field of the tree. A pointer to the field is returned. - */ -EPG * -__rec_search(t, recno, op) - BTREE *t; - recno_t recno; - enum SRCHOP op; -{ - indx_t index; - PAGE *h; - EPGNO *parent; - RINTERNAL *r; - pgno_t pg; - indx_t top; - recno_t total; - int sverrno; - - BT_CLR(t); - for (pg = P_ROOT, total = 0;;) { - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - goto err; - if (h->flags & P_RLEAF) { - t->bt_cur.page = h; - t->bt_cur.index = recno - total; - return (&t->bt_cur); - } - for (index = 0, top = NEXTINDEX(h);;) { - r = GETRINTERNAL(h, index); - if (++index == top || total + r->nrecs > recno) - break; - total += r->nrecs; - } - - BT_PUSH(t, pg, index - 1); - - pg = r->pgno; - switch (op) { - case SDELETE: - --GETRINTERNAL(h, (index - 1))->nrecs; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - break; - case SINSERT: - ++GETRINTERNAL(h, (index - 1))->nrecs; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - break; - case SEARCH: - mpool_put(t->bt_mp, h, 0); - break; - } - - } - /* Try and recover the tree. */ -err: sverrno = errno; - if (op != SEARCH) - while ((parent = BT_POP(t)) != NULL) { - if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) - break; - if (op == SINSERT) - --GETRINTERNAL(h, parent->index)->nrecs; - else - ++GETRINTERNAL(h, parent->index)->nrecs; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - } - errno = sverrno; - return (NULL); -} diff --git a/db/recno/rec_search-fbsd.c b/db/recno/rec_search-fbsd.c new file mode 120000 index 0000000..b4a722a --- /dev/null +++ b/db/recno/rec_search-fbsd.c @@ -0,0 +1 @@ +./rec_search.c \ No newline at end of file diff --git a/db/recno/rec_seq-fbsd.c b/db/recno/rec_seq-fbsd.c deleted file mode 100644 index 6ed3384..0000000 --- a/db/recno/rec_seq-fbsd.c +++ /dev/null @@ -1,134 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#include -#ifndef lint -/* XXX use __SCCSID */ -static char sccsid[] __unused = "@(#)rec_seq.c 8.3 (Berkeley) 7/14/94"; -#endif /* not lint */ -__FBSDID("$FreeBSD: src/lib/libc/db/recno/rec_seq.c,v 1.5 2003/02/16 17:29:09 nectar Exp $"); - -#include - -#include -#include -#include -#include - -#include -#include "recno.h" - -/* - * __REC_SEQ -- Recno sequential scan interface. - * - * Parameters: - * dbp: pointer to access method - * key: key for positioning and return value - * data: data return value - * flags: R_CURSOR, R_FIRST, R_LAST, R_NEXT, R_PREV. - * - * Returns: - * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. - */ -int -__rec_seq(dbp, key, data, flags) - const DB *dbp; - DBT *key, *data; - u_int flags; -{ - BTREE *t; - EPG *e; - recno_t nrec; - int status; - - t = dbp->internal; - - /* Toss any page pinned across calls. */ - if (t->bt_pinned != NULL) { - mpool_put(t->bt_mp, t->bt_pinned, 0); - t->bt_pinned = NULL; - } - - switch(flags) { - case R_CURSOR: - if ((nrec = *(recno_t *)key->data) == 0) - goto einval; - break; - case R_NEXT: - if (F_ISSET(&t->bt_cursor, CURS_INIT)) { - nrec = t->bt_cursor.rcursor + 1; - break; - } - /* FALLTHROUGH */ - case R_FIRST: - nrec = 1; - break; - case R_PREV: - if (F_ISSET(&t->bt_cursor, CURS_INIT)) { - if ((nrec = t->bt_cursor.rcursor - 1) == 0) - return (RET_SPECIAL); - break; - } - /* FALLTHROUGH */ - case R_LAST: - if (!F_ISSET(t, R_EOF | R_INMEM) && - t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) - return (RET_ERROR); - nrec = t->bt_nrecs; - break; - default: -einval: errno = EINVAL; - return (RET_ERROR); - } - - if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) { - if (!F_ISSET(t, R_EOF | R_INMEM) && - (status = t->bt_irec(t, nrec)) != RET_SUCCESS) - return (status); - if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) - return (RET_SPECIAL); - } - - if ((e = __rec_search(t, nrec - 1, SEARCH)) == NULL) - return (RET_ERROR); - - F_SET(&t->bt_cursor, CURS_INIT); - t->bt_cursor.rcursor = nrec; - - status = __rec_ret(t, e, nrec, key, data); - if (F_ISSET(t, B_DB_LOCK)) - mpool_put(t->bt_mp, e->page, 0); - else - t->bt_pinned = e->page; - return (status); -} diff --git a/db/recno/rec_seq-fbsd.c b/db/recno/rec_seq-fbsd.c new file mode 120000 index 0000000..3274e31 --- /dev/null +++ b/db/recno/rec_seq-fbsd.c @@ -0,0 +1 @@ +./rec_seq.c \ No newline at end of file diff --git a/db/recno/rec_utils-fbsd.c b/db/recno/rec_utils-fbsd.c deleted file mode 100644 index 81fa1d6..0000000 --- a/db/recno/rec_utils-fbsd.c +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * 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[] = "@(#)rec_utils.c 8.6 (Berkeley) 7/16/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/db/recno/rec_utils.c,v 1.2 2002/03/22 21:52:02 obrien Exp $"); - -#include - -#include -#include -#include - -#include -#include "recno.h" - -/* - * __rec_ret -- - * Build return data. - * - * Parameters: - * t: tree - * e: key/data pair to be returned - * nrec: record number - * key: user's key structure - * data: user's data structure - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -int -__rec_ret(t, e, nrec, key, data) - BTREE *t; - EPG *e; - recno_t nrec; - DBT *key, *data; -{ - RLEAF *rl; - void *p; - - if (key == NULL) - goto dataonly; - - /* We have to copy the key, it's not on the page. */ - if (sizeof(recno_t) > t->bt_rkey.size) { - p = (void *)(t->bt_rkey.data == NULL ? - malloc(sizeof(recno_t)) : - realloc(t->bt_rkey.data, sizeof(recno_t))); - if (p == NULL) - return (RET_ERROR); - t->bt_rkey.data = p; - t->bt_rkey.size = sizeof(recno_t); - } - memmove(t->bt_rkey.data, &nrec, sizeof(recno_t)); - key->size = sizeof(recno_t); - key->data = t->bt_rkey.data; - -dataonly: - if (data == NULL) - return (RET_SUCCESS); - - /* - * We must copy big keys/data to make them contigous. Otherwise, - * leave the page pinned and don't copy unless the user specified - * concurrent access. - */ - rl = GETRLEAF(e->page, e->index); - if (rl->flags & P_BIGDATA) { - if (__ovfl_get(t, rl->bytes, - &data->size, &t->bt_rdata.data, &t->bt_rdata.size)) - return (RET_ERROR); - data->data = t->bt_rdata.data; - } else if (F_ISSET(t, B_DB_LOCK)) { - /* Use +1 in case the first record retrieved is 0 length. */ - if (rl->dsize + 1 > t->bt_rdata.size) { - p = (void *)(t->bt_rdata.data == NULL ? - malloc(rl->dsize + 1) : - realloc(t->bt_rdata.data, rl->dsize + 1)); - if (p == NULL) - return (RET_ERROR); - t->bt_rdata.data = p; - t->bt_rdata.size = rl->dsize + 1; - } - memmove(t->bt_rdata.data, rl->bytes, rl->dsize); - data->size = rl->dsize; - data->data = t->bt_rdata.data; - } else { - data->size = rl->dsize; - data->data = rl->bytes; - } - return (RET_SUCCESS); -} diff --git a/db/recno/rec_utils-fbsd.c b/db/recno/rec_utils-fbsd.c new file mode 120000 index 0000000..eb044fb --- /dev/null +++ b/db/recno/rec_utils-fbsd.c @@ -0,0 +1 @@ +./rec_utils.c \ No newline at end of file diff --git a/fbsdcompat/_fpmath.h b/fbsdcompat/_fpmath.h index 3871ec2..1df393e 100644 --- a/fbsdcompat/_fpmath.h +++ b/fbsdcompat/_fpmath.h @@ -97,6 +97,35 @@ union IEEEl2bits { (a)[0] = (uint32_t)(u).bits.manl; \ (a)[1] = (uint32_t)(u).bits.manh; \ } while(0) +#elif defined(__arm__) + +union IEEEl2bits { + long double e; + struct { +#ifndef __ARMEB__ + unsigned int manl :32; + unsigned int manh :20; + unsigned int exp :11; + unsigned int sign :1; +#else + unsigned int sign :1; + unsigned int exp :11; + unsigned int manh :20; + unsigned int manl :32; +#endif + } bits; +}; + +#define LDBL_NBIT 0 +#define mask_nbit_l(u) ((void)0) + +#define LDBL_MANH_SIZE 20 +#define LDBL_MANL_SIZE 32 + +#define LDBL_TO_ARRAY32(u, a) do { \ + (a)[0] = (uint32_t)(u).bits.manl; \ + (a)[1] = (uint32_t)(u).bits.manh; \ +} while(0) #else #error unsupported architecture diff --git a/fbsdcompat/port_after.h b/fbsdcompat/port_after.h new file mode 100644 index 0000000..3fbf933 --- /dev/null +++ b/fbsdcompat/port_after.h @@ -0,0 +1 @@ +/* FreeBSD only needs this for isc, nameser and resolv */ diff --git a/fbsdcompat/port_before.h b/fbsdcompat/port_before.h new file mode 100644 index 0000000..3fbf933 --- /dev/null +++ b/fbsdcompat/port_before.h @@ -0,0 +1 @@ +/* FreeBSD only needs this for isc, nameser and resolv */ diff --git a/gdtoa/FreeBSD/_hdtoa.c.patch b/gdtoa/FreeBSD/_hdtoa.c.patch index 2982437..4e14727 100644 --- a/gdtoa/FreeBSD/_hdtoa.c.patch +++ b/gdtoa/FreeBSD/_hdtoa.c.patch @@ -1,6 +1,6 @@ ---- _hdtoa.c.orig 2006-08-14 16:12:46.000000000 -0700 -+++ _hdtoa.c 2006-08-14 23:02:39.000000000 -0700 -@@ -55,7 +55,7 @@ +--- _hdtoa.c.orig 2008-03-15 10:50:51.000000000 -0700 ++++ _hdtoa.c 2008-03-27 00:55:34.000000000 -0700 +@@ -55,7 +55,7 @@ roundup(char *s0, int ndigits) *s = 1; return (1); } @@ -9,7 +9,15 @@ } ++*s; return (0); -@@ -223,12 +223,17 @@ +@@ -210,6 +210,7 @@ __hdtoa(double d, const char *xdigs, int + return (s0); + } + ++#ifndef LDBL_COMPAT + #if (LDBL_MANT_DIG > DBL_MANT_DIG) + + /* +@@ -223,12 +224,17 @@ __hldtoa(long double e, const char *xdig union IEEEl2bits u; char *s, *s0; int bufsize; @@ -27,7 +35,7 @@ *decpt = u.bits.exp - LDBL_ADJ; break; case FP_ZERO: -@@ -270,6 +275,19 @@ +@@ -270,6 +276,19 @@ __hldtoa(long double e, const char *xdig */ for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--) *s = 0; @@ -47,7 +55,7 @@ for (; s > s0 + sigfigs - (LDBL_MANL_SIZE / 4) - 1 && s > s0; s--) { *s = u.bits.manl & 0xf; u.bits.manl >>= 4; -@@ -278,6 +296,7 @@ +@@ -278,6 +297,7 @@ __hldtoa(long double e, const char *xdig *s = u.bits.manh & 0xf; u.bits.manh >>= 4; } @@ -55,7 +63,7 @@ /* * At this point, we have snarfed all the bits in the -@@ -285,7 +304,11 @@ +@@ -285,7 +305,11 @@ __hldtoa(long double e, const char *xdig * (partial) nibble, which is dealt with by the next * statement. We also tack on the implicit normalization bit. */ @@ -67,3 +75,8 @@ /* If ndigits < 0, we are expected to auto-size the precision. */ if (ndigits < 0) { +@@ -317,3 +341,4 @@ __hldtoa(long double e, const char *xdig + } + + #endif /* (LDBL_MANT_DIG == DBL_MANT_DIG) */ ++#endif /* !LDBL_COMPAT */ diff --git a/gdtoa/FreeBSD/gdtoa-hexnan.c.patch b/gdtoa/FreeBSD/gdtoa-hexnan.c.patch index 23aa1aa..924fac9 100644 --- a/gdtoa/FreeBSD/gdtoa-hexnan.c.patch +++ b/gdtoa/FreeBSD/gdtoa-hexnan.c.patch @@ -114,7 +114,7 @@ + x0[2] = (ULong)(u.bits.manh >> 12); + x0[1] = ((ULong)u.bits.manh & 0xfff) << 20 | (ULong)(u.bits.manl >> 32); + x0[0] = (ULong)u.bits.manl; -+#elif defined(__i386__) || defined(__x86_64__) ++#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) + x0[1] = (ULong)u.bits.manh; + x0[0] = (ULong)u.bits.manl; +#else diff --git a/gdtoa/FreeBSD/gdtoaimp.h.patch b/gdtoa/FreeBSD/gdtoaimp.h.patch index 4b7ee34..e9cb409 100644 --- a/gdtoa/FreeBSD/gdtoaimp.h.patch +++ b/gdtoa/FreeBSD/gdtoaimp.h.patch @@ -1,5 +1,5 @@ ---- gdtoaimp.h.orig 2007-10-04 15:00:21.000000000 -0700 -+++ gdtoaimp.h 2007-10-04 15:35:46.000000000 -0700 +--- gdtoaimp.h.orig 2008-07-30 13:29:37.000000000 -0700 ++++ gdtoaimp.h 2008-07-30 13:49:16.000000000 -0700 @@ -167,6 +167,7 @@ #ifndef GDTOAIMP_H_INCLUDED @@ -30,18 +30,7 @@ #undef IEEE_Arith #undef Avoid_Underflow #ifdef IEEE_MC68k -@@ -233,6 +240,10 @@ - - #else /* ifndef Bad_float_h */ - #include "float.h" -+/* force the correct definition of FLT_ROUNDS */ -+extern int __fegetfltrounds( void ); -+#undef FLT_ROUNDS -+#define FLT_ROUNDS (__fegetfltrounds ()) - #endif /* Bad_float_h */ - - #ifdef IEEE_Arith -@@ -449,10 +460,16 @@ +@@ -449,10 +456,16 @@ #define ALL_ON 0xffff #endif @@ -62,7 +51,7 @@ #define Kmax 15 -@@ -475,51 +492,89 @@ +@@ -475,51 +488,89 @@ #define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int)) #endif /* NO_STRING_H */ @@ -197,7 +186,7 @@ extern char *dtoa_result; extern CONST double bigtens[], tens[], tinytens[]; -@@ -542,8 +597,11 @@ +@@ -542,8 +593,11 @@ extern Bigint *diff ANSI((Bigint*, Bigint*)); extern char *dtoa ANSI((double d, int mode, int ndigits, int *decpt, int *sign, char **rve)); @@ -210,7 +199,7 @@ extern void hexdig_init_D2A(Void); extern int hexnan ANSI((CONST char**, FPI*, ULong*)); extern int hi0bits_D2A ANSI((ULong)); -@@ -560,11 +618,32 @@ +@@ -560,11 +614,32 @@ extern double ratio ANSI((Bigint*, Bigint*)); extern void rshift ANSI((Bigint*, int)); extern char *rv_alloc ANSI((int)); diff --git a/gdtoa/FreeBSD/machdep_ldisd.c.patch b/gdtoa/FreeBSD/machdep_ldisd.c.patch new file mode 100644 index 0000000..e6605cd --- /dev/null +++ b/gdtoa/FreeBSD/machdep_ldisd.c.patch @@ -0,0 +1,14 @@ +--- machdep_ldisd.c.orig 2005-07-06 16:00:22.000000000 -0700 ++++ machdep_ldisd.c 2005-07-06 16:02:24.000000000 -0700 +@@ -41,3 +41,11 @@ + + return strtod(s, sp); + } ++ ++long double ++strtold_l(const char * __restrict s, char ** __restrict sp, locale_t loc) ++{ ++ ++ return strtod_l(s, sp, loc); ++} ++ diff --git a/gdtoa/Makefile.inc b/gdtoa/Makefile.inc index 50e8f90..e016bc1 100644 --- a/gdtoa/Makefile.inc +++ b/gdtoa/Makefile.inc @@ -1,28 +1,25 @@ .PATH: ${.CURDIR}/gdtoa +CWD := ${.CURDIR}/gdtoa CFLAGS += -I${.CURDIR}/gdtoa -.ifmake autopatch -ALL_ARCHS ?= i386 ppc ppc64 x86_64 -.for a in $(ALL_ARCHS) -.if exists(../${a}/stdlib/gdtoa.mk) -.include "../${a}/stdlib/gdtoa.mk" -.endif -.endfor -.else # !autopatch -.if exists(${.CURDIR}/${MACHINE_ARCH}/stdlib/gdtoa.mk) -.include "${.CURDIR}/${MACHINE_ARCH}/stdlib/gdtoa.mk" -.endif -.endif # autopatch +.sinclude "${.CURDIR}/${MACHINE_ARCH}/stdlib/gdtoa.mk" + GDTOA_UNIQUE_SRCS != perl -e '@z = split(" ", "$(GDTOA_FBSDSRCS)"); $$, = "\n"; print @z' | sort -u .include "Makefile.fbsd_begin" -FBSDMISRCS= $(GDTOA_UNIQUE_SRCS) _hdtoa.c _ldtoa.c glue.c \ +FBSDMISRCS= $(GDTOA_UNIQUE_SRCS) _hdtoa.c glue.c \ gdtoa-dmisc.c gdtoa-dtoa.c gdtoa-gdtoa.c gdtoa-gethex.c gdtoa-gmisc.c \ gdtoa-hd_init.c gdtoa-hexnan.c gdtoa-misc.c gdtoa-smisc.c \ gdtoa-strtod.c gdtoa-strtodg.c gdtoa-strtof.c gdtoa-strtord.c \ gdtoa-sum.c gdtoa-ulp.c + +.ifndef FEATURE_ONLY_LONG_DOUBLE_IS_DOUBLE +FBSDMISRCS+= _ldtoa.c +.endif + FBSDHDRS= gdtoa.h gdtoaimp.h + .include "Makefile.fbsd_end" LEGACYSRCS += gdtoa-strtof.c gdtoa-strtod.c gdtoa-strtodg.c diff --git a/gdtoa/_hdtoa-fbsd.c b/gdtoa/_hdtoa-fbsd.c index 0476f2e..bd25906 100644 --- a/gdtoa/_hdtoa-fbsd.c +++ b/gdtoa/_hdtoa-fbsd.c @@ -210,6 +210,7 @@ __hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign, return (s0); } +#ifndef LDBL_COMPAT #if (LDBL_MANT_DIG > DBL_MANT_DIG) /* @@ -340,3 +341,4 @@ __hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign, } #endif /* (LDBL_MANT_DIG == DBL_MANT_DIG) */ +#endif /* !LDBL_COMPAT */ diff --git a/gdtoa/arith.h b/gdtoa/arith.h index 2ebf333..b0554a9 100644 --- a/gdtoa/arith.h +++ b/gdtoa/arith.h @@ -41,6 +41,12 @@ #define IEEE_8087 #define Arith_Kind_ASL 1 #define Long int +#elif defined(__arm__) +#if __VFP_FP__ +#define IEEE_8087 +#else +#define IEEE_MC68k +#endif #else #error Unsupported architecture #endif diff --git a/gdtoa/gd_qnan.h b/gdtoa/gd_qnan.h index ea5fd60..6b22c9f 100644 --- a/gdtoa/gd_qnan.h +++ b/gdtoa/gd_qnan.h @@ -13,7 +13,7 @@ #define ldus_QNAN3 0x0 #define ldus_QNAN4 0x0 -#elif defined(__i386__) || defined(__x86_64__) +#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) #define f_QNAN 0xffc00000 #define d_QNAN0 0x0 diff --git a/gdtoa/gdtoa-dmisc-fbsd.c b/gdtoa/gdtoa-dmisc-fbsd.c deleted file mode 100644 index ce170c7..0000000 --- a/gdtoa/gdtoa-dmisc-fbsd.c +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************** - -The author of this software is David M. Gay. - -Copyright (C) 1998 by Lucent Technologies -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 the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES 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. - -****************************************************************/ - -/* Please send bug reports to David M. Gay (dmg at acm dot org, - * with " at " changed at "@" and " dot " changed to "."). */ - -#include "gdtoaimp.h" - -#ifndef MULTIPLE_THREADS - char *dtoa_result; -#endif - - char * -#ifdef KR_headers -rv_alloc(i) int i; -#else -rv_alloc(int i) -#endif -{ - int j, k, *r; - - j = sizeof(ULong); - for(k = 0; - sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i; - j <<= 1) - k++; - r = (int*)Balloc(k); - *r = k; - return -#ifndef MULTIPLE_THREADS - dtoa_result = -#endif - (char *)(r+1); - } - - char * -#ifdef KR_headers -nrv_alloc(s, rve, n) char *s, **rve; int n; -#else -nrv_alloc(char *s, char **rve, int n) -#endif -{ - char *rv, *t; - - t = rv = rv_alloc(n); - while((*t = *s++) !=0) - t++; - if (rve) - *rve = t; - return rv; - } - -/* freedtoa(s) must be used to free values s returned by dtoa - * when MULTIPLE_THREADS is #defined. It should be used in all cases, - * but for consistency with earlier versions of dtoa, it is optional - * when MULTIPLE_THREADS is not defined. - */ - - void -#ifdef KR_headers -freedtoa(s) char *s; -#else -freedtoa(char *s) -#endif -{ - Bigint *b = (Bigint *)((int *)s - 1); - b->maxwds = 1 << (b->k = *(int*)b); - Bfree(b); -#ifndef MULTIPLE_THREADS - if (s == dtoa_result) - dtoa_result = 0; -#endif - } - - int -quorem -#ifdef KR_headers - (b, S) Bigint *b, *S; -#else - (Bigint *b, Bigint *S) -#endif -{ - int n; - ULong *bx, *bxe, q, *sx, *sxe; -#ifdef ULLong - ULLong borrow, carry, y, ys; -#else - ULong borrow, carry, y, ys; -#ifdef Pack_32 - ULong si, z, zs; -#endif -#endif - - n = S->wds; -#ifdef DEBUG - /*debug*/ if (b->wds > n) - /*debug*/ Bug("oversize b in quorem"); -#endif - if (b->wds < n) - return 0; - sx = S->x; - sxe = sx + --n; - bx = b->x; - bxe = bx + n; - q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ -#ifdef DEBUG - /*debug*/ if (q > 9) - /*debug*/ Bug("oversized quotient in quorem"); -#endif - if (q) { - borrow = 0; - carry = 0; - do { -#ifdef ULLong - ys = *sx++ * (ULLong)q + carry; - carry = ys >> 32; - y = *bx - (ys & 0xffffffffUL) - borrow; - borrow = y >> 32 & 1UL; - *bx++ = y & 0xffffffffUL; -#else -#ifdef Pack_32 - si = *sx++; - ys = (si & 0xffff) * q + carry; - zs = (si >> 16) * q + (ys >> 16); - carry = zs >> 16; - y = (*bx & 0xffff) - (ys & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - z = (*bx >> 16) - (zs & 0xffff) - borrow; - borrow = (z & 0x10000) >> 16; - Storeinc(bx, z, y); -#else - ys = *sx++ * q + carry; - carry = ys >> 16; - y = *bx - (ys & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - *bx++ = y & 0xffff; -#endif -#endif - } - while(sx <= sxe); - if (!*bxe) { - bx = b->x; - while(--bxe > bx && !*bxe) - --n; - b->wds = n; - } - } - if (cmp(b, S) >= 0) { - q++; - borrow = 0; - carry = 0; - bx = b->x; - sx = S->x; - do { -#ifdef ULLong - ys = *sx++ + carry; - carry = ys >> 32; - y = *bx - (ys & 0xffffffffUL) - borrow; - borrow = y >> 32 & 1UL; - *bx++ = y & 0xffffffffUL; -#else -#ifdef Pack_32 - si = *sx++; - ys = (si & 0xffff) + carry; - zs = (si >> 16) + (ys >> 16); - carry = zs >> 16; - y = (*bx & 0xffff) - (ys & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - z = (*bx >> 16) - (zs & 0xffff) - borrow; - borrow = (z & 0x10000) >> 16; - Storeinc(bx, z, y); -#else - ys = *sx++ + carry; - carry = ys >> 16; - y = *bx - (ys & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - *bx++ = y & 0xffff; -#endif -#endif - } - while(sx <= sxe); - bx = b->x; - bxe = bx + n; - if (!*bxe) { - while(--bxe > bx && !*bxe) - --n; - b->wds = n; - } - } - return q; - } diff --git a/gdtoa/gdtoa-dmisc-fbsd.c b/gdtoa/gdtoa-dmisc-fbsd.c new file mode 120000 index 0000000..5d57ae1 --- /dev/null +++ b/gdtoa/gdtoa-dmisc-fbsd.c @@ -0,0 +1 @@ +./gdtoa-dmisc.c \ No newline at end of file diff --git a/gdtoa/gdtoa-dtoa-fbsd.c b/gdtoa/gdtoa-dtoa-fbsd.c deleted file mode 100644 index e808cc1..0000000 --- a/gdtoa/gdtoa-dtoa-fbsd.c +++ /dev/null @@ -1,753 +0,0 @@ -/**************************************************************** - -The author of this software is David M. Gay. - -Copyright (C) 1998, 1999 by Lucent Technologies -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 the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES 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. - -****************************************************************/ - -/* Please send bug reports to David M. Gay (dmg at acm dot org, - * with " at " changed at "@" and " dot " changed to "."). */ - -#include "gdtoaimp.h" - -/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string. - * - * Inspired by "How to Print Floating-Point Numbers Accurately" by - * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126]. - * - * Modifications: - * 1. Rather than iterating, we use a simple numeric overestimate - * to determine k = floor(log10(d)). We scale relevant - * quantities using O(log2(k)) rather than O(k) multiplications. - * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't - * try to generate digits strictly left to right. Instead, we - * compute with fewer bits and propagate the carry if necessary - * when rounding the final digit up. This is often faster. - * 3. Under the assumption that input will be rounded nearest, - * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. - * That is, we allow equality in stopping tests when the - * round-nearest rule will give the same floating-point value - * as would satisfaction of the stopping test with strict - * inequality. - * 4. We remove common factors of powers of 2 from relevant - * quantities. - * 5. When converting floating-point integers less than 1e16, - * we use floating-point arithmetic rather than resorting - * to multiple-precision integers. - * 6. When asked to produce fewer than 15 digits, we first try - * to get by with floating-point arithmetic; we resort to - * multiple-precision integer arithmetic only if we cannot - * guarantee that the floating-point calculation has given - * the correctly rounded result. For k requested digits and - * "uniformly" distributed input, the probability is - * something like 10^(k-15) that we must resort to the Long - * calculation. - */ - -#ifdef Honor_FLT_ROUNDS -#define Rounding rounding -#undef Check_FLT_ROUNDS -#define Check_FLT_ROUNDS -#else -#define Rounding Flt_Rounds -#endif - - char * -dtoa -#ifdef KR_headers - (d, mode, ndigits, decpt, sign, rve) - double d; int mode, ndigits, *decpt, *sign; char **rve; -#else - (double d, int mode, int ndigits, int *decpt, int *sign, char **rve) -#endif -{ - /* Arguments ndigits, decpt, sign are similar to those - of ecvt and fcvt; trailing zeros are suppressed from - the returned string. If not null, *rve is set to point - to the end of the return value. If d is +-Infinity or NaN, - then *decpt is set to 9999. - - mode: - 0 ==> shortest string that yields d when read in - and rounded to nearest. - 1 ==> like 0, but with Steele & White stopping rule; - e.g. with IEEE P754 arithmetic , mode 0 gives - 1e23 whereas mode 1 gives 9.999999999999999e22. - 2 ==> max(1,ndigits) significant digits. This gives a - return value similar to that of ecvt, except - that trailing zeros are suppressed. - 3 ==> through ndigits past the decimal point. This - gives a return value similar to that from fcvt, - except that trailing zeros are suppressed, and - ndigits can be negative. - 4,5 ==> similar to 2 and 3, respectively, but (in - round-nearest mode) with the tests of mode 0 to - possibly return a shorter string that rounds to d. - With IEEE arithmetic and compilation with - -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same - as modes 2 and 3 when FLT_ROUNDS != 1. - 6-9 ==> Debugging modes similar to mode - 4: don't try - fast floating-point estimate (if applicable). - - Values of mode other than 0-9 are treated as mode 0. - - Sufficient space is allocated to the return value - to hold the suppressed trailing zeros. - */ - - int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1, - j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, - spec_case, try_quick; - Long L; -#ifndef Sudden_Underflow - int denorm; - ULong x; -#endif - Bigint *b, *b1, *delta, *mlo, *mhi, *S; - double d2, ds, eps; - char *s, *s0; -#ifdef Honor_FLT_ROUNDS - int rounding; -#endif -#ifdef SET_INEXACT - int inexact, oldinexact; -#endif - -#ifndef MULTIPLE_THREADS - if (dtoa_result) { - freedtoa(dtoa_result); - dtoa_result = 0; - } -#endif - - if (word0(d) & Sign_bit) { - /* set sign for everything, including 0's and NaNs */ - *sign = 1; - word0(d) &= ~Sign_bit; /* clear sign bit */ - } - else - *sign = 0; - -#if defined(IEEE_Arith) + defined(VAX) -#ifdef IEEE_Arith - if ((word0(d) & Exp_mask) == Exp_mask) -#else - if (word0(d) == 0x8000) -#endif - { - /* Infinity or NaN */ - *decpt = 9999; -#ifdef IEEE_Arith - if (!word1(d) && !(word0(d) & 0xfffff)) - return nrv_alloc("Infinity", rve, 8); -#endif - return nrv_alloc("NaN", rve, 3); - } -#endif -#ifdef IBM - dval(d) += 0; /* normalize */ -#endif - if (!dval(d)) { - *decpt = 1; - return nrv_alloc("0", rve, 1); - } - -#ifdef SET_INEXACT - try_quick = oldinexact = get_inexact(); - inexact = 1; -#endif -#ifdef Honor_FLT_ROUNDS - if ((rounding = Flt_Rounds) >= 2) { - if (*sign) - rounding = rounding == 2 ? 0 : 2; - else - if (rounding != 2) - rounding = 0; - } -#endif - - b = d2b(dval(d), &be, &bbits); -#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)) )!=0) { -#endif - dval(d2) = dval(d); - word0(d2) &= Frac_mask1; - word0(d2) |= Exp_11; -#ifdef IBM - if (( j = 11 - hi0bits(word0(d2) & Frac_mask) )!=0) - dval(d2) /= 1 << j; -#endif - - /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 - * log10(x) = log(x) / log(10) - * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) - * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) - * - * This suggests computing an approximation k to log10(d) by - * - * k = (i - Bias)*0.301029995663981 - * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); - * - * We want k to be too large rather than too small. - * The error in the first-order Taylor series approximation - * is in our favor, so we just round up the constant enough - * to compensate for any error in the multiplication of - * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, - * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, - * adding 1e-13 to the constant term more than suffices. - * Hence we adjust the constant term to 0.1760912590558. - * (We could get a more accurate k by invoking log10, - * but this is probably not worthwhile.) - */ - - i -= Bias; -#ifdef IBM - i <<= 2; - i += j; -#endif -#ifndef Sudden_Underflow - denorm = 0; - } - else { - /* 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; - dval(d2) = x; - word0(d2) -= 31*Exp_msk1; /* adjust exponent */ - i -= (Bias + (P-1) - 1) + 1; - denorm = 1; - } -#endif - ds = (dval(d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; - k = (int)ds; - if (ds < 0. && ds != k) - k--; /* want k = floor(ds) */ - k_check = 1; - if (k >= 0 && k <= Ten_pmax) { - if (dval(d) < tens[k]) - k--; - k_check = 0; - } - j = bbits - i - 1; - if (j >= 0) { - b2 = 0; - s2 = j; - } - else { - b2 = -j; - s2 = 0; - } - if (k >= 0) { - b5 = 0; - s5 = k; - s2 += k; - } - else { - b2 -= k; - b5 = -k; - s5 = 0; - } - if (mode < 0 || mode > 9) - mode = 0; - -#ifndef SET_INEXACT -#ifdef Check_FLT_ROUNDS - try_quick = Rounding == 1; -#else - try_quick = 1; -#endif -#endif /*SET_INEXACT*/ - - if (mode > 5) { - mode -= 4; - try_quick = 0; - } - leftright = 1; - switch(mode) { - case 0: - case 1: - ilim = ilim1 = -1; - i = 18; - ndigits = 0; - break; - case 2: - leftright = 0; - /* no break */ - case 4: - if (ndigits <= 0) - ndigits = 1; - ilim = ilim1 = i = ndigits; - break; - case 3: - leftright = 0; - /* no break */ - case 5: - i = ndigits + k + 1; - ilim = i; - ilim1 = i - 1; - if (i <= 0) - i = 1; - } - s = s0 = rv_alloc(i); - -#ifdef Honor_FLT_ROUNDS - if (mode > 1 && rounding != 1) - leftright = 0; -#endif - - if (ilim >= 0 && ilim <= Quick_max && try_quick) { - - /* Try to get by with floating-point arithmetic. */ - - i = 0; - dval(d2) = dval(d); - k0 = k; - ilim0 = ilim; - ieps = 2; /* conservative */ - if (k > 0) { - ds = tens[k&0xf]; - j = k >> 4; - if (j & Bletch) { - /* prevent overflows */ - j &= Bletch - 1; - dval(d) /= bigtens[n_bigtens-1]; - ieps++; - } - for(; j; j >>= 1, i++) - if (j & 1) { - ieps++; - ds *= bigtens[i]; - } - dval(d) /= ds; - } - else if (( j1 = -k )!=0) { - dval(d) *= tens[j1 & 0xf]; - for(j = j1 >> 4; j; j >>= 1, i++) - if (j & 1) { - ieps++; - dval(d) *= bigtens[i]; - } - } - if (k_check && dval(d) < 1. && ilim > 0) { - if (ilim1 <= 0) - goto fast_failed; - ilim = ilim1; - k--; - dval(d) *= 10.; - ieps++; - } - dval(eps) = ieps*dval(d) + 7.; - word0(eps) -= (P-1)*Exp_msk1; - if (ilim == 0) { - S = mhi = 0; - dval(d) -= 5.; - if (dval(d) > dval(eps)) - goto one_digit; - if (dval(d) < -dval(eps)) - goto no_digits; - goto fast_failed; - } -#ifndef No_leftright - if (leftright) { - /* Use Steele & White method of only - * generating digits needed. - */ - dval(eps) = 0.5/tens[ilim-1] - dval(eps); - for(i = 0;;) { - L = dval(d); - dval(d) -= L; - *s++ = '0' + (int)L; - if (dval(d) < dval(eps)) - goto ret1; - if (1. - dval(d) < dval(eps)) - goto bump_up; - if (++i >= ilim) - break; - dval(eps) *= 10.; - dval(d) *= 10.; - } - } - else { -#endif - /* Generate ilim digits, then fix them up. */ - dval(eps) *= tens[ilim-1]; - for(i = 1;; i++, dval(d) *= 10.) { - L = (Long)(dval(d)); - if (!(dval(d) -= L)) - ilim = i; - *s++ = '0' + (int)L; - if (i == ilim) { - if (dval(d) > 0.5 + dval(eps)) - goto bump_up; - else if (dval(d) < 0.5 - dval(eps)) { - while(*--s == '0'); - s++; - goto ret1; - } - break; - } - } -#ifndef No_leftright - } -#endif - fast_failed: - s = s0; - dval(d) = dval(d2); - k = k0; - ilim = ilim0; - } - - /* Do we have a "small" integer? */ - - if (be >= 0 && k <= Int_max) { - /* Yes. */ - ds = tens[k]; - if (ndigits < 0 && ilim <= 0) { - S = mhi = 0; - if (ilim < 0 || dval(d) <= 5*ds) - goto no_digits; - goto one_digit; - } - for(i = 1;; i++, dval(d) *= 10.) { - L = (Long)(dval(d) / ds); - dval(d) -= L*ds; -#ifdef Check_FLT_ROUNDS - /* If FLT_ROUNDS == 2, L will usually be high by 1 */ - if (dval(d) < 0) { - L--; - dval(d) += ds; - } -#endif - *s++ = '0' + (int)L; - if (!dval(d)) { -#ifdef SET_INEXACT - inexact = 0; -#endif - break; - } - if (i == ilim) { -#ifdef Honor_FLT_ROUNDS - if (mode > 1) - switch(rounding) { - case 0: goto ret1; - case 2: goto bump_up; - } -#endif - dval(d) += dval(d); - if (dval(d) > ds || dval(d) == ds && L & 1) { - bump_up: - while(*--s == '9') - if (s == s0) { - k++; - *s = '0'; - break; - } - ++*s++; - } - break; - } - } - goto ret1; - } - - m2 = b2; - m5 = b5; - mhi = mlo = 0; - if (leftright) { - i = -#ifndef Sudden_Underflow - denorm ? be + (Bias + (P-1) - 1 + 1) : -#endif -#ifdef IBM - 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3); -#else - 1 + P - bbits; -#endif - b2 += i; - s2 += i; - mhi = i2b(1); - } - if (m2 > 0 && s2 > 0) { - i = m2 < s2 ? m2 : s2; - b2 -= i; - m2 -= i; - s2 -= i; - } - if (b5 > 0) { - if (leftright) { - if (m5 > 0) { - mhi = pow5mult(mhi, m5); - b1 = mult(mhi, b); - Bfree(b); - b = b1; - } - if (( j = b5 - m5 )!=0) - b = pow5mult(b, j); - } - else - b = pow5mult(b, b5); - } - S = i2b(1); - if (s5 > 0) - S = pow5mult(S, s5); - - /* Check for special case that d is a normalized power of 2. */ - - spec_case = 0; - if ((mode < 2 || leftright) -#ifdef Honor_FLT_ROUNDS - && rounding == 1 -#endif - ) { - if (!word1(d) && !(word0(d) & Bndry_mask) -#ifndef Sudden_Underflow - && word0(d) & (Exp_mask & ~Exp_msk1) -#endif - ) { - /* The special case */ - b2 += Log2P; - s2 += Log2P; - spec_case = 1; - } - } - - /* Arrange for convenient computation of quotients: - * shift left if necessary so divisor has 4 leading 0 bits. - * - * Perhaps we should just compute leading 28 bits of S once - * and for all and pass them and a shift to quorem, so it - * 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 )!=0) - i = 32 - i; -#else - if (( i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf )!=0) - i = 16 - i; -#endif - if (i > 4) { - i -= 4; - b2 += i; - m2 += i; - s2 += i; - } - else if (i < 4) { - i += 28; - b2 += i; - m2 += i; - s2 += i; - } - if (b2 > 0) - b = lshift(b, b2); - if (s2 > 0) - S = lshift(S, s2); - if (k_check) { - if (cmp(b,S) < 0) { - k--; - b = multadd(b, 10, 0); /* we botched the k estimate */ - if (leftright) - mhi = multadd(mhi, 10, 0); - ilim = ilim1; - } - } - if (ilim <= 0 && (mode == 3 || mode == 5)) { - if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) { - /* no digits, fcvt style */ - no_digits: - k = -1 - ndigits; - goto ret; - } - one_digit: - *s++ = '1'; - k++; - goto ret; - } - if (leftright) { - if (m2 > 0) - mhi = lshift(mhi, m2); - - /* Compute mlo -- check for special case - * that d is a normalized power of 2. - */ - - mlo = mhi; - if (spec_case) { - mhi = Balloc(mhi->k); - Bcopy(mhi, mlo); - mhi = lshift(mhi, Log2P); - } - - for(i = 1;;i++) { - dig = quorem(b,S) + '0'; - /* Do we yet have the shortest decimal string - * that will round to d? - */ - j = cmp(b, mlo); - delta = diff(S, mhi); - j1 = delta->sign ? 1 : cmp(b, delta); - Bfree(delta); -#ifndef ROUND_BIASED - if (j1 == 0 && mode != 1 && !(word1(d) & 1) -#ifdef Honor_FLT_ROUNDS - && rounding >= 1 -#endif - ) { - if (dig == '9') - goto round_9_up; - if (j > 0) - dig++; -#ifdef SET_INEXACT - else if (!b->x[0] && b->wds <= 1) - inexact = 0; -#endif - *s++ = dig; - goto ret; - } -#endif - if (j < 0 || j == 0 && mode != 1 -#ifndef ROUND_BIASED - && !(word1(d) & 1) -#endif - ) { - if (!b->x[0] && b->wds <= 1) { -#ifdef SET_INEXACT - inexact = 0; -#endif - goto accept_dig; - } -#ifdef Honor_FLT_ROUNDS - if (mode > 1) - switch(rounding) { - case 0: goto accept_dig; - case 2: goto keep_dig; - } -#endif /*Honor_FLT_ROUNDS*/ - if (j1 > 0) { - b = lshift(b, 1); - j1 = cmp(b, S); - if ((j1 > 0 || j1 == 0 && dig & 1) - && dig++ == '9') - goto round_9_up; - } - accept_dig: - *s++ = dig; - goto ret; - } - if (j1 > 0) { -#ifdef Honor_FLT_ROUNDS - if (!rounding) - goto accept_dig; -#endif - if (dig == '9') { /* possible if i == 1 */ - round_9_up: - *s++ = '9'; - goto roundoff; - } - *s++ = dig + 1; - goto ret; - } -#ifdef Honor_FLT_ROUNDS - keep_dig: -#endif - *s++ = dig; - if (i == ilim) - break; - b = multadd(b, 10, 0); - if (mlo == mhi) - mlo = mhi = multadd(mhi, 10, 0); - else { - mlo = multadd(mlo, 10, 0); - mhi = multadd(mhi, 10, 0); - } - } - } - else - for(i = 1;; i++) { - *s++ = dig = quorem(b,S) + '0'; - if (!b->x[0] && b->wds <= 1) { -#ifdef SET_INEXACT - inexact = 0; -#endif - goto ret; - } - if (i >= ilim) - break; - b = multadd(b, 10, 0); - } - - /* Round off last digit */ - -#ifdef Honor_FLT_ROUNDS - switch(rounding) { - case 0: goto trimzeros; - case 2: goto roundoff; - } -#endif - b = lshift(b, 1); - j = cmp(b, S); - if (j > 0 || j == 0 && dig & 1) { - roundoff: - while(*--s == '9') - if (s == s0) { - k++; - *s++ = '1'; - goto ret; - } - ++*s++; - } - else { - trimzeros: - while(*--s == '0'); - s++; - } - ret: - Bfree(S); - if (mhi) { - if (mlo && mlo != mhi) - Bfree(mlo); - Bfree(mhi); - } - ret1: -#ifdef SET_INEXACT - if (inexact) { - if (!oldinexact) { - word0(d) = Exp_1 + (70 << Exp_shift); - word1(d) = 0; - dval(d) += 1.; - } - } - else if (!oldinexact) - clear_inexact(); -#endif - Bfree(b); - *s = 0; - *decpt = k + 1; - if (rve) - *rve = s; - return s0; - } diff --git a/gdtoa/gdtoa-dtoa-fbsd.c b/gdtoa/gdtoa-dtoa-fbsd.c new file mode 120000 index 0000000..82ff421 --- /dev/null +++ b/gdtoa/gdtoa-dtoa-fbsd.c @@ -0,0 +1 @@ +./gdtoa-dtoa.c \ No newline at end of file diff --git a/gdtoa/gdtoa-gmisc-fbsd.c b/gdtoa/gdtoa-gmisc-fbsd.c deleted file mode 100644 index 8270ef9..0000000 --- a/gdtoa/gdtoa-gmisc-fbsd.c +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************** - -The author of this software is David M. Gay. - -Copyright (C) 1998 by Lucent Technologies -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 the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES 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. - -****************************************************************/ - -/* Please send bug reports to David M. Gay (dmg at acm dot org, - * with " at " changed at "@" and " dot " changed to "."). */ - -#include "gdtoaimp.h" - - void -#ifdef KR_headers -rshift(b, k) Bigint *b; int k; -#else -rshift(Bigint *b, int k) -#endif -{ - ULong *x, *x1, *xe, y; - int n; - - x = x1 = b->x; - n = k >> kshift; - if (n < b->wds) { - xe = x + b->wds; - x += n; - if (k &= kmask) { - n = ULbits - k; - y = *x++ >> k; - while(x < xe) { - *x1++ = (y | (*x << n)) & ALL_ON; - y = *x++ >> k; - } - if ((*x1 = y) !=0) - x1++; - } - else - while(x < xe) - *x1++ = *x++; - } - if ((b->wds = x1 - b->x) == 0) - b->x[0] = 0; - } - - int -#ifdef KR_headers -trailz(b) Bigint *b; -#else -trailz(Bigint *b) -#endif -{ - ULong L, *x, *xe; - int n = 0; - - x = b->x; - xe = x + b->wds; - for(n = 0; x < xe && !*x; x++) - n += ULbits; - if (x < xe) { - L = *x; - n += lo0bits(&L); - } - return n; - } diff --git a/gdtoa/gdtoa-gmisc-fbsd.c b/gdtoa/gdtoa-gmisc-fbsd.c new file mode 120000 index 0000000..d7a4165 --- /dev/null +++ b/gdtoa/gdtoa-gmisc-fbsd.c @@ -0,0 +1 @@ +./gdtoa-gmisc.c \ No newline at end of file diff --git a/gdtoa/gdtoa-hd_init-fbsd.c b/gdtoa/gdtoa-hd_init-fbsd.c deleted file mode 100644 index fa6e18d..0000000 --- a/gdtoa/gdtoa-hd_init-fbsd.c +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************** - -The author of this software is David M. Gay. - -Copyright (C) 2000 by Lucent Technologies -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 the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES 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. - -****************************************************************/ - -/* Please send bug reports to David M. Gay (dmg at acm dot org, - * with " at " changed at "@" and " dot " changed to "."). */ - -#include "gdtoaimp.h" - - unsigned char hexdig[256]; - - static void -#ifdef KR_headers -htinit(h, s, inc) unsigned char *h; unsigned char *s; int inc; -#else -htinit(unsigned char *h, unsigned char *s, int inc) -#endif -{ - int i, j; - for(i = 0; (j = s[i]) !=0; i++) - h[j] = i + inc; - } - - void -hexdig_init_D2A(Void) -{ -#define USC (unsigned char *) - htinit(hexdig, USC "0123456789", 0x10); - htinit(hexdig, USC "abcdef", 0x10 + 10); - htinit(hexdig, USC "ABCDEF", 0x10 + 10); - } diff --git a/gdtoa/gdtoa-hd_init-fbsd.c b/gdtoa/gdtoa-hd_init-fbsd.c new file mode 120000 index 0000000..795e2b0 --- /dev/null +++ b/gdtoa/gdtoa-hd_init-fbsd.c @@ -0,0 +1 @@ +./gdtoa-hd_init.c \ No newline at end of file diff --git a/gdtoa/gdtoa-hexnan-fbsd.c b/gdtoa/gdtoa-hexnan-fbsd.c index 6ba12a8..a953da1 100644 --- a/gdtoa/gdtoa-hexnan-fbsd.c +++ b/gdtoa/gdtoa-hexnan-fbsd.c @@ -98,7 +98,7 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0) x0[2] = (ULong)(u.bits.manh >> 12); x0[1] = ((ULong)u.bits.manh & 0xfff) << 20 | (ULong)(u.bits.manl >> 32); x0[0] = (ULong)u.bits.manl; -#elif defined(__i386__) || defined(__x86_64__) +#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) x0[1] = (ULong)u.bits.manh; x0[0] = (ULong)u.bits.manl; #else diff --git a/gdtoa/gdtoa-misc-fbsd.c b/gdtoa/gdtoa-misc-fbsd.c deleted file mode 100644 index b3ce7c9..0000000 --- a/gdtoa/gdtoa-misc-fbsd.c +++ /dev/null @@ -1,865 +0,0 @@ -/**************************************************************** - -The author of this software is David M. Gay. - -Copyright (C) 1998, 1999 by Lucent Technologies -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 the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES 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. - -****************************************************************/ - -/* Please send bug reports to David M. Gay (dmg at acm dot org, - * with " at " changed at "@" and " dot " changed to "."). */ - -#include "gdtoaimp.h" - - static Bigint *freelist[Kmax+1]; -#ifndef Omit_Private_Memory -#ifndef PRIVATE_MEM -#define PRIVATE_MEM 2304 -#endif -#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double)) -static double private_mem[PRIVATE_mem], *pmem_next = private_mem; -#endif - - Bigint * -Balloc -#ifdef KR_headers - (k) int k; -#else - (int k) -#endif -{ - int x; - Bigint *rv; -#ifndef Omit_Private_Memory - unsigned int len; -#endif - - ACQUIRE_DTOA_LOCK(0); - if ( (rv = freelist[k]) !=0) { - freelist[k] = rv->next; - } - else { - x = 1 << k; -#ifdef Omit_Private_Memory - rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong)); -#else - len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) - /sizeof(double); - if (pmem_next - private_mem + len <= PRIVATE_mem) { - rv = (Bigint*)pmem_next; - pmem_next += len; - } - else - rv = (Bigint*)MALLOC(len*sizeof(double)); -#endif - rv->k = k; - rv->maxwds = x; - } - FREE_DTOA_LOCK(0); - rv->sign = rv->wds = 0; - return rv; - } - - void -Bfree -#ifdef KR_headers - (v) Bigint *v; -#else - (Bigint *v) -#endif -{ - if (v) { - ACQUIRE_DTOA_LOCK(0); - v->next = freelist[v->k]; - freelist[v->k] = v; - FREE_DTOA_LOCK(0); - } - } - - int -lo0bits -#ifdef KR_headers - (y) ULong *y; -#else - (ULong *y) -#endif -{ - register int k; - register ULong x = *y; - - if (x & 7) { - if (x & 1) - return 0; - if (x & 2) { - *y = x >> 1; - return 1; - } - *y = x >> 2; - return 2; - } - k = 0; - if (!(x & 0xffff)) { - k = 16; - x >>= 16; - } - if (!(x & 0xff)) { - k += 8; - x >>= 8; - } - if (!(x & 0xf)) { - k += 4; - x >>= 4; - } - if (!(x & 0x3)) { - k += 2; - x >>= 2; - } - if (!(x & 1)) { - k++; - x >>= 1; - if (!x) - return 32; - } - *y = x; - return k; - } - - Bigint * -multadd -#ifdef KR_headers - (b, m, a) Bigint *b; int m, a; -#else - (Bigint *b, int m, int a) /* multiply by m and add a */ -#endif -{ - int i, wds; -#ifdef ULLong - ULong *x; - ULLong carry, y; -#else - ULong carry, *x, y; -#ifdef Pack_32 - ULong xi, z; -#endif -#endif - Bigint *b1; - - wds = b->wds; - x = b->x; - i = 0; - carry = a; - do { -#ifdef ULLong - y = *x * (ULLong)m + carry; - carry = y >> 32; - *x++ = y & 0xffffffffUL; -#else -#ifdef Pack_32 - xi = *x; - y = (xi & 0xffff) * m + carry; - z = (xi >> 16) * m + (y >> 16); - carry = z >> 16; - *x++ = (z << 16) + (y & 0xffff); -#else - y = *x * m + carry; - carry = y >> 16; - *x++ = y & 0xffff; -#endif -#endif - } - while(++i < wds); - if (carry) { - if (wds >= b->maxwds) { - b1 = Balloc(b->k+1); - Bcopy(b1, b); - Bfree(b); - b = b1; - } - b->x[wds++] = carry; - b->wds = wds; - } - return b; - } - - int -hi0bits_D2A -#ifdef KR_headers - (x) register ULong x; -#else - (register ULong x) -#endif -{ - register int k = 0; - - if (!(x & 0xffff0000)) { - k = 16; - x <<= 16; - } - if (!(x & 0xff000000)) { - k += 8; - x <<= 8; - } - if (!(x & 0xf0000000)) { - k += 4; - x <<= 4; - } - if (!(x & 0xc0000000)) { - k += 2; - x <<= 2; - } - if (!(x & 0x80000000)) { - k++; - if (!(x & 0x40000000)) - return 32; - } - return k; - } - - Bigint * -i2b -#ifdef KR_headers - (i) int i; -#else - (int i) -#endif -{ - Bigint *b; - - b = Balloc(1); - b->x[0] = i; - b->wds = 1; - return b; - } - - Bigint * -mult -#ifdef KR_headers - (a, b) Bigint *a, *b; -#else - (Bigint *a, Bigint *b) -#endif -{ - Bigint *c; - int k, wa, wb, wc; - ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; - ULong y; -#ifdef ULLong - ULLong carry, z; -#else - ULong carry, z; -#ifdef Pack_32 - ULong z2; -#endif -#endif - - if (a->wds < b->wds) { - c = a; - a = b; - b = c; - } - k = a->k; - wa = a->wds; - wb = b->wds; - wc = wa + wb; - if (wc > a->maxwds) - k++; - c = Balloc(k); - for(x = c->x, xa = x + wc; x < xa; x++) - *x = 0; - xa = a->x; - xae = xa + wa; - xb = b->x; - xbe = xb + wb; - xc0 = c->x; -#ifdef ULLong - for(; xb < xbe; xc0++) { - if ( (y = *xb++) !=0) { - x = xa; - xc = xc0; - carry = 0; - do { - z = *x++ * (ULLong)y + *xc + carry; - carry = z >> 32; - *xc++ = z & 0xffffffffUL; - } - while(x < xae); - *xc = carry; - } - } -#else -#ifdef Pack_32 - for(; xb < xbe; xb++, xc0++) { - if ( (y = *xb & 0xffff) !=0) { - x = xa; - xc = xc0; - carry = 0; - do { - z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; - carry = z >> 16; - z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; - carry = z2 >> 16; - Storeinc(xc, z2, z); - } - while(x < xae); - *xc = carry; - } - if ( (y = *xb >> 16) !=0) { - x = xa; - xc = xc0; - carry = 0; - z2 = *xc; - do { - z = (*x & 0xffff) * y + (*xc >> 16) + carry; - carry = z >> 16; - Storeinc(xc, z, z2); - z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; - carry = z2 >> 16; - } - while(x < xae); - *xc = z2; - } - } -#else - for(; xb < xbe; xc0++) { - if ( (y = *xb++) !=0) { - x = xa; - xc = xc0; - carry = 0; - do { - z = *x++ * y + *xc + carry; - carry = z >> 16; - *xc++ = z & 0xffff; - } - while(x < xae); - *xc = carry; - } - } -#endif -#endif - for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ; - c->wds = wc; - return c; - } - - static Bigint *p5s; - - Bigint * -pow5mult -#ifdef KR_headers - (b, k) Bigint *b; int k; -#else - (Bigint *b, int k) -#endif -{ - Bigint *b1, *p5, *p51; - int i; - static int p05[3] = { 5, 25, 125 }; - - if ( (i = k & 3) !=0) - b = multadd(b, p05[i-1], 0); - - if (!(k >>= 2)) - return b; - if ((p5 = p5s) == 0) { - /* first time */ -#ifdef MULTIPLE_THREADS - ACQUIRE_DTOA_LOCK(1); - if (!(p5 = p5s)) { - p5 = p5s = i2b(625); - p5->next = 0; - } - FREE_DTOA_LOCK(1); -#else - p5 = p5s = i2b(625); - p5->next = 0; -#endif - } - for(;;) { - if (k & 1) { - b1 = mult(b, p5); - Bfree(b); - b = b1; - } - if (!(k >>= 1)) - break; - if ((p51 = p5->next) == 0) { -#ifdef MULTIPLE_THREADS - ACQUIRE_DTOA_LOCK(1); - if (!(p51 = p5->next)) { - p51 = p5->next = mult(p5,p5); - p51->next = 0; - } - FREE_DTOA_LOCK(1); -#else - p51 = p5->next = mult(p5,p5); - p51->next = 0; -#endif - } - p5 = p51; - } - return b; - } - - Bigint * -lshift -#ifdef KR_headers - (b, k) Bigint *b; int k; -#else - (Bigint *b, int k) -#endif -{ - int i, k1, n, n1; - Bigint *b1; - ULong *x, *x1, *xe, z; - - n = k >> kshift; - k1 = b->k; - n1 = n + b->wds + 1; - for(i = b->maxwds; n1 > i; i <<= 1) - k1++; - b1 = Balloc(k1); - x1 = b1->x; - for(i = 0; i < n; i++) - *x1++ = 0; - x = b->x; - xe = x + b->wds; - if (k &= kmask) { -#ifdef Pack_32 - k1 = 32 - k; - z = 0; - do { - *x1++ = *x << k | z; - z = *x++ >> k1; - } - while(x < xe); - if ((*x1 = z) !=0) - ++n1; -#else - k1 = 16 - k; - z = 0; - do { - *x1++ = *x << k & 0xffff | z; - z = *x++ >> k1; - } - while(x < xe); - if (*x1 = z) - ++n1; -#endif - } - else do - *x1++ = *x++; - while(x < xe); - b1->wds = n1 - 1; - Bfree(b); - return b1; - } - - int -cmp -#ifdef KR_headers - (a, b) Bigint *a, *b; -#else - (Bigint *a, Bigint *b) -#endif -{ - ULong *xa, *xa0, *xb, *xb0; - int i, j; - - i = a->wds; - j = b->wds; -#ifdef DEBUG - if (i > 1 && !a->x[i-1]) - Bug("cmp called with a->x[a->wds-1] == 0"); - if (j > 1 && !b->x[j-1]) - Bug("cmp called with b->x[b->wds-1] == 0"); -#endif - if (i -= j) - return i; - xa0 = a->x; - xa = xa0 + j; - xb0 = b->x; - xb = xb0 + j; - for(;;) { - if (*--xa != *--xb) - return *xa < *xb ? -1 : 1; - if (xa <= xa0) - break; - } - return 0; - } - - Bigint * -diff -#ifdef KR_headers - (a, b) Bigint *a, *b; -#else - (Bigint *a, Bigint *b) -#endif -{ - Bigint *c; - int i, wa, wb; - ULong *xa, *xae, *xb, *xbe, *xc; -#ifdef ULLong - ULLong borrow, y; -#else - ULong borrow, y; -#ifdef Pack_32 - ULong z; -#endif -#endif - - i = cmp(a,b); - if (!i) { - c = Balloc(0); - c->wds = 1; - c->x[0] = 0; - return c; - } - if (i < 0) { - c = a; - a = b; - b = c; - i = 1; - } - else - i = 0; - c = Balloc(a->k); - c->sign = i; - wa = a->wds; - xa = a->x; - xae = xa + wa; - wb = b->wds; - xb = b->x; - xbe = xb + wb; - xc = c->x; - borrow = 0; -#ifdef ULLong - do { - y = (ULLong)*xa++ - *xb++ - borrow; - borrow = y >> 32 & 1UL; - *xc++ = y & 0xffffffffUL; - } - while(xb < xbe); - while(xa < xae) { - y = *xa++ - borrow; - borrow = y >> 32 & 1UL; - *xc++ = y & 0xffffffffUL; - } -#else -#ifdef Pack_32 - do { - y = (*xa & 0xffff) - (*xb & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - z = (*xa++ >> 16) - (*xb++ >> 16) - borrow; - borrow = (z & 0x10000) >> 16; - Storeinc(xc, z, y); - } - while(xb < xbe); - while(xa < xae) { - y = (*xa & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - z = (*xa++ >> 16) - borrow; - borrow = (z & 0x10000) >> 16; - Storeinc(xc, z, y); - } -#else - do { - y = *xa++ - *xb++ - borrow; - borrow = (y & 0x10000) >> 16; - *xc++ = y & 0xffff; - } - while(xb < xbe); - while(xa < xae) { - y = *xa++ - borrow; - borrow = (y & 0x10000) >> 16; - *xc++ = y & 0xffff; - } -#endif -#endif - while(!*--xc) - wa--; - c->wds = wa; - return c; - } - - double -b2d -#ifdef KR_headers - (a, e) Bigint *a; int *e; -#else - (Bigint *a, int *e) -#endif -{ - ULong *xa, *xa0, w, y, z; - int k; - double d; -#ifdef VAX - ULong d0, d1; -#else -#define d0 word0(d) -#define d1 word1(d) -#endif - - xa0 = a->x; - xa = xa0 + a->wds; - y = *--xa; -#ifdef DEBUG - if (!y) Bug("zero y in b2d"); -#endif - k = hi0bits(y); - *e = 32 - k; -#ifdef Pack_32 - if (k < Ebits) { - d0 = Exp_1 | y >> Ebits - k; - w = xa > xa0 ? *--xa : 0; - 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; - y = xa > xa0 ? *--xa : 0; - d1 = z << k | y >> 32 - k; - } - else { - d0 = Exp_1 | y; - d1 = z; - } -#else - if (k < Ebits + 16) { - z = xa > xa0 ? *--xa : 0; - d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k; - w = xa > xa0 ? *--xa : 0; - y = xa > xa0 ? *--xa : 0; - d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k; - goto ret_d; - } - z = xa > xa0 ? *--xa : 0; - w = xa > xa0 ? *--xa : 0; - k -= Ebits + 16; - d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k; - y = xa > xa0 ? *--xa : 0; - d1 = w << k + 16 | y << k; -#endif - ret_d: -#ifdef VAX - word0(d) = d0 >> 16 | d0 << 16; - word1(d) = d1 >> 16 | d1 << 16; -#endif - return dval(d); - } -#undef d0 -#undef d1 - - Bigint * -d2b -#ifdef KR_headers - (d, e, bits) double d; int *e, *bits; -#else - (double d, int *e, int *bits) -#endif -{ - Bigint *b; -#ifndef Sudden_Underflow - int i; -#endif - int de, k; - ULong *x, y, z; -#ifdef VAX - ULong d0, d1; - d0 = word0(d) >> 16 | word0(d) << 16; - d1 = word1(d) >> 16 | word1(d) << 16; -#else -#define d0 word0(d) -#define d1 word1(d) -#endif - -#ifdef Pack_32 - b = Balloc(1); -#else - b = Balloc(2); -#endif - x = b->x; - - z = d0 & Frac_mask; - d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ -#ifdef Sudden_Underflow - de = (int)(d0 >> Exp_shift); -#ifndef IBM - z |= Exp_msk11; -#endif -#else - if ( (de = (int)(d0 >> Exp_shift)) !=0) - z |= Exp_msk1; -#endif -#ifdef Pack_32 - if ( (y = d1) !=0) { - if ( (k = lo0bits(&y)) !=0) { - x[0] = y | z << 32 - k; - z >>= k; - } - else - x[0] = y; -#ifndef Sudden_Underflow - i = -#endif - b->wds = (x[1] = z) !=0 ? 2 : 1; - } - else { -#ifdef DEBUG - if (!z) - Bug("Zero passed to d2b"); -#endif - k = lo0bits(&z); - x[0] = z; -#ifndef Sudden_Underflow - i = -#endif - b->wds = 1; - k += 32; - } -#else - if ( (y = d1) !=0) { - if ( (k = lo0bits(&y)) !=0) - if (k >= 16) { - x[0] = y | z << 32 - k & 0xffff; - x[1] = z >> k - 16 & 0xffff; - x[2] = z >> k; - i = 2; - } - else { - x[0] = y & 0xffff; - x[1] = y >> 16 | z << 16 - k & 0xffff; - x[2] = z >> k & 0xffff; - x[3] = z >> k+16; - i = 3; - } - else { - x[0] = y & 0xffff; - x[1] = y >> 16; - x[2] = z & 0xffff; - x[3] = z >> 16; - i = 3; - } - } - else { -#ifdef DEBUG - if (!z) - Bug("Zero passed to d2b"); -#endif - k = lo0bits(&z); - if (k >= 16) { - x[0] = z; - i = 0; - } - else { - x[0] = z & 0xffff; - x[1] = z >> 16; - i = 1; - } - k += 32; - } - while(!x[i]) - --i; - b->wds = i + 1; -#endif -#ifndef Sudden_Underflow - if (de) { -#endif -#ifdef IBM - *e = (de - Bias - (P-1) << 2) + k; - *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask); -#else - *e = de - Bias - (P-1) + k; - *bits = P - k; -#endif -#ifndef Sudden_Underflow - } - else { - *e = de - Bias - (P-1) + 1 + k; -#ifdef Pack_32 - *bits = 32*i - hi0bits(x[i-1]); -#else - *bits = (i+2)*16 - hi0bits(x[i]); -#endif - } -#endif - return b; - } -#undef d0 -#undef d1 - - CONST double -#ifdef IEEE_Arith -bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }; -CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 - }; -#else -#ifdef IBM -bigtens[] = { 1e16, 1e32, 1e64 }; -CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 }; -#else -bigtens[] = { 1e16, 1e32 }; -CONST double tinytens[] = { 1e-16, 1e-32 }; -#endif -#endif - - CONST double -tens[] = { - 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, - 1e20, 1e21, 1e22 -#ifdef VAX - , 1e23, 1e24 -#endif - }; - - char * -#ifdef KR_headers -strcp_D2A(a, b) char *a; char *b; -#else -strcp_D2A(char *a, CONST char *b) -#endif -{ - while(*a = *b++) - a++; - return a; - } - -#ifdef NO_STRING_H - - Char * -#ifdef KR_headers -memcpy_D2A(a, b, len) Char *a; Char *b; size_t len; -#else -memcpy_D2A(void *a1, void *b1, size_t len) -#endif -{ - register char *a = (char*)a1, *ae = a + len; - register char *b = (char*)b1, *a0 = a; - while(a < ae) - *a++ = *b++; - return a0; - } - -#endif /* NO_STRING_H */ diff --git a/gdtoa/gdtoa-misc-fbsd.c b/gdtoa/gdtoa-misc-fbsd.c new file mode 120000 index 0000000..171bacb --- /dev/null +++ b/gdtoa/gdtoa-misc-fbsd.c @@ -0,0 +1 @@ +./gdtoa-misc.c \ No newline at end of file diff --git a/gdtoa/gdtoa-sum-fbsd.c b/gdtoa/gdtoa-sum-fbsd.c deleted file mode 100644 index dc0c88b..0000000 --- a/gdtoa/gdtoa-sum-fbsd.c +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************** - -The author of this software is David M. Gay. - -Copyright (C) 1998 by Lucent Technologies -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 the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES 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. - -****************************************************************/ - -/* Please send bug reports to David M. Gay (dmg at acm dot org, - * with " at " changed at "@" and " dot " changed to "."). */ - -#include "gdtoaimp.h" - - Bigint * -#ifdef KR_headers -sum(a, b) Bigint *a; Bigint *b; -#else -sum(Bigint *a, Bigint *b) -#endif -{ - Bigint *c; - ULong carry, *xc, *xa, *xb, *xe, y; -#ifdef Pack_32 - ULong z; -#endif - - if (a->wds < b->wds) { - c = b; b = a; a = c; - } - c = Balloc(a->k); - c->wds = a->wds; - carry = 0; - xa = a->x; - xb = b->x; - xc = c->x; - xe = xc + b->wds; -#ifdef Pack_32 - do { - y = (*xa & 0xffff) + (*xb & 0xffff) + carry; - carry = (y & 0x10000) >> 16; - z = (*xa++ >> 16) + (*xb++ >> 16) + carry; - carry = (z & 0x10000) >> 16; - Storeinc(xc, z, y); - } - while(xc < xe); - xe += a->wds - b->wds; - while(xc < xe) { - y = (*xa & 0xffff) + carry; - carry = (y & 0x10000) >> 16; - z = (*xa++ >> 16) + carry; - carry = (z & 0x10000) >> 16; - Storeinc(xc, z, y); - } -#else - do { - y = *xa++ + *xb++ + carry; - carry = (y & 0x10000) >> 16; - *xc++ = y & 0xffff; - } - while(xc < xe); - xe += a->wds - b->wds; - while(xc < xe) { - y = *xa++ + carry; - carry = (y & 0x10000) >> 16; - *xc++ = y & 0xffff; - } -#endif - if (carry) { - if (c->wds == c->maxwds) { - b = Balloc(c->k + 1); - Bcopy(b, c); - Bfree(c); - c = b; - } - c->x[c->wds++] = 1; - } - return c; - } diff --git a/gdtoa/gdtoa-sum-fbsd.c b/gdtoa/gdtoa-sum-fbsd.c new file mode 120000 index 0000000..d7692e4 --- /dev/null +++ b/gdtoa/gdtoa-sum-fbsd.c @@ -0,0 +1 @@ +./gdtoa-sum.c \ No newline at end of file diff --git a/gdtoa/gdtoa-ulp-fbsd.c b/gdtoa/gdtoa-ulp-fbsd.c deleted file mode 100644 index 7810a5c..0000000 --- a/gdtoa/gdtoa-ulp-fbsd.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************** - -The author of this software is David M. Gay. - -Copyright (C) 1998, 1999 by Lucent Technologies -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 the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES 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. - -****************************************************************/ - -/* Please send bug reports to David M. Gay (dmg at acm dot org, - * with " at " changed at "@" and " dot " changed to "."). */ - -#include "gdtoaimp.h" - - double -ulp -#ifdef KR_headers - (x) double x; -#else - (double x) -#endif -{ - Long L; - double a; - - L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; -#ifndef Sudden_Underflow - if (L > 0) { -#endif -#ifdef IBM - L |= Exp_msk1 >> 4; -#endif - word0(a) = L; - word1(a) = 0; -#ifndef Sudden_Underflow - } - else { - L = -L >> Exp_shift; - if (L < Exp_shift) { - word0(a) = 0x80000 >> L; - word1(a) = 0; - } - else { - word0(a) = 0; - L -= Exp_shift; - word1(a) = L >= 31 ? 1 : 1 << 31 - L; - } - } -#endif - return a; - } diff --git a/gdtoa/gdtoa-ulp-fbsd.c b/gdtoa/gdtoa-ulp-fbsd.c new file mode 120000 index 0000000..5e1ddd4 --- /dev/null +++ b/gdtoa/gdtoa-ulp-fbsd.c @@ -0,0 +1 @@ +./gdtoa-ulp.c \ No newline at end of file diff --git a/gdtoa/gdtoa.h b/gdtoa/gdtoa.h deleted file mode 100644 index ee6a9e5..0000000 --- a/gdtoa/gdtoa.h +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************** - -The author of this software is David M. Gay. - -Copyright (C) 1998 by Lucent Technologies -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 the copyright notice and this -permission notice and warranty disclaimer appear in supporting -documentation, and that the name of Lucent or any of its entities -not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES 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. - -****************************************************************/ - -/* Please send bug reports to David M. Gay (dmg at acm dot org, - * with " at " changed at "@" and " dot " changed to "."). */ - -#ifndef GDTOA_H_INCLUDED -#define GDTOA_H_INCLUDED - -#include "arith.h" - -#ifndef Long -#define Long long -#endif -#ifndef ULong -typedef unsigned Long ULong; -#endif -#ifndef UShort -typedef unsigned short UShort; -#endif - -#ifndef ANSI -#ifdef KR_headers -#define ANSI(x) () -#define Void /*nothing*/ -#else -#define ANSI(x) x -#define Void void -#endif -#endif /* ANSI */ - -#ifndef CONST -#ifdef KR_headers -#define CONST /* blank */ -#else -#define CONST const -#endif -#endif /* CONST */ - - enum { /* return values from strtodg */ - STRTOG_Zero = 0, - STRTOG_Normal = 1, - STRTOG_Denormal = 2, - STRTOG_Infinite = 3, - STRTOG_NaN = 4, - STRTOG_NaNbits = 5, - STRTOG_NoNumber = 6, - STRTOG_Retmask = 7, - - /* The following may be or-ed into one of the above values. */ - - STRTOG_Neg = 0x08, - STRTOG_Inexlo = 0x10, - STRTOG_Inexhi = 0x20, - STRTOG_Inexact = 0x30, - STRTOG_Underflow= 0x40, - STRTOG_Overflow = 0x80 - }; - - typedef struct -FPI { - int nbits; - int emin; - int emax; - int rounding; - int sudden_underflow; - } FPI; - -enum { /* FPI.rounding values: same as FLT_ROUNDS */ - FPI_Round_zero = 0, - FPI_Round_near = 1, - FPI_Round_up = 2, - FPI_Round_down = 3 - }; - -#ifdef __cplusplus -extern "C" { -#endif - -extern char* dtoa ANSI((double d, int mode, int ndigits, int *decpt, - int *sign, char **rve)); -extern char* gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp, - int mode, int ndigits, int *decpt, char **rve)); -extern void freedtoa ANSI((char*)); -extern float strtof ANSI((CONST char *, char **)); -extern double strtod ANSI((CONST char *, char **)); -extern int strtodg ANSI((CONST char*, char**, FPI*, Long*, ULong*)); - -extern char* g_ddfmt ANSI((char*, double*, int, unsigned)); -extern char* g_dfmt ANSI((char*, double*, int, unsigned)); -extern char* g_ffmt ANSI((char*, float*, int, unsigned)); -extern char* g_Qfmt ANSI((char*, void*, int, unsigned)); -extern char* g_xfmt ANSI((char*, void*, int, unsigned)); -extern char* g_xLfmt ANSI((char*, void*, int, unsigned)); - -extern int strtoId ANSI((CONST char*, char**, double*, double*)); -extern int strtoIdd ANSI((CONST char*, char**, double*, double*)); -extern int strtoIf ANSI((CONST char*, char**, float*, float*)); -extern int strtoIQ ANSI((CONST char*, char**, void*, void*)); -extern int strtoIx ANSI((CONST char*, char**, void*, void*)); -extern int strtoIxL ANSI((CONST char*, char**, void*, void*)); -extern int strtord ANSI((CONST char*, char**, int, double*)); -extern int strtordd ANSI((CONST char*, char**, int, double*)); -extern int strtorf ANSI((CONST char*, char**, int, float*)); -extern int strtorQ ANSI((CONST char*, char**, int, void*)); -extern int strtorx ANSI((CONST char*, char**, int, void*)); -extern int strtorxL ANSI((CONST char*, char**, int, void*)); -#if 1 -extern int strtodI ANSI((CONST char*, char**, double*)); -extern int strtopd ANSI((CONST char*, char**, double*)); -extern int strtopdd ANSI((CONST char*, char**, double*)); -extern int strtopf ANSI((CONST char*, char**, float*)); -extern int strtopQ ANSI((CONST char*, char**, void*)); -extern int strtopx ANSI((CONST char*, char**, void*)); -extern int strtopxL ANSI((CONST char*, char**, void*)); -#else -#define strtopd(s,se,x) strtord(s,se,1,x) -#define strtopdd(s,se,x) strtordd(s,se,1,x) -#define strtopf(s,se,x) strtorf(s,se,1,x) -#define strtopQ(s,se,x) strtorQ(s,se,1,x) -#define strtopx(s,se,x) strtorx(s,se,1,x) -#define strtopxL(s,se,x) strtorxL(s,se,1,x) -#endif - -#ifdef __cplusplus -} -#endif -#endif /* GDTOA_H_INCLUDED */ diff --git a/gdtoa/gdtoa.h b/gdtoa/gdtoa.h new file mode 120000 index 0000000..b9a0344 --- /dev/null +++ b/gdtoa/gdtoa.h @@ -0,0 +1 @@ +./gdtoa.h \ No newline at end of file diff --git a/gdtoa/gdtoaimp.h b/gdtoa/gdtoaimp.h index c98a956..6f9d1dd 100644 --- a/gdtoa/gdtoaimp.h +++ b/gdtoa/gdtoaimp.h @@ -240,10 +240,6 @@ extern Char *MALLOC ANSI((size_t)); #else /* ifndef Bad_float_h */ #include "float.h" -/* force the correct definition of FLT_ROUNDS */ -extern int __fegetfltrounds( void ); -#undef FLT_ROUNDS -#define FLT_ROUNDS (__fegetfltrounds ()) #endif /* Bad_float_h */ #ifdef IEEE_Arith diff --git a/gdtoa/glue-fbsd.c b/gdtoa/glue-fbsd.c deleted file mode 100644 index 0db1914..0000000 --- a/gdtoa/glue-fbsd.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Machine-independent glue to integrate David Gay's gdtoa - * package into libc. - * - * $FreeBSD: src/lib/libc/gdtoa/glue.c,v 1.1 2003/03/12 20:29:58 das Exp $ - */ - -#include "spinlock.h" - -spinlock_t __gdtoa_locks[2]; diff --git a/gdtoa/glue-fbsd.c b/gdtoa/glue-fbsd.c new file mode 120000 index 0000000..1f7982a --- /dev/null +++ b/gdtoa/glue-fbsd.c @@ -0,0 +1 @@ +./glue.c \ No newline at end of file diff --git a/gdtoa/machdep_ldisd-fbsd.c b/gdtoa/machdep_ldisd-fbsd.c new file mode 100644 index 0000000..f674ebc --- /dev/null +++ b/gdtoa/machdep_ldisd-fbsd.c @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 2003 David Schultz + * 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. + */ + +/* + * Machine-dependent glue to integrate David Gay's gdtoa + * package into libc for architectures where a long double + * is the same as a double, such as the Alpha. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gdtoa/machdep_ldisd.c,v 1.1 2003/03/12 20:29:58 das Exp $"); + +#include "gdtoaimp.h" + +long double +strtold(const char * __restrict s, char ** __restrict sp) +{ + + return strtod(s, sp); +} + +long double +strtold_l(const char * __restrict s, char ** __restrict sp, locale_t loc) +{ + + return strtod_l(s, sp, loc); +} + diff --git a/gen/FreeBSD/getmntinfo.3.patch b/gen/FreeBSD/getmntinfo.3.patch index f0e51e1..5c10700 100644 --- a/gen/FreeBSD/getmntinfo.3.patch +++ b/gen/FreeBSD/getmntinfo.3.patch @@ -1,11 +1,13 @@ ---- getmntinfo.3.orig 2007-01-21 11:53:36.000000000 -0800 -+++ getmntinfo.3 2007-01-21 17:19:17.000000000 -0800 -@@ -46,14 +46,22 @@ +--- getmntinfo.3.orig 2008-04-28 16:25:33.000000000 -0700 ++++ getmntinfo.3 2008-04-30 04:01:45.000000000 -0700 +@@ -46,14 +46,26 @@ .In sys/mount.h .Ft int .Fn getmntinfo "struct statfs **mntbufp" "int flags" ++#ifdef UNIFDEF_LEGACY_64_APIS +.Ft int +.Fn getmntinfo64 "struct statfs64 **mntbufp" "int flags" ++#endif /* UNIFDEF_LEGACY_64_APIS */ .Sh DESCRIPTION The .Fn getmntinfo @@ -15,20 +17,22 @@ +.Ft statfs structures describing each currently mounted file system (see .Xr statfs 2 ) . ++#ifdef UNIFDEF_LEGACY_64_APIS +Likewise, the +.Fn getmntinfo64 +function +returns an array of +.Ft statfs64 +structures describing each currently mounted file system. ++#endif /* UNIFDEF_LEGACY_64_APIS */ .Pp The .Fn getmntinfo -@@ -61,11 +69,20 @@ +@@ -61,11 +73,28 @@ passes its .Fa flags argument transparently to --.Xr getfsstat 2 . ++#ifdef UNIFDEF_LEGACY_64_APIS +.Xr getfsstat 2 , +while the +.Fn getmntinfo64 @@ -37,53 +41,72 @@ +.Fa flags +argument transparently to +.Fn getfsstat64 . ++#else /* !UNIFDEF_LEGACY_64_APIS */ + .Xr getfsstat 2 . ++#endif /* UNIFDEF_LEGACY_64_APIS */ .Sh RETURN VALUES On successful completion, .Fn getmntinfo --returns a count of the number of elements in the array. ++#ifdef UNIFDEF_LEGACY_64_APIS +and +.Fn getmntinfo64 +return a count of the number of elements in the array. ++#else /* !UNIFDEF_LEGACY_64_APIS */ + returns a count of the number of elements in the array. ++#endif /* UNIFDEF_LEGACY_64_APIS */ The pointer to the array is stored into .Fa mntbufp . .Pp -@@ -76,11 +93,15 @@ +@@ -76,11 +105,21 @@ .Fa mntbufp will be unmodified, any information previously returned by .Fn getmntinfo ++#ifdef UNIFDEF_LEGACY_64_APIS +or +.Fn getmntinfo64 ++#endif /* UNIFDEF_LEGACY_64_APIS */ will be lost. .Sh ERRORS The .Fn getmntinfo --function ++#ifdef UNIFDEF_LEGACY_64_APIS +and +.Fn getmntinfo64 +functions ++#else /* !UNIFDEF_LEGACY_64_APIS */ + function ++#endif /* UNIFDEF_LEGACY_64_APIS */ may fail and set errno for any of the errors specified for the library routines .Xr getfsstat 2 -@@ -99,15 +120,21 @@ +@@ -99,15 +138,29 @@ .Sh BUGS The .Fn getmntinfo -function writes the array of structures to an internal static object ++#ifdef UNIFDEF_LEGACY_64_APIS +and +.Fn getmntinfo64 +functions write the array of structures to an internal static object ++#else /* !UNIFDEF_LEGACY_64_APIS */ ++function write the array of structures to an internal static object ++#endif /* UNIFDEF_LEGACY_64_APIS */ and returns a pointer to that object. Subsequent calls to .Fn getmntinfo ++#ifdef UNIFDEF_LEGACY_64_APIS +and +.Fn getmntinfo64 ++#endif /* UNIFDEF_LEGACY_64_APIS */ will modify the same object. .Pp The memory allocated by .Fn getmntinfo ++#ifdef UNIFDEF_LEGACY_64_APIS +and +.Fn getmntinfo64 ++#endif /* UNIFDEF_LEGACY_64_APIS */ cannot be .Xr free 3 Ns 'd by the application. diff --git a/gen/FreeBSD/glob.c.patch b/gen/FreeBSD/glob.c.patch index 904b155..cd9a66a 100644 --- a/gen/FreeBSD/glob.c.patch +++ b/gen/FreeBSD/glob.c.patch @@ -1,6 +1,6 @@ ---- glob.c.orig 2004-11-25 11:38:01.000000000 -0800 -+++ glob.c 2006-07-04 12:47:05.000000000 -0700 -@@ -40,6 +40,8 @@ +--- glob.c.orig 2008-03-15 10:50:43.000000000 -0700 ++++ glob.c 2008-03-27 03:28:31.000000000 -0700 +@@ -40,6 +40,8 @@ static char sccsid[] = "@(#)glob.c 8.3 ( #include __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.22 2004/07/29 03:48:52 tjr Exp $"); @@ -9,37 +9,32 @@ /* * glob(3) -- a superset of the one defined in POSIX 1003.2. * -@@ -142,29 +144,42 @@ - #define M_SET META('[') +@@ -143,25 +145,33 @@ typedef char Char; #define ismeta(c) (((c)&M_QUOTE) != 0) -+static int g_lstat(Char *, struct stat *, glob_t *, locale_t); -+static int g_stat(Char *, struct stat *, glob_t *, locale_t); -+ + +-static int compare(const void *, const void *); +-static int g_Ctoc(const Char *, char *, u_int); +-static int g_lstat(Char *, struct stat *, glob_t *); +-static DIR *g_opendir(Char *, glob_t *); +-static Char *g_strchr(Char *, wchar_t); ++#define compare __gl_compare +#define g_Ctoc __gl_g_Ctoc -+#define glob0 __gl_glob0 -+#define glob2_32 __gl_glob0_32 -+#define glob2_64 __gl_glob0_64 -+#define glob3 __gl_glob3 -+#define globexp1 __gl_globexp1 ++#define g_strchr __gl_g_strchr +#define globextend __gl_globextend ++#define globtilde __gl_globtilde ++#define match __gl_match ++__private_extern__ int compare(const void *, const void *); +__private_extern__ int g_Ctoc(const Char *, char *, u_int, locale_t); -+__private_extern__ int glob0(const Char *, glob_t *, int *, locale_t); -+__private_extern__ int glob2_32(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t); -+__private_extern__ int glob2_64(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t); -+__private_extern__ int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *, locale_t); -+__private_extern__ int globexp1(const Char *, glob_t *, int *, locale_t); ++__private_extern__ Char *g_strchr(Char *, wchar_t); +__private_extern__ int globextend(const Char *, glob_t *, int *, locale_t); ++__private_extern__ const Char * ++ globtilde(const Char *, Char *, size_t, glob_t *); ++__private_extern__ int match(Char *, Char *, Char *, locale_t); + -+#ifndef BUILDING_VARIANT -+#define glob2(a,b,c,d,e,f,g) (((e)->gl_flags & GLOB_INODE64) ? glob2_64((a),(b),(c),(d),(e),(f),(g)) : glob2_32((a),(b),(c),(d),(e),(f),(g))) - - static int compare(const void *, const void *); --static int g_Ctoc(const Char *, char *, u_int); --static int g_lstat(Char *, struct stat *, glob_t *); --static DIR *g_opendir(Char *, glob_t *); ++ ++static int g_lstat(Char *, struct stat *, glob_t *, locale_t); +static DIR *g_opendir(Char *, glob_t *, locale_t); - static Char *g_strchr(Char *, wchar_t); #ifdef notdef static Char *g_strcat(Char *, const Char *); #endif @@ -49,22 +44,22 @@ -static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *); -static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *); -static int globextend(const Char *, glob_t *, int *); -+static int glob1(Char *, glob_t *, int *, locale_t); - static const Char * - globtilde(const Char *, Char *, size_t, glob_t *); +-static const Char * +- globtilde(const Char *, Char *, size_t, glob_t *); -static int globexp1(const Char *, glob_t *, int *); -static int globexp2(const Char *, const Char *, glob_t *, int *, int *); -static int match(Char *, Char *, Char *); ++static int g_stat(Char *, struct stat *, glob_t *, locale_t); ++static int glob0(const Char *, glob_t *, int *, locale_t); ++static int glob1(Char *, glob_t *, int *, locale_t); ++static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t); ++static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *, locale_t); ++static int globexp1(const Char *, glob_t *, int *, locale_t); +static int globexp2(const Char *, const Char *, glob_t *, int *, int *, locale_t); -+static int match(Char *, Char *, Char *, locale_t); #ifdef DEBUG static void qprintf(const char *, Char *); #endif -+#endif /* !BUILDING_VARIANT */ - - int - glob(pattern, flags, errfunc, pglob) -@@ -178,6 +193,8 @@ +@@ -178,6 +188,8 @@ glob(pattern, flags, errfunc, pglob) mbstate_t mbs; wchar_t wc; size_t clen; @@ -73,20 +68,7 @@ patnext = (u_char *) pattern; if (!(flags & GLOB_APPEND)) { -@@ -192,7 +209,12 @@ - limit = ARG_MAX; - } else - limit = 0; -+#if __DARWIN_64_BIT_INO_T - pglob->gl_flags = flags & ~GLOB_MAGCHAR; -+ pglob->gl_flags |= GLOB_INODE64; -+#else /* !__DARWIN_64_BIT_INO_T */ -+ pglob->gl_flags = flags & ~(GLOB_MAGCHAR | GLOB_INODE64); -+#endif /* __DARWIN_64_BIT_INO_T */ - pglob->gl_errfunc = errfunc; - pglob->gl_matchc = 0; - -@@ -200,8 +222,8 @@ +@@ -200,8 +212,8 @@ glob(pattern, flags, errfunc, pglob) bufend = bufnext + MAXPATHLEN - 1; if (flags & GLOB_NOESCAPE) { memset(&mbs, 0, sizeof(mbs)); @@ -97,7 +79,7 @@ if (clen == (size_t)-1 || clen == (size_t)-2) return (GLOB_NOMATCH); else if (clen == 0) -@@ -212,7 +234,7 @@ +@@ -212,7 +224,7 @@ glob(pattern, flags, errfunc, pglob) } else { /* Protect the quoted characters. */ memset(&mbs, 0, sizeof(mbs)); @@ -106,7 +88,7 @@ if (*patnext == QUOTE) { if (*++patnext == EOS) { *bufnext++ = QUOTE | M_PROTECT; -@@ -221,7 +243,7 @@ +@@ -221,7 +233,7 @@ glob(pattern, flags, errfunc, pglob) prot = M_PROTECT; } else prot = 0; @@ -115,7 +97,7 @@ if (clen == (size_t)-1 || clen == (size_t)-2) return (GLOB_NOMATCH); else if (clen == 0) -@@ -233,34 +255,36 @@ +@@ -233,9 +245,9 @@ glob(pattern, flags, errfunc, pglob) *bufnext = EOS; if (flags & GLOB_BRACE) @@ -126,15 +108,12 @@ + return glob0(patbuf, pglob, &limit, loc); } -+#ifndef BUILDING_VARIANT /* - * Expand recursively a glob {} pattern. When there is no more expansion - * invoke the standard globbing routine to glob the rest of the magic +@@ -244,23 +256,24 @@ glob(pattern, flags, errfunc, pglob) * characters */ --static int + static int -globexp1(pattern, pglob, limit) -+__private_extern__ int +globexp1(pattern, pglob, limit, loc) const Char *pattern; glob_t *pglob; @@ -159,7 +138,7 @@ } -@@ -270,10 +294,11 @@ +@@ -270,10 +283,11 @@ globexp1(pattern, pglob, limit) * If it fails then it tries to glob the rest of the pattern and returns. */ static int @@ -172,7 +151,7 @@ { int i; Char *lm, *ls; -@@ -310,7 +335,7 @@ +@@ -310,7 +324,7 @@ globexp2(ptr, pattern, pglob, rv, limit) /* Non matching braces; just glob the pattern */ if (i != 0 || *pe == EOS) { @@ -181,7 +160,7 @@ return 0; } -@@ -357,7 +382,7 @@ +@@ -357,7 +371,7 @@ globexp2(ptr, pattern, pglob, rv, limit) #ifdef DEBUG qprintf("globexp2:", patbuf); #endif @@ -190,13 +169,32 @@ /* move after the comma, to the next string */ pl = pm + 1; -@@ -446,14 +471,16 @@ - * sorts the list (unless unsorted operation is requested). Returns 0 +@@ -373,10 +387,11 @@ globexp2(ptr, pattern, pglob, rv, limit) + + + ++#ifndef BUILDING_VARIANT + /* + * expand tilde from the passwd file. + */ +-static const Char * ++__private_extern__ const Char * + globtilde(pattern, patbuf, patbuf_len, pglob) + const Char *pattern; + Char *patbuf; +@@ -438,6 +453,7 @@ globtilde(pattern, patbuf, patbuf_len, p + + return patbuf; + } ++#endif /* BUILDING_VARIANT */ + + + /* +@@ -447,13 +463,15 @@ globtilde(pattern, patbuf, patbuf_len, p * if things went well, nonzero if errors occurred. */ --static int + static int -glob0(pattern, pglob, limit) -+__private_extern__ int +glob0(pattern, pglob, limit, loc) const Char *pattern; glob_t *pglob; @@ -210,7 +208,7 @@ Char *bufnext, patbuf[MAXPATHLEN]; qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob); -@@ -462,6 +489,10 @@ +@@ -462,6 +480,10 @@ glob0(pattern, pglob, limit) /* We don't need to check for buffer overflow any more. */ while ((c = *qpatnext++) != EOS) { @@ -221,7 +219,7 @@ switch (c) { case LBRACKET: c = *qpatnext; -@@ -512,7 +543,7 @@ +@@ -512,7 +534,7 @@ glob0(pattern, pglob, limit) qprintf("glob0:", patbuf); #endif @@ -230,7 +228,7 @@ return(err); /* -@@ -525,7 +556,7 @@ +@@ -525,7 +547,7 @@ glob0(pattern, pglob, limit) if (((pglob->gl_flags & GLOB_NOCHECK) || ((pglob->gl_flags & GLOB_NOMAGIC) && !(pglob->gl_flags & GLOB_MAGCHAR)))) @@ -239,13 +237,20 @@ else return(GLOB_NOMATCH); } -@@ -539,14 +570,15 @@ +@@ -535,18 +557,21 @@ glob0(pattern, pglob, limit) + return(0); + } + +-static int ++#ifndef BUILDING_VARIANT ++__private_extern__ int compare(p, q) const void *p, *q; { - return(strcmp(*(char **)p, *(char **)q)); + return(strcoll(*(char **)p, *(char **)q)); } ++#endif /* BUILDING_VARIANT */ static int -glob1(pattern, pglob, limit) @@ -257,28 +262,21 @@ { Char pathbuf[MAXPATHLEN]; -@@ -554,19 +586,25 @@ +@@ -554,7 +579,7 @@ glob1(pattern, pglob, limit) if (*pattern == EOS) return(0); return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1, - pattern, pglob, limit)); + pattern, pglob, limit, loc)); } -+#endif /* !BUILDING_VARIANT */ /* - * The functions glob2 and glob3 are mutually recursive; there is one level - * of recursion for each segment in the pattern that contains one or more +@@ -563,10 +588,11 @@ glob1(pattern, pglob, limit) * meta characters. */ --static int + static int -glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit) -+__private_extern__ int -+#if __DARWIN_64_BIT_INO_T -+glob2_64(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc) -+#else /* !__DARWIN_64_BIT_INO_T */ -+glob2_32(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc) -+#endif /* __DARWIN_64_BIT_INO_T */ ++glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc) Char *pathbuf, *pathend, *pathend_last, *pattern; glob_t *pglob; int *limit; @@ -286,7 +284,7 @@ { struct stat sb; Char *p, *q; -@@ -579,13 +617,13 @@ +@@ -579,13 +605,13 @@ glob2(pathbuf, pathend, pathend_last, pa for (anymeta = 0;;) { if (*pattern == EOS) { /* End of pattern? */ *pathend = EOS; @@ -302,7 +300,7 @@ S_ISDIR(sb.st_mode)))) { if (pathend + 1 > pathend_last) return (GLOB_ABORTED); -@@ -593,7 +631,7 @@ +@@ -593,7 +619,7 @@ glob2(pathbuf, pathend, pathend_last, pa *pathend = EOS; } ++pglob->gl_matchc; @@ -311,7 +309,7 @@ } /* Find end of next segment, copy tentatively to pathend. */ -@@ -617,16 +655,18 @@ +@@ -617,16 +643,17 @@ glob2(pathbuf, pathend, pathend_last, pa } } else /* Need expansion, recurse. */ return(glob3(pathbuf, pathend, pathend_last, pattern, p, @@ -321,10 +319,8 @@ /* NOTREACHED */ } --static int + static int -glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit) -+#ifndef BUILDING_VARIANT -+__private_extern__ int +glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit, loc) Char *pathbuf, *pathend, *pathend_last, *pattern, *restpattern; glob_t *pglob; @@ -333,7 +329,7 @@ { struct dirent *dp; DIR *dirp; -@@ -646,15 +686,16 @@ +@@ -646,15 +673,16 @@ glob3(pathbuf, pathend, pathend_last, pa *pathend = EOS; errno = 0; @@ -354,7 +350,7 @@ return(0); } -@@ -679,7 +720,7 @@ +@@ -679,7 +707,7 @@ glob3(pathbuf, pathend, pathend_last, pa dc = pathend; sc = (u_char *) dp->d_name; while (dc < pathend_last) { @@ -363,7 +359,7 @@ if (clen == (size_t)-1 || clen == (size_t)-2) { wc = *sc; clen = 1; -@@ -689,12 +730,12 @@ +@@ -689,12 +717,12 @@ glob3(pathbuf, pathend, pathend_last, pa break; sc += clen; } @@ -378,7 +374,15 @@ if (err) break; } -@@ -721,11 +762,12 @@ +@@ -707,6 +735,7 @@ glob3(pathbuf, pathend, pathend_last, pa + } + + ++#ifndef BUILDING_VARIANT + /* + * Extend the gl_pathv member of a glob_t structure to accomodate a new item, + * add the new item, and update gl_pathc. +@@ -721,11 +750,12 @@ glob3(pathbuf, pathend, pathend_last, pa * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and * gl_pathv points to (gl_offs + gl_pathc + 1) items. */ @@ -393,7 +397,7 @@ { char **pathv; int i; -@@ -760,9 +802,9 @@ +@@ -760,9 +790,9 @@ globextend(path, pglob, limit) for (p = path; *p++;) continue; @@ -405,18 +409,20 @@ free(copy); return (GLOB_NOSPACE); } -@@ -777,8 +819,9 @@ +@@ -776,9 +806,10 @@ globextend(path, pglob, limit) + * pattern matching function for filenames. Each occurrence of the * * pattern causes a recursion level. */ - static int +-static int -match(name, pat, patend) ++__private_extern__ int +match(name, pat, patend, loc) Char *name, *pat, *patend; + locale_t loc; { int ok, negate_range; Char c, k; -@@ -790,7 +833,7 @@ +@@ -790,7 +821,7 @@ match(name, pat, patend) if (pat == patend) return(1); do @@ -425,7 +431,7 @@ return(1); while (*name++ != EOS); return(0); -@@ -806,10 +849,10 @@ +@@ -806,10 +837,10 @@ match(name, pat, patend) ++pat; while (((c = *pat++) & M_MASK) != M_END) if ((*pat & M_MASK) == M_RNG) { @@ -439,8 +445,11 @@ ) ok = 1; pat += 2; -@@ -846,16 +889,17 @@ +@@ -844,18 +875,20 @@ globfree(pglob) + pglob->gl_pathv = NULL; + } } ++#endif /* !BUILDING_VARIANT */ static DIR * -g_opendir(str, pglob) @@ -459,11 +468,8 @@ return (NULL); } -@@ -864,16 +908,18 @@ - - return(opendir(buf)); +@@ -866,14 +899,15 @@ g_opendir(str, pglob) } -+#endif /* !BUILDING_VARIANT */ static int -g_lstat(fn, sb, pglob) @@ -480,7 +486,7 @@ errno = ENAMETOOLONG; return (-1); } -@@ -883,14 +929,15 @@ +@@ -883,14 +917,15 @@ g_lstat(fn, sb, pglob) } static int @@ -498,15 +504,17 @@ errno = ENAMETOOLONG; return (-1); } -@@ -899,6 +946,7 @@ +@@ -899,7 +934,8 @@ g_stat(fn, sb, pglob) return(stat(buf, sb)); } +-static Char * +#ifndef BUILDING_VARIANT - static Char * ++__private_extern__ Char * g_strchr(str, ch) Char *str; -@@ -911,18 +959,20 @@ + wchar_t ch; +@@ -911,18 +947,20 @@ g_strchr(str, ch) return (NULL); } @@ -531,7 +539,7 @@ if (clen == (size_t)-1) return (1); if (*str == L'\0') -@@ -954,3 +1004,4 @@ +@@ -954,3 +992,4 @@ qprintf(str, s) (void)printf("\n"); } #endif diff --git a/gen/FreeBSD/time.c.patch b/gen/FreeBSD/time.c.patch index 6433f6f..df72dfe 100644 --- a/gen/FreeBSD/time.c.patch +++ b/gen/FreeBSD/time.c.patch @@ -1,6 +1,6 @@ ---- time.c.orig 2004-11-25 11:38:01.000000000 -0800 -+++ time.c 2005-03-24 14:09:30.000000000 -0800 -@@ -39,6 +39,7 @@ +--- time.c.orig 2008-07-30 13:29:30.000000000 -0700 ++++ time.c 2008-07-30 13:36:03.000000000 -0700 +@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/tim #include #include @@ -8,19 +8,25 @@ time_t time(t) -@@ -46,12 +47,15 @@ +@@ -46,12 +47,21 @@ time(t) { struct timeval tt; time_t retval; ++#ifdef FE_DFL_ENV + fenv_t fenv; ++#endif /* FE_DFL_ENV */ ++#ifdef FE_DFL_ENV + fegetenv(&fenv); /* 3965505 - need to preserve floating point enviroment */ ++#endif /* FE_DFL_ENV */ if (gettimeofday(&tt, (struct timezone *)0) < 0) retval = -1; else retval = tt.tv_sec; if (t != NULL) *t = retval; ++#ifdef FE_DFL_ENV + fesetenv(&fenv); ++#endif /* FE_DFL_ENV */ return (retval); } diff --git a/gen/Makefile.inc b/gen/Makefile.inc index cfa4911..a9297c4 100644 --- a/gen/Makefile.inc +++ b/gen/Makefile.inc @@ -1,15 +1,12 @@ # @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # $FreeBSD: src/lib/libc/gen/Makefile.inc,v 1.80 2001/08/17 22:09:15 dd Exp $ -.ifnmake autopatch # machine-dependent gen sources -.if exists(${.CURDIR}/${MACHINE_ARCH}/gen/Makefile.inc) -.include "${.CURDIR}/${MACHINE_ARCH}/gen/Makefile.inc" -.endif -.endif # !autopatch +.sinclude "${.CURDIR}/${MACHINE_ARCH}/gen/Makefile.inc" # machine-independent gen sources .PATH: ${.CURDIR}/gen +CWD := ${.CURDIR}/gen CFLAGS += -I${.CURDIR}/gen @@ -18,7 +15,7 @@ GENMIGHDRS += ${GENMIGDEFS:.defs=.h} GENMIGSRCS += ${GENMIGDEFS:.defs=User.c} MISRCS += ${GENMIGSRCS} NSSystemDirectories.c OSSystemInfo.c \ - asl.c asl_util.c \ + asl.c asl_core.c asl_file.c asl_legacy1.c asl_store.c asl_util.c \ backtrace.c \ cache.c confstr.c crypt.c devname.c disklabel.c errlst.c \ filesec.c fts.c \ @@ -26,16 +23,21 @@ MISRCS += ${GENMIGSRCS} NSSystemDirectories.c OSSystemInfo.c \ isinf.c isnan.c \ malloc.c nanosleep.c nftw.c nlist.c scalable_malloc.c setlogin.c \ sigsetops.c _simple.c stack_logging.c stack_logging_disk.c strtofflags.c syslog.c \ - thread_stack_pcs.c uname.c utmpx-darwin.c wordexp.c zone.c + thread_stack_pcs.c uname.c utmpx-darwin.c wordexp.c + +.ifdef FEATURE_LEGACY_NXZONE_APIS +MISRCS += zone.c +.endif # Force these files to build after the mig stuff -asl.So asl.po asl.do asl.o: asl_ipcUser.c -utmpx-darwin.So utmpx-darwin.po utmpx-darwin.do utmpx-darwin.o: asl_ipcUser.c +asl.${OBJSUFFIX}: asl_ipcUser.c +utmpx-darwin.${OBJSUFFIX}: asl_ipcUser.c CLEANFILES += ${GENMIGHDRS} ${GENMIGSRCS} ${GENMIGDEFS:.defs=Server.c} -PRECFLAGS-asl.c = -I${OBJROOT} -LOCALHDRS += ${.CURDIR}/gen/asl_private.h ${.CURDIR}/gen/_simple.h ${.CURDIR}/gen/stack_logging.h +LOCALHDRS += ${.CURDIR}/gen/asl_core.h ${.CURDIR}/gen/asl_file.h ${.CURDIR}/gen/asl_legacy1.h \ + ${.CURDIR}/gen/asl_private.h ${.CURDIR}/gen/asl_store.h \ + ${.CURDIR}/gen/_simple.h ${.CURDIR}/gen/stack_logging.h CFLAGS-confstr.c += -I${.CURDIR}/darwin @@ -46,6 +48,11 @@ CFLAGS-glob-fbsd.c += -UDEBUG CFLAGS-scalable_malloc.c += -funit-at-a-time .endif +# Malloc uses count leading zeroes, not available in thumb +.if (${MACHINE_ARCH} == arm) +CFLAGS-scalable_malloc.c += -mno-thumb +.endif + # also build 64-bit long double versions (ppc only) LDBLSRCS += asl.c err.c syslog.c @@ -66,23 +73,32 @@ FBSDMISRCS = _rand48.c alarm.c arc4random.c assert.c \ ttyname.c ttyslot.c ualarm.c ulimit.c unvis.c usleep.c utime.c vis.c \ wait.c wait3.c waitpid.c +.ifdef FEATURE_LEGACY_64_APIS # special case: getmntinfo64-fbsd.c is derived from getmntinfo.c with getmntinfo64.c.patch .ifmake autopatch -AUTOPATCHSRCS+= getmntinfo64-fbsd.c -getmntinfo64-fbsd.c: FreeBSD/getmntinfo.c + +# This .for statement forces evaluation of ${CWD} +.for _cwd in ${CWD} +AUTOPATCHSRCS+= ${_cwd}/getmntinfo64-fbsd.c +${_cwd}/getmntinfo64-fbsd.c: ${_cwd}/FreeBSD/getmntinfo.c cp ${.ALLSRC} ${.TARGET} patch ${.TARGET} ${.ALLSRC:S/getmntinfo/getmntinfo64/}.patch +.endfor # _cwd + .else # !autopatch MISRCS+= getmntinfo64.c .endif # autopatch +.endif # FEATURE_LEGACY_64_APIS PRE1050SRCS+= daemon.c -.ifdef LP64 +.if defined(LP64) PRE1050SRCS+= pselect.c -.else # !LP64 +.endif +.ifndef FEATURE_ONLY_UNIX_CONFORMANCE # only patch timezone.c; don't build in base variant, but in other variants FBSDPATCHSRCS += timezone.c .endif + FBSDHDRS = rand48.h telldir.h .include "Makefile.fbsd_end" @@ -139,6 +155,7 @@ CFLAGS-nice-fbsd.c += -DLIBC_ALIAS_NICE CFLAGS-opendir-fbsd.c += -DLIBC_ALIAS___OPENDIR2 -DLIBC_ALIAS_OPENDIR CFLAGS-rewinddir-fbsd.c += -DLIBC_ALIAS_REWINDDIR CFLAGS-pause-fbsd.c += -DLIBC_ALIAS_PAUSE +CFLAGS-pselect-fbsd.c += -DLIBC_ALIAS_PSELECT CFLAGS-seekdir-fbsd.c += -DLIBC_ALIAS_SEEKDIR CFLAGS-sleep-fbsd.c += -DLIBC_ALIAS_SLEEP CFLAGS-telldir-fbsd.c += -DLIBC_ALIAS__SEEKDIR -DLIBC_ALIAS_TELLDIR diff --git a/gen/NetBSD/utmpx.c.patch b/gen/NetBSD/utmpx.c.patch index b4816c9..33e2a4b 100644 --- a/gen/NetBSD/utmpx.c.patch +++ b/gen/NetBSD/utmpx.c.patch @@ -1,6 +1,6 @@ ---- utmpx.c.orig 2006-02-06 00:43:57.000000000 -0800 -+++ utmpx.c 2006-02-06 00:51:52.000000000 -0800 -@@ -49,34 +49,27 @@ +--- utmpx.c.orig 2008-07-17 11:34:16.000000000 -0700 ++++ utmpx.c 2008-07-17 12:05:58.000000000 -0700 +@@ -49,34 +49,29 @@ __RCSID("$NetBSD: utmpx.c,v 1.21 2003/09 #include #include @@ -12,9 +12,11 @@ #include #include #include ++#ifdef LEGACY_UTMP_APIS #include -/* don't define earlier, has side effects in fcntl.h */ -#define __LIBC12_SOURCE__ ++#endif /* LEGACY_UTMP_APIS */ #include +#include +#include @@ -41,7 +43,7 @@ void setutxent() -@@ -85,7 +78,11 @@ +@@ -85,7 +80,11 @@ setutxent() (void)memset(&ut, 0, sizeof(ut)); if (fp == NULL) return; @@ -53,7 +55,7 @@ } -@@ -105,6 +102,9 @@ +@@ -105,6 +104,9 @@ endutxent() struct utmpx * getutxent() { @@ -63,7 +65,7 @@ if (fp == NULL) { struct stat st; -@@ -124,42 +124,80 @@ +@@ -124,42 +126,80 @@ getutxent() if (st.st_size == 0) { /* new file, add signature record */ @@ -147,7 +149,7 @@ do { if (ut.ut_type == EMPTY) continue; -@@ -225,30 +263,68 @@ +@@ -225,30 +265,68 @@ getutxline(const struct utmpx *utx) struct utmpx * pututxline(const struct utmpx *utx) { @@ -226,7 +228,7 @@ if (lockf(fileno(fp), F_LOCK, (off_t)0) == -1) return NULL; gotlock++; -@@ -258,99 +334,66 @@ +@@ -258,99 +336,66 @@ pututxline(const struct utmpx *utx) } if (!gotlock) { @@ -359,7 +361,7 @@ len = strlen(fname); -@@ -363,6 +406,7 @@ +@@ -363,18 +408,17 @@ utmpxname(const char *fname) (void)strlcpy(utfile, fname, sizeof(utfile)); endutxent(); @@ -367,7 +369,9 @@ return 1; } -@@ -371,10 +415,8 @@ +- ++#ifdef LEGACY_UTMP_APIS + void getutmp(const struct utmpx *ux, struct utmp *u) { @@ -380,7 +384,7 @@ (void)memcpy(u->ut_line, ux->ut_line, sizeof(u->ut_line)); (void)memcpy(u->ut_host, ux->ut_host, sizeof(u->ut_host)); u->ut_time = ux->ut_tv.tv_sec; -@@ -384,109 +426,15 @@ +@@ -384,109 +428,16 @@ void getutmpx(const struct utmp *u, struct utmpx *ux) { @@ -496,3 +500,4 @@ - (db->close)(db); - return error; } ++#endif /* LEGACY_UTMP_APIS */ diff --git a/gen/alarm-fbsd.c b/gen/alarm-fbsd.c deleted file mode 100644 index 58cce20..0000000 --- a/gen/alarm-fbsd.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)alarm.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/alarm.c,v 1.2 2002/02/01 01:08:47 obrien Exp $"); - -/* - * Backwards compatible alarm. - */ -#include -#include - -unsigned int -alarm(secs) - unsigned int secs; -{ - struct itimerval it, oitv; - struct itimerval *itp = ⁢ - - timerclear(&itp->it_interval); - itp->it_value.tv_sec = secs; - itp->it_value.tv_usec = 0; - if (setitimer(ITIMER_REAL, itp, &oitv) < 0) - return (-1); - if (oitv.it_value.tv_usec) - oitv.it_value.tv_sec++; - return (oitv.it_value.tv_sec); -} diff --git a/gen/alarm-fbsd.c b/gen/alarm-fbsd.c new file mode 120000 index 0000000..ca8f1f2 --- /dev/null +++ b/gen/alarm-fbsd.c @@ -0,0 +1 @@ +./alarm.c \ No newline at end of file diff --git a/gen/asl.3 b/gen/asl.3 index 1ebef2b..8db0965 100644 --- a/gen/asl.3 +++ b/gen/asl.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2005-2007 Apple Inc. +.\" Copyright (c) 2005-2008 Apple Inc. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -141,7 +141,7 @@ .Fc .Ft void .Fo aslresponse_free -.Fa "aslresponse a" +.Fa "aslresponse r" .Fc .Ft aslmsg .Fo aslresponse_next @@ -160,11 +160,226 @@ Messages received by the server are saved in a data store (subject to input filtering constraints). This API permits clients to create queries and search the message data store for matching messages. +.Pp +An introduction to the concepts underlying this interface follows the interface summary below. +.Ss INTERFACE SUMMARY +.Fo asl_open +.Fa ident +.Fa facility +.Fa opts +.Fc +creates and returns a client handle, or NULL if an error occurs in the library. +Messages sent using this handle will default to having the string +.Ar ident +as the value assocated with the ASL_KEY_SENDER key, and the value +.Ar facility +assocated with the ASL_KEY_FACILITY key. +Several options are available, as described in the +.Sx CLIENT HANDLES +section. +.Pp +Multi-threaded applications should create one client handle for each thread that logs messages. +A client may use NULL as a client handle, in which case a default handle managed by the library will be used. +A NULL handle may be used safely by multiple threads, but the threads will contend for a single internal lock when +sending log messages using a NULL handle. +.Pp +.Fo asl_close +.Fa asl +.Fc +closes the client handle +.Ar asl +and releases its associated resources. +.Pp +.Fo asl_add_log_file +.Fa asl +.Fa fd +.Fc +adds the file descriptor +.Ar fd +to the a set of file descriptors associated with the client handle +.Ar asl . +Each log message sent by that client handle is also written to these file descriptors. +Returns 0 on success, non-zero on failure. +.Pp +.Fo asl_remove_log_file +.Fa asl +.Fa fd +.Fc +removes a file descriptor from the set of file descriptors associated with a client handle. +Returns 0 on success, non-zero on failure. +.Pp +.Fo asl_new +.Fa type +.Fc +allocates and returns an aslmsg structure, or NULL in the case of a failure in the library. +The +.Ar type +argument must be ASL_TYPE_MSG or ASL_TYPE_QUERY. +.Pp +.Fo asl_free +.Fa msg +.Fc +frees an aslmsg and releases resources associated with the structure. +.Pp +.Fo asl_set +.Fa msg +.Fa key +.Fa value +.Fc +creates a new key and value in an aslmsg structure, or replaces the value of an existing key. +Returns 0 on success, non-zero on failure. +.Pp +.Fo asl_set_query +.Fa msg +.Fa key +.Fa op +.Fa value +.Fc +is used to construct searches. +It is similar to +.Fn asl_set , +except that it takes an additional +.Ar op +(operation) argument. +Creates a new (key, op, value) triple in an aslmsg structure, +or replaces the value and operation for an existing key. +See the +.Sx SEARCHING +section for more information. +Returns 0 on success, non-zero on failure. +.Pp +.Fo asl_unset +.Fa msg +.Fa key +.Fc +removes a key and its associated value from an aslmsg structure. +Returns 0 on success, non-zero on failure. +.Pp +.Fo asl_key +.Fa msg +.Fa n +.Fc +returns the nth key in an aslmsg (beginning at zero), +allowing an application to iterate through the keys. +Returns NULL if +.Ar n +indexes beyond the number of keys in +.Ar msg . +.Pp +.Fo asl_get +.Fa msg +.Fa key +.Fc +returns the value associated with +.Ar key +in the aslmsg +.Ar msg . +Returns NULL if +.Ar msg +does not contain +. Ar key . +.Pp +.Fo asl_set_filter +.Fa asl +.Fa f +.Fc +sets a filter for messages being sent to the server. +The filter is a bitmask representing priority levels. +Only messages having a priority level with a corresponding bit set in the filter mask are sent to the +.Nm syslogd +server. +The filter does not control writes to additional files associated with the client handle using +.Fn asl_add_log_file . +Returns the previous filter value. +.Pp +.Fo asl_log +.Fa asl +.Fa msg +.Fa level +.Fa format +.Fa args... +.Fc +sends a log to the server (subject to filtering, see +.Fn asl_set_filter +above) and to any file descriptors associated with the client handle +.Ar asl . +The +.Ar msg +argument may contain any keys and values, which will be formatted as part of the log message. +The value for ASL_KEY_LEVEL is supplied by the +.Ar level +argument. +The value for ASL_KEY_MESSAGE is computed from +.Ar format +and the associated arguments +.Ar args... . +Normal +.Fn printf +style argument processing is applied to the format and the arguments. +The format may also contain +.Dq %m +which will be substituted with the string value corresponding to the current +.Em errno . +.Pp +.Fo asl_vlog +.Fa asl +.Fa msg +.Fa level +.Fa format +.Fa ap +.Fc +is similar to +.Fn asl_log +except that it takes a va_list argument. +.Pp +.Fo asl_send +.Fa asl +.Fa msg +.Fc +is similar to +.Fn asl_log , +exceopt the value for ASL_KEY_MESSAGE is taken from +.Ar msg +rather than being constructed using a +.Fn printf +style syntax. +.Pp +.Fo asl_search +.Fa asl +.Fa msg +.Fc +searches for messages that match the keys and values in +.Ar msg , +subject to matching operations associated with those keys and values. +The +.Ar msg +argument should be constructed using +.Fn asl_set_query . +See the +.Sx SEARCHING +section for details on constructing queries. +Returns an aslresponse structure that contains matching log messages. +NULL is returned in case of error or if there are no matching messages in the ASL database. +.Pp +.Fo aslresponse_next +.Fa r +.Fc +iterates over an aslresponse structure returned by +.Fn asl_search . +Each call returns the next aslmsg in the response. +Returns NULL when there are no further messages. +.Pp +.Fo aslresponse_free +.Fa r +.Fc +frees the aslresponse structure +.Ar r +and all of its associated resources. .Ss MESSAGES At the core of this API is the aslmsg structure. Although the structure is opaque and may not be directly manipulated, it contains a list of key/value pairs. -All keys and values are NULL-terminated C language character strings. +All keys and values are NUL-character terminated C language strings. UTF-8 encoding may be used for non-ASCII characters. .Pp Message structures are generally used to send log messages, @@ -176,7 +391,7 @@ Another message type, ASL_TYPE_QUERY, is used to create queries when searching the data store. Query type messages and searching are described in detail in the .Sx SEARCHING -section below. +section. For the remainder of this section, the messages described will be of the ASL_TYPE_MSG variety. .Pp @@ -269,10 +484,15 @@ In this example, the aslclient argument is NULL. This is sufficient for a single-threaded application, or for an application which only sends log messages from a single thread. When logging from multiple threads, -each thread must open a separate client handle using +each thread +.Em should +open a separate client handle using .Nm asl_open . The client handle may then be closed when it is no longer required using .Nm asl_close . +Multiple threads may log messages safely using a NULL aslclient argument, +but the library will use an internal lock, so that in fact only one thread +will log at a time. .Pp When an application requires additional keys and values to be associated with each log message, @@ -399,6 +619,17 @@ connects to the server immediately disables remote-control filter adjustment .El .Pp +ASL_OPT_NO_DELAY makes the client library connect to the +.Nm syslogd +server at the time that +.Nm asl_open +is called, rather than waiting for the first message to be sent. +Opening the connection is quite fast, but some applications may want to avoid any unnecessary delays when calling +.Nm asl_log , +.Nm asl_vlog , +or +.Nm asl_send . +.Pp See the FILTERING section below, and the .Xr syslog 1 for additional details on filter controls. @@ -422,9 +653,16 @@ Messages sent to stderr or other files are printed in the "standard" message for also used as a default format by the .Xr syslog 1 command line utility. -The -.Xr strvis 3 -encoding with the VIS_CSTYLE, VIS_TAB, and VIS_NL options is used to print the message. +Non-ASCII characters in a message are encoded using the +.Dq safe +encoding style used by +.Xr syslog 1 +with the +.Fl E Ar safe +option. +Backspace characters are printed as ^H. +Carriage returns are mapped to newlines. +A tab character is appended after newlines so that message text is indented. .Pp File descriptors may be removed from the list of outputs associated with a client handle with @@ -434,24 +672,6 @@ The file is not closed as a result. .Pp The ASL_OPT_STDERR option may not be unset after a client handle has been opened. -.Pp -In the present release of Mac OS X, a -.Dq raw -format is used to format messages -that are sent to file descriptors -that have been added to a client handle. -Each message is preceded by a 10-character field containing a message length. -The message length is padded with leading white space. -The length gives the string length of the remainder of the output string. -Following the length is a space character, and then the message. -The message is encoded as a set of key/value pairs -enclosed in square brackets, -which are themselves separated by a space character. -The key is separated from the value by space character. -Embedded closing square brackets are escaped by a backslash. -Embedded space characters in keys are escaped by a backslash; -Embedded newlines are summarily turned into semicolons. -The output is terminated by a trailing newline and a NUL character. .Ss SEARCHING The .Nm syslogd diff --git a/gen/asl.c b/gen/asl.c index a5d07fc..edd1efb 100644 --- a/gen/asl.c +++ b/gen/asl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2007 Apple Inc. All rights reserved. + * Copyright (c) 2004-2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -32,9 +32,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -70,10 +72,6 @@ #define TFMT_UTC 1 #define TFMT_LCL 2 -#define ENCODE_NONE 0 -#define ENCODE_VIS 1 -#define ENCODE_ASL 2 - #define XML_TAG_KEY 0 #define XML_TAG_STRING 1 #define XML_TAG_DATA 2 @@ -264,7 +262,7 @@ asl_open(const char *ident, const char *facility, uint32_t opts) if (!(asl->options & ASL_OPT_NO_REMOTE)) _asl_notify_open(1); - if (asl->options & ASL_OPT_STDERR) asl_add_output((aslclient)asl, fileno(stderr), ASL_MSG_FMT_STD, ASL_TIME_FMT_LCL); + if (asl->options & ASL_OPT_STDERR) asl_add_output((aslclient)asl, fileno(stderr), ASL_MSG_FMT_STD, ASL_TIME_FMT_LCL, ASL_ENCODE_SAFE); return (aslclient)asl; } @@ -296,6 +294,8 @@ asl_close(aslclient ac) free(asl->fd_tfmt); } + if (asl->fd_encoding != NULL) free(asl->fd_encoding); + memset(asl, 0, sizeof(asl_client_t)); free(asl); } @@ -409,8 +409,8 @@ _asl_encode_char(char **m, uint32_t *x, uint32_t c, uint32_t encode, uint32_t en return; } - /* [ and ] ane escaped in ASL encoding */ - if ((encode == ENCODE_ASL) && (meta == 0) && ((c == 91) || (c == 93))) + /* [ and ] are escaped in ASL encoding */ + if ((encode == ASL_ENCODE_ASL) && (meta == 0) && ((c == 91) || (c == 93))) { *p++ = '\\'; *p++ = c; @@ -484,13 +484,16 @@ _asl_append_string(char **m, uint32_t *x, const char *s, uint32_t encode, uint32 { uint32_t i, n, spextra; uint8_t c; + char *p; if (m == NULL) return; if (x == NULL) return; if (s == NULL) return; - if (encode == ENCODE_NONE) + if (encode == ASL_ENCODE_NONE) { + /* no encoding - just allocate enough space and copy the string */ + n = strlen(s); if (n == 0) return; @@ -511,6 +514,66 @@ _asl_append_string(char **m, uint32_t *x, const char *s, uint32_t encode, uint32 return; } + else if (encode == ASL_ENCODE_SAFE) + { + /* + * Minor encoding to reduce the likelyhood of spoof attacks. + * + * - append a tab after newlines + * - translate \r to newline & append a tab + * - map backspace to ^H + * + * Note that there may be UTF-8 characters that could be used in a spoof + * attack that we don't check. Caveat Reador. + */ + n = 0; + for (i = 0; s[i] != '\0'; i++) + { + n++; + c = s[i]; + if ((c == 10) || (c == 13) || (c == 8)) n++; + } + + if (n == 0) return; + + if (*m == NULL) + { + *m = malloc(n + 1); + *x = 1; + } + else + { + *m = reallocf(*m, n + (*x)); + } + + if (*m == NULL) return; + + p = *m + *x - 1; + + for (i = 0; s[i] != '\0'; i++) + { + c = s[i]; + if ((c == 10) || (c == 13)) + { + *p++ = '\n'; + *p++ = '\t'; + *x = *x + 2; + } + else if (c == 8) + { + *p++ = '^'; + *p++ = 'H'; + *x = *x + 2; + } + else + { + *p++ = c; + *x = *x + 1; + } + } + + return; + } spextra = 0; @@ -527,7 +590,7 @@ _asl_append_string(char **m, uint32_t *x, const char *s, uint32_t encode, uint32 } else if ((c == 91) || (c == 93)) { - if (encode == ENCODE_ASL) n += 2; + if (encode == ASL_ENCODE_ASL) n += 2; else n += 1; } else @@ -679,30 +742,30 @@ _asl_append_xml_tag(char **m, uint32_t *x, int tag, char *s) if (tag == XML_TAG_KEY) { - _asl_append_string(m, x, "\t\t", ENCODE_NONE, 0); + _asl_append_string(m, x, "\t\t", ASL_ENCODE_NONE, 0); _asl_append_xml_string(m, x, s); - _asl_append_string(m, x, "\n", ENCODE_NONE, 0); + _asl_append_string(m, x, "\n", ASL_ENCODE_NONE, 0); return; } if (tag == XML_TAG_STRING) { - _asl_append_string(m, x, "\t\t", ENCODE_NONE, 0); + _asl_append_string(m, x, "\t\t", ASL_ENCODE_NONE, 0); _asl_append_xml_string(m, x, s); - _asl_append_string(m, x, "\n", ENCODE_NONE, 0); + _asl_append_string(m, x, "\n", ASL_ENCODE_NONE, 0); return; } if (tag == XML_TAG_DATA) { - _asl_append_string(m, x, "\t\t", ENCODE_NONE, 0); + _asl_append_string(m, x, "\t\t", ASL_ENCODE_NONE, 0); b64 = (char *)asl_b64_encode((uint8_t *)s, strlen(s)); if (b64 != NULL) { - _asl_append_string(m, x, b64, ENCODE_NONE, 0); + _asl_append_string(m, x, b64, ASL_ENCODE_NONE, 0); free(b64); } - _asl_append_string(m, x, "\n", ENCODE_NONE, 0); + _asl_append_string(m, x, "\n", ASL_ENCODE_NONE, 0); return; } } @@ -716,7 +779,7 @@ _asl_append_op(char **m, uint32_t *x, uint32_t op) if (m == NULL) return; if (x == NULL) return; - if (op == ASL_QUERY_OP_NULL) return _asl_append_string(m, x, ".", ENCODE_NONE, 0); + if (op == ASL_QUERY_OP_NULL) return _asl_append_string(m, x, ".", ASL_ENCODE_NONE, 0); i = 0; if (op & ASL_QUERY_OP_CASEFOLD) opstr[i++] = 'C'; @@ -761,10 +824,10 @@ _asl_append_op(char **m, uint32_t *x, uint32_t op) break; } - if (i == 0) return _asl_append_string(m, x, ".", ENCODE_NONE, 0); + if (i == 0) return _asl_append_string(m, x, ".", ASL_ENCODE_NONE, 0); opstr[i++] = '\0'; - return _asl_append_string(m, x, opstr, ENCODE_NONE, 0); + return _asl_append_string(m, x, opstr, ASL_ENCODE_NONE, 0); } static char * @@ -829,30 +892,30 @@ _asl_msg_to_string_time_fmt(asl_msg_t *msg, uint32_t *len, int tf) for (i = 0; i < msg->count; i++) { if (msg->key[i] == NULL) continue; - if (i > 0) _asl_append_string(&out, &outlen, " [", ENCODE_NONE, 0); - else _asl_append_string(&out, &outlen, "[", ENCODE_NONE, 0); + if (i > 0) _asl_append_string(&out, &outlen, " [", ASL_ENCODE_NONE, 0); + else _asl_append_string(&out, &outlen, "[", ASL_ENCODE_NONE, 0); - _asl_append_string(&out, &outlen, msg->key[i], ENCODE_ASL, 1); + _asl_append_string(&out, &outlen, msg->key[i], ASL_ENCODE_ASL, 1); if ((tf != TFMT_SEC) && (!strcmp(msg->key[i], ASL_KEY_TIME))) { s = _asl_time_string(tf, msg->val[i]); if (s != NULL) { - _asl_append_string(&out, &outlen, " ", ENCODE_NONE, 0); - _asl_append_string(&out, &outlen, s, ENCODE_ASL, 0); + _asl_append_string(&out, &outlen, " ", ASL_ENCODE_NONE, 0); + _asl_append_string(&out, &outlen, s, ASL_ENCODE_ASL, 0); } } else if (msg->val[i] != NULL) { - _asl_append_string(&out, &outlen, " ", ENCODE_NONE, 0); - _asl_append_string(&out, &outlen, msg->val[i], ENCODE_ASL, 0); + _asl_append_string(&out, &outlen, " ", ASL_ENCODE_NONE, 0); + _asl_append_string(&out, &outlen, msg->val[i], ASL_ENCODE_ASL, 0); } - _asl_append_string(&out, &outlen, "]", ENCODE_NONE, 0); + _asl_append_string(&out, &outlen, "]", ASL_ENCODE_NONE, 0); } - _asl_append_string(&out, &outlen, "\n", ENCODE_NONE, 0); + _asl_append_string(&out, &outlen, "\n", ASL_ENCODE_NONE, 0); *len = outlen; return out; @@ -874,7 +937,7 @@ asl_msg_to_string(asl_msg_t *msg, uint32_t *len) if (msg->type == ASL_TYPE_QUERY) { - _asl_append_string(&out, &outlen, "Q ", ENCODE_NONE, 0); + _asl_append_string(&out, &outlen, "Q ", ASL_ENCODE_NONE, 0); if (out == NULL) return NULL; } @@ -889,24 +952,24 @@ asl_msg_to_string(asl_msg_t *msg, uint32_t *len) { if (msg->key[i] == NULL) continue; - if (i > 0) _asl_append_string(&out, &outlen, " [", ENCODE_NONE, 0); - else _asl_append_string(&out, &outlen, "[", ENCODE_NONE, 0); + if (i > 0) _asl_append_string(&out, &outlen, " [", ASL_ENCODE_NONE, 0); + else _asl_append_string(&out, &outlen, "[", ASL_ENCODE_NONE, 0); if (msg->type == ASL_TYPE_QUERY) { _asl_append_op(&out, &outlen, msg->op[i]); - _asl_append_string(&out, &outlen, " ", ENCODE_NONE, 0); + _asl_append_string(&out, &outlen, " ", ASL_ENCODE_NONE, 0); } - _asl_append_string(&out, &outlen, msg->key[i], ENCODE_ASL, 1); + _asl_append_string(&out, &outlen, msg->key[i], ASL_ENCODE_ASL, 1); if (msg->val[i] != NULL) { - _asl_append_string(&out, &outlen, " ", ENCODE_NONE, 0); - _asl_append_string(&out, &outlen, msg->val[i], ENCODE_ASL, 0); + _asl_append_string(&out, &outlen, " ", ASL_ENCODE_NONE, 0); + _asl_append_string(&out, &outlen, msg->val[i], ASL_ENCODE_ASL, 0); } - _asl_append_string(&out, &outlen, "]", ENCODE_NONE, 0); + _asl_append_string(&out, &outlen, "]", ASL_ENCODE_NONE, 0); } *len = outlen; @@ -1698,7 +1761,7 @@ asl_msg_cmp(asl_msg_t *a, asl_msg_t *b) * Log messages will be written to this file as well as to the server. */ int -asl_add_output(aslclient ac, int fd, const char *mfmt, const char *tfmt) +asl_add_output(aslclient ac, int fd, const char *mfmt, const char *tfmt, uint32_t text_encoding) { uint32_t i; int use_global_lock; @@ -1718,7 +1781,7 @@ asl_add_output(aslclient ac, int fd, const char *mfmt, const char *tfmt) { if (asl->fd_list[i] == fd) { - /* update message format and time format */ + /* update message format, time format, and text encoding */ if (asl->fd_mfmt[i] != NULL) free(asl->fd_mfmt[i]); asl->fd_mfmt[i] = NULL; if (mfmt != NULL) asl->fd_mfmt[i] = strdup(mfmt); @@ -1727,6 +1790,8 @@ asl_add_output(aslclient ac, int fd, const char *mfmt, const char *tfmt) asl->fd_tfmt[i] = NULL; if (tfmt != NULL) asl->fd_tfmt[i] = strdup(tfmt); + asl->fd_encoding[i] = text_encoding; + if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock); return 0; } @@ -1737,19 +1802,22 @@ asl_add_output(aslclient ac, int fd, const char *mfmt, const char *tfmt) asl->fd_list = (int *)calloc(1, sizeof(int)); asl->fd_mfmt = (char **)calloc(1, sizeof(char *)); asl->fd_tfmt = (char **)calloc(1, sizeof(char *)); + asl->fd_encoding = (uint32_t *)calloc(1, sizeof(int)); } else { asl->fd_list = (int *)reallocf(asl->fd_list, (1 + asl->fd_count) * sizeof(int)); asl->fd_mfmt = (char **)reallocf(asl->fd_mfmt, (1 + asl->fd_count) * sizeof(char *)); asl->fd_tfmt = (char **)reallocf(asl->fd_tfmt, (1 + asl->fd_count) * sizeof(char *)); + asl->fd_encoding = (uint32_t *)reallocf(asl->fd_encoding, (1 + asl->fd_count) * sizeof(uint32_t)); } - if ((asl->fd_list == NULL) || (asl->fd_mfmt == NULL) || (asl->fd_tfmt == NULL)) + if ((asl->fd_list == NULL) || (asl->fd_mfmt == NULL) || (asl->fd_tfmt == NULL) || (asl->fd_encoding == NULL)) { if (asl->fd_list != NULL) free(asl->fd_list); if (asl->fd_mfmt != NULL) free(asl->fd_mfmt); if (asl->fd_tfmt != NULL) free(asl->fd_tfmt); + if (asl->fd_encoding != NULL) free(asl->fd_encoding); if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock); return -1; @@ -1758,6 +1826,7 @@ asl_add_output(aslclient ac, int fd, const char *mfmt, const char *tfmt) asl->fd_list[asl->fd_count] = fd; if (mfmt != NULL) asl->fd_mfmt[asl->fd_count] = strdup(mfmt); if (tfmt != NULL) asl->fd_tfmt[asl->fd_count] = strdup(tfmt); + asl->fd_encoding[asl->fd_count] = text_encoding; asl->fd_count++; @@ -1768,7 +1837,7 @@ asl_add_output(aslclient ac, int fd, const char *mfmt, const char *tfmt) int asl_add_log_file(aslclient ac, int fd) { - return asl_add_output(ac, fd, ASL_MSG_FMT_STD, ASL_TIME_FMT_LCL); + return asl_add_output(ac, fd, ASL_MSG_FMT_STD, ASL_TIME_FMT_LCL, ASL_ENCODE_SAFE); } /* @@ -1821,6 +1890,7 @@ asl_remove_output(aslclient ac, int fd) asl->fd_list[x] = asl->fd_list[i]; asl->fd_mfmt[x] = asl->fd_mfmt[i]; asl->fd_tfmt[x] = asl->fd_tfmt[i]; + asl->fd_encoding[x] = asl->fd_encoding[i]; } asl->fd_count--; @@ -1829,16 +1899,24 @@ asl_remove_output(aslclient ac, int fd) { free(asl->fd_list); asl->fd_list = NULL; + + free(asl->fd_mfmt); asl->fd_mfmt = NULL; + + free(asl->fd_tfmt); asl->fd_tfmt = NULL; + + free(asl->fd_encoding); + asl->fd_encoding = NULL; } else { asl->fd_list = (int *)reallocf(asl->fd_list, asl->fd_count * sizeof(int)); asl->fd_mfmt = (char **)reallocf(asl->fd_mfmt, asl->fd_count * sizeof(char *)); asl->fd_tfmt = (char **)reallocf(asl->fd_tfmt, asl->fd_count * sizeof(char *)); + asl->fd_encoding = (uint32_t *)reallocf(asl->fd_encoding, asl->fd_count * sizeof(uint32_t)); - if ((asl->fd_list == NULL) || (asl->fd_mfmt == NULL) || (asl->fd_tfmt == NULL)) + if ((asl->fd_list == NULL) || (asl->fd_mfmt == NULL) || (asl->fd_tfmt == NULL) || (asl->fd_encoding == NULL)) { if (asl->fd_list != NULL) { @@ -1860,6 +1938,12 @@ asl_remove_output(aslclient ac, int fd) asl->fd_tfmt = NULL; } + if (asl->fd_encoding != NULL) + { + free(asl->fd_encoding); + asl->fd_encoding = NULL; + } + asl->fd_count = 0; if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock); return -1; @@ -2246,7 +2330,7 @@ _asl_level_string(int level) * out parameter len returns string length including trailing NUL */ char * -asl_format_message(aslmsg msg, const char *mfmt, const char *tfmt, uint32_t *len) +asl_format_message(aslmsg msg, const char *mfmt, const char *tfmt, uint32_t text_encoding, uint32_t *len) { char *out, *tstr, *k, c[2]; const char *hstr, *sstr, *pstr, *mstr, *lstr, *rprc, *rpid, *v; @@ -2284,8 +2368,8 @@ asl_format_message(aslmsg msg, const char *mfmt, const char *tfmt, uint32_t *len mstr = asl_get(msg, ASL_KEY_MSG); if (mstr == NULL) return NULL; - _asl_append_string(&out, len, mstr, ENCODE_VIS, 0); - _asl_append_string(&out, len, "\n", ENCODE_NONE, 0); + _asl_append_string(&out, len, mstr, text_encoding, 0); + _asl_append_string(&out, len, "\n", ASL_ENCODE_NONE, 0); return out; } @@ -2318,61 +2402,61 @@ asl_format_message(aslmsg msg, const char *mfmt, const char *tfmt, uint32_t *len if (tstr == NULL) { - _asl_append_string(&out, len, "0", ENCODE_NONE, 0); + _asl_append_string(&out, len, "0", ASL_ENCODE_NONE, 0); } else { - _asl_append_string(&out, len, tstr, ENCODE_NONE, 0); + _asl_append_string(&out, len, tstr, ASL_ENCODE_NONE, 0); free(tstr); } - _asl_append_string(&out, len, " ", ENCODE_NONE, 0); + _asl_append_string(&out, len, " ", ASL_ENCODE_NONE, 0); - if (hstr == NULL) _asl_append_string(&out, len, "unknown", ENCODE_NONE, 0); - else _asl_append_string(&out, len, hstr, ENCODE_VIS, 0); + if (hstr == NULL) _asl_append_string(&out, len, "unknown", ASL_ENCODE_NONE, 0); + else _asl_append_string(&out, len, hstr, text_encoding, 0); - _asl_append_string(&out, len, " ", ENCODE_NONE, 0); + _asl_append_string(&out, len, " ", ASL_ENCODE_NONE, 0); - if (sstr == NULL) _asl_append_string(&out, len, "unknown", ENCODE_NONE, 0); - else _asl_append_string(&out, len, sstr, ENCODE_VIS, 0); + if (sstr == NULL) _asl_append_string(&out, len, "unknown", ASL_ENCODE_NONE, 0); + else _asl_append_string(&out, len, sstr, text_encoding, 0); if ((pstr != NULL) && (strcmp(pstr, "-1"))) { - _asl_append_string(&out, len, "[", ENCODE_NONE, 0); - _asl_append_string(&out, len, pstr, ENCODE_NONE, 0); - _asl_append_string(&out, len, "]", ENCODE_NONE, 0); + _asl_append_string(&out, len, "[", ASL_ENCODE_NONE, 0); + _asl_append_string(&out, len, pstr, ASL_ENCODE_NONE, 0); + _asl_append_string(&out, len, "]", ASL_ENCODE_NONE, 0); } - if ((rprc != NULL) || (rpid != NULL)) _asl_append_string(&out, len, " (", ENCODE_NONE, 0); + if ((rprc != NULL) || (rpid != NULL)) _asl_append_string(&out, len, " (", ASL_ENCODE_NONE, 0); - if (rprc != NULL) _asl_append_string(&out, len, rprc, ENCODE_VIS, 0); + if (rprc != NULL) _asl_append_string(&out, len, rprc, text_encoding, 0); if (rpid != NULL) { - _asl_append_string(&out, len, "[", ENCODE_NONE, 0); - _asl_append_string(&out, len, rpid, ENCODE_NONE, 0); - _asl_append_string(&out, len, "]", ENCODE_NONE, 0); + _asl_append_string(&out, len, "[", ASL_ENCODE_NONE, 0); + _asl_append_string(&out, len, rpid, ASL_ENCODE_NONE, 0); + _asl_append_string(&out, len, "]", ASL_ENCODE_NONE, 0); } - if ((rprc != NULL) || (rpid != NULL)) _asl_append_string(&out, len, ")", ENCODE_NONE, 0); + if ((rprc != NULL) || (rpid != NULL)) _asl_append_string(&out, len, ")", ASL_ENCODE_NONE, 0); if (mf == MFMT_STD) { - _asl_append_string(&out, len, " <", ENCODE_NONE, 0); - _asl_append_string(&out, len, _asl_level_string(level), ENCODE_NONE, 0); - _asl_append_string(&out, len, ">", ENCODE_NONE, 0); + _asl_append_string(&out, len, " <", ASL_ENCODE_NONE, 0); + _asl_append_string(&out, len, _asl_level_string(level), ASL_ENCODE_NONE, 0); + _asl_append_string(&out, len, ">", ASL_ENCODE_NONE, 0); } - _asl_append_string(&out, len, ": ", ENCODE_NONE, 0); + _asl_append_string(&out, len, ": ", ASL_ENCODE_NONE, 0); - if (mstr != NULL) _asl_append_string(&out, len, mstr, ENCODE_VIS, 0); + if (mstr != NULL) _asl_append_string(&out, len, mstr, text_encoding, 0); - _asl_append_string(&out, len, "\n", ENCODE_NONE, 0); + _asl_append_string(&out, len, "\n", ASL_ENCODE_NONE, 0); return out; } if (mf == MFMT_XML) { - _asl_append_string(&out, len, "\t\n", ENCODE_NONE, 0); + _asl_append_string(&out, len, "\t\n", ASL_ENCODE_NONE, 0); for (i = 0; i < msg->count; i++) { @@ -2393,7 +2477,7 @@ asl_format_message(aslmsg msg, const char *mfmt, const char *tfmt, uint32_t *len } } - _asl_append_string(&out, len, "\t\n", ENCODE_NONE, 0); + _asl_append_string(&out, len, "\t\n", ASL_ENCODE_NONE, 0); return out; } @@ -2453,12 +2537,12 @@ asl_format_message(aslmsg msg, const char *mfmt, const char *tfmt, uint32_t *len if (!strcmp(k, ASL_KEY_TIME)) { tstr = _asl_time_string(tf, v); - _asl_append_string(&out, len, tstr, ENCODE_NONE, 0); + _asl_append_string(&out, len, tstr, ASL_ENCODE_NONE, 0); if (tstr != NULL) free(tstr); } else { - _asl_append_string(&out, len, (char *)v, ENCODE_NONE, 0); + _asl_append_string(&out, len, (char *)v, ASL_ENCODE_NONE, 0); } } } @@ -2468,18 +2552,18 @@ asl_format_message(aslmsg msg, const char *mfmt, const char *tfmt, uint32_t *len if (mfmt[i] == '\\') { i++; - if (mfmt[i] == '$') _asl_append_string(&out, len, "$", ENCODE_NONE, 0); - else if (mfmt[i] == 'e') _asl_append_string(&out, len, "\e", ENCODE_NONE, 0); - else if (mfmt[i] == 's') _asl_append_string(&out, len, " ", ENCODE_NONE, 0); - else if (mfmt[i] == 'a') _asl_append_string(&out, len, "\a", ENCODE_NONE, 0); - else if (mfmt[i] == 'b') _asl_append_string(&out, len, "\b", ENCODE_NONE, 0); - else if (mfmt[i] == 'f') _asl_append_string(&out, len, "\f", ENCODE_NONE, 0); - else if (mfmt[i] == 'n') _asl_append_string(&out, len, "\n", ENCODE_NONE, 0); - else if (mfmt[i] == 'r') _asl_append_string(&out, len, "\r", ENCODE_NONE, 0); - else if (mfmt[i] == 't') _asl_append_string(&out, len, "\t", ENCODE_NONE, 0); - else if (mfmt[i] == 'v') _asl_append_string(&out, len, "\v", ENCODE_NONE, 0); - else if (mfmt[i] == '\'') _asl_append_string(&out, len, "\'", ENCODE_NONE, 0); - else if (mfmt[i] == '\\') _asl_append_string(&out, len, "\\", ENCODE_NONE, 0); + if (mfmt[i] == '$') _asl_append_string(&out, len, "$", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == 'e') _asl_append_string(&out, len, "\e", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == 's') _asl_append_string(&out, len, " ", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == 'a') _asl_append_string(&out, len, "\a", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == 'b') _asl_append_string(&out, len, "\b", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == 'f') _asl_append_string(&out, len, "\f", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == 'n') _asl_append_string(&out, len, "\n", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == 'r') _asl_append_string(&out, len, "\r", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == 't') _asl_append_string(&out, len, "\t", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == 'v') _asl_append_string(&out, len, "\v", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == '\'') _asl_append_string(&out, len, "\'", ASL_ENCODE_NONE, 0); + else if (mfmt[i] == '\\') _asl_append_string(&out, len, "\\", ASL_ENCODE_NONE, 0); else if (isdigit(mfmt[i])) { oval = mfmt[i] - '0'; @@ -2494,17 +2578,17 @@ asl_format_message(aslmsg msg, const char *mfmt, const char *tfmt, uint32_t *len } } c[0] = oval; - _asl_append_string(&out, len, c, ENCODE_NONE, 0); + _asl_append_string(&out, len, c, ASL_ENCODE_NONE, 0); } continue; } if (mfmt[i] == '\0') break; c[0] = mfmt[i]; - _asl_append_string(&out, len, c, ENCODE_NONE, 0); + _asl_append_string(&out, len, c, ASL_ENCODE_NONE, 0); } - _asl_append_string(&out, len, "\n", ENCODE_NONE, 0); + _asl_append_string(&out, len, "\n", ASL_ENCODE_NONE, 0); return out; } @@ -2525,6 +2609,7 @@ asl_send(aslclient ac, aslmsg msg) const char *val; char *name, *x; time_t tick; + struct timeval tval; int status, rc_filter; asl_client_t *asl; int use_global_lock; @@ -2583,15 +2668,40 @@ asl_send(aslclient ac, aslmsg msg) } /* - * Time, Host, PID, UID, and GID values get set here + * Time, TimeNanoSec, Host, PID, UID, and GID values get set here */ str = NULL; - tick = time(NULL); - asprintf(&str, "%lu", tick); - if (str != NULL) + memset(&tval, 0, sizeof(struct timeval)); + + status = gettimeofday(&tval, NULL); + if (status == 0) { - asl_set(msg, ASL_KEY_TIME, str); - free(str); + asprintf(&str, "%lu", tval.tv_sec); + if (str != NULL) + { + asl_set(msg, ASL_KEY_TIME, str); + free(str); + str = NULL; + } + + asprintf(&str, "%lu", tval.tv_usec * 1000); + if (str != NULL) + { + asl_set(msg, ASL_KEY_TIME_NSEC, str); + free(str); + str = NULL; + } + } + else + { + tick = time(NULL); + asprintf(&str, "%lu", tick); + if (str != NULL) + { + asl_set(msg, ASL_KEY_TIME, str); + free(str); + str = NULL; + } } memset(&hname, 0, _POSIX_HOST_NAME_MAX); @@ -2724,7 +2834,7 @@ asl_send(aslclient ac, aslmsg msg) if (asl->fd_list[i] < 0) continue; len = 0; - out = asl_format_message(msg, asl->fd_mfmt[i], asl->fd_tfmt[i], &len); + out = asl_format_message(msg, asl->fd_mfmt[i], asl->fd_tfmt[i], asl->fd_encoding[i], &len); if (out == NULL) continue; status = write(asl->fd_list[i], out, len - 1); @@ -3063,104 +3173,30 @@ asl_unset(aslmsg a, const char *key) aslresponse asl_search(aslclient ac, aslmsg a) { - asl_search_result_t *batch, *out; - char *qstr, *str, *res; - uint32_t i, j, len, reslen, status; - uint64_t cmax, qmin; - kern_return_t kstatus; - security_token_t sec; - caddr_t vmstr; - - if (a == NULL) return 0; - - len = 0; - qstr = asl_msg_to_string((asl_msg_t *)a, &len); - - str = NULL; - if (qstr == NULL) - { - asprintf(&str, "0\n"); - len = 3; - } - else - { - asprintf(&str, "1\n%s\n", qstr); - len += 4; - free(qstr); - } + asl_search_result_t query, *out; + asl_msg_t *qlist[1]; + uint32_t status; + uint64_t last_id; + asl_store_t *store; - if (str == NULL) return NULL; + if (a == NULL) return NULL; - if (asl_server_port == MACH_PORT_NULL) - { - kstatus = bootstrap_look_up(bootstrap_port, ASL_SERVICE_NAME, &asl_server_port); - if (kstatus != KERN_SUCCESS) return NULL; - } + store = NULL; + status = asl_store_open_read(NULL, &store); + if (status != 0) return NULL; + if (store == NULL) return NULL; - /* - * Fetch a batch of results each time through the loop. - * Fetching many small batches rebuces the load on syslogd. - */ out = NULL; - qmin = 0; - cmax = 0; + last_id = 0; - forever - { - res = NULL; - reslen = 0; - sec.val[0] = -1; - sec.val[1] = -1; - status = 0; - - kstatus = vm_allocate(mach_task_self(), (vm_address_t *)&vmstr, len, TRUE); - if (kstatus != KERN_SUCCESS) return NULL; - - memmove(vmstr, str, len); - - kstatus = _asl_server_query(asl_server_port, vmstr, len, qmin, FETCH_BATCH, 0, (caddr_t *)&res, &reslen, &cmax, (int *)&status, &sec); - if (kstatus != KERN_SUCCESS) break; - if (res == NULL) break; - - batch = asl_list_from_string(res); - vm_deallocate(mach_task_self(), (vm_address_t)res, reslen); - - if (batch == NULL) break; - if (batch->count == 0) - { - aslresponse_free(batch); - break; - } - - if (out == NULL) out = (asl_search_result_t *)calloc(1, sizeof(asl_search_result_t)); - if (out == NULL) - { - aslresponse_free(batch); - break; - } + qlist[0] = a; + memset(&query, 0, sizeof(asl_search_result_t)); + query.count = 1; + query.msg = qlist; - if (out->count == 0) out->msg = (asl_msg_t **)calloc(batch->count, sizeof(asl_msg_t *)); - else out->msg = (asl_msg_t **)reallocf(out->msg, (out->count + batch->count) * sizeof(asl_msg_t *)); - if (out->msg == NULL) - { - aslresponse_free(batch); - free(out); - free(str); - return NULL; - } + status = asl_store_match(store, &query, &out, &last_id, 0, 0, 1); + asl_store_close(store); - for (i = 0, j = out->count; i < batch->count; i++, j++) out->msg[j] = batch->msg[i]; - - out->count += batch->count; - free(batch->msg); - free(batch); - - if (i < FETCH_BATCH) break; - - if (cmax > qmin) qmin = cmax; - } - - free(str); return out; } diff --git a/gen/asl_core.c b/gen/asl_core.c new file mode 100644 index 0000000..8d8bb05 --- /dev/null +++ b/gen/asl_core.c @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2007 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2007 Apple Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include +#include +#include + +/* + * Message ID generation + */ +static uint64_t _asl_core_msg_next_id = 1; +static pthread_mutex_t msg_id_lock = PTHREAD_MUTEX_INITIALIZER; + +#define mix(a, b, c) \ +{ \ + a -= b; a -= c; a ^= (c>>13); \ + b -= c; b -= a; b ^= (a<< 8); \ + c -= a; c -= b; c ^= (b>>13); \ + a -= b; a -= c; a ^= (c>>12); \ + b -= c; b -= a; b ^= (a<<16); \ + c -= a; c -= b; c ^= (b>> 5); \ + a -= b; a -= c; a ^= (c>> 3); \ + b -= c; b -= a; b ^= (a<<10); \ + c -= a; c -= b; c ^= (b>>15); \ +} + +/* + * Hash is used to improve string search. + */ +uint32_t +asl_core_string_hash(const char *s, uint32_t inlen) +{ + uint32_t a, b, c, l, len; + + if (s == NULL) return 0; + + l = inlen; + + len = l; + a = b = 0x9e3779b9; + c = 0; + + while (len >= 12) + { + a += (s[0] + ((uint32_t)s[1]<<8) + ((uint32_t)s[ 2]<<16) + ((uint32_t)s[ 3]<<24)); + b += (s[4] + ((uint32_t)s[5]<<8) + ((uint32_t)s[ 6]<<16) + ((uint32_t)s[ 7]<<24)); + c += (s[8] + ((uint32_t)s[9]<<8) + ((uint32_t)s[10]<<16) + ((uint32_t)s[11]<<24)); + + mix(a, b, c); + + s += 12; + len -= 12; + } + + c += l; + switch(len) + { + case 11: c += ((uint32_t)s[10]<<24); + case 10: c += ((uint32_t)s[9]<<16); + case 9 : c += ((uint32_t)s[8]<<8); + + case 8 : b += ((uint32_t)s[7]<<24); + case 7 : b += ((uint32_t)s[6]<<16); + case 6 : b += ((uint32_t)s[5]<<8); + case 5 : b += s[4]; + + case 4 : a += ((uint32_t)s[3]<<24); + case 3 : a += ((uint32_t)s[2]<<16); + case 2 : a += ((uint32_t)s[1]<<8); + case 1 : a += s[0]; + } + + mix(a, b, c); + + if (c == 0) c = 1; + return c; +} + +const char * +asl_core_error(uint32_t code) +{ + switch (code) + { + case ASL_STATUS_OK: return "Operation Succeeded"; + case ASL_STATUS_INVALID_ARG: return "Invalid Argument"; + case ASL_STATUS_INVALID_STORE: return "Invalid Data Store"; + case ASL_STATUS_INVALID_STRING: return "Invalid String"; + case ASL_STATUS_INVALID_ID: return "Invalid ID Number"; + case ASL_STATUS_INVALID_MESSAGE: return "Invalid Message"; + case ASL_STATUS_NOT_FOUND: return "Not Found"; + case ASL_STATUS_READ_FAILED: return "Read Operation Failed"; + case ASL_STATUS_WRITE_FAILED: return "Write Operation Failed"; + case ASL_STATUS_NO_MEMORY: return "System Memory Allocation Failed"; + case ASL_STATUS_ACCESS_DENIED: return "Access Denied"; + case ASL_STATUS_READ_ONLY: return "Read Only Access"; + case ASL_STATUS_WRITE_ONLY: return "Write Only Access"; + case ASL_STATUS_MATCH_FAILED: return "Match Failed"; + case ASL_STATUS_NO_RECORDS: return "No More Records"; + } + + return "Operation Failed"; +} + +static uint32_t +asl_core_check_user_access(int32_t msgu, int32_t readu) +{ + /* -1 means anyone may read */ + if (msgu == -1) return ASL_STATUS_OK; + + /* Check for exact match */ + if (msgu == readu) return ASL_STATUS_OK; + + return ASL_STATUS_ACCESS_DENIED; +} + +static uint32_t +asl_core_check_group_access(int32_t msgg, int32_t readu, int32_t readg) +{ + int check; + uuid_t uu, gu; + + /* -1 means anyone may read */ + if (msgg == -1) return ASL_STATUS_OK; + + /* Check for exact match */ + if (msgg == readg) return ASL_STATUS_OK; + + /* Check if user (u) is in read group (msgg) */ + mbr_uid_to_uuid(readu, uu); + mbr_gid_to_uuid(msgg, gu); + + check = 0; + mbr_check_membership(uu, gu, &check); + if (check != 0) return ASL_STATUS_OK; + + return ASL_STATUS_ACCESS_DENIED; +} + +uint32_t +asl_core_check_access(int32_t msgu, int32_t msgg, int32_t readu, int32_t readg, uint16_t flags) +{ + uint16_t uset, gset; + + /* root (uid 0) may always read */ + if (readu == 0) return ASL_STATUS_OK; + + uset = flags & ASL_MSG_FLAG_READ_UID_SET; + gset = flags & ASL_MSG_FLAG_READ_GID_SET; + + /* if no access controls are set, anyone may read */ + if ((uset | gset) == 0) return ASL_STATUS_OK; + + /* if only uid is set, then access is only by uid match */ + if ((uset != 0) && (gset == 0)) return asl_core_check_user_access(msgu, readu); + + /* if only gid is set, then access is only by gid match */ + if ((uset == 0) && (gset != 0)) return asl_core_check_group_access(msgg, readu, readg); + + /* both uid and gid are set - check user, then group */ + if ((asl_core_check_user_access(msgu, readu)) == ASL_STATUS_OK) return ASL_STATUS_OK; + return asl_core_check_group_access(msgg, readu, readg); +} + +uint64_t +asl_core_htonq(uint64_t n) +{ +#ifdef __BIG_ENDIAN__ + return n; +#else + u_int32_t t; + union + { + u_int64_t q; + u_int32_t l[2]; + } x; + + x.q = n; + t = x.l[0]; + x.l[0] = htonl(x.l[1]); + x.l[1] = htonl(t); + + return x.q; +#endif +} + +uint64_t +asl_core_ntohq(uint64_t n) +{ +#ifdef __BIG_ENDIAN__ + return n; +#else + u_int32_t t; + union + { + u_int64_t q; + u_int32_t l[2]; + } x; + + x.q = n; + t = x.l[0]; + x.l[0] = ntohl(x.l[1]); + x.l[1] = ntohl(t); + + return x.q; +#endif +} + +uint64_t +asl_core_new_msg_id(uint64_t start) +{ + uint64_t out; + + pthread_mutex_lock(&msg_id_lock); + + if (start != 0) _asl_core_msg_next_id = start; + + out = _asl_core_msg_next_id; + _asl_core_msg_next_id++; + + pthread_mutex_unlock(&msg_id_lock); + + return out; +} diff --git a/gen/asl_core.h b/gen/asl_core.h new file mode 100644 index 0000000..6b0dbc1 --- /dev/null +++ b/gen/asl_core.h @@ -0,0 +1,84 @@ +#ifndef __ASL_CORE_H__ +#define __ASL_CORE_H__ + +/* + * Copyright (c) 2007 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2007 Apple Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include + +#define asl_msg_list_t asl_search_result_t + +#define ASL_STATUS_OK 0 +#define ASL_STATUS_INVALID_ARG 1 +#define ASL_STATUS_INVALID_STORE 2 +#define ASL_STATUS_INVALID_STRING 3 +#define ASL_STATUS_INVALID_ID 4 +#define ASL_STATUS_INVALID_MESSAGE 5 +#define ASL_STATUS_NOT_FOUND 6 +#define ASL_STATUS_READ_FAILED 7 +#define ASL_STATUS_WRITE_FAILED 8 +#define ASL_STATUS_NO_MEMORY 9 +#define ASL_STATUS_ACCESS_DENIED 10 +#define ASL_STATUS_READ_ONLY 11 +#define ASL_STATUS_WRITE_ONLY 12 +#define ASL_STATUS_MATCH_FAILED 13 +#define ASL_STATUS_NO_RECORDS 14 +#define ASL_STATUS_FAILED 9999 + +#define ASL_REF_NULL 0xffffffffffffffffLL + +#define ASL_MSG_FLAG_READ_UID_SET 0x0001 +#define ASL_MSG_FLAG_READ_GID_SET 0x0002 +#define ASL_MSG_FLAG_SEARCH_MATCH 0x8000 +#define ASL_MSG_FLAG_SEARCH_CLEAR 0x7fff + +#define ASL_QUERY_MATCH_SLOW 0x00000000 +#define ASL_QUERY_MATCH_MSG_ID 0x00000001 +#define ASL_QUERY_MATCH_TIME 0x00000002 +#define ASL_QUERY_MATCH_NANO 0x00000004 +#define ASL_QUERY_MATCH_LEVEL 0x00000008 +#define ASL_QUERY_MATCH_PID 0x00000010 +#define ASL_QUERY_MATCH_UID 0x00000020 +#define ASL_QUERY_MATCH_GID 0x00000040 +#define ASL_QUERY_MATCH_RUID 0x00000080 +#define ASL_QUERY_MATCH_RGID 0x00000100 +#define ASL_QUERY_MATCH_REF_PID 0x00000200 +#define ASL_QUERY_MATCH_HOST 0x00000400 +#define ASL_QUERY_MATCH_SENDER 0x00000800 +#define ASL_QUERY_MATCH_FACILITY 0x00001000 +#define ASL_QUERY_MATCH_MESSAGE 0x00002000 +#define ASL_QUERY_MATCH_REF_PROC 0x00004000 +#define ASL_QUERY_MATCH_SESSION 0x00008000 +#define ASL_QUERY_MATCH_TRUE 0x80000000 +#define ASL_QUERY_MATCH_FALSE 0x40000000 +#define ASL_QUERY_MATCH_ERROR 0x20000000 + +uint32_t asl_core_string_hash(const char *str, uint32_t len); +const char *asl_core_error(uint32_t code); +uint32_t asl_core_check_access(int32_t msgu, int32_t msgg, int32_t readu, int32_t readg, uint16_t flags); +uint64_t asl_core_htonq(uint64_t n); +uint64_t asl_core_ntohq(uint64_t n); +uint64_t asl_core_new_msg_id(uint64_t start); + +#endif __ASL_CORE_H__ \ No newline at end of file diff --git a/gen/asl_file.c b/gen/asl_file.c new file mode 100644 index 0000000..159d628 --- /dev/null +++ b/gen/asl_file.c @@ -0,0 +1,1837 @@ +/* + * Copyright (c) 2007-2008 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2007 Apple Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern time_t asl_parse_time(const char *str); +extern int asl_msg_cmp(asl_msg_t *a, asl_msg_t *b); + +#define forever for(;;) +#define MILLION 1000000 + +/* + * MSG and STR records have (at least) a type (uint16_t) and a length (uint32_t) + * type and level are both 16 bit fields so that alignment isn't a pain. + */ +#define RECORD_COMMON_LEN 6 +#define RECORD_TYPE_LEN 2 +#define RECORD_OFFSET_FLAGS 30 +#define RECORD_OFFSET_RUID 44 +#define RECORD_OFFSET_RGID 48 + +#define SCRATCH_BUFFER_SIZE (MSG_RECORD_FIXED_LENGTH + (20 * sizeof(uint64_t))) + +typedef struct +{ + uint64_t next; + uint64_t mid; + uint64_t time; + uint32_t nano; + uint16_t level; + uint16_t flags; + uint32_t pid; + uint32_t uid; + uint32_t gid; + uint32_t ruid; + uint32_t rgid; + uint32_t refpid; + uint32_t kvcount; + uint64_t host; + uint64_t sender; + uint64_t facility; + uint64_t message; + uint64_t refproc; + uint64_t session; + uint64_t prev; +} file_record_t; + +typedef struct +{ + asl_file_list_t *list; + int dir; +} asl_file_match_token_t; + +static uint16_t +_asl_get_16(char *h) +{ + uint16_t x; + + memcpy(&x, h, 2); + return ntohs(x); +} + +static void +_asl_put_16(uint16_t i, char *h) +{ + uint16_t x; + + x = htons(i); + memcpy(h, &x, 2); +} + +static uint32_t +_asl_get_32(char *h) +{ + uint32_t x; + + memcpy(&x, h, 4); + return ntohl(x); +} + +static void +_asl_put_32(uint32_t i, char *h) +{ + uint32_t x; + + x = htonl(i); + memcpy(h, &x, 4); +} + +static uint64_t +_asl_get_64(char *h) +{ + uint64_t x; + + memcpy(&x, h, 8); + return asl_core_ntohq(x); +} + +static void +_asl_put_64(uint64_t i, char *h) +{ + uint64_t x; + + x = asl_core_htonq(i); + memcpy(h, &x, 8); +} + +static uint32_t +asl_file_read_uint32(asl_file_t *s, off_t off, uint32_t *out) +{ + uint32_t status, val; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (s->store == NULL) return ASL_STATUS_INVALID_STORE; + + status = fseeko(s->store, off, SEEK_SET); + if (status != 0) return ASL_STATUS_READ_FAILED; + + val = 0; + + status = fread(&val, sizeof(uint32_t), 1, s->store); + if (status != 1) return ASL_STATUS_READ_FAILED; + + if (out != NULL) *out = ntohl(val); + return ASL_STATUS_OK; +} + +static uint32_t +asl_file_read_uint64(asl_file_t *s, off_t off, uint64_t *out) +{ + uint32_t status; + uint64_t val; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (s->store == NULL) return ASL_STATUS_INVALID_STORE; + + status = fseeko(s->store, off, SEEK_SET); + if (status != 0) return ASL_STATUS_READ_FAILED; + + val = 0; + + status = fread(&val, sizeof(uint64_t), 1, s->store); + if (status != 1) return ASL_STATUS_READ_FAILED; + + if (out != NULL) *out = asl_core_ntohq(val); + return ASL_STATUS_OK; +} + +uint32_t +asl_file_close(asl_file_t *s) +{ + file_string_t *x; + + if (s == NULL) return ASL_STATUS_OK; + + if (s->version == 1) + { + return asl_legacy1_close((asl_legacy1_t *)s->legacy); + } + + while (s->string_list != NULL) + { + x = s->string_list->next; + free(s->string_list); + s->string_list = x; + } + + if (s->store != NULL) fclose(s->store); + + memset(s, 0, sizeof(asl_file_t)); + free(s); + + return ASL_STATUS_OK; +} + +uint32_t +asl_file_open_write(const char *path, mode_t mode, uid_t uid, gid_t gid, asl_file_t **s) +{ + time_t now; + int i, status, fd; + struct stat sb; + char buf[DB_HEADER_LEN]; + asl_file_t *out; + uint32_t aslstatus, vers; + + memset(&sb, 0, sizeof(struct stat)); + + status = stat(path, &sb); + if (status == 0) + { + /* XXX Check that mode, uid, and gid are correct */ + out = (asl_file_t *)calloc(1, sizeof(asl_file_t)); + if (out == NULL) return ASL_STATUS_NO_MEMORY; + + out->store = fopen(path, "r+"); + if (out->store == NULL) + { + free(out); + return ASL_STATUS_FAILED; + } + + out->file_size = sb.st_size; + + i = fread(buf, DB_HEADER_LEN, 1, out->store); + if (i < 1) + { + asl_file_close(out); + return ASL_STATUS_READ_FAILED; + } + + /* check version */ + vers = _asl_get_32(buf + DB_HEADER_VERS_OFFSET); + if (vers != DB_VERSION) + { + asl_file_close(out); + return ASL_STATUS_INVALID_STORE; + } + + out->dob = _asl_get_64(buf + DB_HEADER_TIME_OFFSET); + out->first = _asl_get_64(buf + DB_HEADER_FIRST_OFFSET); + out->last = _asl_get_64(buf + DB_HEADER_LAST_OFFSET); + + aslstatus = asl_file_read_set_position(out, ASL_FILE_POSITION_LAST); + if (aslstatus != ASL_STATUS_OK) + { + asl_file_close(out); + return aslstatus; + } + + out->prev = out->cursor; + status = fseeko(out->store, 0, SEEK_END); + if (status != 0) + { + asl_file_close(out); + return ASL_STATUS_READ_FAILED; + } + + out->file_size = ftello(out->store); + + /* scratch buffer for file writes (we test for NULL before using it) */ + out->scratch = malloc(SCRATCH_BUFFER_SIZE); + + *s = out; + + return ASL_STATUS_OK; + } + + if (errno != ENOENT) return ASL_STATUS_FAILED; + + fd = open(path, O_RDWR | O_CREAT | O_EXCL, mode); + if (fd < 0) return ASL_STATUS_FAILED; + + status = fchown(fd, uid, gid); + if (status != 0) + { + close(fd); + unlink(path); + return ASL_STATUS_FAILED; + } + + out = (asl_file_t *)calloc(1, sizeof(asl_file_t)); + if (out == NULL) return ASL_STATUS_NO_MEMORY; + + out->store = fdopen(fd, "w+"); + if (out->store == NULL) + { + free(out); + return ASL_STATUS_FAILED; + } + + memset(buf, 0, sizeof(buf)); + memcpy(buf, ASL_DB_COOKIE, ASL_DB_COOKIE_LEN); + + _asl_put_32(DB_VERSION, buf + DB_HEADER_VERS_OFFSET); + + now = time(NULL); + out->dob = now; + _asl_put_64(out->dob, buf + DB_HEADER_TIME_OFFSET); + + _asl_put_32(CACHE_SIZE, buf + DB_HEADER_CSIZE_OFFSET); + + status = fwrite(buf, sizeof(buf), 1, out->store); + if (status != 1) + { + fclose(out->store); + free(out); + unlink(path); + return ASL_STATUS_FAILED; + } + + out->file_size = sizeof(buf); + + *s = out; + + return ASL_STATUS_OK; +} + +uint32_t +asl_file_compact(asl_file_t *s, const char *path, mode_t mode, uid_t uid, gid_t gid) +{ + asl_file_t *new; + struct stat sb; + aslmsg m; + uint64_t xid; + uint32_t status; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (path == NULL) return ASL_STATUS_INVALID_ARG; + + if (s->version == 1) return ASL_STATUS_FAILED; + + memset(&sb, 0, sizeof(struct stat)); + + if (stat(path, &sb) == 0) return ASL_STATUS_FAILED; + if (errno != ENOENT) return ASL_STATUS_FAILED; + + status = asl_file_read_set_position(s, ASL_FILE_POSITION_FIRST); + if (status != ASL_STATUS_OK) return status; + + new = NULL; + status = asl_file_open_write(path, mode, uid, gid, &new); + if (status != ASL_STATUS_OK) return status; + new->flags = ASL_FILE_FLAG_UNLIMITED_CACHE | ASL_FILE_FLAG_PRESERVE_MSG_ID; + + while ((status == ASL_STATUS_OK) && (s->cursor != 0)) + { + m = NULL; + status = asl_file_fetch_next(s, &m); + if (status != ASL_STATUS_OK) break; + + xid = 0; + status = asl_file_save(new, m, &xid); + asl_free(m); + } + + asl_file_close(new); + return status; +} + +static uint32_t +asl_file_string_encode(asl_file_t *s, const char *str, uint64_t *out) +{ + uint32_t i, hash, len, x32; + file_string_t *sp, *sx, *sl; + uint64_t x64; + uint8_t inls; + uint16_t type; + off_t off; + char *p; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (str == NULL) return ASL_STATUS_INVALID_ARG; + + len = strlen(str); + + /* inline strings */ + if (len < 8) + { + /* inline string */ + inls = len; + inls |= 0x80; + + x64 = 0; + p = (char *)&x64; + memcpy(p, &inls, 1); + memcpy(p + 1, str, len); + *out = asl_core_ntohq(x64); + return ASL_STATUS_OK; + } + + /* check the cache */ + hash = asl_core_string_hash(str, len); + + sp = NULL; + for (sx = s->string_list; sx != NULL; sx = sx->next) + { + if ((hash == sx->hash) && (!strcmp(str, sx->str))) + { + /* Move this string to the head of the list */ + if (sp != NULL) + { + sl = s->string_list; + sp->next = sx->next; + sx->next = sl; + s->string_list = sx; + } + + *out = sx->where; + return ASL_STATUS_OK; + } + + sp = sx; + } + + off = ftello(s->store); + + /* Type */ + type = htons(ASL_FILE_TYPE_STR); + i = fwrite(&type, sizeof(uint16_t), 1, s->store); + if (i != 1) return ASL_STATUS_WRITE_FAILED; + s->file_size += sizeof(uint16_t); + + /* Length (includes trailing nul) */ + x32 = htonl(len + 1); + i = fwrite(&x32, sizeof(uint32_t), 1, s->store); + if (i != 1) return ASL_STATUS_WRITE_FAILED; + s->file_size += sizeof(uint32_t); + + /* String data (nul terminated) */ + i = fwrite(str, len + 1, 1, s->store); + if (i != 1) return ASL_STATUS_WRITE_FAILED; + s->file_size += len; + + /* create file_string_t and insert into the cache */ + sx = (file_string_t *)calloc(1, offsetof(file_string_t, str) + len + 1); + if (sx == NULL) return ASL_STATUS_NO_MEMORY; + + sx->where = off; + sx->hash = hash; + sx->next = s->string_list; + memcpy(sx->str, str, len); + + s->string_list = sx; + + if (((s->flags & ASL_FILE_FLAG_UNLIMITED_CACHE) == 0) && (s->string_count == CACHE_SIZE)) + { + /* drop last (lru) string from cache */ + sp = s->string_list; + sx = sp->next; + + /* NB CACHE_SIZE must be > 1 */ + while (sx->next != NULL) + { + sp = sx; + sx = sx->next; + } + + sp->next = NULL; + free(sx); + } + else + { + s->string_count++; + } + + *out = off; + return ASL_STATUS_OK; +} + +/* + * Encode an aslmsg as a record structure. + * Creates and caches strings. + */ +uint32_t +asl_file_save(asl_file_t *s, aslmsg msg, uint64_t *mid) +{ + char *buf, *p; + uint32_t len, i, status; + file_record_t r; + uint64_t k, v; + uint64_t *kvlist; + off_t off; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (msg == NULL) return ASL_STATUS_INVALID_MESSAGE; + + if (s->flags & ASL_FILE_FLAG_READ_ONLY) return ASL_STATUS_READ_ONLY; + + memset(&r, 0, sizeof(file_record_t)); + + r.flags = 0; + r.level = ASL_LEVEL_DEBUG; + r.pid = -1; + r.uid = -2; + r.gid = -2; + r.ruid = -1; + r.rgid = -1; + r.time = 0; + r.nano = 0; + r.prev = s->prev; + kvlist = NULL; + + for (i = 0; i < msg->count; i++) + { + if (msg->key[i] == NULL) + { + continue; + } + else if (!strcmp(msg->key[i], ASL_KEY_TIME)) + { + if (msg->val[i] != NULL) r.time = asl_parse_time(msg->val[i]); + } + else if (!strcmp(msg->key[i], ASL_KEY_TIME_NSEC)) + { + if (msg->val[i] != NULL) r.nano = atoi(msg->val[i]); + } + else if (!strcmp(msg->key[i], ASL_KEY_HOST)) + { + if (msg->val[i] != NULL) + { + status = asl_file_string_encode(s, msg->val[i], &(r.host)); + if (status != ASL_STATUS_OK) + { + if (kvlist != NULL) free(kvlist); + return status; + } + } + } + else if (!strcmp(msg->key[i], ASL_KEY_SENDER)) + { + if (msg->val[i] != NULL) + { + status = asl_file_string_encode(s, msg->val[i], &(r.sender)); + if (status != ASL_STATUS_OK) + { + if (kvlist != NULL) free(kvlist); + return status; + } + } + } + else if (!strcmp(msg->key[i], ASL_KEY_PID)) + { + if (msg->val[i] != NULL) r.pid = atoi(msg->val[i]); + } + else if (!strcmp(msg->key[i], ASL_KEY_REF_PID)) + { + if (msg->val[i] != NULL) r.refpid = atoi(msg->val[i]); + } + else if (!strcmp(msg->key[i], ASL_KEY_UID)) + { + if (msg->val[i] != NULL) r.uid = atoi(msg->val[i]); + } + else if (!strcmp(msg->key[i], ASL_KEY_GID)) + { + if (msg->val[i] != NULL) r.gid = atoi(msg->val[i]); + } + else if (!strcmp(msg->key[i], ASL_KEY_LEVEL)) + { + if (msg->val[i] != NULL) r.level = atoi(msg->val[i]); + } + else if (!strcmp(msg->key[i], ASL_KEY_MSG)) + { + if (msg->val[i] != NULL) + { + status = asl_file_string_encode(s, msg->val[i], &(r.message)); + if (status != ASL_STATUS_OK) + { + if (kvlist != NULL) free(kvlist); + return status; + } + } + } + else if (!strcmp(msg->key[i], ASL_KEY_FACILITY)) + { + if (msg->val[i] != NULL) + { + status = asl_file_string_encode(s, msg->val[i], &(r.facility)); + if (status != ASL_STATUS_OK) + { + if (kvlist != NULL) free(kvlist); + return status; + } + } + } + else if (!strcmp(msg->key[i], ASL_KEY_REF_PROC)) + { + if (msg->val[i] != NULL) + { + status = asl_file_string_encode(s, msg->val[i], &(r.refproc)); + if (status != ASL_STATUS_OK) + { + if (kvlist != NULL) free(kvlist); + return status; + } + } + } + else if (!strcmp(msg->key[i], ASL_KEY_SESSION)) + { + if (msg->val[i] != NULL) + { + status = asl_file_string_encode(s, msg->val[i], &(r.session)); + if (status != ASL_STATUS_OK) + { + if (kvlist != NULL) free(kvlist); + return status; + } + } + } + else if (!strcmp(msg->key[i], ASL_KEY_READ_UID)) + { + if (((r.flags & ASL_MSG_FLAG_READ_UID_SET) == 0) && (msg->val[i] != NULL)) + { + r.ruid = atoi(msg->val[i]); + r.flags |= ASL_MSG_FLAG_READ_UID_SET; + } + } + else if (!strcmp(msg->key[i], ASL_KEY_READ_GID)) + { + if (((r.flags & ASL_MSG_FLAG_READ_GID_SET) == 0) && (msg->val[i] != NULL)) + { + r.rgid = atoi(msg->val[i]); + r.flags |= ASL_MSG_FLAG_READ_GID_SET; + } + } + else if (!strcmp(msg->key[i], ASL_KEY_MSG_ID)) + { + if (s->flags & ASL_FILE_FLAG_PRESERVE_MSG_ID) *mid = atoll(msg->val[i]); + } + else + { + status = asl_file_string_encode(s, msg->key[i], &k); + if (status != ASL_STATUS_OK) + { + if (kvlist != NULL) free(kvlist); + return status; + } + + v = 0; + if (msg->val[i] != NULL) + { + status = asl_file_string_encode(s, msg->val[i], &v); + if (status != ASL_STATUS_OK) + { + if (kvlist != NULL) free(kvlist); + return status; + } + } + + if (r.kvcount == 0) + { + kvlist = (uint64_t *)calloc(2, sizeof(uint64_t)); + } + else + { + kvlist = (uint64_t *)reallocf(kvlist, (r.kvcount + 2) * sizeof(uint64_t)); + } + + if (kvlist == NULL) + { + return ASL_STATUS_NO_MEMORY; + } + + kvlist[r.kvcount++] = k; + kvlist[r.kvcount++] = v; + } + } + + len = MSG_RECORD_FIXED_LENGTH + (r.kvcount * sizeof(uint64_t)); + buf = NULL; + + /* use the scratch buffer if it exists and is large enough */ + if ((s->scratch != NULL) && (len <= SCRATCH_BUFFER_SIZE)) + { + memset(s->scratch, 0, SCRATCH_BUFFER_SIZE); + buf = s->scratch; + } + else + { + buf = calloc(1, len); + } + + if (buf == NULL) return ASL_STATUS_NO_MEMORY; + + if (*mid != 0) + { + r.mid = *mid; + } + else + { + r.mid = asl_core_new_msg_id(0); + *mid = r.mid; + } + + p = buf; + + /* Type */ + _asl_put_16(ASL_FILE_TYPE_MSG, p); + p += sizeof(uint16_t); + + /* Length of message (excludes type and length fields) */ + _asl_put_32(len - RECORD_COMMON_LEN, p); + p += sizeof(uint32_t); + + /* Message data... */ + + _asl_put_64(r.next, p); + p += sizeof(uint64_t); + + _asl_put_64(r.mid, p); + p += sizeof(uint64_t); + + _asl_put_64(r.time, p); + p += sizeof(uint64_t); + + _asl_put_32(r.nano, p); + p += sizeof(uint32_t); + + _asl_put_16(r.level, p); + p += sizeof(uint16_t); + + _asl_put_16(r.flags, p); + p += sizeof(uint16_t); + + _asl_put_32(r.pid, p); + p += sizeof(uint32_t); + + _asl_put_32(r.uid, p); + p += sizeof(uint32_t); + + _asl_put_32(r.gid, p); + p += sizeof(uint32_t); + + _asl_put_32(r.ruid, p); + p += sizeof(uint32_t); + + _asl_put_32(r.rgid, p); + p += sizeof(uint32_t); + + _asl_put_32(r.refpid, p); + p += sizeof(uint32_t); + + _asl_put_32(r.kvcount, p); + p += sizeof(uint32_t); + + _asl_put_64(r.host, p); + p += sizeof(uint64_t); + + _asl_put_64(r.sender, p); + p += sizeof(uint64_t); + + _asl_put_64(r.facility, p); + p += sizeof(uint64_t); + + _asl_put_64(r.message, p); + p += sizeof(uint64_t); + + _asl_put_64(r.refproc, p); + p += sizeof(uint64_t); + + _asl_put_64(r.session, p); + p += sizeof(uint64_t); + + for (i = 0; i < r.kvcount; i++) + { + _asl_put_64(kvlist[i], p); + p += sizeof(uint64_t); + } + + _asl_put_64(r.prev, p); + p += sizeof(uint64_t); + + free(kvlist); + kvlist = NULL; + + if (status != 0) return ASL_STATUS_WRITE_FAILED; + + /* write record at end of file */ + status = fseeko(s->store, 0, SEEK_END); + if (status != 0) return ASL_STATUS_WRITE_FAILED; + + s->last = (uint64_t)ftello(s->store); + v = asl_core_htonq(s->last); + + status = fwrite(buf, len, 1, s->store); + fflush(s->store); + + /* free the buffer if it was allocated here */ + if (buf != s->scratch) free(buf); + + /* seek to "next" field of previous record, write last offset */ + off = s->prev + RECORD_COMMON_LEN; + if (s->prev == 0) off = DB_HEADER_FIRST_OFFSET; + + status = fseeko(s->store, off, SEEK_SET); + if (status != 0) return ASL_STATUS_WRITE_FAILED; + + status = fwrite(&v, sizeof(uint64_t), 1, s->store); + if (status != 1) return ASL_STATUS_WRITE_FAILED; + + /* seek to DB_HEADER_LAST_OFFSET, write last record offset */ + off = DB_HEADER_LAST_OFFSET; + + status = fseeko(s->store, off, SEEK_SET); + if (status != 0) return ASL_STATUS_WRITE_FAILED; + + status = fwrite(&v, sizeof(uint64_t), 1, s->store); + if (status != 1) return ASL_STATUS_WRITE_FAILED; + + /* return to the end of the store (this is expected by other routines) */ + status = fseeko(s->store, 0, SEEK_END); + if (status != 0) return ASL_STATUS_WRITE_FAILED; + + s->prev = s->last; + + return ASL_STATUS_OK; +} + +static uint32_t +asl_file_fetch_object(asl_file_t *s, uint64_t where, char **out) +{ + static char ils[9]; + char *p; + uint32_t len; + int status; + uint64_t x64; + uint8_t inls; + uint16_t type; + off_t off; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (out == NULL) return ASL_STATUS_INVALID_ARG; + if (where == 0) return ASL_STATUS_INVALID_ARG; + + *out = NULL; + + inls = 0; + x64 = asl_core_htonq(where); + memcpy(&inls, &x64, 1); + if (inls & 0x80) + { + /* inline string */ + memset(ils, 0, sizeof(ils)); + inls &= 0x0f; + p = 1 + (char *)&x64; + memcpy(ils, p, inls); + *out = strdup(ils); + + if (*out == NULL) return ASL_STATUS_NO_MEMORY; + return ASL_STATUS_OK; + } + + off = where; + status = fseeko(s->store, off, SEEK_SET); + if (status != 0) return ASL_STATUS_READ_FAILED; + + /* Type */ + status = fread(&type, sizeof(uint16_t), 1, s->store); + if (status != 1) return ASL_STATUS_READ_FAILED; + + /* Length */ + len = 0; + status = fread(&len, sizeof(uint32_t), 1, s->store); + if (status != 1) return ASL_STATUS_READ_FAILED; + len = ntohl(len); + + *out = calloc(1, len); + if (*out == NULL) return ASL_STATUS_NO_MEMORY; + + status = fread(*out, len, 1, s->store); + if (status != 1) + { + free(*out); + return ASL_STATUS_READ_FAILED; + } + + return ASL_STATUS_OK; +} + +static uint16_t +asl_file_fetch_helper_16(asl_file_t *s, char **p, aslmsg m, const char *key) +{ + uint16_t out; + char str[256]; + + out = _asl_get_16(*p); + *p += sizeof(uint16_t); + + if ((m == NULL) || (key == NULL)) return out; + + snprintf(str, sizeof(str), "%hu", out); + asl_set(m, key, str); + + return out; +} + +static uint32_t +asl_file_fetch_helper_32(asl_file_t *s, char **p, aslmsg m, const char *key, int ignore, uint32_t ignoreval) +{ + uint32_t out, doit; + char str[256]; + + out = _asl_get_32(*p); + *p += sizeof(uint32_t); + + if ((m == NULL) || (key == NULL)) return out; + + doit = 1; + if ((ignore != 0) && (out == ignoreval)) doit = 0; + if (doit != 0) + { + snprintf(str, sizeof(str), "%u", out); + asl_set(m, key, str); + } + + return out; +} + +static uint64_t +asl_file_fetch_helper_64(asl_file_t *s, char **p, aslmsg m, const char *key) +{ + uint64_t out; + char str[256]; + + out = _asl_get_64(*p); + *p += sizeof(uint64_t); + + if ((m == NULL) || (key == NULL)) return out; + + snprintf(str, sizeof(str), "%llu", out); + asl_set(m, key, str); + + return out; +} + +static uint64_t +asl_file_fetch_helper_str(asl_file_t *s, char **p, aslmsg m, const char *key) +{ + uint64_t out; + char *val; + uint32_t status; + + out = _asl_get_64(*p); + *p += sizeof(uint64_t); + + val = NULL; + status = asl_file_fetch_object(s, out, &val); + if ((status == ASL_STATUS_OK) && (val != NULL)) + { + asl_set(m, key, val); + free(val); + } + + return out; +} + +static uint32_t +asl_file_fetch_pos(asl_file_t *s, uint64_t where, int dir, aslmsg *msg) +{ + char *buf, *p, *k, *v; + file_record_t r; + uint32_t i, status; + uint64_t x64, kv; + aslmsg out; + off_t off; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (msg == NULL) return ASL_STATUS_INVALID_ARG; + if ((s->flags & ASL_FILE_FLAG_READ_ONLY) == 0) return ASL_STATUS_WRITE_ONLY; + + buf = NULL; + status = asl_file_fetch_object(s, where, &buf); + if (buf == NULL) return status; + + out = asl_new(ASL_TYPE_MSG); + if (out == NULL) return ASL_STATUS_NO_MEMORY; + + memset(&r, 0, sizeof(file_record_t)); + p = buf; + + r.next = asl_file_fetch_helper_64(s, &p, NULL, NULL); + r.mid = asl_file_fetch_helper_64(s, &p, out, ASL_KEY_MSG_ID); + r.time = asl_file_fetch_helper_64(s, &p, out, ASL_KEY_TIME); + r.nano = asl_file_fetch_helper_32(s, &p, out, ASL_KEY_TIME_NSEC, 0, 0); + r.level = asl_file_fetch_helper_16(s, &p, out, ASL_KEY_LEVEL); + r.flags = asl_file_fetch_helper_16(s, &p, NULL, NULL); + r.pid = asl_file_fetch_helper_32(s, &p, out, ASL_KEY_PID, 0, 0); + r.uid = asl_file_fetch_helper_32(s, &p, out, ASL_KEY_UID, 1, (uint32_t)-1); + r.gid = asl_file_fetch_helper_32(s, &p, out, ASL_KEY_GID, 1, (uint32_t)-1); + r.ruid = asl_file_fetch_helper_32(s, &p, out, ASL_KEY_READ_UID, 1, (uint32_t)-1); + r.rgid = asl_file_fetch_helper_32(s, &p, out, ASL_KEY_READ_GID, 1, (uint32_t)-1); + r.refpid = asl_file_fetch_helper_32(s, &p, out, ASL_KEY_REF_PID, 1, 0); + r.kvcount = asl_file_fetch_helper_32(s, &p, NULL, NULL, 0, 0); + r.host = asl_file_fetch_helper_str(s, &p, out, ASL_KEY_HOST); + r.sender = asl_file_fetch_helper_str(s, &p, out, ASL_KEY_SENDER); + r.facility = asl_file_fetch_helper_str(s, &p, out, ASL_KEY_FACILITY); + r.message = asl_file_fetch_helper_str(s, &p, out, ASL_KEY_MSG); + r.refproc = asl_file_fetch_helper_str(s, &p, out, ASL_KEY_REF_PROC); + r.session = asl_file_fetch_helper_str(s, &p, out, ASL_KEY_SESSION); + + for (i = 0; i < r.kvcount / 2; i++) + { + kv = _asl_get_64(p); + p += sizeof(uint64_t); + k = NULL; + status = asl_file_fetch_object(s, kv, &k); + + kv = _asl_get_64(p); + p += sizeof(uint64_t); + v = NULL; + status = asl_file_fetch_object(s, kv, &v); + + if ((status == ASL_STATUS_OK) && (k != NULL)) + { + asl_set(out, k, v); + if (v != NULL) free(v); + free(k); + } + } + + r.prev = asl_file_fetch_helper_64(s, &p, NULL, NULL); + + free(buf); + + if (dir >= 0) s->cursor = r.next; + else s->cursor = r.prev; + + s->cursor_xid = 0; + + if (s->cursor != 0) + { + off = s->cursor + RECORD_COMMON_LEN + sizeof(uint64_t); + status = fseeko(s->store, off, SEEK_SET); + if (status != 0) return ASL_STATUS_READ_FAILED; + + status = fread(&x64, sizeof(uint64_t), 1, s->store); + if (status != 1) return ASL_STATUS_READ_FAILED; + + s->cursor_xid = asl_core_ntohq(x64); + } + + *msg = out; + return ASL_STATUS_OK; +} + +uint32_t +asl_file_open_read(const char *path, asl_file_t **s) +{ + asl_file_t *out; + FILE *f; + int i; + uint32_t status, vers; + char buf[DB_HEADER_LEN]; + off_t off; + asl_legacy1_t *legacy; + + f = fopen(path, "r"); + if (f == NULL) + { + if (errno == EACCES) return ASL_STATUS_ACCESS_DENIED; + return ASL_STATUS_FAILED; + } + + i = fread(buf, DB_HEADER_LEN, 1, f); + if (i < 1) + { + fclose(f); + return ASL_STATUS_INVALID_STORE; + } + + /* validate header */ + if (strncmp(buf, ASL_DB_COOKIE, ASL_DB_COOKIE_LEN)) + { + fclose(f); + return ASL_STATUS_INVALID_STORE; + } + + legacy = NULL; + + vers = _asl_get_32(buf + DB_HEADER_VERS_OFFSET); + if (vers == DB_VERSION_LEGACY_1) + { + fclose(f); + status = asl_legacy1_open(path, &legacy); + if (status != ASL_STATUS_OK) return status; + } + + out = (asl_file_t *)calloc(1, sizeof(asl_file_t)); + if (out == NULL) + { + fclose(f); + return ASL_STATUS_NO_MEMORY; + } + + out->flags = ASL_FILE_FLAG_READ_ONLY; + out->version = vers; + + if (legacy != NULL) + { + out->flags |= ASL_FILE_FLAG_LEGACY_STORE; + out->legacy = (void *)legacy; + + *s = out; + return ASL_STATUS_OK; + } + + out->first = _asl_get_64(buf + DB_HEADER_FIRST_OFFSET); + out->last = _asl_get_64(buf + DB_HEADER_LAST_OFFSET); + + out->store = f; + + out->cursor = out->first; + if (out->cursor != 0) + { + off = out->cursor + RECORD_COMMON_LEN + sizeof(uint64_t); + status = asl_file_read_uint64(out, off, &(out->cursor_xid)); + if (status != ASL_STATUS_OK) + { + fclose(f); + return status; + } + } + + *s = out; + return ASL_STATUS_OK; +} + +static uint32_t +asl_file_read_set_position_first(asl_file_t *s) +{ + uint32_t status; + off_t off; + + s->cursor = s->first; + s->cursor_xid = 0; + + if (s->cursor == 0) return ASL_STATUS_OK; + + /* read ID of the first record */ + off = s->cursor + RECORD_COMMON_LEN + sizeof(uint64_t); + status = asl_file_read_uint64(s, off, &(s->cursor_xid)); + return status; +} + +static uint32_t +asl_file_read_set_position_last(asl_file_t *s) +{ + uint64_t next; + uint32_t status; + off_t off; + + /* + * If the file has the offset of the last record, we just go there. + * The last record offset was added to improve performance, so it may + * or may not be there. If we don't have the last record offset, we + * just iterate down the record links to find the last one. + * + * Note that s->last may be zero if the file is empty. + */ + + if (s->last != 0) + { + s->cursor = s->last; + off = s->last + RECORD_COMMON_LEN + sizeof(uint64_t); + + /* read ID of the last record */ + status = asl_file_read_uint64(s, off, &(s->cursor_xid)); + return status; + } + + /* start at the first record and iterate */ + s->cursor = s->first; + s->cursor_xid = 0; + + forever + { + off = s->cursor + RECORD_COMMON_LEN; + next = 0; + + /* read next offset */ + status = asl_file_read_uint64(s, off, &next); + if (status != ASL_STATUS_OK) return status; + + if (next == 0) + { + if (s->cursor == 0) return ASL_STATUS_OK; + + off = s->cursor + RECORD_COMMON_LEN + sizeof(uint64_t); + status = asl_file_read_uint64(s, off, &(s->cursor_xid)); + return ASL_STATUS_OK; + } + + s->cursor = next; + } +} + +uint32_t +asl_file_read_set_position(asl_file_t *s, uint32_t pos) +{ + uint32_t len, status; + off_t off; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (s->version == 1) return ASL_STATUS_FAILED; + + if (pos == ASL_FILE_POSITION_FIRST) return asl_file_read_set_position_first(s); + if (pos == ASL_FILE_POSITION_LAST) return asl_file_read_set_position_last(s); + + off = 0; + + if (pos == ASL_FILE_POSITION_PREVIOUS) + { + if (s->cursor == s->first) return ASL_STATUS_NO_RECORDS; + if (s->cursor == 0) return ASL_STATUS_NO_RECORDS; + + off = s->cursor + RECORD_TYPE_LEN; + status = asl_file_read_uint32(s, off, &len); + if (status != ASL_STATUS_OK) return status; + + /* set offset to read the "previous" field at the end of the record */ + off = s->cursor + RECORD_COMMON_LEN + len - sizeof(uint64_t); + } + else if (pos == ASL_FILE_POSITION_NEXT) + { + if (s->cursor == s->last) return ASL_STATUS_NO_RECORDS; + if (s->cursor == 0) return ASL_STATUS_NO_RECORDS; + + off = s->cursor + RECORD_COMMON_LEN; + } + else return ASL_STATUS_INVALID_ARG; + + s->cursor_xid = 0; + + /* + * read offset of next / previous + */ + status = asl_file_read_uint64(s, off, &(s->cursor)); + if (status != ASL_STATUS_OK) return ASL_STATUS_READ_FAILED; + + if (s->cursor == 0) return ASL_STATUS_NO_RECORDS; + + /* read ID of the record */ + off = s->cursor + RECORD_COMMON_LEN + sizeof(uint64_t); + status = asl_file_read_uint64(s, off, &(s->cursor_xid)); + return status; +} + +uint32_t +asl_file_fetch_next(asl_file_t *s, aslmsg *msg) +{ + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (s->version == 1) return ASL_STATUS_FAILED; + + return asl_file_fetch_pos(s, s->cursor, 1, msg); +} + +uint32_t +asl_file_fetch_previous(asl_file_t *s, aslmsg *msg) +{ + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (s->version == 1) return ASL_STATUS_FAILED; + + return asl_file_fetch_pos(s, s->cursor, -1, msg); +} + +uint32_t +asl_file_fetch(asl_file_t *s, uint64_t mid, aslmsg *msg) +{ + uint32_t status; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (msg == NULL) return ASL_STATUS_INVALID_ARG; + if ((s->flags & ASL_FILE_FLAG_READ_ONLY) == 0) return ASL_STATUS_WRITE_ONLY; + + if (s->version == 1) + { + return asl_legacy1_fetch((asl_legacy1_t *)s->legacy, mid, msg); + } + + if (s->cursor_xid == 0) + { + status = asl_file_read_set_position(s, ASL_FILE_POSITION_FIRST); + if (status != ASL_STATUS_OK) return status; + if (s->cursor_xid == 0) return ASL_STATUS_INVALID_ID; + } + + while (s->cursor_xid < mid) + { + status = asl_file_read_set_position(s, ASL_FILE_POSITION_NEXT); + if (status != ASL_STATUS_OK) return status; + if (s->cursor_xid > mid) return ASL_STATUS_INVALID_ID; + if (s->cursor_xid == 0) return ASL_STATUS_INVALID_ID; + } + + while (s->cursor_xid > mid) + { + status = asl_file_read_set_position(s, ASL_FILE_POSITION_PREVIOUS); + if (status != ASL_STATUS_OK) return status; + if (s->cursor_xid < mid) return ASL_STATUS_INVALID_ID; + if (s->cursor_xid == 0) return ASL_STATUS_INVALID_ID; + } + + if (s->cursor_xid != mid) return ASL_STATUS_INVALID_ID; + + return asl_file_fetch_pos(s, s->cursor, 1, msg); +} + +uint64_t +asl_file_cursor(asl_file_t *s) +{ + if (s == NULL) return 0; + if ((s->flags & ASL_FILE_FLAG_READ_ONLY) == 0) return 0; + if (s->version == 1) return 0; + + return s->cursor_xid; +} + +uint32_t +asl_file_match_start(asl_file_t *s, uint64_t start_id, int32_t direction) +{ + uint32_t status, d; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (s->version == 1) return ASL_STATUS_INVALID_STORE; + if ((s->flags & ASL_FILE_FLAG_READ_ONLY) == 0) return ASL_STATUS_WRITE_ONLY; + + d = ASL_FILE_POSITION_NEXT; + if (direction < 0) d = ASL_FILE_POSITION_PREVIOUS; + + /* + * find starting point + */ + status = ASL_STATUS_OK; + if (direction >= 0) status = asl_file_read_set_position(s, ASL_FILE_POSITION_FIRST); + else status = asl_file_read_set_position(s, ASL_FILE_POSITION_LAST); + if (status != ASL_STATUS_OK) return status; + + while ((status == ASL_STATUS_OK) && (((direction >= 0) && (s->cursor_xid < start_id)) || ((direction < 0) && (s->cursor_xid > start_id)))) + { + status = asl_file_read_set_position(s, d); + } + + return status; +} + +uint32_t +asl_file_match_next(asl_file_t *s, aslresponse query, asl_msg_t **msg, uint64_t *last_id, int32_t direction) +{ + uint32_t status, d, i, do_match, did_match; + aslmsg m; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (msg == NULL) return ASL_STATUS_INVALID_ARG; + if (s->version == 1) return ASL_STATUS_INVALID_STORE; + if ((s->flags & ASL_FILE_FLAG_READ_ONLY) == 0) return ASL_STATUS_WRITE_ONLY; + if (s->cursor == 0) return ASL_STATUS_NO_RECORDS; + + *msg = NULL; + do_match = 1; + + d = ASL_FILE_POSITION_NEXT; + if (direction < 0) d = ASL_FILE_POSITION_PREVIOUS; + + if ((query == NULL) || ((query != NULL) && (query->count == 0))) do_match = 0; + + m = NULL; + + *last_id = s->cursor_xid; + + status = asl_file_fetch_pos(s, s->cursor, direction, &m); + if (status == ASL_STATUS_ACCESS_DENIED) return ASL_STATUS_MATCH_FAILED; + if ((status == ASL_STATUS_INVALID_ARG) && (s->cursor == 0)) return ASL_STATUS_NO_RECORDS; + if (status != ASL_STATUS_OK) return status; + + did_match = 1; + + if (do_match != 0) + { + did_match = 0; + + for (i = 0; (i < query->count) && (did_match == 0); i++) + { + did_match = asl_msg_cmp(query->msg[i], m); + } + } + + if (did_match != 0) + { + *msg = m; + return ASL_STATUS_OK; + } + + asl_free(m); + return ASL_STATUS_MATCH_FAILED; +} + +uint32_t +asl_file_match(asl_file_t *s, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction) +{ + uint32_t status, d, i, do_match, did_match, rescount; + asl_msg_t *m; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (res == NULL) return ASL_STATUS_INVALID_ARG; + if ((s->flags & ASL_FILE_FLAG_READ_ONLY) == 0) return ASL_STATUS_WRITE_ONLY; + + if (s->version == 1) + { + return asl_legacy1_match((asl_legacy1_t *)s->legacy, query, res, last_id, start_id, count, direction); + } + + do_match = 1; + rescount = 0; + + d = ASL_FILE_POSITION_NEXT; + if (direction < 0) d = ASL_FILE_POSITION_PREVIOUS; + + if ((query == NULL) || ((query != NULL) && (query->count == 0))) do_match = 0; + + /* + * find starting point + */ + status = ASL_STATUS_OK; + if (direction >= 0) status = asl_file_read_set_position(s, ASL_FILE_POSITION_FIRST); + else status = asl_file_read_set_position(s, ASL_FILE_POSITION_LAST); + if (status != ASL_STATUS_OK) return status; + + while ((status == ASL_STATUS_OK) && (((direction >= 0) && (s->cursor_xid < start_id)) || ((direction < 0) && (s->cursor_xid > start_id)))) + { + status = asl_file_read_set_position(s, d); + } + + /* + * loop through records + */ + forever + { + m = NULL; + status = asl_file_fetch_pos(s, s->cursor, direction, &m); + if (status == ASL_STATUS_ACCESS_DENIED) continue; + if (status != ASL_STATUS_OK) break; + + *last_id = s->cursor_xid; + + did_match = 1; + + if (do_match != 0) + { + did_match = 0; + + for (i = 0; (i < query->count) && (did_match == 0); i++) + { + did_match = asl_msg_cmp(query->msg[i], m); + } + } + + if (did_match == 1) + { + /* append m to res */ + if (*res == NULL) + { + *res = (aslresponse)calloc(1, sizeof(aslresponse)); + if (*res == NULL) return ASL_STATUS_NO_MEMORY; + (*res)->msg = (asl_msg_t **)calloc(1, sizeof(asl_msg_t *)); + if ((*res)->msg == NULL) + { + free(*res); + return ASL_STATUS_NO_MEMORY; + } + } + else + { + (*res)->msg = (asl_msg_t **)realloc((*res)->msg, ((*res)->count + 1) * sizeof(asl_msg_t *)); + if ((*res)->msg == NULL) + { + free(*res); + return ASL_STATUS_NO_MEMORY; + } + } + + (*res)->msg[(*res)->count] = m; + (*res)->count++; + + rescount++; + if ((count != 0) && (rescount >= count)) break; + } + else + { + asl_free(m); + } + } + + /* NOT REACHED */ + return ASL_STATUS_OK; +} + +size_t +asl_file_size(asl_file_t *s) +{ + if (s == NULL) return 0; + return s->file_size; +} + +uint64_t +asl_file_ctime(asl_file_t *s) +{ + if (s == NULL) return 0; + return s->dob; +} + +void +asl_file_list_close(asl_file_list_t *head) +{ + asl_file_list_t *next; + + while (head != NULL) + { + next = head->next; + asl_file_close(head->file); + free(head); + head = next; + } +} + +static void +asl_file_list_free(asl_file_list_t *head) +{ + asl_file_list_t *next; + + while (head != NULL) + { + next = head->next; + free(head); + head = next; + } +} + +asl_file_list_t * +asl_file_list_insert(asl_file_list_t *list, asl_file_t *f, int32_t dir) +{ + asl_file_list_t *a, *b, *tmp; + + if (f == NULL) return list; + + tmp = (asl_file_list_t *)calloc(1, sizeof(asl_file_list_t)); + if (tmp == NULL) return NULL; + tmp->file = f; + + if (list == NULL) return tmp; + + a = list; + if (((dir < 0) && (f->cursor_xid > a->file->cursor_xid)) || ((dir >= 0) && (f->cursor_xid < a->file->cursor_xid))) + { + tmp->next = list; + return tmp; + } + + b = a->next; + while (b != NULL) + { + if (((dir < 0) && (f->cursor_xid > b->file->cursor_xid)) || ((dir >= 0) && (f->cursor_xid < b->file->cursor_xid))) + { + tmp->next = b; + a->next = tmp; + return list; + } + + a = b; + b = a->next; + } + + a->next = tmp; + return list; +} + +asl_file_list_t * +asl_file_list_add(asl_file_list_t *list, asl_file_t *f) +{ + asl_file_list_t *tmp; + + if (f == NULL) return list; + if (f->version == 1) return list; + + tmp = (asl_file_list_t *)calloc(1, sizeof(asl_file_list_t)); + if (tmp == NULL) return NULL; + tmp->file = f; + + tmp->next = list; + return tmp; +} + +void * +asl_file_list_match_start(asl_file_list_t *list, uint64_t start_id, int32_t direction) +{ + uint32_t status; + asl_file_list_t *n; + asl_file_match_token_t *out; + + if (list == NULL) return NULL; + + out = (asl_file_match_token_t *)calloc(1, sizeof(asl_file_match_token_t)); + if (out == NULL) return NULL; + + for (n = list; n != NULL; n = n->next) + { + /* init file for the search */ + status = asl_file_match_start(n->file, start_id, direction); + if (status != ASL_STATUS_OK) continue; + if (n->file->cursor_xid == 0) continue; + + out->list = asl_file_list_insert(out->list, n->file, direction); + } + + out->dir = direction; + return out; +} + +uint32_t +asl_file_list_match_next(void *token, aslresponse query, aslresponse *res, uint32_t count) +{ + uint32_t status, rescount; + asl_file_list_t *n; + asl_msg_t *m; + asl_file_match_token_t *work; + uint64_t last_id; + + if (token == NULL) return ASL_STATUS_OK; + if (res == NULL) return ASL_STATUS_INVALID_ARG; + + work = (asl_file_match_token_t *)token; + + rescount = 0; + last_id = 0; + + while ((work->list != NULL) && ((rescount < count) || (count == 0))) + { + m = NULL; + status = asl_file_match_next(work->list->file, query, &m, &last_id, work->dir); + if (m != NULL) + { + if (*res == NULL) *res = (aslresponse)calloc(1, sizeof(asl_search_result_t)); + if (*res == NULL) + { + asl_file_list_free(work->list); + work->list = NULL; + return ASL_STATUS_NO_MEMORY; + } + + if ((*res)->msg == NULL) (*res)->msg = (asl_msg_t **)calloc(1, sizeof(asl_msg_t *)); + else (*res)->msg = (asl_msg_t **)reallocf((*res)->msg, ((*res)->count + 1) * sizeof(asl_msg_t *)); + if ((*res)->msg == NULL) + { + free(*res); + *res = NULL; + asl_file_list_free(work->list); + work->list = NULL; + return ASL_STATUS_NO_MEMORY; + } + + (*res)->msg[(*res)->count] = m; + (*res)->count++; + rescount++; + } + + if (work->list->file->cursor_xid == 0) + { + n = work->list->next; + free(work->list); + work->list = n; + } + + if (work->list != NULL) + { + n = work->list->next; + if (n != NULL) + { + if (((work->dir < 0) && (work->list->file->cursor_xid <= n->file->cursor_xid)) || ((work->dir >= 0) && (work->list->file->cursor_xid > n->file->cursor_xid))) + { + n = work->list; + work->list = work->list->next; + n->next = NULL; + work->list = asl_file_list_insert(work->list, n->file, work->dir); + free(n); + } + } + } + } + + return ASL_STATUS_OK; +} + +void +asl_file_list_match_end(void *token) +{ + asl_file_match_token_t *work; + + if (token == NULL) return; + + work = (asl_file_match_token_t *)token; + asl_file_list_free(work->list); + work->list = NULL; + + free(token); +} + +uint32_t +asl_file_list_match_timeout(asl_file_list_t *list, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction, uint32_t usec) +{ + uint32_t status, rescount; + asl_file_list_t *files, *n; + asl_msg_t *m; + struct timeval now, finish; + + if (list == NULL) return ASL_STATUS_INVALID_ARG; + if (res == NULL) return ASL_STATUS_INVALID_ARG; + if (last_id == NULL) return ASL_STATUS_INVALID_ARG; + + files = NULL; + + for (n = list; n != NULL; n = n->next) + { + /* init file for the search */ + status = asl_file_match_start(n->file, start_id, direction); + if (status != ASL_STATUS_OK) continue; + if (n->file->cursor_xid == 0) continue; + + files = asl_file_list_insert(files, n->file, direction); + } + + if (files == NULL) + { + asl_file_list_free(files); + return ASL_STATUS_OK; + } + + /* start the timer if a timeout was specified */ + memset(&finish, 0, sizeof(struct timeval)); + if (usec != 0) + { + if (gettimeofday(&finish, NULL) == 0) + { + finish.tv_sec += (usec / MILLION); + finish.tv_usec += (usec % MILLION); + if (finish.tv_usec > MILLION) + { + finish.tv_usec -= MILLION; + finish.tv_sec += 1; + } + } + else + { + /* shouldn't happen, but if gettimeofday failed we just run without a timeout */ + memset(&finish, 0, sizeof(struct timeval)); + } + } + + rescount = 0; + while ((files != NULL) && ((rescount < count) || (count == 0))) + { + m = NULL; + status = asl_file_match_next(files->file, query, &m, last_id, direction); + if (m != NULL) + { + if (*res == NULL) *res = (aslresponse)calloc(1, sizeof(asl_search_result_t)); + if (*res == NULL) + { + asl_file_list_free(files); + return ASL_STATUS_NO_MEMORY; + } + + if ((*res)->msg == NULL) (*res)->msg = (asl_msg_t **)calloc(1, sizeof(asl_msg_t *)); + else (*res)->msg = (asl_msg_t **)reallocf((*res)->msg, ((*res)->count + 1) * sizeof(asl_msg_t *)); + if ((*res)->msg == NULL) + { + free(*res); + *res = NULL; + asl_file_list_free(files); + return ASL_STATUS_NO_MEMORY; + } + + (*res)->msg[(*res)->count] = m; + (*res)->count++; + rescount++; + } + + if (files->file->cursor_xid == 0) + { + n = files->next; + free(files); + files = n; + } + + if (files != NULL) + { + n = files->next; + if (n != NULL) + { + if (((direction < 0) && (files->file->cursor_xid <= n->file->cursor_xid)) || ((direction >= 0) && (files->file->cursor_xid > n->file->cursor_xid))) + { + n = files; + files = files->next; + n->next = NULL; + files = asl_file_list_insert(files, n->file, direction); + free(n); + } + } + } + + /* check the timer */ + if ((finish.tv_sec != 0) && (gettimeofday(&now, NULL) == 0)) + { + if ((now.tv_sec > finish.tv_sec) || ((now.tv_sec == finish.tv_sec) && (now.tv_usec > finish.tv_usec))) break; + } + } + + asl_file_list_free(files); + return ASL_STATUS_OK; +} + +uint32_t +asl_file_list_match(asl_file_list_t *list, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction) +{ + return asl_file_list_match_timeout(list, query, res, last_id, start_id, count, direction, 0); +} diff --git a/gen/asl_file.h b/gen/asl_file.h new file mode 100644 index 0000000..3953d11 --- /dev/null +++ b/gen/asl_file.h @@ -0,0 +1,150 @@ +#ifndef __ASL_FILE_H__ +#define __ASL_FILE_H__ + +/* + * Copyright (c) 2007-2008 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2007 Apple Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include +#include +#include + +#define DB_HEADER_LEN 80 +#define DB_HEADER_COOKIE_OFFSET 0 +#define DB_HEADER_VERS_OFFSET 12 +#define DB_HEADER_FIRST_OFFSET 16 +#define DB_HEADER_TIME_OFFSET 24 +#define DB_HEADER_CSIZE_OFFSET 32 +#define DB_HEADER_LAST_OFFSET 36 + +/* + * Magic Cookie for database files. + * MAXIMUM 12 CHARS! (DB_HEADER_VERS_OFFSET) + */ +#define ASL_DB_COOKIE "ASL DB" +#define ASL_DB_COOKIE_LEN 6 +#define DB_VERSION 2 +#define DB_VERSION_LEGACY_1 1 + +#define ASL_FILE_FLAG_READ_ONLY 0x00000001 +#define ASL_FILE_FLAG_UNLIMITED_CACHE 0x00000002 +#define ASL_FILE_FLAG_PRESERVE_MSG_ID 0x00000004 +#define ASL_FILE_FLAG_LEGACY_STORE 0x00000008 + +#define ASL_FILE_TYPE_MSG 0 +#define ASL_FILE_TYPE_STR 1 + +#define ASL_FILE_POSITION_FIRST 0 +#define ASL_FILE_POSITION_PREVIOUS 1 +#define ASL_FILE_POSITION_NEXT 2 +#define ASL_FILE_POSITION_LAST 3 + +/* NB CACHE_SIZE must be > 1 */ +#define CACHE_SIZE 256 + +/* Size of the fixed-length part of a MSG record */ +#define MSG_RECORD_FIXED_LENGTH 122 + +/* + * The first record (header) in the database has the format: + * + * | 12 | 4 | 8 | 8 | 4 | 8 | 36 | (80 bytes) + * | Cookie | Vers | First | Time | String cache size | Last | Zero | + * + * MSG records have the format: + * + * | 2 | 4 | 8 | 8 | 8 | 4 | 2 | 2 | 4 | 4 | 4 | 4 | 4 | 4 | 4 + * | 00 | Len | Next | ID | Time | Nano | Level | Flags | PID | UID | GID | RUID | RGID | RefPID | KV count ... + * + * | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | | 8 + * | Host | Sender | Facility | Message | RefProc | Session | Key0 | Val0 | ... | Previous | + * + * STR records have the format: + * + * | 2 | 4 | Len | (Len + 6 bytes) + * | 01 | Len | Data+NUL | + * + */ + +typedef struct file_string_s +{ + uint64_t where; + uint32_t hash; + struct file_string_s *next; + char str[]; +} file_string_t; + +typedef struct +{ + uint32_t flags; + uint32_t version; + uint32_t string_count; + file_string_t *string_list; + uint64_t first; + uint64_t last; + uint64_t prev; + uint64_t cursor; + uint64_t cursor_xid; + uint64_t dob; + size_t file_size; + FILE *store; + void *legacy; + char *scratch; +} asl_file_t; + +typedef struct asl_file_list_s +{ + asl_file_t *file; + struct asl_file_list_s *next; +} asl_file_list_t; + +asl_file_list_t *asl_file_list_add(asl_file_list_t *list, asl_file_t *f); +void asl_file_list_close(asl_file_list_t *list); + +uint32_t asl_file_open_write(const char *path, mode_t mode, uid_t uid, gid_t gid, asl_file_t **s); +uint32_t asl_file_close(asl_file_t *s); + +uint32_t asl_file_save(asl_file_t *s, aslmsg msg, uint64_t *mid); + +uint32_t asl_file_open_read(const char *path, asl_file_t **s); +uint32_t asl_file_fetch(asl_file_t *s, uint64_t mid, aslmsg *msg); + +uint32_t asl_file_read_set_position(asl_file_t *s, uint32_t pos); +uint32_t asl_file_fetch_next(asl_file_t *s, aslmsg *msg); +uint32_t asl_file_fetch_previous(asl_file_t *s, aslmsg *msg); + +uint32_t asl_file_match(asl_file_t *s, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction); +uint32_t asl_file_list_match_timeout(asl_file_list_t *list, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction, uint32_t usec); +uint32_t asl_file_list_match(asl_file_list_t *list, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction); + +void *asl_file_list_match_start(asl_file_list_t *list, uint64_t start_id, int32_t direction); +uint32_t asl_file_list_match_next(void *token, aslresponse query, aslresponse *res, uint32_t count); +void asl_file_list_match_end(void *token); + +size_t asl_file_size(asl_file_t *s); +uint64_t asl_file_ctime(asl_file_t *s); + +uint32_t asl_file_compact(asl_file_t *s, const char *path, mode_t mode, uid_t uid, gid_t gid); + +#endif __ASL_FILE_H__ diff --git a/gen/asl_legacy1.c b/gen/asl_legacy1.c new file mode 100644 index 0000000..843a930 --- /dev/null +++ b/gen/asl_legacy1.c @@ -0,0 +1,1823 @@ +/* + * Copyright (c) 2007-2008 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2007 Apple Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define forever for(;;) + +#define FILE_MODE 0600 + +#define DB_RECORD_LEN 80 + +#define DB_HEADER_COOKIE_OFFSET 0 +#define DB_HEADER_VERS_OFFSET 12 + +#define DB_TYPE_EMPTY 0 +#define DB_TYPE_HEADER 1 +#define DB_TYPE_MESSAGE 2 +#define DB_TYPE_KVLIST 3 +#define DB_TYPE_STRING 4 +#define DB_TYPE_STRCONT 5 + +/* + * Magic Cookie for database files. + * MAXIMUM 12 CHARS! (DB_HEADER_VERS_OFFSET) + */ +#define ASL_DB_COOKIE "ASL DB" +#define ASL_DB_COOKIE_LEN 6 + +#define ASL_INDEX_NULL 0xffffffff + +#define DB_HLEN_EMPTY 0 +#define DB_HLEN_HEADER 13 +#define DB_HLEN_MESSAGE 13 +#define DB_HLEN_KVLIST 9 +#define DB_HLEN_STRING 25 +#define DB_HLEN_STRCONT 5 + +#define MSG_OFF_KEY_TYPE 0 +#define MSG_OFF_KEY_NEXT 1 +#define MSG_OFF_KEY_ID 5 +#define MSG_OFF_KEY_RUID 13 +#define MSG_OFF_KEY_RGID 17 +#define MSG_OFF_KEY_TIME 21 +#define MSG_OFF_KEY_HOST 29 +#define MSG_OFF_KEY_SENDER 37 +#define MSG_OFF_KEY_FACILITY 45 +#define MSG_OFF_KEY_LEVEL 53 +#define MSG_OFF_KEY_PID 57 +#define MSG_OFF_KEY_UID 61 +#define MSG_OFF_KEY_GID 65 +#define MSG_OFF_KEY_MSG 69 +#define MSG_OFF_KEY_FLAGS 77 + +extern time_t asl_parse_time(const char *str); +extern int asl_msg_cmp(asl_msg_t *a, asl_msg_t *b); + +#define asl_msg_list_t asl_search_result_t + +#define PMSG_SEL_TIME 0x0001 +#define PMSG_SEL_HOST 0x0002 +#define PMSG_SEL_SENDER 0x0004 +#define PMSG_SEL_FACILITY 0x0008 +#define PMSG_SEL_MESSAGE 0x0010 +#define PMSG_SEL_LEVEL 0x0020 +#define PMSG_SEL_PID 0x0040 +#define PMSG_SEL_UID 0x0080 +#define PMSG_SEL_GID 0x0100 +#define PMSG_SEL_RUID 0x0200 +#define PMSG_SEL_RGID 0x0400 + +#define PMSG_FETCH_ALL 0 +#define PMSG_FETCH_STD 1 +#define PMSG_FETCH_KV 2 + +#define Q_NULL 100001 +#define Q_FAST 100002 +#define Q_SLOW 100003 +#define Q_FAIL 100004 + +typedef struct +{ + uint16_t kselect; + uint16_t vselect; + uint64_t msgid; + uint64_t time; + uint64_t host; + uint64_t sender; + uint64_t facility; + uint64_t message; + uint32_t level; + uint32_t pid; + int32_t uid; + int32_t gid; + int32_t ruid; + int32_t rgid; + uint32_t next; + uint32_t kvcount; + uint64_t *kvlist; +} pmsg_t; + +static uint64_t +_asl_htonq(uint64_t n) +{ +#ifdef __BIG_ENDIAN__ + return n; +#else + u_int32_t t; + union + { + u_int64_t q; + u_int32_t l[2]; + } x; + + x.q = n; + t = x.l[0]; + x.l[0] = htonl(x.l[1]); + x.l[1] = htonl(t); + + return x.q; +#endif +} + +static uint64_t +_asl_ntohq(uint64_t n) +{ +#ifdef __BIG_ENDIAN__ + return n; +#else + u_int32_t t; + union + { + u_int64_t q; + u_int32_t l[2]; + } x; + + x.q = n; + t = x.l[0]; + x.l[0] = ntohl(x.l[1]); + x.l[1] = ntohl(t); + + return x.q; +#endif +} + +static uint16_t +_asl_get_16(char *h) +{ + uint16_t x; + + memcpy(&x, h, 2); + return ntohs(x); +} + +static uint32_t +_asl_get_32(char *h) +{ + uint32_t x; + + memcpy(&x, h, 4); + return ntohl(x); +} + +static uint64_t +_asl_get_64(char *h) +{ + uint64_t x; + + memcpy(&x, h, 8); + return _asl_ntohq(x); +} + +#define header_get_next(h) _asl_get_32(h + 1) +#define header_get_id(h) _asl_get_64(h + 5) +#define header_get_hash(h) _asl_get_32(h + 17) + +/* + * callback for sorting slotlist + * primary sort is by xid + * secondary sort is by slot, which happens when xid is 0 + * this allows us to quickly find xids (using binary search on the xid key) + * it's also used to find slots quickly from record_chain_free() + */ +static int +slot_comp(const void *a, const void *b) +{ + asl_legacy1_slot_info_t *ai, *bi; + + if (a == NULL) + { + if (b == NULL) return 0; + return -1; + } + + if (b == NULL) return 1; + + ai = (asl_legacy1_slot_info_t *)a; + bi = (asl_legacy1_slot_info_t *)b; + + if (ai->xid < bi->xid) return -1; + + if (ai->xid == bi->xid) + { + if (ai->slot < bi->slot) return -1; + if (ai->slot == bi->slot) return 0; + return 1; + } + + return 1; +} + +/* find an xid in the slot list */ +static uint32_t +slotlist_find(asl_legacy1_t *s, uint64_t xid, int32_t direction) +{ + uint32_t top, bot, mid, range; + + if (s == NULL) return ASL_INDEX_NULL; + if (s->slotlist_count == 0) return ASL_INDEX_NULL; + if (xid == 0) return ASL_INDEX_NULL; + + top = s->slotlist_count - 1; + bot = 0; + mid = top / 2; + + range = top - bot; + while (range > 1) + { + if (xid == s->slotlist[mid].xid) return mid; + else if (xid < s->slotlist[mid].xid) top = mid; + else bot = mid; + + range = top - bot; + mid = bot + (range / 2); + } + + if (xid == s->slotlist[top].xid) return top; + if (xid == s->slotlist[bot].xid) return bot; + + if (direction == 0) return ASL_INDEX_NULL; + if (direction < 0) return bot; + return top; +} + +static uint32_t +slotlist_init(asl_legacy1_t *s, uint32_t count) +{ + uint32_t i, si, status, hash, addslot; + uint64_t xid; + uint8_t t; + char tmp[DB_RECORD_LEN]; + + /* Start at first slot after the header */ + status = fseek(s->db, DB_RECORD_LEN, SEEK_SET); + if (status != 0) return ASL_STATUS_READ_FAILED; + + s->slotlist = (asl_legacy1_slot_info_t *)calloc(count, sizeof(asl_legacy1_slot_info_t)); + if (s->slotlist == NULL) return ASL_STATUS_NO_MEMORY; + + si = 0; + + for (i = 1; i < count; i++) + { + status = fread(tmp, DB_RECORD_LEN, 1, s->db); + if (status != 1) return ASL_STATUS_READ_FAILED; + + t = tmp[0]; + addslot = 0; + xid = 0; + hash = 0; + + if (t == DB_TYPE_EMPTY) addslot = 1; + + if (t == DB_TYPE_STRING) + { + addslot = 1; + xid = header_get_id(tmp); + hash = header_get_hash(tmp); + } + + if (t == DB_TYPE_MESSAGE) + { + addslot = 1; + xid = header_get_id(tmp); + } + + if (addslot == 1) + { + s->slotlist[si].type = t; + s->slotlist[si].slot = i; + s->slotlist[si].xid = xid; + s->slotlist[si].hash = hash; + si++; + } + } + + s->slotlist = (asl_legacy1_slot_info_t *)reallocf(s->slotlist, si * sizeof(asl_legacy1_slot_info_t)); + if (s->slotlist == NULL) return ASL_STATUS_NO_MEMORY; + s->slotlist_count = si; + + /* slotlist is sorted by xid */ + qsort((void *)s->slotlist, s->slotlist_count, sizeof(asl_legacy1_slot_info_t), slot_comp); + + return ASL_STATUS_OK; +} + +uint32_t +asl_legacy1_open(const char *path, asl_legacy1_t **out) +{ + asl_legacy1_t *s; + struct stat sb; + int status; + char cbuf[DB_RECORD_LEN]; + off_t fsize; + uint32_t count; + + memset(&sb, 0, sizeof(struct stat)); + status = stat(path, &sb); + if (status < 0) return ASL_STATUS_FAILED; + + fsize = sb.st_size; + + s = (asl_legacy1_t *)calloc(1, sizeof(asl_legacy1_t)); + if (s == NULL) return ASL_STATUS_NO_MEMORY; + + s->db = fopen(path, "r"); + if (s->db == NULL) + { + free(s); + return ASL_STATUS_INVALID_STORE; + } + + memset(cbuf, 0, DB_RECORD_LEN); + status = fread(cbuf, DB_RECORD_LEN, 1, s->db); + if (status != 1) + { + fclose(s->db); + free(s); + return ASL_STATUS_READ_FAILED; + } + + /* Check the database Magic Cookie */ + if (strncmp(cbuf, ASL_DB_COOKIE, ASL_DB_COOKIE_LEN)) + { + fclose(s->db); + free(s); + return ASL_STATUS_INVALID_STORE; + } + + count = fsize / DB_RECORD_LEN; + + status = slotlist_init(s, count); + + *out = s; + return ASL_STATUS_OK; +} + +uint32_t +asl_legacy1_close(asl_legacy1_t *s) +{ + if (s == NULL) return ASL_STATUS_INVALID_STORE; + + if (s->slotlist != NULL) free(s->slotlist); + if (s->db != NULL) fclose(s->db); + free(s); + + return ASL_STATUS_OK; +} + +static uint32_t +string_fetch_slot(asl_legacy1_t *s, uint32_t slot, char **out) +{ + off_t offset; + uint8_t type; + uint32_t status, next, len, x, remaining; + char *outstr, *p, tmp[DB_RECORD_LEN]; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (out == NULL) return ASL_STATUS_INVALID_ARG; + + *out = NULL; + offset = slot * DB_RECORD_LEN; + status = fseek(s->db, offset, SEEK_SET); + + if (status < 0) return ASL_STATUS_READ_FAILED; + + status = fread(tmp, DB_RECORD_LEN, 1, s->db); + if (status != 1) return ASL_STATUS_READ_FAILED; + + type = tmp[0]; + if (type != DB_TYPE_STRING) return ASL_STATUS_INVALID_STRING; + + len = _asl_get_32(tmp + 21); + if (len == 0) return ASL_STATUS_OK; + + next = header_get_next(tmp); + + outstr = calloc(1, len); + if (outstr == NULL) return ASL_STATUS_NO_MEMORY; + + p = outstr; + remaining = len; + + x = DB_RECORD_LEN - DB_HLEN_STRING; + if (x > remaining) x = remaining; + + memcpy(p, tmp + DB_HLEN_STRING, x); + p += x; + remaining -= x; + + while ((next != 0) && (remaining > 0)) + { + offset = next * DB_RECORD_LEN; + status = fseek(s->db, offset, SEEK_SET); + + if (status < 0) + { + free(outstr); + return ASL_STATUS_READ_FAILED; + } + + status = fread(tmp, DB_RECORD_LEN, 1, s->db); + if (status != 1) + { + free(outstr); + return ASL_STATUS_READ_FAILED; + } + + next = header_get_next(tmp); + + x = DB_RECORD_LEN - DB_HLEN_STRCONT; + if (x > remaining) x = remaining; + + memcpy(p, tmp + DB_HLEN_STRCONT, x); + p += x; + remaining -= x; + } + + if ((next != 0) || (remaining != 0)) + { + free(outstr); + return ASL_STATUS_READ_FAILED; + } + + *out = outstr; + return ASL_STATUS_OK; +} + +static uint32_t +string_fetch_sid(asl_legacy1_t *s, uint64_t sid, char **out) +{ + uint32_t i, len, ref; + uint64_t nsid; + uint8_t inls; + char *p; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (out == NULL) return ASL_STATUS_INVALID_ARG; + + *out = NULL; + if (sid == ASL_REF_NULL) return ASL_STATUS_OK; + + ref = 0; + + inls = 0; + nsid = _asl_htonq(sid); + memcpy(&inls, &nsid, 1); + if (inls & 0x80) + { + /* inline string */ + inls &= 0x0f; + len = inls; + *out = calloc(1, len); + if (*out == NULL) return ASL_STATUS_NO_MEMORY; + p = 1 + (char *)&nsid; + memcpy(*out, p, len); + return ASL_STATUS_OK; + } + + /* Find the string in the database */ + i = slotlist_find(s, sid, 0); + if (i == ASL_INDEX_NULL) return ASL_STATUS_NOT_FOUND; + + return string_fetch_slot(s, s->slotlist[i].slot, out); +} + +static uint32_t +pmsg_fetch(asl_legacy1_t *s, uint32_t slot, uint32_t action, pmsg_t **pmsg) +{ + off_t offset; + uint32_t status, i, n, v32, next; + int32_t msgu, msgg; + uint64_t msgid; + uint16_t flags; + pmsg_t *out; + char *p, tmp[DB_RECORD_LEN]; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (pmsg == NULL) return ASL_STATUS_INVALID_ARG; + + out = NULL; + + if ((action == PMSG_FETCH_ALL) || (action == PMSG_FETCH_STD)) + { + *pmsg = NULL; + + offset = slot * DB_RECORD_LEN; + status = fseek(s->db, offset, SEEK_SET); + + if (status < 0) return ASL_STATUS_READ_FAILED; + + status = fread(tmp, DB_RECORD_LEN, 1, s->db); + if (status != 1) return ASL_STATUS_READ_FAILED; + + msgid = _asl_get_64(tmp + MSG_OFF_KEY_ID); + msgu = _asl_get_32(tmp + MSG_OFF_KEY_RUID); + msgg = _asl_get_32(tmp + MSG_OFF_KEY_RGID); + flags = _asl_get_16(tmp + MSG_OFF_KEY_FLAGS); + + out = (pmsg_t *)calloc(1, sizeof(pmsg_t)); + if (out == NULL) return ASL_STATUS_NO_MEMORY; + + + p = tmp + 21; + + /* ID */ + out->msgid = msgid; + + /* ReadUID */ + out->ruid = msgu; + + /* ReadGID */ + out->rgid = msgg; + + /* Time */ + out->time = _asl_get_64(p); + p += 8; + + /* Host */ + out->host = _asl_get_64(p); + p += 8; + + /* Sender */ + out->sender = _asl_get_64(p); + p += 8; + + /* Facility */ + out->facility = _asl_get_64(p); + p += 8; + + /* Level */ + out->level = _asl_get_32(p); + p += 4; + + /* PID */ + out->pid = _asl_get_32(p); + p += 4; + + /* UID */ + out->uid = _asl_get_32(p); + p += 4; + + /* GID */ + out->gid = _asl_get_32(p); + p += 4; + + /* Message */ + out->message = _asl_get_64(p); + p += 8; + + next = header_get_next(tmp); + out->next = next; + + if (action == PMSG_FETCH_STD) + { + /* caller only wants "standard" keys */ + *pmsg = out; + return ASL_STATUS_OK; + } + + *pmsg = out; + } + else + { + out = *pmsg; + } + + n = 0; + next = out->next; + + while (next != 0) + { + offset = next * DB_RECORD_LEN; + status = fseek(s->db, offset, SEEK_SET); + if (status < 0) + { + *pmsg = NULL; + free(out); + return ASL_STATUS_READ_FAILED; + } + + status = fread(tmp, DB_RECORD_LEN, 1, s->db); + if (status != 1) + { + *pmsg = NULL; + free(out); + return ASL_STATUS_READ_FAILED; + } + + if (out->kvcount == 0) + { + v32 = _asl_get_32(tmp + 5); + out->kvcount = v32 * 2; + out->kvlist = (uint64_t *)calloc(out->kvcount, sizeof(uint64_t)); + if (out->kvlist == NULL) + { + *pmsg = NULL; + free(out); + return ASL_STATUS_NO_MEMORY; + } + } + + p = tmp + 9; + + for (i = 0; (i < 4) && (n < out->kvcount); i++) + { + out->kvlist[n++] = _asl_get_64(p); + p += 8; + + out->kvlist[n++] = _asl_get_64(p); + p += 8; + } + + next = header_get_next(tmp); + } + + return ASL_STATUS_OK; +} + +static uint32_t +pmsg_match(asl_legacy1_t *s, pmsg_t *q, pmsg_t *m) +{ + uint32_t i, j; + + if (s == NULL) return 0; + if (q == NULL) return 1; + if (m == NULL) return 0; + + if (q->kselect & PMSG_SEL_TIME) + { + if (q->time == ASL_REF_NULL) return 0; + if ((q->vselect & PMSG_SEL_TIME) && (q->time != m->time)) return 0; + } + + if (q->kselect & PMSG_SEL_HOST) + { + if (q->host == ASL_REF_NULL) return 0; + if ((q->vselect & PMSG_SEL_HOST) && (q->host != m->host)) return 0; + } + + if (q->kselect & PMSG_SEL_SENDER) + { + if (q->sender == ASL_REF_NULL) return 0; + if ((q->vselect & PMSG_SEL_SENDER) && (q->sender != m->sender)) return 0; + } + + if (q->kselect & PMSG_SEL_FACILITY) + { + if (q->facility == ASL_REF_NULL) return 0; + if ((q->vselect & PMSG_SEL_FACILITY) && (q->facility != m->facility)) return 0; + } + + if (q->kselect & PMSG_SEL_MESSAGE) + { + if (q->message == ASL_REF_NULL) return 0; + if ((q->vselect & PMSG_SEL_MESSAGE) && (q->message != m->message)) return 0; + } + + if (q->kselect & PMSG_SEL_LEVEL) + { + if (q->level == ASL_INDEX_NULL) return 0; + if ((q->vselect & PMSG_SEL_LEVEL) && (q->level != m->level)) return 0; + } + + if (q->kselect & PMSG_SEL_PID) + { + if (q->pid == -1) return 0; + if ((q->vselect & PMSG_SEL_PID) && (q->pid != m->pid)) return 0; + } + + if (q->kselect & PMSG_SEL_UID) + { + if (q->uid == -2) return 0; + if ((q->vselect & PMSG_SEL_UID) && (q->uid != m->uid)) return 0; + } + + if (q->kselect & PMSG_SEL_GID) + { + if (q->gid == -2) return 0; + if ((q->vselect & PMSG_SEL_GID) && (q->gid != m->gid)) return 0; + } + + if (q->kselect & PMSG_SEL_RUID) + { + if (q->ruid == -1) return 0; + if ((q->vselect & PMSG_SEL_RUID) && (q->ruid != m->ruid)) return 0; + } + + if (q->kselect & PMSG_SEL_RGID) + { + if (q->rgid == -1) return 0; + if ((q->vselect & PMSG_SEL_RGID) && (q->rgid != m->rgid)) return 0; + } + + for (i = 0; i < q->kvcount; i += 2) + { + for (j = 0; j < m->kvcount; j += 2) + { + if (q->kvlist[i] == m->kvlist[j]) + { + if (q->kvlist[i + 1] == m->kvlist[j + 1]) break; + return 0; + } + } + + if (j >= m->kvcount) return 0; + } + + return 1; +} + +static void +free_pmsg(pmsg_t *p) +{ + if (p == NULL) return; + if (p->kvlist != NULL) free(p->kvlist); + free(p); +} + +static uint32_t +pmsg_fetch_by_id(asl_legacy1_t *s, uint64_t msgid, pmsg_t **pmsg, uint32_t *slot) +{ + uint32_t i, status; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (msgid == ASL_REF_NULL) return ASL_STATUS_INVALID_ARG; + if (slot == NULL) return ASL_STATUS_INVALID_ARG; + + *slot = ASL_INDEX_NULL; + + i = slotlist_find(s, msgid, 0); + if (i == ASL_INDEX_NULL) return ASL_STATUS_INVALID_ID; + + *slot = s->slotlist[i].slot; + + /* read the message */ + *pmsg = NULL; + status = pmsg_fetch(s, s->slotlist[i].slot, PMSG_FETCH_ALL, pmsg); + if (status != ASL_STATUS_OK) return status; + if (pmsg == NULL) return ASL_STATUS_FAILED; + + return status; +} + +static uint32_t +msg_decode(asl_legacy1_t *s, pmsg_t *pmsg, asl_msg_t **out) +{ + uint32_t status, i, n; + char *key, *val; + asl_msg_t *msg; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (out == NULL) return ASL_STATUS_INVALID_ARG; + if (pmsg == NULL) return ASL_STATUS_INVALID_ARG; + + *out = NULL; + + msg = (asl_msg_t *)calloc(1, sizeof(asl_msg_t)); + if (msg == NULL) return ASL_STATUS_NO_MEMORY; + + msg->type = ASL_TYPE_MSG; + msg->count = 0; + if (pmsg->time != ASL_REF_NULL) msg->count++; + if (pmsg->host != ASL_REF_NULL) msg->count++; + if (pmsg->sender != ASL_REF_NULL) msg->count++; + if (pmsg->facility != ASL_REF_NULL) msg->count++; + if (pmsg->message != ASL_REF_NULL) msg->count++; + if (pmsg->level != ASL_INDEX_NULL) msg->count++; + if (pmsg->pid != -1) msg->count++; + if (pmsg->uid != -2) msg->count++; + if (pmsg->gid != -2) msg->count++; + if (pmsg->ruid != -1) msg->count++; + if (pmsg->rgid != -1) msg->count++; + + msg->count += pmsg->kvcount / 2; + + if (msg->count == 0) + { + free(msg); + return ASL_STATUS_INVALID_MESSAGE; + } + + /* Message ID */ + msg->count += 1; + + msg->key = (char **)calloc(msg->count, sizeof(char *)); + if (msg->key == NULL) + { + free(msg); + return ASL_STATUS_NO_MEMORY; + } + + msg->val = (char **)calloc(msg->count, sizeof(char *)); + if (msg->val == NULL) + { + free(msg->key); + free(msg); + return ASL_STATUS_NO_MEMORY; + } + + n = 0; + + /* Time */ + if (pmsg->time != ASL_REF_NULL) + { + msg->key[n] = strdup(ASL_KEY_TIME); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + asprintf(&(msg->val[n]), "%llu", pmsg->time); + if (msg->val[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + n++; + } + + /* Host */ + if (pmsg->host != ASL_REF_NULL) + { + msg->key[n] = strdup(ASL_KEY_HOST); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + status = string_fetch_sid(s, pmsg->host, &(msg->val[n])); + n++; + } + + /* Sender */ + if (pmsg->sender != ASL_REF_NULL) + { + msg->key[n] = strdup(ASL_KEY_SENDER); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + status = string_fetch_sid(s, pmsg->sender, &(msg->val[n])); + n++; + } + + /* Facility */ + if (pmsg->facility != ASL_REF_NULL) + { + msg->key[n] = strdup(ASL_KEY_FACILITY); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + status = string_fetch_sid(s, pmsg->facility, &(msg->val[n])); + n++; + } + + /* Level */ + if (pmsg->level != ASL_INDEX_NULL) + { + msg->key[n] = strdup(ASL_KEY_LEVEL); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + asprintf(&(msg->val[n]), "%u", pmsg->level); + if (msg->val[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + n++; + } + + /* PID */ + if (pmsg->pid != -1) + { + msg->key[n] = strdup(ASL_KEY_PID); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + asprintf(&(msg->val[n]), "%d", pmsg->pid); + if (msg->val[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + n++; + } + + /* UID */ + if (pmsg->uid != -2) + { + msg->key[n] = strdup(ASL_KEY_UID); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + asprintf(&(msg->val[n]), "%d", pmsg->uid); + if (msg->val[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + n++; + } + + /* GID */ + if (pmsg->gid != -2) + { + msg->key[n] = strdup(ASL_KEY_GID); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + asprintf(&(msg->val[n]), "%d", pmsg->gid); + if (msg->val[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + n++; + } + + /* Message */ + if (pmsg->message != ASL_REF_NULL) + { + msg->key[n] = strdup(ASL_KEY_MSG); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + status = string_fetch_sid(s, pmsg->message, &(msg->val[n])); + n++; + } + + /* ReadUID */ + if (pmsg->ruid != -1) + { + msg->key[n] = strdup(ASL_KEY_READ_UID); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + asprintf(&(msg->val[n]), "%d", pmsg->ruid); + if (msg->val[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + n++; + } + + /* ReadGID */ + if (pmsg->rgid != -1) + { + msg->key[n] = strdup(ASL_KEY_READ_GID); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + asprintf(&(msg->val[n]), "%d", pmsg->rgid); + if (msg->val[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + n++; + } + + /* Message ID */ + msg->key[n] = strdup(ASL_KEY_MSG_ID); + if (msg->key[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + + asprintf(&(msg->val[n]), "%llu", pmsg->msgid); + if (msg->val[n] == NULL) + { + asl_free(msg); + return ASL_STATUS_NO_MEMORY; + } + n++; + + /* Key - Value List */ + for (i = 0; i < pmsg->kvcount; i++) + { + key = NULL; + status = string_fetch_sid(s, pmsg->kvlist[i++], &key); + if (status != ASL_STATUS_OK) + { + if (key != NULL) free(key); + continue; + } + + val = NULL; + status = string_fetch_sid(s, pmsg->kvlist[i], &val); + if (status != ASL_STATUS_OK) + { + if (key != NULL) free(key); + if (val != NULL) free(val); + continue; + } + + msg->key[n] = key; + msg->val[n] = val; + n++; + } + + *out = msg; + return ASL_STATUS_OK; +} + +/* + * Finds string either in the string cache or in the database + */ +static uint32_t +store_string_find(asl_legacy1_t *s, uint32_t hash, const char *str, uint32_t *index) +{ + uint32_t i, status; + char *tmp; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (str == NULL) return ASL_STATUS_INVALID_ARG; + if (index == NULL) return ASL_STATUS_INVALID_ARG; + if (s->slotlist == NULL) return ASL_STATUS_FAILED; + + /* check the database */ + for (i = 0; i < s->slotlist_count; i++) + { + if ((s->slotlist[i].type != DB_TYPE_STRING) || (s->slotlist[i].hash != hash)) continue; + + /* read the whole string */ + tmp = NULL; + status = string_fetch_slot(s, s->slotlist[i].slot, &tmp); + if (status != ASL_STATUS_OK) return status; + if (tmp == NULL) return ASL_STATUS_FAILED; + + status = strcmp(tmp, str); + free(tmp); + if (status != 0) continue; + + /* Bingo! */ + *index = i; + return ASL_STATUS_OK; + } + + return ASL_STATUS_FAILED; +} + +/* + * Looks up a string ID number. + */ +static uint64_t +string_lookup(asl_legacy1_t *s, const char *str) +{ + uint32_t status, hash, index, slot, len; + uint64_t nsid, sid; + char *p; + uint8_t inls; + + if (s == NULL) return ASL_REF_NULL; + if (str == NULL) return ASL_REF_NULL; + + sid = ASL_REF_NULL; + index = ASL_INDEX_NULL; + slot = ASL_INDEX_NULL; + + len = strlen(str); + if (len < 8) + { + /* inline string */ + inls = len; + inls |= 0x80; + + nsid = 0; + p = (char *)&nsid; + memcpy(p, &inls, 1); + memcpy(p + 1, str, len); + sid = _asl_ntohq(nsid); + return sid; + } + + hash = asl_core_string_hash(str, len); + + /* check the database */ + status = store_string_find(s, hash, str, &index); + if (status == ASL_STATUS_OK) + { + if (index == ASL_INDEX_NULL) return ASL_REF_NULL; + return s->slotlist[index].xid; + } + + return ASL_REF_NULL; +} + +uint32_t +asl_legacy1_fetch(asl_legacy1_t *s, uint64_t msgid, asl_msg_t **msg) +{ + uint32_t status, slot; + pmsg_t *pmsg; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (msgid == ASL_REF_NULL) return ASL_STATUS_INVALID_ARG; + + pmsg = NULL; + slot = ASL_INDEX_NULL; + + status = pmsg_fetch_by_id(s, msgid, &pmsg, &slot); + if (status != ASL_STATUS_OK) return status; + if (pmsg == NULL) return ASL_STATUS_FAILED; + + status = msg_decode(s, pmsg, msg); + free_pmsg(pmsg); + + return status; +} + +static uint32_t +query_to_pmsg(asl_legacy1_t *s, asl_msg_t *q, pmsg_t **p) +{ + pmsg_t *out; + uint32_t i, j; + uint64_t ksid, vsid; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (p == NULL) return ASL_STATUS_INVALID_ARG; + + if (q == NULL) return Q_NULL; + if (q->count == 0) return Q_NULL; + + *p = NULL; + + if (q->op != NULL) + { + for (i = 0; i < q->count; i++) if (q->op[i] != ASL_QUERY_OP_EQUAL) return Q_SLOW; + } + + out = (pmsg_t *)calloc(1, sizeof(pmsg_t)); + if (out == NULL) return ASL_STATUS_NO_MEMORY; + + for (i = 0; i < q->count; i++) + { + if (q->key[i] == NULL) continue; + + else if (!strcmp(q->key[i], ASL_KEY_TIME)) + { + if (out->kselect & PMSG_SEL_TIME) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_TIME; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_TIME; + out->time = asl_parse_time(q->val[i]); + } + } + else if (!strcmp(q->key[i], ASL_KEY_HOST)) + { + if (out->kselect & PMSG_SEL_HOST) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_HOST; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_HOST; + out->host = string_lookup(s, q->val[i]); + if (out->host == ASL_REF_NULL) + { + free_pmsg(out); + return Q_FAIL; + } + } + } + else if (!strcmp(q->key[i], ASL_KEY_SENDER)) + { + if (out->kselect & PMSG_SEL_SENDER) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_SENDER; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_SENDER; + out->sender = string_lookup(s, q->val[i]); + if (out->sender == ASL_REF_NULL) + { + free_pmsg(out); + return Q_FAIL; + } + } + } + else if (!strcmp(q->key[i], ASL_KEY_PID)) + { + if (out->kselect & PMSG_SEL_PID) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_PID; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_PID; + out->pid = atoi(q->val[i]); + } + } + else if (!strcmp(q->key[i], ASL_KEY_UID)) + { + if (out->kselect & PMSG_SEL_UID) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_UID; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_UID; + out->uid = atoi(q->val[i]); + } + } + else if (!strcmp(q->key[i], ASL_KEY_GID)) + { + if (out->kselect & PMSG_SEL_GID) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_GID; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_GID; + out->gid = atoi(q->val[i]); + } + } + else if (!strcmp(q->key[i], ASL_KEY_LEVEL)) + { + if (out->kselect & PMSG_SEL_LEVEL) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_LEVEL; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_LEVEL; + out->level = atoi(q->val[i]); + } + } + else if (!strcmp(q->key[i], ASL_KEY_MSG)) + { + if (out->kselect & PMSG_SEL_MESSAGE) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_MESSAGE; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_MESSAGE; + out->message = string_lookup(s, q->val[i]); + if (out->message == ASL_REF_NULL) + { + free_pmsg(out); + return Q_FAIL; + } + } + } + else if (!strcmp(q->key[i], ASL_KEY_FACILITY)) + { + if (out->kselect & PMSG_SEL_FACILITY) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_FACILITY; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_FACILITY; + out->facility = string_lookup(s, q->val[i]); + if (out->facility == ASL_REF_NULL) + { + free_pmsg(out); + return Q_FAIL; + } + } + } + else if (!strcmp(q->key[i], ASL_KEY_READ_UID)) + { + if (out->kselect & PMSG_SEL_RUID) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_RUID; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_RUID; + out->ruid = atoi(q->val[i]); + } + } + else if (!strcmp(q->key[i], ASL_KEY_READ_GID)) + { + if (out->kselect & PMSG_SEL_RGID) + { + free_pmsg(out); + return Q_SLOW; + } + + out->kselect |= PMSG_SEL_RGID; + if (q->val[i] != NULL) + { + out->vselect |= PMSG_SEL_RGID; + out->rgid = atoi(q->val[i]); + } + } + else + { + ksid = string_lookup(s, q->key[i]); + if (ksid == ASL_REF_NULL) + { + free_pmsg(out); + return Q_FAIL; + } + + for (j = 0; j < out->kvcount; j += 2) + { + if (out->kvlist[j] == ksid) + { + free_pmsg(out); + return Q_SLOW; + } + } + + vsid = ASL_REF_NULL; + if (q->val[i] != NULL) + { + vsid = string_lookup(s, q->val[i]); + if (ksid == ASL_REF_NULL) + { + free_pmsg(out); + return Q_FAIL; + } + } + + if (out->kvcount == 0) + { + out->kvlist = (uint64_t *)calloc(2, sizeof(uint64_t)); + } + else + { + out->kvlist = (uint64_t *)reallocf(out->kvlist, (out->kvcount + 2) * sizeof(uint64_t)); + } + + if (out->kvlist == NULL) + { + free_pmsg(out); + return ASL_STATUS_NO_MEMORY; + } + + out->kvlist[out->kvcount++] = ksid; + out->kvlist[out->kvcount++] = vsid; + } + } + + *p = out; + return Q_FAST; +} + +static uint32_t +msg_match(asl_legacy1_t *s, uint32_t qtype, pmsg_t *qp, asl_msg_t *q, uint32_t slot, pmsg_t **iopm, asl_msg_t **iomsg, asl_msg_list_t **res, uint32_t *didmatch) +{ + uint32_t status, what; + + *didmatch = 0; + + if (qtype == Q_FAIL) return ASL_STATUS_OK; + + if (qtype == Q_NULL) + { + if (*iopm == NULL) + { + status = pmsg_fetch(s, slot, PMSG_FETCH_ALL, iopm); + if (status != ASL_STATUS_OK) return status; + if (*iopm == NULL) return ASL_STATUS_FAILED; + } + } + else if (qtype == Q_FAST) + { + if (qp == NULL) return ASL_STATUS_INVALID_ARG; + + what = PMSG_FETCH_STD; + if (qp->kvcount > 0) what = PMSG_FETCH_ALL; + + if (*iopm == NULL) + { + status = pmsg_fetch(s, slot, what, iopm); + if (status != ASL_STATUS_OK) return status; + if (*iopm == NULL) return ASL_STATUS_FAILED; + } + + status = pmsg_match(s, qp, *iopm); + if (status == 1) + { + if ((what == PMSG_FETCH_STD) && ((*iopm)->next != 0) && ((*iopm)->kvcount == 0)) + { + status = pmsg_fetch(s, slot, PMSG_FETCH_KV, iopm); + if (status != ASL_STATUS_OK) return status; + if (*iopm == NULL) return ASL_STATUS_FAILED; + } + } + else return ASL_STATUS_OK; + } + else if (qtype == Q_SLOW) + { + if (*iomsg == NULL) + { + if (*iopm == NULL) + { + status = pmsg_fetch(s, slot, PMSG_FETCH_ALL, iopm); + if (status != ASL_STATUS_OK) return status; + if (*iopm == NULL) return ASL_STATUS_FAILED; + } + + status = msg_decode(s, *iopm, iomsg); + if (status == ASL_STATUS_INVALID_MESSAGE) return ASL_STATUS_OK; + if (status != ASL_STATUS_OK) return status; + if (*iomsg == NULL) return ASL_STATUS_FAILED; + } + + status = 0; + if (asl_msg_cmp(q, *iomsg) != 0) status = 1; + if (status == 0) return ASL_STATUS_OK; + } + + *didmatch = 1; + + if (res == NULL) return ASL_STATUS_OK; + + if (*iomsg == NULL) + { + status = msg_decode(s, *iopm, iomsg); + if (status == ASL_STATUS_INVALID_MESSAGE) + { + *didmatch = 0; + return ASL_STATUS_OK; + } + + if (status != ASL_STATUS_OK) return status; + } + + if ((*res)->count == 0) (*res)->msg = (asl_msg_t **)calloc(1, sizeof(asl_msg_t *)); + else (*res)->msg = (asl_msg_t **)reallocf((*res)->msg, (1 + (*res)->count) * sizeof(asl_msg_t *)); + if ((*res)->msg == NULL) return ASL_STATUS_NO_MEMORY; + + (*res)->msg[(*res)->count++] = *iomsg; + + return ASL_STATUS_OK; +} + +static uint32_t +next_search_slot(asl_legacy1_t *s, uint32_t last_si, int32_t direction) +{ + uint32_t i; + + if (direction >= 0) + { + for (i = last_si + 1; i < s->slotlist_count; i++) + { + if (s->slotlist[i].type == DB_TYPE_MESSAGE) return i; + } + + return ASL_INDEX_NULL; + } + + if (last_si == 0) return ASL_INDEX_NULL; + if (last_si > s->slotlist_count) return ASL_INDEX_NULL; + + for (i = last_si - 1; i > 0; i--) + { + if (s->slotlist[i].type == DB_TYPE_MESSAGE) return i; + } + + if (s->slotlist[0].type == DB_TYPE_MESSAGE) return 0; + + return ASL_INDEX_NULL; +} + +static uint32_t +query_list_to_pmsg_list(asl_legacy1_t *s, asl_msg_list_t *query, uint32_t *match, pmsg_t ***qp, uint32_t **qtype, uint32_t *count) +{ + pmsg_t **outp, *pm; + uint32_t i, j, *outt; + *match = 0; + *qp = NULL; + *qtype = 0; + *count = 0; + + if (query == NULL) return ASL_STATUS_OK; + if (match == NULL) return ASL_STATUS_INVALID_ARG; + if (qp == NULL) return ASL_STATUS_INVALID_ARG; + if (qtype == NULL) return ASL_STATUS_OK; + if (query->msg == NULL) return ASL_STATUS_OK; + if (query->count == 0) return ASL_STATUS_OK; + + outp = (pmsg_t **)calloc(query->count, sizeof(pmsg_t *)); + if (outp == NULL) return ASL_STATUS_NO_MEMORY; + + outt = (uint32_t *)calloc(query->count, sizeof(uint32_t)); + if (outt == NULL) + { + free(outp); + return ASL_STATUS_NO_MEMORY; + } + + *match = 1; + + for (i = 0; i < query->count; i++) + { + pm = NULL; + outt[i] = query_to_pmsg(s, query->msg[i], &pm); + if (outt[i] <= ASL_STATUS_FAILED) + { + if (pm != NULL) free_pmsg(pm); + for (j = 0; j < i; j++) free_pmsg(outp[j]); + free(outp); + free(outt); + return ASL_STATUS_NO_MEMORY; + } + + outp[i] = pm; + } + + *count = query->count; + *qp = outp; + *qtype = outt; + return ASL_STATUS_OK; +} + +static void +match_worker_cleanup(pmsg_t **ql, uint32_t *qt, uint32_t n, asl_msg_list_t **res) +{ + uint32_t i; + + if (ql != NULL) + { + for (i = 0; i < n; i++) free_pmsg(ql[i]); + free(ql); + } + + if (qt != NULL) free(qt); + + if (res != NULL) + { + for (i = 0; i < (*res)->count; i++) asl_free((*res)->msg[i]); + free(*res); + } +} + +/* + * Input to asl_legacy1_match is a list of queries. + * A record in the store matches if it matches any query (i.e. query list is "OR"ed) + * + * If counting up (direction is positive) find first record with ID > start_id. + * Else if counting down (direction is negative) find first record with ID < start_id. + * + * Set match flag on. + * If any query is NULL, set match flog off (skips matching below). + * Else if all queries only check "standard" keys, set std flag to on. + * + * If a query only tests equality, convert it to a pmsg_t. The conversion routine + * checks for string values that are NOT in the database. If a string is not found, + * the conversion fails and the query is markes as "never matches". Otherwise, + * the query is marked "fast". + * + * If all queries are marked as "never matches", return NULL. + * + * match loop: + * fetch record (with std flag) + * if match flag is off, decode record and add it to result. + * else for each query: + * if query is NULL (shouldn't happen) decode record and add it to result. Return to match loop. + * else if query never matches, ignore it. + * else if query is fast, use pmsg_match. If it succeeds, decode record and add it to result. Return to match loop. + * else decode record and use asl_cmp. If it succeeds, add record to result. Return to match loop. + * + * return results. + */ +static uint32_t +match_worker(asl_legacy1_t *s, asl_msg_list_t *query, asl_msg_list_t **res, uint64_t *last_id, uint64_t **idlist, uint32_t *idcount, uint64_t start_id, int32_t count, int32_t direction) +{ + uint32_t mx, si, slot, i, qcount, match, didmatch, status, *qtype; + uint64_t xid; + pmsg_t **qp, *iopmsg; + asl_msg_t *iomsg; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if ((res == NULL) && (idlist == NULL)) return ASL_STATUS_INVALID_ARG; + if (last_id == NULL) return ASL_STATUS_INVALID_ARG; + if (idcount == NULL) return ASL_STATUS_INVALID_ARG; + + if (res != NULL) *res = NULL; + if (idlist != NULL) *idlist = NULL; + + mx = 0; + + if (direction < 0) direction = -1; + else direction = 1; + + si = ASL_INDEX_NULL; + if ((direction == -1) && (start_id == ASL_REF_NULL)) si = s->slotlist_count; + else si = slotlist_find(s, start_id, direction); + + si = next_search_slot(s, si, direction); + if (si == ASL_INDEX_NULL) return ASL_STATUS_OK; + if (si >= s->slotlist_count) return ASL_STATUS_FAILED; + + slot = s->slotlist[si].slot; + + status = query_list_to_pmsg_list(s, query, &match, &qp, &qtype, &qcount); + if (status != ASL_STATUS_OK) return status; + + /* + * initialize result list if we've been asked to return messages + */ + if (res != NULL) + { + *res = (asl_msg_list_t *)calloc(1, sizeof(asl_msg_list_t)); + if (*res == NULL) + { + match_worker_cleanup(qp, qtype, qcount, NULL); + return ASL_STATUS_NO_MEMORY; + } + } + + /* + * loop through records + */ + *idcount = 0; + while ((count == 0) || (*idcount < count)) + { + if (si == ASL_INDEX_NULL) break; + if (si >= s->slotlist_count) break; + + slot = s->slotlist[si].slot; + xid = s->slotlist[si].xid; + + *last_id = xid; + + iopmsg = NULL; + iomsg = NULL; + + didmatch = 0; + if (match == 0) + { + status = msg_match(s, Q_NULL, NULL, NULL, slot, &iopmsg, &iomsg, res, &didmatch); + free_pmsg(iopmsg); + if (didmatch == 0) + { + asl_free(iomsg); + iomsg = NULL; + } + else + { + if (idlist != NULL) + { + if (*idlist == NULL) *idlist = (uint64_t *)calloc(1, sizeof(uint64_t)); + else *idlist = (uint64_t *)reallocf(*idlist, (*idcount + 1) * sizeof(uint64_t)); + if (*idlist == NULL) status = ASL_STATUS_NO_MEMORY; + else (*idlist)[*idcount] = xid; + } + + (*idcount)++; + } + + if (status != ASL_STATUS_OK) + { + match_worker_cleanup(qp, qtype, qcount, res); + return status; + } + } + else + { + for (i = 0; i < qcount; i++) + { + status = msg_match(s, qtype[i], qp[i], query->msg[i], slot, &iopmsg, &iomsg, res, &didmatch); + if (status != ASL_STATUS_OK) + { + free_pmsg(iopmsg); + asl_free(iomsg); + match_worker_cleanup(qp, qtype, qcount, res); + return status; + } + + if (didmatch == 1) + { + if (idlist != NULL) + { + if (*idlist == NULL) *idlist = (uint64_t *)calloc(1, sizeof(uint64_t)); + else *idlist = (uint64_t *)reallocf(*idlist, (*idcount + 1) * sizeof(uint64_t)); + if (*idlist == NULL) + { + match_worker_cleanup(qp, qtype, qcount, res); + return ASL_STATUS_NO_MEMORY; + } + + (*idlist)[*idcount] = xid; + } + + (*idcount)++; + break; + } + } + + free_pmsg(iopmsg); + if ((didmatch == 0) || (res == NULL)) asl_free(iomsg); + } + + si = next_search_slot(s, si, direction); + } + + match_worker_cleanup(qp, qtype, qcount, NULL); + return status; +} + +uint32_t +asl_legacy1_match(asl_legacy1_t *s, asl_msg_list_t *query, asl_msg_list_t **res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction) +{ + uint32_t idcount; + + idcount = 0; + return match_worker(s, query, res, last_id, NULL, &idcount, start_id, count, direction); +} diff --git a/gen/asl_legacy1.h b/gen/asl_legacy1.h new file mode 100644 index 0000000..8b869e9 --- /dev/null +++ b/gen/asl_legacy1.h @@ -0,0 +1,86 @@ +#ifndef __ASL_LEGACY1_H__ +#define __ASL_LEGACY1_H__ + +/* + * Copyright (c) 2007 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2007 Apple Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * ASL Database VERSION 1 (LEGACY) + * + * Log messages are stored in 80 byte records of the form: + * + * | 1 | 4 | 8 | 4 | 4 | 8 | 8 | 8 | 8 | 4 | 4 | 4 | 4 | 8 | 2 | 1 | (80 bytes) + * | Type | Next | ID | RUID | RGID | Time | Host | Sender | Facility | LEVEL | PID | UID | GID | Message | Flags | Zero | + * + * If there are no additional key/value pairs in the message, Next will be zero. If there are additional + * key/value pairs in the database, Next is a record number for a record with the format: + * + * | 1 | 4 | 4 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 7 | (80 bytes) + * | Type | Next | Count | Key1 | Val1 | Key2 | Val2 | Key3 | Val3 | Key4 | Val4 | Zero | + * + * Additional records will be chained using the Next field, with the count field left zero. + * + * Strings stored in records of the form: + * + * | 1 | 4 | 8 | 4 | 4 | 4 | 55 | (80 bytes) + * | Type | Next | ID | Refcount | Hash | Length | String | + * + * If the string is longer than 55 bytes, Next is a record number for a record with the format: + * + * | 1 | 4 | 75 | (80 bytes) + * | Type | Next | String | + * + * The first record (header) in the database has the format: + * + * | 12 | 4 | 8 | 56 | (80 bytes) + * | Cookie | Vers | Max ID | Zero | + * + */ + +#include +#include +#include +#include + +typedef struct +{ + uint8_t type; + uint32_t slot; + uint64_t xid; + uint32_t hash; +} asl_legacy1_slot_info_t; + +typedef struct +{ + asl_legacy1_slot_info_t *slotlist; + uint32_t slotlist_count; + FILE *db; +} asl_legacy1_t; + +uint32_t asl_legacy1_open(const char *path, asl_legacy1_t **s); +uint32_t asl_legacy1_close(asl_legacy1_t *s); +uint32_t asl_legacy1_fetch(asl_legacy1_t *s, uint64_t msgid, aslmsg *msg); +uint32_t asl_legacy1_match(asl_legacy1_t *s, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction); + +#endif /*__ASL_LEGACY1_H__*/ diff --git a/gen/asl_private.h b/gen/asl_private.h index 913f9ce..989fb5b 100644 --- a/gen/asl_private.h +++ b/gen/asl_private.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 Apple Inc. All rights reserved. + * Copyright (c) 2007-2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -46,6 +46,11 @@ #define ASL_TIME_FMT_UTC "utc" #define ASL_TIME_FMT_LCL "lcl" +#define ASL_ENCODE_NONE 0 +#define ASL_ENCODE_SAFE 1 +#define ASL_ENCODE_VIS 2 +#define ASL_ENCODE_ASL 3 + #define ASL_KEY_REF_PID "RefPID" #define ASL_KEY_REF_PROC "RefProc" @@ -66,6 +71,7 @@ typedef struct __aslclient int *fd_list; char **fd_mfmt; char **fd_tfmt; + uint32_t *fd_encoding; uint32_t reserved1; void *reserved2; } asl_client_t; @@ -89,9 +95,9 @@ typedef struct __aslresponse __BEGIN_DECLS -int asl_add_output(aslclient asl, int fd, const char *msg_fmt, const char *time_fmt); +int asl_add_output(aslclient asl, int fd, const char *msg_fmt, const char *time_fmt, uint32_t text_encoding); int asl_remove_output(aslclient asl, int fd); -char *asl_format_message(aslmsg msg, const char *msg_fmt, const char *time_fmt, uint32_t *outlen); +char *asl_format_message(aslmsg msg, const char *msg_fmt, const char *time_fmt, uint32_t text_encoding, uint32_t *outlen); __END_DECLS diff --git a/gen/asl_store.c b/gen/asl_store.c new file mode 100644 index 0000000..1e37cab --- /dev/null +++ b/gen/asl_store.c @@ -0,0 +1,720 @@ +/* + * Copyright (c) 2007-2008 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2007 Apple Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern time_t asl_parse_time(const char *str); +extern uint64_t asl_file_cursor(asl_file_t *s); +extern uint32_t asl_file_match_start(asl_file_t *s, uint64_t start_id, int32_t direction); +extern uint32_t asl_file_match_next(asl_file_t *s, aslresponse query, asl_msg_t **msg, uint64_t *last_id, int32_t direction, int32_t ruid, int32_t rgid); + +#define SECONDS_PER_DAY 86400 + +/* + * The ASL Store is organized as a set of files in a common directory. + * Files are prefixed by the date (YYYY.MM.DD) of their contents. + * There are also files for long-TTL (> 1 day) messages. + * + * Messages with no access controls are saved in YYYY.MM.DD.asl + * Messages with access limited to UID U are saved in YYYY.MM.DD.uU.asl + * Messages with access limited to GID G are saved in YYYY.MM.DD.gG.asl + * Messages with access limited to UID U and GID G are saved in YYYY.MM.DD.uU.gG.asl + * + * An external tool runs daily and deletes "old" files. + */ + +/* + * The base directory contains a data file which stores + * the last record ID. + * + * | MAX_ID (uint64_t) | + * + */ +uint32_t +asl_store_open_write(const char *basedir, asl_store_t **s) +{ + asl_store_t *out; + asl_file_t *db; + struct stat sb; + uint32_t i, status; + char *path, *subpath; + time_t now; + struct tm ctm; + FILE *sd; + uint64_t last_id; + + if (s == NULL) return ASL_STATUS_INVALID_ARG; + + if (basedir == NULL) basedir = PATH_ASL_STORE; + + memset(&sb, 0, sizeof(struct stat)); + if (stat(basedir, &sb) != 0) return ASL_STATUS_INVALID_STORE; + if ((sb.st_mode & S_IFDIR) == 0) return ASL_STATUS_INVALID_STORE; + + path = NULL; + asprintf(&path, "%s/%s", basedir, FILE_ASL_STORE_DATA); + if (path == NULL) return ASL_STATUS_NO_MEMORY; + + sd = NULL; + + memset(&sb, 0, sizeof(struct stat)); + if (stat(path, &sb) != 0) + { + if (errno != ENOENT) + { + free(path); + return ASL_STATUS_FAILED; + } + + sd = fopen(path, "w+"); + free(path); + + if (sd == NULL) return ASL_STATUS_FAILED; + + last_id = 0; + + if (fwrite(&last_id, sizeof(uint64_t), 1, sd) != 1) + { + fclose(sd); + return ASL_STATUS_WRITE_FAILED; + } + } + else + { + sd = fopen(path, "r+"); + free(path); + + if (sd == NULL) return ASL_STATUS_FAILED; + if (fread(&last_id, sizeof(uint64_t), 1, sd) != 1) + { + fclose(sd); + return ASL_STATUS_READ_FAILED; + } + + last_id = asl_core_ntohq(last_id); + } + + memset(&ctm, 0, sizeof(struct tm)); + now = time(NULL); + + if (localtime_r((const time_t *)&now, &ctm) == NULL) + { + fclose(sd); + return ASL_STATUS_FAILED; + } + + subpath = NULL; + asprintf(&subpath, "%s/%d.%02d.%02d", basedir, ctm.tm_year + 1900, ctm.tm_mon + 1, ctm.tm_mday); + if (subpath == NULL) + { + fclose(sd); + return ASL_STATUS_NO_MEMORY; + } + + path = NULL; + asprintf(&path, "%s.asl", subpath); + free(subpath); + if (path == NULL) + { + fclose(sd); + return ASL_STATUS_NO_MEMORY; + } + + db = NULL; + status = asl_file_open_write(path, 0644, 0, 0, &db); + free(path); + if ((status != ASL_STATUS_OK) || (db == NULL)) + { + fclose(sd); + return ASL_STATUS_FAILED; + } + + out = (asl_store_t *)calloc(1, sizeof(asl_store_t)); + if (out == NULL) + { + fclose(sd); + asl_file_close(db); + return ASL_STATUS_NO_MEMORY; + } + + if (basedir == NULL) out->base_dir = strdup(PATH_ASL_STORE); + else out->base_dir = strdup(basedir); + + if (out->base_dir == NULL) + { + fclose(sd); + asl_file_close(db); + free(out); + return ASL_STATUS_NO_MEMORY; + } + + ctm.tm_sec = 0; + ctm.tm_min = 0; + ctm.tm_hour = 0; + + out->start_today = mktime(&ctm); + out->start_tomorrow = out->start_today + SECONDS_PER_DAY; + out->db = db; + out->storedata = sd; + out->next_id = last_id + 1; + + for (i = 0; i < FILE_CACHE_SIZE; i++) + { + memset(&out->file_cache[i], 0, sizeof(asl_cached_file_t)); + out->file_cache[i].u = -1; + out->file_cache[i].g = -1; + } + + *s = out; + return ASL_STATUS_OK; +} + +uint32_t +asl_store_statistics(asl_store_t *s, aslmsg *msg) +{ + aslmsg out; + char str[256]; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (msg == NULL) return ASL_STATUS_INVALID_ARG; + + out = (aslmsg)calloc(1, sizeof(asl_msg_t)); + if (out == NULL) return ASL_STATUS_NO_MEMORY; + + snprintf(str, sizeof(str), "%u", s->db->string_count); + asl_set(out, "StringCount", str); + + *msg = out; + return ASL_STATUS_OK; +} + +uint32_t +asl_store_open_read(const char *basedir, asl_store_t **s) +{ + asl_store_t *out; + struct stat sb; + + if (s == NULL) return ASL_STATUS_INVALID_ARG; + + if (basedir == NULL) basedir = PATH_ASL_STORE; + + memset(&sb, 0, sizeof(struct stat)); + if (stat(basedir, &sb) != 0) return ASL_STATUS_INVALID_STORE; + if ((sb.st_mode & S_IFDIR) == 0) return ASL_STATUS_INVALID_STORE; + + out = (asl_store_t *)calloc(1, sizeof(asl_store_t)); + if (out == NULL) return ASL_STATUS_NO_MEMORY; + + if (basedir == NULL) out->base_dir = strdup(PATH_ASL_STORE); + else out->base_dir = strdup(basedir); + + if (out->base_dir == NULL) + { + free(out); + return ASL_STATUS_NO_MEMORY; + } + + *s = out; + return ASL_STATUS_OK; +} + +uint32_t +asl_store_max_file_size(asl_store_t *s, size_t max) +{ + if (s == NULL) return ASL_STATUS_INVALID_STORE; + + s->max_file_size = max; + return ASL_STATUS_OK; +} + +void +asl_store_file_closeall(asl_store_t *s) +{ + uint32_t i; + + if (s == NULL) return; + + for (i = 0; i < FILE_CACHE_SIZE; i++) + { + if (s->file_cache[i].f != NULL) asl_file_close(s->file_cache[i].f); + s->file_cache[i].f = NULL; + if (s->file_cache[i].path != NULL) free(s->file_cache[i].path); + s->file_cache[i].path = NULL; + s->file_cache[i].u = -1; + s->file_cache[i].g = -1; + s->file_cache[i].ts = 0; + } +} + +uint32_t +asl_store_close(asl_store_t *s) +{ + if (s == NULL) return ASL_STATUS_OK; + + if (s->base_dir != NULL) free(s->base_dir); + s->base_dir = NULL; + asl_file_close(s->db); + asl_store_file_closeall(s); + if (s->storedata != NULL) fclose(s->storedata); + + free(s); + + return ASL_STATUS_OK; +} + +uint32_t +asl_store_signal_sweep(asl_store_t *s) +{ + char *str; + int semfd; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + + asprintf(&str, "%s/%s", s->base_dir, FILE_ASL_STORE_SWEEP_SEMAPHORE); + if (str == NULL) return ASL_STATUS_NO_MEMORY; + + semfd = open(str, O_WRONLY | O_CREAT | O_NONBLOCK, 0644); + free(str); + + if (semfd < 0) return ASL_STATUS_WRITE_FAILED; + + close(semfd); + return ASL_STATUS_OK; +} + +/* + * Sweep the file cache. + * Close any files that have not been used in the last FILE_CACHE_TTL seconds. + * Returns least recently used or unused cache slot. + */ +static uint32_t +asl_store_file_cache_lru(asl_store_t *s, time_t now) +{ + time_t min; + uint32_t i, x; + + if (s == NULL) return 0; + + x = 0; + min = now - FILE_CACHE_TTL; + + for (i = 0; i < FILE_CACHE_SIZE; i++) + { + if (s->file_cache[i].ts < min) + { + asl_file_close(s->file_cache[i].f); + s->file_cache[i].f = NULL; + if (s->file_cache[i].path != NULL) free(s->file_cache[i].path); + s->file_cache[i].path = NULL; + s->file_cache[i].u = -1; + s->file_cache[i].g = -1; + s->file_cache[i].ts = 0; + } + + if (s->file_cache[i].ts < s->file_cache[x].ts) x = i; + } + + return x; +} + +uint32_t +asl_store_sweep_file_cache(asl_store_t *s) +{ + if (s == NULL) return ASL_STATUS_INVALID_STORE; + + asl_store_file_cache_lru(s, time(NULL)); + return ASL_STATUS_OK; +} + +static uint32_t +asl_store_file_open_write(asl_store_t *s, char *subpath, int32_t ruid, int32_t rgid, asl_file_t **f, time_t now, uint32_t check_cache) +{ + char *path; + mode_t m; + int32_t i, x, u, g; + uint32_t status; + asl_file_t *out; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + + /* see if the file is already open and in the cache */ + for (i = 0; i < FILE_CACHE_SIZE; i++) + { + if ((s->file_cache[i].u == ruid) && (s->file_cache[i].g == rgid) && (s->file_cache[i].f != NULL)) + { + s->file_cache[i].ts = now; + *f = s->file_cache[i].f; + if (check_cache == 1) asl_store_file_cache_lru(s, now); + return ASL_STATUS_OK; + } + } + + path = NULL; + u = 0; + g = 0; + m = 0644; + + if (ruid == -1) + { + if (rgid == -1) + { + asprintf(&path, "%s.asl", subpath); + } + else + { + g = rgid; + m = 0640; + asprintf(&path, "%s.G%d.asl", subpath, g); + } + } + else + { + u = ruid; + if (rgid == -1) + { + m = 0600; + asprintf(&path, "%s.U%d.asl", subpath, u); + } + else + { + g = rgid; + m = 0640; + asprintf(&path, "%s.U%d.G%u.asl", subpath, u, g); + } + } + + if (path == NULL) return ASL_STATUS_NO_MEMORY; + + out = NULL; + status = asl_file_open_write(path, m, u, g, &out); + if (status != ASL_STATUS_OK) + { + free(path); + return status; + } + + x = asl_store_file_cache_lru(s, now); + if (s->file_cache[x].f != NULL) asl_file_close(s->file_cache[x].f); + if (s->file_cache[x].path != NULL) free(s->file_cache[x].path); + + s->file_cache[x].f = out; + s->file_cache[x].path = path; + s->file_cache[x].u = ruid; + s->file_cache[x].g = rgid; + s->file_cache[x].ts = time(NULL); + + *f = out; + + return ASL_STATUS_OK; +} + +char * +asl_store_file_path(asl_store_t *s, asl_file_t *f) +{ + uint32_t i; + + if (s == NULL) return NULL; + + for (i = 0; i < FILE_CACHE_SIZE; i++) + { + if (s->file_cache[i].f == f) + { + if (s->file_cache[i].path == NULL) return NULL; + return strdup(s->file_cache[i].path); + } + } + + return NULL; +} + +void +asl_store_file_close(asl_store_t *s, asl_file_t *f) +{ + uint32_t i; + + if (s == NULL) return; + + for (i = 0; i < FILE_CACHE_SIZE; i++) + { + if (s->file_cache[i].f == f) + { + asl_file_close(s->file_cache[i].f); + s->file_cache[i].f = NULL; + if (s->file_cache[i].path != NULL) free(s->file_cache[i].path); + s->file_cache[i].path = NULL; + s->file_cache[i].u = -1; + s->file_cache[i].g = -1; + s->file_cache[i].ts = 0; + return; + } + } +} + +uint32_t +asl_store_save(asl_store_t *s, aslmsg msg) +{ + struct tm ctm; + time_t t, now; + char *path, *subpath; + const char *val; + uid_t ruid; + gid_t rgid; + asl_file_t *f; + uint32_t status, check_cache; + asl_store_t *tmp; + uint64_t xid, ftime; + size_t fsize; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (msg == NULL) return ASL_STATUS_INVALID_ARG; + + now = time(NULL); + + val = asl_get(msg, ASL_KEY_TIME); + t = 0; + if (val == NULL) t = now; + else t = asl_parse_time(val); + + if (t >= s->start_tomorrow) + { + if (now >= s->start_tomorrow) + { + /* new day begins */ + tmp = NULL; + status = asl_store_open_write(s->base_dir, &tmp); + asl_file_close(s->db); + s->db = NULL; + if (status != ASL_STATUS_OK) + { + fclose(s->storedata); + free(s->base_dir); + free(s); + return status; + } + + s->db = tmp->db; + s->start_today = tmp->start_today; + s->start_tomorrow = tmp->start_tomorrow; + free(tmp->base_dir); + fclose(tmp->storedata); + free(tmp); + + status = asl_store_signal_sweep(s); + /* allow this to fail quietly */ + } + } + + val = asl_get(msg, ASL_KEY_READ_UID); + ruid = -1; + if (val != NULL) ruid = atoi(val); + + val = asl_get(msg, ASL_KEY_READ_GID); + rgid = -1; + if (val != NULL) rgid = atoi(val); + + if (fseeko(s->storedata, 0, SEEK_SET) != 0) return ASL_STATUS_WRITE_FAILED; + + xid = asl_core_htonq(s->next_id); + if (fwrite(&xid, sizeof(uint64_t), 1, s->storedata) != 1) return ASL_STATUS_WRITE_FAILED; + + xid = s->next_id; + s->next_id++; + + check_cache = 0; + if ((s->last_write + FILE_CACHE_TTL) <= now) check_cache = 1; + + s->last_write = now; + + if ((t >= s->start_today) && (t < s->start_tomorrow) && (ruid == -1) && (rgid == -1)) + { + status = asl_file_save(s->db, msg, &xid); + if (check_cache == 1) asl_store_file_cache_lru(s, now); + return status; + } + + if (localtime_r((const time_t *)&t, &ctm) == NULL) return ASL_STATUS_FAILED; + + asprintf(&subpath, "%s/%d.%02d.%02d", s->base_dir, ctm.tm_year + 1900, ctm.tm_mon + 1, ctm.tm_mday); + if (subpath == NULL) return ASL_STATUS_NO_MEMORY; + + f = NULL; + status = asl_store_file_open_write(s, subpath, ruid, rgid, &f, now, check_cache); + free(subpath); + subpath = NULL; + + if (status != ASL_STATUS_OK) return status; + + status = asl_file_save(f, msg, &xid); + if (status != ASL_STATUS_OK) return status; + + fsize = asl_file_size(f); + ftime = asl_file_ctime(f); + + /* if file is larger than max_file_size, rename it and create semaphore file in the store */ + if ((s->max_file_size != 0) && (fsize > s->max_file_size)) + { + status = ASL_STATUS_OK; + + path = asl_store_file_path(s, f); + subpath = NULL; + + asl_store_file_close(s, f); + + if (path != NULL) + { + asprintf(&subpath, "%s.%llu", path, ftime); + if (subpath == NULL) + { + status = ASL_STATUS_NO_MEMORY; + } + else + { + if (rename(path, subpath) != 0) status = ASL_STATUS_FAILED; + free(subpath); + } + + free(path); + } + + if (status == ASL_STATUS_OK) status = asl_store_signal_sweep(s); + } + + return status; +} + +uint32_t +asl_store_match_timeout(asl_store_t *s, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction, uint32_t usec) +{ + DIR *dp; + struct dirent *dent; + uint32_t status; + asl_file_t *f; + char *path; + asl_file_list_t *files; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (res == NULL) return ASL_STATUS_INVALID_ARG; + + files = NULL; + + /* + * Open all readable files + */ + dp = opendir(s->base_dir); + if (dp == NULL) return ASL_STATUS_READ_FAILED; + + while ((dent = readdir(dp)) != NULL) + { + if (dent->d_name[0] == '.') continue; + + path = NULL; + asprintf(&path, "%s/%s", s->base_dir, dent->d_name); + + /* NB asl_file_open_read will fail if path is NULL, if the file is not an ASL store file, or if it isn't readable */ + status = asl_file_open_read(path, &f); + if (path != NULL) free(path); + if ((status != ASL_STATUS_OK) || (f == NULL)) continue; + + files = asl_file_list_add(files, f); + } + + closedir(dp); + + status = asl_file_list_match_timeout(files, query, res, last_id, start_id, count, direction, usec); + asl_file_list_close(files); + return status; +} + +uint32_t +asl_store_match(asl_store_t *s, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction) +{ + return asl_store_match_timeout(s, query, res, last_id, start_id, count, direction, 0); +} + +uint32_t +asl_store_match_start(asl_store_t *s, uint64_t start_id, int32_t direction) +{ + DIR *dp; + struct dirent *dent; + uint32_t status; + asl_file_t *f; + char *path; + asl_file_list_t *files; + + if (s == NULL) return ASL_STATUS_INVALID_STORE; + + if (s->work != NULL) asl_file_list_match_end(s->work); + s->work = NULL; + + files = NULL; + + /* + * Open all readable files + */ + dp = opendir(s->base_dir); + if (dp == NULL) return ASL_STATUS_READ_FAILED; + + while ((dent = readdir(dp)) != NULL) + { + if (dent->d_name[0] == '.') continue; + + path = NULL; + asprintf(&path, "%s/%s", s->base_dir, dent->d_name); + + /* NB asl_file_open_read will fail if path is NULL, if the file is not an ASL store file, or if it isn't readable */ + status = asl_file_open_read(path, &f); + if (path != NULL) free(path); + if ((status != ASL_STATUS_OK) || (f == NULL)) continue; + + files = asl_file_list_add(files, f); + } + + closedir(dp); + + s->work = asl_file_list_match_start(files, start_id, direction); + if (s->work == NULL) return ASL_STATUS_FAILED; + + return ASL_STATUS_OK; +} + +uint32_t +asl_store_match_next(asl_store_t *s, aslresponse query, aslresponse *res, uint32_t count) +{ + if (s == NULL) return ASL_STATUS_INVALID_STORE; + if (s->work == NULL) return ASL_STATUS_OK; + + return asl_file_list_match_next(s->work, query, res, count); +} diff --git a/gen/asl_store.h b/gen/asl_store.h new file mode 100644 index 0000000..faa817a --- /dev/null +++ b/gen/asl_store.h @@ -0,0 +1,82 @@ +#ifndef __ASL_STORE_H__ +#define __ASL_STORE_H__ + +/* + * Copyright (c) 2007-2008 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 2007 Apple Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include +#include +#include +#include + +#define PATH_ASL_STORE "/var/log/asl" +#define PATH_ASL_ARCHIVE "/var/log/asl.archive" +#define FILE_ASL_STORE_DATA "StoreData" +#define FILE_ASL_STORE_SWEEP_SEMAPHORE "SweepStore" + +#define FILE_CACHE_SIZE 64 +#define FILE_CACHE_TTL 300 + +typedef struct +{ + time_t ts; + uid_t u; + gid_t g; + char *path; + asl_file_t *f; +} asl_cached_file_t; + +typedef struct +{ + char *base_dir; + FILE *storedata; + uint64_t next_id; + asl_file_t *db; + asl_cached_file_t file_cache[FILE_CACHE_SIZE]; + void *work; + time_t start_today; + time_t start_tomorrow; + time_t last_write; + size_t max_file_size; +} asl_store_t; + +uint32_t asl_store_open_write(const char *basedir, asl_store_t **s); +uint32_t asl_store_open_read(const char *basedir, asl_store_t **s); +uint32_t asl_store_close(asl_store_t *s); +uint32_t asl_store_statistics(asl_store_t *s, aslmsg *msg); + +uint32_t asl_store_save(asl_store_t *s, aslmsg msg); + +uint32_t asl_store_match(asl_store_t *s, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction); +uint32_t asl_store_match_timeout(asl_store_t *s, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction, uint32_t usec); + +uint32_t asl_store_match_start(asl_store_t *s, uint64_t start_id, int32_t direction); +uint32_t asl_store_match_next(asl_store_t *s, aslresponse query, aslresponse *res, uint32_t count); + +uint32_t asl_store_max_file_size(asl_store_t *s, size_t max); +uint32_t asl_store_signal_sweep(asl_store_t *s); +uint32_t asl_store_sweep_file_cache(asl_store_t *s); + +#endif __ASL_STORE_H__ diff --git a/gen/asl_util.c b/gen/asl_util.c index a7240a6..4a0130b 100644 --- a/gen/asl_util.c +++ b/gen/asl_util.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2007 Apple Inc. All rights reserved. + * Copyright (c) 2006-2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -31,7 +31,9 @@ #include #include #include +#include #include +#include #define _PATH_ASL_IN "/var/run/asl_input" diff --git a/gen/clock-fbsd.c b/gen/clock-fbsd.c deleted file mode 100644 index ddfccbe..0000000 --- a/gen/clock-fbsd.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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[] = "@(#)clock.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/clock.c,v 1.3 2002/03/22 21:52:05 obrien Exp $"); - -#include -#include -#include - -/* - * 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 * CLOCKS_PER_SEC \ - + (r).tv_usec / (1000000 / CLOCKS_PER_SEC)) - -clock_t -clock() -{ - struct rusage ru; - - if (getrusage(RUSAGE_SELF, &ru)) - return ((clock_t) -1); - return((clock_t)((CONVTCK(ru.ru_utime) + CONVTCK(ru.ru_stime)))); -} diff --git a/gen/clock-fbsd.c b/gen/clock-fbsd.c new file mode 120000 index 0000000..7a89aae --- /dev/null +++ b/gen/clock-fbsd.c @@ -0,0 +1 @@ +./clock.c \ No newline at end of file diff --git a/gen/ctermid-fbsd.c b/gen/ctermid-fbsd.c deleted file mode 100644 index 6b2c682..0000000 --- a/gen/ctermid-fbsd.c +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ctermid.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/ctermid.c,v 1.3 2002/03/22 21:52:05 obrien Exp $"); - -#include -#include -#include - -char * -ctermid(char *s) -{ - static char def[] = _PATH_TTY; - - if (s) { - bcopy(def, s, sizeof(_PATH_TTY)); - return(s); - } - return(def); -} - - -char * -ctermid_r(char *s) -{ - return (s) ? ctermid(s) : NULL; -} diff --git a/gen/ctermid-fbsd.c b/gen/ctermid-fbsd.c new file mode 120000 index 0000000..0300f3c --- /dev/null +++ b/gen/ctermid-fbsd.c @@ -0,0 +1 @@ +./ctermid.c \ No newline at end of file diff --git a/gen/errno_-fbsd.c b/gen/errno_-fbsd.c deleted file mode 100644 index 7d98857..0000000 --- a/gen/errno_-fbsd.c +++ /dev/null @@ -1,30 +0,0 @@ -/*- - * Copyright (c) 2002 Peter Wemm - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/errno.c,v 1.1 2002/10/09 08:04:24 peter Exp $"); - -int errno; diff --git a/gen/errno_-fbsd.c b/gen/errno_-fbsd.c new file mode 120000 index 0000000..f3e3eb4 --- /dev/null +++ b/gen/errno_-fbsd.c @@ -0,0 +1 @@ +./errno_.c \ No newline at end of file diff --git a/gen/fmtcheck-fbsd.c b/gen/fmtcheck-fbsd.c deleted file mode 100644 index e907995..0000000 --- a/gen/fmtcheck-fbsd.c +++ /dev/null @@ -1,267 +0,0 @@ -/*- - * Copyright (c) 2000 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code was contributed to The NetBSD Foundation by Allen Briggs. - * - * 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 FOUNDATION 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. - */ - -/* $NetBSD: fmtcheck.c,v 1.2 2000/11/01 01:17:20 briggs Exp $ */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/fmtcheck.c,v 1.7 2004/05/02 10:55:05 das Exp $"); - -#include -#include -#include - -__weak_reference(__fmtcheck, fmtcheck); - -enum __e_fmtcheck_types { - FMTCHECK_START, - FMTCHECK_SHORT, - FMTCHECK_INT, - FMTCHECK_LONG, - FMTCHECK_QUAD, - FMTCHECK_PTRDIFFT, - FMTCHECK_SIZET, - FMTCHECK_SHORTPOINTER, - FMTCHECK_INTPOINTER, - FMTCHECK_LONGPOINTER, - FMTCHECK_QUADPOINTER, - FMTCHECK_PTRDIFFTPOINTER, - FMTCHECK_SIZETPOINTER, -#ifndef NO_FLOATING_POINT - FMTCHECK_DOUBLE, - FMTCHECK_LONGDOUBLE, -#endif - FMTCHECK_STRING, - FMTCHECK_WIDTH, - FMTCHECK_PRECISION, - FMTCHECK_DONE, - FMTCHECK_UNKNOWN -}; -typedef enum __e_fmtcheck_types EFT; - -#define RETURN(pf,f,r) do { \ - *(pf) = (f); \ - return r; \ - } /*NOTREACHED*/ /*CONSTCOND*/ while (0) - -static EFT -get_next_format_from_precision(const char **pf) -{ - int sh, lg, quad, longdouble, ptrdifft, sizet; - const char *f; - - sh = lg = quad = longdouble = ptrdifft = sizet = 0; - - f = *pf; - switch (*f) { - case 'h': - f++; - sh = 1; - break; - case 'l': - f++; - if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); - if (*f == 'l') { - f++; - quad = 1; - } else { - lg = 1; - } - break; - case 'q': - f++; - quad = 1; - break; - case 't': - f++; - ptrdifft = 1; - break; - case 'z': - f++; - sizet = 1; - break; - case 'L': - f++; - longdouble = 1; - break; - default: - break; - } - if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); - if (strchr("diouxX", *f)) { - if (longdouble) - RETURN(pf,f,FMTCHECK_UNKNOWN); - if (lg) - RETURN(pf,f,FMTCHECK_LONG); - if (quad) - RETURN(pf,f,FMTCHECK_QUAD); - if (ptrdifft) - RETURN(pf,f,FMTCHECK_PTRDIFFT); - if (sizet) - RETURN(pf,f,FMTCHECK_SIZET); - RETURN(pf,f,FMTCHECK_INT); - } - if (*f == 'n') { - if (longdouble) - RETURN(pf,f,FMTCHECK_UNKNOWN); - if (sh) - RETURN(pf,f,FMTCHECK_SHORTPOINTER); - if (lg) - RETURN(pf,f,FMTCHECK_LONGPOINTER); - if (quad) - RETURN(pf,f,FMTCHECK_QUADPOINTER); - if (ptrdifft) - RETURN(pf,f,FMTCHECK_PTRDIFFTPOINTER); - if (sizet) - RETURN(pf,f,FMTCHECK_SIZETPOINTER); - RETURN(pf,f,FMTCHECK_INTPOINTER); - } - if (strchr("DOU", *f)) { - if (sh + lg + quad + longdouble + ptrdifft + sizet) - RETURN(pf,f,FMTCHECK_UNKNOWN); - RETURN(pf,f,FMTCHECK_LONG); - } -#ifndef NO_FLOATING_POINT - if (strchr("aAeEfFgG", *f)) { - if (longdouble) - RETURN(pf,f,FMTCHECK_LONGDOUBLE); - if (sh + lg + quad + ptrdifft + sizet) - RETURN(pf,f,FMTCHECK_UNKNOWN); - RETURN(pf,f,FMTCHECK_DOUBLE); - } -#endif - if (*f == 'c') { - if (sh + lg + quad + longdouble + ptrdifft + sizet) - RETURN(pf,f,FMTCHECK_UNKNOWN); - RETURN(pf,f,FMTCHECK_INT); - } - if (*f == 's') { - if (sh + lg + quad + longdouble + ptrdifft + sizet) - RETURN(pf,f,FMTCHECK_UNKNOWN); - RETURN(pf,f,FMTCHECK_STRING); - } - if (*f == 'p') { - if (sh + lg + quad + longdouble + ptrdifft + sizet) - RETURN(pf,f,FMTCHECK_UNKNOWN); - RETURN(pf,f,FMTCHECK_LONG); - } - RETURN(pf,f,FMTCHECK_UNKNOWN); - /*NOTREACHED*/ -} - -static EFT -get_next_format_from_width(const char **pf) -{ - const char *f; - - f = *pf; - if (*f == '.') { - f++; - if (*f == '*') { - RETURN(pf,f,FMTCHECK_PRECISION); - } - /* eat any precision (empty is allowed) */ - while (isdigit(*f)) f++; - if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); - } - RETURN(pf,f,get_next_format_from_precision(pf)); - /*NOTREACHED*/ -} - -static EFT -get_next_format(const char **pf, EFT eft) -{ - int infmt; - const char *f; - - if (eft == FMTCHECK_WIDTH) { - (*pf)++; - return get_next_format_from_width(pf); - } else if (eft == FMTCHECK_PRECISION) { - (*pf)++; - return get_next_format_from_precision(pf); - } - - f = *pf; - infmt = 0; - while (!infmt) { - f = strchr(f, '%'); - if (f == NULL) - RETURN(pf,f,FMTCHECK_DONE); - f++; - if (!*f) - RETURN(pf,f,FMTCHECK_UNKNOWN); - if (*f != '%') - infmt = 1; - else - f++; - } - - /* Eat any of the flags */ - while (*f && (strchr("#0- +", *f))) - f++; - - if (*f == '*') { - RETURN(pf,f,FMTCHECK_WIDTH); - } - /* eat any width */ - while (isdigit(*f)) f++; - if (!*f) { - RETURN(pf,f,FMTCHECK_UNKNOWN); - } - - RETURN(pf,f,get_next_format_from_width(pf)); - /*NOTREACHED*/ -} - -__const char * -__fmtcheck(const char *f1, const char *f2) -{ - const char *f1p, *f2p; - EFT f1t, f2t; - - if (!f1) return f2; - - f1p = f1; - f1t = FMTCHECK_START; - f2p = f2; - f2t = FMTCHECK_START; - while ((f1t = get_next_format(&f1p, f1t)) != FMTCHECK_DONE) { - if (f1t == FMTCHECK_UNKNOWN) - return f2; - f2t = get_next_format(&f2p, f2t); - if (f1t != f2t) - return f2; - } - return f1; -} diff --git a/gen/fmtcheck-fbsd.c b/gen/fmtcheck-fbsd.c new file mode 120000 index 0000000..b7c0fe8 --- /dev/null +++ b/gen/fmtcheck-fbsd.c @@ -0,0 +1 @@ +./fmtcheck.c \ No newline at end of file diff --git a/gen/ftok-fbsd.c b/gen/ftok-fbsd.c deleted file mode 100644 index 6c7157a..0000000 --- a/gen/ftok-fbsd.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 1994 SigmaSoft, Th. Lockert - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/ftok.c,v 1.7 2004/06/01 06:53:07 tjr Exp $"); - -#include -#include -#include - -key_t -ftok(path, id) - const char *path; - int 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/gen/ftok-fbsd.c b/gen/ftok-fbsd.c new file mode 120000 index 0000000..19e8277 --- /dev/null +++ b/gen/ftok-fbsd.c @@ -0,0 +1 @@ +./ftok.c \ No newline at end of file diff --git a/gen/getbsize-fbsd.c b/gen/getbsize-fbsd.c deleted file mode 100644 index b922f1c..0000000 --- a/gen/getbsize-fbsd.c +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getbsize.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/getbsize.c,v 1.7 2002/12/30 19:04:06 obrien Exp $"); - -#include -#include -#include -#include - -char * -getbsize(headerlenp, blocksizep) - int *headerlenp; - long *blocksizep; -{ - static char header[20]; - long n, max, mul, blocksize; - char *ep, *p; - const char *form; - -#define KB (1024L) -#define MB (1024L * 1024L) -#define GB (1024L * 1024L * 1024L) -#define MAXB GB /* No tera, peta, nor exa. */ - form = ""; - if ((p = getenv("BLOCKSIZE")) != NULL && *p != '\0') { - if ((n = strtol(p, &ep, 10)) < 0) - goto underflow; - if (n == 0) - n = 1; - if (*ep && ep[1]) - goto fmterr; - switch (*ep) { - case 'G': case 'g': - form = "G"; - max = MAXB / GB; - mul = GB; - break; - case 'K': case 'k': - form = "K"; - max = MAXB / KB; - mul = KB; - break; - case 'M': case 'm': - form = "M"; - max = MAXB / MB; - mul = MB; - break; - case '\0': - max = MAXB; - mul = 1; - break; - default: -fmterr: warnx("%s: unknown blocksize", p); - n = 512; - mul = 1; - break; - } - if (n > max) { - warnx("maximum blocksize is %ldG", MAXB / GB); - n = max; - } - if ((blocksize = n * mul) < 512) { -underflow: warnx("minimum blocksize is 512"); - form = ""; - blocksize = n = 512; - } - } else - blocksize = n = 512; - - (void)snprintf(header, sizeof(header), "%ld%s-blocks", n, form); - *headerlenp = strlen(header); - *blocksizep = blocksize; - return (header); -} diff --git a/gen/getbsize-fbsd.c b/gen/getbsize-fbsd.c new file mode 120000 index 0000000..e8f2107 --- /dev/null +++ b/gen/getbsize-fbsd.c @@ -0,0 +1 @@ +./getbsize.c \ No newline at end of file diff --git a/gen/getmntinfo-fbsd.c b/gen/getmntinfo-fbsd.c deleted file mode 100644 index 383df1e..0000000 --- a/gen/getmntinfo-fbsd.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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[] = "@(#)getmntinfo.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/getmntinfo.c,v 1.4 2002/02/01 00:57:29 obrien Exp $"); - -#include -#include -#include -#include - -/* - * Return information about mounted filesystems. - */ -int -getmntinfo(mntbufp, flags) - struct statfs **mntbufp; - int flags; -{ - static struct statfs *mntbuf; - static int mntsize; - static long bufsize; - - if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) - return (0); - if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) - return (0); - while (bufsize <= mntsize * sizeof(struct statfs)) { - if (mntbuf) - free(mntbuf); - bufsize = (mntsize + 1) * sizeof(struct statfs); - if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0) - return (0); - if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) - return (0); - } - *mntbufp = mntbuf; - return (mntsize); -} diff --git a/gen/getmntinfo-fbsd.c b/gen/getmntinfo-fbsd.c new file mode 120000 index 0000000..abe4b01 --- /dev/null +++ b/gen/getmntinfo-fbsd.c @@ -0,0 +1 @@ +./getmntinfo.c \ No newline at end of file diff --git a/gen/getmntinfo.3 b/gen/getmntinfo.3 index f7fb48e..207f366 100644 --- a/gen/getmntinfo.3 +++ b/gen/getmntinfo.3 @@ -46,8 +46,10 @@ .In sys/mount.h .Ft int .Fn getmntinfo "struct statfs **mntbufp" "int flags" +#ifdef UNIFDEF_LEGACY_64_APIS .Ft int .Fn getmntinfo64 "struct statfs64 **mntbufp" "int flags" +#endif /* UNIFDEF_LEGACY_64_APIS */ .Sh DESCRIPTION The .Fn getmntinfo @@ -56,12 +58,14 @@ returns an array of .Ft statfs structures describing each currently mounted file system (see .Xr statfs 2 ) . +#ifdef UNIFDEF_LEGACY_64_APIS Likewise, the .Fn getmntinfo64 function returns an array of .Ft statfs64 structures describing each currently mounted file system. +#endif /* UNIFDEF_LEGACY_64_APIS */ .Pp The .Fn getmntinfo @@ -69,6 +73,7 @@ function passes its .Fa flags argument transparently to +#ifdef UNIFDEF_LEGACY_64_APIS .Xr getfsstat 2 , while the .Fn getmntinfo64 @@ -77,12 +82,19 @@ passes its .Fa flags argument transparently to .Fn getfsstat64 . +#else /* !UNIFDEF_LEGACY_64_APIS */ +.Xr getfsstat 2 . +#endif /* UNIFDEF_LEGACY_64_APIS */ .Sh RETURN VALUES On successful completion, .Fn getmntinfo +#ifdef UNIFDEF_LEGACY_64_APIS and .Fn getmntinfo64 return a count of the number of elements in the array. +#else /* !UNIFDEF_LEGACY_64_APIS */ +returns a count of the number of elements in the array. +#endif /* UNIFDEF_LEGACY_64_APIS */ The pointer to the array is stored into .Fa mntbufp . .Pp @@ -93,15 +105,21 @@ Although the pointer .Fa mntbufp will be unmodified, any information previously returned by .Fn getmntinfo +#ifdef UNIFDEF_LEGACY_64_APIS or .Fn getmntinfo64 +#endif /* UNIFDEF_LEGACY_64_APIS */ will be lost. .Sh ERRORS The .Fn getmntinfo +#ifdef UNIFDEF_LEGACY_64_APIS and .Fn getmntinfo64 functions +#else /* !UNIFDEF_LEGACY_64_APIS */ +function +#endif /* UNIFDEF_LEGACY_64_APIS */ may fail and set errno for any of the errors specified for the library routines .Xr getfsstat 2 @@ -120,21 +138,29 @@ function first appeared in .Sh BUGS The .Fn getmntinfo +#ifdef UNIFDEF_LEGACY_64_APIS and .Fn getmntinfo64 functions write the array of structures to an internal static object +#else /* !UNIFDEF_LEGACY_64_APIS */ +function write the array of structures to an internal static object +#endif /* UNIFDEF_LEGACY_64_APIS */ and returns a pointer to that object. Subsequent calls to .Fn getmntinfo +#ifdef UNIFDEF_LEGACY_64_APIS and .Fn getmntinfo64 +#endif /* UNIFDEF_LEGACY_64_APIS */ will modify the same object. .Pp The memory allocated by .Fn getmntinfo +#ifdef UNIFDEF_LEGACY_64_APIS and .Fn getmntinfo64 +#endif /* UNIFDEF_LEGACY_64_APIS */ cannot be .Xr free 3 Ns 'd by the application. diff --git a/gen/getpagesize-fbsd.c b/gen/getpagesize-fbsd.c deleted file mode 100644 index 3c8881e..0000000 --- a/gen/getpagesize-fbsd.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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[] = "@(#)getpagesize.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/getpagesize.c,v 1.4 2002/02/01 00:57:29 obrien Exp $"); - -#include -#include - -/* - * This is unlikely to change over the running time of any - * program, so we cache the result to save some syscalls. - * - * NB: This function may be called from malloc(3) at initialization - * NB: so must not result in a malloc(3) related call! - */ - -int -getpagesize() -{ - int mib[2]; - static int value; - size_t size; - - 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/gen/getpagesize-fbsd.c b/gen/getpagesize-fbsd.c new file mode 120000 index 0000000..4b61652 --- /dev/null +++ b/gen/getpagesize-fbsd.c @@ -0,0 +1 @@ +./getpagesize.c \ No newline at end of file diff --git a/gen/getpeereid-fbsd.c b/gen/getpeereid-fbsd.c deleted file mode 100644 index 5608c48..0000000 --- a/gen/getpeereid-fbsd.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2001 Dima Dorfman. - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/getpeereid.c,v 1.6 2002/12/16 13:42:13 maxim Exp $"); - -#include -#include -#include -#include - -#include -#include - -int -getpeereid(int s, uid_t *euid, gid_t *egid) -{ - struct xucred xuc; - socklen_t xuclen; - int error; - - xuclen = sizeof(xuc); - error = getsockopt(s, 0, LOCAL_PEERCRED, &xuc, &xuclen); - if (error != 0) - return (error); - if (xuc.cr_version != XUCRED_VERSION) - return (EINVAL); - *euid = xuc.cr_uid; - *egid = xuc.cr_gid; - return (0); -} diff --git a/gen/getpeereid-fbsd.c b/gen/getpeereid-fbsd.c new file mode 120000 index 0000000..843d1f4 --- /dev/null +++ b/gen/getpeereid-fbsd.c @@ -0,0 +1 @@ +./getpeereid.c \ No newline at end of file diff --git a/gen/glob-fbsd.c b/gen/glob-fbsd.c index 49d0cbb..30df8a7 100644 --- a/gen/glob-fbsd.c +++ b/gen/glob-fbsd.c @@ -144,42 +144,37 @@ typedef char Char; #define M_SET META('[') #define ismeta(c) (((c)&M_QUOTE) != 0) -static int g_lstat(Char *, struct stat *, glob_t *, locale_t); -static int g_stat(Char *, struct stat *, glob_t *, locale_t); +#define compare __gl_compare #define g_Ctoc __gl_g_Ctoc -#define glob0 __gl_glob0 -#define glob2_32 __gl_glob0_32 -#define glob2_64 __gl_glob0_64 -#define glob3 __gl_glob3 -#define globexp1 __gl_globexp1 +#define g_strchr __gl_g_strchr #define globextend __gl_globextend +#define globtilde __gl_globtilde +#define match __gl_match +__private_extern__ int compare(const void *, const void *); __private_extern__ int g_Ctoc(const Char *, char *, u_int, locale_t); -__private_extern__ int glob0(const Char *, glob_t *, int *, locale_t); -__private_extern__ int glob2_32(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t); -__private_extern__ int glob2_64(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t); -__private_extern__ int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *, locale_t); -__private_extern__ int globexp1(const Char *, glob_t *, int *, locale_t); +__private_extern__ Char *g_strchr(Char *, wchar_t); __private_extern__ int globextend(const Char *, glob_t *, int *, locale_t); +__private_extern__ const Char * + globtilde(const Char *, Char *, size_t, glob_t *); +__private_extern__ int match(Char *, Char *, Char *, locale_t); -#ifndef BUILDING_VARIANT -#define glob2(a,b,c,d,e,f,g) (((e)->gl_flags & GLOB_INODE64) ? glob2_64((a),(b),(c),(d),(e),(f),(g)) : glob2_32((a),(b),(c),(d),(e),(f),(g))) -static int compare(const void *, const void *); +static int g_lstat(Char *, struct stat *, glob_t *, locale_t); static DIR *g_opendir(Char *, glob_t *, locale_t); -static Char *g_strchr(Char *, wchar_t); #ifdef notdef static Char *g_strcat(Char *, const Char *); #endif +static int g_stat(Char *, struct stat *, glob_t *, locale_t); +static int glob0(const Char *, glob_t *, int *, locale_t); static int glob1(Char *, glob_t *, int *, locale_t); -static const Char * - globtilde(const Char *, Char *, size_t, glob_t *); +static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t); +static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *, locale_t); +static int globexp1(const Char *, glob_t *, int *, locale_t); static int globexp2(const Char *, const Char *, glob_t *, int *, int *, locale_t); -static int match(Char *, Char *, Char *, locale_t); #ifdef DEBUG static void qprintf(const char *, Char *); #endif -#endif /* !BUILDING_VARIANT */ int glob(pattern, flags, errfunc, pglob) @@ -209,12 +204,7 @@ glob(pattern, flags, errfunc, pglob) limit = ARG_MAX; } else limit = 0; -#if __DARWIN_64_BIT_INO_T pglob->gl_flags = flags & ~GLOB_MAGCHAR; - pglob->gl_flags |= GLOB_INODE64; -#else /* !__DARWIN_64_BIT_INO_T */ - pglob->gl_flags = flags & ~(GLOB_MAGCHAR | GLOB_INODE64); -#endif /* __DARWIN_64_BIT_INO_T */ pglob->gl_errfunc = errfunc; pglob->gl_matchc = 0; @@ -260,13 +250,12 @@ glob(pattern, flags, errfunc, pglob) return glob0(patbuf, pglob, &limit, loc); } -#ifndef BUILDING_VARIANT /* * Expand recursively a glob {} pattern. When there is no more expansion * invoke the standard globbing routine to glob the rest of the magic * characters */ -__private_extern__ int +static int globexp1(pattern, pglob, limit, loc) const Char *pattern; glob_t *pglob; @@ -398,10 +387,11 @@ globexp2(ptr, pattern, pglob, rv, limit, loc) +#ifndef BUILDING_VARIANT /* * expand tilde from the passwd file. */ -static const Char * +__private_extern__ const Char * globtilde(pattern, patbuf, patbuf_len, pglob) const Char *pattern; Char *patbuf; @@ -463,6 +453,7 @@ globtilde(pattern, patbuf, patbuf_len, pglob) return patbuf; } +#endif /* BUILDING_VARIANT */ /* @@ -471,7 +462,7 @@ globtilde(pattern, patbuf, patbuf_len, pglob) * sorts the list (unless unsorted operation is requested). Returns 0 * if things went well, nonzero if errors occurred. */ -__private_extern__ int +static int glob0(pattern, pglob, limit, loc) const Char *pattern; glob_t *pglob; @@ -566,12 +557,14 @@ glob0(pattern, pglob, limit, loc) return(0); } -static int +#ifndef BUILDING_VARIANT +__private_extern__ int compare(p, q) const void *p, *q; { return(strcoll(*(char **)p, *(char **)q)); } +#endif /* BUILDING_VARIANT */ static int glob1(pattern, pglob, limit, loc) @@ -588,19 +581,14 @@ glob1(pattern, pglob, limit, loc) return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1, pattern, pglob, limit, loc)); } -#endif /* !BUILDING_VARIANT */ /* * The functions glob2 and glob3 are mutually recursive; there is one level * of recursion for each segment in the pattern that contains one or more * meta characters. */ -__private_extern__ int -#if __DARWIN_64_BIT_INO_T -glob2_64(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc) -#else /* !__DARWIN_64_BIT_INO_T */ -glob2_32(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc) -#endif /* __DARWIN_64_BIT_INO_T */ +static int +glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc) Char *pathbuf, *pathend, *pathend_last, *pattern; glob_t *pglob; int *limit; @@ -660,8 +648,7 @@ glob2_32(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc) /* NOTREACHED */ } -#ifndef BUILDING_VARIANT -__private_extern__ int +static int glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit, loc) Char *pathbuf, *pathend, *pathend_last, *pattern, *restpattern; glob_t *pglob; @@ -748,6 +735,7 @@ glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit, loc) } +#ifndef BUILDING_VARIANT /* * Extend the gl_pathv member of a glob_t structure to accomodate a new item, * add the new item, and update gl_pathc. @@ -818,7 +806,7 @@ globextend(path, pglob, limit, loc) * pattern matching function for filenames. Each occurrence of the * * pattern causes a recursion level. */ -static int +__private_extern__ int match(name, pat, patend, loc) Char *name, *pat, *patend; locale_t loc; @@ -887,6 +875,7 @@ globfree(pglob) pglob->gl_pathv = NULL; } } +#endif /* !BUILDING_VARIANT */ static DIR * g_opendir(str, pglob, loc) @@ -908,7 +897,6 @@ g_opendir(str, pglob, loc) return(opendir(buf)); } -#endif /* !BUILDING_VARIANT */ static int g_lstat(fn, sb, pglob, loc) @@ -947,7 +935,7 @@ g_stat(fn, sb, pglob, loc) } #ifndef BUILDING_VARIANT -static Char * +__private_extern__ Char * g_strchr(str, ch) Char *str; wchar_t ch; diff --git a/gen/isinf.c b/gen/isinf.c index cc2902d..cf0f5d2 100644 --- a/gen/isinf.c +++ b/gen/isinf.c @@ -28,5 +28,5 @@ int isinf(double d) { - return __isinfd(d); + return __inline_isinfd(d); } diff --git a/gen/isnan.c b/gen/isnan.c index 300d959..2eaf6e0 100644 --- a/gen/isnan.c +++ b/gen/isnan.c @@ -28,5 +28,5 @@ int isnan(double d) { - return __isnand(d); + return __inline_isnand(d); } diff --git a/gen/psignal-fbsd.c b/gen/psignal-fbsd.c deleted file mode 100644 index 832e04b..0000000 --- a/gen/psignal-fbsd.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)psignal.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/psignal.c,v 1.7 2002/02/01 01:08:48 obrien Exp $"); - -/* - * Print the name of the signal indicated - * along with the supplied message. - */ -#include "namespace.h" -#include -#include -#include -#include "un-namespace.h" - -void -psignal(sig, s) - unsigned int sig; - const char *s; -{ - const char *c; - - if (sig < NSIG) - c = sys_siglist[sig]; - else - c = "Unknown signal"; - if (s != NULL && *s != '\0') { - (void)_write(STDERR_FILENO, s, strlen(s)); - (void)_write(STDERR_FILENO, ": ", 2); - } - (void)_write(STDERR_FILENO, c, strlen(c)); - (void)_write(STDERR_FILENO, "\n", 1); -} diff --git a/gen/psignal-fbsd.c b/gen/psignal-fbsd.c new file mode 120000 index 0000000..993ff39 --- /dev/null +++ b/gen/psignal-fbsd.c @@ -0,0 +1 @@ +./psignal.c \ No newline at end of file diff --git a/gen/raise-fbsd.c b/gen/raise-fbsd.c deleted file mode 100644 index 4a94cb9..0000000 --- a/gen/raise-fbsd.c +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)raise.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/raise.c,v 1.4 2003/07/19 05:22:56 davidxu Exp $"); - -#include -#include - -__weak_reference(__raise, raise); -__weak_reference(__raise, _raise); - -int -__raise(s) - int s; -{ - return(kill(getpid(), s)); -} diff --git a/gen/raise-fbsd.c b/gen/raise-fbsd.c new file mode 120000 index 0000000..9229902 --- /dev/null +++ b/gen/raise-fbsd.c @@ -0,0 +1 @@ +./raise.c \ No newline at end of file diff --git a/gen/rewinddir-fbsd.c b/gen/rewinddir-fbsd.c deleted file mode 100644 index dae75cc..0000000 --- a/gen/rewinddir-fbsd.c +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rewinddir.c 8.1 (Berkeley) 6/8/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/rewinddir.c,v 1.5 2002/02/01 00:57:29 obrien Exp $"); - -#include -#include - -#include "telldir.h" - -void -rewinddir(dirp) - DIR *dirp; -{ - - _seekdir(dirp, dirp->dd_rewind); - dirp->dd_rewind = telldir(dirp); -} diff --git a/gen/rewinddir-fbsd.c b/gen/rewinddir-fbsd.c new file mode 120000 index 0000000..e39837e --- /dev/null +++ b/gen/rewinddir-fbsd.c @@ -0,0 +1 @@ +./rewinddir.c \ No newline at end of file diff --git a/gen/scandir-fbsd.c b/gen/scandir-fbsd.c deleted file mode 100644 index cf79bce..0000000 --- a/gen/scandir-fbsd.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)scandir.c 8.3 (Berkeley) 1/2/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/scandir.c,v 1.7 2002/02/01 01:32:19 obrien Exp $"); - -/* - * Scan the directory dirname calling select to make a list of selected - * directory entries then sort using qsort and compare routine dcomp. - * Returns the number of entries and a pointer to a list of pointers to - * struct dirent (through namelist). Returns -1 if there were any errors. - */ - -#include "namespace.h" -#include -#include -#include -#include -#include -#include "un-namespace.h" - -/* - * The DIRSIZ macro is the minimum record length which will hold the directory - * entry. This requires the amount of space in struct dirent without the - * d_name field, plus enough space for the name and a terminating nul byte - * (dp->d_namlen + 1), rounded up to a 4 byte boundary. - */ -#undef DIRSIZ -#define DIRSIZ(dp) \ - ((sizeof(struct dirent) - sizeof(dp)->d_name) + \ - (((dp)->d_namlen + 1 + 3) &~ 3)) - -int -scandir(dirname, namelist, select, dcomp) - const char *dirname; - struct dirent ***namelist; - int (*select)(struct dirent *); - int (*dcomp)(const void *, const void *); -{ - struct dirent *d, *p, **names = NULL; - size_t nitems = 0; - struct stat stb; - long arraysz; - DIR *dirp; - - if ((dirp = opendir(dirname)) == NULL) - return(-1); - if (_fstat(dirp->dd_fd, &stb) < 0) - goto fail; - - /* - * estimate the array size by taking the size of the directory file - * and dividing it by a multiple of the minimum size entry. - */ - arraysz = (stb.st_size / 24); - names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); - if (names == NULL) - goto fail; - - while ((d = readdir(dirp)) != NULL) { - if (select != NULL && !(*select)(d)) - continue; /* just selected names */ - /* - * Make a minimum size copy of the data - */ - p = (struct dirent *)malloc(DIRSIZ(d)); - if (p == NULL) - goto fail; - 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); - /* - * Check to make sure the array has space left and - * realloc the maximum size. - */ - if (nitems >= arraysz) { - const int inc = 10; /* increase by this much */ - struct dirent **names2; - - names2 = (struct dirent **)realloc((char *)names, - (arraysz + inc) * sizeof(struct dirent *)); - if (names2 == NULL) { - free(p); - goto fail; - } - names = names2; - arraysz += inc; - } - names[nitems++] = p; - } - closedir(dirp); - if (nitems && dcomp != NULL) - qsort(names, nitems, sizeof(struct dirent *), dcomp); - *namelist = names; - return(nitems); - -fail: - while (nitems > 0) - free(names[--nitems]); - free(names); - closedir(dirp); - return -1; -} - -/* - * Alphabetic order comparison routine for those who want it. - */ -int -alphasort(d1, d2) - const void *d1; - const void *d2; -{ - return(strcmp((*(struct dirent **)d1)->d_name, - (*(struct dirent **)d2)->d_name)); -} diff --git a/gen/scandir-fbsd.c b/gen/scandir-fbsd.c new file mode 120000 index 0000000..b9bd40c --- /dev/null +++ b/gen/scandir-fbsd.c @@ -0,0 +1 @@ +./scandir.c \ No newline at end of file diff --git a/gen/seekdir-fbsd.c b/gen/seekdir-fbsd.c deleted file mode 100644 index 5385819..0000000 --- a/gen/seekdir-fbsd.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)seekdir.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/seekdir.c,v 1.5 2002/02/01 00:57:29 obrien Exp $"); - -#include "namespace.h" -#include -#include -#include -#include "un-namespace.h" - -#include "libc_private.h" -#include "telldir.h" - -/* - * Seek to an entry in a directory. - * _seekdir is in telldir.c so that it can share opaque data structures. - */ -void -seekdir(dirp, loc) - DIR *dirp; - long loc; -{ - if (__isthreaded) - _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); - _seekdir(dirp, loc); - if (__isthreaded) - _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); -} diff --git a/gen/seekdir-fbsd.c b/gen/seekdir-fbsd.c new file mode 120000 index 0000000..d04fec6 --- /dev/null +++ b/gen/seekdir-fbsd.c @@ -0,0 +1 @@ +./seekdir.c \ No newline at end of file diff --git a/gen/sethostname-fbsd.c b/gen/sethostname-fbsd.c deleted file mode 100644 index 3a15727..0000000 --- a/gen/sethostname-fbsd.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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[] = "@(#)sethostname.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/sethostname.c,v 1.4 2002/05/28 16:59:39 alfred Exp $"); - -#include -#include - -int -sethostname(const char *name, int namelen) -{ - int mib[2]; - - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTNAME; - if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1) - return (-1); - return (0); -} diff --git a/gen/sethostname-fbsd.c b/gen/sethostname-fbsd.c new file mode 120000 index 0000000..2501195 --- /dev/null +++ b/gen/sethostname-fbsd.c @@ -0,0 +1 @@ +./sethostname.c \ No newline at end of file diff --git a/gen/setmode-fbsd.c b/gen/setmode-fbsd.c deleted file mode 100644 index 3e4a6ee..0000000 --- a/gen/setmode-fbsd.c +++ /dev/null @@ -1,459 +0,0 @@ -/* - * Copyright (c) 1989, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Dave Borman at Cray Research, Inc. - * - * 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[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/setmode.c,v 1.9 2003/02/23 00:24:03 mikeh Exp $"); - -#include "namespace.h" -#include -#include - -#include -#include -#include -#include -#include - -#ifdef SETMODE_DEBUG -#include -#endif -#include "un-namespace.h" - -#define SET_LEN 6 /* initial # of bitcmd struct to malloc */ -#define SET_LEN_INCR 4 /* # of bitcmd structs to add as needed */ - -typedef struct bitcmd { - char cmd; - char cmd2; - mode_t bits; -} BITCMD; - -#define CMD2_CLR 0x01 -#define CMD2_SET 0x02 -#define CMD2_GBITS 0x04 -#define CMD2_OBITS 0x08 -#define CMD2_UBITS 0x10 - -static BITCMD *addcmd(BITCMD *, int, int, int, u_int); -static void compress_mode(BITCMD *); -#ifdef SETMODE_DEBUG -static void dumpmode(BITCMD *); -#endif - -/* - * Given the old mode and an array of bitcmd structures, apply the operations - * described in the bitcmd structures to the old mode, and return the new mode. - * Note that there is no '=' command; a strict assignment is just a '-' (clear - * bits) followed by a '+' (set bits). - */ -mode_t -getmode(bbox, omode) - const void *bbox; - mode_t omode; -{ - const BITCMD *set; - mode_t clrval, newmode, value; - - set = (const BITCMD *)bbox; - newmode = omode; - for (value = 0;; set++) - switch(set->cmd) { - /* - * When copying the user, group or other bits around, we "know" - * where the bits are in the mode so that we can do shifts to - * copy them around. If we don't use shifts, it gets real - * grundgy with lots of single bit checks and bit sets. - */ - case 'u': - value = (newmode & S_IRWXU) >> 6; - goto common; - - case 'g': - value = (newmode & S_IRWXG) >> 3; - goto common; - - case 'o': - value = newmode & S_IRWXO; -common: if (set->cmd2 & CMD2_CLR) { - clrval = - (set->cmd2 & CMD2_SET) ? S_IRWXO : value; - if (set->cmd2 & CMD2_UBITS) - newmode &= ~((clrval<<6) & set->bits); - if (set->cmd2 & CMD2_GBITS) - newmode &= ~((clrval<<3) & set->bits); - if (set->cmd2 & CMD2_OBITS) - newmode &= ~(clrval & set->bits); - } - if (set->cmd2 & CMD2_SET) { - if (set->cmd2 & CMD2_UBITS) - newmode |= (value<<6) & set->bits; - if (set->cmd2 & CMD2_GBITS) - newmode |= (value<<3) & set->bits; - if (set->cmd2 & CMD2_OBITS) - newmode |= value & set->bits; - } - break; - - case '+': - newmode |= set->bits; - break; - - case '-': - newmode &= ~set->bits; - break; - - case 'X': - if (omode & (S_IFDIR|S_IXUSR|S_IXGRP|S_IXOTH)) - newmode |= set->bits; - break; - - case '\0': - default: -#ifdef SETMODE_DEBUG - (void)printf("getmode:%04o -> %04o\n", omode, newmode); -#endif - return (newmode); - } -} - -#define ADDCMD(a, b, c, d) \ - if (set >= endset) { \ - BITCMD *newset; \ - setlen += SET_LEN_INCR; \ - newset = realloc(saveset, sizeof(BITCMD) * setlen); \ - if (!newset) { \ - if (saveset) \ - free(saveset); \ - saveset = NULL; \ - return (NULL); \ - } \ - set = newset + (set - saveset); \ - saveset = newset; \ - endset = newset + (setlen - 2); \ - } \ - set = addcmd(set, (a), (b), (c), (d)) - -#define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) - -void * -setmode(p) - const char *p; -{ - int perm, who; - char op, *ep; - BITCMD *set, *saveset, *endset; - sigset_t sigset, sigoset; - mode_t mask; - int equalopdone=0, permXbits, setlen; - long perml; - - if (!*p) - return (NULL); - - /* - * Get a copy of the mask for the permissions that are mask relative. - * Flip the bits, we want what's not set. Since it's possible that - * the caller is opening files inside a signal handler, protect them - * as best we can. - */ - sigfillset(&sigset); - (void)_sigprocmask(SIG_BLOCK, &sigset, &sigoset); - (void)umask(mask = umask(0)); - mask = ~mask; - (void)_sigprocmask(SIG_SETMASK, &sigoset, NULL); - - setlen = SET_LEN + 2; - - if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL) - return (NULL); - saveset = set; - endset = set + (setlen - 2); - - /* - * If an absolute number, get it and return; disallow non-octal digits - * or illegal bits. - */ - if (isdigit((unsigned char)*p)) { - perml = strtol(p, &ep, 8); - if (*ep || perml < 0 || perml & ~(STANDARD_BITS|S_ISTXT)) { - free(saveset); - return (NULL); - } - perm = (mode_t)perml; - ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask); - set->cmd = 0; - return (saveset); - } - - /* - * Build list of structures to set/clear/copy bits as described by - * each clause of the symbolic mode. - */ - for (;;) { - /* First, find out which bits might be modified. */ - for (who = 0;; ++p) { - switch (*p) { - case 'a': - who |= STANDARD_BITS; - break; - case 'u': - who |= S_ISUID|S_IRWXU; - break; - case 'g': - who |= S_ISGID|S_IRWXG; - break; - case 'o': - who |= S_IRWXO; - break; - default: - goto getop; - } - } - -getop: if ((op = *p++) != '+' && op != '-' && op != '=') { - free(saveset); - return (NULL); - } - if (op == '=') - equalopdone = 0; - - who &= ~S_ISTXT; - for (perm = 0, permXbits = 0;; ++p) { - switch (*p) { - case 'r': - perm |= S_IRUSR|S_IRGRP|S_IROTH; - break; - case 's': - /* If only "other" bits ignore set-id. */ - if (!who || who & ~S_IRWXO) - perm |= S_ISUID|S_ISGID; - break; - case 't': - /* If only "other" bits ignore sticky. */ - if (!who || who & ~S_IRWXO) { - who |= S_ISTXT; - perm |= S_ISTXT; - } - break; - case 'w': - perm |= S_IWUSR|S_IWGRP|S_IWOTH; - break; - case 'X': - permXbits = S_IXUSR|S_IXGRP|S_IXOTH; - break; - case 'x': - perm |= S_IXUSR|S_IXGRP|S_IXOTH; - break; - case 'u': - case 'g': - case 'o': - /* - * When ever we hit 'u', 'g', or 'o', we have - * to flush out any partial mode that we have, - * and then do the copying of the mode bits. - */ - if (perm) { - ADDCMD(op, who, perm, mask); - perm = 0; - } - if (op == '=') - equalopdone = 1; - if (op == '+' && permXbits) { - ADDCMD('X', who, permXbits, mask); - permXbits = 0; - } - ADDCMD(*p, who, op, mask); - break; - - default: - /* - * Add any permissions that we haven't already - * done. - */ - if (perm || (op == '=' && !equalopdone)) { - if (op == '=') - equalopdone = 1; - ADDCMD(op, who, perm, mask); - perm = 0; - } - if (permXbits) { - ADDCMD('X', who, permXbits, mask); - permXbits = 0; - } - goto apply; - } - } - -apply: if (!*p) - break; - if (*p != ',') - goto getop; - ++p; - } - set->cmd = 0; -#ifdef SETMODE_DEBUG - (void)printf("Before compress_mode()\n"); - dumpmode(saveset); -#endif - compress_mode(saveset); -#ifdef SETMODE_DEBUG - (void)printf("After compress_mode()\n"); - dumpmode(saveset); -#endif - return (saveset); -} - -static BITCMD * -addcmd(set, op, who, oparg, mask) - BITCMD *set; - int oparg, who; - int op; - u_int mask; -{ - switch (op) { - case '=': - set->cmd = '-'; - set->bits = who ? who : STANDARD_BITS; - set++; - - op = '+'; - /* FALLTHROUGH */ - case '+': - case '-': - case 'X': - set->cmd = op; - set->bits = (who ? who : mask) & oparg; - break; - - case 'u': - case 'g': - case 'o': - set->cmd = op; - if (who) { - set->cmd2 = ((who & S_IRUSR) ? CMD2_UBITS : 0) | - ((who & S_IRGRP) ? CMD2_GBITS : 0) | - ((who & S_IROTH) ? CMD2_OBITS : 0); - set->bits = (mode_t)~0; - } else { - set->cmd2 = CMD2_UBITS | CMD2_GBITS | CMD2_OBITS; - set->bits = mask; - } - - if (oparg == '+') - set->cmd2 |= CMD2_SET; - else if (oparg == '-') - set->cmd2 |= CMD2_CLR; - else if (oparg == '=') - set->cmd2 |= CMD2_SET|CMD2_CLR; - break; - } - return (set + 1); -} - -#ifdef SETMODE_DEBUG -static void -dumpmode(set) - BITCMD *set; -{ - for (; set->cmd; ++set) - (void)printf("cmd: '%c' bits %04o%s%s%s%s%s%s\n", - set->cmd, set->bits, set->cmd2 ? " cmd2:" : "", - set->cmd2 & CMD2_CLR ? " CLR" : "", - set->cmd2 & CMD2_SET ? " SET" : "", - set->cmd2 & CMD2_UBITS ? " UBITS" : "", - set->cmd2 & CMD2_GBITS ? " GBITS" : "", - set->cmd2 & CMD2_OBITS ? " OBITS" : ""); -} -#endif - -/* - * 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 - * compacted, but it's not worth the effort. - */ -static void -compress_mode(set) - BITCMD *set; -{ - BITCMD *nset; - int setbits, clrbits, Xbits, op; - - for (nset = set;;) { - /* Copy over any 'u', 'g' and 'o' commands. */ - while ((op = nset->cmd) != '+' && op != '-' && op != 'X') { - *set++ = *nset++; - if (!op) - return; - } - - for (setbits = clrbits = Xbits = 0;; nset++) { - if ((op = nset->cmd) == '-') { - clrbits |= nset->bits; - setbits &= ~nset->bits; - Xbits &= ~nset->bits; - } else if (op == '+') { - setbits |= nset->bits; - clrbits &= ~nset->bits; - Xbits &= ~nset->bits; - } else if (op == 'X') - Xbits |= nset->bits & ~setbits; - else - break; - } - if (clrbits) { - set->cmd = '-'; - set->cmd2 = 0; - set->bits = clrbits; - set++; - } - if (setbits) { - set->cmd = '+'; - set->cmd2 = 0; - set->bits = setbits; - set++; - } - if (Xbits) { - set->cmd = 'X'; - set->cmd2 = 0; - set->bits = Xbits; - set++; - } - } -} diff --git a/gen/setmode-fbsd.c b/gen/setmode-fbsd.c new file mode 120000 index 0000000..cb65fef --- /dev/null +++ b/gen/setmode-fbsd.c @@ -0,0 +1 @@ +./setmode.c \ No newline at end of file diff --git a/gen/siginterrupt-fbsd.c b/gen/siginterrupt-fbsd.c deleted file mode 100644 index 8c719f8..0000000 --- a/gen/siginterrupt-fbsd.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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[] = "@(#)siginterrupt.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/siginterrupt.c,v 1.4 2002/02/01 00:57:29 obrien Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "libc_private.h" - -/* - * Set signal state to prevent restart of system calls - * after an instance of the indicated signal. - */ -int -siginterrupt(sig, flag) - int sig, flag; -{ - extern sigset_t _sigintr; - struct sigaction sa; - int ret; - - if ((ret = _sigaction(sig, (struct sigaction *)0, &sa)) < 0) - return (ret); - if (flag) { - sigaddset(&_sigintr, sig); - sa.sa_flags &= ~SA_RESTART; - } else { - sigdelset(&_sigintr, sig); - sa.sa_flags |= SA_RESTART; - } - return (_sigaction(sig, &sa, (struct sigaction *)0)); -} diff --git a/gen/siginterrupt-fbsd.c b/gen/siginterrupt-fbsd.c new file mode 120000 index 0000000..73b87a5 --- /dev/null +++ b/gen/siginterrupt-fbsd.c @@ -0,0 +1 @@ +./siginterrupt.c \ No newline at end of file diff --git a/gen/stringlist-fbsd.c b/gen/stringlist-fbsd.c deleted file mode 100644 index 1d977e4..0000000 --- a/gen/stringlist-fbsd.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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 -__FBSDID("$FreeBSD: src/lib/libc/gen/stringlist.c,v 1.7 2003/01/19 01:16:01 obrien Exp $"); - -#include "namespace.h" -#include -#include -#include -#include -#include -#include "un-namespace.h" - -#define _SL_CHUNKSIZE 20 - -/* - * sl_init(): Initialize a string list - */ -StringList * -sl_init() -{ - StringList *sl; - - 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 - */ -int -sl_add(sl, name) - StringList *sl; - char *name; -{ - if (sl->sl_cur == sl->sl_max - 1) { - sl->sl_max += _SL_CHUNKSIZE; - sl->sl_str = reallocf(sl->sl_str, sl->sl_max * sizeof(char *)); - if (sl->sl_str == NULL) - return (-1); - } - sl->sl_str[sl->sl_cur++] = name; - return (0); -} - - -/* - * 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/gen/stringlist-fbsd.c b/gen/stringlist-fbsd.c new file mode 120000 index 0000000..8dfffde --- /dev/null +++ b/gen/stringlist-fbsd.c @@ -0,0 +1 @@ +./stringlist.c \ No newline at end of file diff --git a/gen/sysctl-fbsd.c b/gen/sysctl-fbsd.c deleted file mode 100644 index b6c89a0..0000000 --- a/gen/sysctl-fbsd.c +++ /dev/null @@ -1,187 +0,0 @@ -/*- - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)sysctl.c 8.2 (Berkeley) 1/4/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/sysctl.c,v 1.5 2003/02/16 17:29:09 nectar Exp $"); - -#include -#include - -#include -#include -#include -#include -#include -#include - -extern int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, - void *newp, size_t newlen); - -int -sysctl(name, namelen, oldp, oldlenp, newp, newlen) - int *name; - u_int namelen; - void *oldp, *newp; - size_t *oldlenp, newlen; -{ - if (name[0] != CTL_USER) - return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen)); - - if (newp != NULL) { - errno = EPERM; - return (-1); - } - if (namelen != 2) { - errno = EINVAL; - return (-1); - } - - switch (name[1]) { - case USER_CS_PATH: - if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) { - errno = ENOMEM; - return -1; - } - *oldlenp = sizeof(_PATH_STDPATH); - if (oldp != NULL) - memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH)); - return (0); - } - - if (oldp && *oldlenp < sizeof(int)) { - errno = ENOMEM; - return (-1); - } - *oldlenp = sizeof(int); - if (oldp == NULL) - return (0); - - switch (name[1]) { - case USER_BC_BASE_MAX: - *(int *)oldp = BC_BASE_MAX; - return (0); - case USER_BC_DIM_MAX: - *(int *)oldp = BC_DIM_MAX; - return (0); - case USER_BC_SCALE_MAX: - *(int *)oldp = BC_SCALE_MAX; - return (0); - case USER_BC_STRING_MAX: - *(int *)oldp = BC_STRING_MAX; - return (0); - case USER_COLL_WEIGHTS_MAX: - *(int *)oldp = COLL_WEIGHTS_MAX; - return (0); - case USER_EXPR_NEST_MAX: - *(int *)oldp = EXPR_NEST_MAX; - return (0); - case USER_LINE_MAX: - *(int *)oldp = LINE_MAX; - return (0); - case USER_RE_DUP_MAX: - *(int *)oldp = RE_DUP_MAX; - return (0); - case USER_POSIX2_VERSION: - *(int *)oldp = _POSIX2_VERSION; - return (0); - case USER_POSIX2_C_BIND: -#ifdef POSIX2_C_BIND - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_C_DEV: -#ifdef POSIX2_C_DEV - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_CHAR_TERM: -#ifdef POSIX2_CHAR_TERM - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_FORT_DEV: -#ifdef POSIX2_FORT_DEV - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_FORT_RUN: -#ifdef POSIX2_FORT_RUN - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_LOCALEDEF: -#ifdef POSIX2_LOCALEDEF - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_SW_DEV: -#ifdef POSIX2_SW_DEV - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_POSIX2_UPE: -#ifdef POSIX2_UPE - *(int *)oldp = 1; -#else - *(int *)oldp = 0; -#endif - return (0); - case USER_STREAM_MAX: - *(int *)oldp = FOPEN_MAX; - return (0); - case USER_TZNAME_MAX: - *(int *)oldp = NAME_MAX; - return (0); - default: - errno = EINVAL; - return (-1); - } - /* NOTREACHED */ -} diff --git a/gen/sysctl-fbsd.c b/gen/sysctl-fbsd.c new file mode 120000 index 0000000..fac1fc6 --- /dev/null +++ b/gen/sysctl-fbsd.c @@ -0,0 +1 @@ +./sysctl.c \ No newline at end of file diff --git a/gen/sysctlbyname-fbsd.c b/gen/sysctlbyname-fbsd.c deleted file mode 100644 index e949a5c..0000000 --- a/gen/sysctlbyname-fbsd.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * 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 - * ---------------------------------------------------------------------------- - * - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/sysctlbyname.c,v 1.5 2002/02/01 00:57:29 obrien Exp $"); - -#include -#include -#include - -int -sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, - size_t newlen) -{ - int name2oid_oid[2]; - int real_oid[CTL_MAXNAME+2]; - int error; - size_t 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, (void *)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/gen/sysctlbyname-fbsd.c b/gen/sysctlbyname-fbsd.c new file mode 120000 index 0000000..b04c734 --- /dev/null +++ b/gen/sysctlbyname-fbsd.c @@ -0,0 +1 @@ +./sysctlbyname.c \ No newline at end of file diff --git a/gen/sysctlnametomib-fbsd.c b/gen/sysctlnametomib-fbsd.c deleted file mode 100644 index 1a932ec..0000000 --- a/gen/sysctlnametomib-fbsd.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2001 The FreeBSD Project. 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 FREEBSD PROJECT ``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 FREEBSD PROJECT 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 -__FBSDID("$FreeBSD: src/lib/libc/gen/sysctlnametomib.c,v 1.4 2003/01/04 00:11:11 tjr Exp $"); - -#include -#include -#include - -/* - * This function uses a presently undocumented interface to the kernel - * to walk the tree and get the type so it can print the value. - * This interface is under work and consideration, and should probably - * be killed with a big axe by the first person who can find the time. - * (be aware though, that the proper interface isn't as obvious as it - * may seem, there are various conflicting requirements. - */ -int -sysctlnametomib(const char *name, int *mibp, size_t *sizep) -{ - int oid[2]; - int error; - - oid[0] = 0; - oid[1] = 3; - - *sizep *= sizeof (int); - error = sysctl(oid, 2, mibp, sizep, (void *)name, strlen(name)); - *sizep /= sizeof (int); - return (error); -} diff --git a/gen/sysctlnametomib-fbsd.c b/gen/sysctlnametomib-fbsd.c new file mode 120000 index 0000000..47688f8 --- /dev/null +++ b/gen/sysctlnametomib-fbsd.c @@ -0,0 +1 @@ +./sysctlnametomib.c \ No newline at end of file diff --git a/gen/syslog.c b/gen/syslog.c index a84e294..231ac32 100644 --- a/gen/syslog.c +++ b/gen/syslog.c @@ -69,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -146,6 +147,7 @@ vsyslog(int pri, const char *fmt, va_list ap) { int status, i, saved_errno, filter, rc_filter; time_t tick; + struct timeval tval; pid_t pid; uint32_t elen, count; char *p, *str, *expanded, *err_str, hname[MAXHOSTNAMELEN+1]; @@ -212,16 +214,41 @@ vsyslog(int pri, const char *fmt, va_list ap) if (str != NULL) asl_set(msg, ASL_KEY_FACILITY, str); str = NULL; - tick = time(NULL); - asprintf(&str, "%lu", tick); - if (str != NULL) + memset(&tval, 0, sizeof(struct timeval)); + + status = gettimeofday(&tval, NULL); + if (status == 0) { - asl_set(msg, ASL_KEY_TIME, str); - free(str); - } + str = NULL; + asprintf(&str, "%lu", tval.tv_sec); + if (str != NULL) + { + asl_set(msg, ASL_KEY_TIME, str); + free(str); + } - str = NULL; + str = NULL; + asprintf(&str, "%lu", tval.tv_usec * 1000); + if (str != NULL) + { + asl_set(msg, ASL_KEY_TIME_NSEC, str); + free(str); + } + } + else + { + tick = time(NULL); + str = NULL; + asprintf(&str, "%lu", tick); + if (str != NULL) + { + asl_set(msg, ASL_KEY_TIME, str); + free(str); + } + } + pid = getpid(); + str = NULL; asprintf(&str, "%u", pid); if (str != NULL) { @@ -336,7 +363,7 @@ vsyslog(int pri, const char *fmt, va_list ap) } /* Get connected, output the message to the local logger. */ - str = asl_format_message(msg, ASL_MSG_FMT_RAW, ASL_TIME_FMT_SEC, &count); + str = asl_format_message(msg, ASL_MSG_FMT_RAW, ASL_TIME_FMT_SEC, ASL_ENCODE_ASL, &count); if (str != NULL) { p = NULL; @@ -374,7 +401,7 @@ vsyslog(int pri, const char *fmt, va_list ap) { count = 0; - p = asl_format_message(msg, ASL_MSG_FMT_STD, ASL_TIME_FMT_LCL, &count); + p = asl_format_message(msg, ASL_MSG_FMT_STD, ASL_TIME_FMT_LCL, ASL_ENCODE_SAFE, &count); if (p != NULL) { struct iovec iov; diff --git a/gen/thread_stack_pcs.c b/gen/thread_stack_pcs.c index 91363aa..3004f5f 100644 --- a/gen/thread_stack_pcs.c +++ b/gen/thread_stack_pcs.c @@ -28,7 +28,7 @@ #include #include -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) #define FP_LINK_OFFSET 1 #elif defined(__ppc__) || defined(__ppc64__) #define FP_LINK_OFFSET 2 @@ -39,6 +39,8 @@ #define INSTACK(a) ((a) >= stackbot && (a) <= stacktop) #if defined(__ppc__) || defined(__ppc64__) || defined(__x86_64__) #define ISALIGNED(a) ((((uintptr_t)(a)) & 0xf) == 0) +#elif defined(__arm__) +#define ISALIGNED(a) ((((uintptr_t)(a)) & 0x1) == 0) #elif defined(__i386__) #define ISALIGNED(a) ((((uintptr_t)(a)) & 0xf) == 8) #endif @@ -65,7 +67,7 @@ _thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb, unsigned ski * optimization). We now inline the code to get the stack frame pointer, * so we are consistent about the stack frame. */ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) frame = __builtin_frame_address(0); #elif defined(__ppc__) || defined(__ppc64__) /* __builtin_frame_address IS BROKEN IN BEAKER: RADAR #2340421 */ diff --git a/gen/time-fbsd.c b/gen/time-fbsd.c index 08921d0..544440c 100644 --- a/gen/time-fbsd.c +++ b/gen/time-fbsd.c @@ -47,15 +47,21 @@ time(t) { struct timeval tt; time_t retval; +#ifdef FE_DFL_ENV fenv_t fenv; +#endif /* FE_DFL_ENV */ +#ifdef FE_DFL_ENV fegetenv(&fenv); /* 3965505 - need to preserve floating point enviroment */ +#endif /* FE_DFL_ENV */ if (gettimeofday(&tt, (struct timezone *)0) < 0) retval = -1; else retval = tt.tv_sec; if (t != NULL) *t = retval; +#ifdef FE_DFL_ENV fesetenv(&fenv); +#endif /* FE_DFL_ENV */ return (retval); } diff --git a/gen/times-fbsd.c b/gen/times-fbsd.c deleted file mode 100644 index 5bdc607..0000000 --- a/gen/times-fbsd.c +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)times.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/times.c,v 1.2 2002/02/01 01:08:48 obrien Exp $"); - -#include -#include -#include -#include - -/* - * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000, - * but this would overflow if we switch to nanosec. - */ -#define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK)) - -clock_t -times(tp) - struct tms *tp; -{ - struct rusage ru; - struct timeval t; - - if (getrusage(RUSAGE_SELF, &ru) < 0) - return ((clock_t)-1); - tp->tms_utime = CONVTCK(ru.ru_utime); - tp->tms_stime = CONVTCK(ru.ru_stime); - if (getrusage(RUSAGE_CHILDREN, &ru) < 0) - return ((clock_t)-1); - tp->tms_cutime = CONVTCK(ru.ru_utime); - tp->tms_cstime = CONVTCK(ru.ru_stime); - if (gettimeofday(&t, (struct timezone *)0)) - return ((clock_t)-1); - return ((clock_t)(CONVTCK(t))); -} diff --git a/gen/times-fbsd.c b/gen/times-fbsd.c new file mode 120000 index 0000000..4391258 --- /dev/null +++ b/gen/times-fbsd.c @@ -0,0 +1 @@ +./times.c \ No newline at end of file diff --git a/gen/timezone-fbsd.c b/gen/timezone-fbsd.c deleted file mode 100644 index 8d8139a..0000000 --- a/gen/timezone-fbsd.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 1987, 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[] = "@(#)timezone.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/timezone.c,v 1.5 2002/02/01 01:08:48 obrien Exp $"); - -#include -#include -#include -#include -#include -#define TZ_MAX_CHARS 255 - -char *_tztab(); - -/* - * timezone -- - * The arguments are the number of minutes of time you are westward - * from Greenwich and whether DST is in effect. It returns a string - * giving the name of the local timezone. Should be replaced, in the - * application code, by a call to localtime. - */ - -static char czone[TZ_MAX_CHARS]; /* space for zone name */ - -char * -timezone(zone, dst) - int zone, - dst; -{ - char *beg, - *end; - - if ( (beg = getenv("TZNAME")) ) { /* set in environment */ - if ( (end = index(beg, ',')) ) {/* "PST,PDT" */ - if (dst) - return(++end); - *end = '\0'; - (void)strncpy(czone,beg,sizeof(czone) - 1); - czone[sizeof(czone) - 1] = '\0'; - *end = ','; - return(czone); - } - return(beg); - } - return(_tztab(zone,dst)); /* default: table or created zone */ -} - -static struct zone { - int offset; - 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 */ -#ifdef notdef - /* there's no way to distinguish this from WET */ - {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} -}; - -/* - * _tztab -- - * check static tables or create a new zone name; broken out so that - * we can make a guess as to what the zone is if the standard tables - * aren't in place in /etc. DO NOT USE THIS ROUTINE OUTSIDE OF THE - * STANDARD LIBRARY. - */ -char * -_tztab(zone,dst) - int zone; - int dst; -{ - struct zone *zp; - char sign; - - for (zp = zonetab; zp->offset != -1;++zp) /* static tables */ - if (zp->offset == zone) { - if (dst && zp->dlzone) - return(zp->dlzone); - if (!dst && zp->stdzone) - return(zp->stdzone); - } - - if (zone < 0) { /* create one */ - zone = -zone; - sign = '+'; - } - else - sign = '-'; - (void)snprintf(czone, sizeof(czone), - "GMT%c%d:%02d",sign,zone / 60,zone % 60); - return(czone); -} diff --git a/gen/timezone-fbsd.c b/gen/timezone-fbsd.c new file mode 120000 index 0000000..acd447d --- /dev/null +++ b/gen/timezone-fbsd.c @@ -0,0 +1 @@ +./timezone.c \ No newline at end of file diff --git a/gen/ttyslot-fbsd.c b/gen/ttyslot-fbsd.c deleted file mode 100644 index 0d7359c..0000000 --- a/gen/ttyslot-fbsd.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ttyslot.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/ttyslot.c,v 1.4 2002/02/01 01:08:48 obrien Exp $"); - -#include -#include -#include -#include - -int -ttyslot() -{ - struct ttyent *ttyp; - int slot; - char *p; - int cnt; - char *name; - - setttyent(); - for (cnt = 0; cnt < 3; ++cnt) - if ( (name = ttyname(cnt)) ) { - if ( (p = rindex(name, '/')) ) - ++p; - else - p = name; - for (slot = 1; (ttyp = getttyent()); ++slot) - if (!strcmp(ttyp->ty_name, p)) { - endttyent(); - return(slot); - } - break; - } - endttyent(); - return(0); -} diff --git a/gen/ttyslot-fbsd.c b/gen/ttyslot-fbsd.c new file mode 120000 index 0000000..7e772b8 --- /dev/null +++ b/gen/ttyslot-fbsd.c @@ -0,0 +1 @@ +./ttyslot.c \ No newline at end of file diff --git a/gen/tzset.3 b/gen/tzset.3 index a681179..3476572 100644 --- a/gen/tzset.3 +++ b/gen/tzset.3 @@ -70,7 +70,11 @@ does not appear in the environment, the best available approximation to local wall clock time, as specified by the .Xr tzfile 5 Ns -format file +#ifdef UNIFDEF_MOVE_LOCALTIME +.Pa /var/db/timezone/localtime , +#else /* !UNIFDEF_MOVE_LOCALTIME */ .Pa /etc/localtime , +#endif /* UNIFDEF_MOVE_LOCALTIME */ is used. .Pp If diff --git a/gen/ualarm-fbsd.c b/gen/ualarm-fbsd.c deleted file mode 100644 index a9200ae..0000000 --- a/gen/ualarm-fbsd.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ualarm.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/ualarm.c,v 1.4 2002/12/29 00:59:09 mike Exp $"); - -#include -#include - -#define USPS 1000000 /* # of microseconds in a second */ - -/* - * Generate a SIGALRM signal in ``usecs'' microseconds. - * If ``reload'' is non-zero, keep generating SIGALRM - * every ``reload'' microseconds after the first signal. - */ -useconds_t -ualarm(usecs, reload) - useconds_t usecs; - useconds_t reload; -{ - struct itimerval new, old; - - 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; - - if (setitimer(ITIMER_REAL, &new, &old) == 0) - return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); - /* else */ - return (-1); -} diff --git a/gen/ualarm-fbsd.c b/gen/ualarm-fbsd.c new file mode 120000 index 0000000..a1e562f --- /dev/null +++ b/gen/ualarm-fbsd.c @@ -0,0 +1 @@ +./ualarm.c \ No newline at end of file diff --git a/gen/ulimit-fbsd.c b/gen/ulimit-fbsd.c deleted file mode 100644 index d25ff47..0000000 --- a/gen/ulimit-fbsd.c +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * Copyright (c) 2002 Kyle Martin - * 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. - * - * $FreeBSD: src/lib/libc/gen/ulimit.c,v 1.3 2003/01/04 01:11:49 tjr Exp $ - */ - -#include -#include -#include - -#include -#include -#include -#include - -long -ulimit(int cmd, ...) -{ - struct rlimit limit; - va_list ap; - long arg; - - if (cmd == UL_GETFSIZE) { - if (getrlimit(RLIMIT_FSIZE, &limit) == -1) - return (-1); - limit.rlim_cur /= 512; - if (limit.rlim_cur > LONG_MAX) - return (LONG_MAX); - return ((long)limit.rlim_cur); - } else if (cmd == UL_SETFSIZE) { - va_start(ap, cmd); - arg = va_arg(ap, long); - va_end(ap); - limit.rlim_max = limit.rlim_cur = (rlim_t)arg * 512; - - /* The setrlimit() function sets errno to EPERM if needed. */ - if (setrlimit(RLIMIT_FSIZE, &limit) == -1) - return (-1); - if (arg * 512 > LONG_MAX) - return (LONG_MAX); - return (arg); - } else { - errno = EINVAL; - return (-1); - } -} diff --git a/gen/ulimit-fbsd.c b/gen/ulimit-fbsd.c new file mode 120000 index 0000000..30722f8 --- /dev/null +++ b/gen/ulimit-fbsd.c @@ -0,0 +1 @@ +./ulimit.c \ No newline at end of file diff --git a/gen/utime-fbsd.c b/gen/utime-fbsd.c deleted file mode 100644 index cefa020..0000000 --- a/gen/utime-fbsd.c +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)utime.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/utime.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); - -#include - -#include - -int -utime(path, times) - const char *path; - const struct utimbuf *times; -{ - struct timeval tv[2], *tvp; - - if (times) { - tv[0].tv_sec = times->actime; - tv[1].tv_sec = times->modtime; - tv[0].tv_usec = tv[1].tv_usec = 0; - tvp = tv; - } else - tvp = NULL; - return (utimes(path, tvp)); -} diff --git a/gen/utime-fbsd.c b/gen/utime-fbsd.c new file mode 120000 index 0000000..ad13533 --- /dev/null +++ b/gen/utime-fbsd.c @@ -0,0 +1 @@ +./utime.c \ No newline at end of file diff --git a/gen/utmpx-darwin.c b/gen/utmpx-darwin.c index 312f4e5..914cca7 100644 --- a/gen/utmpx-darwin.c +++ b/gen/utmpx-darwin.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2005-2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -34,11 +34,14 @@ #include #include #include +#ifdef UTMP_COMPAT #include +#endif /* UTMP_COMPAT */ #include #include #include #include +#include #include #include @@ -62,15 +65,13 @@ static void msg2lastlogx(const aslmsg, struct lastlogx *); static void msg2utmpx(const aslmsg, struct utmpx *); static void utmpx2msg(const struct utmpx *, aslmsg); -static mach_port_t asl_server_port = MACH_PORT_NULL; static int pw_size = 0; -#define ASL_SERVICE_NAME "com.apple.system.logger" #define FACILITY "Facility" #define WTMP_COUNT 32 -/* ASL timeout in milliseconds */ -#define ASL_QUERY_TIMEOUT 4000 +/* ASL timeout in microseconds */ +#define ASL_QUERY_TIMEOUT 4000000 /* indirection causes argument to be substituted before stringification */ #define STR(x) __STRING(x) @@ -137,81 +138,67 @@ getlastlogx(uid_t uid, struct lastlogx *lx) struct lastlogx * getlastlogxbyname(const char *user, struct lastlogx *lx) { - aslmsg q; - asl_msg_t *m[1]; - asl_search_result_t s, *l; - char *qstr, *res; - uint32_t len, reslen, status; + aslmsg m; + asl_msg_t *qm[1]; + asl_search_result_t query, *res; + uint32_t status; uint64_t cmax; - security_token_t sec; - caddr_t vmstr; struct lastlogx *result = NULL; - mach_port_t port; + asl_store_t *store; - if (!user || !*user) - return NULL; + if (!user || !*user) return NULL; - if (bootstrap_look_up(bootstrap_port, ASL_SERVICE_NAME, &port) != KERN_SUCCESS) - return NULL; + store = NULL; + status = asl_store_open_read(NULL, &store); + if (status != 0) return NULL; + if (store == NULL) return NULL; /* * We search for the last LASTLOG_FACILITY entry that has the * ut_user entry matching the user's name. */ - if ((q = asl_new(ASL_TYPE_QUERY)) == NULL) - goto out; - asl_set_query(q, FACILITY, LASTLOG_FACILITY, ASL_QUERY_OP_EQUAL); - asl_set_query(q, "ut_user", user, ASL_QUERY_OP_EQUAL); - m[0] = q; - s.count = 1; - s.msg = m; - - len = 0; - qstr = asl_list_to_string(&s, &len); - asl_free(q); - - if (qstr == NULL) - goto out; - - /* the server frees this memory */ - if (vm_allocate(mach_task_self(), (vm_address_t *)&vmstr, len, TRUE) != KERN_SUCCESS) { - free(qstr); - goto out; + if ((m = asl_new(ASL_TYPE_QUERY)) == NULL) + { + asl_store_close(store); + return NULL; } - strcpy(vmstr, qstr); - free(qstr); + asl_set_query(m, FACILITY, LASTLOG_FACILITY, ASL_QUERY_OP_EQUAL); + asl_set_query(m, "ut_user", user, ASL_QUERY_OP_EQUAL); + qm[0] = m; + query.count = 1; + query.msg = qm; res = NULL; - reslen = 0; cmax = 0; - sec.val[0] = -1; - sec.val[1] = -1; - status = 0; - - _asl_server_query_timeout(port, vmstr, len, -1, 1, 1, ASL_QUERY_TIMEOUT, (caddr_t *)&res, &reslen, &cmax, (int *)&status, &sec); - - if (res == NULL) - goto out; - l = asl_list_from_string(res); - vm_deallocate(mach_task_self(), (vm_address_t)res, reslen); - q = aslresponse_next(l); - if (q == NULL) { - aslresponse_free(l); - goto out; + + asl_store_match_timeout(store, &query, &res, &cmax, -1, 1, -1, ASL_QUERY_TIMEOUT); + asl_store_close(store); + asl_free(m); + + if (status != 0) return NULL; + if (res == NULL) return NULL; + + m = aslresponse_next(res); + if (m == NULL) + { + aslresponse_free(res); + return NULL; } - if (lx == NULL) { - if ((lx = (struct lastlogx *)malloc(sizeof(*lx))) == NULL) { - aslresponse_free(l); - goto out; + if (lx == NULL) + { + if ((lx = (struct lastlogx *)malloc(sizeof(*lx))) == NULL) + { + aslresponse_free(res); + return NULL; } } - msg2lastlogx(q, lx); - aslresponse_free(l); + + msg2lastlogx(m, lx); + aslresponse_free(res); result = lx; -out: - mach_port_deallocate(mach_task_self(), port); + return result; } @@ -578,16 +565,14 @@ wtmpxname(const char *fname) static void end_asl(void) { - if (wtmp_asl.res) { + if (wtmp_asl.res != NULL) + { aslresponse_free(wtmp_asl.res); wtmp_asl.res = NULL; } + wtmp_asl.inited = 0; wtmp_asl.done = 0; - if (asl_server_port != MACH_PORT_NULL) { - mach_port_deallocate(mach_task_self(), asl_server_port); - asl_server_port = MACH_PORT_NULL; - } } static void @@ -606,61 +591,25 @@ end_file(void) static struct utmpx * get_asl(void) { - aslmsg q; - char *res; - uint32_t reslen, status; - security_token_t sec; - caddr_t vmstr; + aslmsg m; static struct utmpx utx; -get_asl_repeat: - if (wtmp_asl.res) { - if ((q = aslresponse_next(wtmp_asl.res)) != NULL) { - msg2utmpx(q, &utx); - return &utx; - } + if (wtmp_asl.inited == 0) set_asl(-1); + if (wtmp_asl.done != 0) return NULL; + + m = aslresponse_next(wtmp_asl.res); + if (m == NULL) + { aslresponse_free(wtmp_asl.res); wtmp_asl.res = NULL; - } else if (!wtmp_asl.inited) { - set_asl(-1); - if (!wtmp_asl.inited) - return NULL; - } - - if (wtmp_asl.done) + wtmp_asl.done = 1; return NULL; - - if (asl_server_port == MACH_PORT_NULL) { - if (bootstrap_look_up(bootstrap_port, ASL_SERVICE_NAME, &asl_server_port) != KERN_SUCCESS) { -get_asl_done: - wtmp_asl.done = 1; - return NULL; - } } - /* the server frees this memory */ - if (vm_allocate(mach_task_self(), (vm_address_t *)&vmstr, wtmp_asl.len, TRUE) != KERN_SUCCESS) - goto get_asl_done; - - /* the search string is defined in set_asl */ - strcpy(vmstr, wtmp_asl.str); - - res = NULL; - reslen = 0; - sec.val[0] = -1; - sec.val[1] = -1; - status = 0; - - _asl_server_query_timeout(asl_server_port, vmstr, wtmp_asl.len, wtmp_asl.start, WTMP_COUNT, wtmp_asl.dir, ASL_QUERY_TIMEOUT, (caddr_t *)&res, &reslen, &wtmp_asl.start, (int *)&status, &sec); - - if (res == NULL) - goto get_asl_done; - wtmp_asl.res = asl_list_from_string(res); - vm_deallocate(mach_task_self(), (vm_address_t)res, reslen); - if(!wtmp_asl.res) - goto get_asl_done; - goto get_asl_repeat; + msg2utmpx(m, &utx); + return &utx; } + static struct utmpx * get_file(void) @@ -735,57 +684,83 @@ get_file_done: static void _set_dir(int forward) { - if (forward < 0) - return; - if (forward) { - wtmp_asl.dir = 0; - wtmp_asl.start = 0; - wtmp_file.dir = 1; - } else { - wtmp_asl.dir = 1; + if (forward < 0) return; + + if (forward == 0) + { + /* go backward */ + wtmp_asl.dir = -1; wtmp_asl.start = -1; wtmp_file.dir = -1; } + else + { + /* go forward */ + wtmp_asl.dir = 1; + wtmp_asl.start = 0; + wtmp_file.dir = 1; + } } static void set_asl(int forward) { + aslmsg q0, q1; + asl_msg_t *m[2]; + asl_search_result_t query; + uint64_t cmax; + asl_store_t *store; + uint32_t status; + _set_dir(forward); - if (!wtmp_asl.str) { - aslmsg q0, q1; - asl_msg_t *m[2]; - asl_search_result_t s; - - /* - * Create a search string that matches either UTMPX_FACILITY - * or LASTLOG_FACILITY. - */ - if ((q0 = asl_new(ASL_TYPE_QUERY)) == NULL) - return; - if ((q1 = asl_new(ASL_TYPE_QUERY)) == NULL) { - asl_free(q0); - return; - } - asl_set_query(q0, FACILITY, UTMPX_FACILITY, ASL_QUERY_OP_EQUAL); - asl_set_query(q1, FACILITY, LASTLOG_FACILITY, ASL_QUERY_OP_EQUAL); - - m[0] = q0; - m[1] = q1; - s.count = 2; - s.msg = m; - - wtmp_asl.len = 0; - wtmp_asl.str = asl_list_to_string(&s, &wtmp_asl.len); - asl_free(q1); - asl_free(q0); - if(!wtmp_asl.str) - return; - } - if (wtmp_asl.res) { + + wtmp_asl.inited = 0; + wtmp_asl.done = 0; + + if (wtmp_asl.res != NULL) + { aslresponse_free(wtmp_asl.res); wtmp_asl.res = NULL; } + + store = NULL; + status = asl_store_open_read(NULL, &store); + if (status != 0) return; + if (store == NULL) return; + + /* + * Create a search query that matches either UTMPX_FACILITY + * or LASTLOG_FACILITY. + */ + q0 = asl_new(ASL_TYPE_QUERY); + q1 = asl_new(ASL_TYPE_QUERY); + + if ((q0 == NULL) || (q1 == NULL)) + { + asl_store_close(store); + if (q0 != NULL) free(q0); + if (q1 != NULL) free(q1); + return; + } + + asl_set_query(q0, FACILITY, UTMPX_FACILITY, ASL_QUERY_OP_EQUAL); + asl_set_query(q1, FACILITY, LASTLOG_FACILITY, ASL_QUERY_OP_EQUAL); + + m[0] = q0; + m[1] = q1; + query.count = 2; + query.msg = m; + + cmax = 0; + + asl_store_match_timeout(store, &query, &(wtmp_asl.res), &cmax, wtmp_asl.start, 0, wtmp_asl.dir, ASL_QUERY_TIMEOUT); + asl_store_close(store); + + asl_free(q1); + asl_free(q0); + + if (wtmp_asl.res == NULL) return; + wtmp_asl.inited = 1; wtmp_asl.done = 0; } diff --git a/gen/utmpx-nbsd.c b/gen/utmpx-nbsd.c index 57a3426..4298fa5 100644 --- a/gen/utmpx-nbsd.c +++ b/gen/utmpx-nbsd.c @@ -54,7 +54,9 @@ __RCSID("$NetBSD: utmpx.c,v 1.21 2003/09/06 16:42:10 wiz Exp $"); #include #include #include +#ifdef LEGACY_UTMP_APIS #include +#endif /* LEGACY_UTMP_APIS */ #include #include #include @@ -410,7 +412,7 @@ utmpxname(const char *fname) return 1; } - +#ifdef LEGACY_UTMP_APIS void getutmp(const struct utmpx *ux, struct utmp *u) { @@ -438,3 +440,4 @@ getutmpx(const struct utmp *u, struct utmpx *ux) ux->ut_pid = getpid(); ux->ut_type = USER_PROCESS; } +#endif /* LEGACY_UTMP_APIS */ diff --git a/gen/wait3-fbsd.c b/gen/wait3-fbsd.c deleted file mode 100644 index a4b91a7..0000000 --- a/gen/wait3-fbsd.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)wait3.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/gen/wait3.c,v 1.3 2002/02/01 00:57:29 obrien Exp $"); - -#include "namespace.h" -#include -#include -#include -#include -#include "un-namespace.h" - -pid_t -wait3(istat, options, rup) - int *istat; - int options; - struct rusage *rup; -{ - return (_wait4(WAIT_ANY, istat, options, rup)); -} diff --git a/gen/wait3-fbsd.c b/gen/wait3-fbsd.c new file mode 120000 index 0000000..5852191 --- /dev/null +++ b/gen/wait3-fbsd.c @@ -0,0 +1 @@ +./wait3.c \ No newline at end of file diff --git a/gmon/Makefile.inc b/gmon/Makefile.inc index 11ce509..da4c2c1 100644 --- a/gmon/Makefile.inc +++ b/gmon/Makefile.inc @@ -12,11 +12,19 @@ MAN3 += moncontrol.3 MLINKS += moncontrol.3 monstartup.3 .endif +GFLAGS = -O -pipe -Wmost -g -fno-common +.if $(MACHINE_ARCH) != arm +GFLAGS += -force_cpusubtype_ALL +.endif +.ifdef SDKROOT +GFLAGS += -isysroot '${SDKROOT}' +.endif # SDKROOT + # mcount cannot be compiled with profiling gmon.po: - ${CC} -O -pipe -arch ${MACHINE_ARCH} -Wmost -g -fno-common \ - -no-cpp-precomp -force_cpusubtype_ALL \ + ${CC} -arch ${CCARCH} ${GFLAGS} \ -I${.CURDIR}/include \ + -I${SYMROOT}/include \ -I${INCLUDEDIR} \ -I${INCLUDEDIR}/objc \ ${PRIVINC} \ diff --git a/gmon/gmon.c b/gmon/gmon.c index 9770f3b..8d5710a 100644 --- a/gmon/gmon.c +++ b/gmon/gmon.c @@ -212,8 +212,7 @@ void) * above calls so the dynamic libraries will be added after the * executable. */ - if(_dyld_present()) - _dyld_moninit(monaddition); + _dyld_moninit(monaddition); #endif } @@ -445,7 +444,7 @@ const char *filename) write(fd, &magic, sizeof(uint32_t)); #if defined(__DYNAMIC__) - if(_dyld_present()){ + { image_count = _dyld_image_count(); if(image_count > 1){ #ifdef DYLD_DEBUG diff --git a/i386/sys/Makefile.inc b/i386/sys/Makefile.inc index c3e1688..df13f6f 100644 --- a/i386/sys/Makefile.inc +++ b/i386/sys/Makefile.inc @@ -8,4 +8,4 @@ MDSRCS+= OSAtomic.s \ setjmp.s \ _sigtramp.s -MDCOPYFILES+= ${.CURDIR}/i386/sys/libc.syscall.i386 +MDCOPYFILES+= ${.CURDIR}/Platforms/${RC_TARGET_CONFIG}/i386/libc.syscall.i386 diff --git a/include/Makefile.inc b/include/Makefile.inc index 656f625..8c8ec19 100644 --- a/include/Makefile.inc +++ b/include/Makefile.inc @@ -1,14 +1,14 @@ -.ifnmake autopatch .include "${.CURDIR}/include/arpa/Makefile.inc" .include "${.CURDIR}/include/libkern/Makefile.inc" .include "${.CURDIR}/include/protocols/Makefile.inc" .include "${.CURDIR}/include/machine/Makefile.inc" .include "${.CURDIR}/include/malloc/Makefile.inc" +.ifdef FEATURE_LEGACY_NXZONE_APIS .include "${.CURDIR}/include/objc/Makefile.inc" +.endif .include "${.CURDIR}/include/secure/Makefile.inc" .include "${.CURDIR}/include/sys/Makefile.inc" .include "${.CURDIR}/include/xlocale/Makefile.inc" -.endif # !autopatch INC_INSTHDRS += NSSystemDirectories.h \ _locale.h \ @@ -62,7 +62,6 @@ INC_INSTHDRS += NSSystemDirectories.h \ ranlib.h \ readpassphrase.h \ regex.h \ - rune.h \ runetype.h \ search.h \ semaphore.h \ @@ -94,7 +93,6 @@ INC_INSTHDRS += NSSystemDirectories.h \ unistd.h \ util.h \ utime.h \ - utmp.h \ utmpx.h \ varargs.h \ vis.h \ @@ -103,15 +101,22 @@ INC_INSTHDRS += NSSystemDirectories.h \ wordexp.h \ xlocale.h +.ifdef FEATURE_LEGACY_RUNE_APIS +INC_INSTHDRS += rune.h +.endif + +.ifdef FEATURE_LEGACY_UTMP_APIS +INC_INSTHDRS += utmp.h +.endif + .PATH: ${.CURDIR}/include +CWD := ${.CURDIR}/include + MAN3 += sysexits.3 INC_INSTHDRS := ${INC_INSTHDRS:S/^/${.CURDIR}\/include\//} INSTHDRS += ${INC_INSTHDRS} -STRIP_HDRS += ctype.h dirent.h fnmatch.h fts.h ftw.h glob.h regex.h \ - signal.h stdio.h stdlib.h string.h time.h unistd.h wchar.h xlocale.h - .include "Makefile.nbsd_begin" NBSDHDRS = utmpx.h .include "Makefile.nbsd_end" diff --git a/include/NetBSD/utmpx.h.patch b/include/NetBSD/utmpx.h.patch index 7f05196..bed5c0c 100644 --- a/include/NetBSD/utmpx.h.patch +++ b/include/NetBSD/utmpx.h.patch @@ -1,5 +1,5 @@ ---- utmpx.h.orig 2006-10-01 22:22:21.000000000 -0700 -+++ utmpx.h 2006-10-02 02:08:04.000000000 -0700 +--- utmpx.h.orig 2008-07-17 11:34:24.000000000 -0700 ++++ utmpx.h 2008-07-17 11:57:27.000000000 -0700 @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2004-2006 Apple Computer, Inc. All rights reserved. @@ -73,7 +73,7 @@ #define EMPTY 0 #define RUN_LVL 1 #define BOOT_TIME 2 -@@ -70,74 +96,85 @@ +@@ -70,74 +96,87 @@ #define USER_PROCESS 7 #define DEAD_PROCESS 8 @@ -171,9 +171,11 @@ + getlastlogx(uid_t, struct lastlogx *); +struct lastlogx * + getlastlogxbyname(const char*, struct lastlogx *); ++#ifdef UNIFDEF_LEGACY_UTMP_APIS +struct utmp; /* forward reference */ +void getutmp(const struct utmpx *, struct utmp *); +void getutmpx(const struct utmp *, struct utmpx *); ++#endif /* UNIFDEF_LEGACY_UTMP_APIS */ +#endif /* !_POSIX_C_SOURCE || _DARWIN_C_SOURCE */ + +struct utmpx * diff --git a/include/_.libc_internal.h b/include/_.libc_internal.h deleted file mode 100644 index dc1c9b4..0000000 --- a/include/_.libc_internal.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2006, 2007 Apple Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ - -/*********************************************************************** - * Not to be installed in /usr/include - ***********************************************************************/ - -#ifndef __LIBC_INTERNAL_H_ -#define __LIBC_INTERNAL_H_ - -#define LIBC_STRING(str) #str - -#if defined(VARIANT_LEGACY) -# define LIBC_ALIAS(sym) /* nothing */ -# define LIBC_ALIAS_C(sym) /* nothing */ -# define LIBC_ALIAS_I(sym) /* nothing */ -# define LIBC_INODE64(sym) /* nothing */ -# define LIBC_1050(sym) /* nothing */ -#else /* !VARIANT_LEGACY */ -# if defined(__LP64__) -# define LIBC_ALIAS(sym) /* nothing */ -# if defined(VARIANT_CANCELABLE) -# define LIBC_ALIAS_C(sym) /* nothing */ -# else /* !VARIANT_CANCELABLE */ -# define LIBC_ALIAS_C(sym) _asm("_" LIBC_STRING(sym) "$NOCANCEL") -# endif /* VARIANT_CANCELABLE */ -# if defined(VARIANT_INODE32) -# define LIBC_ALIAS_I(sym) /* nothing */ -# else /* !VARIANT_INODE32 */ -# define LIBC_ALIAS_I(sym) _asm("_" LIBC_STRING(sym) "$INODE64") -# endif /* VARIANT_INODE32 */ -# else /* !__LP64__ */ -# define LIBC_ALIAS(sym) _asm("_" LIBC_STRING(sym) "$UNIX2003") -# if defined(VARIANT_CANCELABLE) -# define LIBC_ALIAS_C(sym) _asm("_" LIBC_STRING(sym) "$UNIX2003") -# else /* !VARIANT_CANCELABLE */ -# define LIBC_ALIAS_C(sym) _asm("_" LIBC_STRING(sym) "$NOCANCEL$UNIX2003") -# endif /* VARIANT_CANCELABLE */ -# if defined(VARIANT_INODE32) -# define LIBC_ALIAS_I(sym) _asm("_" LIBC_STRING(sym) "$UNIX2003") -# else /* !VARIANT_INODE32 */ -# define LIBC_ALIAS_I(sym) _asm("_" LIBC_STRING(sym) "$INODE64$UNIX2003") -# endif /* VARIANT_INODE32 */ -# endif /* __LP64__ */ -# if defined(VARIANT_INODE32) -# define LIBC_INODE64(sym) /* nothing */ -# else /* !VARIANT_INODE32 */ -# define LIBC_INODE64(sym) _asm("_" LIBC_STRING(sym) "$INODE64") -# endif /* VARIANT_INODE32 */ -# if defined(VARIANT_PRE1050) -# define LIBC_1050(sym) /* nothing */ -# else /* !VARIANT_PRE1050 */ -# define LIBC_1050(sym) _asm("_" LIBC_STRING(sym) "$1050") -# endif /* VARIANT_PRE1050 */ -#endif /* VARIANT_LEGACY */ - -#define LIBC_EXTSN(sym) _asm("_" LIBC_STRING(sym) "$DARWIN_EXTSN") -#if defined(VARIANT_CANCELABLE) -# define LIBC_EXTSN_C(sym) _asm("_" LIBC_STRING(sym) "$DARWIN_EXTSN") -#else /* !VARIANT_CANCELABLE */ -# define LIBC_EXTSN_C(sym) _asm("_" LIBC_STRING(sym) "$DARWIN_EXTSN$NOCANCEL") -#endif /* !VARIANT_CANCELABLE */ - -/* 5243343 - define PR_5243343 temporarily */ -#define PR_5243343 - -#endif /* __LIBC_INTERNAL_H_ */ diff --git a/include/arpa/nameser_compat.h b/include/arpa/nameser_compat.h index 33c96ac..493b2c8 100644 --- a/include/arpa/nameser_compat.h +++ b/include/arpa/nameser_compat.h @@ -33,7 +33,7 @@ /* * from nameser.h 8.1 (Berkeley) 6/2/93 * From: Id: nameser_compat.h,v 8.9 1998/03/20 23:25:10 halley Exp - * $FreeBSD: src/include/arpa/nameser_compat.h,v 1.1.2.1 1999/08/29 14:39:01 peter Exp $ + * $FreeBSD: src/include/arpa/nameser_compat.h,v 1.4 2002/05/28 04:32:25 mike Exp $ */ #ifndef _ARPA_NAMESER_COMPAT_ @@ -51,7 +51,7 @@ * which will force your compiles to bomb until you fix * the above macros. */ - error "Undefined or invalid BYTE_ORDER"; +#error "Undefined or invalid BYTE_ORDER"; #endif /* @@ -173,6 +173,7 @@ typedef struct { #define T_SRV ns_t_srv #define T_ATMA ns_t_atma #define T_NAPTR ns_t_naptr +#define T_OPT ns_t_opt #define T_IXFR ns_t_ixfr #define T_AXFR ns_t_axfr #define T_MAILB ns_t_mailb diff --git a/include/asl.h b/include/asl.h index c9c115c..dadc15a 100644 --- a/include/asl.h +++ b/include/asl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2004 - 2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -82,15 +82,23 @@ typedef struct __aslresponse *aslresponse; * Additional attributes may be added as desired, and are * appended in the order that they are defined. */ -#define ASL_KEY_TIME "Time" /* Timestamp (see ctime(3)). Set automatically */ -#define ASL_KEY_HOST "Host" /* Sender's address (set by the server) */ -#define ASL_KEY_SENDER "Sender" /* Sender's identification string. Default is process name */ -#define ASL_KEY_FACILITY "Facility" /* Sender's facility. Default is "user". */ -#define ASL_KEY_PID "PID" /* Sending process ID encoded as a string. Set automatically */ -#define ASL_KEY_UID "UID" /* UID that sent the log message (set by the server) */ -#define ASL_KEY_GID "GID" /* GID that sent the log message (set by the server) */ -#define ASL_KEY_LEVEL "Level" /* Log level number encoded as a string. See levels above */ -#define ASL_KEY_MSG "Message" /* Actual message that will be logged */ +#define ASL_KEY_TIME "Time" /* Timestamp. Set automatically */ +#define ASL_KEY_TIME_NSEC "TimeNanoSec" /* Nanosecond time. */ +#define ASL_KEY_HOST "Host" /* Sender's address (set by the server). */ +#define ASL_KEY_SENDER "Sender" /* Sender's identification string. Default is process name. */ +#define ASL_KEY_FACILITY "Facility" /* Sender's facility. Default is "user". */ +#define ASL_KEY_PID "PID" /* Sending process ID encoded as a string. Set automatically. */ +#define ASL_KEY_UID "UID" /* UID that sent the log message (set by the server). */ +#define ASL_KEY_GID "GID" /* GID that sent the log message (set by the server). */ +#define ASL_KEY_LEVEL "Level" /* Log level number encoded as a string. See levels above. */ +#define ASL_KEY_MSG "Message" /* Message text. */ +#define ASL_KEY_READ_UID "ReadUID" /* User read access (-1 is any group). */ +#define ASL_KEY_READ_GID "ReadGID" /* Group read access (-1 is any group). */ +#define ASL_KEY_EXPIRE_TIME "ASLExpireTime" /* Expiration time for messages with long TTL. */ +#define ASL_KEY_MSG_ID "ASLMessageID" /* 64-bit message ID number (set by the server). */ +#define ASL_KEY_SESSION "Session" /* Session (set by the launchd). */ +#define ASL_KEY_REF_PID "RefPID" /* Reference PID for messages proxied by launchd */ +#define ASL_KEY_REF_PROC "RefProc" /* Reference process for messages proxied by launchd */ /* * Message Types @@ -267,7 +275,7 @@ int asl_set_query(aslmsg msg, const char *key, const char *value, uint32_t op); /* * asl_search: Search for messages matching the criteria described * by the aslmsg . The caller should set the attributes to match using - * asl_set_query() or asl_set(). The operatoin ASL_QUERY_OP_EQUAL is + * asl_set_query() or asl_set(). The operation ASL_QUERY_OP_EQUAL is * used for attributes set with asl_set(). * a: an aslmsg * returns: a set of messages that can be iterated over using aslresp_next(), @@ -277,16 +285,16 @@ aslresponse asl_search(aslclient asl, aslmsg msg); /* * aslresponse_next: Iterate over responses returned from asl_search() - * a: a response returned from asl_search(); + * r: a response returned from asl_search(); * returns: The next log message (an aslmsg) or NULL on failure */ aslmsg aslresponse_next(aslresponse r); /* * aslresponse_free: Free a response returned from asl_search() - * a: a response returned from asl_search() + * r: a response returned from asl_search() */ -void aslresponse_free(aslresponse a); +void aslresponse_free(aslresponse r); __END_DECLS diff --git a/include/glob.h b/include/glob.h index 62b1756..13c8da4 100644 --- a/include/glob.h +++ b/include/glob.h @@ -103,9 +103,6 @@ typedef struct { #define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ #define GLOB_LIMIT 0x1000 /* limit number of returned paths */ -//Begin-Libc -#define GLOB_INODE64 0x80000000 -//End-Libc /* source compatibility, these are the old names */ #define GLOB_MAXPATH GLOB_LIMIT diff --git a/include/libkern/Makefile.inc b/include/libkern/Makefile.inc index 65ac7ee..bf3bf18 100644 --- a/include/libkern/Makefile.inc +++ b/include/libkern/Makefile.inc @@ -1,2 +1,7 @@ -LIBKERN_INSTHDRS += OSAtomic.h OSCacheControl.h +LIBKERN_INSTHDRS += OSAtomic.h OSCacheControl.h + +.ifdef FEATURE_MEM_THERM_NOTIFICATION_APIS +LIBKERN_INSTHDRS += OSMemoryNotification.h OSThermalNotification.h +.endif + LIBKERN_INSTHDRS := ${LIBKERN_INSTHDRS:S/^/${.CURDIR}\/include\/libkern\//} diff --git a/include/libkern/OSMemoryNotification.h b/include/libkern/OSMemoryNotification.h new file mode 100644 index 0000000..ee6714b --- /dev/null +++ b/include/libkern/OSMemoryNotification.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#ifndef _OSMEMORYNOTIFICATION_H_ +#define _OSMEMORYNOTIFICATION_H_ + +#include + +/* +** OSMemoryNotification.h +** +** Kernel-generated notification mechanism to alert registered tasks when physical memory +** pressure reaches certain thresholds. Notifications are triggered in both directions +** so clients can manage their memory usage more and less aggressively. +** +*/ + +__BEGIN_DECLS + +struct timeval; + +/* +** Opaque type for notification object +*/ + +typedef struct _OSMemoryNotification * OSMemoryNotificationRef; + +/* +** Threshold values for notifications +*/ + +typedef enum { + OSMemoryNotificationLevelAny = -1, + OSMemoryNotificationLevelNormal = 0, + OSMemoryNotificationLevelWarning = 1, + OSMemoryNotificationLevelUrgent = 2, + OSMemoryNotificationLevelCritical = 3 +} OSMemoryNotificationLevel; + +/* +** Creation routines. Returns the created OSMemoryNotificationRef in the note param. +** returns: 0 on success +** ENOMEM if insufficient memory or resources exists to create the notification object +** EINVAL if the threshold is not a valid notification level +*/ + +int OSMemoryNotificationCreate(OSMemoryNotificationRef *note); + +/* +** returns: 0 on success +** EINVAL if the notification is not an initialized notification object +*/ + +int OSMemoryNotificationDestroy(OSMemoryNotificationRef note); + +/* +** Block waiting for notification +** returns: 0 on success, with the level that triggered the notification in the level param +** EINVAL if the notification object is invalid +** ETIMEDOUT if abstime passes before notification occurs +*/ +int OSMemoryNotificationWait(OSMemoryNotificationRef note, OSMemoryNotificationLevel *level); +int OSMemoryNotificationTimedWait(OSMemoryNotificationRef note, OSMemoryNotificationLevel *level, const struct timeval *abstime); + +/* +** Simple polling interface to detect current memory pressure level +*/ + +OSMemoryNotificationLevel OSMemoryNotificationCurrentLevel(void); + +/* +** External notify(3) string for manual notification setup +*/ + +extern const char *kOSMemoryNotificationName; + +__END_DECLS + +#endif /* _OSMEMORYNOTIFICATION_H_ */ diff --git a/include/libkern/OSThermalNotification.h b/include/libkern/OSThermalNotification.h new file mode 100644 index 0000000..da74a59 --- /dev/null +++ b/include/libkern/OSThermalNotification.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2007 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#ifndef _OSTHERMALNOTIFICATION_H_ +#define _OSTHERMALNOTIFICATION_H_ + +#include + +/* +** OSThermalNotification.h +** +** Notification mechanism to alert registered tasks when device thermal conditions +** reach certain thresholds. Notifications are triggered in both directions +** so clients can manage their memory usage more and less aggressively. +** +*/ + +__BEGIN_DECLS + +typedef enum { + OSThermalNotificationLevelAny = -1, + OSThermalNotificationLevelNormal = 0, + OSThermalNotificationLevel70PercentBacklight = 3, + OSThermalNotificationLevel50PercentBacklight = 5, + OSThermalNotificationLevelAppTerminate = 12, + OSThermalNotificationLevelDeviceRestart = 16 +} OSThermalNotificationLevel; + +/* Backwards compatibility */ +#define OSThermalNotificationLevelWarning OSThermalNotificationLevel70PercentBacklight +#define OSThermalNotificationLevelUrgent OSThermalNotificationLevelAppTerminate +#define OSThermalNotificationLevelCritical OSThermalNotificationLevelDeviceRestart + +/* +** Simple polling interface to detect current thermal level +*/ + +OSThermalNotificationLevel OSThermalNotificationCurrentLevel(void); + +/* +** External notify(3) string for manual notification setup +*/ + +extern const char *kOSThermalNotificationName; + +__END_DECLS + +#endif /* _OSTHERMALNOTIFICATION_H_ */ diff --git a/include/machine/limits.h b/include/machine/limits.h index 0f40842..d52080f 100644 --- a/include/machine/limits.h +++ b/include/machine/limits.h @@ -6,6 +6,8 @@ #include #elif defined (__i386__) || defined(__x86_64__) #include +#elif defined (__arm__) +#include #else #error architecture not supported #endif diff --git a/include/protocols/dumprestore.h b/include/protocols/dumprestore.h index fca4616..885a355 100644 --- a/include/protocols/dumprestore.h +++ b/include/protocols/dumprestore.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000, 2006, 2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -101,7 +101,7 @@ union u_spcl { long c_volume; /* dump volume number */ #endif /* __LP64__ */ daddr_t c_tapea; /* logical block of this record */ - ino_t c_inumber; /* number of inode */ + unsigned int c_inumber; /* number of inode */ #ifdef __LP64__ int c_magic; /* magic number (see above) */ int c_checksum; /* record checksum */ diff --git a/include/stdlib.h b/include/stdlib.h index 602a692..62dd972 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2005 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000, 2002 - 2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -58,7 +58,7 @@ #ifndef _STDLIB_H_ #define _STDLIB_H_ -#include +#include #include <_types.h> #if !defined(_ANSI_SOURCE) @@ -336,7 +336,7 @@ int cgetset(const char *); int cgetstr(char *, const char *, char **); int cgetustr(char *, const char *, char **); -int daemon(int, int) __DARWIN_1050(daemon) __AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5; +int daemon(int, int) __DARWIN_1050(daemon) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0,__MAC_10_5,__IPHONE_2_0,__IPHONE_2_0); char *devname(dev_t, mode_t); char *devname_r(dev_t, mode_t, char *buf, int len); char *getbsize(int *, long *); diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h new file mode 100644 index 0000000..73628a7 --- /dev/null +++ b/include/sys/cdefs.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2006 - 2008 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/*********************************************************************** + * Not to be installed in /usr/include + ***********************************************************************/ + +#ifndef _LIBC_SYS_CDEFS_H_ +#define _LIBC_SYS_CDEFS_H_ + +/* + * Now include the real sys/cdefs.h. The checks in libc-features.h will assure + * that those macros are consistent with the current build environment. + */ +#include_next +#ifndef _LIBC_NO_FEATURE_VERIFICATION +#if defined(__arm__) +# include +#elif defined(__i386__) +# include +#elif defined(__ppc__) +# include +#elif defined(__ppc64__) +# include +#elif defined(__x86_64__) +# include +#else +# error "Unknown architecture." +#endif +#endif /* _LIBC_NO_FEATURE_VERIFICATION */ + +/* + * symbol suffixes used for symbol versioning + */ +#if defined(VARIANT_LEGACY) +# define LIBC_SUF_UNIX03 /* nothing */ +# define LIBC_SUF_64_BIT_INO_T /* nothing */ +# define LIBC_SUF_NON_CANCELABLE /* nothing */ +# define LIBC_SUF_1050 /* nothing */ +#else /* !VARIANT_LEGACY */ +# if __DARWIN_ONLY_UNIX_CONFORMANCE +# define LIBC_SUF_UNIX03 /* nothing */ +# else /* !__DARWIN_ONLY_UNIX_CONFORMANCE */ +# define LIBC_SUF_UNIX03 "$UNIX2003" +# endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */ + +# if defined(VARIANT_INODE32) +# define LIBC_SUF_64_BIT_INO_T /* nothing */ +# else /* !VARIANT_INODE32 */ +# if __DARWIN_ONLY_64_BIT_INO_T +# define LIBC_SUF_64_BIT_INO_T /* nothing */ +# else /* !__DARWIN_ONLY_64_BIT_INO_T */ +# define LIBC_SUF_64_BIT_INO_T "$INODE64" +# endif /* __DARWIN_ONLY_64_BIT_INO_T */ +# endif /* VARIANT_INODE32 */ + +# if defined(VARIANT_CANCELABLE) +# define LIBC_SUF_NON_CANCELABLE /* nothing */ +# else /* !LIBC_NON_CANCELABLE */ +# define LIBC_SUF_NON_CANCELABLE "$NOCANCEL" +# endif /* LIBC_NON_CANCELABLE */ + +# if defined(VARIANT_PRE1050) +# define LIBC_SUF_1050 /* nothing */ +# else /* !VARIANT_PRE1050 */ +# if __DARWIN_ONLY_VERS_1050 +# define LIBC_SUF_1050 /* nothing */ +# else /* !__DARWIN_ONLY_VERS_1050 */ +# define LIBC_SUF_1050 "$1050" +# endif /* __DARWIN_ONLY_VERS_1050 */ +# endif /* VARIANT_PRE1050 */ + +#endif /* LIBC_UNIX03 */ + +#define LIBC_SUF_EXTSN "$DARWIN_EXTSN" + +/* + * symbol versioning macros + */ +#define LIBC_ALIAS(sym) __asm("_" __STRING(sym) LIBC_SUF_UNIX03) +#define LIBC_ALIAS_C(sym) __asm("_" __STRING(sym) LIBC_SUF_NON_CANCELABLE LIBC_SUF_UNIX03) +#define LIBC_ALIAS_I(sym) __asm("_" __STRING(sym) LIBC_SUF_64_BIT_INO_T LIBC_SUF_UNIX03) +#define LIBC_INODE64(sym) __asm("_" __STRING(sym) LIBC_SUF_64_BIT_INO_T) + +#define LIBC_1050(sym) __asm("_" __STRING(sym) LIBC_SUF_1050) +#define LIBC_1050ALIAS(sym) __asm("_" __STRING(sym) LIBC_SUF_1050 LIBC_SUF_UNIX03) +#define LIBC_1050ALIAS_C(sym) __asm("_" __STRING(sym) LIBC_SUF_1050 LIBC_SUF_NON_CANCELABLE LIBC_SUF_UNIX03) +#define LIBC_1050ALIAS_I(sym) __asm("_" __STRING(sym) LIBC_SUF_1050 LIBC_SUF_64_BIT_INO_T LIBC_SUF_UNIX03) +#define LIBC_1050INODE64(sym) __asm("_" __STRING(sym) LIBC_SUF_1050 LIBC_SUF_64_BIT_INO_T) + +#define LIBC_EXTSN(sym) __asm("_" __STRING(sym) LIBC_SUF_EXTSN) +#define LIBC_EXTSN_C(sym) __asm("_" __STRING(sym) LIBC_SUF_EXTSN LIBC_SUF_NON_CANCELABLE) + +#endif /* _LIBC_SYS_CDEFS_H_ */ diff --git a/include/util.h b/include/util.h index a8078f8..bbfad2b 100644 --- a/include/util.h +++ b/include/util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2007 Apple Inc. All rights reserved. + * Copyright (c) 2000, 2007, 2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -64,7 +64,7 @@ #include #include #include -#include +#include #define PIDLOCK_NONBLOCK 1 #define PIDLOCK_USEHOSTNAME 2 @@ -85,11 +85,15 @@ #define OPENDEV_BLCK 0x04 /* Open block, not character device. */ __BEGIN_DECLS +#ifdef UNIFDEF_LEGACY_UTMP_APIS struct utmp; /* forward reference to /usr/include/utmp.h */ -void login(struct utmp *) __DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER; +void login(struct utmp *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); +#endif /* UNIFDEF_LEGACY_UTMP_APIS */ int login_tty(int); -int logout(const char *) __DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER; -void logwtmp(const char *, const char *, const char *) __DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER; +#ifdef UNIFDEF_LEGACY_UTMP_APIS +int logout(const char *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); +#endif /* UNIFDEF_LEGACY_UTMP_APIS */ +void logwtmp(const char *, const char *, const char *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0,__MAC_10_5,__IPHONE_2_0,__IPHONE_2_0); int opendev(char *, int, int, char **); int openpty(int *, int *, char *, struct termios *, struct winsize *); @@ -102,8 +106,10 @@ int ttyaction(char *tty, char *act, char *user); struct iovec; char *ttymsg(struct iovec *, int, const char *, int); __END_DECLS +#ifdef UNIFDEF_LEGACY_UTMP_APIS /* Include utmp.h last to avoid deprecation warning above */ #include +#endif /* UNIFDEF_LEGACY_UTMP_APIS */ #endif /* !_UTIL_H_ */ diff --git a/include/utmp.h b/include/utmp.h index f53763c..46a8f6a 100644 --- a/include/utmp.h +++ b/include/utmp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2005, 2007 Apple Inc. All rights reserved. + * Copyright (c) 2000, 2005, 2007, 2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -72,7 +72,7 @@ */ #include <_types.h> -#include +#include #ifndef _TIME_T #define _TIME_T @@ -92,13 +92,13 @@ struct lastlog { time_t ll_time; char ll_line[UT_LINESIZE]; char ll_host[UT_HOSTSIZE]; -} __DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER; +} __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); struct utmp { char ut_line[UT_LINESIZE]; char ut_name[UT_NAMESIZE]; char ut_host[UT_HOSTSIZE]; long ut_time; -} __DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER; +} __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); #endif /* !_UTMP_H_ */ diff --git a/include/utmpx.h b/include/utmpx.h index ee657d2..d902550 100644 --- a/include/utmpx.h +++ b/include/utmpx.h @@ -149,9 +149,11 @@ struct lastlogx * getlastlogx(uid_t, struct lastlogx *); struct lastlogx * getlastlogxbyname(const char*, struct lastlogx *); +#ifdef UNIFDEF_LEGACY_UTMP_APIS struct utmp; /* forward reference */ void getutmp(const struct utmpx *, struct utmp *); void getutmpx(const struct utmp *, struct utmpx *); +#endif /* UNIFDEF_LEGACY_UTMP_APIS */ #endif /* !_POSIX_C_SOURCE || _DARWIN_C_SOURCE */ struct utmpx * diff --git a/include/xlocale/Makefile.inc b/include/xlocale/Makefile.inc index 5aac5a6..03bc781 100644 --- a/include/xlocale/Makefile.inc +++ b/include/xlocale/Makefile.inc @@ -4,5 +4,3 @@ INCXLOCALE_INSTHDRS += __wctype.h _ctype.h _inttypes.h _langinfo.h \ INCXLOCALE_INSTHDRS := ${INCXLOCALE_INSTHDRS:S/^/${.CURDIR}\/include\/xlocale\//} XLOCALE_INSTHDRS += ${INCXLOCALE_INSTHDRS} - -STRIP_HDRS += xlocale/_ctype.h xlocale/_time.h xlocale/_wchar.h diff --git a/locale/FreeBSD/localeconv.c.patch b/locale/FreeBSD/localeconv.c.patch index 079f611..5c6ad8d 100644 --- a/locale/FreeBSD/localeconv.c.patch +++ b/locale/FreeBSD/localeconv.c.patch @@ -1,6 +1,6 @@ ---- localeconv.c.orig 2004-11-25 11:38:18.000000000 -0800 -+++ localeconv.c 2005-02-17 23:35:43.000000000 -0800 -@@ -38,11 +38,69 @@ +--- localeconv.c.orig 2008-03-15 10:50:38.000000000 -0700 ++++ localeconv.c 2008-03-26 16:49:24.000000000 -0700 +@@ -38,11 +38,71 @@ static char sccsid[] = "@(#)localeconv.c #include __FBSDID("$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.13 2003/06/26 10:46:16 phantom Exp $"); @@ -12,6 +12,7 @@ #include "lmonetary.h" #include "lnumeric.h" ++#ifdef __APPLE_PR3417676_HACK__ +/*------------------------------------------------------------------------ + * PR-3417676: We need to provide a way to force "C" locale style number + * formatting independent of the locale setting. We provide private @@ -66,11 +67,12 @@ + _onlyClocaleconv = val; + return prev; +} ++#endif /* __APPLE_PR3417676_HACK__ */ + /* * The localeconv() function constructs a struct lconv from the current * monetary and numeric locales. -@@ -52,25 +110,37 @@ +@@ -52,25 +112,37 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/ * lconv structure are computed only when the monetary or numeric * locale has been changed. */ @@ -116,7 +118,7 @@ M_ASSIGN_STR(int_curr_symbol); M_ASSIGN_STR(currency_symbol); M_ASSIGN_STR(mon_decimal_point); -@@ -92,21 +162,39 @@ +@@ -92,21 +164,41 @@ localeconv() M_ASSIGN_CHAR(int_n_sep_by_space); M_ASSIGN_CHAR(int_p_sign_posn); M_ASSIGN_CHAR(int_n_sign_posn); @@ -154,11 +156,13 @@ +struct lconv * +localeconv() +{ ++#ifdef __APPLE_PR3417676_HACK__ + /*-------------------------------------------------------------------- + * If _onlyClocaleconv is non-zero, just return __lconv, which is a "C" + * struct lconv *. Otherwise, do the normal thing. + *--------------------------------------------------------------------*/ + if (_onlyClocaleconv) + return &_C_lconv; ++#endif /* __APPLE_PR3417676_HACK__ */ + return localeconv_l(__current_locale()); } diff --git a/locale/FreeBSD/setrunelocale.c.patch b/locale/FreeBSD/setrunelocale.c.patch index 3638b2a..cf763a9 100644 --- a/locale/FreeBSD/setrunelocale.c.patch +++ b/locale/FreeBSD/setrunelocale.c.patch @@ -1,5 +1,5 @@ ---- setrunelocale.c.orig 2007-02-13 00:16:13.000000000 -0800 -+++ setrunelocale.c 2007-02-13 00:22:39.000000000 -0800 +--- setrunelocale.c.orig 2008-04-28 16:25:31.000000000 -0700 ++++ setrunelocale.c 2008-04-28 17:02:02.000000000 -0700 @@ -37,6 +37,8 @@ #include __FBSDID("$FreeBSD: src/lib/libc/locale/setrunelocale.c,v 1.44 2004/10/18 02:06:18 ache Exp $"); @@ -9,7 +9,7 @@ #include #include #include -@@ -49,67 +51,67 @@ +@@ -49,67 +51,69 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/ #include "mblocal.h" #include "setlocale.h" @@ -38,9 +38,11 @@ +extern void spin_lock(int *); +extern void spin_unlock(int *); + ++#ifdef LEGACY_RUNE_APIS +/* depreciated interfaces */ +rune_t sgetrune(const char *, size_t, char const **); +int sputrune(rune_t, char *, size_t, char **); ++#endif /* LEGACY_RUNE_APIS */ -static int -__setrunelocale(const char *encoding) @@ -118,7 +120,7 @@ /* * Slurp the locale file into the cache. -@@ -124,63 +126,74 @@ +@@ -124,63 +128,81 @@ __setrunelocale(const char *encoding) if ((fp = fopen(name, "r")) == NULL) return (errno == 0 ? ENOENT : errno); @@ -135,8 +137,6 @@ - __mbsnrtowcs = __mbsnrtowcs_std; - __wcrtomb = NULL; - __wcsnrtombs = __wcsnrtombs_std; -- rl->__sputrune = NULL; -- rl->__sgetrune = NULL; + xrl->__mbrtowc = NULL; + xrl->__mbsinit = NULL; + xrl->__mbsnrtowcs = __mbsnrtowcs_std; @@ -145,9 +145,14 @@ + + rl = &xrl->_CurrentRuneLocale; + ++#ifdef LEGACY_RUNE_APIS + /* provide backwards compatibility (depreciated interface) */ + rl->__sputrune = sputrune; + rl->__sgetrune = sgetrune; ++#else /* LEGACY_RUNE_APIS */ + rl->__sputrune = NULL; + rl->__sgetrune = NULL; ++#endif /* LEGACY_RUNE_APIS */ + if (strcmp(rl->__encoding, "NONE") == 0) - ret = _none_init(rl); @@ -210,12 +215,14 @@ return (ret); } ++#ifdef LEGACY_RUNE_APIS int -__wrap_setrunelocale(const char *locale) +setrunelocale(const char *encoding) +{ + return __setrunelocale(encoding, &__global_locale); +} ++#endif /* LEGACY_RUNE_APIS */ + +__private_extern__ int +__wrap_setrunelocale(const char *locale, locale_t loc) diff --git a/locale/Makefile.inc b/locale/Makefile.inc index 29d54d5..aff0816 100644 --- a/locale/Makefile.inc +++ b/locale/Makefile.inc @@ -3,10 +3,17 @@ # locale sources .PATH: ${.CURDIR}/${MACHINE_ARCH}/locale ${.CURDIR}/locale +CWD := ${.CURDIR}/locale +.ifdef FEATURE_LEGACY_RUNE_APIS # depreciated interfaces MISRCS += frune.c mbrune.c runedepreciated.c setinvalidrune.c +.for _src in frune.c mbrune.c setinvalidrune.c +CFLAGS-${_src} += -D__FBSDID=__RCSID +.endfor +.endif + # extended locale MISRCS += isctype.c iswctype.c xlocale.c @@ -27,12 +34,17 @@ FBSDHDRS= collate.h ldpart.h lmessages.h lmonetary.h lnumeric.h \ mblocal.h setlocale.h .include "Makefile.fbsd_end" -# special case: utf2-fbsd.c is derived from utf8.c with utf2.c.patch .ifmake autopatch -AUTOPATCHSRCS+= utf2-fbsd.c -utf2-fbsd.c: FreeBSD/utf8.c +# special case: utf2-fbsd.c is derived from utf8.c with utf2.c.patch + +# This .for statement forces evaluation of ${CWD} +.for _cwd in ${CWD} +AUTOPATCHSRCS+= ${_cwd}/utf2-fbsd.c +${_cwd}/utf2-fbsd.c: ${_cwd}/FreeBSD/utf8.c cp ${.ALLSRC} ${.TARGET} - patch ${.TARGET} ${.ALLSRC:S/utf8/utf2/}.patch; + patch ${.TARGET} ${.ALLSRC:S/utf8/utf2/}.patch +.endfor # _cwd + .else # !autopatch MISRCS+= utf2.c .endif # autopatch @@ -40,12 +52,9 @@ MISRCS+= utf2.c # also build a 64-bit long double version (ppc only) LDBLSRCS += wcstold.c -# Begin hack for 3333969 - +.ifdef FEATURE_PATCH_3333969 MISRCS += lconv.c -CFLAGS-lconv.c += -D__APPLE_PR_3333969_HACK__ - -# End hack for 3333969 +.endif # FEATURE_PATCH_3333969 LEGACYSRCS += wcsftime.c @@ -53,28 +62,35 @@ LEGACYSRCS += wcsftime.c # of other macro settings CFLAGS-wcsftime-fbsd.c += -DLIBC_ALIAS_WCSFTIME -DLIBC_ALIAS_WCSFTIME_L +.ifmake autopatch # for LP64, we need to create rune32.h # the following is good enough for ppc, ppc64, i386 and x86_64 -.ifmake autopatch + +# This .for statement forces evaluation of ${CWD} +.for _cwd in ${CWD} _ARCH != arch .if $(_ARCH) == x86_64 ARCH32 = i386 .else ARCH32 = $(_ARCH:C/64$//) .endif -rune32.h: rune-fbsd.c - ${CC} -arch ${ARCH32} -I${.CURDIR}/include -DRUNEOFF32 -o ${SRCROOT}/rune32 ${.ALLSRC} - ${SRCROOT}/rune32 > ${.TARGET} - rm -f ${SRCROOT}/rune32 -AUTOPATCHHDRS+= rune32.h +${_cwd}/rune32.h: ${_cwd}/rune-fbsd.c + ${CC} -arch ${ARCH32} -D_LIBC_NO_FEATURE_VERIFICATION -I${.CURDIR}/include -DRUNEOFF32 -o ${_cwd}/rune32 ${.ALLSRC} + ${_cwd}/rune32 > ${.TARGET} + rm -f ${_cwd}/rune32 +AUTOPATCHHDRS+= ${_cwd}/rune32.h +.endfor # _cwd + .endif # autopatch .if ${LIB} == "c" MAN3+= ctype_l.3 isalnum_l.3 iswalnum_l.3 wcstod_l.3 wcstol_l.3 MAN3+= duplocale.3 freelocale.3 newlocale.3 \ querylocale.3 uselocale.3 xlocale.3 +.ifdef FEATURE_LEGACY_RUNE_APIS # depreciated man pages MAN3+= mbrune.3 rune.3 +.endif MAN5+= utf2.5 .include "Makefile.fbsd_begin" @@ -167,8 +183,10 @@ MLINKS+= mbrlen.3 mbrlen_l.3 MLINKS+= mbrtowc.3 mbrtowc_l.3 +.ifdef FEATURE_LEGACY_RUNE_APIS MLINKS+= mbrune.3 mbmb.3 \ mbrune.3 mbrrune.3 +.endif MLINKS+= mbsinit.3 mbsinit_l.3 @@ -185,6 +203,7 @@ MLINKS+= nextwctype.3 nextwctype_l.3 MLINKS+= nl_langinfo.3 nl_langinfo_l.3 +.ifdef FEATURE_LEGACY_RUNE_APIS MLINKS+= rune.3 fgetrune.3 \ rune.3 fputrune.3 \ rune.3 fungetrune.3 \ @@ -192,6 +211,7 @@ MLINKS+= rune.3 fgetrune.3 \ rune.3 setrunelocale.3 \ rune.3 sgetrune.3 \ rune.3 sputrune.3 +.endif MLINKS+= tolower.3 tolower_l.3 diff --git a/locale/lconv.c b/locale/lconv.c index e48aa34..66dd0af 100644 --- a/locale/lconv.c +++ b/locale/lconv.c @@ -53,7 +53,6 @@ * SUCH DAMAGE. */ -#ifdef __APPLE_PR_3333969_HACK__ /* * 3333969: SPSS links directly to __lconv, which is gone in Panther. * So we resurrect the __lconv symbol, which points to data that never @@ -97,5 +96,3 @@ static struct lconv C_lconv = { * Current locale conversion. */ struct lconv *__lconv = &C_lconv; - -#endif // __APPLE_PR_3333969_HACK__ diff --git a/locale/localeconv-fbsd.c b/locale/localeconv-fbsd.c index d924e0e..f16ba6a 100644 --- a/locale/localeconv-fbsd.c +++ b/locale/localeconv-fbsd.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.13 2003/06/26 10:46:16 #include "lmonetary.h" #include "lnumeric.h" +#ifdef __APPLE_PR3417676_HACK__ /*------------------------------------------------------------------------ * PR-3417676: We need to provide a way to force "C" locale style number * formatting independent of the locale setting. We provide private @@ -100,6 +101,7 @@ __setonlyClocaleconv(int val) _onlyClocaleconv = val; return prev; } +#endif /* __APPLE_PR3417676_HACK__ */ /* * The localeconv() function constructs a struct lconv from the current @@ -190,11 +192,13 @@ localeconv_l(locale_t loc) struct lconv * localeconv() { +#ifdef __APPLE_PR3417676_HACK__ /*-------------------------------------------------------------------- * If _onlyClocaleconv is non-zero, just return __lconv, which is a "C" * struct lconv *. Otherwise, do the normal thing. *--------------------------------------------------------------------*/ if (_onlyClocaleconv) return &_C_lconv; +#endif /* __APPLE_PR3417676_HACK__ */ return localeconv_l(__current_locale()); } diff --git a/locale/nomacros-fbsd.c b/locale/nomacros-fbsd.c deleted file mode 100644 index eea37d0..0000000 --- a/locale/nomacros-fbsd.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -__FBSDID("$FreeBSD: src/lib/libc/locale/nomacros.c,v 1.5 2002/03/22 21:52:18 obrien Exp $"); - -/* - * Tell 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 . - */ -#define _EXTERNALIZE_CTYPE_INLINES_ - -#include diff --git a/locale/nomacros-fbsd.c b/locale/nomacros-fbsd.c new file mode 120000 index 0000000..d193afd --- /dev/null +++ b/locale/nomacros-fbsd.c @@ -0,0 +1 @@ +./nomacros.c \ No newline at end of file diff --git a/locale/setrunelocale-fbsd.c b/locale/setrunelocale-fbsd.c index c0cda24..4cca971 100644 --- a/locale/setrunelocale-fbsd.c +++ b/locale/setrunelocale-fbsd.c @@ -65,9 +65,11 @@ extern struct __xlocale_st_runelocale *_Read_RuneMagi(FILE *); extern void spin_lock(int *); extern void spin_unlock(int *); +#ifdef LEGACY_RUNE_APIS /* depreciated interfaces */ rune_t sgetrune(const char *, size_t, char const **); int sputrune(rune_t, char *, size_t, char **); +#endif /* LEGACY_RUNE_APIS */ __private_extern__ int __setrunelocale(const char *encoding, locale_t loc) @@ -141,9 +143,14 @@ __setrunelocale(const char *encoding, locale_t loc) rl = &xrl->_CurrentRuneLocale; +#ifdef LEGACY_RUNE_APIS /* provide backwards compatibility (depreciated interface) */ rl->__sputrune = sputrune; rl->__sgetrune = sgetrune; +#else /* LEGACY_RUNE_APIS */ + rl->__sputrune = NULL; + rl->__sgetrune = NULL; +#endif /* LEGACY_RUNE_APIS */ if (strcmp(rl->__encoding, "NONE") == 0) ret = _none_init(xrl); @@ -184,11 +191,13 @@ __setrunelocale(const char *encoding, locale_t loc) return (ret); } +#ifdef LEGACY_RUNE_APIS int setrunelocale(const char *encoding) { return __setrunelocale(encoding, &__global_locale); } +#endif /* LEGACY_RUNE_APIS */ __private_extern__ int __wrap_setrunelocale(const char *locale, locale_t loc) diff --git a/locale/xlocale.3 b/locale/xlocale.3 index 101402b..b83609d 100644 --- a/locale/xlocale.3 +++ b/locale/xlocale.3 @@ -54,6 +54,7 @@ so using it when a per-thread locale is in effect will not change locale behavior for that thread. However, it will change behavior for threads with no per-thread locale in effect. +#ifdef UNIFDEF_LEGACY_RUNE_APIS .Pp The routines defined in .Aq rune.h @@ -67,6 +68,7 @@ and sub-structures may be shared by multiple locales, .Fn setinvalidrune has been modified to make a copy of the sub-structure. This prevents it from affecting other locales. +#endif /* UNIFDEF_LEGACY_RUNE_APIS */ .Sh SEE ALSO .Xr duplocale 3 , .Xr freelocale 3 , diff --git a/man/Makefile.inc b/man/Makefile.inc index 413ad34..8206a14 100644 --- a/man/Makefile.inc +++ b/man/Makefile.inc @@ -5,6 +5,9 @@ .if ${LIB} == "c" MAN3 += assert.3 bitstring.3 stdarg.3 +.ifdef FEATURE_LEGACY_UTMP_APIS +MAN5 += utmp.5 +.endif MAN7 += environ.7 MLINKS += bitstring.3 bit_alloc.3 diff --git a/man/utmp.5 b/man/utmp.5 new file mode 100644 index 0000000..288097e --- /dev/null +++ b/man/utmp.5 @@ -0,0 +1,234 @@ +.\" $NetBSD: utmp.5,v 1.5 1994/11/30 19:31:35 jtc 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. +.\" +.\" @(#)utmp.5 8.2 (Berkeley) 3/17/94 +.\" +.Dd March 17, 1994 +.Dt UTMP 5 +.Os BSD 4 +.Sh NAME +.Nm utmp , +.Nm wtmp , +.Nm lastlog +.Nd login records (DEPRECATED) +.Sh SYNOPSIS +.Fd #include +.Sh DESCRIPTION +The interfaces in file +.Aq Pa utmp.h +are all +.Sy DEPRECIATED +and are only provided for compatibility with previous releases of Mac OS X. +See +.Xr pututxline 3 +and +.Xr utmpx 5 +for the supported interfaces. +.Pp +.Aq Pa utmp.h +declares the structures used to record information about current +users in the file +.Nm utmp , +logins and logouts in the file +.Nm wtmp , +and last logins in the file +.Nm lastlog . +The time stamps of date changes, shutdowns and reboots are also logged in +the +.Nm wtmp +file. +.Pp +These files can grow rapidly on busy systems, daily or weekly rotation +is recommended. +If any of these files do not exist, it is not created. +These +files must be created manually and are normally maintained in either the script +.Pa /etc/daily +or the script +.Pa /etc/weekly . +(See +.Xr cron 8 . ) +.Bd -literal -offset indent +#define _PATH_UTMP "/var/run/utmp" +#define _PATH_WTMP "/var/log/wtmp" +#define _PATH_LASTLOG "/var/log/lastlog" + +#define UT_NAMESIZE 8 +#define UT_LINESIZE 8 +#define UT_HOSTSIZE 16 + +struct lastlog { + time_t ll_time; + char ll_line[UT_LINESIZE]; + char ll_host[UT_HOSTSIZE]; +}; + +struct utmp { + char ut_line[UT_LINESIZE]; + char ut_name[UT_NAMESIZE]; + char ut_host[UT_HOSTSIZE]; + time_t ut_time; +}; +.Ed +.Pp +Each time a user logs in, the +.Xr login +program looks up the user's +.Tn UID +in the file +.Nm lastlog. +If it is found, the timestamp of the last time the user logged +in, the terminal line and the hostname +are written to the standard output. (Providing the login is not +.Em quiet , +see +.Xr login 1 . ) +The +.Xr login +program then records the new login time in the file +.Nm lastlog . +.Pp +After the new +.Fa lastlog +record is written , +.\" the +.\" .Xr libutil 3 +.\" routine +the file +.Nm utmp +is opened and the +.Fa utmp +record for the user inserted. +This record remains there until +the user logs out at which time it is deleted. +The +.Nm utmp +file is used by the programs +.Xr rwho 1 , +.Xr users 1 , +.Xr w 1 , +and +.Xr who 1 . +.Pp +Next, the +.Xr login +program opens the file +.Nm wtmp , +and appends the user's +.Fa utmp +record. +The same +.Fa utmp +record, with an updated time stamp is later appended +to the file when the user logs out. (See +.Xr launchd 8 . ) +The +.Nm wtmp +file is used by the programs +.Xr last 1 +and +.Xr ac 8 . +.Pp +In the event of a date change, a shutdown or reboot, the +following items are logged in the +.Nm wtmp +file. +.Pp +.Bl -tag -width shutdownxx -compact +.It Li reboot +.It Li shutdown +A system reboot or shutdown has been initiated. +The character +.Ql \&~ +is placed in the field +.Fa ut_line , +and +.Li reboot +or +.Li shutdown +in the field +.Fa ut_name . +(See +.Xr shutdown 8 +and +.Xr reboot 8 . ) +.Pp +.It Li date +The system time has been manually or automatically updated. +(See +.Xr date 1 . ) +The command name +.Xr date +is recorded in the field +.Fa ut_name . +In the field +.Fa ut_line , +the character +.Ql \\*(Ba +indicates the time prior to the change, and the character +.Ql \&{ +indicates the new time. +.El +.Sh FILES +.Bf Sy +(These files no longer exist in 10.5 or later.) +.Ef +.Pp +.Bl -tag -width /var/log/lastlog -compact +.It Pa /var/run/utmp +The +.Nm utmp file. +.It Pa /var/log/wtmp +The +.Nm wtmp file. +.It Pa /var/log/lastlog +The +.Nm lastlog file. +.El +.Sh SEE ALSO +.Xr last 1 , +.Xr login 1 , +.Xr who 1 , +.Xr ac 8 , +.Xr launchd 8 +.Sh HISTORY +A +.Nm utmp +and +.Nm wtmp +file format appeared in +.At v6 . +The +.Nm lastlog +file format appeared in +.Bx 3.0 . diff --git a/net/FreeBSD/inet_net.3 b/net/FreeBSD/inet_net.3 index 220075f..201100c 100644 --- a/net/FreeBSD/inet_net.3 +++ b/net/FreeBSD/inet_net.3 @@ -14,10 +14,6 @@ .\" 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. @@ -34,9 +30,9 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.2 2002/12/19 09:40:22 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.4 2007/01/09 00:28:02 imp Exp $ .\" -.Dd June 18, 1997 +.Dd February 26, 2006 .Dt INET_NET 3 .Os .Sh NAME @@ -88,10 +84,12 @@ It will be set to .Er ENOENT if the Internet network number was not valid). .Pp -The only value for +The currently supported values for .Fa af -currently supported is -.Dv AF_INET . +are +.Dv AF_INET +and +.Dv AF_INET6 . The .Fa size argument @@ -149,6 +147,10 @@ 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). +.\" +.\" .Sh NETWORK NUMBERS (IP VERSION 6) +.\" XXX - document this! +.\" .Sh SEE ALSO .Xr byteorder 3 , .Xr inet 3 , diff --git a/net/FreeBSD/inet_net.3.patch b/net/FreeBSD/inet_net.3.patch new file mode 100644 index 0000000..775bbc3 --- /dev/null +++ b/net/FreeBSD/inet_net.3.patch @@ -0,0 +1,26 @@ +--- inet_net.3.orig 2008-09-01 23:06:53.000000000 -0700 ++++ inet_net.3 2008-09-01 23:14:39.000000000 -0700 +@@ -42,9 +42,6 @@ + .Sh LIBRARY + .Lb libc + .Sh SYNOPSIS +-.In sys/types.h +-.In sys/socket.h +-.In netinet/in.h + .In arpa/inet.h + .Ft char * + .Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" +@@ -151,6 +148,13 @@ + .\" .Sh NETWORK NUMBERS (IP VERSION 6) + .\" XXX - document this! + .\" ++.Sh LEGACY SYNOPSIS ++.Fd #include ++.Fd #include ++.Fd #include ++.Fd #include ++.Pp ++These include files were necessary for all functions. + .Sh SEE ALSO + .Xr byteorder 3 , + .Xr inet 3 , diff --git a/net/FreeBSD/inet_net_pton.c b/net/FreeBSD/inet_net_pton.c index 6958f17..5c6598b 100644 --- a/net/FreeBSD/inet_net_pton.c +++ b/net/FreeBSD/inet_net_pton.c @@ -1,29 +1,32 @@ /* - * Copyright (c) 1996 by Internet Software Consortium. + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996,1999 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. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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 1.8 1996/11/21 10:28:12 vixie Exp $"; +static const char rcsid[] = "$Id: inet_net_pton.c,v 1.7.18.1 2005/04/27 05:00:53 sra Exp $"; #endif #include -__FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 fenner Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/inet/inet_net_pton.c,v 1.3 2007/06/03 17:20:26 ume Exp $"); + +#include "port_before.h" #include #include #include +#include #include #include @@ -33,44 +36,15 @@ __FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 f #include #include +#include "port_after.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(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. @@ -82,46 +56,47 @@ inet_net_pton(af, src, dst, size) * not an IPv4 network specification. * note: * network byte order assumed. this means 192.5.5.240/28 has - * 0x11110000 in its fourth octet. + * 0b11110000 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; +inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) { + static const char xdigits[] = "0123456789abcdef"; + static const char digits[] = "0123456789"; + int n, ch, tmp = 0, dirty, bits; const u_char *odst = dst; ch = *src++; if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii(src[1]) && isxdigit(src[1])) { + && isascii((unsigned char)(src[1])) + && isxdigit((unsigned char)(src[1]))) { /* Hexadecimal: Eat nybble string. */ - if (size <= 0) + if (size <= 0U) goto emsgsize; - *dst = 0, dirty = 0; - src++; /* skip x or X. */ - while ((ch = *src++) != '\0' && - isascii(ch) && isxdigit(ch)) { + 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; + if (dirty == 0) + tmp = n; else + tmp = (tmp << 4) | n; + if (++dirty == 2) { + if (size-- <= 0U) + goto emsgsize; + *dst++ = (u_char) tmp; + dirty = 0; + } + } + if (dirty) { /*%< Odd trailing nybble? */ + if (size-- <= 0U) goto emsgsize; + *dst++ = (u_char) (tmp << 4); } - if (dirty) - size--; } else if (isascii(ch) && isdigit(ch)) { /* Decimal: eat dotted digit string. */ for (;;) { @@ -135,7 +110,7 @@ inet_net_pton_ipv4(src, dst, size) goto enoent; } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); - if (size-- <= 0) + if (size-- <= 0U) goto emsgsize; *dst++ = (u_char) tmp; if (ch == '\0' || ch == '/') @@ -150,9 +125,10 @@ inet_net_pton_ipv4(src, dst, size) goto enoent; bits = -1; - if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { + if (ch == '/' && isascii((unsigned char)(src[0])) && + isdigit((unsigned char)(src[0])) && dst > odst) { /* CIDR width specifier. Nothing can follow it. */ - ch = *src++; /* Skip over the /. */ + ch = *src++; /*%< Skip over the /. */ bits = 0; do { n = strchr(digits, ch) - digits; @@ -175,23 +151,29 @@ inet_net_pton_ipv4(src, dst, size) goto enoent; /* If no CIDR spec was given, infer width from net class. */ if (bits == -1) { - if (*odst >= 240) /* Class E */ + if (*odst >= 240) /*%< Class E */ bits = 32; - else if (*odst >= 224) /* Class D */ - bits = 4; - else if (*odst >= 192) /* Class C */ + else if (*odst >= 224) /*%< Class D */ + bits = 8; + else if (*odst >= 192) /*%< Class C */ bits = 24; - else if (*odst >= 128) /* Class B */ + else if (*odst >= 128) /*%< Class B */ bits = 16; - else /* Class A */ + else /*%< Class A */ bits = 8; /* If imputed mask is narrower than specified octets, widen. */ if (bits < ((dst - odst) * 8)) bits = (dst - odst) * 8; + /* + * If there are no additional bits specified for a class D + * address adjust bits to 4. + */ + if (bits == 8 && *odst == 224) + bits = 4; } /* Extend network to cover the actual mask. */ while (bits > ((dst - odst) * 8)) { - if (size-- <= 0) + if (size-- <= 0U) goto emsgsize; *dst++ = '\0'; } @@ -206,9 +188,229 @@ inet_net_pton_ipv4(src, dst, size) return (-1); } +static int +getbits(const char *src, int *bitsp) { + static const char digits[] = "0123456789"; + int n; + int val; + char ch; + + val = 0; + n = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + pch = strchr(digits, ch); + if (pch != NULL) { + if (n++ != 0 && val == 0) /*%< no leading zeros */ + return (0); + val *= 10; + val += (pch - digits); + if (val > 128) /*%< range */ + return (0); + continue; + } + return (0); + } + if (n == 0) + return (0); + *bitsp = val; + return (1); +} + +static int +getv4(const char *src, u_char *dst, int *bitsp) { + static const char digits[] = "0123456789"; + u_char *odst = dst; + int n; + u_int val; + char ch; + + val = 0; + n = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + pch = strchr(digits, ch); + if (pch != NULL) { + if (n++ != 0 && val == 0) /*%< no leading zeros */ + return (0); + val *= 10; + val += (pch - digits); + if (val > 255) /*%< range */ + return (0); + continue; + } + if (ch == '.' || ch == '/') { + if (dst - odst > 3) /*%< too many octets? */ + return (0); + *dst++ = val; + if (ch == '/') + return (getbits(src, bitsp)); + val = 0; + n = 0; + continue; + } + return (0); + } + if (n == 0) + return (0); + if (dst - odst > 3) /*%< too many octets? */ + return (0); + *dst++ = val; + return (1); +} + +static int +inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { + static const char xdigits_l[] = "0123456789abcdef", + xdigits_u[] = "0123456789ABCDEF"; + u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; + const char *xdigits, *curtok; + int ch, saw_xdigit; + u_int val; + int digits; + int bits; + size_t bytes; + int words; + int ipv4; + + memset((tp = tmp), '\0', NS_IN6ADDRSZ); + endp = tp + NS_IN6ADDRSZ; + colonp = NULL; + /* Leading :: requires some special handling. */ + if (*src == ':') + if (*++src != ':') + goto enoent; + curtok = src; + saw_xdigit = 0; + val = 0; + digits = 0; + bits = -1; + ipv4 = 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 (++digits > 4) + goto enoent; + saw_xdigit = 1; + continue; + } + if (ch == ':') { + curtok = src; + if (!saw_xdigit) { + if (colonp) + goto enoent; + colonp = tp; + continue; + } else if (*src == '\0') + goto enoent; + if (tp + NS_INT16SZ > endp) + return (0); + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + saw_xdigit = 0; + digits = 0; + val = 0; + continue; + } + if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && + getv4(curtok, tp, &bits) > 0) { + tp += NS_INADDRSZ; + saw_xdigit = 0; + ipv4 = 1; + break; /*%< '\\0' was seen by inet_pton4(). */ + } + if (ch == '/' && getbits(src, &bits) > 0) + break; + goto enoent; + } + if (saw_xdigit) { + if (tp + NS_INT16SZ > endp) + goto enoent; + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + } + if (bits == -1) + bits = 128; + + words = (bits + 15) / 16; + if (words < 2) + words = 2; + if (ipv4) + words = 8; + endp = tmp + 2 * words; + + 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; + + if (tp == endp) + goto enoent; + for (i = 1; i <= n; i++) { + endp[- i] = colonp[n - i]; + colonp[n - i] = 0; + } + tp = endp; + } + if (tp != endp) + goto enoent; + + bytes = (bits + 7) / 8; + if (bytes > size) + goto emsgsize; + memcpy(dst, tmp, bytes); + return (bits); + + enoent: + errno = ENOENT; + return (-1); + + emsgsize: + errno = EMSGSIZE; + return (-1); +} + +/*% + * 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(int af, const char *src, void *dst, size_t size) { + switch (af) { + case AF_INET: + return (inet_net_pton_ipv4(src, dst, size)); + case AF_INET6: + return (inet_net_pton_ipv6(src, dst, size)); + default: + errno = EAFNOSUPPORT; + return (-1); + } +} + /* * Weak aliases for applications that use certain private entry points, * and fail to include . */ #undef inet_net_pton __weak_reference(__inet_net_pton, inet_net_pton); + +/*! \file */ diff --git a/net/FreeBSD/inet_net_pton.c.patch b/net/FreeBSD/inet_net_pton.c.patch index 6fa728e..2982459 100644 --- a/net/FreeBSD/inet_net_pton.c.patch +++ b/net/FreeBSD/inet_net_pton.c.patch @@ -1,80 +1,27 @@ ---- inet_net_pton.c.orig 2004-11-25 11:38:29.000000000 -0800 -+++ inet_net_pton.c 2005-02-24 16:53:40.000000000 -0800 -@@ -21,6 +21,8 @@ - #include - __FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 fenner Exp $"); - -+#include "xlocale_private.h" +--- inet_net_pton.c.orig 2008-09-01 22:59:17.000000000 -0700 ++++ inet_net_pton.c 2008-09-01 23:00:34.000000000 -0700 +@@ -18,6 +18,10 @@ + #if defined(LIBC_SCCS) && !defined(lint) + static const char rcsid[] = "$Id: inet_net_pton.c,v 1.7.18.1 2005/04/27 05:00:53 sra Exp $"; + #endif + - #include - #include - #include -@@ -97,19 +99,20 @@ - digits[] = "0123456789"; - int n, ch, tmp, dirty, bits; - const u_char *odst = dst; -+ locale_t loc = __current_locale(); - - ch = *src++; - if (ch == '0' && (src[0] == 'x' || src[0] == 'X') -- && isascii(src[1]) && isxdigit(src[1])) { -+ && isascii(src[1]) && isxdigit_l(src[1], loc)) { - /* 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); -+ isascii(ch) && isxdigit_l(ch, loc)) { -+ if (isupper_l(ch, loc)) -+ ch = tolower_l(ch, loc); - n = strchr(xdigits, ch) - xdigits; - assert(n >= 0 && n <= 15); - *dst |= n; -@@ -122,7 +125,7 @@ - } - if (dirty) - size--; -- } else if (isascii(ch) && isdigit(ch)) { -+ } else if (isascii(ch) && isdigit_l(ch, loc)) { - /* Decimal: eat dotted digit string. */ - for (;;) { - tmp = 0; -@@ -134,7 +137,7 @@ - if (tmp > 255) - goto enoent; - } while ((ch = *src++) != '\0' && -- isascii(ch) && isdigit(ch)); -+ isascii(ch) && isdigit_l(ch, loc)); - if (size-- <= 0) - goto emsgsize; - *dst++ = (u_char) tmp; -@@ -143,14 +146,14 @@ - if (ch != '.') - goto enoent; - ch = *src++; -- if (!isascii(ch) || !isdigit(ch)) -+ if (!isascii(ch) || !isdigit_l(ch, loc)) - goto enoent; - } - } else - goto enoent; ++/* the algorithms only can deal with ASCII, so we optimize for it */ ++#define USE_ASCII ++ + #include + __FBSDID("$FreeBSD: src/lib/libc/inet/inet_net_pton.c,v 1.3 2007/06/03 17:20:26 ume Exp $"); - bits = -1; -- if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { -+ if (ch == '/' && isascii(src[0]) && isdigit_l(src[0], loc) && dst > odst) { - /* CIDR width specifier. Nothing can follow it. */ - ch = *src++; /* Skip over the /. */ - bits = 0; -@@ -159,7 +162,7 @@ +@@ -135,11 +139,11 @@ inet_net_pton_ipv4(const char *src, u_ch assert(n >= 0 && n <= 9); bits *= 10; bits += n; -- } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); -+ } while ((ch = *src++) != '\0' && isascii(ch) && isdigit_l(ch, loc)); ++ if (bits > 32) ++ goto emsgsize; + } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); if (ch != '\0') goto enoent; - if (bits > 32) +- if (bits > 32) +- goto emsgsize; + } + + /* Firey death and destruction unless we prefetched EOS. */ diff --git a/net/Makefile.inc b/net/Makefile.inc index 1a07714..9717198 100644 --- a/net/Makefile.inc +++ b/net/Makefile.inc @@ -1,15 +1,12 @@ # from @(#)Makefile.inc 8.2 (Berkeley) 9/5/93 # $FreeBSD: src/lib/libc/net/Makefile.inc,v 1.43 2001/10/23 06:22:14 imp Exp $ -.ifnmake autopatch # machine-dependent net sources -.if exists(${.CURDIR}/${MACHINE_ARCH}/net/Makefile.inc) -.include "${.CURDIR}/${MACHINE_ARCH}/net/Makefile.inc" -.endif -.endif # !autopatch +.sinclude "${.CURDIR}/${MACHINE_ARCH}/net/Makefile.inc" # machine-independent net sources .PATH: ${.CURDIR}/${MACHINE_ARCH}/net ${.CURDIR}/net +CWD := ${.CURDIR}/net .include "Makefile.fbsd_begin" FBSDMISRCS= addr2ascii.c ascii2addr.c inet_addr.c inet_lnaof.c \ diff --git a/net/addr2ascii-fbsd.c b/net/addr2ascii-fbsd.c deleted file mode 100644 index 708b0f5..0000000 --- a/net/addr2ascii-fbsd.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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 -__FBSDID("$FreeBSD: src/lib/libc/net/addr2ascii.c,v 1.2 2002/03/22 21:52:28 obrien Exp $"); - -#include -#include - -#include -#include - -#include -#include -#include - -/*- - * 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/net/addr2ascii-fbsd.c b/net/addr2ascii-fbsd.c new file mode 120000 index 0000000..346d48e --- /dev/null +++ b/net/addr2ascii-fbsd.c @@ -0,0 +1 @@ +./addr2ascii.c \ No newline at end of file diff --git a/net/ascii2addr-fbsd.c b/net/ascii2addr-fbsd.c deleted file mode 100644 index bf2263b..0000000 --- a/net/ascii2addr-fbsd.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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 -__FBSDID("$FreeBSD: src/lib/libc/net/ascii2addr.c,v 1.4 2002/03/22 21:52:28 obrien Exp $"); - -#include -#include - -#include -#include - -#include -#include -#include - -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/net/ascii2addr-fbsd.c b/net/ascii2addr-fbsd.c new file mode 120000 index 0000000..bbe3e8a --- /dev/null +++ b/net/ascii2addr-fbsd.c @@ -0,0 +1 @@ +./ascii2addr.c \ No newline at end of file diff --git a/net/inet_lnaof-fbsd.c b/net/inet_lnaof-fbsd.c deleted file mode 100644 index d107b27..0000000 --- a/net/inet_lnaof-fbsd.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_lnaof.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/net/inet_lnaof.c,v 1.5 2002/03/22 21:52:29 obrien Exp $"); - -#include -#include -#include - -/* - * Return the local network address portion of an - * internet address; handles class a/b/c network - * number formats. - */ -in_addr_t -inet_lnaof(in) - struct in_addr in; -{ - in_addr_t i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return ((i)&IN_CLASSA_HOST); - else if (IN_CLASSB(i)) - return ((i)&IN_CLASSB_HOST); - else - return ((i)&IN_CLASSC_HOST); -} - -/* - * Weak aliases for applications that use certain private entry points, - * and fail to include . - */ -#undef inet_lnaof -__weak_reference(__inet_lnaof, inet_lnaof); diff --git a/net/inet_lnaof-fbsd.c b/net/inet_lnaof-fbsd.c new file mode 120000 index 0000000..63a9274 --- /dev/null +++ b/net/inet_lnaof-fbsd.c @@ -0,0 +1 @@ +./inet_lnaof.c \ No newline at end of file diff --git a/net/inet_makeaddr-fbsd.c b/net/inet_makeaddr-fbsd.c deleted file mode 100644 index 27544e7..0000000 --- a/net/inet_makeaddr-fbsd.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/net/inet_makeaddr.c,v 1.4 2002/03/22 21:52:29 obrien Exp $"); - -#include -#include -#include - -/* - * Formulate an Internet address from network + host. Used in - * building addresses stored in the ifnet structure. - */ -struct in_addr -inet_makeaddr(net, host) - in_addr_t net, host; -{ - in_addr_t addr; - - if (net < 128) - addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); - else if (net < 65536) - addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); - else if (net < 16777216L) - addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); - else - addr = net | host; - addr = htonl(addr); - return (*(struct in_addr *)&addr); -} - -/* - * Weak aliases for applications that use certain private entry points, - * and fail to include . - */ -#undef inet_makeaddr -__weak_reference(__inet_makeaddr, inet_makeaddr); diff --git a/net/inet_makeaddr-fbsd.c b/net/inet_makeaddr-fbsd.c new file mode 120000 index 0000000..d695f22 --- /dev/null +++ b/net/inet_makeaddr-fbsd.c @@ -0,0 +1 @@ +./inet_makeaddr.c \ No newline at end of file diff --git a/net/inet_net.3 b/net/inet_net.3 deleted file mode 120000 index 18824dc..0000000 --- a/net/inet_net.3 +++ /dev/null @@ -1 +0,0 @@ -./inet_net.3 \ No newline at end of file diff --git a/net/inet_net.3 b/net/inet_net.3 new file mode 100644 index 0000000..469ebad --- /dev/null +++ b/net/inet_net.3 @@ -0,0 +1,167 @@ +.\" $NetBSD: inet_net.3,v 1.4 1999/03/22 19:44:52 garbled Exp $ +.\" +.\" Copyright (c) 1997 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software 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. +.\" 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 FOUNDATION 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. +.\" +.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.4 2007/01/09 00:28:02 imp Exp $ +.\" +.Dd February 26, 2006 +.Dt INET_NET 3 +.Os +.Sh NAME +.Nm inet_net_ntop , +.Nm inet_net_pton +.Nd Internet network number manipulation routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In arpa/inet.h +.Ft char * +.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" +.Ft int +.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" +.Sh DESCRIPTION +The +.Fn inet_net_ntop +function converts an Internet network number from network format (usually a +.Vt "struct in_addr" +or some other binary form, in network byte order) to CIDR presentation format +(suitable for external display purposes). +The +.Fa bits +argument +is the number of bits in +.Fa src +that are the network number. +It returns +.Dv NULL +if a system error occurs (in which case, +.Va errno +will have been set), or it returns a pointer to the destination string. +.Pp +The +.Fn inet_net_pton +function converts a presentation format Internet network number (that is, +printable form as held in a character string) to network format (usually a +.Vt "struct in_addr" +or some other internal binary representation, in network byte order). +It returns the number of bits (either computed based on the class, or +specified with /CIDR), or \-1 if a failure occurred +(in which case +.Va errno +will have been set. +It will be set to +.Er ENOENT +if the Internet network number was not valid). +.Pp +The currently supported values for +.Fa af +are +.Dv AF_INET +and +.Dv AF_INET6 . +The +.Fa size +argument +is the size of the result buffer +.Fa dst . +.Pp +.Sh NETWORK NUMBERS (IP VERSION 4) +Internet network numbers may be specified in one of the following forms: +.Bd -literal -offset indent +a.b.c.d/bits +a.b.c.d +a.b.c +a.b +a +.Ed +.Pp +When four parts are specified, each is interpreted +as a byte of data and assigned, from left to right, +to the four bytes of an Internet network number. +Note +that when an Internet network number is viewed as a 32-bit +integer quantity on a system that uses little-endian +byte order (such as the +.Tn Intel 386 , 486 , +and +.Tn Pentium +processors) the bytes referred to above appear as +.Dq Li d.c.b.a . +That is, little-endian bytes are ordered from right to left. +.Pp +When a three part number is specified, the last +part is interpreted as a 16-bit quantity and placed +in the rightmost two bytes of the Internet network number. +This makes the three part number format convenient +for specifying Class B network numbers as +.Dq Li 128.net.host . +.Pp +When a two part number is supplied, the last part +is interpreted as a 24-bit quantity and placed in +the rightmost three bytes of the Internet network number. +This makes the two part number format convenient +for specifying Class A network numbers as +.Dq Li net.host . +.Pp +When only one part is given, the value is stored +directly in the Internet network number without any byte +rearrangement. +.Pp +All numbers supplied as +.Dq parts +in a +.Ql \&. +notation +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). +.\" +.\" .Sh NETWORK NUMBERS (IP VERSION 6) +.\" XXX - document this! +.\" +.Sh LEGACY SYNOPSIS +.Fd #include +.Fd #include +.Fd #include +.Fd #include +.Pp +These include files were necessary for all functions. +.Sh SEE ALSO +.Xr byteorder 3 , +.Xr inet 3 , +.Xr networks 5 +.Sh HISTORY +The +.Fn inet_net_ntop +and +.Fn inet_net_pton +functions appeared in BIND 4.9.4. diff --git a/net/inet_net_ntop-fbsd.c b/net/inet_net_ntop-fbsd.c deleted file mode 100644 index b97428a..0000000 --- a/net/inet_net_ntop-fbsd.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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"; -#endif -#include -__FBSDID("$FreeBSD: src/lib/libc/net/inet_net_ntop.c,v 1.7 2002/03/22 21:52:29 obrien Exp $"); - -#include -#include -#include -#include - -#include -#include -#include -#include - -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -#else -# define SPRINTF(x) ((size_t)sprintf x) -#endif - -static char * inet_net_ntop_ipv4(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); -} - -/* - * Weak aliases for applications that use certain private entry points, - * and fail to include . - */ -#undef inet_net_ntop -__weak_reference(__inet_net_ntop, inet_net_ntop); diff --git a/net/inet_net_ntop-fbsd.c b/net/inet_net_ntop-fbsd.c new file mode 120000 index 0000000..2d504f3 --- /dev/null +++ b/net/inet_net_ntop-fbsd.c @@ -0,0 +1 @@ +./inet_net_ntop.c \ No newline at end of file diff --git a/net/inet_net_pton-fbsd.c b/net/inet_net_pton-fbsd.c index fc122b8..153d5bf 100644 --- a/net/inet_net_pton-fbsd.c +++ b/net/inet_net_pton-fbsd.c @@ -1,31 +1,36 @@ /* - * Copyright (c) 1996 by Internet Software Consortium. + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996,1999 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. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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 1.8 1996/11/21 10:28:12 vixie Exp $"; +static const char rcsid[] = "$Id: inet_net_pton.c,v 1.7.18.1 2005/04/27 05:00:53 sra Exp $"; #endif + +/* the algorithms only can deal with ASCII, so we optimize for it */ +#define USE_ASCII + #include -__FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 fenner Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/inet/inet_net_pton.c,v 1.3 2007/06/03 17:20:26 ume Exp $"); -#include "xlocale_private.h" +#include "port_before.h" #include #include #include +#include #include #include @@ -35,44 +40,15 @@ __FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 f #include #include +#include "port_after.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(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. @@ -84,48 +60,48 @@ inet_net_pton(af, src, dst, size) * not an IPv4 network specification. * note: * network byte order assumed. this means 192.5.5.240/28 has - * 0x11110000 in its fourth octet. + * 0b11110000 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; +inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) { + static const char xdigits[] = "0123456789abcdef"; + static const char digits[] = "0123456789"; + int n, ch, tmp = 0, dirty, bits; const u_char *odst = dst; - locale_t loc = __current_locale(); ch = *src++; if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii(src[1]) && isxdigit_l(src[1], loc)) { + && isascii((unsigned char)(src[1])) + && isxdigit((unsigned char)(src[1]))) { /* Hexadecimal: Eat nybble string. */ - if (size <= 0) + if (size <= 0U) goto emsgsize; - *dst = 0, dirty = 0; - src++; /* skip x or X. */ - while ((ch = *src++) != '\0' && - isascii(ch) && isxdigit_l(ch, loc)) { - if (isupper_l(ch, loc)) - ch = tolower_l(ch, loc); + 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; + if (dirty == 0) + tmp = n; else + tmp = (tmp << 4) | n; + if (++dirty == 2) { + if (size-- <= 0U) + goto emsgsize; + *dst++ = (u_char) tmp; + dirty = 0; + } + } + if (dirty) { /*%< Odd trailing nybble? */ + if (size-- <= 0U) goto emsgsize; + *dst++ = (u_char) (tmp << 4); } - if (dirty) - size--; - } else if (isascii(ch) && isdigit_l(ch, loc)) { + } else if (isascii(ch) && isdigit(ch)) { /* Decimal: eat dotted digit string. */ for (;;) { tmp = 0; @@ -137,8 +113,8 @@ inet_net_pton_ipv4(src, dst, size) if (tmp > 255) goto enoent; } while ((ch = *src++) != '\0' && - isascii(ch) && isdigit_l(ch, loc)); - if (size-- <= 0) + isascii(ch) && isdigit(ch)); + if (size-- <= 0U) goto emsgsize; *dst++ = (u_char) tmp; if (ch == '\0' || ch == '/') @@ -146,27 +122,28 @@ inet_net_pton_ipv4(src, dst, size) if (ch != '.') goto enoent; ch = *src++; - if (!isascii(ch) || !isdigit_l(ch, loc)) + if (!isascii(ch) || !isdigit(ch)) goto enoent; } } else goto enoent; bits = -1; - if (ch == '/' && isascii(src[0]) && isdigit_l(src[0], loc) && dst > odst) { + if (ch == '/' && isascii((unsigned char)(src[0])) && + isdigit((unsigned char)(src[0])) && dst > odst) { /* CIDR width specifier. Nothing can follow it. */ - ch = *src++; /* Skip over the /. */ + 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_l(ch, loc)); + if (bits > 32) + goto emsgsize; + } 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. */ @@ -178,23 +155,29 @@ inet_net_pton_ipv4(src, dst, size) goto enoent; /* If no CIDR spec was given, infer width from net class. */ if (bits == -1) { - if (*odst >= 240) /* Class E */ + if (*odst >= 240) /*%< Class E */ bits = 32; - else if (*odst >= 224) /* Class D */ - bits = 4; - else if (*odst >= 192) /* Class C */ + else if (*odst >= 224) /*%< Class D */ + bits = 8; + else if (*odst >= 192) /*%< Class C */ bits = 24; - else if (*odst >= 128) /* Class B */ + else if (*odst >= 128) /*%< Class B */ bits = 16; - else /* Class A */ + else /*%< Class A */ bits = 8; /* If imputed mask is narrower than specified octets, widen. */ if (bits < ((dst - odst) * 8)) bits = (dst - odst) * 8; + /* + * If there are no additional bits specified for a class D + * address adjust bits to 4. + */ + if (bits == 8 && *odst == 224) + bits = 4; } /* Extend network to cover the actual mask. */ while (bits > ((dst - odst) * 8)) { - if (size-- <= 0) + if (size-- <= 0U) goto emsgsize; *dst++ = '\0'; } @@ -209,9 +192,229 @@ inet_net_pton_ipv4(src, dst, size) return (-1); } +static int +getbits(const char *src, int *bitsp) { + static const char digits[] = "0123456789"; + int n; + int val; + char ch; + + val = 0; + n = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + pch = strchr(digits, ch); + if (pch != NULL) { + if (n++ != 0 && val == 0) /*%< no leading zeros */ + return (0); + val *= 10; + val += (pch - digits); + if (val > 128) /*%< range */ + return (0); + continue; + } + return (0); + } + if (n == 0) + return (0); + *bitsp = val; + return (1); +} + +static int +getv4(const char *src, u_char *dst, int *bitsp) { + static const char digits[] = "0123456789"; + u_char *odst = dst; + int n; + u_int val; + char ch; + + val = 0; + n = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + pch = strchr(digits, ch); + if (pch != NULL) { + if (n++ != 0 && val == 0) /*%< no leading zeros */ + return (0); + val *= 10; + val += (pch - digits); + if (val > 255) /*%< range */ + return (0); + continue; + } + if (ch == '.' || ch == '/') { + if (dst - odst > 3) /*%< too many octets? */ + return (0); + *dst++ = val; + if (ch == '/') + return (getbits(src, bitsp)); + val = 0; + n = 0; + continue; + } + return (0); + } + if (n == 0) + return (0); + if (dst - odst > 3) /*%< too many octets? */ + return (0); + *dst++ = val; + return (1); +} + +static int +inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { + static const char xdigits_l[] = "0123456789abcdef", + xdigits_u[] = "0123456789ABCDEF"; + u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; + const char *xdigits, *curtok; + int ch, saw_xdigit; + u_int val; + int digits; + int bits; + size_t bytes; + int words; + int ipv4; + + memset((tp = tmp), '\0', NS_IN6ADDRSZ); + endp = tp + NS_IN6ADDRSZ; + colonp = NULL; + /* Leading :: requires some special handling. */ + if (*src == ':') + if (*++src != ':') + goto enoent; + curtok = src; + saw_xdigit = 0; + val = 0; + digits = 0; + bits = -1; + ipv4 = 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 (++digits > 4) + goto enoent; + saw_xdigit = 1; + continue; + } + if (ch == ':') { + curtok = src; + if (!saw_xdigit) { + if (colonp) + goto enoent; + colonp = tp; + continue; + } else if (*src == '\0') + goto enoent; + if (tp + NS_INT16SZ > endp) + return (0); + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + saw_xdigit = 0; + digits = 0; + val = 0; + continue; + } + if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && + getv4(curtok, tp, &bits) > 0) { + tp += NS_INADDRSZ; + saw_xdigit = 0; + ipv4 = 1; + break; /*%< '\\0' was seen by inet_pton4(). */ + } + if (ch == '/' && getbits(src, &bits) > 0) + break; + goto enoent; + } + if (saw_xdigit) { + if (tp + NS_INT16SZ > endp) + goto enoent; + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + } + if (bits == -1) + bits = 128; + + words = (bits + 15) / 16; + if (words < 2) + words = 2; + if (ipv4) + words = 8; + endp = tmp + 2 * words; + + 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; + + if (tp == endp) + goto enoent; + for (i = 1; i <= n; i++) { + endp[- i] = colonp[n - i]; + colonp[n - i] = 0; + } + tp = endp; + } + if (tp != endp) + goto enoent; + + bytes = (bits + 7) / 8; + if (bytes > size) + goto emsgsize; + memcpy(dst, tmp, bytes); + return (bits); + + enoent: + errno = ENOENT; + return (-1); + + emsgsize: + errno = EMSGSIZE; + return (-1); +} + +/*% + * 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(int af, const char *src, void *dst, size_t size) { + switch (af) { + case AF_INET: + return (inet_net_pton_ipv4(src, dst, size)); + case AF_INET6: + return (inet_net_pton_ipv6(src, dst, size)); + default: + errno = EAFNOSUPPORT; + return (-1); + } +} + /* * Weak aliases for applications that use certain private entry points, * and fail to include . */ #undef inet_net_pton __weak_reference(__inet_net_pton, inet_net_pton); + +/*! \file */ diff --git a/net/inet_neta-fbsd.c b/net/inet_neta-fbsd.c deleted file mode 100644 index 43b4af1..0000000 --- a/net/inet_neta-fbsd.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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"; -#endif -#include -__FBSDID("$FreeBSD: src/lib/libc/net/inet_neta.c,v 1.9 2003/01/01 18:48:43 schweikh Exp $"); - -#include -#include -#include -#include - -#include -#include -#include - -#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 an in_addr_t 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) - in_addr_t 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); -} - -/* - * Weak aliases for applications that use certain private entry points, - * and fail to include . - */ -#undef inet_neta -__weak_reference(__inet_neta, inet_neta); diff --git a/net/inet_neta-fbsd.c b/net/inet_neta-fbsd.c new file mode 120000 index 0000000..e6bea35 --- /dev/null +++ b/net/inet_neta-fbsd.c @@ -0,0 +1 @@ +./inet_neta.c \ No newline at end of file diff --git a/net/inet_netof-fbsd.c b/net/inet_netof-fbsd.c deleted file mode 100644 index 1f829a4..0000000 --- a/net/inet_netof-fbsd.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/net/inet_netof.c,v 1.5 2002/03/22 21:52:29 obrien Exp $"); - -#include -#include -#include - -/* - * Return the network number from an internet - * address; handles class a/b/c network #'s. - */ -in_addr_t -inet_netof(in) - struct in_addr in; -{ - in_addr_t i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); - else if (IN_CLASSB(i)) - return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); - else - return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); -} - -/* - * Weak aliases for applications that use certain private entry points, - * and fail to include . - */ -#undef inet_netof -__weak_reference(__inet_netof, inet_netof); diff --git a/net/inet_netof-fbsd.c b/net/inet_netof-fbsd.c new file mode 120000 index 0000000..c926efc --- /dev/null +++ b/net/inet_netof-fbsd.c @@ -0,0 +1 @@ +./inet_netof.c \ No newline at end of file diff --git a/net/inet_ntoa-fbsd.c b/net/inet_ntoa-fbsd.c deleted file mode 100644 index 326a76a..0000000 --- a/net/inet_ntoa-fbsd.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/net/inet_ntoa.c,v 1.6 2002/03/22 21:52:29 obrien Exp $"); - -#include -#include -#include -#include -#include -#include - -/* - * Convert network-format internet address - * to base 256 d.d.d.d representation. - */ -char * -inet_ntoa(in) - struct in_addr in; -{ - static char ret[18]; - - strcpy(ret, "[inet_ntoa error]"); - (void) inet_ntop(AF_INET, &in, ret, sizeof ret); - return (ret); -} - -/* - * Weak aliases for applications that use certain private entry points, - * and fail to include . - */ -#undef inet_ntoa -__weak_reference(__inet_ntoa, inet_ntoa); diff --git a/net/inet_ntoa-fbsd.c b/net/inet_ntoa-fbsd.c new file mode 120000 index 0000000..8d899ad --- /dev/null +++ b/net/inet_ntoa-fbsd.c @@ -0,0 +1 @@ +./inet_ntoa.c \ No newline at end of file diff --git a/net/linkaddr-fbsd.c b/net/linkaddr-fbsd.c deleted file mode 100644 index 0161558..0000000 --- a/net/linkaddr-fbsd.c +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/net/linkaddr.c,v 1.3 2002/03/21 18:49:23 obrien Exp $"); - -#include -#include -#include -#include - -/* States*/ -#define NAMING 0 -#define GOTONE 1 -#define GOTTWO 2 -#define RESET 3 -/* Inputs */ -#define DIGIT (4*0) -#define END (4*1) -#define DELIM (4*2) -#define LETTER (4*3) - -void -link_addr(addr, sdl) - const char *addr; - struct sockaddr_dl *sdl; -{ - char *cp = sdl->sdl_data; - char *cplim = sdl->sdl_len + (char *)sdl; - int byte = 0, state = NAMING, new; - - bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1); - sdl->sdl_family = AF_LINK; - do { - state &= ~LETTER; - if ((*addr >= '0') && (*addr <= '9')) { - new = *addr - '0'; - } else if ((*addr >= 'a') && (*addr <= 'f')) { - new = *addr - 'a' + 10; - } else if ((*addr >= 'A') && (*addr <= 'F')) { - new = *addr - 'A' + 10; - } else if (*addr == 0) { - state |= END; - } else if (state == NAMING && - (((*addr >= 'A') && (*addr <= 'Z')) || - ((*addr >= 'a') && (*addr <= 'z')))) - state |= LETTER; - else - state |= DELIM; - addr++; - switch (state /* | INPUT */) { - case NAMING | DIGIT: - case NAMING | LETTER: - *cp++ = addr[-1]; - continue; - case NAMING | DELIM: - state = RESET; - sdl->sdl_nlen = cp - sdl->sdl_data; - continue; - case GOTTWO | DIGIT: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | DIGIT: - state = GOTONE; - byte = new; - continue; - case GOTONE | DIGIT: - state = GOTTWO; - byte = new + (byte << 4); - continue; - default: /* | DELIM */ - state = RESET; - *cp++ = byte; - byte = 0; - continue; - case GOTONE | END: - case GOTTWO | END: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | END: - break; - } - break; - } while (cp < cplim); - sdl->sdl_alen = cp - LLADDR(sdl); - new = cp - (char *)sdl; - if (new > sizeof(*sdl)) - sdl->sdl_len = new; - return; -} - -static char hexlist[] = "0123456789abcdef"; - -char * -link_ntoa(sdl) - const struct sockaddr_dl *sdl; -{ - static char obuf[64]; - char *out = obuf; - int i; - u_char *in = (u_char *)LLADDR(sdl); - u_char *inlim = in + sdl->sdl_alen; - int firsttime = 1; - - if (sdl->sdl_nlen) { - bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen); - out += sdl->sdl_nlen; - if (sdl->sdl_alen) - *out++ = ':'; - } - while (in < inlim) { - if (firsttime) - firsttime = 0; - else - *out++ = '.'; - i = *in++; - if (i > 0xf) { - out[1] = hexlist[i & 0xf]; - i >>= 4; - out[0] = hexlist[i]; - out += 2; - } else - *out++ = hexlist[i]; - } - *out = 0; - return (obuf); -} diff --git a/net/linkaddr-fbsd.c b/net/linkaddr-fbsd.c new file mode 120000 index 0000000..47b6dd0 --- /dev/null +++ b/net/linkaddr-fbsd.c @@ -0,0 +1 @@ +./linkaddr.c \ No newline at end of file diff --git a/net/sockatmark-fbsd.c b/net/sockatmark-fbsd.c deleted file mode 100644 index 497ce7f..0000000 --- a/net/sockatmark-fbsd.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2002 William C. Fenner. 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 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. - * - * $FreeBSD: src/lib/libc/net/sockatmark.c,v 1.1 2002/12/13 22:22:55 fenner Exp $ - */ -#include - -int sockatmark(int s) -{ - int atmark; - - if (ioctl(s, SIOCATMARK, &atmark) == -1) - return -1; - return atmark; -} diff --git a/net/sockatmark-fbsd.c b/net/sockatmark-fbsd.c new file mode 120000 index 0000000..bcccd5c --- /dev/null +++ b/net/sockatmark-fbsd.c @@ -0,0 +1 @@ +./sockatmark.c \ No newline at end of file diff --git a/nls/Makefile.inc b/nls/Makefile.inc index e25b6c6..0efa92d 100644 --- a/nls/Makefile.inc +++ b/nls/Makefile.inc @@ -2,6 +2,7 @@ # $FreeBSD: src/lib/libc/nls/Makefile.inc,v 1.5.2.2 2001/04/25 10:04:07 ru Exp $ .PATH: ${.CURDIR}/nls +CWD := ${.CURDIR}/nls .include "Makefile.fbsd_begin" FBSDMISRCS= msgcat.c diff --git a/ppc/sys/Makefile.inc b/ppc/sys/Makefile.inc index 64a9e46..2cb77d1 100644 --- a/ppc/sys/Makefile.inc +++ b/ppc/sys/Makefile.inc @@ -9,4 +9,4 @@ MDSRCS+= OSAtomic.s \ setjmp.s \ _sigtramp.s -MDCOPYFILES+= ${.CURDIR}/ppc/sys/libc.syscall.ppc +MDCOPYFILES+= ${.CURDIR}/Platforms/${RC_TARGET_CONFIG}/ppc/libc.syscall.ppc diff --git a/ppc64/sys/Makefile.inc b/ppc64/sys/Makefile.inc index b8cff02..3d9776b 100644 --- a/ppc64/sys/Makefile.inc +++ b/ppc64/sys/Makefile.inc @@ -9,4 +9,4 @@ MDSRCS+= OSAtomic.s \ setjmp.s \ _sigtramp.s -MDCOPYFILES+= ${.CURDIR}/ppc64/sys/libc.syscall.ppc64 +MDCOPYFILES+= ${.CURDIR}/Platforms/${RC_TARGET_CONFIG}/ppc64/libc.syscall.ppc64 diff --git a/pthreads/Makefile.inc b/pthreads/Makefile.inc index 447cf68..673dc3e 100644 --- a/pthreads/Makefile.inc +++ b/pthreads/Makefile.inc @@ -1,8 +1,4 @@ -.ifnmake autopatch -.if exists(${.CURDIR}/${MACHINE_ARCH}/pthreads/Makefile.inc) -.include "${.CURDIR}/${MACHINE_ARCH}/pthreads/Makefile.inc" -.endif -.endif # !autopatch +.sinclude "${.CURDIR}/${MACHINE_ARCH}/pthreads/Makefile.inc" .PATH: ${.CURDIR}/pthreads @@ -11,13 +7,15 @@ CFLAGS += -I${.CURDIR}/pthreads MISRCS += pthread_cancelable.c pthread_cond.c pthread_tsd.c pthread.c \ pthread_mutex.c thread_setup.c stack.s pthread_rwlock.c -${SYMROOT}/plockstat.h: ${.CURDIR}/pthreads/plockstat.d +.ifdef FEATURE_PLOCKSTAT +${SYMROOTINC}/plockstat.h: ${.CURDIR}/pthreads/plockstat.d + mkdir -p ${SYMROOTINC} dtrace -o ${.TARGET} -C -h -s ${.ALLSRC} .for _src in pthread_cond.c pthread_mutex.c pthread_rwlock.c -CFLAGS-${_src} += -I${SYMROOT} -${_src:R}.So ${_src:R}.po ${_src:R}.do ${_src:R}.o: ${SYMROOT}/plockstat.h +${_src:R}.${OBJSUFFIX}: ${SYMROOTINC}/plockstat.h .endfor +.endif # FEATURE_PLOCKSTAT PTHREADS_INSTHDRS += pthread.h pthread_impl.h sched.h PTHREADS_INSTHDRS := ${PTHREADS_INSTHDRS:S/^/${.CURDIR}\/pthreads\//} diff --git a/pthreads/pthread.c b/pthreads/pthread.c index 59632e6..b01850a 100644 --- a/pthreads/pthread.c +++ b/pthreads/pthread.c @@ -217,6 +217,7 @@ void _pthread_start(pthread_t self, mach_port_t kport, void *(*fun)(void *), voi #define PTHREAD_START_POLICY_MASK 0xff #define PTHREAD_START_IMPORTANCE_MASK 0xffff +static int pthread_setschedparam_internal(pthread_t, mach_port_t, int, const struct sched_param *); extern pthread_t __bsdthread_create(void (*func)(void *), void * func_arg, void * stack, pthread_t thread, unsigned int flags); extern int __bsdthread_terminate(void * freeaddr, size_t freesize, mach_port_t kport, mach_port_t joinsem); @@ -224,6 +225,8 @@ extern int __bsdthread_terminate(void * freeaddr, size_t freesize, mach_port_t k static const vm_address_t PTHREAD_STACK_HINT = 0xF0000000; #elif defined(__i386__) || defined(__x86_64__) static const vm_address_t PTHREAD_STACK_HINT = 0xB0000000; +#elif defined(__arm__) +static const vm_address_t PTHREAD_STACK_HINT = 0x30000000; #else #error Need to define a stack address hint for this architecture #endif @@ -890,7 +893,7 @@ _pthread_create(pthread_t t, t->death = SEMAPHORE_NULL; if (kernel_thread != MACH_PORT_NULL) - pthread_setschedparam(t, t->policy, &t->param); + (void)pthread_setschedparam_internal(t, kernel_thread, t->policy, &t->param); } while (0); return (res); } @@ -1650,8 +1653,9 @@ pthread_getschedparam(pthread_t thread, /* * Set the scheduling policy and scheduling paramters for a thread. */ -int -pthread_setschedparam(pthread_t thread, +static int +pthread_setschedparam_internal(pthread_t thread, + mach_port_t kport, int policy, const struct sched_param *param) { @@ -1682,14 +1686,48 @@ pthread_setschedparam(pthread_t thread, default: return (EINVAL); } - ret = thread_policy(pthread_mach_thread_np(thread), policy, base, count, TRUE); + ret = thread_policy(kport, policy, base, count, TRUE); if (ret != KERN_SUCCESS) return (EINVAL); - thread->policy = policy; - thread->param = *param; return (0); } +int +pthread_setschedparam(pthread_t t, + int policy, + const struct sched_param *param) +{ + mach_port_t kport = MACH_PORT_NULL; + int error; + int bypass = 1; + + if (t != pthread_self() && t != &_thread ) { //since the main thread will not get de-allocated from underneath us + bypass = 0; + if (_pthread_lookup_thread(t, &kport, 0) != 0) + return(ESRCH); + } else + kport = t->kernel_thread; + + error = pthread_setschedparam_internal(t, kport, policy, param); + if (error == 0) { + if (bypass == 0) { + /* ensure the thread is still valid */ + LOCK(_pthread_list_lock); + if ((error = _pthread_find_thread(t)) != 0) { + UNLOCK(_pthread_list_lock); + return(error); + } + t->policy = policy; + t->param = *param; + UNLOCK(_pthread_list_lock); + } else { + t->policy = policy; + t->param = *param; + } + } + return(error); +} + /* * Get the minimum priority for the given policy */ diff --git a/pthreads/pthread_cond.c b/pthreads/pthread_cond.c index ff2bed1..13b35dd 100644 --- a/pthreads/pthread_cond.c +++ b/pthreads/pthread_cond.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2003, 2007 Apple Inc. All rights reserved. + * Copyright (c) 2000-2003, 2007, 2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -52,8 +52,12 @@ #include /* For struct timespec and getclock(). */ #include +#ifdef PLOCKSTAT #include "plockstat.h" - +#else /* !PLOCKSTAT */ +#define PLOCKSTAT_MUTEX_RELEASE(x, y) +#endif /* PLOCKSTAT */ + extern void _pthread_mutex_remove(pthread_mutex_t *, pthread_t); extern int __unix_conforming; diff --git a/pthreads/pthread_internals.h b/pthreads/pthread_internals.h index cce2e48..a0549d6 100644 --- a/pthreads/pthread_internals.h +++ b/pthreads/pthread_internals.h @@ -367,7 +367,7 @@ extern struct __pthread_workqueue_pool __pthread_workqueue_pool_head; /* #include "pthread.h" -#if defined(__i386__) || defined(__ppc64__) || defined(__x86_64__) +#if defined(__i386__) || defined(__ppc64__) || defined(__x86_64__) || defined(__arm__) /* * Inside libSystem, we can use r13 or %gs directly to get access to the * thread-specific data area. The current thread is in the first slot. @@ -381,6 +381,9 @@ _pthread_self_direct(void) #elif defined(__ppc64__) register const pthread_t __pthread_self asm ("r13"); ret = __pthread_self; +#elif defined(__arm__) + register const pthread_t __pthread_self asm ("r9"); + ret = __pthread_self; #endif return ret; } diff --git a/pthreads/pthread_machdep.h b/pthreads/pthread_machdep.h index 9dc0be2..af369c1 100644 --- a/pthreads/pthread_machdep.h +++ b/pthreads/pthread_machdep.h @@ -135,6 +135,9 @@ _pthread_getspecific_direct(unsigned long slot) #elif defined(__ppc64__) register void **__pthread_tsd asm ("r13"); ret = __pthread_tsd[slot + (_PTHREAD_TSD_OFFSET / sizeof(void *))]; +#elif defined(__arm__) + register void **__pthread_tsd asm ("r9"); + ret = __pthread_tsd[slot + (_PTHREAD_TSD_OFFSET / sizeof(void *))]; #else #error no pthread_getspecific_direct implementation for this arch #endif diff --git a/pthreads/pthread_mutex.c b/pthreads/pthread_mutex.c index dbe5cf6..04c38a2 100644 --- a/pthreads/pthread_mutex.c +++ b/pthreads/pthread_mutex.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2003, 2007 Apple Inc. All rights reserved. + * Copyright (c) 2000-2003, 2007, 2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -52,7 +52,17 @@ #include "pthread_internals.h" +#ifdef PLOCKSTAT #include "plockstat.h" +#else /* !PLOCKSTAT */ +#define PLOCKSTAT_MUTEX_SPIN(x) +#define PLOCKSTAT_MUTEX_SPUN(x, y, z) +#define PLOCKSTAT_MUTEX_ERROR(x, y) +#define PLOCKSTAT_MUTEX_BLOCK(x) +#define PLOCKSTAT_MUTEX_BLOCKED(x, y) +#define PLOCKSTAT_MUTEX_ACQUIRE(x, y, z) +#define PLOCKSTAT_MUTEX_RELEASE(x, y) +#endif /* PLOCKSTAT */ extern int __unix_conforming; diff --git a/pthreads/pthread_rwlock.c b/pthreads/pthread_rwlock.c index 92dd740..35bb6d0 100644 --- a/pthreads/pthread_rwlock.c +++ b/pthreads/pthread_rwlock.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2003, 2007 Apple Inc. All rights reserved. + * Copyright (c) 2000-2003, 2007, 2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -58,7 +58,16 @@ #include "pthread_internals.h" extern int __unix_conforming; +#ifdef PLOCKSTAT #include "plockstat.h" +#else /* !PLOCKSTAT */ +#define PLOCKSTAT_RW_ERROR(x, y, z) +#define PLOCKSTAT_RW_BLOCK(x, y) +#define PLOCKSTAT_RW_BLOCKED(x, y, z) +#define PLOCKSTAT_RW_ACQUIRE(x, y) +#define PLOCKSTAT_RW_RELEASE(x, y) +#endif /* PLOCKSTAT */ + #define READ_LOCK_PLOCKSTAT 0 #define WRITE_LOCK_PLOCKSTAT 1 diff --git a/pthreads/stack.s b/pthreads/stack.s index 5be1689..a1e10d6 100644 --- a/pthreads/stack.s +++ b/pthreads/stack.s @@ -104,6 +104,25 @@ LEAF(__adjust_sp,0) subq $0x100,%rax ret +#elif defined(__arm__) + +#define LEAF(name) \ + .align 2 @\ + .globl name @\ +name: @\ + .set __framesize,0 + +LEAF(__sp) + mov r0,sp + bx lr + +/* + * void *_adjust_sp(void *sp) + */ +LEAF(__adjust_sp) + sub r0, r0, #0x100 + bx lr + #else #error sp functions not defined for this architecture #endif diff --git a/pthreads/thread_setup.c b/pthreads/thread_setup.c index dab0750..2f6c9d5 100644 --- a/pthreads/thread_setup.c +++ b/pthreads/thread_setup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2003, 2008 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -51,6 +51,8 @@ #if defined(__ppc__) || defined(__ppc64__) #include +#elif defined(__arm__) +#include #endif #include "pthread_internals.h" @@ -203,6 +205,48 @@ _pthread_setup(pthread_t thread, r); } +#elif defined(__arm__) + arm_thread_state_t state = {0}; + arm_thread_state_t *ts = &state; + thread_state_flavor_t flavor = ARM_THREAD_STATE; + count = ARM_THREAD_STATE_COUNT; + + if (suspended) { + PTHREAD_MACH_CALL(thread_get_state(thread->kernel_thread, + flavor, + (thread_state_t) &state, + &count), + r); + } + + ts->pc = (uintptr_t)routine; + + if (ts->pc & 1) { + ts->pc &= ~1; + ts->cpsr |= 0x20; /* PSR_THUMB */ + } + + ts->sp = (uintptr_t)vsp - C_ARGSAVE_LEN - C_RED_ZONE; + ts->r[0] = (uintptr_t)thread; + + /* Incase of needresume, suspend is always set */ + if (suspended) { + PTHREAD_MACH_CALL(thread_set_state(thread->kernel_thread, + flavor, + (thread_state_t) &state, + count), + r); + if (needresume) + PTHREAD_MACH_CALL(thread_resume(thread->kernel_thread), + r); + } else { + PTHREAD_MACH_CALL(thread_create_running(mach_task_self(), + flavor, + (thread_state_t) ts, + count, + &thread->kernel_thread), + r); + } #else #error _pthread_setup not defined for this architecture #endif diff --git a/regex/Makefile.inc b/regex/Makefile.inc index c04a212..2c5523a 100644 --- a/regex/Makefile.inc +++ b/regex/Makefile.inc @@ -3,6 +3,7 @@ # regex sources .PATH: ${.CURDIR}/regex +CWD := ${.CURDIR}/regex .include "Makefile.fbsd_begin" FBSDMISRCS= regcomp.c regerror.c regexec.c regfree.c diff --git a/regex/cclass.h b/regex/cclass.h deleted file mode 100644 index 956a655..0000000 --- a/regex/cclass.h +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * Copyright (c) 1992, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Henry Spencer. - * - * 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. - * - * @(#)cclass.h 8.3 (Berkeley) 3/20/94 - * $FreeBSD: src/lib/libc/regex/cclass.h,v 1.4 2002/03/22 23:41:56 obrien Exp $ - */ - - -typedef enum {CALNUM, CALPHA, CBLANK, CCNTRL, CDIGIT, CGRAPH, - CLOWER, CPRINT, CPUNCT, CSPACE, CUPPER, CXDIGIT} citype; - -/* character-class table */ -static struct cclass { - char *name; - citype fidx; -} cclasses[] = { - {"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/regex/cclass.h b/regex/cclass.h new file mode 120000 index 0000000..b39907d --- /dev/null +++ b/regex/cclass.h @@ -0,0 +1 @@ +./cclass.h \ No newline at end of file diff --git a/regex/cname.h b/regex/cname.h deleted file mode 100644 index 4f0d583..0000000 --- a/regex/cname.h +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * Copyright (c) 1992, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Henry Spencer. - * - * 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. - * - * @(#)cname.h 8.3 (Berkeley) 3/20/94 - * $FreeBSD: src/lib/libc/regex/cname.h,v 1.3 2002/03/22 23:41:56 obrien Exp $ - */ - -/* character-name table */ -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} -}; diff --git a/regex/cname.h b/regex/cname.h new file mode 120000 index 0000000..776c31e --- /dev/null +++ b/regex/cname.h @@ -0,0 +1 @@ +./cname.h \ No newline at end of file diff --git a/regex/regerror-fbsd.c b/regex/regerror-fbsd.c deleted file mode 100644 index 4e43f3d..0000000 --- a/regex/regerror-fbsd.c +++ /dev/null @@ -1,181 +0,0 @@ -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * Copyright (c) 1992, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Henry Spencer. - * - * 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. - * - * @(#)regerror.c 8.4 (Berkeley) 3/20/94 - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/regex/regerror.c,v 1.9 2004/07/12 06:07:26 tjr Exp $"); - -#include -#include -#include -#include -#include -#include - -#include "utils.h" - -/* ========= begin header generated by ./mkh ========= */ -#ifdef __cplusplus -extern "C" { -#endif - -/* === regerror.c === */ -static char *regatoi(const regex_t *preg, char *localbuf); - -#ifdef __cplusplus -} -#endif -/* ========= end header generated by ./mkh ========= */ -/* - = #define REG_NOMATCH 1 - = #define REG_BADPAT 2 - = #define REG_ECOLLATE 3 - = #define REG_ECTYPE 4 - = #define REG_EESCAPE 5 - = #define REG_ESUBREG 6 - = #define REG_EBRACK 7 - = #define REG_EPAREN 8 - = #define REG_EBRACE 9 - = #define REG_BADBR 10 - = #define REG_ERANGE 11 - = #define REG_ESPACE 12 - = #define REG_BADRPT 13 - = #define REG_EMPTY 14 - = #define REG_ASSERT 15 - = #define REG_INVARG 16 - = #define REG_ILLSEQ 17 - = #define REG_ATOI 255 // convert name to number (!) - = #define REG_ITOA 0400 // convert number to name (!) - */ -static struct rerr { - int code; - 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"}, - {REG_ILLSEQ, "REG_ILLSEQ", "illegal byte sequence"}, - {0, "", "*** unknown regexp error code ***"} -}; - -/* - - regerror - the interface to error numbers - = extern size_t regerror(int, const regex_t *, char *, size_t); - */ -/* ARGSUSED */ -size_t -regerror(errcode, preg, errbuf, errbuf_size) -int errcode; -const regex_t * __restrict preg; -char * __restrict errbuf; -size_t errbuf_size; -{ - struct rerr *r; - size_t len; - int target = errcode &~ REG_ITOA; - char *s; - char convbuf[50]; - - if (errcode == REG_ATOI) - s = regatoi(preg, convbuf); - else { - for (r = rerrs; r->code != 0; r++) - if (r->code == target) - break; - - if (errcode®_ITOA) { - if (r->code != 0) - (void) strcpy(convbuf, r->name); - else - sprintf(convbuf, "REG_0x%x", target); - assert(strlen(convbuf) < sizeof(convbuf)); - s = convbuf; - } else - s = r->explain; - } - - len = strlen(s) + 1; - if (errbuf_size > 0) { - if (errbuf_size > len) - (void) strcpy(errbuf, s); - else { - (void) strncpy(errbuf, s, errbuf_size-1); - errbuf[errbuf_size-1] = '\0'; - } - } - - return(len); -} - -/* - - regatoi - internal routine to implement REG_ATOI - == static char *regatoi(const regex_t *preg, char *localbuf); - */ -static char * -regatoi(preg, localbuf) -const regex_t *preg; -char *localbuf; -{ - struct rerr *r; - - for (r = rerrs; r->code != 0; r++) - if (strcmp(r->name, preg->re_endp) == 0) - break; - if (r->code == 0) - return("0"); - - sprintf(localbuf, "%d", r->code); - return(localbuf); -} diff --git a/regex/regerror-fbsd.c b/regex/regerror-fbsd.c new file mode 120000 index 0000000..e635b8f --- /dev/null +++ b/regex/regerror-fbsd.c @@ -0,0 +1 @@ +./regerror.c \ No newline at end of file diff --git a/regex/utils.h b/regex/utils.h deleted file mode 100644 index 5439b6c..0000000 --- a/regex/utils.h +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * Copyright (c) 1992, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Henry Spencer. - * - * 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. - * - * @(#)utils.h 8.3 (Berkeley) 3/20/94 - * $FreeBSD: src/lib/libc/regex/utils.h,v 1.2 2002/03/22 23:41:56 obrien Exp $ - */ - -/* utility definitions */ -#define DUPMAX _POSIX2_RE_DUP_MAX /* xxx is this right? */ -#define INFINITY (DUPMAX + 1) -#define NC (CHAR_MAX - CHAR_MIN + 1) -typedef unsigned char uch; - -/* switch off assertions (if not already off) if no REDEBUG */ -#ifndef REDEBUG -#ifndef NDEBUG -#define NDEBUG /* no assertions please */ -#endif -#endif -#include - -/* for old systems with bcopy() but no memmove() */ -#ifdef USEBCOPY -#define memmove(d, s, c) bcopy(s, d, c) -#endif diff --git a/regex/utils.h b/regex/utils.h new file mode 120000 index 0000000..55b5b71 --- /dev/null +++ b/regex/utils.h @@ -0,0 +1 @@ +./utils.h \ No newline at end of file diff --git a/stdio/Makefile.inc b/stdio/Makefile.inc index c09ffd2..910da4d 100644 --- a/stdio/Makefile.inc +++ b/stdio/Makefile.inc @@ -3,6 +3,7 @@ # stdio sources .PATH: ${.CURDIR}/stdio +CWD := ${.CURDIR}/stdio .include "Makefile.fbsd_begin" FBSDMISRCS= _flock_stub.c asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c \ diff --git a/stdio/_flock_stub-fbsd.c b/stdio/_flock_stub-fbsd.c deleted file mode 100644 index 3a73ee1..0000000 --- a/stdio/_flock_stub-fbsd.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 1998 John Birrell . - * 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 John Birrell. - * 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 JOHN BIRRELL 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. - */ - -/* - * POSIX stdio FILE locking functions. These assume that the locking - * is only required at FILE structure level, not at file descriptor - * level too. - * - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/_flock_stub.c,v 1.14 2004/03/09 04:51:58 jb Exp $"); - -#include "namespace.h" -#include -#include -#include -#include -#include "un-namespace.h" - -#include "local.h" - - -/* - * Weak symbols for externally visible functions in this file: - */ -__weak_reference(_flockfile, flockfile); -__weak_reference(_flockfile_debug_stub, _flockfile_debug); -__weak_reference(_ftrylockfile, ftrylockfile); -__weak_reference(_funlockfile, funlockfile); - -/* - * We need to retain binary compatibility for a while. So pretend - * that _lock is part of FILE * even though it is dereferenced off - * _extra now. When we stop encoding the size of FILE into binaries - * this can be changed in stdio.h. This will reduce the amount of - * code that has to change in the future (just remove this comment - * and #define). - */ -#define _lock _extra - -void -_flockfile(FILE *fp) -{ - pthread_t curthread = _pthread_self(); - - if (fp->_lock->fl_owner == curthread) - fp->_lock->fl_count++; - else { - /* - * Make sure this mutex is treated as a private - * internal mutex: - */ - _pthread_mutex_lock(&fp->_lock->fl_mutex); - fp->_lock->fl_owner = curthread; - fp->_lock->fl_count = 1; - } -} - -/* - * This can be overriden by the threads library if it is linked in. - */ -void -_flockfile_debug_stub(FILE *fp, char *fname, int lineno) -{ - _flockfile(fp); -} - -int -_ftrylockfile(FILE *fp) -{ - pthread_t curthread = _pthread_self(); - int ret = 0; - - if (fp->_lock->fl_owner == curthread) - fp->_lock->fl_count++; - /* - * Make sure this mutex is treated as a private - * internal mutex: - */ - else if (_pthread_mutex_trylock(&fp->_lock->fl_mutex) == 0) { - fp->_lock->fl_owner = curthread; - fp->_lock->fl_count = 1; - } - else - ret = -1; - return (ret); -} - -void -_funlockfile(FILE *fp) -{ - pthread_t curthread = _pthread_self(); - - /* - * Check if this file is owned by the current thread: - */ - if (fp->_lock->fl_owner == curthread) { - /* - * Check if this thread has locked the FILE - * more than once: - */ - if (fp->_lock->fl_count > 1) - /* - * Decrement the count of the number of - * times the running thread has locked this - * file: - */ - fp->_lock->fl_count--; - else { - /* - * The running thread will release the - * lock now: - */ - fp->_lock->fl_count = 0; - fp->_lock->fl_owner = NULL; - _pthread_mutex_unlock(&fp->_lock->fl_mutex); - } - } -} diff --git a/stdio/_flock_stub-fbsd.c b/stdio/_flock_stub-fbsd.c new file mode 120000 index 0000000..6ed2784 --- /dev/null +++ b/stdio/_flock_stub-fbsd.c @@ -0,0 +1 @@ +./_flock_stub.c \ No newline at end of file diff --git a/stdio/clrerr-fbsd.c b/stdio/clrerr-fbsd.c deleted file mode 100644 index bfac2c1..0000000 --- a/stdio/clrerr-fbsd.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/clrerr.c,v 1.9 2002/03/22 21:53:04 obrien Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "libc_private.h" -#undef clearerr - -void -clearerr(fp) - FILE *fp; -{ - FLOCKFILE(fp); - __sclearerr(fp); - FUNLOCKFILE(fp); -} diff --git a/stdio/clrerr-fbsd.c b/stdio/clrerr-fbsd.c new file mode 120000 index 0000000..c958cba --- /dev/null +++ b/stdio/clrerr-fbsd.c @@ -0,0 +1 @@ +./clrerr.c \ No newline at end of file diff --git a/stdio/fdopen-fbsd.c b/stdio/fdopen-fbsd.c deleted file mode 100644 index 15e7e8f..0000000 --- a/stdio/fdopen-fbsd.c +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fdopen.c,v 1.7 2002/03/22 21:53:04 obrien Exp $"); - -#include "namespace.h" -#include -#include -#include -#include -#include -#include "un-namespace.h" -#include "local.h" - -FILE * -fdopen(fd, mode) - int fd; - const char *mode; -{ - FILE *fp; - static int nofile; - int flags, oflags, fdflags, tmp; - - if (nofile == 0) - nofile = getdtablesize(); - - if ((flags = __sflags(mode, &oflags)) == 0) - return (NULL); - - /* Make sure the mode the user wants is a subset of the actual mode. */ - if ((fdflags = _fcntl(fd, F_GETFL, 0)) < 0) - return (NULL); - tmp = fdflags & O_ACCMODE; - if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) { - errno = EINVAL; - return (NULL); - } - - if ((fp = __sfp()) == NULL) - return (NULL); - fp->_flags = flags; - /* - * If opened for appending, but underlying descriptor does not have - * O_APPEND bit set, assert __SAPP so that __swrite() caller - * will _sseek() to the end before write. - */ - if ((oflags & O_APPEND) && !(fdflags & O_APPEND)) - fp->_flags |= __SAPP; - fp->_file = fd; - fp->_cookie = fp; - fp->_read = __sread; - fp->_write = __swrite; - fp->_seek = __sseek; - fp->_close = __sclose; - return (fp); -} diff --git a/stdio/fdopen-fbsd.c b/stdio/fdopen-fbsd.c new file mode 120000 index 0000000..bf3e32b --- /dev/null +++ b/stdio/fdopen-fbsd.c @@ -0,0 +1 @@ +./fdopen.c \ No newline at end of file diff --git a/stdio/feof-fbsd.c b/stdio/feof-fbsd.c deleted file mode 100644 index 7c09187..0000000 --- a/stdio/feof-fbsd.c +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/feof.c,v 1.9 2004/03/17 01:43:07 tjr Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "libc_private.h" - -#undef feof - -int -feof(FILE *fp) -{ - int ret; - - FLOCKFILE(fp); - ret= __sfeof(fp); - FUNLOCKFILE(fp); - return (ret); -} diff --git a/stdio/feof-fbsd.c b/stdio/feof-fbsd.c new file mode 120000 index 0000000..c1253c2 --- /dev/null +++ b/stdio/feof-fbsd.c @@ -0,0 +1 @@ +./feof.c \ No newline at end of file diff --git a/stdio/ferror-fbsd.c b/stdio/ferror-fbsd.c deleted file mode 100644 index 0f960f7..0000000 --- a/stdio/ferror-fbsd.c +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/ferror.c,v 1.9 2004/03/17 01:43:07 tjr Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "libc_private.h" - -#undef ferror - -int -ferror(FILE *fp) -{ - int ret; - - FLOCKFILE(fp); - ret = __sferror(fp); - FUNLOCKFILE(fp); - return (ret); -} diff --git a/stdio/ferror-fbsd.c b/stdio/ferror-fbsd.c new file mode 120000 index 0000000..5ad5a2f --- /dev/null +++ b/stdio/ferror-fbsd.c @@ -0,0 +1 @@ +./ferror.c \ No newline at end of file diff --git a/stdio/fgetc-fbsd.c b/stdio/fgetc-fbsd.c deleted file mode 100644 index 5cd8c7e..0000000 --- a/stdio/fgetc-fbsd.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetc.c,v 1.12 2004/03/19 09:04:56 tjr Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "libc_private.h" -#include "local.h" - -int -fgetc(fp) - FILE *fp; -{ - int retval; - FLOCKFILE(fp); - /* Orientation set by __sgetc() when buffer is empty. */ - /* ORIENT(fp, -1); */ - retval = __sgetc(fp); - FUNLOCKFILE(fp); - return (retval); -} diff --git a/stdio/fgetc-fbsd.c b/stdio/fgetc-fbsd.c new file mode 120000 index 0000000..bdb4e54 --- /dev/null +++ b/stdio/fgetc-fbsd.c @@ -0,0 +1 @@ +./fgetc.c \ No newline at end of file diff --git a/stdio/fgetln-fbsd.c b/stdio/fgetln-fbsd.c deleted file mode 100644 index a1b303e..0000000 --- a/stdio/fgetln-fbsd.c +++ /dev/null @@ -1,168 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetln.c,v 1.10 2004/07/16 05:52:51 tjr Exp $"); - -#include "namespace.h" -#include -#include -#include -#include "un-namespace.h" -#include "libc_private.h" -#include "local.h" - -/* - * Expand the line buffer. Return -1 on error. -#ifdef notdef - * The `new size' does not account for a terminating '\0', - * so we add 1 here. -#endif - */ -int -__slbexpand(FILE *fp, size_t newsize) -{ - void *p; - -#ifdef notdef - ++newsize; -#endif - if (fp->_lb._size >= newsize) - return (0); - if ((p = realloc(fp->_lb._base, newsize)) == NULL) - return (-1); - fp->_lb._base = p; - fp->_lb._size = newsize; - return (0); -} - -/* - * Get an input line. The returned pointer often (but not always) - * points into a stdio buffer. Fgetln does not alter the text of - * the returned line (which is thus not a C string because it will - * not necessarily end with '\0'), but does allow callers to modify - * it if they wish. Thus, we set __SMOD in case the caller does. - */ -char * -fgetln(FILE *fp, size_t *lenp) -{ - unsigned char *p; - size_t len; - size_t off; - - FLOCKFILE(fp); - ORIENT(fp, -1); - /* make sure there is input */ - if (fp->_r <= 0 && __srefill(fp)) { - *lenp = 0; - FUNLOCKFILE(fp); - return (NULL); - } - - /* look for a newline in the input */ - if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) { - char *ret; - - /* - * Found one. Flag buffer as modified to keep fseek from - * `optimising' a backward seek, in case the user stomps on - * the text. - */ - p++; /* advance over it */ - ret = (char *)fp->_p; - *lenp = len = p - fp->_p; - fp->_flags |= __SMOD; - fp->_r -= len; - fp->_p = p; - FUNLOCKFILE(fp); - return (ret); - } - - /* - * We have to copy the current buffered data to the line buffer. - * As a bonus, though, we can leave off the __SMOD. - * - * OPTIMISTIC is length that we (optimistically) expect will - * accomodate the `rest' of the string, on each trip through the - * loop below. - */ -#define OPTIMISTIC 80 - - for (len = fp->_r, off = 0;; len += fp->_r) { - size_t diff; - - /* - * Make sure there is room for more bytes. Copy data from - * file buffer to line buffer, refill file and look for - * newline. The loop stops only when we find a newline. - */ - if (__slbexpand(fp, len + OPTIMISTIC)) - goto error; - (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, - len - off); - off = len; - if (__srefill(fp)) - break; /* EOF or error: return partial line */ - if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL) - continue; - - /* got it: finish up the line (like code above) */ - p++; - diff = p - fp->_p; - len += diff; - if (__slbexpand(fp, len)) - goto error; - (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, - diff); - fp->_r -= diff; - fp->_p = p; - break; - } - *lenp = len; -#ifdef notdef - fp->_lb._base[len] = 0; -#endif - FUNLOCKFILE(fp); - return ((char *)fp->_lb._base); - -error: - *lenp = 0; /* ??? */ - FUNLOCKFILE(fp); - return (NULL); /* ??? */ -} diff --git a/stdio/fgetln-fbsd.c b/stdio/fgetln-fbsd.c new file mode 120000 index 0000000..61a12e8 --- /dev/null +++ b/stdio/fgetln-fbsd.c @@ -0,0 +1 @@ +./fgetln.c \ No newline at end of file diff --git a/stdio/fgetpos-fbsd.c b/stdio/fgetpos-fbsd.c deleted file mode 100644 index 581c5c8..0000000 --- a/stdio/fgetpos-fbsd.c +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetpos.c,v 1.12 2002/10/12 16:13:37 mike Exp $"); - -#include - -int -fgetpos(FILE * __restrict fp, fpos_t * __restrict pos) -{ - /* - * ftello is thread-safe; no need to lock fp. - */ - if ((*pos = ftello(fp)) == (fpos_t)-1) - return (-1); - else - return (0); -} diff --git a/stdio/fgetpos-fbsd.c b/stdio/fgetpos-fbsd.c new file mode 120000 index 0000000..331e98f --- /dev/null +++ b/stdio/fgetpos-fbsd.c @@ -0,0 +1 @@ +./fgetpos.c \ No newline at end of file diff --git a/stdio/fgets-fbsd.c b/stdio/fgets-fbsd.c deleted file mode 100644 index 36ae4fd..0000000 --- a/stdio/fgets-fbsd.c +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fgets.c,v 1.13 2002/08/13 09:30:41 tjr Exp $"); - -#include "namespace.h" -#include -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -/* - * Read at most n-1 characters from the given file. - * Stop when a newline has been read, or the count runs out. - * Return first argument, or NULL if no characters were read. - */ -char * -fgets(buf, n, fp) - char *buf; - int n; - FILE *fp; -{ - size_t len; - char *s; - unsigned char *p, *t; - - if (n <= 0) /* sanity check */ - return (NULL); - - FLOCKFILE(fp); - ORIENT(fp, -1); - s = buf; - n--; /* leave space for NUL */ - while (n != 0) { - /* - * If the buffer is empty, refill it. - */ - if ((len = fp->_r) <= 0) { - if (__srefill(fp)) { - /* EOF/error: stop with partial or no line */ - if (s == buf) { - FUNLOCKFILE(fp); - return (NULL); - } - break; - } - len = fp->_r; - } - p = fp->_p; - - /* - * Scan through at most n bytes of the current buffer, - * looking for '\n'. If found, copy up to and including - * newline, and stop. Otherwise, copy entire chunk - * and loop. - */ - if (len > n) - len = n; - t = memchr((void *)p, '\n', len); - if (t != NULL) { - len = ++t - p; - fp->_r -= len; - fp->_p = t; - (void)memcpy((void *)s, (void *)p, len); - s[len] = 0; - FUNLOCKFILE(fp); - return (buf); - } - fp->_r -= len; - fp->_p += len; - (void)memcpy((void *)s, (void *)p, len); - s += len; - n -= len; - } - *s = 0; - FUNLOCKFILE(fp); - return (buf); -} diff --git a/stdio/fgets-fbsd.c b/stdio/fgets-fbsd.c new file mode 120000 index 0000000..f32d128 --- /dev/null +++ b/stdio/fgets-fbsd.c @@ -0,0 +1 @@ +./fgets.c \ No newline at end of file diff --git a/stdio/fileno-fbsd.c b/stdio/fileno-fbsd.c deleted file mode 100644 index 60bac45..0000000 --- a/stdio/fileno-fbsd.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fileno.c,v 1.10 2004/03/17 01:43:07 tjr Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "libc_private.h" - -#undef fileno - -int -fileno(FILE *fp) -{ - int fd; - - FLOCKFILE(fp); - fd = __sfileno(fp); - FUNLOCKFILE(fp); - - return (fd); -} diff --git a/stdio/fileno-fbsd.c b/stdio/fileno-fbsd.c new file mode 120000 index 0000000..45ad009 --- /dev/null +++ b/stdio/fileno-fbsd.c @@ -0,0 +1 @@ +./fileno.c \ No newline at end of file diff --git a/stdio/floatio.h b/stdio/floatio.h deleted file mode 100644 index 83beec7..0000000 --- a/stdio/floatio.h +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * 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. - * - * 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. - * - * @(#)floatio.h 8.1 (Berkeley) 6/4/93 - * $FreeBSD: src/lib/libc/stdio/floatio.h,v 1.5 2004/01/18 08:28:47 das Exp $ - */ - -/* - * Floating point scanf/printf (input/output) definitions. - */ - -/* - * MAXEXPDIG is the maximum number of decimal digits needed to store a - * floating point exponent in the largest supported format. It should - * be ceil(log10(LDBL_MAX_10_EXP)) or, if hexadecimal floating point - * conversions are supported, ceil(log10(LDBL_MAX_EXP)). But since it - * is presently never greater than 5 in practice, we fudge it. - */ -#define MAXEXPDIG 6 -#if LDBL_MAX_EXP > 999999 -#error "floating point buffers too small" -#endif - -char *__hdtoa(double, const char *, int, int *, int *, char **); -char *__hldtoa(long double, const char *, int, int *, int *, char **); -char *__ldtoa(long double *, int, int, int *, int *, char **); diff --git a/stdio/floatio.h b/stdio/floatio.h new file mode 120000 index 0000000..a04c54b --- /dev/null +++ b/stdio/floatio.h @@ -0,0 +1 @@ +./floatio.h \ No newline at end of file diff --git a/stdio/fopen-fbsd.c b/stdio/fopen-fbsd.c deleted file mode 100644 index 5a043ca..0000000 --- a/stdio/fopen-fbsd.c +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fopen.c,v 1.10 2002/10/12 16:13:37 mike Exp $"); - -#include "namespace.h" -#include -#include -#include -#include -#include -#include "un-namespace.h" - -#include "local.h" - -FILE * -fopen(file, mode) - const char * __restrict file; - const char * __restrict mode; -{ - FILE *fp; - int f; - int flags, oflags; - - if ((flags = __sflags(mode, &oflags)) == 0) - return (NULL); - if ((fp = __sfp()) == NULL) - return (NULL); - if ((f = _open(file, oflags, DEFFILEMODE)) < 0) { - fp->_flags = 0; /* release */ - return (NULL); - } - fp->_file = f; - fp->_flags = flags; - fp->_cookie = fp; - fp->_read = __sread; - fp->_write = __swrite; - fp->_seek = __sseek; - fp->_close = __sclose; - /* - * When opening in append mode, even though we use O_APPEND, - * we need to seek to the end so that ftell() gets the right - * answer. If the user then alters the seek pointer, or - * the file extends, this will fail, but there is not much - * we can do about this. (We could set __SAPP and check in - * fseek and ftell.) - */ - if (oflags & O_APPEND) - (void)_sseek(fp, (fpos_t)0, SEEK_END); - return (fp); -} diff --git a/stdio/fopen-fbsd.c b/stdio/fopen-fbsd.c new file mode 120000 index 0000000..fb2fffa --- /dev/null +++ b/stdio/fopen-fbsd.c @@ -0,0 +1 @@ +./fopen.c \ No newline at end of file diff --git a/stdio/fpurge-fbsd.c b/stdio/fpurge-fbsd.c deleted file mode 100644 index f191843..0000000 --- a/stdio/fpurge-fbsd.c +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fpurge.c,v 1.10 2002/03/22 21:53:04 obrien Exp $"); - -#include "namespace.h" -#include -#include -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -/* - * fpurge: like fflush, but without writing anything: leave the - * given FILE's buffer empty. - */ -int -fpurge(fp) - FILE *fp; -{ - int retval; - FLOCKFILE(fp); - if (!fp->_flags) { - errno = EBADF; - 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; - } - FUNLOCKFILE(fp); - return (retval); -} diff --git a/stdio/fpurge-fbsd.c b/stdio/fpurge-fbsd.c new file mode 120000 index 0000000..87455f1 --- /dev/null +++ b/stdio/fpurge-fbsd.c @@ -0,0 +1 @@ +./fpurge.c \ No newline at end of file diff --git a/stdio/fputc-fbsd.c b/stdio/fputc-fbsd.c deleted file mode 100644 index a10af2b..0000000 --- a/stdio/fputc-fbsd.c +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fputc.c,v 1.13 2004/03/19 09:04:56 tjr Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -int -fputc(c, fp) - int c; - FILE *fp; -{ - int retval; - FLOCKFILE(fp); - /* Orientation set by __sputc() when buffer is full. */ - /* ORIENT(fp, -1); */ - retval = __sputc(c, fp); - FUNLOCKFILE(fp); - return (retval); -} diff --git a/stdio/fputc-fbsd.c b/stdio/fputc-fbsd.c new file mode 120000 index 0000000..c141df3 --- /dev/null +++ b/stdio/fputc-fbsd.c @@ -0,0 +1 @@ +./fputc.c \ No newline at end of file diff --git a/stdio/fread-fbsd.c b/stdio/fread-fbsd.c deleted file mode 100644 index ad5d81b..0000000 --- a/stdio/fread-fbsd.c +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fread.c,v 1.12 2002/10/12 16:13:37 mike Exp $"); - -#include "namespace.h" -#include -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -size_t -fread(buf, size, count, fp) - void * __restrict buf; - size_t size, count; - FILE * __restrict fp; -{ - size_t resid; - char *p; - int r; - size_t total; - - /* - * The ANSI standard requires a return value of 0 for a count - * or a size of 0. Peculiarily, it imposes no such requirements - * on fwrite; it only requires fread to be broken. - */ - if ((resid = count * size) == 0) - return (0); - FLOCKFILE(fp); - ORIENT(fp, -1); - if (fp->_r < 0) - fp->_r = 0; - total = resid; - p = buf; - while (resid > (r = fp->_r)) { - (void)memcpy((void *)p, (void *)fp->_p, (size_t)r); - fp->_p += r; - /* fp->_r = 0 ... done in __srefill */ - p += r; - resid -= r; - if (__srefill(fp)) { - /* no more input: return partial result */ - FUNLOCKFILE(fp); - return ((total - resid) / size); - } - } - (void)memcpy((void *)p, (void *)fp->_p, resid); - fp->_r -= resid; - fp->_p += resid; - FUNLOCKFILE(fp); - return (count); -} diff --git a/stdio/fread-fbsd.c b/stdio/fread-fbsd.c new file mode 120000 index 0000000..776c767 --- /dev/null +++ b/stdio/fread-fbsd.c @@ -0,0 +1 @@ +./fread.c \ No newline at end of file diff --git a/stdio/fseek-fbsd.c b/stdio/fseek-fbsd.c deleted file mode 100644 index e6a5bd6..0000000 --- a/stdio/fseek-fbsd.c +++ /dev/null @@ -1,314 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fseek.c,v 1.41 2004/05/22 15:19:41 tjr Exp $"); - -#include "namespace.h" -#include -#include -#include -#include -#include -#include -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -#define POS_ERR (-(fpos_t)1) - -int -fseek(fp, offset, whence) - FILE *fp; - long offset; - int whence; -{ - int ret; - int serrno = errno; - - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - FLOCKFILE(fp); - ret = _fseeko(fp, (off_t)offset, whence, 1); - FUNLOCKFILE(fp); - if (ret == 0) - errno = serrno; - return (ret); -} - -int -fseeko(fp, offset, whence) - FILE *fp; - off_t offset; - int whence; -{ - int ret; - int serrno = errno; - - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - FLOCKFILE(fp); - ret = _fseeko(fp, offset, whence, 0); - FUNLOCKFILE(fp); - if (ret == 0) - errno = serrno; - return (ret); -} - -/* - * Seek the given file to the given offset. - * `Whence' must be one of the three SEEK_* macros. - */ -int -_fseeko(fp, offset, whence, ltest) - FILE *fp; - off_t offset; - int whence; - int ltest; -{ - fpos_t (*seekfn)(void *, fpos_t, int); - fpos_t target, curoff, ret; - size_t n; - struct stat st; - int havepos; - - /* - * Have to be able to seek. - */ - if ((seekfn = fp->_seek) == NULL) { - errno = ESPIPE; /* historic practice */ - return (-1); - } - - /* - * Change any SEEK_CUR to SEEK_SET, and check `whence' argument. - * After this, whence is either SEEK_SET or SEEK_END. - */ - switch (whence) { - - case SEEK_CUR: - /* - * In order to seek relative to the current stream offset, - * we have to first find the current stream offset via - * ftell (see ftell for details). - */ - if (_ftello(fp, &curoff)) - return (-1); - if (curoff < 0) { - /* Unspecified position because of ungetc() at 0 */ - errno = ESPIPE; - return (-1); - } - if (offset > 0 && curoff > OFF_MAX - offset) { - errno = EOVERFLOW; - return (-1); - } - offset += curoff; - if (offset < 0) { - errno = EINVAL; - return (-1); - } - if (ltest && offset > LONG_MAX) { - errno = EOVERFLOW; - return (-1); - } - whence = SEEK_SET; - havepos = 1; - break; - - case SEEK_SET: - if (offset < 0) { - errno = EINVAL; - return (-1); - } - case SEEK_END: - curoff = 0; /* XXX just to keep gcc quiet */ - havepos = 0; - break; - - default: - errno = EINVAL; - return (-1); - } - - /* - * Can only optimise if: - * reading (and not reading-and-writing); - * not unbuffered; and - * this is a `regular' Unix file (and hence seekfn==__sseek). - * We must check __NBF first, because it is possible to have __NBF - * and __SOPT both set. - */ - if (fp->_bf._base == NULL) - __smakebuf(fp); - if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT)) - goto dumb; - if ((fp->_flags & __SOPT) == 0) { - if (seekfn != __sseek || - fp->_file < 0 || _fstat(fp->_file, &st) || - (st.st_mode & S_IFMT) != S_IFREG) { - fp->_flags |= __SNPT; - goto dumb; - } - fp->_blksize = st.st_blksize; - fp->_flags |= __SOPT; - } - - /* - * We are reading; we can try to optimise. - * Figure out where we are going and where we are now. - */ - if (whence == SEEK_SET) - target = offset; - else { - if (_fstat(fp->_file, &st)) - goto dumb; - if (offset > 0 && st.st_size > OFF_MAX - offset) { - errno = EOVERFLOW; - return (-1); - } - target = st.st_size + offset; - if ((off_t)target < 0) { - errno = EINVAL; - return (-1); - } - if (ltest && (off_t)target > LONG_MAX) { - errno = EOVERFLOW; - return (-1); - } - } - - if (!havepos && _ftello(fp, &curoff)) - goto dumb; - - /* - * (If the buffer was modified, we have to - * skip this; see fgetln.c.) - */ - if (fp->_flags & __SMOD) - goto abspos; - - /* - * Compute the number of bytes in the input buffer (pretending - * that any ungetc() input has been discarded). Adjust current - * offset backwards by this count so that it represents the - * file offset for the first byte in the current input buffer. - */ - if (HASUB(fp)) { - curoff += fp->_r; /* kill off ungetc */ - n = fp->_extra->_up - fp->_bf._base; - curoff -= n; - n += fp->_ur; - } else { - n = fp->_p - fp->_bf._base; - curoff -= n; - n += fp->_r; - } - - /* - * If the target offset is within the current buffer, - * simply adjust the pointers, clear EOF, undo ungetc(), - * and return. - */ - if (target >= curoff && target < curoff + n) { - size_t o = target - curoff; - - fp->_p = fp->_bf._base + o; - fp->_r = n - o; - if (HASUB(fp)) - FREEUB(fp); - fp->_flags &= ~__SEOF; - memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t)); - return (0); - } - -abspos: - /* - * The place we want to get to is not within the current buffer, - * but we can still be kind to the kernel copyout mechanism. - * By aligning the file offset to a block boundary, we can let - * the kernel use the VM hardware to map pages instead of - * copying bytes laboriously. Using a block boundary also - * ensures that we only read one block, rather than two. - */ - curoff = target & ~(fp->_blksize - 1); - if (_sseek(fp, curoff, SEEK_SET) == POS_ERR) - goto dumb; - fp->_r = 0; - fp->_p = fp->_bf._base; - if (HASUB(fp)) - FREEUB(fp); - n = target - curoff; - if (n) { - if (__srefill(fp) || fp->_r < n) - goto dumb; - fp->_p += n; - fp->_r -= n; - } - fp->_flags &= ~__SEOF; - return (0); - - /* - * We get here if we cannot optimise the seek ... just - * do it. Allow the seek function to change fp->_bf._base. - */ -dumb: - if (__sflush(fp) || - (ret = _sseek(fp, (fpos_t)offset, whence)) == POS_ERR) - return (-1); - /* success: clear EOF indicator and discard ungetc() data */ - if (HASUB(fp)) - FREEUB(fp); - fp->_p = fp->_bf._base; - fp->_r = 0; - /* fp->_w = 0; */ /* unnecessary (I think...) */ - fp->_flags &= ~__SEOF; - memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t)); - if (ltest && ret > LONG_MAX) { - fp->_flags |= __SERR; - errno = EOVERFLOW; - return (-1); - } - return (0); -} diff --git a/stdio/fseek-fbsd.c b/stdio/fseek-fbsd.c new file mode 120000 index 0000000..9d9ddce --- /dev/null +++ b/stdio/fseek-fbsd.c @@ -0,0 +1 @@ +./fseek.c \ No newline at end of file diff --git a/stdio/fsetpos-fbsd.c b/stdio/fsetpos-fbsd.c deleted file mode 100644 index 6d75acd..0000000 --- a/stdio/fsetpos-fbsd.c +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fsetpos.c,v 1.8 2002/03/22 21:53:04 obrien Exp $"); - -#include -#include - -/* - * fsetpos: like fseek. - */ -int -fsetpos(iop, pos) - FILE *iop; - const fpos_t *pos; -{ - return (fseeko(iop, (off_t)*pos, SEEK_SET)); -} diff --git a/stdio/fsetpos-fbsd.c b/stdio/fsetpos-fbsd.c new file mode 120000 index 0000000..513eb4a --- /dev/null +++ b/stdio/fsetpos-fbsd.c @@ -0,0 +1 @@ +./fsetpos.c \ No newline at end of file diff --git a/stdio/funopen-fbsd.c b/stdio/funopen-fbsd.c deleted file mode 100644 index 040c806..0000000 --- a/stdio/funopen-fbsd.c +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/funopen.c,v 1.5 2002/05/28 16:59:39 alfred Exp $"); - -#include -#include - -#include "local.h" - -FILE * -funopen(cookie, readfn, writefn, seekfn, closefn) - const void *cookie; - int (*readfn)(), (*writefn)(); - fpos_t (*seekfn)(void *cookie, fpos_t off, int whence); - int (*closefn)(); -{ - FILE *fp; - int flags; - - if (readfn == NULL) { - if (writefn == NULL) { /* illegal */ - errno = EINVAL; - return (NULL); - } else - flags = __SWR; /* write only */ - } else { - if (writefn == NULL) - flags = __SRD; /* read only */ - else - flags = __SRW; /* read-write */ - } - if ((fp = __sfp()) == NULL) - return (NULL); - fp->_flags = flags; - fp->_file = -1; - fp->_cookie = (void *)cookie; - fp->_read = readfn; - fp->_write = writefn; - fp->_seek = seekfn; - fp->_close = closefn; - return (fp); -} diff --git a/stdio/funopen-fbsd.c b/stdio/funopen-fbsd.c new file mode 120000 index 0000000..22c4bf4 --- /dev/null +++ b/stdio/funopen-fbsd.c @@ -0,0 +1 @@ +./funopen.c \ No newline at end of file diff --git a/stdio/fvwrite-fbsd.c b/stdio/fvwrite-fbsd.c deleted file mode 100644 index fd12da1..0000000 --- a/stdio/fvwrite-fbsd.c +++ /dev/null @@ -1,211 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fvwrite.c,v 1.17 2004/06/08 05:45:48 das Exp $"); - -#include -#include -#include -#include "local.h" -#include "fvwrite.h" - -/* - * Write some memory regions. Return zero on success, EOF on error. - * - * 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) - FILE *fp; - struct __suio *uio; -{ - size_t len; - char *p; - struct __siov *iov; - int w, s; - char *nl; - int nlknown, nldist; - - if ((len = uio->uio_resid) == 0) - return (0); - /* make sure we can write */ - if (prepwrite(fp) != 0) - return (EOF); - -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n)) - - iov = uio->uio_iov; - p = iov->iov_base; - len = iov->iov_len; - iov++; -#define GETIOV(extra_work) \ - while (len == 0) { \ - extra_work; \ - p = iov->iov_base; \ - len = iov->iov_len; \ - iov++; \ - } - if (fp->_flags & __SNBF) { - /* - * Unbuffered: write up to BUFSIZ bytes at a time. - */ - do { - GETIOV(;); - w = _swrite(fp, p, MIN(len, BUFSIZ)); - if (w <= 0) - goto err; - p += w; - len -= w; - } while ((uio->uio_resid -= w) != 0); - } else if ((fp->_flags & __SLBF) == 0) { - /* - * Fully buffered: fill partially full buffer, if any, - * and then flush. If there is no partial buffer, write - * one _bf._size byte chunk directly (without copying). - * - * String output is a special case: write as many bytes - * as fit, but pretend we wrote everything. This makes - * snprintf() return the number of bytes needed, rather - * than the number used, and avoids its write function - * (so that the write function can be invalid). - */ - do { - GETIOV(;); - if ((fp->_flags & (__SALC | __SSTR)) == - (__SALC | __SSTR) && fp->_w < len) { - size_t blen = fp->_p - fp->_bf._base; - - /* - * Alloc an extra 128 bytes (+ 1 for NULL) - * so we don't call realloc(3) so often. - */ - fp->_w = len + 128; - fp->_bf._size = blen + len + 128; - fp->_bf._base = - reallocf(fp->_bf._base, fp->_bf._size + 1); - if (fp->_bf._base == NULL) - goto err; - fp->_p = fp->_bf._base + blen; - } - w = fp->_w; - if (fp->_flags & __SSTR) { - if (len < w) - w = len; - if (w > 0) { - COPY(w); /* copy MIN(fp->_w,len), */ - fp->_w -= w; - fp->_p += w; - } - w = len; /* but pretend copied all */ - } else if (fp->_p > fp->_bf._base && len > w) { - /* fill and flush */ - COPY(w); - /* fp->_w -= w; */ /* unneeded */ - fp->_p += w; - if (__fflush(fp)) - goto err; - } else if (len >= (w = fp->_bf._size)) { - /* write directly */ - w = _swrite(fp, p, w); - if (w <= 0) - goto err; - } else { - /* fill and done */ - w = len; - COPY(w); - fp->_w -= w; - fp->_p += w; - } - p += w; - len -= w; - } while ((uio->uio_resid -= w) != 0); - } else { - /* - * Line buffered: like fully buffered, but we - * must check for newlines. Compute the distance - * to the first newline (including the newline), - * or `infinity' if there is none, then pretend - * that the amount to write is MIN(len,nldist). - */ - nlknown = 0; - nldist = 0; /* XXX just to keep gcc happy */ - do { - GETIOV(nlknown = 0); - if (!nlknown) { - nl = memchr((void *)p, '\n', len); - nldist = nl ? nl + 1 - p : len + 1; - nlknown = 1; - } - s = MIN(len, nldist); - w = fp->_w + fp->_bf._size; - if (fp->_p > fp->_bf._base && s > w) { - COPY(w); - /* fp->_w -= w; */ - fp->_p += w; - if (__fflush(fp)) - goto err; - } else if (s >= (w = fp->_bf._size)) { - w = _swrite(fp, p, w); - if (w <= 0) - goto err; - } else { - w = s; - COPY(w); - fp->_w -= w; - fp->_p += w; - } - if ((nldist -= w) == 0) { - /* copied the newline: flush and forget */ - if (__fflush(fp)) - goto err; - nlknown = 0; - } - p += w; - len -= w; - } while ((uio->uio_resid -= w) != 0); - } - return (0); - -err: - fp->_flags |= __SERR; - return (EOF); -} diff --git a/stdio/fvwrite-fbsd.c b/stdio/fvwrite-fbsd.c new file mode 120000 index 0000000..82b857c --- /dev/null +++ b/stdio/fvwrite-fbsd.c @@ -0,0 +1 @@ +./fvwrite.c \ No newline at end of file diff --git a/stdio/fvwrite.h b/stdio/fvwrite.h deleted file mode 100644 index 5414ec8..0000000 --- a/stdio/fvwrite.h +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * 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. - * - * 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. - * - * @(#)fvwrite.h 8.1 (Berkeley) 6/4/93 - * $FreeBSD: src/lib/libc/stdio/fvwrite.h,v 1.3 2002/05/28 16:59:39 alfred Exp $ - */ - -/* - * I/O descriptors for __sfvwrite(). - */ -struct __siov { - void *iov_base; - size_t iov_len; -}; -struct __suio { - struct __siov *uio_iov; - int uio_iovcnt; - int uio_resid; -}; - -extern int __sfvwrite(FILE *, struct __suio *); diff --git a/stdio/fvwrite.h b/stdio/fvwrite.h new file mode 120000 index 0000000..365b356 --- /dev/null +++ b/stdio/fvwrite.h @@ -0,0 +1 @@ +./fvwrite.h \ No newline at end of file diff --git a/stdio/fwalk-fbsd.c b/stdio/fwalk-fbsd.c deleted file mode 100644 index a8a49fc..0000000 --- a/stdio/fwalk-fbsd.c +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fwalk.c,v 1.9 2002/03/22 21:53:04 obrien Exp $"); - -#include -#include -#include -#include "local.h" -#include "glue.h" - -int -_fwalk(function) - int (*function)(FILE *); -{ - FILE *fp; - int n, ret; - struct glue *g; - - ret = 0; - /* - * It should be safe to walk the list without locking it; - * new nodes are only added to the end and none are ever - * removed. - * - * Avoid locking this list while walking it or else you will - * introduce a potential deadlock in [at least] refill.c. - */ - for (g = &__sglue; g != NULL; g = g->next) - for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) - if ((fp->_flags != 0) && ((fp->_flags & __SIGN) == 0)) - ret |= (*function)(fp); - return (ret); -} diff --git a/stdio/fwalk-fbsd.c b/stdio/fwalk-fbsd.c new file mode 120000 index 0000000..f72aef9 --- /dev/null +++ b/stdio/fwalk-fbsd.c @@ -0,0 +1 @@ +./fwalk.c \ No newline at end of file diff --git a/stdio/fwide-fbsd.c b/stdio/fwide-fbsd.c deleted file mode 100644 index 1386c48..0000000 --- a/stdio/fwide-fbsd.c +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright (c) 2002 Tim J. Robbins. - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fwide.c,v 1.1 2002/08/13 09:30:41 tjr Exp $"); - -#include "namespace.h" -#include -#include -#include -#include "un-namespace.h" -#include "libc_private.h" -#include "local.h" - -int -fwide(FILE *fp, int mode) -{ - int m; - - FLOCKFILE(fp); - /* Only change the orientation if the stream is not oriented yet. */ - if (mode != 0 && fp->_extra->orientation == 0) - fp->_extra->orientation = mode > 0 ? 1 : -1; - m = fp->_extra->orientation; - FUNLOCKFILE(fp); - - return (m); -} diff --git a/stdio/fwide-fbsd.c b/stdio/fwide-fbsd.c new file mode 120000 index 0000000..76245a0 --- /dev/null +++ b/stdio/fwide-fbsd.c @@ -0,0 +1 @@ +./fwide.c \ No newline at end of file diff --git a/stdio/getc-fbsd.c b/stdio/getc-fbsd.c deleted file mode 100644 index 0aa9dca..0000000 --- a/stdio/getc-fbsd.c +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/getc.c,v 1.13 2004/03/19 09:04:56 tjr Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "libc_private.h" -#include "local.h" - -#undef getc - -int -getc(FILE *fp) -{ - int retval; - FLOCKFILE(fp); - /* Orientation set by __sgetc() when buffer is empty. */ - /* ORIENT(fp, -1); */ - retval = __sgetc(fp); - FUNLOCKFILE(fp); - return (retval); -} diff --git a/stdio/getc-fbsd.c b/stdio/getc-fbsd.c new file mode 120000 index 0000000..06a612e --- /dev/null +++ b/stdio/getc-fbsd.c @@ -0,0 +1 @@ +./getc.c \ No newline at end of file diff --git a/stdio/getchar-fbsd.c b/stdio/getchar-fbsd.c deleted file mode 100644 index 2ea530f..0000000 --- a/stdio/getchar-fbsd.c +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/getchar.c,v 1.12 2004/03/19 09:04:56 tjr Exp $"); - -/* - * A subroutine version of the macro getchar. - */ -#include "namespace.h" -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -#undef getchar - -int -getchar() -{ - int retval; - FLOCKFILE(stdin); - /* Orientation set by __sgetc() when buffer is empty. */ - /* ORIENT(stdin, -1); */ - retval = __sgetc(stdin); - FUNLOCKFILE(stdin); - return (retval); -} diff --git a/stdio/getchar-fbsd.c b/stdio/getchar-fbsd.c new file mode 120000 index 0000000..776594f --- /dev/null +++ b/stdio/getchar-fbsd.c @@ -0,0 +1 @@ +./getchar.c \ No newline at end of file diff --git a/stdio/gets-fbsd.c b/stdio/gets-fbsd.c deleted file mode 100644 index 5ef23ab..0000000 --- a/stdio/gets-fbsd.c +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)gets.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/gets.c,v 1.16 2003/01/30 23:32:53 tjr Exp $"); - -#include "namespace.h" -#include -#include -#include -#include "un-namespace.h" -#include "libc_private.h" -#include "local.h" - -__warn_references(gets, "warning: this program uses gets(), which is unsafe."); - -char * -gets(buf) - char *buf; -{ - int c; - char *s; - static int warned; - static char w[] = - "warning: this program uses gets(), which is unsafe.\n"; - - FLOCKFILE(stdin); - ORIENT(stdin, -1); - if (!warned) { - (void) _write(STDERR_FILENO, w, sizeof(w) - 1); - warned = 1; - } - for (s = buf; (c = __sgetc(stdin)) != '\n';) - if (c == EOF) - if (s == buf) { - FUNLOCKFILE(stdin); - return (NULL); - } else - break; - else - *s++ = c; - *s = 0; - FUNLOCKFILE(stdin); - return (buf); -} diff --git a/stdio/gets-fbsd.c b/stdio/gets-fbsd.c new file mode 120000 index 0000000..4810abf --- /dev/null +++ b/stdio/gets-fbsd.c @@ -0,0 +1 @@ +./gets.c \ No newline at end of file diff --git a/stdio/getw-fbsd.c b/stdio/getw-fbsd.c deleted file mode 100644 index c7ba04f..0000000 --- a/stdio/getw-fbsd.c +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)getw.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/getw.c,v 1.7 2002/03/22 21:53:04 obrien Exp $"); - -#include - -int -getw(fp) - FILE *fp; -{ - int x; - - return (fread((void *)&x, sizeof(x), 1, fp) == 1 ? x : EOF); -} diff --git a/stdio/getw-fbsd.c b/stdio/getw-fbsd.c new file mode 120000 index 0000000..2cb73af --- /dev/null +++ b/stdio/getw-fbsd.c @@ -0,0 +1 @@ +./getw.c \ No newline at end of file diff --git a/stdio/putc-fbsd.c b/stdio/putc-fbsd.c deleted file mode 100644 index e78bb42..0000000 --- a/stdio/putc-fbsd.c +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/putc.c,v 1.13 2004/03/19 09:04:56 tjr Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -#undef putc - -int -putc(c, fp) - int c; - FILE *fp; -{ - int retval; - FLOCKFILE(fp); - /* Orientation set by __sputc() when buffer is full. */ - /* ORIENT(fp, -1); */ - retval = __sputc(c, fp); - FUNLOCKFILE(fp); - return (retval); -} diff --git a/stdio/putc-fbsd.c b/stdio/putc-fbsd.c new file mode 120000 index 0000000..5d17899 --- /dev/null +++ b/stdio/putc-fbsd.c @@ -0,0 +1 @@ +./putc.c \ No newline at end of file diff --git a/stdio/putchar-fbsd.c b/stdio/putchar-fbsd.c deleted file mode 100644 index d23161d..0000000 --- a/stdio/putchar-fbsd.c +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/putchar.c,v 1.13 2004/03/19 09:04:56 tjr Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -#undef putchar - -/* - * A subroutine version of the macro putchar - */ -int -putchar(c) - int c; -{ - int retval; - FILE *so = stdout; - - FLOCKFILE(so); - /* Orientation set by __sputc() when buffer is full. */ - /* ORIENT(so, -1); */ - retval = __sputc(c, so); - FUNLOCKFILE(so); - return (retval); -} diff --git a/stdio/putchar-fbsd.c b/stdio/putchar-fbsd.c new file mode 120000 index 0000000..931f024 --- /dev/null +++ b/stdio/putchar-fbsd.c @@ -0,0 +1 @@ +./putchar.c \ No newline at end of file diff --git a/stdio/putw-fbsd.c b/stdio/putw-fbsd.c deleted file mode 100644 index ee0c23b..0000000 --- a/stdio/putw-fbsd.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)putw.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/putw.c,v 1.9 2002/03/22 21:53:04 obrien Exp $"); - -#include "namespace.h" -#include -#include "un-namespace.h" -#include "fvwrite.h" -#include "libc_private.h" - -int -putw(w, fp) - int w; - FILE *fp; -{ - int retval; - struct __suio uio; - struct __siov iov; - - iov.iov_base = &w; - iov.iov_len = uio.uio_resid = sizeof(w); - uio.uio_iov = &iov; - uio.uio_iovcnt = 1; - FLOCKFILE(fp); - retval = __sfvwrite(fp, &uio); - FUNLOCKFILE(fp); - return (retval); -} diff --git a/stdio/putw-fbsd.c b/stdio/putw-fbsd.c new file mode 120000 index 0000000..f7fa830 --- /dev/null +++ b/stdio/putw-fbsd.c @@ -0,0 +1 @@ +./putw.c \ No newline at end of file diff --git a/stdio/refill-fbsd.c b/stdio/refill-fbsd.c deleted file mode 100644 index edd8bb6..0000000 --- a/stdio/refill-fbsd.c +++ /dev/null @@ -1,150 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/refill.c,v 1.18 2002/08/13 09:30:41 tjr Exp $"); - -#include "namespace.h" -#include -#include -#include -#include "un-namespace.h" - -#include "libc_private.h" -#include "local.h" - -static int lflush(FILE *); - -static int -lflush(FILE *fp) -{ - int ret = 0; - - if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) { - FLOCKFILE(fp); - ret = __sflush(fp); - FUNLOCKFILE(fp); - } - return (ret); -} - -/* - * Refill a stdio buffer. - * Return EOF on eof or error, 0 otherwise. - */ -int -__srefill(FILE *fp) -{ - - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - ORIENT(fp, -1); - - fp->_r = 0; /* largely a convenience for callers */ - - /* SysV does not make this test; take it out for compatibility */ - if (fp->_flags & __SEOF) - return (EOF); - - /* if not already reading, have to be reading and writing */ - if ((fp->_flags & __SRD) == 0) { - if ((fp->_flags & __SRW) == 0) { - errno = EBADF; - fp->_flags |= __SERR; - return (EOF); - } - /* switch to reading */ - if (fp->_flags & __SWR) { - if (__sflush(fp)) - return (EOF); - fp->_flags &= ~__SWR; - fp->_w = 0; - fp->_lbfsize = 0; - } - fp->_flags |= __SRD; - } else { - /* - * We were reading. If there is an ungetc buffer, - * we must have been reading from that. Drop it, - * restoring the previous buffer (if any). If there - * is anything in that buffer, return. - */ - if (HASUB(fp)) { - FREEUB(fp); - if ((fp->_r = fp->_ur) != 0) { - fp->_p = fp->_extra->_up; - return (0); - } - } - } - - if (fp->_bf._base == NULL) - __smakebuf(fp); - - /* - * Before reading from a line buffered or unbuffered file, - * flush all line buffered output files, per the ANSI C - * standard. - */ - if (fp->_flags & (__SLBF|__SNBF)) { - /* Ignore this file in _fwalk to avoid potential deadlock. */ - fp->_flags |= __SIGN; - (void) _fwalk(lflush); - fp->_flags &= ~__SIGN; - - /* Now flush this file without locking it. */ - if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) - __sflush(fp); - } - fp->_p = fp->_bf._base; - fp->_r = _sread(fp, (char *)fp->_p, fp->_bf._size); - fp->_flags &= ~__SMOD; /* buffer contents are again pristine */ - if (fp->_r <= 0) { - if (fp->_r == 0) - fp->_flags |= __SEOF; - else { - fp->_r = 0; - fp->_flags |= __SERR; - } - return (EOF); - } - return (0); -} diff --git a/stdio/refill-fbsd.c b/stdio/refill-fbsd.c new file mode 120000 index 0000000..13270fe --- /dev/null +++ b/stdio/refill-fbsd.c @@ -0,0 +1 @@ +./refill.c \ No newline at end of file diff --git a/stdio/remove-fbsd.c b/stdio/remove-fbsd.c deleted file mode 100644 index 2553f64..0000000 --- a/stdio/remove-fbsd.c +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/remove.c,v 1.8 2002/03/22 21:53:04 obrien Exp $"); - -#include -#include -#include -#include - -int -remove(file) - const char *file; -{ - struct stat sb; - - if (lstat(file, &sb) < 0) - return (-1); - if (S_ISDIR(sb.st_mode)) - return (rmdir(file)); - return (unlink(file)); -} diff --git a/stdio/remove-fbsd.c b/stdio/remove-fbsd.c new file mode 120000 index 0000000..77af909 --- /dev/null +++ b/stdio/remove-fbsd.c @@ -0,0 +1 @@ +./remove.c \ No newline at end of file diff --git a/stdio/rget-fbsd.c b/stdio/rget-fbsd.c deleted file mode 100644 index 9b7f586..0000000 --- a/stdio/rget-fbsd.c +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)rget.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/rget.c,v 1.5 2002/03/22 21:53:04 obrien Exp $"); - -#include -#include "local.h" - -/* - * Handle getc() when the buffer ran out: - * Refill, then return the first character - * in the newly-filled buffer. - */ -int -__srget(FILE *fp) -{ - if (__srefill(fp) == 0) { - fp->_r--; - return (*fp->_p++); - } - return (EOF); -} diff --git a/stdio/rget-fbsd.c b/stdio/rget-fbsd.c new file mode 120000 index 0000000..6508de2 --- /dev/null +++ b/stdio/rget-fbsd.c @@ -0,0 +1 @@ +./rget.c \ No newline at end of file diff --git a/stdio/setbuf-fbsd.c b/stdio/setbuf-fbsd.c deleted file mode 100644 index 5eb6fb1..0000000 --- a/stdio/setbuf-fbsd.c +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)setbuf.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/setbuf.c,v 1.4 2002/09/06 11:23:55 tjr Exp $"); - -#include -#include "local.h" - -void -setbuf(FILE * __restrict fp, char * __restrict buf) -{ - (void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ); -} diff --git a/stdio/setbuf-fbsd.c b/stdio/setbuf-fbsd.c new file mode 120000 index 0000000..329af07 --- /dev/null +++ b/stdio/setbuf-fbsd.c @@ -0,0 +1 @@ +./setbuf.c \ No newline at end of file diff --git a/stdio/setbuffer-fbsd.c b/stdio/setbuffer-fbsd.c deleted file mode 100644 index 6ec4376..0000000 --- a/stdio/setbuffer-fbsd.c +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)setbuffer.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/setbuffer.c,v 1.7 2002/03/22 21:53:04 obrien Exp $"); - -#include - -void -setbuffer(fp, buf, size) - FILE *fp; - char *buf; - int size; -{ - - (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size); -} - -/* - * set line buffering - */ -int -setlinebuf(fp) - FILE *fp; -{ - - return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0)); -} diff --git a/stdio/setbuffer-fbsd.c b/stdio/setbuffer-fbsd.c new file mode 120000 index 0000000..ee91e10 --- /dev/null +++ b/stdio/setbuffer-fbsd.c @@ -0,0 +1 @@ +./setbuffer.c \ No newline at end of file diff --git a/stdio/setvbuf-fbsd.c b/stdio/setvbuf-fbsd.c deleted file mode 100644 index 166d5b1..0000000 --- a/stdio/setvbuf-fbsd.c +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)setvbuf.c 8.2 (Berkeley) 11/16/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/setvbuf.c,v 1.13 2002/09/06 11:23:55 tjr Exp $"); - -#include "namespace.h" -#include -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -/* - * Set one of the three kinds of buffering, optionally including - * a buffer. - */ -int -setvbuf(FILE * __restrict fp, char * __restrict buf, int mode, size_t size) -{ - int ret, flags; - size_t iosize; - int ttyflag; - - /* - * Verify arguments. The `int' limit on `size' is due to this - * particular implementation. Note, buf and size are ignored - * when setting _IONBF. - */ - if (mode != _IONBF) - if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0) - return (EOF); - - FLOCKFILE(fp); - /* - * Write current buffer, if any. Discard unread input (including - * ungetc data), cancel line buffering, and free old buffer if - * malloc()ed. We also clear any eof condition, as if this were - * a seek. - */ - ret = 0; - (void)__sflush(fp); - if (HASUB(fp)) - FREEUB(fp); - fp->_r = fp->_lbfsize = 0; - flags = fp->_flags; - if (flags & __SMBF) - free((void *)fp->_bf._base); - flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SOFF | __SNPT | __SEOF); - - /* If setting unbuffered mode, skip all the hard work. */ - if (mode == _IONBF) - goto nbf; - - /* - * Find optimal I/O size for seek optimization. This also returns - * a `tty flag' to suggest that we check isatty(fd), but we do not - * care since our caller told us how to buffer. - */ - flags |= __swhatbuf(fp, &iosize, &ttyflag); - if (size == 0) { - buf = NULL; /* force local allocation */ - size = iosize; - } - - /* Allocate buffer if needed. */ - if (buf == NULL) { - if ((buf = malloc(size)) == NULL) { - /* - * Unable to honor user's request. We will return - * failure, but try again with file system size. - */ - ret = EOF; - if (size != iosize) { - size = iosize; - buf = malloc(size); - } - } - if (buf == NULL) { - /* No luck; switch to unbuffered I/O. */ -nbf: - fp->_flags = flags | __SNBF; - fp->_w = 0; - fp->_bf._base = fp->_p = fp->_nbuf; - fp->_bf._size = 1; - FUNLOCKFILE(fp); - return (ret); - } - flags |= __SMBF; - } - - /* - * Kill any seek optimization if the buffer is not the - * right size. - * - * SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)? - */ - if (size != iosize) - flags |= __SNPT; - - /* - * Fix up the FILE fields, and set __cleanup for output flush on - * exit (since we are buffered in some way). - */ - if (mode == _IOLBF) - flags |= __SLBF; - fp->_flags = flags; - fp->_bf._base = fp->_p = (unsigned char *)buf; - fp->_bf._size = size; - /* fp->_lbfsize is still 0 */ - if (flags & __SWR) { - /* - * Begin or continue writing: see __swsetup(). Note - * that __SNBF is impossible (it was handled earlier). - */ - if (flags & __SLBF) { - fp->_w = 0; - fp->_lbfsize = -fp->_bf._size; - } else - fp->_w = size; - } else { - /* begin/continue reading, or stay in intermediate state */ - fp->_w = 0; - } - __cleanup = _cleanup; - - FUNLOCKFILE(fp); - return (ret); -} diff --git a/stdio/setvbuf-fbsd.c b/stdio/setvbuf-fbsd.c new file mode 120000 index 0000000..dfc0b57 --- /dev/null +++ b/stdio/setvbuf-fbsd.c @@ -0,0 +1 @@ +./setvbuf.c \ No newline at end of file diff --git a/stdio/stdio-fbsd.c b/stdio/stdio-fbsd.c deleted file mode 100644 index 233427c..0000000 --- a/stdio/stdio-fbsd.c +++ /dev/null @@ -1,191 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/stdio.c,v 1.24 2003/01/07 06:17:13 tjr Exp $"); - -#include "namespace.h" -#include -#include -#include -#include -#include -#include -#include "un-namespace.h" -#include "local.h" - -/* - * Small standard I/O/seek/close functions. - */ -int -__sread(cookie, buf, n) - void *cookie; - char *buf; - int n; -{ - FILE *fp = cookie; - - return(_read(fp->_file, buf, (size_t)n)); -} - -int -__swrite(cookie, buf, n) - void *cookie; - char const *buf; - int n; -{ - FILE *fp = cookie; - - return (_write(fp->_file, buf, (size_t)n)); -} - -fpos_t -__sseek(cookie, offset, whence) - void *cookie; - fpos_t offset; - int whence; -{ - FILE *fp = cookie; - - return (lseek(fp->_file, (off_t)offset, whence)); -} - -int -__sclose(cookie) - void *cookie; -{ - - return (_close(((FILE *)cookie)->_file)); -} - -/* - * Higher level wrappers. - */ -int -_sread(fp, buf, n) - FILE *fp; - char *buf; - int n; -{ - int ret; - - ret = (*fp->_read)(fp->_cookie, buf, n); - if (ret > 0) { - if (fp->_flags & __SOFF) { - if (fp->_offset <= OFF_MAX - ret) - fp->_offset += ret; - else - fp->_flags &= ~__SOFF; - } - } else if (ret < 0) - fp->_flags &= ~__SOFF; - return (ret); -} - -int -_swrite(fp, buf, n) - FILE *fp; - char const *buf; - int n; -{ - int ret; - int serrno; - - if (fp->_flags & __SAPP) { - serrno = errno; - if (_sseek(fp, (fpos_t)0, SEEK_END) == -1 && - (fp->_flags & __SOPT)) - return (-1); - errno = serrno; - } - ret = (*fp->_write)(fp->_cookie, buf, n); - /* __SOFF removed even on success in case O_APPEND mode is set. */ - if (ret >= 0) { - if ((fp->_flags & (__SAPP|__SOFF)) == (__SAPP|__SOFF) && - fp->_offset <= OFF_MAX - ret) - fp->_offset += ret; - else - fp->_flags &= ~__SOFF; - - } else if (ret < 0) - fp->_flags &= ~__SOFF; - return (ret); -} - -fpos_t -_sseek(fp, offset, whence) - FILE *fp; - fpos_t offset; - int whence; -{ - fpos_t ret; - int serrno, errret; - - serrno = errno; - errno = 0; - ret = (*fp->_seek)(fp->_cookie, offset, whence); - errret = errno; - if (errno == 0) - errno = serrno; - /* - * Disallow negative seeks per POSIX. - * It is needed here to help upper level caller - * in the cases it can't detect. - */ - if (ret < 0) { - if (errret == 0) { - if (offset != 0 || whence != SEEK_CUR) { - if (HASUB(fp)) - FREEUB(fp); - fp->_p = fp->_bf._base; - fp->_r = 0; - fp->_flags &= ~__SEOF; - } - fp->_flags |= __SERR; - errno = EINVAL; - } else if (errret == ESPIPE) - fp->_flags &= ~__SAPP; - fp->_flags &= ~__SOFF; - ret = -1; - } else if (fp->_flags & __SOPT) { - fp->_flags |= __SOFF; - fp->_offset = ret; - } - return (ret); -} diff --git a/stdio/stdio-fbsd.c b/stdio/stdio-fbsd.c new file mode 120000 index 0000000..5731d59 --- /dev/null +++ b/stdio/stdio-fbsd.c @@ -0,0 +1 @@ +./stdio.c \ No newline at end of file diff --git a/stdio/tmpfile-fbsd.c b/stdio/tmpfile-fbsd.c deleted file mode 100644 index cf5b70a..0000000 --- a/stdio/tmpfile-fbsd.c +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/tmpfile.c,v 1.9 2003/02/06 01:08:19 mtm Exp $"); - -#include "namespace.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "un-namespace.h" - -FILE * -tmpfile() -{ - sigset_t set, oset; - FILE *fp; - int fd, sverrno; -#define TRAILER "tmp.XXXXXX" - char *buf; - const char *tmpdir; - - tmpdir = NULL; - if (issetugid() == 0) - tmpdir = getenv("TMPDIR"); - if (tmpdir == NULL) - tmpdir = _PATH_TMP; - - (void)asprintf(&buf, "%s%s%s", tmpdir, - (tmpdir[strlen(tmpdir) - 1] == '/') ? "" : "/", TRAILER); - if (buf == NULL) - return (NULL); - - sigfillset(&set); - (void)_sigprocmask(SIG_BLOCK, &set, &oset); - - fd = mkstemp(buf); - if (fd != -1) - (void)unlink(buf); - - free(buf); - - (void)_sigprocmask(SIG_SETMASK, &oset, NULL); - - if (fd == -1) - return (NULL); - - if ((fp = fdopen(fd, "w+")) == NULL) { - sverrno = errno; - (void)_close(fd); - errno = sverrno; - return (NULL); - } - return (fp); -} diff --git a/stdio/tmpfile-fbsd.c b/stdio/tmpfile-fbsd.c new file mode 120000 index 0000000..771e10e --- /dev/null +++ b/stdio/tmpfile-fbsd.c @@ -0,0 +1 @@ +./tmpfile.c \ No newline at end of file diff --git a/stdio/tmpnam-fbsd.c b/stdio/tmpnam-fbsd.c deleted file mode 100644 index 38fcdd6..0000000 --- a/stdio/tmpnam-fbsd.c +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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[] = "@(#)tmpnam.c 8.3 (Berkeley) 3/28/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/tmpnam.c,v 1.5 2002/03/22 21:53:04 obrien Exp $"); - -#include - -#include -#include - -__warn_references(tmpnam, - "warning: tmpnam() possibly used unsafely; consider using mkstemp()"); - -extern char *_mktemp(char *); - -char * -tmpnam(s) - char *s; -{ - static u_long tmpcount; - static char buf[L_tmpnam]; - - if (s == NULL) - s = buf; - (void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount); - ++tmpcount; - return (_mktemp(s)); -} diff --git a/stdio/tmpnam-fbsd.c b/stdio/tmpnam-fbsd.c new file mode 120000 index 0000000..d8c0fc5 --- /dev/null +++ b/stdio/tmpnam-fbsd.c @@ -0,0 +1 @@ +./tmpnam.c \ No newline at end of file diff --git a/stdio/ungetc-fbsd.c b/stdio/ungetc-fbsd.c deleted file mode 100644 index 2217259..0000000 --- a/stdio/ungetc-fbsd.c +++ /dev/null @@ -1,172 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/ungetc.c,v 1.16 2004/03/10 12:41:11 tjr Exp $"); - -#include "namespace.h" -#include -#include -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -static int __submore(FILE *); - -/* - * Expand the ungetc buffer `in place'. That is, adjust fp->_p when - * the buffer moves, so that it points the same distance from the end, - * and move the bytes in the buffer around as necessary so that they - * are all at the end (stack-style). - */ -static int -__submore(FILE *fp) -{ - int i; - unsigned char *p; - - if (fp->_ub._base == fp->_ubuf) { - /* - * Get a new buffer (rather than expanding the old one). - */ - if ((p = malloc((size_t)BUFSIZ)) == NULL) - return (EOF); - fp->_ub._base = p; - fp->_ub._size = BUFSIZ; - p += BUFSIZ - sizeof(fp->_ubuf); - for (i = sizeof(fp->_ubuf); --i >= 0;) - p[i] = fp->_ubuf[i]; - fp->_p = p; - return (0); - } - i = fp->_ub._size; - 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 */ - (void)memcpy((void *)(p + i), (void *)p, (size_t)i); - fp->_p = p + i; - fp->_ub._base = p; - fp->_ub._size = i << 1; - return (0); -} - -/* - * MT-safe version - */ -int -ungetc(int c, FILE *fp) -{ - int ret; - - if (!__sdidinit) - __sinit(); - FLOCKFILE(fp); - ORIENT(fp, -1); - ret = __ungetc(c, fp); - FUNLOCKFILE(fp); - return (ret); -} - -/* - * Non-MT-safe version - */ -int -__ungetc(int c, FILE *fp) -{ - - if (c == EOF) - return (EOF); - 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) - return (EOF); - if (fp->_flags & __SWR) { - if (__sflush(fp)) - return (EOF); - fp->_flags &= ~__SWR; - fp->_w = 0; - fp->_lbfsize = 0; - } - fp->_flags |= __SRD; - } - c = (unsigned char)c; - - /* - * If we are in the middle of ungetc'ing, just continue. - * This may require expanding the current ungetc buffer. - */ - if (HASUB(fp)) { - if (fp->_r >= fp->_ub._size && __submore(fp)) - return (EOF); - *--fp->_p = c; - fp->_r++; - return (c); - } - fp->_flags &= ~__SEOF; - - /* - * If we can handle this by simply backing up, do so, - * but never replace the original character. - * (This makes sscanf() work when scanning `const' data.) - */ - if (fp->_bf._base != NULL && fp->_p > fp->_bf._base && - fp->_p[-1] == c) { - fp->_p--; - fp->_r++; - return (c); - } - - /* - * Create an ungetc buffer. - * Initially, we will use the `reserve' buffer. - */ - fp->_ur = fp->_r; - fp->_extra->_up = fp->_p; - fp->_ub._base = fp->_ubuf; - fp->_ub._size = sizeof(fp->_ubuf); - fp->_ubuf[sizeof(fp->_ubuf) - 1] = c; - fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1]; - fp->_r = 1; - return (c); -} diff --git a/stdio/ungetc-fbsd.c b/stdio/ungetc-fbsd.c new file mode 120000 index 0000000..3680701 --- /dev/null +++ b/stdio/ungetc-fbsd.c @@ -0,0 +1 @@ +./ungetc.c \ No newline at end of file diff --git a/stdio/unlocked-fbsd.c b/stdio/unlocked-fbsd.c deleted file mode 100644 index 6b1c0ef..0000000 --- a/stdio/unlocked-fbsd.c +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * Copyright (c) 2003 Tim J. Robbins. - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/unlocked.c,v 1.1 2003/01/10 04:35:08 tjr Exp $"); - -#include - -#undef getchar_unlocked -int -getchar_unlocked(void) -{ - - return (__sgetc(stdin)); -} - -#undef getc_unlocked -int -getc_unlocked(FILE *fp) -{ - - return (__sgetc(fp)); -} - -#undef putchar_unlocked -int -putchar_unlocked(int ch) -{ - - return (__sputc(ch, stdout)); -} - -#undef putc_unlocked -int -putc_unlocked(int ch, FILE *fp) -{ - - return (__sputc(ch, fp)); -} - -#undef feof_unlocked -int -feof_unlocked(FILE *fp) -{ - - return (__sfeof(fp)); -} - -#undef ferror_unlocked -int -ferror_unlocked(FILE *fp) -{ - - return (__sferror(fp)); -} - -#undef clearerr_unlocked -void -clearerr_unlocked(FILE *fp) -{ - - __sclearerr(fp); -} - -#undef fileno_unlocked -int -fileno_unlocked(FILE *fp) -{ - - return (__sfileno(fp)); -} diff --git a/stdio/unlocked-fbsd.c b/stdio/unlocked-fbsd.c new file mode 120000 index 0000000..242fcd9 --- /dev/null +++ b/stdio/unlocked-fbsd.c @@ -0,0 +1 @@ +./unlocked.c \ No newline at end of file diff --git a/stdio/wsetup-fbsd.c b/stdio/wsetup-fbsd.c deleted file mode 100644 index 7b120ff..0000000 --- a/stdio/wsetup-fbsd.c +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdio/wsetup.c,v 1.9 2004/06/08 05:44:52 das Exp $"); - -#include -#include -#include -#include "local.h" - -/* - * Various output routines call wsetup to be sure it is safe to write, - * because either _flags does not include __SWR, or _buf is NULL. - * _wsetup returns 0 if OK to write; otherwise, it returns EOF and sets errno. - */ -int -__swsetup(fp) - FILE *fp; -{ - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - /* - * If we are not writing, we had better be reading and writing. - */ - if ((fp->_flags & __SWR) == 0) { - if ((fp->_flags & __SRW) == 0) { - errno = EBADF; - return (EOF); - } - if (fp->_flags & __SRD) { - /* clobber any ungetc data */ - if (HASUB(fp)) - FREEUB(fp); - fp->_flags &= ~(__SRD|__SEOF); - fp->_r = 0; - fp->_p = fp->_bf._base; - } - fp->_flags |= __SWR; - } - - /* - * Make a buffer if necessary, then set _w. - */ - if (fp->_bf._base == NULL) - __smakebuf(fp); - if (fp->_flags & __SLBF) { - /* - * It is line buffered, so make _lbfsize be -_bufsize - * for the putc() macro. We will change _lbfsize back - * to 0 whenever we turn off __SWR. - */ - fp->_w = 0; - fp->_lbfsize = -fp->_bf._size; - } else - fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size; - return (0); -} diff --git a/stdio/wsetup-fbsd.c b/stdio/wsetup-fbsd.c new file mode 120000 index 0000000..4f613d3 --- /dev/null +++ b/stdio/wsetup-fbsd.c @@ -0,0 +1 @@ +./wsetup.c \ No newline at end of file diff --git a/stdlib/FreeBSD/atexit.c.patch b/stdlib/FreeBSD/atexit.c.patch index 1aa7e42..a671536 100644 --- a/stdlib/FreeBSD/atexit.c.patch +++ b/stdlib/FreeBSD/atexit.c.patch @@ -1,11 +1,11 @@ ---- atexit.c.orig 2006-04-09 01:23:25.000000000 -0700 -+++ atexit.c 2006-04-09 01:44:07.000000000 -0700 +--- atexit.c.orig 2008-02-01 22:43:20.000000000 -0800 ++++ atexit.c 2008-02-01 22:47:49.000000000 -0800 @@ -45,6 +45,9 @@ #include #include #include +#if defined(__DYNAMIC__) -+#include ++#include +#endif /* defined(__DYNAMIC__) */ #include "atexit.h" #include "un-namespace.h" @@ -26,19 +26,28 @@ _MUTEX_UNLOCK(&atexit_mutex); return 0; } -@@ -125,7 +130,11 @@ +@@ -120,12 +125,20 @@ + atexit(void (*func)(void)) + { + struct atexit_fn fn; ++ struct dl_info info; + int error; + fn.fn_type = ATEXIT_FN_STD; fn.fn_ptr.std_func = func;; fn.fn_arg = NULL; +#if defined(__DYNAMIC__) -+ fn.fn_dso = (void *)_dyld_get_image_header_containing_address((unsigned long) func); ++ if ( dladdr(func, &info) ) ++ fn.fn_dso = info.dli_fbase; ++ else ++ fn.fn_dso = NULL; +#else /* ! defined(__DYNAMIC__) */ fn.fn_dso = NULL; +#endif /* defined(__DYNAMIC__) */ error = atexit_register(&fn); return (error); -@@ -156,13 +165,14 @@ +@@ -156,13 +169,14 @@ * handlers are called. */ void @@ -54,7 +63,7 @@ for (p = __atexit; p; p = p->next) { for (n = p->ind; --n >= 0;) { if (p->fns[n].fn_type == ATEXIT_FN_EMPTY) -@@ -175,6 +185,7 @@ +@@ -175,6 +189,7 @@ has already been called. */ p->fns[n].fn_type = ATEXIT_FN_EMPTY; @@ -62,7 +71,7 @@ _MUTEX_UNLOCK(&atexit_mutex); /* Call the function of correct type. */ -@@ -183,6 +194,8 @@ +@@ -183,6 +198,8 @@ else if (fn.fn_type == ATEXIT_FN_STD) fn.fn_ptr.std_func(); _MUTEX_LOCK(&atexit_mutex); diff --git a/stdlib/Makefile.inc b/stdlib/Makefile.inc index 530bfdc..acb2899 100644 --- a/stdlib/Makefile.inc +++ b/stdlib/Makefile.inc @@ -1,15 +1,12 @@ # from @(#)Makefile.inc 8.3 (Berkeley) 2/4/95 # $FreeBSD: src/lib/libc/stdlib/Makefile.inc,v 1.45 2003/04/05 07:33:46 tjr Exp $ -.ifnmake autopatch # machine-dependent stdlib sources -.if exists(${.CURDIR}/${MACHINE_ARCH}/stdlib/Makefile.inc) -.include "${.CURDIR}/${MACHINE_ARCH}/stdlib/Makefile.inc" -.endif -.endif # !autopatch +.sinclude "${.CURDIR}/${MACHINE_ARCH}/stdlib/Makefile.inc" # machine-independent stdlib sources .PATH: ${.CURDIR}/stdlib +CWD := ${.CURDIR}/stdlib MISRCS+=a64l.c grantpt.c l64a.c @@ -19,12 +16,16 @@ FBSDMISRCS=_Exit_.c abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \ hcreate.c heapsort.c imaxabs.c imaxdiv.c insque.c labs.c \ ldiv.c llabs.c lldiv.c lsearch.c merge.c putenv.c qsort.c qsort_r.c \ radixsort.c rand.c random.c reallocf.c realpath.c remque.c setenv.c \ - strfmon.c strhash.c strtoimax.c strtol.c strtoll.c strtoq.c strtoul.c \ + strhash.c strtoimax.c strtol.c strtoll.c strtoq.c strtoul.c \ strtoull.c strtoumax.c strtouq.c system.c tdelete.c tfind.c tsearch.c \ twalk.c FBSDHDRS= atexit.h .include "Makefile.fbsd_end" +.include "Makefile.nbsd_begin" +NBSDMISRCS = strfmon.c +.include "Makefile.nbsd_end" + # 4302056: compile qsort.c and bsearch.c with -fexceptions .for _src in qsort-fbsd.c bsearch-fbsd.c CFLAGS-${_src} += -fexceptions @@ -57,9 +58,13 @@ FBSDMAN3= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ div.3 exit.3 getenv.3 getopt.3 getopt_long.3 getsubopt.3 \ hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 llabs.3 lldiv.3 \ lsearch.3 memory.3 qsort.3 radixsort.3 rand.3 random.3 realpath.3 \ - strfmon.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3 + strtod.3 strtol.3 strtoul.3 system.3 tsearch.3 .include "Makefile.fbsd_end" +.include "Makefile.nbsd_begin" +NBSDMAN3= strfmon.3 +.include "Makefile.nbsd_end" + .include "Makefile.obsd_begin" OBSDMAN3= ecvt.3 .include "Makefile.obsd_end" diff --git a/stdlib/FreeBSD/strfmon.3 b/stdlib/NetBSD/strfmon.3 similarity index 95% rename from stdlib/FreeBSD/strfmon.3 rename to stdlib/NetBSD/strfmon.3 index 739a798..7d7fe40 100644 --- a/stdlib/FreeBSD/strfmon.3 +++ b/stdlib/NetBSD/strfmon.3 @@ -1,3 +1,5 @@ +.\" $NetBSD: strfmon.3,v 1.3 2005/04/04 08:19:00 wiz Exp $ +.\" .\" Copyright (c) 2001 Jeroen Ruigrok van der Werven .\" All rights reserved. .\" @@ -22,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libc/stdlib/strfmon.3,v 1.7 2003/01/06 06:21:25 tjr Exp $ +.\" From: FreeBSD: Id: strfmon.3,v 1.7 2003/01/06 06:21:25 tjr Exp .\" .Dd October 12, 2002 .Dt STRFMON 3 @@ -95,7 +97,7 @@ expected number of digits after the radix character. A .Sq Cm \&. character followed by a decimal number specifying the number -the number of digits after the radix character. +of digits after the radix character. .It One of the following conversion specifiers: .Bl -tag -width "XXX" @@ -158,7 +160,7 @@ function was implemented by .Pp This manual page was written by .An Jeroen Ruigrok van der Werven Aq asmodai@FreeBSD.org -based on the standards' text. +based on the standard's text. .Sh BUGS The .Fn strfmon diff --git a/stdlib/FreeBSD/strfmon.3.patch b/stdlib/NetBSD/strfmon.3.patch similarity index 86% rename from stdlib/FreeBSD/strfmon.3.patch rename to stdlib/NetBSD/strfmon.3.patch index 8dbaa10..6bba2fa 100644 --- a/stdlib/FreeBSD/strfmon.3.patch +++ b/stdlib/NetBSD/strfmon.3.patch @@ -1,6 +1,6 @@ ---- _SB/Libc/stdlib/FreeBSD/strfmon.3 2003-05-20 15:23:25.000000000 -0700 -+++ _SB/Libc/stdlib/FreeBSD/strfmon.3.edit 2006-06-28 16:55:53.000000000 -0700 -@@ -28,25 +28,49 @@ +--- strfmon.3.orig 2008-04-05 20:02:08.000000000 -0700 ++++ strfmon.3 2008-04-05 20:05:49.000000000 -0700 +@@ -30,25 +30,49 @@ .Dt STRFMON 3 .Os .Sh NAME @@ -8,8 +8,10 @@ +.Nm strfmon , +.Nm strfmon_l .Nd convert monetary value to string - .Sh LIBRARY - .Lb libc +-.Sh LIBRARY +-.Lb libc ++.\" .Sh LIBRARY ++.\" .Lb libc .Sh SYNOPSIS .In monetary.h .Ft ssize_t @@ -53,7 +55,7 @@ The format string is composed of zero or more directives: ordinary characters (not .Cm % ) , -@@ -114,9 +138,9 @@ +@@ -116,9 +140,9 @@ .El .El .Sh RETURN VALUES @@ -65,7 +67,7 @@ .Fa maxsize , .Fn strfmon returns the number of bytes placed into the array pointed to by -@@ -142,7 +166,8 @@ +@@ -144,7 +168,8 @@ Not enough memory for temporary buffers. .El .Sh SEE ALSO diff --git a/stdlib/FreeBSD/strfmon.c b/stdlib/NetBSD/strfmon.c similarity index 93% rename from stdlib/FreeBSD/strfmon.c rename to stdlib/NetBSD/strfmon.c index db569d5..98f0aad 100644 --- a/stdlib/FreeBSD/strfmon.c +++ b/stdlib/NetBSD/strfmon.c @@ -1,3 +1,5 @@ +/* $NetBSD: strfmon.c,v 1.6 2008/03/27 21:50:30 christos Exp $ */ + /*- * Copyright (c) 2001 Alexey Zelkin * All rights reserved. @@ -26,7 +28,18 @@ */ #include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); +#else +__RCSID("$NetBSD: strfmon.c,v 1.6 2008/03/27 21:50:30 christos Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#if defined(__NetBSD__) +#include "namespace.h" +#include +#endif #include #include @@ -37,6 +50,7 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ach #include #include #include +#include /* internal flags */ #define NEED_GROUPING 0x01 /* print digits grouped (default) */ @@ -53,22 +67,24 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ach if (dst >= s + maxsize) \ goto e2big_error; \ *dst++ = CH; \ -} while (0) +} while (/* CONSTCOND */ 0) #define PRINTS(STR) do { \ - char *tmps = STR; \ + const char *tmps = STR; \ while (*tmps != '\0') \ PRINT(*tmps++); \ -} while (0) +} while (/* CONSTCOND */ 0) #define GET_NUMBER(VAR) do { \ VAR = 0; \ while (isdigit((unsigned char)*fmt)) { \ VAR *= 10; \ VAR += *fmt - '0'; \ + if (VAR > 0x00ffffff) \ + goto e2big_error; \ fmt++; \ } \ -} while (0) +} while (/* CONSTCOND */ 0) #define GRPCPY(howmany) do { \ int i = howmany; \ @@ -76,14 +92,14 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ach avalue_size--; \ *--bufend = *(avalue+avalue_size+padded); \ } \ -} while (0) +} while (/* CONSTCOND */ 0) #define GRPSEP do { \ *--bufend = thousands_sep; \ groups++; \ -} while (0) +} while (/* CONSTCOND */ 0) -static void __setup_vars(int, char *, char *, char *, char **); +static void __setup_vars(int, char *, char *, char *, const char **); static int __calc_left_pad(int, char *); static char *__format_grouped_double(double, int *, int, int, int); @@ -109,8 +125,8 @@ strfmon(char * __restrict s, size_t maxsize, const char * __restrict format, char cs_precedes, /* values gathered from struct lconv */ sep_by_space, sign_posn, - *signstr, *currency_symbol; + const char *signstr; char *tmpptr; /* temporary vars */ int sverrno; @@ -148,7 +164,7 @@ strfmon(char * __restrict s, size_t maxsize, const char * __restrict format, value = 0; /* we have no value to print now */ /* Flags */ - while (1) { + while (/* CONSTCOND */ 1) { switch (*++fmt) { case '=': /* fill character */ pad_char = *++fmt; @@ -182,11 +198,13 @@ strfmon(char * __restrict s, size_t maxsize, const char * __restrict format, /* field Width */ if (isdigit((unsigned char)*fmt)) { + ptrdiff_t d = dst - s; GET_NUMBER(width); /* Do we have enough space to put number with * required width ? */ - if (dst + width >= s + maxsize) + + if (d + width >= maxsize) goto e2big_error; } @@ -217,6 +235,8 @@ strfmon(char * __restrict s, size_t maxsize, const char * __restrict format, goto format_error; } + if (currency_symbol) + free(currency_symbol); if (flags & USE_INTL_CURRENCY) { currency_symbol = strdup(lc->int_curr_symbol); if (currency_symbol != NULL) @@ -358,8 +378,8 @@ strfmon(char * __restrict s, size_t maxsize, const char * __restrict format, } else { pad_size = dst-tmpptr; memmove(tmpptr + width-pad_size, tmpptr, - pad_size); - memset(tmpptr, ' ', width-pad_size); + (size_t) pad_size); + memset(tmpptr, ' ', (size_t) width-pad_size); dst += width-pad_size; } } @@ -391,8 +411,7 @@ end_error: static void __setup_vars(int flags, char *cs_precedes, char *sep_by_space, - char *sign_posn, char **signstr) { - + char *sign_posn, const char **signstr) { struct lconv *lc = localeconv(); if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) { @@ -431,7 +450,8 @@ __setup_vars(int flags, char *cs_precedes, char *sep_by_space, static int __calc_left_pad(int flags, char *cur_symb) { - char cs_precedes, sep_by_space, sign_posn, *signstr; + char cs_precedes, sep_by_space, sign_posn; + const char *signstr; int left_chars = 0; __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr); @@ -552,7 +572,7 @@ __format_grouped_double(double value, int *flags, if (right_prec > 0) { bufend -= right_prec; memcpy(bufend, avalue + avalue_size+padded-right_prec, - right_prec); + (size_t) right_prec); *--bufend = decimal_point; avalue_size -= (right_prec + 1); } @@ -585,7 +605,7 @@ __format_grouped_double(double value, int *flags, } else { bufend -= avalue_size; - memcpy(bufend, avalue+padded, avalue_size); + memcpy(bufend, avalue+padded, (size_t) avalue_size); if (right_prec == 0) padded--; /* decrease assumed $decimal_point */ } @@ -593,7 +613,7 @@ __format_grouped_double(double value, int *flags, /* do padding with pad_char */ if (padded > 0) { bufend -= padded; - memset(bufend, pad_char, padded); + memset(bufend, pad_char, (size_t) padded); } bufsize = bufsize - (bufend - rslt) + 1; diff --git a/stdlib/FreeBSD/strfmon.c.patch b/stdlib/NetBSD/strfmon.c.patch similarity index 77% rename from stdlib/FreeBSD/strfmon.c.patch rename to stdlib/NetBSD/strfmon.c.patch index 9ff3b5d..7e73ea7 100644 --- a/stdlib/FreeBSD/strfmon.c.patch +++ b/stdlib/NetBSD/strfmon.c.patch @@ -1,17 +1,17 @@ ---- strfmon.c.orig 2003-05-20 15:23:25.000000000 -0700 -+++ strfmon.c 2005-04-27 23:34:08.000000000 -0700 -@@ -28,6 +28,8 @@ - #include - __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); +--- strfmon.c.orig 2008-04-04 21:54:54.000000000 -0700 ++++ strfmon.c 2008-04-04 22:11:39.000000000 -0700 +@@ -41,6 +41,8 @@ __RCSID("$NetBSD: strfmon.c,v 1.6 2008/0 + #include + #endif +#include "xlocale_private.h" + #include #include #include -@@ -61,9 +63,9 @@ +@@ -75,9 +77,9 @@ __RCSID("$NetBSD: strfmon.c,v 1.6 2008/0 PRINT(*tmps++); \ - } while (0) + } while (/* CONSTCOND */ 0) -#define GET_NUMBER(VAR) do { \ +#define GET_NUMBER(VAR,LOC) do { \ @@ -20,31 +20,29 @@ + while (isdigit_l((unsigned char)*fmt, (LOC))) { \ VAR *= 10; \ VAR += *fmt - '0'; \ - fmt++; \ -@@ -83,15 +85,14 @@ + if (VAR > 0x00ffffff) \ +@@ -99,15 +101,13 @@ __RCSID("$NetBSD: strfmon.c,v 1.6 2008/0 groups++; \ - } while (0) + } while (/* CONSTCOND */ 0) --static void __setup_vars(int, char *, char *, char *, char **); +-static void __setup_vars(int, char *, char *, char *, const char **); -static int __calc_left_pad(int, char *); -static char *__format_grouped_double(double, int *, int, int, int); -- ++static void __setup_vars(int, char *, char *, char *, const char **, struct lconv *); ++static int __calc_left_pad(int, char *, struct lconv *); ++static char *__format_grouped_double(double, int *, int, int, int, struct lconv *, locale_t); + -ssize_t -strfmon(char * __restrict s, size_t maxsize, const char * __restrict format, - ...) -+static void __setup_vars(int, char *, char *, char *, char **, struct lconv *); -+static int __calc_left_pad(int, char *, struct lconv *); -+static char *__format_grouped_double(double, int *, int, int, int, struct lconv *, locale_t); -+ +static ssize_t -+_strfmon(char * __restrict s, size_t maxsize, locale_t loc, -+ const char * __restrict format, va_list ap) ++_strfmon(char * __restrict s, size_t maxsize, locale_t loc, const char * __restrict format, va_list ap) { - va_list ap; char *dst; /* output destination pointer */ const char *fmt; /* current format poistion pointer */ struct lconv *lc; /* pointer to lconv structure */ -@@ -115,9 +116,7 @@ +@@ -131,9 +131,7 @@ strfmon(char * __restrict s, size_t maxs char *tmpptr; /* temporary vars */ int sverrno; @@ -55,18 +53,19 @@ dst = s; fmt = format; asciivalue = NULL; -@@ -181,8 +180,8 @@ +@@ -197,9 +195,9 @@ strfmon(char * __restrict s, size_t maxs } /* field Width */ - if (isdigit((unsigned char)*fmt)) { -- GET_NUMBER(width); + if (isdigit_l((unsigned char)*fmt, loc)) { + ptrdiff_t d = dst - s; +- GET_NUMBER(width); + GET_NUMBER(width, loc); /* Do we have enough space to put number with * required width ? */ -@@ -192,16 +191,16 @@ +@@ -210,16 +208,16 @@ strfmon(char * __restrict s, size_t maxs /* Left precision */ if (*fmt == '#') { @@ -87,8 +86,8 @@ } /* Conversion Characters */ -@@ -219,8 +218,10 @@ - +@@ -239,8 +237,10 @@ strfmon(char * __restrict s, size_t maxs + free(currency_symbol); if (flags & USE_INTL_CURRENCY) { currency_symbol = strdup(lc->int_curr_symbol); - if (currency_symbol != NULL) @@ -99,7 +98,7 @@ } else currency_symbol = strdup(lc->currency_symbol); -@@ -239,21 +240,21 @@ +@@ -259,21 +259,21 @@ strfmon(char * __restrict s, size_t maxs /* fill left_prec with amount of padding chars */ if (left_prec >= 0) { pad_size = __calc_left_pad((flags ^ IS_NEGATIVE), @@ -125,7 +124,7 @@ /* * Description of some LC_MONETARY's values: -@@ -313,8 +314,11 @@ +@@ -333,8 +333,11 @@ strfmon(char * __restrict s, size_t maxs } else if (sep_by_space == 1) PRINT(space_char); } @@ -138,7 +137,7 @@ PRINTS(asciivalue); -@@ -348,8 +352,12 @@ +@@ -368,8 +371,12 @@ strfmon(char * __restrict s, size_t maxs PRINTS(signstr); } @@ -153,7 +152,7 @@ if (dst - tmpptr < width) { if (flags & LEFT_JUSTIFY) { -@@ -366,7 +374,6 @@ +@@ -386,7 +393,6 @@ strfmon(char * __restrict s, size_t maxs } PRINT('\0'); @@ -161,7 +160,7 @@ free(asciivalue); free(currency_symbol); return (dst - s - 1); /* return size of put data except trailing '\0' */ -@@ -385,15 +392,12 @@ +@@ -405,14 +411,12 @@ end_error: if (currency_symbol != NULL) free(currency_symbol); errno = sverrno; @@ -171,21 +170,21 @@ static void __setup_vars(int flags, char *cs_precedes, char *sep_by_space, -- char *sign_posn, char **signstr) { -- +- char *sign_posn, const char **signstr) { - struct lconv *lc = localeconv(); -+ char *sign_posn, char **signstr, struct lconv *lc) { ++ char *sign_posn, const char **signstr, struct lconv *lc) { if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) { *cs_precedes = lc->int_n_cs_precedes; -@@ -429,12 +433,12 @@ +@@ -448,13 +452,13 @@ __setup_vars(int flags, char *cs_precede } static int -__calc_left_pad(int flags, char *cur_symb) { +__calc_left_pad(int flags, char *cur_symb, struct lconv *lc) { - char cs_precedes, sep_by_space, sign_posn, *signstr; + char cs_precedes, sep_by_space, sign_posn; + const char *signstr; int left_chars = 0; - __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr); @@ -193,7 +192,7 @@ if (cs_precedes != 0) { left_chars += strlen(cur_symb); -@@ -443,6 +447,10 @@ +@@ -463,6 +467,10 @@ __calc_left_pad(int flags, char *cur_sym } switch (sign_posn) { @@ -204,7 +203,7 @@ case 1: left_chars += strlen(signstr); break; -@@ -478,9 +486,11 @@ +@@ -498,9 +506,11 @@ get_groups(int size, char *grouping) { } /* convert double to ASCII */ @@ -217,7 +216,7 @@ char *rslt; char *avalue; -@@ -492,14 +502,13 @@ +@@ -512,14 +522,13 @@ __format_grouped_double(double value, in int padded; @@ -233,7 +232,7 @@ decimal_point = *lc->mon_decimal_point; if (decimal_point == '\0') decimal_point = *lc->decimal_point; -@@ -526,9 +535,9 @@ +@@ -546,9 +555,9 @@ __format_grouped_double(double value, in left_prec += get_groups(left_prec, grouping); /* convert to string */ @@ -245,7 +244,7 @@ if (avalue_size < 0) return (NULL); -@@ -601,3 +610,30 @@ +@@ -621,3 +630,30 @@ __format_grouped_double(double value, in free(avalue); return (rslt); } diff --git a/stdlib/_Exit_-fbsd.c b/stdlib/_Exit_-fbsd.c deleted file mode 100644 index 3a2e94e..0000000 --- a/stdlib/_Exit_-fbsd.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This file is in the public domain. Written by Garrett A. Wollman, - * 2002-09-07. - * - * $FreeBSD: src/lib/libc/stdlib/_Exit.c,v 1.1 2002/09/10 02:04:49 wollman Exp $ - */ - -#include -#include - -/* - * ISO C99 added this function to provide for Standard C applications - * which needed something like POSIX _exit(). A new interface was created - * in case it turned out that _exit() was insufficient to meet the - * requirements of ISO C. (That's probably not the case, but here - * is where you would put the extra code if it were.) - */ -void -_Exit(int code) -{ - _exit(code); -} diff --git a/stdlib/_Exit_-fbsd.c b/stdlib/_Exit_-fbsd.c new file mode 120000 index 0000000..b2b392f --- /dev/null +++ b/stdlib/_Exit_-fbsd.c @@ -0,0 +1 @@ +./_Exit_.c \ No newline at end of file diff --git a/stdlib/abs-fbsd.c b/stdlib/abs-fbsd.c deleted file mode 100644 index 26f87eb..0000000 --- a/stdlib/abs-fbsd.c +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)abs.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/abs.c,v 1.2 2002/03/22 21:53:09 obrien Exp $"); - -#include - -int -abs(j) - int j; -{ - return(j < 0 ? -j : j); -} diff --git a/stdlib/abs-fbsd.c b/stdlib/abs-fbsd.c new file mode 120000 index 0000000..9ff17c5 --- /dev/null +++ b/stdlib/abs-fbsd.c @@ -0,0 +1 @@ +./abs.c \ No newline at end of file diff --git a/stdlib/atexit-fbsd.c b/stdlib/atexit-fbsd.c index d8edf72..3207f7f 100644 --- a/stdlib/atexit-fbsd.c +++ b/stdlib/atexit-fbsd.c @@ -46,7 +46,7 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/atexit.c,v 1.7 2003/12/19 17:11:20 kan E #include #include #if defined(__DYNAMIC__) -#include +#include #endif /* defined(__DYNAMIC__) */ #include "atexit.h" #include "un-namespace.h" @@ -125,13 +125,17 @@ int atexit(void (*func)(void)) { struct atexit_fn fn; + struct dl_info info; int error; fn.fn_type = ATEXIT_FN_STD; fn.fn_ptr.std_func = func;; fn.fn_arg = NULL; #if defined(__DYNAMIC__) - fn.fn_dso = (void *)_dyld_get_image_header_containing_address((unsigned long) func); + if ( dladdr(func, &info) ) + fn.fn_dso = info.dli_fbase; + else + fn.fn_dso = NULL; #else /* ! defined(__DYNAMIC__) */ fn.fn_dso = NULL; #endif /* defined(__DYNAMIC__) */ diff --git a/stdlib/bsearch-fbsd.c b/stdlib/bsearch-fbsd.c deleted file mode 100644 index 7717582..0000000 --- a/stdlib/bsearch-fbsd.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bsearch.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/bsearch.c,v 1.3 2002/03/21 22:48:41 obrien Exp $"); - -#include -#include - -/* - * Perform a binary search. - * - * The code below is a bit sneaky. After a comparison fails, we - * divide the work in half by moving either left or right. If lim - * is odd, moving left simply involves halving lim: e.g., when lim - * is 5 we look at item 2, so we change lim to 2 so that we will - * look at items 0 & 1. If lim is even, the same applies. If lim - * is odd, moving right again involes halving lim, this time moving - * the base up one item past p: e.g., when lim is 5 we change base - * to item 3 and make lim 2 so that we will look at items 3 and 4. - * If lim is even, however, we have to shrink it by one before - * halving: e.g., when lim is 4, we still looked at item 2, so we - * have to make lim 3, then halve, obtaining 1, so that we will only - * look at item 3. - */ -void * -bsearch(key, base0, nmemb, size, compar) - const void *key; - const void *base0; - size_t nmemb; - size_t size; - int (*compar)(const void *, const void *); -{ - const char *base = base0; - size_t lim; - int cmp; - const void *p; - - for (lim = nmemb; lim != 0; lim >>= 1) { - p = base + (lim >> 1) * size; - cmp = (*compar)(key, p); - if (cmp == 0) - return ((void *)p); - if (cmp > 0) { /* key > p: move right */ - base = (char *)p + size; - lim--; - } /* else move left */ - } - return (NULL); -} diff --git a/stdlib/bsearch-fbsd.c b/stdlib/bsearch-fbsd.c new file mode 120000 index 0000000..f7ab5d5 --- /dev/null +++ b/stdlib/bsearch-fbsd.c @@ -0,0 +1 @@ +./bsearch.c \ No newline at end of file diff --git a/stdlib/div-fbsd.c b/stdlib/div-fbsd.c deleted file mode 100644 index 54278d6..0000000 --- a/stdlib/div-fbsd.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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. - * - * 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[] = "@(#)div.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/div.c,v 1.2 2002/03/22 21:53:10 obrien Exp $"); - -#include /* div_t */ - -div_t -div(num, denom) - int num, denom; -{ - div_t r; - - r.quot = num / denom; - r.rem = num % denom; - /* - * The ANSI standard says that |r.quot| <= |n/d|, where - * n/d is to be computed in infinite precision. In other - * words, we should always truncate the quotient towards - * 0, never -infinity. - * - * Machine division and remainer may work either way when - * one or both of n or d is negative. If only one is - * negative and r.quot has been truncated towards -inf, - * r.rem will have the same sign as denom and the opposite - * sign of num; if both are negative and r.quot has been - * truncated towards -inf, r.rem will be positive (will - * have the opposite sign of num). These are considered - * `wrong'. - * - * If both are num and denom are positive, r will always - * be positive. - * - * This all boils down to: - * if num >= 0, but r.rem < 0, we got the wrong answer. - * In that case, to get the right answer, add 1 to r.quot and - * subtract denom from r.rem. - */ - if (num >= 0 && r.rem < 0) { - r.quot++; - r.rem -= denom; - } - return (r); -} diff --git a/stdlib/div-fbsd.c b/stdlib/div-fbsd.c new file mode 120000 index 0000000..9fce9b8 --- /dev/null +++ b/stdlib/div-fbsd.c @@ -0,0 +1 @@ +./div.c \ No newline at end of file diff --git a/stdlib/getopt_long-fbsd.c b/stdlib/getopt_long-fbsd.c deleted file mode 100644 index ef306bc..0000000 --- a/stdlib/getopt_long-fbsd.c +++ /dev/null @@ -1,642 +0,0 @@ -/* $OpenBSD: getopt_long.c,v 1.17 2004/06/03 18:46:52 millert Exp $ */ -/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ - -/* - * Copyright (c) 2002 Todd C. Miller - * - * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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. - * - * Sponsored in part by the Defense Advanced Research Projects - * Agency (DARPA) and Air Force Research Laboratory, Air Force - * Materiel Command, USAF, under agreement number F39502-99-1-0512. - */ -/*- - * Copyright (c) 2000 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Dieter Baron and Thomas Klausner. - * - * 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 FOUNDATION 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 0 -#if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: getopt_long.c,v 1.16 2004/02/04 18:17:25 millert Exp $"; -#endif /* LIBC_SCCS and not lint */ -#endif -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/getopt_long.c,v 1.12 2004/07/06 13:58:45 ache Exp $"); - -#include -#include -#include -#include -#include - -#define GNU_COMPATIBLE /* Be more compatible, configure's use us! */ - -#ifndef GNU_COMPATIBLE -#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */ -#endif - -#ifdef REPLACE_GETOPT -int opterr = 1; /* if error message should be printed */ -int optind = 1; /* index into parent argv vector */ -int optopt = '?'; /* character checked for validity */ -int optreset; /* reset getopt */ -char *optarg; /* argument associated with option */ -#endif - -#define PRINT_ERROR ((opterr) && (*options != ':')) - -#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */ -#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */ -#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */ - -/* return values */ -#define BADCH (int)'?' -#define BADARG ((*options == ':') ? (int)':' : (int)'?') -#define INORDER (int)1 - -#define EMSG "" - -#ifdef GNU_COMPATIBLE -#define NO_PREFIX (-1) -#define D_PREFIX 0 -#define DD_PREFIX 1 -#define W_PREFIX 2 -#endif - -static int getopt_internal(int, char * const *, const char *, - const struct option *, int *, int); -static int parse_long_options(char * const *, const char *, - const struct option *, int *, int, int); -static int gcd(int, int); -static void permute_args(int, int, int, char * const *); - -static char *place = EMSG; /* option letter processing */ - -/* XXX: set optreset to 1 rather than these two */ -static int nonopt_start = -1; /* first non option argument (for permute) */ -static int nonopt_end = -1; /* first option after non options (for permute) */ - -/* Error messages */ -static const char recargchar[] = "option requires an argument -- %c"; -static const char illoptchar[] = "illegal option -- %c"; /* From P1003.2 */ -#ifdef GNU_COMPATIBLE -static int dash_prefix = NO_PREFIX; -static const char gnuoptchar[] = "invalid option -- %c"; - -static const char recargstring[] = "option `%s%s' requires an argument"; -static const char ambig[] = "option `%s%.*s' is ambiguous"; -static const char noarg[] = "option `%s%.*s' doesn't allow an argument"; -static const char illoptstring[] = "unrecognized option `%s%s'"; -#else -static const char recargstring[] = "option requires an argument -- %s"; -static const char ambig[] = "ambiguous option -- %.*s"; -static const char noarg[] = "option doesn't take an argument -- %.*s"; -static const char illoptstring[] = "unknown option -- %s"; -#endif - -/* - * Compute the greatest common divisor of a and b. - */ -static int -gcd(int a, int b) -{ - int c; - - c = a % b; - while (c != 0) { - a = b; - b = c; - c = a % b; - } - - return (b); -} - -/* - * Exchange the block from nonopt_start to nonopt_end with the block - * from nonopt_end to opt_end (keeping the same order of arguments - * in each block). - */ -static void -permute_args(int panonopt_start, int panonopt_end, int opt_end, - char * const *nargv) -{ - int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; - char *swap; - - /* - * compute lengths of blocks and number and size of cycles - */ - nnonopts = panonopt_end - panonopt_start; - nopts = opt_end - panonopt_end; - ncycle = gcd(nnonopts, nopts); - cyclelen = (opt_end - panonopt_start) / ncycle; - - for (i = 0; i < ncycle; i++) { - cstart = panonopt_end+i; - pos = cstart; - for (j = 0; j < cyclelen; j++) { - if (pos >= panonopt_end) - pos -= nnonopts; - else - pos += nopts; - swap = nargv[pos]; - /* LINTED const cast */ - ((char **) nargv)[pos] = nargv[cstart]; - /* LINTED const cast */ - ((char **)nargv)[cstart] = swap; - } - } -} - -/* - * parse_long_options -- - * Parse long options in argc/argv argument vector. - * Returns -1 if short_too is set and the option does not match long_options. - */ -static int -parse_long_options(char * const *nargv, const char *options, - const struct option *long_options, int *idx, int short_too, int flags) -{ - char *current_argv, *has_equal; -#ifdef GNU_COMPATIBLE - char *current_dash; -#endif - size_t current_argv_len; - int i, match, exact_match, second_partial_match; - - current_argv = place; -#ifdef GNU_COMPATIBLE - switch (dash_prefix) { - case D_PREFIX: - current_dash = "-"; - break; - case DD_PREFIX: - current_dash = "--"; - break; - case W_PREFIX: - current_dash = "-W "; - break; - default: - current_dash = ""; - break; - } -#endif - match = -1; - exact_match = 0; - second_partial_match = 0; - - optind++; - - if ((has_equal = strchr(current_argv, '=')) != NULL) { - /* argument found (--option=arg) */ - current_argv_len = has_equal - current_argv; - has_equal++; - } else - current_argv_len = strlen(current_argv); - - for (i = 0; long_options[i].name; i++) { - /* find matching long option */ - if (strncmp(current_argv, long_options[i].name, - current_argv_len)) - continue; - - if (strlen(long_options[i].name) == current_argv_len) { - /* exact match */ - match = i; - exact_match = 1; - break; - } - /* - * If this is a known short option, don't allow - * a partial match of a single character. - */ - if (short_too && current_argv_len == 1) - continue; - - if (match == -1) /* first partial match */ - match = i; - else if ((flags & FLAG_LONGONLY) || - long_options[i].has_arg != - long_options[match].has_arg || - long_options[i].flag != long_options[match].flag || - long_options[i].val != long_options[match].val) - second_partial_match = 1; - } - if (!exact_match && second_partial_match) { - /* ambiguous abbreviation */ - if (PRINT_ERROR) - warnx(ambig, -#ifdef GNU_COMPATIBLE - current_dash, -#endif - (int)current_argv_len, - current_argv); - optopt = 0; - return (BADCH); - } - if (match != -1) { /* option found */ - if (long_options[match].has_arg == no_argument - && has_equal) { - if (PRINT_ERROR) - warnx(noarg, -#ifdef GNU_COMPATIBLE - current_dash, -#endif - (int)current_argv_len, - current_argv); - /* - * XXX: GNU sets optopt to val regardless of flag - */ - if (long_options[match].flag == NULL) - optopt = long_options[match].val; - else - optopt = 0; -#ifdef GNU_COMPATIBLE - return (BADCH); -#else - return (BADARG); -#endif - } - if (long_options[match].has_arg == required_argument || - long_options[match].has_arg == optional_argument) { - if (has_equal) - optarg = has_equal; - else if (long_options[match].has_arg == - required_argument) { - /* - * optional argument doesn't use next nargv - */ - optarg = nargv[optind++]; - } - } - if ((long_options[match].has_arg == required_argument) - && (optarg == NULL)) { - /* - * Missing argument; leading ':' indicates no error - * should be generated. - */ - if (PRINT_ERROR) - warnx(recargstring, -#ifdef GNU_COMPATIBLE - current_dash, -#endif - current_argv); - /* - * XXX: GNU sets optopt to val regardless of flag - */ - if (long_options[match].flag == NULL) - optopt = long_options[match].val; - else - optopt = 0; - --optind; - return (BADARG); - } - } else { /* unknown option */ - if (short_too) { - --optind; - return (-1); - } - if (PRINT_ERROR) - warnx(illoptstring, -#ifdef GNU_COMPATIBLE - current_dash, -#endif - current_argv); - optopt = 0; - return (BADCH); - } - if (idx) - *idx = match; - if (long_options[match].flag) { - *long_options[match].flag = long_options[match].val; - return (0); - } else - return (long_options[match].val); -} - -/* - * getopt_internal -- - * Parse argc/argv argument vector. Called by user level routines. - */ -static int -getopt_internal(int nargc, char * const *nargv, const char *options, - const struct option *long_options, int *idx, int flags) -{ - char *oli; /* option letter list index */ - int optchar, short_too; - int posixly_correct; - - if (options == NULL) - return (-1); - - /* - * Disable GNU extensions if POSIXLY_CORRECT is set or options - * string begins with a '+'. - */ - posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); -#ifdef GNU_COMPATIBLE - if (*options == '-') - flags |= FLAG_ALLARGS; - else if (posixly_correct || *options == '+') - flags &= ~FLAG_PERMUTE; -#else - if (posixly_correct || *options == '+') - flags &= ~FLAG_PERMUTE; - else if (*options == '-') - flags |= FLAG_ALLARGS; -#endif - if (*options == '+' || *options == '-') - options++; - - /* - * XXX Some GNU programs (like cvs) set optind to 0 instead of - * XXX using optreset. Work around this braindamage. - */ - if (optind == 0) - optind = optreset = 1; - - optarg = NULL; - if (optreset) - nonopt_start = nonopt_end = -1; -start: - if (optreset || !*place) { /* update scanning pointer */ - optreset = 0; - if (optind >= nargc) { /* end of argument vector */ - place = EMSG; - if (nonopt_end != -1) { - /* do permutation, if we have to */ - permute_args(nonopt_start, nonopt_end, - optind, nargv); - optind -= nonopt_end - nonopt_start; - } - else if (nonopt_start != -1) { - /* - * If we skipped non-options, set optind - * to the first of them. - */ - optind = nonopt_start; - } - nonopt_start = nonopt_end = -1; - return (-1); - } - if (*(place = nargv[optind]) != '-' || -#ifdef GNU_COMPATIBLE - place[1] == '\0') { -#else - (place[1] == '\0' && strchr(options, '-') == NULL)) { -#endif - place = EMSG; /* found non-option */ - if (flags & FLAG_ALLARGS) { - /* - * GNU extension: - * return non-option as argument to option 1 - */ - optarg = nargv[optind++]; - return (INORDER); - } - if (!(flags & FLAG_PERMUTE)) { - /* - * If no permutation wanted, stop parsing - * at first non-option. - */ - return (-1); - } - /* do permutation */ - if (nonopt_start == -1) - nonopt_start = optind; - else if (nonopt_end != -1) { - permute_args(nonopt_start, nonopt_end, - optind, nargv); - nonopt_start = optind - - (nonopt_end - nonopt_start); - nonopt_end = -1; - } - optind++; - /* process next argument */ - goto start; - } - if (nonopt_start != -1 && nonopt_end == -1) - nonopt_end = optind; - - /* - * If we have "-" do nothing, if "--" we are done. - */ - if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { - optind++; - place = EMSG; - /* - * We found an option (--), so if we skipped - * non-options, we have to permute. - */ - if (nonopt_end != -1) { - permute_args(nonopt_start, nonopt_end, - optind, nargv); - optind -= nonopt_end - nonopt_start; - } - nonopt_start = nonopt_end = -1; - return (-1); - } - } - - /* - * Check long options if: - * 1) we were passed some - * 2) the arg is not just "-" - * 3) either the arg starts with -- we are getopt_long_only() - */ - if (long_options != NULL && place != nargv[optind] && - (*place == '-' || (flags & FLAG_LONGONLY))) { - short_too = 0; -#ifdef GNU_COMPATIBLE - dash_prefix = D_PREFIX; -#endif - if (*place == '-') { - place++; /* --foo long option */ -#ifdef GNU_COMPATIBLE - dash_prefix = DD_PREFIX; -#endif - } else if (*place != ':' && strchr(options, *place) != NULL) - short_too = 1; /* could be short option too */ - - optchar = parse_long_options(nargv, options, long_options, - idx, short_too, flags); - if (optchar != -1) { - place = EMSG; - return (optchar); - } - } - - if ((optchar = (int)*place++) == (int)':' || - (optchar == (int)'-' && *place != '\0') || - (oli = strchr(options, optchar)) == NULL) { - /* - * If the user specified "-" and '-' isn't listed in - * options, return -1 (non-option) as per POSIX. - * Otherwise, it is an unknown option character (or ':'). - */ - if (optchar == (int)'-' && *place == '\0') - return (-1); - if (!*place) - ++optind; -#ifdef GNU_COMPATIBLE - if (PRINT_ERROR) - warnx(posixly_correct ? illoptchar : gnuoptchar, - optchar); -#else - if (PRINT_ERROR) - warnx(illoptchar, optchar); -#endif - optopt = optchar; - return (BADCH); - } - if (long_options != NULL && optchar == 'W' && oli[1] == ';') { - /* -W long-option */ - if (*place) /* no space */ - /* NOTHING */; - else if (++optind >= nargc) { /* no arg */ - place = EMSG; - if (PRINT_ERROR) - warnx(recargchar, optchar); - optopt = optchar; - return (BADARG); - } else /* white space */ - place = nargv[optind]; -#ifdef GNU_COMPATIBLE - dash_prefix = W_PREFIX; -#endif - optchar = parse_long_options(nargv, options, long_options, - idx, 0, flags); - place = EMSG; - return (optchar); - } - if (*++oli != ':') { /* doesn't take argument */ - if (!*place) - ++optind; - } else { /* takes (optional) argument */ - optarg = NULL; - if (*place) /* no white space */ - optarg = place; - /* XXX: disable test for :: if PC? (GNU doesn't) */ - else if (oli[1] != ':') { /* arg not optional */ - if (++optind >= nargc) { /* no arg */ - place = EMSG; - if (PRINT_ERROR) - warnx(recargchar, optchar); - optopt = optchar; - return (BADARG); - } else - optarg = nargv[optind]; - } else if (!(flags & FLAG_PERMUTE)) { - /* - * If permutation is disabled, we can accept an - * optional arg separated by whitespace so long - * as it does not start with a dash (-). - */ - if (optind + 1 < nargc && *nargv[optind + 1] != '-') - optarg = nargv[++optind]; - } - place = EMSG; - ++optind; - } - /* dump back option letter */ - return (optchar); -} - -#ifdef REPLACE_GETOPT -/* - * getopt -- - * Parse argc/argv argument vector. - * - * [eventually this will replace the BSD getopt] - */ -int -getopt(int nargc, char * const *nargv, const char *options) -{ - - /* - * We don't pass FLAG_PERMUTE to getopt_internal() since - * the BSD getopt(3) (unlike GNU) has never done this. - * - * Furthermore, since many privileged programs call getopt() - * before dropping privileges it makes sense to keep things - * as simple (and bug-free) as possible. - */ - return (getopt_internal(nargc, nargv, options, NULL, NULL, 0)); -} -#endif /* REPLACE_GETOPT */ - -/* - * getopt_long -- - * Parse argc/argv argument vector. - */ -int -getopt_long(nargc, nargv, options, long_options, idx) - int nargc; - char * const *nargv; - const char *options; - const struct option *long_options; - int *idx; -{ - - return (getopt_internal(nargc, nargv, options, long_options, idx, - FLAG_PERMUTE)); -} - -/* - * getopt_long_only -- - * Parse argc/argv argument vector. - */ -int -getopt_long_only(nargc, nargv, options, long_options, idx) - int nargc; - char * const *nargv; - const char *options; - const struct option *long_options; - int *idx; -{ - - return (getopt_internal(nargc, nargv, options, long_options, idx, - FLAG_PERMUTE|FLAG_LONGONLY)); -} diff --git a/stdlib/getopt_long-fbsd.c b/stdlib/getopt_long-fbsd.c new file mode 120000 index 0000000..efa4ec8 --- /dev/null +++ b/stdlib/getopt_long-fbsd.c @@ -0,0 +1 @@ +./getopt_long.c \ No newline at end of file diff --git a/stdlib/getsubopt-fbsd.c b/stdlib/getsubopt-fbsd.c deleted file mode 100644 index 488706a..0000000 --- a/stdlib/getsubopt-fbsd.c +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getsubopt.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/getsubopt.c,v 1.6 2004/02/23 03:30:02 ache Exp $"); - -#include -#include - -/* - * The SVID interface to getsubopt provides no way of figuring out which - * part of the suboptions list wasn't matched. This makes error messages - * tricky... The extern variable suboptarg is a pointer to the token - * which didn't match. - */ -char *suboptarg; - -int -getsubopt(optionp, tokens, valuep) - char **optionp, **valuep; - char * const *tokens; -{ - int cnt; - char *p; - - suboptarg = *valuep = NULL; - - if (!optionp || !*optionp) - return(-1); - - /* skip leading white-space, commas */ - for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); - - if (!*p) { - *optionp = p; - return(-1); - } - - /* save the start of the token, and skip the rest of the token. */ - for (suboptarg = p; - *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';); - - if (*p) { - /* - * If there's an equals sign, set the value pointer, and - * skip over the value part of the token. Terminate the - * token. - */ - if (*p == '=') { - *p = '\0'; - for (*valuep = ++p; - *p && *p != ',' && *p != ' ' && *p != '\t'; ++p); - if (*p) - *p++ = '\0'; - } else - *p++ = '\0'; - /* Skip any whitespace or commas after this token. */ - for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); - } - - /* set optionp for next round. */ - *optionp = p; - - for (cnt = 0; *tokens; ++tokens, ++cnt) - if (!strcmp(suboptarg, *tokens)) - return(cnt); - return(-1); -} diff --git a/stdlib/getsubopt-fbsd.c b/stdlib/getsubopt-fbsd.c new file mode 120000 index 0000000..96dc064 --- /dev/null +++ b/stdlib/getsubopt-fbsd.c @@ -0,0 +1 @@ +./getsubopt.c \ No newline at end of file diff --git a/stdlib/hcreate-fbsd.c b/stdlib/hcreate-fbsd.c deleted file mode 100644 index 6ab33e5..0000000 --- a/stdlib/hcreate-fbsd.c +++ /dev/null @@ -1,185 +0,0 @@ -/* $NetBSD: hcreate.c,v 1.2 2001/02/19 21:26:04 ross Exp $ */ - -/* - * Copyright (c) 2001 Christopher G. Demetriou - * 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. See http://www.netbsd.org/ for - * information about NetBSD. - * 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. - * - * <> - */ - -/* - * hcreate() / hsearch() / hdestroy() - * - * SysV/XPG4 hash table functions. - * - * Implementation done based on NetBSD manual page and Solaris manual page, - * plus my own personal experience about how they're supposed to work. - * - * I tried to look at Knuth (as cited by the Solaris manual page), but - * nobody had a copy in the office, so... - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: hcreate.c,v 1.2 2001/02/19 21:26:04 ross Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/stdlib/hcreate.c,v 1.3 2002/06/27 13:18:27 deischen Exp $"); - -#include -#include -#include -#include -#include -#include - -/* - * DO NOT MAKE THIS STRUCTURE LARGER THAN 32 BYTES (4 ptrs on 64-bit - * ptr machine) without adjusting MAX_BUCKETS_LG2 below. - */ -struct internal_entry { - SLIST_ENTRY(internal_entry) link; - ENTRY ent; -}; -SLIST_HEAD(internal_head, internal_entry); - -#define MIN_BUCKETS_LG2 4 -#define MIN_BUCKETS (1 << MIN_BUCKETS_LG2) - -/* - * max * sizeof internal_entry must fit into size_t. - * assumes internal_entry is <= 32 (2^5) bytes. - */ -#define MAX_BUCKETS_LG2 (sizeof (size_t) * 8 - 1 - 5) -#define MAX_BUCKETS ((size_t)1 << MAX_BUCKETS_LG2) - -/* Default hash function, from db/hash/hash_func.c */ -extern u_int32_t (*__default_hash)(const void *, size_t); - -static struct internal_head *htable; -static size_t htablesize; - -int -hcreate(size_t nel) -{ - size_t idx; - unsigned int p2; - - /* Make sure this this isn't called when a table already exists. */ - if (htable != NULL) { - errno = EINVAL; - return 0; - } - - /* If nel is too small, make it min sized. */ - if (nel < MIN_BUCKETS) - nel = MIN_BUCKETS; - - /* If it's too large, cap it. */ - if (nel > MAX_BUCKETS) - nel = MAX_BUCKETS; - - /* If it's is not a power of two in size, round up. */ - if ((nel & (nel - 1)) != 0) { - for (p2 = 0; nel != 0; p2++) - nel >>= 1; - nel = 1 << p2; - } - - /* Allocate the table. */ - htablesize = nel; - htable = malloc(htablesize * sizeof htable[0]); - if (htable == NULL) { - errno = ENOMEM; - return 0; - } - - /* Initialize it. */ - for (idx = 0; idx < htablesize; idx++) - SLIST_INIT(&htable[idx]); - - return 1; -} - -void -hdestroy(void) -{ - struct internal_entry *ie; - size_t idx; - - if (htable == NULL) - return; - - for (idx = 0; idx < htablesize; idx++) { - while (!SLIST_EMPTY(&htable[idx])) { - ie = SLIST_FIRST(&htable[idx]); - SLIST_REMOVE_HEAD(&htable[idx], link); - free(ie->ent.key); - free(ie); - } - } - free(htable); - htable = NULL; -} - -ENTRY * -hsearch(ENTRY item, ACTION action) -{ - struct internal_head *head; - struct internal_entry *ie; - uint32_t hashval; - size_t len; - - len = strlen(item.key); - hashval = (*__default_hash)(item.key, len); - - head = &htable[hashval & (htablesize - 1)]; - ie = SLIST_FIRST(head); - while (ie != NULL) { - if (strcmp(ie->ent.key, item.key) == 0) - break; - ie = SLIST_NEXT(ie, link); - } - - if (ie != NULL) - return &ie->ent; - else if (action == FIND) - return NULL; - - ie = malloc(sizeof *ie); - if (ie == NULL) - return NULL; - ie->ent.key = item.key; - ie->ent.data = item.data; - - SLIST_INSERT_HEAD(head, ie, link); - return &ie->ent; -} diff --git a/stdlib/hcreate-fbsd.c b/stdlib/hcreate-fbsd.c new file mode 120000 index 0000000..b06b592 --- /dev/null +++ b/stdlib/hcreate-fbsd.c @@ -0,0 +1 @@ +./hcreate.c \ No newline at end of file diff --git a/stdlib/heapsort-fbsd.c b/stdlib/heapsort-fbsd.c deleted file mode 100644 index e846be2..0000000 --- a/stdlib/heapsort-fbsd.c +++ /dev/null @@ -1,185 +0,0 @@ -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ronnie Kon at Mindcraft Inc., Kevin Lew and Elmer Yglesias. - * - * 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[] = "@(#)heapsort.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/heapsort.c,v 1.4 2002/03/21 22:48:41 obrien Exp $"); - -#include -#include -#include - -/* - * Swap two areas of size number of bytes. Although qsort(3) permits random - * blocks of memory to be sorted, sorting pointers is almost certainly the - * common case (and, were it not, could easily be made so). Regardless, it - * isn't worth optimizing; the SWAP's get sped up by the cache, and pointer - * arithmetic gets lost in the time required for comparison function calls. - */ -#define SWAP(a, b, count, size, tmp) { \ - count = size; \ - do { \ - tmp = *a; \ - *a++ = *b; \ - *b++ = tmp; \ - } while (--count); \ -} - -/* Copy one block of size size to another. */ -#define COPY(a, b, count, size, tmp1, tmp2) { \ - count = size; \ - tmp1 = a; \ - tmp2 = b; \ - do { \ - *tmp1++ = *tmp2++; \ - } while (--count); \ -} - -/* - * Build the list into a heap, where a heap is defined such that for - * the records K1 ... KN, Kj/2 >= Kj for 1 <= j/2 <= j <= N. - * - * There two cases. If j == nmemb, select largest of Ki and Kj. If - * j < nmemb, select largest of Ki, Kj and Kj+1. - */ -#define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) { \ - for (par_i = initval; (child_i = par_i * 2) <= nmemb; \ - par_i = child_i) { \ - child = base + child_i * size; \ - if (child_i < nmemb && compar(child, child + size) < 0) { \ - child += size; \ - ++child_i; \ - } \ - par = base + par_i * size; \ - if (compar(child, par) <= 0) \ - break; \ - SWAP(par, child, count, size, tmp); \ - } \ -} - -/* - * Select the top of the heap and 'heapify'. Since by far the most expensive - * action is the call to the compar function, a considerable optimization - * in the average case can be achieved due to the fact that k, the displaced - * elememt, is ususally quite small, so it would be preferable to first - * heapify, always maintaining the invariant that the larger child is copied - * over its parent's record. - * - * Then, starting from the *bottom* of the heap, finding k's correct place, - * again maintianing the invariant. As a result of the invariant no element - * is 'lost' when k is assigned its correct place in the heap. - * - * The time savings from this optimization are on the order of 15-20% for the - * average case. See Knuth, Vol. 3, page 158, problem 18. - * - * XXX Don't break the #define SELECT line, below. Reiser cpp gets upset. - */ -#define SELECT(par_i, child_i, nmemb, par, child, size, k, count, tmp1, tmp2) { \ - for (par_i = 1; (child_i = par_i * 2) <= nmemb; par_i = child_i) { \ - child = base + child_i * size; \ - if (child_i < nmemb && compar(child, child + size) < 0) { \ - child += size; \ - ++child_i; \ - } \ - par = base + par_i * size; \ - COPY(par, child, count, size, tmp1, tmp2); \ - } \ - for (;;) { \ - child_i = par_i; \ - par_i = child_i / 2; \ - child = base + child_i * size; \ - par = base + par_i * size; \ - if (child_i == 1 || compar(k, par) < 0) { \ - COPY(child, k, count, size, tmp1, tmp2); \ - break; \ - } \ - COPY(child, par, count, size, tmp1, tmp2); \ - } \ -} - -/* - * Heapsort -- Knuth, Vol. 3, page 145. Runs in O (N lg N), both average - * and worst. While heapsort is faster than the worst case of quicksort, - * the BSD quicksort does median selection so that the chance of finding - * a data set that will trigger the worst case is nonexistent. Heapsort's - * only advantage over quicksort is that it requires little additional memory. - */ -int -heapsort(vbase, nmemb, size, compar) - void *vbase; - size_t nmemb, size; - int (*compar)(const void *, const void *); -{ - int cnt, i, j, l; - char tmp, *tmp1, *tmp2; - char *base, *k, *p, *t; - - if (nmemb <= 1) - return (0); - - if (!size) { - errno = EINVAL; - return (-1); - } - - if ((k = malloc(size)) == NULL) - return (-1); - - /* - * Items are numbered from 1 to nmemb, so offset from size bytes - * below the starting address. - */ - base = (char *)vbase - size; - - for (l = nmemb / 2 + 1; --l;) - CREATE(l, nmemb, i, j, t, p, size, cnt, tmp); - - /* - * For each element of the heap, save the largest element into its - * final slot, save the displaced element (k), then recreate the - * heap. - */ - while (nmemb > 1) { - COPY(k, base + nmemb * size, cnt, size, tmp1, tmp2); - COPY(base + nmemb * size, base + size, cnt, size, tmp1, tmp2); - --nmemb; - SELECT(i, j, nmemb, t, p, size, k, cnt, tmp1, tmp2); - } - free(k); - return (0); -} diff --git a/stdlib/heapsort-fbsd.c b/stdlib/heapsort-fbsd.c new file mode 120000 index 0000000..a549564 --- /dev/null +++ b/stdlib/heapsort-fbsd.c @@ -0,0 +1 @@ +./heapsort.c \ No newline at end of file diff --git a/stdlib/imaxabs-fbsd.c b/stdlib/imaxabs-fbsd.c deleted file mode 100644 index 531de24..0000000 --- a/stdlib/imaxabs-fbsd.c +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * Copyright (c) 2001 Mike Barcroft - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/imaxabs.c,v 1.1 2001/11/15 02:05:03 mike Exp $"); - -#include - -intmax_t -imaxabs(intmax_t j) -{ - return (j < 0 ? -j : j); -} diff --git a/stdlib/imaxabs-fbsd.c b/stdlib/imaxabs-fbsd.c new file mode 120000 index 0000000..2ec179f --- /dev/null +++ b/stdlib/imaxabs-fbsd.c @@ -0,0 +1 @@ +./imaxabs.c \ No newline at end of file diff --git a/stdlib/imaxdiv-fbsd.c b/stdlib/imaxdiv-fbsd.c deleted file mode 100644 index ff3087b..0000000 --- a/stdlib/imaxdiv-fbsd.c +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * Copyright (c) 2001 Mike Barcroft - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/imaxdiv.c,v 1.1 2001/11/15 02:05:03 mike Exp $"); - -#include - -/* See comments in div.c for implementation details. */ -imaxdiv_t -imaxdiv(intmax_t numer, intmax_t denom) -{ - imaxdiv_t retval; - - retval.quot = numer / denom; - retval.rem = numer % denom; - if (numer >= 0 && retval.rem < 0) { - retval.quot++; - retval.rem -= denom; - } - return (retval); -} diff --git a/stdlib/imaxdiv-fbsd.c b/stdlib/imaxdiv-fbsd.c new file mode 120000 index 0000000..e8331e0 --- /dev/null +++ b/stdlib/imaxdiv-fbsd.c @@ -0,0 +1 @@ +./imaxdiv.c \ No newline at end of file diff --git a/stdlib/insque-fbsd.c b/stdlib/insque-fbsd.c deleted file mode 100644 index 92984b0..0000000 --- a/stdlib/insque-fbsd.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Initial implementation: - * Copyright (c) 2002 Robert Drehmel - * All rights reserved. - * - * As long as the above copyright statement and this notice remain - * unchanged, you can do what ever you want with this file. - */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/insque.c,v 1.3 2003/01/04 07:34:41 tjr Exp $"); - -#define _SEARCH_PRIVATE -#include -#ifdef DEBUG -#include -#else -#include /* for NULL */ -#endif - -void -insque(void *element, void *pred) -{ - struct que_elem *prev, *next, *elem; - - elem = (struct que_elem *)element; - prev = (struct que_elem *)pred; - - if (prev == NULL) { - elem->prev = elem->next = NULL; - return; - } - - next = prev->next; - if (next != NULL) { -#ifdef DEBUG - if (next->prev != prev) { - fprintf(stderr, "insque: Inconsistency detected:" - " next(%p)->prev(%p) != prev(%p)\n", - next, next->prev, prev); - } -#endif - next->prev = elem; - } - prev->next = elem; - elem->prev = prev; - elem->next = next; -} diff --git a/stdlib/insque-fbsd.c b/stdlib/insque-fbsd.c new file mode 120000 index 0000000..86c8bff --- /dev/null +++ b/stdlib/insque-fbsd.c @@ -0,0 +1 @@ +./insque.c \ No newline at end of file diff --git a/stdlib/labs-fbsd.c b/stdlib/labs-fbsd.c deleted file mode 100644 index 42e63d1..0000000 --- a/stdlib/labs-fbsd.c +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)labs.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/labs.c,v 1.2 2002/03/22 21:53:10 obrien Exp $"); - -#include - -long -labs(j) - long j; -{ - return(j < 0 ? -j : j); -} diff --git a/stdlib/labs-fbsd.c b/stdlib/labs-fbsd.c new file mode 120000 index 0000000..8c4a475 --- /dev/null +++ b/stdlib/labs-fbsd.c @@ -0,0 +1 @@ +./labs.c \ No newline at end of file diff --git a/stdlib/ldiv-fbsd.c b/stdlib/ldiv-fbsd.c deleted file mode 100644 index 560d5c2..0000000 --- a/stdlib/ldiv-fbsd.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - * - * 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[] = "@(#)ldiv.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/ldiv.c,v 1.2 2002/03/22 21:53:10 obrien Exp $"); - -#include /* ldiv_t */ - -ldiv_t -ldiv(num, denom) - long num, denom; -{ - ldiv_t r; - - /* see div.c for comments */ - - r.quot = num / denom; - r.rem = num % denom; - if (num >= 0 && r.rem < 0) { - r.quot++; - r.rem -= denom; - } - return (r); -} diff --git a/stdlib/ldiv-fbsd.c b/stdlib/ldiv-fbsd.c new file mode 120000 index 0000000..0b50c5d --- /dev/null +++ b/stdlib/ldiv-fbsd.c @@ -0,0 +1 @@ +./ldiv.c \ No newline at end of file diff --git a/stdlib/llabs-fbsd.c b/stdlib/llabs-fbsd.c deleted file mode 100644 index 4721fce..0000000 --- a/stdlib/llabs-fbsd.c +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * Copyright (c) 2001 Mike Barcroft - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/llabs.c,v 1.1 2001/11/15 02:05:03 mike Exp $"); - -#include - -long long -llabs(long long j) -{ - return (j < 0 ? -j : j); -} diff --git a/stdlib/llabs-fbsd.c b/stdlib/llabs-fbsd.c new file mode 120000 index 0000000..1eabe54 --- /dev/null +++ b/stdlib/llabs-fbsd.c @@ -0,0 +1 @@ +./llabs.c \ No newline at end of file diff --git a/stdlib/lldiv-fbsd.c b/stdlib/lldiv-fbsd.c deleted file mode 100644 index c9a4853..0000000 --- a/stdlib/lldiv-fbsd.c +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * Copyright (c) 2001 Mike Barcroft - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/lldiv.c,v 1.1 2001/11/15 02:05:03 mike Exp $"); - -#include - -/* See comments in div.c for implementation details. */ -lldiv_t -lldiv(long long numer, long long denom) -{ - lldiv_t retval; - - retval.quot = numer / denom; - retval.rem = numer % denom; - if (numer >= 0 && retval.rem < 0) { - retval.quot++; - retval.rem -= denom; - } - return (retval); -} diff --git a/stdlib/lldiv-fbsd.c b/stdlib/lldiv-fbsd.c new file mode 120000 index 0000000..266ebc0 --- /dev/null +++ b/stdlib/lldiv-fbsd.c @@ -0,0 +1 @@ +./lldiv.c \ No newline at end of file diff --git a/stdlib/lsearch-fbsd.c b/stdlib/lsearch-fbsd.c deleted file mode 100644 index 791bc49..0000000 --- a/stdlib/lsearch-fbsd.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Initial implementation: - * Copyright (c) 2002 Robert Drehmel - * All rights reserved. - * - * As long as the above copyright statement and this notice remain - * unchanged, you can do what ever you want with this file. - */ -#include -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/lsearch.c,v 1.1 2002/10/16 14:29:22 robert Exp $"); - -#define _SEARCH_PRIVATE -#include -#include /* for uint8_t */ -#include /* for NULL */ -#include /* for memcpy() prototype */ - -static void *lwork(const void *, const void *, size_t *, size_t, - int (*)(const void *, const void *), int); - -void *lsearch(const void *key, void *base, size_t *nelp, size_t width, - int (*compar)(const void *, const void *)) -{ - - return (lwork(key, base, nelp, width, compar, 1)); -} - -void *lfind(const void *key, const void *base, size_t *nelp, size_t width, - int (*compar)(const void *, const void *)) -{ - - return (lwork(key, base, nelp, width, compar, 0)); -} - -static void * -lwork(const void *key, const void *base, size_t *nelp, size_t width, - int (*compar)(const void *, const void *), int addelem) -{ - uint8_t *ep, *endp; - - /* - * Cast to an integer value first to avoid the warning for removing - * 'const' via a cast. - */ - ep = (uint8_t *)(uintptr_t)base; - for (endp = (uint8_t *)(ep + width * *nelp); ep < endp; ep += width) { - if (compar(key, ep) == 0) - return (ep); - } - - /* lfind() shall return when the key was not found. */ - if (!addelem) - return (NULL); - - /* - * lsearch() adds the key to the end of the table and increments - * the number of elements. - */ - memcpy(endp, key, width); - ++*nelp; - - return (endp); -} diff --git a/stdlib/lsearch-fbsd.c b/stdlib/lsearch-fbsd.c new file mode 120000 index 0000000..739569c --- /dev/null +++ b/stdlib/lsearch-fbsd.c @@ -0,0 +1 @@ +./lsearch.c \ No newline at end of file diff --git a/stdlib/merge-fbsd.c b/stdlib/merge-fbsd.c deleted file mode 100644 index 711b9cd..0000000 --- a/stdlib/merge-fbsd.c +++ /dev/null @@ -1,352 +0,0 @@ -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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[] = "@(#)merge.c 8.2 (Berkeley) 2/14/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/merge.c,v 1.6 2002/03/21 22:48:42 obrien Exp $"); - -/* - * Hybrid exponential search/linear search merge sort with hybrid - * natural/pairwise first pass. Requires about .3% more comparisons - * for random data than LSMS with pairwise first pass alone. - * It works for objects as small as two bytes. - */ - -#define NATURAL -#define THRESHOLD 16 /* Best choice for natural merge cut-off. */ - -/* #define NATURAL to get hybrid natural merge. - * (The default is pairwise merging.) - */ - -#include - -#include -#include -#include - -static void setup(u_char *, u_char *, size_t, size_t, int (*)()); -static void insertionsort(u_char *, size_t, size_t, int (*)()); - -#define ISIZE sizeof(int) -#define PSIZE sizeof(u_char *) -#define ICOPY_LIST(src, dst, last) \ - do \ - *(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE; \ - while(src < last) -#define ICOPY_ELT(src, dst, i) \ - do \ - *(int*) dst = *(int*) src, src += ISIZE, dst += ISIZE; \ - while (i -= ISIZE) - -#define CCOPY_LIST(src, dst, last) \ - do \ - *dst++ = *src++; \ - while (src < last) -#define CCOPY_ELT(src, dst, i) \ - 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 - * boundaries. - */ -/* Assumption: PSIZE is a power of 2. */ -#define EVAL(p) (u_char **) \ - ((u_char *)0 + \ - (((u_char *)p + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1))) - -/* - * Arguments are as for qsort. - */ -int -mergesort(base, nmemb, size, cmp) - void *base; - size_t nmemb; - size_t size; - int (*cmp)(const void *, const void *); -{ - int i, sense; - int big, iflag; - u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2; - u_char *list2, *list1, *p2, *p, *last, **p1; - - if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */ - errno = EINVAL; - return (-1); - } - - if (nmemb == 0) - return (0); - - /* - * XXX - * Stupid subtraction for the Cray. - */ - iflag = 0; - if (!(size % ISIZE) && !(((char *)base - (char *)0) % ISIZE)) - iflag = 1; - - if ((list2 = malloc(nmemb * size + PSIZE)) == NULL) - return (-1); - - list1 = base; - setup(list1, list2, nmemb, size, cmp); - last = list2 + nmemb * size; - i = big = 0; - while (*EVAL(list2) != last) { - l2 = list1; - p1 = EVAL(list1); - for (tp2 = p2 = list2; p2 != last; p1 = EVAL(l2)) { - p2 = *EVAL(p2); - f1 = l2; - f2 = l1 = list1 + (p2 - list2); - if (p2 != last) - p2 = *EVAL(p2); - l2 = list1 + (p2 - list2); - while (f1 < l1 && f2 < l2) { - if ((*cmp)(f1, f2) <= 0) { - q = f2; - b = f1, t = l1; - sense = -1; - } else { - q = f1; - b = f2, t = l2; - sense = 0; - } - if (!big) { /* here i = 0 */ - while ((b += size) < t && cmp(q, b) >sense) - if (++i == 6) { - big = 1; - goto EXPONENTIAL; - } - } else { -EXPONENTIAL: for (i = size; ; i <<= 1) - if ((p = (b + i)) >= t) { - if ((p = t - size) > b && - (*cmp)(q, p) <= sense) - t = p; - else - b = p; - break; - } else if ((*cmp)(q, p) <= sense) { - t = p; - if (i == size) - big = 0; - goto FASTCASE; - } else - b = p; - while (t > b+size) { - i = (((t - b) / size) >> 1) * size; - if ((*cmp)(q, p = b + i) <= sense) - t = p; - else - b = p; - } - goto COPY; -FASTCASE: while (i > size) - if ((*cmp)(q, - p = b + (i >>= 1)) <= sense) - t = p; - else - b = p; -COPY: b = t; - } - i = size; - if (q == f1) { - if (iflag) { - ICOPY_LIST(f2, tp2, b); - ICOPY_ELT(f1, tp2, i); - } else { - CCOPY_LIST(f2, tp2, b); - CCOPY_ELT(f1, tp2, i); - } - } else { - if (iflag) { - ICOPY_LIST(f1, tp2, b); - ICOPY_ELT(f2, tp2, i); - } else { - CCOPY_LIST(f1, tp2, b); - CCOPY_ELT(f2, tp2, i); - } - } - } - if (f2 < l2) { - if (iflag) - ICOPY_LIST(f2, tp2, l2); - else - CCOPY_LIST(f2, tp2, l2); - } else if (f1 < l1) { - if (iflag) - ICOPY_LIST(f1, tp2, l1); - else - CCOPY_LIST(f1, tp2, l1); - } - *p1 = l2; - } - tp2 = list1; /* swap list1, list2 */ - list1 = list2; - list2 = tp2; - last = list2 + nmemb*size; - } - if (base == list2) { - memmove(list2, list1, nmemb*size); - list2 = list1; - } - free(list2); - return (0); -} - -#define swap(a, b) { \ - s = b; \ - i = size; \ - do { \ - tmp = *a; *a++ = *s; *s++ = tmp; \ - } while (--i); \ - a -= size; \ - } -#define reverse(bot, top) { \ - s = top; \ - do { \ - i = size; \ - do { \ - tmp = *bot; *bot++ = *s; *s++ = tmp; \ - } while (--i); \ - s -= size2; \ - } while(bot < s); \ -} - -/* - * Optional hybrid natural/pairwise first pass. Eats up list1 in runs of - * increasing order, list2 in a corresponding linked list. Checks for runs - * when THRESHOLD/2 pairs compare with same sense. (Only used when NATURAL - * is defined. Otherwise simple pairwise merging is used.) - */ -void -setup(list1, list2, n, size, cmp) - size_t n, size; - int (*cmp)(const void *, const void *); - u_char *list1, *list2; -{ - int i, length, size2, tmp, sense; - u_char *f1, *f2, *s, *l2, *last, *p2; - - size2 = size*2; - if (n <= 5) { - insertionsort(list1, n, size, cmp); - *EVAL(list2) = (u_char*) list2 + n*size; - return; - } - /* - * Avoid running pointers out of bounds; limit n to evens - * for simplicity. - */ - i = 4 + (n & 1); - insertionsort(list1 + (n - i) * size, i, size, cmp); - last = list1 + size * (n - i); - *EVAL(list2 + (last - list1)) = list2 + n * size; - -#ifdef NATURAL - p2 = list2; - f1 = list1; - sense = (cmp(f1, f1 + size) > 0); - for (; f1 < last; sense = !sense) { - length = 2; - /* Find pairs with same sense. */ - for (f2 = f1 + size2; f2 < last; f2 += size2) { - if ((cmp(f2, f2+ size) > 0) != sense) - break; - length += 2; - } - if (length < THRESHOLD) { /* Pairwise merge */ - do { - p2 = *EVAL(p2) = f1 + size2 - list1 + list2; - if (sense > 0) - swap (f1, f1 + size); - } while ((f1 += size2) < f2); - } else { /* Natural merge */ - l2 = f2; - for (f2 = f1 + size2; f2 < l2; f2 += size2) { - if ((cmp(f2-size, f2) > 0) != sense) { - p2 = *EVAL(p2) = f2 - list1 + list2; - if (sense > 0) - reverse(f1, f2-size); - f1 = f2; - } - } - if (sense > 0) - reverse (f1, f2-size); - f1 = f2; - if (f2 < last || cmp(f2 - size, f2) > 0) - p2 = *EVAL(p2) = f2 - list1 + list2; - else - p2 = *EVAL(p2) = list2 + n*size; - } - } -#else /* pairwise merge only. */ - for (f1 = list1, p2 = list2; f1 < last; f1 += size2) { - p2 = *EVAL(p2) = p2 + size2; - if (cmp (f1, f1 + size) > 0) - swap(f1, f1 + size); - } -#endif /* NATURAL */ -} - -/* - * This is to avoid out-of-bounds addresses in sorting the - * last 4 elements. - */ -static void -insertionsort(a, n, size, cmp) - u_char *a; - size_t n, size; - int (*cmp)(const void *, const void *); -{ - u_char *ai, *s, *t, *u, tmp; - int i; - - for (ai = a+size; --n >= 1; ai += size) - for (t = ai; t > a; t -= size) { - u = t - size; - if (cmp(u, t) <= 0) - break; - swap(u, t); - } -} diff --git a/stdlib/merge-fbsd.c b/stdlib/merge-fbsd.c new file mode 120000 index 0000000..474ed7f --- /dev/null +++ b/stdlib/merge-fbsd.c @@ -0,0 +1 @@ +./merge.c \ No newline at end of file diff --git a/stdlib/rand-fbsd.c b/stdlib/rand-fbsd.c deleted file mode 100644 index 359e12a..0000000 --- a/stdlib/rand-fbsd.c +++ /dev/null @@ -1,172 +0,0 @@ -/*- - * Copyright (c) 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. - * - * Posix rand_r function added May 1999 by Wes Peters . - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rand.c 8.1 (Berkeley) 6/14/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/rand.c,v 1.15 2003/02/17 03:52:35 ache Exp $"); - -#include "namespace.h" -#include /* for sranddev() */ -#include -#include /* for sranddev() */ -#include -#include /* for sranddev() */ -#include "un-namespace.h" - -#ifdef TEST -#include -#endif /* TEST */ - -static int -do_rand(unsigned long *ctx) -{ -#ifdef USE_WEAK_SEEDING -/* - * Historic implementation compatibility. - * The random sequences do not vary much with the seed, - * even with overflowing. - */ - return ((*ctx = *ctx * 1103515245 + 12345) % ((u_long)RAND_MAX + 1)); -#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. - */ - long hi, lo, x; - - /* Can't be initialized with 0, so use another value. */ - if (*ctx == 0) - *ctx = 123459876; - hi = *ctx / 127773; - lo = *ctx % 127773; - x = 16807 * lo - 2836 * hi; - if (x < 0) - x += 0x7fffffff; - return ((*ctx = x) % ((u_long)RAND_MAX + 1)); -#endif /* !USE_WEAK_SEEDING */ -} - - -int -rand_r(unsigned int *ctx) -{ - u_long val = (u_long) *ctx; - int r = do_rand(&val); - - *ctx = (unsigned int) val; - return (r); -} - - -static u_long next = 1; - -int -rand() -{ - return (do_rand(&next)); -} - -void -srand(seed) -u_int seed; -{ - next = seed; -} - - -/* - * sranddev: - * - * Many programs choose the seed value in a totally predictable manner. - * This often causes problems. We seed the generator using the much more - * secure random(4) interface. - */ -void -sranddev() -{ - int fd, done; - - done = 0; - fd = _open("/dev/random", O_RDONLY, 0); - if (fd >= 0) { - if (_read(fd, (void *) &next, sizeof(next)) == sizeof(next)) - done = 1; - _close(fd); - } - - if (!done) { - struct timeval tv; - unsigned long junk; - - gettimeofday(&tv, NULL); - srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk); - } -} - - -#ifdef TEST - -main() -{ - int i; - unsigned myseed; - - printf("seeding rand with 0x19610910: \n"); - srand(0x19610910); - - printf("generating three pseudo-random numbers:\n"); - for (i = 0; i < 3; i++) - { - printf("next random number = %d\n", rand()); - } - - printf("generating the same sequence with rand_r:\n"); - myseed = 0x19610910; - for (i = 0; i < 3; i++) - { - printf("next random number = %d\n", rand_r(&myseed)); - } - - return 0; -} - -#endif /* TEST */ - diff --git a/stdlib/rand-fbsd.c b/stdlib/rand-fbsd.c new file mode 120000 index 0000000..a77f59d --- /dev/null +++ b/stdlib/rand-fbsd.c @@ -0,0 +1 @@ +./rand.c \ No newline at end of file diff --git a/stdlib/reallocf-fbsd.c b/stdlib/reallocf-fbsd.c deleted file mode 100644 index d502006..0000000 --- a/stdlib/reallocf-fbsd.c +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * Copyright (c) 1998, M. Warner Losh - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/reallocf.c,v 1.4 2002/03/22 21:53:10 obrien Exp $"); - -#include - -void * -reallocf(void *ptr, size_t size) -{ - void *nptr; - - nptr = realloc(ptr, size); - if (!nptr && ptr) - free(ptr); - return (nptr); -} diff --git a/stdlib/reallocf-fbsd.c b/stdlib/reallocf-fbsd.c new file mode 120000 index 0000000..001360c --- /dev/null +++ b/stdlib/reallocf-fbsd.c @@ -0,0 +1 @@ +./reallocf.c \ No newline at end of file diff --git a/stdlib/remque-fbsd.c b/stdlib/remque-fbsd.c deleted file mode 100644 index 068a75f..0000000 --- a/stdlib/remque-fbsd.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Initial implementation: - * Copyright (c) 2002 Robert Drehmel - * All rights reserved. - * - * As long as the above copyright statement and this notice remain - * unchanged, you can do what ever you want with this file. - */ -#include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/remque.c,v 1.3 2003/01/04 07:34:41 tjr Exp $"); - -#define _SEARCH_PRIVATE -#include -#include /* for NULL */ - -void -remque(void *element) -{ - struct que_elem *prev, *next, *elem; - - elem = (struct que_elem *)element; - - prev = elem->prev; - next = elem->next; - - if (prev != NULL) - prev->next = next; - if (next != NULL) - next->prev = prev; -} diff --git a/stdlib/remque-fbsd.c b/stdlib/remque-fbsd.c new file mode 120000 index 0000000..f8680b9 --- /dev/null +++ b/stdlib/remque-fbsd.c @@ -0,0 +1 @@ +./remque.c \ No newline at end of file diff --git a/stdlib/strfmon-fbsd.c b/stdlib/strfmon-nbsd.c similarity index 92% rename from stdlib/strfmon-fbsd.c rename to stdlib/strfmon-nbsd.c index 3ffb346..ac7a536 100644 --- a/stdlib/strfmon-fbsd.c +++ b/stdlib/strfmon-nbsd.c @@ -1,3 +1,5 @@ +/* $NetBSD: strfmon.c,v 1.6 2008/03/27 21:50:30 christos Exp $ */ + /*- * Copyright (c) 2001 Alexey Zelkin * All rights reserved. @@ -26,7 +28,18 @@ */ #include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); +#else +__RCSID("$NetBSD: strfmon.c,v 1.6 2008/03/27 21:50:30 christos Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#if defined(__NetBSD__) +#include "namespace.h" +#include +#endif #include "xlocale_private.h" @@ -39,6 +52,7 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ach #include #include #include +#include /* internal flags */ #define NEED_GROUPING 0x01 /* print digits grouped (default) */ @@ -55,22 +69,24 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ach if (dst >= s + maxsize) \ goto e2big_error; \ *dst++ = CH; \ -} while (0) +} while (/* CONSTCOND */ 0) #define PRINTS(STR) do { \ - char *tmps = STR; \ + const char *tmps = STR; \ while (*tmps != '\0') \ PRINT(*tmps++); \ -} while (0) +} while (/* CONSTCOND */ 0) #define GET_NUMBER(VAR,LOC) do { \ VAR = 0; \ while (isdigit_l((unsigned char)*fmt, (LOC))) { \ VAR *= 10; \ VAR += *fmt - '0'; \ + if (VAR > 0x00ffffff) \ + goto e2big_error; \ fmt++; \ } \ -} while (0) +} while (/* CONSTCOND */ 0) #define GRPCPY(howmany) do { \ int i = howmany; \ @@ -78,20 +94,19 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ach avalue_size--; \ *--bufend = *(avalue+avalue_size+padded); \ } \ -} while (0) +} while (/* CONSTCOND */ 0) #define GRPSEP do { \ *--bufend = thousands_sep; \ groups++; \ -} while (0) +} while (/* CONSTCOND */ 0) -static void __setup_vars(int, char *, char *, char *, char **, struct lconv *); +static void __setup_vars(int, char *, char *, char *, const char **, struct lconv *); static int __calc_left_pad(int, char *, struct lconv *); static char *__format_grouped_double(double, int *, int, int, int, struct lconv *, locale_t); static ssize_t -_strfmon(char * __restrict s, size_t maxsize, locale_t loc, - const char * __restrict format, va_list ap) +_strfmon(char * __restrict s, size_t maxsize, locale_t loc, const char * __restrict format, va_list ap) { char *dst; /* output destination pointer */ const char *fmt; /* current format poistion pointer */ @@ -110,8 +125,8 @@ _strfmon(char * __restrict s, size_t maxsize, locale_t loc, char cs_precedes, /* values gathered from struct lconv */ sep_by_space, sign_posn, - *signstr, *currency_symbol; + const char *signstr; char *tmpptr; /* temporary vars */ int sverrno; @@ -147,7 +162,7 @@ _strfmon(char * __restrict s, size_t maxsize, locale_t loc, value = 0; /* we have no value to print now */ /* Flags */ - while (1) { + while (/* CONSTCOND */ 1) { switch (*++fmt) { case '=': /* fill character */ pad_char = *++fmt; @@ -181,11 +196,13 @@ _strfmon(char * __restrict s, size_t maxsize, locale_t loc, /* field Width */ if (isdigit_l((unsigned char)*fmt, loc)) { + ptrdiff_t d = dst - s; GET_NUMBER(width, loc); /* Do we have enough space to put number with * required width ? */ - if (dst + width >= s + maxsize) + + if (d + width >= maxsize) goto e2big_error; } @@ -216,6 +233,8 @@ _strfmon(char * __restrict s, size_t maxsize, locale_t loc, goto format_error; } + if (currency_symbol) + free(currency_symbol); if (flags & USE_INTL_CURRENCY) { currency_symbol = strdup(lc->int_curr_symbol); if (currency_symbol != NULL) { @@ -366,8 +385,8 @@ _strfmon(char * __restrict s, size_t maxsize, locale_t loc, } else { pad_size = dst-tmpptr; memmove(tmpptr + width-pad_size, tmpptr, - pad_size); - memset(tmpptr, ' ', width-pad_size); + (size_t) pad_size); + memset(tmpptr, ' ', (size_t) width-pad_size); dst += width-pad_size; } } @@ -397,7 +416,7 @@ end_error: static void __setup_vars(int flags, char *cs_precedes, char *sep_by_space, - char *sign_posn, char **signstr, struct lconv *lc) { + char *sign_posn, const char **signstr, struct lconv *lc) { if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) { *cs_precedes = lc->int_n_cs_precedes; @@ -435,7 +454,8 @@ __setup_vars(int flags, char *cs_precedes, char *sep_by_space, static int __calc_left_pad(int flags, char *cur_symb, struct lconv *lc) { - char cs_precedes, sep_by_space, sign_posn, *signstr; + char cs_precedes, sep_by_space, sign_posn; + const char *signstr; int left_chars = 0; __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr, lc); @@ -561,7 +581,7 @@ __format_grouped_double(double value, int *flags, if (right_prec > 0) { bufend -= right_prec; memcpy(bufend, avalue + avalue_size+padded-right_prec, - right_prec); + (size_t) right_prec); *--bufend = decimal_point; avalue_size -= (right_prec + 1); } @@ -594,7 +614,7 @@ __format_grouped_double(double value, int *flags, } else { bufend -= avalue_size; - memcpy(bufend, avalue+padded, avalue_size); + memcpy(bufend, avalue+padded, (size_t) avalue_size); if (right_prec == 0) padded--; /* decrease assumed $decimal_point */ } @@ -602,7 +622,7 @@ __format_grouped_double(double value, int *flags, /* do padding with pad_char */ if (padded > 0) { bufend -= padded; - memset(bufend, pad_char, padded); + memset(bufend, pad_char, (size_t) padded); } bufsize = bufsize - (bufend - rslt) + 1; diff --git a/stdlib/strfmon.3 b/stdlib/strfmon.3 index 3634fbb..a3d9133 100644 --- a/stdlib/strfmon.3 +++ b/stdlib/strfmon.3 @@ -1,3 +1,5 @@ +.\" $NetBSD: strfmon.3,v 1.3 2005/04/04 08:19:00 wiz Exp $ +.\" .\" Copyright (c) 2001 Jeroen Ruigrok van der Werven .\" All rights reserved. .\" @@ -22,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libc/stdlib/strfmon.3,v 1.7 2003/01/06 06:21:25 tjr Exp $ +.\" From: FreeBSD: Id: strfmon.3,v 1.7 2003/01/06 06:21:25 tjr Exp .\" .Dd October 12, 2002 .Dt STRFMON 3 @@ -31,8 +33,8 @@ .Nm strfmon , .Nm strfmon_l .Nd convert monetary value to string -.Sh LIBRARY -.Lb libc +.\" .Sh LIBRARY +.\" .Lb libc .Sh SYNOPSIS .In monetary.h .Ft ssize_t @@ -119,7 +121,7 @@ expected number of digits after the radix character. A .Sq Cm \&. character followed by a decimal number specifying the number -the number of digits after the radix character. +of digits after the radix character. .It One of the following conversion specifiers: .Bl -tag -width "XXX" @@ -183,7 +185,7 @@ function was implemented by .Pp This manual page was written by .An Jeroen Ruigrok van der Werven Aq asmodai@FreeBSD.org -based on the standards' text. +based on the standard's text. .Sh BUGS The .Fn strfmon diff --git a/stdlib/tdelete-fbsd.c b/stdlib/tdelete-fbsd.c deleted file mode 100644 index 7fb6893..0000000 --- a/stdlib/tdelete-fbsd.c +++ /dev/null @@ -1,71 +0,0 @@ -/* $NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ - -/* - * Tree search generalized from Knuth (6.2.2) Algorithm T just like - * the AT&T man page says. - * - * The node_t structure is for internal use only, lint doesn't grok it. - * - * Written by reading the System V Interface Definition, not the code. - * - * Totally public domain. - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/stdlib/tdelete.c,v 1.6 2003/01/05 02:43:18 tjr Exp $"); - -#define _SEARCH_PRIVATE -#include -#include - - -/* - * delete node with given key - * - * vkey: key to be deleted - * vrootp: address of the root of the tree - * compar: function to carry out node comparisons - */ -void * -tdelete(const void * __restrict vkey, void ** __restrict vrootp, - int (*compar)(const void *, const void *)) -{ - node_t **rootp = (node_t **)vrootp; - node_t *p, *q, *r; - int cmp; - - if (rootp == NULL || (p = *rootp) == NULL) - return NULL; - - while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0) { - p = *rootp; - rootp = (cmp < 0) ? - &(*rootp)->llink : /* follow llink branch */ - &(*rootp)->rlink; /* follow rlink branch */ - if (*rootp == NULL) - return NULL; /* key not found */ - } - r = (*rootp)->rlink; /* D1: */ - if ((q = (*rootp)->llink) == NULL) /* Left NULL? */ - q = r; - else if (r != NULL) { /* Right link is NULL? */ - if (r->llink == NULL) { /* D2: Find successor */ - r->llink = q; - q = r; - } else { /* D3: Find NULL link */ - for (q = r->llink; q->llink != NULL; q = r->llink) - r = q; - r->llink = q->rlink; - q->llink = (*rootp)->llink; - q->rlink = (*rootp)->rlink; - } - } - free(*rootp); /* D4: Free node */ - *rootp = q; /* link parent to new node */ - return p; -} diff --git a/stdlib/tdelete-fbsd.c b/stdlib/tdelete-fbsd.c new file mode 120000 index 0000000..780001f --- /dev/null +++ b/stdlib/tdelete-fbsd.c @@ -0,0 +1 @@ +./tdelete.c \ No newline at end of file diff --git a/stdlib/tfind-fbsd.c b/stdlib/tfind-fbsd.c deleted file mode 100644 index b58ed88..0000000 --- a/stdlib/tfind-fbsd.c +++ /dev/null @@ -1,48 +0,0 @@ -/* $NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ - -/* - * Tree search generalized from Knuth (6.2.2) Algorithm T just like - * the AT&T man page says. - * - * The node_t structure is for internal use only, lint doesn't grok it. - * - * Written by reading the System V Interface Definition, not the code. - * - * Totally public domain. - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/stdlib/tfind.c,v 1.5 2003/01/05 02:43:18 tjr Exp $"); - -#define _SEARCH_PRIVATE -#include -#include - -/* find a node, or return 0 */ -void * -tfind(vkey, vrootp, compar) - const void *vkey; /* key to be found */ - void * const *vrootp; /* address of the tree root */ - int (*compar)(const void *, const void *); -{ - node_t **rootp = (node_t **)vrootp; - - if (rootp == NULL) - return NULL; - - while (*rootp != NULL) { /* T1: */ - int r; - - if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ - return *rootp; /* key found */ - rootp = (r < 0) ? - &(*rootp)->llink : /* T3: follow left branch */ - &(*rootp)->rlink; /* T4: follow right branch */ - } - return NULL; -} diff --git a/stdlib/tfind-fbsd.c b/stdlib/tfind-fbsd.c new file mode 120000 index 0000000..a6149c5 --- /dev/null +++ b/stdlib/tfind-fbsd.c @@ -0,0 +1 @@ +./tfind.c \ No newline at end of file diff --git a/stdlib/tsearch-fbsd.c b/stdlib/tsearch-fbsd.c deleted file mode 100644 index edeccde..0000000 --- a/stdlib/tsearch-fbsd.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $NetBSD: tsearch.c,v 1.3 1999/09/16 11:45:37 lukem Exp $ */ - -/* - * Tree search generalized from Knuth (6.2.2) Algorithm T just like - * the AT&T man page says. - * - * The node_t structure is for internal use only, lint doesn't grok it. - * - * Written by reading the System V Interface Definition, not the code. - * - * Totally public domain. - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tsearch.c,v 1.3 1999/09/16 11:45:37 lukem Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/stdlib/tsearch.c,v 1.4 2003/01/05 02:43:18 tjr Exp $"); - -#define _SEARCH_PRIVATE -#include -#include - -/* find or insert datum into search tree */ -void * -tsearch(vkey, vrootp, compar) - const void *vkey; /* key to be located */ - void **vrootp; /* address of tree root */ - int (*compar)(const void *, const void *); -{ - node_t *q; - node_t **rootp = (node_t **)vrootp; - - if (rootp == NULL) - return NULL; - - while (*rootp != NULL) { /* Knuth's T1: */ - int r; - - if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ - return *rootp; /* we found it! */ - - rootp = (r < 0) ? - &(*rootp)->llink : /* T3: follow left branch */ - &(*rootp)->rlink; /* T4: follow right branch */ - } - - q = malloc(sizeof(node_t)); /* T5: key not found */ - if (q != 0) { /* make new node */ - *rootp = q; /* link new node to old */ - /* LINTED const castaway ok */ - q->key = (void *)vkey; /* initialize new node */ - q->llink = q->rlink = NULL; - } - return q; -} diff --git a/stdlib/tsearch-fbsd.c b/stdlib/tsearch-fbsd.c new file mode 120000 index 0000000..9a316ad --- /dev/null +++ b/stdlib/tsearch-fbsd.c @@ -0,0 +1 @@ +./tsearch.c \ No newline at end of file diff --git a/stdlib/twalk-fbsd.c b/stdlib/twalk-fbsd.c deleted file mode 100644 index 516ef44..0000000 --- a/stdlib/twalk-fbsd.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $ */ - -/* - * Tree search generalized from Knuth (6.2.2) Algorithm T just like - * the AT&T man page says. - * - * The node_t structure is for internal use only, lint doesn't grok it. - * - * Written by reading the System V Interface Definition, not the code. - * - * Totally public domain. - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/stdlib/twalk.c,v 1.5 2003/01/05 02:43:18 tjr Exp $"); - -#define _SEARCH_PRIVATE -#include -#include - -static void trecurse(const node_t *, - void (*action)(const void *, VISIT, int), int level); - -/* Walk the nodes of a tree */ -static void -trecurse(root, action, level) - const node_t *root; /* Root of the tree to be walked */ - void (*action)(const void *, VISIT, int); - int level; -{ - - if (root->llink == NULL && root->rlink == NULL) - (*action)(root, leaf, level); - else { - (*action)(root, preorder, level); - if (root->llink != NULL) - trecurse(root->llink, action, level + 1); - (*action)(root, postorder, level); - if (root->rlink != NULL) - trecurse(root->rlink, action, level + 1); - (*action)(root, endorder, level); - } -} - -/* Walk the nodes of a tree */ -void -twalk(vroot, action) - const void *vroot; /* Root of the tree to be walked */ - void (*action)(const void *, VISIT, int); -{ - if (vroot != NULL && action != NULL) - trecurse(vroot, action, 0); -} diff --git a/stdlib/twalk-fbsd.c b/stdlib/twalk-fbsd.c new file mode 120000 index 0000000..eef8457 --- /dev/null +++ b/stdlib/twalk-fbsd.c @@ -0,0 +1 @@ +./twalk.c \ No newline at end of file diff --git a/stdtime/FreeBSD/strptime.c.patch b/stdtime/FreeBSD/strptime.c.patch index 2c6acc5..3cbe4ff 100644 --- a/stdtime/FreeBSD/strptime.c.patch +++ b/stdtime/FreeBSD/strptime.c.patch @@ -1,6 +1,6 @@ ---- strptime.c.orig 2007-04-03 12:19:24.000000000 -0700 -+++ strptime.c 2007-04-03 12:39:20.000000000 -0700 -@@ -61,10 +61,13 @@ +--- strptime.c.orig 2008-04-24 01:10:36.000000000 -0700 ++++ strptime.c 2008-04-24 02:01:31.000000000 -0700 +@@ -61,10 +61,13 @@ static char sccsid[] __unused = "@(#)str #endif /* not lint */ __FBSDID("$FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.35 2003/11/17 04:19:15 nectar Exp $"); @@ -14,7 +14,7 @@ #include #include #include -@@ -72,30 +75,41 @@ +@@ -72,30 +75,41 @@ __FBSDID("$FreeBSD: src/lib/libc/stdtime #include "libc_private.h" #include "timelocal.h" @@ -63,7 +63,7 @@ buf++; else if (c != *buf++) return 0; -@@ -114,18 +128,18 @@ +@@ -114,18 +128,18 @@ label: break; case '+': @@ -85,7 +85,7 @@ i *= 10; i += *buf - '0'; len--; -@@ -133,17 +147,21 @@ +@@ -133,17 +147,21 @@ label: if (i < 19) return 0; @@ -109,7 +109,7 @@ if (buf == 0) return 0; break; -@@ -161,47 +179,55 @@ +@@ -161,47 +179,55 @@ label: goto label; case 'F': @@ -173,7 +173,7 @@ i *= 10; i += *buf - '0'; len--; -@@ -209,19 +235,19 @@ +@@ -209,19 +235,19 @@ label: if (i < 1 || i > 366) return 0; @@ -197,7 +197,7 @@ i *= 10; i += *buf - '0'; len--; -@@ -237,8 +263,8 @@ +@@ -237,8 +263,8 @@ label: tm->tm_sec = i; } @@ -208,7 +208,7 @@ ptr++; break; -@@ -254,11 +280,11 @@ +@@ -254,11 +280,11 @@ label: * XXX The %l specifier may gobble one too many * digits if used incorrectly. */ @@ -222,7 +222,7 @@ i *= 10; i += *buf - '0'; len--; -@@ -271,8 +297,8 @@ +@@ -271,8 +297,8 @@ label: tm->tm_hour = i; @@ -233,7 +233,7 @@ ptr++; break; -@@ -282,7 +308,7 @@ +@@ -282,7 +308,7 @@ label: * specifiers. */ len = strlen(tptr->am); @@ -242,7 +242,7 @@ if (tm->tm_hour > 12) return 0; if (tm->tm_hour == 12) -@@ -292,7 +318,7 @@ +@@ -292,7 +318,7 @@ label: } len = strlen(tptr->pm); @@ -251,7 +251,7 @@ if (tm->tm_hour > 12) return 0; if (tm->tm_hour != 12) -@@ -307,34 +333,28 @@ +@@ -307,34 +333,28 @@ label: case 'a': for (i = 0; i < asizeof(tptr->weekday); i++) { len = strlen(tptr->weekday[i]); @@ -295,7 +295,7 @@ i *= 10; i += *buf - '0'; len--; -@@ -342,23 +362,46 @@ +@@ -342,23 +362,46 @@ label: if (i > 53) return 0; @@ -352,7 +352,7 @@ ptr++; break; -@@ -372,11 +415,18 @@ +@@ -372,11 +415,18 @@ label: * XXX The %e specifier may gobble one too many * digits if used incorrectly. */ @@ -374,7 +374,7 @@ i *= 10; i += *buf - '0'; len--; -@@ -386,8 +436,8 @@ +@@ -386,8 +436,8 @@ label: tm->tm_mday = i; @@ -385,7 +385,7 @@ ptr++; break; -@@ -398,19 +448,19 @@ +@@ -398,19 +448,19 @@ label: if (Oalternative) { if (c == 'B') { len = strlen(tptr->alt_month[i]); @@ -411,7 +411,7 @@ break; } } -@@ -422,11 +472,11 @@ +@@ -422,11 +472,11 @@ label: break; case 'm': @@ -425,7 +425,7 @@ i *= 10; i += *buf - '0'; len--; -@@ -436,8 +486,8 @@ +@@ -436,8 +486,8 @@ label: tm->tm_mon = i - 1; @@ -436,7 +436,7 @@ ptr++; break; -@@ -450,7 +500,7 @@ +@@ -450,7 +500,7 @@ label: sverrno = errno; errno = 0; @@ -445,7 +445,7 @@ if (errno == ERANGE || (long)(t = n) != n) { errno = sverrno; return 0; -@@ -458,24 +508,37 @@ +@@ -458,24 +508,37 @@ label: errno = sverrno; buf = cp; gmtime_r(&t, tm); @@ -487,7 +487,7 @@ if (c == 'Y') i -= 1900; if (c == 'y' && i < 69) -@@ -483,10 +546,10 @@ +@@ -483,35 +546,58 @@ label: if (i < 0) return 0; @@ -501,19 +501,49 @@ ptr++; break; -@@ -502,7 +565,7 @@ - zonestr[cp - buf] = '\0'; - tzset(); - if (0 == strcmp(zonestr, "GMT")) { + case 'Z': + { + const char *cp; +- char *zonestr; ++ size_t tzlen, len; + + for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) {/*empty*/} +- if (cp - buf) { +- zonestr = alloca(cp - buf + 1); +- strncpy(zonestr, buf, cp - buf); +- zonestr[cp - buf] = '\0'; +- tzset(); +- if (0 == strcmp(zonestr, "GMT")) { - *GMTp = 1; -+ *convp = CONVERT_GMT; - } else if (0 == strcmp(zonestr, tzname[0])) { - tm->tm_isdst = 0; - } else if (0 == strcmp(zonestr, tzname[1])) { -@@ -514,6 +577,26 @@ +- } else if (0 == strcmp(zonestr, tzname[0])) { +- tm->tm_isdst = 0; +- } else if (0 == strcmp(zonestr, tzname[1])) { +- tm->tm_isdst = 1; +- } else { +- return 0; +- } +- buf += cp - buf; ++ len = cp - buf; ++ if (len == 3 && strncmp(buf, "GMT", 3) == 0) { ++ *convp = CONVERT_GMT; ++ buf += len; ++ break; } - } - break; ++ tzset(); ++ tzlen = strlen(tzname[0]); ++ if (len == tzlen && strncmp(buf, tzname[0], tzlen) == 0) { ++ tm->tm_isdst = 0; ++ buf += len; ++ break; ++ } ++ tzlen = strlen(tzname[1]); ++ if (len == tzlen && strncmp(buf, tzname[1], tzlen) == 0) { ++ tm->tm_isdst = 1; ++ buf += len; ++ break; ++ } ++ return 0; ++ } + + case 'z': + { @@ -532,12 +562,10 @@ + if (sign == '-') + tm->tm_gmtoff = -tm->tm_gmtoff; + buf += 5; -+ } -+ break; + } + break; } - } - return (char *)buf; -@@ -524,14 +607,39 @@ +@@ -524,14 +610,39 @@ char * strptime(const char * __restrict buf, const char * __restrict fmt, struct tm * __restrict tm) { diff --git a/stdtime/FreeBSD/tzfile.h.patch b/stdtime/FreeBSD/tzfile.h.patch new file mode 100644 index 0000000..4ff5d4b --- /dev/null +++ b/stdtime/FreeBSD/tzfile.h.patch @@ -0,0 +1,14 @@ +--- tzfile.h.orig 2008-03-15 10:50:45.000000000 -0700 ++++ tzfile.h 2008-03-29 11:45:13.000000000 -0700 +@@ -38,7 +38,11 @@ + #endif /* !defined TZDIR */ + + #ifndef TZDEFAULT ++#ifdef UNIFDEF_MOVE_LOCALTIME ++#define TZDEFAULT "/var/db/timezone/localtime" ++#else /* !UNIFDEF_MOVE_LOCALTIME */ + #define TZDEFAULT "/etc/localtime" ++#endif /* UNIFDEF_MOVE_LOCALTIME */ + #endif /* !defined TZDEFAULT */ + + #ifndef TZDEFRULES diff --git a/stdtime/Makefile.inc b/stdtime/Makefile.inc index bb3a497..619863b 100644 --- a/stdtime/Makefile.inc +++ b/stdtime/Makefile.inc @@ -1,12 +1,11 @@ # Makefile.inc,v 1.2 1994/09/13 21:26:01 wollman Exp # $FreeBSD: src/lib/libc/stdtime/Makefile.inc,v 1.14 2002/11/18 09:50:56 ru Exp $ -.PATH: ${.CURDIR}/stdtime +.PATH: ${.CURDIR}/stdtime +CWD := ${.CURDIR}/stdtime CFLAGS += -I${.CURDIR}/stdtime -CFLAGS-localtime-fbsd.c += -DNOTIFY_TZ - LEGACYSRCS += localtime.c strftime.c strptime.c MISRCS += getdate.c timezone_unix03.c diff --git a/stdtime/difftime-fbsd.c b/stdtime/difftime-fbsd.c deleted file mode 100644 index df55753..0000000 --- a/stdtime/difftime-fbsd.c +++ /dev/null @@ -1,87 +0,0 @@ -/* -** This file is in the public domain, so clarified as of -** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). -*/ - -#include -#ifndef lint -#ifndef NOID -static char elsieid[] __unused = "@(#)difftime.c 7.9"; -#endif /* !defined NOID */ -#endif /* !defined lint */ -__FBSDID("$FreeBSD: src/lib/libc/stdtime/difftime.c,v 1.8 2004/06/14 10:31:52 stefanf Exp $"); - -/*LINTLIBRARY*/ - -#include "namespace.h" -#include "private.h" -#include "un-namespace.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; - - { - time_t tt; - double d; - long_double ld; - - if (sizeof tt < sizeof d) - return (double) time1 - (double) time0; - if (sizeof tt < sizeof ld) - 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/stdtime/difftime-fbsd.c b/stdtime/difftime-fbsd.c new file mode 120000 index 0000000..64af329 --- /dev/null +++ b/stdtime/difftime-fbsd.c @@ -0,0 +1 @@ +./difftime.c \ No newline at end of file diff --git a/stdtime/ftime-fbsd.c b/stdtime/ftime-fbsd.c deleted file mode 100644 index 6bb3f03..0000000 --- a/stdtime/ftime-fbsd.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * 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 Christopher G. Demetriou. - * 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. - */ - -#ifndef lint -static char rcsid[] = "$FreeBSD: /repoman/r/ncvs/src/lib/libcompat/4.1/ftime.c,v 1.5 1999/08/28 00:04:12 peter Exp $"; -#endif /* not lint */ - -#include -#include -#include - -int -ftime(tbp) - struct timeb *tbp; -{ - struct timezone tz; - struct timeval t; - - if (gettimeofday(&t, &tz) < 0) - return (-1); - tbp->millitm = t.tv_usec / 1000; - tbp->time = t.tv_sec; - tbp->timezone = tz.tz_minuteswest; - tbp->dstflag = tz.tz_dsttime; - - return (0); -} diff --git a/stdtime/ftime-fbsd.c b/stdtime/ftime-fbsd.c new file mode 120000 index 0000000..cdda967 --- /dev/null +++ b/stdtime/ftime-fbsd.c @@ -0,0 +1 @@ +./ftime.c \ No newline at end of file diff --git a/stdtime/private.h b/stdtime/private.h deleted file mode 100644 index 9878a1a..0000000 --- a/stdtime/private.h +++ /dev/null @@ -1,260 +0,0 @@ -#ifndef PRIVATE_H - -#define PRIVATE_H - -/* -** This file is in the public domain, so clarified as of -** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). -** -** $FreeBSD: src/lib/libc/stdtime/private.h,v 1.10 2004/06/14 10:31:52 stefanf Exp $ -*/ - -/* 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.53"; -*/ -#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_INCOMPATIBLE_CTIME_R -#define HAVE_INCOMPATIBLE_CTIME_R 0 -#endif /* !defined INCOMPATIBLE_CTIME_R */ - -#ifndef HAVE_SETTIMEOFDAY -#define HAVE_SETTIMEOFDAY 3 -#endif /* !defined HAVE_SETTIMEOFDAY */ - -#ifndef HAVE_STRERROR -#define HAVE_STRERROR 1 -#endif /* !defined HAVE_STRERROR */ - -#ifndef HAVE_SYMLINK -#define HAVE_SYMLINK 1 -#endif /* !defined HAVE_SYMLINK */ - -#ifndef HAVE_SYS_STAT_H -#define HAVE_SYS_STAT_H 1 -#endif /* !defined HAVE_SYS_STAT_H */ - -#ifndef HAVE_SYS_WAIT_H -#define HAVE_SYS_WAIT_H 1 -#endif /* !defined HAVE_SYS_WAIT_H */ - -#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 */ - -#if HAVE_INCOMPATIBLE_CTIME_R -#define asctime_r _incompatible_asctime_r -#define ctime_r _incompatible_ctime_r -#endif /* HAVE_INCOMPATIBLE_CTIME_R */ - -/* -** 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_SYS_WAIT_H - 0 -#include /* for WIFEXITED and WEXITSTATUS */ -#endif /* HAVE_SYS_WAIT_H - 0 */ - -#ifndef WIFEXITED -#define WIFEXITED(status) (((status) & 0xff) == 0) -#endif /* !defined WIFEXITED */ -#ifndef WEXITSTATUS -#define WEXITSTATUS(status) (((status) >> 8) & 0xff) -#endif /* !defined WEXITSTATUS */ - -#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 's isdigit, this also works if c < 0 | c > UCHAR_MAX. */ -#define is_digit(c) ((unsigned)(c) - '0' <= 9) - -/* -** 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 */ - -/* -** Private function declarations. -*/ -char * icalloc(int nelem, int elsize); -char * icatalloc(char * old, const char * new); -char * icpyalloc(const char * string); -char * imalloc(int n); -void * irealloc(void * pointer, int size); -void icfree(char * pointer); -void ifree(char * pointer); -char * scheck(const char *string, const char *format); - - -/* -** 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 / 1000 + 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 */ - -#if HAVE_INCOMPATIBLE_CTIME_R -#undef asctime_r -#undef ctime_r -char *asctime_r(struct tm const *, char *); -char *ctime_r(time_t const *, char *); -#endif /* HAVE_INCOMPATIBLE_CTIME_R */ - -/* -** UNIX was a registered trademark of The Open Group in 2003. -*/ - -#endif /* !defined PRIVATE_H */ diff --git a/stdtime/private.h b/stdtime/private.h new file mode 120000 index 0000000..af6f8e0 --- /dev/null +++ b/stdtime/private.h @@ -0,0 +1 @@ +./private.h \ No newline at end of file diff --git a/stdtime/strptime-fbsd.c b/stdtime/strptime-fbsd.c index 064ddca..e2d4395 100644 --- a/stdtime/strptime-fbsd.c +++ b/stdtime/strptime-fbsd.c @@ -556,27 +556,30 @@ label: case 'Z': { const char *cp; - char *zonestr; + size_t tzlen, len; for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) {/*empty*/} - if (cp - buf) { - zonestr = alloca(cp - buf + 1); - strncpy(zonestr, buf, cp - buf); - zonestr[cp - buf] = '\0'; - tzset(); - if (0 == strcmp(zonestr, "GMT")) { - *convp = CONVERT_GMT; - } else if (0 == strcmp(zonestr, tzname[0])) { - tm->tm_isdst = 0; - } else if (0 == strcmp(zonestr, tzname[1])) { - tm->tm_isdst = 1; - } else { - return 0; - } - buf += cp - buf; + len = cp - buf; + if (len == 3 && strncmp(buf, "GMT", 3) == 0) { + *convp = CONVERT_GMT; + buf += len; + break; + } + tzset(); + tzlen = strlen(tzname[0]); + if (len == tzlen && strncmp(buf, tzname[0], tzlen) == 0) { + tm->tm_isdst = 0; + buf += len; + break; + } + tzlen = strlen(tzname[1]); + if (len == tzlen && strncmp(buf, tzname[1], tzlen) == 0) { + tm->tm_isdst = 1; + buf += len; + break; } + return 0; } - break; case 'z': { diff --git a/stdtime/time32-fbsd.c b/stdtime/time32-fbsd.c deleted file mode 100644 index 5085dd7..0000000 --- a/stdtime/time32-fbsd.c +++ /dev/null @@ -1,100 +0,0 @@ -/*- - * Copyright (c) 2001 FreeBSD Inc. - * All rights reserved. - * - * These routines are for converting time_t to fixed-bit representations - * for use in protocols or storage. When converting time to a larger - * representation of time_t these routines are expected to assume temporal - * locality and use the 50-year rule to properly set the msb bits. XXX - * - * Redistribution and use under the terms of the COPYRIGHT file at the - * base of the source tree. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/stdtime/time32.c,v 1.5 2002/06/17 01:42:29 wollman Exp $"); - -#include -#include - -/* - * Convert a 32 bit representation of time_t into time_t. XXX needs to - * implement the 50-year rule to handle post-2038 conversions. - */ -time_t -_time32_to_time(__int32_t t32) -{ - return((time_t)t32); -} - -/* - * Convert time_t to a 32 bit representation. If time_t is 64 bits we can - * simply chop it down. The resulting 32 bit representation can be - * converted back to a temporally local 64 bit time_t using time32_to_time. - */ -__int32_t -_time_to_time32(time_t t) -{ - return((__int32_t)t); -} - -/* - * Convert a 64 bit representation of time_t into time_t. If time_t is - * represented as 32 bits we can simply chop it and not support times - * past 2038. - */ -time_t -_time64_to_time(__int64_t t64) -{ - return((time_t)t64); -} - -/* - * Convert time_t to a 64 bit representation. If time_t is represented - * as 32 bits we simply sign-extend and do not support times past 2038. - */ -__int64_t -_time_to_time64(time_t t) -{ - return((__int64_t)t); -} - -/* - * Convert to/from 'long'. Depending on the sizeof(long) this may or - * may not require using the 50-year rule. - */ -long -_time_to_long(time_t t) -{ - if (sizeof(long) == sizeof(__int64_t)) - return(_time_to_time64(t)); - return((long)t); -} - -time_t -_long_to_time(long tlong) -{ - if (sizeof(long) == sizeof(__int32_t)) - return(_time32_to_time(tlong)); - return((time_t)tlong); -} - -/* - * Convert to/from 'int'. Depending on the sizeof(int) this may or - * may not require using the 50-year rule. - */ -int -_time_to_int(time_t t) -{ - if (sizeof(int) == sizeof(__int64_t)) - return(_time_to_time64(t)); - return((int)t); -} - -time_t -_int_to_time(int tint) -{ - if (sizeof(int) == sizeof(__int32_t)) - return(_time32_to_time(tint)); - return((time_t)tint); -} diff --git a/stdtime/time32-fbsd.c b/stdtime/time32-fbsd.c new file mode 120000 index 0000000..80a48d1 --- /dev/null +++ b/stdtime/time32-fbsd.c @@ -0,0 +1 @@ +./time32.c \ No newline at end of file diff --git a/stdtime/tzfile.h b/stdtime/tzfile.h index 378d7ae..9ca2f63 100644 --- a/stdtime/tzfile.h +++ b/stdtime/tzfile.h @@ -38,7 +38,11 @@ static char tzfilehid[] = "@(#)tzfile.h 7.14"; #endif /* !defined TZDIR */ #ifndef TZDEFAULT +#ifdef UNIFDEF_MOVE_LOCALTIME +#define TZDEFAULT "/var/db/timezone/localtime" +#else /* !UNIFDEF_MOVE_LOCALTIME */ #define TZDEFAULT "/etc/localtime" +#endif /* UNIFDEF_MOVE_LOCALTIME */ #endif /* !defined TZDEFAULT */ #ifndef TZDEFRULES diff --git a/string/Makefile.inc b/string/Makefile.inc index 14ce753..e037f52 100644 --- a/string/Makefile.inc +++ b/string/Makefile.inc @@ -1,14 +1,11 @@ # @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 # $FreeBSD: src/lib/libc/string/Makefile.inc,v 1.32 2002/11/18 09:50:56 ru Exp $ -.ifnmake autopatch # machine-dependent string sources -.if exists(${.CURDIR}/${MACHINE_ARCH}/string/Makefile.inc) -.include "${.CURDIR}/${MACHINE_ARCH}/string/Makefile.inc" -.endif -.endif # !autopatch +.sinclude "${.CURDIR}/${MACHINE_ARCH}/string/Makefile.inc" .PATH: ${.CURDIR}/string +CWD := ${.CURDIR}/string CFLAGS+= -I${.CURDIR}/locale diff --git a/string/bcmp-fbsd.c b/string/bcmp-fbsd.c deleted file mode 100644 index f5227df..0000000 --- a/string/bcmp-fbsd.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 1987, 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[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/bcmp.c,v 1.5 2002/08/30 21:07:40 robert Exp $"); - -#include - -/* - * bcmp -- vax cmpc3 instruction - */ -int -bcmp(const void *b1, const void *b2, size_t length) -{ - char *p1, *p2; - - if (length == 0) - return (0); - p1 = (char *)b1; - p2 = (char *)b2; - do - if (*p1++ != *p2++) - break; - while (--length); - return (length); -} diff --git a/string/bcmp-fbsd.c b/string/bcmp-fbsd.c new file mode 120000 index 0000000..354ed88 --- /dev/null +++ b/string/bcmp-fbsd.c @@ -0,0 +1 @@ +./bcmp.c \ No newline at end of file diff --git a/string/index-fbsd.c b/string/index-fbsd.c deleted file mode 100644 index be2c052..0000000 --- a/string/index-fbsd.c +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)index.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/index.c,v 1.7 2003/12/18 07:44:53 jkh Exp $"); - -#include - -#ifdef STRCHR -#include - -char * -strchr -#else -#include - -char * -index -#endif -(const char *p, int ch) -{ - char c; - - c = ch; - for (;; ++p) { - if (*p == c) - return ((char *)p); - if (*p == '\0') - return (NULL); - } - /* NOTREACHED */ -} diff --git a/string/index-fbsd.c b/string/index-fbsd.c new file mode 120000 index 0000000..d789f40 --- /dev/null +++ b/string/index-fbsd.c @@ -0,0 +1 @@ +./index.c \ No newline at end of file diff --git a/string/memccpy-fbsd.c b/string/memccpy-fbsd.c deleted file mode 100644 index 0bc6a11..0000000 --- a/string/memccpy-fbsd.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/memccpy.c,v 1.5 2002/03/21 18:44:54 obrien Exp $"); - -#include - -void * -memccpy(t, f, c, n) - void *t; - const void *f; - int c; - size_t n; -{ - - if (n) { - unsigned char *tp = t; - const unsigned char *fp = f; - unsigned char uc = c; - do { - if ((*tp++ = *fp++) == uc) - return (tp); - } while (--n != 0); - } - return (0); -} diff --git a/string/memccpy-fbsd.c b/string/memccpy-fbsd.c new file mode 120000 index 0000000..44404f4 --- /dev/null +++ b/string/memccpy-fbsd.c @@ -0,0 +1 @@ +./memccpy.c \ No newline at end of file diff --git a/string/memchr-fbsd.c b/string/memchr-fbsd.c deleted file mode 100644 index e3c6679..0000000 --- a/string/memchr-fbsd.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)memchr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/memchr.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); - -#include - -void * -memchr(s, c, n) - const void *s; - unsigned char c; - size_t n; -{ - if (n != 0) { - const unsigned char *p = s; - - do { - if (*p++ == c) - return ((void *)(p - 1)); - } while (--n != 0); - } - return (NULL); -} diff --git a/string/memchr-fbsd.c b/string/memchr-fbsd.c new file mode 120000 index 0000000..c6fcee6 --- /dev/null +++ b/string/memchr-fbsd.c @@ -0,0 +1 @@ +./memchr.c \ No newline at end of file diff --git a/string/memcmp-fbsd.c b/string/memcmp-fbsd.c deleted file mode 100644 index 045e4d9..0000000 --- a/string/memcmp-fbsd.c +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)memcmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/memcmp.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); - -#include - -/* - * Compare memory regions. - */ -int -memcmp(s1, s2, n) - const void *s1, *s2; - size_t n; -{ - if (n != 0) { - const unsigned char *p1 = s1, *p2 = s2; - - do { - if (*p1++ != *p2++) - return (*--p1 - *--p2); - } while (--n != 0); - } - return (0); -} diff --git a/string/memcmp-fbsd.c b/string/memcmp-fbsd.c new file mode 120000 index 0000000..d50831d --- /dev/null +++ b/string/memcmp-fbsd.c @@ -0,0 +1 @@ +./memcmp.c \ No newline at end of file diff --git a/string/memset-fbsd.c b/string/memset-fbsd.c deleted file mode 100644 index 1cb8644..0000000 --- a/string/memset-fbsd.c +++ /dev/null @@ -1,132 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Hibler and Chris Torek. - * - * 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[] = "@(#)memset.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/memset.c,v 1.8 2002/09/01 21:53:46 robert Exp $"); - -#include - -#include - -#define wsize sizeof(u_int) -#define wmask (wsize - 1) - -#ifdef BZERO -#include - -#define RETURN return -#define VAL 0 -#define WIDEVAL 0 - -void -bzero(void *dst0, size_t length) -#else -#include - -#define RETURN return (dst0) -#define VAL c0 -#define WIDEVAL c - -void * -memset(void *dst0, int c0, size_t length) -#endif -{ - size_t t; -#ifndef BZERO - u_int c; -#endif - u_char *dst; - - dst = dst0; - /* - * If not enough words, just fill bytes. A length >= 2 words - * guarantees that at least one of them is `complete' after - * any necessary alignment. For instance: - * - * |-----------|-----------|-----------| - * |00|01|02|03|04|05|06|07|08|09|0A|00| - * ^---------------------^ - * dst dst+length-1 - * - * 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; - --length; - } - RETURN; - } - -#ifndef BZERO - if ((c = (u_char)c0) != 0) { /* Fill the word. */ - c = (c << 8) | c; /* u_int is 16 bits. */ -#if UINT_MAX > 0xffff - c = (c << 16) | c; /* u_int is 32 bits. */ -#endif -#if UINT_MAX > 0xffffffff - c = (c << 32) | c; /* u_int is 64 bits. */ -#endif - } -#endif - /* Align destination by filling in bytes. */ - if ((t = (long)dst & wmask) != 0) { - t = wsize - t; - length -= t; - do { - *dst++ = VAL; - } while (--t != 0); - } - - /* Fill words. Length was >= 2*words so we know t >= 1 here. */ - t = length / wsize; - do { - *(u_int *)dst = WIDEVAL; - dst += wsize; - } while (--t != 0); - - /* Mop up trailing bytes, if any. */ - t = length & wmask; - if (t != 0) - do { - *dst++ = VAL; - } while (--t != 0); - RETURN; -} diff --git a/string/memset-fbsd.c b/string/memset-fbsd.c new file mode 120000 index 0000000..0ea82de --- /dev/null +++ b/string/memset-fbsd.c @@ -0,0 +1 @@ +./memset.c \ No newline at end of file diff --git a/string/rindex-fbsd.c b/string/rindex-fbsd.c deleted file mode 100644 index 697b69a..0000000 --- a/string/rindex-fbsd.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rindex.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/rindex.c,v 1.7 2003/12/18 07:44:53 jkh Exp $"); - -#include - -#ifdef STRRCHR -#include - -char * -strrchr -#else -#include - -char * -rindex -#endif -(const char *p, int ch) -{ - char *save; - char c; - - c = ch; - for (save = NULL;; ++p) { - if (*p == c) - save = (char *)p; - if (*p == '\0') - return (save); - } - /* NOTREACHED */ -} diff --git a/string/rindex-fbsd.c b/string/rindex-fbsd.c new file mode 120000 index 0000000..648088c --- /dev/null +++ b/string/rindex-fbsd.c @@ -0,0 +1 @@ +./rindex.c \ No newline at end of file diff --git a/string/stpcpy-fbsd.c b/string/stpcpy-fbsd.c deleted file mode 100644 index 2742bf7..0000000 --- a/string/stpcpy-fbsd.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 1999 - * David E. O'Brien - * 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. 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[] = "@(#)strcpy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/stpcpy.c,v 1.1 2002/10/03 19:39:20 obrien Exp $"); - -#include - -char * -stpcpy(char * to, const char * from) -{ - - for (; (*to = *from); ++from, ++to); - return(to); -} diff --git a/string/stpcpy-fbsd.c b/string/stpcpy-fbsd.c new file mode 120000 index 0000000..64749ca --- /dev/null +++ b/string/stpcpy-fbsd.c @@ -0,0 +1 @@ +./stpcpy.c \ No newline at end of file diff --git a/string/strcat-fbsd.c b/string/strcat-fbsd.c deleted file mode 100644 index 5d28c86..0000000 --- a/string/strcat-fbsd.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcat.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strcat.c,v 1.7 2002/09/06 11:24:06 tjr Exp $"); - -#include - -char * -strcat(char * __restrict s, const char * __restrict append) -{ - char *save = s; - - for (; *s; ++s); - while ((*s++ = *append++)); - return(save); -} diff --git a/string/strcat-fbsd.c b/string/strcat-fbsd.c new file mode 120000 index 0000000..6dc4b61 --- /dev/null +++ b/string/strcat-fbsd.c @@ -0,0 +1 @@ +./strcat.c \ No newline at end of file diff --git a/string/strcpy-fbsd.c b/string/strcpy-fbsd.c deleted file mode 100644 index 5cd2f45..0000000 --- a/string/strcpy-fbsd.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcpy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strcpy.c,v 1.7 2002/09/06 11:24:06 tjr Exp $"); - -#include - -char * -strcpy(char * __restrict to, const char * __restrict from) -{ - char *save = to; - - for (; (*to = *from); ++from, ++to); - return(save); -} diff --git a/string/strcpy-fbsd.c b/string/strcpy-fbsd.c new file mode 120000 index 0000000..39cf6f7 --- /dev/null +++ b/string/strcpy-fbsd.c @@ -0,0 +1 @@ +./strcpy.c \ No newline at end of file diff --git a/string/strcspn-fbsd.c b/string/strcspn-fbsd.c deleted file mode 100644 index 55acb8b..0000000 --- a/string/strcspn-fbsd.c +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * Copyright (c) 2005 David Schultz - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strcspn.c,v 1.5 2005/04/02 18:52:44 das Exp $"); - -#include -#include -#include - -#define IDX(c) ((u_char)(c) / LONG_BIT) -#define BIT(c) ((u_long)1 << ((u_char)(c) % LONG_BIT)) - -size_t -strcspn(const char *s, const char *charset) -{ - /* - * NB: idx and bit are temporaries whose use causes gcc 3.4.2 to - * generate better code. Without them, gcc gets a little confused. - */ - const char *s1; - u_long bit; - u_long tbl[(UCHAR_MAX + 1) / LONG_BIT]; - int idx; - - if(*s == '\0') - return (0); - -#if LONG_BIT == 64 /* always better to unroll on 64-bit architectures */ - tbl[0] = 1; - tbl[3] = tbl[2] = tbl[1] = 0; -#else - for (tbl[0] = idx = 1; idx < sizeof(tbl) / sizeof(tbl[0]); idx++) - tbl[idx] = 0; -#endif - for (; *charset != '\0'; charset++) { - idx = IDX(*charset); - bit = BIT(*charset); - tbl[idx] |= bit; - } - - for(s1 = s; ; s1++) { - idx = IDX(*s1); - bit = BIT(*s1); - if ((tbl[idx] & bit) != 0) - break; - } - return (s1 - s); -} diff --git a/string/strcspn-fbsd.c b/string/strcspn-fbsd.c new file mode 120000 index 0000000..c86ab8c --- /dev/null +++ b/string/strcspn-fbsd.c @@ -0,0 +1 @@ +./strcspn.c \ No newline at end of file diff --git a/string/strdup-fbsd.c b/string/strdup-fbsd.c deleted file mode 100644 index a9881a1..0000000 --- a/string/strdup-fbsd.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strdup.c,v 1.4 2001/11/07 19:55:16 obrien Exp $"); - -#include -#include -#include - -char * -strdup(str) - const char *str; -{ - size_t len; - char *copy; - - len = strlen(str) + 1; - if ((copy = malloc(len)) == NULL) - return (NULL); - memcpy(copy, str, len); - return (copy); -} diff --git a/string/strdup-fbsd.c b/string/strdup-fbsd.c new file mode 120000 index 0000000..e2aeecc --- /dev/null +++ b/string/strdup-fbsd.c @@ -0,0 +1 @@ +./strdup.c \ No newline at end of file diff --git a/string/strlcat-fbsd.c b/string/strlcat-fbsd.c deleted file mode 100644 index b8f0ff3..0000000 --- a/string/strlcat-fbsd.c +++ /dev/null @@ -1,75 +0,0 @@ -/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * 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 ``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 = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strlcat.c,v 1.10 2004/10/16 06:32:43 obrien Exp $"); - -#include -#include - -/* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. - */ -size_t -strlcat(dst, src, siz) - char *dst; - const char *src; - size_t siz; -{ - char *d = dst; - const char *s = src; - size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} diff --git a/string/strlcat-fbsd.c b/string/strlcat-fbsd.c new file mode 120000 index 0000000..8828d3f --- /dev/null +++ b/string/strlcat-fbsd.c @@ -0,0 +1 @@ +./strlcat.c \ No newline at end of file diff --git a/string/strlcpy-fbsd.c b/string/strlcpy-fbsd.c deleted file mode 100644 index 9383236..0000000 --- a/string/strlcpy-fbsd.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * 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 ``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 = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.8 2004/10/14 21:31:42 stefanf Exp $"); - -#include -#include - -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -size_t strlcpy(dst, src, siz) - char *dst; - const char *src; - size_t siz; -{ - char *d = dst; - const char *s = src; - size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) - break; - } while (--n != 0); - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} diff --git a/string/strlcpy-fbsd.c b/string/strlcpy-fbsd.c new file mode 120000 index 0000000..f63c48d --- /dev/null +++ b/string/strlcpy-fbsd.c @@ -0,0 +1 @@ +./strlcpy.c \ No newline at end of file diff --git a/string/strlen-fbsd.c b/string/strlen-fbsd.c deleted file mode 100644 index c67667d..0000000 --- a/string/strlen-fbsd.c +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strlen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strlen.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); - -#include - -size_t -strlen(str) - const char *str; -{ - const char *s; - - for (s = str; *s; ++s); - return(s - str); -} - diff --git a/string/strlen-fbsd.c b/string/strlen-fbsd.c new file mode 120000 index 0000000..2261013 --- /dev/null +++ b/string/strlen-fbsd.c @@ -0,0 +1 @@ +./strlen.c \ No newline at end of file diff --git a/string/strmode-fbsd.c b/string/strmode-fbsd.c deleted file mode 100644 index 2409b4e..0000000 --- a/string/strmode-fbsd.c +++ /dev/null @@ -1,154 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strmode.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); - -#include -#include -#include - -void -strmode(mode, p) - mode_t mode; - char *p; -{ - /* print type */ - switch (mode & S_IFMT) { - case S_IFDIR: /* directory */ - *p++ = 'd'; - break; - case S_IFCHR: /* character special */ - *p++ = 'c'; - break; - case S_IFBLK: /* block special */ - *p++ = 'b'; - break; - case S_IFREG: /* regular */ - *p++ = '-'; - break; - case S_IFLNK: /* symbolic link */ - *p++ = 'l'; - break; - case S_IFSOCK: /* socket */ - *p++ = 's'; - break; -#ifdef S_IFIFO - case S_IFIFO: /* fifo */ - *p++ = 'p'; - break; -#endif -#ifdef S_IFWHT - case S_IFWHT: /* whiteout */ - *p++ = 'w'; - break; -#endif - default: /* unknown */ - *p++ = '?'; - break; - } - /* usr */ - if (mode & S_IRUSR) - *p++ = 'r'; - else - *p++ = '-'; - if (mode & S_IWUSR) - *p++ = 'w'; - else - *p++ = '-'; - switch (mode & (S_IXUSR | S_ISUID)) { - case 0: - *p++ = '-'; - break; - case S_IXUSR: - *p++ = 'x'; - break; - case S_ISUID: - *p++ = 'S'; - break; - case S_IXUSR | S_ISUID: - *p++ = 's'; - break; - } - /* group */ - if (mode & S_IRGRP) - *p++ = 'r'; - else - *p++ = '-'; - if (mode & S_IWGRP) - *p++ = 'w'; - else - *p++ = '-'; - switch (mode & (S_IXGRP | S_ISGID)) { - case 0: - *p++ = '-'; - break; - case S_IXGRP: - *p++ = 'x'; - break; - case S_ISGID: - *p++ = 'S'; - break; - case S_IXGRP | S_ISGID: - *p++ = 's'; - break; - } - /* other */ - if (mode & S_IROTH) - *p++ = 'r'; - else - *p++ = '-'; - if (mode & S_IWOTH) - *p++ = 'w'; - else - *p++ = '-'; - switch (mode & (S_IXOTH | S_ISVTX)) { - case 0: - *p++ = '-'; - break; - case S_IXOTH: - *p++ = 'x'; - break; - case S_ISVTX: - *p++ = 'T'; - break; - case S_IXOTH | S_ISVTX: - *p++ = 't'; - break; - } - *p++ = ' '; /* will be a '+' if ACL's implemented */ - *p = '\0'; -} diff --git a/string/strmode-fbsd.c b/string/strmode-fbsd.c new file mode 120000 index 0000000..baa76fd --- /dev/null +++ b/string/strmode-fbsd.c @@ -0,0 +1 @@ +./strmode.c \ No newline at end of file diff --git a/string/strncat-fbsd.c b/string/strncat-fbsd.c deleted file mode 100644 index e05e030..0000000 --- a/string/strncat-fbsd.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)strncat.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strncat.c,v 1.6 2002/09/06 11:24:06 tjr Exp $"); - -#include - -/* - * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes - * are written at dst (at most n+1 bytes being appended). Return dst. - */ -char * -strncat(char * __restrict dst, const char * __restrict src, size_t n) -{ - if (n != 0) { - char *d = dst; - const char *s = src; - - while (*d != 0) - d++; - do { - if ((*d = *s++) == 0) - break; - d++; - } while (--n != 0); - *d = 0; - } - return (dst); -} diff --git a/string/strncat-fbsd.c b/string/strncat-fbsd.c new file mode 120000 index 0000000..b375d5e --- /dev/null +++ b/string/strncat-fbsd.c @@ -0,0 +1 @@ +./strncat.c \ No newline at end of file diff --git a/string/strncmp-fbsd.c b/string/strncmp-fbsd.c deleted file mode 100644 index 6b0cfc8..0000000 --- a/string/strncmp-fbsd.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strncmp.c,v 1.5 2002/03/21 18:44:54 obrien Exp $"); - -#include - -int -strncmp(s1, s2, n) - const char *s1, *s2; - size_t n; -{ - - if (n == 0) - return (0); - do { - if (*s1 != *s2++) - return (*(const unsigned char *)s1 - - *(const unsigned char *)(s2 - 1)); - if (*s1++ == 0) - break; - } while (--n != 0); - return (0); -} diff --git a/string/strncmp-fbsd.c b/string/strncmp-fbsd.c new file mode 120000 index 0000000..7816922 --- /dev/null +++ b/string/strncmp-fbsd.c @@ -0,0 +1 @@ +./strncmp.c \ No newline at end of file diff --git a/string/strncpy-fbsd.c b/string/strncpy-fbsd.c deleted file mode 100644 index 2fcc957..0000000 --- a/string/strncpy-fbsd.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strncpy.c,v 1.6 2002/09/06 11:24:06 tjr Exp $"); - -#include - -/* - * Copy src to dst, truncating or null-padding to always copy n bytes. - * Return dst. - */ -char * -strncpy(char * __restrict dst, const char * __restrict src, size_t n) -{ - if (n != 0) { - char *d = dst; - const char *s = src; - - do { - if ((*d++ = *s++) == 0) { - /* NUL pad the remaining n-1 bytes */ - while (--n != 0) - *d++ = 0; - break; - } - } while (--n != 0); - } - return (dst); -} diff --git a/string/strncpy-fbsd.c b/string/strncpy-fbsd.c new file mode 120000 index 0000000..1b81656 --- /dev/null +++ b/string/strncpy-fbsd.c @@ -0,0 +1 @@ +./strncpy.c \ No newline at end of file diff --git a/string/strnstr-fbsd.c b/string/strnstr-fbsd.c deleted file mode 100644 index abe2f8d..0000000 --- a/string/strnstr-fbsd.c +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * Copyright (c) 2001 Mike Barcroft - * 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. - * - * 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[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strnstr.c,v 1.3 2005/02/11 21:07:51 pjd Exp $"); - -#include - -/* - * Find the first occurrence of find in s, where the search is limited to the - * first slen characters of s. - */ -char * -strnstr(s, find, slen) - const char *s; - const char *find; - size_t slen; -{ - char c, sc; - size_t len; - - if ((c = *find++) != '\0') { - len = strlen(find); - do { - do { - if (slen-- < 1 || (sc = *s++) == '\0') - return (NULL); - } while (sc != c); - if (len > slen) - return (NULL); - } while (strncmp(s, find, len) != 0); - s--; - } - return ((char *)s); -} diff --git a/string/strnstr-fbsd.c b/string/strnstr-fbsd.c new file mode 120000 index 0000000..98aea3e --- /dev/null +++ b/string/strnstr-fbsd.c @@ -0,0 +1 @@ +./strnstr.c \ No newline at end of file diff --git a/string/strpbrk-fbsd.c b/string/strpbrk-fbsd.c deleted file mode 100644 index fb0e1d4..0000000 --- a/string/strpbrk-fbsd.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strpbrk.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strpbrk.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); - -#include - -/* - * Find the first occurrence in s1 of a character in s2 (excluding NUL). - */ -char * -strpbrk(s1, s2) - const char *s1, *s2; -{ - const char *scanp; - int c, sc; - - while ((c = *s1++) != 0) { - for (scanp = s2; (sc = *scanp++) != 0;) - if (sc == c) - return ((char *)(s1 - 1)); - } - return (NULL); -} diff --git a/string/strpbrk-fbsd.c b/string/strpbrk-fbsd.c new file mode 120000 index 0000000..d21223d --- /dev/null +++ b/string/strpbrk-fbsd.c @@ -0,0 +1 @@ +./strpbrk.c \ No newline at end of file diff --git a/string/strsep-fbsd.c b/string/strsep-fbsd.c deleted file mode 100644 index d0bccce..0000000 --- a/string/strsep-fbsd.c +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * Copyright (c) 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strsep.c,v 1.5 2002/03/21 18:44:54 obrien Exp $"); - -#include -#include - -/* - * Get next token from string *stringp, where tokens are possibly-empty - * 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. - * On return, *stringp points past the last NUL written (if there might - * be further tokens), or is NULL (if there are definitely no more tokens). - * - * If *stringp is NULL, strsep returns NULL. - */ -char * -strsep(stringp, delim) - char **stringp; - const char *delim; -{ - char *s; - const char *spanp; - int c, sc; - char *tok; - - if ((s = *stringp) == NULL) - return (NULL); - for (tok = s;;) { - c = *s++; - spanp = delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - *stringp = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ -} diff --git a/string/strsep-fbsd.c b/string/strsep-fbsd.c new file mode 120000 index 0000000..acbe4c2 --- /dev/null +++ b/string/strsep-fbsd.c @@ -0,0 +1 @@ +./strsep.c \ No newline at end of file diff --git a/string/strspn-fbsd.c b/string/strspn-fbsd.c deleted file mode 100644 index 3b96365..0000000 --- a/string/strspn-fbsd.c +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * Copyright (c) 2005 David Schultz - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strspn.c,v 1.5 2005/04/02 18:52:44 das Exp $"); - -#include -#include -#include - -#define IDX(c) ((u_char)(c) / LONG_BIT) -#define BIT(c) ((u_long)1 << ((u_char)(c) % LONG_BIT)) - -size_t -strspn(const char *s, const char *charset) -{ - /* - * NB: idx and bit are temporaries whose use causes gcc 3.4.2 to - * generate better code. Without them, gcc gets a little confused. - */ - const char *s1; - u_long bit; - u_long tbl[(UCHAR_MAX + 1) / LONG_BIT]; - int idx; - - if(*s == '\0') - return (0); - -#if LONG_BIT == 64 /* always better to unroll on 64-bit architectures */ - tbl[3] = tbl[2] = tbl[1] = tbl[0] = 0; -#else - for (idx = 0; idx < sizeof(tbl) / sizeof(tbl[0]); idx++) - tbl[idx] = 0; -#endif - for (; *charset != '\0'; charset++) { - idx = IDX(*charset); - bit = BIT(*charset); - tbl[idx] |= bit; - } - - for(s1 = s; ; s1++) { - idx = IDX(*s1); - bit = BIT(*s1); - if ((tbl[idx] & bit) == 0) - break; - } - return (s1 - s); -} diff --git a/string/strspn-fbsd.c b/string/strspn-fbsd.c new file mode 120000 index 0000000..2b2b2b8 --- /dev/null +++ b/string/strspn-fbsd.c @@ -0,0 +1 @@ +./strspn.c \ No newline at end of file diff --git a/string/strstr-fbsd.c b/string/strstr-fbsd.c deleted file mode 100644 index f51d170..0000000 --- a/string/strstr-fbsd.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * 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. - * - * 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[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strstr.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); - -#include - -/* - * Find the first occurrence of find in s. - */ -char * -strstr(s, find) - const char *s, *find; -{ - char c, sc; - size_t len; - - if ((c = *find++) != 0) { - len = strlen(find); - do { - do { - if ((sc = *s++) == 0) - return (NULL); - } while (sc != c); - } while (strncmp(s, find, len) != 0); - s--; - } - return ((char *)s); -} diff --git a/string/strstr-fbsd.c b/string/strstr-fbsd.c new file mode 120000 index 0000000..ec3a758 --- /dev/null +++ b/string/strstr-fbsd.c @@ -0,0 +1 @@ +./strstr.c \ No newline at end of file diff --git a/string/strtok-fbsd.c b/string/strtok-fbsd.c deleted file mode 100644 index 6aec194..0000000 --- a/string/strtok-fbsd.c +++ /dev/null @@ -1,140 +0,0 @@ -/*- - * Copyright (c) 1998 Softweyr LLC. All rights reserved. - * - * strtok_r, from Berkeley strtok - * Oct 13, 1998 by Wes Peters - * - * 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 - * notices, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notices, 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 Softweyr LLC, 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 SOFTWEYR LLC, 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 SOFTWEYR LLC, 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[] = "@(#)strtok.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD: src/lib/libc/string/strtok.c,v 1.9 2002/09/07 02:53:19 tjr Exp $"); - -#include -#ifdef DEBUG_STRTOK -#include -#endif -#include - -char *__strtok_r(char *, const char *, char **); - -__weak_reference(__strtok_r, strtok_r); - -char * -__strtok_r(char *s, const char *delim, char **last) -{ - char *spanp, *tok; - int c, sc; - - if (s == NULL && (s = *last) == NULL) - return (NULL); - - /* - * Skip (span) leading delimiters (s += strspn(s, delim), sort of). - */ -cont: - c = *s++; - for (spanp = (char *)delim; (sc = *spanp++) != 0;) { - if (c == sc) - goto cont; - } - - if (c == 0) { /* no non-delimiter characters */ - *last = NULL; - return (NULL); - } - tok = s - 1; - - /* - * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). - * Note that delim must have one NUL; we stop if we see that, too. - */ - for (;;) { - c = *s++; - spanp = (char *)delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = '\0'; - *last = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ -} - -char * -strtok(char *s, const char *delim) -{ - static char *last; - - return (__strtok_r(s, delim, &last)); -} - -#ifdef DEBUG_STRTOK -/* - * Test the tokenizer. - */ -int -main(void) -{ - char blah[80], test[80]; - char *brkb, *brkt, *phrase, *sep, *word; - - sep = "\\/:;=-"; - phrase = "foo"; - - printf("String tokenizer test:\n"); - strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); - for (word = strtok(test, sep); word; word = strtok(NULL, sep)) - printf("Next word is \"%s\".\n", word); - strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); - - for (word = strtok_r(test, sep, &brkt); word; - word = strtok_r(NULL, sep, &brkt)) { - strcpy(blah, "blah:blat:blab:blag"); - - for (phrase = strtok_r(blah, sep, &brkb); phrase; - phrase = strtok_r(NULL, sep, &brkb)) - printf("So far we're at %s:%s\n", word, phrase); - } - - return (0); -} - -#endif /* DEBUG_STRTOK */ diff --git a/string/strtok-fbsd.c b/string/strtok-fbsd.c new file mode 120000 index 0000000..48d8517 --- /dev/null +++ b/string/strtok-fbsd.c @@ -0,0 +1 @@ +./strtok.c \ No newline at end of file diff --git a/string/wcscat-fbsd.c b/string/wcscat-fbsd.c deleted file mode 100644 index cf7812f..0000000 --- a/string/wcscat-fbsd.c +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcscat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wcscat.c,v 1.8 2002/09/26 09:28:55 tjr Exp $"); - -#include - -wchar_t * -wcscat(s1, s2) - wchar_t * __restrict s1; - const wchar_t * __restrict s2; -{ - wchar_t *cp; - - cp = s1; - while (*cp != L'\0') - cp++; - while ((*cp++ = *s2++) != L'\0') - ; - - return (s1); -} diff --git a/string/wcscat-fbsd.c b/string/wcscat-fbsd.c new file mode 120000 index 0000000..530f0a9 --- /dev/null +++ b/string/wcscat-fbsd.c @@ -0,0 +1 @@ +./wcscat.c \ No newline at end of file diff --git a/string/wcschr-fbsd.c b/string/wcschr-fbsd.c deleted file mode 100644 index 0fae132..0000000 --- a/string/wcschr-fbsd.c +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * Copyright (c) 2002 Tim J. Robbins - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/string/wcschr.c,v 1.7 2002/10/23 10:47:47 tjr Exp $"); - -#include - -wchar_t * -wcschr(const wchar_t *s, wchar_t c) -{ - - while (*s != c && *s != L'\0') - s++; - if (*s == c) - return ((wchar_t *)s); - return (NULL); -} diff --git a/string/wcschr-fbsd.c b/string/wcschr-fbsd.c new file mode 120000 index 0000000..4d19f9f --- /dev/null +++ b/string/wcschr-fbsd.c @@ -0,0 +1 @@ +./wcschr.c \ No newline at end of file diff --git a/string/wcscmp-fbsd.c b/string/wcscmp-fbsd.c deleted file mode 100644 index 20152b2..0000000 --- a/string/wcscmp-fbsd.c +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * 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. - * - * 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 -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93"; -#if 0 -__RCSID("$NetBSD: wcscmp.c,v 1.3 2001/01/05 12:13:12 itojun Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ -__FBSDID("$FreeBSD: src/lib/libc/string/wcscmp.c,v 1.7 2002/10/23 11:08:40 tjr Exp $"); - -#include - -/* - * Compare strings. - */ -int -wcscmp(s1, s2) - const wchar_t *s1, *s2; -{ - - while (*s1 == *s2++) - if (*s1++ == 0) - return (0); - /* XXX assumes wchar_t = int */ - return (*(const unsigned int *)s1 - *(const unsigned int *)--s2); -} diff --git a/string/wcscmp-fbsd.c b/string/wcscmp-fbsd.c new file mode 120000 index 0000000..825a844 --- /dev/null +++ b/string/wcscmp-fbsd.c @@ -0,0 +1 @@ +./wcscmp.c \ No newline at end of file diff --git a/string/wcscpy-fbsd.c b/string/wcscpy-fbsd.c deleted file mode 100644 index b4c236a..0000000 --- a/string/wcscpy-fbsd.c +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcscpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wcscpy.c,v 1.8 2002/09/26 09:23:07 tjr Exp $"); - -#include - -wchar_t * -wcscpy(s1, s2) - wchar_t * __restrict s1; - const wchar_t * __restrict s2; -{ - wchar_t *cp; - - cp = s1; - while ((*cp++ = *s2++) != L'\0') - ; - - return (s1); -} diff --git a/string/wcscpy-fbsd.c b/string/wcscpy-fbsd.c new file mode 120000 index 0000000..c966e09 --- /dev/null +++ b/string/wcscpy-fbsd.c @@ -0,0 +1 @@ +./wcscpy.c \ No newline at end of file diff --git a/string/wcscspn-fbsd.c b/string/wcscspn-fbsd.c deleted file mode 100644 index c16f270..0000000 --- a/string/wcscspn-fbsd.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcscspn.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wcscspn.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); - -#include - -size_t -wcscspn(s, set) - const wchar_t *s; - const wchar_t *set; -{ - const wchar_t *p; - const wchar_t *q; - - p = s; - while (*p) { - q = set; - while (*q) { - if (*p == *q) - goto done; - q++; - } - p++; - } - -done: - return (p - s); -} diff --git a/string/wcscspn-fbsd.c b/string/wcscspn-fbsd.c new file mode 120000 index 0000000..2ba3b34 --- /dev/null +++ b/string/wcscspn-fbsd.c @@ -0,0 +1 @@ +./wcscspn.c \ No newline at end of file diff --git a/string/wcslcat-fbsd.c b/string/wcslcat-fbsd.c deleted file mode 100644 index f3b9a63..0000000 --- a/string/wcslcat-fbsd.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1998 Todd C. Miller - * 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 ``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. - * - * from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wcslcat.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); - -#include -#include - -/* - * Appends src to string dst of size siz (unlike wcsncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns wcslen(initial dst) + wcslen(src); if retval >= siz, - * truncation occurred. - */ -size_t -wcslcat(dst, src, siz) - wchar_t *dst; - const wchar_t *src; - size_t siz; -{ - wchar_t *d = dst; - const wchar_t *s = src; - size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (*d != '\0' && n-- != 0) - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + wcslen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} diff --git a/string/wcslcat-fbsd.c b/string/wcslcat-fbsd.c new file mode 120000 index 0000000..171476e --- /dev/null +++ b/string/wcslcat-fbsd.c @@ -0,0 +1 @@ +./wcslcat.c \ No newline at end of file diff --git a/string/wcslcpy-fbsd.c b/string/wcslcpy-fbsd.c deleted file mode 100644 index 273c8fd..0000000 --- a/string/wcslcpy-fbsd.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 1998 Todd C. Miller - * 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 ``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. - * - * from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wcslcpy.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); - -#include -#include - -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns wcslen(src); if retval >= siz, truncation occurred. - */ -size_t -wcslcpy(dst, src, siz) - wchar_t *dst; - const wchar_t *src; - size_t siz; -{ - wchar_t *d = dst; - const wchar_t *s = src; - size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) - break; - } while (--n != 0); - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} diff --git a/string/wcslcpy-fbsd.c b/string/wcslcpy-fbsd.c new file mode 120000 index 0000000..680dfea --- /dev/null +++ b/string/wcslcpy-fbsd.c @@ -0,0 +1 @@ +./wcslcpy.c \ No newline at end of file diff --git a/string/wcslen-fbsd.c b/string/wcslen-fbsd.c deleted file mode 100644 index 5e462a1..0000000 --- a/string/wcslen-fbsd.c +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcslen.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wcslen.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); - -#include - -size_t -wcslen(s) - const wchar_t *s; -{ - const wchar_t *p; - - p = s; - while (*p) - p++; - - return p - s; -} diff --git a/string/wcslen-fbsd.c b/string/wcslen-fbsd.c new file mode 120000 index 0000000..168686a --- /dev/null +++ b/string/wcslen-fbsd.c @@ -0,0 +1 @@ +./wcslen.c \ No newline at end of file diff --git a/string/wcsncat-fbsd.c b/string/wcsncat-fbsd.c deleted file mode 100644 index 5abb442..0000000 --- a/string/wcsncat-fbsd.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcsncat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wcsncat.c,v 1.7 2002/09/21 00:29:23 tjr Exp $"); - -#include - -wchar_t * -wcsncat(s1, s2, n) - wchar_t * __restrict s1; - const wchar_t * __restrict s2; - size_t n; -{ - wchar_t *p; - wchar_t *q; - const wchar_t *r; - - p = s1; - while (*p) - p++; - q = p; - r = s2; - while (*r && n) { - *q++ = *r++; - n--; - } - *q = '\0'; - return s1; -} diff --git a/string/wcsncat-fbsd.c b/string/wcsncat-fbsd.c new file mode 120000 index 0000000..581b079 --- /dev/null +++ b/string/wcsncat-fbsd.c @@ -0,0 +1 @@ +./wcsncat.c \ No newline at end of file diff --git a/string/wcsncmp-fbsd.c b/string/wcsncmp-fbsd.c deleted file mode 100644 index 7043e06..0000000 --- a/string/wcsncmp-fbsd.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; -__RCSID("$NetBSD: wcsncmp.c,v 1.3 2001/01/05 12:13:13 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wcsncmp.c,v 1.7 2002/10/23 11:08:40 tjr Exp $"); - -#include - -int -wcsncmp(s1, s2, n) - const wchar_t *s1, *s2; - size_t n; -{ - - if (n == 0) - return (0); - do { - if (*s1 != *s2++) { - /* XXX assumes wchar_t = int */ - return (*(const unsigned int *)s1 - - *(const unsigned int *)--s2); - } - if (*s1++ == 0) - break; - } while (--n != 0); - return (0); -} diff --git a/string/wcsncmp-fbsd.c b/string/wcsncmp-fbsd.c new file mode 120000 index 0000000..aa426db --- /dev/null +++ b/string/wcsncmp-fbsd.c @@ -0,0 +1 @@ +./wcsncmp.c \ No newline at end of file diff --git a/string/wcsncpy-fbsd.c b/string/wcsncpy-fbsd.c deleted file mode 100644 index fb9cef0..0000000 --- a/string/wcsncpy-fbsd.c +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * 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. - * - * 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 0 -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#endif -#include -__FBSDID("$FreeBSD: src/lib/libc/string/wcsncpy.c,v 1.9 2002/10/24 02:48:45 tjr Exp $"); - -#include - -/* - * Copy src to dst, truncating or null-padding to always copy n bytes. - * Return dst. - */ -wchar_t * -wcsncpy(wchar_t * __restrict dst, const wchar_t * __restrict src, size_t n) -{ - if (n != 0) { - wchar_t *d = dst; - const wchar_t *s = src; - - do { - if ((*d++ = *s++) == L'\0') { - /* NUL pad the remaining n-1 bytes */ - while (--n != 0) - *d++ = L'\0'; - break; - } - } while (--n != 0); - } - return (dst); -} diff --git a/string/wcsncpy-fbsd.c b/string/wcsncpy-fbsd.c new file mode 120000 index 0000000..94dc751 --- /dev/null +++ b/string/wcsncpy-fbsd.c @@ -0,0 +1 @@ +./wcsncpy.c \ No newline at end of file diff --git a/string/wcspbrk-fbsd.c b/string/wcspbrk-fbsd.c deleted file mode 100644 index 5502440..0000000 --- a/string/wcspbrk-fbsd.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wcspbrk.c,v 1.2 2000/12/21 05:07:25 itojun Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcspbrk.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wcspbrk.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); - -#include - -wchar_t * -wcspbrk(s, set) - const wchar_t *s; - const wchar_t *set; -{ - const wchar_t *p; - const wchar_t *q; - - p = s; - while (*p) { - q = set; - while (*q) { - if (*p == *q) { - /* LINTED interface specification */ - return (wchar_t *)p; - } - q++; - } - p++; - } - return NULL; -} diff --git a/string/wcspbrk-fbsd.c b/string/wcspbrk-fbsd.c new file mode 120000 index 0000000..2e91288 --- /dev/null +++ b/string/wcspbrk-fbsd.c @@ -0,0 +1 @@ +./wcspbrk.c \ No newline at end of file diff --git a/string/wcsrchr-fbsd.c b/string/wcsrchr-fbsd.c deleted file mode 100644 index 093dd08..0000000 --- a/string/wcsrchr-fbsd.c +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * Copyright (c) 2002 Tim J. Robbins - * 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. - */ - -#include -__FBSDID("$FreeBSD: src/lib/libc/string/wcsrchr.c,v 1.7 2002/10/23 10:52:04 tjr Exp $"); - -#include - -wchar_t * -wcsrchr(const wchar_t *s, wchar_t c) -{ - const wchar_t *last; - - last = NULL; - for (;;) { - if (*s == c) - last = s; - if (*s == L'\0') - break; - s++; - } - - return ((wchar_t *)last); -} diff --git a/string/wcsrchr-fbsd.c b/string/wcsrchr-fbsd.c new file mode 120000 index 0000000..1514a72 --- /dev/null +++ b/string/wcsrchr-fbsd.c @@ -0,0 +1 @@ +./wcsrchr.c \ No newline at end of file diff --git a/string/wcsspn-fbsd.c b/string/wcsspn-fbsd.c deleted file mode 100644 index d4101c7..0000000 --- a/string/wcsspn-fbsd.c +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wcsspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcsspn.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wcsspn.c,v 1.7 2002/09/21 00:29:23 tjr Exp $"); - -#include - -size_t -wcsspn(s, set) - const wchar_t *s; - const wchar_t *set; -{ - const wchar_t *p; - const wchar_t *q; - - p = s; - while (*p) { - q = set; - while (*q) { - if (*p == *q) - break; - q++; - } - if (!*q) - goto done; - p++; - } - -done: - return (p - s); -} diff --git a/string/wcsspn-fbsd.c b/string/wcsspn-fbsd.c new file mode 120000 index 0000000..d161daa --- /dev/null +++ b/string/wcsspn-fbsd.c @@ -0,0 +1 @@ +./wcsspn.c \ No newline at end of file diff --git a/string/wcsstr-fbsd.c b/string/wcsstr-fbsd.c deleted file mode 100644 index 0533e59..0000000 --- a/string/wcsstr-fbsd.c +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * 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. - * - * 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 0 -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#endif -#include -__FBSDID("$FreeBSD: src/lib/libc/string/wcsstr.c,v 1.8 2002/10/24 02:53:45 tjr Exp $"); - -#include - -/* - * Find the first occurrence of find in s. - */ -wchar_t * -wcsstr(const wchar_t * __restrict s, const wchar_t * __restrict find) -{ - wchar_t c, sc; - size_t len; - - if ((c = *find++) != 0) { - len = wcslen(find); - do { - do { - if ((sc = *s++) == L'\0') - return (NULL); - } while (sc != c); - } while (wcsncmp(s, find, len) != 0); - s--; - } - return ((wchar_t *)s); -} diff --git a/string/wcsstr-fbsd.c b/string/wcsstr-fbsd.c new file mode 120000 index 0000000..bd7adb3 --- /dev/null +++ b/string/wcsstr-fbsd.c @@ -0,0 +1 @@ +./wcsstr.c \ No newline at end of file diff --git a/string/wcstok-fbsd.c b/string/wcstok-fbsd.c deleted file mode 100644 index 5781adb..0000000 --- a/string/wcstok-fbsd.c +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * Copyright (c) 1998 Softweyr LLC. All rights reserved. - * - * strtok_r, from Berkeley strtok - * Oct 13, 1998 by Wes Peters - * - * 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 - * notices, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notices, 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 Softweyr LLC, 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 SOFTWEYR LLC, 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 SOFTWEYR LLC, 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 -__FBSDID("$FreeBSD: src/lib/libc/string/wcstok.c,v 1.2 2003/03/12 06:41:49 tjr Exp $"); - -#include - -wchar_t * -wcstok(wchar_t * __restrict s, const wchar_t * __restrict delim, - wchar_t ** __restrict last) -{ - const wchar_t *spanp; - wchar_t *tok; - wchar_t c, sc; - - if (s == NULL && (s = *last) == NULL) - return (NULL); - - /* - * Skip (span) leading delimiters (s += wcsspn(s, delim), sort of). - */ -cont: - c = *s++; - for (spanp = delim; (sc = *spanp++) != L'\0';) { - if (c == sc) - goto cont; - } - - if (c == L'\0') { /* no non-delimiter characters */ - *last = NULL; - return (NULL); - } - tok = s - 1; - - /* - * Scan token (scan for delimiters: s += wcscspn(s, delim), sort of). - * Note that delim must have one NUL; we stop if we see that, too. - */ - for (;;) { - c = *s++; - spanp = delim; - do { - if ((sc = *spanp++) == c) { - if (c == L'\0') - s = NULL; - else - s[-1] = L'\0'; - *last = s; - return (tok); - } - } while (sc != L'\0'); - } - /* NOTREACHED */ -} diff --git a/string/wcstok-fbsd.c b/string/wcstok-fbsd.c new file mode 120000 index 0000000..256c17d --- /dev/null +++ b/string/wcstok-fbsd.c @@ -0,0 +1 @@ +./wcstok.c \ No newline at end of file diff --git a/string/wmemchr-fbsd.c b/string/wmemchr-fbsd.c deleted file mode 100644 index 0b09f94..0000000 --- a/string/wmemchr-fbsd.c +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wmemchr.c,v 1.2 2000/12/20 14:08:31 itojun Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemchr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wmemchr.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); - -#include - -wchar_t * -wmemchr(s, c, n) - const wchar_t *s; - wchar_t c; - size_t n; -{ - size_t i; - - for (i = 0; i < n; i++) { - if (*s == c) { - /* LINTED const castaway */ - return (wchar_t *)s; - } - s++; - } - return NULL; -} diff --git a/string/wmemchr-fbsd.c b/string/wmemchr-fbsd.c new file mode 120000 index 0000000..0ad0f50 --- /dev/null +++ b/string/wmemchr-fbsd.c @@ -0,0 +1 @@ +./wmemchr.c \ No newline at end of file diff --git a/string/wmemcmp-fbsd.c b/string/wmemcmp-fbsd.c deleted file mode 100644 index 3014041..0000000 --- a/string/wmemcmp-fbsd.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemcmp.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wmemcmp.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); - -#include - -int -wmemcmp(s1, s2, n) - const wchar_t *s1; - const wchar_t *s2; - size_t n; -{ - size_t i; - - for (i = 0; i < n; i++) { - if (*s1 != *s2) { - /* wchar might be unsigned */ - return *s1 > *s2 ? 1 : -1; - } - s1++; - s2++; - } - return 0; -} diff --git a/string/wmemcmp-fbsd.c b/string/wmemcmp-fbsd.c new file mode 120000 index 0000000..e0c5393 --- /dev/null +++ b/string/wmemcmp-fbsd.c @@ -0,0 +1 @@ +./wmemcmp.c \ No newline at end of file diff --git a/string/wmemcpy-fbsd.c b/string/wmemcpy-fbsd.c deleted file mode 100644 index 4391309..0000000 --- a/string/wmemcpy-fbsd.c +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemcpy.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wmemcpy.c,v 1.7 2002/09/21 00:29:23 tjr Exp $"); - -#include -#include - -wchar_t * -wmemcpy(d, s, n) - wchar_t * __restrict d; - const wchar_t * __restrict s; - size_t n; -{ - - return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t)); -} diff --git a/string/wmemcpy-fbsd.c b/string/wmemcpy-fbsd.c new file mode 120000 index 0000000..0518204 --- /dev/null +++ b/string/wmemcpy-fbsd.c @@ -0,0 +1 @@ +./wmemcpy.c \ No newline at end of file diff --git a/string/wmemmove-fbsd.c b/string/wmemmove-fbsd.c deleted file mode 100644 index dd2036c..0000000 --- a/string/wmemmove-fbsd.c +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wmemmove.c,v 1.2 2000/12/20 14:08:31 itojun Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemmove.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wmemmove.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); - -#include -#include - -wchar_t * -wmemmove(d, s, n) - wchar_t *d; - const wchar_t *s; - size_t n; -{ - - return (wchar_t *)memmove(d, s, n * sizeof(wchar_t)); -} diff --git a/string/wmemmove-fbsd.c b/string/wmemmove-fbsd.c new file mode 120000 index 0000000..39fcfbe --- /dev/null +++ b/string/wmemmove-fbsd.c @@ -0,0 +1 @@ +./wmemmove.c \ No newline at end of file diff --git a/string/wmemset-fbsd.c b/string/wmemset-fbsd.c deleted file mode 100644 index df91537..0000000 --- a/string/wmemset-fbsd.c +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * Copyright (c)1999 Citrus Project, - * 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. - * - * citrus Id: wmemset.c,v 1.2 2000/12/20 14:08:31 itojun Exp - */ - -#include -#if 0 -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemset.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); -#endif /* LIBC_SCCS and not lint */ -#endif -__FBSDID("$FreeBSD: src/lib/libc/string/wmemset.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); - -#include - -wchar_t * -wmemset(s, c, n) - wchar_t *s; - wchar_t c; - size_t n; -{ - size_t i; - wchar_t *p; - - p = (wchar_t *)s; - for (i = 0; i < n; i++) { - *p = c; - p++; - } - return s; -} diff --git a/string/wmemset-fbsd.c b/string/wmemset-fbsd.c new file mode 120000 index 0000000..60f8a54 --- /dev/null +++ b/string/wmemset-fbsd.c @@ -0,0 +1 @@ +./wmemset.c \ No newline at end of file diff --git a/sys/Makefile.inc b/sys/Makefile.inc index 296066b..3434b08 100644 --- a/sys/Makefile.inc +++ b/sys/Makefile.inc @@ -6,14 +6,11 @@ # MDASM names override the default syscall names in MIASM. # NOASM will prevent the default syscall code from being generated. # -.ifnmake autopatch -.if exists(${.CURDIR}/${MACHINE_ARCH}/sys/Makefile.inc) -.include "${.CURDIR}/${MACHINE_ARCH}/sys/Makefile.inc" -.endif -.endif # !autopatch +.sinclude "${.CURDIR}/${MACHINE_ARCH}/sys/Makefile.inc" # sys sources .PATH: ${.CURDIR}/sys +CWD := ${.CURDIR}/sys # Include the generated makefile containing the *complete* list # of syscall names in MIASM. @@ -21,9 +18,8 @@ # Sources common to both syscall interfaces: -# 3375657: patches for sem_open() sem_unlink() shm_open() shm_unlink() -MISRCS+= chmod.c chmodx_np.c crt_externs.c \ - errno.c fchmod.c fix-3375657.c \ +MISRCS += chmod.c chmodx_np.c crt_externs.c \ + errno.c fchmod.c \ getiopolicy_np.c getrlimit.c gettimeofday.c \ kill.c __libc_init.c \ mmap.c \ @@ -35,31 +31,33 @@ MISRCS+= chmod.c chmodx_np.c crt_externs.c \ sigtramp.c statx_np.c \ umaskx_np.c +.ifdef FEATURE_MEM_THERM_NOTIFICATION_APIS +MISRCS += OSMemoryNotification.c OSThermalNotification.c +.endif + .if (${MACHINE_ARCH} != ppc) .if (${MACHINE_ARCH} != i386) MISRCS+= context-stubs.c .endif .endif -.ifdef LP64 -MISRCS+= fcntl.c ioctl.c -PRE1050SRCS+= select.c -.endif - .include "Makefile.obsd_begin" OBSDMISRCS= stack_protector.c .include "Makefile.obsd_end" -.for _src in sem_open.c sem_unlink.c shm_open.c shm_unlink.c fix-3375657.c -CFLAGS-${_src} += -D__APPLE_PR3375657_HACK__ -.endfor +.ifdef FEATURE_PATCH_3375657 +# patches for sem_open() sem_unlink() shm_open() shm_unlink() +MISRCS+= fix-3375657.c +.endif # FEATURE_PATCH_3375657 INODE32SRCS += statx_np.c CANCELABLESRCS += select.c sigsuspend.c -.ifdef LP64 +.if defined(LP64) || (${MACHINE_ARCH} == arm) CANCELABLESRCS+= fcntl.c +MISRCS+= fcntl.c ioctl.c +PRE1050SRCS+= select.c .endif LEGACYSRCS += accept.c bind.c connect.c \ @@ -72,7 +70,7 @@ LEGACYSRCS += accept.c bind.c connect.c \ shmctl.c sigsuspend.c socketpair.c # we need to create open.h, which just contains a definition for O_NOCTTY -open.do open.o open.po open.So: open.h +open.${OBJSUFFIX}: open.h open.h : ${CC} -E -dD ${CFLAGS} -include fcntl.h -x c /dev/null | grep O_NOCTTY > ${.TARGET} @@ -102,6 +100,7 @@ CFLAGS-getrlimit.c += -DLIBC_ALIAS_GETRLIMIT CFLAGS-getsockname.c += -DLIBC_ALIAS_GETSOCKNAME CFLAGS-kill.c += -DLIBC_ALIAS_KILL CFLAGS-lchmod.c += -DLIBC_ALIAS_LCHMOD +CFLAGS-lchown.c += -DLIBC_ALIAS_LCHOWN CFLAGS-listen.c += -DLIBC_ALIAS_LISTEN CFLAGS-mmap.c += -DLIBC_ALIAS_MMAP CFLAGS-mprotect.c += -DLIBC_ALIAS_MPROTECT diff --git a/sys/OSMemoryNotification.c b/sys/OSMemoryNotification.c new file mode 100644 index 0000000..b0f1ae4 --- /dev/null +++ b/sys/OSMemoryNotification.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include +#include +#include +#include +#include + +const char *kOSMemoryNotificationName = "com.apple.system.memorystatus"; + +struct _OSMemoryNotification { + int token; + mach_port_t port; +}; + +int +OSMemoryNotificationCreate(OSMemoryNotificationRef *note) +{ + OSMemoryNotificationRef ref = malloc(sizeof(struct _OSMemoryNotification)); + + if (NULL == ref) { + return ENOMEM; + } + + if (NOTIFY_STATUS_OK != notify_register_mach_port(kOSMemoryNotificationName, &ref->port, 0, &ref->token)) + return ENOMEM; + + *note = ref; + + return 0; +} + +int +OSMemoryNotificationDestroy(OSMemoryNotificationRef note) +{ + if (NOTIFY_STATUS_OK != notify_cancel(note->token)) + return EINVAL; + + if (KERN_SUCCESS != mach_port_deallocate(mach_task_self(), note->port)) + return EINVAL; + + free(note); + + return 0; +} + +int +OSMemoryNotificationWait(OSMemoryNotificationRef note, OSMemoryNotificationLevel *level) +{ + + return OSMemoryNotificationTimedWait(note, level, NULL); +} + +static mach_msg_timeout_t +abs_to_timeout(const struct timeval *abstime) +{ + struct timeval rel, now; + + gettimeofday(&now, NULL); + + rel.tv_usec = abstime->tv_usec - now.tv_usec; + rel.tv_sec = abstime->tv_sec - now.tv_sec; + if (rel.tv_usec < 0) { + rel.tv_usec += 1000000; + rel.tv_sec--; + } + if (((int)rel.tv_sec < 0) || ((rel.tv_sec == 0) && (rel.tv_usec == 0))) { + return 0; + } + return rel.tv_sec * 1000 + rel.tv_usec / 1000; +} + +int +OSMemoryNotificationTimedWait(OSMemoryNotificationRef note, OSMemoryNotificationLevel *level, const struct timeval *abstime) +{ + mach_msg_empty_rcv_t msg = {{0}}; + mach_msg_return_t ret; + uint64_t val; + + if (abstime) { + mach_msg_timeout_t timeout = abs_to_timeout(abstime); + + if (0 == timeout) + return ETIMEDOUT; + + ret = mach_msg(&msg.header, MACH_RCV_MSG | MACH_RCV_TIMEOUT, 0, sizeof msg, note->port, timeout, MACH_PORT_NULL); + + if (MACH_RCV_TIMED_OUT == ret) { + return ETIMEDOUT; + } + } else { + ret = mach_msg(&msg.header, MACH_RCV_MSG, 0, sizeof msg, note->port, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + } + + if (MACH_MSG_SUCCESS != ret) + return EINVAL; + + if (NOTIFY_STATUS_OK != notify_get_state(note->token, &val)) + return EINVAL; + + *level = (OSMemoryNotificationLevel)val; + + return 0; +} + +OSMemoryNotificationLevel OSMemoryNotificationCurrentLevel(void) +{ + uint64_t val; + int token; + + if (NOTIFY_STATUS_OK != notify_register_check(kOSMemoryNotificationName, &token)) + return OSMemoryNotificationLevelAny; + + if (NOTIFY_STATUS_OK != notify_get_state(token, &val)) + return OSMemoryNotificationLevelAny; + + if (NOTIFY_STATUS_OK != notify_cancel(token)) + return OSMemoryNotificationLevelAny; + + return (OSMemoryNotificationLevel)val; +} diff --git a/sys/OSThermalNotification.c b/sys/OSThermalNotification.c new file mode 100644 index 0000000..cd4d2b7 --- /dev/null +++ b/sys/OSThermalNotification.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2007 Apple Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include + +const char *kOSThermalNotificationName = "com.apple.system.thermalstatus"; + +OSThermalNotificationLevel OSThermalNotificationCurrentLevel(void) +{ + uint64_t val; + int token; + + if (NOTIFY_STATUS_OK != notify_register_check(kOSThermalNotificationName, &token)) + return OSThermalNotificationLevelAny; + + if (NOTIFY_STATUS_OK != notify_get_state(token, &val)) + return OSThermalNotificationLevelAny; + + if (NOTIFY_STATUS_OK != notify_cancel(token)) + return OSThermalNotificationLevelAny; + + return (OSThermalNotificationLevel)val; +} diff --git a/sys/fix-3375657.c b/sys/fix-3375657.c index d37d952..0ee18e2 100644 --- a/sys/fix-3375657.c +++ b/sys/fix-3375657.c @@ -21,8 +21,6 @@ * @APPLE_LICENSE_HEADER_END@ */ -#ifdef __APPLE_PR3375657_HACK__ - /* * When mutexes or spinlocks were added for thread safety, the system would * hang during the boot process, just after changing to the blue background. @@ -407,5 +405,3 @@ _shm_match(const char *name) return dosearch(name, shm_hack_names); #endif /* SHM_DEBUG_FILE */ } - -#endif /* __APPLE_PR3375657_HACK__ */ diff --git a/sys/libc.syscall b/sys/libc.syscall index efaef30..37cfceb 100644 --- a/sys/libc.syscall +++ b/sys/libc.syscall @@ -1,18 +1,12 @@ __exit ___exit _accessx_np ___access_extended -_fstat$INODE64 ___fstat64 -_fstatfs$INODE64 ___fstatfs64 -_getfsstat$INODE64 ___getfsstat64 _getsgroups_np ___getsgroups _getwgroups_np ___getwgroups # initgroups wrapper is defined in Libinfo _initgroups -_lstat$INODE64 ___lstat64 _posix_madvise ___madvise _pthread_getugid_np ___gettid _pthread_setugid_np ___settid _setsgroups_np ___setsgroups _setwgroups_np ___setwgroups -_stat$INODE64 ___stat64 -_statfs$INODE64 ___statfs64 _wait4 ___wait4_nocancel diff --git a/sys/statx_np.c b/sys/statx_np.c index 3159378..9817c37 100644 --- a/sys/statx_np.c +++ b/sys/statx_np.c @@ -69,7 +69,7 @@ lstatx_np(const char *path, struct stat *sb, filesec_t fsec) } -#if __DARWIN_64_BIT_INO_T +#if __DARWIN_64_BIT_INO_T && !__DARWIN_ONLY_64_BIT_INO_T int statx64_np(const char *path, struct stat64 *sb, filesec_t fsec) { @@ -87,7 +87,7 @@ lstatx64_np(const char *path, struct stat64 *sb, filesec_t fsec) { return(lstatx_np(path, (struct stat *)sb, fsec)); } -#endif /* __DARWIN_64_BIT_INO_T */ +#endif /* __DARWIN_64_BIT_INO_T && !__DARWIN_ONLY_64_BIT_INO_T */ /* * Stat syscalls diff --git a/threads/Makefile.inc b/threads/Makefile.inc index 6495b95..4b5fd6c 100644 --- a/threads/Makefile.inc +++ b/threads/Makefile.inc @@ -1,9 +1,5 @@ .PATH: ${.CURDIR}/${MACHINE_ARCH}/threads ${.CURDIR}/threads -.ifnmake autopatch -.if exists(${.CURDIR}/${MACHINE_ARCH}/threads/Makefile.inc) -.include "${.CURDIR}/${MACHINE_ARCH}/threads/Makefile.inc" -.endif -.endif # !autopatch +.sinclude "${.CURDIR}/${MACHINE_ARCH}/threads/Makefile.inc" MISRCS += cprocs.c cthreads.c lu_utils.c mig_support.c diff --git a/util/Makefile.inc b/util/Makefile.inc index 34271ca..69f132e 100644 --- a/util/Makefile.inc +++ b/util/Makefile.inc @@ -1,13 +1,26 @@ .PATH: ${.CURDIR}/${MACHINE_ARCH}/util ${.CURDIR}/util -MISRCS += login.c login_tty.c logout.c logwtmp.c pty.c fparseln.c \ - opendev.c +MISRCS += login_tty.c logwtmp.c pty.c fparseln.c opendev.c + +.ifdef FEATURE_LEGACY_UTMP_APIS +MISRCS += login.c logout.c +.endif + +.for _src in fparseln.c +CFLAGS-${_src} += -D__FBSDID=__RCSID +.endfor .if ${LIB} == "c" -MAN3 += fparseln.3 login.3 opendev.3 openpty.3 +MAN3 += fparseln.3 opendev.3 openpty.3 + +.ifdef FEATURE_LEGACY_UTMP_APIS +MAN3 += login.3 +.endif MLINKS += openpty.3 forkpty.3 MLINKS += openpty.3 login_tty.3 +.ifdef FEATURE_LEGACY_UTMP_APIS MLINKS += login.3 logwtmp.3 MLINKS += login.3 logout.3 .endif +.endif diff --git a/uuid/Makefile.inc b/uuid/Makefile.inc index f7fcd6e..ede65ae 100644 --- a/uuid/Makefile.inc +++ b/uuid/Makefile.inc @@ -1,5 +1,6 @@ # uuid sources .PATH: ${.CURDIR}/uuid +CWD := ${.CURDIR}/uuid # uuid/uuid.h is now installed by xnu @@ -13,10 +14,13 @@ UUIDMAN3 = uuid_clear.3.in uuid_compare.3.in uuid_copy.3.in \ uuid_unparse.3.in PRIVUUID_INSTHDRS += ${.CURDIR}/uuid/namespace.h +# This .for statement forces evaluation of ${CWD} +.for _cwd in ${CWD} + .for _src in ${UUIDSRCS} .ifmake autopatch -${_src:R}-uuid.${_src:E}: uuidsrc/${_src} _AUTOPATCHCUR -AUTOPATCHSRCS+= ${_src:R}-uuid.${_src:E} +${_cwd}/${_src:R}-uuid.${_src:E}: ${_cwd}/uuidsrc/${_src} _AUTOPATCH +AUTOPATCHSRCS+= ${_cwd}/${_src:R}-uuid.${_src:E} .else # !autopatch MISRCS+= ${_src} .endif # autopatch @@ -24,15 +28,15 @@ MISRCS+= ${_src} .ifmake autopatch .for _src in ${UUIDHDRS} -${_src}: uuidsrc/${_src} _AUTOPATCHCUR -AUTOPATCHHDRS+= ${_src} +${_cwd}/${_src}: ${_cwd}/uuidsrc/${_src} _AUTOPATCH +AUTOPATCHHDRS+= ${_cwd}/${_src} .endfor .endif # autopatch .for _src in ${UUIDMAN3} .ifmake autopatch -${_src:R}-uuid.${_src:E}: uuidsrc/${_src} _AUTOPATCH -AUTOPATCHMAN+= ${_src:R} +${_cwd}/${_src:R}-uuid.${_src:E}: ${_cwd}/uuidsrc/${_src} _AUTOPATCH +AUTOPATCHMAN+= ${_cwd}/${_src:R} .else # !autopatch MAN3+= ${_src:R} .endif # autopatch @@ -45,8 +49,10 @@ MLINKS+= uuid_unparse.3 uuid_unparse_lower.3 \ uuid_unparse.3 uuid_unparse_upper.3 .ifmake autopatch -${UUIDTOMAN:R}-uuid.${UUIDTOMAN:E}: uuidsrc/${UUIDFROMMAN} _AUTOPATCH -AUTOPATCHMAN+= ${UUIDTOMAN:R} +${_cwd}/${UUIDTOMAN:R}-uuid.${UUIDTOMAN:E}: ${_cwd}/uuidsrc/${UUIDFROMMAN} _AUTOPATCH +AUTOPATCHMAN+= ${_cwd}/${UUIDTOMAN:R} .else # !autopatch MAN3+= ${UUIDTOMAN:R} .endif # autopatch + +.endfor # _cwd diff --git a/uuid/clear-uuid.c b/uuid/clear-uuid.c deleted file mode 100644 index f3a1005..0000000 --- a/uuid/clear-uuid.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * clear.c -- Clear a UUID - * - * Copyright (C) 1996, 1997 Theodore Ts'o. - * - * %Begin-Header% - * 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, and the entire permission notice in its entirety, - * including the disclaimer of warranties. - * 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF - * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * %End-Header% - */ - -#include "string.h" - -#include "uuidP.h" - -void uuid_clear(uuid_t uu) -{ - memset(uu, 0, 16); -} - diff --git a/uuid/clear-uuid.c b/uuid/clear-uuid.c new file mode 120000 index 0000000..77ad4f8 --- /dev/null +++ b/uuid/clear-uuid.c @@ -0,0 +1 @@ +./clear.c \ No newline at end of file diff --git a/uuid/compare-uuid.c b/uuid/compare-uuid.c deleted file mode 100644 index a9c505c..0000000 --- a/uuid/compare-uuid.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * compare.c --- compare whether or not two UUID's are the same - * - * Returns 0 if the two UUID's are different, and 1 if they are the same. - * - * Copyright (C) 1996, 1997 Theodore Ts'o. - * - * %Begin-Header% - * 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, and the entire permission notice in its entirety, - * including the disclaimer of warranties. - * 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF - * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * %End-Header% - */ - -#include "uuidP.h" -#include - -#define UUCMP(u1,u2) if (u1 != u2) return((u1 < u2) ? -1 : 1); - -int uuid_compare(const uuid_t uu1, const uuid_t uu2) -{ - struct uuid uuid1, uuid2; - - uuid_unpack(uu1, &uuid1); - uuid_unpack(uu2, &uuid2); - - UUCMP(uuid1.time_low, uuid2.time_low); - UUCMP(uuid1.time_mid, uuid2.time_mid); - UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version); - UUCMP(uuid1.clock_seq, uuid2.clock_seq); - return memcmp(uuid1.node, uuid2.node, 6); -} - diff --git a/uuid/compare-uuid.c b/uuid/compare-uuid.c new file mode 120000 index 0000000..51b9486 --- /dev/null +++ b/uuid/compare-uuid.c @@ -0,0 +1 @@ +./compare.c \ No newline at end of file diff --git a/uuid/copy-uuid.c b/uuid/copy-uuid.c deleted file mode 100644 index 963bc81..0000000 --- a/uuid/copy-uuid.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * copy.c --- copy UUIDs - * - * Copyright (C) 1996, 1997 Theodore Ts'o. - * - * %Begin-Header% - * 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, and the entire permission notice in its entirety, - * including the disclaimer of warranties. - * 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF - * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * %End-Header% - */ - -#include "uuidP.h" - -void uuid_copy(uuid_t dst, const uuid_t src) -{ - unsigned char *cp1; - const unsigned char *cp2; - int i; - - for (i=0, cp1 = dst, cp2 = src; i < 16; i++) - *cp1++ = *cp2++; -} diff --git a/uuid/copy-uuid.c b/uuid/copy-uuid.c new file mode 120000 index 0000000..4372f3f --- /dev/null +++ b/uuid/copy-uuid.c @@ -0,0 +1 @@ +./copy.c \ No newline at end of file diff --git a/uuid/isnull-uuid.c b/uuid/isnull-uuid.c deleted file mode 100644 index 54a8300..0000000 --- a/uuid/isnull-uuid.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * isnull.c --- Check whether or not the UUID is null - * - * Copyright (C) 1996, 1997 Theodore Ts'o. - * - * %Begin-Header% - * 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, and the entire permission notice in its entirety, - * including the disclaimer of warranties. - * 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF - * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * %End-Header% - */ - -#include "uuidP.h" - -/* Returns 1 if the uuid is the NULL uuid */ -int uuid_is_null(const uuid_t uu) -{ - const unsigned char *cp; - int i; - - for (i=0, cp = uu; i < 16; i++) - if (*cp++) - return 0; - return 1; -} - diff --git a/uuid/isnull-uuid.c b/uuid/isnull-uuid.c new file mode 120000 index 0000000..ba062b0 --- /dev/null +++ b/uuid/isnull-uuid.c @@ -0,0 +1 @@ +./isnull.c \ No newline at end of file diff --git a/uuid/pack-uuid.c b/uuid/pack-uuid.c deleted file mode 100644 index 348d432..0000000 --- a/uuid/pack-uuid.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Internal routine for packing UUID's - * - * Copyright (C) 1996, 1997 Theodore Ts'o. - * - * %Begin-Header% - * 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, and the entire permission notice in its entirety, - * including the disclaimer of warranties. - * 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF - * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * %End-Header% - */ - -#include -#include "uuidP.h" - -void uuid_pack(const struct uuid *uu, uuid_t ptr) -{ - uint32_t tmp; - unsigned char *out = ptr; - - tmp = uu->time_low; - out[3] = (unsigned char) tmp; - tmp >>= 8; - out[2] = (unsigned char) tmp; - tmp >>= 8; - out[1] = (unsigned char) tmp; - tmp >>= 8; - out[0] = (unsigned char) tmp; - - tmp = uu->time_mid; - out[5] = (unsigned char) tmp; - tmp >>= 8; - out[4] = (unsigned char) tmp; - - tmp = uu->time_hi_and_version; - out[7] = (unsigned char) tmp; - tmp >>= 8; - out[6] = (unsigned char) tmp; - - tmp = uu->clock_seq; - out[9] = (unsigned char) tmp; - tmp >>= 8; - out[8] = (unsigned char) tmp; - - memcpy(out+10, uu->node, 6); -} - diff --git a/uuid/pack-uuid.c b/uuid/pack-uuid.c new file mode 120000 index 0000000..772b4f2 --- /dev/null +++ b/uuid/pack-uuid.c @@ -0,0 +1 @@ +./pack.c \ No newline at end of file diff --git a/uuid/parse-uuid.c b/uuid/parse-uuid.c deleted file mode 100644 index 07b894d..0000000 --- a/uuid/parse-uuid.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * parse.c --- UUID parsing - * - * Copyright (C) 1996, 1997 Theodore Ts'o. - * - * %Begin-Header% - * 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, and the entire permission notice in its entirety, - * including the disclaimer of warranties. - * 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF - * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * %End-Header% - */ - -#include -#include -#include -#include - -#include "uuidP.h" - -int uuid_parse(const char *in, uuid_t uu) -{ - struct uuid uuid; - int i; - const char *cp; - char buf[3]; - - if (strlen(in) != 36) - return -1; - for (i=0, cp = in; i <= 36; i++,cp++) { - if ((i == 8) || (i == 13) || (i == 18) || - (i == 23)) { - if (*cp == '-') - continue; - else - return -1; - } - if (i== 36) - if (*cp == 0) - continue; - if (!isxdigit(*cp)) - return -1; - } - uuid.time_low = strtoul(in, NULL, 16); - uuid.time_mid = strtoul(in+9, NULL, 16); - uuid.time_hi_and_version = strtoul(in+14, NULL, 16); - uuid.clock_seq = strtoul(in+19, NULL, 16); - cp = in+24; - buf[2] = 0; - for (i=0; i < 6; i++) { - buf[0] = *cp++; - buf[1] = *cp++; - uuid.node[i] = strtoul(buf, NULL, 16); - } - - uuid_pack(&uuid, uu); - return 0; -} diff --git a/uuid/parse-uuid.c b/uuid/parse-uuid.c new file mode 120000 index 0000000..5f2e8d6 --- /dev/null +++ b/uuid/parse-uuid.c @@ -0,0 +1 @@ +./parse.c \ No newline at end of file diff --git a/uuid/unpack-uuid.c b/uuid/unpack-uuid.c deleted file mode 100644 index 9502fc2..0000000 --- a/uuid/unpack-uuid.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Internal routine for unpacking UUID - * - * Copyright (C) 1996, 1997 Theodore Ts'o. - * - * %Begin-Header% - * 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, and the entire permission notice in its entirety, - * including the disclaimer of warranties. - * 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF - * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * %End-Header% - */ - -#include -#include "uuidP.h" - -void uuid_unpack(const uuid_t in, struct uuid *uu) -{ - const uint8_t *ptr = in; - uint32_t tmp; - - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - tmp = (tmp << 8) | *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->time_low = tmp; - - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->time_mid = tmp; - - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->time_hi_and_version = tmp; - - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->clock_seq = tmp; - - memcpy(uu->node, ptr, 6); -} - diff --git a/uuid/unpack-uuid.c b/uuid/unpack-uuid.c new file mode 120000 index 0000000..dd9411c --- /dev/null +++ b/uuid/unpack-uuid.c @@ -0,0 +1 @@ +./unpack.c \ No newline at end of file diff --git a/uuid/unparse-uuid.c b/uuid/unparse-uuid.c deleted file mode 100644 index c0e08ef..0000000 --- a/uuid/unparse-uuid.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * unparse.c -- convert a UUID to string - * - * Copyright (C) 1996, 1997 Theodore Ts'o. - * - * %Begin-Header% - * 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, and the entire permission notice in its entirety, - * including the disclaimer of warranties. - * 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF - * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * %End-Header% - */ - -#include - -#include "uuidP.h" - -static const char *fmt_lower = - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"; - -static const char *fmt_upper = - "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"; - -#ifdef UUID_UNPARSE_DEFAULT_UPPER -#define FMT_DEFAULT fmt_upper -#else -#define FMT_DEFAULT fmt_lower -#endif - -static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt) -{ - struct uuid uuid; - - uuid_unpack(uu, &uuid); - sprintf(out, fmt, - uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, - uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, - uuid.node[0], uuid.node[1], uuid.node[2], - uuid.node[3], uuid.node[4], uuid.node[5]); -} - -void uuid_unparse_lower(const uuid_t uu, char *out) -{ - uuid_unparse_x(uu, out, fmt_lower); -} - -void uuid_unparse_upper(const uuid_t uu, char *out) -{ - uuid_unparse_x(uu, out, fmt_upper); -} - -void uuid_unparse(const uuid_t uu, char *out) -{ - uuid_unparse_x(uu, out, FMT_DEFAULT); -} diff --git a/uuid/unparse-uuid.c b/uuid/unparse-uuid.c new file mode 120000 index 0000000..bac9a9f --- /dev/null +++ b/uuid/unparse-uuid.c @@ -0,0 +1 @@ +./unparse.c \ No newline at end of file diff --git a/x86_64/sys/Makefile.inc b/x86_64/sys/Makefile.inc index 04738a1..95a979c 100644 --- a/x86_64/sys/Makefile.inc +++ b/x86_64/sys/Makefile.inc @@ -8,4 +8,4 @@ MDSRCS+= OSAtomic.s \ setjmp.s \ _sigtramp.s -MDCOPYFILES+= ${.CURDIR}/x86_64/sys/libc.syscall.x86_64 +MDCOPYFILES+= ${.CURDIR}/Platforms/${RC_TARGET_CONFIG}/x86_64/libc.syscall.x86_64 -- 2.45.2