diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2016-06-30 21:30:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-30 21:30:35 +0200 |
commit | f15461b2b234c178ecbbc18defaef0032a9b3431 (patch) | |
tree | 81faab6f15ff44393c55484d216fd2e80b993bbf /src/basic | |
parent | 17c22746b176f2e544d33bdaf30b282ce2c88933 (diff) | |
parent | 1c6c037cece7add31e4017ea7775ddb32d4fe7ec (diff) |
Merge pull request #3596 from poettering/machine-clean
make "machinectl clean" asynchronous, and open it up via PolicyKit
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/fileio.c | 41 | ||||
-rw-r--r-- | src/basic/fileio.h | 2 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 29f5374222..0360a8eab3 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -1354,3 +1354,44 @@ int link_tmpfile(int fd, const char *path, const char *target) { return 0; } + +int read_nul_string(FILE *f, char **ret) { + _cleanup_free_ char *x = NULL; + size_t allocated = 0, n = 0; + + assert(f); + assert(ret); + + /* Reads a NUL-terminated string from the specified file. */ + + for (;;) { + int c; + + if (!GREEDY_REALLOC(x, allocated, n+2)) + return -ENOMEM; + + c = fgetc(f); + if (c == 0) /* Terminate at NUL byte */ + break; + if (c == EOF) { + if (ferror(f)) + return -errno; + break; /* Terminate at EOF */ + } + + x[n++] = (char) c; + } + + if (x) + x[n] = 0; + else { + x = new0(char, 1); + if (!x) + return -ENOMEM; + } + + *ret = x; + x = NULL; + + return 0; +} diff --git a/src/basic/fileio.h b/src/basic/fileio.h index 58dbc80c24..9ac497d9eb 100644 --- a/src/basic/fileio.h +++ b/src/basic/fileio.h @@ -86,3 +86,5 @@ int open_tmpfile_unlinkable(const char *directory, int flags); int open_tmpfile_linkable(const char *target, int flags, char **ret_path); int link_tmpfile(int fd, const char *path, const char *target); + +int read_nul_string(FILE *f, char **ret); |