19#ifndef ZEPHYR_INCLUDE_POSIX_UNISTD_H_
20#define ZEPHYR_INCLUDE_POSIX_UNISTD_H_
22#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
24#include "posix_features.h"
32#include <zephyr/toolchain.h>
89#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
107#define STDERR_FILENO 2
112#define STDIN_FILENO 0
117#define STDOUT_FILENO 1
123#define _POSIX_VDISABLE ('\0')
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
131#if !defined(_OFF_T_DECLARED) && !defined(__off_t_defined)
133#define _OFF_T_DECLARED
134#define __off_t_defined
137#if !defined(_PID_T_DECLARED) && !defined(__pid_t_defined)
140#define _PID_T_DECLARED
141#define __pid_t_defined
146#if !defined(_SSIZE_T_DECLARED) && !defined(__ssize_t_defined)
148#define __SIZE_TYPE__ unsigned long
150#define unsigned signed
151typedef __SIZE_TYPE__ ssize_t;
153#define _SSIZE_T_DECLARED
154#define __ssize_t_defined
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
163#if (_POSIX_C_SOURCE < 200809L) || defined(__DOXYGEN__)
164#if !defined(_USECONDS_T_DECLARED) && !defined(__useconds_t_defined)
166#define _USECONDS_T_DECLARED
167#define __useconds_t_defined
183unsigned int alarm(
unsigned int seconds);
207size_t confstr(
int name,
char *buf,
size_t len);
208#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
214char *
crypt(
const char *key,
const char *salt);
227int dup2(
int fildes,
int fildes2);
232FUNC_NORETURN
void _exit(
int status);
233#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
246int execl(
const char *path,
const char *arg0, ...);
252int execle(
const char *path,
const char *arg0, ...);
258int execlp(
const char *file,
const char *arg0, ...);
264int execv(
const char *path,
char *
const argv[]);
270int execve(
const char *path,
char *
const argv[],
char *
const envp[]);
276int execvp(
const char *file,
char *
const argv[]);
282int faccessat(
int fd,
const char *path,
int amode,
int flag);
301#if defined(_POSIX_SYNCHRONIZED_IO) || defined(__DOXYGEN__)
314int fexecve(
int fd,
char *
const argv[],
char *
const envp[]);
327#if defined(_POSIX_FSYNC) || defined(__DOXYGEN__)
353#if (_POSIX_C_SOURCE >= 202405L) || defined(__DOXYGEN__)
379#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
410int getopt(
int argc,
char *
const argv[],
const char *optstring);
464int link(
const char *path1,
const char *path2);
470int linkat(
int fd1,
const char *path1,
int fd2,
const char *path2,
int flag);
471#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
485#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
516ssize_t
pread(
int fildes,
void *buf,
size_t nbyte,
off_t offset);
522ssize_t
pwrite(
int fildes,
const void *buf,
size_t nbyte,
off_t offset);
528ssize_t
read(
int fildes,
void *buf,
size_t nbyte);
534ssize_t
readlink(
const char *restrict path,
char *restrict buf,
size_t bufsize);
540ssize_t
readlinkat(
int fd,
const char *restrict path,
char *restrict buf,
size_t bufsize);
571#if (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500 && _XOPEN_SOURCE < 800)) || \
580#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
610unsigned int sleep(
unsigned int seconds);
611#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
617void swab(
const void *ZRESTRICT src,
void *ZRESTRICT dest, ssize_t nbytes);
624int symlink(
const char *path1,
const char *path2);
630int symlinkat(
const char *path1,
int fd,
const char *path2);
631#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
639#ifdef CONFIG_POSIX_SYSCONF_IMPL_MACRO
644#define sysconf(x) (long)CONCAT(__z_posix_sysconf, x)
695#if (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE < 700)) || defined(__DOXYGEN__)
708ssize_t
write(
int fildes,
const void *buf,
size_t nbyte);
POSIX configuration string constants (<sys/confstr.h>)
int pid_t
Process ID type.
long off_t
File offset type.
int fsync(int fd)
Synchronise an open file's data and metadata to storage.
int optopt
Unrecognised option character from getopt().
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.
char * ttyname(int fildes)
Get the name of the terminal associated with a file descriptor.
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 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 seteuid(uid_t uid)
Set the effective user ID of the calling process.
pid_t getpgrp(void)
Get the process group ID of the calling process.
int getgroups(int gidsetsize, gid_t grouplist[])
Get the supplementary group IDs of the calling process.
FUNC_NORETURN void _exit(int status)
Terminate the calling process without calling atexit() handlers.
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.
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.
gid_t getegid(void)
Get the effective group ID of the calling process.
pid_t getpgid(pid_t pid)
Get the process group ID of a process.
int nice(int incr)
Change the scheduling priority of the calling process (XSI extension).
gid_t getgid(void)
Get the real group ID of the calling 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).
uid_t geteuid(void)
Get the effective user ID of the calling process.
int execvp(const char *file, char *const argv[])
Replace process image using PATH search (vector form).
int tcsetpgrp(int fildes, pid_t pgid_id)
Set the foreground process group ID of a terminal.
int setuid(uid_t uid)
Set the real user ID of the calling process.
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.
pid_t setpgrp(void)
Set the process group ID to the process ID of the calling process (obsolescent).
int execv(const char *path, char *const argv[])
Replace process image with a new program (vector form).
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.
int setegid(gid_t gid)
Set the effective group ID of the calling process.
char * getlogin(void)
Get the login name of the user.
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 getentropy(void *buffer, size_t length)
Fill a buffer with cryptographically secure random bytes.
int gethostname(char *name, size_t namelen)
Get the name of the current host.
void encrypt(char block[64], int edflag)
Encrypt or decrypt a 64-bit block using DES (XSI extension).
int setreuid(uid_t ruid, uid_t euid)
Set the real and effective user IDs (XSI extension).
char * crypt(const char *key, const char *salt)
Encrypt a password string (XSI extension, not recommended for new code).
int lockf(int fildes, int function, off_t size)
Apply, test, or remove an advisory file lock (XSI extension).
int setregid(gid_t rgid, gid_t egid)
Set the real and effective group IDs (XSI extension).
long gethostid(void)
Get a unique identifier for the host system (XSI extension).
void sync(void)
Schedule outstanding writes to all file systems (XSI extension).
void swab(const void *ZRESTRICT src, void *ZRESTRICT dest, ssize_t nbytes)
Swap bytes in a block of memory (XSI extension).
int fdatasync(int fildes)
Synchronise the data of an open file to storage (without metadata).
int getlogin_r(char *name, size_t namesize)
Get the login name of the user into a caller-supplied buffer.
int ttyname_r(int fildes, char *name, size_t namesize)
Get the name of the terminal into a caller-supplied buffer.
POSIX pathname configuration constants (<sys/pathconf.h>)
POSIX runtime system configuration (<sys/sysconf.h>)
unsigned long useconds_t
Used for time in microseconds (obsolescent).