88 *
99 *
1010 * 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 $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
1515
1616#ifdef __bsdi__
1717
18+ #include <pthread.h>
1819#include <stdio.h>
1920#include <sys/types.h>
2021#include <sys/stat.h>
2526 *off_t is an arithmetic type, but not necessarily integral,
2627 *while fpos_t might be neither.
2728 *
28- *I don't think this is thread-safe.
29+ *This is thread-safe using flockfile/funlockfile .
2930 */
3031
3132int
@@ -37,11 +38,19 @@ fseeko(FILE *stream, off_t offset, int whence)
3738switch (whence )
3839{
3940case SEEK_CUR :
41+ flockfile (stream );
4042if (fgetpos (stream ,& floc )!= 0 )
43+ {
44+ funlockfile (stream );
4145return -1 ;
46+ }
4247floc += offset ;
4348if (fsetpos (stream ,& floc )!= 0 )
49+ {
50+ funlockfile (stream );
4451return -1 ;
52+ }
53+ flockfile (stream );
4554return 0 ;
4655break ;
4756case SEEK_SET :
@@ -50,11 +59,19 @@ fseeko(FILE *stream, off_t offset, int whence)
5059return 0 ;
5160break ;
5261case SEEK_END :
62+ flockfile (stream );
5363if (fstat (fileno (stream ),& filestat )!= 0 )
64+ {
65+ funlockfile (stream );
5466return -1 ;
67+ }
5568floc = filestat .st_size ;
5669if (fsetpos (stream ,& floc )!= 0 )
70+ {
71+ funlockfile (stream );
5772return -1 ;
73+ }
74+ funlockfile (stream );
5875return 0 ;
5976break ;
6077default :