Commit Graph

1173 Commits

Author SHA1 Message Date
yinshengkai
81a4f21f1b libc/libvsprintf: use puts to replace the putc
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-03-08 16:56:17 +08:00
yinshengkai
b8e622ea5d libc/stream: unify stream behavior
Return the error code when all gets occur when an error is wrong
and return immediately when obtaining any valid data

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-03-04 01:48:22 +08:00
yinshengkai
205ca26556 libc/streams: Implement gets/puts for all streams
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-03-03 00:49:04 +08:00
Huang Qi
dfc70b1ddb libc/stdio: Implement lib_get_stream
Use lib_get_stream() to fetch stdin/stdout/stderr,
since is more easy to works with other language by function call
than export native C structure memory layout.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-03-02 09:56:57 +01:00
Huang Qi
b99a96a7d0 stream: Exchange name of lib_rawsostream.c and lib_rawoutstream.c
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-03-01 10:07:36 -03:00
Huang Qi
b96035885a stdio: Implement simple buffered out stream for vdprintf
Improve performance for raw fd based printf like operation.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-03-01 13:08:59 +09:00
Xiang Xiao
2c5f653bfd Remove the tail spaces from all files except Documentation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-26 13:24:24 -08:00
yinshengkai
8d16fa04df libc/stream: Implement lowoutstream_puts
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-02-25 18:39:27 +08:00
chenrun1
4f3c73fb45 libc/lib_bzero:Add bzero prototype.
Implement the bzero function as an alternative to macro expansion.
2023-02-25 08:07:07 +02:00
lilei19
38f64f559d change strcpy to strlcpy
Signed-off-by: lilei19 <lilei19@xiaomi.com>
2023-02-24 12:15:40 +08:00
Xiang Xiao
68ff73c5fb stdio: lib_fgets convert \r\n to \n
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-24 10:39:48 +08:00
Xiang Xiao
cd74a1df22 libc/stdio: Make gets/gets_s work without CONFIG_FILE_STREAM
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-24 10:39:48 +08:00
chenrun1
5430de72f8 libc/lib_rawmemchr.c:Add rawmemchr methon. 2023-02-24 04:06:04 +08:00
Huang Qi
ca61c40453 stdio: Remove CONFIG_EOL_IS_XXX
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-02-24 00:35:19 +08:00
Xiang Xiao
8b4ecac6c2 libc: Move math library from libs/libc/math to libs/libm/libm
to prepare the support of other implementation e.g.:
https://github.com/JuliaMath/openlibm
https://gitlab.com/gtd-gmbh/libmcs

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-23 10:40:07 +02:00
chao an
0f8ecc0150 libs/libc: export exit() if configured in flat mode
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-23 13:50:03 +08:00
Xiang Xiao
a05ab2ab49 libc: Remove dependence of LIBC_FLOATINGPOINT and LIBC_LONG_LONG from LIBC_NUMBERED_ARGS
since LIBC_NUMBERED_ARGS can work without both

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-22 16:37:48 +08:00
lilei19
e6e2017d3c fix a bug of strtof 2023-02-22 01:20:21 +08:00
Ville Juven
f8d3032732 libc/lib_assert.c: Remove the re-definition of abort()
This should now be irrelevant, as abort() is forwarded to _exit() instead.
2023-02-22 01:10:39 +08:00
Ville Juven
07039b8a36 lib_abort.c: Change call to userspace exit() into syscall _exit()
The POSIX standard dictates that during abnormal termination the functions
registered by atexit() are _not_ called, also flushing the streams is
optional. So in this case, it is perfectly legal / better to call the
kernel system call _exit() instead.

This fixes regression issues caused by removal exit() from the kernel.
2023-02-22 01:10:39 +08:00
Xiang Xiao
fa3e0faffc fs: Map FD_SETSIZE to OPEN_MAX instead hardcoding 256
and change the default value of LIBC_OPEN_MAX to 256.
Here has more discussion:
https://www.mail-archive.com/dev@nuttx.apache.org/msg09095.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-19 19:17:20 +02:00
Ville Juven
e9ef70e24b sched/assert: Call abort() instead of exit() in assert
POSIX dictates that assert() terminates via abort(), even though in NuttX
abort() just calls exit(EXIT_FAILURE) it is better to use the correct
API here, if at some point a proper implementation for abort() is made.

