X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Ffileio.c;h=f2a8f29e677c7180077959994c0cac76c24c4911;hb=66ecc207e203db5434610395cd04c40ae8727b58;hp=cd2c361e3df600a15a40b383126f0c04c224e662;hpb=4084669c7f802c9745bcb6bed77bdaf49ffd896d;p=elogind.git
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index cd2c361e3..f2a8f29e6 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
/***
This file is part of systemd.
@@ -19,6 +17,15 @@
along with systemd; If not, see .
***/
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#include
#include "alloc-util.h"
@@ -28,15 +35,17 @@
#include "fileio.h"
#include "fs-util.h"
#include "hexdecoct.h"
+//#include "log.h"
+//#include "macro.h"
#include "parse-util.h"
#include "path-util.h"
#include "random-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
+//#include "time-util.h"
#include "umask-util.h"
#include "utf8.h"
-#include "util.h"
int write_string_stream(FILE *f, const char *line, bool enforce_newline) {
@@ -154,7 +163,7 @@ int read_one_line_file(const char *fn, char **line) {
if (!fgets(t, sizeof(t), f)) {
if (ferror(f))
- return errno ? -errno : -EIO;
+ return errno > 0 ? -errno : -EIO;
t[0] = 0;
}
@@ -935,6 +944,7 @@ DIR *xopendirat(int fd, const char *name, int flags) {
return d;
}
+#if 0 /// UNNEEDED by elogind
static int search_and_fopen_internal(const char *path, const char *mode, const char *root, char **search, FILE **_f) {
char **i;
@@ -995,7 +1005,6 @@ int search_and_fopen(const char *path, const char *mode, const char *root, const
return search_and_fopen_internal(path, mode, root, copy, _f);
}
-#if 0 /// UNNEEDED by elogind
int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f) {
_cleanup_strv_free_ char **s = NULL;
@@ -1059,7 +1068,7 @@ int fflush_and_check(FILE *f) {
fflush(f);
if (ferror(f))
- return errno ? -errno : -EIO;
+ return errno > 0 ? -errno : -EIO;
return 0;
}
@@ -1138,6 +1147,7 @@ int tempfn_xxxxxx(const char *p, const char *extra, char **ret) {
return 0;
}
+#if 0 /// UNNEEDED by elogind
int tempfn_random(const char *p, const char *extra, char **ret) {
const char *fn;
char *t, *x;
@@ -1180,7 +1190,6 @@ int tempfn_random(const char *p, const char *extra, char **ret) {
return 0;
}
-#if 0 /// UNNEEDED by elogind
int tempfn_random_child(const char *p, const char *extra, char **ret) {
char *t, *x;
uint64_t u;
@@ -1249,4 +1258,33 @@ int read_timestamp_file(const char *fn, usec_t *ret) {
*ret = (usec_t) t;
return 0;
}
+
+int fputs_with_space(FILE *f, const char *s, const char *separator, bool *space) {
+ int r;
+
+ assert(s);
+
+ /* Outputs the specified string with fputs(), but optionally prefixes it with a separator. The *space parameter
+ * when specified shall initially point to a boolean variable initialized to false. It is set to true after the
+ * first invocation. This call is supposed to be use in loops, where a separator shall be inserted between each
+ * element, but not before the first one. */
+
+ if (!f)
+ f = stdout;
+
+ if (space) {
+ if (!separator)
+ separator = " ";
+
+ if (*space) {
+ r = fputs(separator, f);
+ if (r < 0)
+ return r;
+ }
+
+ *space = true;
+ }
+
+ return fputs(s, f);
+}
#endif // 0