Skip to content

Commit

Permalink
libc: minimal: stubs getc_unlocked & getchar_unlocked
Browse files Browse the repository at this point in the history
Add stub implementation and test for `getc_unlocked()` &
`getchar_unlocked()`.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
  • Loading branch information
ycsin committed Jun 24, 2024
1 parent 778629e commit a206ee6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions doc/services/portability/posix/option_groups/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ This table lists service support status in Zephyr for `POSIX_FD_MGMT`:
flockfile(), yes
ftrylockfile(), yes
funlockfile(), yes
getc_unlocked(),
getchar_unlocked(),
getc_unlocked(), yes :ref:`†<posix_undefined_behaviour>`
getchar_unlocked(), yes :ref:`†<posix_undefined_behaviour>`
putc_unlocked(), yes
putchar_unlocked(), yes

Expand Down Expand Up @@ -904,8 +904,8 @@ _POSIX_THREAD_SAFE_FUNCTIONS
flockfile(), yes
ftrylockfile(), yes
funlockfile(), yes
getc_unlocked(),
getchar_unlocked(),
getc_unlocked(), yes :ref:`†<posix_undefined_behaviour>`
getchar_unlocked(), yes :ref:`†<posix_undefined_behaviour>`
getgrgid_r(),
getgrnam_r(),
getpwnam_r(),
Expand Down
5 changes: 5 additions & 0 deletions lib/libc/minimal/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ int putc_unlocked(int c, FILE *stream);
int putchar_unlocked(int c);
#endif /* CONFIG_COMMON_LIBC_PUTC_UNLOCKED || __DOXYGEN__ */

#if defined(CONFIG_COMMON_LIBC_GETC_UNLOCKED) || defined(__DOXYGEN__)
int getc_unlocked(FILE *stream);
int getchar_unlocked(void);
#endif /* CONFIG_COMMON_LIBC_GETC_UNLOCKED || __DOXYGEN__ */

#if defined(CONFIG_POSIX_FILE_LOCKING) || defined(__DOXYGEN__)
void flockfile(FILE *file);
int ftrylockfile(FILE *file);
Expand Down
1 change: 1 addition & 0 deletions lib/posix/options/file_locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <errno.h>
#include <stdio.h>

#include <zephyr/sys/libc-hooks.h>
Expand Down
18 changes: 18 additions & 0 deletions tests/posix/common/src/file_locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ ZTEST(file_locking, test_stdio)
z_free_fd(POINTER_TO_INT(file));
}

/**
* @brief Existence test for the stubs
*/
ZTEST(file_locking, test_stubs)
{
#ifndef CONFIG_NEWLIB_LIBC
errno = 0;
zassert_equal(getchar_unlocked(), EOF);
zassert_equal(errno, ENOSYS);

errno = 0;
zassert_equal(getc_unlocked(stdin), EOF);
zassert_equal(errno, ENOSYS);
#else
ztest_test_skip();
#endif /* !CONFIG_NEWLIB_LIBC */
}

#else
/**
* PicoLIBC doesn't support these functions in its header
Expand Down

0 comments on commit a206ee6

Please sign in to comment.