Skip to content

Commit abf6269

Browse files
karthi012nashif
authored andcommitted
lib: libc: stdio: add support remove api
Implement remove api to zephyr's native c library Signed-off-by: Karthikeyan Krishnasamy <[email protected]>
1 parent e8ab88b commit abf6269

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

lib/libc/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_THRD
1919
source/thrd/thrd.c
2020
source/thrd/tss.c
2121
)
22+
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_REMOVE source/stdio/remove.c)
2223

2324
# Prevent compiler from optimizing calloc into an infinite recursive call
2425
zephyr_library_compile_options($<TARGET_PROPERTY:compiler,no_builtin_malloc>)

lib/libc/common/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,10 @@ config COMMON_LIBC_THRD
115115
default y
116116
help
117117
Common implementation of C11 <threads.h> API.
118+
119+
config COMMON_LIBC_REMOVE
120+
bool "Common C library remove"
121+
depends on !SEMIHOST
122+
default y if FILE_SYSTEM
123+
help
124+
Common implementation of remove().
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2024 Linumiz.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <errno.h>
8+
#include <stdio.h>
9+
#include <zephyr/fs/fs.h>
10+
#include <zephyr/sys/util_macro.h>
11+
12+
/**
13+
*
14+
* @brief deletes a name from the filesystem
15+
*
16+
* @return On success, zero is returned. On error, -1 is returned
17+
* and errno is set to indicate the error.
18+
*/
19+
20+
int remove(const char *path)
21+
{
22+
if (!IS_ENABLED(CONFIG_FILE_SYSTEM)) {
23+
errno = ENOTSUP;
24+
return -1;
25+
}
26+
27+
int ret = fs_unlink(path);
28+
29+
if (ret < 0) {
30+
errno = -ret;
31+
return -1;
32+
}
33+
34+
return 0;
35+
}

lib/libc/minimal/include/stdio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ int fputc(int c, FILE *stream);
6060
int fputs(const char *ZRESTRICT s, FILE *ZRESTRICT stream);
6161
size_t fwrite(const void *ZRESTRICT ptr, size_t size, size_t nitems,
6262
FILE *ZRESTRICT stream);
63+
int remove(const char *path);
6364
#define putc(c, stream) fputc(c, stream)
6465
#define putchar(c) putc(c, stdout)
6566

0 commit comments

Comments
 (0)