Use ftruncate() not truncate() in mdunlink. Seems Windows doesn't
authorTom Lane
Thu, 15 Nov 2007 21:49:47 +0000 (21:49 +0000)
committerTom Lane
Thu, 15 Nov 2007 21:49:47 +0000 (21:49 +0000)
support the latter.

src/backend/storage/smgr/md.c

index 0ae0d0daf6b8d7f8abfb4f6321703e03a4320dd7..0211b3f74e7905b09ca07646a89f82ce97b343a4 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.131 2007/11/15 21:14:38 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.132 2007/11/15 21:49:47 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -316,7 +316,23 @@ mdunlink(RelFileNode rnode, bool isRedo)
    if (isRedo)
        ret = unlink(path);
    else
-       ret = truncate(path, 0);
+   {
+       /* truncate(2) would be easier here, but Windows hasn't got it */
+       int     fd;
+
+       fd = BasicOpenFile(path, O_RDWR | PG_BINARY, 0);
+       if (fd >= 0)
+       {
+           int     save_errno;
+
+           ret = ftruncate(fd, 0);
+           save_errno = errno;
+           close(fd);
+           errno = save_errno;
+       }
+       else
+           ret = -1;
+   }
    if (ret < 0)
    {
        if (!isRedo || errno != ENOENT)