Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b9d496

Browse files
committed
Make BSD/OS fseeko thread-safe.
1 parentc9984ab commit6b9d496

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/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>
@@ -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 thisis thread-safe.
29+
*Thisis 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
caseSEEK_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
return0;
4655
break;
4756
caseSEEK_SET:
@@ -50,11 +59,19 @@ fseeko(FILE *stream, off_t offset, int whence)
5059
return0;
5160
break;
5261
caseSEEK_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
return0;
5976
break;
6077
default:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp