Skip to content

Commit

Permalink
libc: minimal: implement putc_unlocked & putchar_unlocked
Browse files Browse the repository at this point in the history
Add a simple implementation for putc_unlocked() &
putchar_unlocked().

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

.. _posix_option_group_memory_protection:

Expand Down
2 changes: 2 additions & 0 deletions lib/libc/minimal/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ size_t fwrite(const void *ZRESTRICT ptr, size_t size, size_t nitems,
FILE *ZRESTRICT stream);
#define putc(c, stream) fputc(c, stream)
#define putchar(c) putc(c, stdout)
#define putc_unlocked(c, stream) putc(c, stream)
#define putchar_unlocked(c) putchar(c)

void flockfile(FILE *file);
int ftrylockfile(FILE *file);
Expand Down
12 changes: 12 additions & 0 deletions lib/posix/options/file_locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ void funlockfile(FILE *file)
#ifdef CONFIG_POSIX_FD_MGMT_ALIAS_FUNLOCKFILE
FUNC_ALIAS(funlockfile, _funlockfile, void);
#endif /* CONFIG_POSIX_FD_MGMT_ALIAS_FUNLOCKFILE */

#undef putc_unlocked
int putc_unlocked(int c, FILE *stream)
{
return putc(c, stream);
}

#undef putchar_unlocked
int putchar_unlocked(int c)
{
return putchar(c);
}
9 changes: 9 additions & 0 deletions tests/posix/common/src/file_locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
void flockfile(FILE *file);
int ftrylockfile(FILE *file);
void funlockfile(FILE *file);
int putc_unlocked(int, FILE *);
int putchar_unlocked(int);
#endif

#include <zephyr/sys/fdtable.h>
Expand Down Expand Up @@ -114,4 +116,11 @@ ZTEST(file_locking, test_file_locking)
zassert_not_ok(ftrylockfile(file));
}

ZTEST(file_locking, test_stdio)
{
int ret;

ret = putc_unlocked('T', stdout);
zassert_equal(ret, 84, "putc \'T\' failed");
}
ZTEST_SUITE(file_locking, NULL, NULL, NULL, NULL, NULL);

0 comments on commit fd80070

Please sign in to comment.