Files
vlibc/include/unistd.h
T

817 lines
29 KiB
C

#ifndef VLIBC_UNISTD_H
#define VLIBC_UNISTD_H
/*
* vlibc — <unistd.h>.
*
* File descriptors, file I/O, and the access/whence symbolic constants
* (POSIX.1-2008). Every function here is an unbuffered pass-through to the
* kernel: failures are reported as -1 (or the fd/offset on success) with
* errno set by the syscall layer.
*
* Level 1 (onlyposix): read, write, pread, pwrite, open, openat, close,
* lseek, dup, dup2, pipe, fsync, fdatasync, ftruncate,
* sync, access, faccessat.
* Level 2 (muslmimic): dup3, pipe2 (Linux extensions), truncate (XSI),
* lseek64 (glibc LFS alias of lseek on x86_64).
*
* Process control (todo 20) is declared further down:
*
* Level 1 (onlyposix): fork, exec family (execl/execlp/execle/execv/
* execvp/execve/fexecve), getpid, getppid, getuid,
* geteuid, getgid, getegid, setuid, seteuid, setgid,
* setegid, getgroups, setpgid, getpgrp, setsid.
* Level 2 (muslmimic): vfork, setpgrp (obsolescent), setgroups, getpgid,
* getsid, tcgetpgrp, tcsetpgrp (XSI).
*
* System limits and options (todo 32) are declared after the process
* block:
*
* Level 1 (onlyposix): sysconf, pathconf, fpathconf, the _SC_* and _PC_*
* configuration keys.
* Level 2 (muslmimic): gethostname, sethostname, gethostid (XSI/BSD
* system identification — NOT POSIX.1-2008 base),
* and the _CS_* keys for confstr().
*
* The current-working-directory, link/symlink/readlink, path-removal and
* *at operations, the terminal-identity and login functions, getopt and
* confstr (todo 38) come after the system-limits block:
*
* Level 1 (onlyposix): getcwd, chdir, fchdir, readlink, symlink, link,
* unlink, rmdir, linkat, readlinkat, renameat,
* symlinkat, unlinkat, isatty, ttyname, ttyname_r,
* getlogin, getlogin_r, getopt plus the optarg/
* optind/opterr/optopt globals, and confstr (its
* _CS_* key constants are level 2, above).
* Level 2 (muslmimic): getwd (obsolescent), chroot, swab (XSI).
* basename/dirname live in <libgen.h> and realpath
* in <stdlib.h> (their POSIX homes), also XSI.
*
* uname() and struct utsname live in <sys/utsname.h> (todo 32).
*
* The open-flag constants (O_RDONLY, O_CREAT, O_CLOEXEC, ...) belong to
* <fcntl.h> and are deliberately not defined here; the oflag arguments below
* are plain int and take their values from that header. The optional mode
* argument of open/openat is a mode_t supplied only when oflag contains
* O_CREAT or O_TMPFILE.
*
* None of these declarations carry an intent attribute: every function
* performs I/O with side effects and reports failures through errno, so
* const/pure would be unsound. The process functions additionally must not
* be const/pure because their results are process state — marking getpid
* const, for example, would let the compiler hoist it across fork() and
* observe the parent's pid inside the child.
*/
#include <vlibc/features.h>
#include <stddef.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Level 1 (POSIX base). */
/* Access-check modes for access() and faccessat(). */
#define F_OK 0 /* existence only */
#define X_OK 1 /* execute (search for a directory) */
#define W_OK 2 /* write */
#define R_OK 4 /* read */
/* whence values for lseek() and lseek64() (also defined by <stdio.h>). */
#define SEEK_SET 0 /* from the beginning of the file */
#define SEEK_CUR 1 /* from the current position */
#define SEEK_END 2 /* from the end of the file */
/*
* Read up to nbyte bytes from fildes into buf and return the number of
* bytes read, 0 at end of file, or -1 with errno set on error. Unbuffered.
*/
ssize_t
read(int fildes, void *buf, size_t nbyte);
/*
* Write up to nbyte bytes from buf to fildes and return the number of
* bytes written, or -1 with errno set on error. Unbuffered.
*/
ssize_t
write(int fildes, const void *buf, size_t nbyte);
/*
* Read nbyte bytes from fildes starting at offset, without changing the
* file position; return the number of bytes read, or -1 with errno set.
*/
ssize_t
pread(int fildes, void *buf, size_t nbyte, off_t offset);
/*
* Write nbyte bytes from buf to fildes starting at offset, without
* changing the file position; return the number of bytes written, or -1
* with errno set.
*/
ssize_t
pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
/*
* Open path with the oflag access mode (from <fcntl.h>) and return a file
* descriptor, or -1 with errno set. A mode argument is required — and read
* from the varargs — only when oflag contains O_CREAT or O_TMPFILE.
*/
int
open(const char *path, int oflag, ...);
/*
* Like open(), but path is relative to the directory named by fd (use
* AT_FDCWD from <fcntl.h> for the current working directory). The mode
* varargs rule is the same as open().
*/
int
openat(int fd, const char *path, int oflag, ...);
/*
* Close the file descriptor fildes; return 0, or -1 with errno set.
*/
int
close(int fildes);
/*
* Reposition the file offset of fildes to offset per whence (SEEK_SET,
* SEEK_CUR, SEEK_END) and return the resulting offset, or (off_t)-1 with
* errno set. The full 64-bit offset is returned; errno is untouched on
* success.
*/
off_t
lseek(int fildes, off_t offset, int whence);
/*
* Duplicate fildes to the lowest-numbered free descriptor; return it, or
* -1 with errno set. The copy shares the file description (position,
* flags, locks) with the original.
*/
int
dup(int fildes);
/*
* Duplicate fildes onto fildes2, closing fildes2 first if it was open;
* return fildes2, or -1 with errno set. dup2(f, f) returns f without
* doing anything (POSIX).
*/
int
dup2(int fildes, int fildes2);
/*
* Create a pipe: fildes[0] becomes the read end, fildes[1] the write end.
* Return 0, or -1 with errno set. No descriptor flags are set (unlike
* pipe2, this is plain POSIX).
*/
int
pipe(int fildes[2]);
/*
* Flush all buffered modifications of fildes and its metadata to stable
* storage; return 0, or -1 with errno set.
*/
int
fsync(int fildes);
/*
* Like fsync(), but may skip the metadata work needed only to preserve
* file contents; return 0, or -1 with errno set.
*/
int
fdatasync(int fildes);
/*
* Truncate fildes to length bytes; return 0, or -1 with errno set.
*/
int
ftruncate(int fildes, off_t length);
/*
* Flush all filesystem caches to stable storage. Returns nothing.
*/
void
sync(void);
/*
* Check accessibility of path under amode (R_OK, W_OK, X_OK, F_OK); return
* 0, or -1 with errno set. Uses the real IDs of the calling process.
*/
int
access(const char *path, int amode);
/*
* Like access(), but path is relative to the directory named by fd (use
* AT_FDCWD for the current working directory) and flag may hold
* AT_EACCESS; return 0, or -1 with errno set.
*/
int
faccessat(int fd, const char *path, int amode, int flag);
/* Level 1 (POSIX base): process control. */
/*
* Create a child process that is a copy of the caller: fork() returns 0
* in the child, the child's pid in the parent, and -1 with errno set on
* failure.
*
* Around the fork, the atfork hook table runs: the prepare handlers in
* reverse registration order before the fork, then the child handlers in
* the child and the parent handlers in the parent, both in registration
* order (POSIX pthread_atfork protocol). The table is registered by
* pthread_atfork() (todo 45) and is empty — a no-op — in a process
* without threads.
*/
pid_t
fork(void);
/*
* Replace the calling process image. Success never returns; -1 with
* errno set otherwise. execl/execle/execlp take the arguments as a
* varargs list terminated by (char *)NULL (execle is followed by one
* final char *const envp[] argument); execv/execvp take an argv array.
* execvp and execlp search the PATH environment variable (default
* "/bin:/usr/bin") when file contains no '/'. execv/execvp/execl/execlp
* use the caller's environment; execve/execle/fexecve take envp.
*/
// NOLINTBEGIN(bugprone-easily-swappable-parameters)
int
execl(const char *path, const char *arg0, ...);
int
execle(const char *path, const char *arg0, ...);
int
execlp(const char *file, const char *arg0, ...);
// NOLINTEND(bugprone-easily-swappable-parameters)
int
execv(const char *path, char *const argv[]);
int
execvp(const char *file, char *const argv[]);
int
execve(const char *path, char *const argv[], char *const envp[]);
/*
* Like execve, but the image is the open descriptor fd.
*/
int
fexecve(int fd, char *const argv[], char *const envp[]);
/*
* Process ids. getpid/getppid/getuid/geteuid/getgid/getegid read the
* kernel's per-process ids; setuid/seteuid/setgid/setegid change them.
* seteuid/setegid change only the effective id (setresuid/setresgid
* underneath: Linux has no seteuid/setegid syscall).
*/
pid_t
getpid(void);
pid_t
getppid(void);
uid_t
getuid(void);
uid_t
geteuid(void);
gid_t
getgid(void);
gid_t
getegid(void);
int
setuid(uid_t uid);
int
seteuid(uid_t euid);
int
setgid(gid_t gid);
int
setegid(gid_t egid);
/*
* Supplementary groups: getgroups fills grouplist with up to gidsetsize
* group ids and returns the total count (0 can be passed to count only);
* setgroups (level 2, XSI) installs the list.
*/
int
getgroups(int gidsetsize, gid_t grouplist[]);
/*
* Session control: setpgid moves pid into process group pgid (0 means
* the caller / the caller's pid); getpgrp returns the caller's process
* group; setsid creates a new session with the caller as leader and
* returns the new session id.
*/
int
setpgid(pid_t pid, pid_t pgid);
pid_t
getpgrp(void);
pid_t
setsid(void);
/* Level 1 (POSIX base): system limits and options. */
/*
* The configuration keys for sysconf(), pathconf() and fpathconf(), and
* (level 2) the _CS_* keys for confstr() (todo 38).
*
* POSIX defines the _SC_* and _PC_* names and the SEMANTICS of the values
* the configuration functions return for them, but NOT their numeric
* values: those are private to each C library (glibc numbers them
* arbitrarily in <bits/confname.h>, musl in a private table). The values
* below are vlibc's OWN stable ABI, assigned in declaration order and never
* reused — program source must pass the symbolic constants, never literal
* integers. They are deliberately NOT glibc's numbers. Any value outside
* these enums is unknown to the configuration functions and yields -1
* without errno (the unsupported-key convention, see below).
*/
/* NOLINTBEGIN(bugprone-reserved-identifier) -- POSIX-mandated _SC_/_PC_ names */
enum
{
/* Process and file limits (sysconf). */
_SC_ARG_MAX = 0, /* max bytes of arguments + environment for exec */
_SC_CHILD_MAX, /* max simultaneous processes per real user id */
_SC_CLK_TCK, /* clock ticks per second, the times() unit (100) */
_SC_NGROUPS_MAX, /* max supplementary group ids */
_SC_OPEN_MAX, /* max open file descriptors per process */
_SC_PAGESIZE, /* memory page size in bytes (from AT_PAGESZ) */
_SC_PAGE_SIZE, /* POSIX synonym of _SC_PAGESIZE */
_SC_NPROCESSORS_CONF, /* number of processors configured */
_SC_NPROCESSORS_ONLN, /* number of processors online */
_SC_PHYS_PAGES, /* number of physical memory pages */
_SC_AVPHYS_PAGES, /* number of currently available memory pages */
_SC_SYMLOOP_MAX, /* max symlink traversals while resolving a path */
_SC_STREAM_MAX, /* max open standard I/O streams (FOPEN_MAX) */
_SC_TZNAME_MAX, /* max bytes in a timezone name */
_SC_VERSION, /* POSIX.1 version, 200809L */
_SC_2_VERSION, /* POSIX.2 version, 200809L */
_SC_JOB_CONTROL, /* 1 if job control is supported */
_SC_SAVED_IDS, /* 1 if saved set-user/group-id is supported */
_SC_HOST_NAME_MAX, /* max bytes in a host name (excluding NUL) */
_SC_LOGIN_NAME_MAX, /* max bytes in a login name */
_SC_GETPW_R_SIZE_MAX, /* recommended buffer size for getpw*_r */
_SC_IOV_MAX, /* max iovec entries in readv/writev */
_SC_LINE_MAX, /* max bytes in an input line (POSIX.2) */
_SC_RE_DUP_MAX, /* max duplicate regexp interval counts */
_SC_COLL_WEIGHTS_MAX, /* max weights for collating elements */
_SC_EXPR_NEST_MAX, /* max expression nesting in expr(1) */
/* POSIX option indicators (sysconf). Values follow the _POSIX_*
* convention: a version value means supported, -1 unsupported. */
_SC_THREADS, /* _POSIX_THREADS */
_SC_SEMAPHORES, /* _POSIX_SEMAPHORES */
_SC_SHARED_MEMORY_OBJECTS, /* _POSIX_SHARED_MEMORY_OBJECTS */
_SC_MESSAGE_PASSING, /* _POSIX_MESSAGE_PASSING */
_SC_MONOTONIC_CLOCK, /* _POSIX_MONOTONIC_CLOCK */
_SC_TIMERS, /* _POSIX_TIMERS */
_SC_SYNCHRONIZED_IO, /* _POSIX_SYNCHRONIZED_IO */
_SC_THREAD_SAFE_FUNCTIONS, /* _POSIX_THREAD_SAFE_FUNCTIONS */
_SC_THREAD_ATTR_STACKADDR, /* _POSIX_THREAD_ATTR_STACKADDR */
_SC_THREAD_ATTR_STACKSIZE, /* _POSIX_THREAD_ATTR_STACKSIZE */
_SC_THREAD_PRIORITY_SCHEDULING, /* _POSIX_THREAD_PRIORITY_SCHEDULING */
_SC_THREAD_PRIO_INHERIT, /* _POSIX_THREAD_PRIO_INHERIT */
_SC_THREAD_PRIO_PROTECT, /* _POSIX_THREAD_PRIO_PROTECT */
_SC_THREAD_PROCESS_SHARED, /* _POSIX_THREAD_PROCESS_SHARED */
_SC_REALTIME_SIGNALS, /* _POSIX_REALTIME_SIGNALS */
/* POSIX.1-2008 option indicators that use plain 1 for supported. */
_SC_REGEXP, /* 1 if the RE functions are supported */
_SC_SHELL, /* 1 if the shell is supported */
_SC_XOPEN_VERSION, /* XSI version, 700 */
_SC_XOPEN_UNIX, /* 1 if XSI interfaces are supported */
_SC_XOPEN_CRYPT, /* 1 if the crypt function is available */
_SC_XOPEN_ENH_I18N, /* 1 if enhanced internationalization is present */
_SC_XOPEN_SHM, /* 1 if XSI shared memory is present */
_SC_2_C_BIND, /* POSIX.2 C-language binding */
_SC_2_C_DEV, /* POSIX.2 C-language development utilities */
_SC_2_FORT_DEV, /* POSIX.2 FORTRAN development utilities */
_SC_2_FORT_RUN, /* POSIX.2 FORTRAN runtime utilities */
_SC_2_LOCALEDEF, /* POSIX.2 locale creation utilities */
_SC_2_SW_DEV, /* POSIX.2 software development utilities */
_SC_2_UPE /* POSIX.2 user-portability utilities */
};
/*
* The _PC_* keys for pathconf() and fpathconf(). Each names a limit or an
* option of the FILESYSTEM holding the queried path or descriptor; see the
* pathconf() documentation below for the supported keys and their values.
*/
enum
{
_PC_LINK_MAX = 0, /* max link count of a file */
_PC_MAX_CANON, /* max bytes in a terminal canonical input line */
_PC_MAX_INPUT, /* max bytes available on a terminal input queue */
_PC_NAME_MAX, /* max bytes in a file name (excluding NUL) */
_PC_PATH_MAX, /* max bytes in a pathname (excluding NUL) */
_PC_PIPE_BUF, /* max bytes atomically writable to a pipe */
_PC_CHOWN_RESTRICTED, /* 1 if chown is restricted to the owner */
_PC_NO_TRUNC, /* 1 if overlong file names are an error */
_PC_VDISABLE, /* the terminal disable character (0 = none) */
_PC_ASYNC_IO, /* 200809L if asynchronous I/O is supported */
_PC_SYNC_IO, /* 200809L if synchronized I/O is supported */
_PC_PRIO_IO, /* 200809L if prioritized I/O is supported */
_PC_SOCK_MAXBUF, /* max bytes storable in a socket buffer */
_PC_FILESIZEBITS, /* bits in a file size field */
_PC_REC_INCR_XFER_SIZE, /* recommended increment for transfer sizes */
_PC_REC_MAX_XFER_SIZE, /* recommended maximum transfer size */
_PC_REC_MIN_XFER_SIZE, /* recommended minimum transfer size */
_PC_REC_XFER_ALIGN, /* recommended transfer alignment */
_PC_ALLOC_SIZE_MIN, /* minimum bytes of a file allocation */
_PC_SYMLINK_MAX, /* max bytes in a symbolic link target */
_PC_2_SYMLINKS /* 1 if symlinks support the ".." resolution rule */
};
/* NOLINTEND(bugprone-reserved-identifier) */
/*
* Query a system configuration value for key name (one of the _SC_* above)
* and return it as a long. A negative value means the option is not
* supported or the key is unknown; for unsupported options and for any key
* outside the _SC_* enum, -1 is returned WITHOUT setting errno (callers
* must not rely on errno after -1).
*
* The supported keys and their vlibc values: _SC_ARG_MAX (2097152),
* _SC_CHILD_MAX (65535), _SC_CLK_TCK (100, the fixed x86_64 clock-tick
* rate — see the note in src/misc/sysconf.c, todo 35's times() consumes
* that same constant), _SC_NGROUPS_MAX (65536), _SC_OPEN_MAX (the current
* RLIMIT_NOFILE soft limit, 1024 if it cannot be read), _SC_PAGESIZE and
* _SC_PAGE_SIZE (the memory page size from the AT_PAGESZ auxiliary vector
* entry, 4096 on x86_64), _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN
* (the processor count), _SC_PHYS_PAGES and _SC_AVPHYS_PAGES (physical and
* available memory page counts), _SC_SYMLOOP_MAX (40), _SC_STREAM_MAX
* (16), _SC_TZNAME_MAX (6), _SC_VERSION and _SC_2_VERSION (200809L),
* _SC_JOB_CONTROL, _SC_SAVED_IDS, _SC_REGEXP, _SC_SHELL (1 each),
* _SC_HOST_NAME_MAX (64), _SC_LOGIN_NAME_MAX (256), _SC_GETPW_R_SIZE_MAX
* (1024), _SC_IOV_MAX (1024), _SC_LINE_MAX (2048), _SC_RE_DUP_MAX (32767),
* _SC_COLL_WEIGHTS_MAX (255), _SC_EXPR_NEST_MAX (32), _SC_XOPEN_VERSION
* (700), _SC_XOPEN_UNIX, _SC_XOPEN_CRYPT, _SC_XOPEN_ENH_I18N, _SC_XOPEN_SHM
* (1 each), and the thread/option version keys (_SC_THREADS ... _SC_2_UPE,
* 200809L each).
*/
long
sysconf(int name);
/*
* Query a configurable limit or option of the filesystem holding path (the
* _PC_* keys above) and return it as a long; -1 with errno set when path
* cannot be examined. Fixed values: _PC_LINK_MAX (32000), _PC_MAX_CANON
* and _PC_MAX_INPUT (255), _PC_PATH_MAX (4096), _PC_PIPE_BUF (4096),
* _PC_CHOWN_RESTRICTED, _PC_NO_TRUNC and _PC_2_SYMLINKS (1), _PC_VDISABLE
* (0), _PC_FILESIZEBITS (64), and _PC_REC_MIN_XFER_SIZE,
* _PC_REC_XFER_ALIGN and _PC_ALLOC_SIZE_MIN (the filesystem block size).
* _PC_NAME_MAX is the filesystem's f_namelen (255 on ext4/xfs). For keys
* whose option the filesystem does not provide (_PC_ASYNC_IO, _PC_SYNC_IO,
* _PC_PRIO_IO, _PC_SOCK_MAXBUF, _PC_REC_INCR_XFER_SIZE,
* _PC_REC_MAX_XFER_SIZE, _PC_SYMLINK_MAX) and for any key outside the
* _PC_* enum, -1 is returned WITHOUT setting errno.
*/
long
pathconf(const char *path, int name);
/*
* Like pathconf(), but the filesystem is the one holding the open
* descriptor fildes.
*/
long
fpathconf(int fildes, int name);
/* Level 1 (POSIX base): current directory, links, and path operations. */
/*
* Store the absolute pathname of the current working directory into buf.
* When buf is NULL, the path is returned in a malloc'd buffer instead
* (size is then only a hint: 0 grows from a default of 128 bytes, and
* the buffer is enlarged as the kernel reports ERANGE); the caller must
* free it. Return buf (or the malloc'd buffer), or NULL with errno set
* (EINVAL for a non-NULL buf with size 0).
*/
char *
getcwd(char *buf, size_t size);
/*
* Change the current working directory to path (chdir) or to the
* directory referred to by the open descriptor fildes (fchdir). Return
* 0, or -1 with errno set.
*/
int
chdir(const char *path);
int
fchdir(int fildes);
/*
* Create a symbolic link: path2 is created as a link whose contents are
* the string path1 (which need not exist). Return 0, or -1 with errno
* set.
*/
int
symlink(const char *path1, const char *path2);
/*
* Like symlink(), but the link is created in the directory named by fd
* when path2 is relative (use AT_FDCWD for the current working
* directory). Return 0, or -1 with errno set.
*/
int
symlinkat(const char *path1, int fd, const char *path2);
/*
* Read the contents of the symbolic link path into buf (bufsize bytes,
* no NUL is appended) and return the number of bytes placed in buf, 0
* for an empty target, or -1 with errno set. The buffer is not
* terminated: callers sized for bufsize + 1 append the NUL themselves.
*/
ssize_t
readlink(const char *restrict path, char *restrict buf, size_t bufsize);
/*
* Like readlink(), but path is resolved in the directory named by fd
* when relative. Return the number of bytes placed in buf, or -1 with
* errno set.
*/
ssize_t
readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize);
/*
* Create a hard link: new is created as a second name for the file old
* (which must not be a directory and must be on the same filesystem).
* Return 0, or -1 with errno set.
*/
int
link(const char *old, const char *new);
/*
* Like link(), but old and new are resolved against the directories
* named by fd1 and fd2 when relative (AT_FDCWD selects the current
* working directory) and flag may hold AT_SYMLINK_FOLLOW from <fcntl.h>.
* Return 0, or -1 with errno set.
*/
int
linkat(int fd1, const char *old, int fd2, const char *new, int flag);
/*
* Remove the name path (a hard link; symbolic links are removed, not
* followed). Return 0, or -1 with errno set.
*/
int
unlink(const char *path);
/*
* Like unlink(), but path is resolved in the directory named by fd when
* relative and flag may hold AT_REMOVEDIR from <fcntl.h> (making it
* remove an empty directory instead). Return 0, or -1 with errno set.
*/
int
unlinkat(int fd, const char *path, int flag);
/*
* Remove the empty directory path. Return 0, or -1 with errno set
* (ENOTEMPTY/EEXIST when the directory is not empty).
*/
int
rmdir(const char *path);
/*
* Rename old to new within the filesystem: old is resolved against fd1
* and new against fd2 (AT_FDCWD for the current working directory). Both
* names may be directories. Return 0, or -1 with errno set.
*/
int
renameat(int fd1, const char *old, int fd2, const char *new);
/* Level 1 (POSIX base): terminal identity, login name, getopt, confstr. */
/*
* Test whether fildes refers to a terminal. Return 1 when it does, and
* 0 otherwise (errno may be set — e.g. EBADF — but the caller must not
* rely on it after a 0 return).
*/
int
isatty(int fildes);
/*
* Return the pathname of the terminal open on fildes in a shared static
* buffer (overwritten by the next call), or NULL with errno set when
* fildes is not a terminal. ttyname_r stores the path in the caller's
* name buffer instead and returns 0, or an error NUMBER (ENOTTY when
* fildes is not a terminal, ERANGE when the name does not fit in
* namesize).
*/
char *
ttyname(int fildes);
int
ttyname_r(int fildes, char *name, size_t namesize);
/*
* Return the login name of the user associated with the calling process
* (the owner of its controlling terminal) in a shared static buffer, or
* NULL with errno set when the name cannot be determined. getlogin_r
* stores the name in the caller's buffer and returns 0, or an error
* number (ERANGE when the name does not fit in namesize).
*/
char *
getlogin(void);
int
getlogin_r(char *name, size_t namesize);
/*
* Command-line option parsing (POSIX.1-2008). getopt returns the next
* option character from argv per the option characters in optstring; a
* character followed by ':' in optstring takes an argument (delivered in
* optarg). A leading ':' in optstring makes missing-argument errors
* return ':' silently instead of '?' with a diagnostic to stderr.
* Return -1 when all options have been consumed: optind then points at
* the first non-option argument, and "--" terminates the scan.
*/
int
getopt(int argc, char *const argv[], const char *optstring);
/* The getopt option state (POSIX.1-2008 base). */
extern char *optarg; /* the argument of the option just returned */
extern int optind; /* index of the next argument to scan (init 1) */
extern int opterr; /* nonzero: write diagnostics to stderr (init 1) */
extern int optopt; /* the option character that caused an error */
/*
* Query the implementation-defined string value of configuration name
* (one of the _CS_* keys above). When buf is not NULL and len is large
* enough, the value (NUL-terminated) is copied into buf; the return
* value is the length of the value including the terminating NUL, so a
* return greater than len means the buffer was too small and nothing was
* copied. For an unknown name, 0 is returned and errno is set to EINVAL.
*/
size_t
confstr(int name, char *buf, size_t len);
#if VLIBC_LEVEL_GE(2)
/* Level 2 (muslmimic): Linux extensions + XSI + obsolescent. */
/*
* Store the current working directory into pathname, which must hold at
* least PATH_MAX bytes. Return pathname, or NULL with errno set.
* Obsolescent: prefer getcwd().
*/
char *
getwd(char *pathname);
/*
* Change the process root directory to path (used with chdir by
* chroot-style confinement). Requires privilege. Return 0, or -1 with
* errno set. XSI.
*/
int
chroot(const char *path);
/*
* Copy nbytes bytes from from to to, swapping each adjacent pair of
* bytes (the odd byte of an odd count is not copied). Used for historic
* byte-order conversion; returns nothing. XSI.
*/
void
swab(const void *restrict from, void *restrict to, ssize_t nbytes);
/*
* Like dup2(), but with descriptor flags (O_CLOEXEC from <fcntl.h>) applied
* atomically; return fildes2, or -1 with errno set. Linux-specific.
*/
int
dup3(int fildes, int fildes2, int flags);
/*
* Like pipe(), but with descriptor flags (e.g. O_CLOEXEC) applied
* atomically; return 0, or -1 with errno set. Linux-specific.
*/
int
pipe2(int fildes[2], int flags);
/*
* Truncate the file named by path to length bytes; return 0, or -1 with
* errno set. XSI.
*/
int
truncate(const char *path, off_t length);
/*
* glibc LFS alias of lseek(): on x86_64 the LFS and non-LFS off_t are
* identical (both 64-bit), so this simply calls lseek(). Provided for
* source compatibility only.
*/
off_t
lseek64(int fildes, off_t offset, int whence);
/*
* vfork (obsolescent): like fork(), but the child borrows the parent's
* address space until it execs or exits.
*/
pid_t
vfork(void);
/*
* setpgrp (obsolescent): setpgid(0, 0) — the caller becomes the leader
* of its own process group.
*/
int
setpgrp(void);
/*
* setgroups (XSI): install the supplementary group list of gidsetsize
* entries. Requires privilege.
*/
int
setgroups(size_t gidsetsize, const gid_t *grouplist);
/*
* getpgid/getsid (XSI): the process group / session of pid (0 = the
* caller).
*/
pid_t
getpgid(pid_t pid);
pid_t
getsid(pid_t pid);
/*
* Controlling-terminal foreground process group (XSI): tcgetpgrp reads
* the foreground group of the terminal on fildes; tcsetpgrp makes pgid
* the foreground group.
*/
pid_t
tcgetpgrp(int fildes);
int
tcsetpgrp(int fildes, pid_t pgid);
/* Level 2 (muslmimic): system identification (XSI / BSD, not POSIX base). */
/*
* The _CS_* keys for confstr() (todo 38, which owns the function and its
* string results). Values are vlibc-local ABI like the _SC_ and _PC_ keys
* above; they are defined here now so todo 38 only implements confstr()
* itself.
*/
/* NOLINTBEGIN(bugprone-reserved-identifier) -- POSIX-mandated _CS_ names */
enum
{
_CS_PATH = 0, /* value of PATH (always a usable default) */
_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS, /* 1 if the V6 width-restricted envs exist */
_CS_POSIX_V7_WIDTH_RESTRICTED_ENVS, /* 1 if the V7 width-restricted envs exist */
_CS_LFS_CFLAGS, /* cpp/cflags for large-file support */
_CS_LFS_LDFLAGS, /* ld flags for large-file support */
_CS_LFS_LIBS, /* libraries for large-file support */
_CS_LFS_LINTFLAGS, /* lint flags for large-file support */
_CS_LFS64_CFLAGS, /* cpp/cflags for large-file64 support */
_CS_LFS64_LDFLAGS, /* ld flags for large-file64 support */
_CS_LFS64_LIBS, /* libraries for large-file64 support */
_CS_LFS64_LINTFLAGS, /* lint flags for large-file64 support */
_CS_GNU_LIBC_VERSION, /* "glibc X.Y" (vlibc extension) */
_CS_GNU_LIBPTHREAD_VERSION /* "NPTL X.Y" (vlibc extension) */
};
/* NOLINTEND(bugprone-reserved-identifier) */
/*
* Store the NUL-terminated host name of the current machine into name,
* sized len bytes. Return 0 on success; if the name (including its NUL
* terminator) does not fit in len bytes, nothing is written beyond the
* fit and -1 is returned with errno set to ENAMETOOLONG. XSI.
*/
int
gethostname(char *name, size_t len);
/*
* Set the kernel's host name from name (len bytes, no NUL required).
* Requires privilege. Return 0, or -1 with errno set. BSD, not POSIX.
*/
int
sethostname(const char *name, size_t len);
/*
* Return the 32-bit host identifier of the current machine. vlibc returns
* 0 (musl's behavior): the historic value was derived from the host's
* primary IP address via gethostbyname, which the modern library does not
* perform. [OB] — obsolescent in POSIX.
*/
long
gethostid(void);
#endif /* VLIBC_LEVEL_GE(2) */
#ifdef __cplusplus
}
#endif
#endif /* VLIBC_UNISTD_H */