am 5c7816f4: Merge "More OpenBSD cleanup (primarily string)."

* commit '5c7816f425cb70ca6920e816aba33ce3d691ef10':
  More OpenBSD cleanup (primarily string).
This commit is contained in:
Elliott Hughes 2014-02-25 21:47:41 +00:00 committed by Android Git Automerger
commit 6358fc2d0b
32 changed files with 295 additions and 293 deletions

View File

@ -84,9 +84,7 @@ libc/
netbsd/
stdio/
stdlib/
string/
unistd/
wchar/
# These are legacy files of unknown provenance. In the past, bionic was a
# mess of random versions of random files from all three of FreeBSD, NetBSD,
# and OpenBSD! We've been working to clean that up, but these directories

View File

@ -45,7 +45,6 @@ libc_common_src_files := \
bionic/ether_aton.c \
bionic/ether_ntoa.c \
bionic/fdprintf.c \
bionic/flockfile.c \
bionic/ftime.c \
bionic/fts.c \
bionic/getdtablesize.c \
@ -109,8 +108,6 @@ libc_common_src_files := \
unistd/syslog.c \
unistd/system.c \
unistd/time.c \
wchar/wcswidth.c \
wchar/wcsxfrm.c \
# Fortify implementations of libc functions.
libc_common_src_files += \
@ -149,6 +146,7 @@ libc_bionic_src_files := \
bionic/eventfd_read.cpp \
bionic/eventfd_write.cpp \
bionic/ffs.cpp \
bionic/flockfile.cpp \
bionic/fork.cpp \
bionic/futimens.cpp \
bionic/getauxval.cpp \
@ -261,7 +259,6 @@ libc_upstream_freebsd_src_files := \
upstream-freebsd/lib/libc/string/wcscspn.c \
upstream-freebsd/lib/libc/string/wcsdup.c \
upstream-freebsd/lib/libc/string/wcslcat.c \
upstream-freebsd/lib/libc/string/wcslcpy.c \
upstream-freebsd/lib/libc/string/wcsncasecmp.c \
upstream-freebsd/lib/libc/string/wcsncat.c \
upstream-freebsd/lib/libc/string/wcsncmp.c \
@ -319,6 +316,80 @@ libc_upstream_netbsd_src_files := \
upstream-netbsd/lib/libc/thread-stub/__isthreaded.c \
upstream-netbsd/lib/libc/unistd/killpg.c \
libc_upstream_openbsd_src_files := \
upstream-openbsd/lib/libc/gen/exec.c \
upstream-openbsd/lib/libc/gen/ftok.c \
upstream-openbsd/lib/libc/gen/fnmatch.c \
upstream-openbsd/lib/libc/gen/toupper_.c \
upstream-openbsd/lib/libc/gen/tolower_.c \
upstream-openbsd/lib/libc/string/strstr.c \
upstream-openbsd/lib/libc/string/strsep.c \
upstream-openbsd/lib/libc/string/wcslcpy.c \
upstream-openbsd/lib/libc/string/strcasecmp.c \
upstream-openbsd/lib/libc/string/strdup.c \
upstream-openbsd/lib/libc/string/strcspn.c \
upstream-openbsd/lib/libc/string/strtok.c \
upstream-openbsd/lib/libc/string/strpbrk.c \
upstream-openbsd/lib/libc/string/strspn.c \
upstream-openbsd/lib/libc/string/wcswidth.c \
upstream-openbsd/lib/libc/string/strndup.c \
upstream-openbsd/lib/libc/stdio/ungetc.c \
upstream-openbsd/lib/libc/stdio/vsnprintf.c \
upstream-openbsd/lib/libc/stdio/tmpnam.c \
upstream-openbsd/lib/libc/stdio/setbuffer.c \
upstream-openbsd/lib/libc/stdio/fsetpos.c \
upstream-openbsd/lib/libc/stdio/setbuf.c \
upstream-openbsd/lib/libc/stdio/vprintf.c \
upstream-openbsd/lib/libc/stdio/perror.c \
upstream-openbsd/lib/libc/stdio/remove.c \
upstream-openbsd/lib/libc/stdio/getc.c \
upstream-openbsd/lib/libc/stdio/funopen.c \
upstream-openbsd/lib/libc/stdio/ferror.c \
upstream-openbsd/lib/libc/stdio/putchar.c \
upstream-openbsd/lib/libc/stdio/vscanf.c \
upstream-openbsd/lib/libc/stdio/fflush.c \
upstream-openbsd/lib/libc/stdio/fpurge.c \
upstream-openbsd/lib/libc/stdio/fputs.c \
upstream-openbsd/lib/libc/stdio/tempnam.c \
upstream-openbsd/lib/libc/stdio/printf.c \
upstream-openbsd/lib/libc/stdio/fileno.c \
upstream-openbsd/lib/libc/stdio/stdio.c \
upstream-openbsd/lib/libc/stdio/getdelim.c \
upstream-openbsd/lib/libc/stdio/fseek.c \
upstream-openbsd/lib/libc/stdio/fputc.c \
upstream-openbsd/lib/libc/stdio/fgetln.c \
upstream-openbsd/lib/libc/stdio/fdopen.c \
upstream-openbsd/lib/libc/stdio/fgets.c \
upstream-openbsd/lib/libc/stdio/fgetc.c \
upstream-openbsd/lib/libc/stdio/feof.c \
upstream-openbsd/lib/libc/stdio/vasprintf.c \
upstream-openbsd/lib/libc/stdio/refill.c \
upstream-openbsd/lib/libc/stdio/getline.c \
upstream-openbsd/lib/libc/stdio/rewind.c \
upstream-openbsd/lib/libc/stdio/wbuf.c \
upstream-openbsd/lib/libc/stdio/gets.c \
upstream-openbsd/lib/libc/stdio/fgetpos.c \
upstream-openbsd/lib/libc/stdio/fscanf.c \
upstream-openbsd/lib/libc/stdio/putc.c \
upstream-openbsd/lib/libc/stdio/vsprintf.c \
upstream-openbsd/lib/libc/stdio/rget.c \
upstream-openbsd/lib/libc/stdio/clrerr.c \
upstream-openbsd/lib/libc/stdio/scanf.c \
upstream-openbsd/lib/libc/stdio/puts.c \
upstream-openbsd/lib/libc/stdio/getchar.c \
upstream-openbsd/lib/libc/stdio/ftell.c \
upstream-openbsd/lib/libc/stdio/fwalk.c \
upstream-openbsd/lib/libc/stdlib/strtoul.c \
upstream-openbsd/lib/libc/stdlib/strtoull.c \
upstream-openbsd/lib/libc/stdlib/atoi.c \
upstream-openbsd/lib/libc/stdlib/atoll.c \
upstream-openbsd/lib/libc/stdlib/atol.c \
upstream-openbsd/lib/libc/stdlib/strtoimax.c \
upstream-openbsd/lib/libc/stdlib/strtoumax.c \
upstream-openbsd/lib/libc/stdlib/strtoll.c \
upstream-openbsd/lib/libc/stdlib/strtol.c \
upstream-openbsd/lib/libc/locale/wcsxfrm.c \
libc_arch_static_src_files := \
bionic/dl_iterate_phdr_static.cpp \
@ -514,7 +585,7 @@ include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-c-files-under,upstream-openbsd)
LOCAL_SRC_FILES := $(libc_upstream_openbsd_src_files)
LOCAL_CFLAGS := \
$(libc_common_cflags) \
-I$(LOCAL_PATH)/upstream-openbsd \

