| 224 | } |
| 225 | |
| 226 | static FILE* fopenGzippedNew(const char* filename, const char* mode) |
| 227 | { |
| 228 | // check mode |
| 229 | if (mode[0] == 'r') |
| 230 | { |
| 231 | // create the pipe |
| 232 | int hPipe[2]; |
| 233 | if (_pipe(hPipe, 2048, ((mode[1] =='b') ? _O_BINARY : _O_TEXT) | _O_NOINHERIT) == -1) |
| 234 | { |
| 235 | laserror("could not create pipe"); |
| 236 | return NULL; |
| 237 | } |
| 238 | |
| 239 | // duplicate stdin/stdout handle so we can restore them later |
| 240 | int hStdOut = _dup(_fileno(stdout)); |
| 241 | |
| 242 | // make the write end of pipe go to stdout |
| 243 | if (_dup2(hPipe[WRITE_HANDLE], _fileno(stdout)) != 0) |
| 244 | { |
| 245 | laserror("could not set pipe output"); |
| 246 | return NULL; |
| 247 | } |
| 248 | |
| 249 | // redirect read end of pipe to input file |
| 250 | if (_dup2(hPipe[READ_HANDLE], _fileno(stdin)) != 0) |
| 251 | { |
| 252 | laserror("could not redirect input file"); |
| 253 | return NULL; |
| 254 | } |
| 255 | |
| 256 | // close original write end of pipe |
| 257 | _close(hPipe[WRITE_HANDLE]); |
| 258 | |
| 259 | // Spawn process |
| 260 | HANDLE hProcess = (HANDLE)_spawnlp(P_NOWAIT, "gzip", "gzip", "-dc", filename, NULL); |
| 261 | |
| 262 | // redirect stdout back into stdout |
| 263 | if (_dup2(hStdOut, _fileno(stdout)) != 0) |
| 264 | { |
| 265 | laserror("could not reconstruct stdout"); |
| 266 | return NULL; |
| 267 | } |
| 268 | |
| 269 | // return redirected stdin |
| 270 | return stdin; |
| 271 | } |
| 272 | else |
| 273 | { |
| 274 | return NULL; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | static FILE* fopenRARed(const char* filename, const char* mode) |
| 279 | { |
nothing calls this directly
no test coverage detected