MCPcopy Create free account
hub / github.com/coreutils/coreutils / do_stat

Function do_stat

src/stat.c:1365–1415  ·  view source on GitHub ↗

statx the file and print what we find */

Source from the content-addressed store, hash-verified

1363
1364/* statx the file and print what we find */
1365NODISCARD
1366static bool
1367do_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

Callers 1

mainFunction · 0.70

Calls 6

format_to_maskFunction · 0.85
statx_to_statFunction · 0.85
print_itFunction · 0.85
statxClass · 0.70
statClass · 0.70

Tested by

no test coverage detected