* 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 | 7 +++++++ lib/same-inode.h | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog index d6377489ce..d60af23955 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2025-03-24 Paul Eggert <egg...@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. 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)); } -- 2.49.0