| 105 | #ifdef _MSC_VER |
| 106 | /* open file using Windows API, as we may need to delete it while it is still open */ |
| 107 | HANDLE handleWin = CreateFile(name.c_str(), |
| 108 | GENERIC_WRITE, |
| 109 | FILE_SHARE_WRITE | FILE_SHARE_DELETE, /* FILE_SHARE_DELETE allows it to be deleted while open */ |
| 110 | NULL, |
| 111 | CREATE_ALWAYS, |
| 112 | FILE_ATTRIBUTE_NORMAL, |
| 113 | NULL); |
| 114 | if( handleWin == INVALID_HANDLE_VALUE) |
| 115 | { /* Failed to open */ |
| 116 | switch(GetLastError()){ |
| 117 | case ERROR_ALREADY_EXISTS: _set_errno(EEXIST); break; |
| 118 | case ERROR_ACCESS_DENIED: _set_errno(EACCES); break; |
| 119 | } |
| 120 | return -1; |
| 121 | } |
| 122 | |
| 123 | /* Now return a standard file descriptor */ |
| 124 | int fd = _open_osfhandle((intptr_t)handleWin, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); |
| 125 | |
| 126 | #else |
| 145 | #ifdef _MSC_VER |
| 146 | /* open file using Windows API, as we may need to delete it while it is still open */ |
| 147 | HANDLE handleWin = CreateFile(name.c_str(), |
| 148 | GENERIC_READ | GENERIC_WRITE, |
| 149 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, /* FILE_SHARE_DELETE allows it to be deleted while open */ |
| 150 | NULL, |
| 151 | CREATE_ALWAYS, |
| 152 | FILE_ATTRIBUTE_NORMAL, |
| 153 | NULL); |
| 154 | if( handleWin == INVALID_HANDLE_VALUE) |
| 155 | { /* Failed to open */ |
| 156 | switch(GetLastError()){ |
| 157 | case ERROR_ALREADY_EXISTS: _set_errno(EEXIST); break; |
| 158 | case ERROR_ACCESS_DENIED: _set_errno(EACCES); break; |
| 159 | } |
| 160 | return -1; |
| 161 | } |
| 162 | |
| 163 | /* Now return a standard file descriptor */ |
| 164 | int fd = _open_osfhandle((intptr_t)handleWin, O_RDWR | O_CREAT | O_TRUNC | O_BINARY); |
| 165 | |
| 166 | #else |