From 8bc918eaf6d8a2f3aea56b7a23662ffaece9c87b Mon Sep 17 00:00:00 2001 From: Burt P Date: Wed, 19 Jul 2017 15:50:03 -0500 Subject: device tree: dtr_obj_read() tweaks, bug fix * fixes a strange bug when running under Arch Signed-off-by: Burt P --- modules/devices/devicetree/dt_util.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'modules') 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; -- cgit v1.2.3