1 #ifndef _UNISTD_H 2 #define _UNISTD_H 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 #include <features.h> 9 10 #define STDIN_FILENO 0 11 #define STDOUT_FILENO 1 12 #define STDERR_FILENO 2 13 14 #define SEEK_SET 0 15 #define SEEK_CUR 1 16 #define SEEK_END 2 17 18 #ifdef __cplusplus 19 #define NULL 0L 20 #else 21 #define NULL ((void*)0) 22 #endif 23 24 #define __NEED_size_t 25 #define __NEED_ssize_t 26 #define __NEED_uid_t 27 #define __NEED_gid_t 28 #define __NEED_off_t 29 #define __NEED_pid_t 30 #define __NEED_intptr_t 31 #define __NEED_useconds_t 32 33 #include <bits/alltypes.h> 34 35 int pipe(int [2]); 36 int pipe2(int [2], int); 37 int close(int); 38 int posix_close(int, int); 39 int dup(int); 40 int dup2(int, int); 41 int dup3(int, int, int); 42 off_t lseek(int, off_t, int); 43 int fsync(int); 44 int fdatasync(int); 45 46 ssize_t read(int, void *, size_t); 47 ssize_t write(int, const void *, size_t); 48 ssize_t pread(int, void *, size_t, off_t); 49 ssize_t pwrite(int, const void *, size_t, off_t); 50 51 int chown(const char *, uid_t, gid_t); 52 int fchown(int, uid_t, gid_t); 53 int lchown(const char *, uid_t, gid_t); 54 int fchownat(int, const char *, uid_t, gid_t, int); 55 56 int link(const char *, const char *); 57 int linkat(int, const char *, int, const char *, int); 58 int symlink(const char *, const char *); 59 int symlinkat(const char *, int, const char *); 60 ssize_t readlink(const char *__restrict, char *__restrict, size_t); 61 ssize_t readlinkat(int, const char *__restrict, char *__restrict, size_t); 62 int unlink(const char *); 63 int unlinkat(int, const char *, int); 64 int rmdir(const char *); 65 int truncate(const char *, off_t); 66 int ftruncate(int, off_t); 67 68 #define F_OK 0 69 #define R_OK 4 70 #define W_OK 2 71 #define X_OK 1 72 73 int access(const char *, int); 74 int faccessat(int, const char *, int, int); 75 76 77 /* Format options */ 78 #define FMT_FAT 0x01 79 #define FMT_FAT32 0x02 80 #define FMT_ANY 0x07 81 #define FMT_ERASE 0x08 82 83 /** 84 * @brief format FAT device (SD card, U disk, and MMC card), this function is OHOS-specific 85 * @param dev device name. 86 * @param sectors sectors per cluster, can be 0 OR power of 2. The sector size for standard FAT volumes is 512 bytes. 87 * -- sector number is 0 OR >128: automatically choose the appropriate cluster size. 88 * -- sector number is 1 ~ 128: cluster size = sectors per cluster * 512B. 89 * @param option file system type. 90 * -- FMT_FAT 91 * -- FMT_FAT32 92 * -- FMT_ANY 93 * -- FMT_ERASE (USB not supported) 94 * @return format result 95 * @retval -1 format error 96 * @retval 0 format successful 97 */ 98 int format(const char *dev, int sectors, int option); 99 100 int chdir(const char *); 101 int fchdir(int); 102 char *getcwd(char *, size_t); 103 104 unsigned alarm(unsigned); 105 unsigned sleep(unsigned); 106 int pause(void); 107 108 pid_t fork(void); 109 int execve(const char *, char *const [], char *const []); 110 int execv(const char *, char *const []); 111 int execle(const char *, const char *, ...); 112 int execl(const char *, const char *, ...); 113 int execvp(const char *, char *const []); 114 int execlp(const char *, const char *, ...); 115 int fexecve(int, char *const [], char *const []); 116 _Noreturn void _exit(int); 117 118 pid_t getpid(void); 119 pid_t getppid(void); 120 pid_t getpgrp(void); 121 pid_t getpgid(pid_t); 122 int setpgid(pid_t, pid_t); 123 pid_t setsid(void); 124 pid_t getsid(pid_t); 125 char *ttyname(int); 126 int ttyname_r(int, char *, size_t); 127 int isatty(int); 128 pid_t tcgetpgrp(int); 129 int tcsetpgrp(int, pid_t); 130 131 uid_t getuid(void); 132 uid_t geteuid(void); 133 gid_t getgid(void); 134 gid_t getegid(void); 135 int getgroups(int, gid_t []); 136 int setuid(uid_t); 137 int seteuid(uid_t); 138 int setgid(gid_t); 139 int setegid(gid_t); 140 141 char *getlogin(void); 142 int getlogin_r(char *, size_t); 143 int gethostname(char *, size_t); 144 char *ctermid(char *); 145 146 int getopt(int, char * const [], const char *); 147 extern char *optarg; 148 extern int optind, opterr, optopt; 149 150 long pathconf(const char *, int); 151 long fpathconf(int, int); 152 long sysconf(int); 153 size_t confstr(int, char *, size_t); 154 155 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 156 #define F_ULOCK 0 157 #define F_LOCK 1 158 #define F_TLOCK 2 159 #define F_TEST 3 160 int setreuid(uid_t, uid_t); 161 int setregid(gid_t, gid_t); 162 int lockf(int, int, off_t); 163 long gethostid(void); 164 int nice(int); 165 void sync(void); 166 pid_t setpgrp(void); 167 char *crypt(const char *, const char *); 168 void encrypt(char *, int); 169 void swab(const void *__restrict, void *__restrict, ssize_t); 170 #endif 171 172 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ 173 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) 174 int usleep(unsigned); 175 unsigned ualarm(unsigned, unsigned); 176 #endif 177 178 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 179 #define L_SET 0 180 #define L_INCR 1 181 #define L_XTND 2 182 int brk(void *); 183 void *sbrk(intptr_t); 184 pid_t vfork(void); 185 int vhangup(void); 186 int chroot(const char *); 187 int getpagesize(void); 188 int getdtablesize(void); 189 int sethostname(const char *, size_t); 190 int getdomainname(char *, size_t); 191 int setdomainname(const char *, size_t); 192 int setgroups(size_t, const gid_t *); 193 char *getpass(const char *); 194 int daemon(int, int); 195 void setusershell(void); 196 void endusershell(void); 197 char *getusershell(void); 198 int acct(const char *); 199 long syscall(long, ...); 200 int execvpe(const char *, char *const [], char *const []); 201 int issetugid(void); 202 int getentropy(void *, size_t); 203 extern int optreset; 204 #endif 205 206 #ifdef _GNU_SOURCE 207 extern char **environ; 208 int setresuid(uid_t, uid_t, uid_t); 209 int setresgid(gid_t, gid_t, gid_t); 210 int getresuid(uid_t *, uid_t *, uid_t *); 211 int getresgid(gid_t *, gid_t *, gid_t *); 212 char *get_current_dir_name(void); 213 int syncfs(int); 214 int euidaccess(const char *, int); 215 int eaccess(const char *, int); 216 ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned); 217 #endif 218 219 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) 220 #define lseek64 lseek 221 #define pread64 pread 222 #define pwrite64 pwrite 223 #define truncate64 truncate 224 #define ftruncate64 ftruncate 225 #define lockf64 lockf 226 #define off64_t off_t 227 #endif 228 229 #define POSIX_CLOSE_RESTART 0 230 231 #define _XOPEN_VERSION 700 232 #define _XOPEN_UNIX 1 233 #define _XOPEN_ENH_I18N 1 234 235 #define _POSIX_VERSION 200809L 236 #define _POSIX2_VERSION _POSIX_VERSION 237 238 #define _POSIX_ADVISORY_INFO _POSIX_VERSION 239 #define _POSIX_CHOWN_RESTRICTED 1 240 #define _POSIX_IPV6 _POSIX_VERSION 241 #define _POSIX_JOB_CONTROL 1 242 #define _POSIX_MAPPED_FILES _POSIX_VERSION 243 #define _POSIX_MEMLOCK _POSIX_VERSION 244 #define _POSIX_MEMLOCK_RANGE _POSIX_VERSION 245 #define _POSIX_MEMORY_PROTECTION _POSIX_VERSION 246 #define _POSIX_MESSAGE_PASSING _POSIX_VERSION 247 #define _POSIX_FSYNC _POSIX_VERSION 248 #define _POSIX_NO_TRUNC 1 249 #define _POSIX_RAW_SOCKETS _POSIX_VERSION 250 #define _POSIX_REALTIME_SIGNALS _POSIX_VERSION 251 #define _POSIX_REGEXP 1 252 #define _POSIX_SAVED_IDS 1 253 #define _POSIX_SHELL 1 254 #define _POSIX_SPAWN _POSIX_VERSION 255 #define _POSIX_VDISABLE 0 256 257 #define _POSIX_THREADS _POSIX_VERSION 258 #define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION 259 #define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION 260 #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION 261 #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION 262 #define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION 263 #define _POSIX_THREAD_CPUTIME _POSIX_VERSION 264 #define _POSIX_TIMERS _POSIX_VERSION 265 #define _POSIX_TIMEOUTS _POSIX_VERSION 266 #define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION 267 #define _POSIX_CPUTIME _POSIX_VERSION 268 #define _POSIX_CLOCK_SELECTION _POSIX_VERSION 269 #define _POSIX_BARRIERS _POSIX_VERSION 270 #define _POSIX_SPIN_LOCKS _POSIX_VERSION 271 #define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION 272 #define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION 273 #define _POSIX_SEMAPHORES _POSIX_VERSION 274 #define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION 275 276 #define _POSIX2_C_BIND _POSIX_VERSION 277 278 #include <bits/posix.h> 279 280 281 282 #define _PC_LINK_MAX 0 283 #define _PC_MAX_CANON 1 284 #define _PC_MAX_INPUT 2 285 #define _PC_NAME_MAX 3 286 #define _PC_PATH_MAX 4 287 #define _PC_PIPE_BUF 5 288 #define _PC_CHOWN_RESTRICTED 6 289 #define _PC_NO_TRUNC 7 290 #define _PC_VDISABLE 8 291 #define _PC_SYNC_IO 9 292 #define _PC_ASYNC_IO 10 293 #define _PC_PRIO_IO 11 294 #define _PC_SOCK_MAXBUF 12 295 #define _PC_FILESIZEBITS 13 296 #define _PC_REC_INCR_XFER_SIZE 14 297 #define _PC_REC_MAX_XFER_SIZE 15 298 #define _PC_REC_MIN_XFER_SIZE 16 299 #define _PC_REC_XFER_ALIGN 17 300 #define _PC_ALLOC_SIZE_MIN 18 301 #define _PC_SYMLINK_MAX 19 302 #define _PC_2_SYMLINKS 20 303 304 #define _SC_ARG_MAX 0 305 #define _SC_CHILD_MAX 1 306 #define _SC_CLK_TCK 2 307 #define _SC_NGROUPS_MAX 3 308 #define _SC_OPEN_MAX 4 309 #define _SC_STREAM_MAX 5 310 #define _SC_TZNAME_MAX 6 311 #define _SC_JOB_CONTROL 7 312 #define _SC_SAVED_IDS 8 313 #define _SC_REALTIME_SIGNALS 9 314 #define _SC_PRIORITY_SCHEDULING 10 315 #define _SC_TIMERS 11 316 #define _SC_ASYNCHRONOUS_IO 12 317 #define _SC_PRIORITIZED_IO 13 318 #define _SC_SYNCHRONIZED_IO 14 319 #define _SC_FSYNC 15 320 #define _SC_MAPPED_FILES 16 321 #define _SC_MEMLOCK 17 322 #define _SC_MEMLOCK_RANGE 18 323 #define _SC_MEMORY_PROTECTION 19 324 #define _SC_MESSAGE_PASSING 20 325 #define _SC_SEMAPHORES 21 326 #define _SC_SHARED_MEMORY_OBJECTS 22 327 #define _SC_AIO_LISTIO_MAX 23 328 #define _SC_AIO_MAX 24 329 #define _SC_AIO_PRIO_DELTA_MAX 25 330 #define _SC_DELAYTIMER_MAX 26 331 #define _SC_MQ_OPEN_MAX 27 332 #define _SC_MQ_PRIO_MAX 28 333 #define _SC_VERSION 29 334 #define _SC_PAGE_SIZE 30 335 #define _SC_PAGESIZE 30 /* !! */ 336 #define _SC_RTSIG_MAX 31 337 #define _SC_SEM_NSEMS_MAX 32 338 #define _SC_SEM_VALUE_MAX 33 339 #define _SC_SIGQUEUE_MAX 34 340 #define _SC_TIMER_MAX 35 341 #define _SC_BC_BASE_MAX 36 342 #define _SC_BC_DIM_MAX 37 343 #define _SC_BC_SCALE_MAX 38 344 #define _SC_BC_STRING_MAX 39 345 #define _SC_COLL_WEIGHTS_MAX 40 346 #define _SC_EXPR_NEST_MAX 42 347 #define _SC_LINE_MAX 43 348 #define _SC_RE_DUP_MAX 44 349 #define _SC_2_VERSION 46 350 #define _SC_2_C_BIND 47 351 #define _SC_2_C_DEV 48 352 #define _SC_2_FORT_DEV 49 353 #define _SC_2_FORT_RUN 50 354 #define _SC_2_SW_DEV 51 355 #define _SC_2_LOCALEDEF 52 356 #define _SC_UIO_MAXIOV 60 /* !! */ 357 #define _SC_IOV_MAX 60 358 #define _SC_THREADS 67 359 #define _SC_THREAD_SAFE_FUNCTIONS 68 360 #define _SC_GETGR_R_SIZE_MAX 69 361 #define _SC_GETPW_R_SIZE_MAX 70 362 #define _SC_LOGIN_NAME_MAX 71 363 #define _SC_TTY_NAME_MAX 72 364 #define _SC_THREAD_DESTRUCTOR_ITERATIONS 73 365 #define _SC_THREAD_KEYS_MAX 74 366 #define _SC_THREAD_STACK_MIN 75 367 #define _SC_THREAD_THREADS_MAX 76 368 #define _SC_THREAD_ATTR_STACKADDR 77 369 #define _SC_THREAD_ATTR_STACKSIZE 78 370 #define _SC_THREAD_PRIORITY_SCHEDULING 79 371 #define _SC_THREAD_PRIO_INHERIT 80 372 #define _SC_THREAD_PRIO_PROTECT 81 373 #define _SC_THREAD_PROCESS_SHARED 82 374 #define _SC_NPROCESSORS_CONF 83 375 #define _SC_NPROCESSORS_ONLN 84 376 #define _SC_PHYS_PAGES 85 377 #define _SC_AVPHYS_PAGES 86 378 #define _SC_ATEXIT_MAX 87 379 #define _SC_PASS_MAX 88 380 #define _SC_XOPEN_VERSION 89 381 #define _SC_XOPEN_XCU_VERSION 90 382 #define _SC_XOPEN_UNIX 91 383 #define _SC_XOPEN_CRYPT 92 384 #define _SC_XOPEN_ENH_I18N 93 385 #define _SC_XOPEN_SHM 94 386 #define _SC_2_CHAR_TERM 95 387 #define _SC_2_UPE 97 388 #define _SC_XOPEN_XPG2 98 389 #define _SC_XOPEN_XPG3 99 390 #define _SC_XOPEN_XPG4 100 391 #define _SC_NZERO 109 392 #define _SC_XBS5_ILP32_OFF32 125 393 #define _SC_XBS5_ILP32_OFFBIG 126 394 #define _SC_XBS5_LP64_OFF64 127 395 #define _SC_XBS5_LPBIG_OFFBIG 128 396 #define _SC_XOPEN_LEGACY 129 397 #define _SC_XOPEN_REALTIME 130 398 #define _SC_XOPEN_REALTIME_THREADS 131 399 #define _SC_ADVISORY_INFO 132 400 #define _SC_BARRIERS 133 401 #define _SC_CLOCK_SELECTION 137 402 #define _SC_CPUTIME 138 403 #define _SC_THREAD_CPUTIME 139 404 #define _SC_MONOTONIC_CLOCK 149 405 #define _SC_READER_WRITER_LOCKS 153 406 #define _SC_SPIN_LOCKS 154 407 #define _SC_REGEXP 155 408 #define _SC_SHELL 157 409 #define _SC_SPAWN 159 410 #define _SC_SPORADIC_SERVER 160 411 #define _SC_THREAD_SPORADIC_SERVER 161 412 #define _SC_TIMEOUTS 164 413 #define _SC_TYPED_MEMORY_OBJECTS 165 414 #define _SC_2_PBS 168 415 #define _SC_2_PBS_ACCOUNTING 169 416 #define _SC_2_PBS_LOCATE 170 417 #define _SC_2_PBS_MESSAGE 171 418 #define _SC_2_PBS_TRACK 172 419 #define _SC_SYMLOOP_MAX 173 420 #define _SC_STREAMS 174 421 #define _SC_2_PBS_CHECKPOINT 175 422 #define _SC_V6_ILP32_OFF32 176 423 #define _SC_V6_ILP32_OFFBIG 177 424 #define _SC_V6_LP64_OFF64 178 425 #define _SC_V6_LPBIG_OFFBIG 179 426 #define _SC_HOST_NAME_MAX 180 427 #define _SC_TRACE 181 428 #define _SC_TRACE_EVENT_FILTER 182 429 #define _SC_TRACE_INHERIT 183 430 #define _SC_TRACE_LOG 184 431 432 #define _SC_IPV6 235 433 #define _SC_RAW_SOCKETS 236 434 #define _SC_V7_ILP32_OFF32 237 435 #define _SC_V7_ILP32_OFFBIG 238 436 #define _SC_V7_LP64_OFF64 239 437 #define _SC_V7_LPBIG_OFFBIG 240 438 #define _SC_SS_REPL_MAX 241 439 #define _SC_TRACE_EVENT_NAME_MAX 242 440 #define _SC_TRACE_NAME_MAX 243 441 #define _SC_TRACE_SYS_MAX 244 442 #define _SC_TRACE_USER_EVENT_MAX 245 443 #define _SC_XOPEN_STREAMS 246 444 #define _SC_THREAD_ROBUST_PRIO_INHERIT 247 445 #define _SC_THREAD_ROBUST_PRIO_PROTECT 248 446 447 #define _CS_PATH 0 448 #define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 1 449 #define _CS_GNU_LIBC_VERSION 2 450 #define _CS_GNU_LIBPTHREAD_VERSION 3 451 #define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS 4 452 #define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 5 453 454 #define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 1116 455 #define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 1117 456 #define _CS_POSIX_V6_ILP32_OFF32_LIBS 1118 457 #define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS 1119 458 #define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 1120 459 #define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 1121 460 #define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 1122 461 #define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS 1123 462 #define _CS_POSIX_V6_LP64_OFF64_CFLAGS 1124 463 #define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 1125 464 #define _CS_POSIX_V6_LP64_OFF64_LIBS 1126 465 #define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS 1127 466 #define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 1128 467 #define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 1129 468 #define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 1130 469 #define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS 1131 470 #define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1132 471 #define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 1133 472 #define _CS_POSIX_V7_ILP32_OFF32_LIBS 1134 473 #define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS 1135 474 #define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 1136 475 #define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 1137 476 #define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 1138 477 #define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS 1139 478 #define _CS_POSIX_V7_LP64_OFF64_CFLAGS 1140 479 #define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 1141 480 #define _CS_POSIX_V7_LP64_OFF64_LIBS 1142 481 #define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS 1143 482 #define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 1144 483 #define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 1145 484 #define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 1146 485 #define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS 1147 486 #define _CS_V6_ENV 1148 487 #define _CS_V7_ENV 1149 488 489 #ifdef __cplusplus 490 } 491 #endif 492 493 #endif 494