unistd.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /****************************************************************************
  2. * include/unistd.h
  3. *
  4. * Copyright (C) 2007-2009, 2013-2014, 2016-2019 Gregory Nutt. All rights
  5. * reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. Neither the name NuttX nor the names of its contributors may be
  19. * used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ****************************************************************************/
  36. #ifndef __INCLUDE_UNISTD_H
  37. #define __INCLUDE_UNISTD_H
  38. /****************************************************************************
  39. * Included Files
  40. ****************************************************************************/
  41. #include <sys/types.h>
  42. #include <nuttx/compiler.h>
  43. /****************************************************************************
  44. * Pre-processor Definitions
  45. ****************************************************************************/
  46. /* Values for seeking */
  47. #define SEEK_SET 0 /* From the start of the file */
  48. #define SEEK_CUR 1 /* From the current file offset */
  49. #define SEEK_END 2 /* From the end of the file */
  50. /* Bit values for the second argument to access */
  51. #define F_OK 0 /* Test existence */
  52. #define X_OK 1 /* Test execute permission */
  53. #define W_OK 2 /* Test write permission */
  54. #define R_OK 4 /* Test read permission */
  55. /* POSIX feature set macros */
  56. #define POSIX_VERSION
  57. #undef _POSIX_SAVED_IDS
  58. #undef _POSIX_JOB_CONTROL
  59. #define _POSIX_REALTIME_SIGNALS 1
  60. #define _POSIX_MESSAGE_PASSING 1
  61. #undef _POSIX_MAPPED_FILES
  62. #undef _POSIX_SHARED_MEMORY_OBJECTS
  63. #define _POSIX_PRIORITY_SCHEDULING 1
  64. #define _POSIX_TIMERS 1
  65. #undef _POSIX_MEMLOCK
  66. #undef _POSIX_MEMLOCK_RANGE
  67. #undef _POSIX_FSYNC
  68. #define _POSIX_SYNCHRONIZED_IO 1
  69. #ifdef CONFIG_FS_AIO
  70. # define _POSIX_ASYNCHRONOUS_IO 1
  71. #else
  72. # undef _POSIX_ASYNCHRONOUS_IO
  73. #endif
  74. #undef _POSIX_PRIORITIZED_IO
  75. #ifdef CONFIG_SCHED_SPORADIC
  76. # define _POSIX_SPORADIC_SERVER 1
  77. # define _POSIX_THREAD_SPORADIC_SERVER 1
  78. #else
  79. # undef _POSIX_SPORADIC_SERVER
  80. # undef _POSIX_THREAD_SPORADIC_SERVER
  81. #endif
  82. /* Execution time constants (not supported) */
  83. #undef _POSIX_CHOWN_RESTRICTED
  84. #undef _POSIX_NO_TRUNC
  85. #undef _POSIX_VDISABLE
  86. #define _POSIX_SYNC_IO 1
  87. #undef _POSIX_ASYNC_IO
  88. #undef _POSIX_PRIO_IO
  89. /* Constants used with POSIX pathconf(). pathconf() will return -1 and set
  90. * errno to ENOSYS for most of these.
  91. */
  92. #define _PC_2_SYMLINKS 0x0001
  93. #define _PC_ALLOC_SIZE_MIN 0x0002
  94. #define _PC_ASYNC_IO 0x0003
  95. #define _PC_CHOWN_RESTRICTED 0x0004
  96. #define _PC_FILESIZEBITS 0x0005
  97. #define _PC_LINK_MAX 0x0006
  98. #define _PC_MAX_CANON 0x0007
  99. #define _PC_MAX_INPUT 0x0008
  100. #define _PC_NAME_MAX 0x0009
  101. #define _PC_NO_TRUNC 0x000a
  102. #define _PC_PATH_MAX 0x000b
  103. #define _PC_PIPE_BUF 0x000c
  104. #define _PC_PRIO_IO 0x000d
  105. #define _PC_REC_INCR_XFER_SIZE 0x000e
  106. #define _PC_REC_MIN_XFER_SIZE 0x000f
  107. #define _PC_REC_XFER_ALIGN 0x0010
  108. #define _PC_SYMLINK_MAX 0x0011
  109. #define _PC_SYNC_IO 0x0012
  110. #define _PC_VDISABLE 0x0013
  111. /* Constants used with POSIX sysconf(). sysconf() will return -1 and set
  112. * errno to ENOSYS for most of these.
  113. */
  114. #define _SC_2_C_BIND 0x0001
  115. #define _SC_2_C_DEV 0x0002
  116. #define _SC_2_CHAR_TERM 0x0003
  117. #define _SC_2_FORT_DEV 0x0004
  118. #define _SC_2_FORT_RUN 0x0005
  119. #define _SC_2_LOCALEDEF 0x0006
  120. #define _SC_2_PBS 0x0007
  121. #define _SC_2_PBS_ACCOUNTING 0x0008
  122. #define _SC_2_PBS_CHECKPOINT 0x0009
  123. #define _SC_2_PBS_LOCATE 0x000a
  124. #define _SC_2_PBS_MESSAGE 0x000b
  125. #define _SC_2_PBS_TRACK 0x000c
  126. #define _SC_2_SW_DEV 0x000d
  127. #define _SC_2_UPE 0x000e
  128. #define _SC_2_VERSION 0x000f
  129. #define _SC_ADVISORY_INFO 0x0010
  130. #define _SC_AIO_LISTIO_MAX 0x0011
  131. #define _SC_AIO_MAX 0x0012
  132. #define _SC_AIO_PRIO_DELTA_MAX 0x0013
  133. #define _SC_ARG_MAX 0x0014
  134. #define _SC_ASYNCHRONOUS_IO 0x0015
  135. #define _SC_ATEXIT_MAX 0x0016
  136. #define _SC_BARRIERS 0x0017
  137. #define _SC_BC_BASE_MAX 0x0018
  138. #define _SC_BC_DIM_MAX 0x0019
  139. #define _SC_BC_SCALE_MAX 0x001a
  140. #define _SC_BC_STRING_MAX 0x001b
  141. #define _SC_CHILD_MAX 0x001c
  142. #define _SC_CLK_TCK 0x001d
  143. #define _SC_CLOCK_SELECTION 0x001e
  144. #define _SC_COLL_WEIGHTS_MAX 0x001f
  145. #define _SC_CPUTIME 0x0020
  146. #define _SC_DELAYTIMER_MAX 0x0021
  147. #define _SC_EXPR_NEST_MAX 0x0022
  148. #define _SC_FSYNC 0x0023
  149. #define _SC_GETGR_R_SIZE_MAX 0x0024
  150. #define _SC_GETPW_R_SIZE_MAX 0x0025
  151. #define _SC_HOST_NAME_MAX 0x0026
  152. #define _SC_IOV_MAX 0x0027
  153. #define _SC_IPV6 0x0028
  154. #define _SC_JOB_CONTROL 0x0029
  155. #define _SC_LINE_MAX 0x002a
  156. #define _SC_LOGIN_NAME_MAX 0x002b
  157. #define _SC_MAPPED_FILES 0x002c
  158. #define _SC_MEMLOCK 0x002d
  159. #define _SC_MEMLOCK_RANGE 0x002e
  160. #define _SC_MEMORY_PROTECTION 0x002f
  161. #define _SC_MESSAGE_PASSING 0x0030
  162. #define _SC_MONOTONIC_CLOCK 0x0031
  163. #define _SC_MQ_OPEN_MAX 0x0032
  164. #define _SC_MQ_PRIO_MAX 0x0033
  165. #define _SC_NGROUPS_MAX 0x0034
  166. #define _SC_OPEN_MAX 0x0035
  167. #define _SC_PAGE_SIZE 0x0036
  168. #define _SC_PAGESIZE _SC_PAGE_SIZE
  169. #define _SC_PRIORITIZED_IO 0x0037
  170. #define _SC_PRIORITY_SCHEDULING 0x0038
  171. #define _SC_RAW_SOCKETS 0x0039
  172. #define _SC_RE_DUP_MAX 0x003a
  173. #define _SC_READER_WRITER_LOCKS 0x003b
  174. #define _SC_REALTIME_SIGNALS 0x003c
  175. #define _SC_REGEXP 0x003d
  176. #define _SC_RTSIG_MAX 0x003e
  177. #define _SC_SAVED_IDS 0x003f
  178. #define _SC_SEM_NSEMS_MAX 0x0040
  179. #define _SC_SEM_VALUE_MAX 0x0041
  180. #define _SC_SEMAPHORES 0x0042
  181. #define _SC_SHARED_MEMORY_OBJECTS 0x0043
  182. #define _SC_SHELL 0x0044
  183. #define _SC_SIGQUEUE_MAX 0x0045
  184. #define _SC_SPAWN 0x0046
  185. #define _SC_SPIN_LOCKS 0x0047
  186. #define _SC_SPORADIC_SERVER 0x0048
  187. #define _SC_SS_REPL_MAX 0x0049
  188. #define _SC_STREAM_MAX 0x004a
  189. #define _SC_SYMLOOP_MAX 0x004b
  190. #define _SC_SYNCHRONIZED_IO 0x004c
  191. #define _SC_THREAD_ATTR_STACKADDR 0x004d
  192. #define _SC_THREAD_ATTR_STACKSIZE 0x004e
  193. #define _SC_THREAD_CPUTIME 0x004f
  194. #define _SC_THREAD_DESTRUCTOR_ITERATIONS 0x0050
  195. #define _SC_THREAD_KEYS_MAX 0x0051
  196. #define _SC_THREAD_PRIO_INHERIT 0x0052
  197. #define _SC_THREAD_PRIO_PROTECT 0x0053
  198. #define _SC_THREAD_PRIORITY_SCHEDULING 0x0054
  199. #define _SC_THREAD_PROCESS_SHARED 0x0055
  200. #define _SC_THREAD_SAFE_FUNCTIONS 0x0056
  201. #define _SC_THREAD_SPORADIC_SERVER 0x0057
  202. #define _SC_THREAD_STACK_MIN 0x0058
  203. #define _SC_THREAD_THREADS_MAX 0x0059
  204. #define _SC_THREADS 0x005a
  205. #define _SC_TIMEOUTS 0x005b
  206. #define _SC_TIMER_MAX 0x005c
  207. #define _SC_TIMERS 0x005d
  208. #define _SC_TRACE 0x005e
  209. #define _SC_TRACE_EVENT_FILTER 0x005f
  210. #define _SC_TRACE_EVENT_NAME_MAX 0x0060
  211. #define _SC_TRACE_INHERIT 0x0061
  212. #define _SC_TRACE_LOG 0x0062
  213. #define _SC_TRACE_NAME_MAX 0x0063
  214. #define _SC_TRACE_SYS_MAX 0x0064
  215. #define _SC_TRACE_USER_EVENT_MAX 0x0065
  216. #define _SC_TTY_NAME_MAX 0x0066
  217. #define _SC_TYPED_MEMORY_OBJECTS 0x0067
  218. #define _SC_TZNAME_MAX 0x0068
  219. #define _SC_V6_ILP32_OFF32 0x0069
  220. #define _SC_V6_ILP32_OFFBIG 0x006a
  221. #define _SC_V6_LP64_OFF64 0x006b
  222. #define _SC_V6_LPBIG_OFFBIG 0x006c
  223. #define _SC_VERSION 0x006d
  224. #define _SC_XBS5_ILP32_OFF32 0x006e /* (LEGACY) */
  225. #define _SC_XBS5_ILP32_OFFBIG 0x006f /* (LEGACY) */
  226. #define _SC_XBS5_LP64_OFF64 0x0070 /* (LEGACY) */
  227. #define _SC_XBS5_LPBIG_OFFBIG 0x0071 /* (LEGACY) */
  228. #define _SC_XOPEN_CRYPT 0x0072
  229. #define _SC_XOPEN_ENH_I18N 0x0073
  230. #define _SC_XOPEN_LEGACY 0x0074
  231. #define _SC_XOPEN_REALTIME 0x0075
  232. #define _SC_XOPEN_REALTIME_THREADS 0x0076
  233. #define _SC_XOPEN_SHM 0x0077
  234. #define _SC_XOPEN_STREAMS 0x0078
  235. #define _SC_XOPEN_UNIX 0x0079
  236. #define _SC_XOPEN_VERSION 0x007a
  237. #define _SC_NPROCESSORS_CONF 0x007b
  238. #define _SC_NPROCESSORS_ONLN 0x007c
  239. /* The following symbolic constants must be defined for file streams: */
  240. #define STDERR_FILENO 2 /* File number of stderr */
  241. #define STDIN_FILENO 0 /* File number of stdin */
  242. #define STDOUT_FILENO 1 /* File number of stdout */
  243. #define HOST_NAME_MAX 32
  244. /* Helpers and legacy compatibility definitions */
  245. #define link(p1, p2) symlink((p1), (p2))
  246. #define fdatasync(f) fsync(f)
  247. #define getdtablesize(f) ((int)sysconf(_SC_OPEN_MAX))
  248. /****************************************************************************
  249. * Public Data
  250. ****************************************************************************/
  251. #undef EXTERN
  252. #if defined(__cplusplus)
  253. #define EXTERN extern "C"
  254. extern "C"
  255. {
  256. #else
  257. #define EXTERN extern
  258. #endif
  259. /* Used by getopt (obviously NOT thread safe!). These variables cannot be
  260. * accessed directly by an external NXFLAT module. In that case, accessor
  261. * functions must be used.
  262. */
  263. #ifndef __NXFLAT__
  264. EXTERN FAR char *optarg; /* Optional argument following option */
  265. EXTERN int optind; /* Index into argv */
  266. EXTERN int optopt; /* Unrecognized option character */
  267. #else
  268. # define optarg (*(getoptargp()))
  269. # define optind (*(getoptindp()))
  270. # define optopt (*(getoptoptp()))
  271. #endif
  272. /****************************************************************************
  273. * Public Function Prototypes
  274. ****************************************************************************/
  275. /* Task Control Interfaces */
  276. pid_t vfork(void);
  277. pid_t getpid(void);
  278. void _exit(int status) noreturn_function;
  279. unsigned int sleep(unsigned int seconds);
  280. int usleep(useconds_t usec);
  281. int pause(void);
  282. int daemon(int nochdir, int noclose);
  283. /* File descriptor operations */
  284. int close(int fd);
  285. int dup(int fd);
  286. int dup2(int fd1, int fd2);
  287. int fsync(int fd);
  288. off_t lseek(int fd, off_t offset, int whence);
  289. ssize_t read(int fd, FAR void *buf, size_t nbytes);
  290. ssize_t write(int fd, FAR const void *buf, size_t nbytes);
  291. ssize_t pread(int fd, FAR void *buf, size_t nbytes, off_t offset);
  292. ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset);
  293. int ftruncate(int fd, off_t length);
  294. /* Check if a file descriptor corresponds to a terminal I/O file */
  295. int isatty(int fd);
  296. /* Memory management */
  297. #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_MM_PGALLOC) && \
  298. defined(CONFIG_ARCH_USE_MMU)
  299. FAR void *sbrk(intptr_t incr);
  300. #endif
  301. /* Special devices */
  302. int pipe(int fd[2]);
  303. /* Schedule an alarm */
  304. unsigned int alarm(unsigned int seconds);
  305. /* Working directory operations */
  306. int chdir(FAR const char *path);
  307. FAR char *getcwd(FAR char *buf, size_t size);
  308. /* File path operations */
  309. int access(FAR const char *path, int amode);
  310. int rmdir(FAR const char *pathname);
  311. int unlink(FAR const char *pathname);
  312. int truncate(FAR const char *path, off_t length);
  313. int symlink(FAR const char *path1, FAR const char *path2);
  314. ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize);
  315. /* Execution of programs from files */
  316. #ifdef CONFIG_LIBC_EXECFUNCS
  317. int execl(FAR const char *path, ...);
  318. int execv(FAR const char *path, FAR char * const argv[]);
  319. #endif
  320. /* Byte operations */
  321. void swab(FAR const void *src, FAR void *dest, ssize_t nbytes);
  322. /* getopt and friends */
  323. int getopt(int argc, FAR char * const argv[], FAR const char *optstring);
  324. /* Accessor functions intended for use only by external NXFLAT
  325. * modules. The global variables optarg, optind, and optopt cannot
  326. * be referenced directly from external modules.
  327. */
  328. FAR char **getoptargp(void); /* Optional argument following option */
  329. FAR int *getoptindp(void); /* Index into argv */
  330. FAR int *getoptoptp(void); /* Unrecognized option character */
  331. int gethostname(FAR char *name, size_t size);
  332. int sethostname(FAR const char *name, size_t size);
  333. /* Get configurable system variables */
  334. long sysconf(int name);
  335. long fpathconf(int fildes, int name);
  336. long pathconf(FAR const char *path, int name);
  337. /* User and group identity management */
  338. int setuid(uid_t uid);
  339. uid_t getuid(void);
  340. int setgid(gid_t gid);
  341. gid_t getgid(void);
  342. int seteuid(uid_t uid);
  343. uid_t geteuid(void);
  344. int setegid(gid_t gid);
  345. gid_t getegid(void);
  346. int setreuid(uid_t ruid, uid_t euid);
  347. int setregid(gid_t rgid, gid_t egid);
  348. #undef EXTERN
  349. #if defined(__cplusplus)
  350. }
  351. #endif
  352. #endif /* __INCLUDE_UNISTD_H */