posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
fcntl.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) The Zephyr Project Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
18#ifndef ZEPHYR_POSIX_FCNTL_H_
19#define ZEPHYR_POSIX_FCNTL_H_
20
21#include <sys/stat.h>
22
23#include <zephyr/sys/fdtable.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
30
31/* --- fcntl() command codes (POSIX_FD_MGMT) -------------------------------- */
32
34#define F_DUPFD ZVFS_F_DUPFD
35#if (_POSIX_C_SOURCE >= 200809L) || defined(__DOXYGEN__)
37#define F_DUPFD_CLOEXEC ZVFS_F_DUPFD_CLOEXEC
38#endif
40#define F_GETFD ZVFS_F_GETFD
42#define F_SETFD ZVFS_F_SETFD
44#define F_GETFL ZVFS_F_GETFL
46#define F_SETFL ZVFS_F_SETFL
48#define F_GETLK ZVFS_F_GETLK
50#define F_SETLK ZVFS_F_SETLK
52#define F_SETLKW ZVFS_F_SETLKW
53#if (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__)
55#define F_GETOWN ZVFS_F_GETOWN
57#define F_SETOWN ZVFS_F_SETOWN
58#endif
59
61#define FD_CLOEXEC ZVFS_FD_CLOEXEC
62
63/* --- File lock type codes (POSIX_FILE_LOCKING) ----------------------------- */
64
66#define F_RDLCK ZVFS_F_RDLCK
68#define F_UNLCK ZVFS_F_UNLCK
70#define F_WRLCK ZVFS_F_WRLCK
71
72/* SEEK_CUR, SEEK_END, SEEK_SET nominally defined in <stdio.h> */
73#ifndef SEEK_CUR
75#define SEEK_CUR ZVFS_SEEK_CUR
76#endif
77
78#ifndef SEEK_END
80#define SEEK_END ZVFS_SEEK_END
81#endif
82
83#ifndef SEEK_SET
85#define SEEK_SET ZVFS_SEEK_SET
86#endif
87
88/* --- open() creation and status flags (POSIX_DEVICE_IO) ------------------- */
89
91#define O_CLOEXEC ZVFS_O_CLOEXEC
93#define O_CREAT ZVFS_O_CREAT
95#define O_DIRECTORY ZVFS_O_DIRECTORY
97#define O_EXCL ZVFS_O_EXCL
99#define O_NOCTTY ZVFS_O_NOCTTY
101#define O_NOFOLLOW ZVFS_O_NOFOLLOW
103#define O_TRUNC ZVFS_O_TRUNC
105#define O_TTY_INIT ZVFS_O_TTY_INIT
106
108#define O_APPEND ZVFS_O_APPEND
110#define O_DSYNC ZVFS_O_DSYNC
112#define O_NONBLOCK ZVFS_O_NONBLOCK
114#define O_RSYNC ZVFS_O_RSYNC
116#define O_SYNC ZVFS_O_SYNC
117
119#define O_EXEC ZVFS_O_EXEC
121#define O_RDONLY ZVFS_O_RDONLY
123#define O_RDWR ZVFS_O_RDWR
125#define O_SEARCH ZVFS_O_SEARCH
127#define O_WRONLY ZVFS_O_WRONLY
128
130#define O_ACCMODE (ZVFS_O_RDONLY | ZVFS_O_RDWR | ZVFS_O_WRONLY)
131
132/* --- *at() directory-relative flags (POSIX_FILE_SYSTEM) ------------------- */
133
135#define AT_FDCWD ZVFS_AT_FDCWD
137#define AT_EACCESS ZVFS_AT_EACCESS
139#define AT_SYMLINK_NOFOLLOW ZVFS_AT_SYMLINK_NOFOLLOW
141#define AT_SYMLINK_FOLLOW ZVFS_AT_SYMLINK_FOLLOW
143#define AT_REMOVEDIR ZVFS_AT_REMOVEDIR
144
145#if defined(_POSIX_ADVISORY_INFO) || defined(__DOXYGEN__)
147#define POSIX_FADV_NORMAL ZVFS_POSIX_FADV_NORMAL
149#define POSIX_FADV_RANDOM ZVFS_POSIX_FADV_RANDOM
151#define POSIX_FADV_SEQUENTIAL ZVFS_POSIX_FADV_SEQUENTIAL
153#define POSIX_FADV_WILLNEED ZVFS_POSIX_FADV_WILLNEED
155#define POSIX_FADV_DONTNEED ZVFS_POSIX_FADV_DONTNEED
157#define POSIX_FADV_NOREUSE ZVFS_POSIX_FADV_NOREUSE
158#endif
159
160#if !defined(_FLOCK_DECLARED) && !defined(__flock_defined)
165struct flock {
166 short l_type;
167 short l_whence;
168 long l_start;
169 long l_len;
171};
172#define _FLOCK_DECLARED
173#define __flock_defined
174#endif
175
176#if !defined(_MODE_T_DECLARED) && !defined(__mode_t_defined)
178typedef int mode_t;
179#define _MODE_T_DECLARED
180#define __mode_t_defined
181#endif
182
183#if !defined(_OFF_T_DECLARED) && !defined(__off_t_defined)
185typedef long off_t;
186#define _OFF_T_DECLARED
187#define __off_t_defined
188#endif
189
190#if !defined(_PID_T_DECLARED) && !defined(__pid_t_defined)
192typedef int pid_t;
193#define _PID_T_DECLARED
194#define __pid_t_defined
195#endif
196
208int creat(const char *path, mode_t mode);
209
219int fcntl(int fildes, int cmd, ...);
220
230int open(const char *name, int flags, ...);
231
242int openat(int fd, const char *path, int oflag, ...);
243
244#if defined(_POSIX_ADVISORY_INFO) || defined(__DOXYGEN__)
255int posix_fadvise(int fd, off_t offset, off_t len, int advice);
256
266int posix_fallocate(int fd, off_t offset, off_t len);
267#endif
268
269#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */
270
271#ifdef __cplusplus
272}
273#endif
274
275#endif /* ZEPHYR_POSIX_FCNTL_H_ */
int pid_t
Process ID type.
Definition fcntl.h:192
int mode_t
File permission bits type.
Definition fcntl.h:178
long off_t
File offset type.
Definition fcntl.h:185
long off_t
File offset type.
Definition aio.h:36
int openat(int fd, const char *path, int oflag,...)
Open or create a file relative to a directory file descriptor.
int open(const char *name, int flags,...)
Open or create a file.
int creat(const char *path, mode_t mode)
Create or truncate a file.
int fcntl(int fildes, int cmd,...)
Perform file control operations on an open file descriptor.
int posix_fadvise(int fd, off_t offset, off_t len, int advice)
Declare an expected access pattern for a file region.
int posix_fallocate(int fd, off_t offset, off_t len)
Guarantee that disk space is allocated for a file region.
POSIX file status types and functions (<sys/stat.h>)
File segment locking structure used with F_GETLK, F_SETLK, and F_SETLKW.
Definition fcntl.h:165
short l_type
Lock type: F_RDLCK, F_WRLCK, or F_UNLCK.
Definition fcntl.h:166
pid_t l_pid
PID of the process holding the lock (F_GETLK output only).
Definition fcntl.h:170
long l_len
Length of locked region in bytes (0 = to EOF).
Definition fcntl.h:169
long l_start
Byte offset to start of locked region.
Definition fcntl.h:168
short l_whence
How to interpret l_start: SEEK_SET, SEEK_CUR, SEEK_END.
Definition fcntl.h:167