summaryrefslogtreecommitdiffstats
path: root/color.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-02-14 13:44:16 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-02-14 13:44:16 -0500
commitc40f26a15c0dce60ee365ee3f6d0779ef19cd947 (patch)
treea2d993f8cac9245c617da01a7f7fdb5b7ea47ffb /color.c
parent585a9dafe86b51a2d120d107bb04a77b34cc1af0 (diff)
downloadbfs-c40f26a15c0dce60ee365ee3f6d0779ef19cd947.tar.xz
Don't modify the result of getenv().
Diffstat (limited to 'color.c')
-rw-r--r--color.c13
1 files changed, 10 insertions, 3 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);
}
}