]> The Tcpdump Group git mirrors - tcpslice/blob - seek-tell.c
Use TS_RAW_US_MAX_DIGITS in parse_time().
[tcpslice] / seek-tell.c
1 /*
2 * Copyright (c) 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 *
21 * 64-bit-offset fseek and ftell.
22 */
23
24 #include <config.h>
25
26 // For fseeko() and ftello().
27 #if defined(__SUNPRO_C) && ! defined(__EXTENSIONS__)
28 #define __EXTENSIONS__
29 #endif
30
31 #include <stdio.h>
32 #include <errno.h>
33
34 #include "tcpslice.h"
35
36 #if defined(HAVE_FSEEKO)
37 /*
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.
43 */
44 int
45 fseek64(FILE *p, const int64_t offset, const int whence)
46 {
47 off_t off_t_offset;
48
49 /*
50 * Make sure the offset fits.
51 */
52 off_t_offset = (off_t)offset;
53 if (offset != off_t_offset) {
54 /*
55 * It doesn't. Fail with EINVAL.
56 */
57 errno = EINVAL;
58 return (-1);
59 }
60 return (fseeko(p, off_t_offset, whence));
61 }
62
63 int64_t
64 ftell64(FILE *p)
65 {
66 return (ftello(p));
67 }
68 #elif defined(_MSC_VER)
69 /*
70 * We have Visual Studio; we support only 2005 and later, so we have
71 * _fseeki64() and _ftelli64().
72 */
73 int
74 fseek64(FILE *p, const int64_t offset, const int whence)
75 {
76 return (_fseeki64(p, offset, whence));
77 }
78
79 int64_t
80 ftell64(FILE *p)
81 {
82 return (_ftelli64(p));
83 }
84 #else
85 /*
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.
91 *
92 * XXX - what about MinGW?
93 */
94 int
95 fseek64(FILE *p, const int64_t offset, const int whence)
96 {
97 long long_offset;
98
99 /*
100 * Make sure the offset fits.
101 */
102 long_offset = (long)offset;
103 if (offset != long_offset) {
104 /*
105 * It doesn't. Fail with EINVAL.
106 */
107 errno = EINVAL;
108 return (-1);
109 }
110 return (fseek(p, long_offset, whence));
111 }
112
113 int64_t
114 ftell64(FILE *p)
115 {
116 return (ftell(p));
117 }
118 #endif