Mercurial > mplayer.hg
annotate osdep/fseeko.c @ 12819:e28849cfac27
removed status in debug_msg as it is nonsens anyway.
author | joyping |
---|---|
date | Wed, 14 Jul 2004 15:46:33 +0000 |
parents | cfe440920be2 |
children | 08cac43f1e38 |
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 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
6 #include "../config.h" |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
7 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
8 #if !defined(HAVE_FSEEKO) || !defined(HAVE_FTELLO) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
9 #include <stdio.h> |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
10 #include <sys/types.h> |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
11 #include <sys/stat.h> |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
12 #include <errno.h> |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
13 #endif |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
14 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
15 #ifdef WIN32 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
16 #define flockfile |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
17 #define funlockfile |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
18 #endif |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
19 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
20 /* |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
21 * 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
|
22 * 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
|
23 * integral, while fpos_t might be neither. |
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 * 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
|
26 */ |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
27 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
28 #ifndef HAVE_FSEEKO |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
29 int |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
30 fseeko(FILE *stream, off_t offset, int whence) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
31 { |
12115
cfe440920be2
10l for the orignial author and 1000l for me for commiting a broken workaround
faust3
parents:
12071
diff
changeset
|
32 fpos_t floc; |
12071
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
33 struct stat filestat; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
34 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
35 switch (whence) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
36 { |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
37 case SEEK_CUR: |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
38 flockfile(stream); |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
39 if (fgetpos(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 floc += offset; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
42 if (fsetpos(stream, &floc) != 0) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
43 goto failure; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
44 funlockfile(stream); |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
45 return 0; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
46 break; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
47 case SEEK_SET: |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
48 if (fsetpos(stream, &offset) != 0) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
49 return -1; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
50 return 0; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
51 break; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
52 case SEEK_END: |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
53 flockfile(stream); |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
54 if (fstat(fileno(stream), &filestat) != 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 floc = filestat.st_size; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
57 if (fsetpos(stream, &floc) != 0) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
58 goto failure; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
59 funlockfile(stream); |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
60 return 0; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
61 break; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
62 default: |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
63 errno = EINVAL; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
64 return -1; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
65 } |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
66 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
67 failure: |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
68 funlockfile(stream); |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
69 return -1; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
70 } |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
71 #endif |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
72 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
73 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
74 #ifndef HAVE_FTELLO |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
75 off_t |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
76 ftello(FILE *stream) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
77 { |
12115
cfe440920be2
10l for the orignial author and 1000l for me for commiting a broken workaround
faust3
parents:
12071
diff
changeset
|
78 fpos_t floc; |
12071
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
79 |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
80 if (fgetpos(stream, &floc) != 0) |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
81 return -1; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
82 return floc; |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
83 } |
ab3590ad2101
fseeko emulation patch by Steven M. Schultz <sms at 2bsd.com>
faust3
parents:
diff
changeset
|
84 #endif |