Also, as the kernel must not use abort() which is a userspace API, direct
the exit to PANIC() if for some reason _assert() returns (it should not
but trap it here just in case).
2023-02-17 23:07:17 +08:00
Ville Juven
df1d7dd480 libc/exit: Purge calls to userspace API exit() from kernel
Remove calls to the userspace API exit() from the kernel. The problem
with doing such calls is that the exit functions are called with kernel
mode privileges which is a big security no-no.
2023-02-17 23:07:17 +08:00
Fotis Panagiotopoulos
85ceb7920e Typo fixes. 2023-02-17 11:17:11 -03:00
Takeyoshi Kikuchi
70ce4b4fc1 libc: unistd: lib_getrlimit: set cur/max value for RLIMIT_NOFILE to "OPEN_MAX".
Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>
2023-02-17 18:07:30 +08:00
Takeyoshi Kikuchi
c4fc414b09 libc: unistd: lib_getrlimit: use INT_MAX as dummy rlim_max value.
Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>
2023-02-17 18:07:30 +08:00
Takeyoshi Kikuchi
2e5a20612c libc: unistd: lib_getrlimit: return a value for RLIMIT_NOFILE request.
In the Nim language "selectors"(I/O multiplexing) module, the maximum
number of file descriptors is obtained with getrlimit() as follows.

        var fdLim: RLimit
        var res = int(getrlimit(RLIMIT_NOFILE, fdLim))
        if res >= 0:
          res = int(fdLim.rlim_cur) - 1

To be able to use the same implementation as other POSIX-based OS,
getrlimit() should return a value.
(For now, let it return 128.)

Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>
2023-02-17 18:07:30 +08:00
crafcat7
33b22f51da libc/lib_memcpy.c: Add mempcpy method.
Signed-off-by: crafcat7 <chenrun1@xiaomi.com>
2023-02-17 15:15:19 +08:00
Nathan Hartman
409e2f3701 drivers/serial, libc/termios: Implement tcsendbreak
The TERMIOS(3) function tcsendbreak() and the IOCTLs TCSBRK and TCSBRKP
transmit a serial line Break.

Previously NuttX included an extern declaration for tcsendbreak() and
defines for TCSBRK and TCSBRKP but none of these were implemented.
Attempting to build programs that called tcsendbreak() would fail with
a linker error; attempting to use TCSBRK and TCSBRKP would result in an
error at runtime.

This changeset adds the tcsendbreak() function and handling for TCSBRK
and TCSBRKP; tcsendbreak() is implemented in terms of TCSBRK. Both
TCSBRK and TCSBRKP are implemented in terms of the BSD-compatible Break
IOCTLs TIOCSBRK and TIOCCBRK, which must be provided by the lower half
serial driver. Currently, not all lower half serial drivers in NuttX
support these IOCTLs. Those that do implement them may need one or more
Kconfig options to be set, such as `CONFIG_*_U[S]ART_BREAKS` and, on
some architectures, a separate `CONFIG_*_SERIALBRK_BSDCOMPAT`.

* drivers/serial/serial.c
  (uart_tcsendbreak): New function.
  (uart_ioctl): Implement TCSBRK and TCSBRKP.

* libs/libc/termios/lib_tcsendbreak.c
  (): New file.

* libs/libc/termios/Make.defs
  (CSRCS): Add lib_tcsendbreak.c to the build.

Thanks to Xiang Xiao for PR feedback.

Co-authored-by: Xiang Xiao <xiaoxiang781216@gmail.com>
2023-02-15 07:50:02 +08:00
Xiang Xiao
dc2e9b8771 libc: Move memfd related stuff to sys/mman.h
follow the freebsd definition:
https://github.com/freebsd/freebsd-src/blob/master/sys/sys/mman.h#L207-L228

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-13 16:00:37 +01:00
Huang Qi
a66f0a6369 stdlib: Guard fflush in exit with CONFIG_FILE_STREAM
If CONFIG_FILE_STREAM disabled, fflush is a undefined function.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-02-12 00:09:29 +08:00
lilei19
23344846f6 fix some bug of strtold
with the test of sim:lua ,I have fixed some bug of error output
  1.input: "  " and error output string is "NULL"
  2.input: "1.2e+", error output string is "NULL"
  3.input: "."      error output string is "NULL"
