Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

file_io.C

Go to the documentation of this file.
00001 #include <config.h>
00002 #include <stdio.h>
00003 #include <stdarg.h>
00004 #include <util/qcdio.h>
00005 CPS_START_NAMESPACE
00006 static FILE FAKE;
00007 const int MAX_FILENAME =200;
00008 FILE *Fopen( FileIoType type, const char *filename, const char *mode){
00009   FILE *fp = NULL;
00010   if ( type == ZERO_ONLY && UniqueID() ) return &FAKE;
00011   if(type == ADD_ID){
00012     char fname[MAX_FILENAME];
00013     if(strlen(filename)+6 >MAX_FILENAME){
00014           fprintf(stderr,"Fopen: filename(%s) is too long\n",filename);
00015       return NULL;
00016     }
00017     sprintf(fname,"%s.%d",filename,UniqueID());
00018     fp = fopen(fname,mode);
00019   } else {
00020     fp =  fopen(filename,mode);
00021   }
00022   if (fp==NULL)
00023     ERR.General("","Fopen","cannot open %s",filename);
00024   return fp;
00025 }
00026 
00027 int Fclose( FileIoType type, FILE *stream){
00028   if ( stream == &FAKE )  return 1;
00029   return fclose(stream);
00030 }
00031 
00032 int Fprintf( FileIoType type, FILE *stream, const char *format,...){
00033   if ( stream == &FAKE )  return 1;
00034   va_list args;
00035   va_start(args,format);
00036   int nb = vfprintf(stream, format, args);
00037   va_end(args);
00038   return nb;
00039 }
00040 
00041 int Fprintf( FILE *stream, const char *format,...){
00042   if ( stream == &FAKE )  return 1;
00043   va_list args;
00044   va_start(args,format);
00045   int nb = vfprintf(stream, format, args);
00046   va_end(args);
00047   return nb;
00048 }
00049 
00050 int Vfprintf( FileIoType type, FILE *stream, const char *format, va_list ap){
00051   if ( stream == &FAKE )  return 1;
00052   return vfprintf(stream, format, ap);
00053 }
00054 CPS_END_NAMESPACE

Generated on Sat Oct 10 14:11:35 2009 for Columbia Physics System by  doxygen 1.3.9.1