blob: b9fe47fbab4c66a0f560e29836e9fc2f78cfd301 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
const char *modestr(int mode)
{
switch (mode)
{
case S_IFCHR:
return "Character device";
case S_IFBLK:
return "Block device";
case S_IFDIR:
return "Directory";
case S_IFREG:
return "Regular file";
case S_IFLNK:
return "Symbolic link";
default:
return "Unknown";
}
}
int main(int argc, char **argv)
{
if (argc != 2)
{
printf("usage: stat file\n");
return 1;
}
stat_t ss;
int rc = stat(argv[1], &ss);
if (rc == -1)
{
printf("stat: %s\n", strerror(errno));
return 1;
}
printf(" File: %s\n", argv[1]);
printf(" Type: %s\n", modestr(ss.st_mode));
printf(" Inode: %d\n", ss.st_ino);
printf("Link count: %d\n", ss.st_nlink);
printf(" Size: %d\n", ss.st_size);
printf(" Blocks: %d\n", ss.st_blocks);
return 0;
}
|