Skip to content

Commit a206ee6

Browse files
committed
libc: minimal: stubs getc_unlocked & getchar_unlocked
Add stub implementation and test for `getc_unlocked()` & `getchar_unlocked()`. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
1 parent 778629e commit a206ee6

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

doc/services/portability/posix/option_groups/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ This table lists service support status in Zephyr for `POSIX_FD_MGMT`:
567567
flockfile(), yes
568568
ftrylockfile(), yes
569569
funlockfile(), yes
570-
getc_unlocked(),
571-
getchar_unlocked(),
570+
getc_unlocked(), yes :ref:`†<posix_undefined_behaviour>`
571+
getchar_unlocked(), yes :ref:`†<posix_undefined_behaviour>`
572572
putc_unlocked(), yes
573573
putchar_unlocked(), yes
574574

@@ -904,8 +904,8 @@ _POSIX_THREAD_SAFE_FUNCTIONS
904904
flockfile(), yes
905905
ftrylockfile(), yes
906906
funlockfile(), yes
907-
getc_unlocked(),
908-
getchar_unlocked(),
907+
getc_unlocked(), yes :ref:`†<posix_undefined_behaviour>`
908+
getchar_unlocked(), yes :ref:`†<posix_undefined_behaviour>`
909909
getgrgid_r(),
910910
getgrnam_r(),
911911
getpwnam_r(),

lib/libc/minimal/include/stdio.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ int putc_unlocked(int c, FILE *stream);
6868
int putchar_unlocked(int c);
6969
#endif /* CONFIG_COMMON_LIBC_PUTC_UNLOCKED || __DOXYGEN__ */
7070

71+
#if defined(CONFIG_COMMON_LIBC_GETC_UNLOCKED) || defined(__DOXYGEN__)
72+
int getc_unlocked(FILE *stream);
73+
int getchar_unlocked(void);
74+
#endif /* CONFIG_COMMON_LIBC_GETC_UNLOCKED || __DOXYGEN__ */
75+
7176
#if defined(CONFIG_POSIX_FILE_LOCKING) || defined(__DOXYGEN__)
7277
void flockfile(FILE *file);
7378
int ftrylockfile(FILE *file);

lib/posix/options/file_locking.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <errno.h>
78
#include <stdio.h>
89

910
#include <zephyr/sys/libc-hooks.h>

tests/posix/common/src/file_locking.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@ ZTEST(file_locking, test_stdio)
145145
z_free_fd(POINTER_TO_INT(file));
146146
}
147147

148+
/**
149+
* @brief Existence test for the stubs
150+
*/
151+
ZTEST(file_locking, test_stubs)
152+
{
153+
#ifndef CONFIG_NEWLIB_LIBC
154+
errno = 0;
155+
zassert_equal(getchar_unlocked(), EOF);
156+
zassert_equal(errno, ENOSYS);
157+
158+
errno = 0;
159+
zassert_equal(getc_unlocked(stdin), EOF);
160+
zassert_equal(errno, ENOSYS);
161+
#else
162+
ztest_test_skip();
163+
#endif /* !CONFIG_NEWLIB_LIBC */
164+
}
165+
148166
#else
149167
/**
150168
* PicoLIBC doesn't support these functions in its header

0 commit comments

Comments
 (0)