00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00036 if (strcmp(fileName, "stdout") == 0) {
00037 fid = stdout;
00038 #if defined(__WIN32__) || defined(_WIN32)
00039 _setmode(_fileno(stdout), _O_BINARY);
00040 #endif
00041 } else if (strcmp(fileName, "stderr") == 0) {
00042 fid = stderr;
00043 #if defined(__WIN32__) || defined(_WIN32)
00044 _setmode(_fileno(stderr), _O_BINARY);
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
00059 if (fid != NULL && fid != stdout && fid != stderr) fclose(fid);
00060 }