chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Properly check for overflow in offsets
[elogind.git]
/
src
/
shared
/
fileio.c
diff --git
a/src/shared/fileio.c
b/src/shared/fileio.c
index 48dd44239fa6dc9930072b808eb2e140d3a7ffb9..ad068bf30da6c4687b80393a6c387ca388ee74ea 100644
(file)
--- a/
src/shared/fileio.c
+++ b/
src/shared/fileio.c
@@
-24,16
+24,8
@@
#include "util.h"
#include "strv.h"
#include "util.h"
#include "strv.h"
-int write_string_file(const char *fn, const char *line) {
- _cleanup_fclose_ FILE *f = NULL;
-
- assert(fn);
- assert(line);
-
- f = fopen(fn, "we");
- if (!f)
- return -errno;
+int write_string_to_file(FILE *f, const char *line) {
errno = 0;
fputs(line, f);
if (!endswith(line, "\n"))
errno = 0;
fputs(line, f);
if (!endswith(line, "\n"))
@@
-47,6
+39,19
@@
int write_string_file(const char *fn, const char *line) {
return 0;
}
return 0;
}
+int write_string_file(const char *fn, const char *line) {
+ _cleanup_fclose_ FILE *f = NULL;
+
+ assert(fn);
+ assert(line);
+
+ f = fopen(fn, "we");
+ if (!f)
+ return -errno;
+
+ return write_string_to_file(f, line);
+}
+
int write_string_file_atomic(const char *fn, const char *line) {
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
int write_string_file_atomic(const char *fn, const char *line) {
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;