stat: Show username of file owner
This commit is contained in:
parent
5aba1c5f15
commit
91470851cd
@ -1,3 +1,4 @@
|
|||||||
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -45,11 +46,16 @@ int main(int argc, char** argv)
|
|||||||
default: puts("Unknown"); break;
|
default: puts("Unknown"); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct passwd* own = getpwuid(st.st_uid);
|
||||||
|
|
||||||
printf("Length: %ld\n", st.st_size);
|
printf("Length: %ld\n", st.st_size);
|
||||||
printf("Inode: %ld\n", st.st_ino);
|
printf("Inode: %ld\n", st.st_ino);
|
||||||
printf("UID: %d\n", st.st_uid);
|
if (!own) printf("Owned by: UID %d\n", st.st_uid);
|
||||||
printf("GID: %d\n", st.st_gid);
|
else
|
||||||
|
printf("Owned by: %s\n", own->pw_name);
|
||||||
printf("Mode: %s\n", mode_to_string(st.st_mode));
|
printf("Mode: %s\n", mode_to_string(st.st_mode));
|
||||||
|
|
||||||
|
endpwent();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user