aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc
AgeCommit message (Collapse)AuthorFilesLines
2020-09-04loadlocale: don't casecmp digitsCorinna Vinschen1-1/+1
strcmp is sufficient here Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-09-03Fix warnings when building for msp430-elfJozef Lawrynowicz6-16/+24
The MSP430 target supports both 16-bit and 20-bit size_t and intptr_t. Some implicit casts in Newlib expect these types to be "long", (a 32-bit type on MSP430) which causes warnings during compilation such as: "cast from pointer to integer of different size"
2020-08-25Enabled _CS* defines for RTEMSEshan dhawan via Newlib1-1/+2
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-08-17libm/stdlib: Realloc when shrinking by 2* or moreKeith Packard via Newlib1-3/+3
This reduces memory usage when reallocating objects much smaller. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-17libm/stdlib: don't read past source in nano_reallocKeith Packard via Newlib1-2/+4
Save the computed block size and use it to avoid reading past the end of the source block. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-13libc/stdlib: Fix build failure in nano_callocCraig Blackmore1-2/+2
commit 588a5e1ddebdf6d74391c7409680ea20e050c0e1 added a non-reentrant call to nano_malloc which causes a build failure if INTERNAL_NEWLIB is defined. Here is a snippet of the error: In file included from .../newlib/newlib/libc/stdlib/nano-mallocr.c:38: .../newlib/newlib/libc/include/malloc.h:42:25: note: expected 'struct _reent *' but argument is of type 'ptrdiff_t' {aka 'int'} 42 | extern void *_malloc_r (struct _reent *, size_t); | ^~~~~~~~~~~~~~~ .../newlib/newlib/libc/stdlib/nano-mallocr.c:67:22: error: too few arguments to function '_malloc_r' 67 | #define nano_malloc _malloc_r | ^~~~~~~~~ .../newlib/newlib/libc/stdlib/nano-mallocr.c:456:11: note: in expansion of macro 'nano_malloc' 456 | mem = nano_malloc(bytes); | ^~~~~~~~~~~ In file included from .../newlib/newlib/libc/stdlib/nano-mallocr.c:38: .../newlib/newlib/libc/include/malloc.h:42:14: note: declared here 42 | extern void *_malloc_r (struct _reent *, size_t); | ^~~~~~~~~ .../newlib/newlib/libc/stdlib/nano-mallocr.c:43: warning: "assert" redefined 43 | #define assert(x) ((void)0) | This patch adds a missing RCALL to the args when calling nano_malloc from nano_calloc, so that if the call is reentrant, reent_ptr is passed as the first argument. The variable `bytes` (also added in 588a5e1d) has been changed from a `ptrdiff_t` to `malloc_size_t` as it does not need to be signed. It is used to store the product of two unsigned malloc_size_t variables and then iff there was no overflow is it passed to malloc and memset which both expect size_t which is unsigned. Signed-off-by: Craig Blackmore <craig.blackmore@embecosm.com>
2020-08-12libc/stdlib: Use __builtin_mul_overflow for reallocarray and callocKeith Packard via Newlib3-15/+22
This built-in function (available in both gcc and clang) is more efficient and generates shorter code than open-coding the test. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-05libm: Control errno support with _IEEE_LIBM configuration parameterKeith Packard via Newlib1-16/+0
This removes the run-time configuration of errno support present in portions of the math library and unifies all of the compile-time errno configuration under a single parameter so that the whole library is consistent. The run-time support provided by _LIB_VERSION is no longer present in the public API, although it is still used internally to disable errno setting in some functions. Now that it is a constant, the compiler should remove that code when errno is not supported. This removes s_lib_ver.c as _LIB_VERSION is no longer variable. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-04libm: Set math_errhandling to match library and hardware [v2]Keith Packard via Newlib2-1/+22
math_errhandling is specified to contain two bits of information: 1. MATH_ERRNO -- Set when the library sets errno 2. MATH_ERREXCEPT -- Set when math operations report exceptions MATH_ERRNO should match whether the original math code is compiled in _IEEE_LIBM mode and the new math code has WANT_ERRNO == 1. MATH_ERREXCEPT should match whether the underlying hardware has exception support. This patch adds configurations of this value for RISC-V, ARM, Aarch64, x86 and x86_64 when using HW float. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-03select.h: update FD macros to latest FreeBSD, fix type conversion warningCorinna Vinschen1-27/+41
Compiling #include <sys/select.h> void f(int X) {   fd_set set;   FD_ZERO(&set);   FD_SET(X,&set);   FD_CLR(X+1,&set);   (void)FD_ISSET(X+2,&set); } results in plenty of gcc warnings when compiled with -Wconversion -Wsign-conversion: fds.c:7:2: warning: conversion to ‘long unsigned int’ from ‘int’ may   FD_SET(X,&set);   ^~~~~~ [...] The unsigned NFDBITS macro combined with the signed 1L constant are causing lots of implicit signed/unsigned type conversions. Fix this by updating the FD_* macro code to the latest from FreeBSD and adding an (int) cast to _NFDBITS. As a side-effect, this fixes the visibility of NFDBITS and fds_bits (only if __BSD_VISIBLE). This also eliminates the old, outdated fd_set workaround. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-03Cygwin: posix_spawn: add Cygwin-specific code fixing process synchronisationCorinna Vinschen1-0/+64
Newlib's posix_spawn has been taken from FreeBSD. The code relies on BSD-specific behaviour of vfork, namely the fact that vfork blocks the parent until the child exits or calls execve as well as the fact that the child shares parent memory in non-COW mode. This behaviour can't be emulated by Cygwin. Cygwin's vfork is equivalent to fork. This is POSIX-compliant, but it's lacking BSD's vfork ingrained synchronization of the parent to wait for the child calling execve, or the chance to just write a variable and the parent will see the result. So this requires a Cygwin-specific solution. The core function of posix_spawn, called do_posix_spawn is now implemented twice, once using the BSD method, and once for Cygwin using Windows synchronization under the hood waiting for the child to call execve and signalling errors upstream. The Windows specifics are hidden inside Cygwin, so newlib only calls internal Cygwin functions. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-29arm: Fix fenv supportEshan dhawan4-476/+17
The previous fenv support for ARM used the soft-float implementation of FreeBSD. Newlib uses the one from libgcc by default. They are not compatible. Having an GCC incompatible soft-float fenv support in Newlib makes no sense. A long-term solution could be to provide a libgcc compatible soft-float support. This likely requires changes in the GCC configuration. For now, provide a stub implementation for soft-float multilibs similar to RISC-V. Move implementation to one file and delete now unused files. Hide implementation details. Remove function parameter names from header file to avoid name conflicts. Provide VFP support if __SOFTFP__ is not defined like glibc. Reviewed-by: Sebastian Huber <sebastian.huber@embedded-brains.de> Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-07-27riscv: fix integer wraparound in memcpyPkmX via Newlib1-2/+2
This patch fixes a bug in RISC-V's memcpy implementation where an integer wraparound occurs when src + size < 8 * sizeof(long), causing the word-sized copy loop to be incorrectly entered. Signed-off-by: Chih-Mao Chen <cmchen@andestech.com>
2020-07-16ctype.h: Fix unused variable warningsAschref Ben Thabet1-4/+9
If __HAVE_LOCALE_INFO__ is not defined, then the locale in the locale-specific ctype functions is ignored. In the previous implementation this resulted in compiler warnings. For example: int main() { locale_t locale; locale = duplocale(uselocale((locale_t)0)); isspace_l('x', locale); return 0; } gcc -Wall main.c main.c: In function 'main': main.c:6:11: warning: variable 'locale' set but not used [-Wunused-but-set-variable] 6 | locale_t locale; | ^~~~~~
2020-07-10libc/iconv: find_alias was mis-computing remaining alias table lengthKeith Packard via Newlib1-1/+1
This caused the strnstr to walk off the end of the alias array and fetch invalid data. Instead of attempting to update 'len', just re-compute it based on the table end pointer that is already known. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-07-10libc/iconv: Remove unneeded pointer var for _iconv_aliasesKeith Packard via Newlib2-6/+3
The pointer value for the iconv alias data never changes, so get rid of the pointer and make it an array instead. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-07-10libc/iconv: Detect CES handler loading failureKeith Packard via Newlib1-1/+1
Fix the code checking for character set loading failure so that it checks the return value from the init function. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-07-06Removed #ifndef _ARM_PCS_VFP_ from sys/fenv.h for armEshan dhawan via Newlib1-2/+2
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-07-03mips fenv supportEshan dhawan via Newlib3-0/+477
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-07-03SPARC fenv supportEshan dhawan via Newlib1-0/+85
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-07-02fenv aarch64 supportEshan dhawan via Newlib2-0/+276
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-06-09fenv support armEshan dhawan via Newlib5-0/+731
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-06-03hard float support for PowerPC taken from FreeBSDEshan dhawan via Newlib2-0/+330
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-05-19Reimplement aligned_allocSzabolcs Nagy1-32/+30
The original implementation had multiple issues: - Only worked when posix_memalign was available (Linux, RTEMS). - Violated C11 link namespace rules by calling posix_memalign. - Failed to set errno on error. These can be fixed by essentially using the same implementation for aligned_alloc as for memalign, i.e. simply calling _memalign_r (which is always available and a "more reserved name" although technically still not in the reserved link namespace, at least code written in c cannot define a colliding symbol, newlib has plenty such namespace issues so this is fine). It is not clear what the right policy is when MALLOC_PROVIDED is set, currently that does not cover aligned_alloc so it is kept that way. Tested on aarch64-none-elf
2020-03-13RTEMS: Include missing header and fix stubSebastian Huber1-1/+2
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2020-03-02arm: Finish moving newlib to unified syntax for Thumb1Richard Earnshaw1-7/+8
Most code in newlib already uses unified syntax, but just a couple of laggards remain. This patch removes these and means the the entire code base has now been converted.
2020-02-20newlib/libc/include/devctl.h: Add extern "C" wrapperJoel Sherrill1-0/+8
Adding this was necessary to allow posix_devctl() from C++.
2020-02-18Locale modifier "@cjksingle" to enforce single-width CJK width.Thomas Wolff2-4/+17
This option follows a proposal in the Terminals Working Group Specifications (https://gitlab.freedesktop.org/terminal-wg/specifications/issues/9#note_406682). It makes locale width consistent with the corresponding mintty feature.
2020-02-06Typo in license for newlib/libc/stdio/flags.cKeith Packard1-1/+1
Fix spelling: MERCHANT I BILITY -> MERCHANT A BILITY Signed-off-by: Keith Packard <keithp@keithp.com>
2020-01-29Use remove-advertising-clause script to edit BSD licensesKeith Packard274-924/+281
This edits licenses held by Berkeley and NetBSD, both of which have removed the advertising requirement from their licenses. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-01-29Revert "newlib: fix fseek optimization with SEEK_CUR"Corinna Vinschen2-12/+50
This reverts commit 59362c80e3a02c011fd0ef3d7f07a20098d2a9d5. This breaks gnulib's autoconf test for POSIX compatibility of fflush/fseek. After fflush/fseek, ftello and lseek are out of sync, with lseek having the wrong offset. This breaks backward compatibility with Cygwin applications. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-01-21Bump up newlib release to 3.3.0Jeff Johnston95-950/+950
2020-01-21riscv: Map between ieeefp.h exception bits and RISC-V FCSR bitsKeith Packard1-3/+37
If we had architecture-specific exception bits, we could just set them to match the processor, but instead ieeefp.h is shared by all targets so we need to map between the public values and the register contents. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-01-21riscv: Add 'break' statements to fpsetround switchKeith Packard1-4/+4
This makes the fpsetround function actually do something rather than just return -1 due to the default 'fall-through' behavior of the switch statement. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-01-21riscv: Use current pseudo-instructions to access the FCSR registerKeith Packard1-2/+2
Use fscsr and frcsr to store and read the FCSR register instead of fssr and frsr. Signed-off-by: Keith Packard <keithp@keithp.com>
2020-01-09Prevent more NULL ptr accesses due to Balloc out of memoryJeff Johnston3-9/+9
- fix gdtoa-gethex.c, ldtoa.c, and strtodg.c to use eBalloc
2020-01-02Bump up release to 3.2.0 for yearly snapshotnewlib-snapshot-20200102newlib-3.2.0Jeff Johnston95-950/+950
2019-12-20Optimize setjmp/longjmp for moxie.Anthony Green2-87/+39
We don't need to save/restore every register -- just those we don't expect to be trashed by function calls.
2019-12-18Don't display trailing '.' in _dcvtKeith Packard1-3/+12
In the two helper functions that _dcvt calls for 'f' and 'e' mode, if there are no digits to display after the decimal point, don't add one. Signed-off-by: Keith Packard <keithp@keithp.com>
2019-12-18Fix gcvt to always show 'ndigits' of precisionKeith Packard1-11/+7
Leading zeros after the decimal point should not count towards the 'ndigits' limit. This makes gcvt match glibc and the posix gcvt man page. Signed-off-by: Keith Packard <keithp@keithp.com>
2019-12-18Fix fcvt to only show 'ndigit' past decimalKeith Packard1-8/+1
Even if the number is really small and this means showing *no* digits. This makes newlib match glibc, and the fcvt posix man page. Signed-off-by: Keith Packard <keithp@keithp.com>
2019-12-17Set __IEEE_LITTLE_ENDIAN for _XTENSA_EL__ (ESP32)Keith Packard1-0/+4
Signed-off-by: Keith Packard <keithp@keithp.com>
2019-12-17Return EINVAL for illegal base in strtolKeith Packard1-2/+7
Signed-off-by: Keith Packard <keithp@keithp.com>
2019-12-16strtold: set errno to ERANGE on underflow per POSIXBruno Haible1-0/+21
https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtod.html
2019-12-13Fix setjmp/longjmp for the moxie port.Anthony Green2-25/+48
These functions needs to save and restore the stack frame, because that's where the return address is stored.
2019-11-26newlib/libc/include/sys/features.h: update __STDC_ISO_10646__Brian Inglis1-3/+7
newlib wide char conversion functions were updated to Unicode 11 on 2019-01-12 update standard symbol __STDC_ISO_10646__ to Unicode 11 release date 2018-06-05 for Cygwin
2019-11-18newlib: fix fseek optimization with SEEK_CURBastien Bouclet2-50/+12
The call to fflush was invalidating the read buffer, preventing relative seeks to positions that would have been inside the read buffer from being optimized. The call to srefill would then re-read mostly the same data that was initially in the read buffer.
2019-11-08Stash reent marker in upper bits of s1 on AMD GCNKwok Cheung Yeung1-10/+10
s[0:3] contain a descriptor used to set up the initial value of the stack, but only the lower 48 bits of s[0:1] are currently used. The reent marker is currently set in s3, but by stashing it in the upper 16 bits of s[0:1] instead, s3 can be freed up for other purposes.
2019-11-04Move timeval macros to <sys/time.h>Sebastian Huber2-32/+31
In FreeBSD, NetBSD, and OpenBSD these macros are defined in <sys/time.h>.
2019-11-04Synchronize <sys/time.h> with FreeBSDSebastian Huber1-0/+27
This change is based on the FreeBSD commit: Author: asomers <asomers@FreeBSD.org> Date: Mon Jul 30 15:46:40 2018 +0000 Make timespecadd(3) and friends public The timespecadd(3) family of macros were imported from NetBSD back in r35029. However, they were initially guarded by #ifdef _KERNEL. In the meantime, we have grown at least 28 syscalls that use timespecs in some way, leading many programs both inside and outside of the base system to redefine those macros. It's better just to make the definitions public. Our kernel currently defines two-argument versions of timespecadd and timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define three-argument versions. Solaris also defines a three-argument version, but only in its kernel. This revision changes our definition to match the common three-argument version. Bump _FreeBSD_version due to the breaking KPI change. Discussed with: cem, jilles, ian, bde Differential Revision: https://reviews.freebsd.org/D14725