2023-02-10 22:45:24 +08:00
chao an
634baa5a2f libs: workaround for Visual Studio(MSVC) Compiler Error C2124
D:\archer\code\nuttx\libs\libc\stdlib\lib_strtod.c: error C2124: divide or mod by zero

Windows MSVC restrictions, MSVC doesn't allow division through a
zero literal, but allows it through const variable set to zero

Reference:
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2124?view=msvc-170

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:11:55 +08:00
chao an
8761cc9bfc libs: fix visual studio Compiler Error C2036
D:\code\nuttx\libs\libc\net\lib_inetpton.c(300,52): error C2036: "void *" : unknown size

Reference:
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2036?view=msvc-170

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:11:55 +08:00
chao an
e942a7c55e build/Kconfig: fix warnings detected by kconfiglib
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:07:46 +08:00
chao an
3a0fdb019d nuttx: replace all ARRAY_SIZE()/ARRAYSIZE() to nitems()
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:05:44 +08:00
dongjiuzhu1
14f8a6c2dd fs: support openat/fchmodat/mkfifoat/fstatat/...at api
Refs to:
https://linux.die.net/man/2/openat

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-02-07 03:45:38 +08:00
lilei19
de21025702 fix a bug of strtold
if input is -1e308,The output should be -100000000......
  but the output is -inf
2023-02-06 20:26:45 +08:00
chao an
02a9e76f73 misc/mutex: fix assertion if nxmutex_reset() before nxmutex_unlock()
sim/rpserver

NuttShell (NSH) NuttX-12.0.0
server> cu
_assert: Current Version: NuttX server 12.0.0 3ead669e7a-dirty Feb  2 2023 23:53:48 sim
_assert: Assertion failed : at file: libs/libc/misc/lib_mutex.c:303 task: cu 0x5662fff4

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-04 02:13:15 +08:00
chao an
7625126c91 Remove the remain MIN/MAX like macro
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-03 23:22:41 +08:00
yinshengkai
35ae47788b libc: Keep printf("%pS", p) behavior consistent
When ALLSYMS is not turned on, %pS will be treated as %p

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-02-03 09:19:06 +02:00
chao an
4c8d244fae sched/getpid: replace syscall getpid/tid/ppid() to kernel version
NuttX kernel should not use the syscall functions, especially after
enabling CONFIG_SCHED_INSTRUMENTATION_SYSCALL, all system functions
will be traced to backend, which will impact system performance.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-02 10:33:01 +08:00
chao an
c9981036a5 nuttx/mutex: move mutex implement to libc
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-02 10:33:01 +08:00
Gustavo Henrique Nihei
e6b204f438 nuttx: Use MIN/MAX definitions from "sys/param.h"
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-02-01 23:47:44 +08:00
Huang Qi
4caf24a00c libc/stdio: Minor comments fix
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-02-01 21:47:30 +08:00
yinshengkai
ab2b09e557 Revert "Makefile: fix redundant delimiters when using make V=1"
This reverts commit 64d39a8b7b.
2023-02-01 20:39:52 +08:00
Nathan Hartman
c65a632788 libc/termios: Fix comment in cfmakeraw docstring. 2023-02-01 09:47:55 +08:00
yinshengkai
64d39a8b7b Makefile: fix redundant delimiters when using make V=1
rm-none-eabi-ar rcs  libc.a    bin//lib_assert.o  bin//lib_builtin_getname.o
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-01-31 15:12:36 -03:00
Zhe Weng
8819eeaf15 net: Implement shutdown() interface and tcp shutdown
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-31 11:15:01 +08:00
lilei19
1d8af7e105 add holder for mutex
Signed-off-by: lilei19 <lilei19@xiaomi.com>
2023-01-31 12:08:05 +09:00