Created
March 7, 2015 00:04
-
-
Save alexpreynolds/11c2cd7eb77ad204a48c to your computer and use it in GitHub Desktop.
Test input file's POSIX type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/stat.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
int main(int argc, char **argv) | |
{ | |
struct stat st; | |
if (stat(argv[1], &st) == -1) { | |
fprintf(stderr, "Error: stat() failed\n"); | |
return EXIT_FAILURE; | |
} | |
switch (st.st_mode & S_IFMT) | |
{ | |
case S_IFBLK: fprintf(stdout, "block device\n"); break; | |
case S_IFCHR: fprintf(stdout, "character device\n"); break; | |
case S_IFDIR: fprintf(stdout, "directory\n"); break; | |
case S_IFIFO: fprintf(stdout, "FIFO/pipe\n"); break; | |
case S_IFLNK: fprintf(stdout, "symlink\n"); break; | |
case S_IFREG: fprintf(stdout, "regular file\n"); break; | |
case S_IFSOCK: fprintf(stdout, "socket\n"); break; | |
default: fprintf(stdout, "unknown?\n"); break; | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiles with
gcc -Wall type_test.c -o type_test
Sample run: