From 0133944b09d1c0a35041f7a41eb6bfb660144f4f Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 20 Feb 2014 18:04:58 -0800 Subject: [PATCH] Clean up our OpenBSD usage. Also undo some of the mess where we have OpenBSD but a mix of different BSD's implementations. In this first pass, I've only moved easy OpenBSD stuff. Change-Id: Iae67b02cde6dba9d8d06fedeb53efbfdac0a8cf6 --- libc/Android.mk | 96 ++++-------- libc/bionic/atoi.c | 33 ---- libc/bionic/atol.c | 33 ---- libc/bionic/atoll.c | 33 ---- libc/bionic/ftok.c | 40 ----- libc/bionic/perror.c | 44 ------ libc/bionic/strndup.c | 44 ------ libc/include/unistd.h | 2 +- .../lib/libc/gen}/charclass.h | 0 .../lib/libc/gen}/exec.c | 42 ++--- .../lib/libc/gen}/fnmatch.c | 0 libc/upstream-openbsd/lib/libc/gen/ftok.c | 43 ++++++ .../lib/libc/gen}/tolower_.c | 0 .../lib/libc/gen}/toupper_.c | 0 .../lib/libc/stdio/clrerr.c | 22 +-- .../lib/libc/stdio/fdopen.c | 31 +--- .../lib/libc/stdio/feof.c | 24 +-- .../lib/libc/stdio/ferror.c | 24 +-- .../lib/libc}/stdio/fflush.c | 6 +- .../lib/libc}/stdio/fgetc.c | 2 +- .../lib/libc/stdio/fgetln.c | 34 ++--- .../lib/libc/stdio/fgetpos.c | 20 +-- .../lib/libc/stdio/fgets.c | 28 ++-- .../lib/libc/stdio/fileno.c | 29 +--- .../lib/libc/stdio/fpurge.c | 30 ++-- .../lib/libc}/stdio/fputc.c | 2 +- .../lib/libc/stdio/fputs.c | 22 +-- .../lib/libc}/stdio/fscanf.c | 3 +- .../lib/libc}/stdio/fseek.c | 19 +-- .../lib/libc/stdio/fsetpos.c | 10 +- .../lib/libc}/stdio/ftell.c | 24 ++- .../lib/libc/stdio/funopen.c | 16 +- .../lib/libc/stdio/fwalk.c | 20 +-- .../lib/libc/stdio/getc.c | 43 +++--- .../lib/libc/stdio/getchar.c | 44 +++--- .../lib/libc/stdio/getdelim.c | 36 +---- .../lib/libc/stdio/getline.c | 10 +- .../lib/libc}/stdio/gets.c | 2 +- libc/upstream-openbsd/lib/libc/stdio/perror.c | 62 ++++++++ .../lib/libc}/stdio/printf.c | 3 +- .../lib/libc/stdio/putc.c | 47 +++--- .../lib/libc/stdio/putchar.c | 39 ++--- .../lib/libc/stdio/puts.c | 22 +-- .../lib/libc}/stdio/refill.c | 6 +- .../lib/libc/stdio/remove.c | 19 +-- .../lib/libc}/stdio/rewind.c | 0 .../lib/libc/stdio/rget.c | 8 +- .../lib/libc}/stdio/scanf.c | 3 +- .../lib/libc/stdio/setbuf.c | 9 +- .../lib/libc/stdio/setbuffer.c | 9 +- .../lib/libc}/stdio/stdio.c | 4 +- .../lib/libc/stdio/tempnam.c | 48 +++--- .../lib/libc/stdio/tmpnam.c | 9 +- .../lib/libc}/stdio/ungetc.c | 2 +- .../lib/libc}/stdio/vasprintf.c | 7 +- .../lib/libc}/stdio/vprintf.c | 0 .../lib/libc}/stdio/vscanf.c | 0 .../lib/libc}/stdio/vsnprintf.c | 2 +- .../lib/libc}/stdio/vsprintf.c | 2 +- .../lib/libc}/stdio/wbuf.c | 2 +- .../lib/libc/stdlib/atoi.c} | 24 +-- libc/upstream-openbsd/lib/libc/stdlib/atol.c | 37 +++++ .../lib/libc/stdlib/atoll.c} | 24 +-- .../lib/libc}/stdlib/strtoimax.c | 37 +---- .../lib/libc}/stdlib/strtol.c | 13 +- .../lib/libc/stdlib/strtoll.c | 144 ++++++++++++++++++ .../lib/libc}/stdlib/strtoul.c | 2 +- .../lib/libc/stdlib/strtoull.c | 106 +++++++++++++ .../lib/libc}/stdlib/strtoumax.c | 19 +-- .../lib/libc}/string/strcasecmp.c | 0 .../lib/libc}/string/strcspn.c | 0 .../lib/libc}/string/strdup.c | 0 .../lib/libc/string/strndup.c | 39 +++++ .../lib/libc}/string/strpbrk.c | 0 .../lib/libc}/string/strsep.c | 2 +- .../lib/libc}/string/strspn.c | 0 .../lib/libc}/string/strstr.c | 0 .../lib/libc}/string/strtok.c | 0 libc/upstream-openbsd/openbsd-compat.h | 22 +++ 79 files changed, 802 insertions(+), 881 deletions(-) delete mode 100644 libc/bionic/atoi.c delete mode 100644 libc/bionic/atol.c delete mode 100644 libc/bionic/atoll.c delete mode 100644 libc/bionic/ftok.c delete mode 100644 libc/bionic/perror.c delete mode 100644 libc/bionic/strndup.c rename libc/{unistd => upstream-openbsd/lib/libc/gen}/charclass.h (100%) rename libc/{unistd => upstream-openbsd/lib/libc/gen}/exec.c (90%) rename libc/{unistd => upstream-openbsd/lib/libc/gen}/fnmatch.c (100%) create mode 100644 libc/upstream-openbsd/lib/libc/gen/ftok.c rename libc/{stdlib => upstream-openbsd/lib/libc/gen}/tolower_.c (100%) rename libc/{stdlib => upstream-openbsd/lib/libc/gen}/toupper_.c (100%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/clrerr.c (83%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/fdopen.c (77%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/feof.c (83%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/ferror.c (83%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/fflush.c (97%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/fgetc.c (96%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/fgetln.c (86%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/fgetpos.c (82%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/fgets.c (86%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/fileno.c (82%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/fpurge.c (80%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/fputc.c (96%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/fputs.c (83%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/fscanf.c (95%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/fseek.c (93%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/fsetpos.c (88%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/ftell.c (88%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/funopen.c (86%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/fwalk.c (79%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/getc.c (82%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/getchar.c (78%) rename libc/{upstream-netbsd => upstream-openbsd}/lib/libc/stdio/getdelim.c (88%) rename libc/{upstream-netbsd => upstream-openbsd}/lib/libc/stdio/getline.c (90%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/gets.c (97%) create mode 100644 libc/upstream-openbsd/lib/libc/stdio/perror.c rename libc/{ => upstream-openbsd/lib/libc}/stdio/printf.c (95%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/putc.c (80%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/putchar.c (78%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/puts.c (84%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/refill.c (96%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/remove.c (86%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/rewind.c (100%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/rget.c (91%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/scanf.c (95%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/setbuf.c (88%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/setbuffer.c (88%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/stdio.c (99%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/tempnam.c (71%) rename libc/{upstream-freebsd => upstream-openbsd}/lib/libc/stdio/tmpnam.c (88%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/ungetc.c (98%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/vasprintf.c (91%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/vprintf.c (100%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/vscanf.c (100%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/vsnprintf.c (97%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/vsprintf.c (96%) rename libc/{ => upstream-openbsd/lib/libc}/stdio/wbuf.c (98%) rename libc/{stdlib/strtoull.c => upstream-openbsd/lib/libc/stdlib/atoi.c} (74%) create mode 100644 libc/upstream-openbsd/lib/libc/stdlib/atol.c rename libc/{stdlib/strtoll.c => upstream-openbsd/lib/libc/stdlib/atoll.c} (76%) rename libc/{ => upstream-openbsd/lib/libc}/stdlib/strtoimax.c (82%) rename libc/{ => upstream-openbsd/lib/libc}/stdlib/strtol.c (93%) create mode 100644 libc/upstream-openbsd/lib/libc/stdlib/strtoll.c rename libc/{ => upstream-openbsd/lib/libc}/stdlib/strtoul.c (97%) create mode 100644 libc/upstream-openbsd/lib/libc/stdlib/strtoull.c rename libc/{ => upstream-openbsd/lib/libc}/stdlib/strtoumax.c (88%) rename libc/{ => upstream-openbsd/lib/libc}/string/strcasecmp.c (100%) rename libc/{ => upstream-openbsd/lib/libc}/string/strcspn.c (100%) rename libc/{ => upstream-openbsd/lib/libc}/string/strdup.c (100%) create mode 100644 libc/upstream-openbsd/lib/libc/string/strndup.c rename libc/{ => upstream-openbsd/lib/libc}/string/strpbrk.c (100%) rename libc/{ => upstream-openbsd/lib/libc}/string/strsep.c (98%) rename libc/{ => upstream-openbsd/lib/libc}/string/strspn.c (100%) rename libc/{ => upstream-openbsd/lib/libc}/string/strstr.c (100%) rename libc/{ => upstream-openbsd/lib/libc}/string/strtok.c (100%) create mode 100644 libc/upstream-openbsd/openbsd-compat.h diff --git a/libc/Android.mk b/libc/Android.mk index 9cde07310..4e140f038 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -38,9 +38,6 @@ endif # ========================================================= libc_common_src_files := \ bionic/arc4random.c \ - bionic/atoi.c \ - bionic/atol.c \ - bionic/atoll.c \ bionic/bindresvport.c \ bionic/clearenv.c \ bionic/daemon.c \ @@ -50,7 +47,6 @@ libc_common_src_files := \ bionic/fdprintf.c \ bionic/flockfile.c \ bionic/ftime.c \ - bionic/ftok.c \ bionic/fts.c \ bionic/getdtablesize.c \ bionic/gethostname.c \ @@ -68,7 +64,6 @@ libc_common_src_files := \ bionic/memmem.c \ bionic/memswap.c \ bionic/pathconf.c \ - bionic/perror.c \ bionic/ptsname.c \ bionic/ptsname_r.c \ bionic/pututline.c \ @@ -81,7 +76,6 @@ libc_common_src_files := \ bionic/sigblock.c \ bionic/siginterrupt.c \ bionic/sigsetmask.c \ - bionic/strndup.c \ bionic/strntoimax.c \ bionic/strntoumax.c \ bionic/strtotimeval.c \ @@ -95,61 +89,24 @@ libc_common_src_files := \ bionic/utmp.c \ bionic/wcscoll.c \ stdio/asprintf.c \ - stdio/fflush.c \ - stdio/fgetc.c \ stdio/findfp.c \ stdio/fprintf.c \ - stdio/fputc.c \ stdio/fread.c \ stdio/freopen.c \ - stdio/fscanf.c \ - stdio/fseek.c \ - stdio/ftell.c \ stdio/fvwrite.c \ - stdio/gets.c \ - stdio/printf.c \ - stdio/refill.c \ - stdio/rewind.c \ - stdio/scanf.c \ stdio/snprintf.c\ stdio/sprintf.c \ stdio/sscanf.c \ - stdio/stdio.c \ - stdio/ungetc.c \ - stdio/vasprintf.c \ stdio/vfprintf.c \ stdio/vfscanf.c \ - stdio/vprintf.c \ - stdio/vscanf.c \ - stdio/vsnprintf.c \ - stdio/vsprintf.c \ stdio/vsscanf.c \ - stdio/wbuf.c \ stdlib/atexit.c \ stdlib/ctype_.c \ stdlib/getenv.c \ stdlib/putenv.c \ stdlib/setenv.c \ stdlib/strtod.c \ - stdlib/strtoimax.c \ - stdlib/strtol.c \ - stdlib/strtoll.c \ - stdlib/strtoul.c \ - stdlib/strtoull.c \ - stdlib/strtoumax.c \ - stdlib/tolower_.c \ - stdlib/toupper_.c \ - string/strcasecmp.c \ - string/strcspn.c \ - string/strdup.c \ - string/strpbrk.c \ - string/strsep.c \ - string/strspn.c \ - string/strstr.c \ - string/strtok.c \ unistd/alarm.c \ - unistd/exec.c \ - unistd/fnmatch.c \ unistd/syslog.c \ unistd/system.c \ unistd/time.c \ @@ -280,38 +237,14 @@ libc_bionic_src_files := \ libc_upstream_freebsd_src_files := \ upstream-freebsd/lib/libc/gen/sleep.c \ upstream-freebsd/lib/libc/gen/usleep.c \ - upstream-freebsd/lib/libc/stdio/clrerr.c \ upstream-freebsd/lib/libc/stdio/fclose.c \ - upstream-freebsd/lib/libc/stdio/fdopen.c \ - upstream-freebsd/lib/libc/stdio/feof.c \ - upstream-freebsd/lib/libc/stdio/ferror.c \ - upstream-freebsd/lib/libc/stdio/fgetln.c \ - upstream-freebsd/lib/libc/stdio/fgetpos.c \ - upstream-freebsd/lib/libc/stdio/fgets.c \ - upstream-freebsd/lib/libc/stdio/fileno.c \ upstream-freebsd/lib/libc/stdio/flags.c \ upstream-freebsd/lib/libc/stdio/fopen.c \ - upstream-freebsd/lib/libc/stdio/fpurge.c \ - upstream-freebsd/lib/libc/stdio/fputs.c \ - upstream-freebsd/lib/libc/stdio/fsetpos.c \ - upstream-freebsd/lib/libc/stdio/funopen.c \ - upstream-freebsd/lib/libc/stdio/fwalk.c \ upstream-freebsd/lib/libc/stdio/fwrite.c \ - upstream-freebsd/lib/libc/stdio/getc.c \ - upstream-freebsd/lib/libc/stdio/getchar.c \ upstream-freebsd/lib/libc/stdio/makebuf.c \ upstream-freebsd/lib/libc/stdio/mktemp.c \ - upstream-freebsd/lib/libc/stdio/putc.c \ - upstream-freebsd/lib/libc/stdio/putchar.c \ - upstream-freebsd/lib/libc/stdio/puts.c \ upstream-freebsd/lib/libc/stdio/putw.c \ - upstream-freebsd/lib/libc/stdio/remove.c \ - upstream-freebsd/lib/libc/stdio/rget.c \ - upstream-freebsd/lib/libc/stdio/setbuf.c \ - upstream-freebsd/lib/libc/stdio/setbuffer.c \ upstream-freebsd/lib/libc/stdio/setvbuf.c \ - upstream-freebsd/lib/libc/stdio/tempnam.c \ - upstream-freebsd/lib/libc/stdio/tmpnam.c \ upstream-freebsd/lib/libc/stdio/wsetup.c \ upstream-freebsd/lib/libc/stdlib/abs.c \ upstream-freebsd/lib/libc/stdlib/getopt_long.c \ @@ -361,8 +294,6 @@ libc_upstream_netbsd_src_files := \ 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 \ @@ -573,6 +504,32 @@ $(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags)) include $(BUILD_STATIC_LIBRARY) +# ======================================================== +# libc_openbsd.a - upstream OpenBSD C library code +# ======================================================== +# +# These files are built with the openbsd-compat.h header file +# automatically included. + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-c-files-under,upstream-openbsd) +LOCAL_CFLAGS := \ + $(libc_common_cflags) \ + -I$(LOCAL_PATH)/upstream-openbsd \ + -I$(LOCAL_PATH)/upstream-openbsd/lib/libc/include \ + -include upstream-openbsd/openbsd-compat.h +LOCAL_CONLYFLAGS := $(libc_common_conlyflags) +LOCAL_CPPFLAGS := $(libc_common_cppflags) +LOCAL_C_INCLUDES := $(libc_common_c_includes) +LOCAL_MODULE := libc_openbsd +LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies) +LOCAL_SYSTEM_SHARED_LIBRARIES := + +$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags)) +include $(BUILD_STATIC_LIBRARY) + + # ======================================================== # libc_bionic.a - home-grown C library code # ======================================================== @@ -633,6 +590,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES := \ libc_dns \ libc_freebsd \ libc_netbsd \ + libc_openbsd \ libc_syscalls \ libc_tzcode \ diff --git a/libc/bionic/atoi.c b/libc/bionic/atoi.c deleted file mode 100644 index 9a655430b..000000000 --- a/libc/bionic/atoi.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must 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 COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (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 - -int atoi(const char* s) -{ - return (int)strtoimax(s, NULL, 10); -} diff --git a/libc/bionic/atol.c b/libc/bionic/atol.c deleted file mode 100644 index 83dc05c70..000000000 --- a/libc/bionic/atol.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must 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 COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (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 - -long atol(const char* s) -{ - return (long)strtoimax(s, NULL, 10); -} diff --git a/libc/bionic/atoll.c b/libc/bionic/atoll.c deleted file mode 100644 index 953878f27..000000000 --- a/libc/bionic/atoll.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must 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 COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (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 - -long long atoll(const char* s) -{ - return (long long)strtoimax(s, NULL, 10); -} diff --git a/libc/bionic/ftok.c b/libc/bionic/ftok.c deleted file mode 100644 index 638bd0ac0..000000000 --- a/libc/bionic/ftok.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must 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 COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (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 -#include -#include - -key_t ftok(const char* path, int id) -{ - struct stat st; - - if ( lstat(path, &st) < 0 ) - return -1; - - return (key_t)( (st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((id & 255) << 24) ); -} diff --git a/libc/bionic/perror.c b/libc/bionic/perror.c deleted file mode 100644 index de55f720d..000000000 --- a/libc/bionic/perror.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must 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 COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (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 -#include -#include - -void perror(const char *prefix) -{ - char buff[256]; - - strerror_r( errno, buff, sizeof(buff) ); - - if (prefix) { - write( 2, prefix, strlen(prefix) ); - write( 2, ": ", 2 ); - } - write( 2, buff, strlen(buff) ); - write( 2, "\n", 1 ); -} diff --git a/libc/bionic/strndup.c b/libc/bionic/strndup.c deleted file mode 100644 index 9dca79c43..000000000 --- a/libc/bionic/strndup.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must 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 COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (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 -#include - -char* strndup(const char* s, size_t n) -{ - size_t slen = (size_t)strlen(s); - char* copy; - - if (slen < n) - n = slen; - copy = malloc(n+1); - if (copy) { - memcpy(copy, s, n); - copy[n] = 0; - } - return copy; -} diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 70cc4c549..d21f23d3f 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -64,6 +64,7 @@ extern pid_t setsid(void); extern int execv(const char *, char * const *); extern int execvp(const char *, char * const *); +extern int execvpe(const char *, char * const *, char * const *); extern int execve(const char *, char * const *, char * const *); extern int execl(const char *, const char *, ...); extern int execlp(const char *, const char *, ...); @@ -194,7 +195,6 @@ extern pid_t tcgetpgrp(int fd); extern int tcsetpgrp(int fd, pid_t _pid); #if 0 /* MISSING FROM BIONIC */ -extern int execvpe(const char *, char * const *, char * const *); extern int execlpe(const char *, const char *, ...); extern int getfsuid(uid_t); extern int setfsuid(uid_t); diff --git a/libc/unistd/charclass.h b/libc/upstream-openbsd/lib/libc/gen/charclass.h similarity index 100% rename from libc/unistd/charclass.h rename to libc/upstream-openbsd/lib/libc/gen/charclass.h diff --git a/libc/unistd/exec.c b/libc/upstream-openbsd/lib/libc/gen/exec.c similarity index 90% rename from libc/unistd/exec.c rename to libc/upstream-openbsd/lib/libc/gen/exec.c index 2fe2a4e0a..1e2f7d97d 100644 --- a/libc/unistd/exec.c +++ b/libc/upstream-openbsd/lib/libc/gen/exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.c,v 1.18 2005/08/08 08:05:34 espie Exp $ */ +/* $OpenBSD: exec.c,v 1.21 2013/09/30 12:02:33 millert Exp $ */ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -28,19 +28,17 @@ * SUCH DAMAGE. */ -#include #include #include + #include -#include #include -#include -#include -#include -#include #include #include -#include +#include +#include +#include +#include extern char **environ; @@ -124,20 +122,21 @@ execlp(const char *name, const char *arg, ...) } int -execv(const char *name, char * const *argv) +execv(const char *name, char *const *argv) { (void)execve(name, argv, environ); return (-1); } int -execvp(const char *name, char * const *argv) +execvpe(const char *name, char *const *argv, char *const *envp) { char **memp; - int cnt, lp, ln, len; + int cnt; + size_t lp, ln, len; char *p; int eacces = 0; - char *bp, *cur, *path, buf[MAXPATHLEN]; + char *bp, *cur, *path, buf[PATH_MAX]; /* * Do not allow null name @@ -183,7 +182,7 @@ execvp(const char *name, char * const *argv) * security issue; given a way to make the path too long * the user may execute the wrong program. */ - if (lp + ln + 2 > (int)sizeof(buf)) { + if (lp + ln + 2 > sizeof(buf)) { struct iovec iov[3]; iov[0].iov_base = "execvp: "; @@ -195,12 +194,12 @@ execvp(const char *name, char * const *argv) (void)writev(STDERR_FILENO, iov, 3); continue; } - memcpy(buf, p, lp); + bcopy(p, buf, lp); buf[lp] = '/'; - memcpy(buf + lp + 1, name, ln); + bcopy(name, buf + lp + 1, ln); buf[lp + ln + 1] = '\0'; -retry: (void)execve(bp, argv, environ); +retry: (void)execve(bp, argv, envp); switch(errno) { case E2BIG: goto done; @@ -217,8 +216,8 @@ retry: (void)execve(bp, argv, environ); goto done; memp[0] = "sh"; memp[1] = bp; - memcpy(memp + 2, argv + 1, cnt * sizeof(char *)); - (void)execve(_PATH_BSHELL, memp, environ); + bcopy(argv + 1, memp + 2, cnt * sizeof(char *)); + (void)execve(_PATH_BSHELL, memp, envp); goto done; case ENOMEM: goto done; @@ -243,3 +242,10 @@ retry: (void)execve(bp, argv, environ); done: return (-1); } + +int +execvp(const char *name, char *const *argv) +{ + return execvpe(name, argv, environ); +} + diff --git a/libc/unistd/fnmatch.c b/libc/upstream-openbsd/lib/libc/gen/fnmatch.c similarity index 100% rename from libc/unistd/fnmatch.c rename to libc/upstream-openbsd/lib/libc/gen/fnmatch.c diff --git a/libc/upstream-openbsd/lib/libc/gen/ftok.c b/libc/upstream-openbsd/lib/libc/gen/ftok.c new file mode 100644 index 000000000..f9d662128 --- /dev/null +++ b/libc/upstream-openbsd/lib/libc/gen/ftok.c @@ -0,0 +1,43 @@ +/* $OpenBSD: ftok.c,v 1.7 2005/08/08 08:05:34 espie Exp $ */ +/* + * Copyright (c) 1994 SigmaSoft, Th. Lockert + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +key_t +ftok(const char *path, int id) +{ + struct stat st; + + if (stat(path, &st) < 0) + return (key_t)-1; + + return (key_t) + ((id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff)); +} diff --git a/libc/stdlib/tolower_.c b/libc/upstream-openbsd/lib/libc/gen/tolower_.c similarity index 100% rename from libc/stdlib/tolower_.c rename to libc/upstream-openbsd/lib/libc/gen/tolower_.c diff --git a/libc/stdlib/toupper_.c b/libc/upstream-openbsd/lib/libc/gen/toupper_.c similarity index 100% rename from libc/stdlib/toupper_.c rename to libc/upstream-openbsd/lib/libc/gen/toupper_.c diff --git a/libc/upstream-freebsd/lib/libc/stdio/clrerr.c b/libc/upstream-openbsd/lib/libc/stdio/clrerr.c similarity index 83% rename from libc/upstream-freebsd/lib/libc/stdio/clrerr.c rename to libc/upstream-openbsd/lib/libc/stdio/clrerr.c index f161a6e1e..ac08c72cd 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/clrerr.c +++ b/libc/upstream-openbsd/lib/libc/stdio/clrerr.c @@ -1,3 +1,4 @@ +/* $OpenBSD: clrerr.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,19 +31,9 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include -#include "un-namespace.h" -#include "libc_private.h" - -#undef clearerr -#undef clearerr_unlocked +#include "local.h" +#undef clearerr void clearerr(FILE *fp) @@ -51,10 +42,3 @@ clearerr(FILE *fp) __sclearerr(fp); FUNLOCKFILE(fp); } - -void -clearerr_unlocked(FILE *fp) -{ - - __sclearerr(fp); -} diff --git a/libc/upstream-freebsd/lib/libc/stdio/fdopen.c b/libc/upstream-openbsd/lib/libc/stdio/fdopen.c similarity index 77% rename from libc/upstream-freebsd/lib/libc/stdio/fdopen.c rename to libc/upstream-openbsd/lib/libc/stdio/fdopen.c index 2e19b9feb..3e47f2c74 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/fdopen.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fdopen.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fdopen.c,v 1.6 2008/04/21 12:28:35 otto Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,20 +31,12 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include #include +#include #include #include #include -#include -#include "un-namespace.h" #include "local.h" FILE * @@ -52,13 +45,7 @@ fdopen(int fd, const char *mode) FILE *fp; int flags, oflags, fdflags, tmp; - /* - * File descriptors are a full int, but _file is only a short. - * If we get a valid file descriptor that is greater than - * SHRT_MAX, then the fd will get sign-extended into an - * invalid file descriptor. Handle this case by failing the - * open. - */ + /* _file is only a short */ if (fd > SHRT_MAX) { errno = EMFILE; return (NULL); @@ -68,7 +55,7 @@ fdopen(int fd, const char *mode) return (NULL); /* Make sure the mode the user wants is a subset of the actual mode. */ - if ((fdflags = _fcntl(fd, F_GETFL, 0)) < 0) + if ((fdflags = fcntl(fd, F_GETFL, 0)) < 0) return (NULL); tmp = fdflags & O_ACCMODE; if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) { @@ -78,17 +65,11 @@ fdopen(int fd, const char *mode) if ((fp = __sfp()) == NULL) return (NULL); - - if ((oflags & O_CLOEXEC) && _fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { - fp->_flags = 0; - return (NULL); - } - fp->_flags = flags; /* * If opened for appending, but underlying descriptor does not have - * O_APPEND bit set, assert __SAPP so that __swrite() caller - * will _sseek() to the end before write. + * O_APPEND bit set, assert __SAPP so that __swrite() will lseek to + * end before each write. */ if ((oflags & O_APPEND) && !(fdflags & O_APPEND)) fp->_flags |= __SAPP; diff --git a/libc/upstream-freebsd/lib/libc/stdio/feof.c b/libc/upstream-openbsd/lib/libc/stdio/feof.c similarity index 83% rename from libc/upstream-freebsd/lib/libc/stdio/feof.c rename to libc/upstream-openbsd/lib/libc/stdio/feof.c index b970248a3..0036bab7d 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/feof.c +++ b/libc/upstream-openbsd/lib/libc/stdio/feof.c @@ -1,3 +1,4 @@ +/* $OpenBSD: feof.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,19 +31,13 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include -#include "un-namespace.h" -#include "libc_private.h" +#include "local.h" +/* + * A subroutine version of the macro feof. + */ #undef feof -#undef feof_unlocked int feof(FILE *fp) @@ -50,14 +45,7 @@ feof(FILE *fp) int ret; FLOCKFILE(fp); - ret= __sfeof(fp); + ret = __sfeof(fp); FUNLOCKFILE(fp); return (ret); } - -int -feof_unlocked(FILE *fp) -{ - - return (__sfeof(fp)); -} diff --git a/libc/upstream-freebsd/lib/libc/stdio/ferror.c b/libc/upstream-openbsd/lib/libc/stdio/ferror.c similarity index 83% rename from libc/upstream-freebsd/lib/libc/stdio/ferror.c rename to libc/upstream-openbsd/lib/libc/stdio/ferror.c index 7e0f8f957..00b9c8b2c 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/ferror.c +++ b/libc/upstream-openbsd/lib/libc/stdio/ferror.c @@ -1,3 +1,4 @@ +/* $OpenBSD: ferror.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,34 +31,21 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include -#include "un-namespace.h" -#include "libc_private.h" +#include "local.h" +/* + * A subroutine version of the macro ferror. + */ #undef ferror -#undef ferror_unlocked int ferror(FILE *fp) { - int ret; + int ret; FLOCKFILE(fp); ret = __sferror(fp); FUNLOCKFILE(fp); return (ret); } - -int -ferror_unlocked(FILE *fp) -{ - - return (__sferror(fp)); -} diff --git a/libc/stdio/fflush.c b/libc/upstream-openbsd/lib/libc/stdio/fflush.c similarity index 97% rename from libc/stdio/fflush.c rename to libc/upstream-openbsd/lib/libc/stdio/fflush.c index e69bdcc77..3e30f1086 100644 --- a/libc/stdio/fflush.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fflush.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fflush.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: fflush.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -39,7 +39,7 @@ int fflush(FILE *fp) { - int r; + int r; if (fp == NULL) return (_fwalk(__sflush_locked)); @@ -88,7 +88,7 @@ __sflush(FILE *fp) int __sflush_locked(FILE *fp) { - int r; + int r; FLOCKFILE(fp); r = __sflush(fp); diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/fgetc.c similarity index 96% rename from libc/stdio/fgetc.c rename to libc/upstream-openbsd/lib/libc/stdio/fgetc.c index 0a6d54eec..c5d7dde2d 100644 --- a/libc/stdio/fgetc.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fgetc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: fgetc.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. diff --git a/libc/upstream-freebsd/lib/libc/stdio/fgetln.c b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c similarity index 86% rename from libc/upstream-freebsd/lib/libc/stdio/fgetln.c rename to libc/upstream-openbsd/lib/libc/stdio/fgetln.c index 1779de2ae..539b3c081 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/fgetln.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fgetln.c,v 1.11 2009/11/21 09:53:44 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,18 +31,9 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include #include #include -#include "un-namespace.h" -#include "libc_private.h" #include "local.h" /* @@ -70,7 +62,7 @@ __slbexpand(FILE *fp, size_t newsize) /* * Get an input line. The returned pointer often (but not always) - * points into a stdio buffer. Fgetln does not alter the text of + * points into a stdio buffer. Fgetline does not alter the text of * the returned line (which is thus not a C string because it will * not necessarily end with '\0'), but does allow callers to modify * it if they wish. Thus, we set __SMOD in case the caller does. @@ -79,22 +71,19 @@ char * fgetln(FILE *fp, size_t *lenp) { unsigned char *p; + char *ret; size_t len; size_t off; FLOCKFILE(fp); - ORIENT(fp, -1); + _SET_ORIENTATION(fp, -1); + /* make sure there is input */ - if (fp->_r <= 0 && __srefill(fp)) { - *lenp = 0; - FUNLOCKFILE(fp); - return (NULL); - } + if (fp->_r <= 0 && __srefill(fp)) + goto error; /* look for a newline in the input */ - if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) { - char *ret; - + if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) { /* * Found one. Flag buffer as modified to keep fseek from * `optimising' a backward seek, in case the user stomps on @@ -135,7 +124,7 @@ fgetln(FILE *fp, size_t *lenp) off = len; if (__srefill(fp)) break; /* EOF or error: return partial line */ - if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL) + if ((p = memchr((void *)fp->_p, '\n', fp->_r)) == NULL) continue; /* got it: finish up the line (like code above) */ @@ -151,11 +140,12 @@ fgetln(FILE *fp, size_t *lenp) break; } *lenp = len; + ret = (char *)fp->_lb._base; #ifdef notdef - fp->_lb._base[len] = 0; + ret[len] = '\0'; #endif FUNLOCKFILE(fp); - return ((char *)fp->_lb._base); + return (ret); error: *lenp = 0; /* ??? */ diff --git a/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c b/libc/upstream-openbsd/lib/libc/stdio/fgetpos.c similarity index 82% rename from libc/upstream-freebsd/lib/libc/stdio/fgetpos.c rename to libc/upstream-openbsd/lib/libc/stdio/fgetpos.c index f161f4325..e6188e5a6 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fgetpos.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fgetpos.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,22 +31,13 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - #include +/* + * fgetpos: like ftello. + */ int -fgetpos(FILE * __restrict fp, fpos_t * __restrict pos) +fgetpos(FILE *fp, fpos_t *pos) { - /* - * ftello is thread-safe; no need to lock fp. - */ - if ((*pos = ftello(fp)) == (fpos_t)-1) - return (-1); - else - return (0); + return((*pos = ftello(fp)) == (fpos_t)-1); } diff --git a/libc/upstream-freebsd/lib/libc/stdio/fgets.c b/libc/upstream-openbsd/lib/libc/stdio/fgets.c similarity index 86% rename from libc/upstream-freebsd/lib/libc/stdio/fgets.c rename to libc/upstream-openbsd/lib/libc/stdio/fgets.c index 9abf559bf..0ba8770e3 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/fgets.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fgets.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fgets.c,v 1.14 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,43 +31,38 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" +#include #include #include -#include "un-namespace.h" #include "local.h" -#include "libc_private.h" /* * Read at most n-1 characters from the given file. * Stop when a newline has been read, or the count runs out. * Return first argument, or NULL if no characters were read. + * Do not return NULL if n == 1. */ char * -fgets(char * __restrict buf, int n, FILE * __restrict fp) +fgets(char *buf, int n, FILE *fp) { size_t len; char *s; unsigned char *p, *t; - if (n <= 0) /* sanity check */ + if (n <= 0) { /* sanity check */ + errno = EINVAL; return (NULL); + } FLOCKFILE(fp); - ORIENT(fp, -1); + _SET_ORIENTATION(fp, -1); s = buf; n--; /* leave space for NUL */ while (n != 0) { /* * If the buffer is empty, refill it. */ - if ((len = fp->_r) <= 0) { + if (fp->_r <= 0) { if (__srefill(fp)) { /* EOF/error: stop with partial or no line */ if (s == buf) { @@ -75,8 +71,8 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp) } break; } - len = fp->_r; } + len = fp->_r; p = fp->_p; /* @@ -93,7 +89,7 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp) fp->_r -= len; fp->_p = t; (void)memcpy((void *)s, (void *)p, len); - s[len] = 0; + s[len] = '\0'; FUNLOCKFILE(fp); return (buf); } @@ -103,7 +99,7 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp) s += len; n -= len; } - *s = 0; + *s = '\0'; FUNLOCKFILE(fp); return (buf); } diff --git a/libc/upstream-freebsd/lib/libc/stdio/fileno.c b/libc/upstream-openbsd/lib/libc/stdio/fileno.c similarity index 82% rename from libc/upstream-freebsd/lib/libc/stdio/fileno.c rename to libc/upstream-openbsd/lib/libc/stdio/fileno.c index 3ac183010..58628da3c 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/fileno.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fileno.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fileno.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,35 +31,21 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include -#include "un-namespace.h" -#include "libc_private.h" +#include "local.h" +/* + * A subroutine version of the macro fileno. + */ #undef fileno -#undef fileno_unlocked int fileno(FILE *fp) { - int fd; + int ret; FLOCKFILE(fp); - fd = __sfileno(fp); + ret = __sfileno(fp); FUNLOCKFILE(fp); - - return (fd); -} - -int -fileno_unlocked(FILE *fp) -{ - - return (__sfileno(fp)); + return (ret); } diff --git a/libc/upstream-freebsd/lib/libc/stdio/fpurge.c b/libc/upstream-openbsd/lib/libc/stdio/fpurge.c similarity index 80% rename from libc/upstream-freebsd/lib/libc/stdio/fpurge.c rename to libc/upstream-openbsd/lib/libc/stdio/fpurge.c index f205bdfc3..65bd74994 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/fpurge.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fpurge.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fpurge.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,19 +31,10 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include #include #include -#include "un-namespace.h" #include "local.h" -#include "libc_private.h" /* * fpurge: like fflush, but without writing anything: leave the @@ -51,19 +43,19 @@ __FBSDID("$FreeBSD$"); int fpurge(FILE *fp) { - int retval; FLOCKFILE(fp); if (!fp->_flags) { + FUNLOCKFILE(fp); errno = EBADF; - retval = EOF; - } else { - if (HASUB(fp)) - FREEUB(fp); - fp->_p = fp->_bf._base; - fp->_r = 0; - fp->_w = fp->_flags & (__SLBF|__SNBF|__SRD) ? 0 : fp->_bf._size; - retval = 0; + return(EOF); } + + if (HASUB(fp)) + FREEUB(fp); + WCIO_FREE(fp); + fp->_p = fp->_bf._base; + fp->_r = 0; + fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; FUNLOCKFILE(fp); - return (retval); + return (0); } diff --git a/libc/stdio/fputc.c b/libc/upstream-openbsd/lib/libc/stdio/fputc.c similarity index 96% rename from libc/stdio/fputc.c rename to libc/upstream-openbsd/lib/libc/stdio/fputc.c index 90809e234..98e39603f 100644 --- a/libc/stdio/fputc.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fputc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fputc.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: fputc.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. diff --git a/libc/upstream-freebsd/lib/libc/stdio/fputs.c b/libc/upstream-openbsd/lib/libc/stdio/fputs.c similarity index 83% rename from libc/upstream-freebsd/lib/libc/stdio/fputs.c rename to libc/upstream-openbsd/lib/libc/stdio/fputs.c index 3b8f2c9d1..ea8556a29 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/fputs.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fputs.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fputs.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,37 +31,28 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include #include -#include "un-namespace.h" -#include "fvwrite.h" -#include "libc_private.h" #include "local.h" +#include "fvwrite.h" /* * Write the given string to the given file. */ int -fputs(const char * __restrict s, FILE * __restrict fp) +fputs(const char *s, FILE *fp) { - int retval; struct __suio uio; struct __siov iov; + int ret; iov.iov_base = (void *)s; iov.iov_len = uio.uio_resid = strlen(s); uio.uio_iov = &iov; uio.uio_iovcnt = 1; FLOCKFILE(fp); - ORIENT(fp, -1); - retval = __sfvwrite(fp, &uio); + _SET_ORIENTATION(fp, -1); + ret = __sfvwrite(fp, &uio); FUNLOCKFILE(fp); - return (retval); + return (ret); } diff --git a/libc/stdio/fscanf.c b/libc/upstream-openbsd/lib/libc/stdio/fscanf.c similarity index 95% rename from libc/stdio/fscanf.c rename to libc/upstream-openbsd/lib/libc/stdio/fscanf.c index 2f3fcebb2..5fd10d4a4 100644 --- a/libc/stdio/fscanf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fscanf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fscanf.c,v 1.9 2005/10/10 17:37:44 espie Exp $ */ +/* $OpenBSD: fscanf.c,v 1.10 2011/05/30 18:48:33 martynas Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -34,6 +34,7 @@ #include #include +/* SCANFLIKE2 */ int fscanf(FILE *fp, const char *fmt, ...) { diff --git a/libc/stdio/fseek.c b/libc/upstream-openbsd/lib/libc/stdio/fseek.c similarity index 93% rename from libc/stdio/fseek.c rename to libc/upstream-openbsd/lib/libc/stdio/fseek.c index 38697f53f..cdd40b62f 100644 --- a/libc/stdio/fseek.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fseek.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fseek.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: fseek.c,v 1.11 2012/05/21 22:24:19 matthew Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -185,7 +185,7 @@ fseeko(FILE *fp, off_t offset, int whence) * skip this; see fgetln.c.) */ if ((fp->_flags & __SMOD) == 0 && - target >= curoff && target < (fpos_t)(curoff + n)) { + target >= curoff && target < curoff + n) { int o = target - curoff; fp->_p = fp->_bf._base + o; @@ -209,13 +209,13 @@ fseeko(FILE *fp, off_t offset, int whence) if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR) goto dumb; fp->_r = 0; - fp->_p = fp->_bf._base; + fp->_p = fp->_bf._base; if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; n = target - curoff; if (n) { - if (__srefill(fp) || (size_t)fp->_r < n) + if (__srefill(fp) || fp->_r < n) goto dumb; fp->_p += n; fp->_r -= n; @@ -244,17 +244,8 @@ dumb: return (0); } -/* - * fseek()'s offset is a long and sizeof(off_t) != sizeof(long) on all arches - */ -#if defined(__alpha__) && defined(__indr_reference) -__indr_reference(fseeko, fseek); -#else int fseek(FILE *fp, long offset, int whence) { - off_t off = offset; - - return(fseeko(fp, off, whence)); + return (fseeko(fp, offset, whence)); } -#endif diff --git a/libc/upstream-freebsd/lib/libc/stdio/fsetpos.c b/libc/upstream-openbsd/lib/libc/stdio/fsetpos.c similarity index 88% rename from libc/upstream-freebsd/lib/libc/stdio/fsetpos.c rename to libc/upstream-openbsd/lib/libc/stdio/fsetpos.c index c6b8b7859..9624fe565 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/fsetpos.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fsetpos.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fsetpos.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,17 +31,10 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include #include /* - * fsetpos: like fseek. + * fsetpos: like fseeko. */ int fsetpos(FILE *iop, const fpos_t *pos) diff --git a/libc/stdio/ftell.c b/libc/upstream-openbsd/lib/libc/stdio/ftell.c similarity index 88% rename from libc/stdio/ftell.c rename to libc/upstream-openbsd/lib/libc/stdio/ftell.c index 9f850ee85..0a2016ce1 100644 --- a/libc/stdio/ftell.c +++ b/libc/upstream-openbsd/lib/libc/stdio/ftell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftell.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: ftell.c,v 1.10 2012/05/21 22:24:19 matthew Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -33,6 +33,7 @@ #include #include +#include #include "local.h" /* @@ -46,14 +47,14 @@ ftello(FILE *fp) if (fp->_seek == NULL) { errno = ESPIPE; /* historic practice */ pos = -1; - goto out; + goto out; } /* * Find offset of underlying I/O object, then * adjust for buffered bytes. */ - FLOCKFILE(fp); + FLOCKFILE(fp); __sflush(fp); /* may adjust seek offset on append stream */ if (fp->_flags & __SOFF) pos = fp->_offset; @@ -83,18 +84,13 @@ out: FUNLOCKFILE(fp); return (pos); } -/* - * ftell() returns a long and sizeof(off_t) != sizeof(long) on all arches - */ -#if defined(__alpha__) && defined(__indr_reference) -__indr_reference(ftello, ftell); -#else long ftell(FILE *fp) { - long pos; - - pos = (long)ftello(fp); - return(pos); + off_t offset = ftello(fp); + if (offset > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + return ((long)offset); } -#endif diff --git a/libc/upstream-freebsd/lib/libc/stdio/funopen.c b/libc/upstream-openbsd/lib/libc/stdio/funopen.c similarity index 86% rename from libc/upstream-freebsd/lib/libc/stdio/funopen.c rename to libc/upstream-openbsd/lib/libc/stdio/funopen.c index 983fe5011..b85ee96a1 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/funopen.c +++ b/libc/upstream-openbsd/lib/libc/stdio/funopen.c @@ -1,3 +1,4 @@ +/* $OpenBSD: funopen.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,23 +31,14 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - #include #include - #include "local.h" FILE * -funopen(const void *cookie, - int (*readfn)(void *, char *, int), +funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int), - fpos_t (*seekfn)(void *, fpos_t, int), - int (*closefn)(void *)) + fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *)) { FILE *fp; int flags; @@ -67,7 +59,7 @@ funopen(const void *cookie, return (NULL); fp->_flags = flags; fp->_file = -1; - fp->_cookie = (void *)cookie; + fp->_cookie = (void *)cookie; /* SAFE: cookie not modified */ fp->_read = readfn; fp->_write = writefn; fp->_seek = seekfn; diff --git a/libc/upstream-freebsd/lib/libc/stdio/fwalk.c b/libc/upstream-openbsd/lib/libc/stdio/fwalk.c similarity index 79% rename from libc/upstream-freebsd/lib/libc/stdio/fwalk.c rename to libc/upstream-openbsd/lib/libc/stdio/fwalk.c index 151837b29..8ac6628aa 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/fwalk.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fwalk.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fwalk.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,13 +31,7 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include +#include #include #include "local.h" #include "glue.h" @@ -49,17 +44,10 @@ _fwalk(int (*function)(FILE *)) struct glue *g; ret = 0; - /* - * It should be safe to walk the list without locking it; - * new nodes are only added to the end and none are ever - * removed. - * - * Avoid locking this list while walking it or else you will - * introduce a potential deadlock in [at least] refill.c. - */ for (g = &__sglue; g != NULL; g = g->next) - for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) + for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) { if ((fp->_flags != 0) && ((fp->_flags & __SIGN) == 0)) ret |= (*function)(fp); + } return (ret); } diff --git a/libc/upstream-freebsd/lib/libc/stdio/getc.c b/libc/upstream-openbsd/lib/libc/stdio/getc.c similarity index 82% rename from libc/upstream-freebsd/lib/libc/stdio/getc.c rename to libc/upstream-openbsd/lib/libc/stdio/getc.c index 4963c8ce6..6879cbb79 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/getc.c +++ b/libc/upstream-openbsd/lib/libc/stdio/getc.c @@ -1,3 +1,4 @@ +/* $OpenBSD: getc.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,36 +31,32 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include -#include "un-namespace.h" -#include "libc_private.h" #include "local.h" -#undef getc +/* + * A subroutine version of the macro getc_unlocked. + */ #undef getc_unlocked -int -getc(FILE *fp) -{ - int retval; - FLOCKFILE(fp); - /* Orientation set by __sgetc() when buffer is empty. */ - /* ORIENT(fp, -1); */ - retval = __sgetc(fp); - FUNLOCKFILE(fp); - return (retval); -} - int getc_unlocked(FILE *fp) { - return (__sgetc(fp)); } + +/* + * A subroutine version of the macro getc. + */ +#undef getc + +int +getc(FILE *fp) +{ + int c; + + FLOCKFILE(fp); + c = __sgetc(fp); + FUNLOCKFILE(fp); + return (c); +} diff --git a/libc/upstream-freebsd/lib/libc/stdio/getchar.c b/libc/upstream-openbsd/lib/libc/stdio/getchar.c similarity index 78% rename from libc/upstream-freebsd/lib/libc/stdio/getchar.c rename to libc/upstream-openbsd/lib/libc/stdio/getchar.c index 21040bc8c..550817de0 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/getchar.c +++ b/libc/upstream-openbsd/lib/libc/stdio/getchar.c @@ -1,3 +1,4 @@ +/* $OpenBSD: getchar.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,39 +31,28 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); +#include /* - * A subroutine version of the macro getchar. + * A subroutine version of the macro getchar_unlocked. */ -#include "namespace.h" -#include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" - -#undef getchar #undef getchar_unlocked -int -getchar() -{ - int retval; - FLOCKFILE(stdin); - /* Orientation set by __sgetc() when buffer is empty. */ - /* ORIENT(stdin, -1); */ - retval = __sgetc(stdin); - FUNLOCKFILE(stdin); - return (retval); -} - int getchar_unlocked(void) { - - return (__sgetc(stdin)); + return (getc_unlocked(stdin)); +} + + +/* + * A subroutine version of the macro getchar. + */ + +#undef getchar + +int +getchar(void) +{ + return (getc(stdin)); } diff --git a/libc/upstream-netbsd/lib/libc/stdio/getdelim.c b/libc/upstream-openbsd/lib/libc/stdio/getdelim.c similarity index 88% rename from libc/upstream-netbsd/lib/libc/stdio/getdelim.c rename to libc/upstream-openbsd/lib/libc/stdio/getdelim.c index acce3764b..dcde0c34e 100644 --- a/libc/upstream-netbsd/lib/libc/stdio/getdelim.c +++ b/libc/upstream-openbsd/lib/libc/stdio/getdelim.c @@ -1,3 +1,4 @@ +/* $OpenBSD: getdelim.c,v 1.1 2012/03/21 23:44:35 fgsch Exp $ */ /* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */ /* @@ -27,41 +28,28 @@ * 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, +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); + FLOCKFILE(fp); if (buf == NULL || buflen == NULL) { errno = EINVAL; @@ -100,6 +88,7 @@ __getdelim(char **__restrict buf, size_t *__restrict buflen, if (newlen > *buflen) { if (newlen < MINBUF) newlen = MINBUF; +#define powerof2(x) ((((x)-1)&(x))==0) if (!powerof2(newlen)) { /* Grow the buffer to the next power of 2 */ newlen--; @@ -128,8 +117,10 @@ __getdelim(char **__restrict buf, size_t *__restrict buflen, off += len; } while (p == NULL); + FUNLOCKFILE(fp); + /* POSIX demands we return -1 on EOF. */ - if (off == 0) + if (off == 0) return -1; if (*buf != NULL) @@ -138,17 +129,6 @@ __getdelim(char **__restrict buf, size_t *__restrict buflen, error: fp->_flags |= __SERR; + FUNLOCKFILE(fp); 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-openbsd/lib/libc/stdio/getline.c similarity index 90% rename from libc/upstream-netbsd/lib/libc/stdio/getline.c rename to libc/upstream-openbsd/lib/libc/stdio/getline.c index e5d4bab26..55ad39675 100644 --- a/libc/upstream-netbsd/lib/libc/stdio/getline.c +++ b/libc/upstream-openbsd/lib/libc/stdio/getline.c @@ -1,3 +1,4 @@ +/* $OpenBSD: getline.c,v 1.1 2012/03/21 23:44:35 fgsch Exp $ */ /* $NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $ */ /* @@ -27,17 +28,8 @@ * 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) { diff --git a/libc/stdio/gets.c b/libc/upstream-openbsd/lib/libc/stdio/gets.c similarity index 97% rename from libc/stdio/gets.c rename to libc/upstream-openbsd/lib/libc/stdio/gets.c index 93e2edd12..c2e1b5057 100644 --- a/libc/stdio/gets.c +++ b/libc/upstream-openbsd/lib/libc/stdio/gets.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gets.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: gets.c,v 1.12 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. diff --git a/libc/upstream-openbsd/lib/libc/stdio/perror.c b/libc/upstream-openbsd/lib/libc/stdio/perror.c new file mode 100644 index 000000000..8728718c5 --- /dev/null +++ b/libc/upstream-openbsd/lib/libc/stdio/perror.c @@ -0,0 +1,62 @@ +/* $OpenBSD: perror.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */ +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include + +void +perror(const char *s) +{ + struct iovec *v; + struct iovec iov[4]; + char buf[NL_TEXTMAX]; + + v = iov; + if (s && *s) { + v->iov_base = (char *)s; + v->iov_len = strlen(s); + v++; + v->iov_base = ": "; + v->iov_len = 2; + v++; + } + (void)strerror_r(errno, buf, sizeof(buf)); + v->iov_base = buf; + v->iov_len = strlen(v->iov_base); + v++; + v->iov_base = "\n"; + v->iov_len = 1; + (void)writev(STDERR_FILENO, iov, (v - iov) + 1); +} diff --git a/libc/stdio/printf.c b/libc/upstream-openbsd/lib/libc/stdio/printf.c similarity index 95% rename from libc/stdio/printf.c rename to libc/upstream-openbsd/lib/libc/stdio/printf.c index 614b43515..09bb3d7f7 100644 --- a/libc/stdio/printf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/printf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printf.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: printf.c,v 1.8 2011/05/30 18:48:33 martynas Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -34,6 +34,7 @@ #include #include +/* PRINTFLIKE1 */ int printf(const char *fmt, ...) { diff --git a/libc/upstream-freebsd/lib/libc/stdio/putc.c b/libc/upstream-openbsd/lib/libc/stdio/putc.c similarity index 80% rename from libc/upstream-freebsd/lib/libc/stdio/putc.c rename to libc/upstream-openbsd/lib/libc/stdio/putc.c index aaffece49..762fecb2d 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/putc.c +++ b/libc/upstream-openbsd/lib/libc/stdio/putc.c @@ -1,3 +1,4 @@ +/* $OpenBSD: putc.c,v 1.12 2009/11/21 10:11:54 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,36 +31,38 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include -#include "un-namespace.h" +#include #include "local.h" -#include "libc_private.h" -#undef putc +/* + * A subroutine version of the macro putc_unlocked. + */ #undef putc_unlocked +int +putc_unlocked(int c, FILE *fp) +{ + if (cantwrite(fp)) { + errno = EBADF; + return (EOF); + } + _SET_ORIENTATION(fp, -1); + return (__sputc(c, fp)); +} + +/* + * A subroutine version of the macro putc. + */ +#undef putc + int putc(int c, FILE *fp) { - int retval; + int ret; + FLOCKFILE(fp); - /* Orientation set by __sputc() when buffer is full. */ - /* ORIENT(fp, -1); */ - retval = __sputc(c, fp); + ret = putc_unlocked(c, fp); FUNLOCKFILE(fp); - return (retval); -} - -int -putc_unlocked(int ch, FILE *fp) -{ - - return (__sputc(ch, fp)); + return (ret); } diff --git a/libc/upstream-freebsd/lib/libc/stdio/putchar.c b/libc/upstream-openbsd/lib/libc/stdio/putchar.c similarity index 78% rename from libc/upstream-freebsd/lib/libc/stdio/putchar.c rename to libc/upstream-openbsd/lib/libc/stdio/putchar.c index 756155902..233cdfd02 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/putchar.c +++ b/libc/upstream-openbsd/lib/libc/stdio/putchar.c @@ -1,3 +1,4 @@ +/* $OpenBSD: putchar.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,20 +31,21 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include -#include "un-namespace.h" -#include "local.h" -#include "libc_private.h" + +#undef putchar_unlocked +/* + * A subrouting version of the macro putchar_unlocked + */ +int +putchar_unlocked(int c) +{ + FILE *so = stdout; + + return (putc_unlocked(c,so)); +} #undef putchar -#undef putchar_unlocked /* * A subroutine version of the macro putchar @@ -51,20 +53,7 @@ __FBSDID("$FreeBSD$"); int putchar(int c) { - int retval; FILE *so = stdout; - FLOCKFILE(so); - /* Orientation set by __sputc() when buffer is full. */ - /* ORIENT(so, -1); */ - retval = __sputc(c, so); - FUNLOCKFILE(so); - return (retval); -} - -int -putchar_unlocked(int ch) -{ - - return (__sputc(ch, stdout)); + return (putc(c, so)); } diff --git a/libc/upstream-freebsd/lib/libc/stdio/puts.c b/libc/upstream-openbsd/lib/libc/stdio/puts.c similarity index 84% rename from libc/upstream-freebsd/lib/libc/stdio/puts.c rename to libc/upstream-openbsd/lib/libc/stdio/puts.c index 5ee7fc1c6..655aed7ec 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/puts.c +++ b/libc/upstream-openbsd/lib/libc/stdio/puts.c @@ -1,3 +1,4 @@ +/* $OpenBSD: puts.c,v 1.11 2009/11/21 09:53:44 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,30 +31,21 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)puts.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include "namespace.h" #include #include -#include "un-namespace.h" -#include "fvwrite.h" -#include "libc_private.h" #include "local.h" +#include "fvwrite.h" /* * Write the given string to stdout, appending a newline. */ int -puts(char const *s) +puts(const char *s) { - int retval; size_t c = strlen(s); struct __suio uio; struct __siov iov[2]; + int ret; iov[0].iov_base = (void *)s; iov[0].iov_len = c; @@ -63,8 +55,8 @@ puts(char const *s) uio.uio_iov = &iov[0]; uio.uio_iovcnt = 2; FLOCKFILE(stdout); - ORIENT(stdout, -1); - retval = __sfvwrite(stdout, &uio) ? EOF : '\n'; + _SET_ORIENTATION(stdout, -1); + ret = __sfvwrite(stdout, &uio); FUNLOCKFILE(stdout); - return (retval); + return (ret ? EOF : '\n'); } diff --git a/libc/stdio/refill.c b/libc/upstream-openbsd/lib/libc/stdio/refill.c similarity index 96% rename from libc/stdio/refill.c rename to libc/upstream-openbsd/lib/libc/stdio/refill.c index 7cb6b7892..165c72a64 100644 --- a/libc/stdio/refill.c +++ b/libc/upstream-openbsd/lib/libc/stdio/refill.c @@ -1,4 +1,4 @@ -/* $OpenBSD: refill.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: refill.c,v 1.11 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -40,7 +40,7 @@ static int lflush(FILE *fp) { if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) - return (__sflush_locked(fp)); /* ignored... */ + return (__sflush_locked(fp)); /* ignored... */ return (0); } @@ -110,7 +110,7 @@ __srefill(FILE *fp) /* Now flush this file without locking it. */ if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) - __sflush(fp); + __sflush(fp); } fp->_p = fp->_bf._base; fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size); diff --git a/libc/upstream-freebsd/lib/libc/stdio/remove.c b/libc/upstream-openbsd/lib/libc/stdio/remove.c similarity index 86% rename from libc/upstream-freebsd/lib/libc/stdio/remove.c rename to libc/upstream-openbsd/lib/libc/stdio/remove.c index 2e984baf9..d09d76f9d 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/remove.c +++ b/libc/upstream-openbsd/lib/libc/stdio/remove.c @@ -1,3 +1,5 @@ +/* $OpenBSD: remove.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */ + /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,25 +32,18 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include #include +#include +#include int remove(const char *file) { - struct stat sb; + struct stat st; - if (lstat(file, &sb) < 0) + if (lstat(file, &st) < 0) return (-1); - if (S_ISDIR(sb.st_mode)) + if (S_ISDIR(st.st_mode)) return (rmdir(file)); return (unlink(file)); } diff --git a/libc/stdio/rewind.c b/libc/upstream-openbsd/lib/libc/stdio/rewind.c similarity index 100% rename from libc/stdio/rewind.c rename to libc/upstream-openbsd/lib/libc/stdio/rewind.c diff --git a/libc/upstream-freebsd/lib/libc/stdio/rget.c b/libc/upstream-openbsd/lib/libc/stdio/rget.c similarity index 91% rename from libc/upstream-freebsd/lib/libc/stdio/rget.c rename to libc/upstream-openbsd/lib/libc/stdio/rget.c index bdc031167..4cd97cbe9 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/rget.c +++ b/libc/upstream-openbsd/lib/libc/stdio/rget.c @@ -1,3 +1,4 @@ +/* $OpenBSD: rget.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,12 +31,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rget.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - #include #include "local.h" @@ -47,6 +42,7 @@ __FBSDID("$FreeBSD$"); int __srget(FILE *fp) { + _SET_ORIENTATION(fp, -1); if (__srefill(fp) == 0) { fp->_r--; return (*fp->_p++); diff --git a/libc/stdio/scanf.c b/libc/upstream-openbsd/lib/libc/stdio/scanf.c similarity index 95% rename from libc/stdio/scanf.c rename to libc/upstream-openbsd/lib/libc/stdio/scanf.c index 71194d04e..90cf12a3b 100644 --- a/libc/stdio/scanf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/scanf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scanf.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: scanf.c,v 1.10 2011/05/30 18:48:33 martynas Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -34,6 +34,7 @@ #include #include +/* SCANFLIKE1 */ int scanf(const char *fmt, ...) { diff --git a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c b/libc/upstream-openbsd/lib/libc/stdio/setbuf.c similarity index 88% rename from libc/upstream-freebsd/lib/libc/stdio/setbuf.c rename to libc/upstream-openbsd/lib/libc/stdio/setbuf.c index 5c65f976c..883b89532 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/setbuf.c @@ -1,3 +1,4 @@ +/* $OpenBSD: setbuf.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,17 +31,11 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)setbuf.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - #include #include "local.h" void -setbuf(FILE * __restrict fp, char * __restrict buf) +setbuf(FILE *fp, char *buf) { (void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ); } diff --git a/libc/upstream-freebsd/lib/libc/stdio/setbuffer.c b/libc/upstream-openbsd/lib/libc/stdio/setbuffer.c similarity index 88% rename from libc/upstream-freebsd/lib/libc/stdio/setbuffer.c rename to libc/upstream-openbsd/lib/libc/stdio/setbuffer.c index af5eb3cab..8725ff795 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/setbuffer.c +++ b/libc/upstream-openbsd/lib/libc/stdio/setbuffer.c @@ -1,3 +1,4 @@ +/* $OpenBSD: setbuffer.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -30,19 +31,13 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)setbuffer.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - #include void setbuffer(FILE *fp, char *buf, int size) { - (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size); + (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, size); } /* diff --git a/libc/stdio/stdio.c b/libc/upstream-openbsd/lib/libc/stdio/stdio.c similarity index 99% rename from libc/stdio/stdio.c rename to libc/upstream-openbsd/lib/libc/stdio/stdio.c index 1596ebf6c..a4a27b53b 100644 --- a/libc/stdio/stdio.c +++ b/libc/upstream-openbsd/lib/libc/stdio/stdio.c @@ -45,7 +45,7 @@ __sread(void *cookie, char *buf, int n) { FILE *fp = cookie; int ret; - + ret = read(fp->_file, buf, n); /* if the read succeeded, update the current offset */ if (ret >= 0) @@ -71,7 +71,7 @@ __sseek(void *cookie, fpos_t offset, int whence) { FILE *fp = cookie; off_t ret; - + ret = lseek(fp->_file, (off_t)offset, whence); if (ret == (off_t)-1) fp->_flags &= ~__SOFF; diff --git a/libc/upstream-freebsd/lib/libc/stdio/tempnam.c b/libc/upstream-openbsd/lib/libc/stdio/tempnam.c similarity index 71% rename from libc/upstream-freebsd/lib/libc/stdio/tempnam.c rename to libc/upstream-openbsd/lib/libc/stdio/tempnam.c index e15746f31..e3f2ab647 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/tempnam.c +++ b/libc/upstream-openbsd/lib/libc/stdio/tempnam.c @@ -1,3 +1,4 @@ +/* $OpenBSD: tempnam.c,v 1.17 2013/09/30 12:02:35 millert Exp $ */ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -27,19 +28,13 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - -#include #include +#include +#include #include #include #include #include -#include __warn_references(tempnam, "warning: tempnam() possibly used unsafely; consider using mkstemp()"); @@ -49,36 +44,53 @@ extern char *_mktemp(char *); char * tempnam(const char *dir, const char *pfx) { - int sverrno; + int sverrno, len; char *f, *name; - if (!(name = malloc(MAXPATHLEN))) + if (!(name = malloc(PATH_MAX))) return(NULL); if (!pfx) pfx = "tmp."; - if (issetugid() == 0 && (f = getenv("TMPDIR"))) { - (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, - *(f + strlen(f) - 1) == '/'? "": "/", pfx); + if (issetugid() == 0 && (f = getenv("TMPDIR")) && *f != '\0') { + len = snprintf(name, PATH_MAX, "%s%s%sXXXXXXXXXX", f, + f[strlen(f) - 1] == '/' ? "" : "/", pfx); + if (len < 0 || len >= PATH_MAX) { + errno = ENAMETOOLONG; + return(NULL); + } if ((f = _mktemp(name))) return(f); } - if ((f = (char *)dir)) { - (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, - *(f + strlen(f) - 1) == '/'? "": "/", pfx); + if (dir != NULL) { + f = *dir ? (char *)dir : "."; + len = snprintf(name, PATH_MAX, "%s%s%sXXXXXXXXXX", f, + f[strlen(f) - 1] == '/' ? "" : "/", pfx); + if (len < 0 || len >= PATH_MAX) { + errno = ENAMETOOLONG; + return(NULL); + } if ((f = _mktemp(name))) return(f); } f = P_tmpdir; - (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); + len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx); + if (len < 0 || len >= PATH_MAX) { + errno = ENAMETOOLONG; + return(NULL); + } if ((f = _mktemp(name))) return(f); f = _PATH_TMP; - (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); + len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx); + if (len < 0 || len >= PATH_MAX) { + errno = ENAMETOOLONG; + return(NULL); + } if ((f = _mktemp(name))) return(f); diff --git a/libc/upstream-freebsd/lib/libc/stdio/tmpnam.c b/libc/upstream-openbsd/lib/libc/stdio/tmpnam.c similarity index 88% rename from libc/upstream-freebsd/lib/libc/stdio/tmpnam.c rename to libc/upstream-openbsd/lib/libc/stdio/tmpnam.c index ce32dcc28..32e0a2202 100644 --- a/libc/upstream-freebsd/lib/libc/stdio/tmpnam.c +++ b/libc/upstream-openbsd/lib/libc/stdio/tmpnam.c @@ -1,3 +1,4 @@ +/* $OpenBSD: tmpnam.c,v 1.10 2005/08/08 08:05:36 espie Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -30,12 +31,6 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)tmpnam.c 8.3 (Berkeley) 3/28/94"; -#endif /* LIBC_SCCS and not lint */ -#include -__FBSDID("$FreeBSD$"); - #include #include @@ -54,7 +49,7 @@ tmpnam(char *s) if (s == NULL) s = buf; - (void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount); + (void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXXXXX", P_tmpdir, tmpcount); ++tmpcount; return (_mktemp(s)); } diff --git a/libc/stdio/ungetc.c b/libc/upstream-openbsd/lib/libc/stdio/ungetc.c similarity index 98% rename from libc/stdio/ungetc.c rename to libc/upstream-openbsd/lib/libc/stdio/ungetc.c index b493d21be..675733aa6 100644 --- a/libc/stdio/ungetc.c +++ b/libc/upstream-openbsd/lib/libc/stdio/ungetc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ungetc.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: ungetc.c,v 1.12 2009/11/09 00:18:27 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. diff --git a/libc/stdio/vasprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c similarity index 91% rename from libc/stdio/vasprintf.c rename to libc/upstream-openbsd/lib/libc/stdio/vasprintf.c index 1630ccbd0..8fe7c5bb5 100644 --- a/libc/stdio/vasprintf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vasprintf.c,v 1.13 2006/01/06 18:53:04 millert Exp $ */ +/* $OpenBSD: vasprintf.c,v 1.16 2009/11/09 00:18:27 kurt Exp $ */ /* * Copyright (c) 1997 Todd C. Miller @@ -48,7 +48,10 @@ vasprintf(char **str, const char *fmt, __va_list ap) return (ret); err: - free(f._bf._base); + if (f._bf._base) { + free(f._bf._base); + f._bf._base = NULL; + } *str = NULL; errno = ENOMEM; return (-1); diff --git a/libc/stdio/vprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vprintf.c similarity index 100% rename from libc/stdio/vprintf.c rename to libc/upstream-openbsd/lib/libc/stdio/vprintf.c diff --git a/libc/stdio/vscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vscanf.c similarity index 100% rename from libc/stdio/vscanf.c rename to libc/upstream-openbsd/lib/libc/stdio/vscanf.c diff --git a/libc/stdio/vsnprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vsnprintf.c similarity index 97% rename from libc/stdio/vsnprintf.c rename to libc/upstream-openbsd/lib/libc/stdio/vsnprintf.c index ca30f9401..8b1a088da 100644 --- a/libc/stdio/vsnprintf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vsnprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vsnprintf.c,v 1.12 2006/01/06 18:53:04 millert Exp $ */ +/* $OpenBSD: vsnprintf.c,v 1.15 2009/11/09 00:18:28 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. diff --git a/libc/stdio/vsprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vsprintf.c similarity index 96% rename from libc/stdio/vsprintf.c rename to libc/upstream-openbsd/lib/libc/stdio/vsprintf.c index 846ee8a90..308ff375a 100644 --- a/libc/stdio/vsprintf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vsprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vsprintf.c,v 1.13 2006/01/06 18:53:04 millert Exp $ */ +/* $OpenBSD: vsprintf.c,v 1.16 2009/11/09 00:18:28 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. diff --git a/libc/stdio/wbuf.c b/libc/upstream-openbsd/lib/libc/stdio/wbuf.c similarity index 98% rename from libc/stdio/wbuf.c rename to libc/upstream-openbsd/lib/libc/stdio/wbuf.c index e09ac594e..6aa00e1d6 100644 --- a/libc/stdio/wbuf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/wbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wbuf.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: wbuf.c,v 1.12 2009/11/09 00:18:28 kurt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. diff --git a/libc/stdlib/strtoull.c b/libc/upstream-openbsd/lib/libc/stdlib/atoi.c similarity index 74% rename from libc/stdlib/strtoull.c rename to libc/upstream-openbsd/lib/libc/stdlib/atoi.c index 36698acc6..b0842678e 100644 --- a/libc/stdlib/strtoull.c +++ b/libc/upstream-openbsd/lib/libc/stdlib/atoi.c @@ -1,6 +1,6 @@ -/* $OpenBSD: strtoull.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */ -/*- - * Copyright (c) 1992 The Regents of the University of California. +/* $OpenBSD: atoi.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ +/* + * Copyright (c) 1988 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,22 +28,10 @@ * SUCH DAMAGE. */ -#include - -#include -#include -#include #include -#include -/* - * Convert a string to an unsigned long long. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -unsigned long long -strtoull(const char *nptr, char **endptr, int base) +int +atoi(const char *str) { - return (unsigned long long)strtoumax(nptr, endptr, base); + return((int)strtol(str, (char **)NULL, 10)); } diff --git a/libc/upstream-openbsd/lib/libc/stdlib/atol.c b/libc/upstream-openbsd/lib/libc/stdlib/atol.c new file mode 100644 index 000000000..197080440 --- /dev/null +++ b/libc/upstream-openbsd/lib/libc/stdlib/atol.c @@ -0,0 +1,37 @@ +/* $OpenBSD: atol.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ +/* + * Copyright (c) 1988 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 + +long +atol(const char *str) +{ + return(strtol(str, (char **)NULL, 10)); +} diff --git a/libc/stdlib/strtoll.c b/libc/upstream-openbsd/lib/libc/stdlib/atoll.c similarity index 76% rename from libc/stdlib/strtoll.c rename to libc/upstream-openbsd/lib/libc/stdlib/atoll.c index 3c75271b0..a65e682cf 100644 --- a/libc/stdlib/strtoll.c +++ b/libc/upstream-openbsd/lib/libc/stdlib/atoll.c @@ -1,6 +1,6 @@ -/* $OpenBSD: strtoll.c,v 1.6 2005/11/10 10:00:17 espie Exp $ */ -/*- - * Copyright (c) 1992 The Regents of the University of California. +/* $OpenBSD: atoll.c,v 1.3 2005/08/08 08:05:36 espie Exp $ */ +/* + * Copyright (c) 1988 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,23 +28,11 @@ * SUCH DAMAGE. */ -#include - -#include -#include -#include #include -#include -/* - * Convert a string to a long long. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ long long -strtoll(const char *nptr, char **endptr, int base) +atoll(str) + const char *str; { - return strtoimax(nptr, endptr, base); + return(strtoll(str, (char **)NULL, 10)); } - diff --git a/libc/stdlib/strtoimax.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c similarity index 82% rename from libc/stdlib/strtoimax.c rename to libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c index 0b4323d3e..2c77f4165 100644 --- a/libc/stdlib/strtoimax.c +++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c @@ -91,40 +91,9 @@ strtoimax(const char *nptr, char **endptr, int base) * Set any if any `digits' consumed; make it negative to indicate * overflow. */ - - /* BIONIC: avoid division and module for common cases */ -#define CASE_BASE(x) \ - case x: \ - if (neg) { \ - cutlim = INTMAX_MIN % x; \ - cutoff = INTMAX_MIN / x; \ - } else { \ - cutlim = INTMAX_MAX % x; \ - cutoff = INTMAX_MAX / x; \ - }; \ - break - - switch (base) { - case 4: - if (neg) { - cutlim = (int)(INTMAX_MIN % 4); - cutoff = INTMAX_MIN / 4; - } else { - cutlim = (int)(INTMAX_MAX % 4); - cutoff = INTMAX_MAX / 4; - } - break; - - CASE_BASE(8); - CASE_BASE(10); - CASE_BASE(16); - default: - cutoff = neg ? INTMAX_MIN : INTMAX_MAX; - cutlim = cutoff % base; - cutoff /= base; - } -#undef CASE_BASE - + cutoff = neg ? INTMAX_MIN : INTMAX_MAX; + cutlim = cutoff % base; + cutoff /= base; if (neg) { if (cutlim > 0) { cutlim -= base; diff --git a/libc/stdlib/strtol.c b/libc/upstream-openbsd/lib/libc/stdlib/strtol.c similarity index 93% rename from libc/stdlib/strtol.c rename to libc/upstream-openbsd/lib/libc/stdlib/strtol.c index a3cdbcdd2..dc2cf8871 100644 --- a/libc/stdlib/strtol.c +++ b/libc/upstream-openbsd/lib/libc/stdlib/strtol.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strtol.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: strtol.c,v 1.9 2013/04/17 17:40:35 tedu Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -48,6 +48,17 @@ strtol(const char *nptr, char **endptr, int base) int c; int neg, any, cutlim; + /* + * Ensure that base is between 2 and 36 inclusive, or the special + * value of 0. + */ + if (base != 0 && (base < 2 || base > 36)) { + if (endptr != 0) + *endptr = (char *)nptr; + errno = EINVAL; + return 0; + } + /* * Skip white space and pick up leading +/- sign if any. * If base is 0, allow 0x for hex and 0 for octal, else diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c new file mode 100644 index 000000000..4bcc5565b --- /dev/null +++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c @@ -0,0 +1,144 @@ +/* $OpenBSD: strtoll.c,v 1.7 2013/03/28 18:09:38 martynas Exp $ */ +/*- + * Copyright (c) 1992 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 + +#include +#include +#include +#include + +/* + * Convert a string to a long long. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +long long +strtoll(const char *nptr, char **endptr, int base) +{ + const char *s; + long long acc, cutoff; + int c; + int neg, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + do { + c = (unsigned char) *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for long longs is + * [-9223372036854775808..9223372036854775807] and the input base + * is 10, cutoff will be set to 922337203685477580 and cutlim to + * either 7 (neg==0) or 8 (neg==1), meaning that if we have + * accumulated a value > 922337203685477580, or equal but the + * next digit is > 7 (or 8), the number is too big, and we will + * return a range error. + * + * Set any if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? LLONG_MIN : LLONG_MAX; + cutlim = cutoff % base; + cutoff /= base; + if (neg) { + if (cutlim > 0) { + cutlim -= base; + cutoff += 1; + } + cutlim = -cutlim; + } + for (acc = 0, any = 0;; c = (unsigned char) *s++) { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0) + continue; + if (neg) { + if (acc < cutoff || (acc == cutoff && c > cutlim)) { + any = -1; + acc = LLONG_MIN; + errno = ERANGE; + } else { + any = 1; + acc *= base; + acc -= c; + } + } else { + if (acc > cutoff || (acc == cutoff && c > cutlim)) { + any = -1; + acc = LLONG_MAX; + errno = ERANGE; + } else { + any = 1; + acc *= base; + acc += c; + } + } + } + if (endptr != 0) + *endptr = (char *) (any ? s - 1 : nptr); + return (acc); +} + +__strong_alias(strtoq, strtoll); diff --git a/libc/stdlib/strtoul.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c similarity index 97% rename from libc/stdlib/strtoul.c rename to libc/upstream-openbsd/lib/libc/stdlib/strtoul.c index 61dbb6fac..a236365d2 100644 --- a/libc/stdlib/strtoul.c +++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strtoul.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: strtoul.c,v 1.8 2013/04/17 17:40:35 tedu Exp $ */ /* * Copyright (c) 1990 Regents of the University of California. * All rights reserved. diff --git a/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c new file mode 100644 index 000000000..28f613a08 --- /dev/null +++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c @@ -0,0 +1,106 @@ +/* $OpenBSD: strtoull.c,v 1.6 2013/03/28 18:09:38 martynas Exp $ */ +/*- + * Copyright (c) 1992 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 + +#include +#include +#include +#include + +/* + * Convert a string to an unsigned long long. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +unsigned long long +strtoull(const char *nptr, char **endptr, int base) +{ + const char *s; + unsigned long long acc, cutoff; + int c; + int neg, any, cutlim; + + /* + * See strtoq for comments as to the logic used. + */ + s = nptr; + do { + c = (unsigned char) *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + + cutoff = ULLONG_MAX / (unsigned long long)base; + cutlim = ULLONG_MAX % (unsigned long long)base; + for (acc = 0, any = 0;; c = (unsigned char) *s++) { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0) + continue; + if (acc > cutoff || (acc == cutoff && c > cutlim)) { + any = -1; + acc = ULLONG_MAX; + errno = ERANGE; + } else { + any = 1; + acc *= (unsigned long long)base; + acc += c; + } + } + if (neg && any > 0) + acc = -acc; + if (endptr != 0) + *endptr = (char *) (any ? s - 1 : nptr); + return (acc); +} + +__strong_alias(strtouq, strtoull); diff --git a/libc/stdlib/strtoumax.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c similarity index 88% rename from libc/stdlib/strtoumax.c rename to libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c index e1ff62377..ce6e2c00f 100644 --- a/libc/stdlib/strtoumax.c +++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c @@ -57,7 +57,7 @@ strtoumax(const char *nptr, char **endptr, int base) if (c == '-') { neg = 1; c = *s++; - } else { + } else { neg = 0; if (c == '+') c = *s++; @@ -71,21 +71,8 @@ strtoumax(const char *nptr, char **endptr, int base) if (base == 0) base = c == '0' ? 8 : 10; - /* BIONIC: avoid division and modulo for common cases */ -#define CASE_BASE(x) \ - case x: cutoff = UINTMAX_MAX / x; \ - cutlim = UINTMAX_MAX % x; \ - break - - switch (base) { - CASE_BASE(8); - CASE_BASE(10); - CASE_BASE(16); - default: - cutoff = UINTMAX_MAX / base; - cutlim = UINTMAX_MAX % base; - } - + cutoff = UINTMAX_MAX / (uintmax_t)base; + cutlim = UINTMAX_MAX % (uintmax_t)base; for (acc = 0, any = 0;; c = (unsigned char) *s++) { if (isdigit(c)) c -= '0'; diff --git a/libc/string/strcasecmp.c b/libc/upstream-openbsd/lib/libc/string/strcasecmp.c similarity index 100% rename from libc/string/strcasecmp.c rename to libc/upstream-openbsd/lib/libc/string/strcasecmp.c diff --git a/libc/string/strcspn.c b/libc/upstream-openbsd/lib/libc/string/strcspn.c similarity index 100% rename from libc/string/strcspn.c rename to libc/upstream-openbsd/lib/libc/string/strcspn.c diff --git a/libc/string/strdup.c b/libc/upstream-openbsd/lib/libc/string/strdup.c similarity index 100% rename from libc/string/strdup.c rename to libc/upstream-openbsd/lib/libc/string/strdup.c diff --git a/libc/upstream-openbsd/lib/libc/string/strndup.c b/libc/upstream-openbsd/lib/libc/string/strndup.c new file mode 100644 index 000000000..27701ac55 --- /dev/null +++ b/libc/upstream-openbsd/lib/libc/string/strndup.c @@ -0,0 +1,39 @@ +/* $OpenBSD: strndup.c,v 1.1 2010/05/18 22:24:55 tedu Exp $ */ + +/* + * Copyright (c) 2010 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. + */ + +#include + +#include +#include +#include + +char * +strndup(const char *str, size_t maxlen) +{ + char *copy; + size_t len; + + len = strnlen(str, maxlen); + copy = malloc(len + 1); + if (copy != NULL) { + (void)memcpy(copy, str, len); + copy[len] = '\0'; + } + + return copy; +} diff --git a/libc/string/strpbrk.c b/libc/upstream-openbsd/lib/libc/string/strpbrk.c similarity index 100% rename from libc/string/strpbrk.c rename to libc/upstream-openbsd/lib/libc/string/strpbrk.c diff --git a/libc/string/strsep.c b/libc/upstream-openbsd/lib/libc/string/strsep.c similarity index 98% rename from libc/string/strsep.c rename to libc/upstream-openbsd/lib/libc/string/strsep.c index c44bc5b2a..bcca681e0 100644 --- a/libc/string/strsep.c +++ b/libc/upstream-openbsd/lib/libc/string/strsep.c @@ -34,7 +34,7 @@ /* * Get next token from string *stringp, where tokens are possibly-empty - * strings separated by characters from delim. + * strings separated by characters from delim. * * Writes NULs into the string at *stringp to end tokens. * delim need not remain constant from call to call. diff --git a/libc/string/strspn.c b/libc/upstream-openbsd/lib/libc/string/strspn.c similarity index 100% rename from libc/string/strspn.c rename to libc/upstream-openbsd/lib/libc/string/strspn.c diff --git a/libc/string/strstr.c b/libc/upstream-openbsd/lib/libc/string/strstr.c similarity index 100% rename from libc/string/strstr.c rename to libc/upstream-openbsd/lib/libc/string/strstr.c diff --git a/libc/string/strtok.c b/libc/upstream-openbsd/lib/libc/string/strtok.c similarity index 100% rename from libc/string/strtok.c rename to libc/upstream-openbsd/lib/libc/string/strtok.c diff --git a/libc/upstream-openbsd/openbsd-compat.h b/libc/upstream-openbsd/openbsd-compat.h new file mode 100644 index 000000000..428156fdd --- /dev/null +++ b/libc/upstream-openbsd/openbsd-compat.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BIONIC_OPENBSD_COMPAT_H_included +#define _BIONIC_OPENBSD_COMPAT_H_included + +#define _GNU_SOURCE + +#endif