summaryrefslogtreecommitdiff
path: root/src/basic/fileio.c
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2016-06-30 21:30:35 +0200
committerGitHub <noreply@github.com>2016-06-30 21:30:35 +0200
commitf15461b2b234c178ecbbc18defaef0032a9b3431 (patch)
tree81faab6f15ff44393c55484d216fd2e80b993bbf /src/basic/fileio.c
parent17c22746b176f2e544d33bdaf30b282ce2c88933 (diff)
parent1c6c037cece7add31e4017ea7775ddb32d4fe7ec (diff)
Merge pull request #3596 from poettering/machine-clean
make "machinectl clean" asynchronous, and open it up via PolicyKit
Diffstat (limited to 'src/basic/fileio.c')
-rw-r--r--src/basic/fileio.c41
1 files changed, 41 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;
+}