From 677b6e605be95f434602f19a627ea0dea2927ccd Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 20 Feb 2014 14:15:09 -0800 Subject: Move the upstream-netbsd libc files into the correct directory. I screwed up when I originally imported these files; they're in lib/libc/ in the upstream tree; there is no top-level libc/ (though there is a top-level common/, so those files stay where they are). Change-Id: I7c5e2224a4441ab0e33616a855a8c6aacfeac46f --- libc/Android.mk | 86 +- libc/upstream-netbsd/lib/libc/gen/ftw.c | 98 + libc/upstream-netbsd/lib/libc/gen/nftw.c | 114 ++ libc/upstream-netbsd/lib/libc/gen/nice.c | 70 + libc/upstream-netbsd/lib/libc/gen/popen.c | 227 +++ libc/upstream-netbsd/lib/libc/gen/psignal.c | 85 + libc/upstream-netbsd/lib/libc/gen/setjmperr.c | 56 + libc/upstream-netbsd/lib/libc/gen/utime.c | 65 + .../lib/libc/include/isc/assertions.h | 132 ++ libc/upstream-netbsd/lib/libc/include/isc/dst.h | 170 ++ .../lib/libc/include/isc/eventlib.h | 206 +++ libc/upstream-netbsd/lib/libc/include/isc/heap.h | 51 + libc/upstream-netbsd/lib/libc/include/isc/list.h | 120 ++ .../lib/libc/include/isc/memcluster.h | 52 + libc/upstream-netbsd/lib/libc/inet/inet_ntoa.c | 64 + libc/upstream-netbsd/lib/libc/inet/inet_ntop.c | 232 +++ libc/upstream-netbsd/lib/libc/inet/inet_pton.c | 310 ++++ libc/upstream-netbsd/lib/libc/isc/ev_streams.c | 319 ++++ libc/upstream-netbsd/lib/libc/isc/ev_timers.c | 519 ++++++ libc/upstream-netbsd/lib/libc/isc/eventlib_p.h | 283 +++ libc/upstream-netbsd/lib/libc/regex/cclass.h | 104 ++ libc/upstream-netbsd/lib/libc/regex/cname.h | 175 ++ libc/upstream-netbsd/lib/libc/regex/engine.c | 1188 ++++++++++++ libc/upstream-netbsd/lib/libc/regex/regcomp.c | 1944 ++++++++++++++++++++ libc/upstream-netbsd/lib/libc/regex/regerror.c | 223 +++ libc/upstream-netbsd/lib/libc/regex/regex2.h | 209 +++ libc/upstream-netbsd/lib/libc/regex/regexec.c | 234 +++ libc/upstream-netbsd/lib/libc/regex/regfree.c | 129 ++ libc/upstream-netbsd/lib/libc/regex/utils.h | 91 + libc/upstream-netbsd/lib/libc/stdio/getdelim.c | 154 ++ libc/upstream-netbsd/lib/libc/stdio/getline.c | 45 + libc/upstream-netbsd/lib/libc/stdlib/_rand48.c | 57 + libc/upstream-netbsd/lib/libc/stdlib/bsearch.c | 85 + libc/upstream-netbsd/lib/libc/stdlib/div.c | 81 + libc/upstream-netbsd/lib/libc/stdlib/drand48.c | 32 + libc/upstream-netbsd/lib/libc/stdlib/erand48.c | 42 + libc/upstream-netbsd/lib/libc/stdlib/exit.c | 63 + libc/upstream-netbsd/lib/libc/stdlib/jrand48.c | 39 + libc/upstream-netbsd/lib/libc/stdlib/ldiv.c | 60 + libc/upstream-netbsd/lib/libc/stdlib/lldiv.c | 66 + libc/upstream-netbsd/lib/libc/stdlib/lrand48.c | 33 + libc/upstream-netbsd/lib/libc/stdlib/mrand48.c | 33 + libc/upstream-netbsd/lib/libc/stdlib/nrand48.c | 38 + libc/upstream-netbsd/lib/libc/stdlib/seed48.c | 49 + libc/upstream-netbsd/lib/libc/stdlib/srand48.c | 38 + libc/upstream-netbsd/lib/libc/stdlib/tdelete.c | 67 + libc/upstream-netbsd/lib/libc/stdlib/tfind.c | 47 + libc/upstream-netbsd/lib/libc/stdlib/tsearch.c | 56 + libc/upstream-netbsd/lib/libc/string/memccpy.c | 61 + libc/upstream-netbsd/lib/libc/string/strcasestr.c | 69 + libc/upstream-netbsd/lib/libc/string/strcoll.c | 59 + libc/upstream-netbsd/lib/libc/string/strxfrm.c | 70 + .../lib/libc/thread-stub/__isthreaded.c | 37 + libc/upstream-netbsd/lib/libc/unistd/killpg.c | 56 + libc/upstream-netbsd/libc/gen/ftw.c | 98 - libc/upstream-netbsd/libc/gen/nftw.c | 114 -- libc/upstream-netbsd/libc/gen/nice.c | 70 - libc/upstream-netbsd/libc/gen/popen.c | 227 --- libc/upstream-netbsd/libc/gen/psignal.c | 85 - libc/upstream-netbsd/libc/gen/setjmperr.c | 56 - libc/upstream-netbsd/libc/gen/utime.c | 65 - libc/upstream-netbsd/libc/include/isc/assertions.h | 132 -- libc/upstream-netbsd/libc/include/isc/dst.h | 170 -- libc/upstream-netbsd/libc/include/isc/eventlib.h | 206 --- libc/upstream-netbsd/libc/include/isc/heap.h | 51 - libc/upstream-netbsd/libc/include/isc/list.h | 120 -- libc/upstream-netbsd/libc/include/isc/memcluster.h | 52 - libc/upstream-netbsd/libc/inet/inet_ntoa.c | 64 - libc/upstream-netbsd/libc/inet/inet_ntop.c | 232 --- libc/upstream-netbsd/libc/inet/inet_pton.c | 310 ---- libc/upstream-netbsd/libc/isc/ev_streams.c | 319 ---- libc/upstream-netbsd/libc/isc/ev_timers.c | 519 ------ libc/upstream-netbsd/libc/isc/eventlib_p.h | 283 --- libc/upstream-netbsd/libc/regex/cclass.h | 104 -- libc/upstream-netbsd/libc/regex/cname.h | 175 -- libc/upstream-netbsd/libc/regex/engine.c | 1188 ------------ libc/upstream-netbsd/libc/regex/regcomp.c | 1944 -------------------- libc/upstream-netbsd/libc/regex/regerror.c | 223 --- libc/upstream-netbsd/libc/regex/regex2.h | 209 --- libc/upstream-netbsd/libc/regex/regexec.c | 234 --- libc/upstream-netbsd/libc/regex/regfree.c | 129 -- libc/upstream-netbsd/libc/regex/utils.h | 91 - libc/upstream-netbsd/libc/stdio/getdelim.c | 154 -- libc/upstream-netbsd/libc/stdio/getline.c | 45 - libc/upstream-netbsd/libc/stdlib/_rand48.c | 57 - libc/upstream-netbsd/libc/stdlib/bsearch.c | 85 - libc/upstream-netbsd/libc/stdlib/div.c | 81 - libc/upstream-netbsd/libc/stdlib/drand48.c | 32 - libc/upstream-netbsd/libc/stdlib/erand48.c | 42 - libc/upstream-netbsd/libc/stdlib/exit.c | 63 - libc/upstream-netbsd/libc/stdlib/jrand48.c | 39 - libc/upstream-netbsd/libc/stdlib/ldiv.c | 60 - libc/upstream-netbsd/libc/stdlib/lldiv.c | 66 - libc/upstream-netbsd/libc/stdlib/lrand48.c | 33 - libc/upstream-netbsd/libc/stdlib/mrand48.c | 33 - libc/upstream-netbsd/libc/stdlib/nrand48.c | 38 - libc/upstream-netbsd/libc/stdlib/seed48.c | 49 - libc/upstream-netbsd/libc/stdlib/srand48.c | 38 - libc/upstream-netbsd/libc/stdlib/tdelete.c | 67 - libc/upstream-netbsd/libc/stdlib/tfind.c | 47 - libc/upstream-netbsd/libc/stdlib/tsearch.c | 56 - libc/upstream-netbsd/libc/string/memccpy.c | 61 - libc/upstream-netbsd/libc/string/strcasestr.c | 69 - libc/upstream-netbsd/libc/string/strcoll.c | 59 - libc/upstream-netbsd/libc/string/strxfrm.c | 70 - .../libc/thread-stub/__isthreaded.c | 37 - libc/upstream-netbsd/libc/unistd/killpg.c | 56 - 107 files changed, 8950 insertions(+), 8950 deletions(-) create mode 100644 libc/upstream-netbsd/lib/libc/gen/ftw.c create mode 100644 libc/upstream-netbsd/lib/libc/gen/nftw.c create mode 100644 libc/upstream-netbsd/lib/libc/gen/nice.c create mode 100644 libc/upstream-netbsd/lib/libc/gen/popen.c create mode 100644 libc/upstream-netbsd/lib/libc/gen/psignal.c create mode 100644 libc/upstream-netbsd/lib/libc/gen/setjmperr.c create mode 100644 libc/upstream-netbsd/lib/libc/gen/utime.c create mode 100644 libc/upstream-netbsd/lib/libc/include/isc/assertions.h create mode 100644 libc/upstream-netbsd/lib/libc/include/isc/dst.h create mode 100644 libc/upstream-netbsd/lib/libc/include/isc/eventlib.h create mode 100644 libc/upstream-netbsd/lib/libc/include/isc/heap.h create mode 100644 libc/upstream-netbsd/lib/libc/include/isc/list.h create mode 100644 libc/upstream-netbsd/lib/libc/include/isc/memcluster.h create mode 100644 libc/upstream-netbsd/lib/libc/inet/inet_ntoa.c create mode 100644 libc/upstream-netbsd/lib/libc/inet/inet_ntop.c create mode 100644 libc/upstream-netbsd/lib/libc/inet/inet_pton.c create mode 100644 libc/upstream-netbsd/lib/libc/isc/ev_streams.c create mode 100644 libc/upstream-netbsd/lib/libc/isc/ev_timers.c create mode 100644 libc/upstream-netbsd/lib/libc/isc/eventlib_p.h create mode 100644 libc/upstream-netbsd/lib/libc/regex/cclass.h create mode 100644 libc/upstream-netbsd/lib/libc/regex/cname.h create mode 100644 libc/upstream-netbsd/lib/libc/regex/engine.c create mode 100644 libc/upstream-netbsd/lib/libc/regex/regcomp.c create mode 100644 libc/upstream-netbsd/lib/libc/regex/regerror.c create mode 100644 libc/upstream-netbsd/lib/libc/regex/regex2.h create mode 100644 libc/upstream-netbsd/lib/libc/regex/regexec.c create mode 100644 libc/upstream-netbsd/lib/libc/regex/regfree.c create mode 100644 libc/upstream-netbsd/lib/libc/regex/utils.h create mode 100644 libc/upstream-netbsd/lib/libc/stdio/getdelim.c create mode 100644 libc/upstream-netbsd/lib/libc/stdio/getline.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/_rand48.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/bsearch.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/div.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/drand48.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/erand48.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/exit.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/jrand48.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/ldiv.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/lldiv.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/lrand48.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/mrand48.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/nrand48.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/seed48.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/srand48.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/tdelete.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/tfind.c create mode 100644 libc/upstream-netbsd/lib/libc/stdlib/tsearch.c create mode 100644 libc/upstream-netbsd/lib/libc/string/memccpy.c create mode 100644 libc/upstream-netbsd/lib/libc/string/strcasestr.c create mode 100644 libc/upstream-netbsd/lib/libc/string/strcoll.c create mode 100644 libc/upstream-netbsd/lib/libc/string/strxfrm.c create mode 100644 libc/upstream-netbsd/lib/libc/thread-stub/__isthreaded.c create mode 100644 libc/upstream-netbsd/lib/libc/unistd/killpg.c delete mode 100644 libc/upstream-netbsd/libc/gen/ftw.c delete mode 100644 libc/upstream-netbsd/libc/gen/nftw.c delete mode 100644 libc/upstream-netbsd/libc/gen/nice.c delete mode 100644 libc/upstream-netbsd/libc/gen/popen.c delete mode 100644 libc/upstream-netbsd/libc/gen/psignal.c delete mode 100644 libc/upstream-netbsd/libc/gen/setjmperr.c delete mode 100644 libc/upstream-netbsd/libc/gen/utime.c delete mode 100644 libc/upstream-netbsd/libc/include/isc/assertions.h delete mode 100644 libc/upstream-netbsd/libc/include/isc/dst.h delete mode 100644 libc/upstream-netbsd/libc/include/isc/eventlib.h delete mode 100644 libc/upstream-netbsd/libc/include/isc/heap.h delete mode 100644 libc/upstream-netbsd/libc/include/isc/list.h delete mode 100644 libc/upstream-netbsd/libc/include/isc/memcluster.h delete mode 100644 libc/upstream-netbsd/libc/inet/inet_ntoa.c delete mode 100644 libc/upstream-netbsd/libc/inet/inet_ntop.c delete mode 100644 libc/upstream-netbsd/libc/inet/inet_pton.c delete mode 100644 libc/upstream-netbsd/libc/isc/ev_streams.c delete mode 100644 libc/upstream-netbsd/libc/isc/ev_timers.c delete mode 100644 libc/upstream-netbsd/libc/isc/eventlib_p.h delete mode 100644 libc/upstream-netbsd/libc/regex/cclass.h delete mode 100644 libc/upstream-netbsd/libc/regex/cname.h delete mode 100644 libc/upstream-netbsd/libc/regex/engine.c delete mode 100644 libc/upstream-netbsd/libc/regex/regcomp.c delete mode 100644 libc/upstream-netbsd/libc/regex/regerror.c delete mode 100644 libc/upstream-netbsd/libc/regex/regex2.h delete mode 100644 libc/upstream-netbsd/libc/regex/regexec.c delete mode 100644 libc/upstream-netbsd/libc/regex/regfree.c delete mode 100644 libc/upstream-netbsd/libc/regex/utils.h delete mode 100644 libc/upstream-netbsd/libc/stdio/getdelim.c delete mode 100644 libc/upstream-netbsd/libc/stdio/getline.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/_rand48.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/bsearch.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/div.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/drand48.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/erand48.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/exit.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/jrand48.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/ldiv.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/lldiv.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/lrand48.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/mrand48.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/nrand48.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/seed48.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/srand48.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/tdelete.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/tfind.c delete mode 100644 libc/upstream-netbsd/libc/stdlib/tsearch.c delete mode 100644 libc/upstream-netbsd/libc/string/memccpy.c delete mode 100644 libc/upstream-netbsd/libc/string/strcasestr.c delete mode 100644 libc/upstream-netbsd/libc/string/strcoll.c delete mode 100644 libc/upstream-netbsd/libc/string/strxfrm.c delete mode 100644 libc/upstream-netbsd/libc/thread-stub/__isthreaded.c delete mode 100644 libc/upstream-netbsd/libc/unistd/killpg.c (limited to 'libc') diff --git a/libc/Android.mk b/libc/Android.mk index cd87170..9cde073 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -345,47 +345,47 @@ libc_upstream_freebsd_src_files := \ libc_upstream_netbsd_src_files := \ upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \ upstream-netbsd/common/lib/libc/inet/inet_addr.c \ - upstream-netbsd/libc/gen/ftw.c \ - upstream-netbsd/libc/gen/nftw.c \ - upstream-netbsd/libc/gen/nice.c \ - upstream-netbsd/libc/gen/popen.c \ - upstream-netbsd/libc/gen/psignal.c \ - upstream-netbsd/libc/gen/setjmperr.c \ - upstream-netbsd/libc/gen/utime.c \ - upstream-netbsd/libc/inet/inet_ntoa.c \ - upstream-netbsd/libc/inet/inet_ntop.c \ - upstream-netbsd/libc/inet/inet_pton.c \ - upstream-netbsd/libc/isc/ev_streams.c \ - upstream-netbsd/libc/isc/ev_timers.c \ - upstream-netbsd/libc/regex/regcomp.c \ - upstream-netbsd/libc/regex/regerror.c \ - upstream-netbsd/libc/regex/regexec.c \ - upstream-netbsd/libc/regex/regfree.c \ - upstream-netbsd/libc/stdio/getdelim.c \ - upstream-netbsd/libc/stdio/getline.c \ - upstream-netbsd/libc/stdlib/bsearch.c \ - upstream-netbsd/libc/stdlib/div.c \ - upstream-netbsd/libc/stdlib/drand48.c \ - upstream-netbsd/libc/stdlib/erand48.c \ - upstream-netbsd/libc/stdlib/exit.c \ - upstream-netbsd/libc/stdlib/jrand48.c \ - upstream-netbsd/libc/stdlib/ldiv.c \ - upstream-netbsd/libc/stdlib/lldiv.c \ - upstream-netbsd/libc/stdlib/lrand48.c \ - upstream-netbsd/libc/stdlib/mrand48.c \ - upstream-netbsd/libc/stdlib/nrand48.c \ - upstream-netbsd/libc/stdlib/_rand48.c \ - upstream-netbsd/libc/stdlib/seed48.c \ - upstream-netbsd/libc/stdlib/srand48.c \ - upstream-netbsd/libc/stdlib/tdelete.c \ - upstream-netbsd/libc/stdlib/tfind.c \ - upstream-netbsd/libc/stdlib/tsearch.c \ - upstream-netbsd/libc/string/memccpy.c \ - upstream-netbsd/libc/string/strcasestr.c \ - upstream-netbsd/libc/string/strcoll.c \ - upstream-netbsd/libc/string/strxfrm.c \ - upstream-netbsd/libc/thread-stub/__isthreaded.c \ - upstream-netbsd/libc/unistd/killpg.c \ + upstream-netbsd/lib/libc/gen/ftw.c \ + upstream-netbsd/lib/libc/gen/nftw.c \ + upstream-netbsd/lib/libc/gen/nice.c \ + upstream-netbsd/lib/libc/gen/popen.c \ + upstream-netbsd/lib/libc/gen/psignal.c \ + upstream-netbsd/lib/libc/gen/setjmperr.c \ + upstream-netbsd/lib/libc/gen/utime.c \ + upstream-netbsd/lib/libc/inet/inet_ntoa.c \ + upstream-netbsd/lib/libc/inet/inet_ntop.c \ + upstream-netbsd/lib/libc/inet/inet_pton.c \ + upstream-netbsd/lib/libc/isc/ev_streams.c \ + upstream-netbsd/lib/libc/isc/ev_timers.c \ + upstream-netbsd/lib/libc/regex/regcomp.c \ + upstream-netbsd/lib/libc/regex/regerror.c \ + upstream-netbsd/lib/libc/regex/regexec.c \ + upstream-netbsd/lib/libc/regex/regfree.c \ + upstream-netbsd/lib/libc/stdio/getdelim.c \ + upstream-netbsd/lib/libc/stdio/getline.c \ + upstream-netbsd/lib/libc/stdlib/bsearch.c \ + upstream-netbsd/lib/libc/stdlib/div.c \ + upstream-netbsd/lib/libc/stdlib/drand48.c \ + upstream-netbsd/lib/libc/stdlib/erand48.c \ + upstream-netbsd/lib/libc/stdlib/exit.c \ + upstream-netbsd/lib/libc/stdlib/jrand48.c \ + upstream-netbsd/lib/libc/stdlib/ldiv.c \ + upstream-netbsd/lib/libc/stdlib/lldiv.c \ + upstream-netbsd/lib/libc/stdlib/lrand48.c \ + upstream-netbsd/lib/libc/stdlib/mrand48.c \ + upstream-netbsd/lib/libc/stdlib/nrand48.c \ + upstream-netbsd/lib/libc/stdlib/_rand48.c \ + upstream-netbsd/lib/libc/stdlib/seed48.c \ + upstream-netbsd/lib/libc/stdlib/srand48.c \ + upstream-netbsd/lib/libc/stdlib/tdelete.c \ + upstream-netbsd/lib/libc/stdlib/tfind.c \ + upstream-netbsd/lib/libc/stdlib/tsearch.c \ + upstream-netbsd/lib/libc/string/memccpy.c \ + upstream-netbsd/lib/libc/string/strcasestr.c \ + upstream-netbsd/lib/libc/string/strcoll.c \ + upstream-netbsd/lib/libc/string/strxfrm.c \ + upstream-netbsd/lib/libc/thread-stub/__isthreaded.c \ + upstream-netbsd/lib/libc/unistd/killpg.c \ libc_arch_static_src_files := \ bionic/dl_iterate_phdr_static.cpp \ @@ -508,7 +508,7 @@ LOCAL_CFLAGS := \ $(libc_common_cflags) \ -DINET6 \ -I$(LOCAL_PATH)/private \ - -I$(LOCAL_PATH)/upstream-netbsd/libc/include # for NetBSD private headers + -I$(LOCAL_PATH)/upstream-netbsd/lib/libc/include # for NetBSD private headers LOCAL_CONLYFLAGS := $(libc_common_conlyflags) LOCAL_CPPFLAGS := $(libc_common_cppflags) LOCAL_C_INCLUDES := $(libc_common_c_includes) @@ -560,7 +560,7 @@ LOCAL_CFLAGS := \ $(libc_common_cflags) \ -DPOSIX_MISTAKE \ -I$(LOCAL_PATH)/upstream-netbsd \ - -I$(LOCAL_PATH)/upstream-netbsd/libc/include \ + -I$(LOCAL_PATH)/upstream-netbsd/lib/libc/include \ -include upstream-netbsd/netbsd-compat.h LOCAL_CONLYFLAGS := $(libc_common_conlyflags) LOCAL_CPPFLAGS := $(libc_common_cppflags) diff --git a/libc/upstream-netbsd/lib/libc/gen/ftw.c b/libc/upstream-netbsd/lib/libc/gen/ftw.c new file mode 100644 index 0000000..a7f6bbd --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/gen/ftw.c @@ -0,0 +1,98 @@ +/* $NetBSD: ftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $ */ + +/* From OpenBSD: ftw.c,v 1.2 2003/07/21 21:15:32 millert Exp */ + +/* + * Copyright (c) 2003 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. + */ +#include + +#ifndef lint +__RCSID("$NetBSD: ftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $"); +#endif + +#include +#include +#include +#include +#include +#include + +int +ftw(const char *path, int (*fn)(const char *, const struct stat *, int), + int nfds) +{ + /* LINTED */ + char * const paths[2] = { __UNCONST(path), NULL }; + FTSENT *cur; + FTS *ftsp; + int fnflag, error, sverrno; + + /* XXX - nfds is currently unused */ + if (nfds < 1 || nfds > OPEN_MAX) { + errno = EINVAL; + return (-1); + } + + ftsp = fts_open(paths, FTS_COMFOLLOW | FTS_NOCHDIR, NULL); + if (ftsp == NULL) + return (-1); + error = 0; + while ((cur = fts_read(ftsp)) != NULL) { + switch (cur->fts_info) { + case FTS_D: + fnflag = FTW_D; + break; + case FTS_DNR: + fnflag = FTW_DNR; + break; + case FTS_DP: + /* we only visit in preorder */ + continue; + case FTS_F: + case FTS_DEFAULT: + fnflag = FTW_F; + break; + case FTS_NS: + case FTS_NSOK: + case FTS_SLNONE: + fnflag = FTW_NS; + break; + case FTS_SL: + fnflag = FTW_SL; + break; + case FTS_DC: + errno = ELOOP; + /* FALLTHROUGH */ + default: + error = -1; + goto done; + } + error = fn(cur->fts_path, cur->fts_statp, fnflag); + if (error != 0) + break; + } +done: + sverrno = errno; + if (fts_close(ftsp) != 0 && error == 0) + error = -1; + else + errno = sverrno; + return (error); +} diff --git a/libc/upstream-netbsd/lib/libc/gen/nftw.c b/libc/upstream-netbsd/lib/libc/gen/nftw.c new file mode 100644 index 0000000..0e51342 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/gen/nftw.c @@ -0,0 +1,114 @@ +/* $NetBSD */ + +/* From OpenBSD: nftw.c,v 1.2 2003/07/21 21:15:32 millert Exp */ + +/* + * Copyright (c) 2003 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. + */ + +#include + +#ifndef lint +__RCSID("$NetBSD: nftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $"); +#endif + +#include +#include +#include +#include +#include +#include + +int +nftw(const char *path, int (*fn)(const char *, const struct stat *, int, + struct FTW *), int nfds, int ftwflags) +{ + /* LINTED */ + char * const paths[2] = { __UNCONST(path), NULL }; + struct FTW f; + FTSENT *cur; + FTS *ftsp; + int ftsflags, fnflag, error, postorder, sverrno; + + /* XXX - nfds is currently unused */ + if (nfds < 1 || nfds > OPEN_MAX) { + errno = EINVAL; + return (-1); + } + + ftsflags = FTS_COMFOLLOW; + if (!(ftwflags & FTW_CHDIR)) + ftsflags |= FTS_NOCHDIR; + if (ftwflags & FTW_MOUNT) + ftsflags |= FTS_XDEV; + if (ftwflags & FTW_PHYS) + ftsflags |= FTS_PHYSICAL; + postorder = (ftwflags & FTW_DEPTH) != 0; + ftsp = fts_open(paths, ftsflags, NULL); + if (ftsp == NULL) + return (-1); + error = 0; + while ((cur = fts_read(ftsp)) != NULL) { + switch (cur->fts_info) { + case FTS_D: + if (postorder) + continue; + fnflag = FTW_D; + break; + case FTS_DNR: + fnflag = FTW_DNR; + break; + case FTS_DP: + if (!postorder) + continue; + fnflag = FTW_DP; + break; + case FTS_F: + case FTS_DEFAULT: + fnflag = FTW_F; + break; + case FTS_NS: + case FTS_NSOK: + fnflag = FTW_NS; + break; + case FTS_SL: + fnflag = FTW_SL; + break; + case FTS_SLNONE: + fnflag = FTW_SLN; + break; + case FTS_DC: + errno = ELOOP; + /* FALLTHROUGH */ + default: + error = -1; + goto done; + } + f.base = cur->fts_pathlen - cur->fts_namelen; + f.level = cur->fts_level; + error = fn(cur->fts_path, cur->fts_statp, fnflag, &f); + if (error != 0) + break; + } +done: + sverrno = errno; + (void) fts_close(ftsp); + errno = sverrno; + return (error); +} diff --git a/libc/upstream-netbsd/lib/libc/gen/nice.c b/libc/upstream-netbsd/lib/libc/gen/nice.c new file mode 100644 index 0000000..19d6711 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/gen/nice.c @@ -0,0 +1,70 @@ +/* $NetBSD: nice.c,v 1.13 2011/05/01 02:49:54 christos Exp $ */ + +/* + * 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. 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) +#if 0 +static char sccsid[] = "@(#)nice.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: nice.c,v 1.13 2011/05/01 02:49:54 christos Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include +#include +#include +#include +#include + +#ifdef __weak_alias +__weak_alias(nice,_nice) +#endif + +/* + * Backwards compatible nice. + */ +int +nice(int incr) +{ + int prio; + + errno = 0; + prio = getpriority(PRIO_PROCESS, 0); + if (prio == -1 && errno) + return -1; + if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) { + if (errno == EACCES) + errno = EPERM; + return -1; + } + return getpriority(PRIO_PROCESS, 0); +} diff --git a/libc/upstream-netbsd/lib/libc/gen/popen.c b/libc/upstream-netbsd/lib/libc/gen/popen.c new file mode 100644 index 0000000..593e346 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/gen/popen.c @@ -0,0 +1,227 @@ +/* $NetBSD: popen.c,v 1.32 2012/06/25 22:32:43 abs Exp $ */ + +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software written by Ken Arnold and + * published in UNIX Review, Vol. 6, No. 8. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95"; +#else +__RCSID("$NetBSD: popen.c,v 1.32 2012/06/25 22:32:43 abs Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "env.h" +#include "reentrant.h" + +#ifdef __weak_alias +__weak_alias(popen,_popen) +__weak_alias(pclose,_pclose) +#endif + +static struct pid { + struct pid *next; + FILE *fp; +#ifdef _REENTRANT + int fd; +#endif + pid_t pid; +} *pidlist; + +#ifdef _REENTRANT +static rwlock_t pidlist_lock = RWLOCK_INITIALIZER; +#endif + +FILE * +popen(const char *command, const char *type) +{ + struct pid *cur, *old; + FILE *iop; + const char * volatile xtype = type; + int pdes[2], pid, serrno; + volatile int twoway; + int flags; + + _DIAGASSERT(command != NULL); + _DIAGASSERT(xtype != NULL); + + flags = strchr(xtype, 'e') ? O_CLOEXEC : 0; + if (strchr(xtype, '+')) { + int stype = flags ? (SOCK_STREAM | SOCK_CLOEXEC) : SOCK_STREAM; + twoway = 1; + xtype = "r+"; + if (socketpair(AF_LOCAL, stype, 0, pdes) < 0) + return NULL; + } else { + twoway = 0; + xtype = strrchr(xtype, 'r') ? "r" : "w"; + if (pipe2(pdes, flags) == -1) + return NULL; + } + + if ((cur = malloc(sizeof(struct pid))) == NULL) { + (void)close(pdes[0]); + (void)close(pdes[1]); + errno = ENOMEM; + return (NULL); + } + + (void)rwlock_rdlock(&pidlist_lock); + (void)__readlockenv(); + switch (pid = vfork()) { + case -1: /* Error. */ + serrno = errno; + (void)__unlockenv(); + (void)rwlock_unlock(&pidlist_lock); + free(cur); + (void)close(pdes[0]); + (void)close(pdes[1]); + errno = serrno; + return (NULL); + /* NOTREACHED */ + case 0: /* Child. */ + /* POSIX.2 B.3.2.2 "popen() shall ensure that any streams + from previous popen() calls that remain open in the + parent process are closed in the new child process. */ + for (old = pidlist; old; old = old->next) +#ifdef _REENTRANT + close(old->fd); /* don't allow a flush */ +#else + close(fileno(old->fp)); /* don't allow a flush */ +#endif + + if (*xtype == 'r') { + (void)close(pdes[0]); + if (pdes[1] != STDOUT_FILENO) { + (void)dup2(pdes[1], STDOUT_FILENO); + (void)close(pdes[1]); + } + if (twoway) + (void)dup2(STDOUT_FILENO, STDIN_FILENO); + } else { + (void)close(pdes[1]); + if (pdes[0] != STDIN_FILENO) { + (void)dup2(pdes[0], STDIN_FILENO); + (void)close(pdes[0]); + } + } + + execl(_PATH_BSHELL, "sh", "-c", command, NULL); + _exit(127); + /* NOTREACHED */ + } + (void)__unlockenv(); + + /* Parent; assume fdopen can't fail. */ + if (*xtype == 'r') { + iop = fdopen(pdes[0], xtype); +#ifdef _REENTRANT + cur->fd = pdes[0]; +#endif + (void)close(pdes[1]); + } else { + iop = fdopen(pdes[1], xtype); +#ifdef _REENTRANT + cur->fd = pdes[1]; +#endif + (void)close(pdes[0]); + } + + /* Link into list of file descriptors. */ + cur->fp = iop; + cur->pid = pid; + cur->next = pidlist; + pidlist = cur; + (void)rwlock_unlock(&pidlist_lock); + + return (iop); +} + +/* + * pclose -- + * Pclose returns -1 if stream is not associated with a `popened' command, + * if already `pclosed', or waitpid returns an error. + */ +int +pclose(FILE *iop) +{ + struct pid *cur, *last; + int pstat; + pid_t pid; + + _DIAGASSERT(iop != NULL); + + rwlock_wrlock(&pidlist_lock); + + /* Find the appropriate file pointer. */ + for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next) + if (cur->fp == iop) + break; + if (cur == NULL) { + (void)rwlock_unlock(&pidlist_lock); + return (-1); + } + + (void)fclose(iop); + + /* Remove the entry from the linked list. */ + if (last == NULL) + pidlist = cur->next; + else + last->next = cur->next; + + (void)rwlock_unlock(&pidlist_lock); + + do { + pid = waitpid(cur->pid, &pstat, 0); + } while (pid == -1 && errno == EINTR); + + free(cur); + + return (pid == -1 ? -1 : pstat); +} diff --git a/libc/upstream-netbsd/lib/libc/gen/psignal.c b/libc/upstream-netbsd/lib/libc/gen/psignal.c new file mode 100644 index 0000000..4472be6 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/gen/psignal.c @@ -0,0 +1,85 @@ +/* $NetBSD: psignal.c,v 1.23 2012/03/13 21:13:36 christos Exp $ */ + +/* + * 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. 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) +#if 0 +static char sccsid[] = "@(#)psignal.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: psignal.c,v 1.23 2012/03/13 21:13:36 christos Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" + +#include +#include + +#include +#include +#include +#include + +#include "extern.h" + +#ifdef __weak_alias +__weak_alias(psignal,_psignal) +#endif + +void +psignal(int sig, const char *s) +{ + struct iovec *v; + struct iovec iov[4]; + char buf[NL_TEXTMAX]; + + v = iov; + if (s && *s) { + v->iov_base = __UNCONST(s); + v->iov_len = strlen(s); + v++; + v->iov_base = __UNCONST(": "); + v->iov_len = 2; + v++; + } + v->iov_base = __UNCONST(__strsignal((int)sig, buf, sizeof(buf))); + v->iov_len = strlen(v->iov_base); + v++; + v->iov_base = __UNCONST("\n"); + v->iov_len = 1; + (void)writev(STDERR_FILENO, iov, (int)((v - iov) + 1)); +} + +void +psiginfo(const siginfo_t *si, const char *s) +{ + psignal(si->si_signo, s); +} diff --git a/libc/upstream-netbsd/lib/libc/gen/setjmperr.c b/libc/upstream-netbsd/lib/libc/gen/setjmperr.c new file mode 100644 index 0000000..5b1432e --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/gen/setjmperr.c @@ -0,0 +1,56 @@ +/* $NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $ */ + +/* + * Copyright (c) 1980, 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)setjmperr.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +/* + * This routine is called from longjmp() when an error occurs. + * Programs that wish to exit gracefully from this error may + * write their own versions. + * If this routine returns, the program is aborted. + */ + +#include +#include + +void +longjmperror(void) +{ +#define ERRMSG "longjmp botch.\n" + (void)write(STDERR_FILENO, ERRMSG, sizeof(ERRMSG) - 1); +} diff --git a/libc/upstream-netbsd/lib/libc/gen/utime.c b/libc/upstream-netbsd/lib/libc/gen/utime.c new file mode 100644 index 0000000..d41aac7 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/gen/utime.c @@ -0,0 +1,65 @@ +/* $NetBSD: utime.c,v 1.14 2012/06/25 22:32:44 abs Exp $ */ + +/*- + * 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. 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) +#if 0 +static char sccsid[] = "@(#)utime.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: utime.c,v 1.14 2012/06/25 22:32:44 abs Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include + +#include +#include +#include +#include + +int +utime(const char *path, const struct utimbuf *times) +{ + struct timeval tv[2], *tvp; + + _DIAGASSERT(path != NULL); + + if (times == (struct utimbuf *) NULL) + tvp = NULL; + else { + tv[0].tv_sec = times->actime; + tv[1].tv_sec = times->modtime; + tv[0].tv_usec = tv[1].tv_usec = 0; + tvp = tv; + } + return (utimes(path, tvp)); +} diff --git a/libc/upstream-netbsd/lib/libc/include/isc/assertions.h b/libc/upstream-netbsd/lib/libc/include/isc/assertions.h new file mode 100644 index 0000000..7db7361 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/include/isc/assertions.h @@ -0,0 +1,132 @@ +/* $NetBSD: assertions.h,v 1.5 2009/04/12 17:07:16 christos Exp $ */ + +/* + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1997-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or 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 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. + */ + +/* + * Id: assertions.h,v 1.5 2008/11/14 02:36:51 marka Exp + */ + +#ifndef ASSERTIONS_H +#define ASSERTIONS_H 1 + +typedef enum { + assert_require, assert_ensure, assert_insist, assert_invariant +} assertion_type; + +typedef void (*assertion_failure_callback)(const char *, int, assertion_type, + const char *, int); + +/* coverity[+kill] */ +extern assertion_failure_callback __assertion_failed; +void set_assertion_failure_callback(assertion_failure_callback f); +const char *assertion_type_to_text(assertion_type type); + +#if defined(CHECK_ALL) || defined(__COVERITY__) +#define CHECK_REQUIRE 1 +#define CHECK_ENSURE 1 +#define CHECK_INSIST 1 +#define CHECK_INVARIANT 1 +#endif + +#if defined(CHECK_NONE) && !defined(__COVERITY__) +#define CHECK_REQUIRE 0 +#define CHECK_ENSURE 0 +#define CHECK_INSIST 0 +#define CHECK_INVARIANT 0 +#endif + +#ifdef _DIAGNOSTIC +#ifndef CHECK_REQUIRE +#define CHECK_REQUIRE 1 +#endif + +#ifndef CHECK_ENSURE +#define CHECK_ENSURE 1 +#endif + +#ifndef CHECK_INSIST +#define CHECK_INSIST 1 +#endif + +#ifndef CHECK_INVARIANT +#define CHECK_INVARIANT 1 +#endif +#endif /* _DIAGNOSTIC */ + +#if CHECK_REQUIRE != 0 +#define REQUIRE(cond) \ + ((void) ((cond) || \ + ((__assertion_failed)(__FILE__, __LINE__, assert_require, \ + #cond, 0), 0))) +#define REQUIRE_ERR(cond) \ + ((void) ((cond) || \ + ((__assertion_failed)(__FILE__, __LINE__, assert_require, \ + #cond, 1), 0))) +#else +#define REQUIRE(cond) ((void) (cond)) +#define REQUIRE_ERR(cond) ((void) (cond)) +#endif /* CHECK_REQUIRE */ + +#if CHECK_ENSURE != 0 +#define ENSURE(cond) \ + ((void) ((cond) || \ + ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \ + #cond, 0), 0))) +#define ENSURE_ERR(cond) \ + ((void) ((cond) || \ + ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \ + #cond, 1), 0))) +#else +#define ENSURE(cond) ((void) (cond)) +#define ENSURE_ERR(cond) ((void) (cond)) +#endif /* CHECK_ENSURE */ + +#if CHECK_INSIST != 0 +#define INSIST(cond) \ + ((void) ((cond) || \ + ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \ + #cond, 0), 0))) +#define INSIST_ERR(cond) \ + ((void) ((cond) || \ + ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \ + #cond, 1), 0))) +#else +#if !defined(__lint__) +#define INSIST(cond) ((void) (cond)) +#define INSIST_ERR(cond) ((void) (cond)) +#else /* !__lint__ */ +#define INSIST(cond) +#define INSIST_ERR(cond) +#endif /* !__lint__ */ +#endif /* CHECK_INSIST */ + +#if CHECK_INVARIANT != 0 +#define INVARIANT(cond) \ + ((void) ((cond) || \ + ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \ + #cond, 0), 0))) +#define INVARIANT_ERR(cond) \ + ((void) ((cond) || \ + ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \ + #cond, 1), 0))) +#else +#define INVARIANT(cond) ((void) (cond)) +#define INVARIANT_ERR(cond) ((void) (cond)) +#endif /* CHECK_INVARIANT */ +#endif /* ASSERTIONS_H */ +/*! \file */ diff --git a/libc/upstream-netbsd/lib/libc/include/isc/dst.h b/libc/upstream-netbsd/lib/libc/include/isc/dst.h new file mode 100644 index 0000000..5537e3d --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/include/isc/dst.h @@ -0,0 +1,170 @@ +/* $NetBSD: dst.h,v 1.1.1.4 2009/04/12 16:35:44 christos Exp $ */ + +#ifndef DST_H +#define DST_H + +#ifndef HAS_DST_KEY +typedef struct dst_key { + char *dk_key_name; /*%< name of the key */ + int dk_key_size; /*%< this is the size of the key in bits */ + int dk_proto; /*%< what protocols this key can be used for */ + int dk_alg; /*%< algorithm number from key record */ + u_int32_t dk_flags; /*%< and the flags of the public key */ + u_int16_t dk_id; /*%< identifier of the key */ +} DST_KEY; +#endif /* HAS_DST_KEY */ +/* + * do not taint namespace + */ +#define dst_bsafe_init __dst_bsafe_init +#define dst_buffer_to_key __dst_buffer_to_key +#define dst_check_algorithm __dst_check_algorithm +#define dst_compare_keys __dst_compare_keys +#define dst_cylink_init __dst_cylink_init +#define dst_dnskey_to_key __dst_dnskey_to_key +#define dst_eay_dss_init __dst_eay_dss_init +#define dst_free_key __dst_free_key +#define dst_generate_key __dst_generate_key +#define dst_hmac_md5_init __dst_hmac_md5_init +#define dst_init __dst_init +#define dst_key_to_buffer __dst_key_to_buffer +#define dst_key_to_dnskey __dst_key_to_dnskey +#define dst_read_key __dst_read_key +#define dst_rsaref_init __dst_rsaref_init +#define dst_s_build_filename __dst_s_build_filename +#define dst_s_calculate_bits __dst_s_calculate_bits +#define dst_s_conv_bignum_b64_to_u8 __dst_s_conv_bignum_b64_to_u8 +#define dst_s_conv_bignum_u8_to_b64 __dst_s_conv_bignum_u8_to_b64 +#define dst_s_dns_key_id __dst_s_dns_key_id +#define dst_s_dump __dst_s_dump +#define dst_s_filename_length __dst_s_filename_length +#define dst_s_fopen __dst_s_fopen +#define dst_s_get_int16 __dst_s_get_int16 +#define dst_s_get_int32 __dst_s_get_int32 +#define dst_s_id_calc __dst_s_id_calc +#define dst_s_put_int16 __dst_s_put_int16 +#define dst_s_put_int32 __dst_s_put_int32 +#define dst_s_quick_random __dst_s_quick_random +#define dst_s_quick_random_set __dst_s_quick_random_set +#define dst_s_random __dst_s_random +#define dst_s_semi_random __dst_s_semi_random +#define dst_s_verify_str __dst_s_verify_str +#define dst_sig_size __dst_sig_size +#define dst_sign_data __dst_sign_data +#define dst_verify_data __dst_verify_data +#define dst_write_key __dst_write_key + +/* + * DST Crypto API defintions + */ +void dst_init(void); +int dst_check_algorithm(const int); + + +int dst_sign_data(const int, /*!< specifies INIT/UPDATE/FINAL/ALL */ + DST_KEY *, /*!< the key to use */ + void **, /*!< pointer to state structure */ + const u_char *, /*!< data to be signed */ + const int, /*!< length of input data */ + u_char *, /*!< buffer to write signature to */ + const int); /*!< size of output buffer */ +int dst_verify_data(const int, /*!< specifies INIT/UPDATE/FINAL/ALL */ + DST_KEY *, /*!< the key to use */ + void **, /*!< pointer to state structure */ + const u_char *, /*!< data to be verified */ + const int, /*!< length of input data */ + const u_char *, /*!< buffer containing signature */ + const int); /*!< length of signature */ +DST_KEY *dst_read_key(const char *, /*!< name of key */ + const u_int16_t, /*!< key tag identifier */ + const int, /*!< key algorithm */ + const int); /*!< Private/PublicKey wanted */ +int dst_write_key(const DST_KEY *, /*!< key to write out */ + const int); /*!< Public/Private */ +DST_KEY *dst_dnskey_to_key(const char *, /*!< KEY record name */ + const u_char *, /*!< KEY RDATA */ + const int); /*!< size of input buffer */ +int dst_key_to_dnskey(const DST_KEY *, /*!< key to translate */ + u_char *, /*!< output buffer */ + const int); /*!< size of out_storage */ +DST_KEY *dst_buffer_to_key(const char *, /*!< name of the key */ + const int, /*!< algorithm */ + const int, /*!< dns flags */ + const int, /*!< dns protocol */ + const u_char *, /*!< key in dns wire fmt */ + const int); /*!< size of key */ +int dst_key_to_buffer(DST_KEY *, u_char *, int); + +DST_KEY *dst_generate_key(const char *, /*!< name of new key */ + const int, /*!< key algorithm to generate */ + const int, /*!< size of new key */ + const int, /*!< alg dependent parameter */ + const int, /*!< key DNS flags */ + const int); /*!< key DNS protocol */ +DST_KEY *dst_free_key(DST_KEY *); +int dst_compare_keys(const DST_KEY *, const DST_KEY *); + +int dst_sig_size(DST_KEY *); + + +/* support for dns key tags/ids */ +u_int16_t dst_s_dns_key_id(const u_char *, const int); +u_int16_t dst_s_id_calc(const u_char *, const int); + +/* Used by callers as well as by the library. */ +#define RAW_KEY_SIZE 8192 /*%< large enough to store any key */ +/* DST_API control flags */ +/* These are used used in functions dst_sign_data and dst_verify_data */ +#define SIG_MODE_INIT 1 /*%< initialize digest */ +#define SIG_MODE_UPDATE 2 /*%< add data to digest */ +#define SIG_MODE_FINAL 4 /*%< generate/verify signature */ +#define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL) + +/* Flags for dst_read_private_key() */ +#define DST_FORCE_READ 0x1000000 +#define DST_CAN_SIGN 0x010F +#define DST_NO_AUTHEN 0x8000 +#define DST_EXTEND_FLAG 0x1000 +#define DST_STANDARD 0 +#define DST_PRIVATE 0x2000000 +#define DST_PUBLIC 0x4000000 +#define DST_RAND_SEMI 1 +#define DST_RAND_STD 2 +#define DST_RAND_KEY 3 +#define DST_RAND_DSS 4 + + +/* DST algorithm codes */ +#define KEY_RSA 1 +#define KEY_DH 2 +#define KEY_DSA 3 +#define KEY_PRIVATE 254 +#define KEY_EXPAND 255 +#define KEY_HMAC_MD5 157 +#define KEY_HMAC_SHA1 158 +#define UNKNOWN_KEYALG 0 +#define DST_MAX_ALGS KEY_HMAC_SHA1 + +/* DST constants to locations in KEY record changes in new KEY record */ +#define DST_FLAGS_SIZE 2 +#define DST_KEY_PROT 2 +#define DST_KEY_ALG 3 +#define DST_EXT_FLAG 4 +#define DST_KEY_START 4 + +#ifndef SIGN_F_NOKEY +#define SIGN_F_NOKEY 0xC000 +#endif + +/* error codes from dst routines */ +#define SIGN_INIT_FAILURE (-23) +#define SIGN_UPDATE_FAILURE (-24) +#define SIGN_FINAL_FAILURE (-25) +#define VERIFY_INIT_FAILURE (-26) +#define VERIFY_UPDATE_FAILURE (-27) +#define VERIFY_FINAL_FAILURE (-28) +#define MISSING_KEY_OR_SIGNATURE (-30) +#define UNSUPPORTED_KEYALG (-31) + +#endif /* DST_H */ +/*! \file */ diff --git a/libc/upstream-netbsd/lib/libc/include/isc/eventlib.h b/libc/upstream-netbsd/lib/libc/include/isc/eventlib.h new file mode 100644 index 0000000..4e9cc2e --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/include/isc/eventlib.h @@ -0,0 +1,206 @@ +/* $NetBSD: eventlib.h,v 1.3 2009/04/12 17:07:16 christos Exp $ */ + +/* + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1995-1999, 2001, 2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or 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 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. + */ + +/* eventlib.h - exported interfaces for eventlib + * vix 09sep95 [initial] + * + * Id: eventlib.h,v 1.7 2008/11/14 02:36:51 marka Exp + */ + +#ifndef _EVENTLIB_H +#define _EVENTLIB_H + +#include +#include +#include +#include + +#ifndef __P +# define __EVENTLIB_P_DEFINED +# ifdef __STDC__ +# define __P(x) x +# else +# define __P(x) () +# endif +#endif + +/* In the absence of branded types... */ +typedef struct { void *opaque; } evConnID; +typedef struct { void *opaque; } evFileID; +typedef struct { void *opaque; } evStreamID; +typedef struct { void *opaque; } evTimerID; +typedef struct { void *opaque; } evWaitID; +typedef struct { void *opaque; } evContext; +typedef struct { void *opaque; } evEvent; + +#define evInitID(id) ((id)->opaque = NULL) +#define evTestID(id) ((id).opaque != NULL) + +typedef void (*evConnFunc)__P((evContext, void *, int, const void *, int, + const void *, int)); +typedef void (*evFileFunc)__P((evContext, void *, int, int)); +typedef void (*evStreamFunc)__P((evContext, void *, int, int)); +typedef void (*evTimerFunc)__P((evContext, void *, + struct timespec, struct timespec)); +typedef void (*evWaitFunc)__P((evContext, void *, const void *)); + +typedef struct { unsigned char mask[256/8]; } evByteMask; +#define EV_BYTEMASK_BYTE(b) ((b) / 8) +#define EV_BYTEMASK_MASK(b) (1 << ((b) % 8)) +#define EV_BYTEMASK_SET(bm, b) \ + ((bm).mask[EV_BYTEMASK_BYTE(b)] |= EV_BYTEMASK_MASK(b)) +#define EV_BYTEMASK_CLR(bm, b) \ + ((bm).mask[EV_BYTEMASK_BYTE(b)] &= ~EV_BYTEMASK_MASK(b)) +#define EV_BYTEMASK_TST(bm, b) \ + ((bm).mask[EV_BYTEMASK_BYTE(b)] & EV_BYTEMASK_MASK(b)) + +#define EV_POLL 1 +#define EV_WAIT 2 +#define EV_NULL 4 + +#define EV_READ 1 +#define EV_WRITE 2 +#define EV_EXCEPT 4 + +#define EV_WASNONBLOCKING 8 /* Internal library use. */ + +/* eventlib.c */ +#define evCreate __evCreate +#define evSetDebug __evSetDebug +#define evDestroy __evDestroy +#define evGetNext __evGetNext +#define evDispatch __evDispatch +#define evDrop __evDrop +#define evMainLoop __evMainLoop +#define evHighestFD __evHighestFD +#define evGetOption __evGetOption +#define evSetOption __evSetOption + +int evCreate __P((evContext *)); +void evSetDebug __P((evContext, int, FILE *)); +int evDestroy __P((evContext)); +int evGetNext __P((evContext, evEvent *, int)); +int evDispatch __P((evContext, evEvent)); +void evDrop __P((evContext, evEvent)); +int evMainLoop __P((evContext)); +int evHighestFD __P((evContext)); +int evGetOption __P((evContext *, const char *, int *)); +int evSetOption __P((evContext *, const char *, int)); + +/* ev_connects.c */ +#define evListen __evListen +#define evConnect __evConnect +#define evCancelConn __evCancelConn +#define evHold __evHold +#define evUnhold __evUnhold +#define evTryAccept __evTryAccept + +int evListen __P((evContext, int, int, evConnFunc, void *, evConnID *)); +int evConnect __P((evContext, int, const void *, int, + evConnFunc, void *, evConnID *)); +int evCancelConn __P((evContext, evConnID)); +int evHold __P((evContext, evConnID)); +int evUnhold __P((evContext, evConnID)); +int evTryAccept __P((evContext, evConnID, int *)); + +/* ev_files.c */ +#define evSelectFD __evSelectFD +#define evDeselectFD __evDeselectFD + +int evSelectFD __P((evContext, int, int, evFileFunc, void *, evFileID *)); +int evDeselectFD __P((evContext, evFileID)); + +/* ev_streams.c */ +#define evConsIovec __evConsIovec +#define evWrite __evWrite +#define evRead __evRead +#define evTimeRW __evTimeRW +#define evUntimeRW __evUntimeRW +#define evCancelRW __evCancelRW + +struct iovec evConsIovec __P((void *, size_t)); +int evWrite __P((evContext, int, const struct iovec *, int, + evStreamFunc func, void *, evStreamID *)); +int evRead __P((evContext, int, const struct iovec *, int, + evStreamFunc func, void *, evStreamID *)); +int evTimeRW __P((evContext, evStreamID, evTimerID timer)); +int evUntimeRW __P((evContext, evStreamID)); +int evCancelRW __P((evContext, evStreamID)); + +/* ev_timers.c */ +#define evConsTime __evConsTime +#define evAddTime __evAddTime +#define evSubTime __evSubTime +#define evCmpTime __evCmpTime +#define evTimeSpec __evTimeSpec +#define evTimeVal __evTimeVal + +#define evNowTime __evNowTime +#define evUTCTime __evUTCTime +#define evLastEventTime __evLastEventTime +#define evSetTimer __evSetTimer +#define evClearTimer __evClearTimer +#define evConfigTimer __evConfigTimer +#define evResetTimer __evResetTimer +#define evSetIdleTimer __evSetIdleTimer +#define evClearIdleTimer __evClearIdleTimer +#define evResetIdleTimer __evResetIdleTimer +#define evTouchIdleTimer __evTouchIdleTimer + +struct timespec evConsTime __P((time_t sec, long nsec)); +struct timespec evAddTime __P((struct timespec, struct timespec)); +struct timespec evSubTime __P((struct timespec, struct timespec)); +struct timespec evNowTime __P((void)); +struct timespec evUTCTime __P((void)); +struct timespec evLastEventTime __P((evContext)); +struct timespec evTimeSpec __P((struct timeval)); +struct timeval evTimeVal __P((struct timespec)); +int evCmpTime __P((struct timespec, struct timespec)); +int evSetTimer __P((evContext, evTimerFunc, void *, struct timespec, + struct timespec, evTimerID *)); +int evClearTimer __P((evContext, evTimerID)); +int evConfigTimer __P((evContext, evTimerID, const char *param, + int value)); +int evResetTimer __P((evContext, evTimerID, evTimerFunc, void *, + struct timespec, struct timespec)); +int evSetIdleTimer __P((evContext, evTimerFunc, void *, struct timespec, + evTimerID *)); +int evClearIdleTimer __P((evContext, evTimerID)); +int evResetIdleTimer __P((evContext, evTimerID, evTimerFunc, void *, + struct timespec)); +int evTouchIdleTimer __P((evContext, evTimerID)); + +/* ev_waits.c */ +#define evWaitFor __evWaitFor +#define evDo __evDo +#define evUnwait __evUnwait +#define evDefer __evDefer + +int evWaitFor __P((evContext, const void *, evWaitFunc, void *, evWaitID *)); +int evDo __P((evContext, const void *)); +int evUnwait __P((evContext, evWaitID)); +int evDefer __P((evContext, evWaitFunc, void *)); + +#ifdef __EVENTLIB_P_DEFINED +# undef __P +#endif + +#endif /*_EVENTLIB_H*/ + +/*! \file */ diff --git a/libc/upstream-netbsd/lib/libc/include/isc/heap.h b/libc/upstream-netbsd/lib/libc/include/isc/heap.h new file mode 100644 index 0000000..30cec98 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/include/isc/heap.h @@ -0,0 +1,51 @@ +/* $NetBSD: heap.h,v 1.1.1.4 2009/04/12 16:35:44 christos Exp $ */ + +/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1997,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 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. + */ + +typedef int (*heap_higher_priority_func)(void *, void *); +typedef void (*heap_index_func)(void *, int); +typedef void (*heap_for_each_func)(void *, void *); + +typedef struct heap_context { + int array_size; + int array_size_increment; + int heap_size; + void **heap; + heap_higher_priority_func higher_priority; + heap_index_func index; +} *heap_context; + +#define heap_new __heap_new +#define heap_free __heap_free +#define heap_insert __heap_insert +#define heap_delete __heap_delete +#define heap_increased __heap_increased +#define heap_decreased __heap_decreased +#define heap_element __heap_element +#define heap_for_each __heap_for_each + +heap_context heap_new(heap_higher_priority_func, heap_index_func, int); +int heap_free(heap_context); +int heap_insert(heap_context, void *); +int heap_delete(heap_context, int); +int heap_increased(heap_context, int); +int heap_decreased(heap_context, int); +void * heap_element(heap_context, int); +int heap_for_each(heap_context, heap_for_each_func, void *); + +/*! \file */ diff --git a/libc/upstream-netbsd/lib/libc/include/isc/list.h b/libc/upstream-netbsd/lib/libc/include/isc/list.h new file mode 100644 index 0000000..46f2e79 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/include/isc/list.h @@ -0,0 +1,120 @@ +/* $NetBSD: list.h,v 1.5 2009/04/12 17:07:16 christos Exp $ */ + +/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1997,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 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. + */ + +#ifndef LIST_H +#define LIST_H 1 +#include + +#define LIST(type) struct { type *head, *tail; } +#define INIT_LIST(list) \ + do { (list).head = NULL; (list).tail = NULL; } while (/*CONSTCOND*/0) + +#define LINK(type) struct { type *prev, *next; } +#define INIT_LINK_TYPE(elt, link, type) \ + do { \ + (elt)->link.prev = (type *)(-1); \ + (elt)->link.next = (type *)(-1); \ + } while (/*CONSTCOND*/0) +#define INIT_LINK(elt, link) \ + INIT_LINK_TYPE(elt, link, void) +#define LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1) && \ + (void *)((elt)->link.next) != (void *)(-1)) + +#define HEAD(list) ((list).head) +#define TAIL(list) ((list).tail) +#define EMPTY(list) ((list).head == NULL) + +#define PREPEND(list, elt, link) \ + do { \ + INSIST(!LINKED(elt, link));\ + if ((list).head != NULL) \ + (list).head->link.prev = (elt); \ + else \ + (list).tail = (elt); \ + (elt)->link.prev = NULL; \ + (elt)->link.next = (list).head; \ + (list).head = (elt); \ + } while (/*CONSTCOND*/0) + +#define APPEND(list, elt, link) \ + do { \ + INSIST(!LINKED(elt, link));\ + if ((list).tail != NULL) \ + (list).tail->link.next = (elt); \ + else \ + (list).head = (elt); \ + (elt)->link.prev = (list).tail; \ + (elt)->link.next = NULL; \ + (list).tail = (elt); \ + } while (/*CONSTCOND*/0) + +#define UNLINK_TYPE(list, elt, link, type) \ + do { \ + INSIST(LINKED(elt, link));\ + if ((elt)->link.next != NULL) \ + (elt)->link.next->link.prev = (elt)->link.prev; \ + else { \ + INSIST((list).tail == (elt)); \ + (list).tail = (elt)->link.prev; \ + } \ + if ((elt)->link.prev != NULL) \ + (elt)->link.prev->link.next = (elt)->link.next; \ + else { \ + INSIST((list).head == (elt)); \ + (list).head = (elt)->link.next; \ + } \ + INIT_LINK_TYPE(elt, link, type); \ + } while (/*CONSTCOND*/0) +#define UNLINK(list, elt, link) \ + UNLINK_TYPE(list, elt, link, void) + +#define PREV(elt, link) ((elt)->link.prev) +#define NEXT(elt, link) ((elt)->link.next) + +#define INSERT_BEFORE(list, before, elt, link) \ + do { \ + INSIST(!LINKED(elt, link));\ + if ((before)->link.prev == NULL) \ + PREPEND(list, elt, link); \ + else { \ + (elt)->link.prev = (before)->link.prev; \ + (before)->link.prev = (elt); \ + (elt)->link.prev->link.next = (elt); \ + (elt)->link.next = (before); \ + } \ + } while (/*CONSTCOND*/0) + +#define INSERT_AFTER(list, after, elt, link) \ + do { \ + INSIST(!LINKED(elt, link));\ + if ((after)->link.next == NULL) \ + APPEND(list, elt, link); \ + else { \ + (elt)->link.next = (after)->link.next; \ + (after)->link.next = (elt); \ + (elt)->link.next->link.prev = (elt); \ + (elt)->link.prev = (after); \ + } \ + } while (/*CONSTCOND*/0) + +#define ENQUEUE(list, elt, link) APPEND(list, elt, link) +#define DEQUEUE(list, elt, link) UNLINK(list, elt, link) + +#endif /* LIST_H */ +/*! \file */ diff --git a/libc/upstream-netbsd/lib/libc/include/isc/memcluster.h b/libc/upstream-netbsd/lib/libc/include/isc/memcluster.h new file mode 100644 index 0000000..3c1b489 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/include/isc/memcluster.h @@ -0,0 +1,52 @@ +/* $NetBSD: memcluster.h,v 1.1.1.4 2009/04/12 16:35:44 christos Exp $ */ + +/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1997,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 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. + */ + +#ifndef MEMCLUSTER_H +#define MEMCLUSTER_H + +#include + +#define meminit __meminit +#ifdef MEMCLUSTER_DEBUG +#define memget(s) __memget_debug(s, __FILE__, __LINE__) +#define memput(p, s) __memput_debug(p, s, __FILE__, __LINE__) +#else /*MEMCLUSTER_DEBUG*/ +#ifdef MEMCLUSTER_RECORD +#define memget(s) __memget_record(s, __FILE__, __LINE__) +#define memput(p, s) __memput_record(p, s, __FILE__, __LINE__) +#else /*MEMCLUSTER_RECORD*/ +#define memget __memget +#define memput __memput +#endif /*MEMCLUSTER_RECORD*/ +#endif /*MEMCLUSTER_DEBUG*/ +#define memstats __memstats +#define memactive __memactive + +int meminit(size_t, size_t); +void * __memget(size_t); +void __memput(void *, size_t); +void * __memget_debug(size_t, const char *, int); +void __memput_debug(void *, size_t, const char *, int); +void * __memget_record(size_t, const char *, int); +void __memput_record(void *, size_t, const char *, int); +void memstats(FILE *); +int memactive(void); + +#endif /* MEMCLUSTER_H */ +/*! \file */ diff --git a/libc/upstream-netbsd/lib/libc/inet/inet_ntoa.c b/libc/upstream-netbsd/lib/libc/inet/inet_ntoa.c new file mode 100644 index 0000000..6ed023b --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/inet/inet_ntoa.c @@ -0,0 +1,64 @@ +/* $NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $ */ + +/* + * 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. 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) +#if 0 +static char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include +#include +#include +#include +#include +#include + +#ifdef __weak_alias +__weak_alias(inet_ntoa,_inet_ntoa) +#endif + +/* + * Convert network-format internet address + * to base 256 d.d.d.d representation. + */ +/*const*/ char * +inet_ntoa(struct in_addr in) { + static char ret[18]; + + strlcpy(ret, "[inet_ntoa error]", sizeof(ret)); + (void) inet_ntop(AF_INET, &in, ret, (socklen_t)sizeof ret); + return ret; +} diff --git a/libc/upstream-netbsd/lib/libc/inet/inet_ntop.c b/libc/upstream-netbsd/lib/libc/inet/inet_ntop.c new file mode 100644 index 0000000..00c55a8 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/inet/inet_ntop.c @@ -0,0 +1,232 @@ +/* $NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $ */ + +/* + * 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 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp"; +#else +__RCSID("$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "port_before.h" + +#include "namespace.h" +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "port_after.h" + +#ifdef __weak_alias +__weak_alias(inet_ntop,_inet_ntop) +#endif + +/*% + * WARNING: Don't even consider trying to compile this on a system where + * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. + */ + +static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size); +static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size); + +/* char * + * inet_ntop(af, src, dst, size) + * convert a network format address to presentation format. + * return: + * pointer to presentation format address (`dst'), or NULL (see errno). + * author: + * Paul Vixie, 1996. + */ +const char * +inet_ntop(int af, const void *src, char *dst, socklen_t size) +{ + + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); + + switch (af) { + case AF_INET: + return (inet_ntop4(src, dst, size)); + case AF_INET6: + return (inet_ntop6(src, dst, size)); + default: + errno = EAFNOSUPPORT; + return (NULL); + } + /* NOTREACHED */ +} + +/* const char * + * inet_ntop4(src, dst, size) + * format an IPv4 address, more or less like inet_ntoa() + * return: + * `dst' (as a const) + * notes: + * (1) uses no statics + * (2) takes a u_char* not an in_addr as input + * author: + * Paul Vixie, 1996. + */ +static const char * +inet_ntop4(const u_char *src, char *dst, socklen_t size) +{ + char tmp[sizeof "255.255.255.255"]; + int l; + + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); + + l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u", + src[0], src[1], src[2], src[3]); + if (l <= 0 || (socklen_t) l >= size) { + errno = ENOSPC; + return (NULL); + } + strlcpy(dst, tmp, size); + return (dst); +} + +/* const char * + * inet_ntop6(src, dst, size) + * convert IPv6 binary address into presentation (printable) format + * author: + * Paul Vixie, 1996. + */ +static const char * +inet_ntop6(const u_char *src, char *dst, socklen_t size) +{ + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; + char *tp, *ep; + struct { int base, len; } best, cur; + u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; + int i; + int advance; + + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); + + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + memset(words, '\0', sizeof words); + for (i = 0; i < NS_IN6ADDRSZ; i++) + words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); + best.base = -1; + best.len = 0; + cur.base = -1; + cur.len = 0; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { + if (words[i] == 0) { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } else { + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } + } + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + } + if (best.base != -1 && best.len < 2) + best.base = -1; + + /* + * Format the result. + */ + tp = tmp; + ep = tmp + sizeof(tmp); + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { + /* Are we inside the best run of 0x00's? */ + if (best.base != -1 && i >= best.base && + i < (best.base + best.len)) { + if (i == best.base) + *tp++ = ':'; + continue; + } + /* Are we following an initial run of 0x00s or any real hex? */ + if (i != 0) { + if (tp + 1 >= ep) + return (NULL); + *tp++ = ':'; + } + /* Is this address an encapsulated IPv4? */ + if (i == 6 && best.base == 0 && + (best.len == 6 || + (best.len == 7 && words[7] != 0x0001) || + (best.len == 5 && words[5] == 0xffff))) { + if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp))) + return (NULL); + tp += strlen(tp); + break; + } + advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]); + if (advance <= 0 || advance >= ep - tp) + return (NULL); + tp += advance; + } + /* Was it a trailing run of 0x00's? */ + if (best.base != -1 && (best.base + best.len) == + (NS_IN6ADDRSZ / NS_INT16SZ)) { + if (tp + 1 >= ep) + return (NULL); + *tp++ = ':'; + } + if (tp + 1 >= ep) + return (NULL); + *tp++ = '\0'; + + /* + * Check for overflow, copy, and we're done. + */ + if ((size_t)(tp - tmp) > size) { + errno = ENOSPC; + return (NULL); + } + strlcpy(dst, tmp, size); + return (dst); +} + +/*! \file */ diff --git a/libc/upstream-netbsd/lib/libc/inet/inet_pton.c b/libc/upstream-netbsd/lib/libc/inet/inet_pton.c new file mode 100644 index 0000000..c1e9a69 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/inet/inet_pton.c @@ -0,0 +1,310 @@ +/* $NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $ */ + +/* + * 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 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static const char rcsid[] = "Id: inet_pton.c,v 1.5 2005/07/28 06:51:47 marka Exp"; +#else +__RCSID("$NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "port_before.h" + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "port_after.h" + +#ifdef __weak_alias +__weak_alias(inet_pton,_inet_pton) +#endif + +/*% + * WARNING: Don't even consider trying to compile this on a system where + * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. + */ + +static int inet_pton4(const char *src, u_char *dst, int pton); +static int inet_pton6(const char *src, u_char *dst); + +/* int + * inet_pton(af, src, dst) + * convert from presentation format (which usually means ASCII printable) + * to network format (which is usually some kind of binary format). + * return: + * 1 if the address was valid for the specified address family + * 0 if the address wasn't valid (`dst' is untouched in this case) + * -1 if some other error occurred (`dst' is untouched in this case, too) + * author: + * Paul Vixie, 1996. + */ +int +inet_pton(int af, const char *src, void *dst) +{ + + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); + + switch (af) { + case AF_INET: + return (inet_pton4(src, dst, 1)); + case AF_INET6: + return (inet_pton6(src, dst)); + default: + errno = EAFNOSUPPORT; + return (-1); + } + /* NOTREACHED */ +} + +/* int + * inet_pton4(src, dst, pton) + * when last arg is 0: inet_aton(). with hexadecimal, octal and shorthand. + * when last arg is 1: inet_pton(). decimal dotted-quad only. + * return: + * 1 if `src' is a valid input, else 0. + * notice: + * does not touch `dst' unless it's returning 1. + * author: + * Paul Vixie, 1996. + */ +static int +inet_pton4(const char *src, u_char *dst, int pton) +{ + u_int32_t val; + u_int digit, base; + ptrdiff_t n; + unsigned char c; + u_int parts[4]; + u_int *pp = parts; + + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); + + c = *src; + for (;;) { + /* + * Collect number up to ``.''. + * Values are specified as for C: + * 0x=hex, 0=octal, isdigit=decimal. + */ + if (!isdigit(c)) + return (0); + val = 0; base = 10; + if (c == '0') { + c = *++src; + if (c == 'x' || c == 'X') + base = 16, c = *++src; + else if (isdigit(c) && c != '9') + base = 8; + } + /* inet_pton() takes decimal only */ + if (pton && base != 10) + return (0); + for (;;) { + if (isdigit(c)) { + digit = c - '0'; + if (digit >= base) + break; + val = (val * base) + digit; + c = *++src; + } else if (base == 16 && isxdigit(c)) { + digit = c + 10 - (islower(c) ? 'a' : 'A'); + if (digit >= 16) + break; + val = (val << 4) | digit; + c = *++src; + } else + break; + } + if (c == '.') { + /* + * Internet format: + * a.b.c.d + * a.b.c (with c treated as 16 bits) + * a.b (with b treated as 24 bits) + * a (with a treated as 32 bits) + */ + if (pp >= parts + 3) + return (0); + *pp++ = val; + c = *++src; + } else + break; + } + /* + * Check for trailing characters. + */ + if (c != '\0' && !isspace(c)) + return (0); + /* + * Concoct the address according to + * the number of parts specified. + */ + n = pp - parts + 1; + /* inet_pton() takes dotted-quad only. it does not take shorthand. */ + if (pton && n != 4) + return (0); + switch (n) { + + case 0: + return (0); /* initial nondigit */ + + case 1: /* a -- 32 bits */ + break; + + case 2: /* a.b -- 8.24 bits */ + if (parts[0] > 0xff || val > 0xffffff) + return (0); + val |= parts[0] << 24; + break; + + case 3: /* a.b.c -- 8.8.16 bits */ + if ((parts[0] | parts[1]) > 0xff || val > 0xffff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 4: /* a.b.c.d -- 8.8.8.8 bits */ + if ((parts[0] | parts[1] | parts[2] | val) > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + } + if (dst) { + val = htonl(val); + memcpy(dst, &val, NS_INADDRSZ); + } + return (1); +} + +/* int + * inet_pton6(src, dst) + * convert presentation level address to network order binary form. + * return: + * 1 if `src' is a valid [RFC1884 2.2] address, else 0. + * notice: + * (1) does not touch `dst' unless it's returning 1. + * (2) :: in a full address is silently ignored. + * credit: + * inspired by Mark Andrews. + * author: + * Paul Vixie, 1996. + */ +static int +inet_pton6(const char *src, u_char *dst) +{ + static const char xdigits_l[] = "0123456789abcdef", + xdigits_u[] = "0123456789ABCDEF"; + u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; + const char *xdigits, *curtok; + int ch, seen_xdigits; + u_int val; + + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); + + memset((tp = tmp), '\0', NS_IN6ADDRSZ); + endp = tp + NS_IN6ADDRSZ; + colonp = NULL; + /* Leading :: requires some special handling. */ + if (*src == ':') + if (*++src != ':') + return (0); + curtok = src; + seen_xdigits = 0; + val = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) + pch = strchr((xdigits = xdigits_u), ch); + if (pch != NULL) { + val <<= 4; + val |= (int)(pch - xdigits); + if (++seen_xdigits > 4) + return (0); + continue; + } + if (ch == ':') { + curtok = src; + if (!seen_xdigits) { + if (colonp) + return (0); + colonp = tp; + continue; + } else if (*src == '\0') + return (0); + if (tp + NS_INT16SZ > endp) + return (0); + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + seen_xdigits = 0; + val = 0; + continue; + } + if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && + inet_pton4(curtok, tp, 1) > 0) { + tp += NS_INADDRSZ; + seen_xdigits = 0; + break; /*%< '\\0' was seen by inet_pton4(). */ + } + return (0); + } + if (seen_xdigits) { + if (tp + NS_INT16SZ > endp) + return (0); + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + } + if (colonp != NULL) { + /* + * Since some memmove()'s erroneously fail to handle + * overlapping regions, we'll do the shift by hand. + */ + const ptrdiff_t n = tp - colonp; + int i; + + if (tp == endp) + return (0); + for (i = 1; i <= n; i++) { + endp[- i] = colonp[n - i]; + colonp[n - i] = 0; + } + tp = endp; + } + if (tp != endp) + return (0); + memcpy(dst, tmp, NS_IN6ADDRSZ); + return (1); +} + +/*! \file */ diff --git a/libc/upstream-netbsd/lib/libc/isc/ev_streams.c b/libc/upstream-netbsd/lib/libc/isc/ev_streams.c new file mode 100644 index 0000000..2804b9f --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/isc/ev_streams.c @@ -0,0 +1,319 @@ +/* $NetBSD: ev_streams.c,v 1.6 2009/04/12 17:07:17 christos Exp $ */ + +/* + * 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 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. + */ + +/* ev_streams.c - implement asynch stream file IO for the eventlib + * vix 04mar96 [initial] + */ + +#include +#if !defined(LINT) && !defined(CODECENTER) && !defined(lint) +#ifdef notdef +static const char rcsid[] = "Id: ev_streams.c,v 1.5 2005/04/27 04:56:36 sra Exp"; +#else +__RCSID("$NetBSD: ev_streams.c,v 1.6 2009/04/12 17:07:17 christos Exp $"); +#endif +#endif + +#include "port_before.h" +#include "fd_setsize.h" + +#include +#include + +#include + +#include +#include +#include "eventlib_p.h" + +#include "port_after.h" + +#ifndef _LIBC +static int copyvec(evStream *str, const struct iovec *iov, int iocnt); +static void consume(evStream *str, size_t bytes); +static void done(evContext opaqueCtx, evStream *str); +static void writable(evContext opaqueCtx, void *uap, int fd, int evmask); +static void readable(evContext opaqueCtx, void *uap, int fd, int evmask); +#endif + +struct iovec +evConsIovec(void *buf, size_t cnt) { + struct iovec ret; + + memset(&ret, 0xf5, sizeof ret); + ret.iov_base = buf; + ret.iov_len = cnt; + return (ret); +} + +#ifndef _LIBC +int +evWrite(evContext opaqueCtx, int fd, const struct iovec *iov, int iocnt, + evStreamFunc func, void *uap, evStreamID *id) +{ + evContext_p *ctx = opaqueCtx.opaque; + evStream *new; + int save; + + OKNEW(new); + new->func = func; + new->uap = uap; + new->fd = fd; + new->flags = 0; + if (evSelectFD(opaqueCtx, fd, EV_WRITE, writable, new, &new->file) < 0) + goto free; + if (copyvec(new, iov, iocnt) < 0) + goto free; + new->prevDone = NULL; + new->nextDone = NULL; + if (ctx->streams != NULL) + ctx->streams->prev = new; + new->prev = NULL; + new->next = ctx->streams; + ctx->streams = new; + if (id != NULL) + id->opaque = new; + return (0); + free: + save = errno; + FREE(new); + errno = save; + return (-1); +} + +int +evRead(evContext opaqueCtx, int fd, const struct iovec *iov, int iocnt, + evStreamFunc func, void *uap, evStreamID *id) +{ + evContext_p *ctx = opaqueCtx.opaque; + evStream *new; + int save; + + OKNEW(new); + new->func = func; + new->uap = uap; + new->fd = fd; + new->flags = 0; + if (evSelectFD(opaqueCtx, fd, EV_READ, readable, new, &new->file) < 0) + goto free; + if (copyvec(new, iov, iocnt) < 0) + goto free; + new->prevDone = NULL; + new->nextDone = NULL; + if (ctx->streams != NULL) + ctx->streams->prev = new; + new->prev = NULL; + new->next = ctx->streams; + ctx->streams = new; + if (id) + id->opaque = new; + return (0); + free: + save = errno; + FREE(new); + errno = save; + return (-1); +} + +int +evTimeRW(evContext opaqueCtx, evStreamID id, evTimerID timer) /*ARGSUSED*/ { + evStream *str = id.opaque; + + UNUSED(opaqueCtx); + + str->timer = timer; + str->flags |= EV_STR_TIMEROK; + return (0); +} + +int +evUntimeRW(evContext opaqueCtx, evStreamID id) /*ARGSUSED*/ { + evStream *str = id.opaque; + + UNUSED(opaqueCtx); + + str->flags &= ~EV_STR_TIMEROK; + return (0); +} + +int +evCancelRW(evContext opaqueCtx, evStreamID id) { + evContext_p *ctx = opaqueCtx.opaque; + evStream *old = id.opaque; + + /* + * The streams list is doubly threaded. First, there's ctx->streams + * that's used by evDestroy() to find and cancel all streams. Second, + * there's ctx->strDone (head) and ctx->strLast (tail) which thread + * through the potentially smaller number of "IO completed" streams, + * used in evGetNext() to avoid scanning the entire list. + */ + + /* Unlink from ctx->streams. */ + if (old->prev != NULL) + old->prev->next = old->next; + else + ctx->streams = old->next; + if (old->next != NULL) + old->next->prev = old->prev; + + /* + * If 'old' is on the ctx->strDone list, remove it. Update + * ctx->strLast if necessary. + */ + if (old->prevDone == NULL && old->nextDone == NULL) { + /* + * Either 'old' is the only item on the done list, or it's + * not on the done list. If the former, then we unlink it + * from the list. If the latter, we leave the list alone. + */ + if (ctx->strDone == old) { + ctx->strDone = NULL; + ctx->strLast = NULL; + } + } else { + if (old->prevDone != NULL) + old->prevDone->nextDone = old->nextDone; + else + ctx->strDone = old->nextDone; + if (old->nextDone != NULL) + old->nextDone->prevDone = old->prevDone; + else + ctx->strLast = old->prevDone; + } + + /* Deallocate the stream. */ + if (old->file.opaque) + evDeselectFD(opaqueCtx, old->file); + memput(old->iovOrig, sizeof (struct iovec) * old->iovOrigCount); + FREE(old); + return (0); +} + +/* Copy a scatter/gather vector and initialize a stream handler's IO. */ +static int +copyvec(evStream *str, const struct iovec *iov, int iocnt) { + int i; + + str->iovOrig = (struct iovec *)memget(sizeof(struct iovec) * iocnt); + if (str->iovOrig == NULL) { + errno = ENOMEM; + return (-1); + } + str->ioTotal = 0; + for (i = 0; i < iocnt; i++) { + str->iovOrig[i] = iov[i]; + str->ioTotal += iov[i].iov_len; + } + str->iovOrigCount = iocnt; + str->iovCur = str->iovOrig; + str->iovCurCount = str->iovOrigCount; + str->ioDone = 0; + return (0); +} + +/* Pull off or truncate lead iovec(s). */ +static void +consume(evStream *str, size_t bytes) { + while (bytes > 0U) { + if (bytes < (size_t)str->iovCur->iov_len) { + str->iovCur->iov_len -= bytes; + str->iovCur->iov_base = (void *) + ((u_char *)str->iovCur->iov_base + bytes); + str->ioDone += bytes; + bytes = 0; + } else { + bytes -= str->iovCur->iov_len; + str->ioDone += str->iovCur->iov_len; + str->iovCur++; + str->iovCurCount--; + } + } +} + +/* Add a stream to Done list and deselect the FD. */ +static void +done(evContext opaqueCtx, evStream *str) { + evContext_p *ctx = opaqueCtx.opaque; + + if (ctx->strLast != NULL) { + str->prevDone = ctx->strLast; + ctx->strLast->nextDone = str; + ctx->strLast = str; + } else { + INSIST(ctx->strDone == NULL); + ctx->strDone = ctx->strLast = str; + } + evDeselectFD(opaqueCtx, str->file); + str->file.opaque = NULL; + /* evDrop() will call evCancelRW() on us. */ +} + +/* Dribble out some bytes on the stream. (Called by evDispatch().) */ +static void +writable(evContext opaqueCtx, void *uap, int fd, int evmask) { + evStream *str = uap; + int bytes; + + UNUSED(evmask); + + bytes = writev(fd, str->iovCur, str->iovCurCount); + if (bytes > 0) { + if ((str->flags & EV_STR_TIMEROK) != 0) + evTouchIdleTimer(opaqueCtx, str->timer); + consume(str, bytes); + } else { + if (bytes < 0 && errno != EINTR) { + str->ioDone = -1; + str->ioErrno = errno; + } + } + if (str->ioDone == -1 || str->ioDone == str->ioTotal) + done(opaqueCtx, str); +} + +/* Scoop up some bytes from the stream. (Called by evDispatch().) */ +static void +readable(evContext opaqueCtx, void *uap, int fd, int evmask) { + evStream *str = uap; + int bytes; + + UNUSED(evmask); + + bytes = readv(fd, str->iovCur, str->iovCurCount); + if (bytes > 0) { + if ((str->flags & EV_STR_TIMEROK) != 0) + evTouchIdleTimer(opaqueCtx, str->timer); + consume(str, bytes); + } else { + if (bytes == 0) + str->ioDone = 0; + else { + if (errno != EINTR) { + str->ioDone = -1; + str->ioErrno = errno; + } + } + } + if (str->ioDone <= 0 || str->ioDone == str->ioTotal) + done(opaqueCtx, str); +} +#endif + +/*! \file */ diff --git a/libc/upstream-netbsd/lib/libc/isc/ev_timers.c b/libc/upstream-netbsd/lib/libc/isc/ev_timers.c new file mode 100644 index 0000000..40521a7 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/isc/ev_timers.c @@ -0,0 +1,519 @@ +/* $NetBSD: ev_timers.c,v 1.11 2012/03/21 00:34:54 christos Exp $ */ + +/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1995-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 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. + */ + +/* ev_timers.c - implement timers for the eventlib + * vix 09sep95 [initial] + */ + +#include +#if !defined(LINT) && !defined(CODECENTER) && !defined(lint) +#ifdef notdef +static const char rcsid[] = "Id: ev_timers.c,v 1.6 2005/04/27 04:56:36 sra Exp"; +#else +__RCSID("$NetBSD: ev_timers.c,v 1.11 2012/03/21 00:34:54 christos Exp $"); +#endif +#endif + +/* Import. */ + +#include "port_before.h" +#include "fd_setsize.h" + +#include + +#include +#include +#include "eventlib_p.h" + +#include "port_after.h" + +/* Constants. */ + +#define MILLION 1000000 +#define BILLION 1000000000 + +/* Forward. */ + +#ifndef _LIBC +static int due_sooner(void *, void *); +static void set_index(void *, int); +static void free_timer(void *, void *); +static void print_timer(void *, void *); +static void idle_timeout(evContext, void *, struct timespec, struct timespec); + +/* Private type. */ + +typedef struct { + evTimerFunc func; + void * uap; + struct timespec lastTouched; + struct timespec max_idle; + evTimer * timer; +} idle_timer; +#endif + +/* Public. */ + +struct timespec +evConsTime(time_t sec, long nsec) { + struct timespec x; + + x.tv_sec = sec; + x.tv_nsec = nsec; + return (x); +} + +struct timespec +evAddTime(struct timespec addend1, struct timespec addend2) { + struct timespec x; + + x.tv_sec = addend1.tv_sec + addend2.tv_sec; + x.tv_nsec = addend1.tv_nsec + addend2.tv_nsec; + if (x.tv_nsec >= BILLION) { + x.tv_sec++; + x.tv_nsec -= BILLION; + } + return (x); +} + +struct timespec +evSubTime(struct timespec minuend, struct timespec subtrahend) { + struct timespec x; + + x.tv_sec = minuend.tv_sec - subtrahend.tv_sec; + if (minuend.tv_nsec >= subtrahend.tv_nsec) + x.tv_nsec = minuend.tv_nsec - subtrahend.tv_nsec; + else { + x.tv_nsec = BILLION - subtrahend.tv_nsec + minuend.tv_nsec; + x.tv_sec--; + } + return (x); +} + +int +evCmpTime(struct timespec a, struct timespec b) { +#define SGN(x) ((x) < 0 ? (-1) : (x) > 0 ? (1) : (0)); + time_t s = a.tv_sec - b.tv_sec; + long n; + + if (s != 0) + return SGN(s); + + n = a.tv_nsec - b.tv_nsec; + return SGN(n); +} + +struct timespec +evNowTime(void) +{ + struct timeval now; +#ifdef CLOCK_REALTIME + struct timespec tsnow; + int m = CLOCK_REALTIME; + +#ifdef CLOCK_MONOTONIC +#ifndef _LIBC + if (__evOptMonoTime) + m = CLOCK_MONOTONIC; +#endif +#endif + if (clock_gettime(m, &tsnow) == 0) + return (tsnow); +#endif + if (gettimeofday(&now, NULL) < 0) + return (evConsTime((time_t)0, 0L)); + return (evTimeSpec(now)); +} + +struct timespec +evUTCTime(void) { + struct timeval now; +#ifdef CLOCK_REALTIME + struct timespec tsnow; + if (clock_gettime(CLOCK_REALTIME, &tsnow) == 0) + return (tsnow); +#endif + if (gettimeofday(&now, NULL) < 0) + return (evConsTime((time_t)0, 0L)); + return (evTimeSpec(now)); +} + +#ifndef _LIBC +struct timespec +evLastEventTime(evContext opaqueCtx) { + evContext_p *ctx = opaqueCtx.opaque; + + return (ctx->lastEventTime); +} +#endif + +struct timespec +evTimeSpec(struct timeval tv) { + struct timespec ts; + + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = tv.tv_usec * 1000; + return (ts); +} + +struct timeval +evTimeVal(struct timespec ts) { + struct timeval tv; + + tv.tv_sec = ts.tv_sec; + tv.tv_usec = (suseconds_t)(ts.tv_nsec / 1000); + return (tv); +} + +#ifndef _LIBC +int +evSetTimer(evContext opaqueCtx, + evTimerFunc func, + void *uap, + struct timespec due, + struct timespec inter, + evTimerID *opaqueID +) { + evContext_p *ctx = opaqueCtx.opaque; + evTimer *id; + + evPrintf(ctx, 1, +"evSetTimer(ctx %p, func %p, uap %p, due %ld.%09ld, inter %ld.%09ld)\n", + ctx, func, uap, + (long)due.tv_sec, due.tv_nsec, + (long)inter.tv_sec, inter.tv_nsec); + +#ifdef __hpux + /* + * tv_sec and tv_nsec are unsigned. + */ + if (due.tv_nsec >= BILLION) + EV_ERR(EINVAL); + + if (inter.tv_nsec >= BILLION) + EV_ERR(EINVAL); +#else + if (due.tv_sec < 0 || due.tv_nsec < 0 || due.tv_nsec >= BILLION) + EV_ERR(EINVAL); + + if (inter.tv_sec < 0 || inter.tv_nsec < 0 || inter.tv_nsec >= BILLION) + EV_ERR(EINVAL); +#endif + + /* due={0,0} is a magic cookie meaning "now." */ + if (due.tv_sec == (time_t)0 && due.tv_nsec == 0L) + due = evNowTime(); + + /* Allocate and fill. */ + OKNEW(id); + id->func = func; + id->uap = uap; + id->due = due; + id->inter = inter; + + if (heap_insert(ctx->timers, id) < 0) + return (-1); + + /* Remember the ID if the caller provided us a place for it. */ + if (opaqueID) + opaqueID->opaque = id; + + if (ctx->debug > 7) { + evPrintf(ctx, 7, "timers after evSetTimer:\n"); + (void) heap_for_each(ctx->timers, print_timer, (void *)ctx); + } + + return (0); +} + +int +evClearTimer(evContext opaqueCtx, evTimerID id) { + evContext_p *ctx = opaqueCtx.opaque; + evTimer *del = id.opaque; + + if (ctx->cur != NULL && + ctx->cur->type == Timer && + ctx->cur->u.timer.this == del) { + evPrintf(ctx, 8, "deferring delete of timer (executing)\n"); + /* + * Setting the interval to zero ensures that evDrop() will + * clean up the timer. + */ + del->inter = evConsTime(0, 0); + return (0); + } + + if (heap_element(ctx->timers, del->index) != del) + EV_ERR(ENOENT); + + if (heap_delete(ctx->timers, del->index) < 0) + return (-1); + FREE(del); + + if (ctx->debug > 7) { + evPrintf(ctx, 7, "timers after evClearTimer:\n"); + (void) heap_for_each(ctx->timers, print_timer, (void *)ctx); + } + + return (0); +} + +int +evConfigTimer(evContext opaqueCtx, + evTimerID id, + const char *param, + int value +) { + evContext_p *ctx = opaqueCtx.opaque; + evTimer *timer = id.opaque; + int result=0; + + UNUSED(value); + + if (heap_element(ctx->timers, timer->index) != timer) + EV_ERR(ENOENT); + + if (strcmp(param, "rate") == 0) + timer->mode |= EV_TMR_RATE; + else if (strcmp(param, "interval") == 0) + timer->mode &= ~EV_TMR_RATE; + else + EV_ERR(EINVAL); + + return (result); +} + +int +evResetTimer(evContext opaqueCtx, + evTimerID id, + evTimerFunc func, + void *uap, + struct timespec due, + struct timespec inter +) { + evContext_p *ctx = opaqueCtx.opaque; + evTimer *timer = id.opaque; + struct timespec old_due; + int result=0; + + if (heap_element(ctx->timers, timer->index) != timer) + EV_ERR(ENOENT); + +#ifdef __hpux + /* + * tv_sec and tv_nsec are unsigned. + */ + if (due.tv_nsec >= BILLION) + EV_ERR(EINVAL); + + if (inter.tv_nsec >= BILLION) + EV_ERR(EINVAL); +#else + if (due.tv_sec < 0 || due.tv_nsec < 0 || due.tv_nsec >= BILLION) + EV_ERR(EINVAL); + + if (inter.tv_sec < 0 || inter.tv_nsec < 0 || inter.tv_nsec >= BILLION) + EV_ERR(EINVAL); +#endif + + old_due = timer->due; + + timer->func = func; + timer->uap = uap; + timer->due = due; + timer->inter = inter; + + switch (evCmpTime(due, old_due)) { + case -1: + result = heap_increased(ctx->timers, timer->index); + break; + case 0: + result = 0; + break; + case 1: + result = heap_decreased(ctx->timers, timer->index); + break; + } + + if (ctx->debug > 7) { + evPrintf(ctx, 7, "timers after evResetTimer:\n"); + (void) heap_for_each(ctx->timers, print_timer, (void *)ctx); + } + + return (result); +} + +int +evSetIdleTimer(evContext opaqueCtx, + evTimerFunc func, + void *uap, + struct timespec max_idle, + evTimerID *opaqueID +) { + evContext_p *ctx = opaqueCtx.opaque; + idle_timer *tt; + + /* Allocate and fill. */ + OKNEW(tt); + tt->func = func; + tt->uap = uap; + tt->lastTouched = ctx->lastEventTime; + tt->max_idle = max_idle; + + if (evSetTimer(opaqueCtx, idle_timeout, tt, + evAddTime(ctx->lastEventTime, max_idle), + max_idle, opaqueID) < 0) { + FREE(tt); + return (-1); + } + + tt->timer = opaqueID->opaque; + + return (0); +} + +int +evClearIdleTimer(evContext opaqueCtx, evTimerID id) { + evTimer *del = id.opaque; + idle_timer *tt = del->uap; + + FREE(tt); + return (evClearTimer(opaqueCtx, id)); +} + +int +evResetIdleTimer(evContext opaqueCtx, + evTimerID opaqueID, + evTimerFunc func, + void *uap, + struct timespec max_idle +) { + evContext_p *ctx = opaqueCtx.opaque; + evTimer *timer = opaqueID.opaque; + idle_timer *tt = timer->uap; + + tt->func = func; + tt->uap = uap; + tt->lastTouched = ctx->lastEventTime; + tt->max_idle = max_idle; + + return (evResetTimer(opaqueCtx, opaqueID, idle_timeout, tt, + evAddTime(ctx->lastEventTime, max_idle), + max_idle)); +} + +int +evTouchIdleTimer(evContext opaqueCtx, evTimerID id) { + evContext_p *ctx = opaqueCtx.opaque; + evTimer *t = id.opaque; + idle_timer *tt = t->uap; + + tt->lastTouched = ctx->lastEventTime; + + return (0); +} + +/* Public to the rest of eventlib. */ + +heap_context +evCreateTimers(const evContext_p *ctx) { + + UNUSED(ctx); + + return (heap_new(due_sooner, set_index, 2048)); +} + +void +evDestroyTimers(const evContext_p *ctx) { + (void) heap_for_each(ctx->timers, free_timer, NULL); + (void) heap_free(ctx->timers); +} + +/* Private. */ + +static int +due_sooner(void *a, void *b) { + evTimer *a_timer, *b_timer; + + a_timer = a; + b_timer = b; + return (evCmpTime(a_timer->due, b_timer->due) < 0); +} + +static void +set_index(void *what, int idx) { + evTimer *timer; + + timer = what; + timer->index = idx; +} + +static void +free_timer(void *what, void *uap) { + evTimer *t = what; + + UNUSED(uap); + + FREE(t); +} + +static void +print_timer(void *what, void *uap) { + evTimer *cur = what; + evContext_p *ctx = uap; + + cur = what; + evPrintf(ctx, 7, + " func %p, uap %p, due %ld.%09ld, inter %ld.%09ld\n", + cur->func, cur->uap, + (long)cur->due.tv_sec, cur->due.tv_nsec, + (long)cur->inter.tv_sec, cur->inter.tv_nsec); +} + +static void +idle_timeout(evContext opaqueCtx, + void *uap, + struct timespec due, + struct timespec inter +) { + evContext_p *ctx = opaqueCtx.opaque; + idle_timer *this = uap; + struct timespec idle; + + UNUSED(due); + UNUSED(inter); + + idle = evSubTime(ctx->lastEventTime, this->lastTouched); + if (evCmpTime(idle, this->max_idle) >= 0) { + (this->func)(opaqueCtx, this->uap, this->timer->due, + this->max_idle); + /* + * Setting the interval to zero will cause the timer to + * be cleaned up in evDrop(). + */ + this->timer->inter = evConsTime(0L, 0L); + FREE(this); + } else { + /* evDrop() will reschedule the timer. */ + this->timer->inter = evSubTime(this->max_idle, idle); + } +} +#endif + +/*! \file */ diff --git a/libc/upstream-netbsd/lib/libc/isc/eventlib_p.h b/libc/upstream-netbsd/lib/libc/isc/eventlib_p.h new file mode 100644 index 0000000..4d6b788 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/isc/eventlib_p.h @@ -0,0 +1,283 @@ +/* $NetBSD: eventlib_p.h,v 1.3 2009/04/12 17:07:17 christos Exp $ */ + +/* + * Copyright (c) 2005 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1995-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 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. + */ + +/*! \file + * \brief private interfaces for eventlib + * \author vix 09sep95 [initial] + * + * Id: eventlib_p.h,v 1.9 2006/03/09 23:57:56 marka Exp + */ + +#ifndef _EVENTLIB_P_H +#define _EVENTLIB_P_H + +#include +#include +#include +#include +#include + +#define EVENTLIB_DEBUG 1 + +#include +#include +#include +#include +#include + +#include +#include +#include + +#define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT) +#define EV_ERR(e) return (errno = (e), -1) +#define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL +#define OKFREE(x, y) if ((x) < 0) { FREE((y)); EV_ERR(errno); } \ + else (void)NULL + +#define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \ + FILL(p); \ + else \ + (void)NULL; +#define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \ + errno = ENOMEM; \ + return (-1); \ + } else \ + FILL(p) +#define FREE(p) memput((p), sizeof *(p)) + +#if EVENTLIB_DEBUG +#define FILL(p) memset((p), 0xF5, sizeof *(p)) +#else +#define FILL(p) +#endif + +#ifdef USE_POLL +#ifdef HAVE_STROPTS_H +#include +#endif +#include +#endif /* USE_POLL */ + +typedef struct evConn { + evConnFunc func; + void * uap; + int fd; + int flags; +#define EV_CONN_LISTEN 0x0001 /*%< Connection is a listener. */ +#define EV_CONN_SELECTED 0x0002 /*%< evSelectFD(conn->file). */ +#define EV_CONN_BLOCK 0x0004 /*%< Listener fd was blocking. */ + evFileID file; + struct evConn * prev; + struct evConn * next; +} evConn; + +typedef struct evAccept { + int fd; + union { + struct sockaddr sa; + struct sockaddr_in in; +#ifndef NO_SOCKADDR_UN + struct sockaddr_un un; +#endif + } la; + ISC_SOCKLEN_T lalen; + union { + struct sockaddr sa; + struct sockaddr_in in; +#ifndef NO_SOCKADDR_UN + struct sockaddr_un un; +#endif + } ra; + ISC_SOCKLEN_T ralen; + int ioErrno; + evConn * conn; + LINK(struct evAccept) link; +} evAccept; + +typedef struct evFile { + evFileFunc func; + void * uap; + int fd; + int eventmask; + int preemptive; + struct evFile * prev; + struct evFile * next; + struct evFile * fdprev; + struct evFile * fdnext; +} evFile; + +typedef struct evStream { + evStreamFunc func; + void * uap; + evFileID file; + evTimerID timer; + int flags; +#define EV_STR_TIMEROK 0x0001 /*%< IFF timer valid. */ + int fd; + struct iovec * iovOrig; + int iovOrigCount; + struct iovec * iovCur; + int iovCurCount; + int ioTotal; + int ioDone; + int ioErrno; + struct evStream *prevDone, *nextDone; + struct evStream *prev, *next; +} evStream; + +typedef struct evTimer { + evTimerFunc func; + void * uap; + struct timespec due, inter; + int index; + int mode; +#define EV_TMR_RATE 1 +} evTimer; + +typedef struct evWait { + evWaitFunc func; + void * uap; + const void * tag; + struct evWait * next; +} evWait; + +typedef struct evWaitList { + evWait * first; + evWait * last; + struct evWaitList * prev; + struct evWaitList * next; +} evWaitList; + +typedef struct evEvent_p { + enum { Accept, File, Stream, Timer, Wait, Free, Null } type; + union { + struct { evAccept *this; } accept; + struct { evFile *this; int eventmask; } file; + struct { evStream *this; } stream; + struct { evTimer *this; } timer; + struct { evWait *this; } wait; + struct { struct evEvent_p *next; } free; + struct { const void *placeholder; } null; + } u; +} evEvent_p; + +#ifdef USE_POLL +typedef struct { + void *ctx; /* pointer to the evContext_p */ + uint32_t type; /* READ, WRITE, EXCEPT, nonblk */ + uint32_t result; /* 1 => revents, 0 => events */ +} __evEmulMask; + +#define emulMaskInit(ctx, field, ev, lastnext) \ + ctx->field.ctx = ctx; \ + ctx->field.type = ev; \ + ctx->field.result = lastnext; + +extern short *__fd_eventfield(int fd, __evEmulMask *maskp); +extern short __poll_event(__evEmulMask *maskp); +extern void __fd_clr(int fd, __evEmulMask *maskp); +extern void __fd_set(int fd, __evEmulMask *maskp); + +#undef FD_ZERO +#define FD_ZERO(maskp) + +#undef FD_SET +#define FD_SET(fd, maskp) \ + __fd_set(fd, maskp) + +#undef FD_CLR +#define FD_CLR(fd, maskp) \ + __fd_clr(fd, maskp) + +#undef FD_ISSET +#define FD_ISSET(fd, maskp) \ + ((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0) + +#endif /* USE_POLL */ + +typedef struct { + /* Global. */ + const evEvent_p *cur; + /* Debugging. */ + int debug; + FILE *output; + /* Connections. */ + evConn *conns; + LIST(evAccept) accepts; + /* Files. */ + evFile *files, *fdNext; +#ifndef USE_POLL + fd_set rdLast, rdNext; + fd_set wrLast, wrNext; + fd_set exLast, exNext; + fd_set nonblockBefore; + int fdMax, fdCount, highestFD; + evFile *fdTable[FD_SETSIZE]; +#else + struct pollfd *pollfds; /* Allocated as needed */ + evFile **fdTable; /* Ditto */ + int maxnfds; /* # elements in above */ + int firstfd; /* First active fd */ + int fdMax; /* Last active fd */ + int fdCount; /* # fd:s with I/O */ + int highestFD; /* max fd allowed by OS */ + __evEmulMask rdLast, rdNext; + __evEmulMask wrLast, wrNext; + __evEmulMask exLast, exNext; + __evEmulMask nonblockBefore; +#endif /* USE_POLL */ +#ifdef EVENTLIB_TIME_CHECKS + struct timespec lastSelectTime; + int lastFdCount; +#endif + /* Streams. */ + evStream *streams; + evStream *strDone, *strLast; + /* Timers. */ + struct timespec lastEventTime; + heap_context timers; + /* Waits. */ + evWaitList *waitLists; + evWaitList waitDone; +} evContext_p; + +/* eventlib.c */ +#define evPrintf __evPrintf +void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...) + ISC_FORMAT_PRINTF(3, 4); + +#ifdef USE_POLL +extern int evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd); +#endif /* USE_POLL */ + +/* ev_timers.c */ +#define evCreateTimers __evCreateTimers +heap_context evCreateTimers(const evContext_p *); +#define evDestroyTimers __evDestroyTimers +void evDestroyTimers(const evContext_p *); + +/* ev_waits.c */ +#define evFreeWait __evFreeWait +evWait *evFreeWait(evContext_p *ctx, evWait *old); + +/* Global options */ +extern int __evOptMonoTime; + +#endif /*_EVENTLIB_P_H*/ diff --git a/libc/upstream-netbsd/lib/libc/regex/cclass.h b/libc/upstream-netbsd/lib/libc/regex/cclass.h new file mode 100644 index 0000000..3ab2ccb --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/regex/cclass.h @@ -0,0 +1,104 @@ +/* $NetBSD: cclass.h,v 1.7 2003/08/07 16:43:19 agc Exp $ */ + +/*- + * 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. 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 + */ + +/*- + * Copyright (c) 1992, 1993, 1994 Henry Spencer. + * + * 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 + */ + +/* character-class table */ +static const struct cclass { + const char *name; + const char *chars; + const char *multis; +} cclasses[] = { + { "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ +0123456789", "" }, + { "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", + "" }, + { "blank", " \t", "" }, + { "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\ +\25\26\27\30\31\32\33\34\35\36\37\177", "" }, + { "digit", "0123456789", "" }, + { "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ +0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", + "" }, + { "lower", "abcdefghijklmnopqrstuvwxyz", + "" }, + { "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ +0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ", + "" }, + { "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", + "" }, + { "space", "\t\n\v\f\r ", "" }, + { "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "" }, + { "xdigit", "0123456789ABCDEFabcdef", + "" }, + { NULL, 0, "" } +}; diff --git a/libc/upstream-netbsd/lib/libc/regex/cname.h b/libc/upstream-netbsd/lib/libc/regex/cname.h new file mode 100644 index 0000000..4b9ef39 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/regex/cname.h @@ -0,0 +1,175 @@ +/* $NetBSD: cname.h,v 1.7 2003/08/07 16:43:19 agc Exp $ */ + +/*- + * 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. 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 + */ + +/*- + * Copyright (c) 1992, 1993, 1994 Henry Spencer. + * + * 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 + */ + +/* character-name table */ +static const struct cname { + const 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/libc/upstream-netbsd/lib/libc/regex/engine.c b/libc/upstream-netbsd/lib/libc/regex/engine.c new file mode 100644 index 0000000..2a800d4 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/regex/engine.c @@ -0,0 +1,1188 @@ +/* $NetBSD: engine.c,v 1.24 2012/03/13 21:13:42 christos Exp $ */ + +/*- + * 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. 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. + * + * @(#)engine.c 8.5 (Berkeley) 3/20/94 + */ + +/*- + * Copyright (c) 1992, 1993, 1994 Henry Spencer. + * + * 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. + * + * @(#)engine.c 8.5 (Berkeley) 3/20/94 + */ + +/* + * The matching engine and friends. This file is #included by regexec.c + * after suitable #defines of a variety of macros used herein, so that + * different state representations can be used without duplicating masses + * of code. + */ + +#ifdef SNAMES +#define matcher smatcher +#define fast sfast +#define slow sslow +#define dissect sdissect +#define backref sbackref +#define step sstep +#define print sprint +#define at sat +#define match smat +#define nope snope +#endif +#ifdef LNAMES +#define matcher lmatcher +#define fast lfast +#define slow lslow +#define dissect ldissect +#define backref lbackref +#define step lstep +#define print lprint +#define at lat +#define match lmat +#define nope lnope +#endif + +/* another structure passed up and down to avoid zillions of parameters */ +struct match { + struct re_guts *g; + int eflags; + regmatch_t *pmatch; /* [nsub+1] (0 element unused) */ + const char *offp; /* offsets work from here */ + const char *beginp; /* start of string -- virtual NUL precedes */ + const char *endp; /* end of string -- virtual NUL here */ + const char *coldp; /* can be no match starting before here */ + const char **lastpos; /* [nplus+1] */ + STATEVARS; + states st; /* current states */ + states fresh; /* states for a fresh start */ + states tmp; /* temporary */ + states empty; /* empty set of states */ +}; + +/* ========= begin header generated by ./mkh ========= */ +#ifdef __cplusplus +extern "C" { +#endif + +/* === engine.c === */ +static int matcher(struct re_guts *g, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); +static const char *dissect(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst); +static const char *backref(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst, sopno lev); +static const char *fast(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst); +static const char *slow(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst); +static states step(struct re_guts *g, sopno start, sopno stop, states bef, int ch, states aft); +#define BOL (OUT+1) +#define EOL (BOL+1) +#define BOLEOL (BOL+2) +#define NOTHING (BOL+3) +#define BOW (BOL+4) +#define EOW (BOL+5) +#define CODEMAX (BOL+5) /* highest code used */ +#define NONCHAR(c) ((c) > CHAR_MAX) +#define NNONCHAR (CODEMAX-CHAR_MAX) +#ifdef REDEBUG +static void print(struct match *m, char *caption, states st, int ch, FILE *d); +#endif +#ifdef REDEBUG +static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst); +#endif +#ifdef REDEBUG +static char *pchar(int ch); +#endif + +#ifdef __cplusplus +} +#endif +/* ========= end header generated by ./mkh ========= */ + +#ifdef REDEBUG +#define SP(t, s, c) print(m, t, s, c, stdout) +#define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2) +#define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); } +static int nope = 0; +#else +#define SP(t, s, c) /* nothing */ +#define AT(t, p1, p2, s1, s2) /* nothing */ +#define NOTE(s) /* nothing */ +#endif + +/* + - matcher - the actual matching engine + == static int matcher(struct re_guts *g, char *string, \ + == size_t nmatch, regmatch_t pmatch[], int eflags); + */ +static int /* 0 success, REG_NOMATCH failure */ +matcher( + struct re_guts *g, + const char *string, + size_t nmatch, + regmatch_t pmatch[], + int eflags) +{ + const char *endp; + size_t i; + struct match mv; + struct match *m = &mv; + const char *dp; + const sopno gf = g->firststate+1; /* +1 for OEND */ + const sopno gl = g->laststate; + const char *start; + const char *stop; + int error = 0; + + _DIAGASSERT(g != NULL); + _DIAGASSERT(string != NULL); + /* pmatch checked below */ + + /* simplify the situation where possible */ + if (g->cflags®_NOSUB) + nmatch = 0; + if (eflags®_STARTEND) { + _DIAGASSERT(pmatch != NULL); + start = string + (size_t)pmatch[0].rm_so; + stop = string + (size_t)pmatch[0].rm_eo; + } else { + start = string; + stop = start + strlen(start); + } + if (stop < start) + return(REG_INVARG); + + /* prescreening; this does wonders for this rather slow code */ + if (g->must != NULL) { + for (dp = start; dp < stop; dp++) + if (*dp == g->must[0] && (size_t)(stop - dp) >= g->mlen && + memcmp(dp, g->must, g->mlen) == 0) + break; + if (dp == stop) /* we didn't find g->must */ + return(REG_NOMATCH); + } + + /* match struct setup */ + m->g = g; + m->eflags = eflags; + m->pmatch = NULL; + m->lastpos = NULL; + m->offp = string; + m->beginp = start; + m->endp = stop; + STATESETUP(m, 4); + SETUP(m->st); + SETUP(m->fresh); + SETUP(m->tmp); + SETUP(m->empty); + CLEAR(m->empty); + + /* this loop does only one repetition except for backrefs */ + for (;;) { + endp = fast(m, start, stop, gf, gl); + if (endp == NULL) { /* a miss */ + error = REG_NOMATCH; + goto done; + } + if (nmatch == 0 && !g->backrefs) + break; /* no further info needed */ + + /* where? */ + assert(m->coldp != NULL); + for (;;) { + NOTE("finding start"); + endp = slow(m, m->coldp, stop, gf, gl); + if (endp != NULL) + break; + assert(m->coldp < m->endp); + m->coldp++; + } + if (nmatch == 1 && !g->backrefs) + break; /* no further info needed */ + + /* oh my, he wants the subexpressions... */ + if (m->pmatch == NULL) + m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) * + sizeof(regmatch_t)); + if (m->pmatch == NULL) { + error = REG_ESPACE; + goto done; + } + for (i = 1; i <= m->g->nsub; i++) + m->pmatch[i].rm_so = m->pmatch[i].rm_eo = (regoff_t)-1; + if (!g->backrefs && !(m->eflags®_BACKR)) { + NOTE("dissecting"); + dp = dissect(m, m->coldp, endp, gf, gl); + } else { + if (g->nplus > 0 && m->lastpos == NULL) + m->lastpos = malloc((g->nplus+1) * + sizeof(const char *)); + if (g->nplus > 0 && m->lastpos == NULL) { + error = REG_ESPACE; + goto done; + } + NOTE("backref dissect"); + dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); + } + if (dp != NULL) + break; + + /* uh-oh... we couldn't find a subexpression-level match */ + assert(g->backrefs); /* must be back references doing it */ + assert(g->nplus == 0 || m->lastpos != NULL); + for (;;) { + if (dp != NULL || endp <= m->coldp) + break; /* defeat */ + NOTE("backoff"); + endp = slow(m, m->coldp, endp-1, gf, gl); + if (endp == NULL) + break; /* defeat */ + /* try it on a shorter possibility */ +#ifndef NDEBUG + for (i = 1; i <= m->g->nsub; i++) { + assert(m->pmatch[i].rm_so == (regoff_t)-1); + assert(m->pmatch[i].rm_eo == (regoff_t)-1); + } +#endif + NOTE("backoff dissect"); + dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); + } + assert(dp == NULL || dp == endp); + if (dp != NULL) /* found a shorter one */ + break; + + /* despite initial appearances, there is no match here */ + NOTE("false alarm"); + start = m->coldp + 1; /* recycle starting later */ + assert(start <= stop); + } + + /* fill in the details if requested */ + if (nmatch > 0) { + _DIAGASSERT(pmatch != NULL); + pmatch[0].rm_so = m->coldp - m->offp; + pmatch[0].rm_eo = endp - m->offp; + } + if (nmatch > 1) { + assert(m->pmatch != NULL); + for (i = 1; i < nmatch; i++) + if (i <= m->g->nsub) + pmatch[i] = m->pmatch[i]; + else { + pmatch[i].rm_so = (regoff_t)-1; + pmatch[i].rm_eo = (regoff_t)-1; + } + } + +done: + if (m->pmatch != NULL) { + free(m->pmatch); + m->pmatch = NULL; + } + if (m->lastpos != NULL) { + free(m->lastpos); + m->lastpos = NULL; + } + STATETEARDOWN(m); + return error; +} + +/* + - dissect - figure out what matched what, no back references + == static const char *dissect(struct match *m, const char *start, \ + == const char *stop, sopno startst, sopno stopst); + */ +static const char * /* == stop (success) always */ +dissect( + struct match *m, + const char *start, + const char *stop, + sopno startst, + sopno stopst) +{ + int i; + sopno ss; /* start sop of current subRE */ + sopno es; /* end sop of current subRE */ + const char *sp; /* start of string matched by it */ + const char *stp; /* string matched by it cannot pass here */ + const char *rest; /* start of rest of string */ + const char *tail; /* string unmatched by rest of RE */ + sopno ssub; /* start sop of subsubRE */ + sopno esub; /* end sop of subsubRE */ + const char *ssp; /* start of string matched by subsubRE */ + const char *sep; /* end of string matched by subsubRE */ + const char *oldssp; /* previous ssp */ +#ifndef NDEBUG + const char *dp; +#endif + + _DIAGASSERT(m != NULL); + _DIAGASSERT(start != NULL); + _DIAGASSERT(stop != NULL); + + AT("diss", start, stop, startst, stopst); + sp = start; + for (ss = startst; ss < stopst; ss = es) { + /* identify end of subRE */ + es = ss; + switch (OP(m->g->strip[es])) { + case OPLUS_: + case OQUEST_: + es += OPND(m->g->strip[es]); + break; + case OCH_: + while (OP(m->g->strip[es]) != O_CH) + es += OPND(m->g->strip[es]); + break; + } + es++; + + /* figure out what it matched */ + switch (OP(m->g->strip[ss])) { + case OEND: + assert(nope); + break; + case OCHAR: + sp++; + break; + case OBOL: + case OEOL: + case OBOW: + case OEOW: + break; + case OANY: + case OANYOF: + sp++; + break; + case OBACK_: + case O_BACK: + assert(nope); + break; + /* cases where length of match is hard to find */ + case OQUEST_: + stp = stop; + for (;;) { + /* how long could this one be? */ + rest = slow(m, sp, stp, ss, es); + assert(rest != NULL); /* it did match */ + /* could the rest match the rest? */ + tail = slow(m, rest, stop, es, stopst); + if (tail == stop) + break; /* yes! */ + /* no -- try a shorter match for this one */ + stp = rest - 1; + assert(stp >= sp); /* it did work */ + } + ssub = ss + 1; + esub = es - 1; + /* did innards match? */ + if (slow(m, sp, rest, ssub, esub) != NULL) { +#ifdef NDEBUG + (void) +#else + dp = +#endif + dissect(m, sp, rest, ssub, esub); + assert(dp == rest); + } else /* no */ + assert(sp == rest); + sp = rest; + break; + case OPLUS_: + stp = stop; + for (;;) { + /* how long could this one be? */ + rest = slow(m, sp, stp, ss, es); + assert(rest != NULL); /* it did match */ + /* could the rest match the rest? */ + tail = slow(m, rest, stop, es, stopst); + if (tail == stop) + break; /* yes! */ + /* no -- try a shorter match for this one */ + stp = rest - 1; + assert(stp >= sp); /* it did work */ + } + ssub = ss + 1; + esub = es - 1; + ssp = sp; + oldssp = ssp; + for (;;) { /* find last match of innards */ + sep = slow(m, ssp, rest, ssub, esub); + if (sep == NULL || sep == ssp) + break; /* failed or matched null */ + oldssp = ssp; /* on to next try */ + ssp = sep; + } + if (sep == NULL) { + /* last successful match */ + sep = ssp; + ssp = oldssp; + } + assert(sep == rest); /* must exhaust substring */ + assert(slow(m, ssp, sep, ssub, esub) == rest); +#ifdef NDEBUG + (void) +#else + dp = +#endif + dissect(m, ssp, sep, ssub, esub); + assert(dp == sep); + sp = rest; + break; + case OCH_: + stp = stop; + for (;;) { + /* how long could this one be? */ + rest = slow(m, sp, stp, ss, es); + assert(rest != NULL); /* it did match */ + /* could the rest match the rest? */ + tail = slow(m, rest, stop, es, stopst); + if (tail == stop) + break; /* yes! */ + /* no -- try a shorter match for this one */ + stp = rest - 1; + assert(stp >= sp); /* it did work */ + } + ssub = ss + 1; + esub = ss + OPND(m->g->strip[ss]) - 1; + assert(OP(m->g->strip[esub]) == OOR1); + for (;;) { /* find first matching branch */ + if (slow(m, sp, rest, ssub, esub) == rest) + break; /* it matched all of it */ + /* that one missed, try next one */ + assert(OP(m->g->strip[esub]) == OOR1); + esub++; + assert(OP(m->g->strip[esub]) == OOR2); + ssub = esub + 1; + esub += OPND(m->g->strip[esub]); + if (OP(m->g->strip[esub]) == OOR2) + esub--; + else + assert(OP(m->g->strip[esub]) == O_CH); + } +#ifdef NDEBUG + (void) +#else + dp = +#endif + dissect(m, sp, rest, ssub, esub); + assert(dp == rest); + sp = rest; + break; + case O_PLUS: + case O_QUEST: + case OOR1: + case OOR2: + case O_CH: + assert(nope); + break; + case OLPAREN: + i = OPND(m->g->strip[ss]); + assert(0 < i && i <= m->g->nsub); + m->pmatch[i].rm_so = sp - m->offp; + break; + case ORPAREN: + i = OPND(m->g->strip[ss]); + assert(0 < i && i <= m->g->nsub); + m->pmatch[i].rm_eo = sp - m->offp; + break; + default: /* uh oh */ + assert(nope); + break; + } + } + + assert(sp == stop); + return(sp); +} + +/* + - backref - figure out what matched what, figuring in back references + == static const char *backref(struct match *m, const char *start, \ + == const char *stop, sopno startst, sopno stopst, sopno lev); + */ +static const char * /* == stop (success) or NULL (failure) */ +backref( + struct match *m, + const char *start, + const char *stop, + sopno startst, + sopno stopst, + sopno lev) /* PLUS nesting level */ +{ + int i; + sopno ss; /* start sop of current subRE */ + const char *sp; /* start of string matched by it */ + sopno ssub; /* start sop of subsubRE */ + sopno esub; /* end sop of subsubRE */ + const char *ssp; /* start of string matched by subsubRE */ + const char *dp; + size_t len; + int hard; + sop s; + regoff_t offsave; + cset *cs; + + _DIAGASSERT(m != NULL); + _DIAGASSERT(start != NULL); + _DIAGASSERT(stop != NULL); + + AT("back", start, stop, startst, stopst); + sp = start; + + /* get as far as we can with easy stuff */ + hard = 0; + for (ss = startst; !hard && ss < stopst; ss++) + switch (OP(s = m->g->strip[ss])) { + case OCHAR: + if (sp == stop || *sp++ != (char)OPND(s)) + return(NULL); + break; + case OANY: + if (sp == stop) + return(NULL); + sp++; + break; + case OANYOF: + cs = &m->g->sets[OPND(s)]; + if (sp == stop || !CHIN(cs, *sp++)) + return(NULL); + break; + case OBOL: + if ( (sp == m->beginp && !(m->eflags®_NOTBOL)) || + (sp < m->endp && *(sp-1) == '\n' && + (m->g->cflags®_NEWLINE)) ) + { /* yes */ } + else + return(NULL); + break; + case OEOL: + if ( (sp == m->endp && !(m->eflags®_NOTEOL)) || + (sp < m->endp && *sp == '\n' && + (m->g->cflags®_NEWLINE)) ) + { /* yes */ } + else + return(NULL); + break; + case OBOW: + if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) || + (sp < m->endp && *(sp-1) == '\n' && + (m->g->cflags®_NEWLINE)) || + (sp > m->beginp && + !ISWORD(*(sp-1))) ) && + (sp < m->endp && ISWORD(*sp)) ) + { /* yes */ } + else + return(NULL); + break; + case OEOW: + if (( (sp == m->endp && !(m->eflags®_NOTEOL)) || + (sp < m->endp && *sp == '\n' && + (m->g->cflags®_NEWLINE)) || + (sp < m->endp && !ISWORD(*sp)) ) && + (sp > m->beginp && ISWORD(*(sp-1))) ) + { /* yes */ } + else + return(NULL); + break; + case O_QUEST: + break; + case OOR1: /* matches null but needs to skip */ + ss++; + s = m->g->strip[ss]; + do { + assert(OP(s) == OOR2); + ss += OPND(s); + } while (OP(s = m->g->strip[ss]) != O_CH); + /* note that the ss++ gets us past the O_CH */ + break; + default: /* have to make a choice */ + hard = 1; + break; + } + if (!hard) { /* that was it! */ + if (sp != stop) + return(NULL); + return(sp); + } + ss--; /* adjust for the for's final increment */ + + /* the hard stuff */ + AT("hard", sp, stop, ss, stopst); + s = m->g->strip[ss]; + switch (OP(s)) { + case OBACK_: /* the vilest depths */ + i = OPND(s); + assert(0 < i && i <= m->g->nsub); + if (m->pmatch[i].rm_eo == (regoff_t)-1) + return(NULL); + assert(m->pmatch[i].rm_so != (regoff_t)-1); + len = (size_t)(m->pmatch[i].rm_eo - m->pmatch[i].rm_so); + if (len == 0) + return(NULL); + assert(stop - m->beginp >= len); + if (sp > stop - len) + return(NULL); /* not enough left to match */ + ssp = m->offp + (size_t)m->pmatch[i].rm_so; + if (memcmp(sp, ssp, len) != 0) + return(NULL); + while (m->g->strip[ss] != SOP(O_BACK, i)) + ss++; + return(backref(m, sp+len, stop, ss+1, stopst, lev)); + + case OQUEST_: /* to null or not */ + dp = backref(m, sp, stop, ss+1, stopst, lev); + if (dp != NULL) + return(dp); /* not */ + return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev)); + + case OPLUS_: + assert(m->lastpos != NULL); + assert(lev+1 <= m->g->nplus); + m->lastpos[lev+1] = sp; + return(backref(m, sp, stop, ss+1, stopst, lev+1)); + + case O_PLUS: + if (sp == m->lastpos[lev]) /* last pass matched null */ + return(backref(m, sp, stop, ss+1, stopst, lev-1)); + /* try another pass */ + m->lastpos[lev] = sp; + dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev); + if (dp == NULL) + dp = backref(m, sp, stop, ss+1, stopst, lev-1); + return(dp); + + case OCH_: /* find the right one, if any */ + ssub = ss + 1; + esub = ss + OPND(s) - 1; + assert(OP(m->g->strip[esub]) == OOR1); + for (;;) { /* find first matching branch */ + dp = backref(m, sp, stop, ssub, esub, lev); + if (dp != NULL) + return(dp); + /* that one missed, try next one */ + if (OP(m->g->strip[esub]) == O_CH) + return(NULL); /* there is none */ + esub++; + assert(OP(m->g->strip[esub]) == OOR2); + ssub = esub + 1; + esub += OPND(m->g->strip[esub]); + if (OP(m->g->strip[esub]) == OOR2) + esub--; + else + assert(OP(m->g->strip[esub]) == O_CH); + } + + case OLPAREN: /* must undo assignment if rest fails */ + i = OPND(s); + assert(0 < i && i <= m->g->nsub); + offsave = m->pmatch[i].rm_so; + m->pmatch[i].rm_so = sp - m->offp; + dp = backref(m, sp, stop, ss+1, stopst, lev); + if (dp != NULL) + return(dp); + m->pmatch[i].rm_so = offsave; + return(NULL); + + case ORPAREN: /* must undo assignment if rest fails */ + i = OPND(s); + assert(0 < i && i <= m->g->nsub); + offsave = m->pmatch[i].rm_eo; + m->pmatch[i].rm_eo = sp - m->offp; + dp = backref(m, sp, stop, ss+1, stopst, lev); + if (dp != NULL) + return(dp); + m->pmatch[i].rm_eo = offsave; + return(NULL); + + default: /* uh oh */ + assert(nope); + break; + } + + /* "can't happen" */ + assert(nope); + /* NOTREACHED */ + return NULL; +} + +/* + - fast - step through the string at top speed + == static const char *fast(struct match *m, const char *start, \ + == const char *stop, sopno startst, sopno stopst); + */ +static const char * /* where tentative match ended, or NULL */ +fast( + struct match *m, + const char *start, + const char *stop, + sopno startst, + sopno stopst) +{ + states st = m->st; + states fresh = m->fresh; + states tmp = m->tmp; + const char *p = start; + int c = (start == m->beginp) ? OUT : *(start-1); + int lastc; /* previous c */ + int flagch; + size_t i; + const char *coldp; /* last p after which no match was underway */ + + _DIAGASSERT(m != NULL); + _DIAGASSERT(start != NULL); + _DIAGASSERT(stop != NULL); + + CLEAR(st); + SET1(st, startst); + st = step(m->g, startst, stopst, st, NOTHING, st); + ASSIGN(fresh, st); + SP("start", st, *p); + coldp = NULL; + for (;;) { + /* next character */ + lastc = c; + c = (p == m->endp) ? OUT : *p; + if (EQ(st, fresh)) + coldp = p; + + /* is there an EOL and/or BOL between lastc and c? */ + flagch = '\0'; + i = 0; + if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || + (lastc == OUT && !(m->eflags®_NOTBOL)) ) { + flagch = BOL; + i = m->g->nbol; + } + if ( (c == '\n' && m->g->cflags®_NEWLINE) || + (c == OUT && !(m->eflags®_NOTEOL)) ) { + flagch = (flagch == BOL) ? BOLEOL : EOL; + i += m->g->neol; + } + if (i != 0) { + for (; i > 0; i--) + st = step(m->g, startst, stopst, st, flagch, st); + SP("boleol", st, c); + } + + /* how about a word boundary? */ + if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && + (c != OUT && ISWORD(c)) ) { + flagch = BOW; + } + if ( (lastc != OUT && ISWORD(lastc)) && + (flagch == EOL || (c != OUT && !ISWORD(c))) ) { + flagch = EOW; + } + if (flagch == BOW || flagch == EOW) { + st = step(m->g, startst, stopst, st, flagch, st); + SP("boweow", st, c); + } + + /* are we done? */ + if (ISSET(st, stopst) || p == stop) + break; /* NOTE BREAK OUT */ + + /* no, we must deal with this character */ + ASSIGN(tmp, st); + ASSIGN(st, fresh); + assert(c != OUT); + st = step(m->g, startst, stopst, tmp, c, st); + SP("aft", st, c); + assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); + p++; + } + + assert(coldp != NULL); + m->coldp = coldp; + if (ISSET(st, stopst)) + return(p+1); + else + return(NULL); +} + +/* + - slow - step through the string more deliberately + == static const char *slow(struct match *m, const char *start, \ + == const char *stop, sopno startst, sopno stopst); + */ +static const char * /* where it ended */ +slow( + struct match *m, + const char *start, + const char *stop, + sopno startst, + sopno stopst) +{ + states st = m->st; + states empty = m->empty; + states tmp = m->tmp; + const char *p = start; + int c = (start == m->beginp) ? OUT : *(start-1); + int lastc; /* previous c */ + int flagch; + size_t i; + const char *matchp; /* last p at which a match ended */ + + _DIAGASSERT(m != NULL); + _DIAGASSERT(start != NULL); + _DIAGASSERT(stop != NULL); + + AT("slow", start, stop, startst, stopst); + CLEAR(st); + SET1(st, startst); + SP("sstart", st, *p); + st = step(m->g, startst, stopst, st, NOTHING, st); + matchp = NULL; + for (;;) { + /* next character */ + lastc = c; + c = (p == m->endp) ? OUT : *p; + + /* is there an EOL and/or BOL between lastc and c? */ + flagch = '\0'; + i = 0; + if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || + (lastc == OUT && !(m->eflags®_NOTBOL)) ) { + flagch = BOL; + i = m->g->nbol; + } + if ( (c == '\n' && m->g->cflags®_NEWLINE) || + (c == OUT && !(m->eflags®_NOTEOL)) ) { + flagch = (flagch == BOL) ? BOLEOL : EOL; + i += m->g->neol; + } + if (i != 0) { + for (; i > 0; i--) + st = step(m->g, startst, stopst, st, flagch, st); + SP("sboleol", st, c); + } + + /* how about a word boundary? */ + if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && + (c != OUT && ISWORD(c)) ) { + flagch = BOW; + } + if ( (lastc != OUT && ISWORD(lastc)) && + (flagch == EOL || (c != OUT && !ISWORD(c))) ) { + flagch = EOW; + } + if (flagch == BOW || flagch == EOW) { + st = step(m->g, startst, stopst, st, flagch, st); + SP("sboweow", st, c); + } + + /* are we done? */ + if (ISSET(st, stopst)) + matchp = p; + if (EQ(st, empty) || p == stop) + break; /* NOTE BREAK OUT */ + + /* no, we must deal with this character */ + ASSIGN(tmp, st); + ASSIGN(st, empty); + assert(c != OUT); + st = step(m->g, startst, stopst, tmp, c, st); + SP("saft", st, c); + assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); + p++; + } + + return(matchp); +} + + +/* + - step - map set of states reachable before char to set reachable after + == static states step(struct re_guts *g, sopno start, sopno stop, \ + == states bef, int ch, states aft); + == #define BOL (OUT+1) + == #define EOL (BOL+1) + == #define BOLEOL (BOL+2) + == #define NOTHING (BOL+3) + == #define BOW (BOL+4) + == #define EOW (BOL+5) + == #define CODEMAX (BOL+5) // highest code used + == #define NONCHAR(c) ((c) > CHAR_MAX) + == #define NNONCHAR (CODEMAX-CHAR_MAX) + */ +static states +step( + struct re_guts *g, + sopno start, /* start state within strip */ + sopno stop, /* state after stop state within strip */ + states bef, /* states reachable before */ + int ch, /* character or NONCHAR code */ + states aft) /* states already known reachable after */ +{ + cset *cs; + sop s; + sopno pc; + onestate here; /* note, macros know this name */ + sopno look; + int i; + + _DIAGASSERT(g != NULL); + + for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) { + s = g->strip[pc]; + switch (OP(s)) { + case OEND: + assert(pc == stop-1); + break; + case OCHAR: + /* only characters can match */ + assert(!NONCHAR(ch) || ch != (char)OPND(s)); + if (ch == (char)OPND(s)) + FWD(aft, bef, 1); + break; + case OBOL: + if (ch == BOL || ch == BOLEOL) + FWD(aft, bef, 1); + break; + case OEOL: + if (ch == EOL || ch == BOLEOL) + FWD(aft, bef, 1); + break; + case OBOW: + if (ch == BOW) + FWD(aft, bef, 1); + break; + case OEOW: + if (ch == EOW) + FWD(aft, bef, 1); + break; + case OANY: + if (!NONCHAR(ch)) + FWD(aft, bef, 1); + break; + case OANYOF: + cs = &g->sets[OPND(s)]; + if (!NONCHAR(ch) && CHIN(cs, ch)) + FWD(aft, bef, 1); + break; + case OBACK_: /* ignored here */ + case O_BACK: + FWD(aft, aft, 1); + break; + case OPLUS_: /* forward, this is just an empty */ + FWD(aft, aft, 1); + break; + case O_PLUS: /* both forward and back */ + FWD(aft, aft, 1); + i = ISSETBACK(aft, OPND(s)); + BACK(aft, aft, OPND(s)); + if (!i && ISSETBACK(aft, OPND(s))) { + /* oho, must reconsider loop body */ + pc -= OPND(s) + 1; + INIT(here, pc); + } + break; + case OQUEST_: /* two branches, both forward */ + FWD(aft, aft, 1); + FWD(aft, aft, OPND(s)); + break; + case O_QUEST: /* just an empty */ + FWD(aft, aft, 1); + break; + case OLPAREN: /* not significant here */ + case ORPAREN: + FWD(aft, aft, 1); + break; + case OCH_: /* mark the first two branches */ + FWD(aft, aft, 1); + assert(OP(g->strip[pc+OPND(s)]) == OOR2); + FWD(aft, aft, OPND(s)); + break; + case OOR1: /* done a branch, find the O_CH */ + if (ISSTATEIN(aft, here)) { + for (look = 1; + OP(s = g->strip[pc+look]) != O_CH; + look += OPND(s)) + assert(OP(s) == OOR2); + FWD(aft, aft, look); + } + break; + case OOR2: /* propagate OCH_'s marking */ + FWD(aft, aft, 1); + if (OP(g->strip[pc+OPND(s)]) != O_CH) { + assert(OP(g->strip[pc+OPND(s)]) == OOR2); + FWD(aft, aft, OPND(s)); + } + break; + case O_CH: /* just empty */ + FWD(aft, aft, 1); + break; + default: /* ooooops... */ + assert(nope); + break; + } + } + + return(aft); +} + +#ifdef REDEBUG +/* + - print - print a set of states + == #ifdef REDEBUG + == static void print(struct match *m, char *caption, states st, \ + == int ch, FILE *d); + == #endif + */ +static void +print( + struct match *m, + char *caption, + states st, + int ch, + FILE *d) +{ + struct re_guts *g = m->g; + int i; + int first = 1; + + _DIAGASSERT(m != NULL); + _DIAGASSERT(caption != NULL); + + if (!(m->eflags®_TRACE)) + return; + + _DIAGASSERT(d != NULL); + + fprintf(d, "%s", caption); + if (ch != '\0') + fprintf(d, " %s", pchar(ch)); + for (i = 0; i < g->nstates; i++) + if (ISSET(st, i)) { + fprintf(d, "%s%d", (first) ? "\t" : ", ", i); + first = 0; + } + fprintf(d, "\n"); +} + +/* + - at - print current situation + == #ifdef REDEBUG + == static void at(struct match *m, char *title, char *start, char *stop, \ + == sopno startst, sopno stopst); + == #endif + */ +static void +at( + struct match *m, + char *title, + char *start, + char *stop, + sopno startst, + sopno stopst) +{ + + _DIAGASSERT(m != NULL); + _DIAGASSERT(title != NULL); + _DIAGASSERT(start != NULL); + _DIAGASSERT(stop != NULL); + + if (!(m->eflags®_TRACE)) + return; + + printf("%s %s-", title, pchar(*start)); + printf("%s ", pchar(*stop)); + printf("%ld-%ld\n", (long)startst, (long)stopst); +} + +#ifndef PCHARDONE +#define PCHARDONE /* never again */ +/* + - pchar - make a character printable + == #ifdef REDEBUG + == static char *pchar(int ch); + == #endif + * + * Is this identical to regchar() over in debug.c? Well, yes. But a + * duplicate here avoids having a debugging-capable regexec.o tied to + * a matching debug.o, and this is convenient. It all disappears in + * the non-debug compilation anyway, so it doesn't matter much. + */ +static char * /* -> representation */ +pchar( + int ch) +{ + static char pbuf[10]; + + if (isprint(ch) || ch == ' ') + (void)snprintf(pbuf, sizeof pbuf, "%c", ch); + else + (void)snprintf(pbuf, sizeof pbuf, "\\%o", ch); + return(pbuf); +} +#endif +#endif + +#undef matcher +#undef fast +#undef slow +#undef dissect +#undef backref +#undef step +#undef print +#undef at +#undef match +#undef nope diff --git a/libc/upstream-netbsd/lib/libc/regex/regcomp.c b/libc/upstream-netbsd/lib/libc/regex/regcomp.c new file mode 100644 index 0000000..2644a22 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/regex/regcomp.c @@ -0,0 +1,1944 @@ +/* $NetBSD: regcomp.c,v 1.33 2012/03/13 21:13:43 christos Exp $ */ + +/*- + * 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. 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. + * + * @(#)regcomp.c 8.5 (Berkeley) 3/20/94 + */ + +/*- + * Copyright (c) 1992, 1993, 1994 Henry Spencer. + * + * 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. + * + * @(#)regcomp.c 8.5 (Berkeley) 3/20/94 + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94"; +#else +__RCSID("$NetBSD: regcomp.c,v 1.33 2012/03/13 21:13:43 christos Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __weak_alias +__weak_alias(regcomp,_regcomp) +#endif + +#include "utils.h" +#include "regex2.h" + +#include "cclass.h" +#include "cname.h" + +/* + * parse structure, passed up and down to avoid global variables and + * other clumsinesses + */ +struct parse { + const char *next; /* next character in RE */ + const char *end; /* end of string (-> NUL normally) */ + int error; /* has an error been seen? */ + sop *strip; /* malloced strip */ + sopno ssize; /* malloced strip size (allocated) */ + sopno slen; /* malloced strip length (used) */ + size_t ncsalloc; /* number of csets allocated */ + struct re_guts *g; +# define NPAREN 10 /* we need to remember () 1-9 for back refs */ + sopno pbegin[NPAREN]; /* -> ( ([0] unused) */ + sopno pend[NPAREN]; /* -> ) ([0] unused) */ +}; + +/* ========= begin header generated by ./mkh ========= */ +#ifdef __cplusplus +extern "C" { +#endif + +/* === regcomp.c === */ +static void p_ere(struct parse *p, int stop, size_t reclimit); +static void p_ere_exp(struct parse *p, size_t reclimit); +static void p_str(struct parse *p); +static void p_bre(struct parse *p, int end1, int end2, size_t reclimit); +static int p_simp_re(struct parse *p, int starordinary, size_t reclimit); +static int p_count(struct parse *p); +static void p_bracket(struct parse *p); +static void p_b_term(struct parse *p, cset *cs); +static void p_b_cclass(struct parse *p, cset *cs); +static void p_b_eclass(struct parse *p, cset *cs); +static char p_b_symbol(struct parse *p); +static char p_b_coll_elem(struct parse *p, int endc); +static int othercase(int ch); +static void bothcases(struct parse *p, int ch); +static void ordinary(struct parse *p, int ch); +static void nonnewline(struct parse *p); +static void repeat(struct parse *p, sopno start, int from, int to, size_t reclimit); +static int seterr(struct parse *p, int e); +static cset *allocset(struct parse *p); +static void freeset(struct parse *p, cset *cs); +static sopno freezeset(struct parse *p, cset *cs); +static int firstch(struct parse *p, cset *cs); +static int nch(struct parse *p, cset *cs); +static void mcadd(struct parse *p, cset *cs, const char *cp); +#if 0 +static void mcsub(cset *cs, char *cp); +static int mcin(cset *cs, char *cp); +static char *mcfind(cset *cs, char *cp); +#endif +static void mcinvert(struct parse *p, cset *cs); +static void mccase(struct parse *p, cset *cs); +static int isinsets(struct re_guts *g, int c); +static int samesets(struct re_guts *g, int c1, int c2); +static void categorize(struct parse *p, struct re_guts *g); +static sopno dupl(struct parse *p, sopno start, sopno finish); +static void doemit(struct parse *p, sop op, sopno opnd); +static void doinsert(struct parse *p, sop op, sopno opnd, sopno pos); +static void dofwd(struct parse *p, sopno pos, sopno value); +static int enlarge(struct parse *p, sopno size); +static void stripsnug(struct parse *p, struct re_guts *g); +static void findmust(struct parse *p, struct re_guts *g); +static sopno pluscount(struct parse *p, struct re_guts *g); + +#ifdef __cplusplus +} +#endif +/* ========= end header generated by ./mkh ========= */ + +static char nuls[10]; /* place to point scanner in event of error */ + +/* + * macros for use with parse structure + * BEWARE: these know that the parse structure is named `p' !!! + */ +#define PEEK() (*p->next) +#define PEEK2() (*(p->next+1)) +#define MORE() (p->next < p->end) +#define MORE2() (p->next+1 < p->end) +#define SEE(c) (MORE() && PEEK() == (c)) +#define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b)) +#define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0) +#define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0) +#define NEXT() (p->next++) +#define NEXT2() (p->next += 2) +#define NEXTn(n) (p->next += (n)) +#define GETNEXT() (*p->next++) +#define SETERROR(e) seterr(p, (e)) +#define REQUIRE(co, e) (void) ((co) || SETERROR(e)) +#define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) +#define MUSTEAT(c, e) (void) (REQUIRE(MORE() && GETNEXT() == (c), e)) +#define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) +#define EMIT(op, sopnd) doemit(p, (sop)(op), sopnd) +#define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos) +#define AHEAD(pos) dofwd(p, pos, HERE()-(pos)) +#define ASTERN(sop, pos) EMIT(sop, HERE()-pos) +#define HERE() (p->slen) +#define THERE() (p->slen - 1) +#define THERETHERE() (p->slen - 2) +#define DROP(n) (p->slen -= (n)) + +#ifndef NDEBUG +static int never = 0; /* for use in asserts; shuts lint up */ +#else +#define never 0 /* some s have bugs too */ +#endif + +#define MEMLIMIT 0x8000000 +#define MEMSIZE(p) \ + ((p)->ncsalloc / CHAR_BIT * (p)->g->csetsize + \ + (p)->ncsalloc * sizeof(cset) + \ + (p)->ssize * sizeof(sop)) +#define RECLIMIT 256 + +/* + - regcomp - interface for parser and compilation + = extern int regcomp(regex_t *, const char *, int); + = #define REG_BASIC 0000 + = #define REG_EXTENDED 0001 + = #define REG_ICASE 0002 + = #define REG_NOSUB 0004 + = #define REG_NEWLINE 0010 + = #define REG_NOSPEC 0020 + = #define REG_PEND 0040 + = #define REG_DUMP 0200 + */ +int /* 0 success, otherwise REG_something */ +regcomp( + regex_t *preg, + const char *pattern, + int cflags) +{ + struct parse pa; + struct re_guts *g; + struct parse *p = &pa; + int i; + size_t len; +#ifdef REDEBUG +# define GOODFLAGS(f) (f) +#else +# define GOODFLAGS(f) ((f)&~REG_DUMP) +#endif + + _DIAGASSERT(preg != NULL); + _DIAGASSERT(pattern != NULL); + + cflags = GOODFLAGS(cflags); + if ((cflags®_EXTENDED) && (cflags®_NOSPEC)) + return(REG_INVARG); + + if (cflags®_PEND) { + if (preg->re_endp < pattern) + return(REG_INVARG); + len = preg->re_endp - pattern; + } else + len = strlen(pattern); + + /* do the mallocs early so failure handling is easy */ + g = (struct re_guts *)malloc(sizeof(struct re_guts) + + (NC-1)*sizeof(cat_t)); + if (g == NULL) + return(REG_ESPACE); + p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ + p->strip = malloc(p->ssize * sizeof(sop)); + p->slen = 0; + if (p->strip == NULL) { + free(g); + return(REG_ESPACE); + } + + /* set things up */ + p->g = g; + p->next = pattern; + p->end = p->next + len; + p->error = 0; + p->ncsalloc = 0; + for (i = 0; i < NPAREN; i++) { + p->pbegin[i] = 0; + p->pend[i] = 0; + } + g->csetsize = NC; + g->sets = NULL; + g->setbits = NULL; + g->ncsets = 0; + g->cflags = cflags; + g->iflags = 0; + g->nbol = 0; + g->neol = 0; + g->must = NULL; + g->mlen = 0; + g->nsub = 0; + g->ncategories = 1; /* category 0 is "everything else" */ + g->categories = &g->catspace[-(CHAR_MIN)]; + (void) memset((char *)g->catspace, 0, NC*sizeof(cat_t)); + g->backrefs = 0; + + /* do it */ + EMIT(OEND, 0); + g->firststate = THERE(); + if (cflags®_EXTENDED) + p_ere(p, OUT, 0); + else if (cflags®_NOSPEC) + p_str(p); + else + p_bre(p, OUT, OUT, 0); + EMIT(OEND, 0); + g->laststate = THERE(); + + /* tidy up loose ends and fill things in */ + categorize(p, g); + stripsnug(p, g); + findmust(p, g); + g->nplus = pluscount(p, g); + g->magic = MAGIC2; + preg->re_nsub = g->nsub; + preg->re_g = g; + preg->re_magic = MAGIC1; +#ifndef REDEBUG + /* not debugging, so can't rely on the assert() in regexec() */ + if (g->iflags&BAD) + SETERROR(REG_ASSERT); +#endif + + /* win or lose, we're done */ + if (p->error != 0) /* lose */ + regfree(preg); + return(p->error); +} + +/* + - p_ere - ERE parser top level, concatenation and alternation + == static void p_ere(struct parse *p, int stop, size_t reclimit); + */ +static void +p_ere( + struct parse *p, + int stop, /* character this ERE should end at */ + size_t reclimit) +{ + char c; + sopno prevback = 0; /* pacify gcc */ + sopno prevfwd = 0; /* pacify gcc */ + sopno conc; + int first = 1; /* is this the first alternative? */ + + _DIAGASSERT(p != NULL); + + if (reclimit++ > RECLIMIT || p->error == REG_ESPACE) { + p->error = REG_ESPACE; + return; + } + + for (;;) { + /* do a bunch of concatenated expressions */ + conc = HERE(); + while (MORE() && (c = PEEK()) != '|' && c != stop) + p_ere_exp(p, reclimit); + REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */ + + if (!EAT('|')) + break; /* NOTE BREAK OUT */ + + if (first) { + INSERT(OCH_, conc); /* offset is wrong */ + prevfwd = conc; + prevback = conc; + first = 0; + } + ASTERN(OOR1, prevback); + prevback = THERE(); + AHEAD(prevfwd); /* fix previous offset */ + prevfwd = HERE(); + EMIT(OOR2, 0); /* offset is very wrong */ + } + + if (!first) { /* tail-end fixups */ + AHEAD(prevfwd); + ASTERN(O_CH, prevback); + } + + assert(!MORE() || SEE(stop)); +} + +/* + - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op + == static void p_ere_exp(struct parse *p, size_t reclimit); + */ +static void +p_ere_exp( + struct parse *p, + size_t reclimit) +{ + char c; + sopno pos; + int count; + int count2; + sopno subno; + int wascaret = 0; + + _DIAGASSERT(p != NULL); + + assert(MORE()); /* caller should have ensured this */ + c = GETNEXT(); + + pos = HERE(); + switch (c) { + case '(': + REQUIRE(MORE(), REG_EPAREN); + p->g->nsub++; + subno = p->g->nsub; + if (subno < NPAREN) + p->pbegin[subno] = HERE(); + EMIT(OLPAREN, subno); + if (!SEE(')')) + p_ere(p, ')', reclimit); + if (subno < NPAREN) { + p->pend[subno] = HERE(); + assert(p->pend[subno] != 0); + } + EMIT(ORPAREN, subno); + MUSTEAT(')', REG_EPAREN); + break; +#ifndef POSIX_MISTAKE + case ')': /* happens only if no current unmatched ( */ + /* + * You may ask, why the ifndef? Because I didn't notice + * this until slightly too late for 1003.2, and none of the + * other 1003.2 regular-expression reviewers noticed it at + * all. So an unmatched ) is legal POSIX, at least until + * we can get it fixed. + */ + SETERROR(REG_EPAREN); + break; +#endif + case '^': + EMIT(OBOL, 0); + p->g->iflags |= USEBOL; + p->g->nbol++; + wascaret = 1; + break; + case '$': + EMIT(OEOL, 0); + p->g->iflags |= USEEOL; + p->g->neol++; + break; + case '|': + SETERROR(REG_EMPTY); + break; + case '*': + case '+': + case '?': + SETERROR(REG_BADRPT); + break; + case '.': + if (p->g->cflags®_NEWLINE) + nonnewline(p); + else + EMIT(OANY, 0); + break; + case '[': + p_bracket(p); + break; + case '\\': + REQUIRE(MORE(), REG_EESCAPE); + c = GETNEXT(); + ordinary(p, c); + break; + case '{': /* okay as ordinary except if digit follows */ + REQUIRE(!MORE() || !isdigit((unsigned char)PEEK()), REG_BADRPT); + /* FALLTHROUGH */ + default: + ordinary(p, c); + break; + } + + if (!MORE()) + return; + c = PEEK(); + /* we call { a repetition if followed by a digit */ + if (!( c == '*' || c == '+' || c == '?' || + (c == '{' && MORE2() && isdigit((unsigned char)PEEK2())) )) + return; /* no repetition, we're done */ + NEXT(); + + REQUIRE(!wascaret, REG_BADRPT); + switch (c) { + case '*': /* implemented as +? */ + /* this case does not require the (y|) trick, noKLUDGE */ + INSERT(OPLUS_, pos); + ASTERN(O_PLUS, pos); + INSERT(OQUEST_, pos); + ASTERN(O_QUEST, pos); + break; + case '+': + INSERT(OPLUS_, pos); + ASTERN(O_PLUS, pos); + break; + case '?': + /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ + INSERT(OCH_, pos); /* offset slightly wrong */ + ASTERN(OOR1, pos); /* this one's right */ + AHEAD(pos); /* fix the OCH_ */ + EMIT(OOR2, 0); /* offset very wrong... */ + AHEAD(THERE()); /* ...so fix it */ + ASTERN(O_CH, THERETHERE()); + break; + case '{': + count = p_count(p); + if (EAT(',')) { + if (isdigit((unsigned char)PEEK())) { + count2 = p_count(p); + REQUIRE(count <= count2, REG_BADBR); + } else /* single number with comma */ + count2 = INFINITY; + } else /* just a single number */ + count2 = count; + repeat(p, pos, count, count2, 0); + if (!EAT('}')) { /* error heuristics */ + while (MORE() && PEEK() != '}') + NEXT(); + REQUIRE(MORE(), REG_EBRACE); + SETERROR(REG_BADBR); + } + break; + } + + if (!MORE()) + return; + c = PEEK(); + if (!( c == '*' || c == '+' || c == '?' || + (c == '{' && MORE2() && isdigit((unsigned char)PEEK2())) ) ) + return; + SETERROR(REG_BADRPT); +} + +/* + - p_str - string (no metacharacters) "parser" + == static void p_str(struct parse *p); + */ +static void +p_str( + struct parse *p) +{ + + _DIAGASSERT(p != NULL); + + REQUIRE(MORE(), REG_EMPTY); + while (MORE()) + ordinary(p, GETNEXT()); +} + +/* + - p_bre - BRE parser top level, anchoring and concatenation + == static void p_bre(struct parse *p, int end1, \ + == int end2, size_t reclimit); + * Giving end1 as OUT essentially eliminates the end1/end2 check. + * + * This implementation is a bit of a kludge, in that a trailing $ is first + * taken as an ordinary character and then revised to be an anchor. The + * only undesirable side effect is that '$' gets included as a character + * category in such cases. This is fairly harmless; not worth fixing. + * The amount of lookahead needed to avoid this kludge is excessive. + */ +static void +p_bre( + struct parse *p, + int end1, /* first terminating character */ + int end2, /* second terminating character */ + size_t reclimit) +{ + sopno start; + int first = 1; /* first subexpression? */ + int wasdollar = 0; + + _DIAGASSERT(p != NULL); + + if (reclimit++ > RECLIMIT || p->error == REG_ESPACE) { + p->error = REG_ESPACE; + return; + } + + start = HERE(); + + if (EAT('^')) { + EMIT(OBOL, 0); + p->g->iflags |= USEBOL; + p->g->nbol++; + } + while (MORE() && !SEETWO(end1, end2)) { + wasdollar = p_simp_re(p, first, reclimit); + first = 0; + } + if (wasdollar) { /* oops, that was a trailing anchor */ + DROP(1); + EMIT(OEOL, 0); + p->g->iflags |= USEEOL; + p->g->neol++; + } + + REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */ +} + +/* + - p_simp_re - parse a simple RE, an atom possibly followed by a repetition + == static int p_simp_re(struct parse *p, int starordinary, size_t reclimit); + */ +static int /* was the simple RE an unbackslashed $? */ +p_simp_re( + struct parse *p, + int starordinary, /* is a leading * an ordinary character? */ + size_t reclimit) +{ + int c; + int count; + int count2; + sopno pos, i; + sopno subno; +# define BACKSL (1<g->cflags®_NEWLINE) + nonnewline(p); + else + EMIT(OANY, 0); + break; + case '[': + p_bracket(p); + break; + case BACKSL|'{': + SETERROR(REG_BADRPT); + break; + case BACKSL|'(': + p->g->nsub++; + subno = p->g->nsub; + if (subno < NPAREN) + p->pbegin[subno] = HERE(); + EMIT(OLPAREN, subno); + /* the MORE here is an error heuristic */ + if (MORE() && !SEETWO('\\', ')')) + p_bre(p, '\\', ')', reclimit); + if (subno < NPAREN) { + p->pend[subno] = HERE(); + assert(p->pend[subno] != 0); + } + EMIT(ORPAREN, subno); + REQUIRE(EATTWO('\\', ')'), REG_EPAREN); + break; + case BACKSL|')': /* should not get here -- must be user */ + case BACKSL|'}': + SETERROR(REG_EPAREN); + break; + case BACKSL|'1': + case BACKSL|'2': + case BACKSL|'3': + case BACKSL|'4': + case BACKSL|'5': + case BACKSL|'6': + case BACKSL|'7': + case BACKSL|'8': + case BACKSL|'9': + i = (c&~BACKSL) - '0'; + assert(i < NPAREN); + if (p->pend[i] != 0) { + assert(i <= p->g->nsub); + EMIT(OBACK_, i); + assert(p->pbegin[i] != 0); + assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); + assert(OP(p->strip[p->pend[i]]) == ORPAREN); + (void) dupl(p, p->pbegin[i]+1, p->pend[i]); + EMIT(O_BACK, i); + } else + SETERROR(REG_ESUBREG); + p->g->backrefs = 1; + break; + case '*': + REQUIRE(starordinary, REG_BADRPT); + /* FALLTHROUGH */ + default: + ordinary(p, c &~ BACKSL); + break; + } + + if (EAT('*')) { /* implemented as +? */ + /* this case does not require the (y|) trick, noKLUDGE */ + INSERT(OPLUS_, pos); + ASTERN(O_PLUS, pos); + INSERT(OQUEST_, pos); + ASTERN(O_QUEST, pos); + } else if (EATTWO('\\', '{')) { + count = p_count(p); + if (EAT(',')) { + if (MORE() && isdigit((unsigned char)PEEK())) { + count2 = p_count(p); + REQUIRE(count <= count2, REG_BADBR); + } else /* single number with comma */ + count2 = INFINITY; + } else /* just a single number */ + count2 = count; + repeat(p, pos, count, count2, 0); + if (!EATTWO('\\', '}')) { /* error heuristics */ + while (MORE() && !SEETWO('\\', '}')) + NEXT(); + REQUIRE(MORE(), REG_EBRACE); + SETERROR(REG_BADBR); + } + } else if (c == (unsigned char)'$') /* $ (but not \$) ends it */ + return(1); + + return(0); +} + +/* + - p_count - parse a repetition count + == static int p_count(struct parse *p); + */ +static int /* the value */ +p_count( + struct parse *p) +{ + int count = 0; + int ndigits = 0; + + _DIAGASSERT(p != NULL); + + while (MORE() && isdigit((unsigned char)PEEK()) && count <= DUPMAX) { + count = count*10 + (GETNEXT() - '0'); + ndigits++; + } + + REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR); + return(count); +} + +/* + - p_bracket - parse a bracketed character list + == static void p_bracket(struct parse *p); + * + * Note a significant property of this code: if the allocset() did SETERROR, + * no set operations are done. + */ +static void +p_bracket( + struct parse *p) +{ + cset *cs; + int invert = 0; + _DIAGASSERT(p != NULL); + + cs = allocset(p); + if (cs == NULL) + return; + + /* Dept of Truly Sickening Special-Case Kludges */ + if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", + (size_t)6) == 0) { + EMIT(OBOW, 0); + NEXTn(6); + return; + } + if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", + (size_t)6) == 0) { + EMIT(OEOW, 0); + NEXTn(6); + return; + } + + if (EAT('^')) + invert++; /* make note to invert set at end */ + if (EAT(']')) + CHadd(cs, ']'); + else if (EAT('-')) + CHadd(cs, '-'); + while (MORE() && PEEK() != ']' && !SEETWO('-', ']')) + p_b_term(p, cs); + if (EAT('-')) + CHadd(cs, '-'); + MUSTEAT(']', REG_EBRACK); + + if (p->error != 0) /* don't mess things up further */ + return; + + if (p->g->cflags®_ICASE) { + ssize_t i; + int ci; + + for (i = p->g->csetsize - 1; i >= 0; i--) + if (CHIN(cs, i) && isalpha(i)) { + ci = othercase((int)i); + if (ci != i) + CHadd(cs, ci); + } + if (cs->multis != NULL) + mccase(p, cs); + } + if (invert) { + ssize_t i; + + for (i = p->g->csetsize - 1; i >= 0; i--) + if (CHIN(cs, i)) + CHsub(cs, (int)i); + else + CHadd(cs, (int)i); + if (p->g->cflags®_NEWLINE) + CHsub(cs, '\n'); + if (cs->multis != NULL) + mcinvert(p, cs); + } + + assert(cs->multis == NULL); /* xxx */ + + if (nch(p, cs) == 1) { /* optimize singleton sets */ + ordinary(p, firstch(p, cs)); + freeset(p, cs); + } else + EMIT(OANYOF, freezeset(p, cs)); +} + +/* + - p_b_term - parse one term of a bracketed character list + == static void p_b_term(struct parse *p, cset *cs); + */ +static void +p_b_term( + struct parse *p, + cset *cs) +{ + char c; + char start, finish; + int i; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(cs != NULL); + + /* classify what we've got */ + switch ((MORE()) ? PEEK() : '\0') { + case '[': + c = (MORE2()) ? PEEK2() : '\0'; + break; + + case '-': + SETERROR(REG_ERANGE); + return; /* NOTE RETURN */ + + default: + c = '\0'; + break; + } + + switch (c) { + case ':': /* character class */ + NEXT2(); + REQUIRE(MORE(), REG_EBRACK); + c = PEEK(); + REQUIRE(c != '-' && c != ']', REG_ECTYPE); + p_b_cclass(p, cs); + REQUIRE(MORE(), REG_EBRACK); + REQUIRE(EATTWO(':', ']'), REG_ECTYPE); + break; + case '=': /* equivalence class */ + NEXT2(); + REQUIRE(MORE(), REG_EBRACK); + c = PEEK(); + REQUIRE(c != '-' && c != ']', REG_ECOLLATE); + p_b_eclass(p, cs); + REQUIRE(MORE(), REG_EBRACK); + REQUIRE(EATTWO('=', ']'), REG_ECOLLATE); + break; + default: /* symbol, ordinary character, or range */ +/* xxx revision needed for multichar stuff */ + start = p_b_symbol(p); + if (SEE('-') && MORE2() && PEEK2() != ']') { + /* range */ + NEXT(); + if (EAT('-')) + finish = '-'; + else + finish = p_b_symbol(p); + } else + finish = start; +/* xxx what about signed chars here... */ + REQUIRE(start <= finish, REG_ERANGE); + for (i = start; i <= finish; i++) + CHadd(cs, i); + break; + } +} + +/* + - p_b_cclass - parse a character-class name and deal with it + == static void p_b_cclass(struct parse *p, cset *cs); + */ +static void +p_b_cclass( + struct parse *p, + cset *cs) +{ + const char *sp; + const struct cclass *cp; + size_t len; + const char *u; + char c; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(cs != NULL); + + sp = p->next; + + while (MORE() && isalpha((unsigned char)PEEK())) + NEXT(); + len = p->next - sp; + for (cp = cclasses; cp->name != NULL; cp++) + if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') + break; + if (cp->name == NULL) { + /* oops, didn't find it */ + SETERROR(REG_ECTYPE); + return; + } + + u = cp->chars; + while ((c = *u++) != '\0') + CHadd(cs, c); + for (u = cp->multis; *u != '\0'; u += strlen(u) + 1) + MCadd(p, cs, u); +} + +/* + - p_b_eclass - parse an equivalence-class name and deal with it + == static void p_b_eclass(struct parse *p, cset *cs); + * + * This implementation is incomplete. xxx + */ +static void +p_b_eclass( + struct parse *p, + cset *cs) +{ + char c; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(cs != NULL); + + c = p_b_coll_elem(p, '='); + CHadd(cs, c); +} + +/* + - p_b_symbol - parse a character or [..]ed multicharacter collating symbol + == static char p_b_symbol(struct parse *p); + */ +static char /* value of symbol */ +p_b_symbol( + struct parse *p) +{ + char value; + + _DIAGASSERT(p != NULL); + + REQUIRE(MORE(), REG_EBRACK); + if (!EATTWO('[', '.')) + return(GETNEXT()); + + /* collating symbol */ + value = p_b_coll_elem(p, '.'); + REQUIRE(EATTWO('.', ']'), REG_ECOLLATE); + return(value); +} + +/* + - p_b_coll_elem - parse a collating-element name and look it up + == static char p_b_coll_elem(struct parse *p, int endc); + */ +static char /* value of collating element */ +p_b_coll_elem( + struct parse *p, + int endc) /* name ended by endc,']' */ +{ + const char *sp; + const struct cname *cp; + size_t len; + + _DIAGASSERT(p != NULL); + + sp = p->next; + + while (MORE() && !SEETWO(endc, ']')) + NEXT(); + if (!MORE()) { + SETERROR(REG_EBRACK); + return(0); + } + len = p->next - sp; + for (cp = cnames; cp->name != NULL; cp++) + if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') + return(cp->code); /* known name */ + if (len == 1) + return(*sp); /* single character */ + SETERROR(REG_ECOLLATE); /* neither */ + return(0); +} + +/* + - othercase - return the case counterpart of an alphabetic + == static int othercase(int ch); + */ +static int /* if no counterpart, return ch */ +othercase( + int ch) +{ + assert(isalpha(ch)); + if (isupper(ch)) + return(tolower(ch)); + else if (islower(ch)) + return(toupper(ch)); + else /* peculiar, but could happen */ + return(ch); +} + +/* + - bothcases - emit a dualcase version of a two-case character + == static void bothcases(struct parse *p, int ch); + * + * Boy, is this implementation ever a kludge... + */ +static void +bothcases( + struct parse *p, + int ch) +{ + const char *oldnext; + const char *oldend; + char bracket[3]; + + _DIAGASSERT(p != NULL); + + oldnext = p->next; + oldend = p->end; + + assert(othercase(ch) != ch); /* p_bracket() would recurse */ + p->next = bracket; + p->end = bracket+2; + bracket[0] = ch; + bracket[1] = ']'; + bracket[2] = '\0'; + p_bracket(p); + assert(p->next == bracket+2); + p->next = oldnext; + p->end = oldend; +} + +/* + - ordinary - emit an ordinary character + == static void ordinary(struct parse *p, int ch); + */ +static void +ordinary( + struct parse *p, + int ch) +{ + cat_t *cap; + + _DIAGASSERT(p != NULL); + + cap = p->g->categories; + if ((p->g->cflags®_ICASE) && isalpha((unsigned char) ch) + && othercase((unsigned char) ch) != (unsigned char) ch) + bothcases(p, (unsigned char) ch); + else { + EMIT(OCHAR, (sopno)(unsigned char)ch); + if (cap[ch] == 0) { + _DIAGASSERT(__type_fit(unsigned char, + p->g->ncategories + 1)); + cap[ch] = (unsigned char)p->g->ncategories++; + } + } +} + +/* + - nonnewline - emit REG_NEWLINE version of OANY + == static void nonnewline(struct parse *p); + * + * Boy, is this implementation ever a kludge... + */ +static void +nonnewline( + struct parse *p) +{ + const char *oldnext; + const char *oldend; + char bracket[4]; + + _DIAGASSERT(p != NULL); + + oldnext = p->next; + oldend = p->end; + + p->next = bracket; + p->end = bracket+3; + bracket[0] = '^'; + bracket[1] = '\n'; + bracket[2] = ']'; + bracket[3] = '\0'; + p_bracket(p); + assert(p->next == bracket+3); + p->next = oldnext; + p->end = oldend; +} + +/* + - repeat - generate code for a bounded repetition, recursively if needed + == static void repeat(struct parse *p, sopno start, int from, int to, + == size_t reclimit); + */ +static void +repeat( + struct parse *p, + sopno start, /* operand from here to end of strip */ + int from, /* repeated from this number */ + int to, /* to this number of times (maybe INFINITY) */ + size_t reclimit) +{ + sopno finish; +# define N 2 +# define INF 3 +# define REP(f, t) ((f)*8 + (t)) +# define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N) + sopno copy; + + _DIAGASSERT(p != NULL); + + if (reclimit++ > RECLIMIT) + p->error = REG_ESPACE; + if (p->error) + return; + + finish = HERE(); + + assert(from <= to); + + switch (REP(MAP(from), MAP(to))) { + case REP(0, 0): /* must be user doing this */ + DROP(finish-start); /* drop the operand */ + break; + case REP(0, 1): /* as x{1,1}? */ + case REP(0, N): /* as x{1,n}? */ + case REP(0, INF): /* as x{1,}? */ + /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ + INSERT(OCH_, start); /* offset is wrong... */ + repeat(p, start+1, 1, to, reclimit); + ASTERN(OOR1, start); + AHEAD(start); /* ... fix it */ + EMIT(OOR2, 0); + AHEAD(THERE()); + ASTERN(O_CH, THERETHERE()); + break; + case REP(1, 1): /* trivial case */ + /* done */ + break; + case REP(1, N): /* as x?x{1,n-1} */ + /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ + INSERT(OCH_, start); + ASTERN(OOR1, start); + AHEAD(start); + EMIT(OOR2, 0); /* offset very wrong... */ + AHEAD(THERE()); /* ...so fix it */ + ASTERN(O_CH, THERETHERE()); + copy = dupl(p, start+1, finish+1); + assert(copy == finish+4); + repeat(p, copy, 1, to-1, reclimit); + break; + case REP(1, INF): /* as x+ */ + INSERT(OPLUS_, start); + ASTERN(O_PLUS, start); + break; + case REP(N, N): /* as xx{m-1,n-1} */ + copy = dupl(p, start, finish); + repeat(p, copy, from-1, to-1, reclimit); + break; + case REP(N, INF): /* as xx{n-1,INF} */ + copy = dupl(p, start, finish); + repeat(p, copy, from-1, to, reclimit); + break; + default: /* "can't happen" */ + SETERROR(REG_ASSERT); /* just in case */ + break; + } +} + +/* + - seterr - set an error condition + == static int seterr(struct parse *p, int e); + */ +static int /* useless but makes type checking happy */ +seterr( + struct parse *p, + int e) +{ + + _DIAGASSERT(p != NULL); + + if (p->error == 0) /* keep earliest error condition */ + p->error = e; + p->next = nuls; /* try to bring things to a halt */ + p->end = nuls; + return(0); /* make the return value well-defined */ +} + +/* + - allocset - allocate a set of characters for [] + == static cset *allocset(struct parse *p); + */ +static cset * +allocset( + struct parse *p) +{ + size_t no; + size_t nc; + size_t nbytes; + cset *cs; + size_t css; + size_t i; + + _DIAGASSERT(p != NULL); + + no = p->g->ncsets++; + css = (size_t)p->g->csetsize; + if (no >= p->ncsalloc) { /* need another column of space */ + p->ncsalloc += CHAR_BIT; + nc = p->ncsalloc; + assert(nc % CHAR_BIT == 0); + nbytes = nc / CHAR_BIT * css; + if (MEMSIZE(p) > MEMLIMIT) + goto oomem; + if (p->g->sets == NULL) + p->g->sets = malloc(nc * sizeof(cset)); + else + p->g->sets = realloc(p->g->sets, nc * sizeof(cset)); + if (p->g->setbits == NULL) + p->g->setbits = malloc(nbytes); + else { + p->g->setbits = realloc(p->g->setbits, nbytes); + /* xxx this isn't right if setbits is now NULL */ + for (i = 0; i < no; i++) + p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT); + } + if (p->g->sets != NULL && p->g->setbits != NULL) + (void) memset((char *)p->g->setbits + (nbytes - css), + 0, css); + else { +oomem: + no = 0; + SETERROR(REG_ESPACE); + /* caller's responsibility not to do set ops */ + return NULL; + } + } + + cs = &p->g->sets[no]; + cs->ptr = p->g->setbits + css*((no)/CHAR_BIT); + cs->mask = 1 << (unsigned int)((no) % CHAR_BIT); + cs->hash = 0; + cs->smultis = 0; + cs->multis = NULL; + + return(cs); +} + +/* + - freeset - free a now-unused set + == static void freeset(struct parse *p, cset *cs); + */ +static void +freeset( + struct parse *p, + cset *cs) +{ + size_t i; + cset *top; + size_t css; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(cs != NULL); + + top = &p->g->sets[p->g->ncsets]; + css = (size_t)p->g->csetsize; + + for (i = 0; i < css; i++) + CHsub(cs, (int)i); + if (cs == top-1) /* recover only the easy case */ + p->g->ncsets--; +} + +/* + - freezeset - final processing on a set of characters + == static int freezeset(struct parse *p, cset *cs); + * + * The main task here is merging identical sets. This is usually a waste + * of time (although the hash code minimizes the overhead), but can win + * big if REG_ICASE is being used. REG_ICASE, by the way, is why the hash + * is done using addition rather than xor -- all ASCII [aA] sets xor to + * the same value! + */ +static sopno /* set number */ +freezeset( + struct parse *p, + cset *cs) +{ + uch h; + size_t i; + cset *top; + cset *cs2; + size_t css; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(cs != NULL); + + h = cs->hash; + top = &p->g->sets[p->g->ncsets]; + css = (size_t)p->g->csetsize; + + /* look for an earlier one which is the same */ + for (cs2 = &p->g->sets[0]; cs2 < top; cs2++) + if (cs2->hash == h && cs2 != cs) { + /* maybe */ + for (i = 0; i < css; i++) + if (!!CHIN(cs2, i) != !!CHIN(cs, i)) + break; /* no */ + if (i == css) + break; /* yes */ + } + + if (cs2 < top) { /* found one */ + freeset(p, cs); + cs = cs2; + } + + return (sopno)(cs - p->g->sets); +} + +/* + - firstch - return first character in a set (which must have at least one) + == static int firstch(struct parse *p, cset *cs); + */ +static int /* character; there is no "none" value */ +firstch( + struct parse *p, + cset *cs) +{ + size_t i; + size_t css; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(cs != NULL); + + css = (size_t)p->g->csetsize; + + for (i = 0; i < css; i++) + if (CHIN(cs, i)) + return((char)i); + assert(never); + return(0); /* arbitrary */ +} + +/* + - nch - number of characters in a set + == static int nch(struct parse *p, cset *cs); + */ +static int +nch( + struct parse *p, + cset *cs) +{ + size_t i; + size_t css; + int n = 0; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(cs != NULL); + + css = (size_t)p->g->csetsize; + + for (i = 0; i < css; i++) + if (CHIN(cs, i)) + n++; + return(n); +} + +/* + - mcadd - add a collating element to a cset + == static void mcadd(struct parse *p, cset *cs, \ + == char *cp); + */ +static void +mcadd( + struct parse *p, + cset *cs, + const char *cp) +{ + size_t oldend; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(cs != NULL); + _DIAGASSERT(cp != NULL); + + oldend = cs->smultis; + + cs->smultis += strlen(cp) + 1; + if (cs->multis == NULL) + cs->multis = malloc(cs->smultis); + else + cs->multis = realloc(cs->multis, cs->smultis); + if (cs->multis == NULL) { + SETERROR(REG_ESPACE); + return; + } + + (void) strcpy(cs->multis + oldend - 1, cp); + cs->multis[cs->smultis - 1] = '\0'; +} + +#if 0 +/* + - mcsub - subtract a collating element from a cset + == static void mcsub(cset *cs, char *cp); + */ +static void +mcsub( + cset *cs, + char *cp) +{ + char *fp; + size_t len; + + _DIAGASSERT(cs != NULL); + _DIAGASSERT(cp != NULL); + + fp = mcfind(cs, cp); + len = strlen(fp); + + assert(fp != NULL); + (void) memmove(fp, fp + len + 1, + cs->smultis - (fp + len + 1 - cs->multis)); + cs->smultis -= len; + + if (cs->smultis == 0) { + free(cs->multis); + cs->multis = NULL; + return; + } + + cs->multis = realloc(cs->multis, cs->smultis); + assert(cs->multis != NULL); +} + +/* + - mcin - is a collating element in a cset? + == static int mcin(cset *cs, char *cp); + */ +static int +mcin( + cset *cs, + char *cp) +{ + + _DIAGASSERT(cs != NULL); + _DIAGASSERT(cp != NULL); + + return(mcfind(cs, cp) != NULL); +} + +/* + - mcfind - find a collating element in a cset + == static char *mcfind(cset *cs, char *cp); + */ +static char * +mcfind( + cset *cs, + char *cp) +{ + char *p; + + _DIAGASSERT(cs != NULL); + _DIAGASSERT(cp != NULL); + + if (cs->multis == NULL) + return(NULL); + for (p = cs->multis; *p != '\0'; p += strlen(p) + 1) + if (strcmp(cp, p) == 0) + return(p); + return(NULL); +} +#endif + +/* + - mcinvert - invert the list of collating elements in a cset + == static void mcinvert(struct parse *p, cset *cs); + * + * This would have to know the set of possibilities. Implementation + * is deferred. + */ +/* ARGSUSED */ +static void +mcinvert( + struct parse *p, + cset *cs) +{ + + _DIAGASSERT(p != NULL); + _DIAGASSERT(cs != NULL); + + assert(cs->multis == NULL); /* xxx */ +} + +/* + - mccase - add case counterparts of the list of collating elements in a cset + == static void mccase(struct parse *p, cset *cs); + * + * This would have to know the set of possibilities. Implementation + * is deferred. + */ +/* ARGSUSED */ +static void +mccase( + struct parse *p, + cset *cs) +{ + + _DIAGASSERT(p != NULL); + _DIAGASSERT(cs != NULL); + + assert(cs->multis == NULL); /* xxx */ +} + +/* + - isinsets - is this character in any sets? + == static int isinsets(struct re_guts *g, int c); + */ +static int /* predicate */ +isinsets( + struct re_guts *g, + int c) +{ + uch *col; + size_t i; + size_t ncols; + unsigned uc = (unsigned char)c; + + _DIAGASSERT(g != NULL); + + if (g->setbits == NULL) + return 0; + + ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; + + for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) + if (col[uc] != 0) + return(1); + return(0); +} + +/* + - samesets - are these two characters in exactly the same sets? + == static int samesets(struct re_guts *g, int c1, int c2); + */ +static int /* predicate */ +samesets( + struct re_guts *g, + int c1, + int c2) +{ + uch *col; + size_t i; + size_t ncols; + unsigned uc1 = (unsigned char)c1; + unsigned uc2 = (unsigned char)c2; + + _DIAGASSERT(g != NULL); + + ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; + + for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) + if (col[uc1] != col[uc2]) + return(0); + return(1); +} + +/* + - categorize - sort out character categories + == static void categorize(struct parse *p, struct re_guts *g); + */ +static void +categorize( + struct parse *p, + struct re_guts *g) +{ + cat_t *cats; + int c; + int c2; + cat_t cat; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(g != NULL); + + cats = g->categories; + + /* avoid making error situations worse */ + if (p->error != 0) + return; + + for (c = CHAR_MIN; c <= CHAR_MAX; c++) + if (cats[c] == 0 && isinsets(g, c)) { + _DIAGASSERT(__type_fit(unsigned char, + g->ncategories + 1)); + cat = g->ncategories++; + cats[c] = cat; + for (c2 = c+1; c2 <= CHAR_MAX; c2++) + if (cats[c2] == 0 && samesets(g, c, c2)) + cats[c2] = cat; + } +} + +/* + - dupl - emit a duplicate of a bunch of sops + == static sopno dupl(struct parse *p, sopno start, sopno finish); + */ +static sopno /* start of duplicate */ +dupl( + struct parse *p, + sopno start, /* from here */ + sopno finish) /* to this less one */ +{ + sopno ret; + sopno len = finish - start; + + _DIAGASSERT(p != NULL); + + ret = HERE(); + + assert(finish >= start); + if (len == 0) + return(ret); + if (!enlarge(p, p->ssize + len))/* this many unexpected additions */ + return ret; + (void)memcpy(p->strip + p->slen, p->strip + start, + (size_t)len * sizeof(sop)); + p->slen += len; + return(ret); +} + +/* + - doemit - emit a strip operator + == static void doemit(struct parse *p, sop op, size_t opnd); + * + * It might seem better to implement this as a macro with a function as + * hard-case backup, but it's just too big and messy unless there are + * some changes to the data structures. Maybe later. + */ +static void +doemit( + struct parse *p, + sop op, + sopno opnd) +{ + _DIAGASSERT(p != NULL); + + /* avoid making error situations worse */ + if (p->error != 0) + return; + + /* deal with oversize operands ("can't happen", more or less) */ + assert(opnd < 1<slen >= p->ssize) + if (!enlarge(p, (p->ssize+1) / 2 * 3)) /* +50% */ + return; + + /* finally, it's all reduced to the easy case */ + p->strip[p->slen++] = (sop)SOP(op, opnd); +} + +/* + - doinsert - insert a sop into the strip + == static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos); + */ +static void +doinsert( + struct parse *p, + sop op, + sopno opnd, + sopno pos) +{ + sopno sn; + sop s; + int i; + + _DIAGASSERT(p != NULL); + + /* avoid making error situations worse */ + if (p->error != 0) + return; + + sn = HERE(); + EMIT(op, opnd); /* do checks, ensure space */ + assert(HERE() == sn+1); + s = p->strip[sn]; + + /* adjust paren pointers */ + assert(pos > 0); + for (i = 1; i < NPAREN; i++) { + if (p->pbegin[i] >= pos) { + p->pbegin[i]++; + } + if (p->pend[i] >= pos) { + p->pend[i]++; + } + } + + memmove(&p->strip[pos+1], &p->strip[pos], (HERE()-pos-1)*sizeof(sop)); + p->strip[pos] = s; +} + +/* + - dofwd - complete a forward reference + == static void dofwd(struct parse *p, sopno pos, sop value); + */ +static void +dofwd( + struct parse *p, + sopno pos, + sopno value) +{ + + _DIAGASSERT(p != NULL); + + /* avoid making error situations worse */ + if (p->error != 0) + return; + + assert(value < 1<strip[pos] = (sop)(OP(p->strip[pos]) | value); +} + +/* + - enlarge - enlarge the strip + == static void enlarge(struct parse *p, sopno size); + */ +static int +enlarge( + struct parse *p, + sopno size) +{ + sop *sp; + sopno osize; + + _DIAGASSERT(p != NULL); + + if (p->ssize >= size) + return 1; + + osize = p->ssize; + p->ssize = size; + if (MEMSIZE(p) > MEMLIMIT) + goto oomem; + sp = realloc(p->strip, p->ssize * sizeof(sop)); + if (sp == NULL) { +oomem: + p->ssize = osize; + SETERROR(REG_ESPACE); + return 0; + } + p->strip = sp; + return 1; +} + +/* + - stripsnug - compact the strip + == static void stripsnug(struct parse *p, struct re_guts *g); + */ +static void +stripsnug( + struct parse *p, + struct re_guts *g) +{ + + _DIAGASSERT(p != NULL); + _DIAGASSERT(g != NULL); + + g->nstates = p->slen; + g->strip = realloc(p->strip, p->slen * sizeof(sop)); + if (g->strip == NULL) { + SETERROR(REG_ESPACE); + g->strip = p->strip; + } +} + +/* + - findmust - fill in must and mlen with longest mandatory literal string + == static void findmust(struct parse *p, struct re_guts *g); + * + * This algorithm could do fancy things like analyzing the operands of | + * for common subsequences. Someday. This code is simple and finds most + * of the interesting cases. + * + * Note that must and mlen got initialized during setup. + */ +static void +findmust( + struct parse *p, + struct re_guts *g) +{ + sop *scan; + sop *start = NULL; + sop *newstart = NULL; + sopno newlen; + sop s; + char *cp; + sopno i; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(g != NULL); + + /* avoid making error situations worse */ + if (p->error != 0) + return; + + /* find the longest OCHAR sequence in strip */ + newlen = 0; + scan = g->strip + 1; + do { + s = *scan++; + switch (OP(s)) { + case OCHAR: /* sequence member */ + if (newlen == 0) /* new sequence */ + newstart = scan - 1; + newlen++; + break; + case OPLUS_: /* things that don't break one */ + case OLPAREN: + case ORPAREN: + break; + case OQUEST_: /* things that must be skipped */ + case OCH_: + scan--; + do { + scan += OPND(s); + s = *scan; + /* assert() interferes w debug printouts */ + if (OP(s) != O_QUEST && OP(s) != O_CH && + OP(s) != OOR2) { + g->iflags |= BAD; + return; + } + } while (OP(s) != O_QUEST && OP(s) != O_CH); + /* FALLTHROUGH */ + default: /* things that break a sequence */ + if (newlen > g->mlen) { /* ends one */ + start = newstart; + g->mlen = newlen; + } + newlen = 0; + break; + } + } while (OP(s) != OEND); + + if (start == NULL) + g->mlen = 0; + + if (g->mlen == 0) /* there isn't one */ + return; + + /* turn it into a character string */ + g->must = malloc((size_t)g->mlen + 1); + if (g->must == NULL) { /* argh; just forget it */ + g->mlen = 0; + return; + } + cp = g->must; + scan = start; + for (i = g->mlen; i > 0; i--) { + while (OP(s = *scan++) != OCHAR) + continue; + assert(cp < g->must + g->mlen); + *cp++ = (char)OPND(s); + } + assert(cp == g->must + g->mlen); + *cp++ = '\0'; /* just on general principles */ +} + +/* + - pluscount - count + nesting + == static sopno pluscount(struct parse *p, struct re_guts *g); + */ +static sopno /* nesting depth */ +pluscount( + struct parse *p, + struct re_guts *g) +{ + sop *scan; + sop s; + sopno plusnest = 0; + sopno maxnest = 0; + + _DIAGASSERT(p != NULL); + _DIAGASSERT(g != NULL); + + if (p->error != 0) + return(0); /* there may not be an OEND */ + + scan = g->strip + 1; + do { + s = *scan++; + switch (OP(s)) { + case OPLUS_: + plusnest++; + break; + case O_PLUS: + if (plusnest > maxnest) + maxnest = plusnest; + plusnest--; + break; + } + } while (OP(s) != OEND); + if (plusnest != 0) + g->iflags |= BAD; + return(maxnest); +} diff --git a/libc/upstream-netbsd/lib/libc/regex/regerror.c b/libc/upstream-netbsd/lib/libc/regex/regerror.c new file mode 100644 index 0000000..e00d7c0 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/regex/regerror.c @@ -0,0 +1,223 @@ +/* $NetBSD: regerror.c,v 1.23 2007/02/09 23:44:18 junyoung Exp $ */ + +/*- + * 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. 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 + */ + +/*- + * Copyright (c) 1992, 1993, 1994 Henry Spencer. + * + * 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 + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94"; +#else +__RCSID("$NetBSD: regerror.c,v 1.23 2007/02/09 23:44:18 junyoung Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __weak_alias +__weak_alias(regerror,_regerror) +#endif + +#include "utils.h" + +/* ========= begin header generated by ./mkh ========= */ +#ifdef __cplusplus +extern "C" { +#endif + +/* === regerror.c === */ +static const char *regatoi(const regex_t *preg, char *localbuf, size_t buflen); + +#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_ATOI 255 // convert name to number (!) + = #define REG_ITOA 0400 // convert number to name (!) + */ +static const struct rerr { + int code; + const char *name; + const char *explain; +} rerrs[] = { + { REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match" }, + { REG_BADPAT, "REG_BADPAT", "invalid regular expression" }, + { REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element" }, + { REG_ECTYPE, "REG_ECTYPE", "invalid character class" }, + { REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)" }, + { REG_ESUBREG, "REG_ESUBREG", "invalid backreference number" }, + { REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced" }, + { REG_EPAREN, "REG_EPAREN", "parentheses not balanced" }, + { REG_EBRACE, "REG_EBRACE", "braces not balanced" }, + { REG_BADBR, "REG_BADBR", "invalid repetition count(s)" }, + { REG_ERANGE, "REG_ERANGE", "invalid character range" }, + { REG_ESPACE, "REG_ESPACE", "out of memory" }, + { REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid" }, + { REG_EMPTY, "REG_EMPTY", "empty (sub)expression" }, + { REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug" }, + { REG_INVARG, "REG_INVARG", "invalid argument to regex routine" }, + { 0, "", "*** unknown regexp error code ***" } +}; + +/* + * regerror - the interface to error numbers + * extern size_t regerror(int, const regex_t *, char *, size_t); + */ +/* ARGSUSED */ +size_t +regerror( + int errcode, + const regex_t *preg, + char *errbuf, + size_t errbuf_size) +{ + const struct rerr *r; + size_t len; + int target = errcode &~ REG_ITOA; + const char *s; + char convbuf[50]; + + _DIAGASSERT(errcode != REG_ATOI || preg != NULL); + _DIAGASSERT(errbuf != NULL); + + if (errcode == REG_ATOI) + s = regatoi(preg, convbuf, sizeof convbuf); + else { + for (r = rerrs; r->code != 0; r++) + if (r->code == target) + break; + + if (errcode & REG_ITOA) { + if (r->code != 0) { + (void)strlcpy(convbuf, r->name, sizeof convbuf); + } else + (void)snprintf(convbuf, sizeof convbuf, + "REG_0x%x", target); + s = convbuf; + } else + s = r->explain; + } + + len = strlen(s) + 1; + if (errbuf_size > 0) + (void)strlcpy(errbuf, s, errbuf_size); + + return(len); +} + +/* + * regatoi - internal routine to implement REG_ATOI + * static const char *regatoi(const regex_t *preg, char *localbuf, + * size_t buflen); + */ +static const char * +regatoi( + const regex_t *preg, + char *localbuf, + size_t buflen) +{ + const 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"; + + (void)snprintf(localbuf, buflen, "%d", r->code); + return localbuf; +} diff --git a/libc/upstream-netbsd/lib/libc/regex/regex2.h b/libc/upstream-netbsd/lib/libc/regex/regex2.h new file mode 100644 index 0000000..7c877ee --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/regex/regex2.h @@ -0,0 +1,209 @@ +/* $NetBSD: regex2.h,v 1.13 2011/10/09 18:23:00 christos Exp $ */ + +/*- + * 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. 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. + * + * @(#)regex2.h 8.4 (Berkeley) 3/20/94 + */ + +/*- + * Copyright (c) 1992, 1993, 1994 Henry Spencer. + * + * 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. + * + * @(#)regex2.h 8.4 (Berkeley) 3/20/94 + */ + +/* + * First, the stuff that ends up in the outside-world include file + = typedef off_t regoff_t; + = typedef struct { + = int re_magic; + = size_t re_nsub; // number of parenthesized subexpressions + = const char *re_endp; // end pointer for REG_PEND + = struct re_guts *re_g; // none of your business :-) + = } regex_t; + = typedef struct { + = regoff_t rm_so; // start of match + = regoff_t rm_eo; // end of match + = } regmatch_t; + */ +/* + * internals of regex_t + */ +#define MAGIC1 ((('r'^0200)<<8) | 'e') + +/* + * The internal representation is a *strip*, a sequence of + * operators ending with an endmarker. (Some terminology etc. is a + * historical relic of earlier versions which used multiple strips.) + * Certain oddities in the representation are there to permit running + * the machinery backwards; in particular, any deviation from sequential + * flow must be marked at both its source and its destination. Some + * fine points: + * + * - OPLUS_ and O_PLUS are *inside* the loop they create. + * - OQUEST_ and O_QUEST are *outside* the bypass they create. + * - OCH_ and O_CH are *outside* the multi-way branch they create, while + * OOR1 and OOR2 are respectively the end and the beginning of one of + * the branches. Note that there is an implicit OOR2 following OCH_ + * and an implicit OOR1 preceding O_CH. + * + * In state representations, an operator's bit is on to signify a state + * immediately *preceding* "execution" of that operator. + */ +typedef u_int32_t sop; /* strip operator */ +typedef size_t sopno; +#define OPRMASK ((u_int32_t)0xf8000000UL) +#define OPDMASK ((u_int32_t)0x07ffffffUL) +#define OPSHIFT ((unsigned)27) +#define OP(n) ((n)&OPRMASK) +#define OPND(n) ((int)((n)&OPDMASK)) +#define SOP(op, opnd) ((op)|(opnd)) + +#define OPC(n) (((u_int32_t)(n))< uch [csetsize] */ + uch mask; /* bit within array */ + uch hash; /* hash code */ + size_t smultis; + char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */ +} cset; +/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */ +#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c)) +#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c)) +#define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask) +#define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */ +#define MCsub(p, cs, cp) mcsub(p, cs, cp) +#define MCin(p, cs, cp) mcin(p, cs, cp) + +/* stuff for character categories */ +typedef unsigned char cat_t; + +/* + * main compiled-expression structure + */ +struct re_guts { + int magic; +# define MAGIC2 ((('R'^0200)<<8)|'E') + sop *strip; /* malloced area for strip */ + size_t csetsize; /* number of bits in a cset vector */ + size_t ncsets; /* number of csets in use */ + cset *sets; /* -> cset [ncsets] */ + uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */ + int cflags; /* copy of regcomp() cflags argument */ + sopno nstates; /* = number of sops */ + sopno firststate; /* the initial OEND (normally 0) */ + sopno laststate; /* the final OEND */ + int iflags; /* internal flags */ +# define USEBOL 01 /* used ^ */ +# define USEEOL 02 /* used $ */ +# define BAD 04 /* something wrong */ + size_t nbol; /* number of ^ used */ + size_t neol; /* number of $ used */ + size_t ncategories; /* how many character categories */ + cat_t *categories; /* ->catspace[-CHAR_MIN] */ + char *must; /* match must contain this string */ + size_t mlen; /* length of must */ + size_t nsub; /* copy of re_nsub */ + int backrefs; /* does it use back references? */ + sopno nplus; /* how deep does it nest +s? */ + /* catspace must be last */ + cat_t catspace[1]; /* actually [NC] */ +}; + +/* misc utilities */ +#define OUT (CHAR_MAX+1) /* a non-character value */ +#define ISWORD(c) (isalnum((unsigned char)c) || (c) == '_') diff --git a/libc/upstream-netbsd/lib/libc/regex/regexec.c b/libc/upstream-netbsd/lib/libc/regex/regexec.c new file mode 100644 index 0000000..f16e0b6 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/regex/regexec.c @@ -0,0 +1,234 @@ +/* $NetBSD: regexec.c,v 1.22 2012/03/13 21:13:43 christos Exp $ */ + +/*- + * 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. 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. + * + * @(#)regexec.c 8.3 (Berkeley) 3/20/94 + */ + +/*- + * Copyright (c) 1992, 1993, 1994 Henry Spencer. + * + * 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. + * + * @(#)regexec.c 8.3 (Berkeley) 3/20/94 + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94"; +#else +__RCSID("$NetBSD: regexec.c,v 1.22 2012/03/13 21:13:43 christos Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +/* + * the outer shell of regexec() + * + * This file includes engine.c *twice*, after muchos fiddling with the + * macros that code uses. This lets the same code operate on two different + * representations for state sets. + */ +#include "namespace.h" +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __weak_alias +__weak_alias(regexec,_regexec) +#endif + +#include "utils.h" +#include "regex2.h" + +/* macros for manipulating states, small version */ +#define states unsigned long +#define states1 unsigned long /* for later use in regexec() decision */ +#define CLEAR(v) ((v) = 0) +#define SET0(v, n) ((v) &= ~((unsigned long)1 << (n))) +#define SET1(v, n) ((v) |= (unsigned long)1 << (n)) +#define ISSET(v, n) (((v) & ((unsigned long)1 << (n))) != 0) +#define ASSIGN(d, s) ((d) = (s)) +#define EQ(a, b) ((a) == (b)) +#define STATEVARS int dummy /* dummy version */ +#define STATESETUP(m, n) /* nothing */ +#define STATETEARDOWN(m) /* nothing */ +#define SETUP(v) ((v) = 0) +#define onestate unsigned long +#define INIT(o, n) ((o) = (unsigned long)1 << (n)) +#define INC(o) ((o) <<= 1) +#define ISSTATEIN(v, o) (((v) & (o)) != 0) +/* some abbreviations; note that some of these know variable names! */ +/* do "if I'm here, I can also be there" etc without branches */ +#define FWD(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) << (n)) +#define BACK(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) >> (n)) +#define ISSETBACK(v, n) (((v) & ((unsigned long)here >> (n))) != 0) +/* function names */ +#define SNAMES /* engine.c looks after details */ + +#include "engine.c" + +/* now undo things */ +#undef states +#undef CLEAR +#undef SET0 +#undef SET1 +#undef ISSET +#undef ASSIGN +#undef EQ +#undef STATEVARS +#undef STATESETUP +#undef STATETEARDOWN +#undef SETUP +#undef onestate +#undef INIT +#undef INC +#undef ISSTATEIN +#undef FWD +#undef BACK +#undef ISSETBACK +#undef SNAMES + +/* macros for manipulating states, large version */ +#define states char * +#define CLEAR(v) memset(v, 0, (size_t)m->g->nstates) +#define SET0(v, n) ((v)[n] = 0) +#define SET1(v, n) ((v)[n] = 1) +#define ISSET(v, n) ((v)[n]) +#define ASSIGN(d, s) memcpy(d, s, (size_t)m->g->nstates) +#define EQ(a, b) (memcmp(a, b, (size_t)m->g->nstates) == 0) +#define STATEVARS int vn; char *space +#define STATESETUP(m, nv) \ + if (((m)->space = malloc((size_t)((nv)*(m)->g->nstates))) == NULL) \ + return(REG_ESPACE); \ + else \ + (m)->vn = 0 + +#define STATETEARDOWN(m) { free((m)->space); m->space = NULL; } +#define SETUP(v) ((v) = &m->space[(size_t)(m->vn++ * m->g->nstates)]) +#define onestate int +#define INIT(o, n) ((o) = (int)(n)) +#define INC(o) ((o)++) +#define ISSTATEIN(v, o) ((v)[o]) +/* some abbreviations; note that some of these know variable names! */ +/* do "if I'm here, I can also be there" etc without branches */ +#define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here]) +#define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here]) +#define ISSETBACK(v, n) ((v)[here - (n)]) +/* function names */ +#define LNAMES /* flag */ + +#include "engine.c" + +/* + - regexec - interface for matching + = extern int regexec(const regex_t *, const char *, size_t, \ + = regmatch_t [], int); + = #define REG_NOTBOL 00001 + = #define REG_NOTEOL 00002 + = #define REG_STARTEND 00004 + = #define REG_TRACE 00400 // tracing of execution + = #define REG_LARGE 01000 // force large representation + = #define REG_BACKR 02000 // force use of backref code + * + * We put this here so we can exploit knowledge of the state representation + * when choosing which matcher to call. Also, by this point the matchers + * have been prototyped. + */ +int /* 0 success, REG_NOMATCH failure */ +regexec( + const regex_t *preg, + const char *string, + size_t nmatch, + regmatch_t pmatch[], + int eflags) +{ + struct re_guts *g = preg->re_g; + char *s; +#ifdef REDEBUG +# define GOODFLAGS(f) (f) +#else +# define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND)) +#endif + + _DIAGASSERT(preg != NULL); + _DIAGASSERT(string != NULL); + + if (preg->re_magic != MAGIC1 || g->magic != MAGIC2) + return(REG_BADPAT); + assert(!(g->iflags&BAD)); + if (g->iflags&BAD) /* backstop for no-debug case */ + return(REG_BADPAT); + eflags = GOODFLAGS(eflags); + + s = __UNCONST(string); + + if (g->nstates <= (sopno)(CHAR_BIT*sizeof(states1)) && !(eflags®_LARGE)) + return(smatcher(g, s, nmatch, pmatch, eflags)); + else + return(lmatcher(g, s, nmatch, pmatch, eflags)); +} diff --git a/libc/upstream-netbsd/lib/libc/regex/regfree.c b/libc/upstream-netbsd/lib/libc/regex/regfree.c new file mode 100644 index 0000000..ce011ea --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/regex/regfree.c @@ -0,0 +1,129 @@ +/* $NetBSD: regfree.c,v 1.15 2007/02/09 23:44:18 junyoung Exp $ */ + +/*- + * 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. 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. + * + * @(#)regfree.c 8.3 (Berkeley) 3/20/94 + */ + +/*- + * Copyright (c) 1992, 1993, 1994 Henry Spencer. + * + * 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. + * + * @(#)regfree.c 8.3 (Berkeley) 3/20/94 + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94"; +#else +__RCSID("$NetBSD: regfree.c,v 1.15 2007/02/09 23:44:18 junyoung Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include + +#include +#include +#include +#include + +#ifdef __weak_alias +__weak_alias(regfree,_regfree) +#endif + +#include "utils.h" +#include "regex2.h" + +/* + - regfree - free everything + = extern void regfree(regex_t *); + */ +void +regfree( + regex_t *preg) +{ + struct re_guts *g; + + _DIAGASSERT(preg != NULL); + + _DIAGASSERT(preg->re_magic == MAGIC1); + if (preg->re_magic != MAGIC1) /* oops */ + return; /* nice to complain, but hard */ + + g = preg->re_g; + if (g == NULL || g->magic != MAGIC2) /* oops again */ + return; + preg->re_magic = 0; /* mark it invalid */ + g->magic = 0; /* mark it invalid */ + + if (g->strip != NULL) + free(g->strip); + if (g->sets != NULL) + free(g->sets); + if (g->setbits != NULL) + free(g->setbits); + if (g->must != NULL) + free(g->must); + free(g); +} diff --git a/libc/upstream-netbsd/lib/libc/regex/utils.h b/libc/upstream-netbsd/lib/libc/regex/utils.h new file mode 100644 index 0000000..762caee --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/regex/utils.h @@ -0,0 +1,91 @@ +/* $NetBSD: utils.h,v 1.6 2003/08/07 16:43:21 agc Exp $ */ + +/*- + * 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. 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 + */ + +/*- + * Copyright (c) 1992, 1993, 1994 Henry Spencer. + * + * 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 + */ + +/* 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/libc/upstream-netbsd/lib/libc/stdio/getdelim.c b/libc/upstream-netbsd/lib/libc/stdio/getdelim.c new file mode 100644 index 0000000..acce376 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdio/getdelim.c @@ -0,0 +1,154 @@ +/* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */ + +/* + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Roy Marples. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__RCSID("$NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $"); + +#include "namespace.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include "reentrant.h" +#include "local.h" + +#ifdef __weak_alias +__weak_alias(getdelim, _getdelim) +#endif + +/* Minimum buffer size we create. + * This should allow config files to fit into our power of 2 buffer growth + * without the need for a realloc. */ +#define MINBUF 128 + +ssize_t +__getdelim(char **__restrict buf, size_t *__restrict buflen, + int sep, FILE *__restrict fp) +{ + unsigned char *p; + size_t len, newlen, off; + char *newb; + + _DIAGASSERT(fp != NULL); + + if (buf == NULL || buflen == NULL) { + errno = EINVAL; + goto error; + } + + /* If buf is NULL, we have to assume a size of zero */ + if (*buf == NULL) + *buflen = 0; + + _SET_ORIENTATION(fp, -1); + off = 0; + do { + /* If the input buffer is empty, refill it */ + if (fp->_r <= 0 && __srefill(fp)) { + if (__sferror(fp)) + goto error; + /* No error, so EOF. */ + break; + } + + /* Scan through looking for the separator */ + p = memchr(fp->_p, sep, (size_t)fp->_r); + if (p == NULL) + len = fp->_r; + else + len = (p - fp->_p) + 1; + + newlen = off + len; + /* Ensure we can handle it */ + if (newlen < off || newlen > SSIZE_MAX) { + errno = EOVERFLOW; + goto error; + } + newlen++; /* reserve space for the NULL terminator */ + if (newlen > *buflen) { + if (newlen < MINBUF) + newlen = MINBUF; + if (!powerof2(newlen)) { + /* Grow the buffer to the next power of 2 */ + newlen--; + newlen |= newlen >> 1; + newlen |= newlen >> 2; + newlen |= newlen >> 4; + newlen |= newlen >> 8; + newlen |= newlen >> 16; +#if SIZE_T_MAX > 0xffffffffU + newlen |= newlen >> 32; +#endif + newlen++; + } + + newb = realloc(*buf, newlen); + if (newb == NULL) + goto error; + *buf = newb; + *buflen = newlen; + } + + (void)memcpy((*buf + off), fp->_p, len); + /* Safe, len is never greater than what fp->_r can fit. */ + fp->_r -= (int)len; + fp->_p += (int)len; + off += len; + } while (p == NULL); + + /* POSIX demands we return -1 on EOF. */ + if (off == 0) + return -1; + + if (*buf != NULL) + *(*buf + off) = '\0'; + return off; + +error: + fp->_flags |= __SERR; + return -1; +} + +ssize_t +getdelim(char **__restrict buf, size_t *__restrict buflen, + int sep, FILE *__restrict fp) +{ + ssize_t n; + + FLOCKFILE(fp); + n = __getdelim(buf, buflen, sep, fp); + FUNLOCKFILE(fp); + return n; +} diff --git a/libc/upstream-netbsd/lib/libc/stdio/getline.c b/libc/upstream-netbsd/lib/libc/stdio/getline.c new file mode 100644 index 0000000..e5d4bab --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdio/getline.c @@ -0,0 +1,45 @@ +/* $NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $ */ + +/* + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Roy Marples. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__RCSID("$NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $"); + +#include "namespace.h" + +#include + +#ifdef __weak_alias +__weak_alias(getline, _getline) +#endif + +ssize_t +getline(char **__restrict buf, size_t *__restrict buflen, FILE *__restrict fp) +{ + return getdelim(buf, buflen, '\n', fp); +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/_rand48.c b/libc/upstream-netbsd/lib/libc/stdlib/_rand48.c new file mode 100644 index 0000000..0468026 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/_rand48.c @@ -0,0 +1,57 @@ +/* $NetBSD: _rand48.c,v 1.7 2005/06/12 05:21:27 lukem Exp $ */ + +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: _rand48.c,v 1.7 2005/06/12 05:21:27 lukem Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include + +#include "rand48.h" + +unsigned short __rand48_seed[3] = { + RAND48_SEED_0, + RAND48_SEED_1, + RAND48_SEED_2 +}; +unsigned short __rand48_mult[3] = { + RAND48_MULT_0, + RAND48_MULT_1, + RAND48_MULT_2 +}; +unsigned short __rand48_add = RAND48_ADD; + +void +__dorand48(unsigned short xseed[3]) +{ + unsigned long accu; + unsigned short temp[2]; + + _DIAGASSERT(xseed != NULL); + + accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0] + + (unsigned long) __rand48_add; + temp[0] = (unsigned short) accu; /* lower 16 bits */ + accu >>= sizeof(unsigned short) * 8; + accu += (unsigned long) __rand48_mult[0] * (unsigned long) xseed[1] + + (unsigned long) __rand48_mult[1] * (unsigned long) xseed[0]; + temp[1] = (unsigned short) accu; /* middle 16 bits */ + accu >>= sizeof(unsigned short) * 8; + accu += __rand48_mult[0] * xseed[2] + __rand48_mult[1] * xseed[1] + __rand48_mult[2] * xseed[0]; + xseed[0] = temp[0]; + xseed[1] = temp[1]; + xseed[2] = (unsigned short) accu; +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/bsearch.c b/libc/upstream-netbsd/lib/libc/stdlib/bsearch.c new file mode 100644 index 0000000..2b0e0d8 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/bsearch.c @@ -0,0 +1,85 @@ +/* $NetBSD: bsearch.c,v 1.15 2012/03/04 20:01:45 christos Exp $ */ + +/* + * 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. 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) +#if 0 +static char sccsid[] = "@(#)bsearch.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: bsearch.c,v 1.15 2012/03/04 20:01:45 christos Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#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(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; + + _DIAGASSERT(key != NULL); + _DIAGASSERT(base0 != NULL || nmemb == 0); + _DIAGASSERT(compar != NULL); + + for (lim = nmemb; lim != 0; lim >>= 1) { + p = base + (lim >> 1) * size; + cmp = (*compar)(key, p); + if (cmp == 0) + return __UNCONST(p); + if (cmp > 0) { /* key > p: move right */ + base = (const char *)p + size; + lim--; + } /* else move left */ + } + return (NULL); +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/div.c b/libc/upstream-netbsd/lib/libc/stdlib/div.c new file mode 100644 index 0000000..f3bd32f --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/div.c @@ -0,0 +1,81 @@ +/* $NetBSD: div.c,v 1.8 2012/06/25 22:32:45 abs Exp $ */ + +/* + * 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. 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) +#if 0 +static char sccsid[] = "@(#)div.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: div.c,v 1.8 2012/06/25 22:32:45 abs Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include /* div_t */ + +div_t +div(int num, int 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/libc/upstream-netbsd/lib/libc/stdlib/drand48.c b/libc/upstream-netbsd/lib/libc/stdlib/drand48.c new file mode 100644 index 0000000..6fba607 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/drand48.c @@ -0,0 +1,32 @@ +/* $NetBSD: drand48.c,v 1.6 2005/06/12 05:21:28 lukem Exp $ */ + +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: drand48.c,v 1.6 2005/06/12 05:21:28 lukem Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include "rand48.h" + +#ifdef __weak_alias +__weak_alias(drand48,_drand48) +#endif + +double +drand48(void) +{ + return erand48(__rand48_seed); +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/erand48.c b/libc/upstream-netbsd/lib/libc/stdlib/erand48.c new file mode 100644 index 0000000..f1d8b4d --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/erand48.c @@ -0,0 +1,42 @@ +/* $NetBSD: erand48.c,v 1.9 2006/03/22 20:52:16 drochner Exp $ */ + +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: erand48.c,v 1.9 2006/03/22 20:52:16 drochner Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" + +#include +#include + +#include "rand48.h" + +#ifdef __weak_alias +__weak_alias(erand48,_erand48) +#endif + +double +erand48(unsigned short xseed[3]) +{ + + _DIAGASSERT(xseed != NULL); + + __dorand48(xseed); + return ldexp((double) xseed[0], -48) + + ldexp((double) xseed[1], -32) + + ldexp((double) xseed[2], -16); +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/exit.c b/libc/upstream-netbsd/lib/libc/stdlib/exit.c new file mode 100644 index 0000000..67e6adf --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/exit.c @@ -0,0 +1,63 @@ +/* $NetBSD: exit.c,v 1.15 2011/05/18 19:36:36 dsl Exp $ */ + +/*- + * 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. 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) +#if 0 +static char sccsid[] = "@(#)exit.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: exit.c,v 1.15 2011/05/18 19:36:36 dsl Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#ifdef _LIBC +#include "reentrant.h" +#include "atexit.h" +#endif + +void (*__cleanup)(void); + +/* + * Exit, flushing stdio buffers if necessary. + */ +void +exit(int status) +{ + +#ifdef _LIBC + __cxa_finalize(NULL); +#endif + if (__cleanup) + (*__cleanup)(); + _exit(status); +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/jrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/jrand48.c new file mode 100644 index 0000000..079dbd3 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/jrand48.c @@ -0,0 +1,39 @@ +/* $NetBSD: jrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $ */ + +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: jrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" + +#include + +#include "rand48.h" + +#ifdef __weak_alias +__weak_alias(jrand48,_jrand48) +#endif + +long +jrand48(unsigned short xseed[3]) +{ + + _DIAGASSERT(xseed != NULL); + + __dorand48(xseed); + return (int16_t)xseed[2] * 65536 + xseed[1]; +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/ldiv.c b/libc/upstream-netbsd/lib/libc/stdlib/ldiv.c new file mode 100644 index 0000000..507c831 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/ldiv.c @@ -0,0 +1,60 @@ +/* $NetBSD: ldiv.c,v 1.8 2012/06/25 22:32:45 abs Exp $ */ + +/* + * 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. 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) +#if 0 +static char sccsid[] = "@(#)ldiv.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: ldiv.c,v 1.8 2012/06/25 22:32:45 abs Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include /* ldiv_t */ + +ldiv_t +ldiv(long num, long 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/libc/upstream-netbsd/lib/libc/stdlib/lldiv.c b/libc/upstream-netbsd/lib/libc/stdlib/lldiv.c new file mode 100644 index 0000000..47104b3 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/lldiv.c @@ -0,0 +1,66 @@ +/* $NetBSD: lldiv.c,v 1.4 2012/06/25 22:32:45 abs Exp $ */ + +/* + * 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. 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) +#if 0 +static char sccsid[] = "from: @(#)ldiv.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: lldiv.c,v 1.4 2012/06/25 22:32:45 abs Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include /* lldiv_t */ + +#ifdef __weak_alias +__weak_alias(lldiv, _lldiv) +#endif + +/* LONGLONG */ +lldiv_t +lldiv(long long int num, long long int denom) +{ + lldiv_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/libc/upstream-netbsd/lib/libc/stdlib/lrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/lrand48.c new file mode 100644 index 0000000..11e6485 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/lrand48.c @@ -0,0 +1,33 @@ +/* $NetBSD: lrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $ */ + +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: lrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include "rand48.h" + +#ifdef __weak_alias +__weak_alias(lrand48,_lrand48) +#endif + +long +lrand48(void) +{ + __dorand48(__rand48_seed); + return __rand48_seed[2] * 32768 + (__rand48_seed[1] >> 1); +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/mrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/mrand48.c new file mode 100644 index 0000000..e51352a --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/mrand48.c @@ -0,0 +1,33 @@ +/* $NetBSD: mrand48.c,v 1.8 2013/10/22 08:08:51 matt Exp $ */ + +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: mrand48.c,v 1.8 2013/10/22 08:08:51 matt Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include "rand48.h" + +#ifdef __weak_alias +__weak_alias(mrand48,_mrand48) +#endif + +long +mrand48(void) +{ + __dorand48(__rand48_seed); + return (int16_t)__rand48_seed[2] * 65536 + __rand48_seed[1]; +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/nrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/nrand48.c new file mode 100644 index 0000000..98becca --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/nrand48.c @@ -0,0 +1,38 @@ +/* $NetBSD: nrand48.c,v 1.10 2013/10/22 08:08:51 matt Exp $ */ + +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: nrand48.c,v 1.10 2013/10/22 08:08:51 matt Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" + +#include + +#include "rand48.h" + +#ifdef __weak_alias +__weak_alias(nrand48,_nrand48) +#endif + +long +nrand48(unsigned short xseed[3]) +{ + _DIAGASSERT(xseed != NULL); + + __dorand48(xseed); + return xseed[2] * 32768 + (xseed[1] >> 1); +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/seed48.c b/libc/upstream-netbsd/lib/libc/stdlib/seed48.c new file mode 100644 index 0000000..36c0570 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/seed48.c @@ -0,0 +1,49 @@ +/* $NetBSD: seed48.c,v 1.8 2005/06/12 05:21:28 lukem Exp $ */ + +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: seed48.c,v 1.8 2005/06/12 05:21:28 lukem Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" + +#include + +#include "rand48.h" + +#ifdef __weak_alias +__weak_alias(seed48,_seed48) +#endif + +unsigned short * +seed48(unsigned short xseed[3]) +{ + static unsigned short sseed[3]; + + _DIAGASSERT(xseed != NULL); + + sseed[0] = __rand48_seed[0]; + sseed[1] = __rand48_seed[1]; + sseed[2] = __rand48_seed[2]; + __rand48_seed[0] = xseed[0]; + __rand48_seed[1] = xseed[1]; + __rand48_seed[2] = xseed[2]; + __rand48_mult[0] = RAND48_MULT_0; + __rand48_mult[1] = RAND48_MULT_1; + __rand48_mult[2] = RAND48_MULT_2; + __rand48_add = RAND48_ADD; + return sseed; +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/srand48.c b/libc/upstream-netbsd/lib/libc/stdlib/srand48.c new file mode 100644 index 0000000..a9673fe --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/srand48.c @@ -0,0 +1,38 @@ +/* $NetBSD: srand48.c,v 1.7 2005/06/12 05:21:28 lukem Exp $ */ + +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: srand48.c,v 1.7 2005/06/12 05:21:28 lukem Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include "rand48.h" + +#ifdef __weak_alias +__weak_alias(srand48,_srand48) +#endif + +void +srand48(long seed) +{ + __rand48_seed[0] = RAND48_SEED_0; + __rand48_seed[1] = (unsigned short) seed; + __rand48_seed[2] = (unsigned short) ((unsigned long)seed >> 16); + __rand48_mult[0] = RAND48_MULT_0; + __rand48_mult[1] = RAND48_MULT_1; + __rand48_mult[2] = RAND48_MULT_2; + __rand48_add = RAND48_ADD; +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/tdelete.c b/libc/upstream-netbsd/lib/libc/stdlib/tdelete.c new file mode 100644 index 0000000..84017dc --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/tdelete.c @@ -0,0 +1,67 @@ +/* $NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs 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 defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include +#define _SEARCH_PRIVATE +#include +#include + + +/* find a node with key "vkey" in tree "vrootp" */ +void * +tdelete(const void *vkey, void **vrootp, + int (*compar)(const void *, const void *)) +{ + node_t **rootp = (node_t **)vrootp; + node_t *p, *q, *r; + int cmp; + + _DIAGASSERT(vkey != NULL); + _DIAGASSERT(compar != NULL); + + 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; + } + } + if (p != *rootp) + free(*rootp); /* D4: Free node */ + *rootp = q; /* link parent to new node */ + return p; +} diff --git a/libc/upstream-netbsd/lib/libc/stdlib/tfind.c b/libc/upstream-netbsd/lib/libc/stdlib/tfind.c new file mode 100644 index 0000000..fd3f362 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/tfind.c @@ -0,0 +1,47 @@ +/* $NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs 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 defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include +#define _SEARCH_PRIVATE +#include +#include + +/* find a node by key "vkey" in tree "vrootp", or return 0 */ +void * +tfind(const void *vkey, void * const *vrootp, + int (*compar)(const void *, const void *)) +{ + node_t * const *rootp = (node_t * const*)vrootp; + + _DIAGASSERT(vkey != NULL); + _DIAGASSERT(compar != NULL); + + 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/libc/upstream-netbsd/lib/libc/stdlib/tsearch.c b/libc/upstream-netbsd/lib/libc/stdlib/tsearch.c new file mode 100644 index 0000000..af2fe9c --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/stdlib/tsearch.c @@ -0,0 +1,56 @@ +/* $NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs 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 defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include +#define _SEARCH_PRIVATE +#include +#include + +/* find or insert datum into search tree */ +void * +tsearch(const void *vkey, void **vrootp, + int (*compar)(const void *, const void *)) +{ + node_t *q; + node_t **rootp = (node_t **)vrootp; + + _DIAGASSERT(vkey != NULL); + _DIAGASSERT(compar != NULL); + + 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 */ + q->key = __UNCONST(vkey); /* initialize new node */ + q->llink = q->rlink = NULL; + } + return q; +} diff --git a/libc/upstream-netbsd/lib/libc/string/memccpy.c b/libc/upstream-netbsd/lib/libc/string/memccpy.c new file mode 100644 index 0000000..c086241 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/string/memccpy.c @@ -0,0 +1,61 @@ +/* $NetBSD: memccpy.c,v 1.13 2012/06/25 22:32:46 abs Exp $ */ + +/*- + * 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. 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) +#if 0 +static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: memccpy.c,v 1.13 2012/06/25 22:32:46 abs Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +void * +memccpy(void *t, const void *f, int c, size_t n) +{ + + _DIAGASSERT(t != 0); + _DIAGASSERT(f != 0); + + 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/libc/upstream-netbsd/lib/libc/string/strcasestr.c b/libc/upstream-netbsd/lib/libc/string/strcasestr.c new file mode 100644 index 0000000..f8a9444 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/string/strcasestr.c @@ -0,0 +1,69 @@ +/* $NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $ */ + +/*- + * 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. 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) +__RCSID("$NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include +#include +#include + +/* + * Find the first occurrence of find in s, ignore case. + */ +char * +strcasestr(const char *s, const char *find) +{ + char c, sc; + size_t len; + + _DIAGASSERT(s != NULL); + _DIAGASSERT(find != NULL); + + if ((c = *find++) != 0) { + c = tolower((unsigned char)c); + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (strncasecmp(s, find, len) != 0); + s--; + } + return __UNCONST(s); +} diff --git a/libc/upstream-netbsd/lib/libc/string/strcoll.c b/libc/upstream-netbsd/lib/libc/string/strcoll.c new file mode 100644 index 0000000..77a0942 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/string/strcoll.c @@ -0,0 +1,59 @@ +/* $NetBSD: strcoll.c,v 1.10 2012/06/25 22:32:46 abs Exp $ */ + +/*- + * 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. 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) +#if 0 +static char sccsid[] = "@(#)strcoll.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: strcoll.c,v 1.10 2012/06/25 22:32:46 abs Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Compare strings according to LC_COLLATE category of current locale. + */ +int +strcoll(const char *s1, const char *s2) +{ + + _DIAGASSERT(s1 != NULL); + _DIAGASSERT(s2 != NULL); + + /* LC_COLLATE is unimplemented, hence always "C" */ + return (strcmp(s1, s2)); +} diff --git a/libc/upstream-netbsd/lib/libc/string/strxfrm.c b/libc/upstream-netbsd/lib/libc/string/strxfrm.c new file mode 100644 index 0000000..42c2a24 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/string/strxfrm.c @@ -0,0 +1,70 @@ +/* $NetBSD: strxfrm.c,v 1.12 2012/06/25 22:32:46 abs Exp $ */ + +/*- + * 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. 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) +#if 0 +static char sccsid[] = "@(#)strxfrm.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: strxfrm.c,v 1.12 2012/06/25 22:32:46 abs Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Transform src, storing the result in dst, such that + * strcmp() on transformed strings returns what strcoll() + * on the original untransformed strings would return. + */ +size_t +strxfrm(char *dst, const char *src, size_t n) +{ + size_t srclen, copysize; + + _DIAGASSERT(src != NULL); + + /* + * Since locales are unimplemented, this is just a copy. + */ + srclen = strlen(src); + if (n != 0) { + _DIAGASSERT(dst != NULL); + copysize = srclen < n ? srclen : n - 1; + (void)memcpy(dst, src, copysize); + dst[copysize] = 0; + } + return (srclen); +} diff --git a/libc/upstream-netbsd/lib/libc/thread-stub/__isthreaded.c b/libc/upstream-netbsd/lib/libc/thread-stub/__isthreaded.c new file mode 100644 index 0000000..50c1b6f --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/thread-stub/__isthreaded.c @@ -0,0 +1,37 @@ +/* $NetBSD: __isthreaded.c,v 1.3 2009/12/01 01:33:25 explorer Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Michael Graff. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must 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 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: __isthreaded.c,v 1.3 2009/12/01 01:33:25 explorer Exp $"); +#endif /* LIBC_SCCS and not lint */ + +int __isthreaded = 0; diff --git a/libc/upstream-netbsd/lib/libc/unistd/killpg.c b/libc/upstream-netbsd/lib/libc/unistd/killpg.c new file mode 100644 index 0000000..ceac3f4 --- /dev/null +++ b/libc/upstream-netbsd/lib/libc/unistd/killpg.c @@ -0,0 +1,56 @@ +/* $NetBSD: killpg.c,v 1.8 2003/08/07 16:42:39 agc Exp $ */ + +/* + * 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. 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) +#if 0 +static char sccsid[] = "@(#)killpg.c 8.1 (Berkeley) 6/2/93"; +#else +__RCSID("$NetBSD: killpg.c,v 1.8 2003/08/07 16:42:39 agc Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include + +/* + * Backwards-compatible killpg(). + */ +int +killpg(pid_t pgid, int sig) +{ + if (pgid == 1) { + errno = ESRCH; + return (-1); + } + return (kill(-pgid, sig)); +} diff --git a/libc/upstream-netbsd/libc/gen/ftw.c b/libc/upstream-netbsd/libc/gen/ftw.c deleted file mode 100644 index a7f6bbd..0000000 --- a/libc/upstream-netbsd/libc/gen/ftw.c +++ /dev/null @@ -1,98 +0,0 @@ -/* $NetBSD: ftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $ */ - -/* From OpenBSD: ftw.c,v 1.2 2003/07/21 21:15:32 millert Exp */ - -/* - * Copyright (c) 2003 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. - */ -#include - -#ifndef lint -__RCSID("$NetBSD: ftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $"); -#endif - -#include -#include -#include -#include -#include -#include - -int -ftw(const char *path, int (*fn)(const char *, const struct stat *, int), - int nfds) -{ - /* LINTED */ - char * const paths[2] = { __UNCONST(path), NULL }; - FTSENT *cur; - FTS *ftsp; - int fnflag, error, sverrno; - - /* XXX - nfds is currently unused */ - if (nfds < 1 || nfds > OPEN_MAX) { - errno = EINVAL; - return (-1); - } - - ftsp = fts_open(paths, FTS_COMFOLLOW | FTS_NOCHDIR, NULL); - if (ftsp == NULL) - return (-1); - error = 0; - while ((cur = fts_read(ftsp)) != NULL) { - switch (cur->fts_info) { - case FTS_D: - fnflag = FTW_D; - break; - case FTS_DNR: - fnflag = FTW_DNR; - break; - case FTS_DP: - /* we only visit in preorder */ - continue; - case FTS_F: - case FTS_DEFAULT: - fnflag = FTW_F; - break; - case FTS_NS: - case FTS_NSOK: - case FTS_SLNONE: - fnflag = FTW_NS; - break; - case FTS_SL: - fnflag = FTW_SL; - break; - case FTS_DC: - errno = ELOOP; - /* FALLTHROUGH */ - default: - error = -1; - goto done; - } - error = fn(cur->fts_path, cur->fts_statp, fnflag); - if (error != 0) - break; - } -done: - sverrno = errno; - if (fts_close(ftsp) != 0 && error == 0) - error = -1; - else - errno = sverrno; - return (error); -} diff --git a/libc/upstream-netbsd/libc/gen/nftw.c b/libc/upstream-netbsd/libc/gen/nftw.c deleted file mode 100644 index 0e51342..0000000 --- a/libc/upstream-netbsd/libc/gen/nftw.c +++ /dev/null @@ -1,114 +0,0 @@ -/* $NetBSD */ - -/* From OpenBSD: nftw.c,v 1.2 2003/07/21 21:15:32 millert Exp */ - -/* - * Copyright (c) 2003 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. - */ - -#include - -#ifndef lint -__RCSID("$NetBSD: nftw.c,v 1.1 2005/12/30 23:07:32 agc Exp $"); -#endif - -#include -#include -#include -#include -#include -#include - -int -nftw(const char *path, int (*fn)(const char *, const struct stat *, int, - struct FTW *), int nfds, int ftwflags) -{ - /* LINTED */ - char * const paths[2] = { __UNCONST(path), NULL }; - struct FTW f; - FTSENT *cur; - FTS *ftsp; - int ftsflags, fnflag, error, postorder, sverrno; - - /* XXX - nfds is currently unused */ - if (nfds < 1 || nfds > OPEN_MAX) { - errno = EINVAL; - return (-1); - } - - ftsflags = FTS_COMFOLLOW; - if (!(ftwflags & FTW_CHDIR)) - ftsflags |= FTS_NOCHDIR; - if (ftwflags & FTW_MOUNT) - ftsflags |= FTS_XDEV; - if (ftwflags & FTW_PHYS) - ftsflags |= FTS_PHYSICAL; - postorder = (ftwflags & FTW_DEPTH) != 0; - ftsp = fts_open(paths, ftsflags, NULL); - if (ftsp == NULL) - return (-1); - error = 0; - while ((cur = fts_read(ftsp)) != NULL) { - switch (cur->fts_info) { - case FTS_D: - if (postorder) - continue; - fnflag = FTW_D; - break; - case FTS_DNR: - fnflag = FTW_DNR; - break; - case FTS_DP: - if (!postorder) - continue; - fnflag = FTW_DP; - break; - case FTS_F: - case FTS_DEFAULT: - fnflag = FTW_F; - break; - case FTS_NS: - case FTS_NSOK: - fnflag = FTW_NS; - break; - case FTS_SL: - fnflag = FTW_SL; - break; - case FTS_SLNONE: - fnflag = FTW_SLN; - break; - case FTS_DC: - errno = ELOOP; - /* FALLTHROUGH */ - default: - error = -1; - goto done; - } - f.base = cur->fts_pathlen - cur->fts_namelen; - f.level = cur->fts_level; - error = fn(cur->fts_path, cur->fts_statp, fnflag, &f); - if (error != 0) - break; - } -done: - sverrno = errno; - (void) fts_close(ftsp); - errno = sverrno; - return (error); -} diff --git a/libc/upstream-netbsd/libc/gen/nice.c b/libc/upstream-netbsd/libc/gen/nice.c deleted file mode 100644 index 19d6711..0000000 --- a/libc/upstream-netbsd/libc/gen/nice.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $NetBSD: nice.c,v 1.13 2011/05/01 02:49:54 christos Exp $ */ - -/* - * 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. 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) -#if 0 -static char sccsid[] = "@(#)nice.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: nice.c,v 1.13 2011/05/01 02:49:54 christos Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include -#include -#include -#include -#include - -#ifdef __weak_alias -__weak_alias(nice,_nice) -#endif - -/* - * Backwards compatible nice. - */ -int -nice(int incr) -{ - int prio; - - errno = 0; - prio = getpriority(PRIO_PROCESS, 0); - if (prio == -1 && errno) - return -1; - if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) { - if (errno == EACCES) - errno = EPERM; - return -1; - } - return getpriority(PRIO_PROCESS, 0); -} diff --git a/libc/upstream-netbsd/libc/gen/popen.c b/libc/upstream-netbsd/libc/gen/popen.c deleted file mode 100644 index 593e346..0000000 --- a/libc/upstream-netbsd/libc/gen/popen.c +++ /dev/null @@ -1,227 +0,0 @@ -/* $NetBSD: popen.c,v 1.32 2012/06/25 22:32:43 abs Exp $ */ - -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software written by Ken Arnold and - * published in UNIX Review, Vol. 6, No. 8. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce 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. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95"; -#else -__RCSID("$NetBSD: popen.c,v 1.32 2012/06/25 22:32:43 abs Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "env.h" -#include "reentrant.h" - -#ifdef __weak_alias -__weak_alias(popen,_popen) -__weak_alias(pclose,_pclose) -#endif - -static struct pid { - struct pid *next; - FILE *fp; -#ifdef _REENTRANT - int fd; -#endif - pid_t pid; -} *pidlist; - -#ifdef _REENTRANT -static rwlock_t pidlist_lock = RWLOCK_INITIALIZER; -#endif - -FILE * -popen(const char *command, const char *type) -{ - struct pid *cur, *old; - FILE *iop; - const char * volatile xtype = type; - int pdes[2], pid, serrno; - volatile int twoway; - int flags; - - _DIAGASSERT(command != NULL); - _DIAGASSERT(xtype != NULL); - - flags = strchr(xtype, 'e') ? O_CLOEXEC : 0; - if (strchr(xtype, '+')) { - int stype = flags ? (SOCK_STREAM | SOCK_CLOEXEC) : SOCK_STREAM; - twoway = 1; - xtype = "r+"; - if (socketpair(AF_LOCAL, stype, 0, pdes) < 0) - return NULL; - } else { - twoway = 0; - xtype = strrchr(xtype, 'r') ? "r" : "w"; - if (pipe2(pdes, flags) == -1) - return NULL; - } - - if ((cur = malloc(sizeof(struct pid))) == NULL) { - (void)close(pdes[0]); - (void)close(pdes[1]); - errno = ENOMEM; - return (NULL); - } - - (void)rwlock_rdlock(&pidlist_lock); - (void)__readlockenv(); - switch (pid = vfork()) { - case -1: /* Error. */ - serrno = errno; - (void)__unlockenv(); - (void)rwlock_unlock(&pidlist_lock); - free(cur); - (void)close(pdes[0]); - (void)close(pdes[1]); - errno = serrno; - return (NULL); - /* NOTREACHED */ - case 0: /* Child. */ - /* POSIX.2 B.3.2.2 "popen() shall ensure that any streams - from previous popen() calls that remain open in the - parent process are closed in the new child process. */ - for (old = pidlist; old; old = old->next) -#ifdef _REENTRANT - close(old->fd); /* don't allow a flush */ -#else - close(fileno(old->fp)); /* don't allow a flush */ -#endif - - if (*xtype == 'r') { - (void)close(pdes[0]); - if (pdes[1] != STDOUT_FILENO) { - (void)dup2(pdes[1], STDOUT_FILENO); - (void)close(pdes[1]); - } - if (twoway) - (void)dup2(STDOUT_FILENO, STDIN_FILENO); - } else { - (void)close(pdes[1]); - if (pdes[0] != STDIN_FILENO) { - (void)dup2(pdes[0], STDIN_FILENO); - (void)close(pdes[0]); - } - } - - execl(_PATH_BSHELL, "sh", "-c", command, NULL); - _exit(127); - /* NOTREACHED */ - } - (void)__unlockenv(); - - /* Parent; assume fdopen can't fail. */ - if (*xtype == 'r') { - iop = fdopen(pdes[0], xtype); -#ifdef _REENTRANT - cur->fd = pdes[0]; -#endif - (void)close(pdes[1]); - } else { - iop = fdopen(pdes[1], xtype); -#ifdef _REENTRANT - cur->fd = pdes[1]; -#endif - (void)close(pdes[0]); - } - - /* Link into list of file descriptors. */ - cur->fp = iop; - cur->pid = pid; - cur->next = pidlist; - pidlist = cur; - (void)rwlock_unlock(&pidlist_lock); - - return (iop); -} - -/* - * pclose -- - * Pclose returns -1 if stream is not associated with a `popened' command, - * if already `pclosed', or waitpid returns an error. - */ -int -pclose(FILE *iop) -{ - struct pid *cur, *last; - int pstat; - pid_t pid; - - _DIAGASSERT(iop != NULL); - - rwlock_wrlock(&pidlist_lock); - - /* Find the appropriate file pointer. */ - for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next) - if (cur->fp == iop) - break; - if (cur == NULL) { - (void)rwlock_unlock(&pidlist_lock); - return (-1); - } - - (void)fclose(iop); - - /* Remove the entry from the linked list. */ - if (last == NULL) - pidlist = cur->next; - else - last->next = cur->next; - - (void)rwlock_unlock(&pidlist_lock); - - do { - pid = waitpid(cur->pid, &pstat, 0); - } while (pid == -1 && errno == EINTR); - - free(cur); - - return (pid == -1 ? -1 : pstat); -} diff --git a/libc/upstream-netbsd/libc/gen/psignal.c b/libc/upstream-netbsd/libc/gen/psignal.c deleted file mode 100644 index 4472be6..0000000 --- a/libc/upstream-netbsd/libc/gen/psignal.c +++ /dev/null @@ -1,85 +0,0 @@ -/* $NetBSD: psignal.c,v 1.23 2012/03/13 21:13:36 christos Exp $ */ - -/* - * 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. 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) -#if 0 -static char sccsid[] = "@(#)psignal.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: psignal.c,v 1.23 2012/03/13 21:13:36 christos Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" - -#include -#include - -#include -#include -#include -#include - -#include "extern.h" - -#ifdef __weak_alias -__weak_alias(psignal,_psignal) -#endif - -void -psignal(int sig, const char *s) -{ - struct iovec *v; - struct iovec iov[4]; - char buf[NL_TEXTMAX]; - - v = iov; - if (s && *s) { - v->iov_base = __UNCONST(s); - v->iov_len = strlen(s); - v++; - v->iov_base = __UNCONST(": "); - v->iov_len = 2; - v++; - } - v->iov_base = __UNCONST(__strsignal((int)sig, buf, sizeof(buf))); - v->iov_len = strlen(v->iov_base); - v++; - v->iov_base = __UNCONST("\n"); - v->iov_len = 1; - (void)writev(STDERR_FILENO, iov, (int)((v - iov) + 1)); -} - -void -psiginfo(const siginfo_t *si, const char *s) -{ - psignal(si->si_signo, s); -} diff --git a/libc/upstream-netbsd/libc/gen/setjmperr.c b/libc/upstream-netbsd/libc/gen/setjmperr.c deleted file mode 100644 index 5b1432e..0000000 --- a/libc/upstream-netbsd/libc/gen/setjmperr.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $ */ - -/* - * Copyright (c) 1980, 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. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)setjmperr.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -/* - * This routine is called from longjmp() when an error occurs. - * Programs that wish to exit gracefully from this error may - * write their own versions. - * If this routine returns, the program is aborted. - */ - -#include -#include - -void -longjmperror(void) -{ -#define ERRMSG "longjmp botch.\n" - (void)write(STDERR_FILENO, ERRMSG, sizeof(ERRMSG) - 1); -} diff --git a/libc/upstream-netbsd/libc/gen/utime.c b/libc/upstream-netbsd/libc/gen/utime.c deleted file mode 100644 index d41aac7..0000000 --- a/libc/upstream-netbsd/libc/gen/utime.c +++ /dev/null @@ -1,65 +0,0 @@ -/* $NetBSD: utime.c,v 1.14 2012/06/25 22:32:44 abs Exp $ */ - -/*- - * 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. 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) -#if 0 -static char sccsid[] = "@(#)utime.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: utime.c,v 1.14 2012/06/25 22:32:44 abs Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include - -#include -#include -#include -#include - -int -utime(const char *path, const struct utimbuf *times) -{ - struct timeval tv[2], *tvp; - - _DIAGASSERT(path != NULL); - - if (times == (struct utimbuf *) NULL) - tvp = NULL; - else { - tv[0].tv_sec = times->actime; - tv[1].tv_sec = times->modtime; - tv[0].tv_usec = tv[1].tv_usec = 0; - tvp = tv; - } - return (utimes(path, tvp)); -} diff --git a/libc/upstream-netbsd/libc/include/isc/assertions.h b/libc/upstream-netbsd/libc/include/isc/assertions.h deleted file mode 100644 index 7db7361..0000000 --- a/libc/upstream-netbsd/libc/include/isc/assertions.h +++ /dev/null @@ -1,132 +0,0 @@ -/* $NetBSD: assertions.h,v 1.5 2009/04/12 17:07:16 christos Exp $ */ - -/* - * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") - * Copyright (C) 1997-2001 Internet Software Consortium. - * - * Permission to use, copy, modify, and/or 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 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. - */ - -/* - * Id: assertions.h,v 1.5 2008/11/14 02:36:51 marka Exp - */ - -#ifndef ASSERTIONS_H -#define ASSERTIONS_H 1 - -typedef enum { - assert_require, assert_ensure, assert_insist, assert_invariant -} assertion_type; - -typedef void (*assertion_failure_callback)(const char *, int, assertion_type, - const char *, int); - -/* coverity[+kill] */ -extern assertion_failure_callback __assertion_failed; -void set_assertion_failure_callback(assertion_failure_callback f); -const char *assertion_type_to_text(assertion_type type); - -#if defined(CHECK_ALL) || defined(__COVERITY__) -#define CHECK_REQUIRE 1 -#define CHECK_ENSURE 1 -#define CHECK_INSIST 1 -#define CHECK_INVARIANT 1 -#endif - -#if defined(CHECK_NONE) && !defined(__COVERITY__) -#define CHECK_REQUIRE 0 -#define CHECK_ENSURE 0 -#define CHECK_INSIST 0 -#define CHECK_INVARIANT 0 -#endif - -#ifdef _DIAGNOSTIC -#ifndef CHECK_REQUIRE -#define CHECK_REQUIRE 1 -#endif - -#ifndef CHECK_ENSURE -#define CHECK_ENSURE 1 -#endif - -#ifndef CHECK_INSIST -#define CHECK_INSIST 1 -#endif - -#ifndef CHECK_INVARIANT -#define CHECK_INVARIANT 1 -#endif -#endif /* _DIAGNOSTIC */ - -#if CHECK_REQUIRE != 0 -#define REQUIRE(cond) \ - ((void) ((cond) || \ - ((__assertion_failed)(__FILE__, __LINE__, assert_require, \ - #cond, 0), 0))) -#define REQUIRE_ERR(cond) \ - ((void) ((cond) || \ - ((__assertion_failed)(__FILE__, __LINE__, assert_require, \ - #cond, 1), 0))) -#else -#define REQUIRE(cond) ((void) (cond)) -#define REQUIRE_ERR(cond) ((void) (cond)) -#endif /* CHECK_REQUIRE */ - -#if CHECK_ENSURE != 0 -#define ENSURE(cond) \ - ((void) ((cond) || \ - ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \ - #cond, 0), 0))) -#define ENSURE_ERR(cond) \ - ((void) ((cond) || \ - ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \ - #cond, 1), 0))) -#else -#define ENSURE(cond) ((void) (cond)) -#define ENSURE_ERR(cond) ((void) (cond)) -#endif /* CHECK_ENSURE */ - -#if CHECK_INSIST != 0 -#define INSIST(cond) \ - ((void) ((cond) || \ - ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \ - #cond, 0), 0))) -#define INSIST_ERR(cond) \ - ((void) ((cond) || \ - ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \ - #cond, 1), 0))) -#else -#if !defined(__lint__) -#define INSIST(cond) ((void) (cond)) -#define INSIST_ERR(cond) ((void) (cond)) -#else /* !__lint__ */ -#define INSIST(cond) -#define INSIST_ERR(cond) -#endif /* !__lint__ */ -#endif /* CHECK_INSIST */ - -#if CHECK_INVARIANT != 0 -#define INVARIANT(cond) \ - ((void) ((cond) || \ - ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \ - #cond, 0), 0))) -#define INVARIANT_ERR(cond) \ - ((void) ((cond) || \ - ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \ - #cond, 1), 0))) -#else -#define INVARIANT(cond) ((void) (cond)) -#define INVARIANT_ERR(cond) ((void) (cond)) -#endif /* CHECK_INVARIANT */ -#endif /* ASSERTIONS_H */ -/*! \file */ diff --git a/libc/upstream-netbsd/libc/include/isc/dst.h b/libc/upstream-netbsd/libc/include/isc/dst.h deleted file mode 100644 index 5537e3d..0000000 --- a/libc/upstream-netbsd/libc/include/isc/dst.h +++ /dev/null @@ -1,170 +0,0 @@ -/* $NetBSD: dst.h,v 1.1.1.4 2009/04/12 16:35:44 christos Exp $ */ - -#ifndef DST_H -#define DST_H - -#ifndef HAS_DST_KEY -typedef struct dst_key { - char *dk_key_name; /*%< name of the key */ - int dk_key_size; /*%< this is the size of the key in bits */ - int dk_proto; /*%< what protocols this key can be used for */ - int dk_alg; /*%< algorithm number from key record */ - u_int32_t dk_flags; /*%< and the flags of the public key */ - u_int16_t dk_id; /*%< identifier of the key */ -} DST_KEY; -#endif /* HAS_DST_KEY */ -/* - * do not taint namespace - */ -#define dst_bsafe_init __dst_bsafe_init -#define dst_buffer_to_key __dst_buffer_to_key -#define dst_check_algorithm __dst_check_algorithm -#define dst_compare_keys __dst_compare_keys -#define dst_cylink_init __dst_cylink_init -#define dst_dnskey_to_key __dst_dnskey_to_key -#define dst_eay_dss_init __dst_eay_dss_init -#define dst_free_key __dst_free_key -#define dst_generate_key __dst_generate_key -#define dst_hmac_md5_init __dst_hmac_md5_init -#define dst_init __dst_init -#define dst_key_to_buffer __dst_key_to_buffer -#define dst_key_to_dnskey __dst_key_to_dnskey -#define dst_read_key __dst_read_key -#define dst_rsaref_init __dst_rsaref_init -#define dst_s_build_filename __dst_s_build_filename -#define dst_s_calculate_bits __dst_s_calculate_bits -#define dst_s_conv_bignum_b64_to_u8 __dst_s_conv_bignum_b64_to_u8 -#define dst_s_conv_bignum_u8_to_b64 __dst_s_conv_bignum_u8_to_b64 -#define dst_s_dns_key_id __dst_s_dns_key_id -#define dst_s_dump __dst_s_dump -#define dst_s_filename_length __dst_s_filename_length -#define dst_s_fopen __dst_s_fopen -#define dst_s_get_int16 __dst_s_get_int16 -#define dst_s_get_int32 __dst_s_get_int32 -#define dst_s_id_calc __dst_s_id_calc -#define dst_s_put_int16 __dst_s_put_int16 -#define dst_s_put_int32 __dst_s_put_int32 -#define dst_s_quick_random __dst_s_quick_random -#define dst_s_quick_random_set __dst_s_quick_random_set -#define dst_s_random __dst_s_random -#define dst_s_semi_random __dst_s_semi_random -#define dst_s_verify_str __dst_s_verify_str -#define dst_sig_size __dst_sig_size -#define dst_sign_data __dst_sign_data -#define dst_verify_data __dst_verify_data -#define dst_write_key __dst_write_key - -/* - * DST Crypto API defintions - */ -void dst_init(void); -int dst_check_algorithm(const int); - - -int dst_sign_data(const int, /*!< specifies INIT/UPDATE/FINAL/ALL */ - DST_KEY *, /*!< the key to use */ - void **, /*!< pointer to state structure */ - const u_char *, /*!< data to be signed */ - const int, /*!< length of input data */ - u_char *, /*!< buffer to write signature to */ - const int); /*!< size of output buffer */ -int dst_verify_data(const int, /*!< specifies INIT/UPDATE/FINAL/ALL */ - DST_KEY *, /*!< the key to use */ - void **, /*!< pointer to state structure */ - const u_char *, /*!< data to be verified */ - const int, /*!< length of input data */ - const u_char *, /*!< buffer containing signature */ - const int); /*!< length of signature */ -DST_KEY *dst_read_key(const char *, /*!< name of key */ - const u_int16_t, /*!< key tag identifier */ - const int, /*!< key algorithm */ - const int); /*!< Private/PublicKey wanted */ -int dst_write_key(const DST_KEY *, /*!< key to write out */ - const int); /*!< Public/Private */ -DST_KEY *dst_dnskey_to_key(const char *, /*!< KEY record name */ - const u_char *, /*!< KEY RDATA */ - const int); /*!< size of input buffer */ -int dst_key_to_dnskey(const DST_KEY *, /*!< key to translate */ - u_char *, /*!< output buffer */ - const int); /*!< size of out_storage */ -DST_KEY *dst_buffer_to_key(const char *, /*!< name of the key */ - const int, /*!< algorithm */ - const int, /*!< dns flags */ - const int, /*!< dns protocol */ - const u_char *, /*!< key in dns wire fmt */ - const int); /*!< size of key */ -int dst_key_to_buffer(DST_KEY *, u_char *, int); - -DST_KEY *dst_generate_key(const char *, /*!< name of new key */ - const int, /*!< key algorithm to generate */ - const int, /*!< size of new key */ - const int, /*!< alg dependent parameter */ - const int, /*!< key DNS flags */ - const int); /*!< key DNS protocol */ -DST_KEY *dst_free_key(DST_KEY *); -int dst_compare_keys(const DST_KEY *, const DST_KEY *); - -int dst_sig_size(DST_KEY *); - - -/* support for dns key tags/ids */ -u_int16_t dst_s_dns_key_id(const u_char *, const int); -u_int16_t dst_s_id_calc(const u_char *, const int); - -/* Used by callers as well as by the library. */ -#define RAW_KEY_SIZE 8192 /*%< large enough to store any key */ -/* DST_API control flags */ -/* These are used used in functions dst_sign_data and dst_verify_data */ -#define SIG_MODE_INIT 1 /*%< initialize digest */ -#define SIG_MODE_UPDATE 2 /*%< add data to digest */ -#define SIG_MODE_FINAL 4 /*%< generate/verify signature */ -#define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL) - -/* Flags for dst_read_private_key() */ -#define DST_FORCE_READ 0x1000000 -#define DST_CAN_SIGN 0x010F -#define DST_NO_AUTHEN 0x8000 -#define DST_EXTEND_FLAG 0x1000 -#define DST_STANDARD 0 -#define DST_PRIVATE 0x2000000 -#define DST_PUBLIC 0x4000000 -#define DST_RAND_SEMI 1 -#define DST_RAND_STD 2 -#define DST_RAND_KEY 3 -#define DST_RAND_DSS 4 - - -/* DST algorithm codes */ -#define KEY_RSA 1 -#define KEY_DH 2 -#define KEY_DSA 3 -#define KEY_PRIVATE 254 -#define KEY_EXPAND 255 -#define KEY_HMAC_MD5 157 -#define KEY_HMAC_SHA1 158 -#define UNKNOWN_KEYALG 0 -#define DST_MAX_ALGS KEY_HMAC_SHA1 - -/* DST constants to locations in KEY record changes in new KEY record */ -#define DST_FLAGS_SIZE 2 -#define DST_KEY_PROT 2 -#define DST_KEY_ALG 3 -#define DST_EXT_FLAG 4 -#define DST_KEY_START 4 - -#ifndef SIGN_F_NOKEY -#define SIGN_F_NOKEY 0xC000 -#endif - -/* error codes from dst routines */ -#define SIGN_INIT_FAILURE (-23) -#define SIGN_UPDATE_FAILURE (-24) -#define SIGN_FINAL_FAILURE (-25) -#define VERIFY_INIT_FAILURE (-26) -#define VERIFY_UPDATE_FAILURE (-27) -#define VERIFY_FINAL_FAILURE (-28) -#define MISSING_KEY_OR_SIGNATURE (-30) -#define UNSUPPORTED_KEYALG (-31) - -#endif /* DST_H */ -/*! \file */ diff --git a/libc/upstream-netbsd/libc/include/isc/eventlib.h b/libc/upstream-netbsd/libc/include/isc/eventlib.h deleted file mode 100644 index 4e9cc2e..0000000 --- a/libc/upstream-netbsd/libc/include/isc/eventlib.h +++ /dev/null @@ -1,206 +0,0 @@ -/* $NetBSD: eventlib.h,v 1.3 2009/04/12 17:07:16 christos Exp $ */ - -/* - * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") - * Copyright (C) 1995-1999, 2001, 2003 Internet Software Consortium. - * - * Permission to use, copy, modify, and/or 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 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. - */ - -/* eventlib.h - exported interfaces for eventlib - * vix 09sep95 [initial] - * - * Id: eventlib.h,v 1.7 2008/11/14 02:36:51 marka Exp - */ - -#ifndef _EVENTLIB_H -#define _EVENTLIB_H - -#include -#include -#include -#include - -#ifndef __P -# define __EVENTLIB_P_DEFINED -# ifdef __STDC__ -# define __P(x) x -# else -# define __P(x) () -# endif -#endif - -/* In the absence of branded types... */ -typedef struct { void *opaque; } evConnID; -typedef struct { void *opaque; } evFileID; -typedef struct { void *opaque; } evStreamID; -typedef struct { void *opaque; } evTimerID; -typedef struct { void *opaque; } evWaitID; -typedef struct { void *opaque; } evContext; -typedef struct { void *opaque; } evEvent; - -#define evInitID(id) ((id)->opaque = NULL) -#define evTestID(id) ((id).opaque != NULL) - -typedef void (*evConnFunc)__P((evContext, void *, int, const void *, int, - const void *, int)); -typedef void (*evFileFunc)__P((evContext, void *, int, int)); -typedef void (*evStreamFunc)__P((evContext, void *, int, int)); -typedef void (*evTimerFunc)__P((evContext, void *, - struct timespec, struct timespec)); -typedef void (*evWaitFunc)__P((evContext, void *, const void *)); - -typedef struct { unsigned char mask[256/8]; } evByteMask; -#define EV_BYTEMASK_BYTE(b) ((b) / 8) -#define EV_BYTEMASK_MASK(b) (1 << ((b) % 8)) -#define EV_BYTEMASK_SET(bm, b) \ - ((bm).mask[EV_BYTEMASK_BYTE(b)] |= EV_BYTEMASK_MASK(b)) -#define EV_BYTEMASK_CLR(bm, b) \ - ((bm).mask[EV_BYTEMASK_BYTE(b)] &= ~EV_BYTEMASK_MASK(b)) -#define EV_BYTEMASK_TST(bm, b) \ - ((bm).mask[EV_BYTEMASK_BYTE(b)] & EV_BYTEMASK_MASK(b)) - -#define EV_POLL 1 -#define EV_WAIT 2 -#define EV_NULL 4 - -#define EV_READ 1 -#define EV_WRITE 2 -#define EV_EXCEPT 4 - -#define EV_WASNONBLOCKING 8 /* Internal library use. */ - -/* eventlib.c */ -#define evCreate __evCreate -#define evSetDebug __evSetDebug -#define evDestroy __evDestroy -#define evGetNext __evGetNext -#define evDispatch __evDispatch -#define evDrop __evDrop -#define evMainLoop __evMainLoop -#define evHighestFD __evHighestFD -#define evGetOption __evGetOption -#define evSetOption __evSetOption - -int evCreate __P((evContext *)); -void evSetDebug __P((evContext, int, FILE *)); -int evDestroy __P((evContext)); -int evGetNext __P((evContext, evEvent *, int)); -int evDispatch __P((evContext, evEvent)); -void evDrop __P((evContext, evEvent)); -int evMainLoop __P((evContext)); -int evHighestFD __P((evContext)); -int evGetOption __P((evContext *, const char *, int *)); -int evSetOption __P((evContext *, const char *, int)); - -/* ev_connects.c */ -#define evListen __evListen -#define evConnect __evConnect -#define evCancelConn __evCancelConn -#define evHold __evHold -#define evUnhold __evUnhold -#define evTryAccept __evTryAccept - -int evListen __P((evContext, int, int, evConnFunc, void *, evConnID *)); -int evConnect __P((evContext, int, const void *, int, - evConnFunc, void *, evConnID *)); -int evCancelConn __P((evContext, evConnID)); -int evHold __P((evContext, evConnID)); -int evUnhold __P((evContext, evConnID)); -int evTryAccept __P((evContext, evConnID, int *)); - -/* ev_files.c */ -#define evSelectFD __evSelectFD -#define evDeselectFD __evDeselectFD - -int evSelectFD __P((evContext, int, int, evFileFunc, void *, evFileID *)); -int evDeselectFD __P((evContext, evFileID)); - -/* ev_streams.c */ -#define evConsIovec __evConsIovec -#define evWrite __evWrite -#define evRead __evRead -#define evTimeRW __evTimeRW -#define evUntimeRW __evUntimeRW -#define evCancelRW __evCancelRW - -struct iovec evConsIovec __P((void *, size_t)); -int evWrite __P((evContext, int, const struct iovec *, int, - evStreamFunc func, void *, evStreamID *)); -int evRead __P((evContext, int, const struct iovec *, int, - evStreamFunc func, void *, evStreamID *)); -int evTimeRW __P((evContext, evStreamID, evTimerID timer)); -int evUntimeRW __P((evContext, evStreamID)); -int evCancelRW __P((evContext, evStreamID)); - -/* ev_timers.c */ -#define evConsTime __evConsTime -#define evAddTime __evAddTime -#define evSubTime __evSubTime -#define evCmpTime __evCmpTime -#define evTimeSpec __evTimeSpec -#define evTimeVal __evTimeVal - -#define evNowTime __evNowTime -#define evUTCTime __evUTCTime -#define evLastEventTime __evLastEventTime -#define evSetTimer __evSetTimer -#define evClearTimer __evClearTimer -#define evConfigTimer __evConfigTimer -#define evResetTimer __evResetTimer -#define evSetIdleTimer __evSetIdleTimer -#define evClearIdleTimer __evClearIdleTimer -#define evResetIdleTimer __evResetIdleTimer -#define evTouchIdleTimer __evTouchIdleTimer - -struct timespec evConsTime __P((time_t sec, long nsec)); -struct timespec evAddTime __P((struct timespec, struct timespec)); -struct timespec evSubTime __P((struct timespec, struct timespec)); -struct timespec evNowTime __P((void)); -struct timespec evUTCTime __P((void)); -struct timespec evLastEventTime __P((evContext)); -struct timespec evTimeSpec __P((struct timeval)); -struct timeval evTimeVal __P((struct timespec)); -int evCmpTime __P((struct timespec, struct timespec)); -int evSetTimer __P((evContext, evTimerFunc, void *, struct timespec, - struct timespec, evTimerID *)); -int evClearTimer __P((evContext, evTimerID)); -int evConfigTimer __P((evContext, evTimerID, const char *param, - int value)); -int evResetTimer __P((evContext, evTimerID, evTimerFunc, void *, - struct timespec, struct timespec)); -int evSetIdleTimer __P((evContext, evTimerFunc, void *, struct timespec, - evTimerID *)); -int evClearIdleTimer __P((evContext, evTimerID)); -int evResetIdleTimer __P((evContext, evTimerID, evTimerFunc, void *, - struct timespec)); -int evTouchIdleTimer __P((evContext, evTimerID)); - -/* ev_waits.c */ -#define evWaitFor __evWaitFor -#define evDo __evDo -#define evUnwait __evUnwait -#define evDefer __evDefer - -int evWaitFor __P((evContext, const void *, evWaitFunc, void *, evWaitID *)); -int evDo __P((evContext, const void *)); -int evUnwait __P((evContext, evWaitID)); -int evDefer __P((evContext, evWaitFunc, void *)); - -#ifdef __EVENTLIB_P_DEFINED -# undef __P -#endif - -#endif /*_EVENTLIB_H*/ - -/*! \file */ diff --git a/libc/upstream-netbsd/libc/include/isc/heap.h b/libc/upstream-netbsd/libc/include/isc/heap.h deleted file mode 100644 index 30cec98..0000000 --- a/libc/upstream-netbsd/libc/include/isc/heap.h +++ /dev/null @@ -1,51 +0,0 @@ -/* $NetBSD: heap.h,v 1.1.1.4 2009/04/12 16:35:44 christos Exp $ */ - -/* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1997,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 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. - */ - -typedef int (*heap_higher_priority_func)(void *, void *); -typedef void (*heap_index_func)(void *, int); -typedef void (*heap_for_each_func)(void *, void *); - -typedef struct heap_context { - int array_size; - int array_size_increment; - int heap_size; - void **heap; - heap_higher_priority_func higher_priority; - heap_index_func index; -} *heap_context; - -#define heap_new __heap_new -#define heap_free __heap_free -#define heap_insert __heap_insert -#define heap_delete __heap_delete -#define heap_increased __heap_increased -#define heap_decreased __heap_decreased -#define heap_element __heap_element -#define heap_for_each __heap_for_each - -heap_context heap_new(heap_higher_priority_func, heap_index_func, int); -int heap_free(heap_context); -int heap_insert(heap_context, void *); -int heap_delete(heap_context, int); -int heap_increased(heap_context, int); -int heap_decreased(heap_context, int); -void * heap_element(heap_context, int); -int heap_for_each(heap_context, heap_for_each_func, void *); - -/*! \file */ diff --git a/libc/upstream-netbsd/libc/include/isc/list.h b/libc/upstream-netbsd/libc/include/isc/list.h deleted file mode 100644 index 46f2e79..0000000 --- a/libc/upstream-netbsd/libc/include/isc/list.h +++ /dev/null @@ -1,120 +0,0 @@ -/* $NetBSD: list.h,v 1.5 2009/04/12 17:07:16 christos Exp $ */ - -/* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1997,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 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. - */ - -#ifndef LIST_H -#define LIST_H 1 -#include - -#define LIST(type) struct { type *head, *tail; } -#define INIT_LIST(list) \ - do { (list).head = NULL; (list).tail = NULL; } while (/*CONSTCOND*/0) - -#define LINK(type) struct { type *prev, *next; } -#define INIT_LINK_TYPE(elt, link, type) \ - do { \ - (elt)->link.prev = (type *)(-1); \ - (elt)->link.next = (type *)(-1); \ - } while (/*CONSTCOND*/0) -#define INIT_LINK(elt, link) \ - INIT_LINK_TYPE(elt, link, void) -#define LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1) && \ - (void *)((elt)->link.next) != (void *)(-1)) - -#define HEAD(list) ((list).head) -#define TAIL(list) ((list).tail) -#define EMPTY(list) ((list).head == NULL) - -#define PREPEND(list, elt, link) \ - do { \ - INSIST(!LINKED(elt, link));\ - if ((list).head != NULL) \ - (list).head->link.prev = (elt); \ - else \ - (list).tail = (elt); \ - (elt)->link.prev = NULL; \ - (elt)->link.next = (list).head; \ - (list).head = (elt); \ - } while (/*CONSTCOND*/0) - -#define APPEND(list, elt, link) \ - do { \ - INSIST(!LINKED(elt, link));\ - if ((list).tail != NULL) \ - (list).tail->link.next = (elt); \ - else \ - (list).head = (elt); \ - (elt)->link.prev = (list).tail; \ - (elt)->link.next = NULL; \ - (list).tail = (elt); \ - } while (/*CONSTCOND*/0) - -#define UNLINK_TYPE(list, elt, link, type) \ - do { \ - INSIST(LINKED(elt, link));\ - if ((elt)->link.next != NULL) \ - (elt)->link.next->link.prev = (elt)->link.prev; \ - else { \ - INSIST((list).tail == (elt)); \ - (list).tail = (elt)->link.prev; \ - } \ - if ((elt)->link.prev != NULL) \ - (elt)->link.prev->link.next = (elt)->link.next; \ - else { \ - INSIST((list).head == (elt)); \ - (list).head = (elt)->link.next; \ - } \ - INIT_LINK_TYPE(elt, link, type); \ - } while (/*CONSTCOND*/0) -#define UNLINK(list, elt, link) \ - UNLINK_TYPE(list, elt, link, void) - -#define PREV(elt, link) ((elt)->link.prev) -#define NEXT(elt, link) ((elt)->link.next) - -#define INSERT_BEFORE(list, before, elt, link) \ - do { \ - INSIST(!LINKED(elt, link));\ - if ((before)->link.prev == NULL) \ - PREPEND(list, elt, link); \ - else { \ - (elt)->link.prev = (before)->link.prev; \ - (before)->link.prev = (elt); \ - (elt)->link.prev->link.next = (elt); \ - (elt)->link.next = (before); \ - } \ - } while (/*CONSTCOND*/0) - -#define INSERT_AFTER(list, after, elt, link) \ - do { \ - INSIST(!LINKED(elt, link));\ - if ((after)->link.next == NULL) \ - APPEND(list, elt, link); \ - else { \ - (elt)->link.next = (after)->link.next; \ - (after)->link.next = (elt); \ - (elt)->link.next->link.prev = (elt); \ - (elt)->link.prev = (after); \ - } \ - } while (/*CONSTCOND*/0) - -#define ENQUEUE(list, elt, link) APPEND(list, elt, link) -#define DEQUEUE(list, elt, link) UNLINK(list, elt, link) - -#endif /* LIST_H */ -/*! \file */ diff --git a/libc/upstream-netbsd/libc/include/isc/memcluster.h b/libc/upstream-netbsd/libc/include/isc/memcluster.h deleted file mode 100644 index 3c1b489..0000000 --- a/libc/upstream-netbsd/libc/include/isc/memcluster.h +++ /dev/null @@ -1,52 +0,0 @@ -/* $NetBSD: memcluster.h,v 1.1.1.4 2009/04/12 16:35:44 christos Exp $ */ - -/* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1997,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 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. - */ - -#ifndef MEMCLUSTER_H -#define MEMCLUSTER_H - -#include - -#define meminit __meminit -#ifdef MEMCLUSTER_DEBUG -#define memget(s) __memget_debug(s, __FILE__, __LINE__) -#define memput(p, s) __memput_debug(p, s, __FILE__, __LINE__) -#else /*MEMCLUSTER_DEBUG*/ -#ifdef MEMCLUSTER_RECORD -#define memget(s) __memget_record(s, __FILE__, __LINE__) -#define memput(p, s) __memput_record(p, s, __FILE__, __LINE__) -#else /*MEMCLUSTER_RECORD*/ -#define memget __memget -#define memput __memput -#endif /*MEMCLUSTER_RECORD*/ -#endif /*MEMCLUSTER_DEBUG*/ -#define memstats __memstats -#define memactive __memactive - -int meminit(size_t, size_t); -void * __memget(size_t); -void __memput(void *, size_t); -void * __memget_debug(size_t, const char *, int); -void __memput_debug(void *, size_t, const char *, int); -void * __memget_record(size_t, const char *, int); -void __memput_record(void *, size_t, const char *, int); -void memstats(FILE *); -int memactive(void); - -#endif /* MEMCLUSTER_H */ -/*! \file */ diff --git a/libc/upstream-netbsd/libc/inet/inet_ntoa.c b/libc/upstream-netbsd/libc/inet/inet_ntoa.c deleted file mode 100644 index 6ed023b..0000000 --- a/libc/upstream-netbsd/libc/inet/inet_ntoa.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $ */ - -/* - * 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. 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) -#if 0 -static char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include -#include -#include -#include -#include -#include - -#ifdef __weak_alias -__weak_alias(inet_ntoa,_inet_ntoa) -#endif - -/* - * Convert network-format internet address - * to base 256 d.d.d.d representation. - */ -/*const*/ char * -inet_ntoa(struct in_addr in) { - static char ret[18]; - - strlcpy(ret, "[inet_ntoa error]", sizeof(ret)); - (void) inet_ntop(AF_INET, &in, ret, (socklen_t)sizeof ret); - return ret; -} diff --git a/libc/upstream-netbsd/libc/inet/inet_ntop.c b/libc/upstream-netbsd/libc/inet/inet_ntop.c deleted file mode 100644 index 00c55a8..0000000 --- a/libc/upstream-netbsd/libc/inet/inet_ntop.c +++ /dev/null @@ -1,232 +0,0 @@ -/* $NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $ */ - -/* - * 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 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. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp"; -#else -__RCSID("$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "port_before.h" - -#include "namespace.h" -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "port_after.h" - -#ifdef __weak_alias -__weak_alias(inet_ntop,_inet_ntop) -#endif - -/*% - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size); -static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size); - -/* char * - * inet_ntop(af, src, dst, size) - * convert a network format address to presentation format. - * return: - * pointer to presentation format address (`dst'), or NULL (see errno). - * author: - * Paul Vixie, 1996. - */ -const char * -inet_ntop(int af, const void *src, char *dst, socklen_t size) -{ - - _DIAGASSERT(src != NULL); - _DIAGASSERT(dst != NULL); - - switch (af) { - case AF_INET: - return (inet_ntop4(src, dst, size)); - case AF_INET6: - return (inet_ntop6(src, dst, size)); - default: - errno = EAFNOSUPPORT; - return (NULL); - } - /* NOTREACHED */ -} - -/* const char * - * inet_ntop4(src, dst, size) - * format an IPv4 address, more or less like inet_ntoa() - * return: - * `dst' (as a const) - * notes: - * (1) uses no statics - * (2) takes a u_char* not an in_addr as input - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop4(const u_char *src, char *dst, socklen_t size) -{ - char tmp[sizeof "255.255.255.255"]; - int l; - - _DIAGASSERT(src != NULL); - _DIAGASSERT(dst != NULL); - - l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u", - src[0], src[1], src[2], src[3]); - if (l <= 0 || (socklen_t) l >= size) { - errno = ENOSPC; - return (NULL); - } - strlcpy(dst, tmp, size); - return (dst); -} - -/* const char * - * inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop6(const u_char *src, char *dst, socklen_t size) -{ - /* - * Note that int32_t and int16_t need only be "at least" large enough - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; - char *tp, *ep; - struct { int base, len; } best, cur; - u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; - int i; - int advance; - - _DIAGASSERT(src != NULL); - _DIAGASSERT(dst != NULL); - - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset(words, '\0', sizeof words); - for (i = 0; i < NS_IN6ADDRSZ; i++) - words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); - best.base = -1; - best.len = 0; - cur.base = -1; - cur.len = 0; - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { - if (words[i] == 0) { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } else { - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - } - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - } - if (best.base != -1 && best.len < 2) - best.base = -1; - - /* - * Format the result. - */ - tp = tmp; - ep = tmp + sizeof(tmp); - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { - /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && - i < (best.base + best.len)) { - if (i == best.base) - *tp++ = ':'; - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) { - if (tp + 1 >= ep) - return (NULL); - *tp++ = ':'; - } - /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && - (best.len == 6 || - (best.len == 7 && words[7] != 0x0001) || - (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp))) - return (NULL); - tp += strlen(tp); - break; - } - advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]); - if (advance <= 0 || advance >= ep - tp) - return (NULL); - tp += advance; - } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == - (NS_IN6ADDRSZ / NS_INT16SZ)) { - if (tp + 1 >= ep) - return (NULL); - *tp++ = ':'; - } - if (tp + 1 >= ep) - return (NULL); - *tp++ = '\0'; - - /* - * Check for overflow, copy, and we're done. - */ - if ((size_t)(tp - tmp) > size) { - errno = ENOSPC; - return (NULL); - } - strlcpy(dst, tmp, size); - return (dst); -} - -/*! \file */ diff --git a/libc/upstream-netbsd/libc/inet/inet_pton.c b/libc/upstream-netbsd/libc/inet/inet_pton.c deleted file mode 100644 index c1e9a69..0000000 --- a/libc/upstream-netbsd/libc/inet/inet_pton.c +++ /dev/null @@ -1,310 +0,0 @@ -/* $NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $ */ - -/* - * 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 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. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static const char rcsid[] = "Id: inet_pton.c,v 1.5 2005/07/28 06:51:47 marka Exp"; -#else -__RCSID("$NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "port_before.h" - -#include "namespace.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "port_after.h" - -#ifdef __weak_alias -__weak_alias(inet_pton,_inet_pton) -#endif - -/*% - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -static int inet_pton4(const char *src, u_char *dst, int pton); -static int inet_pton6(const char *src, u_char *dst); - -/* int - * inet_pton(af, src, dst) - * convert from presentation format (which usually means ASCII printable) - * to network format (which is usually some kind of binary format). - * return: - * 1 if the address was valid for the specified address family - * 0 if the address wasn't valid (`dst' is untouched in this case) - * -1 if some other error occurred (`dst' is untouched in this case, too) - * author: - * Paul Vixie, 1996. - */ -int -inet_pton(int af, const char *src, void *dst) -{ - - _DIAGASSERT(src != NULL); - _DIAGASSERT(dst != NULL); - - switch (af) { - case AF_INET: - return (inet_pton4(src, dst, 1)); - case AF_INET6: - return (inet_pton6(src, dst)); - default: - errno = EAFNOSUPPORT; - return (-1); - } - /* NOTREACHED */ -} - -/* int - * inet_pton4(src, dst, pton) - * when last arg is 0: inet_aton(). with hexadecimal, octal and shorthand. - * when last arg is 1: inet_pton(). decimal dotted-quad only. - * return: - * 1 if `src' is a valid input, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton4(const char *src, u_char *dst, int pton) -{ - u_int32_t val; - u_int digit, base; - ptrdiff_t n; - unsigned char c; - u_int parts[4]; - u_int *pp = parts; - - _DIAGASSERT(src != NULL); - _DIAGASSERT(dst != NULL); - - c = *src; - for (;;) { - /* - * Collect number up to ``.''. - * Values are specified as for C: - * 0x=hex, 0=octal, isdigit=decimal. - */ - if (!isdigit(c)) - return (0); - val = 0; base = 10; - if (c == '0') { - c = *++src; - if (c == 'x' || c == 'X') - base = 16, c = *++src; - else if (isdigit(c) && c != '9') - base = 8; - } - /* inet_pton() takes decimal only */ - if (pton && base != 10) - return (0); - for (;;) { - if (isdigit(c)) { - digit = c - '0'; - if (digit >= base) - break; - val = (val * base) + digit; - c = *++src; - } else if (base == 16 && isxdigit(c)) { - digit = c + 10 - (islower(c) ? 'a' : 'A'); - if (digit >= 16) - break; - val = (val << 4) | digit; - c = *++src; - } else - break; - } - if (c == '.') { - /* - * Internet format: - * a.b.c.d - * a.b.c (with c treated as 16 bits) - * a.b (with b treated as 24 bits) - * a (with a treated as 32 bits) - */ - if (pp >= parts + 3) - return (0); - *pp++ = val; - c = *++src; - } else - break; - } - /* - * Check for trailing characters. - */ - if (c != '\0' && !isspace(c)) - return (0); - /* - * Concoct the address according to - * the number of parts specified. - */ - n = pp - parts + 1; - /* inet_pton() takes dotted-quad only. it does not take shorthand. */ - if (pton && n != 4) - return (0); - switch (n) { - - case 0: - return (0); /* initial nondigit */ - - case 1: /* a -- 32 bits */ - break; - - case 2: /* a.b -- 8.24 bits */ - if (parts[0] > 0xff || val > 0xffffff) - return (0); - val |= parts[0] << 24; - break; - - case 3: /* a.b.c -- 8.8.16 bits */ - if ((parts[0] | parts[1]) > 0xff || val > 0xffff) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16); - break; - - case 4: /* a.b.c.d -- 8.8.8.8 bits */ - if ((parts[0] | parts[1] | parts[2] | val) > 0xff) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); - break; - } - if (dst) { - val = htonl(val); - memcpy(dst, &val, NS_INADDRSZ); - } - return (1); -} - -/* int - * inet_pton6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton6(const char *src, u_char *dst) -{ - static const char xdigits_l[] = "0123456789abcdef", - xdigits_u[] = "0123456789ABCDEF"; - u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; - const char *xdigits, *curtok; - int ch, seen_xdigits; - u_int val; - - _DIAGASSERT(src != NULL); - _DIAGASSERT(dst != NULL); - - memset((tp = tmp), '\0', NS_IN6ADDRSZ); - endp = tp + NS_IN6ADDRSZ; - colonp = NULL; - /* Leading :: requires some special handling. */ - if (*src == ':') - if (*++src != ':') - return (0); - curtok = src; - seen_xdigits = 0; - val = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) - pch = strchr((xdigits = xdigits_u), ch); - if (pch != NULL) { - val <<= 4; - val |= (int)(pch - xdigits); - if (++seen_xdigits > 4) - return (0); - continue; - } - if (ch == ':') { - curtok = src; - if (!seen_xdigits) { - if (colonp) - return (0); - colonp = tp; - continue; - } else if (*src == '\0') - return (0); - if (tp + NS_INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - seen_xdigits = 0; - val = 0; - continue; - } - if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && - inet_pton4(curtok, tp, 1) > 0) { - tp += NS_INADDRSZ; - seen_xdigits = 0; - break; /*%< '\\0' was seen by inet_pton4(). */ - } - return (0); - } - if (seen_xdigits) { - if (tp + NS_INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - } - if (colonp != NULL) { - /* - * Since some memmove()'s erroneously fail to handle - * overlapping regions, we'll do the shift by hand. - */ - const ptrdiff_t n = tp - colonp; - int i; - - if (tp == endp) - return (0); - for (i = 1; i <= n; i++) { - endp[- i] = colonp[n - i]; - colonp[n - i] = 0; - } - tp = endp; - } - if (tp != endp) - return (0); - memcpy(dst, tmp, NS_IN6ADDRSZ); - return (1); -} - -/*! \file */ diff --git a/libc/upstream-netbsd/libc/isc/ev_streams.c b/libc/upstream-netbsd/libc/isc/ev_streams.c deleted file mode 100644 index 2804b9f..0000000 --- a/libc/upstream-netbsd/libc/isc/ev_streams.c +++ /dev/null @@ -1,319 +0,0 @@ -/* $NetBSD: ev_streams.c,v 1.6 2009/04/12 17:07:17 christos Exp $ */ - -/* - * 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 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. - */ - -/* ev_streams.c - implement asynch stream file IO for the eventlib - * vix 04mar96 [initial] - */ - -#include -#if !defined(LINT) && !defined(CODECENTER) && !defined(lint) -#ifdef notdef -static const char rcsid[] = "Id: ev_streams.c,v 1.5 2005/04/27 04:56:36 sra Exp"; -#else -__RCSID("$NetBSD: ev_streams.c,v 1.6 2009/04/12 17:07:17 christos Exp $"); -#endif -#endif - -#include "port_before.h" -#include "fd_setsize.h" - -#include -#include - -#include - -#include -#include -#include "eventlib_p.h" - -#include "port_after.h" - -#ifndef _LIBC -static int copyvec(evStream *str, const struct iovec *iov, int iocnt); -static void consume(evStream *str, size_t bytes); -static void done(evContext opaqueCtx, evStream *str); -static void writable(evContext opaqueCtx, void *uap, int fd, int evmask); -static void readable(evContext opaqueCtx, void *uap, int fd, int evmask); -#endif - -struct iovec -evConsIovec(void *buf, size_t cnt) { - struct iovec ret; - - memset(&ret, 0xf5, sizeof ret); - ret.iov_base = buf; - ret.iov_len = cnt; - return (ret); -} - -#ifndef _LIBC -int -evWrite(evContext opaqueCtx, int fd, const struct iovec *iov, int iocnt, - evStreamFunc func, void *uap, evStreamID *id) -{ - evContext_p *ctx = opaqueCtx.opaque; - evStream *new; - int save; - - OKNEW(new); - new->func = func; - new->uap = uap; - new->fd = fd; - new->flags = 0; - if (evSelectFD(opaqueCtx, fd, EV_WRITE, writable, new, &new->file) < 0) - goto free; - if (copyvec(new, iov, iocnt) < 0) - goto free; - new->prevDone = NULL; - new->nextDone = NULL; - if (ctx->streams != NULL) - ctx->streams->prev = new; - new->prev = NULL; - new->next = ctx->streams; - ctx->streams = new; - if (id != NULL) - id->opaque = new; - return (0); - free: - save = errno; - FREE(new); - errno = save; - return (-1); -} - -int -evRead(evContext opaqueCtx, int fd, const struct iovec *iov, int iocnt, - evStreamFunc func, void *uap, evStreamID *id) -{ - evContext_p *ctx = opaqueCtx.opaque; - evStream *new; - int save; - - OKNEW(new); - new->func = func; - new->uap = uap; - new->fd = fd; - new->flags = 0; - if (evSelectFD(opaqueCtx, fd, EV_READ, readable, new, &new->file) < 0) - goto free; - if (copyvec(new, iov, iocnt) < 0) - goto free; - new->prevDone = NULL; - new->nextDone = NULL; - if (ctx->streams != NULL) - ctx->streams->prev = new; - new->prev = NULL; - new->next = ctx->streams; - ctx->streams = new; - if (id) - id->opaque = new; - return (0); - free: - save = errno; - FREE(new); - errno = save; - return (-1); -} - -int -evTimeRW(evContext opaqueCtx, evStreamID id, evTimerID timer) /*ARGSUSED*/ { - evStream *str = id.opaque; - - UNUSED(opaqueCtx); - - str->timer = timer; - str->flags |= EV_STR_TIMEROK; - return (0); -} - -int -evUntimeRW(evContext opaqueCtx, evStreamID id) /*ARGSUSED*/ { - evStream *str = id.opaque; - - UNUSED(opaqueCtx); - - str->flags &= ~EV_STR_TIMEROK; - return (0); -} - -int -evCancelRW(evContext opaqueCtx, evStreamID id) { - evContext_p *ctx = opaqueCtx.opaque; - evStream *old = id.opaque; - - /* - * The streams list is doubly threaded. First, there's ctx->streams - * that's used by evDestroy() to find and cancel all streams. Second, - * there's ctx->strDone (head) and ctx->strLast (tail) which thread - * through the potentially smaller number of "IO completed" streams, - * used in evGetNext() to avoid scanning the entire list. - */ - - /* Unlink from ctx->streams. */ - if (old->prev != NULL) - old->prev->next = old->next; - else - ctx->streams = old->next; - if (old->next != NULL) - old->next->prev = old->prev; - - /* - * If 'old' is on the ctx->strDone list, remove it. Update - * ctx->strLast if necessary. - */ - if (old->prevDone == NULL && old->nextDone == NULL) { - /* - * Either 'old' is the only item on the done list, or it's - * not on the done list. If the former, then we unlink it - * from the list. If the latter, we leave the list alone. - */ - if (ctx->strDone == old) { - ctx->strDone = NULL; - ctx->strLast = NULL; - } - } else { - if (old->prevDone != NULL) - old->prevDone->nextDone = old->nextDone; - else - ctx->strDone = old->nextDone; - if (old->nextDone != NULL) - old->nextDone->prevDone = old->prevDone; - else - ctx->strLast = old->prevDone; - } - - /* Deallocate the stream. */ - if (old->file.opaque) - evDeselectFD(opaqueCtx, old->file); - memput(old->iovOrig, sizeof (struct iovec) * old->iovOrigCount); - FREE(old); - return (0); -} - -/* Copy a scatter/gather vector and initialize a stream handler's IO. */ -static int -copyvec(evStream *str, const struct iovec *iov, int iocnt) { - int i; - - str->iovOrig = (struct iovec *)memget(sizeof(struct iovec) * iocnt); - if (str->iovOrig == NULL) { - errno = ENOMEM; - return (-1); - } - str->ioTotal = 0; - for (i = 0; i < iocnt; i++) { - str->iovOrig[i] = iov[i]; - str->ioTotal += iov[i].iov_len; - } - str->iovOrigCount = iocnt; - str->iovCur = str->iovOrig; - str->iovCurCount = str->iovOrigCount; - str->ioDone = 0; - return (0); -} - -/* Pull off or truncate lead iovec(s). */ -static void -consume(evStream *str, size_t bytes) { - while (bytes > 0U) { - if (bytes < (size_t)str->iovCur->iov_len) { - str->iovCur->iov_len -= bytes; - str->iovCur->iov_base = (void *) - ((u_char *)str->iovCur->iov_base + bytes); - str->ioDone += bytes; - bytes = 0; - } else { - bytes -= str->iovCur->iov_len; - str->ioDone += str->iovCur->iov_len; - str->iovCur++; - str->iovCurCount--; - } - } -} - -/* Add a stream to Done list and deselect the FD. */ -static void -done(evContext opaqueCtx, evStream *str) { - evContext_p *ctx = opaqueCtx.opaque; - - if (ctx->strLast != NULL) { - str->prevDone = ctx->strLast; - ctx->strLast->nextDone = str; - ctx->strLast = str; - } else { - INSIST(ctx->strDone == NULL); - ctx->strDone = ctx->strLast = str; - } - evDeselectFD(opaqueCtx, str->file); - str->file.opaque = NULL; - /* evDrop() will call evCancelRW() on us. */ -} - -/* Dribble out some bytes on the stream. (Called by evDispatch().) */ -static void -writable(evContext opaqueCtx, void *uap, int fd, int evmask) { - evStream *str = uap; - int bytes; - - UNUSED(evmask); - - bytes = writev(fd, str->iovCur, str->iovCurCount); - if (bytes > 0) { - if ((str->flags & EV_STR_TIMEROK) != 0) - evTouchIdleTimer(opaqueCtx, str->timer); - consume(str, bytes); - } else { - if (bytes < 0 && errno != EINTR) { - str->ioDone = -1; - str->ioErrno = errno; - } - } - if (str->ioDone == -1 || str->ioDone == str->ioTotal) - done(opaqueCtx, str); -} - -/* Scoop up some bytes from the stream. (Called by evDispatch().) */ -static void -readable(evContext opaqueCtx, void *uap, int fd, int evmask) { - evStream *str = uap; - int bytes; - - UNUSED(evmask); - - bytes = readv(fd, str->iovCur, str->iovCurCount); - if (bytes > 0) { - if ((str->flags & EV_STR_TIMEROK) != 0) - evTouchIdleTimer(opaqueCtx, str->timer); - consume(str, bytes); - } else { - if (bytes == 0) - str->ioDone = 0; - else { - if (errno != EINTR) { - str->ioDone = -1; - str->ioErrno = errno; - } - } - } - if (str->ioDone <= 0 || str->ioDone == str->ioTotal) - done(opaqueCtx, str); -} -#endif - -/*! \file */ diff --git a/libc/upstream-netbsd/libc/isc/ev_timers.c b/libc/upstream-netbsd/libc/isc/ev_timers.c deleted file mode 100644 index 40521a7..0000000 --- a/libc/upstream-netbsd/libc/isc/ev_timers.c +++ /dev/null @@ -1,519 +0,0 @@ -/* $NetBSD: ev_timers.c,v 1.11 2012/03/21 00:34:54 christos Exp $ */ - -/* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1995-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 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. - */ - -/* ev_timers.c - implement timers for the eventlib - * vix 09sep95 [initial] - */ - -#include -#if !defined(LINT) && !defined(CODECENTER) && !defined(lint) -#ifdef notdef -static const char rcsid[] = "Id: ev_timers.c,v 1.6 2005/04/27 04:56:36 sra Exp"; -#else -__RCSID("$NetBSD: ev_timers.c,v 1.11 2012/03/21 00:34:54 christos Exp $"); -#endif -#endif - -/* Import. */ - -#include "port_before.h" -#include "fd_setsize.h" - -#include - -#include -#include -#include "eventlib_p.h" - -#include "port_after.h" - -/* Constants. */ - -#define MILLION 1000000 -#define BILLION 1000000000 - -/* Forward. */ - -#ifndef _LIBC -static int due_sooner(void *, void *); -static void set_index(void *, int); -static void free_timer(void *, void *); -static void print_timer(void *, void *); -static void idle_timeout(evContext, void *, struct timespec, struct timespec); - -/* Private type. */ - -typedef struct { - evTimerFunc func; - void * uap; - struct timespec lastTouched; - struct timespec max_idle; - evTimer * timer; -} idle_timer; -#endif - -/* Public. */ - -struct timespec -evConsTime(time_t sec, long nsec) { - struct timespec x; - - x.tv_sec = sec; - x.tv_nsec = nsec; - return (x); -} - -struct timespec -evAddTime(struct timespec addend1, struct timespec addend2) { - struct timespec x; - - x.tv_sec = addend1.tv_sec + addend2.tv_sec; - x.tv_nsec = addend1.tv_nsec + addend2.tv_nsec; - if (x.tv_nsec >= BILLION) { - x.tv_sec++; - x.tv_nsec -= BILLION; - } - return (x); -} - -struct timespec -evSubTime(struct timespec minuend, struct timespec subtrahend) { - struct timespec x; - - x.tv_sec = minuend.tv_sec - subtrahend.tv_sec; - if (minuend.tv_nsec >= subtrahend.tv_nsec) - x.tv_nsec = minuend.tv_nsec - subtrahend.tv_nsec; - else { - x.tv_nsec = BILLION - subtrahend.tv_nsec + minuend.tv_nsec; - x.tv_sec--; - } - return (x); -} - -int -evCmpTime(struct timespec a, struct timespec b) { -#define SGN(x) ((x) < 0 ? (-1) : (x) > 0 ? (1) : (0)); - time_t s = a.tv_sec - b.tv_sec; - long n; - - if (s != 0) - return SGN(s); - - n = a.tv_nsec - b.tv_nsec; - return SGN(n); -} - -struct timespec -evNowTime(void) -{ - struct timeval now; -#ifdef CLOCK_REALTIME - struct timespec tsnow; - int m = CLOCK_REALTIME; - -#ifdef CLOCK_MONOTONIC -#ifndef _LIBC - if (__evOptMonoTime) - m = CLOCK_MONOTONIC; -#endif -#endif - if (clock_gettime(m, &tsnow) == 0) - return (tsnow); -#endif - if (gettimeofday(&now, NULL) < 0) - return (evConsTime((time_t)0, 0L)); - return (evTimeSpec(now)); -} - -struct timespec -evUTCTime(void) { - struct timeval now; -#ifdef CLOCK_REALTIME - struct timespec tsnow; - if (clock_gettime(CLOCK_REALTIME, &tsnow) == 0) - return (tsnow); -#endif - if (gettimeofday(&now, NULL) < 0) - return (evConsTime((time_t)0, 0L)); - return (evTimeSpec(now)); -} - -#ifndef _LIBC -struct timespec -evLastEventTime(evContext opaqueCtx) { - evContext_p *ctx = opaqueCtx.opaque; - - return (ctx->lastEventTime); -} -#endif - -struct timespec -evTimeSpec(struct timeval tv) { - struct timespec ts; - - ts.tv_sec = tv.tv_sec; - ts.tv_nsec = tv.tv_usec * 1000; - return (ts); -} - -struct timeval -evTimeVal(struct timespec ts) { - struct timeval tv; - - tv.tv_sec = ts.tv_sec; - tv.tv_usec = (suseconds_t)(ts.tv_nsec / 1000); - return (tv); -} - -#ifndef _LIBC -int -evSetTimer(evContext opaqueCtx, - evTimerFunc func, - void *uap, - struct timespec due, - struct timespec inter, - evTimerID *opaqueID -) { - evContext_p *ctx = opaqueCtx.opaque; - evTimer *id; - - evPrintf(ctx, 1, -"evSetTimer(ctx %p, func %p, uap %p, due %ld.%09ld, inter %ld.%09ld)\n", - ctx, func, uap, - (long)due.tv_sec, due.tv_nsec, - (long)inter.tv_sec, inter.tv_nsec); - -#ifdef __hpux - /* - * tv_sec and tv_nsec are unsigned. - */ - if (due.tv_nsec >= BILLION) - EV_ERR(EINVAL); - - if (inter.tv_nsec >= BILLION) - EV_ERR(EINVAL); -#else - if (due.tv_sec < 0 || due.tv_nsec < 0 || due.tv_nsec >= BILLION) - EV_ERR(EINVAL); - - if (inter.tv_sec < 0 || inter.tv_nsec < 0 || inter.tv_nsec >= BILLION) - EV_ERR(EINVAL); -#endif - - /* due={0,0} is a magic cookie meaning "now." */ - if (due.tv_sec == (time_t)0 && due.tv_nsec == 0L) - due = evNowTime(); - - /* Allocate and fill. */ - OKNEW(id); - id->func = func; - id->uap = uap; - id->due = due; - id->inter = inter; - - if (heap_insert(ctx->timers, id) < 0) - return (-1); - - /* Remember the ID if the caller provided us a place for it. */ - if (opaqueID) - opaqueID->opaque = id; - - if (ctx->debug > 7) { - evPrintf(ctx, 7, "timers after evSetTimer:\n"); - (void) heap_for_each(ctx->timers, print_timer, (void *)ctx); - } - - return (0); -} - -int -evClearTimer(evContext opaqueCtx, evTimerID id) { - evContext_p *ctx = opaqueCtx.opaque; - evTimer *del = id.opaque; - - if (ctx->cur != NULL && - ctx->cur->type == Timer && - ctx->cur->u.timer.this == del) { - evPrintf(ctx, 8, "deferring delete of timer (executing)\n"); - /* - * Setting the interval to zero ensures that evDrop() will - * clean up the timer. - */ - del->inter = evConsTime(0, 0); - return (0); - } - - if (heap_element(ctx->timers, del->index) != del) - EV_ERR(ENOENT); - - if (heap_delete(ctx->timers, del->index) < 0) - return (-1); - FREE(del); - - if (ctx->debug > 7) { - evPrintf(ctx, 7, "timers after evClearTimer:\n"); - (void) heap_for_each(ctx->timers, print_timer, (void *)ctx); - } - - return (0); -} - -int -evConfigTimer(evContext opaqueCtx, - evTimerID id, - const char *param, - int value -) { - evContext_p *ctx = opaqueCtx.opaque; - evTimer *timer = id.opaque; - int result=0; - - UNUSED(value); - - if (heap_element(ctx->timers, timer->index) != timer) - EV_ERR(ENOENT); - - if (strcmp(param, "rate") == 0) - timer->mode |= EV_TMR_RATE; - else if (strcmp(param, "interval") == 0) - timer->mode &= ~EV_TMR_RATE; - else - EV_ERR(EINVAL); - - return (result); -} - -int -evResetTimer(evContext opaqueCtx, - evTimerID id, - evTimerFunc func, - void *uap, - struct timespec due, - struct timespec inter -) { - evContext_p *ctx = opaqueCtx.opaque; - evTimer *timer = id.opaque; - struct timespec old_due; - int result=0; - - if (heap_element(ctx->timers, timer->index) != timer) - EV_ERR(ENOENT); - -#ifdef __hpux - /* - * tv_sec and tv_nsec are unsigned. - */ - if (due.tv_nsec >= BILLION) - EV_ERR(EINVAL); - - if (inter.tv_nsec >= BILLION) - EV_ERR(EINVAL); -#else - if (due.tv_sec < 0 || due.tv_nsec < 0 || due.tv_nsec >= BILLION) - EV_ERR(EINVAL); - - if (inter.tv_sec < 0 || inter.tv_nsec < 0 || inter.tv_nsec >= BILLION) - EV_ERR(EINVAL); -#endif - - old_due = timer->due; - - timer->func = func; - timer->uap = uap; - timer->due = due; - timer->inter = inter; - - switch (evCmpTime(due, old_due)) { - case -1: - result = heap_increased(ctx->timers, timer->index); - break; - case 0: - result = 0; - break; - case 1: - result = heap_decreased(ctx->timers, timer->index); - break; - } - - if (ctx->debug > 7) { - evPrintf(ctx, 7, "timers after evResetTimer:\n"); - (void) heap_for_each(ctx->timers, print_timer, (void *)ctx); - } - - return (result); -} - -int -evSetIdleTimer(evContext opaqueCtx, - evTimerFunc func, - void *uap, - struct timespec max_idle, - evTimerID *opaqueID -) { - evContext_p *ctx = opaqueCtx.opaque; - idle_timer *tt; - - /* Allocate and fill. */ - OKNEW(tt); - tt->func = func; - tt->uap = uap; - tt->lastTouched = ctx->lastEventTime; - tt->max_idle = max_idle; - - if (evSetTimer(opaqueCtx, idle_timeout, tt, - evAddTime(ctx->lastEventTime, max_idle), - max_idle, opaqueID) < 0) { - FREE(tt); - return (-1); - } - - tt->timer = opaqueID->opaque; - - return (0); -} - -int -evClearIdleTimer(evContext opaqueCtx, evTimerID id) { - evTimer *del = id.opaque; - idle_timer *tt = del->uap; - - FREE(tt); - return (evClearTimer(opaqueCtx, id)); -} - -int -evResetIdleTimer(evContext opaqueCtx, - evTimerID opaqueID, - evTimerFunc func, - void *uap, - struct timespec max_idle -) { - evContext_p *ctx = opaqueCtx.opaque; - evTimer *timer = opaqueID.opaque; - idle_timer *tt = timer->uap; - - tt->func = func; - tt->uap = uap; - tt->lastTouched = ctx->lastEventTime; - tt->max_idle = max_idle; - - return (evResetTimer(opaqueCtx, opaqueID, idle_timeout, tt, - evAddTime(ctx->lastEventTime, max_idle), - max_idle)); -} - -int -evTouchIdleTimer(evContext opaqueCtx, evTimerID id) { - evContext_p *ctx = opaqueCtx.opaque; - evTimer *t = id.opaque; - idle_timer *tt = t->uap; - - tt->lastTouched = ctx->lastEventTime; - - return (0); -} - -/* Public to the rest of eventlib. */ - -heap_context -evCreateTimers(const evContext_p *ctx) { - - UNUSED(ctx); - - return (heap_new(due_sooner, set_index, 2048)); -} - -void -evDestroyTimers(const evContext_p *ctx) { - (void) heap_for_each(ctx->timers, free_timer, NULL); - (void) heap_free(ctx->timers); -} - -/* Private. */ - -static int -due_sooner(void *a, void *b) { - evTimer *a_timer, *b_timer; - - a_timer = a; - b_timer = b; - return (evCmpTime(a_timer->due, b_timer->due) < 0); -} - -static void -set_index(void *what, int idx) { - evTimer *timer; - - timer = what; - timer->index = idx; -} - -static void -free_timer(void *what, void *uap) { - evTimer *t = what; - - UNUSED(uap); - - FREE(t); -} - -static void -print_timer(void *what, void *uap) { - evTimer *cur = what; - evContext_p *ctx = uap; - - cur = what; - evPrintf(ctx, 7, - " func %p, uap %p, due %ld.%09ld, inter %ld.%09ld\n", - cur->func, cur->uap, - (long)cur->due.tv_sec, cur->due.tv_nsec, - (long)cur->inter.tv_sec, cur->inter.tv_nsec); -} - -static void -idle_timeout(evContext opaqueCtx, - void *uap, - struct timespec due, - struct timespec inter -) { - evContext_p *ctx = opaqueCtx.opaque; - idle_timer *this = uap; - struct timespec idle; - - UNUSED(due); - UNUSED(inter); - - idle = evSubTime(ctx->lastEventTime, this->lastTouched); - if (evCmpTime(idle, this->max_idle) >= 0) { - (this->func)(opaqueCtx, this->uap, this->timer->due, - this->max_idle); - /* - * Setting the interval to zero will cause the timer to - * be cleaned up in evDrop(). - */ - this->timer->inter = evConsTime(0L, 0L); - FREE(this); - } else { - /* evDrop() will reschedule the timer. */ - this->timer->inter = evSubTime(this->max_idle, idle); - } -} -#endif - -/*! \file */ diff --git a/libc/upstream-netbsd/libc/isc/eventlib_p.h b/libc/upstream-netbsd/libc/isc/eventlib_p.h deleted file mode 100644 index 4d6b788..0000000 --- a/libc/upstream-netbsd/libc/isc/eventlib_p.h +++ /dev/null @@ -1,283 +0,0 @@ -/* $NetBSD: eventlib_p.h,v 1.3 2009/04/12 17:07:17 christos Exp $ */ - -/* - * Copyright (c) 2005 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1995-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 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. - */ - -/*! \file - * \brief private interfaces for eventlib - * \author vix 09sep95 [initial] - * - * Id: eventlib_p.h,v 1.9 2006/03/09 23:57:56 marka Exp - */ - -#ifndef _EVENTLIB_P_H -#define _EVENTLIB_P_H - -#include -#include -#include -#include -#include - -#define EVENTLIB_DEBUG 1 - -#include -#include -#include -#include -#include - -#include -#include -#include - -#define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT) -#define EV_ERR(e) return (errno = (e), -1) -#define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL -#define OKFREE(x, y) if ((x) < 0) { FREE((y)); EV_ERR(errno); } \ - else (void)NULL - -#define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \ - FILL(p); \ - else \ - (void)NULL; -#define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \ - errno = ENOMEM; \ - return (-1); \ - } else \ - FILL(p) -#define FREE(p) memput((p), sizeof *(p)) - -#if EVENTLIB_DEBUG -#define FILL(p) memset((p), 0xF5, sizeof *(p)) -#else -#define FILL(p) -#endif - -#ifdef USE_POLL -#ifdef HAVE_STROPTS_H -#include -#endif -#include -#endif /* USE_POLL */ - -typedef struct evConn { - evConnFunc func; - void * uap; - int fd; - int flags; -#define EV_CONN_LISTEN 0x0001 /*%< Connection is a listener. */ -#define EV_CONN_SELECTED 0x0002 /*%< evSelectFD(conn->file). */ -#define EV_CONN_BLOCK 0x0004 /*%< Listener fd was blocking. */ - evFileID file; - struct evConn * prev; - struct evConn * next; -} evConn; - -typedef struct evAccept { - int fd; - union { - struct sockaddr sa; - struct sockaddr_in in; -#ifndef NO_SOCKADDR_UN - struct sockaddr_un un; -#endif - } la; - ISC_SOCKLEN_T lalen; - union { - struct sockaddr sa; - struct sockaddr_in in; -#ifndef NO_SOCKADDR_UN - struct sockaddr_un un; -#endif - } ra; - ISC_SOCKLEN_T ralen; - int ioErrno; - evConn * conn; - LINK(struct evAccept) link; -} evAccept; - -typedef struct evFile { - evFileFunc func; - void * uap; - int fd; - int eventmask; - int preemptive; - struct evFile * prev; - struct evFile * next; - struct evFile * fdprev; - struct evFile * fdnext; -} evFile; - -typedef struct evStream { - evStreamFunc func; - void * uap; - evFileID file; - evTimerID timer; - int flags; -#define EV_STR_TIMEROK 0x0001 /*%< IFF timer valid. */ - int fd; - struct iovec * iovOrig; - int iovOrigCount; - struct iovec * iovCur; - int iovCurCount; - int ioTotal; - int ioDone; - int ioErrno; - struct evStream *prevDone, *nextDone; - struct evStream *prev, *next; -} evStream; - -typedef struct evTimer { - evTimerFunc func; - void * uap; - struct timespec due, inter; - int index; - int mode; -#define EV_TMR_RATE 1 -} evTimer; - -typedef struct evWait { - evWaitFunc func; - void * uap; - const void * tag; - struct evWait * next; -} evWait; - -typedef struct evWaitList { - evWait * first; - evWait * last; - struct evWaitList * prev; - struct evWaitList * next; -} evWaitList; - -typedef struct evEvent_p { - enum { Accept, File, Stream, Timer, Wait, Free, Null } type; - union { - struct { evAccept *this; } accept; - struct { evFile *this; int eventmask; } file; - struct { evStream *this; } stream; - struct { evTimer *this; } timer; - struct { evWait *this; } wait; - struct { struct evEvent_p *next; } free; - struct { const void *placeholder; } null; - } u; -} evEvent_p; - -#ifdef USE_POLL -typedef struct { - void *ctx; /* pointer to the evContext_p */ - uint32_t type; /* READ, WRITE, EXCEPT, nonblk */ - uint32_t result; /* 1 => revents, 0 => events */ -} __evEmulMask; - -#define emulMaskInit(ctx, field, ev, lastnext) \ - ctx->field.ctx = ctx; \ - ctx->field.type = ev; \ - ctx->field.result = lastnext; - -extern short *__fd_eventfield(int fd, __evEmulMask *maskp); -extern short __poll_event(__evEmulMask *maskp); -extern void __fd_clr(int fd, __evEmulMask *maskp); -extern void __fd_set(int fd, __evEmulMask *maskp); - -#undef FD_ZERO -#define FD_ZERO(maskp) - -#undef FD_SET -#define FD_SET(fd, maskp) \ - __fd_set(fd, maskp) - -#undef FD_CLR -#define FD_CLR(fd, maskp) \ - __fd_clr(fd, maskp) - -#undef FD_ISSET -#define FD_ISSET(fd, maskp) \ - ((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0) - -#endif /* USE_POLL */ - -typedef struct { - /* Global. */ - const evEvent_p *cur; - /* Debugging. */ - int debug; - FILE *output; - /* Connections. */ - evConn *conns; - LIST(evAccept) accepts; - /* Files. */ - evFile *files, *fdNext; -#ifndef USE_POLL - fd_set rdLast, rdNext; - fd_set wrLast, wrNext; - fd_set exLast, exNext; - fd_set nonblockBefore; - int fdMax, fdCount, highestFD; - evFile *fdTable[FD_SETSIZE]; -#else - struct pollfd *pollfds; /* Allocated as needed */ - evFile **fdTable; /* Ditto */ - int maxnfds; /* # elements in above */ - int firstfd; /* First active fd */ - int fdMax; /* Last active fd */ - int fdCount; /* # fd:s with I/O */ - int highestFD; /* max fd allowed by OS */ - __evEmulMask rdLast, rdNext; - __evEmulMask wrLast, wrNext; - __evEmulMask exLast, exNext; - __evEmulMask nonblockBefore; -#endif /* USE_POLL */ -#ifdef EVENTLIB_TIME_CHECKS - struct timespec lastSelectTime; - int lastFdCount; -#endif - /* Streams. */ - evStream *streams; - evStream *strDone, *strLast; - /* Timers. */ - struct timespec lastEventTime; - heap_context timers; - /* Waits. */ - evWaitList *waitLists; - evWaitList waitDone; -} evContext_p; - -/* eventlib.c */ -#define evPrintf __evPrintf -void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...) - ISC_FORMAT_PRINTF(3, 4); - -#ifdef USE_POLL -extern int evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd); -#endif /* USE_POLL */ - -/* ev_timers.c */ -#define evCreateTimers __evCreateTimers -heap_context evCreateTimers(const evContext_p *); -#define evDestroyTimers __evDestroyTimers -void evDestroyTimers(const evContext_p *); - -/* ev_waits.c */ -#define evFreeWait __evFreeWait -evWait *evFreeWait(evContext_p *ctx, evWait *old); - -/* Global options */ -extern int __evOptMonoTime; - -#endif /*_EVENTLIB_P_H*/ diff --git a/libc/upstream-netbsd/libc/regex/cclass.h b/libc/upstream-netbsd/libc/regex/cclass.h deleted file mode 100644 index 3ab2ccb..0000000 --- a/libc/upstream-netbsd/libc/regex/cclass.h +++ /dev/null @@ -1,104 +0,0 @@ -/* $NetBSD: cclass.h,v 1.7 2003/08/07 16:43:19 agc Exp $ */ - -/*- - * 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. 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 - */ - -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * - * 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 - */ - -/* character-class table */ -static const struct cclass { - const char *name; - const char *chars; - const char *multis; -} cclasses[] = { - { "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ -0123456789", "" }, - { "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", - "" }, - { "blank", " \t", "" }, - { "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\ -\25\26\27\30\31\32\33\34\35\36\37\177", "" }, - { "digit", "0123456789", "" }, - { "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ -0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", - "" }, - { "lower", "abcdefghijklmnopqrstuvwxyz", - "" }, - { "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ -0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ", - "" }, - { "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", - "" }, - { "space", "\t\n\v\f\r ", "" }, - { "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", - "" }, - { "xdigit", "0123456789ABCDEFabcdef", - "" }, - { NULL, 0, "" } -}; diff --git a/libc/upstream-netbsd/libc/regex/cname.h b/libc/upstream-netbsd/libc/regex/cname.h deleted file mode 100644 index 4b9ef39..0000000 --- a/libc/upstream-netbsd/libc/regex/cname.h +++ /dev/null @@ -1,175 +0,0 @@ -/* $NetBSD: cname.h,v 1.7 2003/08/07 16:43:19 agc Exp $ */ - -/*- - * 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. 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 - */ - -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * - * 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 - */ - -/* character-name table */ -static const struct cname { - const 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/libc/upstream-netbsd/libc/regex/engine.c b/libc/upstream-netbsd/libc/regex/engine.c deleted file mode 100644 index 2a800d4..0000000 --- a/libc/upstream-netbsd/libc/regex/engine.c +++ /dev/null @@ -1,1188 +0,0 @@ -/* $NetBSD: engine.c,v 1.24 2012/03/13 21:13:42 christos Exp $ */ - -/*- - * 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. 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. - * - * @(#)engine.c 8.5 (Berkeley) 3/20/94 - */ - -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * - * 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. - * - * @(#)engine.c 8.5 (Berkeley) 3/20/94 - */ - -/* - * The matching engine and friends. This file is #included by regexec.c - * after suitable #defines of a variety of macros used herein, so that - * different state representations can be used without duplicating masses - * of code. - */ - -#ifdef SNAMES -#define matcher smatcher -#define fast sfast -#define slow sslow -#define dissect sdissect -#define backref sbackref -#define step sstep -#define print sprint -#define at sat -#define match smat -#define nope snope -#endif -#ifdef LNAMES -#define matcher lmatcher -#define fast lfast -#define slow lslow -#define dissect ldissect -#define backref lbackref -#define step lstep -#define print lprint -#define at lat -#define match lmat -#define nope lnope -#endif - -/* another structure passed up and down to avoid zillions of parameters */ -struct match { - struct re_guts *g; - int eflags; - regmatch_t *pmatch; /* [nsub+1] (0 element unused) */ - const char *offp; /* offsets work from here */ - const char *beginp; /* start of string -- virtual NUL precedes */ - const char *endp; /* end of string -- virtual NUL here */ - const char *coldp; /* can be no match starting before here */ - const char **lastpos; /* [nplus+1] */ - STATEVARS; - states st; /* current states */ - states fresh; /* states for a fresh start */ - states tmp; /* temporary */ - states empty; /* empty set of states */ -}; - -/* ========= begin header generated by ./mkh ========= */ -#ifdef __cplusplus -extern "C" { -#endif - -/* === engine.c === */ -static int matcher(struct re_guts *g, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); -static const char *dissect(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst); -static const char *backref(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst, sopno lev); -static const char *fast(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst); -static const char *slow(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst); -static states step(struct re_guts *g, sopno start, sopno stop, states bef, int ch, states aft); -#define BOL (OUT+1) -#define EOL (BOL+1) -#define BOLEOL (BOL+2) -#define NOTHING (BOL+3) -#define BOW (BOL+4) -#define EOW (BOL+5) -#define CODEMAX (BOL+5) /* highest code used */ -#define NONCHAR(c) ((c) > CHAR_MAX) -#define NNONCHAR (CODEMAX-CHAR_MAX) -#ifdef REDEBUG -static void print(struct match *m, char *caption, states st, int ch, FILE *d); -#endif -#ifdef REDEBUG -static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst); -#endif -#ifdef REDEBUG -static char *pchar(int ch); -#endif - -#ifdef __cplusplus -} -#endif -/* ========= end header generated by ./mkh ========= */ - -#ifdef REDEBUG -#define SP(t, s, c) print(m, t, s, c, stdout) -#define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2) -#define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); } -static int nope = 0; -#else -#define SP(t, s, c) /* nothing */ -#define AT(t, p1, p2, s1, s2) /* nothing */ -#define NOTE(s) /* nothing */ -#endif - -/* - - matcher - the actual matching engine - == static int matcher(struct re_guts *g, char *string, \ - == size_t nmatch, regmatch_t pmatch[], int eflags); - */ -static int /* 0 success, REG_NOMATCH failure */ -matcher( - struct re_guts *g, - const char *string, - size_t nmatch, - regmatch_t pmatch[], - int eflags) -{ - const char *endp; - size_t i; - struct match mv; - struct match *m = &mv; - const char *dp; - const sopno gf = g->firststate+1; /* +1 for OEND */ - const sopno gl = g->laststate; - const char *start; - const char *stop; - int error = 0; - - _DIAGASSERT(g != NULL); - _DIAGASSERT(string != NULL); - /* pmatch checked below */ - - /* simplify the situation where possible */ - if (g->cflags®_NOSUB) - nmatch = 0; - if (eflags®_STARTEND) { - _DIAGASSERT(pmatch != NULL); - start = string + (size_t)pmatch[0].rm_so; - stop = string + (size_t)pmatch[0].rm_eo; - } else { - start = string; - stop = start + strlen(start); - } - if (stop < start) - return(REG_INVARG); - - /* prescreening; this does wonders for this rather slow code */ - if (g->must != NULL) { - for (dp = start; dp < stop; dp++) - if (*dp == g->must[0] && (size_t)(stop - dp) >= g->mlen && - memcmp(dp, g->must, g->mlen) == 0) - break; - if (dp == stop) /* we didn't find g->must */ - return(REG_NOMATCH); - } - - /* match struct setup */ - m->g = g; - m->eflags = eflags; - m->pmatch = NULL; - m->lastpos = NULL; - m->offp = string; - m->beginp = start; - m->endp = stop; - STATESETUP(m, 4); - SETUP(m->st); - SETUP(m->fresh); - SETUP(m->tmp); - SETUP(m->empty); - CLEAR(m->empty); - - /* this loop does only one repetition except for backrefs */ - for (;;) { - endp = fast(m, start, stop, gf, gl); - if (endp == NULL) { /* a miss */ - error = REG_NOMATCH; - goto done; - } - if (nmatch == 0 && !g->backrefs) - break; /* no further info needed */ - - /* where? */ - assert(m->coldp != NULL); - for (;;) { - NOTE("finding start"); - endp = slow(m, m->coldp, stop, gf, gl); - if (endp != NULL) - break; - assert(m->coldp < m->endp); - m->coldp++; - } - if (nmatch == 1 && !g->backrefs) - break; /* no further info needed */ - - /* oh my, he wants the subexpressions... */ - if (m->pmatch == NULL) - m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) * - sizeof(regmatch_t)); - if (m->pmatch == NULL) { - error = REG_ESPACE; - goto done; - } - for (i = 1; i <= m->g->nsub; i++) - m->pmatch[i].rm_so = m->pmatch[i].rm_eo = (regoff_t)-1; - if (!g->backrefs && !(m->eflags®_BACKR)) { - NOTE("dissecting"); - dp = dissect(m, m->coldp, endp, gf, gl); - } else { - if (g->nplus > 0 && m->lastpos == NULL) - m->lastpos = malloc((g->nplus+1) * - sizeof(const char *)); - if (g->nplus > 0 && m->lastpos == NULL) { - error = REG_ESPACE; - goto done; - } - NOTE("backref dissect"); - dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); - } - if (dp != NULL) - break; - - /* uh-oh... we couldn't find a subexpression-level match */ - assert(g->backrefs); /* must be back references doing it */ - assert(g->nplus == 0 || m->lastpos != NULL); - for (;;) { - if (dp != NULL || endp <= m->coldp) - break; /* defeat */ - NOTE("backoff"); - endp = slow(m, m->coldp, endp-1, gf, gl); - if (endp == NULL) - break; /* defeat */ - /* try it on a shorter possibility */ -#ifndef NDEBUG - for (i = 1; i <= m->g->nsub; i++) { - assert(m->pmatch[i].rm_so == (regoff_t)-1); - assert(m->pmatch[i].rm_eo == (regoff_t)-1); - } -#endif - NOTE("backoff dissect"); - dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); - } - assert(dp == NULL || dp == endp); - if (dp != NULL) /* found a shorter one */ - break; - - /* despite initial appearances, there is no match here */ - NOTE("false alarm"); - start = m->coldp + 1; /* recycle starting later */ - assert(start <= stop); - } - - /* fill in the details if requested */ - if (nmatch > 0) { - _DIAGASSERT(pmatch != NULL); - pmatch[0].rm_so = m->coldp - m->offp; - pmatch[0].rm_eo = endp - m->offp; - } - if (nmatch > 1) { - assert(m->pmatch != NULL); - for (i = 1; i < nmatch; i++) - if (i <= m->g->nsub) - pmatch[i] = m->pmatch[i]; - else { - pmatch[i].rm_so = (regoff_t)-1; - pmatch[i].rm_eo = (regoff_t)-1; - } - } - -done: - if (m->pmatch != NULL) { - free(m->pmatch); - m->pmatch = NULL; - } - if (m->lastpos != NULL) { - free(m->lastpos); - m->lastpos = NULL; - } - STATETEARDOWN(m); - return error; -} - -/* - - dissect - figure out what matched what, no back references - == static const char *dissect(struct match *m, const char *start, \ - == const char *stop, sopno startst, sopno stopst); - */ -static const char * /* == stop (success) always */ -dissect( - struct match *m, - const char *start, - const char *stop, - sopno startst, - sopno stopst) -{ - int i; - sopno ss; /* start sop of current subRE */ - sopno es; /* end sop of current subRE */ - const char *sp; /* start of string matched by it */ - const char *stp; /* string matched by it cannot pass here */ - const char *rest; /* start of rest of string */ - const char *tail; /* string unmatched by rest of RE */ - sopno ssub; /* start sop of subsubRE */ - sopno esub; /* end sop of subsubRE */ - const char *ssp; /* start of string matched by subsubRE */ - const char *sep; /* end of string matched by subsubRE */ - const char *oldssp; /* previous ssp */ -#ifndef NDEBUG - const char *dp; -#endif - - _DIAGASSERT(m != NULL); - _DIAGASSERT(start != NULL); - _DIAGASSERT(stop != NULL); - - AT("diss", start, stop, startst, stopst); - sp = start; - for (ss = startst; ss < stopst; ss = es) { - /* identify end of subRE */ - es = ss; - switch (OP(m->g->strip[es])) { - case OPLUS_: - case OQUEST_: - es += OPND(m->g->strip[es]); - break; - case OCH_: - while (OP(m->g->strip[es]) != O_CH) - es += OPND(m->g->strip[es]); - break; - } - es++; - - /* figure out what it matched */ - switch (OP(m->g->strip[ss])) { - case OEND: - assert(nope); - break; - case OCHAR: - sp++; - break; - case OBOL: - case OEOL: - case OBOW: - case OEOW: - break; - case OANY: - case OANYOF: - sp++; - break; - case OBACK_: - case O_BACK: - assert(nope); - break; - /* cases where length of match is hard to find */ - case OQUEST_: - stp = stop; - for (;;) { - /* how long could this one be? */ - rest = slow(m, sp, stp, ss, es); - assert(rest != NULL); /* it did match */ - /* could the rest match the rest? */ - tail = slow(m, rest, stop, es, stopst); - if (tail == stop) - break; /* yes! */ - /* no -- try a shorter match for this one */ - stp = rest - 1; - assert(stp >= sp); /* it did work */ - } - ssub = ss + 1; - esub = es - 1; - /* did innards match? */ - if (slow(m, sp, rest, ssub, esub) != NULL) { -#ifdef NDEBUG - (void) -#else - dp = -#endif - dissect(m, sp, rest, ssub, esub); - assert(dp == rest); - } else /* no */ - assert(sp == rest); - sp = rest; - break; - case OPLUS_: - stp = stop; - for (;;) { - /* how long could this one be? */ - rest = slow(m, sp, stp, ss, es); - assert(rest != NULL); /* it did match */ - /* could the rest match the rest? */ - tail = slow(m, rest, stop, es, stopst); - if (tail == stop) - break; /* yes! */ - /* no -- try a shorter match for this one */ - stp = rest - 1; - assert(stp >= sp); /* it did work */ - } - ssub = ss + 1; - esub = es - 1; - ssp = sp; - oldssp = ssp; - for (;;) { /* find last match of innards */ - sep = slow(m, ssp, rest, ssub, esub); - if (sep == NULL || sep == ssp) - break; /* failed or matched null */ - oldssp = ssp; /* on to next try */ - ssp = sep; - } - if (sep == NULL) { - /* last successful match */ - sep = ssp; - ssp = oldssp; - } - assert(sep == rest); /* must exhaust substring */ - assert(slow(m, ssp, sep, ssub, esub) == rest); -#ifdef NDEBUG - (void) -#else - dp = -#endif - dissect(m, ssp, sep, ssub, esub); - assert(dp == sep); - sp = rest; - break; - case OCH_: - stp = stop; - for (;;) { - /* how long could this one be? */ - rest = slow(m, sp, stp, ss, es); - assert(rest != NULL); /* it did match */ - /* could the rest match the rest? */ - tail = slow(m, rest, stop, es, stopst); - if (tail == stop) - break; /* yes! */ - /* no -- try a shorter match for this one */ - stp = rest - 1; - assert(stp >= sp); /* it did work */ - } - ssub = ss + 1; - esub = ss + OPND(m->g->strip[ss]) - 1; - assert(OP(m->g->strip[esub]) == OOR1); - for (;;) { /* find first matching branch */ - if (slow(m, sp, rest, ssub, esub) == rest) - break; /* it matched all of it */ - /* that one missed, try next one */ - assert(OP(m->g->strip[esub]) == OOR1); - esub++; - assert(OP(m->g->strip[esub]) == OOR2); - ssub = esub + 1; - esub += OPND(m->g->strip[esub]); - if (OP(m->g->strip[esub]) == OOR2) - esub--; - else - assert(OP(m->g->strip[esub]) == O_CH); - } -#ifdef NDEBUG - (void) -#else - dp = -#endif - dissect(m, sp, rest, ssub, esub); - assert(dp == rest); - sp = rest; - break; - case O_PLUS: - case O_QUEST: - case OOR1: - case OOR2: - case O_CH: - assert(nope); - break; - case OLPAREN: - i = OPND(m->g->strip[ss]); - assert(0 < i && i <= m->g->nsub); - m->pmatch[i].rm_so = sp - m->offp; - break; - case ORPAREN: - i = OPND(m->g->strip[ss]); - assert(0 < i && i <= m->g->nsub); - m->pmatch[i].rm_eo = sp - m->offp; - break; - default: /* uh oh */ - assert(nope); - break; - } - } - - assert(sp == stop); - return(sp); -} - -/* - - backref - figure out what matched what, figuring in back references - == static const char *backref(struct match *m, const char *start, \ - == const char *stop, sopno startst, sopno stopst, sopno lev); - */ -static const char * /* == stop (success) or NULL (failure) */ -backref( - struct match *m, - const char *start, - const char *stop, - sopno startst, - sopno stopst, - sopno lev) /* PLUS nesting level */ -{ - int i; - sopno ss; /* start sop of current subRE */ - const char *sp; /* start of string matched by it */ - sopno ssub; /* start sop of subsubRE */ - sopno esub; /* end sop of subsubRE */ - const char *ssp; /* start of string matched by subsubRE */ - const char *dp; - size_t len; - int hard; - sop s; - regoff_t offsave; - cset *cs; - - _DIAGASSERT(m != NULL); - _DIAGASSERT(start != NULL); - _DIAGASSERT(stop != NULL); - - AT("back", start, stop, startst, stopst); - sp = start; - - /* get as far as we can with easy stuff */ - hard = 0; - for (ss = startst; !hard && ss < stopst; ss++) - switch (OP(s = m->g->strip[ss])) { - case OCHAR: - if (sp == stop || *sp++ != (char)OPND(s)) - return(NULL); - break; - case OANY: - if (sp == stop) - return(NULL); - sp++; - break; - case OANYOF: - cs = &m->g->sets[OPND(s)]; - if (sp == stop || !CHIN(cs, *sp++)) - return(NULL); - break; - case OBOL: - if ( (sp == m->beginp && !(m->eflags®_NOTBOL)) || - (sp < m->endp && *(sp-1) == '\n' && - (m->g->cflags®_NEWLINE)) ) - { /* yes */ } - else - return(NULL); - break; - case OEOL: - if ( (sp == m->endp && !(m->eflags®_NOTEOL)) || - (sp < m->endp && *sp == '\n' && - (m->g->cflags®_NEWLINE)) ) - { /* yes */ } - else - return(NULL); - break; - case OBOW: - if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) || - (sp < m->endp && *(sp-1) == '\n' && - (m->g->cflags®_NEWLINE)) || - (sp > m->beginp && - !ISWORD(*(sp-1))) ) && - (sp < m->endp && ISWORD(*sp)) ) - { /* yes */ } - else - return(NULL); - break; - case OEOW: - if (( (sp == m->endp && !(m->eflags®_NOTEOL)) || - (sp < m->endp && *sp == '\n' && - (m->g->cflags®_NEWLINE)) || - (sp < m->endp && !ISWORD(*sp)) ) && - (sp > m->beginp && ISWORD(*(sp-1))) ) - { /* yes */ } - else - return(NULL); - break; - case O_QUEST: - break; - case OOR1: /* matches null but needs to skip */ - ss++; - s = m->g->strip[ss]; - do { - assert(OP(s) == OOR2); - ss += OPND(s); - } while (OP(s = m->g->strip[ss]) != O_CH); - /* note that the ss++ gets us past the O_CH */ - break; - default: /* have to make a choice */ - hard = 1; - break; - } - if (!hard) { /* that was it! */ - if (sp != stop) - return(NULL); - return(sp); - } - ss--; /* adjust for the for's final increment */ - - /* the hard stuff */ - AT("hard", sp, stop, ss, stopst); - s = m->g->strip[ss]; - switch (OP(s)) { - case OBACK_: /* the vilest depths */ - i = OPND(s); - assert(0 < i && i <= m->g->nsub); - if (m->pmatch[i].rm_eo == (regoff_t)-1) - return(NULL); - assert(m->pmatch[i].rm_so != (regoff_t)-1); - len = (size_t)(m->pmatch[i].rm_eo - m->pmatch[i].rm_so); - if (len == 0) - return(NULL); - assert(stop - m->beginp >= len); - if (sp > stop - len) - return(NULL); /* not enough left to match */ - ssp = m->offp + (size_t)m->pmatch[i].rm_so; - if (memcmp(sp, ssp, len) != 0) - return(NULL); - while (m->g->strip[ss] != SOP(O_BACK, i)) - ss++; - return(backref(m, sp+len, stop, ss+1, stopst, lev)); - - case OQUEST_: /* to null or not */ - dp = backref(m, sp, stop, ss+1, stopst, lev); - if (dp != NULL) - return(dp); /* not */ - return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev)); - - case OPLUS_: - assert(m->lastpos != NULL); - assert(lev+1 <= m->g->nplus); - m->lastpos[lev+1] = sp; - return(backref(m, sp, stop, ss+1, stopst, lev+1)); - - case O_PLUS: - if (sp == m->lastpos[lev]) /* last pass matched null */ - return(backref(m, sp, stop, ss+1, stopst, lev-1)); - /* try another pass */ - m->lastpos[lev] = sp; - dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev); - if (dp == NULL) - dp = backref(m, sp, stop, ss+1, stopst, lev-1); - return(dp); - - case OCH_: /* find the right one, if any */ - ssub = ss + 1; - esub = ss + OPND(s) - 1; - assert(OP(m->g->strip[esub]) == OOR1); - for (;;) { /* find first matching branch */ - dp = backref(m, sp, stop, ssub, esub, lev); - if (dp != NULL) - return(dp); - /* that one missed, try next one */ - if (OP(m->g->strip[esub]) == O_CH) - return(NULL); /* there is none */ - esub++; - assert(OP(m->g->strip[esub]) == OOR2); - ssub = esub + 1; - esub += OPND(m->g->strip[esub]); - if (OP(m->g->strip[esub]) == OOR2) - esub--; - else - assert(OP(m->g->strip[esub]) == O_CH); - } - - case OLPAREN: /* must undo assignment if rest fails */ - i = OPND(s); - assert(0 < i && i <= m->g->nsub); - offsave = m->pmatch[i].rm_so; - m->pmatch[i].rm_so = sp - m->offp; - dp = backref(m, sp, stop, ss+1, stopst, lev); - if (dp != NULL) - return(dp); - m->pmatch[i].rm_so = offsave; - return(NULL); - - case ORPAREN: /* must undo assignment if rest fails */ - i = OPND(s); - assert(0 < i && i <= m->g->nsub); - offsave = m->pmatch[i].rm_eo; - m->pmatch[i].rm_eo = sp - m->offp; - dp = backref(m, sp, stop, ss+1, stopst, lev); - if (dp != NULL) - return(dp); - m->pmatch[i].rm_eo = offsave; - return(NULL); - - default: /* uh oh */ - assert(nope); - break; - } - - /* "can't happen" */ - assert(nope); - /* NOTREACHED */ - return NULL; -} - -/* - - fast - step through the string at top speed - == static const char *fast(struct match *m, const char *start, \ - == const char *stop, sopno startst, sopno stopst); - */ -static const char * /* where tentative match ended, or NULL */ -fast( - struct match *m, - const char *start, - const char *stop, - sopno startst, - sopno stopst) -{ - states st = m->st; - states fresh = m->fresh; - states tmp = m->tmp; - const char *p = start; - int c = (start == m->beginp) ? OUT : *(start-1); - int lastc; /* previous c */ - int flagch; - size_t i; - const char *coldp; /* last p after which no match was underway */ - - _DIAGASSERT(m != NULL); - _DIAGASSERT(start != NULL); - _DIAGASSERT(stop != NULL); - - CLEAR(st); - SET1(st, startst); - st = step(m->g, startst, stopst, st, NOTHING, st); - ASSIGN(fresh, st); - SP("start", st, *p); - coldp = NULL; - for (;;) { - /* next character */ - lastc = c; - c = (p == m->endp) ? OUT : *p; - if (EQ(st, fresh)) - coldp = p; - - /* is there an EOL and/or BOL between lastc and c? */ - flagch = '\0'; - i = 0; - if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || - (lastc == OUT && !(m->eflags®_NOTBOL)) ) { - flagch = BOL; - i = m->g->nbol; - } - if ( (c == '\n' && m->g->cflags®_NEWLINE) || - (c == OUT && !(m->eflags®_NOTEOL)) ) { - flagch = (flagch == BOL) ? BOLEOL : EOL; - i += m->g->neol; - } - if (i != 0) { - for (; i > 0; i--) - st = step(m->g, startst, stopst, st, flagch, st); - SP("boleol", st, c); - } - - /* how about a word boundary? */ - if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && - (c != OUT && ISWORD(c)) ) { - flagch = BOW; - } - if ( (lastc != OUT && ISWORD(lastc)) && - (flagch == EOL || (c != OUT && !ISWORD(c))) ) { - flagch = EOW; - } - if (flagch == BOW || flagch == EOW) { - st = step(m->g, startst, stopst, st, flagch, st); - SP("boweow", st, c); - } - - /* are we done? */ - if (ISSET(st, stopst) || p == stop) - break; /* NOTE BREAK OUT */ - - /* no, we must deal with this character */ - ASSIGN(tmp, st); - ASSIGN(st, fresh); - assert(c != OUT); - st = step(m->g, startst, stopst, tmp, c, st); - SP("aft", st, c); - assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); - p++; - } - - assert(coldp != NULL); - m->coldp = coldp; - if (ISSET(st, stopst)) - return(p+1); - else - return(NULL); -} - -/* - - slow - step through the string more deliberately - == static const char *slow(struct match *m, const char *start, \ - == const char *stop, sopno startst, sopno stopst); - */ -static const char * /* where it ended */ -slow( - struct match *m, - const char *start, - const char *stop, - sopno startst, - sopno stopst) -{ - states st = m->st; - states empty = m->empty; - states tmp = m->tmp; - const char *p = start; - int c = (start == m->beginp) ? OUT : *(start-1); - int lastc; /* previous c */ - int flagch; - size_t i; - const char *matchp; /* last p at which a match ended */ - - _DIAGASSERT(m != NULL); - _DIAGASSERT(start != NULL); - _DIAGASSERT(stop != NULL); - - AT("slow", start, stop, startst, stopst); - CLEAR(st); - SET1(st, startst); - SP("sstart", st, *p); - st = step(m->g, startst, stopst, st, NOTHING, st); - matchp = NULL; - for (;;) { - /* next character */ - lastc = c; - c = (p == m->endp) ? OUT : *p; - - /* is there an EOL and/or BOL between lastc and c? */ - flagch = '\0'; - i = 0; - if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || - (lastc == OUT && !(m->eflags®_NOTBOL)) ) { - flagch = BOL; - i = m->g->nbol; - } - if ( (c == '\n' && m->g->cflags®_NEWLINE) || - (c == OUT && !(m->eflags®_NOTEOL)) ) { - flagch = (flagch == BOL) ? BOLEOL : EOL; - i += m->g->neol; - } - if (i != 0) { - for (; i > 0; i--) - st = step(m->g, startst, stopst, st, flagch, st); - SP("sboleol", st, c); - } - - /* how about a word boundary? */ - if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && - (c != OUT && ISWORD(c)) ) { - flagch = BOW; - } - if ( (lastc != OUT && ISWORD(lastc)) && - (flagch == EOL || (c != OUT && !ISWORD(c))) ) { - flagch = EOW; - } - if (flagch == BOW || flagch == EOW) { - st = step(m->g, startst, stopst, st, flagch, st); - SP("sboweow", st, c); - } - - /* are we done? */ - if (ISSET(st, stopst)) - matchp = p; - if (EQ(st, empty) || p == stop) - break; /* NOTE BREAK OUT */ - - /* no, we must deal with this character */ - ASSIGN(tmp, st); - ASSIGN(st, empty); - assert(c != OUT); - st = step(m->g, startst, stopst, tmp, c, st); - SP("saft", st, c); - assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); - p++; - } - - return(matchp); -} - - -/* - - step - map set of states reachable before char to set reachable after - == static states step(struct re_guts *g, sopno start, sopno stop, \ - == states bef, int ch, states aft); - == #define BOL (OUT+1) - == #define EOL (BOL+1) - == #define BOLEOL (BOL+2) - == #define NOTHING (BOL+3) - == #define BOW (BOL+4) - == #define EOW (BOL+5) - == #define CODEMAX (BOL+5) // highest code used - == #define NONCHAR(c) ((c) > CHAR_MAX) - == #define NNONCHAR (CODEMAX-CHAR_MAX) - */ -static states -step( - struct re_guts *g, - sopno start, /* start state within strip */ - sopno stop, /* state after stop state within strip */ - states bef, /* states reachable before */ - int ch, /* character or NONCHAR code */ - states aft) /* states already known reachable after */ -{ - cset *cs; - sop s; - sopno pc; - onestate here; /* note, macros know this name */ - sopno look; - int i; - - _DIAGASSERT(g != NULL); - - for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) { - s = g->strip[pc]; - switch (OP(s)) { - case OEND: - assert(pc == stop-1); - break; - case OCHAR: - /* only characters can match */ - assert(!NONCHAR(ch) || ch != (char)OPND(s)); - if (ch == (char)OPND(s)) - FWD(aft, bef, 1); - break; - case OBOL: - if (ch == BOL || ch == BOLEOL) - FWD(aft, bef, 1); - break; - case OEOL: - if (ch == EOL || ch == BOLEOL) - FWD(aft, bef, 1); - break; - case OBOW: - if (ch == BOW) - FWD(aft, bef, 1); - break; - case OEOW: - if (ch == EOW) - FWD(aft, bef, 1); - break; - case OANY: - if (!NONCHAR(ch)) - FWD(aft, bef, 1); - break; - case OANYOF: - cs = &g->sets[OPND(s)]; - if (!NONCHAR(ch) && CHIN(cs, ch)) - FWD(aft, bef, 1); - break; - case OBACK_: /* ignored here */ - case O_BACK: - FWD(aft, aft, 1); - break; - case OPLUS_: /* forward, this is just an empty */ - FWD(aft, aft, 1); - break; - case O_PLUS: /* both forward and back */ - FWD(aft, aft, 1); - i = ISSETBACK(aft, OPND(s)); - BACK(aft, aft, OPND(s)); - if (!i && ISSETBACK(aft, OPND(s))) { - /* oho, must reconsider loop body */ - pc -= OPND(s) + 1; - INIT(here, pc); - } - break; - case OQUEST_: /* two branches, both forward */ - FWD(aft, aft, 1); - FWD(aft, aft, OPND(s)); - break; - case O_QUEST: /* just an empty */ - FWD(aft, aft, 1); - break; - case OLPAREN: /* not significant here */ - case ORPAREN: - FWD(aft, aft, 1); - break; - case OCH_: /* mark the first two branches */ - FWD(aft, aft, 1); - assert(OP(g->strip[pc+OPND(s)]) == OOR2); - FWD(aft, aft, OPND(s)); - break; - case OOR1: /* done a branch, find the O_CH */ - if (ISSTATEIN(aft, here)) { - for (look = 1; - OP(s = g->strip[pc+look]) != O_CH; - look += OPND(s)) - assert(OP(s) == OOR2); - FWD(aft, aft, look); - } - break; - case OOR2: /* propagate OCH_'s marking */ - FWD(aft, aft, 1); - if (OP(g->strip[pc+OPND(s)]) != O_CH) { - assert(OP(g->strip[pc+OPND(s)]) == OOR2); - FWD(aft, aft, OPND(s)); - } - break; - case O_CH: /* just empty */ - FWD(aft, aft, 1); - break; - default: /* ooooops... */ - assert(nope); - break; - } - } - - return(aft); -} - -#ifdef REDEBUG -/* - - print - print a set of states - == #ifdef REDEBUG - == static void print(struct match *m, char *caption, states st, \ - == int ch, FILE *d); - == #endif - */ -static void -print( - struct match *m, - char *caption, - states st, - int ch, - FILE *d) -{ - struct re_guts *g = m->g; - int i; - int first = 1; - - _DIAGASSERT(m != NULL); - _DIAGASSERT(caption != NULL); - - if (!(m->eflags®_TRACE)) - return; - - _DIAGASSERT(d != NULL); - - fprintf(d, "%s", caption); - if (ch != '\0') - fprintf(d, " %s", pchar(ch)); - for (i = 0; i < g->nstates; i++) - if (ISSET(st, i)) { - fprintf(d, "%s%d", (first) ? "\t" : ", ", i); - first = 0; - } - fprintf(d, "\n"); -} - -/* - - at - print current situation - == #ifdef REDEBUG - == static void at(struct match *m, char *title, char *start, char *stop, \ - == sopno startst, sopno stopst); - == #endif - */ -static void -at( - struct match *m, - char *title, - char *start, - char *stop, - sopno startst, - sopno stopst) -{ - - _DIAGASSERT(m != NULL); - _DIAGASSERT(title != NULL); - _DIAGASSERT(start != NULL); - _DIAGASSERT(stop != NULL); - - if (!(m->eflags®_TRACE)) - return; - - printf("%s %s-", title, pchar(*start)); - printf("%s ", pchar(*stop)); - printf("%ld-%ld\n", (long)startst, (long)stopst); -} - -#ifndef PCHARDONE -#define PCHARDONE /* never again */ -/* - - pchar - make a character printable - == #ifdef REDEBUG - == static char *pchar(int ch); - == #endif - * - * Is this identical to regchar() over in debug.c? Well, yes. But a - * duplicate here avoids having a debugging-capable regexec.o tied to - * a matching debug.o, and this is convenient. It all disappears in - * the non-debug compilation anyway, so it doesn't matter much. - */ -static char * /* -> representation */ -pchar( - int ch) -{ - static char pbuf[10]; - - if (isprint(ch) || ch == ' ') - (void)snprintf(pbuf, sizeof pbuf, "%c", ch); - else - (void)snprintf(pbuf, sizeof pbuf, "\\%o", ch); - return(pbuf); -} -#endif -#endif - -#undef matcher -#undef fast -#undef slow -#undef dissect -#undef backref -#undef step -#undef print -#undef at -#undef match -#undef nope diff --git a/libc/upstream-netbsd/libc/regex/regcomp.c b/libc/upstream-netbsd/libc/regex/regcomp.c deleted file mode 100644 index 2644a22..0000000 --- a/libc/upstream-netbsd/libc/regex/regcomp.c +++ /dev/null @@ -1,1944 +0,0 @@ -/* $NetBSD: regcomp.c,v 1.33 2012/03/13 21:13:43 christos Exp $ */ - -/*- - * 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. 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. - * - * @(#)regcomp.c 8.5 (Berkeley) 3/20/94 - */ - -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * - * 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. - * - * @(#)regcomp.c 8.5 (Berkeley) 3/20/94 - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94"; -#else -__RCSID("$NetBSD: regcomp.c,v 1.33 2012/03/13 21:13:43 christos Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __weak_alias -__weak_alias(regcomp,_regcomp) -#endif - -#include "utils.h" -#include "regex2.h" - -#include "cclass.h" -#include "cname.h" - -/* - * parse structure, passed up and down to avoid global variables and - * other clumsinesses - */ -struct parse { - const char *next; /* next character in RE */ - const char *end; /* end of string (-> NUL normally) */ - int error; /* has an error been seen? */ - sop *strip; /* malloced strip */ - sopno ssize; /* malloced strip size (allocated) */ - sopno slen; /* malloced strip length (used) */ - size_t ncsalloc; /* number of csets allocated */ - struct re_guts *g; -# define NPAREN 10 /* we need to remember () 1-9 for back refs */ - sopno pbegin[NPAREN]; /* -> ( ([0] unused) */ - sopno pend[NPAREN]; /* -> ) ([0] unused) */ -}; - -/* ========= begin header generated by ./mkh ========= */ -#ifdef __cplusplus -extern "C" { -#endif - -/* === regcomp.c === */ -static void p_ere(struct parse *p, int stop, size_t reclimit); -static void p_ere_exp(struct parse *p, size_t reclimit); -static void p_str(struct parse *p); -static void p_bre(struct parse *p, int end1, int end2, size_t reclimit); -static int p_simp_re(struct parse *p, int starordinary, size_t reclimit); -static int p_count(struct parse *p); -static void p_bracket(struct parse *p); -static void p_b_term(struct parse *p, cset *cs); -static void p_b_cclass(struct parse *p, cset *cs); -static void p_b_eclass(struct parse *p, cset *cs); -static char p_b_symbol(struct parse *p); -static char p_b_coll_elem(struct parse *p, int endc); -static int othercase(int ch); -static void bothcases(struct parse *p, int ch); -static void ordinary(struct parse *p, int ch); -static void nonnewline(struct parse *p); -static void repeat(struct parse *p, sopno start, int from, int to, size_t reclimit); -static int seterr(struct parse *p, int e); -static cset *allocset(struct parse *p); -static void freeset(struct parse *p, cset *cs); -static sopno freezeset(struct parse *p, cset *cs); -static int firstch(struct parse *p, cset *cs); -static int nch(struct parse *p, cset *cs); -static void mcadd(struct parse *p, cset *cs, const char *cp); -#if 0 -static void mcsub(cset *cs, char *cp); -static int mcin(cset *cs, char *cp); -static char *mcfind(cset *cs, char *cp); -#endif -static void mcinvert(struct parse *p, cset *cs); -static void mccase(struct parse *p, cset *cs); -static int isinsets(struct re_guts *g, int c); -static int samesets(struct re_guts *g, int c1, int c2); -static void categorize(struct parse *p, struct re_guts *g); -static sopno dupl(struct parse *p, sopno start, sopno finish); -static void doemit(struct parse *p, sop op, sopno opnd); -static void doinsert(struct parse *p, sop op, sopno opnd, sopno pos); -static void dofwd(struct parse *p, sopno pos, sopno value); -static int enlarge(struct parse *p, sopno size); -static void stripsnug(struct parse *p, struct re_guts *g); -static void findmust(struct parse *p, struct re_guts *g); -static sopno pluscount(struct parse *p, struct re_guts *g); - -#ifdef __cplusplus -} -#endif -/* ========= end header generated by ./mkh ========= */ - -static char nuls[10]; /* place to point scanner in event of error */ - -/* - * macros for use with parse structure - * BEWARE: these know that the parse structure is named `p' !!! - */ -#define PEEK() (*p->next) -#define PEEK2() (*(p->next+1)) -#define MORE() (p->next < p->end) -#define MORE2() (p->next+1 < p->end) -#define SEE(c) (MORE() && PEEK() == (c)) -#define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b)) -#define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0) -#define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0) -#define NEXT() (p->next++) -#define NEXT2() (p->next += 2) -#define NEXTn(n) (p->next += (n)) -#define GETNEXT() (*p->next++) -#define SETERROR(e) seterr(p, (e)) -#define REQUIRE(co, e) (void) ((co) || SETERROR(e)) -#define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) -#define MUSTEAT(c, e) (void) (REQUIRE(MORE() && GETNEXT() == (c), e)) -#define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) -#define EMIT(op, sopnd) doemit(p, (sop)(op), sopnd) -#define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos) -#define AHEAD(pos) dofwd(p, pos, HERE()-(pos)) -#define ASTERN(sop, pos) EMIT(sop, HERE()-pos) -#define HERE() (p->slen) -#define THERE() (p->slen - 1) -#define THERETHERE() (p->slen - 2) -#define DROP(n) (p->slen -= (n)) - -#ifndef NDEBUG -static int never = 0; /* for use in asserts; shuts lint up */ -#else -#define never 0 /* some s have bugs too */ -#endif - -#define MEMLIMIT 0x8000000 -#define MEMSIZE(p) \ - ((p)->ncsalloc / CHAR_BIT * (p)->g->csetsize + \ - (p)->ncsalloc * sizeof(cset) + \ - (p)->ssize * sizeof(sop)) -#define RECLIMIT 256 - -/* - - regcomp - interface for parser and compilation - = extern int regcomp(regex_t *, const char *, int); - = #define REG_BASIC 0000 - = #define REG_EXTENDED 0001 - = #define REG_ICASE 0002 - = #define REG_NOSUB 0004 - = #define REG_NEWLINE 0010 - = #define REG_NOSPEC 0020 - = #define REG_PEND 0040 - = #define REG_DUMP 0200 - */ -int /* 0 success, otherwise REG_something */ -regcomp( - regex_t *preg, - const char *pattern, - int cflags) -{ - struct parse pa; - struct re_guts *g; - struct parse *p = &pa; - int i; - size_t len; -#ifdef REDEBUG -# define GOODFLAGS(f) (f) -#else -# define GOODFLAGS(f) ((f)&~REG_DUMP) -#endif - - _DIAGASSERT(preg != NULL); - _DIAGASSERT(pattern != NULL); - - cflags = GOODFLAGS(cflags); - if ((cflags®_EXTENDED) && (cflags®_NOSPEC)) - return(REG_INVARG); - - if (cflags®_PEND) { - if (preg->re_endp < pattern) - return(REG_INVARG); - len = preg->re_endp - pattern; - } else - len = strlen(pattern); - - /* do the mallocs early so failure handling is easy */ - g = (struct re_guts *)malloc(sizeof(struct re_guts) + - (NC-1)*sizeof(cat_t)); - if (g == NULL) - return(REG_ESPACE); - p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ - p->strip = malloc(p->ssize * sizeof(sop)); - p->slen = 0; - if (p->strip == NULL) { - free(g); - return(REG_ESPACE); - } - - /* set things up */ - p->g = g; - p->next = pattern; - p->end = p->next + len; - p->error = 0; - p->ncsalloc = 0; - for (i = 0; i < NPAREN; i++) { - p->pbegin[i] = 0; - p->pend[i] = 0; - } - g->csetsize = NC; - g->sets = NULL; - g->setbits = NULL; - g->ncsets = 0; - g->cflags = cflags; - g->iflags = 0; - g->nbol = 0; - g->neol = 0; - g->must = NULL; - g->mlen = 0; - g->nsub = 0; - g->ncategories = 1; /* category 0 is "everything else" */ - g->categories = &g->catspace[-(CHAR_MIN)]; - (void) memset((char *)g->catspace, 0, NC*sizeof(cat_t)); - g->backrefs = 0; - - /* do it */ - EMIT(OEND, 0); - g->firststate = THERE(); - if (cflags®_EXTENDED) - p_ere(p, OUT, 0); - else if (cflags®_NOSPEC) - p_str(p); - else - p_bre(p, OUT, OUT, 0); - EMIT(OEND, 0); - g->laststate = THERE(); - - /* tidy up loose ends and fill things in */ - categorize(p, g); - stripsnug(p, g); - findmust(p, g); - g->nplus = pluscount(p, g); - g->magic = MAGIC2; - preg->re_nsub = g->nsub; - preg->re_g = g; - preg->re_magic = MAGIC1; -#ifndef REDEBUG - /* not debugging, so can't rely on the assert() in regexec() */ - if (g->iflags&BAD) - SETERROR(REG_ASSERT); -#endif - - /* win or lose, we're done */ - if (p->error != 0) /* lose */ - regfree(preg); - return(p->error); -} - -/* - - p_ere - ERE parser top level, concatenation and alternation - == static void p_ere(struct parse *p, int stop, size_t reclimit); - */ -static void -p_ere( - struct parse *p, - int stop, /* character this ERE should end at */ - size_t reclimit) -{ - char c; - sopno prevback = 0; /* pacify gcc */ - sopno prevfwd = 0; /* pacify gcc */ - sopno conc; - int first = 1; /* is this the first alternative? */ - - _DIAGASSERT(p != NULL); - - if (reclimit++ > RECLIMIT || p->error == REG_ESPACE) { - p->error = REG_ESPACE; - return; - } - - for (;;) { - /* do a bunch of concatenated expressions */ - conc = HERE(); - while (MORE() && (c = PEEK()) != '|' && c != stop) - p_ere_exp(p, reclimit); - REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */ - - if (!EAT('|')) - break; /* NOTE BREAK OUT */ - - if (first) { - INSERT(OCH_, conc); /* offset is wrong */ - prevfwd = conc; - prevback = conc; - first = 0; - } - ASTERN(OOR1, prevback); - prevback = THERE(); - AHEAD(prevfwd); /* fix previous offset */ - prevfwd = HERE(); - EMIT(OOR2, 0); /* offset is very wrong */ - } - - if (!first) { /* tail-end fixups */ - AHEAD(prevfwd); - ASTERN(O_CH, prevback); - } - - assert(!MORE() || SEE(stop)); -} - -/* - - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op - == static void p_ere_exp(struct parse *p, size_t reclimit); - */ -static void -p_ere_exp( - struct parse *p, - size_t reclimit) -{ - char c; - sopno pos; - int count; - int count2; - sopno subno; - int wascaret = 0; - - _DIAGASSERT(p != NULL); - - assert(MORE()); /* caller should have ensured this */ - c = GETNEXT(); - - pos = HERE(); - switch (c) { - case '(': - REQUIRE(MORE(), REG_EPAREN); - p->g->nsub++; - subno = p->g->nsub; - if (subno < NPAREN) - p->pbegin[subno] = HERE(); - EMIT(OLPAREN, subno); - if (!SEE(')')) - p_ere(p, ')', reclimit); - if (subno < NPAREN) { - p->pend[subno] = HERE(); - assert(p->pend[subno] != 0); - } - EMIT(ORPAREN, subno); - MUSTEAT(')', REG_EPAREN); - break; -#ifndef POSIX_MISTAKE - case ')': /* happens only if no current unmatched ( */ - /* - * You may ask, why the ifndef? Because I didn't notice - * this until slightly too late for 1003.2, and none of the - * other 1003.2 regular-expression reviewers noticed it at - * all. So an unmatched ) is legal POSIX, at least until - * we can get it fixed. - */ - SETERROR(REG_EPAREN); - break; -#endif - case '^': - EMIT(OBOL, 0); - p->g->iflags |= USEBOL; - p->g->nbol++; - wascaret = 1; - break; - case '$': - EMIT(OEOL, 0); - p->g->iflags |= USEEOL; - p->g->neol++; - break; - case '|': - SETERROR(REG_EMPTY); - break; - case '*': - case '+': - case '?': - SETERROR(REG_BADRPT); - break; - case '.': - if (p->g->cflags®_NEWLINE) - nonnewline(p); - else - EMIT(OANY, 0); - break; - case '[': - p_bracket(p); - break; - case '\\': - REQUIRE(MORE(), REG_EESCAPE); - c = GETNEXT(); - ordinary(p, c); - break; - case '{': /* okay as ordinary except if digit follows */ - REQUIRE(!MORE() || !isdigit((unsigned char)PEEK()), REG_BADRPT); - /* FALLTHROUGH */ - default: - ordinary(p, c); - break; - } - - if (!MORE()) - return; - c = PEEK(); - /* we call { a repetition if followed by a digit */ - if (!( c == '*' || c == '+' || c == '?' || - (c == '{' && MORE2() && isdigit((unsigned char)PEEK2())) )) - return; /* no repetition, we're done */ - NEXT(); - - REQUIRE(!wascaret, REG_BADRPT); - switch (c) { - case '*': /* implemented as +? */ - /* this case does not require the (y|) trick, noKLUDGE */ - INSERT(OPLUS_, pos); - ASTERN(O_PLUS, pos); - INSERT(OQUEST_, pos); - ASTERN(O_QUEST, pos); - break; - case '+': - INSERT(OPLUS_, pos); - ASTERN(O_PLUS, pos); - break; - case '?': - /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ - INSERT(OCH_, pos); /* offset slightly wrong */ - ASTERN(OOR1, pos); /* this one's right */ - AHEAD(pos); /* fix the OCH_ */ - EMIT(OOR2, 0); /* offset very wrong... */ - AHEAD(THERE()); /* ...so fix it */ - ASTERN(O_CH, THERETHERE()); - break; - case '{': - count = p_count(p); - if (EAT(',')) { - if (isdigit((unsigned char)PEEK())) { - count2 = p_count(p); - REQUIRE(count <= count2, REG_BADBR); - } else /* single number with comma */ - count2 = INFINITY; - } else /* just a single number */ - count2 = count; - repeat(p, pos, count, count2, 0); - if (!EAT('}')) { /* error heuristics */ - while (MORE() && PEEK() != '}') - NEXT(); - REQUIRE(MORE(), REG_EBRACE); - SETERROR(REG_BADBR); - } - break; - } - - if (!MORE()) - return; - c = PEEK(); - if (!( c == '*' || c == '+' || c == '?' || - (c == '{' && MORE2() && isdigit((unsigned char)PEEK2())) ) ) - return; - SETERROR(REG_BADRPT); -} - -/* - - p_str - string (no metacharacters) "parser" - == static void p_str(struct parse *p); - */ -static void -p_str( - struct parse *p) -{ - - _DIAGASSERT(p != NULL); - - REQUIRE(MORE(), REG_EMPTY); - while (MORE()) - ordinary(p, GETNEXT()); -} - -/* - - p_bre - BRE parser top level, anchoring and concatenation - == static void p_bre(struct parse *p, int end1, \ - == int end2, size_t reclimit); - * Giving end1 as OUT essentially eliminates the end1/end2 check. - * - * This implementation is a bit of a kludge, in that a trailing $ is first - * taken as an ordinary character and then revised to be an anchor. The - * only undesirable side effect is that '$' gets included as a character - * category in such cases. This is fairly harmless; not worth fixing. - * The amount of lookahead needed to avoid this kludge is excessive. - */ -static void -p_bre( - struct parse *p, - int end1, /* first terminating character */ - int end2, /* second terminating character */ - size_t reclimit) -{ - sopno start; - int first = 1; /* first subexpression? */ - int wasdollar = 0; - - _DIAGASSERT(p != NULL); - - if (reclimit++ > RECLIMIT || p->error == REG_ESPACE) { - p->error = REG_ESPACE; - return; - } - - start = HERE(); - - if (EAT('^')) { - EMIT(OBOL, 0); - p->g->iflags |= USEBOL; - p->g->nbol++; - } - while (MORE() && !SEETWO(end1, end2)) { - wasdollar = p_simp_re(p, first, reclimit); - first = 0; - } - if (wasdollar) { /* oops, that was a trailing anchor */ - DROP(1); - EMIT(OEOL, 0); - p->g->iflags |= USEEOL; - p->g->neol++; - } - - REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */ -} - -/* - - p_simp_re - parse a simple RE, an atom possibly followed by a repetition - == static int p_simp_re(struct parse *p, int starordinary, size_t reclimit); - */ -static int /* was the simple RE an unbackslashed $? */ -p_simp_re( - struct parse *p, - int starordinary, /* is a leading * an ordinary character? */ - size_t reclimit) -{ - int c; - int count; - int count2; - sopno pos, i; - sopno subno; -# define BACKSL (1<g->cflags®_NEWLINE) - nonnewline(p); - else - EMIT(OANY, 0); - break; - case '[': - p_bracket(p); - break; - case BACKSL|'{': - SETERROR(REG_BADRPT); - break; - case BACKSL|'(': - p->g->nsub++; - subno = p->g->nsub; - if (subno < NPAREN) - p->pbegin[subno] = HERE(); - EMIT(OLPAREN, subno); - /* the MORE here is an error heuristic */ - if (MORE() && !SEETWO('\\', ')')) - p_bre(p, '\\', ')', reclimit); - if (subno < NPAREN) { - p->pend[subno] = HERE(); - assert(p->pend[subno] != 0); - } - EMIT(ORPAREN, subno); - REQUIRE(EATTWO('\\', ')'), REG_EPAREN); - break; - case BACKSL|')': /* should not get here -- must be user */ - case BACKSL|'}': - SETERROR(REG_EPAREN); - break; - case BACKSL|'1': - case BACKSL|'2': - case BACKSL|'3': - case BACKSL|'4': - case BACKSL|'5': - case BACKSL|'6': - case BACKSL|'7': - case BACKSL|'8': - case BACKSL|'9': - i = (c&~BACKSL) - '0'; - assert(i < NPAREN); - if (p->pend[i] != 0) { - assert(i <= p->g->nsub); - EMIT(OBACK_, i); - assert(p->pbegin[i] != 0); - assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); - assert(OP(p->strip[p->pend[i]]) == ORPAREN); - (void) dupl(p, p->pbegin[i]+1, p->pend[i]); - EMIT(O_BACK, i); - } else - SETERROR(REG_ESUBREG); - p->g->backrefs = 1; - break; - case '*': - REQUIRE(starordinary, REG_BADRPT); - /* FALLTHROUGH */ - default: - ordinary(p, c &~ BACKSL); - break; - } - - if (EAT('*')) { /* implemented as +? */ - /* this case does not require the (y|) trick, noKLUDGE */ - INSERT(OPLUS_, pos); - ASTERN(O_PLUS, pos); - INSERT(OQUEST_, pos); - ASTERN(O_QUEST, pos); - } else if (EATTWO('\\', '{')) { - count = p_count(p); - if (EAT(',')) { - if (MORE() && isdigit((unsigned char)PEEK())) { - count2 = p_count(p); - REQUIRE(count <= count2, REG_BADBR); - } else /* single number with comma */ - count2 = INFINITY; - } else /* just a single number */ - count2 = count; - repeat(p, pos, count, count2, 0); - if (!EATTWO('\\', '}')) { /* error heuristics */ - while (MORE() && !SEETWO('\\', '}')) - NEXT(); - REQUIRE(MORE(), REG_EBRACE); - SETERROR(REG_BADBR); - } - } else if (c == (unsigned char)'$') /* $ (but not \$) ends it */ - return(1); - - return(0); -} - -/* - - p_count - parse a repetition count - == static int p_count(struct parse *p); - */ -static int /* the value */ -p_count( - struct parse *p) -{ - int count = 0; - int ndigits = 0; - - _DIAGASSERT(p != NULL); - - while (MORE() && isdigit((unsigned char)PEEK()) && count <= DUPMAX) { - count = count*10 + (GETNEXT() - '0'); - ndigits++; - } - - REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR); - return(count); -} - -/* - - p_bracket - parse a bracketed character list - == static void p_bracket(struct parse *p); - * - * Note a significant property of this code: if the allocset() did SETERROR, - * no set operations are done. - */ -static void -p_bracket( - struct parse *p) -{ - cset *cs; - int invert = 0; - _DIAGASSERT(p != NULL); - - cs = allocset(p); - if (cs == NULL) - return; - - /* Dept of Truly Sickening Special-Case Kludges */ - if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", - (size_t)6) == 0) { - EMIT(OBOW, 0); - NEXTn(6); - return; - } - if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", - (size_t)6) == 0) { - EMIT(OEOW, 0); - NEXTn(6); - return; - } - - if (EAT('^')) - invert++; /* make note to invert set at end */ - if (EAT(']')) - CHadd(cs, ']'); - else if (EAT('-')) - CHadd(cs, '-'); - while (MORE() && PEEK() != ']' && !SEETWO('-', ']')) - p_b_term(p, cs); - if (EAT('-')) - CHadd(cs, '-'); - MUSTEAT(']', REG_EBRACK); - - if (p->error != 0) /* don't mess things up further */ - return; - - if (p->g->cflags®_ICASE) { - ssize_t i; - int ci; - - for (i = p->g->csetsize - 1; i >= 0; i--) - if (CHIN(cs, i) && isalpha(i)) { - ci = othercase((int)i); - if (ci != i) - CHadd(cs, ci); - } - if (cs->multis != NULL) - mccase(p, cs); - } - if (invert) { - ssize_t i; - - for (i = p->g->csetsize - 1; i >= 0; i--) - if (CHIN(cs, i)) - CHsub(cs, (int)i); - else - CHadd(cs, (int)i); - if (p->g->cflags®_NEWLINE) - CHsub(cs, '\n'); - if (cs->multis != NULL) - mcinvert(p, cs); - } - - assert(cs->multis == NULL); /* xxx */ - - if (nch(p, cs) == 1) { /* optimize singleton sets */ - ordinary(p, firstch(p, cs)); - freeset(p, cs); - } else - EMIT(OANYOF, freezeset(p, cs)); -} - -/* - - p_b_term - parse one term of a bracketed character list - == static void p_b_term(struct parse *p, cset *cs); - */ -static void -p_b_term( - struct parse *p, - cset *cs) -{ - char c; - char start, finish; - int i; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(cs != NULL); - - /* classify what we've got */ - switch ((MORE()) ? PEEK() : '\0') { - case '[': - c = (MORE2()) ? PEEK2() : '\0'; - break; - - case '-': - SETERROR(REG_ERANGE); - return; /* NOTE RETURN */ - - default: - c = '\0'; - break; - } - - switch (c) { - case ':': /* character class */ - NEXT2(); - REQUIRE(MORE(), REG_EBRACK); - c = PEEK(); - REQUIRE(c != '-' && c != ']', REG_ECTYPE); - p_b_cclass(p, cs); - REQUIRE(MORE(), REG_EBRACK); - REQUIRE(EATTWO(':', ']'), REG_ECTYPE); - break; - case '=': /* equivalence class */ - NEXT2(); - REQUIRE(MORE(), REG_EBRACK); - c = PEEK(); - REQUIRE(c != '-' && c != ']', REG_ECOLLATE); - p_b_eclass(p, cs); - REQUIRE(MORE(), REG_EBRACK); - REQUIRE(EATTWO('=', ']'), REG_ECOLLATE); - break; - default: /* symbol, ordinary character, or range */ -/* xxx revision needed for multichar stuff */ - start = p_b_symbol(p); - if (SEE('-') && MORE2() && PEEK2() != ']') { - /* range */ - NEXT(); - if (EAT('-')) - finish = '-'; - else - finish = p_b_symbol(p); - } else - finish = start; -/* xxx what about signed chars here... */ - REQUIRE(start <= finish, REG_ERANGE); - for (i = start; i <= finish; i++) - CHadd(cs, i); - break; - } -} - -/* - - p_b_cclass - parse a character-class name and deal with it - == static void p_b_cclass(struct parse *p, cset *cs); - */ -static void -p_b_cclass( - struct parse *p, - cset *cs) -{ - const char *sp; - const struct cclass *cp; - size_t len; - const char *u; - char c; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(cs != NULL); - - sp = p->next; - - while (MORE() && isalpha((unsigned char)PEEK())) - NEXT(); - len = p->next - sp; - for (cp = cclasses; cp->name != NULL; cp++) - if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') - break; - if (cp->name == NULL) { - /* oops, didn't find it */ - SETERROR(REG_ECTYPE); - return; - } - - u = cp->chars; - while ((c = *u++) != '\0') - CHadd(cs, c); - for (u = cp->multis; *u != '\0'; u += strlen(u) + 1) - MCadd(p, cs, u); -} - -/* - - p_b_eclass - parse an equivalence-class name and deal with it - == static void p_b_eclass(struct parse *p, cset *cs); - * - * This implementation is incomplete. xxx - */ -static void -p_b_eclass( - struct parse *p, - cset *cs) -{ - char c; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(cs != NULL); - - c = p_b_coll_elem(p, '='); - CHadd(cs, c); -} - -/* - - p_b_symbol - parse a character or [..]ed multicharacter collating symbol - == static char p_b_symbol(struct parse *p); - */ -static char /* value of symbol */ -p_b_symbol( - struct parse *p) -{ - char value; - - _DIAGASSERT(p != NULL); - - REQUIRE(MORE(), REG_EBRACK); - if (!EATTWO('[', '.')) - return(GETNEXT()); - - /* collating symbol */ - value = p_b_coll_elem(p, '.'); - REQUIRE(EATTWO('.', ']'), REG_ECOLLATE); - return(value); -} - -/* - - p_b_coll_elem - parse a collating-element name and look it up - == static char p_b_coll_elem(struct parse *p, int endc); - */ -static char /* value of collating element */ -p_b_coll_elem( - struct parse *p, - int endc) /* name ended by endc,']' */ -{ - const char *sp; - const struct cname *cp; - size_t len; - - _DIAGASSERT(p != NULL); - - sp = p->next; - - while (MORE() && !SEETWO(endc, ']')) - NEXT(); - if (!MORE()) { - SETERROR(REG_EBRACK); - return(0); - } - len = p->next - sp; - for (cp = cnames; cp->name != NULL; cp++) - if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') - return(cp->code); /* known name */ - if (len == 1) - return(*sp); /* single character */ - SETERROR(REG_ECOLLATE); /* neither */ - return(0); -} - -/* - - othercase - return the case counterpart of an alphabetic - == static int othercase(int ch); - */ -static int /* if no counterpart, return ch */ -othercase( - int ch) -{ - assert(isalpha(ch)); - if (isupper(ch)) - return(tolower(ch)); - else if (islower(ch)) - return(toupper(ch)); - else /* peculiar, but could happen */ - return(ch); -} - -/* - - bothcases - emit a dualcase version of a two-case character - == static void bothcases(struct parse *p, int ch); - * - * Boy, is this implementation ever a kludge... - */ -static void -bothcases( - struct parse *p, - int ch) -{ - const char *oldnext; - const char *oldend; - char bracket[3]; - - _DIAGASSERT(p != NULL); - - oldnext = p->next; - oldend = p->end; - - assert(othercase(ch) != ch); /* p_bracket() would recurse */ - p->next = bracket; - p->end = bracket+2; - bracket[0] = ch; - bracket[1] = ']'; - bracket[2] = '\0'; - p_bracket(p); - assert(p->next == bracket+2); - p->next = oldnext; - p->end = oldend; -} - -/* - - ordinary - emit an ordinary character - == static void ordinary(struct parse *p, int ch); - */ -static void -ordinary( - struct parse *p, - int ch) -{ - cat_t *cap; - - _DIAGASSERT(p != NULL); - - cap = p->g->categories; - if ((p->g->cflags®_ICASE) && isalpha((unsigned char) ch) - && othercase((unsigned char) ch) != (unsigned char) ch) - bothcases(p, (unsigned char) ch); - else { - EMIT(OCHAR, (sopno)(unsigned char)ch); - if (cap[ch] == 0) { - _DIAGASSERT(__type_fit(unsigned char, - p->g->ncategories + 1)); - cap[ch] = (unsigned char)p->g->ncategories++; - } - } -} - -/* - - nonnewline - emit REG_NEWLINE version of OANY - == static void nonnewline(struct parse *p); - * - * Boy, is this implementation ever a kludge... - */ -static void -nonnewline( - struct parse *p) -{ - const char *oldnext; - const char *oldend; - char bracket[4]; - - _DIAGASSERT(p != NULL); - - oldnext = p->next; - oldend = p->end; - - p->next = bracket; - p->end = bracket+3; - bracket[0] = '^'; - bracket[1] = '\n'; - bracket[2] = ']'; - bracket[3] = '\0'; - p_bracket(p); - assert(p->next == bracket+3); - p->next = oldnext; - p->end = oldend; -} - -/* - - repeat - generate code for a bounded repetition, recursively if needed - == static void repeat(struct parse *p, sopno start, int from, int to, - == size_t reclimit); - */ -static void -repeat( - struct parse *p, - sopno start, /* operand from here to end of strip */ - int from, /* repeated from this number */ - int to, /* to this number of times (maybe INFINITY) */ - size_t reclimit) -{ - sopno finish; -# define N 2 -# define INF 3 -# define REP(f, t) ((f)*8 + (t)) -# define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N) - sopno copy; - - _DIAGASSERT(p != NULL); - - if (reclimit++ > RECLIMIT) - p->error = REG_ESPACE; - if (p->error) - return; - - finish = HERE(); - - assert(from <= to); - - switch (REP(MAP(from), MAP(to))) { - case REP(0, 0): /* must be user doing this */ - DROP(finish-start); /* drop the operand */ - break; - case REP(0, 1): /* as x{1,1}? */ - case REP(0, N): /* as x{1,n}? */ - case REP(0, INF): /* as x{1,}? */ - /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ - INSERT(OCH_, start); /* offset is wrong... */ - repeat(p, start+1, 1, to, reclimit); - ASTERN(OOR1, start); - AHEAD(start); /* ... fix it */ - EMIT(OOR2, 0); - AHEAD(THERE()); - ASTERN(O_CH, THERETHERE()); - break; - case REP(1, 1): /* trivial case */ - /* done */ - break; - case REP(1, N): /* as x?x{1,n-1} */ - /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ - INSERT(OCH_, start); - ASTERN(OOR1, start); - AHEAD(start); - EMIT(OOR2, 0); /* offset very wrong... */ - AHEAD(THERE()); /* ...so fix it */ - ASTERN(O_CH, THERETHERE()); - copy = dupl(p, start+1, finish+1); - assert(copy == finish+4); - repeat(p, copy, 1, to-1, reclimit); - break; - case REP(1, INF): /* as x+ */ - INSERT(OPLUS_, start); - ASTERN(O_PLUS, start); - break; - case REP(N, N): /* as xx{m-1,n-1} */ - copy = dupl(p, start, finish); - repeat(p, copy, from-1, to-1, reclimit); - break; - case REP(N, INF): /* as xx{n-1,INF} */ - copy = dupl(p, start, finish); - repeat(p, copy, from-1, to, reclimit); - break; - default: /* "can't happen" */ - SETERROR(REG_ASSERT); /* just in case */ - break; - } -} - -/* - - seterr - set an error condition - == static int seterr(struct parse *p, int e); - */ -static int /* useless but makes type checking happy */ -seterr( - struct parse *p, - int e) -{ - - _DIAGASSERT(p != NULL); - - if (p->error == 0) /* keep earliest error condition */ - p->error = e; - p->next = nuls; /* try to bring things to a halt */ - p->end = nuls; - return(0); /* make the return value well-defined */ -} - -/* - - allocset - allocate a set of characters for [] - == static cset *allocset(struct parse *p); - */ -static cset * -allocset( - struct parse *p) -{ - size_t no; - size_t nc; - size_t nbytes; - cset *cs; - size_t css; - size_t i; - - _DIAGASSERT(p != NULL); - - no = p->g->ncsets++; - css = (size_t)p->g->csetsize; - if (no >= p->ncsalloc) { /* need another column of space */ - p->ncsalloc += CHAR_BIT; - nc = p->ncsalloc; - assert(nc % CHAR_BIT == 0); - nbytes = nc / CHAR_BIT * css; - if (MEMSIZE(p) > MEMLIMIT) - goto oomem; - if (p->g->sets == NULL) - p->g->sets = malloc(nc * sizeof(cset)); - else - p->g->sets = realloc(p->g->sets, nc * sizeof(cset)); - if (p->g->setbits == NULL) - p->g->setbits = malloc(nbytes); - else { - p->g->setbits = realloc(p->g->setbits, nbytes); - /* xxx this isn't right if setbits is now NULL */ - for (i = 0; i < no; i++) - p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT); - } - if (p->g->sets != NULL && p->g->setbits != NULL) - (void) memset((char *)p->g->setbits + (nbytes - css), - 0, css); - else { -oomem: - no = 0; - SETERROR(REG_ESPACE); - /* caller's responsibility not to do set ops */ - return NULL; - } - } - - cs = &p->g->sets[no]; - cs->ptr = p->g->setbits + css*((no)/CHAR_BIT); - cs->mask = 1 << (unsigned int)((no) % CHAR_BIT); - cs->hash = 0; - cs->smultis = 0; - cs->multis = NULL; - - return(cs); -} - -/* - - freeset - free a now-unused set - == static void freeset(struct parse *p, cset *cs); - */ -static void -freeset( - struct parse *p, - cset *cs) -{ - size_t i; - cset *top; - size_t css; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(cs != NULL); - - top = &p->g->sets[p->g->ncsets]; - css = (size_t)p->g->csetsize; - - for (i = 0; i < css; i++) - CHsub(cs, (int)i); - if (cs == top-1) /* recover only the easy case */ - p->g->ncsets--; -} - -/* - - freezeset - final processing on a set of characters - == static int freezeset(struct parse *p, cset *cs); - * - * The main task here is merging identical sets. This is usually a waste - * of time (although the hash code minimizes the overhead), but can win - * big if REG_ICASE is being used. REG_ICASE, by the way, is why the hash - * is done using addition rather than xor -- all ASCII [aA] sets xor to - * the same value! - */ -static sopno /* set number */ -freezeset( - struct parse *p, - cset *cs) -{ - uch h; - size_t i; - cset *top; - cset *cs2; - size_t css; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(cs != NULL); - - h = cs->hash; - top = &p->g->sets[p->g->ncsets]; - css = (size_t)p->g->csetsize; - - /* look for an earlier one which is the same */ - for (cs2 = &p->g->sets[0]; cs2 < top; cs2++) - if (cs2->hash == h && cs2 != cs) { - /* maybe */ - for (i = 0; i < css; i++) - if (!!CHIN(cs2, i) != !!CHIN(cs, i)) - break; /* no */ - if (i == css) - break; /* yes */ - } - - if (cs2 < top) { /* found one */ - freeset(p, cs); - cs = cs2; - } - - return (sopno)(cs - p->g->sets); -} - -/* - - firstch - return first character in a set (which must have at least one) - == static int firstch(struct parse *p, cset *cs); - */ -static int /* character; there is no "none" value */ -firstch( - struct parse *p, - cset *cs) -{ - size_t i; - size_t css; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(cs != NULL); - - css = (size_t)p->g->csetsize; - - for (i = 0; i < css; i++) - if (CHIN(cs, i)) - return((char)i); - assert(never); - return(0); /* arbitrary */ -} - -/* - - nch - number of characters in a set - == static int nch(struct parse *p, cset *cs); - */ -static int -nch( - struct parse *p, - cset *cs) -{ - size_t i; - size_t css; - int n = 0; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(cs != NULL); - - css = (size_t)p->g->csetsize; - - for (i = 0; i < css; i++) - if (CHIN(cs, i)) - n++; - return(n); -} - -/* - - mcadd - add a collating element to a cset - == static void mcadd(struct parse *p, cset *cs, \ - == char *cp); - */ -static void -mcadd( - struct parse *p, - cset *cs, - const char *cp) -{ - size_t oldend; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(cs != NULL); - _DIAGASSERT(cp != NULL); - - oldend = cs->smultis; - - cs->smultis += strlen(cp) + 1; - if (cs->multis == NULL) - cs->multis = malloc(cs->smultis); - else - cs->multis = realloc(cs->multis, cs->smultis); - if (cs->multis == NULL) { - SETERROR(REG_ESPACE); - return; - } - - (void) strcpy(cs->multis + oldend - 1, cp); - cs->multis[cs->smultis - 1] = '\0'; -} - -#if 0 -/* - - mcsub - subtract a collating element from a cset - == static void mcsub(cset *cs, char *cp); - */ -static void -mcsub( - cset *cs, - char *cp) -{ - char *fp; - size_t len; - - _DIAGASSERT(cs != NULL); - _DIAGASSERT(cp != NULL); - - fp = mcfind(cs, cp); - len = strlen(fp); - - assert(fp != NULL); - (void) memmove(fp, fp + len + 1, - cs->smultis - (fp + len + 1 - cs->multis)); - cs->smultis -= len; - - if (cs->smultis == 0) { - free(cs->multis); - cs->multis = NULL; - return; - } - - cs->multis = realloc(cs->multis, cs->smultis); - assert(cs->multis != NULL); -} - -/* - - mcin - is a collating element in a cset? - == static int mcin(cset *cs, char *cp); - */ -static int -mcin( - cset *cs, - char *cp) -{ - - _DIAGASSERT(cs != NULL); - _DIAGASSERT(cp != NULL); - - return(mcfind(cs, cp) != NULL); -} - -/* - - mcfind - find a collating element in a cset - == static char *mcfind(cset *cs, char *cp); - */ -static char * -mcfind( - cset *cs, - char *cp) -{ - char *p; - - _DIAGASSERT(cs != NULL); - _DIAGASSERT(cp != NULL); - - if (cs->multis == NULL) - return(NULL); - for (p = cs->multis; *p != '\0'; p += strlen(p) + 1) - if (strcmp(cp, p) == 0) - return(p); - return(NULL); -} -#endif - -/* - - mcinvert - invert the list of collating elements in a cset - == static void mcinvert(struct parse *p, cset *cs); - * - * This would have to know the set of possibilities. Implementation - * is deferred. - */ -/* ARGSUSED */ -static void -mcinvert( - struct parse *p, - cset *cs) -{ - - _DIAGASSERT(p != NULL); - _DIAGASSERT(cs != NULL); - - assert(cs->multis == NULL); /* xxx */ -} - -/* - - mccase - add case counterparts of the list of collating elements in a cset - == static void mccase(struct parse *p, cset *cs); - * - * This would have to know the set of possibilities. Implementation - * is deferred. - */ -/* ARGSUSED */ -static void -mccase( - struct parse *p, - cset *cs) -{ - - _DIAGASSERT(p != NULL); - _DIAGASSERT(cs != NULL); - - assert(cs->multis == NULL); /* xxx */ -} - -/* - - isinsets - is this character in any sets? - == static int isinsets(struct re_guts *g, int c); - */ -static int /* predicate */ -isinsets( - struct re_guts *g, - int c) -{ - uch *col; - size_t i; - size_t ncols; - unsigned uc = (unsigned char)c; - - _DIAGASSERT(g != NULL); - - if (g->setbits == NULL) - return 0; - - ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; - - for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) - if (col[uc] != 0) - return(1); - return(0); -} - -/* - - samesets - are these two characters in exactly the same sets? - == static int samesets(struct re_guts *g, int c1, int c2); - */ -static int /* predicate */ -samesets( - struct re_guts *g, - int c1, - int c2) -{ - uch *col; - size_t i; - size_t ncols; - unsigned uc1 = (unsigned char)c1; - unsigned uc2 = (unsigned char)c2; - - _DIAGASSERT(g != NULL); - - ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; - - for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) - if (col[uc1] != col[uc2]) - return(0); - return(1); -} - -/* - - categorize - sort out character categories - == static void categorize(struct parse *p, struct re_guts *g); - */ -static void -categorize( - struct parse *p, - struct re_guts *g) -{ - cat_t *cats; - int c; - int c2; - cat_t cat; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(g != NULL); - - cats = g->categories; - - /* avoid making error situations worse */ - if (p->error != 0) - return; - - for (c = CHAR_MIN; c <= CHAR_MAX; c++) - if (cats[c] == 0 && isinsets(g, c)) { - _DIAGASSERT(__type_fit(unsigned char, - g->ncategories + 1)); - cat = g->ncategories++; - cats[c] = cat; - for (c2 = c+1; c2 <= CHAR_MAX; c2++) - if (cats[c2] == 0 && samesets(g, c, c2)) - cats[c2] = cat; - } -} - -/* - - dupl - emit a duplicate of a bunch of sops - == static sopno dupl(struct parse *p, sopno start, sopno finish); - */ -static sopno /* start of duplicate */ -dupl( - struct parse *p, - sopno start, /* from here */ - sopno finish) /* to this less one */ -{ - sopno ret; - sopno len = finish - start; - - _DIAGASSERT(p != NULL); - - ret = HERE(); - - assert(finish >= start); - if (len == 0) - return(ret); - if (!enlarge(p, p->ssize + len))/* this many unexpected additions */ - return ret; - (void)memcpy(p->strip + p->slen, p->strip + start, - (size_t)len * sizeof(sop)); - p->slen += len; - return(ret); -} - -/* - - doemit - emit a strip operator - == static void doemit(struct parse *p, sop op, size_t opnd); - * - * It might seem better to implement this as a macro with a function as - * hard-case backup, but it's just too big and messy unless there are - * some changes to the data structures. Maybe later. - */ -static void -doemit( - struct parse *p, - sop op, - sopno opnd) -{ - _DIAGASSERT(p != NULL); - - /* avoid making error situations worse */ - if (p->error != 0) - return; - - /* deal with oversize operands ("can't happen", more or less) */ - assert(opnd < 1<slen >= p->ssize) - if (!enlarge(p, (p->ssize+1) / 2 * 3)) /* +50% */ - return; - - /* finally, it's all reduced to the easy case */ - p->strip[p->slen++] = (sop)SOP(op, opnd); -} - -/* - - doinsert - insert a sop into the strip - == static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos); - */ -static void -doinsert( - struct parse *p, - sop op, - sopno opnd, - sopno pos) -{ - sopno sn; - sop s; - int i; - - _DIAGASSERT(p != NULL); - - /* avoid making error situations worse */ - if (p->error != 0) - return; - - sn = HERE(); - EMIT(op, opnd); /* do checks, ensure space */ - assert(HERE() == sn+1); - s = p->strip[sn]; - - /* adjust paren pointers */ - assert(pos > 0); - for (i = 1; i < NPAREN; i++) { - if (p->pbegin[i] >= pos) { - p->pbegin[i]++; - } - if (p->pend[i] >= pos) { - p->pend[i]++; - } - } - - memmove(&p->strip[pos+1], &p->strip[pos], (HERE()-pos-1)*sizeof(sop)); - p->strip[pos] = s; -} - -/* - - dofwd - complete a forward reference - == static void dofwd(struct parse *p, sopno pos, sop value); - */ -static void -dofwd( - struct parse *p, - sopno pos, - sopno value) -{ - - _DIAGASSERT(p != NULL); - - /* avoid making error situations worse */ - if (p->error != 0) - return; - - assert(value < 1<strip[pos] = (sop)(OP(p->strip[pos]) | value); -} - -/* - - enlarge - enlarge the strip - == static void enlarge(struct parse *p, sopno size); - */ -static int -enlarge( - struct parse *p, - sopno size) -{ - sop *sp; - sopno osize; - - _DIAGASSERT(p != NULL); - - if (p->ssize >= size) - return 1; - - osize = p->ssize; - p->ssize = size; - if (MEMSIZE(p) > MEMLIMIT) - goto oomem; - sp = realloc(p->strip, p->ssize * sizeof(sop)); - if (sp == NULL) { -oomem: - p->ssize = osize; - SETERROR(REG_ESPACE); - return 0; - } - p->strip = sp; - return 1; -} - -/* - - stripsnug - compact the strip - == static void stripsnug(struct parse *p, struct re_guts *g); - */ -static void -stripsnug( - struct parse *p, - struct re_guts *g) -{ - - _DIAGASSERT(p != NULL); - _DIAGASSERT(g != NULL); - - g->nstates = p->slen; - g->strip = realloc(p->strip, p->slen * sizeof(sop)); - if (g->strip == NULL) { - SETERROR(REG_ESPACE); - g->strip = p->strip; - } -} - -/* - - findmust - fill in must and mlen with longest mandatory literal string - == static void findmust(struct parse *p, struct re_guts *g); - * - * This algorithm could do fancy things like analyzing the operands of | - * for common subsequences. Someday. This code is simple and finds most - * of the interesting cases. - * - * Note that must and mlen got initialized during setup. - */ -static void -findmust( - struct parse *p, - struct re_guts *g) -{ - sop *scan; - sop *start = NULL; - sop *newstart = NULL; - sopno newlen; - sop s; - char *cp; - sopno i; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(g != NULL); - - /* avoid making error situations worse */ - if (p->error != 0) - return; - - /* find the longest OCHAR sequence in strip */ - newlen = 0; - scan = g->strip + 1; - do { - s = *scan++; - switch (OP(s)) { - case OCHAR: /* sequence member */ - if (newlen == 0) /* new sequence */ - newstart = scan - 1; - newlen++; - break; - case OPLUS_: /* things that don't break one */ - case OLPAREN: - case ORPAREN: - break; - case OQUEST_: /* things that must be skipped */ - case OCH_: - scan--; - do { - scan += OPND(s); - s = *scan; - /* assert() interferes w debug printouts */ - if (OP(s) != O_QUEST && OP(s) != O_CH && - OP(s) != OOR2) { - g->iflags |= BAD; - return; - } - } while (OP(s) != O_QUEST && OP(s) != O_CH); - /* FALLTHROUGH */ - default: /* things that break a sequence */ - if (newlen > g->mlen) { /* ends one */ - start = newstart; - g->mlen = newlen; - } - newlen = 0; - break; - } - } while (OP(s) != OEND); - - if (start == NULL) - g->mlen = 0; - - if (g->mlen == 0) /* there isn't one */ - return; - - /* turn it into a character string */ - g->must = malloc((size_t)g->mlen + 1); - if (g->must == NULL) { /* argh; just forget it */ - g->mlen = 0; - return; - } - cp = g->must; - scan = start; - for (i = g->mlen; i > 0; i--) { - while (OP(s = *scan++) != OCHAR) - continue; - assert(cp < g->must + g->mlen); - *cp++ = (char)OPND(s); - } - assert(cp == g->must + g->mlen); - *cp++ = '\0'; /* just on general principles */ -} - -/* - - pluscount - count + nesting - == static sopno pluscount(struct parse *p, struct re_guts *g); - */ -static sopno /* nesting depth */ -pluscount( - struct parse *p, - struct re_guts *g) -{ - sop *scan; - sop s; - sopno plusnest = 0; - sopno maxnest = 0; - - _DIAGASSERT(p != NULL); - _DIAGASSERT(g != NULL); - - if (p->error != 0) - return(0); /* there may not be an OEND */ - - scan = g->strip + 1; - do { - s = *scan++; - switch (OP(s)) { - case OPLUS_: - plusnest++; - break; - case O_PLUS: - if (plusnest > maxnest) - maxnest = plusnest; - plusnest--; - break; - } - } while (OP(s) != OEND); - if (plusnest != 0) - g->iflags |= BAD; - return(maxnest); -} diff --git a/libc/upstream-netbsd/libc/regex/regerror.c b/libc/upstream-netbsd/libc/regex/regerror.c deleted file mode 100644 index e00d7c0..0000000 --- a/libc/upstream-netbsd/libc/regex/regerror.c +++ /dev/null @@ -1,223 +0,0 @@ -/* $NetBSD: regerror.c,v 1.23 2007/02/09 23:44:18 junyoung Exp $ */ - -/*- - * 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. 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 - */ - -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * - * 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 - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94"; -#else -__RCSID("$NetBSD: regerror.c,v 1.23 2007/02/09 23:44:18 junyoung Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __weak_alias -__weak_alias(regerror,_regerror) -#endif - -#include "utils.h" - -/* ========= begin header generated by ./mkh ========= */ -#ifdef __cplusplus -extern "C" { -#endif - -/* === regerror.c === */ -static const char *regatoi(const regex_t *preg, char *localbuf, size_t buflen); - -#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_ATOI 255 // convert name to number (!) - = #define REG_ITOA 0400 // convert number to name (!) - */ -static const struct rerr { - int code; - const char *name; - const char *explain; -} rerrs[] = { - { REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match" }, - { REG_BADPAT, "REG_BADPAT", "invalid regular expression" }, - { REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element" }, - { REG_ECTYPE, "REG_ECTYPE", "invalid character class" }, - { REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)" }, - { REG_ESUBREG, "REG_ESUBREG", "invalid backreference number" }, - { REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced" }, - { REG_EPAREN, "REG_EPAREN", "parentheses not balanced" }, - { REG_EBRACE, "REG_EBRACE", "braces not balanced" }, - { REG_BADBR, "REG_BADBR", "invalid repetition count(s)" }, - { REG_ERANGE, "REG_ERANGE", "invalid character range" }, - { REG_ESPACE, "REG_ESPACE", "out of memory" }, - { REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid" }, - { REG_EMPTY, "REG_EMPTY", "empty (sub)expression" }, - { REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug" }, - { REG_INVARG, "REG_INVARG", "invalid argument to regex routine" }, - { 0, "", "*** unknown regexp error code ***" } -}; - -/* - * regerror - the interface to error numbers - * extern size_t regerror(int, const regex_t *, char *, size_t); - */ -/* ARGSUSED */ -size_t -regerror( - int errcode, - const regex_t *preg, - char *errbuf, - size_t errbuf_size) -{ - const struct rerr *r; - size_t len; - int target = errcode &~ REG_ITOA; - const char *s; - char convbuf[50]; - - _DIAGASSERT(errcode != REG_ATOI || preg != NULL); - _DIAGASSERT(errbuf != NULL); - - if (errcode == REG_ATOI) - s = regatoi(preg, convbuf, sizeof convbuf); - else { - for (r = rerrs; r->code != 0; r++) - if (r->code == target) - break; - - if (errcode & REG_ITOA) { - if (r->code != 0) { - (void)strlcpy(convbuf, r->name, sizeof convbuf); - } else - (void)snprintf(convbuf, sizeof convbuf, - "REG_0x%x", target); - s = convbuf; - } else - s = r->explain; - } - - len = strlen(s) + 1; - if (errbuf_size > 0) - (void)strlcpy(errbuf, s, errbuf_size); - - return(len); -} - -/* - * regatoi - internal routine to implement REG_ATOI - * static const char *regatoi(const regex_t *preg, char *localbuf, - * size_t buflen); - */ -static const char * -regatoi( - const regex_t *preg, - char *localbuf, - size_t buflen) -{ - const 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"; - - (void)snprintf(localbuf, buflen, "%d", r->code); - return localbuf; -} diff --git a/libc/upstream-netbsd/libc/regex/regex2.h b/libc/upstream-netbsd/libc/regex/regex2.h deleted file mode 100644 index 7c877ee..0000000 --- a/libc/upstream-netbsd/libc/regex/regex2.h +++ /dev/null @@ -1,209 +0,0 @@ -/* $NetBSD: regex2.h,v 1.13 2011/10/09 18:23:00 christos Exp $ */ - -/*- - * 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. 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. - * - * @(#)regex2.h 8.4 (Berkeley) 3/20/94 - */ - -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * - * 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. - * - * @(#)regex2.h 8.4 (Berkeley) 3/20/94 - */ - -/* - * First, the stuff that ends up in the outside-world include file - = typedef off_t regoff_t; - = typedef struct { - = int re_magic; - = size_t re_nsub; // number of parenthesized subexpressions - = const char *re_endp; // end pointer for REG_PEND - = struct re_guts *re_g; // none of your business :-) - = } regex_t; - = typedef struct { - = regoff_t rm_so; // start of match - = regoff_t rm_eo; // end of match - = } regmatch_t; - */ -/* - * internals of regex_t - */ -#define MAGIC1 ((('r'^0200)<<8) | 'e') - -/* - * The internal representation is a *strip*, a sequence of - * operators ending with an endmarker. (Some terminology etc. is a - * historical relic of earlier versions which used multiple strips.) - * Certain oddities in the representation are there to permit running - * the machinery backwards; in particular, any deviation from sequential - * flow must be marked at both its source and its destination. Some - * fine points: - * - * - OPLUS_ and O_PLUS are *inside* the loop they create. - * - OQUEST_ and O_QUEST are *outside* the bypass they create. - * - OCH_ and O_CH are *outside* the multi-way branch they create, while - * OOR1 and OOR2 are respectively the end and the beginning of one of - * the branches. Note that there is an implicit OOR2 following OCH_ - * and an implicit OOR1 preceding O_CH. - * - * In state representations, an operator's bit is on to signify a state - * immediately *preceding* "execution" of that operator. - */ -typedef u_int32_t sop; /* strip operator */ -typedef size_t sopno; -#define OPRMASK ((u_int32_t)0xf8000000UL) -#define OPDMASK ((u_int32_t)0x07ffffffUL) -#define OPSHIFT ((unsigned)27) -#define OP(n) ((n)&OPRMASK) -#define OPND(n) ((int)((n)&OPDMASK)) -#define SOP(op, opnd) ((op)|(opnd)) - -#define OPC(n) (((u_int32_t)(n))< uch [csetsize] */ - uch mask; /* bit within array */ - uch hash; /* hash code */ - size_t smultis; - char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */ -} cset; -/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */ -#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c)) -#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c)) -#define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask) -#define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */ -#define MCsub(p, cs, cp) mcsub(p, cs, cp) -#define MCin(p, cs, cp) mcin(p, cs, cp) - -/* stuff for character categories */ -typedef unsigned char cat_t; - -/* - * main compiled-expression structure - */ -struct re_guts { - int magic; -# define MAGIC2 ((('R'^0200)<<8)|'E') - sop *strip; /* malloced area for strip */ - size_t csetsize; /* number of bits in a cset vector */ - size_t ncsets; /* number of csets in use */ - cset *sets; /* -> cset [ncsets] */ - uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */ - int cflags; /* copy of regcomp() cflags argument */ - sopno nstates; /* = number of sops */ - sopno firststate; /* the initial OEND (normally 0) */ - sopno laststate; /* the final OEND */ - int iflags; /* internal flags */ -# define USEBOL 01 /* used ^ */ -# define USEEOL 02 /* used $ */ -# define BAD 04 /* something wrong */ - size_t nbol; /* number of ^ used */ - size_t neol; /* number of $ used */ - size_t ncategories; /* how many character categories */ - cat_t *categories; /* ->catspace[-CHAR_MIN] */ - char *must; /* match must contain this string */ - size_t mlen; /* length of must */ - size_t nsub; /* copy of re_nsub */ - int backrefs; /* does it use back references? */ - sopno nplus; /* how deep does it nest +s? */ - /* catspace must be last */ - cat_t catspace[1]; /* actually [NC] */ -}; - -/* misc utilities */ -#define OUT (CHAR_MAX+1) /* a non-character value */ -#define ISWORD(c) (isalnum((unsigned char)c) || (c) == '_') diff --git a/libc/upstream-netbsd/libc/regex/regexec.c b/libc/upstream-netbsd/libc/regex/regexec.c deleted file mode 100644 index f16e0b6..0000000 --- a/libc/upstream-netbsd/libc/regex/regexec.c +++ /dev/null @@ -1,234 +0,0 @@ -/* $NetBSD: regexec.c,v 1.22 2012/03/13 21:13:43 christos Exp $ */ - -/*- - * 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. 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. - * - * @(#)regexec.c 8.3 (Berkeley) 3/20/94 - */ - -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * - * 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. - * - * @(#)regexec.c 8.3 (Berkeley) 3/20/94 - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94"; -#else -__RCSID("$NetBSD: regexec.c,v 1.22 2012/03/13 21:13:43 christos Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -/* - * the outer shell of regexec() - * - * This file includes engine.c *twice*, after muchos fiddling with the - * macros that code uses. This lets the same code operate on two different - * representations for state sets. - */ -#include "namespace.h" -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __weak_alias -__weak_alias(regexec,_regexec) -#endif - -#include "utils.h" -#include "regex2.h" - -/* macros for manipulating states, small version */ -#define states unsigned long -#define states1 unsigned long /* for later use in regexec() decision */ -#define CLEAR(v) ((v) = 0) -#define SET0(v, n) ((v) &= ~((unsigned long)1 << (n))) -#define SET1(v, n) ((v) |= (unsigned long)1 << (n)) -#define ISSET(v, n) (((v) & ((unsigned long)1 << (n))) != 0) -#define ASSIGN(d, s) ((d) = (s)) -#define EQ(a, b) ((a) == (b)) -#define STATEVARS int dummy /* dummy version */ -#define STATESETUP(m, n) /* nothing */ -#define STATETEARDOWN(m) /* nothing */ -#define SETUP(v) ((v) = 0) -#define onestate unsigned long -#define INIT(o, n) ((o) = (unsigned long)1 << (n)) -#define INC(o) ((o) <<= 1) -#define ISSTATEIN(v, o) (((v) & (o)) != 0) -/* some abbreviations; note that some of these know variable names! */ -/* do "if I'm here, I can also be there" etc without branches */ -#define FWD(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) << (n)) -#define BACK(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) >> (n)) -#define ISSETBACK(v, n) (((v) & ((unsigned long)here >> (n))) != 0) -/* function names */ -#define SNAMES /* engine.c looks after details */ - -#include "engine.c" - -/* now undo things */ -#undef states -#undef CLEAR -#undef SET0 -#undef SET1 -#undef ISSET -#undef ASSIGN -#undef EQ -#undef STATEVARS -#undef STATESETUP -#undef STATETEARDOWN -#undef SETUP -#undef onestate -#undef INIT -#undef INC -#undef ISSTATEIN -#undef FWD -#undef BACK -#undef ISSETBACK -#undef SNAMES - -/* macros for manipulating states, large version */ -#define states char * -#define CLEAR(v) memset(v, 0, (size_t)m->g->nstates) -#define SET0(v, n) ((v)[n] = 0) -#define SET1(v, n) ((v)[n] = 1) -#define ISSET(v, n) ((v)[n]) -#define ASSIGN(d, s) memcpy(d, s, (size_t)m->g->nstates) -#define EQ(a, b) (memcmp(a, b, (size_t)m->g->nstates) == 0) -#define STATEVARS int vn; char *space -#define STATESETUP(m, nv) \ - if (((m)->space = malloc((size_t)((nv)*(m)->g->nstates))) == NULL) \ - return(REG_ESPACE); \ - else \ - (m)->vn = 0 - -#define STATETEARDOWN(m) { free((m)->space); m->space = NULL; } -#define SETUP(v) ((v) = &m->space[(size_t)(m->vn++ * m->g->nstates)]) -#define onestate int -#define INIT(o, n) ((o) = (int)(n)) -#define INC(o) ((o)++) -#define ISSTATEIN(v, o) ((v)[o]) -/* some abbreviations; note that some of these know variable names! */ -/* do "if I'm here, I can also be there" etc without branches */ -#define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here]) -#define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here]) -#define ISSETBACK(v, n) ((v)[here - (n)]) -/* function names */ -#define LNAMES /* flag */ - -#include "engine.c" - -/* - - regexec - interface for matching - = extern int regexec(const regex_t *, const char *, size_t, \ - = regmatch_t [], int); - = #define REG_NOTBOL 00001 - = #define REG_NOTEOL 00002 - = #define REG_STARTEND 00004 - = #define REG_TRACE 00400 // tracing of execution - = #define REG_LARGE 01000 // force large representation - = #define REG_BACKR 02000 // force use of backref code - * - * We put this here so we can exploit knowledge of the state representation - * when choosing which matcher to call. Also, by this point the matchers - * have been prototyped. - */ -int /* 0 success, REG_NOMATCH failure */ -regexec( - const regex_t *preg, - const char *string, - size_t nmatch, - regmatch_t pmatch[], - int eflags) -{ - struct re_guts *g = preg->re_g; - char *s; -#ifdef REDEBUG -# define GOODFLAGS(f) (f) -#else -# define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND)) -#endif - - _DIAGASSERT(preg != NULL); - _DIAGASSERT(string != NULL); - - if (preg->re_magic != MAGIC1 || g->magic != MAGIC2) - return(REG_BADPAT); - assert(!(g->iflags&BAD)); - if (g->iflags&BAD) /* backstop for no-debug case */ - return(REG_BADPAT); - eflags = GOODFLAGS(eflags); - - s = __UNCONST(string); - - if (g->nstates <= (sopno)(CHAR_BIT*sizeof(states1)) && !(eflags®_LARGE)) - return(smatcher(g, s, nmatch, pmatch, eflags)); - else - return(lmatcher(g, s, nmatch, pmatch, eflags)); -} diff --git a/libc/upstream-netbsd/libc/regex/regfree.c b/libc/upstream-netbsd/libc/regex/regfree.c deleted file mode 100644 index ce011ea..0000000 --- a/libc/upstream-netbsd/libc/regex/regfree.c +++ /dev/null @@ -1,129 +0,0 @@ -/* $NetBSD: regfree.c,v 1.15 2007/02/09 23:44:18 junyoung Exp $ */ - -/*- - * 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. 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. - * - * @(#)regfree.c 8.3 (Berkeley) 3/20/94 - */ - -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * - * 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. - * - * @(#)regfree.c 8.3 (Berkeley) 3/20/94 - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94"; -#else -__RCSID("$NetBSD: regfree.c,v 1.15 2007/02/09 23:44:18 junyoung Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include - -#include -#include -#include -#include - -#ifdef __weak_alias -__weak_alias(regfree,_regfree) -#endif - -#include "utils.h" -#include "regex2.h" - -/* - - regfree - free everything - = extern void regfree(regex_t *); - */ -void -regfree( - regex_t *preg) -{ - struct re_guts *g; - - _DIAGASSERT(preg != NULL); - - _DIAGASSERT(preg->re_magic == MAGIC1); - if (preg->re_magic != MAGIC1) /* oops */ - return; /* nice to complain, but hard */ - - g = preg->re_g; - if (g == NULL || g->magic != MAGIC2) /* oops again */ - return; - preg->re_magic = 0; /* mark it invalid */ - g->magic = 0; /* mark it invalid */ - - if (g->strip != NULL) - free(g->strip); - if (g->sets != NULL) - free(g->sets); - if (g->setbits != NULL) - free(g->setbits); - if (g->must != NULL) - free(g->must); - free(g); -} diff --git a/libc/upstream-netbsd/libc/regex/utils.h b/libc/upstream-netbsd/libc/regex/utils.h deleted file mode 100644 index 762caee..0000000 --- a/libc/upstream-netbsd/libc/regex/utils.h +++ /dev/null @@ -1,91 +0,0 @@ -/* $NetBSD: utils.h,v 1.6 2003/08/07 16:43:21 agc Exp $ */ - -/*- - * 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. 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 - */ - -/*- - * Copyright (c) 1992, 1993, 1994 Henry Spencer. - * - * 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 - */ - -/* 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/libc/upstream-netbsd/libc/stdio/getdelim.c b/libc/upstream-netbsd/libc/stdio/getdelim.c deleted file mode 100644 index acce376..0000000 --- a/libc/upstream-netbsd/libc/stdio/getdelim.c +++ /dev/null @@ -1,154 +0,0 @@ -/* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */ - -/* - * Copyright (c) 2009 The NetBSD Foundation, Inc. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Roy Marples. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__RCSID("$NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $"); - -#include "namespace.h" - -#include - -#include -#include -#include -#include -#include -#include - -#include "reentrant.h" -#include "local.h" - -#ifdef __weak_alias -__weak_alias(getdelim, _getdelim) -#endif - -/* Minimum buffer size we create. - * This should allow config files to fit into our power of 2 buffer growth - * without the need for a realloc. */ -#define MINBUF 128 - -ssize_t -__getdelim(char **__restrict buf, size_t *__restrict buflen, - int sep, FILE *__restrict fp) -{ - unsigned char *p; - size_t len, newlen, off; - char *newb; - - _DIAGASSERT(fp != NULL); - - if (buf == NULL || buflen == NULL) { - errno = EINVAL; - goto error; - } - - /* If buf is NULL, we have to assume a size of zero */ - if (*buf == NULL) - *buflen = 0; - - _SET_ORIENTATION(fp, -1); - off = 0; - do { - /* If the input buffer is empty, refill it */ - if (fp->_r <= 0 && __srefill(fp)) { - if (__sferror(fp)) - goto error; - /* No error, so EOF. */ - break; - } - - /* Scan through looking for the separator */ - p = memchr(fp->_p, sep, (size_t)fp->_r); - if (p == NULL) - len = fp->_r; - else - len = (p - fp->_p) + 1; - - newlen = off + len; - /* Ensure we can handle it */ - if (newlen < off || newlen > SSIZE_MAX) { - errno = EOVERFLOW; - goto error; - } - newlen++; /* reserve space for the NULL terminator */ - if (newlen > *buflen) { - if (newlen < MINBUF) - newlen = MINBUF; - if (!powerof2(newlen)) { - /* Grow the buffer to the next power of 2 */ - newlen--; - newlen |= newlen >> 1; - newlen |= newlen >> 2; - newlen |= newlen >> 4; - newlen |= newlen >> 8; - newlen |= newlen >> 16; -#if SIZE_T_MAX > 0xffffffffU - newlen |= newlen >> 32; -#endif - newlen++; - } - - newb = realloc(*buf, newlen); - if (newb == NULL) - goto error; - *buf = newb; - *buflen = newlen; - } - - (void)memcpy((*buf + off), fp->_p, len); - /* Safe, len is never greater than what fp->_r can fit. */ - fp->_r -= (int)len; - fp->_p += (int)len; - off += len; - } while (p == NULL); - - /* POSIX demands we return -1 on EOF. */ - if (off == 0) - return -1; - - if (*buf != NULL) - *(*buf + off) = '\0'; - return off; - -error: - fp->_flags |= __SERR; - return -1; -} - -ssize_t -getdelim(char **__restrict buf, size_t *__restrict buflen, - int sep, FILE *__restrict fp) -{ - ssize_t n; - - FLOCKFILE(fp); - n = __getdelim(buf, buflen, sep, fp); - FUNLOCKFILE(fp); - return n; -} diff --git a/libc/upstream-netbsd/libc/stdio/getline.c b/libc/upstream-netbsd/libc/stdio/getline.c deleted file mode 100644 index e5d4bab..0000000 --- a/libc/upstream-netbsd/libc/stdio/getline.c +++ /dev/null @@ -1,45 +0,0 @@ -/* $NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $ */ - -/* - * Copyright (c) 2009 The NetBSD Foundation, Inc. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Roy Marples. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__RCSID("$NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $"); - -#include "namespace.h" - -#include - -#ifdef __weak_alias -__weak_alias(getline, _getline) -#endif - -ssize_t -getline(char **__restrict buf, size_t *__restrict buflen, FILE *__restrict fp) -{ - return getdelim(buf, buflen, '\n', fp); -} diff --git a/libc/upstream-netbsd/libc/stdlib/_rand48.c b/libc/upstream-netbsd/libc/stdlib/_rand48.c deleted file mode 100644 index 0468026..0000000 --- a/libc/upstream-netbsd/libc/stdlib/_rand48.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $NetBSD: _rand48.c,v 1.7 2005/06/12 05:21:27 lukem Exp $ */ - -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _rand48.c,v 1.7 2005/06/12 05:21:27 lukem Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include - -#include "rand48.h" - -unsigned short __rand48_seed[3] = { - RAND48_SEED_0, - RAND48_SEED_1, - RAND48_SEED_2 -}; -unsigned short __rand48_mult[3] = { - RAND48_MULT_0, - RAND48_MULT_1, - RAND48_MULT_2 -}; -unsigned short __rand48_add = RAND48_ADD; - -void -__dorand48(unsigned short xseed[3]) -{ - unsigned long accu; - unsigned short temp[2]; - - _DIAGASSERT(xseed != NULL); - - accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0] + - (unsigned long) __rand48_add; - temp[0] = (unsigned short) accu; /* lower 16 bits */ - accu >>= sizeof(unsigned short) * 8; - accu += (unsigned long) __rand48_mult[0] * (unsigned long) xseed[1] + - (unsigned long) __rand48_mult[1] * (unsigned long) xseed[0]; - temp[1] = (unsigned short) accu; /* middle 16 bits */ - accu >>= sizeof(unsigned short) * 8; - accu += __rand48_mult[0] * xseed[2] + __rand48_mult[1] * xseed[1] + __rand48_mult[2] * xseed[0]; - xseed[0] = temp[0]; - xseed[1] = temp[1]; - xseed[2] = (unsigned short) accu; -} diff --git a/libc/upstream-netbsd/libc/stdlib/bsearch.c b/libc/upstream-netbsd/libc/stdlib/bsearch.c deleted file mode 100644 index 2b0e0d8..0000000 --- a/libc/upstream-netbsd/libc/stdlib/bsearch.c +++ /dev/null @@ -1,85 +0,0 @@ -/* $NetBSD: bsearch.c,v 1.15 2012/03/04 20:01:45 christos Exp $ */ - -/* - * 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. 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) -#if 0 -static char sccsid[] = "@(#)bsearch.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: bsearch.c,v 1.15 2012/03/04 20:01:45 christos Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include -#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(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; - - _DIAGASSERT(key != NULL); - _DIAGASSERT(base0 != NULL || nmemb == 0); - _DIAGASSERT(compar != NULL); - - for (lim = nmemb; lim != 0; lim >>= 1) { - p = base + (lim >> 1) * size; - cmp = (*compar)(key, p); - if (cmp == 0) - return __UNCONST(p); - if (cmp > 0) { /* key > p: move right */ - base = (const char *)p + size; - lim--; - } /* else move left */ - } - return (NULL); -} diff --git a/libc/upstream-netbsd/libc/stdlib/div.c b/libc/upstream-netbsd/libc/stdlib/div.c deleted file mode 100644 index f3bd32f..0000000 --- a/libc/upstream-netbsd/libc/stdlib/div.c +++ /dev/null @@ -1,81 +0,0 @@ -/* $NetBSD: div.c,v 1.8 2012/06/25 22:32:45 abs Exp $ */ - -/* - * 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. 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) -#if 0 -static char sccsid[] = "@(#)div.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: div.c,v 1.8 2012/06/25 22:32:45 abs Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include /* div_t */ - -div_t -div(int num, int 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/libc/upstream-netbsd/libc/stdlib/drand48.c b/libc/upstream-netbsd/libc/stdlib/drand48.c deleted file mode 100644 index 6fba607..0000000 --- a/libc/upstream-netbsd/libc/stdlib/drand48.c +++ /dev/null @@ -1,32 +0,0 @@ -/* $NetBSD: drand48.c,v 1.6 2005/06/12 05:21:28 lukem Exp $ */ - -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: drand48.c,v 1.6 2005/06/12 05:21:28 lukem Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include "rand48.h" - -#ifdef __weak_alias -__weak_alias(drand48,_drand48) -#endif - -double -drand48(void) -{ - return erand48(__rand48_seed); -} diff --git a/libc/upstream-netbsd/libc/stdlib/erand48.c b/libc/upstream-netbsd/libc/stdlib/erand48.c deleted file mode 100644 index f1d8b4d..0000000 --- a/libc/upstream-netbsd/libc/stdlib/erand48.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $NetBSD: erand48.c,v 1.9 2006/03/22 20:52:16 drochner Exp $ */ - -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: erand48.c,v 1.9 2006/03/22 20:52:16 drochner Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" - -#include -#include - -#include "rand48.h" - -#ifdef __weak_alias -__weak_alias(erand48,_erand48) -#endif - -double -erand48(unsigned short xseed[3]) -{ - - _DIAGASSERT(xseed != NULL); - - __dorand48(xseed); - return ldexp((double) xseed[0], -48) + - ldexp((double) xseed[1], -32) + - ldexp((double) xseed[2], -16); -} diff --git a/libc/upstream-netbsd/libc/stdlib/exit.c b/libc/upstream-netbsd/libc/stdlib/exit.c deleted file mode 100644 index 67e6adf..0000000 --- a/libc/upstream-netbsd/libc/stdlib/exit.c +++ /dev/null @@ -1,63 +0,0 @@ -/* $NetBSD: exit.c,v 1.15 2011/05/18 19:36:36 dsl Exp $ */ - -/*- - * 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. 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) -#if 0 -static char sccsid[] = "@(#)exit.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: exit.c,v 1.15 2011/05/18 19:36:36 dsl Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#ifdef _LIBC -#include "reentrant.h" -#include "atexit.h" -#endif - -void (*__cleanup)(void); - -/* - * Exit, flushing stdio buffers if necessary. - */ -void -exit(int status) -{ - -#ifdef _LIBC - __cxa_finalize(NULL); -#endif - if (__cleanup) - (*__cleanup)(); - _exit(status); -} diff --git a/libc/upstream-netbsd/libc/stdlib/jrand48.c b/libc/upstream-netbsd/libc/stdlib/jrand48.c deleted file mode 100644 index 079dbd3..0000000 --- a/libc/upstream-netbsd/libc/stdlib/jrand48.c +++ /dev/null @@ -1,39 +0,0 @@ -/* $NetBSD: jrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $ */ - -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: jrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" - -#include - -#include "rand48.h" - -#ifdef __weak_alias -__weak_alias(jrand48,_jrand48) -#endif - -long -jrand48(unsigned short xseed[3]) -{ - - _DIAGASSERT(xseed != NULL); - - __dorand48(xseed); - return (int16_t)xseed[2] * 65536 + xseed[1]; -} diff --git a/libc/upstream-netbsd/libc/stdlib/ldiv.c b/libc/upstream-netbsd/libc/stdlib/ldiv.c deleted file mode 100644 index 507c831..0000000 --- a/libc/upstream-netbsd/libc/stdlib/ldiv.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $NetBSD: ldiv.c,v 1.8 2012/06/25 22:32:45 abs Exp $ */ - -/* - * 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. 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) -#if 0 -static char sccsid[] = "@(#)ldiv.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: ldiv.c,v 1.8 2012/06/25 22:32:45 abs Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include /* ldiv_t */ - -ldiv_t -ldiv(long num, long 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/libc/upstream-netbsd/libc/stdlib/lldiv.c b/libc/upstream-netbsd/libc/stdlib/lldiv.c deleted file mode 100644 index 47104b3..0000000 --- a/libc/upstream-netbsd/libc/stdlib/lldiv.c +++ /dev/null @@ -1,66 +0,0 @@ -/* $NetBSD: lldiv.c,v 1.4 2012/06/25 22:32:45 abs Exp $ */ - -/* - * 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. 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) -#if 0 -static char sccsid[] = "from: @(#)ldiv.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: lldiv.c,v 1.4 2012/06/25 22:32:45 abs Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include /* lldiv_t */ - -#ifdef __weak_alias -__weak_alias(lldiv, _lldiv) -#endif - -/* LONGLONG */ -lldiv_t -lldiv(long long int num, long long int denom) -{ - lldiv_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/libc/upstream-netbsd/libc/stdlib/lrand48.c b/libc/upstream-netbsd/libc/stdlib/lrand48.c deleted file mode 100644 index 11e6485..0000000 --- a/libc/upstream-netbsd/libc/stdlib/lrand48.c +++ /dev/null @@ -1,33 +0,0 @@ -/* $NetBSD: lrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $ */ - -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: lrand48.c,v 1.9 2013/10/22 08:08:51 matt Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include "rand48.h" - -#ifdef __weak_alias -__weak_alias(lrand48,_lrand48) -#endif - -long -lrand48(void) -{ - __dorand48(__rand48_seed); - return __rand48_seed[2] * 32768 + (__rand48_seed[1] >> 1); -} diff --git a/libc/upstream-netbsd/libc/stdlib/mrand48.c b/libc/upstream-netbsd/libc/stdlib/mrand48.c deleted file mode 100644 index e51352a..0000000 --- a/libc/upstream-netbsd/libc/stdlib/mrand48.c +++ /dev/null @@ -1,33 +0,0 @@ -/* $NetBSD: mrand48.c,v 1.8 2013/10/22 08:08:51 matt Exp $ */ - -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: mrand48.c,v 1.8 2013/10/22 08:08:51 matt Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include "rand48.h" - -#ifdef __weak_alias -__weak_alias(mrand48,_mrand48) -#endif - -long -mrand48(void) -{ - __dorand48(__rand48_seed); - return (int16_t)__rand48_seed[2] * 65536 + __rand48_seed[1]; -} diff --git a/libc/upstream-netbsd/libc/stdlib/nrand48.c b/libc/upstream-netbsd/libc/stdlib/nrand48.c deleted file mode 100644 index 98becca..0000000 --- a/libc/upstream-netbsd/libc/stdlib/nrand48.c +++ /dev/null @@ -1,38 +0,0 @@ -/* $NetBSD: nrand48.c,v 1.10 2013/10/22 08:08:51 matt Exp $ */ - -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: nrand48.c,v 1.10 2013/10/22 08:08:51 matt Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" - -#include - -#include "rand48.h" - -#ifdef __weak_alias -__weak_alias(nrand48,_nrand48) -#endif - -long -nrand48(unsigned short xseed[3]) -{ - _DIAGASSERT(xseed != NULL); - - __dorand48(xseed); - return xseed[2] * 32768 + (xseed[1] >> 1); -} diff --git a/libc/upstream-netbsd/libc/stdlib/seed48.c b/libc/upstream-netbsd/libc/stdlib/seed48.c deleted file mode 100644 index 36c0570..0000000 --- a/libc/upstream-netbsd/libc/stdlib/seed48.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $NetBSD: seed48.c,v 1.8 2005/06/12 05:21:28 lukem Exp $ */ - -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: seed48.c,v 1.8 2005/06/12 05:21:28 lukem Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" - -#include - -#include "rand48.h" - -#ifdef __weak_alias -__weak_alias(seed48,_seed48) -#endif - -unsigned short * -seed48(unsigned short xseed[3]) -{ - static unsigned short sseed[3]; - - _DIAGASSERT(xseed != NULL); - - sseed[0] = __rand48_seed[0]; - sseed[1] = __rand48_seed[1]; - sseed[2] = __rand48_seed[2]; - __rand48_seed[0] = xseed[0]; - __rand48_seed[1] = xseed[1]; - __rand48_seed[2] = xseed[2]; - __rand48_mult[0] = RAND48_MULT_0; - __rand48_mult[1] = RAND48_MULT_1; - __rand48_mult[2] = RAND48_MULT_2; - __rand48_add = RAND48_ADD; - return sseed; -} diff --git a/libc/upstream-netbsd/libc/stdlib/srand48.c b/libc/upstream-netbsd/libc/stdlib/srand48.c deleted file mode 100644 index a9673fe..0000000 --- a/libc/upstream-netbsd/libc/stdlib/srand48.c +++ /dev/null @@ -1,38 +0,0 @@ -/* $NetBSD: srand48.c,v 1.7 2005/06/12 05:21:28 lukem Exp $ */ - -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: srand48.c,v 1.7 2005/06/12 05:21:28 lukem Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include "rand48.h" - -#ifdef __weak_alias -__weak_alias(srand48,_srand48) -#endif - -void -srand48(long seed) -{ - __rand48_seed[0] = RAND48_SEED_0; - __rand48_seed[1] = (unsigned short) seed; - __rand48_seed[2] = (unsigned short) ((unsigned long)seed >> 16); - __rand48_mult[0] = RAND48_MULT_0; - __rand48_mult[1] = RAND48_MULT_1; - __rand48_mult[2] = RAND48_MULT_2; - __rand48_add = RAND48_ADD; -} diff --git a/libc/upstream-netbsd/libc/stdlib/tdelete.c b/libc/upstream-netbsd/libc/stdlib/tdelete.c deleted file mode 100644 index 84017dc..0000000 --- a/libc/upstream-netbsd/libc/stdlib/tdelete.c +++ /dev/null @@ -1,67 +0,0 @@ -/* $NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs 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 defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include -#define _SEARCH_PRIVATE -#include -#include - - -/* find a node with key "vkey" in tree "vrootp" */ -void * -tdelete(const void *vkey, void **vrootp, - int (*compar)(const void *, const void *)) -{ - node_t **rootp = (node_t **)vrootp; - node_t *p, *q, *r; - int cmp; - - _DIAGASSERT(vkey != NULL); - _DIAGASSERT(compar != NULL); - - 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; - } - } - if (p != *rootp) - free(*rootp); /* D4: Free node */ - *rootp = q; /* link parent to new node */ - return p; -} diff --git a/libc/upstream-netbsd/libc/stdlib/tfind.c b/libc/upstream-netbsd/libc/stdlib/tfind.c deleted file mode 100644 index fd3f362..0000000 --- a/libc/upstream-netbsd/libc/stdlib/tfind.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs 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 defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include -#define _SEARCH_PRIVATE -#include -#include - -/* find a node by key "vkey" in tree "vrootp", or return 0 */ -void * -tfind(const void *vkey, void * const *vrootp, - int (*compar)(const void *, const void *)) -{ - node_t * const *rootp = (node_t * const*)vrootp; - - _DIAGASSERT(vkey != NULL); - _DIAGASSERT(compar != NULL); - - 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/libc/upstream-netbsd/libc/stdlib/tsearch.c b/libc/upstream-netbsd/libc/stdlib/tsearch.c deleted file mode 100644 index af2fe9c..0000000 --- a/libc/upstream-netbsd/libc/stdlib/tsearch.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs 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 defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include -#define _SEARCH_PRIVATE -#include -#include - -/* find or insert datum into search tree */ -void * -tsearch(const void *vkey, void **vrootp, - int (*compar)(const void *, const void *)) -{ - node_t *q; - node_t **rootp = (node_t **)vrootp; - - _DIAGASSERT(vkey != NULL); - _DIAGASSERT(compar != NULL); - - 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 */ - q->key = __UNCONST(vkey); /* initialize new node */ - q->llink = q->rlink = NULL; - } - return q; -} diff --git a/libc/upstream-netbsd/libc/string/memccpy.c b/libc/upstream-netbsd/libc/string/memccpy.c deleted file mode 100644 index c086241..0000000 --- a/libc/upstream-netbsd/libc/string/memccpy.c +++ /dev/null @@ -1,61 +0,0 @@ -/* $NetBSD: memccpy.c,v 1.13 2012/06/25 22:32:46 abs Exp $ */ - -/*- - * 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. 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) -#if 0 -static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: memccpy.c,v 1.13 2012/06/25 22:32:46 abs Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -void * -memccpy(void *t, const void *f, int c, size_t n) -{ - - _DIAGASSERT(t != 0); - _DIAGASSERT(f != 0); - - 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/libc/upstream-netbsd/libc/string/strcasestr.c b/libc/upstream-netbsd/libc/string/strcasestr.c deleted file mode 100644 index f8a9444..0000000 --- a/libc/upstream-netbsd/libc/string/strcasestr.c +++ /dev/null @@ -1,69 +0,0 @@ -/* $NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $ */ - -/*- - * 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. 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) -__RCSID("$NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include -#include -#include - -/* - * Find the first occurrence of find in s, ignore case. - */ -char * -strcasestr(const char *s, const char *find) -{ - char c, sc; - size_t len; - - _DIAGASSERT(s != NULL); - _DIAGASSERT(find != NULL); - - if ((c = *find++) != 0) { - c = tolower((unsigned char)c); - len = strlen(find); - do { - do { - if ((sc = *s++) == 0) - return (NULL); - } while ((char)tolower((unsigned char)sc) != c); - } while (strncasecmp(s, find, len) != 0); - s--; - } - return __UNCONST(s); -} diff --git a/libc/upstream-netbsd/libc/string/strcoll.c b/libc/upstream-netbsd/libc/string/strcoll.c deleted file mode 100644 index 77a0942..0000000 --- a/libc/upstream-netbsd/libc/string/strcoll.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $NetBSD: strcoll.c,v 1.10 2012/06/25 22:32:46 abs Exp $ */ - -/*- - * 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. 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) -#if 0 -static char sccsid[] = "@(#)strcoll.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: strcoll.c,v 1.10 2012/06/25 22:32:46 abs Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -/* - * Compare strings according to LC_COLLATE category of current locale. - */ -int -strcoll(const char *s1, const char *s2) -{ - - _DIAGASSERT(s1 != NULL); - _DIAGASSERT(s2 != NULL); - - /* LC_COLLATE is unimplemented, hence always "C" */ - return (strcmp(s1, s2)); -} diff --git a/libc/upstream-netbsd/libc/string/strxfrm.c b/libc/upstream-netbsd/libc/string/strxfrm.c deleted file mode 100644 index 42c2a24..0000000 --- a/libc/upstream-netbsd/libc/string/strxfrm.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $NetBSD: strxfrm.c,v 1.12 2012/06/25 22:32:46 abs Exp $ */ - -/*- - * 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. 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) -#if 0 -static char sccsid[] = "@(#)strxfrm.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: strxfrm.c,v 1.12 2012/06/25 22:32:46 abs Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include -#include - -/* - * Transform src, storing the result in dst, such that - * strcmp() on transformed strings returns what strcoll() - * on the original untransformed strings would return. - */ -size_t -strxfrm(char *dst, const char *src, size_t n) -{ - size_t srclen, copysize; - - _DIAGASSERT(src != NULL); - - /* - * Since locales are unimplemented, this is just a copy. - */ - srclen = strlen(src); - if (n != 0) { - _DIAGASSERT(dst != NULL); - copysize = srclen < n ? srclen : n - 1; - (void)memcpy(dst, src, copysize); - dst[copysize] = 0; - } - return (srclen); -} diff --git a/libc/upstream-netbsd/libc/thread-stub/__isthreaded.c b/libc/upstream-netbsd/libc/thread-stub/__isthreaded.c deleted file mode 100644 index 50c1b6f..0000000 --- a/libc/upstream-netbsd/libc/thread-stub/__isthreaded.c +++ /dev/null @@ -1,37 +0,0 @@ -/* $NetBSD: __isthreaded.c,v 1.3 2009/12/01 01:33:25 explorer Exp $ */ - -/*- - * Copyright (c) 1999 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Michael Graff. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must 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 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. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: __isthreaded.c,v 1.3 2009/12/01 01:33:25 explorer Exp $"); -#endif /* LIBC_SCCS and not lint */ - -int __isthreaded = 0; diff --git a/libc/upstream-netbsd/libc/unistd/killpg.c b/libc/upstream-netbsd/libc/unistd/killpg.c deleted file mode 100644 index ceac3f4..0000000 --- a/libc/upstream-netbsd/libc/unistd/killpg.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $NetBSD: killpg.c,v 1.8 2003/08/07 16:42:39 agc Exp $ */ - -/* - * 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. 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) -#if 0 -static char sccsid[] = "@(#)killpg.c 8.1 (Berkeley) 6/2/93"; -#else -__RCSID("$NetBSD: killpg.c,v 1.8 2003/08/07 16:42:39 agc Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include - -/* - * Backwards-compatible killpg(). - */ -int -killpg(pid_t pgid, int sig) -{ - if (pgid == 1) { - errno = ESRCH; - return (-1); - } - return (kill(-pgid, sig)); -} -- cgit v1.1