1 // Copyright 2020 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 #define MSVC_POSIX 18 // windows.h must come before any of these files, or bad things will happen 19 #include <windows.h> 20 21 #include <direct.h> 22 #include <ehstorioctl.h> 23 #include <fcntl.h> 24 #include <io.h> 25 #include <process.h> 26 #include <stdint.h> 27 #include <sys/stat.h> 28 #include <time.h> 29 #include <winsock2.h> 30 //#include <basetsd.h> 31 32 // From <unistd.h> 33 typedef SSIZE_T ssize_t; 34 typedef int mode_t; 35 #ifdef _WIN64 36 typedef int64_t pid_t; 37 #else 38 typedef int pid_t; 39 #endif 40 #define STDIN_FILENO _fileno(stdin) 41 #define STDOUT_FILENO _fileno(stdout) 42 #define STDERR_FILENO _fileno(stderr) 43 #define lseek(a, b, c) _lseek(a, b, c) 44 #define lseek64 _lseeki64 45 46 // Need <dirent.h> 47 48 // Define for convenience only in mingw. This is 49 // convenient for the _access function in Windows. 50 #define F_OK 0 /* Check for file existence */ 51 #define X_OK 1 /* Check for execute permission (not supported in Windows) */ 52 #define W_OK 2 /* Check for write permission */ 53 #define R_OK 4 /* Check for read permission */ 54 55 typedef int mode_t; 56 #ifdef _WIN64 57 typedef int64_t pid_t; 58 #else 59 typedef int pid_t; 60 #endif 61 #define STDIN_FILENO _fileno(stdin) 62 #define STDOUT_FILENO _fileno(stdout) 63 #define STDERR_FILENO _fileno(stderr) 64 #define lseek(a, b, c) _lseek(a, b, c) 65 #define lseek64 _lseeki64 66 67 // These functions were deprecated and replaced with ISO C++ conformant ones 68 // in MSVC 2017. 69 /* 70 #define strdup _strdup 71 #define mkdir _mkdir 72 #define rmdir _rmdir 73 #define getcwd _getcwd 74 #define getpid _getpid 75 #define close _close 76 #define open _open 77 #define read _read 78 #define write _write 79 #define creat _creat 80 */ 81 82 // From <fcntl.h> 83 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) 84 85 // From <sys/types.h> 86 typedef int64_t off64_t; 87 88 // From <sys/cdefs.h> 89 #ifdef __cplusplus 90 #define __BEGIN_DECLS extern "C" { 91 #define __END_DECLS } 92 #else 93 #define __BEGIN_DECLS /* empty */ 94 #define __END_DECLS /* empty */ 95 #endif 96 97 98 typedef VOID (CALLBACK* SystemTime)(LPFILETIME); 99 100 // From <sys/time.h> 101 struct timezone { 102 int tz_minuteswest; /* of Greenwich */ 103 int tz_dsttime; /* type of dst correction to apply */ 104 }; 105 106 // From <strings.h> 107 #define strcasecmp _stricmp 108 #define strncasecmp _strnicmp 109 110 // From <stdio.h> 111 #define fseeko64 _fseeki64 112 #define ftello64 _ftelli64 113 114 // From <linux/limits.h> 115 #define PATH_MAX MAX_PATH 116 117 __BEGIN_DECLS 118 119 120 extern SystemTime getSystemTime; 121 extern int gettimeofday(struct timeval* tp, struct timezone* tz); 122 extern int asprintf(char** buf, const char* format, ...); 123 extern int vasprintf(char** buf, const char* format, va_list args); 124 extern int mkstemp(char* t); 125 126 __END_DECLS 127