chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
sysusers: add minimal tool to reconstruct /etc/passwd and /etc/group from static...
[elogind.git]
/
src
/
shared
/
util.c
diff --git
a/src/shared/util.c
b/src/shared/util.c
index 91cbf2045444cffdc78f7c188382ffefc2ee2bae..a7aec5c54f53114b991084277055901e77f74a96 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-4007,24
+4007,16
@@
int fd_wait_for_event(int fd, int event, usec_t t) {
int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
FILE *f;
char *t;
int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
FILE *f;
char *t;
- const char *fn;
- size_t k;
int fd;
assert(path);
assert(_f);
assert(_temp_path);
int fd;
assert(path);
assert(_f);
assert(_temp_path);
- t =
new(char, strlen(path) + 1 + 6 + 1
);
+ t =
strappend(path, ".XXXXXX"
);
if (!t)
return -ENOMEM;
if (!t)
return -ENOMEM;
- fn = basename(path);
- k = fn - path;
- memcpy(t, path, k);
- t[k] = '.';
- stpcpy(stpcpy(t+k+1, fn), "XXXXXX");
-
fd = mkostemp_safe(t, O_WRONLY|O_CLOEXEC);
if (fd < 0) {
free(t);
fd = mkostemp_safe(t, O_WRONLY|O_CLOEXEC);
if (fd < 0) {
free(t);
@@
-6665,3
+6657,14
@@
int bind_remount_recursive(const char *prefix, bool ro) {
}
}
}
}
}
}
+
+int fflush_and_check(FILE *f) {
+
+ errno = 0;
+ fflush(f);
+
+ if (ferror(f))
+ return errno ? -errno : -EIO;
+
+ return 0;
+}