-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
posix: fd_mgmt: add fd_mgmt option group
Signed-off-by: Chris Friedt <[email protected]>
- Loading branch information
Chris Friedt
committed
May 22, 2024
1 parent
7f91781
commit 51a4ef8
Showing
7 changed files
with
94 additions
and
14 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
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,36 @@ | ||
# Copyright (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
menuconfig POSIX_FD_MGMT | ||
bool "POSIX file descriptor management" | ||
default y if POSIX_API | ||
help | ||
Select 'y' here and Zephyr will provide implementations for the POSIX_FD_MGMT Option Group. | ||
This includes support for dup(), dup2(), fcntl(), fseeko(), ftello(), ftruncate(), | ||
and lseek(). | ||
|
||
For more information, please see | ||
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html | ||
|
||
if POSIX_FD_MGMT | ||
|
||
# These options are intended to be used for compatibility with external POSIX | ||
# implementations such as those in Newlib or Picolibc. | ||
|
||
config POSIX_FD_MGMT_ALIAS_FCNTL | ||
bool | ||
help | ||
Select 'y' here and Zephyr will provide an alias for fcntl() as _fcntl(). | ||
|
||
config POSIX_FD_MGMT_ALIAS_FTRUNCATE | ||
bool | ||
help | ||
Select 'y' here and Zephyr will provide an alias for ftruncate() as _ftruncate(). | ||
|
||
config POSIX_FD_MGMT_ALIAS_LSEEK | ||
bool | ||
help | ||
Select 'y' here and Zephyr will provide an alias for lseek() as _lseek(). | ||
|
||
endif # POSIX_FD_MGMT |
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,50 @@ | ||
/* | ||
* Copyright (c) 2024, Tenstorrent AI ULC | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdarg.h> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
#include <zephyr/posix/unistd.h> | ||
#include <zephyr/posix/sys/select.h> | ||
#include <zephyr/posix/sys/socket.h> | ||
#include <zephyr/sys/fdtable.h> | ||
|
||
/* prototypes for external, not-yet-public, functions in fdtable.c or fs.c */ | ||
int zvfs_fcntl(int fd, int cmd, va_list arg); | ||
int zvfs_ftruncate(int fd, off_t length); | ||
off_t zvfs_lseek(int fd, off_t offset, int whence); | ||
|
||
int fcntl(int fd, int cmd, ...) | ||
{ | ||
int ret; | ||
va_list args; | ||
|
||
va_start(args, cmd); | ||
ret = zvfs_fcntl(fd, cmd, args); | ||
va_end(args); | ||
|
||
return ret; | ||
} | ||
#ifdef CONFIG_POSIX_FD_MGMT_ALIAS_FCNTL | ||
FUNC_ALIAS(fcntl, _fcntl, int); | ||
#endif /* CONFIG_POSIX_FD_MGMT_ALIAS_FCNTL */ | ||
|
||
int ftruncate(int fd, off_t length) | ||
{ | ||
return zvfs_ftruncate(fd, length); | ||
} | ||
#ifdef CONFIG_POSIX_FD_MGMT_ALIAS_FTRUNCATE | ||
FUNC_ALIAS(ftruncate, _ftruncate, int); | ||
#endif /* CONFIG_POSIX_FD_MGMT_ALIAS_FTRUNCATE */ | ||
|
||
off_t lseek(int fd, off_t offset, int whence) | ||
{ | ||
return zvfs_lseek(fd, offset, whence); | ||
} | ||
#ifdef CONFIG_POSIX_FD_MGMT_ALIAS_LSEEK | ||
FUNC_ALIAS(lseek, _lseek, off_t); | ||
#endif /* CONFIG_POSIX_FD_MGMT_ALIAS_LSEEK */ |
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