statx the file and print what we find */
| 1363 | |
| 1364 | /* statx the file and print what we find */ |
| 1365 | NODISCARD |
| 1366 | static bool |
| 1367 | do_stat (char const *filename, char const *format, char const *format2) |
| 1368 | { |
| 1369 | int fd = streq (filename, "-") ? 0 : AT_FDCWD; |
| 1370 | int flags = 0; |
| 1371 | struct stat st; |
| 1372 | struct statx stx = {0}; |
| 1373 | char const *pathname = filename; |
| 1374 | struct print_args pa; |
| 1375 | pa.st = &st; |
| 1376 | pa.btime = (struct timespec) {.tv_sec = -1, .tv_nsec = -1}; |
| 1377 | |
| 1378 | if (AT_FDCWD != fd) |
| 1379 | { |
| 1380 | pathname = ""; |
| 1381 | flags = AT_EMPTY_PATH; |
| 1382 | } |
| 1383 | else if (!follow_links) |
| 1384 | { |
| 1385 | flags = AT_SYMLINK_NOFOLLOW; |
| 1386 | } |
| 1387 | |
| 1388 | if (dont_sync) |
| 1389 | flags |= AT_STATX_DONT_SYNC; |
| 1390 | else if (force_sync) |
| 1391 | flags |= AT_STATX_FORCE_SYNC; |
| 1392 | |
| 1393 | if (! force_sync) |
| 1394 | flags |= AT_NO_AUTOMOUNT; |
| 1395 | |
| 1396 | fd = statx (fd, pathname, flags, format_to_mask (format), &stx); |
| 1397 | if (fd < 0) |
| 1398 | { |
| 1399 | if (flags & AT_EMPTY_PATH) |
| 1400 | error (0, errno, _("cannot stat standard input")); |
| 1401 | else |
| 1402 | error (0, errno, _("cannot statx %s"), quoteaf (filename)); |
| 1403 | return false; |
| 1404 | } |
| 1405 | |
| 1406 | if (S_ISBLK (stx.stx_mode) || S_ISCHR (stx.stx_mode)) |
| 1407 | format = format2; |
| 1408 | |
| 1409 | statx_to_stat (&stx, &st); |
| 1410 | if (stx.stx_mask & STATX_BTIME) |
| 1411 | pa.btime = statx_timestamp_to_timespec (stx.stx_btime); |
| 1412 | |
| 1413 | bool fail = print_it (format, fd, filename, print_stat, &pa); |
| 1414 | return ! fail; |
| 1415 | } |
| 1416 | |
| 1417 | #else /* USE_STATX */ |
| 1418 |
no test coverage detected