4 /* Copyright 1999,2001-2004,2007-2009 Alain Knaff.
5 * This file is part of mtools.
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.
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.
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/>.
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
32 # define MT_SIZE_T size_t
37 # if defined(HAVE_LLSEEK) || defined(HAVE_LSEEK64)
38 /* we have llseek. Now, what's its type called? loff_t or offset_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
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
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
61 # define MT_OFF_T off64_t
62 # define MT_SIZE_T off64_t
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
71 typedef MT_OFF_T mt_off_t;
72 typedef MT_SIZE_T mt_size_t;
75 /* testing: meant to flag dubious assignments between 32 bit length types
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)
93 #if defined(HAVE_LLSEEK) || defined(HAVE_LSEEK64)
96 # define SEEK_BITS (sizeof(off_t) * 8 - 1)
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;
103 extern off_t truncBytes32(mt_off_t off);
104 extern int fileTooBig(mt_off_t off);
106 int mt_lseek(int fd, mt_off_t where, int whence);
108 unsigned int log_2(int);