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 14, 2024
1 parent 8e011a7 commit 0266adb
Show file tree
Hide file tree
Showing 4 changed files with 19 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 @@ -556,8 +556,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_multi_process:

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/libc/minimal/source/stdout/stdout_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,24 @@ int putc(int c, FILE *stream)
return zephyr_fputc(c, stream);
}

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

#undef putchar
int putchar(int c)
{
return zephyr_fputc(c, stdout);
}

#undef putchar_unlocked
int putchar_unlocked(int c)
{
return putchar(c);
}

size_t z_impl_zephyr_fwrite(const void *ZRESTRICT ptr, size_t size,
size_t nitems, FILE *ZRESTRICT stream)
{
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/sprintf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ ZTEST(sprintf, test_put)
ret = fputc('T', stderr);
zassert_equal(ret, 84, "fputc \'T\' failed");

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

ret = fputc('T', stdin);
zassert_equal(ret, EOF, "fputc to stdin");
}
Expand Down

0 comments on commit 0266adb

Please sign in to comment.