46 static FILE* fopen7zipped(
const char* 
filename, 
const char* mode)
 
   53                 if (_pipe(hPipe, 2048, ((mode[1] ==
'b') ? _O_BINARY : _O_TEXT) | _O_NOINHERIT) == -1)
 
   55                         fprintf(stderr, 
"could not create pipe\n");
 
   60                 int hStdOut = _dup(_fileno(stdout));
 
   65                         fprintf(stderr, 
"could not set pipe output\n");
 
   72                         fprintf(stderr, 
"could not redirect input file\n");
 
   80                 HANDLE hProcess = (HANDLE) spawnlp(P_NOWAIT, 
"7z", 
"7z", 
"e", 
"-so", 
filename, 
NULL);
 
   83                 if (_dup2(hStdOut, _fileno(stdout)) != 0)
 
   85                         fprintf(stderr, 
"could not reconstruct stdout\n");
 
   98 static FILE* fopenZIPped(
const char* 
filename, 
const char* mode)
 
  105                 if (_pipe(hPipe, 2048, ((mode[1] ==
'b') ? _O_BINARY : _O_TEXT) | _O_NOINHERIT) == -1)
 
  107                         fprintf(stderr, 
"could not create pipe\n");
 
  112                 int hStdOut = _dup(_fileno(stdout));
 
  117                         fprintf(stderr, 
"could not set pipe output\n");
 
  122                 if (_dup2(hPipe[
READ_HANDLE], _fileno(stdin)) != 0)
 
  124                         fprintf(stderr, 
"could not redirect input file\n");
 
  132                 HANDLE hProcess = (HANDLE) spawnlp(P_NOWAIT, 
"unzip", 
"unzip", 
"-p", 
filename, 
NULL);
 
  135                 if (_dup2(hStdOut, _fileno(stdout)) != 0)
 
  137                         fprintf(stderr, 
"could not reconstruct stdout\n");
 
  150 static FILE* fopenGzipped(
const char* 
filename, 
const char* mode)
 
  156                 FILE* gzipInput = fopen(
filename, mode);
 
  157                 if (!gzipInput) 
return NULL;
 
  161                 if (_pipe(hPipe, 2048, ((mode[1] ==
'b') ? _O_BINARY : _O_TEXT) | _O_NOINHERIT) == -1)
 
  163                         fprintf(stderr, 
"could not create pipe\n");
 
  168                 int hStdIn = _dup(_fileno(stdin));
 
  170                 if (_dup2(_fileno(gzipInput), _fileno(stdin)) != 0)
 
  172                         fprintf(stderr, 
"could not redirect stdin\n");
 
  177                 int hStdOut = _dup(_fileno(stdout));
 
  181                         fprintf(stderr, 
"could not set pipe output\n");
 
  189                 if (_dup2(hPipe[
READ_HANDLE], _fileno(gzipInput)) != 0)
 
  191                         fprintf(stderr, 
"could not redirect input file\n");
 
  199                 HANDLE hProcess = (HANDLE) spawnlp(P_NOWAIT, 
"gzip", 
"gzip", 
"-d", 
NULL);
 
  202                 if (_dup2(hStdIn, _fileno(stdin)) != 0)
 
  204                         fprintf(stderr, 
"could not reconstruct stdin\n");
 
  209                 if (_dup2(hStdOut, _fileno(stdout)) != 0)
 
  211                         fprintf(stderr, 
"could not reconstruct stdout\n");
 
  224 static FILE* fopenGzippedNew(
const char* 
filename, 
const char* mode)
 
  231                 if (_pipe(hPipe, 2048, ((mode[1] ==
'b') ? _O_BINARY : _O_TEXT) | _O_NOINHERIT) == -1)
 
  233                         fprintf(stderr, 
"could not create pipe\n");
 
  238                 int hStdOut = _dup(_fileno(stdout));
 
  243                         fprintf(stderr, 
"could not set pipe output\n");
 
  248                 if (_dup2(hPipe[
READ_HANDLE], _fileno(stdin)) != 0)
 
  250                         fprintf(stderr, 
"could not redirect input file\n");
 
  258                 HANDLE hProcess = (HANDLE) spawnlp(P_NOWAIT, 
"gzip", 
"gzip", 
"-dc", 
filename, 
NULL);
 
  261                 if (_dup2(hStdOut, _fileno(stdout)) != 0)
 
  263                         fprintf(stderr, 
"could not reconstruct stdout\n");
 
  276 static FILE* fopenRARed(
const char* 
filename, 
const char* mode)
 
  283                 if (_pipe(hPipe, 2048, ((mode[1] ==
'b') ? _O_BINARY : _O_TEXT) | _O_NOINHERIT) == -1)
 
  285                         fprintf(stderr, 
"could not create pipe\n");
 
  290                 int hStdOut = _dup(_fileno(stdout));
 
  295                         fprintf(stderr, 
"could not set pipe output\n");
 
  300                 if (_dup2(hPipe[
READ_HANDLE], _fileno(stdin)) != 0)
 
  302                         fprintf(stderr, 
"could not redirect input file\n");
 
  310                 HANDLE hProcess = (HANDLE) spawnlp(P_NOWAIT, 
"unrar", 
"unrar", 
"p", 
"-ierr", 
filename, 
NULL);
 
  313                 if (_dup2(hStdOut, _fileno(stdout)) != 0)
 
  315                         fprintf(stderr, 
"could not reconstruct stdout\n");
 
  339     if (piped) *piped = 
true;
 
  341     fprintf(stderr, 
"ERROR: no support for gzipped input\n");
 
  349     if (piped) *piped = 
true;
 
  351     fprintf(stderr, 
"ERROR: no support for ZIPped input\n");
 
  359     if (piped) *piped = 
true;
 
  361     fprintf(stderr, 
"ERROR: no support for 7zipped input\n");
 
  369     if (piped) *piped = 
true;
 
  371     fprintf(stderr, 
"ERROR: no support for RARed input\n");
 
  378     if (piped) *piped = 
false;