#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

int main(int argc, char **argv) {
    char *path;
    struct stat statbuf;

    if (argc < 2) {
        fprintf(stderr, "USAGE: %s path\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    path = argv[1];

    if (-1 == stat(path, &statbuf)) {
        perror("stat");
        exit(EXIT_FAILURE);
    }

    printf("File size: %jd\n", statbuf.st_size);
    printf("Hard links: %jd\n", statbuf.st_nlink);
    switch (statbuf.st_mode & S_IFMT) {
        case S_IFSOCK:  printf("S_IFSOCK\n");   break; 
        case S_IFLNK:   printf("S_IFLNK\n");    break;
        case S_IFREG:   printf("S_IFREG\n");    break;
        case S_IFBLK:   printf("S_IFBLK\n");    break;
        case S_IFDIR:   printf("S_IFDIR\n");    break;
        case S_IFCHR:   printf("S_IFCHR\n");    break;
        case S_IFIFO:   printf("S_IFIFO\n");    break;
        default: printf("unknown file type\n");
    }

    return EXIT_SUCCESS;
}
