aboutsummaryrefslogtreecommitdiff
path: root/modules/devices
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2017-07-19 15:50:03 -0500
committerLeandro A. F. Pereira <leandro@hardinfo.org>2017-07-21 05:14:20 -0700
commit8bc918eaf6d8a2f3aea56b7a23662ffaece9c87b (patch)
tree8e3cba89960a2f4cc8c7c1fd27007c96f3abd01e /modules/devices
parent09a97340826d926f9949f4aa1a99c4f6848c10ac (diff)
device tree: dtr_obj_read() tweaks, bug fix
* fixes a strange bug when running under Arch Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules/devices')
-rw-r--r--modules/devices/devicetree/dt_util.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/modules/devices/devicetree/dt_util.c b/modules/devices/devicetree/dt_util.c
index 3440c3a1..0bbf26a0 100644
--- a/modules/devices/devicetree/dt_util.c
+++ b/modules/devices/devicetree/dt_util.c
@@ -246,43 +246,41 @@ dtr_obj *dtr_obj_read(dtr *s, const char *dtp) {
obj = malloc(sizeof(dtr_obj));
if (obj != NULL) {
memset(obj, 0, sizeof(dtr_obj));
+
obj->dt = s;
if (*dtp != '/') {
+ /* doesn't start with slash, use alias */
obj->path = (char*)dtr_alias_lookup(s, dtp);
if (obj->path != NULL)
obj->path = strdup(obj->path);
else {
- // obj->path = strdup( (dtp != NULL && strcmp(dtp, "")) ? dtp : "/" );
dtr_obj_free(obj);
return NULL;
}
} else
obj->path = strdup(dtp);
- full_path = g_strdup_printf("%s%s", s->base_path, obj->path);
+ /* find name after last slash, or start */
+ slash = strrchr(obj->path, '/');
+ if (slash != NULL)
+ obj->name = strdup(slash + 1);
+ else
+ obj->name = strdup(obj->path);
+ /* read data */
+ full_path = g_strdup_printf("%s%s", s->base_path, obj->path);
if ( g_file_test(full_path, G_FILE_TEST_IS_DIR) ) {
obj->type = DT_NODE;
} else {
- obj->type = DTP_UNK;
if (!g_file_get_contents(full_path, (gchar**)&obj->data, (gsize*)&obj->length, NULL)) {
dtr_obj_free(obj);
g_free(full_path);
return NULL;
}
+ obj->type = dtr_guess_type(obj);
}
g_free(full_path);
- /* find name after last slash, or start */
- slash = strrchr(obj->path, '/');
- if (slash != NULL)
- obj->name = strdup(slash + 1);
- else
- obj->name = strdup(obj->path);
-
- if (obj->type == DTP_UNK)
- obj->type = dtr_guess_type(obj);
-
return obj;
}
return NULL;