1/* File identity for the dynamic linker. Generic POSIX.1 version.
2 Copyright (C) 2015-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <stdbool.h>
20#include <sys/stat.h>
21
22/* For POSIX.1 systems, the pair of st_dev and st_ino constitute
23 a unique identifier for a file. */
24struct r_file_id
25 {
26 dev_t dev;
27 ino64_t ino;
28 };
29
30/* Sample FD to fill in *ID. Returns true on success.
31 On error, returns false, with errno set. */
32static inline bool
33_dl_get_file_id (int fd, struct r_file_id *id)
34{
35 struct __stat64_t64 st;
36
37 if (__glibc_unlikely (__fstat64_time64 (fd, &st) < 0))
38 return false;
39
40 id->dev = st.st_dev;
41 id->ino = st.st_ino;
42 return true;
43}
44
45/* Compare two results from _dl_get_file_id for equality. */
46static inline bool
47_dl_file_id_match_p (const struct r_file_id *a, const struct r_file_id *b)
48{
49 return a->dev == b->dev && a->ino == b->ino;
50}
51

source code of glibc/sysdeps/posix/dl-fileid.h