xref: /dflybsd-src/contrib/grep/lib/same-inode.h (revision 91b9ed38d3db6a8a8ac5b66da1d43e6e331e259a)
1*09d4459fSDaniel Fojt /* Determine whether two stat buffers are known to refer to the same file.
2cf28ed85SJohn Marino 
3*09d4459fSDaniel Fojt    Copyright (C) 2006, 2009-2020 Free Software Foundation, Inc.
4cf28ed85SJohn Marino 
5cf28ed85SJohn Marino    This program is free software: you can redistribute it and/or modify
6cf28ed85SJohn Marino    it under the terms of the GNU General Public License as published by
7cf28ed85SJohn Marino    the Free Software Foundation; either version 3 of the License, or
8cf28ed85SJohn Marino    (at your option) any later version.
9cf28ed85SJohn Marino 
10cf28ed85SJohn Marino    This program is distributed in the hope that it will be useful,
11cf28ed85SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
12cf28ed85SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13cf28ed85SJohn Marino    GNU General Public License for more details.
14cf28ed85SJohn Marino 
15cf28ed85SJohn Marino    You should have received a copy of the GNU General Public License
16*09d4459fSDaniel Fojt    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
17cf28ed85SJohn Marino 
18cf28ed85SJohn Marino #ifndef SAME_INODE_H
19cf28ed85SJohn Marino # define SAME_INODE_H 1
20cf28ed85SJohn Marino 
21*09d4459fSDaniel Fojt # include <sys/types.h>
22*09d4459fSDaniel Fojt 
23*09d4459fSDaniel Fojt # if defined __VMS && __CRTL_VER < 80200000
24cf28ed85SJohn Marino #  define SAME_INODE(a, b)             \
25cf28ed85SJohn Marino     ((a).st_ino[0] == (b).st_ino[0]    \
26cf28ed85SJohn Marino      && (a).st_ino[1] == (b).st_ino[1] \
27cf28ed85SJohn Marino      && (a).st_ino[2] == (b).st_ino[2] \
28cf28ed85SJohn Marino      && (a).st_dev == (b).st_dev)
29*09d4459fSDaniel Fojt # elif defined _WIN32 && ! defined __CYGWIN__
30*09d4459fSDaniel Fojt    /* Native Windows.  */
31*09d4459fSDaniel Fojt #  if _GL_WINDOWS_STAT_INODES
32*09d4459fSDaniel Fojt     /* stat() and fstat() set st_dev and st_ino to 0 if information about
33*09d4459fSDaniel Fojt        the inode is not available.  */
34*09d4459fSDaniel Fojt #   define SAME_INODE(a, b) \
35*09d4459fSDaniel Fojt      (!((a).st_ino == 0 && (a).st_dev == 0) \
36*09d4459fSDaniel Fojt       && (a).st_ino == (b).st_ino && (a).st_dev == (b).st_dev)
37*09d4459fSDaniel Fojt #  else
38*09d4459fSDaniel Fojt     /* stat() and fstat() set st_ino to 0 always.  */
39*09d4459fSDaniel Fojt #   define SAME_INODE(a, b) 0
40*09d4459fSDaniel Fojt #  endif
41cf28ed85SJohn Marino # else
42cf28ed85SJohn Marino #  define SAME_INODE(a, b)    \
43cf28ed85SJohn Marino     ((a).st_ino == (b).st_ino \
44cf28ed85SJohn Marino      && (a).st_dev == (b).st_dev)
45cf28ed85SJohn Marino # endif
46cf28ed85SJohn Marino 
47cf28ed85SJohn Marino #endif
48