1 // Copyright 2023 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #ifndef __linux__ 18 #ifndef __QNX__ 19 // Make sure these are defined and don't change anything if used. 20 enum { 21 SOCK_CLOEXEC = 0, 22 #ifndef __APPLE__ 23 O_CLOEXEC = 0 24 #endif 25 }; 26 #endif // !__QNX__ 27 #endif // !__linux__ 28 29 #ifdef _MSC_VER 30 31 #include <windows.h> 32 #include <BaseTsd.h> 33 34 #include <direct.h> 35 #include <fcntl.h> 36 #include <io.h> 37 #include <process.h> 38 #include <stdint.h> 39 #include <sys/stat.h> 40 #include <time.h> 41 #include <winsock2.h> 42 43 typedef SSIZE_T ssize_t; 44 45 typedef int mode_t; 46 #ifdef _WIN64 47 typedef int64_t pid_t; 48 #else 49 typedef int pid_t; 50 #endif 51 #define STDIN_FILENO _fileno(stdin) 52 #define STDOUT_FILENO _fileno(stdout) 53 #define STDERR_FILENO _fileno(stderr) 54 #define lseek(a, b, c) _lseek(a, b, c) 55 #define lseek64 _lseeki64 56 57 typedef struct FileTime { 58 uint32_t dwLowDateTime; 59 uint32_t dwHighDateTime; 60 } FileTime; 61 62 // Need <dirent.h> 63 64 // Define for convenience only in mingw. This is 65 // convenient for the _access function in Windows. 66 #define F_OK 0 /* Check for file existence */ 67 #define X_OK 1 /* Check for execute permission (not supported in Windows) */ 68 #define W_OK 2 /* Check for write permission */ 69 #define R_OK 4 /* Check for read permission */ 70 71 typedef int mode_t; 72 #ifdef _WIN64 73 typedef int64_t pid_t; 74 #else 75 typedef int pid_t; 76 #endif 77 #define STDIN_FILENO _fileno(stdin) 78 #define STDOUT_FILENO _fileno(stdout) 79 #define STDERR_FILENO _fileno(stderr) 80 #define lseek(a, b, c) _lseek(a, b, c) 81 #define lseek64 _lseeki64 82 83 // These functions were deprecated and replaced with ISO C++ conformant ones 84 // in MSVC 2017. 85 /* 86 #define strdup _strdup 87 #define mkdir _mkdir 88 #define rmdir _rmdir 89 #define getcwd _getcwd 90 #define getpid _getpid 91 #define close _close 92 #define open _open 93 #define read _read 94 #define write _write 95 #define creat _creat 96 */ 97 98 // From <fcntl.h> 99 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) 100 101 // From <sys/types.h> 102 typedef int64_t off64_t; 103 104 // From <sys/cdefs.h> 105 #ifdef __cplusplus 106 #define __BEGIN_DECLS extern "C" { 107 #define __END_DECLS } 108 #else 109 #define __BEGIN_DECLS /* empty */ 110 #define __END_DECLS /* empty */ 111 #endif 112 113 114 typedef void (*SystemTime)(FileTime*); 115 116 // From <sys/time.h> 117 struct timezone { 118 int tz_minuteswest; /* of Greenwich */ 119 int tz_dsttime; /* type of dst correction to apply */ 120 }; 121 122 // From <strings.h> 123 #define strcasecmp _stricmp 124 #define strncasecmp _strnicmp 125 126 // From <stdio.h> 127 #define fseeko64 _fseeki64 128 #define ftello64 _ftelli64 129 130 // From <linux/limits.h> 131 #define PATH_MAX MAX_PATH 132 133 __BEGIN_DECLS 134 135 136 extern SystemTime getSystemTime; 137 extern int gettimeofday(struct timeval* tp, struct timezone* tz); 138 extern int asprintf(char** buf, const char* format, ...); 139 extern int vasprintf(char** buf, const char* format, va_list args); 140 extern int mkstemp(char* t); 141 142 __END_DECLS 143 144 #endif 145