From 55e51d9534a547c7bd4148d952b317884991078e Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 10 May 2016 15:14:30 -0700 Subject: [PATCH] nasmlib/file.c: Windows _chsize_s() *returns* errno _chsize_s(), but not _chsize(), actually *returns* errno rather than setting errno; create a wrapper routine to make it match the other nasm_ftruncate() varieties. Signed-off-by: H. Peter Anvin --- nasmlib/file.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nasmlib/file.c b/nasmlib/file.c index 6ba38444..ce22ea31 100644 --- a/nasmlib/file.c +++ b/nasmlib/file.c @@ -60,7 +60,17 @@ /* Can we adjust the file size without actually writing all the bytes? */ #ifdef HAVE_FILENO /* Useless without fileno() */ # ifdef HAVE__CHSIZE_S -# define nasm_ftruncate(fd,size) _chsize_s(fd,size) +static int nasm_ftruncate(int fd, int64_t size) +{ + int err = _chsize_s(fd, size); + + if (!err) + return 0; + + errno = err; + return -1; +} +# define nasm_ftruncate(fd,size) nasm_ftruncate(fd,size) # elif defined(HAVE__CHSIZE) # define nasm_ftruncate(fd,size) _chsize(fd,size) # elif defined(HAVE_FTRUNCATE)