View File

@ -10,19 +10,13 @@ libc_bionic_src_files_arm := \
bionic/mmap.cpp
libc_common_src_files_arm += \
bionic/index.cpp \
bionic/memchr.c \
bionic/memmove.c.arm \
bionic/memrchr.c \
bionic/strchr.cpp \
bionic/strnlen.c \
string/bcopy.c \
string/index.c \
string/strlcat.c \
string/strlcpy.c \
string/strncat.c \
string/strncmp.c \
string/strncpy.c \
string/strrchr.c \
bionic/strrchr.cpp \
upstream-freebsd/lib/libc/string/wcscat.c \
upstream-freebsd/lib/libc/string/wcschr.c \
upstream-freebsd/lib/libc/string/wcscmp.c \
@ -30,6 +24,12 @@ libc_common_src_files_arm += \
upstream-freebsd/lib/libc/string/wcslen.c \
upstream-freebsd/lib/libc/string/wcsrchr.c \
upstream-freebsd/lib/libc/string/wmemcmp.c \
upstream-openbsd/lib/libc/string/bcopy.c \
upstream-openbsd/lib/libc/string/strlcat.c \
upstream-openbsd/lib/libc/string/strlcpy.c \
upstream-openbsd/lib/libc/string/strncat.c \
upstream-openbsd/lib/libc/string/strncmp.c \
upstream-openbsd/lib/libc/string/strncpy.c \
# The C++ fortify function implementations for which there is an
# arm assembler version.

View File

@ -1,9 +1,9 @@
libc_bionic_src_files_arm += \
arch-arm/generic/bionic/memcpy.S \
arch-arm/generic/bionic/memset.S \
string/strcat.c \
arch-arm/generic/bionic/strcmp.S \
arch-arm/generic/bionic/strcpy.S \
arch-arm/generic/bionic/strlen.c \
bionic/__strcat_chk.cpp \
bionic/__strcpy_chk.cpp \
upstream-openbsd/lib/libc/string/strcat.c \

View File

@ -1,7 +1,9 @@
# arm64 specific configs
libc_common_src_files_arm64 := \
bionic/index.cpp \
bionic/memchr.c \
bionic/__memcmp16.cpp \
bionic/memcmp.c \
bionic/memcpy.c \
bionic/memmove.c \
@ -9,19 +11,7 @@ libc_common_src_files_arm64 := \
bionic/memset.c \
bionic/strchr.cpp \
bionic/strnlen.c \
string/bcopy.c \
string/index.c \
string/memcmp16.c \
string/strcat.c \
string/strcmp.c \
string/strcpy.c \
string/strlcat.c \
string/strlcpy.c \
string/strlen.c \
string/strncat.c \
string/strncmp.c \
string/strncpy.c \
string/strrchr.c \
bionic/strrchr.cpp \
upstream-freebsd/lib/libc/string/wcscat.c \
upstream-freebsd/lib/libc/string/wcschr.c \
upstream-freebsd/lib/libc/string/wcscmp.c \
@ -29,6 +19,16 @@ libc_common_src_files_arm64 := \
upstream-freebsd/lib/libc/string/wcslen.c \
upstream-freebsd/lib/libc/string/wcsrchr.c \
upstream-freebsd/lib/libc/string/wmemcmp.c \
upstream-openbsd/lib/libc/string/bcopy.c \
upstream-openbsd/lib/libc/string/strcat.c \
upstream-openbsd/lib/libc/string/strcmp.c \
upstream-openbsd/lib/libc/string/strcpy.c \
upstream-openbsd/lib/libc/string/strlcat.c \
upstream-openbsd/lib/libc/string/strlcpy.c \
upstream-openbsd/lib/libc/string/strlen.c \
upstream-openbsd/lib/libc/string/strncat.c \
upstream-openbsd/lib/libc/string/strncmp.c \
upstream-openbsd/lib/libc/string/strncpy.c \
# Fortify implementations of libc functions.
libc_common_src_files_arm64 += \

View File

@ -10,23 +10,14 @@ libc_bionic_src_files_mips += \
bionic/mmap.cpp
libc_common_src_files_mips += \
bionic/index.cpp \
bionic/memchr.c \
bionic/memcmp.c \
bionic/memmove.c \
bionic/memrchr.c \
bionic/strchr.cpp \
bionic/strnlen.c \
string/bcopy.c \
string/index.c \
string/strcat.c \
string/strcmp.c \
string/strcpy.c \
string/strlcat.c \
string/strlcpy.c \
string/strncat.c \
string/strncmp.c \
string/strncpy.c \
string/strrchr.c \
bionic/strrchr.cpp \
upstream-freebsd/lib/libc/string/wcscat.c \
upstream-freebsd/lib/libc/string/wcschr.c \
upstream-freebsd/lib/libc/string/wcscmp.c \
@ -34,6 +25,15 @@ libc_common_src_files_mips += \
upstream-freebsd/lib/libc/string/wcslen.c \
upstream-freebsd/lib/libc/string/wcsrchr.c \
upstream-freebsd/lib/libc/string/wmemcmp.c \
upstream-openbsd/lib/libc/string/bcopy.c \
upstream-openbsd/lib/libc/string/strcat.c \
upstream-openbsd/lib/libc/string/strcmp.c \
upstream-openbsd/lib/libc/string/strcpy.c \
upstream-openbsd/lib/libc/string/strlcat.c \
upstream-openbsd/lib/libc/string/strlcpy.c \
upstream-openbsd/lib/libc/string/strncat.c \
upstream-openbsd/lib/libc/string/strncmp.c \
upstream-openbsd/lib/libc/string/strncpy.c \
# Fortify implementations of libc functions.
libc_common_src_files_mips += \

View File

@ -1,23 +1,14 @@
# mips64 specific configs
libc_common_src_files_mips64 := \
bionic/index.cpp \
bionic/memchr.c \
bionic/memcmp.c \
bionic/memmove.c \
bionic/memrchr.c \
bionic/strchr.cpp \
bionic/strnlen.c \
string/bcopy.c \
string/index.c \
string/strcat.c \
string/strcmp.c \
string/strcpy.c \
string/strlcat.c \
string/strlcpy.c \
string/strncat.c \
string/strncmp.c \
string/strncpy.c \
string/strrchr.c \
bionic/strrchr.cpp \
upstream-freebsd/lib/libc/string/wcscat.c \
upstream-freebsd/lib/libc/string/wcschr.c \
upstream-freebsd/lib/libc/string/wcscmp.c \
@ -25,6 +16,16 @@ libc_common_src_files_mips64 := \
upstream-freebsd/lib/libc/string/wcslen.c \
upstream-freebsd/lib/libc/string/wcsrchr.c \
upstream-freebsd/lib/libc/string/wmemcmp.c \
upstream-openbsd/lib/libc/string/bcopy.c \
upstream-openbsd/lib/libc/string/strcat.c \
upstream-openbsd/lib/libc/string/strcmp.c \
upstream-openbsd/lib/libc/string/strcpy.c \
upstream-openbsd/lib/libc/string/strlcat.c \
upstream-openbsd/lib/libc/string/strlcpy.c \
upstream-openbsd/lib/libc/string/strlen.c \
upstream-openbsd/lib/libc/string/strncat.c \
upstream-openbsd/lib/libc/string/strncmp.c \
upstream-openbsd/lib/libc/string/strncpy.c \
# Fortify implementations of libc functions.
libc_common_src_files_mips64 += \
@ -54,10 +55,8 @@ libc_bionic_src_files_mips64 := \
# FIXME TODO
## libc_bionic_src_files_mips64 += arch-mips64/string/memcpy.S
## libc_bionic_src_files_mips64 += arch-mips64/string/memset.S
## libc_bionic_src_files_mips64 += arch-mips64/string/mips_strlen.c
libc_bionic_src_files_mips64 += bionic/memcpy.c
libc_bionic_src_files_mips64 += bionic/memset.c
libc_bionic_src_files_mips64 += string/strlen.c
libc_crt_target_cflags_mips64 := \

View File

@ -58,15 +58,16 @@ libc_bionic_src_files_x86 += \
arch-x86/string/strncmp.S \
arch-x86/string/strcat.S \
arch-x86/string/memcmp.S \
string/memcmp16.c \
string/strcpy.c \
string/strncat.c \
string/strncpy.c \
string/strlcat.c \
string/strlcpy.c \
bionic/__memcmp16.cpp \
upstream-freebsd/lib/libc/string/wcscpy.c \
upstream-freebsd/lib/libc/string/wcscat.c \
upstream-freebsd/lib/libc/string/wmemcmp.c
upstream-freebsd/lib/libc/string/wmemcmp.c \
upstream-openbsd/lib/libc/string/strcpy.c \
upstream-openbsd/lib/libc/string/strlcat.c \
upstream-openbsd/lib/libc/string/strlcpy.c \
upstream-openbsd/lib/libc/string/strncat.c \
upstream-openbsd/lib/libc/string/strncpy.c \
endif
libc_bionic_src_files_x86 += \

