return 0;
}
+int fputs_with_newline(FILE *f, const char *s) {
+
+ /* This is like fputs() but outputs a trailing newline char, but only if the string isn't empty
+ * and doesn't end in a newline already. Returns 0 in case we didn't append a newline, > 0 otherwise. */
+
+ if (isempty(s))
+ return 0;
+
+ if (!f)
+ f = stdout;
+
+ if (fputs(s, f) < 0)
+ return -EIO;
+
+ if (endswith(s, "\n"))
+ return 0;
+
+ if (fputc('\n', f) < 0)
+ return -EIO;
+
+ return 1;
+}
+
/* A bitmask of the EOL markers we know */
typedef enum EndOfLineMarker {
EOL_NONE = 0,
int read_timestamp_file(const char *fn, usec_t *ret);
int fputs_with_separator(FILE *f, const char *s, const char *separator, bool *space);
+int fputs_with_newline(FILE *f, const char *s);
typedef enum ReadLineFlags {
READ_LINE_ONLY_NUL = 1 << 0,
return q - (const uint8_t*) p;
}
-
-int fputs_with_newline(const char *s, FILE *f) {
- assert(s);
- assert(f);
-
- /* This is like fputs() but outputs a trailing newline char, but only if the string doesn't end in a
- * newline anyway. Just like fputs() returns EOF on error. Otherwise returns 0 in case we didn't
- * append a newline, > 0 otherwise. */
-
- if (fputs(s, f) == EOF)
- return EOF;
- if (endswith(s, "\n"))
- return 0;
-
- return fputc('\n', f) == EOF ? EOF : 1;
-}
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include <stdio.h>
#include <sys/types.h>
#include "macro.h"
return FILE_SIZE_VALID(l);
}
-
-int fputs_with_newline(const char *s, FILE *f);
#include "format-util.h"
#include "id128-util.h"
#include "install.h"
-#include "io-util.h"
#include "iovec-util.h"
#include "label-util.h"
#include "load-dropin.h"
}
if (u->transient_file) {
- /* When this is a transient unit file in creation, then let's not create a new drop-in but instead
- * write to the transient unit file. */
- fputs_with_newline(data, u->transient_file);
+ /* When this is a transient unit file in creation, then let's not create a new drop-in,
+ * but instead write to the transient unit file. */
+ fputs_with_newline(u->transient_file, data);
/* Remember which section we wrote this entry to */
u->last_section_private = !!(flags & UNIT_PRIVATE);
log_warning_errno(r, "Failed to parse returned interface description at %u:%u, showing raw interface description: %m", line, column);
pager_open(arg_pager_flags);
- fputs_with_newline(description, stdout);
+ fputs_with_newline(stdout, description);
} else if (list_methods) {
for (const VarlinkSymbol *const *y = vi->symbols, *symbol; (symbol = *y); y++) {
if (symbol->symbol_type != VARLINK_METHOD)