return devpath;
}
-char *get_devnode(void)
+char *get_devname(void)
{
- char *devnode;
+ char *devname;
- devnode = getenv("DEVNODE");
- if (devnode != NULL && strlen(devnode) > NAME_SIZE)
- devnode[NAME_SIZE-1] = '\0';
+ devname = getenv("DEVNAME");
+ if (devname != NULL && strlen(devname) > NAME_SIZE)
+ devname[NAME_SIZE-1] = '\0';
- return devnode;
+ return devname;
}
char *get_seqnum(void)
return subsystem;
}
+#define BLOCK_PATH "/block/"
+#define CLASS_PATH "/class/"
+#define NET_PATH "/class/net/"
+
char get_device_type(const char *path, const char *subsystem)
{
- if (strcmp(subsystem, "block") == 0 ||
- strstr(path, "/block/") != NULL)
+ if (strcmp(subsystem, "block") == 0)
return 'b';
- if (strcmp(subsystem, "net") == 0 ||
- strstr(path, "/class/net/") != NULL)
+ if (strcmp(subsystem, "net") == 0)
return 'n';
- if (strstr(path, "/class/") != NULL)
+ if (strncmp(path, BLOCK_PATH, strlen(BLOCK_PATH)) == 0 &&
+ strlen(path) > strlen(BLOCK_PATH))
+ return 'b';
+
+ if (strncmp(path, NET_PATH, strlen(NET_PATH)) == 0 &&
+ strlen(path) > strlen(NET_PATH))
+ return 'n';
+
+ if (strncmp(path, CLASS_PATH, strlen(CLASS_PATH)) == 0 &&
+ strlen(path) > strlen(CLASS_PATH))
return 'c';
return '\0';
}
if (fstat(fd, &stats) < 0) {
+ close(fd);
return -1;
}
*buf = mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (*buf == MAP_FAILED) {
+ close(fd);
return -1;
}
*bufsize = stats.st_size;
return count - cur;
}
+void leading_slash(char *path)
+{
+ int len;
+
+ len = strlen(path);
+ if (len > 0 && path[len-1] != '/') {
+ path[len] = '/';
+ path[len+1] = '\0';
+ }
+}
+
+void no_leading_slash(char *path)
+{
+ int len;
+
+ len = strlen(path);
+ if (len > 0 && path[len-1] == '/')
+ path[len-1] = '\0';
+}
+
struct files {
struct list_head list;
char name[NAME_SIZE];
return 0;
}
-/* calls function for file or every file found in directory */
+/* calls function for every file found in specified directory */
int call_foreach_file(int fnct(char *f) , char *dirname, char *suffix)
{
struct dirent *ent;