#include <sys/stat.h>
#include <sys/mman.h>
-#include "libsysfs/sysfs/libsysfs.h"
#include "udev.h"
#include "logging.h"
#include "udev_lib.h"
return '\0';
}
+void udev_set_values(struct udevice *udev, const char* devpath, const char *subsystem)
+{
+ memset(udev, 0x00, sizeof(struct udevice));
+ strfieldcpy(udev->devpath, devpath);
+ strfieldcpy(udev->subsystem, subsystem);
+ udev->type = get_device_type(devpath, subsystem);
+}
+
+int create_path(const char *path)
+{
+ char p[NAME_SIZE];
+ char *pos;
+ struct stat stats;
+
+ strcpy (p, path);
+ pos = strrchr(p, '/');
+ if (pos == p || pos == NULL)
+ return 0;
+
+ while (pos[-1] == '/')
+ pos--;
+
+ pos[0] = '\0';
+
+ dbg("stat '%s'\n", p);
+ if (stat (p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR)
+ return 0;
+
+ if (create_path (p) != 0)
+ return -1;
+
+ dbg("mkdir '%s'\n", p);
+ return mkdir(p, 0755);
+}
+
int file_map(const char *filename, char **buf, size_t *bufsize)
{
struct stat stats;
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)
+void no_trailing_slash(char *path)
{
int len;
/* call function for every file in the list */
list_for_each_entry_safe(loop_file, tmp_file, &file_list, list) {
- strfieldcpy(file, dirname);
- strfieldcat(file, "/");
- strfieldcat(file, loop_file->name);
+ snprintf(file, NAME_SIZE-1, "%s/%s", dirname, loop_file->name);
+ file[NAME_SIZE-1] = '\0';
fnct(file);