X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.c;h=a7aec5c54f53114b991084277055901e77f74a96;hb=1b99214789101976d6bbf75c351279584b071998;hp=91cbf2045444cffdc78f7c188382ffefc2ee2bae;hpb=849958d1ba3533c953fad46d4d41c0ec6e48316d;p=elogind.git diff --git a/src/shared/util.c b/src/shared/util.c index 91cbf2045..a7aec5c54 100644 --- 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; - const char *fn; - size_t k; 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; - 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); @@ -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; +}