From 591b9b091ce55be90cd4807cfe39b01428107a87 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 15 Nov 2007 21:49:47 +0000 Subject: [PATCH] Use ftruncate() not truncate() in mdunlink. Seems Windows doesn't support the latter. --- src/backend/storage/smgr/md.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index 0ae0d0daf6..0211b3f74e 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -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) -- GitLab