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 (_POSIX_C_SOURCE < 200809L) || defined(__DOXYGEN__)
164#if !defined(_USECONDS_T_DECLARED) && !defined(__useconds_t_defined)
165typedef unsigned long useconds_t;
166#define _USECONDS_T_DECLARED
167#define __useconds_t_defined
168#endif
169#endif
170
171/* intptr_t is optionally defined by the libc stdint.h and we assume it is defined there */
172
178int access(const char *path, int amode);
183unsigned int alarm(unsigned int seconds);
189int chdir(const char *path);
195int chown(const char *path, uid_t owner, gid_t group);
201int close(int fildes);
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);
215#endif
221int dup(int fildes);
227int dup2(int fildes, int fildes2);
232FUNC_NORETURN void _exit(int status);
233#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
239void encrypt(char block[64], int edflag);
240#endif
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);
288int fchdir(int fildes);
294int fchown(int fildes, uid_t owner, gid_t group);
300int fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag);
301#if defined(_POSIX_SYNCHRONIZED_IO) || defined(__DOXYGEN__)
307int fdatasync(int fildes);
308#endif
314int fexecve(int fd, char *const argv[], char *const envp[]);
326long fpathconf(int fildes, int name);
327#if defined(_POSIX_FSYNC) || defined(__DOXYGEN__)
333int fsync(int fd);
334#endif
340int ftruncate(int fildes, off_t length);
346char *getcwd(char *buf, size_t size);
352gid_t getegid(void);
353#if (_POSIX_C_SOURCE >= 202405L) || defined(__DOXYGEN__)
359int getentropy(void *buffer, size_t length);
360#endif
366uid_t geteuid(void);
372gid_t getgid(void);
378int getgroups(int gidsetsize, gid_t grouplist[]);
379#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
385long gethostid(void);
386#endif
392int gethostname(char *name, size_t namelen);
398char *getlogin(void);
404int getlogin_r(char *name, size_t namesize);
410int getopt(int argc, char *const argv[], const char *optstring);
446uid_t getuid(void);
452int isatty(int fildes);
458int lchown(const char *path, uid_t owner, gid_t group);
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__)
477int lockf(int fildes, int function, off_t size);
478#endif
484off_t lseek(int fildes, off_t offset, int whence);
485#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
491int nice(int incr);
492#endif
498long pathconf(const char *path, int name);
504int pause(void);
510int pipe(int fildes[2]);
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);
546int rmdir(const char *path);
552int setegid(gid_t gid);
558int seteuid(uid_t uid);
564int setgid(gid_t gid);
570int setpgid(pid_t pid, pid_t pgid);
571#if (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500 && _XOPEN_SOURCE < 800)) || \
572 defined(__DOXYGEN__)
579#endif
580#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
586int setregid(gid_t rgid, gid_t egid);
592int setreuid(uid_t ruid, uid_t euid);
593#endif
605int setuid(uid_t uid);
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);
618#endif
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__)
637void sync(void);
638#endif
639#ifdef CONFIG_POSIX_SYSCONF_IMPL_MACRO
644#define sysconf(x) (long)CONCAT(__z_posix_sysconf, x)
645#else
651long sysconf(int opt);
652#endif /* CONFIG_POSIX_SYSCONF_IMPL_FULL */
658pid_t tcgetpgrp(int fildes);
664int tcsetpgrp(int fildes, pid_t pgid_id);
670int truncate(const char *path, off_t length);
676char *ttyname(int fildes);
682int ttyname_r(int fildes, char *name, size_t namesize);
688int unlink(const char *path);
694int unlinkat(int fd, const char *path, int flag);
695#if (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE < 700)) || defined(__DOXYGEN__)
701int usleep(useconds_t useconds);
702#endif
708ssize_t write(int fildes, const void *buf, size_t nbyte);
709
714extern char *optarg;
719extern int opterr;
724extern int optind;
729extern int optopt;
730
731#ifdef __cplusplus
732}
733#endif
734
735#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */
736
737#endif /* ZEPHYR_INCLUDE_POSIX_UNISTD_H_ */
POSIX configuration string constants (<sys/confstr.h>)
int pid_t
Process ID type.
Definition fcntl.h:192
long off_t
File offset type.
Definition aio.h:36
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>)
Group database entry.
Definition grp.h:27
POSIX runtime system configuration (<sys/sysconf.h>)
unsigned long useconds_t
Used for time in microseconds (obsolescent).
Definition types.h:185