summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2007-12-18 18:33:24 +0000
committerYang Tse <yangsita@gmail.com>2007-12-18 18:33:24 +0000
commit674845f23997c61f8e88a7d425517c4d8f496265 (patch)
tree97fd2983bdedda1821ddec4843bdbf0a684c40b3 /src
parent07a1857d59e2da6d57eb622e90822ffa4835e1de (diff)
downloadcurl-674845f23997c61f8e88a7d425517c4d8f496265.tar.gz
(http://curl.haxx.se/mail/archive-2007-12/0039.html) reported and fixed
a file truncation problem on Windows build targets triggered when retrying a download with curl.
Diffstat (limited to 'src')
-rw-r--r--src/main.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/main.c b/src/main.c
index 91b6d9fb2..b7a02b3ab 100644
--- a/src/main.c
+++ b/src/main.c
@@ -323,21 +323,19 @@ char convert_char(curl_infotype infotype, char this_char)
#define _lseeki64(hnd,ofs,whence) lseek(hnd,ofs,whence)
#endif
+#ifndef HAVE_FTRUNCATE
+#define HAVE_FTRUNCATE 1
+#endif
+
static int ftruncate64 (int fd, curl_off_t where)
{
- curl_off_t curr;
- int rc = 0;
-
- if ((curr = _lseeki64(fd, 0, SEEK_CUR)) < 0)
- return -1;
+ if(_lseeki64(fd, where, SEEK_SET) < 0)
+ return -1;
- if (_lseeki64(fd, where, SEEK_SET) < 0)
- return -1;
+ if(!SetEndOfFile((HANDLE)_get_osfhandle(fd)))
+ return -1;
- if (write(fd, 0, 0) < 0)
- rc = -1;
- _lseeki64(fd, curr, SEEK_SET);
- return rc;
+ return 0;
}
#define ftruncate(fd,where) ftruncate64(fd,where)
#endif