00001 /* Copyright 2002-2003 The MathWorks, Inc. */ 00002 00003 /* io64.h 00004 * 00005 * Include this header file if you need to perform file I/O 00006 * on large files greater than 2GB (2^31-1 bytes). 00007 * The definitions in this header file are designed to facilitate 00008 * cross-platform 64 bit file I/O. 00009 * 00010 * This file must be included before any other include file, at the 00011 * very top of your source file, even before system include files 00012 * such as stdio.h, to enable 64 bit file I/O for mex files. 00013 * 00014 * After including this file (io64.h), you should use the following 00015 * functions, structs and types for file I/O to enable file I/O beyond 00016 * the 2GB (2^31-1 byte) limit: 00017 * 00018 * fopen() - 64 bit capable after including this file, use as always 00019 * with no changes 00020 * 00021 * getFilePos() - use this function instead of ftell(), as ftell() is 00022 * not supported for 64 bit file I/O on most platforms. 00023 * getFilePos() is an alias for the POSIX fgetpos() 00024 * 00025 * setFilePos() - use this function instead of fseek(), as fseek() is 00026 * not supported for 64 bit file I/O on most platforms. 00027 * setFilePos() is an alias for the POSIX fsetpos() 00028 * 00029 * fpos_T - the offset argument for getFilePos() and setFilePos() 00030 * is really a pointer to a signed 64 bit integer, 00031 * int64_T, but it must be cast to (fpos_T*) 00032 * 00033 * getFileStat() - use this function instead of stat() to get the size 00034 * in bytes of a file on disk specified by name 00035 * 00036 * getFileFstat() - use this function instead of fstat() to get the size 00037 * in bytes of an opened file specified by a FILE* pointer 00038 * 00039 * structStat - use a pointer to a structStat instead of a pointer to 00040 * struct stat as argument to getFileStat() and 00041 * getFileFstat() 00042 * 00043 * No changes are required for the following functions: 00044 * 00045 * fprintf(), fscanf(), fread(), fwrite(), fclose(). 00046 */ 00047 00048 #ifndef __tmw__io64__h__ 00049 #define __tmw__io64__h__ 00050 00051 #define TMW_ENABLE_INT64 (-1) 00052 00053 /* linux, hpux - must be defined before any other include file */ 00054 #if defined(__linux__) 00055 # undef _LARGEFILE64_SOURCE 00056 # define _LARGEFILE64_SOURCE 00057 #endif 00058 00059 #include <stdio.h> 00060 #include <sys/stat.h> 00061 00062 #if defined(_WIN32) /* windows */ 00063 # define getFilePos fgetpos 00064 # define setFilePos fsetpos 00065 # define structStat struct _stati64 00066 # define getFileStat _stati64 00067 # define getFileFstat _fstati64 00068 # define fileno _fileno 00069 # define fpos_T fpos_t 00070 #elif defined(__APPLE__) /* mac */ 00071 # define getFilePos fgetpos 00072 # define setFilePos fsetpos 00073 # define structStat struct stat 00074 # define getFileStat stat 00075 # define getFileFstat fstat 00076 # define fpos_T fpos_t 00077 #elif defined(__linux__) || defined(__sun) 00078 # if defined(__GNUC__) && (__GNUC__ >= 3) 00079 /* fopen works for large files as-is */ 00080 # else 00081 # define fopen fopen64 00082 # endif 00083 # define getFilePos fgetpos64 00084 # define setFilePos fsetpos64 00085 # define structStat struct stat64 00086 # define getFileStat stat64 00087 # define getFileFstat fstat64 00088 # define fpos_T fpos64_t 00089 #endif 00090 00091 #endif /* __tmw__io64__h__ */