unistd.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 <Kernel/API/POSIX/unistd.h>
  14. #include <fd_set.h>
  15. #include <limits.h>
  16. #include <sys/cdefs.h>
  17. __BEGIN_DECLS
  18. #define HZ 1000
  19. /* lseek whence values */
  20. #ifndef _STDIO_H /* also defined in stdio.h */
  21. # define SEEK_SET 0 /* from beginning of file. */
  22. # define SEEK_CUR 1 /* from current position in file. */
  23. # define SEEK_END 2 /* from the end of the file. */
  24. #endif
  25. extern char** environ;
  26. int get_process_name(char* buffer, int buffer_size);
  27. int set_process_name(char const* name, size_t name_length);
  28. void dump_backtrace(void);
  29. int fsync(int fd);
  30. int sysbeep(int tone);
  31. int gettid(void);
  32. int getpagesize(void);
  33. pid_t fork(void);
  34. pid_t vfork(void);
  35. int daemon(int nochdir, int noclose);
  36. int execv(char const* path, char* const argv[]);
  37. int execve(char const* filename, char* const argv[], char* const envp[]);
  38. int execvpe(char const* filename, char* const argv[], char* const envp[]);
  39. int execvp(char const* filename, char* const argv[]);
  40. int execl(char const* filename, char const* arg, ...);
  41. int execle(char const* filename, char const* arg, ...);
  42. int execlp(char const* filename, char const* arg, ...);
  43. void sync(void);
  44. __attribute__((noreturn)) void _exit(int status);
  45. pid_t getsid(pid_t);
  46. pid_t setsid(void);
  47. int setpgid(pid_t pid, pid_t pgid);
  48. pid_t getpgid(pid_t);
  49. pid_t getpgrp(void);
  50. uid_t geteuid(void);
  51. gid_t getegid(void);
  52. uid_t getuid(void);
  53. gid_t getgid(void);
  54. pid_t getpid(void);
  55. pid_t getppid(void);
  56. int getresuid(uid_t*, uid_t*, uid_t*);
  57. int getresgid(gid_t*, gid_t*, gid_t*);
  58. int getgroups(int size, gid_t list[]);
  59. int setgroups(size_t, gid_t const*);
  60. int seteuid(uid_t);
  61. int setegid(gid_t);
  62. int setuid(uid_t);
  63. int setgid(gid_t);
  64. int setreuid(uid_t, uid_t);
  65. int setresuid(uid_t, uid_t, uid_t);
  66. int setregid(gid_t, gid_t);
  67. int setresgid(gid_t, gid_t, gid_t);
  68. pid_t tcgetpgrp(int fd);
  69. int tcsetpgrp(int fd, pid_t pgid);
  70. ssize_t read(int fd, void* buf, size_t count);
  71. ssize_t pread(int fd, void* buf, size_t count, off_t);
  72. ssize_t write(int fd, void const* buf, size_t count);
  73. ssize_t pwrite(int fd, void const* buf, size_t count, off_t);
  74. int close(int fd);
  75. int chdir(char const* path);
  76. int fchdir(int fd);
  77. char* getcwd(char* buffer, size_t size);
  78. char* getwd(char* buffer);
  79. unsigned int sleep(unsigned int seconds);
  80. int usleep(useconds_t);
  81. int gethostname(char*, size_t);
  82. int sethostname(char const*, ssize_t);
  83. ssize_t readlink(char const* path, char* buffer, size_t);
  84. ssize_t readlinkat(int dirfd, char const* path, char* buffer, size_t);
  85. char* ttyname(int fd);
  86. int ttyname_r(int fd, char* buffer, size_t);
  87. off_t lseek(int fd, off_t, int whence);
  88. int link(char const* oldpath, char const* newpath);
  89. int unlink(char const* pathname);
  90. int unlinkat(int dirfd, char const* pathname, int flags);
  91. int symlink(char const* target, char const* linkpath);
  92. int symlinkat(char const* target, int newdirfd, char const* linkpath);
  93. int rmdir(char const* 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(char const* pathname, int mode);
  100. int faccessat(int dirfd, char const* pathname, int mode, int flags);
  101. int isatty(int fd);
  102. int mknod(char const* pathname, mode_t, dev_t);
  103. long fpathconf(int fd, int name);
  104. long pathconf(char const* path, int name);
  105. char* getlogin(void);
  106. int lchown(char const* pathname, uid_t uid, gid_t gid);
  107. int chown(char const* pathname, uid_t, gid_t);
  108. int fchown(int fd, uid_t, gid_t);
  109. int fchownat(int fd, char const* pathname, uid_t uid, gid_t gid, int flags);
  110. int ftruncate(int fd, off_t length);
  111. int truncate(char const* path, off_t length);
  112. int mount(int source_fd, char const* target, char const* fs_type, int flags);
  113. int umount(char const* mountpoint);
  114. int pledge(char const* promises, char const* execpromises);
  115. int unveil(char const* path, char const* permissions);
  116. char* getpass(char const* prompt);
  117. int pause(void);
  118. int chroot(char const*);
  119. int getdtablesize(void);
  120. int nice(int incr);
  121. int brk(void* addr);
  122. void* sbrk(intptr_t incr);
  123. enum {
  124. _PC_NAME_MAX,
  125. _PC_PATH_MAX,
  126. _PC_PIPE_BUF,
  127. _PC_VDISABLE,
  128. _PC_LINK_MAX
  129. };
  130. #define _POSIX_FSYNC 200112L
  131. #define _POSIX_MAPPED_FILES 200112L
  132. #define _POSIX_MEMORY_PROTECTION 200112L
  133. #define _POSIX_MONOTONIC_CLOCK 200112L
  134. #define _POSIX_RAW_SOCKETS 200112L
  135. #define _POSIX_REGEXP 1
  136. #define _POSIX_SAVED_IDS 1
  137. #define _POSIX_SPAWN 200112L
  138. #define _POSIX_THREADS 200112L
  139. #define _POSIX_THREAD_ATTR_STACKADDR 200112L
  140. #define _POSIX_THREAD_ATTR_STACKSIZE 200112L
  141. #define _POSIX_TIMERS 200809L
  142. /*
  143. * We aren't fully compliant (don't support policies, and don't have a wide
  144. * range of values), but we do have process priorities.
  145. */
  146. #define _POSIX_PRIORITY_SCHEDULING
  147. #define _POSIX_VDISABLE '\0'
  148. long sysconf(int name);
  149. // If opterr is set (the default), print error messages to stderr.
  150. extern int opterr;
  151. // On errors, optopt is set to the erroneous *character*.
  152. extern int optopt;
  153. // Index of the next argument to process upon a getopt*() call.
  154. extern int optind;
  155. // If set, reset the internal state kept by getopt*(). You may also want to set
  156. // optind to 1 in that case.
  157. extern int optreset;
  158. // After parsing an option that accept an argument, set to point to the argument
  159. // value.
  160. extern char* optarg;
  161. int getopt(int argc, char* const* argv, char const* short_options);
  162. int getsubopt(char** optionp, char* const* tokens, char** valuep);
  163. __END_DECLS