diff --git a/main.c b/main.c index 1459369..4c745c2 100644 --- a/main.c +++ b/main.c @@ -946,6 +946,7 @@ static struct ovl_layer * read_dirs (char *path, bool low, struct ovl_layer *layers) { char *buf = NULL, *saveptr = NULL, *it; + struct ovl_layer *last; if (path == NULL) return NULL; @@ -954,6 +955,10 @@ read_dirs (char *path, bool low, struct ovl_layer *layers) if (buf == NULL) return NULL; + last = layers; + while (last && last->next) + last = last->next; + for (it = strtok_r (path, ":", &saveptr); it; it = strtok_r (NULL, ":", &saveptr)) { char full_path[PATH_MAX + 1]; @@ -987,8 +992,24 @@ read_dirs (char *path, bool low, struct ovl_layer *layers) } l->low = low; - l->next = layers; - layers = l; + if (low) + { + if (last == NULL) + { + last = layers = l; + l->next = NULL; + } + else + { + last->next = l; + last = l; + } + } + else + { + l->next = layers; + layers = l; + } } free (buf); return layers;