1 /*
2 * Copyright (c) 2018 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #ifndef ZEPHYR_INCLUDE_POSIX_UNISTD_H_
7 #define ZEPHYR_INCLUDE_POSIX_UNISTD_H_
8
9 #include <zephyr/posix/posix_types.h>
10
11 #ifdef CONFIG_POSIX_API
12 #include <zephyr/fs/fs.h>
13 #endif
14 #ifdef CONFIG_NETWORKING
15 /* For zsock_gethostname() */
16 #include <zephyr/net/socket.h>
17 #include <zephyr/net/hostname.h>
18 #endif
19 #include <zephyr/posix/sys/confstr.h>
20 #include <zephyr/posix/sys/stat.h>
21 #include <zephyr/posix/sys/sysconf.h>
22
23 #include "posix_features.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #ifdef CONFIG_POSIX_API
30 /* File related operations */
31 int close(int file);
32 ssize_t write(int file, const void *buffer, size_t count);
33 ssize_t read(int file, void *buffer, size_t count);
34 off_t lseek(int file, off_t offset, int whence);
35 int fsync(int fd);
36 int ftruncate(int fd, off_t length);
37
38 #ifdef CONFIG_POSIX_SYNCHRONIZED_IO
39 int fdatasync(int fd);
40 #endif /* CONFIG_POSIX_SYNCHRONIZED_IO */
41
42 /* File System related operations */
43 int rename(const char *old, const char *newp);
44 int unlink(const char *path);
45 int stat(const char *path, struct stat *buf);
46 int mkdir(const char *path, mode_t mode);
47 int rmdir(const char *path);
48
49 FUNC_NORETURN void _exit(int status);
50
51 #ifdef CONFIG_NETWORKING
gethostname(char * buf,size_t len)52 static inline int gethostname(char *buf, size_t len)
53 {
54 return zsock_gethostname(buf, len);
55 }
56 #endif /* CONFIG_NETWORKING */
57
58 #endif /* CONFIG_POSIX_API */
59
60 #ifdef CONFIG_POSIX_C_LIB_EXT
61 int getopt(int argc, char *const argv[], const char *optstring);
62 extern char *optarg;
63 extern int opterr, optind, optopt;
64 #endif
65
66 int getentropy(void *buffer, size_t length);
67 pid_t getpid(void);
68 unsigned sleep(unsigned int seconds);
69 int usleep(useconds_t useconds);
70 #if _POSIX_C_SOURCE >= 2
71 size_t confstr(int name, char *buf, size_t len);
72 #endif
73
74 #ifdef CONFIG_POSIX_SYSCONF_IMPL_MACRO
75 #define sysconf(x) (long)CONCAT(__z_posix_sysconf, x)
76 #else
77 long sysconf(int opt);
78 #endif /* CONFIG_POSIX_SYSCONF_IMPL_FULL */
79
80 #ifdef __cplusplus
81 }
82 #endif
83
84 #endif /* ZEPHYR_INCLUDE_POSIX_UNISTD_H_ */
85