From: Paul Eggert Date: Tue, 25 Mar 2025 00:00:20 +0000 (-0700) Subject: same-inode: don't assume memory objects have ino X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=16a5aa623106fbab7eacb0dfd081288ae79c16cf;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index d6377489ce..d60af23955 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2025-03-24 Paul Eggert + 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. diff --git a/lib/same-inode.h b/lib/same-inode.h index 8ed3b3a0cc..70f17b0345 100644 --- a/lib/same-inode.h +++ b/lib/same-inode.h @@ -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)); }