| 1 | /* Copyright 2002-2003 The MathWorks, Inc. */ |
|---|
| 2 | |
|---|
| 3 | /* io64.h |
|---|
| 4 | * |
|---|
| 5 | * Include this header file if you need to perform file I/O |
|---|
| 6 | * on large files greater than 2GB (2^31-1 bytes). |
|---|
| 7 | * The definitions in this header file are designed to facilitate |
|---|
| 8 | * cross-platform 64 bit file I/O. |
|---|
| 9 | * |
|---|
| 10 | * This file must be included before any other include file, at the |
|---|
| 11 | * very top of your source file, even before system include files |
|---|
| 12 | * such as stdio.h, to enable 64 bit file I/O for mex files. |
|---|
| 13 | * |
|---|
| 14 | * After including this file (io64.h), you should use the following |
|---|
| 15 | * functions, structs and types for file I/O to enable file I/O beyond |
|---|
| 16 | * the 2GB (2^31-1 byte) limit: |
|---|
| 17 | * |
|---|
| 18 | * fopen() - 64 bit capable after including this file, use as always |
|---|
| 19 | * with no changes |
|---|
| 20 | * |
|---|
| 21 | * getFilePos() - use this function instead of ftell(), as ftell() is |
|---|
| 22 | * not supported for 64 bit file I/O on most platforms. |
|---|
| 23 | * getFilePos() is an alias for the POSIX fgetpos() |
|---|
| 24 | * |
|---|
| 25 | * setFilePos() - use this function instead of fseek(), as fseek() is |
|---|
| 26 | * not supported for 64 bit file I/O on most platforms. |
|---|
| 27 | * setFilePos() is an alias for the POSIX fsetpos() |
|---|
| 28 | * |
|---|
| 29 | * fpos_T - the offset argument for getFilePos() and setFilePos() |
|---|
| 30 | * is really a pointer to a signed 64 bit integer, |
|---|
| 31 | * int64_T, but it must be cast to (fpos_T*) |
|---|
| 32 | * |
|---|
| 33 | * getFileStat() - use this function instead of stat() to get the size |
|---|
| 34 | * in bytes of a file on disk specified by name |
|---|
| 35 | * |
|---|
| 36 | * getFileFstat() - use this function instead of fstat() to get the size |
|---|
| 37 | * in bytes of an opened file specified by a FILE* pointer |
|---|
| 38 | * |
|---|
| 39 | * structStat - use a pointer to a structStat instead of a pointer to |
|---|
| 40 | * struct stat as argument to getFileStat() and |
|---|
| 41 | * getFileFstat() |
|---|
| 42 | * |
|---|
| 43 | * No changes are required for the following functions: |
|---|
| 44 | * |
|---|
| 45 | * fprintf(), fscanf(), fread(), fwrite(), fclose(). |
|---|
| 46 | */ |
|---|
| 47 | |
|---|
| 48 | #ifndef __tmw__io64__h__ |
|---|
| 49 | #define __tmw__io64__h__ |
|---|
| 50 | |
|---|
| 51 | #define TMW_ENABLE_INT64 (-1) |
|---|
| 52 | |
|---|
| 53 | /* linux, hpux - must be defined before any other include file */ |
|---|
| 54 | #if defined(__linux) || defined(linux) || defined(__linux__) \ |
|---|
| 55 | || defined(__hpux) || defined(hpux) |
|---|
| 56 | # undef _LARGEFILE64_SOURCE |
|---|
| 57 | # define _LARGEFILE64_SOURCE |
|---|
| 58 | #endif |
|---|
| 59 | |
|---|
| 60 | #include <stdio.h> |
|---|
| 61 | #include <sys/stat.h> |
|---|
| 62 | |
|---|
| 63 | #if defined(_MSC_VER) /* windows */ |
|---|
| 64 | # define getFilePos fgetpos |
|---|
| 65 | # define setFilePos fsetpos |
|---|
| 66 | # define structStat struct _stati64 |
|---|
| 67 | # define getFileStat _stati64 |
|---|
| 68 | # define getFileFstat _fstati64 |
|---|
| 69 | # define fileno _fileno |
|---|
| 70 | # define fpos_T fpos_t |
|---|
| 71 | #elif defined(__ppc__) /* mac */ |
|---|
| 72 | # define getFilePos fgetpos |
|---|
| 73 | # define setFilePos fsetpos |
|---|
| 74 | # define structStat struct stat |
|---|
| 75 | # define getFileStat stat |
|---|
| 76 | # define getFileFstat fstat |
|---|
| 77 | # define fpos_T fpos_t |
|---|
| 78 | #elif /* linux, hpux, sol2 */ \ |
|---|
| 79 | defined(__linux) || defined(linux) || defined(__linux__) \ |
|---|
| 80 | || defined(__hpux) || defined(hpux) \ |
|---|
| 81 | || defined(__sparc) || defined(sparc) |
|---|
| 82 | # if defined(__GNUC__) && (__GNUC__ >= 3) |
|---|
| 83 | /* fopen works for large files as-is */ |
|---|
| 84 | # else |
|---|
| 85 | # define fopen fopen64 |
|---|
| 86 | # endif |
|---|
| 87 | # define getFilePos fgetpos64 |
|---|
| 88 | # define setFilePos fsetpos64 |
|---|
| 89 | # define structStat struct stat64 |
|---|
| 90 | # define getFileStat stat64 |
|---|
| 91 | # define getFileFstat fstat64 |
|---|
| 92 | # define fpos_T fpos64_t |
|---|
| 93 | #endif |
|---|
| 94 | |
|---|
| 95 | #endif /* __tmw__io64__h__ */ |
|---|