]>
The Tcpdump Group git mirrors - tcpslice/blob - seek-tell.c
2 * Copyright (c) 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * 64-bit-offset fseek and ftell.
26 // For fseeko() and ftello().
27 #if defined(__SUNPRO_C) && ! defined(__EXTENSIONS__)
28 #define __EXTENSIONS__
36 #if defined(HAVE_FSEEKO)
38 * We have fseeko(), so we have ftello().
39 * If we have large file support (files larger than 2^31-1 bytes),
40 * fseeko() will let us seek to a current file position with more
41 * than 32 bits and ftello() will give us a current file position
42 * with more than 32 bits.
45 fseek64(FILE *p
, const int64_t offset
, const int whence
)
50 * Make sure the offset fits.
52 off_t_offset
= (off_t
)offset
;
53 if (offset
!= off_t_offset
) {
55 * It doesn't. Fail with EINVAL.
60 return (fseeko(p
, off_t_offset
, whence
));
68 #elif defined(_MSC_VER)
70 * We have Visual Studio; we support only 2005 and later, so we have
71 * _fseeki64() and _ftelli64().
74 fseek64(FILE *p
, const int64_t offset
, const int whence
)
76 return (_fseeki64(p
, offset
, whence
));
82 return (_ftelli64(p
));
86 * We don't have ftello() or _ftelli64(), so fall back on ftell().
87 * Either long is 64 bits, in which case ftell() should suffice,
88 * or this is probably an older 32-bit UN*X without large file
89 * support, which means you'll probably get errors trying to
90 * write files > 2^31-1, so it won't matter anyway.
92 * XXX - what about MinGW?
95 fseek64(FILE *p
, const int64_t offset
, const int whence
)
100 * Make sure the offset fits.
102 long_offset
= (long)offset
;
103 if (offset
!= long_offset
) {
105 * It doesn't. Fail with EINVAL.
110 return (fseek(p
, long_offset
, whence
));