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 "posix_types.h"
10 #include <zephyr/posix/sys/stat.h>
11 #ifdef CONFIG_NETWORKING
12 /* For zsock_gethostname() */
13 #include <zephyr/net/socket.h>
14 #endif
15 
16 #ifdef CONFIG_POSIX_API
17 #include <zephyr/fs/fs.h>
18 #endif
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #ifdef CONFIG_POSIX_API
25 /* File related operations */
26 extern int close(int file);
27 extern ssize_t write(int file, const void *buffer, size_t count);
28 extern ssize_t read(int file, void *buffer, size_t count);
29 extern off_t lseek(int file, off_t offset, int whence);
30 
31 /* File System related operations */
32 extern int rename(const char *old, const char *newp);
33 extern int unlink(const char *path);
34 extern int stat(const char *path, struct stat *buf);
35 extern int mkdir(const char *path, mode_t mode);
36 
37 FUNC_NORETURN void _exit(int status);
38 
39 #ifdef CONFIG_NETWORKING
gethostname(char * buf,size_t len)40 static inline int gethostname(char *buf, size_t len)
41 {
42 	return zsock_gethostname(buf, len);
43 }
44 #endif /* CONFIG_NETWORKING */
45 
46 #endif /* CONFIG_POSIX_API */
47 
48 #ifdef CONFIG_GETOPT
49 int getopt(int argc, char *const argv[], const char *optstring);
50 extern char *optarg;
51 extern int opterr, optind, optopt;
52 #endif
53 
54 unsigned sleep(unsigned int seconds);
55 int usleep(useconds_t useconds);
56 
57 #ifdef __cplusplus
58 }
59 #endif
60 
61 #endif	/* ZEPHYR_INCLUDE_POSIX_UNISTD_H_ */
62