unistd.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. /* standard symbolic constants and types
  7. *
  8. * values from POSIX standard unix specification
  9. *
  10. * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html
  11. */
  12. #pragma once
  13. #include <fd_set.h>
  14. #include <limits.h>
  15. #include <sys/cdefs.h>
  16. #include <sys/types.h>
  17. __BEGIN_DECLS
  18. #define HZ 1000
  19. #define STDIN_FILENO 0
  20. #define STDOUT_FILENO 1
  21. #define STDERR_FILENO 2
  22. /* lseek whence values */
  23. #ifndef _STDIO_H /* also defined in stdio.h */
  24. # define SEEK_SET 0 /* from beginning of file. */
  25. # define SEEK_CUR 1 /* from current position in file. */
  26. # define SEEK_END 2 /* from the end of the file. */
  27. #endif
  28. extern char** environ;
  29. int get_process_name(char* buffer, int buffer_size);
  30. int set_process_name(const char* name, size_t name_length);
  31. void dump_backtrace();
  32. int fsync(int fd);
  33. void sysbeep();
  34. int gettid();
  35. int getpagesize();
  36. pid_t fork();
  37. pid_t vfork();
  38. int execv(const char* path, char* const argv[]);
  39. int execve(const char* filename, char* const argv[], char* const envp[]);
  40. int execvpe(const char* filename, char* const argv[], char* const envp[]);
  41. int execvp(const char* filename, char* const argv[]);
  42. int execl(const char* filename, const char* arg, ...);
  43. int execle(const char* filename, const char* arg, ...);
  44. int execlp(const char* filename, const char* arg, ...);
  45. int chroot(const char* path);
  46. int chroot_with_mount_flags(const char* path, int mount_flags);
  47. void sync();
  48. __attribute__((noreturn)) void _exit(int status);
  49. pid_t getsid(pid_t);
  50. pid_t setsid();
  51. int setpgid(pid_t pid, pid_t pgid);
  52. pid_t getpgid(pid_t);
  53. pid_t getpgrp();
  54. uid_t geteuid();
  55. gid_t getegid();
  56. uid_t getuid();
  57. gid_t getgid();
  58. pid_t getpid();
  59. pid_t getppid();
  60. int getresuid(uid_t*, uid_t*, uid_t*);
  61. int getresgid(gid_t*, gid_t*, gid_t*);
  62. int getgroups(int size, gid_t list[]);
  63. int setgroups(size_t, const gid_t*);
  64. int seteuid(uid_t);
  65. int setegid(gid_t);
  66. int setuid(uid_t);
  67. int setgid(gid_t);
  68. int setreuid(uid_t, uid_t);
  69. int setresuid(uid_t, uid_t, uid_t);
  70. int setresgid(gid_t, gid_t, gid_t);
  71. pid_t tcgetpgrp(int fd);
  72. int tcsetpgrp(int fd, pid_t pgid);
  73. ssize_t read(int fd, void* buf, size_t count);
  74. ssize_t pread(int fd, void* buf, size_t count, off_t);
  75. ssize_t write(int fd, const void* buf, size_t count);
  76. ssize_t pwrite(int fd, const void* buf, size_t count, off_t);
  77. int close(int fd);
  78. int chdir(const char* path);
  79. int fchdir(int fd);
  80. char* getcwd(char* buffer, size_t size);
  81. char* getwd(char* buffer);
  82. unsigned int sleep(unsigned int seconds);
  83. int usleep(useconds_t);
  84. int gethostname(char*, size_t);
  85. int sethostname(const char*, ssize_t);
  86. ssize_t readlink(const char* path, char* buffer, size_t);
  87. char* ttyname(int fd);
  88. int ttyname_r(int fd, char* buffer, size_t);
  89. off_t lseek(int fd, off_t, int whence);
  90. int link(const char* oldpath, const char* newpath);
  91. int unlink(const char* pathname);
  92. int symlink(const char* target, const char* linkpath);
  93. int rmdir(const char* pathname);
  94. int dup(int old_fd);
  95. int dup2(int old_fd, int new_fd);
  96. int pipe(int pipefd[2]);
  97. int pipe2(int pipefd[2], int flags);
  98. unsigned int alarm(unsigned int seconds);
  99. int access(const char* pathname, int mode);
  100. int isatty(int fd);
  101. int mknod(const char* pathname, mode_t, dev_t);
  102. long fpathconf(int fd, int name);
  103. long pathconf(const char* path, int name);
  104. char* getlogin();
  105. int chown(const char* pathname, uid_t, gid_t);
  106. int fchown(int fd, uid_t, gid_t);
  107. int ftruncate(int fd, off_t length);
  108. int truncate(const char* path, off_t length);
  109. int halt();
  110. int reboot();
  111. int mount(int source_fd, const char* target, const char* fs_type, int flags);
  112. int umount(const char* mountpoint);
  113. int pledge(const char* promises, const char* execpromises);
  114. int unveil(const char* path, const char* permissions);
  115. char* getpass(const char* prompt);
  116. enum {
  117. _PC_NAME_MAX,
  118. _PC_PATH_MAX,
  119. _PC_PIPE_BUF,
  120. _PC_VDISABLE
  121. };
  122. #define R_OK 4
  123. #define W_OK 2
  124. #define X_OK 1
  125. #define F_OK 0
  126. #define MS_NODEV (1 << 0)
  127. #define MS_NOEXEC (1 << 1)
  128. #define MS_NOSUID (1 << 2)
  129. #define MS_BIND (1 << 3)
  130. #define MS_RDONLY (1 << 4)
  131. #define MS_REMOUNT (1 << 5)
  132. #define _POSIX_MONOTONIC_CLOCK 200112L
  133. #define _POSIX_SAVED_IDS
  134. #define _POSIX_TIMERS 200809L
  135. /*
  136. * We aren't fully compliant (don't support policies, and don't have a wide
  137. * range of values), but we do have process priorities.
  138. */
  139. #define _POSIX_PRIORITY_SCHEDULING
  140. #define _POSIX_VDISABLE '\0'
  141. enum {
  142. _SC_MONOTONIC_CLOCK,
  143. _SC_NPROCESSORS_CONF,
  144. _SC_NPROCESSORS_ONLN,
  145. _SC_OPEN_MAX,
  146. _SC_TTY_NAME_MAX,
  147. _SC_PAGESIZE,
  148. _SC_GETPW_R_SIZE_MAX,
  149. _SC_CLK_TCK,
  150. };
  151. #define _SC_MONOTONIC_CLOCK _SC_MONOTONIC_CLOCK
  152. #define _SC_NPROCESSORS_CONF _SC_NPROCESSORS_CONF
  153. #define _SC_NPROCESSORS_ONLN _SC_NPROCESSORS_ONLN
  154. #define _SC_OPEN_MAX _SC_OPEN_MAX
  155. #define _SC_PAGESIZE _SC_PAGESIZE
  156. #define _SC_TTY_NAME_MAX _SC_TTY_NAME_MAX
  157. #define _SC_GETPW_R_SIZE_MAX _SC_GETPW_R_SIZE_MAX
  158. #define _SC_CLK_TCK _SC_CLK_TCK
  159. long sysconf(int name);
  160. // If opterr is set (the default), print error messages to stderr.
  161. extern int opterr;
  162. // On errors, optopt is set to the erroneous *character*.
  163. extern int optopt;
  164. // Index of the next argument to process upon a getopt*() call.
  165. extern int optind;
  166. // If set, reset the internal state kept by getopt*(). You may also want to set
  167. // optind to 1 in that case. Alternatively, setting optind to 0 is treated like
  168. // doing both of the above.
  169. extern int optreset;
  170. // After parsing an option that accept an argument, set to point to the argument
  171. // value.
  172. extern char* optarg;
  173. int getopt(int argc, char* const* argv, const char* short_options);
  174. __END_DECLS