1 #include <fcntl.h> 2 #include <sys/types.h> 3 #include <sys/stat.h> 4 #include <sys/statvfs.h> 5 #include <stdlib.h> 6 #include <string.h> 7 #include <errno.h> 8 #include <stdio.h> 9 10 int main(int argc, char** argv) { 11 char temp[] = "/tmp/stattest-XXXXXX"; 12 const char file[] = "/mkfifo_fifo"; 13 int len = sizeof(temp) + sizeof(file); 14 char* path = malloc(len * sizeof(char)); 15 16 if (path == NULL) { 17 fprintf(stderr, "Could not allocate: %s\n", strerror(errno)); 18 exit(1); 19 } 20 21 path = strncat(path, mktemp(temp), sizeof(temp)); 22 path = strncat(path, file, sizeof(file)); 23 if (mkdir(temp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) { 24 fprintf(stderr, "mkdir %s: %s\n", temp, strerror(errno)); 25 exit(1); 26 } 27 if (mkfifo(path, S_IRUSR) == -1) { 28 fprintf(stderr, "mkfifo %s: %s\n", path, strerror(errno)); 29 exit(1); 30 } 31 struct stat sb; 32 if (stat(path, &sb) != 0) { 33 fprintf(stderr, "stat: %s\n", strerror(errno)); 34 exit(1); 35 } 36 if (!(sb.st_mode & S_IFIFO)) { 37 fprintf(stderr, "Not a FIFO: %d\n", sb.st_mode); 38 exit(1); 39 } 40 } 41