libStatGen Software  1
GzipFileType.cpp
1 /*
2  * Copyright (C) 2010 Regents of the University of Michigan
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "GzipFileType.h"
19 #include <string.h>
20 #include <stdio.h>
21 
22 #ifdef __ZLIB_AVAILABLE__
23 
24 GzipFileType::GzipFileType(const char * filename, const char * mode)
25 {
26  // If the file is for write and is '-', then write to stdout.
27  if(((mode[0] == 'w') || (mode[0] == 'W')) &&
28  ((strcmp(filename, "-") == 0) || (strcmp(filename, "-.gz") == 0)))
29  {
30  // Write to stdout.
31  gzHandle = gzdopen(fileno(stdout), mode);
32  }
33  else if(((mode[0] == 'r') || (mode[0] == 'R')) &&
34  ((strcmp(filename, "-") == 0) || (strcmp(filename, "-.gz") == 0)))
35  {
36  // read from stdin
37  gzHandle = gzdopen(fileno(stdin), mode);
38  }
39  else
40  {
41  // Open the file.
42  gzHandle = gzopen(filename, mode);
43  }
44 };
45 
46 #endif
47