]> Savannah Git Hosting - gnulib.git/commitdiff
same-inode: don't assume memory objects have ino
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 25 Mar 2025 00:00:20 +0000 (17:00 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 25 Mar 2025 00:04:40 +0000 (17:04 -0700)
* lib/same-inode.h (psame_inode): Do not assume shared and/or
typed memory objects have reliable st_dev and st_ino when given to
stat-like functions, as POSIX does not guarantee this.
I don’t know of any such platforms (QNX perhaps?) but it’s
easy to be safe.

ChangeLog
lib/same-inode.h

index d6377489ce8c73190aa1a6bc0deeaf5ffef9df6e..d60af23955611c111438f3c25a33e4abbbf04429 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2025-03-24  Paul Eggert  <eggert@cs.ucla.edu>
 
+       same-inode: don't assume memory objects have ino
+       * lib/same-inode.h (psame_inode): Do not assume shared and/or
+       typed memory objects have reliable st_dev and st_ino when given to
+       stat-like functions, as POSIX does not guarantee this.
+       I don’t know of any such platforms (QNX perhaps?) but it’s
+       easy to be safe.
+
        same-inode: update now-wrong dependency
        * modules/same-inode (Depends-on): Depend on sys_stat-h,
        not sys_types.h.
index 8ed3b3a0cc207ca4afd2a1f27cfee0607ffa3312..70f17b0345cf242390d79120644942c8b8e7900d 100644 (file)
@@ -77,12 +77,17 @@ extern "C" {
 #define SAME_INODE(a, b) PSAME_INODE (&(a), &(b))
 
 /* True if *A and *B represent the same file.  Unlike PSAME_INODE,
-   args are evaluated once and must point to struct stat.  */
+   args are evaluated once and must point to struct stat,
+   and this function works even on POSIX platforms where fstat etc. do
+   not return useful st_dev and st_ino values for shared memory
+   objects and typed memory objects.  */
 
 SAME_INODE_INLINE bool
 psame_inode (struct stat const *a, struct stat const *b)
 {
-  return PSAME_INODE (a, b);
+  return (! (S_TYPEISSHM (a) | S_TYPEISTMO (a)
+             | S_TYPEISSHM (b) | S_TYPEISTMO (b))
+          && PSAME_INODE (a, b));
 }