-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
posix: options: fs: separate file_system_r to its own file
Move the functionality of POSIX_FILE_SYSTEM_R to its own compilation unit and remove the unnecessary dependency on POSIX_FILE_SYSTEM. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
- Loading branch information
Showing
7 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config POSIX_FILE_SYSTEM_R | ||
bool "Thread-Safe File System" | ||
select FILE_SYSTEM | ||
select FDTABLE | ||
help | ||
Select 'y' here and Zephyr will provide an implementation of the POSIX_FILE_SYSTEM_R | ||
Option Group, consisting of readdir_r(). | ||
|
||
For more informnation, please see | ||
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2024 Tenstorrent AI ULC | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#undef _POSIX_C_SOURCE | ||
#define _POSIX_C_SOURCE 200809L | ||
|
||
#include "fs_priv.h" | ||
|
||
#include <errno.h> | ||
#include <limits.h> | ||
#include <string.h> | ||
|
||
#include <zephyr/fs/fs.h> | ||
#include <zephyr/posix/posix_features.h> | ||
#include <zephyr/posix/dirent.h> | ||
|
||
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) | ||
{ | ||
int rc; | ||
struct fs_dirent de; | ||
struct posix_fs_desc *const ptr = dirp; | ||
|
||
if (result == NULL) { | ||
return EINVAL; | ||
} | ||
|
||
if (entry == NULL) { | ||
*result = NULL; | ||
return EINVAL; | ||
} | ||
|
||
if (dirp == NULL) { | ||
*result = NULL; | ||
return EBADF; | ||
} | ||
|
||
rc = fs_readdir(&ptr->dir, &de); | ||
if (rc < 0) { | ||
*result = NULL; | ||
return -rc; | ||
} | ||
|
||
strncpy(entry->d_name, de.name, MIN(sizeof(entry->d_name), sizeof(de.name))); | ||
entry->d_name[sizeof(entry->d_name) - 1] = '\0'; | ||
|
||
if (entry->d_name[0] == '\0') { | ||
*result = NULL; | ||
return 0; | ||
} | ||
|
||
*result = entry; | ||
return 0; | ||
} |