Skip to content

Commit 6b9d496

Browse files
committed
Make BSD/OS fseeko thread-safe.
1 parent c9984ab commit 6b9d496

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/port/fseeko.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/port/fseeko.c,v 1.1 2002/10/23 20:56:24 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/port/fseeko.c,v 1.2 2002/10/23 21: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>
@@ -25,7 +26,7 @@
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

3132
int
@@ -37,11 +38,19 @@ fseeko(FILE *stream, off_t offset, int whence)
3738
switch (whence)
3839
{
3940
case SEEK_CUR:
41+
flockfile(stream);
4042
if (fgetpos(stream, &floc) != 0)
43+
{
44+
funlockfile(stream);
4145
return -1;
46+
}
4247
floc += offset;
4348
if (fsetpos(stream, &floc) != 0)
49+
{
50+
funlockfile(stream);
4451
return -1;
52+
}
53+
flockfile(stream);
4554
return 0;
4655
break;
4756
case SEEK_SET:
@@ -50,11 +59,19 @@ fseeko(FILE *stream, off_t offset, int whence)
5059
return 0;
5160
break;
5261
case SEEK_END:
62+
flockfile(stream);
5363
if (fstat(fileno(stream), &filestat) != 0)
64+
{
65+
funlockfile(stream);
5466
return -1;
67+
}
5568
floc = filestat.st_size;
5669
if (fsetpos(stream, &floc) != 0)
70+
{
71+
funlockfile(stream);
5772
return -1;
73+
}
74+
funlockfile(stream);
5875
return 0;
5976
break;
6077
default:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy