diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/devices/devicetree/dt_util.c | 24 | 
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; | 
