Filling a struct stat, and checking that you did
Filling a struct stat, and checking that you did
Answer
struct stat sb; if (stat(path, &sb) == -1) { perror("stat"); return 1; } printf("size %lld bytes, %llu links\n", (long long)sb.st_size, (unsigned long long)sb.st_nlink);
stat returns 0 or -1, never the data — the structure is filled through the pointer you pass. The casts exist because off_t and nlink_t have no portable printf conversion.
S&K 3e ch18 §18.9; stat/lstat/fstat signatures and <sys/stat.h> macros per POSIX.1-2024