Hi Ramsis94.
You can just use status, but pass it's address like &status.
Code:
#define _DEFAULT_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
void serious_error(char *msg) {
perror(msg);
exit(EXIT_FAILURE);
}
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: get_stats FILENAME\n");
return EXIT_FAILURE;
}
struct stat status;
if (stat(argv[1], &status) < 0)
serious_error("stat");
struct passwd *pass = getpwuid(status.st_uid);
const char *type = "other";
if (S_ISREG(status.st_mode))
type = "regular";
else if (S_ISDIR(status.st_mode))
type = "dir";
else if (S_ISLNK(status.st_mode))
type = "symlink";
printf("File: %s type: %s mode: %o size: %ld owner: %s (%d)\n",
argv[1], type, (unsigned)(0777 & status.st_mode), (long)status.st_size,
pass->pw_name, status.st_uid);
return 0;
}