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

Commit47a19a4

Browse files
committed
Create wrapper pgwin32_safestat() and redefine stat() to it
on win32, because the stat() function in the runtime cannotbe trusted to always update the st_size field.Per report and research by Sergey Zubkovsky.
1 parenta57a1e6 commit47a19a4

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

‎src/include/port.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.118 2008/02/29 15:31:33 mha Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.119 2008/04/10 16:58:51 mha Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -298,6 +298,19 @@ extern FILE *pgwin32_fopen(const char *, const char *);
298298
#definepopen(a,b) _popen(a,b)
299299
#definepclose(a) _pclose(a)
300300

301+
/*
302+
* stat() is not guaranteed to set the st_size field on win32, so we
303+
* redefine it to our own implementation that is.
304+
*
305+
* We must pull in sys/stat.h here so the system header definition
306+
* goes in first, and we redefine that, and not the other way around.
307+
*/
308+
externintpgwin32_safestat(constchar*path,structstat*buf);
309+
#if !defined(FRONTEND)&& !defined(_DIRMOD_C)
310+
#include<sys/stat.h>
311+
#definestat(a,b) pgwin32_safestat(a,b)
312+
#endif
313+
301314
/* Missing rand functions */
302315
externlonglrand48(void);
303316
externvoidsrand48(longseed);

‎src/port/dirmod.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*Win32 (NT, Win2k, XP).replace() doesn't work on Win95/98/Me.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/port/dirmod.c,v 1.51 2008/01/01 19:46:00 momjian Exp $
13+
* $PostgreSQL: pgsql/src/port/dirmod.c,v 1.52 2008/04/10 16:58:51 mha Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -447,3 +447,37 @@ rmtree(char *path, bool rmtopdir)
447447
pgfnames_cleanup(filenames);
448448
return false;
449449
}
450+
451+
452+
#ifdefWIN32
453+
/*
454+
* The stat() function in win32 is not guaranteed to update the st_size
455+
* field when run. So we define our own version that uses the Win32 API
456+
* to update this field.
457+
*/
458+
#undef stat
459+
int
460+
pgwin32_safestat(constchar*path,structstat*buf)
461+
{
462+
intr;
463+
WIN32_FILE_ATTRIBUTE_DATAattr;
464+
465+
r=stat(path,buf);
466+
if (r<0)
467+
returnr;
468+
469+
if (!GetFileAttributesEx(path,GetFileExInfoStandard,&attr))
470+
{
471+
_dosmaperr(GetLastError());
472+
return-1;
473+
}
474+
475+
/*
476+
* XXX no support for large files here, but we don't do that in
477+
* general on Win32 yet.
478+
*/
479+
buf->st_size=attr.nFileSizeLow;
480+
481+
return0;
482+
}
483+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp