gettext: Sync with gettext 0.23.
[gnulib.git] / lib / same-inode.h
blob13ae24b71bb54b824d4f9bc904a9294787534d09
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 #ifdef __cplusplus
34 extern "C" {
35 #endif
38 /* True if A and B point to structs with st_dev and st_ino members
39 that are known to represent the same file.
41 Use | and ^ to shorten generated code, and to lessen the
42 probability of screwups if st_ino is an array. */
44 #if defined __VMS && __CRTL_VER < 80200000
45 # define PSAME_INODE(a, b) (! (((a)->st_dev ^ (b)->st_dev) \
46 | ((a)->st_ino[0] ^ (b)->st_ino[0]) \
47 | ((a)->st_ino[1] ^ (b)->st_ino[1]) \
48 | ((a)->st_ino[2] ^ (b)->st_ino[2])))
49 #elif defined _WIN32 && ! defined __CYGWIN__
50 /* Native Windows. */
51 # if _GL_WINDOWS_STAT_INODES
52 /* stat() and fstat() set st_dev and st_ino to 0 if information about
53 the inode is not available. */
54 # if _GL_WINDOWS_STAT_INODES == 2
55 # define PSAME_INODE(a, b) \
56 (! (! ((a)->st_dev | (a)->st_ino._gl_ino[0] | (a)->st_ino._gl_ino[1]) \
57 | ((a)->st_dev ^ (b)->st_dev) \
58 | ((a)->st_ino._gl_ino[0] ^ (b)->st_ino._gl_ino[0]) \
59 | ((a)->st_ino._gl_ino[1] ^ (b)->st_ino._gl_ino[1])))
60 # else
61 # define PSAME_INODE(a, b) (! (! ((a)->st_dev | (a)->st_ino) \
62 | ((a)->st_dev ^ (b)->st_dev) \
63 | ((a)->st_ino ^ (b)->st_ino)))
64 # endif
65 # else
66 /* stat() and fstat() set st_ino to 0 always. */
67 # define PSAME_INODE(a, b) 0
68 # endif
69 #else
70 /* POSIX. */
71 # define PSAME_INODE(a, b) (! (((a)->st_dev ^ (b)->st_dev) \
72 | ((a)->st_ino ^ (b)->st_ino)))
73 #endif
75 /* True if struct objects A and B are known to represent the same file. */
77 #define SAME_INODE(a, b) PSAME_INODE (&(a), &(b))
79 /* True if *A and *B represent the same file. Unlike PSAME_INODE,
80 args are evaluated once and must point to struct stat. */
82 SAME_INODE_INLINE bool
83 psame_inode (struct stat const *a, struct stat const *b)
85 return PSAME_INODE (a, b);
89 #ifdef __cplusplus
91 #endif
93 _GL_INLINE_HEADER_END
95 #endif