]> mj.ucw.cz Git - libucw.git/blob - lfs.h
274b72a743553c5fe239cd56dcd4a764bb8016ab
[libucw.git] / lfs.h
1 /*
2  *      UCW Library -- Large File Support
3  *
4  *      (c) 1999--2002 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _UCW_LFS_H
11 #define _UCW_LFS_H
12
13 #include <fcntl.h>
14 #include <unistd.h>
15
16 #ifdef CONFIG_LFS
17
18 #define sh_open open64
19 #define sh_seek lseek64
20 #define sh_pread pread64
21 #define sh_pwrite pwrite64
22 #define sh_ftruncate ftruncate64
23 #define sh_mmap(a,l,p,f,d,o) mmap64(a,l,p,f,d,o)
24 #define sh_pread pread64
25 #define sh_pwrite pwrite64
26 #define sh_stat stat64
27 #define sh_fstat fstat64
28 typedef struct stat64 sh_stat_t;
29
30 #else   /* !CONFIG_LFS */
31
32 #define sh_open open
33 #define sh_seek(f,o,w) lseek(f,o,w)
34 #define sh_ftruncate(f,o) ftruncate(f,o)
35 #define sh_mmap(a,l,p,f,d,o) mmap(a,l,p,f,d,o)
36 #define sh_pread pread
37 #define sh_pwrite pwrite
38 #define sh_stat stat
39 #define sh_fstat fstat
40 typedef struct stat sh_stat_t;
41
42 #endif  /* !CONFIG_LFS */
43
44 #define HAVE_PREAD
45
46 static inline sh_off_t
47 sh_file_size(byte *name)
48 {
49   int fd = sh_open(name, O_RDONLY);
50   if (fd < 0)
51     die("Cannot open %s: %m", name);
52   sh_off_t len = sh_seek(fd, 0, SEEK_END);
53   close(fd);
54   return len;
55 }
56
57 #endif  /* !_UCW_LFS_H */