8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/port/fseeko.c,v 1.1 2002/10/2320:56:24 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/src/port/fseeko.c,v 1.2 2002/10/2321:16:17 momjian Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
15
15
16
16
#ifdef __bsdi__
17
17
18
+ #include <pthread.h>
18
19
#include <stdio.h>
19
20
#include <sys/types.h>
20
21
#include <sys/stat.h>
25
26
*off_t is an arithmetic type, but not necessarily integral,
26
27
*while fpos_t might be neither.
27
28
*
28
- *I don't think this is thread-safe.
29
+ *This is thread-safe using flockfile/funlockfile .
29
30
*/
30
31
31
32
int
@@ -37,11 +38,19 @@ fseeko(FILE *stream, off_t offset, int whence)
37
38
switch (whence )
38
39
{
39
40
case SEEK_CUR :
41
+ flockfile (stream );
40
42
if (fgetpos (stream ,& floc )!= 0 )
43
+ {
44
+ funlockfile (stream );
41
45
return -1 ;
46
+ }
42
47
floc += offset ;
43
48
if (fsetpos (stream ,& floc )!= 0 )
49
+ {
50
+ funlockfile (stream );
44
51
return -1 ;
52
+ }
53
+ flockfile (stream );
45
54
return 0 ;
46
55
break ;
47
56
case SEEK_SET :
@@ -50,11 +59,19 @@ fseeko(FILE *stream, off_t offset, int whence)
50
59
return 0 ;
51
60
break ;
52
61
case SEEK_END :
62
+ flockfile (stream );
53
63
if (fstat (fileno (stream ),& filestat )!= 0 )
64
+ {
65
+ funlockfile (stream );
54
66
return -1 ;
67
+ }
55
68
floc = filestat .st_size ;
56
69
if (fsetpos (stream ,& floc )!= 0 )
70
+ {
71
+ funlockfile (stream );
57
72
return -1 ;
73
+ }
74
+ funlockfile (stream );
58
75
return 0 ;
59
76
break ;
60
77
default :