summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--color.c13
-rw-r--r--color.h2
2 files changed, 11 insertions, 4 deletions
diff --git a/color.c b/color.c
index d89be4f..f32d5a3 100644
--- a/color.c
+++ b/color.c
@@ -49,9 +49,11 @@ struct color_table {
const char *exec;
struct ext_color *ext_list;
+
+ char *data;
};
-struct color_table *parse_colors(char *ls_colors) {
+struct color_table *parse_colors(const char *ls_colors) {
struct color_table *colors = malloc(sizeof(struct color_table));
if (!colors) {
goto done;
@@ -79,11 +81,15 @@ struct color_table *parse_colors(char *ls_colors) {
colors->exec = "01;32";
colors->ext_list = NULL;
- if (!ls_colors) {
+ if (ls_colors) {
+ colors->data = strdup(ls_colors);
+ }
+
+ if (!colors->data) {
goto done;
}
- char *start = ls_colors;
+ char *start = colors->data;
char *end;
struct ext_color *ext;
for (end = strchr(start, ':'); *start && end; start = end + 1, end = strchr(start, ':')) {
@@ -333,6 +339,7 @@ void free_colors(struct color_table *colors) {
free(saved);
}
+ free(colors->data);
free(colors);
}
}
diff --git a/color.h b/color.h
index d022d34..61b71c0 100644
--- a/color.h
+++ b/color.h
@@ -26,7 +26,7 @@ struct color_table;
* A color table in the LS_COLORS environment variable format.
* @return The parsed color table.
*/
-struct color_table *parse_colors(char *ls_colors);
+struct color_table *parse_colors(const char *ls_colors);
/**
* Pretty-print a file path.