chiark / gitweb /
[Patch 3/3] Add cgroups initialization and handling
[elogind.git] / src / basic / fileio.c
index 718ed3642dca88c5dfe18fe32566940671a30d47..f666380a414e8f5554c9f2511d932aca3c5519bd 100644 (file)
 #include "fileio.h"
 
 int write_string_stream(FILE *f, const char *line, bool enforce_newline) {
+
         assert(f);
         assert(line);
 
-        errno = 0;
-
         fputs(line, f);
         if (enforce_newline && !endswith(line, "\n"))
                 fputc('\n', f);
 
-        fflush(f);
-
-        if (ferror(f))
-                return errno ? -errno : -EIO;
-
-        return 0;
+        return fflush_and_check(f);
 }
 
 static int write_string_file_atomic(const char *fn, const char *line, bool enforce_newline) {
@@ -134,6 +128,8 @@ int read_one_line_file(const char *fn, char **line) {
         return 0;
 }
 
+/// UNNEEDED by elogind
+#if 0
 int verify_one_line_file(const char *fn, const char *line) {
         _cleanup_free_ char *value = NULL;
         int r;
@@ -144,6 +140,7 @@ int verify_one_line_file(const char *fn, const char *line) {
 
         return streq(value, line);
 }
+#endif // 0
 
 int read_full_stream(FILE *f, char **contents, size_t *size) {
         size_t n, l;
@@ -792,7 +789,7 @@ int executable_is_script(const char *path, char **interpreter) {
  */
 int get_status_field(const char *filename, const char *pattern, char **field) {
         _cleanup_free_ char *status = NULL;
-        char *t;
+        char *t, *f;
         size_t len;
         int r;
 
@@ -826,9 +823,10 @@ int get_status_field(const char *filename, const char *pattern, char **field) {
 
         len = strcspn(t, WHITESPACE);
 
-        *field = strndup(t, len);
-        if (!*field)
+        f = strndup(t, len);
+        if (!f)
                 return -ENOMEM;
 
+        *field = f;
         return 0;
 }