files.h 778 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#ifndef FILES_H
#define FILES_H

#ifdef _MSC_VER
  #include <io.h>
  #include <direct.h>
  #define GET_WORKDIR _getcwd
  #define OPEN_FILE _open
  #define LSEEK_FD _lseek
  #define FOPEN_RO(_descriptor,_filename) \
    if(fopen_s(&(_descriptor),_filename,"r")){ \
        fprintf(stderr,"unable to open file '%s'\n",_filename); \
        exit(-1); \
    }
#else
  #include <cstdio>     // for fopen and fclose
  #include <unistd.h>   // for getcwd, getpwuid, getuid
  #define GET_WORKDIR getcwd
  #define OPEN_FILE open
  #define LSEEK_FD lseek
  #define FOPEN_RO(_descriptor,_filename) \
    _descriptor=fopen(_filename,"r"); \
    if((_descriptor)==NULL){ \
        fprintf(stderr,"unable to open file '%s'\n",_filename); \
        exit(-1); \
    }
#endif

#endif // FILES_H