summaryrefslogtreecommitdiff
path: root/src/basic/fileio.c
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-09-13 20:39:58 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-09-13 20:39:58 -0400
commitb3ec0a0674f4e499bcb6d2469acdf9d2d574c3d6 (patch)
tree374687545d464bb1e57991cf73b654a7fa0b83ba /src/basic/fileio.c
parentf6e7ffdf3fe8e3ed5e659f747946461350ade5a8 (diff)
parentae8150ecbd54765622aadf288100440d71a10ccd (diff)
Merge tag 'systemd/v231-1.parabola1' into systemd/parabola
Diffstat (limited to 'src/basic/fileio.c')
-rw-r--r--src/basic/fileio.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index 29f5374222..f183de4999 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -1067,7 +1067,7 @@ int fflush_and_check(FILE *f) {
return 0;
}
-/* This is much like like mkostemp() but is subject to umask(). */
+/* This is much like mkostemp() but is subject to umask(). */
int mkostemp_safe(char *pattern, int flags) {
_cleanup_umask_ mode_t u = 0;
int fd;
@@ -1259,7 +1259,8 @@ int open_tmpfile_unlinkable(const char *directory, int flags) {
char *p;
int fd;
- assert(directory);
+ if (!directory)
+ directory = "/tmp";
/* Returns an unlinked temporary file that cannot be linked into the file system anymore */
@@ -1354,3 +1355,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;
+}