sort: better -Wmissing-variable-declarations
[coreutils.git] / src / statx.h
blob7c29597e1e521ee201aae3e245c427f1a801ce6c
1 /* statx -> stat conversion functions for coreutils
2 Copyright (C) 2019-2024 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 3 of the License, or
7 (at your option) any later version.
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, see <https://www.gnu.org/licenses/>. */
17 #ifndef COREUTILS_STATX_H
18 # define COREUTILS_STATX_H
20 # if HAVE_STATX && defined STATX_INO
21 /* Much of the format printing requires a struct stat or timespec */
22 static inline struct timespec
23 statx_timestamp_to_timespec (struct statx_timestamp tsx)
25 struct timespec ts;
27 ts.tv_sec = tsx.tv_sec;
28 ts.tv_nsec = tsx.tv_nsec;
29 return ts;
32 static inline void
33 statx_to_stat (struct statx *stx, struct stat *stat)
35 stat->st_dev = makedev (stx->stx_dev_major, stx->stx_dev_minor);
36 stat->st_ino = stx->stx_ino;
37 stat->st_mode = stx->stx_mode;
38 stat->st_nlink = stx->stx_nlink;
39 stat->st_uid = stx->stx_uid;
40 stat->st_gid = stx->stx_gid;
41 stat->st_rdev = makedev (stx->stx_rdev_major, stx->stx_rdev_minor);
42 stat->st_size = stx->stx_size;
43 stat->st_blksize = stx->stx_blksize;
44 /* define to avoid sc_prohibit_stat_st_blocks. */
45 # define SC_ST_BLOCKS st_blocks
46 stat->SC_ST_BLOCKS = stx->stx_blocks;
47 stat->st_atim = statx_timestamp_to_timespec (stx->stx_atime);
48 stat->st_mtim = statx_timestamp_to_timespec (stx->stx_mtime);
49 stat->st_ctim = statx_timestamp_to_timespec (stx->stx_ctime);
51 # endif /* HAVE_STATX && defined STATX_INO */
52 #endif /* COREUTILS_STATX_H */