diff options
Diffstat (limited to 'src/env-update.c')
-rw-r--r-- | src/env-update.c | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/src/env-update.c b/src/env-update.c index e01c8c48..1df55386 100644 --- a/src/env-update.c +++ b/src/env-update.c @@ -25,12 +25,12 @@ #define CSH_ENV "/etc/csh.env" #define LDSOCONF "/etc/ld.so.conf" -#define NOTICE "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n" \ - "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n" \ - "# GO INTO %s NOT %s\n\n" +#define NOTICE "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n" \ + "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n" \ +"# GO INTO %s NOT %s\n\n" -#define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \ - "# changes to contents of /etc/env.d directory\n" +#define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \ + "# changes to contents of /etc/env.d directory\n" static const char *specials[] = { @@ -85,78 +85,78 @@ int main (int argc, char **argv) int j; if (! rc_is_dir (path)) - entries = rc_get_config (NULL, path); + entries = rc_get_config (NULL, path); free (path); STRLIST_FOREACH (entries, entry, j) - { - char *tmpent = rc_xstrdup (entry); - char *value = tmpent; - char *var = strsep (&value, "="); - int k; - bool isspecial = false; - bool isspecial_spaced = false; - bool replaced = false; - - for (k = 0; special_spaces[k]; k++) - if (strcmp (special_spaces[k], var) == 0) - { - isspecial = true; - isspecial_spaced = true; - break; - } - - if (! isspecial) - { - for (k = 0; specials[k]; k++) - if (strcmp (specials[k], var) == 0) - { - isspecial = true; - break; - } - } - - /* Skip blank vars */ - if (isspecial && - (! value || strlen (value)) == 0) - { - free (tmpent); - continue; - } - - STRLIST_FOREACH (envs, env, k) - { - char *tmpenv = rc_xstrdup (env); - char *tmpvalue = tmpenv; - char *tmpentry = strsep (&tmpvalue, "="); - - if (strcmp (tmpentry, var) == 0) - { - if (isspecial) - { - int len = strlen (envs[k - 1]) + strlen (entry) + 1; - envs[k - 1] = rc_xrealloc (envs[k - 1], len); - snprintf (envs[k - 1] + strlen (envs[k - 1]), len, - "%s%s", isspecial_spaced ? " " : ":", value); - } - else - { - free (envs[k - 1]); - envs[k - 1] = strdup (entry); - } - replaced = true; - } - free (tmpenv); - - if (replaced) - break; - } - - if (! replaced) - envs = rc_strlist_addsort (envs, entry); - - free (tmpent); - } + { + char *tmpent = rc_xstrdup (entry); + char *value = tmpent; + char *var = strsep (&value, "="); + int k; + bool isspecial = false; + bool isspecial_spaced = false; + bool replaced = false; + + for (k = 0; special_spaces[k]; k++) + if (strcmp (special_spaces[k], var) == 0) + { + isspecial = true; + isspecial_spaced = true; + break; + } + + if (! isspecial) + { + for (k = 0; specials[k]; k++) + if (strcmp (specials[k], var) == 0) + { + isspecial = true; + break; + } + } + + /* Skip blank vars */ + if (isspecial && + (! value || strlen (value)) == 0) + { + free (tmpent); + continue; + } + + STRLIST_FOREACH (envs, env, k) + { + char *tmpenv = rc_xstrdup (env); + char *tmpvalue = tmpenv; + char *tmpentry = strsep (&tmpvalue, "="); + + if (strcmp (tmpentry, var) == 0) + { + if (isspecial) + { + int len = strlen (envs[k - 1]) + strlen (entry) + 1; + envs[k - 1] = rc_xrealloc (envs[k - 1], len); + snprintf (envs[k - 1] + strlen (envs[k - 1]), len, + "%s%s", isspecial_spaced ? " " : ":", value); + } + else + { + free (envs[k - 1]); + envs[k - 1] = strdup (entry); + } + replaced = true; + } + free (tmpenv); + + if (replaced) + break; + } + + if (! replaced) + envs = rc_strlist_addsort (envs, entry); + + free (tmpent); + } } if ((fp = fopen (PROFILE_ENV, "w")) == NULL) @@ -168,7 +168,7 @@ int main (int argc, char **argv) char *value = tmpent; char *var = strsep (&value, "="); if (strcmp (var, "LDPATH") != 0) - fprintf (fp, "export %s='%s'\n", var, value); + fprintf (fp, "export %s='%s'\n", var, value); free (tmpent); } fclose (fp); @@ -182,24 +182,24 @@ int main (int argc, char **argv) char *value = tmpent; char *var = strsep (&value, "="); if (strcmp (var, "LDPATH") != 0) - fprintf (fp, "setenv %s '%s'\n", var, value); + fprintf (fp, "setenv %s '%s'\n", var, value); free (tmpent); } fclose (fp); ldent = rc_get_config_entry (envs, "LDPATH"); - if (! ldent || - (argc > 1 && argv[1] && strcmp (argv[1], "--no-ldconfig") == 0)) - { - free (envs); - return (EXIT_SUCCESS); - } + if (! ldent || + (argc > 1 && argv[1] && strcmp (argv[1], "--no-ldconfig") == 0)) + { + free (envs); + return (EXIT_SUCCESS); + } while ((file = strsep (&ldent, ":"))) { if (strlen (file) == 0) - continue; + continue; ldents = rc_strlist_add (ldents, file); nents++; @@ -213,12 +213,12 @@ int main (int argc, char **argv) ld = false; STRLIST_FOREACH (lines, line, i) if (i > nents || strcmp (line, ldents[i - 1]) != 0) - { - ld = true; - break; - } + { + ld = true; + break; + } if (i - 1 != nents) - ld = true; + ld = true; } if (ld) @@ -226,7 +226,7 @@ int main (int argc, char **argv) int retval = 0; if ((fp = fopen (LDSOCONF, "w")) == NULL) - eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF, strerror (errno)); + eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF, strerror (errno)); fprintf (fp, LDNOTICE); STRLIST_FOREACH (ldents, ldent, i) fprintf (fp, "%s\n", ldent); |