Subject: Minor buglet in file causes cygwin build failure
To: None <>
From: Ian Lance Taylor <>
List: tech-toolchain
Date: 05/21/2004 00:55:03
The file src/dist/file/src/magic.c can use either utime or utimes.
The choice is made in one function, close_and_restore().  If
HAVE_UTIMES is defined, that function uses utimes.  Otherwise, if
HAVE_UTIME_H or HAVE_SYS_UTIME_H is defined, that function uses

That is fine.  However, at the top of the file, when including header
files, it checks for HAVE_UTIME before checking for HAVE_UTIMES.  In
particular, <sys/time.h> is only included if HAVE_UTIME is not

When cross-building the tools on cygwin (please don't ask), both
HAVE_UTIME and HAVE_UTIMES are defined, so <sys/time.h> is not
included.  The compilation then gets an error because struct timeval
is not defined:

/home/ian/wasabisrc/src/dist/file/src/magic.c: In function `close_and_restore':
/home/ian/wasabisrc/src/dist/file/src/magic.c:198: error: storage size of `utsb\uf' isn't known

I have appended what seems to me to be the obvious patch: to check for
HAVE_UTIMES before HAVE_UTIME when including header files, so that the
header file inclusion matches the usage.

(By the way, in the HAVE_UTIMES case, the tv_usec fields of the struct
timeval arguments to utimes are uninitialized.  I suppose this doesn't
matter because current file systems will ignore the microsecond values
anyhow.  But it seems like a lurking bug.  I haven't included the
obvious fix.)



Index: magic.c
RCS file: /cvsroot/wasabisrc/src/dist/file/src/magic.c,v
retrieving revision
diff -p -u -r1.1.1.5 magic.c
--- magic.c	10 May 2004 04:18:24 -0000
+++ magic.c	21 May 2004 04:36:05 -0000
@@ -44,14 +44,14 @@
 #include <sys/mman.h>
-#if defined(HAVE_UTIME)
+#if defined(HAVE_UTIMES)
+# include <sys/time.h>
+#elif defined(HAVE_UTIME)
 # if defined(HAVE_SYS_UTIME_H)
 #  include <sys/utime.h>
 # elif defined(HAVE_UTIME_H)
 #  include <utime.h>
 # endif
-#elif defined(HAVE_UTIMES)
-# include <sys/time.h>