aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/kiss-stat.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/bin/kiss-stat.c b/bin/kiss-stat.c
index 5d62855..8692904 100644
--- a/bin/kiss-stat.c
+++ b/bin/kiss-stat.c
@@ -14,19 +14,24 @@
int main (int argc, char *argv[]) {
struct stat sb;
- // Exit if no or multiple arguments are given
+ // Exit if no or multiple arguments are given.
if (argc != 2 || strcmp(argv[1], "--help") == 0) {
fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
return(1);
}
- // Exit if file stat cannot be obtained
+ // Exit if file stat cannot be obtained.
if (lstat(argv[1], &sb) == -1) {
perror(argv[0]);
return(1);
}
- // Print the user name of file owner
+ // Exit if name of the owner cannot be retrieved.
+ if (!getpwuid(sb.st_uid)) {
+ return(1);
+ }
+
+ // Print the user name of file owner.
struct passwd *pw = getpwuid(sb.st_uid);
printf("%s\n", pw->pw_name);
return(0);