exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / same-inode.h
blob62dd088e538e1134365b7992357e696c1ed9a653
1 /* Determine whether two stat buffers are known to refer to the same file.
3 Copyright (C) 2006, 2009-2024 Free Software Foundation, Inc.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #ifndef SAME_INODE_H
19 #define SAME_INODE_H 1
21 /* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */
22 #if !_GL_CONFIG_H_INCLUDED
23 #error "Please include config.h first."
24 #endif
26 #include <sys/stat.h>
28 _GL_INLINE_HEADER_BEGIN
29 #ifndef SAME_INODE_INLINE
30 # define SAME_INODE_INLINE _GL_INLINE
31 #endif
33 /* True if A and B point to structs with st_dev and st_ino members
34 that are known to represent the same file.
36 Use | and ^ to shorten generated code, and to lessen the
37 probability of screwups if st_ino is an array. */
39 #if defined __VMS && __CRTL_VER < 80200000
40 # define PSAME_INODE(a, b) (! (((a)->st_dev ^ (b)->st_dev) \
41 | ((a)->st_ino[0] ^ (b)->st_ino[0]) \
42 | ((a)->st_ino[1] ^ (b)->st_ino[1]) \
43 | ((a)->st_ino[2] ^ (b)->st_ino[2])))
44 #elif defined _WIN32 && ! defined __CYGWIN__
45 /* Native Windows. */
46 # if _GL_WINDOWS_STAT_INODES
47 /* stat() and fstat() set st_dev and st_ino to 0 if information about
48 the inode is not available. */
49 # if _GL_WINDOWS_STAT_INODES == 2
50 # define PSAME_INODE(a, b) \
51 (! (! ((a)->st_dev | (a)->st_ino._gl_ino[0] | (a)->st_ino._gl_ino[1]) \
52 | ((a)->st_dev ^ (b)->st_dev) \
53 | ((a)->st_ino._gl_ino[0] ^ (b)->st_ino._gl_ino[0]) \
54 | ((a)->st_ino._gl_ino[1] ^ (b)->st_ino._gl_ino[1])))
55 # else
56 # define PSAME_INODE(a, b) (! (! ((a)->st_dev | (a)->st_ino) \
57 | ((a)->st_dev ^ (b)->st_dev) \
58 | ((a)->st_ino ^ (b)->st_ino)))
59 # endif
60 # else
61 /* stat() and fstat() set st_ino to 0 always. */
62 # define PSAME_INODE(a, b) 0
63 # endif
64 #else
65 /* POSIX. */
66 # define PSAME_INODE(a, b) (! (((a)->st_dev ^ (b)->st_dev) \
67 | ((a)->st_ino ^ (b)->st_ino)))
68 #endif
70 /* True if struct objects A and B are known to represent the same file. */
72 #define SAME_INODE(a, b) PSAME_INODE (&(a), &(b))
74 /* True if *A and *B represent the same file. Unlike PSAME_INODE,
75 args are evaluated once and must point to struct stat. */
77 SAME_INODE_INLINE bool
78 psame_inode (struct stat const *a, struct stat const *b)
80 return PSAME_INODE (a, b);
83 _GL_INLINE_HEADER_END
85 #endif