Merge pull request #17567 from keszybz/various-small-cleanups
Various small cleanups
This commit is contained in:
@@ -747,3 +747,15 @@ int getenv_bool_secure(const char *p) {
|
||||
|
||||
return parse_boolean(e);
|
||||
}
|
||||
|
||||
int set_unset_env(const char *name, const char *value, bool overwrite) {
|
||||
int r;
|
||||
|
||||
if (value)
|
||||
r = setenv(name, value, overwrite);
|
||||
else
|
||||
r = unsetenv(name);
|
||||
if (r < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -52,3 +52,6 @@ char *strv_env_get(char **x, const char *n) _pure_;
|
||||
|
||||
int getenv_bool(const char *p);
|
||||
int getenv_bool_secure(const char *p);
|
||||
|
||||
/* Like setenv, but calls unsetenv if value == NULL. */
|
||||
int set_unset_env(const char *name, const char *value, bool overwrite);
|
||||
|
||||
+4
-4
@@ -117,7 +117,7 @@ int write_string_stream_ts(
|
||||
FILE *f,
|
||||
const char *line,
|
||||
WriteStringFileFlags flags,
|
||||
struct timespec *ts) {
|
||||
const struct timespec *ts) {
|
||||
|
||||
bool needs_nl;
|
||||
int r, fd;
|
||||
@@ -161,7 +161,7 @@ int write_string_stream_ts(
|
||||
return r;
|
||||
|
||||
if (ts) {
|
||||
struct timespec twice[2] = {*ts, *ts};
|
||||
const struct timespec twice[2] = {*ts, *ts};
|
||||
|
||||
if (futimens(fd, twice) < 0)
|
||||
return -errno;
|
||||
@@ -174,7 +174,7 @@ static int write_string_file_atomic(
|
||||
const char *fn,
|
||||
const char *line,
|
||||
WriteStringFileFlags flags,
|
||||
struct timespec *ts) {
|
||||
const struct timespec *ts) {
|
||||
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_free_ char *p = NULL;
|
||||
@@ -221,7 +221,7 @@ int write_string_file_ts(
|
||||
const char *fn,
|
||||
const char *line,
|
||||
WriteStringFileFlags flags,
|
||||
struct timespec *ts) {
|
||||
const struct timespec *ts) {
|
||||
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
int q, r, fd;
|
||||
|
||||
+2
-2
@@ -48,11 +48,11 @@ DIR* take_fdopendir(int *dfd);
|
||||
FILE* open_memstream_unlocked(char **ptr, size_t *sizeloc);
|
||||
FILE* fmemopen_unlocked(void *buf, size_t size, const char *mode);
|
||||
|
||||
int write_string_stream_ts(FILE *f, const char *line, WriteStringFileFlags flags, struct timespec *ts);
|
||||
int write_string_stream_ts(FILE *f, const char *line, WriteStringFileFlags flags, const struct timespec *ts);
|
||||
static inline int write_string_stream(FILE *f, const char *line, WriteStringFileFlags flags) {
|
||||
return write_string_stream_ts(f, line, flags, NULL);
|
||||
}
|
||||
int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags flags, struct timespec *ts);
|
||||
int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags flags, const struct timespec *ts);
|
||||
static inline int write_string_file(const char *fn, const char *line, WriteStringFileFlags flags) {
|
||||
return write_string_file_ts(fn, line, flags, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user