From f0cf9ffcf8082b8453e557e8efabf3045468dfad Mon Sep 17 00:00:00 2001 From: jzlv Date: Fri, 25 Jun 2021 23:13:19 +0800 Subject: [PATCH] [refactor] replace system libc with local libc --- bsp/bsp_common/platform/syscalls.c | 290 +++++++ common/CMakeLists.txt | 10 +- common/libc/LICENSE | 62 -- common/libc/README | 8 - common/libc/inc/arm_gcc/compat_attribute.h | 27 - common/libc/inc/arm_gcc/compat_compiler.h | 5 - common/libc/inc/arm_gcc/compat_errno.h | 8 - common/libc/inc/arm_gcc/compat_param.h | 6 - common/libc/inc/arm_gcc/compat_time.h | 8 - common/libc/inc/bits/ctype_base.h | 28 - common/libc/inc/ctype.h | 140 --- common/libc/inc/extern.h | 16 - common/libc/inc/fnmatch.h | 15 - common/libc/inc/inttypes.h | 227 ----- common/libc/inc/libc_compiler.h | 109 --- common/libc/inc/limits.h | 51 -- common/libc/inc/stdarg.h | 14 - common/libc/inc/stdbool.h | 14 - common/libc/inc/stddef.h | 29 - common/libc/inc/stdint.h | 165 ---- common/libc/inc/stdio.h | 24 - common/libc/inc/stdlib.h | 62 -- common/libc/inc/string.h | 52 -- common/libc/inc/sys/types.h | 97 --- common/libc/src/atof.c | 103 --- common/libc/src/atoi.c | 7 - common/libc/src/atol.c | 7 - common/libc/src/atoll.c | 3 - common/libc/src/atox.c | 19 - common/libc/src/bsearch.c | 33 - common/libc/src/common.c | 26 - common/libc/src/ctype_isalnum.c | 6 - common/libc/src/ctype_isalpha.c | 6 - common/libc/src/ctype_isascii.c | 6 - common/libc/src/ctype_isblank.c | 6 - common/libc/src/ctype_iscntrl.c | 6 - common/libc/src/ctype_isdigit.c | 6 - common/libc/src/ctype_isgraph.c | 6 - common/libc/src/ctype_islower.c | 6 - common/libc/src/ctype_isprint.c | 6 - common/libc/src/ctype_ispunct.c | 6 - common/libc/src/ctype_isspace.c | 6 - common/libc/src/ctype_isupper.c | 6 - common/libc/src/ctype_isxdigit.c | 6 - common/libc/src/ctype_tolower.c | 6 - common/libc/src/ctype_toupper.c | 6 - common/libc/src/ctypefunc.h | 14 - common/libc/src/ctypes.c | 288 ------- common/libc/src/fnmatch.c | 97 --- common/libc/src/jrand48.c | 28 - common/libc/src/lrand48.c | 27 - common/libc/src/memccpy.c | 29 - common/libc/src/memchr.c | 25 - common/libc/src/memcmp.c | 25 - common/libc/src/memcpy.c | 18 - common/libc/src/memmem.c | 61 -- common/libc/src/memrchr.c | 25 - common/libc/src/memset.c | 19 - common/libc/src/memswap.c | 28 - common/libc/src/mrand48.c | 18 - common/libc/src/nrand48.c | 15 - common/libc/src/qsort.c | 58 -- common/libc/src/seed48.c | 22 - common/libc/src/snprintf.c | 21 - common/libc/src/sprintf.c | 22 - common/libc/src/srand48.c | 30 - common/libc/src/sscanf.c | 22 - common/libc/src/stdlib.c | 31 - common/libc/src/strcasecmp.c | 30 - common/libc/src/strcat.c | 15 - common/libc/src/strchr.c | 24 - common/libc/src/strcmp.c | 31 - common/libc/src/strcpy.c | 24 - common/libc/src/strcspn.c | 16 - common/libc/src/strlcat.c | 37 - common/libc/src/strlcpy.c | 32 - common/libc/src/strlen.c | 20 - common/libc/src/strncasecmp.c | 30 - common/libc/src/strncat.c | 28 - common/libc/src/strncmp.c | 27 - common/libc/src/strncpy.c | 30 - common/libc/src/strnlen.c | 23 - common/libc/src/strntoimax.c | 18 - common/libc/src/strntoumax.c | 83 -- common/libc/src/strpbrk.c | 18 - common/libc/src/strrchr.c | 24 - common/libc/src/strsep.c | 28 - common/libc/src/strspn.c | 16 - common/libc/src/strstr.c | 16 - common/libc/src/strtoimax.c | 7 - common/libc/src/strtok.c | 16 - common/libc/src/strtok_r.c | 18 - common/libc/src/strtol.c | 7 - common/libc/src/strtoll.c | 7 - common/libc/src/strtoul.c | 7 - common/libc/src/strtoull.c | 7 - common/libc/src/strtoumax.c | 7 - common/libc/src/strtox.c | 19 - common/libc/src/strxspn.c | 36 - common/libc/src/strxspn.h | 12 - common/libc/src/vsnprintf.c | 934 --------------------- common/libc/src/vsprintf.c | 15 - common/libc/src/vsscanf.c | 470 ----------- common/misc/misc.h | 11 +- tools/cmake/compiler_flags.cmake | 4 +- tools/cmake/tools.cmake | 33 +- 106 files changed, 324 insertions(+), 4534 deletions(-) create mode 100644 bsp/bsp_common/platform/syscalls.c delete mode 100644 common/libc/LICENSE delete mode 100644 common/libc/README delete mode 100644 common/libc/inc/arm_gcc/compat_attribute.h delete mode 100644 common/libc/inc/arm_gcc/compat_compiler.h delete mode 100644 common/libc/inc/arm_gcc/compat_errno.h delete mode 100644 common/libc/inc/arm_gcc/compat_param.h delete mode 100644 common/libc/inc/arm_gcc/compat_time.h delete mode 100644 common/libc/inc/bits/ctype_base.h delete mode 100644 common/libc/inc/ctype.h delete mode 100644 common/libc/inc/extern.h delete mode 100644 common/libc/inc/fnmatch.h delete mode 100644 common/libc/inc/inttypes.h delete mode 100644 common/libc/inc/libc_compiler.h delete mode 100644 common/libc/inc/limits.h delete mode 100644 common/libc/inc/stdarg.h delete mode 100644 common/libc/inc/stdbool.h delete mode 100644 common/libc/inc/stddef.h delete mode 100644 common/libc/inc/stdint.h delete mode 100644 common/libc/inc/stdio.h delete mode 100644 common/libc/inc/stdlib.h delete mode 100644 common/libc/inc/string.h delete mode 100644 common/libc/inc/sys/types.h delete mode 100644 common/libc/src/atof.c delete mode 100644 common/libc/src/atoi.c delete mode 100644 common/libc/src/atol.c delete mode 100644 common/libc/src/atoll.c delete mode 100644 common/libc/src/atox.c delete mode 100644 common/libc/src/bsearch.c delete mode 100644 common/libc/src/common.c delete mode 100644 common/libc/src/ctype_isalnum.c delete mode 100644 common/libc/src/ctype_isalpha.c delete mode 100644 common/libc/src/ctype_isascii.c delete mode 100644 common/libc/src/ctype_isblank.c delete mode 100644 common/libc/src/ctype_iscntrl.c delete mode 100644 common/libc/src/ctype_isdigit.c delete mode 100644 common/libc/src/ctype_isgraph.c delete mode 100644 common/libc/src/ctype_islower.c delete mode 100644 common/libc/src/ctype_isprint.c delete mode 100644 common/libc/src/ctype_ispunct.c delete mode 100644 common/libc/src/ctype_isspace.c delete mode 100644 common/libc/src/ctype_isupper.c delete mode 100644 common/libc/src/ctype_isxdigit.c delete mode 100644 common/libc/src/ctype_tolower.c delete mode 100644 common/libc/src/ctype_toupper.c delete mode 100644 common/libc/src/ctypefunc.h delete mode 100644 common/libc/src/ctypes.c delete mode 100644 common/libc/src/fnmatch.c delete mode 100644 common/libc/src/jrand48.c delete mode 100644 common/libc/src/lrand48.c delete mode 100644 common/libc/src/memccpy.c delete mode 100644 common/libc/src/memchr.c delete mode 100644 common/libc/src/memcmp.c delete mode 100644 common/libc/src/memcpy.c delete mode 100644 common/libc/src/memmem.c delete mode 100644 common/libc/src/memrchr.c delete mode 100644 common/libc/src/memset.c delete mode 100644 common/libc/src/memswap.c delete mode 100644 common/libc/src/mrand48.c delete mode 100644 common/libc/src/nrand48.c delete mode 100644 common/libc/src/qsort.c delete mode 100644 common/libc/src/seed48.c delete mode 100644 common/libc/src/snprintf.c delete mode 100644 common/libc/src/sprintf.c delete mode 100644 common/libc/src/srand48.c delete mode 100644 common/libc/src/sscanf.c delete mode 100644 common/libc/src/stdlib.c delete mode 100644 common/libc/src/strcasecmp.c delete mode 100644 common/libc/src/strcat.c delete mode 100644 common/libc/src/strchr.c delete mode 100644 common/libc/src/strcmp.c delete mode 100644 common/libc/src/strcpy.c delete mode 100644 common/libc/src/strcspn.c delete mode 100644 common/libc/src/strlcat.c delete mode 100644 common/libc/src/strlcpy.c delete mode 100644 common/libc/src/strlen.c delete mode 100644 common/libc/src/strncasecmp.c delete mode 100644 common/libc/src/strncat.c delete mode 100644 common/libc/src/strncmp.c delete mode 100644 common/libc/src/strncpy.c delete mode 100644 common/libc/src/strnlen.c delete mode 100644 common/libc/src/strntoimax.c delete mode 100644 common/libc/src/strntoumax.c delete mode 100644 common/libc/src/strpbrk.c delete mode 100644 common/libc/src/strrchr.c delete mode 100644 common/libc/src/strsep.c delete mode 100644 common/libc/src/strspn.c delete mode 100644 common/libc/src/strstr.c delete mode 100644 common/libc/src/strtoimax.c delete mode 100644 common/libc/src/strtok.c delete mode 100644 common/libc/src/strtok_r.c delete mode 100644 common/libc/src/strtol.c delete mode 100644 common/libc/src/strtoll.c delete mode 100644 common/libc/src/strtoul.c delete mode 100644 common/libc/src/strtoull.c delete mode 100644 common/libc/src/strtoumax.c delete mode 100644 common/libc/src/strtox.c delete mode 100644 common/libc/src/strxspn.c delete mode 100644 common/libc/src/strxspn.h delete mode 100644 common/libc/src/vsnprintf.c delete mode 100644 common/libc/src/vsprintf.c delete mode 100644 common/libc/src/vsscanf.c diff --git a/bsp/bsp_common/platform/syscalls.c b/bsp/bsp_common/platform/syscalls.c new file mode 100644 index 00000000..fbaf7718 --- /dev/null +++ b/bsp/bsp_common/platform/syscalls.c @@ -0,0 +1,290 @@ +#include +#include +#include +#include "drv_mmheap.h" +#include "drv_device.h" + +#ifdef CONF_VFS_ENABLE +#include +#endif + +/* Reentrant versions of system calls. */ + +/* global errno in RT-Thread */ +static volatile int _sys_errno = 0; + +#ifndef _REENT_ONLY +int *__errno() +{ + // #if (configUSE_POSIX_ERRNO == 1) + // { + // extern int FreeRTOS_errno; + + // return &FreeRTOS_errno; + // } + // #endif + return (int *)&_sys_errno; +} +#endif + +int _getpid_r(struct _reent *ptr) +{ + return 0; +} + +int _execve_r(struct _reent *ptr, const char *name, char *const *argv, char *const *env) +{ + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +} + +int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg) +{ + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +} + +int _fork_r(struct _reent *ptr) +{ + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +} + +int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat) +{ + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +} + +int _isatty_r(struct _reent *ptr, int fd) +{ + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +} + +int _kill_r(struct _reent *ptr, int pid, int sig) +{ + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +} + +int _link_r(struct _reent *ptr, const char *old, const char *new) +{ + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +} + +_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) +{ +#ifndef CONF_VFS_ENABLE + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +#else + _off_t rc; + + rc = aos_lseek(fd, pos, whence); + return rc; +#endif +} + +int _mkdir_r(struct _reent *ptr, const char *name, int mode) +{ +#ifndef CONF_VFS_ENABLE + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +#else + int rc; + + rc = aos_mkdir(name); + return rc; +#endif +} + +int _open_r(struct _reent *ptr, const char *file, int flags, int mode) +{ +#ifndef CONF_VFS_ENABLE + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +#else + int rc; + + rc = aos_open(file, flags); + return rc; +#endif +} + +int _close_r(struct _reent *ptr, int fd) +{ +#ifndef CONF_VFS_ENABLE + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +#else + return aos_close(fd); +#endif +} + +_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) +{ +#ifndef CONF_VFS_ENABLE + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +#else + _ssize_t rc; + + rc = aos_read(fd, buf, nbytes); + return rc; +#endif +} + +int _rename_r(struct _reent *ptr, const char *old, const char *new) +{ +#ifndef CONF_VFS_ENABLE + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +#else + int rc; + + rc = aos_rename(old, new); + return rc; +#endif +} + +int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) +{ +#ifndef CONF_VFS_ENABLE + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +#else + int rc; + + rc = aos_stat(file, pstat); + return rc; +#endif +} + +int _unlink_r(struct _reent *ptr, const char *file) +{ +#ifndef CONF_VFS_ENABLE + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +#else + return aos_unlink(file); +#endif +} + +int _wait_r(struct _reent *ptr, int *status) +{ + /* return "not supported" */ + ptr->_errno = -ENOSYS; + return -1; +} + +_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) +{ +#ifndef CONF_VFS_ENABLE + struct device *uart = device_find("debug_log"); + if ((STDOUT_FILENO == fd) || (STDERR_FILENO == fd)) { + device_write(uart, 0, (uint8_t *)buf, nbytes); + } + return 0; +#else + _ssize_t rc; + + rc = aos_write(fd, buf, nbytes); + return rc; +#endif +} + +void *_malloc_r(struct _reent *ptr, size_t size) +{ + void *result; + + result = (void *)mmheap_alloc(size); + if (result == NULL) { + ptr->_errno = -ENOMEM; + } + + return result; +} + +void *_realloc_r(struct _reent *ptr, void *old, size_t newlen) +{ + void *result; + + result = (void *)mmheap_realloc(old, newlen); + if (result == NULL) { + ptr->_errno = -ENOMEM; + } + + return result; +} + +void *_calloc_r(struct _reent *ptr, size_t size, size_t len) +{ + void *result; + + result = (void *)mmheap_calloc(size, len); + if (result == NULL) { + ptr->_errno = -ENOMEM; + } + + return result; +} + +void _free_r(struct _reent *ptr, void *addr) +{ + mmheap_free(addr); +} + +void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr) +{ + return 0; +} + +/* for exit() and abort() */ +void __attribute__((noreturn)) +_exit(int status) +{ + while (1) { + } +} + +void _system(const char *s) +{ +} + +void __libc_init_array(void) +{ + /* we not use __libc init_aray to initialize C++ objects */ +} + +mode_t umask(mode_t mask) +{ + return 022; +} + +int flock(int fd, int operation) +{ + return 0; +} + +/* +These functions are implemented and replaced by the 'common/time.c' file +int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); +_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms); +*/ diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 8218406b..b6889ee9 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,12 +1,12 @@ ################# Add global include ################# list(APPEND ADD_INCLUDE -"${CMAKE_CURRENT_SOURCE_DIR}/libc/inc" +# "${CMAKE_CURRENT_SOURCE_DIR}/libc/inc" "${CMAKE_CURRENT_SOURCE_DIR}/ring_buffer" "${CMAKE_CURRENT_SOURCE_DIR}/soft_crc" "${CMAKE_CURRENT_SOURCE_DIR}/memheap" -"${CMAKE_CURRENT_SOURCE_DIR}/libc/inc/arm_gcc" -"${CMAKE_CURRENT_SOURCE_DIR}/libc/inc/bits" -"${CMAKE_CURRENT_SOURCE_DIR}/libc/inc/sys" +# "${CMAKE_CURRENT_SOURCE_DIR}/libc/inc/arm_gcc" +# "${CMAKE_CURRENT_SOURCE_DIR}/libc/inc/bits" +# "${CMAKE_CURRENT_SOURCE_DIR}/libc/inc/sys" "${CMAKE_CURRENT_SOURCE_DIR}/misc" "${CMAKE_CURRENT_SOURCE_DIR}/list" "${CMAKE_CURRENT_SOURCE_DIR}/device" @@ -21,7 +21,7 @@ list(APPEND ADD_INCLUDE ############## Add current dir source files ########### file(GLOB_RECURSE sources -"${CMAKE_CURRENT_SOURCE_DIR}/libc/src/*.c" +# "${CMAKE_CURRENT_SOURCE_DIR}/libc/src/*.c" "${CMAKE_CURRENT_SOURCE_DIR}/ring_buffer/*.c" "${CMAKE_CURRENT_SOURCE_DIR}/soft_crc/*.c" "${CMAKE_CURRENT_SOURCE_DIR}/memheap/*.c" diff --git a/common/libc/LICENSE b/common/libc/LICENSE deleted file mode 100644 index 79a98597..00000000 --- a/common/libc/LICENSE +++ /dev/null @@ -1,62 +0,0 @@ -Some files are derived from files copyrighted by the Regents of The -University of California, and are available under the following -license: - -Note: The advertising clause in the license appearing on BSD Unix -files was officially rescinded by the Director of the Office of -Technology Licensing of the University of California on July 22 -1999. He states that clause 3 is "hereby deleted in its entirety." - - * Copyright (c) - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - - ----- - -For all remaining files, the following license applies: - - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * Any copyright notice(s) and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/common/libc/README b/common/libc/README deleted file mode 100644 index de1c3db6..00000000 --- a/common/libc/README +++ /dev/null @@ -1,8 +0,0 @@ -This is a subset of klibc (http://www.kernel.org/pub/linux/libs/klibc/) -which is itself a subset of standard C library functions. - -The provided functions are those which can be safely used in the SDK -environment. - -The included code was extracted from klibc version 1.5.15 without any -of the GPL licensed parts. See the LICENSE file for details. diff --git a/common/libc/inc/arm_gcc/compat_attribute.h b/common/libc/inc/arm_gcc/compat_attribute.h deleted file mode 100644 index 90ac3505..00000000 --- a/common/libc/inc/arm_gcc/compat_attribute.h +++ /dev/null @@ -1,27 +0,0 @@ - - -#ifndef _COMPAT_ATTRIBUTE_H_ -#define _COMPAT_ATTRIBUTE_H_ - -#define __DEPRECATED__(x) __attribute__((deprecated(x))) -#define __PACKED__ __attribute__((packed)) - -#define __PACKED_START__ -#define __PACKED_END__ __PACKED__ - -#define __UNUSED__ __attribute__((unused)) -#define __MAY_ALIAS__ __attribute__((may_alias)) - -#define __ALIGNED__(y) __attribute__((aligned(y))) -#define __SECTION__(y) __attribute__((section(#y))) - -#define __FORCED_INLINE__ inline __attribute__((always_inline)) -#define __NOINLINE__ __attribute__((noinline)) - -#define __WEAK__ __attribute__((weak)) -#define __INTERRUPT__ __attribute__((interrupt)) -#define __USED__ __attribute__((used)) -#define __NAKED__ __attribute__((naked)) - -#define __VISIBILITY__ __attribute__((visibility("default"))) -#endif /* _COMPAT_ATTRIBUTE_H_ */ diff --git a/common/libc/inc/arm_gcc/compat_compiler.h b/common/libc/inc/arm_gcc/compat_compiler.h deleted file mode 100644 index f6ab4a33..00000000 --- a/common/libc/inc/arm_gcc/compat_compiler.h +++ /dev/null @@ -1,5 +0,0 @@ - - -#ifndef _COMPAT_COMPILER_H_ -#define _COMPAT_COMPILER_H_ -#endif /* _COMPAT_COMPILER_H_ */ diff --git a/common/libc/inc/arm_gcc/compat_errno.h b/common/libc/inc/arm_gcc/compat_errno.h deleted file mode 100644 index 5b109a1c..00000000 --- a/common/libc/inc/arm_gcc/compat_errno.h +++ /dev/null @@ -1,8 +0,0 @@ - - -#ifndef _COMPAT_ERRNO_H_ -#define _COMPAT_ERRNO_H_ - -#include - -#endif /* _COMPAT_ERRNO_H_ */ diff --git a/common/libc/inc/arm_gcc/compat_param.h b/common/libc/inc/arm_gcc/compat_param.h deleted file mode 100644 index 77289c24..00000000 --- a/common/libc/inc/arm_gcc/compat_param.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _COMPAT_PARAM_H -#define _COMPAT_PARAM_H - -#include /* need this to define BSD */ - -#endif /* _COMPAT_PARAM_H */ diff --git a/common/libc/inc/arm_gcc/compat_time.h b/common/libc/inc/arm_gcc/compat_time.h deleted file mode 100644 index 75c4a2db..00000000 --- a/common/libc/inc/arm_gcc/compat_time.h +++ /dev/null @@ -1,8 +0,0 @@ - - -#ifndef _COMPAT_TIME_H_ -#define _COMPAT_TIME_H_ - -#include - -#endif /* _COMPAT_TIME_H_ */ diff --git a/common/libc/inc/bits/ctype_base.h b/common/libc/inc/bits/ctype_base.h deleted file mode 100644 index 4b851462..00000000 --- a/common/libc/inc/bits/ctype_base.h +++ /dev/null @@ -1,28 +0,0 @@ - -namespace std _GLIBCXX_VISIBILITY(default) -{ - _GLIBCXX_BEGIN_NAMESPACE_VERSION - - /// @brief Base class for ctype. - struct ctype_base { - // Non-standard typedefs. - typedef const int *__to_type; - - // NB: Offsets into ctype::_M_table force a particular size - // on the mask type. Because of this, we don't use an enum. - typedef char mask; - static const mask upper = _U; - static const mask lower = _L; - static const mask alpha = _U | _L; - static const mask digit = _N; - static const mask xdigit = _X | _N; - static const mask space = _S; - static const mask print = _P | _U | _L | _N | _B; - static const mask graph = _P | _U | _L | _N; - static const mask cntrl = _C; - static const mask punct = _P; - static const mask alnum = _U | _L | _N; - }; - - _GLIBCXX_END_NAMESPACE_VERSION -} // namespace ) diff --git a/common/libc/inc/ctype.h b/common/libc/inc/ctype.h deleted file mode 100644 index 81ee4bcf..00000000 --- a/common/libc/inc/ctype.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * ctype.h - * - * This assumes ISO 8859-1, being a reasonable superset of ASCII. - */ - -#ifndef _CTYPE_H -#define _CTYPE_H - -#include -#include - -#define _U (1 << 0) -#define _L (1 << 1) -#define _N (1 << 2) -#define _S (1 << 3) -#define _P (1 << 4) -#define _C (1 << 5) -#define _X (1 << 6) -#define _B (1 << 7) - -/* - * This relies on the following definitions: - * - * cntrl = !print - * alpha = upper|lower - * graph = punct|alpha|digit - * blank = '\t' || ' ' (per POSIX requirement) - */ -enum { - __ctype_upper = _U, - __ctype_lower = _L, - __ctype_digit = _N, - __ctype_xdigit = _S, - __ctype_space = _P, - __ctype_print = _C, - __ctype_punct = _X, - __ctype_cntrl = _B -}; - -__extern int isalnum(int); -__extern int isalpha(int); -__extern int isascii(int); -__extern int isblank(int); -__extern int iscntrl(int); -__extern int isdigit(int); -__extern int isgraph(int); -__extern int islower(int); -__extern int isprint(int); -__extern int ispunct(int); -__extern int isspace(int); -__extern int isupper(int); -__extern int isxdigit(int); -__extern int toupper(int); -__extern int tolower(int); - -extern const unsigned char __ctypes[]; - -__must_inline int __ctype_isalnum(int __c) -{ - return __ctypes[__c + 1] & - (__ctype_upper | __ctype_lower | __ctype_digit); -} - -__must_inline int __ctype_isalpha(int __c) -{ - return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower); -} - -__must_inline int __ctype_isascii(int __c) -{ - return !(__c & ~0x7f); -} - -__must_inline int __ctype_isblank(int __c) -{ - return (__c == '\t') || (__c == ' '); -} - -__must_inline int __ctype_iscntrl(int __c) -{ - return __ctypes[__c + 1] & __ctype_cntrl; -} - -__must_inline int __ctype_isdigit(int __c) -{ - return ((unsigned)__c - '0') <= 9; -} - -__must_inline int __ctype_isgraph(int __c) -{ - return __ctypes[__c + 1] & - (__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct); -} - -__must_inline int __ctype_islower(int __c) -{ - return __ctypes[__c + 1] & __ctype_lower; -} - -__must_inline int __ctype_isprint(int __c) -{ - return __ctypes[__c + 1] & __ctype_print; -} - -__must_inline int __ctype_ispunct(int __c) -{ - return __ctypes[__c + 1] & __ctype_punct; -} - -__must_inline int __ctype_isspace(int __c) -{ - return __ctypes[__c + 1] & __ctype_space; -} - -__must_inline int __ctype_isupper(int __c) -{ - return __ctypes[__c + 1] & __ctype_upper; -} - -__must_inline int __ctype_isxdigit(int __c) -{ - return __ctypes[__c + 1] & __ctype_xdigit; -} - -/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */ -#define _toupper(__c) ((__c) & ~32) -#define _tolower(__c) ((__c) | 32) - -__must_inline int __ctype_toupper(int __c) -{ - return __ctype_islower(__c) ? _toupper(__c) : __c; -} - -__must_inline int __ctype_tolower(int __c) -{ - return __ctype_isupper(__c) ? _tolower(__c) : __c; -} - -#endif /* _CTYPE_H */ diff --git a/common/libc/inc/extern.h b/common/libc/inc/extern.h deleted file mode 100644 index 426d966b..00000000 --- a/common/libc/inc/extern.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * klibc/extern.h - */ - -#ifndef _EXTERN_H -#define _EXTERN_H - -#ifdef __cplusplus -#define __extern extern "C" -#else -#define __extern extern -#endif - -#define __alias(x) __attribute__((weak, alias(x))) - -#endif /* _EXTERN_H */ diff --git a/common/libc/inc/fnmatch.h b/common/libc/inc/fnmatch.h deleted file mode 100644 index e7191809..00000000 --- a/common/libc/inc/fnmatch.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _FNMATCH_H -#define _FNMATCH_H - -#include - -#define FNM_NOMATCH 1 - -#define FNM_PATHNAME 1 -#define FNM_FILE_NAME FNM_PATHNAME -#define FNM_NOESCAPE 2 -#define FNM_PERIOD 4 - -__extern int fnmatch(const char *, const char *, int); - -#endif /* _FNMATCH_H */ diff --git a/common/libc/inc/inttypes.h b/common/libc/inc/inttypes.h deleted file mode 100644 index 50fbcce2..00000000 --- a/common/libc/inc/inttypes.h +++ /dev/null @@ -1,227 +0,0 @@ -/* - * inttypes.h - */ - -#ifndef _INTTYPES_H -#define _INTTYPES_H - -#include -#include -#include -#include - -static __inline intmax_t imaxabs(intmax_t __n) -{ - return (__n < (intmax_t)0) ? -__n : __n; -} - -__extern intmax_t strtoimax(const char *, char **, int); -__extern uintmax_t strtoumax(const char *, char **, int); - -/* extensions */ -__extern intmax_t strntoimax(const char *, char **, int, size_t); -__extern uintmax_t strntoumax(const char *, char **, int, size_t); - -#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) - -#define PRId8 "d" -#define PRId16 "d" -#define PRId32 "d" -#define PRId64 __PRI64_RANK "d" - -#define PRIdLEAST8 "d" -#define PRIdLEAST16 "d" -#define PRIdLEAST32 "d" -#define PRIdLEAST64 __PRI64_RANK "d" - -#define PRIdFAST8 "d" -#define PRIdFAST16 __PRIFAST_RANK "d" -#define PRIdFAST32 __PRIFAST_RANK "d" -#define PRIdFAST64 __PRI64_RANK "d" - -#define PRIdMAX __PRI64_RANK "d" -#define PRIdPTR __PRIPTR_RANK "d" - -#define PRIi8 "i" -#define PRIi16 "i" -#define PRIi32 "i" -#define PRIi64 __PRI64_RANK "i" - -#define PRIiLEAST8 "i" -#define PRIiLEAST16 "i" -#define PRIiLEAST32 "i" -#define PRIiLEAST64 __PRI64_RANK "i" - -#define PRIiFAST8 "i" -#define PRIiFAST16 __PRIFAST_RANK "i" -#define PRIiFAST32 __PRIFAST_RANK "i" -#define PRIiFAST64 __PRI64_RANK "i" - -#define PRIiMAX __PRI64_RANK "i" -#define PRIiPTR __PRIPTR_RANK "i" - -#define PRIo8 "o" -#define PRIo16 "o" -#define PRIo32 "o" -#define PRIo64 __PRI64_RANK "o" - -#define PRIoLEAST8 "o" -#define PRIoLEAST16 "o" -#define PRIoLEAST32 "o" -#define PRIoLEAST64 __PRI64_RANK "o" - -#define PRIoFAST8 "o" -#define PRIoFAST16 __PRIFAST_RANK "o" -#define PRIoFAST32 __PRIFAST_RANK "o" -#define PRIoFAST64 __PRI64_RANK "o" - -#define PRIoMAX __PRI64_RANK "o" -#define PRIoPTR __PRIPTR_RANK "o" - -#define PRIu8 "u" -#define PRIu16 "u" -#define PRIu32 "u" -#define PRIu64 __PRI64_RANK "u" - -#define PRIuLEAST8 "u" -#define PRIuLEAST16 "u" -#define PRIuLEAST32 "u" -#define PRIuLEAST64 __PRI64_RANK "u" - -#define PRIuFAST8 "u" -#define PRIuFAST16 __PRIFAST_RANK "u" -#define PRIuFAST32 __PRIFAST_RANK "u" -#define PRIuFAST64 __PRI64_RANK "u" - -#define PRIuMAX __PRI64_RANK "u" -#define PRIuPTR __PRIPTR_RANK "u" - -#define PRIx8 "x" -#define PRIx16 "x" -#define PRIx32 "x" -#define PRIx64 __PRI64_RANK "x" - -#define PRIxLEAST8 "x" -#define PRIxLEAST16 "x" -#define PRIxLEAST32 "x" -#define PRIxLEAST64 __PRI64_RANK "x" - -#define PRIxFAST8 "x" -#define PRIxFAST16 __PRIFAST_RANK "x" -#define PRIxFAST32 __PRIFAST_RANK "x" -#define PRIxFAST64 __PRI64_RANK "x" - -#define PRIxMAX __PRI64_RANK "x" -#define PRIxPTR __PRIPTR_RANK "x" - -#define PRIX8 "X" -#define PRIX16 "X" -#define PRIX32 "X" -#define PRIX64 __PRI64_RANK "X" - -#define PRIXLEAST8 "X" -#define PRIXLEAST16 "X" -#define PRIXLEAST32 "X" -#define PRIXLEAST64 __PRI64_RANK "X" - -#define PRIXFAST8 "X" -#define PRIXFAST16 __PRIFAST_RANK "X" -#define PRIXFAST32 __PRIFAST_RANK "X" -#define PRIXFAST64 __PRI64_RANK "X" - -#define PRIXMAX __PRI64_RANK "X" -#define PRIXPTR __PRIPTR_RANK "X" - -#define SCNd8 "hhd" -#define SCNd16 "hd" -#define SCNd32 "d" -#define SCNd64 __PRI64_RANK "d" - -#define SCNdLEAST8 "hhd" -#define SCNdLEAST16 "hd" -#define SCNdLEAST32 "d" -#define SCNdLEAST64 __PRI64_RANK "d" - -#define SCNdFAST8 "hhd" -#define SCNdFAST16 __PRIFAST_RANK "d" -#define SCNdFAST32 __PRIFAST_RANK "d" -#define SCNdFAST64 __PRI64_RANK "d" - -#define SCNdMAX __PRI64_RANK "d" -#define SCNdPTR __PRIPTR_RANK "d" - -#define SCNi8 "hhi" -#define SCNi16 "hi" -#define SCNi32 "i" -#define SCNi64 __PRI64_RANK "i" - -#define SCNiLEAST8 "hhi" -#define SCNiLEAST16 "hi" -#define SCNiLEAST32 "i" -#define SCNiLEAST64 __PRI64_RANK "i" - -#define SCNiFAST8 "hhi" -#define SCNiFAST16 __PRIFAST_RANK "i" -#define SCNiFAST32 __PRIFAST_RANK "i" -#define SCNiFAST64 __PRI64_RANK "i" - -#define SCNiMAX __PRI64_RANK "i" -#define SCNiPTR __PRIPTR_RANK "i" - -#define SCNo8 "hho" -#define SCNo16 "ho" -#define SCNo32 "o" -#define SCNo64 __PRI64_RANK "o" - -#define SCNoLEAST8 "hho" -#define SCNoLEAST16 "ho" -#define SCNoLEAST32 "o" -#define SCNoLEAST64 __PRI64_RANK "o" - -#define SCNoFAST8 "hho" -#define SCNoFAST16 __PRIFAST_RANK "o" -#define SCNoFAST32 __PRIFAST_RANK "o" -#define SCNoFAST64 __PRI64_RANK "o" - -#define SCNoMAX __PRI64_RANK "o" -#define SCNoPTR __PRIPTR_RANK "o" - -#define SCNu8 "hhu" -#define SCNu16 "hu" -#define SCNu32 "u" -#define SCNu64 __PRI64_RANK "u" - -#define SCNuLEAST8 "hhu" -#define SCNuLEAST16 "hu" -#define SCNuLEAST32 "u" -#define SCNuLEAST64 __PRI64_RANK "u" - -#define SCNuFAST8 "hhu" -#define SCNuFAST16 __PRIFAST_RANK "u" -#define SCNuFAST32 __PRIFAST_RANK "u" -#define SCNuFAST64 __PRI64_RANK "u" - -#define SCNuMAX __PRI64_RANK "u" -#define SCNuPTR __PRIPTR_RANK "u" - -#define SCNx8 "hhx" -#define SCNx16 "hx" -#define SCNx32 "x" -#define SCNx64 __PRI64_RANK "x" - -#define SCNxLEAST8 "hhx" -#define SCNxLEAST16 "hx" -#define SCNxLEAST32 "x" -#define SCNxLEAST64 __PRI64_RANK "x" - -#define SCNxFAST8 "hhx" -#define SCNxFAST16 __PRIFAST_RANK "x" -#define SCNxFAST32 __PRIFAST_RANK "x" -#define SCNxFAST64 __PRI64_RANK "x" - -#define SCNxMAX __PRI64_RANK "x" -#define SCNxPTR __PRIPTR_RANK "x" - -#endif - -#endif /* _INTTYPES_H */ diff --git a/common/libc/inc/libc_compiler.h b/common/libc/inc/libc_compiler.h deleted file mode 100644 index c12274c4..00000000 --- a/common/libc/inc/libc_compiler.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * libc compiler.h - * - * Various compiler features - */ - -#ifndef _LIBC_COMPILER_H -#define _LIBC_COMPILER_H - -/* Specific calling conventions */ -/* __cdecl is used when we want varadic and non-varadic functions to have - the same binary calling convention. */ -#ifdef __i386__ -#ifdef __GNUC__ -#define __cdecl __attribute__((cdecl, regparm(0))) -#else -/* Most other C compilers have __cdecl as a keyword */ -#endif -#else -#define __cdecl /* Meaningless on non-i386 */ -#endif - -/* How to declare a function that *must* be inlined */ -/* Use "extern inline" even in the gcc3+ case to avoid warnings in ctype.h */ -#ifdef __GNUC__ -#if __GNUC__ >= 3 -#ifdef __GNUC_STDC_INLINE__ -#define __must_inline extern __inline__ \ - __attribute__((__gnu_inline__, __always_inline__)) -#else -#define __must_inline extern __inline__ __attribute__((__always_inline__)) -#endif -#else -#define __must_inline extern __inline__ -#endif -#else -#define __must_inline __inline /* Just hope this works... */ -#define __inline inline -#endif - -/* How to declare a function that does not return */ -#ifdef __GNUC__ -#define __noreturn void __attribute__((noreturn)) -#else -#define __noreturn void -#endif - -/* "const" function: - - Many functions do not examine any values except their arguments, - and have no effects except the return value. Basically this is - just slightly more strict class than the `pure' attribute above, - since function is not allowed to read global memory. - - Note that a function that has pointer arguments and examines the - data pointed to must _not_ be declared `const'. Likewise, a - function that calls a non-`const' function usually must not be - `const'. It does not make sense for a `const' function to return - `void'. -*/ -#ifdef __GNUC__ -#define __constfunc __attribute__((const)) -#else -#define __constfunc -#endif -#undef __attribute_const__ -#define __attribute_const__ __constfunc - -/* "pure" function: - - Many functions have no effects except the return value and their - return value depends only on the parameters and/or global - variables. Such a function can be subject to common subexpression - elimination and loop optimization just as an arithmetic operator - would be. These functions should be declared with the attribute - `pure'. -*/ -#ifdef __GNUC__ -#define __purefunc __attribute__((pure)) -#else -#define __purefunc -#endif -#undef __attribute_pure__ -#define __attribute_pure__ __purefunc - -/* Format attribute */ -#ifdef __GNUC__ -#define __formatfunc(t, f, a) __attribute__((format(t, f, a))) -#else -#define __formatfunc(t, f, a) -#endif - -/* malloc() function (returns unaliased pointer) */ -#if defined(__GNUC__) && (__GNUC__ >= 3) -#define __mallocfunc __attribute__((malloc)) -#else -#define __mallocfunc -#endif - -/* likely/unlikely */ -#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)) -#define __likely(x) __builtin_expect(!!(x), 1) -#define __unlikely(x) __builtin_expect(!!(x), 0) -#else -#define __likely(x) (!!(x)) -#define __unlikely(x) (!!(x)) -#endif - -#endif diff --git a/common/libc/inc/limits.h b/common/libc/inc/limits.h deleted file mode 100644 index 7118e8a6..00000000 --- a/common/libc/inc/limits.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * limits.h - */ - -#ifndef _LIMITS_H -#define _LIMITS_H - -#define CHAR_BIT 8 -#define SHRT_BIT 16 -#define INT_BIT 32 -#define LONGLONG_BIT 64 - -#define SCHAR_MIN (-128) -#define SCHAR_MAX 127 -#define UCHAR_MAX 255 - -#ifdef __CHAR_UNSIGNED__ -#define CHAR_MIN 0 -#define CHAR_MAX UCHAR_MAX -#else -#define CHAR_MIN SCHAR_MIN -#define CHAR_MAX SCHAR_MAX -#endif - -#define SHRT_MIN (-32768) -#define SHRT_MAX 32767 -#define USHRT_MAX 65535 - -#define INT_MIN (-2147483647 - 1) -#define INT_MAX 2147483647 -#define UINT_MAX 4294967295U - -#if __riscv_xlen == 64 -#define LONG_BIT 64 - -#define LONG_MIN (-9223372036854775807LL - 1) -#define LONG_MAX 9223372036854775807LL -#define ULONG_MAX 18446744073709551615ULL -#else -#define LONG_BIT 32 - -#define LONG_MIN (-2147483647L - 1) -#define LONG_MAX 2147483647L -#define ULONG_MAX 4294967295UL -#endif - -#define LONGLONG_MIN (-9223372036854775807LL - 1) -#define LONGLONG_MAX 9223372036854775807LL -#define ULONGLONG_MAX 18446744073709551615ULL - -#endif /* _LIMITS_H */ diff --git a/common/libc/inc/stdarg.h b/common/libc/inc/stdarg.h deleted file mode 100644 index 76352d94..00000000 --- a/common/libc/inc/stdarg.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * stdarg.h - * - * This is just a wrapper for the gcc one, but defines va_copy() - * even if gcc doesn't. - */ - -/* Note: the _STDARG_H macro belongs to the gcc header... */ -#include_next - -/* Older gcc considers this an extension, so it's double underbar only */ -#ifndef va_copy -#define va_copy(d, s) __va_copy(d, s) -#endif diff --git a/common/libc/inc/stdbool.h b/common/libc/inc/stdbool.h deleted file mode 100644 index 14a4008f..00000000 --- a/common/libc/inc/stdbool.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * stdbool.h - */ - -#ifndef _STDBOOL_H -#define _STDBOOL_H - -#ifndef __cplusplus -#define bool _Bool -#define true 1 -#define false 0 -#endif - -#endif /* _STDBOOL_H */ diff --git a/common/libc/inc/stddef.h b/common/libc/inc/stddef.h deleted file mode 100644 index 951d80a7..00000000 --- a/common/libc/inc/stddef.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * stddef.h - */ - -#ifndef _STDDEF_H -#define _STDDEF_H - -#define _SIZE_T -typedef unsigned long size_t; - -#define _PTRDIFF_T -typedef signed int ptrdiff_t; - -#ifndef __ICCARM__ -#define _WINT_T -typedef signed int wint_t; -#endif - -#undef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif - -#undef offsetof -#define offsetof(t, m) ((size_t) & ((t *)0)->m) - -#endif /* _STDDEF_H */ diff --git a/common/libc/inc/stdint.h b/common/libc/inc/stdint.h deleted file mode 100644 index 3763ede3..00000000 --- a/common/libc/inc/stdint.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - * stdint.h - */ - -#ifndef _STDINT_H -#define _STDINT_H - -typedef signed char int8_t; -typedef short int int16_t; -typedef int int32_t; -typedef long long int int64_t; - -typedef unsigned char uint8_t; -typedef unsigned short int uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long int uint64_t; - -typedef int int_fast16_t; -typedef int int_fast32_t; - -typedef unsigned int uint_fast16_t; -typedef unsigned int uint_fast32_t; - -#if __riscv_xlen == 32 -typedef int intptr_t; -typedef unsigned int uintptr_t; - -#undef __INT64_C -#define __INT64_C(c) c##LL -#undef __UINT64_C -#define __UINT64_C(c) c##ULL -#elif __riscv_xlen == 64 -typedef long long intptr_t; -typedef unsigned long long uintptr_t; -#else -#error "unsupported __riscv_xlen" -#endif - -#define __PRI64_RANK "ll" -#define __PRIFAST_RANK "" -#define __PRIPTR_RANK "" -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; - -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -typedef int8_t int_fast8_t; -typedef int64_t int_fast64_t; - -typedef uint8_t uint_fast8_t; -typedef uint64_t uint_fast64_t; - -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; - -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) - -#define INT8_MIN (-128) -#define INT16_MIN (-32768) -#define INT32_MIN (-2147483647 - 1) -#define INT64_MIN (__INT64_C(-9223372036854775807) - 1) - -#define INT8_MAX (127) -#define INT16_MAX (32767) -#define INT32_MAX (2147483647) -#define INT64_MAX (__INT64_C(9223372036854775807)) - -#define UINT8_MAX (255U) -#define UINT16_MAX (65535U) -#define UINT32_MAX (4294967295U) -#define UINT64_MAX (__UINT64_C(18446744073709551615)) - -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST64_MIN INT64_MIN - -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MAX INT64_MAX - -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST64_MIN INT64_MIN - -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST64_MAX INT64_MAX - -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST64_MAX UINT64_MAX - -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -#define INT_FAST16_MIN INT32_MIN -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST16_MAX INT32_MAX -#define INT_FAST32_MAX INT32_MAX -#define UINT_FAST16_MAX UINT32_MAX -#define UINT_FAST32_MAX UINT32_MAX - -#define INTPTR_MIN INT32_MIN -#define INTPTR_MAX INT32_MAX -#define UINTPTR_MAX UINT32_MAX - -#define PTRDIFF_MIN INT32_MIN -#define PTRDIFF_MAX INT32_MAX - -#endif - -#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) - -#define INT8_C(c) c -#define INT16_C(c) c -#define INT32_C(c) c -#define INT64_C(c) __INT64_C(c) - -#define UINT8_C(c) c##U -#define UINT16_C(c) c##U -#define UINT32_C(c) c##U -#define UINT64_C(c) __UINT64_C(c) - -#define INT_LEAST8_C(c) INT8_C(c) -#define INT_LEAST16_C(c) INT16_C(c) -#define INT_LEAST32_C(c) INT32_C(c) -#define INT_LEAST64_C(c) INT64_C(c) - -#define UINT_LEAST8_C(c) UINT8_C(c) -#define UINT_LEAST16_C(c) UINT16_C(c) -#define UINT_LEAST32_C(c) UINT32_C(c) -#define UINT_LEAST64_C(c) UINT64_C(c) - -#define INT_FAST8_C(c) INT8_C(c) -#define INT_FAST64_C(c) INT64_C(c) - -#define UINT_FAST8_C(c) UINT8_C(c) -#define UINT_FAST64_C(c) UINT64_C(c) - -#define INTMAX_C(c) INT64_C(c) -#define UINTMAX_C(c) UINT64_C(c) - -#define INT_FAST16_C(c) INT32_C(c) -#define INT_FAST32_C(c) INT32_C(c) - -#define UINT_FAST16_C(c) UINT32_C(c) -#define UINT_FAST32_C(c) UINT32_C(c) - -#define INTPTR_C(c) INT32_C(c) -#define UINTPTR_C(c) UINT32_C(c) -#define PTRDIFF_C(c) INT32_C(c) - -#endif - -#endif /* _STDINT_H */ diff --git a/common/libc/inc/stdio.h b/common/libc/inc/stdio.h deleted file mode 100644 index 3e07085d..00000000 --- a/common/libc/inc/stdio.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * stdio.h - */ - -#ifndef _STDIO_H -#define _STDIO_H - -#include -#include -#include - -/* The actual IO functions are not included. */ -#if __riscv_xlen == 64 -#include_next -#else -__extern int sprintf(char *, const char *, ...); -__extern int vsprintf(char *, const char *, va_list); -__extern int snprintf(char *__restrict, size_t, const char *__restrict, ...); -__extern int vsnprintf(char *, size_t, const char *, va_list); -__extern int sscanf(const char *, const char *, ...); -__extern int vsscanf(const char *, const char *, va_list); -#endif /* __riscv_xlen == 64 */ - -#endif /* _STDIO_H */ diff --git a/common/libc/inc/stdlib.h b/common/libc/inc/stdlib.h deleted file mode 100644 index d265baa7..00000000 --- a/common/libc/inc/stdlib.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * stdlib.h - */ - -#ifndef _STDLIB_H -#define _STDLIB_H - -#include -#include -#include - -#define EXIT_FAILURE 1 -#define EXIT_SUCCESS 0 - -static __inline int abs(int __n) -{ - return (__n < 0) ? -__n : __n; -} - -#if __riscv_xlen == 64 -#include_next -__extern long jrand48(unsigned short *); -#else -__extern int atoi(const char *); -__extern double atof(const char *); -__extern long atol(const char *); -__extern long long atoll(const char *); -static __inline long labs(long __n) -{ - return (__n < 0L) ? -__n : __n; -} - -static __inline long long llabs(long long __n) -{ - return (__n < 0LL) ? -__n : __n; -} - -__extern long strtol(const char *, char **, int); -__extern long long strtoll(const char *, char **, int); -__extern unsigned long strtoul(const char *, char **, int); -__extern unsigned long long strtoull(const char *, char **, int); - -typedef int (*__comparefunc_t)(const void *, const void *); -__extern void *bsearch(const void *, const void *, size_t, size_t, - __comparefunc_t); -__extern void qsort(void *, size_t, size_t, __comparefunc_t); - -__extern long jrand48(unsigned short *); -__extern long mrand48(void); -__extern long nrand48(unsigned short *); -__extern long lrand48(void); -__extern unsigned short *seed48(unsigned short *); -__extern void srand48(long); - -#define RAND_MAX 0x7fffffff -__extern int rand(void); -__extern void srand(unsigned int __s); -__extern long random(void); -__extern void srandom(unsigned int __s); -#endif /* __riscv_xlen == 64 */ - -#endif /* _STDLIB_H */ diff --git a/common/libc/inc/string.h b/common/libc/inc/string.h deleted file mode 100644 index 57fe989c..00000000 --- a/common/libc/inc/string.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * string.h - */ - -#ifndef _STRING_H -#define _STRING_H - -#include -#include -#include -#if __riscv_xlen == 64 -__extern void memswap(void *m1, void *m2, size_t n); -__extern void *memmem(const void *haystack, size_t n, const void *needle, size_t m); -__extern char *strtok_r(char *, const char *, char **); -__extern char *strsep(char **, const char *); -#include_next -#else -__extern void *memccpy(void *, const void *, int, size_t); -__extern void *memchr(const void *, int, size_t); -__extern void *memrchr(const void *, int, size_t); -__extern int memcmp(const void *, const void *, size_t); -__extern void *memcpy(void *, const void *, size_t); -__extern void *memmove(void *, const void *, size_t); -__extern void *memset(void *, int, size_t); -__extern void *memmem(const void *, size_t, const void *, size_t); -__extern void memswap(void *, void *, size_t); -__extern void bzero(void *, size_t); -__extern int strcasecmp(const char *, const char *); -__extern int strncasecmp(const char *, const char *, size_t); -__extern char *strcat(char *, const char *); -__extern char *strchr(const char *, int); -__extern char *strrchr(const char *, int); -__extern int strcmp(const char *, const char *); -__extern char *strcpy(char *, const char *); -__extern size_t strcspn(const char *, const char *); -__extern size_t strlen(const char *); -__extern size_t strnlen(const char *, size_t); -__extern char *strncat(char *, const char *, size_t); -__extern size_t strlcat(char *, const char *, size_t); -__extern int strncmp(const char *, const char *, size_t); -__extern char *strncpy(char *, const char *, size_t); -__extern size_t strlcpy(char *, const char *, size_t); -__extern char *strpbrk(const char *, const char *); -__extern char *strsep(char **, const char *); -__extern size_t strspn(const char *, const char *); -__extern char *strstr(const char *, const char *); -__extern char *strtok(char *, const char *); -__extern char *strtok_r(char *, const char *, char **); -char *index(const char *s, int c); -#endif /* __riscv_xlen == 64 */ - -#endif /* _STRING_H */ diff --git a/common/libc/inc/sys/types.h b/common/libc/inc/sys/types.h deleted file mode 100644 index 247109fd..00000000 --- a/common/libc/inc/sys/types.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * sys/types.h - */ - -#ifndef _SYS_TYPES_H -#define _SYS_TYPES_H - -#include -#include - -#define _SSIZE_T -typedef ptrdiff_t ssize_t; - -#undef NULL -#if defined(__cplusplus) -#define NULL 0 -#else -#define NULL ((void *)0) -#endif - -typedef int daddr_t; -typedef char *caddr_t; - -/* BSD */ -typedef unsigned char u_char; -typedef unsigned short u_short; -typedef unsigned int u_int; -typedef unsigned long u_long; - -/* SysV */ -typedef unsigned char unchar; -typedef unsigned short ushort; -typedef unsigned int uint; -typedef unsigned long ulong; - -/* More BSD */ -typedef uint8_t u_int8_t; -typedef uint16_t u_int16_t; -typedef uint32_t u_int32_t; -typedef uint64_t u_int64_t; - -/* Time related */ -typedef signed int sbintime_t; - -/* Required by cyassl build */ -typedef long off_t; -typedef short dev_t; -typedef unsigned short ino_t; -typedef unsigned short nlink_t; -typedef unsigned short uid_t; -typedef unsigned short mode_t; -typedef unsigned short gid_t; -typedef signed char pid_t; -typedef unsigned long useconds_t; - -/* - * Some headers seem to require this... - */ -#ifndef BITS_PER_LONG -#define BITS_PER_LONG 32 -#endif - -/* - * The following FD_SET macros were added to solve the issue where the - * lwip/sockets.h saw different sys/types.h files when built, and when its - * header files sys/sockets file was included by the SDK. - */ -/* - * Select uses bit masks of file descriptors in longs. - * These macros manipulate such bit fields (the filesystem macros use chars). - * FD_SETSIZE may be defined by the user, but the default here - * should be >= NOFILE (param.h). - */ -#ifndef FD_SET -#ifndef FD_SETSIZE -#define FD_SETSIZE 64 -#endif -#define FD_SET(n, p) ((p)->fd_bits[(n) / 8] |= (1 << ((n)&7))) -#define FD_CLR(n, p) ((p)->fd_bits[(n) / 8] &= ~(1 << ((n)&7))) -#define FD_ISSET(n, p) ((p)->fd_bits[(n) / 8] & (1 << ((n)&7))) -#define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p))) - -typedef struct fd_set { - unsigned char fd_bits[(FD_SETSIZE + 7) / 8]; -} fd_set; -#endif /* FD_SET */ - -#ifndef __ICCARM__ -/* wmsdk: Added from sys/times.h and machine/types.h */ -#define _CLOCK_T_ unsigned long /* clock() */ -#ifndef __clock_t_defined -typedef _CLOCK_T_ clock_t; -#define __clock_t_defined -#endif -#endif - -#endif /* _SYS_TYPES_H */ diff --git a/common/libc/src/atof.c b/common/libc/src/atof.c deleted file mode 100644 index d1b0d819..00000000 --- a/common/libc/src/atof.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * atof.c - * - * The atof() function - */ - -#include -#include -#include -#include -#include - -static inline int digitval(int ch) -{ - if (ch >= '0' && ch <= '9') { - return ch - '0'; - } else if (ch >= 'A' && ch <= 'Z') { - return ch - 'A' + 10; - } else if (ch >= 'a' && ch <= 'z') { - return ch - 'a' + 10; - } else { - return -1; - } -} - -double strntof(const char *nptr, char **endptr, int base, size_t n) -{ - int minus = 0; - double v = 0.0, m = 0.0, divisor = 1.0; - int d; - - while (n && isspace((unsigned char)*nptr)) { - nptr++; - n--; - } - - /* Single optional + or - */ - if (n) { - char c = *nptr; - - if (c == '-' || c == '+') { - minus = (c == '-'); - nptr++; - n--; - } - } - - if (base == 0) { - if (n >= 2 && nptr[0] == '0' && - (nptr[1] == 'x' || nptr[1] == 'X')) { - n -= 2; - nptr += 2; - base = 16; - } else if (n >= 1 && nptr[0] == '0') { - n--; - nptr++; - base = 8; - } else { - base = 10; - } - } else if (base == 16) { - if (n >= 2 && nptr[0] == '0' && - (nptr[1] == 'x' || nptr[1] == 'X')) { - n -= 2; - nptr += 2; - } - } - - while (n && (d = digitval(*nptr)) >= 0 && d < base) { - v = v * base + d; - n--; - nptr++; - } - - if (*nptr == '.') { - n--; - nptr++; - - while (n && (d = digitval(*nptr)) >= 0 && d < base) { - m = m * base + d; - n--; - nptr++; - divisor *= 10.0; - } - } - - if (endptr) { - *endptr = (char *)nptr; - } - - v = v + (m / divisor); - - return minus ? -v : v; -} - -double atof(const char *nptr) -{ - return strntof(nptr, NULL, 0, strlen(nptr)); -} diff --git a/common/libc/src/atoi.c b/common/libc/src/atoi.c deleted file mode 100644 index fd655c3d..00000000 --- a/common/libc/src/atoi.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#define TYPE int -#define NAME atoi -#include "atox.c" diff --git a/common/libc/src/atol.c b/common/libc/src/atol.c deleted file mode 100644 index 36f331ab..00000000 --- a/common/libc/src/atol.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#define TYPE long -#define NAME atol -#include "atox.c" diff --git a/common/libc/src/atoll.c b/common/libc/src/atoll.c deleted file mode 100644 index 25df79e1..00000000 --- a/common/libc/src/atoll.c +++ /dev/null @@ -1,3 +0,0 @@ -#define TYPE long long -#define NAME atoll -#include "atox.c" diff --git a/common/libc/src/atox.c b/common/libc/src/atox.c deleted file mode 100644 index 6694c024..00000000 --- a/common/libc/src/atox.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * atox.c - * - * atoi(), atol(), atoll() - */ - -#include -#include -#include -//#include - -TYPE NAME(const char *nptr) -{ - return (TYPE)strntoumax(nptr, (char **)NULL, 10, ~(size_t)0); -} diff --git a/common/libc/src/bsearch.c b/common/libc/src/bsearch.c deleted file mode 100644 index 5cb91a28..00000000 --- a/common/libc/src/bsearch.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * bsearch.c - */ - -#include - -void *bsearch(const void *key, const void *base, size_t nmemb, - size_t size, int (*cmp)(const void *, const void *)) -{ - while (nmemb) { - size_t mididx = nmemb / 2; - const void *midobj = (const unsigned char *)base + - mididx * size; - int diff = cmp(key, midobj); - - if (diff == 0) { - return (void *)midobj; - } - - if (diff > 0) { - base = (const unsigned char *)midobj + size; - nmemb -= mididx + 1; - } else { - nmemb = mididx; - } - } - - return NULL; -} diff --git a/common/libc/src/common.c b/common/libc/src/common.c deleted file mode 100644 index a36530e8..00000000 --- a/common/libc/src/common.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -//#include - -void __assert_func(const char *file, int line, - const char *func, const char *failedexpr) -{ -#if 0 - printf("assertion \"%s\" failed: file \"%s\", line %d%s%s\n", - failedexpr, file, line, func ? ", function: " : "", - func ? func : ""); - - /* Ensure that nothing runs after this */ - while(1) - ; - -#endif -} - -float strtof(const char *nptr, char **endptr) -{ - // printf("Float print not supported yet!\r\n"); - return 0; -} diff --git a/common/libc/src/ctype_isalnum.c b/common/libc/src/ctype_isalnum.c deleted file mode 100644 index 201e9352..00000000 --- a/common/libc/src/ctype_isalnum.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(isalnum) diff --git a/common/libc/src/ctype_isalpha.c b/common/libc/src/ctype_isalpha.c deleted file mode 100644 index 6a7e70c4..00000000 --- a/common/libc/src/ctype_isalpha.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(isalpha) diff --git a/common/libc/src/ctype_isascii.c b/common/libc/src/ctype_isascii.c deleted file mode 100644 index d56c8a95..00000000 --- a/common/libc/src/ctype_isascii.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(isascii) diff --git a/common/libc/src/ctype_isblank.c b/common/libc/src/ctype_isblank.c deleted file mode 100644 index 4dcc47a2..00000000 --- a/common/libc/src/ctype_isblank.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(isblank) diff --git a/common/libc/src/ctype_iscntrl.c b/common/libc/src/ctype_iscntrl.c deleted file mode 100644 index 98eda158..00000000 --- a/common/libc/src/ctype_iscntrl.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(iscntrl) diff --git a/common/libc/src/ctype_isdigit.c b/common/libc/src/ctype_isdigit.c deleted file mode 100644 index 222c6006..00000000 --- a/common/libc/src/ctype_isdigit.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(isdigit) diff --git a/common/libc/src/ctype_isgraph.c b/common/libc/src/ctype_isgraph.c deleted file mode 100644 index 8b417663..00000000 --- a/common/libc/src/ctype_isgraph.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(isgraph) diff --git a/common/libc/src/ctype_islower.c b/common/libc/src/ctype_islower.c deleted file mode 100644 index 796205c2..00000000 --- a/common/libc/src/ctype_islower.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(islower) diff --git a/common/libc/src/ctype_isprint.c b/common/libc/src/ctype_isprint.c deleted file mode 100644 index 495d8f5d..00000000 --- a/common/libc/src/ctype_isprint.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(isprint) diff --git a/common/libc/src/ctype_ispunct.c b/common/libc/src/ctype_ispunct.c deleted file mode 100644 index 97dc64f2..00000000 --- a/common/libc/src/ctype_ispunct.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(ispunct) diff --git a/common/libc/src/ctype_isspace.c b/common/libc/src/ctype_isspace.c deleted file mode 100644 index 2b3b5dc0..00000000 --- a/common/libc/src/ctype_isspace.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(isspace) diff --git a/common/libc/src/ctype_isupper.c b/common/libc/src/ctype_isupper.c deleted file mode 100644 index f6f7173b..00000000 --- a/common/libc/src/ctype_isupper.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(isupper) diff --git a/common/libc/src/ctype_isxdigit.c b/common/libc/src/ctype_isxdigit.c deleted file mode 100644 index 9b4db7c6..00000000 --- a/common/libc/src/ctype_isxdigit.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(isxdigit) diff --git a/common/libc/src/ctype_tolower.c b/common/libc/src/ctype_tolower.c deleted file mode 100644 index 7a5fd834..00000000 --- a/common/libc/src/ctype_tolower.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(tolower) diff --git a/common/libc/src/ctype_toupper.c b/common/libc/src/ctype_toupper.c deleted file mode 100644 index 56878d6f..00000000 --- a/common/libc/src/ctype_toupper.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include "ctypefunc.h" -CTYPEFUNC(toupper) diff --git a/common/libc/src/ctypefunc.h b/common/libc/src/ctypefunc.h deleted file mode 100644 index c26ef2a3..00000000 --- a/common/libc/src/ctypefunc.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * ctype/ctype.h - * - * Common header for out-of-line ctype functions - */ - -#define __CTYPE_NO_INLINE -#include - -#define CTYPEFUNC(X) \ - int X(int c) \ - { \ - return __ctype_##X(c); \ - } diff --git a/common/libc/src/ctypes.c b/common/libc/src/ctypes.c deleted file mode 100644 index 2d5bd65d..00000000 --- a/common/libc/src/ctypes.c +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * ctypes.c - * - * This is the array that defines classes. - * This assumes ISO 8859-1. - */ - -#include - -const unsigned char __ctypes[257] = { - 0, /* EOF */ - - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl | __ctype_space, /* BS */ - __ctype_cntrl | __ctype_space, /* TAB */ - __ctype_cntrl | __ctype_space, /* LF */ - __ctype_cntrl | __ctype_space, /* VT */ - __ctype_cntrl | __ctype_space, /* FF */ - __ctype_cntrl | __ctype_space, /* CR */ - __ctype_cntrl, /* control character */ - - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - - __ctype_print | __ctype_space, /* space */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - - __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ - __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ - __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ - __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ - __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ - __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ - __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ - __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ - __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ - __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ - __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ - __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ - __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ - __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ - __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_upper, /* G-Z */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ - __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ - __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ - __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ - __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ - __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_lower, /* g-z */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_cntrl, /* control character */ - - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - __ctype_cntrl, /* control character */ - - __ctype_print | __ctype_space, /* NBSP */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_punct, /* punctuation */ - - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_upper, /* upper accented */ - __ctype_print | __ctype_lower, /* lower accented */ - - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_punct, /* punctuation */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ - __ctype_print | __ctype_lower, /* lower accented */ -}; diff --git a/common/libc/src/fnmatch.c b/common/libc/src/fnmatch.c deleted file mode 100644 index 713b52cf..00000000 --- a/common/libc/src/fnmatch.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * fnmatch.c - * - * Original implementation by Kay Sievers, modified by H. Peter Anvin. - */ - -#include - -int fnmatch(const char *p, const char *s, int flags) -{ - if (flags & FNM_PATHNAME && *s == '/') { - return (*p != '/') || fnmatch(p + 1, s + 1, flags); - } - - if (flags & FNM_PERIOD && *s == '.') { - return (*p != '.') || fnmatch(p + 1, s + 1, flags); - } - - flags &= ~FNM_PERIOD; /* Only applies at beginning */ - - if (!(flags & FNM_NOESCAPE) && *p == '\\') { - p++; - return (*p != *s) || fnmatch(p + 1, s + 1, flags); - } - - if (*s == '\0') { - while (*p == '*') { - p++; - } - - return (*p != '\0'); - } - - switch (*p) { - case '[': { - int not_mark = 0; - p++; - - if (*p == '!') { - not_mark = 1; - p++; - } - - while ((*p != '\0') && (*p != ']')) { - int match = 0; - - if (p[1] == '-') { - if ((*s >= *p) && (*s <= p[2])) { - match = 1; - } - - p += 3; - } else { - match = (*p == *s); - p++; - } - - if (match ^ not_mark) { - while ((*p != '\0') && (*p != ']')) { - p++; - } - - if (*p == ']') { - return fnmatch(p + 1, s + 1, flags); - } - } - } - } break; - - case '*': - if (fnmatch(p, s + 1, flags)) { - return fnmatch(p + 1, s, flags); - } - - return 0; - - case '\0': - if (*s == '\0') { - return 0; - } - - break; - - default: - if ((*p == *s) || (*p == '?')) { - return fnmatch(p + 1, s + 1, flags); - } - - break; - } - - return 1; -} diff --git a/common/libc/src/jrand48.c b/common/libc/src/jrand48.c deleted file mode 100644 index e8dbb578..00000000 --- a/common/libc/src/jrand48.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * jrand48.c - */ - -#include -#include - -long jrand48(unsigned short xsubi[3]) -{ - uint64_t x; - - /* The xsubi[] array is littleendian by spec */ - x = (uint64_t)(uint16_t)xsubi[0] + - ((uint64_t)(uint16_t)xsubi[1] << 16) + - ((uint64_t)(uint16_t)xsubi[2] << 32); - - x = (0x5deece66dULL * x) + 0xb; - - xsubi[0] = (unsigned short)(uint16_t)x; - xsubi[1] = (unsigned short)(uint16_t)(x >> 16); - xsubi[2] = (unsigned short)(uint16_t)(x >> 32); - - return (long)(int32_t)(x >> 16); -} diff --git a/common/libc/src/lrand48.c b/common/libc/src/lrand48.c deleted file mode 100644 index 7f66a3cf..00000000 --- a/common/libc/src/lrand48.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * lrand48.c - */ - -#include -#include - -unsigned short __rand48_seed[3]; /* Common with mrand48.c, srand48.c */ - -long lrand48(void) -{ - return (uint32_t)jrand48(__rand48_seed) >> 1; -} - -int rand(void) -{ - return (int)lrand48(); -} - -long random(void) -{ - return lrand48(); -} diff --git a/common/libc/src/memccpy.c b/common/libc/src/memccpy.c deleted file mode 100644 index 51c6ad66..00000000 --- a/common/libc/src/memccpy.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * memccpy.c - * - * memccpy() - */ - -#include -#include - -void *memccpy(void *dst, const void *src, int c, size_t n) -{ - char *q = (char *)dst; - const char *p = (char *)src; - char ch; - - while (n--) { - *q++ = ch = *p++; - - if (ch == (char)c) { - return q; - } - } - - return NULL; /* No instance of "c" found */ -} diff --git a/common/libc/src/memchr.c b/common/libc/src/memchr.c deleted file mode 100644 index 7ad16847..00000000 --- a/common/libc/src/memchr.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * memchr.c - */ - -#include -#include - -void *memchr(const void *s, int c, size_t n) -{ - const unsigned char *sp = (unsigned char *)s; - - while (n--) { - if (*sp == (unsigned char)c) { - return (void *)sp; - } - - sp++; - } - - return NULL; -} diff --git a/common/libc/src/memcmp.c b/common/libc/src/memcmp.c deleted file mode 100644 index 74234c40..00000000 --- a/common/libc/src/memcmp.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * memcmp.c - */ - -#include - -int memcmp(const void *s1, const void *s2, size_t n) -{ - const unsigned char *c1 = (unsigned char *)s1, *c2 = (unsigned char *)s2; - int d = 0; - - while (n--) { - d = (int)*c1++ - (int)*c2++; - - if (d) { - break; - } - } - - return d; -} diff --git a/common/libc/src/memcpy.c b/common/libc/src/memcpy.c deleted file mode 100644 index e8b9267b..00000000 --- a/common/libc/src/memcpy.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * memcpy.c - */ - -#include -#include - -void *memcpy(void *dst, const void *src, size_t n) -{ - const char *p = (char *)src; - char *q = (char *)dst; - - while (n--) { - *q++ = *p++; - } - - return dst; -} diff --git a/common/libc/src/memmem.c b/common/libc/src/memmem.c deleted file mode 100644 index 9f845d66..00000000 --- a/common/libc/src/memmem.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * memmem.c - * - * Find a byte string inside a longer byte string - * - * This uses the "Not So Naive" algorithm, a very simple but - * usually effective algorithm, see: - * - * http://www-igm.univ-mlv.fr/~lecroq/string/ - */ - -#include - -void *memmem(const void *haystack, size_t n, const void *needle, size_t m) -{ - const unsigned char *y = (const unsigned char *)haystack; - const unsigned char *x = (const unsigned char *)needle; - - size_t j, k, l; - - if (m > n || !m || !n) { - return NULL; - } - - if (1 != m) { - if (x[0] == x[1]) { - k = 2; - l = 1; - } else { - k = 1; - l = 2; - } - - j = 0; - - while (j <= n - m) { - if (x[1] != y[j + 1]) { - j += k; - } else { - if (!memcmp(x + 2, y + j + 2, m - 2) && x[0] == y[j]) { - return (void *)&y[j]; - } - - j += l; - } - } - } else - do { - if (*y == *x) { - return (void *)y; - } - - y++; - } while (--n); - - return NULL; -} diff --git a/common/libc/src/memrchr.c b/common/libc/src/memrchr.c deleted file mode 100644 index b9155ba4..00000000 --- a/common/libc/src/memrchr.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * memrchr.c - */ - -#include -#include - -void *memrchr(const void *s, int c, size_t n) -{ - const unsigned char *sp = (const unsigned char *)s + n - 1; - - while (n--) { - if (*sp == (unsigned char)c) { - return (void *)sp; - } - - sp--; - } - - return NULL; -} diff --git a/common/libc/src/memset.c b/common/libc/src/memset.c deleted file mode 100644 index 4530052d..00000000 --- a/common/libc/src/memset.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * memset.c - */ - -#include -#include - -void *memset(void *dst, int c, size_t n) -{ - char *q = (char *)dst; - - while (n--) { - *q++ = c; - __asm volatile("" :: - : "memory"); - } - - return dst; -} diff --git a/common/libc/src/memswap.c b/common/libc/src/memswap.c deleted file mode 100644 index 2c5f6e2d..00000000 --- a/common/libc/src/memswap.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * memswap() - * - * Swaps the contents of two nonoverlapping memory areas. - * This really could be done faster... - */ - -#include - -void memswap(void *m1, void *m2, size_t n) -{ - char *p = (char *)m1; - char *q = (char *)m2; - char tmp; - - while (n--) { - tmp = *p; - *p = *q; - *q = tmp; - - p++; - q++; - } -} diff --git a/common/libc/src/mrand48.c b/common/libc/src/mrand48.c deleted file mode 100644 index f9d68bd3..00000000 --- a/common/libc/src/mrand48.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * mrand48.c - */ - -#include -#include - -/* Common with lrand48.c, srand48.c */ -extern unsigned short __rand48_seed[3]; - -long mrand48(void) -{ - return jrand48(__rand48_seed); -} diff --git a/common/libc/src/nrand48.c b/common/libc/src/nrand48.c deleted file mode 100644 index 82b074b6..00000000 --- a/common/libc/src/nrand48.c +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * nrand48.c - */ - -#include -#include - -long nrand48(unsigned short xsubi[3]) -{ - return (long)((uint32_t)jrand48(xsubi) >> 1); -} diff --git a/common/libc/src/qsort.c b/common/libc/src/qsort.c deleted file mode 100644 index de30040c..00000000 --- a/common/libc/src/qsort.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * qsort.c - * - * This is actually combsort. It's an O(n log n) algorithm with - * simplicity/small code size being its main virtue. - */ - -#include -#include -#include -#include -//#include - -static __inline size_t newgap(size_t gap) -{ - gap = (gap * 10) / 13; - - if (gap == 9 || gap == 10) { - gap = 11; - } - - if (gap < 1) { - gap = 1; - } - - return gap; -} - -void qsort(void *base, size_t nmemb, size_t size, - int (*compar)(const void *, const void *)) -{ - size_t gap = nmemb; - size_t i, j; - char *p1, *p2; - int swapped; - - if (!nmemb) { - return; - } - - do { - gap = newgap(gap); - swapped = 0; - - for (i = 0, p1 = (char *)base; i < nmemb - gap; i++, p1 += size) { - j = i + gap; - - if (compar(p1, p2 = (char *)base + j * size) > 0) { - memswap(p1, p2, size); - swapped = 1; - } - } - } while (gap > 1 || swapped); -} diff --git a/common/libc/src/seed48.c b/common/libc/src/seed48.c deleted file mode 100644 index 41bdbe70..00000000 --- a/common/libc/src/seed48.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * seed48.c - */ - -#include -#include -#include - -extern unsigned short __rand48_seed[3]; - -unsigned short *seed48(unsigned short int xsubi[3]) -{ - static unsigned short oldseed[3]; - memcpy(oldseed, __rand48_seed, sizeof __rand48_seed); - memcpy(__rand48_seed, xsubi, sizeof __rand48_seed); - - return oldseed; -} diff --git a/common/libc/src/snprintf.c b/common/libc/src/snprintf.c deleted file mode 100644 index 6c470ee4..00000000 --- a/common/libc/src/snprintf.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * snprintf.c - */ - -#include -#include - -int snprintf(char *buffer, size_t n, const char *format, ...) -{ - va_list ap; - int rv; - - va_start(ap, format); - rv = vsnprintf(buffer, n, format, ap); - va_end(ap); - return rv; -} diff --git a/common/libc/src/sprintf.c b/common/libc/src/sprintf.c deleted file mode 100644 index a385cf19..00000000 --- a/common/libc/src/sprintf.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * sprintf.c - */ - -#include -#include - -int sprintf(char *buffer, const char *format, ...) -{ - va_list ap; - int rv; - - va_start(ap, format); - rv = vsnprintf(buffer, (~(unsigned int)0) >> 1, format, ap); - va_end(ap); - - return rv; -} diff --git a/common/libc/src/srand48.c b/common/libc/src/srand48.c deleted file mode 100644 index 85fec411..00000000 --- a/common/libc/src/srand48.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * srand48.c - */ - -#include -#include - -/* Common with mrand48.c, lrand48.c */ -extern unsigned short __rand48_seed[3]; - -void srand48(long seedval) -{ - __rand48_seed[0] = 0x330e; - __rand48_seed[1] = (unsigned short)seedval; - __rand48_seed[2] = (unsigned short)((uint32_t)seedval >> 16); -} - -void srand(unsigned int __s) -{ - srand48(__s); -} - -void srandom(unsigned int __s) -{ - srand48(__s); -} diff --git a/common/libc/src/sscanf.c b/common/libc/src/sscanf.c deleted file mode 100644 index 1b92a9bb..00000000 --- a/common/libc/src/sscanf.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * sscanf() - */ - -#include -#include - -int sscanf(const char *str, const char *format, ...) -{ - va_list ap; - int rv; - - va_start(ap, format); - rv = vsscanf(str, format, ap); - va_end(ap); - - return rv; -} diff --git a/common/libc/src/stdlib.c b/common/libc/src/stdlib.c deleted file mode 100644 index d3d5de65..00000000 --- a/common/libc/src/stdlib.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - * - * This functions implement WMSDK specific memory allocator routines. - */ - -#include -#include -#include - -#ifndef BFLB_IN_BENCHMARK -void *malloc(size_t size) -{ - return NULL; -} - -void free(void *ptr) -{ -} -#endif - -void *calloc(size_t nmemb, size_t size) -{ - return NULL; -} - -void *realloc(void *ptr, size_t size) -{ - return NULL; -} diff --git a/common/libc/src/strcasecmp.c b/common/libc/src/strcasecmp.c deleted file mode 100644 index 39b2f7fa..00000000 --- a/common/libc/src/strcasecmp.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strcasecmp.c - */ - -#include -#include - -int strcasecmp(const char *s1, const char *s2) -{ - const unsigned char *c1 = (const unsigned char *)s1; - const unsigned char *c2 = (const unsigned char *)s2; - unsigned char ch; - int d = 0; - - while (1) { - /* toupper() expects an unsigned char (implicitly cast to int) - as input, and returns an int, which is exactly what we want. */ - d = toupper(ch = *c1++) - toupper(*c2++); - - if (d || !ch) { - break; - } - } - - return d; -} diff --git a/common/libc/src/strcat.c b/common/libc/src/strcat.c deleted file mode 100644 index 71e993dc..00000000 --- a/common/libc/src/strcat.c +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strcat.c - */ - -#include - -char *strcat(char *dst, const char *src) -{ - strcpy(strchr(dst, '\0'), src); - return dst; -} diff --git a/common/libc/src/strchr.c b/common/libc/src/strchr.c deleted file mode 100644 index 88e72dfc..00000000 --- a/common/libc/src/strchr.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strchr.c - */ - -#include -#include - -__WEAK__ -char *strchr(const char *s, int c) -{ - while (*s != (char)c) { - if (!*s) { - return NULL; - } - - s++; - } - - return (char *)s; -} diff --git a/common/libc/src/strcmp.c b/common/libc/src/strcmp.c deleted file mode 100644 index b23556e4..00000000 --- a/common/libc/src/strcmp.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strcmp.c - */ - -#include - -#ifdef BFLB_IN_BENCHMARK -int bflb_strcmp(const char *s1, const char *s2) -#else -int strcmp(const char *s1, const char *s2) -#endif -{ - const unsigned char *c1 = (const unsigned char *)s1; - const unsigned char *c2 = (const unsigned char *)s2; - unsigned char ch; - int d = 0; - - while (1) { - d = (int)(ch = *c1++) - (int)*c2++; - - if (d || !ch) { - break; - } - } - - return d; -} diff --git a/common/libc/src/strcpy.c b/common/libc/src/strcpy.c deleted file mode 100644 index c1a52020..00000000 --- a/common/libc/src/strcpy.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strcpy.c - * - * strcpy() - */ - -#include - -char *strcpy(char *dst, const char *src) -{ - char *q = dst; - const char *p = src; - char ch; - - do { - *q++ = ch = *p++; - } while (ch); - - return dst; -} diff --git a/common/libc/src/strcspn.c b/common/libc/src/strcspn.c deleted file mode 100644 index 39b938de..00000000 --- a/common/libc/src/strcspn.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strcspn - */ - -#include - -#include "strxspn.h" - -size_t strcspn(const char *s, const char *reject) -{ - return __strxspn(s, reject, 1); -} diff --git a/common/libc/src/strlcat.c b/common/libc/src/strlcat.c deleted file mode 100644 index 67f31741..00000000 --- a/common/libc/src/strlcat.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strlcat.c - */ - -#include - -size_t strlcat(char *dst, const char *src, size_t size) -{ - size_t bytes = 0; - char *q = dst; - const char *p = src; - char ch; - - while (bytes < size && *q) { - q++; - bytes++; - } - - if (bytes == size) { - return (bytes + strlen(src)); - } - - while ((ch = *p++)) { - if (bytes + 1 < size) { - *q++ = ch; - } - - bytes++; - } - - *q = '\0'; - return bytes; -} diff --git a/common/libc/src/strlcpy.c b/common/libc/src/strlcpy.c deleted file mode 100644 index 5df7f9dd..00000000 --- a/common/libc/src/strlcpy.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strlcpy.c - */ - -#include - -size_t strlcpy(char *dst, const char *src, size_t size) -{ - size_t bytes = 0; - char *q = dst; - const char *p = src; - char ch; - - while ((ch = *p++)) { - if (bytes + 1 < size) { - *q++ = ch; - } - - bytes++; - } - - /* If size == 0 there is no space for a final null... */ - if (size) { - *q = '\0'; - } - - return bytes; -} diff --git a/common/libc/src/strlen.c b/common/libc/src/strlen.c deleted file mode 100644 index bd771bea..00000000 --- a/common/libc/src/strlen.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strlen() - */ - -#include - -size_t strlen(const char *s) -{ - const char *ss = s; - - while (*ss) { - ss++; - } - - return ss - s; -} diff --git a/common/libc/src/strncasecmp.c b/common/libc/src/strncasecmp.c deleted file mode 100644 index db53ebd5..00000000 --- a/common/libc/src/strncasecmp.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strncasecmp.c - */ - -#include -#include - -int strncasecmp(const char *s1, const char *s2, size_t n) -{ - const unsigned char *c1 = (const unsigned char *)s1; - const unsigned char *c2 = (const unsigned char *)s2; - unsigned char ch; - int d = 0; - - while (n--) { - /* toupper() expects an unsigned char (implicitly cast to int) - as input, and returns an int, which is exactly what we want. */ - d = toupper(ch = *c1++) - toupper(*c2++); - - if (d || !ch) { - break; - } - } - - return d; -} diff --git a/common/libc/src/strncat.c b/common/libc/src/strncat.c deleted file mode 100644 index 7ca8a6c4..00000000 --- a/common/libc/src/strncat.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strncat.c - */ - -#include - -char *strncat(char *dst, const char *src, size_t n) -{ - char *q = strchr(dst, '\0'); - const char *p = src; - char ch; - - while (n--) { - *q++ = ch = *p++; - - if (!ch) { - return dst; - } - } - - *q = '\0'; - - return dst; -} diff --git a/common/libc/src/strncmp.c b/common/libc/src/strncmp.c deleted file mode 100644 index db04a96a..00000000 --- a/common/libc/src/strncmp.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strncmp.c - */ - -#include - -int strncmp(const char *s1, const char *s2, size_t n) -{ - const unsigned char *c1 = (const unsigned char *)s1; - const unsigned char *c2 = (const unsigned char *)s2; - unsigned char ch; - int d = 0; - - while (n--) { - d = (int)(ch = *c1++) - (int)*c2++; - - if (d || !ch) { - break; - } - } - - return d; -} diff --git a/common/libc/src/strncpy.c b/common/libc/src/strncpy.c deleted file mode 100644 index 1e270fab..00000000 --- a/common/libc/src/strncpy.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strncpy.c - */ - -#include - -char *strncpy(char *dst, const char *src, size_t n) -{ - char *q = dst; - const char *p = src; - char ch; - - while (n) { - n--; - *q++ = ch = *p++; - - if (!ch) { - break; - } - } - - /* The specs say strncpy() fills the entire buffer with NUL. Sigh. */ - memset(q, 0, n); - - return dst; -} diff --git a/common/libc/src/strnlen.c b/common/libc/src/strnlen.c deleted file mode 100644 index 82e8972d..00000000 --- a/common/libc/src/strnlen.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strnlen() - */ - -#include - -size_t strnlen(const char *s, size_t maxlen) -{ - const char *ss = s; - - /* Important: the maxlen test must precede the reference through ss; - since the byte beyond the maximum may segfault */ - while ((maxlen > 0) && *ss) { - ss++; - maxlen--; - } - - return ss - s; -} diff --git a/common/libc/src/strntoimax.c b/common/libc/src/strntoimax.c deleted file mode 100644 index 0fe8a28f..00000000 --- a/common/libc/src/strntoimax.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strntoimax.c - * - * strntoimax() - */ - -#include -#include -//#include - -intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n) -{ - return (intmax_t)strntoumax(nptr, endptr, base, n); -} diff --git a/common/libc/src/strntoumax.c b/common/libc/src/strntoumax.c deleted file mode 100644 index eca59641..00000000 --- a/common/libc/src/strntoumax.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strntoumax.c - * - * The strntoumax() function and associated - */ - -#include -#include -#include -#include - -static __inline int digitval(int ch) -{ - if (ch >= '0' && ch <= '9') { - return ch - '0'; - } else if (ch >= 'A' && ch <= 'Z') { - return ch - 'A' + 10; - } else if (ch >= 'a' && ch <= 'z') { - return ch - 'a' + 10; - } else { - return -1; - } -} - -uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n) -{ - int minus = 0; - uintmax_t v = 0; - int d; - - while (n && isspace((unsigned char)*nptr)) { - nptr++; - n--; - } - - /* Single optional + or - */ - if (n) { - char c = *nptr; - - if (c == '-' || c == '+') { - minus = (c == '-'); - nptr++; - n--; - } - } - - if (base == 0) { - if (n >= 2 && nptr[0] == '0' && - (nptr[1] == 'x' || nptr[1] == 'X')) { - n -= 2; - nptr += 2; - base = 16; - } else if (n >= 1 && nptr[0] == '0') { - n--; - nptr++; - base = 8; - } else { - base = 10; - } - } else if (base == 16) { - if (n >= 2 && nptr[0] == '0' && - (nptr[1] == 'x' || nptr[1] == 'X')) { - n -= 2; - nptr += 2; - } - } - - while (n && (d = digitval(*nptr)) >= 0 && d < base) { - v = v * base + d; - n--; - nptr++; - } - - if (endptr) { - *endptr = (char *)nptr; - } - - return minus ? -v : v; -} diff --git a/common/libc/src/strpbrk.c b/common/libc/src/strpbrk.c deleted file mode 100644 index 9c24e925..00000000 --- a/common/libc/src/strpbrk.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strpbrk - */ - -#include - -#include "strxspn.h" - -char *strpbrk(const char *s, const char *accept) -{ - const char *ss = s + __strxspn(s, accept, 1); - - return *ss ? (char *)ss : NULL; -} diff --git a/common/libc/src/strrchr.c b/common/libc/src/strrchr.c deleted file mode 100644 index 03aef6a6..00000000 --- a/common/libc/src/strrchr.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strrchr.c - */ - -#include - -char *strrchr(const char *s, int c) -{ - const char *found = NULL; - - while (*s) { - if (*s == (char)c) { - found = s; - } - - s++; - } - - return (char *)found; -} diff --git a/common/libc/src/strsep.c b/common/libc/src/strsep.c deleted file mode 100644 index 426d07d4..00000000 --- a/common/libc/src/strsep.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strsep.c - */ - -#include - -char *strsep(char **stringp, const char *delim) -{ - char *s = *stringp; - char *e; - - if (!s) { - return NULL; - } - - e = strpbrk(s, delim); - - if (e) { - *e++ = '\0'; - } - - *stringp = e; - return s; -} diff --git a/common/libc/src/strspn.c b/common/libc/src/strspn.c deleted file mode 100644 index 9f346af7..00000000 --- a/common/libc/src/strspn.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strspn - */ - -#include - -#include "strxspn.h" - -size_t strspn(const char *s, const char *accept) -{ - return __strxspn(s, accept, 0); -} diff --git a/common/libc/src/strstr.c b/common/libc/src/strstr.c deleted file mode 100644 index ddad3307..00000000 --- a/common/libc/src/strstr.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strstr.c - */ - -#include -//#include - -char *strstr(const char *haystack, const char *needle) -{ - return (char *)memmem(haystack, strlen(haystack), needle, - strlen(needle)); -} diff --git a/common/libc/src/strtoimax.c b/common/libc/src/strtoimax.c deleted file mode 100644 index ba4bd1e6..00000000 --- a/common/libc/src/strtoimax.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#define TYPE intmax_t -#define NAME strtoimax -#include "strtox.c" diff --git a/common/libc/src/strtok.c b/common/libc/src/strtok.c deleted file mode 100644 index d5341c24..00000000 --- a/common/libc/src/strtok.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strtok.c - */ - -#include - -char *strtok(char *s, const char *delim) -{ - static char *holder; - - return strtok_r(s, delim, &holder); -} diff --git a/common/libc/src/strtok_r.c b/common/libc/src/strtok_r.c deleted file mode 100644 index 65c54539..00000000 --- a/common/libc/src/strtok_r.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#include - -char *strtok_r(char *s, const char *delim, char **holder) -{ - if (s) { - *holder = s; - } - - do { - s = strsep(holder, delim); - } while (s && !*s); - - return s; -} diff --git a/common/libc/src/strtol.c b/common/libc/src/strtol.c deleted file mode 100644 index 773db454..00000000 --- a/common/libc/src/strtol.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#define TYPE signed long -#define NAME strtol -#include "strtox.c" diff --git a/common/libc/src/strtoll.c b/common/libc/src/strtoll.c deleted file mode 100644 index ef19ae87..00000000 --- a/common/libc/src/strtoll.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#define TYPE signed long long -#define NAME strtoll -#include "strtox.c" diff --git a/common/libc/src/strtoul.c b/common/libc/src/strtoul.c deleted file mode 100644 index 1ee24f34..00000000 --- a/common/libc/src/strtoul.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#define TYPE unsigned long -#define NAME strtoul -#include "strtox.c" diff --git a/common/libc/src/strtoull.c b/common/libc/src/strtoull.c deleted file mode 100644 index 0bcf8026..00000000 --- a/common/libc/src/strtoull.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#define TYPE unsigned long long -#define NAME strtoull -#include "strtox.c" diff --git a/common/libc/src/strtoumax.c b/common/libc/src/strtoumax.c deleted file mode 100644 index 37cad718..00000000 --- a/common/libc/src/strtoumax.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -#define TYPE uintmax_t -#define NAME strtoumax -#include "strtox.c" diff --git a/common/libc/src/strtox.c b/common/libc/src/strtox.c deleted file mode 100644 index 27d9e950..00000000 --- a/common/libc/src/strtox.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strtox.c - * - * strto...() functions, by macro definition - */ - -#include -#include -#include -#include - -WEAK TYPE NAME(const char *nptr, char **endptr, int base) -{ - return (TYPE)strntoumax(nptr, endptr, base, ~(size_t)0); -} diff --git a/common/libc/src/strxspn.c b/common/libc/src/strxspn.c deleted file mode 100644 index 574aed0b..00000000 --- a/common/libc/src/strxspn.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * strpbrk - */ - -#include -#include -#include -#include -#include "strxspn.h" - -size_t __strxspn(const char *s, const char *map, int parity) -{ - char matchmap[UCHAR_MAX + 1]; - size_t n = 0; - - /* Create bitmap */ - memset(matchmap, 0, sizeof matchmap); - - while (*map) { - matchmap[(unsigned char)*map++] = 1; - } - - /* Make sure the null character never matches */ - matchmap[0] = parity; - - /* Calculate span length */ - while (matchmap[(unsigned char)*s++] ^ parity) { - n++; - } - - return n; -} diff --git a/common/libc/src/strxspn.h b/common/libc/src/strxspn.h deleted file mode 100644 index ce56ff29..00000000 --- a/common/libc/src/strxspn.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * strxspn.h - */ - -#ifndef STRXSPN_H -#define STRXSPN_H - -#include - -extern size_t __strxspn(const char *s, const char *map, int parity); - -#endif diff --git a/common/libc/src/vsnprintf.c b/common/libc/src/vsnprintf.c deleted file mode 100644 index f1ab0f92..00000000 --- a/common/libc/src/vsnprintf.c +++ /dev/null @@ -1,934 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * vsnprintf.c - * - * vsnprintf(), from which the rest of the printf() - * family is built - */ - -#include -#include -#include -#include -#include -#include - -enum flag { - FL_ZERO = 0x01, /* Zero modifier */ - FL_MINUS = 0x02, /* Minus modifier */ - FL_PLUS = 0x04, /* Plus modifier */ - FL_TICK = 0x08, /* ' modifier */ - FL_SPACE = 0x10, /* Space modifier */ - FL_HASH = 0x20, /* # modifier */ - FL_SIGNED = 0x40, /* Number is signed */ - FL_UPPER = 0x80 /* Upper case digits */ -}; - -/* These may have to be adjusted on certain implementations */ -enum ranks { - rank_char = -2, - rank_short = -1, - rank_int = 0, - rank_long = 1, - rank_longlong = 2 -}; - -#define MIN_RANK rank_char -#define MAX_RANK rank_longlong - -#define INTMAX_RANK rank_longlong -#define SIZE_T_RANK rank_long -#define PTRDIFF_T_RANK rank_long - -#define EMIT(x) \ - { \ - if (o < n) { \ - *q++ = (x); \ - } \ - o++; \ - } -static size_t format_int(char *q, size_t n, uintmax_t val, unsigned int flags, - int base, int width, int prec) -{ - char *qq; - size_t o = 0, oo; - static const char lcdigits[] = "0123456789abcdef"; - static const char ucdigits[] = "0123456789ABCDEF"; - const char *digits; - uintmax_t tmpval; - int minus = 0; - int ndigits = 0, nchars; - int tickskip, b4tick; - - /* Select type of digits */ - digits = (flags & FL_UPPER) ? ucdigits : lcdigits; - - /* If signed, separate out the minus */ - if (flags & FL_SIGNED && (intmax_t)val < 0) { - minus = 1; - val = (uintmax_t)(-(intmax_t)val); - } - - /* Count the number of digits needed. This returns zero for 0. */ - tmpval = val; - - while (tmpval) { - tmpval /= base; - ndigits++; - } - - /* Adjust ndigits for size of output */ - - if (flags & FL_HASH && base == 8) { - if (prec < ndigits + 1) { - prec = ndigits + 1; - } - } - - if (ndigits < prec) { - ndigits = prec; /* Mandatory number padding */ - } else if (val == 0) { - ndigits = 1; /* Zero still requires space */ - } - - /* For ', figure out what the skip should be */ - if (flags & FL_TICK) { - tickskip = (base == 16) ? 4 : 3; - } else { - tickskip = ndigits; /* No tick marks */ - } - - /* Tick marks aren't digits, but generated by the number converter */ - ndigits += (ndigits - 1) / tickskip; - - /* Now compute the number of nondigits */ - nchars = ndigits; - - if (minus || (flags & (FL_PLUS | FL_SPACE))) { - nchars++; /* Need space for sign */ - } - - if ((flags & FL_HASH) && base == 16) { - nchars += 2; /* Add 0x for hex */ - } - - /* Emit early space padding */ - if (!(flags & (FL_MINUS | FL_ZERO)) && width > nchars) { - while (width > nchars) { - EMIT(' '); - width--; - } - } - - /* Emit nondigits */ - if (minus) { - EMIT('-'); - } else if (flags & FL_PLUS) { - EMIT('+'); - } else if (flags & FL_SPACE) { - EMIT(' '); - } - - if ((flags & FL_HASH) && base == 16) { - EMIT('0'); - EMIT((flags & FL_UPPER) ? 'X' : 'x'); - } - - /* Emit zero padding */ - if ((flags & (FL_MINUS | FL_ZERO)) == FL_ZERO && width > ndigits) { - while (width > nchars) { - EMIT('0'); - width--; - } - } - - /* Generate the number. This is done from right to left. */ - q += ndigits; /* Advance the pointer to end of number */ - o += ndigits; - qq = q; - oo = o; /* Temporary values */ - - b4tick = tickskip; - - while (ndigits > 0) { - if (!b4tick--) { - qq--; - oo--; - ndigits--; - - if (oo < n) { - *qq = '_'; - } - - b4tick = tickskip - 1; - } - - qq--; - oo--; - ndigits--; - - if (oo < n) { - *qq = digits[val % base]; - } - - val /= base; - } - - /* Emit late space padding */ - while ((flags & FL_MINUS) && width > nchars) { - EMIT(' '); - width--; - } - - return o; -} - -#ifdef BFLB_PRINT_FLOAT_SUPPORT - -#define ZEROPAD (1 << 0) /* Pad with zero */ -#define SIGN (1 << 1) /* Unsigned/signed long */ -#define PLUS (1 << 2) /* Show plus */ -#define SPACE (1 << 3) /* Spacer */ -#define LEFT (1 << 4) /* Left justified */ -#define HEX_PREP (1 << 5) /* 0x */ -#define UPPERCASE (1 << 6) /* 'ABCDEF' */ - -#include -#define CVTBUFSIZE 80 - -static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, int eflag) -{ - int r2; - double fi, fj; - char *p, *p1; - - if (ndigits < 0) { - ndigits = 0; - } - - if (ndigits >= CVTBUFSIZE - 1) { - ndigits = CVTBUFSIZE - 2; - } - - r2 = 0; - *sign = 0; - p = &buf[0]; - - if (arg < 0) { - *sign = 1; - arg = -arg; - } - - arg = modf(arg, &fi); - p1 = &buf[CVTBUFSIZE]; - - if (fi != 0) { - p1 = &buf[CVTBUFSIZE]; - - while (fi != 0) { - fj = modf(fi / 10, &fi); - *--p1 = (int)((fj + 0.03) * 10) + '0'; - r2++; - } - - while (p1 < &buf[CVTBUFSIZE]) { - *p++ = *p1++; - } - } else if (arg > 0) { - while ((fj = arg * 10) < 1) { - arg = fj; - r2--; - } - } - - p1 = &buf[ndigits]; - - if (eflag == 0) { - p1 += r2; - } - - *decpt = r2; - - if (p1 < &buf[0]) { - buf[0] = '\0'; - return buf; - } - - while (p <= p1 && p < &buf[CVTBUFSIZE]) { - arg *= 10; - arg = modf(arg, &fj); - *p++ = (int)fj + '0'; - } - - if (p1 >= &buf[CVTBUFSIZE]) { - buf[CVTBUFSIZE - 1] = '\0'; - return buf; - } - - p = p1; - *p1 += 5; - - while (*p1 > '9') { - *p1 = '0'; - - if (p1 > buf) { - ++*--p1; - } else { - *p1 = '1'; - (*decpt)++; - - if (eflag == 0) { - if (p > buf) { - *p = '0'; - } - - p++; - } - } - } - - *p = '\0'; - return buf; -} - -char *ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf) -{ - return cvt(arg, ndigits, decpt, sign, buf, 1); -} - -char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf) -{ - return cvt(arg, ndigits, decpt, sign, buf, 0); -} - -static void ee_bufcpy(char *d, char *s, int count); - -void ee_bufcpy(char *pd, char *ps, int count) -{ - char *pe = ps + count; - - while (ps != pe) { - *pd++ = *ps++; - } -} - -static void parse_float(double value, char *buffer, char fmt, int precision) -{ - int decpt, sign, exp, pos; - char *digits = NULL; - char cvtbuf[80]; - int capexp = 0; - int magnitude; - - if (fmt == 'G' || fmt == 'E') { - capexp = 1; - fmt += 'a' - 'A'; - } - - if (fmt == 'g') { - digits = ecvtbuf(value, precision, &decpt, &sign, cvtbuf); - magnitude = decpt - 1; - - if (magnitude < -4 || magnitude > precision - 1) { - fmt = 'e'; - precision -= 1; - } else { - fmt = 'f'; - precision -= decpt; - } - } - - if (fmt == 'e') { - digits = ecvtbuf(value, precision + 1, &decpt, &sign, cvtbuf); - - if (sign) { - *buffer++ = '-'; - } - - *buffer++ = *digits; - - if (precision > 0) { - *buffer++ = '.'; - } - - ee_bufcpy(buffer, digits + 1, precision); - buffer += precision; - *buffer++ = capexp ? 'E' : 'e'; - - if (decpt == 0) { - if (value == 0.0) { - exp = 0; - } else { - exp = -1; - } - } else { - exp = decpt - 1; - } - - if (exp < 0) { - *buffer++ = '-'; - exp = -exp; - } else { - *buffer++ = '+'; - } - - buffer[2] = (exp % 10) + '0'; - exp = exp / 10; - buffer[1] = (exp % 10) + '0'; - exp = exp / 10; - buffer[0] = (exp % 10) + '0'; - buffer += 3; - } else if (fmt == 'f') { - digits = fcvtbuf(value, precision, &decpt, &sign, cvtbuf); - - if (sign) { - *buffer++ = '-'; - } - - if (*digits) { - if (decpt <= 0) { - *buffer++ = '0'; - *buffer++ = '.'; - - for (pos = 0; pos < -decpt; pos++) { - *buffer++ = '0'; - } - - while (*digits) { - *buffer++ = *digits++; - } - } else { - pos = 0; - - while (*digits) { - if (pos++ == decpt) { - *buffer++ = '.'; - } - - *buffer++ = *digits++; - } - } - } else { - *buffer++ = '0'; - - if (precision > 0) { - *buffer++ = '.'; - - for (pos = 0; pos < precision; pos++) { - *buffer++ = '0'; - } - } - } - } - - *buffer = '\0'; -} - -static void decimal_point(char *buffer) -{ - while (*buffer) { - if (*buffer == '.') { - return; - } - - if (*buffer == 'e' || *buffer == 'E') { - break; - } - - buffer++; - } - - if (*buffer) { - int n = strnlen(buffer, 256); - - while (n > 0) { - buffer[n + 1] = buffer[n]; - n--; - } - - *buffer = '.'; - } else { - *buffer++ = '.'; - *buffer = '\0'; - } -} - -static void cropzeros(char *buffer) -{ - char *stop; - - while (*buffer && *buffer != '.') { - buffer++; - } - - if (*buffer++) { - while (*buffer && *buffer != 'e' && *buffer != 'E') { - buffer++; - } - - stop = buffer--; - - while (*buffer == '0') { - buffer--; - } - - if (*buffer == '.') { - buffer--; - } - - while (buffer != stop) { - *++buffer = 0; - } - } -} - -static char *flt(char *str, double num, int size, int precision, char fmt, int flags) -{ - char tmp[80]; - char c, sign; - int n, i; - - // Left align means no zero padding - if (flags & LEFT) { - flags &= ~ZEROPAD; - } - - // Determine padding and sign char - c = (flags & ZEROPAD) ? '0' : ' '; - sign = 0; - - if (flags & SIGN) { - if (num < 0.0) { - sign = '-'; - num = -num; - size--; - } else if (flags & PLUS) { - sign = '+'; - size--; - } else if (flags & SPACE) { - sign = ' '; - size--; - } - } - - // Compute the precision value - if (precision < 0) { - precision = 6; // Default precision: 6 - } - - // Convert floating point number to text - parse_float(num, tmp, fmt, precision); - - if ((flags & HEX_PREP) && precision == 0) { - decimal_point(tmp); - } - - if (fmt == 'g' && !(flags & HEX_PREP)) { - cropzeros(tmp); - } - - n = strnlen(tmp, 256); - - // Output number with alignment and padding - size -= n; - - if (!(flags & (ZEROPAD | LEFT))) - while (size-- > 0) { - *str++ = ' '; - } - - if (sign) { - *str++ = sign; - } - - if (!(flags & LEFT)) - while (size-- > 0) { - *str++ = c; - } - - for (i = 0; i < n; i++) { - *str++ = tmp[i]; - } - - while (size-- > 0) { - *str++ = ' '; - } - - return str; -} -#endif - -int vsnprintf(char *buffer, size_t n, const char *format, va_list ap) -{ - const char *p = format; - char ch; - char *q = buffer; - size_t o = 0; /* Number of characters output */ - uintmax_t val = 0; - int rank = rank_int; /* Default rank */ - int width = 0; - int prec = -1; - int base; - size_t sz; - unsigned int flags = 0; - enum { - st_normal, /* Ground state */ - st_flags, /* Special flags */ - st_width, /* Field width */ - st_prec, /* Field precision */ - st_modifiers /* Length or conversion modifiers */ - } state = st_normal; - const char *sarg; /* %s string argument */ - char carg; /* %c char argument */ - int slen; /* String length */ - - while ((ch = *p++)) { - switch (state) { - case st_normal: - if (ch == '%') { - state = st_flags; - flags = 0; - rank = rank_int; - width = 0; - prec = -1; - } else { - EMIT(ch); - } - - break; - - case st_flags: - switch (ch) { - case '-': - flags |= FL_MINUS; - break; - - case '+': - flags |= FL_PLUS; - break; - - case '\'': - flags |= FL_TICK; - break; - - case ' ': - flags |= FL_SPACE; - break; - - case '#': - flags |= FL_HASH; - break; - - case '0': - flags |= FL_ZERO; - break; - - default: - state = st_width; - p--; /* Process this character again */ - break; - } - - break; - - case st_width: - if (ch >= '0' && ch <= '9') { - width = width * 10 + (ch - '0'); - } else if (ch == '*') { - width = va_arg(ap, int); - - if (width < 0) { - width = -width; - flags |= FL_MINUS; - } - } else if (ch == '.') { - prec = 0; /* Precision given */ - state = st_prec; - } else { - state = st_modifiers; - p--; /* Process this character again */ - } - - break; - - case st_prec: - if (ch >= '0' && ch <= '9') { - prec = prec * 10 + (ch - '0'); - } else if (ch == '*') { - prec = va_arg(ap, int); - - if (prec < 0) { - prec = -1; - } - } else { - state = st_modifiers; - p--; /* Process this character again */ - } - - break; - - case st_modifiers: - switch (ch) { - /* Length modifiers - nonterminal sequences */ - case 'h': - rank--; /* Shorter rank */ - break; - - case 'l': - rank++; /* Longer rank */ - break; - - case 'j': - rank = INTMAX_RANK; - break; - - case 'z': - rank = SIZE_T_RANK; - break; - - case 't': - rank = PTRDIFF_T_RANK; - break; - - case 'L': - case 'q': - rank += 2; - break; - - default: - /* Output modifiers - terminal sequences */ - - /* Next state will be normal */ - state = st_normal; - - /* Canonicalize rank */ - if (rank < MIN_RANK) { - rank = MIN_RANK; - } else if (rank > MAX_RANK) { - rank = MAX_RANK; - } - - switch (ch) { - case 'P': /* Upper case pointer */ - flags |= FL_UPPER; - __attribute__((fallthrough)); - - /* fall through */ - case 'p': /* Pointer */ - base = 16; - prec = (CHAR_BIT * sizeof(void *) + 3) / 4; - flags |= FL_HASH; - val = (uintmax_t)(uintptr_t) - va_arg(ap, void *); - goto is_integer; - - case 'd': /* Signed decimal output */ - case 'i': - base = 10; - flags |= FL_SIGNED; - - switch (rank) { - case rank_char: - /* Yes, all these casts are - needed... */ - val = (uintmax_t)(intmax_t)(signed char) - va_arg(ap, signed int); - break; - - case rank_short: - val = (uintmax_t)(intmax_t)(signed short) - va_arg(ap, signed int); - break; - - case rank_int: - val = (uintmax_t)(intmax_t) - va_arg(ap, signed int); - break; - - case rank_long: - val = (uintmax_t)(intmax_t) - va_arg(ap, signed long); - break; - - case rank_longlong: - val = (uintmax_t)(intmax_t) - va_arg(ap, - signed long long); - break; - - default: - break; - } - - goto is_integer; - - case 'o': /* Octal */ - base = 8; - goto is_unsigned; - - case 'u': /* Unsigned decimal */ - base = 10; - goto is_unsigned; - - case 'X': /* Upper case hexadecimal */ - flags |= FL_UPPER; - __attribute__((fallthrough)); - - /* fall through */ - case 'x': /* Hexadecimal */ - base = 16; - goto is_unsigned; - - is_unsigned: - - switch (rank) { - case rank_char: - val = (uintmax_t)(unsigned char) - va_arg(ap, unsigned int); - break; - - case rank_short: - val = (uintmax_t)(unsigned short) - va_arg(ap, unsigned int); - break; - - case rank_int: - val = (uintmax_t) - va_arg(ap, unsigned int); - break; - - case rank_long: - val = (uintmax_t) - va_arg(ap, unsigned long); - break; - - case rank_longlong: - val = (uintmax_t) - va_arg(ap, unsigned long long); - break; - - default: - break; - } - - /* fall through */ - - is_integer: - sz = format_int(q, (o < n) ? n - o : 0, - val, flags, base, - width, prec); - q += sz; - o += sz; - break; - - case 'c': /* Character */ - carg = (char)va_arg(ap, int); - sarg = &carg; - slen = 1; - goto is_string; - - case 's': /* String */ - sarg = va_arg(ap, const char *); - sarg = sarg ? sarg : "(null)"; - slen = strlen(sarg); - goto is_string; - - is_string : { - char sch; - int i; - - if (prec != -1 && slen > prec) { - slen = prec; - } - - if (width > slen && !(flags & FL_MINUS)) { - char pad = - (flags & FL_ZERO) ? - '0' : - ' '; - - while (width > slen) { - EMIT(pad); - width--; - } - } - - for (i = slen; i; i--) { - sch = *sarg++; - EMIT(sch); - } - - if (width > slen && (flags & FL_MINUS)) { - while (width > slen) { - EMIT(' '); - width--; - } - } - } break; - - case 'n': { - /* Output the number of - characters written */ - - switch (rank) { - case rank_char: - *va_arg(ap, - signed char *) = o; - break; - - case rank_short: - *va_arg(ap, - signed short *) = o; - break; - - case rank_int: - *va_arg(ap, - signed int *) = o; - break; - - case rank_long: - *va_arg(ap, - signed long *) = o; - break; - - case rank_longlong: - *va_arg(ap, - signed long long *) = o; - break; - - default: - break; - } - } break; -#ifdef BFLB_PRINT_FLOAT_SUPPORT - - case 'f': { - q = flt(q, va_arg(ap, double), width, prec, ch, SIGN); - continue; - } - -#endif - - default: /* Anything else, including % */ - EMIT(ch); - break; - } - } - - default: - break; - } - } - - /* Null-terminate the string */ - if (o < n) { - *q = '\0'; /* No overflow */ - } else if (n > 0) { - buffer[n - 1] = '\0'; /* Overflow - terminate at end of buffer */ - } - - return o; -} diff --git a/common/libc/src/vsprintf.c b/common/libc/src/vsprintf.c deleted file mode 100644 index 7434eadc..00000000 --- a/common/libc/src/vsprintf.c +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * vsprintf.c - */ - -#include -#include - -int vsprintf(char *buffer, const char *format, va_list ap) -{ - return vsnprintf(buffer, (~(unsigned int)0) >> 1, format, ap); -} diff --git a/common/libc/src/vsscanf.c b/common/libc/src/vsscanf.c deleted file mode 100644 index b4d74bec..00000000 --- a/common/libc/src/vsscanf.c +++ /dev/null @@ -1,470 +0,0 @@ -/* - * Derived from: - * http://www.kernel.org/pub/linux/libs/klibc/ - */ -/* - * vsscanf.c - * - * vsscanf(), from which the rest of the scanf() - * family is built - */ - -#include -#include -#include -#include -#include -#include -#include -//#include -#include - -#ifndef LONG_BIT -#define LONG_BIT (CHAR_BIT * sizeof(long)) -#endif - -enum flag { - FL_SPLAT = 0x01, /* Drop the value, do not assign */ - FL_INV = 0x02, /* Character-set with inverse */ - FL_WIDTH = 0x04, /* Field width specified */ - FL_MINUS = 0x08, /* Negative number */ -}; - -enum ranks { - rank_char = -2, - rank_short = -1, - rank_int = 0, - rank_long = 1, - rank_longlong = 2, - rank_ptr = INT_MAX /* Special value used for pointers */ -}; - -#define MIN_RANK rank_char -#define MAX_RANK rank_longlong - -#define INTMAX_RANK rank_longlong -#define SIZE_T_RANK rank_long -#define PTRDIFF_T_RANK rank_long - -enum bail { - bail_none = 0, /* No error condition */ - bail_eof, /* Hit EOF */ - bail_err /* Conversion mismatch */ -}; - -static __inline const char *skipspace(const char *p) -{ - while (isspace((unsigned char)*p)) { - p++; - } - - return p; -} - -#undef set_bit -static __inline void set_bit(unsigned long *bitmap, unsigned int bit) -{ - bitmap[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT); -} - -#undef test_bit -static __inline int test_bit(unsigned long *bitmap, unsigned int bit) -{ - return (int)(bitmap[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1; -} - -int vsscanf(const char *buffer, const char *format, va_list ap) -{ - const char *p = format; - char ch; - unsigned char uc; - const char *q = buffer; - const char *qq; - uintmax_t val = 0; - int rank = rank_int; /* Default rank */ - unsigned int width = UINT_MAX; - int base; - unsigned int flags = 0; - enum { - st_normal, /* Ground state */ - st_flags, /* Special flags */ - st_width, /* Field width */ - st_modifiers, /* Length or conversion modifiers */ - st_match_init, /* Initial state of %[ sequence */ - st_match, /* Main state of %[ sequence */ - st_match_range, /* After - in a %[ sequence */ - } state = st_normal; - char *sarg = NULL; /* %s %c or %[ string argument */ - enum bail bail = bail_none; - __UNUSED__ int sign; - int converted = 0; /* Successful conversions */ - unsigned long matchmap[((1 << CHAR_BIT) + (LONG_BIT - 1)) / LONG_BIT]; - int matchinv = 0; /* Is match map inverted? */ - unsigned char range_start = 0; - - while ((ch = *p++) && !bail) { - switch (state) { - case st_normal: - if (ch == '%') { - state = st_flags; - flags = 0; - rank = rank_int; - width = UINT_MAX; - } else if (isspace((unsigned char)ch)) { - q = skipspace(q); - } else { - if (*q == ch) { - q++; - } else { - bail = bail_err; /* Match failure */ - } - } - - break; - - case st_flags: - switch (ch) { - case '*': - flags |= FL_SPLAT; - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - width = (ch - '0'); - state = st_width; - flags |= FL_WIDTH; - break; - - default: - state = st_modifiers; - p--; /* Process this character again */ - break; - } - - break; - - case st_width: - if (ch >= '0' && ch <= '9') { - width = width * 10 + (ch - '0'); - } else { - state = st_modifiers; - p--; /* Process this character again */ - } - - break; - - case st_modifiers: - switch (ch) { - /* Length modifiers - nonterminal sequences */ - case 'h': - rank--; /* Shorter rank */ - break; - - case 'l': - rank++; /* Longer rank */ - break; - - case 'j': - rank = INTMAX_RANK; - break; - - case 'z': - rank = SIZE_T_RANK; - break; - - case 't': - rank = PTRDIFF_T_RANK; - break; - - case 'L': - case 'q': - rank = rank_longlong; /* long double/long long */ - break; - - default: - /* Output modifiers - terminal sequences */ - /* Next state will be normal */ - state = st_normal; - - /* Canonicalize rank */ - if (rank < MIN_RANK) { - rank = MIN_RANK; - } else if (rank > MAX_RANK) { - rank = MAX_RANK; - } - - switch (ch) { - case 'P': /* Upper case pointer */ - case 'p': /* Pointer */ - rank = rank_ptr; - base = 0; - sign = 0; - goto scan_int; - - case 'i': /* Base-independent integer */ - base = 0; - sign = 1; - goto scan_int; - - case 'd': /* Decimal integer */ - base = 10; - sign = 1; - goto scan_int; - - case 'o': /* Octal integer */ - base = 8; - sign = 0; - goto scan_int; - - case 'u': /* Unsigned decimal integer */ - base = 10; - sign = 0; - goto scan_int; - - case 'x': /* Hexadecimal integer */ - case 'X': - base = 16; - sign = 0; - goto scan_int; - - case 'n': /* # of characters consumed */ - val = (q - buffer); - goto set_integer; - - scan_int: - q = skipspace(q); - - if (!*q) { - bail = bail_eof; - break; - } - - val = - strntoumax(q, (char **)&qq, base, - width); - - if (qq == q) { - bail = bail_err; - break; - } - - q = qq; - - if (!(flags & FL_SPLAT)) { - converted++; - } - - /* fall through */ - - set_integer: - - if (!(flags & FL_SPLAT)) { - switch (rank) { - case rank_char: - *va_arg(ap, - unsigned char *) = val; - break; - - case rank_short: - *va_arg(ap, - unsigned short - *) = val; - break; - - case rank_int: - *va_arg(ap, - unsigned int *) = val; - break; - - case rank_long: - *va_arg(ap, - unsigned long *) = val; - break; - - case rank_longlong: - *va_arg(ap, - unsigned long long *) = val; - break; - - case rank_ptr: - *va_arg(ap, void **) = - (void *)(uintptr_t)val; - break; - - default: - break; - } - } - - break; - - case 'c': /* Character */ - /* Default width == 1 */ - width = (flags & FL_WIDTH) ? width : 1; - - if (flags & FL_SPLAT) { - while (width--) { - if (!*q) { - bail = bail_eof; - break; - } - } - } else { - sarg = va_arg(ap, char *); - - while (width--) { - if (!*q) { - bail = bail_eof; - break; - } - - *sarg++ = *q++; - } - - if (!bail) { - converted++; - } - } - - break; - - case 's': /* String */ - uc = 1; /* Anything nonzero */ - - if (flags & FL_SPLAT) { - while (width-- && (uc = *q) && - !isspace(uc)) { - q++; - } - } else { - char *sp; - sp = sarg = va_arg(ap, char *); - - while (width-- && (uc = *q) && - !isspace(uc)) { - *sp++ = uc; - q++; - } - - if (sarg != sp) { - /* Terminate output */ - *sp = '\0'; - converted++; - } - } - - if (!uc) { - bail = bail_eof; - } - - break; - - case '[': /* Character range */ - sarg = (flags & FL_SPLAT) ? NULL : va_arg(ap, char *); - state = st_match_init; - matchinv = 0; - memset(matchmap, 0, sizeof matchmap); - break; - - case '%': /* %% sequence */ - if (*q == '%') { - q++; - } else { - bail = bail_err; - } - - break; - - default: /* Anything else */ - /* Unknown sequence */ - bail = bail_err; - break; - } - } - - break; - - case st_match_init: /* Initial state for %[ match */ - if (ch == '^' && !(flags & FL_INV)) { - matchinv = 1; - } else { - set_bit(matchmap, (unsigned char)ch); - state = st_match; - } - - break; - - case st_match: /* Main state for %[ match */ - if (ch == ']') { - goto match_run; - } else if (ch == '-') { - range_start = (unsigned char)ch; - state = st_match_range; - } else { - set_bit(matchmap, (unsigned char)ch); - } - - break; - - case st_match_range: /* %[ match after - */ - if (ch == ']') { - /* - was last character */ - set_bit(matchmap, (unsigned char)'-'); - goto match_run; - } else { - int i; - - for (i = range_start; i < (unsigned char)ch; - i++) { - set_bit(matchmap, i); - } - - state = st_match; - } - - break; - - match_run: /* Match expression finished */ - qq = q; - uc = 1; /* Anything nonzero */ - - while (width && (uc = *q) && test_bit(matchmap, uc) ^ matchinv) { - if (sarg) { - *sarg++ = uc; - } - - q++; - } - - if (q != qq && sarg) { - *sarg = '\0'; - converted++; - } else { - bail = bail_err; - } - - if (!uc) { - bail = bail_eof; - } - - break; - - default: - break; - } - } - - if (bail == bail_eof && !converted) { - converted = -1; /* Return EOF (-1) */ - } - - return converted; -} diff --git a/common/misc/misc.h b/common/misc/misc.h index 27af8b0d..2b958fa8 100644 --- a/common/misc/misc.h +++ b/common/misc/misc.h @@ -23,11 +23,12 @@ #ifndef _MISC_H #define _MISC_H -#include "stdio.h" -#include "stdint.h" -#include "string.h" -#include "stdarg.h" -#include "stdbool.h" +#include +#include +#include +#include +#include +#include #include "gcc.h" /*@} end of group COMMON_Public_Types */ diff --git a/tools/cmake/compiler_flags.cmake b/tools/cmake/compiler_flags.cmake index 36da2981..9192ae05 100644 --- a/tools/cmake/compiler_flags.cmake +++ b/tools/cmake/compiler_flags.cmake @@ -8,9 +8,11 @@ list(APPEND GLOBAL_C_FLAGS -msmall-data-limit=4) list(APPEND GLOBAL_LD_FLAGS -Wl,--cref -Wl,--gc-sections -nostartfiles -g3) list(APPEND GLOBAL_LD_FLAGS -fms-extensions -ffunction-sections -fdata-sections) list(APPEND GLOBAL_LD_FLAGS -Wall -Wchar-subscripts -std=c99) +list(APPEND GLOBAL_LD_FLAGS --specs=nano.specs) + if(${SUPPORT_FLOAT} STREQUAL "y") -list(APPEND GLOBAL_C_FLAGS -DBFLB_PRINT_FLOAT_SUPPORT) +list(APPEND GLOBAL_LD_FLAGS -u _printf_float) endif() if(${SUPPORT_SHELL} STREQUAL "y") diff --git a/tools/cmake/tools.cmake b/tools/cmake/tools.cmake index f086fd0b..08f943d0 100644 --- a/tools/cmake/tools.cmake +++ b/tools/cmake/tools.cmake @@ -7,12 +7,6 @@ function(generate_library) # Add src to lib if(ADD_SRCS) target_sources(${library_name} PRIVATE ${ADD_SRCS}) - - foreach(f ${ADD_SRCS}) - if(${f} MATCHES ".S|.s") - set_property(SOURCE ${f} PROPERTY LANGUAGE C) - endif() - endforeach() endif() # Add global config include @@ -96,6 +90,9 @@ function(generate_bin) add_compile_options(${GLOBAL_C_FLAGS}) add_compile_options($<$:-std=c99>) add_compile_options($<$:-std=c++11>) + add_compile_options($<$:-nostdlib>) + add_compile_options($<$:-fno-rtti>) + add_compile_options($<$:-fno-exceptions>) check_all_library() @@ -134,6 +131,7 @@ function(generate_bin) endif() list(APPEND SRCS ${CMAKE_SOURCE_DIR}/bsp/bsp_common/platform/bflb_platform.c) + list(APPEND SRCS ${CMAKE_SOURCE_DIR}/bsp/bsp_common/platform/syscalls.c) list(APPEND SRCS ${CMAKE_SOURCE_DIR}/bsp/board/${BOARD}/board.c) add_executable(${target_name}.elf ${mainfile} ${SRCS}) @@ -159,13 +157,7 @@ function(generate_bin) add_dependencies(${target_name}.elf ${CHIP}_driver) # Add libs - target_link_libraries(${target_name}.elf ${CHIP}_driver) - - if(${SUPPORT_SHELL} STREQUAL "y") - target_link_libraries(${target_name}.elf shell) - else() - target_include_directories(${target_name}.elf PRIVATE ${CMAKE_SOURCE_DIR}/components/shell) - endif() + target_link_libraries(${target_name}.elf ${CHIP}_driver c) if(TARGET_REQUIRED_LIBS) target_link_libraries(${target_name}.elf ${TARGET_REQUIRED_LIBS}) @@ -233,6 +225,10 @@ function(check_all_library) check_add_library(freertos ${CMAKE_SOURCE_DIR}/components/freertos) endif() + if(${SUPPORT_CRYPTO} STREQUAL "sw" OR ${SUPPORT_CRYPTO} STREQUAL "hw") + check_add_library(bflb_port ${CMAKE_SOURCE_DIR}/components/mbedtls/bflb_port) + endif() + if(${SUPPORT_LVGL} STREQUAL "y") check_add_library(lvgl ${CMAKE_SOURCE_DIR}/components/lvgl) endif() @@ -248,4 +244,15 @@ function(check_all_library) check_add_library(ble ${CMAKE_SOURCE_DIR}/components/ble) endif() + if(${SUPPORT_LWIP} STREQUAL "y") + if(${SUPPORT_FREERTOS} STREQUAL "n") + message(FATAL_ERROR "lwip need freertos,so you should set SUPPORT_FREERTOS=y") + endif() + check_add_library(lwip ${CMAKE_SOURCE_DIR}/components/lwip) + endif() + + if(${SUPPORT_TFLITE} STREQUAL "y") + check_add_library(xz ${CMAKE_SOURCE_DIR}/components/tflite) + endif() + endfunction(check_all_library)