posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
unistd.h
Go to the documentation of this file.
1/*
2 * Copyright (c) The Zephyr Project Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
19#ifndef ZEPHYR_INCLUDE_POSIX_UNISTD_H_
20#define ZEPHYR_INCLUDE_POSIX_UNISTD_H_
21
22#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
23
24#include "posix_features.h"
25
26#include <stddef.h>
27#include <stdint.h>
28
32#include <zephyr/toolchain.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/* Version test macros _POSIX_VERSION, _XOPEN_VERSION, etc, defined in posix_features.h */
39/* Constants for Options and Option Groups defined in posix_features.h */
40
41/* Execution-Time Symbolic Constants defined in posix_features.h */
42/* TODO: define _POSIX_ASYNC_IO, _POSIX_PRIO_IO, _POSIX_SYNC_IO */
43/* TODO: define _POSIX_TIMESTAMP_RESOLUTION, _POSIX2_SYMLINKS */
44
45/* _POSIX2_VERSION defined by posix_features.h */
46/* _XOPEN_VERSION defined by posix_features.h */
47
48/* NULL must be defined by the libc stddef.h */
49
54#define F_OK 0
59#define R_OK 4
64#define W_OK 2
69#define X_OK 1
70
71/* confstr() constants in zephyr/posix/sys/confstr.h */
72
73/* SEEK_CUR, SEEK_END, SEEK_SET nominally defined in <stdio.h> */
74#ifndef SEEK_CUR
76#define SEEK_CUR 1
77#endif
78
79#ifndef SEEK_END
81#define SEEK_END 2
82#endif
83
84#ifndef SEEK_SET
86#define SEEK_SET 0
87#endif
88
89#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
91#define F_LOCK 1
93#define F_TEST 3
95#define F_TLOCK 2
97#define F_ULOCK 0
98#endif
99
100/* pathconf() constants in zephyr/posix/sys/pathconf.h */
101/* sysconf() constants in zephyr/posix/sys/sysconf.h */
102
107#define STDERR_FILENO 2
112#define STDIN_FILENO 0
117#define STDOUT_FILENO 1
118
123#define _POSIX_VDISABLE ('\0')
124
125#if !defined(_GID_T_DECLARED) && !defined(__gid_t_defined)
126typedef unsigned short gid_t;
127#define _GID_T_DECLARED
128#define __gid_t_defined
129#endif
130
131#if !defined(_OFF_T_DECLARED) && !defined(__off_t_defined)
132typedef long off_t;
133#define _OFF_T_DECLARED
134#define __off_t_defined
135#endif
136
137#if !defined(_PID_T_DECLARED) && !defined(__pid_t_defined)
138/* TODO: it would be nice to convert this to a long */
139typedef int pid_t;
140#define _PID_T_DECLARED
141#define __pid_t_defined
142#endif
143
144/* size_t must be defined by the libc stddef.h */
145
146#if !defined(_SSIZE_T_DECLARED) && !defined(__ssize_t_defined)
147#ifndef __SIZE_TYPE__
148#define __SIZE_TYPE__ unsigned long
149#endif
150#define unsigned signed /* parasoft-suppress MISRAC2012-RULE_20_4-a MISRAC2012-RULE_20_4-b */
151typedef __SIZE_TYPE__ ssize_t;
152#undef unsigned
153#define _SSIZE_T_DECLARED
154#define __ssize_t_defined
155#endif
156
157#if !defined(_UID_T_DECLARED) && !defined(__uid_t_defined)
158typedef unsigned short uid_t;
159#define _UID_T_DECLARED
160#define __uid_t_defined
161#endif
162
163#if !defined(_USECONDS_T_DECLARED) && !defined(__useconds_t_defined)
164typedef unsigned long useconds_t;
165#define _USECONDS_T_DECLARED
166#define __useconds_t_defined
167#endif
168
169/* intptr_t is optionally defined by the libc stdint.h and we assume it is defined there */
170
176int access(const char *path, int amode);
181unsigned int alarm(unsigned int seconds);
187int chdir(const char *path);
193int chown(const char *path, uid_t owner, gid_t group);
199int close(int fildes);
205size_t confstr(int name, char *buf, size_t len);
206#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
212char *crypt(const char *key, const char *salt);
213#endif
219int dup(int fildes);
225int dup2(int fildes, int fildes2);
230FUNC_NORETURN void _exit(int status);
231#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
237void encrypt(char block[64], int edflag);
238#endif
244int execl(const char *path, const char *arg0, ...);
250int execle(const char *path, const char *arg0, ...);
256int execlp(const char *file, const char *arg0, ...);
262int execv(const char *path, char *const argv[]);
268int execve(const char *path, char *const argv[], char *const envp[]);
274int execvp(const char *file, char *const argv[]);
280int faccessat(int fd, const char *path, int amode, int flag);
286int fchdir(int fildes);
292int fchown(int fildes, uid_t owner, gid_t group);
298int fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag);
299#if defined(_POSIX_SYNCHRONIZED_IO) || defined(__DOXYGEN__)
305int fdatasync(int fildes);
306#endif
312int fexecve(int fd, char *const argv[], char *const envp[]);
324long fpathconf(int fildes, int name);
325#if defined(_POSIX_FSYNC) || defined(__DOXYGEN__)
331int fsync(int fd);
332#endif
338int ftruncate(int fildes, off_t length);
344char *getcwd(char *buf, size_t size);
350gid_t getegid(void);
351#if (_POSIX_C_SOURCE >= 202405L) || defined(__DOXYGEN__)
357int getentropy(void *buffer, size_t length);
358#endif
364uid_t geteuid(void);
370gid_t getgid(void);
376int getgroups(int gidsetsize, gid_t grouplist[]);
377#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
383long gethostid(void);
384#endif
390int gethostname(char *name, size_t namelen);
396char *getlogin(void);
402int getlogin_r(char *name, size_t namesize);
408int getopt(int argc, char *const argv[], const char *optstring);
444uid_t getuid(void);
450int isatty(int fildes);
456int lchown(const char *path, uid_t owner, gid_t group);
462int link(const char *path1, const char *path2);
468int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag);
469#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
475int lockf(int fildes, int function, off_t size);
476#endif
482off_t lseek(int fildes, off_t offset, int whence);
483#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
489int nice(int incr);
490#endif
496long pathconf(const char *path, int name);
502int pause(void);
508int pipe(int fildes[2]);
514ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
520ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
526ssize_t read(int fildes, void *buf, size_t nbyte);
532ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
538ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize);
544int rmdir(const char *path);
550int setegid(gid_t gid);
556int seteuid(uid_t uid);
562int setgid(gid_t gid);
568int setpgid(pid_t pid, pid_t pgid);
569#if (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500 && _XOPEN_SOURCE < 800)) || \
570 defined(__DOXYGEN__)
577#endif
578#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
584int setregid(gid_t rgid, gid_t egid);
590int setreuid(uid_t ruid, uid_t euid);
591#endif
603int setuid(uid_t uid);
608unsigned int sleep(unsigned int seconds);
609#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
615void swab(const void *ZRESTRICT src, void *ZRESTRICT dest, ssize_t nbytes);
616#endif
622int symlink(const char *path1, const char *path2);
628int symlinkat(const char *path1, int fd, const char *path2);
629#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
635void sync(void);
636#endif
637#ifdef CONFIG_POSIX_SYSCONF_IMPL_MACRO
642#define sysconf(x) (long)CONCAT(__z_posix_sysconf, x)
643#else
649long sysconf(int opt);
650#endif /* CONFIG_POSIX_SYSCONF_IMPL_FULL */
656pid_t tcgetpgrp(int fildes);
662int tcsetpgrp(int fildes, pid_t pgid_id);
668int truncate(const char *path, off_t length);
674char *ttyname(int fildes);
680int ttyname_r(int fildes, char *name, size_t namesize);
686int unlink(const char *path);
692int unlinkat(int fd, const char *path, int flag);
693#if (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE < 700)) || defined(__DOXYGEN__)
699int usleep(useconds_t useconds);
700#endif
706ssize_t write(int fildes, const void *buf, size_t nbyte);
707
712extern char *optarg;
717extern int opterr;
722extern int optind;
727extern int optopt;
728
729#ifdef __cplusplus
730}
731#endif
732
733#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */
734
735#endif /* ZEPHYR_INCLUDE_POSIX_UNISTD_H_ */
POSIX configuration string constants (<sys/confstr.h>)
int pid_t
Process ID type.
Definition fcntl.h:192
int fsync(int fd)
Synchronise an open file's data and metadata to storage.
int optopt
Unrecognised option character from getopt().
int getentropy(void *buffer, size_t length)
Fill a buffer with cryptographically secure random bytes.
int getopt(int argc, char *const argv[], const char *optstring)
Parse command-line options.
int optind
Index of the next element to be processed by getopt().
char * optarg
Argument for the current option from getopt().
int opterr
Error flag for getopt() (non-zero enables error messages).
ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
Write to a file at a given offset without changing the file offset.
ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)
Read from a file at a given offset without changing the file offset.
ssize_t write(int fildes, const void *buf, size_t nbyte)
Write to a file descriptor.
int close(int fildes)
Close a file descriptor.
ssize_t read(int fildes, void *buf, size_t nbyte)
Read from a file descriptor.
int ttyname_r(int fildes, char *name, size_t namesize)
Get the name of the terminal into a caller-supplied buffer.
char * ttyname(int fildes)
Get the name of the terminal associated with a file descriptor.
int isatty(int fildes)
Determine whether a file descriptor refers to a terminal.
int dup2(int fildes, int fildes2)
Duplicate an open file descriptor to a specific descriptor number.
int ftruncate(int fildes, off_t length)
Truncate an open file to a specified length.
off_t lseek(int fildes, off_t offset, int whence)
Reposition the file offset of an open file descriptor.
int dup(int fildes)
Duplicate an open file descriptor to the lowest available descriptor.
int chdir(const char *path)
Change the current working directory.
int chown(const char *path, uid_t owner, gid_t group)
Change the owner and group of a file.
int unlink(const char *path)
Remove a directory entry.
ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize)
Read the value of a symbolic link.
int symlink(const char *path1, const char *path2)
Create a symbolic link.
ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize)
Read the value of a symbolic link relative to a directory descriptor.
int fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag)
Change owner and group of a file relative to a directory descriptor.
int truncate(const char *path, off_t length)
Truncate a file on the filesystem to a specified length.
int link(const char *path1, const char *path2)
Create a hard link.
int fchown(int fildes, uid_t owner, gid_t group)
Change the owner and group of an open file.
int symlinkat(const char *path1, int fd, const char *path2)
Create a symbolic link relative to a directory file descriptor.
int unlinkat(int fd, const char *path, int flag)
Remove a directory entry relative to a directory file descriptor.
long pathconf(const char *path, int name)
Determine the value of a configurable limit for a file path.
int access(const char *path, int amode)
Determine accessibility of a file.
int rmdir(const char *path)
Remove an empty directory.
int fchdir(int fildes)
Change the current working directory to the directory named by a file descriptor.
char * getcwd(char *buf, size_t size)
Get the pathname of the current working directory.
long fpathconf(int fildes, int name)
Determine the value of a configurable limit for an open file.
int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag)
Create a hard link relative to directory file descriptors.
int lchown(const char *path, uid_t owner, gid_t group)
Change the owner and group of a symbolic link.
int faccessat(int fd, const char *path, int amode, int flag)
Determine accessibility of a file relative to a directory descriptor.
int tcsetpgrp(int fildes, pid_t pgid_id)
Set the foreground process group ID of a terminal.
pid_t setpgrp(void)
Set the process group ID to the process ID of the calling process (obsolescent).
pid_t tcgetpgrp(int fildes)
Get the process group ID of the foreground process group of the terminal.
int setpgid(pid_t pid, pid_t pgid)
Set the process group ID for a process.
pid_t getpgrp(void)
Get the process group ID of the calling process.
FUNC_NORETURN void _exit(int status)
Terminate the calling process without calling atexit() handlers.
pid_t getsid(pid_t pid)
Get the session ID of a process.
int execle(const char *path, const char *arg0,...)
Replace process image with a new program plus environment (argument list form).
pid_t setsid(void)
Create a new session and set the process group ID.
pid_t getpgid(pid_t pid)
Get the process group ID of a process.
int usleep(useconds_t useconds)
Suspend execution for at least the specified number of microseconds (obsolescent).
unsigned int sleep(unsigned int seconds)
Suspend execution for at least the specified number of seconds.
int execve(const char *path, char *const argv[], char *const envp[])
Replace process image with a new program plus environment (vector form).
int execl(const char *path, const char *arg0,...)
Replace the process image with a new program (argument list form).
int execlp(const char *file, const char *arg0,...)
Replace process image using PATH search (argument list form).
int execvp(const char *file, char *const argv[])
Replace process image using PATH search (vector form).
pid_t fork(void)
Create a child process.
int fexecve(int fd, char *const argv[], char *const envp[])
Replace process image using an open file descriptor (vector form).
pid_t getpid(void)
Get the process ID of the calling process.
pid_t getppid(void)
Get the process ID of the parent of the calling process.
int execv(const char *path, char *const argv[])
Replace process image with a new program (vector form).
int gethostname(char *name, size_t namelen)
Get the name of the current host.
int pipe(int fildes[2])
Create a pipe — a pair of connected file descriptors.
int pause(void)
Suspend process execution until a signal is received.
unsigned int alarm(unsigned int seconds)
Schedule an alarm signal (SIGALRM) after a given number of seconds.
size_t confstr(int name, char *buf, size_t len)
Determine the value of a configurable system variable by name string.
long sysconf(int opt)
Get a configurable system variable.
int getlogin_r(char *name, size_t namesize)
Get the login name of the user into a caller-supplied buffer.
int seteuid(uid_t uid)
Set the effective user ID of the calling process.
int getgroups(int gidsetsize, gid_t grouplist[])
Get the supplementary group IDs of the calling process.
uid_t getuid(void)
Get the real user ID of the calling process.
int setgid(gid_t gid)
Set the real group ID of the calling process.
gid_t getegid(void)
Get the effective group ID of the calling process.
gid_t getgid(void)
Get the real group ID of the calling process.
uid_t geteuid(void)
Get the effective user ID of the calling process.
int setuid(uid_t uid)
Set the real user ID of the calling process.
int setegid(gid_t gid)
Set the effective group ID of the calling process.
char * getlogin(void)
Get the login name of the user.
void swab(const void *ZRESTRICT src, void *ZRESTRICT dest, ssize_t nbytes)
Swap bytes in a block of memory (XSI extension).
int lockf(int fildes, int function, off_t size)
Apply, test, or remove an advisory file lock (XSI extension).
void sync(void)
Schedule outstanding writes to all file systems (XSI extension).
int nice(int incr)
Change the scheduling priority of the calling process (XSI extension).
void encrypt(char block[64], int edflag)
Encrypt or decrypt a 64-bit block using DES (XSI extension).
char * crypt(const char *key, const char *salt)
Encrypt a password string (XSI extension, not recommended for new code).
long gethostid(void)
Get a unique identifier for the host system (XSI extension).
int setreuid(uid_t ruid, uid_t euid)
Set the real and effective user IDs (XSI extension).
int setregid(gid_t rgid, gid_t egid)
Set the real and effective group IDs (XSI extension).
int fdatasync(int fildes)
Synchronise the data of an open file to storage (without metadata).
POSIX pathname configuration constants (<sys/pathconf.h>)
POSIX group database entry.
Definition grp.h:32
POSIX runtime system configuration (<sys/sysconf.h>)
unsigned long useconds_t
Used for time in microseconds (obsolescent).
Definition types.h:183