Merge "Clean up our OpenBSD usage."
This commit is contained in:
commit
9150dfb1c6
@ -38,9 +38,6 @@ endif
|
||||
# =========================================================
|
||||
libc_common_src_files := \
|
||||
bionic/arc4random.c \
|
||||
bionic/atoi.c \
|
||||
bionic/atol.c \
|
||||
bionic/atoll.c \
|
||||
bionic/bindresvport.c \
|
||||
bionic/clearenv.c \
|
||||
bionic/daemon.c \
|
||||
@ -50,7 +47,6 @@ libc_common_src_files := \
|
||||
bionic/fdprintf.c \
|
||||
bionic/flockfile.c \
|
||||
bionic/ftime.c \
|
||||
bionic/ftok.c \
|
||||
bionic/fts.c \
|
||||
bionic/getdtablesize.c \
|
||||
bionic/gethostname.c \
|
||||
@ -68,7 +64,6 @@ libc_common_src_files := \
|
||||
bionic/memmem.c \
|
||||
bionic/memswap.c \
|
||||
bionic/pathconf.c \
|
||||
bionic/perror.c \
|
||||
bionic/ptsname.c \
|
||||
bionic/ptsname_r.c \
|
||||
bionic/pututline.c \
|
||||
@ -81,7 +76,6 @@ libc_common_src_files := \
|
||||
bionic/sigblock.c \
|
||||
bionic/siginterrupt.c \
|
||||
bionic/sigsetmask.c \
|
||||
bionic/strndup.c \
|
||||
bionic/strntoimax.c \
|
||||
bionic/strntoumax.c \
|
||||
bionic/strtotimeval.c \
|
||||
@ -95,61 +89,24 @@ libc_common_src_files := \
|
||||
bionic/utmp.c \
|
||||
bionic/wcscoll.c \
|
||||
stdio/asprintf.c \
|
||||
stdio/fflush.c \
|
||||
stdio/fgetc.c \
|
||||
stdio/findfp.c \
|
||||
stdio/fprintf.c \
|
||||
stdio/fputc.c \
|
||||
stdio/fread.c \
|
||||
stdio/freopen.c \
|
||||
stdio/fscanf.c \
|
||||
stdio/fseek.c \
|
||||
stdio/ftell.c \
|
||||
stdio/fvwrite.c \
|
||||
stdio/gets.c \
|
||||
stdio/printf.c \
|
||||
stdio/refill.c \
|
||||
stdio/rewind.c \
|
||||
stdio/scanf.c \
|
||||
stdio/snprintf.c\
|
||||
stdio/sprintf.c \
|
||||
stdio/sscanf.c \
|
||||
stdio/stdio.c \
|
||||
stdio/ungetc.c \
|
||||
stdio/vasprintf.c \
|
||||
stdio/vfprintf.c \
|
||||
stdio/vfscanf.c \
|
||||
stdio/vprintf.c \
|
||||
stdio/vscanf.c \
|
||||
stdio/vsnprintf.c \
|
||||
stdio/vsprintf.c \
|
||||
stdio/vsscanf.c \
|
||||
stdio/wbuf.c \
|
||||
stdlib/atexit.c \
|
||||
stdlib/ctype_.c \
|
||||
stdlib/getenv.c \
|
||||
stdlib/putenv.c \
|
||||
stdlib/setenv.c \
|
||||
stdlib/strtod.c \
|
||||
stdlib/strtoimax.c \
|
||||
stdlib/strtol.c \
|
||||
stdlib/strtoll.c \
|
||||
stdlib/strtoul.c \
|
||||
stdlib/strtoull.c \
|
||||
stdlib/strtoumax.c \
|
||||
stdlib/tolower_.c \
|
||||
stdlib/toupper_.c \
|
||||
string/strcasecmp.c \
|
||||
string/strcspn.c \
|
||||
string/strdup.c \
|
||||
string/strpbrk.c \
|
||||
string/strsep.c \
|
||||
string/strspn.c \
|
||||
string/strstr.c \
|
||||
string/strtok.c \
|
||||
unistd/alarm.c \
|
||||
unistd/exec.c \
|
||||
unistd/fnmatch.c \
|
||||
unistd/syslog.c \
|
||||
unistd/system.c \
|
||||
unistd/time.c \
|
||||
@ -280,38 +237,14 @@ libc_bionic_src_files := \
|
||||
libc_upstream_freebsd_src_files := \
|
||||
upstream-freebsd/lib/libc/gen/sleep.c \
|
||||
upstream-freebsd/lib/libc/gen/usleep.c \
|
||||
upstream-freebsd/lib/libc/stdio/clrerr.c \
|
||||
upstream-freebsd/lib/libc/stdio/fclose.c \
|
||||
upstream-freebsd/lib/libc/stdio/fdopen.c \
|
||||
upstream-freebsd/lib/libc/stdio/feof.c \
|
||||
upstream-freebsd/lib/libc/stdio/ferror.c \
|
||||
upstream-freebsd/lib/libc/stdio/fgetln.c \
|
||||
upstream-freebsd/lib/libc/stdio/fgetpos.c \
|
||||
upstream-freebsd/lib/libc/stdio/fgets.c \
|
||||
upstream-freebsd/lib/libc/stdio/fileno.c \
|
||||
upstream-freebsd/lib/libc/stdio/flags.c \
|
||||
upstream-freebsd/lib/libc/stdio/fopen.c \
|
||||
upstream-freebsd/lib/libc/stdio/fpurge.c \
|
||||
upstream-freebsd/lib/libc/stdio/fputs.c \
|
||||
upstream-freebsd/lib/libc/stdio/fsetpos.c \
|
||||
upstream-freebsd/lib/libc/stdio/funopen.c \
|
||||
upstream-freebsd/lib/libc/stdio/fwalk.c \
|
||||
upstream-freebsd/lib/libc/stdio/fwrite.c \
|
||||
upstream-freebsd/lib/libc/stdio/getc.c \
|
||||
upstream-freebsd/lib/libc/stdio/getchar.c \
|
||||
upstream-freebsd/lib/libc/stdio/makebuf.c \
|
||||
upstream-freebsd/lib/libc/stdio/mktemp.c \
|
||||
upstream-freebsd/lib/libc/stdio/putc.c \
|
||||
upstream-freebsd/lib/libc/stdio/putchar.c \
|
||||
upstream-freebsd/lib/libc/stdio/puts.c \
|
||||
upstream-freebsd/lib/libc/stdio/putw.c \
|
||||
upstream-freebsd/lib/libc/stdio/remove.c \
|
||||
upstream-freebsd/lib/libc/stdio/rget.c \
|
||||
upstream-freebsd/lib/libc/stdio/setbuf.c \
|
||||
upstream-freebsd/lib/libc/stdio/setbuffer.c \
|
||||
upstream-freebsd/lib/libc/stdio/setvbuf.c \
|
||||
upstream-freebsd/lib/libc/stdio/tempnam.c \
|
||||
upstream-freebsd/lib/libc/stdio/tmpnam.c \
|
||||
upstream-freebsd/lib/libc/stdio/wsetup.c \
|
||||
upstream-freebsd/lib/libc/stdlib/abs.c \
|
||||
upstream-freebsd/lib/libc/stdlib/getopt_long.c \
|
||||
@ -361,8 +294,6 @@ libc_upstream_netbsd_src_files := \
|
||||
upstream-netbsd/lib/libc/regex/regerror.c \
|
||||
upstream-netbsd/lib/libc/regex/regexec.c \
|
||||
upstream-netbsd/lib/libc/regex/regfree.c \
|
||||
upstream-netbsd/lib/libc/stdio/getdelim.c \
|
||||
upstream-netbsd/lib/libc/stdio/getline.c \
|
||||
upstream-netbsd/lib/libc/stdlib/bsearch.c \
|
||||
upstream-netbsd/lib/libc/stdlib/div.c \
|
||||
upstream-netbsd/lib/libc/stdlib/drand48.c \
|
||||
@ -573,6 +504,32 @@ $(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
|
||||
# ========================================================
|
||||
# libc_openbsd.a - upstream OpenBSD C library code
|
||||
# ========================================================
|
||||
#
|
||||
# These files are built with the openbsd-compat.h header file
|
||||
# automatically included.
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-c-files-under,upstream-openbsd)
|
||||
LOCAL_CFLAGS := \
|
||||
$(libc_common_cflags) \
|
||||
-I$(LOCAL_PATH)/upstream-openbsd \
|
||||
-I$(LOCAL_PATH)/upstream-openbsd/lib/libc/include \
|
||||
-include upstream-openbsd/openbsd-compat.h
|
||||
LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
|
||||
LOCAL_CPPFLAGS := $(libc_common_cppflags)
|
||||
LOCAL_C_INCLUDES := $(libc_common_c_includes)
|
||||
LOCAL_MODULE := libc_openbsd
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
|
||||
LOCAL_SYSTEM_SHARED_LIBRARIES :=
|
||||
|
||||
$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
|
||||
# ========================================================
|
||||
# libc_bionic.a - home-grown C library code
|
||||
# ========================================================
|
||||
@ -633,6 +590,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES := \
|
||||
libc_dns \
|
||||
libc_freebsd \
|
||||
libc_netbsd \
|
||||
libc_openbsd \
|
||||
libc_syscalls \
|
||||
libc_tzcode \
|
||||
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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) );
|
||||
}
|
@ -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 );
|
||||
}
|
@ -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;
|
||||
}
|
@ -64,6 +64,7 @@ extern pid_t setsid(void);
|
||||
|
||||
extern int execv(const char *, char * const *);
|
||||
extern int execvp(const char *, char * const *);
|
||||
extern int execvpe(const char *, char * const *, char * const *);
|
||||
extern int execve(const char *, char * const *, char * const *);
|
||||
extern int execl(const char *, const char *, ...);
|
||||
extern int execlp(const char *, const char *, ...);
|
||||
@ -194,7 +195,6 @@ extern pid_t tcgetpgrp(int fd);
|
||||
extern int tcsetpgrp(int fd, pid_t _pid);
|
||||
|
||||
#if 0 /* MISSING FROM BIONIC */
|
||||
extern int execvpe(const char *, char * const *, char * const *);
|
||||
extern int execlpe(const char *, const char *, ...);
|
||||
extern int getfsuid(uid_t);
|
||||
extern int setfsuid(uid_t);
|
||||
|
@ -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 @@ execlp(const char *name, const char *arg, ...)
|
||||
}
|
||||
|
||||
int
|
||||
execv(const char *name, char * const *argv)
|
||||
execv(const char *name, char *const *argv)
|
||||
{
|
||||
(void)execve(name, argv, environ);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
execvp(const char *name, char * const *argv)
|
||||
execvpe(const char *name, char *const *argv, char *const *envp)
|
||||
{
|
||||
char **memp;
|
||||
int cnt, lp, ln, len;
|
||||
int cnt;
|
||||
size_t lp, ln, len;
|
||||
char *p;
|
||||
int eacces = 0;
|
||||
char *bp, *cur, *path, buf[MAXPATHLEN];
|
||||
char *bp, *cur, *path, buf[PATH_MAX];
|
||||
|
||||
/*
|
||||
* Do not allow null name
|
||||
@ -183,7 +182,7 @@ execvp(const char *name, char * const *argv)
|
||||
* security issue; given a way to make the path too long
|
||||
* the user may execute the wrong program.
|
||||
*/
|
||||
if (lp + ln + 2 > (int)sizeof(buf)) {
|
||||
if (lp + ln + 2 > sizeof(buf)) {
|
||||
struct iovec iov[3];
|
||||
|
||||
iov[0].iov_base = "execvp: ";
|
||||
@ -195,12 +194,12 @@ execvp(const char *name, char * const *argv)
|
||||
(void)writev(STDERR_FILENO, iov, 3);
|
||||
continue;
|
||||
}
|
||||
memcpy(buf, p, lp);
|
||||
bcopy(p, buf, lp);
|
||||
buf[lp] = '/';
|
||||
memcpy(buf + lp + 1, name, ln);
|
||||
bcopy(name, buf + lp + 1, ln);
|
||||
buf[lp + ln + 1] = '\0';
|
||||
|
||||
retry: (void)execve(bp, argv, environ);
|
||||
retry: (void)execve(bp, argv, envp);
|
||||
switch(errno) {
|
||||
case E2BIG:
|
||||
goto done;
|
||||
@ -217,8 +216,8 @@ retry: (void)execve(bp, argv, environ);
|
||||
goto done;
|
||||
memp[0] = "sh";
|
||||
memp[1] = bp;
|
||||
memcpy(memp + 2, argv + 1, cnt * sizeof(char *));
|
||||
(void)execve(_PATH_BSHELL, memp, environ);
|
||||
bcopy(argv + 1, memp + 2, cnt * sizeof(char *));
|
||||
(void)execve(_PATH_BSHELL, memp, envp);
|
||||
goto done;
|
||||
case ENOMEM:
|
||||
goto done;
|
||||
@ -243,3 +242,10 @@ retry: (void)execve(bp, argv, environ);
|
||||
done:
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
execvp(const char *name, char *const *argv)
|
||||
{
|
||||
return execvpe(name, argv, environ);
|
||||
}
|
||||
|
43
libc/upstream-openbsd/lib/libc/gen/ftok.c
Normal file
43
libc/upstream-openbsd/lib/libc/gen/ftok.c
Normal file
@ -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));
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: clrerr.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,19 +31,9 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <stdio.h>
|
||||
#include "un-namespace.h"
|
||||
#include "libc_private.h"
|
||||
|
||||
#undef clearerr
|
||||
#undef clearerr_unlocked
|
||||
#include "local.h"
|
||||
#undef clearerr
|
||||
|
||||
void
|
||||
clearerr(FILE *fp)
|
||||
@ -51,10 +42,3 @@ clearerr(FILE *fp)
|
||||
__sclearerr(fp);
|
||||
FUNLOCKFILE(fp);
|
||||
}
|
||||
|
||||
void
|
||||
clearerr_unlocked(FILE *fp)
|
||||
{
|
||||
|
||||
__sclearerr(fp);
|
||||
}
|
@ -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 @@ fdopen(int fd, const char *mode)
|
||||
FILE *fp;
|
||||
int flags, oflags, fdflags, tmp;
|
||||
|
||||
/*
|
||||
* File descriptors are a full int, but _file is only a short.
|
||||
* If we get a valid file descriptor that is greater than
|
||||
* SHRT_MAX, then the fd will get sign-extended into an
|
||||
* invalid file descriptor. Handle this case by failing the
|
||||
* open.
|
||||
*/
|
||||
/* _file is only a short */
|
||||
if (fd > SHRT_MAX) {
|
||||
errno = EMFILE;
|
||||
return (NULL);
|
||||
@ -68,7 +55,7 @@ fdopen(int fd, const char *mode)
|
||||
return (NULL);
|
||||
|
||||
/* Make sure the mode the user wants is a subset of the actual mode. */
|
||||
if ((fdflags = _fcntl(fd, F_GETFL, 0)) < 0)
|
||||
if ((fdflags = fcntl(fd, F_GETFL, 0)) < 0)
|
||||
return (NULL);
|
||||
tmp = fdflags & O_ACCMODE;
|
||||
if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) {
|
||||
@ -78,17 +65,11 @@ fdopen(int fd, const char *mode)
|
||||
|
||||
if ((fp = __sfp()) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if ((oflags & O_CLOEXEC) && _fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
|
||||
fp->_flags = 0;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
fp->_flags = flags;
|
||||
/*
|
||||
* If opened for appending, but underlying descriptor does not have
|
||||
* O_APPEND bit set, assert __SAPP so that __swrite() caller
|
||||
* will _sseek() to the end before write.
|
||||
* O_APPEND bit set, assert __SAPP so that __swrite() will lseek to
|
||||
* end before each write.
|
||||
*/
|
||||
if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
|
||||
fp->_flags |= __SAPP;
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: feof.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,19 +31,13 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <stdio.h>
|
||||
#include "un-namespace.h"
|
||||
#include "libc_private.h"
|
||||
#include "local.h"
|
||||
|
||||
/*
|
||||
* A subroutine version of the macro feof.
|
||||
*/
|
||||
#undef feof
|
||||
#undef feof_unlocked
|
||||
|
||||
int
|
||||
feof(FILE *fp)
|
||||
@ -50,14 +45,7 @@ feof(FILE *fp)
|
||||
int ret;
|
||||
|
||||
FLOCKFILE(fp);
|
||||
ret= __sfeof(fp);
|
||||
ret = __sfeof(fp);
|
||||
FUNLOCKFILE(fp);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
feof_unlocked(FILE *fp)
|
||||
{
|
||||
|
||||
return (__sfeof(fp));
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: ferror.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,34 +31,21 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <stdio.h>
|
||||
#include "un-namespace.h"
|
||||
#include "libc_private.h"
|
||||
#include "local.h"
|
||||
|
||||
/*
|
||||
* A subroutine version of the macro ferror.
|
||||
*/
|
||||
#undef ferror
|
||||
#undef ferror_unlocked
|
||||
|
||||
int
|
||||
ferror(FILE *fp)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
FLOCKFILE(fp);
|
||||
ret = __sferror(fp);
|
||||
FUNLOCKFILE(fp);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
ferror_unlocked(FILE *fp)
|
||||
{
|
||||
|
||||
return (__sferror(fp));
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: fflush.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
|
||||
/* $OpenBSD: fflush.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -39,7 +39,7 @@
|
||||
int
|
||||
fflush(FILE *fp)
|
||||
{
|
||||
int r;
|
||||
int r;
|
||||
|
||||
if (fp == NULL)
|
||||
return (_fwalk(__sflush_locked));
|
||||
@ -88,7 +88,7 @@ __sflush(FILE *fp)
|
||||
int
|
||||
__sflush_locked(FILE *fp)
|
||||
{
|
||||
int r;
|
||||
int r;
|
||||
|
||||
FLOCKFILE(fp);
|
||||
r = __sflush(fp);
|
@ -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.
|
@ -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 @@ __slbexpand(FILE *fp, size_t newsize)
|
||||
|
||||
/*
|
||||
* Get an input line. The returned pointer often (but not always)
|
||||
* points into a stdio buffer. Fgetln does not alter the text of
|
||||
* points into a stdio buffer. Fgetline does not alter the text of
|
||||
* the returned line (which is thus not a C string because it will
|
||||
* not necessarily end with '\0'), but does allow callers to modify
|
||||
* it if they wish. Thus, we set __SMOD in case the caller does.
|
||||
@ -79,22 +71,19 @@ char *
|
||||
fgetln(FILE *fp, size_t *lenp)
|
||||
{
|
||||
unsigned char *p;
|
||||
char *ret;
|
||||
size_t len;
|
||||
size_t off;
|
||||
|
||||
FLOCKFILE(fp);
|
||||
ORIENT(fp, -1);
|
||||
_SET_ORIENTATION(fp, -1);
|
||||
|
||||
/* make sure there is input */
|
||||
if (fp->_r <= 0 && __srefill(fp)) {
|
||||
*lenp = 0;
|
||||
FUNLOCKFILE(fp);
|
||||
return (NULL);
|
||||
}
|
||||
if (fp->_r <= 0 && __srefill(fp))
|
||||
goto error;
|
||||
|
||||
/* look for a newline in the input */
|
||||
if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) {
|
||||
char *ret;
|
||||
|
||||
if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) {
|
||||
/*
|
||||
* Found one. Flag buffer as modified to keep fseek from
|
||||
* `optimising' a backward seek, in case the user stomps on
|
||||
@ -135,7 +124,7 @@ fgetln(FILE *fp, size_t *lenp)
|
||||
off = len;
|
||||
if (__srefill(fp))
|
||||
break; /* EOF or error: return partial line */
|
||||
if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL)
|
||||
if ((p = memchr((void *)fp->_p, '\n', fp->_r)) == NULL)
|
||||
continue;
|
||||
|
||||
/* got it: finish up the line (like code above) */
|
||||
@ -151,11 +140,12 @@ fgetln(FILE *fp, size_t *lenp)
|
||||
break;
|
||||
}
|
||||
*lenp = len;
|
||||
ret = (char *)fp->_lb._base;
|
||||
#ifdef notdef
|
||||
fp->_lb._base[len] = 0;
|
||||
ret[len] = '\0';
|
||||
#endif
|
||||
FUNLOCKFILE(fp);
|
||||
return ((char *)fp->_lb._base);
|
||||
return (ret);
|
||||
|
||||
error:
|
||||
*lenp = 0; /* ??? */
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: fgetpos.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,22 +31,13 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* fgetpos: like ftello.
|
||||
*/
|
||||
int
|
||||
fgetpos(FILE * __restrict fp, fpos_t * __restrict pos)
|
||||
fgetpos(FILE *fp, fpos_t *pos)
|
||||
{
|
||||
/*
|
||||
* ftello is thread-safe; no need to lock fp.
|
||||
*/
|
||||
if ((*pos = ftello(fp)) == (fpos_t)-1)
|
||||
return (-1);
|
||||
else
|
||||
return (0);
|
||||
return((*pos = ftello(fp)) == (fpos_t)-1);
|
||||
}
|
@ -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 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp)
|
||||
}
|
||||
break;
|
||||
}
|
||||
len = fp->_r;
|
||||
}
|
||||
len = fp->_r;
|
||||
p = fp->_p;
|
||||
|
||||
/*
|
||||
@ -93,7 +89,7 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp)
|
||||
fp->_r -= len;
|
||||
fp->_p = t;
|
||||
(void)memcpy((void *)s, (void *)p, len);
|
||||
s[len] = 0;
|
||||
s[len] = '\0';
|
||||
FUNLOCKFILE(fp);
|
||||
return (buf);
|
||||
}
|
||||
@ -103,7 +99,7 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp)
|
||||
s += len;
|
||||
n -= len;
|
||||
}
|
||||
*s = 0;
|
||||
*s = '\0';
|
||||
FUNLOCKFILE(fp);
|
||||
return (buf);
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: fileno.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,35 +31,21 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <stdio.h>
|
||||
#include "un-namespace.h"
|
||||
#include "libc_private.h"
|
||||
#include "local.h"
|
||||
|
||||
/*
|
||||
* A subroutine version of the macro fileno.
|
||||
*/
|
||||
#undef fileno
|
||||
#undef fileno_unlocked
|
||||
|
||||
int
|
||||
fileno(FILE *fp)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
FLOCKFILE(fp);
|
||||
fd = __sfileno(fp);
|
||||
ret = __sfileno(fp);
|
||||
FUNLOCKFILE(fp);
|
||||
|
||||
return (fd);
|
||||
}
|
||||
|
||||
int
|
||||
fileno_unlocked(FILE *fp)
|
||||
{
|
||||
|
||||
return (__sfileno(fp));
|
||||
return (ret);
|
||||
}
|
@ -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 @@ __FBSDID("$FreeBSD$");
|
||||
int
|
||||
fpurge(FILE *fp)
|
||||
{
|
||||
int retval;
|
||||
FLOCKFILE(fp);
|
||||
if (!fp->_flags) {
|
||||
FUNLOCKFILE(fp);
|
||||
errno = EBADF;
|
||||
retval = EOF;
|
||||
} else {
|
||||
if (HASUB(fp))
|
||||
FREEUB(fp);
|
||||
fp->_p = fp->_bf._base;
|
||||
fp->_r = 0;
|
||||
fp->_w = fp->_flags & (__SLBF|__SNBF|__SRD) ? 0 : fp->_bf._size;
|
||||
retval = 0;
|
||||
return(EOF);
|
||||
}
|
||||
|
||||
if (HASUB(fp))
|
||||
FREEUB(fp);
|
||||
WCIO_FREE(fp);
|
||||
fp->_p = fp->_bf._base;
|
||||
fp->_r = 0;
|
||||
fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
|
||||
FUNLOCKFILE(fp);
|
||||
return (retval);
|
||||
return (0);
|
||||
}
|
@ -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.
|
@ -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);
|
||||
}
|
@ -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, ...)
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: fseek.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
|
||||
/* $OpenBSD: fseek.c,v 1.11 2012/05/21 22:24:19 matthew Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -185,7 +185,7 @@ fseeko(FILE *fp, off_t offset, int whence)
|
||||
* skip this; see fgetln.c.)
|
||||
*/
|
||||
if ((fp->_flags & __SMOD) == 0 &&
|
||||
target >= curoff && target < (fpos_t)(curoff + n)) {
|
||||
target >= curoff && target < curoff + n) {
|
||||
int o = target - curoff;
|
||||
|
||||
fp->_p = fp->_bf._base + o;
|
||||
@ -209,13 +209,13 @@ fseeko(FILE *fp, off_t offset, int whence)
|
||||
if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR)
|
||||
goto dumb;
|
||||
fp->_r = 0;
|
||||
fp->_p = fp->_bf._base;
|
||||
fp->_p = fp->_bf._base;
|
||||
if (HASUB(fp))
|
||||
FREEUB(fp);
|
||||
fp->_flags &= ~__SEOF;
|
||||
n = target - curoff;
|
||||
if (n) {
|
||||
if (__srefill(fp) || (size_t)fp->_r < n)
|
||||
if (__srefill(fp) || fp->_r < n)
|
||||
goto dumb;
|
||||
fp->_p += n;
|
||||
fp->_r -= n;
|
||||
@ -244,17 +244,8 @@ dumb:
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* fseek()'s offset is a long and sizeof(off_t) != sizeof(long) on all arches
|
||||
*/
|
||||
#if defined(__alpha__) && defined(__indr_reference)
|
||||
__indr_reference(fseeko, fseek);
|
||||
#else
|
||||
int
|
||||
fseek(FILE *fp, long offset, int whence)
|
||||
{
|
||||
off_t off = offset;
|
||||
|
||||
return(fseeko(fp, off, whence));
|
||||
return (fseeko(fp, offset, whence));
|
||||
}
|
||||
#endif
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: fsetpos.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,17 +31,10 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* fsetpos: like fseek.
|
||||
* fsetpos: like fseeko.
|
||||
*/
|
||||
int
|
||||
fsetpos(FILE *iop, const fpos_t *pos)
|
@ -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 @@ ftello(FILE *fp)
|
||||
if (fp->_seek == NULL) {
|
||||
errno = ESPIPE; /* historic practice */
|
||||
pos = -1;
|
||||
goto out;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find offset of underlying I/O object, then
|
||||
* adjust for buffered bytes.
|
||||
*/
|
||||
FLOCKFILE(fp);
|
||||
FLOCKFILE(fp);
|
||||
__sflush(fp); /* may adjust seek offset on append stream */
|
||||
if (fp->_flags & __SOFF)
|
||||
pos = fp->_offset;
|
||||
@ -83,18 +84,13 @@ out: FUNLOCKFILE(fp);
|
||||
return (pos);
|
||||
}
|
||||
|
||||
/*
|
||||
* ftell() returns a long and sizeof(off_t) != sizeof(long) on all arches
|
||||
*/
|
||||
#if defined(__alpha__) && defined(__indr_reference)
|
||||
__indr_reference(ftello, ftell);
|
||||
#else
|
||||
long
|
||||
ftell(FILE *fp)
|
||||
{
|
||||
long pos;
|
||||
|
||||
pos = (long)ftello(fp);
|
||||
return(pos);
|
||||
off_t offset = ftello(fp);
|
||||
if (offset > LONG_MAX) {
|
||||
errno = EOVERFLOW;
|
||||
return (-1);
|
||||
}
|
||||
return ((long)offset);
|
||||
}
|
||||
#endif
|
@ -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 @@ funopen(const void *cookie,
|
||||
return (NULL);
|
||||
fp->_flags = flags;
|
||||
fp->_file = -1;
|
||||
fp->_cookie = (void *)cookie;
|
||||
fp->_cookie = (void *)cookie; /* SAFE: cookie not modified */
|
||||
fp->_read = readfn;
|
||||
fp->_write = writefn;
|
||||
fp->_seek = seekfn;
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: fwalk.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,13 +31,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
#include "glue.h"
|
||||
@ -49,17 +44,10 @@ _fwalk(int (*function)(FILE *))
|
||||
struct glue *g;
|
||||
|
||||
ret = 0;
|
||||
/*
|
||||
* It should be safe to walk the list without locking it;
|
||||
* new nodes are only added to the end and none are ever
|
||||
* removed.
|
||||
*
|
||||
* Avoid locking this list while walking it or else you will
|
||||
* introduce a potential deadlock in [at least] refill.c.
|
||||
*/
|
||||
for (g = &__sglue; g != NULL; g = g->next)
|
||||
for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
|
||||
for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) {
|
||||
if ((fp->_flags != 0) && ((fp->_flags & __SIGN) == 0))
|
||||
ret |= (*function)(fp);
|
||||
}
|
||||
return (ret);
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: getc.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,36 +31,32 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <stdio.h>
|
||||
#include "un-namespace.h"
|
||||
#include "libc_private.h"
|
||||
#include "local.h"
|
||||
|
||||
#undef getc
|
||||
/*
|
||||
* A subroutine version of the macro getc_unlocked.
|
||||
*/
|
||||
#undef getc_unlocked
|
||||
|
||||
int
|
||||
getc(FILE *fp)
|
||||
{
|
||||
int retval;
|
||||
FLOCKFILE(fp);
|
||||
/* Orientation set by __sgetc() when buffer is empty. */
|
||||
/* ORIENT(fp, -1); */
|
||||
retval = __sgetc(fp);
|
||||
FUNLOCKFILE(fp);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
int
|
||||
getc_unlocked(FILE *fp)
|
||||
{
|
||||
|
||||
return (__sgetc(fp));
|
||||
}
|
||||
|
||||
/*
|
||||
* A subroutine version of the macro getc.
|
||||
*/
|
||||
#undef getc
|
||||
|
||||
int
|
||||
getc(FILE *fp)
|
||||
{
|
||||
int c;
|
||||
|
||||
FLOCKFILE(fp);
|
||||
c = __sgetc(fp);
|
||||
FUNLOCKFILE(fp);
|
||||
return (c);
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: getchar.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,39 +31,28 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* A subroutine version of the macro getchar.
|
||||
* A subroutine version of the macro getchar_unlocked.
|
||||
*/
|
||||
#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));
|
||||
return (getc_unlocked(stdin));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* A subroutine version of the macro getchar.
|
||||
*/
|
||||
|
||||
#undef getchar
|
||||
|
||||
int
|
||||
getchar(void)
|
||||
{
|
||||
return (getc(stdin));
|
||||
}
|
@ -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 @@ __getdelim(char **__restrict buf, size_t *__restrict buflen,
|
||||
if (newlen > *buflen) {
|
||||
if (newlen < MINBUF)
|
||||
newlen = MINBUF;
|
||||
#define powerof2(x) ((((x)-1)&(x))==0)
|
||||
if (!powerof2(newlen)) {
|
||||
/* Grow the buffer to the next power of 2 */
|
||||
newlen--;
|
||||
@ -128,8 +117,10 @@ __getdelim(char **__restrict buf, size_t *__restrict buflen,
|
||||
off += len;
|
||||
} while (p == NULL);
|
||||
|
||||
FUNLOCKFILE(fp);
|
||||
|
||||
/* POSIX demands we return -1 on EOF. */
|
||||
if (off == 0)
|
||||
if (off == 0)
|
||||
return -1;
|
||||
|
||||
if (*buf != NULL)
|
||||
@ -138,17 +129,6 @@ __getdelim(char **__restrict buf, size_t *__restrict buflen,
|
||||
|
||||
error:
|
||||
fp->_flags |= __SERR;
|
||||
FUNLOCKFILE(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
getdelim(char **__restrict buf, size_t *__restrict buflen,
|
||||
int sep, FILE *__restrict fp)
|
||||
{
|
||||
ssize_t n;
|
||||
|
||||
FLOCKFILE(fp);
|
||||
n = __getdelim(buf, buflen, sep, fp);
|
||||
FUNLOCKFILE(fp);
|
||||
return n;
|
||||
}
|
@ -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)
|
||||
{
|
@ -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.
|
62
libc/upstream-openbsd/lib/libc/stdio/perror.c
Normal file
62
libc/upstream-openbsd/lib/libc/stdio/perror.c
Normal file
@ -0,0 +1,62 @@
|
||||
/* $OpenBSD: perror.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
void
|
||||
perror(const char *s)
|
||||
{
|
||||
struct iovec *v;
|
||||
struct iovec iov[4];
|
||||
char buf[NL_TEXTMAX];
|
||||
|
||||
v = iov;
|
||||
if (s && *s) {
|
||||
v->iov_base = (char *)s;
|
||||
v->iov_len = strlen(s);
|
||||
v++;
|
||||
v->iov_base = ": ";
|
||||
v->iov_len = 2;
|
||||
v++;
|
||||
}
|
||||
(void)strerror_r(errno, buf, sizeof(buf));
|
||||
v->iov_base = buf;
|
||||
v->iov_len = strlen(v->iov_base);
|
||||
v++;
|
||||
v->iov_base = "\n";
|
||||
v->iov_len = 1;
|
||||
(void)writev(STDERR_FILENO, iov, (v - iov) + 1);
|
||||
}
|
@ -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, ...)
|
||||
{
|
@ -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);
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: putchar.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,20 +31,21 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <stdio.h>
|
||||
#include "un-namespace.h"
|
||||
#include "local.h"
|
||||
#include "libc_private.h"
|
||||
|
||||
#undef putchar_unlocked
|
||||
/*
|
||||
* A subrouting version of the macro putchar_unlocked
|
||||
*/
|
||||
int
|
||||
putchar_unlocked(int c)
|
||||
{
|
||||
FILE *so = stdout;
|
||||
|
||||
return (putc_unlocked(c,so));
|
||||
}
|
||||
|
||||
#undef putchar
|
||||
#undef putchar_unlocked
|
||||
|
||||
/*
|
||||
* A subroutine version of the macro putchar
|
||||
@ -51,20 +53,7 @@ __FBSDID("$FreeBSD$");
|
||||
int
|
||||
putchar(int c)
|
||||
{
|
||||
int retval;
|
||||
FILE *so = stdout;
|
||||
|
||||
FLOCKFILE(so);
|
||||
/* Orientation set by __sputc() when buffer is full. */
|
||||
/* ORIENT(so, -1); */
|
||||
retval = __sputc(c, so);
|
||||
FUNLOCKFILE(so);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
int
|
||||
putchar_unlocked(int ch)
|
||||
{
|
||||
|
||||
return (__sputc(ch, stdout));
|
||||
return (putc(c, so));
|
||||
}
|
@ -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 @@ puts(char const *s)
|
||||
uio.uio_iov = &iov[0];
|
||||
uio.uio_iovcnt = 2;
|
||||
FLOCKFILE(stdout);
|
||||
ORIENT(stdout, -1);
|
||||
retval = __sfvwrite(stdout, &uio) ? EOF : '\n';
|
||||
_SET_ORIENTATION(stdout, -1);
|
||||
ret = __sfvwrite(stdout, &uio);
|
||||
FUNLOCKFILE(stdout);
|
||||
return (retval);
|
||||
return (ret ? EOF : '\n');
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: refill.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */
|
||||
/* $OpenBSD: refill.c,v 1.11 2009/11/09 00:18:27 kurt Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -40,7 +40,7 @@ static int
|
||||
lflush(FILE *fp)
|
||||
{
|
||||
if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
|
||||
return (__sflush_locked(fp)); /* ignored... */
|
||||
return (__sflush_locked(fp)); /* ignored... */
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ __srefill(FILE *fp)
|
||||
|
||||
/* Now flush this file without locking it. */
|
||||
if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
|
||||
__sflush(fp);
|
||||
__sflush(fp);
|
||||
}
|
||||
fp->_p = fp->_bf._base;
|
||||
fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size);
|
@ -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));
|
||||
}
|
@ -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 @@ __FBSDID("$FreeBSD$");
|
||||
int
|
||||
__srget(FILE *fp)
|
||||
{
|
||||
_SET_ORIENTATION(fp, -1);
|
||||
if (__srefill(fp) == 0) {
|
||||
fp->_r--;
|
||||
return (*fp->_p++);
|
@ -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, ...)
|
||||
{
|
@ -1,3 +1,4 @@
|
||||
/* $OpenBSD: setbuf.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -30,17 +31,11 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)setbuf.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
|
||||
void
|
||||
setbuf(FILE * __restrict fp, char * __restrict buf)
|
||||
setbuf(FILE *fp, char *buf)
|
||||
{
|
||||
(void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
@ -45,7 +45,7 @@ __sread(void *cookie, char *buf, int n)
|
||||
{
|
||||
FILE *fp = cookie;
|
||||
int ret;
|
||||
|
||||
|
||||
ret = read(fp->_file, buf, n);
|
||||
/* if the read succeeded, update the current offset */
|
||||
if (ret >= 0)
|
||||
@ -71,7 +71,7 @@ __sseek(void *cookie, fpos_t offset, int whence)
|
||||
{
|
||||
FILE *fp = cookie;
|
||||
off_t ret;
|
||||
|
||||
|
||||
ret = lseek(fp->_file, (off_t)offset, whence);
|
||||
if (ret == (off_t)-1)
|
||||
fp->_flags &= ~__SOFF;
|
@ -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 @@ extern char *_mktemp(char *);
|
||||
char *
|
||||
tempnam(const char *dir, const char *pfx)
|
||||
{
|
||||
int sverrno;
|
||||
int sverrno, len;
|
||||
char *f, *name;
|
||||
|
||||
if (!(name = malloc(MAXPATHLEN)))
|
||||
if (!(name = malloc(PATH_MAX)))
|
||||
return(NULL);
|
||||
|
||||
if (!pfx)
|
||||
pfx = "tmp.";
|
||||
|
||||
if (issetugid() == 0 && (f = getenv("TMPDIR"))) {
|
||||
(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
|
||||
*(f + strlen(f) - 1) == '/'? "": "/", pfx);
|
||||
if (issetugid() == 0 && (f = getenv("TMPDIR")) && *f != '\0') {
|
||||
len = snprintf(name, PATH_MAX, "%s%s%sXXXXXXXXXX", f,
|
||||
f[strlen(f) - 1] == '/' ? "" : "/", pfx);
|
||||
if (len < 0 || len >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return(NULL);
|
||||
}
|
||||
if ((f = _mktemp(name)))
|
||||
return(f);
|
||||
}
|
||||
|
||||
if ((f = (char *)dir)) {
|
||||
(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
|
||||
*(f + strlen(f) - 1) == '/'? "": "/", pfx);
|
||||
if (dir != NULL) {
|
||||
f = *dir ? (char *)dir : ".";
|
||||
len = snprintf(name, PATH_MAX, "%s%s%sXXXXXXXXXX", f,
|
||||
f[strlen(f) - 1] == '/' ? "" : "/", pfx);
|
||||
if (len < 0 || len >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return(NULL);
|
||||
}
|
||||
if ((f = _mktemp(name)))
|
||||
return(f);
|
||||
}
|
||||
|
||||
f = P_tmpdir;
|
||||
(void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
|
||||
len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx);
|
||||
if (len < 0 || len >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return(NULL);
|
||||
}
|
||||
if ((f = _mktemp(name)))
|
||||
return(f);
|
||||
|
||||
f = _PATH_TMP;
|
||||
(void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
|
||||
len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx);
|
||||
if (len < 0 || len >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return(NULL);
|
||||
}
|
||||
if ((f = _mktemp(name)))
|
||||
return(f);
|
||||
|
@ -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 @@ tmpnam(char *s)
|
||||
|
||||
if (s == NULL)
|
||||
s = buf;
|
||||
(void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount);
|
||||
(void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXXXXX", P_tmpdir, tmpcount);
|
||||
++tmpcount;
|
||||
return (_mktemp(s));
|
||||
}
|
@ -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.
|
@ -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 @@ vasprintf(char **str, const char *fmt, __va_list ap)
|
||||
return (ret);
|
||||
|
||||
err:
|
||||
free(f._bf._base);
|
||||
if (f._bf._base) {
|
||||
free(f._bf._base);
|
||||
f._bf._base = NULL;
|
||||
}
|
||||
*str = NULL;
|
||||
errno = ENOMEM;
|
||||
return (-1);
|
@ -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.
|
@ -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.
|
@ -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.
|
@ -1,6 +1,6 @@
|
||||
/* $OpenBSD: strtoull.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1992 The Regents of the University of California.
|
||||
/* $OpenBSD: atoi.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1988 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -28,22 +28,10 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <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)
|
||||
int
|
||||
atoi(const char *str)
|
||||
{
|
||||
return (unsigned long long)strtoumax(nptr, endptr, base);
|
||||
return((int)strtol(str, (char **)NULL, 10));
|
||||
}
|
37
libc/upstream-openbsd/lib/libc/stdlib/atol.c
Normal file
37
libc/upstream-openbsd/lib/libc/stdlib/atol.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* $OpenBSD: atol.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1988 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
long
|
||||
atol(const char *str)
|
||||
{
|
||||
return(strtol(str, (char **)NULL, 10));
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/* $OpenBSD: strtoll.c,v 1.6 2005/11/10 10:00:17 espie Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1992 The Regents of the University of California.
|
||||
/* $OpenBSD: atoll.c,v 1.3 2005/08/08 08:05:36 espie Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1988 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -28,23 +28,11 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <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)
|
||||
atoll(str)
|
||||
const char *str;
|
||||
{
|
||||
return strtoimax(nptr, endptr, base);
|
||||
return(strtoll(str, (char **)NULL, 10));
|
||||
}
|
||||
|
@ -91,40 +91,9 @@ strtoimax(const char *nptr, char **endptr, int base)
|
||||
* Set any if any `digits' consumed; make it negative to indicate
|
||||
* overflow.
|
||||
*/
|
||||
|
||||
/* BIONIC: avoid division and module for common cases */
|
||||
#define CASE_BASE(x) \
|
||||
case x: \
|
||||
if (neg) { \
|
||||
cutlim = INTMAX_MIN % x; \
|
||||
cutoff = INTMAX_MIN / x; \
|
||||
} else { \
|
||||
cutlim = INTMAX_MAX % x; \
|
||||
cutoff = INTMAX_MAX / x; \
|
||||
}; \
|
||||
break
|
||||
|
||||
switch (base) {
|
||||
case 4:
|
||||
if (neg) {
|
||||
cutlim = (int)(INTMAX_MIN % 4);
|
||||
cutoff = INTMAX_MIN / 4;
|
||||
} else {
|
||||
cutlim = (int)(INTMAX_MAX % 4);
|
||||
cutoff = INTMAX_MAX / 4;
|
||||
}
|
||||
break;
|
||||
|
||||
CASE_BASE(8);
|
||||
CASE_BASE(10);
|
||||
CASE_BASE(16);
|
||||
default:
|
||||
cutoff = neg ? INTMAX_MIN : INTMAX_MAX;
|
||||
cutlim = cutoff % base;
|
||||
cutoff /= base;
|
||||
}
|
||||
#undef CASE_BASE
|
||||
|
||||
cutoff = neg ? INTMAX_MIN : INTMAX_MAX;
|
||||
cutlim = cutoff % base;
|
||||
cutoff /= base;
|
||||
if (neg) {
|
||||
if (cutlim > 0) {
|
||||
cutlim -= base;
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: strtol.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
|
||||
/* $OpenBSD: strtol.c,v 1.9 2013/04/17 17:40:35 tedu Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
@ -48,6 +48,17 @@ strtol(const char *nptr, char **endptr, int base)
|
||||
int c;
|
||||
int neg, any, cutlim;
|
||||
|
||||
/*
|
||||
* Ensure that base is between 2 and 36 inclusive, or the special
|
||||
* value of 0.
|
||||
*/
|
||||
if (base != 0 && (base < 2 || base > 36)) {
|
||||
if (endptr != 0)
|
||||
*endptr = (char *)nptr;
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip white space and pick up leading +/- sign if any.
|
||||
* If base is 0, allow 0x for hex and 0 for octal, else
|
144
libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
Normal file
144
libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
Normal file
@ -0,0 +1,144 @@
|
||||
/* $OpenBSD: strtoll.c,v 1.7 2013/03/28 18:09:38 martynas Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1992 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.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)
|
||||
{
|
||||
const char *s;
|
||||
long long acc, cutoff;
|
||||
int c;
|
||||
int neg, any, cutlim;
|
||||
|
||||
/*
|
||||
* Skip white space and pick up leading +/- sign if any.
|
||||
* If base is 0, allow 0x for hex and 0 for octal, else
|
||||
* assume decimal; if base is already 16, allow 0x.
|
||||
*/
|
||||
s = nptr;
|
||||
do {
|
||||
c = (unsigned char) *s++;
|
||||
} while (isspace(c));
|
||||
if (c == '-') {
|
||||
neg = 1;
|
||||
c = *s++;
|
||||
} else {
|
||||
neg = 0;
|
||||
if (c == '+')
|
||||
c = *s++;
|
||||
}
|
||||
if ((base == 0 || base == 16) &&
|
||||
c == '0' && (*s == 'x' || *s == 'X')) {
|
||||
c = s[1];
|
||||
s += 2;
|
||||
base = 16;
|
||||
}
|
||||
if (base == 0)
|
||||
base = c == '0' ? 8 : 10;
|
||||
|
||||
/*
|
||||
* Compute the cutoff value between legal numbers and illegal
|
||||
* numbers. That is the largest legal value, divided by the
|
||||
* base. An input number that is greater than this value, if
|
||||
* followed by a legal input character, is too big. One that
|
||||
* is equal to this value may be valid or not; the limit
|
||||
* between valid and invalid numbers is then based on the last
|
||||
* digit. For instance, if the range for long longs is
|
||||
* [-9223372036854775808..9223372036854775807] and the input base
|
||||
* is 10, cutoff will be set to 922337203685477580 and cutlim to
|
||||
* either 7 (neg==0) or 8 (neg==1), meaning that if we have
|
||||
* accumulated a value > 922337203685477580, or equal but the
|
||||
* next digit is > 7 (or 8), the number is too big, and we will
|
||||
* return a range error.
|
||||
*
|
||||
* Set any if any `digits' consumed; make it negative to indicate
|
||||
* overflow.
|
||||
*/
|
||||
cutoff = neg ? LLONG_MIN : LLONG_MAX;
|
||||
cutlim = cutoff % base;
|
||||
cutoff /= base;
|
||||
if (neg) {
|
||||
if (cutlim > 0) {
|
||||
cutlim -= base;
|
||||
cutoff += 1;
|
||||
}
|
||||
cutlim = -cutlim;
|
||||
}
|
||||
for (acc = 0, any = 0;; c = (unsigned char) *s++) {
|
||||
if (isdigit(c))
|
||||
c -= '0';
|
||||
else if (isalpha(c))
|
||||
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
||||
else
|
||||
break;
|
||||
if (c >= base)
|
||||
break;
|
||||
if (any < 0)
|
||||
continue;
|
||||
if (neg) {
|
||||
if (acc < cutoff || (acc == cutoff && c > cutlim)) {
|
||||
any = -1;
|
||||
acc = LLONG_MIN;
|
||||
errno = ERANGE;
|
||||
} else {
|
||||
any = 1;
|
||||
acc *= base;
|
||||
acc -= c;
|
||||
}
|
||||
} else {
|
||||
if (acc > cutoff || (acc == cutoff && c > cutlim)) {
|
||||
any = -1;
|
||||
acc = LLONG_MAX;
|
||||
errno = ERANGE;
|
||||
} else {
|
||||
any = 1;
|
||||
acc *= base;
|
||||
acc += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (endptr != 0)
|
||||
*endptr = (char *) (any ? s - 1 : nptr);
|
||||
return (acc);
|
||||
}
|
||||
|
||||
__strong_alias(strtoq, strtoll);
|
@ -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.
|
106
libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
Normal file
106
libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
Normal file
@ -0,0 +1,106 @@
|
||||
/* $OpenBSD: strtoull.c,v 1.6 2013/03/28 18:09:38 martynas Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1992 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.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)
|
||||
{
|
||||
const char *s;
|
||||
unsigned long long acc, cutoff;
|
||||
int c;
|
||||
int neg, any, cutlim;
|
||||
|
||||
/*
|
||||
* See strtoq for comments as to the logic used.
|
||||
*/
|
||||
s = nptr;
|
||||
do {
|
||||
c = (unsigned char) *s++;
|
||||
} while (isspace(c));
|
||||
if (c == '-') {
|
||||
neg = 1;
|
||||
c = *s++;
|
||||
} else {
|
||||
neg = 0;
|
||||
if (c == '+')
|
||||
c = *s++;
|
||||
}
|
||||
if ((base == 0 || base == 16) &&
|
||||
c == '0' && (*s == 'x' || *s == 'X')) {
|
||||
c = s[1];
|
||||
s += 2;
|
||||
base = 16;
|
||||
}
|
||||
if (base == 0)
|
||||
base = c == '0' ? 8 : 10;
|
||||
|
||||
cutoff = ULLONG_MAX / (unsigned long long)base;
|
||||
cutlim = ULLONG_MAX % (unsigned long long)base;
|
||||
for (acc = 0, any = 0;; c = (unsigned char) *s++) {
|
||||
if (isdigit(c))
|
||||
c -= '0';
|
||||
else if (isalpha(c))
|
||||
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
||||
else
|
||||
break;
|
||||
if (c >= base)
|
||||
break;
|
||||
if (any < 0)
|
||||
continue;
|
||||
if (acc > cutoff || (acc == cutoff && c > cutlim)) {
|
||||
any = -1;
|
||||
acc = ULLONG_MAX;
|
||||
errno = ERANGE;
|
||||
} else {
|
||||
any = 1;
|
||||
acc *= (unsigned long long)base;
|
||||
acc += c;
|
||||
}
|
||||
}
|
||||
if (neg && any > 0)
|
||||
acc = -acc;
|
||||
if (endptr != 0)
|
||||
*endptr = (char *) (any ? s - 1 : nptr);
|
||||
return (acc);
|
||||
}
|
||||
|
||||
__strong_alias(strtouq, strtoull);
|
@ -57,7 +57,7 @@ strtoumax(const char *nptr, char **endptr, int base)
|
||||
if (c == '-') {
|
||||
neg = 1;
|
||||
c = *s++;
|
||||
} else {
|
||||
} else {
|
||||
neg = 0;
|
||||
if (c == '+')
|
||||
c = *s++;
|
||||
@ -71,21 +71,8 @@ strtoumax(const char *nptr, char **endptr, int base)
|
||||
if (base == 0)
|
||||
base = c == '0' ? 8 : 10;
|
||||
|
||||
/* BIONIC: avoid division and modulo for common cases */
|
||||
#define CASE_BASE(x) \
|
||||
case x: cutoff = UINTMAX_MAX / x; \
|
||||
cutlim = UINTMAX_MAX % x; \
|
||||
break
|
||||
|
||||
switch (base) {
|
||||
CASE_BASE(8);
|
||||
CASE_BASE(10);
|
||||
CASE_BASE(16);
|
||||
default:
|
||||
cutoff = UINTMAX_MAX / base;
|
||||
cutlim = UINTMAX_MAX % base;
|
||||
}
|
||||
|
||||
cutoff = UINTMAX_MAX / (uintmax_t)base;
|
||||
cutlim = UINTMAX_MAX % (uintmax_t)base;
|
||||
for (acc = 0, any = 0;; c = (unsigned char) *s++) {
|
||||
if (isdigit(c))
|
||||
c -= '0';
|
39
libc/upstream-openbsd/lib/libc/string/strndup.c
Normal file
39
libc/upstream-openbsd/lib/libc/string/strndup.c
Normal file
@ -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;
|
||||
}
|
@ -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.
|
22
libc/upstream-openbsd/openbsd-compat.h
Normal file
22
libc/upstream-openbsd/openbsd-compat.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user