1 // Copyright 2021 The Android Open Source Project 2 // 3 // This software is licensed under the terms of the GNU General Public 4 // License version 2, as published by the Free Software Foundation, and 5 // may be copied, distributed, and modified under those terms. 6 // 7 // This program is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 // GNU General Public License for more details. 11 12 // A minimal set of functions found in unistd.h 13 #if !defined(_AEMU_UNISTD_H_) && !defined(_MSVC_UNISTD_H) 14 #define _AEMU_UNISTD_H_ 15 #define _MSVC_UNISTD_H 16 17 #include "compat_compiler.h" 18 #include <process.h> 19 20 ANDROID_BEGIN_HEADER 21 22 #include <direct.h> 23 #include <inttypes.h> 24 #include <io.h> 25 #include <stdio.h> 26 #include <sys/stat.h> 27 28 typedef long long ssize_t; 29 typedef unsigned long long size_t; 30 typedef long off_t; 31 typedef int64_t off64_t; 32 typedef int mode_t; 33 34 #undef fstat 35 #define fstat _fstat64 36 37 #define lseek(a, b, c) _lseek(a, b, c) 38 #define lseek64 _lseeki64 39 40 /* File type and permission flags for stat(), general mask */ 41 #if !defined(S_IFMT) 42 #define S_IFMT _S_IFMT 43 #endif 44 45 /* Directory bit */ 46 #if !defined(S_IFDIR) 47 #define S_IFDIR _S_IFDIR 48 #endif 49 50 /* Character device bit */ 51 #if !defined(S_IFCHR) 52 #define S_IFCHR _S_IFCHR 53 #endif 54 55 /* Pipe bit */ 56 #if !defined(S_IFFIFO) 57 #define S_IFFIFO _S_IFFIFO 58 #endif 59 60 /* Regular file bit */ 61 #if !defined(S_IFREG) 62 #define S_IFREG _S_IFREG 63 #endif 64 65 /* Read permission */ 66 #if !defined(S_IREAD) 67 #define S_IREAD _S_IREAD 68 #endif 69 70 /* Write permission */ 71 #if !defined(S_IWRITE) 72 #define S_IWRITE _S_IWRITE 73 #endif 74 75 /* Execute permission */ 76 #if !defined(S_IEXEC) 77 #define S_IEXEC _S_IEXEC 78 #endif 79 80 /* Pipe */ 81 #if !defined(S_IFIFO) 82 #define S_IFIFO _S_IFIFO 83 #endif 84 85 /* Block device */ 86 #if !defined(S_IFBLK) 87 #define S_IFBLK 0 88 #endif 89 90 /* Link */ 91 #if !defined(S_IFLNK) 92 #define S_IFLNK 0 93 #endif 94 95 /* Socket */ 96 #if !defined(S_IFSOCK) 97 #define S_IFSOCK 0 98 #endif 99 100 /* Read user permission */ 101 #if !defined(S_IRUSR) 102 #define S_IRUSR S_IREAD 103 #endif 104 105 /* Write user permission */ 106 #if !defined(S_IWUSR) 107 #define S_IWUSR S_IWRITE 108 #endif 109 110 /* Execute user permission */ 111 #if !defined(S_IXUSR) 112 #define S_IXUSR 0 113 #endif 114 115 /* Read group permission */ 116 #if !defined(S_IRGRP) 117 #define S_IRGRP 0 118 #endif 119 120 /* Write group permission */ 121 #if !defined(S_IWGRP) 122 #define S_IWGRP 0 123 #endif 124 125 /* Execute group permission */ 126 #if !defined(S_IXGRP) 127 #define S_IXGRP 0 128 #endif 129 130 /* Read others permission */ 131 #if !defined(S_IROTH) 132 #define S_IROTH 0 133 #endif 134 135 /* Write others permission */ 136 #if !defined(S_IWOTH) 137 #define S_IWOTH 0 138 #endif 139 140 /* Execute others permission */ 141 #if !defined(S_IXOTH) 142 #define S_IXOTH 0 143 #endif 144 145 /* Maximum length of file name */ 146 #if !defined(PATH_MAX) 147 #define PATH_MAX MAX_PATH 148 #endif 149 #if !defined(FILENAME_MAX) 150 #define FILENAME_MAX MAX_PATH 151 #endif 152 #if !defined(NAME_MAX) 153 #define NAME_MAX FILENAME_MAX 154 #endif 155 156 // Define for convenience only in mingw. This is 157 // convenient for the _access function in Windows. 158 #if !defined(F_OK) 159 #define F_OK 0 /* Check for file existence */ 160 #endif 161 #if !defined(X_OK) 162 #define X_OK 1 /* Check for execute permission (not supported in Windows) */ 163 #endif 164 #if !defined(W_OK) 165 #define W_OK 2 /* Check for write permission */ 166 #endif 167 #if !defined(R_OK) 168 #define R_OK 4 /* Check for read permission */ 169 #endif 170 171 #define STDIN_FILENO _fileno(stdin) 172 #define STDOUT_FILENO _fileno(stdout) 173 #define STDERR_FILENO _fileno(stderr) 174 ssize_t pread(int fd, void *buf, size_t count, off_t offset); 175 176 int usleep(long usec); 177 unsigned int sleep(unsigned int seconds); 178 179 // Qemu will redefine this if it can. 180 int _ftruncate(int fd, off_t length); 181 #define ftruncate _ftruncate 182 183 184 #define __try1(x) __try 185 #define __except1 __except (EXCEPTION_EXECUTE_HANDLER) 186 187 ANDROID_END_HEADER 188 #endif /* Not _AEMU_UNISTD_H_ */ 189