| 1 | /* | 
|---|
| 2 | * Copyright (c) 2011 Jiri Zarevucky | 
|---|
| 3 | * Copyright (c) 2011 Petr Koupy | 
|---|
| 4 | * All rights reserved. | 
|---|
| 5 | * | 
|---|
| 6 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 7 | * modification, are permitted provided that the following conditions | 
|---|
| 8 | * are met: | 
|---|
| 9 | * | 
|---|
| 10 | * - Redistributions of source code must retain the above copyright | 
|---|
| 11 | *   notice, this list of conditions and the following disclaimer. | 
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright | 
|---|
| 13 | *   notice, this list of conditions and the following disclaimer in the | 
|---|
| 14 | *   documentation and/or other materials provided with the distribution. | 
|---|
| 15 | * - The name of the author may not be used to endorse or promote products | 
|---|
| 16 | *   derived from this software without specific prior written permission. | 
|---|
| 17 | * | 
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 28 | */ | 
|---|
| 29 |  | 
|---|
| 30 | /** @addtogroup libposix | 
|---|
| 31 | * @{ | 
|---|
| 32 | */ | 
|---|
| 33 | /** @file Miscellaneous standard definitions. | 
|---|
| 34 | */ | 
|---|
| 35 |  | 
|---|
| 36 | #ifndef POSIX_UNISTD_H_ | 
|---|
| 37 | #define POSIX_UNISTD_H_ | 
|---|
| 38 |  | 
|---|
| 39 | #include "libc/unistd.h" | 
|---|
| 40 | #include "sys/types.h" | 
|---|
| 41 |  | 
|---|
| 42 | /* Process Termination */ | 
|---|
| 43 | #define _exit exit | 
|---|
| 44 |  | 
|---|
| 45 | extern char *posix_optarg; | 
|---|
| 46 | extern int optind, opterr, optopt; | 
|---|
| 47 | extern int posix_getopt(int, char * const [], const char *); | 
|---|
| 48 |  | 
|---|
| 49 | /* Environment */ | 
|---|
| 50 | extern char **posix_environ; | 
|---|
| 51 |  | 
|---|
| 52 | /* Login Information */ | 
|---|
| 53 | extern char *posix_getlogin(void); | 
|---|
| 54 | extern int posix_getlogin_r(char *name, size_t namesize); | 
|---|
| 55 |  | 
|---|
| 56 | /* Identifying Terminals */ | 
|---|
| 57 | extern int posix_isatty(int fd); | 
|---|
| 58 |  | 
|---|
| 59 | /* Working Directory */ | 
|---|
| 60 | extern char *posix_getcwd(char *buf, size_t size); | 
|---|
| 61 | extern int posix_chdir(const char *path); | 
|---|
| 62 |  | 
|---|
| 63 | /* Query Memory Parameters */ | 
|---|
| 64 | extern int posix_getpagesize(void); | 
|---|
| 65 |  | 
|---|
| 66 | /* Process Identification */ | 
|---|
| 67 | extern posix_pid_t posix_getpid(void); | 
|---|
| 68 | extern posix_uid_t posix_getuid(void); | 
|---|
| 69 | extern posix_gid_t posix_getgid(void); | 
|---|
| 70 |  | 
|---|
| 71 | /* File Manipulation */ | 
|---|
| 72 | extern int posix_close(int fildes); | 
|---|
| 73 | extern ssize_t posix_read(int fildes, void *buf, size_t nbyte); | 
|---|
| 74 | extern ssize_t posix_write(int fildes, const void *buf, size_t nbyte); | 
|---|
| 75 | extern int posix_fsync(int fildes); | 
|---|
| 76 | extern int posix_ftruncate(int fildes, posix_off_t length); | 
|---|
| 77 | extern int posix_rmdir(const char *path); | 
|---|
| 78 | extern int posix_unlink(const char *path); | 
|---|
| 79 | extern int posix_dup(int fildes); | 
|---|
| 80 | extern int posix_dup2(int fildes, int fildes2); | 
|---|
| 81 |  | 
|---|
| 82 | /* Standard Streams */ | 
|---|
| 83 | #undef STDIN_FILENO | 
|---|
| 84 | #define STDIN_FILENO (fileno(stdin)) | 
|---|
| 85 | #undef STDOUT_FILENO | 
|---|
| 86 | #define STDOUT_FILENO (fileno(stdout)) | 
|---|
| 87 | #undef STDERR_FILENO | 
|---|
| 88 | #define STDERR_FILENO (fileno(stderr)) | 
|---|
| 89 |  | 
|---|
| 90 | /* File Accessibility */ | 
|---|
| 91 | #undef F_OK | 
|---|
| 92 | #undef X_OK | 
|---|
| 93 | #undef W_OK | 
|---|
| 94 | #undef R_OK | 
|---|
| 95 | #define F_OK 0 /* Test for existence. */ | 
|---|
| 96 | #define X_OK 1 /* Test for execute permission. */ | 
|---|
| 97 | #define W_OK 2 /* Test for write permission. */ | 
|---|
| 98 | #define R_OK 4 /* Test for read permission. */ | 
|---|
| 99 | extern int posix_access(const char *path, int amode); | 
|---|
| 100 |  | 
|---|
| 101 | /* System Parameters */ | 
|---|
| 102 | enum { | 
|---|
| 103 | _SC_PHYS_PAGES, | 
|---|
| 104 | _SC_AVPHYS_PAGES, | 
|---|
| 105 | _SC_PAGESIZE, | 
|---|
| 106 | _SC_CLK_TCK | 
|---|
| 107 | }; | 
|---|
| 108 | extern long posix_sysconf(int name); | 
|---|
| 109 |  | 
|---|
| 110 | /* Path Configuration Parameters */ | 
|---|
| 111 | enum { | 
|---|
| 112 | _PC_2_SYMLINKS, | 
|---|
| 113 | _PC_ALLOC_SIZE_MIN, | 
|---|
| 114 | _PC_ASYNC_IO, | 
|---|
| 115 | _PC_CHOWN_RESTRICTED, | 
|---|
| 116 | _PC_FILESIZEBITS, | 
|---|
| 117 | _PC_LINK_MAX, | 
|---|
| 118 | _PC_MAX_CANON, | 
|---|
| 119 | _PC_MAX_INPUT, | 
|---|
| 120 | _PC_NAME_MAX, | 
|---|
| 121 | _PC_NO_TRUNC, | 
|---|
| 122 | _PC_PATH_MAX, | 
|---|
| 123 | _PC_PIPE_BUF, | 
|---|
| 124 | _PC_PRIO_IO, | 
|---|
| 125 | _PC_REC_INCR_XFER_SIZE, | 
|---|
| 126 | _PC_REC_MIN_XFER_SIZE, | 
|---|
| 127 | _PC_REC_XFER_ALIGN, | 
|---|
| 128 | _PC_SYMLINK_MAX, | 
|---|
| 129 | _PC_SYNC_IO, | 
|---|
| 130 | _PC_VDISABLE | 
|---|
| 131 | }; | 
|---|
| 132 | extern long posix_pathconf(const char *path, int name); | 
|---|
| 133 |  | 
|---|
| 134 | /* Creating a Process */ | 
|---|
| 135 | extern posix_pid_t posix_fork(void); | 
|---|
| 136 |  | 
|---|
| 137 | /* Executing a File */ | 
|---|
| 138 | extern int posix_execv(const char *path, char *const argv[]); | 
|---|
| 139 | extern int posix_execvp(const char *file, char *const argv[]); | 
|---|
| 140 |  | 
|---|
| 141 | /* Creating a Pipe */ | 
|---|
| 142 | extern int posix_pipe(int fildes[2]); | 
|---|
| 143 |  | 
|---|
| 144 | #ifndef LIBPOSIX_INTERNAL | 
|---|
| 145 | #define getopt posix_getopt | 
|---|
| 146 | #define optarg posix_optarg | 
|---|
| 147 |  | 
|---|
| 148 | #define environ posix_environ | 
|---|
| 149 |  | 
|---|
| 150 | #define getlogin posix_getlogin | 
|---|
| 151 | #define getlogin_r posix_getlogin_r | 
|---|
| 152 |  | 
|---|
| 153 | #define getcwd posix_getcwd | 
|---|
| 154 | #define chdir posix_chdir | 
|---|
| 155 |  | 
|---|
| 156 | #define isatty posix_isatty | 
|---|
| 157 |  | 
|---|
| 158 | #undef getpagesize | 
|---|
| 159 | #define getpagesize posix_getpagesize | 
|---|
| 160 |  | 
|---|
| 161 | #define getpid posix_getpid | 
|---|
| 162 | #define getuid posix_getuid | 
|---|
| 163 | #define getgid posix_getgid | 
|---|
| 164 |  | 
|---|
| 165 | #define close posix_close | 
|---|
| 166 | #define read posix_read | 
|---|
| 167 | #define write posix_write | 
|---|
| 168 | #define fsync posix_fsync | 
|---|
| 169 | #define ftruncate posix_ftruncate | 
|---|
| 170 | #define rmdir posix_rmdir | 
|---|
| 171 | #define unlink posix_unlink | 
|---|
| 172 | #define dup posix_dup | 
|---|
| 173 | #define dup2 posix_dup2 | 
|---|
| 174 |  | 
|---|
| 175 | #define access posix_access | 
|---|
| 176 |  | 
|---|
| 177 | #define sysconf posix_sysconf | 
|---|
| 178 |  | 
|---|
| 179 | #define pathconf posix_pathconf | 
|---|
| 180 |  | 
|---|
| 181 | #define fork posix_fork | 
|---|
| 182 |  | 
|---|
| 183 | #define execv posix_execv | 
|---|
| 184 | #define execvp posix_execvp | 
|---|
| 185 |  | 
|---|
| 186 | #define pipe posix_pipe | 
|---|
| 187 | #endif | 
|---|
| 188 |  | 
|---|
| 189 | #endif /* POSIX_UNISTD_H_ */ | 
|---|
| 190 |  | 
|---|
| 191 | /** @} | 
|---|
| 192 | */ | 
|---|