fileio.c | fileio.c | |||
---|---|---|---|---|
skipping to change at line 61 | skipping to change at line 61 | |||
assert(fn); | assert(fn); | |||
assert(line); | assert(line); | |||
f = fopen(fn, "we"); | f = fopen(fn, "we"); | |||
if (!f) | if (!f) | |||
return -errno; | return -errno; | |||
return write_string_stream(f, line); | return write_string_stream(f, line); | |||
} | } | |||
int write_string_file_no_create(const char *fn, const char *line) { | ||||
_cleanup_fclose_ FILE *f = NULL; | ||||
int fd; | ||||
assert(fn); | ||||
assert(line); | ||||
/* We manually build our own version of fopen(..., "we") that | ||||
* without O_CREAT */ | ||||
fd = open(fn, O_WRONLY|O_CLOEXEC|O_NOCTTY); | ||||
if (fd < 0) | ||||
return -errno; | ||||
f = fdopen(fd, "we"); | ||||
if (!f) { | ||||
safe_close(fd); | ||||
return -errno; | ||||
} | ||||
return write_string_stream(f, line); | ||||
} | ||||
int write_string_file_atomic(const char *fn, const char *line) { | int write_string_file_atomic(const char *fn, const char *line) { | |||
_cleanup_fclose_ FILE *f = NULL; | _cleanup_fclose_ FILE *f = NULL; | |||
_cleanup_free_ char *p = NULL; | _cleanup_free_ char *p = NULL; | |||
int r; | int r; | |||
assert(fn); | assert(fn); | |||
assert(line); | assert(line); | |||
r = fopen_temporary(fn, &f, &p); | r = fopen_temporary(fn, &f, &p); | |||
if (r < 0) | if (r < 0) | |||
skipping to change at line 741 | skipping to change at line 763 | |||
if (!p) { | if (!p) { | |||
/* Fallback */ | /* Fallback */ | |||
fputs(v, f); | fputs(v, f); | |||
fputc('\n', f); | fputc('\n', f); | |||
return; | return; | |||
} | } | |||
p++; | p++; | |||
fwrite(v, 1, p-v, f); | fwrite(v, 1, p-v, f); | |||
if (string_has_cc(p) || chars_intersect(p, WHITESPACE "\'\"\\`$")) { | if (string_has_cc(p, NULL) || chars_intersect(p, WHITESPACE SHELL_N EED_QUOTES)) { | |||
fputc('\"', f); | fputc('\"', f); | |||
for (; *p; p++) { | for (; *p; p++) { | |||
if (strchr("\'\"\\`$", *p)) | if (strchr(SHELL_NEED_ESCAPE, *p)) | |||
fputc('\\', f); | fputc('\\', f); | |||
fputc(*p, f); | fputc(*p, f); | |||
} | } | |||
fputc('\"', f); | fputc('\"', f); | |||
} else | } else | |||
fputs(p, f); | fputs(p, f); | |||
fputc('\n', f); | fputc('\n', f); | |||
} | } | |||
int write_env_file(const char *fname, char **l) { | int write_env_file(const char *fname, char **l) { | |||
char **i; | ||||
_cleanup_free_ char *p = NULL; | ||||
_cleanup_fclose_ FILE *f = NULL; | _cleanup_fclose_ FILE *f = NULL; | |||
_cleanup_free_ char *p = NULL; | ||||
char **i; | ||||
int r; | int r; | |||
assert(fname); | ||||
r = fopen_temporary(fname, &f, &p); | r = fopen_temporary(fname, &f, &p); | |||
if (r < 0) | if (r < 0) | |||
return r; | return r; | |||
fchmod_umask(fileno(f), 0644); | fchmod_umask(fileno(f), 0644); | |||
errno = 0; | ||||
STRV_FOREACH(i, l) | STRV_FOREACH(i, l) | |||
write_env_var(f, *i); | write_env_var(f, *i); | |||
fflush(f); | r = fflush_and_check(f); | |||
if (r >= 0) { | ||||
if (rename(p, fname) >= 0) | ||||
return 0; | ||||
if (ferror(f)) | r = -errno; | |||
r = errno ? -errno : -EIO; | ||||
else { | ||||
if (rename(p, fname) < 0) | ||||
r = -errno; | ||||
else | ||||
r = 0; | ||||
} | } | |||
if (r < 0) | unlink(p); | |||
unlink(p); | ||||
return r; | return r; | |||
} | } | |||
int executable_is_script(const char *path, char **interpreter) { | int executable_is_script(const char *path, char **interpreter) { | |||
int r; | int r; | |||
_cleanup_free_ char *line = NULL; | _cleanup_free_ char *line = NULL; | |||
int len; | int len; | |||
char *ans; | char *ans; | |||
assert(path); | assert(path); | |||
End of changes. 10 change blocks. | ||||
16 lines changed or deleted | 34 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |