Skip to content

Commit

Permalink
libc/picolibc: Add 'write' implementation when needed
Browse files Browse the repository at this point in the history
This is needed for the picolibc __chk_fail implementation as that
uses it up through version 1.8.5. After that, picolibc uses puts.

Signed-off-by: Keith Packard <[email protected]>
  • Loading branch information
keith-packard committed Nov 19, 2023
1 parent a1f24c3 commit a3157ce
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/libc/picolibc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ zephyr_library_sources(
exit.c
locks.c
stdio.c
write.c
)

# define __LINUX_ERRNO_EXTENSIONS__ so we get errno defines like -ESHUTDOWN
Expand Down
38 changes: 38 additions & 0 deletions lib/libc/picolibc/write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright © 2021, Keith Packard <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <zephyr/posix/sys/stat.h>
#include <sys/time.h>
#include <zephyr/arch/cpu.h>
#include <zephyr/linker/linker-defs.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/errno_private.h>
#include <zephyr/sys/libc-hooks.h>
#include <zephyr/internal/syscall_handler.h>
#include <zephyr/app_memory/app_memdomain.h>
#include <zephyr/init.h>
#include <zephyr/sys/sem.h>
#include <zephyr/logging/log.h>
#ifdef CONFIG_MMU
#include <zephyr/sys/mem_manage.h>
#endif

/* Don't replace the version supplied by fdtable */
#if !defined(CONFIG_FDTABLE) || !defined(CONFIG_POSIX_API)
ssize_t write(int fd, const void *buf, size_t len)
{
size_t count;
const char *b = buf;

(void) fd;
for (count = 0; count < len; count++)
zephyr_fputc(*b++, stdout);
return len;
}
#endif

0 comments on commit a3157ce

Please sign in to comment.