static void write_env_var(FILE *f, const char *v) { const char *p; p = strchr(v, '='); if (!p) { /* Fallback */ fputs(v, f); fputc('\n', f); return; } p++; fwrite(v, 1, p-v, f); if (string_has_cc(p) || chars_intersect(p, WHITESPACE "\'\"\\`$")) { fputc('\"', f); for (; *p; p++) { if (strchr("\'\"\\`$", *p)) fputc('\\', f); fputc(*p, f); } fputc('\"', f); } else fputs(p, f); fputc('\n', f); }
static void write_env_var(FILE *f, const char *v) { const char *p; p = strchr(v, '='); if (!p) { /* Fallback */ fputs_unlocked(v, f); fputc_unlocked('\n', f); return; } p++; fwrite_unlocked(v, 1, p-v, f); if (string_has_cc(p, NULL) || chars_intersect(p, WHITESPACE SHELL_NEED_QUOTES)) { fputc_unlocked('\"', f); for (; *p; p++) { if (strchr(SHELL_NEED_ESCAPE, *p)) fputc_unlocked('\\', f); fputc_unlocked(*p, f); } fputc_unlocked('\"', f); } else fputs_unlocked(p, f); fputc_unlocked('\n', f); }