1 #ifndef MTOOLS_LLONG_H 2 #define MTOOLS_LLONG_H 3 4 /* Copyright 1999,2001-2004,2007-2009 Alain Knaff. 5 * This file is part of mtools. 6 * 7 * Mtools is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * Mtools is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with Mtools. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #if 1 22 23 24 #ifdef HAVE_OFF_T_64 25 /* if off_t is already 64 bits, be happy, and don't worry about the 26 * loff_t and llseek stuff */ 27 # define MT_OFF_T off_t 28 # if SIZEOF_SIZE_T == 4 29 /* Some systems (NetBSD) apparently have 64 bit off_t, but 32 bit size_t ... */ 30 # define MT_SIZE_T off_t 31 # else 32 # define MT_SIZE_T size_t 33 # endif 34 #endif 35 36 #ifndef MT_OFF_T 37 # if defined(HAVE_LLSEEK) || defined(HAVE_LSEEK64) 38 /* we have llseek. Now, what's its type called? loff_t or offset_t ? */ 39 # ifdef HAVE_LOFF_T 40 # define MT_OFF_T loff_t 41 /* use the same type for size. Better to get signedness wrong than width */ 42 # define MT_SIZE_T loff_t 43 # else 44 # ifdef HAVE_OFFSET_T 45 # define MT_OFF_T offset_t 46 /* use the same type for size. Better to get signedness wrong than width */ 47 # define MT_SIZE_T offset_t 48 # endif 49 # endif 50 # endif 51 #endif 52 53 #ifndef MT_OFF_T 54 /* we still don't have a suitable mt_off_t type...*/ 55 # ifdef HAVE_LONG_LONG 56 /* ... first try long long ... */ 57 # define MT_OFF_T long long 58 # define MT_SIZE_T unsigned long long 59 # else 60 # ifdef HAVE_OFF64_T 61 # define MT_OFF_T off64_t 62 # define MT_SIZE_T off64_t 63 # else 64 /* ... and if that fails, fall back on good ole' off_t */ 65 # define MT_OFF_T off_t 66 # define MT_SIZE_T size_t 67 # endif 68 # endif 69 #endif 70 71 typedef MT_OFF_T mt_off_t; 72 typedef MT_SIZE_T mt_size_t; 73 74 #else 75 /* testing: meant to flag dubious assignments between 32 bit length types 76 * and 64 bit ones */ 77 typedef struct { 78 unsigned int lo; 79 int high; 80 } *mt_off_t; 81 82 typedef struct { 83 unsigned int lo; 84 unsigned int high; 85 } *mt_size_t; 86 87 #endif 88 89 #define min(a,b) ((a) < (b) ? (a) : (b)) 90 #define MAX_OFF_T_B(bits) \ 91 ((((mt_off_t) 1 << min(bits-1, sizeof(mt_off_t)*8 - 2)) -1) << 1 | 1) 92 93 #if defined(HAVE_LLSEEK) || defined(HAVE_LSEEK64) 94 # define SEEK_BITS 63 95 #else 96 # define SEEK_BITS (sizeof(off_t) * 8 - 1) 97 #endif 98 99 extern const mt_off_t max_off_t_31; 100 extern const mt_off_t max_off_t_41; 101 extern const mt_off_t max_off_t_seek; 102 103 extern off_t truncBytes32(mt_off_t off); 104 extern int fileTooBig(mt_off_t off); 105 106 int mt_lseek(int fd, mt_off_t where, int whence); 107 108 unsigned int log_2(int); 109 110 #endif 111