liveMedia/OutputFile.cpp

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2012 Live Networks, Inc.  All rights reserved.
00018 // Common routines for opening/closing named output files
00019 // Implementation
00020 
00021 #if (defined(__WIN32__) || defined(_WIN32)) && !defined(_WIN32_WCE)
00022 #include <io.h>
00023 #include <fcntl.h>
00024 #endif
00025 #ifndef _WIN32_WCE
00026 #include <sys/stat.h>
00027 #endif
00028 #include <string.h>
00029 
00030 #include "OutputFile.hh"
00031 
00032 FILE* OpenOutputFile(UsageEnvironment& env, char const* fileName) {
00033   FILE* fid;
00034 
00035   // Check for special case 'file names': "stdout" and "stderr"
00036   if (strcmp(fileName, "stdout") == 0) {
00037     fid = stdout;
00038 #if (defined(__WIN32__) || defined(_WIN32)) && !defined(_WIN32_WCE)
00039     _setmode(_fileno(stdout), _O_BINARY);       // convert to binary mode
00040 #endif
00041   } else if (strcmp(fileName, "stderr") == 0) {
00042     fid = stderr;
00043 #if (defined(__WIN32__) || defined(_WIN32)) && !defined(_WIN32_WCE)
00044     _setmode(_fileno(stderr), _O_BINARY);       // convert to binary mode
00045 #endif
00046   } else {
00047     fid = fopen(fileName, "wb");
00048   }
00049 
00050   if (fid == NULL) {
00051     env.setResultMsg("unable to open file \"", fileName, "\"");
00052   }
00053 
00054   return fid;
00055 }
00056 
00057 void CloseOutputFile(FILE* fid) {
00058   // Don't close 'stdout' or 'stderr', in case we want to use it again later.
00059   if (fid != NULL && fid != stdout && fid != stderr) fclose(fid);
00060 }

Generated on Thu May 17 07:11:47 2012 for live by  doxygen 1.5.2