View File

@ -1,6 +1,7 @@
# x86_64 specific configs
libc_common_src_files_x86_64 := \
bionic/index.cpp \
bionic/memchr.c \
bionic/memcmp.c \
bionic/memcpy.c \
@ -9,18 +10,7 @@ libc_common_src_files_x86_64 := \
bionic/memset.c \
bionic/strchr.cpp \
bionic/strnlen.c \
string/bcopy.c \
string/index.c \
string/strcat.c \
string/strcmp.c \
string/strcpy.c \
string/strlcat.c \
string/strlcpy.c \
string/strlen.c \
string/strncat.c \
string/strncmp.c \
string/strncpy.c \
string/strrchr.c \
bionic/strrchr.cpp \
upstream-freebsd/lib/libc/string/wcscat.c \
upstream-freebsd/lib/libc/string/wcschr.c \
upstream-freebsd/lib/libc/string/wcscmp.c \
@ -28,6 +18,16 @@ libc_common_src_files_x86_64 := \
upstream-freebsd/lib/libc/string/wcslen.c \
upstream-freebsd/lib/libc/string/wcsrchr.c \
upstream-freebsd/lib/libc/string/wmemcmp.c \
upstream-openbsd/lib/libc/string/bcopy.c \
upstream-openbsd/lib/libc/string/strcat.c \
upstream-openbsd/lib/libc/string/strcmp.c \
upstream-openbsd/lib/libc/string/strcpy.c \
upstream-openbsd/lib/libc/string/strlcat.c \
upstream-openbsd/lib/libc/string/strlcpy.c \
upstream-openbsd/lib/libc/string/strlen.c \
upstream-openbsd/lib/libc/string/strncat.c \
upstream-openbsd/lib/libc/string/strncmp.c \
upstream-openbsd/lib/libc/string/strncpy.c \
# Fortify implementations of libc functions.
libc_common_src_files_x86_64 += \
@ -51,8 +51,7 @@ libc_bionic_src_files_x86_64 := \
arch-x86_64/bionic/sigsetjmp.S \
arch-x86_64/bionic/syscall.S \
arch-x86_64/bionic/vfork.S \
string/memcmp16.c \
bionic/__memcmp16.cpp \
libc_crt_target_cflags_x86_64 += \
-m64 \

View File

