Revision 900cea42 src/dvbcat.cpp

View differences:

src/dvbcat.cpp
30 30
#include <getopt.h>
31 31
#include <cerrno>
32 32
#include <fstream>
33

  
34
// Unfortunately, large file support (LFS) in gcc 3.2, 3.3 is broken
35
// on Debian sarge/sid. Work around with LFS_WORKAROUND
36

  
37
#define LFS_WORKAROUND
38

  
39
#ifdef LFS_WORKAROUND
40 33
#include <fcntl.h>
41
#include <ext/stdio_filebuf.h>
42
#endif
43 34

  
44 35
void usage(const char *progname);
45 36
time_t convertTime(const char *theTime);
46
std::ostream *openOutputFile(std::string &outputfile);
47
void closeOutputFile(std::ostream *o);
37
int openOutputFile(std::string &outputfile);
38
void closeOutputFile(int fd);
48 39

  
49 40
int main(int argc, char *argv[])
50 41
{
......
115 106
  }
116 107

  
117 108
  // Open the output file
118
  std::ostream *output = openOutputFile(outputFile);
119
  if (output == NULL || !*output) {
109
  int outputFd = openOutputFile(outputFile);
110
  if (outputFd < 0) {
120 111
    std::cerr << "Fatal error: failed to open " << outputFile << " for output"
121 112
	      << std::endl;
122 113
    return 1;
......
163 154
      int bytesRead = data.read(buffer, 1024);
164 155

  
165 156
      if (bytesRead > 0) 
166
	output->write(buffer, bytesRead);
157
	write(outputFd, buffer, bytesRead);
167 158
    }
168 159
    else if (control.isReady(s)) {
169 160
      if (!control.processReady(s)) {
......
177 168
    }
178 169
  } while (true);
179 170

  
180
  closeOutputFile(output);
171
  closeOutputFile(outputFd);
181 172
  return 0;
182 173
}
183 174

  
184
std::ostream *openOutputFile(std::string &outputFile)
175
int openOutputFile(std::string &outputFile)
185 176
{
186 177
  if (outputFile == "-") 
187
    return &std::cout;
178
    return 0;
188 179

  
189
#ifndef LFS_WORKAROUND
190
  return = new std::ofstream(outputFile.c_str());
191
#else
192 180
  int openMode = O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE;
193 181

  
194 182
  // Don't bother caching if possible
......
196 184
  openMode |= O_STREAMING;
197 185
#endif
198 186
  
199
  int fd = open(outputFile.c_str(), openMode, 0644);
200
  if (fd < 0) 
201
    return NULL;
202
  return new std::ostream(new __gnu_cxx::stdio_filebuf<char>(fd, std::ios_base::out, true, BUFSIZ));
203
#endif // LFS_WORKAROUND
187
  return open(outputFile.c_str(), openMode, 0644);
204 188
}
205 189

  
206
void closeOutputFile(std::ostream *o)
190
void closeOutputFile(int fd)
207 191
{
208
  if (o != &std::cout)
209
    delete o;
192
  if (fd > 0)
193
    close(fd);
210 194
}
211 195

  
212 196
void usage(const char *progname) {

Also available in: Unified diff