32 char new_device[1024] =
"/dev/";
34 strcat(new_device, device_name);
35 ret = (access(device_name, F_OK) == 0) || (access(new_device, F_OK) == 0);
45 FILE *in_file = fopen(
"/proc/devices",
"r");
48 stat(
"/proc/devices", &sb);
50 char file_contents[1024] =
"";
52 while (fscanf(in_file,
"%[^\n] ", file_contents) != EOF) {
55 int correct_format = sscanf(file_contents,
"%d %s", &major, name);
56 int compare = strcmp(name, device);
58 if (correct_format == 2 && compare == 0)
71 int32_t
get_param(
const char* filename,
const char* parameter)
74 FILE *in_file = fopen(filename,
"r");
79 char file_contents[1024] =
"";
81 sprintf(name,
"%s: %%d", parameter);
83 while (fscanf(in_file,
"%[^\n] ", file_contents) != EOF) {
84 int correct_format = sscanf(file_contents, name, &ret);
86 if (correct_format == 1)
uint8_t device_exists(const char *device_name)
Does a device file exist?
int32_t get_major(const char *device)
Gets the device major id from /proc/devices.
int32_t get_param(const char *filename, const char *parameter)
Gets a parameter from a driver param file.