Commit Graph

269 Commits

Author SHA1 Message Date
guoshichao ddc6e31740 libc/fputwc: fix the return value truncated from stdio interface
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-21 02:57:43 +08:00
guoshichao ca1e007a22 wchar/lib_ungetwc: fix the array access out of bounds error
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-21 02:57:43 +08:00
guoshichao 9876b0b615 wchar/fgetwc: fix the return value truncate error
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-21 02:57:43 +08:00
guoshichao 390275f867 wchar/putwc: fix the putwc return value truncate error
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-21 02:57:43 +08:00
chenrun1 e15100543f lib_remove.c:fix code style error
Summary:
  Warning: /home/runner/work/nuttx/nuttx/nuttx/libs/libc/stdio/lib_remove.c:59:32: warning: Wrong column position of comment right of code

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-20 13:50:15 +08:00
chenrun1 0a4770b44a lib_remove:Repair the logical judgment
Summary:
  When the deleted path is a file, the return value of get_errno is -EISDIR, so in Condition Two
(get_errno() ! = EPERM && /* .... . try to remove it. */
       rmdir(path) ! = 0)
The judgment holds directly, so it can't actually execute to rmdir

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-20 13:50:15 +08:00
yanghuatao 681122bc23 toolchain/ghs: Fix green hills toolchain build Vela MIN_MANT error
"stdio/lib_dtoa_engine.c", line 102: error #166: invalid floating constant
        if (x < MIN_MANT)
                ^

"stdio/lib_dtoa_engine.c", line 102: warning #1626-D: concatenation with "("
          in macro "PASTE" does not create a valid token
        if (x < MIN_MANT)
                ^

"stdio/lib_dtoa_engine.c", line 102: error #109: expression preceding
          parentheses of apparent call must have (pointer-to-) function type
        if (x < MIN_MANT)
                ^

"stdio/lib_dtoa_engine.c", line 107: error #166: invalid floating constant
                if (y < MAX_MANT)
                        ^

"stdio/lib_dtoa_engine.c", line 107: warning #1626-D: concatenation with "("
          in macro "PASTE" does not create a valid token
                if (y < MAX_MANT)
                        ^

"stdio/lib_dtoa_engine.c", line 107: error #109: expression preceding
          parentheses of apparent call must have (pointer-to-) function type
                if (y < MAX_MANT)
                        ^

"stdio/lib_dtoa_engine.c", line 119: error #166: invalid floating constant
                if (y >= MIN_MANT)
                         ^

"stdio/lib_dtoa_engine.c", line 119: warning #1626-D: concatenation with "("
          in macro "PASTE" does not create a valid token
                if (y >= MIN_MANT)
                         ^

"stdio/lib_dtoa_engine.c", line 119: error #109: expression preceding
          parentheses of apparent call must have (pointer-to-) function type
                if (y >= MIN_MANT)
                         ^

"stdio/lib_dtoa_engine.c", line 144: error #166: invalid floating constant
        if (x >= MAX_MANT)
                 ^

"stdio/lib_dtoa_engine.c", line 144: warning #1626-D: concatenation with "("
          in macro "PASTE" does not create a valid token
        if (x >= MAX_MANT)
                 ^

"stdio/lib_dtoa_engine.c", line 144: error #109: expression preceding
          parentheses of apparent call must have (pointer-to-) function type
        if (x >= MAX_MANT)
                 ^

"stdio/lib_dtoa_engine.c", line 153: error #166: invalid floating constant
        uint64_t decimal = MIN_MANT_INT;
                           ^

"stdio/lib_dtoa_engine.c", line 153: warning #1626-D: concatenation with "("
          in macro "PASTE" does not create a valid token
        uint64_t decimal = MIN_MANT_INT;
                           ^

