Clean up our OpenBSD usage.
Also undo some of the mess where we have OpenBSD <stdio.h> but a mix of
different BSD's implementations.
In this first pass, I've only moved easy OpenBSD stuff.
Change-Id: Iae67b02cde6dba9d8d06fedeb53efbfdac0a8cf6
diff --git a/libc/Android.mk b/libc/Android.mk
index 9cde073..4e140f0 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -38,9 +38,6 @@
# =========================================================
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 @@
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 @@
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 @@
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 @@
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_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 @@
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 \
@@ -574,6 +505,32 @@
# ========================================================
+# 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 @@
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 9a65543..0000000
--- 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 <inttypes.h>
-
-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 83dc05c..0000000
--- 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 <inttypes.h>
-
-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 953878f..0000000
--- 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 <inttypes.h>
-
-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 638bd0a..0000000
--- 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 <unistd.h>
-#include <sys/ipc.h>
-#include <sys/stat.h>
-
-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 de55f72..0000000
--- 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 <errno.h>
-#include <unistd.h>
-#include <string.h>
-
-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 9dca79c..0000000
--- 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 <string.h>
-#include <stdlib.h>
-
-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 70cc4c5..d21f23d 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -64,6 +64,7 @@
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 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/stdlib/strtoll.c b/libc/stdlib/strtoll.c
deleted file mode 100644
index 3c75271..0000000
--- a/libc/stdlib/strtoll.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* $OpenBSD: strtoll.c,v 1.6 2005/11/10 10:00:17 espie 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 <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-/*
- * 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)
-{
- return strtoimax(nptr, endptr, base);
-}
-
diff --git a/libc/stdlib/strtoull.c b/libc/stdlib/strtoull.c
deleted file mode 100644
index 36698ac..0000000
--- a/libc/stdlib/strtoull.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/* $OpenBSD: strtoull.c,v 1.5 2005/08/08 08:05:37 espie 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 <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-/*
- * 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)
-{
- return (unsigned long long)strtoumax(nptr, endptr, base);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/clrerr.c b/libc/upstream-freebsd/lib/libc/stdio/clrerr.c
deleted file mode 100644
index f161a6e..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/clrerr.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef clearerr
-#undef clearerr_unlocked
-
-void
-clearerr(FILE *fp)
-{
- FLOCKFILE(fp);
- __sclearerr(fp);
- FUNLOCKFILE(fp);
-}
-
-void
-clearerr_unlocked(FILE *fp)
-{
-
- __sclearerr(fp);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/feof.c b/libc/upstream-freebsd/lib/libc/stdio/feof.c
deleted file mode 100644
index b970248..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/feof.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef feof
-#undef feof_unlocked
-
-int
-feof(FILE *fp)
-{
- int ret;
-
- FLOCKFILE(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-freebsd/lib/libc/stdio/ferror.c
deleted file mode 100644
index 7e0f8f9..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/ferror.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef ferror
-#undef ferror_unlocked
-
-int
-ferror(FILE *fp)
-{
- int ret;
-
- FLOCKFILE(fp);
- ret = __sferror(fp);
- FUNLOCKFILE(fp);
- return (ret);
-}
-
-int
-ferror_unlocked(FILE *fp)
-{
-
- return (__sferror(fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c b/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c
deleted file mode 100644
index f161f43..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-
-int
-fgetpos(FILE * __restrict fp, fpos_t * __restrict pos)
-{
- /*
- * ftello is thread-safe; no need to lock fp.
- */
- if ((*pos = ftello(fp)) == (fpos_t)-1)
- return (-1);
- else
- return (0);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fileno.c b/libc/upstream-freebsd/lib/libc/stdio/fileno.c
deleted file mode 100644
index 3ac1830..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fileno.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef fileno
-#undef fileno_unlocked
-
-int
-fileno(FILE *fp)
-{
- int fd;
-
- FLOCKFILE(fp);
- fd = __sfileno(fp);
- FUNLOCKFILE(fp);
-
- return (fd);
-}
-
-int
-fileno_unlocked(FILE *fp)
-{
-
- return (__sfileno(fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fwalk.c b/libc/upstream-freebsd/lib/libc/stdio/fwalk.c
deleted file mode 100644
index 151837b..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fwalk.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <stdio.h>
-#include "local.h"
-#include "glue.h"
-
-int
-_fwalk(int (*function)(FILE *))
-{
- FILE *fp;
- int n, ret;
- struct glue *g;
-
- ret = 0;
- /*
- * It should be safe to walk the list without locking it;
- * new nodes are only added to the end and none are ever
- * removed.
- *
- * Avoid locking this list while walking it or else you will
- * introduce a potential deadlock in [at least] refill.c.
- */
- for (g = &__sglue; g != NULL; g = g->next)
- for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
- if ((fp->_flags != 0) && ((fp->_flags & __SIGN) == 0))
- ret |= (*function)(fp);
- return (ret);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/getc.c b/libc/upstream-freebsd/lib/libc/stdio/getc.c
deleted file mode 100644
index 4963c8c..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/getc.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-#include "local.h"
-
-#undef getc
-#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));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/getchar.c b/libc/upstream-freebsd/lib/libc/stdio/getchar.c
deleted file mode 100644
index 21040bc..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/getchar.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * A subroutine version of the macro getchar.
- */
-#include "namespace.h"
-#include <stdio.h>
-#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));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/putchar.c b/libc/upstream-freebsd/lib/libc/stdio/putchar.c
deleted file mode 100644
index 7561559..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/putchar.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "local.h"
-#include "libc_private.h"
-
-#undef putchar
-#undef putchar_unlocked
-
-/*
- * A subroutine version of the macro putchar
- */
-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));
-}
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 89%
rename from libc/unistd/exec.c
rename to libc/upstream-openbsd/lib/libc/gen/exec.c
index 2fe2a4e..1e2f7d9 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 <sys/param.h>
#include <sys/types.h>
#include <sys/uio.h>
+
#include <errno.h>
-#include <unistd.h>
#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <stdio.h>
#include <paths.h>
#include <stdarg.h>
-#include <alloca.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
extern char **environ;
@@ -124,20 +122,21 @@
}
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 @@
* 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 @@
(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 @@
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 @@
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 0000000..f9d6621
--- /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 <tholo@sigmasoft.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ipc.h>
+
+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/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/clrerr.c
similarity index 90%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdio/clrerr.c
index 0a6d54e..ac08c72 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/clrerr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/* $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.
@@ -32,9 +32,13 @@
*/
#include <stdio.h>
+#include "local.h"
+#undef clearerr
-int
-fgetc(FILE *fp)
+void
+clearerr(FILE *fp)
{
- return (getc(fp));
+ FLOCKFILE(fp);
+ __sclearerr(fp);
+ FUNLOCKFILE(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 2e19b9f..3e47f2c 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
#include <sys/types.h>
#include <fcntl.h>
+#include <limits.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
-#include <limits.h>
-#include "un-namespace.h"
#include "local.h"
FILE *
@@ -52,13 +45,7 @@
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 @@
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 @@
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/stdio/fscanf.c b/libc/upstream-openbsd/lib/libc/stdio/feof.c
similarity index 88%
copy from libc/stdio/fscanf.c
copy to libc/upstream-openbsd/lib/libc/stdio/feof.c
index 2f3fceb..0036bab 100644
--- a/libc/stdio/fscanf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/feof.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fscanf.c,v 1.9 2005/10/10 17:37:44 espie Exp $ */
+/* $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.
@@ -32,16 +32,20 @@
*/
#include <stdio.h>
-#include <stdarg.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro feof.
+ */
+#undef feof
int
-fscanf(FILE *fp, const char *fmt, ...)
+feof(FILE *fp)
{
- int ret;
- va_list ap;
+ int ret;
- va_start(ap, fmt);
- ret = vfscanf(fp, fmt, ap);
- va_end(ap);
+ FLOCKFILE(fp);
+ ret = __sfeof(fp);
+ FUNLOCKFILE(fp);
return (ret);
}
diff --git a/libc/stdio/fscanf.c b/libc/upstream-openbsd/lib/libc/stdio/ferror.c
similarity index 87%
copy from libc/stdio/fscanf.c
copy to libc/upstream-openbsd/lib/libc/stdio/ferror.c
index 2f3fceb..00b9c8b 100644
--- a/libc/stdio/fscanf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/ferror.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fscanf.c,v 1.9 2005/10/10 17:37:44 espie Exp $ */
+/* $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.
@@ -32,16 +32,20 @@
*/
#include <stdio.h>
-#include <stdarg.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro ferror.
+ */
+#undef ferror
int
-fscanf(FILE *fp, const char *fmt, ...)
+ferror(FILE *fp)
{
- int ret;
- va_list ap;
+ int ret;
- va_start(ap, fmt);
- ret = vfscanf(fp, fmt, ap);
- va_end(ap);
+ FLOCKFILE(fp);
+ ret = __sferror(fp);
+ FUNLOCKFILE(fp);
return (ret);
}
diff --git a/libc/stdio/fflush.c b/libc/upstream-openbsd/lib/libc/stdio/fflush.c
similarity index 96%
rename from libc/stdio/fflush.c
rename to libc/upstream-openbsd/lib/libc/stdio/fflush.c
index e69bdcc..3e30f10 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 @@
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 0a6d54e..c5d7dde 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 1779de2..539b3c0 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "un-namespace.h"
-#include "libc_private.h"
#include "local.h"
/*
@@ -70,7 +62,7 @@
/*
* 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 @@
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 @@
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 @@
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/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/fgetpos.c
similarity index 90%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdio/fgetpos.c
index 0a6d54e..e6188e5 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgetpos.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/* $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.
@@ -33,8 +33,11 @@
#include <stdio.h>
+/*
+ * fgetpos: like ftello.
+ */
int
-fgetc(FILE *fp)
+fgetpos(FILE *fp, fpos_t *pos)
{
- return (getc(fp));
+ 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 9abf559..0ba8770 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
+#include <errno.h>
#include <stdio.h>
#include <string.h>
-#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 @@
}
break;
}
- len = fp->_r;
}
+ len = fp->_r;
p = fp->_p;
/*
@@ -93,7 +89,7 @@
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 @@
s += len;
n -= len;
}
- *s = 0;
+ *s = '\0';
FUNLOCKFILE(fp);
return (buf);
}
diff --git a/libc/stdio/fscanf.c b/libc/upstream-openbsd/lib/libc/stdio/fileno.c
similarity index 87%
copy from libc/stdio/fscanf.c
copy to libc/upstream-openbsd/lib/libc/stdio/fileno.c
index 2f3fceb..58628da 100644
--- a/libc/stdio/fscanf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fileno.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fscanf.c,v 1.9 2005/10/10 17:37:44 espie Exp $ */
+/* $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.
@@ -32,16 +32,20 @@
*/
#include <stdio.h>
-#include <stdarg.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro fileno.
+ */
+#undef fileno
int
-fscanf(FILE *fp, const char *fmt, ...)
+fileno(FILE *fp)
{
- int ret;
- va_list ap;
+ int ret;
- va_start(ap, fmt);
- ret = vfscanf(fp, fmt, ap);
- va_end(ap);
+ FLOCKFILE(fp);
+ ret = __sfileno(fp);
+ FUNLOCKFILE(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 f205bdf..65bd749 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-#include "un-namespace.h"
#include "local.h"
-#include "libc_private.h"
/*
* fpurge: like fflush, but without writing anything: leave the
@@ -51,19 +43,19 @@
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 90809e2..98e3960 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 3b8f2c9..ea8556a 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
#include <stdio.h>
#include <string.h>
-#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 2f3fceb..5fd10d4 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 <stdio.h>
#include <stdarg.h>
+/* 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 38697f5..cdd40b6 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 @@
* 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 @@
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 @@
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/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/fsetpos.c
similarity index 89%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdio/fsetpos.c
index 0a6d54e..9624fe5 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fsetpos.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/* $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.
@@ -33,8 +33,11 @@
#include <stdio.h>
+/*
+ * fsetpos: like fseeko.
+ */
int
-fgetc(FILE *fp)
+fsetpos(FILE *iop, const fpos_t *pos)
{
- return (getc(fp));
+ return (fseeko(iop, (off_t)*pos, SEEK_SET));
}
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 9f850ee..0a2016c 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 <stdio.h>
#include <errno.h>
+#include <limits.h>
#include "local.h"
/*
@@ -46,14 +47,14 @@
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 @@
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 983fe50..b85ee96 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <stdio.h>
#include <errno.h>
-
#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 @@
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/stdio/fscanf.c b/libc/upstream-openbsd/lib/libc/stdio/fwalk.c
similarity index 81%
copy from libc/stdio/fscanf.c
copy to libc/upstream-openbsd/lib/libc/stdio/fwalk.c
index 2f3fceb..8ac6628 100644
--- a/libc/stdio/fscanf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fwalk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fscanf.c,v 1.9 2005/10/10 17:37:44 espie Exp $ */
+/* $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.
@@ -31,17 +31,23 @@
* SUCH DAMAGE.
*/
+#include <errno.h>
#include <stdio.h>
-#include <stdarg.h>
+#include "local.h"
+#include "glue.h"
int
-fscanf(FILE *fp, const char *fmt, ...)
+_fwalk(int (*function)(FILE *))
{
- int ret;
- va_list ap;
+ FILE *fp;
+ int n, ret;
+ struct glue *g;
- va_start(ap, fmt);
- ret = vfscanf(fp, fmt, ap);
- va_end(ap);
+ ret = 0;
+ for (g = &__sglue; g != NULL; g = g->next)
+ for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) {
+ if ((fp->_flags != 0) && ((fp->_flags & __SIGN) == 0))
+ ret |= (*function)(fp);
+ }
return (ret);
}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c b/libc/upstream-openbsd/lib/libc/stdio/getc.c
similarity index 82%
rename from libc/upstream-freebsd/lib/libc/stdio/setbuf.c
rename to libc/upstream-openbsd/lib/libc/stdio/getc.c
index 5c65f97..6879cbb 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/setbuf.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,17 +31,32 @@
* 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <stdio.h>
#include "local.h"
-void
-setbuf(FILE * __restrict fp, char * __restrict buf)
+/*
+ * A subroutine version of the macro getc_unlocked.
+ */
+#undef getc_unlocked
+
+int
+getc_unlocked(FILE *fp)
{
- (void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
+ 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/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/getchar.c
similarity index 83%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdio/getchar.c
index 0a6d54e..550817d 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/getchar.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/* $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.
@@ -33,8 +33,26 @@
#include <stdio.h>
+/*
+ * A subroutine version of the macro getchar_unlocked.
+ */
+#undef getchar_unlocked
+
int
-fgetc(FILE *fp)
+getchar_unlocked(void)
{
- return (getc(fp));
+ 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 acce376..dcde0c3 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 <sys/cdefs.h>
-__RCSID("$NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $");
-
-#include "namespace.h"
-
-#include <sys/param.h>
-
-#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#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 @@
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 @@
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 @@
error:
fp->_flags |= __SERR;
- return -1;
-}
-
-ssize_t
-getdelim(char **__restrict buf, size_t *__restrict buflen,
- int sep, FILE *__restrict fp)
-{
- ssize_t n;
-
- FLOCKFILE(fp);
- n = __getdelim(buf, buflen, sep, fp);
FUNLOCKFILE(fp);
- return n;
+ return -1;
}
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 e5d4bab..55ad396 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 <sys/cdefs.h>
-__RCSID("$NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $");
-
-#include "namespace.h"
-
#include <stdio.h>
-#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 96%
rename from libc/stdio/gets.c
rename to libc/upstream-openbsd/lib/libc/stdio/gets.c
index 93e2edd..c2e1b50 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-freebsd/lib/libc/stdio/remove.c b/libc/upstream-openbsd/lib/libc/stdio/perror.c
similarity index 72%
copy from libc/upstream-freebsd/lib/libc/stdio/remove.c
copy to libc/upstream-openbsd/lib/libc/stdio/perror.c
index 2e984ba..8728718 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/remove.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/perror.c
@@ -1,10 +1,8 @@
-/*-
- * Copyright (c) 1990, 1993
+/* $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.
*
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -30,25 +28,35 @@
* 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
-#include <sys/stat.h>
+#include <sys/uio.h>
#include <unistd.h>
+#include <errno.h>
#include <stdio.h>
+#include <string.h>
+#include <limits.h>
-int
-remove(const char *file)
+void
+perror(const char *s)
{
- struct stat sb;
+ struct iovec *v;
+ struct iovec iov[4];
+ char buf[NL_TEXTMAX];
- if (lstat(file, &sb) < 0)
- return (-1);
- if (S_ISDIR(sb.st_mode))
- return (rmdir(file));
- return (unlink(file));
+ 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 614b435..09bb3d7 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 <stdio.h>
#include <stdarg.h>
+/* 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 aaffece..762fecb 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
#include <stdio.h>
-#include "un-namespace.h"
+#include <errno.h>
#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/fsetpos.c b/libc/upstream-openbsd/lib/libc/stdio/putchar.c
similarity index 82%
rename from libc/upstream-freebsd/lib/libc/stdio/fsetpos.c
rename to libc/upstream-openbsd/lib/libc/stdio/putchar.c
index c6b8b78..233cdfd 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/fsetpos.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,29 @@
* 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
#include <stdio.h>
+#undef putchar_unlocked
/*
- * fsetpos: like fseek.
+ * A subrouting version of the macro putchar_unlocked
*/
int
-fsetpos(FILE *iop, const fpos_t *pos)
+putchar_unlocked(int c)
{
- return (fseeko(iop, (off_t)*pos, SEEK_SET));
+ FILE *so = stdout;
+
+ return (putc_unlocked(c,so));
+}
+
+#undef putchar
+
+/*
+ * A subroutine version of the macro putchar
+ */
+int
+putchar(int c)
+{
+ FILE *so = 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 5ee7fc1..655aed7 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
#include <stdio.h>
#include <string.h>
-#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 @@
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 7cb6b78..165c72a 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 @@
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 @@
/* 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 2e984ba..d09d76f 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
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 bdc0311..4cd97cb 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <stdio.h>
#include "local.h"
@@ -47,6 +42,7 @@
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 71194d0..90cf12a 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 <stdio.h>
#include <stdarg.h>
+/* SCANFLIKE1 */
int
scanf(const char *fmt, ...)
{
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/setbuf.c
similarity index 90%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdio/setbuf.c
index 0a6d54e..883b895 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/setbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/* $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.
@@ -32,9 +32,10 @@
*/
#include <stdio.h>
+#include "local.h"
-int
-fgetc(FILE *fp)
+void
+setbuf(FILE *fp, char *buf)
{
- return (getc(fp));
+ (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 af5eb3c..8725ff7 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <stdio.h>
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 1596ebf..a4a27b5 100644
--- a/libc/stdio/stdio.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/stdio.c
@@ -45,7 +45,7 @@
{
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 @@
{
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 e15746f..e3f2ab6 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
#include <errno.h>
+#include <limits.h>
+#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <paths.h>
__warn_references(tempnam,
"warning: tempnam() possibly used unsafely; consider using mkstemp()");
@@ -49,36 +44,53 @@
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 ce32dcc..32e0a22 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <stdio.h>
@@ -54,7 +49,7 @@
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 b493d21..675733a 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 1630ccb..8fe7c5b 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 <Todd.Miller@courtesan.com>
@@ -48,7 +48,10 @@
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 96%
rename from libc/stdio/vsnprintf.c
rename to libc/upstream-openbsd/lib/libc/stdio/vsnprintf.c
index ca30f94..8b1a088 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 846ee8a..308ff37 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 97%
rename from libc/stdio/wbuf.c
rename to libc/upstream-openbsd/lib/libc/stdio/wbuf.c
index e09ac59..6aa00e1 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/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdlib/atoi.c
similarity index 82%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdlib/atoi.c
index 0a6d54e..b084267 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atoi.c
@@ -1,10 +1,7 @@
-/* $OpenBSD: fgetc.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.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
+/* $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
* modification, are permitted provided that the following conditions
@@ -31,10 +28,10 @@
* SUCH DAMAGE.
*/
-#include <stdio.h>
+#include <stdlib.h>
int
-fgetc(FILE *fp)
+atoi(const char *str)
{
- return (getc(fp));
+ return((int)strtol(str, (char **)NULL, 10));
}
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdlib/atol.c
similarity index 82%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdlib/atol.c
index 0a6d54e..1970804 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atol.c
@@ -1,10 +1,7 @@
-/* $OpenBSD: fgetc.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.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
+/* $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
@@ -31,10 +28,10 @@
* SUCH DAMAGE.
*/
-#include <stdio.h>
+#include <stdlib.h>
-int
-fgetc(FILE *fp)
+long
+atol(const char *str)
{
- return (getc(fp));
+ return(strtol(str, (char **)NULL, 10));
}
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdlib/atoll.c
similarity index 82%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdlib/atoll.c
index 0a6d54e..a65e682 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atoll.c
@@ -1,10 +1,7 @@
-/* $OpenBSD: fgetc.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.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
+/* $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
* modification, are permitted provided that the following conditions
@@ -31,10 +28,11 @@
* SUCH DAMAGE.
*/
-#include <stdio.h>
+#include <stdlib.h>
-int
-fgetc(FILE *fp)
+long long
+atoll(str)
+ const char *str;
{
- return (getc(fp));
+ 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 0b4323d..2c77f41 100644
--- a/libc/stdlib/strtoimax.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c
@@ -91,40 +91,9 @@
* 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 a3cdbcd..dc2cf88 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.
@@ -49,6 +49,17 @@
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
* assume decimal; if base is already 16, allow 0x.
diff --git a/libc/stdlib/strtol.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
similarity index 80%
copy from libc/stdlib/strtol.c
copy to libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
index a3cdbcd..4bcc556 100644
--- a/libc/stdlib/strtol.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
@@ -1,6 +1,6 @@
-/* $OpenBSD: strtol.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
+/* $OpenBSD: strtoll.c,v 1.7 2013/03/28 18:09:38 martynas Exp $ */
/*-
- * Copyright (c) 1990 The Regents of the University of California.
+ * Copyright (c) 1992 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -28,23 +28,24 @@
* SUCH DAMAGE.
*/
+#include <sys/types.h>
+
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
-
/*
- * Convert a string to a long integer.
+ * Convert a string to a long long.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
-long
-strtol(const char *nptr, char **endptr, int base)
+long long
+strtoll(const char *nptr, char **endptr, int base)
{
const char *s;
- long acc, cutoff;
+ long long acc, cutoff;
int c;
int neg, any, cutlim;
@@ -81,17 +82,18 @@
* 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 longs is
- * [-2147483648..2147483647] and the input base is 10,
- * cutoff will be set to 214748364 and cutlim to either
- * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
- * a value > 214748364, or equal but the next digit is > 7 (or 8),
- * the number is too big, and we will return a range error.
+ * 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 ? LONG_MIN : LONG_MAX;
+ cutoff = neg ? LLONG_MIN : LLONG_MAX;
cutlim = cutoff % base;
cutoff /= base;
if (neg) {
@@ -115,7 +117,7 @@
if (neg) {
if (acc < cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
- acc = LONG_MIN;
+ acc = LLONG_MIN;
errno = ERANGE;
} else {
any = 1;
@@ -125,7 +127,7 @@
} else {
if (acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
- acc = LONG_MAX;
+ acc = LLONG_MAX;
errno = ERANGE;
} else {
any = 1;
@@ -138,3 +140,5 @@
*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 61dbb6f..a236365 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/stdlib/strtoul.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
similarity index 81%
copy from libc/stdlib/strtoul.c
copy to libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
index 61dbb6f..28f613a 100644
--- a/libc/stdlib/strtoul.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
@@ -1,6 +1,6 @@
-/* $OpenBSD: strtoul.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
-/*
- * Copyright (c) 1990 Regents of the University of California.
+/* $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
@@ -28,27 +28,29 @@
* SUCH DAMAGE.
*/
+#include <sys/types.h>
+
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
/*
- * Convert a string to an unsigned long integer.
+ * 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
-strtoul(const char *nptr, char **endptr, int base)
+unsigned long long
+strtoull(const char *nptr, char **endptr, int base)
{
const char *s;
- unsigned long acc, cutoff;
+ unsigned long long acc, cutoff;
int c;
int neg, any, cutlim;
/*
- * See strtol for comments as to the logic used.
+ * See strtoq for comments as to the logic used.
*/
s = nptr;
do {
@@ -57,7 +59,7 @@
if (c == '-') {
neg = 1;
c = *s++;
- } else {
+ } else {
neg = 0;
if (c == '+')
c = *s++;
@@ -71,8 +73,8 @@
if (base == 0)
base = c == '0' ? 8 : 10;
- cutoff = ULONG_MAX / (unsigned long)base;
- cutlim = ULONG_MAX % (unsigned long)base;
+ 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';
@@ -86,11 +88,11 @@
continue;
if (acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
- acc = ULONG_MAX;
+ acc = ULLONG_MAX;
errno = ERANGE;
} else {
any = 1;
- acc *= (unsigned long)base;
+ acc *= (unsigned long long)base;
acc += c;
}
}
@@ -100,3 +102,5 @@
*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 87%
rename from libc/stdlib/strtoumax.c
rename to libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c
index e1ff623..ce6e2c0 100644
--- a/libc/stdlib/strtoumax.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c
@@ -57,7 +57,7 @@
if (c == '-') {
neg = 1;
c = *s++;
- } else {
+ } else {
neg = 0;
if (c == '+')
c = *s++;
@@ -71,21 +71,8 @@
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 0000000..27701ac
--- /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 <Todd.Miller@courtesan.com>
+ *
+ * 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 <sys/types.h>
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+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 97%
rename from libc/string/strsep.c
rename to libc/upstream-openbsd/lib/libc/string/strsep.c
index c44bc5b..bcca681 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 0000000..428156f
--- /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