changeset 38226:ad896936aac4

same-inode: port to MinGW Here st_ino is always 0, so change the definition of SAME_INODE so that 1 means the two files are the same, 0 with st_ino != 0 means they differ, and 0 with st_ino == 0 means we don’t know. Problem reported by Bruno Haible (Bug#25146). * doc/posix-headers/sys_stat.texi (sys/stat.h): Update. * lib/same-inode.h (SAME_INODE): Return 0 on MinGW.
author Paul Eggert <eggert@cs.ucla.edu>
date Fri, 09 Dec 2016 08:16:13 -0800
parents b052d67dd6e2
children bab27c536fba
files ChangeLog doc/posix-headers/sys_stat.texi lib/same-inode.h
diffstat 3 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Dec 04 19:50:26 2016 +0100
+++ b/ChangeLog	Fri Dec 09 08:16:13 2016 -0800
@@ -1,3 +1,13 @@
+2016-12-09  Paul Eggert  <eggert@cs.ucla.edu>
+
+	same-inode: port to MinGW
+	Here st_ino is always 0, so change the definition of SAME_INODE so
+	that 1 means the two files are the same, 0 with st_ino != 0 means
+	they differ, and 0 with st_ino == 0 means we don’t know.  Problem
+	reported by Bruno Haible (Bug#25146).
+	* doc/posix-headers/sys_stat.texi (sys/stat.h): Update.
+	* lib/same-inode.h (SAME_INODE): Return 0 on MinGW.
+
 2016-12-04  Bruno Haible  <bruno@clisp.org>
 
 	javacomp: Support Java 7 and 8.
--- a/doc/posix-headers/sys_stat.texi	Sun Dec 04 19:50:26 2016 +0100
+++ b/doc/posix-headers/sys_stat.texi	Fri Dec 09 08:16:13 2016 -0800
@@ -44,8 +44,8 @@
 @item
 To partially work around the previous two problems, you can test for
 nonzero @code{st_ino} and use the Gnulib @code{same-inode} module to
-compare nonzero values.  For example, @code{(a.st_ino && SAME_INODE
-(a, b))} is true if the @code{struct stat} values @code{a} and
+compare nonzero values.  For example, @code{SAME_INODE (a, b)}
+is true if the @code{struct stat} values @code{a} and
 @code{b} are known to represent the same file, @code{(a.st_ino &&
 !SAME_INODE (a, b))} is true if they are known to represent different
 files, and @code{!a.st_ino} is true if it is not known whether they
--- a/lib/same-inode.h	Sun Dec 04 19:50:26 2016 +0100
+++ b/lib/same-inode.h	Fri Dec 09 08:16:13 2016 -0800
@@ -1,4 +1,4 @@
-/* Determine whether two stat buffers refer to the same file.
+/* Determine whether two stat buffers are known to refer to the same file.
 
    Copyright (C) 2006, 2009-2016 Free Software Foundation, Inc.
 
@@ -24,6 +24,10 @@
      && (a).st_ino[1] == (b).st_ino[1] \
      && (a).st_ino[2] == (b).st_ino[2] \
      && (a).st_dev == (b).st_dev)
+# elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* On MinGW, struct stat lacks necessary info, so always return 0.
+   Callers can use !a.st_ino to deduce that the information is unknown.  */
+#  define SAME_INODE(a, b) 0
 # else
 #  define SAME_INODE(a, b)    \
     ((a).st_ino == (b).st_ino \