Skip to content

Instantly share code, notes, and snippets.

@ajithbh
Last active January 1, 2016 13:49
Show Gist options
  • Save ajithbh/8154165 to your computer and use it in GitHub Desktop.
Save ajithbh/8154165 to your computer and use it in GitHub Desktop.
Has Device in C
#include <sys/stat.h>
// 0: No Such Device, 1: Found Device
int has_device(char *path)
{
struct stat buf;
if (stat(path, &buf) < 0) {
return 0;
}
printf("dev = %d/%d", major(buf.st_dev), minor(buf.st_dev));
if (S_ISCHR(buf.st_mode) || S_ISBLK(buf.st_mode)) {
printf("(%s) rdev = %d/%d", (S_ISCHR(buf.st_mode)) ? "char" : "block", major(buf.st_rdev), minor(buf.st_rdev));
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment