diff options
author | Magnus Hagander <magnus@hagander.net> | 2008-04-10 16:58:51 +0000 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2008-04-10 16:58:51 +0000 |
commit | 47a19a495d89e00fd98ad7139beb0dbecedca353 (patch) | |
tree | 4f061bb10cad784af09e3e434e0ac39bde01c1ef /src/port/dirmod.c | |
parent | a57a1e61a17c002b300da397726b9d0fd86b59a0 (diff) | |
download | postgresql-47a19a495d89e00fd98ad7139beb0dbecedca353.tar.gz postgresql-47a19a495d89e00fd98ad7139beb0dbecedca353.zip |
Create wrapper pgwin32_safestat() and redefine stat() to it
on win32, because the stat() function in the runtime cannot
be trusted to always update the st_size field.
Per report and research by Sergey Zubkovsky.
Diffstat (limited to 'src/port/dirmod.c')
-rw-r--r-- | src/port/dirmod.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/port/dirmod.c b/src/port/dirmod.c index ac01b832053..792c3f21b64 100644 --- a/src/port/dirmod.c +++ b/src/port/dirmod.c @@ -10,7 +10,7 @@ * Win32 (NT, Win2k, XP). replace() doesn't work on Win95/98/Me. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.51 2008/01/01 19:46:00 momjian Exp $ + * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.52 2008/04/10 16:58:51 mha Exp $ * *------------------------------------------------------------------------- */ @@ -447,3 +447,37 @@ report_and_fail: pgfnames_cleanup(filenames); return false; } + + +#ifdef WIN32 +/* + * The stat() function in win32 is not guaranteed to update the st_size + * field when run. So we define our own version that uses the Win32 API + * to update this field. + */ +#undef stat +int +pgwin32_safestat(const char *path, struct stat *buf) +{ + int r; + WIN32_FILE_ATTRIBUTE_DATA attr; + + r = stat(path, buf); + if (r < 0) + return r; + + if (!GetFileAttributesEx(path, GetFileExInfoStandard, &attr)) + { + _dosmaperr(GetLastError()); + return -1; + } + + /* + * XXX no support for large files here, but we don't do that in + * general on Win32 yet. + */ + buf->st_size = attr.nFileSizeLow; + + return 0; +} +#endif |