1 /* Determine whether two file names refer to the same file.
2 Copyright (C) 1997-2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* written by Jim Meyering */
31 #include <sys/types.h>
52 # define _(Text) gettext (Text)
57 #define STREQ(a, b) (strcmp ((a), (b)) == 0)
59 #ifndef HAVE_DECL_FREE
60 "this configure-time declaration test was not run"
66 char *base_name
PARAMS ((char const *));
68 #define SAME_INODE(Stat_buf_1, Stat_buf_2) \
69 ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
70 && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
72 /* Return nonzero if SOURCE and DEST point to the same name in the same
76 same_name (const char *source
, const char *dest
)
78 struct stat source_dir_stats
;
79 struct stat dest_dir_stats
;
80 char *source_dirname
, *dest_dirname
;
82 source_dirname
= dir_name (source
);
83 dest_dirname
= dir_name (dest
);
84 if (source_dirname
== NULL
|| dest_dirname
== NULL
)
87 if (stat (source_dirname
, &source_dir_stats
))
89 /* Shouldn't happen. */
90 error (1, errno
, "%s", source_dirname
);
93 if (stat (dest_dirname
, &dest_dir_stats
))
95 /* Shouldn't happen. */
96 error (1, errno
, "%s", dest_dirname
);
99 free (source_dirname
);
102 return (SAME_INODE (source_dir_stats
, dest_dir_stats
)
103 && STREQ (base_name (source
), base_name (dest
)));