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(data, u->transient_file);
-
- if (!endswith(data, "\n"))
- fputc('\n', u->transient_file);
+ fputs_with_newline(data, u->transient_file);
/* Remember which section we wrote this entry to */
u->last_section_private = !!(flags & UNIT_PRIVATE);