@ -30,14 +30,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stddef.h>
/* Unoptimised version of __memcmp16 */
int __memcmp16(const unsigned short *ptr1, const unsigned short *ptr2, size_t n)
{
size_t i;
// Unoptimized version of __memcmp16.
int __memcmp16(const unsigned short *ptr1, const unsigned short *ptr2, size_t n) {
for (i = 0; i < n; i++) {
if (*ptr1 != *ptr2)
for (size_t i = 0; i < n; i++) {
if (*ptr1 != *ptr2) {
return *ptr1 - *ptr2;
}
ptr1++;
ptr2++;
}

View File

@ -1,4 +1,3 @@
/* $OpenBSD: rindex.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */
/*
* Copyright (c) 1988 Regents of the University of California.
* All rights reserved.

View File

@ -26,50 +26,33 @@
* SUCH DAMAGE.
*/
/* implement flockfile(), ftrylockfile() and funlockfile()
*
* we can't use the OpenBSD implementation which uses kernel-specific
* APIs not available on Linux.
*
* Instead, we use a pthread_mutex_t within the FILE* internal state.
* See fileext.h for details.
*
* the behaviour, if fclose() is called while the corresponding
* file is locked is totally undefined.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include "fileext.h"
// We can't use the OpenBSD implementation which uses kernel-specific
// APIs not available on Linux. Instead we use a pthread_mutex_t within
// struct __sfileext (see fileext.h).
void
flockfile(FILE * fp)
{
void flockfile(FILE* fp) {
if (fp != NULL) {
_FLOCK_LOCK(fp);
pthread_mutex_lock(&_FLOCK(fp));
}
}
int
ftrylockfile(FILE *fp)
{
/* The specification for ftrylockfile() says it returns 0 on success,
* or non-zero on error. So return an errno code directly on error.
*/
int ret = EINVAL;
if (fp != NULL) {
ret = _FLOCK_TRYLOCK(fp);
int ftrylockfile(FILE* fp) {
// The specification for ftrylockfile() says it returns 0 on success,
// or non-zero on error. So return an errno code directly on error.
if (fp == NULL) {
return EINVAL;
}
return ret;
return pthread_mutex_trylock(&_FLOCK(fp));
}
void
funlockfile(FILE * fp)
{
void funlockfile(FILE* fp) {
if (fp != NULL) {
_FLOCK_UNLOCK(fp);
pthread_mutex_unlock(&_FLOCK(fp));
}
}

View File

@ -1,4 +1,3 @@
/* $OpenBSD: index.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@ -28,16 +27,9 @@
* SUCH DAMAGE.
*/
#undef _FORTIFY_SOURCE
#include <string.h>
char *
index(const char *p, int ch)
{
for (;; ++p) {
if (*p == (char) ch)
return((char *)p);
if (!*p)
return((char *)NULL);
}
/* NOTREACHED */
char* index(const char* p, int ch) {
return __strchr_chk(p, ch, __BIONIC_FORTIFY_UNKNOWN_SIZE);
}

View File

@ -30,6 +30,6 @@
#undef _FORTIFY_SOURCE
#include <string.h>
extern "C" char* strchr(const char* p, int ch) {
char* strchr(const char* p, int ch) {
return __strchr_chk(p, ch, __BIONIC_FORTIFY_UNKNOWN_SIZE);
}

View File

@ -1,4 +1,3 @@
/* $OpenBSD: rindex.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */
/*
* Copyright (c) 1988 Regents of the University of California.
* All rights reserved.
@ -28,10 +27,9 @@
* SUCH DAMAGE.
*/
#undef _FORTIFY_SOURCE
#include <string.h>
char *
strrchr(const char *p, int ch)
{
char* strrchr(const char* p, int ch) {
return __strrchr_chk(p, ch, __BIONIC_FORTIFY_UNKNOWN_SIZE);
}

View File

@ -49,6 +49,7 @@ extern char* strchr(const char *, int) __purefunc;
extern char* __strchr_chk(const char *, int, size_t);
extern char* strrchr(const char *, int) __purefunc;
extern char* __strrchr_chk(const char *, int, size_t);
extern size_t strlen(const char *) __purefunc;
extern size_t __strlen_chk(const char *, size_t);
@ -263,8 +264,6 @@ char* strchr(const char *s, int c) {
return __strchr_chk(s, c, bos);
}
extern char* __strrchr_chk(const char *, int, size_t);
__BIONIC_FORTIFY_INLINE
char* strrchr(const char *s, int c) {
size_t bos = __bos(s);

View File

@ -147,6 +147,9 @@ extern wchar_t *wmemset(wchar_t *, wchar_t, size_t);
extern int wprintf(const wchar_t *, ...);
extern int wscanf(const wchar_t *, ...);
extern size_t wcslcat(wchar_t*, const wchar_t*, size_t);
extern size_t wcslcpy(wchar_t*, const wchar_t*, size_t);
/* No really supported. These are just for making libstdc++-v3 happy. */
typedef void *wctrans_t;
extern wint_t towctrans(wint_t, wctrans_t);

View File

@ -52,18 +52,9 @@ do { \
_UB(fp)._base = NULL; \
_UB(fp)._size = 0; \
WCIO_INIT(fp); \
_FLOCK_INIT(fp); \
_FLOCK(fp).value = __PTHREAD_RECURSIVE_MUTEX_INIT_VALUE; \
} while (0)
/* Helper macros to avoid a function call when you know that fp is not NULL.
* Notice that we keep _FLOCK_INIT() fast by slightly breaking our pthread
* encapsulation.
*/
#define _FLOCK_INIT(fp) _FLOCK(fp).value = __PTHREAD_RECURSIVE_MUTEX_INIT_VALUE
#define _FLOCK_LOCK(fp) pthread_mutex_lock(&_FLOCK(fp))
#define _FLOCK_TRYLOCK(fp) pthread_mutex_trylock(&_FLOCK(fp))
#define _FLOCK_UNLOCK(fp) pthread_mutex_unlock(&_FLOCK(fp))
#define _FILEEXT_SETUP(f, fext) \
do { \
(f)->_ext._base = (unsigned char *)(fext); \

View File

@ -1,70 +0,0 @@
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.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 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp
*/
#include <sys/cdefs.h>
#if 0
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#endif
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <wchar.h>
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns wcslen(src); if retval >= siz, truncation occurred.
*/
size_t
wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
{
wchar_t *d = dst;
const wchar_t *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
if ((*d++ = *s++) == 0)
break;
} while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}

View File

@ -1,14 +1,10 @@
/* $OpenBSD: wcsxfrm.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
/* $OpenBSD: wcsxfrm.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
/* $NetBSD: multibyte_sb.c,v 1.4 2003/08/07 16:43:04 agc Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* This code is derived from software contributed to Berkeley by
* Paul Borman at Krystal Technologies.
* Copyright (c) 1991 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
@ -18,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* 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.
*
@ -35,23 +31,12 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <wchar.h>
int
wcswidth(const wchar_t *pwcs, size_t n)
size_t
wcsxfrm(wchar_t *dest, const wchar_t *src, size_t n)
{
wchar_t wc;
int len, l;
len = 0;
while (n-- > 0 && (wc = *pwcs++) != L'\0') {
if ((l = wcwidth(wc)) < 0)
return (-1);
len += l;
}
return (len);
if (n == 0)
return wcslen(src);
return wcslcpy(dest, src, n);
}

View File

@ -29,7 +29,16 @@
* SUCH DAMAGE.
*/
#if !defined(_KERNEL) && !defined(_STANDALONE)
#include <string.h>
#else
#include <lib/libkern/libkern.h>
#endif
#if defined(APIWARN)
__warn_references(strcpy,
"warning: strcpy() is almost always misused, please use strlcpy()");
#endif
char *
strcpy(char *to, const char *from)

View File

@ -38,6 +38,7 @@
int
strncmp(const char *s1, const char *s2, size_t n)
{
if (n == 0)
return (0);
do {

View File

@ -0,0 +1,52 @@
/* $OpenBSD: wcslcpy.c,v 1.5 2011/07/24 15:21:28 millert Exp $ */
/* $NetBSD: wcslcpy.c,v 1.2 2001/01/03 14:33:02 lukem Exp $ */
/*
* Copyright (c) 1998 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 <wchar.h>
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns wcslen(src); if retval >= siz, truncation occurred.
*/
size_t
wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
{
wchar_t *d = dst;
const wchar_t *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0) {
while (--n != 0) {
if ((*d++ = *s++) == '\0')
break;
}
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}

View File

@ -1,6 +1,8 @@
/* $OpenBSD: wcswidth.c,v 1.4 2011/04/04 18:16:24 stsp Exp $ */
/* $NetBSD: wcswidth.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
/*-
* Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
* at Electronni Visti IA, Kiev, Ukraine.
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -12,10 +14,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@ -23,35 +25,26 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcswidth.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
*/
#include <wchar.h>
/*
* Placeholder wcsxfrm() implementation. See wcscoll.c for a description of
* the logic used.
*/
size_t
wcsxfrm(wchar_t * __restrict dest, const wchar_t * __restrict src, size_t len)
int
wcswidth(const wchar_t *s, size_t n)
{
int prim, sec, l;
size_t slen;
char *mbsrc, *s, *ss;
int w, q;
if (*src == L'\0') {
if (len != 0)
*dest = L'\0';
return (0);
w = 0;
while (n && *s) {
q = wcwidth(*s);
if (q == -1)
return (-1);
w += q;
s++;
n--;
}
slen = wcslen(src);
if (len > 0) {
if (slen < len)
wcscpy(dest, src);
else {
wcsncpy(dest, src, len - 1);
dest[len - 1] = L'\0';
}
}
return (slen);
return w;
}