From 675e7b7d7993ed9b2e9e3bcd7a0de605aa4d9f0d Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 5 Apr 2017 21:19:03 -0700 Subject: [PATCH] MSVC compatibility: clean up the handling of _stati64/_fstati64 On Windows we need to use _stati64/_fstati64 in order to handle large file sizes, but the handling was broken in the canned MSVC++ configuration. Clean it up and fix it. This addresses BR 3392398. Reported-by: Nikolai Saoukh Signed-off-by: H. Peter Anvin --- Mkfiles/msvc.mak | 2 +- config/msvc.h | 9 ++++++--- configure.ac | 4 ++-- nasmlib/file.c | 6 +++--- nasmlib/file.h | 13 +++++++------ 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index 1dedad61..3141fced 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -12,7 +12,7 @@ top_srcdir = . srcdir = . VPATH = . -prefix = C:\Program Files\NASM +prefix = "C:\Program Files\NASM" exec_prefix = $(prefix) bindir = $(prefix)/bin mandir = $(prefix)/man diff --git a/config/msvc.h b/config/msvc.h index 464d06e1..4ade0273 100644 --- a/config/msvc.h +++ b/config/msvc.h @@ -49,6 +49,7 @@ * 1700 - Visual Studio 2012 * 1800 - Visual Studio 2013 * 1900 - Visual Studio 2015 + * 1910 - Visual Studio 2017 */ #ifndef NASM_CONFIG_MSVC_H @@ -112,9 +113,11 @@ /* Define to 1 if you have the `_fullpath' function. */ #define HAVE__FULLPATH 1 -/* Define to 1 if you have the `stat' function. */ -#define HAVE_STAT 1 -#define stat _stati64 +/* Define to 1 if you have the `_stati64' function. */ +#define HAVE__STATI64 1 + +/* Define to 1 if you have the `_fstati64' function. */ +#define HAVE__FSTATI64 1 /* Define to 1 if stdbool.h conforms to C99. */ #if _MSC_VER >= 1800 diff --git a/configure.ac b/configure.ac index 29bf0989..eb2a6010 100644 --- a/configure.ac +++ b/configure.ac @@ -84,8 +84,8 @@ AC_CHECK_HEADERS(fcntl.h) AC_CHECK_HEADERS(unistd.h) AC_CHECK_HEADERS(sys/param.h) AC_CHECK_HEADERS(sys/mman.h) -AC_CHECK_HEADERS(sys/stat.h) AC_CHECK_HEADERS(sys/types.h) +AC_CHECK_HEADERS(sys/stat.h) dnl Checks for library functions. AC_CHECK_FUNCS(strcasecmp stricmp) @@ -108,7 +108,7 @@ AC_CHECK_FUNCS([fileno _fileno]) AC_CHECK_FUNCS(_filelengthi64) AC_CHECK_FUNCS([stat _stati64]) -AC_CHECK_FUNCS(fstat) +AC_CHECK_FUNCS([fstat _fstati64]) AC_FUNC_MMAP AC_CHECK_FUNCS(getpagesize) AC_CHECK_FUNCS(sysconf) diff --git a/nasmlib/file.c b/nasmlib/file.c index a6e7d565..93d61117 100644 --- a/nasmlib/file.c +++ b/nasmlib/file.c @@ -208,10 +208,10 @@ off_t nasm_file_size(FILE *f) */ off_t nasm_file_size_by_path(const char *pathname) { -#ifdef HAVE_STAT - struct stat st; +#ifdef nasm_stat + struct nasm_stat st; - if (stat(pathname, &st)) + if (nasm_stat(pathname, &st)) return (off_t)-1; return st.st_size; diff --git a/nasmlib/file.h b/nasmlib/file.h index 774dadf4..df79ee89 100644 --- a/nasmlib/file.h +++ b/nasmlib/file.h @@ -43,6 +43,9 @@ #ifdef HAVE_FCNTL_H # include #endif +#ifdef HAVE_SYS_TYPES_H +# include +#endif #ifdef HAVE_SYS_STAT_H # include #endif @@ -87,14 +90,12 @@ */ #ifdef HAVE__STATI64 # define nasm_stat _stati64 +# if defined(HAVE_FILENO) && defined(HAVE__FSTATI64) +# define nasm_fstat _fstati64 +# endif #elif defined(HAVE_STAT) # define nasm_stat stat -#endif - -#ifdef HAVE_FILENO -# ifdef HAVE__FSTATI64 -# define nasm_fstat _fstati64 -# elif defined(HAVE_FSTAT) +# if defined(HAVE_FILENO) && defined(HAVE_FSTAT) # define nasm_fstat fstat # endif #endif