"stdio/lib_dtoa_engine.c", line 153: error #109: expression preceding
          parentheses of apparent call must have (pointer-to-) function type
        uint64_t decimal = MIN_MANT_INT;

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2024-08-19 10:37:54 +08:00
yanghuatao 2ae4ea3f99 toolchain/ghs: Fix green hills toolchain build Vela link error
[elxr] (error #412) unresolved symbols:
 __builtin_signbit     from libc.a(lib_dtoa_engine.o)

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2024-08-19 10:37:54 +08:00
buxiasen 7445c97c77 libc: scanf, printf %z change switch const to if
switch const will cause a switch_selector_expr_is_constant
warning catched by coverity.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-07-02 02:57:00 +08:00
hujun5 638716504d fdcheck: update fdcheck impl
1 store fd in the high position
2 removing the pid information , as the tag information is sufficient.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-04-11 10:45:44 +08:00
chao an d4d49e9645 stdio/file: unify group file list to common single queue
unify group file list to common single queue

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-18 19:32:49 +08:00
chao an 8ff97f6210 compiler/tasking: fix unreachable code on tasking toolchain
ctc W544: ["serial/serial.c" 284/3] unreachable code
ctc W544: ["vfs/fs_lseek.c" 96/13] unreachable code
ctc W544: ["wqueue/kwork_thread.c" 210/32] unreachable code
ctc W544: ["stdio/lib_fopen.c" 327/19] unreachable code
ctc W544: ["stdio/lib_fopen.c" 404/13] unreachable code
ctc W544: ["string/lib_strcasestr.c" 120/3] unreachable code
ctc W544: ["unistd/lib_getopt_common.c" 156/21] unreachable code
ctc W544: ["unistd/lib_getopt_common.c" 216/21] unreachable code
ctc W544: ["wctype/lib_iswctype.c" 155/3] unreachable code

Signed-off-by: chao an <anchao@lixiang.com>
2024-01-30 20:53:00 -08:00
guoshichao b3867d5230 libs/libc/wchar: add ungetwc implementation
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-12-17 01:39:06 -08:00
guoshichao 0b2f7f7f3c libs/libc/wchar: add getwc implementation
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-12-17 01:39:06 -08:00
guoshichao 8c37c3841b libs/libc/wchar: add fgetwc implementation
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-12-17 01:39:06 -08:00
Zhang Yang 4f9d014994 Fix -nan issue with f32 2023-12-01 18:49:46 -08:00
Michal Lenc eea7db24f3 libc: add support for open_memstream
Adds support for POSIX interface open_memstream() that allows writing
to dynamic memory buffer stream. The stream is dynamically reallocated
as the buffer grows with initial size set to zero.

The caller has to free the buffer after the stream is closed.

The implementation uses fopencookie() for custom stream operations and
callbacks.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2023-11-29 02:13:19 -08:00
PwnVerse e2627d4558 Fix improper handling of 64 bit types for libvsprintf 2023-11-15 18:37:43 -08:00
fengxuesong bb14e45ec9 the bug of sscanf exception output in arm64 platform
Signed-off-by: fengxuesong <fengxuesong@xiaomi.com>
2023-11-15 03:45:32 -08:00
Xiang Xiao 7aad7eebff libc: Change errno to set_errno and get_errno
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-29 17:16:09 +02:00
Xiang Xiao f911d3a1c3 stdio: Implement [clearerr|putc|fflush]_unlocked
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-29 17:09:18 +02:00
Xiang Xiao 2c9511e655 libc/stdio: Remove bforce from lib_fflush[_unlocked]
since all callers set bforce to true

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-29 17:09:18 +02:00
Xiang Xiao c3be772441 libc/stdio: lib_fwrite_unlocked must call lib_fflush_unlocked with true
otherwise the following file i/o mess up the output

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-29 17:09:18 +02:00
Michal Lenc 65ae8a545c libc: add support for memory buffer stream with fmemopen()
Add support for POSIX interface fmemopen(). This interface open a memory
buffer as a stream and permits access to this buffer specified by mode.
This allows I/O operations to be performed on the memory buffer.

The implementation uses fopencookie() for custom stream operations and
callbacks.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2023-10-27 08:55:24 +08:00
Xiang Xiao 1883b91e3c libc: Remove the unused lib_libdtoa.c
__dtoa is not used because currently NuttX uses other
function called __dtoa_engine() to do the same thing

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-23 20:06:34 -03:00
Xiang Xiao 66db15437d libc/stdio: Change FILE buffer field from "unsigned char *" to "char *"
to avoid the unnecessary casting

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-22 21:18:46 +03:00
Michal Lenc 0a107ca6d9 libc: add support for custom streams with fopencookie()
This commit adds support for custom stream via fopencookie function.
The function allows the programmer the create his own custom stream
for IO operations and hook his custom functions to it.

This is a non POSIX interface defined in Standard C library and implemented
according to it. The only difference is in usage of off_t instead of
off64_t. Programmer can use 64 bits offset if CONFIG_FS_LARGEFILE is
enabled. In that case off_t is defined as int64_t (int32_t otherwise).

Field fs_fd is removed from file_struct and fs_cookie is used instead
as a shared variable for file descriptor or user defined cookie.

The interface will be useful for future fmemopen implementation.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2023-10-18 21:13:01 +08:00
Xiang Xiao b1c8c84e81 stdio: Merge fs_fdopen into fdopen to simplify the code logi
since fs_fdopen could avoid call the kernel specific function now

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 13:34:00 +08:00
Xiang Xiao b0d197534f stdio: Move lib_stream_[initialize|release] from libc/stdio to sched/tls
both functions aren't suitable to be put into libc,
because they call the kernel internal functions directly.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 13:34:00 +08:00
guoshichao 5bd8e56cbe libs/libc/wchar: add fputws implementation
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-09-22 08:51:07 +08:00
guoshichao d67090c47e libs/libc/wchar: add putwc implementation
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-09-22 08:51:07 +08:00
guoshichao a9b2857754 libs/libc/wchar: add putwchar implementation
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-09-22 08:51:07 +08:00
guoshichao f8b5f613e2 libs/libc/wchar: add fputwc implementation
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-09-22 08:51:07 +08:00
Daniel Appiagyei 5bfda12634 c++ compatibility: rename reserved c++ keywords 'public' and 'this' 2023-09-16 19:45:02 +08:00
Ville Juven c178fa3260 stdio/lib_libfread: Fix buffer overflow issue
If the gulp size in the stdio buffer the remaining user buffer size it will:
- Corrupt memory in dest (user memory) and
- Keep corrupting KERNEL memory via the stdio character buffer until the
  whole system crashes, as the 'remaining' count underflows

This patch fixes this behavior.
2023-09-13 21:52:57 +08:00
dongjiuzhu1 5e3c1985e7 libc/fopen: support fopen with mode 'm'
refs:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html
This is a fake implementation, in order for fopen to succeed,
Because the complete mmap mapping the entire file will waste a lot of
memory.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-09-07 23:05:38 +08:00
SPRESENSE d4fbd7a190 libs/libc: Fix a fatal bug in fread
Fix a bug the destination buffer is not updated.
It is caused by the following commit.
commit 5d8d5bfd73
2023-09-07 17:44:31 +08:00
dongjiuzhu1 df98320c2c libs/libc: support unlock version for fread/fwrite/fputc/fgetc/...
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-09-06 15:08:24 +03:00
dongjiuzhu1 e8842f59da libs/libc: remove unnecessary flockfile to improve performance
modify lib_wrflush/lib_rdflush/lib_ffulsh to unlocked version

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-09-06 15:08:24 +03:00
Stuart Ianna 5d8d5bfd73 libc/libfread: Use memcpy to copy read-ahead buffer to caller buffer.
This change improves the performance when using larger CONFIG_STDIO_BUFFER_SIZE values as it allows architecture specific, or optimized memcpy algorithms to be utilized.

Link: https://git.motec.com.au/id/I317dc4da266aed1ce0f1b5f9a609759e863b9005
2023-08-24 11:19:54 +08:00
yinshengkai 26fc59bc35 libc/stdio: changed LIBC_NL_ARGMAX default value to 9
If LIBC_NL_ARGMAX is too large, the stack usage of printf family functions will increase

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-03 19:07:22 -07:00
yinshengkai fe9251b546 libc: export lib_sprintf_internal function
This function does not take numbered arguments in printf

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-07-14 00:22:11 +03:00
yinshengkai 135959eb83 libc/printf: fix "%pS" length error
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-07-14 00:22:11 +03:00
chao an 8277229f53 nxstyle: covert utf-8 to ascii
libs/libc/stdio/lib_libgetstreams.c: C source, UTF-8 Unicode text
->
libs/libc/stdio/lib_libgetstreams.c: C source, ASCII text

Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-14 01:24:50 +08:00
Xiang Xiao ebcb03dce9 libc/symtab: Don't include symtab.h in the header files
to unify the inclusion of symtab.h only from the source files

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-10 23:03:17 +03:00
Sunny 9856eae61f libc/libvsprintf: fix vsnprintf bug with "%e"
For "%e" conversion, the exponent always contains at least two digits.
That means if the value is zero, the exponent is 00, not 0.

Such as code:
  printf(buffer, sizeof(buffer), "%e", 1.232323232323);
  printf(buffer, sizeof(buffer), "%e", 12.32323232323);
  printf(buffer, sizeof(buffer), "%e", 123.2323232323);

Expected output:
  1.232323e+00
  1.232323e+01
  1.232323e+02

But real output:
  1.232323e+0
  1.232323e+1
  1.232323e+2

Signed-off-by: Sunny <zxcvbnm37425@gmail.com>
2023-07-09 01:50:41 +08:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
Sunny abfdffd879 libc/libvsprintf:fix vsnprintf bug with "%#.0f"
With double value=3.141593 initialized in va_list ap,
such code:
   vsnprintf(buffer, sizeof(buffer), "%#.0f", ap);
expected output string: "3."
but real output string: ".3"

Signed-off-by: Sunny <zxcvbnm37425@gmail.com>
2023-07-04 10:36:31 -03:00
Mingjie Shen f5a2741ec2 libc/lib_remove: fix TOCTOU race condition
Separately checking the state of a file before operating on it may allow
an attacker to modify the file between the two operations.

Reference:
  CWE-367
  4290aed051/sysdeps/posix/remove.c (L29-L41)

Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2023-06-29 18:15:06 +08:00
chao an fb9b41221d semantic/parser: fix compile warning found by sparse
Reference:
https://linux.die.net/man/1/sparse

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-30 23:00:00 +08:00