Mercurial > mplayer.hg
annotate osdep/fseeko.c @ 21875:d81cf0be50f0
Frametime was being read from the wrong offset, compare
http://www.onicos.com/staff/iz/formats/gif.html#gceb
patch by John Koleszar, jkoleszar on2 com
author | diego |
---|---|
date | Sat, 13 Jan 2007 06:00:34 +0000 |
parents | e268886eb13d |
children |
rev | line source |
---|---|
12071
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
1 /* |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
2 * fseeko.c |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
3 * 64-bit versions of fseeko/ftello() for systems which do not have them |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
4 */ |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
5 |
16985 | 6 #include "config.h" |
21856
e268886eb13d
Split fseeko.c into fseeko.c and ftello.c, move #ifdefs into the build system.
diego
parents:
16985
diff
changeset
|
7 |
12071
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
8 #include <stdio.h> |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
9 #include <sys/types.h> |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
10 #include <sys/stat.h> |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
11 #include <errno.h> |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
12 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
13 #ifdef WIN32 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
14 #define flockfile |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
15 #define funlockfile |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
16 #endif |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
17 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
18 /* |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
19 * On BSD/OS and NetBSD (and perhaps others), off_t and fpos_t are the |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
20 * same. Standards say off_t is an arithmetic type, but not necessarily |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
21 * integral, while fpos_t might be neither. |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
22 * |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
23 * This is thread-safe on BSD/OS using flockfile/funlockfile. |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
24 */ |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
25 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
26 int |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
27 fseeko(FILE *stream, off_t offset, int whence) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
28 { |
12115
cfe440920be2
10l for the orignial author and 1000l for me for commiting a broken workaround
faust3
parents:
12071
diff
changeset
|
29 fpos_t floc; |
12071
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
30 struct stat filestat; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
31 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
32 switch (whence) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
33 { |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
34 case SEEK_CUR: |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
35 flockfile(stream); |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
36 if (fgetpos(stream, &floc) != 0) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
37 goto failure; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
38 floc += offset; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
39 if (fsetpos(stream, &floc) != 0) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
40 goto failure; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
41 funlockfile(stream); |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
42 return 0; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
43 break; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
44 case SEEK_SET: |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
45 if (fsetpos(stream, &offset) != 0) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
46 return -1; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
47 return 0; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
48 break; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
49 case SEEK_END: |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
50 flockfile(stream); |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
51 if (fstat(fileno(stream), &filestat) != 0) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
52 goto failure; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
53 floc = filestat.st_size; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
54 if (fsetpos(stream, &floc) != 0) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
55 goto failure; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
56 funlockfile(stream); |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
57 return 0; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
58 break; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
59 default: |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
60 errno = EINVAL; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
61 return -1; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
62 } |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
63 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
64 failure: |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
65 funlockfile(stream); |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
66 return -1; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
67 } |