git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a57a1e6)
Create wrapper pgwin32_safestat() and redefine stat() to it
2008年4月10日 16:58:51 +0000 (16:58 +0000)
2008年4月10日 16:58:51 +0000 (16:58 +0000)
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.


diff --git a/src/include/port.h b/src/include/port.h
index 38c6c5f68691a1d91a99fd35f4ebd1b6c9ac0870..e1cc4c74dc67bb773caed1bc4f96a888e8792753 100644 (file)
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/port.h,v 1.118 2008年02月29日 15:31:33 mha Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.119 2008年04月10日 16:58:51 mha Exp $
*
*-------------------------------------------------------------------------
*/
@@ -298,6 +298,19 @@ extern FILE *pgwin32_fopen(const char *, const char *);
#define popen(a,b) _popen(a,b)
#define pclose(a) _pclose(a)
+/*
+ * stat() is not guaranteed to set the st_size field on win32, so we
+ * redefine it to our own implementation that is.
+ *
+ * We must pull in sys/stat.h here so the system header definition
+ * goes in first, and we redefine that, and not the other way around.
+ */
+extern int pgwin32_safestat(const char *path, struct stat *buf);
+#if !defined(FRONTEND) && !defined(_DIRMOD_C)
+#include <sys/stat.h>
+#define stat(a,b) pgwin32_safestat(a,b)
+#endif
+
/* Missing rand functions */
extern long lrand48(void);
extern void srand48(long seed);
diff --git a/src/port/dirmod.c b/src/port/dirmod.c
index ac01b832053dd25a65fd8d803bb6bc96750a5569..792c3f21b6431db44e6edc5cdea50fbef87c1fb6 100644 (file)
--- 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
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /