File tree Expand file tree Collapse file tree 2 files changed +49
-2
lines changed
Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Original file line number Diff line number Diff line change 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#define popen (a ,b ) _popen(a,b)
299299#define pclose (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+ extern int pgwin32_safestat (const char * path , struct stat * buf );
309+ #if !defined(FRONTEND ) && !defined(_DIRMOD_C )
310+ #include <sys/stat.h>
311+ #define stat (a ,b ) pgwin32_safestat(a,b)
312+ #endif
313+
301314/* Missing rand functions */
302315extern long lrand48 (void );
303316extern void srand48 (long seed );
Original file line number Diff line number Diff line change 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+ #ifdef WIN32
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 (const char * path , struct stat * buf )
461+ {
462+ int r ;
463+ WIN32_FILE_ATTRIBUTE_DATA attr ;
464+
465+ r = stat (path , buf );
466+ if (r < 0 )
467+ return r ;
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+ return 0 ;
482+ }
483+ #endif
You can’t perform that action at this time.
0 commit comments